Repository navigation
Reject signatures when the verification sum is the point at infinity - #391
Open
mathewOracle wants to merge 1 commit into
Open
mathewOracle wants to merge 1 commit into
mathewOracle wants to merge 1 commit into
Conversation
When u1*G + u2*Q is the point at infinity, Public_key.verifies() computed `xy.x() % n` with `xy.x()` returning None, so VerifyingKey.verify() raised TypeError instead of BadSignatureError. Fixes tlsfuzzer#389
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 #389.
If
u1*G + u2*Qis the point at infinity,Public_key.verifies()evaluatesxy.x() % nwithxy.x()returningNone, soVerifyingKey.verify()raisesTypeErrorinstead ofBadSignatureError. The signature was never accepted, but callers that only catchBadSignatureErrorget an unhandled exception on attacker-chosen input.The fix returns
Falsewhenxy == ellipticcurve.INFINITY, as suggested in the issue. BothPoint.__eq__andPointJacobi.__eq__short-circuit onother is INFINITY, so it adds no real cost. I used the equality check rather thanxy.x() is Nonebecause aPointJacobiwithz == 0compares equal toINFINITY, while itsx()would callinverse_mod(0, p).Tests:
test_ecdsa.py:r = s = 1withQ = -msg*G, for both the Jacobi generator and an affinePointgenerator (themul_addand non-mul_addbranches).test_keys.py: the same case throughVerifyingKey.verify()on NIST P-256, expectingBadSignatureError.All three fail on master and pass with the fix. The full suite passes locally, and
black --line-length 79andflake8are clean.I also ran Wycheproof
testvectors_v1(brainpoolP224/256/320/384/512r1 and secp256r1/secp384r1 with their SHA-2 files, 5058 vectors) throughVerifyingKey.verify(). On master, 47 vectors raiseTypeError, all flaggedPointDuplicationand/orArithmeticError, on the NIST curves as well as brainpool. With this change all 5058 give the expected result, with no new accepts or rejects.I used an AI assistant to help write and test this change. I've reviewed the diff and the test results.