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_224_init nettle_sha3_224_init
46 #define sha3_224_update nettle_sha3_224_update
47 #define sha3_224_digest nettle_sha3_224_digest
48 #define sha3_256_init nettle_sha3_256_init
49 #define sha3_256_update nettle_sha3_256_update
50 #define sha3_256_digest nettle_sha3_256_digest
51 #define sha3_384_init nettle_sha3_384_init
52 #define sha3_384_update nettle_sha3_384_update
53 #define sha3_384_digest nettle_sha3_384_digest
54 #define sha3_512_init nettle_sha3_512_init
55 #define sha3_512_update nettle_sha3_512_update
56 #define sha3_512_digest nettle_sha3_512_digest
58 /* Indicates that SHA3 is the NIST FIPS 202 version. */
59 #define NETTLE_SHA3_FIPS202 1
61 /* The sha3 state is a 5x5 matrix of 64-bit words. In the notation of
62 Keccak description, S[x,y] is element x + 5*y, so if x is
63 interpreted as the row index and y the column index, it is stored
64 in column-major order. */
65 #define SHA3_STATE_LENGTH 25
67 /* The "width" is 1600 bits or 200 octets */
70 uint64_t a[SHA3_STATE_LENGTH];
74 sha3_permute (struct sha3_state *state);
76 /* The "capacity" is set to 2*(digest size), 512 bits or 64 octets.
77 The "rate" is the width - capacity, or width - 2 * (digest
80 #define SHA3_224_DIGEST_SIZE 28
81 #define SHA3_224_BLOCK_SIZE 144
83 #define SHA3_256_DIGEST_SIZE 32
84 #define SHA3_256_BLOCK_SIZE 136
86 #define SHA3_384_DIGEST_SIZE 48
87 #define SHA3_384_BLOCK_SIZE 104
89 #define SHA3_512_DIGEST_SIZE 64
90 #define SHA3_512_BLOCK_SIZE 72
92 /* For backwards compatibility */
93 #define SHA3_224_DATA_SIZE SHA3_224_BLOCK_SIZE
94 #define SHA3_256_DATA_SIZE SHA3_256_BLOCK_SIZE
95 #define SHA3_384_DATA_SIZE SHA3_384_BLOCK_SIZE
96 #define SHA3_512_DATA_SIZE SHA3_512_BLOCK_SIZE
100 struct sha3_state state;
102 uint8_t block[SHA3_224_BLOCK_SIZE];
106 sha3_224_init (struct sha3_224_ctx *ctx);
109 sha3_224_update (struct sha3_224_ctx *ctx,
111 const uint8_t *data);
114 sha3_224_digest(struct sha3_224_ctx *ctx,
120 struct sha3_state state;
122 uint8_t block[SHA3_256_BLOCK_SIZE];
126 sha3_256_init (struct sha3_256_ctx *ctx);
129 sha3_256_update (struct sha3_256_ctx *ctx,
131 const uint8_t *data);
134 sha3_256_digest(struct sha3_256_ctx *ctx,
140 struct sha3_state state;
142 uint8_t block[SHA3_384_BLOCK_SIZE];
146 sha3_384_init (struct sha3_384_ctx *ctx);
149 sha3_384_update (struct sha3_384_ctx *ctx,
151 const uint8_t *data);
154 sha3_384_digest(struct sha3_384_ctx *ctx,
160 struct sha3_state state;
162 uint8_t block[SHA3_512_BLOCK_SIZE];
166 sha3_512_init (struct sha3_512_ctx *ctx);
169 sha3_512_update (struct sha3_512_ctx *ctx,
171 const uint8_t *data);
174 sha3_512_digest(struct sha3_512_ctx *ctx,
182 #endif /* NETTLE_SHA3_H_INCLUDED */