aboutsummaryrefslogtreecommitdiffstats
path: root/docs/development
diff options
context:
space:
mode:
Diffstat (limited to 'docs/development')
-rw-r--r--docs/development/custom-vectors/idea.rst25
-rw-r--r--docs/development/custom-vectors/idea/generate_idea.py59
-rw-r--r--docs/development/test-vectors.rst4
3 files changed, 87 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 a70b82d3..1d768179 100644
--- a/docs/development/test-vectors.rst
+++ b/docs/development/test-vectors.rst
@@ -69,6 +69,8 @@ Symmetric Ciphers
* 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`
Two Factor Authentication
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -77,7 +79,6 @@ Two Factor Authentication
* TOTP from :rfc:`6238` (Note that an `errata`_ for the test vectors in RFC
6238 exists)
-
Creating Test Vectors
---------------------
@@ -88,6 +89,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.