puantum 1.1.1__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.
- puantum/__init__.py +1 -0
- puantum/__internal__.cp313-win_amd64.pyd +0 -0
- puantum/classic/__init__.py +2 -0
- puantum/quantum/__init__.py +1 -0
- puantum/quantum/dsa/__init__.py +5 -0
- puantum/quantum/dsa/__internal__.py +498 -0
- puantum/quantum/kem/__init__.py +5 -0
- puantum/quantum/kem/__internal__.py +563 -0
- puantum-1.1.1.dist-info/METADATA +66 -0
- puantum-1.1.1.dist-info/RECORD +12 -0
- puantum-1.1.1.dist-info/WHEEL +4 -0
- puantum-1.1.1.dist-info/licenses/license.md +24 -0
puantum/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# EMPTY
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
# EMPTY
|
@@ -0,0 +1,498 @@
|
|
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 CROSS(_enum.Enum):
|
9
|
+
CROSSR128B = "CrossRsdp128Balanced"
|
10
|
+
CROSSR128F = "CrossRsdp128Fast"
|
11
|
+
CROSSR128S = "CrossRsdp128Small"
|
12
|
+
CROSSR192B = "CrossRsdp192Balanced"
|
13
|
+
CROSSR192F = "CrossRsdp192Fast"
|
14
|
+
CROSSR192S = "CrossRsdp192Small"
|
15
|
+
CROSSR256B = "CrossRsdp256Balanced"
|
16
|
+
CROSSR256F = "CrossRsdp256Fast"
|
17
|
+
CROSSR256S = "CrossRsdp256Small"
|
18
|
+
CROSSRG128B = "CrossRsdpg128Balanced"
|
19
|
+
CROSSRG128F = "CrossRsdpg128Fast"
|
20
|
+
CROSSRG128S = "CrossRsdpg128Small"
|
21
|
+
CROSSRG192B = "CrossRsdpg192Balanced"
|
22
|
+
CROSSRG192F = "CrossRsdpg192Fast"
|
23
|
+
CROSSRG192S = "CrossRsdpg192Small"
|
24
|
+
CROSSRG256B = "CrossRsdpg256Balanced"
|
25
|
+
CROSSRG256F = "CrossRsdpg256Fast"
|
26
|
+
CROSSRG256S = "CrossRsdpg256Small"
|
27
|
+
#
|
28
|
+
class DILITHIUM(_enum.Enum):
|
29
|
+
DILITHIUM2 = "Dilithium2"
|
30
|
+
DILITHIUM3 = "Dilithium3"
|
31
|
+
DILITHIUM5 = "Dilithium5"
|
32
|
+
#
|
33
|
+
class FALCON(_enum.Enum):
|
34
|
+
FALCON512 = "Falcon512"
|
35
|
+
FALCON1024 = "Falcon1024"
|
36
|
+
#
|
37
|
+
class MAYO(_enum.Enum):
|
38
|
+
MAYO1 = "Mayo1"
|
39
|
+
MAYO2 = "Mayo2"
|
40
|
+
MAYO3 = "Mayo3"
|
41
|
+
MAYO5 = "Mayo5"
|
42
|
+
#
|
43
|
+
class MLDSA(_enum.Enum):
|
44
|
+
MLDSA44 = "MlDsa44"
|
45
|
+
MLDSA65 = "MlDsa65"
|
46
|
+
MLDSA87 = "MlDsa87"
|
47
|
+
#
|
48
|
+
class SPHINCS(_enum.Enum):
|
49
|
+
SHA2128F = "SphincsSha2128fSimple"
|
50
|
+
SHA2128S = "SphincsSha2128sSimple"
|
51
|
+
SHA2192F = "SphincsSha2192fSimple"
|
52
|
+
SHA2192S = "SphincsSha2192sSimple"
|
53
|
+
SHA2256F = "SphincsSha2256fSimple"
|
54
|
+
SHA2256S = "SphincsSha2256sSimple"
|
55
|
+
SHAKE128F = "SphincsShake128fSimple"
|
56
|
+
SHAKE128S = "SphincsShake128sSimple"
|
57
|
+
SHAKE192F = "SphincsShake192fSimple"
|
58
|
+
SHAKE192S = "SphincsShake192sSimple"
|
59
|
+
SHAKE256F = "SphincsShake256fSimple"
|
60
|
+
SHAKE256S = "SphincsShake256sSimple"
|
61
|
+
#
|
62
|
+
class UOV(_enum.Enum):
|
63
|
+
UOVOVIII = "UovOvIII"
|
64
|
+
UOVOVIIIPKC = "UovOvIIIPkc"
|
65
|
+
UOVOVIIIPKCSKC = "UovOvIIIPkcSkc"
|
66
|
+
UOVOVIP = "UovOvIp"
|
67
|
+
UOVOVIPPKC = "UovOvIpPkc"
|
68
|
+
UOVOVIPPKCSKC = "UovOvIpPkcSkc"
|
69
|
+
UOVOVIS = "UovOvIs"
|
70
|
+
UOVOVISPKC = "UovOvIsPkc"
|
71
|
+
UOVOVISPKCSKC = "UovOvIsPkcSkc"
|
72
|
+
UOVOVV = "UovOvV"
|
73
|
+
UOVOVVPKC = "UovOvVPkc"
|
74
|
+
UOVOVVPKCSKC = "UovOvVPkcSkc"
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
class Signature:
|
79
|
+
def __init__(self, signature: bytes) -> None:
|
80
|
+
if not isinstance(signature, bytes):
|
81
|
+
raise TypeError("Signature Not Valid")
|
82
|
+
#
|
83
|
+
self.signature = signature
|
84
|
+
#
|
85
|
+
return None
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
class CROSSSignature(Signature):
|
90
|
+
def __init__(self, name: Algorithm.CROSS, signature: bytes) -> None:
|
91
|
+
if not isinstance(name, Algorithm.CROSS):
|
92
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
93
|
+
else:
|
94
|
+
super().__init__(signature)
|
95
|
+
#
|
96
|
+
return None
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
class DILITHIUMSignature(Signature):
|
101
|
+
def __init__(self, name: Algorithm.DILITHIUM, signature: bytes) -> None:
|
102
|
+
if not isinstance(name, Algorithm.DILITHIUM):
|
103
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
104
|
+
else:
|
105
|
+
super().__init__(signature)
|
106
|
+
#
|
107
|
+
return None
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
class FALCONSignature(Signature):
|
112
|
+
def __init__(self, name: Algorithm.FALCON, signature: bytes) -> None:
|
113
|
+
if not isinstance(name, Algorithm.FALCON):
|
114
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
115
|
+
else:
|
116
|
+
super().__init__(signature)
|
117
|
+
#
|
118
|
+
return None
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
class MAYOSignature(Signature):
|
123
|
+
def __init__(self, name: Algorithm.MAYO, signature: bytes) -> None:
|
124
|
+
if not isinstance(name, Algorithm.MAYO):
|
125
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
126
|
+
else:
|
127
|
+
super().__init__(signature)
|
128
|
+
#
|
129
|
+
return None
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
class MLDSASignature(Signature):
|
134
|
+
def __init__(self, name: Algorithm.MLDSA, signature: bytes) -> None:
|
135
|
+
if not isinstance(name, Algorithm.MLDSA):
|
136
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
137
|
+
else:
|
138
|
+
super().__init__(signature)
|
139
|
+
#
|
140
|
+
return None
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
class SPHINCSSignature(Signature):
|
145
|
+
def __init__(self, name: Algorithm.SPHINCS, signature: bytes) -> None:
|
146
|
+
if not isinstance(name, Algorithm.SPHINCS):
|
147
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
148
|
+
else:
|
149
|
+
super().__init__(signature)
|
150
|
+
#
|
151
|
+
return None
|
152
|
+
|
153
|
+
|
154
|
+
class UOVSignature(Signature):
|
155
|
+
def __init__(self, name: Algorithm.UOV, signature: bytes) -> None:
|
156
|
+
if not isinstance(name, Algorithm.UOV):
|
157
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
158
|
+
else:
|
159
|
+
super().__init__(signature)
|
160
|
+
#
|
161
|
+
return None
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
class PublicKey:
|
166
|
+
def __init__(self, publickey: bytes) -> None:
|
167
|
+
if not isinstance(publickey, bytes):
|
168
|
+
raise TypeError("PublicKey Not Valid")
|
169
|
+
#
|
170
|
+
self.publickey = publickey
|
171
|
+
#
|
172
|
+
return None
|
173
|
+
#
|
174
|
+
def verify(self, signature: _typing.Any, message: _typing.Any) -> _typing.Any:
|
175
|
+
raise NotImplementedError()
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
class CROSSPublicKey(PublicKey):
|
180
|
+
def __init__(self, name: Algorithm.CROSS, publickey: bytes) -> None:
|
181
|
+
if not isinstance(name, Algorithm.CROSS):
|
182
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
183
|
+
else:
|
184
|
+
super().__init__(publickey)
|
185
|
+
#
|
186
|
+
self._algorithm = name
|
187
|
+
#
|
188
|
+
return None
|
189
|
+
#
|
190
|
+
def verify(self, signature: CROSSSignature, message: bytes) -> bool:
|
191
|
+
result: bool = _internal.sigverify(self._algorithm.value, self.publickey, signature.signature, message) # type: ignore
|
192
|
+
return result # type: ignore
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
class DILITHIUMPublicKey(PublicKey):
|
197
|
+
def __init__(self, name: Algorithm.DILITHIUM, publickey: bytes) -> None:
|
198
|
+
if not isinstance(name, Algorithm.DILITHIUM):
|
199
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
200
|
+
else:
|
201
|
+
super().__init__(publickey)
|
202
|
+
#
|
203
|
+
self._algorithm = name
|
204
|
+
#
|
205
|
+
return None
|
206
|
+
#
|
207
|
+
def verify(self, signature: DILITHIUMSignature, message: bytes) -> bool:
|
208
|
+
result: bool = _internal.sigverify(self._algorithm.value, self.publickey, signature.signature, message) # type: ignore
|
209
|
+
return result # type: ignore
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
class FALCONPublicKey(PublicKey):
|
214
|
+
def __init__(self, name: Algorithm.FALCON, publickey: bytes) -> None:
|
215
|
+
if not isinstance(name, Algorithm.FALCON):
|
216
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
217
|
+
else:
|
218
|
+
super().__init__(publickey)
|
219
|
+
#
|
220
|
+
self._algorithm = name
|
221
|
+
#
|
222
|
+
return None
|
223
|
+
#
|
224
|
+
def verify(self, signature: FALCONSignature, message: bytes) -> bool:
|
225
|
+
result: bool = _internal.sigverify(self._algorithm.value, self.publickey, signature.signature, message) # type: ignore
|
226
|
+
return result # type: ignore
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
class MAYOPublicKey(PublicKey):
|
231
|
+
def __init__(self, name: Algorithm.MAYO, publickey: bytes) -> None:
|
232
|
+
if not isinstance(name, Algorithm.MAYO):
|
233
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
234
|
+
else:
|
235
|
+
super().__init__(publickey)
|
236
|
+
#
|
237
|
+
self._algorithm = name
|
238
|
+
#
|
239
|
+
return None
|
240
|
+
#
|
241
|
+
def verify(self, signature: MAYOSignature, message: bytes) -> bool:
|
242
|
+
result: bool = _internal.sigverify(self._algorithm.value, self.publickey, signature.signature, message) # type: ignore
|
243
|
+
return result # type: ignore
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
class MLDSAPublicKey(PublicKey):
|
248
|
+
def __init__(self, name: Algorithm.MLDSA, publickey: bytes) -> None:
|
249
|
+
if not isinstance(name, Algorithm.MLDSA):
|
250
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
251
|
+
else:
|
252
|
+
super().__init__(publickey)
|
253
|
+
#
|
254
|
+
self._algorithm = name
|
255
|
+
#
|
256
|
+
return None
|
257
|
+
#
|
258
|
+
def verify(self, signature: MLDSASignature, message: bytes) -> bool:
|
259
|
+
result: bool = _internal.sigverify(self._algorithm.value, self.publickey, signature.signature, message) # type: ignore
|
260
|
+
return result # type: ignore
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
class SPHINCSPublicKey(PublicKey):
|
265
|
+
def __init__(self, name: Algorithm.SPHINCS, publickey: bytes) -> None:
|
266
|
+
if not isinstance(name, Algorithm.SPHINCS):
|
267
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
268
|
+
else:
|
269
|
+
super().__init__(publickey)
|
270
|
+
#
|
271
|
+
self._algorithm = name
|
272
|
+
#
|
273
|
+
return None
|
274
|
+
#
|
275
|
+
def verify(self, signature: SPHINCSSignature, message: bytes) -> bool:
|
276
|
+
result: bool = _internal.sigverify(self._algorithm.value, self.publickey, signature.signature, message) # type: ignore
|
277
|
+
return result # type: ignore
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
class UOVPublicKey(PublicKey):
|
282
|
+
def __init__(self, name: Algorithm.UOV, publickey: bytes) -> None:
|
283
|
+
if not isinstance(name, Algorithm.UOV):
|
284
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
285
|
+
else:
|
286
|
+
super().__init__(publickey)
|
287
|
+
#
|
288
|
+
self._algorithm = name
|
289
|
+
#
|
290
|
+
return None
|
291
|
+
#
|
292
|
+
def verify(self, signature: UOVSignature, message: bytes) -> bool:
|
293
|
+
result: bool = _internal.sigverify(self._algorithm.value, self.publickey, signature.signature, message) # type: ignore
|
294
|
+
return result # type: ignore
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
class SecretKey:
|
299
|
+
def __init__(self, secretkey: bytes) -> None:
|
300
|
+
if not isinstance(secretkey, bytes):
|
301
|
+
raise TypeError("SecretKey Not Valid")
|
302
|
+
#
|
303
|
+
self.secretkey = secretkey
|
304
|
+
#
|
305
|
+
return None
|
306
|
+
#
|
307
|
+
def sign(self, message: _typing.Any) -> _typing.Any:
|
308
|
+
raise NotImplementedError()
|
309
|
+
|
310
|
+
|
311
|
+
|
312
|
+
class CROSSSecretKey(SecretKey):
|
313
|
+
def __init__(self, name: Algorithm.CROSS, secretkey: bytes) -> None:
|
314
|
+
if not isinstance(name, Algorithm.CROSS):
|
315
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
316
|
+
else:
|
317
|
+
super().__init__(secretkey)
|
318
|
+
#
|
319
|
+
self._algorithm = name
|
320
|
+
#
|
321
|
+
return None
|
322
|
+
#
|
323
|
+
def sign(self, message: bytes) -> CROSSSignature:
|
324
|
+
signature: bytes = _internal.sigsign(self._algorithm.value, self.secretkey, message) # type: ignore
|
325
|
+
return CROSSSignature(self._algorithm, signature) # type: ignore
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
class DILITHIUMSecretKey(SecretKey):
|
330
|
+
def __init__(self, name: Algorithm.DILITHIUM, secretkey: bytes) -> None:
|
331
|
+
if not isinstance(name, Algorithm.DILITHIUM):
|
332
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
333
|
+
else:
|
334
|
+
super().__init__(secretkey)
|
335
|
+
#
|
336
|
+
self._algorithm = name
|
337
|
+
#
|
338
|
+
return None
|
339
|
+
#
|
340
|
+
def sign(self, message: bytes) -> DILITHIUMSignature:
|
341
|
+
signature: bytes = _internal.sigsign(self._algorithm.value, self.secretkey, message) # type: ignore
|
342
|
+
return DILITHIUMSignature(self._algorithm, signature) # type: ignore
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
class FALCONSecretKey(SecretKey):
|
347
|
+
def __init__(self, name: Algorithm.FALCON, secretkey: bytes) -> None:
|
348
|
+
if not isinstance(name, Algorithm.FALCON):
|
349
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
350
|
+
else:
|
351
|
+
super().__init__(secretkey)
|
352
|
+
#
|
353
|
+
self._algorithm = name
|
354
|
+
#
|
355
|
+
return None
|
356
|
+
#
|
357
|
+
def sign(self, message: bytes) -> FALCONSignature:
|
358
|
+
signature: bytes = _internal.sigsign(self._algorithm.value, self.secretkey, message) # type: ignore
|
359
|
+
return FALCONSignature(self._algorithm, signature) # type: ignore
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
class MAYOSecretKey(SecretKey):
|
364
|
+
def __init__(self, name: Algorithm.MAYO, secretkey: bytes) -> None:
|
365
|
+
if not isinstance(name, Algorithm.MAYO):
|
366
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
367
|
+
else:
|
368
|
+
super().__init__(secretkey)
|
369
|
+
#
|
370
|
+
self._algorithm = name
|
371
|
+
#
|
372
|
+
return None
|
373
|
+
#
|
374
|
+
def sign(self, message: bytes) -> MAYOSignature:
|
375
|
+
signature: bytes = _internal.sigsign(self._algorithm.value, self.secretkey, message) # type: ignore
|
376
|
+
return MAYOSignature(self._algorithm, signature) # type: ignore
|
377
|
+
|
378
|
+
|
379
|
+
|
380
|
+
class MLDSASecretKey(SecretKey):
|
381
|
+
def __init__(self, name: Algorithm.MLDSA, secretkey: bytes) -> None:
|
382
|
+
if not isinstance(name, Algorithm.MLDSA):
|
383
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
384
|
+
else:
|
385
|
+
super().__init__(secretkey)
|
386
|
+
#
|
387
|
+
self._algorithm = name
|
388
|
+
#
|
389
|
+
return None
|
390
|
+
#
|
391
|
+
def sign(self, message: bytes) -> MLDSASignature:
|
392
|
+
signature: bytes = _internal.sigsign(self._algorithm.value, self.secretkey, message) # type: ignore
|
393
|
+
return MLDSASignature(self._algorithm, signature) # type: ignore
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
class SPHINCSSecretKey(SecretKey):
|
398
|
+
def __init__(self, name: Algorithm.SPHINCS, secretkey: bytes) -> None:
|
399
|
+
if not isinstance(name, Algorithm.SPHINCS):
|
400
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
401
|
+
else:
|
402
|
+
super().__init__(secretkey)
|
403
|
+
#
|
404
|
+
self._algorithm = name
|
405
|
+
#
|
406
|
+
return None
|
407
|
+
#
|
408
|
+
def sign(self, message: bytes) -> SPHINCSSignature:
|
409
|
+
signature: bytes = _internal.sigsign(self._algorithm.value, self.secretkey, message) # type: ignore
|
410
|
+
return SPHINCSSignature(self._algorithm, signature) # type: ignore
|
411
|
+
|
412
|
+
|
413
|
+
|
414
|
+
class UOVSecretKey(SecretKey):
|
415
|
+
def __init__(self, name: Algorithm.UOV, secretkey: bytes) -> None:
|
416
|
+
if not isinstance(name, Algorithm.UOV):
|
417
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
418
|
+
else:
|
419
|
+
super().__init__(secretkey)
|
420
|
+
#
|
421
|
+
self._algorithm = name
|
422
|
+
#
|
423
|
+
return None
|
424
|
+
#
|
425
|
+
def sign(self, message: bytes) -> UOVSignature:
|
426
|
+
signature: bytes = _internal.sigsign(self._algorithm.value, self.secretkey, message) # type: ignore
|
427
|
+
return UOVSignature(self._algorithm, signature) # type: ignore
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
Algorithms = Algorithm | Algorithm.CROSS | Algorithm.DILITHIUM | Algorithm.FALCON | Algorithm.MAYO | Algorithm.MLDSA | Algorithm.SPHINCS | Algorithm.UOV
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
@_typing.overload
|
436
|
+
def KeyPair(name: Algorithm) -> tuple[SecretKey, PublicKey]: ...
|
437
|
+
|
438
|
+
|
439
|
+
@_typing.overload
|
440
|
+
def KeyPair(name: Algorithm.CROSS) -> tuple[CROSSSecretKey, CROSSPublicKey]: ...
|
441
|
+
|
442
|
+
|
443
|
+
|
444
|
+
@_typing.overload
|
445
|
+
def KeyPair(name: Algorithm.DILITHIUM) -> tuple[DILITHIUMSecretKey, DILITHIUMPublicKey]: ...
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
@_typing.overload
|
450
|
+
def KeyPair(name: Algorithm.FALCON) -> tuple[FALCONSecretKey, FALCONPublicKey]: ...
|
451
|
+
|
452
|
+
|
453
|
+
|
454
|
+
@_typing.overload
|
455
|
+
def KeyPair(name: Algorithm.MAYO) -> tuple[MAYOSecretKey, MAYOPublicKey]: ...
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
@_typing.overload
|
460
|
+
def KeyPair(name: Algorithm.MLDSA) -> tuple[MLDSASecretKey, MLDSAPublicKey]: ...
|
461
|
+
|
462
|
+
|
463
|
+
|
464
|
+
@_typing.overload
|
465
|
+
def KeyPair(name: Algorithm.SPHINCS) -> tuple[SPHINCSSecretKey, SPHINCSPublicKey]: ...
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
@_typing.overload
|
470
|
+
def KeyPair(name: Algorithm.UOV) -> tuple[UOVSecretKey, UOVPublicKey]: ...
|
471
|
+
|
472
|
+
|
473
|
+
|
474
|
+
def KeyPair(name: Algorithms) -> tuple[SecretKey, PublicKey]:
|
475
|
+
algorithm = name
|
476
|
+
if isinstance(algorithm, Algorithm.CROSS):
|
477
|
+
secretkey, publickey = _internal.sigkeygen(algorithm.value) # type: ignore
|
478
|
+
return CROSSSecretKey(algorithm, secretkey), CROSSPublicKey(algorithm, publickey) # type: ignore
|
479
|
+
elif isinstance(algorithm, Algorithm.DILITHIUM):
|
480
|
+
secretkey, publickey = _internal.sigkeygen(algorithm.value) # type: ignore
|
481
|
+
return DILITHIUMSecretKey(algorithm, secretkey), DILITHIUMPublicKey(algorithm, publickey) # type: ignore
|
482
|
+
elif isinstance(algorithm, Algorithm.FALCON):
|
483
|
+
secretkey, publickey = _internal.sigkeygen(algorithm.value) # type: ignore
|
484
|
+
return FALCONSecretKey(algorithm, secretkey), FALCONPublicKey(algorithm, publickey) # type: ignore
|
485
|
+
elif isinstance(algorithm, Algorithm.MAYO):
|
486
|
+
secretkey, publickey = _internal.sigkeygen(algorithm.value) # type: ignore
|
487
|
+
return MAYOSecretKey(algorithm, secretkey), MAYOPublicKey(algorithm, publickey) # type: ignore
|
488
|
+
elif isinstance(algorithm, Algorithm.MLDSA):
|
489
|
+
secretkey, publickey = _internal.sigkeygen(algorithm.value) # type: ignore
|
490
|
+
return MLDSASecretKey(algorithm, secretkey), MLDSAPublicKey(algorithm, publickey) # type: ignore
|
491
|
+
elif isinstance(algorithm, Algorithm.SPHINCS):
|
492
|
+
secretkey, publickey = _internal.sigkeygen(algorithm.value) # type: ignore
|
493
|
+
return SPHINCSSecretKey(algorithm, secretkey), SPHINCSPublicKey(algorithm, publickey) # type: ignore
|
494
|
+
elif isinstance(algorithm, Algorithm.UOV):
|
495
|
+
secretkey, publickey = _internal.sigkeygen(algorithm.value) # type: ignore
|
496
|
+
return UOVSecretKey(algorithm, secretkey), UOVPublicKey(algorithm, publickey) # type: ignore
|
497
|
+
else:
|
498
|
+
raise ValueError(f"Unsupported algorithm: {name}")
|
@@ -0,0 +1,563 @@
|
|
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}")
|
@@ -0,0 +1,66 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: puantum
|
3
|
+
Version: 1.1.1
|
4
|
+
Classifier: Programming Language :: Python :: 3
|
5
|
+
Classifier: Programming Language :: Rust
|
6
|
+
Classifier: Operating System :: OS Independent
|
7
|
+
Classifier: License :: Public Domain
|
8
|
+
Classifier: License :: OSI Approved :: The Unlicense (Unlicense)
|
9
|
+
License-File: license.md
|
10
|
+
Summary: Python Cryptography
|
11
|
+
Keywords: python,cryptography,quantum,security
|
12
|
+
Author-email: Anonymous <217687495+1xfakebit@users.noreply.github.com>
|
13
|
+
License: Unlicense
|
14
|
+
Description-Content-Type: text/markdown
|
15
|
+
Project-URL: source, https://github.com/1xfakebit/puantum
|
16
|
+
Project-URL: x, https://x.com/1xfakebit
|
17
|
+
|
18
|
+
# 🔐 Python Cryptography
|
19
|
+
|
20
|
+
A blazing-fast cryptography library for Python, built on Rust.
|
21
|
+
|
22
|
+
Puantum supports an extensive set of **post-quantum** key encapsulation mechanisms (KEM) and digital signature algorithms (DSA), and will soon support **classic cryptography** as well.
|
23
|
+
|
24
|
+
---
|
25
|
+
## ⚡ Features
|
26
|
+
- ✅ Dozens of NIST PQC candidates
|
27
|
+
- 🦀 Rust core for speed and safety
|
28
|
+
- 📦 Easy installation via [`pip`](https://pip.pypa.io)
|
29
|
+
---
|
30
|
+
|
31
|
+
### 🧬 Supported Algorithms
|
32
|
+
|
33
|
+
### 🛡️ KEM
|
34
|
+
- #### Bike
|
35
|
+
- #### ClassicMcEliece
|
36
|
+
- #### Hqc
|
37
|
+
- #### Kyber
|
38
|
+
- #### MLKEM
|
39
|
+
- #### NtruPrime
|
40
|
+
- #### FrodoKem
|
41
|
+
|
42
|
+
### ✍️ DSA
|
43
|
+
- #### Cross
|
44
|
+
- #### Dilithium
|
45
|
+
- #### Falcon
|
46
|
+
- #### Mayo
|
47
|
+
- #### MLDSA
|
48
|
+
- #### Sphincs
|
49
|
+
- #### Uov
|
50
|
+
|
51
|
+
### 🚧 Coming Soon
|
52
|
+
- #### AES, ChaCha20, XChaCha20
|
53
|
+
- #### RSA, EC
|
54
|
+
- #### Argon2, Bcrypt
|
55
|
+
|
56
|
+
### 📦 Install
|
57
|
+
```shell
|
58
|
+
pip install puantum
|
59
|
+
```
|
60
|
+
#### or from source:
|
61
|
+
```shell
|
62
|
+
make python
|
63
|
+
```
|
64
|
+
|
65
|
+
### 🥳 Enjoy!
|
66
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
puantum-1.1.1.dist-info/METADATA,sha256=fkR1pA0LXrj7i6HDAAq1vnQi2anznKaHLtx54kkSh0k,1524
|
2
|
+
puantum-1.1.1.dist-info/WHEEL,sha256=AUbk9LW_pz5a6zxr9a09TpfZobAyvDuruoOj7fuVtLM,96
|
3
|
+
puantum-1.1.1.dist-info/licenses/license.md,sha256=tQZYOMusRS38hVum5uAxSBrSxoQG9w0h6tkyE3RlPmw,1212
|
4
|
+
puantum/__init__.py,sha256=DqzIK80d6ihVj9p2qBPJwBjM0V3kl6MRRjKowVB61Ak,8
|
5
|
+
puantum/__internal__.cp313-win_amd64.pyd,sha256=cjhOPOrmTQyz-wQLWpjppo5BYtiAYF5joWpGf1rNUOQ,4341248
|
6
|
+
puantum/classic/__init__.py,sha256=Dlr1m0uJio3HWH8_gkdhnQS87KUZfUw5wX4tXQtbvWQ,35
|
7
|
+
puantum/quantum/__init__.py,sha256=DqzIK80d6ihVj9p2qBPJwBjM0V3kl6MRRjKowVB61Ak,8
|
8
|
+
puantum/quantum/dsa/__init__.py,sha256=r9eRKYMhU7KC2nwb1hW26KVpwz2XuXDQBzW3m36yCkM,127
|
9
|
+
puantum/quantum/dsa/__internal__.py,sha256=A7oG_CDypKWhlKkjSRNRgyCrdrx2ekx3kTJaJED_Lmg,16609
|
10
|
+
puantum/quantum/kem/__init__.py,sha256=U3TwWZ7eIYQgPeMXN2pfQvaqdWQimQTP-KDosfFvwk0,127
|
11
|
+
puantum/quantum/kem/__internal__.py,sha256=iXegH9Zxh5M2L1ZK-7wLjRKehCruxK_W4X9OORGG8r0,19485
|
12
|
+
puantum-1.1.1.dist-info/RECORD,,
|
@@ -0,0 +1,24 @@
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
+
distribute this software, either in source code form or as a compiled
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
+
means.
|
7
|
+
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
+
of this software dedicate any and all copyright interest in the
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
11
|
+
of the public at large and to the detriment of our heirs and
|
12
|
+
successors. We intend this dedication to be an overt act of
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
14
|
+
software under copyright law.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
For more information, please refer to <https://unlicense.org/>
|