1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-29 19:01:22 +00:00
pqcrypto/test/test_nistkat.py

53 lines
1.7 KiB
Python
Raw Normal View History

2019-04-14 22:17:11 +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.
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
import pytest
import helpers
import pqclean
2019-04-14 22:17:11 +01:00
@pytest.mark.parametrize(
'implementation,test_dir,impl_path, init, destr',
[(impl, *helpers.isolate_test_files(impl.path(), 'test_functest_'))
for impl in pqclean.Scheme.all_supported_implementations()],
ids=[str(impl) for impl in pqclean.Scheme.all_supported_implementations()],
)
@helpers.filtered_test
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,
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(
[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 ''
))],
print_output=False,
2019-04-14 22:17:11 +01:00
).replace('\r', '')
assert(implementation.scheme.metadata()['nistkat-sha256'].lower()
== hashlib.sha256(out.encode('utf-8')).hexdigest().lower())
destr()
2019-04-14 22:17:11 +01:00
if __name__ == '__main__':
import sys
pytest.main(sys.argv)