ECDH (Elliptic Curve Diffie-Hellman) — Textbook Construction
- •
What it is
- •
The elliptic-curve analogue of ordinary Diffie-Hellman: instead of modular exponentiation in , both parties use scalar multiplication of a fixed base point on an agreed elliptic curve. Alice picks a secret integer and publishes ; Bob does the same with and ; both then compute the same shared point , by associativity of scalar multiplication — exactly mirroring in ordinary DH, just written additively. As with ordinary DH, the raw shared value (here, the -coordinate of ) isn't used directly as a key; it's hashed (commonly SHA-1 or SHA-256) and truncated to derive a symmetric key. Security rests on the elliptic curve discrete logarithm problem (ECDLP) — recovering from and — which, for a well-chosen curve, has no known algorithm faster than roughly operations where is the order of the subgroup generated by (hence why real-world curves use a generator of large prime order).
- •
- •
When to apply
- •
The starting point for any ECC-flavored key-exchange challenge — deviations from this baseline (weak curves, bad point validation, small subgroups) are what specific ECC attacks target.
- •
- •
Symbols and assumptions
- •
is a curve point of order ; are private scalars modulo . Public points are , . Coordinates are elements of the curve’s field, whose modulus need not equal .
- •
- •
Math — step by step
- •
- Alice computes . Bob computes . Associativity of the group law makes their shared points identical.
- •
- Implement point operations with field arithmetic and scalar operations modulo the order of . Validate received points and follow the protocol’s subgroup rules.
- •
- Protocols commonly feed the shared x-coordinate, suitably encoded, into a KDF. Sharing an x-coordinate loses the sign of the point but can still suffice for deriving the same key.
- •
- •
Worked example
- •
Use the curve and from Elliptic Curves (Group Law Basics). Choose . Then and .
- •
Alice doubles : . This gives , .
- •
Bob obtains as well. Check membership: . Shared x-coordinate: 16.
- •
- •
Python
- •
S = nB * QA # scalar multiplication (Sage's `*` operator on an EllipticCurve point) key_material = str(int(S[0])).encode() key = hashlib.sha1(key_material).digest()[:16]
- •
- •
SageMath
- •
E = EllipticCurve(GF(p), [a, b]) QA = E(xA, yA) S = nB * QA
- •
- •
- •
Cards
- •
What plays the role of g^ab in elliptic-curve Diffie-Hellman?
- •
The shared point S = [n_A][n_B]G = [n_B][n_A]G, computed via scalar multiplication instead of modular exponentiation.
- •
- •
Why is it important that the generator point G have large prime order?
- •
It keeps the ECDLP hard within the subgroup actually used — a small or composite-order subgroup would make the discrete log tractable (analogous to why safe primes matter for ordinary DH).
- •
- •