webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
sha.h
Go to the documentation of this file.
1 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
2  * All rights reserved.
3  *
4  * This package is an SSL implementation written
5  * by Eric Young (eay@cryptsoft.com).
6  * The implementation was written so as to conform with Netscapes SSL.
7  *
8  * This library is free for commercial and non-commercial use as long as
9  * the following conditions are aheared to. The following conditions
10  * apply to all code found in this distribution, be it the RC4, RSA,
11  * lhash, DES, etc., code; not just the SSL code. The SSL documentation
12  * included with this distribution is covered by the same copyright terms
13  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
14  *
15  * Copyright remains Eric Young's, and as such any Copyright notices in
16  * the code are not to be removed.
17  * If this package is used in a product, Eric Young should be given attribution
18  * as the author of the parts of the library used.
19  * This can be in the form of a textual message at program startup or
20  * in documentation (online or textual) provided with the package.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the copyright
26  * notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  * notice, this list of conditions and the following disclaimer in the
29  * documentation and/or other materials provided with the distribution.
30  * 3. All advertising materials mentioning features or use of this software
31  * must display the following acknowledgement:
32  * "This product includes cryptographic software written by
33  * Eric Young (eay@cryptsoft.com)"
34  * The word 'cryptographic' can be left out if the rouines from the library
35  * being used are not cryptographic related :-).
36  * 4. If you include any Windows specific code (or a derivative thereof) from
37  * the apps directory (application code) you must include an acknowledgement:
38  * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
39  *
40  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  *
52  * The licence and distribution terms for any publically available version or
53  * derivative of this code cannot be changed. i.e. this code cannot simply be
54  * copied and put under another distribution licence
55  * [including the GNU Public Licence.] */
56 
57 #ifndef OPENSSL_HEADER_SHA_H
58 #define OPENSSL_HEADER_SHA_H
59 
60 #include <openssl/base.h>
61 
62 #if defined(__cplusplus)
63 extern "C" {
64 #endif
65 
66 
67 /* The SHA family of hash functions (SHA-1 and SHA-2). */
68 
69 
70 /* SHA_CBLOCK is the block size of SHA-1. */
71 #define SHA_CBLOCK 64
72 
73 /* SHA_DIGEST_LENGTH is the length of a SHA-1 digest. */
74 #define SHA_DIGEST_LENGTH 20
75 
76 /* TODO(fork): remove */
77 #define SHA_LBLOCK 16
78 #define SHA_LONG uint32_t
79 
80 /* SHA1_Init initialises |sha| and returns one. */
82 
83 /* SHA1_Update adds |len| bytes from |data| to |sha| and returns one. */
84 OPENSSL_EXPORT int SHA1_Update(SHA_CTX *sha, const void *data, size_t len);
85 
86 /* SHA1_Final adds the final padding to |sha| and writes the resulting digest
87  * to |md|, which must have at least |SHA_DIGEST_LENGTH| bytes of space. It
88  * returns one. */
90 
91 /* SHA1 writes the digest of |len| bytes from |data| to |out| and returns
92  * |out|. There must be at least |SHA_DIGEST_LENGTH| bytes of space in
93  * |out|. */
95 
96 /* SHA1_Transform is a low-level function that performs a single, SHA-1 block
97  * transformation using the state from |sha| and |SHA_CBLOCK| bytes from
98  * |block|. */
100 
101 struct sha_state_st {
102 #if defined(OPENSSL_WINDOWS)
103  uint32_t h[5];
104 #else
105  /* wpa_supplicant accesses |h0|..|h4| so we must support those names
106  * for compatibility with it until it can be updated. */
107  union {
108  uint32_t h[5];
109  struct {
115  };
116  };
117 #endif
120  unsigned num;
121 };
122 
123 
124 /* SHA-224. */
125 
126 /* SHA224_CBLOCK is the block size of SHA-224. */
127 #define SHA224_CBLOCK 64
128 
129 /* SHA224_DIGEST_LENGTH is the length of a SHA-224 digest. */
130 #define SHA224_DIGEST_LENGTH 28
131 
132 /* SHA224_Init initialises |sha| and returns 1. */
134 
135 /* SHA224_Update adds |len| bytes from |data| to |sha| and returns 1. */
136 OPENSSL_EXPORT int SHA224_Update(SHA256_CTX *sha, const void *data, size_t len);
137 
138 /* SHA224_Final adds the final padding to |sha| and writes the resulting digest
139  * to |md|, which must have at least |SHA224_DIGEST_LENGTH| bytes of space. It
140  * returns one on success and zero on programmer error. */
142 
143 /* SHA224 writes the digest of |len| bytes from |data| to |out| and returns
144  * |out|. There must be at least |SHA224_DIGEST_LENGTH| bytes of space in
145  * |out|. */
147 
148 
149 /* SHA-256. */
150 
151 /* SHA256_CBLOCK is the block size of SHA-256. */
152 #define SHA256_CBLOCK 64
153 
154 /* SHA256_DIGEST_LENGTH is the length of a SHA-256 digest. */
155 #define SHA256_DIGEST_LENGTH 32
156 
157 /* SHA256_Init initialises |sha| and returns 1. */
159 
160 /* SHA256_Update adds |len| bytes from |data| to |sha| and returns 1. */
161 OPENSSL_EXPORT int SHA256_Update(SHA256_CTX *sha, const void *data, size_t len);
162 
163 /* SHA256_Final adds the final padding to |sha| and writes the resulting digest
164  * to |md|, which must have at least |SHA256_DIGEST_LENGTH| bytes of space. It
165  * returns one on success and zero on programmer error. */
167 
168 /* SHA256 writes the digest of |len| bytes from |data| to |out| and returns
169  * |out|. There must be at least |SHA256_DIGEST_LENGTH| bytes of space in
170  * |out|. */
172 
173 /* SHA256_Transform is a low-level function that performs a single, SHA-256
174  * block transformation using the state from |sha| and |SHA256_CBLOCK| bytes
175  * from |block|. */
177 
182  unsigned num, md_len;
183 };
184 
185 
186 /* SHA-384. */
187 
188 /* SHA384_CBLOCK is the block size of SHA-384. */
189 #define SHA384_CBLOCK 128
190 
191 /* SHA384_DIGEST_LENGTH is the length of a SHA-384 digest. */
192 #define SHA384_DIGEST_LENGTH 48
193 
194 /* SHA384_Init initialises |sha| and returns 1. */
196 
197 /* SHA384_Update adds |len| bytes from |data| to |sha| and returns 1. */
198 OPENSSL_EXPORT int SHA384_Update(SHA512_CTX *sha, const void *data, size_t len);
199 
200 /* SHA384_Final adds the final padding to |sha| and writes the resulting digest
201  * to |md|, which must have at least |SHA384_DIGEST_LENGTH| bytes of space. It
202  * returns one on success and zero on programmer error. */
204 
205 /* SHA384 writes the digest of |len| bytes from |data| to |out| and returns
206  * |out|. There must be at least |SHA384_DIGEST_LENGTH| bytes of space in
207  * |out|. */
209 
210 /* SHA384_Transform is a low-level function that performs a single, SHA-384
211  * block transformation using the state from |sha| and |SHA384_CBLOCK| bytes
212  * from |block|. */
214 
215 
216 /* SHA-512. */
217 
218 /* SHA512_CBLOCK is the block size of SHA-512. */
219 #define SHA512_CBLOCK 128
220 
221 /* SHA512_DIGEST_LENGTH is the length of a SHA-512 digest. */
222 #define SHA512_DIGEST_LENGTH 64
223 
224 /* SHA512_Init initialises |sha| and returns 1. */
226 
227 /* SHA512_Update adds |len| bytes from |data| to |sha| and returns 1. */
228 OPENSSL_EXPORT int SHA512_Update(SHA512_CTX *sha, const void *data, size_t len);
229 
230 /* SHA512_Final adds the final padding to |sha| and writes the resulting digest
231  * to |md|, which must have at least |SHA512_DIGEST_LENGTH| bytes of space. It
232  * returns one on success and zero on programmer error. */
234 
235 /* SHA512 writes the digest of |len| bytes from |data| to |out| and returns
236  * |out|. There must be at least |SHA512_DIGEST_LENGTH| bytes of space in
237  * |out|. */
239 
240 /* SHA512_Transform is a low-level function that performs a single, SHA-512
241  * block transformation using the state from |sha| and |SHA512_CBLOCK| bytes
242  * from |block|. */
244 
248  union {
249  uint64_t d[16];
250  uint8_t p[128];
251  } u;
252  unsigned num, md_len;
253 };
254 
255 
256 #if defined(__cplusplus)
257 } /* extern C */
258 #endif
259 
260 #endif /* OPENSSL_HEADER_SHA_H */
unsigned long long uint64_t
Definition: ptypes.h:120
OPENSSL_EXPORT int SHA224_Update(SHA256_CTX *sha, const void *data, size_t len)
Definition: sha256.c:128
DOMString p
Definition: WebCryptoAPI.idl:116
uint32_t h0
Definition: sha.h:110
unsigned int uint32_t
Definition: ptypes.h:105
OPENSSL_EXPORT int SHA1_Final(uint8_t *md, SHA_CTX *sha)
OPENSSL_EXPORT pem_password_cb void * u
Definition: pem.h:398
OPENSSL_EXPORT void SHA1_Transform(SHA_CTX *sha, const uint8_t *block)
OPENSSL_EXPORT int SHA256_Final(uint8_t *md, SHA256_CTX *sha)
unsigned num
Definition: sha.h:252
unsigned num
Definition: sha.h:182
OPENSSL_EXPORT int SHA1_Update(SHA_CTX *sha, const void *data, size_t len)
uint64_t Nl
Definition: sha.h:247
OPENSSL_EXPORT int SHA256_Update(SHA256_CTX *sha, const void *data, size_t len)
OPENSSL_EXPORT uint8_t * SHA512(const uint8_t *data, size_t len, uint8_t *out)
Definition: sha512.c:138
Definition: sha.h:101
OPENSSL_EXPORT int SHA512_Update(SHA512_CTX *sha, const void *data, size_t len)
Definition: sha512.c:177
OPENSSL_EXPORT const ASN1_OBJECT int const unsigned char int len
Definition: x509.h:1053
uint32_t h1
Definition: sha.h:111
int int * out
Definition: gcc-loops.cpp:206
#define OPENSSL_EXPORT
Definition: base.h:160
OPENSSL_EXPORT int SHA224_Init(SHA256_CTX *sha)
Definition: sha256.c:70
OPENSSL_EXPORT int SHA1_Init(SHA_CTX *sha)
Definition: sha1.c:70
unsigned char uint8_t
Definition: ptypes.h:89
uint32_t Nl
Definition: sha.h:118
uint32_t h2
Definition: sha.h:112
#define SHA_CBLOCK
Definition: sha.h:71
OPENSSL_EXPORT uint8_t * SHA384(const uint8_t *data, size_t len, uint8_t *out)
Definition: sha512.c:122
OPENSSL_EXPORT int SHA512_Init(SHA512_CTX *sha)
Definition: sha512.c:105
OPENSSL_EXPORT int SHA224_Final(uint8_t *md, SHA256_CTX *sha)
Definition: sha256.c:132
OPENSSL_EXPORT uint8_t * SHA224(const uint8_t *data, size_t len, uint8_t *out)
Definition: sha256.c:98
Definition: xmlparse.c:217
OPENSSL_EXPORT int SHA384_Init(SHA512_CTX *sha)
Definition: sha512.c:87
Definition: sha.h:178
EGLStreamKHR EGLint EGLint EGLint const void * data
Definition: eglext.h:984
OPENSSL_EXPORT void SHA512_Transform(SHA512_CTX *sha, const uint8_t *block)
Definition: sha512.c:167
OPENSSL_EXPORT int SHA512_Final(uint8_t *md, SHA512_CTX *sha)
Definition: sha512.c:237
GLfloat GLfloat GLfloat GLfloat h
Definition: gl2ext.h:3060
#define SHA256_CBLOCK
Definition: sha.h:152
OPENSSL_EXPORT uint8_t * SHA256(const uint8_t *data, size_t len, uint8_t *out)
Definition: sha256.c:113
OPENSSL_EXPORT int SHA384_Final(uint8_t *md, SHA512_CTX *sha)
Definition: sha512.c:159
OPENSSL_EXPORT int SHA384_Update(SHA512_CTX *sha, const void *data, size_t len)
Definition: sha512.c:163
OPENSSL_EXPORT int SHA256_Init(SHA256_CTX *sha)
Definition: sha256.c:84
unsigned num
Definition: sha.h:120
Definition: sha.h:245
uint32_t Nh
Definition: sha.h:118
uint32_t Nl
Definition: sha.h:180
OPENSSL_EXPORT uint8_t * SHA1(const uint8_t *data, size_t len, uint8_t *out)
Definition: sha1.c:80
#define d
Definition: float-mm.c:30
uint32_t h3
Definition: sha.h:113
OPENSSL_EXPORT void SHA256_Transform(SHA256_CTX *sha, const uint8_t *block)
uint32_t h4
Definition: sha.h:114
OPENSSL_EXPORT void SHA384_Transform(SHA512_CTX *sha, const uint8_t *block)