tor  0.4.1.0-alpha-dev
Functions
weakrng.c File Reference
#include "lib/intmath/weakrng.h"
#include "lib/err/torerr.h"
#include <stdlib.h>

Go to the source code of this file.

Functions

void tor_init_weak_random (tor_weak_rng_t *rng, unsigned seed)
 
int32_t tor_weak_random (tor_weak_rng_t *rng)
 
int32_t tor_weak_random_range (tor_weak_rng_t *rng, int32_t top)
 

Detailed Description

A weak but fast PRNG based on a linear congruential generator.

We don't want to use the platform random(), since some of them are even worse than this.

Definition in file weakrng.c.

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.