aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2015-06-24 05:22:14 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2015-06-24 05:22:14 +0300
commit606c6b47a12842c7a87ac17b8a4f0762f86d603e (patch)
treeab730cae9edf1e82b24991142ae1c62f3e20d653 /test
parentadd missing extern "C" { (diff)
downloadaes-tools-606c6b47a12842c7a87ac17b8a4f0762f86d603e.tar.gz
aes-tools-606c6b47a12842c7a87ac17b8a4f0762f86d603e.zip
test: locate executables in PATH
Diffstat (limited to '')
-rw-r--r--test/README.md6
-rw-r--r--test/cavp.py10
-rw-r--r--test/nist-sp-800-38a.py10
-rw-r--r--test/toolkit.py30
4 files changed, 28 insertions, 28 deletions
diff --git a/test/README.md b/test/README.md
index a10b13a..e05b840 100644
--- a/test/README.md
+++ b/test/README.md
@@ -33,7 +33,7 @@ You must therefore make sure that
* all the tests succeeded,
* and the skipped tests were skipped for a good reason.
-To pass a path to the directory with the required utilities, use the `--root` parameter.
+To pass a path to the directory with the required utilities, use the `--path` parameter.
To make scripts run the utilities using Intel SDE, pass `--sde`.
Use `--help` to see the script's usage details.
@@ -41,11 +41,11 @@ Use `--help` to see the script's usage details.
To test the implementation against the vectors from [NIST SP 800-38A](http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf) using `nist-sp-800-32a.py`.
- python nist-sp-800-38a.py -r C:\build\test\Debug
+ python nist-sp-800-38a.py -p C:\build\test\Debug
### Cryptographic Algorithm Validation Program
To test the implementation against the vectors from [CAVP](http://csrc.nist.gov/groups/STM/cavp/) using `cavp.py`.
The AES Known Answer Test (KAT) Vectors are used and read from `KAT_AES.zip`.
- python cavp.py -r C:\build\test\Debug
+ python cavp.py -p C:\build\test\Debug
diff --git a/test/cavp.py b/test/cavp.py
index a94eaef..474818d 100644
--- a/test/cavp.py
+++ b/test/cavp.py
@@ -95,13 +95,13 @@ class _TestVectorsFile:
logging.info('Running encryption tests...')
keys, plaintexts, ciphertexts, init_vectors = self._extract_test_data('ENCRYPT')
inputs = _gen_encryption_inputs(keys, plaintexts, init_vectors)
- return self._run_tests(tools.run_encrypt_tool, inputs, ciphertexts)
+ return self._run_tests(tools.run_encrypt_block, inputs, ciphertexts)
def run_decryption_tests(self, tools):
logging.info('Running decryption tests...')
keys, plaintexts, ciphertexts, init_vectors = self._extract_test_data('DECRYPT')
inputs = _gen_decryption_inputs(keys, ciphertexts, init_vectors)
- return self._run_tests(tools.run_decrypt_tool, inputs, plaintexts)
+ return self._run_tests(tools.run_decrypt_block, inputs, plaintexts)
def _parse(self):
logging.info('Trying to parse test vectors file name \'{0}\'...'.format(self._fn))
@@ -174,8 +174,8 @@ def _parse_test_vectors_archive(tools, archive_path='KAT_AES.zip'):
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
- parser.add_argument('--root', '-r', required=True,
- help='set path to *.exe files')
+ parser.add_argument('--path', '-p', nargs='*',
+ help='set path to block encryption utilities')
parser.add_argument('--sde', '-e', action='store_true',
help='use Intel SDE to run *.exe files')
parser.add_argument('--log', '-l', help='set log file path')
@@ -189,5 +189,5 @@ if __name__ == '__main__':
logging_options['filename'] = args.log
logging.basicConfig(**logging_options)
- tools = toolkit.Tools(args.root, use_sde=args.sde)
+ tools = toolkit.Tools(args.path, use_sde=args.sde)
_parse_test_vectors_archive(tools)
diff --git a/test/nist-sp-800-38a.py b/test/nist-sp-800-38a.py
index df45451..c5c0af8 100644
--- a/test/nist-sp-800-38a.py
+++ b/test/nist-sp-800-38a.py
@@ -111,7 +111,7 @@ def _run_encryption_tests(tools, algo, mode):
ciphertexts = _ciphertexts[algo][mode]
_input = toolkit.EncryptionInput(key, _plaintexts, iv=iv)
try:
- actual_output = tools.run_encrypt_tool(algo, mode, _input)
+ actual_output = tools.run_encrypt_block(algo, mode, _input)
if not _assert_output(actual_output, ciphertexts):
return _TestExitCode.FAILURE
return _TestExitCode.SUCCESS
@@ -132,7 +132,7 @@ def _run_decryption_tests(tools, algo, mode):
ciphertexts = _ciphertexts[algo][mode]
_input = toolkit.DecryptionInput(key, ciphertexts, iv=iv)
try:
- actual_output = tools.run_decrypt_tool(algo, mode, _input)
+ actual_output = tools.run_decrypt_block(algo, mode, _input)
if not _assert_output(actual_output, _plaintexts):
return _TestExitCode.FAILURE
return _TestExitCode.SUCCESS
@@ -144,14 +144,14 @@ def _run_decryption_tests(tools, algo, mode):
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
- parser.add_argument('--root', '-r', required=True,
- help='set path to *.exe files')
+ parser.add_argument('--path', '-p', nargs='*',
+ help='set path to block encryption utilities')
parser.add_argument('--sde', '-e', action='store_true',
help='use Intel SDE to run *.exe files')
parser.add_argument('--log', '-l', help='set log file path')
args = parser.parse_args()
- tools = toolkit.Tools(args.root, args.sde)
+ tools = toolkit.Tools(args.path, args.sde)
logging_options = {'format': '%(asctime)s | %(module)s | %(levelname)s | %(message)s',
'level': logging.DEBUG}
diff --git a/test/toolkit.py b/test/toolkit.py
index 372d2cc..bd50edc 100644
--- a/test/toolkit.py
+++ b/test/toolkit.py
@@ -67,21 +67,21 @@ class ToolkitError(RuntimeError):
pass
class Tools:
- def __init__(self, root_dir_path, use_sde=False):
- self._root_dir_path = root_dir_path
+ def __init__(self, search_dirs, use_sde=False):
+ if search_dirs:
+ if isinstance(search_dirs, str):
+ os.environ['PATH'] += os.pathsep + search_dirs
+ elif isinstance(search_dirs, collections.Iterable):
+ os.environ['PATH'] += os.pathsep + os.pathsep.join(search_dirs)
+ else:
+ os.environ['PATH'] += os.pathsep + str(search_dirs)
self._use_sde = use_sde
self._logger = logging.getLogger(__name__)
- def _get_tool_path(self, fn):
- return os.path.join(self._root_dir_path, fn)
+ _ENCRYPT_BLOCK = 'aes_encrypt_block.exe'
+ _DECRYPT_BLOCK = 'aes_decrypt_block.exe'
- def get_encrypt_tool_path(self):
- return self._get_tool_path('aes_encrypt_block.exe')
-
- def get_decrypt_tool_path(self):
- return self._get_tool_path('aes_decrypt_block.exe')
-
- def run_tool(self, tool_path, algo, mode, args):
+ def run(self, tool_path, algo, mode, args):
cmd_list = ['sde', '--', tool_path] if self._use_sde else [tool_path]
cmd_list.extend(('-a', algo, '-m', mode, '--'))
cmd_list.extend(args)
@@ -110,16 +110,16 @@ class Tools:
args.extend(tail.to_args())
return args
- def run_encrypt_tool(self, algo, mode, inputs):
+ def run_encrypt_block(self, algo, mode, inputs):
if isinstance(inputs, collections.Iterable):
args = self._inputs_to_args(iter(inputs))
else:
args = inputs.to_args()
- return self.run_tool(self.get_encrypt_tool_path(), algo, mode, args)
+ return self.run(self._ENCRYPT_BLOCK, algo, mode, args)
- def run_decrypt_tool(self, algo, mode, inputs):
+ def run_decrypt_block(self, algo, mode, inputs):
if isinstance(inputs, collections.Iterable):
args = self._inputs_to_args(iter(inputs))
else:
args = inputs.to_args()
- return self.run_tool(self.get_decrypt_tool_path(), algo, mode, args)
+ return self.run(self._DECRYPT_BLOCK, algo, mode, args)