libsodium (1.0.19)
1
2 #ifndef randombytes_H
3 #define randombytes_H
4
5 #include <stddef.h>
6 #include <stdint.h>
7
8 #include <sys/types.h>
9
10 #include "export.h"
11
12 #ifdef __cplusplus
13 # ifdef __GNUC__
14 # pragma GCC diagnostic ignored "-Wlong-long"
15 # endif
16 extern "C" {
17 #endif
18
19 typedef struct randombytes_implementation {
20 const char *(*implementation_name)(void); /* required */
21 uint32_t (*random)(void); /* required */
22 void (*stir)(void); /* optional */
23 uint32_t (*uniform)(const uint32_t upper_bound); /* optional, a default implementation will be used if NULL */
24 void (*buf)(void * const buf, const size_t size); /* required */
25 int (*close)(void); /* optional */
26 } randombytes_implementation;
27
28 #define randombytes_BYTES_MAX SODIUM_MIN(SODIUM_SIZE_MAX, 0xffffffffUL)
29
30 #define randombytes_SEEDBYTES 32U
31 SODIUM_EXPORT
32 size_t randombytes_seedbytes(void);
33
34 SODIUM_EXPORT
35 void randombytes_buf(void * const buf, const size_t size)
36 __attribute__ ((nonnull));
37
38 SODIUM_EXPORT
39 void randombytes_buf_deterministic(void * const buf, const size_t size,
40 const unsigned char seed[randombytes_SEEDBYTES])
41 __attribute__ ((nonnull));
42
43 SODIUM_EXPORT
44 uint32_t randombytes_random(void);
45
46 SODIUM_EXPORT
47 uint32_t randombytes_uniform(const uint32_t upper_bound);
48
49 SODIUM_EXPORT
50 void randombytes_stir(void);
51
52 SODIUM_EXPORT
53 int randombytes_close(void);
54
55 SODIUM_EXPORT
56 int randombytes_set_implementation(const randombytes_implementation *impl)
57 __attribute__ ((nonnull));
58
59 SODIUM_EXPORT
60 const char *randombytes_implementation_name(void);
61
62 /* -- NaCl compatibility interface -- */
63
64 SODIUM_EXPORT
65 void randombytes(unsigned char * const buf, const unsigned long long buf_len)
66 __attribute__ ((nonnull));
67
68 #ifdef __cplusplus
69 }
70 #endif
71
72 #endif