sha.h 3.7 KB

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