Tutorial 2.14: Elliptic Curve Cryptography

Table of Contents

Learning Objectives

After completing this tutorial, you should be able to:

Overview

Elliptic Curve Cryptography (ECC) is a modern public-key cryptographic system that provides the same security as traditional systems (like RSA and classical Diffie-Hellman) but with significantly smaller key sizes. This efficiency makes ECC particularly attractive for constrained environments such as mobile devices, embedded systems, IoT devices, and smart cards, where computational power, memory, and bandwidth are limited.

ECC was independently proposed by Neal Koblitz and Victor S. Miller in 1985. It leverages the algebraic structure of elliptic curves over finite fields. The security of ECC is based on the Elliptic Curve Discrete Logarithm Problem (ECDLP), which is believed to be computationally harder than the integer factorization problem (used by RSA) or the finite field discrete logarithm problem (used by classical DH).

In this tutorial, we explore the mathematics and cryptographic applications of elliptic curves. We begin by defining elliptic curves and their group law (point addition and doubling). We then extend these concepts to finite fields and discuss scalar multiplication. We introduce the ECDLP and explain why it underpins ECC security. We then examine the major ECC protocols: ECDH (key exchange), ECDSA (digital signatures), and ECIES (encryption).

We compare ECC with RSA and classical DH, demonstrating the advantages of smaller key sizes and improved performance. We review standardized curves, including NIST P-256, Curve25519, and secp256k1, and discuss their use in real-world protocols such as TLS 1.3, SSH, Bitcoin, and WireGuard. Finally, we consider implementation considerations and security pitfalls.

Relationship to the Tutorial Series

In Tutorial 2.11, we introduced public-key cryptography. Tutorial 2.12 covered RSA, and Tutorial 2.13 covered Diffie-Hellman. This tutorial introduces ECC, which provides the same services (key exchange, signatures, encryption) as RSA and DH but with better efficiency. Tutorial 2.15 will cover digital signatures and PKI in more detail, building on the ECDSA foundation established here.

History of ECC

Elliptic curves have been studied in number theory for over a century, but their application to cryptography is relatively recent:

Today, ECC is the preferred public-key cryptography for many applications due to its efficiency and strong security properties.

Elliptic Curves: Definition and Properties

Elliptic Curve
An elliptic curve over a field K is defined by the Weierstrass equation:

y² = x³ + a·x + b

where a, bK and the discriminant Δ = −16(4a³ + 27b²) ≠ 0 (to ensure the curve has no singular points).

For real numbers, an elliptic curve is a smooth, cubic curve. The graph of y² = x³ + a·x + b has a characteristic shape:

y │ │ ╱╲ ╱╲ │ ╱ ╲ ╱ ╲ │ ╱ ╲ ╱ ╲ │ ╱ ╲╱ ╲ │ ╱ ╲ │ ╱ ╲ │╱ ╲ └─────────────────────────── x (Elliptic curve with one component, a > 0)

Figure 1: An elliptic curve over the real numbers (y² = x³ + ax + b).

Key Properties

The Group Law

The set of points on an elliptic curve, together with the point at infinity O, forms an abelian group with:

Elliptic Curves over Finite Fields

For cryptography, elliptic curves are defined over finite fields rather than real numbers. This ensures that the points form a finite set, making the discrete logarithm problem computationally hard.

Two types of finite fields are commonly used:

1. Prime Fields GF(p)

Where p is a large prime. The curve equation is:

y² ≡ x³ + a·x + b (mod p)

with a, b ∈ GF(p) and discriminant ≠ 0 mod p. The points are pairs (x, y) ∈ GF(p) × GF(p) that satisfy the equation, plus the point at infinity O.

2. Binary Fields GF(2m)

Where m is a positive integer. The curve equation is:

y² + x·y = x³ + a·x² + b

Binary fields are less common in modern applications due to security concerns and performance issues on many platforms. Prime fields are preferred.

Example: Consider the curve y² = x³ + 2x + 3 over GF(5). The points are:

Total points: (1,1), (1,4), (2,0), (3,1), (3,4), (4,0), plus O = 7 points.

Point Addition and Doubling

The group operation on elliptic curves can be defined geometrically or algebraically. For cryptographic implementations, we use algebraic formulas.

Point Addition (P ≠ Q)

For P = (x₁, y₁) and Q = (x₂, y₂) with P ≠ Q and P ≠ −Q:

λ = (y₂ − y₁) / (x₂ − x₁)
x₃ = λ² − x₁ − x₂
y₃ = λ·(x₁ − x₃) − y₁

P + Q = (x₃, y₃)

Point Doubling (P = Q)

For P = (x₁, y₁) with y₁ ≠ 0:

λ = (3x₁² + a) / (2y₁)
x₃ = λ² − 2x₁
y₃ = λ·(x₁ − x₃) − y₁

2P = (x₃, y₃)

Identity and Inverses

Worked Example: Point Addition on y² = x³ + 2x + 3 over GF(5)

Let P = (1, 1) and Q = (3, 1).
λ = (1 − 1) / (3 − 1) = 0 / 2 = 0
x₃ = 0² − 1 − 3 = −4 ≡ 1 mod 5
y₃ = 0·(1 − 1) − 1 = −1 ≡ 4 mod 5
P + Q = (1, 4).

Double P = (1, 1):
λ = (3·1² + 2) / (2·1) = (5) / 2 = 5 · 2⁻¹ mod 5 = 5 · 3 = 15 ≡ 0 mod 5
x₃ = 0² − 2·1 = −2 ≡ 3 mod 5
y₃ = 0·(1 − 3) − 1 = −1 ≡ 4 mod 5
2P = (3, 4).

Scalar Multiplication

Scalar multiplication is the operation of adding a point P to itself k times:

[k]P = P + P + ... + P (k times)

This is the ECC analog of modular exponentiation in RSA/DH. Efficient scalar multiplication is critical for ECC performance. The standard method is the double-and-add algorithm (similar to square-and-multiply).

Double-and-Add Algorithm

Input: Point P, scalar k
Output: Q = [k]P

Q ← O
R ← P
while k > 0:
  if k mod 2 = 1: Q ← Q + R
  R ← 2R
  k ← k / 2
return Q

The complexity of scalar multiplication is O(log k) point operations, making it efficient even for large k.

Key Insight: The difficulty of reversing scalar multiplication—finding k given P and Q = [k]P—is the Elliptic Curve Discrete Logarithm Problem (ECDLP). This is the foundation of ECC security.

The Elliptic Curve Discrete Logarithm Problem (ECDLP)

Elliptic Curve Discrete Logarithm Problem (ECDLP)
Given an elliptic curve E over a finite field, a base point P of order n, and a point Q ∈ ⟨P⟩, find the integer k (0 ≤ k < n) such that Q = [k]P.

The ECDLP is believed to be computationally hard for carefully chosen curves. The best known algorithms (Pollard's rho, baby-step giant-step) have exponential complexity, O(√n) group operations. For a 256-bit curve (n ≈ 2²⁵⁶), this is approximately 2¹²⁸ operations, which is infeasible with current technology.

Why ECDLP is harder than DLP in finite fields: The finite field DLP has subexponential algorithms (index calculus), while the ECDLP has no known subexponential algorithm for well-chosen curves. This allows ECC to use much smaller key sizes for the same security level.

ECC Key Generation

ECC key generation is simple and efficient:

ECC Key Generation

1. Select a curve E over a finite field and a base point P of prime order n.
2. Generate a random integer d in [1, n−1] (the private key).
3. Compute Q = [d]P (the public key).
4. Private key: d
5. Public key: Q (a point on the curve)

The security of ECC relies on the fact that given Q and P, it is infeasible to find d (the ECDLP).

Elliptic Curve Diffie-Hellman (ECDH)

ECDH is the elliptic curve version of Diffie-Hellman. It allows two parties to establish a shared secret over an insecure channel.

ECDH Key Exchange

Public parameters: Curve E, base point P of order n.

1. Alice: Generates private key dA ∈ [1, n−1], computes QA = [dA]P, sends QA to Bob.
2. Bob: Generates private key dB ∈ [1, n−1], computes QB = [dB]P, sends QB to Alice.
3. Alice: Computes S = [dA]QB.
4. Bob: Computes S = [dB]QA.
5. Both compute the same S = [dAdB]P.

The shared secret S is a point on the curve. The x-coordinate (or the full point) is passed through a key derivation function to produce a symmetric key.

Worked Example: ECDH (Conceptual)

Let E: y² = x³ + 2x + 3 over GF(5). P = (1, 1).
Alice chooses dA = 2 → QA = [2]P = (3, 4).
Bob chooses dB = 3 → QB = [3]P = (4, 0).
Alice computes S = [2]QB = [2](4, 0) = (2, 0).
Bob computes S = [3]QA = [3](3, 4) = (2, 0).
Shared secret: (2, 0).

Ephemeral ECDH (ECDHE)

When ephemeral keys are used for each session, ECDH provides perfect forward secrecy (PFS). This is the standard in TLS 1.3 and other modern protocols.

Elliptic Curve Digital Signature Algorithm (ECDSA)

ECDSA is the elliptic curve version of the Digital Signature Algorithm (DSA). It provides authentication and non-repudiation.

ECDSA Signing

Input: Message M, private key d, curve order n
1. Compute hash h = Hash(M).
2. Generate a random ephemeral key k ∈ [1, n−1].
3. Compute R = [k]P = (x₁, y₁).
4. Compute r = x₁ mod n. If r = 0, go to step 2.
5. Compute s = k⁻¹ (h + d·r) mod n. If s = 0, go to step 2.
6. Output signature (r, s).
ECDSA Verification

Input: Message M, signature (r, s), public key Q, curve order n
1. Check that r, s ∈ [1, n−1]. If not, reject.
2. Compute hash h = Hash(M).
3. Compute u₁ = h·s⁻¹ mod n and u₂ = r·s⁻¹ mod n.
4. Compute V = [u₁]P + [u₂]Q.
5. If V = O, reject.
6. Let x = x-coordinate of V. Accept if x ≡ r (mod n); otherwise reject.

Security of ECDSA

⚠️ Critical: Never reuse the ephemeral key k in ECDSA. If k is reused, the private key can be computed from the two signatures.

Elliptic Curve Encryption (ECIES)

ECIES (Elliptic Curve Integrated Encryption Scheme) is a hybrid encryption scheme that uses ECC for key exchange and a symmetric cipher for confidentiality.

ECIES Encryption

1. Generate an ephemeral key pair (k, R = [k]P).
2. Compute the shared secret S = [k]Q (where Q is the recipient's public key).
3. Derive symmetric keys from S using a KDF.
4. Encrypt the message with the symmetric key (e.g., AES-GCM).
5. Send (R, ciphertext, tag).

Decryption: Recipient uses their private key d to compute S = [d]R, derives the symmetric key, and decrypts.

ECIES is secure and efficient, but it is less commonly used than ECDH (for key exchange) and ECDSA (for signatures).

Security Benefits of ECC

Key Size Comparison

Security Level (bits)RSA Key SizeECC Key SizeRatio
8010241606.4x
11220482249.1x
128307225612x
192768038420x
2561536051230x

Advantages of ECC

Disadvantages

Standards and Recommended Curves

Standard Curves

CurveFieldKey Size (bits)Security (bits)Applications
NIST P-256GF(p)256128TLS, SSH, U.S. government
NIST P-384GF(p)384192High-security applications
NIST P-521GF(p)521256Very high security
Curve25519GF(p)255128TLS 1.3, SSH, WireGuard
Ed25519GF(p)255128Signatures (EdDSA)
secp256k1GF(p)256128Bitcoin, Ethereum
Curve448GF(p)448224High-security TLS

NIST Curves (FIPS 186-4)

NIST standardized 15 elliptic curves (P-192, P-224, P-256, P-384, P-521, and binary curves). P-256 is the most commonly used prime-field curve.

Curve25519 and Ed25519

Designed by Daniel J. Bernstein, Curve25519 and Ed25519 are modern, highly secure curves optimized for performance. They avoid many of the pitfalls of older curves (e.g., they are designed to be resistant to side-channel attacks and have simple, constant-time implementations).

SECG Curves

The Standards for Efficient Cryptography Group (SECG) defined the secp* and sect* curves. secp256k1 is the curve used in Bitcoin.

Standards Documents

Implementation Considerations

1. Point Validation

When receiving a point, always verify that it is on the curve (i.e., satisfies y² = x³ + ax + b) and that it is not the point at infinity unless expected. This prevents invalid curve attacks.

2. Constant-Time Operations

ECC operations must be constant-time to prevent timing and power analysis attacks. All scalar multiplication, point addition, and field operations should run in constant time.

3. Randomness

Private keys and ephemeral nonces must be generated using a cryptographically secure random number generator. In ECDSA, nonce reuse is catastrophic.

4. Deterministic ECDSA

Use RFC 6979 (Deterministic ECDSA) to generate k from the message and the private key using a KDF. This avoids the need for a random number generator for signatures.

5. Key Storage

Private keys must be stored securely, preferably in a hardware security module (HSM) or secure enclave.

6. Side-Channel Countermeasures

Applications

Transport Layer Security (TLS 1.3)

TLS 1.3 mandates ECDHE for key exchange (with P-256, P-384, X25519). It also uses Ed25519 signatures for some certificate types.

Secure Shell (SSH)

SSH supports ECDH (with NIST curves and Curve25519) and ECDSA for host and user authentication.

Bitcoin and Cryptocurrencies

Bitcoin uses secp256k1 with ECDSA for transaction signing. Ethereum also uses secp256k1.

WireGuard VPN

WireGuard uses Curve25519 (X25519) for key exchange and BLAKE2 for hashing.

Digital Signatures

ECDSA and EdDSA are used for code signing, document signing, and certificate signing.

Smart Cards and IoT

ECC's small key sizes and low power consumption make it ideal for constrained devices.

PGP/GPG

GPG supports ECDH and ECDSA for email encryption and signing.

Case Studies

Case Study 1: The PlayStation 3 Hack (2010)

In 2010, hackers recovered the ECDSA private key used by Sony to sign PlayStation 3 software. The attack exploited the reuse of the ephemeral nonce k in ECDSA signatures. By having two signatures with the same k, the private key could be recovered using basic algebra. This allowed unauthorized software to run on the PS3.

Lesson: Nonce reuse in ECDSA is catastrophic. Use deterministic ECDSA (RFC 6979) or ensure perfect randomness for each signature.

Case Study 2: Bitcoin and secp256k1

Bitcoin uses the secp256k1 curve for ECDSA signatures. The curve was chosen for its efficiency and security properties. However, in 2013, a vulnerability was discovered in Android's random number generator that caused nonce reuse, leading to the theft of Bitcoin. This highlighted the importance of secure randomness in ECDSA.

Case Study 3: The NSA's Suite B Cryptography

The NSA adopted ECC (Suite B) for U.S. government classified communications. Suite B mandated ECDH for key exchange and ECDSA for signatures, with P-256 and P-384 curves. This endorsement helped drive ECC adoption in industry.

Case Study 4: TLS 1.3 and ECC

TLS 1.3's mandate for ECDHE with forward secrecy, and the inclusion of X25519 and Ed25519, has made ECC the dominant public-key cryptography in modern web communications. Over 90% of TLS 1.3 connections use ECC.

Key Takeaways

Quiz

  1. What is an elliptic curve in cryptographic terms?
  2. AnswerAn elliptic curve is defined by the equation y² = x³ + ax + b over a finite field, with a non-zero discriminant. The set of points on the curve, together with the point at infinity, forms an abelian group.
  3. What is the group operation on an elliptic curve?
  4. AnswerThe group operation is point addition: given two points P and Q, their sum R = P + Q is defined geometrically (the reflection of the third intersection point of the line through P and Q) or algebraically using formulas.
  5. What is scalar multiplication in ECC?
  6. AnswerScalar multiplication is the operation of adding a point P to itself k times: [k]P = P + P + ... + P (k times). It is the core operation in ECC protocols.
  7. What is the ECDLP and why is it important?
  8. AnswerThe Elliptic Curve Discrete Logarithm Problem (ECDLP) is the problem of finding k given P and Q = [k]P. The hardness of the ECDLP is the foundation of ECC security.
  9. What is the difference between ECDH and ECDHE?
  10. AnswerECDH uses long-term (static) keys. ECDHE uses ephemeral keys generated per session, providing perfect forward secrecy.
  11. How many bits of security does a 256-bit ECC key provide?
  12. AnswerA 256-bit ECC key provides approximately 128 bits of security (the square root of the group size).
  13. What is the most critical vulnerability in ECDSA?
  14. AnswerThe most critical vulnerability is the reuse of the ephemeral nonce k. If k is reused for two different signatures, the private key can be recovered.
  15. Name three commonly used elliptic curves in practice.
  16. AnswerNIST P-256, Curve25519 (X25519), secp256k1, and Ed25519 are commonly used.
  17. What is the advantage of ECC over RSA?
  18. AnswerECC provides the same security as RSA with much smaller key sizes, leading to faster operations, lower power consumption, and reduced storage and bandwidth requirements.
  19. What is the role of point validation in ECC implementation?
  20. AnswerPoint validation ensures that a received point is actually on the curve and is not the point at infinity (unless expected). This prevents invalid curve attacks and small subgroup attacks.

Exercises

  1. Point Addition (GF(p))

    Consider E: y² = x³ + x + 1 over GF(7). P = (0, 1), Q = (1, 4). Compute P + Q and 2P.

  2. Sample Solution

    P = (0, 1), Q = (1, 4).

    λ = (4 − 1) / (1 − 0) = 3 / 1 = 3 mod 7.

    x₃ = 3² − 0 − 1 = 9 − 1 = 8 ≡ 1 mod 7.

    y₃ = 3·(0 − 1) − 1 = 3·(−1) − 1 = −3 − 1 = −4 ≡ 3 mod 7.

    P + Q = (1, 3).

    2P: λ = (3·0² + 1) / (2·1) = 1 / 2 = 1 · 4 = 4 mod 7.

    x₃ = 4² − 2·0 = 16 ≡ 2 mod 7.

    y₃ = 4·(0 − 2) − 1 = 4·(−2) − 1 = −8 − 1 = −9 ≡ 5 mod 7.

    2P = (2, 5).

  3. Scalar Multiplication

    Using the curve from Exercise 1, compute [3]P where P = (0, 1).

  4. Sample Solution

    From Exercise 1, 2P = (2, 5).

    3P = 2P + P = (2, 5) + (0, 1).

    λ = (1 − 5) / (0 − 2) = (−4) / (−2) = 4 / 2 = 4 · 4 = 16 ≡ 2 mod 7.

    x₃ = 2² − 2 − 0 = 4 − 2 = 2 mod 7.

    y₃ = 2·(2 − 2) − 5 = 0 − 5 = −5 ≡ 2 mod 7.

    [3]P = (2, 2).

  5. ECDH Key Exchange

    Using E: y² = x³ + 2x + 3 over GF(5) with P = (1, 1). Alice's private key is dA = 2, Bob's private key is dB = 4. Compute the public keys and the shared secret.

  6. Sample Solution

    QA = [2]P = (3, 4) (from earlier example).

    QB = [4]P = [2](2P) = [2](3, 4) = (2, 0) (from earlier).

    Shared secret S = [dA]QB = [2](2, 0) = (3, 4).

    Alternatively, S = [dB]QA = [4](3, 4) = (3, 4).

    Shared secret: (3, 4).

  7. Key Size Comparison

    What is the ratio of RSA key size to ECC key size for 128-bit security? (RSA: 3072 bits, ECC: 256 bits)

  8. Sample Solution

    Ratio = 3072 / 256 = 12. ECC keys are 12× smaller than RSA keys for the same security level.

  9. ECDSA Nonce Reuse

    If an attacker obtains two ECDSA signatures (r, s₁) and (r, s₂) with the same ephemeral key k, show how the private key d can be recovered. (Assume hash values h₁ and h₂ are known.)

  10. Sample Solution

    Given s₁ = k⁻¹(h₁ + d·r) mod n and s₂ = k⁻¹(h₂ + d·r) mod n.

    Subtract: s₁ − s₂ = k⁻¹(h₁ − h₂) mod n.

    Thus k = (h₁ − h₂) / (s₁ − s₂) mod n.

    Then d = (s₁·k − h₁) / r mod n.

    This shows how nonce reuse allows recovery of the private key.

Homework

  1. Research: The Elliptic Curve Discrete Logarithm Problem

    Write a 500-word report on the ECDLP. Include:

  2. Sample Answer

    Complete answer would define the ECDLP, describe Pollard's rho (O(√n) complexity) and baby-step giant-step, explain that no subexponential algorithm is known for well-chosen curves, and discuss how curves with anomalies, small subgroups, or weak fields are vulnerable.

  3. Compare ECC and RSA Performance

    Research and compare the performance of ECC and RSA in a real-world application. Address:

  4. Sample Answer

    Complete answer would include benchmarks showing ECC is faster for key generation and signing, while RSA is often faster for signature verification. ECC consumes less memory and bandwidth. ECC is preferred in constrained environments; RSA is still used in many legacy systems.

  5. Analyze a Real-World ECC Implementation

    Research how ECC is implemented in a specific library (e.g., OpenSSL, libsodium, Bouncy Castle). Write a report addressing:

  6. Sample Answer

    Complete answer would discuss OpenSSL's support for NIST curves, Curve25519, and Ed25519; its use of Montgomery ladder for constant-time scalar multiplication; blinding; and past vulnerabilities like the cache timing attack on ECDSA.

  7. Design an ECDH-Based Protocol

    Design a secure communication protocol using ECDH and a symmetric cipher. Specify:

  8. Sample Answer

    Complete answer would describe a protocol similar to TLS with ECDHE: parties exchange ephemeral public keys, sign them with their long-term keys (certificates), compute the shared secret, derive keys using a KDF, and use a symmetric cipher (e.g., AES-GCM) for encryption.

  9. Mini-Project: Implement ECC Operations

    Implement point addition, point doubling, and scalar multiplication for a small elliptic curve over GF(p) (e.g., p = 17 or 23). Test with sample points. Report on:

  10. Sample Answer

    Complete answer would include source code for the field operations, point addition, and double-and-add scalar multiplication. It would show test results verifying correctness and discuss the complexity of handling modular arithmetic and edge cases (e.g., point at infinity).

Summary

This tutorial has provided a comprehensive examination of Elliptic Curve Cryptography (ECC). We began by defining elliptic curves and their algebraic structure, extending the concept to finite fields to make cryptography practical. We explored the group operation—point addition and point doubling—and the core operation of scalar multiplication, which is the workhorse of ECC protocols.

We introduced the Elliptic Curve Discrete Logarithm Problem (ECDLP), the foundation of ECC security, and explained why it is believed to be harder than the discrete logarithm problem in finite fields, enabling smaller key sizes. We covered the three main ECC protocols:

We compared ECC with RSA and classical DH, demonstrating the significant efficiency advantages of ECC in terms of key sizes, performance, and resource consumption. We reviewed standardized curves, including NIST P-256, Curve25519, Ed25519, and secp256k1, and discussed their applications in TLS, SSH, Bitcoin, and other protocols.

We discussed implementation considerations, emphasizing point validation, constant-time operations, secure randomness, and side-channel resistance. The case studies illustrated the real-world impact of ECC vulnerabilities (e.g., the PS3 hack) and the importance of careful implementation.

With this knowledge, you are now equipped to understand, implement, and evaluate ECC in cryptographic systems, and to appreciate its advantages over traditional public-key algorithms.

Connection to the Next Tutorial

In Tutorial 2.15: Digital Signatures and Public Key Infrastructure, we will explore digital signatures in depth, including RSA signatures, DSA, and ECDSA, and we will discuss how Public-Key Infrastructure (PKI) binds public keys to identities, enabling secure authentication on the Internet.