Skip to content

Commit

Permalink
Merge pull request #9611 from gabor-mezei-arm/9142_update_depends.py_…
Browse files Browse the repository at this point in the history
…cipher_chaining_domain

Update the `cipher_chaining` domain to use PSA macros in `depends.py`
  • Loading branch information
ronald-cron-arm authored Nov 14, 2024
2 parents 824a8dc + 6763a55 commit 0cc6860
Showing 1 changed file with 40 additions and 13 deletions.
53 changes: 40 additions & 13 deletions tests/scripts/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,19 @@ def test(self, options):
'MBEDTLS_CMAC_C'],
'PSA_WANT_ALG_GCM': ['MBEDTLS_GCM_C'],

'MBEDTLS_CIPHER_MODE_CBC': ['PSA_WANT_ALG_CBC_PKCS7',
'PSA_WANT_ALG_CBC_NO_PADDING'],
'MBEDTLS_CIPHER_MODE_CFB': ['PSA_WANT_ALG_CFB'],
'MBEDTLS_CIPHER_MODE_CTR': ['PSA_WANT_ALG_CTR'],
'MBEDTLS_CIPHER_MODE_OFB': ['PSA_WANT_ALG_OFB'],
'PSA_WANT_ALG_CBC_NO_PADDING': ['MBEDTLS_CIPHER_MODE_CBC'],
'PSA_WANT_ALG_CBC_PKCS7': ['MBEDTLS_CIPHER_MODE_CBC'],
'PSA_WANT_ALG_CFB': ['MBEDTLS_CIPHER_MODE_CFB'],
'PSA_WANT_ALG_CTR': ['MBEDTLS_CIPHER_MODE_CTR'],
'PSA_WANT_ALG_OFB': ['MBEDTLS_CIPHER_MODE_OFB'],
'PSA_WANT_ALG_XTS': ['MBEDTLS_CIPHER_MODE_XTS'],

'MBEDTLS_CIPHER_PADDING_PKCS7': ['MBEDTLS_PKCS5_C',
'MBEDTLS_PKCS12_C',
'PSA_WANT_ALG_CBC_PKCS7'],
'MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS': ['MBEDTLS_CIPHER_MODE_CBC'],
'MBEDTLS_CIPHER_PADDING_ZEROS': ['MBEDTLS_CIPHER_MODE_CBC'],
'MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN': ['MBEDTLS_CIPHER_MODE_CBC'],

'MBEDTLS_ECP_DP_BP256R1_ENABLED': ['PSA_WANT_ECC_BRAINPOOL_P_R1_256'],
'MBEDTLS_ECP_DP_BP384R1_ENABLED': ['PSA_WANT_ECC_BRAINPOOL_P_R1_384'],
Expand Down Expand Up @@ -387,19 +391,33 @@ def handle_exclusive_groups(config_settings, symbol):
dep = dep[1:]
config_settings[dep] = not unset

def turn_off_dependencies(config_settings):
def turn_off_dependencies(config_settings, exclude=None):
"""For every option turned off config_settings, also turn off what depends on it.
An option O is turned off if config_settings[O] is False.
Handle the dependencies recursively.
If 'exclude' is a symbol, ensure its dependencies are not turned off while dependencies
of other settings are turned off.
"""

# Determine recursively the settings that should not be turned off for the sake of 'exclude'.
excludes = set()
if exclude:
revdep = set(REVERSE_DEPENDENCIES.get(exclude, []))
while revdep:
dep = revdep.pop()
excludes.add(dep)
revdep.update(set(REVERSE_DEPENDENCIES.get(dep, [])) - excludes)

for key, value in sorted(config_settings.items()):
if value is not False:
continue

# Save the processed settings to handle cross referencies
revdep = set(REVERSE_DEPENDENCIES.get(key, []))
history = set()
# Save the processed settings to handle cross referencies.
# Start with set of settings that we do not want to turn off.
history = excludes.copy()
revdep = set(REVERSE_DEPENDENCIES.get(key, [])) - excludes
while revdep:
dep = revdep.pop()
history.add(dep)
Expand Down Expand Up @@ -435,7 +453,7 @@ def __init__(self, symbols, commands, exclude=None):
config_settings = base_config_settings.copy()
config_settings[symbol] = True
handle_exclusive_groups(config_settings, symbol)
turn_off_dependencies(config_settings)
turn_off_dependencies(config_settings, symbol)
job = Job(description, config_settings, commands)
self.jobs.append(job)

Expand Down Expand Up @@ -504,14 +522,23 @@ def __init__(self, options, conf):
for key_type, symbol in key_types.items()
for alg in cipher_algs
if key_type.can_do(alg)}
# Find block cipher chaining and padding mode enabling macros by name.
cipher_chaining_symbols = self.config_symbols_matching(r'MBEDTLS_CIPHER_MODE_\w+\Z')

# Get cipher modes
cipher_chaining_symbols = {algs[cipher_alg] for cipher_alg in cipher_algs}

# Find block padding mode enabling macros by name.
cipher_padding_symbols = self.config_symbols_matching(r'MBEDTLS_CIPHER_PADDING_\w+\Z')

self.domains = {
# Cipher key types
'cipher_id': ExclusiveDomain(cipher_key_types, build_and_test),

# XTS is not yet supported via the PSA API.
# See https://github.com/Mbed-TLS/mbedtls/issues/6384
'cipher_chaining': ExclusiveDomain(cipher_chaining_symbols,
build_and_test),
build_and_test,
exclude=r'PSA_WANT_ALG_XTS'),

'cipher_padding': ExclusiveDomain(cipher_padding_symbols,
build_and_test),
# Elliptic curves. Run the test suites.
Expand Down

0 comments on commit 0cc6860

Please sign in to comment.