diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-02-11 11:28:08 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-02-11 11:28:08 -0500 |
commit | 2b4d4ccb3d1ecf984012b39eb361307785b0c1c0 (patch) | |
tree | 037f87559f31a6804bdf62ab9c948f3138990fae /src/common/util.h | |
parent | d86a45f991693cf2367a6ccb94fc29c22f5f7b45 (diff) | |
parent | 69ab7cd8281dcb312eb47b738d1c620e7bc042d9 (diff) | |
download | tor-2b4d4ccb3d1ecf984012b39eb361307785b0c1c0.tar.gz tor-2b4d4ccb3d1ecf984012b39eb361307785b0c1c0.zip |
Merge remote-tracking branch 'public/bug7801_v2'
Diffstat (limited to 'src/common/util.h')
-rw-r--r-- | src/common/util.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/common/util.h b/src/common/util.h index 911b1b5a37..ac88f1ca1c 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -494,6 +494,20 @@ int tor_terminate_process(process_handle_t *process_handle); void tor_process_handle_destroy(process_handle_t *process_handle, int also_terminate_process); +/* ===== Insecure rng */ +typedef struct tor_weak_rng_t { + uint32_t state; +} tor_weak_rng_t; + +#define TOR_WEAK_RNG_INIT {383745623} +#define TOR_WEAK_RANDOM_MAX (INT_MAX) +void tor_init_weak_random(tor_weak_rng_t *weak_rng, unsigned seed); +int32_t tor_weak_random(tor_weak_rng_t *weak_rng); +int32_t tor_weak_random_range(tor_weak_rng_t *rng, int32_t top); +/** Randomly return true according to <b>rng</b> with probability 1 in + * <b>n</b> */ +#define tor_weak_random_one_in_n(rng, n) (0==tor_weak_random_range((rng),(n))) + #ifdef UTIL_PRIVATE /* Prototypes for private functions only used by util.c (and unit tests) */ |