diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-03-08 11:11:56 -0400 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-03-08 11:58:25 -0400 |
commit | ae28ca2648e71f0f1c420cf39c042184bff6cdf4 (patch) | |
tree | 1b81c6769c5a41afebfdc86595dc7daa5f260dec /docs/development/custom-vectors/idea/verify_idea.py | |
parent | bf2a9d9545f39ad0dd9b9c9c4aa2f7f2b5669f0f (diff) | |
download | cryptography-ae28ca2648e71f0f1c420cf39c042184bff6cdf4.tar.gz cryptography-ae28ca2648e71f0f1c420cf39c042184bff6cdf4.tar.bz2 cryptography-ae28ca2648e71f0f1c420cf39c042184bff6cdf4.zip |
update headers, add verification code
Diffstat (limited to 'docs/development/custom-vectors/idea/verify_idea.py')
-rw-r--r-- | docs/development/custom-vectors/idea/verify_idea.py | 37 |
1 files changed, 37 insertions, 0 deletions
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) |