Repository navigation
Check the order and cofactor of explicit curve parameters - #392
Open
mathewOracle wants to merge 1 commit into
Open
mathewOracle wants to merge 1 commit into
mathewOracle wants to merge 1 commit into
Conversation
Curve equality only compares the curve equation and the generator, so explicit parameters with a wrong order or cofactor were matched to a well-known curve and accepted. Reject an order below 2 and a cofactor of 0, and require the order and the cofactor (when present) to match the well-known curve. Fixes tlsfuzzer#390
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 #390.
Curve.from_der()matches explicit parameters to a well-known curve withCurve.__eq__, which only compares the curve equation and the generator. So parameters withorder = 0, orcofactor = n, were matched to the named curve and accepted.This change:
remove_integer)I left
Curve.__eq__alone, because changing equality semantics seemed riskier than checking in the parser.New tests in
test_curves.pybuild NIST P-256 explicit parameters with order 0, 1 and n-1, and with cofactor 0, 2 and n. All six fail on master and pass here. Matching parameters with cofactor 1 or no cofactor still decode toNIST256p. The full suite passes, andblack --line-length 79andflake8are clean.Wycheproof check. I ran
testvectors_v1ecdh_*for brainpoolP224r1 through P512r1 and secp224r1 through secp521r1 (9 files) throughECDH.load_received_public_key_der()andgenerate_sharedsecret_bytes().public,privateandsharedvalues as a "no cofactor" vector marked acceptable, so no implementation can satisfy both. Accepting it matches the field being optional.I used an AI assistant to help write and test this change. I've reviewed the diff and the test results.