Diffie-Hellman Key Exchange

Aliases
  • Diffie-Hellman Key Exchange
  • DHKE
Image of Author
September 1, 2023 (last updated August 5, 2025)

https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange

From the wiki page:

Diffie–Hellman (DH) key exchange is a mathematical method of securely generating a symmetric cryptographic key over a public channel

Also notable from the wiki page intro:

DH is one of the earliest practical examples of public key exchange implemented within the field of cryptography. Published in 1976 by Diffie and Hellman, this is the earliest publicly known work that proposed the idea of a private key and a corresponding public key.

Mixing colors analogy

https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange#General_overview

https://cryptobook.nakov.com/key-exchange/diffie-hellman-key-exchange#key-exchange-by-mixing-colors

Mixing colors is a decent analogy, as explained in the cryptobook link above. A and B agree on a color that Z can sniff over the wire, i.e., it's public knowledge. A and B then each choose a private color and mix the public color with their private color. Then they each pass their mixed colors over the wire. Z can see these mixed colors too. This feels like a lot of information, but still Z cannot reverse engineer the unmixed private colors (color doesn't work as well as the math does, so the analogy breaks down a bit, so just trust me on this). Now, after the mixed colors are exchanged, A and B will take these newly exchanged colors and mix in their private color. This creates the same super color on each side. A and B have the same super color and Z cannot generate it. Z has seen the color Pub and the colors Pub+A_priv and Pub+B_priv. The closest Z can get to Pub+A_priv+B_priv is 2Pub+A_priv+B_priv when they mix the shared colors together. But this is not the secret color. The brilliance of this method is the network is completely compromised and it doesn't matter.

With this freshly exchanged key A and B can do whatever they like. Since they now share the same key a common next step is symmetric-key encryption, where the encryption step and decryption step requires the same key. Now they can pass encrypted messages back and forth, etc.

See the discrete logarithm problem for the math backing up the colors analogy.