Skip to main content

Python Library for Elliptic Curve Cryptography: key exchanges (Diffie-Hellman, Massey-Omura), ECDSA signatures, and Koblitz encoding. Suitable for crypto education and secure systems.

Project description

ecutils

A Pythonic Elliptic Curve Cryptography Library

CI Documentation Status PyPI Version PyPI Downloads codecov

ecutils is a pure Python library that provides a clean and straightforward interface for elliptic curve cryptography (ECC). Designed for educational purposes and for building secure systems, it implements common ECC operations, algorithms, and protocols with a focus on readability and ease of use.

Features

  • Core Operations: Point addition, doubling, and scalar multiplication on various curves.
  • Standard Curves: Pre-configured parameters for secp192k1, secp192r1, secp224k1, secp224r1, secp256k1, secp256r1, secp384r1, and secp521r1.
  • Digital Signatures: Implementation of the Elliptic Curve Digital Signature Algorithm (ECDSA).
  • Key Exchange Protocols: Secure key exchange using Diffie-Hellman (ECDH) and Massey-Omura.
  • Message Encoding: Koblitz's method for encoding messages to and from curve points.
  • Performance: Optimized with LRU cache and Jacobian (projective) coordinates for faster computations.
  • Pure Python: No external dependencies required.

Installation

Install ecutils directly from PyPI:

pip install ecutils

Quickstart: Digital Signatures (ECDSA)

Here's a quick example of how to generate and verify a digital signature.

import hashlib
import secrets
from ecutils.algorithms import DigitalSignature

# 1. Generate a secure private key
# In a real application, this should be a securely generated and stored key.
private_key = secrets.randbits(256)

# 2. Create a DigitalSignature instance
# This automatically derives the public key.
ds = DigitalSignature(private_key, curve_name="secp256r1")

# 3. Prepare the message
# Always hash the message before signing.
message = b"This is a message to be signed."
message_hash = int.from_bytes(hashlib.sha256(message).digest(), "big")

# 4. Generate the signature
r, s = ds.generate_signature(message_hash)
print(f"Signature: (r={r}, s={s})")

# 5. Verify the signature
# This step would typically be done by the receiver, using the sender's public key.
is_valid = ds.verify_signature(ds.public_key, message_hash, r, s)

print(f"Signature is valid: {is_valid}")
# Output: Signature is valid: True

For more examples, including key exchange and message encoding, please check out our full documentation.

Performance

ECUtils is optimized for performance using LRU caching and Jacobian coordinates. Here's a sample of signature operations on secp256r1:

Configuration Signature Generation Signature Verification
Jacobian + LRU Cache 0.02 ms 0.04 ms
Jacobian (no cache) 17.35 ms 53.48 ms
Affine + LRU Cache 0.07 ms 0.11 ms
Affine (no cache) 17.24 ms 51.21 ms

For complete benchmarks across all curves and operations, see the Benchmarks documentation.

Supported Curves

Curve Key Size Use Case
secp192k1 192-bit Legacy systems
secp192r1 192-bit Legacy systems
secp224k1 224-bit Moderate security
secp224r1 224-bit Moderate security
secp256k1 256-bit Bitcoin, Ethereum
secp256r1 256-bit TLS, general purpose
secp384r1 384-bit High security
secp521r1 521-bit Maximum security

Documentation

Contributing

Contributions are welcome! Please read our contributing guidelines to get started.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ecutils-1.1.5.tar.gz (39.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ecutils-1.1.5-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file ecutils-1.1.5.tar.gz.

File metadata

  • Download URL: ecutils-1.1.5.tar.gz
  • Upload date:
  • Size: 39.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ecutils-1.1.5.tar.gz
Algorithm Hash digest
SHA256 baea6c53d0e74792719a4c4d89f942944a3bf8efbf4f0be58a65de2ab1d09cce
MD5 65598a808c214db662636125bc031de8
BLAKE2b-256 033d892b718caf9c7e8d1dc9d0964c8db900ef15d855c5ea9f426cdacd4dac64

See more details on using hashes here.

File details

Details for the file ecutils-1.1.5-py3-none-any.whl.

File metadata

  • Download URL: ecutils-1.1.5-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ecutils-1.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8077c5a4627734fb0e0933d197b3a882a82c2bac7c1bddc1278bdab3d824ca6a
MD5 e62ea33be4f712b534979c7c8a1e83b6
BLAKE2b-256 2d27209b4b853b39be52800bdedca8821853a6a982078b23012071a9cf4f016a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page