koichi12 commited on
Commit
66f4e48
·
verified ·
1 Parent(s): d13f4a1

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. .venv/lib/python3.11/site-packages/cryptography/__about__.py +17 -0
  3. .venv/lib/python3.11/site-packages/cryptography/__init__.py +13 -0
  4. .venv/lib/python3.11/site-packages/cryptography/__pycache__/__about__.cpython-311.pyc +0 -0
  5. .venv/lib/python3.11/site-packages/cryptography/__pycache__/__init__.cpython-311.pyc +0 -0
  6. .venv/lib/python3.11/site-packages/cryptography/__pycache__/exceptions.cpython-311.pyc +0 -0
  7. .venv/lib/python3.11/site-packages/cryptography/__pycache__/fernet.cpython-311.pyc +0 -0
  8. .venv/lib/python3.11/site-packages/cryptography/__pycache__/utils.cpython-311.pyc +0 -0
  9. .venv/lib/python3.11/site-packages/cryptography/exceptions.py +52 -0
  10. .venv/lib/python3.11/site-packages/cryptography/fernet.py +215 -0
  11. .venv/lib/python3.11/site-packages/cryptography/hazmat/__init__.py +13 -0
  12. .venv/lib/python3.11/site-packages/cryptography/hazmat/_oid.py +313 -0
  13. .venv/lib/python3.11/site-packages/cryptography/hazmat/backends/__init__.py +13 -0
  14. .venv/lib/python3.11/site-packages/cryptography/hazmat/backends/__pycache__/__init__.cpython-311.pyc +0 -0
  15. .venv/lib/python3.11/site-packages/cryptography/hazmat/backends/openssl/__init__.py +9 -0
  16. .venv/lib/python3.11/site-packages/cryptography/hazmat/backends/openssl/__pycache__/__init__.cpython-311.pyc +0 -0
  17. .venv/lib/python3.11/site-packages/cryptography/hazmat/backends/openssl/__pycache__/backend.cpython-311.pyc +0 -0
  18. .venv/lib/python3.11/site-packages/cryptography/hazmat/backends/openssl/backend.py +291 -0
  19. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/__init__.py +3 -0
  20. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/_asymmetric.py +19 -0
  21. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/_cipheralgorithm.py +58 -0
  22. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/_serialization.py +169 -0
  23. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__init__.py +3 -0
  24. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/__init__.cpython-311.pyc +0 -0
  25. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/dh.cpython-311.pyc +0 -0
  26. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/dsa.cpython-311.pyc +0 -0
  27. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/ec.cpython-311.pyc +0 -0
  28. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/ed25519.cpython-311.pyc +0 -0
  29. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/ed448.cpython-311.pyc +0 -0
  30. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/padding.cpython-311.pyc +0 -0
  31. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/rsa.cpython-311.pyc +0 -0
  32. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/types.cpython-311.pyc +0 -0
  33. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/utils.cpython-311.pyc +0 -0
  34. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/x25519.cpython-311.pyc +0 -0
  35. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/x448.cpython-311.pyc +0 -0
  36. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/dh.py +135 -0
  37. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py +154 -0
  38. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/ec.py +403 -0
  39. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/ed25519.py +116 -0
  40. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/ed448.py +118 -0
  41. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/padding.py +113 -0
  42. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.py +260 -0
  43. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/types.py +111 -0
  44. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/utils.py +24 -0
  45. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/x25519.py +109 -0
  46. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/x448.py +112 -0
  47. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/cmac.py +10 -0
  48. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/constant_time.py +14 -0
  49. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/hashes.py +242 -0
  50. .venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/hmac.py +13 -0
.gitattributes CHANGED
@@ -328,3 +328,4 @@ tuning-competition-baseline/.venv/lib/python3.11/site-packages/nvidia/cudnn/lib/
328
  .venv/lib/python3.11/site-packages/networkx/utils/__pycache__/backends.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
329
  .venv/lib/python3.11/site-packages/httptools/parser/url_parser.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
330
  .venv/lib/python3.11/site-packages/httptools/parser/parser.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
 
 
328
  .venv/lib/python3.11/site-packages/networkx/utils/__pycache__/backends.cpython-311.pyc filter=lfs diff=lfs merge=lfs -text
329
  .venv/lib/python3.11/site-packages/httptools/parser/url_parser.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
330
  .venv/lib/python3.11/site-packages/httptools/parser/parser.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
331
+ .venv/lib/python3.11/site-packages/yarl/_quoting_c.cpython-311-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
.venv/lib/python3.11/site-packages/cryptography/__about__.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ __all__ = [
8
+ "__author__",
9
+ "__copyright__",
10
+ "__version__",
11
+ ]
12
+
13
+ __version__ = "43.0.3"
14
+
15
+
16
+ __author__ = "The Python Cryptographic Authority and individual contributors"
17
+ __copyright__ = f"Copyright 2013-2024 {__author__}"
.venv/lib/python3.11/site-packages/cryptography/__init__.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ from cryptography.__about__ import __author__, __copyright__, __version__
8
+
9
+ __all__ = [
10
+ "__author__",
11
+ "__copyright__",
12
+ "__version__",
13
+ ]
.venv/lib/python3.11/site-packages/cryptography/__pycache__/__about__.cpython-311.pyc ADDED
Binary file (477 Bytes). View file
 
.venv/lib/python3.11/site-packages/cryptography/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (410 Bytes). View file
 
.venv/lib/python3.11/site-packages/cryptography/__pycache__/exceptions.cpython-311.pyc ADDED
Binary file (2.95 kB). View file
 
.venv/lib/python3.11/site-packages/cryptography/__pycache__/fernet.cpython-311.pyc ADDED
Binary file (11.9 kB). View file
 
.venv/lib/python3.11/site-packages/cryptography/__pycache__/utils.cpython-311.pyc ADDED
Binary file (7.1 kB). View file
 
.venv/lib/python3.11/site-packages/cryptography/exceptions.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import typing
8
+
9
+ from cryptography.hazmat.bindings._rust import exceptions as rust_exceptions
10
+
11
+ if typing.TYPE_CHECKING:
12
+ from cryptography.hazmat.bindings._rust import openssl as rust_openssl
13
+
14
+ _Reasons = rust_exceptions._Reasons
15
+
16
+
17
+ class UnsupportedAlgorithm(Exception):
18
+ def __init__(self, message: str, reason: _Reasons | None = None) -> None:
19
+ super().__init__(message)
20
+ self._reason = reason
21
+
22
+
23
+ class AlreadyFinalized(Exception):
24
+ pass
25
+
26
+
27
+ class AlreadyUpdated(Exception):
28
+ pass
29
+
30
+
31
+ class NotYetFinalized(Exception):
32
+ pass
33
+
34
+
35
+ class InvalidTag(Exception):
36
+ pass
37
+
38
+
39
+ class InvalidSignature(Exception):
40
+ pass
41
+
42
+
43
+ class InternalError(Exception):
44
+ def __init__(
45
+ self, msg: str, err_code: list[rust_openssl.OpenSSLError]
46
+ ) -> None:
47
+ super().__init__(msg)
48
+ self.err_code = err_code
49
+
50
+
51
+ class InvalidKey(Exception):
52
+ pass
.venv/lib/python3.11/site-packages/cryptography/fernet.py ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import base64
8
+ import binascii
9
+ import os
10
+ import time
11
+ import typing
12
+
13
+ from cryptography import utils
14
+ from cryptography.exceptions import InvalidSignature
15
+ from cryptography.hazmat.primitives import hashes, padding
16
+ from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
17
+ from cryptography.hazmat.primitives.hmac import HMAC
18
+
19
+
20
+ class InvalidToken(Exception):
21
+ pass
22
+
23
+
24
+ _MAX_CLOCK_SKEW = 60
25
+
26
+
27
+ class Fernet:
28
+ def __init__(
29
+ self,
30
+ key: bytes | str,
31
+ backend: typing.Any = None,
32
+ ) -> None:
33
+ try:
34
+ key = base64.urlsafe_b64decode(key)
35
+ except binascii.Error as exc:
36
+ raise ValueError(
37
+ "Fernet key must be 32 url-safe base64-encoded bytes."
38
+ ) from exc
39
+ if len(key) != 32:
40
+ raise ValueError(
41
+ "Fernet key must be 32 url-safe base64-encoded bytes."
42
+ )
43
+
44
+ self._signing_key = key[:16]
45
+ self._encryption_key = key[16:]
46
+
47
+ @classmethod
48
+ def generate_key(cls) -> bytes:
49
+ return base64.urlsafe_b64encode(os.urandom(32))
50
+
51
+ def encrypt(self, data: bytes) -> bytes:
52
+ return self.encrypt_at_time(data, int(time.time()))
53
+
54
+ def encrypt_at_time(self, data: bytes, current_time: int) -> bytes:
55
+ iv = os.urandom(16)
56
+ return self._encrypt_from_parts(data, current_time, iv)
57
+
58
+ def _encrypt_from_parts(
59
+ self, data: bytes, current_time: int, iv: bytes
60
+ ) -> bytes:
61
+ utils._check_bytes("data", data)
62
+
63
+ padder = padding.PKCS7(algorithms.AES.block_size).padder()
64
+ padded_data = padder.update(data) + padder.finalize()
65
+ encryptor = Cipher(
66
+ algorithms.AES(self._encryption_key),
67
+ modes.CBC(iv),
68
+ ).encryptor()
69
+ ciphertext = encryptor.update(padded_data) + encryptor.finalize()
70
+
71
+ basic_parts = (
72
+ b"\x80"
73
+ + current_time.to_bytes(length=8, byteorder="big")
74
+ + iv
75
+ + ciphertext
76
+ )
77
+
78
+ h = HMAC(self._signing_key, hashes.SHA256())
79
+ h.update(basic_parts)
80
+ hmac = h.finalize()
81
+ return base64.urlsafe_b64encode(basic_parts + hmac)
82
+
83
+ def decrypt(self, token: bytes | str, ttl: int | None = None) -> bytes:
84
+ timestamp, data = Fernet._get_unverified_token_data(token)
85
+ if ttl is None:
86
+ time_info = None
87
+ else:
88
+ time_info = (ttl, int(time.time()))
89
+ return self._decrypt_data(data, timestamp, time_info)
90
+
91
+ def decrypt_at_time(
92
+ self, token: bytes | str, ttl: int, current_time: int
93
+ ) -> bytes:
94
+ if ttl is None:
95
+ raise ValueError(
96
+ "decrypt_at_time() can only be used with a non-None ttl"
97
+ )
98
+ timestamp, data = Fernet._get_unverified_token_data(token)
99
+ return self._decrypt_data(data, timestamp, (ttl, current_time))
100
+
101
+ def extract_timestamp(self, token: bytes | str) -> int:
102
+ timestamp, data = Fernet._get_unverified_token_data(token)
103
+ # Verify the token was not tampered with.
104
+ self._verify_signature(data)
105
+ return timestamp
106
+
107
+ @staticmethod
108
+ def _get_unverified_token_data(token: bytes | str) -> tuple[int, bytes]:
109
+ if not isinstance(token, (str, bytes)):
110
+ raise TypeError("token must be bytes or str")
111
+
112
+ try:
113
+ data = base64.urlsafe_b64decode(token)
114
+ except (TypeError, binascii.Error):
115
+ raise InvalidToken
116
+
117
+ if not data or data[0] != 0x80:
118
+ raise InvalidToken
119
+
120
+ if len(data) < 9:
121
+ raise InvalidToken
122
+
123
+ timestamp = int.from_bytes(data[1:9], byteorder="big")
124
+ return timestamp, data
125
+
126
+ def _verify_signature(self, data: bytes) -> None:
127
+ h = HMAC(self._signing_key, hashes.SHA256())
128
+ h.update(data[:-32])
129
+ try:
130
+ h.verify(data[-32:])
131
+ except InvalidSignature:
132
+ raise InvalidToken
133
+
134
+ def _decrypt_data(
135
+ self,
136
+ data: bytes,
137
+ timestamp: int,
138
+ time_info: tuple[int, int] | None,
139
+ ) -> bytes:
140
+ if time_info is not None:
141
+ ttl, current_time = time_info
142
+ if timestamp + ttl < current_time:
143
+ raise InvalidToken
144
+
145
+ if current_time + _MAX_CLOCK_SKEW < timestamp:
146
+ raise InvalidToken
147
+
148
+ self._verify_signature(data)
149
+
150
+ iv = data[9:25]
151
+ ciphertext = data[25:-32]
152
+ decryptor = Cipher(
153
+ algorithms.AES(self._encryption_key), modes.CBC(iv)
154
+ ).decryptor()
155
+ plaintext_padded = decryptor.update(ciphertext)
156
+ try:
157
+ plaintext_padded += decryptor.finalize()
158
+ except ValueError:
159
+ raise InvalidToken
160
+ unpadder = padding.PKCS7(algorithms.AES.block_size).unpadder()
161
+
162
+ unpadded = unpadder.update(plaintext_padded)
163
+ try:
164
+ unpadded += unpadder.finalize()
165
+ except ValueError:
166
+ raise InvalidToken
167
+ return unpadded
168
+
169
+
170
+ class MultiFernet:
171
+ def __init__(self, fernets: typing.Iterable[Fernet]):
172
+ fernets = list(fernets)
173
+ if not fernets:
174
+ raise ValueError(
175
+ "MultiFernet requires at least one Fernet instance"
176
+ )
177
+ self._fernets = fernets
178
+
179
+ def encrypt(self, msg: bytes) -> bytes:
180
+ return self.encrypt_at_time(msg, int(time.time()))
181
+
182
+ def encrypt_at_time(self, msg: bytes, current_time: int) -> bytes:
183
+ return self._fernets[0].encrypt_at_time(msg, current_time)
184
+
185
+ def rotate(self, msg: bytes | str) -> bytes:
186
+ timestamp, data = Fernet._get_unverified_token_data(msg)
187
+ for f in self._fernets:
188
+ try:
189
+ p = f._decrypt_data(data, timestamp, None)
190
+ break
191
+ except InvalidToken:
192
+ pass
193
+ else:
194
+ raise InvalidToken
195
+
196
+ iv = os.urandom(16)
197
+ return self._fernets[0]._encrypt_from_parts(p, timestamp, iv)
198
+
199
+ def decrypt(self, msg: bytes | str, ttl: int | None = None) -> bytes:
200
+ for f in self._fernets:
201
+ try:
202
+ return f.decrypt(msg, ttl)
203
+ except InvalidToken:
204
+ pass
205
+ raise InvalidToken
206
+
207
+ def decrypt_at_time(
208
+ self, msg: bytes | str, ttl: int, current_time: int
209
+ ) -> bytes:
210
+ for f in self._fernets:
211
+ try:
212
+ return f.decrypt_at_time(msg, ttl, current_time)
213
+ except InvalidToken:
214
+ pass
215
+ raise InvalidToken
.venv/lib/python3.11/site-packages/cryptography/hazmat/__init__.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ """
8
+ Hazardous Materials
9
+
10
+ This is a "Hazardous Materials" module. You should ONLY use it if you're
11
+ 100% absolutely sure that you know what you're doing because this module
12
+ is full of land mines, dragons, and dinosaurs with laser guns.
13
+ """
.venv/lib/python3.11/site-packages/cryptography/hazmat/_oid.py ADDED
@@ -0,0 +1,313 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ from cryptography.hazmat.bindings._rust import (
8
+ ObjectIdentifier as ObjectIdentifier,
9
+ )
10
+ from cryptography.hazmat.primitives import hashes
11
+
12
+
13
+ class ExtensionOID:
14
+ SUBJECT_DIRECTORY_ATTRIBUTES = ObjectIdentifier("2.5.29.9")
15
+ SUBJECT_KEY_IDENTIFIER = ObjectIdentifier("2.5.29.14")
16
+ KEY_USAGE = ObjectIdentifier("2.5.29.15")
17
+ SUBJECT_ALTERNATIVE_NAME = ObjectIdentifier("2.5.29.17")
18
+ ISSUER_ALTERNATIVE_NAME = ObjectIdentifier("2.5.29.18")
19
+ BASIC_CONSTRAINTS = ObjectIdentifier("2.5.29.19")
20
+ NAME_CONSTRAINTS = ObjectIdentifier("2.5.29.30")
21
+ CRL_DISTRIBUTION_POINTS = ObjectIdentifier("2.5.29.31")
22
+ CERTIFICATE_POLICIES = ObjectIdentifier("2.5.29.32")
23
+ POLICY_MAPPINGS = ObjectIdentifier("2.5.29.33")
24
+ AUTHORITY_KEY_IDENTIFIER = ObjectIdentifier("2.5.29.35")
25
+ POLICY_CONSTRAINTS = ObjectIdentifier("2.5.29.36")
26
+ EXTENDED_KEY_USAGE = ObjectIdentifier("2.5.29.37")
27
+ FRESHEST_CRL = ObjectIdentifier("2.5.29.46")
28
+ INHIBIT_ANY_POLICY = ObjectIdentifier("2.5.29.54")
29
+ ISSUING_DISTRIBUTION_POINT = ObjectIdentifier("2.5.29.28")
30
+ AUTHORITY_INFORMATION_ACCESS = ObjectIdentifier("1.3.6.1.5.5.7.1.1")
31
+ SUBJECT_INFORMATION_ACCESS = ObjectIdentifier("1.3.6.1.5.5.7.1.11")
32
+ OCSP_NO_CHECK = ObjectIdentifier("1.3.6.1.5.5.7.48.1.5")
33
+ TLS_FEATURE = ObjectIdentifier("1.3.6.1.5.5.7.1.24")
34
+ CRL_NUMBER = ObjectIdentifier("2.5.29.20")
35
+ DELTA_CRL_INDICATOR = ObjectIdentifier("2.5.29.27")
36
+ PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS = ObjectIdentifier(
37
+ "1.3.6.1.4.1.11129.2.4.2"
38
+ )
39
+ PRECERT_POISON = ObjectIdentifier("1.3.6.1.4.1.11129.2.4.3")
40
+ SIGNED_CERTIFICATE_TIMESTAMPS = ObjectIdentifier("1.3.6.1.4.1.11129.2.4.5")
41
+ MS_CERTIFICATE_TEMPLATE = ObjectIdentifier("1.3.6.1.4.1.311.21.7")
42
+
43
+
44
+ class OCSPExtensionOID:
45
+ NONCE = ObjectIdentifier("1.3.6.1.5.5.7.48.1.2")
46
+ ACCEPTABLE_RESPONSES = ObjectIdentifier("1.3.6.1.5.5.7.48.1.4")
47
+
48
+
49
+ class CRLEntryExtensionOID:
50
+ CERTIFICATE_ISSUER = ObjectIdentifier("2.5.29.29")
51
+ CRL_REASON = ObjectIdentifier("2.5.29.21")
52
+ INVALIDITY_DATE = ObjectIdentifier("2.5.29.24")
53
+
54
+
55
+ class NameOID:
56
+ COMMON_NAME = ObjectIdentifier("2.5.4.3")
57
+ COUNTRY_NAME = ObjectIdentifier("2.5.4.6")
58
+ LOCALITY_NAME = ObjectIdentifier("2.5.4.7")
59
+ STATE_OR_PROVINCE_NAME = ObjectIdentifier("2.5.4.8")
60
+ STREET_ADDRESS = ObjectIdentifier("2.5.4.9")
61
+ ORGANIZATION_IDENTIFIER = ObjectIdentifier("2.5.4.97")
62
+ ORGANIZATION_NAME = ObjectIdentifier("2.5.4.10")
63
+ ORGANIZATIONAL_UNIT_NAME = ObjectIdentifier("2.5.4.11")
64
+ SERIAL_NUMBER = ObjectIdentifier("2.5.4.5")
65
+ SURNAME = ObjectIdentifier("2.5.4.4")
66
+ GIVEN_NAME = ObjectIdentifier("2.5.4.42")
67
+ TITLE = ObjectIdentifier("2.5.4.12")
68
+ INITIALS = ObjectIdentifier("2.5.4.43")
69
+ GENERATION_QUALIFIER = ObjectIdentifier("2.5.4.44")
70
+ X500_UNIQUE_IDENTIFIER = ObjectIdentifier("2.5.4.45")
71
+ DN_QUALIFIER = ObjectIdentifier("2.5.4.46")
72
+ PSEUDONYM = ObjectIdentifier("2.5.4.65")
73
+ USER_ID = ObjectIdentifier("0.9.2342.19200300.100.1.1")
74
+ DOMAIN_COMPONENT = ObjectIdentifier("0.9.2342.19200300.100.1.25")
75
+ EMAIL_ADDRESS = ObjectIdentifier("1.2.840.113549.1.9.1")
76
+ JURISDICTION_COUNTRY_NAME = ObjectIdentifier("1.3.6.1.4.1.311.60.2.1.3")
77
+ JURISDICTION_LOCALITY_NAME = ObjectIdentifier("1.3.6.1.4.1.311.60.2.1.1")
78
+ JURISDICTION_STATE_OR_PROVINCE_NAME = ObjectIdentifier(
79
+ "1.3.6.1.4.1.311.60.2.1.2"
80
+ )
81
+ BUSINESS_CATEGORY = ObjectIdentifier("2.5.4.15")
82
+ POSTAL_ADDRESS = ObjectIdentifier("2.5.4.16")
83
+ POSTAL_CODE = ObjectIdentifier("2.5.4.17")
84
+ INN = ObjectIdentifier("1.2.643.3.131.1.1")
85
+ OGRN = ObjectIdentifier("1.2.643.100.1")
86
+ SNILS = ObjectIdentifier("1.2.643.100.3")
87
+ UNSTRUCTURED_NAME = ObjectIdentifier("1.2.840.113549.1.9.2")
88
+
89
+
90
+ class SignatureAlgorithmOID:
91
+ RSA_WITH_MD5 = ObjectIdentifier("1.2.840.113549.1.1.4")
92
+ RSA_WITH_SHA1 = ObjectIdentifier("1.2.840.113549.1.1.5")
93
+ # This is an alternate OID for RSA with SHA1 that is occasionally seen
94
+ _RSA_WITH_SHA1 = ObjectIdentifier("1.3.14.3.2.29")
95
+ RSA_WITH_SHA224 = ObjectIdentifier("1.2.840.113549.1.1.14")
96
+ RSA_WITH_SHA256 = ObjectIdentifier("1.2.840.113549.1.1.11")
97
+ RSA_WITH_SHA384 = ObjectIdentifier("1.2.840.113549.1.1.12")
98
+ RSA_WITH_SHA512 = ObjectIdentifier("1.2.840.113549.1.1.13")
99
+ RSA_WITH_SHA3_224 = ObjectIdentifier("2.16.840.1.101.3.4.3.13")
100
+ RSA_WITH_SHA3_256 = ObjectIdentifier("2.16.840.1.101.3.4.3.14")
101
+ RSA_WITH_SHA3_384 = ObjectIdentifier("2.16.840.1.101.3.4.3.15")
102
+ RSA_WITH_SHA3_512 = ObjectIdentifier("2.16.840.1.101.3.4.3.16")
103
+ RSASSA_PSS = ObjectIdentifier("1.2.840.113549.1.1.10")
104
+ ECDSA_WITH_SHA1 = ObjectIdentifier("1.2.840.10045.4.1")
105
+ ECDSA_WITH_SHA224 = ObjectIdentifier("1.2.840.10045.4.3.1")
106
+ ECDSA_WITH_SHA256 = ObjectIdentifier("1.2.840.10045.4.3.2")
107
+ ECDSA_WITH_SHA384 = ObjectIdentifier("1.2.840.10045.4.3.3")
108
+ ECDSA_WITH_SHA512 = ObjectIdentifier("1.2.840.10045.4.3.4")
109
+ ECDSA_WITH_SHA3_224 = ObjectIdentifier("2.16.840.1.101.3.4.3.9")
110
+ ECDSA_WITH_SHA3_256 = ObjectIdentifier("2.16.840.1.101.3.4.3.10")
111
+ ECDSA_WITH_SHA3_384 = ObjectIdentifier("2.16.840.1.101.3.4.3.11")
112
+ ECDSA_WITH_SHA3_512 = ObjectIdentifier("2.16.840.1.101.3.4.3.12")
113
+ DSA_WITH_SHA1 = ObjectIdentifier("1.2.840.10040.4.3")
114
+ DSA_WITH_SHA224 = ObjectIdentifier("2.16.840.1.101.3.4.3.1")
115
+ DSA_WITH_SHA256 = ObjectIdentifier("2.16.840.1.101.3.4.3.2")
116
+ DSA_WITH_SHA384 = ObjectIdentifier("2.16.840.1.101.3.4.3.3")
117
+ DSA_WITH_SHA512 = ObjectIdentifier("2.16.840.1.101.3.4.3.4")
118
+ ED25519 = ObjectIdentifier("1.3.101.112")
119
+ ED448 = ObjectIdentifier("1.3.101.113")
120
+ GOSTR3411_94_WITH_3410_2001 = ObjectIdentifier("1.2.643.2.2.3")
121
+ GOSTR3410_2012_WITH_3411_2012_256 = ObjectIdentifier("1.2.643.7.1.1.3.2")
122
+ GOSTR3410_2012_WITH_3411_2012_512 = ObjectIdentifier("1.2.643.7.1.1.3.3")
123
+
124
+
125
+ _SIG_OIDS_TO_HASH: dict[ObjectIdentifier, hashes.HashAlgorithm | None] = {
126
+ SignatureAlgorithmOID.RSA_WITH_MD5: hashes.MD5(),
127
+ SignatureAlgorithmOID.RSA_WITH_SHA1: hashes.SHA1(),
128
+ SignatureAlgorithmOID._RSA_WITH_SHA1: hashes.SHA1(),
129
+ SignatureAlgorithmOID.RSA_WITH_SHA224: hashes.SHA224(),
130
+ SignatureAlgorithmOID.RSA_WITH_SHA256: hashes.SHA256(),
131
+ SignatureAlgorithmOID.RSA_WITH_SHA384: hashes.SHA384(),
132
+ SignatureAlgorithmOID.RSA_WITH_SHA512: hashes.SHA512(),
133
+ SignatureAlgorithmOID.RSA_WITH_SHA3_224: hashes.SHA3_224(),
134
+ SignatureAlgorithmOID.RSA_WITH_SHA3_256: hashes.SHA3_256(),
135
+ SignatureAlgorithmOID.RSA_WITH_SHA3_384: hashes.SHA3_384(),
136
+ SignatureAlgorithmOID.RSA_WITH_SHA3_512: hashes.SHA3_512(),
137
+ SignatureAlgorithmOID.ECDSA_WITH_SHA1: hashes.SHA1(),
138
+ SignatureAlgorithmOID.ECDSA_WITH_SHA224: hashes.SHA224(),
139
+ SignatureAlgorithmOID.ECDSA_WITH_SHA256: hashes.SHA256(),
140
+ SignatureAlgorithmOID.ECDSA_WITH_SHA384: hashes.SHA384(),
141
+ SignatureAlgorithmOID.ECDSA_WITH_SHA512: hashes.SHA512(),
142
+ SignatureAlgorithmOID.ECDSA_WITH_SHA3_224: hashes.SHA3_224(),
143
+ SignatureAlgorithmOID.ECDSA_WITH_SHA3_256: hashes.SHA3_256(),
144
+ SignatureAlgorithmOID.ECDSA_WITH_SHA3_384: hashes.SHA3_384(),
145
+ SignatureAlgorithmOID.ECDSA_WITH_SHA3_512: hashes.SHA3_512(),
146
+ SignatureAlgorithmOID.DSA_WITH_SHA1: hashes.SHA1(),
147
+ SignatureAlgorithmOID.DSA_WITH_SHA224: hashes.SHA224(),
148
+ SignatureAlgorithmOID.DSA_WITH_SHA256: hashes.SHA256(),
149
+ SignatureAlgorithmOID.ED25519: None,
150
+ SignatureAlgorithmOID.ED448: None,
151
+ SignatureAlgorithmOID.GOSTR3411_94_WITH_3410_2001: None,
152
+ SignatureAlgorithmOID.GOSTR3410_2012_WITH_3411_2012_256: None,
153
+ SignatureAlgorithmOID.GOSTR3410_2012_WITH_3411_2012_512: None,
154
+ }
155
+
156
+
157
+ class PublicKeyAlgorithmOID:
158
+ DSA = ObjectIdentifier("1.2.840.10040.4.1")
159
+ EC_PUBLIC_KEY = ObjectIdentifier("1.2.840.10045.2.1")
160
+ RSAES_PKCS1_v1_5 = ObjectIdentifier("1.2.840.113549.1.1.1")
161
+ RSASSA_PSS = ObjectIdentifier("1.2.840.113549.1.1.10")
162
+ X25519 = ObjectIdentifier("1.3.101.110")
163
+ X448 = ObjectIdentifier("1.3.101.111")
164
+ ED25519 = ObjectIdentifier("1.3.101.112")
165
+ ED448 = ObjectIdentifier("1.3.101.113")
166
+
167
+
168
+ class ExtendedKeyUsageOID:
169
+ SERVER_AUTH = ObjectIdentifier("1.3.6.1.5.5.7.3.1")
170
+ CLIENT_AUTH = ObjectIdentifier("1.3.6.1.5.5.7.3.2")
171
+ CODE_SIGNING = ObjectIdentifier("1.3.6.1.5.5.7.3.3")
172
+ EMAIL_PROTECTION = ObjectIdentifier("1.3.6.1.5.5.7.3.4")
173
+ TIME_STAMPING = ObjectIdentifier("1.3.6.1.5.5.7.3.8")
174
+ OCSP_SIGNING = ObjectIdentifier("1.3.6.1.5.5.7.3.9")
175
+ ANY_EXTENDED_KEY_USAGE = ObjectIdentifier("2.5.29.37.0")
176
+ SMARTCARD_LOGON = ObjectIdentifier("1.3.6.1.4.1.311.20.2.2")
177
+ KERBEROS_PKINIT_KDC = ObjectIdentifier("1.3.6.1.5.2.3.5")
178
+ IPSEC_IKE = ObjectIdentifier("1.3.6.1.5.5.7.3.17")
179
+ CERTIFICATE_TRANSPARENCY = ObjectIdentifier("1.3.6.1.4.1.11129.2.4.4")
180
+
181
+
182
+ class AuthorityInformationAccessOID:
183
+ CA_ISSUERS = ObjectIdentifier("1.3.6.1.5.5.7.48.2")
184
+ OCSP = ObjectIdentifier("1.3.6.1.5.5.7.48.1")
185
+
186
+
187
+ class SubjectInformationAccessOID:
188
+ CA_REPOSITORY = ObjectIdentifier("1.3.6.1.5.5.7.48.5")
189
+
190
+
191
+ class CertificatePoliciesOID:
192
+ CPS_QUALIFIER = ObjectIdentifier("1.3.6.1.5.5.7.2.1")
193
+ CPS_USER_NOTICE = ObjectIdentifier("1.3.6.1.5.5.7.2.2")
194
+ ANY_POLICY = ObjectIdentifier("2.5.29.32.0")
195
+
196
+
197
+ class AttributeOID:
198
+ CHALLENGE_PASSWORD = ObjectIdentifier("1.2.840.113549.1.9.7")
199
+ UNSTRUCTURED_NAME = ObjectIdentifier("1.2.840.113549.1.9.2")
200
+
201
+
202
+ _OID_NAMES = {
203
+ NameOID.COMMON_NAME: "commonName",
204
+ NameOID.COUNTRY_NAME: "countryName",
205
+ NameOID.LOCALITY_NAME: "localityName",
206
+ NameOID.STATE_OR_PROVINCE_NAME: "stateOrProvinceName",
207
+ NameOID.STREET_ADDRESS: "streetAddress",
208
+ NameOID.ORGANIZATION_NAME: "organizationName",
209
+ NameOID.ORGANIZATIONAL_UNIT_NAME: "organizationalUnitName",
210
+ NameOID.SERIAL_NUMBER: "serialNumber",
211
+ NameOID.SURNAME: "surname",
212
+ NameOID.GIVEN_NAME: "givenName",
213
+ NameOID.TITLE: "title",
214
+ NameOID.GENERATION_QUALIFIER: "generationQualifier",
215
+ NameOID.X500_UNIQUE_IDENTIFIER: "x500UniqueIdentifier",
216
+ NameOID.DN_QUALIFIER: "dnQualifier",
217
+ NameOID.PSEUDONYM: "pseudonym",
218
+ NameOID.USER_ID: "userID",
219
+ NameOID.DOMAIN_COMPONENT: "domainComponent",
220
+ NameOID.EMAIL_ADDRESS: "emailAddress",
221
+ NameOID.JURISDICTION_COUNTRY_NAME: "jurisdictionCountryName",
222
+ NameOID.JURISDICTION_LOCALITY_NAME: "jurisdictionLocalityName",
223
+ NameOID.JURISDICTION_STATE_OR_PROVINCE_NAME: (
224
+ "jurisdictionStateOrProvinceName"
225
+ ),
226
+ NameOID.BUSINESS_CATEGORY: "businessCategory",
227
+ NameOID.POSTAL_ADDRESS: "postalAddress",
228
+ NameOID.POSTAL_CODE: "postalCode",
229
+ NameOID.INN: "INN",
230
+ NameOID.OGRN: "OGRN",
231
+ NameOID.SNILS: "SNILS",
232
+ NameOID.UNSTRUCTURED_NAME: "unstructuredName",
233
+ SignatureAlgorithmOID.RSA_WITH_MD5: "md5WithRSAEncryption",
234
+ SignatureAlgorithmOID.RSA_WITH_SHA1: "sha1WithRSAEncryption",
235
+ SignatureAlgorithmOID.RSA_WITH_SHA224: "sha224WithRSAEncryption",
236
+ SignatureAlgorithmOID.RSA_WITH_SHA256: "sha256WithRSAEncryption",
237
+ SignatureAlgorithmOID.RSA_WITH_SHA384: "sha384WithRSAEncryption",
238
+ SignatureAlgorithmOID.RSA_WITH_SHA512: "sha512WithRSAEncryption",
239
+ SignatureAlgorithmOID.RSASSA_PSS: "RSASSA-PSS",
240
+ SignatureAlgorithmOID.ECDSA_WITH_SHA1: "ecdsa-with-SHA1",
241
+ SignatureAlgorithmOID.ECDSA_WITH_SHA224: "ecdsa-with-SHA224",
242
+ SignatureAlgorithmOID.ECDSA_WITH_SHA256: "ecdsa-with-SHA256",
243
+ SignatureAlgorithmOID.ECDSA_WITH_SHA384: "ecdsa-with-SHA384",
244
+ SignatureAlgorithmOID.ECDSA_WITH_SHA512: "ecdsa-with-SHA512",
245
+ SignatureAlgorithmOID.DSA_WITH_SHA1: "dsa-with-sha1",
246
+ SignatureAlgorithmOID.DSA_WITH_SHA224: "dsa-with-sha224",
247
+ SignatureAlgorithmOID.DSA_WITH_SHA256: "dsa-with-sha256",
248
+ SignatureAlgorithmOID.ED25519: "ed25519",
249
+ SignatureAlgorithmOID.ED448: "ed448",
250
+ SignatureAlgorithmOID.GOSTR3411_94_WITH_3410_2001: (
251
+ "GOST R 34.11-94 with GOST R 34.10-2001"
252
+ ),
253
+ SignatureAlgorithmOID.GOSTR3410_2012_WITH_3411_2012_256: (
254
+ "GOST R 34.10-2012 with GOST R 34.11-2012 (256 bit)"
255
+ ),
256
+ SignatureAlgorithmOID.GOSTR3410_2012_WITH_3411_2012_512: (
257
+ "GOST R 34.10-2012 with GOST R 34.11-2012 (512 bit)"
258
+ ),
259
+ PublicKeyAlgorithmOID.DSA: "dsaEncryption",
260
+ PublicKeyAlgorithmOID.EC_PUBLIC_KEY: "id-ecPublicKey",
261
+ PublicKeyAlgorithmOID.RSAES_PKCS1_v1_5: "rsaEncryption",
262
+ PublicKeyAlgorithmOID.RSASSA_PSS: "rsassaPss",
263
+ PublicKeyAlgorithmOID.X25519: "X25519",
264
+ PublicKeyAlgorithmOID.X448: "X448",
265
+ ExtendedKeyUsageOID.SERVER_AUTH: "serverAuth",
266
+ ExtendedKeyUsageOID.CLIENT_AUTH: "clientAuth",
267
+ ExtendedKeyUsageOID.CODE_SIGNING: "codeSigning",
268
+ ExtendedKeyUsageOID.EMAIL_PROTECTION: "emailProtection",
269
+ ExtendedKeyUsageOID.TIME_STAMPING: "timeStamping",
270
+ ExtendedKeyUsageOID.OCSP_SIGNING: "OCSPSigning",
271
+ ExtendedKeyUsageOID.SMARTCARD_LOGON: "msSmartcardLogin",
272
+ ExtendedKeyUsageOID.KERBEROS_PKINIT_KDC: "pkInitKDC",
273
+ ExtensionOID.SUBJECT_DIRECTORY_ATTRIBUTES: "subjectDirectoryAttributes",
274
+ ExtensionOID.SUBJECT_KEY_IDENTIFIER: "subjectKeyIdentifier",
275
+ ExtensionOID.KEY_USAGE: "keyUsage",
276
+ ExtensionOID.SUBJECT_ALTERNATIVE_NAME: "subjectAltName",
277
+ ExtensionOID.ISSUER_ALTERNATIVE_NAME: "issuerAltName",
278
+ ExtensionOID.BASIC_CONSTRAINTS: "basicConstraints",
279
+ ExtensionOID.PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS: (
280
+ "signedCertificateTimestampList"
281
+ ),
282
+ ExtensionOID.SIGNED_CERTIFICATE_TIMESTAMPS: (
283
+ "signedCertificateTimestampList"
284
+ ),
285
+ ExtensionOID.PRECERT_POISON: "ctPoison",
286
+ ExtensionOID.MS_CERTIFICATE_TEMPLATE: "msCertificateTemplate",
287
+ CRLEntryExtensionOID.CRL_REASON: "cRLReason",
288
+ CRLEntryExtensionOID.INVALIDITY_DATE: "invalidityDate",
289
+ CRLEntryExtensionOID.CERTIFICATE_ISSUER: "certificateIssuer",
290
+ ExtensionOID.NAME_CONSTRAINTS: "nameConstraints",
291
+ ExtensionOID.CRL_DISTRIBUTION_POINTS: "cRLDistributionPoints",
292
+ ExtensionOID.CERTIFICATE_POLICIES: "certificatePolicies",
293
+ ExtensionOID.POLICY_MAPPINGS: "policyMappings",
294
+ ExtensionOID.AUTHORITY_KEY_IDENTIFIER: "authorityKeyIdentifier",
295
+ ExtensionOID.POLICY_CONSTRAINTS: "policyConstraints",
296
+ ExtensionOID.EXTENDED_KEY_USAGE: "extendedKeyUsage",
297
+ ExtensionOID.FRESHEST_CRL: "freshestCRL",
298
+ ExtensionOID.INHIBIT_ANY_POLICY: "inhibitAnyPolicy",
299
+ ExtensionOID.ISSUING_DISTRIBUTION_POINT: "issuingDistributionPoint",
300
+ ExtensionOID.AUTHORITY_INFORMATION_ACCESS: "authorityInfoAccess",
301
+ ExtensionOID.SUBJECT_INFORMATION_ACCESS: "subjectInfoAccess",
302
+ ExtensionOID.OCSP_NO_CHECK: "OCSPNoCheck",
303
+ ExtensionOID.CRL_NUMBER: "cRLNumber",
304
+ ExtensionOID.DELTA_CRL_INDICATOR: "deltaCRLIndicator",
305
+ ExtensionOID.TLS_FEATURE: "TLSFeature",
306
+ AuthorityInformationAccessOID.OCSP: "OCSP",
307
+ AuthorityInformationAccessOID.CA_ISSUERS: "caIssuers",
308
+ SubjectInformationAccessOID.CA_REPOSITORY: "caRepository",
309
+ CertificatePoliciesOID.CPS_QUALIFIER: "id-qt-cps",
310
+ CertificatePoliciesOID.CPS_USER_NOTICE: "id-qt-unotice",
311
+ OCSPExtensionOID.NONCE: "OCSPNonce",
312
+ AttributeOID.CHALLENGE_PASSWORD: "challengePassword",
313
+ }
.venv/lib/python3.11/site-packages/cryptography/hazmat/backends/__init__.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ from typing import Any
8
+
9
+
10
+ def default_backend() -> Any:
11
+ from cryptography.hazmat.backends.openssl.backend import backend
12
+
13
+ return backend
.venv/lib/python3.11/site-packages/cryptography/hazmat/backends/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (568 Bytes). View file
 
.venv/lib/python3.11/site-packages/cryptography/hazmat/backends/openssl/__init__.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ from cryptography.hazmat.backends.openssl.backend import backend
8
+
9
+ __all__ = ["backend"]
.venv/lib/python3.11/site-packages/cryptography/hazmat/backends/openssl/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (388 Bytes). View file
 
.venv/lib/python3.11/site-packages/cryptography/hazmat/backends/openssl/__pycache__/backend.cpython-311.pyc ADDED
Binary file (13.7 kB). View file
 
.venv/lib/python3.11/site-packages/cryptography/hazmat/backends/openssl/backend.py ADDED
@@ -0,0 +1,291 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ from cryptography.hazmat.bindings._rust import openssl as rust_openssl
8
+ from cryptography.hazmat.bindings.openssl import binding
9
+ from cryptography.hazmat.primitives import hashes
10
+ from cryptography.hazmat.primitives._asymmetric import AsymmetricPadding
11
+ from cryptography.hazmat.primitives.asymmetric import ec
12
+ from cryptography.hazmat.primitives.asymmetric import utils as asym_utils
13
+ from cryptography.hazmat.primitives.asymmetric.padding import (
14
+ MGF1,
15
+ OAEP,
16
+ PSS,
17
+ PKCS1v15,
18
+ )
19
+ from cryptography.hazmat.primitives.ciphers import (
20
+ CipherAlgorithm,
21
+ )
22
+ from cryptography.hazmat.primitives.ciphers.algorithms import (
23
+ AES,
24
+ )
25
+ from cryptography.hazmat.primitives.ciphers.modes import (
26
+ CBC,
27
+ Mode,
28
+ )
29
+
30
+
31
+ class Backend:
32
+ """
33
+ OpenSSL API binding interfaces.
34
+ """
35
+
36
+ name = "openssl"
37
+
38
+ # TripleDES encryption is disallowed/deprecated throughout 2023 in
39
+ # FIPS 140-3. To keep it simple we denylist any use of TripleDES (TDEA).
40
+ _fips_ciphers = (AES,)
41
+ # Sometimes SHA1 is still permissible. That logic is contained
42
+ # within the various *_supported methods.
43
+ _fips_hashes = (
44
+ hashes.SHA224,
45
+ hashes.SHA256,
46
+ hashes.SHA384,
47
+ hashes.SHA512,
48
+ hashes.SHA512_224,
49
+ hashes.SHA512_256,
50
+ hashes.SHA3_224,
51
+ hashes.SHA3_256,
52
+ hashes.SHA3_384,
53
+ hashes.SHA3_512,
54
+ hashes.SHAKE128,
55
+ hashes.SHAKE256,
56
+ )
57
+ _fips_ecdh_curves = (
58
+ ec.SECP224R1,
59
+ ec.SECP256R1,
60
+ ec.SECP384R1,
61
+ ec.SECP521R1,
62
+ )
63
+ _fips_rsa_min_key_size = 2048
64
+ _fips_rsa_min_public_exponent = 65537
65
+ _fips_dsa_min_modulus = 1 << 2048
66
+ _fips_dh_min_key_size = 2048
67
+ _fips_dh_min_modulus = 1 << _fips_dh_min_key_size
68
+
69
+ def __init__(self) -> None:
70
+ self._binding = binding.Binding()
71
+ self._ffi = self._binding.ffi
72
+ self._lib = self._binding.lib
73
+ self._fips_enabled = rust_openssl.is_fips_enabled()
74
+
75
+ def __repr__(self) -> str:
76
+ return (
77
+ f"<OpenSSLBackend(version: {self.openssl_version_text()}, "
78
+ f"FIPS: {self._fips_enabled}, "
79
+ f"Legacy: {rust_openssl._legacy_provider_loaded})>"
80
+ )
81
+
82
+ def openssl_assert(self, ok: bool) -> None:
83
+ return binding._openssl_assert(ok)
84
+
85
+ def _enable_fips(self) -> None:
86
+ # This function enables FIPS mode for OpenSSL 3.0.0 on installs that
87
+ # have the FIPS provider installed properly.
88
+ rust_openssl.enable_fips(rust_openssl._providers)
89
+ assert rust_openssl.is_fips_enabled()
90
+ self._fips_enabled = rust_openssl.is_fips_enabled()
91
+
92
+ def openssl_version_text(self) -> str:
93
+ """
94
+ Friendly string name of the loaded OpenSSL library. This is not
95
+ necessarily the same version as it was compiled against.
96
+
97
+ Example: OpenSSL 3.2.1 30 Jan 2024
98
+ """
99
+ return rust_openssl.openssl_version_text()
100
+
101
+ def openssl_version_number(self) -> int:
102
+ return rust_openssl.openssl_version()
103
+
104
+ def _evp_md_from_algorithm(self, algorithm: hashes.HashAlgorithm):
105
+ if algorithm.name in ("blake2b", "blake2s"):
106
+ alg = f"{algorithm.name}{algorithm.digest_size * 8}".encode(
107
+ "ascii"
108
+ )
109
+ else:
110
+ alg = algorithm.name.encode("ascii")
111
+
112
+ evp_md = self._lib.EVP_get_digestbyname(alg)
113
+ return evp_md
114
+
115
+ def hash_supported(self, algorithm: hashes.HashAlgorithm) -> bool:
116
+ if self._fips_enabled and not isinstance(algorithm, self._fips_hashes):
117
+ return False
118
+
119
+ evp_md = self._evp_md_from_algorithm(algorithm)
120
+ return evp_md != self._ffi.NULL
121
+
122
+ def signature_hash_supported(
123
+ self, algorithm: hashes.HashAlgorithm
124
+ ) -> bool:
125
+ # Dedicated check for hashing algorithm use in message digest for
126
+ # signatures, e.g. RSA PKCS#1 v1.5 SHA1 (sha1WithRSAEncryption).
127
+ if self._fips_enabled and isinstance(algorithm, hashes.SHA1):
128
+ return False
129
+ return self.hash_supported(algorithm)
130
+
131
+ def scrypt_supported(self) -> bool:
132
+ if self._fips_enabled:
133
+ return False
134
+ else:
135
+ return hasattr(rust_openssl.kdf, "derive_scrypt")
136
+
137
+ def hmac_supported(self, algorithm: hashes.HashAlgorithm) -> bool:
138
+ # FIPS mode still allows SHA1 for HMAC
139
+ if self._fips_enabled and isinstance(algorithm, hashes.SHA1):
140
+ return True
141
+
142
+ return self.hash_supported(algorithm)
143
+
144
+ def cipher_supported(self, cipher: CipherAlgorithm, mode: Mode) -> bool:
145
+ if self._fips_enabled:
146
+ # FIPS mode requires AES. TripleDES is disallowed/deprecated in
147
+ # FIPS 140-3.
148
+ if not isinstance(cipher, self._fips_ciphers):
149
+ return False
150
+
151
+ return rust_openssl.ciphers.cipher_supported(cipher, mode)
152
+
153
+ def pbkdf2_hmac_supported(self, algorithm: hashes.HashAlgorithm) -> bool:
154
+ return self.hmac_supported(algorithm)
155
+
156
+ def _consume_errors(self) -> list[rust_openssl.OpenSSLError]:
157
+ return rust_openssl.capture_error_stack()
158
+
159
+ def _oaep_hash_supported(self, algorithm: hashes.HashAlgorithm) -> bool:
160
+ if self._fips_enabled and isinstance(algorithm, hashes.SHA1):
161
+ return False
162
+
163
+ return isinstance(
164
+ algorithm,
165
+ (
166
+ hashes.SHA1,
167
+ hashes.SHA224,
168
+ hashes.SHA256,
169
+ hashes.SHA384,
170
+ hashes.SHA512,
171
+ ),
172
+ )
173
+
174
+ def rsa_padding_supported(self, padding: AsymmetricPadding) -> bool:
175
+ if isinstance(padding, PKCS1v15):
176
+ return True
177
+ elif isinstance(padding, PSS) and isinstance(padding._mgf, MGF1):
178
+ # SHA1 is permissible in MGF1 in FIPS even when SHA1 is blocked
179
+ # as signature algorithm.
180
+ if self._fips_enabled and isinstance(
181
+ padding._mgf._algorithm, hashes.SHA1
182
+ ):
183
+ return True
184
+ else:
185
+ return self.hash_supported(padding._mgf._algorithm)
186
+ elif isinstance(padding, OAEP) and isinstance(padding._mgf, MGF1):
187
+ return self._oaep_hash_supported(
188
+ padding._mgf._algorithm
189
+ ) and self._oaep_hash_supported(padding._algorithm)
190
+ else:
191
+ return False
192
+
193
+ def rsa_encryption_supported(self, padding: AsymmetricPadding) -> bool:
194
+ if self._fips_enabled and isinstance(padding, PKCS1v15):
195
+ return False
196
+ else:
197
+ return self.rsa_padding_supported(padding)
198
+
199
+ def dsa_supported(self) -> bool:
200
+ return (
201
+ not rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL
202
+ and not self._fips_enabled
203
+ )
204
+
205
+ def dsa_hash_supported(self, algorithm: hashes.HashAlgorithm) -> bool:
206
+ if not self.dsa_supported():
207
+ return False
208
+ return self.signature_hash_supported(algorithm)
209
+
210
+ def cmac_algorithm_supported(self, algorithm) -> bool:
211
+ return self.cipher_supported(
212
+ algorithm, CBC(b"\x00" * algorithm.block_size)
213
+ )
214
+
215
+ def elliptic_curve_supported(self, curve: ec.EllipticCurve) -> bool:
216
+ if self._fips_enabled and not isinstance(
217
+ curve, self._fips_ecdh_curves
218
+ ):
219
+ return False
220
+
221
+ return rust_openssl.ec.curve_supported(curve)
222
+
223
+ def elliptic_curve_signature_algorithm_supported(
224
+ self,
225
+ signature_algorithm: ec.EllipticCurveSignatureAlgorithm,
226
+ curve: ec.EllipticCurve,
227
+ ) -> bool:
228
+ # We only support ECDSA right now.
229
+ if not isinstance(signature_algorithm, ec.ECDSA):
230
+ return False
231
+
232
+ return self.elliptic_curve_supported(curve) and (
233
+ isinstance(signature_algorithm.algorithm, asym_utils.Prehashed)
234
+ or self.hash_supported(signature_algorithm.algorithm)
235
+ )
236
+
237
+ def elliptic_curve_exchange_algorithm_supported(
238
+ self, algorithm: ec.ECDH, curve: ec.EllipticCurve
239
+ ) -> bool:
240
+ return self.elliptic_curve_supported(curve) and isinstance(
241
+ algorithm, ec.ECDH
242
+ )
243
+
244
+ def dh_supported(self) -> bool:
245
+ return not rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL
246
+
247
+ def dh_x942_serialization_supported(self) -> bool:
248
+ return self._lib.Cryptography_HAS_EVP_PKEY_DHX == 1
249
+
250
+ def x25519_supported(self) -> bool:
251
+ if self._fips_enabled:
252
+ return False
253
+ return True
254
+
255
+ def x448_supported(self) -> bool:
256
+ if self._fips_enabled:
257
+ return False
258
+ return (
259
+ not rust_openssl.CRYPTOGRAPHY_IS_LIBRESSL
260
+ and not rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL
261
+ )
262
+
263
+ def ed25519_supported(self) -> bool:
264
+ if self._fips_enabled:
265
+ return False
266
+ return True
267
+
268
+ def ed448_supported(self) -> bool:
269
+ if self._fips_enabled:
270
+ return False
271
+ return (
272
+ not rust_openssl.CRYPTOGRAPHY_IS_LIBRESSL
273
+ and not rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL
274
+ )
275
+
276
+ def ecdsa_deterministic_supported(self) -> bool:
277
+ return (
278
+ rust_openssl.CRYPTOGRAPHY_OPENSSL_320_OR_GREATER
279
+ and not self._fips_enabled
280
+ )
281
+
282
+ def poly1305_supported(self) -> bool:
283
+ if self._fips_enabled:
284
+ return False
285
+ return True
286
+
287
+ def pkcs7_supported(self) -> bool:
288
+ return not rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL
289
+
290
+
291
+ backend = Backend()
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/__init__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/_asymmetric.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import abc
8
+
9
+ # This exists to break an import cycle. It is normally accessible from the
10
+ # asymmetric padding module.
11
+
12
+
13
+ class AsymmetricPadding(metaclass=abc.ABCMeta):
14
+ @property
15
+ @abc.abstractmethod
16
+ def name(self) -> str:
17
+ """
18
+ A string naming this padding (e.g. "PSS", "PKCS1").
19
+ """
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/_cipheralgorithm.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import abc
8
+
9
+ from cryptography import utils
10
+
11
+ # This exists to break an import cycle. It is normally accessible from the
12
+ # ciphers module.
13
+
14
+
15
+ class CipherAlgorithm(metaclass=abc.ABCMeta):
16
+ @property
17
+ @abc.abstractmethod
18
+ def name(self) -> str:
19
+ """
20
+ A string naming this mode (e.g. "AES", "Camellia").
21
+ """
22
+
23
+ @property
24
+ @abc.abstractmethod
25
+ def key_sizes(self) -> frozenset[int]:
26
+ """
27
+ Valid key sizes for this algorithm in bits
28
+ """
29
+
30
+ @property
31
+ @abc.abstractmethod
32
+ def key_size(self) -> int:
33
+ """
34
+ The size of the key being used as an integer in bits (e.g. 128, 256).
35
+ """
36
+
37
+
38
+ class BlockCipherAlgorithm(CipherAlgorithm):
39
+ key: bytes
40
+
41
+ @property
42
+ @abc.abstractmethod
43
+ def block_size(self) -> int:
44
+ """
45
+ The size of a block as an integer in bits (e.g. 64, 128).
46
+ """
47
+
48
+
49
+ def _verify_key_size(algorithm: CipherAlgorithm, key: bytes) -> bytes:
50
+ # Verify that the key is instance of bytes
51
+ utils._check_byteslike("key", key)
52
+
53
+ # Verify that the key size matches the expected key size
54
+ if len(key) * 8 not in algorithm.key_sizes:
55
+ raise ValueError(
56
+ f"Invalid key size ({len(key) * 8}) for {algorithm.name}."
57
+ )
58
+ return key
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/_serialization.py ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import abc
8
+
9
+ from cryptography import utils
10
+ from cryptography.hazmat.primitives.hashes import HashAlgorithm
11
+
12
+ # This exists to break an import cycle. These classes are normally accessible
13
+ # from the serialization module.
14
+
15
+
16
+ class PBES(utils.Enum):
17
+ PBESv1SHA1And3KeyTripleDESCBC = "PBESv1 using SHA1 and 3-Key TripleDES"
18
+ PBESv2SHA256AndAES256CBC = "PBESv2 using SHA256 PBKDF2 and AES256 CBC"
19
+
20
+
21
+ class Encoding(utils.Enum):
22
+ PEM = "PEM"
23
+ DER = "DER"
24
+ OpenSSH = "OpenSSH"
25
+ Raw = "Raw"
26
+ X962 = "ANSI X9.62"
27
+ SMIME = "S/MIME"
28
+
29
+
30
+ class PrivateFormat(utils.Enum):
31
+ PKCS8 = "PKCS8"
32
+ TraditionalOpenSSL = "TraditionalOpenSSL"
33
+ Raw = "Raw"
34
+ OpenSSH = "OpenSSH"
35
+ PKCS12 = "PKCS12"
36
+
37
+ def encryption_builder(self) -> KeySerializationEncryptionBuilder:
38
+ if self not in (PrivateFormat.OpenSSH, PrivateFormat.PKCS12):
39
+ raise ValueError(
40
+ "encryption_builder only supported with PrivateFormat.OpenSSH"
41
+ " and PrivateFormat.PKCS12"
42
+ )
43
+ return KeySerializationEncryptionBuilder(self)
44
+
45
+
46
+ class PublicFormat(utils.Enum):
47
+ SubjectPublicKeyInfo = "X.509 subjectPublicKeyInfo with PKCS#1"
48
+ PKCS1 = "Raw PKCS#1"
49
+ OpenSSH = "OpenSSH"
50
+ Raw = "Raw"
51
+ CompressedPoint = "X9.62 Compressed Point"
52
+ UncompressedPoint = "X9.62 Uncompressed Point"
53
+
54
+
55
+ class ParameterFormat(utils.Enum):
56
+ PKCS3 = "PKCS3"
57
+
58
+
59
+ class KeySerializationEncryption(metaclass=abc.ABCMeta):
60
+ pass
61
+
62
+
63
+ class BestAvailableEncryption(KeySerializationEncryption):
64
+ def __init__(self, password: bytes):
65
+ if not isinstance(password, bytes) or len(password) == 0:
66
+ raise ValueError("Password must be 1 or more bytes.")
67
+
68
+ self.password = password
69
+
70
+
71
+ class NoEncryption(KeySerializationEncryption):
72
+ pass
73
+
74
+
75
+ class KeySerializationEncryptionBuilder:
76
+ def __init__(
77
+ self,
78
+ format: PrivateFormat,
79
+ *,
80
+ _kdf_rounds: int | None = None,
81
+ _hmac_hash: HashAlgorithm | None = None,
82
+ _key_cert_algorithm: PBES | None = None,
83
+ ) -> None:
84
+ self._format = format
85
+
86
+ self._kdf_rounds = _kdf_rounds
87
+ self._hmac_hash = _hmac_hash
88
+ self._key_cert_algorithm = _key_cert_algorithm
89
+
90
+ def kdf_rounds(self, rounds: int) -> KeySerializationEncryptionBuilder:
91
+ if self._kdf_rounds is not None:
92
+ raise ValueError("kdf_rounds already set")
93
+
94
+ if not isinstance(rounds, int):
95
+ raise TypeError("kdf_rounds must be an integer")
96
+
97
+ if rounds < 1:
98
+ raise ValueError("kdf_rounds must be a positive integer")
99
+
100
+ return KeySerializationEncryptionBuilder(
101
+ self._format,
102
+ _kdf_rounds=rounds,
103
+ _hmac_hash=self._hmac_hash,
104
+ _key_cert_algorithm=self._key_cert_algorithm,
105
+ )
106
+
107
+ def hmac_hash(
108
+ self, algorithm: HashAlgorithm
109
+ ) -> KeySerializationEncryptionBuilder:
110
+ if self._format is not PrivateFormat.PKCS12:
111
+ raise TypeError(
112
+ "hmac_hash only supported with PrivateFormat.PKCS12"
113
+ )
114
+
115
+ if self._hmac_hash is not None:
116
+ raise ValueError("hmac_hash already set")
117
+ return KeySerializationEncryptionBuilder(
118
+ self._format,
119
+ _kdf_rounds=self._kdf_rounds,
120
+ _hmac_hash=algorithm,
121
+ _key_cert_algorithm=self._key_cert_algorithm,
122
+ )
123
+
124
+ def key_cert_algorithm(
125
+ self, algorithm: PBES
126
+ ) -> KeySerializationEncryptionBuilder:
127
+ if self._format is not PrivateFormat.PKCS12:
128
+ raise TypeError(
129
+ "key_cert_algorithm only supported with "
130
+ "PrivateFormat.PKCS12"
131
+ )
132
+ if self._key_cert_algorithm is not None:
133
+ raise ValueError("key_cert_algorithm already set")
134
+ return KeySerializationEncryptionBuilder(
135
+ self._format,
136
+ _kdf_rounds=self._kdf_rounds,
137
+ _hmac_hash=self._hmac_hash,
138
+ _key_cert_algorithm=algorithm,
139
+ )
140
+
141
+ def build(self, password: bytes) -> KeySerializationEncryption:
142
+ if not isinstance(password, bytes) or len(password) == 0:
143
+ raise ValueError("Password must be 1 or more bytes.")
144
+
145
+ return _KeySerializationEncryption(
146
+ self._format,
147
+ password,
148
+ kdf_rounds=self._kdf_rounds,
149
+ hmac_hash=self._hmac_hash,
150
+ key_cert_algorithm=self._key_cert_algorithm,
151
+ )
152
+
153
+
154
+ class _KeySerializationEncryption(KeySerializationEncryption):
155
+ def __init__(
156
+ self,
157
+ format: PrivateFormat,
158
+ password: bytes,
159
+ *,
160
+ kdf_rounds: int | None,
161
+ hmac_hash: HashAlgorithm | None,
162
+ key_cert_algorithm: PBES | None,
163
+ ):
164
+ self._format = format
165
+ self.password = password
166
+
167
+ self._kdf_rounds = kdf_rounds
168
+ self._hmac_hash = hmac_hash
169
+ self._key_cert_algorithm = key_cert_algorithm
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__init__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (214 Bytes). View file
 
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/dh.cpython-311.pyc ADDED
Binary file (5.92 kB). View file
 
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/dsa.cpython-311.pyc ADDED
Binary file (6.75 kB). View file
 
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/ec.cpython-311.pyc ADDED
Binary file (17.6 kB). View file
 
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/ed25519.cpython-311.pyc ADDED
Binary file (5.55 kB). View file
 
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/ed448.cpython-311.pyc ADDED
Binary file (5.64 kB). View file
 
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/padding.cpython-311.pyc ADDED
Binary file (5.59 kB). View file
 
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/rsa.cpython-311.pyc ADDED
Binary file (9.96 kB). View file
 
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/types.cpython-311.pyc ADDED
Binary file (2.8 kB). View file
 
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/utils.cpython-311.pyc ADDED
Binary file (1.46 kB). View file
 
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/x25519.cpython-311.pyc ADDED
Binary file (5.34 kB). View file
 
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/__pycache__/x448.cpython-311.pyc ADDED
Binary file (5.42 kB). View file
 
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/dh.py ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import abc
8
+
9
+ from cryptography.hazmat.bindings._rust import openssl as rust_openssl
10
+ from cryptography.hazmat.primitives import _serialization
11
+
12
+ generate_parameters = rust_openssl.dh.generate_parameters
13
+
14
+
15
+ DHPrivateNumbers = rust_openssl.dh.DHPrivateNumbers
16
+ DHPublicNumbers = rust_openssl.dh.DHPublicNumbers
17
+ DHParameterNumbers = rust_openssl.dh.DHParameterNumbers
18
+
19
+
20
+ class DHParameters(metaclass=abc.ABCMeta):
21
+ @abc.abstractmethod
22
+ def generate_private_key(self) -> DHPrivateKey:
23
+ """
24
+ Generates and returns a DHPrivateKey.
25
+ """
26
+
27
+ @abc.abstractmethod
28
+ def parameter_bytes(
29
+ self,
30
+ encoding: _serialization.Encoding,
31
+ format: _serialization.ParameterFormat,
32
+ ) -> bytes:
33
+ """
34
+ Returns the parameters serialized as bytes.
35
+ """
36
+
37
+ @abc.abstractmethod
38
+ def parameter_numbers(self) -> DHParameterNumbers:
39
+ """
40
+ Returns a DHParameterNumbers.
41
+ """
42
+
43
+
44
+ DHParametersWithSerialization = DHParameters
45
+ DHParameters.register(rust_openssl.dh.DHParameters)
46
+
47
+
48
+ class DHPublicKey(metaclass=abc.ABCMeta):
49
+ @property
50
+ @abc.abstractmethod
51
+ def key_size(self) -> int:
52
+ """
53
+ The bit length of the prime modulus.
54
+ """
55
+
56
+ @abc.abstractmethod
57
+ def parameters(self) -> DHParameters:
58
+ """
59
+ The DHParameters object associated with this public key.
60
+ """
61
+
62
+ @abc.abstractmethod
63
+ def public_numbers(self) -> DHPublicNumbers:
64
+ """
65
+ Returns a DHPublicNumbers.
66
+ """
67
+
68
+ @abc.abstractmethod
69
+ def public_bytes(
70
+ self,
71
+ encoding: _serialization.Encoding,
72
+ format: _serialization.PublicFormat,
73
+ ) -> bytes:
74
+ """
75
+ Returns the key serialized as bytes.
76
+ """
77
+
78
+ @abc.abstractmethod
79
+ def __eq__(self, other: object) -> bool:
80
+ """
81
+ Checks equality.
82
+ """
83
+
84
+
85
+ DHPublicKeyWithSerialization = DHPublicKey
86
+ DHPublicKey.register(rust_openssl.dh.DHPublicKey)
87
+
88
+
89
+ class DHPrivateKey(metaclass=abc.ABCMeta):
90
+ @property
91
+ @abc.abstractmethod
92
+ def key_size(self) -> int:
93
+ """
94
+ The bit length of the prime modulus.
95
+ """
96
+
97
+ @abc.abstractmethod
98
+ def public_key(self) -> DHPublicKey:
99
+ """
100
+ The DHPublicKey associated with this private key.
101
+ """
102
+
103
+ @abc.abstractmethod
104
+ def parameters(self) -> DHParameters:
105
+ """
106
+ The DHParameters object associated with this private key.
107
+ """
108
+
109
+ @abc.abstractmethod
110
+ def exchange(self, peer_public_key: DHPublicKey) -> bytes:
111
+ """
112
+ Given peer's DHPublicKey, carry out the key exchange and
113
+ return shared key as bytes.
114
+ """
115
+
116
+ @abc.abstractmethod
117
+ def private_numbers(self) -> DHPrivateNumbers:
118
+ """
119
+ Returns a DHPrivateNumbers.
120
+ """
121
+
122
+ @abc.abstractmethod
123
+ def private_bytes(
124
+ self,
125
+ encoding: _serialization.Encoding,
126
+ format: _serialization.PrivateFormat,
127
+ encryption_algorithm: _serialization.KeySerializationEncryption,
128
+ ) -> bytes:
129
+ """
130
+ Returns the key serialized as bytes.
131
+ """
132
+
133
+
134
+ DHPrivateKeyWithSerialization = DHPrivateKey
135
+ DHPrivateKey.register(rust_openssl.dh.DHPrivateKey)
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import abc
8
+ import typing
9
+
10
+ from cryptography.hazmat.bindings._rust import openssl as rust_openssl
11
+ from cryptography.hazmat.primitives import _serialization, hashes
12
+ from cryptography.hazmat.primitives.asymmetric import utils as asym_utils
13
+
14
+
15
+ class DSAParameters(metaclass=abc.ABCMeta):
16
+ @abc.abstractmethod
17
+ def generate_private_key(self) -> DSAPrivateKey:
18
+ """
19
+ Generates and returns a DSAPrivateKey.
20
+ """
21
+
22
+ @abc.abstractmethod
23
+ def parameter_numbers(self) -> DSAParameterNumbers:
24
+ """
25
+ Returns a DSAParameterNumbers.
26
+ """
27
+
28
+
29
+ DSAParametersWithNumbers = DSAParameters
30
+ DSAParameters.register(rust_openssl.dsa.DSAParameters)
31
+
32
+
33
+ class DSAPrivateKey(metaclass=abc.ABCMeta):
34
+ @property
35
+ @abc.abstractmethod
36
+ def key_size(self) -> int:
37
+ """
38
+ The bit length of the prime modulus.
39
+ """
40
+
41
+ @abc.abstractmethod
42
+ def public_key(self) -> DSAPublicKey:
43
+ """
44
+ The DSAPublicKey associated with this private key.
45
+ """
46
+
47
+ @abc.abstractmethod
48
+ def parameters(self) -> DSAParameters:
49
+ """
50
+ The DSAParameters object associated with this private key.
51
+ """
52
+
53
+ @abc.abstractmethod
54
+ def sign(
55
+ self,
56
+ data: bytes,
57
+ algorithm: asym_utils.Prehashed | hashes.HashAlgorithm,
58
+ ) -> bytes:
59
+ """
60
+ Signs the data
61
+ """
62
+
63
+ @abc.abstractmethod
64
+ def private_numbers(self) -> DSAPrivateNumbers:
65
+ """
66
+ Returns a DSAPrivateNumbers.
67
+ """
68
+
69
+ @abc.abstractmethod
70
+ def private_bytes(
71
+ self,
72
+ encoding: _serialization.Encoding,
73
+ format: _serialization.PrivateFormat,
74
+ encryption_algorithm: _serialization.KeySerializationEncryption,
75
+ ) -> bytes:
76
+ """
77
+ Returns the key serialized as bytes.
78
+ """
79
+
80
+
81
+ DSAPrivateKeyWithSerialization = DSAPrivateKey
82
+ DSAPrivateKey.register(rust_openssl.dsa.DSAPrivateKey)
83
+
84
+
85
+ class DSAPublicKey(metaclass=abc.ABCMeta):
86
+ @property
87
+ @abc.abstractmethod
88
+ def key_size(self) -> int:
89
+ """
90
+ The bit length of the prime modulus.
91
+ """
92
+
93
+ @abc.abstractmethod
94
+ def parameters(self) -> DSAParameters:
95
+ """
96
+ The DSAParameters object associated with this public key.
97
+ """
98
+
99
+ @abc.abstractmethod
100
+ def public_numbers(self) -> DSAPublicNumbers:
101
+ """
102
+ Returns a DSAPublicNumbers.
103
+ """
104
+
105
+ @abc.abstractmethod
106
+ def public_bytes(
107
+ self,
108
+ encoding: _serialization.Encoding,
109
+ format: _serialization.PublicFormat,
110
+ ) -> bytes:
111
+ """
112
+ Returns the key serialized as bytes.
113
+ """
114
+
115
+ @abc.abstractmethod
116
+ def verify(
117
+ self,
118
+ signature: bytes,
119
+ data: bytes,
120
+ algorithm: asym_utils.Prehashed | hashes.HashAlgorithm,
121
+ ) -> None:
122
+ """
123
+ Verifies the signature of the data.
124
+ """
125
+
126
+ @abc.abstractmethod
127
+ def __eq__(self, other: object) -> bool:
128
+ """
129
+ Checks equality.
130
+ """
131
+
132
+
133
+ DSAPublicKeyWithSerialization = DSAPublicKey
134
+ DSAPublicKey.register(rust_openssl.dsa.DSAPublicKey)
135
+
136
+ DSAPrivateNumbers = rust_openssl.dsa.DSAPrivateNumbers
137
+ DSAPublicNumbers = rust_openssl.dsa.DSAPublicNumbers
138
+ DSAParameterNumbers = rust_openssl.dsa.DSAParameterNumbers
139
+
140
+
141
+ def generate_parameters(
142
+ key_size: int, backend: typing.Any = None
143
+ ) -> DSAParameters:
144
+ if key_size not in (1024, 2048, 3072, 4096):
145
+ raise ValueError("Key size must be 1024, 2048, 3072, or 4096 bits.")
146
+
147
+ return rust_openssl.dsa.generate_parameters(key_size)
148
+
149
+
150
+ def generate_private_key(
151
+ key_size: int, backend: typing.Any = None
152
+ ) -> DSAPrivateKey:
153
+ parameters = generate_parameters(key_size)
154
+ return parameters.generate_private_key()
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/ec.py ADDED
@@ -0,0 +1,403 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import abc
8
+ import typing
9
+
10
+ from cryptography import utils
11
+ from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
12
+ from cryptography.hazmat._oid import ObjectIdentifier
13
+ from cryptography.hazmat.bindings._rust import openssl as rust_openssl
14
+ from cryptography.hazmat.primitives import _serialization, hashes
15
+ from cryptography.hazmat.primitives.asymmetric import utils as asym_utils
16
+
17
+
18
+ class EllipticCurveOID:
19
+ SECP192R1 = ObjectIdentifier("1.2.840.10045.3.1.1")
20
+ SECP224R1 = ObjectIdentifier("1.3.132.0.33")
21
+ SECP256K1 = ObjectIdentifier("1.3.132.0.10")
22
+ SECP256R1 = ObjectIdentifier("1.2.840.10045.3.1.7")
23
+ SECP384R1 = ObjectIdentifier("1.3.132.0.34")
24
+ SECP521R1 = ObjectIdentifier("1.3.132.0.35")
25
+ BRAINPOOLP256R1 = ObjectIdentifier("1.3.36.3.3.2.8.1.1.7")
26
+ BRAINPOOLP384R1 = ObjectIdentifier("1.3.36.3.3.2.8.1.1.11")
27
+ BRAINPOOLP512R1 = ObjectIdentifier("1.3.36.3.3.2.8.1.1.13")
28
+ SECT163K1 = ObjectIdentifier("1.3.132.0.1")
29
+ SECT163R2 = ObjectIdentifier("1.3.132.0.15")
30
+ SECT233K1 = ObjectIdentifier("1.3.132.0.26")
31
+ SECT233R1 = ObjectIdentifier("1.3.132.0.27")
32
+ SECT283K1 = ObjectIdentifier("1.3.132.0.16")
33
+ SECT283R1 = ObjectIdentifier("1.3.132.0.17")
34
+ SECT409K1 = ObjectIdentifier("1.3.132.0.36")
35
+ SECT409R1 = ObjectIdentifier("1.3.132.0.37")
36
+ SECT571K1 = ObjectIdentifier("1.3.132.0.38")
37
+ SECT571R1 = ObjectIdentifier("1.3.132.0.39")
38
+
39
+
40
+ class EllipticCurve(metaclass=abc.ABCMeta):
41
+ @property
42
+ @abc.abstractmethod
43
+ def name(self) -> str:
44
+ """
45
+ The name of the curve. e.g. secp256r1.
46
+ """
47
+
48
+ @property
49
+ @abc.abstractmethod
50
+ def key_size(self) -> int:
51
+ """
52
+ Bit size of a secret scalar for the curve.
53
+ """
54
+
55
+
56
+ class EllipticCurveSignatureAlgorithm(metaclass=abc.ABCMeta):
57
+ @property
58
+ @abc.abstractmethod
59
+ def algorithm(
60
+ self,
61
+ ) -> asym_utils.Prehashed | hashes.HashAlgorithm:
62
+ """
63
+ The digest algorithm used with this signature.
64
+ """
65
+
66
+
67
+ class EllipticCurvePrivateKey(metaclass=abc.ABCMeta):
68
+ @abc.abstractmethod
69
+ def exchange(
70
+ self, algorithm: ECDH, peer_public_key: EllipticCurvePublicKey
71
+ ) -> bytes:
72
+ """
73
+ Performs a key exchange operation using the provided algorithm with the
74
+ provided peer's public key.
75
+ """
76
+
77
+ @abc.abstractmethod
78
+ def public_key(self) -> EllipticCurvePublicKey:
79
+ """
80
+ The EllipticCurvePublicKey for this private key.
81
+ """
82
+
83
+ @property
84
+ @abc.abstractmethod
85
+ def curve(self) -> EllipticCurve:
86
+ """
87
+ The EllipticCurve that this key is on.
88
+ """
89
+
90
+ @property
91
+ @abc.abstractmethod
92
+ def key_size(self) -> int:
93
+ """
94
+ Bit size of a secret scalar for the curve.
95
+ """
96
+
97
+ @abc.abstractmethod
98
+ def sign(
99
+ self,
100
+ data: bytes,
101
+ signature_algorithm: EllipticCurveSignatureAlgorithm,
102
+ ) -> bytes:
103
+ """
104
+ Signs the data
105
+ """
106
+
107
+ @abc.abstractmethod
108
+ def private_numbers(self) -> EllipticCurvePrivateNumbers:
109
+ """
110
+ Returns an EllipticCurvePrivateNumbers.
111
+ """
112
+
113
+ @abc.abstractmethod
114
+ def private_bytes(
115
+ self,
116
+ encoding: _serialization.Encoding,
117
+ format: _serialization.PrivateFormat,
118
+ encryption_algorithm: _serialization.KeySerializationEncryption,
119
+ ) -> bytes:
120
+ """
121
+ Returns the key serialized as bytes.
122
+ """
123
+
124
+
125
+ EllipticCurvePrivateKeyWithSerialization = EllipticCurvePrivateKey
126
+ EllipticCurvePrivateKey.register(rust_openssl.ec.ECPrivateKey)
127
+
128
+
129
+ class EllipticCurvePublicKey(metaclass=abc.ABCMeta):
130
+ @property
131
+ @abc.abstractmethod
132
+ def curve(self) -> EllipticCurve:
133
+ """
134
+ The EllipticCurve that this key is on.
135
+ """
136
+
137
+ @property
138
+ @abc.abstractmethod
139
+ def key_size(self) -> int:
140
+ """
141
+ Bit size of a secret scalar for the curve.
142
+ """
143
+
144
+ @abc.abstractmethod
145
+ def public_numbers(self) -> EllipticCurvePublicNumbers:
146
+ """
147
+ Returns an EllipticCurvePublicNumbers.
148
+ """
149
+
150
+ @abc.abstractmethod
151
+ def public_bytes(
152
+ self,
153
+ encoding: _serialization.Encoding,
154
+ format: _serialization.PublicFormat,
155
+ ) -> bytes:
156
+ """
157
+ Returns the key serialized as bytes.
158
+ """
159
+
160
+ @abc.abstractmethod
161
+ def verify(
162
+ self,
163
+ signature: bytes,
164
+ data: bytes,
165
+ signature_algorithm: EllipticCurveSignatureAlgorithm,
166
+ ) -> None:
167
+ """
168
+ Verifies the signature of the data.
169
+ """
170
+
171
+ @classmethod
172
+ def from_encoded_point(
173
+ cls, curve: EllipticCurve, data: bytes
174
+ ) -> EllipticCurvePublicKey:
175
+ utils._check_bytes("data", data)
176
+
177
+ if len(data) == 0:
178
+ raise ValueError("data must not be an empty byte string")
179
+
180
+ if data[0] not in [0x02, 0x03, 0x04]:
181
+ raise ValueError("Unsupported elliptic curve point type")
182
+
183
+ return rust_openssl.ec.from_public_bytes(curve, data)
184
+
185
+ @abc.abstractmethod
186
+ def __eq__(self, other: object) -> bool:
187
+ """
188
+ Checks equality.
189
+ """
190
+
191
+
192
+ EllipticCurvePublicKeyWithSerialization = EllipticCurvePublicKey
193
+ EllipticCurvePublicKey.register(rust_openssl.ec.ECPublicKey)
194
+
195
+ EllipticCurvePrivateNumbers = rust_openssl.ec.EllipticCurvePrivateNumbers
196
+ EllipticCurvePublicNumbers = rust_openssl.ec.EllipticCurvePublicNumbers
197
+
198
+
199
+ class SECT571R1(EllipticCurve):
200
+ name = "sect571r1"
201
+ key_size = 570
202
+
203
+
204
+ class SECT409R1(EllipticCurve):
205
+ name = "sect409r1"
206
+ key_size = 409
207
+
208
+
209
+ class SECT283R1(EllipticCurve):
210
+ name = "sect283r1"
211
+ key_size = 283
212
+
213
+
214
+ class SECT233R1(EllipticCurve):
215
+ name = "sect233r1"
216
+ key_size = 233
217
+
218
+
219
+ class SECT163R2(EllipticCurve):
220
+ name = "sect163r2"
221
+ key_size = 163
222
+
223
+
224
+ class SECT571K1(EllipticCurve):
225
+ name = "sect571k1"
226
+ key_size = 571
227
+
228
+
229
+ class SECT409K1(EllipticCurve):
230
+ name = "sect409k1"
231
+ key_size = 409
232
+
233
+
234
+ class SECT283K1(EllipticCurve):
235
+ name = "sect283k1"
236
+ key_size = 283
237
+
238
+
239
+ class SECT233K1(EllipticCurve):
240
+ name = "sect233k1"
241
+ key_size = 233
242
+
243
+
244
+ class SECT163K1(EllipticCurve):
245
+ name = "sect163k1"
246
+ key_size = 163
247
+
248
+
249
+ class SECP521R1(EllipticCurve):
250
+ name = "secp521r1"
251
+ key_size = 521
252
+
253
+
254
+ class SECP384R1(EllipticCurve):
255
+ name = "secp384r1"
256
+ key_size = 384
257
+
258
+
259
+ class SECP256R1(EllipticCurve):
260
+ name = "secp256r1"
261
+ key_size = 256
262
+
263
+
264
+ class SECP256K1(EllipticCurve):
265
+ name = "secp256k1"
266
+ key_size = 256
267
+
268
+
269
+ class SECP224R1(EllipticCurve):
270
+ name = "secp224r1"
271
+ key_size = 224
272
+
273
+
274
+ class SECP192R1(EllipticCurve):
275
+ name = "secp192r1"
276
+ key_size = 192
277
+
278
+
279
+ class BrainpoolP256R1(EllipticCurve):
280
+ name = "brainpoolP256r1"
281
+ key_size = 256
282
+
283
+
284
+ class BrainpoolP384R1(EllipticCurve):
285
+ name = "brainpoolP384r1"
286
+ key_size = 384
287
+
288
+
289
+ class BrainpoolP512R1(EllipticCurve):
290
+ name = "brainpoolP512r1"
291
+ key_size = 512
292
+
293
+
294
+ _CURVE_TYPES: dict[str, EllipticCurve] = {
295
+ "prime192v1": SECP192R1(),
296
+ "prime256v1": SECP256R1(),
297
+ "secp192r1": SECP192R1(),
298
+ "secp224r1": SECP224R1(),
299
+ "secp256r1": SECP256R1(),
300
+ "secp384r1": SECP384R1(),
301
+ "secp521r1": SECP521R1(),
302
+ "secp256k1": SECP256K1(),
303
+ "sect163k1": SECT163K1(),
304
+ "sect233k1": SECT233K1(),
305
+ "sect283k1": SECT283K1(),
306
+ "sect409k1": SECT409K1(),
307
+ "sect571k1": SECT571K1(),
308
+ "sect163r2": SECT163R2(),
309
+ "sect233r1": SECT233R1(),
310
+ "sect283r1": SECT283R1(),
311
+ "sect409r1": SECT409R1(),
312
+ "sect571r1": SECT571R1(),
313
+ "brainpoolP256r1": BrainpoolP256R1(),
314
+ "brainpoolP384r1": BrainpoolP384R1(),
315
+ "brainpoolP512r1": BrainpoolP512R1(),
316
+ }
317
+
318
+
319
+ class ECDSA(EllipticCurveSignatureAlgorithm):
320
+ def __init__(
321
+ self,
322
+ algorithm: asym_utils.Prehashed | hashes.HashAlgorithm,
323
+ deterministic_signing: bool = False,
324
+ ):
325
+ from cryptography.hazmat.backends.openssl.backend import backend
326
+
327
+ if (
328
+ deterministic_signing
329
+ and not backend.ecdsa_deterministic_supported()
330
+ ):
331
+ raise UnsupportedAlgorithm(
332
+ "ECDSA with deterministic signature (RFC 6979) is not "
333
+ "supported by this version of OpenSSL.",
334
+ _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
335
+ )
336
+ self._algorithm = algorithm
337
+ self._deterministic_signing = deterministic_signing
338
+
339
+ @property
340
+ def algorithm(
341
+ self,
342
+ ) -> asym_utils.Prehashed | hashes.HashAlgorithm:
343
+ return self._algorithm
344
+
345
+ @property
346
+ def deterministic_signing(
347
+ self,
348
+ ) -> bool:
349
+ return self._deterministic_signing
350
+
351
+
352
+ generate_private_key = rust_openssl.ec.generate_private_key
353
+
354
+
355
+ def derive_private_key(
356
+ private_value: int,
357
+ curve: EllipticCurve,
358
+ backend: typing.Any = None,
359
+ ) -> EllipticCurvePrivateKey:
360
+ if not isinstance(private_value, int):
361
+ raise TypeError("private_value must be an integer type.")
362
+
363
+ if private_value <= 0:
364
+ raise ValueError("private_value must be a positive integer.")
365
+
366
+ return rust_openssl.ec.derive_private_key(private_value, curve)
367
+
368
+
369
+ class ECDH:
370
+ pass
371
+
372
+
373
+ _OID_TO_CURVE = {
374
+ EllipticCurveOID.SECP192R1: SECP192R1,
375
+ EllipticCurveOID.SECP224R1: SECP224R1,
376
+ EllipticCurveOID.SECP256K1: SECP256K1,
377
+ EllipticCurveOID.SECP256R1: SECP256R1,
378
+ EllipticCurveOID.SECP384R1: SECP384R1,
379
+ EllipticCurveOID.SECP521R1: SECP521R1,
380
+ EllipticCurveOID.BRAINPOOLP256R1: BrainpoolP256R1,
381
+ EllipticCurveOID.BRAINPOOLP384R1: BrainpoolP384R1,
382
+ EllipticCurveOID.BRAINPOOLP512R1: BrainpoolP512R1,
383
+ EllipticCurveOID.SECT163K1: SECT163K1,
384
+ EllipticCurveOID.SECT163R2: SECT163R2,
385
+ EllipticCurveOID.SECT233K1: SECT233K1,
386
+ EllipticCurveOID.SECT233R1: SECT233R1,
387
+ EllipticCurveOID.SECT283K1: SECT283K1,
388
+ EllipticCurveOID.SECT283R1: SECT283R1,
389
+ EllipticCurveOID.SECT409K1: SECT409K1,
390
+ EllipticCurveOID.SECT409R1: SECT409R1,
391
+ EllipticCurveOID.SECT571K1: SECT571K1,
392
+ EllipticCurveOID.SECT571R1: SECT571R1,
393
+ }
394
+
395
+
396
+ def get_curve_for_oid(oid: ObjectIdentifier) -> type[EllipticCurve]:
397
+ try:
398
+ return _OID_TO_CURVE[oid]
399
+ except KeyError:
400
+ raise LookupError(
401
+ "The provided object identifier has no matching elliptic "
402
+ "curve class"
403
+ )
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/ed25519.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import abc
8
+
9
+ from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
10
+ from cryptography.hazmat.bindings._rust import openssl as rust_openssl
11
+ from cryptography.hazmat.primitives import _serialization
12
+
13
+
14
+ class Ed25519PublicKey(metaclass=abc.ABCMeta):
15
+ @classmethod
16
+ def from_public_bytes(cls, data: bytes) -> Ed25519PublicKey:
17
+ from cryptography.hazmat.backends.openssl.backend import backend
18
+
19
+ if not backend.ed25519_supported():
20
+ raise UnsupportedAlgorithm(
21
+ "ed25519 is not supported by this version of OpenSSL.",
22
+ _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
23
+ )
24
+
25
+ return rust_openssl.ed25519.from_public_bytes(data)
26
+
27
+ @abc.abstractmethod
28
+ def public_bytes(
29
+ self,
30
+ encoding: _serialization.Encoding,
31
+ format: _serialization.PublicFormat,
32
+ ) -> bytes:
33
+ """
34
+ The serialized bytes of the public key.
35
+ """
36
+
37
+ @abc.abstractmethod
38
+ def public_bytes_raw(self) -> bytes:
39
+ """
40
+ The raw bytes of the public key.
41
+ Equivalent to public_bytes(Raw, Raw).
42
+ """
43
+
44
+ @abc.abstractmethod
45
+ def verify(self, signature: bytes, data: bytes) -> None:
46
+ """
47
+ Verify the signature.
48
+ """
49
+
50
+ @abc.abstractmethod
51
+ def __eq__(self, other: object) -> bool:
52
+ """
53
+ Checks equality.
54
+ """
55
+
56
+
57
+ Ed25519PublicKey.register(rust_openssl.ed25519.Ed25519PublicKey)
58
+
59
+
60
+ class Ed25519PrivateKey(metaclass=abc.ABCMeta):
61
+ @classmethod
62
+ def generate(cls) -> Ed25519PrivateKey:
63
+ from cryptography.hazmat.backends.openssl.backend import backend
64
+
65
+ if not backend.ed25519_supported():
66
+ raise UnsupportedAlgorithm(
67
+ "ed25519 is not supported by this version of OpenSSL.",
68
+ _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
69
+ )
70
+
71
+ return rust_openssl.ed25519.generate_key()
72
+
73
+ @classmethod
74
+ def from_private_bytes(cls, data: bytes) -> Ed25519PrivateKey:
75
+ from cryptography.hazmat.backends.openssl.backend import backend
76
+
77
+ if not backend.ed25519_supported():
78
+ raise UnsupportedAlgorithm(
79
+ "ed25519 is not supported by this version of OpenSSL.",
80
+ _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
81
+ )
82
+
83
+ return rust_openssl.ed25519.from_private_bytes(data)
84
+
85
+ @abc.abstractmethod
86
+ def public_key(self) -> Ed25519PublicKey:
87
+ """
88
+ The Ed25519PublicKey derived from the private key.
89
+ """
90
+
91
+ @abc.abstractmethod
92
+ def private_bytes(
93
+ self,
94
+ encoding: _serialization.Encoding,
95
+ format: _serialization.PrivateFormat,
96
+ encryption_algorithm: _serialization.KeySerializationEncryption,
97
+ ) -> bytes:
98
+ """
99
+ The serialized bytes of the private key.
100
+ """
101
+
102
+ @abc.abstractmethod
103
+ def private_bytes_raw(self) -> bytes:
104
+ """
105
+ The raw bytes of the private key.
106
+ Equivalent to private_bytes(Raw, Raw, NoEncryption()).
107
+ """
108
+
109
+ @abc.abstractmethod
110
+ def sign(self, data: bytes) -> bytes:
111
+ """
112
+ Signs the data.
113
+ """
114
+
115
+
116
+ Ed25519PrivateKey.register(rust_openssl.ed25519.Ed25519PrivateKey)
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/ed448.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import abc
8
+
9
+ from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
10
+ from cryptography.hazmat.bindings._rust import openssl as rust_openssl
11
+ from cryptography.hazmat.primitives import _serialization
12
+
13
+
14
+ class Ed448PublicKey(metaclass=abc.ABCMeta):
15
+ @classmethod
16
+ def from_public_bytes(cls, data: bytes) -> Ed448PublicKey:
17
+ from cryptography.hazmat.backends.openssl.backend import backend
18
+
19
+ if not backend.ed448_supported():
20
+ raise UnsupportedAlgorithm(
21
+ "ed448 is not supported by this version of OpenSSL.",
22
+ _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
23
+ )
24
+
25
+ return rust_openssl.ed448.from_public_bytes(data)
26
+
27
+ @abc.abstractmethod
28
+ def public_bytes(
29
+ self,
30
+ encoding: _serialization.Encoding,
31
+ format: _serialization.PublicFormat,
32
+ ) -> bytes:
33
+ """
34
+ The serialized bytes of the public key.
35
+ """
36
+
37
+ @abc.abstractmethod
38
+ def public_bytes_raw(self) -> bytes:
39
+ """
40
+ The raw bytes of the public key.
41
+ Equivalent to public_bytes(Raw, Raw).
42
+ """
43
+
44
+ @abc.abstractmethod
45
+ def verify(self, signature: bytes, data: bytes) -> None:
46
+ """
47
+ Verify the signature.
48
+ """
49
+
50
+ @abc.abstractmethod
51
+ def __eq__(self, other: object) -> bool:
52
+ """
53
+ Checks equality.
54
+ """
55
+
56
+
57
+ if hasattr(rust_openssl, "ed448"):
58
+ Ed448PublicKey.register(rust_openssl.ed448.Ed448PublicKey)
59
+
60
+
61
+ class Ed448PrivateKey(metaclass=abc.ABCMeta):
62
+ @classmethod
63
+ def generate(cls) -> Ed448PrivateKey:
64
+ from cryptography.hazmat.backends.openssl.backend import backend
65
+
66
+ if not backend.ed448_supported():
67
+ raise UnsupportedAlgorithm(
68
+ "ed448 is not supported by this version of OpenSSL.",
69
+ _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
70
+ )
71
+
72
+ return rust_openssl.ed448.generate_key()
73
+
74
+ @classmethod
75
+ def from_private_bytes(cls, data: bytes) -> Ed448PrivateKey:
76
+ from cryptography.hazmat.backends.openssl.backend import backend
77
+
78
+ if not backend.ed448_supported():
79
+ raise UnsupportedAlgorithm(
80
+ "ed448 is not supported by this version of OpenSSL.",
81
+ _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
82
+ )
83
+
84
+ return rust_openssl.ed448.from_private_bytes(data)
85
+
86
+ @abc.abstractmethod
87
+ def public_key(self) -> Ed448PublicKey:
88
+ """
89
+ The Ed448PublicKey derived from the private key.
90
+ """
91
+
92
+ @abc.abstractmethod
93
+ def sign(self, data: bytes) -> bytes:
94
+ """
95
+ Signs the data.
96
+ """
97
+
98
+ @abc.abstractmethod
99
+ def private_bytes(
100
+ self,
101
+ encoding: _serialization.Encoding,
102
+ format: _serialization.PrivateFormat,
103
+ encryption_algorithm: _serialization.KeySerializationEncryption,
104
+ ) -> bytes:
105
+ """
106
+ The serialized bytes of the private key.
107
+ """
108
+
109
+ @abc.abstractmethod
110
+ def private_bytes_raw(self) -> bytes:
111
+ """
112
+ The raw bytes of the private key.
113
+ Equivalent to private_bytes(Raw, Raw, NoEncryption()).
114
+ """
115
+
116
+
117
+ if hasattr(rust_openssl, "x448"):
118
+ Ed448PrivateKey.register(rust_openssl.ed448.Ed448PrivateKey)
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/padding.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import abc
8
+
9
+ from cryptography.hazmat.primitives import hashes
10
+ from cryptography.hazmat.primitives._asymmetric import (
11
+ AsymmetricPadding as AsymmetricPadding,
12
+ )
13
+ from cryptography.hazmat.primitives.asymmetric import rsa
14
+
15
+
16
+ class PKCS1v15(AsymmetricPadding):
17
+ name = "EMSA-PKCS1-v1_5"
18
+
19
+
20
+ class _MaxLength:
21
+ "Sentinel value for `MAX_LENGTH`."
22
+
23
+
24
+ class _Auto:
25
+ "Sentinel value for `AUTO`."
26
+
27
+
28
+ class _DigestLength:
29
+ "Sentinel value for `DIGEST_LENGTH`."
30
+
31
+
32
+ class PSS(AsymmetricPadding):
33
+ MAX_LENGTH = _MaxLength()
34
+ AUTO = _Auto()
35
+ DIGEST_LENGTH = _DigestLength()
36
+ name = "EMSA-PSS"
37
+ _salt_length: int | _MaxLength | _Auto | _DigestLength
38
+
39
+ def __init__(
40
+ self,
41
+ mgf: MGF,
42
+ salt_length: int | _MaxLength | _Auto | _DigestLength,
43
+ ) -> None:
44
+ self._mgf = mgf
45
+
46
+ if not isinstance(
47
+ salt_length, (int, _MaxLength, _Auto, _DigestLength)
48
+ ):
49
+ raise TypeError(
50
+ "salt_length must be an integer, MAX_LENGTH, "
51
+ "DIGEST_LENGTH, or AUTO"
52
+ )
53
+
54
+ if isinstance(salt_length, int) and salt_length < 0:
55
+ raise ValueError("salt_length must be zero or greater.")
56
+
57
+ self._salt_length = salt_length
58
+
59
+ @property
60
+ def mgf(self) -> MGF:
61
+ return self._mgf
62
+
63
+
64
+ class OAEP(AsymmetricPadding):
65
+ name = "EME-OAEP"
66
+
67
+ def __init__(
68
+ self,
69
+ mgf: MGF,
70
+ algorithm: hashes.HashAlgorithm,
71
+ label: bytes | None,
72
+ ):
73
+ if not isinstance(algorithm, hashes.HashAlgorithm):
74
+ raise TypeError("Expected instance of hashes.HashAlgorithm.")
75
+
76
+ self._mgf = mgf
77
+ self._algorithm = algorithm
78
+ self._label = label
79
+
80
+ @property
81
+ def algorithm(self) -> hashes.HashAlgorithm:
82
+ return self._algorithm
83
+
84
+ @property
85
+ def mgf(self) -> MGF:
86
+ return self._mgf
87
+
88
+
89
+ class MGF(metaclass=abc.ABCMeta):
90
+ _algorithm: hashes.HashAlgorithm
91
+
92
+
93
+ class MGF1(MGF):
94
+ MAX_LENGTH = _MaxLength()
95
+
96
+ def __init__(self, algorithm: hashes.HashAlgorithm):
97
+ if not isinstance(algorithm, hashes.HashAlgorithm):
98
+ raise TypeError("Expected instance of hashes.HashAlgorithm.")
99
+
100
+ self._algorithm = algorithm
101
+
102
+
103
+ def calculate_max_pss_salt_length(
104
+ key: rsa.RSAPrivateKey | rsa.RSAPublicKey,
105
+ hash_algorithm: hashes.HashAlgorithm,
106
+ ) -> int:
107
+ if not isinstance(key, (rsa.RSAPrivateKey, rsa.RSAPublicKey)):
108
+ raise TypeError("key must be an RSA public or private key")
109
+ # bit length - 1 per RFC 3447
110
+ emlen = (key.key_size + 6) // 8
111
+ salt_length = emlen - hash_algorithm.digest_size - 2
112
+ assert salt_length >= 0
113
+ return salt_length
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.py ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import abc
8
+ import typing
9
+ from math import gcd
10
+
11
+ from cryptography.hazmat.bindings._rust import openssl as rust_openssl
12
+ from cryptography.hazmat.primitives import _serialization, hashes
13
+ from cryptography.hazmat.primitives._asymmetric import AsymmetricPadding
14
+ from cryptography.hazmat.primitives.asymmetric import utils as asym_utils
15
+
16
+
17
+ class RSAPrivateKey(metaclass=abc.ABCMeta):
18
+ @abc.abstractmethod
19
+ def decrypt(self, ciphertext: bytes, padding: AsymmetricPadding) -> bytes:
20
+ """
21
+ Decrypts the provided ciphertext.
22
+ """
23
+
24
+ @property
25
+ @abc.abstractmethod
26
+ def key_size(self) -> int:
27
+ """
28
+ The bit length of the public modulus.
29
+ """
30
+
31
+ @abc.abstractmethod
32
+ def public_key(self) -> RSAPublicKey:
33
+ """
34
+ The RSAPublicKey associated with this private key.
35
+ """
36
+
37
+ @abc.abstractmethod
38
+ def sign(
39
+ self,
40
+ data: bytes,
41
+ padding: AsymmetricPadding,
42
+ algorithm: asym_utils.Prehashed | hashes.HashAlgorithm,
43
+ ) -> bytes:
44
+ """
45
+ Signs the data.
46
+ """
47
+
48
+ @abc.abstractmethod
49
+ def private_numbers(self) -> RSAPrivateNumbers:
50
+ """
51
+ Returns an RSAPrivateNumbers.
52
+ """
53
+
54
+ @abc.abstractmethod
55
+ def private_bytes(
56
+ self,
57
+ encoding: _serialization.Encoding,
58
+ format: _serialization.PrivateFormat,
59
+ encryption_algorithm: _serialization.KeySerializationEncryption,
60
+ ) -> bytes:
61
+ """
62
+ Returns the key serialized as bytes.
63
+ """
64
+
65
+
66
+ RSAPrivateKeyWithSerialization = RSAPrivateKey
67
+ RSAPrivateKey.register(rust_openssl.rsa.RSAPrivateKey)
68
+
69
+
70
+ class RSAPublicKey(metaclass=abc.ABCMeta):
71
+ @abc.abstractmethod
72
+ def encrypt(self, plaintext: bytes, padding: AsymmetricPadding) -> bytes:
73
+ """
74
+ Encrypts the given plaintext.
75
+ """
76
+
77
+ @property
78
+ @abc.abstractmethod
79
+ def key_size(self) -> int:
80
+ """
81
+ The bit length of the public modulus.
82
+ """
83
+
84
+ @abc.abstractmethod
85
+ def public_numbers(self) -> RSAPublicNumbers:
86
+ """
87
+ Returns an RSAPublicNumbers
88
+ """
89
+
90
+ @abc.abstractmethod
91
+ def public_bytes(
92
+ self,
93
+ encoding: _serialization.Encoding,
94
+ format: _serialization.PublicFormat,
95
+ ) -> bytes:
96
+ """
97
+ Returns the key serialized as bytes.
98
+ """
99
+
100
+ @abc.abstractmethod
101
+ def verify(
102
+ self,
103
+ signature: bytes,
104
+ data: bytes,
105
+ padding: AsymmetricPadding,
106
+ algorithm: asym_utils.Prehashed | hashes.HashAlgorithm,
107
+ ) -> None:
108
+ """
109
+ Verifies the signature of the data.
110
+ """
111
+
112
+ @abc.abstractmethod
113
+ def recover_data_from_signature(
114
+ self,
115
+ signature: bytes,
116
+ padding: AsymmetricPadding,
117
+ algorithm: hashes.HashAlgorithm | None,
118
+ ) -> bytes:
119
+ """
120
+ Recovers the original data from the signature.
121
+ """
122
+
123
+ @abc.abstractmethod
124
+ def __eq__(self, other: object) -> bool:
125
+ """
126
+ Checks equality.
127
+ """
128
+
129
+
130
+ RSAPublicKeyWithSerialization = RSAPublicKey
131
+ RSAPublicKey.register(rust_openssl.rsa.RSAPublicKey)
132
+
133
+ RSAPrivateNumbers = rust_openssl.rsa.RSAPrivateNumbers
134
+ RSAPublicNumbers = rust_openssl.rsa.RSAPublicNumbers
135
+
136
+
137
+ def generate_private_key(
138
+ public_exponent: int,
139
+ key_size: int,
140
+ backend: typing.Any = None,
141
+ ) -> RSAPrivateKey:
142
+ _verify_rsa_parameters(public_exponent, key_size)
143
+ return rust_openssl.rsa.generate_private_key(public_exponent, key_size)
144
+
145
+
146
+ def _verify_rsa_parameters(public_exponent: int, key_size: int) -> None:
147
+ if public_exponent not in (3, 65537):
148
+ raise ValueError(
149
+ "public_exponent must be either 3 (for legacy compatibility) or "
150
+ "65537. Almost everyone should choose 65537 here!"
151
+ )
152
+
153
+ if key_size < 1024:
154
+ raise ValueError("key_size must be at least 1024-bits.")
155
+
156
+
157
+ def _modinv(e: int, m: int) -> int:
158
+ """
159
+ Modular Multiplicative Inverse. Returns x such that: (x*e) mod m == 1
160
+ """
161
+ x1, x2 = 1, 0
162
+ a, b = e, m
163
+ while b > 0:
164
+ q, r = divmod(a, b)
165
+ xn = x1 - q * x2
166
+ a, b, x1, x2 = b, r, x2, xn
167
+ return x1 % m
168
+
169
+
170
+ def rsa_crt_iqmp(p: int, q: int) -> int:
171
+ """
172
+ Compute the CRT (q ** -1) % p value from RSA primes p and q.
173
+ """
174
+ return _modinv(q, p)
175
+
176
+
177
+ def rsa_crt_dmp1(private_exponent: int, p: int) -> int:
178
+ """
179
+ Compute the CRT private_exponent % (p - 1) value from the RSA
180
+ private_exponent (d) and p.
181
+ """
182
+ return private_exponent % (p - 1)
183
+
184
+
185
+ def rsa_crt_dmq1(private_exponent: int, q: int) -> int:
186
+ """
187
+ Compute the CRT private_exponent % (q - 1) value from the RSA
188
+ private_exponent (d) and q.
189
+ """
190
+ return private_exponent % (q - 1)
191
+
192
+
193
+ def rsa_recover_private_exponent(e: int, p: int, q: int) -> int:
194
+ """
195
+ Compute the RSA private_exponent (d) given the public exponent (e)
196
+ and the RSA primes p and q.
197
+
198
+ This uses the Carmichael totient function to generate the
199
+ smallest possible working value of the private exponent.
200
+ """
201
+ # This lambda_n is the Carmichael totient function.
202
+ # The original RSA paper uses the Euler totient function
203
+ # here: phi_n = (p - 1) * (q - 1)
204
+ # Either version of the private exponent will work, but the
205
+ # one generated by the older formulation may be larger
206
+ # than necessary. (lambda_n always divides phi_n)
207
+ #
208
+ # TODO: Replace with lcm(p - 1, q - 1) once the minimum
209
+ # supported Python version is >= 3.9.
210
+ lambda_n = (p - 1) * (q - 1) // gcd(p - 1, q - 1)
211
+ return _modinv(e, lambda_n)
212
+
213
+
214
+ # Controls the number of iterations rsa_recover_prime_factors will perform
215
+ # to obtain the prime factors. Each iteration increments by 2 so the actual
216
+ # maximum attempts is half this number.
217
+ _MAX_RECOVERY_ATTEMPTS = 1000
218
+
219
+
220
+ def rsa_recover_prime_factors(n: int, e: int, d: int) -> tuple[int, int]:
221
+ """
222
+ Compute factors p and q from the private exponent d. We assume that n has
223
+ no more than two factors. This function is adapted from code in PyCrypto.
224
+ """
225
+ # See 8.2.2(i) in Handbook of Applied Cryptography.
226
+ ktot = d * e - 1
227
+ # The quantity d*e-1 is a multiple of phi(n), even,
228
+ # and can be represented as t*2^s.
229
+ t = ktot
230
+ while t % 2 == 0:
231
+ t = t // 2
232
+ # Cycle through all multiplicative inverses in Zn.
233
+ # The algorithm is non-deterministic, but there is a 50% chance
234
+ # any candidate a leads to successful factoring.
235
+ # See "Digitalized Signatures and Public Key Functions as Intractable
236
+ # as Factorization", M. Rabin, 1979
237
+ spotted = False
238
+ a = 2
239
+ while not spotted and a < _MAX_RECOVERY_ATTEMPTS:
240
+ k = t
241
+ # Cycle through all values a^{t*2^i}=a^k
242
+ while k < ktot:
243
+ cand = pow(a, k, n)
244
+ # Check if a^k is a non-trivial root of unity (mod n)
245
+ if cand != 1 and cand != (n - 1) and pow(cand, 2, n) == 1:
246
+ # We have found a number such that (cand-1)(cand+1)=0 (mod n).
247
+ # Either of the terms divides n.
248
+ p = gcd(cand + 1, n)
249
+ spotted = True
250
+ break
251
+ k *= 2
252
+ # This value was not any good... let's try another!
253
+ a += 2
254
+ if not spotted:
255
+ raise ValueError("Unable to compute factors p and q from exponent d.")
256
+ # Found !
257
+ q, r = divmod(n, p)
258
+ assert r == 0
259
+ p, q = sorted((p, q), reverse=True)
260
+ return (p, q)
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/types.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import typing
8
+
9
+ from cryptography import utils
10
+ from cryptography.hazmat.primitives.asymmetric import (
11
+ dh,
12
+ dsa,
13
+ ec,
14
+ ed448,
15
+ ed25519,
16
+ rsa,
17
+ x448,
18
+ x25519,
19
+ )
20
+
21
+ # Every asymmetric key type
22
+ PublicKeyTypes = typing.Union[
23
+ dh.DHPublicKey,
24
+ dsa.DSAPublicKey,
25
+ rsa.RSAPublicKey,
26
+ ec.EllipticCurvePublicKey,
27
+ ed25519.Ed25519PublicKey,
28
+ ed448.Ed448PublicKey,
29
+ x25519.X25519PublicKey,
30
+ x448.X448PublicKey,
31
+ ]
32
+ PUBLIC_KEY_TYPES = PublicKeyTypes
33
+ utils.deprecated(
34
+ PUBLIC_KEY_TYPES,
35
+ __name__,
36
+ "Use PublicKeyTypes instead",
37
+ utils.DeprecatedIn40,
38
+ name="PUBLIC_KEY_TYPES",
39
+ )
40
+ # Every asymmetric key type
41
+ PrivateKeyTypes = typing.Union[
42
+ dh.DHPrivateKey,
43
+ ed25519.Ed25519PrivateKey,
44
+ ed448.Ed448PrivateKey,
45
+ rsa.RSAPrivateKey,
46
+ dsa.DSAPrivateKey,
47
+ ec.EllipticCurvePrivateKey,
48
+ x25519.X25519PrivateKey,
49
+ x448.X448PrivateKey,
50
+ ]
51
+ PRIVATE_KEY_TYPES = PrivateKeyTypes
52
+ utils.deprecated(
53
+ PRIVATE_KEY_TYPES,
54
+ __name__,
55
+ "Use PrivateKeyTypes instead",
56
+ utils.DeprecatedIn40,
57
+ name="PRIVATE_KEY_TYPES",
58
+ )
59
+ # Just the key types we allow to be used for x509 signing. This mirrors
60
+ # the certificate public key types
61
+ CertificateIssuerPrivateKeyTypes = typing.Union[
62
+ ed25519.Ed25519PrivateKey,
63
+ ed448.Ed448PrivateKey,
64
+ rsa.RSAPrivateKey,
65
+ dsa.DSAPrivateKey,
66
+ ec.EllipticCurvePrivateKey,
67
+ ]
68
+ CERTIFICATE_PRIVATE_KEY_TYPES = CertificateIssuerPrivateKeyTypes
69
+ utils.deprecated(
70
+ CERTIFICATE_PRIVATE_KEY_TYPES,
71
+ __name__,
72
+ "Use CertificateIssuerPrivateKeyTypes instead",
73
+ utils.DeprecatedIn40,
74
+ name="CERTIFICATE_PRIVATE_KEY_TYPES",
75
+ )
76
+ # Just the key types we allow to be used for x509 signing. This mirrors
77
+ # the certificate private key types
78
+ CertificateIssuerPublicKeyTypes = typing.Union[
79
+ dsa.DSAPublicKey,
80
+ rsa.RSAPublicKey,
81
+ ec.EllipticCurvePublicKey,
82
+ ed25519.Ed25519PublicKey,
83
+ ed448.Ed448PublicKey,
84
+ ]
85
+ CERTIFICATE_ISSUER_PUBLIC_KEY_TYPES = CertificateIssuerPublicKeyTypes
86
+ utils.deprecated(
87
+ CERTIFICATE_ISSUER_PUBLIC_KEY_TYPES,
88
+ __name__,
89
+ "Use CertificateIssuerPublicKeyTypes instead",
90
+ utils.DeprecatedIn40,
91
+ name="CERTIFICATE_ISSUER_PUBLIC_KEY_TYPES",
92
+ )
93
+ # This type removes DHPublicKey. x448/x25519 can be a public key
94
+ # but cannot be used in signing so they are allowed here.
95
+ CertificatePublicKeyTypes = typing.Union[
96
+ dsa.DSAPublicKey,
97
+ rsa.RSAPublicKey,
98
+ ec.EllipticCurvePublicKey,
99
+ ed25519.Ed25519PublicKey,
100
+ ed448.Ed448PublicKey,
101
+ x25519.X25519PublicKey,
102
+ x448.X448PublicKey,
103
+ ]
104
+ CERTIFICATE_PUBLIC_KEY_TYPES = CertificatePublicKeyTypes
105
+ utils.deprecated(
106
+ CERTIFICATE_PUBLIC_KEY_TYPES,
107
+ __name__,
108
+ "Use CertificatePublicKeyTypes instead",
109
+ utils.DeprecatedIn40,
110
+ name="CERTIFICATE_PUBLIC_KEY_TYPES",
111
+ )
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/utils.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ from cryptography.hazmat.bindings._rust import asn1
8
+ from cryptography.hazmat.primitives import hashes
9
+
10
+ decode_dss_signature = asn1.decode_dss_signature
11
+ encode_dss_signature = asn1.encode_dss_signature
12
+
13
+
14
+ class Prehashed:
15
+ def __init__(self, algorithm: hashes.HashAlgorithm):
16
+ if not isinstance(algorithm, hashes.HashAlgorithm):
17
+ raise TypeError("Expected instance of HashAlgorithm.")
18
+
19
+ self._algorithm = algorithm
20
+ self._digest_size = algorithm.digest_size
21
+
22
+ @property
23
+ def digest_size(self) -> int:
24
+ return self._digest_size
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/x25519.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import abc
8
+
9
+ from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
10
+ from cryptography.hazmat.bindings._rust import openssl as rust_openssl
11
+ from cryptography.hazmat.primitives import _serialization
12
+
13
+
14
+ class X25519PublicKey(metaclass=abc.ABCMeta):
15
+ @classmethod
16
+ def from_public_bytes(cls, data: bytes) -> X25519PublicKey:
17
+ from cryptography.hazmat.backends.openssl.backend import backend
18
+
19
+ if not backend.x25519_supported():
20
+ raise UnsupportedAlgorithm(
21
+ "X25519 is not supported by this version of OpenSSL.",
22
+ _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM,
23
+ )
24
+
25
+ return rust_openssl.x25519.from_public_bytes(data)
26
+
27
+ @abc.abstractmethod
28
+ def public_bytes(
29
+ self,
30
+ encoding: _serialization.Encoding,
31
+ format: _serialization.PublicFormat,
32
+ ) -> bytes:
33
+ """
34
+ The serialized bytes of the public key.
35
+ """
36
+
37
+ @abc.abstractmethod
38
+ def public_bytes_raw(self) -> bytes:
39
+ """
40
+ The raw bytes of the public key.
41
+ Equivalent to public_bytes(Raw, Raw).
42
+ """
43
+
44
+ @abc.abstractmethod
45
+ def __eq__(self, other: object) -> bool:
46
+ """
47
+ Checks equality.
48
+ """
49
+
50
+
51
+ X25519PublicKey.register(rust_openssl.x25519.X25519PublicKey)
52
+
53
+
54
+ class X25519PrivateKey(metaclass=abc.ABCMeta):
55
+ @classmethod
56
+ def generate(cls) -> X25519PrivateKey:
57
+ from cryptography.hazmat.backends.openssl.backend import backend
58
+
59
+ if not backend.x25519_supported():
60
+ raise UnsupportedAlgorithm(
61
+ "X25519 is not supported by this version of OpenSSL.",
62
+ _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM,
63
+ )
64
+ return rust_openssl.x25519.generate_key()
65
+
66
+ @classmethod
67
+ def from_private_bytes(cls, data: bytes) -> X25519PrivateKey:
68
+ from cryptography.hazmat.backends.openssl.backend import backend
69
+
70
+ if not backend.x25519_supported():
71
+ raise UnsupportedAlgorithm(
72
+ "X25519 is not supported by this version of OpenSSL.",
73
+ _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM,
74
+ )
75
+
76
+ return rust_openssl.x25519.from_private_bytes(data)
77
+
78
+ @abc.abstractmethod
79
+ def public_key(self) -> X25519PublicKey:
80
+ """
81
+ Returns the public key associated with this private key
82
+ """
83
+
84
+ @abc.abstractmethod
85
+ def private_bytes(
86
+ self,
87
+ encoding: _serialization.Encoding,
88
+ format: _serialization.PrivateFormat,
89
+ encryption_algorithm: _serialization.KeySerializationEncryption,
90
+ ) -> bytes:
91
+ """
92
+ The serialized bytes of the private key.
93
+ """
94
+
95
+ @abc.abstractmethod
96
+ def private_bytes_raw(self) -> bytes:
97
+ """
98
+ The raw bytes of the private key.
99
+ Equivalent to private_bytes(Raw, Raw, NoEncryption()).
100
+ """
101
+
102
+ @abc.abstractmethod
103
+ def exchange(self, peer_public_key: X25519PublicKey) -> bytes:
104
+ """
105
+ Performs a key exchange operation using the provided peer's public key.
106
+ """
107
+
108
+
109
+ X25519PrivateKey.register(rust_openssl.x25519.X25519PrivateKey)
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/asymmetric/x448.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import abc
8
+
9
+ from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
10
+ from cryptography.hazmat.bindings._rust import openssl as rust_openssl
11
+ from cryptography.hazmat.primitives import _serialization
12
+
13
+
14
+ class X448PublicKey(metaclass=abc.ABCMeta):
15
+ @classmethod
16
+ def from_public_bytes(cls, data: bytes) -> X448PublicKey:
17
+ from cryptography.hazmat.backends.openssl.backend import backend
18
+
19
+ if not backend.x448_supported():
20
+ raise UnsupportedAlgorithm(
21
+ "X448 is not supported by this version of OpenSSL.",
22
+ _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM,
23
+ )
24
+
25
+ return rust_openssl.x448.from_public_bytes(data)
26
+
27
+ @abc.abstractmethod
28
+ def public_bytes(
29
+ self,
30
+ encoding: _serialization.Encoding,
31
+ format: _serialization.PublicFormat,
32
+ ) -> bytes:
33
+ """
34
+ The serialized bytes of the public key.
35
+ """
36
+
37
+ @abc.abstractmethod
38
+ def public_bytes_raw(self) -> bytes:
39
+ """
40
+ The raw bytes of the public key.
41
+ Equivalent to public_bytes(Raw, Raw).
42
+ """
43
+
44
+ @abc.abstractmethod
45
+ def __eq__(self, other: object) -> bool:
46
+ """
47
+ Checks equality.
48
+ """
49
+
50
+
51
+ if hasattr(rust_openssl, "x448"):
52
+ X448PublicKey.register(rust_openssl.x448.X448PublicKey)
53
+
54
+
55
+ class X448PrivateKey(metaclass=abc.ABCMeta):
56
+ @classmethod
57
+ def generate(cls) -> X448PrivateKey:
58
+ from cryptography.hazmat.backends.openssl.backend import backend
59
+
60
+ if not backend.x448_supported():
61
+ raise UnsupportedAlgorithm(
62
+ "X448 is not supported by this version of OpenSSL.",
63
+ _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM,
64
+ )
65
+
66
+ return rust_openssl.x448.generate_key()
67
+
68
+ @classmethod
69
+ def from_private_bytes(cls, data: bytes) -> X448PrivateKey:
70
+ from cryptography.hazmat.backends.openssl.backend import backend
71
+
72
+ if not backend.x448_supported():
73
+ raise UnsupportedAlgorithm(
74
+ "X448 is not supported by this version of OpenSSL.",
75
+ _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM,
76
+ )
77
+
78
+ return rust_openssl.x448.from_private_bytes(data)
79
+
80
+ @abc.abstractmethod
81
+ def public_key(self) -> X448PublicKey:
82
+ """
83
+ Returns the public key associated with this private key
84
+ """
85
+
86
+ @abc.abstractmethod
87
+ def private_bytes(
88
+ self,
89
+ encoding: _serialization.Encoding,
90
+ format: _serialization.PrivateFormat,
91
+ encryption_algorithm: _serialization.KeySerializationEncryption,
92
+ ) -> bytes:
93
+ """
94
+ The serialized bytes of the private key.
95
+ """
96
+
97
+ @abc.abstractmethod
98
+ def private_bytes_raw(self) -> bytes:
99
+ """
100
+ The raw bytes of the private key.
101
+ Equivalent to private_bytes(Raw, Raw, NoEncryption()).
102
+ """
103
+
104
+ @abc.abstractmethod
105
+ def exchange(self, peer_public_key: X448PublicKey) -> bytes:
106
+ """
107
+ Performs a key exchange operation using the provided peer's public key.
108
+ """
109
+
110
+
111
+ if hasattr(rust_openssl, "x448"):
112
+ X448PrivateKey.register(rust_openssl.x448.X448PrivateKey)
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/cmac.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ from cryptography.hazmat.bindings._rust import openssl as rust_openssl
8
+
9
+ __all__ = ["CMAC"]
10
+ CMAC = rust_openssl.cmac.CMAC
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/constant_time.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import hmac
8
+
9
+
10
+ def bytes_eq(a: bytes, b: bytes) -> bool:
11
+ if not isinstance(a, bytes) or not isinstance(b, bytes):
12
+ raise TypeError("a and b must be bytes.")
13
+
14
+ return hmac.compare_digest(a, b)
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/hashes.py ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ import abc
8
+
9
+ from cryptography.hazmat.bindings._rust import openssl as rust_openssl
10
+
11
+ __all__ = [
12
+ "MD5",
13
+ "SHA1",
14
+ "SHA3_224",
15
+ "SHA3_256",
16
+ "SHA3_384",
17
+ "SHA3_512",
18
+ "SHA224",
19
+ "SHA256",
20
+ "SHA384",
21
+ "SHA512",
22
+ "SHA512_224",
23
+ "SHA512_256",
24
+ "SHAKE128",
25
+ "SHAKE256",
26
+ "SM3",
27
+ "BLAKE2b",
28
+ "BLAKE2s",
29
+ "ExtendableOutputFunction",
30
+ "Hash",
31
+ "HashAlgorithm",
32
+ "HashContext",
33
+ ]
34
+
35
+
36
+ class HashAlgorithm(metaclass=abc.ABCMeta):
37
+ @property
38
+ @abc.abstractmethod
39
+ def name(self) -> str:
40
+ """
41
+ A string naming this algorithm (e.g. "sha256", "md5").
42
+ """
43
+
44
+ @property
45
+ @abc.abstractmethod
46
+ def digest_size(self) -> int:
47
+ """
48
+ The size of the resulting digest in bytes.
49
+ """
50
+
51
+ @property
52
+ @abc.abstractmethod
53
+ def block_size(self) -> int | None:
54
+ """
55
+ The internal block size of the hash function, or None if the hash
56
+ function does not use blocks internally (e.g. SHA3).
57
+ """
58
+
59
+
60
+ class HashContext(metaclass=abc.ABCMeta):
61
+ @property
62
+ @abc.abstractmethod
63
+ def algorithm(self) -> HashAlgorithm:
64
+ """
65
+ A HashAlgorithm that will be used by this context.
66
+ """
67
+
68
+ @abc.abstractmethod
69
+ def update(self, data: bytes) -> None:
70
+ """
71
+ Processes the provided bytes through the hash.
72
+ """
73
+
74
+ @abc.abstractmethod
75
+ def finalize(self) -> bytes:
76
+ """
77
+ Finalizes the hash context and returns the hash digest as bytes.
78
+ """
79
+
80
+ @abc.abstractmethod
81
+ def copy(self) -> HashContext:
82
+ """
83
+ Return a HashContext that is a copy of the current context.
84
+ """
85
+
86
+
87
+ Hash = rust_openssl.hashes.Hash
88
+ HashContext.register(Hash)
89
+
90
+
91
+ class ExtendableOutputFunction(metaclass=abc.ABCMeta):
92
+ """
93
+ An interface for extendable output functions.
94
+ """
95
+
96
+
97
+ class SHA1(HashAlgorithm):
98
+ name = "sha1"
99
+ digest_size = 20
100
+ block_size = 64
101
+
102
+
103
+ class SHA512_224(HashAlgorithm): # noqa: N801
104
+ name = "sha512-224"
105
+ digest_size = 28
106
+ block_size = 128
107
+
108
+
109
+ class SHA512_256(HashAlgorithm): # noqa: N801
110
+ name = "sha512-256"
111
+ digest_size = 32
112
+ block_size = 128
113
+
114
+
115
+ class SHA224(HashAlgorithm):
116
+ name = "sha224"
117
+ digest_size = 28
118
+ block_size = 64
119
+
120
+
121
+ class SHA256(HashAlgorithm):
122
+ name = "sha256"
123
+ digest_size = 32
124
+ block_size = 64
125
+
126
+
127
+ class SHA384(HashAlgorithm):
128
+ name = "sha384"
129
+ digest_size = 48
130
+ block_size = 128
131
+
132
+
133
+ class SHA512(HashAlgorithm):
134
+ name = "sha512"
135
+ digest_size = 64
136
+ block_size = 128
137
+
138
+
139
+ class SHA3_224(HashAlgorithm): # noqa: N801
140
+ name = "sha3-224"
141
+ digest_size = 28
142
+ block_size = None
143
+
144
+
145
+ class SHA3_256(HashAlgorithm): # noqa: N801
146
+ name = "sha3-256"
147
+ digest_size = 32
148
+ block_size = None
149
+
150
+
151
+ class SHA3_384(HashAlgorithm): # noqa: N801
152
+ name = "sha3-384"
153
+ digest_size = 48
154
+ block_size = None
155
+
156
+
157
+ class SHA3_512(HashAlgorithm): # noqa: N801
158
+ name = "sha3-512"
159
+ digest_size = 64
160
+ block_size = None
161
+
162
+
163
+ class SHAKE128(HashAlgorithm, ExtendableOutputFunction):
164
+ name = "shake128"
165
+ block_size = None
166
+
167
+ def __init__(self, digest_size: int):
168
+ if not isinstance(digest_size, int):
169
+ raise TypeError("digest_size must be an integer")
170
+
171
+ if digest_size < 1:
172
+ raise ValueError("digest_size must be a positive integer")
173
+
174
+ self._digest_size = digest_size
175
+
176
+ @property
177
+ def digest_size(self) -> int:
178
+ return self._digest_size
179
+
180
+
181
+ class SHAKE256(HashAlgorithm, ExtendableOutputFunction):
182
+ name = "shake256"
183
+ block_size = None
184
+
185
+ def __init__(self, digest_size: int):
186
+ if not isinstance(digest_size, int):
187
+ raise TypeError("digest_size must be an integer")
188
+
189
+ if digest_size < 1:
190
+ raise ValueError("digest_size must be a positive integer")
191
+
192
+ self._digest_size = digest_size
193
+
194
+ @property
195
+ def digest_size(self) -> int:
196
+ return self._digest_size
197
+
198
+
199
+ class MD5(HashAlgorithm):
200
+ name = "md5"
201
+ digest_size = 16
202
+ block_size = 64
203
+
204
+
205
+ class BLAKE2b(HashAlgorithm):
206
+ name = "blake2b"
207
+ _max_digest_size = 64
208
+ _min_digest_size = 1
209
+ block_size = 128
210
+
211
+ def __init__(self, digest_size: int):
212
+ if digest_size != 64:
213
+ raise ValueError("Digest size must be 64")
214
+
215
+ self._digest_size = digest_size
216
+
217
+ @property
218
+ def digest_size(self) -> int:
219
+ return self._digest_size
220
+
221
+
222
+ class BLAKE2s(HashAlgorithm):
223
+ name = "blake2s"
224
+ block_size = 64
225
+ _max_digest_size = 32
226
+ _min_digest_size = 1
227
+
228
+ def __init__(self, digest_size: int):
229
+ if digest_size != 32:
230
+ raise ValueError("Digest size must be 32")
231
+
232
+ self._digest_size = digest_size
233
+
234
+ @property
235
+ def digest_size(self) -> int:
236
+ return self._digest_size
237
+
238
+
239
+ class SM3(HashAlgorithm):
240
+ name = "sm3"
241
+ digest_size = 32
242
+ block_size = 64
.venv/lib/python3.11/site-packages/cryptography/hazmat/primitives/hmac.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from __future__ import annotations
6
+
7
+ from cryptography.hazmat.bindings._rust import openssl as rust_openssl
8
+ from cryptography.hazmat.primitives import hashes
9
+
10
+ __all__ = ["HMAC"]
11
+
12
+ HMAC = rust_openssl.hmac.HMAC
13
+ hashes.HashContext.register(HMAC)