sha.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OPENSSL_SHA_H
  10. # define OPENSSL_SHA_H
  11. # pragma once
  12. # include <openssl/macros.h>
  13. # ifndef OPENSSL_NO_DEPRECATED_3_0
  14. # define HEADER_SHA_H
  15. # endif
  16. # include <openssl/e_os2.h>
  17. # include <stddef.h>
  18. # ifdef __cplusplus
  19. extern "C" {
  20. # endif
  21. # define SHA_DIGEST_LENGTH 20
  22. # ifndef OPENSSL_NO_DEPRECATED_3_0
  23. /*-
  24. * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  25. * ! SHA_LONG has to be at least 32 bits wide. !
  26. * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  27. */
  28. # define SHA_LONG unsigned int
  29. # define SHA_LBLOCK 16
  30. # define SHA_CBLOCK (SHA_LBLOCK*4)/* SHA treats input data as a
  31. * contiguous array of 32 bit wide
  32. * big-endian values. */
  33. # define SHA_LAST_BLOCK (SHA_CBLOCK-8)
  34. typedef struct SHAstate_st {
  35. SHA_LONG h0, h1, h2, h3, h4;
  36. SHA_LONG Nl, Nh;
  37. SHA_LONG data[SHA_LBLOCK];
  38. unsigned int num;
  39. } SHA_CTX;
  40. OSSL_DEPRECATEDIN_3_0 int SHA1_Init(SHA_CTX *c);
  41. OSSL_DEPRECATEDIN_3_0 int SHA1_Update(SHA_CTX *c, const void *data, size_t len);
  42. OSSL_DEPRECATEDIN_3_0 int SHA1_Final(unsigned char *md, SHA_CTX *c);
  43. OSSL_DEPRECATEDIN_3_0 void SHA1_Transform(SHA_CTX *c, const unsigned char *data);
  44. # endif
  45. unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md);
  46. # ifndef OPENSSL_NO_DEPRECATED_3_0
  47. # define SHA256_CBLOCK (SHA_LBLOCK*4)/* SHA-256 treats input data as a
  48. * contiguous array of 32 bit wide
  49. * big-endian values. */
  50. typedef struct SHA256state_st {
  51. SHA_LONG h[8];
  52. SHA_LONG Nl, Nh;
  53. SHA_LONG data[SHA_LBLOCK];
  54. unsigned int num, md_len;
  55. } SHA256_CTX;
  56. OSSL_DEPRECATEDIN_3_0 int SHA224_Init(SHA256_CTX *c);
  57. OSSL_DEPRECATEDIN_3_0 int SHA224_Update(SHA256_CTX *c,
  58. const void *data, size_t len);
  59. OSSL_DEPRECATEDIN_3_0 int SHA224_Final(unsigned char *md, SHA256_CTX *c);
  60. OSSL_DEPRECATEDIN_3_0 int SHA256_Init(SHA256_CTX *c);
  61. OSSL_DEPRECATEDIN_3_0 int SHA256_Update(SHA256_CTX *c,
  62. const void *data, size_t len);
  63. OSSL_DEPRECATEDIN_3_0 int SHA256_Final(unsigned char *md, SHA256_CTX *c);
  64. OSSL_DEPRECATEDIN_3_0 void SHA256_Transform(SHA256_CTX *c,
  65. const unsigned char *data);
  66. # endif
  67. unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md);
  68. unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md);
  69. # define SHA224_DIGEST_LENGTH 28
  70. # define SHA256_DIGEST_LENGTH 32
  71. # define SHA384_DIGEST_LENGTH 48
  72. # define SHA512_DIGEST_LENGTH 64
  73. # ifndef OPENSSL_NO_DEPRECATED_3_0
  74. /*
  75. * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64
  76. * being exactly 64-bit wide. See Implementation Notes in sha512.c
  77. * for further details.
  78. */
  79. /*
  80. * SHA-512 treats input data as a
  81. * contiguous array of 64 bit
  82. * wide big-endian values.
  83. */
  84. # define SHA512_CBLOCK (SHA_LBLOCK*8)
  85. # if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
  86. # define SHA_LONG64 unsigned __int64
  87. # elif defined(__arch64__)
  88. # define SHA_LONG64 unsigned long
  89. # else
  90. # define SHA_LONG64 unsigned long long
  91. # endif
  92. typedef struct SHA512state_st {
  93. SHA_LONG64 h[8];
  94. SHA_LONG64 Nl, Nh;
  95. union {
  96. SHA_LONG64 d[SHA_LBLOCK];
  97. unsigned char p[SHA512_CBLOCK];
  98. } u;
  99. unsigned int num, md_len;
  100. } SHA512_CTX;
  101. OSSL_DEPRECATEDIN_3_0 int SHA384_Init(SHA512_CTX *c);
  102. OSSL_DEPRECATEDIN_3_0 int SHA384_Update(SHA512_CTX *c,
  103. const void *data, size_t len);
  104. OSSL_DEPRECATEDIN_3_0 int SHA384_Final(unsigned char *md, SHA512_CTX *c);
  105. OSSL_DEPRECATEDIN_3_0 int SHA512_Init(SHA512_CTX *c);
  106. OSSL_DEPRECATEDIN_3_0 int SHA512_Update(SHA512_CTX *c,
  107. const void *data, size_t len);
  108. OSSL_DEPRECATEDIN_3_0 int SHA512_Final(unsigned char *md, SHA512_CTX *c);
  109. OSSL_DEPRECATEDIN_3_0 void SHA512_Transform(SHA512_CTX *c,
  110. const unsigned char *data);
  111. # endif
  112. unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md);
  113. unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md);
  114. # ifdef __cplusplus
  115. }
  116. # endif
  117. #endif