blob: 07e234105e06b2b89ab52bb780d4db39d862f8ff (
plain)
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
|
#include <sys/types.h>
#include <assert.h>
#include <limits.h>
#include <stdint.h>
#include "randombytes.h"
#include "randombytes_sysrandom.h"
static const randombytes_implementation *implementation =
&randombytes_sysrandom_implementation;
int
randombytes_set_implementation(randombytes_implementation *impl)
{
implementation = impl;
return 0;
}
const char *
randombytes_implementation_name(void)
{
return implementation->implementation_name();
}
uint32_t
randombytes_random(void)
{
return implementation->random();
}
void
randombytes_stir(void)
{
implementation->stir();
}
uint32_t
randombytes_uniform(const uint32_t upper_bound)
{
return implementation->uniform(upper_bound);
}
void
randombytes_buf(void * const buf, const size_t size)
{
if (size > (size_t) 0U) {
implementation->buf(buf, size);
}
}
int
randombytes_close(void)
{
return implementation->close();
}
void
randombytes(unsigned char * const buf, const unsigned long long buf_len)
{
assert(buf_len <= SIZE_MAX);
randombytes_buf(buf, (size_t) buf_len);
}
|