From: Christian Grothoff Date: Thu, 22 Apr 2010 09:21:18 +0000 (+0000) Subject: make weakness more explicit X-Git-Tag: initial-import-from-subversion-38251~22046 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=79dea1de0667904be4ec99d7b65a61fa966da3f3;p=oweals%2Fgnunet.git make weakness more explicit --- 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 @@ -29,6 +29,18 @@ #include "gnunet_crypto_lib.h" #include +/** + * 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. * @@ -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;