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,
95 /* SHA224, a truncated SHA256 with different initial state. */
97 #define SHA224_DIGEST_SIZE 28
98 #define SHA224_BLOCK_SIZE SHA256_BLOCK_SIZE
99 #define sha224_ctx sha256_ctx
102 sha224_init(struct sha256_ctx *ctx);
104 #define sha224_update nettle_sha256_update
107 sha224_digest(struct sha256_ctx *ctx,
114 #define SHA512_DIGEST_SIZE 64
115 #define SHA512_BLOCK_SIZE 128
117 /* Digest is kept internally as 8 64-bit words. */
118 #define _SHA512_DIGEST_LENGTH 8
122 uint64_t state[_SHA512_DIGEST_LENGTH]; /* State variables */
123 uint64_t count_low, count_high; /* 128-bit block count */
124 uint8_t block[SHA512_BLOCK_SIZE]; /* SHA512 data buffer */
125 unsigned int index; /* index into buffer */
129 sha512_init(struct sha512_ctx *ctx);
132 sha512_update(struct sha512_ctx *ctx,
134 const uint8_t *data);
137 sha512_digest(struct sha512_ctx *ctx,
142 /* SHA384, a truncated SHA512 with different initial state. */
144 #define SHA384_DIGEST_SIZE 48
145 #define SHA384_BLOCK_SIZE SHA512_BLOCK_SIZE
146 #define sha384_ctx sha512_ctx
149 sha384_init(struct sha512_ctx *ctx);
151 #define sha384_update nettle_sha512_update
154 sha384_digest(struct sha512_ctx *ctx,
159 /* SHA512_224 and SHA512_256, two truncated versions of SHA512
160 with different initial states. */
162 #define SHA512_224_DIGEST_SIZE 28
163 #define SHA512_224_BLOCK_SIZE SHA512_BLOCK_SIZE
164 #define sha512_224_ctx sha512_ctx
167 sha512_224_init(struct sha512_224_ctx *ctx);
169 #define sha512_224_update nettle_sha512_update
172 sha512_224_digest(struct sha512_224_ctx *ctx,
176 #define SHA512_256_DIGEST_SIZE 32
177 #define SHA512_256_BLOCK_SIZE SHA512_BLOCK_SIZE
178 #define sha512_256_ctx sha512_ctx
181 sha512_256_init(struct sha512_256_ctx *ctx);
183 #define sha512_256_update nettle_sha512_update
186 sha512_256_digest(struct sha512_256_ctx *ctx,
194 #endif /* NETTLE_SHA2_H_INCLUDED */