← back to cryptography

Key Exchange

Wikipedia · wpDiffie-Hellman key exchange · CC BY-SA 4.0

Diffie-Hellman lets two parties who have never met agree on a shared secret over a public channel. Each picks a private number, publishes a public value, and combines the other's public value with their own private number. Both arrive at the same shared secret. An eavesdropper who sees the public values cannot compute the secret without solving the discrete logarithm problem.

Alice secret: a Bob secret: b computes g^a computes g^b g^a (public) g^b (public) (g^b)^a = g^ab (g^a)^b = g^ab shared secret

Diffie-Hellman with small numbers

Pick a prime p and a generator g of the cyclic group Z*p. Alice picks secret a, publishes A = ga mod p. Bob picks secret b, publishes B = gb mod p. Alice computes Ba mod p. Bob computes Ab mod p. Both get gab mod p. An eavesdropper sees g, p, A, B but not a or b.

Scheme

The discrete logarithm problem

Given g, p, and A = ga mod p, find a. For small p this is easy (try all values). For a 2048-bit prime, no known algorithm solves it efficiently. The best general algorithm (number field sieve) runs in sub-exponential but still impractical time. This hardness assumption is the foundation of DH security.

Scheme

Man-in-the-middle attack

Plain DH is vulnerable to an active attacker (Mallory) who intercepts the exchange. Mallory runs separate DH with Alice and Bob, establishing different shared secrets with each. She decrypts Alice's messages, re-encrypts for Bob, and neither party knows. The fix: authenticated key exchange, where each party proves their identity (via signatures or certificates) alongside the DH exchange.

Scheme
Neighbors

Cross-references

Foundations (Wikipedia)