Whatsapp Encryption Overview: Technical White Paper
Whatsapp Encryption Overview: Technical White Paper
WhatsApp
Encryption Overview
Version 6 Updated November 15, 2021
Version 5 Preview (Applicable to Multi-Device Beta Only) Updated September 27, 2021
Version 4 Preview (Applicable to Multi-Device Beta Only) Updated July 14, 2021
Version 3 Updated October 22, 2020
Version 2 Updated December 19, 2017
Version 1 Originally published April 5, 2016
SEPTEMBER 27 2021
Contents
Introduction......................................................................................................3
Client Registration............................................................................................5
Exchanging Messages.....................................................................................8
Group Messages............................................................................................10
Call Setup.......................................................................................................12
Group Calling..................................................................................................12
Statuses.........................................................................................................13
Live Location..................................................................................................13
Verifying Keys................................................................................................22
Transport Security.........................................................................................24
Conclusion.....................................................................................................27
Messaging Security
Introduction
This white paper provides a technical explanation of WhatsApp’s end-to-
end encryption system . Please visit WhatsApp’s website at
www .whatsapp .com/ security for more information .
The Signal Protocol, designed by Open Whisper Systems, is the basis for
WhatsApp’s end-to-end encryption . This end-to-end encryption protocol is
designed to prevent third parties and WhatsApp from having plaintext
access to messages or calls . Due to the ephemeral nature of the
cryptographic keys, even in a situation where the current encryption keys
from a user’s device are physically compromised, they cannot be used to
decrypt previously transmitted messages .
A user can have multiple devices, each with its own set of encryption keys .
If the encryption keys of one device are compromised, an attacker cannot
use them to decrypt the messages sent to other devices, even devices
registered to the same user . WhatsApp also uses end-to-end encryption to
encrypt the message history transferred between devices when a user
registers a new device .
This document gives an overview of the Signal Protocol and its use in
WhatsApp .
Terms
Device Types
• Primary device - A device that is used to register a WhatsApp
account with a phone number . Each WhatsApp account is
associated with a single primary device . This primary device can be
used to link additional companion devices to the account .
Supported primary device platforms include Android and iPhone .
• One-Time Pre Keys – A queue of Curve25519 key pairs for one time
use, generated at install time, and replenished as needed .
Companion Linking
• Linking Metadata - An encoded blob of metadata assigned to a
companion device during linking, used in conjunction with the
companion device’s Identity Key to identify a linked companion on
WhatsApp clients .
Client Registration
Primary Device Registration
At registration time, a WhatsApp client transmits its public Identity Key,
public Signed Pre Key (with its signature), and a batch of public One-Time
Pre Keys to the server . The WhatsApp server stores these public keys
associated with the user’s identifier.
2 . The primary client scans the linking QR code and saves Icompanion
6 . The primary generates a Device List Signature for the updated Device
List Data, ListSignature = CURVE25519_SIGN(Iprimary, 0x0602 || ListData).
15 . The server stores the uploaded data associated with the user’s
identifier combined with a device specific identifier.
3 . For every returned key set for a companion device, the initiator
needs to verify Asignature by CURVE25519_VERIFY_SIGNATURE(Iprimary,
0x0600 || Lmetadata || Icompanion), and Dsignature by CURVE25519_
VERIFY_SIGNATURE(Icompanion, 0x0601 || Lmetadata || Icompanion
|| Iprimary). If any of the verification fails for a companion device, the
initiator terminates the encryption session building process
immediately and will not send any messages to that device .
After getting the keys from server and verifying each device identity, the
initiator starts to establish the encryption session with each individual
device:
5 . The initiator uses HKDF to create a Root Key and Chain Keys
from the master_secret .
Until the recipient responds, the initiator includes the information (in the
header of all messages sent) that the recipient requires to build a
corresponding session . This includes the initiator’s (Einitiator and Iinitiator) .
Additionally, if the initiator is a companion device, it also includes its Iprimary,
Lmetadata, Asignature and Dsignature .
Exchanging Messages
Once a session has been established, clients exchange messages that are
protected with a Message Key using AES256 in CBC mode for encryption
and HMAC-SHA256 for authentication . The client uses client-fanout for all
the exchanged messages, which means each message is encrypted for
each device with the corresponding pairwise session .
The Message Key is derived from a sender’s Chain Key that “ratchets”
forward with every message sent . Additionally, a new ECDH agreement is
performed with each message roundtrip to create a new Chain Key . This
provides forward secrecy through the combination of both an immediate
“hash ratchet” and a round trip “DH ratchet.”
1 . ephemeral_secret =
ECDH(Ephemeralsender, Ephemeralrecipient) .
A chain is only ever used to send messages from one user, so message
keys are not reused . Because of the way Message Keys and Chain Keys
are calculated, messages can arrive delayed, out of order, or can be lost
entirely without any problems .
2 . The sender encrypts the attachment with the AES256 key in CBC
mode with a random IV, then appends a MAC of the ciphertext using
HMAC-SHA256 .
Group Messages
End-to-end encryption of messages sent to WhatsApp groups utilize the
established pairwise encrypted sessions, as previously described in the
“Initiation Session Setup” section, to distribute the “Sender Key”
component of the Signal Messaging Protocol .
When sending a message to a group for the first time, a “Sender Key” is
generated and distributed to each member device of the group, using the
pairwise encrypted sessions . The message content is encrypted using the
“Sender Key”, achieving an efficient and secure fan-out for the messages
that are sent to groups .
3 . The sender combines the 32-byte Chain Key and the public key
from the Signature Key into a Sender Key message .
1 . The sender derives a Message Key from the Chain Key, and
updates the Chain Key .
The “hash ratchet” of the message sender’s Chain Key provides forward
secrecy . Whenever a group member leaves, all group participants clear
their Sender Key and start over .
Call Setup
WhatsApp voice and video calls are end-to-end encrypted . When a
WhatsApp user initiates a voice or video call:
Group Calling
WhatsApp group calls are end-to-end encrypted . Unlike one-to-one calls
that setup keys only once, in group calls, keys are reset whenever a
participant joins the call or leaves the call .
Note that in a group call, a participant becomes active when they initiate
a group call or accepts the group call invitation from any of their
devices . Therefore each active participant has exactly one active device .
To ensure call quality and to avoid race conditions from conflicting user
actions, the WhatsApp server stores the state of the current group call (for
example: participant list, call initiator) and media metadata (e .g . resolution,
media type) . With this information, the WhatsApp server is able to broadcast
participant membership changes and select one as key distributor to initiate
key reset . membership changes and select one as key distributor to initiate
key reset .
Statuses
WhatsApp statuses are encrypted in much the same way as group messages
. The first status sent to a given set of devices follows the same sequence of
steps as the first time a WhatsApp group member sends a message to a
group. Similarly, subsequent statuses sent to the same set of devices follow
the same sequence of steps as all subsequent messages to a group . When
a status sender removes a receiver either through changing status privacy
settings or removing a number from their address book, the status sender
clears their Sender Key and starts over .
Live Location
Live location messages and updates are encrypted in much the same way as
group messages . Currently, sending and receiving live locations is only
supported on primary devices. The first live location message or update sent
follows the same sequence of steps as the first time a WhatsApp group
member sends a message to a group . But, live location demands a high
volume of location broadcasts and updates with lossy delivery where
receivers can expect to see large jumps in the number of ratchets, or
iteration counts . The Signal Protocol uses a linear-time algorithm for
ratcheting that is too slow for this application . This document offers a fast
ratcheting algorithm to solve this problem .
CK(1)
CK(N-1) MK(N-1)
CK (0) CK (0)
1 2
CK 2 ( M-1) MK(M-1)
In this example, message keys are always derived from CK2 . A receiver who
needs to ratchet by a large amount can skip M iterations at a time (where M
is an agreed-upon constant positive integer) by ratcheting CK1 and
generating a new CK2:
CK1 (0)
After a sender creates a message key and encrypts a message with it, all
chain keys on the path that led to its creation must be destroyed to preserve
forward secrecy .
CK (0)
1
CK (2) CK (1)
1 2
If a chain key CKj (for j in [1, D]) has an iteration count of M, it cannot be
used . This algorithm restores the chain keys to a usable state:
Moving from one iteration count to another never ratchets a single chain key
more than M times . Therefore, no ratcheting operation takes more than D×M
steps .
MK = HmacSHA256(CKj(i), {1})
Each dimension must use a different function . Keys are initialized as:
j = 1 : CK1(0) RNG(32)
Example App State Syncing client settings and other data include the
following:
App State does not include user messages’ content, nor keys that could be
used to decrypt messages, nor settings that might impact the secrecy of
messages .
App State Syncing is designed to guarantee the secrecy and integrity of the
data being synchronized . The pairwise encrypted sessions (as outlined in
the Initiating Session Setup Section) are used for transferring secret keys
between different devices of the same account .
Terms
• Base Key - Input key material used to generate the keys used to encrypt
the data or provide its integrity .
• Index MAC Key - Key derived from the Base Key via HKDF and used to
compute the HMAC of the index .
• Value Encryption Key - Key derived from the Base Key via HKDF and used
to encrypt the combined Mutation index and value . The encryption is
done via AES-256 in CBC mode .
• Value MAC Key - Key derived from the Base Key via HKDF and used to
compute the HMAC of the combined Mutation index and value . Used on
the MAC stage of Encrypt-then-MAC approach to provide authenticated
encryption .
• Snapshot MAC Key - Key derived from the Base Key via HKDF and used
to provide anti-tampering for Snapshots generated by Base Roller .
• Patch MAC Key - Key derived from the Base Key via HKDF and used to
provide anti-tampering for Patches .
• KeyID - Unique identifier for the Base Key . Base Keys are rotated
periodically and when a device is removed from the account to provide
eventual future secrecy . An attacker in possession of a removed device
and access to the server can no longer decrypt the content of SET
Mutations submitted after the removal .
Encryption of Mutations
In order for Base Roller to coalesce sequences of actions to the same index,
it needs the index submitted to the server to be deterministic . HMAC of the
index is used as an identifier of the index-value record the Mutations refers
to. This also makes sure that the indexes that the server sees have the same
length and prevent the server from guessing the record for which the
Mutation is applied .
Combined index and value plaintext are supplemented with arbitrary length
padding in order to enable some model of differential privacy on the type of
the records .
Anti-Tampering
The anti-tampering mechanisms described below are designed to prevent:
The server periodically runs a Base Roller which compacts the Patch
Queue into a single Snapshot . Clients cannot predict when the Snapshot
is going to be built (at the extreme the Snapshots could be built on every
Patch) . Thus, clients include an additional unforgeable checksum for
each Patch in order to be able to verify all possible Snapshots built by the
server .
• Build a set A of MACs of all SET records (in encrypted form) in the
Patch P .
LtHash16Add(H, A): R
= H for Item in A:
R = LtHash16AddSingle(R, Item) return R
LtHash16AddSingle(H, I):
X = HKDF(1024, “WhatsApp Patch Integrity”, I) return
PointwiseAdd16(H, X)
SnapshotMAC = HMAC_SHA_256(
SnapshotMACKey,
LtHash ||
TO_64_BIT_NETWORK_ORDER(PatchVersion) ||
TO_UTF8(CollectionName) )
PatchMACKey,
SnapshotMAC ||
MutationMAC_0 ||
MutationMAC_1 ||
.. ||
MutationMAC_N ||
TO_64_BIT_NETWORK_ORDER(PatchVersion) ||
TO_UTF8(CollectionName) )
Both values PatchMAC and SnapshotMAC are included in the Patch and
submitted to the server .
Verification
The Base Roller process on the server must preserve SnapshotMAC (and
the KeyID used to generate it) of the latest Patch that was used to
construct the Base Rolled Snapshot . This value is used by a client that
received a Snapshot to independently verify its integrity by applying
LtHash16 over all of its records and further compute the MAC as
described above .
Key Rotation
A Key Rotation involves a client randomly generating a new key tuple and
broadcasting it to all other devices . In the event of Key Rotation, all
future Mutations must not use any previous key version . To preserve the
ability of the server to coalesce the Mutations applied to a record when
updating across a key boundary, a client must submit a REMOVE
Mutation with the old key and a SET Mutation (if needed) with the new
key . It is notable that a simultaneous REMOVE and SET occurring as the
key version increases will be relatively easy for the server to correlate as
equating to an update of the record . In collusion with anyone with
access to the old key, WhatsApp would therefore be able to determine
with high confidence the value of the new index; and might be able to
assume that this means it has been updated .
Each device maintains a list of the encryption keys together with additional
data:
• When a client wants to submit a new Patch to the server it first must
check the list of known keys . If there is one that is still active it uses
it . Otherwise, it performs the Key Rotation . To rotate the key:
If a device receives a Mutation from the server and the KeyID is not
known, a device can request to resend the encryption keys from other
devices .
To guarantee that encryption keys are not shared with untrusted devices,
all client applications only send them via authenticated pairwise
encrypted sessions:
To make sure that other devices will not inadvertently use an encryption
key that should be expired on device removal, the device that performs
the removal (the companion device itself or primary device) submits a
Patch into all Collections marking all the current keys as expired . This
Verifying Keys
WhatsApp users additionally have the option to verify the keys of their
devices and the devices of the users with which they are communicating
in end-to-end encrypted chats, so that they are able to confirm that an
unauthorized third party (or WhatsApp) has not initiated a man-in-the-
middle attack. Verification can be done by scanning the QR code or by
comparing the 60-digit number between two primary devices . WhatsApp
users can also verify individual companion devices manually by using a
primary device to check the same QR code or 60-digit number .
1 . A version .
3 . The full 32-byte public Identity Key for all devices of both
parties .
When either device scans the other’s QR code, the keys are compared to
ensure that what is in the QR code matches the Identity Key as retrieved
from the server .
7 . The primary detects a device removal and loads its own Identity
Key as Iprimary .
Transport Security
Communication between WhatsApp clients and WhatsApp chat servers
is layered within a separate encrypted channel using Noise Pipes with
Curve25519, AES-GCM, and SHA256 from the Noise Protocol Framework
for long running interactive connections .
Implementation on WhatsApp
Services
This is straightforward when it comes to two people communicating on
their phones or computers using WhatsApp Messenger or the WhatsApp
Business App: each person’s WhatsApp endpoint is running on a device
they control .
Conclusion
All WhatsApp messages are sent with the same Signal protocol outlined
above . WhatsApp considers all messages, voice calls, and video calls
sent between all devices controlled by a sender user and all devices
controlled by a recipient user to be end-to-end encrypted . WhatsApp
message history syncing and app state syncing are also protected by
end-to-end encryption . Communications with a recipient who elects to
use a vendor to manage their API endpoint are not considered end-to-end
encrypted . If this occurs, WhatsApp makes it clear to users within the
chat .
http://github .com/whispersystems/libsignal-protocol-java/