1 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
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.
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).
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.
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
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)"
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
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.] */
57 #ifndef OPENSSL_HEADER_SHA_H
58 #define OPENSSL_HEADER_SHA_H
60 #include <openssl/base.h>
62 #if defined(__cplusplus)
70 /* SHA_CBLOCK is the block size of SHA-1. */
73 /* SHA_DIGEST_LENGTH is the length of a SHA-1 digest. */
74 #define SHA_DIGEST_LENGTH 20
76 /* TODO(fork): remove */
78 #define SHA_LONG uint32_t
80 /* SHA1_Init initialises |sha| and returns one. */
81 OPENSSL_EXPORT int SHA1_Init(SHA_CTX *sha);
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);
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
89 OPENSSL_EXPORT int SHA1_Final(uint8_t *md, SHA_CTX *sha);
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
94 OPENSSL_EXPORT uint8_t *SHA1(const uint8_t *data, size_t len, uint8_t *out);
96 /* SHA1_Transform is a low-level function that performs a single, SHA-1 block
97 * transformation using the state from |sha| and 64 bytes from |block|. */
98 OPENSSL_EXPORT void SHA1_Transform(SHA_CTX *sha, const uint8_t *block);
100 struct sha_state_st {
101 uint32_t h0, h1, h2, h3, h4;
110 /* SHA224_CBLOCK is the block size of SHA-224. */
111 #define SHA224_CBLOCK 64
113 /* SHA224_DIGEST_LENGTH is the length of a SHA-224 digest. */
114 #define SHA224_DIGEST_LENGTH 28
116 /* SHA224_Init initialises |sha| and returns 1. */
117 OPENSSL_EXPORT int SHA224_Init(SHA256_CTX *sha);
119 /* SHA224_Update adds |len| bytes from |data| to |sha|. */
120 OPENSSL_EXPORT int SHA224_Update(SHA256_CTX *sha, const void *data, size_t len);
122 /* SHA224_Final adds the final padding to |sha| and writes the resulting digest
123 * to |md|, which must have at least |SHA_DIGEST_LENGTH| bytes of space. */
124 OPENSSL_EXPORT int SHA224_Final(uint8_t *md, SHA256_CTX *sha);
126 /* SHA224 writes the digest of |len| bytes from |data| to |out| and returns
127 * |out|. There must be at least |SHA_DIGEST_LENGTH| bytes of space in
129 OPENSSL_EXPORT uint8_t *SHA224(const uint8_t *data, size_t len, uint8_t *out);
134 /* SHA256_CBLOCK is the block size of SHA-256. */
135 #define SHA256_CBLOCK 64
137 /* SHA256_DIGEST_LENGTH is the length of a SHA-256 digest. */
138 #define SHA256_DIGEST_LENGTH 32
140 /* SHA256_Init initialises |sha| and returns 1. */
141 OPENSSL_EXPORT int SHA256_Init(SHA256_CTX *sha);
143 /* SHA256_Update adds |len| bytes from |data| to |sha|. */
144 OPENSSL_EXPORT int SHA256_Update(SHA256_CTX *sha, const void *data, size_t len);
146 /* SHA256_Final adds the final padding to |sha| and writes the resulting digest
147 * to |md|, which must have at least |SHA_DIGEST_LENGTH| bytes of space. */
148 OPENSSL_EXPORT int SHA256_Final(uint8_t *md, SHA256_CTX *sha);
150 /* SHA256 writes the digest of |len| bytes from |data| to |out| and returns
151 * |out|. There must be at least |SHA_DIGEST_LENGTH| bytes of space in
153 OPENSSL_EXPORT uint8_t *SHA256(const uint8_t *data, size_t len, uint8_t *out);
155 /* SHA256_Transform is a low-level function that performs a single, SHA-1 block
156 * transformation using the state from |sha| and 64 bytes from |block|. */
157 OPENSSL_EXPORT void SHA256_Transform(SHA256_CTX *sha, const uint8_t *data);
159 struct sha256_state_st {
163 unsigned int num, md_len;
169 /* SHA384_CBLOCK is the block size of SHA-384. */
170 #define SHA384_CBLOCK 128
172 /* SHA384_DIGEST_LENGTH is the length of a SHA-384 digest. */
173 #define SHA384_DIGEST_LENGTH 48
175 /* SHA384_Init initialises |sha| and returns 1. */
176 OPENSSL_EXPORT int SHA384_Init(SHA512_CTX *sha);
178 /* SHA384_Update adds |len| bytes from |data| to |sha|. */
179 OPENSSL_EXPORT int SHA384_Update(SHA512_CTX *sha, const void *data, size_t len);
181 /* SHA384_Final adds the final padding to |sha| and writes the resulting digest
182 * to |md|, which must have at least |SHA_DIGEST_LENGTH| bytes of space. */
183 OPENSSL_EXPORT int SHA384_Final(uint8_t *md, SHA512_CTX *sha);
185 /* SHA384 writes the digest of |len| bytes from |data| to |out| and returns
186 * |out|. There must be at least |SHA_DIGEST_LENGTH| bytes of space in
188 OPENSSL_EXPORT uint8_t *SHA384(const uint8_t *data, size_t len, uint8_t *out);
190 /* SHA384_Transform is a low-level function that performs a single, SHA-1 block
191 * transformation using the state from |sha| and 64 bytes from |block|. */
192 OPENSSL_EXPORT void SHA384_Transform(SHA512_CTX *sha, const uint8_t *data);
197 /* SHA512_CBLOCK is the block size of SHA-512. */
198 #define SHA512_CBLOCK 128
200 /* SHA512_DIGEST_LENGTH is the length of a SHA-512 digest. */
201 #define SHA512_DIGEST_LENGTH 64
203 /* SHA512_Init initialises |sha| and returns 1. */
204 OPENSSL_EXPORT int SHA512_Init(SHA512_CTX *sha);
206 /* SHA512_Update adds |len| bytes from |data| to |sha|. */
207 OPENSSL_EXPORT int SHA512_Update(SHA512_CTX *sha, const void *data, size_t len);
209 /* SHA512_Final adds the final padding to |sha| and writes the resulting digest
210 * to |md|, which must have at least |SHA_DIGEST_LENGTH| bytes of space. */
211 OPENSSL_EXPORT int SHA512_Final(uint8_t *md, SHA512_CTX *sha);
213 /* SHA512 writes the digest of |len| bytes from |data| to |out| and returns
214 * |out|. There must be at least |SHA_DIGEST_LENGTH| bytes of space in
216 OPENSSL_EXPORT uint8_t *SHA512(const uint8_t *data, size_t len, uint8_t *out);
218 /* SHA512_Transform is a low-level function that performs a single, SHA-1 block
219 * transformation using the state from |sha| and 64 bytes from |block|. */
220 OPENSSL_EXPORT void SHA512_Transform(SHA512_CTX *sha, const uint8_t *data);
222 struct sha512_state_st {
229 unsigned int num, md_len;
233 #if defined(__cplusplus)
237 #endif /* OPENSSL_HEADER_SHA_H */