Elliptic Curves
Table of Contents
A class of algebraic curves defined by equations of the form \(y^2 = x^3 + Ax + B\) over a field. In cryptography, the key property is the discrete logarithm problem — computing \(k\) from \(G\) and \(kG\) is computationally infeasible for large parameters, while computing \(kG\) from \(G\) and \(k\) is efficient. This asymmetry underlies most modern public-key cryptography.
Note: "elliptic" is not the same as "ellipse" — the name is historical, not geometric.
Related: Cryptography Hashing PKI TLS / SSL
The Curve
The standard short Weierstrass form over a prime field \(\mathbb{F}_p\):
\[y^2 \equiv x^3 + Ax + B \pmod{p}\]
For the curve to be valid (non-singular): \(4A^3 + 27B^2 \neq 0\)
The curve consists of all integer pairs \((x, y)\) satisfying the equation modulo \(p\), plus a special "point at infinity" \(\mathcal{O}\) that serves as the identity element.
Point Addition
The group operation on an elliptic curve is called point addition. Given points \(P\) and \(Q\) on the curve:
Geometric interpretation (over the reals)
- Draw a line through \(P\) and \(Q\)
- The line intersects the curve at a third point \(R'\)
- Reflect \(R'\) across the x-axis — the result is \(P + Q\)
For \(P + P\) (point doubling): use the tangent line at \(P\) instead of a line through two points.
Identity element
\(\mathcal{O}\) is the point at infinity. For any point \(P\): \[P + \mathcal{O} = P\]
Every point \(P = (x, y)\) has an inverse \(-P = (x, -y)\): \[P + (-P) = \mathcal{O}\]
Scalar Multiplication
The cryptographically critical operation. Given a point \(G\) and a scalar \(k\):
\[kG = \underbrace{G + G + \cdots + G}_{k \text{ times}}\]
Computed efficiently using double-and-add (analogous to square-and-multiply):
def scalar_multiply(k, G): result = INFINITY # identity element addend = G while k: if k & 1: result = point_add(result, addend) addend = point_add(addend, addend) # double k >>= 1 return result
The Discrete Logarithm Problem
Given \(G\) and \(P = kG\), find \(k\).
- Easy: Computing \(kG\) from \(G\) and \(k\) — \(O(\log k)\) operations via double-and-add
- Hard: Computing \(k\) from \(G\) and \(P\) — no known sub-exponential algorithm for well-chosen curves and large parameters
This one-way asymmetry is the foundation of ECC security. With 256-bit curves, the best known attacks require \(2^{128}\) operations — computationally infeasible.
Domain Parameters
A curve is defined by a set of domain parameters:
| Parameter | Meaning |
|---|---|
| \(p\) | Prime field modulus |
| \(A, B\) | Curve coefficients |
| \(G\) | Generator point (base point) — a specific point on the curve |
| \(n\) | Order of \(G\) — smallest integer such that \(nG = \mathcal{O}\) |
| \(h\) | Cofactor — \(h = \lvert E(\mathbb{F}_p) \rvert / n\) (ideally 1) |
Named Curves in Practice
These are standardised curves with pre-agreed domain parameters:
| Curve | Field size | Usage |
|---|---|---|
| P-256 (secp256r1) | 256-bit | TLS, ECDSA, widely supported |
| P-384 (secp384r1) | 384-bit | Higher security TLS, government |
| P-521 (secp521r1) | 521-bit | Maximum NIST security level |
| Curve25519 | 255-bit | ECDH key exchange (X25519), modern TLS |
| Ed25519 | 255-bit | EdDSA signatures — SSH keys, modern crypto |
| secp256k1 | 256-bit | Bitcoin — Koblitz curve, different from P-256 |
Curve25519 and Ed25519 are designed for resistance to implementation attacks and are preferred in modern protocols over NIST curves.
Cryptographic Schemes Using ECC
ECDH — Elliptic Curve Diffie-Hellman
Key agreement: two parties derive a shared secret without transmitting it.
Alice: private key a, public key A = aG Bob: private key b, public key B = bG Shared secret: aB = a(bG) = ab·G = b(aG) = bA Alice computes: aB Bob computes: bA Both arrive at the same point without knowing each other's private keys.
ECDSA — Elliptic Curve Digital Signature Algorithm
Sign data with a private key; verify with the public key. Used in TLS certificates, code signing, JWT (ES256).
EdDSA — Edwards-curve Digital Signature Algorithm
Signature scheme over twisted Edwards curves (Ed25519). Used in SSH keys, Signal protocol, age encryption.
Security Relevance
# Inspect a TLS certificate's curve openssl s_client -connect target.com:443 | openssl x509 -text | grep -A2 "Public Key" # Check SSH host key type (Ed25519 = elliptic curve) ssh-keygen -l -f /etc/ssh/ssh_host_ed25519_key.pub # Check JWT algorithm header (ES256 = ECDSA with P-256) echo "eyJ..." | base64 -d | python3 -m json.tool # Weak curve usage is a finding — look for: # — secp112r1, secp128r1 (too small) # — Brainpool curves with implementation concerns # — Custom/non-standard curves (red flag)
Tips
- P-256 and Curve25519 are the two most commonly encountered curves in the wild — P-256 in legacy TLS and ECDSA signatures, Curve25519 in modern key exchange
- ECC keys are much shorter than RSA keys for equivalent security: 256-bit ECC ≈ 3072-bit RSA
- The generator point \(G\) is public — the security depends entirely on keeping \(k\) (the private key) secret
- JWT algorithm "none" and weak curve issues in JWT libraries
are known CVEs —
ES256(ECDSA/P-256) is secure when signature verification is properly implemented