X3DH Formal Proof
Time to read: 40 minutes
Prerequisites: Basic understanding of X3DH (see X3DH Tutorial)
Difficulty: Beginner
Next: 03 Double Ratchet Formal Proof
The Simple Story
Alice and Bob want to start a secure conversation using X3DH.
Eve (the attacker) tries to:
- Read their messages (secrecy)
- Impersonate Bob (authentication)
- Replace Bob's keys (MITM attack)
Formal verification asks: Can we mathematically prove Eve can't succeed?
Answer: YES! Here's how we prove it using ProVerif.
Mental Model: What We're Proving
Hold this picture in your head:
What We Prove:
- Eve cannot learn the shared secret
- The 4 DH operations are in the correct order
- Keys are derived correctly from DH outputs
- MITM attacks fail (with signature verification)
The Story: Eve's Attack Attempts
Attempt 1: Eve Tries to Read the Shared Secret
Eve's plan:
- Watch Alice download Bob's public keys
- Intercept Alice's message to Bob
- Derive the shared secret herself
- Decrypt the message
The formal verification query:
\forall x: \text{bitstring}; \quad \text{not attacker}(\text{shared_secret}[x])ProVerif says: RESULT: true
Meaning: Eve can't derive the shared secret from public information alone.
Why?
- Eve knows: (Bob's identity key), (signed pre-key), (one-time pre-key), Bob's (Alice's ephemeral key)
- Eve needs: (Alice's identity private key), (Bob's signed pre-key private key), (Alice's identity private key)
- The only way to do X3DH: Have Alice's private keys (only Alice has them!)
- Eve can't: Learn private keys from public keys (ECC is hard)
Attempt 2: Eve Tries to Impersonate Bob
Eve's plan:
- Replace Bob's public keys on the server with Eve's keys
- Alice downloads "Bob's keys" (actually Eve's)
- Alice does X3DH with Eve
- Eve can now read all messages
Without signature verification:
Result: MITM attack succeeds!
With signature verification:
ProVerif query:
Meaning: If Bob uploaded real keys, then Alice should initiate with Bob's keys.
Result: RESULT: true (when signature verification included)
Note: This is demonstrated in x3dh_security.pv (see next section).
The Mathematics: Modeling X3DH in ProVerif
The 4 DH Operations
Real X3DH (from Signal Protocol spec):
Where:
- = Identity Key
- = Signed Pre-Key
- = One-Time Pre-Key
- = Ephemeral Key
ProVerif Model (x3dh_complete.pv):
(* DH1 = DH(Identity_Alice, SignedPreKey_Bob) *)
let dh1 = compute_dh(identity_a, signed_prekey_b_pub) in
(* DH2 = DH(Ephemeral_Alice, Identity_Bob) *)
let dh2 = compute_dh(ephemeral_a, identity_b_pub) in
(* DH3 = DH(Ephemeral_Alice, SignedPreKey_Bob) *)
let dh3 = compute_dh(ephemeral_a, signed_prekey_b_pub) in
(* DH4 = DH(Ephemeral_Alice, OneTimePreKey_Bob) *)
let dh4 = compute_dh(ephemeral_a, one_time_prekey_b_pub) in
Comparison Table:
| Real Protocol | ProVerif Model | File Path | Lines |
|---|---|---|---|
compute_dh(identity_a, signed_prekey_b_pub) | formal-proofs/proverif/x3dh/x3dh_complete.pv | 50 | |