Tor  0.4.7.0-alpha-dev
weakrng.h
Go to the documentation of this file.
1 /* Copyright (c) 2003, Roger Dingledine
2  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3  * Copyright (c) 2007-2021, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
5 
6 /**
7  * \file weakrng.h
8  *
9  * \brief Header for weakrng.c
10  **/
11 
12 #ifndef TOR_WEAKRNG_H
13 #define TOR_WEAKRNG_H
14 
15 #include "lib/cc/torint.h"
16 
17 /* ===== Insecure rng */
18 typedef struct tor_weak_rng_t {
19  uint32_t state;
21 
22 #ifndef COCCI
23 #define TOR_WEAK_RNG_INIT {383745623}
24 #endif
25 #define TOR_WEAK_RANDOM_MAX (INT_MAX)
26 
27 void tor_init_weak_random(tor_weak_rng_t *weak_rng, unsigned seed);
28 int32_t tor_weak_random(tor_weak_rng_t *weak_rng);
29 int32_t tor_weak_random_range(tor_weak_rng_t *rng, int32_t top);
30 /** Randomly return true according to <b>rng</b> with probability 1 in
31  * <b>n</b> */
32 #define tor_weak_random_one_in_n(rng, n) (0==tor_weak_random_range((rng),(n)))
33 
34 #endif /* !defined(TOR_WEAKRNG_H) */
Integer definitions used throughout Tor.
int32_t tor_weak_random_range(tor_weak_rng_t *rng, int32_t top)
Definition: weakrng.c:48
int32_t tor_weak_random(tor_weak_rng_t *weak_rng)
Definition: weakrng.c:32
void tor_init_weak_random(tor_weak_rng_t *weak_rng, unsigned seed)
Definition: weakrng.c:22