blob: 942a359c58ce5253494c4088347d3654dfaa3378 [file] [log] [blame]
David Reid2a746ce2013-11-15 15:32:14 -08001.. hazmat::
2
Alex Stapletonc5fffd32014-03-18 15:29:00 +00003Backend interfaces
David Reid2a746ce2013-11-15 15:32:14 -08004==================
5
Alex Gaynorf8796b12013-12-13 20:28:55 -08006.. currentmodule:: cryptography.hazmat.backends.interfaces
David Reid2a746ce2013-11-15 15:32:14 -08007
8
Alex Gaynor969f18e2014-05-17 20:07:35 -07009Backend implementations may provide a number of interfaces to support
10operations such as :doc:`/hazmat/primitives/symmetric-encryption`,
David Reid6b9df812013-11-18 14:13:02 -080011:doc:`/hazmat/primitives/cryptographic-hashes`, and
Ayrxfa4a6b22014-04-16 23:03:14 +080012:doc:`/hazmat/primitives/mac/hmac`.
David Reid6b9df812013-11-18 14:13:02 -080013
14A specific ``backend`` may provide one or more of these interfaces.
15
16
David Reid2a746ce2013-11-15 15:32:14 -080017.. class:: CipherBackend
18
Alex Stapleton63b3de22014-02-08 09:43:16 +000019 A backend that provides methods for using ciphers for encryption
David Reid5973f4c2013-11-18 11:29:44 -080020 and decryption.
21
Alex Gaynor585c99c2014-02-04 16:10:10 -080022 The following backends implement this interface:
23
24 * :doc:`/hazmat/backends/openssl`
25 * :doc:`/hazmat/backends/commoncrypto`
26
David Reid2a746ce2013-11-15 15:32:14 -080027 .. method:: cipher_supported(cipher, mode)
28
David Reid5973f4c2013-11-18 11:29:44 -080029 Check if a ``cipher`` and ``mode`` combination is supported by
30 this backend.
31
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -030032 :param cipher: An instance of
33 :class:`~cryptography.hazmat.primitives.ciphers.CipherAlgorithm`.
34
35 :param mode: An instance of
36 :class:`~cryptography.hazmat.primitives.ciphers.modes.Mode`.
David Reid5973f4c2013-11-18 11:29:44 -080037
38 :returns: ``True`` if the specified ``cipher`` and ``mode`` combination
39 is supported by this backend, otherwise ``False``
David Reid2a746ce2013-11-15 15:32:14 -080040
David Reid2a746ce2013-11-15 15:32:14 -080041
42 .. method:: create_symmetric_encryption_ctx(cipher, mode)
43
David Reid5973f4c2013-11-18 11:29:44 -080044 Create a
Paul Kehrer7c5c9fe2015-02-14 10:27:14 -060045 :class:`~cryptography.hazmat.primitives.ciphers.CipherContext` that
David Reid5973f4c2013-11-18 11:29:44 -080046 can be used for encrypting data with the symmetric ``cipher`` using
47 the given ``mode``.
48
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -030049 :param cipher: An instance of
50 :class:`~cryptography.hazmat.primitives.ciphers.CipherAlgorithm`.
51
52 :param mode: An instance of
53 :class:`~cryptography.hazmat.primitives.ciphers.modes.Mode`.
David Reid5973f4c2013-11-18 11:29:44 -080054
55 :returns:
Paul Kehrer7c5c9fe2015-02-14 10:27:14 -060056 :class:`~cryptography.hazmat.primitives.ciphers.CipherContext`
David Reid5973f4c2013-11-18 11:29:44 -080057
Paul Kehrera07925a2013-12-06 11:49:42 -060058 :raises ValueError: When tag is not None in an AEAD mode
59
David Reid2a746ce2013-11-15 15:32:14 -080060
61 .. method:: create_symmetric_decryption_ctx(cipher, mode)
62
David Reid5973f4c2013-11-18 11:29:44 -080063 Create a
Paul Kehrer7c5c9fe2015-02-14 10:27:14 -060064 :class:`~cryptography.hazmat.primitives.ciphers.CipherContext` that
David Reid5973f4c2013-11-18 11:29:44 -080065 can be used for decrypting data with the symmetric ``cipher`` using
66 the given ``mode``.
67
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -030068 :param cipher: An instance of
69 :class:`~cryptography.hazmat.primitives.ciphers.CipherAlgorithm`.
70
71 :param mode: An instance of
72 :class:`~cryptography.hazmat.primitives.ciphers.modes.Mode`.
David Reid5973f4c2013-11-18 11:29:44 -080073
74 :returns:
Paul Kehrer7c5c9fe2015-02-14 10:27:14 -060075 :class:`~cryptography.hazmat.primitives.ciphers.CipherContext`
David Reid2a746ce2013-11-15 15:32:14 -080076
Paul Kehrera07925a2013-12-06 11:49:42 -060077 :raises ValueError: When tag is None in an AEAD mode
78
David Reid2a746ce2013-11-15 15:32:14 -080079
80.. class:: HashBackend
81
David Reid5973f4c2013-11-18 11:29:44 -080082 A backend with methods for using cryptographic hash functions.
83
Alex Gaynor585c99c2014-02-04 16:10:10 -080084 The following backends implement this interface:
85
86 * :doc:`/hazmat/backends/openssl`
87 * :doc:`/hazmat/backends/commoncrypto`
88
David Reid2a746ce2013-11-15 15:32:14 -080089 .. method:: hash_supported(algorithm)
90
David Reid6624a442013-11-18 12:44:30 -080091 Check if the specified ``algorithm`` is supported by this backend.
92
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -030093 :param algorithm: An instance of
94 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`.
David Reid5973f4c2013-11-18 11:29:44 -080095
96 :returns: ``True`` if the specified ``algorithm`` is supported by this
97 backend, otherwise ``False``.
98
David Reid2a746ce2013-11-15 15:32:14 -080099
100 .. method:: create_hash_ctx(algorithm)
101
David Reid6624a442013-11-18 12:44:30 -0800102 Create a
Paul Kehrer601278a2015-02-12 12:51:00 -0600103 :class:`~cryptography.hazmat.primitives.hashes.HashContext` that
David Reid6624a442013-11-18 12:44:30 -0800104 uses the specified ``algorithm`` to calculate a message digest.
105
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300106 :param algorithm: An instance of
107 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`.
David Reid5973f4c2013-11-18 11:29:44 -0800108
109 :returns:
Paul Kehrer601278a2015-02-12 12:51:00 -0600110 :class:`~cryptography.hazmat.primitives.hashes.HashContext`
David Reid2a746ce2013-11-15 15:32:14 -0800111
112
113.. class:: HMACBackend
114
David Reid5973f4c2013-11-18 11:29:44 -0800115 A backend with methods for using cryptographic hash functions as message
116 authentication codes.
117
Alex Gaynor585c99c2014-02-04 16:10:10 -0800118 The following backends implement this interface:
119
120 * :doc:`/hazmat/backends/openssl`
121 * :doc:`/hazmat/backends/commoncrypto`
122
Paul Kehrer90ae8662013-12-23 17:21:00 -0600123 .. method:: hmac_supported(algorithm)
124
125 Check if the specified ``algorithm`` is supported by this backend.
126
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300127 :param algorithm: An instance of
128 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`.
Paul Kehrer90ae8662013-12-23 17:21:00 -0600129
130 :returns: ``True`` if the specified ``algorithm`` is supported for HMAC
131 by this backend, otherwise ``False``.
132
Alex Gaynorb80a5ab2016-01-30 16:24:19 -0500133 .. method:: create_hmac_ctx(key, algorithm)
David Reid2a746ce2013-11-15 15:32:14 -0800134
David Reid6624a442013-11-18 12:44:30 -0800135 Create a
Paul Kehrer601278a2015-02-12 12:51:00 -0600136 :class:`~cryptography.hazmat.primitives.hashes.HashContext` that
Paul Kehrer4f776c42013-12-23 17:25:54 -0600137 uses the specified ``algorithm`` to calculate a hash-based message
138 authentication code.
David Reid6624a442013-11-18 12:44:30 -0800139
Alex Gaynorb80a5ab2016-01-30 16:24:19 -0500140 :param bytes key: Secret key as ``bytes``.
141
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300142 :param algorithm: An instance of
143 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`.
David Reid5973f4c2013-11-18 11:29:44 -0800144
145 :returns:
Paul Kehrer601278a2015-02-12 12:51:00 -0600146 :class:`~cryptography.hazmat.primitives.hashes.HashContext`
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600147
148
Alexander Gaynora1f1afa2014-07-18 10:57:41 -0700149.. class:: CMACBackend
150
151 .. versionadded:: 0.4
152
153 A backend with methods for using CMAC
154
155 .. method:: cmac_algorithm_supported(algorithm)
156
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300157 :param algorithm: An instance of
158 :class:`~cryptography.hazmat.primitives.ciphers.BlockCipherAlgorithm`.
159
Alexander Gaynora1f1afa2014-07-18 10:57:41 -0700160 :return: Returns True if the block cipher is supported for CMAC by this backend
161
162 .. method:: create_cmac_ctx(algorithm)
163
164 Create a
Paul Kehrer891efd92015-03-09 09:25:22 -0500165 :class:`~cryptography.hazmat.primitives.interfaces.MACContext` that
Alexander Gaynora1f1afa2014-07-18 10:57:41 -0700166 uses the specified ``algorithm`` to calculate a message authentication code.
167
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300168 :param algorithm: An instance of
169 :class:`~cryptography.hazmat.primitives.ciphers.BlockCipherAlgorithm`.
Alexander Gaynora1f1afa2014-07-18 10:57:41 -0700170
171 :returns:
Paul Kehrer891efd92015-03-09 09:25:22 -0500172 :class:`~cryptography.hazmat.primitives.interfaces.MACContext`
Alexander Gaynora1f1afa2014-07-18 10:57:41 -0700173
174
Paul Kehrer98e40e62014-01-28 15:07:49 -0600175.. class:: PBKDF2HMACBackend
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600176
Paul Kehrer5d1af212014-01-28 12:19:32 -0600177 .. versionadded:: 0.2
178
Paul Kehrer98e40e62014-01-28 15:07:49 -0600179 A backend with methods for using PBKDF2 using HMAC as a PRF.
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600180
Alex Gaynor585c99c2014-02-04 16:10:10 -0800181 The following backends implement this interface:
182
183 * :doc:`/hazmat/backends/openssl`
184 * :doc:`/hazmat/backends/commoncrypto`
185
Paul Kehrer98e40e62014-01-28 15:07:49 -0600186 .. method:: pbkdf2_hmac_supported(algorithm)
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600187
188 Check if the specified ``algorithm`` is supported by this backend.
189
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300190 :param algorithm: An instance of
191 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`.
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600192
193 :returns: ``True`` if the specified ``algorithm`` is supported for
Paul Kehrer98e40e62014-01-28 15:07:49 -0600194 PBKDF2 HMAC by this backend, otherwise ``False``.
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600195
Alex Gaynor1cfc5d52014-11-23 17:44:28 -0600196 .. method:: derive_pbkdf2_hmac(self, algorithm, length, salt, iterations, key_material)
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600197
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300198 :param algorithm: An instance of
199 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`.
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600200
201 :param int length: The desired length of the derived key. Maximum is
Paul Kehrer98e40e62014-01-28 15:07:49 -0600202 (2\ :sup:`32` - 1) * ``algorithm.digest_size``
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600203
Paul Kehrerb6d764c2014-01-27 22:32:11 -0600204 :param bytes salt: A salt.
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600205
206 :param int iterations: The number of iterations to perform of the hash
Paul Kehrerc58b4782014-01-29 13:56:25 -0600207 function. This can be used to control the length of time the
208 operation takes. Higher numbers help mitigate brute force attacks
209 against derived keys.
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600210
211 :param bytes key_material: The key material to use as a basis for
212 the derived key. This is typically a password.
213
214 :return bytes: Derived key.
Alex Stapleton209a1322014-02-07 20:26:44 +0000215
216
217.. class:: RSABackend
218
219 .. versionadded:: 0.2
220
221 A backend with methods for using RSA.
222
Alex Stapletone009ad22014-02-08 17:23:46 +0000223 .. method:: generate_rsa_private_key(public_exponent, key_size)
Alex Stapleton209a1322014-02-07 20:26:44 +0000224
225 :param int public_exponent: The public exponent of the new key.
226 Often one of the small Fermat primes 3, 5, 17, 257 or 65537.
227
Alex Stapletone009ad22014-02-08 17:23:46 +0000228 :param int key_size: The length in bits of the modulus. Should be
Alex Stapleton209a1322014-02-07 20:26:44 +0000229 at least 2048.
230
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300231 :return: A new instance of
232 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`.
Alex Stapleton209a1322014-02-07 20:26:44 +0000233
234 :raises ValueError: If the public_exponent is not valid.
Paul Kehrer2b3f0fc2014-02-17 19:20:14 -0600235
Paul Kehrerc333dbc2014-05-24 18:35:02 -0500236 .. method:: rsa_padding_supported(padding)
237
238 Check if the specified ``padding`` is supported by the backend.
239
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300240 :param padding: An instance of
241 :class:`~cryptography.hazmat.primitives.asymmetric.padding.AsymmetricPadding`.
Paul Kehrerc333dbc2014-05-24 18:35:02 -0500242
243 :returns: ``True`` if the specified ``padding`` is supported by this
244 backend, otherwise ``False``.
245
Paul Kehrer342d2e42014-05-25 22:01:20 -0500246 .. method:: generate_rsa_parameters_supported(public_exponent, key_size)
247
248 Check if the specified parameters are supported for key generation by
249 the backend.
250
Paul Kehrer1b760f12014-05-26 08:54:38 -0500251 :param int public_exponent: The public exponent.
Paul Kehrer342d2e42014-05-25 22:01:20 -0500252
Paul Kehrer1b760f12014-05-26 08:54:38 -0500253 :param int key_size: The bit length of the generated modulus.
Paul Kehrer342d2e42014-05-25 22:01:20 -0500254
Alex Gaynor4922c452014-11-20 19:45:07 -0800255 .. method:: load_rsa_private_numbers(numbers)
David Reid68b509a2014-05-08 10:31:51 -0700256
257 :param numbers: An instance of
David Reida674afe2014-05-30 14:15:29 -0700258 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateNumbers`.
David Reid68b509a2014-05-08 10:31:51 -0700259
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300260 :returns: An instance of
Alex Stapletonf79c2312014-12-30 12:50:14 +0000261 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`.
David Reida674afe2014-05-30 14:15:29 -0700262
David Reidc57a3762014-06-03 13:27:50 -0700263 :raises ValueError: This is raised when the values of ``p``, ``q``,
264 ``private_exponent``, ``public_exponent``, or ``modulus`` do not
265 match the bounds specified in :rfc:`3447`.
266
Alex Gaynorfecf6442014-12-27 11:19:32 -0800267 :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised
268 when any backend specific criteria are not met.
David Reidda76ae02014-06-03 14:01:18 -0700269
Alex Gaynor4922c452014-11-20 19:45:07 -0800270 .. method:: load_rsa_public_numbers(numbers)
David Reida674afe2014-05-30 14:15:29 -0700271
272 :param numbers: An instance of
273 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateNumbers`.
274
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300275 :returns: An instance of
Alex Stapletonf79c2312014-12-30 12:50:14 +0000276 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`.
David Reid68b509a2014-05-08 10:31:51 -0700277
David Reidc57a3762014-06-03 13:27:50 -0700278 :raises ValueError: This is raised when the values of
279 ``public_exponent`` or ``modulus`` do not match the bounds
280 specified in :rfc:`3447`.
281
Alex Gaynorfecf6442014-12-27 11:19:32 -0800282 :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised
283 when any backend specific criteria are not met.
David Reidda76ae02014-06-03 14:01:18 -0700284
Alex Stapleton2fb76a32014-02-15 11:10:57 +0000285
Mohammed Attia29474ac2014-04-02 04:03:09 +0200286.. class:: DSABackend
287
288 .. versionadded:: 0.4
289
290 A backend with methods for using DSA.
291
292 .. method:: generate_dsa_parameters(key_size)
293
Alex Gaynorc9dc0a02014-04-24 13:38:12 -0700294 :param int key_size: The length of the modulus in bits. It should be
Alex Gaynor20c44042015-01-08 11:00:00 -0800295 either 1024, 2048 or 3072. For keys generated in 2015 this should
Mohammed Attia29474ac2014-04-02 04:03:09 +0200296 be at least 2048.
Alex Gaynorc9dc0a02014-04-24 13:38:12 -0700297 Note that some applications (such as SSH) have not yet gained
298 support for larger key sizes specified in FIPS 186-3 and are still
299 restricted to only the 1024-bit keys specified in FIPS 186-2.
Mohammed Attia29474ac2014-04-02 04:03:09 +0200300
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300301 :return: A new instance of
302 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameters`.
Mohammed Attia29474ac2014-04-02 04:03:09 +0200303
304 .. method:: generate_dsa_private_key(parameters)
305
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300306 :param parameters: An instance of
307 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameters`.
Mohammed Attia29474ac2014-04-02 04:03:09 +0200308
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300309 :return: A new instance of
310 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey`.
Mohammed Attia29474ac2014-04-02 04:03:09 +0200311
Alex Gaynor239d5182014-04-24 13:42:58 -0700312 :raises ValueError: This is raised if the key size is not one of 1024,
Alex Gaynora8f935b2016-06-26 13:25:59 -0400313 2048, or 3072.
Ayrx97a72fd2014-04-15 19:02:51 +0800314
Paul Kehrer298effd2014-06-27 14:07:59 -0600315 .. method:: generate_dsa_private_key_and_parameters(key_size)
316
317 :param int key_size: The length of the modulus in bits. It should be
Alex Gaynor20c44042015-01-08 11:00:00 -0800318 either 1024, 2048 or 3072. For keys generated in 2015 this should
Paul Kehrer298effd2014-06-27 14:07:59 -0600319 be at least 2048.
320 Note that some applications (such as SSH) have not yet gained
321 support for larger key sizes specified in FIPS 186-3 and are still
322 restricted to only the 1024-bit keys specified in FIPS 186-2.
323
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300324 :return: A new instance of
325 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey`.
Paul Kehrer298effd2014-06-27 14:07:59 -0600326
327 :raises ValueError: This is raised if the key size is not supported
328 by the backend.
329
Alex Gaynor4922c452014-11-20 19:45:07 -0800330 .. method:: dsa_hash_supported(algorithm)
Paul Kehrer43dc2762014-04-30 16:24:39 -0500331
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300332 :param algorithm: An instance of
333 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`.
Mohammed Attia59edb612014-04-25 22:44:40 +0200334
335 :returns: ``True`` if the specified ``algorithm`` is supported by this
336 backend, otherwise ``False``.
337
Alex Gaynor4922c452014-11-20 19:45:07 -0800338 .. method:: dsa_parameters_supported(p, q, g)
Paul Kehrerb4037872014-04-30 16:32:23 -0500339
340 :param int p: The p value of a DSA key.
341
342 :param int q: The q value of a DSA key.
343
Paul Kehrer21babbb2014-05-01 11:33:22 -0500344 :param int g: The g value of a DSA key.
345
346 :returns: ``True`` if the given values of ``p``, ``q``, and ``g`` are
347 supported by this backend, otherwise ``False``.
Paul Kehrerb4037872014-04-30 16:32:23 -0500348
Alex Gaynor4922c452014-11-20 19:45:07 -0800349 .. method:: load_dsa_parameter_numbers(numbers)
Paul Kehrer0739afc2014-06-22 12:06:18 -0600350
351 :param numbers: An instance of
352 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameterNumbers`.
353
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300354 :returns: An instance of
Alex Stapletonf48f69d2015-01-18 15:57:28 +0000355 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameters`.
Paul Kehrer0739afc2014-06-22 12:06:18 -0600356
Alex Gaynorfecf6442014-12-27 11:19:32 -0800357 :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised
358 when any backend specific criteria are not met.
Paul Kehrer0739afc2014-06-22 12:06:18 -0600359
Alex Gaynor4922c452014-11-20 19:45:07 -0800360 .. method:: load_dsa_private_numbers(numbers)
Paul Kehrer0739afc2014-06-22 12:06:18 -0600361
362 :param numbers: An instance of
363 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateNumbers`.
364
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300365 :returns: An instance of
Alex Stapletonf48f69d2015-01-18 15:57:28 +0000366 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey`.
Paul Kehrer0739afc2014-06-22 12:06:18 -0600367
Alex Gaynorfecf6442014-12-27 11:19:32 -0800368 :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised
369 when any backend specific criteria are not met.
Paul Kehrer0739afc2014-06-22 12:06:18 -0600370
Alex Gaynor4922c452014-11-20 19:45:07 -0800371 .. method:: load_dsa_public_numbers(numbers)
Paul Kehrer0739afc2014-06-22 12:06:18 -0600372
373 :param numbers: An instance of
374 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicNumbers`.
375
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300376 :returns: An instance of
Alex Stapletonf48f69d2015-01-18 15:57:28 +0000377 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`.
Paul Kehrer0739afc2014-06-22 12:06:18 -0600378
Alex Gaynorfecf6442014-12-27 11:19:32 -0800379 :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised
380 when any backend specific criteria are not met.
Paul Kehrer0739afc2014-06-22 12:06:18 -0600381
382
Alex Stapleton13f1d8d2014-05-17 16:50:11 +0100383.. class:: EllipticCurveBackend
384
385 .. versionadded:: 0.5
386
387 .. method:: elliptic_curve_supported(curve)
388
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300389 :param curve: An instance of
390 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve`.
Alex Stapleton13f1d8d2014-05-17 16:50:11 +0100391
392 :returns: True if the elliptic curve is supported by this backend.
393
394 .. method:: elliptic_curve_signature_algorithm_supported(signature_algorithm, curve)
395
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300396 :param signature_algorithm: An instance of
397 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurveSignatureAlgorithm`.
Alex Stapleton13f1d8d2014-05-17 16:50:11 +0100398
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300399 :param curve: An instance of
400 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve`.
Alex Stapleton13f1d8d2014-05-17 16:50:11 +0100401
402 :returns: True if the signature algorithm and curve are supported by this backend.
403
404 .. method:: generate_elliptic_curve_private_key(curve)
405
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300406 :param curve: An instance of
407 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve`.
Alex Stapleton13f1d8d2014-05-17 16:50:11 +0100408
Paul Kehrer77e95a02014-09-25 12:28:07 -0500409 .. method:: load_elliptic_curve_private_numbers(numbers)
Alex Stapleton13f1d8d2014-05-17 16:50:11 +0100410
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300411 :param numbers: An instance of
412 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateNumbers`.
Alex Stapleton13f1d8d2014-05-17 16:50:11 +0100413
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300414 :returns: An instance of
415 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`.
Alex Stapleton13f1d8d2014-05-17 16:50:11 +0100416
Paul Kehrer77e95a02014-09-25 12:28:07 -0500417 .. method:: load_elliptic_curve_public_numbers(numbers)
Alex Stapleton13f1d8d2014-05-17 16:50:11 +0100418
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300419 :param numbers: An instance of
420 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers`.
Alex Stapleton13f1d8d2014-05-17 16:50:11 +0100421
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300422 :returns: An instance of
423 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
Alexander Gaynora1f1afa2014-07-18 10:57:41 -0700424
Ofek Levc8167352016-11-11 10:54:00 -0500425 .. method:: derive_elliptic_curve_public_point(private_value, curve)
426
427 :param private_value: A secret scalar value.
428
429 :param curve: An instance of
430 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve`.
431
432 :returns: A tuple (x, y).
433
Alexander Gaynore0e95412014-07-19 10:58:50 -0700434.. class:: PEMSerializationBackend
435
436 .. versionadded:: 0.6
437
438 A backend with methods for working with any PEM encoded keys.
439
440 .. method:: load_pem_private_key(data, password)
441
442 :param bytes data: PEM data to load.
443 :param bytes password: The password to use if the data is encrypted.
Alex Gaynor99e61ea2014-09-08 10:26:40 -0700444 Should be ``None`` if the data is not encrypted.
Alexander Gaynore0e95412014-07-19 10:58:50 -0700445 :return: A new instance of the appropriate type of private key that the
446 serialized data contains.
447 :raises ValueError: If the data could not be deserialized.
448 :raises cryptography.exceptions.UnsupportedAlgorithm: If the data is
449 encrypted with an unsupported algorithm.
450
michael-hart801e8c12014-09-26 00:32:25 +0100451 .. method:: load_pem_public_key(data)
452
453 :param bytes data: PEM data to load.
Alex Gaynorb366f392014-09-29 11:07:05 -0700454 :return: A new instance of the appropriate type of public key
455 serialized data contains.
michael-hart801e8c12014-09-26 00:32:25 +0100456 :raises ValueError: If the data could not be deserialized.
457
Paul Kehrer76da86a2015-01-04 15:54:32 -0600458.. class:: DERSerializationBackend
459
460 .. versionadded:: 0.8
461
462 A backend with methods for working with DER encoded keys.
463
464 .. method:: load_der_private_key(data, password)
465
466 :param bytes data: DER data to load.
467 :param bytes password: The password to use if the data is encrypted.
468 Should be ``None`` if the data is not encrypted.
469 :return: A new instance of the appropriate type of private key that the
470 serialized data contains.
471 :raises ValueError: If the data could not be deserialized.
472 :raises cryptography.exceptions.UnsupportedAlgorithm: If the data is
473 encrypted with an unsupported algorithm.
474
475 .. method:: load_der_public_key(data)
476
477 :param bytes data: DER data to load.
478 :return: A new instance of the appropriate type of public key
479 serialized data contains.
480 :raises ValueError: If the data could not be deserialized.
481
Paul Kehrer6c4302e2014-11-24 09:20:38 -1000482.. class:: X509Backend
483
484 .. versionadded:: 0.7
485
486 A backend with methods for working with X.509 objects.
487
488 .. method:: load_pem_x509_certificate(data)
489
490 :param bytes data: PEM formatted certificate data.
491
Paul Kehrer13b6aff2015-02-12 14:05:44 -0600492 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer8473df62014-11-24 17:13:59 -1000493
494 .. method:: load_der_x509_certificate(data)
495
496 :param bytes data: DER formatted certificate data.
497
Paul Kehrer13b6aff2015-02-12 14:05:44 -0600498 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600499
Paul Kehrer31e39882015-03-11 11:37:04 -0500500 .. method:: load_pem_x509_csr(data)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600501
502 .. versionadded:: 0.9
503
Paul Kehrer7e007d52015-03-16 21:10:03 -0500504 :param bytes data: PEM formatted certificate signing request data.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600505
Paul Kehrera1a1f232015-03-15 15:34:35 -0500506 :returns: An instance of
507 :class:`~cryptography.x509.CertificateSigningRequest`.
Alex Stapletonb7c60292014-08-25 10:57:42 +0100508
Paul Kehrera9732f52015-06-26 09:43:45 -0500509 .. method:: load_der_x509_csr(data)
510
511 .. versionadded:: 0.9
512
513 :param bytes data: DER formatted certificate signing request data.
514
515 :returns: An instance of
516 :class:`~cryptography.x509.CertificateSigningRequest`.
517
518 .. method:: create_x509_csr(builder, private_key, algorithm)
519
520 .. versionadded:: 1.0
521
522 :param builder: An instance of
523 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
524
525 :param private_key: The
526 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
527 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
528 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
529 that will be used to sign the request. When the request is
530 signed by a certificate authority, the private key's associated
531 public key will be stored in the resulting certificate.
532
533 :param algorithm: The
534 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
535 that will be used to generate the request signature.
536
Alex Gaynor6b3184c2015-12-24 14:21:47 -0500537 :returns: A new instance of
538 :class:`~cryptography.x509.CertificateSigningRequest`.
Paul Kehrera9732f52015-06-26 09:43:45 -0500539
Paul Kehrer1ae76532015-08-06 12:37:10 +0100540 .. method:: create_x509_certificate(builder, private_key, algorithm)
Paul Kehrer0d62a072015-08-06 11:00:47 +0100541
542 .. versionadded:: 1.0
543
544 :param builder: An instance of
545 :class:`~cryptography.x509.CertificateBuilder`.
546
547 :param private_key: The
548 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
549 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
550 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
551 that will be used to sign the certificate.
552
553 :param algorithm: The
554 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
555 that will be used to generate the certificate signature.
556
Alex Gaynor6b3184c2015-12-24 14:21:47 -0500557 :returns: A new instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer0d62a072015-08-06 11:00:47 +0100558
Paul Kehrer07b7e7f2015-12-24 13:06:12 -0600559 .. method:: create_x509_crl(builder, private_key, algorithm)
560
561 .. versionadded:: 1.2
562
563 :param builder: An instance of
Paul Kehrer7eaaf0c2015-12-24 19:27:38 -0600564 :class:`~cryptography.x509.CertificateRevocationListBuilder`.
Paul Kehrer07b7e7f2015-12-24 13:06:12 -0600565
566 :param private_key: The
567 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
568 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
569 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
570 that will be used to sign the CRL.
571
572 :param algorithm: The
573 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
574 that will be used to generate the CRL signature.
575
Paul Kehrera3ef6212015-12-24 13:20:41 -0600576 :returns: A new instance of
577 :class:`~cryptography.x509.CertificateRevocationList`.
Paul Kehrer07b7e7f2015-12-24 13:06:12 -0600578
Paul Kehreraa8b0f42015-12-25 11:13:45 -0600579 .. method:: create_x509_revoked_certificate(builder)
580
581 .. versionadded:: 1.2
582
583 :param builder: An instance of RevokedCertificateBuilder.
584
585 :returns: A new instance of
586 :class:`~cryptography.x509.RevokedCertificate`.
587
Paul Kehrer3a15b032016-11-13 14:30:11 -0800588 .. method:: x509_name_bytes(name)
589
590 .. versionadded:: 1.6
591
592 :param name: An instance of :class:`~cryptography.x509.Name`.
593
594 :return bytes: The DER encoded bytes.
595
Alex Stapletonb7c60292014-08-25 10:57:42 +0100596.. class:: DHBackend
597
598 .. versionadded:: 0.9
599
600 A backend with methods for doing Diffie-Hellman key exchange.
601
602 .. method:: generate_dh_parameters(key_size)
603
604 :param int key_size: The bit length of the prime modulus to generate.
605
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300606 :return: A new instance of
607 :class:`~cryptography.hazmat.primitives.asymmetric.dh.DHParameters`.
Alex Stapletonb7c60292014-08-25 10:57:42 +0100608
609 :raises ValueError: If ``key_size`` is not at least 512.
610
611 .. method:: generate_dh_private_key(parameters)
612
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300613 :param parameters: An instance of
614 :class:`~cryptography.hazmat.primitives.asymmetric.dh.DHParameters`.
Alex Stapletonb7c60292014-08-25 10:57:42 +0100615
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300616 :return: A new instance of
617 :class:`~cryptography.hazmat.primitives.asymmetric.dh.DHPrivateKey`.
Alex Stapletonb7c60292014-08-25 10:57:42 +0100618
619 .. method:: generate_dh_private_key_and_parameters(self, key_size)
620
621 :param int key_size: The bit length of the prime modulus to generate.
622
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300623 :return: A new instance of
624 :class:`~cryptography.hazmat.primitives.asymmetric.dh.DHPrivateKey`.
Alex Stapletonb7c60292014-08-25 10:57:42 +0100625
626 :raises ValueError: If ``key_size`` is not at least 512.
627
628 .. method:: load_dh_private_numbers(numbers)
629
630 :param numbers: A
631 :class:`~cryptography.hazmat.primitives.asymmetric.dh.DHPrivateNumbers`
632 instance.
633
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300634 :return: A new instance of
635 :class:`~cryptography.hazmat.primitives.asymmetric.dh.DHPrivateKey`.
Alex Stapletonb7c60292014-08-25 10:57:42 +0100636
637 :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised
638 when any backend specific criteria are not met.
639
640 .. method:: load_dh_public_numbers(numbers)
641
642 :param numbers: A
643 :class:`~cryptography.hazmat.primitives.asymmetric.dh.DHPublicNumbers`
644 instance.
645
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300646 :return: A new instance of
647 :class:`~cryptography.hazmat.primitives.asymmetric.dh.DHPublicKey`.
Alex Stapletonb7c60292014-08-25 10:57:42 +0100648
649 :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised
650 when any backend specific criteria are not met.
651
652 .. method:: load_dh_parameter_numbers(numbers)
653
654 :param numbers: A
655 :class:`~cryptography.hazmat.primitives.asymmetric.dh.DHParameterNumbers`
656 instance.
657
Gabriel Orisaka6868b1f2016-07-18 21:54:23 -0300658 :return: A new instance of
659 :class:`~cryptography.hazmat.primitives.asymmetric.dh.DHParameters`.
Alex Stapletonb7c60292014-08-25 10:57:42 +0100660
661 :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised
662 when any backend specific criteria are not met.
663
664 .. method:: dh_parameters_supported(p, g)
665
666 :param int p: The p value of the DH key.
667
668 :param int g: The g value of the DH key.
669
670 :returns: ``True`` if the given values of ``p`` and ``g`` are supported
671 by this backend, otherwise ``False``.
Terry Chiad8a27df2016-09-01 23:39:57 +0800672
673
674.. class:: ScryptBackend
675
676 .. versionadded:: 1.6
677
678 A backend with methods for using Scrypt.
679
680 The following backends implement this interface:
681
682 * :doc:`/hazmat/backends/openssl`
683
684 .. method:: derive_scrypt(self, key_material, salt, length, n, r, p)
685
686 :param bytes key_material: The key material to use as a basis for
687 the derived key. This is typically a password.
688
689 :param bytes salt: A salt.
690
691 :param int length: The desired length of the derived key.
692
693 :param int n: CPU/Memory cost parameter. It must be larger than 1 and be a
694 power of 2.
695
696 :param int r: Block size parameter.
697
698 :param int p: Parallelization parameter.
699
700 :return bytes: Derived key.
701