Leancrypto 0.12.0
Post-Quantum Cryptographic Library
Loading...
Searching...
No Matches
lc_kmac256_drng.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 - 2024, Stephan Mueller <smueller@chronox.de>
3 *
4 * License: see LICENSE file in root directory
5 *
6 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
7 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
9 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
10 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
11 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
12 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
13 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
14 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
16 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
17 * DAMAGE.
18 */
19
20#ifndef LC_KMAC256_DRNG_H
21#define LC_KMAC256_DRNG_H
22
23#include "lc_kmac.h"
24#include "lc_rng.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
31#define LC_KMAC256_DRNG_KEYSIZE 64
32
33struct lc_kmac256_drng_state {
34 uint8_t initially_seeded;
35 uint8_t key[LC_KMAC256_DRNG_KEYSIZE];
36};
37
38#define LC_KMAC256_DRNG_MAX_CHUNK (LC_SHA3_256_SIZE_BLOCK * 2)
39#define LC_KMAC256_DRNG_STATE_SIZE (sizeof(struct lc_kmac256_drng_state))
40#define LC_KMAC256_DRNG_CTX_SIZE \
41 (sizeof(struct lc_rng) + LC_KMAC256_DRNG_STATE_SIZE)
42
43/* KMAC256-based DRNG */
44extern const struct lc_rng *lc_kmac256_drng;
45
46#define LC_KMAC256_RNG_CTX(name) \
47 LC_RNG_CTX(name, lc_kmac256_drng); \
48 lc_kmac256_drng->zero(name->rng_state)
50
58#define LC_KMAC256_DRNG_CTX_ON_STACK(name) \
59 _Pragma("GCC diagnostic push") _Pragma( \
60 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
61 LC_ALIGNED_BUFFER(name##_ctx_buf, LC_KMAC256_DRNG_CTX_SIZE, \
62 LC_HASH_COMMON_ALIGNMENT); \
63 struct lc_rng_ctx *name = (struct lc_rng_ctx *)name##_ctx_buf; \
64 LC_KMAC256_RNG_CTX(name); \
65 _Pragma("GCC diagnostic pop")
66
80int lc_kmac256_drng_alloc(struct lc_rng_ctx **state);
81
82#ifdef __cplusplus
83}
84#endif
85
86#endif /* LC_KMAC256_DRNG_H */
int lc_kmac256_drng_alloc(struct lc_rng_ctx **state)
Allocation of a KMAC DRNG context.