make weakness more explicit
authorChristian Grothoff <christian@grothoff.org>
Thu, 22 Apr 2010 09:21:18 +0000 (09:21 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 22 Apr 2010 09:21:18 +0000 (09:21 +0000)
src/util/crypto_random.c

index 5d85d1daa1376d5b2f96b5f2ba146acd69e8664a..35dafd071b98afcda77b4b4d95c19927e645aeaf 100644 (file)
 #include "gnunet_crypto_lib.h"
 #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.
  *
@@ -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;