Reference implementations of PQC
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

53 lines
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_supported_implementations()],
  18. ids=[str(impl) for impl in pqclean.Scheme.all_supported_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. print_output=False,
  38. ).replace('\r', '')
  39. assert(implementation.scheme.metadata()['nistkat-sha256'].lower()
  40. == hashlib.sha256(out.encode('utf-8')).hexdigest().lower())
  41. destr()
  42. if __name__ == '__main__':
  43. import sys
  44. pytest.main(sys.argv)