Blame SOURCES/libgcrypt-1.10.0-allow-small-RSA-verify.patch

7682e8
From ca2afc9fb64d9a9b2f8930ba505d9ab6c8a57667 Mon Sep 17 00:00:00 2001
7682e8
From: Jakub Jelen <jjelen@redhat.com>
7682e8
Date: Thu, 12 May 2022 10:56:47 +0200
7682e8
Subject: [PATCH] cipher: Allow verification of small RSA signatures in FIPS
7682e8
 mode
7682e8
7682e8
* cipher/rsa.c (rsa_check_keysize): Formatting.
7682e8
  (rsa_check_verify_keysize): New function.
7682e8
  (rsa_verify): Allow using smaller keys for verification.
7682e8
--
7682e8
7682e8
GnuPG-bug-id: 5975
7682e8
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
7682e8
---
7682e8
 cipher/rsa.c | 26 ++++++++++++++++++++++++--
7682e8
 1 file changed, 24 insertions(+), 2 deletions(-)
7682e8
7682e8
diff --git a/cipher/rsa.c b/cipher/rsa.c
7682e8
index c6319b67..9f2b36e8 100644
7682e8
--- a/cipher/rsa.c
7682e8
+++ b/cipher/rsa.c
7682e8
@@ -352,13 +352,35 @@ generate_std (RSA_secret_key *sk, unsigned int nbits, unsigned long use_e,
7682e8
 static gpg_err_code_t
7682e8
 rsa_check_keysize (unsigned int nbits)
7682e8
 {
7682e8
-  if (fips_mode() && nbits < 2048)
7682e8
+  if (fips_mode () && nbits < 2048)
7682e8
     return GPG_ERR_INV_VALUE;
7682e8
 
7682e8
   return GPG_ERR_NO_ERROR;
7682e8
 }
7682e8
 
7682e8
 
7682e8
+/* Check the RSA key length is acceptable for signature verification
7682e8
+ *
7682e8
+ * FIPS allows signature verification with RSA keys of size
7682e8
+ * 1024, 1280, 1536 and 1792 in legacy mode, but this is up to the
7682e8
+ * calling application to decide if the signature is legacy and
7682e8
+ * should be accepted.
7682e8
+ */
7682e8
+static gpg_err_code_t
7682e8
+rsa_check_verify_keysize (unsigned int nbits)
7682e8
+{
7682e8
+  if (fips_mode ())
7682e8
+    {
7682e8
+      if ((nbits >= 1024 && (nbits % 256) == 0) || nbits >= 2048)
7682e8
+        return GPG_ERR_NO_ERROR;
7682e8
+
7682e8
+      return GPG_ERR_INV_VALUE;
7682e8
+    }
7682e8
+
7682e8
+  return GPG_ERR_NO_ERROR;
7682e8
+}
7682e8
+
7682e8
+
7682e8
 /****************
7682e8
  * Generate a key pair with a key of size NBITS.
7682e8
  * USE_E = 0 let Libcgrypt decide what exponent to use.
7682e8
@@ -1602,7 +1624,7 @@ rsa_verify (gcry_sexp_t s_sig, gcry_sexp_t s_data, gcry_sexp_t keyparms)
7682e8
   gcry_mpi_t result = NULL;
7682e8
   unsigned int nbits = rsa_get_nbits (keyparms);
7682e8
 
7682e8
-  rc = rsa_check_keysize (nbits);
7682e8
+  rc = rsa_check_verify_keysize (nbits);
7682e8
   if (rc)
7682e8
     return rc;
7682e8
 
7682e8
-- 
7682e8
2.37.1
7682e8