blob: fa4f800ce39fdd6d136cb167f7ba6903e3a04d5e [file] [log] [blame]
David Reid2a746ce2013-11-15 15:32:14 -08001.. hazmat::
2
3Backend Interfaces
4==================
5
Alex Gaynorf8796b12013-12-13 20:28:55 -08006.. currentmodule:: cryptography.hazmat.backends.interfaces
David Reid2a746ce2013-11-15 15:32:14 -08007
8
David Reid6b9df812013-11-18 14:13:02 -08009Backend implementations may provide a number of interfaces to support operations
10such as :doc:`/hazmat/primitives/symmetric-encryption`,
11:doc:`/hazmat/primitives/cryptographic-hashes`, and
12:doc:`/hazmat/primitives/hmac`.
13
14A specific ``backend`` may provide one or more of these interfaces.
15
16
David Reid2a746ce2013-11-15 15:32:14 -080017.. class:: CipherBackend
18
David Reid5973f4c2013-11-18 11:29:44 -080019 A backend which provides methods for using ciphers for encryption
20 and decryption.
21
David Reid2a746ce2013-11-15 15:32:14 -080022 .. method:: cipher_supported(cipher, mode)
23
David Reid5973f4c2013-11-18 11:29:44 -080024 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 Reid2a746ce2013-11-15 15:32:14 -080035
David Reid2a746ce2013-11-15 15:32:14 -080036
37 .. method:: create_symmetric_encryption_ctx(cipher, mode)
38
David Reid5973f4c2013-11-18 11:29:44 -080039 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 Kehrera07925a2013-12-06 11:49:42 -060053 :raises ValueError: When tag is not None in an AEAD mode
54
David Reid2a746ce2013-11-15 15:32:14 -080055
56 .. method:: create_symmetric_decryption_ctx(cipher, mode)
57
David Reid5973f4c2013-11-18 11:29:44 -080058 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 Reid2a746ce2013-11-15 15:32:14 -080071
Paul Kehrera07925a2013-12-06 11:49:42 -060072 :raises ValueError: When tag is None in an AEAD mode
73
David Reid2a746ce2013-11-15 15:32:14 -080074
75.. class:: HashBackend
76
David Reid5973f4c2013-11-18 11:29:44 -080077 A backend with methods for using cryptographic hash functions.
78
David Reid2a746ce2013-11-15 15:32:14 -080079 .. method:: hash_supported(algorithm)
80
David Reid6624a442013-11-18 12:44:30 -080081 Check if the specified ``algorithm`` is supported by this backend.
82
David Reid5973f4c2013-11-18 11:29:44 -080083 :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 Reid2a746ce2013-11-15 15:32:14 -080090
91 .. method:: create_hash_ctx(algorithm)
92
David Reid6624a442013-11-18 12:44:30 -080093 Create a
94 :class:`~cryptogrpahy.hazmat.primitives.interfaces.HashContext` that
95 uses the specified ``algorithm`` to calculate a message digest.
96
David Reid5973f4c2013-11-18 11:29:44 -080097 :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 Reid2a746ce2013-11-15 15:32:14 -0800103
104
105.. class:: HMACBackend
106
David Reid5973f4c2013-11-18 11:29:44 -0800107 A backend with methods for using cryptographic hash functions as message
108 authentication codes.
109
Paul Kehrer90ae8662013-12-23 17:21:00 -0600110 .. 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 Reid2a746ce2013-11-15 15:32:14 -0800121 .. method:: create_hmac_ctx(algorithm)
122
David Reid6624a442013-11-18 12:44:30 -0800123 Create a
124 :class:`~cryptogrpahy.hazmat.primitives.interfaces.HashContext` that
Paul Kehrer4f776c42013-12-23 17:25:54 -0600125 uses the specified ``algorithm`` to calculate a hash-based message
126 authentication code.
David Reid6624a442013-11-18 12:44:30 -0800127
David Reid5973f4c2013-11-18 11:29:44 -0800128 :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 Kehrer1050ddf2014-01-27 21:04:03 -0600134
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