David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 1 | .. hazmat:: |
| 2 | |
Alex Stapleton | c5fffd3 | 2014-03-18 15:29:00 +0000 | [diff] [blame] | 3 | Backend interfaces |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 4 | ================== |
| 5 | |
Alex Gaynor | f8796b1 | 2013-12-13 20:28:55 -0800 | [diff] [blame] | 6 | .. currentmodule:: cryptography.hazmat.backends.interfaces |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 7 | |
| 8 | |
Alex Gaynor | 969f18e | 2014-05-17 20:07:35 -0700 | [diff] [blame] | 9 | Backend implementations may provide a number of interfaces to support |
| 10 | operations such as :doc:`/hazmat/primitives/symmetric-encryption`, |
David Reid | 6b9df81 | 2013-11-18 14:13:02 -0800 | [diff] [blame] | 11 | :doc:`/hazmat/primitives/cryptographic-hashes`, and |
Ayrx | fa4a6b2 | 2014-04-16 23:03:14 +0800 | [diff] [blame] | 12 | :doc:`/hazmat/primitives/mac/hmac`. |
David Reid | 6b9df81 | 2013-11-18 14:13:02 -0800 | [diff] [blame] | 13 | |
| 14 | A specific ``backend`` may provide one or more of these interfaces. |
| 15 | |
| 16 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 17 | .. class:: CipherBackend |
| 18 | |
Alex Stapleton | 63b3de2 | 2014-02-08 09:43:16 +0000 | [diff] [blame] | 19 | A backend that provides methods for using ciphers for encryption |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 20 | and decryption. |
| 21 | |
Alex Gaynor | 585c99c | 2014-02-04 16:10:10 -0800 | [diff] [blame] | 22 | The following backends implement this interface: |
| 23 | |
| 24 | * :doc:`/hazmat/backends/openssl` |
| 25 | * :doc:`/hazmat/backends/commoncrypto` |
| 26 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 27 | .. method:: cipher_supported(cipher, mode) |
| 28 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 29 | Check if a ``cipher`` and ``mode`` combination is supported by |
| 30 | this backend. |
| 31 | |
| 32 | :param cipher: An instance of a |
Paul Kehrer | 7c5c9fe | 2015-02-14 10:27:14 -0600 | [diff] [blame] | 33 | :class:`~cryptography.hazmat.primitives.ciphers.CipherAlgorithm` |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 34 | provider. |
| 35 | :param mode: An instance of a |
Paul Kehrer | 513b7cb | 2015-02-12 17:31:24 -0600 | [diff] [blame] | 36 | :class:`~cryptography.hazmat.primitives.ciphers.modes.Mode` provider. |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 37 | |
| 38 | :returns: ``True`` if the specified ``cipher`` and ``mode`` combination |
| 39 | is supported by this backend, otherwise ``False`` |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 40 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 41 | |
| 42 | .. method:: create_symmetric_encryption_ctx(cipher, mode) |
| 43 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 44 | Create a |
Paul Kehrer | 7c5c9fe | 2015-02-14 10:27:14 -0600 | [diff] [blame] | 45 | :class:`~cryptography.hazmat.primitives.ciphers.CipherContext` that |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 46 | can be used for encrypting data with the symmetric ``cipher`` using |
| 47 | the given ``mode``. |
| 48 | |
| 49 | :param cipher: An instance of a |
Paul Kehrer | 7c5c9fe | 2015-02-14 10:27:14 -0600 | [diff] [blame] | 50 | :class:`~cryptography.hazmat.primitives.ciphers.CipherAlgorithm` |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 51 | provider. |
| 52 | :param mode: An instance of a |
Paul Kehrer | 513b7cb | 2015-02-12 17:31:24 -0600 | [diff] [blame] | 53 | :class:`~cryptography.hazmat.primitives.ciphers.modes.Mode` provider. |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 54 | |
| 55 | :returns: |
Paul Kehrer | 7c5c9fe | 2015-02-14 10:27:14 -0600 | [diff] [blame] | 56 | :class:`~cryptography.hazmat.primitives.ciphers.CipherContext` |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 57 | |
Paul Kehrer | a07925a | 2013-12-06 11:49:42 -0600 | [diff] [blame] | 58 | :raises ValueError: When tag is not None in an AEAD mode |
| 59 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 60 | |
| 61 | .. method:: create_symmetric_decryption_ctx(cipher, mode) |
| 62 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 63 | Create a |
Paul Kehrer | 7c5c9fe | 2015-02-14 10:27:14 -0600 | [diff] [blame] | 64 | :class:`~cryptography.hazmat.primitives.ciphers.CipherContext` that |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 65 | can be used for decrypting data with the symmetric ``cipher`` using |
| 66 | the given ``mode``. |
| 67 | |
| 68 | :param cipher: An instance of a |
Paul Kehrer | 7c5c9fe | 2015-02-14 10:27:14 -0600 | [diff] [blame] | 69 | :class:`~cryptography.hazmat.primitives.ciphers.CipherAlgorithm` |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 70 | provider. |
| 71 | :param mode: An instance of a |
Paul Kehrer | 513b7cb | 2015-02-12 17:31:24 -0600 | [diff] [blame] | 72 | :class:`~cryptography.hazmat.primitives.ciphers.modes.Mode` provider. |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 73 | |
| 74 | :returns: |
Paul Kehrer | 7c5c9fe | 2015-02-14 10:27:14 -0600 | [diff] [blame] | 75 | :class:`~cryptography.hazmat.primitives.ciphers.CipherContext` |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 76 | |
Paul Kehrer | a07925a | 2013-12-06 11:49:42 -0600 | [diff] [blame] | 77 | :raises ValueError: When tag is None in an AEAD mode |
| 78 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 79 | |
| 80 | .. class:: HashBackend |
| 81 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 82 | A backend with methods for using cryptographic hash functions. |
| 83 | |
Alex Gaynor | 585c99c | 2014-02-04 16:10:10 -0800 | [diff] [blame] | 84 | The following backends implement this interface: |
| 85 | |
| 86 | * :doc:`/hazmat/backends/openssl` |
| 87 | * :doc:`/hazmat/backends/commoncrypto` |
| 88 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 89 | .. method:: hash_supported(algorithm) |
| 90 | |
David Reid | 6624a44 | 2013-11-18 12:44:30 -0800 | [diff] [blame] | 91 | Check if the specified ``algorithm`` is supported by this backend. |
| 92 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 93 | :param algorithm: An instance of a |
Paul Kehrer | 601278a | 2015-02-12 12:51:00 -0600 | [diff] [blame] | 94 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 95 | provider. |
| 96 | |
| 97 | :returns: ``True`` if the specified ``algorithm`` is supported by this |
| 98 | backend, otherwise ``False``. |
| 99 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 100 | |
| 101 | .. method:: create_hash_ctx(algorithm) |
| 102 | |
David Reid | 6624a44 | 2013-11-18 12:44:30 -0800 | [diff] [blame] | 103 | Create a |
Paul Kehrer | 601278a | 2015-02-12 12:51:00 -0600 | [diff] [blame] | 104 | :class:`~cryptography.hazmat.primitives.hashes.HashContext` that |
David Reid | 6624a44 | 2013-11-18 12:44:30 -0800 | [diff] [blame] | 105 | uses the specified ``algorithm`` to calculate a message digest. |
| 106 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 107 | :param algorithm: An instance of a |
Paul Kehrer | 601278a | 2015-02-12 12:51:00 -0600 | [diff] [blame] | 108 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 109 | provider. |
| 110 | |
| 111 | :returns: |
Paul Kehrer | 601278a | 2015-02-12 12:51:00 -0600 | [diff] [blame] | 112 | :class:`~cryptography.hazmat.primitives.hashes.HashContext` |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 113 | |
| 114 | |
| 115 | .. class:: HMACBackend |
| 116 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 117 | A backend with methods for using cryptographic hash functions as message |
| 118 | authentication codes. |
| 119 | |
Alex Gaynor | 585c99c | 2014-02-04 16:10:10 -0800 | [diff] [blame] | 120 | The following backends implement this interface: |
| 121 | |
| 122 | * :doc:`/hazmat/backends/openssl` |
| 123 | * :doc:`/hazmat/backends/commoncrypto` |
| 124 | |
Paul Kehrer | 90ae866 | 2013-12-23 17:21:00 -0600 | [diff] [blame] | 125 | .. method:: hmac_supported(algorithm) |
| 126 | |
| 127 | Check if the specified ``algorithm`` is supported by this backend. |
| 128 | |
| 129 | :param algorithm: An instance of a |
Paul Kehrer | 601278a | 2015-02-12 12:51:00 -0600 | [diff] [blame] | 130 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
Paul Kehrer | 90ae866 | 2013-12-23 17:21:00 -0600 | [diff] [blame] | 131 | provider. |
| 132 | |
| 133 | :returns: ``True`` if the specified ``algorithm`` is supported for HMAC |
| 134 | by this backend, otherwise ``False``. |
| 135 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 136 | .. method:: create_hmac_ctx(algorithm) |
| 137 | |
David Reid | 6624a44 | 2013-11-18 12:44:30 -0800 | [diff] [blame] | 138 | Create a |
Paul Kehrer | 601278a | 2015-02-12 12:51:00 -0600 | [diff] [blame] | 139 | :class:`~cryptography.hazmat.primitives.hashes.HashContext` that |
Paul Kehrer | 4f776c4 | 2013-12-23 17:25:54 -0600 | [diff] [blame] | 140 | uses the specified ``algorithm`` to calculate a hash-based message |
| 141 | authentication code. |
David Reid | 6624a44 | 2013-11-18 12:44:30 -0800 | [diff] [blame] | 142 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 143 | :param algorithm: An instance of a |
Paul Kehrer | 601278a | 2015-02-12 12:51:00 -0600 | [diff] [blame] | 144 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 145 | provider. |
| 146 | |
| 147 | :returns: |
Paul Kehrer | 601278a | 2015-02-12 12:51:00 -0600 | [diff] [blame] | 148 | :class:`~cryptography.hazmat.primitives.hashes.HashContext` |
Paul Kehrer | 1050ddf | 2014-01-27 21:04:03 -0600 | [diff] [blame] | 149 | |
| 150 | |
Alexander Gaynor | a1f1afa | 2014-07-18 10:57:41 -0700 | [diff] [blame] | 151 | .. class:: CMACBackend |
| 152 | |
| 153 | .. versionadded:: 0.4 |
| 154 | |
| 155 | A backend with methods for using CMAC |
| 156 | |
| 157 | .. method:: cmac_algorithm_supported(algorithm) |
| 158 | |
| 159 | :param algorithm: An instance of a |
Paul Kehrer | 7c5c9fe | 2015-02-14 10:27:14 -0600 | [diff] [blame] | 160 | :class:`~cryptography.hazmat.primitives.ciphers.BlockCipherAlgorithm` |
Alexander Gaynor | a1f1afa | 2014-07-18 10:57:41 -0700 | [diff] [blame] | 161 | provider. |
| 162 | :return: Returns True if the block cipher is supported for CMAC by this backend |
| 163 | |
| 164 | .. method:: create_cmac_ctx(algorithm) |
| 165 | |
| 166 | Create a |
| 167 | :class:`~cryptography.hazmat.primitives.interfaces.CMACContext` that |
| 168 | uses the specified ``algorithm`` to calculate a message authentication code. |
| 169 | |
| 170 | :param algorithm: An instance of a |
Paul Kehrer | 7c5c9fe | 2015-02-14 10:27:14 -0600 | [diff] [blame] | 171 | :class:`~cryptography.hazmat.primitives.ciphers.BlockCipherAlgorithm` |
Alexander Gaynor | a1f1afa | 2014-07-18 10:57:41 -0700 | [diff] [blame] | 172 | provider. |
| 173 | |
| 174 | :returns: |
| 175 | :class:`~cryptography.hazmat.primitives.interfaces.CMACContext` |
| 176 | |
| 177 | |
Paul Kehrer | 98e40e6 | 2014-01-28 15:07:49 -0600 | [diff] [blame] | 178 | .. class:: PBKDF2HMACBackend |
Paul Kehrer | 1050ddf | 2014-01-27 21:04:03 -0600 | [diff] [blame] | 179 | |
Paul Kehrer | 5d1af21 | 2014-01-28 12:19:32 -0600 | [diff] [blame] | 180 | .. versionadded:: 0.2 |
| 181 | |
Paul Kehrer | 98e40e6 | 2014-01-28 15:07:49 -0600 | [diff] [blame] | 182 | A backend with methods for using PBKDF2 using HMAC as a PRF. |
Paul Kehrer | 1050ddf | 2014-01-27 21:04:03 -0600 | [diff] [blame] | 183 | |
Alex Gaynor | 585c99c | 2014-02-04 16:10:10 -0800 | [diff] [blame] | 184 | The following backends implement this interface: |
| 185 | |
| 186 | * :doc:`/hazmat/backends/openssl` |
| 187 | * :doc:`/hazmat/backends/commoncrypto` |
| 188 | |
Paul Kehrer | 98e40e6 | 2014-01-28 15:07:49 -0600 | [diff] [blame] | 189 | .. method:: pbkdf2_hmac_supported(algorithm) |
Paul Kehrer | 1050ddf | 2014-01-27 21:04:03 -0600 | [diff] [blame] | 190 | |
| 191 | Check if the specified ``algorithm`` is supported by this backend. |
| 192 | |
Paul Kehrer | 589b908 | 2014-01-28 21:25:41 -0600 | [diff] [blame] | 193 | :param algorithm: An instance of a |
Paul Kehrer | 601278a | 2015-02-12 12:51:00 -0600 | [diff] [blame] | 194 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
Paul Kehrer | 1050ddf | 2014-01-27 21:04:03 -0600 | [diff] [blame] | 195 | provider. |
| 196 | |
| 197 | :returns: ``True`` if the specified ``algorithm`` is supported for |
Paul Kehrer | 98e40e6 | 2014-01-28 15:07:49 -0600 | [diff] [blame] | 198 | PBKDF2 HMAC by this backend, otherwise ``False``. |
Paul Kehrer | 1050ddf | 2014-01-27 21:04:03 -0600 | [diff] [blame] | 199 | |
Alex Gaynor | 1cfc5d5 | 2014-11-23 17:44:28 -0600 | [diff] [blame] | 200 | .. method:: derive_pbkdf2_hmac(self, algorithm, length, salt, iterations, key_material) |
Paul Kehrer | 1050ddf | 2014-01-27 21:04:03 -0600 | [diff] [blame] | 201 | |
| 202 | :param algorithm: An instance of a |
Paul Kehrer | 601278a | 2015-02-12 12:51:00 -0600 | [diff] [blame] | 203 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
Paul Kehrer | 1050ddf | 2014-01-27 21:04:03 -0600 | [diff] [blame] | 204 | provider. |
| 205 | |
| 206 | :param int length: The desired length of the derived key. Maximum is |
Paul Kehrer | 98e40e6 | 2014-01-28 15:07:49 -0600 | [diff] [blame] | 207 | (2\ :sup:`32` - 1) * ``algorithm.digest_size`` |
Paul Kehrer | 1050ddf | 2014-01-27 21:04:03 -0600 | [diff] [blame] | 208 | |
Paul Kehrer | b6d764c | 2014-01-27 22:32:11 -0600 | [diff] [blame] | 209 | :param bytes salt: A salt. |
Paul Kehrer | 1050ddf | 2014-01-27 21:04:03 -0600 | [diff] [blame] | 210 | |
| 211 | :param int iterations: The number of iterations to perform of the hash |
Paul Kehrer | c58b478 | 2014-01-29 13:56:25 -0600 | [diff] [blame] | 212 | function. This can be used to control the length of time the |
| 213 | operation takes. Higher numbers help mitigate brute force attacks |
| 214 | against derived keys. |
Paul Kehrer | 1050ddf | 2014-01-27 21:04:03 -0600 | [diff] [blame] | 215 | |
| 216 | :param bytes key_material: The key material to use as a basis for |
| 217 | the derived key. This is typically a password. |
| 218 | |
| 219 | :return bytes: Derived key. |
Alex Stapleton | 209a132 | 2014-02-07 20:26:44 +0000 | [diff] [blame] | 220 | |
| 221 | |
| 222 | .. class:: RSABackend |
| 223 | |
| 224 | .. versionadded:: 0.2 |
| 225 | |
| 226 | A backend with methods for using RSA. |
| 227 | |
Alex Stapleton | e009ad2 | 2014-02-08 17:23:46 +0000 | [diff] [blame] | 228 | .. method:: generate_rsa_private_key(public_exponent, key_size) |
Alex Stapleton | 209a132 | 2014-02-07 20:26:44 +0000 | [diff] [blame] | 229 | |
| 230 | :param int public_exponent: The public exponent of the new key. |
| 231 | Often one of the small Fermat primes 3, 5, 17, 257 or 65537. |
| 232 | |
Alex Stapleton | e009ad2 | 2014-02-08 17:23:46 +0000 | [diff] [blame] | 233 | :param int key_size: The length in bits of the modulus. Should be |
Alex Stapleton | 209a132 | 2014-02-07 20:26:44 +0000 | [diff] [blame] | 234 | at least 2048. |
| 235 | |
| 236 | :return: A new instance of a |
Alex Stapleton | f79c231 | 2014-12-30 12:50:14 +0000 | [diff] [blame] | 237 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey` |
Alex Stapleton | 209a132 | 2014-02-07 20:26:44 +0000 | [diff] [blame] | 238 | provider. |
| 239 | |
| 240 | :raises ValueError: If the public_exponent is not valid. |
Paul Kehrer | 2b3f0fc | 2014-02-17 19:20:14 -0600 | [diff] [blame] | 241 | |
Paul Kehrer | c333dbc | 2014-05-24 18:35:02 -0500 | [diff] [blame] | 242 | .. method:: rsa_padding_supported(padding) |
| 243 | |
| 244 | Check if the specified ``padding`` is supported by the backend. |
| 245 | |
| 246 | :param padding: An instance of an |
Paul Kehrer | 64ddb7a | 2015-02-14 19:20:28 -0600 | [diff] [blame] | 247 | :class:`~cryptography.hazmat.primitives.asymmetric.padding.AsymmetricPadding` |
Paul Kehrer | c333dbc | 2014-05-24 18:35:02 -0500 | [diff] [blame] | 248 | provider. |
| 249 | |
| 250 | :returns: ``True`` if the specified ``padding`` is supported by this |
| 251 | backend, otherwise ``False``. |
| 252 | |
Paul Kehrer | 342d2e4 | 2014-05-25 22:01:20 -0500 | [diff] [blame] | 253 | .. method:: generate_rsa_parameters_supported(public_exponent, key_size) |
| 254 | |
| 255 | Check if the specified parameters are supported for key generation by |
| 256 | the backend. |
| 257 | |
Paul Kehrer | 1b760f1 | 2014-05-26 08:54:38 -0500 | [diff] [blame] | 258 | :param int public_exponent: The public exponent. |
Paul Kehrer | 342d2e4 | 2014-05-25 22:01:20 -0500 | [diff] [blame] | 259 | |
Paul Kehrer | 1b760f1 | 2014-05-26 08:54:38 -0500 | [diff] [blame] | 260 | :param int key_size: The bit length of the generated modulus. |
Paul Kehrer | 342d2e4 | 2014-05-25 22:01:20 -0500 | [diff] [blame] | 261 | |
Alex Gaynor | 4922c45 | 2014-11-20 19:45:07 -0800 | [diff] [blame] | 262 | .. method:: load_rsa_private_numbers(numbers) |
David Reid | 68b509a | 2014-05-08 10:31:51 -0700 | [diff] [blame] | 263 | |
| 264 | :param numbers: An instance of |
David Reid | a674afe | 2014-05-30 14:15:29 -0700 | [diff] [blame] | 265 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateNumbers`. |
David Reid | 68b509a | 2014-05-08 10:31:51 -0700 | [diff] [blame] | 266 | |
| 267 | :returns: A provider of |
Alex Stapleton | f79c231 | 2014-12-30 12:50:14 +0000 | [diff] [blame] | 268 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`. |
David Reid | a674afe | 2014-05-30 14:15:29 -0700 | [diff] [blame] | 269 | |
David Reid | c57a376 | 2014-06-03 13:27:50 -0700 | [diff] [blame] | 270 | :raises ValueError: This is raised when the values of ``p``, ``q``, |
| 271 | ``private_exponent``, ``public_exponent``, or ``modulus`` do not |
| 272 | match the bounds specified in :rfc:`3447`. |
| 273 | |
Alex Gaynor | fecf644 | 2014-12-27 11:19:32 -0800 | [diff] [blame] | 274 | :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised |
| 275 | when any backend specific criteria are not met. |
David Reid | da76ae0 | 2014-06-03 14:01:18 -0700 | [diff] [blame] | 276 | |
Alex Gaynor | 4922c45 | 2014-11-20 19:45:07 -0800 | [diff] [blame] | 277 | .. method:: load_rsa_public_numbers(numbers) |
David Reid | a674afe | 2014-05-30 14:15:29 -0700 | [diff] [blame] | 278 | |
| 279 | :param numbers: An instance of |
| 280 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateNumbers`. |
| 281 | |
| 282 | :returns: A provider of |
Alex Stapleton | f79c231 | 2014-12-30 12:50:14 +0000 | [diff] [blame] | 283 | :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`. |
David Reid | 68b509a | 2014-05-08 10:31:51 -0700 | [diff] [blame] | 284 | |
David Reid | c57a376 | 2014-06-03 13:27:50 -0700 | [diff] [blame] | 285 | :raises ValueError: This is raised when the values of |
| 286 | ``public_exponent`` or ``modulus`` do not match the bounds |
| 287 | specified in :rfc:`3447`. |
| 288 | |
Alex Gaynor | fecf644 | 2014-12-27 11:19:32 -0800 | [diff] [blame] | 289 | :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised |
| 290 | when any backend specific criteria are not met. |
David Reid | da76ae0 | 2014-06-03 14:01:18 -0700 | [diff] [blame] | 291 | |
Alex Stapleton | 2fb76a3 | 2014-02-15 11:10:57 +0000 | [diff] [blame] | 292 | |
Mohammed Attia | 29474ac | 2014-04-02 04:03:09 +0200 | [diff] [blame] | 293 | .. class:: DSABackend |
| 294 | |
| 295 | .. versionadded:: 0.4 |
| 296 | |
| 297 | A backend with methods for using DSA. |
| 298 | |
| 299 | .. method:: generate_dsa_parameters(key_size) |
| 300 | |
Alex Gaynor | c9dc0a0 | 2014-04-24 13:38:12 -0700 | [diff] [blame] | 301 | :param int key_size: The length of the modulus in bits. It should be |
Alex Gaynor | 20c4404 | 2015-01-08 11:00:00 -0800 | [diff] [blame] | 302 | either 1024, 2048 or 3072. For keys generated in 2015 this should |
Mohammed Attia | 29474ac | 2014-04-02 04:03:09 +0200 | [diff] [blame] | 303 | be at least 2048. |
Alex Gaynor | c9dc0a0 | 2014-04-24 13:38:12 -0700 | [diff] [blame] | 304 | Note that some applications (such as SSH) have not yet gained |
| 305 | support for larger key sizes specified in FIPS 186-3 and are still |
| 306 | restricted to only the 1024-bit keys specified in FIPS 186-2. |
Mohammed Attia | 29474ac | 2014-04-02 04:03:09 +0200 | [diff] [blame] | 307 | |
| 308 | :return: A new instance of a |
Alex Stapleton | f48f69d | 2015-01-18 15:57:28 +0000 | [diff] [blame] | 309 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameters` |
Mohammed Attia | 29474ac | 2014-04-02 04:03:09 +0200 | [diff] [blame] | 310 | provider. |
| 311 | |
| 312 | .. method:: generate_dsa_private_key(parameters) |
| 313 | |
| 314 | :param parameters: A |
Alex Stapleton | f48f69d | 2015-01-18 15:57:28 +0000 | [diff] [blame] | 315 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameters` |
Mohammed Attia | 29474ac | 2014-04-02 04:03:09 +0200 | [diff] [blame] | 316 | provider. |
| 317 | |
| 318 | :return: A new instance of a |
Alex Stapleton | f48f69d | 2015-01-18 15:57:28 +0000 | [diff] [blame] | 319 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` |
Mohammed Attia | 29474ac | 2014-04-02 04:03:09 +0200 | [diff] [blame] | 320 | provider. |
| 321 | |
Alex Gaynor | 239d518 | 2014-04-24 13:42:58 -0700 | [diff] [blame] | 322 | :raises ValueError: This is raised if the key size is not one of 1024, |
| 323 | 2048, or 3072. It is also raised when OpenSSL is older than version |
| 324 | 1.0.0 and the key size is larger than 1024; older OpenSSL versions |
| 325 | do not support keys larger than 1024 bits. |
Ayrx | 97a72fd | 2014-04-15 19:02:51 +0800 | [diff] [blame] | 326 | |
Paul Kehrer | 298effd | 2014-06-27 14:07:59 -0600 | [diff] [blame] | 327 | .. method:: generate_dsa_private_key_and_parameters(key_size) |
| 328 | |
| 329 | :param int key_size: The length of the modulus in bits. It should be |
Alex Gaynor | 20c4404 | 2015-01-08 11:00:00 -0800 | [diff] [blame] | 330 | either 1024, 2048 or 3072. For keys generated in 2015 this should |
Paul Kehrer | 298effd | 2014-06-27 14:07:59 -0600 | [diff] [blame] | 331 | be at least 2048. |
| 332 | Note that some applications (such as SSH) have not yet gained |
| 333 | support for larger key sizes specified in FIPS 186-3 and are still |
| 334 | restricted to only the 1024-bit keys specified in FIPS 186-2. |
| 335 | |
| 336 | :return: A new instance of a |
Paul Kehrer | 45efdbc | 2015-02-12 10:58:22 -0600 | [diff] [blame] | 337 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` |
Paul Kehrer | 298effd | 2014-06-27 14:07:59 -0600 | [diff] [blame] | 338 | provider. |
| 339 | |
| 340 | :raises ValueError: This is raised if the key size is not supported |
| 341 | by the backend. |
| 342 | |
Alex Gaynor | 4922c45 | 2014-11-20 19:45:07 -0800 | [diff] [blame] | 343 | .. method:: dsa_hash_supported(algorithm) |
Paul Kehrer | 43dc276 | 2014-04-30 16:24:39 -0500 | [diff] [blame] | 344 | |
Mohammed Attia | 59edb61 | 2014-04-25 22:44:40 +0200 | [diff] [blame] | 345 | :param algorithm: An instance of a |
Paul Kehrer | 601278a | 2015-02-12 12:51:00 -0600 | [diff] [blame] | 346 | :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` |
Mohammed Attia | 59edb61 | 2014-04-25 22:44:40 +0200 | [diff] [blame] | 347 | provider. |
| 348 | |
| 349 | :returns: ``True`` if the specified ``algorithm`` is supported by this |
| 350 | backend, otherwise ``False``. |
| 351 | |
Alex Gaynor | 4922c45 | 2014-11-20 19:45:07 -0800 | [diff] [blame] | 352 | .. method:: dsa_parameters_supported(p, q, g) |
Paul Kehrer | b403787 | 2014-04-30 16:32:23 -0500 | [diff] [blame] | 353 | |
| 354 | :param int p: The p value of a DSA key. |
| 355 | |
| 356 | :param int q: The q value of a DSA key. |
| 357 | |
Paul Kehrer | 21babbb | 2014-05-01 11:33:22 -0500 | [diff] [blame] | 358 | :param int g: The g value of a DSA key. |
| 359 | |
| 360 | :returns: ``True`` if the given values of ``p``, ``q``, and ``g`` are |
| 361 | supported by this backend, otherwise ``False``. |
Paul Kehrer | b403787 | 2014-04-30 16:32:23 -0500 | [diff] [blame] | 362 | |
Alex Gaynor | 4922c45 | 2014-11-20 19:45:07 -0800 | [diff] [blame] | 363 | .. method:: load_dsa_parameter_numbers(numbers) |
Paul Kehrer | 0739afc | 2014-06-22 12:06:18 -0600 | [diff] [blame] | 364 | |
| 365 | :param numbers: An instance of |
| 366 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameterNumbers`. |
| 367 | |
| 368 | :returns: A provider of |
Alex Stapleton | f48f69d | 2015-01-18 15:57:28 +0000 | [diff] [blame] | 369 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAParameters`. |
Paul Kehrer | 0739afc | 2014-06-22 12:06:18 -0600 | [diff] [blame] | 370 | |
Alex Gaynor | fecf644 | 2014-12-27 11:19:32 -0800 | [diff] [blame] | 371 | :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised |
| 372 | when any backend specific criteria are not met. |
Paul Kehrer | 0739afc | 2014-06-22 12:06:18 -0600 | [diff] [blame] | 373 | |
Alex Gaynor | 4922c45 | 2014-11-20 19:45:07 -0800 | [diff] [blame] | 374 | .. method:: load_dsa_private_numbers(numbers) |
Paul Kehrer | 0739afc | 2014-06-22 12:06:18 -0600 | [diff] [blame] | 375 | |
| 376 | :param numbers: An instance of |
| 377 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateNumbers`. |
| 378 | |
| 379 | :returns: A provider of |
Alex Stapleton | f48f69d | 2015-01-18 15:57:28 +0000 | [diff] [blame] | 380 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey`. |
Paul Kehrer | 0739afc | 2014-06-22 12:06:18 -0600 | [diff] [blame] | 381 | |
Alex Gaynor | fecf644 | 2014-12-27 11:19:32 -0800 | [diff] [blame] | 382 | :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised |
| 383 | when any backend specific criteria are not met. |
Paul Kehrer | 0739afc | 2014-06-22 12:06:18 -0600 | [diff] [blame] | 384 | |
Alex Gaynor | 4922c45 | 2014-11-20 19:45:07 -0800 | [diff] [blame] | 385 | .. method:: load_dsa_public_numbers(numbers) |
Paul Kehrer | 0739afc | 2014-06-22 12:06:18 -0600 | [diff] [blame] | 386 | |
| 387 | :param numbers: An instance of |
| 388 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicNumbers`. |
| 389 | |
| 390 | :returns: A provider of |
Alex Stapleton | f48f69d | 2015-01-18 15:57:28 +0000 | [diff] [blame] | 391 | :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`. |
Paul Kehrer | 0739afc | 2014-06-22 12:06:18 -0600 | [diff] [blame] | 392 | |
Alex Gaynor | fecf644 | 2014-12-27 11:19:32 -0800 | [diff] [blame] | 393 | :raises cryptography.exceptions.UnsupportedAlgorithm: This is raised |
| 394 | when any backend specific criteria are not met. |
Paul Kehrer | 0739afc | 2014-06-22 12:06:18 -0600 | [diff] [blame] | 395 | |
| 396 | |
Alex Stapleton | 13f1d8d | 2014-05-17 16:50:11 +0100 | [diff] [blame] | 397 | .. class:: EllipticCurveBackend |
| 398 | |
| 399 | .. versionadded:: 0.5 |
| 400 | |
| 401 | .. method:: elliptic_curve_supported(curve) |
| 402 | |
| 403 | :param curve: An instance of a |
Paul Kehrer | 45efdbc | 2015-02-12 10:58:22 -0600 | [diff] [blame] | 404 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve` |
Alex Stapleton | 13f1d8d | 2014-05-17 16:50:11 +0100 | [diff] [blame] | 405 | provider. |
| 406 | |
| 407 | :returns: True if the elliptic curve is supported by this backend. |
| 408 | |
| 409 | .. method:: elliptic_curve_signature_algorithm_supported(signature_algorithm, curve) |
| 410 | |
| 411 | :param signature_algorithm: An instance of a |
Paul Kehrer | 45efdbc | 2015-02-12 10:58:22 -0600 | [diff] [blame] | 412 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurveSignatureAlgorithm` |
Alex Stapleton | 13f1d8d | 2014-05-17 16:50:11 +0100 | [diff] [blame] | 413 | provider. |
| 414 | |
| 415 | :param curve: An instance of a |
Paul Kehrer | 45efdbc | 2015-02-12 10:58:22 -0600 | [diff] [blame] | 416 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve` |
Alex Stapleton | 13f1d8d | 2014-05-17 16:50:11 +0100 | [diff] [blame] | 417 | provider. |
| 418 | |
| 419 | :returns: True if the signature algorithm and curve are supported by this backend. |
| 420 | |
| 421 | .. method:: generate_elliptic_curve_private_key(curve) |
| 422 | |
| 423 | :param curve: An instance of a |
Paul Kehrer | 45efdbc | 2015-02-12 10:58:22 -0600 | [diff] [blame] | 424 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurve` |
Alex Stapleton | 13f1d8d | 2014-05-17 16:50:11 +0100 | [diff] [blame] | 425 | provider. |
| 426 | |
Paul Kehrer | 77e95a0 | 2014-09-25 12:28:07 -0500 | [diff] [blame] | 427 | .. method:: load_elliptic_curve_private_numbers(numbers) |
Alex Stapleton | 13f1d8d | 2014-05-17 16:50:11 +0100 | [diff] [blame] | 428 | |
| 429 | :param numbers: An instance of a |
Paul Kehrer | 45efdbc | 2015-02-12 10:58:22 -0600 | [diff] [blame] | 430 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateNumbers` |
Alex Stapleton | 13f1d8d | 2014-05-17 16:50:11 +0100 | [diff] [blame] | 431 | provider. |
| 432 | |
| 433 | :returns: An instance of a |
Paul Kehrer | 45efdbc | 2015-02-12 10:58:22 -0600 | [diff] [blame] | 434 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey` |
Alex Stapleton | 13f1d8d | 2014-05-17 16:50:11 +0100 | [diff] [blame] | 435 | provider. |
| 436 | |
Paul Kehrer | 77e95a0 | 2014-09-25 12:28:07 -0500 | [diff] [blame] | 437 | .. method:: load_elliptic_curve_public_numbers(numbers) |
Alex Stapleton | 13f1d8d | 2014-05-17 16:50:11 +0100 | [diff] [blame] | 438 | |
| 439 | :param numbers: An instance of a |
Paul Kehrer | 45efdbc | 2015-02-12 10:58:22 -0600 | [diff] [blame] | 440 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers` |
Alex Stapleton | 13f1d8d | 2014-05-17 16:50:11 +0100 | [diff] [blame] | 441 | provider. |
| 442 | |
| 443 | :returns: An instance of a |
Paul Kehrer | 45efdbc | 2015-02-12 10:58:22 -0600 | [diff] [blame] | 444 | :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey` |
Alex Stapleton | 13f1d8d | 2014-05-17 16:50:11 +0100 | [diff] [blame] | 445 | provider. |
Alexander Gaynor | a1f1afa | 2014-07-18 10:57:41 -0700 | [diff] [blame] | 446 | |
Alexander Gaynor | e0e9541 | 2014-07-19 10:58:50 -0700 | [diff] [blame] | 447 | .. class:: PEMSerializationBackend |
| 448 | |
| 449 | .. versionadded:: 0.6 |
| 450 | |
| 451 | A backend with methods for working with any PEM encoded keys. |
| 452 | |
| 453 | .. method:: load_pem_private_key(data, password) |
| 454 | |
| 455 | :param bytes data: PEM data to load. |
| 456 | :param bytes password: The password to use if the data is encrypted. |
Alex Gaynor | 99e61ea | 2014-09-08 10:26:40 -0700 | [diff] [blame] | 457 | Should be ``None`` if the data is not encrypted. |
Alexander Gaynor | e0e9541 | 2014-07-19 10:58:50 -0700 | [diff] [blame] | 458 | :return: A new instance of the appropriate type of private key that the |
| 459 | serialized data contains. |
| 460 | :raises ValueError: If the data could not be deserialized. |
| 461 | :raises cryptography.exceptions.UnsupportedAlgorithm: If the data is |
| 462 | encrypted with an unsupported algorithm. |
| 463 | |
michael-hart | 801e8c1 | 2014-09-26 00:32:25 +0100 | [diff] [blame] | 464 | .. method:: load_pem_public_key(data) |
| 465 | |
| 466 | :param bytes data: PEM data to load. |
Alex Gaynor | b366f39 | 2014-09-29 11:07:05 -0700 | [diff] [blame] | 467 | :return: A new instance of the appropriate type of public key |
| 468 | serialized data contains. |
michael-hart | 801e8c1 | 2014-09-26 00:32:25 +0100 | [diff] [blame] | 469 | :raises ValueError: If the data could not be deserialized. |
| 470 | |
Paul Kehrer | 76da86a | 2015-01-04 15:54:32 -0600 | [diff] [blame] | 471 | .. class:: DERSerializationBackend |
| 472 | |
| 473 | .. versionadded:: 0.8 |
| 474 | |
| 475 | A backend with methods for working with DER encoded keys. |
| 476 | |
| 477 | .. method:: load_der_private_key(data, password) |
| 478 | |
| 479 | :param bytes data: DER data to load. |
| 480 | :param bytes password: The password to use if the data is encrypted. |
| 481 | Should be ``None`` if the data is not encrypted. |
| 482 | :return: A new instance of the appropriate type of private key that the |
| 483 | serialized data contains. |
| 484 | :raises ValueError: If the data could not be deserialized. |
| 485 | :raises cryptography.exceptions.UnsupportedAlgorithm: If the data is |
| 486 | encrypted with an unsupported algorithm. |
| 487 | |
| 488 | .. method:: load_der_public_key(data) |
| 489 | |
| 490 | :param bytes data: DER data to load. |
| 491 | :return: A new instance of the appropriate type of public key |
| 492 | serialized data contains. |
| 493 | :raises ValueError: If the data could not be deserialized. |
| 494 | |
Paul Kehrer | 6c4302e | 2014-11-24 09:20:38 -1000 | [diff] [blame] | 495 | .. class:: X509Backend |
| 496 | |
| 497 | .. versionadded:: 0.7 |
| 498 | |
| 499 | A backend with methods for working with X.509 objects. |
| 500 | |
| 501 | .. method:: load_pem_x509_certificate(data) |
| 502 | |
| 503 | :param bytes data: PEM formatted certificate data. |
| 504 | |
Paul Kehrer | 13b6aff | 2015-02-12 14:05:44 -0600 | [diff] [blame] | 505 | :returns: An instance of :class:`~cryptography.x509.Certificate`. |
Paul Kehrer | 8473df6 | 2014-11-24 17:13:59 -1000 | [diff] [blame] | 506 | |
| 507 | .. method:: load_der_x509_certificate(data) |
| 508 | |
| 509 | :param bytes data: DER formatted certificate data. |
| 510 | |
Paul Kehrer | 13b6aff | 2015-02-12 14:05:44 -0600 | [diff] [blame] | 511 | :returns: An instance of :class:`~cryptography.x509.Certificate`. |