cryptographic protocol
Altbook cryptographic protocol
Revision 2, 2 December 2026. Describes Altbook 0.2: wire and storage format version 1, pairing version 2, knock letter version 2, mailbox server requests versions 1 and 2.
This document may be copied and redistributed freely, in whole or in part.
1. Introduction
Altbook is an iPhone app with a calculator, a notebook, a calendar and an optional private messenger. This document describes the cryptography of the messenger and of the app's encrypted storage: the primitives, how keys are agreed and derived, the message formats, the transports and servers, and what each party can see.
Every primitive used is standardised or published. This document publishes the way they are combined.
There are no accounts and no phone numbers. A contact exists only after two phones pair, in person or through a one-time invitation checked by voice. A person may also make a nickname public, so that others can find it and knock (5.8); a knock carries such an invitation and leads to the same pairing.
2. Notation
  • || is concatenation. u8, u16, u32, u64 are unsigned big-endian integers of 1, 2, 4 and 8 bytes. Z32 is 32 zero bytes.
  • H(x) is SHA-256. HMAC(k, x) is HMAC-SHA256.
  • HKDF(salt, ikm, info, L) is HKDF-SHA256 (RFC 5869), extract then expand. L is 32 bytes unless stated.
  • AEAD(k, n, p, a) is AES-256-GCM with a 12-byte nonce n, plaintext p, associated data a and a 16-byte tag.
  • Every info label is an ASCII string used for one purpose only; no label is a prefix of another. Labels begin with aleteo/, the project's working name, and are part of the format.
  • Pairing gives each phone a role: 0 (initiator) or 1 (responder).
  • "Reject" means: discard the input, change no state, return one generic error.
3. Primitives

Purpose

Primitive

Provided by

Key agreement at pairing

X-Wing (ML-KEM-768 + X25519), draft-connolly-cfrg-xwing-kem-06

Apple CryptoKit

Post-quantum ratchet step

ML-KEM-768 (FIPS 203); every received encapsulation key passes the FIPS 203 §7.2 modulus check, done by our own code before use

Apple CryptoKit

Classical ratchet

X25519 (RFC 7748); an all-zero result and small-order points are rejected

Apple CryptoKit

Encryption

AES-256-GCM (NIST SP 800-38D)

Apple CryptoKit

Key derivation

HKDF-SHA256 (RFC 5869); HMAC-SHA256 for chain keys

Apple CryptoKit

Hash

SHA-256; SHA3-256 only for the Tor onion address checksum

Apple CryptoKit

Outer end-to-end layer

Olm: Curve25519 Double Ratchet with AES-256-CBC and HMAC-SHA256 (MAC truncated to 8 bytes), session configuration version 1

vodozemac 0.11.1, unmodified

Onion service identity

Ed25519 (RFC 8032), only to form Tor v3 onion addresses. The protocol itself signs nothing

Apple CryptoKit

Onion service client authorization

X25519

Apple CryptoKit, tor

Sealing the notification address (11) and knock letters (5.8)

HPKE (RFC 9180), base mode, KEM X-Wing (0x647a), KDF HKDF-SHA256, AEAD AES-256-GCM

Apple CryptoKit; wake server: Go crypto/hpke

Device binding of stored keys

Secure Enclave P-256 ECDH

Apple CryptoKit

Access code to key

Argon2id v1.3 (RFC 9106), t = 3, m = 64 MiB, p = 1, 16-byte salt, 32-byte output

libsodium 1.0.22

Fingerprint of a public nickname

Argon2id v1.3 (RFC 9106), t = 2, m = 256 MiB, p = 1, one fixed 16-byte salt, 32-byte output

libsodium 1.0.22

Nearby link

TLS 1.2 with TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 (RFC 7905)

Apple Network.framework

Network transport

Tor onion services, optionally through bridges (pluggable transports)

tor, embedded

Randomness

the operating system's CSPRNG

iOS

4. Architecture
text → inner plaintext (1280 B) → inner layer, AES-256-GCM (1353 B) → Olm (≤ 1412 B)
     → frame layer, AES-256-GCM (1494 B) → Tor stream to the contact's onion service
                                         or a letter of 1494 B to the mailbox server
  • Two end-to-end layers. The inner layer (section 6) is Altbook's own post-quantum ratchet. The outer layer (section 7) is Olm from vodozemac, an independent implementation. The two layers share no key, so either one alone keeps the text secret.
  • The frame layer (section 8) is transport protection, not end-to-end encryption: every packet has one size, cover frames look exactly like real ones, and frames from anyone but the contact are rejected before any parsing.
  • Servers (sections 10 and 11) are optional and untrusted. A mailbox server keeps encrypted letters for a phone that is offline, and the sealed records and knock boxes of public nicknames; a wake server sends a notification that carries nothing of the message.
5. Pairing
5.1 Setting
In person, the two phones talk over Bluetooth LE or peer-to-peer Wi-Fi. At a distance, they talk over Tor after a one-time invitation (5.7), passed by the people or carried by a knock on a public nickname (5.8), and the two people compare words in a phone call. In both cases the channel is assumed to be fully controlled by an attacker. Security comes only from a commitment, two word checks done by the people, and key confirmation.
5.2 Material made for each contact
Each phone generates fresh: a 32-byte nonce; an X-Wing key pair (xw_pk, 1216 B); an X25519 key pair for the first ratchet step (dr_pub); a vodozemac Account with its Curve25519 identity key (olm_id); on the responder, one Olm one-time key (olm_otk); an Ed25519 seed for "my onion service for you" (onion_pub); an X25519 key pair for "my client authorization at your service" (auth_pub). Nothing is shared between contacts.
5.3 Messages
body_I (1379 B) = u8 version = 2 | u8 role = 0 | nonce 32 | xw_pk 1216 | dr_pub 32 | olm_id 32
                | onion_pub 32 | auth_pub 32 | u8 lang
body_R (1411 B) = u8 version = 2 | u8 role = 1 | nonce 32 | xw_pk 1216 | dr_pub 32 | olm_id 32
                | olm_otk 32 | onion_pub 32 | auth_pub 32 | u8 lang

M1  I → R   0x01 || C,     C = H("aleteo/pair/commit/v1" || body_I)
M2  R → I   0x02 || body_R
M3  I → R   0x03 || body_I                  R checks C
M4  I → R   0x04 || ct_I,  (ss_I, ct_I) = X-Wing.Encaps(xw_pk_R)
M5  R → I   0x05 || ct_R,  (ss_R, ct_R) = X-Wing.Encaps(xw_pk_I)
H1  I → R   0x06 || u16 len || Olm pre-key message holding the inner message HELLO (content th)
H2  R → I   0x07 || u16 len || Olm message holding HELLO_ACK (content th)
H3  I → R   0x08 || u16 len || Olm message holding WORDS_OK (content th)
lang is the word-list language of the phone. Messages are accepted only in this order; M1 to M5 have exact lengths and H1 to H3 bounded ones. Any other message, length or version aborts the attempt and erases all its material. A new attempt needs an action of the person on both phones.
5.4 Transcript and shared secret
th_c   = H("aleteo/pair/th-commit/v1" || M1 || M2 || M3)
th     = H("aleteo/pair/th/v1"        || M1 || M2 || M3 || M4 || M5)
S_pair = HKDF(salt = th, ikm = ss_I || ss_R, info = "aleteo/pair/secret/v1")
Both encapsulations are used, so the randomness of each phone contributes. th covers every public key, both KEM ciphertexts, the nonces and the onion and Olm keys. This matters because the X-Wing combiner hashes the X25519 part of the ciphertext and key but not the ML-KEM part.
5.5 Check words
sas     = HKDF(salt = Z32, ikm = th_c, info = "aleteo/pair/sas/v1", L = 16)
words_I = five 11-bit indexes from bits 0..54 of sas     (most significant bit first)
words_R = five 11-bit indexes from bits 55..109 of sas
Indexes point into a list of 2048 words; the Russian and English lists share indexes.
  • In person. The initiator shows words_I. The responder shows four sets of five words in random order, the true one and three decoys, plus "None matches", and the person picks the set that matches. Then the same in reverse with words_R. A wrong pick aborts.
  • At a distance. Each person reads their five words aloud in the call; the other types them, and their phone compares. The typing aid never suggests the expected words.
  • A phone's own check off. The setting "Check Words When Pairing" is on by default; switching it off asks for the combination that opens the messenger, where there is one. A phone with it off skips only its own check and still shows its own words, so the other phone checks as before. Nothing on the wire changes, and the other phone cannot tell. Such a phone no longer authenticates the other: an attacker in the middle of that pairing goes unnoticed on it, and, if the other phone's check is on, on it alone, because that check refuses the attacker. With both checks off, nothing authenticates either phone. The phone with its check off says "Words not checked on this phone" where it would say that the words matched.
The commitment makes the initiator fix body_I before it sees body_R, and keeps its nonce hidden until the responder has fixed body_R. An attacker in the middle therefore gets one try per check, with success probability 2⁻⁵⁵. M4 and M5 are not in the words, because an attacker chooses ciphertexts last; key confirmation covers them, since H1 and H2 decrypt only if both phones derived the same S_pair.
5.6 Key confirmation and the keys of the contact
After M5 each phone derives:
RK0     = HKDF(salt = th, ikm = S_pair, info = "aleteo/inner/root0/v1")              inner root key
E0      = HKDF(salt = th, ikm = S_pair, info = "aleteo/inner/pq-epoch0/v1")          first epoch secret
FK_r,0  = HKDF(salt = th, ikm = S_pair, info = "aleteo/frame/key/v1" || u8(r))       frame key of role r
NPSK    = HKDF(salt = th, ikm = S_pair, info = "aleteo/nearby/psk/v1")               nearby TLS key
ND      = HKDF(salt = th, ikm = S_pair, info = "aleteo/nearby/discovery/v1")         discovery and mailbox root
  • H1. The initiator opens an Olm outbound session to olm_id_R and olm_otk_R and sends HELLO through both end-to-end layers.
  • The responder opens the inbound session and checks that the pre-key message names olm_id_I and olm_otk_R, that the inner header's ratchet key equals dr_pub_I from the committed body, and that the content equals its own th. It answers with H2.
  • The initiator checks H2. After its person's word check passes, it saves the contact and sends H3. The responder saves the contact only after its own person's check and after H3 has arrived.
  • Both phones then drop the vodozemac Account and erase the X-Wing private keys, ss_I, ss_R, the nonces and S_pair.
The Olm session has keys of its own, never derived from S_pair. The onion keys are random per contact.
5.7 Invitation at a distance
inv            = 16 random bytes
words          = 12 indexes of 11 bits of inv || first 4 bits of H(inv)
inv_onion_seed = HKDF(salt = Z32, ikm = inv, info = "aleteo/invite/onion/v1")   Ed25519 seed of a temporary onion service
inv_auth_seed  = HKDF(salt = Z32, ikm = inv, info = "aleteo/invite/auth/v1")    X25519 client authorization key for it
inv_knock_key  = HKDF(salt = Z32, ikm = inv, info = "aleteo/invite/knock/v1")   AES-256-GCM key of the knock
The inviter passes the 12 words (or a QR code holding inv) by any channel. The invited phone reaches the temporary onion service and sends a knock:
knock (1494 B) = u8 knock_version = 1 | nonce 12 | ciphertext 1465 | tag 16
                 AEAD(inv_knock_key, nonce, plaintext, associated data = the first 13 bytes)
plaintext      = u8 name_len (0..32) | name 32 | knock_id 16 | zero padding
If the inviter accepts, M1 to H3 run over the same Tor stream. Nothing derived from inv enters th or any later key. The invitation is an address and a pass, not an identity: whoever holds it can attempt pairing, and the voice check of 5.5 is what stops them. An invitation is valid for 24 hours, gives at most one contact, and is destroyed when a check fails.
A QR code only names the way to a phone (the nickname it announces nearby, or inv). It enters neither the transcript nor any key of the contact, and both word checks stay as they are.
5.8 Public nickname
A nickname is private by default, in both modes of the app. Then nothing of this section runs: the phone sends no request about it to any server, and the nickname is shown only to phones nearby. A person may make it public. Whoever then types it whole finds on the mailbox server a sealed record that names the owner's knock box, and may leave in that box a knock letter carrying an ordinary invitation of 5.7, made by the finder. The owner answers that invitation on the next entry into the messenger, and from there pairing runs exactly as in 5.3–5.7, with both voice checks. Nothing of this section enters th, S_pair or any key of a contact.
Nickname.
nickname = base "." digits
base     = one of a–z, then 2..17 of a–z, 0–9, "_"          3..18 characters
digits   = 2..5 of 0–9
Typed text is read in this order: white space at both ends dropped, Unicode NFC, the 26 capital Latin letters to small; then it must match the rule exactly, or it is no public nickname. No other character changes, so a look-alike letter of another script or a fullwidth letter is never part of a public nickname, and two public nicknames that look alike are the same bytes (nick, 6 to 24 ASCII bytes). A nickname is found only whole: there is no search by a part, no list and no suggestion. The app proposes two random digits, which the person may change. The public nickname is never announced nearby: phones nearby find a separate nickname, the one the person set for them, which making a nickname public, changing it or leaving it does not touch. So whoever meets the person nearby does not learn the nickname strangers knock on.
Fingerprint and the record key.
salt_n    = first 16 bytes of H("aleteo/nick/salt/v1")
s         = Argon2id(password = nick, salt = salt_n, t = 2, m = 256 MiB, p = 1, 32-byte output)
lookup_id = HKDF(salt = Z32, ikm = s, info = "aleteo/nick/lookup/v1")      the record's name on the server
K_rec     = HKDF(salt = Z32, ikm = s, info = "aleteo/nick/record/v1")      AES-256-GCM key of the record
There is one salt for everyone, because a finder knows nothing but the nickname; the label of its own keeps tables built for other systems useless. Every guess of a nickname therefore costs one Argon2id with 256 MiB of memory. A phone runs it once per search and once per publication, and erases s and the typed nickname as soon as lookup_id and K_rec are made.
The owner's keys. When a nickname is made public, the phone draws from the operating system's generator, apart from s:
owner_token  32 B      the right to publish, renew and remove the record
ktoken       32 B      the right to read and delete letters in the knock box
xk           an X-Wing key pair, kept as its 32-byte seed; xk_pk 1216 B
kbox_id      = H("aleteo/nick/kbox/v1" || ktoken)            the knock box's address
None of them comes from the nickname: whoever knows the nickname finds the record and can knock, but cannot remove or renew the record, nor read or empty the box. A nickname made public anew gets new keys, except a nickname its owner takes back within its hold (below), which keeps its owner_token.
Record (exactly 1494 B, the size of a letter).
record = nonce 12 | AEAD(K_rec, nonce, body (1466 B), associated data = lookup_id) | tag 16
body   = u8 rec_layout = 1 | kbox_id 32 | xk_pk 1216 | zero padding
The record is sealed once, with a random nonce, and every renewal sends the same bytes. A finder accepts it only if it is exactly 1494 bytes, the tag verifies before any byte is read, the layout is 1, the padding is zero and xk_pk is an X-Wing public key whose ML-KEM part passes the FIPS 203 §7.2 check; anything else is "not found". The tag proves only that the record was sealed by someone who knows the nickname, since K_rec comes from the nickname alone. It keeps the server, and everyone who does not know the nickname, from changing a record or moving it to another lookup_id. It cannot tell the owner's record from one made by someone else who knows the nickname, the server included; against that, the voice checks of 5.5 are the defence, as against whoever carries an invitation.
Knock letter (exactly 1494 B).
letter = u8 kl_version = 2 | enc 1120 (X-Wing ciphertext) | sealed knock 357 | tag 16
         HPKE base mode, X-Wing / HKDF-SHA256 / AES-256-GCM, recipient key xk_pk,
         info = "aleteo/nick/knock/v1", aad = kl_version || kbox_id || lookup_id (65 B)
knock  = u8 name_len (0..32) | name 32 | inv 16 | u64 made_at | zero padding
inv is a new invitation of 5.7 that the finder made for this knock, and made_at the time it was made. The owner opens a letter only with xk of the box it came from, and the associated data binds the letter to that box and to the nickname it was knocked on: whoever has read a record may publish its kbox_id and xk_pk under a nickname of their own, and a letter sealed through that record fails the tag in the owner's box. No byte of the knock is read before the tag verifies, and a letter of version 1 is deleted. A letter that fails is deleted from the box and gives nothing. A letter already taken, one whose inv this phone already holds (its owner's own knock, or a repeat) and one whose invitation has expired (24 hours after made_at, with ten minutes for clocks) give no card. HPKE with X-Wing is used because the two phones share no key before the knock, and the letter may wait on the server for a day, so the name and inv are sealed against a later quantum computer, as the notification address is (11.1). Base mode authenticates no sender, and none is wanted: the knocker is a stranger until the voice checks.
Steps.
  • Publishing. The phone computes s, lookup_id and K_rec, draws the owner's keys, seals the record and stores all of it in its encrypted storage (12.3) before PUBLISH leaves (10.5), so that a stop after the server stored the record still holds the token that removes it. A nickname another owner holds is refused, and the person picks other digits.
  • Keeping. At entries of the messenger, the phone renews the record about once a day and reads the knock box, each at a random moment after the way to the server opens and each on a Tor circuit of its own. Nothing wakes the owner for a knock: the owner sees it on entering. A record not renewed for 30 days ends; its nickname is then held 30 days, for its owner's token alone, and is then free.
  • Knocking. The finder types the nickname. The phone computes lookup_id and K_rec, sends LOOKUP, reads the record, makes an ordinary invitation of 5.7, seals the knock letter and sends it by KNOCK, the search and the knock each on a new Tor circuit. For 24 hours after a knock the finder's phone keeps only its time and the first 8 bytes of its lookup_id, nothing else of the nickname, so that one phone knocks on one nickname at most once in 24 hours; in all it sends at most 30 knocks in 24 hours. These limits bind an honest app; the server has limits of its own (10.5). The invitation lives its usual 24 hours.
  • Answering. The owner sees a card with the name the finder sent and may accept, decline or report it. Accepting enters inv as if its 12 words had been typed (5.7): the owner's phone knocks on the finder's temporary onion service, M1 to H3 run with the finder as initiator, and the two people compare words in a call. Declining sends nothing, and the finder's invitation expires.
  • Pausing and leaving. "Stop accepting knocks" pauses the reading of the box for an hour, 8 hours, a day or until the person turns it back on: the phone shows no card and sends nothing to the box, while the record stays published and is renewed, so nobody takes the nickname meanwhile; knocks that expire during the pause are lost. While the setting that allows pairing only in person is on, the phone neither searches nor reads the box, removes the record by UNPUBLISH and keeps its keys; when the setting is turned off, the same record is published again. Making the nickname private, or changing it, first reads the box once more if the server can be reached, then removes the record; the old nickname is held for 30 days, so its owner can take it back. Wiping the phone sends nothing; the record then ends at its time.
6. Inner layer: post-quantum ratchet
Two ratchets run side by side, as in Signal's Triple Ratchet: a Double Ratchet over X25519 and a periodic ML-KEM-768 epoch ratchet. Every message key mixes both.
6.1 State per contact
role; AD = H("aleteo/inner/ad/v1" || th); the Double Ratchet state RK, DHs, DHr, CKs, CKr, Ns, Nr, PN; the epoch state e, E_cur, E_prev, and on the phone that proposed the next epoch its ML-KEM private key; a status, active or broken.
6.2 Initialisation
Initiator: DHs = (dr_sk_I, dr_pub_I); DHr = dr_pub_R; (RK, CKs) = KDF_RK(RK0, DH(dr_sk_I, dr_pub_R))
Responder: DHs = (dr_sk_R, dr_pub_R); DHr = none;     RK = RK0
e = 0; E_cur = E0
6.3 Ratchet functions
KDF_RK(rk, dh_out) = split( HKDF(salt = rk, ikm = dh_out, info = "aleteo/inner/rk/v1", L = 64) ) → (rk', ck)
KDF_CK(ck)         = (ck' = HMAC(ck, 0x02), mk = HMAC(ck, 0x01))
DH(a, B)           = X25519; an all-zero output is rejected
Sending, receiving and the DH ratchet step follow the Signal Double Ratchet specification. A new X25519 key is generated at every DH step.
6.4 Message encryption
k_enc      = HKDF(salt = E_epoch, ikm = mk, info = "aleteo/inner/mk/v1" || u32(epoch))
nonce      = 12 random bytes, new for every message
AAD        = AD || u8(sender_role) || header
ciphertext = AEAD(k_enc, nonce, inner plaintext (1280 B), AAD)                 → 1296 B

header (45 B)         = u8 version = 1 | u32 epoch | dh 32 | u32 pn | u32 n
inner message (1353 B) = header || nonce || ciphertext
E_epoch is the epoch secret the header names. As in Signal's hybrid key derivation, the post-quantum secret is the HKDF salt and the Double Ratchet key is the input. Each mk and k_enc encrypts once and is erased; in the code k_enc is a one-time type that cannot encrypt twice.
6.5 Inner plaintext (always 1280 B)
u8 type | u8 lifetime | u16 content_len | msg_id 16 (random) | u64 compose_time | content (≤ 1252 B) | zero padding
Types: TEXT, REPLY, EDIT, SETTINGS (message lifetime), READ, SCREENSHOT, DELETE, CLEAR, TALK, NAME, ONLINE, NO_COPY, WAKE (section 11), TYPES (which types a phone reads), PQ_PK and PQ_CT (6.6), and HELLO, HELLO_ACK, WORDS_OK during pairing only. Messages are plain text: there are no attachments, links or formatting. Text must be valid UTF-8 of Unicode 15.1, in NFC, without control characters other than line feed, without U+2028 and U+2029, and without bidirectional formatting characters. A plaintext that breaks any rule, including non-zero padding, is rejected after decryption and the state stays as it was. Types 0x40–0x7F are reserved for hints a phone may ignore: one it does not know is accepted and ignored.
6.6 Post-quantum epochs
  • The proposer of epoch e+1 is the phone with role = e mod 2. It proposes when 3600 seconds have passed since the epoch began or 50 messages were sent or received in it: it generates an ML-KEM-768 key pair and sends PQ_PK(e+1, encapsulation key, 1184 B).
  • The responder checks the key (FIPS 203 §7.2), encapsulates, and derives E_next = HKDF(salt = E_cur, ikm = ss, info = "aleteo/inner/pq-epoch/v1" || u32(e+1) || H(pk) || H(ct)). It sends PQ_CT(e+1, ciphertext, 1088 B) as its next message, then moves to epoch e+1.
  • The proposer decapsulates, derives the same E_next and moves to e+1. Private keys and shared secrets are erased.
  • A message must name epoch e or e−1; E_prev is erased when the first message of the new epoch arrives from the peer.
  • PQ_PK and PQ_CT are sent until acknowledged. An epoch advances while the pair exchanges messages.
6.7 Skipped keys and failures
Delivery is in order (section 8), so keys are skipped only after a message expired undelivered. Skipped keys are derived to advance the chain and erased at once; none is stored, and the number skipped at once is bounded. Every received message is decrypted on a copy of the state, and the state is written only after both end-to-end layers and the plaintext checks succeed. After three consecutive failures the contact is marked broken: sending stops and the people must pair again. There is no automatic reset.
6.8 Differences from Signal
  1. The initiator's first ratchet key is announced in the committed pairing body.
  2. The post-quantum ratchet is a simple alternating exchange of whole ML-KEM keys and ciphertexts, not SPQR's chunked exchange: an inner message holds a whole key, and delivery is reliable and in order.
  3. AES-256-GCM with a random nonce carried in the message.
  4. The inner header is not encrypted by the inner layer; it travels inside Olm and inside the frame layer.
  5. No store of skipped message keys.
7. Outer layer: Olm
  • vodozemac 0.11.1, unmodified, with session configuration version 1 (the configuration compatible with libolm). One Account per contact, used only during pairing; one Session per contact.
  • Olm encrypts the 1353-byte inner message; a normal Olm message is at most 1412 bytes.
  • The Olm session is stored only inside Altbook's encrypted storage (section 12); vodozemac's own pickle encryption is not used.
  • Olm keys come from vodozemac and the operating system's generator; they are never derived from, or mixed with, a key of the inner layer.
8. Frame layer
8.1 Keys
FK_r,0   = see 5.6
FK_r,j+1 = HKDF(salt = Z32, ikm = FK_r,j, info = "aleteo/frame/next/v1" || u8(r) || u64(j+1))
block j  = frame_counter >> 16
A phone encrypts with the key of its own role and decrypts with the peer's. The key moves forward every 65 536 frames and the old key is erased, so this layer has forward secrecy; healing after a compromise is the job of the end-to-end layers.
8.2 Layout (every frame is exactly 1494 B, three Tor cell payloads)
u8 frame_version = 1 | 3 B zero | u64 frame_counter       12-byte clear header, the associated data
1466 B ciphertext of the body | 16 B tag
nonce = u32(0) || u64(frame_counter)

body (1466 B) = u8 kind (0 cover, 1 data, 2 tombstone) | u8 flags = 0 | u8 olm_type | u8 0
              | u64 seq | u64 ack | u16 olm_len | Olm message | zero padding
The counter only grows and is reserved on disk before use, so a nonce is never reused. A receiver checks the size, the version, that the counter is above the last accepted one and within a bounded window, then the tag; no byte of the body is read before the tag verifies, and the body is then parsed at fixed offsets.
8.3 Delivery
Each message gets the next seq of its direction when it is encrypted. The receiver takes messages in seq order, and every frame acknowledges the highest seq received in order. Unacknowledged messages are resent from their stored Olm bytes in new frames, so a message is encrypted only once. When an undelivered message expires, the sender erases it and sends a tombstone for its seq. Tombstones and acknowledgements are authenticated by the frame layer only.
8.4 Cover frames
While a link between the two phones is up, which needs the messenger open on both, each phone sends frames on an even time grid that starts with the link: in each slot a data frame when a message waits, otherwise a cover frame. Frames are built ahead of their slot, so the time a frame leaves does not depend on its kind. Without the frame key, cover and data frames cannot be told apart.
9. Transports
9.1 Tor
Each phone runs one Tor v3 onion service per contact, with client authorization, so that only that contact can fetch the service descriptor. The address of a service is computed from onion_pub (Tor rend-spec-v3), and the client authorization keys travel in the pairing bodies, so they are covered by the check words. The app hands these keys to tor at run time through its control interface; tor never stores them, and the services are removed when the messenger closes. Tor may connect through bridges.
9.2 Nearby
Over Bluetooth LE (an L2CAP channel) or peer-to-peer Wi-Fi, frames run inside TLS 1.2 with TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256, pre-shared key NPSK and PSK identity 0x01; no other suite is accepted. The TLS key exchange is not post-quantum; the frame and inner layers are. A paired phone is found by names that change over time:
Wi-Fi service name   = base32( HMAC(ND, u64(floor(unix_time / 600)))[0..16] )
Bluetooth service UUID = HMAC(ND, "aleteo/nearby/bluetooth/v1" || u64(floor(unix_time / 900)))[0..16]
10. Mailbox server
The mailbox server keeps encrypted letters until the recipient fetches them, so a sender may close the app. It is not trusted: it has no key of any letter. The same server keeps the directory of public nicknames and their knock boxes (10.5).
10.1 Boxes and keys
R_mb       = HKDF(salt = Z32, ikm = ND,   info = "aleteo/mailbox/root/v1")
d          = floor(unix_time / 86400)                                    day, UTC
token(w,d) = HKDF(salt = Z32, ikm = R_mb, info = "aleteo/mailbox/token/v1"  || u8(w) || u64(d))
K_L(w,d)   = HKDF(salt = Z32, ikm = R_mb, info = "aleteo/mailbox/letter/v1" || u8(w) || u64(d))
box_id     = H("aleteo/mailbox/box/v1" || token)
w is the writer's role, so a pair has two boxes a day, one per direction, and both addresses change every day. Whoever presents token may put, read and delete letters of box box_id; the server keeps only box_id.
10.2 Letter (exactly 1494 B)
nonce 12 | AEAD(K_L(w, d), nonce, frame body (1466 B, as 8.2), associated data = box_id) | tag 16
A letter carries the same stored Olm bytes as a frame would, so a message is still encrypted once, and whichever path delivers first counts. A message leaves the sender's phone only when the recipient acknowledges it; a letter the server loses, delays, repeats or reorders costs delay only.
10.3 Requests
The phone reaches the server through Tor, with a separate Tor circuit for each box. Every request and every answer is exactly 1992 bytes:
request = u8 version = 1 | u8 op (1 put, 2 get, 3 delete) | token 32 | u8 index | letter_id 16 | letter 1494 | zero padding
answer  = u8 status | u8 count | letter_id 16 | letter 1494 | zero padding
letter_id = first 16 bytes of H(letter)
10.4 What the server sees
It sees, for each letter, its box_id, the hour it expires and 1494 random-looking bytes; while it runs, the token of each request it handles, which box is used and when, and how many letters each box holds. It does not see who writes or reads (requests come through Tor and carry nothing of the phone), what a letter holds or whether it is a text, a control message or an acknowledgement. Letters are deleted when the recipient deletes them after reading, or when they expire after about a week.
10.5 Directory and knock boxes
The public nickname (5.8) uses the same server program behind the same onion service, with requests of version 2 beside those of version 1 (10.3). It has two stores of its own: the directory, sealed records under their lookup_id, and the knock boxes, knock letters under their kbox_id. They share no key and no file with the mailbox, and a knock box is never a box of 10.1.
request (1992 B) = u8 version = 2 | u8 op | id 32 | owner_token 32 | u8 index | letter_id 16 | body 1494 | zero padding
  op 4 PUBLISH     id = lookup_id   owner_token   body = the record
  op 5 UNPUBLISH   id = lookup_id   owner_token
  op 6 LOOKUP      id = lookup_id
  op 7 KNOCK       id = kbox_id                   body = the knock letter
  op 8 KGET        id = ktoken      index
  op 9 KDEL        id = ktoken      letter_id
answer  (1992 B) = u8 status (0 done, 2 later, 3 refused, 4 taken) | u8 count | letter_id 16 | body 1494 | zero padding
owner_hash = H("aleteo/nick/owner/v1" || owner_token)
letter_id  = first 16 bytes of H(body), of a record as of a letter
Every field an op does not use is zero, and the server refuses a request otherwise. It keeps owner_hash, never the token, compares it only in constant time, computes kbox_id from ktoken and erases the token. A PUBLISH under a lookup_id that another owner_hash holds answers "taken" and changes nothing. An UNPUBLISH answers "done" whatever it finds, and a LOOKUP of a nickname that is held finds nothing, so neither tells whether a nickname is taken; only a PUBLISH does. Anyone who has read a record may knock on its box; only the holder of ktoken reads and deletes. A knock letter lives at most 26 hours (25 hours, rounded up to the hour), enough for an invitation of 24 hours. A knock box takes at most 5 different letters an hour and 15 a UTC day; a letter past these limits is answered "later", and a full box stores nothing more. During a flood the operator can switch version 2 off without a restart: every request of version 2 is then answered "refused", and the phone offers no search or knock until its next entry. A record changed on disk is written into a free place before its old place is cleared, so a crash keeps the last answered version.
The server sees, on disk, for each public or held nickname its lookup_id (an Argon2id fingerprint, 5.8), the hour it ends, whether it is live or held, its owner_hash and its sealed record; for each knock box its kbox_id and its letters, each with the hour it expires. While it runs, it sees the id and the token of each request it handles, and which record is published, renewed, removed or looked up and which box is knocked on, read or emptied, and when. It does not see a nickname, unless it guesses one at the cost of one Argon2id per guess; who asks, because requests come through Tor and carry nothing of the phone; what a letter says; or which knock box belongs to which record, because kbox_id lies inside the sealed record, except by timing. A server that knows a nickname reads its record as anyone can, and may serve a record of its own under it and receive the knocks of whoever looks it up; it still gets no contact without the two voice checks (5.5).
11. Wake server
When the recipient's messenger is closed, a contact whose message waits can ask a wake server to make the recipient's phone show a notification. The notification looks like an ordinary reminder and carries nothing of the message.
11.1 Sealed notification address
The recipient seals its Apple push token for the server's X-Wing public key pk_W:
record (80 B) = u8 env | u8 notification text index | u64 not_after | u8 token_len | token 64 | u8 interval | 4 B zero
blob (1219 B) = u8 wake_version = 1 | u16 key_id = first 2 bytes of H(pk_W) | enc 1120 (X-Wing ciphertext) | sealed record 80 | tag 16
HPKE base mode, X-Wing / HKDF-SHA256 / AES-256-GCM, info = "aleteo/wake/blob/v1", aad = the first 3 bytes of the blob
A token longer than 64 bytes uses version 2 of the record (112 B) and of the blob (1251 B). The recipient seals a separate blob for each contact, valid for 30 days, and gives it to that contact inside the end-to-end layers (inner type WAKE). Two contacts cannot tell from their blobs that they belong to one phone. X-Wing is used because the blob travels over Tor, whose key exchange is not post-quantum.
11.2 A wake request
The sender opens a Tor stream to the server and sends 1494 bytes: a version byte, the blob, zero padding. The server opens the blob, checks it strictly, sends Apple one push with no content from the message, answers with one status byte, and erases the token once the push has gone.
11.3 What the server and Apple see
The server learns the push token while it handles a request and keeps it, in memory only, until the push has gone; it counts the signals of each token in memory under a keyed hash whose key is new at each start; it does not learn who sent a signal, because the sender comes through Tor and a signal is the same for every contact. Apple sees when a notification goes to which device and can link a device to an Apple ID. A phone with message notifications switched off issues no blob.
12. Storage on the phone
12.1 Files
All files of the private part are in the app container under iOS Data Protection class Complete (readable only while the phone is unlocked) and are excluded from backups. The one exception is the file of texts the person chose for notifications, which must be readable on a locked phone. Apart from that file and a few small files of settings and counters that must be read before any code is typed, which hold no text, no contact and no key, every byte written is ciphertext, random filler, a public value or a clear header field such as a format version or the Argon2id parameters.
12.2 Master key and the vault
A random 32-byte master key MK protects the messenger's data. Each private notebook and the private calendar either has a random key of its own or uses MK. These keys are kept in one fixed-size file, the vault, in sealed slots:
  • Without a code (the default). One slot is sealed under a key bound to this phone's Secure Enclave: `` SE_o = Secure Enclave P-256 key (usable only while unlocked, this device only) eph = new software P-256 key; s = ECDH(eph, SE_o.pub); eph erased KEK_open = HKDF(salt = Z32, ikm = s, info = "aleteo/store/kek-open/v1" || eph.pub || SE_o.pub) slot = eph.pub 65 | nonce 12 | AEAD(KEK_open, nonce, keys, "aleteo/store/vault-open/v2" || header) `` Opening repeats the agreement inside the Secure Enclave, so a copy of the files is useless on another phone. In private mode this slot holds random bytes, and every part opens only with a code.
  • With an access code. Each code has its own slot, sealed under a key that needs both the code and this phone's Secure Enclave: `` a = Argon2id(code, salt, t = 3, m = 64 MiB, p = 1) x_0 = HKDF(salt = Z32, ikm = a, info = "aleteo/store/se-chain/v1" || u16(0)) for j = 1 .. N: Q_j = the P-256 point with even y and x-coordinate HKDF(salt = Z32, ikm = x_(j−1), info = "aleteo/store/se-point/v1" || u16(j) || u8(i)) for the first i that gives a point s_j = ECDH(SE_c, Q_j) computed by this phone's Secure Enclave x_j = HKDF(salt = Z32, ikm = s_j || x_(j−1), info = "aleteo/store/se-chain/v1" || u16(j)) KEK(code) = HKDF(salt = a, ikm = x_N, info = "aleteo/store/kek/v2") slot = nonce 12 | AEAD(KEK(code), nonce, keys of the parts this code opens, "aleteo/store/vault-door/v1" || header fields) ` Nobody knows the discrete logarithm of Q_j`, so a step cannot be computed without the enclave key, and each step depends on the one before. Every guess of a code therefore costs one Argon2id and N sequential Secure Enclave operations on this phone while it is unlocked. N is measured on the phone when the vault is made and kept, with the salt and the Argon2id parameters, in the vault's clear header. No code is stored anywhere: a code is checked by deriving its key and trying the slots. Slots not in use hold random bytes, so the file does not show how many codes exist.
12.3 Keys of the stored data
K_contact = HKDF(salt = Z32, ikm = MK, info = "aleteo/store/contact/v1")      contact state: ratchet, Olm session, keys
K_wrap    = HKDF(salt = Z32, ikm = K_part, info = label of the space)
            labels: "aleteo/store/bucket-wrap/v1", "aleteo/store/chat-wrap/v1",
                    "aleteo/store/notebook-wrap/v1" || u8(n), "aleteo/store/calendar-wrap/v1"
BK_h      = 32 random bytes per expiry hour h;    file = nonce | AEAD(K_wrap, nonce, BK_h, "b" || u64(h))
record    = nonce_w | AEAD(BK_h, nonce_w, K_m, "w" || rid) | nonce_r | AEAD(K_m, nonce_r, record 1408 B, "r" || rid)
            K_m = 32 random bytes, new at every write
The files of notifications and of the mailbox have keys of their own derived from MK the same way. A public nickname, its keys, the cards of knocks waiting for an answer and the list of letters already taken are kept in one file sealed under K_contact, of the same size as a contact's file, so the storage does not show whether the messenger has a public nickname. Every record has the same size, whatever it holds. Deleting a message deletes its file, the only copy of its K_m; when an hour of expiry passes, its BK_h is deleted first, which makes every remaining copy of that hour's records unreadable.
12.4 Memory
Keys and decrypted text are kept in buffers that are wiped when released. When the app goes to the background or the phone locks, the private part closes and its keys leave memory; entering again derives them again.
13. Security properties and limits
Protected:
  • Message text against the network, Tor relays and bridges, both servers, Apple, and a thief of the locked phone.
  • Against recording now and decrypting later with a quantum computer: pairing uses X-Wing, the inner ratchet adds an ML-KEM-768 step after an hour or 50 messages while the pair exchanges messages, and the notification address is sealed with X-Wing.
  • Forward secrecy and recovery after a one-time compromise of a phone's state: classically after a Double Ratchet step, post-quantum after an epoch, against an attacker who does not stay active after the compromise.
  • Integrity: every modified, replayed or foreign frame is rejected before parsing.
  • Length: every frame, letter, request and stored record has a fixed size.
  • A private nickname, the default, sends nothing to any server. The server stores no nickname, can open no knock letter, and without the nickname no record; a knock becomes a contact only through an ordinary invitation and both voice checks.
Not protected, or only partly:
  • A phone fully compromised by spyware with system rights sees the screen and the keyboard.
  • The contact: a modified app on the other phone can keep what it receives.
  • Authentication rests on the people comparing words. A person who picks a set at random without comparing passes an attack with probability 1/4 per check. A phone whose check is switched off (5.5) does not authenticate the other phone at all.
  • Metadata: the servers see timing and counts of their own traffic, and timing can link boxes while few people use the service. Apple sees when notifications go to a device and can link the device to an Apple ID. Tor hides addresses, not timing, from an observer who sees both ends.
  • The frame and letter keys are transport keys: whoever obtains them can forge acknowledgements and tombstones (denial of service), never read text.
  • Flash storage and the iOS Keychain may keep old blocks that the app cannot overwrite.
  • Timing side channels at processor level are not ruled out; we use constant-time library functions.
  • X-Wing is still an IETF draft; CryptoKit implements draft-connolly-cfrg-xwing-kem-06.
  • A public nickname is public: whoever types it whole learns that it is public now and can knock, and can fill its knock box with 5 letters an hour and 15 a day, after which further knocks, honest ones included, are refused for that hour or day. Whoever holds the server's disk learns every nickname whose base it guesses: the fingerprint hides the list, not a guessed name, and a known base with all its digits costs 111 100 Argon2id runs, minutes on one large graphics card (an estimate). The server, or anyone who knows a nickname, can serve a record of its own and receive the knocks meant for the owner; the voice checks keep it from becoming a contact. While few people use the server, it may guess by timing whose records and knock boxes they are. A nickname stays findable for up to 30 days after its owner last renewed it, a wiped phone included, and is then held 30 days more. A knock waits for the owner's entry and the finder's invitation lives 24 hours, so an owner who enters less than once a day may miss a knock; the finder may knock again a day later.
14. References
  • RFC 5869 (HKDF), RFC 7748 (X25519), RFC 8032 (Ed25519), RFC 9106 (Argon2), RFC 9180 (HPKE), RFC 7905 (ChaCha20-Poly1305 for TLS).
  • FIPS 203 (ML-KEM). NIST SP 800-38D (GCM).
  • draft-connolly-cfrg-xwing-kem-06 (X-Wing). draft-ietf-hpke-pq (post-quantum HPKE, KEM 0x647a).
  • The Signal Double Ratchet specification, revision 4; Signal's PQXDH and Triple Ratchet (SPQR) documents.
  • The Olm specification (Matrix) and vodozemac.
  • Tor rend-spec-v3 (onion services v3, client authorization).


Revision 2, 2 December 2026.
Author: Maksim Timofeev.