2019-04-05 16:04:37 +01:00
|
|
|
import json
|
|
|
|
import os
|
|
|
|
|
2019-07-29 09:38:25 +01:00
|
|
|
import pytest
|
2019-04-05 16:04:37 +01:00
|
|
|
|
2019-07-29 09:38:25 +01:00
|
|
|
import helpers
|
|
|
|
import pqclean
|
2019-04-05 16:04:37 +01:00
|
|
|
|
|
|
|
|
2019-07-29 09:38:25 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'implementation,test_dir,impl_path, init, destr',
|
2019-09-06 11:01:44 +01:00
|
|
|
[(impl, *helpers.isolate_test_files(impl.path(), 'test_printparams_'))
|
2019-07-29 09:38:25 +01:00
|
|
|
for impl in pqclean.Scheme.all_implementations()],
|
|
|
|
ids=[str(impl) for impl in pqclean.Scheme.all_implementations()],
|
|
|
|
)
|
2019-04-18 09:00:08 +01:00
|
|
|
@helpers.filtered_test
|
2019-07-29 09:38:25 +01:00
|
|
|
def test_metadata_sizes(implementation, impl_path, test_dir, init, destr):
|
|
|
|
init()
|
2019-04-05 16:04:37 +01:00
|
|
|
metadata = implementation.scheme.metadata()
|
|
|
|
helpers.make('printparams',
|
|
|
|
TYPE=implementation.scheme.type,
|
|
|
|
SCHEME=implementation.scheme.name,
|
|
|
|
IMPLEMENTATION=implementation.name,
|
2019-07-29 09:38:25 +01:00
|
|
|
SCHEME_DIR=impl_path,
|
2019-04-05 16:04:37 +01:00
|
|
|
working_dir=os.path.join('..', 'test'))
|
|
|
|
|
|
|
|
out = helpers.run_subprocess(
|
|
|
|
[os.path.join('..', 'bin', 'printparams_{}_{}{}'.format(
|
|
|
|
implementation.scheme.name,
|
|
|
|
implementation.name,
|
|
|
|
'.exe' if os.name == 'nt' else ''
|
|
|
|
))],
|
|
|
|
os.path.join('..', 'bin'),
|
|
|
|
).replace('\r', '')
|
|
|
|
|
|
|
|
parsed = json.loads(out)
|
|
|
|
|
2019-04-17 09:55:10 +01:00
|
|
|
assert parsed['CRYPTO_SECRETKEYBYTES'] == metadata['length-secret-key']
|
2019-04-05 16:04:37 +01:00
|
|
|
assert parsed['CRYPTO_PUBLICKEYBYTES'] == metadata['length-public-key']
|
2019-09-19 11:43:57 +01:00
|
|
|
assert parsed['CRYPTO_ALGNAME'] == metadata['name']
|
2019-04-05 16:04:37 +01:00
|
|
|
|
|
|
|
if implementation.scheme.type == 'kem':
|
|
|
|
assert (
|
|
|
|
parsed['CRYPTO_CIPHERTEXTBYTES'] == metadata['length-ciphertext'])
|
|
|
|
assert parsed['CRYPTO_BYTES'] == metadata['length-shared-secret']
|
|
|
|
else:
|
|
|
|
assert parsed['CRYPTO_BYTES'] == metadata['length-signature']
|
2019-07-29 09:38:25 +01:00
|
|
|
destr()
|
2019-04-05 16:04:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-07-29 09:38:25 +01:00
|
|
|
import sys
|
|
|
|
pytest.main(sys.argv)
|