We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
KDF Interfaces
Who has opinions? This is relevant for HKDF in #490 and upcoming PBKDF2.

Here's a straw man to knock down:

``` python
# This API is a bit challenging since each KDF has different features 
# (salt/no salt, maximum time, output length, iteration count, etc)

kdf = PBKDF2(iterations, digest, backend)
key = kdf.derive("key/password", "salt")
kdf.verify("key/password", salt="salt", key)

kdf = HKDF(algorithm, key_length, info, backend)
key = kdf.derive("key/password", "salt")
kdf.verify("key/password", salt="salt", key)

kdf = BCrypt(work_factor=100, backend)
key = kdf.derive("key/password")
kdf.verify("key/password", key)

kdf = SCrypt(key_length, salt_size=16, max_time=0.1, max_mem=4, backend)
key = kdf.derive("key/password") # really need to get key/salt out since auto-generated
kdf.verify("key/password", key)
```

There are also calibration routines available for some of these KDFs. (scrypt has one as well as CommonCrypto's `CCCalibratePBKDF` for PBKDF2).


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `cryptography/hazmat/primitives/interfaces.py`
Content:
```
1 # Licensed under the Apache License, Version 2.0 (the "License");
2 # you may not use this file except in compliance with the License.
3 # You may obtain a copy of the License at
4 #
5 #    http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
10 # implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13 
14 from __future__ import absolute_import, division, print_function
15 
16 import abc
17 
18 import six
19 
20 
21 class CipherAlgorithm(six.with_metaclass(abc.ABCMeta)):
22     @abc.abstractproperty
23     def name(self):
24         """
25         A string naming this mode (e.g. "AES", "Camellia").
26         """
27 
28     @abc.abstractproperty
29     def key_size(self):
30         """
31         The size of the key being used as an integer in bits (e.g. 128, 256).
32         """
33 
34 
35 class BlockCipherAlgorithm(six.with_metaclass(abc.ABCMeta)):
36     @abc.abstractproperty
37     def block_size(self):
38         """
39         The size of a block as an integer in bits (e.g. 64, 128).
40         """
41 
42 
43 class Mode(six.with_metaclass(abc.ABCMeta)):
44     @abc.abstractproperty
45     def name(self):
46         """
47         A string naming this mode (e.g. "ECB", "CBC").
48         """
49 
50     @abc.abstractmethod
51     def validate_for_algorithm(self, algorithm):
52         """
53         Checks that all the necessary invariants of this (mode, algorithm)
54         combination are met.
55         """
56 
57 
58 class ModeWithInitializationVector(six.with_metaclass(abc.ABCMeta)):
59     @abc.abstractproperty
60     def initialization_vector(self):
61         """
62         The value of the initialization vector for this mode as bytes.
63         """
64 
65 
66 class ModeWithNonce(six.with_metaclass(abc.ABCMeta)):
67     @abc.abstractproperty
68     def nonce(self):
69         """
70         The value of the nonce for this mode as bytes.
71         """
72 
73 
74 class ModeWithAuthenticationTag(six.with_metaclass(abc.ABCMeta)):
75     @abc.abstractproperty
76     def tag(self):
77         """
78         The value of the tag supplied to the constructor of this mode.
79         """
80 
81 
82 class CipherContext(six.with_metaclass(abc.ABCMeta)):
83     @abc.abstractmethod
84     def update(self, data):
85         """
86         Processes the provided bytes through the cipher and returns the results
87         as bytes.
88         """
89 
90     @abc.abstractmethod
91     def finalize(self):
92         """
93         Returns the results of processing the final block as bytes.
94         """
95 
96 
97 class AEADCipherContext(six.with_metaclass(abc.ABCMeta)):
98     @abc.abstractmethod
99     def authenticate_additional_data(self, data):
100         """
101         Authenticates the provided bytes.
102         """
103 
104 
105 class AEADEncryptionContext(six.with_metaclass(abc.ABCMeta)):
106     @abc.abstractproperty
107     def tag(self):
108         """
109         Returns tag bytes. This is only available after encryption is
110         finalized.
111         """
112 
113 
114 class PaddingContext(six.with_metaclass(abc.ABCMeta)):
115     @abc.abstractmethod
116     def update(self, data):
117         """
118         Pads the provided bytes and returns any available data as bytes.
119         """
120 
121     @abc.abstractmethod
122     def finalize(self):
123         """
124         Finalize the padding, returns bytes.
125         """
126 
127 
128 class HashAlgorithm(six.with_metaclass(abc.ABCMeta)):
129     @abc.abstractproperty
130     def name(self):
131         """
132         A string naming this algorithm (e.g. "sha256", "md5").
133         """
134 
135     @abc.abstractproperty
136     def digest_size(self):
137         """
138         The size of the resulting digest in bytes.
139         """
140 
141     @abc.abstractproperty
142     def block_size(self):
143         """
144         The internal block size of the hash algorithm in bytes.
145         """
146 
147 
148 class HashContext(six.with_metaclass(abc.ABCMeta)):
149     @abc.abstractproperty
150     def algorithm(self):
151         """
152         A HashAlgorithm that will be used by this context.
153         """
154 
155     @abc.abstractmethod
156     def update(self, data):
157         """
158         Processes the provided bytes through the hash.
159         """
160 
161     @abc.abstractmethod
162     def finalize(self):
163         """
164         Finalizes the hash context and returns the hash digest as bytes.
165         """
166 
167     @abc.abstractmethod
168     def copy(self):
169         """
170         Return a HashContext that is a copy of the current context.
171         """
172 
173 
174 class RSAPrivateKey(six.with_metaclass(abc.ABCMeta)):
175     @abc.abstractproperty
176     def modulus(self):
177         """
178         The public modulus of the RSA key.
179         """
180 
181     @abc.abstractproperty
182     def public_exponent(self):
183         """
184         The public exponent of the RSA key.
185         """
186 
187     @abc.abstractproperty
188     def key_length(self):
189         """
190         The bit length of the public modulus.
191         """
192 
193     @abc.abstractmethod
194     def public_key(self):
195         """
196         The RSAPublicKey associated with this private key.
197         """
198 
199     @abc.abstractproperty
200     def n(self):
201         """
202         The public modulus of the RSA key. Alias for modulus.
203         """
204 
205     @abc.abstractproperty
206     def p(self):
207         """
208         One of the two primes used to generate d.
209         """
210 
211     @abc.abstractproperty
212     def q(self):
213         """
214         One of the two primes used to generate d.
215         """
216 
217     @abc.abstractproperty
218     def d(self):
219         """
220         The private exponent. This can be calculated using p and q.
221         """
222 
223     @abc.abstractproperty
224     def e(self):
225         """
226         The public exponent of the RSA key. Alias for public_exponent.
227         """
228 
229 
230 class RSAPublicKey(six.with_metaclass(abc.ABCMeta)):
231     @abc.abstractproperty
232     def modulus(self):
233         """
234         The public modulus of the RSA key.
235         """
236 
237     @abc.abstractproperty
238     def public_exponent(self):
239         """
240         The public exponent of the RSA key.
241         """
242 
243     @abc.abstractproperty
244     def key_length(self):
245         """
246         The bit length of the public modulus.
247         """
248 
249     @abc.abstractproperty
250     def n(self):
251         """
252         The public modulus of the RSA key. Alias for modulus.
253         """
254 
255     @abc.abstractproperty
256     def e(self):
257         """
258         The public exponent of the RSA key. Alias for public_exponent.
259         """
260
```

Path: `cryptography/exceptions.py`
Content:
```
1 # Licensed under the Apache License, Version 2.0 (the "License");
2 # you may not use this file except in compliance with the License.
3 # You may obtain a copy of the License at
4 #
5 #    http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
10 # implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13 
14 
15 class UnsupportedAlgorithm(Exception):
16     pass
17 
18 
19 class AlreadyFinalized(Exception):
20     pass
21 
22 
23 class AlreadyUpdated(Exception):
24     pass
25 
26 
27 class NotYetFinalized(Exception):
28     pass
29 
30 
31 class InvalidTag(Exception):
32     pass
33 
34 
35 class InvalidSignature(Exception):
36     pass
37 
38 
39 class InternalError(Exception):
40     pass
41
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/cryptography/exceptions.py b/cryptography/exceptions.py
--- a/cryptography/exceptions.py
+++ b/cryptography/exceptions.py
@@ -38,3 +38,7 @@
 
 class InternalError(Exception):
     pass
+
+
+class InvalidKey(Exception):
+    pass
diff --git a/cryptography/hazmat/primitives/interfaces.py b/cryptography/hazmat/primitives/interfaces.py
--- a/cryptography/hazmat/primitives/interfaces.py
+++ b/cryptography/hazmat/primitives/interfaces.py
@@ -257,3 +257,19 @@
         """
         The public exponent of the RSA key. Alias for public_exponent.
         """
+
+
+class KeyDerivationFunction(six.with_metaclass(abc.ABCMeta)):
+    @abc.abstractmethod
+    def derive(self, key_material):
+        """
+        Deterministically generates and returns a new key based on the existing
+        key material.
+        """
+
+    @abc.abstractmethod
+    def verify(self, key_material, expected_key):
+        """
+        Checks whether the key generated by the key material matches the
+        expected derived key. Raises an exception if they do not match.
+        """

{"golden_diff": "diff --git a/cryptography/exceptions.py b/cryptography/exceptions.py\n--- a/cryptography/exceptions.py\n+++ b/cryptography/exceptions.py\n@@ -38,3 +38,7 @@\n \n class InternalError(Exception):\n     pass\n+\n+\n+class InvalidKey(Exception):\n+    pass\ndiff --git a/cryptography/hazmat/primitives/interfaces.py b/cryptography/hazmat/primitives/interfaces.py\n--- a/cryptography/hazmat/primitives/interfaces.py\n+++ b/cryptography/hazmat/primitives/interfaces.py\n@@ -257,3 +257,19 @@\n         \"\"\"\n         The public exponent of the RSA key. Alias for public_exponent.\n         \"\"\"\n+\n+\n+class KeyDerivationFunction(six.with_metaclass(abc.ABCMeta)):\n+    @abc.abstractmethod\n+    def derive(self, key_material):\n+        \"\"\"\n+        Deterministically generates and returns a new key based on the existing\n+        key material.\n+        \"\"\"\n+\n+    @abc.abstractmethod\n+    def verify(self, key_material, expected_key):\n+        \"\"\"\n+        Checks whether the key generated by the key material matches the\n+        expected derived key. Raises an exception if they do not match.\n+        \"\"\"\n", "issue": "KDF Interfaces\nWho has opinions? This is relevant for HKDF in #490 and upcoming PBKDF2.\n\nHere's a straw man to knock down:\n\n``` python\n# This API is a bit challenging since each KDF has different features \n# (salt/no salt, maximum time, output length, iteration count, etc)\n\nkdf = PBKDF2(iterations, digest, backend)\nkey = kdf.derive(\"key/password\", \"salt\")\nkdf.verify(\"key/password\", salt=\"salt\", key)\n\nkdf = HKDF(algorithm, key_length, info, backend)\nkey = kdf.derive(\"key/password\", \"salt\")\nkdf.verify(\"key/password\", salt=\"salt\", key)\n\nkdf = BCrypt(work_factor=100, backend)\nkey = kdf.derive(\"key/password\")\nkdf.verify(\"key/password\", key)\n\nkdf = SCrypt(key_length, salt_size=16, max_time=0.1, max_mem=4, backend)\nkey = kdf.derive(\"key/password\") # really need to get key/salt out since auto-generated\nkdf.verify(\"key/password\", key)\n```\n\nThere are also calibration routines available for some of these KDFs. (scrypt has one as well as CommonCrypto's `CCCalibratePBKDF` for PBKDF2).\n\n", "before_files": [{"content": "# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n# implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom __future__ import absolute_import, division, print_function\n\nimport abc\n\nimport six\n\n\nclass CipherAlgorithm(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def name(self):\n        \"\"\"\n        A string naming this mode (e.g. \"AES\", \"Camellia\").\n        \"\"\"\n\n    @abc.abstractproperty\n    def key_size(self):\n        \"\"\"\n        The size of the key being used as an integer in bits (e.g. 128, 256).\n        \"\"\"\n\n\nclass BlockCipherAlgorithm(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def block_size(self):\n        \"\"\"\n        The size of a block as an integer in bits (e.g. 64, 128).\n        \"\"\"\n\n\nclass Mode(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def name(self):\n        \"\"\"\n        A string naming this mode (e.g. \"ECB\", \"CBC\").\n        \"\"\"\n\n    @abc.abstractmethod\n    def validate_for_algorithm(self, algorithm):\n        \"\"\"\n        Checks that all the necessary invariants of this (mode, algorithm)\n        combination are met.\n        \"\"\"\n\n\nclass ModeWithInitializationVector(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def initialization_vector(self):\n        \"\"\"\n        The value of the initialization vector for this mode as bytes.\n        \"\"\"\n\n\nclass ModeWithNonce(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def nonce(self):\n        \"\"\"\n        The value of the nonce for this mode as bytes.\n        \"\"\"\n\n\nclass ModeWithAuthenticationTag(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def tag(self):\n        \"\"\"\n        The value of the tag supplied to the constructor of this mode.\n        \"\"\"\n\n\nclass CipherContext(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractmethod\n    def update(self, data):\n        \"\"\"\n        Processes the provided bytes through the cipher and returns the results\n        as bytes.\n        \"\"\"\n\n    @abc.abstractmethod\n    def finalize(self):\n        \"\"\"\n        Returns the results of processing the final block as bytes.\n        \"\"\"\n\n\nclass AEADCipherContext(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractmethod\n    def authenticate_additional_data(self, data):\n        \"\"\"\n        Authenticates the provided bytes.\n        \"\"\"\n\n\nclass AEADEncryptionContext(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def tag(self):\n        \"\"\"\n        Returns tag bytes. This is only available after encryption is\n        finalized.\n        \"\"\"\n\n\nclass PaddingContext(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractmethod\n    def update(self, data):\n        \"\"\"\n        Pads the provided bytes and returns any available data as bytes.\n        \"\"\"\n\n    @abc.abstractmethod\n    def finalize(self):\n        \"\"\"\n        Finalize the padding, returns bytes.\n        \"\"\"\n\n\nclass HashAlgorithm(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def name(self):\n        \"\"\"\n        A string naming this algorithm (e.g. \"sha256\", \"md5\").\n        \"\"\"\n\n    @abc.abstractproperty\n    def digest_size(self):\n        \"\"\"\n        The size of the resulting digest in bytes.\n        \"\"\"\n\n    @abc.abstractproperty\n    def block_size(self):\n        \"\"\"\n        The internal block size of the hash algorithm in bytes.\n        \"\"\"\n\n\nclass HashContext(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def algorithm(self):\n        \"\"\"\n        A HashAlgorithm that will be used by this context.\n        \"\"\"\n\n    @abc.abstractmethod\n    def update(self, data):\n        \"\"\"\n        Processes the provided bytes through the hash.\n        \"\"\"\n\n    @abc.abstractmethod\n    def finalize(self):\n        \"\"\"\n        Finalizes the hash context and returns the hash digest as bytes.\n        \"\"\"\n\n    @abc.abstractmethod\n    def copy(self):\n        \"\"\"\n        Return a HashContext that is a copy of the current context.\n        \"\"\"\n\n\nclass RSAPrivateKey(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def modulus(self):\n        \"\"\"\n        The public modulus of the RSA key.\n        \"\"\"\n\n    @abc.abstractproperty\n    def public_exponent(self):\n        \"\"\"\n        The public exponent of the RSA key.\n        \"\"\"\n\n    @abc.abstractproperty\n    def key_length(self):\n        \"\"\"\n        The bit length of the public modulus.\n        \"\"\"\n\n    @abc.abstractmethod\n    def public_key(self):\n        \"\"\"\n        The RSAPublicKey associated with this private key.\n        \"\"\"\n\n    @abc.abstractproperty\n    def n(self):\n        \"\"\"\n        The public modulus of the RSA key. Alias for modulus.\n        \"\"\"\n\n    @abc.abstractproperty\n    def p(self):\n        \"\"\"\n        One of the two primes used to generate d.\n        \"\"\"\n\n    @abc.abstractproperty\n    def q(self):\n        \"\"\"\n        One of the two primes used to generate d.\n        \"\"\"\n\n    @abc.abstractproperty\n    def d(self):\n        \"\"\"\n        The private exponent. This can be calculated using p and q.\n        \"\"\"\n\n    @abc.abstractproperty\n    def e(self):\n        \"\"\"\n        The public exponent of the RSA key. Alias for public_exponent.\n        \"\"\"\n\n\nclass RSAPublicKey(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def modulus(self):\n        \"\"\"\n        The public modulus of the RSA key.\n        \"\"\"\n\n    @abc.abstractproperty\n    def public_exponent(self):\n        \"\"\"\n        The public exponent of the RSA key.\n        \"\"\"\n\n    @abc.abstractproperty\n    def key_length(self):\n        \"\"\"\n        The bit length of the public modulus.\n        \"\"\"\n\n    @abc.abstractproperty\n    def n(self):\n        \"\"\"\n        The public modulus of the RSA key. Alias for modulus.\n        \"\"\"\n\n    @abc.abstractproperty\n    def e(self):\n        \"\"\"\n        The public exponent of the RSA key. Alias for public_exponent.\n        \"\"\"\n", "path": "cryptography/hazmat/primitives/interfaces.py"}, {"content": "# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n# implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\nclass UnsupportedAlgorithm(Exception):\n    pass\n\n\nclass AlreadyFinalized(Exception):\n    pass\n\n\nclass AlreadyUpdated(Exception):\n    pass\n\n\nclass NotYetFinalized(Exception):\n    pass\n\n\nclass InvalidTag(Exception):\n    pass\n\n\nclass InvalidSignature(Exception):\n    pass\n\n\nclass InternalError(Exception):\n    pass\n", "path": "cryptography/exceptions.py"}], "after_files": [{"content": "# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n# implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom __future__ import absolute_import, division, print_function\n\nimport abc\n\nimport six\n\n\nclass CipherAlgorithm(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def name(self):\n        \"\"\"\n        A string naming this mode (e.g. \"AES\", \"Camellia\").\n        \"\"\"\n\n    @abc.abstractproperty\n    def key_size(self):\n        \"\"\"\n        The size of the key being used as an integer in bits (e.g. 128, 256).\n        \"\"\"\n\n\nclass BlockCipherAlgorithm(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def block_size(self):\n        \"\"\"\n        The size of a block as an integer in bits (e.g. 64, 128).\n        \"\"\"\n\n\nclass Mode(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def name(self):\n        \"\"\"\n        A string naming this mode (e.g. \"ECB\", \"CBC\").\n        \"\"\"\n\n    @abc.abstractmethod\n    def validate_for_algorithm(self, algorithm):\n        \"\"\"\n        Checks that all the necessary invariants of this (mode, algorithm)\n        combination are met.\n        \"\"\"\n\n\nclass ModeWithInitializationVector(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def initialization_vector(self):\n        \"\"\"\n        The value of the initialization vector for this mode as bytes.\n        \"\"\"\n\n\nclass ModeWithNonce(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def nonce(self):\n        \"\"\"\n        The value of the nonce for this mode as bytes.\n        \"\"\"\n\n\nclass ModeWithAuthenticationTag(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def tag(self):\n        \"\"\"\n        The value of the tag supplied to the constructor of this mode.\n        \"\"\"\n\n\nclass CipherContext(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractmethod\n    def update(self, data):\n        \"\"\"\n        Processes the provided bytes through the cipher and returns the results\n        as bytes.\n        \"\"\"\n\n    @abc.abstractmethod\n    def finalize(self):\n        \"\"\"\n        Returns the results of processing the final block as bytes.\n        \"\"\"\n\n\nclass AEADCipherContext(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractmethod\n    def authenticate_additional_data(self, data):\n        \"\"\"\n        Authenticates the provided bytes.\n        \"\"\"\n\n\nclass AEADEncryptionContext(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def tag(self):\n        \"\"\"\n        Returns tag bytes. This is only available after encryption is\n        finalized.\n        \"\"\"\n\n\nclass PaddingContext(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractmethod\n    def update(self, data):\n        \"\"\"\n        Pads the provided bytes and returns any available data as bytes.\n        \"\"\"\n\n    @abc.abstractmethod\n    def finalize(self):\n        \"\"\"\n        Finalize the padding, returns bytes.\n        \"\"\"\n\n\nclass HashAlgorithm(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def name(self):\n        \"\"\"\n        A string naming this algorithm (e.g. \"sha256\", \"md5\").\n        \"\"\"\n\n    @abc.abstractproperty\n    def digest_size(self):\n        \"\"\"\n        The size of the resulting digest in bytes.\n        \"\"\"\n\n    @abc.abstractproperty\n    def block_size(self):\n        \"\"\"\n        The internal block size of the hash algorithm in bytes.\n        \"\"\"\n\n\nclass HashContext(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def algorithm(self):\n        \"\"\"\n        A HashAlgorithm that will be used by this context.\n        \"\"\"\n\n    @abc.abstractmethod\n    def update(self, data):\n        \"\"\"\n        Processes the provided bytes through the hash.\n        \"\"\"\n\n    @abc.abstractmethod\n    def finalize(self):\n        \"\"\"\n        Finalizes the hash context and returns the hash digest as bytes.\n        \"\"\"\n\n    @abc.abstractmethod\n    def copy(self):\n        \"\"\"\n        Return a HashContext that is a copy of the current context.\n        \"\"\"\n\n\nclass RSAPrivateKey(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def modulus(self):\n        \"\"\"\n        The public modulus of the RSA key.\n        \"\"\"\n\n    @abc.abstractproperty\n    def public_exponent(self):\n        \"\"\"\n        The public exponent of the RSA key.\n        \"\"\"\n\n    @abc.abstractproperty\n    def key_length(self):\n        \"\"\"\n        The bit length of the public modulus.\n        \"\"\"\n\n    @abc.abstractmethod\n    def public_key(self):\n        \"\"\"\n        The RSAPublicKey associated with this private key.\n        \"\"\"\n\n    @abc.abstractproperty\n    def n(self):\n        \"\"\"\n        The public modulus of the RSA key. Alias for modulus.\n        \"\"\"\n\n    @abc.abstractproperty\n    def p(self):\n        \"\"\"\n        One of the two primes used to generate d.\n        \"\"\"\n\n    @abc.abstractproperty\n    def q(self):\n        \"\"\"\n        One of the two primes used to generate d.\n        \"\"\"\n\n    @abc.abstractproperty\n    def d(self):\n        \"\"\"\n        The private exponent. This can be calculated using p and q.\n        \"\"\"\n\n    @abc.abstractproperty\n    def e(self):\n        \"\"\"\n        The public exponent of the RSA key. Alias for public_exponent.\n        \"\"\"\n\n\nclass RSAPublicKey(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractproperty\n    def modulus(self):\n        \"\"\"\n        The public modulus of the RSA key.\n        \"\"\"\n\n    @abc.abstractproperty\n    def public_exponent(self):\n        \"\"\"\n        The public exponent of the RSA key.\n        \"\"\"\n\n    @abc.abstractproperty\n    def key_length(self):\n        \"\"\"\n        The bit length of the public modulus.\n        \"\"\"\n\n    @abc.abstractproperty\n    def n(self):\n        \"\"\"\n        The public modulus of the RSA key. Alias for modulus.\n        \"\"\"\n\n    @abc.abstractproperty\n    def e(self):\n        \"\"\"\n        The public exponent of the RSA key. Alias for public_exponent.\n        \"\"\"\n\n\nclass KeyDerivationFunction(six.with_metaclass(abc.ABCMeta)):\n    @abc.abstractmethod\n    def derive(self, key_material):\n        \"\"\"\n        Deterministically generates and returns a new key based on the existing\n        key material.\n        \"\"\"\n\n    @abc.abstractmethod\n    def verify(self, key_material, expected_key):\n        \"\"\"\n        Checks whether the key generated by the key material matches the\n        expected derived key. Raises an exception if they do not match.\n        \"\"\"\n", "path": "cryptography/hazmat/primitives/interfaces.py"}, {"content": "# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n# implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\nclass UnsupportedAlgorithm(Exception):\n    pass\n\n\nclass AlreadyFinalized(Exception):\n    pass\n\n\nclass AlreadyUpdated(Exception):\n    pass\n\n\nclass NotYetFinalized(Exception):\n    pass\n\n\nclass InvalidTag(Exception):\n    pass\n\n\nclass InvalidSignature(Exception):\n    pass\n\n\nclass InternalError(Exception):\n    pass\n\n\nclass InvalidKey(Exception):\n    pass\n", "path": "cryptography/exceptions.py"}]}