63 const uint8_t *s,
size_t slen);
92 struct lc_hash_ctx hash_ctx;
95#define LC_CSHAKE_STATE_SIZE(x) (LC_HASH_STATE_SIZE(x))
96#define LC_CSHAKE_STATE_SIZE_REINIT(x) (2 * LC_HASH_STATE_SIZE(x))
97#define LC_CSHAKE_CTX_SIZE(x) \
98 (LC_CSHAKE_STATE_SIZE(x) + sizeof(struct lc_cshake_ctx))
99#define LC_CSHAKE_CTX_SIZE_REINIT(x) \
100 (LC_CSHAKE_STATE_SIZE_REINIT(x) + sizeof(struct lc_cshake_ctx))
102#define _LC_CSHAKE_SET_CTX(name, hashname, ctx, offset) \
103 _LC_HASH_SET_CTX((&name->hash_ctx), hashname, ctx, offset); \
104 name->shadow_ctx = NULL
106#define LC_CSHAKE_SET_CTX(name, hashname) \
107 _LC_CSHAKE_SET_CTX(name, hashname, name, sizeof(struct lc_cshake_ctx))
109#define _LC_CSHAKE_SET_CTX_REINIT(name, hashname, ctx, offset) \
110 _LC_HASH_SET_CTX((&name->hash_ctx), hashname, ctx, offset); \
111 name->shadow_ctx = (uint8_t *)((uint8_t *)ctx + offset + \
112 LC_HASH_STATE_SIZE(hashname))
114#define LC_CSHAKE_SET_CTX_REINIT(name, hashname) \
115 _LC_CSHAKE_SET_CTX_REINIT(name, hashname, name, \
116 sizeof(struct lc_cshake_ctx))
136 size_t nlen,
const uint8_t *s,
size_t slen);
187 struct lc_cshake_ctx **cshake_ctx, uint32_t flags);
197#define LC_CSHAKE_FLAGS_SUPPORT_REINIT (1 << 0)
214 struct lc_hash_ctx *hash_ctx;
219 hash_ctx = &cshake_ctx->hash_ctx;
220 hash = hash_ctx->hash;
224 cshake_ctx->shadow_ctx ?
225 LC_CSHAKE_STATE_SIZE_REINIT(hash) :
226 LC_CSHAKE_STATE_SIZE(hash));
239#define LC_CSHAKE_CTX_ON_STACK(name, hashname) \
240 _Pragma("GCC diagnostic push") \
241 _Pragma("GCC diagnostic ignored \"-Wvla\"") _Pragma( \
242 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
243 LC_ALIGNED_BUFFER(name##_ctx_buf, \
244 LC_CSHAKE_CTX_SIZE(hashname), \
245 LC_HASH_COMMON_ALIGNMENT); \
246 struct lc_cshake_ctx *name = (struct lc_cshake_ctx *)name##_ctx_buf; \
247 LC_CSHAKE_SET_CTX(name, hashname); \
248 lc_cshake_ctx_zero(name); \
249 _Pragma("GCC diagnostic pop")
262#define LC_CSHAKE_CTX_ON_STACK_REINIT(name, hashname) \
263 _Pragma("GCC diagnostic push") \
264 _Pragma("GCC diagnostic ignored \"-Wvla\"") _Pragma( \
265 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
266 LC_ALIGNED_BUFFER(name##_ctx_buf, \
267 LC_CSHAKE_CTX_SIZE_REINIT(hashname), \
268 LC_HASH_COMMON_ALIGNMENT); \
269 struct lc_cshake_ctx *name = (struct lc_cshake_ctx *)name##_ctx_buf; \
270 LC_CSHAKE_SET_CTX_REINIT(name, hashname); \
271 lc_cshake_ctx_zero(name); \
272 _Pragma("GCC diagnostic pop")
void lc_hash_set_digestsize(struct lc_hash_ctx *hash_ctx, size_t digestsize)
Set the size of the message digest - this call is intended for SHAKE.
int lc_hash(const struct lc_hash *hash, const uint8_t *in, size_t inlen, uint8_t *digest)
Calculate message digest - one-shot.
void lc_hash_final(struct lc_hash_ctx *hash_ctx, uint8_t *digest)
Calculate message digest.
int lc_cshake_ctx_init(struct lc_cshake_ctx *cshake_ctx, const uint8_t *n, size_t nlen, const uint8_t *s, size_t slen)
Initialize the hash state with re-init support following the cSHAKE specification.
void lc_cshake_ctx_update(struct lc_cshake_ctx *cshake_ctx, const uint8_t *in, size_t inlen)
Update CSHAKE.
int lc_cshake_ctx_alloc(const struct lc_hash *hash, struct lc_cshake_ctx **cshake_ctx, uint32_t flags)
Allocate CSHAKE context on heap.
int lc_cshake_init(struct lc_hash_ctx *ctx, const uint8_t *n, size_t nlen, const uint8_t *s, size_t slen)
Initialize the hash state following the cSHAKE specification.
void lc_cshake_ctx_final(struct lc_cshake_ctx *cshake_ctx, uint8_t *out, size_t outlen)
Generate a cSHAKE message digest from a given state.
void lc_cshake_ctx_zero_free(struct lc_cshake_ctx *cshake_ctx)
Zeroize and free CSHAKE context.
static void lc_cshake_ctx_zero(struct lc_cshake_ctx *cshake_ctx)
Zeroize CSHAKE context allocated with either LC_CSHAKE_CTX_ON_STACK or lc_cshake_alloc.
void lc_cshake_ctx_reinit(struct lc_cshake_ctx *cshake_ctx)
Re-initialize CSHAKE context after a cshake_final operation.
static void lc_cshake_final(struct lc_hash_ctx *ctx, uint8_t *out, size_t outlen)
Generate a cSHAKE message digest from a given state.
static void lc_memset_secure(void *s, int c, size_t n)