diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-07-09 16:27:12 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-07-09 16:27:12 +0000 |
commit | 3b2822c3b587365589a8a98c37256ac4588d1a04 (patch) | |
tree | 1ad0a792f15d0d5037461cac03b2c28a8e8c9fba /src/util/crypto_ksk.c | |
parent | 191131b599cc0dc1219930221f84155b870ec6cd (diff) | |
download | gnunet-3b2822c3b587365589a8a98c37256ac4588d1a04.tar.gz gnunet-3b2822c3b587365589a8a98c37256ac4588d1a04.zip |
use libgcrypt entropy progress callback to fork a find to hopefully generate entropy
Diffstat (limited to 'src/util/crypto_ksk.c')
-rw-r--r-- | src/util/crypto_ksk.c | 48 |
1 files changed, 48 insertions, 0 deletions
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 @@ | |||
35 | #include "platform.h" | 35 | #include "platform.h" |
36 | #include "gnunet_common.h" | 36 | #include "gnunet_common.h" |
37 | #include "gnunet_crypto_lib.h" | 37 | #include "gnunet_crypto_lib.h" |
38 | #include "gnunet_os_lib.h" | ||
38 | #include <gmp.h> | 39 | #include <gmp.h> |
39 | #include <gcrypt.h> | 40 | #include <gcrypt.h> |
40 | 41 | ||
@@ -761,6 +762,50 @@ GNUNET_CRYPTO_rsa_key_create_from_hash (const GNUNET_HashCode * hc) | |||
761 | return ksk_decode_key (line->pke); | 762 | return ksk_decode_key (line->pke); |
762 | } | 763 | } |
763 | 764 | ||
765 | |||
766 | /* Used to register a progress callback. This needs to be called | ||
767 | before any threads are created. */ | ||
768 | void | ||
769 | _gcry_register_random_progress (void (*cb)(void *,const char*,int,int,int), | ||
770 | void *cb_data ); | ||
771 | |||
772 | |||
773 | /** | ||
774 | * Function called by libgcrypt whenever we are | ||
775 | * blocked gathering entropy. | ||
776 | */ | ||
777 | static void | ||
778 | entropy_generator (void *cls, | ||
779 | const char *what, | ||
780 | int printchar, | ||
781 | int current, | ||
782 | int total) | ||
783 | { | ||
784 | static pid_t genproc; | ||
785 | if (0 != strcmp (what, "need_entropy")) | ||
786 | return; | ||
787 | if (current == total) | ||
788 | { | ||
789 | if (genproc != 0) | ||
790 | { | ||
791 | PLIBC_KILL(genproc, SIGKILL); | ||
792 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc)); | ||
793 | genproc = 0; | ||
794 | } | ||
795 | return; | ||
796 | } | ||
797 | genproc = GNUNET_OS_start_process ("find", | ||
798 | "find", | ||
799 | "-type", | ||
800 | "s", | ||
801 | "-fprint", | ||
802 | "/dev/null", | ||
803 | NULL); | ||
804 | |||
805 | |||
806 | } | ||
807 | |||
808 | |||
764 | void __attribute__ ((constructor)) GNUNET_CRYPTO_ksk_init () | 809 | void __attribute__ ((constructor)) GNUNET_CRYPTO_ksk_init () |
765 | { | 810 | { |
766 | gcry_control (GCRYCTL_DISABLE_SECMEM, 0); | 811 | gcry_control (GCRYCTL_DISABLE_SECMEM, 0); |
@@ -775,17 +820,20 @@ void __attribute__ ((constructor)) GNUNET_CRYPTO_ksk_init () | |||
775 | #ifdef gcry_fast_random_poll | 820 | #ifdef gcry_fast_random_poll |
776 | gcry_fast_random_poll (); | 821 | gcry_fast_random_poll (); |
777 | #endif | 822 | #endif |
823 | _gcry_register_random_progress (&entropy_generator, NULL); | ||
778 | } | 824 | } |
779 | 825 | ||
780 | void __attribute__ ((destructor)) GNUNET_CRYPTO_ksk_fini () | 826 | void __attribute__ ((destructor)) GNUNET_CRYPTO_ksk_fini () |
781 | { | 827 | { |
782 | int i; | 828 | int i; |
829 | |||
783 | for (i = 0; i < cacheSize; i++) | 830 | for (i = 0; i < cacheSize; i++) |
784 | { | 831 | { |
785 | GNUNET_free (cache[i]->pke); | 832 | GNUNET_free (cache[i]->pke); |
786 | GNUNET_free (cache[i]); | 833 | GNUNET_free (cache[i]); |
787 | } | 834 | } |
788 | GNUNET_array_grow (cache, cacheSize, 0); | 835 | GNUNET_array_grow (cache, cacheSize, 0); |
836 | _gcry_register_random_progress (NULL, NULL); | ||
789 | } | 837 | } |
790 | 838 | ||
791 | /* end of kblockkey.c */ | 839 | /* end of kblockkey.c */ |