Elliptic curve cryptography
Elliptic curve cryptography (ECC): group law on elliptic curves over finite fields, scalar multiplication, ECDLP hardness and parameters used in blockchain (e.g. secp256k1); how to add/double points and compute k·P (double-and-add).
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Elliptic curve cryptography (ECC) is widely used by engineers to build compact public-key systems in blockchains: private keys are scalars and public keys are curve points, signatures and key agreement rely on the hardness of the elliptic curve discrete logarithm problem (ECDLP). ECC gives similar security to RSA with much smaller keys — important for storage, bandwidth and performance in blockchain nodes and wallets.
Key ideas
Definition: E: y^2 = x^3 + a·x + b, where a,b ∈ K and the discriminant Δ ≠ 0. The discriminant condition ensures the curve has no singular points (no cusps or self-intersections).
Exact discriminant (for the short Weierstrass form): Δ = -16·(4·a^3 + 27·b^2). The curve is non-singular iff Δ ≠ 0. These formulas assume char(K) ≠ 2,3 (e.g., prime fields F_p with p > 3 used in blockchains).
Point at infinity (O) — the identity element for the group law on E. For any point P on E, P + O = P.
Group law (geometric description) — the set E(K) forms an abelian group with addition '+' defined as:
- To add distinct points P and Q: draw the straight line through P and Q. This line meets the cubic curve in a third point R'. Reflect R' across the x-axis to get R = P + Q.
- To double P (P = Q): draw the tangent line at P, find its second intersection R' with the curve, reflect to obtain 2P.
- The point at infinity O plays the role of identity.
Diagram to draw for an exam: Cartesian axes, draw a typical elliptic curve (cubic-shaped), mark points P and Q on the curve, draw the secant line meeting the curve at R', then a horizontal reflection to R; label P, Q, R' and R and indicate O at 'infinity' (write O on top). For doubling, draw tangent at P meeting curve at R' and reflect.
Algebraic formulas (prime field F_p)
- If P = (x1,y1), Q = (x2,y2) and P ≠ ±Q, slope m = (y2 - y1)·(x2 - x1)^{-1} mod p (inverse exists if x2 ≠ x1).
- x3 = m^2 - x1 - x2 (mod p)
- y3 = m·(x1 - x3) - y1 (mod p)
- For doubling (P = Q): m = (3·x1^2 + a)·(2·y1)^{-1} (mod p). If y1 ≡ 0 (mod p), then 2P = O.
- If P = (x1,y1) and Q = -P = (x1,-y1), then P + Q = O.
These rules make E(F_p) an abelian group law written additively.
Scalar multiplication — for integer k and point P define k·P = P + P + ... + P (k times). Efficient computation uses the double-and-add (binary) algorithm with O(log k) point operations.
Order of a point — the smallest positive integer n such that n·P = O. A point with large prime order is chosen as base point G.
Domain parameters — a standard set for a curve over F_p used in systems: (p, a, b, G, n, h), where G is the base point, n is the order of G, and h is the cofactor (h = #E(F_p) / n). By Hasse's theorem, #E(F_p) = p + 1 - t with |t| ≤ 2√p. Example used in many blockchains: secp256k1 (curve used by Bitcoin) has a = 0, b = 7 over prime p = 2^256 - 2^32 - 977 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F, base point G = (xG, yG) with xG = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798 and yG = 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8, order n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141, and cofactor h = 1.
Security basis — the ECDLP: given P and Q = k·P, find k. The best-known generic algorithm for arbitrary curves is Pollard's rho with time ≈ O(√n) group operations. This is why n (order of G) must be large (e.g. ~2^256 for 128-bit security). In practice, n should be prime and the cofactor h small (ideally h = 1) to avoid small-subgroup attacks.
Formulas
y^2 = x^3 + a·x + b — curve equation over field K; a,b ∈ K. Units: unitless (field elements). Applies to short Weierstrass curves.
Δ = -16·(4·a^3 + 27·b^2) — discriminant; non-zero ensures non-singular curve. Units: unitless. Applies to short Weierstrass form.
m = (y2 - y1)·(x2 - x1)^{-1} (mod p) — slope for P ≠ Q; (x2 - x1)^{-1} is modular inverse. Symbols: x1,x2,y1,y2 ∈ F_p. Units: unitless.
x3 = m^2 - x1 - x2 (mod p) — x-coordinate of P + Q. Symbols as above.
y3 = m·(x1 - x3) - y1 (mod p) — y-coordinate of P + Q.
m = (3·x1^2 + a)·(2·y1)^{-1} (mod p) — slope for doubling P = Q.
k·P = P + P + ... + P (k times) — scalar multiplication; use double-and-add. Symbols: integer k ≥ 0, P ∈ E(F_p).
n·G = O — order n of base point G. Units: unitless.
Complexity statement (verbal): Pollard's rho attack runs in expected time O(√n) group operations on curve of order n (useful for security parameter selection).
Notes: modular inverse a^{-1} mod p is computed by the extended Euclidean algorithm. All arithmetic in these formulas is modulo p when working over F_p. Implementations often use projective/Jacobian coordinates to avoid costly field inversions in affine formulas.
Worked examples
Example 1 — point addition and doubling on a small prime field (full algebraic steps and checks):
Given curve E: y^2 = x^3 + 2·x + 2 over F_17 (so p = 17, a = 2, b = 2). Verify first that discriminant Δ = -16·(4·2^3 + 27·2^2) ≠ 0 (compute if required in exam).
Let P = (5,1) and Q = (6,3).
Step 1: check points lie on curve:
- For x=5: RHS = 5^3 + 2·5 + 2 = 125 + 10 + 2 = 137 ≡ 1 (mod 17). y^2 = 1^2 = 1. Okay.
- For x=6: RHS = 6^3 + 2·6 + 2 = 216 + 12 + 2 = 230 ≡ 9 (mod 17). y^2 = 3^2 = 9. Okay.
Compute R = P + Q:
- Slope m = (y2 - y1)·(x2 - x1)^{-1} mod 17 = (3 - 1)·(6 - 5)^{-1} = 2·1^{-1} = 2.
- x3 = m^2 - x1 - x2 = 2^2 - 5 - 6 = 4 - 11 = -7 ≡ 10 (mod 17).
- y3 = m·(x1 - x3) - y1 = 2·(5 - 10) - 1 = 2·(-5) - 1 = -10 - 1 = -11 ≡ 6 (mod 17).
So P + Q = (10,6). Verify: RHS at x=10 is 10^3 + 2·10 + 2 = 1000 + 20 + 2 = 1022 ≡ 2 (mod 17). y^2 = 6^2 = 36 ≡ 2. OK.
Compute 2P (doubling P):
- m = (3·x1^2 + a)·(2·y1)^{-1} mod 17 = (3·25 + 2)·(2·1)^{-1} = (75 + 2)·2^{-1} = 77·2^{-1}.
- 77 ≡ 9 (mod 17); inverse of 2 mod 17 is 9 (since 2·9 = 18 ≡ 1). So m = 9·9 = 81 ≡ 13.
- x3 = m^2 - 2·x1 = 13^2 - 10 = 169 - 10 = 159 ≡ 6 (mod 17).
- y3 = m·(x1 - x3) - y1 = 13·(5 - 6) - 1 = 13·(-1) - 1 = -13 -1 = -14 ≡ 3 (mod 17).
Thus 2P = (6,3) which equals Q (consistent with earlier). This shows 3P = P + 2P = (10,6).
Example 2 — small ECDLP demonstration (expository):
On the same curve, given P = (5,1) and Q = (10,6) find k such that Q = k·P.
Compute multiples quickly (we already computed):
- P = (5,1)
- 2P = (6,3)
- 3P = (10,6)
Hence Q = 3·P so k = 3. For big curves (e.g. secp256k1) this search is infeasible; security relies on that hardness.
Optional extra (trace of double-and-add for k=7): show binary decomposition 7 = 111_2 and compute doubles and adds using the points from Example 1 to arrive at 7P = (0,6) (students should show intermediate doubles and adds, carrying mod p arithmetic).
Common mistakes
- Confusing addition on the curve with coordinate-wise addition (remember it is a geometric/group operation, not (x1+x2,y1+y2)).
- Not checking the discriminant (choosing a,b making curve singular).
- Confusing point sign: Q = -P has same x and negated y (y → -y mod p) and P + (-P) = O.
- Misreading additive notation: private key k is scalar, public key is point k·G (additive notation), not multiplication of coordinates.
- When implementing, not validating input points (e.g. don't assume an untrusted public key lies on curve: always check it). Also ensure cofactor-related checks (e.g., verify [n]Q = O or perform cofactor clearing) when h > 1.
For your exam
Typical question types:
- Definitions: define elliptic curve, point at infinity, discriminant, ECDLP, domain parameters.
- Short notes: explain geometric group law, explain why discriminant must be non-zero, explain domain parameters (p,a,b,G,n,h).
- Derivations: derive algebraic formulas for point addition and doubling from the geometric process (show solving for intersection of line and cubic and the reflection step).
- Numericals: compute P + Q or k·P on a small curve over F_p (show all modular steps). Exams expect modular inverse steps shown.
- Programs / algorithms: write or trace double-and-add for scalar multiplication; explain time complexity O(log k) point operations. Also mention constant-time, side-channel-safe scalar multiplication (e.g., Montgomery ladder).
- Diagrams: draw curve, P,Q, secant/tangent, intersection R' and reflected result R.
What full-marks answers include:
- Clear definitions with required conditions (e.g. Δ ≠ 0); correct algebraic formulas; all modular arithmetic steps shown and checked; when deriving formulas, show the polynomial for line·curve intersection and why reflection (negate y) is needed; for numericals show verification that resulting point lies on curve.
Quick check
- State the short Weierstrass equation used in many ECC systems.
- Give the algebraic formula for the slope m when adding two distinct points P = (x1,y1) and Q = (x2,y2) over F_p.
- On curve E: y^2 = x^3 + 2x + 2 over F_17, if P = (5,1), what is 2P?
Answers: 1) y^2 = x^3 + a·x + b. 2) m = (y2 - y1)·(x2 - x1)^{-1} (mod p). 3) 2P = (6,3).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?