Public Parameters
Alice and Bob first agree on two public numbers:
- p: a large prime number
- g: a generator (a number with special properties)
Everyone can know these. They’re not secret.
Let’s Use Real Numbers
| Parameter | Value |
|---|---|
| Prime | 23 |
| Generator | 5 |
Alice’s Side
Step 1: Alice picks a secret number.
This is her private key. She never shares it.
Step 2: Alice computes her public value.
She sends A = 8 to Bob. Everyone can see this.
Bob’s Side
Step 1: Bob picks a secret number.
This is his private key. He never shares it.
Step 2: Bob computes his public value.
He sends B = 19 to Alice. Everyone can see this.
Creating the Shared Secret
Now comes the magic.
Alice computes:
Bob computes:
Same answer! Both get K = 2.
This is their shared secret. They can now use it as a key for symmetric encryption.
Why Do They Get the Same Answer?
Alice computes:
Bob computes:
Since , they get the same result.
What Eve (the Attacker) Sees
Eve is watching the whole conversation. She knows:
| Value | Known to Eve? |
|---|---|
| Yes (public) | |
| Yes (public) | |
| Yes (sent publicly) | |
| Yes (sent publicly) | |
| No (Alice’s secret) | |
| No (Bob’s secret) | |
| No (shared secret) |
Why Can’t Eve Calculate K?
To find K, Eve would need either or .
She knows and that .
So she needs to find where .
This is the Discrete Logarithm Problem.
For small numbers like 23, she could just try all possibilities. But for a 600-digit prime? There’s no known efficient algorithm.
Diffie-Hellman’s security rests on the difficulty of the discrete logarithm problem.