Raise ValueError from verify_digest for Edwards curve keys (fixes #349)#380
Open
apoorvdarshan wants to merge 1 commit into
Open
Raise ValueError from verify_digest for Edwards curve keys (fixes #349)#380apoorvdarshan wants to merge 1 commit into
apoorvdarshan wants to merge 1 commit into
Conversation
VerifyingKey.verify_digest lacked the CurveEdTw guard that verify() and
the SigningKey.sign_digest* methods already have. Calling it on an EdDSA
(Ed25519/Ed448) key therefore fell through to the ECDSA path and raised a
confusing AttributeError: 'PublicKey' object has no attribute 'order',
instead of a clear error telling the user the method is unsupported.
Add the same guard used by sign_digest(), raising
ValueError("Method unsupported for Edwards curves"), and document the
raised exception. EdDSA signs the message directly and has no pre-hashed
digest API, so verify() is the correct entry point.
Fixes tlsfuzzer#349
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 #349
Root cause
VerifyingKey.verify_digestis missing theCurveEdTwguard thatVerifyingKey.verifyand theSigningKey.sign_digest*methods alreadyhave. For an Edwards-curve (EdDSA) key the method falls through to the
ECDSA code path and reaches:
An EdDSA public key's
pubkeyis aPublicKeyobject that has noorderattribute, so the call raises a confusingAttributeErrorinstead of a clear "unsupported for Edwards curves" error. This is
exactly the behaviour reported in the issue.
Reproduction
Before the fix:
After the fix:
Fix
Add the same two-line guard used by
sign_digest()/sign_digest_deterministic()/sign_number()at the top ofverify_digest():and document the raised exception in the docstring. EdDSA signs the
message directly and has no pre-hashed-digest verification API, so
verify()is the correct entry point (as noted in the issue). Thechange is fully localized to
verify_digest; no other code path isaffected.
Tests
Added
test_ed25519_verify_digesttoTestVerifyingKeyFromDerinsrc/ecdsa/test_keys.py, asserting thatverify_digeston an Ed25519key raises
ValueErrorcontaining "Method unsupported for Edwards".It mirrors the existing
test_ed25519_sign_digeststyle. Confirmed itfails on unmodified
master(with theAttributeErrorabove) andpasses after the fix.
Test runs (Python 3.14, pytest):
test_keys.py: 179 passedtest_eddsa.py: 87 passedtest_pyecdsa.py: 800 passedtest_malformed_sigs.py: 205 passedflake8 setup.py speed.py srcis clean, andblack --line-length 79reports both changed files unchanged.
Disclosure: prepared with AI assistance; reviewed and verified locally.