|
1 | | -## Elliptic Curve Cryptography in Python |
| 1 | +# ECC |
| 2 | + |
| 3 | +[](https://pypi.org/project/eccrypto/) |
| 4 | +[](./LICENSE) |
| 5 | +[](https://pypi.org/project/eccrypto/) |
| 6 | +[](https://github.com/drtoxic69/ECC/issues) |
| 7 | + |
| 8 | + |
| 9 | +A pure Python library for **Elliptic Curve Cryptography (ECC)** — built from scratch with clarity and educational readability in mind. |
| 10 | +Supports digital signatures (ECDSA), key generation, and secure field arithmetic over common curves like `secp256k1`, `P-256`, and more. |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## ✨ Features |
| 15 | +- Finite field arithmetic over prime fields (`FieldElement`) |
| 16 | +- Curve definition (`Curve` and `Point`) |
| 17 | +- ECC point addition, doubling, and scalar multiplication |
| 18 | +- Key pair generation (`keys.py`) |
| 19 | +- ECDSA signature generation and verification (`ecdsa.py`) |
| 20 | +- Built-in support for popular curves (`secp256k1`, `P-256`, `brainpool`, etc.) |
| 21 | +- Easy-to-understand documentation in every module for educational purposes |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +## 📦 Installation |
| 26 | + |
| 27 | +### From PyPI: |
| 28 | +```bash |
| 29 | +pip install eccrypto |
| 30 | +``` |
| 31 | + |
| 32 | +## 🔍 Quick Examples |
| 33 | + |
| 34 | +### 🔑 Key Generation |
| 35 | + |
| 36 | +```python |
| 37 | +from ecc import generate_keypair |
| 38 | +from ecc import secp256k1 |
| 39 | + |
| 40 | +priv, pub = generate_keypair(secp256k1) |
| 41 | + |
| 42 | +print("Private Key:\n", priv) |
| 43 | +print("Public Key:\n", pub) |
| 44 | +``` |
| 45 | + |
| 46 | +### ✍️ ECDSA Sign & Verify |
| 47 | + |
| 48 | +```python |
| 49 | +from ecc import secp256k1 |
| 50 | +from ecc import generate_keypair |
| 51 | +from ecc import sign, verify |
| 52 | + |
| 53 | +priv, pub = generate_keypair(secp256k1) |
| 54 | + |
| 55 | +msg = b"Heyy! :D" |
| 56 | +signature = sign(msg, priv) |
| 57 | +print("Signature:", signature) |
| 58 | + |
| 59 | +valid = verify(msg, signature, pub) |
| 60 | + |
| 61 | +if valid: |
| 62 | + print("The signtature is valid!") |
| 63 | +``` |
| 64 | + |
| 65 | +### 📌 Curve and Point Usage |
| 66 | + |
| 67 | +```python |
| 68 | +from ecc import Curve, Point |
| 69 | + |
| 70 | +a, b = 2, 2 # Curve: y^2 = x^3 + 2x + 2 |
| 71 | + |
| 72 | +P = 17 # Prime modulus |
| 73 | +G = (5, 1) # Generator Point |
| 74 | +n = 19 # Number of points in E(Z/17Z) |
| 75 | + |
| 76 | +curve = Curve(a, b, P, G, n) |
| 77 | +print(curve) |
| 78 | + |
| 79 | +G = Point(5, 1, curve) |
| 80 | +print("Generator point: ", G) |
| 81 | + |
| 82 | +P = 2 * G # Scalar Multiplication |
| 83 | +P1 = P + P # Point Addition |
| 84 | + |
| 85 | +print("2G = ", P) |
| 86 | +print("2G + 2G = ", P1) |
| 87 | +``` |
| 88 | + |
| 89 | +### 🔢 Field Arithmetic |
| 90 | + |
| 91 | +```python |
| 92 | +from ecc import FieldElement |
| 93 | + |
| 94 | +a = FieldElement(7, 13) |
| 95 | +b = FieldElement(8, 13) |
| 96 | + |
| 97 | +print("a + b =", a + b) |
| 98 | +print("a * b =", a * b) |
| 99 | +print("a ** -1 =", a ** -1) # Inverse of a |
| 100 | +``` |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +## 🧪 Testing |
| 105 | + |
| 106 | +You can run the test suite using pytest: |
| 107 | + |
| 108 | +```bash |
| 109 | +pytest |
| 110 | +``` |
| 111 | + |
| 112 | +All tests are located in the `tests/` directory and cover field arithmetic, point operations, key generation, and ECDSA functionality. |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +## 🤝 Contributions Welcome |
| 117 | + |
| 118 | +PRs for adding new curves, improving documentation, and optimizations are welcome. Please make sure all tests pass. |
| 119 | + |
| 120 | +--- |
| 121 | + |
| 122 | +## 📄 License |
| 123 | + |
| 124 | +Licensed under the GPL-3.0 License. See [LICENSE](./LICENSE). |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +## 📞 Contact |
| 129 | + |
| 130 | +**Author:** Shivakumar |
| 131 | +**Email:** shivakumarjagadish12@gmail.com |
| 132 | +**GitHub:** [drtoxic69](https://github.com/drtoxic69) |
| 133 | + |
| 134 | +For questions, bug reports, or feature requests, please open an issue on the [GitHub repository](https://github.com/drtoxic69/ECC) or contact me directly via email. |
0 commit comments