keys: VerifyingKey.precompute() works for keys built from bytes, PEM or DER - #382
Open
fametrano wants to merge 1 commit into
Open
keys: VerifyingKey.precompute() works for keys built from bytes, PEM or DER#382fametrano wants to merge 1 commit into
fametrano wants to merge 1 commit into
Conversation
VerifyingKey.from_string built the public point without the curve order, so on the Weierstrass curves precompute() failed with AssertionError for every key built from bytes, PEM or DER, the last two going through from_string. A verifying key obtained from a SigningKey, or from signature recovery, carries the order and could be precomputed. Pass the order to PointJacobi.from_bytes and test precompute() after each of the four constructions.
fametrano
force-pushed
the
precompute-after-from-string
branch
from
September 7, 2026 15:09
c07251f to
02c9cb7
Compare
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.
On the Weierstrass curves,
VerifyingKey.precompute()raisesAssertionErrorfor every key built withfrom_string,from_pemorfrom_der. On 0.19.2:precompute()SigningKey.from_secret_exponent(...).verifying_keyVerifyingKey.from_string(raw)/from_string(compressed)AssertionErrorVerifyingKey.from_pem(...)/from_der(...)AssertionErrorCause:
from_stringcallsPointJacobi.from_byteswithoutorder, sopoint.order()isNone;precompute()then hitsassert orderin_maybe_precompute.from_pemandfrom_dergo throughfrom_string. Keys from aSigningKeyor from signature recovery carry the order and are not affected; EdDSA keys take a separate branch.Fix: pass
order=curve.order(one line). Test:precompute()thenverify()after each of the four constructions; it fails on master and passes with the fix. Full suite: 2040 passed.The docstring says to call
precompute()when verifying hundreds of signatures under one key, which is exactly the caller who has the key as bytes, PEM or DER. Measured on secp256k1, a verification drops from about 1057 µs to 501 µs with the table.