3 The sha3 hash function (aka Keccak).
5 Copyright (C) 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_SHA3_H_INCLUDED
35 #define NETTLE_SHA3_H_INCLUDED
37 #include "nettle-types.h"
44 #define sha3_permute nettle_sha3_permute
45 #define _sha3_update _nettle_sha3_update
46 #define _sha3_pad _nettle_sha3_pad
47 #define sha3_224_init nettle_sha3_224_init
48 #define sha3_224_update nettle_sha3_224_update
49 #define sha3_224_digest nettle_sha3_224_digest
50 #define sha3_256_init nettle_sha3_256_init
51 #define sha3_256_update nettle_sha3_256_update
52 #define sha3_256_digest nettle_sha3_256_digest
53 #define sha3_384_init nettle_sha3_384_init
54 #define sha3_384_update nettle_sha3_384_update
55 #define sha3_384_digest nettle_sha3_384_digest
56 #define sha3_512_init nettle_sha3_512_init
57 #define sha3_512_update nettle_sha3_512_update
58 #define sha3_512_digest nettle_sha3_512_digest
60 /* Indicates that SHA3 is the NIST FIPS 202 version. */
61 #define NETTLE_SHA3_FIPS202 1
63 /* The sha3 state is a 5x5 matrix of 64-bit words. In the notation of
64 Keccak description, S[x,y] is element x + 5*y, so if x is
65 interpreted as the row index and y the column index, it is stored
66 in column-major order. */
67 #define SHA3_STATE_LENGTH 25
69 /* The "width" is 1600 bits or 200 octets */
72 uint64_t a[SHA3_STATE_LENGTH];
76 sha3_permute (struct sha3_state *state);
79 _sha3_update (struct sha3_state *state,
80 unsigned block_size, uint8_t *block,
82 size_t length, const uint8_t *data);
84 _sha3_pad (struct sha3_state *state,
85 unsigned block_size, uint8_t *block, unsigned pos);
87 /* The "capacity" is set to 2*(digest size), 512 bits or 64 octets.
88 The "rate" is the width - capacity, or width - 2 * (digest
91 #define SHA3_224_DIGEST_SIZE 28
92 #define SHA3_224_BLOCK_SIZE 144
94 #define SHA3_256_DIGEST_SIZE 32
95 #define SHA3_256_BLOCK_SIZE 136
97 #define SHA3_384_DIGEST_SIZE 48
98 #define SHA3_384_BLOCK_SIZE 104
100 #define SHA3_512_DIGEST_SIZE 64
101 #define SHA3_512_BLOCK_SIZE 72
103 /* For backwards compatibility */
104 #define SHA3_224_DATA_SIZE SHA3_224_BLOCK_SIZE
105 #define SHA3_256_DATA_SIZE SHA3_256_BLOCK_SIZE
106 #define SHA3_384_DATA_SIZE SHA3_384_BLOCK_SIZE
107 #define SHA3_512_DATA_SIZE SHA3_512_BLOCK_SIZE
111 struct sha3_state state;
113 uint8_t block[SHA3_224_BLOCK_SIZE];
117 sha3_224_init (struct sha3_224_ctx *ctx);
120 sha3_224_update (struct sha3_224_ctx *ctx,
122 const uint8_t *data);
125 sha3_224_digest(struct sha3_224_ctx *ctx,
131 struct sha3_state state;
133 uint8_t block[SHA3_256_BLOCK_SIZE];
137 sha3_256_init (struct sha3_256_ctx *ctx);
140 sha3_256_update (struct sha3_256_ctx *ctx,
142 const uint8_t *data);
145 sha3_256_digest(struct sha3_256_ctx *ctx,
151 struct sha3_state state;
153 uint8_t block[SHA3_384_BLOCK_SIZE];
157 sha3_384_init (struct sha3_384_ctx *ctx);
160 sha3_384_update (struct sha3_384_ctx *ctx,
162 const uint8_t *data);
165 sha3_384_digest(struct sha3_384_ctx *ctx,
171 struct sha3_state state;
173 uint8_t block[SHA3_512_BLOCK_SIZE];
177 sha3_512_init (struct sha3_512_ctx *ctx);
180 sha3_512_update (struct sha3_512_ctx *ctx,
182 const uint8_t *data);
185 sha3_512_digest(struct sha3_512_ctx *ctx,
193 #endif /* NETTLE_SHA3_H_INCLUDED */