crypto_rand.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Copyright (c) 2001, Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file crypto_rand.h
  8. *
  9. * \brief Common functions for using (psuedo-)random number generators.
  10. **/
  11. #ifndef TOR_CRYPTO_RAND_H
  12. #define TOR_CRYPTO_RAND_H
  13. #include "torint.h"
  14. #include "util.h"
  15. /* random numbers */
  16. int crypto_seed_rng(void) ATTR_WUR;
  17. MOCK_DECL(void,crypto_rand,(char *to, size_t n));
  18. void crypto_rand_unmocked(char *to, size_t n);
  19. void crypto_strongest_rand(uint8_t *out, size_t out_len);
  20. int crypto_rand_int(unsigned int max);
  21. int crypto_rand_int_range(unsigned int min, unsigned int max);
  22. uint64_t crypto_rand_uint64_range(uint64_t min, uint64_t max);
  23. time_t crypto_rand_time_range(time_t min, time_t max);
  24. uint64_t crypto_rand_uint64(uint64_t max);
  25. double crypto_rand_double(void);
  26. struct tor_weak_rng_t;
  27. void crypto_seed_weak_rng(struct tor_weak_rng_t *rng);
  28. char *crypto_random_hostname(int min_rand_len, int max_rand_len,
  29. const char *prefix, const char *suffix);
  30. struct smartlist_t;
  31. void *smartlist_choose(const struct smartlist_t *sl);
  32. void smartlist_shuffle(struct smartlist_t *sl);
  33. int crypto_force_rand_ssleay(void);
  34. #ifdef CRYPTO_RAND_PRIVATE
  35. STATIC int crypto_strongest_rand_raw(uint8_t *out, size_t out_len);
  36. #ifdef TOR_UNIT_TESTS
  37. extern int break_strongest_rng_syscall;
  38. extern int break_strongest_rng_fallback;
  39. #endif
  40. #endif /* defined(CRYPTO_RAND_PRIVATE) */
  41. #endif /* !defined(TOR_CRYPTO_RAND_H) */