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 */
59 uint64_t a
[SHA3_STATE_LENGTH
];
63 sha3_permute(struct sha3_state
*state
);
66 _sha3_update(struct sha3_state
*state
,
67 unsigned block_size
, uint8_t * block
,
68 unsigned pos
, unsigned length
, const uint8_t * data
);
70 _sha3_pad(struct sha3_state
*state
,
71 unsigned block_size
, uint8_t * block
, unsigned pos
);
73 /* The "capacity" is set to 2*(digest size), 512 bits or 64 octets.
74 The "rate" is the width - capacity, or width - 2 * (digest
77 #define SHA3_224_DIGEST_SIZE 28
78 #define SHA3_224_DATA_SIZE 144
80 #define SHA3_256_DIGEST_SIZE 32
81 #define SHA3_256_DATA_SIZE 136
83 #define SHA3_384_DIGEST_SIZE 48
84 #define SHA3_384_DATA_SIZE 104
86 #define SHA3_512_DIGEST_SIZE 64
87 #define SHA3_512_DATA_SIZE 72
91 struct sha3_state state
;
93 uint8_t block
[SHA3_224_DATA_SIZE
];
97 sha3_224_init(struct sha3_224_ctx
*ctx
);
100 sha3_224_update(struct sha3_224_ctx
*ctx
,
101 unsigned length
, const uint8_t * data
);
104 sha3_224_digest(struct sha3_224_ctx
*ctx
,
105 unsigned length
, uint8_t * digest
);
107 struct sha3_256_ctx
{
108 struct sha3_state state
;
110 uint8_t block
[SHA3_256_DATA_SIZE
];
114 sha3_256_init(struct sha3_256_ctx
*ctx
);
117 sha3_256_update(struct sha3_256_ctx
*ctx
,
118 unsigned length
, const uint8_t * data
);
121 sha3_256_digest(struct sha3_256_ctx
*ctx
,
122 unsigned length
, uint8_t * digest
);
124 struct sha3_384_ctx
{
125 struct sha3_state state
;
127 uint8_t block
[SHA3_384_DATA_SIZE
];
131 sha3_384_init(struct sha3_384_ctx
*ctx
);
134 sha3_384_update(struct sha3_384_ctx
*ctx
,
135 unsigned length
, const uint8_t * data
);
138 sha3_384_digest(struct sha3_384_ctx
*ctx
,
139 unsigned length
, uint8_t * digest
);
141 struct sha3_512_ctx
{
142 struct sha3_state state
;
144 uint8_t block
[SHA3_512_DATA_SIZE
];
148 sha3_512_init(struct sha3_512_ctx
*ctx
);
151 sha3_512_update(struct sha3_512_ctx
*ctx
,
152 unsigned length
, const uint8_t * data
);
155 sha3_512_digest(struct sha3_512_ctx
*ctx
,
156 unsigned length
, uint8_t * digest
);
161 #endif /* NETTLE_SHA3_H_INCLUDED */