aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/800-38a.py
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2015-06-04 08:05:49 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2015-06-04 08:05:49 +0300
commit31eb9272bedd00476b6b109e282465940925d716 (patch)
tree3dda74824495d2d32f1002ea79a86d1067c3f817 /test/800-38a.py
parentadd .gitignore (diff)
downloadaes-tools-31eb9272bedd00476b6b109e282465940925d716.tar.gz
aes-tools-31eb9272bedd00476b6b109e282465940925d716.zip
test: add test vectors from NIST 800-38A
Diffstat (limited to '')
-rw-r--r--test/800-38a.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/800-38a.py b/test/800-38a.py
new file mode 100644
index 0000000..b029890
--- /dev/null
+++ b/test/800-38a.py
@@ -0,0 +1,33 @@
+# Copyright 2015 Egor Tensin <Egor.Tensin@gmail.com>
+# This file is licensed under the terms of the MIT License.
+# See LICENSE.txt for details.
+
+if __name__ == '__main__':
+ import argparse, json, toolkit, sys
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--root', '-r', required=True,
+ help='set path to *.exe files')
+ parser.add_argument('--sde', '-e', action='store_true',
+ help='use Intel SDE to run *.exe files')
+ args = parser.parse_args()
+ tools = toolkit.Tools('C:\\build\\test\\Debug', use_sde=args.sde)
+ vectors = json.load(open('800-38a.json'))
+ success = True
+ for prefix in vectors:
+ if 'iv' in vectors[prefix]:
+ iv = vectors[prefix]['iv']
+ encrypt = lambda key, plaintexts: tools.encrypt_with_iv(prefix, key, iv, plaintexts)
+ decrypt = lambda key, ciphers: tools.decrypt_with_iv(prefix, key, iv, ciphers)
+ else:
+ encrypt = lambda key, plaintexts: tools.encrypt(prefix, key, plaintexts)
+ decrypt = lambda key, ciphers: tools.decrypt(prefix, key, ciphers)
+ key = vectors[prefix]['key']
+ plaintexts = vectors[prefix]['plaintexts']
+ ciphers = vectors[prefix]['ciphers']
+ success = success and tools.detect_mismatches(plaintexts, encrypt(key, plaintexts), ciphers)
+ success = success and tools.detect_mismatches(ciphers, decrypt(key, ciphers), plaintexts)
+ if success:
+ print('No mismatches detected!')
+ else:
+ print('Detected mismatches!')
+ sys.exit(1)