quantum-resistant-rustykey 0.13.0 → 0.13.2

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/README.md CHANGED
@@ -22,6 +22,7 @@ npm add quantum-resistant-rustykey
22
22
  - **SQIsign** Level 5, Level 3, Level 1 NOT approved yet by NIST, refer [cose-sqisign] (https://datatracker.ietf.org/doc/draft-mott-cose-sqisign/)
23
23
  - **ML-DSA** ML-DSA-65, ML-DSA-87
24
24
  - **FN-DSA** FN-DSA-512, FN-DSA-1024
25
+ - **SLH-DSA** (SPHINCS+) SLH-DSA-SHA2-128s / 192s / 256s — hash-based, NIST-standardized ([FIPS 205](https://csrc.nist.gov/pubs/fips/205/final))
25
26
  - **ML-KEM** 512, 768, 1024 using [mlkem-native](https://github.com/pq-code-package/mlkem-native).
26
27
 
27
28
  ### SQISign is 'NIST-on-ramp': get ahead and test TODAY, SQISign is the ONLY signature for constrained-development use
@@ -149,25 +150,130 @@ Notes:
149
150
 
150
151
  ## Usage
151
152
 
152
- ### SQISign-webGPU (browser accelerated)
153
+ ### SQISign-webGPU (browser accelerated "racecar")
153
154
 
154
- Browser-only accelerated SQISign variants: **SQISign-L1-webGPU**, **SQISign-L3-webGPU**, **SQISign-L5-webGPU**.
155
- Requires COOP/COEP headers (`crossOriginIsolated`). See [docs/SQISIGN-WEBGPU.md](./docs/SQISIGN-WEBGPU.md).
155
+ Browser-only accelerated SQISign variants using **SharedArrayBuffer** and **WebGPU**.
156
+ These are separate from the standard server-compatible WASM loaders and are **not available in Node.js**.
156
157
 
157
- ```typescript
158
+ #### Variant names
159
+
160
+ | Security level | Standard loader | Accelerated (browser) |
161
+ |----------------|-----------------|------------------------|
162
+ | L5 | `loadSqisignLvl5()` → SQISign-L5 | `loadSqisignLvl5WebGpu()` → **SQISign-L5-webGPU** |
163
+ | L3 | `loadSqisignLvl3()` → SQISign-L3 | `loadSqisignLvl3WebGpu()` → **SQISign-L3-webGPU** |
164
+ | L1 | `loadSqisignLvl1()` → SQISign-L1 | `loadSqisignLvl1WebGpu()` → **SQISign-L1-webGPU** |
165
+
166
+ Labels are exported as `SQISIGN_WEBGPU_VARIANT_LABELS`.
167
+
168
+ #### Requirements (COOP / COEP)
169
+
170
+ Accelerated SQISign requires a **cross-origin isolated** browsing context:
171
+
172
+ 1. `crossOriginIsolated === true`
173
+ 2. `SharedArrayBuffer` available
174
+ 3. `navigator.gpu` (WebGPU) available
175
+
176
+ Serve these response headers on pages that load the accelerated variants:
177
+
178
+ ```http
179
+ Cross-Origin-Opener-Policy: same-origin
180
+ Cross-Origin-Embedder-Policy: require-corp
181
+ ```
182
+
183
+ ⚠️ IMPORTANT for this highly-tuned "racecar" version
184
+
185
+ Enforcing these headers on a production web app creates a challenging isolation boundary
186
+ - Breaking Third Parties: Every single script, analytic tracker, embedded iframe (like Stripe or YouTube), and cross-origin image on that page will immediately break or be blocked unless they are explicitly served with a Cross-Origin-Resource-Policy header
187
+ - Maintenance Overhead: the accelerated version is browser-only frontend, use our standard web-assembly package in nodejs backend***
188
+ - ok, so you're a self-confessed speed demon, you've read the cautions. But before you jump into this shiny new machine, remember you asked the crew to fit 'racing slicks for dry weather only'. If the weather changes unexpectedly, you'll find yourself behind the wheel of an 'aquatic hydroplaning device'. No airbags.
189
+
190
+ #### Specific risks introduced with this "racecar" version
191
+
192
+ 1. Security unknowns
193
+ - Side-Channel Vulnerabilities are untested. Offloading cryptographic math to a smartphone's WebGPU - billions of them, various model, makes, years - means executing field arithmetic directly on the host computer's GPU threads. Graphics processors are fundamentally optimized for parallel throughput, not constant-time deterministic execution.
194
+ - Novel unseen threats: Running cryptographic primitives on shared GPU hardware makes them highly susceptible to advanced timing and memory-coalescing side-channel attacks. ⚠️ Upstream C formal proofs absolutely do not account for WebGPU compute shader pipeline execution. ⚠️
195
+
196
+ ##### Next.js example
197
+
198
+ ```js
199
+ // next.config.mjs
200
+ async headers() {
201
+ return [
202
+ {
203
+ source: "/your-pqc-page/:path*",
204
+ headers: [
205
+ { key: "Cross-Origin-Opener-Policy", value: "same-origin" },
206
+ { key: "Cross-Origin-Embedder-Policy", value: "require-corp" },
207
+ ],
208
+ },
209
+ ];
210
+ }
211
+ ```
212
+
213
+ Third-party scripts, images, and iframes on the same page must be served with appropriate `Cross-Origin-Resource-Policy` (or `crossorigin` attributes) or they will be blocked under `require-corp`.
214
+
215
+ ##### Worker script (required for bundlers like Next.js)
216
+
217
+ Bundled apps cannot load `sqisign-accel-worker.js` from `node_modules`. Copy it to a public URL:
218
+
219
+ ```bash
220
+ cp node_modules/quantum-resistant-rustykey/dist/sqisign-accel-worker.js public/pqc/
221
+ ```
222
+
223
+ The testbed sync script does this automatically (`pnpm pqc:sync-local`).
224
+
225
+ Default worker URL: `/pqc/sqisign-accel-worker.js`. Override if needed:
226
+
227
+ ```ts
228
+ import { setSqisignAccelWorkerUrl } from "quantum-resistant-rustykey";
229
+ setSqisignAccelWorkerUrl("/your/path/sqisign-accel-worker.js");
230
+ ```
231
+
232
+ If the worker fails to load, the library falls back to main-thread WASM (same crypto, UI may stutter on L5).
233
+
234
+ #### Usage
235
+
236
+ ```ts
158
237
  import {
238
+ benchSqisignWebGpu,
239
+ getSqisignWebGpuSupport,
159
240
  isSqisignWebGpuAvailable,
160
241
  loadSqisignLvl5WebGpu,
161
- benchSqisignWebGpu,
242
+ SQISIGN_WEBGPU_VARIANT_LABELS,
162
243
  } from "quantum-resistant-rustykey";
163
244
 
164
- if (isSqisignWebGpuAvailable()) {
165
- const sq = await loadSqisignLvl5WebGpu();
166
- const bench = await benchSqisignWebGpu("lvl5");
167
- console.log(bench.steps);
245
+ const support = getSqisignWebGpuSupport();
246
+ if (!support.available) {
247
+ console.warn(support.reason);
168
248
  }
249
+
250
+ // Same IFnDsa surface as standard loaders
251
+ const sq = await loadSqisignLvl5WebGpu();
252
+ const kp = sq.keypair();
253
+ const pk = await kp.get("public_key");
254
+ const sk = await kp.get("private_key");
255
+ const msg = new TextEncoder().encode("hello");
256
+ const sig = await sq.sign(msg, sk);
257
+ const ok = await sq.verify(sig, msg, pk);
258
+
259
+ // Built-in keygen + sign + verify benchmark (browser only)
260
+ const bench = await benchSqisignWebGpu("lvl5");
261
+ console.log(bench.algorithm); // SQISign-L5-webGPU
262
+ console.log(bench.steps);
169
263
  ```
170
264
 
265
+ #### Architecture
266
+
267
+ 1. **Web Worker** — SQISign WASM runs off the main thread (worker bundle: `dist/sqisign-accel-worker.js`).
268
+ 2. **SharedArrayBuffer** — enabled when COOP/COEP isolate the origin (required for future pthread WASM builds).
269
+ 3. **WebGPU** — device initialization and compute pipeline warmup for field-arithmetic acceleration.
270
+
271
+ Standard `loadSqisignLvl*` loaders remain unchanged for Node.js and non-isolated browsers.
272
+
273
+ #### Live comparison
274
+
275
+ The [pqc.rustykey.me](https://pqc.rustykey.me) testbed shows side-by-side timings for SQISign-L1/L3/L5 vs SQISign-L1-webGPU / L3 / L5 on the **COSE** and **Verifiable Credentials** tabs when SQISign is selected.
276
+
171
277
  ### Node.js example
172
278
 
173
279
  ```typescript
@@ -308,6 +414,112 @@ Security note for web apps:
308
414
  - prefer HTTPS + short-lived keys
309
415
  - use secure key storage strategy (e.g. IndexedDB + app-level protections)
310
416
 
417
+ ### SLH-DSA (SPHINCS+) — hash-based signatures
418
+
419
+ SLH-DSA is a **stateless hash-based** signature scheme standardized by NIST in [FIPS 205](https://csrc.nist.gov/pubs/fips/205/final). Its security rests only on the security of its underlying hash function, giving it the most conservative assumptions of any signature family in this package — at the cost of large signatures and slow signing. This package ships the three SHA2 **`s` (small-signature)** parameter sets.
420
+
421
+ | Loader | Variant | COSE (provisional) | Public key | Secret key | Signature | W3C appendix |
422
+ | :--- | :--- | :---: | :---: | :---: | :---: | :---: |
423
+ | `loadSlhDsa128()` | SLH-DSA-SHA2-128s | `0x1220` | 32 B | 64 B | 7,856 B | ✅ L1 golden vector |
424
+ | `loadSlhDsa192()` | SLH-DSA-SHA2-192s | `0x1221` | 48 B | 96 B | 16,224 B | generated keys |
425
+ | `loadSlhDsa256()` | SLH-DSA-SHA2-256s | `0x1222` | 64 B | 128 B | 29,792 B | generated keys |
426
+
427
+ > [!NOTE]
428
+ > COSE identifiers above are **provisional** and used for testbed/interop only — SLH-DSA COSE code points are not yet finalized by IANA. Cryptosuite names follow the W3C VC data-integrity pattern: `slhdsa128-rdfc-2024`, `slhdsa128-jcs-2024` (and `slhdsa192-*` / `slhdsa256-*`).
429
+
430
+ > [!WARNING]
431
+ > **SLH-DSA signing is slow and signatures are large** (kilobytes, not the ~200 bytes of SQISign). It is unsuitable for the CTAP2 1024-byte WebAuthn buffer. Prefer it where conservative, hash-only security matters and bandwidth/latency are not constrained (e.g. long-lived certificates, firmware, archival VCs). Verification is comparatively fast.
432
+
433
+ All SLH-DSA loaders expose the same `IFnDsa` interface (`keypair()`, `sign()`, `verify()`, `buffer_to_string()`):
434
+
435
+ ```typescript
436
+ import { loadSlhDsa128 } from "quantum-resistant-rustykey";
437
+
438
+ async function demo() {
439
+ const slh = await loadSlhDsa128(); // or loadSlhDsa192 / loadSlhDsa256
440
+ const kp = slh.keypair();
441
+ const publicKey = await kp.get("public_key");
442
+ const privateKey = await kp.get("private_key");
443
+
444
+ const message = new TextEncoder().encode("Authored by RustyKey (SLH-DSA)");
445
+ const signature = await slh.sign(message, privateKey);
446
+ const isValid = await slh.verify(signature, message, publicKey);
447
+ console.log("SLH-DSA-SHA2-128s valid?", isValid);
448
+ }
449
+
450
+ demo().catch(console.error);
451
+ ```
452
+
453
+ The pure-JS SLH-DSA path is provided via [`@noble/post-quantum`](https://github.com/paulmillr/noble-post-quantum) and works identically in Node.js and the browser (no WASM/COOP-COEP requirements).
454
+
455
+ ## REST endpoint summary — Verifiable Credentials (VC)
456
+
457
+ This library is the cryptographic core behind the **[pqc.rustykey.me](https://pqc.rustykey.me)** testbed. The testbed exposes a small HTTP surface (Next.js route handlers) that wraps the loaders above so you can produce W3C **Verifiable Credential** data-integrity proofs over the wire. The package itself ships no server — this section documents the reference endpoints so integrators can call or replicate them.
458
+
459
+ All endpoints run server-side (`runtime: "nodejs"`) and accept/return JSON.
460
+
461
+ ### `POST /api/pqc/vc/sign` — one-shot signed VC
462
+
463
+ The high-level endpoint: generates a fresh keypair, canonicalizes the document, hashes it, and returns the data-integrity proof value.
464
+
465
+ **Request body**
466
+
467
+ | Field | Type | Description |
468
+ | :--- | :--- | :--- |
469
+ | `document` | object | The unsecured W3C credential payload. |
470
+ | `algorithm` | string | One of the identifiers in the table below. |
471
+ | `dataset_canonicalization` | `"rdfc"` \| `"ics"` | RDF Dataset Canonicalization (`rdfc`) or JSON canonicalization (`ics`/JCS). |
472
+
473
+ **Supported `algorithm` identifiers**
474
+
475
+ | Identifier | Family | Cryptosuite prefix |
476
+ | :--- | :--- | :--- |
477
+ | `SQIsign-L1` / `SQIsign-L3` / `SQIsign-L5` | SQISign | `sqisign1` / `sqisign3` / `sqisign5` |
478
+ | `mldsa44` | ML-DSA | `mldsa44` |
479
+ | `falcon512` | FN-DSA | `falcon512` |
480
+ | `slhdsa128` / `slhdsa192` / `slhdsa256` | **SLH-DSA** | `slhdsa128` / `slhdsa192` / `slhdsa256` |
481
+
482
+ **Response body**
483
+
484
+ ```jsonc
485
+ {
486
+ "runtime": "nodejs",
487
+ "totalMs": 1234.5,
488
+ "algorithm": "slhdsa128",
489
+ "cryptosuite": "slhdsa128-rdfc-2024",
490
+ "dataset_canonicalization": "rdfc",
491
+ "publicKey": "…hex…",
492
+ "privateKey": "…hex…",
493
+ "canonicalizedDoc": "…canonical form…",
494
+ "hash": "…hex…",
495
+ "signature": "z…", // multibase proofValue
496
+ "signatureHex": "…hex…"
497
+ }
498
+ ```
499
+
500
+ **Example**
501
+
502
+ ```bash
503
+ curl -X POST https://pqc.rustykey.me/api/pqc/vc/sign \
504
+ -H "Content-Type: application/json" \
505
+ -d '{
506
+ "document": { "@context": ["https://www.w3.org/ns/credentials/v2"], "type": ["VerifiableCredential"] },
507
+ "algorithm": "slhdsa128",
508
+ "dataset_canonicalization": "rdfc"
509
+ }'
510
+ ```
511
+
512
+ ### `POST /api/pqc/vc/proof` — full pipeline / bring-your-own-keys
513
+
514
+ Lower-level endpoint used by the testbed's step-by-step VC view. It has two modes:
515
+
516
+ - **Proof pipeline** — send `unsecuredDocument`, `family` (`sqisign` \| `mldsa` \| `falcon` \| `slhdsa`), `level` (`l1` \| `l3` \| `l5`), `canonicalization` (`rdfc` \| `jcs`), plus `publicKeyHex` / `secretKeyHex` (and optional `verificationMethod`). Returns each canonicalize → hash → sign → verify step.
517
+ - **Sign-only** — send `hashDataHex` with `family`, `level`, `publicKeyHex`, `secretKeyHex` (and optional `referenceProofValue`) to sign a pre-computed hash and verify it (including against a W3C appendix golden value).
518
+
519
+ ### `PUT /api/pqc/vc/proof` — keygen
520
+
521
+ Send `{ "family": "slhdsa", "level": "l1" }` to get a fresh `publicKeyHex` / `secretKeyHex` and the resolved algorithm label. Handy for pre-provisioning keys before calling the proof pipeline.
522
+
311
523
  ## Building from Source
312
524
 
313
525
  ### Prerequisites
@@ -350,7 +562,7 @@ pnpm build
350
562
 
351
563
  ### Digital Signatures (Node.js & Frontend)
352
564
 
353
- All signature algorithms (**FN-DSA**, **ML-DSA**, and **SQIsign**) share a common interface.
565
+ All signature algorithms (**FN-DSA**, **ML-DSA**, **SQIsign**, and **SLH-DSA**) share a common interface.
354
566
 
355
567
  ```typescript
356
568
  import {
@@ -390,6 +602,24 @@ See the live [PQC testbed](https://pqc.rustykey.me) or run the frontend examples
390
602
 
391
603
  ML-KEM logic comes from **mlkem-native** (C), compiled with **Emscripten** under `wasm/`, wrapped by TypeScript in `mlkem-src/`, then bundled into `src/vendor/mlkem*.js`.
392
604
 
605
+ ## Supply-chain provenance
606
+
607
+ Each release tarball is built in GitHub Actions and signed with a Sigstore-backed
608
+ **build provenance attestation** (keyless, via GitHub OIDC). This proves the exact
609
+ published artifact was produced by this repository's CI at a specific commit. Verify
610
+ before installing:
611
+
612
+ ```bash
613
+ gh attestation verify "$(npm pack quantum-resistant-rustykey@<version> 2>/dev/null)" \
614
+ --repo antonymott/quantum-resistant-rustykey
615
+ ```
616
+
617
+ **Scope of this guarantee:** the attestation proves *provenance* — who built the
618
+ artifact, from which repository and commit. It is **not** a reproducible build and
619
+ does **not**, on its own, prove that the compiled WASM is bit-for-bit derivable from
620
+ the C sources. WASM behavioural correctness is covered separately by the Known Answer
621
+ Tests below.
622
+
393
623
  ## Security Considerations
394
624
 
395
625
  This implementation includes patches to withstand side-channel attacks. For more information about the security improvements, see: [RaspberryPi recovers secret keys from NIST winner implementation...within minutes](https://kannwischer.eu/papers/2024_kyberslash_preprint20240628.pdf)
package/dist/index.d.ts CHANGED
@@ -83,7 +83,7 @@ declare function getSqisignWebGpuSupport(): SqisignWebGpuSupport;
83
83
  declare function isSqisignWebGpuAvailable(): boolean;
84
84
  //#endregion
85
85
  //#region src/sqisign-webgpu.d.ts
86
- /** Host apps (e.g. Next.js) must serve dist/sqisign-accel-worker.js — see docs/SQISIGN-WEBGPU.md */
86
+ /** Host apps (e.g. Next.js) must serve dist/sqisign-accel-worker.js — see the "SQISign-webGPU" section in README.md */
87
87
  declare function setSqisignAccelWorkerUrl(url: string): void;
88
88
  type SqisignBenchSteps = {
89
89
  keygenMs: number;
package/dist/index.js CHANGED
@@ -4607,7 +4607,7 @@ const mainThreadLoaders = {
4607
4607
  lvl3: loadSqisignLvl3,
4608
4608
  lvl5: loadSqisignLvl5
4609
4609
  };
4610
- /** Host apps (e.g. Next.js) must serve dist/sqisign-accel-worker.js — see docs/SQISIGN-WEBGPU.md */
4610
+ /** Host apps (e.g. Next.js) must serve dist/sqisign-accel-worker.js — see the "SQISign-webGPU" section in README.md */
4611
4611
  function setSqisignAccelWorkerUrl(url) {
4612
4612
  customWorkerUrl = url;
4613
4613
  if (worker) {