The Double Ratchet Algorithm
Overview
The classical Double Ratchet is a foundation of the Signal Protocol. Session setup and continuing message-key updates are separate stages. This lab teaches:
- Forward Secrecy: Old messages stay secure even if keys leak
- Break-in Recovery: New messages become secure after key changes
How this compares with current Signal
Signal introduced PQXDH for session establishment in 2023, then announced SPQR and the Triple Ratchet on 2 October 2025 (opens in new tab). The ratchet specification, revision 4 (4 November 2025) (opens in new tab), describes the classical Double Ratchet (Β§3), SPQR (Β§5), the Triple Ratchet (Β§6), and integration with PQXDH (Β§7.1).
| Construction | At session setup | During the conversation |
|---|---|---|
| Classical mode β runs here | Four X25519 DH secrets, legacy demo KDF | Symmetric chains and fresh X25519 DH steps |
| Hybrid mode β runs here | Four DH secrets + real ML-KEM-1024 secret; initial AEAD confirmation | The same classical Double Ratchet; no new post-quantum secrets |
| Triple Ratchet β reading only | PQXDH seed expanded into separate classical and SCKA roots | Double Ratchet and SPQR run in parallel; both message keys are combined before encryption |
A hybrid handshake addresses passive harvest-now/decrypt-later attacks under the KEM and symmetric-crypto assumptions. It does not provide post-quantum authentication or quantum post-compromise healing after the session state is stolen. The recovery exercise here shows classical DH recovery only, in either setup mode.
SPQR uses a sparse continuous key agreement, recommended as ML-KEM Braid, to introduce fresh post-quantum secrets across later messages. Epoch coordination, loss handling and key mixing are essential; this lab does not implement them.
For the handshakeβs individual steps and attack models, see PQXDH Wire. The hybrid mode here follows the structure of PQXDH revision 3 (updated 23 January 2024) (opens in new tab) with lab-specific encodings and signatures. ML-KEM-1024 is standardized in FIPS 203 (13 August 2024) (opens in new tab); it is not a byte-compatible replacement for older Kyber ciphertexts.
Notation Cheat-Sheet
The specs (and this demo's labels) use a compact shorthand. Keep this handy:
| Symbol | Meaning | Stage |
|---|---|---|
IK | Identity Key β long-term key identifying a party | X3DH |
EK | Ephemeral Key β Alice's one-off key for this handshake | X3DH |
SPK | Signed Pre-Key β Bob's medium-term key, signed by his IK | X3DH |
OPK | One-Time Pre-Key β Bob's single-use key (the 4th DH) | X3DH |
SK | Shared secret from X3DH; becomes the first root key | X3DH |
RK | Root Key β advanced by the DH ratchet | Double Ratchet |
CK | Chain Key β advanced by the symmetric ratchet | Double Ratchet |
MK | Message Key β used once to encrypt/decrypt one message | Double Ratchet |
DHs / DHr | Our / their current ratchet key pair (sending / receiving) | Double Ratchet |
Ns / Nr | Message number in the sending / receiving chain | Double Ratchet |
PN | Previous-chain length β # of messages in the prior sending chain | Double Ratchet |
Two Ratchets
| Ratchet | Purpose | Trigger | Output |
|---|---|---|---|
| Symmetric Ratchet | Forward Secrecy | Every message sent | Unique message key |
| DH Ratchet | Break-in Recovery | Direction change | New root + chain keys |
Symmetric Ratchet:
Uses HKDF to derive a unique message key from a chain key:
MK[n] = HKDF(CK[n], salt=0x01, "ratchet-wire-message")
CK[n+1] = HKDF(CK[n], salt=0x02, "ratchet-wire-chain")
DH Ratchet:
Uses fresh X25519 key pairs to derive a new root key and a new chain key (the root key is the HKDF salt, the DH output is the input key material):
root_new β chain_key = HKDF(
ikm = DH(my_private, their_public),
salt = root_old,
info = "ratchet-wire-root"
)
Key Properties
- One-way: Chain keys advance forward; you can't derive the previous chain key
- Deletable: Message keys are ephemeral; no stored history
- Testable: Both parties use the same HKDF labels, ensuring consistency
Classical setup β simplified X3DH
Classical mode models X3DH ("Extended Triple Diffie-Hellman") using separate signing and DH identity keys:
- Signed pre-key: Bob signs his pre-key with his long-term Ed25519 identity key; Alice verifies that signature before deriving anything. A changed prekey with an invalid signature is rejected β try the "Alter a pre-key without re-signing" button on the Conversation tab. This does not authenticate the supplied identity itself: compare or pin the displayed fingerprint through a trusted channel, because a complete valid bundle can be substituted.
- One-time pre-key: a single-use key contributes a fourth DH, so the session stays secret even if Bob's long-term keys later leak.
verify Sig(IK_B, SPK_B) β abort on invalid signature
SK = HKDF( DH1 β DH2 β DH3 β DH4 ) β DH4 uses the one-time pre-key
This Demo vs. Production
Implemented here:
- Classical X3DH-style or hybrid PQXDH-style session setup with checked prekey signatures
- Double Ratchet with out-of-order handling and skipped-key bounds
- Low-order public keys rejected; message headers bound as AEAD associated data
Still simplified (for the demo):
-
The classical-mode X3DH KDF omits the
Fprefix (32 bytes of 0xFF) that X3DH Β§2.2 requires, so derived secrets do not match a conformant implementation β see the note above - Identity uses a separate Ed25519 signing key + X25519 DH key, where production Signal uses a single key via XEdDSA (not exposed by Web Crypto)
- No pre-key server, pool exhaustion or scheduled rotation. Hybrid mode consumes one-time private prekeys after initial AEAD acceptance; its last-resort KEM option retains the KEM key for reuse.
- No XEdDSA, Signal wire format, SPQR, ML-KEM Braid or Triple Ratchet; no quantum recovery demonstration
- In-memory state only (no persistence)
References
Credits
The Double Ratchet Algorithm was developed by Trevor Perrin and Moxie Marlinspike (2016), building on prior work in the Off-the-Record Messaging (opens in new tab) protocol.