David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 1 | .. hazmat:: |
| 2 | |
| 3 | Backend Interfaces |
| 4 | ================== |
| 5 | |
| 6 | .. currentmodule:: cryptography.hazmat.bindings.interfaces |
| 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 | |
| 36 | .. method:: register_cipher_adapter(cipher_cls, mode_cls, adapter) |
| 37 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 38 | Register an adapter which can be used to create a backend specific |
| 39 | object from instances of the |
| 40 | :class:`~cryptography.hazmat.primitives.interfaces.CipherAlgorithm` and |
| 41 | the :class:`~cryptography.hazmat.primitives.interfaces.Mode` primitives. |
| 42 | |
| 43 | :param cipher_cls: A class whose instances provide |
| 44 | :class:`~cryptography.hazmat.primitives.interfaces.CipherAlgorithm` |
| 45 | :param mode_cls: A class whose instances provide: |
| 46 | :class:`~cryptography.hazmat.primitives.interfaces.Mode` |
| 47 | :param adapter: A ``function`` that takes 3 arguments, ``backend`` (a |
| 48 | :class:`CipherBackend` provider), ``cipher`` (a |
| 49 | :class:`~cryptography.hazmat.primitives.interfaces.CipherAlgorithm` |
| 50 | provider ), and ``mode`` (a |
| 51 | :class:`~cryptography.hazmat.primitives.interfaces.Mode` provider). |
| 52 | It returns a backend specific object which may be used to construct |
| 53 | a :class:`~cryptogrpahy.hazmat.primitives.interfaces.CipherContext`. |
| 54 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 55 | |
| 56 | .. method:: create_symmetric_encryption_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 encrypting 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` |
| 71 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 72 | |
| 73 | .. method:: create_symmetric_decryption_ctx(cipher, mode) |
| 74 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 75 | Create a |
| 76 | :class:`~cryptogrpahy.hazmat.primitives.interfaces.CipherContext` that |
| 77 | can be used for decrypting data with the symmetric ``cipher`` using |
| 78 | the given ``mode``. |
| 79 | |
| 80 | :param cipher: An instance of a |
| 81 | :class:`~cryptography.hazmat.primitives.interfaces.CipherAlgorithm` |
| 82 | provider. |
| 83 | :param mode: An instance of a |
| 84 | :class:`~cryptography.hazmat.primitives.interfaces.Mode` provider. |
| 85 | |
| 86 | :returns: |
| 87 | :class:`~cryptography.hazmat.primitives.interfaces.CipherContext` |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 88 | |
| 89 | |
| 90 | .. class:: HashBackend |
| 91 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 92 | A backend with methods for using cryptographic hash functions. |
| 93 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 94 | .. method:: hash_supported(algorithm) |
| 95 | |
David Reid | 6624a44 | 2013-11-18 12:44:30 -0800 | [diff] [blame] | 96 | Check if the specified ``algorithm`` is supported by this backend. |
| 97 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 98 | :param algorithm: An instance of a |
| 99 | :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 100 | provider. |
| 101 | |
| 102 | :returns: ``True`` if the specified ``algorithm`` is supported by this |
| 103 | backend, otherwise ``False``. |
| 104 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 105 | |
| 106 | .. method:: create_hash_ctx(algorithm) |
| 107 | |
David Reid | 6624a44 | 2013-11-18 12:44:30 -0800 | [diff] [blame] | 108 | Create a |
| 109 | :class:`~cryptogrpahy.hazmat.primitives.interfaces.HashContext` that |
| 110 | uses the specified ``algorithm`` to calculate a message digest. |
| 111 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 112 | :param algorithm: An instance of a |
| 113 | :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 114 | provider. |
| 115 | |
| 116 | :returns: |
| 117 | :class:`~cryptography.hazmat.primitives.interfaces.HashContext` |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 118 | |
| 119 | |
| 120 | .. class:: HMACBackend |
| 121 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 122 | A backend with methods for using cryptographic hash functions as message |
| 123 | authentication codes. |
| 124 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 125 | .. method:: create_hmac_ctx(algorithm) |
| 126 | |
David Reid | 6624a44 | 2013-11-18 12:44:30 -0800 | [diff] [blame] | 127 | Create a |
| 128 | :class:`~cryptogrpahy.hazmat.primitives.interfaces.HashContext` that |
| 129 | uses the specified ``algorithm`` to calculate a hash-based message |
| 130 | authentication code. |
| 131 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 132 | :param algorithm: An instance of a |
| 133 | :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 134 | provider. |
| 135 | |
| 136 | :returns: |
| 137 | :class:`~cryptography.hazmat.primitives.interfaces.HashContext` |