-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathkem_algos.py
More file actions
73 lines (61 loc) · 3.52 KB
/
kem_algos.py
File metadata and controls
73 lines (61 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#
# MIT License
#
# Copyright (c) 2024, Mattias Aabmets
#
# The contents of this file are subject to the terms and conditions defined in the License.
# You may not use, modify, or distribute this file except in compliance with the License.
#
# SPDX-License-Identifier: MIT
#
from quantcrypt.internal import utils, constants as const
from quantcrypt.internal.pqa.base_kem import BaseKEM
__all__ = ["MLKEM_512", "MLKEM_768", "MLKEM_1024"]
class MLKEM_512(BaseKEM): # NOSONAR
@utils.input_validator()
def __init__(self, variant: const.PQAVariant = None, *, allow_fallback: bool = True) -> None:
"""
Initializes the MLKEM_512 key encapsulation mechanism algorithm
instance with compiled C extension binaries.
:param variant: Which compiled binary to use underneath.
When variant is None *(auto-select mode)*, QuantCrypt will first try to use
platform-optimized binaries. If it fails to do so and fallback is allowed,
it will then try to fall back to using clean reference binaries.
:param allow_fallback: Allow falling back to using clean reference binaries when
QuantCrypt has failed to import platform-optimized binaries. Defaults to True.
:raises - ImportFailedError: When QuantCrypt has failed to fall back to using clean
reference binaries, either because they are missing or fallback was not permitted.
"""
super().__init__(variant, allow_fallback)
class MLKEM_768(BaseKEM): # NOSONAR
@utils.input_validator()
def __init__(self, variant: const.PQAVariant = None, *, allow_fallback: bool = True) -> None:
"""
Initializes the MLKEM_512 key encapsulation mechanism algorithm
instance with compiled C extension binaries.
:param variant: Which compiled binary to use underneath.
When variant is None *(auto-select mode)*, QuantCrypt will first try to use
platform-optimized binaries. If it fails to do so and fallback is allowed,
it will then try to fall back to using clean reference binaries.
:param allow_fallback: Allow falling back to using clean reference binaries when
QuantCrypt has failed to import platform-optimized binaries. Defaults to True.
:raises - ImportFailedError: When QuantCrypt has failed to fall back to using clean
reference binaries, either because they are missing or fallback was not permitted.
"""
super().__init__(variant, allow_fallback)
class MLKEM_1024(BaseKEM): # NOSONAR
@utils.input_validator()
def __init__(self, variant: const.PQAVariant = None, *, allow_fallback: bool = True) -> None:
"""
Initializes the MLKEM_512 key encapsulation mechanism algorithm
instance with compiled C extension binaries.
:param variant: Which compiled binary to use underneath.
When variant is None *(auto-select mode)*, QuantCrypt will first try to use
platform-optimized binaries. If it fails to do so and fallback is allowed,
it will then try to fall back to using clean reference binaries.
:param allow_fallback: Allow falling back to using clean reference binaries when
QuantCrypt has failed to import platform-optimized binaries. Defaults to True.
:raises - ImportFailedError: When QuantCrypt has failed to fall back to using clean
reference binaries, either because they are missing or fallback was not permitted.
"""
super().__init__(variant, allow_fallback)