blob: 43982ce8107e7bfa0272d5d45a7d26f12fc14760 [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',
143 # We don't test with HMAC disabled.
144 # https://github.com/Mbed-TLS/mbedtls/issues/9591
145 'Config: !PSA_WANT_ALG_TLS12_PRF',
146 # The DERIVE key type is always enabled.
147 'Config: !PSA_WANT_KEY_TYPE_DERIVE',
148 # More granularity of key pair type enablement macros
149 # than we care to test.
150 # https://github.com/Mbed-TLS/mbedtls/issues/9590
151 'Config: !PSA_WANT_KEY_TYPE_DH_KEY_PAIR_EXPORT',
152 'Config: !PSA_WANT_KEY_TYPE_DH_KEY_PAIR_GENERATE',
153 'Config: !PSA_WANT_KEY_TYPE_DH_KEY_PAIR_IMPORT',
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_ECC_KEY_PAIR_EXPORT',
158 'Config: !PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT',
159 # We don't test with HMAC disabled.
160 # https://github.com/Mbed-TLS/mbedtls/issues/9591
161 'Config: !PSA_WANT_KEY_TYPE_HMAC',
162 # The PASSWORD key type is always enabled.
163 'Config: !PSA_WANT_KEY_TYPE_PASSWORD',
164 # The PASSWORD_HASH key type is always enabled.
165 'Config: !PSA_WANT_KEY_TYPE_PASSWORD_HASH',
166 # The RAW_DATA key type is always enabled.
167 'Config: !PSA_WANT_KEY_TYPE_RAW_DATA',
168 # More granularity of key pair type enablement macros
169 # than we care to test.
170 # https://github.com/Mbed-TLS/mbedtls/issues/9590
171 'Config: !PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT',
172 'Config: !PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT',
173 # Algorithm declared but not supported.
174 'Config: PSA_WANT_ALG_CBC_MAC',
175 # Algorithm declared but not supported.
176 'Config: PSA_WANT_ALG_XTS',
177 # Family declared but not supported.
178 'Config: PSA_WANT_ECC_SECP_K1_224',
179 # More granularity of key pair type enablement macros
180 # than we care to test.
181 # https://github.com/Mbed-TLS/mbedtls/issues/9590
182 'Config: PSA_WANT_KEY_TYPE_DH_KEY_PAIR_DERIVE',
183 'Config: PSA_WANT_KEY_TYPE_ECC_KEY_PAIR',
184 'Config: PSA_WANT_KEY_TYPE_RSA_KEY_PAIR',
185 'Config: PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_DERIVE',
186 ],
187 'test_suite_config.psa_combinations': [
188 # We don't test this unusual, but sensible configuration.
189 # https://github.com/Mbed-TLS/mbedtls/issues/9592
190 'Config: PSA_WANT_ALG_DETERMINSTIC_ECDSA without PSA_WANT_ALG_ECDSA',
191 ],
Gilles Peskineb0ec85d2024-09-17 18:33:29 +0200192 'test_suite_pkcs12': [
Gilles Peskine2fd25bb2024-09-17 19:46:18 +0200193 # We never test with CBC/PKCS5/PKCS12 enabled but
194 # PKCS7 padding disabled.
Gilles Peskineb0ec85d2024-09-17 18:33:29 +0200195 # https://github.com/Mbed-TLS/mbedtls/issues/9580
196 'PBE Decrypt, (Invalid padding & PKCS7 padding disabled)',
197 'PBE Encrypt, pad = 8 (PKCS7 padding disabled)',
198 ],
199 'test_suite_pkcs5': [
Gilles Peskine2fd25bb2024-09-17 19:46:18 +0200200 # We never test with CBC/PKCS5/PKCS12 enabled but
201 # PKCS7 padding disabled.
Gilles Peskineb0ec85d2024-09-17 18:33:29 +0200202 # https://github.com/Mbed-TLS/mbedtls/issues/9580
203 'PBES2 Decrypt (Invalid padding & PKCS7 padding disabled)',
204 'PBES2 Encrypt, pad=6 (PKCS7 padding disabled)',
205 'PBES2 Encrypt, pad=8 (PKCS7 padding disabled)',
206 ],
Gilles Peskine2a71fac2024-09-17 15:07:22 +0200207 'test_suite_psa_crypto_generate_key.generated': [
Gilles Peskine5872c0d2024-09-17 17:15:29 +0200208 # Ignore mechanisms that are not implemented, except
209 # for public keys for which we always test that
210 # psa_generate_key() returns PSA_ERROR_INVALID_ARGUMENT
211 # regardless of whether the specific key type is supported.
212 _has_word_re((mech
213 for mech in _PSA_MECHANISMS_NOT_IMPLEMENTED
214 if not mech.startswith('ECC_PUB')),
215 exclude=r'ECC_PUB'),
Gilles Peskine2a71fac2024-09-17 15:07:22 +0200216 ],
Gilles Peskineb0ec85d2024-09-17 18:33:29 +0200217 'test_suite_psa_crypto_metadata': [
218 # Algorithms declared but not supported.
219 # https://github.com/Mbed-TLS/mbedtls/issues/9579
220 'Asymmetric signature: Ed25519ph',
221 'Asymmetric signature: Ed448ph',
222 'Asymmetric signature: pure EdDSA',
223 'Cipher: XTS',
224 'MAC: CBC_MAC-3DES',
225 'MAC: CBC_MAC-AES-128',
226 'MAC: CBC_MAC-AES-192',
227 'MAC: CBC_MAC-AES-256',
228 ],
Gilles Peskine2a71fac2024-09-17 15:07:22 +0200229 'test_suite_psa_crypto_not_supported.generated': [
Gilles Peskineab5cc9b2024-09-17 17:57:11 +0200230 # It is a bug that not-supported test cases aren't getting
231 # run for never-implemented key types.
232 # https://github.com/Mbed-TLS/mbedtls/issues/7915
Gilles Peskine2a71fac2024-09-17 15:07:22 +0200233 PSA_MECHANISM_NOT_IMPLEMENTED_SEARCH_RE,
Gilles Peskine5e3ed3f2024-10-11 12:00:44 +0200234 # We never test with DH key support disabled but support
Gilles Peskineab5cc9b2024-09-17 17:57:11 +0200235 # for a DH group enabled. The dependencies of these test
236 # cases don't really make sense.
237 # https://github.com/Mbed-TLS/mbedtls/issues/9574
238 re.compile(r'PSA \w+ DH_.*type not supported'),
239 # We only test partial support for DH with the 2048-bit group
240 # enabled and the other groups disabled.
241 # https://github.com/Mbed-TLS/mbedtls/issues/9575
242 'PSA generate DH_KEY_PAIR(RFC7919) 2048-bit group not supported',
243 'PSA import DH_KEY_PAIR(RFC7919) 2048-bit group not supported',
244 'PSA import DH_PUBLIC_KEY(RFC7919) 2048-bit group not supported',
Gilles Peskine2a71fac2024-09-17 15:07:22 +0200245 ],
246 'test_suite_psa_crypto_op_fail.generated': [
Gilles Peskine5872c0d2024-09-17 17:15:29 +0200247 # Ignore mechanisms that are not implemented, except
248 # for test cases that assume the mechanism is not supported.
249 _has_word_re(_PSA_MECHANISMS_NOT_IMPLEMENTED,
250 exclude=(r'.*: !(?:' +
251 r'|'.join(_PSA_MECHANISMS_NOT_IMPLEMENTED) +
252 r')\b')),
Gilles Peskineab5cc9b2024-09-17 17:57:11 +0200253 # Incorrect dependency generation. To be fixed as part of the
254 # resolution of https://github.com/Mbed-TLS/mbedtls/issues/9167
255 # by forward-porting the commit
256 # "PSA test case generation: dependency inference class: operation fail"
257 # from https://github.com/Mbed-TLS/mbedtls/pull/9025 .
258 re.compile(r'.* with (?:DH|ECC)_(?:KEY_PAIR|PUBLIC_KEY)\(.*'),
Gilles Peskineab5cc9b2024-09-17 17:57:11 +0200259 # We never test with TLS12_PRF or TLS12_PSK_TO_MS disabled
260 # but certain other things enabled.
261 # https://github.com/Mbed-TLS/mbedtls/issues/9577
262 re.compile(r'PSA key_derivation TLS12_PRF\(\w+\): !TLS12_PRF'),
263 re.compile(r'PSA key_derivation TLS12_PSK_TO_MS'
264 r'\((?!SHA_256|SHA_384|SHA_512)\w+\): !TLS12_PSK_TO_MS'),
265 'PSA key_derivation KEY_AGREEMENT(ECDH,TLS12_PRF(SHA_256)): !TLS12_PRF',
266 'PSA key_derivation KEY_AGREEMENT(ECDH,TLS12_PRF(SHA_384)): !TLS12_PRF',
267
268 # We never test with the HMAC algorithm enabled but the HMAC
269 # key type disabled. Those dependencies don't really make sense.
270 # https://github.com/Mbed-TLS/mbedtls/issues/9573
271 re.compile(r'.* !HMAC with HMAC'),
Gilles Peskine2a71fac2024-09-17 15:07:22 +0200272 ],
273 'test_suite_psa_crypto_storage_format.current': [
274 PSA_MECHANISM_NOT_IMPLEMENTED_SEARCH_RE,
275 ],
276 'test_suite_psa_crypto_storage_format.v0': [
277 PSA_MECHANISM_NOT_IMPLEMENTED_SEARCH_RE,
278 ],
Gilles Peskinede2316b2024-09-17 18:32:05 +0200279 'tls13-misc': [
280 # Disabled due to OpenSSL bug.
281 # https://github.com/openssl/openssl/issues/10714
282 'TLS 1.3 O->m: resumption',
283 # Disabled due to OpenSSL command line limitation.
284 # https://github.com/Mbed-TLS/mbedtls/issues/9582
285 'TLS 1.3 m->O: resumption with early data',
286 ],
Gilles Peskine2a71fac2024-09-17 15:07:22 +0200287 }
288
Gilles Peskine82b16722024-09-16 19:57:10 +0200289
Gilles Peskine9df375b2024-09-16 20:14:26 +0200290# The names that we give to classes derived from DriverVSReference do not
291# follow the usual naming convention, because it's more readable to use
292# underscores and parts of the configuration names. Also, these classes
293# are just there to specify some data, so they don't need repetitive
294# documentation.
295#pylint: disable=invalid-name,missing-class-docstring
296
Gilles Peskine082eade2024-10-03 18:42:37 +0200297class DriverVSReference_hash(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200298 REFERENCE = 'test_psa_crypto_config_reference_hash_use_psa'
299 DRIVER = 'test_psa_crypto_config_accel_hash_use_psa'
300 IGNORED_SUITES = [
301 'shax', 'mdx', # the software implementations that are being excluded
302 'md.psa', # purposefully depends on whether drivers are present
303 'psa_crypto_low_hash.generated', # testing the builtins
304 ]
305 IGNORED_TESTS = {
306 'test_suite_config': [
307 re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
308 ],
309 'test_suite_platform': [
310 # Incompatible with sanitizers (e.g. ASan). If the driver
311 # component uses a sanitizer but the reference component
312 # doesn't, we have a PASS vs SKIP mismatch.
313 'Check mbedtls_calloc overallocation',
314 ],
315 }
316
Gilles Peskine082eade2024-10-03 18:42:37 +0200317class DriverVSReference_hmac(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200318 REFERENCE = 'test_psa_crypto_config_reference_hmac'
319 DRIVER = 'test_psa_crypto_config_accel_hmac'
320 IGNORED_SUITES = [
321 # These suites require legacy hash support, which is disabled
322 # in the accelerated component.
323 'shax', 'mdx',
324 # This suite tests builtins directly, but these are missing
325 # in the accelerated case.
326 'psa_crypto_low_hash.generated',
327 ]
328 IGNORED_TESTS = {
329 'test_suite_config': [
330 re.compile(r'.*\bMBEDTLS_(MD5|RIPEMD160|SHA[0-9]+)_.*'),
331 re.compile(r'.*\bMBEDTLS_MD_C\b')
332 ],
333 'test_suite_md': [
334 # Builtin HMAC is not supported in the accelerate component.
335 re.compile('.*HMAC.*'),
336 # Following tests make use of functions which are not available
337 # when MD_C is disabled, as it happens in the accelerated
338 # test component.
339 re.compile('generic .* Hash file .*'),
340 'MD list',
341 ],
342 'test_suite_md.psa': [
343 # "legacy only" tests require hash algorithms to be NOT
344 # accelerated, but this of course false for the accelerated
345 # test component.
346 re.compile('PSA dispatch .* legacy only'),
347 ],
348 'test_suite_platform': [
349 # Incompatible with sanitizers (e.g. ASan). If the driver
350 # component uses a sanitizer but the reference component
351 # doesn't, we have a PASS vs SKIP mismatch.
352 'Check mbedtls_calloc overallocation',
353 ],
354 }
355
Gilles Peskine082eade2024-10-03 18:42:37 +0200356class DriverVSReference_cipher_aead_cmac(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200357 REFERENCE = 'test_psa_crypto_config_reference_cipher_aead_cmac'
358 DRIVER = 'test_psa_crypto_config_accel_cipher_aead_cmac'
359 # Modules replaced by drivers.
360 IGNORED_SUITES = [
361 # low-level (block/stream) cipher modules
362 'aes', 'aria', 'camellia', 'des', 'chacha20',
363 # AEAD modes and CMAC
364 'ccm', 'chachapoly', 'cmac', 'gcm',
365 # The Cipher abstraction layer
366 'cipher',
367 ]
368 IGNORED_TESTS = {
369 'test_suite_config': [
370 re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA|CHACHA20|DES)_.*'),
371 re.compile(r'.*\bMBEDTLS_(CCM|CHACHAPOLY|CMAC|GCM)_.*'),
372 re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'),
373 re.compile(r'.*\bMBEDTLS_CIPHER_.*'),
374 ],
375 # PEM decryption is not supported so far.
376 # The rest of PEM (write, unencrypted read) works though.
377 'test_suite_pem': [
378 re.compile(r'PEM read .*(AES|DES|\bencrypt).*'),
379 ],
380 'test_suite_platform': [
381 # Incompatible with sanitizers (e.g. ASan). If the driver
382 # component uses a sanitizer but the reference component
383 # doesn't, we have a PASS vs SKIP mismatch.
384 'Check mbedtls_calloc overallocation',
385 ],
386 # Following tests depend on AES_C/DES_C but are not about
387 # them really, just need to know some error code is there.
388 'test_suite_error': [
389 'Low and high error',
390 'Single low error'
391 ],
392 # Similar to test_suite_error above.
393 'test_suite_version': [
394 'Check for MBEDTLS_AES_C when already present',
395 ],
396 # The en/decryption part of PKCS#12 is not supported so far.
397 # The rest of PKCS#12 (key derivation) works though.
398 'test_suite_pkcs12': [
399 re.compile(r'PBE Encrypt, .*'),
400 re.compile(r'PBE Decrypt, .*'),
401 ],
402 # The en/decryption part of PKCS#5 is not supported so far.
403 # The rest of PKCS#5 (PBKDF2) works though.
404 'test_suite_pkcs5': [
405 re.compile(r'PBES2 Encrypt, .*'),
406 re.compile(r'PBES2 Decrypt .*'),
407 ],
408 # Encrypted keys are not supported so far.
409 # pylint: disable=line-too-long
410 'test_suite_pkparse': [
411 'Key ASN1 (Encrypted key PKCS12, trailing garbage data)',
412 'Key ASN1 (Encrypted key PKCS5, trailing garbage data)',
413 re.compile(r'Parse (RSA|EC) Key .*\(.* ([Ee]ncrypted|password).*\)'),
414 ],
415 # Encrypted keys are not supported so far.
416 'ssl-opt': [
417 'TLS: password protected server key',
418 'TLS: password protected client key',
419 'TLS: password protected server key, two certificates',
420 ],
421 }
422
Gilles Peskine082eade2024-10-03 18:42:37 +0200423class DriverVSReference_ecp_light_only(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200424 REFERENCE = 'test_psa_crypto_config_reference_ecc_ecp_light_only'
425 DRIVER = 'test_psa_crypto_config_accel_ecc_ecp_light_only'
426 IGNORED_SUITES = [
427 # Modules replaced by drivers
428 'ecdsa', 'ecdh', 'ecjpake',
429 ]
430 IGNORED_TESTS = {
431 'test_suite_config': [
432 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
433 ],
434 'test_suite_platform': [
435 # Incompatible with sanitizers (e.g. ASan). If the driver
436 # component uses a sanitizer but the reference component
437 # doesn't, we have a PASS vs SKIP mismatch.
438 'Check mbedtls_calloc overallocation',
439 ],
440 # This test wants a legacy function that takes f_rng, p_rng
441 # arguments, and uses legacy ECDSA for that. The test is
442 # really about the wrapper around the PSA RNG, not ECDSA.
443 'test_suite_random': [
444 'PSA classic wrapper: ECDSA signature (SECP256R1)',
445 ],
446 # In the accelerated test ECP_C is not set (only ECP_LIGHT is)
447 # so we must ignore disparities in the tests for which ECP_C
448 # is required.
449 'test_suite_ecp': [
450 re.compile(r'ECP check public-private .*'),
451 re.compile(r'ECP calculate public: .*'),
452 re.compile(r'ECP gen keypair .*'),
453 re.compile(r'ECP point muladd .*'),
454 re.compile(r'ECP point multiplication .*'),
455 re.compile(r'ECP test vectors .*'),
456 ],
457 'test_suite_ssl': [
458 # This deprecated function is only present when ECP_C is On.
459 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
460 ],
461 }
462
Gilles Peskine082eade2024-10-03 18:42:37 +0200463class DriverVSReference_no_ecp_at_all(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200464 REFERENCE = 'test_psa_crypto_config_reference_ecc_no_ecp_at_all'
465 DRIVER = 'test_psa_crypto_config_accel_ecc_no_ecp_at_all'
466 IGNORED_SUITES = [
467 # Modules replaced by drivers
468 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
469 ]
470 IGNORED_TESTS = {
471 'test_suite_config': [
472 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
473 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
474 ],
475 'test_suite_platform': [
476 # Incompatible with sanitizers (e.g. ASan). If the driver
477 # component uses a sanitizer but the reference component
478 # doesn't, we have a PASS vs SKIP mismatch.
479 'Check mbedtls_calloc overallocation',
480 ],
481 # See ecp_light_only
482 'test_suite_random': [
483 'PSA classic wrapper: ECDSA signature (SECP256R1)',
484 ],
485 'test_suite_pkparse': [
486 # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED
487 # is automatically enabled in build_info.h (backward compatibility)
488 # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a
489 # consequence compressed points are supported in the reference
490 # component but not in the accelerated one, so they should be skipped
491 # while checking driver's coverage.
492 re.compile(r'Parse EC Key .*compressed\)'),
493 re.compile(r'Parse Public EC Key .*compressed\)'),
494 ],
495 # See ecp_light_only
496 'test_suite_ssl': [
497 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
498 ],
499 }
500
Gilles Peskine082eade2024-10-03 18:42:37 +0200501class DriverVSReference_ecc_no_bignum(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200502 REFERENCE = 'test_psa_crypto_config_reference_ecc_no_bignum'
503 DRIVER = 'test_psa_crypto_config_accel_ecc_no_bignum'
504 IGNORED_SUITES = [
505 # Modules replaced by drivers
506 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
507 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
508 'bignum.generated', 'bignum.misc',
509 ]
510 IGNORED_TESTS = {
511 'test_suite_config': [
512 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
513 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
514 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
515 ],
516 'test_suite_platform': [
517 # Incompatible with sanitizers (e.g. ASan). If the driver
518 # component uses a sanitizer but the reference component
519 # doesn't, we have a PASS vs SKIP mismatch.
520 'Check mbedtls_calloc overallocation',
521 ],
522 # See ecp_light_only
523 'test_suite_random': [
524 'PSA classic wrapper: ECDSA signature (SECP256R1)',
525 ],
526 # See no_ecp_at_all
527 'test_suite_pkparse': [
528 re.compile(r'Parse EC Key .*compressed\)'),
529 re.compile(r'Parse Public EC Key .*compressed\)'),
530 ],
531 'test_suite_asn1parse': [
532 'INTEGER too large for mpi',
533 ],
534 'test_suite_asn1write': [
535 re.compile(r'ASN.1 Write mpi.*'),
536 ],
537 'test_suite_debug': [
538 re.compile(r'Debug print mbedtls_mpi.*'),
539 ],
540 # See ecp_light_only
541 'test_suite_ssl': [
542 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
543 ],
544 }
545
Gilles Peskine082eade2024-10-03 18:42:37 +0200546class DriverVSReference_ecc_ffdh_no_bignum(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200547 REFERENCE = 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum'
548 DRIVER = 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum'
549 IGNORED_SUITES = [
550 # Modules replaced by drivers
551 'ecp', 'ecdsa', 'ecdh', 'ecjpake', 'dhm',
552 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
553 'bignum.generated', 'bignum.misc',
554 ]
555 IGNORED_TESTS = {
556 'ssl-opt': [
557 # DHE support in TLS 1.2 requires built-in MBEDTLS_DHM_C
558 # (because it needs custom groups, which PSA does not
559 # provide), even with MBEDTLS_USE_PSA_CRYPTO.
560 re.compile(r'PSK callback:.*\bdhe-psk\b.*'),
561 ],
562 'test_suite_config': [
563 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
564 re.compile(r'.*\bMBEDTLS_DHM_C\b.*'),
565 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECJPAKE|ECP)_.*'),
566 re.compile(r'.*\bMBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED\b.*'),
567 re.compile(r'.*\bMBEDTLS_PK_PARSE_EC_COMPRESSED\b.*'),
568 ],
569 'test_suite_platform': [
570 # Incompatible with sanitizers (e.g. ASan). If the driver
571 # component uses a sanitizer but the reference component
572 # doesn't, we have a PASS vs SKIP mismatch.
573 'Check mbedtls_calloc overallocation',
574 ],
575 # See ecp_light_only
576 'test_suite_random': [
577 'PSA classic wrapper: ECDSA signature (SECP256R1)',
578 ],
579 # See no_ecp_at_all
580 'test_suite_pkparse': [
581 re.compile(r'Parse EC Key .*compressed\)'),
582 re.compile(r'Parse Public EC Key .*compressed\)'),
583 ],
584 'test_suite_asn1parse': [
585 'INTEGER too large for mpi',
586 ],
587 'test_suite_asn1write': [
588 re.compile(r'ASN.1 Write mpi.*'),
589 ],
590 'test_suite_debug': [
591 re.compile(r'Debug print mbedtls_mpi.*'),
592 ],
593 # See ecp_light_only
594 'test_suite_ssl': [
595 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
596 ],
597 }
598
Gilles Peskine082eade2024-10-03 18:42:37 +0200599class DriverVSReference_ffdh_alg(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200600 REFERENCE = 'test_psa_crypto_config_reference_ffdh'
601 DRIVER = 'test_psa_crypto_config_accel_ffdh'
602 IGNORED_SUITES = ['dhm']
603 IGNORED_TESTS = {
604 'test_suite_config': [
605 re.compile(r'.*\bMBEDTLS_DHM_C\b.*'),
606 ],
607 'test_suite_platform': [
608 # Incompatible with sanitizers (e.g. ASan). If the driver
609 # component uses a sanitizer but the reference component
610 # doesn't, we have a PASS vs SKIP mismatch.
611 'Check mbedtls_calloc overallocation',
612 ],
613 }
614
Gilles Peskine082eade2024-10-03 18:42:37 +0200615class DriverVSReference_tfm_config(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200616 REFERENCE = 'test_tfm_config_no_p256m'
617 DRIVER = 'test_tfm_config_p256m_driver_accel_ec'
618 IGNORED_SUITES = [
619 # Modules replaced by drivers
620 'asn1parse', 'asn1write',
621 'ecp', 'ecdsa', 'ecdh', 'ecjpake',
622 'bignum_core', 'bignum_random', 'bignum_mod', 'bignum_mod_raw',
623 'bignum.generated', 'bignum.misc',
624 ]
625 IGNORED_TESTS = {
626 'test_suite_config': [
627 re.compile(r'.*\bMBEDTLS_BIGNUM_C\b.*'),
628 re.compile(r'.*\bMBEDTLS_(ASN1\w+)_C\b.*'),
629 re.compile(r'.*\bMBEDTLS_(ECDH|ECDSA|ECP)_.*'),
630 re.compile(r'.*\bMBEDTLS_PSA_P256M_DRIVER_ENABLED\b.*')
631 ],
632 'test_suite_config.crypto_combinations': [
633 'Config: ECC: Weierstrass curves only',
634 ],
635 'test_suite_platform': [
636 # Incompatible with sanitizers (e.g. ASan). If the driver
637 # component uses a sanitizer but the reference component
638 # doesn't, we have a PASS vs SKIP mismatch.
639 'Check mbedtls_calloc overallocation',
640 ],
641 # See ecp_light_only
642 'test_suite_random': [
643 'PSA classic wrapper: ECDSA signature (SECP256R1)',
644 ],
645 }
646
Gilles Peskine082eade2024-10-03 18:42:37 +0200647class DriverVSReference_rsa(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200648 REFERENCE = 'test_psa_crypto_config_reference_rsa_crypto'
649 DRIVER = 'test_psa_crypto_config_accel_rsa_crypto'
650 IGNORED_SUITES = [
651 # Modules replaced by drivers.
652 'rsa', 'pkcs1_v15', 'pkcs1_v21',
653 # We temporarily don't care about PK stuff.
654 'pk', 'pkwrite', 'pkparse'
655 ]
656 IGNORED_TESTS = {
657 'test_suite_config': [
658 re.compile(r'.*\bMBEDTLS_(PKCS1|RSA)_.*'),
659 re.compile(r'.*\bMBEDTLS_GENPRIME\b.*')
660 ],
661 'test_suite_platform': [
662 # Incompatible with sanitizers (e.g. ASan). If the driver
663 # component uses a sanitizer but the reference component
664 # doesn't, we have a PASS vs SKIP mismatch.
665 'Check mbedtls_calloc overallocation',
666 ],
667 # Following tests depend on RSA_C but are not about
668 # them really, just need to know some error code is there.
669 'test_suite_error': [
670 'Low and high error',
671 'Single high error'
672 ],
673 # Constant time operations only used for PKCS1_V15
674 'test_suite_constant_time': [
675 re.compile(r'mbedtls_ct_zeroize_if .*'),
676 re.compile(r'mbedtls_ct_memmove_left .*')
677 ],
678 'test_suite_psa_crypto': [
679 # We don't support generate_key_custom entry points
680 # in drivers yet.
681 re.compile(r'PSA generate key custom: RSA, e=.*'),
682 re.compile(r'PSA generate key ext: RSA, e=.*'),
683 ],
684 }
685
Gilles Peskine082eade2024-10-03 18:42:37 +0200686class DriverVSReference_block_cipher_dispatch(outcome_analysis.DriverVSReference):
Gilles Peskine9df375b2024-09-16 20:14:26 +0200687 REFERENCE = 'test_full_block_cipher_legacy_dispatch'
688 DRIVER = 'test_full_block_cipher_psa_dispatch'
689 IGNORED_SUITES = [
690 # Skipped in the accelerated component
691 'aes', 'aria', 'camellia',
692 # These require AES_C, ARIA_C or CAMELLIA_C to be enabled in
693 # order for the cipher module (actually cipher_wrapper) to work
694 # properly. However these symbols are disabled in the accelerated
695 # component so we ignore them.
696 'cipher.ccm', 'cipher.gcm', 'cipher.aes', 'cipher.aria',
697 'cipher.camellia',
698 ]
699 IGNORED_TESTS = {
700 'test_suite_config': [
701 re.compile(r'.*\bMBEDTLS_(AES|ARIA|CAMELLIA)_.*'),
702 re.compile(r'.*\bMBEDTLS_AES(\w+)_C\b.*'),
703 ],
704 'test_suite_cmac': [
705 # Following tests require AES_C/ARIA_C/CAMELLIA_C to be enabled,
706 # but these are not available in the accelerated component.
707 'CMAC null arguments',
708 re.compile('CMAC.* (AES|ARIA|Camellia).*'),
709 ],
710 'test_suite_cipher.padding': [
711 # Following tests require AES_C/CAMELLIA_C to be enabled,
712 # but these are not available in the accelerated component.
713 re.compile('Set( non-existent)? padding with (AES|CAMELLIA).*'),
714 ],
715 'test_suite_pkcs5': [
716 # The AES part of PKCS#5 PBES2 is not yet supported.
717 # The rest of PKCS#5 (PBKDF2) works, though.
718 re.compile(r'PBES2 .* AES-.*')
719 ],
720 'test_suite_pkparse': [
721 # PEM (called by pkparse) requires AES_C in order to decrypt
722 # the key, but this is not available in the accelerated
723 # component.
724 re.compile('Parse RSA Key.*(password|AES-).*'),
725 ],
726 'test_suite_pem': [
727 # Following tests require AES_C, but this is diabled in the
728 # accelerated component.
729 re.compile('PEM read .*AES.*'),
730 'PEM read (unknown encryption algorithm)',
731 ],
732 'test_suite_error': [
733 # Following tests depend on AES_C but are not about them
734 # really, just need to know some error code is there.
735 'Single low error',
736 'Low and high error',
737 ],
738 'test_suite_version': [
739 # Similar to test_suite_error above.
740 'Check for MBEDTLS_AES_C when already present',
741 ],
742 'test_suite_platform': [
743 # Incompatible with sanitizers (e.g. ASan). If the driver
744 # component uses a sanitizer but the reference component
745 # doesn't, we have a PASS vs SKIP mismatch.
746 'Check mbedtls_calloc overallocation',
747 ],
748 }
749
750#pylint: enable=invalid-name,missing-class-docstring
751
752
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100753# List of tasks with a function that can handle this task and additional arguments if required
Valerio Settidfd7ca62023-10-09 16:30:11 +0200754KNOWN_TASKS = {
Gilles Peskinef646dbf2024-09-16 19:15:29 +0200755 'analyze_coverage': CoverageTask,
Gilles Peskine9df375b2024-09-16 20:14:26 +0200756 'analyze_driver_vs_reference_hash': DriverVSReference_hash,
757 'analyze_driver_vs_reference_hmac': DriverVSReference_hmac,
758 'analyze_driver_vs_reference_cipher_aead_cmac': DriverVSReference_cipher_aead_cmac,
759 'analyze_driver_vs_reference_ecp_light_only': DriverVSReference_ecp_light_only,
760 'analyze_driver_vs_reference_no_ecp_at_all': DriverVSReference_no_ecp_at_all,
761 'analyze_driver_vs_reference_ecc_no_bignum': DriverVSReference_ecc_no_bignum,
762 'analyze_driver_vs_reference_ecc_ffdh_no_bignum': DriverVSReference_ecc_ffdh_no_bignum,
763 'analyze_driver_vs_reference_ffdh_alg': DriverVSReference_ffdh_alg,
764 'analyze_driver_vs_reference_tfm_config': DriverVSReference_tfm_config,
765 'analyze_driver_vs_reference_rsa': DriverVSReference_rsa,
766 'analyze_block_cipher_dispatch': DriverVSReference_block_cipher_dispatch,
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200767}
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200768
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200769if __name__ == '__main__':
Gilles Peskine082eade2024-10-03 18:42:37 +0200770 outcome_analysis.main(KNOWN_TASKS)