Background#
In public-key cryptography, public values are shared while private values remain secret. Diffie–Hellman lets two participants, commonly Alice and Bob, agree on a mutual secret through exponentiation in modular arithmetic.
An observer can see the public parameters and both public keys. Deriving a private key from them requires solving the discrete logarithm problem, which is computationally hard for suitably large parameters.
Algorithm overview#
Choose public parameters#
Select a prime \( q \) and a primitive root \( \alpha \), with \( 1 < \alpha < q \).
Pick private keys#
Participant A chooses a private key \( X_a \) and participant B chooses \( X_b \). Neither is ever sent.
Compute public keys#
A computes \( Y_a = \alpha^{X_a} \bmod q \) and B computes \( Y_b = \alpha^{X_b} \bmod q \).
Exchange public keys#
\( Y_a \) and \( Y_b \) cross the insecure channel. An eavesdropper may read them.
Compute the shared secret#
A computes \( K = Y_b^{X_a} \bmod q \) and B computes \( K = Y_a^{X_b} \bmod q \). Both obtain the same result, \( K_a = K_b \).
Why both keys agree#
Exponentiation in \( \mathbb{Z}_q \) respects the usual power rules, so each side reaches the same power of \( \alpha \) by a different route:
Security assumption
Given \( \alpha^x \bmod q \), recovering \( x \) is infeasible in practice for strong parameter sizes. This is the discrete logarithm problem.
Numerical example#
Using \( q = 23 \) and \( \alpha = 5 \):
| Step | Participant A | Participant B |
|---|---|---|
| Private key | \( X_a = 6 \) | \( X_b = 15 \) |
| Public key | \( Y_a = 5^{6} \bmod 23 = 8 \) | \( Y_b = 5^{15} \bmod 23 = 19 \) |
| Shared key | \( K = 19^{6} \bmod 23 = 2 \) | \( K = 8^{15} \bmod 23 = 2 \) |
Both participants derive the same shared secret, \( K = 2 \).
Interpretation
The public values \( q, \alpha, Y_a, Y_b \) alone are not enough to feasibly recover the private keys under standard assumptions.