3
* The sha2 family of hash functions.
6
/* nettle, low-level cryptographics library
8
* Copyright (C) 2001, 2012 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., 51 Franklin Street, Fifth Floor, Boston,
26
#ifndef NETTLE_SHA2_H_INCLUDED
27
#define NETTLE_SHA2_H_INCLUDED
29
#include "nettle-types.h"
36
#define sha224_init nettle_sha224_init
37
#define sha224_digest nettle_sha224_digest
38
#define sha256_init nettle_sha256_init
39
#define sha256_update nettle_sha256_update
40
#define sha256_digest nettle_sha256_digest
41
#define sha384_init nettle_sha384_init
42
#define sha384_digest nettle_sha384_digest
43
#define sha512_init nettle_sha512_init
44
#define sha512_update nettle_sha512_update
45
#define sha512_digest nettle_sha512_digest
49
#define SHA256_DIGEST_SIZE 32
50
#define SHA256_DATA_SIZE 64
52
/* Digest is kept internally as 8 32-bit words. */
53
#define _SHA256_DIGEST_LENGTH 8
57
uint32_t state[_SHA256_DIGEST_LENGTH]; /* State variables */
58
uint32_t count_low, count_high; /* 64-bit block count */
59
uint8_t block[SHA256_DATA_SIZE]; /* SHA256 data buffer */
60
unsigned int index; /* index into buffer */
64
sha256_init(struct sha256_ctx *ctx);
67
sha256_update(struct sha256_ctx *ctx,
72
sha256_digest(struct sha256_ctx *ctx,
76
/* Internal compression function. STATE points to 8 uint32_t words,
77
DATA points to 64 bytes of input data, possibly unaligned, and K
78
points to the table of constants. */
80
_nettle_sha256_compress(uint32_t *state, const uint8_t *data, const uint32_t *k);
83
/* SHA224, a truncated SHA256 with different initial state. */
85
#define SHA224_DIGEST_SIZE 28
86
#define SHA224_DATA_SIZE SHA256_DATA_SIZE
87
#define sha224_ctx sha256_ctx
90
sha224_init(struct sha256_ctx *ctx);
92
#define sha224_update nettle_sha256_update
95
sha224_digest(struct sha256_ctx *ctx,
102
#define SHA512_DIGEST_SIZE 64
103
#define SHA512_DATA_SIZE 128
105
/* Digest is kept internally as 8 64-bit words. */
106
#define _SHA512_DIGEST_LENGTH 8
110
uint64_t state[_SHA512_DIGEST_LENGTH]; /* State variables */
111
uint64_t count_low, count_high; /* 128-bit block count */
112
uint8_t block[SHA512_DATA_SIZE]; /* SHA512 data buffer */
113
unsigned int index; /* index into buffer */
117
sha512_init(struct sha512_ctx *ctx);
120
sha512_update(struct sha512_ctx *ctx,
122
const uint8_t *data);
125
sha512_digest(struct sha512_ctx *ctx,
129
/* Internal compression function. STATE points to 8 uint64_t words,
130
DATA points to 128 bytes of input data, possibly unaligned, and K
131
points to the table of constants. */
133
_nettle_sha512_compress(uint64_t *state, const uint8_t *data, const uint64_t *k);
136
/* SHA384, a truncated SHA512 with different initial state. */
138
#define SHA384_DIGEST_SIZE 48
139
#define SHA384_DATA_SIZE SHA512_DATA_SIZE
140
#define sha384_ctx sha512_ctx
143
sha384_init(struct sha512_ctx *ctx);
145
#define sha384_update nettle_sha512_update
148
sha384_digest(struct sha512_ctx *ctx,
156
#endif /* NETTLE_SHA2_H_INCLUDED */