@theqrl/dilithium5 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,7 +44,9 @@ 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(
@@ -182,43 +184,67 @@ 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
+ export function zeroizePolyVec(polyVec: PolyVecK | PolyVecL): void;
192
+
185
193
  // Internal classes (exported but primarily for internal use)
186
194
 
195
+ /** @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
196
  export class Poly {
188
197
  coeffs: Int32Array;
189
198
  constructor();
190
199
  copy(poly: Poly): void;
191
200
  }
192
201
 
202
+ /** @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
203
  export class PolyVecK {
194
204
  vec: Poly[];
195
205
  constructor();
196
206
  }
197
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". */
198
209
  export class PolyVecL {
199
210
  vec: Poly[];
200
211
  constructor();
201
212
  copy(polyVecL: PolyVecL): void;
202
213
  }
203
214
 
215
+ /** @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
216
  export class KeccakState {
205
217
  constructor();
206
218
  }
207
219
 
208
220
  // Internal functions (exported but primarily for internal use)
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". */
209
222
  export function polyNTT(a: Poly): void;
223
+ /** @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
224
  export function polyInvNTTToMont(a: Poly): void;
225
+ /** @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
226
  export function polyChallenge(c: Poly, seed: Uint8Array): void;
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". */
212
228
  export function ntt(a: Int32Array): 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". */
213
230
  export function invNTTToMont(a: Int32Array): 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". */
214
232
  export function montgomeryReduce(a: bigint): bigint;
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". */
215
234
  export function reduce32(a: number): number;
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". */
216
236
  export function cAddQ(a: number): number;
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". */
217
238
  export function decompose(a0: Int32Array, i: number, a: number): number;
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". */
218
240
  export function power2round(a0: Int32Array, i: number, 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". */
219
242
  export function makeHint(a0: number, a1: 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". */
220
244
  export function useHint(a: number, hint: 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". */
221
246
  export function packPk(pk: Uint8Array, rho: Uint8Array, t1: PolyVecK): void;
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". */
222
248
  export function packSk(
223
249
  sk: Uint8Array,
224
250
  rho: Uint8Array,
@@ -228,13 +254,16 @@ export function packSk(
228
254
  s1: PolyVecL,
229
255
  s2: PolyVecK
230
256
  ): void;
257
+ /** @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
258
  export function packSig(
232
259
  sig: Uint8Array,
233
260
  c: Uint8Array,
234
261
  z: PolyVecL,
235
262
  h: PolyVecK
236
263
  ): void;
264
+ /** @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
265
  export function unpackPk(rho: Uint8Array, t1: PolyVecK, pk: Uint8Array): void;
266
+ /** @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
267
  export function unpackSk(
239
268
  rho: Uint8Array,
240
269
  tr: Uint8Array,
@@ -244,6 +273,7 @@ export function unpackSk(
244
273
  s2: PolyVecK,
245
274
  sk: Uint8Array
246
275
  ): void;
276
+ /** @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
277
  export function unpackSig(
248
278
  c: Uint8Array,
249
279
  z: PolyVecL,
@@ -252,18 +282,26 @@ export function unpackSig(
252
282
  ): number;
253
283
 
254
284
  // FIPS 202 SHAKE primitives (low-level XOF interface, primarily internal)
285
+ /** @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
286
  export function shake128Init(state: KeccakState): void;
287
+ /** @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
288
  export function shake128Absorb(state: KeccakState, input: Uint8Array): void;
289
+ /** @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
290
  export function shake128Finalize(state: KeccakState): void;
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". */
258
292
  export function shake128SqueezeBlocks(
259
293
  out: Uint8Array,
260
294
  outputOffset: number,
261
295
  nBlocks: number,
262
296
  state: KeccakState
263
297
  ): void;
298
+ /** @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
299
  export function shake256Init(state: KeccakState): void;
300
+ /** @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
301
  export function shake256Absorb(state: KeccakState, input: Uint8Array): void;
302
+ /** @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
303
  export function shake256Finalize(state: KeccakState): 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". */
267
305
  export function shake256SqueezeBlocks(
268
306
  out: Uint8Array,
269
307
  outputOffset: number,
@@ -272,11 +310,13 @@ export function shake256SqueezeBlocks(
272
310
  ): void;
273
311
 
274
312
  // Dilithium-specific stream initializers
313
+ /** @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
314
  export function dilithiumShake128StreamInit(
276
315
  state: KeccakState,
277
316
  seed: Uint8Array,
278
317
  nonce: number
279
318
  ): void;
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". */
280
320
  export function dilithiumShake256StreamInit(
281
321
  state: KeccakState,
282
322
  seed: Uint8Array,
@@ -284,17 +324,29 @@ export function dilithiumShake256StreamInit(
284
324
  ): void;
285
325
 
286
326
  // Polynomial operations (internal)
327
+ /** @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
328
  export function polyReduce(a: Poly): void;
329
+ /** @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
330
  export function polyCAddQ(a: Poly): void;
331
+ /** @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
332
  export function polyAdd(c: Poly, a: Poly, b: Poly): void;
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". */
290
334
  export function polySub(c: Poly, a: Poly, b: 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". */
291
336
  export function polyShiftL(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". */
292
338
  export function polyPointWiseMontgomery(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". */
293
340
  export function polyPower2round(a1: Poly, a0: Poly, a: 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". */
294
342
  export function polyDecompose(a1: Poly, a0: Poly, 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". */
295
344
  export function polyMakeHint(h: Poly, a0: Poly, a1: Poly): number;
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". */
296
346
  export function polyUseHint(b: Poly, a: Poly, h: 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". */
297
348
  export function polyChkNorm(a: Poly, b: number): number;
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". */
298
350
  export function rejUniform(
299
351
  a: Int32Array,
300
352
  aOffset: number,
@@ -302,7 +354,9 @@ export function rejUniform(
302
354
  buf: Uint8Array,
303
355
  bufLen: number
304
356
  ): number;
357
+ /** @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
358
  export function polyUniform(a: Poly, seed: Uint8Array, nonce: number): void;
359
+ /** @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
360
  export function rejEta(
307
361
  a: Int32Array,
308
362
  aOffset: number,
@@ -310,58 +364,95 @@ export function rejEta(
310
364
  buf: Uint8Array,
311
365
  bufLen: number
312
366
  ): number;
367
+ /** @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
368
  export function polyUniformEta(a: Poly, seed: Uint8Array, nonce: number): void;
369
+ /** @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
370
  export function polyZUnpack(r: Poly, a: Uint8Array, aOffset: number): void;
371
+ /** @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
372
  export function polyUniformGamma1(a: Poly, seed: Uint8Array, nonce: number): void;
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". */
316
374
  export function polyEtaPack(r: Uint8Array, rOffset: number, a: Poly): 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". */
317
376
  export function polyEtaUnpack(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". */
318
378
  export function polyT1Pack(r: Uint8Array, rOffset: number, a: Poly): 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". */
319
380
  export function polyT1Unpack(r: Poly, a: Uint8Array, aOffset: number): 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". */
320
382
  export function polyT0Pack(r: Uint8Array, rOffset: number, a: Poly): 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". */
321
384
  export function polyT0Unpack(r: Poly, a: Uint8Array, aOffset: number): 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". */
322
386
  export function polyZPack(r: Uint8Array, rOffset: number, a: Poly): 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". */
323
388
  export function polyW1Pack(r: Uint8Array, rOffset: number, a: Poly): void;
324
389
 
325
390
  // Polynomial vector operations (internal)
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". */
326
392
  export function polyVecMatrixExpand(mat: PolyVecL[], rho: Uint8Array): 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". */
327
394
  export function polyVecMatrixPointWiseMontgomery(
328
395
  t: PolyVecK,
329
396
  mat: PolyVecL[],
330
397
  v: PolyVecL
331
398
  ): 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". */
332
400
  export function polyVecLUniformEta(v: PolyVecL, seed: Uint8Array, nonce: number): void;
401
+ /** @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
402
  export function polyVecLUniformGamma1(v: PolyVecL, seed: Uint8Array, nonce: number): void;
403
+ /** @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
404
  export function polyVecLReduce(v: PolyVecL): 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". */
335
406
  export function polyVecLAdd(w: PolyVecL, u: PolyVecL, v: PolyVecL): 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". */
336
408
  export function polyVecLNTT(v: PolyVecL): 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". */
337
410
  export function polyVecLInvNTTToMont(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". */
338
412
  export function polyVecLPointWisePolyMontgomery(
339
413
  r: PolyVecL,
340
414
  a: Poly,
341
415
  v: PolyVecL
342
416
  ): 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". */
343
418
  export function polyVecLPointWiseAccMontgomery(
344
419
  w: Poly,
345
420
  u: PolyVecL,
346
421
  v: PolyVecL
347
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". */
348
424
  export function polyVecLChkNorm(v: PolyVecL, bound: number): number;
425
+ /** @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
426
  export function polyVecKUniformEta(v: PolyVecK, seed: Uint8Array, nonce: number): void;
427
+ /** @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
428
  export function polyVecKReduce(v: PolyVecK): 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". */
351
430
  export function polyVecKCAddQ(v: PolyVecK): void;
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". */
352
432
  export function polyVecKAdd(w: PolyVecK, u: PolyVecK, v: PolyVecK): 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". */
353
434
  export function polyVecKSub(w: PolyVecK, u: PolyVecK, 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". */
354
436
  export function polyVecKShiftL(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". */
355
438
  export function polyVecKNTT(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". */
356
440
  export function polyVecKInvNTTToMont(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". */
357
442
  export function polyVecKPointWisePolyMontgomery(
358
443
  r: PolyVecK,
359
444
  a: Poly,
360
445
  v: PolyVecK
361
446
  ): 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". */
362
448
  export function polyVecKChkNorm(v: PolyVecK, bound: number): number;
449
+ /** @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
450
  export function polyVecKPower2round(v1: PolyVecK, v0: PolyVecK, v: PolyVecK): void;
451
+ /** @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
452
  export function polyVecKDecompose(v1: PolyVecK, v0: PolyVecK, v: PolyVecK): 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". */
365
454
  export function polyVecKMakeHint(h: PolyVecK, v0: PolyVecK, v1: PolyVecK): 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". */
366
456
  export function polyVecKUseHint(w: PolyVecK, u: PolyVecK, h: 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". */
367
458
  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.0",
3
+ "version": "1.2.2",
4
4
  "description": "Dilithium-5 cryptography",
5
5
  "keywords": [
6
6
  "dilithium",
@@ -63,24 +63,24 @@
63
63
  "@rollup/plugin-node-resolve": "16.0.3",
64
64
  "c8": "11.0.0",
65
65
  "chai": "6.2.2",
66
- "eslint": "10.0.3",
66
+ "eslint": "10.3.0",
67
67
  "eslint-config-prettier": "10.1.8",
68
68
  "eslint-plugin-import-x": "4.16.2",
69
69
  "eslint-plugin-prettier": "5.5.5",
70
- "globals": "17.4.0",
71
- "minimatch": "10.2.4",
70
+ "globals": "17.6.0",
71
+ "minimatch": "10.2.5",
72
72
  "mocha": "11.7.5",
73
- "prettier": "3.8.1",
74
- "rollup": "4.59.0",
75
- "serialize-javascript": "7.0.4",
76
- "tar": "7.5.11"
73
+ "prettier": "3.8.3",
74
+ "rollup": "4.60.3",
75
+ "serialize-javascript": "7.0.5",
76
+ "tar": "7.5.15"
77
77
  },
78
78
  "dependencies": {
79
- "@noble/hashes": "2.0.1"
79
+ "@noble/hashes": "2.2.0"
80
80
  },
81
81
  "overrides": {
82
82
  "diff": "8.0.3",
83
- "minimatch": "10.2.4"
83
+ "minimatch": "10.2.5"
84
84
  },
85
85
  "c8": {
86
86
  "include": [