1# This file is dual licensed under the terms of the Apache License, Version 2# 2.0, and the BSD License. See the LICENSE file in the root of this repository 3# for complete details. 4 5from __future__ import absolute_import, division, print_function 6 7import binascii 8import os 9 10import pytest 11 12from cryptography.hazmat.backends.interfaces import CipherBackend 13from cryptography.hazmat.primitives.ciphers import algorithms, modes 14 15from .utils import generate_encrypt_test 16from ...utils import load_nist_vectors 17 18 19@pytest.mark.supported( 20 only_if=lambda backend: backend.cipher_supported( 21 algorithms.CAST5(b"\x00" * 16), modes.ECB() 22 ), 23 skip_message="Does not support CAST5 ECB", 24) 25@pytest.mark.requires_backend_interface(interface=CipherBackend) 26class TestCAST5ModeECB(object): 27 test_ecb = generate_encrypt_test( 28 load_nist_vectors, 29 os.path.join("ciphers", "CAST5"), 30 ["cast5-ecb.txt"], 31 lambda key, **kwargs: algorithms.CAST5(binascii.unhexlify((key))), 32 lambda **kwargs: modes.ECB(), 33 ) 34 35 36@pytest.mark.supported( 37 only_if=lambda backend: backend.cipher_supported( 38 algorithms.CAST5(b"\x00" * 16), modes.CBC(b"\x00" * 8) 39 ), 40 skip_message="Does not support CAST5 CBC", 41) 42@pytest.mark.requires_backend_interface(interface=CipherBackend) 43class TestCAST5ModeCBC(object): 44 test_cbc = generate_encrypt_test( 45 load_nist_vectors, 46 os.path.join("ciphers", "CAST5"), 47 ["cast5-cbc.txt"], 48 lambda key, **kwargs: algorithms.CAST5(binascii.unhexlify((key))), 49 lambda iv, **kwargs: modes.CBC(binascii.unhexlify(iv)), 50 ) 51 52 53@pytest.mark.supported( 54 only_if=lambda backend: backend.cipher_supported( 55 algorithms.CAST5(b"\x00" * 16), modes.OFB(b"\x00" * 8) 56 ), 57 skip_message="Does not support CAST5 OFB", 58) 59@pytest.mark.requires_backend_interface(interface=CipherBackend) 60class TestCAST5ModeOFB(object): 61 test_ofb = generate_encrypt_test( 62 load_nist_vectors, 63 os.path.join("ciphers", "CAST5"), 64 ["cast5-ofb.txt"], 65 lambda key, **kwargs: algorithms.CAST5(binascii.unhexlify((key))), 66 lambda iv, **kwargs: modes.OFB(binascii.unhexlify(iv)), 67 ) 68 69 70@pytest.mark.supported( 71 only_if=lambda backend: backend.cipher_supported( 72 algorithms.CAST5(b"\x00" * 16), modes.CFB(b"\x00" * 8) 73 ), 74 skip_message="Does not support CAST5 CFB", 75) 76@pytest.mark.requires_backend_interface(interface=CipherBackend) 77class TestCAST5ModeCFB(object): 78 test_cfb = generate_encrypt_test( 79 load_nist_vectors, 80 os.path.join("ciphers", "CAST5"), 81 ["cast5-cfb.txt"], 82 lambda key, **kwargs: algorithms.CAST5(binascii.unhexlify((key))), 83 lambda iv, **kwargs: modes.CFB(binascii.unhexlify(iv)), 84 ) 85