libsodium: Needed for Dnscrypto-proxy Release 1.3.0
[tomato.git] / release / src / router / libsodium / src / libsodium / randombytes / randombytes.c
blob38bc939bb48c25501134ac822e7871b9fd4c33d6
2 #include <sys/types.h>
4 #include <assert.h>
5 #include <inttypes.h>
6 #include <limits.h>
7 #include <stdint.h>
9 #include "randombytes.h"
10 #include "randombytes_sysrandom.h"
12 static const randombytes_implementation *implementation =
13 &randombytes_sysrandom_implementation;
15 int
16 randombytes_set_implementation(randombytes_implementation *impl)
18 implementation = impl;
20 return 0;
23 const char *
24 randombytes_implementation_name(void)
26 return implementation->implementation_name();
29 uint32_t
30 randombytes_random(void)
32 return implementation->random();
35 void
36 randombytes_stir(void)
38 return implementation->stir();
41 uint32_t
42 randombytes_uniform(const uint32_t upper_bound)
44 return implementation->uniform(upper_bound);
47 void
48 randombytes_buf(void * const buf, const size_t size)
50 implementation->buf(buf, size);
53 int
54 randombytes_close(void)
56 return implementation->close();
59 void
60 randombytes(unsigned char * const buf, const unsigned long long buf_len)
62 assert(buf_len <= SIZE_MAX);
63 randombytes_buf(buf, (size_t) buf_len);