You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sha.h 4.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. {
  21. #endif
  22. #define SHA_DIGEST_LENGTH 20
  23. #ifndef OPENSSL_NO_DEPRECATED_3_0
  24. /*-
  25. * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  26. * ! SHA_LONG has to be at least 32 bits wide. !
  27. * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  28. */
  29. #define SHA_LONG unsigned int
  30. #define SHA_LBLOCK 16
  31. #define SHA_CBLOCK (SHA_LBLOCK * 4) /* SHA treats input data as a \
  32. * contiguous array of 32 bit wide \
  33. * big-endian values. */
  34. #define SHA_LAST_BLOCK (SHA_CBLOCK - 8)
  35. typedef struct SHAstate_st
  36. {
  37. SHA_LONG h0, h1, h2, h3, h4;
  38. SHA_LONG Nl, Nh;
  39. SHA_LONG data[SHA_LBLOCK];
  40. unsigned int num;
  41. } SHA_CTX;
  42. OSSL_DEPRECATEDIN_3_0 int SHA1_Init(SHA_CTX* c);
  43. OSSL_DEPRECATEDIN_3_0 int SHA1_Update(SHA_CTX* c, const void* data, size_t len);
  44. OSSL_DEPRECATEDIN_3_0 int SHA1_Final(unsigned char* md, SHA_CTX* c);
  45. OSSL_DEPRECATEDIN_3_0 void SHA1_Transform(SHA_CTX* c, const unsigned char* data);
  46. #endif
  47. unsigned char* SHA1(const unsigned char* d, size_t n, unsigned char* md);
  48. #ifndef OPENSSL_NO_DEPRECATED_3_0
  49. #define SHA256_CBLOCK (SHA_LBLOCK * 4) /* SHA-256 treats input data as a \
  50. * contiguous array of 32 bit wide \
  51. * big-endian values. */
  52. typedef struct SHA256state_st
  53. {
  54. SHA_LONG h[8];
  55. SHA_LONG Nl, Nh;
  56. SHA_LONG data[SHA_LBLOCK];
  57. unsigned int num, md_len;
  58. } SHA256_CTX;
  59. OSSL_DEPRECATEDIN_3_0 int SHA224_Init(SHA256_CTX* c);
  60. OSSL_DEPRECATEDIN_3_0 int SHA224_Update(SHA256_CTX* c, const void* data, size_t len);
  61. OSSL_DEPRECATEDIN_3_0 int SHA224_Final(unsigned char* md, SHA256_CTX* c);
  62. OSSL_DEPRECATEDIN_3_0 int SHA256_Init(SHA256_CTX* c);
  63. OSSL_DEPRECATEDIN_3_0 int SHA256_Update(SHA256_CTX* c, const void* data, size_t len);
  64. OSSL_DEPRECATEDIN_3_0 int SHA256_Final(unsigned char* md, SHA256_CTX* c);
  65. OSSL_DEPRECATEDIN_3_0 void SHA256_Transform(SHA256_CTX* c, 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. {
  94. SHA_LONG64 h[8];
  95. SHA_LONG64 Nl, Nh;
  96. union
  97. {
  98. SHA_LONG64 d[SHA_LBLOCK];
  99. unsigned char p[SHA512_CBLOCK];
  100. } u;
  101. unsigned int num, md_len;
  102. } SHA512_CTX;
  103. OSSL_DEPRECATEDIN_3_0 int SHA384_Init(SHA512_CTX* c);
  104. OSSL_DEPRECATEDIN_3_0 int SHA384_Update(SHA512_CTX* c, const void* data, size_t len);
  105. OSSL_DEPRECATEDIN_3_0 int SHA384_Final(unsigned char* md, SHA512_CTX* c);
  106. OSSL_DEPRECATEDIN_3_0 int SHA512_Init(SHA512_CTX* c);
  107. OSSL_DEPRECATEDIN_3_0 int SHA512_Update(SHA512_CTX* c, 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, const unsigned char* data);
  110. #endif
  111. unsigned char* SHA384(const unsigned char* d, size_t n, unsigned char* md);
  112. unsigned char* SHA512(const unsigned char* d, size_t n, unsigned char* md);
  113. #ifdef __cplusplus
  114. }
  115. #endif
  116. #endif