Reject non-canonical Ed25519 public keys with y >= p (GH #1348)#1349
Open
Coralesoft wants to merge 1 commit into
Open
Reject non-canonical Ed25519 public keys with y >= p (GH #1348)#1349Coralesoft wants to merge 1 commit into
Coralesoft wants to merge 1 commit into
Conversation
Per RFC 8032 section 5.1.3, the encoded y coordinate of an Ed25519 public key must satisfy y < p = 2^255 - 19. ed25519PublicKey::Validate() returned true unconditionally, and the Donna verify path unpacked pubkeys without a canonicality check, so encodings with y = p, y = p + 1, and similar aliases decoded to the identity point. Adds an IsCanonicalY helper in xed25519.cpp and a matching ed25519_pubkey_is_canonical helper in donna_32.cpp and donna_64.cpp. Validate() and ge25519_unpack_negative_vartime() now reject y >= p before point recovery. Regression test in validat9.cpp covers y = 1, y = p - 1 (accepted) and y = p, y = p + 1, y = 2^255 - 1 (rejected) against the witness signature from the issue.
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.
Fixes #1348.
Problem
ed25519PublicKey::Validate()returns true unconditionally, and the Donna verify path unpacks the encoded public key without rejectingy >= p = 2^255 - 19. This lets multiple byte encodings decode to the same group element, as demonstrated by the PoC in the issue (canonicaly = 1and non-canonicaly = p + 1both verify against the same witness signature).Fix
xed25519.cpp: newIsCanonicalYhelper;Validate()calls it and returns false fory >= p.donna_32.cpp,donna_64.cpp: newed25519_pubkey_is_canonicalhelper;ge25519_unpack_negative_vartimerejects non-canonicalybefore pointrecovery.
validat9.cpp: regression test covering canonical (y = 1,y = p - 1, accepted) andnon-canonical (
y = p,y = p + 1,y = 2^255 - 1, rejected) using the witness signature from the PoC.Testing
Validation passes locally on GCC 14 (Linux) and MinGW-w64 GCC 14 (Windows).
ValidateEd25519shows:No other tests affected.
Compatibility
y >= p.Validate()always returning true will now see falsefor such keys.
References