@stenvault/pqc-wasm 0.1.2 → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gefson Costa
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
@@ -45,7 +45,7 @@ const decrypted = await decapsulate(ciphertext, kp.secretKey)
45
45
  // ML-DSA-65
46
46
  const sigKp = await generateSignatureKeyPair()
47
47
  // sigKp.publicKey: Uint8Array (1,952 bytes)
48
- // sigKp.secretKey: Uint8Array (4,032 bytes)
48
+ // sigKp.secretKey: Uint8Array (32 bytes, FIPS 204 seed)
49
49
 
50
50
  const signature = await sign(message, sigKp.secretKey)
51
51
  // signature: Uint8Array (3,309 bytes)
@@ -76,14 +76,17 @@ The consumer never calls `free()`, never calls `init()`, and never imports from
76
76
  | Algorithm | Public Key | Secret Key | Ciphertext | Signature | Shared Secret |
77
77
  |-----------|-----------|-----------|-----------|----------|--------------|
78
78
  | ML-KEM-768 | 1,184 B | 2,400 B | 1,088 B | — | 32 B |
79
- | ML-DSA-65 | 1,952 B | 4,032 B | — | 3,309 B | — |
79
+ | ML-DSA-65 | 1,952 B | 32 B (seed) | — | 3,309 B | — |
80
80
 
81
81
  ## Security
82
82
 
83
83
  - **Constant-time**: `subtle` crate in Rust, preserved through WASM compilation
84
84
  - **Memory zeroing**: `zeroize` crate with `#[derive(ZeroizeOnDrop)]` on all secret-holding structs
85
- - **No audit**: Neither RustCrypto nor this wrapper have been independently audited. RustCrypto is honest about this. See `PLAN_stenvault_pqc_wasm.md` section 10 for full risk analysis.
86
- - **CVE-2026-22705**: Timing side-channel in `ml-dsa` Decompose function, patched in `>= 0.1.0-rc.3` (Barrett reduction). Cargo.toml pins `>= 0.1.0-rc.3, < 0.2`.
85
+ - **No audit**: Neither RustCrypto nor this wrapper have been independently audited. RustCrypto is honest about this.
86
+ - **CVE-2026-22705**: Timing side-channel in `ml-dsa` Decompose function, patched in `>= 0.1.0-rc.3` (Barrett reduction).
87
+ - **CVE-2026-24850**: Signature malleability via duplicate hint indices in `ml-dsa`, patched in `>= 0.1.0-rc.4`.
88
+ - **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`.
89
+ - Cargo.toml pins `= 0.1.0-rc.8` (FIPS 204 seed API + WASM stack-overflow fix via PRs #1259 + #1261).
87
90
  - **Supply chain**: `Cargo.lock` committed, CI runs `cargo audit` before every build.
88
91
 
89
92
  ## License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stenvault/pqc-wasm",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "description": "ML-KEM-768 + ML-DSA-65 WASM wrapper — RustCrypto compiled to WebAssembly",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -44,6 +44,6 @@
44
44
  "devDependencies": {
45
45
  "@openforge-sh/liboqs": "^0.14.3",
46
46
  "tsx": "^4.21.0",
47
- "typescript": "^5.9.3"
47
+ "typescript": "^5.7.0"
48
48
  }
49
49
  }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gefson Costa
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.
@@ -45,7 +45,7 @@ const decrypted = await decapsulate(ciphertext, kp.secretKey)
45
45
  // ML-DSA-65
46
46
  const sigKp = await generateSignatureKeyPair()
47
47
  // sigKp.publicKey: Uint8Array (1,952 bytes)
48
- // sigKp.secretKey: Uint8Array (4,032 bytes)
48
+ // sigKp.secretKey: Uint8Array (32 bytes, FIPS 204 seed)
49
49
 
50
50
  const signature = await sign(message, sigKp.secretKey)
51
51
  // signature: Uint8Array (3,309 bytes)
@@ -76,14 +76,17 @@ The consumer never calls `free()`, never calls `init()`, and never imports from
76
76
  | Algorithm | Public Key | Secret Key | Ciphertext | Signature | Shared Secret |
77
77
  |-----------|-----------|-----------|-----------|----------|--------------|
78
78
  | ML-KEM-768 | 1,184 B | 2,400 B | 1,088 B | — | 32 B |
79
- | ML-DSA-65 | 1,952 B | 4,032 B | — | 3,309 B | — |
79
+ | ML-DSA-65 | 1,952 B | 32 B (seed) | — | 3,309 B | — |
80
80
 
81
81
  ## Security
82
82
 
83
83
  - **Constant-time**: `subtle` crate in Rust, preserved through WASM compilation
84
84
  - **Memory zeroing**: `zeroize` crate with `#[derive(ZeroizeOnDrop)]` on all secret-holding structs
85
- - **No audit**: Neither RustCrypto nor this wrapper have been independently audited. RustCrypto is honest about this. See `PLAN_stenvault_pqc_wasm.md` section 10 for full risk analysis.
86
- - **CVE-2026-22705**: Timing side-channel in `ml-dsa` Decompose function, patched in `>= 0.1.0-rc.3` (Barrett reduction). Cargo.toml pins `>= 0.1.0-rc.3, < 0.2`.
85
+ - **No audit**: Neither RustCrypto nor this wrapper have been independently audited. RustCrypto is honest about this.
86
+ - **CVE-2026-22705**: Timing side-channel in `ml-dsa` Decompose function, patched in `>= 0.1.0-rc.3` (Barrett reduction).
87
+ - **CVE-2026-24850**: Signature malleability via duplicate hint indices in `ml-dsa`, patched in `>= 0.1.0-rc.4`.
88
+ - **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`.
89
+ - Cargo.toml pins `= 0.1.0-rc.8` (FIPS 204 seed API + WASM stack-overflow fix via PRs #1259 + #1261).
87
90
  - **Supply chain**: `Cargo.lock` committed, CI runs `cargo audit` before every build.
88
91
 
89
92
  ## License
@@ -2,7 +2,7 @@
2
2
  "name": "stenvault-pqc",
3
3
  "type": "module",
4
4
  "description": "ML-KEM-768 + ML-DSA-65 WASM wrapper for StenVault",
5
- "version": "0.1.0",
5
+ "version": "0.2.0",
6
6
  "license": "MIT",
7
7
  "files": [
8
8
  "stenvault_pqc_bg.wasm",
@@ -16,4 +16,4 @@
16
16
  "./stenvault_pqc.js",
17
17
  "./snippets/*"
18
18
  ]
19
- }
19
+ }
@@ -1,38 +1,96 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
+ /**
5
+ * ML-DSA-65 key pair (verifying key + 32-byte signing seed).
6
+ */
4
7
  export class MlDsa65KeyPair {
5
8
  private constructor();
6
9
  free(): void;
7
10
  [Symbol.dispose](): void;
11
+ /**
12
+ * Signing key as a 32-byte seed; expanded on demand during signing.
13
+ */
8
14
  readonly signing_key: Uint8Array;
15
+ /**
16
+ * Verifying (public) key, 1952 bytes.
17
+ */
9
18
  readonly verifying_key: Uint8Array;
10
19
  }
11
20
 
21
+ /**
22
+ * Output of ML-KEM-768 decapsulation: the recovered shared secret.
23
+ */
24
+ export class MlKem768DecapResult {
25
+ private constructor();
26
+ free(): void;
27
+ [Symbol.dispose](): void;
28
+ /**
29
+ * Shared secret recovered from the ciphertext, 32 bytes.
30
+ */
31
+ readonly shared_secret: Uint8Array;
32
+ }
33
+
34
+ /**
35
+ * Output of ML-KEM-768 encapsulation: ciphertext + shared secret.
36
+ */
12
37
  export class MlKem768EncapResult {
13
38
  private constructor();
14
39
  free(): void;
15
40
  [Symbol.dispose](): void;
41
+ /**
42
+ * Ciphertext to send to the decapsulator, 1088 bytes.
43
+ */
16
44
  readonly ciphertext: Uint8Array;
45
+ /**
46
+ * Shared secret derived from encapsulation, 32 bytes.
47
+ */
17
48
  readonly shared_secret: Uint8Array;
18
49
  }
19
50
 
51
+ /**
52
+ * ML-KEM-768 key pair (encapsulation + decapsulation key).
53
+ */
20
54
  export class MlKem768KeyPair {
21
55
  private constructor();
22
56
  free(): void;
23
57
  [Symbol.dispose](): void;
58
+ /**
59
+ * Decapsulation (private) key, 2400 bytes.
60
+ */
24
61
  readonly decapsulation_key: Uint8Array;
62
+ /**
63
+ * Encapsulation (public) key, 1184 bytes.
64
+ */
25
65
  readonly encapsulation_key: Uint8Array;
26
66
  }
27
67
 
68
+ /**
69
+ * Generate a fresh ML-DSA-65 key pair from 32 random seed bytes.
70
+ */
28
71
  export function ml_dsa_65_generate(): MlDsa65KeyPair;
29
72
 
73
+ /**
74
+ * Sign `message` with a 32-byte ML-DSA-65 seed, returning a 3309-byte signature.
75
+ */
30
76
  export function ml_dsa_65_sign(sk_bytes: Uint8Array, message: Uint8Array): Uint8Array;
31
77
 
78
+ /**
79
+ * Verify a 3309-byte ML-DSA-65 signature over `message` against a 1952-byte verifying key.
80
+ */
32
81
  export function ml_dsa_65_verify(vk_bytes: Uint8Array, message: Uint8Array, signature: Uint8Array): boolean;
33
82
 
34
- export function ml_kem_768_decapsulate(dk_bytes: Uint8Array, ct_bytes: Uint8Array): Uint8Array;
83
+ /**
84
+ * Decapsulate a 1088-byte ciphertext with a 2400-byte decapsulation key.
85
+ */
86
+ export function ml_kem_768_decapsulate(dk_bytes: Uint8Array, ct_bytes: Uint8Array): MlKem768DecapResult;
35
87
 
88
+ /**
89
+ * Encapsulate a fresh shared secret to a 1184-byte encapsulation key.
90
+ */
36
91
  export function ml_kem_768_encapsulate(ek_bytes: Uint8Array): MlKem768EncapResult;
37
92
 
93
+ /**
94
+ * Generate a fresh ML-KEM-768 key pair using OS randomness.
95
+ */
38
96
  export function ml_kem_768_generate(): MlKem768KeyPair;
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./stenvault_pqc_bg.js";
5
5
  __wbg_set_wasm(wasm);
6
6
  wasm.__wbindgen_start();
7
7
  export {
8
- MlDsa65KeyPair, MlKem768EncapResult, MlKem768KeyPair, ml_dsa_65_generate, ml_dsa_65_sign, ml_dsa_65_verify, ml_kem_768_decapsulate, ml_kem_768_encapsulate, ml_kem_768_generate
8
+ MlDsa65KeyPair, MlKem768DecapResult, MlKem768EncapResult, MlKem768KeyPair, ml_dsa_65_generate, ml_dsa_65_sign, ml_dsa_65_verify, ml_kem_768_decapsulate, ml_kem_768_encapsulate, ml_kem_768_generate
9
9
  } from "./stenvault_pqc_bg.js";
@@ -1,3 +1,6 @@
1
+ /**
2
+ * ML-DSA-65 key pair (verifying key + 32-byte signing seed).
3
+ */
1
4
  export class MlDsa65KeyPair {
2
5
  static __wrap(ptr) {
3
6
  ptr = ptr >>> 0;
@@ -17,6 +20,7 @@ export class MlDsa65KeyPair {
17
20
  wasm.__wbg_mldsa65keypair_free(ptr, 0);
18
21
  }
19
22
  /**
23
+ * Signing key as a 32-byte seed; expanded on demand during signing.
20
24
  * @returns {Uint8Array}
21
25
  */
22
26
  get signing_key() {
@@ -26,6 +30,7 @@ export class MlDsa65KeyPair {
26
30
  return v1;
27
31
  }
28
32
  /**
33
+ * Verifying (public) key, 1952 bytes.
29
34
  * @returns {Uint8Array}
30
35
  */
31
36
  get verifying_key() {
@@ -37,6 +42,43 @@ export class MlDsa65KeyPair {
37
42
  }
38
43
  if (Symbol.dispose) MlDsa65KeyPair.prototype[Symbol.dispose] = MlDsa65KeyPair.prototype.free;
39
44
 
45
+ /**
46
+ * Output of ML-KEM-768 decapsulation: the recovered shared secret.
47
+ */
48
+ export class MlKem768DecapResult {
49
+ static __wrap(ptr) {
50
+ ptr = ptr >>> 0;
51
+ const obj = Object.create(MlKem768DecapResult.prototype);
52
+ obj.__wbg_ptr = ptr;
53
+ MlKem768DecapResultFinalization.register(obj, obj.__wbg_ptr, obj);
54
+ return obj;
55
+ }
56
+ __destroy_into_raw() {
57
+ const ptr = this.__wbg_ptr;
58
+ this.__wbg_ptr = 0;
59
+ MlKem768DecapResultFinalization.unregister(this);
60
+ return ptr;
61
+ }
62
+ free() {
63
+ const ptr = this.__destroy_into_raw();
64
+ wasm.__wbg_mlkem768decapresult_free(ptr, 0);
65
+ }
66
+ /**
67
+ * Shared secret recovered from the ciphertext, 32 bytes.
68
+ * @returns {Uint8Array}
69
+ */
70
+ get shared_secret() {
71
+ const ret = wasm.mlkem768decapresult_shared_secret(this.__wbg_ptr);
72
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
73
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
74
+ return v1;
75
+ }
76
+ }
77
+ if (Symbol.dispose) MlKem768DecapResult.prototype[Symbol.dispose] = MlKem768DecapResult.prototype.free;
78
+
79
+ /**
80
+ * Output of ML-KEM-768 encapsulation: ciphertext + shared secret.
81
+ */
40
82
  export class MlKem768EncapResult {
41
83
  static __wrap(ptr) {
42
84
  ptr = ptr >>> 0;
@@ -56,6 +98,7 @@ export class MlKem768EncapResult {
56
98
  wasm.__wbg_mlkem768encapresult_free(ptr, 0);
57
99
  }
58
100
  /**
101
+ * Ciphertext to send to the decapsulator, 1088 bytes.
59
102
  * @returns {Uint8Array}
60
103
  */
61
104
  get ciphertext() {
@@ -65,6 +108,7 @@ export class MlKem768EncapResult {
65
108
  return v1;
66
109
  }
67
110
  /**
111
+ * Shared secret derived from encapsulation, 32 bytes.
68
112
  * @returns {Uint8Array}
69
113
  */
70
114
  get shared_secret() {
@@ -76,6 +120,9 @@ export class MlKem768EncapResult {
76
120
  }
77
121
  if (Symbol.dispose) MlKem768EncapResult.prototype[Symbol.dispose] = MlKem768EncapResult.prototype.free;
78
122
 
123
+ /**
124
+ * ML-KEM-768 key pair (encapsulation + decapsulation key).
125
+ */
79
126
  export class MlKem768KeyPair {
80
127
  static __wrap(ptr) {
81
128
  ptr = ptr >>> 0;
@@ -95,6 +142,7 @@ export class MlKem768KeyPair {
95
142
  wasm.__wbg_mlkem768keypair_free(ptr, 0);
96
143
  }
97
144
  /**
145
+ * Decapsulation (private) key, 2400 bytes.
98
146
  * @returns {Uint8Array}
99
147
  */
100
148
  get decapsulation_key() {
@@ -104,6 +152,7 @@ export class MlKem768KeyPair {
104
152
  return v1;
105
153
  }
106
154
  /**
155
+ * Encapsulation (public) key, 1184 bytes.
107
156
  * @returns {Uint8Array}
108
157
  */
109
158
  get encapsulation_key() {
@@ -116,6 +165,7 @@ export class MlKem768KeyPair {
116
165
  if (Symbol.dispose) MlKem768KeyPair.prototype[Symbol.dispose] = MlKem768KeyPair.prototype.free;
117
166
 
118
167
  /**
168
+ * Generate a fresh ML-DSA-65 key pair from 32 random seed bytes.
119
169
  * @returns {MlDsa65KeyPair}
120
170
  */
121
171
  export function ml_dsa_65_generate() {
@@ -124,6 +174,7 @@ export function ml_dsa_65_generate() {
124
174
  }
125
175
 
126
176
  /**
177
+ * Sign `message` with a 32-byte ML-DSA-65 seed, returning a 3309-byte signature.
127
178
  * @param {Uint8Array} sk_bytes
128
179
  * @param {Uint8Array} message
129
180
  * @returns {Uint8Array}
@@ -143,6 +194,7 @@ export function ml_dsa_65_sign(sk_bytes, message) {
143
194
  }
144
195
 
145
196
  /**
197
+ * Verify a 3309-byte ML-DSA-65 signature over `message` against a 1952-byte verifying key.
146
198
  * @param {Uint8Array} vk_bytes
147
199
  * @param {Uint8Array} message
148
200
  * @param {Uint8Array} signature
@@ -163,9 +215,10 @@ export function ml_dsa_65_verify(vk_bytes, message, signature) {
163
215
  }
164
216
 
165
217
  /**
218
+ * Decapsulate a 1088-byte ciphertext with a 2400-byte decapsulation key.
166
219
  * @param {Uint8Array} dk_bytes
167
220
  * @param {Uint8Array} ct_bytes
168
- * @returns {Uint8Array}
221
+ * @returns {MlKem768DecapResult}
169
222
  */
170
223
  export function ml_kem_768_decapsulate(dk_bytes, ct_bytes) {
171
224
  const ptr0 = passArray8ToWasm0(dk_bytes, wasm.__wbindgen_malloc);
@@ -173,15 +226,14 @@ export function ml_kem_768_decapsulate(dk_bytes, ct_bytes) {
173
226
  const ptr1 = passArray8ToWasm0(ct_bytes, wasm.__wbindgen_malloc);
174
227
  const len1 = WASM_VECTOR_LEN;
175
228
  const ret = wasm.ml_kem_768_decapsulate(ptr0, len0, ptr1, len1);
176
- if (ret[3]) {
177
- throw takeFromExternrefTable0(ret[2]);
229
+ if (ret[2]) {
230
+ throw takeFromExternrefTable0(ret[1]);
178
231
  }
179
- var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
180
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
181
- return v3;
232
+ return MlKem768DecapResult.__wrap(ret[0]);
182
233
  }
183
234
 
184
235
  /**
236
+ * Encapsulate a fresh shared secret to a 1184-byte encapsulation key.
185
237
  * @param {Uint8Array} ek_bytes
186
238
  * @returns {MlKem768EncapResult}
187
239
  */
@@ -196,6 +248,7 @@ export function ml_kem_768_encapsulate(ek_bytes) {
196
248
  }
197
249
 
198
250
  /**
251
+ * Generate a fresh ML-KEM-768 key pair using OS randomness.
199
252
  * @returns {MlKem768KeyPair}
200
253
  */
201
254
  export function ml_kem_768_generate() {
@@ -313,6 +366,9 @@ export function __wbindgen_init_externref_table() {
313
366
  const MlDsa65KeyPairFinalization = (typeof FinalizationRegistry === 'undefined')
314
367
  ? { register: () => {}, unregister: () => {} }
315
368
  : new FinalizationRegistry(ptr => wasm.__wbg_mldsa65keypair_free(ptr >>> 0, 1));
369
+ const MlKem768DecapResultFinalization = (typeof FinalizationRegistry === 'undefined')
370
+ ? { register: () => {}, unregister: () => {} }
371
+ : new FinalizationRegistry(ptr => wasm.__wbg_mlkem768decapresult_free(ptr >>> 0, 1));
316
372
  const MlKem768EncapResultFinalization = (typeof FinalizationRegistry === 'undefined')
317
373
  ? { register: () => {}, unregister: () => {} }
318
374
  : new FinalizationRegistry(ptr => wasm.__wbg_mlkem768encapresult_free(ptr >>> 0, 1));
Binary file
@@ -2,20 +2,22 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const __wbg_mldsa65keypair_free: (a: number, b: number) => void;
5
- export const __wbg_mlkem768keypair_free: (a: number, b: number) => void;
5
+ export const __wbg_mlkem768decapresult_free: (a: number, b: number) => void;
6
6
  export const ml_dsa_65_generate: () => number;
7
7
  export const ml_dsa_65_sign: (a: number, b: number, c: number, d: number) => [number, number, number, number];
8
8
  export const ml_dsa_65_verify: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
9
- export const ml_kem_768_decapsulate: (a: number, b: number, c: number, d: number) => [number, number, number, number];
9
+ export const ml_kem_768_decapsulate: (a: number, b: number, c: number, d: number) => [number, number, number];
10
10
  export const ml_kem_768_encapsulate: (a: number, b: number) => [number, number, number];
11
11
  export const ml_kem_768_generate: () => number;
12
12
  export const mldsa65keypair_signing_key: (a: number) => [number, number];
13
13
  export const mldsa65keypair_verifying_key: (a: number) => [number, number];
14
- export const mlkem768keypair_decapsulation_key: (a: number) => [number, number];
15
- export const mlkem768keypair_encapsulation_key: (a: number) => [number, number];
14
+ export const mlkem768decapresult_shared_secret: (a: number) => [number, number];
15
+ export const __wbg_mlkem768encapresult_free: (a: number, b: number) => void;
16
+ export const __wbg_mlkem768keypair_free: (a: number, b: number) => void;
16
17
  export const mlkem768encapresult_ciphertext: (a: number) => [number, number];
17
18
  export const mlkem768encapresult_shared_secret: (a: number) => [number, number];
18
- export const __wbg_mlkem768encapresult_free: (a: number, b: number) => void;
19
+ export const mlkem768keypair_decapsulation_key: (a: number) => [number, number];
20
+ export const mlkem768keypair_encapsulation_key: (a: number) => [number, number];
19
21
  export const __wbindgen_exn_store: (a: number) => void;
20
22
  export const __externref_table_alloc: () => number;
21
23
  export const __wbindgen_externrefs: WebAssembly.Table;
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gefson Costa
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.
@@ -45,7 +45,7 @@ const decrypted = await decapsulate(ciphertext, kp.secretKey)
45
45
  // ML-DSA-65
46
46
  const sigKp = await generateSignatureKeyPair()
47
47
  // sigKp.publicKey: Uint8Array (1,952 bytes)
48
- // sigKp.secretKey: Uint8Array (4,032 bytes)
48
+ // sigKp.secretKey: Uint8Array (32 bytes, FIPS 204 seed)
49
49
 
50
50
  const signature = await sign(message, sigKp.secretKey)
51
51
  // signature: Uint8Array (3,309 bytes)
@@ -76,14 +76,17 @@ The consumer never calls `free()`, never calls `init()`, and never imports from
76
76
  | Algorithm | Public Key | Secret Key | Ciphertext | Signature | Shared Secret |
77
77
  |-----------|-----------|-----------|-----------|----------|--------------|
78
78
  | ML-KEM-768 | 1,184 B | 2,400 B | 1,088 B | — | 32 B |
79
- | ML-DSA-65 | 1,952 B | 4,032 B | — | 3,309 B | — |
79
+ | ML-DSA-65 | 1,952 B | 32 B (seed) | — | 3,309 B | — |
80
80
 
81
81
  ## Security
82
82
 
83
83
  - **Constant-time**: `subtle` crate in Rust, preserved through WASM compilation
84
84
  - **Memory zeroing**: `zeroize` crate with `#[derive(ZeroizeOnDrop)]` on all secret-holding structs
85
- - **No audit**: Neither RustCrypto nor this wrapper have been independently audited. RustCrypto is honest about this. See `PLAN_stenvault_pqc_wasm.md` section 10 for full risk analysis.
86
- - **CVE-2026-22705**: Timing side-channel in `ml-dsa` Decompose function, patched in `>= 0.1.0-rc.3` (Barrett reduction). Cargo.toml pins `>= 0.1.0-rc.3, < 0.2`.
85
+ - **No audit**: Neither RustCrypto nor this wrapper have been independently audited. RustCrypto is honest about this.
86
+ - **CVE-2026-22705**: Timing side-channel in `ml-dsa` Decompose function, patched in `>= 0.1.0-rc.3` (Barrett reduction).
87
+ - **CVE-2026-24850**: Signature malleability via duplicate hint indices in `ml-dsa`, patched in `>= 0.1.0-rc.4`.
88
+ - **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`.
89
+ - Cargo.toml pins `= 0.1.0-rc.8` (FIPS 204 seed API + WASM stack-overflow fix via PRs #1259 + #1261).
87
90
  - **Supply chain**: `Cargo.lock` committed, CI runs `cargo audit` before every build.
88
91
 
89
92
  ## License
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "stenvault-pqc",
3
3
  "description": "ML-KEM-768 + ML-DSA-65 WASM wrapper for StenVault",
4
- "version": "0.1.0",
4
+ "version": "0.2.0",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "stenvault_pqc_bg.wasm",
@@ -10,4 +10,4 @@
10
10
  ],
11
11
  "main": "stenvault_pqc.js",
12
12
  "types": "stenvault_pqc.d.ts"
13
- }
13
+ }
@@ -1,38 +1,96 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
+ /**
5
+ * ML-DSA-65 key pair (verifying key + 32-byte signing seed).
6
+ */
4
7
  export class MlDsa65KeyPair {
5
8
  private constructor();
6
9
  free(): void;
7
10
  [Symbol.dispose](): void;
11
+ /**
12
+ * Signing key as a 32-byte seed; expanded on demand during signing.
13
+ */
8
14
  readonly signing_key: Uint8Array;
15
+ /**
16
+ * Verifying (public) key, 1952 bytes.
17
+ */
9
18
  readonly verifying_key: Uint8Array;
10
19
  }
11
20
 
21
+ /**
22
+ * Output of ML-KEM-768 decapsulation: the recovered shared secret.
23
+ */
24
+ export class MlKem768DecapResult {
25
+ private constructor();
26
+ free(): void;
27
+ [Symbol.dispose](): void;
28
+ /**
29
+ * Shared secret recovered from the ciphertext, 32 bytes.
30
+ */
31
+ readonly shared_secret: Uint8Array;
32
+ }
33
+
34
+ /**
35
+ * Output of ML-KEM-768 encapsulation: ciphertext + shared secret.
36
+ */
12
37
  export class MlKem768EncapResult {
13
38
  private constructor();
14
39
  free(): void;
15
40
  [Symbol.dispose](): void;
41
+ /**
42
+ * Ciphertext to send to the decapsulator, 1088 bytes.
43
+ */
16
44
  readonly ciphertext: Uint8Array;
45
+ /**
46
+ * Shared secret derived from encapsulation, 32 bytes.
47
+ */
17
48
  readonly shared_secret: Uint8Array;
18
49
  }
19
50
 
51
+ /**
52
+ * ML-KEM-768 key pair (encapsulation + decapsulation key).
53
+ */
20
54
  export class MlKem768KeyPair {
21
55
  private constructor();
22
56
  free(): void;
23
57
  [Symbol.dispose](): void;
58
+ /**
59
+ * Decapsulation (private) key, 2400 bytes.
60
+ */
24
61
  readonly decapsulation_key: Uint8Array;
62
+ /**
63
+ * Encapsulation (public) key, 1184 bytes.
64
+ */
25
65
  readonly encapsulation_key: Uint8Array;
26
66
  }
27
67
 
68
+ /**
69
+ * Generate a fresh ML-DSA-65 key pair from 32 random seed bytes.
70
+ */
28
71
  export function ml_dsa_65_generate(): MlDsa65KeyPair;
29
72
 
73
+ /**
74
+ * Sign `message` with a 32-byte ML-DSA-65 seed, returning a 3309-byte signature.
75
+ */
30
76
  export function ml_dsa_65_sign(sk_bytes: Uint8Array, message: Uint8Array): Uint8Array;
31
77
 
78
+ /**
79
+ * Verify a 3309-byte ML-DSA-65 signature over `message` against a 1952-byte verifying key.
80
+ */
32
81
  export function ml_dsa_65_verify(vk_bytes: Uint8Array, message: Uint8Array, signature: Uint8Array): boolean;
33
82
 
34
- export function ml_kem_768_decapsulate(dk_bytes: Uint8Array, ct_bytes: Uint8Array): Uint8Array;
83
+ /**
84
+ * Decapsulate a 1088-byte ciphertext with a 2400-byte decapsulation key.
85
+ */
86
+ export function ml_kem_768_decapsulate(dk_bytes: Uint8Array, ct_bytes: Uint8Array): MlKem768DecapResult;
35
87
 
88
+ /**
89
+ * Encapsulate a fresh shared secret to a 1184-byte encapsulation key.
90
+ */
36
91
  export function ml_kem_768_encapsulate(ek_bytes: Uint8Array): MlKem768EncapResult;
37
92
 
93
+ /**
94
+ * Generate a fresh ML-KEM-768 key pair using OS randomness.
95
+ */
38
96
  export function ml_kem_768_generate(): MlKem768KeyPair;
@@ -1,5 +1,8 @@
1
1
  /* @ts-self-types="./stenvault_pqc.d.ts" */
2
2
 
3
+ /**
4
+ * ML-DSA-65 key pair (verifying key + 32-byte signing seed).
5
+ */
3
6
  class MlDsa65KeyPair {
4
7
  static __wrap(ptr) {
5
8
  ptr = ptr >>> 0;
@@ -19,6 +22,7 @@ class MlDsa65KeyPair {
19
22
  wasm.__wbg_mldsa65keypair_free(ptr, 0);
20
23
  }
21
24
  /**
25
+ * Signing key as a 32-byte seed; expanded on demand during signing.
22
26
  * @returns {Uint8Array}
23
27
  */
24
28
  get signing_key() {
@@ -28,6 +32,7 @@ class MlDsa65KeyPair {
28
32
  return v1;
29
33
  }
30
34
  /**
35
+ * Verifying (public) key, 1952 bytes.
31
36
  * @returns {Uint8Array}
32
37
  */
33
38
  get verifying_key() {
@@ -40,6 +45,44 @@ class MlDsa65KeyPair {
40
45
  if (Symbol.dispose) MlDsa65KeyPair.prototype[Symbol.dispose] = MlDsa65KeyPair.prototype.free;
41
46
  exports.MlDsa65KeyPair = MlDsa65KeyPair;
42
47
 
48
+ /**
49
+ * Output of ML-KEM-768 decapsulation: the recovered shared secret.
50
+ */
51
+ class MlKem768DecapResult {
52
+ static __wrap(ptr) {
53
+ ptr = ptr >>> 0;
54
+ const obj = Object.create(MlKem768DecapResult.prototype);
55
+ obj.__wbg_ptr = ptr;
56
+ MlKem768DecapResultFinalization.register(obj, obj.__wbg_ptr, obj);
57
+ return obj;
58
+ }
59
+ __destroy_into_raw() {
60
+ const ptr = this.__wbg_ptr;
61
+ this.__wbg_ptr = 0;
62
+ MlKem768DecapResultFinalization.unregister(this);
63
+ return ptr;
64
+ }
65
+ free() {
66
+ const ptr = this.__destroy_into_raw();
67
+ wasm.__wbg_mlkem768decapresult_free(ptr, 0);
68
+ }
69
+ /**
70
+ * Shared secret recovered from the ciphertext, 32 bytes.
71
+ * @returns {Uint8Array}
72
+ */
73
+ get shared_secret() {
74
+ const ret = wasm.mlkem768decapresult_shared_secret(this.__wbg_ptr);
75
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
76
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
77
+ return v1;
78
+ }
79
+ }
80
+ if (Symbol.dispose) MlKem768DecapResult.prototype[Symbol.dispose] = MlKem768DecapResult.prototype.free;
81
+ exports.MlKem768DecapResult = MlKem768DecapResult;
82
+
83
+ /**
84
+ * Output of ML-KEM-768 encapsulation: ciphertext + shared secret.
85
+ */
43
86
  class MlKem768EncapResult {
44
87
  static __wrap(ptr) {
45
88
  ptr = ptr >>> 0;
@@ -59,6 +102,7 @@ class MlKem768EncapResult {
59
102
  wasm.__wbg_mlkem768encapresult_free(ptr, 0);
60
103
  }
61
104
  /**
105
+ * Ciphertext to send to the decapsulator, 1088 bytes.
62
106
  * @returns {Uint8Array}
63
107
  */
64
108
  get ciphertext() {
@@ -68,6 +112,7 @@ class MlKem768EncapResult {
68
112
  return v1;
69
113
  }
70
114
  /**
115
+ * Shared secret derived from encapsulation, 32 bytes.
71
116
  * @returns {Uint8Array}
72
117
  */
73
118
  get shared_secret() {
@@ -80,6 +125,9 @@ class MlKem768EncapResult {
80
125
  if (Symbol.dispose) MlKem768EncapResult.prototype[Symbol.dispose] = MlKem768EncapResult.prototype.free;
81
126
  exports.MlKem768EncapResult = MlKem768EncapResult;
82
127
 
128
+ /**
129
+ * ML-KEM-768 key pair (encapsulation + decapsulation key).
130
+ */
83
131
  class MlKem768KeyPair {
84
132
  static __wrap(ptr) {
85
133
  ptr = ptr >>> 0;
@@ -99,6 +147,7 @@ class MlKem768KeyPair {
99
147
  wasm.__wbg_mlkem768keypair_free(ptr, 0);
100
148
  }
101
149
  /**
150
+ * Decapsulation (private) key, 2400 bytes.
102
151
  * @returns {Uint8Array}
103
152
  */
104
153
  get decapsulation_key() {
@@ -108,6 +157,7 @@ class MlKem768KeyPair {
108
157
  return v1;
109
158
  }
110
159
  /**
160
+ * Encapsulation (public) key, 1184 bytes.
111
161
  * @returns {Uint8Array}
112
162
  */
113
163
  get encapsulation_key() {
@@ -121,6 +171,7 @@ if (Symbol.dispose) MlKem768KeyPair.prototype[Symbol.dispose] = MlKem768KeyPair.
121
171
  exports.MlKem768KeyPair = MlKem768KeyPair;
122
172
 
123
173
  /**
174
+ * Generate a fresh ML-DSA-65 key pair from 32 random seed bytes.
124
175
  * @returns {MlDsa65KeyPair}
125
176
  */
126
177
  function ml_dsa_65_generate() {
@@ -130,6 +181,7 @@ function ml_dsa_65_generate() {
130
181
  exports.ml_dsa_65_generate = ml_dsa_65_generate;
131
182
 
132
183
  /**
184
+ * Sign `message` with a 32-byte ML-DSA-65 seed, returning a 3309-byte signature.
133
185
  * @param {Uint8Array} sk_bytes
134
186
  * @param {Uint8Array} message
135
187
  * @returns {Uint8Array}
@@ -150,6 +202,7 @@ function ml_dsa_65_sign(sk_bytes, message) {
150
202
  exports.ml_dsa_65_sign = ml_dsa_65_sign;
151
203
 
152
204
  /**
205
+ * Verify a 3309-byte ML-DSA-65 signature over `message` against a 1952-byte verifying key.
153
206
  * @param {Uint8Array} vk_bytes
154
207
  * @param {Uint8Array} message
155
208
  * @param {Uint8Array} signature
@@ -171,9 +224,10 @@ function ml_dsa_65_verify(vk_bytes, message, signature) {
171
224
  exports.ml_dsa_65_verify = ml_dsa_65_verify;
172
225
 
173
226
  /**
227
+ * Decapsulate a 1088-byte ciphertext with a 2400-byte decapsulation key.
174
228
  * @param {Uint8Array} dk_bytes
175
229
  * @param {Uint8Array} ct_bytes
176
- * @returns {Uint8Array}
230
+ * @returns {MlKem768DecapResult}
177
231
  */
178
232
  function ml_kem_768_decapsulate(dk_bytes, ct_bytes) {
179
233
  const ptr0 = passArray8ToWasm0(dk_bytes, wasm.__wbindgen_malloc);
@@ -181,16 +235,15 @@ function ml_kem_768_decapsulate(dk_bytes, ct_bytes) {
181
235
  const ptr1 = passArray8ToWasm0(ct_bytes, wasm.__wbindgen_malloc);
182
236
  const len1 = WASM_VECTOR_LEN;
183
237
  const ret = wasm.ml_kem_768_decapsulate(ptr0, len0, ptr1, len1);
184
- if (ret[3]) {
185
- throw takeFromExternrefTable0(ret[2]);
238
+ if (ret[2]) {
239
+ throw takeFromExternrefTable0(ret[1]);
186
240
  }
187
- var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
188
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
189
- return v3;
241
+ return MlKem768DecapResult.__wrap(ret[0]);
190
242
  }
191
243
  exports.ml_kem_768_decapsulate = ml_kem_768_decapsulate;
192
244
 
193
245
  /**
246
+ * Encapsulate a fresh shared secret to a 1184-byte encapsulation key.
194
247
  * @param {Uint8Array} ek_bytes
195
248
  * @returns {MlKem768EncapResult}
196
249
  */
@@ -206,6 +259,7 @@ function ml_kem_768_encapsulate(ek_bytes) {
206
259
  exports.ml_kem_768_encapsulate = ml_kem_768_encapsulate;
207
260
 
208
261
  /**
262
+ * Generate a fresh ML-KEM-768 key pair using OS randomness.
209
263
  * @returns {MlKem768KeyPair}
210
264
  */
211
265
  function ml_kem_768_generate() {
@@ -335,6 +389,9 @@ function __wbg_get_imports() {
335
389
  const MlDsa65KeyPairFinalization = (typeof FinalizationRegistry === 'undefined')
336
390
  ? { register: () => {}, unregister: () => {} }
337
391
  : new FinalizationRegistry(ptr => wasm.__wbg_mldsa65keypair_free(ptr >>> 0, 1));
392
+ const MlKem768DecapResultFinalization = (typeof FinalizationRegistry === 'undefined')
393
+ ? { register: () => {}, unregister: () => {} }
394
+ : new FinalizationRegistry(ptr => wasm.__wbg_mlkem768decapresult_free(ptr >>> 0, 1));
338
395
  const MlKem768EncapResultFinalization = (typeof FinalizationRegistry === 'undefined')
339
396
  ? { register: () => {}, unregister: () => {} }
340
397
  : new FinalizationRegistry(ptr => wasm.__wbg_mlkem768encapresult_free(ptr >>> 0, 1));
Binary file
@@ -2,20 +2,22 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const __wbg_mldsa65keypair_free: (a: number, b: number) => void;
5
- export const __wbg_mlkem768keypair_free: (a: number, b: number) => void;
5
+ export const __wbg_mlkem768decapresult_free: (a: number, b: number) => void;
6
6
  export const ml_dsa_65_generate: () => number;
7
7
  export const ml_dsa_65_sign: (a: number, b: number, c: number, d: number) => [number, number, number, number];
8
8
  export const ml_dsa_65_verify: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
9
- export const ml_kem_768_decapsulate: (a: number, b: number, c: number, d: number) => [number, number, number, number];
9
+ export const ml_kem_768_decapsulate: (a: number, b: number, c: number, d: number) => [number, number, number];
10
10
  export const ml_kem_768_encapsulate: (a: number, b: number) => [number, number, number];
11
11
  export const ml_kem_768_generate: () => number;
12
12
  export const mldsa65keypair_signing_key: (a: number) => [number, number];
13
13
  export const mldsa65keypair_verifying_key: (a: number) => [number, number];
14
- export const mlkem768keypair_decapsulation_key: (a: number) => [number, number];
15
- export const mlkem768keypair_encapsulation_key: (a: number) => [number, number];
14
+ export const mlkem768decapresult_shared_secret: (a: number) => [number, number];
15
+ export const __wbg_mlkem768encapresult_free: (a: number, b: number) => void;
16
+ export const __wbg_mlkem768keypair_free: (a: number, b: number) => void;
16
17
  export const mlkem768encapresult_ciphertext: (a: number) => [number, number];
17
18
  export const mlkem768encapresult_shared_secret: (a: number) => [number, number];
18
- export const __wbg_mlkem768encapresult_free: (a: number, b: number) => void;
19
+ export const mlkem768keypair_decapsulation_key: (a: number) => [number, number];
20
+ export const mlkem768keypair_encapsulation_key: (a: number) => [number, number];
19
21
  export const __wbindgen_exn_store: (a: number) => void;
20
22
  export const __externref_table_alloc: () => number;
21
23
  export const __wbindgen_externrefs: WebAssembly.Table;
package/src/core.js CHANGED
@@ -44,7 +44,13 @@ export function encapsulateCore(publicKey) {
44
44
  export function decapsulateCore(ciphertext, secretKey) {
45
45
  const w = getWasm();
46
46
  // Rust API: (dk, ct) — we receive (ct, sk) from StenVault convention
47
- return new Uint8Array(w.ml_kem_768_decapsulate(secretKey, ciphertext));
47
+ const result = w.ml_kem_768_decapsulate(secretKey, ciphertext);
48
+ try {
49
+ return new Uint8Array(result.shared_secret);
50
+ }
51
+ finally {
52
+ result.free();
53
+ }
48
54
  }
49
55
  // ── ML-DSA-65 ───────────────────────────────────────────────────────────────
50
56
  export function generateSignatureKeyPairCore() {