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.IDEA(b"\x00" * 16), modes.ECB() 22 ), 23 skip_message="Does not support IDEA ECB", 24) 25@pytest.mark.requires_backend_interface(interface=CipherBackend) 26class TestIDEAModeECB(object): 27 test_ecb = generate_encrypt_test( 28 load_nist_vectors, 29 os.path.join("ciphers", "IDEA"), 30 ["idea-ecb.txt"], 31 lambda key, **kwargs: algorithms.IDEA(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.IDEA(b"\x00" * 16), modes.CBC(b"\x00" * 8) 39 ), 40 skip_message="Does not support IDEA CBC", 41) 42@pytest.mark.requires_backend_interface(interface=CipherBackend) 43class TestIDEAModeCBC(object): 44 test_cbc = generate_encrypt_test( 45 load_nist_vectors, 46 os.path.join("ciphers", "IDEA"), 47 ["idea-cbc.txt"], 48 lambda key, **kwargs: algorithms.IDEA(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.IDEA(b"\x00" * 16), modes.OFB(b"\x00" * 8) 56 ), 57 skip_message="Does not support IDEA OFB", 58) 59@pytest.mark.requires_backend_interface(interface=CipherBackend) 60class TestIDEAModeOFB(object): 61 test_ofb = generate_encrypt_test( 62 load_nist_vectors, 63 os.path.join("ciphers", "IDEA"), 64 ["idea-ofb.txt"], 65 lambda key, **kwargs: algorithms.IDEA(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.IDEA(b"\x00" * 16), modes.CFB(b"\x00" * 8) 73 ), 74 skip_message="Does not support IDEA CFB", 75) 76@pytest.mark.requires_backend_interface(interface=CipherBackend) 77class TestIDEAModeCFB(object): 78 test_cfb = generate_encrypt_test( 79 load_nist_vectors, 80 os.path.join("ciphers", "IDEA"), 81 ["idea-cfb.txt"], 82 lambda key, **kwargs: algorithms.IDEA(binascii.unhexlify((key))), 83 lambda iv, **kwargs: modes.CFB(binascii.unhexlify(iv)), 84 ) 85