Tor  0.4.7.0-alpha-dev
Data Structures | Macros | Functions
weakrng.h File Reference

Header for weakrng.c. More...

#include "lib/cc/torint.h"

Go to the source code of this file.

Data Structures

struct  tor_weak_rng_t
 

Macros

#define TOR_WEAK_RNG_INIT   {383745623}
 
#define TOR_WEAK_RANDOM_MAX   (INT_MAX)
 
#define tor_weak_random_one_in_n(rng, n)   (0==tor_weak_random_range((rng),(n)))
 

Functions

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)
 

Detailed Description

Header for weakrng.c.

Definition in file weakrng.h.

Macro Definition Documentation

◆ tor_weak_random_one_in_n

#define tor_weak_random_one_in_n (   rng,
 
)    (0==tor_weak_random_range((rng),(n)))

Randomly return true according to rng with probability 1 in n

Definition at line 32 of file weakrng.h.

Function Documentation

◆ tor_init_weak_random()

void tor_init_weak_random ( tor_weak_rng_t rng,
unsigned  seed 
)

Initialize the insecure RNG rng from a seed value seed.

Definition at line 22 of file weakrng.c.

Referenced by crypto_seed_weak_rng().

◆ tor_weak_random()

int32_t tor_weak_random ( tor_weak_rng_t rng)

Return a randomly chosen value in the range 0..TOR_WEAK_RANDOM_MAX based on the RNG state of rng. This entropy will not be cryptographically strong; do not rely on it for anything an adversary should not be able to predict.

Definition at line 32 of file weakrng.c.

◆ tor_weak_random_range()

int32_t tor_weak_random_range ( tor_weak_rng_t rng,
int32_t  top 
)

Return a random number in the range [0 , top). {That is, the range of integers i such that 0 <= i < top.} Chooses uniformly. Requires that top is greater than 0. This randomness is not cryptographically strong; do not rely on it for anything an adversary should not be able to predict.

Definition at line 48 of file weakrng.c.