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.
 
 
 
 

53 lines
1.6 KiB

  1. import json
  2. import os
  3. import pytest
  4. import helpers
  5. import pqclean
  6. @pytest.mark.parametrize(
  7. 'implementation,test_dir,impl_path, init, destr',
  8. [(impl, *helpers.isolate_test_files(impl.path(), 'test_functest_'))
  9. for impl in pqclean.Scheme.all_implementations()],
  10. ids=[str(impl) for impl in pqclean.Scheme.all_implementations()],
  11. )
  12. @helpers.filtered_test
  13. def test_metadata_sizes(implementation, impl_path, test_dir, init, destr):
  14. init()
  15. metadata = implementation.scheme.metadata()
  16. helpers.make('printparams',
  17. TYPE=implementation.scheme.type,
  18. SCHEME=implementation.scheme.name,
  19. IMPLEMENTATION=implementation.name,
  20. SCHEME_DIR=impl_path,
  21. working_dir=os.path.join('..', 'test'))
  22. out = helpers.run_subprocess(
  23. [os.path.join('..', 'bin', 'printparams_{}_{}{}'.format(
  24. implementation.scheme.name,
  25. implementation.name,
  26. '.exe' if os.name == 'nt' else ''
  27. ))],
  28. os.path.join('..', 'bin'),
  29. ).replace('\r', '')
  30. parsed = json.loads(out)
  31. assert parsed['CRYPTO_SECRETKEYBYTES'] == metadata['length-secret-key']
  32. assert parsed['CRYPTO_PUBLICKEYBYTES'] == metadata['length-public-key']
  33. if implementation.scheme.type == 'kem':
  34. assert (
  35. parsed['CRYPTO_CIPHERTEXTBYTES'] == metadata['length-ciphertext'])
  36. assert parsed['CRYPTO_BYTES'] == metadata['length-shared-secret']
  37. else:
  38. assert parsed['CRYPTO_BYTES'] == metadata['length-signature']
  39. destr()
  40. if __name__ == '__main__':
  41. import sys
  42. pytest.main(sys.argv)