logo

Proof of the Diffie-Hellman Key Exchange Algorithm 📂Number Theory

Proof of the Diffie-Hellman Key Exchange Algorithm

Buildup

20190220_171354.png

From left to right, let’s call them Alice, Bob, and Eve. Alice and Bob are the parties exchanging messages, and Eve is a passive attacker interested in the messages. The orange box denotes information known only to Alice, the sky-blue box denotes information known only to Bob, and the black box denotes information that is public (also known to Eve).

Alice and Bob intend to exchange messages under the cryptography system (K,M,C,ek,dk)( \mathcal{K} , \mathcal{M} , \mathcal{C} , e_{k} , d_{k} ). Unfortunately, Eve knows the decryption function dkd_{k} and cannot directly transmit the key kk without Eve finding out. However, if in this situation, Alice and Bob can each generate a key KK that only the two of them share, Eve would not be able to decrypt the ciphertext despite knowing dkd_{k} because she does not know the key KK. This solution is exactly the Diffie-Hellman Key Exchange Algorithm.

Algorithm 1

Let Fp=Fp{0}={1,g,g2,,gp2}\mathbb{F}_{p}^{ \ast } = \mathbb{F}_{p} \setminus \left\{ 0 \right\} = \left\{ 1, g , g^2 , \cdots , g^{p-2} \right\} be a cyclic group with (p1)(p-1) elements.


Step 1.

A very large prime number pp and ordp(g)\text{ord}_{p} (g), which is a large prime number, are chosen and made public.

20190221_101527.png


Step 2.

Alice picks an arbitrary integer aa, and Bob picks an arbitrary integer bb.

20190221_101538.png


Step 3. Encryption

Aga(modp)A \equiv g^{a} \pmod{p} and Bgb(modp)B \equiv g^{b} \pmod{p} are calculated and made public.

20190221_102156.png


Step 4. Decryption

By using the cipher c=eK(m)c = e_{K} (m) encrypted with KK as the key, KBaAb(modp)K \equiv B^{a} \equiv A^{b} \pmod{p} is computed, and Eve realistically cannot know KK, so she cannot know m=dK(c)m = d_{K} (c).

20190221_103703.png

Description

In Step 1., ordp(g)\text{ord}_{p} (g) serves as the order, which should be as large a prime as possible so that gng_{n} makes it difficult to predict changes depending on nn. If it only reaches about ordp(g)=3\text{ord}_{p} (g) = 3, calculating KK becomes too easy. If ordp(g)=nm\text{ord}_{p} (g) = nm is a composite number, then when it’s said that gnm1(modp)g^{nm} \equiv 1 \pmod{p}, it means (gn)m1(modp)( g^{n} ) ^{m} \equiv 1 \pmod{p}; hence it’s essentially the same as using G:=gnG:=g^{n}, which is a smaller order.

It’s important to note that the Diffie-Hellman key exchange algorithm itself does not become some cryptographic system but is merely a method for Alice and Bob to create a secret key KK in the presence of a passive attacker. The KK obtained in this way is unrelated to the message, and the cryptographic system does not change at all.

Proof

Decryption

Alice and Bob, knowing aa and bb, can easily compute KAb(ga)bgab(gb)aBa(modp) \begin{align*} K & \equiv A^{b} \\ & \equiv \left(g^{a} \right)^{b} \\ & \equiv g^{ab} \\ & \equiv \left(g^{b} \right)^{a} \\ & \equiv B^{a} \pmod{p} \end{align*} Therefore, with the public gg, knowing either aa or bb is enough to find KK.

Encryption

Since Eve only knows AA and BB, not aa and bb, she has to solve the discrete logarithm problem AxK(modp)A^{x} \equiv K \pmod{p} or BxK(modp)B^{x} \equiv K \pmod{p}. This is very difficult, so Alice and Bob can communicate securely from Eve using KK as the key.

See Also

Security algorithms utilizing the difficulty of the discrete logarithm problem

Attack algorithms for the discrete logarithm problem


  1. Hoffstein. (2008). An Introduction to Mathematical Cryptography: p66. ↩︎