Pure Python library for Elliptic Curve Cryptography (ECC) — built from scratch with clarity and educational readability in mind
Project description
ECC
A pure Python library for Elliptic Curve Cryptography (ECC) — built from scratch with clarity and educational readability in mind.
Supports digital signatures (ECDSA), key generation, and secure field arithmetic over common curves like secp256k1, P-256, and more.
✨ Features
- Finite field arithmetic over prime fields (
FieldElement) - Curve definition (
CurveandPoint) - ECC point addition, doubling, and scalar multiplication
- Key pair generation (
keys.py) - ECDSA signature generation and verification (
ecdsa.py) - Built-in support for popular curves (
secp256k1,P-256,brainpool, etc.) - Easy-to-understand documentation in every module for educational purposes
📦 Installation
From PyPI:
pip install eccrypto
🔍 Quick Examples
🔑 Key Generation
from ecc import generate_keypair
from ecc import secp256k1
priv, pub = generate_keypair(secp256k1)
print("Private Key:\n", priv)
print("Public Key:\n", pub)
✍️ ECDSA Sign & Verify
from ecc import secp256k1
from ecc import generate_keypair
from ecc import sign, verify
priv, pub = generate_keypair(secp256k1)
msg = b"Heyy! :D"
signature = sign(msg, priv)
print("Signature:", signature)
valid = verify(msg, signature, pub)
if valid:
print("The signtature is valid!")
📌 Curve and Point Usage
from ecc import Curve, Point
a, b = 2, 2 # Curve: y^2 = x^3 + 2x + 2
P = 17 # Prime modulus
G = (5, 1) # Generator Point
n = 19 # Number of points in E(Z/17Z)
curve = Curve(a, b, P, G, n)
print(curve)
G = Point(5, 1, curve)
print("Generator point: ", G)
P = 2 * G # Scalar Multiplication
P1 = P + P # Point Addition
print("2G = ", P)
print("2G + 2G = ", P1)
🔢 Field Arithmetic
from ecc import FieldElement
a = FieldElement(7, 13)
b = FieldElement(8, 13)
print("a + b =", a + b)
print("a * b =", a * b)
print("a ** -1 =", a ** -1) # Inverse of a
🧪 Testing
You can run the test suite using pytest:
pytest
All tests are located in the tests/ directory and cover field arithmetic, point operations, key generation, and ECDSA functionality.
🤝 Contributions Welcome
PRs for adding new curves, improving documentation, and optimizations are welcome. Please make sure all tests pass.
📄 License
Licensed under the GPL-3.0 License. See LICENSE.
📞 Contact
Author: Shivakumar Email: shivakumarjagadish12@gmail.com GitHub: drtoxic69
For questions, bug reports, or feature requests, please open an issue on the GitHub repository or contact me directly via email.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file eccrypto-0.2.0.tar.gz.
File metadata
- Download URL: eccrypto-0.2.0.tar.gz
- Upload date:
- Size: 47.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76f564c229382b15c96697f70d3ee7b4cf0b0d9ba605b2c291e7983c33a7030b
|
|
| MD5 |
2a0e98498a5ed55afa3f77c4a25dc1a9
|
|
| BLAKE2b-256 |
e7167bd66d014ec9a068462ffd5f84a74f5f7cb9c828bd55b41f966e67ccf6d0
|
File details
Details for the file eccrypto-0.2.0-py3-none-any.whl.
File metadata
- Download URL: eccrypto-0.2.0-py3-none-any.whl
- Upload date:
- Size: 26.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e50615e287b02254c4d3f87e68d3ecff7842cbba542ea6adf77662842682bf5
|
|
| MD5 |
e7e4f4f7a0732b7d38c84e377ce40c03
|
|
| BLAKE2b-256 |
fa7ce67310f3d1827810e92453a28a78f4aa9a978f0705c9260504349059bf63
|