241384
diff -up libgcrypt-1.5.0/cipher/dsa.c.tests libgcrypt-1.5.0/cipher/dsa.c
241384
--- libgcrypt-1.5.0/cipher/dsa.c.tests	2011-06-13 12:24:46.000000000 +0200
241384
+++ libgcrypt-1.5.0/cipher/dsa.c	2011-07-20 16:44:51.000000000 +0200
241384
@@ -479,22 +479,21 @@ generate_fips186 (DSA_secret_key *sk, un
241384
             initial_seed.seed = gcry_sexp_nth_data (initial_seed.sexp, 1,
241384
                                                     &initial_seed.seedlen);
241384
         }
241384
-
241384
-      /* Fixme: Enable 186-3 after it has been approved and after fixing
241384
-         the generation function.  */
241384
-      /*   if (use_fips186_2) */
241384
-      (void)use_fips186_2;
241384
-      ec = _gcry_generate_fips186_2_prime (nbits, qbits,
241384
-                                           initial_seed.seed,
241384
+      
241384
+      if (use_fips186_2)
241384
+        ec = _gcry_generate_fips186_2_prime (nbits, qbits, 
241384
+                                           initial_seed.seed, 
241384
                                            initial_seed.seedlen,
241384
                                            &prime_q, &prime_p,
241384
                                            r_counter,
241384
                                            r_seed, r_seedlen);
241384
-      /*   else */
241384
-      /*     ec = _gcry_generate_fips186_3_prime (nbits, qbits, NULL, 0, */
241384
-      /*                                          &prime_q, &prime_p, */
241384
-      /*                                          r_counter, */
241384
-      /*                                          r_seed, r_seedlen, NULL); */
241384
+      else
241384
+        ec = _gcry_generate_fips186_3_prime (nbits, qbits,
241384
+                                          initial_seed.seed,
241384
+                                          initial_seed.seedlen,
241384
+                                          &prime_q, &prime_p,
241384
+                                          r_counter,
241384
+                                          r_seed, r_seedlen, NULL);
241384
       gcry_sexp_release (initial_seed.sexp);
241384
       if (ec)
241384
         goto leave;
241384
diff -up libgcrypt-1.5.0/cipher/primegen.c.tests libgcrypt-1.5.0/cipher/primegen.c
241384
--- libgcrypt-1.5.0/cipher/primegen.c.tests	2011-03-28 14:19:52.000000000 +0200
241384
+++ libgcrypt-1.5.0/cipher/primegen.c	2011-07-21 14:36:03.000000000 +0200
241384
@@ -1647,7 +1647,7 @@ _gcry_generate_fips186_3_prime (unsigned
241384
   gpg_err_code_t ec;
241384
   unsigned char seed_help_buffer[256/8];  /* Used to hold a generated SEED. */
241384
   unsigned char *seed_plus;     /* Malloced buffer to hold SEED+x.  */
241384
-  unsigned char digest[256/8];  /* Helper buffer for SHA-1 digest.  */
241384
+  unsigned char digest[256/8];  /* Helper buffer for SHA-x digest.  */
241384
   gcry_mpi_t val_2 = NULL;      /* Helper for the prime test.  */
241384
   gcry_mpi_t tmpval = NULL;     /* Helper variable.  */
241384
   int hashalgo;                 /* The id of the Approved Hash Function.  */
241384
@@ -1737,7 +1737,7 @@ _gcry_generate_fips186_3_prime (unsigned
241384
         }
241384
       gcry_mpi_release (prime_q); prime_q = NULL;
241384
       ec = gpg_err_code (gcry_mpi_scan (&prime_q, GCRYMPI_FMT_USG,
241384
-                                        value_u, sizeof value_u, NULL));
241384
+                                        value_u, qbits/8, NULL));
241384
       if (ec)
241384
         goto leave;
241384
       mpi_set_highbit (prime_q, qbits-1 );
241384
@@ -1782,11 +1782,11 @@ _gcry_generate_fips186_3_prime (unsigned
241384
               if (seed_plus[i])
241384
                 break;
241384
             }
241384
-          gcry_md_hash_buffer (GCRY_MD_SHA1, digest, seed_plus, seedlen);
241384
+          gcry_md_hash_buffer (hashalgo, digest, seed_plus, seedlen);
241384
 
241384
           gcry_mpi_release (tmpval); tmpval = NULL;
241384
           ec = gpg_err_code (gcry_mpi_scan (&tmpval, GCRYMPI_FMT_USG,
241384
-                                            digest, sizeof digest, NULL));
241384
+                                            digest, qbits/8, NULL));
241384
           if (ec)
241384
             goto leave;
241384
           if (value_j == value_n)
241384
@@ -1822,11 +1822,11 @@ _gcry_generate_fips186_3_prime (unsigned
241384
     }
241384
 
241384
   /* Step 12:  Save p, q, counter and seed.  */
241384
-  log_debug ("fips186-3 pbits p=%u q=%u counter=%d\n",
241384
+/*  log_debug ("fips186-3 pbits p=%u q=%u counter=%d\n",
241384
              mpi_get_nbits (prime_p), mpi_get_nbits (prime_q), counter);
241384
   log_printhex("fips186-3 seed:", seed, seedlen);
241384
   log_mpidump ("fips186-3 prime p", prime_p);
241384
-  log_mpidump ("fips186-3 prime q", prime_q);
241384
+  log_mpidump ("fips186-3 prime q", prime_q); */
241384
   if (r_q)
241384
     {
241384
       *r_q = prime_q;
241384
diff -up libgcrypt-1.5.0/cipher/rsa.c.tests libgcrypt-1.5.0/cipher/rsa.c
241384
--- libgcrypt-1.5.0/cipher/rsa.c.tests	2011-06-10 10:53:41.000000000 +0200
241384
+++ libgcrypt-1.5.0/cipher/rsa.c	2011-07-21 14:36:59.000000000 +0200
241384
@@ -388,7 +388,7 @@ generate_x931 (RSA_secret_key *sk, unsig
241384
 
241384
   *swapped = 0;
241384
 
241384
-  if (e_value == 1)   /* Alias for a secure value. */
241384
+  if (e_value == 1 || e_value == 0)   /* Alias for a secure value. */
241384
     e_value = 65537;
241384
 
241384
   /* Point 1 of section 4.1:  k = 1024 + 256s with S >= 0  */
241384
diff -up libgcrypt-1.5.0/random/random-fips.c.tests libgcrypt-1.5.0/random/random-fips.c
241384
--- libgcrypt-1.5.0/random/random-fips.c.tests	2011-07-20 16:40:59.000000000 +0200
241384
+++ libgcrypt-1.5.0/random/random-fips.c	2011-07-20 16:40:59.000000000 +0200
241384
@@ -691,6 +691,7 @@ get_random (void *buffer, size_t length,
241384
 
241384
   check_guards (rng_ctx);
241384
 
241384
+ reinitialize:
241384
   /* Initialize the cipher handle and thus setup the key if needed.  */
241384
   if (!rng_ctx->cipher_hd)
241384
     {
241384
@@ -710,13 +711,11 @@ get_random (void *buffer, size_t length,
241384
   if (rng_ctx->key_init_pid != getpid ()
241384
       || rng_ctx->seed_init_pid != getpid ())
241384
     {
241384
-      /* We are in a child of us.  Because we have no way yet to do
241384
-         proper re-initialization (including self-checks etc), the
241384
-         only chance we have is to bail out.  Obviusly a fork/exec
241384
-         won't harm because the exec overwrites the old image. */
241384
-      fips_signal_error ("fork without proper re-initialization "
241384
-                         "detected in RNG");
241384
-      goto bailout;
241384
+      /* Just reinitialize the key & seed. */
241384
+      gcry_cipher_close(rng_ctx->cipher_hd);
241384
+      rng_ctx->cipher_hd = NULL;
241384
+      rng_ctx->is_seeded = 0;
241384
+      goto reinitialize;
241384
     }
241384
 
241384
   if (x931_aes_driver (buffer, length, rng_ctx))
241384
diff -up libgcrypt-1.5.0/tests/ac.c.tests libgcrypt-1.5.0/tests/ac.c
241384
--- libgcrypt-1.5.0/tests/ac.c.tests	2011-02-04 20:18:20.000000000 +0100
241384
+++ libgcrypt-1.5.0/tests/ac.c	2011-07-20 16:40:59.000000000 +0200
241384
@@ -150,6 +150,9 @@ main (int argc, char **argv)
241384
   if (!gcry_check_version (GCRYPT_VERSION))
241384
     die ("version mismatch\n");
241384
   gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
241384
+  if (gcry_fips_mode_active())
241384
+    /* ac not functional in the fips mode, skip it */
241384
+    return 77;
241384
   if (debug)
241384
     gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0);
241384
   /* No valuable keys are create, so we can speed up our RNG. */
241384
diff -up libgcrypt-1.5.0/tests/ac-data.c.tests libgcrypt-1.5.0/tests/ac-data.c
241384
--- libgcrypt-1.5.0/tests/ac-data.c.tests	2011-02-04 20:18:20.000000000 +0100
241384
+++ libgcrypt-1.5.0/tests/ac-data.c	2011-07-20 16:40:59.000000000 +0200
241384
@@ -198,6 +198,9 @@ main (int argc, char **argv)
241384
   if (!gcry_check_version (GCRYPT_VERSION))
241384
     die ("version mismatch\n");
241384
   gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
241384
+  if (gcry_fips_mode_active())
241384
+    /* ac not functional in the fips mode, skip it */
241384
+    return 77;
241384
   if (debug)
241384
     gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0);
241384
 
241384
diff -up libgcrypt-1.5.0/tests/ac-schemes.c.tests libgcrypt-1.5.0/tests/ac-schemes.c
241384
--- libgcrypt-1.5.0/tests/ac-schemes.c.tests	2011-02-04 20:18:20.000000000 +0100
241384
+++ libgcrypt-1.5.0/tests/ac-schemes.c	2011-07-20 16:40:59.000000000 +0200
241384
@@ -338,6 +338,9 @@ main (int argc, char **argv)
241384
   if (! gcry_check_version (GCRYPT_VERSION))
241384
     die ("version mismatch\n");
241384
   gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
241384
+  if (gcry_fips_mode_active())
241384
+    /* ac not functional in the fips mode, skip it */
241384
+    return 77;
241384
   if (debug)
241384
     gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0);
241384
 
241384
diff -up libgcrypt-1.5.0/tests/keygen.c.tests libgcrypt-1.5.0/tests/keygen.c
241384
--- libgcrypt-1.5.0/tests/keygen.c.tests	2011-02-04 20:18:20.000000000 +0100
241384
+++ libgcrypt-1.5.0/tests/keygen.c	2011-07-21 14:39:03.000000000 +0200
241384
@@ -148,12 +148,12 @@ check_rsa_keys (void)
241384
     }
241384
 
241384
   if (verbose)
241384
-    fprintf (stderr, "creating 1536 bit DSA key\n");
241384
+    fprintf (stderr, "creating 2048 bit DSA key\n");
241384
   rc = gcry_sexp_new (&keyparm,
241384
                       "(genkey\n"
241384
                       " (dsa\n"
241384
-                      "  (nbits 4:1536)\n"
241384
-                      "  (qbits 3:224)\n"
241384
+                      "  (nbits 4:2048)\n"
241384
+                      "  (qbits 3:256)\n"
241384
                       " ))", 0, 1);
241384
   if (rc)
241384
     die ("error creating S-expression: %s\n", gpg_strerror (rc));
241384
@@ -190,11 +190,11 @@ check_rsa_keys (void)
241384
 
241384
 
241384
   if (verbose)
241384
-    fprintf (stderr, "creating 512 bit RSA key with e=257\n");
241384
+    fprintf (stderr, "creating 1024 bit RSA key with e=257\n");
241384
   rc = gcry_sexp_new (&keyparm,
241384
                       "(genkey\n"
241384
                       " (rsa\n"
241384
-                      "  (nbits 3:512)\n"
241384
+                      "  (nbits 4:1024)\n"
241384
                       "  (rsa-use-e 3:257)\n"
241384
                       " ))", 0, 1);
241384
   if (rc)
241384
@@ -208,11 +208,11 @@ check_rsa_keys (void)
241384
   gcry_sexp_release (key);
241384
 
241384
   if (verbose)
241384
-    fprintf (stderr, "creating 512 bit RSA key with default e\n");
241384
+    fprintf (stderr, "creating 1024 bit RSA key with default secure e\n");
241384
   rc = gcry_sexp_new (&keyparm,
241384
                       "(genkey\n"
241384
                       " (rsa\n"
241384
-                      "  (nbits 3:512)\n"
241384
+                      "  (nbits 4:1024)\n"
241384
                       "  (rsa-use-e 1:0)\n"
241384
                       " ))", 0, 1);
241384
   if (rc)