diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-04-22 09:21:18 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-04-22 09:21:18 +0000 |
commit | 79dea1de0667904be4ec99d7b65a61fa966da3f3 (patch) | |
tree | 0738167e2e560df1d0e8c7b553bc8125b21bb38b /src/util/crypto_random.c | |
parent | e333bd101e59a42d91b50f959c749aeddef2546a (diff) |
make weakness more explicit
Diffstat (limited to 'src/util/crypto_random.c')
-rw-r--r-- | src/util/crypto_random.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c index 5d85d1daa1..35dafd071b 100644 --- a/src/util/crypto_random.c +++ b/src/util/crypto_random.c @@ -30,6 +30,18 @@ #include <gcrypt.h> /** + * Create a cryptographically weak pseudo-random number in the interval of 0 to 1. + * + * @return number between 0 and 1. + */ +static double +weak_random () +{ + return ((double) RANDOM () / RAND_MAX); +} + + +/** * Produce a random value. * * @param mode desired quality of the random number @@ -59,7 +71,7 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i) } else { - ret = i * ((double) RANDOM () / RAND_MAX); + ret = i * weak_random (); if (ret >= i) ret = i - 1; return ret; @@ -119,7 +131,7 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max) } else { - ret = max * ((double) RANDOM () / RAND_MAX); + ret = max * weak_random (); if (ret >= max) ret = max - 1; return ret; |