20#ifndef LC_XDRBG256_DRNG_H
21#define LC_XDRBG256_DRNG_H
32#define LC_XDRBG_DRNG_INITIALLY_SEEDED 0x80
33#define LC_XDRBG_DRNG_KEYSIZE_MASK 0x7F
35struct lc_xdrbg_drng_state {
48extern const struct lc_rng *lc_xdrbg_drng;
51#define LC_XDRBG_DRNG_CTX_ON_STACK(name) \
52 _Pragma("GCC diagnostic push") _Pragma( \
53 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
54 LC_ALIGNED_BUFFER(name##_ctx_buf, LC_XDRBG256_DRNG_CTX_SIZE, \
55 LC_HASH_COMMON_ALIGNMENT); \
56 struct lc_rng_ctx *name = (struct lc_rng_ctx *)name##_ctx_buf; \
57 _Pragma("GCC diagnostic pop")
59#define LC_XDRBG256_DRNG_KEYSIZE 64
65#define LC_XDRBG256_DRNG_MAX_CHUNK \
66 (LC_SHAKE_256_SIZE_BLOCK * 2 - LC_XDRBG256_DRNG_KEYSIZE)
67#define LC_XDRBG256_DRNG_STATE_SIZE \
68 (sizeof(struct lc_xdrbg_drng_state) + LC_XDRBG256_DRNG_KEYSIZE)
69#define LC_XDRBG256_DRNG_CTX_SIZE \
70 (sizeof(struct lc_rng) + LC_XDRBG256_DRNG_STATE_SIZE)
72#define LC_XDRBG256_RNG_CTX(name) \
73 LC_RNG_CTX(name, lc_xdrbg_drng); \
74 struct lc_xdrbg_drng_state *__name = name->rng_state; \
75 __name->status = LC_XDRBG256_DRNG_KEYSIZE; \
76 __name->xof = lc_shake256; \
77 __name->chunksize = LC_XDRBG256_DRNG_MAX_CHUNK; \
78 lc_xdrbg_drng->zero(name->rng_state);
96#define LC_XDRBG256_DRNG_CTX_ON_STACK(name) \
97 LC_XDRBG_DRNG_CTX_ON_STACK(name); \
98 LC_XDRBG256_RNG_CTX(name)
116#define LC_XDRBG128_DRNG_KEYSIZE 32
123#define LC_XDRBG128_DRNG_MAX_CHUNK (LC_ASCON_HASH_RATE * 32)
124#define LC_XDRBG128_DRNG_STATE_SIZE \
125 (sizeof(struct lc_xdrbg_drng_state) + LC_XDRBG128_DRNG_KEYSIZE)
126#define LC_XDRBG128_DRNG_CTX_SIZE \
127 (sizeof(struct lc_rng) + LC_XDRBG128_DRNG_STATE_SIZE)
129#define LC_XDRBG128_RNG_CTX(name) \
130 LC_RNG_CTX(name, lc_xdrbg_drng); \
131 struct lc_xdrbg_drng_state *__name = name->rng_state; \
132 __name->status = LC_XDRBG128_DRNG_KEYSIZE; \
133 __name->xof = lc_ascon_xof; \
134 __name->chunksize = LC_XDRBG128_DRNG_MAX_CHUNK; \
135 lc_xdrbg_drng->zero(name->rng_state);
154#define LC_XDRBG128_DRNG_CTX_ON_STACK(name) \
155 LC_XDRBG_DRNG_CTX_ON_STACK(name); \
156 LC_XDRBG128_RNG_CTX(name)
void lc_hash(const struct lc_hash *hash, const uint8_t *in, size_t inlen, uint8_t *digest)
Calculate message digest - one-shot.
int lc_xdrbg128_drng_alloc(struct lc_rng_ctx **state)
Allocation of a XDRBG128 DRNG context using Ascon-XOF.
int lc_xdrbg256_drng_alloc(struct lc_rng_ctx **state)
Allocation of a XDRBG256 DRNG context using SHAKE-256.