Whatsapp Encryption Overview: Technical White Paper
Whatsapp Encryption Overview: Technical White Paper
Whatsapp Encryption Overview: Technical White Paper
Encryption Overview
Technical white paper
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Client Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Exchanging Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Group Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Call Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Group Calling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Statuses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Live Location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Verifying Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Transport Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
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.
Companion Linking
• Linking Metadata - An encoded blob of metadata assigned to a com-
panion 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.
1. The companion client displays its public Identity Key (Icompanion) and
a generated ephemeral Linking Secret Key (Lcompanion) in a linking QR
code. Lcompanion is never sent to WhatsApp server.
2. The primary client scans the linking QR code and saves Icompanion to disk.
6. The primary generates a Device List Signature for the updated Device
List Data, ListSignature = CURVE25519_SIGN(Iprimary, 0x0602
|| ListData).
10. The server stores ListData and ListSignature, and forwards Ldata
and PHMAC to the companion.
15. The server stores the uploaded data associated with the user’s identifier
combined with a device specific identifier.
To establish a session:
1. The initiating client (“initiator”) requests the public Identity Key, public
Signed Pre Key, and a single public One-Time Pre Key for each device of
the recipient and each additional device of the initiating user (excluding
the initiator).
2. The server returns the requested public key values. A One-Time Pre
Key is only used once, so it is removed from server storage after being
requested. If the recipient’s latest batch of One-Time Pre Keys has been
consumed and the recipient has not replenished them, no One-Time Pre
Key will be returned. Additionally, for each companion device (for both the
initiator’s account and the recipient’s), the server also returns the Linking
Metadata (Lmetadata), Account Signature (Asignature) and Device signature
(Dsignature) that was uploaded by the companion device when linked.
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:
1. The initiator saves the recipient’s Identity Key as Irecipient, the Signed
Pre Key as Srecipient, and the One-Time Pre Key as Orecipient.
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.
When the recipient receives a message that includes session setup information:
3. The recipient deletes the One-Time Pre Key used by the initiator.
4. The initiator uses HKDF to derive a corresponding Root Key and Chain
Keys from the master_secret.
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).
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.
5. All receiving devices decrypt the message, retrieve the encrypted blob
from the blob store, verify the SHA256 hash of it, verify the MAC, and
decrypt the plaintext.
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.
4. The sender transmits the single ciphertext message to the server, which
does server-side fan-out to all group participants.
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.
3. The sender combines the 32-byte Chain Key and the public key from
the Signature Key into into an Add-on Sender Key message.
4. The sender individually encrypts the Add-on Sender Key to each member
of the community announcement group, using the pairwise messaging
protocol explained previously.
1. The sender derives an encryption key from the target message’s Message
Secret Add-on Target Key = HKDF(length=32, key=Target
Message Secret, info=Target Message Identifier ||
Target sender Identifier || Add-on Sender Identifier
|| “Add-on type string”).
2. The sender then encrypts the Add-on content with Add-on Target Key
using AES-256-GCM to produce inner ciphertext.
3. The sender derives a Message Key from the Chain Key, and updates
the Chain Key
4. The sender encrypts the inner ciphertext using AES256 in CBC mode to
produce outer ciphertext.
5. The sender signs the outer ciphertext using the Signature Key.
6. The sender transmits the single outer ciphertext Add-on message to the
server, which does server-side fan-out to all group participants.
The “hash ratchet” of the Add-on sender’s Chain Key in conjunction with
the target message’s message secret provides forward secrecy. Whenever a
group member leaves, all Admins clear their Group Sender Key and start
over. Group members, including admins, will not clear their Add-on Sender
Key when a group member leaves and instead will continue to use the existing
key to encrypt for the remaining participants of the group. When promoted
to admin group members will generate a new regular Group Sender Key but
will not update their Add-on Sender Key.
Call Setup
WhatsApp voice and video calls are end-to-end encrypted. When a WhatsApp
user initiates a voice or video call:
4. If the responder answers the call from one of the devices, a SRTP
encrypted call is started, protected by the SRTP master secret gener-
ated for that device.
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.
1. When a participant joins or leaves the call, the WhatsApp server arbitrarily
selects one of the active participants as the key distributor.
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.
Whatsapp servers do not have access to them, and cannot access the
actual audio and video media.
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(0)
CK(1)
…
Consider an extension where we keep two chains of chain keys:
CK(N-1) MK(N-1)
CK1(0) CK2(0)
CK1(1) CK2(1)
CK2(M-1) MK(M-1)
CK1(0)
CK1(2) CK2(1)
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)
CK1(2) CK2(1)
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.
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.
Signal uses different functions for ratcheting versus message key computa-
tion, since both come from the same chain key. In this notation {x} refers to
an array of bytes containing a single byte x.
MK = HmacSHA256(CKj(i), {1})
CKj(i+1) = HmacSHA256(CKj(i), {2})
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 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
Values (together with indexes, as mentioned above) are encrypted using standard
authenticated encryption (described below) with random IVs.
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.
3. Construct the plaintext by combining Index and Value with random padding
(used to obfuscate the size of the Mutation from the server).
Anti-Tampering
The anti-tampering mechanisms described below are designed to prevent:
Snapshot Integrity
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.
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:
4. Persist the key information and send it to all other devices using
the corresponding pairwise encrypted sessions.
5. Use the key to encrypt the Mutations and submit them to the server.
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:
1. While performing Key Rotation, a device must send the new key to all
other devices which are known to be authorized by the primary.
2. When a device receives a new key from a device which is not authorized
by the primary this key is ignored.
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.
1. Lexicographically sort public Identity Keys for all of the user’s devices
and concatenate them.
2. Iteratively SHA-512 hash the sorted Identity Keys and user identi-
fier 5200 times.
7. The primary detects a device removal and loads its own Identity
Key as Iprimary.
Even if no device removal has been detected, while one or more companions
remain linked, primary devices will periodically upload updated Signed
Device List Data following the above steps to produce a signature with an
updated timestamp.
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/