1
  #   ˆl–Ãa¾”ªeJu@·pÜlJbÑ¿¿„M‰ÏÂÁ ?÷     .. hazmat::

Backend interfaces
==================

.. currentmodule:: cryptography.hazmat.backends.interfaces


Backend implementations may provide a number of interfaces to support
operations such as :doc:`/hazmat/primitives/symmetric-encryption`,
:doc:`/hazmat/primitives/cryptographic-hashes`, and
:doc:`/hazmat/primitives/mac/hmac`.

A specific ``backend`` may provide one or more of these interfaces.


.. class:: CipherBackend

    A backend that provides methods for using ciphers for encryption
    and decryption.

    The following backends implement this interface:

    * :doc:`/hazmat/backends/openssl`
    * :doc:`/hazmat/backends/commoncrypto`

    .. method:: cipher_supported(cipher, mode)

        Check if a ``cipher`` and ``mode`` combination is supported by
        this backend.

        :param cipher: An instance of
            :class:`~cryptography.hazmat.primitives.ciphers.CipherAlgorithm`.

        :param mode: An instance of
            :class:`~cryptography.hazmat.primitives.ciphers.modes.Mode`.

        :returns: ``True`` if the specified ``cipher`` and ``mode`` combination
            is supported by this backend, otherwise ``False``


    .. method:: create_symmetric_encryption_ctx(cipher, mode)

        Create a
        :class:`~cryptography.hazmat.primitives.ciphers.CipherContext` that
        can be used for encrypting data with the symmetric ``cipher`` using
        the given ``mode``.

        :param cipher: An instance of
            :class:`~cryptography.hazmat.primitives.ciphers.CipherAlgorithm`.

        :param mode: An instance of
            :class:`~cryptography.hazmat.primitives.ciphers.modes.Mode`.

        :returns:
            :class:`~cryptography.hazmat.primitives.ciphers.CipherContext`

        :raises ValueError: When tag is not None in an AEAD mode


    .. method:: create_symmetric_decryption_ctx(cipher, mode)

        Create a
        :class:`~cryptography.hazmat.primitives.ciphers.CipherContext` that
        can be used for decrypting data with the symmetric ``cipher`` using
        the given ``mode``.

        :param cipher: An instance of
            :class:`~cryptography.hazmat.primitives.ciphers.CipherAlgorithm`.

        :param mode: An instance of
            :class:`~cryptography.hazmat.primitives.ciphers.modes.Mode`.

        :returns:
            :class:`~cryptography.hazmat.primitives.ciphers.CipherContext`

        :raises ValueError: When tag is None in an AEAD mode


.. class:: HashBackend

    A backend with methods for using cryptographic hash functions.

    The following backends implement this interface:

    * :doc:`/hazmat/backends/openssl`
    * :doc:`/hazmat/backends/commoncrypto`

    .. method:: hash_supported(algorithm)

        Check if the specified ``algorithm`` is supported by this backend.

        :param algorithm: An instance of
            :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`.

        :returns: ``True`` if the specified ``algorithm`` is supported by this
            backend, otherwise ``False``.


    .. method:: create_hash_ctx(algorithm)

        Create a
        :class:`~cryptography.hazmat.primitives.hashes.HashContext` that
        uses the specified ``algorithm`` to calculate a message digest.

        :param algorithm: An instance of
            :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`.

        :returns:
            :class:`~cryptography.hazmat.primitives.hashes.HashContext`


.. class:: HMACBackend

    A backend with methods for using cryptographic hash functions as message
    authentication codes.

    The following backends implement this interface:

    * :doc:`/hazmat/backends/openssl`
    * :doc:`/hazmat/backends/commoncrypto`

    .. method:: hmac_supported(algorithm)

        Check if the specified ``algorithm`` is supported by this backend.

        :param algorithm: An instance of
            :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`.

        :returns: ``True`` if the specified ``algorithm`` is supported