diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-02-08 16:28:05 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-02-08 16:28:05 -0500 |
commit | 8cdd8b83539e57fb1891cce5b527dda335ab1452 (patch) | |
tree | 656a1bbdfe0c240a810333c803b3c2a718cf7a13 /src/common/compat.c | |
parent | fd1c2a13e7558086732288eb1a4f52aef2edeb2f (diff) | |
download | tor-8cdd8b83539e57fb1891cce5b527dda335ab1452.tar.gz tor-8cdd8b83539e57fb1891cce5b527dda335ab1452.zip |
Fix numerous problems with Tor's weak RNG.
We need a weak RNG in a couple of places where the strong RNG is
both needless and too slow. We had been using the weak RNG from our
platform's libc implementation, but that was problematic (because
many platforms have exceptionally horrible weak RNGs -- like, ones
that only return values between 0 and SHORT_MAX) and because we were
using it in a way that was wrong for LCG-based weak RNGs. (We were
counting on the low bits of the LCG output to be as random as the
high ones, which isn't true.)
This patch adds a separate type for a weak RNG, adds an LCG
implementation for it, and uses that exclusively where we had been
using the platform weak RNG.
Diffstat (limited to 'src/common/compat.c')
-rw-r--r-- | src/common/compat.c | 24 |
1 files changed, 0 insertions, 24 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index 3b15f8ad24..d7ce89479a 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -2059,30 +2059,6 @@ tor_lookup_hostname(const char *name, uint32_t *addr) return -1; } -/** Initialize the insecure libc RNG. */ -void -tor_init_weak_random(unsigned seed) -{ -#ifdef _WIN32 - srand(seed); -#else - srandom(seed); -#endif -} - -/** Return a randomly chosen value in the range 0..TOR_RAND_MAX. This - * entropy will not be cryptographically strong; do not rely on it - * for anything an adversary should not be able to predict. */ -long -tor_weak_random(void) -{ -#ifdef _WIN32 - return rand(); -#else - return random(); -#endif -} - /** Hold the result of our call to <b>uname</b>. */ static char uname_result[256]; /** True iff uname_result is set. */ |