@stenvault/pqc-wasm 0.4.0 → 0.4.1

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
@@ -4,9 +4,9 @@ Post-quantum cryptography WASM wrapper for StenVault — ML-KEM-768 and ML-KEM-1
4
4
 
5
5
  ## Why
6
6
 
7
- Replaces `@openforge-sh/liboqs` (unofficial C wrapper, single anonymous maintainer, 0 stars) with a self-maintained Rust→WASM build using the RustCrypto ecosystem (`ml-kem` + `ml-dsa` crates).
7
+ Replaces `@openforge-sh/liboqs`, an unofficial wrapper of the liboqs C library, with a self-maintained Rust→WASM build of the RustCrypto `ml-kem` and `ml-dsa` crates.
8
8
 
9
- WASM preserves constant-time properties from the Rust `subtle` crate — pure JS alternatives (noble-post-quantum, mlkem) cannot guarantee this due to V8 JIT and GC interference.
9
+ RustCrypto writes these crates to run in constant time, with `ctutils` for selections and comparisons. Neither WebAssembly nor a JavaScript engine guarantees that compiled code keeps that property, and this package has not verified it on the final `.wasm`. `npm run test:timing` checks total running time statistically; see Security for what it does not cover.
10
10
 
11
11
  ## Build
12
12
 
@@ -25,10 +25,19 @@ wasm-pack build --target nodejs --release --out-dir pkg-nodejs
25
25
 
26
26
  ```bash
27
27
  cargo test # Rust unit tests (native target)
28
- npm test # interop, FIPS 203 input checks, Wycheproof vectors and memory wiping, against the pkg-nodejs build
28
+ npm test # copies of secrets in the JS layer (fake bindings), then interop, FIPS 203 input checks, Wycheproof vectors and memory wiping against the pkg-nodejs build
29
29
  npm run test:fips203-scan # every single-byte change of one public key per ML-KEM parameter set, checked against noble
30
+ npm run test:timing # dudect-style timing test of decapsulation and signing, not part of npm test
30
31
  ```
31
32
 
33
+ The Kani proofs in `proofs/` (CI, on pull requests and `main`) check that the
34
+ key and ciphertext types have the sizes the wrapper converts into, that ML-DSA
35
+ verifying keys and signatures one byte short are rejected, and that two
36
+ 32-byte seed conversions cannot panic. They prove nothing about the
37
+ cryptography or its timing. Key and ciphertext decoding is fuzzed instead, by
38
+ the cargo-fuzz targets in `fuzz/` (ML-KEM-768 and ML-DSA-65). The global
39
+ allocator, the crate's only `unsafe` code, is tested under Miri in CI.
40
+
32
41
  The FIPS 203 tests draw their samples from a seed that is printed in the output.
33
42
  `FIPS203_SEED=<n> npm test` replays a run.
34
43
 
@@ -110,7 +119,7 @@ Consumer (StenVault)
110
119
  ↓ imports from "@stenvault/pqc-wasm"
111
120
  index.browser.ts / index.node.ts ← ensurePqcInit() + re-export
112
121
  ↓
113
- core.ts ← free() in try/finally, param order normalization
122
+ core.ts ← free() in try/finally, param order normalization, each getter read once and returned as is
114
123
  ↓
115
124
  pkg-bundler/ or pkg-nodejs/ ← wasm-bindgen generated bindings
116
125
  ↓
@@ -132,10 +141,10 @@ The consumer never calls `free()`, never calls `init()`, and never imports from
132
141
 
133
142
  ## Security
134
143
 
135
- - **Constant-time**: `subtle` crate in Rust, preserved through WASM compilation
136
- - **Memory wiping**: every heap block is zeroed before it is freed, and each operation then overwrites the part of the stack it used, so no secret key, seed or shared secret is left in the module's memory after a call. `tests/memory.ts` scans the memory after every operation. The `Uint8Array`s returned to JavaScript are the caller's to overwrite.
144
+ - **Constant time**: RustCrypto writes `ml-kem` and `ml-dsa` to run in constant time, with `ctutils`. Whether the compiled `.wasm` keeps that is not verified (see SECURITY.md, Known Limitations). `npm run test:timing` finds no timing difference between valid and invalid ciphertexts in decapsulation, or between seeds in signing, in Node 24.
145
+ - **Memory wiping**: every heap block is zeroed before it is freed, and each operation then overwrites the part of the stack it used, so no secret key, seed or shared secret is left in the module's memory after a call. `tests/memory.ts` scans the memory after every operation. Each secret leaves the module's memory once, as the `Uint8Array` returned to the caller, and the package keeps no other copy (`tests/core.ts`): that array is the one to overwrite with `fill(0)` when done. This keeps the copies down but is not a full guarantee: the JavaScript engine's garbage collector and JIT may copy the bytes where no code can reach them. In V8, for example, small arrays such as 32-byte secrets live inside the JavaScript heap, which the garbage collector moves.
137
146
  - **FIPS 203 input checks**: `encapsulate` runs the §7.2 modulus check; `decapsulate` runs the §7.3 hash check, then the §7.2 check on the public key inside the secret key. `ml-kem` 0.3 runs the same checks; this package runs its own first, so the errors do not depend on the crate.
138
- - **No audit**: Neither RustCrypto nor this wrapper have been independently audited. RustCrypto is honest about this.
147
+ - **No audit**: Neither RustCrypto nor this wrapper have been independently audited.
139
148
  - **CVE-2026-22705**: Timing side-channel in `ml-dsa` Decompose function, patched in `>= 0.1.0-rc.3` (Barrett reduction).
140
149
  - **CVE-2026-24850**: Signature malleability via duplicate hint indices in `ml-dsa`, patched in `>= 0.1.0-rc.4`.
141
150
  - **GHSA-h37v-hp6w-2pp8**: Off-by-two in `ml-dsa` `use_hint` when `r0 = 0` (FIPS 204 Alg. 40 deviation), patched in `>= 0.1.0-rc.5`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stenvault/pqc-wasm",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "ML-KEM-768/1024 + ML-DSA-65/87 WASM wrapper — RustCrypto compiled to WebAssembly",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -39,7 +39,7 @@
39
39
  "postbuild:wasm": "rm -f pkg-bundler/.gitignore pkg-nodejs/.gitignore",
40
40
  "build:ts": "tsc",
41
41
  "build": "npm run build:wasm && npm run build:ts",
42
- "test": "npx tsx tests/interop.ts && npx tsx tests/fips203.ts && npx tsx tests/wycheproof.ts && npx tsx tests/memory.ts",
42
+ "test": "npx tsx tests/core.ts && npx tsx tests/interop.ts && npx tsx tests/fips203.ts && npx tsx tests/wycheproof.ts && npx tsx tests/memory.ts",
43
43
  "test:fips203-scan": "npx tsx tests/fips203.ts --full-scan",
44
44
  "test:timing": "npx tsx tests/timing.ts"
45
45
  },
@@ -4,9 +4,9 @@ Post-quantum cryptography WASM wrapper for StenVault — ML-KEM-768 and ML-KEM-1
4
4
 
5
5
  ## Why
6
6
 
7
- Replaces `@openforge-sh/liboqs` (unofficial C wrapper, single anonymous maintainer, 0 stars) with a self-maintained Rust→WASM build using the RustCrypto ecosystem (`ml-kem` + `ml-dsa` crates).
7
+ Replaces `@openforge-sh/liboqs`, an unofficial wrapper of the liboqs C library, with a self-maintained Rust→WASM build of the RustCrypto `ml-kem` and `ml-dsa` crates.
8
8
 
9
- WASM preserves constant-time properties from the Rust `subtle` crate — pure JS alternatives (noble-post-quantum, mlkem) cannot guarantee this due to V8 JIT and GC interference.
9
+ RustCrypto writes these crates to run in constant time, with `ctutils` for selections and comparisons. Neither WebAssembly nor a JavaScript engine guarantees that compiled code keeps that property, and this package has not verified it on the final `.wasm`. `npm run test:timing` checks total running time statistically; see Security for what it does not cover.
10
10
 
11
11
  ## Build
12
12
 
@@ -25,10 +25,19 @@ wasm-pack build --target nodejs --release --out-dir pkg-nodejs
25
25
 
26
26
  ```bash
27
27
  cargo test # Rust unit tests (native target)
28
- npm test # interop, FIPS 203 input checks, Wycheproof vectors and memory wiping, against the pkg-nodejs build
28
+ npm test # copies of secrets in the JS layer (fake bindings), then interop, FIPS 203 input checks, Wycheproof vectors and memory wiping against the pkg-nodejs build
29
29
  npm run test:fips203-scan # every single-byte change of one public key per ML-KEM parameter set, checked against noble
30
+ npm run test:timing # dudect-style timing test of decapsulation and signing, not part of npm test
30
31
  ```
31
32
 
33
+ The Kani proofs in `proofs/` (CI, on pull requests and `main`) check that the
34
+ key and ciphertext types have the sizes the wrapper converts into, that ML-DSA
35
+ verifying keys and signatures one byte short are rejected, and that two
36
+ 32-byte seed conversions cannot panic. They prove nothing about the
37
+ cryptography or its timing. Key and ciphertext decoding is fuzzed instead, by
38
+ the cargo-fuzz targets in `fuzz/` (ML-KEM-768 and ML-DSA-65). The global
39
+ allocator, the crate's only `unsafe` code, is tested under Miri in CI.
40
+
32
41
  The FIPS 203 tests draw their samples from a seed that is printed in the output.
33
42
  `FIPS203_SEED=<n> npm test` replays a run.
34
43
 
@@ -110,7 +119,7 @@ Consumer (StenVault)
110
119
  ↓ imports from "@stenvault/pqc-wasm"
111
120
  index.browser.ts / index.node.ts ← ensurePqcInit() + re-export
112
121
  ↓
113
- core.ts ← free() in try/finally, param order normalization
122
+ core.ts ← free() in try/finally, param order normalization, each getter read once and returned as is
114
123
  ↓
115
124
  pkg-bundler/ or pkg-nodejs/ ← wasm-bindgen generated bindings
116
125
  ↓
@@ -132,10 +141,10 @@ The consumer never calls `free()`, never calls `init()`, and never imports from
132
141
 
133
142
  ## Security
134
143
 
135
- - **Constant-time**: `subtle` crate in Rust, preserved through WASM compilation
136
- - **Memory wiping**: every heap block is zeroed before it is freed, and each operation then overwrites the part of the stack it used, so no secret key, seed or shared secret is left in the module's memory after a call. `tests/memory.ts` scans the memory after every operation. The `Uint8Array`s returned to JavaScript are the caller's to overwrite.
144
+ - **Constant time**: RustCrypto writes `ml-kem` and `ml-dsa` to run in constant time, with `ctutils`. Whether the compiled `.wasm` keeps that is not verified (see SECURITY.md, Known Limitations). `npm run test:timing` finds no timing difference between valid and invalid ciphertexts in decapsulation, or between seeds in signing, in Node 24.
145
+ - **Memory wiping**: every heap block is zeroed before it is freed, and each operation then overwrites the part of the stack it used, so no secret key, seed or shared secret is left in the module's memory after a call. `tests/memory.ts` scans the memory after every operation. Each secret leaves the module's memory once, as the `Uint8Array` returned to the caller, and the package keeps no other copy (`tests/core.ts`): that array is the one to overwrite with `fill(0)` when done. This keeps the copies down but is not a full guarantee: the JavaScript engine's garbage collector and JIT may copy the bytes where no code can reach them. In V8, for example, small arrays such as 32-byte secrets live inside the JavaScript heap, which the garbage collector moves.
137
146
  - **FIPS 203 input checks**: `encapsulate` runs the §7.2 modulus check; `decapsulate` runs the §7.3 hash check, then the §7.2 check on the public key inside the secret key. `ml-kem` 0.3 runs the same checks; this package runs its own first, so the errors do not depend on the crate.
138
- - **No audit**: Neither RustCrypto nor this wrapper have been independently audited. RustCrypto is honest about this.
147
+ - **No audit**: Neither RustCrypto nor this wrapper have been independently audited.
139
148
  - **CVE-2026-22705**: Timing side-channel in `ml-dsa` Decompose function, patched in `>= 0.1.0-rc.3` (Barrett reduction).
140
149
  - **CVE-2026-24850**: Signature malleability via duplicate hint indices in `ml-dsa`, patched in `>= 0.1.0-rc.4`.
141
150
  - **GHSA-h37v-hp6w-2pp8**: Off-by-two in `ml-dsa` `use_hint` when `r0 = 0` (FIPS 204 Alg. 40 deviation), patched in `>= 0.1.0-rc.5`.
@@ -2,7 +2,7 @@
2
2
  "name": "stenvault-pqc",
3
3
  "type": "module",
4
4
  "description": "ML-KEM-768/1024 + ML-DSA-65/87 WASM wrapper for StenVault",
5
- "version": "0.4.0",
5
+ "version": "0.4.1",
6
6
  "license": "MIT",
7
7
  "files": [
8
8
  "stenvault_pqc_bg.wasm",
@@ -4,9 +4,9 @@ Post-quantum cryptography WASM wrapper for StenVault — ML-KEM-768 and ML-KEM-1
4
4
 
5
5
  ## Why
6
6
 
7
- Replaces `@openforge-sh/liboqs` (unofficial C wrapper, single anonymous maintainer, 0 stars) with a self-maintained Rust→WASM build using the RustCrypto ecosystem (`ml-kem` + `ml-dsa` crates).
7
+ Replaces `@openforge-sh/liboqs`, an unofficial wrapper of the liboqs C library, with a self-maintained Rust→WASM build of the RustCrypto `ml-kem` and `ml-dsa` crates.
8
8
 
9
- WASM preserves constant-time properties from the Rust `subtle` crate — pure JS alternatives (noble-post-quantum, mlkem) cannot guarantee this due to V8 JIT and GC interference.
9
+ RustCrypto writes these crates to run in constant time, with `ctutils` for selections and comparisons. Neither WebAssembly nor a JavaScript engine guarantees that compiled code keeps that property, and this package has not verified it on the final `.wasm`. `npm run test:timing` checks total running time statistically; see Security for what it does not cover.
10
10
 
11
11
  ## Build
12
12
 
@@ -25,10 +25,19 @@ wasm-pack build --target nodejs --release --out-dir pkg-nodejs
25
25
 
26
26
  ```bash
27
27
  cargo test # Rust unit tests (native target)
28
- npm test # interop, FIPS 203 input checks, Wycheproof vectors and memory wiping, against the pkg-nodejs build
28
+ npm test # copies of secrets in the JS layer (fake bindings), then interop, FIPS 203 input checks, Wycheproof vectors and memory wiping against the pkg-nodejs build
29
29
  npm run test:fips203-scan # every single-byte change of one public key per ML-KEM parameter set, checked against noble
30
+ npm run test:timing # dudect-style timing test of decapsulation and signing, not part of npm test
30
31
  ```
31
32
 
33
+ The Kani proofs in `proofs/` (CI, on pull requests and `main`) check that the
34
+ key and ciphertext types have the sizes the wrapper converts into, that ML-DSA
35
+ verifying keys and signatures one byte short are rejected, and that two
36
+ 32-byte seed conversions cannot panic. They prove nothing about the
37
+ cryptography or its timing. Key and ciphertext decoding is fuzzed instead, by
38
+ the cargo-fuzz targets in `fuzz/` (ML-KEM-768 and ML-DSA-65). The global
39
+ allocator, the crate's only `unsafe` code, is tested under Miri in CI.
40
+
32
41
  The FIPS 203 tests draw their samples from a seed that is printed in the output.
33
42
  `FIPS203_SEED=<n> npm test` replays a run.
34
43
 
@@ -110,7 +119,7 @@ Consumer (StenVault)
110
119
  ↓ imports from "@stenvault/pqc-wasm"
111
120
  index.browser.ts / index.node.ts ← ensurePqcInit() + re-export
112
121
  ↓
113
- core.ts ← free() in try/finally, param order normalization
122
+ core.ts ← free() in try/finally, param order normalization, each getter read once and returned as is
114
123
  ↓
115
124
  pkg-bundler/ or pkg-nodejs/ ← wasm-bindgen generated bindings
116
125
  ↓
@@ -132,10 +141,10 @@ The consumer never calls `free()`, never calls `init()`, and never imports from
132
141
 
133
142
  ## Security
134
143
 
135
- - **Constant-time**: `subtle` crate in Rust, preserved through WASM compilation
136
- - **Memory wiping**: every heap block is zeroed before it is freed, and each operation then overwrites the part of the stack it used, so no secret key, seed or shared secret is left in the module's memory after a call. `tests/memory.ts` scans the memory after every operation. The `Uint8Array`s returned to JavaScript are the caller's to overwrite.
144
+ - **Constant time**: RustCrypto writes `ml-kem` and `ml-dsa` to run in constant time, with `ctutils`. Whether the compiled `.wasm` keeps that is not verified (see SECURITY.md, Known Limitations). `npm run test:timing` finds no timing difference between valid and invalid ciphertexts in decapsulation, or between seeds in signing, in Node 24.
145
+ - **Memory wiping**: every heap block is zeroed before it is freed, and each operation then overwrites the part of the stack it used, so no secret key, seed or shared secret is left in the module's memory after a call. `tests/memory.ts` scans the memory after every operation. Each secret leaves the module's memory once, as the `Uint8Array` returned to the caller, and the package keeps no other copy (`tests/core.ts`): that array is the one to overwrite with `fill(0)` when done. This keeps the copies down but is not a full guarantee: the JavaScript engine's garbage collector and JIT may copy the bytes where no code can reach them. In V8, for example, small arrays such as 32-byte secrets live inside the JavaScript heap, which the garbage collector moves.
137
146
  - **FIPS 203 input checks**: `encapsulate` runs the §7.2 modulus check; `decapsulate` runs the §7.3 hash check, then the §7.2 check on the public key inside the secret key. `ml-kem` 0.3 runs the same checks; this package runs its own first, so the errors do not depend on the crate.
138
- - **No audit**: Neither RustCrypto nor this wrapper have been independently audited. RustCrypto is honest about this.
147
+ - **No audit**: Neither RustCrypto nor this wrapper have been independently audited.
139
148
  - **CVE-2026-22705**: Timing side-channel in `ml-dsa` Decompose function, patched in `>= 0.1.0-rc.3` (Barrett reduction).
140
149
  - **CVE-2026-24850**: Signature malleability via duplicate hint indices in `ml-dsa`, patched in `>= 0.1.0-rc.4`.
141
150
  - **GHSA-h37v-hp6w-2pp8**: Off-by-two in `ml-dsa` `use_hint` when `r0 = 0` (FIPS 204 Alg. 40 deviation), patched in `>= 0.1.0-rc.5`.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "stenvault-pqc",
3
3
  "description": "ML-KEM-768/1024 + ML-DSA-65/87 WASM wrapper for StenVault",
4
- "version": "0.4.0",
4
+ "version": "0.4.1",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "stenvault_pqc_bg.wasm",
package/src/core.js CHANGED
@@ -5,6 +5,11 @@
5
5
  //
6
6
  // This file is imported by index.browser.ts and index.node.ts, which each
7
7
  // provide their own ensurePqcInit() before delegating here.
8
+ //
9
+ // Each wasm-bindgen getter returns a new Uint8Array that owns a copy of the
10
+ // bytes, and each read makes another copy. Read every getter once and return
11
+ // its array as is: wrapping it again would leave a second copy of each secret
12
+ // in the JavaScript heap, one the caller cannot zero.
8
13
  let wasm = null;
9
14
  export function setWasmBindings(bindings) {
10
15
  wasm = bindings;
@@ -27,10 +32,7 @@ function kemBindings(name) {
27
32
  export function generateKemKeyPairCore(name) {
28
33
  const kp = kemBindings(name).generate();
29
34
  try {
30
- return {
31
- publicKey: new Uint8Array(kp.encapsulation_key),
32
- secretKey: new Uint8Array(kp.decapsulation_key),
33
- };
35
+ return { publicKey: kp.encapsulation_key, secretKey: kp.decapsulation_key };
34
36
  }
35
37
  finally {
36
38
  kp.free();
@@ -39,10 +41,7 @@ export function generateKemKeyPairCore(name) {
39
41
  export function encapsulateCore(publicKey, name) {
40
42
  const result = kemBindings(name).encapsulate(publicKey);
41
43
  try {
42
- return {
43
- ciphertext: new Uint8Array(result.ciphertext),
44
- sharedSecret: new Uint8Array(result.shared_secret),
45
- };
44
+ return { ciphertext: result.ciphertext, sharedSecret: result.shared_secret };
46
45
  }
47
46
  finally {
48
47
  result.free();
@@ -52,7 +51,7 @@ export function decapsulateCore(ciphertext, secretKey, name) {
52
51
  // Rust API: (dk, ct) — we receive (ct, sk) from StenVault convention
53
52
  const result = kemBindings(name).decapsulate(secretKey, ciphertext);
54
53
  try {
55
- return new Uint8Array(result.shared_secret);
54
+ return result.shared_secret;
56
55
  }
57
56
  finally {
58
57
  result.free();
@@ -71,10 +70,7 @@ function dsaBindings(name) {
71
70
  export function generateSignatureKeyPairCore(name) {
72
71
  const kp = dsaBindings(name).generate();
73
72
  try {
74
- return {
75
- publicKey: new Uint8Array(kp.verifying_key),
76
- secretKey: new Uint8Array(kp.signing_key),
77
- };
73
+ return { publicKey: kp.verifying_key, secretKey: kp.signing_key };
78
74
  }
79
75
  finally {
80
76
  kp.free();
@@ -82,7 +78,7 @@ export function generateSignatureKeyPairCore(name) {
82
78
  }
83
79
  export function signCore(message, secretKey, name) {
84
80
  // Rust API: (sk, msg) — we receive (msg, sk) from StenVault convention
85
- return new Uint8Array(dsaBindings(name).sign(secretKey, message));
81
+ return dsaBindings(name).sign(secretKey, message);
86
82
  }
87
83
  export function verifyCore(message, signature, publicKey, name) {
88
84
  // Rust API: (vk, msg, sig) — we receive (msg, sig, pk) from StenVault convention