pqbox
A post-quantum crypto toolkit with a Rust core and bindings for Python and JavaScript. It covers hybrid key encapsulation, sealed boxes, composite signatures, authenticated encryption, key derivation, hashing and password hashing.
pqbox implements no cryptographic primitive itself. Every algorithm comes from a pinned crate,
mostly from RustCrypto, plus Cryspen's formally verified
libcrux for ML-KEM-1024 and classic-mceliece-rust for
Classic McEliece. pqbox only adds the hybrid combiners, the composite signature framing and a versioned
wire format.
- Rust: crate
pqbox(sans-IO,#![forbid(unsafe_code)]) and the CLIpqbox-cli. - Python: package
pqboxon PyPI, built with PyO3 (abi3, Python ≥ 3.10). - JavaScript / TypeScript: package
pqboxon npm, built with WebAssembly (Node ≥ 20 and browsers, ESM, synchronous API).
Suites
Every key, ciphertext, sealed box and signature records its suite in its header, so objects from different suites can never be mixed.
| Id | Name | KEM | Signature | Use it for |
|---|---|---|---|---|
0x02 |
pqbox-max (default) |
ML-KEM-1024 + ECDH P-384 | ML-DSA-87 + ECDSA P-384 (SHA-384) | Everything, unless you have a reason below |
0x03 |
pqbox-paranoid (experimental) |
ML-KEM-1024 + Classic McEliece 8192128 + ECDH P-384 | ML-DSA-87 + SLH-DSA-SHAKE-256s + ECDSA P-384 | Long-term archives and secrets meant to last decades, where size and speed do not matter |
0x01 |
xwing (compat only) |
X-Wing (ML-KEM-768 + X25519) | ML-DSA-65 + Ed25519 | Interop with X-Wing tooling such as hush. Never the default |
Suite policy. The functions that read keys, ciphertexts, signatures and sealed boxes accept
pqbox-max objects only. xwing and pqbox-paranoid objects are refused with
SuiteNotAllowed unless the caller allows their suite explicitly, so an attacker cannot steer a
caller onto a suite it did not choose (for instance by handing over an xwing public key):
- Rust:
from_bytes_with_policyandopen_with_policywith aSuitePolicysuch asSuitePolicy::DEFAULT.allow(Suite::XWing)(from_bytesandopenuseSuitePolicy::DEFAULT); - Python: the keyword-only
allow_suites=["xwing"]argument; - JavaScript: the
{ allowSuites: ["xwing"] }option; - CLI:
--allow-suite xwing(repeatable) onseal,open,signandverify.
Key generation takes the suite by name and needs no policy.
The paranoid feature. pqbox-paranoid is experimental: its SLH-DSA half comes from
slh-dsa 0.2.0-rc.5, a release candidate. The Rust crates compile it only with the paranoid
cargo feature, off by default (cargo add pqbox --features paranoid,
cargo install pqbox-cli --features paranoid); without it, paranoid objects are refused with
SuiteNotEnabled. The Python wheels and the npm package include it: it adds about 66 KB to a
wheel (542 KB to 608 KB, macOS arm64) and about 67 KB to the WebAssembly module (801 KB to 868 KB
before wasm-bindgen).
Hybrid rationale. A hybrid stays secure as long as one of its components holds. KEM shared secrets go through a combiner, so recovering the session key means breaking every component. A composite signature verifies only if every component signature verifies.
pqbox-maxrests on ML-KEM-1024 and ML-DSA-87 (NIST category 5). The classical half is defense in depth: if elliptic-curve cryptography (or RSA) were broken outright, security would still rest on ML-KEM-1024 and ML-DSA-87. The classical half is P-384 rather than X25519 or Ed25519. P-384 is a stronger classical fallback, and it is the curve the NSA's December 2, 2026 advisory (PP-26-4956) keeps as an interim choice. That advisory lists elliptic curves other than P-384/P-521, and EdDSA, among the algorithms to inventory and replace. Some cryptographers read it as a sign that 256-bit curves may be weaker than believed. The advisory itself does not say they are broken.pqbox-paranoidalso survives a break of lattice cryptography. Classic McEliece (code-based) and SLH-DSA (hash-based) do not rely on lattices.xwingexists only for compatibility. Its classical half is a 256-bit curve, so treat its security as resting entirely on ML-KEM-768 and ML-DSA-65.
The pqbox-max and pqbox-paranoid KEM combiners are modeled on X-Wing but are not
IETF-standardized:
pqbox-max: ss = SHA3-256(ss_mlkem ‖ ss_p384 ‖ ct_p384 ‖ pk_p384 ‖ "pqbox/v1/kem-max")
pqbox-paranoid: ss = SHA3-256(ss_mlkem ‖ ss_mceliece ‖ ss_p384 ‖ ct_p384 ‖ pk_p384
‖ SHA3-256(ct_mlkem) ‖ SHA3-256(ct_mceliece) ‖ "pqbox/v1/kem-paranoid")
Signatures follow the IETF composite ML-DSA draft (draft-ietf-lamps-pq-composite-sigs-19): the
message representative is "CompositeAlgorithmSignatures2025" ‖ Label ‖ len(ctx) ‖ ctx ‖ SHA-512(M),
using the draft's labels for xwing and pqbox-max and a pqbox-specific label for
pqbox-paranoid. The deviations are documented in sign.rs:
pqbox's own encodings instead of ASN.1, a fixed-length low-s ECDSA r‖s, and the signer's key
fingerprint bound in ctx.
Composite signatures are strongly unforgeable (SUF-CMA): nobody can produce a second valid
signature of a message that was signed, not just a signature of a new message. Every component
has a single valid encoding per signing operation: ML-DSA and SLH-DSA are designed to be strongly
unforgeable, Ed25519 is verified strictly, and the ECDSA s must be in the lower half of the group
order (signing normalizes it; the malleable n - s twin is refused).
Algorithms
| Purpose | Algorithm | Crate |
|---|---|---|
| KEM | ML-KEM-1024 (FIPS 203), in pqbox-max and pqbox-paranoid |
libcrux-ml-kem 0.0.12 (portable build) |
| KEM | ML-KEM-768 (FIPS 203), inside X-Wing | ml-kem 0.3.4 |
| KEM | X-Wing (draft-connolly-cfrg-xwing-kem) | x-wing 0.1.1 |
| KEM | Classic McEliece 8192128 | classic-mceliece-rust 3.1.0 |
| KEM (classical half) | ECDH P-384, X25519 | p384 0.14.0, x25519-dalek 3.0.0 |
| Signature | ML-DSA-65 / ML-DSA-87 (FIPS 204) | ml-dsa 0.1.2 |
| Signature | SLH-DSA-SHAKE-256s (FIPS 205), paranoid feature only, experimental |
slh-dsa 0.2.0-rc.5 (release candidate) |
| Signature (classical half) | ECDSA P-384 with SHA-384, Ed25519 | p384 0.14.0, ed25519-dalek 3.0.0 |
| Sealed box | suite KEM + HKDF-SHA-256 + XChaCha20-Poly1305 | |
| AEAD | XChaCha20-Poly1305 (default), AES-256-GCM | chacha20poly1305 0.11.0, aes-gcm 0.11.1 |
| KDF / MAC | HKDF-SHA-256, HMAC-SHA-256 | hkdf 0.13.0, hmac 0.13.0 |
| Hash | SHA-256, SHA3-256, BLAKE3 | sha2 0.11.1, sha3 0.12.0, blake3 1.8.9 |
| Password | Argon2id (64 MiB, t=3, p=1 by default; verification and key derivation capped at 256 MiB, t=10, p=8): PHC strings, and keys derived from a password and a stored salt | argon2 0.6.0 |
Symmetric keys are always 256-bit.
Sizes and timings
Sizes are of serialized objects and include the 6-byte header. Timings are medians from
cargo bench -p pqbox (criterion, release build) on an Apple M5 laptop (rustc 1.99.0); they
show orders of magnitude, not guarantees.
| Suite | KEM public key | KEM secret key | KEM ciphertext | Sealed-box overhead | Signing public key | Signing secret key | Signature |
|---|---|---|---|---|---|---|---|
xwing |
1,222 B | 38 B | 1,126 B | 1,166 B | 1,990 B | 70 B | 3,379 B |
pqbox-max |
1,671 B | 118 B | 1,671 B | 1,711 B | 2,695 B | 86 B | 4,729 B |
pqbox-paranoid |
1,359,495 B | 1,372,094 B | 1,879 B | 1,919 B | 2,759 B | 214 B | 34,521 B |
| Suite | KEM keygen | Encapsulate | Decapsulate | Seal 1 KiB | Open 1 KiB | Sign keygen | Sign | Verify |
|---|---|---|---|---|---|---|---|---|
xwing |
53 µs | 50 µs | 80 µs | 54 µs | 83 µs | 264 µs | 378 µs | 61 µs |
pqbox-max |
311 µs | 607 µs | 642 µs | 595 µs | 601 µs | 730 µs | 775 µs | 446 µs |
pqbox-paranoid |
966.99 ms | 1.13 ms | 62.03 ms | 2.37 ms | 62.98 ms | 37.48 ms | 435.01 ms | 1.06 ms |
Paranoid KEM key generation varies a lot from run to run (0.74 s to 1.20 s here), because Classic McEliece retries until it finds a usable key. In WebAssembly under Node 24, the paranoid KEM key generation took 6.5 to 11.6 s. Symmetric primitives on 64 KiB: XChaCha20-Poly1305 62 µs, AES-256-GCM 14 µs, SHA-256 20 µs, SHA3-256 59 µs, BLAKE3 26 µs.
Install
Each GitHub release also carries prebuilt pqbox binaries, pqbox-<target> for macOS (arm64,
x86_64) and Linux (arm64, x86_64), with a SHA256SUMS file. pqbox --version reports the release,
and pqbox selftest checks the installed binary offline.
Examples
Rust
use ;
use UnwrapErr;
let mut rng = UnwrapErr; // getrandom 0.4 with the `sys_rng` feature
// Sealed box to a recipient (default suite: pqbox-max). The plaintext is wiped on drop.
let recipient = generate?;
let sealed = seal?;
assert_eq!;
// Composite signature: every component must verify.
let signer = generate?;
let sig = signer.sign?;
signer.public_key.verify?;
// Keys serialize with a versioned header. Parsers accept pqbox-max only by default.
let bytes = recipient.public_key.to_bytes;
assert_eq!;
// Other suites must be allowed explicitly.
let legacy = generate?;
let bytes = legacy.public_key.to_bytes;
assert!; // SuiteNotAllowed
let policy = DEFAULT.allow;
let pk = from_bytes_with_policy?;
// A key derived from a password: store the salt (and the costs) with the data, and derive the
// same key again later. Argon2id, 64 MiB, 3 passes, 1 lane by default; the key is wiped on drop.
let salt = generate_salt;
let key = derive_key?;
let ct = encrypt?;
# Ok::
Python
, = # "pqbox-max"
=
assert == b
, =
=
assert
# Suites other than pqbox-max are read only when allowed explicitly.
, =
=
assert
=
=
assert == b
=
assert
# A key derived from a password and a stored salt (Argon2id, same defaults as password_hash).
= # 16 random bytes: store them with the data
= # 32 bytes
assert ==
JavaScript / TypeScript
import { kemKeygen, seal, open, signKeygen, sign, verify, blake3, passwordDeriveKey, passwordGenerateSalt } from "pqbox";
const { publicKey, secretKey } = kemKeygen(); // "pqbox-max"
const box = seal(publicKey, new TextEncoder().encode("hello"));
console.log(new TextDecoder().decode(open(secretKey, box)));
const signer = signKeygen("pqbox-max");
const msg = new TextEncoder().encode("release v1.2.3");
const sig = sign(signer.secretKey, msg);
console.log(verify(signer.publicKey, msg, sig)); // true
console.log(blake3(msg));
// Suites other than pqbox-max are read only when allowed explicitly.
const legacy = kemKeygen("xwing");
const box2 = seal(legacy.publicKey, msg, { allowSuites: ["xwing"] });
open(legacy.secretKey, box2, { allowSuites: ["xwing"] });
// A key derived from a password and a stored salt (Argon2id, same defaults as passwordHash).
const salt = passwordGenerateSalt(); // 16 random bytes: store them with the data
const key = passwordDeriveKey("correct horse battery staple", salt); // 32 bytes
Errors are thrown as PqboxError (in Python, raised as pqbox.PqboxError, a ValueError). They
carry a stable code such as Decrypt, BadSignature, SuiteMismatch, SuiteNotAllowed or
UnsupportedVersion.
CLI
# Other suites must be allowed when their objects are read (paranoid needs `--features paranoid`).
selftest runs a seal/open and a sign/verify round trip for pqbox-max and xwing, checks that
a tampered box and a tampered signature are refused, and replays the frozen known answers built
into the binary (the xwing and pqbox-max entries of
tests/vectors/pqbox/kat.json).
Keys, boxes and signatures are base64 text by default, or raw bytes with --raw. Both forms are
accepted as input.
Secret keys and decrypted plaintext written to a file get mode 0600 on Unix. Every file is written
atomically (a temporary file in the same directory, flushed, then renamed into place), so
keygen --force or open -o over an existing world-readable file never leaves the secret readable
by others.
Wire format
Every object is "PQB" ‖ version (0x02) ‖ type ‖ suite ‖ body. Types: KEM public key 0x01,
KEM secret key 0x02, KEM ciphertext 0x03, signing public key 0x11, signing secret key
0x12, signature 0x13, sealed box 0x21, AEAD ciphertext 0x31 (where the suite byte is the
cipher: 0x01 XChaCha20-Poly1305, 0x02 AES-256-GCM). Parsers dispatch on the version and
reject unknown versions with UnsupportedVersion, so future versions can be added while older
objects stay readable. Version 2 is the first released format; the pre-release version 1 is not
read. A pqbox-paranoid KEM secret key ends with the fingerprint (SHA3-256) of its whole public
key, checked when it is parsed, so an embedded McEliece public key that does not belong to the key
is refused. The body layouts are documented in format.rs,
kem.rs, sign.rs and
seal.rs.
Testing
- Official vectors only (see
tests/vectors/README.md):- X-Wing draft vectors;
- IETF LAMPS ML-KEM/ML-DSA examples;
- NIST ACVP SLH-DSA-SHAKE-256s;
- Wycheproof for XChaCha20-Poly1305, AES-GCM, HKDF, HMAC, Ed25519, X25519, ECDH and ECDSA P-384, ML-KEM (key generation, decapsulation, and encapsulation through pqbox's own key parser) and ML-DSA (verification and signing);
- the RFC vectors.
- Frozen pqbox 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 X25519 and P-384 keys, and each signature component failing on its own.
- Property tests (proptest), cargo-fuzz targets for every parser plus round trips, and criterion benches.
- Instruction-count benchmarks (gungraun, under Callgrind) of
pqbox-maxand the AEADs: every pull request is measured against its base branch, and CI fails if any benchmark runs more than 10% more instructions. - A cross-language interop matrix (
scripts/interop.sh): keys from Rust, Python and JavaScript seal and sign for each other, in every suite.
Security notes
- The post-quantum crates are not independently audited.
ml-kem,ml-dsa,x-wingandslh-dsa(a release candidate) come from RustCrypto, which has not had them audited, andclassic-mceliece-rustis a community crate.libcrux-ml-kem(ML-KEM-1024) is partly formally verified (panic freedom and functional correctness of most of its code, not constant time; see docs/BACKENDS.md) but has no public audit either. pqbox itself has not been audited. - Why bother now: harvest now, decrypt later. No practical break of RSA is publicly known, and no cryptographically relevant quantum computer is known to exist. Data recorded today, however, can be decrypted whenever one appears. Hybrids protect it against that while keeping a classical safety net.
- Password hash limits. The costs in a PHC string come from whoever wrote it, so
verify_password(Pythonpassword_verify, JavaScriptpasswordVerify) refuses strings above 256 MiB, 10 passes or 8 lanes before allocating anything;hash_passwordholds itself to the same limits. At the limits one verification takes 256 MiB and about a second of CPU. To accept more expensive hashes from a trusted source, raise the limits explicitly:verify_password_with_limitsin Rust,max_m_cost/max_t_cost/max_p_costin Python,{ maxMCost, maxTCost, maxPCost }in JavaScript. - Keys derived from passwords.
password::derive_key(Pythonpassword_derive_key, JavaScriptpasswordDeriveKey) is plain Argon2id (version 0x13, no secret, no associated data), so it matches other Argon2 libraries given the same inputs. It needs a salt of at least 16 bytes (generate_saltmakes one; store it, and the costs, next to the data) and derives 16 to 64 bytes, 32 by default. The costs default to 64 MiB, 3 passes and 1 lane, and are held to the same limits as verification, with the same opt-in to raise them. Choose the highest memory cost your slowest target can afford (RFC 9106 suggests 64 MiB with 3 passes when 2 GiB is too much), and never lower the costs of existing data. There is no context input: keep keys for different purposes apart with distinct salts, or derive one key and expand it with HKDF-SHA-256 using oneinfolabel per purpose. - AES-256-GCM nonce limit.
encryptdraws a random nonce per message. AES-256-GCM's nonce is 96 bits, so encrypt at most about 2^32 messages under one key (NIST SP 800-38D) and rotate it after that. XChaCha20-Poly1305, the default, has a 192-bit nonce and no practical limit: prefer it for long-lived keys. Sealed boxes use XChaCha20-Poly1305 with a fresh key each time. - Sealed boxes are anonymous; they do not authenticate the sender. Sign the plaintext if the recipient needs to know who sent it.
- Read THREAT_MODEL.md for what is and is not protected, and SECURITY.md to report a vulnerability.
Upstream
pqbox stands on these projects. The versions are pinned in the Cargo.toml files (exactly, with
=, for every cryptographic crate); Dependabot proposes updates, and a weekly
upstream watch reports advisories, new releases and
alternatives (scripts/watch/). docs/BACKENDS.md compares
the backends with the alternatives (RustCrypto, libcrux and AWS-LC), and explains the move of
ML-KEM-1024 to libcrux.
Cryptography (crate pqbox)
| Crate | Purpose | Repository | crates.io | Implements |
|---|---|---|---|---|
libcrux-ml-kem |
ML-KEM-1024 (pqbox-max, pqbox-paranoid), portable build; formally verified with hax and F* (verification status) |
cryspen/libcrux | libcrux-ml-kem | FIPS 203 |
ml-kem |
ML-KEM-768 (inside X-Wing) | RustCrypto/KEMs | ml-kem | FIPS 203 |
x-wing |
X-Wing KEM (xwing suite) |
RustCrypto/KEMs | x-wing | draft-connolly-cfrg-xwing-kem |
classic-mceliece-rust |
Classic McEliece 8192128 (paranoid) |
Colfenor/classic-mceliece-rust | classic-mceliece-rust | Classic McEliece NIST submission |
ml-dsa |
ML-DSA-65 / ML-DSA-87 | RustCrypto/signatures | ml-dsa | FIPS 204 |
slh-dsa |
SLH-DSA-SHAKE-256s (paranoid) |
RustCrypto/signatures | slh-dsa | FIPS 205 |
p384 |
ECDH and ECDSA P-384 (classical half of pqbox-max) |
RustCrypto/elliptic-curves | p384 | FIPS 186-5 (ECDSA), SP 800-56A Rev. 3 (ECDH), SP 800-186 (the curve) |
x25519-dalek |
X25519 (inside X-Wing) | dalek-cryptography/curve25519-dalek | x25519-dalek | RFC 7748 |
ed25519-dalek |
Ed25519 (classical half of xwing signatures) |
dalek-cryptography/curve25519-dalek | ed25519-dalek | RFC 8032 |
chacha20poly1305 |
XChaCha20-Poly1305 (AEAD, sealed boxes) | RustCrypto/AEADs | chacha20poly1305 | RFC 8439, draft-irtf-cfrg-xchacha |
aes-gcm |
AES-256-GCM | RustCrypto/AEADs | aes-gcm | FIPS 197, SP 800-38D |
hkdf |
HKDF-SHA-256 | RustCrypto/KDFs | hkdf | RFC 5869 |
hmac |
HMAC-SHA-256 | RustCrypto/MACs | hmac | RFC 2104, FIPS 198-1 |
sha2 |
SHA-256, SHA-384, SHA-512 | RustCrypto/hashes | sha2 | FIPS 180-4 |
sha3 |
SHA3-256 (KEM combiners, fingerprints) | RustCrypto/hashes | sha3 | FIPS 202 |
blake3 |
BLAKE3 | BLAKE3-team/BLAKE3 | blake3 | BLAKE3 specification |
argon2 |
Argon2id, PHC strings | RustCrypto/password-hashes | argon2 | RFC 9106, PHC string format |
subtle |
Constant-time comparisons | dalek-cryptography/subtle | subtle | |
zeroize |
Wiping secrets from memory | RustCrypto/utils | zeroize | |
rand_core |
The RNG traits every function takes | rust-random/rand_core | rand_core | |
getrandom |
The operating system's CSPRNG (CLI, bindings, tests) | rust-random/getrandom | getrandom | |
thiserror |
Error type | dtolnay/thiserror | thiserror |
The composite signatures follow
draft-ietf-lamps-pq-composite-sigs-19
(since published as RFC 10073); the pqbox-max and
pqbox-paranoid KEM combiners are pqbox's own (see Suites).
CLI and bindings
| Crate or tool | Purpose | Repository | Registry |
|---|---|---|---|
clap |
CLI argument parsing | clap-rs/clap | crates.io |
base64ct |
Constant-time base64 for keys and boxes | RustCrypto/formats | crates.io |
serde_json |
pqbox selftest: embedded known answers, --json report |
serde-rs/json | crates.io |
pyo3 |
Python bindings | PyO3/pyo3 | crates.io |
maturin |
Builds and publishes the Python wheels | PyO3/maturin | crates.io, PyPI |
wasm-bindgen |
WebAssembly bindings for the npm package | wasm-bindgen/wasm-bindgen | crates.io |
js-sys |
JavaScript types for the WebAssembly bindings | wasm-bindgen/wasm-bindgen | crates.io |
criterion |
Timing benchmarks | criterion-rs/criterion.rs | crates.io |
gungraun |
Instruction-count benchmarks (the CI regression gate) | gungraun/gungraun | crates.io |
proptest |
Property tests | proptest-rs/proptest | crates.io |
cargo-fuzz |
Fuzzing (libFuzzer) | rust-fuzz/cargo-fuzz | crates.io |
Test vectors
Listed with their exact revisions in tests/vectors/README.md:
- NIST ACVP-Server (SLH-DSA key generation and verification);
- C2SP/wycheproof (AEADs, HKDF, HMAC, Ed25519, X25519, P-384, ML-KEM, ML-DSA);
- the X-Wing draft's test vectors;
- the IETF LAMPS examples for ML-KEM and ML-DSA keys;
- the RFC vectors cited next to each test.
License
MIT © maxgfr