A hands-on implementation of elliptic curve cryptography from first principles, written in Rust.
This project walks through the full cryptographic stack that powers Bitcoin — built from scratch, layer by layer.
| Module | Topic | What It Does |
|---|---|---|
1.1 |
Hashing & Randomness | SHA-256 hashing and cryptographically secure random number generation |
1.2 |
Field Element | Arithmetic over a finite field — numbers mod a prime p |
1.3 |
Scalar | Arithmetic mod the curve order n — the space where private keys live |
1.4 |
Curve Point | Elliptic curve point addition and the double-and-add scalar multiplication algorithm |
1.5 |
Secp256k1 | The specific curve parameters used by Bitcoin (p, n, G) |
1.6 |
Keys | Private key and public key generation (Q = d * G) |
1.7 |
ECDSA | Elliptic Curve Digital Signature Algorithm — sign and verify messages |
bitcoin_dojo/
├── src/
│ ├── lib.rs
│ └── ecc/
│ ├── constants.rs # secp256k1 curve parameters (p, n, G)
│ ├── field.rs # FieldElement — arithmetic mod p
│ ├── scalar.rs # Scalar — arithmetic mod n
│ ├── curve.rs # Point — elliptic curve point operations
│ ├── keys.rs # PrivateKey / PublicKey
│ ├── ecdsa.rs # sign() / verify() with RFC 6979
│ └── util.rs # SHA-256, secure random
└── tests/
└── ecc/
├── field_tests.rs
├── scalar_tests.rs
├── curve_tests.rs
├── keys_tests.rs
├── ecdsa_tests.rs
└── util_tests.rs
# Run all tests
cargo test
# Run tests for a specific module
cargo test field
cargo test scalar
cargo test curve
cargo test ecdsa
# Run with output visible
cargo test -- --nocapture┌─────────────────────────────────────────┐
│ 1.7 ECDSA — sign() / verify() │
├─────────────────────────────────────────┤
│ 1.6 Keys — PrivateKey / PublicKey │
├─────────────────────────────────────────┤
│ 1.5 Secp256k1 — p, n, G constants │
├─────────────────────────────────────────┤
│ 1.4 Curve Point — add, double-and-add │
├─────────────────────────────────────────┤
│ 1.3 Scalar — arithmetic mod n │
├─────────────────────────────────────────┤
│ 1.2 Field Element — arithmetic mod p │
├─────────────────────────────────────────┤
│ 1.1 Hashing & Randomness │
└─────────────────────────────────────────┘
[dependencies]
num-bigint = "0.4"
lazy_static = "1.4"
sha2 = "0.10"
hmac = "0.12"
rand = "0.9"
hex = "0.4"- Bitcoin / Ethereum transaction signing
- TLS/HTTPS certificate authentication
- SSH key-based authentication
- JWT token signing (ES256)
- Code signing and software verification
- Hardware wallet key management
- Zero-knowledge proof systems
- Programming Bitcoin — Jimmy Song
- Bitcoin Whitepaper — Satoshi Nakamoto
- SEC 2: Recommended Elliptic Curve Domain Parameters
- RFC 6979 — Deterministic ECDSA