15. The Signal Protocol

End-to-end encryption with forward and future secrecy

TLS is a masterpiece of secure channel design — but it solves a specific problem: securing a connection between a client and a server. The server participates in the cryptography. It knows the session keys. That means anyone who controls the server can read your messages.

For private messaging between two people, that's not good enough. You want encryption where the server is just a relay — a dumb mailbox that forwards bytes it cannot read. You want end-to-end encryption, where only the two endpoints hold the keys.

The Signal Protocol — invented by Moxie Marlinspike and Trevor Perrin, and used by Signal, WhatsApp, Facebook Messenger, and Google's RCS — is the gold standard for this. It provides end-to-end encryption with two remarkable properties that go far beyond TLS: forward secrecy and future secrecy (also called break-in recovery). Understanding why you need both, and how the protocol achieves them, is the goal of this page.

The Problems to Solve

Designing an end-to-end encrypted messaging protocol turns out to be surprisingly hard. Three problems make it difficult:

  1. Asynchronous delivery

    Alice wants to send Bob a message right now. Bob's phone is off. Bob hasn't generated any ephemeral keys for this session. There's nobody to do a real-time Diffie-Hellman handshake with.

    TLS solves this by having the server always online. Messaging apps can't: the server shouldn't hold any keying material. The protocol needs a way for Alice to establish a shared secret with Bob before Bob is online.

  2. Forward secrecy

    If an attacker records Alice and Bob's encrypted messages today, then later compromises Bob's long-term private key, can they decrypt the recorded messages? In a naive system, yes. You want a protocol where past messages stay safe even if current keys are stolen.

  3. Future secrecy (break-in recovery)

    Suppose an attacker installs malware on Bob's phone and reads his current session state. Forward secrecy ensures they can't read old messages. But can they read future messages? In many protocols, yes — they've captured the session key and can decrypt everything until Bob reboots or rekeys.

    Future secrecy means the protocol heals. Even after a full state compromise, once a new message exchange happens, the attacker is locked out again.

The Signal Protocol achieves all three

X3DH handles asynchronous initial key establishment. The Double Ratchet provides forward secrecy (via the symmetric ratchet) and future secrecy / break-in recovery (via the DH ratchet). Together, they make the Signal Protocol the most security-principled messaging protocol in widespread deployment.

X3DH: The Initial Handshake

Before Alice can send Bob an encrypted message, they need a shared secret. X3DH (Extended Triple Diffie-Hellman) is how they get one — even when Bob is offline.

The key insight: Bob uploads several prekeys to the server in advance, before Alice ever contacts him. When Alice wants to message Bob, she fetches those prekeys and performs a set of DH operations that produce a shared secret. When Bob comes online later, he can perform the same computations and arrive at the same secret.

Bob's Key Material

Bob generates and uploads four types of keys to the Signal server:

Bob's keys on the server

IK_B  — Identity Key (long-term EC key pair, lives for months/years)
SPK_B — Signed Prekey (medium-term EC key pair, rotated weekly/monthly)
        Signed by IK_B so Alice can verify it's genuinely from Bob.
OPK_B — One-Time Prekey (batch of ephemeral EC key pairs, each used once)
        Once Alice consumes OPK_B, it's deleted and never reused.

The signed prekey is rotated periodically to limit the window of exposure. The one-time prekeys are a batch of disposable keys uploaded in bulk — the server sends Alice one per session and deletes it immediately after. If all one-time prekeys are exhausted, the protocol still works, but with slightly reduced security properties.

Alice's Computation

Alice fetches Bob's prekeys and generates her own ephemeral key pair (EKA)(EK_A). She then computes four separate DH operations:

The four DH computations

Alice has:
  IK_A  — her own identity key
  EK_A  — ephemeral key she generates fresh for this session

She fetches from server: IK_B, SPK_B, OPK_B

DH1 = DH(IK_A, SPK_B) ← mutual authentication DH2 = DH(EK_A, IK_B) ← forward secrecy for Bob's identity key DH3 = DH(EK_A, SPK_B) ← forward secrecy for signed prekey DH4 = DH(EK_A, OPK_B) ← one-time prekey for extra forward secrecy

Master secret = HKDF(DH1 || DH2 || DH3 || DH4)

This combination of keys is why it's called "Extended Triple DH" — three distinct Diffie-Hellman contexts (plus a fourth for the one-time prekey). No single compromised key breaks all four simultaneously.

Why It Works Offline

When Bob comes online and receives Alice's first message, she includes her identity key IKAIK_A, her ephemeral key EKAEK_A, and the ID of the one-time prekey she used. Bob performs the same four DH computations (with the roles of A/B reversed — DH is symmetric), derives the same master secret, and the session is established.

The server never sees any of the private key material. It only stores public keys. It cannot compute the master secret.

X3DH Overview

           Before Alice contacts Bob:

Bob's device Signal server ───────────── ───────────── Generate IK_B, SPK_B, OPK_B → stores public parts (private keys stay on device)

       When Alice sends first message:

Alice's device Signal server Bob's device ────────────── ───────────── ──────────── Generate EK_A Fetch Bob's prekeys ←────────── send IK_B, SPK_B, OPK_B Compute DH1,2,3,4 Derive master secret Encrypt first message ─────────────────────────────────> fetch message (delete OPK_B) Compute DH1,2,3,4 Derive same secret Decrypt ✓

The Double Ratchet

X3DH establishes the initial shared secret. The Double Ratchet uses it to encrypt the actual conversation — and it's where forward secrecy and break-in recovery come from.

The Double Ratchet combines two interlocking ratchets:

  1. A symmetric-key ratchet (the chain key) that produces a new message key for every single message sent or received.
  2. A Diffie-Hellman ratchet (the root key) that resets the chain keys every time a new message is sent in a new direction.

The Symmetric (Chain) Ratchet

The chain key ratchet is simple: a KDF chain that advances with every message.

Chain key derivation

CK_0 = initial chain key (from X3DH or DH ratchet step)

CK_1, MK_1 = KDF(CK_0) ← message 1 uses MK_1, chain advances to CK_1 CK_2, MK_2 = KDF(CK_1) ← message 2 uses MK_2 CK_3, MK_3 = KDF(CK_2) ← message 3 uses MK_3 ...

Each message key MK_n is used to encrypt exactly one message, then immediately deleted.

CK_0 → CK_1 → CK_2 → CK_3 → ... ↓ ↓ ↓ MK_1 MK_2 MK_3

Because message keys are derived forward and then deleted, an attacker who captures MK3MK_3 cannot reverse it to find MK1MK_1 or MK2MK_2 — KDF chains are one-way. This is the forward secrecy of the symmetric ratchet.

The DH Ratchet

The symmetric ratchet alone has one vulnerability: if an attacker captures the current chain key CKnCK_n, they can derive all future message keys in this chain — MKn+1MK_{n+1}, MKn+2MK_{n+2}, and so on. They're locked in from the current state forward until the chain ends.

The DH ratchet solves this. Every time you send a reply in a new conversational turn, you include a fresh ephemeral DH public key in the message header. When the other party receives it, they perform a new DH exchange. Both sides derive a new root key, which seeds new chain keys. The attacker — who doesn't have the ephemeral private key — is locked out.

DH ratchet step

Alice sends:
  - Her new ephemeral public key: alice_ratchet_pub_2
  - Messages encrypted with keys from her sending chain

Bob receives:

  • Sees alice_ratchet_pub_2 (different from last time)
  • Computes DH(bob_ratchet_priv, alice_ratchet_pub_2) = new_DH_output
  • RK_new, CK_recv_new = KDF(RK_old, new_DH_output)
  • Decrypts messages using keys from CK_recv_new

Bob replies:

  • Generates new ratchet key pair: bob_ratchet_pub_3
  • Computes DH(bob_ratchet_priv_3, alice_ratchet_pub_2) = another_DH_output
  • RK_new2, CK_send_new = KDF(RK_new, another_DH_output)
  • Encrypts reply using keys from CK_send_new

Both Ratchets Together

The real protocol combines the two ratchets. Each party maintains:

  • A root key (RK) — ratcheted by each DH step
  • A sending chain key (CKs) — ratcheted by each sent message
  • A receiving chain key (CKr) — ratcheted by each received message
  • Current ratchet key pair — replaced on each DH ratchet step

Double Ratchet Structure

X3DH shared secret
       │
       ▼
  ┌─────────┐
  │ Root Key│ ◄─── DH ratchet steps renew this
  └────┬────┘
       │
   ┌───┴─────────────────────────────────┐
   │                                     │
   ▼                                     ▼
Send chain key                    Recv chain key
   │                                     │
   ├──► MK_s1 (encrypt msg 1)           ├──► MK_r1 (decrypt msg 1)
   │                                     │
   ├──► MK_s2 (encrypt msg 2)           ├──► MK_r2 (decrypt msg 2)
   │                                     │
   ▼ (new DH exchange resets both)       ▼

Forward Secrecy and Break-In Recovery

Let's see concretely what these properties mean when an attacker is in the picture.

Forward Secrecy

An attacker records every encrypted message Alice and Bob exchange over six months. Six months later, they compromise Bob's phone and steal the current session state — all current chain keys, ratchet key pairs, and even the root key.

Without forward secrecy

A long-term static key encrypts all sessions. An attacker with that key can decrypt six months of recorded messages in one sitting. This is the model of classic asymmetric encryption: one private key unlocks everything encrypted to the corresponding public key.

With the Double Ratchet

The attacker has the current chain key. But all prior message keys have been deleted. The KDF chain is one-way. They cannot derive any past message key from the current chain key. Six months of recorded messages remain undecipherable.

Break-In Recovery (Future Secrecy)

Now consider the same attacker who has compromised Bob's current state. They have the current chain key and ratchet state. Can they read Bob's future messages?

Temporarily, yes — they can derive the next few message keys from the stolen chain key. But as soon as Alice sends a new message, she includes a fresh DH ratchet key. Bob's app generates a new ephemeral key pair, performs the DH exchange, and derives new root and chain keys. The attacker, who doesn't have Bob's new ephemeral private key, cannot perform the DH computation. They're locked out.

The healing window

The attacker stays locked in until the next DH ratchet step. In the Signal Protocol, a DH ratchet step happens every time the conversation direction changes — Alice sends, then Bob replies. In practice, this means an attacker who compromises the current state is locked out after just one round-trip exchange. The protocol heals automatically, with no action required from either user.

This is why the DH ratchet exists at all. The symmetric ratchet alone gives forward secrecy. Only the DH ratchet gives break-in recovery.

Out-of-Order Messages

Real networks don't deliver messages in order. Alice sends messages 5, 6, and 7, but they arrive as 7, 5, 6. This is a problem for a chain where each message key is derived from the previous one — you'd need message 5's key to derive 6's, and 6's to derive 7's.

The Signal Protocol handles this elegantly: when a message arrives out of order, the receiver advances their chain key to derive the expected message key but stores the skipped keys in a dictionary keyed by (ratchet-key, message-number). When the out-of-order message eventually arrives, the stored key decrypts it.

Skipped message keys

Alice sends: 1, 2, 3, 4, 5
Bob receives: 1, 2, 5 (out of order — 3 and 4 arrive later)

When Bob receives 5: Advance chain: derive MK_3, MK_4, MK_5 Store MK_3 and MK_4 in "skipped keys" cache Use MK_5 to decrypt message 5 ✓

When message 3 arrives: Look up MK_3 in cache, decrypt ✓ Delete MK_3 from cache

Skipped keys are kept for a limited window (e.g., 1000 messages) and deleted after a timeout. Any message arriving outside the window is rejected as potentially replayed.

The skipped-key window is bounded — if a message is too old or too far ahead, it's rejected. This prevents an attacker from forcing the receiver to accumulate enormous amounts of keying material.

Signal Protocol vs TLS

Both protocols provide encrypted communication. The difference is who the server can see.

TLS

Encrypts the connection between your browser and the server. The server terminates the TLS session — it decrypts your request, processes it, and re-encrypts the response. The server reads everything.

Appropriate for: banking, web apps, APIs — you're supposed to trust the server.

Signal Protocol

Encrypts the message between Alice's device and Bob's device. The Signal server forwards opaque ciphertext it cannot decrypt. Even if the server is compromised, the attacker sees only ciphertext and metadata (who is messaging whom, and when — not what they said).

Appropriate for: messaging where the server operator should not be trusted with message content.

Property TLS Signal Protocol
Encrypts against network attackers Yes Yes
Server can read messages Yes No
Forward secrecy Yes (per-session ECDHE) Yes (per-message chain keys)
Future secrecy / break-in recovery No Yes (DH ratchet)
Works asynchronously (recipient offline) No Yes (X3DH prekeys)
Designed for Client-server Peer-to-peer via relay

Real-World Adoption

The Signal Protocol is the most widely deployed end-to-end encryption protocol for messaging. It has been adopted — in full or in modified form — by:

App Status
Signal Original and reference implementation
WhatsApp Full Signal Protocol, end-to-end by default for all chats since 2016
Facebook Messenger "Secret Conversations" uses Signal Protocol; regular chats do not
Google Messages (RCS) End-to-end encryption using Signal Protocol for RCS chats
Skype "Private Conversations" feature uses Signal Protocol

The most notable caveat: metadata. The Signal Protocol hides message content from the server, but the server still sees who is messaging whom, and when. Signal (the app) goes to significant lengths to minimize this — sealed sender, private contact discovery — but the protocol itself doesn't solve the metadata problem.

Double Ratchet Simulator

Step through a conversation between Alice and Bob. Watch the DH ratchet key advance with each new conversational turn, and see the chain key ratchet forward for every individual message. Each cell shows which key was used to encrypt or decrypt that message.

Forward Secrecy Demo

Simulate a session compromise. Select which message number represents the moment an attacker captures the current state. See which messages are exposed (future messages until the next DH ratchet step) and which remain safe (all past messages, and all messages after the next DH exchange).

Key Takeaways

  • End-to-end encryption means the server is a relay that cannot read messages — only the endpoints hold keys
  • X3DH solves asynchronous key agreement: Bob uploads prekeys so Alice can initiate a session while Bob is offline
  • The Double Ratchet combines a symmetric chain ratchet (per-message keys) with a DH ratchet (per-turn keys)
  • Forward secrecy comes from the chain ratchet: message keys are derived forward and deleted, making them unrecoverable from current state
  • Break-in recovery (future secrecy) comes from the DH ratchet: a new ephemeral DH exchange locks out any attacker who captured past state
  • Out-of-order messages are handled by caching skipped message keys in a bounded window
  • The Signal Protocol is used by Signal, WhatsApp, Google Messages, and others — it is the industry standard for end-to-end encrypted messaging
  • The protocol protects message content, not metadata — who talks to whom is still visible to the server

We've now built up a complete picture of modern cryptography: symmetric ciphers, hash functions, public-key systems, signatures, key exchange, TLS, and end-to-end messaging. Every protocol we've studied is correct in theory. But cryptography is implemented by humans, and implementations have subtle flaws. In the next section we turn to attacks — not on the math, but on the way these primitives are used in practice. Padding oracles, timing side channels, and length-extension attacks all exploit gaps between the ideal and the real.