From: Christian Grothoff Date: Mon, 11 Feb 2013 23:04:43 +0000 (+0000) Subject: -trying to address #2791 X-Git-Tag: initial-import-from-subversion-38251~9964 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=81e30a126c1a7be76b87acab0b16933d2a5b4064;p=oweals%2Fgnunet.git -trying to address #2791 --- diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 2be833fa0..6e0dbc122 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c @@ -24,6 +24,7 @@ * @author Christian Grothoff */ #include "platform.h" +#include #include "gnunet_util_lib.h" #include "gnunet-service-core.h" #include "gnunet-service-core_clients.h" diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index fb299267b..99d4ac58f 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -1342,26 +1342,6 @@ GNUNET_CRYPTO_ecc_verify (uint32_t purpose, *publicKey); -/** - * This function should only be called in testcases - * where strong entropy gathering is not desired - * (for example, for hostkey generation). - */ -void -GNUNET_CRYPTO_random_disable_entropy_gathering (void); - - -/** - * Check if we are using weak random number generation. - * - * @return GNUNET_YES if weak number generation is on - * (thus will return YES if 'GNUNET_CRYPTO_random_disable_entropy_gathering' - * was called previously). - */ -int -GNUNET_CRYPTO_random_is_weak (void); - - #if 0 /* keep Emacsens' auto-indent happy */ { #endif diff --git a/src/util/configuration.c b/src/util/configuration.c index 72fe0e7d0..c762e3b9c 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -1499,11 +1499,6 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, (filename != NULL)) GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", filename); - if ((GNUNET_YES == - GNUNET_CONFIGURATION_have_value (cfg, "TESTING", "WEAKRANDOM")) && - (GNUNET_YES == - GNUNET_CONFIGURATION_get_value_yesno (cfg, "TESTING", "WEAKRANDOM"))) - GNUNET_CRYPTO_random_disable_entropy_gathering (); return GNUNET_OK; } diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index 97ba2a3b6..2e4ba6a9d 100644 --- a/src/util/crypto_ecc.c +++ b/src/util/crypto_ecc.c @@ -831,7 +831,6 @@ GNUNET_CRYPTO_ecc_key_create_start (const char *filename, { struct GNUNET_CRYPTO_EccKeyGenerationContext *gc; struct GNUNET_CRYPTO_EccPrivateKey *pk; - const char *weak_random; if (NULL != (pk = try_read_key (filename))) { @@ -859,10 +858,6 @@ GNUNET_CRYPTO_ecc_key_create_start (const char *filename, GNUNET_free (gc); return NULL; } - weak_random = NULL; - if (GNUNET_YES == - GNUNET_CRYPTO_random_is_weak ()) - weak_random = "-w"; gc->gnunet_ecc = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ERR, NULL, @@ -870,7 +865,6 @@ GNUNET_CRYPTO_ecc_key_create_start (const char *filename, "gnunet-ecc", "gnunet-ecc", gc->filename, - weak_random, NULL); if (NULL == gc->gnunet_ecc) { diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c index b61d59613..8ba6641b9 100644 --- a/src/util/crypto_random.c +++ b/src/util/crypto_random.c @@ -35,13 +35,6 @@ #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall) -/** - * GNUNET_YES if we are using a 'weak' (low-entropy) PRNG. - */ -static int weak_random; - - - /* TODO: ndurner, move this to plibc? */ /* The code is derived from glibc, obviously */ #if MINGW @@ -236,31 +229,6 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max) } -/** - * Check if we are using weak random number generation. - * - * @return GNUNET_YES if weak number generation is on - */ -int -GNUNET_CRYPTO_random_is_weak () -{ - return weak_random; -} - - -/** - * This function should only be called in testcases - * where strong entropy gathering is not desired - * (for example, for hostkey generation). - */ -void -GNUNET_CRYPTO_random_disable_entropy_gathering () -{ - weak_random = GNUNET_YES; - gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); -} - - /** * Process ID of the "find" process that we use for * entropy gathering. @@ -332,10 +300,12 @@ killfind () } -void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init () +void __attribute__ ((constructor)) +GNUNET_CRYPTO_random_init () { - gcry_control (GCRYCTL_DISABLE_SECMEM, 0); - if (!gcry_check_version (NEED_LIBGCRYPT_VERSION)) + gcry_error_t rc; + + if (! gcry_check_version (NEED_LIBGCRYPT_VERSION)) { FPRINTF (stderr, _ @@ -343,6 +313,15 @@ void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init () NEED_LIBGCRYPT_VERSION); GNUNET_abort (); } + if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0))) + FPRINTF (stderr, "Failed to set libgcrypt option %s: %s\n", "DISABLE_SECMEM", + gcry_strerror (rc)); + /* we only generate ephemeral keys in-process; for those, + we are fine with "just" using GCRY_STRONG_RANDOM */ + if ((rc = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0))) + FPRINTF (stderr, "Failed to set libgcrypt option %s: %s\n", "ENABLE_QUICK_RANDOM", + gcry_strerror (rc)); + #ifdef GCRYCTL_INITIALIZATION_FINISHED gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); #endif @@ -357,7 +336,8 @@ void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init () } -void __attribute__ ((destructor)) GNUNET_CRYPTO_random_fini () +void __attribute__ ((destructor)) +GNUNET_CRYPTO_random_fini () { gcry_set_progress_handler (NULL, NULL); } diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index cd9a33f61..6857a1221 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c @@ -998,7 +998,6 @@ GNUNET_CRYPTO_rsa_key_create_start (const char *filename, { struct GNUNET_CRYPTO_RsaKeyGenerationContext *gc; struct GNUNET_CRYPTO_RsaPrivateKey *pk; - const char *weak_random; if (NULL != (pk = try_read_key (filename))) { @@ -1026,10 +1025,6 @@ GNUNET_CRYPTO_rsa_key_create_start (const char *filename, GNUNET_free (gc); return NULL; } - weak_random = NULL; - if (GNUNET_YES == - GNUNET_CRYPTO_random_is_weak ()) - weak_random = "-w"; gc->gnunet_rsa = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ERR, NULL, @@ -1037,7 +1032,6 @@ GNUNET_CRYPTO_rsa_key_create_start (const char *filename, "gnunet-rsa", "gnunet-rsa", gc->filename, - weak_random, NULL); if (NULL == gc->gnunet_rsa) { diff --git a/src/util/gnunet-ecc.c b/src/util/gnunet-ecc.c index d7f1dd58d..a00ef0573 100644 --- a/src/util/gnunet-ecc.c +++ b/src/util/gnunet-ecc.c @@ -44,11 +44,6 @@ static int print_peer_identity; */ static int print_short_identity; -/** - * Use weak random number generator for key generation. - */ -static int weak_random; - /** * Option set to create a bunch of keys at once. */ @@ -143,8 +138,6 @@ run (void *cls, char *const *args, const char *cfgfile, fprintf (stderr, _("No hostkey file specified on command line\n")); return; } - if (0 != weak_random) - GNUNET_CRYPTO_random_disable_entropy_gathering (); if (make_keys > 0) { create_keys (args[0]); @@ -208,9 +201,6 @@ main (int argc, char *const *argv) { 's', "print-short-identity", NULL, gettext_noop ("print the short hash of the public key in ASCII format"), 0, &GNUNET_GETOPT_set_one, &print_short_identity }, - { 'w', "weak-random", NULL, - gettext_noop ("use insecure, weak random number generator for key generation (for testing only)"), - 0, &GNUNET_GETOPT_set_one, &weak_random }, GNUNET_GETOPT_OPTION_END }; int ret; diff --git a/src/util/gnunet-rsa.c b/src/util/gnunet-rsa.c index 1e7132d3f..ab4bf2cb0 100644 --- a/src/util/gnunet-rsa.c +++ b/src/util/gnunet-rsa.c @@ -43,11 +43,6 @@ static int print_peer_identity; */ static int print_short_identity; -/** - * Use weak random number generator for key generation. - */ -static int weak_random; - /** * Main function that will be run by the scheduler. @@ -70,8 +65,6 @@ run (void *cls, char *const *args, const char *cfgfile, fprintf (stderr, _("No hostkey file specified on command line\n")); return; } - if (0 != weak_random) - GNUNET_CRYPTO_random_disable_entropy_gathering (); pk = GNUNET_CRYPTO_rsa_key_create_from_file (args[0]); if (NULL == pk) return; @@ -127,9 +120,6 @@ main (int argc, char *const*argv) { 's', "print-short-identity", NULL, gettext_noop ("print the short hash of the public key in ASCII format"), 0, &GNUNET_GETOPT_set_one, &print_short_identity }, - { 'w', "weak-random", NULL, - gettext_noop ("use insecure, weak random number generator for key generation (for testing only)"), - 0, &GNUNET_GETOPT_set_one, &weak_random }, GNUNET_GETOPT_OPTION_END }; int ret; diff --git a/src/util/test_crypto_aes.c b/src/util/test_crypto_aes.c index 88b51188e..1c5897c1e 100644 --- a/src/util/test_crypto_aes.c +++ b/src/util/test_crypto_aes.c @@ -147,7 +147,6 @@ main (int argc, char *argv[]) int failureCount = 0; GNUNET_log_setup ("test-crypto-aes", "WARNING", NULL); - GNUNET_CRYPTO_random_disable_entropy_gathering (); GNUNET_assert (strlen (INITVALUE) > sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); failureCount += testSymcipher (); diff --git a/src/util/test_crypto_aes_weak.c b/src/util/test_crypto_aes_weak.c index 201bfeb5d..f2ddf2012 100644 --- a/src/util/test_crypto_aes_weak.c +++ b/src/util/test_crypto_aes_weak.c @@ -175,7 +175,6 @@ main (int argc, char *argv[]) int weak_keys; GNUNET_log_setup ("test-crypto-aes-weak", "WARNING", NULL); - GNUNET_CRYPTO_random_disable_entropy_gathering (); if (GENERATE_WEAK_KEYS) { weak_keys = getWeakKeys (); diff --git a/src/util/test_crypto_ecc.c b/src/util/test_crypto_ecc.c index 6dac1763f..1adb41888 100644 --- a/src/util/test_crypto_ecc.c +++ b/src/util/test_crypto_ecc.c @@ -216,7 +216,6 @@ main (int argc, char *argv[]) return 0; } GNUNET_log_setup ("test-crypto-ecc", "WARNING", NULL); - GNUNET_CRYPTO_random_disable_entropy_gathering (); if (GNUNET_OK != testCreateFromFile ()) failureCount++; GNUNET_SCHEDULER_run (&test_async_creation, NULL); diff --git a/src/util/test_crypto_rsa.c b/src/util/test_crypto_rsa.c index ee673786d..6574cc970 100644 --- a/src/util/test_crypto_rsa.c +++ b/src/util/test_crypto_rsa.c @@ -325,7 +325,6 @@ main (int argc, char *argv[]) int failureCount = 0; GNUNET_log_setup ("test-crypto-rsa", "WARNING", NULL); - GNUNET_CRYPTO_random_disable_entropy_gathering (); if (GNUNET_OK != testCreateFromFile ()) failureCount++; GNUNET_SCHEDULER_run (&test_async_creation, NULL); diff --git a/src/util/test_pseudonym.c b/src/util/test_pseudonym.c index 9b5085b25..56159be1c 100644 --- a/src/util/test_pseudonym.c +++ b/src/util/test_pseudonym.c @@ -112,7 +112,6 @@ main (int argc, char *argv[]) GNUNET_log_setup ("test-pseudonym", "WARNING", NULL); ok = GNUNET_YES; - GNUNET_CRYPTO_random_disable_entropy_gathering (); (void) GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"); cfg = GNUNET_CONFIGURATION_create (); if (-1 == GNUNET_CONFIGURATION_parse (cfg, "test_pseudonym_data.conf"))