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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Exchanging Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Group Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Call Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Statuses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Live Location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Verifying Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Transport Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
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. What’s more, even if encryption keys from a user’s device
are ever physically compromised, they cannot be used to go back in time to
decrypt previously transmitted messages.
This document gives an overview of the Signal Protocol and its use in
WhatsApp.
Terms
Public Key Types
• Identity Key Pair – A long-term Curve25519 key pair,
generated at install time.
Client 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.
To establish a session:
7. The initiator uses HKDF to create a Root Key and Chain Keys
from the master_secret.
2. The recipient deletes the One-Time Pre Key used by the initiator.
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 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.”
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
Traditional unencrypted messenger apps typically employ “server-side fan-out”
for group messages. A client wishing to send a message to a group of users
transmits a single message, which is then distributed N times to the N different
group members by the server.
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 also end-to-end encrypted. When a
WhatsApp user initiates a voice or video call:
Statuses
WhatsApp statuses are encrypted in much the same way as group messages.
The first status sent to a given set of recipients 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 recipients 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. 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)
CK(N-1) MK(N-1)
CK1(0) CK2(0)
CK1(1) CK2(1)
…
CK2(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.
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 com-
putation, 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})
Verifying Keys
WhatsApp users additionally have the option to verify the keys of the other
users with whom they are communicating in end-to-end encrypted contexts
so that they are able to confirm that an unauthorized third party (or WhatsApp)
has not initiated a man-in-the-middle attack. This can be done by scanning a
QR code, or by comparing a 60-digit number.
1. A version.
When either user 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. Iteratively SHA-512 hash the public Identity Key and user identi-
fier 5200 times.
Transport Security
Communication between WhatsApp clients and WhatsApp chat servers
is layered within a separate encrypted channel. On KaiOS, iPhone, and
Android, those end-to-end encryption capable clients use 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,
and WhatsApp considers all messages from a device controlled by the sender
to one whose device is controlled by the recipient to be end-to-end encrypted.
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/