diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-10-06 22:18:01 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-10-06 22:18:01 +0000 |
commit | cc35e1720f7dde775e2c8246c2f9b542954e401f (patch) | |
tree | 68a8b834a6d2a466d883a733923168ea915d4205 /src/common/crypto.c | |
parent | 0e5b6a84eb1ab156437d24c2fc1cb61249b008d4 (diff) | |
download | tor-cc35e1720f7dde775e2c8246c2f9b542954e401f.tar.gz tor-cc35e1720f7dde775e2c8246c2f9b542954e401f.zip |
Using RAND_pseudo_bytes instead of RAND_bytes is an accident waiting to happen, and does not really speed us up much when we do it. So stop doing it.
svn:r5210
Diffstat (limited to 'src/common/crypto.c')
-rw-r--r-- | src/common/crypto.c | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index 120d0c1cac..16d1734ac4 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -1645,24 +1645,10 @@ crypto_rand(char *to, size_t n) return (r == 1) ? 0 : -1; } -/** Write n bytes of pseudorandom data to <b>to</b>. Return 0 on - * success, -1 on failure. - */ -void -crypto_pseudo_rand(char *to, size_t n) -{ - tor_assert(to); - if (RAND_pseudo_bytes((unsigned char*)to, n) == -1) { - log_fn(LOG_ERR, "RAND_pseudo_bytes failed unexpectedly."); - crypto_log_errors(LOG_WARN, "generating random data"); - exit(1); - } -} - /** Return a pseudorandom integer, chosen uniformly from the values * between 0 and max-1. */ int -crypto_pseudo_rand_int(unsigned int max) +crypto_rand_int(unsigned int max) { unsigned int val; unsigned int cutoff; @@ -1675,7 +1661,7 @@ crypto_pseudo_rand_int(unsigned int max) */ cutoff = UINT_MAX - (UINT_MAX%max); while (1) { - crypto_pseudo_rand((char*)&val, sizeof(val)); + crypto_rand((char*)&val, sizeof(val)); if (val < cutoff) return val % max; } @@ -1689,7 +1675,7 @@ smartlist_choose(const smartlist_t *sl) size_t len; len = smartlist_len(sl); if (len) - return smartlist_get(sl,crypto_pseudo_rand_int(len)); + return smartlist_get(sl,crypto_rand_int(len)); return NULL; /* no elements to choose from */ } |