Replace stringly typed data by class: driver vs reference (data)

Work on the stringly typed KNOWN_TASKS by classes for each category
of tasks, with a structure that matches the behavior.

This commit migrates the data for driver-vs-reference analysis and gets rid
of the transitional code that was using the old form of the data.

No intended behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine 2024-09-16 20:14:26 +02:00
parent 17e071b0ab
commit 92cc8dba27

View File

@ -272,32 +272,22 @@ class DriverVSReference(Task):
ignored_suites, self.IGNORED_TESTS) ignored_suites, self.IGNORED_TESTS)
def driver_vs_reference_factory(name: str, # The names that we give to classes derived from DriverVSReference do not
args: typing.Dict[str, typing.Any] # follow the usual naming convention, because it's more readable to use
) -> typing.Type[DriverVSReference]: # underscores and parts of the configuration names. Also, these classes
"""Build a driver-vs-reference class from dynamic data.""" # are just there to specify some data, so they don't need repetitive
return type('Drivervsreference_' + name, # documentation.
(DriverVSReference,), #pylint: disable=invalid-name,missing-class-docstring
{
'REFERENCE': args['component_ref'],
'DRIVER': args['component_driver'],
'IGNORED_SUITES': args['ignored_suites'],
'IGNORED_TESTS': args['ignored_tests'],
})
# List of tasks with a function that can handle this task and additional arguments if required class DriverVSReference_hash(DriverVSReference):
KNOWN_TASKS = { REFERENCE = 'test_psa_crypto_config_reference_hash_use_psa'
'analyze_coverage': CoverageTask, DRIVER = 'test_psa_crypto_config_accel_hash_use_psa'
IGNORED_SUITES = [
'analyze_driver_vs_reference_hash': driver_vs_reference_factory('hash', {
'component_ref': 'test_psa_crypto_config_reference_hash_use_psa',
'component_driver': 'test_psa_crypto_config_accel_hash_use_psa',
'ignored_suites': [
'shax', 'mdx', # the software implementations that are being excluded 'shax', 'mdx', # the software implementations that are being excluded
'md.psa', # purposefully depends on whether drivers are present 'md.psa', # purposefully depends on whether drivers are present
'psa_crypto_low_hash.generated', # testing the builtins 'psa_crypto_low_hash.generated', # testing the builtins
], ]
'ignored_tests': { IGNORED_TESTS = {
'test_suite_config': [ 'test_suite_config': [
re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'), re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
], ],
@ -308,20 +298,19 @@ KNOWN_TASKS = {
'Check mbedtls_calloc overallocation', 'Check mbedtls_calloc overallocation',
], ],
} }
}
), class DriverVSReference_hmac(DriverVSReference):
'analyze_driver_vs_reference_hmac': driver_vs_reference_factory('hmac', { REFERENCE = 'test_psa_crypto_config_reference_hmac'
'component_ref': 'test_psa_crypto_config_reference_hmac', DRIVER = 'test_psa_crypto_config_accel_hmac'
'component_driver': 'test_psa_crypto_config_accel_hmac', IGNORED_SUITES = [
'ignored_suites': [
# These suites require legacy hash support, which is disabled # These suites require legacy hash support, which is disabled
# in the accelerated component. # in the accelerated component.
'shax', 'mdx', 'shax', 'mdx',
# This suite tests builtins directly, but these are missing # This suite tests builtins directly, but these are missing
# in the accelerated case. # in the accelerated case.
'psa_crypto_low_hash.generated', 'psa_crypto_low_hash.generated',
], ]
'ignored_tests': { IGNORED_TESTS = {
'test_suite_config': [ 'test_suite_config': [
re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'), re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
re.compile(r'.*\bMBEDTLS_MD_C\b') re.compile(r'.*\bMBEDTLS_MD_C\b')
@ -348,21 +337,20 @@ KNOWN_TASKS = {
'Check mbedtls_calloc overallocation', 'Check mbedtls_calloc overallocation',
], ],
} }
}
), class DriverVSReference_cipher_aead_cmac(DriverVSReference):
'analyze_driver_vs_reference_cipher_aead_cmac': driver_vs_reference_factory('cipher_aead_cmac', { REFERENCE = 'test_psa_crypto_config_reference_cipher_aead_cmac'
'component_ref': 'test_psa_crypto_config_reference_cipher_aead_cmac', DRIVER = 'test_psa_crypto_config_accel_cipher_aead_cmac'
'component_driver': 'test_psa_crypto_config_accel_cipher_aead_cmac',
# Modules replaced by drivers. # Modules replaced by drivers.
'ignored_suites': [ IGNORED_SUITES = [
# low-level (block/stream) cipher modules # low-level (block/stream) cipher modules
'aes', 'aria', 'camellia', 'des', 'chacha20', 'aes', 'aria', 'camellia', 'des', 'chacha20',
# AEAD modes and CMAC # AEAD modes and CMAC
'ccm', 'chachapoly', 'cmac', 'gcm', 'ccm', 'chachapoly', 'cmac', 'gcm',
# The Cipher abstraction layer # The Cipher abstraction layer
'cipher', 'cipher',
], ]
'ignored_tests': { IGNORED_TESTS = {
'test_suite_config': [ 'test_suite_config': [
re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA|CHACHA20|DES)_.*'), re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA|CHACHA20|DES)_.*'),
re.compile(r'.*\bMBEDTLS_(CCM|CHACHAPOLY|CMAC|GCM)_.*'), re.compile(r'.*\bMBEDTLS_(CCM|CHACHAPOLY|CMAC|GCM)_.*'),
@ -416,16 +404,15 @@ KNOWN_TASKS = {
'TLS: password protected server key, two certificates', 'TLS: password protected server key, two certificates',
], ],
} }
}
), class DriverVSReference_ecp_light_only(DriverVSReference):
'analyze_driver_vs_reference_ecp_light_only': driver_vs_reference_factory('ecp_light_only', { REFERENCE = 'test_psa_crypto_config_reference_ecc_ecp_light_only'
'component_ref': 'test_psa_crypto_config_reference_ecc_ecp_light_only', DRIVER = 'test_psa_crypto_config_accel_ecc_ecp_light_only'
'component_driver': 'test_psa_crypto_config_accel_ecc_ecp_light_only', IGNORED_SUITES = [
'ignored_suites': [
# Modules replaced by drivers # Modules replaced by drivers
'ecdsa', 'ecdh', 'ecjpake', 'ecdsa', 'ecdh', 'ecjpake',
], ]
'ignored_tests': { IGNORED_TESTS = {
'test_suite_config': [ 'test_suite_config': [
re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'), re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
], ],
@ -457,16 +444,15 @@ KNOWN_TASKS = {
'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()', 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
], ],
} }
}
), class DriverVSReference_no_ecp_at_all(DriverVSReference):
'analyze_driver_vs_reference_no_ecp_at_all': driver_vs_reference_factory('no_ecp_at_all', { REFERENCE = 'test_psa_crypto_config_reference_ecc_no_ecp_at_all'
'component_ref': 'test_psa_crypto_config_reference_ecc_no_ecp_at_all', DRIVER = 'test_psa_crypto_config_accel_ecc_no_ecp_at_all'
'component_driver': 'test_psa_crypto_config_accel_ecc_no_ecp_at_all', IGNORED_SUITES = [
'ignored_suites': [
# Modules replaced by drivers # Modules replaced by drivers
'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
], ]
'ignored_tests': { IGNORED_TESTS = {
'test_suite_config': [ 'test_suite_config': [
re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'), re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'), re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
@ -496,18 +482,17 @@ KNOWN_TASKS = {
'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()', 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
], ],
} }
}
), class DriverVSReference_ecc_no_bignum(DriverVSReference):
'analyze_driver_vs_reference_ecc_no_bignum': driver_vs_reference_factory('ecc_no_bignum', { REFERENCE = 'test_psa_crypto_config_reference_ecc_no_bignum'
'component_ref': 'test_psa_crypto_config_reference_ecc_no_bignum', DRIVER = 'test_psa_crypto_config_accel_ecc_no_bignum'
'component_driver': 'test_psa_crypto_config_accel_ecc_no_bignum', IGNORED_SUITES = [
'ignored_suites': [
# Modules replaced by drivers # Modules replaced by drivers
'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw', 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
'bignum.generated', 'bignum.misc', 'bignum.generated', 'bignum.misc',
], ]
'ignored_tests': { IGNORED_TESTS = {
'test_suite_config': [ 'test_suite_config': [
re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'), re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'), re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
@ -542,18 +527,17 @@ KNOWN_TASKS = {
'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()', 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
], ],
} }
}
), class DriverVSReference_ecc_ffdh_no_bignum(DriverVSReference):
'analyze_driver_vs_reference_ecc_ffdh_no_bignum': driver_vs_reference_factory('ecc_ffdh_no_bignum', { REFERENCE = 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum'
'component_ref': 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum', DRIVER = 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum'
'component_driver': 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum', IGNORED_SUITES = [
'ignored_suites': [
# Modules replaced by drivers # Modules replaced by drivers
'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'dhm', 'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'dhm',
'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw', 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
'bignum.generated', 'bignum.misc', 'bignum.generated', 'bignum.misc',
], ]
'ignored_tests': { IGNORED_TESTS = {
'ssl-opt': [ 'ssl-opt': [
# DHE support in TLS 1.2 requires built-in MBEDTLS_DHM_C # DHE support in TLS 1.2 requires built-in MBEDTLS_DHM_C
# (because it needs custom groups, which PSA does not # (because it needs custom groups, which PSA does not
@ -596,13 +580,12 @@ KNOWN_TASKS = {
'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()', 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
], ],
} }
}
), class DriverVSReference_ffdh_alg(DriverVSReference):
'analyze_driver_vs_reference_ffdh_alg': driver_vs_reference_factory('ffdh_alg', { REFERENCE = 'test_psa_crypto_config_reference_ffdh'
'component_ref': 'test_psa_crypto_config_reference_ffdh', DRIVER = 'test_psa_crypto_config_accel_ffdh'
'component_driver': 'test_psa_crypto_config_accel_ffdh', IGNORED_SUITES = ['dhm']
'ignored_suites': ['dhm'], IGNORED_TESTS = {
'ignored_tests': {
'test_suite_config': [ 'test_suite_config': [
re.compile(r'.*\bMBEDTLS_DHM_C\b.*'), re.compile(r'.*\bMBEDTLS_DHM_C\b.*'),
], ],
@ -613,19 +596,18 @@ KNOWN_TASKS = {
'Check mbedtls_calloc overallocation', 'Check mbedtls_calloc overallocation',
], ],
} }
}
), class DriverVSReference_tfm_config(DriverVSReference):
'analyze_driver_vs_reference_tfm_config': driver_vs_reference_factory('tfm_config', { REFERENCE = 'test_tfm_config_no_p256m'
'component_ref': 'test_tfm_config_no_p256m', DRIVER = 'test_tfm_config_p256m_driver_accel_ec'
'component_driver': 'test_tfm_config_p256m_driver_accel_ec', IGNORED_SUITES = [
'ignored_suites': [
# Modules replaced by drivers # Modules replaced by drivers
'asn1parse', 'asn1write', 'asn1parse', 'asn1write',
'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw', 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
'bignum.generated', 'bignum.misc', 'bignum.generated', 'bignum.misc',
], ]
'ignored_tests': { IGNORED_TESTS = {
'test_suite_config': [ 'test_suite_config': [
re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'), re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
re.compile(r'.*\bMBEDTLS_(ASN1\w+)_C\b.*'), re.compile(r'.*\bMBEDTLS_(ASN1\w+)_C\b.*'),
@ -646,18 +628,17 @@ KNOWN_TASKS = {
'PSA classic wrapper: ECDSA signature (SECP256R1)', 'PSA classic wrapper: ECDSA signature (SECP256R1)',
], ],
} }
}
), class DriverVSReference_rsa(DriverVSReference):
'analyze_driver_vs_reference_rsa': driver_vs_reference_factory('rsa', { REFERENCE = 'test_psa_crypto_config_reference_rsa_crypto'
'component_ref': 'test_psa_crypto_config_reference_rsa_crypto', DRIVER = 'test_psa_crypto_config_accel_rsa_crypto'
'component_driver': 'test_psa_crypto_config_accel_rsa_crypto', IGNORED_SUITES = [
'ignored_suites': [
# Modules replaced by drivers. # Modules replaced by drivers.
'rsa', 'pkcs1_v15', 'pkcs1_v21', 'rsa', 'pkcs1_v15', 'pkcs1_v21',
# We temporarily don't care about PK stuff. # We temporarily don't care about PK stuff.
'pk', 'pkwrite', 'pkparse' 'pk', 'pkwrite', 'pkparse'
], ]
'ignored_tests': { IGNORED_TESTS = {
'test_suite_config': [ 'test_suite_config': [
re.compile(r'.*\bMBEDTLS_(PKCS1|RSA)_.*'), re.compile(r'.*\bMBEDTLS_(PKCS1|RSA)_.*'),
re.compile(r'.*\bMBEDTLS_GENPRIME\b.*') re.compile(r'.*\bMBEDTLS_GENPRIME\b.*')
@ -686,12 +667,11 @@ KNOWN_TASKS = {
re.compile(r'PSA generate key ext: RSA, e=.*'), re.compile(r'PSA generate key ext: RSA, e=.*'),
], ],
} }
}
), class DriverVSReference_block_cipher_dispatch(DriverVSReference):
'analyze_block_cipher_dispatch': driver_vs_reference_factory('block_cipher_dispatch', { REFERENCE = 'test_full_block_cipher_legacy_dispatch'
'component_ref': 'test_full_block_cipher_legacy_dispatch', DRIVER = 'test_full_block_cipher_psa_dispatch'
'component_driver': 'test_full_block_cipher_psa_dispatch', IGNORED_SUITES = [
'ignored_suites': [
# Skipped in the accelerated component # Skipped in the accelerated component
'aes', 'aria', 'camellia', 'aes', 'aria', 'camellia',
# These require AES_C, ARIA_C or CAMELLIA_C to be enabled in # These require AES_C, ARIA_C or CAMELLIA_C to be enabled in
@ -700,8 +680,8 @@ KNOWN_TASKS = {
# component so we ignore them. # component so we ignore them.
'cipher.ccm', 'cipher.gcm', 'cipher.aes', 'cipher.aria', 'cipher.ccm', 'cipher.gcm', 'cipher.aes', 'cipher.aria',
'cipher.camellia', 'cipher.camellia',
], ]
'ignored_tests': { IGNORED_TESTS = {
'test_suite_config': [ 'test_suite_config': [
re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA)_.*'), re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA)_.*'),
re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'), re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'),
@ -751,9 +731,27 @@ KNOWN_TASKS = {
'Check mbedtls_calloc overallocation', 'Check mbedtls_calloc overallocation',
], ],
} }
#pylint: enable=invalid-name,missing-class-docstring
# List of tasks with a function that can handle this task and additional arguments if required
KNOWN_TASKS = {
'analyze_coverage': CoverageTask,
'analyze_driver_vs_reference_hash': DriverVSReference_hash,
'analyze_driver_vs_reference_hmac': DriverVSReference_hmac,
'analyze_driver_vs_reference_cipher_aead_cmac': DriverVSReference_cipher_aead_cmac,
'analyze_driver_vs_reference_ecp_light_only': DriverVSReference_ecp_light_only,
'analyze_driver_vs_reference_no_ecp_at_all': DriverVSReference_no_ecp_at_all,
'analyze_driver_vs_reference_ecc_no_bignum': DriverVSReference_ecc_no_bignum,
'analyze_driver_vs_reference_ecc_ffdh_no_bignum': DriverVSReference_ecc_ffdh_no_bignum,
'analyze_driver_vs_reference_ffdh_alg': DriverVSReference_ffdh_alg,
'analyze_driver_vs_reference_tfm_config': DriverVSReference_tfm_config,
'analyze_driver_vs_reference_rsa': DriverVSReference_rsa,
'analyze_block_cipher_dispatch': DriverVSReference_block_cipher_dispatch,
} }
),
}
def main(): def main():
main_results = Results() main_results = Results()