A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Diffie-Hellman Key Exchange

Graduate Depth 82 in the knowledge graph ☐ I know this ☆ Set as goal
24topics build on this
399prerequisites beneath it
See this on the map →
Discrete LogarithmsModular Arithmetic and Congruences+1 more→→Computational Hardness AssumptionsElliptic Curve Cryptography Basics+1 more
diffie-hellman key-exchange discrete-logarithm-problem man-in-the-middle

Core Idea

Diffie-Hellman (1976) allows two parties to establish a shared secret key over a public channel without any prior shared secret. Both parties agree on a public prime p and generator g. Alice picks secret a, sends ga mod p; Bob picks secret b, sends gb mod p. Both compute the shared key gab mod p. Security rests on the Computational Diffie-Hellman (CDH) assumption: given ga and gb, computing gab is hard without knowing a or b. DH is vulnerable to man-in-the-middle attacks without authentication. The protocol also works over elliptic curve groups (ECDH), offering equivalent security with smaller parameters.

Explainer

In 1976, Whitfield Diffie and Martin Hellman published a protocol that solved one of the oldest problems in cryptography: how can two people who have never met establish a shared secret over a channel that anyone can listen to? Before their work, all encryption required a pre-existing shared key — to communicate securely, you first needed a secure channel to exchange keys, which was precisely the problem you were trying to solve. Diffie-Hellman key exchange breaks this circularity using the one-way nature of modular exponentiation.

The protocol is remarkably simple. Alice and Bob publicly agree on a large prime p and a generator g of a multiplicative group modulo p. Alice picks a random secret integer a and sends A = ga mod p to Bob. Bob picks a random secret b and sends B = gb mod p to Alice. Alice computes K = Ba = gba mod p; Bob computes K = Ab = gab mod p. Both arrive at the same shared secret K = gab mod p. An eavesdropper sees g, p, ga, and gb, but computing gab from this information appears to require solving the Computational Diffie-Hellman (CDH) problem, which is believed hard in well-chosen groups. The eavesdropper would need to either compute a discrete logarithm (find a from ga) or find some other way to compute gab — and no efficient method is known.

The main vulnerability of basic DH is man-in-the-middle attack. An active attacker Mallory can intercept Alice's message, replace it with her own public value, and do the same to Bob. She ends up sharing one key with Alice and a different key with Bob, relaying (and reading) all messages between them. Neither Alice nor Bob detects the interception because basic DH provides no authentication — they have no way to verify whose public value they received. The solution is to authenticate the DH exchange, typically by having each party sign their DH public value with a long-term digital signature key (as in the TLS handshake) or by using certificates from a trusted authority.

Modern deployments predominantly use Elliptic Curve Diffie-Hellman (ECDH), which performs the same protocol in an elliptic curve group rather than a multiplicative group modulo a prime. Elliptic curve groups resist the index calculus attacks that apply to modular arithmetic, so a 256-bit elliptic curve provides approximately the same security as a 3072-bit prime — dramatically smaller keys and faster computation. TLS 1.3, the protocol securing most web traffic, mandates ECDH (or its post-quantum successors) and has removed classical DH entirely. The conceptual contribution of Diffie and Hellman — that secure key agreement is possible over public channels — remains the intellectual foundation of internet security, even as the specific groups and parameters evolve.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Set Operations: Union, Intersection, and Complement → Proof by Cases → Proving by Cases and Exhaustion → Vacuous Truth and Trivial Cases → Proof by Cases (Proof by Exhaustion) → Mathematical Induction → Divisibility and Greatest Common Divisor → The Fundamental Theorem of Arithmetic → Divisibility Theory (Formal Treatment) → Fundamental Theorem of Arithmetic (Rigorous Proof) → Arithmetic Functions and Multiplicativity → Euler's Totient Function → Primitive Roots and Cyclic Groups Mod p → Discrete Logarithms → Diffie-Hellman Key Exchange

Longest path: 83 steps · 399 total prerequisite topics

Prerequisites (3)

Leads To (3)