mirror of
https://github.com/henrydcase/pqc.git
synced 2024-11-26 17:31:38 +00:00
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
|
import json
|
||
|
import os
|
||
|
|
||
|
import pqclean
|
||
|
import helpers
|
||
|
|
||
|
|
||
|
def test_metadata_sizes():
|
||
|
for scheme in pqclean.Scheme.all_schemes():
|
||
|
for implementation in scheme.implementations:
|
||
|
yield check_metadata_sizes, implementation
|
||
|
|
||
|
|
||
|
def check_metadata_sizes(implementation):
|
||
|
metadata = implementation.scheme.metadata()
|
||
|
helpers.make('printparams',
|
||
|
TYPE=implementation.scheme.type,
|
||
|
SCHEME=implementation.scheme.name,
|
||
|
IMPLEMENTATION=implementation.name,
|
||
|
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)
|
||
|
|
||
|
assert parsed['CRYPTO_SECRETKEYBYTES'] == metadata['length-secret-key']
|
||
|
assert parsed['CRYPTO_PUBLICKEYBYTES'] == metadata['length-public-key']
|
||
|
|
||
|
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']
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
try:
|
||
|
import nose2
|
||
|
nose2.main()
|
||
|
except ImportError:
|
||
|
import nose
|
||
|
nose.runmodule()
|