blob: 95f0cc6973888b89c463c6dd3fe8fd0490a31a5f [file] [log] [blame]
Valerio Settif075e472023-10-17 11:03:16 +02001 #!/usr/bin/env python3
Gilles Peskine15c2cbf2020-06-25 18:36:28 +02002
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
9import argparse
10import sys
11import traceback
Przemek Stekiel85c54ea2022-11-17 11:50:23 +010012import re
Valerio Settia2663322023-03-24 08:20:18 +010013import subprocess
14import os
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020015
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020016import check_test_cases
17
Valerio Settif075e472023-10-17 11:03:16 +020018class Results:
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020019 """Process analysis results."""
20
21 def __init__(self):
22 self.error_count = 0
23 self.warning_count = 0
Valerio Settiaaef0bc2023-10-10 09:42:13 +020024
25 def info(self, fmt, *args, **kwargs):
Valerio Setti3f339892023-10-17 10:42:11 +020026 self.print_line('Info: ' + fmt, *args, **kwargs)
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020027
28 def error(self, fmt, *args, **kwargs):
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020029 self.error_count += 1
Valerio Setti3f339892023-10-17 10:42:11 +020030 self.print_line('Error: ' + fmt, *args, **kwargs)
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020031
32 def warning(self, fmt, *args, **kwargs):
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020033 self.warning_count += 1
Valerio Setti3f339892023-10-17 10:42:11 +020034 self.print_line('Warning: ' + fmt, *args, **kwargs)
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020035
Valerio Setti3f339892023-10-17 10:42:11 +020036 @staticmethod
37 def print_line(fmt, *args, **kwargs):
38 sys.stderr.write(fmt, *args, **kwargs)
Valerio Settiaaef0bc2023-10-10 09:42:13 +020039
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020040class TestCaseOutcomes:
41 """The outcomes of one test case across many configurations."""
42 # pylint: disable=too-few-public-methods
43
44 def __init__(self):
Gilles Peskine3d863f22020-06-26 13:02:30 +020045 # Collect a list of witnesses of the test case succeeding or failing.
46 # Currently we don't do anything with witnesses except count them.
47 # The format of a witness is determined by the read_outcome_file
48 # function; it's the platform and configuration joined by ';'.
Gilles Peskine15c2cbf2020-06-25 18:36:28 +020049 self.successes = []
50 self.failures = []
51
52 def hits(self):
53 """Return the number of times a test case has been run.
54
55 This includes passes and failures, but not skips.
56 """
57 return len(self.successes) + len(self.failures)
58
Valerio Settif075e472023-10-17 11:03:16 +020059def execute_reference_driver_tests(results: Results, ref_component, driver_component, \
60 outcome_file) -> Results:
Valerio Setti22992a02023-03-29 11:15:28 +020061 """Run the tests specified in ref_component and driver_component. Results
62 are stored in the output_file and they will be used for the following
Valerio Settia2663322023-03-24 08:20:18 +010063 coverage analysis"""
64 # If the outcome file already exists, we assume that the user wants to
65 # perform the comparison analysis again without repeating the tests.
66 if os.path.exists(outcome_file):
Valerio Settif075e472023-10-17 11:03:16 +020067 results.info("Outcome file (" + outcome_file + ") already exists. " + \
Valerio Settiaaef0bc2023-10-10 09:42:13 +020068 "Tests will be skipped.")
Valerio Settif075e472023-10-17 11:03:16 +020069 return results
Valerio Settia2663322023-03-24 08:20:18 +010070
71 shell_command = "tests/scripts/all.sh --outcome-file " + outcome_file + \
72 " " + ref_component + " " + driver_component
Valerio Settif075e472023-10-17 11:03:16 +020073 results.info("Running: " + shell_command)
Valerio Settia2663322023-03-24 08:20:18 +010074 ret_val = subprocess.run(shell_command.split(), check=False).returncode
75
76 if ret_val != 0:
Valerio Settif075e472023-10-17 11:03:16 +020077 results.error("failed to run reference/driver components")
Valerio Settiaaef0bc2023-10-10 09:42:13 +020078
Valerio Settif075e472023-10-17 11:03:16 +020079 return results
Valerio Settia2663322023-03-24 08:20:18 +010080
Tomás Gonzálezb401e112023-08-11 15:22:04 +010081def analyze_coverage(results, outcomes, allow_list, full_coverage):
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020082 """Check that all available test cases are executed at least once."""
Gilles Peskine686c2922022-01-07 15:58:38 +010083 available = check_test_cases.collect_available_test_cases()
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020084 for key in available:
85 hits = outcomes[key].hits() if key in outcomes else 0
Tomás González07bdcc22023-08-11 14:59:03 +010086 if hits == 0 and key not in allow_list:
Tomás Gonzálezb401e112023-08-11 15:22:04 +010087 if full_coverage:
88 results.error('Test case not executed: {}', key)
89 else:
90 results.warning('Test case not executed: {}', key)
Tomás González07bdcc22023-08-11 14:59:03 +010091 elif hits != 0 and key in allow_list:
92 # Test Case should be removed from the allow list.
Tomás González7ebb18f2023-08-22 09:40:23 +010093 if full_coverage:
Tomás Gonzáleza0631442023-08-22 12:17:57 +010094 results.error('Allow listed test case was executed: {}', key)
Tomás González7ebb18f2023-08-22 09:40:23 +010095 else:
96 results.warning('Allow listed test case was executed: {}', key)
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020097
Valerio Settif075e472023-10-17 11:03:16 +020098def analyze_driver_vs_reference(results: Results, outcomes,
Valerio Settiaaef0bc2023-10-10 09:42:13 +020099 component_ref, component_driver,
Valerio Setti3002c992023-01-18 17:28:36 +0100100 ignored_suites, ignored_test=None):
Przemek Stekiel4e955902022-10-21 13:42:08 +0200101 """Check that all tests executed in the reference component are also
102 executed in the corresponding driver component.
Valerio Setti3002c992023-01-18 17:28:36 +0100103 Skip:
104 - full test suites provided in ignored_suites list
105 - only some specific test inside a test suite, for which the corresponding
106 output string is provided
Przemek Stekiel4e955902022-10-21 13:42:08 +0200107 """
Przemek Stekiel4e955902022-10-21 13:42:08 +0200108 available = check_test_cases.collect_available_test_cases()
Przemek Stekiel4e955902022-10-21 13:42:08 +0200109
110 for key in available:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200111 # Continue if test was not executed by any component
112 hits = outcomes[key].hits() if key in outcomes else 0
Przemek Stekielc86dedf2022-10-24 09:16:04 +0200113 if hits == 0:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200114 continue
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100115 # Skip ignored test suites
116 full_test_suite = key.split(';')[0] # retrieve full test suite name
117 test_string = key.split(';')[1] # retrieve the text string of this test
118 test_suite = full_test_suite.split('.')[0] # retrieve main part of test suite name
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100119 if test_suite in ignored_suites or full_test_suite in ignored_suites:
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100120 continue
Valerio Setti3002c992023-01-18 17:28:36 +0100121 if ((full_test_suite in ignored_test) and
122 (test_string in ignored_test[full_test_suite])):
123 continue
Przemek Stekiel4e955902022-10-21 13:42:08 +0200124 # Search for tests that run in reference component and not in driver component
125 driver_test_passed = False
126 reference_test_passed = False
127 for entry in outcomes[key].successes:
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100128 if component_driver in entry:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200129 driver_test_passed = True
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100130 if component_ref in entry:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200131 reference_test_passed = True
Manuel Pégourié-Gonnardc6967d22022-12-30 13:40:34 +0100132 if(reference_test_passed and not driver_test_passed):
Valerio Settif075e472023-10-17 11:03:16 +0200133 results.error(key)
Przemek Stekiel4e955902022-10-21 13:42:08 +0200134
Valerio Settif075e472023-10-17 11:03:16 +0200135 return results
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200136
Valerio Settif075e472023-10-17 11:03:16 +0200137def analyze_outcomes(results: Results, outcomes, args) -> Results:
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200138 """Run all analyses on the given outcome collection."""
Valerio Settif075e472023-10-17 11:03:16 +0200139 analyze_coverage(results, outcomes, args['allow_list'],
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100140 args['full_coverage'])
Valerio Settif075e472023-10-17 11:03:16 +0200141 return results
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200142
143def read_outcome_file(outcome_file):
144 """Parse an outcome file and return an outcome collection.
145
146An outcome collection is a dictionary mapping keys to TestCaseOutcomes objects.
147The keys are the test suite name and the test case description, separated
148by a semicolon.
149"""
150 outcomes = {}
151 with open(outcome_file, 'r', encoding='utf-8') as input_file:
152 for line in input_file:
153 (platform, config, suite, case, result, _cause) = line.split(';')
154 key = ';'.join([suite, case])
155 setup = ';'.join([platform, config])
156 if key not in outcomes:
157 outcomes[key] = TestCaseOutcomes()
158 if result == 'PASS':
159 outcomes[key].successes.append(setup)
160 elif result == 'FAIL':
161 outcomes[key].failures.append(setup)
162 return outcomes
163
Valerio Settif075e472023-10-17 11:03:16 +0200164def do_analyze_coverage(results: Results, outcome_file, args) -> Results:
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100165 """Perform coverage analysis."""
Valerio Settif075e472023-10-17 11:03:16 +0200166 results.info("\n*** Analyze coverage ***\n")
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200167 outcomes = read_outcome_file(outcome_file)
Valerio Settif075e472023-10-17 11:03:16 +0200168 results = analyze_outcomes(results, outcomes, args)
169 return results
Przemek Stekiel4e955902022-10-21 13:42:08 +0200170
Valerio Settif075e472023-10-17 11:03:16 +0200171def do_analyze_driver_vs_reference(results: Results, outcome_file, args) -> Results:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200172 """Perform driver vs reference analyze."""
Valerio Settif075e472023-10-17 11:03:16 +0200173 results.info("\n*** Analyze driver {} vs reference {} ***\n".format(
Valerio Settib0c618e2023-10-16 14:19:49 +0200174 args['component_driver'], args['component_ref']))
175
Valerio Settif075e472023-10-17 11:03:16 +0200176 results = execute_reference_driver_tests(results, args['component_ref'], \
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200177 args['component_driver'], outcome_file)
Valerio Settia2663322023-03-24 08:20:18 +0100178
Valerio Setti3002c992023-01-18 17:28:36 +0100179 ignored_suites = ['test_suite_' + x for x in args['ignored_suites']]
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100180
Przemek Stekiel4e955902022-10-21 13:42:08 +0200181 outcomes = read_outcome_file(outcome_file)
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200182
Valerio Settif075e472023-10-17 11:03:16 +0200183 results = analyze_driver_vs_reference(results, outcomes,
184 args['component_ref'], args['component_driver'],
185 ignored_suites, args['ignored_tests'])
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200186
Valerio Settif075e472023-10-17 11:03:16 +0200187 return results
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200188
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100189# List of tasks with a function that can handle this task and additional arguments if required
Valerio Settidfd7ca62023-10-09 16:30:11 +0200190KNOWN_TASKS = {
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200191 'analyze_coverage': {
192 'test_function': do_analyze_coverage,
Tomás González07bdcc22023-08-11 14:59:03 +0100193 'args': {
Tomás González358c6c62023-08-14 15:43:46 +0100194 'allow_list': [
Tomás González50223112023-08-22 09:52:06 +0100195 # Algorithm not supported yet
196 'test_suite_psa_crypto_metadata;Asymmetric signature: pure EdDSA',
197 # Algorithm not supported yet
198 'test_suite_psa_crypto_metadata;Cipher: XTS',
Tomás Gonzálezd43cab32023-08-24 09:12:40 +0100199 ],
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100200 'full_coverage': False,
Tomás González07bdcc22023-08-11 14:59:03 +0100201 }
Tomás Gonzálezd43cab32023-08-24 09:12:40 +0100202 },
Valerio Settia2663322023-03-24 08:20:18 +0100203 # There are 2 options to use analyze_driver_vs_reference_xxx locally:
204 # 1. Run tests and then analysis:
205 # - tests/scripts/all.sh --outcome-file "$PWD/out.csv" <component_ref> <component_driver>
206 # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
207 # 2. Let this script run both automatically:
208 # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200209 'analyze_driver_vs_reference_hash': {
210 'test_function': do_analyze_driver_vs_reference,
211 'args': {
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100212 'component_ref': 'test_psa_crypto_config_reference_hash_use_psa',
213 'component_driver': 'test_psa_crypto_config_accel_hash_use_psa',
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +0100214 'ignored_suites': [
215 'shax', 'mdx', # the software implementations that are being excluded
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100216 'md.psa', # purposefully depends on whether drivers are present
Gilles Peskine35b49c42023-10-04 12:28:41 +0200217 'psa_crypto_low_hash.generated', # testing the builtins
Valerio Setti3002c992023-01-18 17:28:36 +0100218 ],
219 'ignored_tests': {
220 }
221 }
222 },
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200223 'analyze_driver_vs_reference_ecp_light_only': {
Valerio Setti42d5f192023-03-20 13:54:41 +0100224 'test_function': do_analyze_driver_vs_reference,
225 'args': {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200226 'component_ref': 'test_psa_crypto_config_reference_ecc_ecp_light_only',
227 'component_driver': 'test_psa_crypto_config_accel_ecc_ecp_light_only',
Valerio Setti42d5f192023-03-20 13:54:41 +0100228 'ignored_suites': [
229 'ecdsa',
230 'ecdh',
231 'ecjpake',
232 ],
233 'ignored_tests': {
234 'test_suite_random': [
235 'PSA classic wrapper: ECDSA signature (SECP256R1)',
236 ],
Valerio Setti0c477d32023-04-07 15:54:20 +0200237 # In the accelerated test ECP_C is not set (only ECP_LIGHT is)
238 # so we must ignore disparities in the tests for which ECP_C
239 # is required.
240 'test_suite_ecp': [
241 'ECP check public-private #1 (OK)',
242 'ECP check public-private #2 (group none)',
243 'ECP check public-private #3 (group mismatch)',
244 'ECP check public-private #4 (Qx mismatch)',
245 'ECP check public-private #5 (Qy mismatch)',
246 'ECP check public-private #6 (wrong Qx)',
247 'ECP check public-private #7 (wrong Qy)',
248 'ECP gen keypair [#1]',
249 'ECP gen keypair [#2]',
250 'ECP gen keypair [#3]',
251 'ECP gen keypair wrapper',
252 'ECP point muladd secp256r1 #1',
253 'ECP point muladd secp256r1 #2',
254 'ECP point multiplication Curve25519 (element of order 2: origin) #3',
255 'ECP point multiplication Curve25519 (element of order 4: 1) #4',
256 'ECP point multiplication Curve25519 (element of order 8) #5',
257 'ECP point multiplication Curve25519 (normalized) #1',
258 'ECP point multiplication Curve25519 (not normalized) #2',
259 'ECP point multiplication rng fail Curve25519',
260 'ECP point multiplication rng fail secp256r1',
261 'ECP test vectors Curve25519',
262 'ECP test vectors Curve448 (RFC 7748 6.2, after decodeUCoordinate)',
263 'ECP test vectors brainpoolP256r1 rfc 7027',
264 'ECP test vectors brainpoolP384r1 rfc 7027',
265 'ECP test vectors brainpoolP512r1 rfc 7027',
266 'ECP test vectors secp192k1',
267 'ECP test vectors secp192r1 rfc 5114',
268 'ECP test vectors secp224k1',
269 'ECP test vectors secp224r1 rfc 5114',
270 'ECP test vectors secp256k1',
271 'ECP test vectors secp256r1 rfc 5114',
272 'ECP test vectors secp384r1 rfc 5114',
273 'ECP test vectors secp521r1 rfc 5114',
Valerio Settie50a75f2023-05-19 17:43:06 +0200274 ],
Valerio Setti482a0b92023-08-18 15:55:10 +0200275 'test_suite_psa_crypto': [
276 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
277 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
278 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
279 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1',
280 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0',
281 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1',
282 ],
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200283 'test_suite_ssl': [
284 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
285 ],
Valerio Setti5f540202023-06-30 17:20:49 +0200286 }
Valerio Setti42d5f192023-03-20 13:54:41 +0100287 }
288 },
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200289 'analyze_driver_vs_reference_no_ecp_at_all': {
Valerio Settie618cb02023-04-12 14:59:16 +0200290 'test_function': do_analyze_driver_vs_reference,
291 'args': {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200292 'component_ref': 'test_psa_crypto_config_reference_ecc_no_ecp_at_all',
293 'component_driver': 'test_psa_crypto_config_accel_ecc_no_ecp_at_all',
Valerio Settie618cb02023-04-12 14:59:16 +0200294 'ignored_suites': [
295 # Ignore test suites for the modules that are disabled in the
296 # accelerated test case.
297 'ecp',
298 'ecdsa',
299 'ecdh',
300 'ecjpake',
301 ],
302 'ignored_tests': {
303 'test_suite_random': [
304 'PSA classic wrapper: ECDSA signature (SECP256R1)',
305 ],
306 'test_suite_psa_crypto': [
307 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
308 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
309 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
310 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1',
311 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0',
312 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1',
313 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)',
314 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)',
315 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)',
316 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)',
317 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)',
318 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)',
319 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)',
Valerio Settiaddeee42023-06-14 10:46:55 +0200320 ],
321 'test_suite_pkparse': [
Valerio Setti5bd25232023-06-19 19:32:14 +0200322 # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED
323 # is automatically enabled in build_info.h (backward compatibility)
324 # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a
325 # consequence compressed points are supported in the reference
326 # component but not in the accelerated one, so they should be skipped
327 # while checking driver's coverage.
328 'Parse EC Key #10a (SEC1 PEM, secp384r1, compressed)',
329 'Parse EC Key #11a (SEC1 PEM, secp521r1, compressed)',
330 'Parse EC Key #12a (SEC1 PEM, bp256r1, compressed)',
331 'Parse EC Key #13a (SEC1 PEM, bp384r1, compressed)',
332 'Parse EC Key #14a (SEC1 PEM, bp512r1, compressed)',
333 'Parse EC Key #2a (SEC1 PEM, secp192r1, compressed)',
334 'Parse EC Key #8a (SEC1 PEM, secp224r1, compressed)',
335 'Parse EC Key #9a (SEC1 PEM, secp256r1, compressed)',
336 'Parse Public EC Key #2a (RFC 5480, PEM, secp192r1, compressed)',
337 'Parse Public EC Key #3a (RFC 5480, secp224r1, compressed)',
338 'Parse Public EC Key #4a (RFC 5480, secp256r1, compressed)',
339 'Parse Public EC Key #5a (RFC 5480, secp384r1, compressed)',
340 'Parse Public EC Key #6a (RFC 5480, secp521r1, compressed)',
341 'Parse Public EC Key #7a (RFC 5480, brainpoolP256r1, compressed)',
342 'Parse Public EC Key #8a (RFC 5480, brainpoolP384r1, compressed)',
343 'Parse Public EC Key #9a (RFC 5480, brainpoolP512r1, compressed)',
Valerio Settiaddeee42023-06-14 10:46:55 +0200344 ],
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200345 'test_suite_ssl': [
346 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
347 ],
Valerio Settie618cb02023-04-12 14:59:16 +0200348 }
349 }
350 },
Valerio Setti307810b2023-08-15 10:12:25 +0200351 'analyze_driver_vs_reference_ecc_no_bignum': {
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200352 'test_function': do_analyze_driver_vs_reference,
353 'args': {
354 'component_ref': 'test_psa_crypto_config_reference_ecc_no_bignum',
355 'component_driver': 'test_psa_crypto_config_accel_ecc_no_bignum',
356 'ignored_suites': [
357 # Ignore test suites for the modules that are disabled in the
358 # accelerated test case.
359 'ecp',
360 'ecdsa',
361 'ecdh',
362 'ecjpake',
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200363 'bignum_core',
364 'bignum_random',
365 'bignum_mod',
366 'bignum_mod_raw',
367 'bignum.generated',
368 'bignum.misc',
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200369 ],
370 'ignored_tests': {
371 'test_suite_random': [
372 'PSA classic wrapper: ECDSA signature (SECP256R1)',
373 ],
374 'test_suite_psa_crypto': [
375 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
376 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
377 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
378 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1',
379 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0',
380 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1',
381 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)',
382 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)',
383 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)',
384 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)',
385 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)',
386 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)',
387 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)',
388 ],
389 'test_suite_pkparse': [
390 # See the description provided above in the
391 # analyze_driver_vs_reference_no_ecp_at_all component.
392 'Parse EC Key #10a (SEC1 PEM, secp384r1, compressed)',
393 'Parse EC Key #11a (SEC1 PEM, secp521r1, compressed)',
394 'Parse EC Key #12a (SEC1 PEM, bp256r1, compressed)',
395 'Parse EC Key #13a (SEC1 PEM, bp384r1, compressed)',
396 'Parse EC Key #14a (SEC1 PEM, bp512r1, compressed)',
397 'Parse EC Key #2a (SEC1 PEM, secp192r1, compressed)',
398 'Parse EC Key #8a (SEC1 PEM, secp224r1, compressed)',
399 'Parse EC Key #9a (SEC1 PEM, secp256r1, compressed)',
400 'Parse Public EC Key #2a (RFC 5480, PEM, secp192r1, compressed)',
401 'Parse Public EC Key #3a (RFC 5480, secp224r1, compressed)',
402 'Parse Public EC Key #4a (RFC 5480, secp256r1, compressed)',
403 'Parse Public EC Key #5a (RFC 5480, secp384r1, compressed)',
404 'Parse Public EC Key #6a (RFC 5480, secp521r1, compressed)',
405 'Parse Public EC Key #7a (RFC 5480, brainpoolP256r1, compressed)',
406 'Parse Public EC Key #8a (RFC 5480, brainpoolP384r1, compressed)',
407 'Parse Public EC Key #9a (RFC 5480, brainpoolP512r1, compressed)',
408 ],
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200409 'test_suite_asn1parse': [
410 # This test depends on BIGNUM_C
411 'INTEGER too large for mpi',
412 ],
413 'test_suite_asn1write': [
414 # Following tests depends on BIGNUM_C
415 'ASN.1 Write mpi 0 (1 limb)',
416 'ASN.1 Write mpi 0 (null)',
417 'ASN.1 Write mpi 0x100',
418 'ASN.1 Write mpi 0x7f',
419 'ASN.1 Write mpi 0x7f with leading 0 limb',
420 'ASN.1 Write mpi 0x80',
421 'ASN.1 Write mpi 0x80 with leading 0 limb',
422 'ASN.1 Write mpi 0xff',
423 'ASN.1 Write mpi 1',
424 'ASN.1 Write mpi, 127*8 bits',
425 'ASN.1 Write mpi, 127*8+1 bits',
426 'ASN.1 Write mpi, 127*8-1 bits',
427 'ASN.1 Write mpi, 255*8 bits',
428 'ASN.1 Write mpi, 255*8-1 bits',
429 'ASN.1 Write mpi, 256*8-1 bits',
430 ],
Valerio Settie0be95e2023-08-01 09:07:43 +0200431 'test_suite_debug': [
432 # Following tests depends on BIGNUM_C
433 'Debug print mbedtls_mpi #2: 3 bits',
434 'Debug print mbedtls_mpi: 0 (empty representation)',
435 'Debug print mbedtls_mpi: 0 (non-empty representation)',
436 'Debug print mbedtls_mpi: 49 bits',
437 'Debug print mbedtls_mpi: 759 bits',
438 'Debug print mbedtls_mpi: 764 bits #1',
439 'Debug print mbedtls_mpi: 764 bits #2',
440 ],
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200441 'test_suite_ssl': [
442 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
443 ],
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200444 }
445 }
446 },
Valerio Setti307810b2023-08-15 10:12:25 +0200447 'analyze_driver_vs_reference_ecc_ffdh_no_bignum': {
448 'test_function': do_analyze_driver_vs_reference,
449 'args': {
450 'component_ref': 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum',
451 'component_driver': 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum',
452 'ignored_suites': [
453 # Ignore test suites for the modules that are disabled in the
454 # accelerated test case.
455 'ecp',
456 'ecdsa',
457 'ecdh',
458 'ecjpake',
459 'bignum_core',
460 'bignum_random',
461 'bignum_mod',
462 'bignum_mod_raw',
463 'bignum.generated',
464 'bignum.misc',
465 'dhm',
466 ],
467 'ignored_tests': {
468 'test_suite_random': [
469 'PSA classic wrapper: ECDSA signature (SECP256R1)',
470 ],
471 'test_suite_psa_crypto': [
472 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
473 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
474 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
475 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1',
476 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0',
477 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1',
478 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)',
479 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)',
480 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)',
481 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)',
482 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)',
483 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)',
484 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)',
485 ],
486 'test_suite_pkparse': [
487 # See the description provided above in the
488 # analyze_driver_vs_reference_no_ecp_at_all component.
489 'Parse EC Key #10a (SEC1 PEM, secp384r1, compressed)',
490 'Parse EC Key #11a (SEC1 PEM, secp521r1, compressed)',
491 'Parse EC Key #12a (SEC1 PEM, bp256r1, compressed)',
492 'Parse EC Key #13a (SEC1 PEM, bp384r1, compressed)',
493 'Parse EC Key #14a (SEC1 PEM, bp512r1, compressed)',
494 'Parse EC Key #2a (SEC1 PEM, secp192r1, compressed)',
495 'Parse EC Key #8a (SEC1 PEM, secp224r1, compressed)',
496 'Parse EC Key #9a (SEC1 PEM, secp256r1, compressed)',
497 'Parse Public EC Key #2a (RFC 5480, PEM, secp192r1, compressed)',
498 'Parse Public EC Key #3a (RFC 5480, secp224r1, compressed)',
499 'Parse Public EC Key #4a (RFC 5480, secp256r1, compressed)',
500 'Parse Public EC Key #5a (RFC 5480, secp384r1, compressed)',
501 'Parse Public EC Key #6a (RFC 5480, secp521r1, compressed)',
502 'Parse Public EC Key #7a (RFC 5480, brainpoolP256r1, compressed)',
503 'Parse Public EC Key #8a (RFC 5480, brainpoolP384r1, compressed)',
504 'Parse Public EC Key #9a (RFC 5480, brainpoolP512r1, compressed)',
505 ],
506 'test_suite_asn1parse': [
507 # This test depends on BIGNUM_C
508 'INTEGER too large for mpi',
509 ],
510 'test_suite_asn1write': [
511 # Following tests depends on BIGNUM_C
512 'ASN.1 Write mpi 0 (1 limb)',
513 'ASN.1 Write mpi 0 (null)',
514 'ASN.1 Write mpi 0x100',
515 'ASN.1 Write mpi 0x7f',
516 'ASN.1 Write mpi 0x7f with leading 0 limb',
517 'ASN.1 Write mpi 0x80',
518 'ASN.1 Write mpi 0x80 with leading 0 limb',
519 'ASN.1 Write mpi 0xff',
520 'ASN.1 Write mpi 1',
521 'ASN.1 Write mpi, 127*8 bits',
522 'ASN.1 Write mpi, 127*8+1 bits',
523 'ASN.1 Write mpi, 127*8-1 bits',
524 'ASN.1 Write mpi, 255*8 bits',
525 'ASN.1 Write mpi, 255*8-1 bits',
526 'ASN.1 Write mpi, 256*8-1 bits',
527 ],
528 'test_suite_debug': [
529 # Following tests depends on BIGNUM_C
530 'Debug print mbedtls_mpi #2: 3 bits',
531 'Debug print mbedtls_mpi: 0 (empty representation)',
532 'Debug print mbedtls_mpi: 0 (non-empty representation)',
533 'Debug print mbedtls_mpi: 49 bits',
534 'Debug print mbedtls_mpi: 759 bits',
535 'Debug print mbedtls_mpi: 764 bits #1',
536 'Debug print mbedtls_mpi: 764 bits #2',
537 ],
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200538 'test_suite_ssl': [
539 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
540 ],
Valerio Setti307810b2023-08-15 10:12:25 +0200541 }
542 }
543 },
Przemek Stekiel85b64422023-05-26 09:55:23 +0200544 'analyze_driver_vs_reference_ffdh_alg': {
545 'test_function': do_analyze_driver_vs_reference,
546 'args': {
547 'component_ref': 'test_psa_crypto_config_reference_ffdh',
548 'component_driver': 'test_psa_crypto_config_accel_ffdh',
Przemek Stekiel84f4ff12023-07-04 12:35:31 +0200549 'ignored_suites': ['dhm'],
Przemek Stekiel565353e2023-07-05 11:07:07 +0200550 'ignored_tests': {}
Przemek Stekiel85b64422023-05-26 09:55:23 +0200551 }
552 },
Valerio Settif01d6482023-08-04 13:51:18 +0200553 'analyze_driver_vs_reference_tfm_config': {
554 'test_function': do_analyze_driver_vs_reference,
555 'args': {
556 'component_ref': 'test_tfm_config',
557 'component_driver': 'test_tfm_config_p256m_driver_accel_ec',
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200558 'ignored_suites': [
559 # Ignore test suites for the modules that are disabled in the
560 # accelerated test case.
561 'ecp',
562 'ecdsa',
563 'ecdh',
564 'ecjpake',
565 'bignum_core',
566 'bignum_random',
567 'bignum_mod',
568 'bignum_mod_raw',
569 'bignum.generated',
570 'bignum.misc',
571 ],
Valerio Settif01d6482023-08-04 13:51:18 +0200572 'ignored_tests': {
573 # Ignore all tests that require DERIVE support which is disabled
574 # in the driver version
575 'test_suite_psa_crypto': [
576 'PSA key agreement setup: ECDH + HKDF-SHA-256: good',
577 ('PSA key agreement setup: ECDH + HKDF-SHA-256: good, key algorithm broader '
578 'than required'),
579 'PSA key agreement setup: ECDH + HKDF-SHA-256: public key not on curve',
580 'PSA key agreement setup: KDF instead of a key agreement algorithm',
581 'PSA key agreement setup: bad key agreement algorithm',
582 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: capacity=8160',
583 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 0+32',
584 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 1+31',
585 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 31+1',
586 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 32+0',
587 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 32+32',
588 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 64+0',
589 'PSA key derivation: ECDH on P256 with HKDF-SHA256, info first',
590 'PSA key derivation: ECDH on P256 with HKDF-SHA256, key output',
591 'PSA key derivation: ECDH on P256 with HKDF-SHA256, missing info',
592 'PSA key derivation: ECDH on P256 with HKDF-SHA256, omitted salt',
593 'PSA key derivation: ECDH on P256 with HKDF-SHA256, raw output',
594 'PSA key derivation: ECDH on P256 with HKDF-SHA256, salt after secret',
595 'PSA key derivation: ECDH with TLS 1.2 PRF SHA-256, good case',
596 'PSA key derivation: ECDH with TLS 1.2 PRF SHA-256, missing label',
597 'PSA key derivation: ECDH with TLS 1.2 PRF SHA-256, missing label and secret',
598 'PSA key derivation: ECDH with TLS 1.2 PRF SHA-256, no inputs',
599 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
600 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
601 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
602 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, SHA-256, 0+48, ka',
603 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, SHA-256, 24+24, ka',
604 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, SHA-256, 48+0, ka',
605 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, bad state #1, ka',
606 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, bad state #3, ka',
607 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, bad state #4, ka',
608 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)',
609 'PSA key derivation: bits=7 invalid for ECC MONTGOMERY (ECC enabled)',
610 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)',
611 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)',
612 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)',
613 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)',
614 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)',
615 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)',
616 'PSA raw key agreement: ECDH SECP256R1 (RFC 5903)',
617 ],
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200618 'test_suite_random': [
619 'PSA classic wrapper: ECDSA signature (SECP256R1)',
620 ],
Valerio Settif01d6482023-08-04 13:51:18 +0200621 'test_suite_psa_crypto_pake': [
622 'PSA PAKE: ecjpake size macros',
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200623 ],
624 'test_suite_asn1parse': [
625 # This test depends on BIGNUM_C
626 'INTEGER too large for mpi',
627 ],
628 'test_suite_asn1write': [
629 # Following tests depends on BIGNUM_C
630 'ASN.1 Write mpi 0 (1 limb)',
631 'ASN.1 Write mpi 0 (null)',
632 'ASN.1 Write mpi 0x100',
633 'ASN.1 Write mpi 0x7f',
634 'ASN.1 Write mpi 0x7f with leading 0 limb',
635 'ASN.1 Write mpi 0x80',
636 'ASN.1 Write mpi 0x80 with leading 0 limb',
637 'ASN.1 Write mpi 0xff',
638 'ASN.1 Write mpi 1',
639 'ASN.1 Write mpi, 127*8 bits',
640 'ASN.1 Write mpi, 127*8+1 bits',
641 'ASN.1 Write mpi, 127*8-1 bits',
642 'ASN.1 Write mpi, 255*8 bits',
643 'ASN.1 Write mpi, 255*8-1 bits',
644 'ASN.1 Write mpi, 256*8-1 bits',
645 ],
Valerio Settif01d6482023-08-04 13:51:18 +0200646 }
647 }
648 }
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200649}
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200650
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200651def main():
Valerio Settif075e472023-10-17 11:03:16 +0200652 main_results = Results()
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200653
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200654 try:
655 parser = argparse.ArgumentParser(description=__doc__)
Przemek Stekiel58bbc232022-10-24 08:10:10 +0200656 parser.add_argument('outcomes', metavar='OUTCOMES.CSV',
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200657 help='Outcome file to analyze')
Valerio Settidfd7ca62023-10-09 16:30:11 +0200658 parser.add_argument('specified_tasks', default='all', nargs='?',
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100659 help='Analysis to be done. By default, run all tasks. '
660 'With one or more TASK, run only those. '
661 'TASK can be the name of a single task or '
Przemek Stekiel85c54ea2022-11-17 11:50:23 +0100662 'comma/space-separated list of tasks. ')
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100663 parser.add_argument('--list', action='store_true',
664 help='List all available tasks and exit.')
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100665 parser.add_argument('--require-full-coverage', action='store_true',
666 dest='full_coverage', help="Require all available "
667 "test cases to be executed and issue an error "
668 "otherwise. This flag is ignored if 'task' is "
669 "neither 'all' nor 'analyze_coverage'")
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200670 options = parser.parse_args()
Przemek Stekiel4e955902022-10-21 13:42:08 +0200671
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100672 if options.list:
Valerio Settidfd7ca62023-10-09 16:30:11 +0200673 for task in KNOWN_TASKS:
Valerio Setti5329ff02023-10-17 09:44:36 +0200674 print(task)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100675 sys.exit(0)
676
Valerio Settidfd7ca62023-10-09 16:30:11 +0200677 if options.specified_tasks == 'all':
678 tasks_list = KNOWN_TASKS.keys()
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100679 else:
Valerio Settidfd7ca62023-10-09 16:30:11 +0200680 tasks_list = re.split(r'[, ]+', options.specified_tasks)
Valerio Settidfd7ca62023-10-09 16:30:11 +0200681 for task in tasks_list:
682 if task not in KNOWN_TASKS:
Valerio Settifb2750e2023-10-17 10:11:45 +0200683 sys.stderr.write('invalid task: {}'.format(task))
684 sys.exit(2)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100685
Valerio Settidfd7ca62023-10-09 16:30:11 +0200686 KNOWN_TASKS['analyze_coverage']['args']['full_coverage'] = options.full_coverage
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100687
Valerio Settifb2750e2023-10-17 10:11:45 +0200688 for task in tasks_list:
689 test_function = KNOWN_TASKS[task]['test_function']
690 test_args = KNOWN_TASKS[task]['args']
Valerio Settif075e472023-10-17 11:03:16 +0200691 main_results = test_function(main_results, options.outcomes, test_args)
Valerio Settidfd7ca62023-10-09 16:30:11 +0200692
Valerio Settif075e472023-10-17 11:03:16 +0200693 main_results.info("Overall results:\n" + \
694 "{} warnings\n".format(main_results.warning_count) + \
695 "{} errors\n".format(main_results.error_count))
696
697 sys.exit(0 if (main_results.error_count == 0) else 2)
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200698
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200699 except Exception: # pylint: disable=broad-except
700 # Print the backtrace and exit explicitly with our chosen status.
701 traceback.print_exc()
702 sys.exit(120)
703
704if __name__ == '__main__':
705 main()