• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
10 #ifndef HEADER_SHA_H
11 # define HEADER_SHA_H
12 
13 # include <openssl/e_os2.h>
14 # include <stddef.h>
15 
16 #ifdef  __cplusplus
17 extern "C" {
18 #endif
19 
20 /*-
21  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
22  * ! SHA_LONG has to be at least 32 bits wide.                    !
23  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
24  */
25 # define SHA_LONG unsigned int
26 
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 
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 
41 int SHA1_Init(SHA_CTX *c);
42 int SHA1_Update(SHA_CTX *c, const void *data, size_t len);
43 int SHA1_Final(unsigned char *md, SHA_CTX *c);
44 unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md);
45 void SHA1_Transform(SHA_CTX *c, const unsigned char *data);
46 
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 
51 typedef struct SHA256state_st {
52     SHA_LONG h[8];
53     SHA_LONG Nl, Nh;
54     SHA_LONG data[SHA_LBLOCK];
55     unsigned int num, md_len;
56 } SHA256_CTX;
57 
58 int SHA224_Init(SHA256_CTX *c);
59 int SHA224_Update(SHA256_CTX *c, const void *data, size_t len);
60 int SHA224_Final(unsigned char *md, SHA256_CTX *c);
61 unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md);
62 int SHA256_Init(SHA256_CTX *c);
63 int SHA256_Update(SHA256_CTX *c, const void *data, size_t len);
64 int SHA256_Final(unsigned char *md, SHA256_CTX *c);
65 unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md);
66 void SHA256_Transform(SHA256_CTX *c, const unsigned char *data);
67 
68 # define SHA224_DIGEST_LENGTH    28
69 # define SHA256_DIGEST_LENGTH    32
70 # define SHA384_DIGEST_LENGTH    48
71 # define SHA512_DIGEST_LENGTH    64
72 
73 /*
74  * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64
75  * being exactly 64-bit wide. See Implementation Notes in sha512.c
76  * for further details.
77  */
78 /*
79  * SHA-512 treats input data as a
80  * contiguous array of 64 bit
81  * wide big-endian values.
82  */
83 # define SHA512_CBLOCK   (SHA_LBLOCK*8)
84 # if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
85 #  define SHA_LONG64 unsigned __int64
86 #  define U64(C)     C##UI64
87 # elif defined(__arch64__)
88 #  define SHA_LONG64 unsigned long
89 #  define U64(C)     C##UL
90 # else
91 #  define SHA_LONG64 unsigned long long
92 #  define U64(C)     C##ULL
93 # endif
94 
95 typedef struct SHA512state_st {
96     SHA_LONG64 h[8];
97     SHA_LONG64 Nl, Nh;
98     union {
99         SHA_LONG64 d[SHA_LBLOCK];
100         unsigned char p[SHA512_CBLOCK];
101     } u;
102     unsigned int num, md_len;
103 } SHA512_CTX;
104 
105 int SHA384_Init(SHA512_CTX *c);
106 int SHA384_Update(SHA512_CTX *c, const void *data, size_t len);
107 int SHA384_Final(unsigned char *md, SHA512_CTX *c);
108 unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md);
109 int SHA512_Init(SHA512_CTX *c);
110 int SHA512_Update(SHA512_CTX *c, const void *data, size_t len);
111 int SHA512_Final(unsigned char *md, SHA512_CTX *c);
112 unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md);
113 void SHA512_Transform(SHA512_CTX *c, const unsigned char *data);
114 
115 #ifdef  __cplusplus
116 }
117 #endif
118 
119 #endif
120