An implementation of the double cryptographic ratchet described by https://whispersystems.org/docs/specifications/doubleratchet/.
This document uses
When this document uses
Where this document uses
The setup takes four Curve25519 inputs: Identity keys for Alice and Bob,
"OLM_ROOT"
as the info.
Advancing a root key takes the previous root key, "OLM_RATCHET"
as the
info.
Advancing a chain key takes the previous chain key, "\x02"
using the
previous chain key as the key.
Creating a message key takes the current chain key, "\x01"
using the
current chain key as the key. The message keys where
Bob publishes the public parts of his identity key,
Alice downloads Bob's identity key,
Alice computes a message key,
Alice encrypts her plain-text with the message key,
She then sends the following to Bob:
- The public part of her identity key,
$I_A$ - The public part of her single-use key,
$E_A$ - The public part of Bob's single-use key,
$E_B$ - The current chain index,
$j$ - The public part of her ratchet key,
$T_0$ - The cipher-text,
$X_{0,j}$
Alice will continue to send pre-key messages until she receives a message from Bob.
Bob receives a pre-key message as above.
Bob looks up the private part of his single-use key,
Bob then advances the chain key
Bob stores Alice's initial ratchet key,
Once a message has been received from the other side, a session is considered established, and a more compact form is used.
To send a message, the user checks if they have a sender chain key,
A message key,
The user then sends the following to the recipient:
- The current chain index,
$j$ - The public part of the current ratchet key,
$T_i$ - The cipher-text,
$X_{i,j}$
The user receives a message as above with the sender's current chain index,
The user checks if they have a receiver chain with the correct
If the
If the decryption succeeds the receiver updates the chain key for
Olm uses two types of messages. The underlying transport protocol must provide a means for recipients to distinguish between them.
Olm messages start with a one byte version followed by a variable length payload followed by a fixed length message authentication code.
+--------------+------------------------------------+-----------+
| Version Byte | Payload Bytes | MAC Bytes |
+--------------+------------------------------------+-----------+
The version byte is "\x03"
.
The payload consists of key-value pairs where the keys are integers and the values are integers and strings. The keys are encoded as a variable length integer tag where the 3 lowest bits indicates the type of the value: 0 for integers, 2 for strings. If the value is an integer then the tag is followed by the value encoded as a variable length integer. If the value is a string then the tag is followed by the length of the string encoded as a variable length integer followed by the string itself.
Olm uses a variable length encoding for integers. Each integer is encoded as a sequence of bytes with the high bit set followed by a byte with the high bit clear. The seven low bits of each byte store the bits of the integer. The least significant bits are stored in the first byte.
Name | Tag | Type | Meaning |
---|---|---|---|
Ratchet-Key | 0x0A | String | The public part of the ratchet key, Ti, of the message |
Chain-Index | 0x10 | Integer | The chain index, j, of the message |
Cipher-Text | 0x22 | String | The cipher-text, Xi, j, of the message |
The length of the MAC is determined by the authenticated encryption algorithm being used. (Olm version 1 uses HMAC-SHA-256, truncated to 8 bytes). The MAC protects all of the bytes preceding the MAC.
Olm pre-key messages start with a one byte version followed by a variable length payload.
+--------------+------------------------------------+
| Version Byte | Payload Bytes |
+--------------+------------------------------------+
The version byte is "\x03"
.
The payload uses the same key-value format as for normal messages.
Name | Tag | Type | Meaning |
---|---|---|---|
One-Time-Key | 0x0A | String | The public part of Bob's single-use key, Eb. |
Base-Key | 0x12 | String | The public part of Alice's single-use key, Ea. |
Identity-Key | 0x1A | String | The public part of Alice's identity key, Ia. |
Message | 0x22 | String | An embedded Olm message with its own version and MAC. |
Version 1 of Olm uses AES-256 in CBC mode with PKCS#7 padding for
encryption and HMAC-SHA-256 (truncated to 64 bits) for authentication. The
256 bit AES key, 256 bit HMAC key, and 128 bit AES IV are derived from the
message key using HKDF-SHA-256 using the default salt and an info of
"OLM_KEYS"
.
The plain-text is encrypted with AES-256, using the key
Then the entire message (including the Version Byte and all Payload Bytes) are passed through HMAC-SHA-256. The first 8 bytes of the MAC are appended to the message.
To avoid unknown key-share attacks, the application must include identifying data for the sending and receiving user in the plain-text of (at least) the pre-key messages. Such data could be a user ID, a telephone number; alternatively it could be the public part of a keypair which the relevant user has proven ownership of.
-
Alice publishes her public Curve25519 identity key,
$I_A$ . Eve publishes the same identity key, claiming it as her own. Bob downloads Eve's keys, and associates$I_A$ with Eve. Alice sends a message to Bob; Eve intercepts it before forwarding it to Bob. Bob believes the message came from Eve rather than Alice.This is prevented if Alice includes her user ID in the plain-text of the pre-key message, so that Bob can see that the message was sent by Alice originally.
-
Bob publishes his public Curve25519 identity key,
$I_B$ . Eve publishes the same identity key, claiming it as her own. Alice downloads Eve's keys, and associates$I_B$ with Eve. Alice sends a message to Eve; Eve cannot decrypt it, but forwards it to Bob. Bob believes the Alice sent the message to him, wheras Alice intended it to go to Eve.This is prevented by Alice including the user ID of the intended recpient (Eve) in the plain-text of the pre-key message. Bob can now tell that the message was meant for Eve rather than him.
The Olm specification (this document) is hereby placed in the public domain.
Can be sent to olm at matrix.org.
The ratchet that Olm implements was designed by Trevor Perrin and Moxie Marlinspike - details at https://whispersystems.org/docs/specifications/doubleratchet/. Olm is an entirely new implementation written by the Matrix.org team.