Reference implementations of PQC
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

53 lines
1.6 KiB

  1. """
  2. Checks that (hash of the) test vectors produced on this platform matches
  3. the one provided in the META file for every scheme/implementation.
  4. """
  5. import hashlib
  6. import os
  7. import unittest
  8. import pytest
  9. import helpers
  10. import pqclean
  11. @pytest.mark.parametrize(
  12. 'implementation,test_dir,impl_path,init,destr',
  13. [(impl, *helpers.isolate_test_files(impl.path(), 'test_testvectors_'))
  14. for sig in pqclean.Signature.all_sigs()
  15. for impl in sig.implementations],
  16. ids=[str(impl) for sig in pqclean.Signature.all_sigs()
  17. for impl in sig.implementations],
  18. )
  19. @helpers.filtered_test
  20. def test_testvectors(implementation, impl_path, test_dir, init, destr):
  21. if not implementation.supported_on_current_platform():
  22. raise unittest.SkipTest("Not supported on current platform")
  23. init()
  24. dest_dir = os.path.join(test_dir, 'bin')
  25. helpers.make('testvectors',
  26. TYPE=implementation.scheme.type,
  27. SCHEME=implementation.scheme.name,
  28. SCHEME_DIR=impl_path,
  29. IMPLEMENTATION=implementation.name,
  30. DEST_DIR=dest_dir,
  31. working_dir=os.path.join(test_dir, 'test'))
  32. out = helpers.run_subprocess(
  33. [os.path.join(dest_dir, 'testvectors_{}_{}{}'.format(
  34. implementation.scheme.name,
  35. implementation.name,
  36. '.exe' if os.name == 'nt' else ''
  37. ))],
  38. print_output=False,
  39. ).replace('\r', '')
  40. assert(implementation.scheme.metadata()['testvectors-sha256'].lower()
  41. == hashlib.sha256(out.encode('utf-8')).hexdigest().lower())
  42. destr()
  43. if __name__ == '__main__':
  44. import sys
  45. pytest.main(sys.argv)