Leancrypto
0.12.0
Post-Quantum Cryptographic Library
Loading...
Searching...
No Matches
drng
api
lc_drbg.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_DRBG_H
21
#define LC_DRBG_H
22
23
#include "ext_headers.h"
24
25
#ifdef __cplusplus
26
extern
"C"
{
27
#endif
28
30
/******************************************************************
31
* Generic internal DRBG helper functions
32
******************************************************************/
33
34
/*
35
* Concatenation Helper and string operation helper
36
*
37
* SP800-90A requires the concatenation of different data. To avoid copying
38
* buffers around or allocate additional memory, the following data structure
39
* is used to point to the original memory with its size. In addition, it
40
* is used to build a linked list. The linked list defines the concatenation
41
* of individual buffers. The order of memory block referenced in that
42
* linked list determines the order of concatenation.
43
*/
44
struct
lc_drbg_string {
45
const
uint8_t *buf;
46
size_t
len;
47
struct
lc_drbg_string *next;
48
};
49
50
enum
lc_drbg_prefixes {
51
DRBG_PREFIX0 = 0x00,
52
DRBG_PREFIX1,
53
DRBG_PREFIX2,
54
DRBG_PREFIX3
55
};
56
57
static
inline
void
lc_drbg_string_fill(
struct
lc_drbg_string *
string
,
58
const
uint8_t *buf,
size_t
len)
59
{
60
string
->buf = buf;
61
string
->len = len;
62
string
->next = NULL;
63
}
64
65
/* SP800-90A requires the limit 2**19 bits, but we return bytes */
66
#define LC_DRBG_MAX_REQUEST_BYTES (1U << 16)
67
static
inline
size_t
lc_drbg_max_request_bytes(
void
)
68
{
69
return
LC_DRBG_MAX_REQUEST_BYTES;
70
}
71
72
static
inline
size_t
lc_drbg_max_addtl(
void
)
73
{
74
return
(1UL << 31);
75
}
77
78
#ifdef __cplusplus
79
}
80
#endif
81
82
#endif
/* LC_DRBG_H */
Generated by
1.11.0