Intermediate Topic 21 of 51 Security & Cryptography
Diffie-Hellman Key Exchange
Agreeing on a shared secret over an open channel.
How it works
Diffie-Hellman lets two parties establish a shared secret over a public channel without having met. Each picks a private value, computes a public value from a common generator and prime modulus or elliptic-curve base point, and exchanges public values; each then combines their private value with the other's public value to arrive at the same secret. An eavesdropper sees only the public values and faces the discrete logarithm problem. Ephemeral variants provide forward secrecy.
Step-by-step walkthrough
- They agree on public numbers g and p.
- Alice computes A from her secret a and sends A.
- Bob computes B from his secret b and sends B.
- Alice computes B to the power a, Bob computes A to the power b.
- Both get the same shared secret and an eavesdropper cannot easily compute it.
Where it is used
TLS, SSH, IPsec, Signal and WireGuard use Diffie-Hellman, usually in elliptic-curve form such as X25519, to derive session keys.
Common pitfall
Unauthenticated exchange is vulnerable to man-in-the-middle attacks, so it must be combined with signatures or certificates. Weak or reused parameters, small groups and invalid public values enable attacks, as in Logjam. Always use standardized groups or curves, validate received points and derive keys with a key derivation function.
Where it fits in the course
Diffie-Hellman Key Exchange is topic 21 of 51 in Security & Cryptography, rated Intermediate. It follows Public Key Infrastructure. The next topic is Block Cipher Modes.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Security & Cryptography quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Security & Cryptography quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Diffie-Hellman Key Exchange?
Where do people use Diffie-Hellman Key Exchange?
What is the most common mistake with Diffie-Hellman Key Exchange?
What should I learn before this topic?
How can I practice it?
Is Diffie-Hellman Key Exchange hard to learn?
How long does it take to learn Diffie-Hellman Key Exchange?
Which topics are related to Diffie-Hellman Key Exchange?
What should I study after Diffie-Hellman Key Exchange?
Related topics
- Public Key Infrastructure (Security & Cryptography)
- Block Cipher Modes (Security & Cryptography)
- Digital Signatures (Security & Cryptography)
- Message Authentication Codes (Security & Cryptography)