5.5: Diffie-Helman Key Exchange
( \newcommand{\kernel}{\mathrm{null}\,}\)
About a year before the RSA cryptosystem was invented, Whitfield Diffie and Martin Hellman published New directions in cryptography [DH76], the first full description of a working public key cryptosystem in the open scientific literature.1 They defined in this paper something which has since been named after them:
Definition: Diffie-Hellman Key Exchange
The following protocol is called Diffie-Hellman key exchange [DHKE]:
- Alice and Bob agree upon a large prime
and a primitive root and publish both. - Alice chooses an
satisfying , computes , keeps secret, but publishes . - Bob chooses a
satisfying , computes , keeps secret, and publishes . - Alice gets the public value
and computes . - Bob gets
and computes the same value . - Both Alice and Bob use the shared secret
for future communications encrypted with some symmetric cryptosystem upon which they had previously agreed.
The value
Here is a graphical representation:
Diffie-Hellman Key Exchange:
| Alice | on public network | Bob |
| pick a prime |
||
| find a primitive root |
||
| pick |
pick |
|
| publish |
publish |
|
| get |
get |
|
Proposition
When Alice and Bob follow the DHKE protocol, they both compute the same shared key; i.e., DHKE works.
- Proof
-
There’s very little to check here: using the notation of the definition and, in the very middle, the commutativity of multiplication, we have
The left end of this equality is the that Alice computes, while the right end is the one that Bob computes, and they are the same.
Example
Alice and Bob agree in open, public discussion to use the prime
Alice privately chooses her secret value
Bob chooses his secret value
Alice computes the shared secret
Bob computes the same shared secret instead by
They then can use this value to do symmetric crypto for the rest of this communication.
What about the practicality of DHKE? As was discussed in Section 4.4, finding a the [large] prime
One way is to avoid searching for
Another, more mathematical, strategy is based on the following definition, which we give because of its independent mathematical interest and the amazing life of its namesake.
Definition: Sophie Germain Prime
A prime
It is not known how many Sophie Germain primes there are, although it is conjectured that there are an infinite number. In fact, there are precise conjectures on the asymptotic density of such primes, as well as algorithmic techniques to generate them efficiently; see [Sho09].
The first seventeen Sophie Germain primes are
The sequence of all Sophie Germain primes is sequence A005384 at the On-Line Encyclopedia of Integer Sequences, oeis.org.
The largest known Sophie Germain prime, at the time of this writing, is
discovered in
The reader is asked to investigate the usefulness of Sophie Germain primes in DHKE is explored in the exercises, below.
As mentioned in the last section 5.4, DHKE depends for its security on modular exponentiation be a one-way function: feasible to compute forwards (by fast modular exponentiation) but infeasible to computer backwards (which is an index).
If discrete logs could be computed by a feasible algorithm, then Eve could completely break the security of DHKE. Starting with the public values of
Actually, it is not necessary for Eve to be able to compute discrete logs, as long as she can solve a specific computation problem.
Definition: Diffie-Hellman Problem
The Diffie-Hellman problem [DHP] consists of the following question: Given
- a prime
, - a primitive root
, and - two elements
which are known to be of the form and for , although the and are not known
compute
.
An efficient way to compute discrete logs would of course result in a solution of the Diffie-Hellman problem, but it is not known if there might be a solution of the DHP which is does not consist of a full-blown algorithm to compute discrete logs. Since this question is open as of this writing, it makes sense to make the most precise statement: breaking DHKE amounts of solving the DHP, which is not feasible on a classical computer2.
DHKE is one of the most widely used cryptologic protocols on the Internet. It is part of SSL, TLS, SSH, IPsec, and many VPNs, among others.
Exercise
1. Suppose you had an efficient algorithm to generate large Sophie Germain primes. Describe how you would use this to do the initial choice of public parameters for DHKE – go through all of the set-up stages of this protocol, and explain how each can be done feasibly, based on either past discussions of calculations we can do feasibly or on new ideas you develop here.
2. The number
Please play the role of Bob and do what is necessary to establish a shared key with your instructor: you compute
You may need to perform calculations that are hard to do on a hand calculator. If you have access to, and are familiar with, some computer system like Octave, Matlab, or Mathematica, you should be able to do the calculations that way. Otherwise, you might try using your favorite search engine on the phrase “fast modular exponentiation applet”, or using wolframalpha.com.
3. Spell out in precise, mathematical detail all of the steps which would be used in a man-in-the-middle attack against DHKE.


