-trying to address #2791
authorChristian Grothoff <christian@grothoff.org>
Mon, 11 Feb 2013 23:04:43 +0000 (23:04 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 11 Feb 2013 23:04:43 +0000 (23:04 +0000)
13 files changed:
src/core/gnunet-service-core.c
src/include/gnunet_crypto_lib.h
src/util/configuration.c
src/util/crypto_ecc.c
src/util/crypto_random.c
src/util/crypto_rsa.c
src/util/gnunet-ecc.c
src/util/gnunet-rsa.c
src/util/test_crypto_aes.c
src/util/test_crypto_aes_weak.c
src/util/test_crypto_ecc.c
src/util/test_crypto_rsa.c
src/util/test_pseudonym.c

index 2be833fa04c38cae36c7d239c110e96cea18e38c..6e0dbc122c332401a6f7b0a7afac160812a46234 100644 (file)
@@ -24,6 +24,7 @@
  * @author Christian Grothoff
  */
 #include "platform.h"
+#include <gcrypt.h>
 #include "gnunet_util_lib.h"
 #include "gnunet-service-core.h"
 #include "gnunet-service-core_clients.h"
index fb299267bb894e7eeaa7bd749126d9c5ab21cac2..99d4ac58f5b6f28679e895e37c8339a7dfff0266 100644 (file)
@@ -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
index 72fe0e7d02de532364bfe63dc660d8acf7c45f5c..c762e3b9c1071b6f419011c3fb6bef0a2a3058ce 100644 (file)
@@ -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;
 }
 
index 97ba2a3b6560563c6ff770b2e32ce6b78c4c8fcb..2e4ba6a9d916b2e424bc000db44c70e04f8fc82f 100644 (file)
@@ -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)
   {
index b61d5961353b5d0f681fa95a4bce4b7b251fe3b7..8ba6641b9d8cb13cac8f6845cc956000f1ab6e74 100644 (file)
 #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);
 }
index cd9a33f6141e460325b6e8789a6d90620f3fa5d6..6857a122141e4865648054d4fd5e388091be52f4 100644 (file)
@@ -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)
   {
index d7f1dd58da8b27ddb4c58d6bb216829637ccc605..a00ef05734cbe9f764c9af5e875922c35a700ef3 100644 (file)
@@ -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;
index 1e7132d3f47e402cecf9ac4fb0310a0a45f1f866..ab4bf2cb0fe01ce876bdc3b2a97c3d808d58a619 100644 (file)
@@ -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;
index 88b51188e8a0d18d32edaad8a96459c87b5af331..1c5897c1e8cd4d0db5dae1205d9759775f1819b9 100644 (file)
@@ -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 ();
index 201bfeb5d3a7cb22c69b40628714e8b2fdbca1c4..f2ddf2012574ab8af7fe378c15cfa45fe3d6e1c5 100644 (file)
@@ -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 ();
index 6dac1763fdaf91509f80a5339c419148988f23b8..1adb418883caafd7e5a98b9e69ab8d53f6b42c35 100644 (file)
@@ -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);
index ee673786d88453e2da42d9331e18fed6e27348ca..6574cc970cbcfe6d0539ed84162f80e561a66a20 100644 (file)
@@ -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);
index 9b5085b25387a86038a9d557890ceb1a4e8e280d..56159be1ccde017e9086cbce6b8d74d7a246e3d3 100644 (file)
@@ -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"))