150a03
diff -up libgcrypt-1.8.4/cipher/dsa.c.fips-keygen libgcrypt-1.8.4/cipher/dsa.c
150a03
--- libgcrypt-1.8.4/cipher/dsa.c.fips-keygen	2017-11-23 19:16:58.000000000 +0100
150a03
+++ libgcrypt-1.8.4/cipher/dsa.c	2019-02-12 14:29:25.629513989 +0100
9fde57
@@ -457,11 +457,22 @@ generate_fips186 (DSA_secret_key *sk, un
9fde57
                                              &prime_q, &prime_p,
9fde57
                                              r_counter,
9fde57
                                              r_seed, r_seedlen);
9fde57
-      else
9fde57
-        ec = _gcry_generate_fips186_3_prime (nbits, qbits, NULL, 0,
9fde57
+      else if (!domain->p || !domain->q)
9fde57
+        ec = _gcry_generate_fips186_3_prime (nbits, qbits,
9fde57
+                                             initial_seed.seed,
9fde57
+                                             initial_seed.seedlen,
9fde57
                                              &prime_q, &prime_p,
9fde57
                                              r_counter,
9fde57
                                              r_seed, r_seedlen, NULL);
9fde57
+      else
9fde57
+        {
9fde57
+          /* Domain parameters p and q are given; use them.  */
9fde57
+          prime_p = mpi_copy (domain->p);
9fde57
+          prime_q = mpi_copy (domain->q);
9fde57
+          gcry_assert (mpi_get_nbits (prime_p) == nbits);
9fde57
+          gcry_assert (mpi_get_nbits (prime_q) == qbits);
9fde57
+          ec = 0;
9fde57
+        }
9fde57
       sexp_release (initial_seed.sexp);
9fde57
       if (ec)
9fde57
         goto leave;
9fde57
@@ -855,13 +866,12 @@ dsa_generate (const gcry_sexp_t genparms
9fde57
       sexp_release (l1);
9fde57
       sexp_release (domainsexp);
9fde57
 
9fde57
-      /* Check that all domain parameters are available.  */
9fde57
-      if (!domain.p || !domain.q || !domain.g)
9fde57
+      /* Check that p and q domain parameters are available.  */
9fde57
+      if (!domain.p || !domain.q || (!domain.g && !(flags & PUBKEY_FLAG_USE_FIPS186)))
9fde57
         {
9fde57
           _gcry_mpi_release (domain.p);
9fde57
           _gcry_mpi_release (domain.q);
9fde57
           _gcry_mpi_release (domain.g);
9fde57
-          sexp_release (deriveparms);
9fde57
           return GPG_ERR_MISSING_VALUE;
9fde57
         }
9fde57
 
150a03
diff -up libgcrypt-1.8.4/cipher/rsa.c.fips-keygen libgcrypt-1.8.4/cipher/rsa.c
150a03
--- libgcrypt-1.8.4/cipher/rsa.c.fips-keygen	2017-11-23 19:16:58.000000000 +0100
150a03
+++ libgcrypt-1.8.4/cipher/rsa.c	2019-02-12 14:29:25.630513971 +0100
150a03
@@ -389,7 +389,7 @@ generate_fips (RSA_secret_key *sk, unsig
150a03
 
150a03
   if (nbits < 1024 || (nbits & 0x1FF))
150a03
     return GPG_ERR_INV_VALUE;
150a03
-  if (_gcry_enforced_fips_mode() && nbits != 2048 && nbits != 3072)
150a03
+  if (fips_mode() && nbits < 2048)
150a03
       return GPG_ERR_INV_VALUE;
150a03
 
150a03
   /* The random quality depends on the transient_key flag.  */
9fde57
@@ -696,7 +696,7 @@ generate_x931 (RSA_secret_key *sk, unsig
9fde57
 
9fde57
   *swapped = 0;
9fde57
 
9fde57
-  if (e_value == 1)   /* Alias for a secure value. */
9fde57
+  if (e_value == 1 || e_value == 0)   /* Alias for a secure value. */
9fde57
     e_value = 65537;
9fde57
 
9fde57
   /* Point 1 of section 4.1:  k = 1024 + 256s with S >= 0  */