Diffie–Hellman key exchange

Diffie–Hellman (DH) key exchange is a mathematical method of securely generating a symmetric cryptographic key over a public channel.

Uses your system voice; voice and rate in settings.

Snapshot

≈ 8 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

Diffie–Hellman (DH) key exchange is a mathematical method of securely generating a symmetric cryptographic key over a public channel. It is named after Whitfield Diffie and Martin Hellman who published it in 19761. DH is one of the earliest practical examples of key exchange implemented within the field of cryptography.

Traditionally, secure encrypted communication between two parties required that they first exchange keys by some secure physical means, such as paper key lists transported by a trusted courier. By contrast, the Diffie–Hellman key exchange method allows two parties that have no prior knowledge of each other to jointly establish a shared secret key over an insecure channel.

This key can then be used to encrypt subsequent communications using a symmetric-key cipher. The scheme was published by Whitfield Diffie and Martin Hellman in 1976 and named as one of Ralph Merkle's original public key protocols in 1978. The method was followed shortly after by the RSA cryptosystem, an implementation of public-key cryptography using asymmetric algorithms.

In 1997 it was revealed that James H. Ellis, Clifford Cocks, and Malcolm J. Williamson of GCHQ, the British signals intelligence agency, had previously shown in 1969 how public-key cryptography could be achieved. Diffie–Hellman is used to secure a variety of Internet services.…

Diffie–Hellman (DH) key exchange is a mathematical method of securely generating a symmetric cryptographic key over a public channel. It is named after Whitfield Diffie and Martin Hellman who published it in 1976. DH is one of the earliest practical examples of key exchange implemented within the field of cryptography.

Traditionally, secure encrypted communication between two parties required that they first exchange keys by some secure physical means, such as paper key lists transported by a trusted courier. By contrast, the Diffie–Hellman key exchange method allows two parties that have no prior knowledge of each other to jointly establish a shared secret key over an insecure channel.

This key can then be used to encrypt subsequent communications using a symmetric-key cipher. The scheme was published by Whitfield Diffie and Martin Hellman in 1976 and named as one of Ralph Merkle's original public key protocols in 1978. The method was followed shortly after by the RSA cryptosystem, an implementation of public-key cryptography using asymmetric algorithms.

In 1997 it was revealed that James H. Ellis, Clifford Cocks, and Malcolm J. Williamson of GCHQ, the British signals intelligence agency, had previously shown in 1969 how public-key cryptography could be achieved. Diffie–Hellman is used to secure a variety of Internet services.

However, research published in October 20151 suggests that the parameters in use for many DH Internet applications at that time were not strong enough to prevent compromise by very well-funded attackers, such as the security services of some countries. Although Diffie–Hellman key exchange itself is a non-authenticated key-agreement protocol, it provides the basis for a variety of authenticated protocols, and is used to provide forward secrecy in Transport Layer Security's ephemeral modes (referred to as EDH or DHE depending on the cipher suite).

Forward secrecy results from the use of ephemeral keys: the private keys are discarded once key agreement is complete, making them safe from later compromise. Ephemeral keys are practical because it is computationally cheap to create public-private key pairs suitable for use with Diffie-Hellman exchange. Expired US patent 4200770 from 1977 describes the now public-domain algorithm.

It credits Hellman, Diffie, and Merkle as inventors. Alice and Bob publicly agree to use a modulus = and base = (which is a primitive root modulo 23).

Alice chooses a secret integer = 4, then sends Bob = mod = mod = (in this example both and have the same value 4, but this is usually not the case) Bob chooses a secret integer = 3, then sends Alice = mod = mod = Alice computes = mod = mod = Bob computes = mod = mod = Alice and Bob now share a secret (the number 18). Both Alice and Bob have arrived at the same values because under mod p, {\color{Blue}A}^{\color{Red}\boldsymbol{b}}\bmod {\color{Blue}p} = {\color{Blue}g}^{\color{Red}\boldsymbol{ab}}\bmod {\color{Blue}p} = {\color{Blue}g}^{\color{Red}\boldsymbol{ba}}\bmod {\color{Blue}p} = {\color{Blue}B}^{\color{Red}\boldsymbol{a}}\bmod {\color{Blue}p} More specifically, ({\color{Blue}g}^{\color{Red}\boldsymbol{a}}\bmod {\color{Blue}p})^{\color{Red}\boldsymbol{b}}\bmod {\color{Blue}p} = ({\color{Blue}g}^{\color{Red}\boldsymbol{b}}\bmod {\color{Blue}p})^{\color{Red}\boldsymbol{a}}\bmod {\color{Blue}p} Only a and b are kept secret.

All the other values – p, g, g a mod p, and g b mod p – are sent in the clear. The strength of the scheme comes from the fact that g ab mod p = g ba mod p take extremely long times to compute by any known classical algorithm just from the knowledge of p, g, g a mod p, and g b mod p. Such a function that is easy to compute but hard to invert is called a one-way function.

Once Alice and Bob compute the shared secret they can use it as an encryption key, known only to them, for sending messages across the same open communications channel. Of course, much larger values of a, b, and p would be needed to make this example secure, since there are only 23 possible results of n mod 23.

However, if p is a prime of at least 600 digits, then even the fastest modern computers using the fastest known algorithm cannot find a given only g, p and g a mod p. Such a problem is called the discrete logarithm problem. The computation of g a mod p is known as modular exponentiation and can be done efficiently even for large numbers.

Note that g need not be large at all, and in practice is usually a small integer (like 2, 3, ...). , public (primitive root) base, known to Alice, Bob, and Eve. = , public (prime) modulus, known to Alice, Bob, and Eve. = , Alice's private key, known only to Alice. = , Bob's private key known only to Bob. = , Alice's public key, known to Alice, Bob, and Eve. = mod = , Bob's public key, known to Alice, Bob, and Eve. = mod = | valign="top" | | valign="top" | |} Now is the shared secret key and it is known to both Alice and Bob, but not to Eve. Note that it is not helpful for Eve to compute , which equals + mod .

Note: It should be difficult for Alice to solve for Bob's private key or for Bob to solve for Alice's private key. If it is not difficult for Alice to solve for Bob's private key (or vice versa), then an eavesdropper, Eve, may simply substitute her own private / public key pair, plug Bob's public key into her private key, produce a fake shared secret key, and solve for Bob's private key (and use that to solve for the shared secret key).

Eve may attempt to choose a public / private key pair that will make it easy for her to solve for Bob's private key. Both Alice and Bob are now in possession of the group element g ab = g ba , which can serve as the shared secret key.

The group G satisfies the requisite condition for secure communication as long as there is no efficient algorithm for determining g ab given g, g a , and g b . For example, the elliptic curve Diffie–Hellman protocol is a variant that represents an element of G as a point on an elliptic curve instead of as an integer modulo n. Variants using hyperelliptic curves have also been proposed. The supersingular isogeny key exchange is a Diffie–Hellman variant that was designed to be secure against quantum computers, but it was broken in July 2022.

Participant A performs one final exponentiation, yielding the secret = , while B does the same to get = ; again, C and D do similarly. Participants E through H simultaneously perform the same operations using as their starting point.

Once this operation has been completed all participants will possess the secret , but each participant will have performed only four modular exponentiations, rather than the eight implied by a simple circular arrangement.

Text derived from https://en.wikipedia.org/w/index.php?oldid=1376512836 under CC BY-SA 4.0; modifications have been made.

References

  1. ↩Wikipedia “Diffie–Hellman key exchange” revision 1376512836 · retrieved 2026-10-20 publication date (×3) · confidence 0.95 revision URL