diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2015-06-04 08:05:49 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2015-06-04 08:05:49 +0300 |
commit | 31eb9272bedd00476b6b109e282465940925d716 (patch) | |
tree | 3dda74824495d2d32f1002ea79a86d1067c3f817 /test/800-38a.py | |
parent | add .gitignore (diff) | |
download | aes-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.py | 33 |
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) |