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.

43 lines
1.3 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 pqclean
  8. import helpers
  9. def test_testvectors():
  10. @helpers.filtered_test
  11. def check_testvectors(implementation):
  12. helpers.make('testvectors',
  13. TYPE=implementation.scheme.type,
  14. SCHEME=implementation.scheme.name,
  15. IMPLEMENTATION=implementation.name,
  16. working_dir=os.path.join('..', 'test'))
  17. out = helpers.run_subprocess(
  18. [os.path.join('..', 'bin', 'testvectors_{}_{}{}'.format(
  19. implementation.scheme.name,
  20. implementation.name,
  21. '.exe' if os.name == 'nt' else ''
  22. ))],
  23. os.path.join('..', 'bin'),
  24. ).replace('\r', '')
  25. assert(implementation.scheme.metadata()['testvectors-sha256'].lower()
  26. == hashlib.sha256(out.encode('utf-8')).hexdigest().lower())
  27. for scheme in pqclean.Scheme.all_schemes():
  28. for implementation in scheme.implementations:
  29. yield check_testvectors, implementation
  30. if __name__ == '__main__':
  31. try:
  32. import nose2
  33. nose2.main()
  34. except ImportError:
  35. import nose
  36. nose.runmodule()