blob: c2ec34e4822aa8cae20bf715b4b4acbb334074f1 [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 Peskine2a71fac2024-09-17 15:07:22 +020010import typing
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020011
Gilles Peskine31467722024-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 Peskine082eade2024-10-03 18:42:37 +020016class CoverageTask(outcome_analysis.CoverageTask):
Gilles Peskine095561c2024-10-04 16:24:26 +020017 """Justify test cases that are never executed."""
Gilles Peskine3f5022e2024-09-16 20:23:40 +020018
Gilles Peskine2a71fac2024-09-17 15:07:22 +020019 @staticmethod
Gilles Peskine5872c0d2024-09-17 17:15:29 +020020 def _has_word_re(words: typing.Iterable[str],
21 exclude: typing.Optional[str] = None) -> typing.Pattern:
Gilles Peskine2a71fac2024-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 Peskine5872c0d2024-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 Peskine2a71fac2024-09-17 15:07:22 +020028 """
Gilles Peskine5872c0d2024-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 Peskine5e3ed3f2024-10-11 12:00:44 +020034 re.DOTALL)
Gilles Peskine2a71fac2024-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 Peskinede2316b2024-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 Peskinede2316b2024-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)',
Gilles Peskine24b03d82024-10-04 16:22:24 +020085 # TLS doesn't use restartable ECDH yet.
86 # https://github.com/Mbed-TLS/mbedtls/issues/7294
87 re.compile(r'EC restart:.*no USE_PSA.*'),
Gilles Peskinede2316b2024-09-17 18:32:05 +020088 # It seems that we don't run `ssl-opt.sh` with
89 # `MBEDTLS_USE_PSA_CRYPTO` enabled but `MBEDTLS_SSL_ASYNC_PRIVATE`
90 # disabled.
91 # https://github.com/Mbed-TLS/mbedtls/issues/9581
92 'Opaque key for server authentication: invalid key: decrypt with ECC key, no async',
93 'Opaque key for server authentication: invalid key: ecdh with RSA key, no async',
94 ],
Gilles Peskine2fd25bb2024-09-17 19:46:18 +020095 'test_suite_config.mbedtls_boolean': [
Gilles Peskine2fd25bb2024-09-17 19:46:18 +020096 # https://github.com/Mbed-TLS/mbedtls/issues/9583
97 'Config: !MBEDTLS_ECP_NIST_OPTIM',
Gilles Peskined9c40f52024-10-04 16:24:02 +020098 # We never test without the PSA client code. Should we?
99 # https://github.com/Mbed-TLS/TF-PSA-Crypto/issues/112
100 'Config: !MBEDTLS_PSA_CRYPTO_CLIENT',
Gilles Peskine2fd25bb2024-09-17 19:46:18 +0200101 # Missing coverage of test configurations.
102 # https://github.com/Mbed-TLS/mbedtls/issues/9585
103 'Config: !MBEDTLS_SSL_DTLS_ANTI_REPLAY',
104 # Missing coverage of test configurations.
105 # https://github.com/Mbed-TLS/mbedtls/issues/9585
106 'Config: !MBEDTLS_SSL_DTLS_HELLO_VERIFY',
107 # We don't run test_suite_config when we test this.
108 # https://github.com/Mbed-TLS/mbedtls/issues/9586
109 'Config: !MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED',
110 # We only test multithreading with pthreads.
111 # https://github.com/Mbed-TLS/mbedtls/issues/9584
112 'Config: !MBEDTLS_THREADING_PTHREAD',
113 # Built but not tested.
114 # https://github.com/Mbed-TLS/mbedtls/issues/9587
115 'Config: MBEDTLS_AES_USE_HARDWARE_ONLY',
116 # Untested platform-specific optimizations.
117 # https://github.com/Mbed-TLS/mbedtls/issues/9588
118 'Config: MBEDTLS_HAVE_SSE2',
119 # Obsolete configuration option, to be replaced by
120 # PSA entropy drivers.
121 # https://github.com/Mbed-TLS/mbedtls/issues/8150
122 'Config: MBEDTLS_NO_PLATFORM_ENTROPY',
123 # Untested aspect of the platform interface.
124 # https://github.com/Mbed-TLS/mbedtls/issues/9589
125 'Config: MBEDTLS_PLATFORM_NO_STD_FUNCTIONS',
126 # In a client-server build, test_suite_config runs in the
127 # client configuration, so it will never report
128 # MBEDTLS_PSA_CRYPTO_SPM as enabled. That's ok.
129 'Config: MBEDTLS_PSA_CRYPTO_SPM',
130 # We don't test on armv8 yet.
131 'Config: MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT',
132 'Config: MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY',
133 'Config: MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY',
134 'Config: MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY',
135 # We don't run test_suite_config when we test this.
136 # https://github.com/Mbed-TLS/mbedtls/issues/9586
137 'Config: MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND',
138 ],
139 'test_suite_config.psa_boolean': [
140 # We don't test with HMAC disabled.
141 # https://github.com/Mbed-TLS/mbedtls/issues/9591
142 'Config: !PSA_WANT_ALG_HMAC',
Gilles Peskine2fd25bb2024-09-17 19:46:18 +0200143 # The DERIVE key type is always enabled.
144 'Config: !PSA_WANT_KEY_TYPE_DERIVE',
145 # More granularity of key pair type enablement macros
146 # than we care to test.
147 # https://github.com/Mbed-TLS/mbedtls/issues/9590
148 'Config: !PSA_WANT_KEY_TYPE_DH_KEY_PAIR_EXPORT',
149 'Config: !PSA_WANT_KEY_TYPE_DH_KEY_PAIR_GENERATE',
150 'Config: !PSA_WANT_KEY_TYPE_DH_KEY_PAIR_IMPORT',
151 # More granularity of key pair type enablement macros
152 # than we care to test.
153 # https://github.com/Mbed-TLS/mbedtls/issues/9590
154 'Config: !PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT',
155 'Config: !PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT',
156 # We don't test with HMAC disabled.
157 # https://github.com/Mbed-TLS/mbedtls/issues/9591
158 'Config: !PSA_WANT_KEY_TYPE_HMAC',
159 # The PASSWORD key type is always enabled.
160 'Config: !PSA_WANT_KEY_TYPE_PASSWORD',
161 # The PASSWORD_HASH key type is always enabled.
162 'Config: !PSA_WANT_KEY_TYPE_PASSWORD_HASH',
163 # The RAW_DATA key type is always enabled.
164 'Config: !PSA_WANT_KEY_TYPE_RAW_DATA',
165 # More granularity of key pair type enablement macros
166 # than we care to test.
167 # https://github.com/Mbed-TLS/mbedtls/issues/9590
168 'Config: !PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT',
169 'Config: !PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT',
170 # Algorithm declared but not supported.
171 'Config: PSA_WANT_ALG_CBC_MAC',
172 # Algorithm declared but not supported.
173 'Config: PSA_WANT_ALG_XTS',
174 # Family declared but not supported.
175 'Config: PSA_WANT_ECC_SECP_K1_224',
176 # More granularity of key pair type enablement macros
177 # than we care to test.
178 # https://github.com/Mbed-TLS/mbedtls/issues/9590
179 'Config: PSA_WANT_KEY_TYPE_DH_KEY_PAIR_DERIVE',
180 'Config: PSA_WANT_KEY_TYPE_ECC_KEY_PAIR',
181 'Config: PSA_WANT_KEY_TYPE_RSA_KEY_PAIR',
182 'Config: PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_DERIVE',
183 ],
184 'test_suite_config.psa_combinations': [
185 # We don't test this unusual, but sensible configuration.
186 # https://github.com/Mbed-TLS/mbedtls/issues/9592
187 'Config: PSA_WANT_ALG_DETERMINSTIC_ECDSA without PSA_WANT_ALG_ECDSA',
188 ],
Gilles Peskineb0ec85d2024-09-17 18:33:29 +0200189 'test_suite_pkcs12': [
Gilles Peskine2fd25bb2024-09-17 19:46:18 +0200190 # We never test with CBC/PKCS5/PKCS12 enabled but
191 # PKCS7 padding disabled.
Gilles Peskineb0ec85d2024-09-17 18:33:29 +0200192 # https://github.com/Mbed-TLS/mbedtls/issues/9580
193 'PBE Decrypt, (Invalid padding & PKCS7 padding disabled)',
194 'PBE Encrypt, pad = 8 (PKCS7 padding disabled)',
195 ],
196 'test_suite_pkcs5': [
Gilles Peskine2fd25bb2024-09-17 19:46:18 +0200197 # We never test with CBC/PKCS5/PKCS12 enabled but
198 # PKCS7 padding disabled.
Gilles Peskineb0ec85d2024-09-17 18:33:29 +0200199 # https://github.com/Mbed-TLS/mbedtls/issues/9580
200 'PBES2 Decrypt (Invalid padding & PKCS7 padding disabled)',
201 'PBES2 Encrypt, pad=6 (PKCS7 padding disabled)',
202 'PBES2 Encrypt, pad=8 (PKCS7 padding disabled)',
203 ],
Gilles Peskine2a71fac2024-09-17 15:07:22 +0200204 'test_suite_psa_crypto_generate_key.generated': [
Gilles Peskine5872c0d2024-09-17 17:15:29 +0200205 # Ignore mechanisms that are not implemented, except
206 # for public keys for which we always test that
207 # psa_generate_key() returns PSA_ERROR_INVALID_ARGUMENT
208 # regardless of whether the specific key type is supported.
209 _has_word_re((mech
210 for mech in _PSA_MECHANISMS_NOT_IMPLEMENTED
211 if not mech.startswith('ECC_PUB')),
212 exclude=r'ECC_PUB'),
Gilles Peskine2a71fac2024-09-17 15:07:22 +0200213 ],
Gilles Peskineb0ec85d2024-09-17 18:33:29 +0200214 'test_suite_psa_crypto_metadata': [
215 # Algorithms declared but not supported.
216 # https://github.com/Mbed-TLS/mbedtls/issues/9579
217 'Asymmetric signature: Ed25519ph',
218 'Asymmetric signature: Ed448ph',
219 'Asymmetric signature: pure EdDSA',
220 'Cipher: XTS',
221 'MAC: CBC_MAC-3DES',
222 'MAC: CBC_MAC-AES-128',
223 'MAC: CBC_MAC-AES-192',
224 'MAC: CBC_MAC-AES-256',
225 ],
Gilles Peskine2a71fac2024-09-17 15:07:22 +0200226 'test_suite_psa_crypto_not_supported.generated': [
Gilles Peskineab5cc9b2024-09-17 17:57:11 +0200227 # It is a bug that not-supported test cases aren't getting
228 # run for never-implemented key types.
229 # https://github.com/Mbed-TLS/mbedtls/issues/7915
Gilles Peskine2a71fac2024-09-17 15:07:22 +0200230 PSA_MECHANISM_NOT_IMPLEMENTED_SEARCH_RE,
Gilles Peskine5e3ed3f2024-10-11 12:00:44 +0200231 # We never test with DH key support disabled but support
Gilles Peskineab5cc9b2024-09-17 17:57:11 +0200232 # for a DH group enabled. The dependencies of these test
233 # cases don't really make sense.
234 # https://github.com/Mbed-TLS/mbedtls/issues/9574
235 re.compile(r'PSA \w+ DH_.*type not supported'),
236 # We only test partial support for DH with the 2048-bit group
237 # enabled and the other groups disabled.
238 # https://github.com/Mbed-TLS/mbedtls/issues/9575
239 'PSA generate DH_KEY_PAIR(RFC7919) 2048-bit group not supported',
240 'PSA import DH_KEY_PAIR(RFC7919) 2048-bit group not supported',
241 'PSA import DH_PUBLIC_KEY(RFC7919) 2048-bit group not supported',
Gilles Peskine2a71fac2024-09-17 15:07:22 +0200242 ],
243 'test_suite_psa_crypto_op_fail.generated': [
Gilles Peskine5872c0d2024-09-17 17:15:29 +0200244 # Ignore mechanisms that are not implemented, except
245 # for test cases that assume the mechanism is not supported.
246 _has_word_re(_PSA_MECHANISMS_NOT_IMPLEMENTED,
247 exclude=(r'.*: !(?:' +
248 r'|'.join(_PSA_MECHANISMS_NOT_IMPLEMENTED) +
249 r')\b')),
Gilles Peskineab5cc9b2024-09-17 17:57:11 +0200250 # Incorrect dependency generation. To be fixed as part of the
251 # resolution of https://github.com/Mbed-TLS/mbedtls/issues/9167
252 # by forward-porting the commit
253 # "PSA test case generation: dependency inference class: operation fail"
254 # from https://github.com/Mbed-TLS/mbedtls/pull/9025 .
255 re.compile(r'.* with (?:DH|ECC)_(?:KEY_PAIR|PUBLIC_KEY)\(.*'),
Gilles Peskineab5cc9b2024-09-17 17:57:11 +0200256
257 # We never test with the HMAC algorithm enabled but the HMAC
258 # key type disabled. Those dependencies don't really make sense.
259 # https://github.com/Mbed-TLS/mbedtls/issues/9573
260 re.compile(r'.* !HMAC with HMAC'),
Gilles Peskine2a71fac2024-09-17 15:07:22 +0200261 ],
262 'test_suite_psa_crypto_storage_format.current': [
263 PSA_MECHANISM_NOT_IMPLEMENTED_SEARCH_RE,
264 ],
265 'test_suite_psa_crypto_storage_format.v0': [
266 PSA_MECHANISM_NOT_IMPLEMENTED_SEARCH_RE,
267 ],
Gilles Peskinede2316b2024-09-17 18:32:05 +0200268 'tls13-misc': [
269 # Disabled due to OpenSSL bug.
270 # https://github.com/openssl/openssl/issues/10714
271 'TLS 1.3 O->m: resumption',
272 # Disabled due to OpenSSL command line limitation.
273 # https://github.com/Mbed-TLS/mbedtls/issues/9582
274 'TLS 1.3 m->O: resumption with early data',
275 ],
Gilles Peskine2a71fac2024-09-17 15:07:22 +0200276 }
277
Gilles Peskine82b16722024-09-16 19:57:10 +0200278
Gilles Peskine9df375b2024-09-16 20:14:26 +0200279# The names that we give to classes derived from DriverVSReference do not
280# follow the usual naming convention, because it's more readable to use
281# underscores and parts of the configuration names. Also, these classes
282# are just there to specify some data, so they don't need repetitive
283# documentation.
284#pylint: disable=invalid-name,missing-class-docstring
285
Gilles Peskine082eade2024-10-03 18:42:37 +0200286class DriverVSReference_hash(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200287 REFERENCE = 'test_psa_crypto_config_reference_hash_use_psa'
288 DRIVER = 'test_psa_crypto_config_accel_hash_use_psa'
289 IGNORED_SUITES = [
290 'shax', 'mdx', # the software implementations that are being excluded
291 'md.psa', # purposefully depends on whether drivers are present
292 'psa_crypto_low_hash.generated', # testing the builtins
293 ]
294 IGNORED_TESTS = {
295 'test_suite_config': [
296 re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
297 ],
298 'test_suite_platform': [
299 # Incompatible with sanitizers (e.g. ASan). If the driver
300 # component uses a sanitizer but the reference component
301 # doesn't, we have a PASS vs SKIP mismatch.
302 'Check mbedtls_calloc overallocation',
303 ],
304 }
305
Gilles Peskine082eade2024-10-03 18:42:37 +0200306class DriverVSReference_hmac(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200307 REFERENCE = 'test_psa_crypto_config_reference_hmac'
308 DRIVER = 'test_psa_crypto_config_accel_hmac'
309 IGNORED_SUITES = [
310 # These suites require legacy hash support, which is disabled
311 # in the accelerated component.
312 'shax', 'mdx',
313 # This suite tests builtins directly, but these are missing
314 # in the accelerated case.
315 'psa_crypto_low_hash.generated',
316 ]
317 IGNORED_TESTS = {
318 'test_suite_config': [
319 re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
320 re.compile(r'.*\bMBEDTLS_MD_C\b')
321 ],
322 'test_suite_md': [
323 # Builtin HMAC is not supported in the accelerate component.
324 re.compile('.*HMAC.*'),
325 # Following tests make use of functions which are not available
326 # when MD_C is disabled, as it happens in the accelerated
327 # test component.
328 re.compile('generic .* Hash file .*'),
329 'MD list',
330 ],
331 'test_suite_md.psa': [
332 # "legacy only" tests require hash algorithms to be NOT
333 # accelerated, but this of course false for the accelerated
334 # test component.
335 re.compile('PSA dispatch .* legacy only'),
336 ],
337 'test_suite_platform': [
338 # Incompatible with sanitizers (e.g. ASan). If the driver
339 # component uses a sanitizer but the reference component
340 # doesn't, we have a PASS vs SKIP mismatch.
341 'Check mbedtls_calloc overallocation',
342 ],
343 }
344
Gilles Peskine082eade2024-10-03 18:42:37 +0200345class DriverVSReference_cipher_aead_cmac(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200346 REFERENCE = 'test_psa_crypto_config_reference_cipher_aead_cmac'
347 DRIVER = 'test_psa_crypto_config_accel_cipher_aead_cmac'
348 # Modules replaced by drivers.
349 IGNORED_SUITES = [
350 # low-level (block/stream) cipher modules
351 'aes', 'aria', 'camellia', 'des', 'chacha20',
352 # AEAD modes and CMAC
353 'ccm', 'chachapoly', 'cmac', 'gcm',
354 # The Cipher abstraction layer
355 'cipher',
356 ]
357 IGNORED_TESTS = {
358 'test_suite_config': [
359 re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA|CHACHA20|DES)_.*'),
360 re.compile(r'.*\bMBEDTLS_(CCM|CHACHAPOLY|CMAC|GCM)_.*'),
361 re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'),
362 re.compile(r'.*\bMBEDTLS_CIPHER_.*'),
363 ],
364 # PEM decryption is not supported so far.
365 # The rest of PEM (write, unencrypted read) works though.
366 'test_suite_pem': [
367 re.compile(r'PEM read .*(AES|DES|\bencrypt).*'),
368 ],
369 'test_suite_platform': [
370 # Incompatible with sanitizers (e.g. ASan). If the driver
371 # component uses a sanitizer but the reference component
372 # doesn't, we have a PASS vs SKIP mismatch.
373 'Check mbedtls_calloc overallocation',
374 ],
375 # Following tests depend on AES_C/DES_C but are not about
376 # them really, just need to know some error code is there.
377 'test_suite_error': [
378 'Low and high error',
379 'Single low error'
380 ],
381 # Similar to test_suite_error above.
382 'test_suite_version': [
383 'Check for MBEDTLS_AES_C when already present',
384 ],
385 # The en/decryption part of PKCS#12 is not supported so far.
386 # The rest of PKCS#12 (key derivation) works though.
387 'test_suite_pkcs12': [
388 re.compile(r'PBE Encrypt, .*'),
389 re.compile(r'PBE Decrypt, .*'),
390 ],
391 # The en/decryption part of PKCS#5 is not supported so far.
392 # The rest of PKCS#5 (PBKDF2) works though.
393 'test_suite_pkcs5': [
394 re.compile(r'PBES2 Encrypt, .*'),
395 re.compile(r'PBES2 Decrypt .*'),
396 ],
397 # Encrypted keys are not supported so far.
398 # pylint: disable=line-too-long
399 'test_suite_pkparse': [
400 'Key ASN1 (Encrypted key PKCS12, trailing garbage data)',
401 'Key ASN1 (Encrypted key PKCS5, trailing garbage data)',
402 re.compile(r'Parse (RSA|EC) Key .*\(.* ([Ee]ncrypted|password).*\)'),
403 ],
404 # Encrypted keys are not supported so far.
405 'ssl-opt': [
406 'TLS: password protected server key',
407 'TLS: password protected client key',
408 'TLS: password protected server key, two certificates',
409 ],
410 }
411
Gilles Peskine082eade2024-10-03 18:42:37 +0200412class DriverVSReference_ecp_light_only(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200413 REFERENCE = 'test_psa_crypto_config_reference_ecc_ecp_light_only'
414 DRIVER = 'test_psa_crypto_config_accel_ecc_ecp_light_only'
415 IGNORED_SUITES = [
416 # Modules replaced by drivers
417 'ecdsa', 'ecdh', 'ecjpake',
418 ]
419 IGNORED_TESTS = {
420 'test_suite_config': [
421 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
422 ],
423 'test_suite_platform': [
424 # Incompatible with sanitizers (e.g. ASan). If the driver
425 # component uses a sanitizer but the reference component
426 # doesn't, we have a PASS vs SKIP mismatch.
427 'Check mbedtls_calloc overallocation',
428 ],
429 # This test wants a legacy function that takes f_rng, p_rng
430 # arguments, and uses legacy ECDSA for that. The test is
431 # really about the wrapper around the PSA RNG, not ECDSA.
432 'test_suite_random': [
433 'PSA classic wrapper: ECDSA signature (SECP256R1)',
434 ],
435 # In the accelerated test ECP_C is not set (only ECP_LIGHT is)
436 # so we must ignore disparities in the tests for which ECP_C
437 # is required.
438 'test_suite_ecp': [
439 re.compile(r'ECP check public-private .*'),
440 re.compile(r'ECP calculate public: .*'),
441 re.compile(r'ECP gen keypair .*'),
442 re.compile(r'ECP point muladd .*'),
443 re.compile(r'ECP point multiplication .*'),
444 re.compile(r'ECP test vectors .*'),
445 ],
446 'test_suite_ssl': [
447 # This deprecated function is only present when ECP_C is On.
448 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
449 ],
450 }
451
Gilles Peskine082eade2024-10-03 18:42:37 +0200452class DriverVSReference_no_ecp_at_all(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200453 REFERENCE = 'test_psa_crypto_config_reference_ecc_no_ecp_at_all'
454 DRIVER = 'test_psa_crypto_config_accel_ecc_no_ecp_at_all'
455 IGNORED_SUITES = [
456 # Modules replaced by drivers
457 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
458 ]
459 IGNORED_TESTS = {
460 'test_suite_config': [
461 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
462 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
463 ],
464 'test_suite_platform': [
465 # Incompatible with sanitizers (e.g. ASan). If the driver
466 # component uses a sanitizer but the reference component
467 # doesn't, we have a PASS vs SKIP mismatch.
468 'Check mbedtls_calloc overallocation',
469 ],
470 # See ecp_light_only
471 'test_suite_random': [
472 'PSA classic wrapper: ECDSA signature (SECP256R1)',
473 ],
474 'test_suite_pkparse': [
475 # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED
476 # is automatically enabled in build_info.h (backward compatibility)
477 # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a
478 # consequence compressed points are supported in the reference
479 # component but not in the accelerated one, so they should be skipped
480 # while checking driver's coverage.
481 re.compile(r'Parse EC Key .*compressed\)'),
482 re.compile(r'Parse Public EC Key .*compressed\)'),
483 ],
484 # See ecp_light_only
485 'test_suite_ssl': [
486 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
487 ],
488 }
489
Gilles Peskine082eade2024-10-03 18:42:37 +0200490class DriverVSReference_ecc_no_bignum(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200491 REFERENCE = 'test_psa_crypto_config_reference_ecc_no_bignum'
492 DRIVER = 'test_psa_crypto_config_accel_ecc_no_bignum'
493 IGNORED_SUITES = [
494 # Modules replaced by drivers
495 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
496 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
497 'bignum.generated', 'bignum.misc',
498 ]
499 IGNORED_TESTS = {
500 'test_suite_config': [
501 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
502 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
503 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
504 ],
505 'test_suite_platform': [
506 # Incompatible with sanitizers (e.g. ASan). If the driver
507 # component uses a sanitizer but the reference component
508 # doesn't, we have a PASS vs SKIP mismatch.
509 'Check mbedtls_calloc overallocation',
510 ],
511 # See ecp_light_only
512 'test_suite_random': [
513 'PSA classic wrapper: ECDSA signature (SECP256R1)',
514 ],
515 # See no_ecp_at_all
516 'test_suite_pkparse': [
517 re.compile(r'Parse EC Key .*compressed\)'),
518 re.compile(r'Parse Public EC Key .*compressed\)'),
519 ],
520 'test_suite_asn1parse': [
521 'INTEGER too large for mpi',
522 ],
523 'test_suite_asn1write': [
524 re.compile(r'ASN.1 Write mpi.*'),
525 ],
526 'test_suite_debug': [
527 re.compile(r'Debug print mbedtls_mpi.*'),
528 ],
529 # See ecp_light_only
530 'test_suite_ssl': [
531 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
532 ],
533 }
534
Gilles Peskine082eade2024-10-03 18:42:37 +0200535class DriverVSReference_ecc_ffdh_no_bignum(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200536 REFERENCE = 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum'
537 DRIVER = 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum'
538 IGNORED_SUITES = [
539 # Modules replaced by drivers
540 'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'dhm',
541 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
542 'bignum.generated', 'bignum.misc',
543 ]
544 IGNORED_TESTS = {
545 'ssl-opt': [
546 # DHE support in TLS 1.2 requires built-in MBEDTLS_DHM_C
547 # (because it needs custom groups, which PSA does not
548 # provide), even with MBEDTLS_USE_PSA_CRYPTO.
549 re.compile(r'PSK callback:.*\bdhe-psk\b.*'),
550 ],
551 'test_suite_config': [
552 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
553 re.compile(r'.*\bMBEDTLS_DHM_C\b.*'),
554 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
555 re.compile(r'.*\bMBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED\b.*'),
556 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
557 ],
558 'test_suite_platform': [
559 # Incompatible with sanitizers (e.g. ASan). If the driver
560 # component uses a sanitizer but the reference component
561 # doesn't, we have a PASS vs SKIP mismatch.
562 'Check mbedtls_calloc overallocation',
563 ],
564 # See ecp_light_only
565 'test_suite_random': [
566 'PSA classic wrapper: ECDSA signature (SECP256R1)',
567 ],
568 # See no_ecp_at_all
569 'test_suite_pkparse': [
570 re.compile(r'Parse EC Key .*compressed\)'),
571 re.compile(r'Parse Public EC Key .*compressed\)'),
572 ],
573 'test_suite_asn1parse': [
574 'INTEGER too large for mpi',
575 ],
576 'test_suite_asn1write': [
577 re.compile(r'ASN.1 Write mpi.*'),
578 ],
579 'test_suite_debug': [
580 re.compile(r'Debug print mbedtls_mpi.*'),
581 ],
582 # See ecp_light_only
583 'test_suite_ssl': [
584 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
585 ],
586 }
587
Gilles Peskine082eade2024-10-03 18:42:37 +0200588class DriverVSReference_ffdh_alg(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200589 REFERENCE = 'test_psa_crypto_config_reference_ffdh'
590 DRIVER = 'test_psa_crypto_config_accel_ffdh'
591 IGNORED_SUITES = ['dhm']
592 IGNORED_TESTS = {
593 'test_suite_config': [
594 re.compile(r'.*\bMBEDTLS_DHM_C\b.*'),
595 ],
596 'test_suite_platform': [
597 # Incompatible with sanitizers (e.g. ASan). If the driver
598 # component uses a sanitizer but the reference component
599 # doesn't, we have a PASS vs SKIP mismatch.
600 'Check mbedtls_calloc overallocation',
601 ],
602 }
603
Gilles Peskine082eade2024-10-03 18:42:37 +0200604class DriverVSReference_tfm_config(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200605 REFERENCE = 'test_tfm_config_no_p256m'
606 DRIVER = 'test_tfm_config_p256m_driver_accel_ec'
607 IGNORED_SUITES = [
608 # Modules replaced by drivers
609 'asn1parse', 'asn1write',
610 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
611 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
612 'bignum.generated', 'bignum.misc',
613 ]
614 IGNORED_TESTS = {
615 'test_suite_config': [
616 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
617 re.compile(r'.*\bMBEDTLS_(ASN1\w+)_C\b.*'),
618 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECP)_.*'),
619 re.compile(r'.*\bMBEDTLS_PSA_P256M_DRIVER_ENABLED\b.*')
620 ],
621 'test_suite_config.crypto_combinations': [
622 'Config: ECC: Weierstrass curves only',
623 ],
624 'test_suite_platform': [
625 # Incompatible with sanitizers (e.g. ASan). If the driver
626 # component uses a sanitizer but the reference component
627 # doesn't, we have a PASS vs SKIP mismatch.
628 'Check mbedtls_calloc overallocation',
629 ],
630 # See ecp_light_only
631 'test_suite_random': [
632 'PSA classic wrapper: ECDSA signature (SECP256R1)',
633 ],
634 }
635
Gilles Peskine082eade2024-10-03 18:42:37 +0200636class DriverVSReference_rsa(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200637 REFERENCE = 'test_psa_crypto_config_reference_rsa_crypto'
638 DRIVER = 'test_psa_crypto_config_accel_rsa_crypto'
639 IGNORED_SUITES = [
640 # Modules replaced by drivers.
641 'rsa', 'pkcs1_v15', 'pkcs1_v21',
642 # We temporarily don't care about PK stuff.
643 'pk', 'pkwrite', 'pkparse'
644 ]
645 IGNORED_TESTS = {
646 'test_suite_config': [
647 re.compile(r'.*\bMBEDTLS_(PKCS1|RSA)_.*'),
648 re.compile(r'.*\bMBEDTLS_GENPRIME\b.*')
649 ],
650 'test_suite_platform': [
651 # Incompatible with sanitizers (e.g. ASan). If the driver
652 # component uses a sanitizer but the reference component
653 # doesn't, we have a PASS vs SKIP mismatch.
654 'Check mbedtls_calloc overallocation',
655 ],
656 # Following tests depend on RSA_C but are not about
657 # them really, just need to know some error code is there.
658 'test_suite_error': [
659 'Low and high error',
660 'Single high error'
661 ],
662 # Constant time operations only used for PKCS1_V15
663 'test_suite_constant_time': [
664 re.compile(r'mbedtls_ct_zeroize_if .*'),
665 re.compile(r'mbedtls_ct_memmove_left .*')
666 ],
667 'test_suite_psa_crypto': [
668 # We don't support generate_key_custom entry points
669 # in drivers yet.
670 re.compile(r'PSA generate key custom: RSA, e=.*'),
671 re.compile(r'PSA generate key ext: RSA, e=.*'),
672 ],
673 }
674
Gilles Peskine082eade2024-10-03 18:42:37 +0200675class DriverVSReference_block_cipher_dispatch(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200676 REFERENCE = 'test_full_block_cipher_legacy_dispatch'
677 DRIVER = 'test_full_block_cipher_psa_dispatch'
678 IGNORED_SUITES = [
679 # Skipped in the accelerated component
680 'aes', 'aria', 'camellia',
681 # These require AES_C, ARIA_C or CAMELLIA_C to be enabled in
682 # order for the cipher module (actually cipher_wrapper) to work
683 # properly. However these symbols are disabled in the accelerated
684 # component so we ignore them.
685 'cipher.ccm', 'cipher.gcm', 'cipher.aes', 'cipher.aria',
686 'cipher.camellia',
687 ]
688 IGNORED_TESTS = {
689 'test_suite_config': [
690 re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA)_.*'),
691 re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'),
692 ],
693 'test_suite_cmac': [
694 # Following tests require AES_C/ARIA_C/CAMELLIA_C to be enabled,
695 # but these are not available in the accelerated component.
696 'CMAC null arguments',
697 re.compile('CMAC.* (AES|ARIA|Camellia).*'),
698 ],
699 'test_suite_cipher.padding': [
700 # Following tests require AES_C/CAMELLIA_C to be enabled,
701 # but these are not available in the accelerated component.
702 re.compile('Set( non-existent)? padding with (AES|CAMELLIA).*'),
703 ],
704 'test_suite_pkcs5': [
705 # The AES part of PKCS#5 PBES2 is not yet supported.
706 # The rest of PKCS#5 (PBKDF2) works, though.
707 re.compile(r'PBES2 .* AES-.*')
708 ],
709 'test_suite_pkparse': [
710 # PEM (called by pkparse) requires AES_C in order to decrypt
711 # the key, but this is not available in the accelerated
712 # component.
713 re.compile('Parse RSA Key.*(password|AES-).*'),
714 ],
715 'test_suite_pem': [
716 # Following tests require AES_C, but this is diabled in the
717 # accelerated component.
718 re.compile('PEM read .*AES.*'),
719 'PEM read (unknown encryption algorithm)',
720 ],
721 'test_suite_error': [
722 # Following tests depend on AES_C but are not about them
723 # really, just need to know some error code is there.
724 'Single low error',
725 'Low and high error',
726 ],
727 'test_suite_version': [
728 # Similar to test_suite_error above.
729 'Check for MBEDTLS_AES_C when already present',
730 ],
731 'test_suite_platform': [
732 # Incompatible with sanitizers (e.g. ASan). If the driver
733 # component uses a sanitizer but the reference component
734 # doesn't, we have a PASS vs SKIP mismatch.
735 'Check mbedtls_calloc overallocation',
736 ],
737 }
738
739#pylint: enable=invalid-name,missing-class-docstring
740
741
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100742# List of tasks with a function that can handle this task and additional arguments if required
Valerio Settidfd7ca62023-10-09 16:30:11 +0200743KNOWN_TASKS = {
Gilles Peskinef646dbf2024-09-16 19:15:29 +0200744 'analyze_coverage': CoverageTask,
Gilles Peskine9df375b2024-09-16 20:14:26 +0200745 'analyze_driver_vs_reference_hash': DriverVSReference_hash,
746 'analyze_driver_vs_reference_hmac': DriverVSReference_hmac,
747 'analyze_driver_vs_reference_cipher_aead_cmac': DriverVSReference_cipher_aead_cmac,
748 'analyze_driver_vs_reference_ecp_light_only': DriverVSReference_ecp_light_only,
749 'analyze_driver_vs_reference_no_ecp_at_all': DriverVSReference_no_ecp_at_all,
750 'analyze_driver_vs_reference_ecc_no_bignum': DriverVSReference_ecc_no_bignum,
751 'analyze_driver_vs_reference_ecc_ffdh_no_bignum': DriverVSReference_ecc_ffdh_no_bignum,
752 'analyze_driver_vs_reference_ffdh_alg': DriverVSReference_ffdh_alg,
753 'analyze_driver_vs_reference_tfm_config': DriverVSReference_tfm_config,
754 'analyze_driver_vs_reference_rsa': DriverVSReference_rsa,
755 'analyze_block_cipher_dispatch': DriverVSReference_block_cipher_dispatch,
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200756}
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200757
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200758if __name__ == '__main__':
Gilles Peskine082eade2024-10-03 18:42:37 +0200759 outcome_analysis.main(KNOWN_TASKS)