aboutsummaryrefslogtreecommitdiffstats
path: root/docs/development/custom-vectors
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-03-08 11:11:56 -0400
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-03-08 11:58:25 -0400
commitae28ca2648e71f0f1c420cf39c042184bff6cdf4 (patch)
tree1b81c6769c5a41afebfdc86595dc7daa5f260dec /docs/development/custom-vectors
parentbf2a9d9545f39ad0dd9b9c9c4aa2f7f2b5669f0f (diff)
downloadcryptography-ae28ca2648e71f0f1c420cf39c042184bff6cdf4.tar.gz
cryptography-ae28ca2648e71f0f1c420cf39c042184bff6cdf4.tar.bz2
cryptography-ae28ca2648e71f0f1c420cf39c042184bff6cdf4.zip
update headers, add verification code
Diffstat (limited to 'docs/development/custom-vectors')
-rw-r--r--docs/development/custom-vectors/idea.rst9
-rw-r--r--docs/development/custom-vectors/idea/verify_idea.py37
2 files changed, 44 insertions, 2 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)