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.
 
 
 
 

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