blob: 98c099bbccc8636b631cfd3b71a0bbb5c47ae1cd [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
9.. class:: CipherBackend
10
David Reid5973f4c2013-11-18 11:29:44 -080011 A backend which provides methods for using ciphers for encryption
12 and decryption.
13
David Reid2a746ce2013-11-15 15:32:14 -080014 .. method:: cipher_supported(cipher, mode)
15
David Reid5973f4c2013-11-18 11:29:44 -080016 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 Reid2a746ce2013-11-15 15:32:14 -080027
28 .. method:: register_cipher_adapter(cipher_cls, mode_cls, adapter)
29
David Reid5973f4c2013-11-18 11:29:44 -080030 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 Reid2a746ce2013-11-15 15:32:14 -080047
48 .. method:: create_symmetric_encryption_ctx(cipher, mode)
49
David Reid5973f4c2013-11-18 11:29:44 -080050 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 Reid2a746ce2013-11-15 15:32:14 -080064
65 .. method:: create_symmetric_decryption_ctx(cipher, mode)
66
David Reid5973f4c2013-11-18 11:29:44 -080067 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 Reid2a746ce2013-11-15 15:32:14 -080080
81
82.. class:: HashBackend
83
David Reid5973f4c2013-11-18 11:29:44 -080084 A backend with methods for using cryptographic hash functions.
85
David Reid2a746ce2013-11-15 15:32:14 -080086 .. method:: hash_supported(algorithm)
87
David Reid6624a442013-11-18 12:44:30 -080088 Check if the specified ``algorithm`` is supported by this backend.
89
David Reid5973f4c2013-11-18 11:29:44 -080090 :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 Reid2a746ce2013-11-15 15:32:14 -080097
98 .. method:: create_hash_ctx(algorithm)
99
David Reid6624a442013-11-18 12:44:30 -0800100 Create a
101 :class:`~cryptogrpahy.hazmat.primitives.interfaces.HashContext` that
102 uses the specified ``algorithm`` to calculate a message digest.
103
David Reid5973f4c2013-11-18 11:29:44 -0800104 :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 Reid2a746ce2013-11-15 15:32:14 -0800110
111
112.. class:: HMACBackend
113
David Reid5973f4c2013-11-18 11:29:44 -0800114 A backend with methods for using cryptographic hash functions as message
115 authentication codes.
116
David Reid2a746ce2013-11-15 15:32:14 -0800117 .. method:: create_hmac_ctx(algorithm)
118
David Reid6624a442013-11-18 12:44:30 -0800119 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 Reid5973f4c2013-11-18 11:29:44 -0800124 :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`