@theqrl/dilithium5 1.2.1 → 1.2.3

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.
@@ -44,11 +44,13 @@ export const zetas: readonly number[];
44
44
  * @param seed - Optional 32-byte seed for deterministic key generation (null for random)
45
45
  * @param pk - Output buffer for public key (must be CryptoPublicKeyBytes length)
46
46
  * @param sk - Output buffer for secret key (must be CryptoSecretKeyBytes length)
47
- * @returns The seed used for key generation
47
+ * @returns The seed used for key generation. **Secret-key-equivalent**: anyone
48
+ * holding it can regenerate the full keypair — store it with the same care
49
+ * as `sk` and `zeroize()` it when no longer needed.
48
50
  * @throws Error if pk/sk buffers are wrong size or null
49
51
  */
50
52
  export function cryptoSignKeypair(
51
- seed: Uint8Array | null,
53
+ seed: Uint8Array | null | undefined,
52
54
  pk: Uint8Array,
53
55
  sk: Uint8Array
54
56
  ): Uint8Array;
@@ -182,43 +184,73 @@ export function zeroize(buffer: Uint8Array): void;
182
184
  */
183
185
  export function isZero(buffer: Uint8Array): boolean;
184
186
 
187
+ /**
188
+ * Zero the coefficient arrays of a polynomial vector (best-effort, see
189
+ * SECURITY.md). Centralizes the secret-wiping pattern used by signing paths.
190
+ *
191
+ * @deprecated Internal API — its parameter types (`PolyVecK`/`PolyVecL`) are
192
+ * themselves internal and cannot be constructed through the documented
193
+ * surface, so this is a stable function over deprecated types. Not part of
194
+ * the stable documented API; will move behind a subpath or be removed at the
195
+ * next major version. See CONTRIBUTING.md "Public API surface policy".
196
+ */
197
+ export function zeroizePolyVec(polyVec: PolyVecK | PolyVecL): void;
198
+
185
199
  // Internal classes (exported but primarily for internal use)
186
200
 
201
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
187
202
  export class Poly {
188
203
  coeffs: Int32Array;
189
204
  constructor();
190
205
  copy(poly: Poly): void;
191
206
  }
192
207
 
208
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
193
209
  export class PolyVecK {
194
210
  vec: Poly[];
195
211
  constructor();
196
212
  }
197
213
 
214
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
198
215
  export class PolyVecL {
199
216
  vec: Poly[];
200
217
  constructor();
201
218
  copy(polyVecL: PolyVecL): void;
202
219
  }
203
220
 
221
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
204
222
  export class KeccakState {
205
223
  constructor();
206
224
  }
207
225
 
208
226
  // Internal functions (exported but primarily for internal use)
227
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
209
228
  export function polyNTT(a: Poly): void;
229
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
210
230
  export function polyInvNTTToMont(a: Poly): void;
231
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
211
232
  export function polyChallenge(c: Poly, seed: Uint8Array): void;
233
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
212
234
  export function ntt(a: Int32Array): void;
235
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
213
236
  export function invNTTToMont(a: Int32Array): void;
237
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
214
238
  export function montgomeryReduce(a: bigint): bigint;
239
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
215
240
  export function reduce32(a: number): number;
241
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
216
242
  export function cAddQ(a: number): number;
243
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
217
244
  export function decompose(a0: Int32Array, i: number, a: number): number;
245
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
218
246
  export function power2round(a0: Int32Array, i: number, a: number): number;
247
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
219
248
  export function makeHint(a0: number, a1: number): number;
249
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
220
250
  export function useHint(a: number, hint: number): number;
251
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
221
252
  export function packPk(pk: Uint8Array, rho: Uint8Array, t1: PolyVecK): void;
253
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
222
254
  export function packSk(
223
255
  sk: Uint8Array,
224
256
  rho: Uint8Array,
@@ -228,13 +260,16 @@ export function packSk(
228
260
  s1: PolyVecL,
229
261
  s2: PolyVecK
230
262
  ): void;
263
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
231
264
  export function packSig(
232
265
  sig: Uint8Array,
233
266
  c: Uint8Array,
234
267
  z: PolyVecL,
235
268
  h: PolyVecK
236
269
  ): void;
270
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
237
271
  export function unpackPk(rho: Uint8Array, t1: PolyVecK, pk: Uint8Array): void;
272
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
238
273
  export function unpackSk(
239
274
  rho: Uint8Array,
240
275
  tr: Uint8Array,
@@ -244,6 +279,7 @@ export function unpackSk(
244
279
  s2: PolyVecK,
245
280
  sk: Uint8Array
246
281
  ): void;
282
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
247
283
  export function unpackSig(
248
284
  c: Uint8Array,
249
285
  z: PolyVecL,
@@ -252,18 +288,26 @@ export function unpackSig(
252
288
  ): number;
253
289
 
254
290
  // FIPS 202 SHAKE primitives (low-level XOF interface, primarily internal)
291
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
255
292
  export function shake128Init(state: KeccakState): void;
293
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
256
294
  export function shake128Absorb(state: KeccakState, input: Uint8Array): void;
295
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
257
296
  export function shake128Finalize(state: KeccakState): void;
297
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
258
298
  export function shake128SqueezeBlocks(
259
299
  out: Uint8Array,
260
300
  outputOffset: number,
261
301
  nBlocks: number,
262
302
  state: KeccakState
263
303
  ): void;
304
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
264
305
  export function shake256Init(state: KeccakState): void;
306
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
265
307
  export function shake256Absorb(state: KeccakState, input: Uint8Array): void;
308
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
266
309
  export function shake256Finalize(state: KeccakState): void;
310
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
267
311
  export function shake256SqueezeBlocks(
268
312
  out: Uint8Array,
269
313
  outputOffset: number,
@@ -272,11 +316,13 @@ export function shake256SqueezeBlocks(
272
316
  ): void;
273
317
 
274
318
  // Dilithium-specific stream initializers
319
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
275
320
  export function dilithiumShake128StreamInit(
276
321
  state: KeccakState,
277
322
  seed: Uint8Array,
278
323
  nonce: number
279
324
  ): void;
325
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
280
326
  export function dilithiumShake256StreamInit(
281
327
  state: KeccakState,
282
328
  seed: Uint8Array,
@@ -284,17 +330,29 @@ export function dilithiumShake256StreamInit(
284
330
  ): void;
285
331
 
286
332
  // Polynomial operations (internal)
333
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
287
334
  export function polyReduce(a: Poly): void;
335
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
288
336
  export function polyCAddQ(a: Poly): void;
337
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
289
338
  export function polyAdd(c: Poly, a: Poly, b: Poly): void;
339
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
290
340
  export function polySub(c: Poly, a: Poly, b: Poly): void;
341
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
291
342
  export function polyShiftL(a: Poly): void;
343
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
292
344
  export function polyPointWiseMontgomery(c: Poly, a: Poly, b: Poly): void;
345
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
293
346
  export function polyPower2round(a1: Poly, a0: Poly, a: Poly): void;
347
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
294
348
  export function polyDecompose(a1: Poly, a0: Poly, a: Poly): void;
349
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
295
350
  export function polyMakeHint(h: Poly, a0: Poly, a1: Poly): number;
351
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
296
352
  export function polyUseHint(b: Poly, a: Poly, h: Poly): void;
353
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
297
354
  export function polyChkNorm(a: Poly, b: number): number;
355
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
298
356
  export function rejUniform(
299
357
  a: Int32Array,
300
358
  aOffset: number,
@@ -302,7 +360,9 @@ export function rejUniform(
302
360
  buf: Uint8Array,
303
361
  bufLen: number
304
362
  ): number;
363
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
305
364
  export function polyUniform(a: Poly, seed: Uint8Array, nonce: number): void;
365
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
306
366
  export function rejEta(
307
367
  a: Int32Array,
308
368
  aOffset: number,
@@ -310,58 +370,95 @@ export function rejEta(
310
370
  buf: Uint8Array,
311
371
  bufLen: number
312
372
  ): number;
373
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
313
374
  export function polyUniformEta(a: Poly, seed: Uint8Array, nonce: number): void;
375
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
314
376
  export function polyZUnpack(r: Poly, a: Uint8Array, aOffset: number): void;
377
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
315
378
  export function polyUniformGamma1(a: Poly, seed: Uint8Array, nonce: number): void;
379
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
316
380
  export function polyEtaPack(r: Uint8Array, rOffset: number, a: Poly): void;
381
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
317
382
  export function polyEtaUnpack(r: Poly, a: Uint8Array, aOffset: number): void;
383
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
318
384
  export function polyT1Pack(r: Uint8Array, rOffset: number, a: Poly): void;
385
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
319
386
  export function polyT1Unpack(r: Poly, a: Uint8Array, aOffset: number): void;
387
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
320
388
  export function polyT0Pack(r: Uint8Array, rOffset: number, a: Poly): void;
389
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
321
390
  export function polyT0Unpack(r: Poly, a: Uint8Array, aOffset: number): void;
391
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
322
392
  export function polyZPack(r: Uint8Array, rOffset: number, a: Poly): void;
393
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
323
394
  export function polyW1Pack(r: Uint8Array, rOffset: number, a: Poly): void;
324
395
 
325
396
  // Polynomial vector operations (internal)
397
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
326
398
  export function polyVecMatrixExpand(mat: PolyVecL[], rho: Uint8Array): void;
399
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
327
400
  export function polyVecMatrixPointWiseMontgomery(
328
401
  t: PolyVecK,
329
402
  mat: PolyVecL[],
330
403
  v: PolyVecL
331
404
  ): void;
405
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
332
406
  export function polyVecLUniformEta(v: PolyVecL, seed: Uint8Array, nonce: number): void;
407
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
333
408
  export function polyVecLUniformGamma1(v: PolyVecL, seed: Uint8Array, nonce: number): void;
409
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
334
410
  export function polyVecLReduce(v: PolyVecL): void;
411
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
335
412
  export function polyVecLAdd(w: PolyVecL, u: PolyVecL, v: PolyVecL): void;
413
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
336
414
  export function polyVecLNTT(v: PolyVecL): void;
415
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
337
416
  export function polyVecLInvNTTToMont(v: PolyVecL): void;
417
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
338
418
  export function polyVecLPointWisePolyMontgomery(
339
419
  r: PolyVecL,
340
420
  a: Poly,
341
421
  v: PolyVecL
342
422
  ): void;
423
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
343
424
  export function polyVecLPointWiseAccMontgomery(
344
425
  w: Poly,
345
426
  u: PolyVecL,
346
427
  v: PolyVecL
347
428
  ): void;
429
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
348
430
  export function polyVecLChkNorm(v: PolyVecL, bound: number): number;
431
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
349
432
  export function polyVecKUniformEta(v: PolyVecK, seed: Uint8Array, nonce: number): void;
433
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
350
434
  export function polyVecKReduce(v: PolyVecK): void;
435
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
351
436
  export function polyVecKCAddQ(v: PolyVecK): void;
437
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
352
438
  export function polyVecKAdd(w: PolyVecK, u: PolyVecK, v: PolyVecK): void;
439
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
353
440
  export function polyVecKSub(w: PolyVecK, u: PolyVecK, v: PolyVecK): void;
441
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
354
442
  export function polyVecKShiftL(v: PolyVecK): void;
443
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
355
444
  export function polyVecKNTT(v: PolyVecK): void;
445
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
356
446
  export function polyVecKInvNTTToMont(v: PolyVecK): void;
447
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
357
448
  export function polyVecKPointWisePolyMontgomery(
358
449
  r: PolyVecK,
359
450
  a: Poly,
360
451
  v: PolyVecK
361
452
  ): void;
453
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
362
454
  export function polyVecKChkNorm(v: PolyVecK, bound: number): number;
455
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
363
456
  export function polyVecKPower2round(v1: PolyVecK, v0: PolyVecK, v: PolyVecK): void;
457
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
364
458
  export function polyVecKDecompose(v1: PolyVecK, v0: PolyVecK, v: PolyVecK): void;
459
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
365
460
  export function polyVecKMakeHint(h: PolyVecK, v0: PolyVecK, v1: PolyVecK): number;
461
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
366
462
  export function polyVecKUseHint(w: PolyVecK, u: PolyVecK, h: PolyVecK): void;
463
+ /** @deprecated Internal API — not part of the stable documented surface; will move behind a subpath or be removed at the next major version. See CONTRIBUTING.md "Public API surface policy". */
367
464
  export function polyVecKPackW1(r: Uint8Array, w1: PolyVecK): void;
@@ -76,7 +76,6 @@ const zetas = [
76
76
  class KeccakState {
77
77
  constructor() {
78
78
  this.hasher = null;
79
- this.finalized = false;
80
79
  }
81
80
  }
82
81
 
@@ -84,17 +83,18 @@ class KeccakState {
84
83
 
85
84
  function shake128Init(state) {
86
85
  state.hasher = shake128.create({});
87
- state.finalized = false;
88
86
  }
89
87
 
90
88
  function shake128Absorb(state, input) {
91
89
  state.hasher.update(input);
92
90
  }
93
91
 
94
- function shake128Finalize(state) {
95
- // Mark as finalized - actual finalization happens on first xofInto call
96
- state.finalized = true;
97
- }
92
+ /**
93
+ * No-op retained for API parity with the C reference's absorb/finalize/squeeze
94
+ * flow: @noble/hashes finalizes the sponge automatically on the first
95
+ * xofInto() call, so there is no separate finalize step to perform.
96
+ */
97
+ function shake128Finalize() {}
98
98
 
99
99
  function shake128SqueezeBlocks(out, outputOffset, nBlocks, state) {
100
100
  const len = nBlocks * Shake128Rate;
@@ -106,17 +106,18 @@ function shake128SqueezeBlocks(out, outputOffset, nBlocks, state) {
106
106
 
107
107
  function shake256Init(state) {
108
108
  state.hasher = shake256.create({});
109
- state.finalized = false;
110
109
  }
111
110
 
112
111
  function shake256Absorb(state, input) {
113
112
  state.hasher.update(input);
114
113
  }
115
114
 
116
- function shake256Finalize(state) {
117
- // Mark as finalized - actual finalization happens on first xofInto call
118
- state.finalized = true;
119
- }
115
+ /**
116
+ * No-op retained for API parity with the C reference's absorb/finalize/squeeze
117
+ * flow: @noble/hashes finalizes the sponge automatically on the first
118
+ * xofInto() call, so there is no separate finalize step to perform.
119
+ */
120
+ function shake256Finalize() {}
120
121
 
121
122
  function shake256SqueezeBlocks(out, outputOffset, nBlocks, state) {
122
123
  const len = nBlocks * Shake256Rate;
@@ -135,7 +136,6 @@ function dilithiumShake128StreamInit(state, seed, nonce) {
135
136
  shake128Init(state);
136
137
  shake128Absorb(state, seed);
137
138
  shake128Absorb(state, t);
138
- shake128Finalize(state);
139
139
  }
140
140
 
141
141
  function dilithiumShake256StreamInit(state, seed, nonce) {
@@ -149,7 +149,6 @@ function dilithiumShake256StreamInit(state, seed, nonce) {
149
149
  shake256Init(state);
150
150
  shake256Absorb(state, seed);
151
151
  shake256Absorb(state, t);
152
- shake256Finalize(state);
153
152
  }
154
153
 
155
154
  function montgomeryReduce(a) {
@@ -448,6 +447,8 @@ function polyUniformGamma1(a, seed, nonce) {
448
447
  }
449
448
 
450
449
  function polyChallenge(cP, seed) {
450
+ // Invariant tripwire: internal callers always pass a SeedBytes-long
451
+ // challenge hash; anything else indicates a regression in sign/verify.
451
452
  if (seed.length !== SeedBytes) throw new Error('invalid seed length');
452
453
 
453
454
  let b;
@@ -458,7 +459,6 @@ function polyChallenge(cP, seed) {
458
459
  const state = new KeccakState();
459
460
  shake256Init(state);
460
461
  shake256Absorb(state, seed);
461
- shake256Finalize(state);
462
462
  shake256SqueezeBlocks(buf, 0, 1, state);
463
463
 
464
464
  let signs = 0n;
@@ -765,6 +765,9 @@ function polyVecLChkNorm(v, bound) {
765
765
 
766
766
  function polyVecKUniformEta(v, seed, nonceP) {
767
767
  let nonce = nonceP;
768
+ if (seed.length !== CRHBytes) {
769
+ throw new Error(`invalid seed length ${seed.length} | Expected length ${CRHBytes}`);
770
+ }
768
771
  for (let i = 0; i < K; ++i) {
769
772
  polyUniformEta(v.vec[i], seed, nonce++);
770
773
  }
@@ -971,6 +974,10 @@ function packSig(sigP, c, z, h) {
971
974
  sig[sigOffset + i] = 0;
972
975
  }
973
976
 
977
+ // Invariant tripwires: h produced by polyVecKMakeHint is always binary
978
+ // with at most OMEGA set coefficients (the sign loop re-samples
979
+ // otherwise). A violation here means an internal regression upstream —
980
+ // fail loudly rather than emit a malformed signature.
974
981
  let k = 0;
975
982
  for (let i = 0; i < K; ++i) {
976
983
  for (let j = 0; j < N; ++j) {
@@ -1064,6 +1071,9 @@ function randomBytes(size) {
1064
1071
  cryptoObj.getRandomValues(out.subarray(i, Math.min(size, i + MAX_BYTES)));
1065
1072
  }
1066
1073
  if (size >= 16) {
1074
+ // Invariant tripwire: a healthy CSPRNG never returns 16 leading zero
1075
+ // bytes (p = 2^-128). All-zero output means the platform RNG is
1076
+ // catastrophically broken — refuse to hand it to key generation.
1067
1077
  let acc = 0;
1068
1078
  for (let i = 0; i < 16; i++) acc |= out[i];
1069
1079
  if (acc === 0) throw new Error('getRandomValues returned all zeros');
@@ -1112,6 +1122,22 @@ function zeroize(buffer) {
1112
1122
  }
1113
1123
  }
1114
1124
 
1125
+ /**
1126
+ * Attempts to zero the coefficient arrays of a polynomial vector
1127
+ * (PolyVecL/PolyVecK). Centralizes the secret-wiping pattern used by the
1128
+ * signing paths so every sensitive PolyVec is cleared the same way.
1129
+ *
1130
+ * Same BEST-EFFORT caveats as zeroize() — see SECURITY.md.
1131
+ *
1132
+ * @param {{vec: {coeffs: Int32Array}[]}} polyVec - The polynomial vector to zero
1133
+ * @returns {void}
1134
+ */
1135
+ function zeroizePolyVec(polyVec) {
1136
+ for (let i = 0; i < polyVec.vec.length; i++) {
1137
+ polyVec.vec[i].coeffs.fill(0);
1138
+ }
1139
+ }
1140
+
1115
1141
  /**
1116
1142
  * Checks if a buffer is all zeros.
1117
1143
  * Uses constant-time comparison to avoid timing leaks.
@@ -1143,6 +1169,8 @@ function isZero(buffer) {
1143
1169
  * @private
1144
1170
  */
1145
1171
  function hexToBytes(hex) {
1172
+ // Unreachable via the public API: messageToBytes routes only strings here.
1173
+ // Kept as defense-in-depth for any future direct internal caller.
1146
1174
  /* c8 ignore start */
1147
1175
  if (typeof hex !== 'string') {
1148
1176
  throw new Error('message must be a hex string');
@@ -1192,13 +1220,18 @@ function messageToBytes(message) {
1192
1220
  * Pass null or undefined for random key generation.
1193
1221
  * @param {Uint8Array} pk - Output buffer for public key (must be CryptoPublicKeyBytes = 2592 bytes)
1194
1222
  * @param {Uint8Array} sk - Output buffer for secret key (must be CryptoSecretKeyBytes = 4896 bytes)
1195
- * @returns {Uint8Array} The seed used for key generation (useful when passedSeed is null)
1223
+ * @returns {Uint8Array} The seed used for key generation (useful when passedSeed is null).
1224
+ * **The returned seed is secret-key-equivalent**: anyone holding it can
1225
+ * regenerate the full keypair. Store it with the same care as `sk` and
1226
+ * `zeroize()` it as soon as it is no longer needed.
1196
1227
  * @throws {Error} If pk/sk buffers are null or wrong size, or if seed is wrong size
1197
1228
  *
1198
1229
  * @example
1199
1230
  * const pk = new Uint8Array(CryptoPublicKeyBytes);
1200
1231
  * const sk = new Uint8Array(CryptoSecretKeyBytes);
1201
1232
  * const seed = cryptoSignKeypair(null, pk, sk);
1233
+ * // ... persist or use seed (it can regenerate sk!) ...
1234
+ * zeroize(seed);
1202
1235
  */
1203
1236
  function cryptoSignKeypair(passedSeed, pk, sk) {
1204
1237
  try {
@@ -1272,10 +1305,10 @@ function cryptoSignKeypair(passedSeed, pk, sk) {
1272
1305
  zeroize(seedBuf);
1273
1306
  zeroize(rhoPrime);
1274
1307
  zeroize(key);
1275
- for (let i = 0; i < L; i++) s1.vec[i].coeffs.fill(0);
1276
- for (let i = 0; i < K; i++) s2.vec[i].coeffs.fill(0);
1277
- if (s1hat) for (let i = 0; i < L; i++) s1hat.vec[i].coeffs.fill(0);
1278
- for (let i = 0; i < K; i++) t0.vec[i].coeffs.fill(0);
1308
+ zeroizePolyVec(s1);
1309
+ zeroizePolyVec(s2);
1310
+ if (s1hat) zeroizePolyVec(s1hat);
1311
+ zeroizePolyVec(t0);
1279
1312
  }
1280
1313
  }
1281
1314
 
@@ -1340,7 +1373,10 @@ function cryptoSignSignature(sig, m, sk, randomizedSigning) {
1340
1373
  const mu = shake256.create({}).update(tr).update(mBytes).xof(CRHBytes);
1341
1374
 
1342
1375
  if (randomizedSigning) {
1343
- rhoPrime = new Uint8Array(randomBytes(CRHBytes));
1376
+ // randomBytes already returns a fresh Uint8Array; assign it directly so
1377
+ // no unwiped intermediate copy is left behind (rhoPrime is zeroized in
1378
+ // the finally block).
1379
+ rhoPrime = randomBytes(CRHBytes);
1344
1380
  } else {
1345
1381
  rhoPrime = shake256.create({}).update(key).update(mu).xof(CRHBytes);
1346
1382
  }
@@ -1367,7 +1403,7 @@ function cryptoSignSignature(sig, m, sk, randomizedSigning) {
1367
1403
  const cHash = shake256
1368
1404
  .create({})
1369
1405
  .update(mu)
1370
- .update(sig.slice(0, K * PolyW1PackedBytes))
1406
+ .update(sig.subarray(0, K * PolyW1PackedBytes))
1371
1407
  .xof(SeedBytes);
1372
1408
  sig.set(cHash);
1373
1409
 
@@ -1394,6 +1430,9 @@ function cryptoSignSignature(sig, m, sk, randomizedSigning) {
1394
1430
  polyVecKPointWisePolyMontgomery(h, cp, t0);
1395
1431
  polyVecKInvNTTToMont(h);
1396
1432
  polyVecKReduce(h);
1433
+ // Statistically rare rejection (depends on key/challenge interaction);
1434
+ // no deterministic trigger is known, so it is exercised by long fuzz
1435
+ // campaigns rather than unit vectors.
1397
1436
  /* c8 ignore start */
1398
1437
  if (polyVecKChkNorm(h, GAMMA2) !== 0) {
1399
1438
  continue;
@@ -1402,6 +1441,7 @@ function cryptoSignSignature(sig, m, sk, randomizedSigning) {
1402
1441
 
1403
1442
  polyVecKAdd(w0, w0, h);
1404
1443
  const n = polyVecKMakeHint(h, w0, w1);
1444
+ // Statistically rare rejection — same rationale as the ct0 check above.
1405
1445
  /* c8 ignore start */
1406
1446
  if (n > OMEGA) {
1407
1447
  continue;
@@ -1414,10 +1454,10 @@ function cryptoSignSignature(sig, m, sk, randomizedSigning) {
1414
1454
  } finally {
1415
1455
  zeroize(key);
1416
1456
  zeroize(rhoPrime);
1417
- for (let i = 0; i < L; i++) s1.vec[i].coeffs.fill(0);
1418
- for (let i = 0; i < K; i++) s2.vec[i].coeffs.fill(0);
1419
- for (let i = 0; i < K; i++) t0.vec[i].coeffs.fill(0);
1420
- for (let i = 0; i < L; i++) y.vec[i].coeffs.fill(0);
1457
+ zeroizePolyVec(s1);
1458
+ zeroizePolyVec(s2);
1459
+ zeroizePolyVec(t0);
1460
+ zeroizePolyVec(y);
1421
1461
  }
1422
1462
  }
1423
1463
 
@@ -1466,13 +1506,14 @@ function cryptoSignSignatureDeterministic(sig, m, sk) {
1466
1506
  function cryptoSign(msg, sk, randomizedSigning) {
1467
1507
  const msgBytes = messageToBytes(msg);
1468
1508
 
1509
+ // Place the message after the signature area. (The C reference uses a
1510
+ // backwards copy because its sm/m buffers may alias; here they never do.)
1469
1511
  const sm = new Uint8Array(CryptoBytes + msgBytes.length);
1470
- const mLen = msgBytes.length;
1471
- for (let i = 0; i < mLen; ++i) {
1472
- sm[CryptoBytes + mLen - 1 - i] = msgBytes[mLen - 1 - i];
1473
- }
1512
+ sm.set(msgBytes, CryptoBytes);
1474
1513
  const result = cryptoSignSignature(sm, msgBytes, sk, randomizedSigning);
1475
1514
 
1515
+ // Unreachable: cryptoSignSignature returns 0 or throws — defensive
1516
+ // tripwire in case a future change introduces a non-zero failure return.
1476
1517
  /* c8 ignore start */
1477
1518
  if (result !== 0) {
1478
1519
  throw new Error('failed to sign');
@@ -1656,4 +1697,4 @@ function cryptoSignOpenWithReason(sm, pk) {
1656
1697
  return { ok: true, message: msg };
1657
1698
  }
1658
1699
 
1659
- export { BETA, CRHBytes, CryptoBytes, CryptoPublicKeyBytes, CryptoSecretKeyBytes, D, ETA, GAMMA1, GAMMA2, K, KeccakState, L, N, OMEGA, Poly, PolyETAPackedBytes, PolyT0PackedBytes, PolyT1PackedBytes, PolyUniformETANBlocks, PolyUniformGamma1NBlocks, PolyUniformNBlocks, PolyVecHPackedBytes, PolyVecK, PolyVecL, PolyW1PackedBytes, PolyZPackedBytes, Q, QInv, SeedBytes, Shake128Rate, Shake256Rate, Stream128BlockBytes, Stream256BlockBytes, TAU, TRBytes, cAddQ, cryptoSign, cryptoSignDeterministic, cryptoSignKeypair, cryptoSignOpen, cryptoSignOpenWithReason, cryptoSignSignature, cryptoSignSignatureDeterministic, cryptoSignVerify, decompose, dilithiumShake128StreamInit, dilithiumShake256StreamInit, invNTTToMont, isZero, makeHint, montgomeryReduce, ntt, packPk, packSig, packSk, polyAdd, polyCAddQ, polyChallenge, polyChkNorm, polyDecompose, polyEtaPack, polyEtaUnpack, polyInvNTTToMont, polyMakeHint, polyNTT, polyPointWiseMontgomery, polyPower2round, polyReduce, polyShiftL, polySub, polyT0Pack, polyT0Unpack, polyT1Pack, polyT1Unpack, polyUniform, polyUniformEta, polyUniformGamma1, polyUseHint, polyVecKAdd, polyVecKCAddQ, polyVecKChkNorm, polyVecKDecompose, polyVecKInvNTTToMont, polyVecKMakeHint, polyVecKNTT, polyVecKPackW1, polyVecKPointWisePolyMontgomery, polyVecKPower2round, polyVecKReduce, polyVecKShiftL, polyVecKSub, polyVecKUniformEta, polyVecKUseHint, polyVecLAdd, polyVecLChkNorm, polyVecLInvNTTToMont, polyVecLNTT, polyVecLPointWiseAccMontgomery, polyVecLPointWisePolyMontgomery, polyVecLReduce, polyVecLUniformEta, polyVecLUniformGamma1, polyVecMatrixExpand, polyVecMatrixPointWiseMontgomery, polyW1Pack, polyZPack, polyZUnpack, power2round, reduce32, rejEta, rejUniform, shake128Absorb, shake128Finalize, shake128Init, shake128SqueezeBlocks, shake256Absorb, shake256Finalize, shake256Init, shake256SqueezeBlocks, unpackPk, unpackSig, unpackSk, useHint, zeroize, zetas };
1700
+ export { BETA, CRHBytes, CryptoBytes, CryptoPublicKeyBytes, CryptoSecretKeyBytes, D, ETA, GAMMA1, GAMMA2, K, KeccakState, L, N, OMEGA, Poly, PolyETAPackedBytes, PolyT0PackedBytes, PolyT1PackedBytes, PolyUniformETANBlocks, PolyUniformGamma1NBlocks, PolyUniformNBlocks, PolyVecHPackedBytes, PolyVecK, PolyVecL, PolyW1PackedBytes, PolyZPackedBytes, Q, QInv, SeedBytes, Shake128Rate, Shake256Rate, Stream128BlockBytes, Stream256BlockBytes, TAU, TRBytes, cAddQ, cryptoSign, cryptoSignDeterministic, cryptoSignKeypair, cryptoSignOpen, cryptoSignOpenWithReason, cryptoSignSignature, cryptoSignSignatureDeterministic, cryptoSignVerify, decompose, dilithiumShake128StreamInit, dilithiumShake256StreamInit, invNTTToMont, isZero, makeHint, montgomeryReduce, ntt, packPk, packSig, packSk, polyAdd, polyCAddQ, polyChallenge, polyChkNorm, polyDecompose, polyEtaPack, polyEtaUnpack, polyInvNTTToMont, polyMakeHint, polyNTT, polyPointWiseMontgomery, polyPower2round, polyReduce, polyShiftL, polySub, polyT0Pack, polyT0Unpack, polyT1Pack, polyT1Unpack, polyUniform, polyUniformEta, polyUniformGamma1, polyUseHint, polyVecKAdd, polyVecKCAddQ, polyVecKChkNorm, polyVecKDecompose, polyVecKInvNTTToMont, polyVecKMakeHint, polyVecKNTT, polyVecKPackW1, polyVecKPointWisePolyMontgomery, polyVecKPower2round, polyVecKReduce, polyVecKShiftL, polyVecKSub, polyVecKUniformEta, polyVecKUseHint, polyVecLAdd, polyVecLChkNorm, polyVecLInvNTTToMont, polyVecLNTT, polyVecLPointWiseAccMontgomery, polyVecLPointWisePolyMontgomery, polyVecLReduce, polyVecLUniformEta, polyVecLUniformGamma1, polyVecMatrixExpand, polyVecMatrixPointWiseMontgomery, polyW1Pack, polyZPack, polyZUnpack, power2round, reduce32, rejEta, rejUniform, shake128Absorb, shake128Finalize, shake128Init, shake128SqueezeBlocks, shake256Absorb, shake256Finalize, shake256Init, shake256SqueezeBlocks, unpackPk, unpackSig, unpackSk, useHint, zeroize, zeroizePolyVec, zetas };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theqrl/dilithium5",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "Dilithium-5 cryptography",
5
5
  "keywords": [
6
6
  "dilithium",
@@ -34,8 +34,6 @@
34
34
  "test": "../../node_modules/mocha/bin/mocha.js --require ../../scripts/node-test-setup.cjs --timeout 10000",
35
35
  "test:browser": "playwright test",
36
36
  "build": "rollup -c && ./fixup",
37
- "lint-check": "eslint 'src/**/*.js' 'test/**/*.js'",
38
- "lint": "eslint --fix 'src/**/*.js' 'test/**/*.js'",
39
37
  "coverage": "c8 npm run test",
40
38
  "report-coverage": "c8 --reporter=text-lcov npm run test > coverage.lcov"
41
39
  },
@@ -73,7 +71,7 @@
73
71
  "prettier": "3.8.3",
74
72
  "rollup": "4.60.3",
75
73
  "serialize-javascript": "7.0.5",
76
- "tar": "7.5.14"
74
+ "tar": "7.5.15"
77
75
  },
78
76
  "dependencies": {
79
77
  "@noble/hashes": "2.2.0"