pqbox

Hybrid post-quantum encryption and signatures from one Rust core, for Rust, Python, JavaScript and the command line.

Sealed boxes to a public key (ML-KEM-1024 + ECDH P-384), composite signatures (ML-DSA-87 + ECDSA P-384), authenticated encryption, HKDF, HMAC, hashes and Argon2id, behind one small API with a versioned wire format. pqbox implements no cryptographic primitive itself: it composes pinned, published crates and adds only the hybrid combiners, the composite signature framing and the wire format.

One core, every platform

  • Rust: crate pqbox, sans-IO, #![forbid(unsafe_code)]
  • Python ≥ 3.10: pqbox on PyPI (PyO3, abi3 wheels)
  • JavaScript / TypeScript: pqbox on npm (WebAssembly, Node ≥ 20 and browsers, synchronous)
  • CLI: pqbox-cli, release binaries and Homebrew

Safe defaults

  • pqbox-max is the default suite, and the only one parsers accept unless the caller allows another
  • Every object carries its format version, type and suite
  • Random nonces are drawn for you; secrets are zeroized in Rust

Same bytes everywhere

Keys, sealed boxes and signatures made in one language open and verify in the others. CI checks it with a cross-language interop matrix and frozen known answers in Rust, Python and JavaScript.

Why post-quantum, and why hybrid

Harvest now, decrypt later. No practical break of RSA or elliptic curves is publicly known, and no cryptographically relevant quantum computer is known to exist. Ciphertexts recorded today, however, can be decrypted whenever one appears. Data that must stay confidential for years needs post-quantum key exchange now.

Hybrid: secure if either part holds. Every suite pairs a post-quantum algorithm with a classical one. KEM shared secrets go through a combiner, so recovering the key means breaking every component. A composite signature verifies only if every component signature verifies.

  • ML-KEM and ML-DSA (FIPS 203, FIPS 204) are the post-quantum part.
  • ECDH and ECDSA on P-384 are a classical stopgap: they protect against a flaw in the young post-quantum algorithms or their implementations, and give no protection against a quantum computer.
  • If elliptic-curve cryptography were broken outright, pqbox-max would still rest on ML-KEM-1024 and ML-DSA-87; if lattices were broken, it would fall back to P-384 only.

Suites

A suite fixes every algorithm of a key, ciphertext, sealed box or signature, and is recorded in its header, so objects from different suites can never be mixed.

The three suites
IdSuiteKEMSignatureUse it for
0x02 pqbox-max (default) ML-KEM-1024 + ECDH P-384 ML-DSA-87 + ECDSA P-384 (SHA-384) Everything, unless a reason below applies
0x03 pqbox-paranoid (opt-in, experimental, not recommended for new keys) ML-KEM-1024 + Classic McEliece 8192128 + ECDH P-384 ML-DSA-87 + SLH-DSA-SHAKE-256s + ECDSA P-384 Not for new keys: reading objects made with it. Its Classic McEliece component is discouraged for new developments (see below)
0x01 xwing (compat only) X-Wing (ML-KEM-768 + X25519) ML-DSA-65 + Ed25519 Interop with X-Wing tooling. Never the default
  • Suite policy. Functions that read keys, ciphertexts, sealed boxes and signatures accept pqbox-max only. Other suites are refused with SuiteNotAllowed unless the caller allows them explicitly (SuitePolicy in Rust, allow_suites in Python, allowSuites in JavaScript, --allow-suite in the CLI), so an attacker cannot steer a caller onto a suite it did not choose.
  • pqbox-paranoid is not recommended for new keys. It was meant to survive a break of lattice cryptography through Classic McEliece (code-based) and SLH-DSA (hash-based). In 2026, new cryptanalysis of Classic McEliece appeared: a quasipolynomial distinguisher with heuristic key recovery (ePrint 2026/1630), and an improved heuristic key recovery estimated at 2117 to 2128 bit operations under the full-memory cost metric, which its author calls not close to practical (ePrint 2026/1984). The BSI now advises that Classic McEliece should no longer be used for new developments, while noting that no practical attack on its recommended parameters is known (Notes on recent developments concerning Classic McEliece, 1 October 2026). The pqbox-paranoid KEM is a hybrid, so it still holds as long as ML-KEM-1024 or P-384 holds, but it can no longer be counted on to survive a lattice break. A replacement (HQC or FrodoKEM, which needs a new suite id) is pending; until then, use pqbox-max.
  • pqbox-paranoid is also experimental: its SLH-DSA half comes from slh-dsa 0.2.0-rc.5, a release candidate. The Rust crates build it only with the paranoid cargo feature; the Python wheels and the npm package include it.
  • Combiners. The pqbox-max and pqbox-paranoid KEM combiners are modeled on X-Wing but are pqbox's own, not IETF-standardized, with no published security proof. Composite signatures follow the IETF composite ML-DSA draft (draft-ietf-lamps-pq-composite-sigs-19, since published as RFC 10073) with pqbox's own encodings; they do not interoperate with X.509 composite implementations.

Primitives

What pqbox provides
PrimitiveConstructionNotes
Sealed box Suite KEM + HKDF-SHA-256 + XChaCha20-Poly1305 Encrypts to a public key with a fresh encapsulation per box. Anonymous: it does not authenticate the sender.
Composite signature ML-DSA + ECDSA P-384 (or + SLH-DSA, or + Ed25519, by suite) Valid only if every component verifies. Strongly unforgeable: ECDSA must be low-s, Ed25519 is verified strictly.
AEAD XChaCha20-Poly1305 (default), AES-256-GCM 256-bit keys, random nonce per message, header authenticated with your AAD. AES-256-GCM's 96-bit nonce limits a key to about 232 messages.
KDF and MAC HKDF-SHA-256, HMAC-SHA-256 HMAC tags are verified in constant time.
Hashes SHA-256, SHA3-256, BLAKE3 32-byte digests.
Password hashing Argon2id, PHC strings 64 MiB, 3 passes, 1 lane by default. Verification refuses costs above 256 MiB, 10 passes or 8 lanes before allocating anything.
Password key derivation Argon2id (derive_key, RFC 9106, version 0x13) A key of 16 to 64 bytes (32 by default) from a password and a stored salt of at least 16 bytes; same defaults and limits as password hashing. Matches other Argon2id implementations given the same inputs.
KEM Encapsulate / decapsulate of each suite For protocols that need a raw shared secret; applications use sealed boxes.

Every serialized object is "PQB" ‖ version ‖ type ‖ suite ‖ body; parsers check exact lengths and reject unknown versions with UnsupportedVersion. Errors carry a stable code such as Decrypt, BadSignature or SuiteNotAllowed in every language.

Install

cargo add pqbox                      # Rust library (--features paranoid for pqbox-paranoid)
pip install pqbox                    # Python ≥ 3.10
npm install pqbox                    # Node ≥ 20 and browsers
cargo install --locked pqbox-cli     # the pqbox command
brew install maxgfr/tap/pqbox        # the pqbox command, from Homebrew

Each GitHub release also carries prebuilt pqbox binaries for macOS and Linux (arm64, x86_64) with a SHA256SUMS file. Since the release after v1.1.0, every asset also has a signed build provenance attestation: gh attestation verify <file> -R maxgfr/pqbox checks it. pqbox selftest checks an installed binary offline: round trips, tamper refusal and frozen known answers.

The Rust examples also need an RNG: pqbox takes a caller-provided CSPRNG.

# Cargo.toml
[dependencies]
pqbox = "1.1"
getrandom = { version = "0.4", features = ["sys_rng"] }
rand_core = "0.10"

Quick start

Seal and open, sign and verify, and encrypt with a password. Only pqbox-max objects are accepted when reading, unless another suite is allowed explicitly.

Python

Seal and open

import pqbox

pk, sk = pqbox.kem_keygen()                  # pqbox-max
box = pqbox.seal(pk, b"hello")
assert pqbox.open(sk, box) == b"hello"

Sign and verify

spk, ssk = pqbox.sign_keygen()
sig = pqbox.sign(ssk, b"release v1.2.3")
assert pqbox.verify(spk, b"release v1.2.3", sig)   # False if any component fails

Encrypt with a password

salt = pqbox.password_generate_salt()        # 16 bytes, store it with the ciphertext
key = pqbox.password_derive_key("correct horse battery staple", salt)
aad = b"myapp/v1/notes"                      # app / format version / purpose
ct = pqbox.encrypt(key, b"secret", aad=aad)  # XChaCha20-Poly1305, random nonce
assert pqbox.decrypt(key, ct, aad=aad) == b"secret"

JavaScript

Seal and open

import { kemKeygen, seal, open } from "pqbox";

const enc = new TextEncoder();
const { publicKey, secretKey } = kemKeygen();     // pqbox-max
const box = seal(publicKey, enc.encode("hello"));
console.log(new TextDecoder().decode(open(secretKey, box)));

Sign and verify

import { signKeygen, sign, verify } from "pqbox";

const signer = signKeygen();
const msg = new TextEncoder().encode("release v1.2.3");
const sig = sign(signer.secretKey, msg);
console.log(verify(signer.publicKey, msg, sig));  // true

Encrypt with a password

import { passwordGenerateSalt, passwordDeriveKey, encrypt, decrypt } from "pqbox";

const salt = passwordGenerateSalt();              // store it with the ciphertext
const key = passwordDeriveKey("correct horse battery staple", salt);
const aad = new TextEncoder().encode("myapp/v1/notes");
const ct = encrypt(key, new TextEncoder().encode("secret"), { aad });
const pt = decrypt(key, ct, { aad });             // throws PqboxError (code "Decrypt") on tampering

Rust

Seal and open

use pqbox::{Suite, kem, seal};
use rand_core::UnwrapErr;

let mut rng = UnwrapErr(getrandom::SysRng);
let recipient = kem::SecretKey::generate(Suite::default(), &mut rng)?;   // pqbox-max
let sealed = seal::seal(recipient.public_key(), b"hello", &mut rng)?;
assert_eq!(*seal::open(&recipient, &sealed)?, b"hello");               // zeroized on drop

Sign and verify

use pqbox::sign;

let signer = sign::SecretKey::generate(Suite::Max, &mut rng)?;
let sig = signer.sign(b"release v1.2.3", &mut rng)?;

// Received as bytes: the parsers accept pqbox-max only.
let pk = sign::PublicKey::from_bytes(&signer.public_key().to_bytes())?;
let sig = sign::Signature::from_bytes(&sig.to_bytes())?;
pk.verify(b"release v1.2.3", &sig)?;                                      // Err(BadSignature) if any component fails

Encrypt with a password

use pqbox::{aead, password};

let salt = password::generate_salt(&mut rng);                               // store it with the ciphertext
let key = password::derive_key(b"correct horse battery staple", &salt,
                               password::Params::default(), password::DEFAULT_KEY_LEN)?;
let aad = b"myapp/v1/notes";
let ct = aead::encrypt(aead::Algorithm::default(), key.as_bytes(), b"secret", aad, &mut rng)?;
assert_eq!(*aead::decrypt(key.as_bytes(), &ct, aad)?, b"secret");

CLI

Seal and open

pqbox keygen kem -o alice                       # alice.pub, alice.sec (mode 0600), pqbox-max
pqbox seal --to alice.pub -i secret.txt -o secret.box
pqbox open --key alice.sec -i secret.box

Sign and verify

pqbox keygen sign -o release
pqbox sign --key release.sec -i dist.tar -o dist.tar.sig
pqbox verify --key release.pub --sig dist.tar.sig -i dist.tar   # exit 0 if valid, 1 if not

Inspect and check

pqbox hash --alg blake3 -i dist.tar
pqbox info alice.pub
pqbox selftest                                   # offline; exit 0 if every check passes

The CLI has no password-based encryption; use a library for it.

Integration guide

The integration guide is the one way applications use pqbox, so that every app encrypts, signs and stores keys the same way and one audit checklist covers them all. In short:

Which pqbox function for which job
JobUse
Encrypt for a person, device or partySealed box to their pqbox-max public key; never a hand-built KEM + AEAD
Encrypt your own data at restAEAD (XChaCha20-Poly1305) with a key from generate_key and an AAD naming the app, format version and record
Encrypt with a passwordderive_key with a fresh generate_salt() stored next to the ciphertext, default costs, then AEAD
Store login passwordspassword_hash and password_verify
SignComposite signatures, verified with the default suite policy, over a context-bound message
Hash, MAC, derive keysSHA-256 / SHA3-256 / BLAKE3, HMAC-SHA-256, HKDF-SHA-256 with labels "<app>/v<N>/<purpose>"

It also covers key storage (OS keychains, IndexedDB and its same-origin caveats), zeroization and logging, version bytes in every stored format, constant-time comparisons, what stays outside pqbox (TLS, WebRTC, Nostr, OAuth PKCE, TOTP, file formats) and how to document it, the dependency policy, and an audit checklist.

Built on established libraries, not hand-rolled

Every algorithm comes from a published crate, pinned to an exact version. pqbox adds only the hybrid combiners, the composite signature framing and the wire format.

Not independently audited. The post-quantum crates (ml-kem, ml-dsa, x-wing, slh-dsa, a release candidate) come from RustCrypto, which has not had them audited; libcrux-ml-kem is partly formally verified (not for constant time) but has no public audit; and classic-mceliece-rust is a community crate. pqbox itself has not been audited.

Upstream cryptography

Crates the pqbox crate is built on
CrateUsed forSourceImplements
libcrux-ml-kemML-KEM-1024 (pqbox-max, pqbox-paranoid), portable buildcryspen/libcruxFIPS 203
ml-kemML-KEM-768 (inside X-Wing)RustCrypto/KEMsFIPS 203
x-wingX-Wing KEM (xwing)RustCrypto/KEMsdraft-connolly-cfrg-xwing-kem
classic-mceliece-rustClassic McEliece 8192128 (pqbox-paranoid)Colfenor/classic-mceliece-rustNIST submission
ml-dsaML-DSA-65 / ML-DSA-87RustCrypto/signaturesFIPS 204
slh-dsaSLH-DSA-SHAKE-256s (pqbox-paranoid)RustCrypto/signaturesFIPS 205
p384ECDH and ECDSA P-384RustCrypto/elliptic-curvesFIPS 186-5, SP 800-56A, SP 800-186
x25519-dalekX25519 (inside X-Wing)dalek-cryptographyRFC 7748
ed25519-dalekEd25519 (xwing signatures)dalek-cryptographyRFC 8032
chacha20poly1305XChaCha20-Poly1305RustCrypto/AEADsRFC 8439, draft-irtf-cfrg-xchacha
aes-gcmAES-256-GCMRustCrypto/AEADsFIPS 197, SP 800-38D
hkdfHKDF-SHA-256RustCrypto/KDFsRFC 5869
hmacHMAC-SHA-256RustCrypto/MACsRFC 2104, FIPS 198-1
sha2SHA-256, SHA-384, SHA-512RustCrypto/hashesFIPS 180-4
sha3SHA3-256 (combiners, fingerprints)RustCrypto/hashesFIPS 202
blake3BLAKE3BLAKE3-team/BLAKE3BLAKE3 specification
argon2Argon2id, PHC stringsRustCrypto/password-hashesRFC 9106, PHC string format
subtleConstant-time comparisonsdalek-cryptography/subtle
zeroizeWiping secrets from memoryRustCrypto/utils
getrandomThe operating system's CSPRNG (CLI, bindings)rust-random/getrandom

The full list, with the CLI and binding crates, is in the README; docs/BACKENDS.md compares the backends with the alternatives.

Tests

  • Official vectors only, listed with their exact revisions in tests/vectors: NIST ACVP (SLH-DSA), Wycheproof (AEADs, HKDF, HMAC, Ed25519, X25519, P-384, ML-KEM, ML-DSA), the X-Wing draft vectors, the IETF LAMPS examples for ML-KEM and ML-DSA, and the RFC vectors.
  • Frozen known answers for the combiners, sealed boxes and composite signatures of every suite, generated once and checked in Rust, Python and JavaScript.
  • Negative tests for every suite: truncation, extension, bit flips in every field, wrong version, suite or type bytes, degenerate points, each signature component failing on its own.
  • Fuzzing (cargo-fuzz) of every parser and of round trips, run in CI on every change, plus property tests.
  • Cross-language interop: keys from Rust, Python and JavaScript seal and sign for each other in every suite.
  • Lints: #![forbid(unsafe_code)]; unwrap, expect, panics and slice indexing denied outside tests; pedantic clippy.

Supply chain

  • Trusted publishing. crates.io, PyPI and npm releases are published from GitHub Actions with short-lived OIDC tokens, from environments restricted to main. No registry token is stored in the repository.
  • Provenance. The npm package is published with provenance. Each GitHub release lists a SHA256SUMS for its binaries, wheels and npm tarball, and the binaries are checked to pass pqbox selftest before release. Since the release after v1.1.0, every release asset, SHA256SUMS included, has a signed SLSA build provenance attestation, checked with gh attestation verify <file> -R maxgfr/pqbox.
  • Pinned dependencies. Every cryptographic crate is pinned to an exact version (=), GitHub Actions are pinned by commit SHA, and the release tooling is installed from a lockfile.
  • Verified arithmetic, no unused SIMD code. The release binaries, wheels and npm package use the formally verified field arithmetic synthesized by fiat-crypto for P-384 and Curve25519 (same bytes as the default backends), compile only the portable code of libcrux, and are built from the lockfile (--locked).
  • Update cooldown. Dependabot proposes a new version only three days after it is published (security updates excepted), so a compromised release has time to be noticed and yanked.
  • Watch. cargo-deny and cargo-audit run in CI (cargo-deny also bans C crypto libraries such as OpenSSL and AWS-LC, and allows build scripts only in a reviewed list of crates), and a daily upstream watch reports advisories and new releases of the pinned crates.

Threat model, in short

Protected

  • Ciphertexts recorded today against a future quantum computer
  • A break of one family of assumptions, while the suite keeps a component outside it
  • Hostile bytes given as keys, ciphertexts, boxes or signatures (exact-length parsers, fuzzed)
  • Suite downgrade and cross-suite confusion
  • Secrets in Rust memory (zeroized, redacted in Debug)

Not protected

  • Bugs in unaudited implementations, pqbox's included
  • The pqbox-max and pqbox-paranoid combiners have no published proof
  • Sealed boxes do not authenticate the sender
  • Side channels beyond the underlying crates' claims; constant time is not guaranteed in JavaScript or WebAssembly
  • JavaScript and Python memory cannot be wiped
  • A broken system RNG; key management; metadata such as sizes

Read the full THREAT_MODEL.md, and report vulnerabilities privately as described in SECURITY.md.