Reference implementations of PQC
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

52 řádky
1.7 KiB

  1. """
  2. Checks that (hash of the) KATs (in NIST format) produced on this platform match
  3. the one provided in the META file for every scheme/implementation.
  4. Note that this only uses the first test case from the NIST-format KAT files.
  5. The appropriate hash can be generated from the original submission's KAT file
  6. using the command:
  7. cat PQCkemKAT_whatever.rsp | head -n 8 | tail -n 6 | sha256sum
  8. """
  9. import hashlib
  10. import os
  11. import pytest
  12. import helpers
  13. import pqclean
  14. @pytest.mark.parametrize(
  15. 'implementation,test_dir,impl_path, init, destr',
  16. [(impl, *helpers.isolate_test_files(impl.path(), 'test_functest_'))
  17. for impl in pqclean.Scheme.all_implementations()],
  18. ids=[str(impl) for impl in pqclean.Scheme.all_implementations()],
  19. )
  20. @helpers.filtered_test
  21. def test_nistkat(implementation, impl_path, test_dir, init, destr):
  22. init()
  23. dest_path = os.path.join(test_dir, 'bin')
  24. helpers.make('nistkat',
  25. TYPE=implementation.scheme.type,
  26. SCHEME=implementation.scheme.name,
  27. IMPLEMENTATION=implementation.name,
  28. SCHEME_DIR=impl_path,
  29. DEST_DIR=dest_path,
  30. working_dir=os.path.join(test_dir, 'test'))
  31. out = helpers.run_subprocess(
  32. [os.path.join(dest_path, 'nistkat_{}_{}{}'.format(
  33. implementation.scheme.name,
  34. implementation.name,
  35. '.exe' if os.name == 'nt' else ''
  36. ))],
  37. ).replace('\r', '')
  38. assert(implementation.scheme.metadata()['nistkat-sha256'].lower()
  39. == hashlib.sha256(out.encode('utf-8')).hexdigest().lower())
  40. destr()
  41. if __name__ == '__main__':
  42. import sys
  43. pytest.main(sys.argv)