liveBook · Manning

Diffie–Hellman key exchange

As explained in Real-World Cryptography

Diffie-Hellman key exchange is a public-key protocol that lets parties establish a shared secret over an insecure channel.

Diffie–Hellman (DH) lets two parties establish the same secret across an insecure channel without sending that secret directly. They can then use it as a key for symmetric encryption. section 1.4.1

A basic DH exchange follows these steps:

  • Agree on public parameters: a large prime p and a generator g. section 5.2.2
  • Generate a random private value: Alice chooses x and Bob chooses y. section 1.4.1 section 5.2.2
  • Derive and exchange public values: Alice sends gˣ mod p and Bob sends gʸ mod p. section 5.2.2
  • Combine the received public value with the local private value; both sides arrive at the same shared secret. section 1.4.1

DH relies on the discrete logarithm problem: deriving a public value is efficient, while recovering the private value from that public value is intended to be impractical with sufficiently large parameters. section 5.2.2

The shape analogy

Alice and Bob agree on a square, privately choose a triangle and a star, and combine each secret with the square to create public shapes. Each then combines the other public shape with their own private shape, producing the same star–square–triangle secret. Observers see only the public shapes. section 1.4.1

Unauthenticated DH protects the shared secret from passive observation but does not stop an active attacker from impersonating a participant. Authentication, often involving public keys or signatures, is needed for that threat. section 5.5

How Real-World Cryptography covers it

How deep it goes
Explains the exchange, modular key formulas, discrete-logarithm basis, standards, and authentication limits.
Examples
Uses Alice-and-Bob shape combinations and modular arithmetic with generator 3 and prime 5.
What it assumes
Builds private keys, public keys, and shared secrets from a simple analogy before introducing modular arithmetic.
What you can do after
Operate/configure DH using suitable parameters, validate received public keys, and distinguish passive from active MITM risks.
How it connects
Connects public-key cryptography with symmetric encryption, discrete logarithms, authenticated key exchange, digital signatures, and ECDH.

Also explained in

Compare how 4 books explain Diffie–Hellman key exchange →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Real-World Cryptography. The section links point to the parts of the book it draws on.