weakrng.h 863 B

12345678910111213141516171819202122232425262728293031
  1. /* Copyright (c) 2003, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2019, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. /**
  6. * \file weakrng.h
  7. *
  8. * \brief Header for weakrng.c
  9. **/
  10. #ifndef TOR_WEAKRNG_H
  11. #define TOR_WEAKRNG_H
  12. #include "lib/cc/torint.h"
  13. /* ===== Insecure rng */
  14. typedef struct tor_weak_rng_t {
  15. uint32_t state;
  16. } tor_weak_rng_t;
  17. #define TOR_WEAK_RNG_INIT {383745623}
  18. #define TOR_WEAK_RANDOM_MAX (INT_MAX)
  19. void tor_init_weak_random(tor_weak_rng_t *weak_rng, unsigned seed);
  20. int32_t tor_weak_random(tor_weak_rng_t *weak_rng);
  21. int32_t tor_weak_random_range(tor_weak_rng_t *rng, int32_t top);
  22. /** Randomly return true according to <b>rng</b> with probability 1 in
  23. * <b>n</b> */
  24. #define tor_weak_random_one_in_n(rng, n) (0==tor_weak_random_range((rng),(n)))
  25. #endif