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/toolkit.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/toolkit.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test/toolkit.py b/test/toolkit.py new file mode 100644 index 0000000..3c5f9dd --- /dev/null +++ b/test/toolkit.py @@ -0,0 +1,62 @@ +# Copyright 2015 Egor Tensin <Egor.Tensin@gmail.com> +# This file is licensed under the terms of the MIT License. +# See LICENSE.txt for details. + +import os.path +import subprocess +import sys + +class Tools: + def __init__(self, root_dir_path, use_sde=False): + self._root_dir_path = root_dir_path + self._use_sde = use_sde + + def _get_tool_path(self, tool_name): + return os.path.join(self._root_dir_path, tool_name) + + def _get_encrypt_tool_path(self, prefix): + return self._get_tool_path('{0}_encrypt.exe'.format(prefix)) + + def _get_decrypt_tool_path(self, prefix): + return self._get_tool_path('{0}_decrypt.exe'.format(prefix)) + + def _capture_tool_output(self, tool_path, args): + with_sde = ['sde', '--', tool_path] if self._use_sde else [tool_path] + return subprocess.check_output(with_sde + args, universal_newlines=True).split() + + def encrypt(self, prefix, key, args): + print('Encrypting using \'{0}\'...'.format(prefix)) + print('\tKey:', key) + return self._capture_tool_output(self._get_encrypt_tool_path(prefix), [key] + args) + + def decrypt(self, prefix, key, args): + print('Decrypting using \'{0}\'...'.format(prefix)) + print('\tKey:', key) + return self._capture_tool_output(self._get_decrypt_tool_path(prefix), [key] + args) + + def encrypt_with_iv(self, prefix, key, iv, args): + print('Encrypting using \'{0}\'...'.format(prefix)) + print('\tKey:', key) + print('\tInitialization vector:', iv) + return self._capture_tool_output(self._get_encrypt_tool_path(prefix), [key, iv] + args) + + def decrypt_with_iv(self, prefix, key, iv, args): + print('Decrypting using \'{0}\'...'.format(prefix)) + print('\tKey:', key) + print('\tInitialization vector:', iv) + return self._capture_tool_output(self._get_decrypt_tool_path(prefix), [key, iv] + args) + + def detect_mismatches(self, input, actual_output, expected_output): + if len(actual_output) != len(expected_output): + print('Unexpected output length!', file=sys.stderr) + print('\tExpected length:', len(expected_output), file=sys.stderr) + print('\tActual length:', len(actual_output), file=sys.stderr) + return False + for i in range(len(input)): + if actual_output[i] != expected_output[i]: + print('A mismatch detected!', file=sys.stderr) + print('\tInput:', input[i], file=sys.stderr) + print('\tExpected:', expected_output[i], file=sys.stderr) + print('\tActual:', actual_output[i], file=sys.stderr) + return False + return True |