crypto_rand.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 (pseudo-)random number generators.
  10. **/
  11. #ifndef TOR_CRYPTO_RAND_H
  12. #define TOR_CRYPTO_RAND_H
  13. #include "lib/cc/compat_compiler.h"
  14. #include "lib/cc/torint.h"
  15. #include "lib/testsupport/testsupport.h"
  16. /* random numbers */
  17. int crypto_seed_rng(void) ATTR_WUR;
  18. MOCK_DECL(void,crypto_rand,(char *to, size_t n));
  19. void crypto_rand_unmocked(char *to, size_t n);
  20. void crypto_strongest_rand(uint8_t *out, size_t out_len);
  21. MOCK_DECL(void,crypto_strongest_rand_,(uint8_t *out, size_t out_len));
  22. int crypto_rand_int(unsigned int max);
  23. int crypto_rand_int_range(unsigned int min, unsigned int max);
  24. uint64_t crypto_rand_uint64_range(uint64_t min, uint64_t max);
  25. time_t crypto_rand_time_range(time_t min, time_t max);
  26. uint32_t crypto_rand_u32(void);
  27. uint64_t crypto_rand_uint64(uint64_t max);
  28. double crypto_rand_double(void);
  29. struct tor_weak_rng_t;
  30. void crypto_seed_weak_rng(struct tor_weak_rng_t *rng);
  31. char *crypto_random_hostname(int min_rand_len, int max_rand_len,
  32. const char *prefix, const char *suffix);
  33. struct smartlist_t;
  34. void *smartlist_choose(const struct smartlist_t *sl);
  35. void smartlist_shuffle(struct smartlist_t *sl);
  36. int crypto_force_rand_ssleay(void);
  37. #ifdef CRYPTO_RAND_PRIVATE
  38. STATIC int crypto_strongest_rand_raw(uint8_t *out, size_t out_len);
  39. #ifdef TOR_UNIT_TESTS
  40. extern int break_strongest_rng_syscall;
  41. extern int break_strongest_rng_fallback;
  42. #endif
  43. #endif /* defined(CRYPTO_RAND_PRIVATE) */
  44. #endif /* !defined(TOR_CRYPTO_RAND_H) */