Docs / Concepts

Envelope format

A PQL1 envelope describes itself: suite, recipient key and KEM ciphertext travel with the data. All three SDKs produce and accept exactly the same bytes.

01Layout

Exploded stack of PQL1 envelope fields with offsets and sizes.
OffsetSizeFieldValue
04magicASCII PQL1
41version0x00
52suite id0x0001 DEFAULT, 0x0002 HIGH, 0x0003 CNSA
78key idkid of the recipient seal key
151,120KEM ciphertextML-KEM-768 (1,088) + X25519 ephemeral key (32)
113512nonceAES-256-GCM nonce
1147n + 16AEADAES-256-GCM ciphertext and tag
1163 + n32commitmentkey commitment

02How seal works

(ct_kem, ss) = X-Wing.Encaps(recipient public key)
header       = "PQL1" || 0x00 || suite || kid || ct_kem || nonce
th           = SHA-256(header)
dek          = HKDF-SHA256(ss, salt "PQL1 v0 seal", info "PQL1 dek"    || th)
commitment   = HKDF-SHA256(ss, salt "PQL1 v0 seal", info "PQL1 commit" || th)
aead         = AES-256-GCM(dek, nonce, aad = header, plaintext)
envelope     = header || aead || commitment

The header is bound twice: as AES-GCM associated data and through the key schedule. The commitment makes the envelope key-committing, so a ciphertext cannot be crafted to open under two different keys.

03How open fails closed

Seven checks in order, each failing into a single error with no plaintext.

Open checks length, magic and version, suite, key id, then decapsulates, compares the commitment in constant time, and only then decrypts. Any failure returns one error type with no hint about which step failed and no partial plaintext.

04Text forms

PrefixWhatEncoding
pql1.Sealed envelopebase64url, no padding
pqlg.Signaturebase64url, no padding
pqlr.Reference cookie for a tokenbase64url of 32 random bytes

05What an envelope reveals

The envelope length reveals the plaintext length, the key id identifies the recipient key and the suite is in clear. Pad the plaintext if length matters. Envelopes can be replayed; put a nonce or version in the plaintext if replay matters.

pqlock v0.1.0 · unaudited preview · source of truth: spec/