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.
 
 
 
 

55 lines
1.7 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_printparams_'))
  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. dest_dir = os.path.join(test_dir, 'bin')
  17. helpers.make('printparams',
  18. TYPE=implementation.scheme.type,
  19. SCHEME=implementation.scheme.name,
  20. IMPLEMENTATION=implementation.name,
  21. SCHEME_DIR=impl_path,
  22. DEST_DIR=dest_dir,
  23. working_dir=os.path.join(test_dir, 'test'))
  24. out = helpers.run_subprocess(
  25. [os.path.join(dest_dir, 'printparams_{}_{}{}'.format(
  26. implementation.scheme.name,
  27. implementation.name,
  28. '.exe' if os.name == 'nt' else ''
  29. ))]
  30. ).replace('\r', '')
  31. parsed = json.loads(out)
  32. assert parsed['CRYPTO_SECRETKEYBYTES'] == metadata['length-secret-key']
  33. assert parsed['CRYPTO_PUBLICKEYBYTES'] == metadata['length-public-key']
  34. assert parsed['CRYPTO_ALGNAME'] == metadata['name']
  35. if implementation.scheme.type == 'kem':
  36. assert (
  37. parsed['CRYPTO_CIPHERTEXTBYTES'] == metadata['length-ciphertext'])
  38. assert parsed['CRYPTO_BYTES'] == metadata['length-shared-secret']
  39. else:
  40. assert parsed['CRYPTO_BYTES'] == metadata['length-signature']
  41. destr()
  42. if __name__ == '__main__':
  43. import sys
  44. pytest.main(sys.argv)