gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r8649 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r8649 - gnunet/src/util
Date: Thu, 9 Jul 2009 10:27:12 -0600

Author: grothoff
Date: 2009-07-09 10:27:12 -0600 (Thu, 09 Jul 2009)
New Revision: 8649

Modified:
   gnunet/src/util/crypto_ksk.c
Log:
use libgcrypt entropy progress callback to fork a find to hopefully generate 
entropy

Modified: gnunet/src/util/crypto_ksk.c
===================================================================
--- gnunet/src/util/crypto_ksk.c        2009-07-08 23:09:41 UTC (rev 8648)
+++ gnunet/src/util/crypto_ksk.c        2009-07-09 16:27:12 UTC (rev 8649)
@@ -35,6 +35,7 @@
 #include "platform.h"
 #include "gnunet_common.h"
 #include "gnunet_crypto_lib.h"
+#include "gnunet_os_lib.h"
 #include <gmp.h>
 #include <gcrypt.h>
 
@@ -761,6 +762,50 @@
   return ksk_decode_key (line->pke);
 }
 
+
+/* Used to register a progress callback.  This needs to be called
+   before any threads are created. */
+void
+_gcry_register_random_progress (void (*cb)(void *,const char*,int,int,int),
+                                void *cb_data );
+
+
+/**
+ * Function called by libgcrypt whenever we are
+ * blocked gathering entropy.
+ */
+static void
+entropy_generator (void *cls, 
+                  const char *what,
+                  int printchar,
+                  int current,
+                  int total)
+{
+  static pid_t genproc;
+  if (0 != strcmp (what, "need_entropy"))
+    return;
+  if (current == total)
+    {
+      if (genproc != 0)
+       {
+         PLIBC_KILL(genproc, SIGKILL);
+         GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
+         genproc = 0;
+       }
+      return;
+    }
+  genproc = GNUNET_OS_start_process ("find",
+                                    "find",
+                                    "-type",
+                                    "s",
+                                    "-fprint",
+                                    "/dev/null",
+                                    NULL);
+                                   
+
+}
+
+
 void __attribute__ ((constructor)) GNUNET_CRYPTO_ksk_init ()
 {
   gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
@@ -775,17 +820,20 @@
 #ifdef gcry_fast_random_poll
   gcry_fast_random_poll ();
 #endif
+  _gcry_register_random_progress (&entropy_generator, NULL);
 }
 
 void __attribute__ ((destructor)) GNUNET_CRYPTO_ksk_fini ()
 {
   int i;
+
   for (i = 0; i < cacheSize; i++)
     {
       GNUNET_free (cache[i]->pke);
       GNUNET_free (cache[i]);
     }
   GNUNET_array_grow (cache, cacheSize, 0);
+  _gcry_register_random_progress (NULL, NULL);
 }
 
 /* end of kblockkey.c */





reply via email to

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