# Cryptography

> Every cryptographic algorithm the library, the server, and the packages use, what each protects, and the post-quantum migration plan.

From `docs/security/cryptography.md` in tensile-tools/tensile-auth at commit `e66760d` (v0.4.1-7-ge66760d). The HTML page is https://auth.tensile.tools/docs/reference/cryptography.

This page lists every cryptographic algorithm that the library, the server, and the TypeScript packages use: what each one protects, its key or parameters, and where it lives in the code. It ends with the plan for post-quantum algorithms.

Update this page in the same change that adds or replaces an algorithm. The [OWASP ASVS 5.0 self-assessment](/docs/reference/asvs) cites it for requirements 11.1.2 and 11.1.4.

## Post-quantum status

| Group | Algorithms | Status |
|---|---|---|
| Symmetric encryption, hashes, and MACs | AES-256-GCM, SHA-256, HMAC-SHA-256, HMAC-SHA-1 (TOTP), Argon2id | Safe: Grover's algorithm leaves about 128 bits of security |
| Random tokens and codes | `crypto/rand`; tokens carry 120 to 256 bits, and short typed codes are limited to a few guesses; stored as SHA-256 or Argon2id | Safe: they're random values, not signatures |
| Outbound TLS key exchange | `X25519MLKEM768` | Hybrid post-quantum when the peer supports it |
| Export files | age with ML-KEM-768 + X25519 hybrid recipients (`age1pq1…`), or a scrypt passphrase | Hybrid post-quantum; classic X25519 recipients are refused |
| Short-lived signatures | Passkeys, DPoP proofs, device-bound proofs, ID tokens, and MCP access tokens: ECDSA, EdDSA, and RSA | Classical; a forgery needs a quantum computer at the time of use |
| Long-lived signatures | Audit checkpoints: Ed25519 | Classical; the first to move, as [Post-quantum migration](/docs/reference/cryptography#post-quantum-migration) describes |

## Inventory

| Use | Algorithm | Key or secret | Where |
|---|---|---|---|
| Session tokens, claim codes, OAuth codes, and device codes | `crypto/rand`, base62 with rejection sampling | About 256 bits per token | `internal/token.Generate` |
| Stored token form | SHA-256 | None | `internal/token.Hash` |
| Token typo check (not security) | CRC32-IEEE | None | `internal/token` |
| Session and agent IDs | `crypto/rand` | 128 bits | `Service.newID` |
| Recovery codes | `crypto/rand`; stored as SHA-256 | 120 bits per code | `recovery.Codes.Generate` |
| TOTP codes | HMAC-SHA-1 (RFC 6238) | 160-bit secret | `totp.hotp` |
| TOTP secret at rest | AES-256-GCM, random 96-bit nonce, associated data | 32-byte keys in the application's key ring | `internal/seal` |
| Ceremony lookup key | SHA-256 of the WebAuthn challenge, or of the federation `state` | None | `passkey.ceremonyID`, `federation.ceremonyID` |
| Passkey assertions | Delegated to go-webauthn v0.18.2 | Credential public keys | `passkey` |
| Federation `state` and nonce | `crypto/rand` | 256 bits each | `federation.randomString` |
| PKCE (S256) for social login | `oauth2.GenerateVerifier`, SHA-256 challenge | 256-bit verifier | `federation` |
| ID token verification (social login) | The algorithms in the issuer's discovery document, verified by go-jose v4 through `zitadel/oidc` | The issuer's key set | `federation.NewOIDC` |
| ID token signing (OAuth provider) | RS256 (RSA, at least 2048 bits) or ES256 (P-256) through go-jose v4 | The application's `oauth.Config.SigningKey` | `oauth.Provider.setKey` |
| OAuth client secrets | SHA-256 digests, compared in constant time | The application's client secrets | `oauth.HashSecret` |
| Device user codes | `crypto/rand`, 8 characters from a 20-letter alphabet; stored as SHA-256 | About 34.6 bits | `oauth.newUserCode` |
| Registered OAuth client IDs | `crypto/rand`, `dcr_` and 32 base62 characters; stored under a SHA-256 key | About 190 bits | `oauth.newRegisteredID` |
| DPoP proofs (RFC 9449) | ES256 (ECDSA P-256 with SHA-256) or EdDSA (Ed25519), verified by go-jose v4 | The agent's public key, from the proof's jwk; the session stores its RFC 7638 SHA-256 thumbprint | `dpop.Verifier.Verify` |
| DPoP token binding | SHA-256 of the access token (ath), and the key thumbprint, compared in constant time | None | `auth.Service.checkKey` |
| DPoP replay cache key | SHA-256 of the key thumbprint and the `jti` | None | `dpop.ReplayKey` |
| Leak alert signatures | ECDSA P-256 over SHA-256 (`ecdsa.VerifyASN1`) | GitHub's published public keys | `leakscan` |
| Ceremony binding comparison | Constant-time comparison | None | `passkey.consume`, `federation.equal` |
| Audit hash chain | SHA-256 over the previous hash and each event's fields | None | `auth.chainHash` |
| Audit checkpoints | Ed25519 (`crypto/ed25519`) | The application's signing key | `Service.Checkpoint` |
| Password hashes | Argon2id v19 (`golang.org/x/crypto/argon2`), 19,456 KiB, 2 iterations, 1 thread by default, at or above the OWASP minimum; PHC strings | 16-byte salt from `crypto/rand`; 32-byte output | `password.hashPassword` |
| Password comparison | Constant-time comparison of Argon2id outputs | None | `password.phc.matches` |
| Email link codes and known-device tokens | `crypto/rand`, base62, as session tokens; stored as SHA-256 | About 256 bits per code | `internal/emailcode.Issue`, `password.newDevice` |
| Typed email codes | `crypto/rand`, 8 Crockford base32 characters; stored as Argon2id v19, 7,168 KiB, 5 iterations, 1 thread, compared in constant time | 40 bits per code; 16-byte salt from `crypto/rand`; 32-byte output; 5 wrong guesses delete it | `internal/emailcode.Issue`, `internal/emailcode.PeekTyped` |
| Sign-up binding comparison | Constant-time comparison | None | `password.authorizeSignUp` |
| Address and federated identity labels in the audit log, and per-address limiter keys | HMAC-SHA-256 of the normalized address, or of the identity's issuer and subject, with a purpose and length-prefixed parts, truncated to 128 bits | The application's audit key from `auth.WithAuditKey`, at least 32 bytes that don't all have the same value; the server generates and seals its own (key kind `audit`), which never rotates | `Service.Pseudonym`, `Service.EmailLabel`, `password.targetKey`, `federation.Federation.factorID` |
| Breached-password lookup (not a storage hash) | SHA-1 of the password after NFC; only the first 5 hexadecimal characters leave the process | None | `password/pwned` |
| Export files | age v1: ML-KEM-768 + X25519 hybrid recipient stanzas, or scrypt for a passphrase; ChaCha20-Poly1305 for the payload | Recipients' public keys, or a generated 128-bit passphrase | `authexport.Export`, `tensile-auth-server export` |
| Server key ring | AES-256-GCM, as for TOTP secrets; a key-check value detects a wrong master key | The operator's 32-byte `master_key` seals every key the server stores | `server` (`masterRing`, `prepareKeys`) |
| ID token signing (server) | ES256 (ECDSA P-256) | A server-generated key, rotatable | `server` (key kind `oidc`) |
| Audit checkpoint key (server) | Ed25519 | A server-generated key, rotatable | `server` (key kind `checkpoint`) |
| Hook and webhook signatures | HMAC-SHA-256 over the message ID, timestamp, and body (`Webhook-Id`, `Webhook-Timestamp`, and `Webhook-Signature` headers) | 32-byte server-generated secrets; several sign during rotation | `server.webhookMAC`; checked by the SDK's `webhooks.ts` through Web Crypto |
| Device-bound session proofs (DBSC) | ES256 (P-256) or RS256 (at least 2048 bits) | The browser's hardware-held key | `devicebound.go` (`parseJWK`) |
| Access tokens for MCP servers | An allowlist of asymmetric algorithms: RS256, PS256, ES256, and EdDSA by default; RS, PS, and ES at 256 to 512 bits, and EdDSA, allowed | The issuer's key set from its metadata | `mcpauth` |
| Imported bcrypt hashes | bcrypt verification only, at cost 10 to 14; a successful sign-in rehashes with Argon2id | The imported hash | `password/bcrypt.go` |
| Browser secrets the server never sees | HKDF-SHA-256 from the passkey's PRF output to a non-extractable AES-GCM 256-bit key, separated by purpose | The passkey's PRF output | `client` (`deriveKey`) |
| SDK check-cache keys | SHA-256 of the credential and the check | None | `sdk` (`cache.ts`) |
| Outbound TLS (OIDC discovery, key sets, webhooks, mail, breach lookups) | Go's defaults: TLS 1.3 with the hybrid `X25519MLKEM768` key exchange when the peer supports it; mail sets TLS 1.2 as its minimum | System roots | `crypto/tls` |
| Inbound TLS | Not terminated by the server; the reverse proxy in front of it handles TLS | The proxy's certificate | Deployment |
| Release signatures | Keyless Sigstore signatures: cosign for the server image, npm provenance for the packages | Short-lived certificates bound to the release workflow's identity | `.github/workflows/release.yml` |

## Post-quantum migration

A quantum computer large enough to run Shor's algorithm would break every public-key signature that the library makes or checks. Symmetric primitives keep enough strength. The plan for each primitive:

| Primitive | Exposure | How to migrate |
|---|---|---|
| Passkey signatures (ECDSA, EdDSA, RSA) | Broken by Shor's algorithm | Follow WebAuthn and go-webauthn as post-quantum algorithms are registered. Credential records store the algorithm, so old and new passkeys can coexist while users add new ones. |
| ID token signatures (RS256, ES256), made by the OAuth provider and checked from identity providers | Broken by Shor's algorithm | Follow JOSE and OpenID Connect as post-quantum algorithms are registered. The provider's key set names keys by ID, so a new key and algorithm can be published beside the old one; relying parties pick the algorithm from discovery. |
| DPoP proofs (ES256, EdDSA) | Broken by Shor's algorithm | Add the new algorithm to `dpop.Algorithms`. Bindings store only a key thumbprint, so agents move by binding new sessions to new keys; agent sessions live at most 8 hours. |
| Audit checkpoints (Ed25519) | Broken by Shor's algorithm | Sign new checkpoints with a post-quantum scheme and keep the old ones; a checkpoint only needs to outlast the chain it protects. |
| Leak alert signatures (ECDSA P-256) | Broken by Shor's algorithm | Set by GitHub's partner program; follow its key format. |
| AES-256-GCM | Grover's algorithm leaves about 128 bits of security | No change needed. If a change is needed, add a sealed-format version: blobs carry a version byte and a key ID, and `totp` reseals on next use. |
| SHA-256 token digests and the audit chain | Grover's algorithm leaves about 128 bits of preimage resistance | No change needed. To replace the digest, store the new one beside the old and let tokens expire: human tokens live at most 90 days, and personal access tokens and OAuth grants at most 366 days. |
| HMAC-SHA-1 in TOTP | Fixed by RFC 6238 and authenticator apps | Passkeys are the primary factor. Replace TOTP rather than its MAC if apps adopt another algorithm. |

On 2 December 2026, the Office of the National Cyber Director, the NSA, and CISA reported that AI models had found weaknesses in some public-key cryptography in use, and assessed that these findings are not an immediate and widespread threat. The NSA asks for a move to post-quantum algorithms (CNSA 2.0) and for cryptographic agility. The library follows that guidance in this order:

1. **Audit checkpoints.** Sign each checkpoint with both Ed25519 and ML-DSA, and accept it only when both signatures verify. Checkpoints prove the log's integrity for years, so they're the one signature that has to outlast a future attack. Go's `crypto/mldsa` package implements ML-DSA (FIPS 204); using it may raise the module's minimum Go version above 1.26.
2. **Tokens from other issuers.** Add ML-DSA verification to `mcpauth` and federation once JOSE registers its algorithm names, so tokens from identity providers that move to ML-DSA keep working.
3. **The SDK's outbound TLS.** Run the SDK on Node.js 24 or later. Node.js 24 negotiates hybrid post-quantum key exchange by default; the packages also support Node.js 22.18 and later, which use classical key exchange.

Short-lived signatures (passkeys, DPoP proofs, device-bound proofs, and ID tokens) move when their standards register post-quantum algorithms, as the table describes.

Chrome stops trusting certificate authority keys on the P-256 curve from 15 March 2027. That rule applies to the TLS certificates of a deployment, which its proxy or hosting provider serves, and not to the library.
