Path: blob/main/foundations/05-discrete-log-diffie-hellman/connect/dh-in-tls13.ipynb
483 views
Connect: Diffie-Hellman in TLS 1.3
Module 05 | Real-World Connections
TLS 1.3 mandates ephemeral Diffie-Hellman for every connection, giving forward secrecy by default.
Introduction
Transport Layer Security (TLS) is the protocol that secures HTTPS, email, VPN, and most Internet communication. TLS 1.3 (RFC 8446, finalized 2018) made a landmark decision: every connection must use ephemeral Diffie-Hellman (or its elliptic curve variant, ECDHE).
This means:
Fresh DH keys are generated for every handshake
After the handshake, the DH secret is deleted
Even if the server's long-term private key is later compromised, past sessions remain secure (forward secrecy)
In this notebook, we simulate a simplified TLS 1.3-style handshake to see DH in action.
The TLS 1.3 Handshake (Simplified)
The key exchange portion of the TLS 1.3 handshake:
Key points:
The DH exchange happens in the first round trip (1-RTT)
Both and are ephemeral (new for each connection)
The shared secret is never transmitted; it's derived independently
Forward Secrecy: Why Ephemeral DH Matters
Forward secrecy means: if the server's long-term private key is compromised at some point in the future, past recorded sessions cannot be decrypted.
This is guaranteed because:
Each session uses fresh DH keys
After deriving the session key, the DH secrets are deleted
The shared secret exists only in memory during the handshake
Without ephemeral DH (as in TLS 1.2 with RSA key exchange), an attacker who records ciphertext and later obtains the server's RSA private key can decrypt everything.
Named Groups: Standardized DH Parameters
TLS 1.3 does not let servers choose arbitrary DH parameters. Instead, it uses named groups from RFC 7919:
| Group | Prime size | Security level |
|---|---|---|
| ffdhe2048 | 2048 bits | ~112 bits |
| ffdhe3072 | 3072 bits | ~128 bits |
| ffdhe4096 | 4096 bits | ~150 bits |
| ffdhe6144 | 6144 bits | ~175 bits |
| ffdhe8192 | 8192 bits | ~192 bits |
All of these are safe primes () with generator .
Why standardize?
Prevents servers from using weak primes (smooth order, small subgroups)
The primes are generated from nothing-up-my-sleeve numbers (digits of ), so no one can embed a backdoor
Enables precomputation for efficiency
Concept Map: Module 05 in TLS 1.3
| Module 05 Concept | TLS 1.3 Application |
|---|---|
| DH key exchange | Session key establishment (ClientHello / ServerHello) |
| Ephemeral keys | Forward secrecy --- fresh per connection |
| DLP hardness | Security of key exchange (eavesdropper can't compute ) |
| Safe primes | Named groups (ffdhe2048-8192) prevent small-subgroup attacks |
| Pohlig-Hellman risk | Why TLS 1.3 mandates safe primes, not arbitrary primes |
| CDH assumption | The core assumption: given and , computing is hard |
Summary
| Concept | Key idea |
|---|---|
| Ephemeral DH | Each connection gets fresh keys, so past sessions stay safe even if long-term keys are later compromised (forward secrecy). |
| DLP/CDH hardness | An eavesdropper who sees and cannot compute the shared secret . |
| Safe primes | TLS 1.3 named groups use safe primes to prevent Pohlig-Hellman and small-subgroup attacks. |
| 1-RTT handshake | DH key shares are sent in the very first messages, completing the exchange in a single round trip. |
| HKDF key derivation | The raw DH shared secret is expanded into a uniform session key via HKDF. |
| No static key exchange | TLS 1.3 removed static RSA and static DH entirely because forward secrecy is too important to leave optional. |
TLS 1.3 removed all non-ephemeral key exchanges (static RSA, static DH) precisely because forward secrecy is too important to leave as optional.