Skip to content

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.

ServerBrowser
Create a keypqsign.GenerateKey()seal.generateSigningKey()
Signkey.Sign(context, message)key.sign(context, data)
Verifypqsign.Verify(publicKey, context, message, signature)seal.verify(publicKey, context, data, signature)
Put under a passphrasekey.Wrap(passphrase, pqsign.DefaultParams())key.wrap(passphrase)
Openpqsign.Unwrap(wrapped, passphrase)seal.unlockSigningKey(wrapped, passphrase)
Fingerprintpqsign.Fingerprint(publicKey)seal.fingerprint(publicKey)

pqsign needs Go 1.27. The other packages keep working with Go 1.26.

  1. 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, wrapped and auth.
  2. Store. The server keeps the public key, wrapped and a hash of auth, never auth itself.
  3. 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 computes auth. The server compares the hash and only then hands out wrapped.
  4. 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.

// 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 as u with a combining mark is the same passphrase.
  • pending.open and pending.cancel use the derivation up. A wrong passphrase ends with unlock_failed.
  • key.forget() removes the private key from the worker, and so does closing the client or the tab.
// 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.

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.

  • 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.js can 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. pqsign has no certificates and no revocation.