Home | History | Annotate | Line # | Download | only in sodium
      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 
     37 SODIUM_EXPORT
     38 void randombytes_buf_deterministic(void * const buf, const size_t size,
     39                                    const unsigned char seed[randombytes_SEEDBYTES]);
     40 
     41 SODIUM_EXPORT
     42 uint32_t randombytes_random(void);
     43 
     44 SODIUM_EXPORT
     45 uint32_t randombytes_uniform(const uint32_t upper_bound);
     46 
     47 SODIUM_EXPORT
     48 void randombytes_stir(void);
     49 
     50 SODIUM_EXPORT
     51 int randombytes_close(void);
     52 
     53 SODIUM_EXPORT
     54 int randombytes_set_implementation(randombytes_implementation *impl);
     55 
     56 SODIUM_EXPORT
     57 const char *randombytes_implementation_name(void);
     58 
     59 /* -- NaCl compatibility interface -- */
     60 
     61 SODIUM_EXPORT
     62 void randombytes(unsigned char * const buf, const unsigned long long buf_len);
     63 
     64 #ifdef __cplusplus
     65 }
     66 #endif
     67 
     68 #endif
     69