mirror of
https://github.com/henrydcase/pqc.git
synced 2024-11-23 07:59:01 +00:00
2eaf382689
* Add support for specifying architecture and feature limits * cpuinfo not supported on ppc * Detect 32-bit python interpreter on 64-bit CPU * Fix bugs in isolated tests * Also support restricting operating system
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
"""
|
|
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
|
|
import unittest
|
|
|
|
import pytest
|
|
|
|
import helpers
|
|
import pqclean
|
|
|
|
|
|
@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):
|
|
if not implementation.supported_on_current_platform():
|
|
raise unittest.SkipTest("Not supported on current platform")
|
|
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 ''
|
|
))],
|
|
).replace('\r', '')
|
|
assert(implementation.scheme.metadata()['testvectors-sha256'].lower()
|
|
== hashlib.sha256(out.encode('utf-8')).hexdigest().lower())
|
|
destr()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
import sys
|
|
pytest.main(sys.argv)
|