gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r30460 - in gnunet/src: include util


From: gnunet
Subject: [GNUnet-SVN] r30460 - in gnunet/src: include util
Date: Tue, 29 Oct 2013 17:41:02 +0100

Author: wachs
Date: 2013-10-29 17:41:02 +0100 (Tue, 29 Oct 2013)
New Revision: 30460

Modified:
   gnunet/src/include/gnunet_crypto_lib.h
   gnunet/src/util/crypto_random.c
Log:
function to fill buffer with random values


Modified: gnunet/src/include/gnunet_crypto_lib.h
===================================================================
--- gnunet/src/include/gnunet_crypto_lib.h      2013-10-29 16:14:10 UTC (rev 
30459)
+++ gnunet/src/include/gnunet_crypto_lib.h      2013-10-29 16:41:02 UTC (rev 
30460)
@@ -410,6 +410,17 @@
 
 /**
  * @ingroup crypto
+ * Fill block with a random values.
+ *
+ * @param mode desired quality of the random number
+ * @param buffer the buffer to fill
+ * @param length buffer length
+ */
+void
+GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode, void *buffer, 
size_t length);
+
+/**
+ * @ingroup crypto
  * Produce a random value.
  *
  * @param mode desired quality of the random number

Modified: gnunet/src/util/crypto_random.c
===================================================================
--- gnunet/src/util/crypto_random.c     2013-10-29 16:14:10 UTC (rev 30459)
+++ gnunet/src/util/crypto_random.c     2013-10-29 16:41:02 UTC (rev 30460)
@@ -95,7 +95,48 @@
   SRANDOM (seed);
 }
 
+/**
+ * @ingroup crypto
+ * Fill block with a random values.
+ *
+ * @param mode desired quality of the random number
+ * @param buffer the buffer to fill
+ * @param length buffer length
+ */
+void
+GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode, void *buffer, 
size_t length)
+{
+#ifdef gcry_fast_random_poll
+  static unsigned int invokeCount;
+#endif
+  switch (mode)
+  {
+  case GNUNET_CRYPTO_QUALITY_STRONG:
+    /* see http://lists.gnupg.org/pipermail/gcrypt-devel/2004-May/000613.html 
*/
+#ifdef gcry_fast_random_poll
+    if ((invokeCount++ % 256) == 0)
+      gcry_fast_random_poll ();
+#endif
+    gcry_randomize (buffer, length, GCRY_STRONG_RANDOM);
+    return;
+  case GNUNET_CRYPTO_QUALITY_NONCE:
+    gcry_create_nonce (buffer, length);
+    return;
+  case GNUNET_CRYPTO_QUALITY_WEAK:
+    /* see http://lists.gnupg.org/pipermail/gcrypt-devel/2004-May/000613.html 
*/
+#ifdef gcry_fast_random_poll
+    if ((invokeCount++ % 256) == 0)
+      gcry_fast_random_poll ();
+#endif
+    gcry_randomize (buffer, length, GCRY_WEAK_RANDOM);
+    return;
+    return;
+  default:
+    GNUNET_assert (0);
+  }
+}
 
+
 /**
  * Produce a random value.
  *




reply via email to

[Prev in Thread] Current Thread [Next in Thread]