forked from relic-toolkit/relic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelic_rand.h
119 lines (100 loc) · 3.36 KB
/
relic_rand.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* RELIC is an Efficient LIbrary for Cryptography
* Copyright (C) 2007-2015 RELIC Authors
*
* This file is part of RELIC. RELIC is legal property of its developers,
* whose names are not listed here. Please refer to the COPYRIGHT file
* for contact information.
*
* RELIC is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* RELIC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with RELIC. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @defgroup rand Pseudo-random number generators.
*/
/**
* @file
*
* Interface of the module for pseudo-random number generation.
*
* @ingroup rand
*/
#ifndef RELIC_RAND_H
#define RELIC_RAND_H
#include "relic_rand.h"
/*============================================================================*/
/* Constant definitions */
/*============================================================================*/
/**
* Size of the PRNG internal state in bytes.
*/
#if RAND == HASH
#if MD_MAP == SHONE || MD_MAP == SH224 || MD_MAP == SH256 || MD_MAP == BLAKE2S_160 || MD_MAP == BLAKE2S_256
#define RAND_SIZE (1 + 2*440/8)
#elif MD_MAP == SH384 || MD_MAP == SH512
#define RAND_SIZE (1 + 2*888/8)
#endif
#elif RAND == UDEV
#define RAND_SIZE (sizeof(int))
#elif RAND == FIPS
#define RAND_SIZE 20
#elif RAND == CALL
#define RAND_SIZE (sizeof(void (*)(uint8_t *, int)))
#elif RAND == RDRND
#define RAND_SIZE 0
#endif
/**
* Minimum size of the PRNG seed.
*/
#define SEED_SIZE 64
/*============================================================================*/
/* Function prototypes */
/*============================================================================*/
/**
* Initializes the pseudo-random number generator.
*/
void rand_init(void);
/**
* Finishes the pseudo-random number generator.
*/
void rand_clean(void);
#if RAND != CALL
/**
* Sets the initial state of the pseudo-random number generator.
*
* @param[in] buf - the buffer that represents the initial state.
* @param[in] size - the number of bytes.
* @throw ERR_NO_VALID - if the entropy length is too small or too large.
*/
void rand_seed(uint8_t *buf, int size);
#else
/**
* Sets the initial state of the pseudo-random number generator as a function
* pointer.
*
* @param[in] callback - the callback to call.
* @param[in] arg - the argument for the callback.
*/
void rand_seed(void (*callback)(uint8_t *, int, void *), void *arg);
#endif
/**
* Gathers pseudo-random bytes from the pseudo-random number generator.
*
* @param[out] buf - the buffer to write.
* @param[in] size - the number of bytes to gather.
* @throw ERR_NO_VALID - if the required length is too large.
* @throw ERR_NO_READ - it the pseudo-random number generator cannot
* generate the specified number of bytes.
*/
void rand_bytes(uint8_t *buf, int size);
#endif /* !RELIC_RAND_H */