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
16extern "C" {
17#endif
18
19typedef 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
31SODIUM_EXPORT
32size_t randombytes_seedbytes(void);
33
34SODIUM_EXPORT
35void randombytes_buf(void * const buf, const size_t size);
36
37SODIUM_EXPORT
38void randombytes_buf_deterministic(void * const buf, const size_t size,
39                                   const unsigned char seed[randombytes_SEEDBYTES]);
40
41SODIUM_EXPORT
42uint32_t randombytes_random(void);
43
44SODIUM_EXPORT
45uint32_t randombytes_uniform(const uint32_t upper_bound);
46
47SODIUM_EXPORT
48void randombytes_stir(void);
49
50SODIUM_EXPORT
51int randombytes_close(void);
52
53SODIUM_EXPORT
54int randombytes_set_implementation(randombytes_implementation *impl);
55
56SODIUM_EXPORT
57const char *randombytes_implementation_name(void);
58
59/* -- NaCl compatibility interface -- */
60
61SODIUM_EXPORT
62void randombytes(unsigned char * const buf, const unsigned long long buf_len);
63
64#ifdef __cplusplus
65}
66#endif
67
68#endif
69