aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_random.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-04-22 09:21:18 +0000
committerChristian Grothoff <christian@grothoff.org>2010-04-22 09:21:18 +0000
commit79dea1de0667904be4ec99d7b65a61fa966da3f3 (patch)
tree0738167e2e560df1d0e8c7b553bc8125b21bb38b /src/util/crypto_random.c
parente333bd101e59a42d91b50f959c749aeddef2546a (diff)
downloadgnunet-79dea1de0667904be4ec99d7b65a61fa966da3f3.tar.gz
gnunet-79dea1de0667904be4ec99d7b65a61fa966da3f3.zip
make weakness more explicit
Diffstat (limited to 'src/util/crypto_random.c')
-rw-r--r--src/util/crypto_random.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c
index 5d85d1daa..35dafd071 100644
--- a/src/util/crypto_random.c
+++ b/src/util/crypto_random.c
@@ -30,6 +30,18 @@
30#include <gcrypt.h> 30#include <gcrypt.h>
31 31
32/** 32/**
33 * Create a cryptographically weak pseudo-random number in the interval of 0 to 1.
34 *
35 * @return number between 0 and 1.
36 */
37static double
38weak_random ()
39{
40 return ((double) RANDOM () / RAND_MAX);
41}
42
43
44/**
33 * Produce a random value. 45 * Produce a random value.
34 * 46 *
35 * @param mode desired quality of the random number 47 * @param mode desired quality of the random number
@@ -59,7 +71,7 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i)
59 } 71 }
60 else 72 else
61 { 73 {
62 ret = i * ((double) RANDOM () / RAND_MAX); 74 ret = i * weak_random ();
63 if (ret >= i) 75 if (ret >= i)
64 ret = i - 1; 76 ret = i - 1;
65 return ret; 77 return ret;
@@ -119,7 +131,7 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max)
119 } 131 }
120 else 132 else
121 { 133 {
122 ret = max * ((double) RANDOM () / RAND_MAX); 134 ret = max * weak_random ();
123 if (ret >= max) 135 if (ret >= max)
124 ret = max - 1; 136 ret = max - 1;
125 return ret; 137 return ret;