forked from open-quantum-safe/liboqs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_alg_info.py
78 lines (73 loc) · 4.05 KB
/
test_alg_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# SPDX-License-Identifier: MIT
import helpers
import os
import os.path
import pytest
import platform
import yaml
@helpers.filtered_test
@pytest.mark.parametrize('kem_name', helpers.available_kems_by_name())
def test_alg_info_kem(kem_name):
if not(helpers.is_kem_enabled_by_name(kem_name)): pytest.skip('Not enabled')
# get the algorithm info from liboqs
output = helpers.run_subprocess([helpers.path_to_executable('dump_alg_info')])
alg_info = yaml.safe_load(output)['KEMs'][kem_name]
assert(not(alg_info['isnull']))
# find and load the datasheet
if platform.system() == 'Windows':
command = f"Select-String -Path 'docs/algorithms/kem/*' -Pattern '{kem_name}' -SimpleMatch -List | Select-Object -ExpandProperty Path"
datasheet_filename = helpers.run_subprocess(['powershell', '-Command', command]).splitlines()[0]
else:
datasheet_filename = helpers.run_subprocess(['grep', '-r', '-l', kem_name, 'docs/algorithms/kem']).splitlines()[0]
datasheet_filename = datasheet_filename.replace('.md','.yml')
with open(datasheet_filename, 'r', encoding='utf8') as datasheet_fh:
datasheet = yaml.safe_load(datasheet_fh.read())
# find the parameter set in the datasheet
foundit = False
for parameter_set in datasheet['parameter-sets']:
if parameter_set['name'] == kem_name or ('alias' in parameter_set and parameter_set['alias'] == kem_name):
foundit = True
# check that the values match
assert(alg_info['claimed-nist-level'] == parameter_set['claimed-nist-level'])
assert(alg_info['claimed-security'] == parameter_set['claimed-security'])
assert(alg_info['length-public-key'] == parameter_set['length-public-key'])
assert(alg_info['length-ciphertext'] == parameter_set['length-ciphertext'])
assert(alg_info['length-secret-key'] == parameter_set['length-secret-key'])
assert(alg_info['length-shared-secret'] == parameter_set['length-shared-secret'])
print("{:s} datasheet matches C algorithm info".format(kem_name))
break
assert(foundit)
@helpers.filtered_test
@pytest.mark.parametrize('sig_name', helpers.available_sigs_by_name())
def test_alg_info_sig(sig_name):
if not(helpers.is_sig_enabled_by_name(sig_name)): pytest.skip('Not enabled')
# get the algorithm info from liboqs
output = helpers.run_subprocess([helpers.path_to_executable('dump_alg_info')])
alg_info = yaml.safe_load(output)['SIGs'][sig_name]
assert(not(alg_info['isnull']))
# find and load the datasheet
if platform.system() == 'Windows':
command = f"Select-String -Path 'docs/algorithms/sig/*' -Pattern '{sig_name}' -SimpleMatch -List | Select-Object -ExpandProperty Path"
datasheet_filename = helpers.run_subprocess(['powershell', '-Command', command]).splitlines()[0]
else:
datasheet_filename = helpers.run_subprocess(['grep', '-r', '-l', sig_name, 'docs/algorithms/sig']).splitlines()[0]
datasheet_filename = datasheet_filename.replace('.md','.yml')
with open(datasheet_filename, 'r', encoding='utf8') as datasheet_fh:
datasheet = yaml.safe_load(datasheet_fh.read())
# find the parameter set in the datasheet
foundit = False
for parameter_set in datasheet['parameter-sets']:
if parameter_set['name'] == sig_name or ('alias' in parameter_set and parameter_set['alias'] == sig_name):
foundit = True
# check that the values match
assert(alg_info['claimed-nist-level'] == parameter_set['claimed-nist-level'])
assert(alg_info['claimed-security'] == parameter_set['claimed-security'])
assert(alg_info['length-public-key'] == parameter_set['length-public-key'])
assert(alg_info['length-secret-key'] == parameter_set['length-secret-key'])
assert(alg_info['length-signature'] == parameter_set['length-signature'])
print("{:s} datasheet matches C algorithm info".format(sig_name))
break
assert(foundit)
if __name__ == "__main__":
import sys
pytest.main(sys.argv)