35 uint8_t final_called : 1;
36 uint8_t rng_initialized : 1;
38 struct lc_hash_ctx hash_ctx;
41#define LC_KMAC_STATE_SIZE (LC_SHA3_224_STATE_SIZE)
42#define LC_KMAC_STATE_SIZE_REINIT (2 * LC_SHA3_224_STATE_SIZE)
43#define LC_KMAC_CTX_SIZE (LC_KMAC_STATE_SIZE + sizeof(struct lc_kmac_ctx))
44#define LC_KMAC_CTX_SIZE_REINIT \
45 (LC_KMAC_STATE_SIZE_REINIT + sizeof(struct lc_kmac_ctx))
47#define _LC_KMAC_SET_CTX(name, hashname, ctx, offset) \
48 _LC_HASH_SET_CTX((&name->hash_ctx), hashname, ctx, offset); \
49 name->shadow_ctx = NULL
51#define LC_KMAC_SET_CTX(name, hashname) \
52 _LC_KMAC_SET_CTX(name, hashname, name, sizeof(struct lc_kmac_ctx))
54#define _LC_KMAC_SET_CTX_REINIT(name, hashname, ctx, offset) \
55 _LC_HASH_SET_CTX((&name->hash_ctx), hashname, ctx, offset); \
56 name->shadow_ctx = (uint8_t *)((uint8_t *)ctx + offset + \
57 LC_HASH_STATE_SIZE(hashname))
59#define LC_KMAC_SET_CTX_REINIT(name, hashname) \
60 _LC_KMAC_SET_CTX_REINIT(name, hashname, name, \
61 sizeof(struct lc_kmac_ctx))
84int lc_kmac_init(
struct lc_kmac_ctx *kmac_ctx,
const uint8_t *key,
size_t klen,
85 const uint8_t *s,
size_t slen);
126int lc_kmac_final(
struct lc_kmac_ctx *kmac_ctx, uint8_t *mac,
size_t maclen);
185#define LC_KMAC_FLAGS_SUPPORT_REINIT (1 << 0)
235#define LC_KMAC_CTX_ON_STACK(name, hashname) \
236 _Pragma("GCC diagnostic push") _Pragma( \
237 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
238 LC_ALIGNED_BUFFER(name##_ctx_buf, LC_KMAC_CTX_SIZE, \
239 LC_HASH_COMMON_ALIGNMENT); \
240 struct lc_kmac_ctx *name = (struct lc_kmac_ctx *)name##_ctx_buf; \
241 LC_KMAC_SET_CTX(name, hashname); \
242 lc_kmac_zero(name); \
243 _Pragma("GCC diagnostic pop")
257#define LC_KMAC_CTX_ON_STACK_REINIT(name, hashname) \
258 _Pragma("GCC diagnostic push") _Pragma( \
259 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
260 LC_ALIGNED_BUFFER(name##_ctx_buf, LC_KMAC_CTX_SIZE_REINIT, \
261 LC_HASH_COMMON_ALIGNMENT); \
262 struct lc_kmac_ctx *name = (struct lc_kmac_ctx *)name##_ctx_buf; \
263 LC_KMAC_SET_CTX_REINIT(name, hashname); \
264 lc_kmac_zero(name); \
265 _Pragma("GCC diagnostic pop")
298 const uint8_t *s,
size_t slen,
const uint8_t *in,
size_t inlen,
299 uint8_t *mac,
size_t maclen);
322 const uint8_t *s,
size_t slen,
const uint8_t *in,
size_t inlen,
323 uint8_t *mac,
size_t maclen);
343#define LC_KMAC_KDF_DRNG_CTX_SIZE (sizeof(struct lc_rng_ctx) + LC_KMAC_CTX_SIZE)
345#define LC_KMAC_KDF_DRNG_SET_CTX(name, hashname) LC_KMAC_SET_CTX(name, hashname)
347#define LC_KMAC_KDF_RNG_CTX(name, hashname) \
348 LC_RNG_CTX(name, lc_kmac_rng); \
349 LC_KMAC_KDF_DRNG_SET_CTX(((struct lc_kmac_ctx *)(name->rng_state)), \
364#define LC_KMAC_KDF_DRNG_CTX_ON_STACK(name, hashname) \
365 _Pragma("GCC diagnostic push") _Pragma( \
366 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
367 LC_ALIGNED_BUFFER(name##_ctx_buf, LC_KMAC_KDF_DRNG_CTX_SIZE, \
368 LC_HASH_COMMON_ALIGNMENT); \
369 struct lc_rng_ctx *name = (struct lc_rng_ctx *)name##_ctx_buf; \
370 LC_KMAC_KDF_RNG_CTX(name, hashname); \
371 _Pragma("GCC diagnostic pop")
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_rng * lc_kmac_rng
int lc_kmac_rng_alloc(struct lc_rng_ctx **state, const struct lc_hash *hash)
Allocation of a KMAC DRNG context.
int lc_kmac_xof(const struct lc_hash *hash, const uint8_t *key, size_t keylen, const uint8_t *s, size_t slen, const uint8_t *in, size_t inlen, uint8_t *mac, size_t maclen)
Calculate KMAC in XOF mode - one-shot.
int lc_kmac_init(struct lc_kmac_ctx *kmac_ctx, const uint8_t *key, size_t klen, const uint8_t *s, size_t slen)
Initialize KMAC context.
int lc_kmac_final(struct lc_kmac_ctx *kmac_ctx, uint8_t *mac, size_t maclen)
Calculate KMAC MAC.
int lc_kmac_alloc(const struct lc_hash *hash, struct lc_kmac_ctx **kmac_ctx, uint32_t flags)
Allocate KMAC context on heap.
enum lc_alg_status_val lc_kmac_alg_status(const struct lc_hash *hash)
Obtain algorithm status.
void lc_kmac_zero(struct lc_kmac_ctx *kmac_ctx)
Zeroize KMAC context allocated with either LC_KMAC_CTX_ON_STACK or lc_kmac_alloc.
void lc_kmac_final_xof(struct lc_kmac_ctx *kmac_ctx, uint8_t *mac, size_t maclen)
Calculate KMAC MAC in XOF mode.
int lc_kmac(const struct lc_hash *hash, const uint8_t *key, size_t keylen, const uint8_t *s, size_t slen, const uint8_t *in, size_t inlen, uint8_t *mac, size_t maclen)
Calculate KMAC - one-shot.
void lc_kmac_update(struct lc_kmac_ctx *kmac_ctx, const uint8_t *in, size_t inlen)
Update KMAC.
size_t lc_kmac_macsize(struct lc_kmac_ctx *kmac_ctx)
Return the MAC size.
void lc_kmac_zero_free(struct lc_kmac_ctx *kmac_ctx)
Zeroize and free KMAC context.
enum lc_alg_status_val lc_kmac_ctx_alg_status(const struct lc_hash_ctx *ctx)
Obtain algorithm status.
void lc_kmac_reinit(struct lc_kmac_ctx *kmac_ctx)
Re-initialize KMAC context after a kmac_final operation.