Fast Elliptic Curve Digital Signatures (fastecdsa)

3.0.1 · active · verified Thu Apr 16

fastecdsa is a Python library designed for fast elliptic curve digital signatures. It provides an efficient implementation of ECDSA for various standard curves and hash functions, outperforming some other pure Python alternatives. The library is currently at version 3.0.1, with its latest major release in January 2025, and continues to be actively maintained.

Common errors

Warnings

Install

Imports

Quickstart

Generates an ECDSA keypair using the P256 curve, signs a sample message with the private key, and then verifies the signature using the public key and the same curve and hash function.

from fastecdsa import keys, curve, ecdsa
from hashlib import sha256

# 1. Generate a keypair
private_key, public_key = keys.gen_keypair(curve.P256)

# 2. Message to sign (can be string, bytes, or bytearray)
message = "This is a test message to be signed."

# 3. Sign the message
r, s = ecdsa.sign(message, private_key, curve.P256, hashfunc=sha256)

# 4. Verify the signature
valid = ecdsa.verify((r, s), message, public_key, curve.P256, hashfunc=sha256)

print(f"Private Key: {hex(private_key)}")
print(f"Public Key (x, y): ({hex(public_key.x)}, {hex(public_key.y)})")
print(f"Signature (r, s): ({hex(r)}, {hex(s)})")
print(f"Signature Valid: {valid}")

view raw JSON →