weakrng.h 800 B

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