sm2: reject point at infinity in signature verification - #1946
Merged
Merged
Conversation
Step B6 of the verification algorithm fails if [s']G + [t]PA is the point at infinity. Without the check its x coordinate is taken as 0 and a signature with r = e passes B7.
tarcieri
reviewed
Oct 2, 2026
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.
In
verify_prehash, step B6 computes[s']G + [t]PAand goes straight to.to_affine().x(). draft-shen-sm2-ecdsa 5.3.1 (and GB/T 32918.2) say verification fails if that point is the point at infinity, but here the identity's x is just 0, so B7 turns intor == eand passes.Producing such a signature needs the private key (
r = e,s = -r*d / (1 + d)), so it's a conformance issue rather than a forgery, but other implementations reject it and this one shouldn't accept it either.This adds the identity check before taking x, plus a test in
tests/sm2dsa.rsthat builds that signature and fails on master.