Signatures
Package pqsign and the same browser worker give a person a signing key that is protected by a passphrase. The server stores the key in encrypted form and checks signatures. It cannot sign: the private key is only open inside a browser’s worker.
Signing is independent of sealing. It has its own keys and formats.
| Server | Browser | |
|---|---|---|
| Create a key | pqsign.GenerateKey() | seal.generateSigningKey() |
| Sign | key.Sign(context, message) | key.sign(context, data) |
| Verify | pqsign.Verify(publicKey, context, message, signature) | seal.verify(publicKey, context, data, signature) |
| Put under a passphrase | key.Wrap(passphrase, pqsign.DefaultParams()) | key.wrap(passphrase) |
| Open | pqsign.Unwrap(wrapped, passphrase) | seal.unlockSigningKey(wrapped, passphrase) |
| Fingerprint | pqsign.Fingerprint(publicKey) | seal.fingerprint(publicKey) |
pqsign needs Go 1.27. The other packages keep working with Go 1.26.
How it fits together
Section titled “How it fits together”- Create. The browser creates the key pair in the worker and puts the private part under the passphrase. Three values go to the server: the public key,
wrappedandauth. - Store. The server keeps the public key,
wrappedand a hash ofauth, neverauthitself. - Unlock. A browser that needs the key fetches the header of
wrapped. The header holds only format, cost and salt and may be given to anyone. From header and passphrase the worker computesauth. The server compares the hash and only then hands outwrapped. - Sign and verify. The worker signs, the server verifies with the public key.
The detour over auth has a reason: without it, anyone who may fetch wrapped could try passphrases against it at home. With it, a stranger gets nothing to test against, and the server can count and limit attempts.
In the browser
Section titled “In the browser”// First time: create and store.const key = await seal.generateSigningKey();const { wrapped, auth } = await key.wrap(passphrase);await api.storeKey({ publicKey: key.publicKey, wrapped, auth });
// Later: unlock. The slow step runs once.const pending = await seal.prepareUnlock(await api.keyHeader(), passphrase);const key = await pending.open(await api.wrappedKey(pending.auth));
const signature = await key.signJSON('user/7/role', { user: 7, role: 'admin' });
// New passphrase: wrap again and replace both values on the server.const replaced = await key.wrap(newPassphrase);- The passphrase is normalized before it reaches the worker (Unicode NFKC). An
ütyped as one character or asuwith a combining mark is the same passphrase. pending.openandpending.canceluse the derivation up. A wrong passphrase ends withunlock_failed.key.forget()removes the private key from the worker, and so does closing the client or the tab.
On the server
Section titled “On the server”// Storing: keep publicKey, wrapped and a hash of auth.sum := sha256.Sum256([]byte(auth))
// Anyone who asks gets the header.header, err := pqsign.Header(wrapped)
// wrapped only for the right auth, compared in constant time.presented := sha256.Sum256([]byte(request.Auth))if subtle.ConstantTimeCompare(presented[:], sum[:]) != 1 { /* count the attempt, refuse */ }
// Checking a signature.if err := pqsign.Verify(publicKey, "user/7/role", statement, signature); err != nil { /* refuse */ }Limit the attempts on auth as for a login. A plain SHA-256 is enough for storing it: auth is 32 random-looking bytes, not a passphrase.
The context
Section titled “The context”As with sealing, the context binds a signature to its purpose. It has 1 to 255 bytes and must be the same when verifying. What was signed for user/7/role does not count as user/8/role.
What signatures give
Section titled “What signatures give”- They protect against anyone who can change what the server stores. A row that must carry a valid signature cannot be made by writing to the database, not even with every key the server has.
- They do not protect against whoever controls the code the browser runs. A server that delivers
client.jscan also deliver a page that reads the passphrase. - The passphrase is the weakest point. Argon2id makes each guess cost about a second and 64 MiB, it does not make a weak passphrase strong. Generated passphrases are better than invented ones.
- Who may sign what, how keys are replaced and which public key to trust is up to the application.
pqsignhas no certificates and no revocation.