ArticleslgStudy

computer science

Diffie–Hellman key exchange

Diffie–Hellman key exchange is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Diffie–Hellman key exchange rather than just read about it. In short: 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.

Diffie–Hellman key exchange — main illustration
Diffie–Hellman key exchange — illustration

Key takeaways

  • Diffie–Hellman key exchange belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Diffie–Hellman key exchange to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Diffie–Hellman key exchange from memory before moving on to harder problems.

Reference excerpt

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 2015 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.

Name In 2006, Hellman suggested the algorithm be called Diffie–Hellman–Merkle key exchange in recognition of Ralph Merkle's contribution to the invention of public-key cryptography (Hellman, 2006), writing:

The system ... has since become known as Diffie–Hellman key exchange. While that system was first described in a paper by Diffie and me, it is a public key distribution system, a concept developed by Merkle, and hence should be called 'Diffie–Hellman–Merkle key exchange' if names are to be associated with it. I hope this small pulpit might help in that endeavor to recognize Merkle's equal contribution to the invention of public key cryptography.

Description

General overview

Diffie–Hellman key exchange establishes a shared secret between two parties that can be used for secret communication for exchanging data over a public network. An analogy illustrates the concept of public key exchange by using colors instead of very large numbers: The process begins by having the two parties, Alice and Bob, publicly agree on an arbitrary starting color that does not need to be kept secret. In this example, the color is yellow. Each person also selects a secret color that they keep to themselves – in this case, red and cyan. The crucial part of the process is that Alice and Bob each mix their own secret color together with their mutually shared color, resulting in orange-tan and light-blue mixtures respectively, and then publicly exchange the two mixed colors. Finally, each of them mixes the color they received from the partner with their own private color. The result is a final color mixture (yellow-brown in this case) that is identical to their partner's final color mixture. If a third party listened to the exchange, they would only know the common color (yellow) and the first mixed colors (orange-tan and light-blue), but it would be very hard for them to find out the final secret color (yellow-brown). Bringing the analogy back to a real-life exchange using large numbers rather than colors, this determination is computationally expensive; it is impossible to compute in a practical amount of time even for modern supercomputers.

Cryptographic explanation The simplest and the original implementation, later formalized as Finite Field Diffie–Hellman in RFC 7919, of the protocol uses the multiplicative group of integers modulo p, where p is prime, and g is a primitive root modulo p. To guard against potential vulnerabilities, it is recommended to use prime numbers of at least 2048 bits in length. This increases the difficulty for an adversary attempting to compute the discrete logarithm and compromise the shared secret. These two values are chosen in this way to ensure that the resulting shared secret can take on any value from 1 to p − 1. Here is an example of the protocol, with non-secret values in blue, and secret values in red.

Alice and Bob publicly agree to use a modulus p = 23 and base g = 5 (which is a primitive root modulo 23). Alice chooses a secret integer a = 4, then sends Bob A = ga mod p A = 54 mod 23 = 4 (in this example both A and a have the same value 4, but this is usually not the case) Bob chooses a secret integer b = 3, then sends Alice B = gb mod p B = 53 mod 23 = 10 Alice computes s = Ba mod p s = 104 mod 23 = 18 Bob computes s = Ab mod p s = 43 mod 23 = 18 Alice and Bob now share a secret (the number 18). Both Alice and Bob have arrived at the same values because under mod p,

A𝒃modp=g𝒂𝒃modp=g𝒃𝒂modp=B𝒂modp More specifically,

… excerpt ends here. Continue reading the full article.

Illustrations

Diffie–Hellman key exchange: With Diffie–Hellman key exchange, two parties arrive at a common secret key, without passing the common secret key across the public channel.
With Diffie–Hellman key exchange, two parties arrive at a common secret key, without passing the common secret key across the public channel.
Diffie–Hellman key exchange: Illustration of the concept behind Diffie–Hellman key exchange
Illustration of the concept behind Diffie–Hellman key exchange

Worked examples

Example 1 — a first encounter with Diffie–Hellman key exchange

Start with the simplest possible case. Write down what Diffie–Hellman key exchange claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Diffie–Hellman key exchange before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Diffie–Hellman key exchange ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Diffie–Hellman key exchange

In research
Diffie–Hellman key exchange appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Diffie–Hellman key exchange in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Diffie–Hellman key exchange is common in secondary-school and first-year university syllabi. It links to neighbouring topics Key-agreement protocols, Public-key cryptography, so understanding it makes those chapters shorter.
In everyday life
Look for Diffie–Hellman key exchange outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Diffie–Hellman key exchange” →

How to study Diffie–Hellman key exchange in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Diffie–Hellman key exchange means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Diffie–Hellman key exchange out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Diffie–Hellman key exchange in simple terms?

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.

Why does Diffie–Hellman key exchange matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Diffie–Hellman key exchange?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Diffie–Hellman key exchange.

Tags

  • Key-agreement protocols
  • Public-key cryptography

Keep exploring