Registry / auth-security / ecdsa
library0.19.2pypypi✓ verified 26d ago

ecdsa is a pure Python implementation of Elliptic Curve Cryptography (ECC) supporting ECDSA (Elliptic Curve Digital Signature Algorithm), EdDSA (Edwards-curve Digital Signature Algorithm), and ECDH (Elliptic Curve Diffie-Hellman). It is actively maintained with several releases per year, providing a robust solution for digital signatures in Python applications. The current version is 0.19.2.

pip install ecdsa
INSTALL
IMPORT
SIG · ECDSA
E
ecdsa
auth-securitypythonv0.19.2
Install
1.8s avg
Import
37ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.19.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.038s · 19MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.036s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SigningKey
from ecdsa import SigningKey
VerifyingKey
from ecdsa import VerifyingKey
NIST256p
from ecdsa import NIST256p
SECP256k1
from ecdsa import SECP256k1

This quickstart demonstrates how to generate an ECDSA private and public key pair using the NIST256p curve, sign a message digest with the private key, and then verify the signature using the corresponding public key.

import hashlib from ecdsa import SigningKey, NIST256p, VerifyingKey # 1. Generate a private key using the NIST256p curve sk = SigningKey.generate(curve=NIST256p) print("Private Key (hex):", sk.to_string().hex()) # 2. Derive the public key vk = sk.get_verifying_key() print("Public Key (hex):", vk.to_string().hex()) # 3. Message to sign (must be bytes) message = b"This is a test message to be signed." # Hash the message before signing message_hash = hashlib.sha256(message).digest() # 4. Sign the message hash signature = sk.sign_digest(message_hash) print("Signature (hex):", signature.hex()) # 5. Verify the signature try: assert vk.verify_digest(signature, message_hash) == True print("Signature is valid.") except Exception as e: print(f"Signature verification failed: {e}")
Debug
Known issues
breakingCVE-2024-23342 (Minerva Timing Attack) affects P-256 curves in versions 0.18.0 and prior. This side-channel vulnerability allows attackers to leak the internal nonce via timing measurements, potentially leading to private key discovery. The maintainers consider side-channel attacks out of scope, and no fix is planned for this pure-Python implementation.
fix
For security-sensitive applications where side-channel resistance is critical, consider using a cryptographic library with constant-time implementations (e.g., `cryptography` library) or ensure your environment mitigates timing attacks.
affects: <=0.18.0
breakingCVE-2026-33936 fixed a DER parsing issue where truncated buffers were not detected, which could lead to unexpected exceptions in functions like `SigningKey.from_der()` when parsing malformed data.
fix
Update to version 0.19.2 or later to ensure robust DER parsing and prevent potential DoS from malformed inputs. Carefully validate any DER-encoded inputs from untrusted sources.
affects: <0.19.2
gotchaWhen serializing keys using `to_pem()` or `to_der()`, in versions 0.16.0 and later, it is recommended to explicitly set `format="pkcs8"`. Not doing so will default to the legacy 'ssleay' format, which may not be the desired standard for modern applications or interoperability.
fix
Always specify `format="pkcs8"` when calling `to_pem()` or `to_der()` for private keys: `key.to_pem(format="pkcs8")`.
affects: >=0.16.0
deprecatedOfficial support for Python 3.3 and 3.4 was dropped starting from version 0.19.0 due to CI environment challenges.
fix
Upgrade to a currently supported Python version (e.g., Python 3.8 or newer).
affects: >=0.19.0
gotchaThe `to_string()` method, inherited from Python 2 naming conventions, actually returns `bytes` objects, not Python `str`.
fix
Handle the return value as `bytes` when using `to_string()`.
affects: All versions
gotchaWhen deserializing keys using `SigningKey.from_string(s, curve)` or `VerifyingKey.from_string(s, curve)`, the `curve` parameter *must* be explicitly provided as the short string format does not embed curve information. If the wrong curve is provided, verification will fail or lead to incorrect keys.
fix
Ensure you store and provide the correct elliptic curve (e.g., `NIST256p`) when using `from_string()`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'ecdsa'
The 'ecdsa' library has not been installed in the Python environment, or the environment where the code is being run is different from where it was installed.
fix
Install the library using pip: `pip install ecdsa`.
ImportError: cannot import name 'SECP256kl' from 'ecdsa'
This error occurs due to a common typo when trying to import the SECP256k1 elliptic curve; the lowercase 'l' is used instead of the numeral '1'.
fix
Correct the curve name to 'SECP256k1': `from ecdsa import SECP256k1, SigningKey`.
AttributeError: 'VerifyingKey' object has no attribute 'default_hashfunc'
This error typically arises when attempting to verify a signature using an older method or when a `VerifyingKey` object has been incorrectly serialized and deserialized, leading to missing internal state, especially when `hashfunc` is not explicitly provided.
fix
When verifying, ensure you explicitly provide the `hashfunc` argument, or use the `VerifyingKey.from_string` (or similar) method to properly reconstruct the key if it was serialized, and ensure compatibility with the library version. Example: `verifying_key.verify(signature, message_hash, sigdecode=ecdsa.util.sigdecode_string, hashfunc=hashlib.sha256)`.
AttributeError: module 'ecdsa' has no attribute 'secp224k1'
The `ecdsa` library does not directly expose all elliptic curves as top-level attributes or may not support specific curves like 'secp224k1' (often confused with 'secp224r1' or requiring a different curve instantiation method).
fix
Refer to the `ecdsa.curves` module for available curves (e.g., `ecdsa.NIST224p` or `ecdsa.SECP256k1`) or use `ecdsa.curves.Curve` to define a custom curve if it's supported and parameters are known.
ecdsa.BadSignatureError
This exception is raised when a signature cannot be successfully verified. Common reasons include incorrect message hashing, wrong public key, signature corruption, or mismatches in signature encoding formats (e.g., DER vs. raw R+S concatenation) or curve parameters between signing and verification processes.
fix
Ensure the message is hashed correctly before signing and verifying, the correct public key is used, and the signature encoding (e.g., DER) is consistently applied during both signing and verification. Double-check the elliptic curve used for key generation and signature operations.
Upgrade
Version history
0.19.2latest on PyPI · released Mar 26, 2026
Audit
Dependencies
sixrequiredMandatory dependency for compatibility, automatically installed by pip.
Agent activity
38 hits · last 30 days
node
36
OpenAI (training)
1
Resources
ecdsa — pip install ecdsa · libregistry