<div dir="ltr"><div><div class="gmail_default" style="color:rgb(7,55,99)"><font face="arial, sans-serif" style="">**In-Reply-To:** <response from NIIBE Yutaka on Oct 22, 2025></font></div><br clear="all"></div><div><div class="gmail_default" style="font-family:"times new roman",serif;font-size:large;color:rgb(7,55,99)"><span style="font-family:Arial,Helvetica,sans-serif;font-size:small;color:rgb(34,34,34)">Hi NIIBE Yutaka,</span></div><br>Thank you for your response on October 22! I apologize for the delay - <span class="gmail_default" style="font-family:"times new roman",serif;font-size:large;color:rgb(7,55,99)"></span><span class="gmail_default" style="font-family:"times new roman",serif;font-size:large;color:rgb(7,55,99)"></span><span class="gmail_default" style=""><font face="arial, sans-serif" style="" color="#000000">I am new to the list and</font></span> didn't receive your email until I checked the web archives today.<br><br>## Clarifying the Bug<br><br>Your response mentioned using `(flags eddsa)` during key generation, which is good practice. However, I want to clarify that **my bug report concerns signature verification, not key generation**.<br><br>The issue is that **Format 2 S-expressions can successfully SIGN but cannot VERIFY** Ed25519 signatures, even when keys are properly generated with the eddsa flag.<br><br>### Reproduction<br><br>Here's a minimal test case showing the problem:<br><br>```c<br>// Key generation (with proper eddsa flag as you suggested)<br>gcry_sexp_t keypair;<br>gcry_sexp_build(&keypair, NULL, "(genkey (ecc (flags eddsa) (curve Ed25519)))");<br>gcry_pk_genkey(&keypair, keypair);<br><br>// Extract public/private keys...<br><br>// TEST: Sign with Format 2 (what GPG agent uses)<br>gcry_sexp_t data_sexp;<br>gcry_sexp_build(&data_sexp, NULL,<br>    "(data (flags eddsa) (hash-algo sha512) (value %b))",<br>    32, message_hash);<br><br>gcry_sexp_t sig;<br>gcry_pk_sign(&sig, data_sexp, private_key);  // ✓ SUCCEEDS<br><font face="arial, sans-serif" color="#000000"><span class="gmail_default" style="font-family:"times new roman",serif;font-size:large;color:rgb(7,55,99)"></span><br>// TEST: Verify the same signature<br>gcry_error_t err = gcry_pk_verify(sig, data_sexp, public_key);<br>// ✗ FAILS with "Bad signature"<br>```<br><br>### Why This Matters<br><br>1. **GPG agent uses Format 2** - The failing format `(data (flags eddsa) (hash-algo sha512) (value %b))` is what GPG agent generates (see `gnupg/agent/pksign.c`)<br><br>2. **GPG agent skips EdDSA verification** - Line 420-425 of `agent/pksign.c` shows verification is only performed for RSA, not EdDSA. This hid the bug.<br><br>3. **Real-world impact** - Applications using libgcrypt to verify GPG agent signatures will fail, even though the signatures are valid.<br><br>### Root Cause<br><br>The bug appears to be in `libgcrypt/cipher/ecc-eddsa.c` where the `PUBKEY_FLAG_PREHASH` flag causes different hash computations during signing vs verification:<br><br>- **During signing:** Hash is computed once and reused<br>- **During verification:** Hash is computed differently<br>- **Result:** Verification fails despite valid signature<br><br>### Test Results<br><br>| Format | Sign | Verify | Notes |<br>|--------|------|--------|-------|<br>| Format 1: `(data (value %b))` | ❌ | N/A | Expected - no hash-algo |<br>| Format 2: `(data (flags eddsa) (hash-algo sha512) (value %b))` | ✅ | ❌ | **THE BUG** |<br>| Format 3: `(data (value %b))` | ✅ | ✅ | Works, but not what GPG uses |<br><br>### Proposed Fix<br><br>The PUBKEY_FLAG_PREHASH logic needs to be consistent between signing and verification paths.<br><br>## Questions<br><br>1. Can you confirm this is a genuine bug in libgcrypt's verification logic?<br>2. Should I open a formal bug in the <a href="http://dev.gnupg.org">dev.gnupg.org</a> tracker?<br>3. Would a patch fixing the PUBKEY_FLAG_PREHASH handling be acceptable?<br><br></font><div class="gmail_default" style=""><font face="arial, sans-serif" style="" color="#000000">Thanks,</font></div>Zachary Fogg<br><br>---<br><br>## Additional Context<br><br>- **Issue tracking:** <a href="https://github.com/zfogg/ascii-chat/issues/92">https://github.com/zfogg/ascii-chat/issues/92</a><br>- **Test programs:** Available on request<br>- **Versions tested:** libgcrypt 1.11.2, GnuPG 2.4.8<br>- **Use case:** Terminal video chat app (ascii-chat) authenticating users via GitHub GPG keys<br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><span><div><div dir="ltr"><span><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><div style="font-size:12.8px"><font size="1" face="monospace, monospace">--</font></div><div style="font-size:12.8px"><font size="1" face="monospace, monospace">🐨 </font>ẔƑ<font size="1" face="monospace, monospace"> 👾</font></div><div style="font-size:12.8px"><font size="1" face="monospace, monospace"><a href="https://zfo.gg/" target="_blank">zfo.gg/</a></font></div></div></div></div></div></div></div></div></div></div></div></span></div></div></span></div></div></div>