pqbox 0.0.0-stage → 1.0.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,381 @@
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 `classic-mceliece-rust` for Classic
9
+ McEliece. pqbox only adds the hybrid combiners, the composite signature framing and a versioned
10
+ wire format.
11
+
12
+ - **Rust:** crate [`pqbox`](crates/pqbox-core) (sans-IO, `#![forbid(unsafe_code)]`) and the CLI [`pqbox-cli`](crates/pqbox-cli).
13
+ - **Python:** package `pqbox` on PyPI, built with PyO3 (abi3, Python ≥ 3.10).
14
+ - **JavaScript / TypeScript:** package `pqbox` on npm, built with WebAssembly (Node ≥ 20 and browsers, ESM, synchronous API).
15
+
16
+ ## Suites
17
+
18
+ Every key, ciphertext, sealed box and signature records its suite in its header, so objects from
19
+ different suites can never be mixed.
20
+
21
+ | Id | Name | KEM | Signature | Use it for |
22
+ |---|---|---|---|---|
23
+ | `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 |
24
+ | `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 |
25
+ | `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 |
26
+
27
+ **Suite policy.** The functions that read keys, ciphertexts, signatures and sealed boxes accept
28
+ `pqbox-max` objects only. `xwing` and `pqbox-paranoid` objects are refused with
29
+ `SuiteNotAllowed` unless the caller allows their suite explicitly, so an attacker cannot steer a
30
+ caller onto a suite it did not choose (for instance by handing over an `xwing` public key):
31
+
32
+ - Rust: `from_bytes_with_policy` and `open_with_policy` with a `SuitePolicy` such as
33
+ `SuitePolicy::DEFAULT.allow(Suite::XWing)` (`from_bytes` and `open` use `SuitePolicy::DEFAULT`);
34
+ - Python: the keyword-only `allow_suites=["xwing"]` argument;
35
+ - JavaScript: the `{ allowSuites: ["xwing"] }` option;
36
+ - CLI: `--allow-suite xwing` (repeatable) on `seal`, `open`, `sign` and `verify`.
37
+
38
+ Key generation takes the suite by name and needs no policy.
39
+
40
+ **The `paranoid` feature.** `pqbox-paranoid` is **experimental**: its SLH-DSA half comes from
41
+ `slh-dsa` 0.2.0-rc.5, a release candidate. The Rust crates compile it only with the `paranoid`
42
+ cargo feature, off by default (`cargo add pqbox --features paranoid`,
43
+ `cargo install pqbox-cli --features paranoid`); without it, paranoid objects are refused with
44
+ `SuiteNotEnabled`. The Python wheels and the npm package include it: it adds about 66 KB to a
45
+ wheel (542 KB to 608 KB, macOS arm64) and about 67 KB to the WebAssembly module (801 KB to 868 KB
46
+ before wasm-bindgen).
47
+
48
+ **Hybrid rationale.** A hybrid stays secure as long as one of its components holds. KEM shared
49
+ secrets go through a combiner, so recovering the session key means breaking every component.
50
+ A composite signature verifies only if every component signature verifies.
51
+
52
+ - `pqbox-max` rests on ML-KEM-1024 and ML-DSA-87 (NIST category 5). The classical half is defense
53
+ in depth: if elliptic-curve cryptography (or RSA) were broken outright, security would still rest
54
+ on ML-KEM-1024 and ML-DSA-87. The classical half is P-384 rather than X25519 or Ed25519. P-384 is a
55
+ stronger classical fallback, and it is the curve the NSA's December 2, 2026 advisory (PP-26-4956)
56
+ keeps as an interim choice. That advisory lists elliptic curves other than P-384/P-521, and
57
+ EdDSA, among the algorithms to inventory and replace. Some cryptographers read it as a sign that
58
+ 256-bit curves may be weaker than believed. The advisory itself does not say they are broken.
59
+ - `pqbox-paranoid` also survives a break of lattice cryptography. Classic McEliece (code-based) and
60
+ SLH-DSA (hash-based) do not rely on lattices.
61
+ - `xwing` exists only for compatibility. Its classical half is a 256-bit curve, so treat its
62
+ security as resting entirely on ML-KEM-768 and ML-DSA-65.
63
+
64
+ The `pqbox-max` and `pqbox-paranoid` KEM combiners are modeled on X-Wing but are **not**
65
+ IETF-standardized:
66
+
67
+ ```text
68
+ pqbox-max: ss = SHA3-256(ss_mlkem ‖ ss_p384 ‖ ct_p384 ‖ pk_p384 ‖ "pqbox/v1/kem-max")
69
+ pqbox-paranoid: ss = SHA3-256(ss_mlkem ‖ ss_mceliece ‖ ss_p384 ‖ ct_p384 ‖ pk_p384
70
+ ‖ SHA3-256(ct_mlkem) ‖ SHA3-256(ct_mceliece) ‖ "pqbox/v1/kem-paranoid")
71
+ ```
72
+
73
+ Signatures follow the IETF composite ML-DSA draft (draft-ietf-lamps-pq-composite-sigs-19): the
74
+ message representative is `"CompositeAlgorithmSignatures2025" ‖ Label ‖ len(ctx) ‖ ctx ‖ SHA-512(M)`,
75
+ using the draft's labels for `xwing` and `pqbox-max` and a pqbox-specific label for
76
+ `pqbox-paranoid`. The deviations are documented in [`sign.rs`](crates/pqbox-core/src/sign.rs):
77
+ pqbox's own encodings instead of ASN.1, a fixed-length low-`s` ECDSA `r‖s`, and the signer's key
78
+ fingerprint bound in `ctx`.
79
+
80
+ Composite signatures are **strongly unforgeable** (SUF-CMA): nobody can produce a second valid
81
+ signature of a message that was signed, not just a signature of a new message. Every component
82
+ has a single valid encoding per signing operation: ML-DSA and SLH-DSA are designed to be strongly
83
+ unforgeable, Ed25519 is verified strictly, and the ECDSA `s` must be in the lower half of the group
84
+ order (signing normalizes it; the malleable `n - s` twin is refused).
85
+
86
+ ## Algorithms
87
+
88
+ | Purpose | Algorithm | Crate |
89
+ |---|---|---|
90
+ | KEM | ML-KEM-768 / ML-KEM-1024 (FIPS 203) | `ml-kem` 0.3.4 |
91
+ | KEM | X-Wing (draft-connolly-cfrg-xwing-kem) | `x-wing` 0.1.1 |
92
+ | KEM | Classic McEliece 8192128 | `classic-mceliece-rust` 3.1.0 |
93
+ | KEM (classical half) | ECDH P-384, X25519 | `p384` 0.14.0, `x25519-dalek` 3.0.0 |
94
+ | Signature | ML-DSA-65 / ML-DSA-87 (FIPS 204) | `ml-dsa` 0.1.2 |
95
+ | Signature | SLH-DSA-SHAKE-256s (FIPS 205), `paranoid` feature only, experimental | `slh-dsa` 0.2.0-rc.5 (release candidate) |
96
+ | Signature (classical half) | ECDSA P-384 with SHA-384, Ed25519 | `p384` 0.14.0, `ed25519-dalek` 3.0.0 |
97
+ | Sealed box | suite KEM + HKDF-SHA-256 + XChaCha20-Poly1305 | |
98
+ | AEAD | XChaCha20-Poly1305 (default), AES-256-GCM | `chacha20poly1305` 0.11.0, `aes-gcm` 0.11.1 |
99
+ | KDF / MAC | HKDF-SHA-256, HMAC-SHA-256 | `hkdf` 0.13.0, `hmac` 0.13.0 |
100
+ | Hash | SHA-256, SHA3-256, BLAKE3 | `sha2` 0.11.1, `sha3` 0.12.0, `blake3` 1.8.9 |
101
+ | Password | Argon2id (64 MiB, t=3, p=1 by default; verification capped at 256 MiB, t=10, p=8), PHC strings | `argon2` 0.6.0 |
102
+
103
+ Symmetric keys are always 256-bit.
104
+
105
+ ## Sizes and timings
106
+
107
+ Sizes are of serialized objects and include the 6-byte header. Timings are medians from
108
+ `cargo bench -p pqbox` (criterion, release build) on an Apple M5 laptop (rustc 1.99.0); they
109
+ show orders of magnitude, not guarantees.
110
+
111
+ | Suite | KEM public key | KEM secret key | KEM ciphertext | Sealed-box overhead | Signing public key | Signing secret key | Signature |
112
+ |---|---:|---:|---:|---:|---:|---:|---:|
113
+ | `xwing` | 1,222 B | 38 B | 1,126 B | 1,166 B | 1,990 B | 70 B | 3,379 B |
114
+ | `pqbox-max` | 1,671 B | 118 B | 1,671 B | 1,711 B | 2,695 B | 86 B | 4,729 B |
115
+ | `pqbox-paranoid` | 1,359,495 B | 1,372,094 B | 1,879 B | 1,919 B | 2,759 B | 214 B | 34,521 B |
116
+
117
+ | Suite | KEM keygen | Encapsulate | Decapsulate | Seal 1 KiB | Open 1 KiB | Sign keygen | Sign | Verify |
118
+ |---|---:|---:|---:|---:|---:|---:|---:|---:|
119
+ | `xwing` | 53 µs | 50 µs | 80 µs | 54 µs | 83 µs | 264 µs | 378 µs | 61 µs |
120
+ | `pqbox-max` | 401 µs | 733 µs | 759 µs | 738 µs | 763 µs | 730 µs | 775 µs | 446 µs |
121
+ | `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 |
122
+
123
+ Paranoid KEM key generation varies a lot from run to run (0.74 s to 1.20 s here), because Classic
124
+ McEliece retries until it finds a usable key. In WebAssembly under Node 24, the paranoid KEM key
125
+ generation took 6.5 to 11.6 s. Symmetric primitives on 64 KiB:
126
+ XChaCha20-Poly1305 62 µs, AES-256-GCM 14 µs, SHA-256 20 µs, SHA3-256 59 µs, BLAKE3 26 µs.
127
+
128
+ ## Install
129
+
130
+ ```sh
131
+ cargo add pqbox # Rust library (add `--features paranoid` for pqbox-paranoid)
132
+ cargo install pqbox-cli # `pqbox` command (same feature)
133
+ pip install pqbox # Python ≥ 3.10
134
+ npm install pqbox # Node ≥ 20, browsers
135
+ ```
136
+
137
+ Each GitHub release also carries prebuilt `pqbox` binaries, `pqbox-<target>` for macOS (arm64,
138
+ x86_64) and Linux (arm64, x86_64), with a `SHA256SUMS` file. `pqbox --version` reports the release,
139
+ and `pqbox selftest` checks the installed binary offline.
140
+
141
+ ## Examples
142
+
143
+ ### Rust
144
+
145
+ ```rust
146
+ use pqbox::{Suite, SuitePolicy, kem, seal, sign};
147
+ use rand_core::UnwrapErr;
148
+
149
+ let mut rng = UnwrapErr(getrandom::SysRng); // getrandom 0.4 with the `sys_rng` feature
150
+
151
+ // Sealed box to a recipient (default suite: pqbox-max). The plaintext is wiped on drop.
152
+ let recipient = kem::SecretKey::generate(Suite::default(), &mut rng)?;
153
+ let sealed = seal::seal(recipient.public_key(), b"hello", &mut rng)?;
154
+ assert_eq!(*seal::open(&recipient, &sealed)?, b"hello");
155
+
156
+ // Composite signature: every component must verify.
157
+ let signer = sign::SecretKey::generate(Suite::Max, &mut rng)?;
158
+ let sig = signer.sign(b"release v1.2.3", &mut rng)?;
159
+ signer.public_key().verify(b"release v1.2.3", &sig)?;
160
+
161
+ // Keys serialize with a versioned header. Parsers accept pqbox-max only by default.
162
+ let bytes = recipient.public_key().to_bytes();
163
+ assert_eq!(kem::PublicKey::from_bytes(&bytes)?.to_bytes(), bytes);
164
+
165
+ // Other suites must be allowed explicitly.
166
+ let legacy = kem::SecretKey::generate(Suite::XWing, &mut rng)?;
167
+ let bytes = legacy.public_key().to_bytes();
168
+ assert!(kem::PublicKey::from_bytes(&bytes).is_err()); // SuiteNotAllowed
169
+ let policy = SuitePolicy::DEFAULT.allow(Suite::XWing);
170
+ let pk = kem::PublicKey::from_bytes_with_policy(&bytes, policy)?;
171
+ # Ok::<(), pqbox::Error>(())
172
+ ```
173
+
174
+ ### Python
175
+
176
+ ```python
177
+ import pqbox
178
+
179
+ pk, sk = pqbox.kem_keygen() # "pqbox-max"
180
+ box = pqbox.seal(pk, b"hello")
181
+ assert pqbox.open(sk, box) == b"hello"
182
+
183
+ spk, ssk = pqbox.sign_keygen()
184
+ sig = pqbox.sign(ssk, b"release v1.2.3")
185
+ assert pqbox.verify(spk, b"release v1.2.3", sig)
186
+
187
+ # Suites other than pqbox-max are read only when allowed explicitly.
188
+ apk, ask = pqbox.sign_keygen("pqbox-paranoid")
189
+ sig = pqbox.sign(ask, b"archive", allow_suites=["pqbox-paranoid"])
190
+ assert pqbox.verify(apk, b"archive", sig, allow_suites=["pqbox-paranoid"])
191
+
192
+ key = pqbox.generate_key()
193
+ ct = pqbox.encrypt(key, b"data", aad=b"header")
194
+ assert pqbox.decrypt(key, ct, aad=b"header") == b"data"
195
+
196
+ phc = pqbox.password_hash("correct horse battery staple")
197
+ assert pqbox.password_verify("correct horse battery staple", phc)
198
+ ```
199
+
200
+ ### JavaScript / TypeScript
201
+
202
+ ```ts
203
+ import { kemKeygen, seal, open, signKeygen, sign, verify, blake3 } from "pqbox";
204
+
205
+ const { publicKey, secretKey } = kemKeygen(); // "pqbox-max"
206
+ const box = seal(publicKey, new TextEncoder().encode("hello"));
207
+ console.log(new TextDecoder().decode(open(secretKey, box)));
208
+
209
+ const signer = signKeygen("pqbox-max");
210
+ const msg = new TextEncoder().encode("release v1.2.3");
211
+ const sig = sign(signer.secretKey, msg);
212
+ console.log(verify(signer.publicKey, msg, sig)); // true
213
+
214
+ console.log(blake3(msg));
215
+
216
+ // Suites other than pqbox-max are read only when allowed explicitly.
217
+ const legacy = kemKeygen("xwing");
218
+ const box2 = seal(legacy.publicKey, msg, { allowSuites: ["xwing"] });
219
+ open(legacy.secretKey, box2, { allowSuites: ["xwing"] });
220
+ ```
221
+
222
+ Errors are thrown as `PqboxError` (in Python, raised as `pqbox.PqboxError`, a `ValueError`). They
223
+ carry a stable `code` such as `Decrypt`, `BadSignature`, `SuiteMismatch`, `SuiteNotAllowed` or
224
+ `UnsupportedVersion`.
225
+
226
+ ### CLI
227
+
228
+ ```sh
229
+ pqbox keygen kem -o alice # alice.pub, alice.sec (0600), suite pqbox-max
230
+ pqbox seal --to alice.pub -i secret.txt -o secret.box
231
+ pqbox open --key alice.sec -i secret.box
232
+
233
+ pqbox keygen sign -o release
234
+ pqbox sign --key release.sec -i dist.tar -o dist.tar.sig
235
+ pqbox verify --key release.pub --sig dist.tar.sig -i dist.tar # exit 0 if valid, 1 if not
236
+
237
+ # Other suites must be allowed when their objects are read (paranoid needs `--features paranoid`).
238
+ pqbox keygen kem --suite xwing -o legacy
239
+ pqbox seal --allow-suite xwing --to legacy.pub -i secret.txt -o secret.box
240
+
241
+ pqbox hash --alg blake3 -i dist.tar
242
+ pqbox info alice.pub
243
+
244
+ pqbox selftest # offline, well under a second; exit 0 if every check passes
245
+ pqbox selftest --json
246
+ ```
247
+
248
+ `selftest` runs a seal/open and a sign/verify round trip for `pqbox-max` and `xwing`, checks that
249
+ a tampered box and a tampered signature are refused, and replays the frozen known answers built
250
+ into the binary (the `xwing` and `pqbox-max` entries of
251
+ [`tests/vectors/pqbox/kat.json`](crates/pqbox-core/tests/vectors/pqbox/kat.json)).
252
+
253
+ Keys, boxes and signatures are base64 text by default, or raw bytes with `--raw`. Both forms are
254
+ accepted as input.
255
+
256
+ Secret keys and decrypted plaintext written to a file get mode 0600 on Unix. Every file is written
257
+ atomically (a temporary file in the same directory, flushed, then renamed into place), so
258
+ `keygen --force` or `open -o` over an existing world-readable file never leaves the secret readable
259
+ by others.
260
+
261
+ ## Wire format
262
+
263
+ Every object is `"PQB" ‖ version (0x02) ‖ type ‖ suite ‖ body`. Types: KEM public key `0x01`,
264
+ KEM secret key `0x02`, KEM ciphertext `0x03`, signing public key `0x11`, signing secret key
265
+ `0x12`, signature `0x13`, sealed box `0x21`, AEAD ciphertext `0x31` (where the suite byte is the
266
+ cipher: `0x01` XChaCha20-Poly1305, `0x02` AES-256-GCM). Parsers dispatch on the version and
267
+ reject unknown versions with `UnsupportedVersion`, so future versions can be added while older
268
+ objects stay readable. Version 2 is the first released format; the pre-release version 1 is not
269
+ read. A `pqbox-paranoid` KEM secret key ends with the fingerprint (SHA3-256) of its whole public
270
+ key, checked when it is parsed, so an embedded McEliece public key that does not belong to the key
271
+ is refused. The body layouts are documented in [`format.rs`](crates/pqbox-core/src/format.rs),
272
+ [`kem.rs`](crates/pqbox-core/src/kem.rs), [`sign.rs`](crates/pqbox-core/src/sign.rs) and
273
+ [`seal.rs`](crates/pqbox-core/src/seal.rs).
274
+
275
+ ## Testing
276
+
277
+ - Official vectors only (see [`tests/vectors/README.md`](crates/pqbox-core/tests/vectors/README.md)):
278
+ - X-Wing draft vectors;
279
+ - IETF LAMPS ML-KEM/ML-DSA examples;
280
+ - NIST ACVP SLH-DSA-SHAKE-256s;
281
+ - 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);
282
+ - the RFC vectors.
283
+ - Frozen pqbox known answers for the combiners, sealed boxes and composite signatures of every suite, generated once and checked in Rust, Python and JavaScript.
284
+ - 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.
285
+ - Property tests (proptest), cargo-fuzz targets for every parser plus round trips, and criterion benches.
286
+ - 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.
287
+ - 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.
288
+
289
+ ## Security notes
290
+
291
+ - **The post-quantum crates are not independently audited.** `ml-kem`, `ml-dsa`, `x-wing` and
292
+ `slh-dsa` (a release candidate) come from RustCrypto, which has not had them audited, and
293
+ `classic-mceliece-rust` is a community crate. pqbox itself has not been audited either.
294
+ - **Why bother now: harvest now, decrypt later.** No practical break of RSA is publicly known, and
295
+ no cryptographically relevant quantum computer is known to exist. Data recorded today, however,
296
+ can be decrypted whenever one appears. Hybrids protect it against that while keeping a classical
297
+ safety net.
298
+ - **Password hash limits.** The costs in a PHC string come from whoever wrote it, so
299
+ `verify_password` (Python `password_verify`, JavaScript `passwordVerify`) refuses strings above
300
+ 256 MiB, 10 passes or 8 lanes before allocating anything; `hash_password` holds itself to the
301
+ same limits. At the limits one verification takes 256 MiB and about a second of CPU. To accept
302
+ more expensive hashes from a trusted source, raise the limits explicitly:
303
+ `verify_password_with_limits` in Rust, `max_m_cost`/`max_t_cost`/`max_p_cost` in Python,
304
+ `{ maxMCost, maxTCost, maxPCost }` in JavaScript.
305
+ - **AES-256-GCM nonce limit.** `encrypt` draws a random nonce per message. AES-256-GCM's nonce is
306
+ 96 bits, so encrypt at most about 2^32 messages under one key (NIST SP 800-38D) and rotate it
307
+ after that. XChaCha20-Poly1305, the default, has a 192-bit nonce and no practical limit: prefer
308
+ it for long-lived keys. Sealed boxes use XChaCha20-Poly1305 with a fresh key each time.
309
+ - Sealed boxes are anonymous; they do not authenticate the sender. Sign the plaintext if the
310
+ recipient needs to know who sent it.
311
+ - Read [THREAT_MODEL.md](THREAT_MODEL.md) for what is and is not protected, and
312
+ [SECURITY.md](SECURITY.md) to report a vulnerability.
313
+
314
+ ## Upstream
315
+
316
+ pqbox stands on these projects. The versions are pinned in the `Cargo.toml` files (exactly, with
317
+ `=`, for every cryptographic crate); Dependabot proposes updates, and a weekly
318
+ [upstream watch](.github/workflows/upstream-watch.yml) reports advisories, new releases and
319
+ alternatives ([`scripts/watch/`](scripts/watch)). [`docs/BACKENDS.md`](docs/BACKENDS.md) compares
320
+ the RustCrypto backends with libcrux and AWS-LC.
321
+
322
+ ### Cryptography (crate `pqbox`)
323
+
324
+ | Crate | Purpose | Repository | crates.io | Implements |
325
+ |---|---|---|---|---|
326
+ | `ml-kem` | ML-KEM-768 / ML-KEM-1024 | [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) |
327
+ | `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/) |
328
+ | `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) |
329
+ | `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) |
330
+ | `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) |
331
+ | `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) |
332
+ | `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) |
333
+ | `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) |
334
+ | `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/) |
335
+ | `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) |
336
+ | `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) |
337
+ | `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) |
338
+ | `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) |
339
+ | `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) |
340
+ | `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) |
341
+ | `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) |
342
+ | `subtle` | Constant-time comparisons | [dalek-cryptography/subtle](https://github.com/dalek-cryptography/subtle) | [subtle](https://crates.io/crates/subtle) | |
343
+ | `zeroize` | Wiping secrets from memory | [RustCrypto/utils](https://github.com/RustCrypto/utils/tree/master/zeroize) | [zeroize](https://crates.io/crates/zeroize) | |
344
+ | `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) | |
345
+ | `getrandom` | The operating system's CSPRNG (CLI, bindings, tests) | [rust-random/getrandom](https://github.com/rust-random/getrandom) | [getrandom](https://crates.io/crates/getrandom) | |
346
+ | `thiserror` | Error type | [dtolnay/thiserror](https://github.com/dtolnay/thiserror) | [thiserror](https://crates.io/crates/thiserror) | |
347
+
348
+ The composite signatures follow
349
+ [draft-ietf-lamps-pq-composite-sigs-19](https://datatracker.ietf.org/doc/draft-ietf-lamps-pq-composite-sigs/19/)
350
+ (since published as [RFC 10073](https://www.rfc-editor.org/rfc/rfc10073)); the `pqbox-max` and
351
+ `pqbox-paranoid` KEM combiners are pqbox's own (see [Suites](#suites)).
352
+
353
+ ### CLI and bindings
354
+
355
+ | Crate or tool | Purpose | Repository | Registry |
356
+ |---|---|---|---|
357
+ | `clap` | CLI argument parsing | [clap-rs/clap](https://github.com/clap-rs/clap) | [crates.io](https://crates.io/crates/clap) |
358
+ | `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) |
359
+ | `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) |
360
+ | `pyo3` | Python bindings | [PyO3/pyo3](https://github.com/PyO3/pyo3) | [crates.io](https://crates.io/crates/pyo3) |
361
+ | `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/) |
362
+ | `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) |
363
+ | `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) |
364
+ | `criterion` | Timing benchmarks | [criterion-rs/criterion.rs](https://github.com/criterion-rs/criterion.rs) | [crates.io](https://crates.io/crates/criterion) |
365
+ | `gungraun` | Instruction-count benchmarks (the CI regression gate) | [gungraun/gungraun](https://github.com/gungraun/gungraun) | [crates.io](https://crates.io/crates/gungraun) |
366
+ | `proptest` | Property tests | [proptest-rs/proptest](https://github.com/proptest-rs/proptest) | [crates.io](https://crates.io/crates/proptest) |
367
+ | `cargo-fuzz` | Fuzzing (libFuzzer) | [rust-fuzz/cargo-fuzz](https://github.com/rust-fuzz/cargo-fuzz) | [crates.io](https://crates.io/crates/cargo-fuzz) |
368
+
369
+ ### Test vectors
370
+
371
+ Listed with their exact revisions in [`tests/vectors/README.md`](crates/pqbox-core/tests/vectors/README.md):
372
+
373
+ - [NIST ACVP-Server](https://github.com/usnistgov/ACVP-Server) (SLH-DSA key generation and verification);
374
+ - [C2SP/wycheproof](https://github.com/C2SP/wycheproof) (AEADs, HKDF, HMAC, Ed25519, X25519, P-384, ML-KEM, ML-DSA);
375
+ - the X-Wing draft's [test vectors](https://github.com/dconnolly/draft-connolly-cfrg-xwing-kem/blob/main/spec/test-vectors.json);
376
+ - 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;
377
+ - the RFC vectors cited next to each test.
378
+
379
+ ## License
380
+
381
+ MIT © maxgfr
@@ -0,0 +1,214 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * BLAKE3 (32 bytes).
6
+ */
7
+ export function blake3(data: Uint8Array): Uint8Array;
8
+
9
+ /**
10
+ * AEAD decryption.
11
+ *
12
+ * # Errors
13
+ * Parse errors or `Decrypt`.
14
+ */
15
+ export function decrypt(key: Uint8Array, data: Uint8Array, aad: Uint8Array): Uint8Array;
16
+
17
+ /**
18
+ * AEAD encryption with a random nonce.
19
+ *
20
+ * # Errors
21
+ * `InvalidParams` for an unknown algorithm, `InvalidLength` for a bad key.
22
+ */
23
+ export function encrypt(key: Uint8Array, plaintext: Uint8Array, aad: Uint8Array, algorithm: string): Uint8Array;
24
+
25
+ /**
26
+ * A fresh random 32-byte AEAD key.
27
+ */
28
+ export function generateKey(): Uint8Array;
29
+
30
+ /**
31
+ * Hashes with a named algorithm (`sha256`, `sha3-256`, `blake3`).
32
+ *
33
+ * # Errors
34
+ * `InvalidParams` for an unknown algorithm.
35
+ */
36
+ export function hash(data: Uint8Array, algorithm: string): Uint8Array;
37
+
38
+ /**
39
+ * HKDF-SHA-256.
40
+ *
41
+ * # Errors
42
+ * `InvalidParams` when `length` is not an integer in `0..=8160`.
43
+ */
44
+ export function hkdfSha256(ikm: Uint8Array, salt: Uint8Array, info: Uint8Array, length: number): Uint8Array;
45
+
46
+ /**
47
+ * HMAC-SHA-256.
48
+ *
49
+ * # Errors
50
+ * Never in practice.
51
+ */
52
+ export function hmacSha256(key: Uint8Array, message: Uint8Array): Uint8Array;
53
+
54
+ /**
55
+ * Constant-time HMAC-SHA-256 tag check.
56
+ */
57
+ export function hmacSha256Verify(key: Uint8Array, message: Uint8Array, tag: Uint8Array): boolean;
58
+
59
+ /**
60
+ * Decapsulates a ciphertext into the 32-byte shared secret.
61
+ *
62
+ * # Errors
63
+ * Parse errors, `SuiteNotAllowed`, `SuiteMismatch` or `Decrypt`.
64
+ */
65
+ export function kemDecapsulate(secret_key: Uint8Array, ciphertext: Uint8Array, allow_suites: string[]): Uint8Array;
66
+
67
+ /**
68
+ * Encapsulates to a public key: `{ ciphertext, sharedSecret }`.
69
+ *
70
+ * # Errors
71
+ * Parse errors of the public key, `SuiteNotAllowed`.
72
+ */
73
+ export function kemEncapsulate(public_key: Uint8Array, allow_suites: string[]): object;
74
+
75
+ /**
76
+ * Generates a KEM key pair: `{ publicKey, secretKey }`.
77
+ *
78
+ * # Errors
79
+ * `InvalidParams` for an unknown suite.
80
+ */
81
+ export function kemKeygen(suite_name: string): object;
82
+
83
+ /**
84
+ * Opens a sealed box.
85
+ *
86
+ * # Errors
87
+ * Parse errors, `SuiteNotAllowed`, `SuiteMismatch` or `Decrypt`.
88
+ */
89
+ export function open(secret_key: Uint8Array, sealed: Uint8Array, allow_suites: string[]): Uint8Array;
90
+
91
+ /**
92
+ * Argon2id password hash as a PHC string.
93
+ *
94
+ * # Errors
95
+ * `InvalidParams` for out-of-range costs (including costs above the default limits: 256 MiB,
96
+ * 10 passes, 8 lanes).
97
+ */
98
+ export function passwordHash(password: Uint8Array, m_cost: number, t_cost: number, p_cost: number): string;
99
+
100
+ /**
101
+ * Checks a password: `false` on mismatch, an error for an invalid hash string or one whose costs
102
+ * exceed the given limits (checked before any memory is allocated).
103
+ *
104
+ * # Errors
105
+ * `InvalidPasswordHash`, or `InvalidParams` for limits that are not integers in `0..=2^32-1`.
106
+ */
107
+ export function passwordVerify(password: Uint8Array, phc: string, max_m_cost: number, max_t_cost: number, max_p_cost: number): boolean;
108
+
109
+ /**
110
+ * Seals a message to a KEM public key.
111
+ *
112
+ * # Errors
113
+ * Parse errors of the public key, `SuiteNotAllowed`.
114
+ */
115
+ export function seal(public_key: Uint8Array, plaintext: Uint8Array, allow_suites: string[]): Uint8Array;
116
+
117
+ /**
118
+ * SHA-256.
119
+ */
120
+ export function sha256(data: Uint8Array): Uint8Array;
121
+
122
+ /**
123
+ * SHA3-256.
124
+ */
125
+ export function sha3_256(data: Uint8Array): Uint8Array;
126
+
127
+ /**
128
+ * Signs a message.
129
+ *
130
+ * # Errors
131
+ * Parse errors of the secret key, `SuiteNotAllowed`.
132
+ */
133
+ export function sign(secret_key: Uint8Array, message: Uint8Array, allow_suites: string[]): Uint8Array;
134
+
135
+ /**
136
+ * Generates a signing key pair: `{ publicKey, secretKey }`.
137
+ *
138
+ * # Errors
139
+ * `InvalidParams` for an unknown suite.
140
+ */
141
+ export function signKeygen(suite_name: string): object;
142
+
143
+ /**
144
+ * The suites compiled into this build, by name.
145
+ */
146
+ export function suites(): string[];
147
+
148
+ /**
149
+ * Verifies a signature: `false` when it does not verify, an error for malformed input.
150
+ *
151
+ * # Errors
152
+ * Parse errors, `SuiteNotAllowed` and `SuiteMismatch`.
153
+ */
154
+ export function verify(public_key: Uint8Array, message: Uint8Array, signature: Uint8Array, allow_suites: string[]): boolean;
155
+
156
+ /**
157
+ * The package version.
158
+ */
159
+ export function version(): string;
160
+
161
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
162
+
163
+ export interface InitOutput {
164
+ readonly memory: WebAssembly.Memory;
165
+ readonly blake3: (a: number, b: number, c: number) => void;
166
+ readonly decrypt: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
167
+ readonly encrypt: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
168
+ readonly generateKey: () => number;
169
+ readonly hash: (a: number, b: number, c: number, d: number, e: number) => void;
170
+ readonly hkdfSha256: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
171
+ readonly hmacSha256: (a: number, b: number, c: number, d: number, e: number) => void;
172
+ readonly hmacSha256Verify: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
173
+ readonly kemDecapsulate: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
174
+ readonly kemEncapsulate: (a: number, b: number, c: number, d: number, e: number) => void;
175
+ readonly kemKeygen: (a: number, b: number, c: number) => void;
176
+ readonly open: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
177
+ readonly passwordHash: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
178
+ readonly passwordVerify: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
179
+ readonly seal: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
180
+ readonly sha256: (a: number, b: number, c: number) => void;
181
+ readonly sha3_256: (a: number, b: number, c: number) => void;
182
+ readonly sign: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
183
+ readonly signKeygen: (a: number, b: number, c: number) => void;
184
+ readonly suites: (a: number) => void;
185
+ readonly verify: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
186
+ readonly version: (a: number) => void;
187
+ readonly __wbindgen_export: (a: number, b: number) => number;
188
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
189
+ readonly __wbindgen_export3: (a: number) => void;
190
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
191
+ readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
192
+ }
193
+
194
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
195
+
196
+ /**
197
+ * Instantiates the given `module`, which can either be bytes or
198
+ * a precompiled `WebAssembly.Module`.
199
+ *
200
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
201
+ *
202
+ * @returns {InitOutput}
203
+ */
204
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
205
+
206
+ /**
207
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
208
+ * for everything else, calls `WebAssembly.instantiate` directly.
209
+ *
210
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
211
+ *
212
+ * @returns {Promise<InitOutput>}
213
+ */
214
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;