[PATCH libgcrypt] ecc: Fix keygrip of native 25519 points starting with 0x02 or 0x03.

NIIBE Yutaka gniibe at fsij.org
Mon Nov 16 05:50:51 CET 2026


Hello,

Thank you for your pointing out the issue.

Firstly, I think that we need this change:

==========================
diff --git a/cipher/ecc.c b/cipher/ecc.c
index 8545145d..47b51c31 100644
--- a/cipher/ecc.c
+++ b/cipher/ecc.c
@@ -1792,7 +1792,11 @@ compute_keygrip (gcry_md_hd_t md, gcry_sexp_t keyparms)
      the compressed version.  Because we don't support any non-eddsa
      compression, the only thing we need to do is to compress
      EdDSA.  */
-  if ((flags & PUBKEY_FLAG_EDDSA) && dialect == ECC_DIALECT_ED25519)
+  if (dialect == ECC_DIALECT_SAFECURVE)
+    {
+      maybe_uncompress = 0;
+    }
+  else if ((flags & PUBKEY_FLAG_EDDSA) && dialect == ECC_DIALECT_ED25519)
     {
       const unsigned int pbits = mpi_get_nbits (values[0]);
 
==========================

That is, for keys with its native format (which should come with no
flags), compression is irrelevant.  The curves are: ietf25 for X25519,
Ed448 and X448.

David Seifert wrote:
> * cipher/ecc.c (compute_keygrip): Do not try to uncompress the point
> of a 255 bit Edwards or Montgomery curve.
> * tests/keygrip.c (key_grips): Add test vectors.

For (normal) use of Ed25519 and Curve25519, the relevant flags should be
supplied.  Historically, Ed25519 with no flags were introduced when
Ed25519 was not mature and it was specifically for ECDSA (not EdDSA).
Around the same time, Curve25519 with the flag was introduced to compute
X25519 (with big-endian private key).

> This is the form of keys from X.509 certificates (RFC 8410) as
> returned by libksba

I don't understand this claim.  Does libksba return an SEXP key with no
flags?  If so, it is libksba which should be fixed.  Please let us know.

> If the first byte of such a point is 0x02 or 0x03, compute_keygrip
> takes it for a compressed Weierstrass point and tries to uncompress
> it.

Yes, this is the behavior.
-- 


More information about the Gcrypt-devel mailing list