2019-02-18 15:07:01 +00:00
|
|
|
"""
|
|
|
|
Checks that (hash of the) test vectors produced on this platform matches
|
|
|
|
the one provided in the META file for every scheme/implementation.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import hashlib
|
|
|
|
import os
|
2019-09-06 11:01:44 +01:00
|
|
|
import unittest
|
2019-02-18 15:07:01 +00:00
|
|
|
|
2019-07-29 09:38:25 +01:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
import helpers
|
|
|
|
import pqclean
|
2019-02-18 15:07:01 +00:00
|
|
|
|
2019-04-18 09:00:08 +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_testvectors_'))
|
|
|
|
for sig in pqclean.Signature.all_sigs()
|
|
|
|
for impl in sig.implementations],
|
|
|
|
ids=[str(impl) for sig in pqclean.Signature.all_sigs()
|
|
|
|
for impl in sig.implementations],
|
|
|
|
)
|
|
|
|
@helpers.filtered_test
|
|
|
|
def test_testvectors(implementation, impl_path, test_dir, init, destr):
|
2019-09-06 11:01:44 +01:00
|
|
|
if not implementation.supported_on_current_platform():
|
|
|
|
raise unittest.SkipTest("Not supported on current platform")
|
2019-07-29 09:38:25 +01:00
|
|
|
init()
|
|
|
|
dest_dir = os.path.join(test_dir, 'bin')
|
|
|
|
helpers.make('testvectors',
|
|
|
|
TYPE=implementation.scheme.type,
|
|
|
|
SCHEME=implementation.scheme.name,
|
|
|
|
SCHEME_DIR=impl_path,
|
|
|
|
IMPLEMENTATION=implementation.name,
|
|
|
|
DEST_DIR=dest_dir,
|
|
|
|
working_dir=os.path.join(test_dir, 'test'))
|
|
|
|
out = helpers.run_subprocess(
|
|
|
|
[os.path.join(dest_dir, 'testvectors_{}_{}{}'.format(
|
|
|
|
implementation.scheme.name,
|
|
|
|
implementation.name,
|
|
|
|
'.exe' if os.name == 'nt' else ''
|
|
|
|
))],
|
2020-06-26 07:01:23 +01:00
|
|
|
print_output=False,
|
2019-07-29 09:38:25 +01:00
|
|
|
).replace('\r', '')
|
|
|
|
assert(implementation.scheme.metadata()['testvectors-sha256'].lower()
|
|
|
|
== hashlib.sha256(out.encode('utf-8')).hexdigest().lower())
|
|
|
|
destr()
|
2019-02-18 15:07:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-07-29 09:38:25 +01:00
|
|
|
import sys
|
|
|
|
pytest.main(sys.argv)
|