@stenvault/pqc-wasm 0.3.1 → 0.4.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/README.md +37 -9
- package/package.json +5 -4
- package/pkg-bundler/README.md +37 -9
- package/pkg-bundler/package.json +2 -2
- package/pkg-bundler/stenvault_pqc.d.ts +94 -0
- package/pkg-bundler/stenvault_pqc.js +1 -1
- package/pkg-bundler/stenvault_pqc_bg.js +272 -95
- package/pkg-bundler/stenvault_pqc_bg.wasm +0 -0
- package/pkg-bundler/stenvault_pqc_bg.wasm.d.ts +21 -4
- package/pkg-nodejs/README.md +37 -9
- package/pkg-nodejs/package.json +2 -2
- package/pkg-nodejs/stenvault_pqc.d.ts +94 -0
- package/pkg-nodejs/stenvault_pqc.js +282 -95
- package/pkg-nodejs/stenvault_pqc_bg.wasm +0 -0
- package/pkg-nodejs/stenvault_pqc_bg.wasm.d.ts +21 -4
- package/src/core.d.ts +9 -7
- package/src/core.js +65 -18
- package/src/index.browser.d.ts +5 -1
- package/src/index.browser.js +12 -7
- package/src/index.node.d.ts +5 -1
- package/src/index.node.js +12 -7
- package/src/types.d.ts +16 -0
|
@@ -42,6 +42,172 @@ export class MlDsa65KeyPair {
|
|
|
42
42
|
}
|
|
43
43
|
if (Symbol.dispose) MlDsa65KeyPair.prototype[Symbol.dispose] = MlDsa65KeyPair.prototype.free;
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* ML-DSA-87 key pair (verifying key + 32-byte signing seed).
|
|
47
|
+
*/
|
|
48
|
+
export class MlDsa87KeyPair {
|
|
49
|
+
static __wrap(ptr) {
|
|
50
|
+
ptr = ptr >>> 0;
|
|
51
|
+
const obj = Object.create(MlDsa87KeyPair.prototype);
|
|
52
|
+
obj.__wbg_ptr = ptr;
|
|
53
|
+
MlDsa87KeyPairFinalization.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
|
+
MlDsa87KeyPairFinalization.unregister(this);
|
|
60
|
+
return ptr;
|
|
61
|
+
}
|
|
62
|
+
free() {
|
|
63
|
+
const ptr = this.__destroy_into_raw();
|
|
64
|
+
wasm.__wbg_mldsa87keypair_free(ptr, 0);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Signing key as a 32-byte seed; expanded on demand during signing.
|
|
68
|
+
* @returns {Uint8Array}
|
|
69
|
+
*/
|
|
70
|
+
get signing_key() {
|
|
71
|
+
const ret = wasm.mldsa87keypair_signing_key(this.__wbg_ptr);
|
|
72
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
73
|
+
wasm.__wbindgen_export5(ret[0], ret[1] * 1, 1);
|
|
74
|
+
return v1;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Verifying (public) key, 2592 bytes.
|
|
78
|
+
* @returns {Uint8Array}
|
|
79
|
+
*/
|
|
80
|
+
get verifying_key() {
|
|
81
|
+
const ret = wasm.mldsa87keypair_verifying_key(this.__wbg_ptr);
|
|
82
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
83
|
+
wasm.__wbindgen_export5(ret[0], ret[1] * 1, 1);
|
|
84
|
+
return v1;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (Symbol.dispose) MlDsa87KeyPair.prototype[Symbol.dispose] = MlDsa87KeyPair.prototype.free;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Output of ML-KEM-1024 decapsulation: the recovered shared secret.
|
|
91
|
+
*/
|
|
92
|
+
export class MlKem1024DecapResult {
|
|
93
|
+
static __wrap(ptr) {
|
|
94
|
+
ptr = ptr >>> 0;
|
|
95
|
+
const obj = Object.create(MlKem1024DecapResult.prototype);
|
|
96
|
+
obj.__wbg_ptr = ptr;
|
|
97
|
+
MlKem1024DecapResultFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
98
|
+
return obj;
|
|
99
|
+
}
|
|
100
|
+
__destroy_into_raw() {
|
|
101
|
+
const ptr = this.__wbg_ptr;
|
|
102
|
+
this.__wbg_ptr = 0;
|
|
103
|
+
MlKem1024DecapResultFinalization.unregister(this);
|
|
104
|
+
return ptr;
|
|
105
|
+
}
|
|
106
|
+
free() {
|
|
107
|
+
const ptr = this.__destroy_into_raw();
|
|
108
|
+
wasm.__wbg_mlkem1024decapresult_free(ptr, 0);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Shared secret recovered from the ciphertext, 32 bytes.
|
|
112
|
+
* @returns {Uint8Array}
|
|
113
|
+
*/
|
|
114
|
+
get shared_secret() {
|
|
115
|
+
const ret = wasm.mlkem1024decapresult_shared_secret(this.__wbg_ptr);
|
|
116
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
117
|
+
wasm.__wbindgen_export5(ret[0], ret[1] * 1, 1);
|
|
118
|
+
return v1;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (Symbol.dispose) MlKem1024DecapResult.prototype[Symbol.dispose] = MlKem1024DecapResult.prototype.free;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Output of ML-KEM-1024 encapsulation: ciphertext + shared secret.
|
|
125
|
+
*/
|
|
126
|
+
export class MlKem1024EncapResult {
|
|
127
|
+
static __wrap(ptr) {
|
|
128
|
+
ptr = ptr >>> 0;
|
|
129
|
+
const obj = Object.create(MlKem1024EncapResult.prototype);
|
|
130
|
+
obj.__wbg_ptr = ptr;
|
|
131
|
+
MlKem1024EncapResultFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
132
|
+
return obj;
|
|
133
|
+
}
|
|
134
|
+
__destroy_into_raw() {
|
|
135
|
+
const ptr = this.__wbg_ptr;
|
|
136
|
+
this.__wbg_ptr = 0;
|
|
137
|
+
MlKem1024EncapResultFinalization.unregister(this);
|
|
138
|
+
return ptr;
|
|
139
|
+
}
|
|
140
|
+
free() {
|
|
141
|
+
const ptr = this.__destroy_into_raw();
|
|
142
|
+
wasm.__wbg_mlkem1024encapresult_free(ptr, 0);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Ciphertext to send to the decapsulator, 1568 bytes.
|
|
146
|
+
* @returns {Uint8Array}
|
|
147
|
+
*/
|
|
148
|
+
get ciphertext() {
|
|
149
|
+
const ret = wasm.mlkem1024encapresult_ciphertext(this.__wbg_ptr);
|
|
150
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
151
|
+
wasm.__wbindgen_export5(ret[0], ret[1] * 1, 1);
|
|
152
|
+
return v1;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Shared secret derived from encapsulation, 32 bytes.
|
|
156
|
+
* @returns {Uint8Array}
|
|
157
|
+
*/
|
|
158
|
+
get shared_secret() {
|
|
159
|
+
const ret = wasm.mlkem1024encapresult_shared_secret(this.__wbg_ptr);
|
|
160
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
161
|
+
wasm.__wbindgen_export5(ret[0], ret[1] * 1, 1);
|
|
162
|
+
return v1;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (Symbol.dispose) MlKem1024EncapResult.prototype[Symbol.dispose] = MlKem1024EncapResult.prototype.free;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* ML-KEM-1024 key pair (encapsulation + decapsulation key).
|
|
169
|
+
*/
|
|
170
|
+
export class MlKem1024KeyPair {
|
|
171
|
+
static __wrap(ptr) {
|
|
172
|
+
ptr = ptr >>> 0;
|
|
173
|
+
const obj = Object.create(MlKem1024KeyPair.prototype);
|
|
174
|
+
obj.__wbg_ptr = ptr;
|
|
175
|
+
MlKem1024KeyPairFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
176
|
+
return obj;
|
|
177
|
+
}
|
|
178
|
+
__destroy_into_raw() {
|
|
179
|
+
const ptr = this.__wbg_ptr;
|
|
180
|
+
this.__wbg_ptr = 0;
|
|
181
|
+
MlKem1024KeyPairFinalization.unregister(this);
|
|
182
|
+
return ptr;
|
|
183
|
+
}
|
|
184
|
+
free() {
|
|
185
|
+
const ptr = this.__destroy_into_raw();
|
|
186
|
+
wasm.__wbg_mlkem1024keypair_free(ptr, 0);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Decapsulation (private) key, 3168 bytes.
|
|
190
|
+
* @returns {Uint8Array}
|
|
191
|
+
*/
|
|
192
|
+
get decapsulation_key() {
|
|
193
|
+
const ret = wasm.mlkem1024keypair_decapsulation_key(this.__wbg_ptr);
|
|
194
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
195
|
+
wasm.__wbindgen_export5(ret[0], ret[1] * 1, 1);
|
|
196
|
+
return v1;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Encapsulation (public) key, 1568 bytes.
|
|
200
|
+
* @returns {Uint8Array}
|
|
201
|
+
*/
|
|
202
|
+
get encapsulation_key() {
|
|
203
|
+
const ret = wasm.mlkem1024keypair_encapsulation_key(this.__wbg_ptr);
|
|
204
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
205
|
+
wasm.__wbindgen_export5(ret[0], ret[1] * 1, 1);
|
|
206
|
+
return v1;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (Symbol.dispose) MlKem1024KeyPair.prototype[Symbol.dispose] = MlKem1024KeyPair.prototype.free;
|
|
210
|
+
|
|
45
211
|
/**
|
|
46
212
|
* Output of ML-KEM-768 decapsulation: the recovered shared secret.
|
|
47
213
|
*/
|
|
@@ -214,6 +380,98 @@ export function ml_dsa_65_verify(vk_bytes, message, signature) {
|
|
|
214
380
|
return ret[0] !== 0;
|
|
215
381
|
}
|
|
216
382
|
|
|
383
|
+
/**
|
|
384
|
+
* Generate a fresh ML-DSA-87 key pair from 32 random seed bytes.
|
|
385
|
+
* @returns {MlDsa87KeyPair}
|
|
386
|
+
*/
|
|
387
|
+
export function ml_dsa_87_generate() {
|
|
388
|
+
const ret = wasm.ml_dsa_87_generate();
|
|
389
|
+
return MlDsa87KeyPair.__wrap(ret);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Sign `message` with a 32-byte ML-DSA-87 seed, returning a 4627-byte signature.
|
|
394
|
+
* @param {Uint8Array} sk_bytes
|
|
395
|
+
* @param {Uint8Array} message
|
|
396
|
+
* @returns {Uint8Array}
|
|
397
|
+
*/
|
|
398
|
+
export function ml_dsa_87_sign(sk_bytes, message) {
|
|
399
|
+
const ptr0 = passArray8ToWasm0(sk_bytes, wasm.__wbindgen_export3);
|
|
400
|
+
const len0 = WASM_VECTOR_LEN;
|
|
401
|
+
const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_export3);
|
|
402
|
+
const len1 = WASM_VECTOR_LEN;
|
|
403
|
+
const ret = wasm.ml_dsa_87_sign(ptr0, len0, ptr1, len1);
|
|
404
|
+
if (ret[3]) {
|
|
405
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
406
|
+
}
|
|
407
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
408
|
+
wasm.__wbindgen_export5(ret[0], ret[1] * 1, 1);
|
|
409
|
+
return v3;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Verify a 4627-byte ML-DSA-87 signature over `message` against a 2592-byte verifying key.
|
|
414
|
+
* @param {Uint8Array} vk_bytes
|
|
415
|
+
* @param {Uint8Array} message
|
|
416
|
+
* @param {Uint8Array} signature
|
|
417
|
+
* @returns {boolean}
|
|
418
|
+
*/
|
|
419
|
+
export function ml_dsa_87_verify(vk_bytes, message, signature) {
|
|
420
|
+
const ptr0 = passArray8ToWasm0(vk_bytes, wasm.__wbindgen_export3);
|
|
421
|
+
const len0 = WASM_VECTOR_LEN;
|
|
422
|
+
const ptr1 = passArray8ToWasm0(message, wasm.__wbindgen_export3);
|
|
423
|
+
const len1 = WASM_VECTOR_LEN;
|
|
424
|
+
const ptr2 = passArray8ToWasm0(signature, wasm.__wbindgen_export3);
|
|
425
|
+
const len2 = WASM_VECTOR_LEN;
|
|
426
|
+
const ret = wasm.ml_dsa_87_verify(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
427
|
+
if (ret[2]) {
|
|
428
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
429
|
+
}
|
|
430
|
+
return ret[0] !== 0;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Decapsulate a 1568-byte ciphertext with a 3168-byte decapsulation key.
|
|
435
|
+
* @param {Uint8Array} dk_bytes
|
|
436
|
+
* @param {Uint8Array} ct_bytes
|
|
437
|
+
* @returns {MlKem1024DecapResult}
|
|
438
|
+
*/
|
|
439
|
+
export function ml_kem_1024_decapsulate(dk_bytes, ct_bytes) {
|
|
440
|
+
const ptr0 = passArray8ToWasm0(dk_bytes, wasm.__wbindgen_export3);
|
|
441
|
+
const len0 = WASM_VECTOR_LEN;
|
|
442
|
+
const ptr1 = passArray8ToWasm0(ct_bytes, wasm.__wbindgen_export3);
|
|
443
|
+
const len1 = WASM_VECTOR_LEN;
|
|
444
|
+
const ret = wasm.ml_kem_1024_decapsulate(ptr0, len0, ptr1, len1);
|
|
445
|
+
if (ret[2]) {
|
|
446
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
447
|
+
}
|
|
448
|
+
return MlKem1024DecapResult.__wrap(ret[0]);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Encapsulate a fresh shared secret to a 1568-byte encapsulation key.
|
|
453
|
+
* @param {Uint8Array} ek_bytes
|
|
454
|
+
* @returns {MlKem1024EncapResult}
|
|
455
|
+
*/
|
|
456
|
+
export function ml_kem_1024_encapsulate(ek_bytes) {
|
|
457
|
+
const ptr0 = passArray8ToWasm0(ek_bytes, wasm.__wbindgen_export3);
|
|
458
|
+
const len0 = WASM_VECTOR_LEN;
|
|
459
|
+
const ret = wasm.ml_kem_1024_encapsulate(ptr0, len0);
|
|
460
|
+
if (ret[2]) {
|
|
461
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
462
|
+
}
|
|
463
|
+
return MlKem1024EncapResult.__wrap(ret[0]);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Generate a fresh ML-KEM-1024 key pair using OS randomness.
|
|
468
|
+
* @returns {MlKem1024KeyPair}
|
|
469
|
+
*/
|
|
470
|
+
export function ml_kem_1024_generate() {
|
|
471
|
+
const ret = wasm.ml_kem_1024_generate();
|
|
472
|
+
return MlKem1024KeyPair.__wrap(ret);
|
|
473
|
+
}
|
|
474
|
+
|
|
217
475
|
/**
|
|
218
476
|
* Decapsulate a 1088-byte ciphertext with a 2400-byte decapsulation key.
|
|
219
477
|
* @param {Uint8Array} dk_bytes
|
|
@@ -259,101 +517,12 @@ export function __wbg_Error_83742b46f01ce22d(arg0, arg1) {
|
|
|
259
517
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
260
518
|
return ret;
|
|
261
519
|
}
|
|
262
|
-
export function __wbg___wbindgen_is_function_3c846841762788c1(arg0) {
|
|
263
|
-
const ret = typeof(arg0) === 'function';
|
|
264
|
-
return ret;
|
|
265
|
-
}
|
|
266
|
-
export function __wbg___wbindgen_is_object_781bc9f159099513(arg0) {
|
|
267
|
-
const val = arg0;
|
|
268
|
-
const ret = typeof(val) === 'object' && val !== null;
|
|
269
|
-
return ret;
|
|
270
|
-
}
|
|
271
|
-
export function __wbg___wbindgen_is_string_7ef6b97b02428fae(arg0) {
|
|
272
|
-
const ret = typeof(arg0) === 'string';
|
|
273
|
-
return ret;
|
|
274
|
-
}
|
|
275
|
-
export function __wbg___wbindgen_is_undefined_52709e72fb9f179c(arg0) {
|
|
276
|
-
const ret = arg0 === undefined;
|
|
277
|
-
return ret;
|
|
278
|
-
}
|
|
279
520
|
export function __wbg___wbindgen_throw_6ddd609b62940d55(arg0, arg1) {
|
|
280
521
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
281
522
|
}
|
|
282
|
-
export function
|
|
283
|
-
|
|
284
|
-
return ret;
|
|
285
|
-
}, arguments); }
|
|
286
|
-
export function __wbg_crypto_38df2bab126b63dc(arg0) {
|
|
287
|
-
const ret = arg0.crypto;
|
|
288
|
-
return ret;
|
|
289
|
-
}
|
|
290
|
-
export function __wbg_getRandomValues_c44a50d8cfdaebeb() { return handleError(function (arg0, arg1) {
|
|
291
|
-
arg0.getRandomValues(arg1);
|
|
523
|
+
export function __wbg_getRandomValues_cc7f052a444bb2ce() { return handleError(function (arg0, arg1) {
|
|
524
|
+
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
292
525
|
}, arguments); }
|
|
293
|
-
export function __wbg_length_ea16607d7b61445b(arg0) {
|
|
294
|
-
const ret = arg0.length;
|
|
295
|
-
return ret;
|
|
296
|
-
}
|
|
297
|
-
export function __wbg_msCrypto_bd5a034af96bcba6(arg0) {
|
|
298
|
-
const ret = arg0.msCrypto;
|
|
299
|
-
return ret;
|
|
300
|
-
}
|
|
301
|
-
export function __wbg_new_with_length_825018a1616e9e55(arg0) {
|
|
302
|
-
const ret = new Uint8Array(arg0 >>> 0);
|
|
303
|
-
return ret;
|
|
304
|
-
}
|
|
305
|
-
export function __wbg_node_84ea875411254db1(arg0) {
|
|
306
|
-
const ret = arg0.node;
|
|
307
|
-
return ret;
|
|
308
|
-
}
|
|
309
|
-
export function __wbg_process_44c7a14e11e9f69e(arg0) {
|
|
310
|
-
const ret = arg0.process;
|
|
311
|
-
return ret;
|
|
312
|
-
}
|
|
313
|
-
export function __wbg_prototypesetcall_d62e5099504357e6(arg0, arg1, arg2) {
|
|
314
|
-
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
315
|
-
}
|
|
316
|
-
export function __wbg_randomFillSync_6c25eac9869eb53c() { return handleError(function (arg0, arg1) {
|
|
317
|
-
arg0.randomFillSync(arg1);
|
|
318
|
-
}, arguments); }
|
|
319
|
-
export function __wbg_require_b4edbdcf3e2a1ef0() { return handleError(function () {
|
|
320
|
-
const ret = module.require;
|
|
321
|
-
return ret;
|
|
322
|
-
}, arguments); }
|
|
323
|
-
export function __wbg_static_accessor_GLOBAL_8adb955bd33fac2f() {
|
|
324
|
-
const ret = typeof global === 'undefined' ? null : global;
|
|
325
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
326
|
-
}
|
|
327
|
-
export function __wbg_static_accessor_GLOBAL_THIS_ad356e0db91c7913() {
|
|
328
|
-
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
329
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
330
|
-
}
|
|
331
|
-
export function __wbg_static_accessor_SELF_f207c857566db248() {
|
|
332
|
-
const ret = typeof self === 'undefined' ? null : self;
|
|
333
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
334
|
-
}
|
|
335
|
-
export function __wbg_static_accessor_WINDOW_bb9f1ba69d61b386() {
|
|
336
|
-
const ret = typeof window === 'undefined' ? null : window;
|
|
337
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
338
|
-
}
|
|
339
|
-
export function __wbg_subarray_a068d24e39478a8a(arg0, arg1, arg2) {
|
|
340
|
-
const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
|
341
|
-
return ret;
|
|
342
|
-
}
|
|
343
|
-
export function __wbg_versions_276b2795b1c6a219(arg0) {
|
|
344
|
-
const ret = arg0.versions;
|
|
345
|
-
return ret;
|
|
346
|
-
}
|
|
347
|
-
export function __wbindgen_cast_0000000000000001(arg0, arg1) {
|
|
348
|
-
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
|
|
349
|
-
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
350
|
-
return ret;
|
|
351
|
-
}
|
|
352
|
-
export function __wbindgen_cast_0000000000000002(arg0, arg1) {
|
|
353
|
-
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
354
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
355
|
-
return ret;
|
|
356
|
-
}
|
|
357
526
|
export function __wbindgen_init_externref_table() {
|
|
358
527
|
const table = wasm.__wbindgen_externrefs;
|
|
359
528
|
const offset = table.grow(4);
|
|
@@ -366,6 +535,18 @@ export function __wbindgen_init_externref_table() {
|
|
|
366
535
|
const MlDsa65KeyPairFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
367
536
|
? { register: () => {}, unregister: () => {} }
|
|
368
537
|
: new FinalizationRegistry(ptr => wasm.__wbg_mldsa65keypair_free(ptr >>> 0, 1));
|
|
538
|
+
const MlDsa87KeyPairFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
539
|
+
? { register: () => {}, unregister: () => {} }
|
|
540
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_mldsa87keypair_free(ptr >>> 0, 1));
|
|
541
|
+
const MlKem1024DecapResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
542
|
+
? { register: () => {}, unregister: () => {} }
|
|
543
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_mlkem1024decapresult_free(ptr >>> 0, 1));
|
|
544
|
+
const MlKem1024EncapResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
545
|
+
? { register: () => {}, unregister: () => {} }
|
|
546
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_mlkem1024encapresult_free(ptr >>> 0, 1));
|
|
547
|
+
const MlKem1024KeyPairFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
548
|
+
? { register: () => {}, unregister: () => {} }
|
|
549
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_mlkem1024keypair_free(ptr >>> 0, 1));
|
|
369
550
|
const MlKem768DecapResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
370
551
|
? { register: () => {}, unregister: () => {} }
|
|
371
552
|
: new FinalizationRegistry(ptr => wasm.__wbg_mlkem768decapresult_free(ptr >>> 0, 1));
|
|
@@ -409,10 +590,6 @@ function handleError(f, args) {
|
|
|
409
590
|
}
|
|
410
591
|
}
|
|
411
592
|
|
|
412
|
-
function isLikeNone(x) {
|
|
413
|
-
return x === undefined || x === null;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
593
|
function passArray8ToWasm0(arg, malloc) {
|
|
417
594
|
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
418
595
|
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
Binary file
|
|
@@ -2,22 +2,39 @@
|
|
|
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
|
|
5
|
+
export const __wbg_mlkem1024decapresult_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_dsa_87_generate: () => number;
|
|
10
|
+
export const ml_dsa_87_sign: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
11
|
+
export const ml_dsa_87_verify: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
12
|
+
export const ml_kem_1024_decapsulate: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
13
|
+
export const ml_kem_1024_encapsulate: (a: number, b: number) => [number, number, number];
|
|
14
|
+
export const ml_kem_1024_generate: () => number;
|
|
9
15
|
export const ml_kem_768_decapsulate: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
10
16
|
export const ml_kem_768_encapsulate: (a: number, b: number) => [number, number, number];
|
|
11
17
|
export const ml_kem_768_generate: () => number;
|
|
12
18
|
export const mldsa65keypair_signing_key: (a: number) => [number, number];
|
|
13
19
|
export const mldsa65keypair_verifying_key: (a: number) => [number, number];
|
|
20
|
+
export const mlkem1024decapresult_shared_secret: (a: number) => [number, number];
|
|
14
21
|
export const mlkem768decapresult_shared_secret: (a: number) => [number, number];
|
|
15
|
-
export const
|
|
16
|
-
export const
|
|
22
|
+
export const __wbg_mldsa87keypair_free: (a: number, b: number) => void;
|
|
23
|
+
export const __wbg_mlkem1024encapresult_free: (a: number, b: number) => void;
|
|
24
|
+
export const __wbg_mlkem1024keypair_free: (a: number, b: number) => void;
|
|
25
|
+
export const __wbg_mlkem768encapresult_free: (a: number, b: number) => void;
|
|
17
26
|
export const __wbg_mlkem768keypair_free: (a: number, b: number) => void;
|
|
27
|
+
export const __wbg_mlkem768decapresult_free: (a: number, b: number) => void;
|
|
28
|
+
export const mlkem1024encapresult_shared_secret: (a: number) => [number, number];
|
|
29
|
+
export const mlkem1024encapresult_ciphertext: (a: number) => [number, number];
|
|
30
|
+
export const mlkem1024keypair_encapsulation_key: (a: number) => [number, number];
|
|
31
|
+
export const mlkem1024keypair_decapsulation_key: (a: number) => [number, number];
|
|
32
|
+
export const mldsa87keypair_verifying_key: (a: number) => [number, number];
|
|
33
|
+
export const mldsa87keypair_signing_key: (a: number) => [number, number];
|
|
18
34
|
export const mlkem768encapresult_shared_secret: (a: number) => [number, number];
|
|
19
35
|
export const mlkem768encapresult_ciphertext: (a: number) => [number, number];
|
|
20
|
-
export const
|
|
36
|
+
export const mlkem768keypair_encapsulation_key: (a: number) => [number, number];
|
|
37
|
+
export const mlkem768keypair_decapsulation_key: (a: number) => [number, number];
|
|
21
38
|
export const __wbindgen_export: (a: number) => void;
|
|
22
39
|
export const __wbindgen_export2: () => number;
|
|
23
40
|
export const __wbindgen_externrefs: WebAssembly.Table;
|
package/pkg-nodejs/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @stenvault/pqc-wasm
|
|
2
2
|
|
|
3
|
-
Post-quantum cryptography WASM wrapper for StenVault — ML-KEM-768 (FIPS 203) and ML-DSA-
|
|
3
|
+
Post-quantum cryptography WASM wrapper for StenVault — ML-KEM-768 and ML-KEM-1024 (FIPS 203), ML-DSA-65 and ML-DSA-87 (FIPS 204), compiled from RustCrypto crates to WebAssembly.
|
|
4
4
|
|
|
5
5
|
## Why
|
|
6
6
|
|
|
@@ -25,8 +25,8 @@ 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 and
|
|
29
|
-
npm run test:fips203-scan # every single-byte change of one public key, checked against noble
|
|
28
|
+
npm test # interop, FIPS 203 input checks, Wycheproof vectors and memory wiping, against the pkg-nodejs build
|
|
29
|
+
npm run test:fips203-scan # every single-byte change of one public key per ML-KEM parameter set, checked against noble
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
The FIPS 203 tests draw their samples from a seed that is printed in the output.
|
|
@@ -64,17 +64,41 @@ const signature = await sign(message, sigKp.secretKey)
|
|
|
64
64
|
const valid = await verify(message, signature, sigKp.publicKey)
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
+
Every parameter set is also an object with the same methods, so moving to
|
|
68
|
+
another security level means passing another object. The top-level functions
|
|
69
|
+
above are ML-KEM-768 and ML-DSA-65.
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { mlKem768, mlKem1024, mlDsa65, mlDsa87, type Kem, type SignatureScheme } from '@stenvault/pqc-wasm'
|
|
73
|
+
|
|
74
|
+
const kem: Kem = mlKem1024
|
|
75
|
+
const kp = await kem.generateKeyPair()
|
|
76
|
+
const { ciphertext, sharedSecret } = await kem.encapsulate(kp.publicKey)
|
|
77
|
+
const decrypted = await kem.decapsulate(ciphertext, kp.secretKey)
|
|
78
|
+
|
|
79
|
+
const dsa: SignatureScheme = mlDsa87
|
|
80
|
+
const sigKp = await dsa.generateKeyPair()
|
|
81
|
+
const signature = await dsa.sign(message, sigKp.secretKey)
|
|
82
|
+
const valid = await dsa.verify(message, signature, sigKp.publicKey)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
A key belongs to one parameter set: an ML-KEM-768 key passed to `mlKem1024`
|
|
86
|
+
fails its length check, and the same holds for ML-DSA.
|
|
87
|
+
|
|
67
88
|
### ML-KEM input errors
|
|
68
89
|
|
|
69
|
-
`encapsulate` and `decapsulate` reject (the promise throws) on malformed keys
|
|
90
|
+
`encapsulate` and `decapsulate` reject (the promise throws) on malformed keys.
|
|
91
|
+
The lengths are those of the parameter set (see Key sizes); the messages below
|
|
92
|
+
are ML-KEM-768's.
|
|
70
93
|
|
|
71
94
|
| Function | Message | Cause |
|
|
72
95
|
|----------|---------|-------|
|
|
73
96
|
| `encapsulate` | `invalid encapsulation key length: expected 1184 bytes` | wrong length |
|
|
74
|
-
| `encapsulate` | `encapsulation key is not canonical` | a 12-bit coefficient of
|
|
97
|
+
| `encapsulate` | `encapsulation key is not canonical` | a 12-bit coefficient of the public key, all but its last 32 bytes, is ≥ 3329 (FIPS 203 §7.2) |
|
|
75
98
|
| `decapsulate` | `invalid decapsulation key length: expected 2400 bytes` | wrong length |
|
|
76
99
|
| `decapsulate` | `invalid ciphertext length: expected 1088 bytes` | wrong length |
|
|
77
100
|
| `decapsulate` | `decapsulation key hash check failed` | SHA3-256 of the public key inside `secretKey` differs from the hash stored after it (FIPS 203 §7.3) |
|
|
101
|
+
| `decapsulate` | `decapsulation key embeds a non-canonical encapsulation key` | the hash matches, but a 12-bit coefficient of the public key inside `secretKey` is ≥ 3329 (the §7.2 check, applied to that key); key generation never produces such a key |
|
|
78
102
|
|
|
79
103
|
A corrupted ciphertext does not throw. `decapsulate` returns ML-KEM's
|
|
80
104
|
implicit-rejection secret, which does not match the sender's.
|
|
@@ -90,7 +114,7 @@ core.ts ← free() in try/finally, param order norma
|
|
|
90
114
|
↓
|
|
91
115
|
pkg-bundler/ or pkg-nodejs/ ← wasm-bindgen generated bindings
|
|
92
116
|
↓
|
|
93
|
-
src/lib.rs ←
|
|
117
|
+
src/lib.rs ← 12 exported Rust functions, memory wiped after each call
|
|
94
118
|
↓
|
|
95
119
|
ml-kem + ml-dsa (RustCrypto) ← FIPS 203/204 implementations
|
|
96
120
|
```
|
|
@@ -102,19 +126,23 @@ The consumer never calls `free()`, never calls `init()`, and never imports from
|
|
|
102
126
|
| Algorithm | Public Key | Secret Key | Ciphertext | Signature | Shared Secret |
|
|
103
127
|
|-----------|-----------|-----------|-----------|----------|--------------|
|
|
104
128
|
| ML-KEM-768 | 1,184 B | 2,400 B | 1,088 B | — | 32 B |
|
|
129
|
+
| ML-KEM-1024 | 1,568 B | 3,168 B | 1,568 B | — | 32 B |
|
|
105
130
|
| ML-DSA-65 | 1,952 B | 32 B (seed) | — | 3,309 B | — |
|
|
131
|
+
| ML-DSA-87 | 2,592 B | 32 B (seed) | — | 4,627 B | — |
|
|
106
132
|
|
|
107
133
|
## Security
|
|
108
134
|
|
|
109
135
|
- **Constant-time**: `subtle` crate in Rust, preserved through WASM compilation
|
|
110
|
-
- **Memory
|
|
111
|
-
- **FIPS 203 input checks**: `encapsulate` runs the §7.2 modulus check
|
|
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.
|
|
137
|
+
- **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.
|
|
112
138
|
- **No audit**: Neither RustCrypto nor this wrapper have been independently audited. RustCrypto is honest about this.
|
|
113
139
|
- **CVE-2026-22705**: Timing side-channel in `ml-dsa` Decompose function, patched in `>= 0.1.0-rc.3` (Barrett reduction).
|
|
114
140
|
- **CVE-2026-24850**: Signature malleability via duplicate hint indices in `ml-dsa`, patched in `>= 0.1.0-rc.4`.
|
|
115
141
|
- **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`.
|
|
116
142
|
- **RUSTSEC-2026-0385**: Non-constant-time mask generation and `u128` comparisons in `ctutils`, which `ml-dsa` uses for constant-time selection, patched in `ctutils >= 0.4.4` (this package: 0.3.1).
|
|
117
|
-
- Cargo.toml requires `ml-dsa >= 0.1.2`, the first release that pulls a patched `ctutils`.
|
|
143
|
+
- Cargo.toml requires `ml-dsa >= 0.1.2`, the first release that pulls a patched `ctutils`.
|
|
144
|
+
- Cargo.toml requires `ml-kem >= 0.3.4`, which removed a secret-indexed table lookup from noise sampling and made the conditional subtraction mod q constant-time.
|
|
145
|
+
- **Hedged signing**: `sign` uses FIPS 204's default, hedged variant: each signature mixes in 32 fresh bytes from `crypto.getRandomValues`, so two signatures of the same message differ. That keeps a fault or a side channel from being lined up across repeated signings. With those bytes pinned to zero it gives the deterministic variant, which the tests use to compare against known-answer vectors. If no randomness is available, `sign` throws instead of signing.
|
|
118
146
|
- **Supply chain**: `Cargo.lock` committed, CI runs `cargo audit` before every build.
|
|
119
147
|
|
|
120
148
|
## License
|
package/pkg-nodejs/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stenvault-pqc",
|
|
3
|
-
"description": "ML-KEM-768 + ML-DSA-65 WASM wrapper for StenVault",
|
|
4
|
-
"version": "0.
|
|
3
|
+
"description": "ML-KEM-768/1024 + ML-DSA-65/87 WASM wrapper for StenVault",
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"stenvault_pqc_bg.wasm",
|
|
@@ -18,6 +18,70 @@ export class MlDsa65KeyPair {
|
|
|
18
18
|
readonly verifying_key: Uint8Array;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* ML-DSA-87 key pair (verifying key + 32-byte signing seed).
|
|
23
|
+
*/
|
|
24
|
+
export class MlDsa87KeyPair {
|
|
25
|
+
private constructor();
|
|
26
|
+
free(): void;
|
|
27
|
+
[Symbol.dispose](): void;
|
|
28
|
+
/**
|
|
29
|
+
* Signing key as a 32-byte seed; expanded on demand during signing.
|
|
30
|
+
*/
|
|
31
|
+
readonly signing_key: Uint8Array;
|
|
32
|
+
/**
|
|
33
|
+
* Verifying (public) key, 2592 bytes.
|
|
34
|
+
*/
|
|
35
|
+
readonly verifying_key: Uint8Array;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Output of ML-KEM-1024 decapsulation: the recovered shared secret.
|
|
40
|
+
*/
|
|
41
|
+
export class MlKem1024DecapResult {
|
|
42
|
+
private constructor();
|
|
43
|
+
free(): void;
|
|
44
|
+
[Symbol.dispose](): void;
|
|
45
|
+
/**
|
|
46
|
+
* Shared secret recovered from the ciphertext, 32 bytes.
|
|
47
|
+
*/
|
|
48
|
+
readonly shared_secret: Uint8Array;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Output of ML-KEM-1024 encapsulation: ciphertext + shared secret.
|
|
53
|
+
*/
|
|
54
|
+
export class MlKem1024EncapResult {
|
|
55
|
+
private constructor();
|
|
56
|
+
free(): void;
|
|
57
|
+
[Symbol.dispose](): void;
|
|
58
|
+
/**
|
|
59
|
+
* Ciphertext to send to the decapsulator, 1568 bytes.
|
|
60
|
+
*/
|
|
61
|
+
readonly ciphertext: Uint8Array;
|
|
62
|
+
/**
|
|
63
|
+
* Shared secret derived from encapsulation, 32 bytes.
|
|
64
|
+
*/
|
|
65
|
+
readonly shared_secret: Uint8Array;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* ML-KEM-1024 key pair (encapsulation + decapsulation key).
|
|
70
|
+
*/
|
|
71
|
+
export class MlKem1024KeyPair {
|
|
72
|
+
private constructor();
|
|
73
|
+
free(): void;
|
|
74
|
+
[Symbol.dispose](): void;
|
|
75
|
+
/**
|
|
76
|
+
* Decapsulation (private) key, 3168 bytes.
|
|
77
|
+
*/
|
|
78
|
+
readonly decapsulation_key: Uint8Array;
|
|
79
|
+
/**
|
|
80
|
+
* Encapsulation (public) key, 1568 bytes.
|
|
81
|
+
*/
|
|
82
|
+
readonly encapsulation_key: Uint8Array;
|
|
83
|
+
}
|
|
84
|
+
|
|
21
85
|
/**
|
|
22
86
|
* Output of ML-KEM-768 decapsulation: the recovered shared secret.
|
|
23
87
|
*/
|
|
@@ -80,6 +144,36 @@ export function ml_dsa_65_sign(sk_bytes: Uint8Array, message: Uint8Array): Uint8
|
|
|
80
144
|
*/
|
|
81
145
|
export function ml_dsa_65_verify(vk_bytes: Uint8Array, message: Uint8Array, signature: Uint8Array): boolean;
|
|
82
146
|
|
|
147
|
+
/**
|
|
148
|
+
* Generate a fresh ML-DSA-87 key pair from 32 random seed bytes.
|
|
149
|
+
*/
|
|
150
|
+
export function ml_dsa_87_generate(): MlDsa87KeyPair;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Sign `message` with a 32-byte ML-DSA-87 seed, returning a 4627-byte signature.
|
|
154
|
+
*/
|
|
155
|
+
export function ml_dsa_87_sign(sk_bytes: Uint8Array, message: Uint8Array): Uint8Array;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Verify a 4627-byte ML-DSA-87 signature over `message` against a 2592-byte verifying key.
|
|
159
|
+
*/
|
|
160
|
+
export function ml_dsa_87_verify(vk_bytes: Uint8Array, message: Uint8Array, signature: Uint8Array): boolean;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Decapsulate a 1568-byte ciphertext with a 3168-byte decapsulation key.
|
|
164
|
+
*/
|
|
165
|
+
export function ml_kem_1024_decapsulate(dk_bytes: Uint8Array, ct_bytes: Uint8Array): MlKem1024DecapResult;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Encapsulate a fresh shared secret to a 1568-byte encapsulation key.
|
|
169
|
+
*/
|
|
170
|
+
export function ml_kem_1024_encapsulate(ek_bytes: Uint8Array): MlKem1024EncapResult;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Generate a fresh ML-KEM-1024 key pair using OS randomness.
|
|
174
|
+
*/
|
|
175
|
+
export function ml_kem_1024_generate(): MlKem1024KeyPair;
|
|
176
|
+
|
|
83
177
|
/**
|
|
84
178
|
* Decapsulate a 1088-byte ciphertext with a 2400-byte decapsulation key.
|
|
85
179
|
*/
|