2019-04-14 22:17:11 +01:00
|
|
|
"""
|
2019-07-29 09:38:25 +01:00
|
|
|
Checks that (hash of the) KATs (in NIST format) produced on this platform match
|
2019-04-14 22:17:11 +01:00
|
|
|
the one provided in the META file for every scheme/implementation.
|
|
|
|
|
2019-04-18 09:00:08 +01:00
|
|
|
Note that this only uses the first test case from the NIST-format KAT files.
|
2019-04-14 22:17:11 +01:00
|
|
|
The appropriate hash can be generated from the original submission's KAT file
|
|
|
|
using the command:
|
|
|
|
cat PQCkemKAT_whatever.rsp | head -n 8 | tail -n 6 | sha256sum
|
|
|
|
"""
|
|
|
|
|
|
|
|
import hashlib
|
|
|
|
import os
|
|
|
|
|
2019-07-29 09:38:25 +01:00
|
|
|
import pytest
|
2019-04-18 09:00:08 +01:00
|
|
|
|
2019-07-29 09:38:25 +01:00
|
|
|
import helpers
|
|
|
|
import pqclean
|
2019-04-14 22:17:11 +01:00
|
|
|
|
|
|
|
|
2019-07-29 09:38:25 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'implementation,test_dir,impl_path, init, destr',
|
|
|
|
[(impl, *helpers.isolate_test_files(impl.path(), 'test_functest_'))
|
2019-09-06 11:01:44 +01:00
|
|
|
for impl in pqclean.Scheme.all_supported_implementations()],
|
|
|
|
ids=[str(impl) for impl in pqclean.Scheme.all_supported_implementations()],
|
2019-07-29 09:38:25 +01:00
|
|
|
)
|
2019-04-18 09:00:08 +01:00
|
|
|
@helpers.filtered_test
|
2019-07-29 09:38:25 +01:00
|
|
|
def test_nistkat(implementation, impl_path, test_dir, init, destr):
|
|
|
|
init()
|
|
|
|
dest_path = os.path.join(test_dir, 'bin')
|
2019-04-14 22:17:11 +01:00
|
|
|
helpers.make('nistkat',
|
|
|
|
TYPE=implementation.scheme.type,
|
|
|
|
SCHEME=implementation.scheme.name,
|
|
|
|
IMPLEMENTATION=implementation.name,
|
2019-07-29 09:38:25 +01:00
|
|
|
SCHEME_DIR=impl_path,
|
|
|
|
DEST_DIR=dest_path,
|
|
|
|
working_dir=os.path.join(test_dir, 'test'))
|
2019-04-14 22:17:11 +01:00
|
|
|
out = helpers.run_subprocess(
|
2019-07-29 09:38:25 +01:00
|
|
|
[os.path.join(dest_path, 'nistkat_{}_{}{}'.format(
|
2019-04-14 22:17:11 +01:00
|
|
|
implementation.scheme.name,
|
|
|
|
implementation.name,
|
|
|
|
'.exe' if os.name == 'nt' else ''
|
|
|
|
))],
|
|
|
|
).replace('\r', '')
|
|
|
|
assert(implementation.scheme.metadata()['nistkat-sha256'].lower()
|
|
|
|
== hashlib.sha256(out.encode('utf-8')).hexdigest().lower())
|
2019-07-29 09:38:25 +01:00
|
|
|
destr()
|
2019-04-14 22:17:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-07-29 09:38:25 +01:00
|
|
|
import sys
|
|
|
|
pytest.main(sys.argv)
|