@theqrl/dilithium5 1.2.1 → 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.
- package/dist/cjs/dilithium5.d.cts +92 -1
- package/dist/cjs/dilithium5.js +71 -29
- package/dist/mjs/dilithium5.d.mts +92 -1
- package/dist/mjs/dilithium5.js +71 -30
- package/package.json +2 -2
- package/src/index.d.ts +92 -1
|
@@ -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;
|
package/dist/cjs/dilithium5.js
CHANGED
|
@@ -707,7 +707,6 @@ genShake(0x1f, 136, 32, /* @__PURE__ */ oidNist(0x0c));
|
|
|
707
707
|
class KeccakState {
|
|
708
708
|
constructor() {
|
|
709
709
|
this.hasher = null;
|
|
710
|
-
this.finalized = false;
|
|
711
710
|
}
|
|
712
711
|
}
|
|
713
712
|
|
|
@@ -715,17 +714,18 @@ class KeccakState {
|
|
|
715
714
|
|
|
716
715
|
function shake128Init(state) {
|
|
717
716
|
state.hasher = shake128.create({});
|
|
718
|
-
state.finalized = false;
|
|
719
717
|
}
|
|
720
718
|
|
|
721
719
|
function shake128Absorb(state, input) {
|
|
722
720
|
state.hasher.update(input);
|
|
723
721
|
}
|
|
724
722
|
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
723
|
+
/**
|
|
724
|
+
* No-op retained for API parity with the C reference's absorb/finalize/squeeze
|
|
725
|
+
* flow: @noble/hashes finalizes the sponge automatically on the first
|
|
726
|
+
* xofInto() call, so there is no separate finalize step to perform.
|
|
727
|
+
*/
|
|
728
|
+
function shake128Finalize() {}
|
|
729
729
|
|
|
730
730
|
function shake128SqueezeBlocks(out, outputOffset, nBlocks, state) {
|
|
731
731
|
const len = nBlocks * Shake128Rate;
|
|
@@ -737,17 +737,18 @@ function shake128SqueezeBlocks(out, outputOffset, nBlocks, state) {
|
|
|
737
737
|
|
|
738
738
|
function shake256Init(state) {
|
|
739
739
|
state.hasher = shake256.create({});
|
|
740
|
-
state.finalized = false;
|
|
741
740
|
}
|
|
742
741
|
|
|
743
742
|
function shake256Absorb(state, input) {
|
|
744
743
|
state.hasher.update(input);
|
|
745
744
|
}
|
|
746
745
|
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
746
|
+
/**
|
|
747
|
+
* No-op retained for API parity with the C reference's absorb/finalize/squeeze
|
|
748
|
+
* flow: @noble/hashes finalizes the sponge automatically on the first
|
|
749
|
+
* xofInto() call, so there is no separate finalize step to perform.
|
|
750
|
+
*/
|
|
751
|
+
function shake256Finalize() {}
|
|
751
752
|
|
|
752
753
|
function shake256SqueezeBlocks(out, outputOffset, nBlocks, state) {
|
|
753
754
|
const len = nBlocks * Shake256Rate;
|
|
@@ -766,7 +767,6 @@ function dilithiumShake128StreamInit(state, seed, nonce) {
|
|
|
766
767
|
shake128Init(state);
|
|
767
768
|
shake128Absorb(state, seed);
|
|
768
769
|
shake128Absorb(state, t);
|
|
769
|
-
shake128Finalize(state);
|
|
770
770
|
}
|
|
771
771
|
|
|
772
772
|
function dilithiumShake256StreamInit(state, seed, nonce) {
|
|
@@ -780,7 +780,6 @@ function dilithiumShake256StreamInit(state, seed, nonce) {
|
|
|
780
780
|
shake256Init(state);
|
|
781
781
|
shake256Absorb(state, seed);
|
|
782
782
|
shake256Absorb(state, t);
|
|
783
|
-
shake256Finalize(state);
|
|
784
783
|
}
|
|
785
784
|
|
|
786
785
|
function montgomeryReduce(a) {
|
|
@@ -1079,6 +1078,8 @@ function polyUniformGamma1(a, seed, nonce) {
|
|
|
1079
1078
|
}
|
|
1080
1079
|
|
|
1081
1080
|
function polyChallenge(cP, seed) {
|
|
1081
|
+
// Invariant tripwire: internal callers always pass a SeedBytes-long
|
|
1082
|
+
// challenge hash; anything else indicates a regression in sign/verify.
|
|
1082
1083
|
if (seed.length !== SeedBytes) throw new Error('invalid seed length');
|
|
1083
1084
|
|
|
1084
1085
|
let b;
|
|
@@ -1089,7 +1090,6 @@ function polyChallenge(cP, seed) {
|
|
|
1089
1090
|
const state = new KeccakState();
|
|
1090
1091
|
shake256Init(state);
|
|
1091
1092
|
shake256Absorb(state, seed);
|
|
1092
|
-
shake256Finalize(state);
|
|
1093
1093
|
shake256SqueezeBlocks(buf, 0, 1, state);
|
|
1094
1094
|
|
|
1095
1095
|
let signs = 0n;
|
|
@@ -1396,6 +1396,9 @@ function polyVecLChkNorm(v, bound) {
|
|
|
1396
1396
|
|
|
1397
1397
|
function polyVecKUniformEta(v, seed, nonceP) {
|
|
1398
1398
|
let nonce = nonceP;
|
|
1399
|
+
if (seed.length !== CRHBytes) {
|
|
1400
|
+
throw new Error(`invalid seed length ${seed.length} | Expected length ${CRHBytes}`);
|
|
1401
|
+
}
|
|
1399
1402
|
for (let i = 0; i < K; ++i) {
|
|
1400
1403
|
polyUniformEta(v.vec[i], seed, nonce++);
|
|
1401
1404
|
}
|
|
@@ -1602,6 +1605,10 @@ function packSig(sigP, c, z, h) {
|
|
|
1602
1605
|
sig[sigOffset + i] = 0;
|
|
1603
1606
|
}
|
|
1604
1607
|
|
|
1608
|
+
// Invariant tripwires: h produced by polyVecKMakeHint is always binary
|
|
1609
|
+
// with at most OMEGA set coefficients (the sign loop re-samples
|
|
1610
|
+
// otherwise). A violation here means an internal regression upstream —
|
|
1611
|
+
// fail loudly rather than emit a malformed signature.
|
|
1605
1612
|
let k = 0;
|
|
1606
1613
|
for (let i = 0; i < K; ++i) {
|
|
1607
1614
|
for (let j = 0; j < N; ++j) {
|
|
@@ -1695,6 +1702,9 @@ function randomBytes(size) {
|
|
|
1695
1702
|
cryptoObj.getRandomValues(out.subarray(i, Math.min(size, i + MAX_BYTES)));
|
|
1696
1703
|
}
|
|
1697
1704
|
if (size >= 16) {
|
|
1705
|
+
// Invariant tripwire: a healthy CSPRNG never returns 16 leading zero
|
|
1706
|
+
// bytes (p = 2^-128). All-zero output means the platform RNG is
|
|
1707
|
+
// catastrophically broken — refuse to hand it to key generation.
|
|
1698
1708
|
let acc = 0;
|
|
1699
1709
|
for (let i = 0; i < 16; i++) acc |= out[i];
|
|
1700
1710
|
if (acc === 0) throw new Error('getRandomValues returned all zeros');
|
|
@@ -1743,6 +1753,22 @@ function zeroize(buffer) {
|
|
|
1743
1753
|
}
|
|
1744
1754
|
}
|
|
1745
1755
|
|
|
1756
|
+
/**
|
|
1757
|
+
* Attempts to zero the coefficient arrays of a polynomial vector
|
|
1758
|
+
* (PolyVecL/PolyVecK). Centralizes the secret-wiping pattern used by the
|
|
1759
|
+
* signing paths so every sensitive PolyVec is cleared the same way.
|
|
1760
|
+
*
|
|
1761
|
+
* Same BEST-EFFORT caveats as zeroize() — see SECURITY.md.
|
|
1762
|
+
*
|
|
1763
|
+
* @param {{vec: {coeffs: Int32Array}[]}} polyVec - The polynomial vector to zero
|
|
1764
|
+
* @returns {void}
|
|
1765
|
+
*/
|
|
1766
|
+
function zeroizePolyVec(polyVec) {
|
|
1767
|
+
for (let i = 0; i < polyVec.vec.length; i++) {
|
|
1768
|
+
polyVec.vec[i].coeffs.fill(0);
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1746
1772
|
/**
|
|
1747
1773
|
* Checks if a buffer is all zeros.
|
|
1748
1774
|
* Uses constant-time comparison to avoid timing leaks.
|
|
@@ -1774,6 +1800,8 @@ function isZero(buffer) {
|
|
|
1774
1800
|
* @private
|
|
1775
1801
|
*/
|
|
1776
1802
|
function hexToBytes(hex) {
|
|
1803
|
+
// Unreachable via the public API: messageToBytes routes only strings here.
|
|
1804
|
+
// Kept as defense-in-depth for any future direct internal caller.
|
|
1777
1805
|
/* c8 ignore start */
|
|
1778
1806
|
if (typeof hex !== 'string') {
|
|
1779
1807
|
throw new Error('message must be a hex string');
|
|
@@ -1823,13 +1851,18 @@ function messageToBytes(message) {
|
|
|
1823
1851
|
* Pass null or undefined for random key generation.
|
|
1824
1852
|
* @param {Uint8Array} pk - Output buffer for public key (must be CryptoPublicKeyBytes = 2592 bytes)
|
|
1825
1853
|
* @param {Uint8Array} sk - Output buffer for secret key (must be CryptoSecretKeyBytes = 4896 bytes)
|
|
1826
|
-
* @returns {Uint8Array} The seed used for key generation (useful when passedSeed is null)
|
|
1854
|
+
* @returns {Uint8Array} The seed used for key generation (useful when passedSeed is null).
|
|
1855
|
+
* **The returned seed is secret-key-equivalent**: anyone holding it can
|
|
1856
|
+
* regenerate the full keypair. Store it with the same care as `sk` and
|
|
1857
|
+
* `zeroize()` it as soon as it is no longer needed.
|
|
1827
1858
|
* @throws {Error} If pk/sk buffers are null or wrong size, or if seed is wrong size
|
|
1828
1859
|
*
|
|
1829
1860
|
* @example
|
|
1830
1861
|
* const pk = new Uint8Array(CryptoPublicKeyBytes);
|
|
1831
1862
|
* const sk = new Uint8Array(CryptoSecretKeyBytes);
|
|
1832
1863
|
* const seed = cryptoSignKeypair(null, pk, sk);
|
|
1864
|
+
* // ... persist or use seed (it can regenerate sk!) ...
|
|
1865
|
+
* zeroize(seed);
|
|
1833
1866
|
*/
|
|
1834
1867
|
function cryptoSignKeypair(passedSeed, pk, sk) {
|
|
1835
1868
|
try {
|
|
@@ -1903,10 +1936,10 @@ function cryptoSignKeypair(passedSeed, pk, sk) {
|
|
|
1903
1936
|
zeroize(seedBuf);
|
|
1904
1937
|
zeroize(rhoPrime);
|
|
1905
1938
|
zeroize(key);
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
if (s1hat)
|
|
1909
|
-
|
|
1939
|
+
zeroizePolyVec(s1);
|
|
1940
|
+
zeroizePolyVec(s2);
|
|
1941
|
+
if (s1hat) zeroizePolyVec(s1hat);
|
|
1942
|
+
zeroizePolyVec(t0);
|
|
1910
1943
|
}
|
|
1911
1944
|
}
|
|
1912
1945
|
|
|
@@ -1971,7 +2004,10 @@ function cryptoSignSignature(sig, m, sk, randomizedSigning) {
|
|
|
1971
2004
|
const mu = shake256.create({}).update(tr).update(mBytes).xof(CRHBytes);
|
|
1972
2005
|
|
|
1973
2006
|
if (randomizedSigning) {
|
|
1974
|
-
|
|
2007
|
+
// randomBytes already returns a fresh Uint8Array; assign it directly so
|
|
2008
|
+
// no unwiped intermediate copy is left behind (rhoPrime is zeroized in
|
|
2009
|
+
// the finally block).
|
|
2010
|
+
rhoPrime = randomBytes(CRHBytes);
|
|
1975
2011
|
} else {
|
|
1976
2012
|
rhoPrime = shake256.create({}).update(key).update(mu).xof(CRHBytes);
|
|
1977
2013
|
}
|
|
@@ -1998,7 +2034,7 @@ function cryptoSignSignature(sig, m, sk, randomizedSigning) {
|
|
|
1998
2034
|
const cHash = shake256
|
|
1999
2035
|
.create({})
|
|
2000
2036
|
.update(mu)
|
|
2001
|
-
.update(sig.
|
|
2037
|
+
.update(sig.subarray(0, K * PolyW1PackedBytes))
|
|
2002
2038
|
.xof(SeedBytes);
|
|
2003
2039
|
sig.set(cHash);
|
|
2004
2040
|
|
|
@@ -2025,6 +2061,9 @@ function cryptoSignSignature(sig, m, sk, randomizedSigning) {
|
|
|
2025
2061
|
polyVecKPointWisePolyMontgomery(h, cp, t0);
|
|
2026
2062
|
polyVecKInvNTTToMont(h);
|
|
2027
2063
|
polyVecKReduce(h);
|
|
2064
|
+
// Statistically rare rejection (depends on key/challenge interaction);
|
|
2065
|
+
// no deterministic trigger is known, so it is exercised by long fuzz
|
|
2066
|
+
// campaigns rather than unit vectors.
|
|
2028
2067
|
/* c8 ignore start */
|
|
2029
2068
|
if (polyVecKChkNorm(h, GAMMA2) !== 0) {
|
|
2030
2069
|
continue;
|
|
@@ -2033,6 +2072,7 @@ function cryptoSignSignature(sig, m, sk, randomizedSigning) {
|
|
|
2033
2072
|
|
|
2034
2073
|
polyVecKAdd(w0, w0, h);
|
|
2035
2074
|
const n = polyVecKMakeHint(h, w0, w1);
|
|
2075
|
+
// Statistically rare rejection — same rationale as the ct0 check above.
|
|
2036
2076
|
/* c8 ignore start */
|
|
2037
2077
|
if (n > OMEGA) {
|
|
2038
2078
|
continue;
|
|
@@ -2045,10 +2085,10 @@ function cryptoSignSignature(sig, m, sk, randomizedSigning) {
|
|
|
2045
2085
|
} finally {
|
|
2046
2086
|
zeroize(key);
|
|
2047
2087
|
zeroize(rhoPrime);
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2088
|
+
zeroizePolyVec(s1);
|
|
2089
|
+
zeroizePolyVec(s2);
|
|
2090
|
+
zeroizePolyVec(t0);
|
|
2091
|
+
zeroizePolyVec(y);
|
|
2052
2092
|
}
|
|
2053
2093
|
}
|
|
2054
2094
|
|
|
@@ -2097,13 +2137,14 @@ function cryptoSignSignatureDeterministic(sig, m, sk) {
|
|
|
2097
2137
|
function cryptoSign(msg, sk, randomizedSigning) {
|
|
2098
2138
|
const msgBytes = messageToBytes(msg);
|
|
2099
2139
|
|
|
2140
|
+
// Place the message after the signature area. (The C reference uses a
|
|
2141
|
+
// backwards copy because its sm/m buffers may alias; here they never do.)
|
|
2100
2142
|
const sm = new Uint8Array(CryptoBytes + msgBytes.length);
|
|
2101
|
-
|
|
2102
|
-
for (let i = 0; i < mLen; ++i) {
|
|
2103
|
-
sm[CryptoBytes + mLen - 1 - i] = msgBytes[mLen - 1 - i];
|
|
2104
|
-
}
|
|
2143
|
+
sm.set(msgBytes, CryptoBytes);
|
|
2105
2144
|
const result = cryptoSignSignature(sm, msgBytes, sk, randomizedSigning);
|
|
2106
2145
|
|
|
2146
|
+
// Unreachable: cryptoSignSignature returns 0 or throws — defensive
|
|
2147
|
+
// tripwire in case a future change introduces a non-zero failure return.
|
|
2107
2148
|
/* c8 ignore start */
|
|
2108
2149
|
if (result !== 0) {
|
|
2109
2150
|
throw new Error('failed to sign');
|
|
@@ -2411,4 +2452,5 @@ exports.unpackSig = unpackSig;
|
|
|
2411
2452
|
exports.unpackSk = unpackSk;
|
|
2412
2453
|
exports.useHint = useHint;
|
|
2413
2454
|
exports.zeroize = zeroize;
|
|
2455
|
+
exports.zeroizePolyVec = zeroizePolyVec;
|
|
2414
2456
|
exports.zetas = zetas;
|