blob: 42f51e6906f2bec09d776369bf561e890aa03ebb [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.*',
34 re.S)
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',
76
77 # We don't have IPv6 in our CI environment.
78 # https://github.com/Mbed-TLS/mbedtls-test/issues/176
79 'DTLS cookie: enabled, IPv6',
80 # Disabled due to OpenSSL bug.
81 # https://github.com/openssl/openssl/issues/18887
82 'DTLS fragmenting: 3d, openssl client, DTLS 1.2',
83 # We don't run ssl-opt.sh with Valgrind on the CI because
84 # it's extremely slow. We don't intend to change this.
85 'DTLS fragmenting: proxy MTU: auto-reduction (with valgrind)',
86 # It seems that we don't run `ssl-opt.sh` with
87 # `MBEDTLS_USE_PSA_CRYPTO` enabled but `MBEDTLS_SSL_ASYNC_PRIVATE`
88 # disabled.
89 # https://github.com/Mbed-TLS/mbedtls/issues/9581
90 'Opaque key for server authentication: invalid key: decrypt with ECC key, no async',
91 'Opaque key for server authentication: invalid key: ecdh with RSA key, no async',
92 ],
Gilles Peskine47243fd2024-09-17 19:46:18 +020093 'test_suite_config.mbedtls_boolean': [
94 # We never test with CBC/PKCS5/PKCS12 enabled but
95 # PKCS7 padding disabled.
96 # https://github.com/Mbed-TLS/mbedtls/issues/9580
97 'Config: !MBEDTLS_CIPHER_PADDING_PKCS7',
98 # https://github.com/Mbed-TLS/mbedtls/issues/9583
99 'Config: !MBEDTLS_ECP_NIST_OPTIM',
Gilles Peskine44fdd922024-10-10 18:19:23 +0200100 # MBEDTLS_ECP_NO_FALLBACK only affects builds using a partial
101 # alternative implementation of ECP arithmetic (with
102 # MBEDTLS_ECP_INTERNAL_ALT enabled). We don't test those builds.
103 # The configuration enumeration script skips xxx_ALT options
104 # but not MBEDTLS_ECP_NO_FALLBACK, so it appears in the report,
105 # but we don't care about it.
106 'Config: MBEDTLS_ECP_NO_FALLBACK',
Gilles Peskine47243fd2024-09-17 19:46:18 +0200107 # Missing coverage of test configurations.
108 # https://github.com/Mbed-TLS/mbedtls/issues/9585
109 'Config: !MBEDTLS_SSL_DTLS_ANTI_REPLAY',
110 # Missing coverage of test configurations.
111 # https://github.com/Mbed-TLS/mbedtls/issues/9585
112 'Config: !MBEDTLS_SSL_DTLS_HELLO_VERIFY',
113 # We don't run test_suite_config when we test this.
114 # https://github.com/Mbed-TLS/mbedtls/issues/9586
115 'Config: !MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED',
116 # We only test multithreading with pthreads.
117 # https://github.com/Mbed-TLS/mbedtls/issues/9584
118 'Config: !MBEDTLS_THREADING_PTHREAD',
119 # Built but not tested.
120 # https://github.com/Mbed-TLS/mbedtls/issues/9587
121 'Config: MBEDTLS_AES_USE_HARDWARE_ONLY',
122 # Untested platform-specific optimizations.
123 # https://github.com/Mbed-TLS/mbedtls/issues/9588
124 'Config: MBEDTLS_HAVE_SSE2',
125 # Obsolete configuration option, to be replaced by
126 # PSA entropy drivers.
127 # https://github.com/Mbed-TLS/mbedtls/issues/8150
128 'Config: MBEDTLS_NO_PLATFORM_ENTROPY',
129 # Untested aspect of the platform interface.
130 # https://github.com/Mbed-TLS/mbedtls/issues/9589
131 'Config: MBEDTLS_PLATFORM_NO_STD_FUNCTIONS',
132 # In a client-server build, test_suite_config runs in the
133 # client configuration, so it will never report
134 # MBEDTLS_PSA_CRYPTO_SPM as enabled. That's ok.
135 'Config: MBEDTLS_PSA_CRYPTO_SPM',
136 # We don't test on armv8 yet.
137 'Config: MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT',
138 'Config: MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY',
139 'Config: MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY',
140 'Config: MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY',
141 # We don't run test_suite_config when we test this.
142 # https://github.com/Mbed-TLS/mbedtls/issues/9586
143 'Config: MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND',
144 ],
145 'test_suite_config.psa_boolean': [
146 # We don't test with HMAC disabled.
147 # https://github.com/Mbed-TLS/mbedtls/issues/9591
148 'Config: !PSA_WANT_ALG_HMAC',
149 # We don't test with HMAC disabled.
150 # https://github.com/Mbed-TLS/mbedtls/issues/9591
151 'Config: !PSA_WANT_ALG_TLS12_PRF',
152 # The DERIVE key type is always enabled.
153 'Config: !PSA_WANT_KEY_TYPE_DERIVE',
154 # More granularity of key pair type enablement macros
155 # than we care to test.
156 # https://github.com/Mbed-TLS/mbedtls/issues/9590
157 'Config: !PSA_WANT_KEY_TYPE_DH_KEY_PAIR_EXPORT',
158 'Config: !PSA_WANT_KEY_TYPE_DH_KEY_PAIR_GENERATE',
159 'Config: !PSA_WANT_KEY_TYPE_DH_KEY_PAIR_IMPORT',
160 # More granularity of key pair type enablement macros
161 # than we care to test.
162 # https://github.com/Mbed-TLS/mbedtls/issues/9590
163 'Config: !PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT',
164 'Config: !PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT',
165 # We don't test with HMAC disabled.
166 # https://github.com/Mbed-TLS/mbedtls/issues/9591
167 'Config: !PSA_WANT_KEY_TYPE_HMAC',
168 # The PASSWORD key type is always enabled.
169 'Config: !PSA_WANT_KEY_TYPE_PASSWORD',
170 # The PASSWORD_HASH key type is always enabled.
171 'Config: !PSA_WANT_KEY_TYPE_PASSWORD_HASH',
172 # The RAW_DATA key type is always enabled.
173 'Config: !PSA_WANT_KEY_TYPE_RAW_DATA',
174 # More granularity of key pair type enablement macros
175 # than we care to test.
176 # https://github.com/Mbed-TLS/mbedtls/issues/9590
177 'Config: !PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT',
178 'Config: !PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT',
179 # Algorithm declared but not supported.
180 'Config: PSA_WANT_ALG_CBC_MAC',
181 # Algorithm declared but not supported.
182 'Config: PSA_WANT_ALG_XTS',
183 # Family declared but not supported.
184 'Config: PSA_WANT_ECC_SECP_K1_224',
185 # More granularity of key pair type enablement macros
186 # than we care to test.
187 # https://github.com/Mbed-TLS/mbedtls/issues/9590
188 'Config: PSA_WANT_KEY_TYPE_DH_KEY_PAIR_DERIVE',
189 'Config: PSA_WANT_KEY_TYPE_ECC_KEY_PAIR',
190 'Config: PSA_WANT_KEY_TYPE_RSA_KEY_PAIR',
191 'Config: PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_DERIVE',
192 ],
193 'test_suite_config.psa_combinations': [
194 # We don't test this unusual, but sensible configuration.
195 # https://github.com/Mbed-TLS/mbedtls/issues/9592
196 'Config: PSA_WANT_ALG_DETERMINSTIC_ECDSA without PSA_WANT_ALG_ECDSA',
197 ],
Gilles Peskine1a176272024-09-17 18:33:29 +0200198 'test_suite_pkcs12': [
Gilles Peskine47243fd2024-09-17 19:46:18 +0200199 # We never test with CBC/PKCS5/PKCS12 enabled but
200 # PKCS7 padding disabled.
Gilles Peskine1a176272024-09-17 18:33:29 +0200201 # https://github.com/Mbed-TLS/mbedtls/issues/9580
202 'PBE Decrypt, (Invalid padding & PKCS7 padding disabled)',
203 'PBE Encrypt, pad = 8 (PKCS7 padding disabled)',
204 ],
205 'test_suite_pkcs5': [
Gilles Peskine47243fd2024-09-17 19:46:18 +0200206 # We never test with CBC/PKCS5/PKCS12 enabled but
207 # PKCS7 padding disabled.
Gilles Peskine1a176272024-09-17 18:33:29 +0200208 # https://github.com/Mbed-TLS/mbedtls/issues/9580
209 'PBES2 Decrypt (Invalid padding & PKCS7 padding disabled)',
210 'PBES2 Encrypt, pad=6 (PKCS7 padding disabled)',
211 'PBES2 Encrypt, pad=8 (PKCS7 padding disabled)',
212 ],
Gilles Peskined8da2fc2024-09-17 15:07:22 +0200213 'test_suite_psa_crypto_generate_key.generated': [
Gilles Peskine72396da2024-09-17 17:15:29 +0200214 # Ignore mechanisms that are not implemented, except
215 # for public keys for which we always test that
216 # psa_generate_key() returns PSA_ERROR_INVALID_ARGUMENT
217 # regardless of whether the specific key type is supported.
218 _has_word_re((mech
219 for mech in _PSA_MECHANISMS_NOT_IMPLEMENTED
220 if not mech.startswith('ECC_PUB')),
221 exclude=r'ECC_PUB'),
Gilles Peskined8da2fc2024-09-17 15:07:22 +0200222 ],
Gilles Peskine1a176272024-09-17 18:33:29 +0200223 'test_suite_psa_crypto_metadata': [
224 # Algorithms declared but not supported.
225 # https://github.com/Mbed-TLS/mbedtls/issues/9579
226 'Asymmetric signature: Ed25519ph',
227 'Asymmetric signature: Ed448ph',
228 'Asymmetric signature: pure EdDSA',
229 'Cipher: XTS',
230 'MAC: CBC_MAC-3DES',
231 'MAC: CBC_MAC-AES-128',
232 'MAC: CBC_MAC-AES-192',
233 'MAC: CBC_MAC-AES-256',
234 ],
Gilles Peskined8da2fc2024-09-17 15:07:22 +0200235 'test_suite_psa_crypto_not_supported.generated': [
Gilles Peskine1fac3712024-09-17 17:57:11 +0200236 # It is a bug that not-supported test cases aren't getting
237 # run for never-implemented key types.
238 # https://github.com/Mbed-TLS/mbedtls/issues/7915
Gilles Peskined8da2fc2024-09-17 15:07:22 +0200239 PSA_MECHANISM_NOT_IMPLEMENTED_SEARCH_RE,
Gilles Peskine1fac3712024-09-17 17:57:11 +0200240 # We mever test with DH key support disabled but support
241 # for a DH group enabled. The dependencies of these test
242 # cases don't really make sense.
243 # https://github.com/Mbed-TLS/mbedtls/issues/9574
244 re.compile(r'PSA \w+ DH_.*type not supported'),
245 # We only test partial support for DH with the 2048-bit group
246 # enabled and the other groups disabled.
247 # https://github.com/Mbed-TLS/mbedtls/issues/9575
248 'PSA generate DH_KEY_PAIR(RFC7919) 2048-bit group not supported',
249 'PSA import DH_KEY_PAIR(RFC7919) 2048-bit group not supported',
250 'PSA import DH_PUBLIC_KEY(RFC7919) 2048-bit group not supported',
Gilles Peskined8da2fc2024-09-17 15:07:22 +0200251 ],
252 'test_suite_psa_crypto_op_fail.generated': [
Gilles Peskine72396da2024-09-17 17:15:29 +0200253 # Ignore mechanisms that are not implemented, except
254 # for test cases that assume the mechanism is not supported.
255 _has_word_re(_PSA_MECHANISMS_NOT_IMPLEMENTED,
256 exclude=(r'.*: !(?:' +
257 r'|'.join(_PSA_MECHANISMS_NOT_IMPLEMENTED) +
258 r')\b')),
Gilles Peskine1fac3712024-09-17 17:57:11 +0200259 # Incorrect dependency generation. To be fixed as part of the
260 # resolution of https://github.com/Mbed-TLS/mbedtls/issues/9167
261 # by forward-porting the commit
262 # "PSA test case generation: dependency inference class: operation fail"
263 # from https://github.com/Mbed-TLS/mbedtls/pull/9025 .
264 re.compile(r'.* with (?:DH|ECC)_(?:KEY_PAIR|PUBLIC_KEY)\(.*'),
265 # PBKDF2_HMAC is not in the default configuration, so we don't
266 # enable it in depends.py where we remove hashes.
267 # https://github.com/Mbed-TLS/mbedtls/issues/9576
268 re.compile(r'PSA key_derivation PBKDF2_HMAC\(\w+\): !(?!PBKDF2_HMAC\Z).*'),
269 # We never test with TLS12_PRF or TLS12_PSK_TO_MS disabled
270 # but certain other things enabled.
271 # https://github.com/Mbed-TLS/mbedtls/issues/9577
272 re.compile(r'PSA key_derivation TLS12_PRF\(\w+\): !TLS12_PRF'),
273 re.compile(r'PSA key_derivation TLS12_PSK_TO_MS'
274 r'\((?!SHA_256|SHA_384|SHA_512)\w+\): !TLS12_PSK_TO_MS'),
275 'PSA key_derivation KEY_AGREEMENT(ECDH,TLS12_PRF(SHA_256)): !TLS12_PRF',
276 'PSA key_derivation KEY_AGREEMENT(ECDH,TLS12_PRF(SHA_384)): !TLS12_PRF',
277
278 # We never test with the HMAC algorithm enabled but the HMAC
279 # key type disabled. Those dependencies don't really make sense.
280 # https://github.com/Mbed-TLS/mbedtls/issues/9573
281 re.compile(r'.* !HMAC with HMAC'),
282 # There's something wrong with PSA_WANT_ALG_RSA_PSS_ANY_SALT
283 # differing from PSA_WANT_ALG_RSA_PSS.
284 # https://github.com/Mbed-TLS/mbedtls/issues/9578
285 re.compile(r'PSA sign RSA_PSS_ANY_SALT.*!(?:MD|RIPEMD|SHA).*'),
Gilles Peskined8da2fc2024-09-17 15:07:22 +0200286 ],
287 'test_suite_psa_crypto_storage_format.current': [
288 PSA_MECHANISM_NOT_IMPLEMENTED_SEARCH_RE,
289 ],
290 'test_suite_psa_crypto_storage_format.v0': [
291 PSA_MECHANISM_NOT_IMPLEMENTED_SEARCH_RE,
292 ],
Gilles Peskine419a5842024-09-17 18:32:05 +0200293 'tls13-misc': [
294 # Disabled due to OpenSSL bug.
295 # https://github.com/openssl/openssl/issues/10714
296 'TLS 1.3 O->m: resumption',
297 # Disabled due to OpenSSL command line limitation.
298 # https://github.com/Mbed-TLS/mbedtls/issues/9582
299 'TLS 1.3 m->O: resumption with early data',
300 ],
Gilles Peskined8da2fc2024-09-17 15:07:22 +0200301 }
302
Gilles Peskine17e071b2024-09-16 19:57:10 +0200303
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200304# The names that we give to classes derived from DriverVSReference do not
305# follow the usual naming convention, because it's more readable to use
306# underscores and parts of the configuration names. Also, these classes
307# are just there to specify some data, so they don't need repetitive
308# documentation.
309#pylint: disable=invalid-name,missing-class-docstring
310
Gilles Peskine45a32b12024-10-03 18:42:37 +0200311class DriverVSReference_hash(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200312 REFERENCE = 'test_psa_crypto_config_reference_hash_use_psa'
313 DRIVER = 'test_psa_crypto_config_accel_hash_use_psa'
314 IGNORED_SUITES = [
315 'shax', 'mdx', # the software implementations that are being excluded
316 'md.psa', # purposefully depends on whether drivers are present
317 'psa_crypto_low_hash.generated', # testing the builtins
318 ]
319 IGNORED_TESTS = {
320 'test_suite_config': [
321 re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
322 ],
323 'test_suite_platform': [
324 # Incompatible with sanitizers (e.g. ASan). If the driver
325 # component uses a sanitizer but the reference component
326 # doesn't, we have a PASS vs SKIP mismatch.
327 'Check mbedtls_calloc overallocation',
328 ],
329 }
330
Gilles Peskine45a32b12024-10-03 18:42:37 +0200331class DriverVSReference_hmac(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200332 REFERENCE = 'test_psa_crypto_config_reference_hmac'
333 DRIVER = 'test_psa_crypto_config_accel_hmac'
334 IGNORED_SUITES = [
335 # These suites require legacy hash support, which is disabled
336 # in the accelerated component.
337 'shax', 'mdx',
338 # This suite tests builtins directly, but these are missing
339 # in the accelerated case.
340 'psa_crypto_low_hash.generated',
341 ]
342 IGNORED_TESTS = {
343 'test_suite_config': [
344 re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
345 re.compile(r'.*\bMBEDTLS_MD_C\b')
346 ],
347 'test_suite_md': [
348 # Builtin HMAC is not supported in the accelerate component.
349 re.compile('.*HMAC.*'),
350 # Following tests make use of functions which are not available
351 # when MD_C is disabled, as it happens in the accelerated
352 # test component.
353 re.compile('generic .* Hash file .*'),
354 'MD list',
355 ],
356 'test_suite_md.psa': [
357 # "legacy only" tests require hash algorithms to be NOT
358 # accelerated, but this of course false for the accelerated
359 # test component.
360 re.compile('PSA dispatch .* legacy only'),
361 ],
362 'test_suite_platform': [
363 # Incompatible with sanitizers (e.g. ASan). If the driver
364 # component uses a sanitizer but the reference component
365 # doesn't, we have a PASS vs SKIP mismatch.
366 'Check mbedtls_calloc overallocation',
367 ],
368 }
369
Gilles Peskine45a32b12024-10-03 18:42:37 +0200370class DriverVSReference_cipher_aead_cmac(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200371 REFERENCE = 'test_psa_crypto_config_reference_cipher_aead_cmac'
372 DRIVER = 'test_psa_crypto_config_accel_cipher_aead_cmac'
373 # Modules replaced by drivers.
374 IGNORED_SUITES = [
375 # low-level (block/stream) cipher modules
376 'aes', 'aria', 'camellia', 'des', 'chacha20',
377 # AEAD modes and CMAC
378 'ccm', 'chachapoly', 'cmac', 'gcm',
379 # The Cipher abstraction layer
380 'cipher',
381 ]
382 IGNORED_TESTS = {
383 'test_suite_config': [
384 re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA|CHACHA20|DES)_.*'),
385 re.compile(r'.*\bMBEDTLS_(CCM|CHACHAPOLY|CMAC|GCM)_.*'),
386 re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'),
387 re.compile(r'.*\bMBEDTLS_CIPHER_.*'),
388 ],
389 # PEM decryption is not supported so far.
390 # The rest of PEM (write, unencrypted read) works though.
391 'test_suite_pem': [
392 re.compile(r'PEM read .*(AES|DES|\bencrypt).*'),
393 ],
394 'test_suite_platform': [
395 # Incompatible with sanitizers (e.g. ASan). If the driver
396 # component uses a sanitizer but the reference component
397 # doesn't, we have a PASS vs SKIP mismatch.
398 'Check mbedtls_calloc overallocation',
399 ],
400 # Following tests depend on AES_C/DES_C but are not about
401 # them really, just need to know some error code is there.
402 'test_suite_error': [
403 'Low and high error',
404 'Single low error'
405 ],
406 # Similar to test_suite_error above.
407 'test_suite_version': [
408 'Check for MBEDTLS_AES_C when already present',
409 ],
410 # The en/decryption part of PKCS#12 is not supported so far.
411 # The rest of PKCS#12 (key derivation) works though.
412 'test_suite_pkcs12': [
413 re.compile(r'PBE Encrypt, .*'),
414 re.compile(r'PBE Decrypt, .*'),
415 ],
416 # The en/decryption part of PKCS#5 is not supported so far.
417 # The rest of PKCS#5 (PBKDF2) works though.
418 'test_suite_pkcs5': [
419 re.compile(r'PBES2 Encrypt, .*'),
420 re.compile(r'PBES2 Decrypt .*'),
421 ],
422 # Encrypted keys are not supported so far.
423 # pylint: disable=line-too-long
424 'test_suite_pkparse': [
425 'Key ASN1 (Encrypted key PKCS12, trailing garbage data)',
426 'Key ASN1 (Encrypted key PKCS5, trailing garbage data)',
427 re.compile(r'Parse (RSA|EC) Key .*\(.* ([Ee]ncrypted|password).*\)'),
428 ],
429 # Encrypted keys are not supported so far.
430 'ssl-opt': [
431 'TLS: password protected server key',
432 'TLS: password protected client key',
433 'TLS: password protected server key, two certificates',
434 ],
435 }
436
Gilles Peskine45a32b12024-10-03 18:42:37 +0200437class DriverVSReference_ecp_light_only(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200438 REFERENCE = 'test_psa_crypto_config_reference_ecc_ecp_light_only'
439 DRIVER = 'test_psa_crypto_config_accel_ecc_ecp_light_only'
440 IGNORED_SUITES = [
441 # Modules replaced by drivers
442 'ecdsa', 'ecdh', 'ecjpake',
443 ]
444 IGNORED_TESTS = {
445 'test_suite_config': [
446 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
447 ],
448 'test_suite_platform': [
449 # Incompatible with sanitizers (e.g. ASan). If the driver
450 # component uses a sanitizer but the reference component
451 # doesn't, we have a PASS vs SKIP mismatch.
452 'Check mbedtls_calloc overallocation',
453 ],
454 # This test wants a legacy function that takes f_rng, p_rng
455 # arguments, and uses legacy ECDSA for that. The test is
456 # really about the wrapper around the PSA RNG, not ECDSA.
457 'test_suite_random': [
458 'PSA classic wrapper: ECDSA signature (SECP256R1)',
459 ],
460 # In the accelerated test ECP_C is not set (only ECP_LIGHT is)
461 # so we must ignore disparities in the tests for which ECP_C
462 # is required.
463 'test_suite_ecp': [
464 re.compile(r'ECP check public-private .*'),
465 re.compile(r'ECP calculate public: .*'),
466 re.compile(r'ECP gen keypair .*'),
467 re.compile(r'ECP point muladd .*'),
468 re.compile(r'ECP point multiplication .*'),
469 re.compile(r'ECP test vectors .*'),
470 ],
471 'test_suite_ssl': [
472 # This deprecated function is only present when ECP_C is On.
473 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
474 ],
475 }
476
Gilles Peskine45a32b12024-10-03 18:42:37 +0200477class DriverVSReference_no_ecp_at_all(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200478 REFERENCE = 'test_psa_crypto_config_reference_ecc_no_ecp_at_all'
479 DRIVER = 'test_psa_crypto_config_accel_ecc_no_ecp_at_all'
480 IGNORED_SUITES = [
481 # Modules replaced by drivers
482 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
483 ]
484 IGNORED_TESTS = {
485 'test_suite_config': [
486 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
487 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
488 ],
489 'test_suite_platform': [
490 # Incompatible with sanitizers (e.g. ASan). If the driver
491 # component uses a sanitizer but the reference component
492 # doesn't, we have a PASS vs SKIP mismatch.
493 'Check mbedtls_calloc overallocation',
494 ],
495 # See ecp_light_only
496 'test_suite_random': [
497 'PSA classic wrapper: ECDSA signature (SECP256R1)',
498 ],
499 'test_suite_pkparse': [
500 # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED
501 # is automatically enabled in build_info.h (backward compatibility)
502 # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a
503 # consequence compressed points are supported in the reference
504 # component but not in the accelerated one, so they should be skipped
505 # while checking driver's coverage.
506 re.compile(r'Parse EC Key .*compressed\)'),
507 re.compile(r'Parse Public EC Key .*compressed\)'),
508 ],
509 # See ecp_light_only
510 'test_suite_ssl': [
511 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
512 ],
513 }
514
Gilles Peskine45a32b12024-10-03 18:42:37 +0200515class DriverVSReference_ecc_no_bignum(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200516 REFERENCE = 'test_psa_crypto_config_reference_ecc_no_bignum'
517 DRIVER = 'test_psa_crypto_config_accel_ecc_no_bignum'
518 IGNORED_SUITES = [
519 # Modules replaced by drivers
520 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
521 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
522 'bignum.generated', 'bignum.misc',
523 ]
524 IGNORED_TESTS = {
525 'test_suite_config': [
526 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
527 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
528 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
529 ],
530 'test_suite_platform': [
531 # Incompatible with sanitizers (e.g. ASan). If the driver
532 # component uses a sanitizer but the reference component
533 # doesn't, we have a PASS vs SKIP mismatch.
534 'Check mbedtls_calloc overallocation',
535 ],
536 # See ecp_light_only
537 'test_suite_random': [
538 'PSA classic wrapper: ECDSA signature (SECP256R1)',
539 ],
540 # See no_ecp_at_all
541 'test_suite_pkparse': [
542 re.compile(r'Parse EC Key .*compressed\)'),
543 re.compile(r'Parse Public EC Key .*compressed\)'),
544 ],
545 'test_suite_asn1parse': [
546 'INTEGER too large for mpi',
547 ],
548 'test_suite_asn1write': [
549 re.compile(r'ASN.1 Write mpi.*'),
550 ],
551 'test_suite_debug': [
552 re.compile(r'Debug print mbedtls_mpi.*'),
553 ],
554 # See ecp_light_only
555 'test_suite_ssl': [
556 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
557 ],
558 }
559
Gilles Peskine45a32b12024-10-03 18:42:37 +0200560class DriverVSReference_ecc_ffdh_no_bignum(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200561 REFERENCE = 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum'
562 DRIVER = 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum'
563 IGNORED_SUITES = [
564 # Modules replaced by drivers
565 'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'dhm',
566 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
567 'bignum.generated', 'bignum.misc',
568 ]
569 IGNORED_TESTS = {
570 'ssl-opt': [
571 # DHE support in TLS 1.2 requires built-in MBEDTLS_DHM_C
572 # (because it needs custom groups, which PSA does not
573 # provide), even with MBEDTLS_USE_PSA_CRYPTO.
574 re.compile(r'PSK callback:.*\bdhe-psk\b.*'),
575 ],
576 'test_suite_config': [
577 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
578 re.compile(r'.*\bMBEDTLS_DHM_C\b.*'),
579 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
580 re.compile(r'.*\bMBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED\b.*'),
581 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
582 ],
583 'test_suite_platform': [
584 # Incompatible with sanitizers (e.g. ASan). If the driver
585 # component uses a sanitizer but the reference component
586 # doesn't, we have a PASS vs SKIP mismatch.
587 'Check mbedtls_calloc overallocation',
588 ],
589 # See ecp_light_only
590 'test_suite_random': [
591 'PSA classic wrapper: ECDSA signature (SECP256R1)',
592 ],
593 # See no_ecp_at_all
594 'test_suite_pkparse': [
595 re.compile(r'Parse EC Key .*compressed\)'),
596 re.compile(r'Parse Public EC Key .*compressed\)'),
597 ],
598 'test_suite_asn1parse': [
599 'INTEGER too large for mpi',
600 ],
601 'test_suite_asn1write': [
602 re.compile(r'ASN.1 Write mpi.*'),
603 ],
604 'test_suite_debug': [
605 re.compile(r'Debug print mbedtls_mpi.*'),
606 ],
607 # See ecp_light_only
608 'test_suite_ssl': [
609 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
610 ],
611 }
612
Gilles Peskine45a32b12024-10-03 18:42:37 +0200613class DriverVSReference_ffdh_alg(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200614 REFERENCE = 'test_psa_crypto_config_reference_ffdh'
615 DRIVER = 'test_psa_crypto_config_accel_ffdh'
616 IGNORED_SUITES = ['dhm']
617 IGNORED_TESTS = {
618 'test_suite_config': [
619 re.compile(r'.*\bMBEDTLS_DHM_C\b.*'),
620 ],
621 'test_suite_platform': [
622 # Incompatible with sanitizers (e.g. ASan). If the driver
623 # component uses a sanitizer but the reference component
624 # doesn't, we have a PASS vs SKIP mismatch.
625 'Check mbedtls_calloc overallocation',
626 ],
627 }
628
Gilles Peskine45a32b12024-10-03 18:42:37 +0200629class DriverVSReference_tfm_config(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200630 REFERENCE = 'test_tfm_config_no_p256m'
631 DRIVER = 'test_tfm_config_p256m_driver_accel_ec'
632 IGNORED_SUITES = [
633 # Modules replaced by drivers
634 'asn1parse', 'asn1write',
635 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
636 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
637 'bignum.generated', 'bignum.misc',
638 ]
639 IGNORED_TESTS = {
640 'test_suite_config': [
641 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
642 re.compile(r'.*\bMBEDTLS_(ASN1\w+)_C\b.*'),
643 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECP)_.*'),
644 re.compile(r'.*\bMBEDTLS_PSA_P256M_DRIVER_ENABLED\b.*')
645 ],
646 'test_suite_config.crypto_combinations': [
647 'Config: ECC: Weierstrass curves only',
648 ],
649 'test_suite_platform': [
650 # Incompatible with sanitizers (e.g. ASan). If the driver
651 # component uses a sanitizer but the reference component
652 # doesn't, we have a PASS vs SKIP mismatch.
653 'Check mbedtls_calloc overallocation',
654 ],
655 # See ecp_light_only
656 'test_suite_random': [
657 'PSA classic wrapper: ECDSA signature (SECP256R1)',
658 ],
659 }
660
Gilles Peskine45a32b12024-10-03 18:42:37 +0200661class DriverVSReference_rsa(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200662 REFERENCE = 'test_psa_crypto_config_reference_rsa_crypto'
663 DRIVER = 'test_psa_crypto_config_accel_rsa_crypto'
664 IGNORED_SUITES = [
665 # Modules replaced by drivers.
666 'rsa', 'pkcs1_v15', 'pkcs1_v21',
667 # We temporarily don't care about PK stuff.
668 'pk', 'pkwrite', 'pkparse'
669 ]
670 IGNORED_TESTS = {
671 'test_suite_config': [
672 re.compile(r'.*\bMBEDTLS_(PKCS1|RSA)_.*'),
673 re.compile(r'.*\bMBEDTLS_GENPRIME\b.*')
674 ],
675 'test_suite_platform': [
676 # Incompatible with sanitizers (e.g. ASan). If the driver
677 # component uses a sanitizer but the reference component
678 # doesn't, we have a PASS vs SKIP mismatch.
679 'Check mbedtls_calloc overallocation',
680 ],
681 # Following tests depend on RSA_C but are not about
682 # them really, just need to know some error code is there.
683 'test_suite_error': [
684 'Low and high error',
685 'Single high error'
686 ],
687 # Constant time operations only used for PKCS1_V15
688 'test_suite_constant_time': [
689 re.compile(r'mbedtls_ct_zeroize_if .*'),
690 re.compile(r'mbedtls_ct_memmove_left .*')
691 ],
692 'test_suite_psa_crypto': [
693 # We don't support generate_key_custom entry points
694 # in drivers yet.
695 re.compile(r'PSA generate key custom: RSA, e=.*'),
696 re.compile(r'PSA generate key ext: RSA, e=.*'),
697 ],
698 }
699
Gilles Peskine45a32b12024-10-03 18:42:37 +0200700class DriverVSReference_block_cipher_dispatch(outcome_analysis.DriverVSReference):
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200701 REFERENCE = 'test_full_block_cipher_legacy_dispatch'
702 DRIVER = 'test_full_block_cipher_psa_dispatch'
703 IGNORED_SUITES = [
704 # Skipped in the accelerated component
705 'aes', 'aria', 'camellia',
706 # These require AES_C, ARIA_C or CAMELLIA_C to be enabled in
707 # order for the cipher module (actually cipher_wrapper) to work
708 # properly. However these symbols are disabled in the accelerated
709 # component so we ignore them.
710 'cipher.ccm', 'cipher.gcm', 'cipher.aes', 'cipher.aria',
711 'cipher.camellia',
712 ]
713 IGNORED_TESTS = {
714 'test_suite_config': [
715 re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA)_.*'),
716 re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'),
717 ],
718 'test_suite_cmac': [
719 # Following tests require AES_C/ARIA_C/CAMELLIA_C to be enabled,
720 # but these are not available in the accelerated component.
721 'CMAC null arguments',
722 re.compile('CMAC.* (AES|ARIA|Camellia).*'),
723 ],
724 'test_suite_cipher.padding': [
725 # Following tests require AES_C/CAMELLIA_C to be enabled,
726 # but these are not available in the accelerated component.
727 re.compile('Set( non-existent)? padding with (AES|CAMELLIA).*'),
728 ],
729 'test_suite_pkcs5': [
730 # The AES part of PKCS#5 PBES2 is not yet supported.
731 # The rest of PKCS#5 (PBKDF2) works, though.
732 re.compile(r'PBES2 .* AES-.*')
733 ],
734 'test_suite_pkparse': [
735 # PEM (called by pkparse) requires AES_C in order to decrypt
736 # the key, but this is not available in the accelerated
737 # component.
738 re.compile('Parse RSA Key.*(password|AES-).*'),
739 ],
740 'test_suite_pem': [
741 # Following tests require AES_C, but this is diabled in the
742 # accelerated component.
743 re.compile('PEM read .*AES.*'),
744 'PEM read (unknown encryption algorithm)',
745 ],
746 'test_suite_error': [
747 # Following tests depend on AES_C but are not about them
748 # really, just need to know some error code is there.
749 'Single low error',
750 'Low and high error',
751 ],
752 'test_suite_version': [
753 # Similar to test_suite_error above.
754 'Check for MBEDTLS_AES_C when already present',
755 ],
756 'test_suite_platform': [
757 # Incompatible with sanitizers (e.g. ASan). If the driver
758 # component uses a sanitizer but the reference component
759 # doesn't, we have a PASS vs SKIP mismatch.
760 'Check mbedtls_calloc overallocation',
761 ],
762 }
763
764#pylint: enable=invalid-name,missing-class-docstring
765
766
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100767# List of tasks with a function that can handle this task and additional arguments if required
Valerio Settidfd7ca62023-10-09 16:30:11 +0200768KNOWN_TASKS = {
Gilles Peskine0316f102024-09-16 19:15:29 +0200769 'analyze_coverage': CoverageTask,
Gilles Peskine92cc8db2024-09-16 20:14:26 +0200770 'analyze_driver_vs_reference_hash': DriverVSReference_hash,
771 'analyze_driver_vs_reference_hmac': DriverVSReference_hmac,
772 'analyze_driver_vs_reference_cipher_aead_cmac': DriverVSReference_cipher_aead_cmac,
773 'analyze_driver_vs_reference_ecp_light_only': DriverVSReference_ecp_light_only,
774 'analyze_driver_vs_reference_no_ecp_at_all': DriverVSReference_no_ecp_at_all,
775 'analyze_driver_vs_reference_ecc_no_bignum': DriverVSReference_ecc_no_bignum,
776 'analyze_driver_vs_reference_ecc_ffdh_no_bignum': DriverVSReference_ecc_ffdh_no_bignum,
777 'analyze_driver_vs_reference_ffdh_alg': DriverVSReference_ffdh_alg,
778 'analyze_driver_vs_reference_tfm_config': DriverVSReference_tfm_config,
779 'analyze_driver_vs_reference_rsa': DriverVSReference_rsa,
780 'analyze_block_cipher_dispatch': DriverVSReference_block_cipher_dispatch,
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200781}
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200782
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200783if __name__ == '__main__':
Gilles Peskine45a32b12024-10-03 18:42:37 +0200784 outcome_analysis.main(KNOWN_TASKS)