blob: 09e1245868e7962d58f816b3172a40bcfb839fbf [file] [log] [blame]
Gilles Peskine15c2cbf2020-06-25 18:36:28 +02001#!/usr/bin/env python3
2
3"""Analyze the test outcomes from a full CI run.
4
5This script can also run on outcomes from a partial run, but the results are
6less likely to be useful.
7"""
8
Przemek Stekiel85c54ea2022-11-17 11:50:23 +01009import re
Gilles Peskined8da2fc2024-09-17 15:07:22 +020010import typing
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020011
Gilles Peskine738a5972024-10-03 18:52:58 +020012import scripts_path # pylint: disable=unused-import
13from mbedtls_framework import outcome_analysis
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020014
Pengyu Lvc2e8f3a2023-11-28 17:22:04 +080015
Gilles Peskine45a32b12024-10-03 18:42:37 +020016class CoverageTask(outcome_analysis.CoverageTask):
Gilles Peskine4e606db2024-10-04 16:24:26 +020017 """Justify test cases that are never executed."""
Gilles Peskine95b2b0c2024-09-16 20:23:40 +020018
Gilles Peskined8da2fc2024-09-17 15:07:22 +020019 @staticmethod
Gilles Peskine72396da2024-09-17 17:15:29 +020020 def _has_word_re(words: typing.Iterable[str],
21 exclude: typing.Optional[str] = None) -> typing.Pattern:
Gilles Peskined8da2fc2024-09-17 15:07:22 +020022 """Construct a regex that matches if any of the words appears.
23
24 The occurrence must start and end at a word boundary.
Gilles Peskine72396da2024-09-17 17:15:29 +020025
26 If exclude is specified, strings containing a match for that
27 regular expression will not match the returned pattern.
Gilles Peskined8da2fc2024-09-17 15:07:22 +020028 """
Gilles Peskine72396da2024-09-17 17:15:29 +020029 exclude_clause = r''
30 if exclude:
31 exclude_clause = r'(?!.*' + exclude + ')'
32 return re.compile(exclude_clause +
33 r'.*\b(?:' + r'|'.join(words) + r')\b.*',
Gilles Peskine1abc8002024-10-11 12:00:44 +020034 re.DOTALL)
Gilles Peskined8da2fc2024-09-17 15:07:22 +020035
36 # generate_psa_tests.py generates test cases involving cryptographic
37 # mechanisms (key types, families, algorithms) that are declared but
38 # not implemented. Until we improve the Python scripts, ignore those
39 # test cases in the analysis.
40 # https://github.com/Mbed-TLS/mbedtls/issues/9572
41 _PSA_MECHANISMS_NOT_IMPLEMENTED = [
42 r'CBC_MAC',
43 r'DETERMINISTIC_DSA',
44 r'DET_DSA',
45 r'DSA',
46 r'ECC_KEY_PAIR\(BRAINPOOL_P_R1\) (?:160|192|224|320)-bit',
47 r'ECC_KEY_PAIR\(SECP_K1\) 225-bit',
48 r'ECC_PAIR\(BP_R1\) (?:160|192|224|320)-bit',
49 r'ECC_PAIR\(SECP_K1\) 225-bit',
50 r'ECC_PUBLIC_KEY\(BRAINPOOL_P_R1\) (?:160|192|224|320)-bit',
51 r'ECC_PUBLIC_KEY\(SECP_K1\) 225-bit',
52 r'ECC_PUB\(BP_R1\) (?:160|192|224|320)-bit',
53 r'ECC_PUB\(SECP_K1\) 225-bit',
54 r'ED25519PH',
55 r'ED448PH',
56 r'PEPPER',
57 r'PURE_EDDSA',
58 r'SECP_R2',
59 r'SECT_K1',
60 r'SECT_R1',
61 r'SECT_R2',
62 r'SHAKE256_512',
63 r'SHA_512_224',
64 r'SHA_512_256',
65 r'TWISTED_EDWARDS',
66 r'XTS',
67 ]
68 PSA_MECHANISM_NOT_IMPLEMENTED_SEARCH_RE = \
69 _has_word_re(_PSA_MECHANISMS_NOT_IMPLEMENTED)
70
71 IGNORED_TESTS = {
Gilles Peskine419a5842024-09-17 18:32:05 +020072 'ssl-opt': [
73 # We don't run ssl-opt.sh with Valgrind on the CI because
74 # it's extremely slow. We don't intend to change this.
75 'DTLS client reconnect from same port: reconnect, nbio, valgrind',
Gilles Peskine419a5842024-09-17 18:32:05 +020076 # We don't have IPv6 in our CI environment.
77 # https://github.com/Mbed-TLS/mbedtls-test/issues/176
78 'DTLS cookie: enabled, IPv6',
79 # Disabled due to OpenSSL bug.
80 # https://github.com/openssl/openssl/issues/18887
81 'DTLS fragmenting: 3d, openssl client, DTLS 1.2',
82 # We don't run ssl-opt.sh with Valgrind on the CI because
83 # it's extremely slow. We don't intend to change this.
84 'DTLS fragmenting: proxy MTU: auto-reduction (with valgrind)',
85 # It seems that we don't run `ssl-opt.sh` with
86 # `MBEDTLS_USE_PSA_CRYPTO` enabled but `MBEDTLS_SSL_ASYNC_PRIVATE`
87 # disabled.
88 # https://github.com/Mbed-TLS/mbedtls/issues/9581
89 'Opaque key for server authentication: invalid key: decrypt with ECC key, no async',
90 'Opaque key for server authentication: invalid key: ecdh with RSA key, no async',
91 ],
Gilles Peskine47243fd2024-09-17 19:46:18 +020092 'test_suite_config.mbedtls_boolean': [
93 # We never test with CBC/PKCS5/PKCS12 enabled but
94 # PKCS7 padding disabled.
95 # https://github.com/Mbed-TLS/mbedtls/issues/9580
96 'Config: !MBEDTLS_CIPHER_PADDING_PKCS7',
97 # https://github.com/Mbed-TLS/mbedtls/issues/9583
98 'Config: !MBEDTLS_ECP_NIST_OPTIM',
Gilles Peskine44fdd922024-10-10 18:19:23 +020099 # MBEDTLS_ECP_NO_FALLBACK only affects builds using a partial
100 # alternative implementation of ECP arithmetic (with
101 # MBEDTLS_ECP_INTERNAL_ALT enabled). We don't test those builds.
102 # The configuration enumeration script skips xxx_ALT options
103 # but not MBEDTLS_ECP_NO_FALLBACK, so it appears in the report,
104 # but we don't care about it.
105 'Config: MBEDTLS_ECP_NO_FALLBACK',
Gilles Peskine47243fd2024-09-17 19:46:18 +0200106 # Missing coverage of test configurations.
107 # https://github.com/Mbed-TLS/mbedtls/issues/9585
108 'Config: !MBEDTLS_SSL_DTLS_ANTI_REPLAY',
109 # Missing coverage of test configurations.
110 # https://github.com/Mbed-TLS/mbedtls/issues/9585
111 'Config: !MBEDTLS_SSL_DTLS_HELLO_VERIFY',
112 # We don't run test_suite_config when we test this.
113 # https://github.com/Mbed-TLS/mbedtls/issues/9586
114 'Config: !MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED',
115 # We only test multithreading with pthreads.
116 # https://github.com/Mbed-TLS/mbedtls/issues/9584
117 'Config: !MBEDTLS_THREADING_PTHREAD',
118 # Built but not tested.
119 # https://github.com/Mbed-TLS/mbedtls/issues/9587
120 'Config: MBEDTLS_AES_USE_HARDWARE_ONLY',
121 # Untested platform-specific optimizations.
122 # https://github.com/Mbed-TLS/mbedtls/issues/9588
123 'Config: MBEDTLS_HAVE_SSE2',
124 # Obsolete configuration option, to be replaced by
125 # PSA entropy drivers.
126 # https://github.com/Mbed-TLS/mbedtls/issues/8150
127 'Config: MBEDTLS_NO_PLATFORM_ENTROPY',
128 # Untested aspect of the platform interface.
129 # https://github.com/Mbed-TLS/mbedtls/issues/9589
130 'Config: MBEDTLS_PLATFORM_NO_STD_FUNCTIONS',
131 # In a client-server build, test_suite_config runs in the
132 # client configuration, so it will never report
133 # MBEDTLS_PSA_CRYPTO_SPM as enabled. That's ok.
134 'Config: MBEDTLS_PSA_CRYPTO_SPM',
135 # We don't test on armv8 yet.
136 'Config: MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT',
137 'Config: MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY',
138 'Config: MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY',
139 'Config: MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY',
140 # We don't run test_suite_config when we test this.
141 # https://github.com/Mbed-TLS/mbedtls/issues/9586
142 'Config: MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND',
143 ],
144 'test_suite_config.psa_boolean': [
145 # We don't test with HMAC disabled.
146 # https://github.com/Mbed-TLS/mbedtls/issues/9591
147 'Config: !PSA_WANT_ALG_HMAC',
Gilles Peskine47243fd2024-09-17 19:46:18 +0200148 # The DERIVE key type is always enabled.
149 'Config: !PSA_WANT_KEY_TYPE_DERIVE',
150 # More granularity of key pair type enablement macros
151 # than we care to test.
152 # https://github.com/Mbed-TLS/mbedtls/issues/9590
153 'Config: !PSA_WANT_KEY_TYPE_DH_KEY_PAIR_EXPORT',
154 'Config: !PSA_WANT_KEY_TYPE_DH_KEY_PAIR_GENERATE',
155 'Config: !PSA_WANT_KEY_TYPE_DH_KEY_PAIR_IMPORT',
156 # More granularity of key pair type enablement macros
157 # than we care to test.
158 # https://github.com/Mbed-TLS/mbedtls/issues/9590
159 'Config: !PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT',
160 'Config: !PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT',
161 # We don't test with HMAC disabled.
162 # https://github.com/Mbed-TLS/mbedtls/issues/9591
163 'Config: !PSA_WANT_KEY_TYPE_HMAC',
164 # The PASSWORD key type is always enabled.
165 'Config: !PSA_WANT_KEY_TYPE_PASSWORD',
166 # The PASSWORD_HASH key type is always enabled.
167 'Config: !PSA_WANT_KEY_TYPE_PASSWORD_HASH',
168 # The RAW_DATA key type is always enabled.
169 'Config: !PSA_WANT_KEY_TYPE_RAW_DATA',
170 # More granularity of key pair type enablement macros
171 # than we care to test.
172 # https://github.com/Mbed-TLS/mbedtls/issues/9590
173 'Config: !PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT',
174 'Config: !PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT',
175 # Algorithm declared but not supported.
176 'Config: PSA_WANT_ALG_CBC_MAC',
177 # Algorithm declared but not supported.
178 'Config: PSA_WANT_ALG_XTS',
179 # Family declared but not supported.
180 'Config: PSA_WANT_ECC_SECP_K1_224',
181 # More granularity of key pair type enablement macros
182 # than we care to test.
183 # https://github.com/Mbed-TLS/mbedtls/issues/9590
184 'Config: PSA_WANT_KEY_TYPE_DH_KEY_PAIR_DERIVE',
185 'Config: PSA_WANT_KEY_TYPE_ECC_KEY_PAIR',
186 'Config: PSA_WANT_KEY_TYPE_RSA_KEY_PAIR',
187 'Config: PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_DERIVE',
188 ],
189 'test_suite_config.psa_combinations': [
190 # We don't test this unusual, but sensible configuration.
191 # https://github.com/Mbed-TLS/mbedtls/issues/9592
192 'Config: PSA_WANT_ALG_DETERMINSTIC_ECDSA without PSA_WANT_ALG_ECDSA',
193 ],
Gilles Peskine1a176272024-09-17 18:33:29 +0200194 'test_suite_pkcs12': [
Gilles Peskine47243fd2024-09-17 19:46:18 +0200195 # We never test with CBC/PKCS5/PKCS12 enabled but
196 # PKCS7 padding disabled.
Gilles Peskine1a176272024-09-17 18:33:29 +0200197 # https://github.com/Mbed-TLS/mbedtls/issues/9580
198 'PBE Decrypt, (Invalid padding & PKCS7 padding disabled)',
199 'PBE Encrypt, pad = 8 (PKCS7 padding disabled)',
200 ],
201 'test_suite_pkcs5': [
Gilles Peskine47243fd2024-09-17 19:46:18 +0200202 # We never test with CBC/PKCS5/PKCS12 enabled but
203 # PKCS7 padding disabled.
Gilles Peskine1a176272024-09-17 18:33:29 +0200204 # https://github.com/Mbed-TLS/mbedtls/issues/9580
205 'PBES2 Decrypt (Invalid padding & PKCS7 padding disabled)',
206 'PBES2 Encrypt, pad=6 (PKCS7 padding disabled)',
207 'PBES2 Encrypt, pad=8 (PKCS7 padding disabled)',
208 ],
Gilles Peskine8729b102024-04-19 19:08:34 +0200209 'test_suite_psa_crypto': [
210 # We don't test this unusual, but sensible configuration.
211 # https://github.com/Mbed-TLS/mbedtls/issues/9592
212 re.compile(r'.*ECDSA.*only deterministic supported'),
213 ],
Gilles Peskined8da2fc2024-09-17 15:07:22 +0200214 'test_suite_psa_crypto_generate_key.generated': [
Gilles Peskine72396da2024-09-17 17:15:29 +0200215 # Ignore mechanisms that are not implemented, except
216 # for public keys for which we always test that
217 # psa_generate_key() returns PSA_ERROR_INVALID_ARGUMENT
218 # regardless of whether the specific key type is supported.
219 _has_word_re((mech
220 for mech in _PSA_MECHANISMS_NOT_IMPLEMENTED
221 if not mech.startswith('ECC_PUB')),
222 exclude=r'ECC_PUB'),
Gilles Peskined8da2fc2024-09-17 15:07:22 +0200223 ],
Gilles Peskine1a176272024-09-17 18:33:29 +0200224 'test_suite_psa_crypto_metadata': [
225 # Algorithms declared but not supported.
226 # https://github.com/Mbed-TLS/mbedtls/issues/9579
227 'Asymmetric signature: Ed25519ph',
228 'Asymmetric signature: Ed448ph',
229 'Asymmetric signature: pure EdDSA',
230 'Cipher: XTS',
231 'MAC: CBC_MAC-3DES',
232 'MAC: CBC_MAC-AES-128',
233 'MAC: CBC_MAC-AES-192',
234 'MAC: CBC_MAC-AES-256',
235 ],
Gilles Peskined8da2fc2024-09-17 15:07:22 +0200236 'test_suite_psa_crypto_not_supported.generated': [
Gilles Peskine1fac3712024-09-17 17:57:11 +0200237 # It is a bug that not-supported test cases aren't getting
238 # run for never-implemented key types.
239 # https://github.com/Mbed-TLS/mbedtls/issues/7915
Gilles Peskined8da2fc2024-09-17 15:07:22 +0200240 PSA_MECHANISM_NOT_IMPLEMENTED_SEARCH_RE,
Gilles Peskine1abc8002024-10-11 12:00:44 +0200241 # We never test with DH key support disabled but support
Gilles Peskine1fac3712024-09-17 17:57:11 +0200242 # for a DH group enabled. The dependencies of these test
243 # cases don't really make sense.
244 # https://github.com/Mbed-TLS/mbedtls/issues/9574
245 re.compile(r'PSA \w+ DH_.*type not supported'),
246 # We only test partial support for DH with the 2048-bit group
247 # enabled and the other groups disabled.
248 # https://github.com/Mbed-TLS/mbedtls/issues/9575
249 'PSA generate DH_KEY_PAIR(RFC7919) 2048-bit group not supported',
250 'PSA import DH_KEY_PAIR(RFC7919) 2048-bit group not supported',
251 'PSA import DH_PUBLIC_KEY(RFC7919) 2048-bit group not supported',
Gilles Peskined8da2fc2024-09-17 15:07:22 +0200252 ],
253 'test_suite_psa_crypto_op_fail.generated': [
Gilles Peskine72396da2024-09-17 17:15:29 +0200254 # Ignore mechanisms that are not implemented, except
255 # for test cases that assume the mechanism is not supported.
256 _has_word_re(_PSA_MECHANISMS_NOT_IMPLEMENTED,
257 exclude=(r'.*: !(?:' +
258 r'|'.join(_PSA_MECHANISMS_NOT_IMPLEMENTED) +
259 r')\b')),
Gilles Peskine1fac3712024-09-17 17:57:11 +0200260 # Incorrect dependency generation. To be fixed as part of the
261 # resolution of https://github.com/Mbed-TLS/mbedtls/issues/9167
262 # by forward-porting the commit
263 # "PSA test case generation: dependency inference class: operation fail"
264 # from https://github.com/Mbed-TLS/mbedtls/pull/9025 .
265 re.compile(r'.* with (?:DH|ECC)_(?:KEY_PAIR|PUBLIC_KEY)\(.*'),
Gilles Peskine8729b102024-04-19 19:08:34 +0200266 # We don't test this unusual, but sensible configuration.
267 # https://github.com/Mbed-TLS/mbedtls/issues/9592
268 re.compile(r'.*: !ECDSA but DETERMINISTIC_ECDSA with ECC_.*'),
Gilles Peskine1fac3712024-09-17 17:57:11 +0200269 # PBKDF2_HMAC is not in the default configuration, so we don't
270 # enable it in depends.py where we remove hashes.
271 # https://github.com/Mbed-TLS/mbedtls/issues/9576
272 re.compile(r'PSA key_derivation PBKDF2_HMAC\(\w+\): !(?!PBKDF2_HMAC\Z).*'),
Gilles Peskine1fac3712024-09-17 17:57:11 +0200273
274 # We never test with the HMAC algorithm enabled but the HMAC
275 # key type disabled. Those dependencies don't really make sense.
276 # https://github.com/Mbed-TLS/mbedtls/issues/9573
277 re.compile(r'.* !HMAC with HMAC'),
278 # There's something wrong with PSA_WANT_ALG_RSA_PSS_ANY_SALT
279 # differing from PSA_WANT_ALG_RSA_PSS.
280 # https://github.com/Mbed-TLS/mbedtls/issues/9578
281 re.compile(r'PSA sign RSA_PSS_ANY_SALT.*!(?:MD|RIPEMD|SHA).*'),
Gilles Peskined8da2fc2024-09-17 15:07:22 +0200282 ],
Gilles Peskine8729b102024-04-19 19:08:34 +0200283 'test_suite_psa_crypto_op_fail.misc': [
284 # We don't test this unusual, but sensible configuration.
285 # https://github.com/Mbed-TLS/mbedtls/issues/9592
286 'PSA sign DETERMINISTIC_ECDSA(SHA_256): !ECDSA but DETERMINISTIC_ECDSA with ECC_KEY_PAIR(SECP_R1)', #pylint: disable=line-too-long
287 ],
Gilles Peskined8da2fc2024-09-17 15:07:22 +0200288 'test_suite_psa_crypto_storage_format.current': [
289 PSA_MECHANISM_NOT_IMPLEMENTED_SEARCH_RE,
290 ],
291 'test_suite_psa_crypto_storage_format.v0': [
292 PSA_MECHANISM_NOT_IMPLEMENTED_SEARCH_RE,
293 ],
Gilles Peskine419a5842024-09-17 18:32:05 +0200294 'tls13-misc': [
295 # Disabled due to OpenSSL bug.
296 # https://github.com/openssl/openssl/issues/10714
297 'TLS 1.3 O->m: resumption',
298 # Disabled due to OpenSSL command line limitation.
299 # https://github.com/Mbed-TLS/mbedtls/issues/9582
300 'TLS 1.3 m->O: resumption with early data',
301 ],
Gilles Peskined8da2fc2024-09-17 15:07:22 +0200302 }
303
Gilles Peskine17e071b2024-09-16 19:57:10 +0200304
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200305# The names that we give to classes derived from DriverVSReference do not
306# follow the usual naming convention, because it's more readable to use
307# underscores and parts of the configuration names. Also, these classes
308# are just there to specify some data, so they don't need repetitive
309# documentation.
310#pylint: disable=invalid-name,missing-class-docstring
311
Gilles Peskine45a32b12024-10-03 18:42:37 +0200312class DriverVSReference_hash(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200313 REFERENCE = 'test_psa_crypto_config_reference_hash_use_psa'
314 DRIVER = 'test_psa_crypto_config_accel_hash_use_psa'
315 IGNORED_SUITES = [
316 'shax', 'mdx', # the software implementations that are being excluded
317 'md.psa', # purposefully depends on whether drivers are present
318 'psa_crypto_low_hash.generated', # testing the builtins
319 ]
320 IGNORED_TESTS = {
321 'test_suite_config': [
322 re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
323 ],
324 'test_suite_platform': [
325 # Incompatible with sanitizers (e.g. ASan). If the driver
326 # component uses a sanitizer but the reference component
327 # doesn't, we have a PASS vs SKIP mismatch.
328 'Check mbedtls_calloc overallocation',
329 ],
330 }
331
Gilles Peskine45a32b12024-10-03 18:42:37 +0200332class DriverVSReference_hmac(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200333 REFERENCE = 'test_psa_crypto_config_reference_hmac'
334 DRIVER = 'test_psa_crypto_config_accel_hmac'
335 IGNORED_SUITES = [
336 # These suites require legacy hash support, which is disabled
337 # in the accelerated component.
338 'shax', 'mdx',
339 # This suite tests builtins directly, but these are missing
340 # in the accelerated case.
341 'psa_crypto_low_hash.generated',
342 ]
343 IGNORED_TESTS = {
344 'test_suite_config': [
345 re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
346 re.compile(r'.*\bMBEDTLS_MD_C\b')
347 ],
348 'test_suite_md': [
349 # Builtin HMAC is not supported in the accelerate component.
350 re.compile('.*HMAC.*'),
351 # Following tests make use of functions which are not available
352 # when MD_C is disabled, as it happens in the accelerated
353 # test component.
354 re.compile('generic .* Hash file .*'),
355 'MD list',
356 ],
357 'test_suite_md.psa': [
358 # "legacy only" tests require hash algorithms to be NOT
359 # accelerated, but this of course false for the accelerated
360 # test component.
361 re.compile('PSA dispatch .* legacy only'),
362 ],
363 'test_suite_platform': [
364 # Incompatible with sanitizers (e.g. ASan). If the driver
365 # component uses a sanitizer but the reference component
366 # doesn't, we have a PASS vs SKIP mismatch.
367 'Check mbedtls_calloc overallocation',
368 ],
369 }
370
Gilles Peskine45a32b12024-10-03 18:42:37 +0200371class DriverVSReference_cipher_aead_cmac(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200372 REFERENCE = 'test_psa_crypto_config_reference_cipher_aead_cmac'
373 DRIVER = 'test_psa_crypto_config_accel_cipher_aead_cmac'
374 # Modules replaced by drivers.
375 IGNORED_SUITES = [
376 # low-level (block/stream) cipher modules
377 'aes', 'aria', 'camellia', 'des', 'chacha20',
378 # AEAD modes and CMAC
379 'ccm', 'chachapoly', 'cmac', 'gcm',
380 # The Cipher abstraction layer
381 'cipher',
382 ]
383 IGNORED_TESTS = {
384 'test_suite_config': [
385 re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA|CHACHA20|DES)_.*'),
386 re.compile(r'.*\bMBEDTLS_(CCM|CHACHAPOLY|CMAC|GCM)_.*'),
387 re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'),
388 re.compile(r'.*\bMBEDTLS_CIPHER_.*'),
389 ],
390 # PEM decryption is not supported so far.
391 # The rest of PEM (write, unencrypted read) works though.
392 'test_suite_pem': [
393 re.compile(r'PEM read .*(AES|DES|\bencrypt).*'),
394 ],
395 'test_suite_platform': [
396 # Incompatible with sanitizers (e.g. ASan). If the driver
397 # component uses a sanitizer but the reference component
398 # doesn't, we have a PASS vs SKIP mismatch.
399 'Check mbedtls_calloc overallocation',
400 ],
401 # Following tests depend on AES_C/DES_C but are not about
402 # them really, just need to know some error code is there.
403 'test_suite_error': [
404 'Low and high error',
405 'Single low error'
406 ],
407 # Similar to test_suite_error above.
408 'test_suite_version': [
409 'Check for MBEDTLS_AES_C when already present',
410 ],
411 # The en/decryption part of PKCS#12 is not supported so far.
412 # The rest of PKCS#12 (key derivation) works though.
413 'test_suite_pkcs12': [
414 re.compile(r'PBE Encrypt, .*'),
415 re.compile(r'PBE Decrypt, .*'),
416 ],
417 # The en/decryption part of PKCS#5 is not supported so far.
418 # The rest of PKCS#5 (PBKDF2) works though.
419 'test_suite_pkcs5': [
420 re.compile(r'PBES2 Encrypt, .*'),
421 re.compile(r'PBES2 Decrypt .*'),
422 ],
423 # Encrypted keys are not supported so far.
424 # pylint: disable=line-too-long
425 'test_suite_pkparse': [
426 'Key ASN1 (Encrypted key PKCS12, trailing garbage data)',
427 'Key ASN1 (Encrypted key PKCS5, trailing garbage data)',
428 re.compile(r'Parse (RSA|EC) Key .*\(.* ([Ee]ncrypted|password).*\)'),
429 ],
430 # Encrypted keys are not supported so far.
431 'ssl-opt': [
432 'TLS: password protected server key',
433 'TLS: password protected client key',
434 'TLS: password protected server key, two certificates',
435 ],
436 }
437
Gilles Peskine45a32b12024-10-03 18:42:37 +0200438class DriverVSReference_ecp_light_only(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200439 REFERENCE = 'test_psa_crypto_config_reference_ecc_ecp_light_only'
440 DRIVER = 'test_psa_crypto_config_accel_ecc_ecp_light_only'
441 IGNORED_SUITES = [
442 # Modules replaced by drivers
443 'ecdsa', 'ecdh', 'ecjpake',
Gilles Peskine9a094432024-10-29 20:55:11 +0100444 # Unit tests for the built-in implementation
445 'psa_crypto_ecp',
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200446 ]
447 IGNORED_TESTS = {
448 'test_suite_config': [
449 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
450 ],
451 'test_suite_platform': [
452 # Incompatible with sanitizers (e.g. ASan). If the driver
453 # component uses a sanitizer but the reference component
454 # doesn't, we have a PASS vs SKIP mismatch.
455 'Check mbedtls_calloc overallocation',
456 ],
457 # This test wants a legacy function that takes f_rng, p_rng
458 # arguments, and uses legacy ECDSA for that. The test is
459 # really about the wrapper around the PSA RNG, not ECDSA.
460 'test_suite_random': [
461 'PSA classic wrapper: ECDSA signature (SECP256R1)',
462 ],
463 # In the accelerated test ECP_C is not set (only ECP_LIGHT is)
464 # so we must ignore disparities in the tests for which ECP_C
465 # is required.
466 'test_suite_ecp': [
467 re.compile(r'ECP check public-private .*'),
468 re.compile(r'ECP calculate public: .*'),
469 re.compile(r'ECP gen keypair .*'),
470 re.compile(r'ECP point muladd .*'),
471 re.compile(r'ECP point multiplication .*'),
472 re.compile(r'ECP test vectors .*'),
473 ],
474 'test_suite_ssl': [
475 # This deprecated function is only present when ECP_C is On.
476 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
477 ],
478 }
479
Gilles Peskine45a32b12024-10-03 18:42:37 +0200480class DriverVSReference_no_ecp_at_all(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200481 REFERENCE = 'test_psa_crypto_config_reference_ecc_no_ecp_at_all'
482 DRIVER = 'test_psa_crypto_config_accel_ecc_no_ecp_at_all'
483 IGNORED_SUITES = [
484 # Modules replaced by drivers
485 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
Gilles Peskine9a094432024-10-29 20:55:11 +0100486 # Unit tests for the built-in implementation
487 'psa_crypto_ecp',
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200488 ]
489 IGNORED_TESTS = {
490 'test_suite_config': [
491 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
492 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
493 ],
494 'test_suite_platform': [
495 # Incompatible with sanitizers (e.g. ASan). If the driver
496 # component uses a sanitizer but the reference component
497 # doesn't, we have a PASS vs SKIP mismatch.
498 'Check mbedtls_calloc overallocation',
499 ],
500 # See ecp_light_only
501 'test_suite_random': [
502 'PSA classic wrapper: ECDSA signature (SECP256R1)',
503 ],
504 'test_suite_pkparse': [
505 # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED
506 # is automatically enabled in build_info.h (backward compatibility)
507 # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a
508 # consequence compressed points are supported in the reference
509 # component but not in the accelerated one, so they should be skipped
510 # while checking driver's coverage.
511 re.compile(r'Parse EC Key .*compressed\)'),
512 re.compile(r'Parse Public EC Key .*compressed\)'),
513 ],
514 # See ecp_light_only
515 'test_suite_ssl': [
516 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
517 ],
518 }
519
Gilles Peskine45a32b12024-10-03 18:42:37 +0200520class DriverVSReference_ecc_no_bignum(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200521 REFERENCE = 'test_psa_crypto_config_reference_ecc_no_bignum'
522 DRIVER = 'test_psa_crypto_config_accel_ecc_no_bignum'
523 IGNORED_SUITES = [
524 # Modules replaced by drivers
525 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
526 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
527 'bignum.generated', 'bignum.misc',
Gilles Peskine9a094432024-10-29 20:55:11 +0100528 # Unit tests for the built-in implementation
529 'psa_crypto_ecp',
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200530 ]
531 IGNORED_TESTS = {
532 'test_suite_config': [
533 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
534 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
535 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
536 ],
537 'test_suite_platform': [
538 # Incompatible with sanitizers (e.g. ASan). If the driver
539 # component uses a sanitizer but the reference component
540 # doesn't, we have a PASS vs SKIP mismatch.
541 'Check mbedtls_calloc overallocation',
542 ],
543 # See ecp_light_only
544 'test_suite_random': [
545 'PSA classic wrapper: ECDSA signature (SECP256R1)',
546 ],
547 # See no_ecp_at_all
548 'test_suite_pkparse': [
549 re.compile(r'Parse EC Key .*compressed\)'),
550 re.compile(r'Parse Public EC Key .*compressed\)'),
551 ],
552 'test_suite_asn1parse': [
553 'INTEGER too large for mpi',
554 ],
555 'test_suite_asn1write': [
556 re.compile(r'ASN.1 Write mpi.*'),
557 ],
558 'test_suite_debug': [
559 re.compile(r'Debug print mbedtls_mpi.*'),
560 ],
561 # See ecp_light_only
562 'test_suite_ssl': [
563 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
564 ],
565 }
566
Gilles Peskine45a32b12024-10-03 18:42:37 +0200567class DriverVSReference_ecc_ffdh_no_bignum(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200568 REFERENCE = 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum'
569 DRIVER = 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum'
570 IGNORED_SUITES = [
571 # Modules replaced by drivers
572 'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'dhm',
573 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
574 'bignum.generated', 'bignum.misc',
Gilles Peskine9a094432024-10-29 20:55:11 +0100575 # Unit tests for the built-in implementation
576 'psa_crypto_ecp',
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200577 ]
578 IGNORED_TESTS = {
579 'ssl-opt': [
580 # DHE support in TLS 1.2 requires built-in MBEDTLS_DHM_C
581 # (because it needs custom groups, which PSA does not
582 # provide), even with MBEDTLS_USE_PSA_CRYPTO.
583 re.compile(r'PSK callback:.*\bdhe-psk\b.*'),
584 ],
585 'test_suite_config': [
586 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
587 re.compile(r'.*\bMBEDTLS_DHM_C\b.*'),
588 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
589 re.compile(r'.*\bMBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED\b.*'),
590 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
591 ],
592 'test_suite_platform': [
593 # Incompatible with sanitizers (e.g. ASan). If the driver
594 # component uses a sanitizer but the reference component
595 # doesn't, we have a PASS vs SKIP mismatch.
596 'Check mbedtls_calloc overallocation',
597 ],
598 # See ecp_light_only
599 'test_suite_random': [
600 'PSA classic wrapper: ECDSA signature (SECP256R1)',
601 ],
602 # See no_ecp_at_all
603 'test_suite_pkparse': [
604 re.compile(r'Parse EC Key .*compressed\)'),
605 re.compile(r'Parse Public EC Key .*compressed\)'),
606 ],
607 'test_suite_asn1parse': [
608 'INTEGER too large for mpi',
609 ],
610 'test_suite_asn1write': [
611 re.compile(r'ASN.1 Write mpi.*'),
612 ],
613 'test_suite_debug': [
614 re.compile(r'Debug print mbedtls_mpi.*'),
615 ],
616 # See ecp_light_only
617 'test_suite_ssl': [
618 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
619 ],
620 }
621
Gilles Peskine45a32b12024-10-03 18:42:37 +0200622class DriverVSReference_ffdh_alg(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200623 REFERENCE = 'test_psa_crypto_config_reference_ffdh'
624 DRIVER = 'test_psa_crypto_config_accel_ffdh'
625 IGNORED_SUITES = ['dhm']
626 IGNORED_TESTS = {
627 'test_suite_config': [
628 re.compile(r'.*\bMBEDTLS_DHM_C\b.*'),
629 ],
630 'test_suite_platform': [
631 # Incompatible with sanitizers (e.g. ASan). If the driver
632 # component uses a sanitizer but the reference component
633 # doesn't, we have a PASS vs SKIP mismatch.
634 'Check mbedtls_calloc overallocation',
635 ],
636 }
637
Gilles Peskine45a32b12024-10-03 18:42:37 +0200638class DriverVSReference_tfm_config(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200639 REFERENCE = 'test_tfm_config_no_p256m'
640 DRIVER = 'test_tfm_config_p256m_driver_accel_ec'
641 IGNORED_SUITES = [
642 # Modules replaced by drivers
643 'asn1parse', 'asn1write',
644 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
645 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
646 'bignum.generated', 'bignum.misc',
Gilles Peskine9a094432024-10-29 20:55:11 +0100647 # Unit tests for the built-in implementation
648 'psa_crypto_ecp',
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200649 ]
650 IGNORED_TESTS = {
651 'test_suite_config': [
652 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
653 re.compile(r'.*\bMBEDTLS_(ASN1\w+)_C\b.*'),
654 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECP)_.*'),
655 re.compile(r'.*\bMBEDTLS_PSA_P256M_DRIVER_ENABLED\b.*')
656 ],
657 'test_suite_config.crypto_combinations': [
658 'Config: ECC: Weierstrass curves only',
659 ],
660 'test_suite_platform': [
661 # Incompatible with sanitizers (e.g. ASan). If the driver
662 # component uses a sanitizer but the reference component
663 # doesn't, we have a PASS vs SKIP mismatch.
664 'Check mbedtls_calloc overallocation',
665 ],
666 # See ecp_light_only
667 'test_suite_random': [
668 'PSA classic wrapper: ECDSA signature (SECP256R1)',
669 ],
670 }
671
Gilles Peskine45a32b12024-10-03 18:42:37 +0200672class DriverVSReference_rsa(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200673 REFERENCE = 'test_psa_crypto_config_reference_rsa_crypto'
674 DRIVER = 'test_psa_crypto_config_accel_rsa_crypto'
675 IGNORED_SUITES = [
676 # Modules replaced by drivers.
677 'rsa', 'pkcs1_v15', 'pkcs1_v21',
678 # We temporarily don't care about PK stuff.
679 'pk', 'pkwrite', 'pkparse'
680 ]
681 IGNORED_TESTS = {
682 'test_suite_config': [
683 re.compile(r'.*\bMBEDTLS_(PKCS1|RSA)_.*'),
684 re.compile(r'.*\bMBEDTLS_GENPRIME\b.*')
685 ],
686 'test_suite_platform': [
687 # Incompatible with sanitizers (e.g. ASan). If the driver
688 # component uses a sanitizer but the reference component
689 # doesn't, we have a PASS vs SKIP mismatch.
690 'Check mbedtls_calloc overallocation',
691 ],
692 # Following tests depend on RSA_C but are not about
693 # them really, just need to know some error code is there.
694 'test_suite_error': [
695 'Low and high error',
696 'Single high error'
697 ],
698 # Constant time operations only used for PKCS1_V15
699 'test_suite_constant_time': [
700 re.compile(r'mbedtls_ct_zeroize_if .*'),
701 re.compile(r'mbedtls_ct_memmove_left .*')
702 ],
703 'test_suite_psa_crypto': [
704 # We don't support generate_key_custom entry points
705 # in drivers yet.
706 re.compile(r'PSA generate key custom: RSA, e=.*'),
707 re.compile(r'PSA generate key ext: RSA, e=.*'),
708 ],
709 }
710
Gilles Peskine45a32b12024-10-03 18:42:37 +0200711class DriverVSReference_block_cipher_dispatch(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200712 REFERENCE = 'test_full_block_cipher_legacy_dispatch'
713 DRIVER = 'test_full_block_cipher_psa_dispatch'
714 IGNORED_SUITES = [
715 # Skipped in the accelerated component
716 'aes', 'aria', 'camellia',
717 # These require AES_C, ARIA_C or CAMELLIA_C to be enabled in
718 # order for the cipher module (actually cipher_wrapper) to work
719 # properly. However these symbols are disabled in the accelerated
720 # component so we ignore them.
721 'cipher.ccm', 'cipher.gcm', 'cipher.aes', 'cipher.aria',
722 'cipher.camellia',
723 ]
724 IGNORED_TESTS = {
725 'test_suite_config': [
726 re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA)_.*'),
727 re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'),
728 ],
729 'test_suite_cmac': [
730 # Following tests require AES_C/ARIA_C/CAMELLIA_C to be enabled,
731 # but these are not available in the accelerated component.
732 'CMAC null arguments',
733 re.compile('CMAC.* (AES|ARIA|Camellia).*'),
734 ],
735 'test_suite_cipher.padding': [
736 # Following tests require AES_C/CAMELLIA_C to be enabled,
737 # but these are not available in the accelerated component.
738 re.compile('Set( non-existent)? padding with (AES|CAMELLIA).*'),
739 ],
740 'test_suite_pkcs5': [
741 # The AES part of PKCS#5 PBES2 is not yet supported.
742 # The rest of PKCS#5 (PBKDF2) works, though.
743 re.compile(r'PBES2 .* AES-.*')
744 ],
745 'test_suite_pkparse': [
746 # PEM (called by pkparse) requires AES_C in order to decrypt
747 # the key, but this is not available in the accelerated
748 # component.
749 re.compile('Parse RSA Key.*(password|AES-).*'),
750 ],
751 'test_suite_pem': [
752 # Following tests require AES_C, but this is diabled in the
753 # accelerated component.
754 re.compile('PEM read .*AES.*'),
755 'PEM read (unknown encryption algorithm)',
756 ],
757 'test_suite_error': [
758 # Following tests depend on AES_C but are not about them
759 # really, just need to know some error code is there.
760 'Single low error',
761 'Low and high error',
762 ],
763 'test_suite_version': [
764 # Similar to test_suite_error above.
765 'Check for MBEDTLS_AES_C when already present',
766 ],
767 'test_suite_platform': [
768 # Incompatible with sanitizers (e.g. ASan). If the driver
769 # component uses a sanitizer but the reference component
770 # doesn't, we have a PASS vs SKIP mismatch.
771 'Check mbedtls_calloc overallocation',
772 ],
773 }
774
775#pylint: enable=invalid-name,missing-class-docstring
776
777
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100778# List of tasks with a function that can handle this task and additional arguments if required
Valerio Settidfd7ca62023-10-09 16:30:11 +0200779KNOWN_TASKS = {
Gilles Peskine0316f102024-09-16 19:15:29 +0200780 'analyze_coverage': CoverageTask,
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200781 'analyze_driver_vs_reference_hash': DriverVSReference_hash,
782 'analyze_driver_vs_reference_hmac': DriverVSReference_hmac,
783 'analyze_driver_vs_reference_cipher_aead_cmac': DriverVSReference_cipher_aead_cmac,
784 'analyze_driver_vs_reference_ecp_light_only': DriverVSReference_ecp_light_only,
785 'analyze_driver_vs_reference_no_ecp_at_all': DriverVSReference_no_ecp_at_all,
786 'analyze_driver_vs_reference_ecc_no_bignum': DriverVSReference_ecc_no_bignum,
787 'analyze_driver_vs_reference_ecc_ffdh_no_bignum': DriverVSReference_ecc_ffdh_no_bignum,
788 'analyze_driver_vs_reference_ffdh_alg': DriverVSReference_ffdh_alg,
789 'analyze_driver_vs_reference_tfm_config': DriverVSReference_tfm_config,
790 'analyze_driver_vs_reference_rsa': DriverVSReference_rsa,
791 'analyze_block_cipher_dispatch': DriverVSReference_block_cipher_dispatch,
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200792}
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200793
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200794if __name__ == '__main__':
Gilles Peskine45a32b12024-10-03 18:42:37 +0200795 outcome_analysis.main(KNOWN_TASKS)