Keysets
A keyset is what an application loads: one purpose, one or more keys, exactly one primary. It is how pqlock rotates keys and changes algorithms without code changes.
01Purposes
| Purpose | Used by | PQL-DEFAULT key |
|---|---|---|
seal | seal, open, seal_batch, stream, rotate | X-Wing seed, 32 B secret, 1,216 B public |
sign | sign, verify, audit | ML-DSA-65 + Ed25519, 64 B secret, 1,984 B public |
token | tokens.issue, tokens.check | ML-DSA-65, 32 B secret, 1,952 B public |
Every operation checks the purpose before touching key material, so a token keyset passed to seal is an error. The purpose is also mixed into the key id, so the same public bytes under two purposes never share an id.
02Key status
| Status | Seal, sign, issue | Open, verify, check |
|---|---|---|
primary | Yes, exactly one per keyset | Yes |
active | No | Yes |
retired | No | Yes, so old data stays readable |
create makes a keyset with one primary key. add adds an active key. promote makes a key primary and demotes the old primary to active. retire stops a key from being used for new data. The primary cannot be retired; promote another key first. Removing a key from the file is the only way to stop it opening old data.
let ks = keyset.load(privateJson);
ks = keyset.add(ks, { suite: 'PQL-DEFAULT' }); // new active key
const newKid = ks.keys.at(-1)!.kid; // its id
ks = keyset.promote(ks, newKid); // new data uses it
ks = keyset.retire(ks, oldKid); // still opens old dataks = keyset.load(private_json)
ks = keyset.add(ks, suite="PQL-DEFAULT")
ks = keyset.promote(ks, new_kid)
ks = keyset.retire(ks, old_kid)ks, _ = keyset.Add(ks, keyset.WithSuite(keyset.SuiteDefault))
ks, _ = keyset.Promote(ks, newKid)
ks, _ = keyset.Retire(ks, oldKid)add without a suite creates a PQL-DEFAULT key in every SDK, even on a PQL-HIGH keyset. Promoting that key would move new data down to PQL-DEFAULT.
03Key ids
A key id is 8 bytes: the first 8 bytes of SHA-256("PQL1 kid" || suite id || purpose code || public key). It appears as lowercase hex in keyset files and as base64url in token headers. Key ids are identifiers, not secrets. Every envelope and signature carries the key id, which is how open finds the right key after a rotation.
04File format
{
"pql_keyset": 0,
"purpose": "seal",
"keys": [
{ "kid": "9c1f…", "suite": "PQL-DEFAULT", "status": "primary",
"public": "…base64url…", "secret": "…base64url, private file only…" }
]
}The normative format is spec/keyset.md. Parsers are strict: unknown fields, non-canonical base64url and wrong lengths are rejected.
05Where keysets live
- Private keysets go in a secret manager or an environment secret. Never commit them; the repository's
.gitignorealready excludes*.key,*.pemand.env. - Public keysets can ship with the services that only encrypt or verify, so those services never hold a secret.
- Authenticity of a public keyset is the application's job. A sender that loads an attacker's public keyset seals data to the attacker.
pqlock v0.1.0 · unaudited preview · source of truth: spec/