F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
sha.h
Go to the documentation of this file.
1 // clang-format off
2 /* crypto/sha/sha.h */
3 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
4  * All rights reserved.
5  *
6  * This package is an SSL implementation written
7  * by Eric Young (eay@cryptsoft.com).
8  * The implementation was written so as to conform with Netscape's SSL.
9  *
10  * This library is free for commercial and non-commercial use as long as
11  * the following conditions are adhered to. The following conditions
12  * apply to all code found in this distribution, be it the RC4, RSA,
13  * lhash, DES, etc., code; not just the SSL code. The SSL documentation
14  * included with this distribution is covered by the same copyright terms
15  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
16  *
17  * Copyright remains Eric Young's, and as such any Copyright notices in
18  * the code are not to be removed.
19  * If this package is used in a product, Eric Young should be given attribution
20  * as the author of the parts of the library used.
21  * This can be in the form of a textual message at program startup or
22  * in documentation (online or textual) provided with the package.
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  * 1. Redistributions of source code must retain the copyright
28  * notice, this list of conditions and the following disclaimer.
29  * 2. Redistributions in binary form must reproduce the above copyright
30  * notice, this list of conditions and the following disclaimer in the
31  * documentation and/or other materials provided with the distribution.
32  * 3. All advertising materials mentioning features or use of this software
33  * must display the following acknowledgement:
34  * "This product includes cryptographic software written by
35  * Eric Young (eay@cryptsoft.com)"
36  * The word 'cryptographic' can be left out if the routines from the library
37  * being used are not cryptographic related :-).
38  * 4. If you include any Windows specific code (or a derivative thereof) from
39  * the apps directory (application code) you must include an acknowledgement:
40  * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
41  *
42  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
43  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
46  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52  * SUCH DAMAGE.
53  *
54  * The licence and distribution terms for any publicly available version or
55  * derivative of this code cannot be changed. i.e. this code cannot simply be
56  * copied and put under another distribution licence
57  * [including the GNU Public Licence.]
58  */
59 
60 #ifndef HEADER_SHA_H
61 # define HEADER_SHA_H
62 
63 # include <openssl/e_os2.h>
64 # include <stddef.h>
65 
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 
70 # if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1))
71 # error SHA is disabled.
72 # endif
73 
74 # if defined(OPENSSL_FIPS)
75 # define FIPS_SHA_SIZE_T size_t
76 # endif
77 
78 /*-
79  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
80  * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then !
81  * ! SHA_LONG_LOG2 has to be defined along. !
82  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
83  */
84 
85 # if defined(__LP32__)
86 # define SHA_LONG unsigned long
87 # elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
88 # define SHA_LONG unsigned long
89 # define SHA_LONG_LOG2 3
90 # else
91 # define SHA_LONG unsigned int
92 # endif
93 
94 # define SHA_LBLOCK 16
95 # define SHA_CBLOCK (SHA_LBLOCK*4)/* SHA treats input data as a
96  * contiguous array of 32 bit wide
97  * big-endian values. */
98 # define SHA_LAST_BLOCK (SHA_CBLOCK-8)
99 # define SHA_DIGEST_LENGTH 20
100 
101 typedef struct SHAstate_st {
105  unsigned int num;
106 } SHA_CTX;
107 
108 # ifndef OPENSSL_NO_SHA0
109 # ifdef OPENSSL_FIPS
110 int private_SHA_Init(SHA_CTX *c);
111 # endif
112 int SHA_Init(SHA_CTX *c);
113 int SHA_Update(SHA_CTX *c, const void *data, size_t len);
114 int SHA_Final(unsigned char *md, SHA_CTX *c);
115 unsigned char *SHA(const unsigned char *d, size_t n, unsigned char *md);
116 void SHA_Transform(SHA_CTX *c, const unsigned char *data);
117 # endif
118 # ifndef OPENSSL_NO_SHA1
119 # ifdef OPENSSL_FIPS
120 int private_SHA1_Init(SHA_CTX *c);
121 # endif
122 int SHA1_Init(SHA_CTX *c);
123 int SHA1_Update(SHA_CTX *c, const void *data, size_t len);
124 int SHA1_Final(unsigned char *md, SHA_CTX *c);
125 unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md);
126 void SHA1_Transform(SHA_CTX *c, const unsigned char *data);
127 # endif
128 
129 # define SHA256_CBLOCK (SHA_LBLOCK*4)/* SHA-256 treats input data as a
130  * contiguous array of 32 bit wide
131  * big-endian values. */
132 # define SHA224_DIGEST_LENGTH 28
133 # define SHA256_DIGEST_LENGTH 32
134 
135 typedef struct SHA256state_st {
139  unsigned int num, md_len;
140 } SHA256_CTX;
141 
142 # ifndef OPENSSL_NO_SHA256
143 # ifdef OPENSSL_FIPS
144 int private_SHA224_Init(SHA256_CTX *c);
145 int private_SHA256_Init(SHA256_CTX *c);
146 # endif
147 int SHA224_Init(SHA256_CTX *c);
148 int SHA224_Update(SHA256_CTX *c, const void *data, size_t len);
149 int SHA224_Final(unsigned char *md, SHA256_CTX *c);
150 unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md);
151 int SHA256_Init(SHA256_CTX *c);
152 int SHA256_Update(SHA256_CTX *c, const void *data, size_t len);
153 int SHA256_Final(unsigned char *md, SHA256_CTX *c);
154 unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md);
155 void SHA256_Transform(SHA256_CTX *c, const unsigned char *data);
156 # endif
157 
158 # define SHA384_DIGEST_LENGTH 48
159 # define SHA512_DIGEST_LENGTH 64
160 
161 # ifndef OPENSSL_NO_SHA512
162 /*
163  * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64
164  * being exactly 64-bit wide. See Implementation Notes in sha512.c
165  * for further details.
166  */
167 /*
168  * SHA-512 treats input data as a
169  * contiguous array of 64 bit
170  * wide big-endian values.
171  */
172 # define SHA512_CBLOCK (SHA_LBLOCK*8)
173 # if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
174 # define SHA_LONG64 unsigned __int64
175 # define U64(C) C##UI64
176 # elif defined(__arch64__)
177 # define SHA_LONG64 unsigned long
178 # define U64(C) C##UL
179 # else
180 # define SHA_LONG64 unsigned long long
181 # define U64(C) C##ULL
182 # endif
183 
184 typedef struct SHA512state_st {
187  union {
189  unsigned char p[SHA512_CBLOCK];
190  } u;
191  unsigned int num, md_len;
192 } SHA512_CTX;
193 # endif
194 
195 # ifndef OPENSSL_NO_SHA512
196 # ifdef OPENSSL_FIPS
197 int private_SHA384_Init(SHA512_CTX *c);
198 int private_SHA512_Init(SHA512_CTX *c);
199 # endif
200 int SHA384_Init(SHA512_CTX *c);
201 int SHA384_Update(SHA512_CTX *c, const void *data, size_t len);
202 int SHA384_Final(unsigned char *md, SHA512_CTX *c);
203 unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md);
204 int SHA512_Init(SHA512_CTX *c);
205 int SHA512_Update(SHA512_CTX *c, const void *data, size_t len);
206 int SHA512_Final(unsigned char *md, SHA512_CTX *c);
207 unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md);
208 void SHA512_Transform(SHA512_CTX *c, const unsigned char *data);
209 # endif
210 
211 #ifdef __cplusplus
212 }
213 #endif
214 
215 #endif
void SHA_Transform(SHA_CTX *c, const unsigned char *data)
union SHA512state_st::@470 u
#define SHA_LONG64
Definition: sha.h:180
SHA_LONG Nh
Definition: sha.h:103
void SHA1_Transform(SHA_CTX *c, const unsigned char *data)
int SHA_Update(SHA_CTX *c, const void *data, size_t len)
SHA_LONG data[SHA_LBLOCK]
Definition: sha.h:138
SHA_LONG h3
Definition: sha.h:102
int SHA384_Final(unsigned char *md, SHA512_CTX *c)
SHA_LONG Nh
Definition: sha.h:137
unsigned char * SHA256(const unsigned char *d, size_t n, unsigned char *md)
SHA_LONG Nl
Definition: sha.h:103
unsigned char p[SHA512_CBLOCK]
Definition: sha.h:189
int SHA224_Update(SHA256_CTX *c, const void *data, size_t len)
unsigned int md_len
Definition: sha.h:191
SHA_LONG64 Nl
Definition: sha.h:186
unsigned int num
Definition: sha.h:191
int SHA_Init(SHA_CTX *c)
SHA_LONG64 Nh
Definition: sha.h:186
int SHA224_Final(unsigned char *md, SHA256_CTX *c)
SHA_LONG64 h[8]
Definition: sha.h:185
SHA_LONG h4
Definition: sha.h:102
void SHA256_Transform(SHA256_CTX *c, const unsigned char *data)
SHA_LONG data[SHA_LBLOCK]
Definition: sha.h:104
int SHA256_Update(SHA256_CTX *c, const void *data, size_t len)
unsigned int num
Definition: sha.h:139
#define SHA_LBLOCK
Definition: sha.h:94
int SHA_Final(unsigned char *md, SHA_CTX *c)
SHA_LONG h0
Definition: sha.h:102
void SHA512_Transform(SHA512_CTX *c, const unsigned char *data)
int SHA1_Init(SHA_CTX *c)
int SHA512_Update(SHA512_CTX *c, const void *data, size_t len)
unsigned char * SHA1(const unsigned char *d, size_t n, unsigned char *md)
unsigned int md_len
Definition: sha.h:139
SHA_LONG h1
Definition: sha.h:102
int SHA1_Update(SHA_CTX *c, const void *data, size_t len)
int SHA1_Final(unsigned char *md, SHA_CTX *c)
unsigned char * SHA(const unsigned char *d, size_t n, unsigned char *md)
int SHA384_Update(SHA512_CTX *c, const void *data, size_t len)
#define SHA512_CBLOCK
Definition: sha.h:172
struct SHA256state_st SHA256_CTX
int SHA256_Init(SHA256_CTX *c)
int SHA512_Init(SHA512_CTX *c)
unsigned int num
Definition: sha.h:105
#define SHA_LONG
Definition: sha.h:91
unsigned char * SHA512(const unsigned char *d, size_t n, unsigned char *md)
struct SHAstate_st SHA_CTX
int SHA224_Init(SHA256_CTX *c)
struct SHA512state_st SHA512_CTX
int SHA256_Final(unsigned char *md, SHA256_CTX *c)
SHA_LONG h[8]
Definition: sha.h:136
SHA_LONG64 d[SHA_LBLOCK]
Definition: sha.h:188
unsigned char * SHA224(const unsigned char *d, size_t n, unsigned char *md)
unsigned char * SHA384(const unsigned char *d, size_t n, unsigned char *md)
SHA_LONG h2
Definition: sha.h:102
int SHA384_Init(SHA512_CTX *c)
SHA_LONG Nl
Definition: sha.h:137
int SHA512_Final(unsigned char *md, SHA512_CTX *c)