1import binascii
2
3import botan
4
5from tests.utils import load_nist_vectors
6
7
8def encrypt(mode, key, iv, plaintext):
9    encryptor = botan.Cipher("SEED/{0}/NoPadding".format(mode), "encrypt",
10                             binascii.unhexlify(key))
11
12    cipher_text = encryptor.cipher(binascii.unhexlify(plaintext),
13                                   binascii.unhexlify(iv))
14    return binascii.hexlify(cipher_text)
15
16
17def verify_vectors(mode, filename):
18    with open(filename, "r") as f:
19        vector_file = f.read().splitlines()
20
21    vectors = load_nist_vectors(vector_file)
22    for vector in vectors:
23        ct = encrypt(
24            mode,
25            vector["key"],
26            vector["iv"],
27            vector["plaintext"]
28        )
29        assert ct == vector["ciphertext"]
30
31
32ofb_path = "vectors/cryptography_vectors/ciphers/SEED/seed-ofb.txt"
33verify_vectors("OFB", ofb_path)
34cfb_path = "vectors/cryptography_vectors/ciphers/SEED/seed-cfb.txt"
35verify_vectors("CFB", cfb_path)
36