puantum 1.1.1__cp313-cp313-win_amd64.whl → 11.0.0.0__cp313-cp313-win_amd64.whl

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.
@@ -1,563 +1,526 @@
1
- # IMPORT
2
- from puantum import __internal__ as _internal # type: ignore
3
- import typing as _typing
4
- import enum as _enum
5
-
6
- # MAIN
7
- class Algorithm:
8
- class BIKE(_enum.Enum):
9
- BIKEL1 = "BikeL1"
10
- BIKEL3 = "BikeL3"
11
- BIKEL5 = "BikeL5"
12
- #
13
- class CLASSICMCELIECE(_enum.Enum):
14
- CLASSICMCELIECE348864 = "ClassicMcEliece348864"
15
- CLASSICMCELIECE348864F = "ClassicMcEliece348864f"
16
- CLASSICMCELIECE460896 = "ClassicMcEliece460896"
17
- CLASSICMCELIECE460896F = "ClassicMcEliece460896f"
18
- CLASSICMCELIECE6688128 = "ClassicMcEliece6688128"
19
- CLASSICMCELIECE6688128F = "ClassicMcEliece6688128f"
20
- CLASSICMCELIECE6960119 = "ClassicMcEliece6960119"
21
- CLASSICMCELIECE6960119F = "ClassicMcEliece6960119f"
22
- CLASSICMCELIECE8192128 = "ClassicMcEliece8192128"
23
- CLASSICMCELIECE8192128F = "ClassicMcEliece8192128f"
24
- #
25
- class HQC(_enum.Enum):
26
- HQC128 = "Hqc128"
27
- HQC192 = "Hqc192"
28
- HQC256 = "Hqc256"
29
- #
30
- class KYBER(_enum.Enum):
31
- KYBER512 = "Kyber512"
32
- KYBER768 = "Kyber768"
33
- KYBER1024 = "Kyber1024"
34
- #
35
- class MLKEM(_enum.Enum):
36
- MLKEM512 = "MlKem512"
37
- MLKEM768 = "MlKem768"
38
- MLKEM1024 = "MlKem1024"
39
- #
40
- class NTRUPRIME(_enum.Enum):
41
- NTRUPRIME = "NtruPrimeSntrup761"
42
- #
43
- class FRODOKEM(_enum.Enum):
44
- FRODOKEM640AES = "FrodoKem640Aes"
45
- FRODOKEM640SHAKE = "FrodoKem640Shake"
46
- FRODOKEM976AES = "FrodoKem976Aes"
47
- FRODOKEM976SHAKE = "FrodoKem976Shake"
48
- FRODOKEM1344AES = "FrodoKem1344Aes"
49
- FRODOKEM1344SHAKE = "FrodoKem1344Shake"
50
-
51
-
52
-
53
- class Ciphertext:
54
- def __init__(self, ciphertext: bytes) -> None:
55
- if not isinstance(ciphertext, bytes):
56
- raise TypeError("Ciphertext Not Valid")
57
- #
58
- self.ciphertext = ciphertext
59
- #
60
- return None
61
-
62
-
63
-
64
- class BIKECiphertext(Ciphertext):
65
- def __init__(self, name: Algorithm.BIKE, ciphertext: bytes) -> None:
66
- if not isinstance(name, Algorithm.BIKE):
67
- raise ValueError(f"Unsupported algorithm: {name}")
68
- else:
69
- super().__init__(ciphertext)
70
- #
71
- return None
72
-
73
-
74
-
75
- class CLASSICMCELIECECiphertext(Ciphertext):
76
- def __init__(self, name: Algorithm.CLASSICMCELIECE, ciphertext: bytes) -> None:
77
- if not isinstance(name, Algorithm.CLASSICMCELIECE):
78
- raise ValueError(f"Unsupported algorithm: {name}")
79
- else:
80
- super().__init__(ciphertext)
81
- #
82
- return None
83
-
84
-
85
-
86
- class HQCCiphertext(Ciphertext):
87
- def __init__(self, name: Algorithm.HQC, ciphertext: bytes) -> None:
88
- if not isinstance(name, Algorithm.HQC):
89
- raise ValueError(f"Unsupported algorithm: {name}")
90
- else:
91
- super().__init__(ciphertext)
92
- #
93
- return None
94
-
95
-
96
-
97
- class KYBERCiphertext(Ciphertext):
98
- def __init__(self, name: Algorithm.KYBER, ciphertext: bytes) -> None:
99
- if not isinstance(name, Algorithm.KYBER):
100
- raise ValueError(f"Unsupported algorithm: {name}")
101
- else:
102
- super().__init__(ciphertext)
103
- #
104
- return None
105
-
106
-
107
-
108
- class MLKEMCiphertext(Ciphertext):
109
- def __init__(self, name: Algorithm.MLKEM, ciphertext: bytes) -> None:
110
- if not isinstance(name, Algorithm.MLKEM):
111
- raise ValueError(f"Unsupported algorithm: {name}")
112
- else:
113
- super().__init__(ciphertext)
114
- #
115
- return None
116
-
117
-
118
-
119
- class NTRUPRIMECiphertext(Ciphertext):
120
- def __init__(self, name: Algorithm.NTRUPRIME, ciphertext: bytes) -> None:
121
- if not isinstance(name, Algorithm.NTRUPRIME):
122
- raise ValueError(f"Unsupported algorithm: {name}")
123
- else:
124
- super().__init__(ciphertext)
125
- #
126
- return None
127
-
128
-
129
-
130
- class FRODOKEMCiphertext(Ciphertext):
131
- def __init__(self, name: Algorithm.FRODOKEM, ciphertext: bytes) -> None:
132
- if not isinstance(name, Algorithm.FRODOKEM):
133
- raise ValueError(f"Unsupported algorithm: {name}")
134
- else:
135
- super().__init__(ciphertext)
136
- #
137
- return None
138
-
139
-
140
-
141
- class SharedSecret:
142
- def __init__(self, sharedsecret: bytes) -> None:
143
- if not isinstance(sharedsecret, bytes):
144
- raise TypeError("SharedSecret Not Valid")
145
- #
146
- self.sharedsecret = sharedsecret
147
- #
148
- return None
149
-
150
-
151
-
152
- class BIKESharedSecret(SharedSecret):
153
- def __init__(self, name: Algorithm.BIKE, sharedsecret: bytes) -> None:
154
- if not isinstance(name, Algorithm.BIKE):
155
- raise ValueError(f"Unsupported algorithm: {name}")
156
- else:
157
- super().__init__(sharedsecret)
158
- #
159
- return None
160
-
161
-
162
-
163
- class CLASSICMCELIECESharedSecret(SharedSecret):
164
- def __init__(self, name: Algorithm.CLASSICMCELIECE, sharedsecret: bytes) -> None:
165
- if not isinstance(name, Algorithm.CLASSICMCELIECE):
166
- raise ValueError(f"Unsupported algorithm: {name}")
167
- else:
168
- super().__init__(sharedsecret)
169
- #
170
- return None
171
-
172
-
173
-
174
- class HQCSharedSecret(SharedSecret):
175
- def __init__(self, name: Algorithm.HQC, sharedsecret: bytes) -> None:
176
- if not isinstance(name, Algorithm.HQC):
177
- raise ValueError(f"Unsupported algorithm: {name}")
178
- else:
179
- super().__init__(sharedsecret)
180
- #
181
- return None
182
-
183
-
184
-
185
- class KYBERSharedSecret(SharedSecret):
186
- def __init__(self, name: Algorithm.KYBER, sharedsecret: bytes) -> None:
187
- if not isinstance(name, Algorithm.KYBER):
188
- raise ValueError(f"Unsupported algorithm: {name}")
189
- else:
190
- super().__init__(sharedsecret)
191
- #
192
- return None
193
-
194
-
195
-
196
- class MLKEMSharedSecret(SharedSecret):
197
- def __init__(self, name: Algorithm.MLKEM, sharedsecret: bytes) -> None:
198
- if not isinstance(name, Algorithm.MLKEM):
199
- raise ValueError(f"Unsupported algorithm: {name}")
200
- else:
201
- super().__init__(sharedsecret)
202
- #
203
- return None
204
-
205
-
206
-
207
- class NTRUPRIMESharedSecret(SharedSecret):
208
- def __init__(self, name: Algorithm.NTRUPRIME, sharedsecret: bytes) -> None:
209
- if not isinstance(name, Algorithm.NTRUPRIME):
210
- raise ValueError(f"Unsupported algorithm: {name}")
211
- else:
212
- super().__init__(sharedsecret)
213
- #
214
- return None
215
-
216
-
217
-
218
- class FRODOKEMSharedSecret(SharedSecret):
219
- def __init__(self, name: Algorithm.FRODOKEM, sharedsecret: bytes) -> None:
220
- if not isinstance(name, Algorithm.FRODOKEM):
221
- raise ValueError(f"Unsupported algorithm: {name}")
222
- else:
223
- super().__init__(sharedsecret)
224
- #
225
- return None
226
-
227
-
228
-
229
- class PublicKey:
230
- def __init__(self, publickey: bytes) -> None:
231
- if not isinstance(publickey, bytes):
232
- raise TypeError("PublicKey Not Valid")
233
- #
234
- self.publickey = publickey
235
- #
236
- return None
237
- #
238
- def encapsulate(self) -> tuple[_typing.Any, _typing.Any]:
239
- raise NotImplementedError()
240
-
241
-
242
-
243
- class BIKEPublicKey(PublicKey):
244
- def __init__(self, name: Algorithm.BIKE, publickey: bytes) -> None:
245
- if not isinstance(name, Algorithm.BIKE):
246
- raise ValueError(f"Unsupported algorithm: {name}")
247
- else:
248
- super().__init__(publickey)
249
- #
250
- self._algorithm = name
251
- #
252
- return None
253
- #
254
- def encapsulate(self) -> tuple[BIKESharedSecret, BIKECiphertext]:
255
- sharedsecret, ciphertext = _internal.kemencapsulate(self._algorithm.value, self.publickey) # type: ignore
256
- return BIKESharedSecret(self._algorithm, sharedsecret), BIKECiphertext(self._algorithm, ciphertext) # type: ignore
257
-
258
-
259
-
260
- class CLASSICMCELIECEPublicKey(PublicKey):
261
- def __init__(self, name: Algorithm.CLASSICMCELIECE, publickey: bytes) -> None:
262
- if not isinstance(name, Algorithm.CLASSICMCELIECE):
263
- raise ValueError(f"Unsupported algorithm: {name}")
264
- else:
265
- super().__init__(publickey)
266
- #
267
- self._algorithm = name
268
- #
269
- return None
270
- #
271
- def encapsulate(self) -> tuple[CLASSICMCELIECESharedSecret, CLASSICMCELIECECiphertext]:
272
- sharedsecret, ciphertext = _internal.kemencapsulate(self._algorithm.value, self.publickey) # type: ignore
273
- return CLASSICMCELIECESharedSecret(self._algorithm, sharedsecret), CLASSICMCELIECECiphertext(self._algorithm, ciphertext) # type: ignore
274
-
275
-
276
-
277
- class HQCPublicKey(PublicKey):
278
- def __init__(self, name: Algorithm.HQC, publickey: bytes) -> None:
279
- if not isinstance(name, Algorithm.HQC):
280
- raise ValueError(f"Unsupported algorithm: {name}")
281
- else:
282
- super().__init__(publickey)
283
- #
284
- self._algorithm = name
285
- #
286
- return None
287
- #
288
- def encapsulate(self) -> tuple[HQCSharedSecret, HQCCiphertext]:
289
- sharedsecret, ciphertext = _internal.kemencapsulate(self._algorithm.value, self.publickey) # type: ignore
290
- return HQCSharedSecret(self._algorithm, sharedsecret), HQCCiphertext(self._algorithm, ciphertext) # type: ignore
291
-
292
-
293
-
294
- class KYBERPublicKey(PublicKey):
295
- def __init__(self, name: Algorithm.KYBER, publickey: bytes) -> None:
296
- if not isinstance(name, Algorithm.KYBER):
297
- raise ValueError(f"Unsupported algorithm: {name}")
298
- else:
299
- super().__init__(publickey)
300
- #
301
- self._algorithm = name
302
- #
303
- return None
304
- #
305
- def encapsulate(self) -> tuple[KYBERSharedSecret, KYBERCiphertext]:
306
- sharedsecret, ciphertext = _internal.kemencapsulate(self._algorithm.value, self.publickey) # type: ignore
307
- return KYBERSharedSecret(self._algorithm, sharedsecret), KYBERCiphertext(self._algorithm, ciphertext) # type: ignore
308
-
309
-
310
-
311
- class MLKEMPublicKey(PublicKey):
312
- def __init__(self, name: Algorithm.MLKEM, publickey: bytes) -> None:
313
- if not isinstance(name, Algorithm.MLKEM):
314
- raise ValueError(f"Unsupported algorithm: {name}")
315
- else:
316
- super().__init__(publickey)
317
- #
318
- self._algorithm = name
319
- #
320
- return None
321
- #
322
- def encapsulate(self) -> tuple[MLKEMSharedSecret, MLKEMCiphertext]:
323
- sharedsecret, ciphertext = _internal.kemencapsulate(self._algorithm.value, self.publickey) # type: ignore
324
- return MLKEMSharedSecret(self._algorithm, sharedsecret), MLKEMCiphertext(self._algorithm, ciphertext) # type: ignore
325
-
326
-
327
-
328
- class NTRUPRIMEPublicKey(PublicKey):
329
- def __init__(self, name: Algorithm.NTRUPRIME, publickey: bytes) -> None:
330
- if not isinstance(name, Algorithm.NTRUPRIME):
331
- raise ValueError(f"Unsupported algorithm: {name}")
332
- else:
333
- super().__init__(publickey)
334
- #
335
- self._algorithm = name
336
- #
337
- return None
338
- #
339
- def encapsulate(self) -> tuple[NTRUPRIMESharedSecret, NTRUPRIMECiphertext]:
340
- sharedsecret, ciphertext = _internal.kemencapsulate(self._algorithm.value, self.publickey) # type: ignore
341
- return NTRUPRIMESharedSecret(self._algorithm, sharedsecret), NTRUPRIMECiphertext(self._algorithm, ciphertext) # type: ignore
342
-
343
-
344
-
345
- class FRODOKEMPublicKey(PublicKey):
346
- def __init__(self, name: Algorithm.FRODOKEM, publickey: bytes) -> None:
347
- if not isinstance(name, Algorithm.FRODOKEM):
348
- raise ValueError(f"Unsupported algorithm: {name}")
349
- else:
350
- super().__init__(publickey)
351
- #
352
- self._algorithm = name
353
- #
354
- return None
355
- #
356
- def encapsulate(self) -> tuple[FRODOKEMSharedSecret, FRODOKEMCiphertext]:
357
- sharedsecret, ciphertext = _internal.kemencapsulate(self._algorithm.value, self.publickey) # type: ignore
358
- return FRODOKEMSharedSecret(self._algorithm, sharedsecret), FRODOKEMCiphertext(self._algorithm, ciphertext) # type: ignore
359
-
360
-
361
-
362
- class SecretKey:
363
- def __init__(self, secretkey: bytes) -> None:
364
- if not isinstance(secretkey, bytes):
365
- raise TypeError("SecretKey Not Valid")
366
- #
367
- self.secretkey = secretkey
368
- #
369
- return None
370
- #
371
- def decapsulate(self, ciphertext: _typing.Any) -> _typing.Any:
372
- raise NotImplementedError()
373
-
374
-
375
-
376
- class BIKESecretKey(SecretKey):
377
- def __init__(self, name: Algorithm.BIKE, secretkey: bytes) -> None:
378
- if not isinstance(name, Algorithm.BIKE):
379
- raise ValueError(f"Unsupported algorithm: {name}")
380
- else:
381
- super().__init__(secretkey)
382
- #
383
- self._algorithm = name
384
- #
385
- return None
386
- #
387
- def decapsulate(self, ciphertext: BIKECiphertext) -> BIKESharedSecret:
388
- sharedsecret: bytes = _internal.kemdecapsulate(self._algorithm.value, self.secretkey, ciphertext.ciphertext) # type: ignore
389
- return BIKESharedSecret(self._algorithm, sharedsecret) # type: ignore
390
-
391
-
392
-
393
- class CLASSICMCELIECESecretKey(SecretKey):
394
- def __init__(self, name: Algorithm.CLASSICMCELIECE, secretkey: bytes) -> None:
395
- if not isinstance(name, Algorithm.CLASSICMCELIECE):
396
- raise ValueError(f"Unsupported algorithm: {name}")
397
- else:
398
- super().__init__(secretkey)
399
- #
400
- self._algorithm = name
401
- #
402
- return None
403
- #
404
- def decapsulate(self, ciphertext: CLASSICMCELIECECiphertext) -> CLASSICMCELIECESharedSecret:
405
- sharedsecret: bytes = _internal.kemdecapsulate(self._algorithm.value, self.secretkey, ciphertext.ciphertext) # type: ignore
406
- return CLASSICMCELIECESharedSecret(self._algorithm, sharedsecret) # type: ignore
407
-
408
-
409
-
410
- class HQCSecretKey(SecretKey):
411
- def __init__(self, name: Algorithm.HQC, secretkey: bytes) -> None:
412
- if not isinstance(name, Algorithm.HQC):
413
- raise ValueError(f"Unsupported algorithm: {name}")
414
- else:
415
- super().__init__(secretkey)
416
- #
417
- self._algorithm = name
418
- #
419
- return None
420
- #
421
- def decapsulate(self, ciphertext: HQCCiphertext) -> HQCSharedSecret:
422
- sharedsecret: bytes = _internal.kemdecapsulate(self._algorithm.value, self.secretkey, ciphertext.ciphertext) # type: ignore
423
- return HQCSharedSecret(self._algorithm, sharedsecret) # type: ignore
424
-
425
-
426
-
427
- class KYBERSecretKey(SecretKey):
428
- def __init__(self, name: Algorithm.KYBER, secretkey: bytes) -> None:
429
- if not isinstance(name, Algorithm.KYBER):
430
- raise ValueError(f"Unsupported algorithm: {name}")
431
- else:
432
- super().__init__(secretkey)
433
- #
434
- self._algorithm = name
435
- #
436
- return None
437
- #
438
- def decapsulate(self, ciphertext: KYBERCiphertext) -> KYBERSharedSecret:
439
- sharedsecret: bytes = _internal.kemdecapsulate(self._algorithm.value, self.secretkey, ciphertext.ciphertext) # type: ignore
440
- return KYBERSharedSecret(self._algorithm, sharedsecret) # type: ignore
441
-
442
-
443
-
444
- class MLKEMSecretKey(SecretKey):
445
- def __init__(self, name: Algorithm.MLKEM, secretkey: bytes) -> None:
446
- if not isinstance(name, Algorithm.MLKEM):
447
- raise ValueError(f"Unsupported algorithm: {name}")
448
- else:
449
- super().__init__(secretkey)
450
- #
451
- self._algorithm = name
452
- #
453
- return None
454
- #
455
- def decapsulate(self, ciphertext: MLKEMCiphertext) -> MLKEMSharedSecret:
456
- sharedsecret: bytes = _internal.kemdecapsulate(self._algorithm.value, self.secretkey, ciphertext.ciphertext) # type: ignore
457
- return MLKEMSharedSecret(self._algorithm, sharedsecret) # type: ignore
458
-
459
-
460
-
461
- class NTRUPRIMESecretKey(SecretKey):
462
- def __init__(self, name: Algorithm.NTRUPRIME, secretkey: bytes) -> None:
463
- if not isinstance(name, Algorithm.NTRUPRIME):
464
- raise ValueError(f"Unsupported algorithm: {name}")
465
- else:
466
- super().__init__(secretkey)
467
- #
468
- self._algorithm = name
469
- #
470
- return None
471
- #
472
- def decapsulate(self, ciphertext: NTRUPRIMECiphertext) -> NTRUPRIMESharedSecret:
473
- sharedsecret: bytes = _internal.kemdecapsulate(self._algorithm.value, self.secretkey, ciphertext.ciphertext) # type: ignore
474
- return NTRUPRIMESharedSecret(self._algorithm, sharedsecret) # type: ignore
475
-
476
-
477
-
478
- class FRODOKEMSecretKey(SecretKey):
479
- def __init__(self, name: Algorithm.FRODOKEM, secretkey: bytes) -> None:
480
- if not isinstance(name, Algorithm.FRODOKEM):
481
- raise ValueError(f"Unsupported algorithm: {name}")
482
- else:
483
- super().__init__(secretkey)
484
- #
485
- self._algorithm = name
486
- #
487
- return None
488
- #
489
- def decapsulate(self, ciphertext: FRODOKEMCiphertext) -> FRODOKEMSharedSecret:
490
- sharedsecret: bytes = _internal.kemdecapsulate(self._algorithm.value, self.secretkey, ciphertext.ciphertext) # type: ignore
491
- return FRODOKEMSharedSecret(self._algorithm, sharedsecret) # type: ignore
492
-
493
-
494
-
495
- Algorithms = Algorithm | Algorithm.BIKE | Algorithm.CLASSICMCELIECE | Algorithm.HQC | Algorithm.KYBER | Algorithm.MLKEM | Algorithm.NTRUPRIME | Algorithm.FRODOKEM
496
-
497
-
498
-
499
- @_typing.overload
500
- def KeyPair(name: Algorithm) -> tuple[SecretKey, PublicKey]: ...
501
-
502
-
503
-
504
- @_typing.overload
505
- def KeyPair(name: Algorithm.BIKE) -> tuple[BIKESecretKey, BIKEPublicKey]: ...
506
-
507
-
508
-
509
- @_typing.overload
510
- def KeyPair(name: Algorithm.CLASSICMCELIECE) -> tuple[CLASSICMCELIECESecretKey, CLASSICMCELIECEPublicKey]: ...
511
-
512
-
513
-
514
- @_typing.overload
515
- def KeyPair(name: Algorithm.HQC) -> tuple[HQCSecretKey, HQCPublicKey]: ...
516
-
517
-
518
-
519
- @_typing.overload
520
- def KeyPair(name: Algorithm.KYBER) -> tuple[KYBERSecretKey, KYBERPublicKey]: ...
521
-
522
-
523
-
524
- @_typing.overload
525
- def KeyPair(name: Algorithm.MLKEM) -> tuple[MLKEMSecretKey, MLKEMPublicKey]: ...
526
-
527
-
528
-
529
- @_typing.overload
530
- def KeyPair(name: Algorithm.NTRUPRIME) -> tuple[NTRUPRIMESecretKey, NTRUPRIMEPublicKey]: ...
531
-
532
-
533
-
534
- @_typing.overload
535
- def KeyPair(name: Algorithm.FRODOKEM) -> tuple[FRODOKEMSecretKey, FRODOKEMPublicKey]: ...
536
-
537
-
538
-
539
- def KeyPair(name: Algorithms) -> tuple[SecretKey, PublicKey]:
540
- algorithm = name
541
- if isinstance(algorithm, Algorithm.BIKE):
542
- secretkey, publickey = _internal.kemkeygen(algorithm.value) # type: ignore
543
- return BIKESecretKey(algorithm, secretkey), BIKEPublicKey(algorithm, publickey) # type: ignore
544
- elif isinstance(algorithm, Algorithm.CLASSICMCELIECE):
545
- secretkey, publickey = _internal.kemkeygen(algorithm.value) # type: ignore
546
- return CLASSICMCELIECESecretKey(algorithm, secretkey), CLASSICMCELIECEPublicKey(algorithm, publickey) # type: ignore
547
- elif isinstance(algorithm, Algorithm.HQC):
548
- secretkey, publickey = _internal.kemkeygen(algorithm.value) # type: ignore
549
- return HQCSecretKey(algorithm, secretkey), HQCPublicKey(algorithm, publickey) # type: ignore
550
- elif isinstance(algorithm, Algorithm.KYBER):
551
- secretkey, publickey = _internal.kemkeygen(algorithm.value) # type: ignore
552
- return KYBERSecretKey(algorithm, secretkey), KYBERPublicKey(algorithm, publickey) # type: ignore
553
- elif isinstance(algorithm, Algorithm.MLKEM):
554
- secretkey, publickey = _internal.kemkeygen(algorithm.value) # type: ignore
555
- return MLKEMSecretKey(algorithm, secretkey), MLKEMPublicKey(algorithm, publickey) # type: ignore
556
- elif isinstance(algorithm, Algorithm.NTRUPRIME):
557
- secretkey, publickey = _internal.kemkeygen(algorithm.value) # type: ignore
558
- return NTRUPRIMESecretKey(algorithm, secretkey), NTRUPRIMEPublicKey(algorithm, publickey) # type: ignore
559
- elif isinstance(algorithm, Algorithm.FRODOKEM):
560
- secretkey, publickey = _internal.kemkeygen(algorithm.value) # type: ignore
561
- return FRODOKEMSecretKey(algorithm, secretkey), FRODOKEMPublicKey(algorithm, publickey) # type: ignore
562
- else:
563
- raise ValueError(f"Unsupported algorithm: {name}")
1
+ # IMPORT
2
+ from puantum import __internal__ as _internal # type: ignore
3
+ import typing as _typing
4
+ import enum as _enum
5
+
6
+ # MAIN
7
+ class Algorithm:
8
+ class BIKE(_enum.Enum):
9
+ BIKEL1 = "BikeL1"
10
+ BIKEL3 = "BikeL3"
11
+ BIKEL5 = "BikeL5"
12
+ #
13
+ class CLASSICMCELIECE(_enum.Enum):
14
+ CLASSICMCELIECE348864 = "ClassicMcEliece348864"
15
+ CLASSICMCELIECE348864F = "ClassicMcEliece348864f"
16
+ CLASSICMCELIECE460896 = "ClassicMcEliece460896"
17
+ CLASSICMCELIECE460896F = "ClassicMcEliece460896f"
18
+ CLASSICMCELIECE6688128 = "ClassicMcEliece6688128"
19
+ CLASSICMCELIECE6688128F = "ClassicMcEliece6688128f"
20
+ CLASSICMCELIECE6960119 = "ClassicMcEliece6960119"
21
+ CLASSICMCELIECE6960119F = "ClassicMcEliece6960119f"
22
+ CLASSICMCELIECE8192128 = "ClassicMcEliece8192128"
23
+ CLASSICMCELIECE8192128F = "ClassicMcEliece8192128f"
24
+ #
25
+ class HQC(_enum.Enum):
26
+ HQC128 = "Hqc128"
27
+ HQC192 = "Hqc192"
28
+ HQC256 = "Hqc256"
29
+ #
30
+ class KYBER(_enum.Enum):
31
+ KYBER512 = "Kyber512"
32
+ KYBER768 = "Kyber768"
33
+ KYBER1024 = "Kyber1024"
34
+ #
35
+ class MLKEM(_enum.Enum):
36
+ MLKEM512 = "MlKem512"
37
+ MLKEM768 = "MlKem768"
38
+ MLKEM1024 = "MlKem1024"
39
+ #
40
+ class NTRUPRIME(_enum.Enum):
41
+ NTRUPRIME = "NtruPrimeSntrup761"
42
+ #
43
+ class FRODOKEM(_enum.Enum):
44
+ FRODOKEM640AES = "FrodoKem640Aes"
45
+ FRODOKEM640SHAKE = "FrodoKem640Shake"
46
+ FRODOKEM976AES = "FrodoKem976Aes"
47
+ FRODOKEM976SHAKE = "FrodoKem976Shake"
48
+ FRODOKEM1344AES = "FrodoKem1344Aes"
49
+ FRODOKEM1344SHAKE = "FrodoKem1344Shake"
50
+
51
+
52
+
53
+ class PublicKey:
54
+ def __init__(self, publickey: bytes) -> None:
55
+ if not isinstance(publickey, bytes):
56
+ raise TypeError("PublicKey Not Valid")
57
+ #
58
+ self.publickey = publickey
59
+ #
60
+ return None
61
+ #
62
+ def encapsulate(self) -> tuple[_typing.Any, _typing.Any]:
63
+ raise NotImplementedError()
64
+
65
+
66
+
67
+ class BIKEPublicKey(PublicKey):
68
+ def __init__(self, name: Algorithm.BIKE, publickey: bytes) -> None:
69
+ if not isinstance(name, Algorithm.BIKE):
70
+ raise ValueError(f"Unsupported algorithm: {name}")
71
+ else:
72
+ super().__init__(publickey)
73
+ #
74
+ self._algorithm = name
75
+ #
76
+ return None
77
+ #
78
+ def encapsulate(self) -> tuple[bytes, bytes]:
79
+ sharedsecret, ciphertext = _internal.kemencapsulate(self._algorithm.value, self.publickey) # type: ignore
80
+ return sharedsecret, ciphertext # type: ignore
81
+
82
+
83
+
84
+ class CLASSICMCELIECEPublicKey(PublicKey):
85
+ def __init__(self, name: Algorithm.CLASSICMCELIECE, publickey: bytes) -> None:
86
+ if not isinstance(name, Algorithm.CLASSICMCELIECE):
87
+ raise ValueError(f"Unsupported algorithm: {name}")
88
+ else:
89
+ super().__init__(publickey)
90
+ #
91
+ self._algorithm = name
92
+ #
93
+ return None
94
+ #
95
+ def encapsulate(self) -> tuple[bytes, bytes]:
96
+ sharedsecret, ciphertext = _internal.kemencapsulate(self._algorithm.value, self.publickey) # type: ignore
97
+ return sharedsecret, ciphertext # type: ignore
98
+
99
+
100
+
101
+ class HQCPublicKey(PublicKey):
102
+ def __init__(self, name: Algorithm.HQC, publickey: bytes) -> None:
103
+ if not isinstance(name, Algorithm.HQC):
104
+ raise ValueError(f"Unsupported algorithm: {name}")
105
+ else:
106
+ super().__init__(publickey)
107
+ #
108
+ self._algorithm = name
109
+ #
110
+ return None
111
+ #
112
+ def encapsulate(self) -> tuple[bytes, bytes]:
113
+ sharedsecret, ciphertext = _internal.kemencapsulate(self._algorithm.value, self.publickey) # type: ignore
114
+ return sharedsecret, ciphertext # type: ignore
115
+
116
+
117
+
118
+ class KYBERPublicKey(PublicKey):
119
+ def __init__(self, name: Algorithm.KYBER, publickey: bytes) -> None:
120
+ if not isinstance(name, Algorithm.KYBER):
121
+ raise ValueError(f"Unsupported algorithm: {name}")
122
+ else:
123
+ super().__init__(publickey)
124
+ #
125
+ self._algorithm = name
126
+ #
127
+ return None
128
+ #
129
+ def encapsulate(self) -> tuple[bytes, bytes]:
130
+ sharedsecret, ciphertext = _internal.kemencapsulate(self._algorithm.value, self.publickey) # type: ignore
131
+ return sharedsecret, ciphertext # type: ignore
132
+
133
+
134
+
135
+ class MLKEMPublicKey(PublicKey):
136
+ def __init__(self, name: Algorithm.MLKEM, publickey: bytes) -> None:
137
+ if not isinstance(name, Algorithm.MLKEM):
138
+ raise ValueError(f"Unsupported algorithm: {name}")
139
+ else:
140
+ super().__init__(publickey)
141
+ #
142
+ self._algorithm = name
143
+ #
144
+ return None
145
+ #
146
+ def encapsulate(self) -> tuple[bytes, bytes]:
147
+ sharedsecret, ciphertext = _internal.kemencapsulate(self._algorithm.value, self.publickey) # type: ignore
148
+ return sharedsecret, ciphertext # type: ignore
149
+
150
+
151
+
152
+ class NTRUPRIMEPublicKey(PublicKey):
153
+ def __init__(self, name: Algorithm.NTRUPRIME, publickey: bytes) -> None:
154
+ if not isinstance(name, Algorithm.NTRUPRIME):
155
+ raise ValueError(f"Unsupported algorithm: {name}")
156
+ else:
157
+ super().__init__(publickey)
158
+ #
159
+ self._algorithm = name
160
+ #
161
+ return None
162
+ #
163
+ def encapsulate(self) -> tuple[bytes, bytes]:
164
+ sharedsecret, ciphertext = _internal.kemencapsulate(self._algorithm.value, self.publickey) # type: ignore
165
+ return sharedsecret, ciphertext # type: ignore
166
+
167
+
168
+
169
+ class FRODOKEMPublicKey(PublicKey):
170
+ def __init__(self, name: Algorithm.FRODOKEM, publickey: bytes) -> None:
171
+ if not isinstance(name, Algorithm.FRODOKEM):
172
+ raise ValueError(f"Unsupported algorithm: {name}")
173
+ else:
174
+ super().__init__(publickey)
175
+ #
176
+ self._algorithm = name
177
+ #
178
+ return None
179
+ #
180
+ def encapsulate(self) -> tuple[bytes, bytes]:
181
+ sharedsecret, ciphertext = _internal.kemencapsulate(self._algorithm.value, self.publickey) # type: ignore
182
+ return sharedsecret, ciphertext # type: ignore
183
+
184
+
185
+
186
+ class SecretKey:
187
+ def __init__(self, secretkey: bytes) -> None:
188
+ if not isinstance(secretkey, bytes):
189
+ raise TypeError("SecretKey Not Valid")
190
+ #
191
+ self.secretkey = secretkey
192
+ #
193
+ return None
194
+ #
195
+ def decapsulate(self, ciphertext: _typing.Any) -> _typing.Any:
196
+ raise NotImplementedError()
197
+
198
+
199
+
200
+ class BIKESecretKey(SecretKey):
201
+ def __init__(self, name: Algorithm.BIKE, secretkey: bytes) -> None:
202
+ if not isinstance(name, Algorithm.BIKE):
203
+ raise ValueError(f"Unsupported algorithm: {name}")
204
+ else:
205
+ super().__init__(secretkey)
206
+ #
207
+ self._algorithm = name
208
+ #
209
+ return None
210
+ #
211
+ def decapsulate(self, ciphertext: bytes) -> bytes:
212
+ sharedsecret: bytes = _internal.kemdecapsulate(self._algorithm.value, self.secretkey, ciphertext) # type: ignore
213
+ return sharedsecret # type: ignore
214
+
215
+
216
+
217
+ class CLASSICMCELIECESecretKey(SecretKey):
218
+ def __init__(self, name: Algorithm.CLASSICMCELIECE, secretkey: bytes) -> None:
219
+ if not isinstance(name, Algorithm.CLASSICMCELIECE):
220
+ raise ValueError(f"Unsupported algorithm: {name}")
221
+ else:
222
+ super().__init__(secretkey)
223
+ #
224
+ self._algorithm = name
225
+ #
226
+ return None
227
+ #
228
+ def decapsulate(self, ciphertext: bytes) -> bytes:
229
+ sharedsecret: bytes = _internal.kemdecapsulate(self._algorithm.value, self.secretkey, ciphertext) # type: ignore
230
+ return sharedsecret # type: ignore
231
+
232
+
233
+
234
+ class HQCSecretKey(SecretKey):
235
+ def __init__(self, name: Algorithm.HQC, secretkey: bytes) -> None:
236
+ if not isinstance(name, Algorithm.HQC):
237
+ raise ValueError(f"Unsupported algorithm: {name}")
238
+ else:
239
+ super().__init__(secretkey)
240
+ #
241
+ self._algorithm = name
242
+ #
243
+ return None
244
+ #
245
+ def decapsulate(self, ciphertext: bytes) -> bytes:
246
+ sharedsecret: bytes = _internal.kemdecapsulate(self._algorithm.value, self.secretkey, ciphertext) # type: ignore
247
+ return sharedsecret # type: ignore
248
+
249
+
250
+
251
+ class KYBERSecretKey(SecretKey):
252
+ def __init__(self, name: Algorithm.KYBER, secretkey: bytes) -> None:
253
+ if not isinstance(name, Algorithm.KYBER):
254
+ raise ValueError(f"Unsupported algorithm: {name}")
255
+ else:
256
+ super().__init__(secretkey)
257
+ #
258
+ self._algorithm = name
259
+ #
260
+ return None
261
+ #
262
+ def decapsulate(self, ciphertext: bytes) -> bytes:
263
+ sharedsecret: bytes = _internal.kemdecapsulate(self._algorithm.value, self.secretkey, ciphertext) # type: ignore
264
+ return sharedsecret # type: ignore
265
+
266
+
267
+
268
+ class MLKEMSecretKey(SecretKey):
269
+ def __init__(self, name: Algorithm.MLKEM, secretkey: bytes) -> None:
270
+ if not isinstance(name, Algorithm.MLKEM):
271
+ raise ValueError(f"Unsupported algorithm: {name}")
272
+ else:
273
+ super().__init__(secretkey)
274
+ #
275
+ self._algorithm = name
276
+ #
277
+ return None
278
+ #
279
+ def decapsulate(self, ciphertext: bytes) -> bytes:
280
+ sharedsecret: bytes = _internal.kemdecapsulate(self._algorithm.value, self.secretkey, ciphertext) # type: ignore
281
+ return sharedsecret # type: ignore
282
+
283
+
284
+
285
+ class NTRUPRIMESecretKey(SecretKey):
286
+ def __init__(self, name: Algorithm.NTRUPRIME, secretkey: bytes) -> None:
287
+ if not isinstance(name, Algorithm.NTRUPRIME):
288
+ raise ValueError(f"Unsupported algorithm: {name}")
289
+ else:
290
+ super().__init__(secretkey)
291
+ #
292
+ self._algorithm = name
293
+ #
294
+ return None
295
+ #
296
+ def decapsulate(self, ciphertext: bytes) -> bytes:
297
+ sharedsecret: bytes = _internal.kemdecapsulate(self._algorithm.value, self.secretkey, ciphertext) # type: ignore
298
+ return sharedsecret # type: ignore
299
+
300
+
301
+
302
+ class FRODOKEMSecretKey(SecretKey):
303
+ def __init__(self, name: Algorithm.FRODOKEM, secretkey: bytes) -> None:
304
+ if not isinstance(name, Algorithm.FRODOKEM):
305
+ raise ValueError(f"Unsupported algorithm: {name}")
306
+ else:
307
+ super().__init__(secretkey)
308
+ #
309
+ self._algorithm = name
310
+ #
311
+ return None
312
+ #
313
+ def decapsulate(self, ciphertext: bytes) -> bytes:
314
+ sharedsecret: bytes = _internal.kemdecapsulate(self._algorithm.value, self.secretkey, ciphertext) # type: ignore
315
+ return sharedsecret # type: ignore
316
+
317
+
318
+
319
+ @_typing.overload
320
+ def KeyPair(
321
+ name: Algorithm,
322
+ *,
323
+ secretkey: bytes,
324
+ publickey: bytes
325
+ ) -> tuple[SecretKey, PublicKey]: ...
326
+ @_typing.overload
327
+ def KeyPair(name: Algorithm, *, secretkey: bytes) -> SecretKey: ...
328
+ @_typing.overload
329
+ def KeyPair(name: Algorithm, *, publickey: bytes) -> PublicKey: ...
330
+ @_typing.overload
331
+ def KeyPair(name: Algorithm) -> tuple[SecretKey, PublicKey]: ...
332
+
333
+
334
+
335
+ @_typing.overload
336
+ def KeyPair(
337
+ name: Algorithm.BIKE,
338
+ *,
339
+ secretkey: bytes,
340
+ publickey: bytes
341
+ ) -> tuple[BIKESecretKey, BIKEPublicKey]: ...
342
+ @_typing.overload
343
+ def KeyPair(name: Algorithm.BIKE, *, secretkey: bytes) -> BIKESecretKey: ...
344
+ @_typing.overload
345
+ def KeyPair(name: Algorithm.BIKE, *, publickey: bytes) -> BIKEPublicKey: ...
346
+ @_typing.overload
347
+ def KeyPair(name: Algorithm.BIKE) -> tuple[BIKESecretKey, BIKEPublicKey]: ...
348
+
349
+
350
+
351
+ @_typing.overload
352
+ def KeyPair(
353
+ name: Algorithm.CLASSICMCELIECE,
354
+ *,
355
+ secretkey: bytes,
356
+ publickey: bytes
357
+ ) -> tuple[CLASSICMCELIECESecretKey, CLASSICMCELIECEPublicKey]: ...
358
+ @_typing.overload
359
+ def KeyPair(name: Algorithm.CLASSICMCELIECE, *, secretkey: bytes) -> CLASSICMCELIECESecretKey: ...
360
+ @_typing.overload
361
+ def KeyPair(name: Algorithm.CLASSICMCELIECE, *, publickey: bytes) -> CLASSICMCELIECEPublicKey: ...
362
+ @_typing.overload
363
+ def KeyPair(name: Algorithm.CLASSICMCELIECE) -> tuple[CLASSICMCELIECESecretKey, CLASSICMCELIECEPublicKey]: ...
364
+
365
+
366
+
367
+ @_typing.overload
368
+ def KeyPair(
369
+ name: Algorithm.HQC,
370
+ *,
371
+ secretkey: bytes,
372
+ publickey: bytes
373
+ ) -> tuple[HQCSecretKey, HQCPublicKey]: ...
374
+ @_typing.overload
375
+ def KeyPair(name: Algorithm.HQC, *, secretkey: bytes) -> HQCSecretKey: ...
376
+ @_typing.overload
377
+ def KeyPair(name: Algorithm.HQC, *, publickey: bytes) -> HQCPublicKey: ...
378
+ @_typing.overload
379
+ def KeyPair(name: Algorithm.HQC) -> tuple[HQCSecretKey, HQCPublicKey]: ...
380
+
381
+
382
+
383
+ @_typing.overload
384
+ def KeyPair(
385
+ name: Algorithm.KYBER,
386
+ *,
387
+ secretkey: bytes,
388
+ publickey: bytes
389
+ ) -> tuple[KYBERSecretKey, KYBERPublicKey]: ...
390
+ @_typing.overload
391
+ def KeyPair(name: Algorithm.KYBER, *, secretkey: bytes) -> KYBERSecretKey: ...
392
+ @_typing.overload
393
+ def KeyPair(name: Algorithm.KYBER, *, publickey: bytes) -> KYBERPublicKey: ...
394
+ @_typing.overload
395
+ def KeyPair(name: Algorithm.KYBER) -> tuple[KYBERSecretKey, KYBERPublicKey]: ...
396
+
397
+
398
+
399
+ @_typing.overload
400
+ def KeyPair(
401
+ name: Algorithm.MLKEM,
402
+ *,
403
+ secretkey: bytes,
404
+ publickey: bytes
405
+ ) -> tuple[MLKEMSecretKey, MLKEMPublicKey]: ...
406
+ @_typing.overload
407
+ def KeyPair(name: Algorithm.MLKEM, *, secretkey: bytes) -> MLKEMSecretKey: ...
408
+ @_typing.overload
409
+ def KeyPair(name: Algorithm.MLKEM, *, publickey: bytes) -> MLKEMPublicKey: ...
410
+ @_typing.overload
411
+ def KeyPair(name: Algorithm.MLKEM) -> tuple[MLKEMSecretKey, MLKEMPublicKey]: ...
412
+
413
+
414
+
415
+ @_typing.overload
416
+ def KeyPair(
417
+ name: Algorithm.NTRUPRIME,
418
+ *,
419
+ secretkey: bytes,
420
+ publickey: bytes
421
+ ) -> tuple[NTRUPRIMESecretKey, NTRUPRIMEPublicKey]: ...
422
+ @_typing.overload
423
+ def KeyPair(name: Algorithm.NTRUPRIME, *, secretkey: bytes) -> NTRUPRIMESecretKey: ...
424
+ @_typing.overload
425
+ def KeyPair(name: Algorithm.NTRUPRIME, *, publickey: bytes) -> NTRUPRIMEPublicKey: ...
426
+ @_typing.overload
427
+ def KeyPair(name: Algorithm.NTRUPRIME) -> tuple[NTRUPRIMESecretKey, NTRUPRIMEPublicKey]: ...
428
+
429
+
430
+
431
+ @_typing.overload
432
+ def KeyPair(
433
+ name: Algorithm.FRODOKEM,
434
+ *,
435
+ secretkey: bytes,
436
+ publickey: bytes
437
+ ) -> tuple[FRODOKEMSecretKey, FRODOKEMPublicKey]: ...
438
+ @_typing.overload
439
+ def KeyPair(name: Algorithm.FRODOKEM, *, secretkey: bytes) -> FRODOKEMSecretKey: ...
440
+ @_typing.overload
441
+ def KeyPair(name: Algorithm.FRODOKEM, *, publickey: bytes) -> FRODOKEMPublicKey: ...
442
+ @_typing.overload
443
+ def KeyPair(name: Algorithm.FRODOKEM) -> tuple[FRODOKEMSecretKey, FRODOKEMPublicKey]: ...
444
+
445
+
446
+
447
+ Algorithms = Algorithm.BIKE | Algorithm.CLASSICMCELIECE | Algorithm.HQC | Algorithm.KYBER | Algorithm.MLKEM | Algorithm.NTRUPRIME | Algorithm.FRODOKEM
448
+ def KeyPair(
449
+ name: Algorithm | Algorithms,
450
+ *,
451
+ secretkey: bytes | None = None,
452
+ publickey: bytes | None = None
453
+ ) -> tuple[SecretKey, PublicKey] | SecretKey | PublicKey:
454
+ algorithm = name
455
+ if isinstance(algorithm, Algorithm.BIKE):
456
+ if secretkey is not None and publickey is None:
457
+ return BIKESecretKey(algorithm, secretkey)
458
+ elif publickey is not None and secretkey is None:
459
+ return BIKEPublicKey(algorithm, publickey)
460
+ elif secretkey is not None and publickey is not None:
461
+ return BIKESecretKey(algorithm, secretkey), BIKEPublicKey(algorithm, publickey)
462
+ else:
463
+ secretkey, publickey = _internal.kemkeygen(algorithm.value) # type: ignore
464
+ return BIKESecretKey(algorithm, secretkey), BIKEPublicKey(algorithm, publickey) # type: ignore
465
+ elif isinstance(algorithm, Algorithm.CLASSICMCELIECE):
466
+ if secretkey is not None and publickey is None:
467
+ return CLASSICMCELIECESecretKey(algorithm, secretkey)
468
+ elif publickey is not None and secretkey is None:
469
+ return CLASSICMCELIECEPublicKey(algorithm, publickey)
470
+ elif secretkey is not None and publickey is not None:
471
+ return CLASSICMCELIECESecretKey(algorithm, secretkey), CLASSICMCELIECEPublicKey(algorithm, publickey)
472
+ else:
473
+ secretkey, publickey = _internal.kemkeygen(algorithm.value) # type: ignore
474
+ return CLASSICMCELIECESecretKey(algorithm, secretkey), CLASSICMCELIECEPublicKey(algorithm, publickey) # type: ignore
475
+ elif isinstance(algorithm, Algorithm.HQC):
476
+ if secretkey is not None and publickey is None:
477
+ return HQCSecretKey(algorithm, secretkey)
478
+ elif publickey is not None and secretkey is None:
479
+ return HQCPublicKey(algorithm, publickey)
480
+ elif secretkey is not None and publickey is not None:
481
+ return HQCSecretKey(algorithm, secretkey), HQCPublicKey(algorithm, publickey)
482
+ else:
483
+ secretkey, publickey = _internal.kemkeygen(algorithm.value) # type: ignore
484
+ return HQCSecretKey(algorithm, secretkey), HQCPublicKey(algorithm, publickey) # type: ignore
485
+ elif isinstance(algorithm, Algorithm.KYBER):
486
+ if secretkey is not None and publickey is None:
487
+ return KYBERSecretKey(algorithm, secretkey)
488
+ elif publickey is not None and secretkey is None:
489
+ return KYBERPublicKey(algorithm, publickey)
490
+ elif secretkey is not None and publickey is not None:
491
+ return KYBERSecretKey(algorithm, secretkey), KYBERPublicKey(algorithm, publickey)
492
+ else:
493
+ secretkey, publickey = _internal.kemkeygen(algorithm.value) # type: ignore
494
+ return KYBERSecretKey(algorithm, secretkey), KYBERPublicKey(algorithm, publickey) # type: ignore
495
+ elif isinstance(algorithm, Algorithm.MLKEM):
496
+ if secretkey is not None and publickey is None:
497
+ return MLKEMSecretKey(algorithm, secretkey)
498
+ elif publickey is not None and secretkey is None:
499
+ return MLKEMPublicKey(algorithm, publickey)
500
+ elif secretkey is not None and publickey is not None:
501
+ return MLKEMSecretKey(algorithm, secretkey), MLKEMPublicKey(algorithm, publickey)
502
+ else:
503
+ secretkey, publickey = _internal.kemkeygen(algorithm.value) # type: ignore
504
+ return MLKEMSecretKey(algorithm, secretkey), MLKEMPublicKey(algorithm, publickey) # type: ignore
505
+ elif isinstance(algorithm, Algorithm.NTRUPRIME):
506
+ if secretkey is not None and publickey is None:
507
+ return NTRUPRIMESecretKey(algorithm, secretkey)
508
+ elif publickey is not None and secretkey is None:
509
+ return NTRUPRIMEPublicKey(algorithm, publickey)
510
+ elif secretkey is not None and publickey is not None:
511
+ return NTRUPRIMESecretKey(algorithm, secretkey), NTRUPRIMEPublicKey(algorithm, publickey)
512
+ else:
513
+ secretkey, publickey = _internal.kemkeygen(algorithm.value) # type: ignore
514
+ return NTRUPRIMESecretKey(algorithm, secretkey), NTRUPRIMEPublicKey(algorithm, publickey) # type: ignore
515
+ elif isinstance(algorithm, Algorithm.FRODOKEM):
516
+ if secretkey is not None and publickey is None:
517
+ return FRODOKEMSecretKey(algorithm, secretkey)
518
+ elif publickey is not None and secretkey is None:
519
+ return FRODOKEMPublicKey(algorithm, publickey)
520
+ elif secretkey is not None and publickey is not None:
521
+ return FRODOKEMSecretKey(algorithm, secretkey), FRODOKEMPublicKey(algorithm, publickey)
522
+ else:
523
+ secretkey, publickey = _internal.kemkeygen(algorithm.value) # type: ignore
524
+ return FRODOKEMSecretKey(algorithm, secretkey), FRODOKEMPublicKey(algorithm, publickey) # type: ignore
525
+ else:
526
+ raise ValueError(f"Unsupported algorithm: {name}")