aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/ci.yml4
-rwxr-xr-xtest/cavp.py108
-rwxr-xr-xtest/file.py106
-rwxr-xr-xtest/nist.py208
-rw-r--r--test/toolkit.py48
5 files changed, 235 insertions, 239 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8e5e6e2..e43b09c 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -27,10 +27,6 @@ jobs:
python-version: '3.x'
- name: Run black
uses: psf/black@stable
- with:
- # > Please note that the --check flag is required so that the
- # > workflow fails if Black finds files that need to be formatted.
- options: --check --verbose --skip-string-normalization
build:
strategy:
diff --git a/test/cavp.py b/test/cavp.py
index b96969d..86486ed 100755
--- a/test/cavp.py
+++ b/test/cavp.py
@@ -30,12 +30,12 @@ class _MultiOrderedDict(OrderedDict):
def verify_test_output(actual, expected):
if len(actual) != len(expected):
- logging.error('Unexpected output length!')
- logging.error('\tExpected: %d', len(expected))
- logging.error('\tActual: %d', len(actual))
+ logging.error("Unexpected output length!")
+ logging.error("\tExpected: %d", len(expected))
+ logging.error("\tActual: %d", len(actual))
return False
if actual != expected:
- logging.error('Expected output:\n%s', '\n'.join(expected))
+ logging.error("Expected output:\n%s", "\n".join(expected))
return False
return True
@@ -65,12 +65,12 @@ class TestFile:
return self._mode
def _parse_data_section(self, parser, section):
- keys = parser.get(section, 'key')
- plaintexts = parser.get(section, 'plaintext')
- ciphertexts = parser.get(section, 'ciphertext')
+ keys = parser.get(section, "key")
+ plaintexts = parser.get(section, "plaintext")
+ ciphertexts = parser.get(section, "ciphertext")
init_vectors = None
if self.mode().requires_init_vector():
- init_vectors = parser.get(section, 'iv')
+ init_vectors = parser.get(section, "iv")
return keys, plaintexts, ciphertexts, init_vectors
def _parse_data(self):
@@ -82,8 +82,8 @@ class TestFile:
)
with open(self._path) as fd:
parser.read_string(fd.read())
- self._encryption_data = self._parse_data_section(parser, 'ENCRYPT')
- self._decryption_data = self._parse_data_section(parser, 'DECRYPT')
+ self._encryption_data = self._parse_data_section(parser, "ENCRYPT")
+ self._decryption_data = self._parse_data_section(parser, "DECRYPT")
@staticmethod
def _gen_inputs(keys, plaintexts, init_vectors):
@@ -109,7 +109,7 @@ class TestFile:
return TestExitCode.SUCCESS
def run_encryption_tests(self, tools, use_boxes=False):
- logging.debug('Running encryption tests...')
+ logging.debug("Running encryption tests...")
if not self.recognized():
return TestExitCode.SKIPPED
try:
@@ -119,12 +119,12 @@ class TestFile:
tools.run_encrypt_block, inputs, ciphertexts, use_boxes
)
except CalledProcessError as e:
- logging.error('Encountered an exception!')
+ logging.error("Encountered an exception!")
logging.exception(e)
return TestExitCode.ERROR
def run_decryption_tests(self, tools, use_boxes=False):
- logging.debug('Running decryption tests...')
+ logging.debug("Running decryption tests...")
if not self.recognized():
return TestExitCode.SKIPPED
try:
@@ -134,12 +134,12 @@ class TestFile:
tools.run_decrypt_block, inputs, plaintexts, use_boxes
)
except CalledProcessError as e:
- logging.error('Encountered an exception!')
+ logging.error("Encountered an exception!")
logging.exception(e)
return TestExitCode.ERROR
def _parse_path(self):
- logging.debug('Trying to parse test file path \'%s\'...', self._path)
+ logging.debug("Trying to parse test file path '%s'...", self._path)
stub = self._strip_extension(os.path.basename(self._path))
if not stub:
return
@@ -154,41 +154,41 @@ class TestFile:
return
self._recognized = True
- _RECOGNIZED_EXT = '.rsp'
+ _RECOGNIZED_EXT = ".rsp"
def _strip_extension(self, path):
stub, ext = os.path.splitext(path)
if ext != self._RECOGNIZED_EXT:
- logging.warning('Unknown test vectors file extension \'%s\'!', self._path)
+ logging.warning("Unknown test vectors file extension '%s'!", self._path)
return None
return stub
def _strip_algorithm(self, stub):
key_size = stub[-3:]
- maybe_algorithm = 'aes{}'.format(key_size)
+ maybe_algorithm = "aes{}".format(key_size)
self._algorithm = Algorithm.try_parse(maybe_algorithm)
if self._algorithm is None:
- logging.warning('Unknown or unsupported algorithm: %s', self._path)
+ logging.warning("Unknown or unsupported algorithm: %s", self._path)
return None
- logging.debug('\tAlgorithm: %s', self._algorithm)
+ logging.debug("\tAlgorithm: %s", self._algorithm)
return stub[0:-3]
- _RECOGNIZED_METHODS = ('GFSbox', 'KeySbox', 'VarKey', 'VarTxt')
+ _RECOGNIZED_METHODS = ("GFSbox", "KeySbox", "VarKey", "VarTxt")
def _strip_method(self, stub):
for method in self._RECOGNIZED_METHODS:
if stub.endswith(method):
- logging.debug('\tMethod: %s', method)
+ logging.debug("\tMethod: %s", method)
return stub[0 : len(stub) - len(method)]
- logging.warning('Unknown or unsupported method: %s', self._path)
+ logging.warning("Unknown or unsupported method: %s", self._path)
return None
def _strip_mode(self, stub):
self._mode = Mode.try_parse(stub)
if self._mode is None:
- logging.warning('Unknown or unsupported mode: %s', self._path)
+ logging.warning("Unknown or unsupported mode: %s", self._path)
return None
- logging.debug('\tMode: %s', self._mode)
+ logging.debug("\tMode: %s", self._mode)
return self._mode
@@ -208,7 +208,7 @@ _script_dir = os.path.dirname(__file__)
def _setup_logging(verbose=False):
level = logging.DEBUG if verbose else logging.INFO
logging.basicConfig(
- format='%(asctime)s | %(module)s | %(levelname)s | %(message)s', level=level
+ format="%(asctime)s | %(module)s | %(levelname)s | %(message)s", level=level
)
@@ -224,11 +224,11 @@ def run_tests(
exit_codes.append(test_file.run_encryption_tests(tools, use_boxes))
exit_codes.append(test_file.run_decryption_tests(tools, use_boxes))
- logging.info('Test exit codes:')
- logging.info('\tSkipped: %d', exit_codes.count(TestExitCode.SKIPPED))
- logging.info('\tError(s): %d', exit_codes.count(TestExitCode.ERROR))
- logging.info('\tSucceeded: %d', exit_codes.count(TestExitCode.SUCCESS))
- logging.info('\tFailed: %d', exit_codes.count(TestExitCode.FAILURE))
+ logging.info("Test exit codes:")
+ logging.info("\tSkipped: %d", exit_codes.count(TestExitCode.SKIPPED))
+ logging.info("\tError(s): %d", exit_codes.count(TestExitCode.ERROR))
+ logging.info("\tSucceeded: %d", exit_codes.count(TestExitCode.SUCCESS))
+ logging.info("\tFailed: %d", exit_codes.count(TestExitCode.FAILURE))
if (
exit_codes.count(TestExitCode.ERROR) == 0
@@ -244,37 +244,37 @@ def _parse_args(args=None):
args = sys.argv[1:]
parser = argparse.ArgumentParser()
parser.add_argument(
- '--path',
- '-p',
- dest='tools_path',
- metavar='PATH',
- nargs='*',
- help='set block encryption utilities directory path',
+ "--path",
+ "-p",
+ dest="tools_path",
+ metavar="PATH",
+ nargs="*",
+ help="set block encryption utilities directory path",
)
parser.add_argument(
- '--sde',
- '-e',
- action='store_true',
- dest='use_sde',
- help='use Intel SDE to run the utilities',
+ "--sde",
+ "-e",
+ action="store_true",
+ dest="use_sde",
+ help="use Intel SDE to run the utilities",
)
parser.add_argument(
- '--boxes',
- '-b',
- action='store_true',
- dest='use_boxes',
+ "--boxes",
+ "-b",
+ action="store_true",
+ dest="use_boxes",
help='use the "boxes" interface',
)
parser.add_argument(
- '--archive',
- '-a',
- dest='archive_path',
- metavar='PATH',
- default=os.path.join(_script_dir, 'data/KAT_AES.zip'),
- help='set test vectors archive file path',
+ "--archive",
+ "-a",
+ dest="archive_path",
+ metavar="PATH",
+ default=os.path.join(_script_dir, "data/KAT_AES.zip"),
+ help="set test vectors archive file path",
)
parser.add_argument(
- '--verbose', '-v', action='store_true', help='verbose log output'
+ "--verbose", "-v", action="store_true", help="verbose log output"
)
return parser.parse_args(args)
@@ -283,5 +283,5 @@ def main(args=None):
return run_tests(**vars(_parse_args(args)))
-if __name__ == '__main__':
+if __name__ == "__main__":
sys.exit(main())
diff --git a/test/file.py b/test/file.py
index 6930c8d..e68d7a7 100755
--- a/test/file.py
+++ b/test/file.py
@@ -24,10 +24,10 @@ class TestExitCode(Enum):
SUCCESS, FAILURE, ERROR, SKIPPED = range(1, 5)
-_KEY_EXT = 'key'
-_IV_EXT = 'iv'
-_PLAIN_EXT = 'plain'
-_CIPHER_EXT = 'cipher'
+_KEY_EXT = "key"
+_IV_EXT = "iv"
+_PLAIN_EXT = "plain"
+_CIPHER_EXT = "cipher"
def _list_dirs(root_path):
@@ -38,7 +38,7 @@ def _list_dirs(root_path):
def _list_files(root_path, ext):
- for path in glob(os.path.join(root_path, '*.{}'.format(ext))):
+ for path in glob(os.path.join(root_path, "*.{}".format(ext))):
if os.path.isfile(path):
yield path
@@ -65,7 +65,7 @@ def _extract_test_name(key_path):
def _replace_ext(path, new_ext):
- return '{}.{}'.format(os.path.splitext(path)[0], new_ext)
+ return "{}.{}".format(os.path.splitext(path)[0], new_ext)
def _extract_iv_path(key_path):
@@ -91,27 +91,27 @@ def _make_output_file():
def run_encryption_test(
tools, algorithm, mode, key, plaintext_path, ciphertext_path, iv=None, force=False
):
- logging.debug('Running encryption test...')
- logging.debug('\tPlaintext file path: %s', plaintext_path)
- logging.debug('\tExpected ciphertext file path: %s', ciphertext_path)
- logging.debug('\tAlgorithm: %s', algorithm)
- logging.debug('\tMode: %s', mode)
+ logging.debug("Running encryption test...")
+ logging.debug("\tPlaintext file path: %s", plaintext_path)
+ logging.debug("\tExpected ciphertext file path: %s", ciphertext_path)
+ logging.debug("\tAlgorithm: %s", algorithm)
+ logging.debug("\tMode: %s", mode)
with _make_output_file() as tmp_path:
- logging.debug('\tEncrypted file path: %s', tmp_path)
+ logging.debug("\tEncrypted file path: %s", tmp_path)
try:
tools.run_encrypt_file(algorithm, mode, key, plaintext_path, tmp_path, iv)
if force:
- logging.warning('Overwriting expected ciphertext file')
+ logging.warning("Overwriting expected ciphertext file")
shutil.copy(tmp_path, ciphertext_path)
return TestExitCode.SKIPPED
if filecmp.cmp(ciphertext_path, tmp_path):
return TestExitCode.SUCCESS
- logging.error('The encrypted file doesn\'t match the ciphertext file')
+ logging.error("The encrypted file doesn't match the ciphertext file")
return TestExitCode.FAILURE
except CalledProcessError as e:
- logging.error('Encountered an exception!')
+ logging.error("Encountered an exception!")
logging.exception(e)
return TestExitCode.ERROR
@@ -119,49 +119,49 @@ def run_encryption_test(
def run_decryption_test(
tools, algorithm, mode, key, plaintext_path, ciphertext_path, iv=None
):
- logging.debug('Running decryption test...')
- logging.debug('\tCiphertext file path: %s', ciphertext_path)
- logging.debug('\tExpected plaintext file path: %s', plaintext_path)
- logging.debug('\tAlgorithm: %s', algorithm)
- logging.debug('\tMode: %s', mode)
+ logging.debug("Running decryption test...")
+ logging.debug("\tCiphertext file path: %s", ciphertext_path)
+ logging.debug("\tExpected plaintext file path: %s", plaintext_path)
+ logging.debug("\tAlgorithm: %s", algorithm)
+ logging.debug("\tMode: %s", mode)
with _make_output_file() as tmp_path:
- logging.debug('\tDecrypted file path: %s', tmp_path)
+ logging.debug("\tDecrypted file path: %s", tmp_path)
try:
tools.run_decrypt_file(algorithm, mode, key, ciphertext_path, tmp_path, iv)
if filecmp.cmp(tmp_path, plaintext_path):
return TestExitCode.SUCCESS
- logging.error('The decrypted file doesn\'t match the plaintext file')
+ logging.error("The decrypted file doesn't match the plaintext file")
return TestExitCode.FAILURE
except CalledProcessError as e:
- logging.error('Encountered an exception!')
+ logging.error("Encountered an exception!")
logging.exception(e)
return TestExitCode.ERROR
def enum_tests(suite_dir):
suite_dir = os.path.abspath(suite_dir)
- logging.info('Suite directory path: %s', suite_dir)
+ logging.info("Suite directory path: %s", suite_dir)
for algorithm_dir in _list_dirs(suite_dir):
algorithm = os.path.basename(algorithm_dir)
maybe_algorithm = Algorithm.try_parse(algorithm)
if maybe_algorithm is None:
- logging.warning('Unknown or unsupported algorithm: %s', algorithm)
+ logging.warning("Unknown or unsupported algorithm: %s", algorithm)
continue
algorithm = maybe_algorithm
for mode_dir in _list_dirs(algorithm_dir):
mode = os.path.basename(mode_dir)
maybe_mode = Mode.try_parse(mode)
if maybe_mode is None:
- logging.warning('Unknown or unsupported mode: %s', mode)
+ logging.warning("Unknown or unsupported mode: %s", mode)
continue
mode = maybe_mode
for key_path in _list_keys(mode_dir):
key = _read_key(key_path)
- logging.debug('Key: %s', key)
+ logging.debug("Key: %s", key)
test_name = _extract_test_name(key_path)
- logging.debug('Test name: %s', test_name)
+ logging.debug("Test name: %s", test_name)
iv = None
if mode.requires_init_vector():
iv_path = _extract_iv_path(key_path)
@@ -178,7 +178,7 @@ _script_name = os.path.splitext(os.path.basename(__file__))[0]
def _setup_logging(verbose=False):
level = logging.DEBUG if verbose else logging.INFO
logging.basicConfig(
- format='%(asctime)s | %(module)s | %(levelname)s | %(message)s', level=level
+ format="%(asctime)s | %(module)s | %(levelname)s | %(message)s", level=level
)
@@ -191,11 +191,11 @@ def run_tests(suite_path, tools_path=(), verbose=False, use_sde=False, force=Fal
exit_codes.append(run_encryption_test(tools, *test, force))
exit_codes.append(run_decryption_test(tools, *test))
- logging.info('Test exit codes:')
- logging.info('\tSkipped: %d', exit_codes.count(TestExitCode.SKIPPED))
- logging.info('\tError(s): %d', exit_codes.count(TestExitCode.ERROR))
- logging.info('\tSucceeded: %d', exit_codes.count(TestExitCode.SUCCESS))
- logging.info('\tFailed: %d', exit_codes.count(TestExitCode.FAILURE))
+ logging.info("Test exit codes:")
+ logging.info("\tSkipped: %d", exit_codes.count(TestExitCode.SKIPPED))
+ logging.info("\tError(s): %d", exit_codes.count(TestExitCode.ERROR))
+ logging.info("\tSucceeded: %d", exit_codes.count(TestExitCode.SUCCESS))
+ logging.info("\tFailed: %d", exit_codes.count(TestExitCode.FAILURE))
if (
exit_codes.count(TestExitCode.ERROR) == 0
@@ -211,32 +211,32 @@ def _parse_args(args=None):
args = sys.argv[1:]
parser = argparse.ArgumentParser()
parser.add_argument(
- '--path',
- '-p',
- dest='tools_path',
- metavar='PATH',
- nargs='*',
- help='set file encryption utilities directory path',
+ "--path",
+ "-p",
+ dest="tools_path",
+ metavar="PATH",
+ nargs="*",
+ help="set file encryption utilities directory path",
)
parser.add_argument(
- '--sde',
- '-e',
- dest='use_sde',
- action='store_true',
- help='use Intel SDE to run the utilities',
+ "--sde",
+ "-e",
+ dest="use_sde",
+ action="store_true",
+ help="use Intel SDE to run the utilities",
)
parser.add_argument(
- '--verbose', '-v', action='store_true', help='verbose log output'
+ "--verbose", "-v", action="store_true", help="verbose log output"
)
parser.add_argument(
- '--force', '-f', action='store_true', help='overwrite ciphertext files'
+ "--force", "-f", action="store_true", help="overwrite ciphertext files"
)
parser.add_argument(
- '--suite',
- '-s',
- dest='suite_path',
- default=os.path.join(_script_dir, 'data', 'file'),
- help='set test suite directory path',
+ "--suite",
+ "-s",
+ dest="suite_path",
+ default=os.path.join(_script_dir, "data", "file"),
+ help="set test suite directory path",
)
return parser.parse_args(args)
@@ -245,5 +245,5 @@ def main(args=None):
return run_tests(**vars(_parse_args(args)))
-if __name__ == '__main__':
+if __name__ == "__main__":
sys.exit(main())
diff --git a/test/nist.py b/test/nist.py
index 9cc0ce9..274cbbc 100755
--- a/test/nist.py
+++ b/test/nist.py
@@ -14,20 +14,20 @@ import sys
from toolkit import Algorithm, BlockInput, Mode, Tools
_TEST_PLAINTEXTS = [
- '6bc1bee22e409f96e93d7e117393172a',
- 'ae2d8a571e03ac9c9eb76fac45af8e51',
- '30c81c46a35ce411e5fbc1191a0a52ef',
- 'f69f2445df4f9b17ad2b417be66c3710',
+ "6bc1bee22e409f96e93d7e117393172a",
+ "ae2d8a571e03ac9c9eb76fac45af8e51",
+ "30c81c46a35ce411e5fbc1191a0a52ef",
+ "f69f2445df4f9b17ad2b417be66c3710",
]
_TEST_KEYS = {
- Algorithm.AES128: '2b7e151628aed2a6abf7158809cf4f3c',
- Algorithm.AES192: '8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b',
- Algorithm.AES256: '603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4',
+ Algorithm.AES128: "2b7e151628aed2a6abf7158809cf4f3c",
+ Algorithm.AES192: "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b",
+ Algorithm.AES256: "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4",
}
-_TEST_INIT_VECTOR = '000102030405060708090a0b0c0d0e0f'
-_TEST_INIT_VECTOR_CTR = 'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff'
+_TEST_INIT_VECTOR = "000102030405060708090a0b0c0d0e0f"
+_TEST_INIT_VECTOR_CTR = "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"
_TEST_INIT_VECTORS = {
Algorithm.AES128: {
@@ -44,98 +44,98 @@ _TEST_INIT_VECTORS[Algorithm.AES256] = _TEST_INIT_VECTORS[Algorithm.AES128]
_TEST_CIPHERTEXTS = {
Algorithm.AES128: {
Mode.ECB: [
- '3ad77bb40d7a3660a89ecaf32466ef97',
- 'f5d3d58503b9699de785895a96fdbaaf',
- '43b1cd7f598ece23881b00e3ed030688',
- '7b0c785e27e8ad3f8223207104725dd4',
+ "3ad77bb40d7a3660a89ecaf32466ef97",
+ "f5d3d58503b9699de785895a96fdbaaf",
+ "43b1cd7f598ece23881b00e3ed030688",
+ "7b0c785e27e8ad3f8223207104725dd4",
],
Mode.CBC: [
- '7649abac8119b246cee98e9b12e9197d',
- '5086cb9b507219ee95db113a917678b2',
- '73bed6b8e3c1743b7116e69e22229516',
- '3ff1caa1681fac09120eca307586e1a7',
+ "7649abac8119b246cee98e9b12e9197d",
+ "5086cb9b507219ee95db113a917678b2",
+ "73bed6b8e3c1743b7116e69e22229516",
+ "3ff1caa1681fac09120eca307586e1a7",
],
Mode.CFB: [
- '3b3fd92eb72dad20333449f8e83cfb4a',
- 'c8a64537a0b3a93fcde3cdad9f1ce58b',
- '26751f67a3cbb140b1808cf187a4f4df',
- 'c04b05357c5d1c0eeac4c66f9ff7f2e6',
+ "3b3fd92eb72dad20333449f8e83cfb4a",
+ "c8a64537a0b3a93fcde3cdad9f1ce58b",
+ "26751f67a3cbb140b1808cf187a4f4df",
+ "c04b05357c5d1c0eeac4c66f9ff7f2e6",
],
Mode.OFB: [
- '3b3fd92eb72dad20333449f8e83cfb4a',
- '7789508d16918f03f53c52dac54ed825',
- '9740051e9c5fecf64344f7a82260edcc',
- '304c6528f659c77866a510d9c1d6ae5e',
+ "3b3fd92eb72dad20333449f8e83cfb4a",
+ "7789508d16918f03f53c52dac54ed825",
+ "9740051e9c5fecf64344f7a82260edcc",
+ "304c6528f659c77866a510d9c1d6ae5e",
],
Mode.CTR: [
- '874d6191b620e3261bef6864990db6ce',
- '9806f66b7970fdff8617187bb9fffdff',
- '5ae4df3edbd5d35e5b4f09020db03eab',
- '1e031dda2fbe03d1792170a0f3009cee',
+ "874d6191b620e3261bef6864990db6ce",
+ "9806f66b7970fdff8617187bb9fffdff",
+ "5ae4df3edbd5d35e5b4f09020db03eab",
+ "1e031dda2fbe03d1792170a0f3009cee",
],
},
Algorithm.AES192: {
Mode.ECB: [
- 'bd334f1d6e45f25ff712a214571fa5cc',
- '974104846d0ad3ad7734ecb3ecee4eef',
- 'ef7afd2270e2e60adce0ba2face6444e',
- '9a4b41ba738d6c72fb16691603c18e0e',
+ "bd334f1d6e45f25ff712a214571fa5cc",
+ "974104846d0ad3ad7734ecb3ecee4eef",
+ "ef7afd2270e2e60adce0ba2face6444e",
+ "9a4b41ba738d6c72fb16691603c18e0e",
],
Mode.CBC: [
- '4f021db243bc633d7178183a9fa071e8',
- 'b4d9ada9ad7dedf4e5e738763f69145a',
- '571b242012fb7ae07fa9baac3df102e0',
- '08b0e27988598881d920a9e64f5615cd',
+ "4f021db243bc633d7178183a9fa071e8",
+ "b4d9ada9ad7dedf4e5e738763f69145a",
+ "571b242012fb7ae07fa9baac3df102e0",
+ "08b0e27988598881d920a9e64f5615cd",
],
Mode.CFB: [
- 'cdc80d6fddf18cab34c25909c99a4174',
- '67ce7f7f81173621961a2b70171d3d7a',
- '2e1e8a1dd59b88b1c8e60fed1efac4c9',
- 'c05f9f9ca9834fa042ae8fba584b09ff',
+ "cdc80d6fddf18cab34c25909c99a4174",
+ "67ce7f7f81173621961a2b70171d3d7a",
+ "2e1e8a1dd59b88b1c8e60fed1efac4c9",
+ "c05f9f9ca9834fa042ae8fba584b09ff",
],
Mode.OFB: [
- 'cdc80d6fddf18cab34c25909c99a4174',
- 'fcc28b8d4c63837c09e81700c1100401',
- '8d9a9aeac0f6596f559c6d4daf59a5f2',
- '6d9f200857ca6c3e9cac524bd9acc92a',
+ "cdc80d6fddf18cab34c25909c99a4174",
+ "fcc28b8d4c63837c09e81700c1100401",
+ "8d9a9aeac0f6596f559c6d4daf59a5f2",
+ "6d9f200857ca6c3e9cac524bd9acc92a",
],
Mode.CTR: [
- '1abc932417521ca24f2b0459fe7e6e0b',
- '090339ec0aa6faefd5ccc2c6f4ce8e94',
- '1e36b26bd1ebc670d1bd1d665620abf7',
- '4f78a7f6d29809585a97daec58c6b050',
+ "1abc932417521ca24f2b0459fe7e6e0b",
+ "090339ec0aa6faefd5ccc2c6f4ce8e94",
+ "1e36b26bd1ebc670d1bd1d665620abf7",
+ "4f78a7f6d29809585a97daec58c6b050",
],
},
Algorithm.AES256: {
Mode.ECB: [
- 'f3eed1bdb5d2a03c064b5a7e3db181f8',
- '591ccb10d410ed26dc5ba74a31362870',
- 'b6ed21b99ca6f4f9f153e7b1beafed1d',
- '23304b7a39f9f3ff067d8d8f9e24ecc7',
+ "f3eed1bdb5d2a03c064b5a7e3db181f8",
+ "591ccb10d410ed26dc5ba74a31362870",
+ "b6ed21b99ca6f4f9f153e7b1beafed1d",
+ "23304b7a39f9f3ff067d8d8f9e24ecc7",
],
Mode.CBC: [
- 'f58c4c04d6e5f1ba779eabfb5f7bfbd6',
- '9cfc4e967edb808d679f777bc6702c7d',
- '39f23369a9d9bacfa530e26304231461',
- 'b2eb05e2c39be9fcda6c19078c6a9d1b',
+ "f58c4c04d6e5f1ba779eabfb5f7bfbd6",
+ "9cfc4e967edb808d679f777bc6702c7d",
+ "39f23369a9d9bacfa530e26304231461",
+ "b2eb05e2c39be9fcda6c19078c6a9d1b",
],
Mode.CFB: [
- 'dc7e84bfda79164b7ecd8486985d3860',
- '39ffed143b28b1c832113c6331e5407b',
- 'df10132415e54b92a13ed0a8267ae2f9',
- '75a385741ab9cef82031623d55b1e471',
+ "dc7e84bfda79164b7ecd8486985d3860",
+ "39ffed143b28b1c832113c6331e5407b",
+ "df10132415e54b92a13ed0a8267ae2f9",
+ "75a385741ab9cef82031623d55b1e471",
],
Mode.OFB: [
- 'dc7e84bfda79164b7ecd8486985d3860',
- '4febdc6740d20b3ac88f6ad82a4fb08d',
- '71ab47a086e86eedf39d1c5bba97c408',
- '0126141d67f37be8538f5a8be740e484',
+ "dc7e84bfda79164b7ecd8486985d3860",
+ "4febdc6740d20b3ac88f6ad82a4fb08d",
+ "71ab47a086e86eedf39d1c5bba97c408",
+ "0126141d67f37be8538f5a8be740e484",
],
Mode.CTR: [
- '601ec313775789a5b7a7f504bbf3d228',
- 'f443e3ca4d62b59aca84e990cacaf5c5',
- '2b0930daa23de94ce87017ba2d84988d',
- 'dfc9c58db67aada613c2dd08457941a6',
+ "601ec313775789a5b7a7f504bbf3d228",
+ "f443e3ca4d62b59aca84e990cacaf5c5",
+ "2b0930daa23de94ce87017ba2d84988d",
+ "dfc9c58db67aada613c2dd08457941a6",
],
},
}
@@ -167,12 +167,12 @@ def get_tested_algorithms_and_modes():
def verify_test_output(actual, expected):
if len(actual) != len(expected):
- logging.error('Unexpected output length!')
- logging.error('\tExpected: %d', len(expected))
- logging.error('\tActual: %d', len(actual))
+ logging.error("Unexpected output length!")
+ logging.error("\tExpected: %d", len(expected))
+ logging.error("\tActual: %d", len(actual))
return False
if actual != expected:
- logging.error('Expected output:\n' + '\n'.join(expected))
+ logging.error("Expected output:\n" + "\n".join(expected))
return False
return True
@@ -182,9 +182,9 @@ class TestExitCode(Enum):
def run_encryption_test(tools, algorithm, mode, use_boxes=False):
- logging.debug('Running encryption test...')
- logging.debug('Algorithm: %s', algorithm)
- logging.debug('Mode: %s', mode)
+ logging.debug("Running encryption test...")
+ logging.debug("Algorithm: %s", algorithm)
+ logging.debug("Mode: %s", mode)
try:
plaintexts = get_test_plaintexts(algorithm, mode)
@@ -197,15 +197,15 @@ def run_encryption_test(tools, algorithm, mode, use_boxes=False):
return TestExitCode.SUCCESS
return TestExitCode.FAILURE
except CalledProcessError as e:
- logging.error('Encountered an exception!')
+ logging.error("Encountered an exception!")
logging.exception(e)
return TestExitCode.ERROR
def run_decryption_test(tools, algorithm, mode, use_boxes=False):
- logging.debug('Running decryption test...')
- logging.debug('Algorithm: %s', algorithm)
- logging.debug('Mode: %s', mode)
+ logging.debug("Running decryption test...")
+ logging.debug("Algorithm: %s", algorithm)
+ logging.debug("Mode: %s", mode)
try:
ciphertexts = get_test_ciphertexts(algorithm, mode)
@@ -218,7 +218,7 @@ def run_decryption_test(tools, algorithm, mode, use_boxes=False):
return TestExitCode.SUCCESS
return TestExitCode.FAILURE
except CalledProcessError as e:
- logging.error('Encountered an exception!')
+ logging.error("Encountered an exception!")
logging.exception(e)
return TestExitCode.ERROR
@@ -226,7 +226,7 @@ def run_decryption_test(tools, algorithm, mode, use_boxes=False):
def _setup_logging(verbose=False):
level = logging.DEBUG if verbose else logging.INFO
logging.basicConfig(
- format='%(asctime)s | %(module)s | %(levelname)s | %(message)s', level=level
+ format="%(asctime)s | %(module)s | %(levelname)s | %(message)s", level=level
)
@@ -243,11 +243,11 @@ def run_tests(tools_path=(), use_sde=False, use_boxes=False, verbose=False):
run_decryption_test(tools, algorithm, mode, use_boxes=use_boxes)
)
- logging.info('Test exit codes:')
- logging.info('\tSkipped: %d', exit_codes.count(TestExitCode.SKIPPED))
- logging.info('\tError(s): %d', exit_codes.count(TestExitCode.ERROR))
- logging.info('\tSucceeded: %d', exit_codes.count(TestExitCode.SUCCESS))
- logging.info('\tFailed: %d', exit_codes.count(TestExitCode.FAILURE))
+ logging.info("Test exit codes:")
+ logging.info("\tSkipped: %d", exit_codes.count(TestExitCode.SKIPPED))
+ logging.info("\tError(s): %d", exit_codes.count(TestExitCode.ERROR))
+ logging.info("\tSucceeded: %d", exit_codes.count(TestExitCode.SUCCESS))
+ logging.info("\tFailed: %d", exit_codes.count(TestExitCode.FAILURE))
if (
exit_codes.count(TestExitCode.ERROR) == 0
@@ -263,29 +263,29 @@ def _parse_args(args=None):
args = sys.argv[1:]
parser = argparse.ArgumentParser()
parser.add_argument(
- '--path',
- '-p',
- dest='tools_path',
- metavar='PATH',
- nargs='*',
- help='set block encryption utilities directory path',
+ "--path",
+ "-p",
+ dest="tools_path",
+ metavar="PATH",
+ nargs="*",
+ help="set block encryption utilities directory path",
)
parser.add_argument(
- '--sde',
- '-e',
- action='store_true',
- dest='use_sde',
- help='use Intel SDE to run the utilities',
+ "--sde",
+ "-e",
+ action="store_true",
+ dest="use_sde",
+ help="use Intel SDE to run the utilities",
)
parser.add_argument(
- '--boxes',
- '-b',
- action='store_true',
- dest='use_boxes',
+ "--boxes",
+ "-b",
+ action="store_true",
+ dest="use_boxes",
help='use the "boxes" interface',
)
parser.add_argument(
- '--verbose', '-v', action='store_true', help='verbose log output'
+ "--verbose", "-v", action="store_true", help="verbose log output"
)
return parser.parse_args(args)
@@ -294,5 +294,5 @@ def main(args=None):
return run_tests(**vars(_parse_args(args)))
-if __name__ == '__main__':
+if __name__ == "__main__":
sys.exit(main())
diff --git a/test/toolkit.py b/test/toolkit.py
index deafd8f..4d8431d 100644
--- a/test/toolkit.py
+++ b/test/toolkit.py
@@ -22,7 +22,7 @@ class Algorithm(Enum):
except ValueError:
return None
- AES128, AES192, AES256 = 'aes128', 'aes192', 'aes256'
+ AES128, AES192, AES256 = "aes128", "aes192", "aes256"
def __str__(self):
return self.value
@@ -32,7 +32,7 @@ class Mode(Enum):
@staticmethod
def parse(s):
s = s.lower()
- if '{}128'.format(Mode.CFB) == s:
+ if "{}128".format(Mode.CFB) == s:
return Mode.CFB
return Mode(s)
@@ -43,7 +43,7 @@ class Mode(Enum):
except ValueError:
return None
- ECB, CBC, CFB, OFB, CTR = 'ecb', 'cbc', 'cfb', 'ofb', 'ctr'
+ ECB, CBC, CFB, OFB, CTR = "ecb", "cbc", "cfb", "ofb", "ctr"
def requires_init_vector(self):
return self != Mode.ECB
@@ -70,30 +70,30 @@ class Tools:
def __init__(self, search_dirs, use_sde=False):
if search_dirs:
if isinstance(search_dirs, str):
- os.environ['PATH'] += os.pathsep + search_dirs
+ os.environ["PATH"] += os.pathsep + search_dirs
elif isinstance(search_dirs, Iterable):
- os.environ['PATH'] += os.pathsep + os.pathsep.join(search_dirs)
+ os.environ["PATH"] += os.pathsep + os.pathsep.join(search_dirs)
else:
- os.environ['PATH'] += os.pathsep + str(search_dirs)
+ os.environ["PATH"] += os.pathsep + str(search_dirs)
self._use_sde = use_sde
- _ENCRYPT_BLOCK = 'encrypt_block'
- _DECRYPT_BLOCK = 'decrypt_block'
- _ENCRYPT_FILE = 'encrypt_file'
- _DECRYPT_FILE = 'decrypt_file'
+ _ENCRYPT_BLOCK = "encrypt_block"
+ _DECRYPT_BLOCK = "decrypt_block"
+ _ENCRYPT_FILE = "encrypt_file"
+ _DECRYPT_FILE = "decrypt_file"
def run(self, tool_path, args):
- cmd_list = ['sde', '--', tool_path] if self._use_sde else [tool_path]
+ cmd_list = ["sde", "--", tool_path] if self._use_sde else [tool_path]
cmd_list.extend(args)
- logging.debug('Trying to execute: %s', subprocess.list2cmdline(cmd_list))
+ logging.debug("Trying to execute: %s", subprocess.list2cmdline(cmd_list))
try:
output = subprocess.check_output(
cmd_list, universal_newlines=True, stderr=subprocess.STDOUT
)
except subprocess.CalledProcessError as e:
- logging.error('Output:\n%s', e.output)
+ logging.error("Output:\n%s", e.output)
raise
- logging.debug('Output:\n%s', output)
+ logging.debug("Output:\n%s", output)
return output.split()
@staticmethod
@@ -103,20 +103,20 @@ class Tools:
head = next(inputs, None)
if head is None:
break
- args.append('--')
+ args.append("--")
args.extend(head.to_args())
return args
@staticmethod
def _block_settings_to_args(algorithm, mode, use_boxes=False):
args = [
- '--algorithm',
+ "--algorithm",
str(algorithm),
- '--mode',
+ "--mode",
str(mode),
]
if use_boxes:
- args.append('--use-boxes')
+ args.append("--use-boxes")
return args
@staticmethod
@@ -140,19 +140,19 @@ class Tools:
def _build_file_args(algorithm, mode, key, input_path, output_path, iv=None):
args = [
- '--algorithm',
+ "--algorithm",
str(algorithm),
- '--mode',
+ "--mode",
str(mode),
- '--key',
+ "--key",
key,
- '--input',
+ "--input",
input_path,
- '--output',
+ "--output",
output_path,
]
if iv is not None:
- args.extend(('--iv', iv))
+ args.extend(("--iv", iv))
return args
def run_encrypt_file(self, algorithm, mode, key, input_path, output_path, iv=None):