# This file is dual licensed under the terms of the Apache License, Version # 2.0, and the BSD License. See the LICENSE file in the root of this repository # for complete details. from __future__ import absolute_import, division, print_function import binascii import os import struct import pytest from cryptography.hazmat.backends.interfaces import CipherBackend from cryptography.hazmat.primitives.ciphers import Cipher, algorithms from .utils import _load_all_params from ...utils import load_nist_vectors @pytest.mark.supported( only_if=lambda backend: backend.cipher_supported( algorithms.ChaCha20(b"\x00" * 32, b"0" * 16), None ), skip_message="Does not support ChaCha20", ) @pytest.mark.requires_backend_interface(interface=CipherBackend) class TestChaCha20(object): @pytest.mark.parametrize( "vector", _load_all_params( os.path.join("ciphers", "ChaCha20"), ["rfc7539.txt"], load_nist_vectors ) ) def test_vectors(self, vector, backend): key = binascii.unhexlify(vector["key"]) nonce = binascii.unhexlify(vector["nonce"]) ibc = struct.pack("