3 The sha2 family of hash functions.
5 Copyright (C) 2001, 2012 Niels Möller
7 This file is part of GNU Nettle.
9 GNU Nettle is free software: you can redistribute it and/or
10 modify it under the terms of either:
12 * the GNU Lesser General Public License as published by the Free
13 Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
18 * the GNU General Public License as published by the Free
19 Software Foundation; either version 2 of the License, or (at your
20 option) any later version.
22 or both in parallel, as here.
24 GNU Nettle is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 General Public License for more details.
29 You should have received copies of the GNU General Public License and
30 the GNU Lesser General Public License along with this program. If
31 not, see http://www.gnu.org/licenses/.
34 #ifndef NETTLE_SHA2_H_INCLUDED
35 #define NETTLE_SHA2_H_INCLUDED
37 #include "nettle-types.h"
44 #define sha224_init nettle_sha224_init
45 #define sha224_digest nettle_sha224_digest
46 #define sha256_init nettle_sha256_init
47 #define sha256_update nettle_sha256_update
48 #define sha256_digest nettle_sha256_digest
49 #define sha384_init nettle_sha384_init
50 #define sha384_digest nettle_sha384_digest
51 #define sha512_init nettle_sha512_init
52 #define sha512_update nettle_sha512_update
53 #define sha512_digest nettle_sha512_digest
54 #define sha512_224_init nettle_sha512_224_init
55 #define sha512_224_digest nettle_sha512_224_digest
56 #define sha512_256_init nettle_sha512_256_init
57 #define sha512_256_digest nettle_sha512_256_digest
59 /* For backwards compatibility */
60 #define SHA224_DATA_SIZE SHA256_BLOCK_SIZE
61 #define SHA256_DATA_SIZE SHA256_BLOCK_SIZE
62 #define SHA512_DATA_SIZE SHA512_BLOCK_SIZE
63 #define SHA384_DATA_SIZE SHA512_BLOCK_SIZE
67 #define SHA256_DIGEST_SIZE 32
68 #define SHA256_BLOCK_SIZE 64
70 /* Digest is kept internally as 8 32-bit words. */
71 #define _SHA256_DIGEST_LENGTH 8
75 uint32_t state[_SHA256_DIGEST_LENGTH]; /* State variables */
76 uint64_t count; /* 64-bit block count */
77 uint8_t block[SHA256_BLOCK_SIZE]; /* SHA256 data buffer */
78 unsigned int index; /* index into buffer */
82 sha256_init(struct sha256_ctx *ctx);
85 sha256_update(struct sha256_ctx *ctx,
90 sha256_digest(struct sha256_ctx *ctx,
94 /* Internal compression function. STATE points to 8 uint32_t words,
95 DATA points to 64 bytes of input data, possibly unaligned, and K
96 points to the table of constants. */
98 _nettle_sha256_compress(uint32_t *state, const uint8_t *data, const uint32_t *k);
101 /* SHA224, a truncated SHA256 with different initial state. */
103 #define SHA224_DIGEST_SIZE 28
104 #define SHA224_BLOCK_SIZE SHA256_BLOCK_SIZE
105 #define sha224_ctx sha256_ctx
108 sha224_init(struct sha256_ctx *ctx);
110 #define sha224_update nettle_sha256_update
113 sha224_digest(struct sha256_ctx *ctx,
120 #define SHA512_DIGEST_SIZE 64
121 #define SHA512_BLOCK_SIZE 128
123 /* Digest is kept internally as 8 64-bit words. */
124 #define _SHA512_DIGEST_LENGTH 8
128 uint64_t state[_SHA512_DIGEST_LENGTH]; /* State variables */
129 uint64_t count_low, count_high; /* 128-bit block count */
130 uint8_t block[SHA512_BLOCK_SIZE]; /* SHA512 data buffer */
131 unsigned int index; /* index into buffer */
135 sha512_init(struct sha512_ctx *ctx);
138 sha512_update(struct sha512_ctx *ctx,
140 const uint8_t *data);
143 sha512_digest(struct sha512_ctx *ctx,
147 /* Internal compression function. STATE points to 8 uint64_t words,
148 DATA points to 128 bytes of input data, possibly unaligned, and K
149 points to the table of constants. */
151 _nettle_sha512_compress(uint64_t *state, const uint8_t *data, const uint64_t *k);
154 /* SHA384, a truncated SHA512 with different initial state. */
156 #define SHA384_DIGEST_SIZE 48
157 #define SHA384_BLOCK_SIZE SHA512_BLOCK_SIZE
158 #define sha384_ctx sha512_ctx
161 sha384_init(struct sha512_ctx *ctx);
163 #define sha384_update nettle_sha512_update
166 sha384_digest(struct sha512_ctx *ctx,
171 /* SHA512_224 and SHA512_256, two truncated versions of SHA512
172 with different initial states. */
174 #define SHA512_224_DIGEST_SIZE 28
175 #define SHA512_224_BLOCK_SIZE SHA512_BLOCK_SIZE
176 #define sha512_224_ctx sha512_ctx
179 sha512_224_init(struct sha512_224_ctx *ctx);
181 #define sha512_224_update nettle_sha512_update
184 sha512_224_digest(struct sha512_224_ctx *ctx,
188 #define SHA512_256_DIGEST_SIZE 32
189 #define SHA512_256_BLOCK_SIZE SHA512_BLOCK_SIZE
190 #define sha512_256_ctx sha512_ctx
193 sha512_256_init(struct sha512_256_ctx *ctx);
195 #define sha512_256_update nettle_sha512_update
198 sha512_256_digest(struct sha512_256_ctx *ctx,
206 #endif /* NETTLE_SHA2_H_INCLUDED */