>From 2c1d41b5f86f93db56432616bc3ee704b9c9cc39 Mon Sep 17 00:00:00 2001
Message-ID: <2c1d41b5f86f93db56432616bc3ee704b9c9cc39.1768962180.git.gniibe@fsij.org>
From: NIIBE Yutaka <gniibe@fsij.org>
Date: Tue, 20 Jan 2026 15:24:24 +0900
Subject: [PATCH] fips,cipher: Fix the regression with disabled public-key
 algo.
To: gcrypt-devel@gnupg.org
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.47.3"

This is a multi-part message in MIME format.
--------------2.47.3
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit


* cipher/pubkey.c (_gcry_pk_decrypt): Continue the computation when
marking non-compliant.
(_gcry_pk_encrypt): When disabled, return an error.
(_gcry_pk_sign, _gcry_pk_sign_md): Likewise.
(gcry_pk_verify, _gcry_pk_verify_md, _gcry_pk_testkey): Likewise.

--

Fixes-commit: 54a6617b3679cfeb6d986ddf3c9c73641929f02c
GnuPG-bug-id: 7338
Reported-by: Pavel Kohout, Aisle Research, www.aisle.com
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
---
 cipher/pubkey.c | 48 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 39 insertions(+), 9 deletions(-)


--------------2.47.3
Content-Type: text/x-patch; name="0001-fips-cipher-Fix-the-regression-with-disabled-public-.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0001-fips-cipher-Fix-the-regression-with-disabled-public-.patch"

diff --git a/cipher/pubkey.c b/cipher/pubkey.c
index d6ebc73b..7b133498 100644
--- a/cipher/pubkey.c
+++ b/cipher/pubkey.c
@@ -329,7 +329,10 @@ _gcry_pk_encrypt (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t s_pkey)
     goto leave;
 
   if (spec->flags.disabled)
-    rc = GPG_ERR_PUBKEY_ALGO;
+    {
+      rc = GPG_ERR_PUBKEY_ALGO;
+      goto leave;
+    }
   else if (!spec->flags.fips && fips_mode ())
     {
       if (fips_check_rejection (GCRY_FIPS_FLAG_REJECT_PK))
@@ -394,10 +397,22 @@ _gcry_pk_decrypt (gcry_sexp_t *r_plain, gcry_sexp_t s_data, gcry_sexp_t s_skey)
     goto leave;
 
   if (spec->flags.disabled)
-    rc = GPG_ERR_PUBKEY_ALGO;
+    {
+      rc = GPG_ERR_PUBKEY_ALGO;
+      goto leave;
+    }
   else if (!spec->flags.fips && fips_mode ())
-    rc = GPG_ERR_PUBKEY_ALGO;
-  else if (spec->decrypt)
+    {
+      if (fips_check_rejection (GCRY_FIPS_FLAG_REJECT_PK))
+        {
+          rc = GPG_ERR_PUBKEY_ALGO;
+          goto leave;
+        }
+      else
+        fips_service_indicator_mark_non_compliant ();
+    }
+
+  if (spec->decrypt)
     rc = spec->decrypt (r_plain, s_data, keyparms);
   else
     rc = GPG_ERR_NOT_IMPLEMENTED;
@@ -451,7 +466,10 @@ _gcry_pk_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_hash, gcry_sexp_t s_skey)
     goto leave;
 
   if (spec->flags.disabled)
-    rc = GPG_ERR_PUBKEY_ALGO;
+    {
+      rc = GPG_ERR_PUBKEY_ALGO;
+      goto leave;
+    }
   else if (!spec->flags.fips && fips_mode ())
     {
       if (fips_check_rejection (GCRY_FIPS_FLAG_REJECT_PK))
@@ -656,7 +674,10 @@ _gcry_pk_sign_md (gcry_sexp_t *r_sig, const char *tmpl, gcry_md_hd_t hd_orig,
     goto leave;
 
   if (spec->flags.disabled)
-    rc = GPG_ERR_PUBKEY_ALGO;
+    {
+      rc = GPG_ERR_PUBKEY_ALGO;
+      goto leave;
+    }
   else if (!spec->flags.fips && fips_mode ())
     {
       if (fips_check_rejection (GCRY_FIPS_FLAG_REJECT_PK))
@@ -699,7 +720,10 @@ _gcry_pk_verify (gcry_sexp_t s_sig, gcry_sexp_t s_hash, gcry_sexp_t s_pkey)
     goto leave;
 
   if (spec->flags.disabled)
-    rc = GPG_ERR_PUBKEY_ALGO;
+    {
+      rc = GPG_ERR_PUBKEY_ALGO;
+      goto leave;
+    }
   else if (!spec->flags.fips && fips_mode ())
     {
       if (fips_check_rejection (GCRY_FIPS_FLAG_REJECT_PK))
@@ -751,7 +775,10 @@ _gcry_pk_verify_md (gcry_sexp_t s_sig, const char *tmpl, gcry_md_hd_t hd_orig,
     goto leave;
 
   if (spec->flags.disabled)
-    rc = GPG_ERR_PUBKEY_ALGO;
+    {
+      rc = GPG_ERR_PUBKEY_ALGO;
+      goto leave;
+    }
   else if (!spec->flags.fips && fips_mode ())
     {
       if (fips_check_rejection (GCRY_FIPS_FLAG_REJECT_PK))
@@ -796,7 +823,10 @@ _gcry_pk_testkey (gcry_sexp_t s_key)
     goto leave;
 
   if (spec->flags.disabled)
-    rc = GPG_ERR_PUBKEY_ALGO;
+    {
+      rc = GPG_ERR_PUBKEY_ALGO;
+      goto leave;
+    }
   else if (!spec->flags.fips && fips_mode ())
     {
       if (fips_check_rejection (GCRY_FIPS_FLAG_REJECT_PK))

--------------2.47.3--


