3 * The sha1 and sha256 hash functions.
6 /* nettle, low-level cryptographics library
8 * Copyright (C) 2001 Niels Möller
10 * The nettle library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or (at your
13 * option) any later version.
15 * The nettle library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with the nettle library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26 #ifndef NETTLE_SHA_H_INCLUDED
27 #define NETTLE_SHA_H_INCLUDED
29 #include "nettle-types.h"
36 #define sha1_init nettle_sha1_init
37 #define sha1_update nettle_sha1_update
38 #define sha1_digest nettle_sha1_digest
39 #define sha224_init nettle_sha224_init
40 #define sha224_digest nettle_sha224_digest
41 #define sha256_init nettle_sha256_init
42 #define sha256_update nettle_sha256_update
43 #define sha256_digest nettle_sha256_digest
44 #define sha384_init nettle_sha384_init
45 #define sha384_digest nettle_sha384_digest
46 #define sha512_init nettle_sha512_init
47 #define sha512_update nettle_sha512_update
48 #define sha512_digest nettle_sha512_digest
52 #define SHA1_DIGEST_SIZE 20
53 #define SHA1_DATA_SIZE 64
55 /* Digest is kept internally as 5 32-bit words. */
56 #define _SHA1_DIGEST_LENGTH 5
60 uint32_t digest[_SHA1_DIGEST_LENGTH]; /* Message digest */
61 uint32_t count_low, count_high; /* 64-bit block count */
62 uint8_t block[SHA1_DATA_SIZE]; /* SHA1 data buffer */
63 unsigned int index; /* index into buffer */
67 sha1_init(struct sha1_ctx *ctx);
70 sha1_update(struct sha1_ctx *ctx,
75 sha1_digest(struct sha1_ctx *ctx,
79 /* Internal compression function. STATE points to 5 uint32_t words,
80 and DATA points to 64 bytes of input data, possibly unaligned. */
82 _nettle_sha1_compress(uint32_t *state, const uint8_t *data);
86 #define SHA256_DIGEST_SIZE 32
87 #define SHA256_DATA_SIZE 64
89 /* Digest is kept internally as 8 32-bit words. */
90 #define _SHA256_DIGEST_LENGTH 8
94 uint32_t state[_SHA256_DIGEST_LENGTH]; /* State variables */
95 uint32_t count_low, count_high; /* 64-bit block count */
96 uint8_t block[SHA256_DATA_SIZE]; /* SHA256 data buffer */
97 unsigned int index; /* index into buffer */
101 sha256_init(struct sha256_ctx *ctx);
104 sha256_update(struct sha256_ctx *ctx,
106 const uint8_t *data);
109 sha256_digest(struct sha256_ctx *ctx,
113 /* Internal compression function. STATE points to 8 uint32_t words,
114 DATA points to 64 bytes of input data, possibly unaligned, and K
115 points to the table of constants. */
117 _nettle_sha256_compress(uint32_t *state, const uint8_t *data, const uint32_t *k);
120 /* SHA224, a truncated SHA256 with different initial state. */
122 #define SHA224_DIGEST_SIZE 28
123 #define SHA224_DATA_SIZE SHA256_DATA_SIZE
124 #define sha224_ctx sha256_ctx
127 sha224_init(struct sha256_ctx *ctx);
129 #define sha224_update nettle_sha256_update
132 sha224_digest(struct sha256_ctx *ctx,
139 #define SHA512_DIGEST_SIZE 64
140 #define SHA512_DATA_SIZE 128
142 /* Digest is kept internally as 8 64-bit words. */
143 #define _SHA512_DIGEST_LENGTH 8
147 uint64_t state[_SHA512_DIGEST_LENGTH]; /* State variables */
148 uint64_t count_low, count_high; /* 128-bit block count */
149 uint8_t block[SHA512_DATA_SIZE]; /* SHA512 data buffer */
150 unsigned int index; /* index into buffer */
154 sha512_init(struct sha512_ctx *ctx);
157 sha512_update(struct sha512_ctx *ctx,
159 const uint8_t *data);
162 sha512_digest(struct sha512_ctx *ctx,
166 /* Internal compression function. STATE points to 8 uint64_t words,
167 DATA points to 128 bytes of input data, possibly unaligned, and K
168 points to the table of constants. */
170 _nettle_sha512_compress(uint64_t *state, const uint8_t *data, const uint64_t *k);
173 /* SHA384, a truncated SHA512 with different initial state. */
175 #define SHA384_DIGEST_SIZE 48
176 #define SHA384_DATA_SIZE SHA512_DATA_SIZE
177 #define sha384_ctx sha512_ctx
180 sha384_init(struct sha512_ctx *ctx);
182 #define sha384_update nettle_sha512_update
185 sha384_digest(struct sha512_ctx *ctx,
193 #endif /* NETTLE_SHA_H_INCLUDED */