3 * The sha3 hash function (aka Keccak).
6 /* nettle, low-level cryptographics library
8 * Copyright (C) 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_SHA3_H_INCLUDED
27 #define NETTLE_SHA3_H_INCLUDED
29 #include "nettle-types.h"
35 #define sha3_permute nettle_sha3_permute
36 #define _sha3_update _nettle_sha3_update
37 #define _sha3_pad _nettle_sha3_pad
38 #define sha3_224_init nettle_sha3_224_init
39 #define sha3_224_update nettle_sha3_224_update
40 #define sha3_224_digest nettle_sha3_224_digest
41 #define sha3_256_init nettle_sha3_256_init
42 #define sha3_256_update nettle_sha3_256_update
43 #define sha3_256_digest nettle_sha3_256_digest
44 #define sha3_384_init nettle_sha3_384_init
45 #define sha3_384_update nettle_sha3_384_update
46 #define sha3_384_digest nettle_sha3_384_digest
47 #define sha3_512_init nettle_sha3_512_init
48 #define sha3_512_update nettle_sha3_512_update
49 #define sha3_512_digest nettle_sha3_512_digest
51 /* The sha3 state is a 5x5 matrix of 64-bit words. In the notation of
52 Keccak description, S[x,y] is element x + 5*y, so if x is
53 interpreted as the row index and y the column index, it is stored
54 in column-major order. */
55 #define SHA3_STATE_LENGTH 25
57 /* The "width" is 1600 bits or 200 octets */
60 uint64_t a
[SHA3_STATE_LENGTH
];
64 sha3_permute (struct sha3_state
*state
);
67 _sha3_update (struct sha3_state
*state
,
68 unsigned block_size
, uint8_t *block
,
70 unsigned length
, const uint8_t *data
);
72 _sha3_pad (struct sha3_state
*state
,
73 unsigned block_size
, uint8_t *block
, unsigned pos
);
75 /* The "capacity" is set to 2*(digest size), 512 bits or 64 octets.
76 The "rate" is the width - capacity, or width - 2 * (digest
79 #define SHA3_224_DIGEST_SIZE 28
80 #define SHA3_224_DATA_SIZE 144
82 #define SHA3_256_DIGEST_SIZE 32
83 #define SHA3_256_DATA_SIZE 136
85 #define SHA3_384_DIGEST_SIZE 48
86 #define SHA3_384_DATA_SIZE 104
88 #define SHA3_512_DIGEST_SIZE 64
89 #define SHA3_512_DATA_SIZE 72
94 struct sha3_state state
;
96 uint8_t block
[SHA3_224_DATA_SIZE
];
100 sha3_224_init (struct sha3_224_ctx
*ctx
);
103 sha3_224_update (struct sha3_224_ctx
*ctx
,
105 const uint8_t *data
);
108 sha3_224_digest(struct sha3_224_ctx
*ctx
,
114 struct sha3_state state
;
116 uint8_t block
[SHA3_256_DATA_SIZE
];
120 sha3_256_init (struct sha3_256_ctx
*ctx
);
123 sha3_256_update (struct sha3_256_ctx
*ctx
,
125 const uint8_t *data
);
128 sha3_256_digest(struct sha3_256_ctx
*ctx
,
134 struct sha3_state state
;
136 uint8_t block
[SHA3_384_DATA_SIZE
];
140 sha3_384_init (struct sha3_384_ctx
*ctx
);
143 sha3_384_update (struct sha3_384_ctx
*ctx
,
145 const uint8_t *data
);
148 sha3_384_digest(struct sha3_384_ctx
*ctx
,
154 struct sha3_state state
;
156 uint8_t block
[SHA3_512_DATA_SIZE
];
160 sha3_512_init (struct sha3_512_ctx
*ctx
);
163 sha3_512_update (struct sha3_512_ctx
*ctx
,
165 const uint8_t *data
);
168 sha3_512_digest(struct sha3_512_ctx
*ctx
,
176 #endif /* NETTLE_SHA3_H_INCLUDED */