sha.h 3.8 KB

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