blob: 5b3e852abad7d2e811402906e47974f1911e5590 [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
Paul Kehrer98e40e62014-01-28 15:07:49 -0600136.. class:: PBKDF2HMACBackend
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600137
Paul Kehrer5d1af212014-01-28 12:19:32 -0600138 .. versionadded:: 0.2
139
Paul Kehrer98e40e62014-01-28 15:07:49 -0600140 A backend with methods for using PBKDF2 using HMAC as a PRF.
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600141
Paul Kehrer98e40e62014-01-28 15:07:49 -0600142 .. method:: pbkdf2_hmac_supported(algorithm)
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600143
144 Check if the specified ``algorithm`` is supported by this backend.
145
Paul Kehrer589b9082014-01-28 21:25:41 -0600146 :param algorithm: An instance of a
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600147 :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm`
148 provider.
149
150 :returns: ``True`` if the specified ``algorithm`` is supported for
Paul Kehrer98e40e62014-01-28 15:07:49 -0600151 PBKDF2 HMAC by this backend, otherwise ``False``.
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600152
Paul Kehrer98e40e62014-01-28 15:07:49 -0600153 .. method:: derive_pbkdf2_hmac(self, algorithm, length, salt, iterations,
154 key_material)
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600155
156 :param algorithm: An instance of a
157 :class:`~cryptography.hazmat.primitives.interfaces.HashAlgorithm`
158 provider.
159
160 :param int length: The desired length of the derived key. Maximum is
Paul Kehrer98e40e62014-01-28 15:07:49 -0600161 (2\ :sup:`32` - 1) * ``algorithm.digest_size``
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600162
Paul Kehrerb6d764c2014-01-27 22:32:11 -0600163 :param bytes salt: A salt.
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600164
165 :param int iterations: The number of iterations to perform of the hash
Paul Kehrerc58b4782014-01-29 13:56:25 -0600166 function. This can be used to control the length of time the
167 operation takes. Higher numbers help mitigate brute force attacks
168 against derived keys.
Paul Kehrer1050ddf2014-01-27 21:04:03 -0600169
170 :param bytes key_material: The key material to use as a basis for
171 the derived key. This is typically a password.
172
173 :return bytes: Derived key.
174