Diffie-Hellman Key Exchange Animation
Step through Diffie-Hellman key agreement and see why public values are safe, private exponents matter, and authentication is still required
Diffie-Hellman Key Exchange Animation
Watch Alice and Bob agree on the same shared secret while Eve sees only public values. The toy numbers are intentionally small so the math is inspectable; the security notes explain what changes in real TLS, DTLS, and IoT systems.
Toy finite-field Diffie-Hellman
Small p and g values make the arithmetic visible. They are not secure; production systems use much larger finite-field groups or elliptic-curve DH.
Key exchange trace
Public parameters are safe to show. The private exponents must stay private.
Security score
Current calculation
Alice and Bob agree on public parameters p and g.
p = 23, g = 5What Eve sees
Eve can read p and g, but no private exponent has been sent.
Accuracy warning
This uses small toy numbers for teaching. Production Diffie-Hellman uses approved large groups or elliptic curves.
Exchange Controls
Choose a parameter set, choose Eve's behavior, then step through the exchange. The private exponent buttons keep the numbers inspectable.
Diffie-Hellman Quick Reference
Alice and Bob can publish p and g. Security depends on using a strong group, not hiding p and g.
Alice keeps a secret a; Bob keeps b. The private exponents must be random and large enough for the group.
A = g^a mod p and B = g^b mod p can travel over the network. Reversing them requires solving a discrete log.
Alice computes B^a mod p. Bob computes A^b mod p. The values match because g^(ab) mod p equals g^(ba) mod p.
Security Pitfalls
Basic DH resists passive eavesdropping, but a man-in-the-middle can replace public values unless the exchange is authenticated.
Small primes make the math readable but are trivially brute forced. Production finite-field groups are thousands of bits.
Ephemeral DH uses fresh secrets per session. That supports forward secrecy when authentication and key derivation are correct.
The raw shared secret should feed a key derivation function. Protocols derive encryption, integrity, and IV material separately.
Technical Accuracy Notes
RFC 3526 defines widely used finite-field MODP Diffie-Hellman groups including 2048-bit group 14 and larger groups.
RFC 8446 uses ephemeral (EC)DHE key exchange with authentication and a key schedule rather than raw DH alone.
RFC 7748 defines Curve25519 and Curve448 functions used for modern elliptic-curve Diffie-Hellman.
RFC 5869 defines HKDF, a common extract-and-expand KDF used in modern protocols.
Practice Prompts
Use Alice +1 or Bob +1. Which public value changes, and why does the final shared secret still match?
Select Passive Eve. List exactly which values Eve can see and which value she is missing.
Select MITM Eve. Why can Eve create two secrets unless Alice and Bob authenticate the public values?
Move to KDF. Explain why DH does not encrypt sensor data by itself.