HushNote message formats.

The complete, normative description of the sealed envelope, the key-locked message and their link forms: fields, encodings, key derivation, locking, opening, and what the formats do not provide.

Status: prototype, not reviewed Version 1 ML-KEM-768 · HKDF-SHA-256 · AES-256-GCM Download test vector (JSON)

v0.1.0Updated 2026-10-12

Two formats are defined here: the envelope, sealed for an ML-KEM-768 public key, and the key-locked message, locked with a key that people hand to each other.

Status: prototype formats. It uses post-quantum cryptography but has not been reviewed or audited. This document is the reference for src/crypto/ and for the independent implementation in tests/reference.ts, which is written from this text and checked against the app in the test suite.

A note on names: the product is called HushNote. It was first called LatticeLink and then LatLink, and the identifiers inside these formats (LatticeLink-envelope, LatticeLink-public-key and the labels that begin LatticeLink/v1) keep that spelling. They are part of version 1, and some of them are authenticated, so changing them would stop existing links from opening.

Algorithms

Role Algorithm Implementation
Key encapsulation ML-KEM-768 (NIST FIPS 203) @noble/post-quantum ml_kem768
Key derivation HKDF with SHA-256 (RFC 5869) WebCrypto HKDF
Authenticated encryption AES-256-GCM, 96-bit nonce, 128-bit tag (NIST SP 800-38D) WebCrypto AES-GCM
Fingerprint SHA-256 of the raw 1,184-byte public key WebCrypto SHA-256
Randomness crypto.getRandomValues (key seeds, ML-KEM message randomness, nonces) browser / OS CSPRNG

Public-key file

{
  "format": "LatticeLink-public-key",
  "v": 1,
  "kem": "ML-KEM-768",
  "fingerprint": "<64 lowercase hex: SHA-256 of the raw public key>",
  "public_key": "<unpadded base64url of the 1,184-byte ML-KEM-768 encapsulation key>"
}

On import, the reader:

  1. rejects unknown fields and any other format, v or kem;
  2. decodes public_key (canonical unpadded base64url only) and requires exactly 1,184 bytes;
  3. runs the FIPS 203 encapsulation-key checks (length and modulus) by performing a throwaway encapsulation;
  4. computes the fingerprint itself and rejects the file if a fingerprint field is present and differs.

These checks show that the bytes are a well-formed key. They do not show whose key it is. Only comparing the fingerprint with the intended recipient over a channel you already trust does that. A bare base64url key, without the JSON wrapper, is also accepted.

Envelope

{
  "format": "LatticeLink-envelope",
  "v": 1,
  "kem": "ML-KEM-768",
  "kdf": "HKDF-SHA-256",
  "aead": "AES-256-GCM",
  "recipient": "<64 lowercase hex: fingerprint of the recipient public key>",
  "kem_ct": "<base64url, 1,088 bytes>",
  "nonce": "<base64url, 12 bytes>",
  "ct": "<base64url, AES-GCM ciphertext followed by the 16-byte tag>"
}

All binary fields are canonical unpadded base64url (RFC 4648 §5). Writers emit the fields in the order shown.

Associated data

AAD = UTF-8( JSON.stringify([format, v, kem, kdf, aead, recipient, kem_ct, nonce]) )

This uses the exact field strings as they appear in the envelope (and the number 1 for v). Every field except ct is authenticated.

Key derivation

ss   = ML-KEM-768.Encaps(recipient_public_key)            // 32 bytes; sender side
info = UTF-8("LatticeLink/v1 message key") || 0x00 || recipient_fingerprint_bytes (32)
key  = HKDF-SHA-256(IKM = ss, salt = empty, info = info, L = 32)

Sealing (sender)

  1. Encode the message as UTF-8. Refuse text containing unpaired UTF-16 surrogates. The maximum is 65,536 bytes.
  2. Fingerprint the recipient public key.
  3. Encapsulate: this gives kem_ct (1,088 bytes) and ss (32 bytes).
  4. Draw a fresh 12-byte nonce from crypto.getRandomValues.
  5. Build the header, compute the AAD, derive key, and wipe ss.
  6. Set ct = AES-256-GCM-Encrypt(key, nonce, plaintext, AAD), which includes the tag.

Each message gets a fresh encapsulation, so every message has its own key. The random nonce is a second safeguard.

Opening (recipient)

  1. Parse strictly, before any cryptography. Reject input that is over 131,072 characters, is not JSON, or is not an object. Also reject unknown or missing fields, wrong types, any format/v/kem/kdf/aead other than the values above, a recipient that is not 64 lowercase hex characters, non-canonical base64url, kem_ct other than 1,088 bytes, nonce other than 12 bytes, and ct outside 16..65,552 bytes.
  2. Note whether recipient equals the fingerprint of the recipient's own key. Continue either way.
  3. Decapsulate kem_ct with the secret key. ML-KEM uses implicit rejection: a foreign or altered ciphertext yields an unrelated secret, not an error.
  4. Derive key using the envelope's own recipient field, then wipe ss.
  5. AES-256-GCM-Decrypt with the AAD rebuilt from the parsed header. If the tag fails, return authentication failed. WebCrypto releases no bytes on tag failure, so no partial plaintext can exist.
  6. If the tag verified but step 2 found a mismatch, refuse with recipient mismatch. This can only happen with a deliberately crafted envelope.
  7. Decode the plaintext as strict UTF-8.

Each of the two objects above also has a link form, so that a key or a message can be passed along as one address. The data sits in the URL fragment (the part after #), which browsers do not send to a web server.

personal link:  <site>/#to=1.<B>     B = base64url( public key, 1,184 bytes )
message link:   <site>/#msg=1.<B>    B = base64url( recipient (32) || kem_ct (1,088) || nonce (12) || ct (16 or more) )

1 is the link version. B is canonical unpadded base64url, and recipient is the 32 raw bytes of the fingerprint. Only the fragment carries meaning: a reader ignores the rest of the address, so links written for another path of the site (early builds used /message/) still open. The site itself calls these "your private link" and a "locked message".

A message link is a version 1 envelope with its five constant fields left out. A reader rebuilds the JSON envelope (format, v, kem, kdf and aead as given above, recipient as lowercase hex, and kem_ct, nonce and ct as base64url) and then follows Opening unchanged. Each encoding is canonical, so the rebuilt envelope is character for character the one the sender sealed. The associated data is therefore the same, and every byte of B is authenticated.

A reader:

  1. accepts a whole address, a bare fragment, or text that contains one, and takes the data up to the first character outside the base64url alphabet;
  2. rejects input over 100,000 characters, any other link version, non-canonical base64url, a personal link that is not exactly 1,184 bytes, and a message link outside 1,148..66,684 bytes;
  3. checks the key in a personal link as it would a public-key file (steps 2 and 3 there).

Writers keep the message in a message link to 4,096 bytes, so that the link survives the apps that carry it. A link that was cut off is either rejected by these checks or fails authentication. It is never opened in part.

A personal link has the same limit as a public-key file: it shows a well-formed key, not whose key it is.

Key-locked messages

A key-locked message needs no public key. It is locked with a decryption key: 32 bytes from crypto.getRandomValues, which the sender gives to the reader by some other route than the message.

The key as text

The key is written in Crockford base32 (alphabet 0123456789ABCDEFGHJKMNPQRSTVWXYZ), most significant bit first. The 256 bits are padded with four zero bits to make 52 characters, written in thirteen groups of four joined by -. A reader ignores case, spaces and dashes, takes O as 0 and I or L as 1, and rejects anything that is not exactly 52 characters of the alphabet, or whose four padding bits are not zero.

Locking

salt  = 16 random bytes                    // fresh for every message
nonce = 12 random bytes
label = UTF-8("LatticeLink/v1 key-locked message")
k     = HKDF-SHA-256(IKM = key, salt = salt, info = label, L = 32)
ct    = AES-256-GCM-Encrypt(k, nonce, plaintext, AAD = label)   // includes the 16-byte tag

The message is UTF-8 text with no unpaired surrogates, as for an envelope. Because every message has its own salt, and so its own AES key, one decryption key can lock many messages.

key-locked link:  <site>/#kmsg=1.<B>    B = base64url( salt (16) || nonce (12) || ct (16 or more) )

The rules for links above apply. A reader rejects a key-locked link outside 44..65,580 bytes. The key is never part of the link.

Unlocking

  1. Read the link and the key as above. Reject either if it is malformed.
  2. Derive k from the key and the link's salt, and AES-256-GCM-Decrypt with the link's nonce and the label as AAD.
  3. If the tag fails, return authentication failed. A wrong key and an altered message are deliberately indistinguishable. WebCrypto releases no bytes on tag failure, so no partial plaintext can exist.
  4. Decode the plaintext as strict UTF-8.

Two locks

The text of an envelope may itself be exactly one key-locked fragment (kmsg=1.<B> and nothing else). A reader that opens an envelope and finds such a text does not show it: it asks for the decryption key and unlocks the fragment as above. The reader then needs both the recipient's secret key and the decryption key.

Test vector

tests/vectors/envelope-v1.json contains an envelope sealed to a key derived from a published seed (so it protects nothing). It also lists the fixed ML-KEM message randomness and nonce, so the envelope can be reproduced byte for byte. The fields personal_link and message_link give the link forms of that key and that envelope, as fragments. The fields decryption_key and key_locked_message give a key-locked message of the same text, with a published key (so it protects nothing either). Regenerate the file with npm run vector.

What the format does not provide

  • Sender authentication. Anyone with the recipient's public key can produce a valid envelope.
  • Replay protection, ordering, or forward secrecy beyond the per-message encapsulation. A compromised recipient secret key opens every envelope ever sealed to it.
  • Hiding message length. Ciphertext length equals plaintext length plus 16 bytes.
  • Hiding the recipient. The recipient field names the key the envelope was sealed for.
  • Any protection once a decryption key and its link are in the same hands. A key-locked message is only as private as the route its key took. It does not use ML-KEM: its strength is that of AES-256 with a 256-bit random key.