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
| Offset | Size | Field | Value |
|---|---|---|---|
0 | 4 | magic | ASCII PQL1 |
4 | 1 | version | 0x00 |
5 | 2 | suite id | 0x0001 DEFAULT, 0x0002 HIGH, 0x0003 CNSA |
7 | 8 | key id | kid of the recipient seal key |
15 | 1,120 | KEM ciphertext | ML-KEM-768 (1,088) + X25519 ephemeral key (32) |
1135 | 12 | nonce | AES-256-GCM nonce |
1147 | n + 16 | AEAD | AES-256-GCM ciphertext and tag |
1163 + n | 32 | commitment | key 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 || commitmentThe 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
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
| Prefix | What | Encoding |
|---|---|---|
pql1. | Sealed envelope | base64url, no padding |
pqlg. | Signature | base64url, no padding |
pqlr. | Reference cookie for a token | base64url 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/