Path: blob/main/foundations/05-discrete-log-diffie-hellman/connect/signal-x3dh.ipynb
483 views
Connect: X3DH in the Signal Protocol
Module 05 | Real-World Connections
Signal uses Extended Triple Diffie-Hellman (X3DH) to establish shared keys between users who may be offline.
Introduction
The Signal Protocol (used by Signal, WhatsApp, and others) faces a challenge that TLS does not: how do you establish a shared secret with someone who is offline?
In TLS, both parties are online and exchange DH key shares in real time. In messaging, Alice might want to send Bob a message while Bob's phone is off.
X3DH (Extended Triple Diffie-Hellman) solves this by having Bob publish prekeys to a server. Alice can use these prekeys to establish a shared secret without Bob being online. When Bob comes online, he can derive the same shared secret and read Alice's messages.
X3DH computes three (or four) DH shared secrets and combines them. Each DH computation provides a different security property.
The X3DH Protocol
Each user has three types of keys:
| Key | Lifetime | Purpose |
|---|---|---|
| Identity key | Long-term | Authenticates the user |
| Signed prekey | Medium-term (rotated weekly/monthly) | Provides forward secrecy |
| One-time prekey | Single use | Provides replay protection |
Bob publishes his public keys to the server.
Alice fetches Bob's keys and computes:
where is Alice's fresh ephemeral key.
The combined session key:
Why Three (or Four) DH Computations?
Each DH computation provides a different security property:
| DH | Keys used | Property provided |
|---|---|---|
| Alice's identity + Bob's signed prekey | Mutual authentication: both long-term keys are involved | |
| Alice's ephemeral + Bob's identity | Sender authentication: proves Alice initiated | |
| Alice's ephemeral + Bob's prekey | Forward secrecy: when both ephemeral keys are deleted, the secret can't be recovered | |
| Alice's ephemeral + Bob's one-time prekey | Replay protection: each OPK is used once, preventing message replay |
No single DH computation provides all these properties. Combining them gives:
Authentication (from identity keys)
Forward secrecy (from ephemeral keys)
Replay protection (from one-time prekeys)
Concept Map: Module 05 in Signal
| Module 05 Concept | Signal/X3DH Application |
|---|---|
| DH key exchange | Core of X3DH --- four DH computations combined |
| DLP hardness | Security of all key exchanges |
| Ephemeral keys | provides forward secrecy |
| Multiple DH rounds | Each provides authentication, forward secrecy, or replay protection |
| Key derivation | KDF combines four DH outputs into one session key |
| Safe parameters | Signal uses Curve25519 (elliptic curve DH) for efficiency and safety |
Summary
| Concept | Key idea |
|---|---|
| Asynchronous key agreement | Alice can establish a shared secret even when Bob is offline, using Bob's prekeys published to a server. |
| Three (or four) DH computations | Each DH provides a distinct security property: authentication, forward secrecy, or replay protection. |
| DLP/CDH hardness | The same hardness assumption from Module 05 underpins every DH computation in X3DH. |
| Elliptic curve DH | Signal uses Curve25519 in practice, but the mathematical structure is identical to finite-field DH. |
| Double Ratchet | X3DH bootstraps the session, and then the Double Ratchet algorithm provides ongoing forward secrecy by continuously rotating keys. |
Signal's X3DH protocol demonstrates the power of combining multiple DH computations to achieve authentication, forward secrecy, and replay protection simultaneously.