diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-02-16 19:32:04 -0600 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-02-16 19:32:04 -0600 |
commit | b09622ccb6e3403e314395ff56fb787efb73bb1b (patch) | |
tree | 55ae993d3b969cb03cd16baad6fe59fc782003d4 /docs | |
parent | 597d64c06a0ddcf2d920e69e9ff98228086e2bad (diff) | |
download | cryptography-b09622ccb6e3403e314395ff56fb787efb73bb1b.tar.gz cryptography-b09622ccb6e3403e314395ff56fb787efb73bb1b.tar.bz2 cryptography-b09622ccb6e3403e314395ff56fb787efb73bb1b.zip |
add beginning of IDEA vector source docs. no verification code yet
Diffstat (limited to 'docs')
-rw-r--r-- | docs/development/custom-vectors/idea.rst | 25 | ||||
-rw-r--r-- | docs/development/custom-vectors/idea/generate_idea.py | 59 | ||||
-rw-r--r-- | docs/development/test-vectors.rst | 7 |
3 files changed, 90 insertions, 1 deletions
diff --git a/docs/development/custom-vectors/idea.rst b/docs/development/custom-vectors/idea.rst new file mode 100644 index 00000000..097819ed --- /dev/null +++ b/docs/development/custom-vectors/idea.rst @@ -0,0 +1,25 @@ +IDEA Vector Creation +===================== + +This page documents the code that was used to generate the IDEA CBC, CFB, and +OFB test vectors as well as the code used to verify them against another +implementation. For IDEA the vectors were generated using OpenSSL and verified +with Go. + +Creation +-------- + +``cryptography`` was modified to support IDEA in CBC, CFB, and OFB modes. Then +the following python script was run to generate the vector files. + +.. literalinclude:: /development/custom-vectors/idea/generate_idea.py + +Download link: :download:`generate_idea.py </development/custom-vectors/idea/generate_idea.py>` + + +Verification +------------ + +The following go code was used to verify the vectors. + +TODO: verify the vectors. diff --git a/docs/development/custom-vectors/idea/generate_idea.py b/docs/development/custom-vectors/idea/generate_idea.py new file mode 100644 index 00000000..c8fe7ed5 --- /dev/null +++ b/docs/development/custom-vectors/idea/generate_idea.py @@ -0,0 +1,59 @@ +import binascii + +from cryptography.hazmat.backends.openssl.backend import backend +from cryptography.hazmat.primitives.ciphers import base, algorithms, modes + + +def encrypt(mode, key, iv, plaintext): + cipher = base.Cipher( + algorithms.IDEA(binascii.unhexlify(key)), + mode(binascii.unhexlify(iv)), + backend + ) + encryptor = cipher.encryptor() + ct = encryptor.update(binascii.unhexlify(plaintext)) + ct += encryptor.finalize() + return binascii.hexlify(ct) + + +def build_vectors(mode, filename): + vector_file = open(filename, "r") + + count = 0 + output = [] + key = None + iv = None + plaintext = None + for line in vector_file: + line = line.strip() + if line.startswith("KEY"): + if count != 0: + output.append("CIPHERTEXT = {}".format( + encrypt(mode, key, iv, plaintext)) + ) + output.append("\nCOUNT = {}".format(count)) + count += 1 + name, key = line.split(" = ") + output.append("KEY = {}".format(key)) + elif line.startswith("IV"): + name, iv = line.split(" = ") + iv = iv[0:16] + output.append("IV = {}".format(iv)) + elif line.startswith("PLAINTEXT"): + name, plaintext = line.split(" = ") + output.append("PLAINTEXT = {}".format(plaintext)) + + output.append("CIPHERTEXT = {}".format(encrypt(mode, key, iv, plaintext))) + return "\n".join(output) + + +def write_file(data, filename): + with open(filename, "w") as f: + f.write(data) + +cbc_path = "tests/hazmat/primitives/vectors/ciphers/AES/CBC/CBCMMT128.rsp" +write_file(build_vectors(modes.CBC, cbc_path), "idea-cbc.txt") +ofb_path = "tests/hazmat/primitives/vectors/ciphers/AES/OFB/OFBMMT128.rsp" +write_file(build_vectors(modes.OFB, ofb_path), "idea-ofb.txt") +cfb_path = "tests/hazmat/primitives/vectors/ciphers/AES/CFB/CFB128MMT128.rsp" +write_file(build_vectors(modes.CFB, cfb_path), "idea-cfb.txt") diff --git a/docs/development/test-vectors.rst b/docs/development/test-vectors.rst index 3b8632e6..8b3a6460 100644 --- a/docs/development/test-vectors.rst +++ b/docs/development/test-vectors.rst @@ -56,7 +56,9 @@ Symmetric Ciphers * CAST5 (ECB) from :rfc:`2144`. * CAST5 (CBC, CFB, OFB) generated by this project. See: :doc:`/development/custom-vectors/cast5` - +* IDEA (ECB) from the `NESSIE IDEA vectors`_ created by `NESSIE`_. +* IDEA (CBC, CFB, OFB) generated by this project. + See: :doc:`/development/custom-vectors/idea` Creating Test Vectors --------------------- @@ -68,6 +70,7 @@ its own using existing vectors as source material. Current custom vectors: :maxdepth: 1 custom-vectors/cast5 + custom-vectors/idea If official test vectors appear in the future the custom generated vectors should be discarded. @@ -92,3 +95,5 @@ header format (substituting the correct information): .. _`RIPEMD website`: http://homes.esat.kuleuven.be/~bosselae/ripemd160.html .. _`Whirlpool website`: http://www.larc.usp.br/~pbarreto/WhirlpoolPage.html .. _`Specification repository`: https://github.com/fernet/spec +.. _`NESSIE IDEA vectors`: https://www.cosic.esat.kuleuven.be/nessie/testvectors/bc/idea/Idea-128-64.verified.test-vectors +.. _`NESSIE`: https://en.wikipedia.org/wiki/NESSIE |