@theqrl/mldsa87 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/dist/cjs/mldsa87.d.cts +385 -0
- package/dist/cjs/mldsa87.js +130 -3
- package/dist/mjs/mldsa87.d.mts +385 -0
- package/dist/mjs/mldsa87.js +128 -4
- package/package.json +9 -3
- package/src/index.d.ts +182 -1
package/src/index.d.ts
CHANGED
|
@@ -89,6 +89,35 @@ export function cryptoSign(
|
|
|
89
89
|
ctx: Uint8Array
|
|
90
90
|
): Uint8Array;
|
|
91
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Create a deterministic ML-DSA-87 detached signature
|
|
94
|
+
* (FIPS 204 §3.5 — `randomizedSigning = false` wrapper).
|
|
95
|
+
*
|
|
96
|
+
* **Use only when the deterministic property is itself a requirement**
|
|
97
|
+
* — RANDAO-style verifiable beacon contributions, ACVP / KAT vector
|
|
98
|
+
* reproduction. For general-purpose signing prefer `cryptoSignSignature`
|
|
99
|
+
* with `randomizedSigning = true` (hedged, FIPS 204 §3.4 recommended).
|
|
100
|
+
* (TOB-QRLLIB-6.)
|
|
101
|
+
*/
|
|
102
|
+
export function cryptoSignSignatureDeterministic(
|
|
103
|
+
sig: Uint8Array,
|
|
104
|
+
m: Uint8Array | string,
|
|
105
|
+
sk: Uint8Array,
|
|
106
|
+
ctx: Uint8Array
|
|
107
|
+
): number;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Attached-form deterministic ML-DSA-87 signing
|
|
111
|
+
* (FIPS 204 §3.5 — `randomizedSigning = false` wrapper for `cryptoSign`).
|
|
112
|
+
* Same recommendation as `cryptoSignSignatureDeterministic`.
|
|
113
|
+
* (TOB-QRLLIB-6.)
|
|
114
|
+
*/
|
|
115
|
+
export function cryptoSignDeterministic(
|
|
116
|
+
msg: Uint8Array | string,
|
|
117
|
+
sk: Uint8Array,
|
|
118
|
+
ctx: Uint8Array
|
|
119
|
+
): Uint8Array;
|
|
120
|
+
|
|
92
121
|
/**
|
|
93
122
|
* Verify a signature
|
|
94
123
|
* @param sig - Signature to verify
|
|
@@ -109,7 +138,10 @@ export function cryptoSignVerify(
|
|
|
109
138
|
* @param sm - Signed message (signature || message)
|
|
110
139
|
* @param pk - Public key
|
|
111
140
|
* @param ctx - Context string (max 255 bytes)
|
|
112
|
-
* @returns Message if valid, undefined if verification fails
|
|
141
|
+
* @returns Message if valid, undefined if verification fails (or if
|
|
142
|
+
* sm is null / undefined / non-Uint8Array / shorter than
|
|
143
|
+
* CryptoBytes — see `cryptoSignOpenWithReason` for distinct
|
|
144
|
+
* failure-mode reporting)
|
|
113
145
|
*/
|
|
114
146
|
export function cryptoSignOpen(
|
|
115
147
|
sm: Uint8Array,
|
|
@@ -117,6 +149,40 @@ export function cryptoSignOpen(
|
|
|
117
149
|
ctx: Uint8Array
|
|
118
150
|
): Uint8Array | undefined;
|
|
119
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Failure-mode discriminator returned by `cryptoSignOpenWithReason`.
|
|
154
|
+
* (TOB-QRLLIB-14: distinct failure modes for Open.)
|
|
155
|
+
*/
|
|
156
|
+
export type CryptoSignOpenReason =
|
|
157
|
+
| 'invalid-ctx-type'
|
|
158
|
+
| 'invalid-ctx-length'
|
|
159
|
+
| 'invalid-sm-type'
|
|
160
|
+
| 'invalid-sm-length'
|
|
161
|
+
| 'invalid-pk'
|
|
162
|
+
| 'verification-failed';
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Open a signed message with a typed failure-mode report.
|
|
166
|
+
* (TOB-QRLLIB-14.) Behavioural twin of `cryptoSignOpen` that
|
|
167
|
+
* distinguishes API-shape problems (input wrong type / length /
|
|
168
|
+
* shape) from genuine verification failures.
|
|
169
|
+
*
|
|
170
|
+
* `cryptoSignOpen` is kept unchanged and continues to return
|
|
171
|
+
* `undefined` for any failure mode. Use this variant when you need
|
|
172
|
+
* to log or route on specific failure modes.
|
|
173
|
+
*
|
|
174
|
+
* @param sm - Signed message (signature || message)
|
|
175
|
+
* @param pk - Public key
|
|
176
|
+
* @param ctx - Context string (max 255 bytes)
|
|
177
|
+
*/
|
|
178
|
+
export function cryptoSignOpenWithReason(
|
|
179
|
+
sm: Uint8Array,
|
|
180
|
+
pk: Uint8Array,
|
|
181
|
+
ctx: Uint8Array
|
|
182
|
+
):
|
|
183
|
+
| { ok: true; message: Uint8Array }
|
|
184
|
+
| { ok: false; reason: CryptoSignOpenReason };
|
|
185
|
+
|
|
120
186
|
// Utility functions
|
|
121
187
|
|
|
122
188
|
/**
|
|
@@ -202,3 +268,118 @@ export function unpackSig(
|
|
|
202
268
|
h: PolyVecK,
|
|
203
269
|
sig: Uint8Array
|
|
204
270
|
): number;
|
|
271
|
+
|
|
272
|
+
// FIPS 202 SHAKE primitives (low-level XOF interface, primarily internal)
|
|
273
|
+
export function shake128Init(state: KeccakState): void;
|
|
274
|
+
export function shake128Absorb(state: KeccakState, input: Uint8Array): void;
|
|
275
|
+
export function shake128Finalize(state: KeccakState): void;
|
|
276
|
+
export function shake128SqueezeBlocks(
|
|
277
|
+
out: Uint8Array,
|
|
278
|
+
outputOffset: number,
|
|
279
|
+
nBlocks: number,
|
|
280
|
+
state: KeccakState
|
|
281
|
+
): void;
|
|
282
|
+
export function shake256Init(state: KeccakState): void;
|
|
283
|
+
export function shake256Absorb(state: KeccakState, input: Uint8Array): void;
|
|
284
|
+
export function shake256Finalize(state: KeccakState): void;
|
|
285
|
+
export function shake256SqueezeBlocks(
|
|
286
|
+
out: Uint8Array,
|
|
287
|
+
outputOffset: number,
|
|
288
|
+
nBlocks: number,
|
|
289
|
+
state: KeccakState
|
|
290
|
+
): void;
|
|
291
|
+
|
|
292
|
+
// ML-DSA-specific stream initializers
|
|
293
|
+
export function mldsaShake128StreamInit(
|
|
294
|
+
state: KeccakState,
|
|
295
|
+
seed: Uint8Array,
|
|
296
|
+
nonce: number
|
|
297
|
+
): void;
|
|
298
|
+
export function mldsaShake256StreamInit(
|
|
299
|
+
state: KeccakState,
|
|
300
|
+
seed: Uint8Array,
|
|
301
|
+
nonce: number
|
|
302
|
+
): void;
|
|
303
|
+
|
|
304
|
+
// Polynomial operations (internal)
|
|
305
|
+
export function polyReduce(a: Poly): void;
|
|
306
|
+
export function polyCAddQ(a: Poly): void;
|
|
307
|
+
export function polyAdd(c: Poly, a: Poly, b: Poly): void;
|
|
308
|
+
export function polySub(c: Poly, a: Poly, b: Poly): void;
|
|
309
|
+
export function polyShiftL(a: Poly): void;
|
|
310
|
+
export function polyPointWiseMontgomery(c: Poly, a: Poly, b: Poly): void;
|
|
311
|
+
export function polyPower2round(a1: Poly, a0: Poly, a: Poly): void;
|
|
312
|
+
export function polyDecompose(a1: Poly, a0: Poly, a: Poly): void;
|
|
313
|
+
export function polyMakeHint(h: Poly, a0: Poly, a1: Poly): number;
|
|
314
|
+
export function polyUseHint(b: Poly, a: Poly, h: Poly): void;
|
|
315
|
+
export function polyChkNorm(a: Poly, b: number): number;
|
|
316
|
+
export function rejUniform(
|
|
317
|
+
a: Int32Array,
|
|
318
|
+
aOffset: number,
|
|
319
|
+
len: number,
|
|
320
|
+
buf: Uint8Array,
|
|
321
|
+
bufLen: number
|
|
322
|
+
): number;
|
|
323
|
+
export function polyUniform(a: Poly, seed: Uint8Array, nonce: number): void;
|
|
324
|
+
export function rejEta(
|
|
325
|
+
a: Int32Array,
|
|
326
|
+
aOffset: number,
|
|
327
|
+
len: number,
|
|
328
|
+
buf: Uint8Array,
|
|
329
|
+
bufLen: number
|
|
330
|
+
): number;
|
|
331
|
+
export function polyUniformEta(a: Poly, seed: Uint8Array, nonce: number): void;
|
|
332
|
+
export function polyZUnpack(r: Poly, a: Uint8Array, aOffset: number): void;
|
|
333
|
+
export function polyUniformGamma1(a: Poly, seed: Uint8Array, nonce: number): void;
|
|
334
|
+
export function polyEtaPack(r: Uint8Array, rOffset: number, a: Poly): void;
|
|
335
|
+
export function polyEtaUnpack(r: Poly, a: Uint8Array, aOffset: number): void;
|
|
336
|
+
export function polyT1Pack(r: Uint8Array, rOffset: number, a: Poly): void;
|
|
337
|
+
export function polyT1Unpack(r: Poly, a: Uint8Array, aOffset: number): void;
|
|
338
|
+
export function polyT0Pack(r: Uint8Array, rOffset: number, a: Poly): void;
|
|
339
|
+
export function polyT0Unpack(r: Poly, a: Uint8Array, aOffset: number): void;
|
|
340
|
+
export function polyZPack(r: Uint8Array, rOffset: number, a: Poly): void;
|
|
341
|
+
export function polyW1Pack(r: Uint8Array, rOffset: number, a: Poly): void;
|
|
342
|
+
|
|
343
|
+
// Polynomial vector operations (internal)
|
|
344
|
+
export function polyVecMatrixExpand(mat: PolyVecL[], rho: Uint8Array): void;
|
|
345
|
+
export function polyVecMatrixPointWiseMontgomery(
|
|
346
|
+
t: PolyVecK,
|
|
347
|
+
mat: PolyVecL[],
|
|
348
|
+
v: PolyVecL
|
|
349
|
+
): void;
|
|
350
|
+
export function polyVecLUniformEta(v: PolyVecL, seed: Uint8Array, nonce: number): void;
|
|
351
|
+
export function polyVecLUniformGamma1(v: PolyVecL, seed: Uint8Array, nonce: number): void;
|
|
352
|
+
export function polyVecLReduce(v: PolyVecL): void;
|
|
353
|
+
export function polyVecLAdd(w: PolyVecL, u: PolyVecL, v: PolyVecL): void;
|
|
354
|
+
export function polyVecLNTT(v: PolyVecL): void;
|
|
355
|
+
export function polyVecLInvNTTToMont(v: PolyVecL): void;
|
|
356
|
+
export function polyVecLPointWisePolyMontgomery(
|
|
357
|
+
r: PolyVecL,
|
|
358
|
+
a: Poly,
|
|
359
|
+
v: PolyVecL
|
|
360
|
+
): void;
|
|
361
|
+
export function polyVecLPointWiseAccMontgomery(
|
|
362
|
+
w: Poly,
|
|
363
|
+
u: PolyVecL,
|
|
364
|
+
v: PolyVecL
|
|
365
|
+
): void;
|
|
366
|
+
export function polyVecLChkNorm(v: PolyVecL, bound: number): number;
|
|
367
|
+
export function polyVecKUniformEta(v: PolyVecK, seed: Uint8Array, nonce: number): void;
|
|
368
|
+
export function polyVecKReduce(v: PolyVecK): void;
|
|
369
|
+
export function polyVecKCAddQ(v: PolyVecK): void;
|
|
370
|
+
export function polyVecKAdd(w: PolyVecK, u: PolyVecK, v: PolyVecK): void;
|
|
371
|
+
export function polyVecKSub(w: PolyVecK, u: PolyVecK, v: PolyVecK): void;
|
|
372
|
+
export function polyVecKShiftL(v: PolyVecK): void;
|
|
373
|
+
export function polyVecKNTT(v: PolyVecK): void;
|
|
374
|
+
export function polyVecKInvNTTToMont(v: PolyVecK): void;
|
|
375
|
+
export function polyVecKPointWisePolyMontgomery(
|
|
376
|
+
r: PolyVecK,
|
|
377
|
+
a: Poly,
|
|
378
|
+
v: PolyVecK
|
|
379
|
+
): void;
|
|
380
|
+
export function polyVecKChkNorm(v: PolyVecK, bound: number): number;
|
|
381
|
+
export function polyVecKPower2round(v1: PolyVecK, v0: PolyVecK, v: PolyVecK): void;
|
|
382
|
+
export function polyVecKDecompose(v1: PolyVecK, v0: PolyVecK, v: PolyVecK): void;
|
|
383
|
+
export function polyVecKMakeHint(h: PolyVecK, v0: PolyVecK, v1: PolyVecK): number;
|
|
384
|
+
export function polyVecKUseHint(w: PolyVecK, u: PolyVecK, h: PolyVecK): void;
|
|
385
|
+
export function polyVecKPackW1(r: Uint8Array, w1: PolyVecK): void;
|