Skip to content

Fix ECDSA timing attack vulnerability#73

Open
gregnazario wants to merge 2 commits intomainfrom
claude/fix-ecdsa-cve-2024-23342-aUa3y
Open

Fix ECDSA timing attack vulnerability#73
gregnazario wants to merge 2 commits intomainfrom
claude/fix-ecdsa-cve-2024-23342-aUa3y

Conversation

@gregnazario
Copy link
Contributor

  • Replaced python-ecdsa dependency with cryptography (>=43.0.0)
  • Rewrote secp256k1_ecdsa.py to use cryptography's EC module
  • CVE-2024-23342 is a Minerva timing attack in python-ecdsa that affects all versions. The maintainers stated they won't fix it as it's inherent to pure Python implementations
  • The cryptography library provides constant-time implementations that eliminate this vulnerability
  • All existing tests pass with the new implementation
  • Bumped version to 0.12.0 (breaking change due to dependency change)
  • Updated mypy.ini to remove ecdsa configuration

Description

Test Plan

Related Links

- Replaced python-ecdsa dependency with cryptography (>=43.0.0)
- Rewrote secp256k1_ecdsa.py to use cryptography's EC module
- CVE-2024-23342 is a Minerva timing attack in python-ecdsa that affects
  all versions. The maintainers stated they won't fix it as it's inherent
  to pure Python implementations
- The cryptography library provides constant-time implementations that
  eliminate this vulnerability
- All existing tests pass with the new implementation
- Bumped version to 0.12.0 (breaking change due to dependency change)
- Updated mypy.ini to remove ecdsa configuration
@gregnazario gregnazario requested a review from a team as a code owner January 21, 2026 02:38
- Remove unused imports (hashlib, serialization)
- Reorder imports per isort
- Apply black formatting
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request migrates from the python-ecdsa library to the cryptography library to fix CVE-2024-23342, a Minerva timing attack vulnerability in ECDSA signature generation. The python-ecdsa maintainers have stated they will not fix this vulnerability as it's inherent to pure Python implementations. The cryptography library provides constant-time implementations that eliminate this security concern.

Changes:

  • Replaced ecdsa dependency with cryptography>=43.0.0 in pyproject.toml
  • Completely rewrote secp256k1_ecdsa.py to use the cryptography library's EC module
  • Removed ecdsa-related mypy configuration
  • Updated CHANGELOG.md with breaking change notice
  • Bumped version to 0.12.0

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pyproject.toml Updated dependency from ecdsa to cryptography>=43.0.0 and bumped version to 0.12.0
poetry.lock Updated lock file with cryptography packages (versions 43.0.3 and 45.0.7 for different Python versions)
mypy.ini Removed ecdsa-specific mypy configuration that's no longer needed
aptos_sdk/secp256k1_ecdsa.py Complete rewrite using cryptography library while maintaining the same API surface for backward compatibility
CHANGELOG.md Added 0.12.0 release notes documenting the security fix and breaking change

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +95 to +96
# Use deterministic ECDSA (RFC 6979) with SHA3-256
signature_der = self.key.sign(data, ec.ECDSA(hashes.SHA3_256()))
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment on line 95 states that deterministic ECDSA (RFC 6979) is being used, but this should be verified. In the cryptography library, the default ec.ECDSA() algorithm uses RFC 6979 for deterministic signatures, which is correct. However, it would be good to add a test that verifies the signature is deterministic by checking that signing the same message multiple times produces the same signature.

Copilot uses AI. Check for mistakes.
signature = cast(Signature, signature)
self.key.verify(signature.data(), data)
sig_bytes = signature.data()

Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The verify method assumes signature bytes are exactly 64 bytes (32 for r, 32 for s) but doesn't validate the length before slicing at lines 188-189. If a signature with incorrect length is passed, this could lead to incorrect parsing. Consider adding a length check similar to what's done in Signature.deserialize.

Suggested change
# Ensure the raw signature is exactly 64 bytes (32 bytes for r, 32 bytes for s)
if len(sig_bytes) != Signature.LENGTH:
raise ValueError("Signature length mismatch")

Copilot uses AI. Check for mistakes.
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.

2 participants