Skip to content

Formats and errors

pk1.<kid>.<key> public key
pq1.<kid>.<enc>.<ct> sealed message

All parts in Base64URL without padding, kid is 8 bytes long. The prefixes carry the format version. A public key has about 1.6 KiB, a message at least about 1.9 KiB.

  • HPKE info: pq-seal v1
  • Additional data: pq1|<kid>|<context>
  • Plaintext before encrypting: 4 bytes of length (big endian), the data, then zeros up to the next multiple of 256 bytes

testdata/vectors.json pins the format.

sp1.<key> public key, 2,607 characters
sg1.<signature> signature, 4,416 characters
wk1.<memory>.<passes>.<salt>.<box> private key under a passphrase, 131 characters
wk1.<memory>.<passes>.<salt> its header, 34 characters
wa1.<value> proof of the passphrase (auth), 47 characters

memory (in KiB) and passes are decimal numbers in their only spelling, everything else is Base64URL without padding.

  • Signature: ML-DSA-65 (FIPS 204), the context is the context of ML-DSA, 1 to 255 bytes
  • Derivation: Argon2id with a 16-byte salt, at least 64 MiB and 3 passes, one lane. From it with HKDF-SHA256 the wrapping key (pqsign wrap v1) and auth (pqsign auth v1)
  • Box: a 24-byte nonce, then the 32-byte seed under XChaCha20-Poly1305, bound to the header

The Go test TestKnownAnswer and the browser test e2e/sign.spec.js pin the format with the same key.

Errors when opening do not say what is wrong with the content and never quote it. In Go they are the values in the table, in the browser a SealError with code. The status is a suggestion by pqhttp.ErrorStatus.

GocodeHTTPMeaning
ErrUnknownKeyunknown_key409Key rotated or restart, seal again
ErrReplayreplay409Message was already opened
ErrVersionbad_version400Unknown format version
ErrOpenFailedopen_failed400Damaged, altered, wrong context or invalid JSON
ErrBadKeybad_key400Public key invalid
ErrContextbad_context400Context is empty
ErrTooLargetoo_large413Larger than MaxBytes
ErrClosedclosed503Sealer or client is closed
load_failedBrowser only: files or key cannot be loaded
worker_failedBrowser only: worker crashed or does not answer, connect again
internal500Unexpected error

In Go they come from pqsign, in the browser it is the same SealError.

GocodeMeaning
ErrBadSignaturebad_signatureSignature malformed, or it does not belong to key, message and context
ErrUnlockFailedunlock_failedWrong passphrase, or the wrapped key is malformed or was altered
ErrParamsbad_paramsCost below the floor or above the limit
ErrPassphrasebad_passphrasePassphrase is empty
ErrBadKeybad_keyPublic key invalid
ErrContextbad_contextContext empty or longer than 255 bytes
ErrVersionbad_versionUnknown format version
no_keyBrowser only: the key was forgotten or the unlock is already used