2018-06-28 11:39:49 -04:00
|
|
|
/* Copyright (c) 2003, Roger Dingledine
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2019-01-16 12:33:22 -05:00
|
|
|
* Copyright (c) 2007-2019, The Tor Project, Inc. */
|
2018-06-28 11:39:49 -04:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
2018-07-01 20:22:55 -04:00
|
|
|
/**
|
|
|
|
* \file weakrng.h
|
|
|
|
*
|
|
|
|
* \brief Header for weakrng.c
|
|
|
|
**/
|
|
|
|
|
2018-06-28 11:39:49 -04:00
|
|
|
#ifndef TOR_WEAKRNG_H
|
|
|
|
#define TOR_WEAKRNG_H
|
|
|
|
|
|
|
|
#include "lib/cc/torint.h"
|
|
|
|
|
|
|
|
/* ===== 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)))
|
|
|
|
|
2019-06-05 09:33:35 -04:00
|
|
|
#endif /* !defined(TOR_WEAKRNG_H) */
|