BUG: gpgsm: gpgsm rejects valid X.509 chain when P-521/ECDSA CA certificate signs with SHA-384
Testing, NormalPublic

Assigned To
Authored By
margirou
Jun 24 2026, 10:29 AM

Description

Product: GnuPG / gpgsm
Environment: Gpg4win, Kleopatra frontend, gpgsm backend
Component: X.509 certificate chain validation

Summary
gpgsm rejects an X.509 certificate chain because the issuer/root CA uses an ECC P-521 key and the certificate signature algorithm is ECDSA with SHA-384. The failure appears to come from a key-size-to-hash-size restriction in chain validation, even though ECDSA with SHA-384 is a defined X.509 signature algorithm and conforming clients must recognize it.

Observed behavior
During certificate dump / chain validation, gpgsm emits:

gpgsm: hash algo: 1.2.840.10045.4.3.3
gpgsm: a 384 bit hash is not valid for a 521 bit ECC key
gpgsm: DBG: gcry_pk_verify: Success
[GNUPG:] FAILURE gpgsm-exit 50331649

The important part is that gcry_pk_verify: Success is logged, but gpgsm still rejects the chain because it considers SHA-384 invalid for a 521-bit ECC key.

Expected behavior
gpgsm should accept the chain if the certificate signature algorithm is ecdsa-with-SHA384 (OID 1.2.840.10045.4.3.3) and the signature verifies correctly. RFC 5758 explicitly defines ecdsa-with-SHA384 and states that conforming client implementations processing ECDSA signatures in certificates and CRLs must recognize the corresponding SHA-2 ECDSA OIDs, including ecdsa-with-SHA384.

Why this looks like a bug
RFC 5758 defines the X.509 signature algorithm OIDs ecdsa-with-SHA224, ecdsa-with-SHA256, ecdsa-with-SHA384, and ecdsa-with-SHA512 for ECDSA signatures in certificates and CRLs. The RFC text does not restrict ecdsa-with-SHA384 to only P-384 keys; it defines the signature algorithm identifier independently and requires clients to recognize it. The current gpgsm behavior appears to impose an additional restriction that rejects P-521 + SHA-384 even after the cryptographic signature verification succeeds.

Reproduction

  1. Import or inspect a certificate chain in Kleopatra / gpgsm.
  2. Use a root CA certificate with an ECC P-521 public key.
  3. Use a certificate signature algorithm of ecdsa-with-SHA384 (1.2.840.10045.4.3.3) on the issuer/root and on the leaf certificate.
  4. Run a certificate dump / validation path in gpgsm.
  5. Observe chain validation failure with the message:

a 384 bit hash is not valid for a 521 bit ECC key

Relevant certificate details from debug output

Signature algorithm OID reported by gpgsm: 1.2.840.10045.4.3.3

gpgsm labels this as a 384-bit hash

Issuer/root key is ECC 521-bit gcry_pk_verify: Success is logged before final failure

Suspected cause
gpgsm appears to contain logic that rejects SHA-384 for ECC P-521 based on a fixed curve-size/hash-size pairing rule. That rule seems too strict for X.509 ECDSA signature validation and contradicts RFC 5758 recognition requirements for ecdsa-with-SHA384.

Impact
This prevents valid X.509 certificate chains from being accepted in Kleopatra/gpgsm when they use ECDSA P-521 keys with SHA-384 signatures. As a result, chain validation fails even though the signature verification step itself succeeds.

Suggested fix
Remove or relax the check that rejects ecdsa-with-SHA384 solely because the signing key is P-521. Validation should follow the certificate’s declared signature algorithm OID and accept ecdsa-with-SHA384 when the ASN.1 algorithm identifier is correct and the ECDSA signature verifies successfully, which RFC 5758 requires clients to recognize.

Reference text
RFC 5758 defines ecdsa-with-SHA384 as OID 1.2.840.10045.4.3.3 and says conforming client implementations processing ECDSA signatures in certificates and CRLs must recognize the corresponding SHA-2 ECDSA OIDs.

Details

Version
Gpg4win-5.0.2

Event Timeline

margirou created this task.
margirou raised the priority of this task from Low to Needs Triage.Jun 27 2026, 2:42 PM
• werner triaged this task as Normal priority.Jul 8 2026, 10:05 AM
• werner added projects: gnupg26, S/MIME.

Here is a patch:

I don't know if this fixes the issue, but this patch is required (to proceed).

• gniibe mentioned this in Unknown Object (Maniphest Task).Oct 26 2026, 3:32 AM
• gniibe changed the task status from Open to Testing.Oct 27 2026, 12:51 AM
• gniibe claimed this task.

Pushed the change.

• gniibe mentioned this in Unknown Object (Maniphest Task).Mon, Nov 2, 1:44 AM

On the other hand, in FIPS 186-5 DIGITAL SIGNATURE STANDARD (DSS), it says (the context is: the bit length of n means the key size):

The security strength associated with the bit length of n and the security strength of the hash
function (or XOF) should be the same unless an agreement has been made between participating
entities to use a stronger hash function. When the length of the output of the hash function (or
XOF) is greater than the bit length of n, then the leftmost n bits of the hash function (or XOF)
output block shall be used in any calculation using the hash function (or XOF) output during the
generation or verification of a digital signature. A hash function (or XOF) that provides a lower
security strength than the security strength associated with the bit length of n ordinarily should
not be used since this would reduce the security strength of the digital signature process to a
level no greater than that provided by the hash function (or XOF).

The BSI's document, Technical Guideline TR-03111 Elliptic Curve Cryptography Version 2.0, also has similar requirement.

So, I think that with opt.require_compliance, it should be rejected.

There is a request for further change:
https://lists.gnupg.org/pipermail/gnupg-devel/2026-November/036529.html

Extend the existing P-521/SHA-384 exception to also allow P-384/SHA-256 and P-521/SHA-256. Restrict these exceptions to ECC keys, preserving DSA checks.

I got a reply by PM, and the example seems that there is a case for P-384/SHA-256 signature made with a Poland's national electronic identity card by PWPW (Polish Security Printing Works), where the card has a P-384 key, and use it for 256-bit strength.

Strictly speaking, I don't think this is a valid use case (P-521/SHA-384, too), but it makes sense to allow this.
(I think that when signature is generated, it should select relevant hash algo from valid combinations of key strength and hash strength.)

For now, I'd like to apply following:

diff --git a/sm/certcheck.c b/sm/certcheck.c
index 41542948f..8ccacb3a0 100644
--- a/sm/certcheck.c
+++ b/sm/certcheck.c
@@ -108,7 +108,10 @@ do_encode_md (gcry_md_hd_t md, int algo, int pkalgo, unsigned int nbits,
       /* Check if we're too short.  Too long is safe as we'll
 	 automatically left-truncate. */
       nframe = gcry_md_get_algo_dlen (algo);
-      if (nframe < qbits/8 && !(qbits0 == 521 && algo == GCRY_MD_SHA384))
+      if (nframe < qbits/8
+          && !(pkalgo == GCRY_PK_ECC && !opt.require_compliance
+               && ((qbits0 == 384 && algo == GCRY_MD_SHA256)
+                   || (qbits0 == 521 && algo == GCRY_MD_SHA384))))
         {
 	  log_error (_("a %u bit hash is not valid for a %u bit %s key\n"),
                      (unsigned int)nframe*8,

Intention is: When opt.require_compliance is not set (no compliance to any standards), it allows P-384/SHA-256 and P-521/SHA-384.
We will consider other possibilities (like P-521/SHA-256, or ones with Brainpool curve 512), when we will see the cases.

• gniibe mentioned this in Unknown Object (Maniphest Task).Mon, Nov 23, 4:01 AM
• gniibe mentioned this in Unknown Object (Maniphest Task).Mon, Nov 30, 5:20 AM