Diffie-Hellman Key Exchange
What You'll Learn
You'll learn how two parties can establish a shared secret key over an insecure channel without ever transmitting the secret itself.
The Core Problem and Solution
Imagine Alice and Bob want to communicate securely using symmetric cryptography (like AES), but they've never met before and can only talk over a channel that Eve can intercept. How do they agree on a shared secret key without Eve discovering it?
Diffie-Hellman solves this by letting Alice and Bob each contribute their own private information, perform mathematical operations using public information, and arrive at the same shared secret—without ever sending that secret over the channel.
How It Works (Simplified)
The protocol uses modular arithmetic and the properties of exponentiation:
- Public parameters: Alice and Bob agree on a large prime number
pand a baseg(these can be public) - Private keys: Alice picks a secret number
a, Bob picks secret numberb - Public exchange:
- Alice computes
A = g^a mod pand sendsAto Bob - Bob computes
B = g^b mod pand sendsBto Alice
- Alice computes
- Shared secret:
- Alice computes
s = B^a mod p - Bob computes
s = A^b mod p - Both arrive at the same value:
s = g^(ab) mod p
- Alice computes
Eve sees g, p, A, and B, but computing a or b from these values (the discrete logarithm problem) is computationally infeasible with proper key sizes.
Paint Mixing Analogy
Think of mixing paint colors: both parties start with a public color (yellow). Each adds their secret color privately. They exchange their mixtures. Each adds their original secret to the received mixture. Both end up with the same final color, but an observer can't "unmix" the paint to discover the secrets.
Key Takeaway: Diffie-Hellman enables two parties to establish a shared secret over an insecure channel by combining public exchanges with private values, relying on the hardness of the discrete logarithm problem for security.