hpke 1.1.6 → 1.1.7

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.
Files changed (4) hide show
  1. package/index.d.ts.map +1 -1
  2. package/index.js +692 -673
  3. package/index.ts +106 -87
  4. package/package.json +2 -2
package/index.js CHANGED
@@ -38,15 +38,15 @@
38
38
 
39
39
 
40
40
 
41
+
42
+
43
+
41
44
 
42
-
43
-
44
-
45
-
45
+
46
46
  function ComputeNonce(base_nonce , seq , Nn ) {
47
-
48
-
49
-
47
+
48
+
49
+
50
50
  const nonce = new Uint8Array(Nn)
51
51
  nonce.set(base_nonce)
52
52
  let s = seq
@@ -58,12 +58,12 @@ function ComputeNonce(base_nonce , seq , Nn )
58
58
  }
59
59
 
60
60
  function MaxSeq(Nn ) {
61
-
62
-
61
+
62
+
63
63
  return Math.min(2 ** (8 * Nn) - 1, Number.MAX_SAFE_INTEGER)
64
64
  }
65
65
 
66
-
66
+
67
67
  function IncrementSeq(seq , maxSeq ) {
68
68
  if (seq >= maxSeq) {
69
69
  throw new MessageLimitReachedError('Sequence number overflow')
@@ -71,7 +71,7 @@ function IncrementSeq(seq , maxSeq ) {
71
71
  return ++seq
72
72
  }
73
73
 
74
-
74
+
75
75
  async function ContextExport(
76
76
  suite ,
77
77
  exporterSecret ,
@@ -105,6 +105,36 @@ class Mutex {
105
105
  }
106
106
  }
107
107
 
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+ function createContextState(
120
+ suite ,
121
+ mode ,
122
+ key ,
123
+ base_nonce ,
124
+ exporter_secret ,
125
+ ) {
126
+ return {
127
+ suite,
128
+ mode,
129
+ key,
130
+ base_nonce,
131
+ exporter_secret,
132
+ max_seq: MaxSeq(suite.AEAD.Nn),
133
+ seq: 0,
134
+ mutex: undefined,
135
+ }
136
+ }
137
+
108
138
 
109
139
 
110
140
 
@@ -125,14 +155,7 @@ class Mutex {
125
155
 
126
156
 
127
157
  class SenderContext {
128
- #suite
129
- #key
130
- #base_nonce
131
- #exporter_secret
132
- #mode
133
- #seq = 0
134
- #max_seq
135
- #mutex
158
+ #state
136
159
 
137
160
  constructor(
138
161
  suite ,
@@ -141,34 +164,29 @@ class SenderContext {
141
164
  base_nonce ,
142
165
  exporter_secret ,
143
166
  ) {
144
- this.#suite = suite
145
- this.#mode = mode
146
- this.#key = key
147
- this.#base_nonce = base_nonce
148
- this.#exporter_secret = exporter_secret
149
- this.#max_seq = MaxSeq(suite.AEAD.Nn)
167
+ this.#state = createContextState(suite, mode, key, base_nonce, exporter_secret)
150
168
  }
151
169
 
152
-
170
+
153
171
 
154
172
 
155
173
 
156
174
 
157
175
  get mode() {
158
- return this.#mode
176
+ return this.#state.mode
159
177
  }
160
178
 
161
-
179
+
162
180
 
163
181
 
164
182
 
165
183
 
166
184
 
167
185
  get seq() {
168
- return this.#seq
186
+ return this.#state.seq
169
187
  }
170
188
 
171
-
189
+
172
190
 
173
191
 
174
192
 
@@ -198,28 +216,29 @@ class SenderContext {
198
216
  checkUint8Array(plaintext, 'plaintext')
199
217
  aad ??= new Uint8Array()
200
218
  checkUint8Array(aad, 'aad')
201
- if (this.#suite.AEAD.id === EXPORT_ONLY) {
219
+ const state = this.#state
220
+ if (state.suite.AEAD.id === EXPORT_ONLY) {
202
221
  throw new TypeError('Export-only AEAD cannot be used with Seal')
203
222
  }
204
223
 
205
- this.#mutex ??= new Mutex()
206
- const release = await this.#mutex.lock()
224
+ state.mutex ??= new Mutex()
225
+ const release = await state.mutex.lock()
207
226
  let ct
208
227
  try {
209
- ct = await this.#suite.AEAD.Seal(
210
- this.#key,
211
- ComputeNonce(this.#base_nonce, this.#seq, this.#suite.AEAD.Nn),
228
+ ct = await state.suite.AEAD.Seal(
229
+ state.key,
230
+ ComputeNonce(state.base_nonce, state.seq, state.suite.AEAD.Nn),
212
231
  aad,
213
232
  plaintext,
214
233
  )
215
- this.#seq = IncrementSeq(this.#seq, this.#max_seq)
234
+ state.seq = IncrementSeq(state.seq, state.max_seq)
216
235
  return ct
217
236
  } finally {
218
237
  release()
219
238
  }
220
239
  }
221
240
 
222
-
241
+
223
242
 
224
243
 
225
244
 
@@ -243,18 +262,23 @@ class SenderContext {
243
262
 
244
263
 
245
264
  async Export(exporterContext , length ) {
246
- return await ContextExport(this.#suite, this.#exporter_secret, exporterContext, length)
265
+ return await ContextExport(
266
+ this.#state.suite,
267
+ this.#state.exporter_secret,
268
+ exporterContext,
269
+ length,
270
+ )
247
271
  }
248
272
 
249
-
273
+
250
274
 
251
275
 
252
276
 
253
277
  get Nt() {
254
- return this.#suite.AEAD.Nt
278
+ return this.#state.suite.AEAD.Nt
255
279
  }
256
280
  }
257
-
281
+
258
282
 
259
283
 
260
284
 
@@ -276,14 +300,7 @@ class SenderContext {
276
300
 
277
301
 
278
302
  class RecipientContext {
279
- #suite
280
- #key
281
- #base_nonce
282
- #exporter_secret
283
- #mode
284
- #seq = 0
285
- #max_seq
286
- #mutex
303
+ #state
287
304
 
288
305
  constructor(
289
306
  suite ,
@@ -292,34 +309,29 @@ class RecipientContext {
292
309
  base_nonce ,
293
310
  exporter_secret ,
294
311
  ) {
295
- this.#suite = suite
296
- this.#mode = mode
297
- this.#key = key
298
- this.#base_nonce = base_nonce
299
- this.#exporter_secret = exporter_secret
300
- this.#max_seq = MaxSeq(suite.AEAD.Nn)
312
+ this.#state = createContextState(suite, mode, key, base_nonce, exporter_secret)
301
313
  }
302
314
 
303
-
315
+
304
316
 
305
317
 
306
318
 
307
319
 
308
320
  get mode() {
309
- return this.#mode
321
+ return this.#state.mode
310
322
  }
311
323
 
312
-
324
+
313
325
 
314
326
 
315
327
 
316
328
 
317
329
 
318
330
  get seq() {
319
- return this.#seq
331
+ return this.#state.seq
320
332
  }
321
333
 
322
-
334
+
323
335
 
324
336
 
325
337
 
@@ -351,18 +363,19 @@ class RecipientContext {
351
363
  aad ??= new Uint8Array()
352
364
  checkUint8Array(aad, 'aad')
353
365
 
354
- if (this.#suite.AEAD.id === EXPORT_ONLY) {
366
+ const state = this.#state
367
+ if (state.suite.AEAD.id === EXPORT_ONLY) {
355
368
  throw new TypeError('Export-only AEAD cannot be used with Open')
356
369
  }
357
370
 
358
- this.#mutex ??= new Mutex()
359
- const release = await this.#mutex.lock()
371
+ state.mutex ??= new Mutex()
372
+ const release = await state.mutex.lock()
360
373
  try {
361
374
  let pt
362
375
  try {
363
- pt = await this.#suite.AEAD.Open(
364
- this.#key,
365
- ComputeNonce(this.#base_nonce, this.#seq, this.#suite.AEAD.Nn),
376
+ pt = await state.suite.AEAD.Open(
377
+ state.key,
378
+ ComputeNonce(state.base_nonce, state.seq, state.suite.AEAD.Nn),
366
379
  aad,
367
380
  ciphertext,
368
381
  )
@@ -373,14 +386,14 @@ class RecipientContext {
373
386
 
374
387
  throw new OpenError('AEAD decryption failed', { cause })
375
388
  }
376
- this.#seq = IncrementSeq(this.#seq, this.#max_seq)
389
+ state.seq = IncrementSeq(state.seq, state.max_seq)
377
390
  return pt
378
391
  } finally {
379
392
  release()
380
393
  }
381
394
  }
382
395
 
383
-
396
+
384
397
 
385
398
 
386
399
 
@@ -404,14 +417,19 @@ class RecipientContext {
404
417
 
405
418
 
406
419
  async Export(exporterContext , length ) {
407
- return await ContextExport(this.#suite, this.#exporter_secret, exporterContext, length)
420
+ return await ContextExport(
421
+ this.#state.suite,
422
+ this.#state.exporter_secret,
423
+ exporterContext,
424
+ length,
425
+ )
408
426
  }
409
427
  }
428
+
410
429
 
411
-
412
-
413
-
414
-
430
+
431
+
432
+
415
433
 
416
434
  const validate = (factory , type ) => {
417
435
  try {
@@ -452,7 +470,7 @@ const validate = (factory , type )
452
470
  export class CipherSuite {
453
471
  #suite
454
472
 
455
-
473
+
456
474
 
457
475
 
458
476
 
@@ -526,24 +544,24 @@ export class CipherSuite {
526
544
  }
527
545
  }
528
546
 
529
-
547
+
530
548
 
531
549
 
532
550
 
533
551
 
534
552
  get KEM()
535
-
536
-
537
-
538
-
539
-
540
-
541
-
542
-
543
-
544
-
545
-
546
-
553
+
554
+
555
+
556
+
557
+
558
+
559
+
560
+
561
+
562
+
563
+
564
+
547
565
  {
548
566
  return {
549
567
  id: this.#suite.KEM.id,
@@ -555,28 +573,28 @@ export class CipherSuite {
555
573
  }
556
574
  }
557
575
 
558
-
576
+
559
577
 
560
578
 
561
579
 
562
580
 
563
581
  get KDF()
564
-
565
-
566
-
567
-
568
-
569
-
570
-
571
-
572
-
573
-
574
-
575
-
576
-
577
-
578
-
579
-
582
+
583
+
584
+
585
+
586
+
587
+
588
+
589
+
590
+
591
+
592
+
593
+
594
+
595
+
596
+
597
+
580
598
  {
581
599
  return {
582
600
  id: this.#suite.KDF.id,
@@ -586,23 +604,23 @@ export class CipherSuite {
586
604
  }
587
605
  }
588
606
 
589
-
607
+
590
608
 
591
609
 
592
610
 
593
611
 
594
612
 
595
613
  get AEAD()
596
-
597
-
598
-
599
-
600
-
601
-
602
-
603
-
604
-
605
-
614
+
615
+
616
+
617
+
618
+
619
+
620
+
621
+
622
+
623
+
606
624
  {
607
625
  return {
608
626
  id: this.#suite.AEAD.id,
@@ -613,7 +631,7 @@ export class CipherSuite {
613
631
  }
614
632
  }
615
633
 
616
-
634
+
617
635
 
618
636
 
619
637
 
@@ -636,7 +654,7 @@ export class CipherSuite {
636
654
  return await this.#suite.KEM.GenerateKeyPair(extractable)
637
655
  }
638
656
 
639
-
657
+
640
658
 
641
659
 
642
660
 
@@ -680,7 +698,7 @@ export class CipherSuite {
680
698
  }
681
699
  }
682
700
 
683
-
701
+
684
702
 
685
703
 
686
704
 
@@ -702,7 +720,7 @@ export class CipherSuite {
702
720
  return await this.#suite.KEM.SerializePrivateKey(privateKey)
703
721
  }
704
722
 
705
-
723
+
706
724
 
707
725
 
708
726
 
@@ -724,7 +742,7 @@ export class CipherSuite {
724
742
  return await this.#suite.KEM.SerializePublicKey(publicKey)
725
743
  }
726
744
 
727
-
745
+
728
746
 
729
747
 
730
748
 
@@ -761,7 +779,7 @@ export class CipherSuite {
761
779
  }
762
780
  }
763
781
 
764
-
782
+
765
783
 
766
784
 
767
785
 
@@ -794,7 +812,7 @@ export class CipherSuite {
794
812
  }
795
813
  }
796
814
 
797
-
815
+
798
816
 
799
817
 
800
818
 
@@ -841,7 +859,7 @@ export class CipherSuite {
841
859
  return { encapsulatedSecret, ciphertext }
842
860
  }
843
861
 
844
-
862
+
845
863
 
846
864
 
847
865
 
@@ -890,7 +908,7 @@ export class CipherSuite {
890
908
  return await ctx.Open(ciphertext, options?.aad)
891
909
  }
892
910
 
893
-
911
+
894
912
 
895
913
 
896
914
 
@@ -936,7 +954,7 @@ export class CipherSuite {
936
954
  return { encapsulatedSecret, exportedSecret }
937
955
  }
938
956
 
939
-
957
+
940
958
 
941
959
 
942
960
 
@@ -984,7 +1002,7 @@ export class CipherSuite {
984
1002
  return await ctx.Export(exporterContext, length)
985
1003
  }
986
1004
 
987
-
1005
+
988
1006
 
989
1007
 
990
1008
 
@@ -1060,7 +1078,7 @@ export class CipherSuite {
1060
1078
  return { encapsulatedSecret: enc, ctx }
1061
1079
  }
1062
1080
 
1063
-
1081
+
1064
1082
 
1065
1083
 
1066
1084
 
@@ -1152,9 +1170,9 @@ export class CipherSuite {
1152
1170
  }
1153
1171
  }
1154
1172
 
1155
-
1156
-
1157
-
1173
+
1174
+
1175
+
1158
1176
 
1159
1177
 
1160
1178
 
@@ -1166,7 +1184,7 @@ export class ValidationError extends Error {
1166
1184
  constructor(message , options ) {
1167
1185
  super(message, options)
1168
1186
  this.name = 'ValidationError'
1169
-
1187
+
1170
1188
  Error.captureStackTrace?.(this, ValidationError)
1171
1189
  }
1172
1190
  }
@@ -1181,7 +1199,7 @@ export class DeserializeError extends Error {
1181
1199
  constructor(message , options ) {
1182
1200
  super(message, options)
1183
1201
  this.name = 'DeserializeError'
1184
-
1202
+
1185
1203
  Error.captureStackTrace?.(this, DeserializeError)
1186
1204
  }
1187
1205
  }
@@ -1196,7 +1214,7 @@ export class EncapError extends Error {
1196
1214
  constructor(message , options ) {
1197
1215
  super(message, options)
1198
1216
  this.name = 'EncapError'
1199
-
1217
+
1200
1218
  Error.captureStackTrace?.(this, EncapError)
1201
1219
  }
1202
1220
  }
@@ -1211,7 +1229,7 @@ export class DecapError extends Error {
1211
1229
  constructor(message , options ) {
1212
1230
  super(message, options)
1213
1231
  this.name = 'DecapError'
1214
-
1232
+
1215
1233
  Error.captureStackTrace?.(this, DecapError)
1216
1234
  }
1217
1235
  }
@@ -1226,7 +1244,7 @@ export class OpenError extends Error {
1226
1244
  constructor(message , options ) {
1227
1245
  super(message, options)
1228
1246
  this.name = 'OpenError'
1229
-
1247
+
1230
1248
  Error.captureStackTrace?.(this, OpenError)
1231
1249
  }
1232
1250
  }
@@ -1241,7 +1259,7 @@ export class MessageLimitReachedError extends Error {
1241
1259
  constructor(message , options ) {
1242
1260
  super(message, options)
1243
1261
  this.name = 'MessageLimitReachedError'
1244
-
1262
+
1245
1263
  Error.captureStackTrace?.(this, MessageLimitReachedError)
1246
1264
  }
1247
1265
  }
@@ -1256,7 +1274,7 @@ export class DeriveKeyPairError extends Error {
1256
1274
  constructor(message , options ) {
1257
1275
  super(message, options)
1258
1276
  this.name = 'DeriveKeyPairError'
1259
-
1277
+
1260
1278
  Error.captureStackTrace?.(this, DeriveKeyPairError)
1261
1279
  }
1262
1280
  }
@@ -1271,21 +1289,21 @@ export class NotSupportedError extends Error {
1271
1289
  constructor(message , options ) {
1272
1290
  super(message, options)
1273
1291
  this.name = 'NotSupportedError'
1274
-
1292
+
1275
1293
  Error.captureStackTrace?.(this, NotSupportedError)
1276
1294
  }
1277
1295
  }
1278
1296
 
1297
+
1298
+
1299
+
1279
1300
 
1280
-
1281
-
1282
-
1283
-
1284
-
1285
-
1286
-
1287
-
1288
-
1301
+
1302
+
1303
+
1304
+
1305
+
1306
+
1289
1307
 
1290
1308
 
1291
1309
 
@@ -1308,6 +1326,8 @@ export const MODE_BASE = 0x00
1308
1326
 
1309
1327
  export const MODE_PSK = 0x01
1310
1328
 
1329
+
1330
+
1311
1331
 
1312
1332
 
1313
1333
 
@@ -1343,6 +1363,7 @@ export const MODE_PSK = 0x01
1343
1363
 
1344
1364
 
1345
1365
 
1366
+
1346
1367
 
1347
1368
 
1348
1369
 
@@ -1364,6 +1385,7 @@ export const MODE_PSK = 0x01
1364
1385
 
1365
1386
 
1366
1387
 
1388
+
1367
1389
 
1368
1390
 
1369
1391
 
@@ -1382,6 +1404,7 @@ export const MODE_PSK = 0x01
1382
1404
 
1383
1405
 
1384
1406
 
1407
+
1385
1408
 
1386
1409
 
1387
1410
 
@@ -1400,6 +1423,12 @@ export const MODE_PSK = 0x01
1400
1423
 
1401
1424
 
1402
1425
 
1426
+
1427
+
1428
+
1429
+
1430
+
1431
+
1403
1432
 
1404
1433
 
1405
1434
 
@@ -1411,8 +1440,19 @@ export const MODE_PSK = 0x01
1411
1440
 
1412
1441
 
1413
1442
 
1443
+
1444
+
1445
+
1446
+
1447
+
1448
+
1414
1449
 
1450
+
1451
+
1415
1452
 
1453
+
1454
+
1455
+
1416
1456
 
1417
1457
 
1418
1458
 
@@ -1421,6 +1461,11 @@ export const MODE_PSK = 0x01
1421
1461
 
1422
1462
 
1423
1463
 
1464
+
1465
+
1466
+
1467
+
1468
+
1424
1469
 
1425
1470
 
1426
1471
 
@@ -1430,43 +1475,16 @@ export const MODE_PSK = 0x01
1430
1475
 
1431
1476
 
1432
1477
 
1478
+
1479
+
1480
+
1481
+
1482
+
1483
+
1433
1484
 
1434
-
1435
-
1436
-
1437
-
1438
-
1439
-
1440
-
1441
-
1442
-
1443
-
1444
-
1445
-
1446
-
1447
-
1448
-
1449
-
1450
-
1451
-
1452
-
1453
-
1454
-
1455
-
1456
-
1457
-
1458
-
1459
-
1460
-
1461
-
1462
-
1463
-
1464
-
1465
-
1466
-
1467
-
1468
-
1469
-
1485
+
1486
+
1487
+
1470
1488
 
1471
1489
 
1472
1490
 
@@ -1515,10 +1533,10 @@ export function encode(string ) {
1515
1533
  return bytes
1516
1534
  }
1517
1535
 
1518
-
1519
-
1520
-
1521
-
1536
+
1537
+
1538
+
1539
+
1522
1540
  const L_HPKE_v1 = /* @__PURE__ */ encode('HPKE-v1')
1523
1541
  const L_HPKE = /* @__PURE__ */ encode('HPKE')
1524
1542
  const L_KEM = /* @__PURE__ */ encode('KEM')
@@ -1541,9 +1559,9 @@ function lengthPrefixed(x ) {
1541
1559
  return concat(I2OSP(x.byteLength, 2), x)
1542
1560
  }
1543
1561
 
1544
-
1545
-
1546
-
1562
+
1563
+
1564
+
1547
1565
 
1548
1566
 
1549
1567
 
@@ -1576,7 +1594,7 @@ export async function LabeledDerive(
1576
1594
  return await KDF.Derive(labeled_ikm, L)
1577
1595
  }
1578
1596
 
1579
-
1597
+
1580
1598
  async function Export_OneStage(
1581
1599
  KDF ,
1582
1600
  suite_id ,
@@ -1588,7 +1606,7 @@ async function Export_OneStage(
1588
1606
  return await LabeledDerive(KDF, suite_id, exporter_secret, L_sec, exporter_context, L)
1589
1607
  }
1590
1608
 
1591
-
1609
+
1592
1610
  async function CombineSecrets_OneStage(
1593
1611
  suite ,
1594
1612
  mode ,
@@ -1620,10 +1638,10 @@ async function CombineSecrets_OneStage(
1620
1638
  return { key, base_nonce, exporter_secret }
1621
1639
  }
1622
1640
 
1623
-
1624
-
1641
+
1642
+
1625
1643
  const MAX_LENGTH_TWO_STAGE = 0xffff
1626
-
1644
+
1627
1645
  const MAX_LENGTH_ONE_STAGE = 0xffff
1628
1646
 
1629
1647
  function checkLength(data , name , maxLength ) {
@@ -1645,7 +1663,7 @@ function checkExtractable(extractable )
1645
1663
  }
1646
1664
  }
1647
1665
 
1648
-
1666
+
1649
1667
  async function CombineSecrets_TwoStage(
1650
1668
  suite ,
1651
1669
  mode ,
@@ -1666,7 +1684,7 @@ async function CombineSecrets_TwoStage(
1666
1684
  const key_schedule_context = concat(I2OSP(mode, 1), psk_id_hash, info_hash)
1667
1685
  const secret = await LabeledExtract(suite.KDF, suite.id, shared_secret, L_secret, psk)
1668
1686
 
1669
-
1687
+
1670
1688
  if (suite.AEAD.id === EXPORT_ONLY) {
1671
1689
  const exporter_secret = await LabeledExpand(
1672
1690
  suite.KDF,
@@ -1688,7 +1706,7 @@ async function CombineSecrets_TwoStage(
1688
1706
  return { key, base_nonce, exporter_secret }
1689
1707
  }
1690
1708
 
1691
-
1709
+
1692
1710
  async function Export_TwoStage(
1693
1711
  KDF ,
1694
1712
  suite_id ,
@@ -1767,61 +1785,61 @@ async function Export_TwoStage(
1767
1785
 
1768
1786
 
1769
1787
 
1788
+
1789
+
1790
+
1770
1791
 
1792
+
1793
+
1771
1794
 
1795
+
1796
+
1772
1797
 
1798
+
1799
+
1800
+
1801
+
1802
+
1803
+
1773
1804
 
1805
+
1806
+
1774
1807
 
1808
+
1809
+
1810
+
1811
+
1812
+
1813
+
1814
+
1815
+
1816
+
1775
1817
 
1818
+
1819
+
1820
+
1821
+
1822
+
1823
+
1824
+
1825
+
1826
+
1827
+
1776
1828
 
1829
+
1830
+
1831
+
1832
+
1833
+
1834
+
1835
+
1836
+
1837
+
1838
+
1777
1839
 
1778
-
1779
-
1780
-
1781
-
1782
-
1783
-
1784
-
1785
-
1786
-
1787
-
1788
-
1789
-
1790
-
1791
-
1792
-
1793
-
1794
-
1795
-
1796
-
1797
-
1798
-
1799
-
1800
-
1801
-
1802
-
1803
-
1804
-
1805
-
1806
-
1807
-
1808
-
1809
-
1810
-
1811
-
1812
-
1813
-
1814
-
1815
-
1816
-
1817
-
1818
-
1819
-
1820
-
1821
-
1822
-
1823
-
1824
-
1840
+
1841
+
1842
+
1825
1843
 
1826
1844
 
1827
1845
 
@@ -1882,6 +1900,13 @@ export async function LabeledExpand(
1882
1900
  return await KDF.Expand(prk, labeled_info, L)
1883
1901
  }
1884
1902
 
1903
+
1904
+
1905
+
1906
+
1907
+
1908
+
1909
+
1885
1910
 
1886
1911
 
1887
1912
 
@@ -1973,21 +1998,152 @@ export async function LabeledExpand(
1973
1998
 
1974
1999
 
1975
2000
 
2001
+
2002
+
2003
+
1976
2004
 
2005
+
2006
+
1977
2007
 
2008
+
2009
+
1978
2010
 
2011
+
2012
+
1979
2013
 
2014
+
2015
+
1980
2016
 
2017
+
2018
+
1981
2019
 
2020
+
2021
+
1982
2022
 
2023
+
2024
+
2025
+
2026
+
2027
+
2028
+
2029
+
2030
+
2031
+
1983
2032
 
2033
+
2034
+
2035
+
2036
+
2037
+
2038
+
2039
+
2040
+
1984
2041
 
2042
+
2043
+
2044
+
2045
+
2046
+
2047
+
2048
+
2049
+
1985
2050
 
2051
+
2052
+
2053
+
2054
+
2055
+
2056
+
2057
+
2058
+
1986
2059
 
2060
+
2061
+
2062
+
2063
+
2064
+
2065
+
2066
+
2067
+
1987
2068
 
2069
+
2070
+
2071
+
2072
+
2073
+
2074
+
2075
+
2076
+
2077
+
2078
+
2079
+
2080
+
2081
+
2082
+
2083
+
2084
+
2085
+
2086
+
2087
+
2088
+
2089
+
2090
+
2091
+
2092
+
2093
+
2094
+
2095
+
2096
+
2097
+
2098
+
2099
+
2100
+
2101
+
2102
+
2103
+
2104
+
2105
+
2106
+
2107
+
2108
+ function isKeyPair (skR ) {
2109
+ if (!skR || typeof skR !== 'object') return false
2110
+ if ('publicKey' in skR && 'privateKey' in skR) {
2111
+ const pkR = skR.publicKey
2112
+ skR = skR.privateKey
2113
+ try {
2114
+ isKey(pkR, 'public')
2115
+ isKey(skR, 'private')
2116
+ if (pkR.algorithm.name !== skR.algorithm.name) {
2117
+ throw new TypeError('key pair algorithms do not match')
2118
+ }
2119
+ } catch (cause) {
2120
+ throw new TypeError('Invalid "privateKey"', { cause })
2121
+ }
2122
+ return true
2123
+ }
2124
+ return false
2125
+ }
1988
2126
 
2127
+ function isKey(key , type , extractable ) {
2128
+ const k = key
2129
+ if (
2130
+ typeof k.algorithm !== 'object' ||
2131
+ typeof k.algorithm.name !== 'string' ||
2132
+ typeof k.extractable !== 'boolean' ||
2133
+ typeof k.type !== 'string' ||
2134
+ k.type !== type
2135
+ ) {
2136
+ throw new TypeError(`Invalid "${type}Key"`)
2137
+ }
1989
2138
 
2139
+ if (extractable && k.extractable !== true) {
2140
+ throw new TypeError(`"${type}Key" must be extractable`)
2141
+ }
2142
+ }
1990
2143
 
2144
+
2145
+
2146
+
1991
2147
 
1992
2148
 
1993
2149
 
@@ -2044,197 +2200,59 @@ export async function LabeledExpand(
2044
2200
 
2045
2201
 
2046
2202
 
2203
+
2204
+
2205
+
2047
2206
 
2207
+
2208
+
2048
2209
 
2210
+
2211
+
2049
2212
 
2213
+
2214
+
2050
2215
 
2216
+
2217
+
2051
2218
 
2219
+
2220
+
2052
2221
 
2222
+
2223
+
2224
+
2225
+
2226
+
2227
+
2228
+
2229
+
2230
+
2231
+
2232
+
2233
+
2234
+
2235
+
2236
+
2237
+
2238
+
2053
2239
 
2240
+
2241
+
2242
+
2243
+
2244
+
2245
+
2246
+
2247
+
2248
+
2249
+
2250
+
2251
+
2054
2252
 
2055
-
2056
-
2057
-
2058
-
2059
-
2060
-
2061
-
2062
-
2063
-
2064
-
2065
-
2066
-
2067
-
2068
-
2069
-
2070
-
2071
-
2072
-
2073
-
2074
-
2075
-
2076
-
2077
-
2078
-
2079
-
2080
-
2081
-
2082
-
2083
-
2084
-
2085
-
2086
-
2087
-
2088
-
2089
-
2090
- function isKeyPair (skR ) {
2091
- if (!skR || typeof skR !== 'object') return false
2092
- if ('publicKey' in skR && 'privateKey' in skR) {
2093
- const pkR = skR.publicKey
2094
- skR = skR.privateKey
2095
- try {
2096
- isKey(pkR, 'public')
2097
- isKey(skR, 'private')
2098
- if (pkR.algorithm.name !== skR.algorithm.name) {
2099
- throw new TypeError('key pair algorithms do not match')
2100
- }
2101
- } catch (cause) {
2102
- throw new TypeError('Invalid "privateKey"', { cause })
2103
- }
2104
- return true
2105
- }
2106
- return false
2107
- }
2108
-
2109
- function isKey(key , type , extractable ) {
2110
- const k = key
2111
- if (
2112
- typeof k.algorithm !== 'object' ||
2113
- typeof k.algorithm.name !== 'string' ||
2114
- typeof k.extractable !== 'boolean' ||
2115
- typeof k.type !== 'string' ||
2116
- k.type !== type
2117
- ) {
2118
- throw new TypeError(`Invalid "${type}Key"`)
2119
- }
2120
-
2121
- if (extractable && k.extractable !== true) {
2122
- throw new TypeError(`"${type}Key" must be extractable`)
2123
- }
2124
- }
2125
-
2126
-
2127
-
2128
-
2129
-
2130
-
2131
-
2132
-
2133
-
2134
-
2135
-
2136
-
2137
-
2138
-
2139
-
2140
-
2141
-
2142
-
2143
-
2144
-
2145
-
2146
-
2147
-
2148
-
2149
-
2150
-
2151
-
2152
-
2153
-
2154
-
2155
-
2156
-
2157
-
2158
-
2159
-
2160
-
2161
-
2162
-
2163
-
2164
-
2165
-
2166
-
2167
-
2168
-
2169
-
2170
-
2171
-
2172
-
2173
-
2174
-
2175
-
2176
-
2177
-
2178
-
2179
-
2180
-
2181
-
2182
-
2183
-
2184
-
2185
-
2186
-
2187
-
2188
-
2189
-
2190
-
2191
-
2192
-
2193
-
2194
-
2195
-
2196
-
2197
-
2198
-
2199
-
2200
-
2201
-
2202
-
2203
-
2204
-
2205
-
2206
-
2207
-
2208
-
2209
-
2210
-
2211
-
2212
-
2213
-
2214
-
2215
-
2216
-
2217
-
2218
-
2219
-
2220
-
2221
-
2222
-
2223
-
2224
-
2225
-
2226
-
2227
-
2228
-
2229
-
2230
-
2231
-
2232
-
2233
-
2234
-
2235
-
2236
-
2237
-
2253
+
2254
+
2255
+
2238
2256
 
2239
2257
 
2240
2258
 
@@ -2272,11 +2290,11 @@ function KDFStages(KDF ) {
2272
2290
  if (KDF.stages === 1 || KDF.stages === 2) {
2273
2291
  return KDF.stages
2274
2292
  }
2275
-
2293
+
2276
2294
  throw new Error('unreachable')
2277
2295
  }
2278
2296
 
2279
-
2297
+
2280
2298
  async function KeySchedule(
2281
2299
  suite ,
2282
2300
  mode ,
@@ -2299,7 +2317,7 @@ async function KeySchedule(
2299
2317
  return await CombineSecrets(suite, mode, shared_secret, info, psk, pskId)
2300
2318
  }
2301
2319
 
2302
-
2320
+
2303
2321
  function VerifyPSKInputs(psk , psk_id ) {
2304
2322
  if (psk.byteLength && psk_id.byteLength) {
2305
2323
  if (psk.byteLength < 32) {
@@ -2313,7 +2331,7 @@ function VerifyPSKInputs(psk , psk_id ) {
2313
2331
  throw new TypeError('Inconsistent PSK inputs')
2314
2332
  }
2315
2333
 
2316
-
2334
+
2317
2335
  const NotApplicable = () => {
2318
2336
  throw new Error('unreachable')
2319
2337
  }
@@ -2346,9 +2364,9 @@ export const AEAD_EXPORT_ONLY = function () {
2346
2364
  }
2347
2365
  }
2348
2366
 
2349
-
2350
-
2351
-
2367
+
2368
+
2369
+
2352
2370
 
2353
2371
  async function subtle (promise , name ) {
2354
2372
  try {
@@ -2364,20 +2382,40 @@ async function subtle (promise , name
2364
2382
  }
2365
2383
  }
2366
2384
 
2385
+
2386
+
2387
+
2367
2388
 
2389
+
2368
2390
 
2391
+
2392
+
2393
+
2394
+
2369
2395
 
2396
+ async function getCachedCryptoKey(
2397
+ cache ,
2398
+ keyBytes ,
2399
+ init ,
2400
+ ) {
2401
+ const cached = cache.get(keyBytes)
2402
+ if (
2403
+ cached &&
2404
+ cached.bytes.byteLength === keyBytes.byteLength &&
2405
+ cached.bytes.every((byte, index) => byte === keyBytes[index])
2406
+ ) {
2407
+ return cached.key
2408
+ }
2370
2409
 
2371
-
2372
-
2373
- async function cacheValue (
2374
- cache ,
2375
- key ,
2376
- init ,
2377
- ) {
2378
- const result = await init()
2379
- cache.set(key, result)
2380
- return result
2410
+ const bytes = slice(keyBytes)
2411
+ const entry = { bytes, key: init(bytes) }
2412
+ cache.set(keyBytes, entry)
2413
+ try {
2414
+ return await entry.key
2415
+ } catch (cause) {
2416
+ if (cache.get(keyBytes) === entry) cache.delete(keyBytes)
2417
+ throw cause
2418
+ }
2381
2419
  }
2382
2420
 
2383
2421
  function HKDF_SHARED() {
@@ -2388,12 +2426,7 @@ function HKDF_SHARED() {
2388
2426
  this.name,
2389
2427
  )
2390
2428
  }
2391
- const cache = new WeakMap ()
2392
- function importPrk( prk ) {
2393
- const key = importKey.call(this, prk )
2394
- cache.set(prk, key)
2395
- return key
2396
- }
2429
+ const cache = new WeakMap ()
2397
2430
  return {
2398
2431
  stages: 2,
2399
2432
  Derive: NotApplicable,
@@ -2414,7 +2447,9 @@ function HKDF_SHARED() {
2414
2447
  throw new Error('L must be <= 255*Nh')
2415
2448
  }
2416
2449
  const N = Math.ceil(L / this.Nh)
2417
- const key = await (cache.get(prk) ?? importPrk.call(this, prk))
2450
+ const key = await getCachedCryptoKey(cache, prk, (bytes) =>
2451
+ importKey.call(this, bytes ),
2452
+ )
2418
2453
 
2419
2454
  const T = new Uint8Array(N * this.Nh)
2420
2455
  let T_prev = new Uint8Array()
@@ -2436,9 +2471,9 @@ function HKDF_SHARED() {
2436
2471
  }
2437
2472
  }
2438
2473
 
2439
-
2440
-
2441
-
2474
+
2475
+
2476
+
2442
2477
 
2443
2478
 
2444
2479
 
@@ -2509,13 +2544,13 @@ export const KDF_HKDF_SHA512 = function () {
2509
2544
  return { id: 0x0003, type: 'KDF', name: 'HKDF-SHA512', Nh: 64, hash: 'SHA-512', ...HKDF_SHARED() }
2510
2545
  }
2511
2546
 
2547
+
2548
+
2549
+
2512
2550
 
2513
-
2514
-
2515
-
2516
-
2517
-
2518
-
2551
+
2552
+
2553
+
2519
2554
 
2520
2555
  async function ShakeDerive(name , variant , ikm , L ) {
2521
2556
  const bits = L << 3
@@ -2679,41 +2714,30 @@ async function getPublicKeyByExport(
2679
2714
 
2680
2715
  async function getPublicKey(name , key , usages ) {
2681
2716
  return (
2682
-
2717
+
2683
2718
  ((await subtle((c) => c.getPublicKey?.(key, usages), name)) ) ||
2684
2719
  (await getPublicKeyByExport(name, key, usages))
2685
2720
  )
2686
2721
  }
2687
2722
 
2688
-
2689
- function checkNotAllZeros(buffer ) {
2690
- let or = 0
2691
- for (let i = 0; i < buffer.length; i++) {
2692
- or |= buffer[i]
2693
- }
2694
- if (or === 0) {
2695
- throw new ValidationError('DH shared secret is an all-zero value')
2696
- }
2697
- }
2698
-
2699
-
2700
-
2701
-
2702
-
2703
-
2704
-
2705
-
2706
-
2707
-
2708
-
2709
-
2710
-
2711
-
2712
-
2713
-
2714
-
2715
-
2716
-
2723
+
2724
+
2725
+
2726
+
2727
+
2728
+
2729
+
2730
+
2731
+
2732
+
2733
+
2734
+
2735
+
2736
+
2737
+
2738
+
2739
+
2740
+
2717
2741
 
2718
2742
  function fromBase64(input ) {
2719
2743
  input = input.replace(/-/g, '+').replace(/_/g, '/')
@@ -2734,20 +2758,20 @@ function toBase64Url(bytes ) {
2734
2758
  }
2735
2759
 
2736
2760
  function toB64u(input ) {
2737
-
2761
+
2738
2762
  return input.toBase64?.({ alphabet: 'base64url', omitPadding: true }) || toBase64Url(input)
2739
2763
  }
2740
2764
 
2741
2765
  function b64u(input ) {
2742
-
2766
+
2743
2767
  return Uint8Array.fromBase64?.(input, { alphabet: 'base64url' }) || fromBase64(input)
2744
2768
  }
2745
2769
 
2770
+
2771
+
2772
+
2746
2773
 
2747
-
2748
-
2749
-
2750
-
2774
+
2751
2775
  async function DeriveKeyPairBytes(
2752
2776
  DHKEM ,
2753
2777
  ikm ,
@@ -2797,14 +2821,14 @@ function assertKeyAlgorithm(key , expectedAlgorithm ) {
2797
2821
  }
2798
2822
 
2799
2823
  function assertCryptoKey(key ) {
2800
-
2824
+
2801
2825
  if (key[Symbol.toStringTag] !== 'CryptoKey') {
2802
2826
  if (key instanceof CryptoKey) return
2803
2827
  throw new TypeError('unexpected key constructor')
2804
2828
  }
2805
2829
  }
2806
2830
 
2807
-
2831
+
2808
2832
  async function ExtractAndExpand_OneStage(
2809
2833
  DHKEM ,
2810
2834
  dh ,
@@ -2820,7 +2844,7 @@ async function ExtractAndExpand_OneStage(
2820
2844
  )
2821
2845
  }
2822
2846
 
2823
-
2847
+
2824
2848
  async function ExtractAndExpand_TwoStage(
2825
2849
  DHKEM ,
2826
2850
  dh ,
@@ -2837,7 +2861,7 @@ async function ExtractAndExpand_TwoStage(
2837
2861
  )
2838
2862
  }
2839
2863
 
2840
-
2864
+
2841
2865
  async function ExtractAndExpand(
2842
2866
  DHKEM ,
2843
2867
  dh ,
@@ -2847,12 +2871,12 @@ async function ExtractAndExpand(
2847
2871
  return await Fn(DHKEM, dh, kem_context)
2848
2872
  }
2849
2873
 
2850
-
2851
-
2852
-
2874
+
2875
+
2876
+
2853
2877
 
2854
2878
  function DHKEM_SHARED()
2855
-
2879
+
2856
2880
  {
2857
2881
  return {
2858
2882
  async GenerateKeyPair( extractable) {
@@ -2886,15 +2910,14 @@ function DHKEM_SHARED()
2886
2910
  const skE = ekp.privateKey
2887
2911
  const pkE = ekp.publicKey
2888
2912
 
2889
-
2890
-
2913
+
2914
+
2891
2915
  const dh = new Uint8Array(
2892
2916
  await subtle(
2893
2917
  (c) => c.deriveBits({ name: skE.algorithm.name, public: pkR }, skE, this.Ndh << 3),
2894
2918
  this.name,
2895
2919
  ),
2896
2920
  )
2897
- checkNotAllZeros(dh)
2898
2921
 
2899
2922
  const enc = await this.SerializePublicKey(pkE)
2900
2923
  const pkRm = await this.SerializePublicKey(pkR)
@@ -2914,15 +2937,14 @@ function DHKEM_SHARED()
2914
2937
 
2915
2938
  const pkE = (await this.DeserializePublicKey(enc))
2916
2939
 
2917
-
2918
-
2940
+
2941
+
2919
2942
  const dh = new Uint8Array(
2920
2943
  await subtle(
2921
2944
  (c) => c.deriveBits({ name: skR.algorithm.name, public: pkE }, skR, this.Ndh << 3),
2922
2945
  this.name,
2923
2946
  ),
2924
2947
  )
2925
- checkNotAllZeros(dh)
2926
2948
 
2927
2949
  const pkRm = await this.SerializePublicKey(pkR)
2928
2950
  const kem_context = concat(enc, pkRm)
@@ -2932,9 +2954,9 @@ function DHKEM_SHARED()
2932
2954
  }
2933
2955
  }
2934
2956
 
2935
-
2936
-
2937
-
2957
+
2958
+
2959
+
2938
2960
 
2939
2961
  async function createKeyPairFromPrivateKey(
2940
2962
  DHKEM ,
@@ -2943,7 +2965,7 @@ async function createKeyPairFromPrivateKey(
2943
2965
  ) {
2944
2966
  let privateKey
2945
2967
  let publicKey
2946
-
2968
+
2947
2969
  if (!extractable && typeof crypto.subtle.getPublicKey !== 'function') {
2948
2970
  privateKey = (await DHKEM.DeserializePrivateKey(key, true))
2949
2971
  publicKey = await getPublicKey(DHKEM.name, privateKey, [])
@@ -2973,21 +2995,21 @@ async function CurveKeyFromD(
2973
2995
  )
2974
2996
  }
2975
2997
 
2976
-
2977
-
2978
-
2979
-
2980
-
2981
-
2982
-
2983
-
2984
-
2985
-
2986
-
2987
-
2988
-
2989
-
2990
-
2998
+
2999
+
3000
+
3001
+
3002
+
3003
+
3004
+
3005
+
3006
+
3007
+
3008
+
3009
+
3010
+
3011
+
3012
+
2991
3013
 
2992
3014
  async function importKeyNist(
2993
3015
  curve ,
@@ -3001,7 +3023,7 @@ async function importKeyNist(
3001
3023
  throw new Error('Invalid scalar')
3002
3024
  }
3003
3025
 
3004
-
3026
+
3005
3027
  const pkcs8 = concat(curve.pkcs8, key)
3006
3028
  return await subtle(async (c) => {
3007
3029
  async function fromJwk(jwk , privateKey ) {
@@ -3016,7 +3038,7 @@ async function importKeyNist(
3016
3038
  }
3017
3039
 
3018
3040
  let privateKey
3019
-
3041
+
3020
3042
  const nativePublicKey = typeof c.getPublicKey === 'function'
3021
3043
  try {
3022
3044
  privateKey = await c.importKey(
@@ -3027,8 +3049,8 @@ async function importKeyNist(
3027
3049
  ['deriveBits'],
3028
3050
  )
3029
3051
  if (nativePublicKey) {
3030
-
3031
-
3052
+
3053
+
3032
3054
  const recovered = await c.getPublicKey(privateKey, [])
3033
3055
  return { privateKey, publicKey: includePublicKey ? recovered : undefined }
3034
3056
  }
@@ -3038,10 +3060,10 @@ async function importKeyNist(
3038
3060
  extractable ? privateKey : undefined,
3039
3061
  )
3040
3062
  } catch (cause) {
3041
-
3042
-
3043
-
3044
-
3063
+
3064
+
3065
+
3066
+
3045
3067
  if (
3046
3068
  !(cause instanceof DOMException) ||
3047
3069
  (cause.name !== 'DataError' && cause.name !== 'OperationError')
@@ -3063,15 +3085,15 @@ async function importKeyNist(
3063
3085
  : await c.importKey('jwk', jwk, signingAlgorithm, false, ['sign'])
3064
3086
  privateKey ??= await c.importKey('jwk', jwk, curve.algorithm, false, ['deriveBits'])
3065
3087
 
3066
-
3067
-
3088
+
3089
+
3068
3090
  const generatorKey = await c.importKey('jwk', generator, curve.algorithm, true, [])
3069
3091
  const x = new Uint8Array(
3070
3092
  await c.deriveBits({ name: 'ECDH', public: generatorKey }, privateKey, curve.Nsk << 3),
3071
3093
  )
3072
3094
 
3073
-
3074
-
3095
+
3096
+
3075
3097
  const message = L_public_key_recovery
3076
3098
  const signatureAlgorithm = { name: 'ECDSA', hash: 'SHA-256' }
3077
3099
  const signature = await c.sign(signatureAlgorithm, signingKey, message)
@@ -3090,16 +3112,16 @@ async function importKeyNist(
3090
3112
  }
3091
3113
 
3092
3114
  async function DeserializePrivateKeyNist(
3093
-
3115
+
3094
3116
  key ,
3095
3117
  extractable ,
3096
3118
  ) {
3097
3119
  return (await importKeyNist(this, key, this.name, extractable, false)).privateKey
3098
3120
  }
3099
3121
 
3100
-
3122
+
3101
3123
  async function DeriveKeyPairNist(
3102
-
3124
+
3103
3125
  ikm ,
3104
3126
  extractable ,
3105
3127
  ) {
@@ -3128,19 +3150,19 @@ async function GetKeyPairNist(
3128
3150
  return (await importKeyNist(curveConfig, sk, name, extractable, true))
3129
3151
  }
3130
3152
 
3153
+
3154
+
3155
+
3131
3156
 
3132
-
3133
-
3134
-
3135
-
3157
+
3136
3158
  async function DeriveKeyPairX( ikm , extractable ) {
3137
3159
  const sk = await DeriveKeyPairBytes(this, ikm, L_sk, new Uint8Array())
3138
3160
  return await createKeyPairFromPrivateKey(this, sk, extractable)
3139
3161
  }
3140
3162
 
3141
-
3142
-
3143
-
3163
+
3164
+
3165
+
3144
3166
 
3145
3167
  const P256 = {
3146
3168
  algorithm: { name: 'ECDH', namedCurve: 'P-256' },
@@ -3148,8 +3170,8 @@ const P256 = {
3148
3170
  Nsk: 32,
3149
3171
  order: 0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551n,
3150
3172
  bitmask: 0xff,
3151
- pkcs8: /* @__PURE__ */ Uint8Array.of(0x30, 0x41, 0x02, 0x01, 0x00, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x04, 0x27, 0x30, 0x25, 0x02, 0x01, 0x01, 0x04, 0x20),
3152
- spki: /* @__PURE__ */ Uint8Array.of(0x30, 0x39, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x22, 0x00),
3173
+ pkcs8: /* @__PURE__ */ Uint8Array.of(0x30, 0x41, 0x02, 0x01, 0x00, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x04, 0x27, 0x30, 0x25, 0x02, 0x01, 0x01, 0x04, 0x20),
3174
+ spki: /* @__PURE__ */ Uint8Array.of(0x30, 0x39, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x22, 0x00),
3153
3175
  Gx: 0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296n,
3154
3176
  Gy: 0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5n,
3155
3177
  }
@@ -3179,7 +3201,7 @@ export const KEM_DHKEM_P256_HKDF_SHA256 = function ()
3179
3201
  const id = 0x0010
3180
3202
  const name = 'DHKEM(P-256, HKDF-SHA256)'
3181
3203
  const kdf = KDF_HKDF_SHA256()
3182
-
3204
+
3183
3205
  kdf.name = name
3184
3206
  return {
3185
3207
  id,
@@ -3204,8 +3226,8 @@ const P384 = {
3204
3226
  order:
3205
3227
  0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973n,
3206
3228
  bitmask: 0xff,
3207
- pkcs8: /* @__PURE__ */ Uint8Array.of(0x30, 0x4e, 0x02, 0x01, 0x00, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x22, 0x04, 0x37, 0x30, 0x35, 0x02, 0x01, 0x01, 0x04, 0x30),
3208
- spki: /* @__PURE__ */ Uint8Array.of(0x30, 0x46, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x22, 0x03, 0x32, 0x00),
3229
+ pkcs8: /* @__PURE__ */ Uint8Array.of(0x30, 0x4e, 0x02, 0x01, 0x00, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x22, 0x04, 0x37, 0x30, 0x35, 0x02, 0x01, 0x01, 0x04, 0x30),
3230
+ spki: /* @__PURE__ */ Uint8Array.of(0x30, 0x46, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x22, 0x03, 0x32, 0x00),
3209
3231
  Gx: 0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7n,
3210
3232
  Gy: 0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5fn,
3211
3233
  }
@@ -3235,7 +3257,7 @@ export const KEM_DHKEM_P384_HKDF_SHA384 = function ()
3235
3257
  const id = 0x0011
3236
3258
  const name = 'DHKEM(P-384, HKDF-SHA384)'
3237
3259
  const kdf = KDF_HKDF_SHA384()
3238
-
3260
+
3239
3261
  kdf.name = name
3240
3262
  return {
3241
3263
  id,
@@ -3260,8 +3282,8 @@ const P521 = {
3260
3282
  order:
3261
3283
  0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409n,
3262
3284
  bitmask: 0x01,
3263
- pkcs8: /* @__PURE__ */ Uint8Array.of(0x30, 0x60, 0x02, 0x01, 0x00, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x23, 0x04, 0x49, 0x30, 0x47, 0x02, 0x01, 0x01, 0x04, 0x42),
3264
- spki: /* @__PURE__ */ Uint8Array.of(0x30, 0x58, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x23, 0x03, 0x44, 0x00),
3285
+ pkcs8: /* @__PURE__ */ Uint8Array.of(0x30, 0x60, 0x02, 0x01, 0x00, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x23, 0x04, 0x49, 0x30, 0x47, 0x02, 0x01, 0x01, 0x04, 0x42),
3286
+ spki: /* @__PURE__ */ Uint8Array.of(0x30, 0x58, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x23, 0x03, 0x44, 0x00),
3265
3287
  Gx: 0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66n,
3266
3288
  Gy: 0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650n,
3267
3289
  }
@@ -3291,7 +3313,7 @@ export const KEM_DHKEM_P521_HKDF_SHA512 = function ()
3291
3313
  const id = 0x0012
3292
3314
  const name = 'DHKEM(P-521, HKDF-SHA512)'
3293
3315
  const kdf = KDF_HKDF_SHA512()
3294
-
3316
+
3295
3317
  kdf.name = name
3296
3318
  return {
3297
3319
  id,
@@ -3309,9 +3331,9 @@ export const KEM_DHKEM_P521_HKDF_SHA512 = function ()
3309
3331
  }
3310
3332
  }
3311
3333
 
3312
-
3313
-
3314
-
3334
+
3335
+
3336
+
3315
3337
 
3316
3338
 
3317
3339
 
@@ -3334,12 +3356,12 @@ export const KEM_DHKEM_P521_HKDF_SHA512 = function ()
3334
3356
 
3335
3357
 
3336
3358
  export const KEM_DHKEM_X25519_HKDF_SHA256 = function ()
3337
-
3359
+
3338
3360
  {
3339
3361
  const id = 0x0020
3340
3362
  const name = 'DHKEM(X25519, HKDF-SHA256)'
3341
3363
  const kdf = KDF_HKDF_SHA256()
3342
-
3364
+
3343
3365
  kdf.name = name
3344
3366
  return {
3345
3367
  id,
@@ -3353,7 +3375,7 @@ export const KEM_DHKEM_X25519_HKDF_SHA256 = function ()
3353
3375
  Nsk: 32,
3354
3376
  Ndh: 32,
3355
3377
  algorithm: { name: 'X25519' },
3356
- pkcs8: Uint8Array.of(0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e, 0x04, 0x22, 0x04, 0x20),
3378
+ pkcs8: Uint8Array.of(0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e, 0x04, 0x22, 0x04, 0x20),
3357
3379
  DeriveKeyPair: DeriveKeyPairX,
3358
3380
  async DeserializePrivateKey(key, extractable) {
3359
3381
  return await CurveKeyFromD(name, this.Nsk, this.pkcs8, this.algorithm, key, extractable)
@@ -3383,12 +3405,12 @@ export const KEM_DHKEM_X25519_HKDF_SHA256 = function ()
3383
3405
 
3384
3406
 
3385
3407
  export const KEM_DHKEM_X448_HKDF_SHA512 = function ()
3386
-
3408
+
3387
3409
  {
3388
3410
  const id = 0x0021
3389
3411
  const name = 'DHKEM(X448, HKDF-SHA512)'
3390
3412
  const kdf = KDF_HKDF_SHA512()
3391
-
3413
+
3392
3414
  kdf.name = name
3393
3415
  return {
3394
3416
  id,
@@ -3402,7 +3424,7 @@ export const KEM_DHKEM_X448_HKDF_SHA512 = function ()
3402
3424
  Nsk: 56,
3403
3425
  Ndh: 56,
3404
3426
  algorithm: { name: 'X448' },
3405
- pkcs8: Uint8Array.of(0x30, 0x46, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6f, 0x04, 0x3a, 0x04, 0x38),
3427
+ pkcs8: Uint8Array.of(0x30, 0x46, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6f, 0x04, 0x3a, 0x04, 0x38),
3406
3428
  DeriveKeyPair: DeriveKeyPairX,
3407
3429
  async DeserializePrivateKey(key, extractable) {
3408
3430
  return await CurveKeyFromD(name, this.Nsk, this.pkcs8, this.algorithm, key, extractable)
@@ -3411,17 +3433,17 @@ export const KEM_DHKEM_X448_HKDF_SHA512 = function ()
3411
3433
  }
3412
3434
  }
3413
3435
 
3436
+
3437
+
3438
+
3414
3439
 
3440
+
3415
3441
 
3416
-
3417
-
3418
-
3419
-
3420
-
3421
-
3422
-
3423
-
3424
-
3442
+
3443
+
3444
+
3445
+
3446
+
3425
3447
 
3426
3448
  function DIRECT_KEM_SHARED() {
3427
3449
  return {
@@ -3436,14 +3458,14 @@ function DIRECT_KEM_SHARED() {
3436
3458
  )
3437
3459
 
3438
3460
  const privateKey = (await this.DeserializePrivateKey(dk, extractable))
3439
-
3461
+
3440
3462
  const usages = ['encapsulateBits']
3441
3463
  const publicKey = await getPublicKey(this.name, privateKey, usages)
3442
3464
 
3443
3465
  return { privateKey, publicKey }
3444
3466
  },
3445
3467
  async GenerateKeyPair( extractable) {
3446
-
3468
+
3447
3469
  const usages = ['encapsulateBits', 'decapsulateBits']
3448
3470
  return (await subtle(
3449
3471
  (c) => c.generateKey(this.algorithm, extractable, usages),
@@ -3453,14 +3475,14 @@ function DIRECT_KEM_SHARED() {
3453
3475
  async SerializePublicKey( key) {
3454
3476
  assertKeyAlgorithm(key, this.algorithm)
3455
3477
  assertCryptoKey(key)
3456
-
3478
+
3457
3479
  const format = 'raw-public'
3458
3480
  return new Uint8Array(await subtle((c) => c.exportKey(format, key), this.name))
3459
3481
  },
3460
3482
  async DeserializePublicKey( key) {
3461
-
3483
+
3462
3484
  const format = 'raw-public'
3463
-
3485
+
3464
3486
  const usages = ['encapsulateBits']
3465
3487
  return await subtle(
3466
3488
  (c) => c.importKey(format, key , this.algorithm, true, usages),
@@ -3470,14 +3492,14 @@ function DIRECT_KEM_SHARED() {
3470
3492
  async SerializePrivateKey( key) {
3471
3493
  assertKeyAlgorithm(key, this.algorithm)
3472
3494
  assertCryptoKey(key)
3473
-
3495
+
3474
3496
  const format = 'raw-seed'
3475
3497
  return new Uint8Array(await subtle((c) => c.exportKey(format, key), this.name))
3476
3498
  },
3477
3499
  async DeserializePrivateKey( key, extractable) {
3478
-
3500
+
3479
3501
  const format = 'raw-seed'
3480
-
3502
+
3481
3503
  const usages = ['decapsulateBits']
3482
3504
  return await subtle(
3483
3505
  (c) => c.importKey(format, key , this.algorithm, extractable, usages),
@@ -3488,7 +3510,7 @@ function DIRECT_KEM_SHARED() {
3488
3510
  assertKeyAlgorithm(pkR, this.algorithm)
3489
3511
 
3490
3512
  const { sharedKey, ciphertext } = (await subtle(
3491
-
3513
+
3492
3514
  (c) => c.encapsulateBits(this.algorithm, pkR),
3493
3515
  this.name,
3494
3516
  ))
@@ -3499,7 +3521,7 @@ function DIRECT_KEM_SHARED() {
3499
3521
  assertKeyAlgorithm(skR, this.algorithm)
3500
3522
  return new Uint8Array(
3501
3523
  await subtle(
3502
-
3524
+
3503
3525
  (c) => c.decapsulateBits(this.algorithm, skR, enc ),
3504
3526
  this.name,
3505
3527
  ),
@@ -3510,7 +3532,7 @@ function DIRECT_KEM_SHARED() {
3510
3532
 
3511
3533
  function createDirectKEM({ id, name, Nsecret, Nenc, Npk, Nsk } ) {
3512
3534
  const kdf = KDF_SHAKE256()
3513
-
3535
+
3514
3536
  kdf.name = name
3515
3537
  return {
3516
3538
  id,
@@ -3527,9 +3549,9 @@ function createDirectKEM({ id, name, Nsecret, Nenc, Npk, Nsk } )
3527
3549
  }
3528
3550
  }
3529
3551
 
3530
-
3531
-
3532
-
3552
+
3553
+
3554
+
3533
3555
 
3534
3556
 
3535
3557
 
@@ -3622,20 +3644,20 @@ export const KEM_ML_KEM_1024 = function () {
3622
3644
  return createDirectKEM({ id, name, Nsecret, Nenc, Npk, Nsk })
3623
3645
  }
3624
3646
 
3647
+
3648
+
3649
+
3650
+
3625
3651
 
3626
-
3627
-
3628
-
3629
-
3630
-
3652
+
3631
3653
 
3632
3654
  function AEAD_SHARED(P_MAX ) {
3633
-
3634
-
3635
-
3636
-
3637
-
3638
- const cache = new WeakMap ()
3655
+
3656
+
3657
+
3658
+
3659
+
3660
+ const cache = new WeakMap ()
3639
3661
  async function importKey( key ) {
3640
3662
  return await subtle(
3641
3663
  (c) =>
@@ -3651,8 +3673,7 @@ function AEAD_SHARED(P_MAX ) {
3651
3673
  if (pt.byteLength > P_MAX) {
3652
3674
  throw new RangeError('"pt" exceeds P_MAX')
3653
3675
  }
3654
- const cryptoKey =
3655
- cache.get(key) ?? (await cacheValue(cache, key, () => importKey.call(this, key)))
3676
+ const cryptoKey = await getCachedCryptoKey(cache, key, (bytes) => importKey.call(this, bytes))
3656
3677
  return new Uint8Array(
3657
3678
  await subtle(
3658
3679
  (c) =>
@@ -3670,8 +3691,7 @@ function AEAD_SHARED(P_MAX ) {
3670
3691
  )
3671
3692
  },
3672
3693
  async Open( key, nonce, aad, ct) {
3673
- const cryptoKey =
3674
- cache.get(key) ?? (await cacheValue(cache, key, () => importKey.call(this, key)))
3694
+ const cryptoKey = await getCachedCryptoKey(cache, key, (bytes) => importKey.call(this, bytes))
3675
3695
  return new Uint8Array(
3676
3696
  await subtle(
3677
3697
  (c) =>
@@ -3691,9 +3711,9 @@ function AEAD_SHARED(P_MAX ) {
3691
3711
  }
3692
3712
  }
3693
3713
 
3694
-
3695
-
3696
-
3714
+
3715
+
3716
+
3697
3717
 
3698
3718
 
3699
3719
 
@@ -3786,17 +3806,17 @@ export const AEAD_ChaCha20Poly1305 = function AEAD_ChaCha20Poly1305
3786
3806
  Nn: 12,
3787
3807
  Nt: 16,
3788
3808
  algorithm: 'ChaCha20-Poly1305',
3789
-
3809
+
3790
3810
  keyFormat: 'raw-secret',
3791
3811
  ...AEAD_SHARED(CHACHA20_POLY1305_P_MAX),
3792
3812
  }
3793
3813
  }
3794
3814
 
3815
+
3816
+
3817
+
3795
3818
 
3796
-
3797
-
3798
-
3799
-
3819
+
3800
3820
  const InvalidInvocation = (_ ) => {
3801
3821
  if (_ !== priv) {
3802
3822
  throw new Error('invalid invocation')
@@ -3910,19 +3930,19 @@ function RandomScalarNist(t , seed )
3910
3930
  return bigIntToUint8Array(sk_bigint, t.Nscalar )
3911
3931
  }
3912
3932
 
3913
-
3933
+
3914
3934
  async function expandDecapsKeyG(kem , seed ) {
3915
3935
  const Nout = kem.pq.Nseed + kem.t.Nseed
3916
3936
  const bits = Nout << 3
3917
-
3937
+
3918
3938
  const algorithm = { name: 'cSHAKE256', length: bits, outputLength: bits }
3919
3939
  const seed_full = await subtle((c) => c.digest(algorithm, seed ), kem.name)
3920
3940
 
3921
3941
  const [seed_PQ, seed_T] = split(kem.pq.Nseed, kem.t.Nseed, new Uint8Array(seed_full))
3922
3942
 
3923
-
3943
+
3924
3944
  const format = 'raw-seed'
3925
-
3945
+
3926
3946
  const usages = ['decapsulateBits', 'encapsulateBits']
3927
3947
  const dk_PQ = await subtle(
3928
3948
  (c) => c.importKey(format, seed_PQ , kem.pq.algorithm, true, [usages[0]]),
@@ -3936,7 +3956,7 @@ async function expandDecapsKeyG(kem , seed ) {
3936
3956
  return { ek_PQ, ek_T, dk_PQ, dk_T }
3937
3957
  }
3938
3958
 
3939
-
3959
+
3940
3960
  async function C2PRICombiner(
3941
3961
  kem ,
3942
3962
  ss_PQ ,
@@ -3950,14 +3970,14 @@ async function C2PRICombiner(
3950
3970
  return new Uint8Array(await subtle((c) => c.digest('SHA3-256', data), kem.name))
3951
3971
  }
3952
3972
 
3953
-
3973
+
3954
3974
  async function prepareEncapsG(
3955
3975
  kem ,
3956
3976
  ek_PQ ,
3957
3977
  ek_T ,
3958
3978
  ) {
3959
3979
  const res = (await subtle(
3960
-
3980
+
3961
3981
  (c) => c.encapsulateBits(kem.pq.algorithm, ek_PQ),
3962
3982
  kem.name,
3963
3983
  ))
@@ -3976,12 +3996,11 @@ async function prepareEncapsG(
3976
3996
  kem.name,
3977
3997
  ),
3978
3998
  )
3979
- checkNotAllZeros(ss_T)
3980
3999
 
3981
4000
  return [ss_PQ, ss_T, ct_PQ, ct_T]
3982
4001
  }
3983
4002
 
3984
-
4003
+
3985
4004
  async function prepareDecapsG(
3986
4005
  kem ,
3987
4006
  dk_PQ ,
@@ -3991,7 +4010,7 @@ async function prepareDecapsG(
3991
4010
  ) {
3992
4011
  const ss_PQ = new Uint8Array(
3993
4012
  await subtle(
3994
-
4013
+
3995
4014
  (c) => c.decapsulateBits(kem.pq.algorithm, dk_PQ, ct_PQ),
3996
4015
  kem.name,
3997
4016
  ),
@@ -4008,40 +4027,39 @@ async function prepareDecapsG(
4008
4027
  kem.name,
4009
4028
  ),
4010
4029
  )
4011
- checkNotAllZeros(ss_T)
4012
4030
 
4013
4031
  return [ss_PQ, ss_T]
4014
4032
  }
4015
4033
 
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
-
4034
+
4035
+
4036
+
4037
+
4038
+
4039
+
4040
+
4041
+
4042
+
4043
+
4044
+
4045
+
4046
+
4047
+
4048
+
4049
+
4050
+
4051
+
4052
+
4053
+
4054
+
4055
+
4056
+
4057
+
4058
+
4059
+
4060
+
4061
+
4062
+
4045
4063
 
4046
4064
  function COMPOSITE_HYBRID_KEM_SHARED() {
4047
4065
  Object.freeze(HybridKey.prototype)
@@ -4078,7 +4096,7 @@ function COMPOSITE_HYBRID_KEM_SHARED() {
4078
4096
  async SerializePublicKey( key) {
4079
4097
  assertKeyAlgorithm(key, this.algorithm)
4080
4098
  HybridKey.validate(key, true)
4081
-
4099
+
4082
4100
  const format = 'raw-public'
4083
4101
  const ek_PQ = new Uint8Array(
4084
4102
  await subtle((c) => c.exportKey(format, key.getPq(priv)), this.name),
@@ -4090,9 +4108,9 @@ function COMPOSITE_HYBRID_KEM_SHARED() {
4090
4108
  return concat(ek_PQ, ek_T)
4091
4109
  },
4092
4110
  async DeserializePublicKey( key) {
4093
-
4111
+
4094
4112
  const format = 'raw-public'
4095
-
4113
+
4096
4114
  const usages = ['encapsulateBits']
4097
4115
  const pubPq = key.subarray(0, this.pq.Npk)
4098
4116
  const pubT = key.subarray(this.pq.Npk)
@@ -4110,7 +4128,8 @@ function COMPOSITE_HYBRID_KEM_SHARED() {
4110
4128
  return key.getSeed(priv)
4111
4129
  },
4112
4130
  async DeserializePrivateKey( key, extractable) {
4113
- const { ek_PQ, ek_T, dk_PQ, dk_T } = await expandDecapsKeyG(this, key)
4131
+ const seed = slice(key)
4132
+ const { ek_PQ, ek_T, dk_PQ, dk_T } = await expandDecapsKeyG(this, seed)
4114
4133
  const publicKey = new HybridKey(priv, this.algorithm, 'public', true, ek_PQ, ek_T)
4115
4134
  const privateKey = new HybridKey(
4116
4135
  priv,
@@ -4119,7 +4138,7 @@ function COMPOSITE_HYBRID_KEM_SHARED() {
4119
4138
  extractable,
4120
4139
  dk_PQ,
4121
4140
  dk_T,
4122
- slice(key),
4141
+ seed,
4123
4142
  publicKey,
4124
4143
  )
4125
4144
 
@@ -4161,7 +4180,7 @@ function COMPOSITE_HYBRID_KEM_SHARED() {
4161
4180
 
4162
4181
  function createCompositeHybridKEM(parameters ) {
4163
4182
  const kdf = KDF_SHAKE256()
4164
-
4183
+
4165
4184
  kdf.name = parameters.name
4166
4185
  return {
4167
4186
  ...parameters,
@@ -4173,9 +4192,9 @@ function createCompositeHybridKEM(parameters )
4173
4192
  }
4174
4193
  }
4175
4194
 
4176
-
4177
-
4178
-
4195
+
4196
+
4197
+
4179
4198
 
4180
4199
 
4181
4200
 
@@ -4210,12 +4229,12 @@ export const KEM_MLKEM768_X25519 = function ()
4210
4229
  const Npk = 1216
4211
4230
  const Nsk = 32
4212
4231
  const kem = { id, name, Nsecret, Nenc, Npk, Nsk }
4213
-
4232
+
4214
4233
  if (SubtleCrypto.supports?.('generateKey', name) ?? false) {
4215
4234
  return createDirectKEM(kem)
4216
4235
  }
4217
4236
 
4218
- const pkcs8 = Uint8Array.of(0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e, 0x04, 0x22, 0x04, 0x20)
4237
+ const pkcs8 = Uint8Array.of(0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e, 0x04, 0x22, 0x04, 0x20)
4219
4238
  return createCompositeHybridKEM({
4220
4239
  ...kem,
4221
4240
  pq: { algorithm: { name: 'ML-KEM-768' }, Nseed: 64, Npk: 1184, Nct: 1088 },
@@ -4233,7 +4252,7 @@ export const KEM_MLKEM768_X25519 = function ()
4233
4252
  return { privateKey, publicKey }
4234
4253
  },
4235
4254
  },
4236
- label: Uint8Array.of(0x5c, 0x2e, 0x2f, 0x2f, 0x5e, 0x5c),
4255
+ label: Uint8Array.of(0x5c, 0x2e, 0x2f, 0x2f, 0x5e, 0x5c),
4237
4256
  })
4238
4257
  }
4239
4258
 
@@ -4270,7 +4289,7 @@ export const KEM_MLKEM768_P256 = function ()
4270
4289
  const Npk = 1249
4271
4290
  const Nsk = 32
4272
4291
  const kem = { id, name, Nsecret, Nenc, Npk, Nsk }
4273
-
4292
+
4274
4293
  if (SubtleCrypto.supports?.('generateKey', name) ?? false) {
4275
4294
  return createDirectKEM(kem)
4276
4295
  }
@@ -4292,7 +4311,7 @@ export const KEM_MLKEM768_P256 = function ()
4292
4311
  return GetKeyPairNist(P256, sk, true, name)
4293
4312
  },
4294
4313
  },
4295
- label: Uint8Array.of(0x4d, 0x4c, 0x4b, 0x45, 0x4d, 0x37, 0x36, 0x38, 0x2d, 0x50, 0x32, 0x35, 0x36),
4314
+ label: Uint8Array.of(0x4d, 0x4c, 0x4b, 0x45, 0x4d, 0x37, 0x36, 0x38, 0x2d, 0x50, 0x32, 0x35, 0x36),
4296
4315
  })
4297
4316
  }
4298
4317
 
@@ -4329,7 +4348,7 @@ export const KEM_MLKEM1024_P384 = function ()
4329
4348
  const Npk = 1665
4330
4349
  const Nsk = 32
4331
4350
  const kem = { id, name, Nsecret, Nenc, Npk, Nsk }
4332
-
4351
+
4333
4352
  if (SubtleCrypto.supports?.('generateKey', name) ?? false) {
4334
4353
  return createDirectKEM(kem)
4335
4354
  }
@@ -4352,6 +4371,6 @@ export const KEM_MLKEM1024_P384 = function ()
4352
4371
  return GetKeyPairNist(P384, sk, true, name)
4353
4372
  },
4354
4373
  },
4355
- label: Uint8Array.of(0x4d, 0x4c, 0x4b, 0x45, 0x4d, 0x31, 0x30, 0x32, 0x34, 0x2d, 0x50, 0x33, 0x38, 0x34),
4374
+ label: Uint8Array.of(0x4d, 0x4c, 0x4b, 0x45, 0x4d, 0x31, 0x30, 0x32, 0x34, 0x2d, 0x50, 0x33, 0x38, 0x34),
4356
4375
  })
4357
4376
  }