Full name: Elliptic-curve Diffie–Hellman key agreement.
Definition
ECDH is Diffie–Hellman key agreement §19.1.4 on an elliptic curve: two parties exchange public points and compute the same secret. Commonly the curve is all pairs of non-negative whole numbers below a prime for which and , for fixed and , leave equal remainders on division by , plus one extra point acting as zero. A fixed rule adds two points to give a third. A private key is a number ; its public key is the sum of copies of a published point .
The idea
The classic form of Diffie–Hellman key agreement, published by Whitfield Diffie and Martin Hellman in 1976 [433], computes with whole numbers modulo a prime, that is, reduced to their remainders after division by the prime. It needs very large numbers, because attacks exist that use the structure of those numbers: NIST rates a 3072-bit prime at a security strength of 128 bits, meaning that the best known attack needs about steps. No comparable attack is known against the standardized elliptic curves, so such a curve over a 256-bit prime reaches the same strength. A public value shrinks from 384 bytes to 64 bytes. Bluetooth Low Energy §7.1, for example, uses the curve named P-256 in its pairing method LE Secure Connections §7.21; pairing is the procedure by which two devices establish shared keys.
The rule for adding points comes from a drawing of the curve over the real numbers. A straight line through two points of the curve, unless it is vertical, meets the curve in a third point, where a point at which the line touches the curve counts twice. Reflect the third point in the x-axis, and the result is defined to be the sum of the two points. To add a point to itself, use the tangent line at the point. A vertical line joins a point to its mirror image, and the sum of those two is defined to be the extra point, called the point at infinity and written . It behaves like zero: adding it changes nothing. With numbers modulo there is no drawing, only the formulas that the drawing leads to, evaluated modulo .
Repeated addition plays the part that repeated multiplication plays in the classic form. The sum of copies of is written , and computing it is called scalar multiplication. It does not multiply the coordinates of by . Computing from is fast. Recovering from is the elliptic-curve form of the discrete logarithm problem §19.1.3 and is believed to be infeasible on a standardized curve such as P-256.
How it works
Modulo means that every result is replaced by its remainder after division by ; the whole numbers 0 to with this arithmetic form a finite field §19.1.2. The public parameters name a curve and a starting point:
: the prime that all coordinate arithmetic is reduced by;
and : the two constants in the equation , chosen so that is not a multiple of (otherwise the curve has a point at which the tangent line is not defined, and the rule for adding a point to itself fails there);
: the base point, one published point of the curve;
: the order of , which means that and no smaller positive multiple of is , so that the multiples of form a cyclic subgroup §19.1.1 of points; is a prime;
: the cofactor, the number of points on the curve, counting , divided by .
To add and , first compute a slope , then the sum : Every operation is modulo , and each division is a multiplication by a modular inverse. Two cases come before these formulas. If the two points have the same and opposite , which includes a point with added to itself, the sum is . And adding to a point leaves the point unchanged.
The exchange between two parties, here called Alice and Bob, then has six steps.
Alice picks a private key at random from 1 to , computes the public key and sends it.
Bob picks the same way and sends .
Each validates the public key received, as described under the question below.
Alice computes the point . Bob computes . Both are the point .
If that point is , the exchange is abandoned. Otherwise its x-coordinate is the shared secret .
Each feeds into a key derivation function §5.20 (KDF), an algorithm §14.1 that turns a secret value into keys, to obtain the session keys, the keys that protect the messages of this one connection, and then erases .
NIST Special Publication 800-56A specifies step 4 with one more factor: each party computes , where is the cofactor. On a curve with , such as P-256, the factor changes nothing.
Worked example
The curve below is far too small to be secure. Take , and , so that the equation is modulo 17, and take . The constants meet the condition on and : , which is not a multiple of 17. is on the curve: , and . The curve has 18 points with coordinates, and with it has 19 points. Since 19 is prime, and .
Doubling . The slope is . Modulo 17, 77 is , and the inverse of 2 is 9, because . So , which is 13. Then , which is 6, and , which is . So .
Adding and . The slope is . Then , which is , and , which is . So . Continuing in the same way gives every multiple of :
| 1 | 7 | 13 | |||
| 2 | 8 | 14 | |||
| 3 | 9 | 15 | |||
| 4 | 10 | 16 | |||
| 5 | 11 | 17 | |||
| 6 | 12 | 18 |
The next multiple, , is .
The exchange. Alice picks and sends . Bob picks and sends . Alice computes , and Bob computes . Since and , . The shared secret is the x-coordinate, . The scalar wrapped round at 19, the order of , and not at 17, the prime of the coordinates.
An invalid public key. An attacker sends Bob the pair . It is not on the curve: , while the right-hand side is 1, as computed above. It lies on a different curve, the one with 1 in place of the constant , because . The addition formulas never use , so they run without complaint. The pair is its own mirror image, because its is 0, so adding it to itself gives : it behaves as a point of order 2. The true curve has no such point, since a group of 19 elements allows only the orders 1 and 19. Bob’s result is , because 7 is odd; for an even private key it would be . So Bob’s shared secret is the x-coordinate 5 unless Bob’s private key is even. The attacker knows the secret that Bob will use without knowing Bob’s private key, and learns whether that key is even. Repeating the trick with pairs of other small orders yields further information about a private key that is used more than once.
Stated precisely
Correctness: for all whole numbers and , This holds in every group and needs no assumption.
Secrecy against an attacker who only observes and rests on two named conditions. The computational Diffie–Hellman problem, to compute from and , is hard in the subgroup generated by . And the private keys are uniformly random in the range 1 to and stay secret. Against an attacker who can also send a public key of its own making, a third condition is needed, so that the result reveals nothing about the receiver’s private key: each public key received has been validated.
NIST Special Publication 800-56A calls the checking of a received public key public-key validation. It defines full validation of a public key as four conditions, explained under the question below: Here means that is a multiple of . Partial validation is the first three. When , the fourth condition follows from the first three: the curve then has exactly points, is prime, and so every point other than has order .
Limits and common mistakes
Validation shows that a public key is a usable point. It does not show who sent it. Without authentication §1.6, ECDH is open to the same man-in-the-middle attack §7.26 as the classic form: an attacker between the two parties runs a separate exchange with each.
The width of the coordinates is not the security strength. A 256-bit curve gives a strength of about 128 bits, because the best known attack needs about steps.
Scalar multiplication must not reveal through its running time or its power use. A loop that does extra work for every 1 bit of can leak the key through a side channel §1.29.
The checks depend on the curve. The function X25519, defined in RFC 7748 [434], uses a curve with a different equation, sends one coordinate only and is specified to accept every 32-byte string as a public value. Its curve has cofactor 8, and an input of small order produces a shared secret of all zero bytes. Version 1.3 of Transport Layer Security (TLS), the Internet protocol that protects connections between clients and servers, requires implementations to detect that value and abort.
ECDH gives no protection against a large quantum computer. NIST warns that such machines will threaten Diffie–Hellman key agreement in both its classic form and its elliptic-curve form, and that both may then have to be replaced.
Questions answered
What must be checked about an input public key?
A received public key must be shown to be a point in the agreed encoding, other than the point at infinity, that lies on the agreed curve and in the agreed subgroup, before it is combined with the private key. In ECDH (elliptic-curve Diffie–Hellman key agreement) a public key is a point that should lie on an agreed curve modulo a prime , and the point at infinity is the extra point of the curve that acts as zero. NIST Special Publication 800-56A lists four checks, for a curve whose base point has prime order .
Not the identity. is not the point at infinity. Otherwise the shared point is the point at infinity whatever the private key is.
Coordinates in range. and are whole numbers from 0 to , in the agreed encoding and length.
On the curve. and leave the same remainder on division by . The addition formulas do not use , so a pair that fails this check is processed as a point of some other curve, where it can have a small order and leak part of the private key.
In the subgroup. The sum of copies of is the point at infinity. On a curve with cofactor 1, such as P-256, this follows from the first three checks; the cofactor is the number of points on the curve divided by . On a curve with a larger cofactor, the protocol either makes this check, or multiplies by the cofactor and rejects a result that is the point at infinity.
After the computation, the shared point must not be the point at infinity. For the key agreement function X25519, which uses a curve of a different form, the corresponding check is that the shared secret is not all zero bytes. The exact list belongs to the curve and the protocol. The Bluetooth specification, for example, requires every device to check that a received public key satisfies the equation of the curve P-256.
These checks concern arithmetic only. A public key that passes all of them can still come from an attacker, so the exchange must also be authenticated.
Related entries: Group, cyclic subgroup, generator, and order (§19.1.1), Authenticated key exchange and transcript binding (§19.1.6), LE Secure Connections (§7.21), Finite field and modular inverse (§19.1.2), Discrete logarithm and the Diffie–Hellman problem (§19.1.3), Diffie–Hellman key agreement (§19.1.4). Further reading: [18, 147, 152, 433, 434].