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.

test_metadata_sizes.py 1.7 KiB

5 vuotta sitten
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. 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. assert parsed['CRYPTO_ALGNAME'] == metadata['name']
  34. if implementation.scheme.type == 'kem':
  35. assert (
  36. parsed['CRYPTO_CIPHERTEXTBYTES'] == metadata['length-ciphertext'])
  37. assert parsed['CRYPTO_BYTES'] == metadata['length-shared-secret']
  38. else:
  39. assert parsed['CRYPTO_BYTES'] == metadata['length-signature']
  40. destr()
  41. if __name__ == '__main__':
  42. import sys
  43. pytest.main(sys.argv)