From 3b2822c3b587365589a8a98c37256ac4588d1a04 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 9 Jul 2009 16:27:12 +0000 Subject: [PATCH] use libgcrypt entropy progress callback to fork a find to hopefully generate entropy --- src/util/crypto_ksk.c | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/util/crypto_ksk.c b/src/util/crypto_ksk.c index c3461ae61..4b6d72764 100644 --- a/src/util/crypto_ksk.c +++ b/src/util/crypto_ksk.c @@ -35,6 +35,7 @@ #include "platform.h" #include "gnunet_common.h" #include "gnunet_crypto_lib.h" +#include "gnunet_os_lib.h" #include #include @@ -761,6 +762,50 @@ GNUNET_CRYPTO_rsa_key_create_from_hash (const GNUNET_HashCode * hc) 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 @@ void __attribute__ ((constructor)) GNUNET_CRYPTO_ksk_init () #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 */ -- 2.25.1