@theqrl/dilithium5 1.1.5 → 1.2.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 CHANGED
@@ -26,9 +26,12 @@ 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
29
+ // Sign a message (hedged by default — recommended per TOB-QRLLIB-6).
30
+ // Pass `false` only when deterministic signatures are themselves a
31
+ // protocol requirement (e.g. KAT vector reproduction); for that case
32
+ // use `cryptoSignDeterministic`.
30
33
  const message = new TextEncoder().encode('Hello, quantum world!');
31
- const signedMessage = cryptoSign(message, sk, false); // false = deterministic
34
+ const signedMessage = cryptoSign(message, sk, true); // true = hedged (recommended)
32
35
 
33
36
  // Verify and extract
34
37
  const extracted = cryptoSignOpen(signedMessage, pk);
@@ -83,6 +83,31 @@ export function cryptoSign(
83
83
  randomizedSigning: boolean
84
84
  ): Uint8Array;
85
85
 
86
+ /**
87
+ * Create a deterministic Dilithium5 detached signature
88
+ * (`randomizedSigning = false` wrapper for `cryptoSignSignature`).
89
+ *
90
+ * **Use only when the deterministic property is itself a requirement**.
91
+ * For general-purpose signing prefer `cryptoSignSignature` with
92
+ * `randomizedSigning = true` (hedged — TOB-QRLLIB-6).
93
+ */
94
+ export function cryptoSignSignatureDeterministic(
95
+ sig: Uint8Array,
96
+ m: Uint8Array | string,
97
+ sk: Uint8Array
98
+ ): number;
99
+
100
+ /**
101
+ * Attached-form deterministic Dilithium5 signing
102
+ * (`randomizedSigning = false` wrapper for `cryptoSign`).
103
+ * Same recommendation as `cryptoSignSignatureDeterministic`.
104
+ * (TOB-QRLLIB-6.)
105
+ */
106
+ export function cryptoSignDeterministic(
107
+ msg: Uint8Array | string,
108
+ sk: Uint8Array
109
+ ): Uint8Array;
110
+
86
111
  /**
87
112
  * Verify a signature
88
113
  * @param sig - Signature to verify
@@ -100,13 +125,46 @@ export function cryptoSignVerify(
100
125
  * Open a signed message (verify and extract message)
101
126
  * @param sm - Signed message (signature || message)
102
127
  * @param pk - Public key
103
- * @returns Message if valid, undefined if verification fails
128
+ * @returns Message if valid, undefined if verification fails (or if
129
+ * sm is null / undefined / non-Uint8Array / shorter than
130
+ * CryptoBytes — see `cryptoSignOpenWithReason` for distinct
131
+ * failure-mode reporting)
104
132
  */
105
133
  export function cryptoSignOpen(
106
134
  sm: Uint8Array,
107
135
  pk: Uint8Array
108
136
  ): Uint8Array | undefined;
109
137
 
138
+ /**
139
+ * Failure-mode discriminator returned by `cryptoSignOpenWithReason`.
140
+ * (TOB-QRLLIB-14: distinct failure modes for Open.)
141
+ */
142
+ export type CryptoSignOpenReason =
143
+ | 'invalid-sm-type'
144
+ | 'invalid-sm-length'
145
+ | 'invalid-pk'
146
+ | 'verification-failed';
147
+
148
+ /**
149
+ * Open a signed message with a typed failure-mode report.
150
+ * (TOB-QRLLIB-14.) Behavioural twin of `cryptoSignOpen` that
151
+ * distinguishes API-shape problems (input wrong type / length /
152
+ * shape) from genuine verification failures.
153
+ *
154
+ * `cryptoSignOpen` is kept unchanged and continues to return
155
+ * `undefined` for any failure mode. Use this variant when you need
156
+ * to log or route on specific failure modes.
157
+ *
158
+ * @param sm - Signed message (signature || message)
159
+ * @param pk - Public key
160
+ */
161
+ export function cryptoSignOpenWithReason(
162
+ sm: Uint8Array,
163
+ pk: Uint8Array
164
+ ):
165
+ | { ok: true; message: Uint8Array }
166
+ | { ok: false; reason: CryptoSignOpenReason };
167
+
110
168
  // Utility functions
111
169
 
112
170
  /**
@@ -1800,6 +1800,31 @@ function cryptoSignSignature(sig, m, sk, randomizedSigning) {
1800
1800
  }
1801
1801
  }
1802
1802
 
1803
+ /**
1804
+ * Create a **deterministic** Dilithium5 detached signature
1805
+ * (`randomizedSigning = false`).
1806
+ *
1807
+ * Convenience wrapper that hard-wires the deterministic mode so callers
1808
+ * who *need* byte-identical signatures for the same `(sk, message)`
1809
+ * — KAT vector reproduction, deterministic-test fixtures, RANDAO-style
1810
+ * protocols — get a clearly-named entry point rather than passing a
1811
+ * bare boolean.
1812
+ *
1813
+ * **Use only when the deterministic property is itself a requirement.**
1814
+ * For general-purpose signing prefer [cryptoSignSignature] with
1815
+ * `randomizedSigning = true` (hedged signing — TOB-QRLLIB-6 audit
1816
+ * recommendation for parity with the lattice-scheme guidance applied
1817
+ * to the Go and Rust ports).
1818
+ *
1819
+ * @param {Uint8Array} sig - Output buffer for signature (must be at least CryptoBytes bytes)
1820
+ * @param {string|Uint8Array} m - Message to sign
1821
+ * @param {Uint8Array} sk - Secret key (must be CryptoSecretKeyBytes bytes)
1822
+ * @returns {number} 0 on success
1823
+ */
1824
+ function cryptoSignSignatureDeterministic(sig, m, sk) {
1825
+ return cryptoSignSignature(sig, m, sk, /* randomizedSigning */ false);
1826
+ }
1827
+
1803
1828
  /**
1804
1829
  * Sign a message, returning signature concatenated with message.
1805
1830
  *
@@ -1835,6 +1860,24 @@ function cryptoSign(msg, sk, randomizedSigning) {
1835
1860
  return sm;
1836
1861
  }
1837
1862
 
1863
+ /**
1864
+ * Attached-form **deterministic** Dilithium5 signing
1865
+ * (`randomizedSigning = false`).
1866
+ *
1867
+ * Convenience wrapper that hard-wires the deterministic mode for the
1868
+ * attached `signature || message` form. Same recommendation as
1869
+ * [cryptoSignSignatureDeterministic]: use only when determinism is a
1870
+ * protocol requirement; for general-purpose signing prefer
1871
+ * [cryptoSign] with `randomizedSigning = true` (hedged — TOB-QRLLIB-6).
1872
+ *
1873
+ * @param {string|Uint8Array} msg - Message to sign
1874
+ * @param {Uint8Array} sk - Secret key
1875
+ * @returns {Uint8Array} Signed message (signature || message)
1876
+ */
1877
+ function cryptoSignDeterministic(msg, sk) {
1878
+ return cryptoSign(msg, sk, /* randomizedSigning */ false);
1879
+ }
1880
+
1838
1881
  /**
1839
1882
  * Verify a detached signature.
1840
1883
  *
@@ -1943,7 +1986,12 @@ function cryptoSignVerify(sig, m, pk) {
1943
1986
  * }
1944
1987
  */
1945
1988
  function cryptoSignOpen(sm, pk) {
1946
- if (sm.length < CryptoBytes) {
1989
+ // Type-guard `sm` so callers passing `null` / `undefined` / non-Uint8Array
1990
+ // get a clean `undefined` return rather than a `Cannot read properties of
1991
+ // null (reading 'length')` thrown deep in the call chain. Mirrors the
1992
+ // existing `pk` / `sig` instanceof checks in `cryptoSignVerify`.
1993
+ // (TOB-QRLLIB-11.)
1994
+ if (!(sm instanceof Uint8Array) || sm.length < CryptoBytes) {
1947
1995
  return undefined;
1948
1996
  }
1949
1997
 
@@ -1956,6 +2004,37 @@ function cryptoSignOpen(sm, pk) {
1956
2004
  return msg;
1957
2005
  }
1958
2006
 
2007
+ /**
2008
+ * Open a signed message with a typed failure-mode report.
2009
+ *
2010
+ * Behavioural twin of [cryptoSignOpen], but returns a discriminated
2011
+ * union so callers can distinguish between API-shape problems (input
2012
+ * was the wrong type / length / shape) and genuine cryptographic
2013
+ * verification failures. See the ML-DSA-87 sibling for the rationale
2014
+ * (TOB-QRLLIB-14).
2015
+ *
2016
+ * @param {Uint8Array} sm Signed message (signature || message).
2017
+ * @param {Uint8Array} pk Public key.
2018
+ * @returns {{ok: true, message: Uint8Array} | {ok: false, reason: 'invalid-sm-type'|'invalid-sm-length'|'invalid-pk'|'verification-failed'}}
2019
+ */
2020
+ function cryptoSignOpenWithReason(sm, pk) {
2021
+ if (!(sm instanceof Uint8Array)) {
2022
+ return { ok: false, reason: 'invalid-sm-type' };
2023
+ }
2024
+ if (sm.length < CryptoBytes) {
2025
+ return { ok: false, reason: 'invalid-sm-length' };
2026
+ }
2027
+ if (!(pk instanceof Uint8Array) || pk.length !== CryptoPublicKeyBytes) {
2028
+ return { ok: false, reason: 'invalid-pk' };
2029
+ }
2030
+ const sig = sm.slice(0, CryptoBytes);
2031
+ const msg = sm.slice(CryptoBytes);
2032
+ if (!cryptoSignVerify(sig, msg, pk)) {
2033
+ return { ok: false, reason: 'verification-failed' };
2034
+ }
2035
+ return { ok: true, message: msg };
2036
+ }
2037
+
1959
2038
  exports.BETA = BETA;
1960
2039
  exports.CRHBytes = CRHBytes;
1961
2040
  exports.CryptoBytes = CryptoBytes;
@@ -1993,9 +2072,12 @@ exports.TAU = TAU;
1993
2072
  exports.TRBytes = TRBytes;
1994
2073
  exports.cAddQ = cAddQ;
1995
2074
  exports.cryptoSign = cryptoSign;
2075
+ exports.cryptoSignDeterministic = cryptoSignDeterministic;
1996
2076
  exports.cryptoSignKeypair = cryptoSignKeypair;
1997
2077
  exports.cryptoSignOpen = cryptoSignOpen;
2078
+ exports.cryptoSignOpenWithReason = cryptoSignOpenWithReason;
1998
2079
  exports.cryptoSignSignature = cryptoSignSignature;
2080
+ exports.cryptoSignSignatureDeterministic = cryptoSignSignatureDeterministic;
1999
2081
  exports.cryptoSignVerify = cryptoSignVerify;
2000
2082
  exports.decompose = decompose;
2001
2083
  exports.dilithiumShake128StreamInit = dilithiumShake128StreamInit;
@@ -83,6 +83,31 @@ export function cryptoSign(
83
83
  randomizedSigning: boolean
84
84
  ): Uint8Array;
85
85
 
86
+ /**
87
+ * Create a deterministic Dilithium5 detached signature
88
+ * (`randomizedSigning = false` wrapper for `cryptoSignSignature`).
89
+ *
90
+ * **Use only when the deterministic property is itself a requirement**.
91
+ * For general-purpose signing prefer `cryptoSignSignature` with
92
+ * `randomizedSigning = true` (hedged — TOB-QRLLIB-6).
93
+ */
94
+ export function cryptoSignSignatureDeterministic(
95
+ sig: Uint8Array,
96
+ m: Uint8Array | string,
97
+ sk: Uint8Array
98
+ ): number;
99
+
100
+ /**
101
+ * Attached-form deterministic Dilithium5 signing
102
+ * (`randomizedSigning = false` wrapper for `cryptoSign`).
103
+ * Same recommendation as `cryptoSignSignatureDeterministic`.
104
+ * (TOB-QRLLIB-6.)
105
+ */
106
+ export function cryptoSignDeterministic(
107
+ msg: Uint8Array | string,
108
+ sk: Uint8Array
109
+ ): Uint8Array;
110
+
86
111
  /**
87
112
  * Verify a signature
88
113
  * @param sig - Signature to verify
@@ -100,13 +125,46 @@ export function cryptoSignVerify(
100
125
  * Open a signed message (verify and extract message)
101
126
  * @param sm - Signed message (signature || message)
102
127
  * @param pk - Public key
103
- * @returns Message if valid, undefined if verification fails
128
+ * @returns Message if valid, undefined if verification fails (or if
129
+ * sm is null / undefined / non-Uint8Array / shorter than
130
+ * CryptoBytes — see `cryptoSignOpenWithReason` for distinct
131
+ * failure-mode reporting)
104
132
  */
105
133
  export function cryptoSignOpen(
106
134
  sm: Uint8Array,
107
135
  pk: Uint8Array
108
136
  ): Uint8Array | undefined;
109
137
 
138
+ /**
139
+ * Failure-mode discriminator returned by `cryptoSignOpenWithReason`.
140
+ * (TOB-QRLLIB-14: distinct failure modes for Open.)
141
+ */
142
+ export type CryptoSignOpenReason =
143
+ | 'invalid-sm-type'
144
+ | 'invalid-sm-length'
145
+ | 'invalid-pk'
146
+ | 'verification-failed';
147
+
148
+ /**
149
+ * Open a signed message with a typed failure-mode report.
150
+ * (TOB-QRLLIB-14.) Behavioural twin of `cryptoSignOpen` that
151
+ * distinguishes API-shape problems (input wrong type / length /
152
+ * shape) from genuine verification failures.
153
+ *
154
+ * `cryptoSignOpen` is kept unchanged and continues to return
155
+ * `undefined` for any failure mode. Use this variant when you need
156
+ * to log or route on specific failure modes.
157
+ *
158
+ * @param sm - Signed message (signature || message)
159
+ * @param pk - Public key
160
+ */
161
+ export function cryptoSignOpenWithReason(
162
+ sm: Uint8Array,
163
+ pk: Uint8Array
164
+ ):
165
+ | { ok: true; message: Uint8Array }
166
+ | { ok: false; reason: CryptoSignOpenReason };
167
+
110
168
  // Utility functions
111
169
 
112
170
  /**
@@ -1421,6 +1421,31 @@ function cryptoSignSignature(sig, m, sk, randomizedSigning) {
1421
1421
  }
1422
1422
  }
1423
1423
 
1424
+ /**
1425
+ * Create a **deterministic** Dilithium5 detached signature
1426
+ * (`randomizedSigning = false`).
1427
+ *
1428
+ * Convenience wrapper that hard-wires the deterministic mode so callers
1429
+ * who *need* byte-identical signatures for the same `(sk, message)`
1430
+ * — KAT vector reproduction, deterministic-test fixtures, RANDAO-style
1431
+ * protocols — get a clearly-named entry point rather than passing a
1432
+ * bare boolean.
1433
+ *
1434
+ * **Use only when the deterministic property is itself a requirement.**
1435
+ * For general-purpose signing prefer [cryptoSignSignature] with
1436
+ * `randomizedSigning = true` (hedged signing — TOB-QRLLIB-6 audit
1437
+ * recommendation for parity with the lattice-scheme guidance applied
1438
+ * to the Go and Rust ports).
1439
+ *
1440
+ * @param {Uint8Array} sig - Output buffer for signature (must be at least CryptoBytes bytes)
1441
+ * @param {string|Uint8Array} m - Message to sign
1442
+ * @param {Uint8Array} sk - Secret key (must be CryptoSecretKeyBytes bytes)
1443
+ * @returns {number} 0 on success
1444
+ */
1445
+ function cryptoSignSignatureDeterministic(sig, m, sk) {
1446
+ return cryptoSignSignature(sig, m, sk, /* randomizedSigning */ false);
1447
+ }
1448
+
1424
1449
  /**
1425
1450
  * Sign a message, returning signature concatenated with message.
1426
1451
  *
@@ -1456,6 +1481,24 @@ function cryptoSign(msg, sk, randomizedSigning) {
1456
1481
  return sm;
1457
1482
  }
1458
1483
 
1484
+ /**
1485
+ * Attached-form **deterministic** Dilithium5 signing
1486
+ * (`randomizedSigning = false`).
1487
+ *
1488
+ * Convenience wrapper that hard-wires the deterministic mode for the
1489
+ * attached `signature || message` form. Same recommendation as
1490
+ * [cryptoSignSignatureDeterministic]: use only when determinism is a
1491
+ * protocol requirement; for general-purpose signing prefer
1492
+ * [cryptoSign] with `randomizedSigning = true` (hedged — TOB-QRLLIB-6).
1493
+ *
1494
+ * @param {string|Uint8Array} msg - Message to sign
1495
+ * @param {Uint8Array} sk - Secret key
1496
+ * @returns {Uint8Array} Signed message (signature || message)
1497
+ */
1498
+ function cryptoSignDeterministic(msg, sk) {
1499
+ return cryptoSign(msg, sk, /* randomizedSigning */ false);
1500
+ }
1501
+
1459
1502
  /**
1460
1503
  * Verify a detached signature.
1461
1504
  *
@@ -1564,7 +1607,12 @@ function cryptoSignVerify(sig, m, pk) {
1564
1607
  * }
1565
1608
  */
1566
1609
  function cryptoSignOpen(sm, pk) {
1567
- if (sm.length < CryptoBytes) {
1610
+ // Type-guard `sm` so callers passing `null` / `undefined` / non-Uint8Array
1611
+ // get a clean `undefined` return rather than a `Cannot read properties of
1612
+ // null (reading 'length')` thrown deep in the call chain. Mirrors the
1613
+ // existing `pk` / `sig` instanceof checks in `cryptoSignVerify`.
1614
+ // (TOB-QRLLIB-11.)
1615
+ if (!(sm instanceof Uint8Array) || sm.length < CryptoBytes) {
1568
1616
  return undefined;
1569
1617
  }
1570
1618
 
@@ -1577,4 +1625,35 @@ function cryptoSignOpen(sm, pk) {
1577
1625
  return msg;
1578
1626
  }
1579
1627
 
1580
- export { BETA, CRHBytes, CryptoBytes, CryptoPublicKeyBytes, CryptoSecretKeyBytes, D, ETA, GAMMA1, GAMMA2, K, KeccakState, L, N, OMEGA, Poly, PolyETAPackedBytes, PolyT0PackedBytes, PolyT1PackedBytes, PolyUniformETANBlocks, PolyUniformGamma1NBlocks, PolyUniformNBlocks, PolyVecHPackedBytes, PolyVecK, PolyVecL, PolyW1PackedBytes, PolyZPackedBytes, Q, QInv, SeedBytes, Shake128Rate, Shake256Rate, Stream128BlockBytes, Stream256BlockBytes, TAU, TRBytes, cAddQ, cryptoSign, cryptoSignKeypair, cryptoSignOpen, cryptoSignSignature, cryptoSignVerify, decompose, dilithiumShake128StreamInit, dilithiumShake256StreamInit, invNTTToMont, isZero, makeHint, montgomeryReduce, ntt, packPk, packSig, packSk, polyAdd, polyCAddQ, polyChallenge, polyChkNorm, polyDecompose, polyEtaPack, polyEtaUnpack, polyInvNTTToMont, polyMakeHint, polyNTT, polyPointWiseMontgomery, polyPower2round, polyReduce, polyShiftL, polySub, polyT0Pack, polyT0Unpack, polyT1Pack, polyT1Unpack, polyUniform, polyUniformEta, polyUniformGamma1, polyUseHint, polyVecKAdd, polyVecKCAddQ, polyVecKChkNorm, polyVecKDecompose, polyVecKInvNTTToMont, polyVecKMakeHint, polyVecKNTT, polyVecKPackW1, polyVecKPointWisePolyMontgomery, polyVecKPower2round, polyVecKReduce, polyVecKShiftL, polyVecKSub, polyVecKUniformEta, polyVecKUseHint, polyVecLAdd, polyVecLChkNorm, polyVecLInvNTTToMont, polyVecLNTT, polyVecLPointWiseAccMontgomery, polyVecLPointWisePolyMontgomery, polyVecLReduce, polyVecLUniformEta, polyVecLUniformGamma1, polyVecMatrixExpand, polyVecMatrixPointWiseMontgomery, polyW1Pack, polyZPack, polyZUnpack, power2round, reduce32, rejEta, rejUniform, shake128Absorb, shake128Finalize, shake128Init, shake128SqueezeBlocks, shake256Absorb, shake256Finalize, shake256Init, shake256SqueezeBlocks, unpackPk, unpackSig, unpackSk, useHint, zeroize, zetas };
1628
+ /**
1629
+ * Open a signed message with a typed failure-mode report.
1630
+ *
1631
+ * Behavioural twin of [cryptoSignOpen], but returns a discriminated
1632
+ * union so callers can distinguish between API-shape problems (input
1633
+ * was the wrong type / length / shape) and genuine cryptographic
1634
+ * verification failures. See the ML-DSA-87 sibling for the rationale
1635
+ * (TOB-QRLLIB-14).
1636
+ *
1637
+ * @param {Uint8Array} sm Signed message (signature || message).
1638
+ * @param {Uint8Array} pk Public key.
1639
+ * @returns {{ok: true, message: Uint8Array} | {ok: false, reason: 'invalid-sm-type'|'invalid-sm-length'|'invalid-pk'|'verification-failed'}}
1640
+ */
1641
+ function cryptoSignOpenWithReason(sm, pk) {
1642
+ if (!(sm instanceof Uint8Array)) {
1643
+ return { ok: false, reason: 'invalid-sm-type' };
1644
+ }
1645
+ if (sm.length < CryptoBytes) {
1646
+ return { ok: false, reason: 'invalid-sm-length' };
1647
+ }
1648
+ if (!(pk instanceof Uint8Array) || pk.length !== CryptoPublicKeyBytes) {
1649
+ return { ok: false, reason: 'invalid-pk' };
1650
+ }
1651
+ const sig = sm.slice(0, CryptoBytes);
1652
+ const msg = sm.slice(CryptoBytes);
1653
+ if (!cryptoSignVerify(sig, msg, pk)) {
1654
+ return { ok: false, reason: 'verification-failed' };
1655
+ }
1656
+ return { ok: true, message: msg };
1657
+ }
1658
+
1659
+ export { BETA, CRHBytes, CryptoBytes, CryptoPublicKeyBytes, CryptoSecretKeyBytes, D, ETA, GAMMA1, GAMMA2, K, KeccakState, L, N, OMEGA, Poly, PolyETAPackedBytes, PolyT0PackedBytes, PolyT1PackedBytes, PolyUniformETANBlocks, PolyUniformGamma1NBlocks, PolyUniformNBlocks, PolyVecHPackedBytes, PolyVecK, PolyVecL, PolyW1PackedBytes, PolyZPackedBytes, Q, QInv, SeedBytes, Shake128Rate, Shake256Rate, Stream128BlockBytes, Stream256BlockBytes, TAU, TRBytes, cAddQ, cryptoSign, cryptoSignDeterministic, cryptoSignKeypair, cryptoSignOpen, cryptoSignOpenWithReason, cryptoSignSignature, cryptoSignSignatureDeterministic, cryptoSignVerify, decompose, dilithiumShake128StreamInit, dilithiumShake256StreamInit, invNTTToMont, isZero, makeHint, montgomeryReduce, ntt, packPk, packSig, packSk, polyAdd, polyCAddQ, polyChallenge, polyChkNorm, polyDecompose, polyEtaPack, polyEtaUnpack, polyInvNTTToMont, polyMakeHint, polyNTT, polyPointWiseMontgomery, polyPower2round, polyReduce, polyShiftL, polySub, polyT0Pack, polyT0Unpack, polyT1Pack, polyT1Unpack, polyUniform, polyUniformEta, polyUniformGamma1, polyUseHint, polyVecKAdd, polyVecKCAddQ, polyVecKChkNorm, polyVecKDecompose, polyVecKInvNTTToMont, polyVecKMakeHint, polyVecKNTT, polyVecKPackW1, polyVecKPointWisePolyMontgomery, polyVecKPower2round, polyVecKReduce, polyVecKShiftL, polyVecKSub, polyVecKUniformEta, polyVecKUseHint, polyVecLAdd, polyVecLChkNorm, polyVecLInvNTTToMont, polyVecLNTT, polyVecLPointWiseAccMontgomery, polyVecLPointWisePolyMontgomery, polyVecLReduce, polyVecLUniformEta, polyVecLUniformGamma1, polyVecMatrixExpand, polyVecMatrixPointWiseMontgomery, polyW1Pack, polyZPack, polyZUnpack, power2round, reduce32, rejEta, rejUniform, shake128Absorb, shake128Finalize, shake128Init, shake128SqueezeBlocks, shake256Absorb, shake256Finalize, shake256Init, shake256SqueezeBlocks, unpackPk, unpackSig, unpackSk, useHint, zeroize, zetas };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theqrl/dilithium5",
3
- "version": "1.1.5",
3
+ "version": "1.2.0",
4
4
  "description": "Dilithium-5 cryptography",
5
5
  "keywords": [
6
6
  "dilithium",
package/src/index.d.ts CHANGED
@@ -83,6 +83,31 @@ export function cryptoSign(
83
83
  randomizedSigning: boolean
84
84
  ): Uint8Array;
85
85
 
86
+ /**
87
+ * Create a deterministic Dilithium5 detached signature
88
+ * (`randomizedSigning = false` wrapper for `cryptoSignSignature`).
89
+ *
90
+ * **Use only when the deterministic property is itself a requirement**.
91
+ * For general-purpose signing prefer `cryptoSignSignature` with
92
+ * `randomizedSigning = true` (hedged — TOB-QRLLIB-6).
93
+ */
94
+ export function cryptoSignSignatureDeterministic(
95
+ sig: Uint8Array,
96
+ m: Uint8Array | string,
97
+ sk: Uint8Array
98
+ ): number;
99
+
100
+ /**
101
+ * Attached-form deterministic Dilithium5 signing
102
+ * (`randomizedSigning = false` wrapper for `cryptoSign`).
103
+ * Same recommendation as `cryptoSignSignatureDeterministic`.
104
+ * (TOB-QRLLIB-6.)
105
+ */
106
+ export function cryptoSignDeterministic(
107
+ msg: Uint8Array | string,
108
+ sk: Uint8Array
109
+ ): Uint8Array;
110
+
86
111
  /**
87
112
  * Verify a signature
88
113
  * @param sig - Signature to verify
@@ -100,13 +125,46 @@ export function cryptoSignVerify(
100
125
  * Open a signed message (verify and extract message)
101
126
  * @param sm - Signed message (signature || message)
102
127
  * @param pk - Public key
103
- * @returns Message if valid, undefined if verification fails
128
+ * @returns Message if valid, undefined if verification fails (or if
129
+ * sm is null / undefined / non-Uint8Array / shorter than
130
+ * CryptoBytes — see `cryptoSignOpenWithReason` for distinct
131
+ * failure-mode reporting)
104
132
  */
105
133
  export function cryptoSignOpen(
106
134
  sm: Uint8Array,
107
135
  pk: Uint8Array
108
136
  ): Uint8Array | undefined;
109
137
 
138
+ /**
139
+ * Failure-mode discriminator returned by `cryptoSignOpenWithReason`.
140
+ * (TOB-QRLLIB-14: distinct failure modes for Open.)
141
+ */
142
+ export type CryptoSignOpenReason =
143
+ | 'invalid-sm-type'
144
+ | 'invalid-sm-length'
145
+ | 'invalid-pk'
146
+ | 'verification-failed';
147
+
148
+ /**
149
+ * Open a signed message with a typed failure-mode report.
150
+ * (TOB-QRLLIB-14.) Behavioural twin of `cryptoSignOpen` that
151
+ * distinguishes API-shape problems (input wrong type / length /
152
+ * shape) from genuine verification failures.
153
+ *
154
+ * `cryptoSignOpen` is kept unchanged and continues to return
155
+ * `undefined` for any failure mode. Use this variant when you need
156
+ * to log or route on specific failure modes.
157
+ *
158
+ * @param sm - Signed message (signature || message)
159
+ * @param pk - Public key
160
+ */
161
+ export function cryptoSignOpenWithReason(
162
+ sm: Uint8Array,
163
+ pk: Uint8Array
164
+ ):
165
+ | { ok: true; message: Uint8Array }
166
+ | { ok: false; reason: CryptoSignOpenReason };
167
+
110
168
  // Utility functions
111
169
 
112
170
  /**