@noble/post-quantum 0.6.1 → 0.7.1
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 +191 -104
- package/_crystals.d.ts +8 -3
- package/_crystals.js +38 -10
- package/falcon.d.ts +1 -2
- package/falcon.js +202 -115
- package/hybrid.d.ts +38 -28
- package/hybrid.js +215 -86
- package/index.d.ts +0 -1
- package/index.js +1 -2
- package/ml-dsa.d.ts +31 -5
- package/ml-dsa.js +118 -34
- package/ml-kem.d.ts +45 -4
- package/ml-kem.js +206 -64
- package/package.json +16 -20
- package/slh-dsa.d.ts +23 -3
- package/slh-dsa.js +127 -60
- package/src/_crystals.ts +45 -11
- package/src/falcon.ts +206 -121
- package/src/hybrid.ts +217 -83
- package/src/index.ts +1 -1
- package/src/ml-dsa.ts +140 -43
- package/src/ml-kem.ts +239 -66
- package/src/slh-dsa.ts +149 -69
- package/src/utils.ts +186 -25
- package/src/webcrypto.ts +322 -0
- package/utils.d.ts +54 -4
- package/utils.js +167 -28
- package/webcrypto.d.ts +91 -0
- package/webcrypto.js +213 -0
- package/_crystals.d.ts.map +0 -1
- package/_crystals.js.map +0 -1
- package/falcon.d.ts.map +0 -1
- package/falcon.js.map +0 -1
- package/hybrid.d.ts.map +0 -1
- package/hybrid.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/ml-dsa.d.ts.map +0 -1
- package/ml-dsa.js.map +0 -1
- package/ml-kem.d.ts.map +0 -1
- package/ml-kem.js.map +0 -1
- package/slh-dsa.d.ts.map +0 -1
- package/slh-dsa.js.map +0 -1
- package/utils.d.ts.map +0 -1
- package/utils.js.map +0 -1
package/hybrid.d.ts
CHANGED
|
@@ -84,6 +84,12 @@ type CurveSign = ECDSA | EdDSA;
|
|
|
84
84
|
/**
|
|
85
85
|
* Wraps an ECDH-capable curve as a KEM.
|
|
86
86
|
* Shared secrets stay in the wrapped curve's raw ECDH byte format with no built-in KDF.
|
|
87
|
+
*
|
|
88
|
+
* SECURITY: this is a low-level component adapter, not a standalone IND-CCA-secure KEM. It does
|
|
89
|
+
* not bind the encapsulation or recipient public key into the secret, so distinct accepted point
|
|
90
|
+
* encodings can produce the same output. Use it only inside a construction whose specified
|
|
91
|
+
* combiner binds those values, or use a standardized DHKEM with labeled extract-and-expand.
|
|
92
|
+
*
|
|
87
93
|
* On SEC 1 / Weierstrass curves, that means the compressed shared-point body without the
|
|
88
94
|
* 1-byte `0x02` / `0x03` prefix.
|
|
89
95
|
* The X25519 path also leaves RFC 7748's optional all-zero shared-secret check to callers.
|
|
@@ -99,12 +105,12 @@ type CurveSign = ECDSA | EdDSA;
|
|
|
99
105
|
* Wrap an ECDH-capable curve as a generic KEM.
|
|
100
106
|
* ```ts
|
|
101
107
|
* import { x25519 } from '@noble/curves/ed25519.js';
|
|
102
|
-
* import {
|
|
103
|
-
* const kem =
|
|
108
|
+
* import { _ecdhKem } from '@noble/post-quantum/hybrid.js';
|
|
109
|
+
* const kem = _ecdhKem(x25519);
|
|
104
110
|
* const publicKeyLen = kem.lengths.publicKey;
|
|
105
111
|
* ```
|
|
106
112
|
*/
|
|
107
|
-
export declare function
|
|
113
|
+
export declare function _ecdhKem(curve: CurveECDH, allowZeroKey?: boolean): TRet<KEM>;
|
|
108
114
|
/**
|
|
109
115
|
* Wraps a curve signer as a generic `Signer`.
|
|
110
116
|
* Signatures stay in the wrapped curve's native byte encoding.
|
|
@@ -151,12 +157,18 @@ export declare function expandSeedXof(xof: TArg<XOF>): TRet<ExpandSeed>;
|
|
|
151
157
|
export type Combiner = (publicKeys: TArg<Uint8Array[]>, cipherTexts: TArg<Uint8Array[]>, sharedSecrets: TArg<Uint8Array[]>) => TRet<Uint8Array>;
|
|
152
158
|
/**
|
|
153
159
|
* Combines multiple KEMs into one composite KEM.
|
|
154
|
-
* @param realSeedLen -
|
|
155
|
-
*
|
|
160
|
+
* @param realSeedLen - Positive input seed length expected by `expandSeed`, or `undefined` to use
|
|
161
|
+
* the sum of component seed lengths. Callers remain responsible for choosing a security-appropriate
|
|
162
|
+
* size.
|
|
163
|
+
* @param realMsgLen - Positive shared-secret length returned by `combiner`, or `undefined` to use
|
|
164
|
+
* the sum of component message lengths.
|
|
156
165
|
* @param expandSeed - Seed expander used to derive per-KEM seeds.
|
|
157
166
|
* @param combiner - Combines the per-KEM outputs into one shared secret.
|
|
158
|
-
* @param kems - KEM
|
|
167
|
+
* @param kems - At least one KEM implementation. A construction advertised as hybrid normally
|
|
168
|
+
* supplies two or more.
|
|
159
169
|
* @returns Composite KEM.
|
|
170
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
171
|
+
* @throws If there are no components or any required length resolves to zero. {@link RangeError}
|
|
160
172
|
* @example
|
|
161
173
|
* Combine multiple KEMs into one composite KEM.
|
|
162
174
|
* ```ts
|
|
@@ -179,10 +191,15 @@ realMsgLen: number | undefined, // how much bytes combiner returns
|
|
|
179
191
|
expandSeed: TArg<ExpandSeed>, combiner: TArg<Combiner>, ...kems: TArg<KEM[]>): TRet<KEM>;
|
|
180
192
|
/**
|
|
181
193
|
* Combines multiple signers into one composite signer.
|
|
182
|
-
* @param realSeedLen -
|
|
194
|
+
* @param realSeedLen - Positive input seed length expected by `expandSeed`, or `undefined` to use
|
|
195
|
+
* the sum of component seed lengths. Callers remain responsible for choosing a security-appropriate
|
|
196
|
+
* size.
|
|
183
197
|
* @param expandSeed - Seed expander used to derive per-signer seeds.
|
|
184
|
-
* @param signers -
|
|
198
|
+
* @param signers - At least one signer. A construction advertised as hybrid normally supplies two
|
|
199
|
+
* or more.
|
|
185
200
|
* @returns Composite signer.
|
|
201
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
202
|
+
* @throws If there are no components or any required length resolves to zero. {@link RangeError}
|
|
186
203
|
* @example
|
|
187
204
|
* Combine multiple signers into one composite signer.
|
|
188
205
|
* ```ts
|
|
@@ -190,7 +207,11 @@ expandSeed: TArg<ExpandSeed>, combiner: TArg<Combiner>, ...kems: TArg<KEM[]>): T
|
|
|
190
207
|
* import { combineSigners, expandSeedXof } from '@noble/post-quantum/hybrid.js';
|
|
191
208
|
* import { ml_dsa44 } from '@noble/post-quantum/ml-dsa.js';
|
|
192
209
|
* const hybrid = combineSigners(32, expandSeedXof(shake256), ml_dsa44, ml_dsa44);
|
|
193
|
-
* const
|
|
210
|
+
* const seed = new Uint8Array(hybrid.lengths.seed!).fill(1);
|
|
211
|
+
* const { secretKey, publicKey } = hybrid.keygen(seed);
|
|
212
|
+
* const msg = new TextEncoder().encode('hello noble');
|
|
213
|
+
* const sig = hybrid.sign(msg, secretKey);
|
|
214
|
+
* const isValid = hybrid.verify(sig, msg, publicKey);
|
|
194
215
|
* ```
|
|
195
216
|
*/
|
|
196
217
|
export declare function combineSigners(realSeedLen: number | undefined, expandSeed: TArg<ExpandSeed>, ...signers: TArg<Signer[]>): TRet<Signer>;
|
|
@@ -207,14 +228,16 @@ export declare function combineSigners(realSeedLen: number | undefined, expandSe
|
|
|
207
228
|
* @param xof - XOF used for seed expansion.
|
|
208
229
|
* @param kdf - Hash used for the final combiner.
|
|
209
230
|
* @returns Hybrid KEM.
|
|
231
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
232
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
210
233
|
* @example
|
|
211
234
|
* Build a QSF hybrid KEM preset from a PQ KEM and an elliptic-curve KEM.
|
|
212
235
|
* ```ts
|
|
213
236
|
* import { p256 } from '@noble/curves/nist.js';
|
|
214
237
|
* import { sha3_256, shake256 } from '@noble/hashes/sha3.js';
|
|
215
|
-
* import { QSF,
|
|
238
|
+
* import { QSF, _ecdhKem } from '@noble/post-quantum/hybrid.js';
|
|
216
239
|
* import { ml_kem768 } from '@noble/post-quantum/ml-kem.js';
|
|
217
|
-
* const kem = QSF('example', ml_kem768,
|
|
240
|
+
* const kem = QSF('example', ml_kem768, _ecdhKem(p256, true), shake256, sha3_256);
|
|
218
241
|
* const publicKeyLen = kem.lengths.publicKey;
|
|
219
242
|
* ```
|
|
220
243
|
*/
|
|
@@ -237,15 +260,17 @@ export declare const QSF_ml_kem1024_p384: TRet<KEM>;
|
|
|
237
260
|
* @param xof - XOF used for seed expansion.
|
|
238
261
|
* @param hash - Hash used for HKDF extraction and expansion.
|
|
239
262
|
* @returns Hybrid KEM.
|
|
263
|
+
* @throws On wrong argument types. {@link TypeError}
|
|
264
|
+
* @throws On wrong argument ranges or values. {@link RangeError}
|
|
240
265
|
* @example
|
|
241
266
|
* Build the "KitchenSink" hybrid KEM combiner.
|
|
242
267
|
* ```ts
|
|
243
268
|
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
244
269
|
* import { shake256 } from '@noble/hashes/sha3.js';
|
|
245
|
-
* import { createKitchenSink,
|
|
270
|
+
* import { createKitchenSink, _ecdhKem } from '@noble/post-quantum/hybrid.js';
|
|
246
271
|
* import { ml_kem768 } from '@noble/post-quantum/ml-kem.js';
|
|
247
272
|
* import { x25519 } from '@noble/curves/ed25519.js';
|
|
248
|
-
* const kem = createKitchenSink('example', ml_kem768,
|
|
273
|
+
* const kem = createKitchenSink('example', ml_kem768, _ecdhKem(x25519), shake256, sha256);
|
|
249
274
|
* const publicKeyLen = kem.lengths.publicKey;
|
|
250
275
|
* ```
|
|
251
276
|
*/
|
|
@@ -263,19 +288,4 @@ export declare const ml_kem768_x25519: TRet<KEM>;
|
|
|
263
288
|
export declare const ml_kem768_p256: TRet<KEM>;
|
|
264
289
|
/** P-384 + ML-KEM-1024 hybrid preset. */
|
|
265
290
|
export declare const ml_kem1024_p384: TRet<KEM>;
|
|
266
|
-
/** Legacy alias for `ml_kem768_x25519`. */
|
|
267
|
-
export declare const XWing: TRet<KEM>;
|
|
268
|
-
/** Legacy alias for `ml_kem768_x25519`. */
|
|
269
|
-
export declare const MLKEM768X25519: TRet<KEM>;
|
|
270
|
-
/** Legacy alias for `ml_kem768_p256`. */
|
|
271
|
-
export declare const MLKEM768P256: TRet<KEM>;
|
|
272
|
-
/** Legacy alias for `ml_kem1024_p384`. */
|
|
273
|
-
export declare const MLKEM1024P384: TRet<KEM>;
|
|
274
|
-
/** Legacy alias for `QSF_ml_kem768_p256`. */
|
|
275
|
-
export declare const QSFMLKEM768P256: TRet<KEM>;
|
|
276
|
-
/** Legacy alias for `QSF_ml_kem1024_p384`. */
|
|
277
|
-
export declare const QSFMLKEM1024P384: TRet<KEM>;
|
|
278
|
-
/** Legacy alias for `KitchenSink_ml_kem768_x25519`. */
|
|
279
|
-
export declare const KitchenSinkMLKEM768X25519: TRet<KEM>;
|
|
280
291
|
export {};
|
|
281
|
-
//# sourceMappingURL=hybrid.d.ts.map
|