diff --git a/scripts/mbedtls_dev/macro_collector.py b/scripts/mbedtls_dev/macro_collector.py index 0c9a9a5b2e..f5f81c8a45 100644 --- a/scripts/mbedtls_dev/macro_collector.py +++ b/scripts/mbedtls_dev/macro_collector.py @@ -301,7 +301,7 @@ class PSAMacroCollector(PSAMacroEnumerator): self.read_line(line) -class InputsForTest(PSAMacroEnumerator): +class InputsForTest(PSAMacroCollector): # pylint: disable=too-many-instance-attributes """Accumulate information about macros to test. enumerate @@ -312,27 +312,6 @@ enumerate def __init__(self) -> None: super().__init__() self.all_declared = set() #type: Set[str] - # Sets of names per type - self.statuses.add('PSA_SUCCESS') - self.algorithms.add('0xffffffff') - self.ecc_curves.add('0xff') - self.dh_groups.add('0xff') - self.key_types.add('0xffff') - self.key_usage_flags.add('0x80000000') - - # Hard-coded values for unknown algorithms - # - # These have to have values that are correct for their respective - # PSA_ALG_IS_xxx macros, but are also not currently assigned and are - # not likely to be assigned in the near future. - self.hash_algorithms.add('0x020000fe') # 0x020000ff is PSA_ALG_ANY_HASH - self.mac_algorithms.add('0x03007fff') - self.ka_algorithms.add('0x09fc0000') - self.kdf_algorithms.add('0x080000ff') - # For AEAD algorithms, the only variability is over the tag length, - # and this only applies to known algorithms, so don't test an - # unknown algorithm. - # Identifier prefixes self.table_by_prefix = { 'ERROR': self.statuses, @@ -370,6 +349,28 @@ enumerate self.arguments_for['tag_length'] += ['1', '63'] self.arguments_for['min_tag_length'] += ['1', '63'] + def add_numerical_values(self) -> None: + """Add numerical values that are not supported to the known identifiers.""" + # Sets of names per type + self.algorithms.add('0xffffffff') + self.ecc_curves.add('0xff') + self.dh_groups.add('0xff') + self.key_types.add('0xffff') + self.key_usage_flags.add('0x80000000') + + # Hard-coded values for unknown algorithms + # + # These have to have values that are correct for their respective + # PSA_ALG_IS_xxx macros, but are also not currently assigned and are + # not likely to be assigned in the near future. + self.hash_algorithms.add('0x020000fe') # 0x020000ff is PSA_ALG_ANY_HASH + self.mac_algorithms.add('0x03007fff') + self.ka_algorithms.add('0x09fc0000') + self.kdf_algorithms.add('0x080000ff') + # For AEAD algorithms, the only variability is over the tag length, + # and this only applies to known algorithms, so don't test an + # unknown algorithm. + def get_names(self, type_word: str) -> Set[str]: """Return the set of known names of values of the given type.""" return { diff --git a/tests/scripts/generate_psa_tests.py b/tests/scripts/generate_psa_tests.py index 30f82db257..8de819b8d4 100755 --- a/tests/scripts/generate_psa_tests.py +++ b/tests/scripts/generate_psa_tests.py @@ -111,13 +111,14 @@ class Information: def read_psa_interface(self) -> macro_collector.PSAMacroCollector: """Return the list of known key types, algorithms, etc.""" - constructors = macro_collector.PSAMacroCollector() + constructors = macro_collector.InputsForTest() header_file_names = ['include/psa/crypto_values.h', 'include/psa/crypto_extra.h'] for header_file_name in header_file_names: with open(header_file_name, 'rb') as header_file: constructors.read_file(header_file) self.remove_unwanted_macros(constructors) + constructors.gather_arguments() return constructors diff --git a/tests/scripts/test_psa_constant_names.py b/tests/scripts/test_psa_constant_names.py index c6f23054cf..07c8ab2e97 100755 --- a/tests/scripts/test_psa_constant_names.py +++ b/tests/scripts/test_psa_constant_names.py @@ -44,6 +44,7 @@ def gather_inputs(headers: Iterable[str], inputs.parse_header(header) for test_cases in test_suites: inputs.parse_test_cases(test_cases) + inputs.add_numerical_values() inputs.gather_arguments() return inputs