Documento
Documento
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
Group Messages........................................................................................ 11
Call Setup................................................................................................... 12
Statuses..................................................................................................... 14
Live Location ............................................................................................. 14
Conclusion ................................................................................................. 28
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 .
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 .
• Signed Device List Data - An encoded list identifying the currently
linked companion devices at the time of signing . Signed by the
primary device’s Identity Key using the 0x0602 prefix.
• Account Signature - A Curve25519 signature computed over the
0x0600 prefix, Linking Metadata, and companion device’s public
Identity Key using a primary device’s Identity Key .
• Device Signature - A Curve25519 signature computed over the
0x0601 prefix, Linking Metadata, companion device’s public Identity
Key, and primary’s devices public Identity Key using a companion
device’s Identity Key .
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).
7 . The primary serializes the Linking Data (Ldata) containing Lmetadata, Iprimary
and Asignature .
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
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 changes for each message transmitted, and is ephemeral,
such that the Message Key used to encrypt a message cannot be
reconstructed from the session state after a message has been transmitted
or received .
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.”
This causes the Chain Key to “ratchet” forward, and also means that a stored
Message Key can’t be used to derive current or past values of the Chain Key
.
1 . ephemeral_secret =
ECDH(Ephemeralsender, Ephemeralrecipient) .
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:
The SRTP master secret is persisted in memory on the client device and
used only during the call . WhatsApp servers do not have access to the
SRTP master secrets .
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 .
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 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 .
CK1 (0)
Legal values for D are positive powers of two less than or equal to the number
of bits in the iteration counter: 1, 2, 4, 8, 16, and 32 . Implementors select a
value of D as an explicit CPU-memory (or CPU-network bandwidth) tradeoff .
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)
j > 1 : CKj(0) HmacSHA256(CKj-1(0), {j+1})
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 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 .
1 . Generate the Index MAC Key, Value Encryption Key, Value MAC Key,
Snapshot MAC Key, and Patch MAC Key from Base Key by means of HKDF .
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 R of MACs of previous states of all records that are affected
(deleted with REMOVE or overwritten with a SET operation) .
• 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) )
PatchMAC = HMAC_SHA_256(
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:
The KeyID is composite and consists of 4 byte Epoch and 2 byte DeviceID.
Epoch is selected randomly between 1 and 65536 by the primary devices
during the registration of the first companion device, and after that
increases by 1 every time a device rotates a key . The DeviceID component
of the KeyID is used to resolve races between several devices rotating the
key at the same time, so that all keys will receive unique IDs . To settle on
a single key after such an event, clients prefer the key with the smallest
DeviceID component when Epoch components are equal . Otherwise,
always prefer the KeyID with the largest Epoch . Additionally, one (or in
rare cases several) encryption keys can be active at any given time .
• Upon receiving a Mutation in any Collection mark all keys with a smaller
Epoch as expired .
• 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:
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 Patch
informs other devices that encryption keys with epoch less or equal to the
provided epoch should not be used going forward .
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 .
9 . The primary generates a Device List Signature for the updated Device
List Data, ListSignature = CURVE25519_ SIGN(Iprimary, 0x0602 ||
ListData) .
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 .
In 2021, organizations who use the Business API will be able to designate
WhatsApp’s parent company, Facebook, as the vendor that operates the
Business API endpoint on their behalf . Since such messages are not
delivered directly to an endpoint controlled by the organization, WhatsApp
does not consider chats with organizations who choose to use Facebook
to operate their API endpoint to be end-to-end encrypted .
When chatting with an organization that uses the Business API, WhatsApp
determines the end-to-end encryption status based only on the
organization’s choice of who operates its endpoint .
These changes will take effect in all WhatsApp versions after January
2021 .
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
.
The Signal Protocol library used by WhatsApp is based on the Open Source
library, available here:
http://github .com/whispersystems/libsignal-protocol-java/