diff options
author | Nick Mathewson <nickm@torproject.org> | 2010-06-22 21:31:31 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2010-06-25 21:33:22 -0400 |
commit | b111a7cd9c5e09bedf57a67f9044a2974222cd11 (patch) | |
tree | 325adafdbc70188d95bfca098b86f506f5f28530 /src/common | |
parent | 006e2e8620fa9001c8df24463c06538cf58ce396 (diff) | |
download | tor-b111a7cd9c5e09bedf57a67f9044a2974222cd11.tar.gz tor-b111a7cd9c5e09bedf57a67f9044a2974222cd11.zip |
Make cbt_generate_sample use crypto_rand_double()
Possible workaround for bug 1139, if anybody cares.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/crypto.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index 23e2a429f5..38fbca717f 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -2065,10 +2065,15 @@ crypto_rand_double(void) /* We just use an unsigned int here; we don't really care about getting * more than 32 bits of resolution */ unsigned int uint; - do { - crypto_rand((char*)&uint, sizeof(uint)); - } while (uint == UINT_MAX); - return ((double)uint) / (double)UINT_MAX; + crypto_rand((char*)&uint, sizeof(uint)); +#if SIZEOF_INT == 4 +#define UINT_MAX_AS_DOUBLE 4294967296.0 +#elif SIZEOF_INT == 8 +#define UINT_MAX_AS_DOUBLE 1.8446744073709552e+19 +#else +#error SIZEOF_INT is neither 4 nor 8 +#endif + return ((double)uint) / UINT_MAX_AS_DOUBLE; } /** Generate and return a new random hostname starting with <b>prefix</b>, |