Move duplicate consistency data outside of META.yml

This commit is contained in:
Douglas Stebila 2019-04-06 09:07:44 -04:00
parent a296085e57
commit 46aa7ff9b2
5 changed files with 27 additions and 46 deletions

View File

@ -20,17 +20,3 @@ auxiliary-submitters:
implementations: implementations:
- name: clean - name: clean
version: https://github.com/Microsoft/PQCrypto-LWEKE/commit/437e228fca580a82435cab09f30ae14b03183119 version: https://github.com/Microsoft/PQCrypto-LWEKE/commit/437e228fca580a82435cab09f30ae14b03183119
duplicate-consistency:
source_namespace: PQCLEAN_FRODOKEM640SHAKE_CLEAN_
target_namespace: PQCLEAN_FRODOKEM976SHAKE_CLEAN_
files:
- source_file: crypto_kem/frodokem640shake/clean/common.h
target_file: common.h
- source_file: crypto_kem/frodokem640shake/clean/kem.c
target_file: kem.c
- source_file: crypto_kem/frodokem640shake/clean/matrix_shake.c
target_file: matrix_shake.c
- source_file: crypto_kem/frodokem640shake/clean/noise.c
target_file: noise.c
- source_file: crypto_kem/frodokem640shake/clean/util.c
target_file: util.c

View File

@ -0,0 +1,9 @@
source:
scheme: frodokem640shake
implementation: clean
files:
- common.h
- kem.c
- matrix_shake.c
- noise.c
- util.c

View File

@ -78,6 +78,9 @@ class Implementation:
def path(self, base='..') -> str: def path(self, base='..') -> str:
return os.path.join(self.scheme.path(), self.name) return os.path.join(self.scheme.path(), self.name)
def namespace_prefix(self):
return 'PQCLEAN_{}_{}_'.format(self.scheme.name.upper(), self.name.upper()).replace('-', '')
def libname(self) -> str: def libname(self) -> str:
if os.name == 'nt': if os.name == 'nt':
return "lib{}_{}.lib".format(self.scheme.name, self.name) return "lib{}_{}.lib".format(self.scheme.name, self.name)

View File

@ -6,32 +6,33 @@ import os
import pqclean import pqclean
import helpers import helpers
import unittest import unittest
import yaml
def test_duplicate_consistency(): def test_duplicate_consistency():
for scheme in pqclean.Scheme.all_schemes(): for scheme in pqclean.Scheme.all_schemes():
for implementation in scheme.implementations: for implementation in scheme.implementations:
if os.path.isfile(os.path.join('duplicate_consistency', '{}_{}.yml'.format(scheme.name, implementation.name))):
yield check_duplicate_consistency, implementation yield check_duplicate_consistency, implementation
def file_get_contents(filename): def file_get_contents(filename):
with open(filename) as f: with open(filename) as f:
return f.read() return f.read()
def check_duplicate_consistency(implementation): def check_duplicate_consistency(implementation):
helpers.skip_windows() helpers.skip_windows()
if not('duplicate-consistency' in implementation.metadata()): metafile = os.path.join('duplicate_consistency', '{}_{}.yml'.format(implementation.scheme.name, implementation.name))
raise unittest.SkipTest('No duplicate consistency requirements defined') with open(metafile, encoding='utf-8') as f:
dc = implementation.metadata()['duplicate-consistency'] metadata = yaml.load(f.read())
for pairs in dc['files']: source = pqclean.Implementation.by_name(metadata['source']['scheme'], metadata['source']['implementation'])
for file in metadata['files']:
transformed_src = helpers.run_subprocess( transformed_src = helpers.run_subprocess(
['sed', '-e', 's/{}/{}/g'.format(dc['source_namespace'], dc['target_namespace']), pairs['source_file']], ['sed', '-e', 's/{}/{}/g'.format(source.namespace_prefix(), implementation.namespace_prefix()), os.path.join(source.path(), file)]
'..',
) )
this_src = file_get_contents(os.path.join(implementation.path(), pairs['target_file'])) this_src = file_get_contents(os.path.join(implementation.path(), file))
print(os.path.join(implementation.path(), file))
print(this_src) print(this_src)
assert(transformed_src == this_src) assert(transformed_src == this_src)
if __name__ == '__main__': if __name__ == '__main__':
try: try:
import nose2 import nose2

View File

@ -53,24 +53,6 @@ EXPECTED_FIELDS = {
'spec': { 'spec': {
'name': {'type': str}, 'name': {'type': str},
'version': {'type': str}, 'version': {'type': str},
'duplicate-consistency': {
'type': dict,
'optional': True,
'spec': {
'source_namespace': {'type': str},
'target_namespace': {'type': str},
'files': {
'type': list,
'elements': {
'type': dict,
'spec': {
'source_file': {'type': str},
'target_file': {'type': str},
},
},
},
},
},
}, },
}, },
}, },