randombytes.h 1.9 KB

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