![]() Server : Apache/2.4.62 (Unix) OpenSSL/1.0.2k-fips System : Linux server1.richineiserver.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : fdshops ( 1003) PHP Version : 8.2.21 Disable Function : NONE Directory : /usr/share/doc/python2-cryptography-1.7.2/docs/development/custom-vectors/idea/ |
import binascii import botan from tests.utils import load_nist_vectors BLOCK_SIZE = 64 def encrypt(mode, key, iv, plaintext): encryptor = botan.Cipher("IDEA/{0}/NoPadding".format(mode), "encrypt", binascii.unhexlify(key)) cipher_text = encryptor.cipher(binascii.unhexlify(plaintext), binascii.unhexlify(iv)) return binascii.hexlify(cipher_text) def verify_vectors(mode, filename): with open(filename, "r") as f: vector_file = f.read().splitlines() vectors = load_nist_vectors(vector_file) for vector in vectors: ct = encrypt( mode, vector["key"], vector["iv"], vector["plaintext"] ) assert ct == vector["ciphertext"] cbc_path = "tests/hazmat/primitives/vectors/ciphers/IDEA/idea-cbc.txt" verify_vectors("CBC", cbc_path) ofb_path = "tests/hazmat/primitives/vectors/ciphers/IDEA/idea-ofb.txt" verify_vectors("OFB", ofb_path) cfb_path = "tests/hazmat/primitives/vectors/ciphers/IDEA/idea-cfb.txt" verify_vectors("CFB", cfb_path)