Repository navigation
Conversation
is_low_order compared the raw bytes against the canonical encodings of 0, 1 and p - 1, so the non-canonical encodings p and p + 1 were not detected and x448() returned an all-zero shared secret for them.
This branch has not been deployed
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.
MontgomeryPoint::is_low_ordercompares the raw 56 bytes againstLOW_A/LOW_B/LOW_C, the canonical encodings of 0, 1 and p - 1. RFC 7748 has implementations accept non-canonical u values and reduce them, which the ladder does, sopandp + 1decode to 0 and 1 but get past the check.x448::PublicKey::from_bytesaccepts them andx448(sk, p)returnsSome([0; 56]), although its docs say it never returns a low order result.The check now reduces u before comparing. Only 0 and 1 have non-canonical encodings in 56 bytes, so this covers all of them.
Added
test_non_canonical_low_orderin x448, which fails on master for both values. #1306 moves this function toMontgomeryXpointunchanged, so it would need the same change if that lands first.