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 | |
| 9 | .. class:: CipherBackend |
| 10 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 11 | A backend which provides methods for using ciphers for encryption |
| 12 | and decryption. |
| 13 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 14 | .. method:: cipher_supported(cipher, mode) |
| 15 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 16 | Check if a ``cipher`` and ``mode`` combination is supported by |
| 17 | this backend. |
| 18 | |
| 19 | :param cipher: An instance of a |
| 20 | :class:`~cryptography.hazmat.primitives.interfaces.CipherAlgorithm` |
| 21 | provider. |
| 22 | :param mode: An instance of a |
| 23 | :class:`~cryptography.hazmat.primitives.interfaces.Mode` provider. |
| 24 | |
| 25 | :returns: ``True`` if the specified ``cipher`` and ``mode`` combination |
| 26 | is supported by this backend, otherwise ``False`` |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 27 | |
| 28 | .. method:: register_cipher_adapter(cipher_cls, mode_cls, adapter) |
| 29 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 30 | Register an adapter which can be used to create a backend specific |
| 31 | object from instances of the |
| 32 | :class:`~cryptography.hazmat.primitives.interfaces.CipherAlgorithm` and |
| 33 | the :class:`~cryptography.hazmat.primitives.interfaces.Mode` primitives. |
| 34 | |
| 35 | :param cipher_cls: A class whose instances provide |
| 36 | :class:`~cryptography.hazmat.primitives.interfaces.CipherAlgorithm` |
| 37 | :param mode_cls: A class whose instances provide: |
| 38 | :class:`~cryptography.hazmat.primitives.interfaces.Mode` |
| 39 | :param adapter: A ``function`` that takes 3 arguments, ``backend`` (a |
| 40 | :class:`CipherBackend` provider), ``cipher`` (a |
| 41 | :class:`~cryptography.hazmat.primitives.interfaces.CipherAlgorithm` |
| 42 | provider ), and ``mode`` (a |
| 43 | :class:`~cryptography.hazmat.primitives.interfaces.Mode` provider). |
| 44 | It returns a backend specific object which may be used to construct |
| 45 | a :class:`~cryptogrpahy.hazmat.primitives.interfaces.CipherContext`. |
| 46 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 47 | |
| 48 | .. method:: create_symmetric_encryption_ctx(cipher, mode) |
| 49 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 50 | Create a |
| 51 | :class:`~cryptogrpahy.hazmat.primitives.interfaces.CipherContext` that |
| 52 | can be used for encrypting data with the symmetric ``cipher`` using |
| 53 | the given ``mode``. |
| 54 | |
| 55 | :param cipher: An instance of a |
| 56 | :class:`~cryptography.hazmat.primitives.interfaces.CipherAlgorithm` |
| 57 | provider. |
| 58 | :param mode: An instance of a |
| 59 | :class:`~cryptography.hazmat.primitives.interfaces.Mode` provider. |
| 60 | |
| 61 | :returns: |
| 62 | :class:`~cryptography.hazmat.primitives.interfaces.CipherContext` |
| 63 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 64 | |
| 65 | .. method:: create_symmetric_decryption_ctx(cipher, mode) |
| 66 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 67 | Create a |
| 68 | :class:`~cryptogrpahy.hazmat.primitives.interfaces.CipherContext` that |
| 69 | can be used for decrypting data with the symmetric ``cipher`` using |
| 70 | the given ``mode``. |
| 71 | |
| 72 | :param cipher: An instance of a |
| 73 | :class:`~cryptography.hazmat.primitives.interfaces.CipherAlgorithm` |
| 74 | provider. |
| 75 | :param mode: An instance of a |
| 76 | :class:`~cryptography.hazmat.primitives.interfaces.Mode` provider. |
| 77 | |
| 78 | :returns: |
| 79 | :class:`~cryptography.hazmat.primitives.interfaces.CipherContext` |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 80 | |
| 81 | |
| 82 | .. class:: HashBackend |
| 83 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 84 | A backend with methods for using cryptographic hash functions. |
| 85 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 86 | .. method:: hash_supported(algorithm) |
| 87 | |
David Reid | 6624a44 | 2013-11-18 12:44:30 -0800 | [diff] [blame] | 88 | Check if the specified ``algorithm`` is supported by this backend. |
| 89 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 90 | :param algorithm: An instance of a |
| 91 | :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 92 | provider. |
| 93 | |
| 94 | :returns: ``True`` if the specified ``algorithm`` is supported by this |
| 95 | backend, otherwise ``False``. |
| 96 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 97 | |
| 98 | .. method:: create_hash_ctx(algorithm) |
| 99 | |
David Reid | 6624a44 | 2013-11-18 12:44:30 -0800 | [diff] [blame] | 100 | Create a |
| 101 | :class:`~cryptogrpahy.hazmat.primitives.interfaces.HashContext` that |
| 102 | uses the specified ``algorithm`` to calculate a message digest. |
| 103 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 104 | :param algorithm: An instance of a |
| 105 | :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 106 | provider. |
| 107 | |
| 108 | :returns: |
| 109 | :class:`~cryptography.hazmat.primitives.interfaces.HashContext` |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 110 | |
| 111 | |
| 112 | .. class:: HMACBackend |
| 113 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 114 | A backend with methods for using cryptographic hash functions as message |
| 115 | authentication codes. |
| 116 | |
David Reid | 2a746ce | 2013-11-15 15:32:14 -0800 | [diff] [blame] | 117 | .. method:: create_hmac_ctx(algorithm) |
| 118 | |
David Reid | 6624a44 | 2013-11-18 12:44:30 -0800 | [diff] [blame] | 119 | Create a |
| 120 | :class:`~cryptogrpahy.hazmat.primitives.interfaces.HashContext` that |
| 121 | uses the specified ``algorithm`` to calculate a hash-based message |
| 122 | authentication code. |
| 123 | |
David Reid | 5973f4c | 2013-11-18 11:29:44 -0800 | [diff] [blame] | 124 | :param algorithm: An instance of a |
| 125 | :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm` |
| 126 | provider. |
| 127 | |
| 128 | :returns: |
| 129 | :class:`~cryptography.hazmat.primitives.interfaces.HashContext` |