Course contentsShow
← Computer Science
Lesson 2411 of 2,87254. Cryptography FundamentalsFree lesson

Diffie-Hellman Key Exchange

Protocol for two parties to establish a shared secret over an insecure channel without prior secrets.

Diffie-Hellman Key Exchange

What You'll Learn

You'll learn how two parties can establish a shared secret key over an insecure channel without ever transmitting the secret itself.

The Core Problem and Solution

Imagine Alice and Bob want to communicate securely using symmetric cryptography (like AES), but they've never met before and can only talk over a channel that Eve can intercept. How do they agree on a shared secret key without Eve discovering it?

Diffie-Hellman solves this by letting Alice and Bob each contribute their own private information, perform mathematical operations using public information, and arrive at the same shared secret—without ever sending that secret over the channel.

How It Works (Simplified)

The protocol uses modular arithmetic and the properties of exponentiation:

  1. Public parameters: Alice and Bob agree on a large prime number p and a base g (these can be public)
  2. Private keys: Alice picks a secret number a, Bob picks secret number b
  3. Public exchange:
    • Alice computes A = g^a mod p and sends A to Bob
    • Bob computes B = g^b mod p and sends B to Alice
  4. Shared secret:
    • Alice computes s = B^a mod p
    • Bob computes s = A^b mod p
    • Both arrive at the same value: s = g^(ab) mod p

Eve sees g, p, A, and B, but computing a or b from these values (the discrete logarithm problem) is computationally infeasible with proper key sizes.

Paint Mixing Analogy

Think of mixing paint colors: both parties start with a public color (yellow). Each adds their secret color privately. They exchange their mixtures. Each adds their original secret to the received mixture. Both end up with the same final color, but an observer can't "unmix" the paint to discover the secrets.

Key Takeaway: Diffie-Hellman enables two parties to establish a shared secret over an insecure channel by combining public exchanges with private values, relying on the hardness of the discrete logarithm problem for security.