Skip to content

Reject signatures when the verification sum is the point at infinity - #391

Open
mathewOracle wants to merge 1 commit into
tlsfuzzer:masterfrom
mathewOracle:fix-verify-point-at-infinity
Open

mathewOracle wants to merge 1 commit into
tlsfuzzer:masterfrom
mathewOracle:fix-verify-point-at-infinity

Conversation

@mathewOracle

Copy link
Copy Markdown

Fixes #389.

If u1*G + u2*Q is the point at infinity, Public_key.verifies() evaluates xy.x() % n with xy.x() returning None, so VerifyingKey.verify() raises TypeError instead of BadSignatureError. The signature was never accepted, but callers that only catch BadSignatureError get an unhandled exception on attacker-chosen input.

The fix returns False when xy == ellipticcurve.INFINITY, as suggested in the issue. Both Point.__eq__ and PointJacobi.__eq__ short-circuit on other is INFINITY, so it adds no real cost. I used the equality check rather than xy.x() is None because a PointJacobi with z == 0 compares equal to INFINITY, while its x() would call inverse_mod(0, p).

Tests:

  • test_ecdsa.py: r = s = 1 with Q = -msg*G, for both the Jacobi generator and an affine Point generator (the mul_add and non-mul_add branches).
  • test_keys.py: the same case through VerifyingKey.verify() on NIST P-256, expecting BadSignatureError.

All three fail on master and pass with the fix. The full suite passes locally, and black --line-length 79 and flake8 are clean.

I also ran Wycheproof testvectors_v1 (brainpoolP224/256/320/384/512r1 and secp256r1/secp384r1 with their SHA-2 files, 5058 vectors) through VerifyingKey.verify(). On master, 47 vectors raise TypeError, all flagged PointDuplication and/or ArithmeticError, 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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

verify() raises TypeError instead of rejecting when u1*G + u2*Q is the point at infinity

1 participant