@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.
- package/README.md +6 -5
- package/dist/cjs/dilithium5.d.cts +99 -2
- package/dist/cjs/dilithium5.js +71 -29
- package/dist/mjs/dilithium5.d.mts +99 -2
- package/dist/mjs/dilithium5.js +71 -30
- package/package.json +2 -4
- package/src/index.d.ts +99 -2
package/README.md
CHANGED
|
@@ -26,10 +26,11 @@ const pk = new Uint8Array(CryptoPublicKeyBytes); // 2592 bytes
|
|
|
26
26
|
const sk = new Uint8Array(CryptoSecretKeyBytes); // 4896 bytes
|
|
27
27
|
cryptoSignKeypair(null, pk, sk); // null = random seed
|
|
28
28
|
|
|
29
|
-
// Sign a message
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
// use
|
|
29
|
+
// Sign a message. The randomized flag is required — there is no default;
|
|
30
|
+
// hedged (`true`) is the recommended mode. Pass `false` only when
|
|
31
|
+
// deterministic signatures are themselves a protocol requirement
|
|
32
|
+
// (e.g. KAT vector reproduction); for that case use
|
|
33
|
+
// `cryptoSignDeterministic`.
|
|
33
34
|
const message = new TextEncoder().encode('Hello, quantum world!');
|
|
34
35
|
const signedMessage = cryptoSign(message, sk, true); // true = hedged (recommended)
|
|
35
36
|
|
|
@@ -121,7 +122,7 @@ Check if buffer is all zeros (constant-time).
|
|
|
121
122
|
go-qrllib pre-hashes seeds with SHAKE256 before key generation. To generate matching keys:
|
|
122
123
|
|
|
123
124
|
```javascript
|
|
124
|
-
import { shake256 } from '@noble/hashes/sha3';
|
|
125
|
+
import { shake256 } from '@noble/hashes/sha3.js';
|
|
125
126
|
|
|
126
127
|
// go-qrllib: hashedSeed = SHAKE256(rawSeed)[:32]
|
|
127
128
|
const hashedSeed = shake256(rawSeed, { dkLen: 32 });
|
|
@@ -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;
|
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;
|