crypto_rand.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. uint64_t crypto_rand_uint64(uint64_t max);
  27. double crypto_rand_double(void);
  28. struct tor_weak_rng_t;
  29. void crypto_seed_weak_rng(struct tor_weak_rng_t *rng);
  30. char *crypto_random_hostname(int min_rand_len, int max_rand_len,
  31. const char *prefix, const char *suffix);
  32. struct smartlist_t;
  33. void *smartlist_choose(const struct smartlist_t *sl);
  34. void smartlist_shuffle(struct smartlist_t *sl);
  35. int crypto_force_rand_ssleay(void);
  36. #ifdef CRYPTO_RAND_PRIVATE
  37. STATIC int crypto_strongest_rand_raw(uint8_t *out, size_t out_len);
  38. #ifdef TOR_UNIT_TESTS
  39. extern int break_strongest_rng_syscall;
  40. extern int break_strongest_rng_fallback;
  41. #endif
  42. #endif /* defined(CRYPTO_RAND_PRIVATE) */
  43. #endif /* !defined(TOR_CRYPTO_RAND_H) */