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

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