diff options
5 files changed, 50 insertions, 7 deletions
diff --git a/docs/development/custom-vectors/idea.rst b/docs/development/custom-vectors/idea.rst index 097819ed..68c00b85 100644 --- a/docs/development/custom-vectors/idea.rst +++ b/docs/development/custom-vectors/idea.rst @@ -20,6 +20,11 @@ Download link: :download:`generate_idea.py </development/custom-vectors/idea/gen Verification ------------ -The following go code was used to verify the vectors. +The following python code was used to verify the vectors using the `Botan`_ +project's Python bindings. -TODO: verify the vectors. +.. literalinclude:: /development/custom-vectors/idea/verify_idea.py + +Download link: :download:`verify_idea.py </development/custom-vectors/idea/verify_idea.py>` + +.. _`Botan`: http://botan.randombit.net diff --git a/docs/development/custom-vectors/idea/verify_idea.py b/docs/development/custom-vectors/idea/verify_idea.py new file mode 100644 index 00000000..692cc76e --- /dev/null +++ b/docs/development/custom-vectors/idea/verify_idea.py @@ -0,0 +1,37 @@ +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): + vector_file = open(filename, "r") + 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) diff --git a/tests/hazmat/primitives/vectors/ciphers/IDEA/idea-cbc.txt b/tests/hazmat/primitives/vectors/ciphers/IDEA/idea-cbc.txt index e8da93be..dac78c23 100644 --- a/tests/hazmat/primitives/vectors/ciphers/IDEA/idea-cbc.txt +++ b/tests/hazmat/primitives/vectors/ciphers/IDEA/idea-cbc.txt @@ -1,8 +1,8 @@ -# IDEA CBC vectors built for https://cryptography.io +# IDEA CBC vectors built for https://github.com/pyca/cryptography # Derived from the AESVS MMT test data for CBC +# Verified against Botan # Key Length : 128 - COUNT = 0 KEY = 1f8e4973953f3fb0bd6b16662e9a3c17 IV = 2fe2b333ceda8f98 diff --git a/tests/hazmat/primitives/vectors/ciphers/IDEA/idea-cfb.txt b/tests/hazmat/primitives/vectors/ciphers/IDEA/idea-cfb.txt index 0423b9cd..090b6a3c 100644 --- a/tests/hazmat/primitives/vectors/ciphers/IDEA/idea-cfb.txt +++ b/tests/hazmat/primitives/vectors/ciphers/IDEA/idea-cfb.txt @@ -1,5 +1,6 @@ -# IDEA CFB128 vectors built for https://cryptography.io +# IDEA CFB vectors built for https://github.com/pyca/cryptography # Derived from the AESVS MMT test data for CFB128 +# Verified against Botan # Key Length : 128 COUNT = 0 diff --git a/tests/hazmat/primitives/vectors/ciphers/IDEA/idea-ofb.txt b/tests/hazmat/primitives/vectors/ciphers/IDEA/idea-ofb.txt index 3ac5dacd..c3d02a77 100644 --- a/tests/hazmat/primitives/vectors/ciphers/IDEA/idea-ofb.txt +++ b/tests/hazmat/primitives/vectors/ciphers/IDEA/idea-ofb.txt @@ -1,8 +1,8 @@ -# IDEA OFB vectors built for https://cryptography.io +# IDEA OFB vectors built for https://github.com/pyca/cryptography # Derived from the AESVS MMT test data for OFB +# Verified against Botan # Key Length : 128 - COUNT = 0 KEY = d7d57bd847154af9722a8df096e61a42 IV = fdde201c91e401d9 |