David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 1 | .. hazmat:: |
| 2 | |
| 3 | Backend Interfaces |
| 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 | |
David Reid | 6b9df81 | 2013-11-18 14:13:02 -0800 | [diff] [blame] | 9 | Backend implementations may provide a number of interfaces to support operations |
| 10 | such as :doc:`/hazmat/primitives/symmetric-encryption`, |
| 11 | :doc:`/hazmat/primitives/cryptographic-hashes`, and |
| 12 | :doc:`/hazmat/primitives/hmac`. |
| 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 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 19 | A backend which provides methods for using ciphers for encryption |
| 20 | and decryption. |
| 21 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 22 | .. method:: cipher_supported(cipher, mode) |
| 23 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 24 | Check if a ``cipher`` and ``mode`` combination is supported by |
| 25 | this backend. |
| 26 | |
| 27 | :param cipher: An instance of a |
| 28 | :class:`~cryptography.hazmat.primitives.interfaces.CipherAlgorithm` |
| 29 | provider. |
| 30 | :param mode: An instance of a |
| 31 | :class:`~cryptography.hazmat.primitives.interfaces.Mode` provider. |
| 32 | |
| 33 | :returns: ``True`` if the specified ``cipher`` and ``mode`` combination |
| 34 | is supported by this backend, otherwise ``False`` |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 35 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 36 | |
| 37 | .. method:: create_symmetric_encryption_ctx(cipher, mode) |
| 38 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 39 | Create a |
| 40 | :class:`~cryptogrpahy.hazmat.primitives.interfaces.CipherContext` that |
| 41 | can be used for encrypting data with the symmetric ``cipher`` using |
| 42 | the given ``mode``. |
| 43 | |
| 44 | :param cipher: An instance of a |
| 45 | :class:`~cryptography.hazmat.primitives.interfaces.CipherAlgorithm` |
| 46 | provider. |
| 47 | :param mode: An instance of a |
| 48 | :class:`~cryptography.hazmat.primitives.interfaces.Mode` provider. |
| 49 | |
| 50 | :returns: |
| 51 | :class:`~cryptography.hazmat.primitives.interfaces.CipherContext` |
| 52 | |
Paul Kehrer | a07925a | 2013-12-06 11:49:42 -0600 | [diff] [blame] | 53 | :raises ValueError: When tag is not None in an AEAD mode |
| 54 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 55 | |
| 56 | .. method:: create_symmetric_decryption_ctx(cipher, mode) |
| 57 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 58 | Create a |
| 59 | :class:`~cryptogrpahy.hazmat.primitives.interfaces.CipherContext` that |
| 60 | can be used for decrypting data with the symmetric ``cipher`` using |
| 61 | the given ``mode``. |
| 62 | |
| 63 | :param cipher: An instance of a |
| 64 | :class:`~cryptography.hazmat.primitives.interfaces.CipherAlgorithm` |
| 65 | provider. |
| 66 | :param mode: An instance of a |
| 67 | :class:`~cryptography.hazmat.primitives.interfaces.Mode` provider. |
| 68 | |
| 69 | :returns: |
| 70 | :class:`~cryptography.hazmat.primitives.interfaces.CipherContext` |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 71 | |
Paul Kehrer | a07925a | 2013-12-06 11:49:42 -0600 | [diff] [blame] | 72 | :raises ValueError: When tag is None in an AEAD mode |
| 73 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 74 | |
| 75 | .. class:: HashBackend |
| 76 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 77 | A backend with methods for using cryptographic hash functions. |
| 78 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 79 | .. method:: hash_supported(algorithm) |
| 80 | |
David Reid | 6624a44 | 2013-11-18 12:44:30 -0800 | [diff] [blame] | 81 | Check if the specified ``algorithm`` is supported by this backend. |
| 82 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 83 | :param algorithm: An instance of a |
| 84 | :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 85 | provider. |
| 86 | |
| 87 | :returns: ``True`` if the specified ``algorithm`` is supported by this |
| 88 | backend, otherwise ``False``. |
| 89 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 90 | |
| 91 | .. method:: create_hash_ctx(algorithm) |
| 92 | |
David Reid | 6624a44 | 2013-11-18 12:44:30 -0800 | [diff] [blame] | 93 | Create a |
| 94 | :class:`~cryptogrpahy.hazmat.primitives.interfaces.HashContext` that |
| 95 | uses the specified ``algorithm`` to calculate a message digest. |
| 96 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 97 | :param algorithm: An instance of a |
| 98 | :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 99 | provider. |
| 100 | |
| 101 | :returns: |
| 102 | :class:`~cryptography.hazmat.primitives.interfaces.HashContext` |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 103 | |
| 104 | |
| 105 | .. class:: HMACBackend |
| 106 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 107 | A backend with methods for using cryptographic hash functions as message |
| 108 | authentication codes. |
| 109 | |
Paul Kehrer | 90ae866 | 2013-12-23 17:21:00 -0600 | [diff] [blame] | 110 | .. method:: hmac_supported(algorithm) |
| 111 | |
| 112 | Check if the specified ``algorithm`` is supported by this backend. |
| 113 | |
| 114 | :param algorithm: An instance of a |
| 115 | :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 116 | provider. |
| 117 | |
| 118 | :returns: ``True`` if the specified ``algorithm`` is supported for HMAC |
| 119 | by this backend, otherwise ``False``. |
| 120 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 121 | .. method:: create_hmac_ctx(algorithm) |
| 122 | |
David Reid | 6624a44 | 2013-11-18 12:44:30 -0800 | [diff] [blame] | 123 | Create a |
| 124 | :class:`~cryptogrpahy.hazmat.primitives.interfaces.HashContext` that |
Paul Kehrer | 4f776c4 | 2013-12-23 17:25:54 -0600 | [diff] [blame] | 125 | uses the specified ``algorithm`` to calculate a hash-based message |
| 126 | authentication code. |
David Reid | 6624a44 | 2013-11-18 12:44:30 -0800 | [diff] [blame] | 127 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 128 | :param algorithm: An instance of a |
| 129 | :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 130 | provider. |
| 131 | |
| 132 | :returns: |
| 133 | :class:`~cryptography.hazmat.primitives.interfaces.HashContext` |
Paul Kehrer | 1050ddf | 2014-01-27 21:04:03 -0600 | [diff] [blame^] | 134 | |
| 135 | |
| 136 | |
| 137 | .. class:: PBKDF2Backend |
| 138 | |
| 139 | A backend with methods for using PBKDF2. |
| 140 | |
| 141 | .. method:: pbkdf2_hash_supported(algorithm) |
| 142 | |
| 143 | Check if the specified ``algorithm`` is supported by this backend. |
| 144 | |
| 145 | :param algorithm: An instance of a |
| 146 | :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 147 | provider. |
| 148 | |
| 149 | :returns: ``True`` if the specified ``algorithm`` is supported for |
| 150 | PBKDF2 by this backend, otherwise ``False``. |
| 151 | |
| 152 | .. method:: derive_pbkdf2(self, algorithm, length, salt, iterations, |
| 153 | key_material) |
| 154 | |
| 155 | :param algorithm: An instance of a |
| 156 | :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 157 | provider. |
| 158 | |
| 159 | :param int length: The desired length of the derived key. Maximum is |
| 160 | 2\ :sup:`31` - 1. |
| 161 | |
| 162 | :param bytes salt: A salt. `RFC 2898`_ recommends 64-bits or longer. |
| 163 | |
| 164 | :param int iterations: The number of iterations to perform of the hash |
| 165 | function. |
| 166 | |
| 167 | :param bytes key_material: The key material to use as a basis for |
| 168 | the derived key. This is typically a password. |
| 169 | |
| 170 | :return bytes: Derived key. |
| 171 | |
| 172 | .. _`RFC 2898`: https://www.ietf.org/rfc/rfc2898.txt |