hpke 1.0.4 → 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
  }
@@ -2459,6 +2490,7 @@ function SHAKE_SHARED() {
2459
2490
 
2460
2491
 
2461
2492
 
2493
+
2462
2494
  export const KDF_SHAKE128 = function () {
2463
2495
  return {
2464
2496
  id: 0x0010,
@@ -2488,6 +2520,7 @@ export const KDF_SHAKE128 = function () {
2488
2520
 
2489
2521
 
2490
2522
 
2523
+
2491
2524
  export const KDF_SHAKE256 = function () {
2492
2525
  return {
2493
2526
  id: 0x0011,
@@ -2592,220 +2625,35 @@ function b64u(input ) {
2592
2625
 
2593
2626
 
2594
2627
 
2595
- async function DeriveCandidate(
2596
- DHKEM ,
2597
- suite_id ,
2598
- ikm ,
2599
- counter ,
2600
- ) {
2601
- const dkp_prk = await LabeledExtract(
2602
- DHKEM.kdf,
2603
- suite_id,
2604
- new Uint8Array(),
2605
- encode('dkp_prk'),
2606
- ikm,
2607
- )
2608
- return await LabeledExpand(
2609
- DHKEM.kdf,
2610
- suite_id,
2611
- dkp_prk,
2612
- encode('candidate'),
2613
- I2OSP(counter, 1),
2614
- DHKEM.Nsk,
2615
- )
2616
- }
2617
2628
 
2618
- function OS2IP(x ) {
2619
- let result = 0n
2620
- for (let i = 0; i < x.byteLength; i++) {
2621
- result = result * 256n + BigInt(x[i] )
2622
- }
2623
- return result
2624
- }
2625
2629
 
2626
- function bigIntToUint8Array(value , byteLength ) {
2627
- const result = new Uint8Array(byteLength)
2628
- let n = value
2629
2630
 
2630
- for (let i = byteLength - 1; i >= 0; i--) {
2631
- result[i] = Number(n & 0xffn)
2632
- n = n >> 8n
2633
- }
2634
2631
 
2635
- return result
2636
- }
2637
2632
 
2638
- function assertKeyAlgorithm(key , expectedAlgorithm ) {
2639
- if (key.algorithm.name !== expectedAlgorithm.name) {
2640
- throw new TypeError(`key algorithm must be ${expectedAlgorithm.name}`)
2641
- }
2642
- if (
2643
- (key.algorithm ).namedCurve !==
2644
- (expectedAlgorithm ).namedCurve
2645
- ) {
2646
- throw new TypeError(
2647
- `key namedCurve must be ${(expectedAlgorithm ).namedCurve}`,
2648
- )
2649
- }
2650
- }
2651
2633
 
2652
- function assertCryptoKey(key ) {
2653
2634
 
2654
- if (key[Symbol.toStringTag] !== 'CryptoKey') {
2655
- if (key instanceof CryptoKey) return
2656
- throw new TypeError('unexpected key constructor')
2657
- }
2658
- }
2659
2635
 
2660
2636
 
2661
2637
 
2662
2638
 
2663
2639
 
2664
- function DHKEM_SHARED() {
2665
- return {
2666
- async GenerateKeyPair( extractable) {
2667
- return (await subtle(
2668
- (c) => c.generateKey(this.algorithm, extractable, ['deriveBits']),
2669
- this.name,
2670
- ))
2671
- },
2672
- async SerializePublicKey( key) {
2673
- assertKeyAlgorithm(key, this.algorithm)
2674
- assertCryptoKey(key)
2675
- return new Uint8Array(await subtle((c) => c.exportKey('raw', key), this.name))
2676
- },
2677
- async DeserializePublicKey( _key) {
2678
- const key = ab(_key)
2679
- return await subtle((c) => c.importKey('raw', key, this.algorithm, true, []), this.name)
2680
- },
2681
- async SerializePrivateKey( key) {
2682
- assertKeyAlgorithm(key, this.algorithm)
2683
- assertCryptoKey(key)
2684
- const { d } = await subtle((c) => c.exportKey('jwk', key), this.name)
2685
- return b64u(d )
2686
- },
2687
- async Encap( pkR) {
2688
- assertKeyAlgorithm(pkR, this.algorithm)
2689
- assertCryptoKey(pkR)
2690
2640
 
2691
- const ekp = (await this.GenerateKeyPair(false))
2692
- const skE = ekp.privateKey
2693
- const pkE = ekp.publicKey
2694
2641
 
2695
2642
 
2696
2643
 
2697
- const dh = new Uint8Array(
2698
- await subtle(
2699
- (c) => c.deriveBits({ name: skE.algorithm.name, public: pkR }, skE, this.Ndh << 3),
2700
- this.name,
2701
- ),
2702
- )
2703
- checkNotAllZeros(dh)
2704
2644
 
2705
- const enc = await this.SerializePublicKey(pkE)
2706
- const pkRm = await this.SerializePublicKey(pkR)
2707
- const kem_context = concat(enc, pkRm)
2708
- const eae_prk = await LabeledExtract(
2709
- this.kdf,
2710
- this.suite_id,
2711
- new Uint8Array(),
2712
- encode('eae_prk'),
2713
- dh,
2714
- )
2715
- const shared_secret = await LabeledExpand(
2716
- this.kdf,
2717
- this.suite_id,
2718
- eae_prk,
2719
- encode('shared_secret'),
2720
- kem_context,
2721
- this.Nsecret,
2722
- )
2723
- return { shared_secret, enc }
2724
- },
2725
- async Decap( enc, skR, pkR) {
2726
- assertKeyAlgorithm(skR, this.algorithm)
2727
- assertCryptoKey(skR)
2728
- if (pkR) {
2729
- assertKeyAlgorithm(pkR, this.algorithm)
2730
- assertCryptoKey(pkR)
2731
- } else {
2732
- pkR = await getPublicKey(this.name, skR, [])
2733
- }
2734
2645
 
2735
- const pkE = (await this.DeserializePublicKey(enc))
2736
2646
 
2737
2647
 
2738
2648
 
2739
- const dh = new Uint8Array(
2740
- await subtle(
2741
- (c) => c.deriveBits({ name: skR.algorithm.name, public: pkE }, skR, this.Ndh << 3),
2742
- this.name,
2743
- ),
2744
- )
2745
- checkNotAllZeros(dh)
2746
2649
 
2747
- const pkRm = await this.SerializePublicKey(pkR)
2748
- const kem_context = concat(enc, pkRm)
2749
- const eae_prk = await LabeledExtract(
2750
- this.kdf,
2751
- this.suite_id,
2752
- new Uint8Array(),
2753
- encode('eae_prk'),
2754
- dh,
2755
- )
2756
- const shared_secret = await LabeledExpand(
2757
- this.kdf,
2758
- this.suite_id,
2759
- eae_prk,
2760
- encode('shared_secret'),
2761
- kem_context,
2762
- this.Nsecret,
2763
- )
2764
- return shared_secret
2765
- },
2766
- }
2767
- }
2768
2650
 
2769
2651
 
2770
2652
 
2771
2653
 
2772
2654
 
2773
- async function createKeyPairFromPrivateKey(
2774
- DHKEM ,
2775
- key ,
2776
- extractable ,
2777
- ) {
2778
- let privateKey
2779
- let publicKey
2780
2655
 
2781
- if (!extractable && typeof crypto.subtle.getPublicKey !== 'function') {
2782
- privateKey = (await DHKEM.DeserializePrivateKey(key, true))
2783
- publicKey = await getPublicKey(DHKEM.name, privateKey, [])
2784
- privateKey = (await DHKEM.DeserializePrivateKey(key, false))
2785
- } else {
2786
- privateKey = (await DHKEM.DeserializePrivateKey(key, extractable))
2787
- publicKey = await getPublicKey(DHKEM.name, privateKey, [])
2788
- }
2789
- return { privateKey, publicKey }
2790
- }
2791
2656
 
2792
- async function CurveKeyFromD(
2793
- name ,
2794
- Nsk ,
2795
- template ,
2796
- algorithm ,
2797
- key ,
2798
- extractable ,
2799
- ) {
2800
- const tmpl = slice(template)
2801
- const pkcs8 = new Uint8Array(Nsk + tmpl.byteLength)
2802
- pkcs8.set(tmpl)
2803
- pkcs8.set(key, tmpl.byteLength)
2804
- return await subtle(
2805
- (c) => c.importKey('pkcs8', pkcs8, algorithm, extractable, ['deriveBits']),
2806
- name,
2807
- )
2808
- }
2809
2657
 
2810
2658
 
2811
2659
 
@@ -2817,90 +2665,35 @@ async function CurveKeyFromD(
2817
2665
 
2818
2666
 
2819
2667
 
2820
- function modInverse(a , m ) {
2821
- a = ((a % m) + m) % m
2822
- let [t, newT] = [0n, 1n]
2823
- let [r, newR] = [m, a]
2824
2668
 
2825
- while (newR !== 0n) {
2826
- const quotient = r / newR
2827
- ;[t, newT] = [newT, t - quotient * newT]
2828
- ;[r, newR] = [newR, r - quotient * newR]
2829
- }
2830
2669
 
2831
- if (r > 1n) throw new Error('a is not invertible')
2832
- if (t < 0n) t = t + m
2833
- return t
2834
- }
2835
2670
 
2836
2671
 
2837
- function pointDouble(p , prime , a ) {
2838
- const { x, y } = p
2839
2672
 
2840
2673
 
2841
- const numerator = (((3n * x * x) % prime) + a) % prime
2842
- const denominator = (2n * y) % prime
2843
- const s = (numerator * modInverse(denominator, prime)) % prime
2844
2674
 
2845
2675
 
2846
- const x3 = (((s * s) % prime) - ((2n * x) % prime) + prime) % prime
2847
2676
 
2848
2677
 
2849
- const y3 = (((s * ((x - x3 + prime) % prime)) % prime) - y + prime) % prime
2850
2678
 
2851
- return { x: x3, y: y3 }
2852
- }
2853
2679
 
2854
2680
 
2855
- function pointAdd(p , q , prime , a ) {
2856
- if (p.x === q.x && p.y === q.y) {
2857
- return pointDouble(p, prime, a)
2858
- }
2859
2681
 
2860
- const { x: x1, y: y1 } = p
2861
- const { x: x2, y: y2 } = q
2862
2682
 
2863
2683
 
2864
2684
 
2865
- if (p.x === q.x) {
2866
- throw new Error('Point addition resulted in point at infinity')
2867
- }
2868
2685
 
2869
2686
 
2870
- const numerator = (((y2 - y1) % prime) + prime) % prime
2871
- const denominator = (((x2 - x1) % prime) + prime) % prime
2872
- const s = (numerator * modInverse(denominator, prime)) % prime
2873
2687
 
2874
2688
 
2875
- const x3 = (((s * s) % prime) - x1 - x2 + prime + prime) % prime
2876
2689
 
2877
2690
 
2878
- const y3 = (((s * ((x1 - x3 + prime) % prime)) % prime) - y1 + prime) % prime
2879
2691
 
2880
- return { x: x3, y: y3 }
2881
- }
2882
2692
 
2883
2693
 
2884
- function scalarMult(k , G , prime , a , order ) {
2885
- if (k === 0n || k >= order) {
2886
- throw new Error('Invalid scalar')
2887
- }
2888
2694
 
2889
- let result = null
2890
- let addend = G
2891
- let scalar = k
2892
2695
 
2893
- while (scalar > 0n) {
2894
- if (scalar & 1n) {
2895
- result = result === null ? addend : pointAdd(result, addend, prime, a)
2896
- }
2897
- addend = pointDouble(addend, prime, a)
2898
- scalar = scalar >> 1n
2899
- }
2900
2696
 
2901
- if (result === null) throw new Error('Invalid result')
2902
- return result
2903
- }
2904
2697
 
2905
2698
 
2906
2699
 
@@ -2914,122 +2707,361 @@ function scalarMult(k , G , prime , a , order
2914
2707
 
2915
2708
 
2916
2709
 
2917
- function getPrivateJwkNist(DHKEM , d ) {
2918
2710
 
2919
- const G = { x: DHKEM.Gx, y: DHKEM.Gy }
2920
- const publicPoint = scalarMult(d, G, DHKEM.prime, DHKEM.prime - 3n, DHKEM.order)
2921
2711
 
2922
- const coordSize = (DHKEM.Npk - 1) / 2
2923
- const xBytes = bigIntToUint8Array(publicPoint.x, coordSize)
2924
- const yBytes = bigIntToUint8Array(publicPoint.y, coordSize)
2925
- const dBytes = bigIntToUint8Array(d, DHKEM.Nsk)
2926
2712
 
2927
2713
 
2928
- return {
2929
- kty: 'EC',
2930
- crv: DHKEM.algorithm.namedCurve,
2931
- x: toB64u(xBytes),
2932
- y: toB64u(yBytes),
2933
- d: toB64u(dBytes),
2934
- }
2935
- }
2936
2714
 
2937
- async function DeserializePrivateKeyNist(
2938
2715
 
2939
- key ,
2940
- extractable ,
2941
- ) {
2942
- const d = OS2IP(key)
2943
- const jwk = getPrivateJwkNist(this, d)
2944
2716
 
2945
- const privateKey = await subtle(
2946
- (c) => c.importKey('jwk', jwk, this.algorithm, extractable, ['deriveBits']),
2947
- this.name,
2948
- )
2949
2717
 
2950
- return privateKey
2951
- }
2952
2718
 
2953
- async function DeriveKeyPairNist(
2954
2719
 
2955
- ikm ,
2956
- extractable ,
2957
- ) {
2958
- let sk = 0n
2959
- let counter = 0
2960
- let bytes
2961
- while (sk === 0n || sk >= this.order) {
2962
- if (counter > 255) {
2963
- throw new DeriveKeyPairError('Key derivation exceeded maximum iterations')
2964
- }
2965
- bytes = await DeriveCandidate(this, this.suite_id, ikm, counter)
2966
- bytes[0] = bytes[0] & this.bitmask
2967
- sk = OS2IP(bytes)
2968
- counter = counter + 1
2969
- }
2970
2720
 
2971
- return GetKeyPairNist(this, bytes , extractable, this.name)
2972
- }
2973
2721
 
2974
- async function GetKeyPairNist(
2975
- curveConfig ,
2976
- sk ,
2977
- extractable ,
2978
- name ,
2979
- ) {
2980
- const jwk = getPrivateJwkNist(curveConfig, OS2IP(sk))
2981
2722
 
2982
- const privateKey = await subtle(
2983
- (c) => c.importKey('jwk', jwk, curveConfig.algorithm, extractable, ['deriveBits']),
2984
- name,
2985
- )
2986
2723
 
2987
- delete jwk.d
2988
- const publicKey = await subtle(
2989
- (c) => c.importKey('jwk', jwk, curveConfig.algorithm, true, []),
2990
- name,
2991
- )
2992
2724
 
2993
- return { privateKey, publicKey }
2994
- }
2995
2725
 
2996
2726
 
2997
2727
 
2998
2728
 
2999
2729
 
3000
- async function DeriveKeyPairX( ikm , extractable ) {
3001
- const dkp_prk = await LabeledExtract(
3002
- this.kdf,
3003
- this.suite_id,
3004
- new Uint8Array(),
3005
- encode('dkp_prk'),
3006
- ikm,
3007
- )
3008
- const sk = await LabeledExpand(
3009
- this.kdf,
3010
- this.suite_id,
3011
- dkp_prk,
3012
- encode('sk'),
3013
- new Uint8Array(),
3014
- this.Nsk,
3015
- )
3016
- return await createKeyPairFromPrivateKey(this, sk, extractable)
3017
- }
3018
2730
 
3019
2731
 
3020
2732
 
3021
2733
 
3022
2734
 
3023
- const P256 = {
3024
- algorithm: { name: 'ECDH', namedCurve: 'P-256' },
3025
- Npk: 65,
3026
- Nsk: 32,
3027
- order: 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551n,
3028
- bitmask: 0xff,
3029
- prime: 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffffn,
3030
- Gx: 0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296n,
3031
- Gy: 0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5n,
3032
- }
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
+
3033
3065
 
3034
3066
 
3035
3067
 
@@ -3103,6 +3135,7 @@ const P384 = {
3103
3135
 
3104
3136
 
3105
3137
 
3138
+
3106
3139
 
3107
3140
  export const KEM_DHKEM_P384_HKDF_SHA384 = function () {
3108
3141
  const id = 0x0011
@@ -3157,6 +3190,7 @@ const P521 = {
3157
3190
 
3158
3191
 
3159
3192
 
3193
+
3160
3194
 
3161
3195
  export const KEM_DHKEM_P521_HKDF_SHA512 = function () {
3162
3196
  const id = 0x0012
@@ -3201,6 +3235,7 @@ export const KEM_DHKEM_P521_HKDF_SHA512 = function ()
3201
3235
 
3202
3236
 
3203
3237
 
3238
+
3204
3239
 
3205
3240
 
3206
3241
  export const KEM_DHKEM_X25519_HKDF_SHA256 = function () {
@@ -3248,6 +3283,7 @@ export const KEM_DHKEM_X25519_HKDF_SHA256 = function ()
3248
3283
 
3249
3284
 
3250
3285
 
3286
+
3251
3287
 
3252
3288
  export const KEM_DHKEM_X448_HKDF_SHA512 = function () {
3253
3289
  const id = 0x0021
@@ -3391,6 +3427,7 @@ function MLKEM_SHARED() {
3391
3427
 
3392
3428
 
3393
3429
 
3430
+
3394
3431
 
3395
3432
 
3396
3433
  export const KEM_ML_KEM_512 = function () {
@@ -3432,6 +3469,7 @@ export const KEM_ML_KEM_512 = function () {
3432
3469
 
3433
3470
 
3434
3471
 
3472
+
3435
3473
  export const KEM_ML_KEM_768 = function () {
3436
3474
  const id = 0x0041
3437
3475
  const name = 'ML-KEM-768'
@@ -3471,6 +3509,7 @@ export const KEM_ML_KEM_768 = function () {
3471
3509
 
3472
3510
 
3473
3511
 
3512
+
3474
3513
  export const KEM_ML_KEM_1024 = function () {
3475
3514
  const id = 0x0042
3476
3515
  const name = 'ML-KEM-1024'
@@ -3557,6 +3596,7 @@ function AEAD_SHARED() {
3557
3596
 
3558
3597
 
3559
3598
 
3599
+
3560
3600
 
3561
3601
 
3562
3602
  export const AEAD_AES_128_GCM = function () {
@@ -3590,6 +3630,7 @@ export const AEAD_AES_128_GCM = function () {
3590
3630
 
3591
3631
 
3592
3632
 
3633
+
3593
3634
  export const AEAD_AES_256_GCM = function () {
3594
3635
  return {
3595
3636
  id: 0x0002,
@@ -3621,6 +3662,7 @@ export const AEAD_AES_256_GCM = function () {
3621
3662
 
3622
3663
 
3623
3664
 
3665
+
3624
3666
  export const AEAD_ChaCha20Poly1305 = function AEAD_ChaCha20Poly1305() {
3625
3667
  return {
3626
3668
  id: 0x0003,
@@ -3754,107 +3796,20 @@ function RandomScalarNist(t , seed ) {
3754
3796
  return bigIntToUint8Array(sk_bigint, t.Nscalar )
3755
3797
  }
3756
3798
 
3757
- async function expandDecapsKeyG(PQTKEM , _seed ) {
3758
- const Nout = PQTKEM.pq.Nseed + PQTKEM.t.Nseed
3759
- const bits = Nout << 3
3760
3799
 
3761
- const algorithm = { name: 'cSHAKE256', length: bits, outputLength: bits }
3762
- const seed = ab(_seed)
3763
- const seed_full = await subtle((c) => c.digest(algorithm, seed), PQTKEM.name)
3764
3800
 
3765
- const [_seed_PQ, seed_T] = split(PQTKEM.pq.Nseed, PQTKEM.t.Nseed, new Uint8Array(seed_full))
3766
- const seed_PQ = ab(_seed_PQ)
3767
3801
 
3768
3802
 
3769
- const format = 'raw-seed'
3770
3803
 
3771
- const usages = ['decapsulateBits', 'encapsulateBits']
3772
- const dk_PQ = await subtle(
3773
- (c) => c.importKey(format, seed_PQ, PQTKEM.pq.algorithm, true, [usages[0]]),
3774
- PQTKEM.name,
3775
- )
3776
- const ek_PQ = await getPublicKey(PQTKEM.name, dk_PQ, [usages[1]])
3777
3804
 
3778
- const sk = PQTKEM.t.RandomScalar?.(seed_T) ?? seed_T
3779
- const { privateKey: dk_T, publicKey: ek_T } = await PQTKEM.t.GetKeyPair(sk)
3780
3805
 
3781
- return { ek_PQ, ek_T, dk_PQ, dk_T }
3782
- }
3783
3806
 
3784
- async function C2PRICombiner(
3785
- PQTKEM ,
3786
- ss_PQ ,
3787
- ss_T ,
3788
- ct_T ,
3789
- _ek_T ,
3790
- label ,
3791
- ) {
3792
- const ek_T = new Uint8Array(await subtle((c) => c.exportKey('raw', _ek_T), PQTKEM.name))
3793
- const data = ab(concat(ss_PQ, ss_T, ct_T, ek_T, label))
3794
- return new Uint8Array(await subtle((c) => c.digest('SHA3-256', data), PQTKEM.name))
3795
- }
3796
3807
 
3797
- async function prepareEncapsG(
3798
- PQTKEM ,
3799
- ek_PQ ,
3800
- ek_T ,
3801
- ) {
3802
- const res = (await subtle(
3803
-
3804
- (c) => c.encapsulateBits(PQTKEM.pq.algorithm, ek_PQ),
3805
- PQTKEM.name,
3806
- ))
3807
- const ss_PQ = new Uint8Array(res.sharedKey)
3808
- const ct_PQ = new Uint8Array(res.ciphertext)
3809
-
3810
- const { privateKey: sk_E, publicKey } = (await subtle(
3811
- (c) => c.generateKey(PQTKEM.t.algorithm, true, ['deriveBits']),
3812
- PQTKEM.name,
3813
- ))
3814
- const ct_T = new Uint8Array(await subtle((c) => c.exportKey('raw', publicKey), PQTKEM.name))
3815
-
3816
- const ss_T = new Uint8Array(
3817
- await subtle(
3818
- (c) => c.deriveBits({ name: PQTKEM.t.algorithm.name, public: ek_T }, sk_E, PQTKEM.t.Nss << 3),
3819
- PQTKEM.name,
3820
- ),
3821
- )
3822
- checkNotAllZeros(ss_T)
3823
3808
 
3824
- return [ss_PQ, ss_T, ct_PQ, ct_T]
3825
- }
3826
3809
 
3827
- async function prepareDecapsG(
3828
- PQTKEM ,
3829
- dk_PQ ,
3830
- dk_T ,
3831
- ct_PQ ,
3832
- _ct_T ,
3833
- ) {
3834
- const ss_PQ = new Uint8Array(
3835
- await subtle(
3836
-
3837
- (c) => c.decapsulateBits(PQTKEM.pq.algorithm, dk_PQ, ct_PQ),
3838
- PQTKEM.name,
3839
- ),
3840
- )
3841
3810
 
3842
- const ct_T = ab(_ct_T)
3843
- const pub = await subtle(
3844
- (c) => c.importKey('raw', ct_T, PQTKEM.t.algorithm, true, []),
3845
- PQTKEM.name,
3846
- )
3847
3811
 
3848
- const ss_T = new Uint8Array(
3849
- await subtle(
3850
- (c) => c.deriveBits({ name: PQTKEM.t.algorithm.name, public: pub }, dk_T, PQTKEM.t.Nss << 3),
3851
- PQTKEM.name,
3852
- ),
3853
- )
3854
- checkNotAllZeros(ss_T)
3855
3812
 
3856
- return [ss_PQ, ss_T]
3857
- }
3858
3813
 
3859
3814
 
3860
3815
 
@@ -3884,121 +3839,213 @@ async function prepareDecapsG(
3884
3839
 
3885
3840
 
3886
3841
 
3887
- function PQTKEM_SHARED() {
3888
- Object.freeze(HybridKey.prototype)
3889
- return {
3890
- async DeriveKeyPair( ikm , extractable) {
3891
- const seed = await LabeledDerive(
3892
- this.kdf,
3893
- this.suite_id,
3894
- ikm,
3895
- encode('DeriveKeyPair'),
3896
- new Uint8Array(),
3897
- 32,
3898
- )
3899
3842
 
3900
- const { ek_PQ, ek_T, dk_PQ, dk_T } = await expandDecapsKeyG(this, seed)
3901
-
3902
- const publicKey = new HybridKey(priv, this.algorithm, 'public', true, ek_PQ, ek_T)
3903
- const privateKey = new HybridKey(
3904
- priv,
3905
- this.algorithm,
3906
- 'private',
3907
- extractable,
3908
- dk_PQ,
3909
- dk_T,
3910
- seed,
3911
- publicKey,
3912
- )
3913
3843
 
3914
- return { privateKey, publicKey }
3915
- },
3916
- async GenerateKeyPair( extractable) {
3917
- return await this.DeriveKeyPair(crypto.getRandomValues(new Uint8Array(32)), extractable)
3918
- },
3919
- async SerializePublicKey( key) {
3920
- assertKeyAlgorithm(key, this.algorithm)
3921
- HybridKey.validate(key, true)
3922
3844
 
3923
- const format = 'raw-public'
3924
- const ek_PQ = new Uint8Array(
3925
- await subtle((c) => c.exportKey(format, key.getPq(priv)), this.name),
3926
- )
3927
- const ek_T = new Uint8Array(
3928
- await subtle((c) => c.exportKey('raw', key.getT(priv)), this.name),
3929
- )
3930
3845
 
3931
- return concat(ek_PQ, ek_T)
3932
- },
3933
- async DeserializePublicKey( key) {
3934
3846
 
3935
- const format = 'raw-public'
3936
3847
 
3937
- const usages = ['encapsulateBits']
3938
- const pubPq = ab(key.subarray(0, this.pq.Npk))
3939
- const pubT = ab(key.subarray(this.pq.Npk))
3940
- const [ek_PQ, ek_T] = await Promise.all([
3941
- subtle((c) => c.importKey(format, pubPq, this.pq.algorithm, true, usages), this.name),
3942
- subtle((c) => c.importKey('raw', pubT, this.t.algorithm, true, []), this.name),
3943
- ])
3944
-
3945
- return new HybridKey(priv, this.algorithm, 'public', true, ek_PQ, ek_T)
3946
- },
3947
- async SerializePrivateKey( key) {
3948
- assertKeyAlgorithm(key, this.algorithm)
3949
- HybridKey.validate(key, true)
3950
3848
 
3951
- return key.getSeed(priv)
3952
- },
3953
- async DeserializePrivateKey( key, extractable) {
3954
- const { ek_PQ, ek_T, dk_PQ, dk_T } = await expandDecapsKeyG(this, key)
3955
- const publicKey = new HybridKey(priv, this.algorithm, 'public', true, ek_PQ, ek_T)
3956
- const privateKey = new HybridKey(
3957
- priv,
3958
- this.algorithm,
3959
- 'private',
3960
- extractable,
3961
- dk_PQ,
3962
- dk_T,
3963
- slice(key),
3964
- publicKey,
3965
- )
3966
3849
 
3967
- return privateKey
3968
- },
3969
- async Encap( pkR) {
3970
- assertKeyAlgorithm(pkR, this.algorithm)
3971
- HybridKey.validate(pkR)
3972
3850
 
3973
- const ek_PQ = pkR.getPq(priv)
3974
- const ek_T = pkR.getT(priv)
3975
- const [ss_PQ, ss_T, ct_PQ, ct_T] = await prepareEncapsG(this, ek_PQ, ek_T)
3976
- const ss_H = await C2PRICombiner(this, ss_PQ, ss_T, ct_T, ek_T, this.label)
3977
- const ct_H = concat(ct_PQ, ct_T)
3978
3851
 
3979
- return { shared_secret: ss_H, enc: ct_H }
3980
- },
3981
- async Decap( enc, skR, pkR) {
3982
- assertKeyAlgorithm(skR, this.algorithm)
3983
- HybridKey.validate(skR)
3984
3852
 
3985
- if (pkR) {
3986
- assertKeyAlgorithm(pkR, this.algorithm)
3987
- HybridKey.validate(pkR)
3988
- }
3989
3853
 
3990
- const [ct_PQ, ct_T] = split(this.pq.Nct, this.t.Nct, enc)
3991
- const ek = pkR ?? skR.getPublicKey(priv)
3992
- const ek_T = ek.getT(priv)
3993
- const dk_PQ = skR.getPq(priv)
3994
- const dk_T = skR.getT(priv)
3995
- const [ss_PQ, ss_T] = await prepareDecapsG(this, dk_PQ, dk_T, ct_PQ, ct_T)
3996
- const ss_H = await C2PRICombiner(this, ss_PQ, ss_T, ct_T, ek_T, this.label)
3997
3854
 
3998
- return ss_H
3999
- },
4000
- }
4001
- }
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
+
4002
4049
 
4003
4050
 
4004
4051
 
@@ -4078,6 +4125,7 @@ export const KEM_MLKEM768_X25519 = function () {
4078
4125
 
4079
4126
 
4080
4127
 
4128
+
4081
4129
  export const KEM_MLKEM768_P256 = function () {
4082
4130
  const id = 0x0050
4083
4131
  const name = 'MLKEM768-P256'
@@ -4133,6 +4181,7 @@ export const KEM_MLKEM768_P256 = function () {
4133
4181
 
4134
4182
 
4135
4183
 
4184
+
4136
4185
  export const KEM_MLKEM1024_P384 = function () {
4137
4186
  const id = 0x0051
4138
4187
  const name = 'MLKEM1024-P384'