Repository navigation
Reject small-order keys and a small-order R: no key anyone can sign for - #31
Merged
Merged
Conversation
Spec 1.4 said only "Ed25519 (RFC 8032)", which does not say which signatures to accept. Both implementations accepted a did:key whose key is the identity point, under which the signature 0x01 followed by 63 zero bytes verifies for every message, and every other small-order encoding, canonical or not, at parse. So anyone could sign a writ, a call, or a tally as such a key, use a writ issued to it, and put a tally in its name into a receipt tree. - spec 1.3: all fourteen small-order encodings are bad_key wherever a key appears, checked at 6.1 step 5 before any signature. - spec 1.4: a signature whose R is a small-order encoding is bad_signature. Only a signer choosing r = 0 makes one; crypto/ed25519 and OpenSSL accept it and libsodium 1.0.22 refuses it (open.c, ge25519_has_small_order on R and on the key). - Go keys and Python keys reject both, from one seven-entry table. - 19 vectors appended (270 to 288); the first 269 regenerate byte for byte. Both verifiers at 85a17fc accept all 19. - Corrects docs/design/08-builder-review.md:92, which said both libraries reject such keys. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
Writ identifies every party by a
did:key, which is just an Ed25519 public key. A handful of public keys are "small-order" points, which no real key pair ever produces. For the worst of them, the identity point (did:key:z6MkeXATEjyXENzBXBxgC5EHk2JE5aqd7qMGGtDpLUH1e2Sj), one fixed 64-byte signature (0x01then 63 zero bytes) verifies over any message. Both implementations accepted it, because the spec said only "Ed25519 (RFC 8032)" and both Ed25519 libraries let it through.What that meant in practice:
docs/design/08-builder-review.md:92said both libraries reject such keys. Nobody had checked.Reproduced on
85a17fcbefore the fix, with a control each time:keys.Verifykeys.verifyWhat changes
bad_key, wherever a key appears, before any signature is checked. The spec lists them as 7 values with the top bit cleared, the same table libsodium uses. I derived the 14 independently from the curve equation and they match libsodium's list exactly.bad_signature. Decision and source are below.hldbound; and the r = 0 signature from an honest key. The first 269 regenerate byte for byte.08-builder-review.md:92corrected, two rows inconformance/ADVERSARIAL.md, and every count that changed (README 269 to 288 vectors, 200 to 219 rejections, Python unit tests 140 to 151,implementation-status.md).Reason code. The builder review called this
did_invalid, a name from before the spec existed. Spec section 11 namesbad_keyfor "an identifier is not an Ed25519 did:key", so that is what this uses. No member, object, or reason code changed meaning.The small-order R decision, and the source
libsodium rejects a small-order R, and also a small-order or non-canonical public key, before it ever runs the verification equation:
src/libsodium/crypto_sign/ed25519/ref10/open.clines 33 to 39:sc25519_is_canonical(sig + 32) == 0 || ge25519_has_small_order(sig) != 0returns -1, thenge25519_is_canonical(pk) == 0 || ge25519_has_small_order(pk) != 0returns -1.ge25519_has_small_order(crypto_core/ed25519/ref10/ed25519_ref10.c:1076) is the same 7-value table, sign bit masked. https://github.com/jedisct1/libsodium/blob/1.0.22-RELEASE/src/libsodium/crypto_sign/ed25519/ref10/open.cmaster(75c6d55) rewrote this to decode the points and use a cofactored check, but it still rejects a small-order R and a small-order key.Decision: reject it. Go's
crypto/ed25519and OpenSSL accept the r = 0 signature, so without the rule one signer could make a tally that our verifiers accept and a libsodium-based verifier rejects. No honest signature is affected. It is not needed against outside forgers once small-order keys are gone.How it was checked
85a17fcfor behavioral reasons, not a build failure (Go fails with "small-order key accepted" and "signature with a small-order R accepted"; Python fails withWritError not raised), and pass here. Both85a17fcverifiers accept all 19 new vectors (269 passed, 19 failed) and reject none.build failedandSyntaxError, not just--- FAIL. The mutants: no key check, no R check, no sign-bit masking, and the table missing the p+1 entry, in Go and in Python.Blast radius
src/encoding.ts:132) and verifies through Node'scrypto, which is OpenSSL. Node 20.19.6 (OpenSSL 3.6.4) accepts the identity-key forgery here, with its control rejecting. So writ-ts has the same hole and is expected to accept all 19. I read its source and tested the primitive; I did not run writ-ts.~/.local/binwere not touched. They run85a17fcuntil rebuilt after merge. The gate's own keys are generated, so they are not small-order.keys.Verify.Not in this PR (open decisions)
🤖 Generated with Claude Code