blob: c55d86dc0bce2732c51d058875c5a2e1e97abe9e [file] [log] [blame]
David Reid2a746ce2013-11-15 15:32:14 -08001.. hazmat::
2
3Backend Interfaces
4==================
5
6.. currentmodule:: cryptography.hazmat.bindings.interfaces
7
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
36 .. method:: register_cipher_adapter(cipher_cls, mode_cls, adapter)
37
David Reid5973f4c2013-11-18 11:29:44 -080038 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 Reid2a746ce2013-11-15 15:32:14 -080055
56 .. method:: create_symmetric_encryption_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 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 Reid2a746ce2013-11-15 15:32:14 -080072
73 .. method:: create_symmetric_decryption_ctx(cipher, mode)
74
David Reid5973f4c2013-11-18 11:29:44 -080075 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 Reid2a746ce2013-11-15 15:32:14 -080088
89
90.. class:: HashBackend
91
David Reid5973f4c2013-11-18 11:29:44 -080092 A backend with methods for using cryptographic hash functions.
93
David Reid2a746ce2013-11-15 15:32:14 -080094 .. method:: hash_supported(algorithm)
95
David Reid6624a442013-11-18 12:44:30 -080096 Check if the specified ``algorithm`` is supported by this backend.
97
David Reid5973f4c2013-11-18 11:29:44 -080098 :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 Reid2a746ce2013-11-15 15:32:14 -0800105
106 .. method:: create_hash_ctx(algorithm)
107
David Reid6624a442013-11-18 12:44:30 -0800108 Create a
109 :class:`~cryptogrpahy.hazmat.primitives.interfaces.HashContext` that
110 uses the specified ``algorithm`` to calculate a message digest.
111
David Reid5973f4c2013-11-18 11:29:44 -0800112 :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 Reid2a746ce2013-11-15 15:32:14 -0800118
119
120.. class:: HMACBackend
121
David Reid5973f4c2013-11-18 11:29:44 -0800122 A backend with methods for using cryptographic hash functions as message
123 authentication codes.
124
David Reid2a746ce2013-11-15 15:32:14 -0800125 .. method:: create_hmac_ctx(algorithm)
126
David Reid6624a442013-11-18 12:44:30 -0800127 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 Reid5973f4c2013-11-18 11:29:44 -0800132 :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`