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.
 
 
 

49 lines
1.5 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 pytest
  8. import helpers
  9. import pqclean
  10. @pytest.mark.parametrize(
  11. 'implementation,test_dir,impl_path,init,destr',
  12. [(impl, *helpers.isolate_test_files(impl.path(), 'test_testvectors_'))
  13. for sig in pqclean.Signature.all_sigs()
  14. for impl in sig.implementations],
  15. ids=[str(impl) for sig in pqclean.Signature.all_sigs()
  16. for impl in sig.implementations],
  17. )
  18. @helpers.filtered_test
  19. def test_testvectors(implementation, impl_path, test_dir, init, destr):
  20. init()
  21. dest_dir = os.path.join(test_dir, 'bin')
  22. helpers.make('testvectors',
  23. TYPE=implementation.scheme.type,
  24. SCHEME=implementation.scheme.name,
  25. SCHEME_DIR=impl_path,
  26. IMPLEMENTATION=implementation.name,
  27. DEST_DIR=dest_dir,
  28. working_dir=os.path.join(test_dir, 'test'))
  29. out = helpers.run_subprocess(
  30. [os.path.join(dest_dir, 'testvectors_{}_{}{}'.format(
  31. implementation.scheme.name,
  32. implementation.name,
  33. '.exe' if os.name == 'nt' else ''
  34. ))],
  35. ).replace('\r', '')
  36. assert(implementation.scheme.metadata()['testvectors-sha256'].lower()
  37. == hashlib.sha256(out.encode('utf-8')).hexdigest().lower())
  38. destr()
  39. if __name__ == '__main__':
  40. import sys
  41. pytest.main(sys.argv)