20#ifndef _LC_CHACHA20_DRNG_H
21#define _LC_CHACHA20_DRNG_H
23#include "ext_headers.h"
32struct lc_chacha20_drng_ctx {
33 struct lc_sym_ctx cc20;
37extern const struct lc_rng *lc_cc20_drng;
39#define LC_CC20_DRNG_SYM_STATE_SIZE (LC_SYM_CTX_SIZE_NONALIGNED(lc_chacha20))
40#define LC_CC20_DRNG_STATE_SIZE \
41 (LC_CC20_DRNG_SYM_STATE_SIZE + sizeof(struct lc_chacha20_drng_ctx))
42#define LC_CC20_DRNG_CTX_SIZE (sizeof(struct lc_rng) + LC_CC20_DRNG_STATE_SIZE)
44#define _LC_CC20_DRNG_SET_CTX(name, ctx, offset) \
45 _LC_SYM_SET_CTX((&name->cc20), lc_chacha20, ctx, offset)
47#define LC_CC20_DRNG_SET_CTX(name) \
48 LC_RNG_CTX(name, lc_cc20_drng); \
49 struct lc_chacha20_drng_ctx *__name = name->rng_state; \
50 _LC_CC20_DRNG_SET_CTX(__name, __name, \
51 sizeof(struct lc_chacha20_drng_ctx)); \
52 lc_cc20_drng->zero(name->rng_state)
62#define LC_CC20_DRNG_CTX_ON_STACK(name) \
63 _Pragma("GCC diagnostic push") \
64 _Pragma("GCC diagnostic ignored \"-Wvla\"") _Pragma( \
65 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
66 LC_ALIGNED_BUFFER(name##_ctx_buf, \
67 LC_CC20_DRNG_CTX_SIZE, \
68 LC_SYM_COMMON_ALIGNMENT); \
69 struct lc_rng_ctx *name = (struct lc_rng_ctx *)name##_ctx_buf; \
70 LC_CC20_DRNG_SET_CTX(name); \
71 _Pragma("GCC diagnostic pop")
int lc_cc20_drng_alloc(struct lc_rng_ctx **state)
Allocation of a ChaCha20 DRNG context.