aboutsummaryrefslogtreecommitdiff
path: root/src/common/crypto.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-02-08 16:28:05 -0500
committerNick Mathewson <nickm@torproject.org>2013-02-08 16:28:05 -0500
commit8cdd8b83539e57fb1891cce5b527dda335ab1452 (patch)
tree656a1bbdfe0c240a810333c803b3c2a718cf7a13 /src/common/crypto.c
parentfd1c2a13e7558086732288eb1a4f52aef2edeb2f (diff)
downloadtor-8cdd8b83539e57fb1891cce5b527dda335ab1452.tar
tor-8cdd8b83539e57fb1891cce5b527dda335ab1452.tar.gz
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/crypto.c')
-rw-r--r--src/common/crypto.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 70bd45299..22d57c7c8 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -2337,12 +2337,12 @@ crypto_dh_free(crypto_dh_t *dh)
(OPENSSL_VERSION_NUMBER >= OPENSSL_V(0,9,8,'c'))
/** Set the seed of the weak RNG to a random value. */
-static void
-seed_weak_rng(void)
+void
+crypto_seed_weak_rng(tor_weak_rng_t *rng)
{
unsigned seed;
crypto_rand((void*)&seed, sizeof(seed));
- tor_init_weak_random(seed);
+ tor_init_weak_random(rng, seed);
}
/** Try to get <b>out_len</b> bytes of the strongest entropy we can generate,
@@ -2426,7 +2426,7 @@ crypto_seed_rng(int startup)
}
memwipe(buf, 0, sizeof(buf));
- seed_weak_rng();
+
if (rand_poll_ok || load_entropy_ok)
return 0;
else