hpke 1.0.3 → 1.0.5

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/index.js CHANGED
@@ -42,50 +42,53 @@
42
42
 
43
43
 
44
44
 
45
- function ComputeNonce(base_nonce , seq , Nn ) {
46
- const seq_bytes = I2OSP(seq, Nn)
47
- return xor(base_nonce, seq_bytes)
48
- }
49
45
 
50
- function IncrementSeq(seq ) {
51
46
 
52
47
 
53
48
 
54
- if (seq >= Number.MAX_SAFE_INTEGER) {
55
- throw new MessageLimitReachedError('Sequence number overflow')
56
- }
57
- return ++seq
58
- }
59
49
 
60
- async function ContextExport(
61
- suite ,
62
- exporterSecret ,
63
- exporterContext ,
64
- L ,
65
- ) {
66
- checkUint8Array(exporterContext, 'exporterContext')
67
- const stages = KDFStages(suite.KDF)
68
- if (!Number.isInteger(L) || L <= 0 || L > 0xffff) {
69
- throw new TypeError('"L" must be a positive integer not exceeding 65535')
70
- }
71
- const Export = stages === 1 ? ExportOneStage : ExportTwoStage
72
- return await Export(suite.KDF, suite.id, exporterSecret, exporterContext, L)
73
- }
74
50
 
75
- class Mutex {
76
- #locked = Promise.resolve()
77
-
78
- async lock() {
79
- let releaseLock
80
- const nextLock = new Promise ((resolve) => {
81
- releaseLock = resolve
82
- })
83
- const previousLock = this.#locked
84
- this.#locked = nextLock
85
- await previousLock
86
- return releaseLock
87
- }
88
- }
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
89
92
 
90
93
 
91
94
 
@@ -170,6 +173,7 @@ class SenderContext {
170
173
 
171
174
 
172
175
 
176
+
173
177
 
174
178
 
175
179
  async Seal(plaintext , aad ) {
@@ -217,6 +221,7 @@ class SenderContext {
217
221
 
218
222
 
219
223
 
224
+
220
225
 
221
226
 
222
227
  async Export(exporterContext , length ) {
@@ -317,6 +322,7 @@ class RecipientContext {
317
322
 
318
323
 
319
324
 
325
+
320
326
 
321
327
 
322
328
  async Open(ciphertext , aad ) {
@@ -373,6 +379,7 @@ class RecipientContext {
373
379
 
374
380
 
375
381
 
382
+
376
383
 
377
384
 
378
385
  async Export(exporterContext , length ) {
@@ -796,6 +803,7 @@ export class CipherSuite {
796
803
 
797
804
 
798
805
 
806
+
799
807
 
800
808
 
801
809
  async Seal(
@@ -844,6 +852,7 @@ export class CipherSuite {
844
852
 
845
853
 
846
854
 
855
+
847
856
 
848
857
 
849
858
  async Open(
@@ -891,6 +900,7 @@ export class CipherSuite {
891
900
 
892
901
 
893
902
 
903
+
894
904
 
895
905
 
896
906
  async SendExport(
@@ -938,6 +948,7 @@ export class CipherSuite {
938
948
 
939
949
 
940
950
 
951
+
941
952
 
942
953
 
943
954
  async ReceiveExport(
@@ -991,6 +1002,7 @@ export class CipherSuite {
991
1002
 
992
1003
 
993
1004
 
1005
+
994
1006
 
995
1007
 
996
1008
  async SetupSender(
@@ -1071,6 +1083,7 @@ export class CipherSuite {
1071
1083
 
1072
1084
 
1073
1085
 
1086
+
1074
1087
 
1075
1088
 
1076
1089
  async SetupRecipient(
@@ -1258,6 +1271,8 @@ export class NotSupportedError extends Error {
1258
1271
 
1259
1272
 
1260
1273
 
1274
+
1275
+
1261
1276
  export const MODE_BASE = 0x00
1262
1277
 
1263
1278
 
@@ -1267,6 +1282,8 @@ export const MODE_BASE = 0x00
1267
1282
 
1268
1283
 
1269
1284
 
1285
+
1286
+
1270
1287
  export const MODE_PSK = 0x01
1271
1288
 
1272
1289
 
@@ -1474,6 +1491,7 @@ function lengthPrefixed(x ) {
1474
1491
 
1475
1492
 
1476
1493
 
1494
+
1477
1495
 
1478
1496
 
1479
1497
  export async function LabeledDerive(
@@ -1495,129 +1513,134 @@ export async function LabeledDerive(
1495
1513
  return await KDF.Derive(labeled_ikm, L)
1496
1514
  }
1497
1515
 
1498
- async function ExportOneStage(
1499
- KDF ,
1500
- suite_id ,
1501
- exporter_secret ,
1502
- exporter_context ,
1503
- L ,
1504
- ) {
1505
- checkLength(exporter_context, 'Exporter context', MAX_LENGTH_ONE_STAGE)
1506
- return await LabeledDerive(KDF, suite_id, exporter_secret, encode('sec'), exporter_context, L)
1507
- }
1508
1516
 
1509
- async function CombineSecretsOneStage(
1510
- suite ,
1511
- mode ,
1512
- shared_secret ,
1513
- info ,
1514
- psk ,
1515
- psk_id ,
1516
- ) {
1517
- checkLength(psk, 'PSK', MAX_LENGTH_ONE_STAGE)
1518
- checkLength(psk_id, 'PSK ID', MAX_LENGTH_ONE_STAGE)
1519
- checkLength(info, 'Info', MAX_LENGTH_ONE_STAGE)
1520
-
1521
- const secrets = concat(lengthPrefixed(psk), lengthPrefixed(shared_secret))
1522
- const context = concat(I2OSP(mode, 1), lengthPrefixed(psk_id), lengthPrefixed(info))
1523
-
1524
- const secret = await LabeledDerive(
1525
- suite.KDF,
1526
- suite.id,
1527
- secrets,
1528
- encode('secret'),
1529
- context,
1530
- suite.AEAD.Nk + suite.AEAD.Nn + suite.KDF.Nh,
1531
- )
1532
1517
 
1533
- const key = slice(secret, 0, suite.AEAD.Nk)
1534
- const base_nonce = slice(secret, suite.AEAD.Nk, suite.AEAD.Nk + suite.AEAD.Nn)
1535
- const exporter_secret = slice(secret, suite.AEAD.Nk + suite.AEAD.Nn)
1536
1518
 
1537
- return { key, base_nonce, exporter_secret }
1538
- }
1539
1519
 
1540
1520
 
1541
1521
 
1542
- const MAX_LENGTH_TWO_STAGE = 0xffff
1543
1522
 
1544
- const MAX_LENGTH_ONE_STAGE = 0xffff
1545
1523
 
1546
- function checkLength(data , name , maxLength ) {
1547
- if (data.byteLength > maxLength) {
1548
- throw new TypeError(`${name} length must not exceed ${maxLength} bytes`)
1549
- }
1550
- }
1551
- function checkUint8Array(input , name ) {
1552
- if (!(input instanceof Uint8Array)) {
1553
- throw new TypeError(`"${name}" must be Uint8Array`)
1554
- }
1555
- }
1556
- function checkExtractable(extractable ) {
1557
- if (typeof extractable !== 'boolean') {
1558
- throw new TypeError('"extractable" must be boolean')
1559
- }
1560
- }
1561
1524
 
1562
- async function CombineSecretsTwoStage(
1563
- suite ,
1564
- mode ,
1565
- shared_secret ,
1566
- info ,
1567
- psk ,
1568
- psk_id ,
1569
- ) {
1570
- checkLength(psk, 'PSK', MAX_LENGTH_TWO_STAGE)
1571
- checkLength(psk_id, 'PSK ID', MAX_LENGTH_TWO_STAGE)
1572
- checkLength(info, 'Info', MAX_LENGTH_TWO_STAGE)
1573
-
1574
- const [psk_id_hash, info_hash] = await Promise.all([
1575
- LabeledExtract(suite.KDF, suite.id, new Uint8Array(), encode('psk_id_hash'), psk_id),
1576
- LabeledExtract(suite.KDF, suite.id, new Uint8Array(), encode('info_hash'), info),
1577
- ])
1578
-
1579
- const key_schedule_context = concat(I2OSP(mode, 1), psk_id_hash, info_hash)
1580
- const secret = await LabeledExtract(suite.KDF, suite.id, shared_secret, encode('secret'), psk)
1581
-
1582
-
1583
- if (suite.AEAD.id === EXPORT_ONLY) {
1584
- const exporter_secret = await LabeledExpand(
1585
- suite.KDF,
1586
- suite.id,
1587
- secret,
1588
- encode('exp'),
1589
- key_schedule_context,
1590
- suite.KDF.Nh,
1591
- )
1592
- return { key: new Uint8Array(), base_nonce: new Uint8Array(), exporter_secret }
1593
- }
1594
1525
 
1595
- const [key, base_nonce, exporter_secret] = await Promise.all([
1596
- LabeledExpand(suite.KDF, suite.id, secret, encode('key'), key_schedule_context, suite.AEAD.Nk),
1597
- LabeledExpand(
1598
- suite.KDF,
1599
- suite.id,
1600
- secret,
1601
- encode('base_nonce'),
1602
- key_schedule_context,
1603
- suite.AEAD.Nn,
1604
- ),
1605
- LabeledExpand(suite.KDF, suite.id, secret, encode('exp'), key_schedule_context, suite.KDF.Nh),
1606
- ])
1607
-
1608
- return { key, base_nonce, exporter_secret }
1609
- }
1610
1526
 
1611
- async function ExportTwoStage(
1612
- KDF ,
1613
- suite_id ,
1614
- exporter_secret ,
1615
- exporter_context ,
1616
- L ,
1617
- ) {
1618
- checkLength(exporter_context, 'Exporter context', MAX_LENGTH_TWO_STAGE)
1619
- return await LabeledExpand(KDF, suite_id, exporter_secret, encode('sec'), exporter_context, L)
1620
- }
1527
+
1528
+
1529
+
1530
+
1531
+
1532
+
1533
+
1534
+
1535
+
1536
+
1537
+
1538
+
1539
+
1540
+
1541
+
1542
+
1543
+
1544
+
1545
+
1546
+
1547
+
1548
+
1549
+
1550
+
1551
+
1552
+
1553
+
1554
+
1555
+
1556
+
1557
+
1558
+
1559
+
1560
+
1561
+
1562
+
1563
+
1564
+
1565
+
1566
+
1567
+
1568
+
1569
+
1570
+
1571
+
1572
+
1573
+
1574
+
1575
+
1576
+
1577
+
1578
+
1579
+
1580
+
1581
+
1582
+
1583
+
1584
+
1585
+
1586
+
1587
+
1588
+
1589
+
1590
+
1591
+
1592
+
1593
+
1594
+
1595
+
1596
+
1597
+
1598
+
1599
+
1600
+
1601
+
1602
+
1603
+
1604
+
1605
+
1606
+
1607
+
1608
+
1609
+
1610
+
1611
+
1612
+
1613
+
1614
+
1615
+
1616
+
1617
+
1618
+
1619
+
1620
+
1621
+
1622
+
1623
+
1624
+
1625
+
1626
+
1627
+
1628
+
1629
+
1630
+
1631
+
1632
+
1633
+
1634
+
1635
+
1636
+
1637
+
1638
+
1639
+
1640
+
1641
+
1642
+
1643
+
1621
1644
 
1622
1645
 
1623
1646
 
@@ -1787,6 +1810,7 @@ export async function LabeledExtract(
1787
1810
 
1788
1811
 
1789
1812
 
1813
+
1790
1814
  export async function LabeledExpand(
1791
1815
  KDF ,
1792
1816
  suite_id ,
@@ -2155,6 +2179,7 @@ function isKey(key , type , extractable )
2155
2179
 
2156
2180
 
2157
2181
 
2182
+
2158
2183
 
2159
2184
 
2160
2185
  export function I2OSP(n , w ) {
@@ -2185,40 +2210,42 @@ function KDFStages(KDF ) {
2185
2210
  throw new Error('unreachable')
2186
2211
  }
2187
2212
 
2188
- async function KeySchedule(
2189
- suite ,
2190
- mode ,
2191
- shared_secret ,
2192
- info ,
2193
- psk ,
2194
- pskId ,
2195
- ) {
2196
- info ??= new Uint8Array()
2197
- checkUint8Array(info, 'info')
2198
- psk ??= new Uint8Array()
2199
- checkUint8Array(psk, 'psk')
2200
- pskId ??= new Uint8Array()
2201
- checkUint8Array(pskId, 'pskId')
2202
-
2203
- const stages = KDFStages(suite.KDF)
2204
- const CombineSecrets = stages === 1 ? CombineSecretsOneStage : CombineSecretsTwoStage
2205
-
2206
- VerifyPSKInputs(psk, pskId)
2207
- return await CombineSecrets(suite, mode, shared_secret, info, psk, pskId)
2208
- }
2209
2213
 
2210
- function VerifyPSKInputs(psk , psk_id ) {
2211
- if (psk.byteLength && psk_id.byteLength) {
2212
- if (psk.byteLength < 32) {
2213
- throw new TypeError('Insufficient PSK length')
2214
- }
2215
- return
2216
- }
2217
- if (!psk.byteLength && !psk_id.byteLength) {
2218
- return
2219
- }
2220
- throw new TypeError('Inconsistent PSK inputs')
2221
- }
2214
+
2215
+
2216
+
2217
+
2218
+
2219
+
2220
+
2221
+
2222
+
2223
+
2224
+
2225
+
2226
+
2227
+
2228
+
2229
+
2230
+
2231
+
2232
+
2233
+
2234
+
2235
+
2236
+
2237
+
2238
+
2239
+
2240
+
2241
+
2242
+
2243
+
2244
+
2245
+
2246
+
2247
+
2248
+
2222
2249
 
2223
2250
 
2224
2251
  const NotApplicable = () => {
@@ -2237,6 +2264,7 @@ const EXPORT_ONLY = 0xffff
2237
2264
 
2238
2265
 
2239
2266
 
2267
+
2240
2268
  export const AEAD_EXPORT_ONLY = function () {
2241
2269
  return {
2242
2270
  id: EXPORT_ONLY,
@@ -2366,6 +2394,7 @@ function HKDF_SHARED() {
2366
2394
 
2367
2395
 
2368
2396
 
2397
+
2369
2398
 
2370
2399
 
2371
2400
  export const KDF_HKDF_SHA256 = function () {
@@ -2390,6 +2419,7 @@ export const KDF_HKDF_SHA256 = function () {
2390
2419
 
2391
2420
 
2392
2421
 
2422
+
2393
2423
  export const KDF_HKDF_SHA384 = function () {
2394
2424
  return { id: 0x0002, type: 'KDF', name: 'HKDF-SHA384', Nh: 48, hash: 'SHA-384', ...HKDF_SHARED() }
2395
2425
  }
@@ -2412,6 +2442,7 @@ export const KDF_HKDF_SHA384 = function () {
2412
2442
 
2413
2443
 
2414
2444
 
2445
+
2415
2446
  export const KDF_HKDF_SHA512 = function () {
2416
2447
  return { id: 0x0003, type: 'KDF', name: 'HKDF-SHA512', Nh: 64, hash: 'SHA-512', ...HKDF_SHARED() }
2417
2448
  }
@@ -2425,7 +2456,8 @@ export const KDF_HKDF_SHA512 = function () {
2425
2456
 
2426
2457
 
2427
2458
  async function ShakeDerive(name , variant , ikm , L ) {
2428
- const alg = { name: variant, length: L << 3 }
2459
+ const bits = L << 3
2460
+ const alg = { name: variant, length: bits, outputLength: bits }
2429
2461
  return new Uint8Array(await subtle((c) => c.digest(alg, ikm), name))
2430
2462
  }
2431
2463
 
@@ -2458,6 +2490,7 @@ function SHAKE_SHARED() {
2458
2490
 
2459
2491
 
2460
2492
 
2493
+
2461
2494
  export const KDF_SHAKE128 = function () {
2462
2495
  return {
2463
2496
  id: 0x0010,
@@ -2487,6 +2520,7 @@ export const KDF_SHAKE128 = function () {
2487
2520
 
2488
2521
 
2489
2522
 
2523
+
2490
2524
  export const KDF_SHAKE256 = function () {
2491
2525
  return {
2492
2526
  id: 0x0011,
@@ -2591,220 +2625,35 @@ function b64u(input ) {
2591
2625
 
2592
2626
 
2593
2627
 
2594
- async function DeriveCandidate(
2595
- DHKEM ,
2596
- suite_id ,
2597
- ikm ,
2598
- counter ,
2599
- ) {
2600
- const dkp_prk = await LabeledExtract(
2601
- DHKEM.kdf,
2602
- suite_id,
2603
- new Uint8Array(),
2604
- encode('dkp_prk'),
2605
- ikm,
2606
- )
2607
- return await LabeledExpand(
2608
- DHKEM.kdf,
2609
- suite_id,
2610
- dkp_prk,
2611
- encode('candidate'),
2612
- I2OSP(counter, 1),
2613
- DHKEM.Nsk,
2614
- )
2615
- }
2616
2628
 
2617
- function OS2IP(x ) {
2618
- let result = 0n
2619
- for (let i = 0; i < x.byteLength; i++) {
2620
- result = result * 256n + BigInt(x[i] )
2621
- }
2622
- return result
2623
- }
2624
2629
 
2625
- function bigIntToUint8Array(value , byteLength ) {
2626
- const result = new Uint8Array(byteLength)
2627
- let n = value
2628
2630
 
2629
- for (let i = byteLength - 1; i >= 0; i--) {
2630
- result[i] = Number(n & 0xffn)
2631
- n = n >> 8n
2632
- }
2633
2631
 
2634
- return result
2635
- }
2636
2632
 
2637
- function assertKeyAlgorithm(key , expectedAlgorithm ) {
2638
- if (key.algorithm.name !== expectedAlgorithm.name) {
2639
- throw new TypeError(`key algorithm must be ${expectedAlgorithm.name}`)
2640
- }
2641
- if (
2642
- (key.algorithm ).namedCurve !==
2643
- (expectedAlgorithm ).namedCurve
2644
- ) {
2645
- throw new TypeError(
2646
- `key namedCurve must be ${(expectedAlgorithm ).namedCurve}`,
2647
- )
2648
- }
2649
- }
2650
2633
 
2651
- function assertCryptoKey(key ) {
2652
2634
 
2653
- if (key[Symbol.toStringTag] !== 'CryptoKey') {
2654
- if (key instanceof CryptoKey) return
2655
- throw new TypeError('unexpected key constructor')
2656
- }
2657
- }
2658
2635
 
2659
2636
 
2660
2637
 
2661
2638
 
2662
2639
 
2663
- function DHKEM_SHARED() {
2664
- return {
2665
- async GenerateKeyPair( extractable) {
2666
- return (await subtle(
2667
- (c) => c.generateKey(this.algorithm, extractable, ['deriveBits']),
2668
- this.name,
2669
- ))
2670
- },
2671
- async SerializePublicKey( key) {
2672
- assertKeyAlgorithm(key, this.algorithm)
2673
- assertCryptoKey(key)
2674
- return new Uint8Array(await subtle((c) => c.exportKey('raw', key), this.name))
2675
- },
2676
- async DeserializePublicKey( _key) {
2677
- const key = ab(_key)
2678
- return await subtle((c) => c.importKey('raw', key, this.algorithm, true, []), this.name)
2679
- },
2680
- async SerializePrivateKey( key) {
2681
- assertKeyAlgorithm(key, this.algorithm)
2682
- assertCryptoKey(key)
2683
- const { d } = await subtle((c) => c.exportKey('jwk', key), this.name)
2684
- return b64u(d )
2685
- },
2686
- async Encap( pkR) {
2687
- assertKeyAlgorithm(pkR, this.algorithm)
2688
- assertCryptoKey(pkR)
2689
2640
 
2690
- const ekp = (await this.GenerateKeyPair(false))
2691
- const skE = ekp.privateKey
2692
- const pkE = ekp.publicKey
2693
2641
 
2694
2642
 
2695
2643
 
2696
- const dh = new Uint8Array(
2697
- await subtle(
2698
- (c) => c.deriveBits({ name: skE.algorithm.name, public: pkR }, skE, this.Ndh << 3),
2699
- this.name,
2700
- ),
2701
- )
2702
- checkNotAllZeros(dh)
2703
2644
 
2704
- const enc = await this.SerializePublicKey(pkE)
2705
- const pkRm = await this.SerializePublicKey(pkR)
2706
- const kem_context = concat(enc, pkRm)
2707
- const eae_prk = await LabeledExtract(
2708
- this.kdf,
2709
- this.suite_id,
2710
- new Uint8Array(),
2711
- encode('eae_prk'),
2712
- dh,
2713
- )
2714
- const shared_secret = await LabeledExpand(
2715
- this.kdf,
2716
- this.suite_id,
2717
- eae_prk,
2718
- encode('shared_secret'),
2719
- kem_context,
2720
- this.Nsecret,
2721
- )
2722
- return { shared_secret, enc }
2723
- },
2724
- async Decap( enc, skR, pkR) {
2725
- assertKeyAlgorithm(skR, this.algorithm)
2726
- assertCryptoKey(skR)
2727
- if (pkR) {
2728
- assertKeyAlgorithm(pkR, this.algorithm)
2729
- assertCryptoKey(pkR)
2730
- } else {
2731
- pkR = await getPublicKey(this.name, skR, [])
2732
- }
2733
2645
 
2734
- const pkE = (await this.DeserializePublicKey(enc))
2735
2646
 
2736
2647
 
2737
2648
 
2738
- const dh = new Uint8Array(
2739
- await subtle(
2740
- (c) => c.deriveBits({ name: skR.algorithm.name, public: pkE }, skR, this.Ndh << 3),
2741
- this.name,
2742
- ),
2743
- )
2744
- checkNotAllZeros(dh)
2745
2649
 
2746
- const pkRm = await this.SerializePublicKey(pkR)
2747
- const kem_context = concat(enc, pkRm)
2748
- const eae_prk = await LabeledExtract(
2749
- this.kdf,
2750
- this.suite_id,
2751
- new Uint8Array(),
2752
- encode('eae_prk'),
2753
- dh,
2754
- )
2755
- const shared_secret = await LabeledExpand(
2756
- this.kdf,
2757
- this.suite_id,
2758
- eae_prk,
2759
- encode('shared_secret'),
2760
- kem_context,
2761
- this.Nsecret,
2762
- )
2763
- return shared_secret
2764
- },
2765
- }
2766
- }
2767
2650
 
2768
2651
 
2769
2652
 
2770
2653
 
2771
2654
 
2772
- async function createKeyPairFromPrivateKey(
2773
- DHKEM ,
2774
- key ,
2775
- extractable ,
2776
- ) {
2777
- let privateKey
2778
- let publicKey
2779
2655
 
2780
- if (!extractable && typeof crypto.subtle.getPublicKey !== 'function') {
2781
- privateKey = (await DHKEM.DeserializePrivateKey(key, true))
2782
- publicKey = await getPublicKey(DHKEM.name, privateKey, [])
2783
- privateKey = (await DHKEM.DeserializePrivateKey(key, false))
2784
- } else {
2785
- privateKey = (await DHKEM.DeserializePrivateKey(key, extractable))
2786
- publicKey = await getPublicKey(DHKEM.name, privateKey, [])
2787
- }
2788
- return { privateKey, publicKey }
2789
- }
2790
2656
 
2791
- async function CurveKeyFromD(
2792
- name ,
2793
- Nsk ,
2794
- template ,
2795
- algorithm ,
2796
- key ,
2797
- extractable ,
2798
- ) {
2799
- const tmpl = slice(template)
2800
- const pkcs8 = new Uint8Array(Nsk + tmpl.byteLength)
2801
- pkcs8.set(tmpl)
2802
- pkcs8.set(key, tmpl.byteLength)
2803
- return await subtle(
2804
- (c) => c.importKey('pkcs8', pkcs8, algorithm, extractable, ['deriveBits']),
2805
- name,
2806
- )
2807
- }
2808
2657
 
2809
2658
 
2810
2659
 
@@ -2816,90 +2665,35 @@ async function CurveKeyFromD(
2816
2665
 
2817
2666
 
2818
2667
 
2819
- function modInverse(a , m ) {
2820
- a = ((a % m) + m) % m
2821
- let [t, newT] = [0n, 1n]
2822
- let [r, newR] = [m, a]
2823
2668
 
2824
- while (newR !== 0n) {
2825
- const quotient = r / newR
2826
- ;[t, newT] = [newT, t - quotient * newT]
2827
- ;[r, newR] = [newR, r - quotient * newR]
2828
- }
2829
2669
 
2830
- if (r > 1n) throw new Error('a is not invertible')
2831
- if (t < 0n) t = t + m
2832
- return t
2833
- }
2834
2670
 
2835
2671
 
2836
- function pointDouble(p , prime , a ) {
2837
- const { x, y } = p
2838
2672
 
2839
2673
 
2840
- const numerator = (((3n * x * x) % prime) + a) % prime
2841
- const denominator = (2n * y) % prime
2842
- const s = (numerator * modInverse(denominator, prime)) % prime
2843
2674
 
2844
2675
 
2845
- const x3 = (((s * s) % prime) - ((2n * x) % prime) + prime) % prime
2846
2676
 
2847
2677
 
2848
- const y3 = (((s * ((x - x3 + prime) % prime)) % prime) - y + prime) % prime
2849
2678
 
2850
- return { x: x3, y: y3 }
2851
- }
2852
2679
 
2853
2680
 
2854
- function pointAdd(p , q , prime , a ) {
2855
- if (p.x === q.x && p.y === q.y) {
2856
- return pointDouble(p, prime, a)
2857
- }
2858
2681
 
2859
- const { x: x1, y: y1 } = p
2860
- const { x: x2, y: y2 } = q
2861
2682
 
2862
2683
 
2863
2684
 
2864
- if (p.x === q.x) {
2865
- throw new Error('Point addition resulted in point at infinity')
2866
- }
2867
2685
 
2868
2686
 
2869
- const numerator = (((y2 - y1) % prime) + prime) % prime
2870
- const denominator = (((x2 - x1) % prime) + prime) % prime
2871
- const s = (numerator * modInverse(denominator, prime)) % prime
2872
2687
 
2873
2688
 
2874
- const x3 = (((s * s) % prime) - x1 - x2 + prime + prime) % prime
2875
2689
 
2876
2690
 
2877
- const y3 = (((s * ((x1 - x3 + prime) % prime)) % prime) - y1 + prime) % prime
2878
2691
 
2879
- return { x: x3, y: y3 }
2880
- }
2881
2692
 
2882
2693
 
2883
- function scalarMult(k , G , prime , a , order ) {
2884
- if (k === 0n || k >= order) {
2885
- throw new Error('Invalid scalar')
2886
- }
2887
2694
 
2888
- let result = null
2889
- let addend = G
2890
- let scalar = k
2891
2695
 
2892
- while (scalar > 0n) {
2893
- if (scalar & 1n) {
2894
- result = result === null ? addend : pointAdd(result, addend, prime, a)
2895
- }
2896
- addend = pointDouble(addend, prime, a)
2897
- scalar = scalar >> 1n
2898
- }
2899
2696
 
2900
- if (result === null) throw new Error('Invalid result')
2901
- return result
2902
- }
2903
2697
 
2904
2698
 
2905
2699
 
@@ -2913,122 +2707,361 @@ function scalarMult(k , G , prime , a , order
2913
2707
 
2914
2708
 
2915
2709
 
2916
- function getPrivateJwkNist(DHKEM , d ) {
2917
2710
 
2918
- const G = { x: DHKEM.Gx, y: DHKEM.Gy }
2919
- const publicPoint = scalarMult(d, G, DHKEM.prime, DHKEM.prime - 3n, DHKEM.order)
2920
2711
 
2921
- const coordSize = (DHKEM.Npk - 1) / 2
2922
- const xBytes = bigIntToUint8Array(publicPoint.x, coordSize)
2923
- const yBytes = bigIntToUint8Array(publicPoint.y, coordSize)
2924
- const dBytes = bigIntToUint8Array(d, DHKEM.Nsk)
2925
2712
 
2926
2713
 
2927
- return {
2928
- kty: 'EC',
2929
- crv: DHKEM.algorithm.namedCurve,
2930
- x: toB64u(xBytes),
2931
- y: toB64u(yBytes),
2932
- d: toB64u(dBytes),
2933
- }
2934
- }
2935
2714
 
2936
- async function DeserializePrivateKeyNist(
2937
2715
 
2938
- key ,
2939
- extractable ,
2940
- ) {
2941
- const d = OS2IP(key)
2942
- const jwk = getPrivateJwkNist(this, d)
2943
2716
 
2944
- const privateKey = await subtle(
2945
- (c) => c.importKey('jwk', jwk, this.algorithm, extractable, ['deriveBits']),
2946
- this.name,
2947
- )
2948
2717
 
2949
- return privateKey
2950
- }
2951
2718
 
2952
- async function DeriveKeyPairNist(
2953
2719
 
2954
- ikm ,
2955
- extractable ,
2956
- ) {
2957
- let sk = 0n
2958
- let counter = 0
2959
- let bytes
2960
- while (sk === 0n || sk >= this.order) {
2961
- if (counter > 255) {
2962
- throw new DeriveKeyPairError('Key derivation exceeded maximum iterations')
2963
- }
2964
- bytes = await DeriveCandidate(this, this.suite_id, ikm, counter)
2965
- bytes[0] = bytes[0] & this.bitmask
2966
- sk = OS2IP(bytes)
2967
- counter = counter + 1
2968
- }
2969
2720
 
2970
- return GetKeyPairNist(this, bytes , extractable, this.name)
2971
- }
2972
2721
 
2973
- async function GetKeyPairNist(
2974
- curveConfig ,
2975
- sk ,
2976
- extractable ,
2977
- name ,
2978
- ) {
2979
- const jwk = getPrivateJwkNist(curveConfig, OS2IP(sk))
2980
2722
 
2981
- const privateKey = await subtle(
2982
- (c) => c.importKey('jwk', jwk, curveConfig.algorithm, extractable, ['deriveBits']),
2983
- name,
2984
- )
2985
2723
 
2986
- delete jwk.d
2987
- const publicKey = await subtle(
2988
- (c) => c.importKey('jwk', jwk, curveConfig.algorithm, true, []),
2989
- name,
2990
- )
2991
2724
 
2992
- return { privateKey, publicKey }
2993
- }
2994
2725
 
2995
2726
 
2996
2727
 
2997
2728
 
2998
2729
 
2999
- async function DeriveKeyPairX( ikm , extractable ) {
3000
- const dkp_prk = await LabeledExtract(
3001
- this.kdf,
3002
- this.suite_id,
3003
- new Uint8Array(),
3004
- encode('dkp_prk'),
3005
- ikm,
3006
- )
3007
- const sk = await LabeledExpand(
3008
- this.kdf,
3009
- this.suite_id,
3010
- dkp_prk,
3011
- encode('sk'),
3012
- new Uint8Array(),
3013
- this.Nsk,
3014
- )
3015
- return await createKeyPairFromPrivateKey(this, sk, extractable)
3016
- }
3017
2730
 
3018
2731
 
3019
2732
 
3020
2733
 
3021
2734
 
3022
- const P256 = {
3023
- algorithm: { name: 'ECDH', namedCurve: 'P-256' },
3024
- Npk: 65,
3025
- Nsk: 32,
3026
- order: 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551n,
3027
- bitmask: 0xff,
3028
- prime: 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffffn,
3029
- Gx: 0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296n,
3030
- Gy: 0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5n,
3031
- }
2735
+
2736
+
2737
+
2738
+
2739
+
2740
+
2741
+
2742
+
2743
+
2744
+
2745
+
2746
+
2747
+
2748
+
2749
+
2750
+
2751
+
2752
+
2753
+
2754
+
2755
+
2756
+
2757
+
2758
+
2759
+
2760
+
2761
+
2762
+
2763
+
2764
+
2765
+
2766
+
2767
+
2768
+
2769
+
2770
+
2771
+
2772
+
2773
+
2774
+
2775
+
2776
+
2777
+
2778
+
2779
+
2780
+
2781
+
2782
+
2783
+
2784
+
2785
+
2786
+
2787
+
2788
+
2789
+
2790
+
2791
+
2792
+
2793
+
2794
+
2795
+
2796
+
2797
+
2798
+
2799
+
2800
+
2801
+
2802
+
2803
+
2804
+
2805
+
2806
+
2807
+
2808
+
2809
+
2810
+
2811
+
2812
+
2813
+
2814
+
2815
+
2816
+
2817
+
2818
+
2819
+
2820
+
2821
+
2822
+
2823
+
2824
+
2825
+
2826
+
2827
+
2828
+
2829
+
2830
+
2831
+
2832
+
2833
+
2834
+
2835
+
2836
+
2837
+
2838
+
2839
+
2840
+
2841
+
2842
+
2843
+
2844
+
2845
+
2846
+
2847
+
2848
+
2849
+
2850
+
2851
+
2852
+
2853
+
2854
+
2855
+
2856
+
2857
+
2858
+
2859
+
2860
+
2861
+
2862
+
2863
+
2864
+
2865
+
2866
+
2867
+
2868
+
2869
+
2870
+
2871
+
2872
+
2873
+
2874
+
2875
+
2876
+
2877
+
2878
+
2879
+
2880
+
2881
+
2882
+
2883
+
2884
+
2885
+
2886
+
2887
+
2888
+
2889
+
2890
+
2891
+
2892
+
2893
+
2894
+
2895
+
2896
+
2897
+
2898
+
2899
+
2900
+
2901
+
2902
+
2903
+
2904
+
2905
+
2906
+
2907
+
2908
+
2909
+
2910
+
2911
+
2912
+
2913
+
2914
+
2915
+
2916
+
2917
+
2918
+
2919
+
2920
+
2921
+
2922
+
2923
+
2924
+
2925
+
2926
+
2927
+
2928
+
2929
+
2930
+
2931
+
2932
+
2933
+
2934
+
2935
+
2936
+
2937
+
2938
+
2939
+
2940
+
2941
+
2942
+
2943
+
2944
+
2945
+
2946
+
2947
+
2948
+
2949
+
2950
+
2951
+
2952
+
2953
+
2954
+
2955
+
2956
+
2957
+
2958
+
2959
+
2960
+
2961
+
2962
+
2963
+
2964
+
2965
+
2966
+
2967
+
2968
+
2969
+
2970
+
2971
+
2972
+
2973
+
2974
+
2975
+
2976
+
2977
+
2978
+
2979
+
2980
+
2981
+
2982
+
2983
+
2984
+
2985
+
2986
+
2987
+
2988
+
2989
+
2990
+
2991
+
2992
+
2993
+
2994
+
2995
+
2996
+
2997
+
2998
+
2999
+
3000
+
3001
+
3002
+
3003
+
3004
+
3005
+
3006
+
3007
+
3008
+
3009
+
3010
+
3011
+
3012
+
3013
+
3014
+
3015
+
3016
+
3017
+
3018
+
3019
+
3020
+
3021
+
3022
+
3023
+
3024
+
3025
+
3026
+
3027
+
3028
+
3029
+
3030
+
3031
+
3032
+
3033
+
3034
+
3035
+
3036
+
3037
+
3038
+
3039
+
3040
+
3041
+
3042
+
3043
+
3044
+
3045
+
3046
+
3047
+
3048
+
3049
+
3050
+
3051
+
3052
+
3053
+
3054
+
3055
+
3056
+
3057
+
3058
+
3059
+
3060
+
3061
+
3062
+
3063
+
3064
+
3032
3065
 
3033
3066
 
3034
3067
 
@@ -3102,6 +3135,7 @@ const P384 = {
3102
3135
 
3103
3136
 
3104
3137
 
3138
+
3105
3139
 
3106
3140
  export const KEM_DHKEM_P384_HKDF_SHA384 = function () {
3107
3141
  const id = 0x0011
@@ -3156,6 +3190,7 @@ const P521 = {
3156
3190
 
3157
3191
 
3158
3192
 
3193
+
3159
3194
 
3160
3195
  export const KEM_DHKEM_P521_HKDF_SHA512 = function () {
3161
3196
  const id = 0x0012
@@ -3200,6 +3235,7 @@ export const KEM_DHKEM_P521_HKDF_SHA512 = function ()
3200
3235
 
3201
3236
 
3202
3237
 
3238
+
3203
3239
 
3204
3240
 
3205
3241
  export const KEM_DHKEM_X25519_HKDF_SHA256 = function () {
@@ -3247,6 +3283,7 @@ export const KEM_DHKEM_X25519_HKDF_SHA256 = function ()
3247
3283
 
3248
3284
 
3249
3285
 
3286
+
3250
3287
 
3251
3288
  export const KEM_DHKEM_X448_HKDF_SHA512 = function () {
3252
3289
  const id = 0x0021
@@ -3390,6 +3427,7 @@ function MLKEM_SHARED() {
3390
3427
 
3391
3428
 
3392
3429
 
3430
+
3393
3431
 
3394
3432
 
3395
3433
  export const KEM_ML_KEM_512 = function () {
@@ -3431,6 +3469,7 @@ export const KEM_ML_KEM_512 = function () {
3431
3469
 
3432
3470
 
3433
3471
 
3472
+
3434
3473
  export const KEM_ML_KEM_768 = function () {
3435
3474
  const id = 0x0041
3436
3475
  const name = 'ML-KEM-768'
@@ -3470,6 +3509,7 @@ export const KEM_ML_KEM_768 = function () {
3470
3509
 
3471
3510
 
3472
3511
 
3512
+
3473
3513
  export const KEM_ML_KEM_1024 = function () {
3474
3514
  const id = 0x0042
3475
3515
  const name = 'ML-KEM-1024'
@@ -3556,6 +3596,7 @@ function AEAD_SHARED() {
3556
3596
 
3557
3597
 
3558
3598
 
3599
+
3559
3600
 
3560
3601
 
3561
3602
  export const AEAD_AES_128_GCM = function () {
@@ -3589,6 +3630,7 @@ export const AEAD_AES_128_GCM = function () {
3589
3630
 
3590
3631
 
3591
3632
 
3633
+
3592
3634
  export const AEAD_AES_256_GCM = function () {
3593
3635
  return {
3594
3636
  id: 0x0002,
@@ -3620,6 +3662,7 @@ export const AEAD_AES_256_GCM = function () {
3620
3662
 
3621
3663
 
3622
3664
 
3665
+
3623
3666
  export const AEAD_ChaCha20Poly1305 = function AEAD_ChaCha20Poly1305() {
3624
3667
  return {
3625
3668
  id: 0x0003,
@@ -3753,106 +3796,20 @@ function RandomScalarNist(t , seed ) {
3753
3796
  return bigIntToUint8Array(sk_bigint, t.Nscalar )
3754
3797
  }
3755
3798
 
3756
- async function expandDecapsKeyG(PQTKEM , _seed ) {
3757
- const Nout = PQTKEM.pq.Nseed + PQTKEM.t.Nseed
3758
3799
 
3759
- const algorithm = { name: 'cSHAKE256', length: Nout << 3 }
3760
- const seed = ab(_seed)
3761
- const seed_full = await subtle((c) => c.digest(algorithm, seed), PQTKEM.name)
3762
3800
 
3763
- const [_seed_PQ, seed_T] = split(PQTKEM.pq.Nseed, PQTKEM.t.Nseed, new Uint8Array(seed_full))
3764
- const seed_PQ = ab(_seed_PQ)
3765
3801
 
3766
3802
 
3767
- const format = 'raw-seed'
3768
3803
 
3769
- const usages = ['decapsulateBits', 'encapsulateBits']
3770
- const dk_PQ = await subtle(
3771
- (c) => c.importKey(format, seed_PQ, PQTKEM.pq.algorithm, true, [usages[0]]),
3772
- PQTKEM.name,
3773
- )
3774
- const ek_PQ = await getPublicKey(PQTKEM.name, dk_PQ, [usages[1]])
3775
3804
 
3776
- const sk = PQTKEM.t.RandomScalar?.(seed_T) ?? seed_T
3777
- const { privateKey: dk_T, publicKey: ek_T } = await PQTKEM.t.GetKeyPair(sk)
3778
3805
 
3779
- return { ek_PQ, ek_T, dk_PQ, dk_T }
3780
- }
3781
3806
 
3782
- async function C2PRICombiner(
3783
- PQTKEM ,
3784
- ss_PQ ,
3785
- ss_T ,
3786
- ct_T ,
3787
- _ek_T ,
3788
- label ,
3789
- ) {
3790
- const ek_T = new Uint8Array(await subtle((c) => c.exportKey('raw', _ek_T), PQTKEM.name))
3791
- const data = ab(concat(ss_PQ, ss_T, ct_T, ek_T, label))
3792
- return new Uint8Array(await subtle((c) => c.digest('SHA3-256', data), PQTKEM.name))
3793
- }
3794
3807
 
3795
- async function prepareEncapsG(
3796
- PQTKEM ,
3797
- ek_PQ ,
3798
- ek_T ,
3799
- ) {
3800
- const res = (await subtle(
3801
-
3802
- (c) => c.encapsulateBits(PQTKEM.pq.algorithm, ek_PQ),
3803
- PQTKEM.name,
3804
- ))
3805
- const ss_PQ = new Uint8Array(res.sharedKey)
3806
- const ct_PQ = new Uint8Array(res.ciphertext)
3807
-
3808
- const { privateKey: sk_E, publicKey } = (await subtle(
3809
- (c) => c.generateKey(PQTKEM.t.algorithm, true, ['deriveBits']),
3810
- PQTKEM.name,
3811
- ))
3812
- const ct_T = new Uint8Array(await subtle((c) => c.exportKey('raw', publicKey), PQTKEM.name))
3813
-
3814
- const ss_T = new Uint8Array(
3815
- await subtle(
3816
- (c) => c.deriveBits({ name: PQTKEM.t.algorithm.name, public: ek_T }, sk_E, PQTKEM.t.Nss << 3),
3817
- PQTKEM.name,
3818
- ),
3819
- )
3820
- checkNotAllZeros(ss_T)
3821
3808
 
3822
- return [ss_PQ, ss_T, ct_PQ, ct_T]
3823
- }
3824
3809
 
3825
- async function prepareDecapsG(
3826
- PQTKEM ,
3827
- dk_PQ ,
3828
- dk_T ,
3829
- ct_PQ ,
3830
- _ct_T ,
3831
- ) {
3832
- const ss_PQ = new Uint8Array(
3833
- await subtle(
3834
-
3835
- (c) => c.decapsulateBits(PQTKEM.pq.algorithm, dk_PQ, ct_PQ),
3836
- PQTKEM.name,
3837
- ),
3838
- )
3839
3810
 
3840
- const ct_T = ab(_ct_T)
3841
- const pub = await subtle(
3842
- (c) => c.importKey('raw', ct_T, PQTKEM.t.algorithm, true, []),
3843
- PQTKEM.name,
3844
- )
3845
3811
 
3846
- const ss_T = new Uint8Array(
3847
- await subtle(
3848
- (c) => c.deriveBits({ name: PQTKEM.t.algorithm.name, public: pub }, dk_T, PQTKEM.t.Nss << 3),
3849
- PQTKEM.name,
3850
- ),
3851
- )
3852
- checkNotAllZeros(ss_T)
3853
3812
 
3854
- return [ss_PQ, ss_T]
3855
- }
3856
3813
 
3857
3814
 
3858
3815
 
@@ -3882,121 +3839,213 @@ async function prepareDecapsG(
3882
3839
 
3883
3840
 
3884
3841
 
3885
- function PQTKEM_SHARED() {
3886
- Object.freeze(HybridKey.prototype)
3887
- return {
3888
- async DeriveKeyPair( ikm , extractable) {
3889
- const seed = await LabeledDerive(
3890
- this.kdf,
3891
- this.suite_id,
3892
- ikm,
3893
- encode('DeriveKeyPair'),
3894
- new Uint8Array(),
3895
- 32,
3896
- )
3897
3842
 
3898
- const { ek_PQ, ek_T, dk_PQ, dk_T } = await expandDecapsKeyG(this, seed)
3899
-
3900
- const publicKey = new HybridKey(priv, this.algorithm, 'public', true, ek_PQ, ek_T)
3901
- const privateKey = new HybridKey(
3902
- priv,
3903
- this.algorithm,
3904
- 'private',
3905
- extractable,
3906
- dk_PQ,
3907
- dk_T,
3908
- seed,
3909
- publicKey,
3910
- )
3911
3843
 
3912
- return { privateKey, publicKey }
3913
- },
3914
- async GenerateKeyPair( extractable) {
3915
- return await this.DeriveKeyPair(crypto.getRandomValues(new Uint8Array(32)), extractable)
3916
- },
3917
- async SerializePublicKey( key) {
3918
- assertKeyAlgorithm(key, this.algorithm)
3919
- HybridKey.validate(key, true)
3920
3844
 
3921
- const format = 'raw-public'
3922
- const ek_PQ = new Uint8Array(
3923
- await subtle((c) => c.exportKey(format, key.getPq(priv)), this.name),
3924
- )
3925
- const ek_T = new Uint8Array(
3926
- await subtle((c) => c.exportKey('raw', key.getT(priv)), this.name),
3927
- )
3928
3845
 
3929
- return concat(ek_PQ, ek_T)
3930
- },
3931
- async DeserializePublicKey( key) {
3932
3846
 
3933
- const format = 'raw-public'
3934
3847
 
3935
- const usages = ['encapsulateBits']
3936
- const pubPq = ab(key.subarray(0, this.pq.Npk))
3937
- const pubT = ab(key.subarray(this.pq.Npk))
3938
- const [ek_PQ, ek_T] = await Promise.all([
3939
- subtle((c) => c.importKey(format, pubPq, this.pq.algorithm, true, usages), this.name),
3940
- subtle((c) => c.importKey('raw', pubT, this.t.algorithm, true, []), this.name),
3941
- ])
3942
-
3943
- return new HybridKey(priv, this.algorithm, 'public', true, ek_PQ, ek_T)
3944
- },
3945
- async SerializePrivateKey( key) {
3946
- assertKeyAlgorithm(key, this.algorithm)
3947
- HybridKey.validate(key, true)
3948
3848
 
3949
- return key.getSeed(priv)
3950
- },
3951
- async DeserializePrivateKey( key, extractable) {
3952
- const { ek_PQ, ek_T, dk_PQ, dk_T } = await expandDecapsKeyG(this, key)
3953
- const publicKey = new HybridKey(priv, this.algorithm, 'public', true, ek_PQ, ek_T)
3954
- const privateKey = new HybridKey(
3955
- priv,
3956
- this.algorithm,
3957
- 'private',
3958
- extractable,
3959
- dk_PQ,
3960
- dk_T,
3961
- slice(key),
3962
- publicKey,
3963
- )
3964
3849
 
3965
- return privateKey
3966
- },
3967
- async Encap( pkR) {
3968
- assertKeyAlgorithm(pkR, this.algorithm)
3969
- HybridKey.validate(pkR)
3970
3850
 
3971
- const ek_PQ = pkR.getPq(priv)
3972
- const ek_T = pkR.getT(priv)
3973
- const [ss_PQ, ss_T, ct_PQ, ct_T] = await prepareEncapsG(this, ek_PQ, ek_T)
3974
- const ss_H = await C2PRICombiner(this, ss_PQ, ss_T, ct_T, ek_T, this.label)
3975
- const ct_H = concat(ct_PQ, ct_T)
3976
3851
 
3977
- return { shared_secret: ss_H, enc: ct_H }
3978
- },
3979
- async Decap( enc, skR, pkR) {
3980
- assertKeyAlgorithm(skR, this.algorithm)
3981
- HybridKey.validate(skR)
3982
3852
 
3983
- if (pkR) {
3984
- assertKeyAlgorithm(pkR, this.algorithm)
3985
- HybridKey.validate(pkR)
3986
- }
3987
3853
 
3988
- const [ct_PQ, ct_T] = split(this.pq.Nct, this.t.Nct, enc)
3989
- const ek = pkR ?? skR.getPublicKey(priv)
3990
- const ek_T = ek.getT(priv)
3991
- const dk_PQ = skR.getPq(priv)
3992
- const dk_T = skR.getT(priv)
3993
- const [ss_PQ, ss_T] = await prepareDecapsG(this, dk_PQ, dk_T, ct_PQ, ct_T)
3994
- const ss_H = await C2PRICombiner(this, ss_PQ, ss_T, ct_T, ek_T, this.label)
3995
3854
 
3996
- return ss_H
3997
- },
3998
- }
3999
- }
3855
+
3856
+
3857
+
3858
+
3859
+
3860
+
3861
+
3862
+
3863
+
3864
+
3865
+
3866
+
3867
+
3868
+
3869
+
3870
+
3871
+
3872
+
3873
+
3874
+
3875
+
3876
+
3877
+
3878
+
3879
+
3880
+
3881
+
3882
+
3883
+
3884
+
3885
+
3886
+
3887
+
3888
+
3889
+
3890
+
3891
+
3892
+
3893
+
3894
+
3895
+
3896
+
3897
+
3898
+
3899
+
3900
+
3901
+
3902
+
3903
+
3904
+
3905
+
3906
+
3907
+
3908
+
3909
+
3910
+
3911
+
3912
+
3913
+
3914
+
3915
+
3916
+
3917
+
3918
+
3919
+
3920
+
3921
+
3922
+
3923
+
3924
+
3925
+
3926
+
3927
+
3928
+
3929
+
3930
+
3931
+
3932
+
3933
+
3934
+
3935
+
3936
+
3937
+
3938
+
3939
+
3940
+
3941
+
3942
+
3943
+
3944
+
3945
+
3946
+
3947
+
3948
+
3949
+
3950
+
3951
+
3952
+
3953
+
3954
+
3955
+
3956
+
3957
+
3958
+
3959
+
3960
+
3961
+
3962
+
3963
+
3964
+
3965
+
3966
+
3967
+
3968
+
3969
+
3970
+
3971
+
3972
+
3973
+
3974
+
3975
+
3976
+
3977
+
3978
+
3979
+
3980
+
3981
+
3982
+
3983
+
3984
+
3985
+
3986
+
3987
+
3988
+
3989
+
3990
+
3991
+
3992
+
3993
+
3994
+
3995
+
3996
+
3997
+
3998
+
3999
+
4000
+
4001
+
4002
+
4003
+
4004
+
4005
+
4006
+
4007
+
4008
+
4009
+
4010
+
4011
+
4012
+
4013
+
4014
+
4015
+
4016
+
4017
+
4018
+
4019
+
4020
+
4021
+
4022
+
4023
+
4024
+
4025
+
4026
+
4027
+
4028
+
4029
+
4030
+
4031
+
4032
+
4033
+
4034
+
4035
+
4036
+
4037
+
4038
+
4039
+
4040
+
4041
+
4042
+
4043
+
4044
+
4045
+
4046
+
4047
+
4048
+
4000
4049
 
4001
4050
 
4002
4051
 
@@ -4076,6 +4125,7 @@ export const KEM_MLKEM768_X25519 = function () {
4076
4125
 
4077
4126
 
4078
4127
 
4128
+
4079
4129
  export const KEM_MLKEM768_P256 = function () {
4080
4130
  const id = 0x0050
4081
4131
  const name = 'MLKEM768-P256'
@@ -4131,6 +4181,7 @@ export const KEM_MLKEM768_P256 = function () {
4131
4181
 
4132
4182
 
4133
4183
 
4184
+
4134
4185
  export const KEM_MLKEM1024_P384 = function () {
4135
4186
  const id = 0x0051
4136
4187
  const name = 'MLKEM1024-P384'