30#define LC_SHA3_SIZE_RATE(bits) ((1600 - 2 * bits) >> 3)
31#define LC_SHA3_STATE_WORDS 25
32#define LC_SHA3_STATE_SIZE (LC_SHA3_STATE_WORDS * sizeof(uint64_t))
44#define LC_SHA3_224_SIZE_DIGEST_BITS 224
45#define LC_SHA3_224_SIZE_DIGEST (LC_SHA3_224_SIZE_DIGEST_BITS >> 3)
46#define LC_SHA3_224_SIZE_BLOCK LC_SHA3_SIZE_RATE(LC_SHA3_224_SIZE_DIGEST_BITS)
48struct lc_sha3_224_state {
49 uint64_t state[LC_SHA3_STATE_WORDS];
56 uint8_t squeeze_more : 1;
59#define LC_SHA3_224_STATE_SIZE \
60 LC_HASH_STATE_SIZE_ALIGN(sizeof(struct lc_sha3_224_state))
61#define LC_SHA3_224_CTX_SIZE \
62 (sizeof(struct lc_hash_ctx) + LC_SHA3_224_STATE_SIZE)
64#define LC_SHA3_224_CTX(name) \
65 LC_HASH_SET_CTX(name, lc_sha3_224); \
74#define LC_SHA3_224_CTX_ON_STACK(name) \
75 _Pragma("GCC diagnostic push") _Pragma( \
76 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
77 LC_ALIGNED_BUFFER(name##_ctx_buf, LC_SHA3_224_CTX_SIZE, \
78 LC_HASH_COMMON_ALIGNMENT); \
79 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
80 LC_SHA3_224_CTX(name); \
81 _Pragma("GCC diagnostic pop")
92#define LC_SHA3_256_SIZE_DIGEST_BITS 256
93#define LC_SHA3_256_SIZE_DIGEST (LC_SHA3_256_SIZE_DIGEST_BITS >> 3)
94#define LC_SHA3_256_SIZE_BLOCK LC_SHA3_SIZE_RATE(LC_SHA3_256_SIZE_DIGEST_BITS)
96struct lc_sha3_256_state {
97 uint64_t state[LC_SHA3_STATE_WORDS];
104 uint8_t squeeze_more : 1;
107#define LC_SHA3_256_STATE_SIZE \
108 LC_HASH_STATE_SIZE_ALIGN(sizeof(struct lc_sha3_256_state))
109#define LC_SHA3_256_CTX_SIZE \
110 (sizeof(struct lc_hash_ctx) + LC_SHA3_256_STATE_SIZE)
112#define LC_SHA3_256_CTX(name) \
113 LC_HASH_SET_CTX(name, lc_sha3_256); \
122#define LC_SHA3_256_CTX_ON_STACK(name) \
123 _Pragma("GCC diagnostic push") _Pragma( \
124 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
125 LC_ALIGNED_BUFFER(name##_ctx_buf, LC_SHA3_256_CTX_SIZE, \
126 LC_HASH_COMMON_ALIGNMENT); \
127 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
128 LC_SHA3_256_CTX(name); \
129 _Pragma("GCC diagnostic pop")
140#define LC_SHA3_384_SIZE_DIGEST_BITS 384
141#define LC_SHA3_384_SIZE_DIGEST (LC_SHA3_384_SIZE_DIGEST_BITS >> 3)
142#define LC_SHA3_384_SIZE_BLOCK LC_SHA3_SIZE_RATE(LC_SHA3_384_SIZE_DIGEST_BITS)
144struct lc_sha3_384_state {
145 uint64_t state[LC_SHA3_STATE_WORDS];
152 uint8_t squeeze_more : 1;
155#define LC_SHA3_384_STATE_SIZE \
156 LC_HASH_STATE_SIZE_ALIGN(sizeof(struct lc_sha3_384_state))
157#define LC_SHA3_384_CTX_SIZE \
158 (sizeof(struct lc_hash_ctx) + LC_SHA3_384_STATE_SIZE)
160#define LC_SHA3_384_CTX(name) \
161 LC_HASH_SET_CTX(name, lc_sha3_384); \
170#define LC_SHA3_384_CTX_ON_STACK(name) \
171 _Pragma("GCC diagnostic push") _Pragma( \
172 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
173 LC_ALIGNED_BUFFER(name##_ctx_buf, LC_SHA3_384_CTX_SIZE, \
174 LC_HASH_COMMON_ALIGNMENT); \
175 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
176 LC_SHA3_384_CTX(name); \
177 _Pragma("GCC diagnostic pop")
188#define LC_SHA3_512_SIZE_DIGEST_BITS 512
189#define LC_SHA3_512_SIZE_DIGEST (LC_SHA3_512_SIZE_DIGEST_BITS >> 3)
190#define LC_SHA3_512_SIZE_BLOCK LC_SHA3_SIZE_RATE(LC_SHA3_512_SIZE_DIGEST_BITS)
192struct lc_sha3_512_state {
193 uint64_t state[LC_SHA3_STATE_WORDS];
200 uint8_t squeeze_more : 1;
203#define LC_SHA3_512_STATE_SIZE \
204 LC_HASH_STATE_SIZE_ALIGN(sizeof(struct lc_sha3_512_state))
205#define LC_SHA3_512_CTX_SIZE \
206 (sizeof(struct lc_hash_ctx) + LC_SHA3_512_STATE_SIZE)
208#define LC_SHA3_512_CTX(name) \
209 LC_HASH_SET_CTX(name, lc_sha3_512); \
218#define LC_SHA3_512_CTX_ON_STACK(name) \
219 _Pragma("GCC diagnostic push") _Pragma( \
220 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
221 LC_ALIGNED_BUFFER(name##_ctx_buf, LC_SHA3_512_CTX_SIZE, \
222 LC_HASH_COMMON_ALIGNMENT); \
223 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
224 LC_SHA3_512_CTX(name); \
225 _Pragma("GCC diagnostic pop")
236#define LC_SHAKE_128_SIZE_DIGEST_BITS 128
237#define LC_SHAKE_128_SIZE_BLOCK LC_SHA3_SIZE_RATE(LC_SHAKE_128_SIZE_DIGEST_BITS)
239struct lc_shake_128_state {
240 uint64_t state[LC_SHA3_STATE_WORDS];
247 uint8_t squeeze_more : 1;
250#define LC_SHAKE_128_STATE_SIZE \
251 LC_HASH_STATE_SIZE_ALIGN(sizeof(struct lc_shake_128_state))
252#define LC_SHAKE_128_CTX_SIZE \
253 (sizeof(struct lc_hash_ctx) + LC_SHAKE_128_STATE_SIZE)
255#define LC_SHAKE_128_CTX(name) \
256 LC_HASH_SET_CTX(name, lc_shake128); \
265#define LC_SHAKE_128_CTX_ON_STACK(name) \
266 _Pragma("GCC diagnostic push") _Pragma( \
267 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
268 LC_ALIGNED_BUFFER(name##_ctx_buf, LC_SHAKE_128_CTX_SIZE, \
269 LC_HASH_COMMON_ALIGNMENT); \
270 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
271 LC_SHAKE_128_CTX(name); \
272 _Pragma("GCC diagnostic pop")
283#define LC_SHAKE_256_SIZE_DIGEST_BITS 256
284#define LC_SHAKE_256_SIZE_BLOCK LC_SHA3_SIZE_RATE(LC_SHAKE_256_SIZE_DIGEST_BITS)
286#define LC_SHAKE_256_CTX_SIZE LC_SHA3_256_CTX_SIZE
288#define LC_SHAKE_256_CTX(name) \
289 LC_HASH_SET_CTX(name, lc_shake256); \
298#define LC_SHAKE_256_CTX_ON_STACK(name) \
299 _Pragma("GCC diagnostic push") _Pragma( \
300 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
301 LC_ALIGNED_BUFFER(name##_ctx_buf, LC_SHAKE_256_CTX_SIZE, \
302 LC_HASH_COMMON_ALIGNMENT); \
303 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
304 LC_SHAKE_256_CTX(name); \
305 _Pragma("GCC diagnostic pop")
316#define LC_SHAKE_512_SIZE_DIGEST_BITS 512
317#define LC_SHAKE_512_SIZE_BLOCK LC_SHA3_SIZE_RATE(LC_SHAKE_512_SIZE_DIGEST_BITS)
319#define LC_SHAKE_512_CTX_SIZE LC_SHA3_512_CTX_SIZE
321#define LC_SHAKE_512_CTX(name) \
322 LC_HASH_SET_CTX(name, lc_shake512); \
331#define LC_SHAKE_512_CTX_ON_STACK(name) \
332 _Pragma("GCC diagnostic push") _Pragma( \
333 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
334 LC_ALIGNED_BUFFER(name##_ctx_buf, LC_SHAKE_512_CTX_SIZE, \
335 LC_HASH_COMMON_ALIGNMENT); \
336 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
337 LC_SHAKE_512_CTX(name); \
338 _Pragma("GCC diagnostic pop")
350#define LC_CSHAKE_256_CTX(name) \
351 LC_HASH_SET_CTX(name, lc_cshake256); \
360#define LC_CSHAKE_256_CTX_ON_STACK(name) \
361 _Pragma("GCC diagnostic push") _Pragma( \
362 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
365 LC_HASH_STATE_SIZE_ALIGN(LC_SHA3_256_CTX_SIZE), \
366 LC_HASH_COMMON_ALIGNMENT); \
367 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
368 LC_CSHAKE_256_CTX(name); \
369 _Pragma("GCC diagnostic pop")
380#define LC_CSHAKE_128_CTX(name) \
381 LC_HASH_SET_CTX(name, lc_cshake128); \
390#define LC_CSHAKE_128_CTX_ON_STACK(name) \
391 _Pragma("GCC diagnostic push") _Pragma( \
392 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
395 LC_HASH_STATE_SIZE_ALIGN(LC_SHAKE_128_CTX_SIZE), \
396 LC_HASH_COMMON_ALIGNMENT); \
397 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
398 LC_CSHAKE_128_CTX(name); \
399 _Pragma("GCC diagnostic pop")
402#define LC_SHA3_MAX_SIZE_BLOCK LC_SHA3_224_SIZE_BLOCK
int lc_hash(const struct lc_hash *hash, const uint8_t *in, size_t inlen, uint8_t *digest)
Calculate message digest - one-shot.
const struct lc_hash * lc_sha3_384
SHA3-384 algorithm reference.
const struct lc_hash * lc_shake512
SHAKE512 algorithm reference.
const struct lc_hash * lc_sha3_224
SHA3-224 algorithm reference.
const struct lc_hash * lc_cshake256
cSHAKE256 algorithm reference
const struct lc_hash * lc_cshake128
cSHAKE128 algorithm reference
const struct lc_hash * lc_shake256
SHAKE256 algorithm reference.
const struct lc_hash * lc_shake128
SHAKE128 algorithm reference.
const struct lc_hash * lc_sha3_256
SHA3-256 algorithm reference.
const struct lc_hash * lc_sha3_512
SHA3-512 algorithm reference.