Elliptic Curve Cryptography

Understanding elliptic curves used in blockchain cryptography.

Advanced⏱️ 50 min📚 Prerequisites: 1

Elliptic Curve Cryptography

Elliptic Curve Cryptography (ECC) is the foundation of blockchain security. It provides strong security with smaller key sizes than RSA.

Why Elliptic Curves?

  • Smaller keys: 256-bit ECC = 3072-bit RSA security
  • Faster operations: More efficient than RSA
  • Lower resource usage: Important for blockchain nodes
  • Industry standard: Used by Bitcoin, Ethereum, and most blockchains

secp256k1 Curve

Bitcoin and Ethereum use the secp256k1 curve:

  • Named after Standards for Efficient Cryptography
  • 256-bit security level
  • Well-tested and widely used

Key Operations

  1. Key Generation: Random point on curve = private key
  2. Public Key Derivation: Public key = private_key × generator_point
  3. Signing: Create signature using private key
  4. Verification: Verify signature using public key

Using ECC in Rust

RUST
// Add to Cargo.toml: secp256k1 = "0.28"
// use secp256k1::{Secp256k1, SecretKey, PublicKey, Message, Signature};

// Generate keypair
// let secp = Secp256k1::new();
// let (secret_key, public_key) = secp.generate_keypair(&mut thread_rng());

Curve Properties

  • Discrete Logarithm Problem: Hard to find private key from public key
  • Point Addition: Special addition operation on curve
  • Scalar Multiplication: Fast way to compute public key

Alternative Curves

  • Ed25519: Used by some newer blockchains (Solana)
  • P-256: NIST standard curve
  • secp256k1: Most common in blockchain

Security Considerations

  • Random number generation: Must be cryptographically secure
  • Key storage: Private keys must be encrypted
  • Side-channel attacks: Timing attacks can leak keys
  • Key derivation: Use proper key derivation functions

Code Examples

ECC Concepts

Understanding elliptic curve concepts

RUST
struct Point {
    x: u64,
    y: u64,
}
struct PrivateKey {
    value: u64,
}
struct PublicKey {
    point: Point,
}
fn generate_keypair() -> (PrivateKey, PublicKey) {
    let private_key = PrivateKey { value: 12345 };
    let public_key = PublicKey {
        point: Point { x: 67890, y: 11111 },
    };
    (private_key, public_key)
}
fn main() {
    let (private_key, public_key) = generate_keypair();
    println!("Private key (secret!): {}", private_key.value);
    println!("Public key point: ({}, {})", public_key.point.x, public_key.point.y);
}

Explanation:

Elliptic curves use points on a curve. The private key is a scalar (number), and the public key is a point derived by multiplying the generator point by the private key.

Curve Security

Why elliptic curves are secure

RUST
struct ECCKeyPair {
    private_key: String,
    public_key: String,
}
fn demonstrate_security() {
    let public_key = "public_point_on_curve";
    let private_key = "secret_scalar_value";
    println!("ECC security: Finding private key from public key is infeasible");
}
fn main() {
    demonstrate_security();
}

Explanation:

ECC security comes from the mathematical difficulty of the discrete logarithm problem. Even with the public key, finding the private key requires solving a computationally infeasible problem.

Exercises

Key Pair Structure

Create a structure representing an ECC key pair!

Medium

Starter Code:

RUST
fn main() {
}