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

animation
security
cryptography
key-exchange
tls
iot-security
interactive
An interactive Diffie-Hellman key exchange animation with live modular exponentiation, Play/Back/Next/Reset controls, passive and MITM attack modes, KDF notes, technical accuracy notes, quick references, and practice prompts.
Animation Key exchange Discrete log TLS and IoT

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 MODPParameter set
1. ParametersActive phase
2Shared secret
passiveEve mode

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.

Diffie-Hellman key exchange diagram Alice, Eve, and Bob exchange public Diffie-Hellman values while private exponents remain hidden.

Security score

Privacy
70
Auth
20
Work factor
18

Current calculation

Alice and Bob agree on public parameters p and g.

p = 23, g = 5

What 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.

Both sides can compute the same secret from different inputs.
Basic Diffie-Hellman by itself does not authenticate who is on the other side.
Alice privatea = 6
Bob privateb = 15
Public valuesA = 8, B = 19
Derived key noteShared secret should feed a KDF, not be used directly as an AES key.

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
Public parameters

Alice and Bob can publish p and g. Security depends on using a strong group, not hiding p and g.

Private exponents

Alice keeps a secret a; Bob keeps b. The private exponents must be random and large enough for the group.

Public values

A = g^a mod p and B = g^b mod p can travel over the network. Reversing them requires solving a discrete log.

Shared secret

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
No authentication

Basic DH resists passive eavesdropping, but a man-in-the-middle can replace public values unless the exchange is authenticated.

Toy groups

Small primes make the math readable but are trivially brute forced. Production finite-field groups are thousands of bits.

Secret reuse

Ephemeral DH uses fresh secrets per session. That supports forward secrecy when authentication and key derivation are correct.

KDF required

The raw shared secret should feed a key derivation function. Protocols derive encryption, integrity, and IV material separately.

Technical Accuracy Notes
MODP groups

RFC 3526 defines widely used finite-field MODP Diffie-Hellman groups including 2048-bit group 14 and larger groups.

TLS 1.3

RFC 8446 uses ephemeral (EC)DHE key exchange with authentication and a key schedule rather than raw DH alone.

X25519/X448

RFC 7748 defines Curve25519 and Curve448 functions used for modern elliptic-curve Diffie-Hellman.

HKDF

RFC 5869 defines HKDF, a common extract-and-expand KDF used in modern protocols.

Practice Prompts
Change a secret

Use Alice +1 or Bob +1. Which public value changes, and why does the final shared secret still match?

Find Eve's limit

Select Passive Eve. List exactly which values Eve can see and which value she is missing.

Inject MITM

Select MITM Eve. Why can Eve create two secrets unless Alice and Bob authenticate the public values?

Separate DH from encryption

Move to KDF. Explain why DH does not encrypt sensor data by itself.