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))
34#define LC_SHA3_STATE_SIZE_ALIGN(x) (x + LC_HASH_COMMON_ALIGNMENT)
46#define LC_SHA3_224_SIZE_DIGEST_BITS 224
47#define LC_SHA3_224_SIZE_DIGEST (LC_SHA3_224_SIZE_DIGEST_BITS >> 3)
48#define LC_SHA3_224_SIZE_BLOCK LC_SHA3_SIZE_RATE(LC_SHA3_224_SIZE_DIGEST_BITS)
50struct lc_sha3_224_state {
51 uint64_t state[LC_SHA3_STATE_WORDS];
58 uint8_t squeeze_more : 1;
61#define LC_SHA3_224_STATE_SIZE (sizeof(struct lc_sha3_224_state))
62#define LC_SHA3_224_CTX_SIZE \
63 (sizeof(struct lc_hash_ctx) + LC_SHA3_224_STATE_SIZE)
65#define LC_SHA3_224_CTX(name) \
66 LC_HASH_SET_CTX(name, lc_sha3_224); \
75#define LC_SHA3_224_CTX_ON_STACK(name) \
76 _Pragma("GCC diagnostic push") _Pragma( \
77 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
80 LC_SHA3_STATE_SIZE_ALIGN(LC_SHA3_224_CTX_SIZE), \
81 LC_HASH_COMMON_ALIGNMENT); \
82 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
83 LC_SHA3_224_CTX(name); \
84 _Pragma("GCC diagnostic pop")
95#define LC_SHA3_256_SIZE_DIGEST_BITS 256
96#define LC_SHA3_256_SIZE_DIGEST (LC_SHA3_256_SIZE_DIGEST_BITS >> 3)
97#define LC_SHA3_256_SIZE_BLOCK LC_SHA3_SIZE_RATE(LC_SHA3_256_SIZE_DIGEST_BITS)
99struct lc_sha3_256_state {
100 uint64_t state[LC_SHA3_STATE_WORDS];
107 uint8_t squeeze_more : 1;
110#define LC_SHA3_256_STATE_SIZE (sizeof(struct lc_sha3_256_state))
111#define LC_SHA3_256_CTX_SIZE (sizeof(struct lc_hash) + LC_SHA3_256_STATE_SIZE)
113#define LC_SHA3_256_CTX(name) \
114 LC_HASH_SET_CTX(name, lc_sha3_256); \
123#define LC_SHA3_256_CTX_ON_STACK(name) \
124 _Pragma("GCC diagnostic push") _Pragma( \
125 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
128 LC_SHA3_STATE_SIZE_ALIGN(LC_SHA3_256_CTX_SIZE), \
129 LC_HASH_COMMON_ALIGNMENT); \
130 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
131 LC_SHA3_256_CTX(name); \
132 _Pragma("GCC diagnostic pop")
143#define LC_SHA3_384_SIZE_DIGEST_BITS 384
144#define LC_SHA3_384_SIZE_DIGEST (LC_SHA3_384_SIZE_DIGEST_BITS >> 3)
145#define LC_SHA3_384_SIZE_BLOCK LC_SHA3_SIZE_RATE(LC_SHA3_384_SIZE_DIGEST_BITS)
147struct lc_sha3_384_state {
148 uint64_t state[LC_SHA3_STATE_WORDS];
155 uint8_t squeeze_more : 1;
158#define LC_SHA3_384_STATE_SIZE (sizeof(struct lc_sha3_384_state))
159#define LC_SHA3_384_CTX_SIZE (sizeof(struct lc_hash) + LC_SHA3_384_STATE_SIZE)
161#define LC_SHA3_384_CTX(name) \
162 LC_HASH_SET_CTX(name, lc_sha3_384); \
171#define LC_SHA3_384_CTX_ON_STACK(name) \
172 _Pragma("GCC diagnostic push") _Pragma( \
173 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
176 LC_SHA3_STATE_SIZE_ALIGN(LC_SHA3_384_CTX_SIZE), \
177 LC_HASH_COMMON_ALIGNMENT); \
178 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
179 LC_SHA3_384_CTX(name); \
180 _Pragma("GCC diagnostic pop")
191#define LC_SHA3_512_SIZE_DIGEST_BITS 512
192#define LC_SHA3_512_SIZE_DIGEST (LC_SHA3_512_SIZE_DIGEST_BITS >> 3)
193#define LC_SHA3_512_SIZE_BLOCK LC_SHA3_SIZE_RATE(LC_SHA3_512_SIZE_DIGEST_BITS)
195struct lc_sha3_512_state {
196 uint64_t state[LC_SHA3_STATE_WORDS];
203 uint8_t squeeze_more : 1;
206#define LC_SHA3_512_STATE_SIZE (sizeof(struct lc_sha3_512_state))
207#define LC_SHA3_512_CTX_SIZE (sizeof(struct lc_hash) + LC_SHA3_512_STATE_SIZE)
209#define LC_SHA3_512_CTX(name) \
210 LC_HASH_SET_CTX(name, lc_sha3_512); \
219#define LC_SHA3_512_CTX_ON_STACK(name) \
220 _Pragma("GCC diagnostic push") _Pragma( \
221 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
224 LC_SHA3_STATE_SIZE_ALIGN(LC_SHA3_512_CTX_SIZE), \
225 LC_HASH_COMMON_ALIGNMENT); \
226 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
227 LC_SHA3_512_CTX(name); \
228 _Pragma("GCC diagnostic pop")
239#define LC_SHAKE_128_SIZE_DIGEST_BITS 128
240#define LC_SHAKE_128_SIZE_BLOCK LC_SHA3_SIZE_RATE(LC_SHAKE_128_SIZE_DIGEST_BITS)
242struct lc_shake_128_state {
243 uint64_t state[LC_SHA3_STATE_WORDS];
250 uint8_t squeeze_more : 1;
253#define LC_SHAKE_128_STATE_SIZE (sizeof(struct lc_shake_128_state))
254#define LC_SHAKE_128_CTX_SIZE (sizeof(struct lc_hash) + LC_SHAKE_128_STATE_SIZE)
256#define LC_SHAKE_128_CTX(name) \
257 LC_HASH_SET_CTX(name, lc_shake128); \
266#define LC_SHAKE_128_CTX_ON_STACK(name) \
267 _Pragma("GCC diagnostic push") _Pragma( \
268 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
271 LC_SHA3_STATE_SIZE_ALIGN(LC_SHAKE_128_CTX_SIZE), \
272 LC_HASH_COMMON_ALIGNMENT); \
273 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
274 LC_SHAKE_128_CTX(name); \
275 _Pragma("GCC diagnostic pop")
286#define LC_SHAKE_256_SIZE_DIGEST_BITS 256
287#define LC_SHAKE_256_SIZE_BLOCK LC_SHA3_SIZE_RATE(LC_SHAKE_256_SIZE_DIGEST_BITS)
289#define LC_SHAKE_256_CTX_SIZE LC_SHA3_256_CTX_SIZE
291#define LC_SHAKE_256_CTX(name) \
292 LC_HASH_SET_CTX(name, lc_shake256); \
301#define LC_SHAKE_256_CTX_ON_STACK(name) \
302 _Pragma("GCC diagnostic push") _Pragma( \
303 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
306 LC_SHA3_STATE_SIZE_ALIGN(LC_SHAKE_256_CTX_SIZE), \
307 LC_HASH_COMMON_ALIGNMENT); \
308 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
309 LC_SHAKE_256_CTX(name); \
310 _Pragma("GCC diagnostic pop")
322#define LC_CSHAKE_256_CTX(name) \
323 LC_HASH_SET_CTX(name, lc_cshake256); \
332#define LC_CSHAKE_256_CTX_ON_STACK(name) \
333 _Pragma("GCC diagnostic push") _Pragma( \
334 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
337 LC_SHA3_STATE_SIZE_ALIGN(LC_SHA3_256_CTX_SIZE), \
338 LC_HASH_COMMON_ALIGNMENT); \
339 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
340 LC_CSHAKE_256_CTX(name); \
341 _Pragma("GCC diagnostic pop")
352#define LC_CSHAKE_128_CTX(name) \
353 LC_HASH_SET_CTX(name, lc_cshake128); \
362#define LC_CSHAKE_128_CTX_ON_STACK(name) \
363 _Pragma("GCC diagnostic push") _Pragma( \
364 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
367 LC_SHA3_STATE_SIZE_ALIGN(LC_SHAKE_128_CTX_SIZE), \
368 LC_HASH_COMMON_ALIGNMENT); \
369 struct lc_hash_ctx *name = (struct lc_hash_ctx *)name##_ctx_buf; \
370 LC_CSHAKE_128_CTX(name); \
371 _Pragma("GCC diagnostic pop")
374#define LC_SHA3_MAX_SIZE_BLOCK LC_SHA3_224_SIZE_BLOCK
void 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_shake128
SHAKE128 algorithm reference.
const struct lc_hash * lc_sha3_384
SHA3-384 algorithm reference.
const struct lc_hash * lc_sha3_256
SHA3-256 algorithm reference.
const struct lc_hash * lc_sha3_512
SHA3-512 algorithm reference.
const struct lc_hash * lc_cshake256
cSHAKE256 algorithm reference
const struct lc_hash * lc_shake256
SHAKE256 algorithm reference.
const struct lc_hash * lc_cshake128
cSHAKE128 algorithm reference
const struct lc_hash * lc_sha3_224
SHA3-224 algorithm reference.