pqbox 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 maxgfr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,413 @@
1
- # Temporary Holding Version
1
+ # pqbox
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A post-quantum crypto toolkit with a Rust core and bindings for Python and JavaScript. It covers
4
+ hybrid key encapsulation, sealed boxes, composite signatures, authenticated encryption, key
5
+ derivation, hashing and password hashing.
6
+
7
+ pqbox implements no cryptographic primitive itself. Every algorithm comes from a pinned crate,
8
+ mostly from [RustCrypto](https://github.com/RustCrypto), plus Cryspen's formally verified
9
+ [libcrux](https://github.com/cryspen/libcrux) for ML-KEM-1024 and `classic-mceliece-rust` for
10
+ Classic McEliece. pqbox only adds the hybrid combiners, the composite signature framing and a versioned
11
+ wire format.
12
+
13
+ - **Rust:** crate [`pqbox`](crates/pqbox-core) (sans-IO, `#![forbid(unsafe_code)]`) and the CLI [`pqbox-cli`](crates/pqbox-cli).
14
+ - **Python:** package `pqbox` on PyPI, built with PyO3 (abi3, Python ≥ 3.10).
15
+ - **JavaScript / TypeScript:** package `pqbox` on npm, built with WebAssembly (Node ≥ 20 and browsers, ESM, synchronous API).
16
+
17
+ ## Suites
18
+
19
+ Every key, ciphertext, sealed box and signature records its suite in its header, so objects from
20
+ different suites can never be mixed.
21
+
22
+ | Id | Name | KEM | Signature | Use it for |
23
+ |---|---|---|---|---|
24
+ | `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 |
25
+ | `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 |
26
+ | `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 |
27
+
28
+ **Suite policy.** The functions that read keys, ciphertexts, signatures and sealed boxes accept
29
+ `pqbox-max` objects only. `xwing` and `pqbox-paranoid` objects are refused with
30
+ `SuiteNotAllowed` unless the caller allows their suite explicitly, so an attacker cannot steer a
31
+ caller onto a suite it did not choose (for instance by handing over an `xwing` public key):
32
+
33
+ - Rust: `from_bytes_with_policy` and `open_with_policy` with a `SuitePolicy` such as
34
+ `SuitePolicy::DEFAULT.allow(Suite::XWing)` (`from_bytes` and `open` use `SuitePolicy::DEFAULT`);
35
+ - Python: the keyword-only `allow_suites=["xwing"]` argument;
36
+ - JavaScript: the `{ allowSuites: ["xwing"] }` option;
37
+ - CLI: `--allow-suite xwing` (repeatable) on `seal`, `open`, `sign` and `verify`.
38
+
39
+ Key generation takes the suite by name and needs no policy.
40
+
41
+ **The `paranoid` feature.** `pqbox-paranoid` is **experimental**: its SLH-DSA half comes from
42
+ `slh-dsa` 0.2.0-rc.5, a release candidate. The Rust crates compile it only with the `paranoid`
43
+ cargo feature, off by default (`cargo add pqbox --features paranoid`,
44
+ `cargo install pqbox-cli --features paranoid`); without it, paranoid objects are refused with
45
+ `SuiteNotEnabled`. The Python wheels and the npm package include it: it adds about 66 KB to a
46
+ wheel (542 KB to 608 KB, macOS arm64) and about 67 KB to the WebAssembly module (801 KB to 868 KB
47
+ before wasm-bindgen).
48
+
49
+ **Hybrid rationale.** A hybrid stays secure as long as one of its components holds. KEM shared
50
+ secrets go through a combiner, so recovering the session key means breaking every component.
51
+ A composite signature verifies only if every component signature verifies.
52
+
53
+ - `pqbox-max` rests on ML-KEM-1024 and ML-DSA-87 (NIST category 5). The classical half is defense
54
+ in depth: if elliptic-curve cryptography (or RSA) were broken outright, security would still rest
55
+ on ML-KEM-1024 and ML-DSA-87. The classical half is P-384 rather than X25519 or Ed25519. P-384 is a
56
+ stronger classical fallback, and it is the curve the NSA's December 2, 2026 advisory (PP-26-4956)
57
+ keeps as an interim choice. That advisory lists elliptic curves other than P-384/P-521, and
58
+ EdDSA, among the algorithms to inventory and replace. Some cryptographers read it as a sign that
59
+ 256-bit curves may be weaker than believed. The advisory itself does not say they are broken.
60
+ - `pqbox-paranoid` also survives a break of lattice cryptography. Classic McEliece (code-based) and
61
+ SLH-DSA (hash-based) do not rely on lattices.
62
+ - `xwing` exists only for compatibility. Its classical half is a 256-bit curve, so treat its
63
+ security as resting entirely on ML-KEM-768 and ML-DSA-65.
64
+
65
+ The `pqbox-max` and `pqbox-paranoid` KEM combiners are modeled on X-Wing but are **not**
66
+ IETF-standardized:
67
+
68
+ ```text
69
+ pqbox-max: ss = SHA3-256(ss_mlkem ‖ ss_p384 ‖ ct_p384 ‖ pk_p384 ‖ "pqbox/v1/kem-max")
70
+ pqbox-paranoid: ss = SHA3-256(ss_mlkem ‖ ss_mceliece ‖ ss_p384 ‖ ct_p384 ‖ pk_p384
71
+ ‖ SHA3-256(ct_mlkem) ‖ SHA3-256(ct_mceliece) ‖ "pqbox/v1/kem-paranoid")
72
+ ```
73
+
74
+ Signatures follow the IETF composite ML-DSA draft (draft-ietf-lamps-pq-composite-sigs-19): the
75
+ message representative is `"CompositeAlgorithmSignatures2025" ‖ Label ‖ len(ctx) ‖ ctx ‖ SHA-512(M)`,
76
+ using the draft's labels for `xwing` and `pqbox-max` and a pqbox-specific label for
77
+ `pqbox-paranoid`. The deviations are documented in [`sign.rs`](crates/pqbox-core/src/sign.rs):
78
+ pqbox's own encodings instead of ASN.1, a fixed-length low-`s` ECDSA `r‖s`, and the signer's key
79
+ fingerprint bound in `ctx`.
80
+
81
+ Composite signatures are **strongly unforgeable** (SUF-CMA): nobody can produce a second valid
82
+ signature of a message that was signed, not just a signature of a new message. Every component
83
+ has a single valid encoding per signing operation: ML-DSA and SLH-DSA are designed to be strongly
84
+ unforgeable, Ed25519 is verified strictly, and the ECDSA `s` must be in the lower half of the group
85
+ order (signing normalizes it; the malleable `n - s` twin is refused).
86
+
87
+ ## Algorithms
88
+
89
+ | Purpose | Algorithm | Crate |
90
+ |---|---|---|
91
+ | KEM | ML-KEM-1024 (FIPS 203), in `pqbox-max` and `pqbox-paranoid` | `libcrux-ml-kem` 0.0.12 (portable build) |
92
+ | KEM | ML-KEM-768 (FIPS 203), inside X-Wing | `ml-kem` 0.3.4 |
93
+ | KEM | X-Wing (draft-connolly-cfrg-xwing-kem) | `x-wing` 0.1.1 |
94
+ | KEM | Classic McEliece 8192128 | `classic-mceliece-rust` 3.1.0 |
95
+ | KEM (classical half) | ECDH P-384, X25519 | `p384` 0.14.0, `x25519-dalek` 3.0.0 |
96
+ | Signature | ML-DSA-65 / ML-DSA-87 (FIPS 204) | `ml-dsa` 0.1.2 |
97
+ | Signature | SLH-DSA-SHAKE-256s (FIPS 205), `paranoid` feature only, experimental | `slh-dsa` 0.2.0-rc.5 (release candidate) |
98
+ | Signature (classical half) | ECDSA P-384 with SHA-384, Ed25519 | `p384` 0.14.0, `ed25519-dalek` 3.0.0 |
99
+ | Sealed box | suite KEM + HKDF-SHA-256 + XChaCha20-Poly1305 | |
100
+ | AEAD | XChaCha20-Poly1305 (default), AES-256-GCM | `chacha20poly1305` 0.11.0, `aes-gcm` 0.11.1 |
101
+ | KDF / MAC | HKDF-SHA-256, HMAC-SHA-256 | `hkdf` 0.13.0, `hmac` 0.13.0 |
102
+ | Hash | SHA-256, SHA3-256, BLAKE3 | `sha2` 0.11.1, `sha3` 0.12.0, `blake3` 1.8.9 |
103
+ | 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 |
104
+
105
+ Symmetric keys are always 256-bit.
106
+
107
+ ## Sizes and timings
108
+
109
+ Sizes are of serialized objects and include the 6-byte header. Timings are medians from
110
+ `cargo bench -p pqbox` (criterion, release build) on an Apple M5 laptop (rustc 1.99.0); they
111
+ show orders of magnitude, not guarantees.
112
+
113
+ | Suite | KEM public key | KEM secret key | KEM ciphertext | Sealed-box overhead | Signing public key | Signing secret key | Signature |
114
+ |---|---:|---:|---:|---:|---:|---:|---:|
115
+ | `xwing` | 1,222 B | 38 B | 1,126 B | 1,166 B | 1,990 B | 70 B | 3,379 B |
116
+ | `pqbox-max` | 1,671 B | 118 B | 1,671 B | 1,711 B | 2,695 B | 86 B | 4,729 B |
117
+ | `pqbox-paranoid` | 1,359,495 B | 1,372,094 B | 1,879 B | 1,919 B | 2,759 B | 214 B | 34,521 B |
118
+
119
+ | Suite | KEM keygen | Encapsulate | Decapsulate | Seal 1 KiB | Open 1 KiB | Sign keygen | Sign | Verify |
120
+ |---|---:|---:|---:|---:|---:|---:|---:|---:|
121
+ | `xwing` | 53 µs | 50 µs | 80 µs | 54 µs | 83 µs | 264 µs | 378 µs | 61 µs |
122
+ | `pqbox-max` | 311 µs | 607 µs | 642 µs | 595 µs | 601 µs | 730 µs | 775 µs | 446 µs |
123
+ | `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 |
124
+
125
+ Paranoid KEM key generation varies a lot from run to run (0.74 s to 1.20 s here), because Classic
126
+ McEliece retries until it finds a usable key. In WebAssembly under Node 24, the paranoid KEM key
127
+ generation took 6.5 to 11.6 s. Symmetric primitives on 64 KiB:
128
+ XChaCha20-Poly1305 62 µs, AES-256-GCM 14 µs, SHA-256 20 µs, SHA3-256 59 µs, BLAKE3 26 µs.
129
+
130
+ ## Install
131
+
132
+ ```sh
133
+ cargo add pqbox # Rust library (add `--features paranoid` for pqbox-paranoid)
134
+ cargo install pqbox-cli # `pqbox` command (same feature)
135
+ pip install pqbox # Python ≥ 3.10
136
+ npm install pqbox # Node ≥ 20, browsers
137
+ ```
138
+
139
+ Each GitHub release also carries prebuilt `pqbox` binaries, `pqbox-<target>` for macOS (arm64,
140
+ x86_64) and Linux (arm64, x86_64), with a `SHA256SUMS` file. `pqbox --version` reports the release,
141
+ and `pqbox selftest` checks the installed binary offline.
142
+
143
+ ## Examples
144
+
145
+ ### Rust
146
+
147
+ ```rust
148
+ use pqbox::{Suite, SuitePolicy, aead, kem, password, seal, sign};
149
+ use rand_core::UnwrapErr;
150
+
151
+ let mut rng = UnwrapErr(getrandom::SysRng); // getrandom 0.4 with the `sys_rng` feature
152
+
153
+ // Sealed box to a recipient (default suite: pqbox-max). The plaintext is wiped on drop.
154
+ let recipient = kem::SecretKey::generate(Suite::default(), &mut rng)?;
155
+ let sealed = seal::seal(recipient.public_key(), b"hello", &mut rng)?;
156
+ assert_eq!(*seal::open(&recipient, &sealed)?, b"hello");
157
+
158
+ // Composite signature: every component must verify.
159
+ let signer = sign::SecretKey::generate(Suite::Max, &mut rng)?;
160
+ let sig = signer.sign(b"release v1.2.3", &mut rng)?;
161
+ signer.public_key().verify(b"release v1.2.3", &sig)?;
162
+
163
+ // Keys serialize with a versioned header. Parsers accept pqbox-max only by default.
164
+ let bytes = recipient.public_key().to_bytes();
165
+ assert_eq!(kem::PublicKey::from_bytes(&bytes)?.to_bytes(), bytes);
166
+
167
+ // Other suites must be allowed explicitly.
168
+ let legacy = kem::SecretKey::generate(Suite::XWing, &mut rng)?;
169
+ let bytes = legacy.public_key().to_bytes();
170
+ assert!(kem::PublicKey::from_bytes(&bytes).is_err()); // SuiteNotAllowed
171
+ let policy = SuitePolicy::DEFAULT.allow(Suite::XWing);
172
+ let pk = kem::PublicKey::from_bytes_with_policy(&bytes, policy)?;
173
+
174
+ // A key derived from a password: store the salt (and the costs) with the data, and derive the
175
+ // same key again later. Argon2id, 64 MiB, 3 passes, 1 lane by default; the key is wiped on drop.
176
+ let salt = password::generate_salt(&mut rng);
177
+ let key = password::derive_key(b"correct horse battery staple", &salt, password::Params::default(), 32)?;
178
+ let ct = aead::encrypt(aead::Algorithm::XChaCha20Poly1305, key.as_bytes(), b"data", b"header", &mut rng)?;
179
+ # Ok::<(), pqbox::Error>(())
180
+ ```
181
+
182
+ ### Python
183
+
184
+ ```python
185
+ import pqbox
186
+
187
+ pk, sk = pqbox.kem_keygen() # "pqbox-max"
188
+ box = pqbox.seal(pk, b"hello")
189
+ assert pqbox.open(sk, box) == b"hello"
190
+
191
+ spk, ssk = pqbox.sign_keygen()
192
+ sig = pqbox.sign(ssk, b"release v1.2.3")
193
+ assert pqbox.verify(spk, b"release v1.2.3", sig)
194
+
195
+ # Suites other than pqbox-max are read only when allowed explicitly.
196
+ apk, ask = pqbox.sign_keygen("pqbox-paranoid")
197
+ sig = pqbox.sign(ask, b"archive", allow_suites=["pqbox-paranoid"])
198
+ assert pqbox.verify(apk, b"archive", sig, allow_suites=["pqbox-paranoid"])
199
+
200
+ key = pqbox.generate_key()
201
+ ct = pqbox.encrypt(key, b"data", aad=b"header")
202
+ assert pqbox.decrypt(key, ct, aad=b"header") == b"data"
203
+
204
+ phc = pqbox.password_hash("correct horse battery staple")
205
+ assert pqbox.password_verify("correct horse battery staple", phc)
206
+
207
+ # A key derived from a password and a stored salt (Argon2id, same defaults as password_hash).
208
+ salt = pqbox.password_generate_salt() # 16 random bytes: store them with the data
209
+ key = pqbox.password_derive_key("correct horse battery staple", salt) # 32 bytes
210
+ assert pqbox.password_derive_key("correct horse battery staple", salt) == key
211
+ ```
212
+
213
+ ### JavaScript / TypeScript
214
+
215
+ ```ts
216
+ import { kemKeygen, seal, open, signKeygen, sign, verify, blake3, passwordDeriveKey, passwordGenerateSalt } from "pqbox";
217
+
218
+ const { publicKey, secretKey } = kemKeygen(); // "pqbox-max"
219
+ const box = seal(publicKey, new TextEncoder().encode("hello"));
220
+ console.log(new TextDecoder().decode(open(secretKey, box)));
221
+
222
+ const signer = signKeygen("pqbox-max");
223
+ const msg = new TextEncoder().encode("release v1.2.3");
224
+ const sig = sign(signer.secretKey, msg);
225
+ console.log(verify(signer.publicKey, msg, sig)); // true
226
+
227
+ console.log(blake3(msg));
228
+
229
+ // Suites other than pqbox-max are read only when allowed explicitly.
230
+ const legacy = kemKeygen("xwing");
231
+ const box2 = seal(legacy.publicKey, msg, { allowSuites: ["xwing"] });
232
+ open(legacy.secretKey, box2, { allowSuites: ["xwing"] });
233
+
234
+ // A key derived from a password and a stored salt (Argon2id, same defaults as passwordHash).
235
+ const salt = passwordGenerateSalt(); // 16 random bytes: store them with the data
236
+ const key = passwordDeriveKey("correct horse battery staple", salt); // 32 bytes
237
+ ```
238
+
239
+ Errors are thrown as `PqboxError` (in Python, raised as `pqbox.PqboxError`, a `ValueError`). They
240
+ carry a stable `code` such as `Decrypt`, `BadSignature`, `SuiteMismatch`, `SuiteNotAllowed` or
241
+ `UnsupportedVersion`.
242
+
243
+ ### CLI
244
+
245
+ ```sh
246
+ pqbox keygen kem -o alice # alice.pub, alice.sec (0600), suite pqbox-max
247
+ pqbox seal --to alice.pub -i secret.txt -o secret.box
248
+ pqbox open --key alice.sec -i secret.box
249
+
250
+ pqbox keygen sign -o release
251
+ pqbox sign --key release.sec -i dist.tar -o dist.tar.sig
252
+ pqbox verify --key release.pub --sig dist.tar.sig -i dist.tar # exit 0 if valid, 1 if not
253
+
254
+ # Other suites must be allowed when their objects are read (paranoid needs `--features paranoid`).
255
+ pqbox keygen kem --suite xwing -o legacy
256
+ pqbox seal --allow-suite xwing --to legacy.pub -i secret.txt -o secret.box
257
+
258
+ pqbox hash --alg blake3 -i dist.tar
259
+ pqbox info alice.pub
260
+
261
+ pqbox selftest # offline, well under a second; exit 0 if every check passes
262
+ pqbox selftest --json
263
+ ```
264
+
265
+ `selftest` runs a seal/open and a sign/verify round trip for `pqbox-max` and `xwing`, checks that
266
+ a tampered box and a tampered signature are refused, and replays the frozen known answers built
267
+ into the binary (the `xwing` and `pqbox-max` entries of
268
+ [`tests/vectors/pqbox/kat.json`](crates/pqbox-core/tests/vectors/pqbox/kat.json)).
269
+
270
+ Keys, boxes and signatures are base64 text by default, or raw bytes with `--raw`. Both forms are
271
+ accepted as input.
272
+
273
+ Secret keys and decrypted plaintext written to a file get mode 0600 on Unix. Every file is written
274
+ atomically (a temporary file in the same directory, flushed, then renamed into place), so
275
+ `keygen --force` or `open -o` over an existing world-readable file never leaves the secret readable
276
+ by others.
277
+
278
+ ## Wire format
279
+
280
+ Every object is `"PQB" ‖ version (0x02) ‖ type ‖ suite ‖ body`. Types: KEM public key `0x01`,
281
+ KEM secret key `0x02`, KEM ciphertext `0x03`, signing public key `0x11`, signing secret key
282
+ `0x12`, signature `0x13`, sealed box `0x21`, AEAD ciphertext `0x31` (where the suite byte is the
283
+ cipher: `0x01` XChaCha20-Poly1305, `0x02` AES-256-GCM). Parsers dispatch on the version and
284
+ reject unknown versions with `UnsupportedVersion`, so future versions can be added while older
285
+ objects stay readable. Version 2 is the first released format; the pre-release version 1 is not
286
+ read. A `pqbox-paranoid` KEM secret key ends with the fingerprint (SHA3-256) of its whole public
287
+ key, checked when it is parsed, so an embedded McEliece public key that does not belong to the key
288
+ is refused. The body layouts are documented in [`format.rs`](crates/pqbox-core/src/format.rs),
289
+ [`kem.rs`](crates/pqbox-core/src/kem.rs), [`sign.rs`](crates/pqbox-core/src/sign.rs) and
290
+ [`seal.rs`](crates/pqbox-core/src/seal.rs).
291
+
292
+ ## Testing
293
+
294
+ - Official vectors only (see [`tests/vectors/README.md`](crates/pqbox-core/tests/vectors/README.md)):
295
+ - X-Wing draft vectors;
296
+ - IETF LAMPS ML-KEM/ML-DSA examples;
297
+ - NIST ACVP SLH-DSA-SHAKE-256s;
298
+ - 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);
299
+ - the RFC vectors.
300
+ - Frozen pqbox known answers for the combiners, sealed boxes and composite signatures of every suite, generated once and checked in Rust, Python and JavaScript.
301
+ - 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.
302
+ - Property tests (proptest), cargo-fuzz targets for every parser plus round trips, and criterion benches.
303
+ - Instruction-count benchmarks ([gungraun](https://github.com/gungraun/gungraun), under Callgrind) of `pqbox-max` and the AEADs: every pull request is measured against its base branch, and CI fails if any benchmark runs more than 10% more instructions.
304
+ - A cross-language interop matrix ([`scripts/interop.sh`](scripts/interop.sh)): keys from Rust, Python and JavaScript seal and sign for each other, in every suite.
305
+
306
+ ## Security notes
307
+
308
+ - **The post-quantum crates are not independently audited.** `ml-kem`, `ml-dsa`, `x-wing` and
309
+ `slh-dsa` (a release candidate) come from RustCrypto, which has not had them audited, and
310
+ `classic-mceliece-rust` is a community crate. `libcrux-ml-kem` (ML-KEM-1024) is partly formally
311
+ verified (panic freedom and functional correctness of most of its code, not constant time; see
312
+ [docs/BACKENDS.md](docs/BACKENDS.md)) but has no public audit either. pqbox itself has not been
313
+ audited.
314
+ - **Why bother now: harvest now, decrypt later.** No practical break of RSA is publicly known, and
315
+ no cryptographically relevant quantum computer is known to exist. Data recorded today, however,
316
+ can be decrypted whenever one appears. Hybrids protect it against that while keeping a classical
317
+ safety net.
318
+ - **Password hash limits.** The costs in a PHC string come from whoever wrote it, so
319
+ `verify_password` (Python `password_verify`, JavaScript `passwordVerify`) refuses strings above
320
+ 256 MiB, 10 passes or 8 lanes before allocating anything; `hash_password` holds itself to the
321
+ same limits. At the limits one verification takes 256 MiB and about a second of CPU. To accept
322
+ more expensive hashes from a trusted source, raise the limits explicitly:
323
+ `verify_password_with_limits` in Rust, `max_m_cost`/`max_t_cost`/`max_p_cost` in Python,
324
+ `{ maxMCost, maxTCost, maxPCost }` in JavaScript.
325
+ - **Keys derived from passwords.** `password::derive_key` (Python `password_derive_key`,
326
+ JavaScript `passwordDeriveKey`) is plain Argon2id (version 0x13, no secret, no associated
327
+ data), so it matches other Argon2 libraries given the same inputs. It needs a salt of at least
328
+ 16 bytes (`generate_salt` makes one; store it, and the costs, next to the data) and derives 16
329
+ to 64 bytes, 32 by default. The costs default to 64 MiB, 3 passes and 1 lane, and are held to
330
+ the same limits as verification, with the same opt-in to raise them. Choose the highest memory
331
+ cost your slowest target can afford (RFC 9106 suggests 64 MiB with 3 passes when 2 GiB is too
332
+ much), and never lower the costs of existing data. There is no context input: keep keys for
333
+ different purposes apart with distinct salts, or derive one key and expand it with HKDF-SHA-256
334
+ using one `info` label per purpose.
335
+ - **AES-256-GCM nonce limit.** `encrypt` draws a random nonce per message. AES-256-GCM's nonce is
336
+ 96 bits, so encrypt at most about 2^32 messages under one key (NIST SP 800-38D) and rotate it
337
+ after that. XChaCha20-Poly1305, the default, has a 192-bit nonce and no practical limit: prefer
338
+ it for long-lived keys. Sealed boxes use XChaCha20-Poly1305 with a fresh key each time.
339
+ - Sealed boxes are anonymous; they do not authenticate the sender. Sign the plaintext if the
340
+ recipient needs to know who sent it.
341
+ - Read [THREAT_MODEL.md](THREAT_MODEL.md) for what is and is not protected, and
342
+ [SECURITY.md](SECURITY.md) to report a vulnerability.
343
+
344
+ ## Upstream
345
+
346
+ pqbox stands on these projects. The versions are pinned in the `Cargo.toml` files (exactly, with
347
+ `=`, for every cryptographic crate); Dependabot proposes updates, and a weekly
348
+ [upstream watch](.github/workflows/upstream-watch.yml) reports advisories, new releases and
349
+ alternatives ([`scripts/watch/`](scripts/watch)). [`docs/BACKENDS.md`](docs/BACKENDS.md) compares
350
+ the backends with the alternatives (RustCrypto, libcrux and AWS-LC), and explains the move of
351
+ ML-KEM-1024 to libcrux.
352
+
353
+ ### Cryptography (crate `pqbox`)
354
+
355
+ | Crate | Purpose | Repository | crates.io | Implements |
356
+ |---|---|---|---|---|
357
+ | `libcrux-ml-kem` | ML-KEM-1024 (`pqbox-max`, `pqbox-paranoid`), portable build; formally verified with [hax](https://github.com/cryspen/hax) and F* ([verification status](https://github.com/cryspen/libcrux/blob/libcrux-ml-kem-v0.0.12/libcrux-ml-kem/proofs/verification_status.md)) | [cryspen/libcrux](https://github.com/cryspen/libcrux/tree/main/libcrux-ml-kem) | [libcrux-ml-kem](https://crates.io/crates/libcrux-ml-kem) | [FIPS 203](https://csrc.nist.gov/pubs/fips/203/final) |
358
+ | `ml-kem` | ML-KEM-768 (inside X-Wing) | [RustCrypto/KEMs](https://github.com/RustCrypto/KEMs/tree/master/ml-kem) | [ml-kem](https://crates.io/crates/ml-kem) | [FIPS 203](https://csrc.nist.gov/pubs/fips/203/final) |
359
+ | `x-wing` | X-Wing KEM (`xwing` suite) | [RustCrypto/KEMs](https://github.com/RustCrypto/KEMs/tree/master/x-wing) | [x-wing](https://crates.io/crates/x-wing) | [draft-connolly-cfrg-xwing-kem](https://datatracker.ietf.org/doc/draft-connolly-cfrg-xwing-kem/) |
360
+ | `classic-mceliece-rust` | Classic McEliece 8192128 (`paranoid`) | [Colfenor/classic-mceliece-rust](https://github.com/Colfenor/classic-mceliece-rust) | [classic-mceliece-rust](https://crates.io/crates/classic-mceliece-rust) | [Classic McEliece NIST submission](https://classic.mceliece.org/nist.html) |
361
+ | `ml-dsa` | ML-DSA-65 / ML-DSA-87 | [RustCrypto/signatures](https://github.com/RustCrypto/signatures/tree/master/ml-dsa) | [ml-dsa](https://crates.io/crates/ml-dsa) | [FIPS 204](https://csrc.nist.gov/pubs/fips/204/final) |
362
+ | `slh-dsa` | SLH-DSA-SHAKE-256s (`paranoid`) | [RustCrypto/signatures](https://github.com/RustCrypto/signatures/tree/master/slh-dsa) | [slh-dsa](https://crates.io/crates/slh-dsa) | [FIPS 205](https://csrc.nist.gov/pubs/fips/205/final) |
363
+ | `p384` | ECDH and ECDSA P-384 (classical half of `pqbox-max`) | [RustCrypto/elliptic-curves](https://github.com/RustCrypto/elliptic-curves/tree/master/p384) | [p384](https://crates.io/crates/p384) | [FIPS 186-5](https://csrc.nist.gov/pubs/fips/186-5/final) (ECDSA), [SP 800-56A Rev. 3](https://csrc.nist.gov/pubs/sp/800/56/a/r3/final) (ECDH), [SP 800-186](https://csrc.nist.gov/pubs/sp/800/186/final) (the curve) |
364
+ | `x25519-dalek` | X25519 (inside X-Wing) | [dalek-cryptography/curve25519-dalek](https://github.com/dalek-cryptography/curve25519-dalek/tree/main/x25519-dalek) | [x25519-dalek](https://crates.io/crates/x25519-dalek) | [RFC 7748](https://www.rfc-editor.org/rfc/rfc7748) |
365
+ | `ed25519-dalek` | Ed25519 (classical half of `xwing` signatures) | [dalek-cryptography/curve25519-dalek](https://github.com/dalek-cryptography/curve25519-dalek/tree/main/ed25519-dalek) | [ed25519-dalek](https://crates.io/crates/ed25519-dalek) | [RFC 8032](https://www.rfc-editor.org/rfc/rfc8032) |
366
+ | `chacha20poly1305` | XChaCha20-Poly1305 (AEAD, sealed boxes) | [RustCrypto/AEADs](https://github.com/RustCrypto/AEADs/tree/master/chacha20poly1305) | [chacha20poly1305](https://crates.io/crates/chacha20poly1305) | [RFC 8439](https://www.rfc-editor.org/rfc/rfc8439), [draft-irtf-cfrg-xchacha](https://datatracker.ietf.org/doc/draft-irtf-cfrg-xchacha/) |
367
+ | `aes-gcm` | AES-256-GCM | [RustCrypto/AEADs](https://github.com/RustCrypto/AEADs/tree/master/aes-gcm) | [aes-gcm](https://crates.io/crates/aes-gcm) | [FIPS 197](https://csrc.nist.gov/pubs/fips/197/final), [SP 800-38D](https://csrc.nist.gov/pubs/sp/800/38/d/final) |
368
+ | `hkdf` | HKDF-SHA-256 | [RustCrypto/KDFs](https://github.com/RustCrypto/KDFs/tree/master/hkdf) | [hkdf](https://crates.io/crates/hkdf) | [RFC 5869](https://www.rfc-editor.org/rfc/rfc5869) |
369
+ | `hmac` | HMAC-SHA-256 | [RustCrypto/MACs](https://github.com/RustCrypto/MACs/tree/master/hmac) | [hmac](https://crates.io/crates/hmac) | [RFC 2104](https://www.rfc-editor.org/rfc/rfc2104), [FIPS 198-1](https://csrc.nist.gov/pubs/fips/198-1/final) |
370
+ | `sha2` | SHA-256, SHA-384, SHA-512 | [RustCrypto/hashes](https://github.com/RustCrypto/hashes/tree/master/sha2) | [sha2](https://crates.io/crates/sha2) | [FIPS 180-4](https://csrc.nist.gov/pubs/fips/180-4/upd1/final) |
371
+ | `sha3` | SHA3-256 (KEM combiners, fingerprints) | [RustCrypto/hashes](https://github.com/RustCrypto/hashes/tree/master/sha3) | [sha3](https://crates.io/crates/sha3) | [FIPS 202](https://csrc.nist.gov/pubs/fips/202/final) |
372
+ | `blake3` | BLAKE3 | [BLAKE3-team/BLAKE3](https://github.com/BLAKE3-team/BLAKE3) | [blake3](https://crates.io/crates/blake3) | [BLAKE3 specification](https://github.com/BLAKE3-team/BLAKE3-specs/blob/master/blake3.pdf) |
373
+ | `argon2` | Argon2id, PHC strings | [RustCrypto/password-hashes](https://github.com/RustCrypto/password-hashes/tree/master/argon2) | [argon2](https://crates.io/crates/argon2) | [RFC 9106](https://www.rfc-editor.org/rfc/rfc9106), [PHC string format](https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md) |
374
+ | `subtle` | Constant-time comparisons | [dalek-cryptography/subtle](https://github.com/dalek-cryptography/subtle) | [subtle](https://crates.io/crates/subtle) | |
375
+ | `zeroize` | Wiping secrets from memory | [RustCrypto/utils](https://github.com/RustCrypto/utils/tree/master/zeroize) | [zeroize](https://crates.io/crates/zeroize) | |
376
+ | `rand_core` | The RNG traits every function takes | [rust-random/rand_core](https://github.com/rust-random/rand_core) | [rand_core](https://crates.io/crates/rand_core) | |
377
+ | `getrandom` | The operating system's CSPRNG (CLI, bindings, tests) | [rust-random/getrandom](https://github.com/rust-random/getrandom) | [getrandom](https://crates.io/crates/getrandom) | |
378
+ | `thiserror` | Error type | [dtolnay/thiserror](https://github.com/dtolnay/thiserror) | [thiserror](https://crates.io/crates/thiserror) | |
379
+
380
+ The composite signatures follow
381
+ [draft-ietf-lamps-pq-composite-sigs-19](https://datatracker.ietf.org/doc/draft-ietf-lamps-pq-composite-sigs/19/)
382
+ (since published as [RFC 10073](https://www.rfc-editor.org/rfc/rfc10073)); the `pqbox-max` and
383
+ `pqbox-paranoid` KEM combiners are pqbox's own (see [Suites](#suites)).
384
+
385
+ ### CLI and bindings
386
+
387
+ | Crate or tool | Purpose | Repository | Registry |
388
+ |---|---|---|---|
389
+ | `clap` | CLI argument parsing | [clap-rs/clap](https://github.com/clap-rs/clap) | [crates.io](https://crates.io/crates/clap) |
390
+ | `base64ct` | Constant-time base64 for keys and boxes | [RustCrypto/formats](https://github.com/RustCrypto/formats/tree/master/base64ct) | [crates.io](https://crates.io/crates/base64ct) |
391
+ | `serde_json` | `pqbox selftest`: embedded known answers, `--json` report | [serde-rs/json](https://github.com/serde-rs/json) | [crates.io](https://crates.io/crates/serde_json) |
392
+ | `pyo3` | Python bindings | [PyO3/pyo3](https://github.com/PyO3/pyo3) | [crates.io](https://crates.io/crates/pyo3) |
393
+ | `maturin` | Builds and publishes the Python wheels | [PyO3/maturin](https://github.com/PyO3/maturin) | [crates.io](https://crates.io/crates/maturin), [PyPI](https://pypi.org/project/maturin/) |
394
+ | `wasm-bindgen` | WebAssembly bindings for the npm package | [wasm-bindgen/wasm-bindgen](https://github.com/wasm-bindgen/wasm-bindgen) | [crates.io](https://crates.io/crates/wasm-bindgen) |
395
+ | `js-sys` | JavaScript types for the WebAssembly bindings | [wasm-bindgen/wasm-bindgen](https://github.com/wasm-bindgen/wasm-bindgen/tree/main/crates/js-sys) | [crates.io](https://crates.io/crates/js-sys) |
396
+ | `criterion` | Timing benchmarks | [criterion-rs/criterion.rs](https://github.com/criterion-rs/criterion.rs) | [crates.io](https://crates.io/crates/criterion) |
397
+ | `gungraun` | Instruction-count benchmarks (the CI regression gate) | [gungraun/gungraun](https://github.com/gungraun/gungraun) | [crates.io](https://crates.io/crates/gungraun) |
398
+ | `proptest` | Property tests | [proptest-rs/proptest](https://github.com/proptest-rs/proptest) | [crates.io](https://crates.io/crates/proptest) |
399
+ | `cargo-fuzz` | Fuzzing (libFuzzer) | [rust-fuzz/cargo-fuzz](https://github.com/rust-fuzz/cargo-fuzz) | [crates.io](https://crates.io/crates/cargo-fuzz) |
400
+
401
+ ### Test vectors
402
+
403
+ Listed with their exact revisions in [`tests/vectors/README.md`](crates/pqbox-core/tests/vectors/README.md):
404
+
405
+ - [NIST ACVP-Server](https://github.com/usnistgov/ACVP-Server) (SLH-DSA key generation and verification);
406
+ - [C2SP/wycheproof](https://github.com/C2SP/wycheproof) (AEADs, HKDF, HMAC, Ed25519, X25519, P-384, ML-KEM, ML-DSA);
407
+ - the X-Wing draft's [test vectors](https://github.com/dconnolly/draft-connolly-cfrg-xwing-kem/blob/main/spec/test-vectors.json);
408
+ - the IETF LAMPS examples for [ML-KEM](https://github.com/lamps-wg/kyber-certificates) and [ML-DSA](https://github.com/lamps-wg/dilithium-certificates) keys;
409
+ - the RFC vectors cited next to each test.
410
+
411
+ ## License
412
+
413
+ MIT © maxgfr