blob: d0b72a859baceaecdd495447076354906e69d12f [file] [log] [blame]
Valerio Setti8d178be2023-10-17 12:23:55 +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 Setti8070dbe2023-10-17 12:29:30 +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 Setti8070dbe2023-10-17 12:29:30 +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 Setti8070dbe2023-10-17 12:29:30 +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
Valerio Setti8070dbe2023-10-17 12:29:30 +020037 def _print_line(fmt, *args, **kwargs):
Valerio Setti735794c2023-10-18 08:05:15 +020038 sys.stderr.write((fmt + '\n').format(*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, \
Valerio Setti781c2342023-10-17 12:47:35 +020060 outcome_file):
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 Setti781c2342023-10-17 12:47:35 +020069 return
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
Tomás Gonzálezb401e112023-08-11 15:22:04 +010079def analyze_coverage(results, outcomes, allow_list, full_coverage):
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020080 """Check that all available test cases are executed at least once."""
Gilles Peskine686c2922022-01-07 15:58:38 +010081 available = check_test_cases.collect_available_test_cases()
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020082 for key in available:
83 hits = outcomes[key].hits() if key in outcomes else 0
Tomás González07bdcc22023-08-11 14:59:03 +010084 if hits == 0 and key not in allow_list:
Tomás Gonzálezb401e112023-08-11 15:22:04 +010085 if full_coverage:
86 results.error('Test case not executed: {}', key)
87 else:
88 results.warning('Test case not executed: {}', key)
Tomás González07bdcc22023-08-11 14:59:03 +010089 elif hits != 0 and key in allow_list:
90 # Test Case should be removed from the allow list.
Tomás González7ebb18f2023-08-22 09:40:23 +010091 if full_coverage:
Tomás Gonzáleza0631442023-08-22 12:17:57 +010092 results.error('Allow listed test case was executed: {}', key)
Tomás González7ebb18f2023-08-22 09:40:23 +010093 else:
94 results.warning('Allow listed test case was executed: {}', key)
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020095
Valerio Settif075e472023-10-17 11:03:16 +020096def analyze_driver_vs_reference(results: Results, outcomes,
Valerio Settiaaef0bc2023-10-10 09:42:13 +020097 component_ref, component_driver,
Valerio Setti3002c992023-01-18 17:28:36 +010098 ignored_suites, ignored_test=None):
Przemek Stekiel4e955902022-10-21 13:42:08 +020099 """Check that all tests executed in the reference component are also
100 executed in the corresponding driver component.
Valerio Setti3002c992023-01-18 17:28:36 +0100101 Skip:
102 - full test suites provided in ignored_suites list
103 - only some specific test inside a test suite, for which the corresponding
104 output string is provided
Przemek Stekiel4e955902022-10-21 13:42:08 +0200105 """
Przemek Stekiel4e955902022-10-21 13:42:08 +0200106 available = check_test_cases.collect_available_test_cases()
Przemek Stekiel4e955902022-10-21 13:42:08 +0200107
108 for key in available:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200109 # Continue if test was not executed by any component
110 hits = outcomes[key].hits() if key in outcomes else 0
Przemek Stekielc86dedf2022-10-24 09:16:04 +0200111 if hits == 0:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200112 continue
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100113 # Skip ignored test suites
114 full_test_suite = key.split(';')[0] # retrieve full test suite name
115 test_string = key.split(';')[1] # retrieve the text string of this test
116 test_suite = full_test_suite.split('.')[0] # retrieve main part of test suite name
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100117 if test_suite in ignored_suites or full_test_suite in ignored_suites:
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100118 continue
Valerio Setti3002c992023-01-18 17:28:36 +0100119 if ((full_test_suite in ignored_test) and
120 (test_string in ignored_test[full_test_suite])):
121 continue
Przemek Stekiel4e955902022-10-21 13:42:08 +0200122 # Search for tests that run in reference component and not in driver component
123 driver_test_passed = False
124 reference_test_passed = False
125 for entry in outcomes[key].successes:
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100126 if component_driver in entry:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200127 driver_test_passed = True
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100128 if component_ref in entry:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200129 reference_test_passed = True
Manuel Pégourié-Gonnardc6967d22022-12-30 13:40:34 +0100130 if(reference_test_passed and not driver_test_passed):
Valerio Settif075e472023-10-17 11:03:16 +0200131 results.error(key)
Przemek Stekiel4e955902022-10-21 13:42:08 +0200132
Valerio Setti781c2342023-10-17 12:47:35 +0200133def analyze_outcomes(results: Results, outcomes, args):
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200134 """Run all analyses on the given outcome collection."""
Valerio Settif075e472023-10-17 11:03:16 +0200135 analyze_coverage(results, outcomes, args['allow_list'],
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100136 args['full_coverage'])
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200137
138def read_outcome_file(outcome_file):
139 """Parse an outcome file and return an outcome collection.
140
141An outcome collection is a dictionary mapping keys to TestCaseOutcomes objects.
142The keys are the test suite name and the test case description, separated
143by a semicolon.
144"""
145 outcomes = {}
146 with open(outcome_file, 'r', encoding='utf-8') as input_file:
147 for line in input_file:
148 (platform, config, suite, case, result, _cause) = line.split(';')
149 key = ';'.join([suite, case])
150 setup = ';'.join([platform, config])
151 if key not in outcomes:
152 outcomes[key] = TestCaseOutcomes()
153 if result == 'PASS':
154 outcomes[key].successes.append(setup)
155 elif result == 'FAIL':
156 outcomes[key].failures.append(setup)
157 return outcomes
158
Valerio Setti781c2342023-10-17 12:47:35 +0200159def do_analyze_coverage(results: Results, outcome_file, args):
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100160 """Perform coverage analysis."""
Valerio Setti40314fc2023-10-17 11:34:31 +0200161 results.info("*** Analyze coverage ***")
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200162 outcomes = read_outcome_file(outcome_file)
Valerio Setti781c2342023-10-17 12:47:35 +0200163 analyze_outcomes(results, outcomes, args)
Przemek Stekiel4e955902022-10-21 13:42:08 +0200164
Valerio Setti781c2342023-10-17 12:47:35 +0200165def do_analyze_driver_vs_reference(results: Results, outcome_file, args):
Przemek Stekiel4e955902022-10-21 13:42:08 +0200166 """Perform driver vs reference analyze."""
Valerio Setti40314fc2023-10-17 11:34:31 +0200167 results.info("*** Analyze driver {} vs reference {} ***".format(
Valerio Settib0c618e2023-10-16 14:19:49 +0200168 args['component_driver'], args['component_ref']))
169
Valerio Setti781c2342023-10-17 12:47:35 +0200170 execute_reference_driver_tests(results, args['component_ref'], \
171 args['component_driver'], outcome_file)
Valerio Settia2663322023-03-24 08:20:18 +0100172
Valerio Setti3002c992023-01-18 17:28:36 +0100173 ignored_suites = ['test_suite_' + x for x in args['ignored_suites']]
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100174
Przemek Stekiel4e955902022-10-21 13:42:08 +0200175 outcomes = read_outcome_file(outcome_file)
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200176
Valerio Setti781c2342023-10-17 12:47:35 +0200177 analyze_driver_vs_reference(results, outcomes,
178 args['component_ref'], args['component_driver'],
179 ignored_suites, args['ignored_tests'])
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200180
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100181# List of tasks with a function that can handle this task and additional arguments if required
Valerio Settidfd7ca62023-10-09 16:30:11 +0200182KNOWN_TASKS = {
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200183 'analyze_coverage': {
184 'test_function': do_analyze_coverage,
Tomás González07bdcc22023-08-11 14:59:03 +0100185 'args': {
Tomás González358c6c62023-08-14 15:43:46 +0100186 'allow_list': [
Tomás González50223112023-08-22 09:52:06 +0100187 # Algorithm not supported yet
188 'test_suite_psa_crypto_metadata;Asymmetric signature: pure EdDSA',
189 # Algorithm not supported yet
190 'test_suite_psa_crypto_metadata;Cipher: XTS',
Tomás Gonzálezd43cab32023-08-24 09:12:40 +0100191 ],
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100192 'full_coverage': False,
Tomás González07bdcc22023-08-11 14:59:03 +0100193 }
Tomás Gonzálezd43cab32023-08-24 09:12:40 +0100194 },
Valerio Settia2663322023-03-24 08:20:18 +0100195 # There are 2 options to use analyze_driver_vs_reference_xxx locally:
196 # 1. Run tests and then analysis:
197 # - tests/scripts/all.sh --outcome-file "$PWD/out.csv" <component_ref> <component_driver>
198 # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
199 # 2. Let this script run both automatically:
200 # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200201 'analyze_driver_vs_reference_hash': {
202 'test_function': do_analyze_driver_vs_reference,
203 'args': {
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100204 'component_ref': 'test_psa_crypto_config_reference_hash_use_psa',
205 'component_driver': 'test_psa_crypto_config_accel_hash_use_psa',
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +0100206 'ignored_suites': [
207 'shax', 'mdx', # the software implementations that are being excluded
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100208 'md.psa', # purposefully depends on whether drivers are present
Gilles Peskine35b49c42023-10-04 12:28:41 +0200209 'psa_crypto_low_hash.generated', # testing the builtins
Valerio Setti3002c992023-01-18 17:28:36 +0100210 ],
211 'ignored_tests': {
212 }
213 }
214 },
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200215 'analyze_driver_vs_reference_ecp_light_only': {
Valerio Setti42d5f192023-03-20 13:54:41 +0100216 'test_function': do_analyze_driver_vs_reference,
217 'args': {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200218 'component_ref': 'test_psa_crypto_config_reference_ecc_ecp_light_only',
219 'component_driver': 'test_psa_crypto_config_accel_ecc_ecp_light_only',
Valerio Setti42d5f192023-03-20 13:54:41 +0100220 'ignored_suites': [
221 'ecdsa',
222 'ecdh',
223 'ecjpake',
224 ],
225 'ignored_tests': {
226 'test_suite_random': [
227 'PSA classic wrapper: ECDSA signature (SECP256R1)',
228 ],
Valerio Setti0c477d32023-04-07 15:54:20 +0200229 # In the accelerated test ECP_C is not set (only ECP_LIGHT is)
230 # so we must ignore disparities in the tests for which ECP_C
231 # is required.
232 'test_suite_ecp': [
233 'ECP check public-private #1 (OK)',
234 'ECP check public-private #2 (group none)',
235 'ECP check public-private #3 (group mismatch)',
236 'ECP check public-private #4 (Qx mismatch)',
237 'ECP check public-private #5 (Qy mismatch)',
238 'ECP check public-private #6 (wrong Qx)',
239 'ECP check public-private #7 (wrong Qy)',
240 'ECP gen keypair [#1]',
241 'ECP gen keypair [#2]',
242 'ECP gen keypair [#3]',
243 'ECP gen keypair wrapper',
244 'ECP point muladd secp256r1 #1',
245 'ECP point muladd secp256r1 #2',
246 'ECP point multiplication Curve25519 (element of order 2: origin) #3',
247 'ECP point multiplication Curve25519 (element of order 4: 1) #4',
248 'ECP point multiplication Curve25519 (element of order 8) #5',
249 'ECP point multiplication Curve25519 (normalized) #1',
250 'ECP point multiplication Curve25519 (not normalized) #2',
251 'ECP point multiplication rng fail Curve25519',
252 'ECP point multiplication rng fail secp256r1',
253 'ECP test vectors Curve25519',
254 'ECP test vectors Curve448 (RFC 7748 6.2, after decodeUCoordinate)',
255 'ECP test vectors brainpoolP256r1 rfc 7027',
256 'ECP test vectors brainpoolP384r1 rfc 7027',
257 'ECP test vectors brainpoolP512r1 rfc 7027',
258 'ECP test vectors secp192k1',
259 'ECP test vectors secp192r1 rfc 5114',
260 'ECP test vectors secp224k1',
261 'ECP test vectors secp224r1 rfc 5114',
262 'ECP test vectors secp256k1',
263 'ECP test vectors secp256r1 rfc 5114',
264 'ECP test vectors secp384r1 rfc 5114',
265 'ECP test vectors secp521r1 rfc 5114',
Valerio Settie50a75f2023-05-19 17:43:06 +0200266 ],
Valerio Setti482a0b92023-08-18 15:55:10 +0200267 'test_suite_psa_crypto': [
268 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
269 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
270 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
271 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1',
272 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0',
273 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1',
274 ],
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200275 'test_suite_ssl': [
276 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
277 ],
Valerio Setti5f540202023-06-30 17:20:49 +0200278 }
Valerio Setti42d5f192023-03-20 13:54:41 +0100279 }
280 },
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200281 'analyze_driver_vs_reference_no_ecp_at_all': {
Valerio Settie618cb02023-04-12 14:59:16 +0200282 'test_function': do_analyze_driver_vs_reference,
283 'args': {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200284 'component_ref': 'test_psa_crypto_config_reference_ecc_no_ecp_at_all',
285 'component_driver': 'test_psa_crypto_config_accel_ecc_no_ecp_at_all',
Valerio Settie618cb02023-04-12 14:59:16 +0200286 'ignored_suites': [
287 # Ignore test suites for the modules that are disabled in the
288 # accelerated test case.
289 'ecp',
290 'ecdsa',
291 'ecdh',
292 'ecjpake',
293 ],
294 'ignored_tests': {
295 'test_suite_random': [
296 'PSA classic wrapper: ECDSA signature (SECP256R1)',
297 ],
298 'test_suite_psa_crypto': [
299 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
300 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
301 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
302 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1',
303 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0',
304 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1',
305 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)',
306 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)',
307 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)',
308 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)',
309 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)',
310 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)',
311 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)',
Valerio Settiaddeee42023-06-14 10:46:55 +0200312 ],
313 'test_suite_pkparse': [
Valerio Setti5bd25232023-06-19 19:32:14 +0200314 # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED
315 # is automatically enabled in build_info.h (backward compatibility)
316 # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a
317 # consequence compressed points are supported in the reference
318 # component but not in the accelerated one, so they should be skipped
319 # while checking driver's coverage.
320 'Parse EC Key #10a (SEC1 PEM, secp384r1, compressed)',
321 'Parse EC Key #11a (SEC1 PEM, secp521r1, compressed)',
322 'Parse EC Key #12a (SEC1 PEM, bp256r1, compressed)',
323 'Parse EC Key #13a (SEC1 PEM, bp384r1, compressed)',
324 'Parse EC Key #14a (SEC1 PEM, bp512r1, compressed)',
325 'Parse EC Key #2a (SEC1 PEM, secp192r1, compressed)',
326 'Parse EC Key #8a (SEC1 PEM, secp224r1, compressed)',
327 'Parse EC Key #9a (SEC1 PEM, secp256r1, compressed)',
328 'Parse Public EC Key #2a (RFC 5480, PEM, secp192r1, compressed)',
329 'Parse Public EC Key #3a (RFC 5480, secp224r1, compressed)',
330 'Parse Public EC Key #4a (RFC 5480, secp256r1, compressed)',
331 'Parse Public EC Key #5a (RFC 5480, secp384r1, compressed)',
332 'Parse Public EC Key #6a (RFC 5480, secp521r1, compressed)',
333 'Parse Public EC Key #7a (RFC 5480, brainpoolP256r1, compressed)',
334 'Parse Public EC Key #8a (RFC 5480, brainpoolP384r1, compressed)',
335 'Parse Public EC Key #9a (RFC 5480, brainpoolP512r1, compressed)',
Valerio Settiaddeee42023-06-14 10:46:55 +0200336 ],
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200337 'test_suite_ssl': [
338 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
339 ],
Valerio Settie618cb02023-04-12 14:59:16 +0200340 }
341 }
342 },
Valerio Setti307810b2023-08-15 10:12:25 +0200343 'analyze_driver_vs_reference_ecc_no_bignum': {
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200344 'test_function': do_analyze_driver_vs_reference,
345 'args': {
346 'component_ref': 'test_psa_crypto_config_reference_ecc_no_bignum',
347 'component_driver': 'test_psa_crypto_config_accel_ecc_no_bignum',
348 'ignored_suites': [
349 # Ignore test suites for the modules that are disabled in the
350 # accelerated test case.
351 'ecp',
352 'ecdsa',
353 'ecdh',
354 'ecjpake',
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200355 'bignum_core',
356 'bignum_random',
357 'bignum_mod',
358 'bignum_mod_raw',
359 'bignum.generated',
360 'bignum.misc',
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200361 ],
362 'ignored_tests': {
363 'test_suite_random': [
364 'PSA classic wrapper: ECDSA signature (SECP256R1)',
365 ],
366 'test_suite_psa_crypto': [
367 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
368 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
369 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
370 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1',
371 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0',
372 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1',
373 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)',
374 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)',
375 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)',
376 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)',
377 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)',
378 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)',
379 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)',
380 ],
381 'test_suite_pkparse': [
382 # See the description provided above in the
383 # analyze_driver_vs_reference_no_ecp_at_all component.
384 'Parse EC Key #10a (SEC1 PEM, secp384r1, compressed)',
385 'Parse EC Key #11a (SEC1 PEM, secp521r1, compressed)',
386 'Parse EC Key #12a (SEC1 PEM, bp256r1, compressed)',
387 'Parse EC Key #13a (SEC1 PEM, bp384r1, compressed)',
388 'Parse EC Key #14a (SEC1 PEM, bp512r1, compressed)',
389 'Parse EC Key #2a (SEC1 PEM, secp192r1, compressed)',
390 'Parse EC Key #8a (SEC1 PEM, secp224r1, compressed)',
391 'Parse EC Key #9a (SEC1 PEM, secp256r1, compressed)',
392 'Parse Public EC Key #2a (RFC 5480, PEM, secp192r1, compressed)',
393 'Parse Public EC Key #3a (RFC 5480, secp224r1, compressed)',
394 'Parse Public EC Key #4a (RFC 5480, secp256r1, compressed)',
395 'Parse Public EC Key #5a (RFC 5480, secp384r1, compressed)',
396 'Parse Public EC Key #6a (RFC 5480, secp521r1, compressed)',
397 'Parse Public EC Key #7a (RFC 5480, brainpoolP256r1, compressed)',
398 'Parse Public EC Key #8a (RFC 5480, brainpoolP384r1, compressed)',
399 'Parse Public EC Key #9a (RFC 5480, brainpoolP512r1, compressed)',
400 ],
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200401 'test_suite_asn1parse': [
402 # This test depends on BIGNUM_C
403 'INTEGER too large for mpi',
404 ],
405 'test_suite_asn1write': [
406 # Following tests depends on BIGNUM_C
407 'ASN.1 Write mpi 0 (1 limb)',
408 'ASN.1 Write mpi 0 (null)',
409 'ASN.1 Write mpi 0x100',
410 'ASN.1 Write mpi 0x7f',
411 'ASN.1 Write mpi 0x7f with leading 0 limb',
412 'ASN.1 Write mpi 0x80',
413 'ASN.1 Write mpi 0x80 with leading 0 limb',
414 'ASN.1 Write mpi 0xff',
415 'ASN.1 Write mpi 1',
416 'ASN.1 Write mpi, 127*8 bits',
417 'ASN.1 Write mpi, 127*8+1 bits',
418 'ASN.1 Write mpi, 127*8-1 bits',
419 'ASN.1 Write mpi, 255*8 bits',
420 'ASN.1 Write mpi, 255*8-1 bits',
421 'ASN.1 Write mpi, 256*8-1 bits',
422 ],
Valerio Settie0be95e2023-08-01 09:07:43 +0200423 'test_suite_debug': [
424 # Following tests depends on BIGNUM_C
425 'Debug print mbedtls_mpi #2: 3 bits',
426 'Debug print mbedtls_mpi: 0 (empty representation)',
427 'Debug print mbedtls_mpi: 0 (non-empty representation)',
428 'Debug print mbedtls_mpi: 49 bits',
429 'Debug print mbedtls_mpi: 759 bits',
430 'Debug print mbedtls_mpi: 764 bits #1',
431 'Debug print mbedtls_mpi: 764 bits #2',
432 ],
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200433 'test_suite_ssl': [
434 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
435 ],
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200436 }
437 }
438 },
Valerio Setti307810b2023-08-15 10:12:25 +0200439 'analyze_driver_vs_reference_ecc_ffdh_no_bignum': {
440 'test_function': do_analyze_driver_vs_reference,
441 'args': {
442 'component_ref': 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum',
443 'component_driver': 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum',
444 'ignored_suites': [
445 # Ignore test suites for the modules that are disabled in the
446 # accelerated test case.
447 'ecp',
448 'ecdsa',
449 'ecdh',
450 'ecjpake',
451 'bignum_core',
452 'bignum_random',
453 'bignum_mod',
454 'bignum_mod_raw',
455 'bignum.generated',
456 'bignum.misc',
457 'dhm',
458 ],
459 'ignored_tests': {
460 'test_suite_random': [
461 'PSA classic wrapper: ECDSA signature (SECP256R1)',
462 ],
463 'test_suite_psa_crypto': [
464 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
465 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
466 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
467 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1',
468 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0',
469 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1',
470 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)',
471 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)',
472 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)',
473 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)',
474 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)',
475 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)',
476 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)',
477 ],
478 'test_suite_pkparse': [
479 # See the description provided above in the
480 # analyze_driver_vs_reference_no_ecp_at_all component.
481 'Parse EC Key #10a (SEC1 PEM, secp384r1, compressed)',
482 'Parse EC Key #11a (SEC1 PEM, secp521r1, compressed)',
483 'Parse EC Key #12a (SEC1 PEM, bp256r1, compressed)',
484 'Parse EC Key #13a (SEC1 PEM, bp384r1, compressed)',
485 'Parse EC Key #14a (SEC1 PEM, bp512r1, compressed)',
486 'Parse EC Key #2a (SEC1 PEM, secp192r1, compressed)',
487 'Parse EC Key #8a (SEC1 PEM, secp224r1, compressed)',
488 'Parse EC Key #9a (SEC1 PEM, secp256r1, compressed)',
489 'Parse Public EC Key #2a (RFC 5480, PEM, secp192r1, compressed)',
490 'Parse Public EC Key #3a (RFC 5480, secp224r1, compressed)',
491 'Parse Public EC Key #4a (RFC 5480, secp256r1, compressed)',
492 'Parse Public EC Key #5a (RFC 5480, secp384r1, compressed)',
493 'Parse Public EC Key #6a (RFC 5480, secp521r1, compressed)',
494 'Parse Public EC Key #7a (RFC 5480, brainpoolP256r1, compressed)',
495 'Parse Public EC Key #8a (RFC 5480, brainpoolP384r1, compressed)',
496 'Parse Public EC Key #9a (RFC 5480, brainpoolP512r1, compressed)',
497 ],
498 'test_suite_asn1parse': [
499 # This test depends on BIGNUM_C
500 'INTEGER too large for mpi',
501 ],
502 'test_suite_asn1write': [
503 # Following tests depends on BIGNUM_C
504 'ASN.1 Write mpi 0 (1 limb)',
505 'ASN.1 Write mpi 0 (null)',
506 'ASN.1 Write mpi 0x100',
507 'ASN.1 Write mpi 0x7f',
508 'ASN.1 Write mpi 0x7f with leading 0 limb',
509 'ASN.1 Write mpi 0x80',
510 'ASN.1 Write mpi 0x80 with leading 0 limb',
511 'ASN.1 Write mpi 0xff',
512 'ASN.1 Write mpi 1',
513 'ASN.1 Write mpi, 127*8 bits',
514 'ASN.1 Write mpi, 127*8+1 bits',
515 'ASN.1 Write mpi, 127*8-1 bits',
516 'ASN.1 Write mpi, 255*8 bits',
517 'ASN.1 Write mpi, 255*8-1 bits',
518 'ASN.1 Write mpi, 256*8-1 bits',
519 ],
520 'test_suite_debug': [
521 # Following tests depends on BIGNUM_C
522 'Debug print mbedtls_mpi #2: 3 bits',
523 'Debug print mbedtls_mpi: 0 (empty representation)',
524 'Debug print mbedtls_mpi: 0 (non-empty representation)',
525 'Debug print mbedtls_mpi: 49 bits',
526 'Debug print mbedtls_mpi: 759 bits',
527 'Debug print mbedtls_mpi: 764 bits #1',
528 'Debug print mbedtls_mpi: 764 bits #2',
529 ],
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200530 'test_suite_ssl': [
531 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
532 ],
Valerio Setti307810b2023-08-15 10:12:25 +0200533 }
534 }
535 },
Przemek Stekiel85b64422023-05-26 09:55:23 +0200536 'analyze_driver_vs_reference_ffdh_alg': {
537 'test_function': do_analyze_driver_vs_reference,
538 'args': {
539 'component_ref': 'test_psa_crypto_config_reference_ffdh',
540 'component_driver': 'test_psa_crypto_config_accel_ffdh',
Przemek Stekiel84f4ff12023-07-04 12:35:31 +0200541 'ignored_suites': ['dhm'],
Przemek Stekiel565353e2023-07-05 11:07:07 +0200542 'ignored_tests': {}
Przemek Stekiel85b64422023-05-26 09:55:23 +0200543 }
544 },
Valerio Settif01d6482023-08-04 13:51:18 +0200545 'analyze_driver_vs_reference_tfm_config': {
546 'test_function': do_analyze_driver_vs_reference,
547 'args': {
548 'component_ref': 'test_tfm_config',
549 'component_driver': 'test_tfm_config_p256m_driver_accel_ec',
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200550 'ignored_suites': [
551 # Ignore test suites for the modules that are disabled in the
552 # accelerated test case.
553 'ecp',
554 'ecdsa',
555 'ecdh',
556 'ecjpake',
557 'bignum_core',
558 'bignum_random',
559 'bignum_mod',
560 'bignum_mod_raw',
561 'bignum.generated',
562 'bignum.misc',
563 ],
Valerio Settif01d6482023-08-04 13:51:18 +0200564 'ignored_tests': {
565 # Ignore all tests that require DERIVE support which is disabled
566 # in the driver version
567 'test_suite_psa_crypto': [
568 'PSA key agreement setup: ECDH + HKDF-SHA-256: good',
569 ('PSA key agreement setup: ECDH + HKDF-SHA-256: good, key algorithm broader '
570 'than required'),
571 'PSA key agreement setup: ECDH + HKDF-SHA-256: public key not on curve',
572 'PSA key agreement setup: KDF instead of a key agreement algorithm',
573 'PSA key agreement setup: bad key agreement algorithm',
574 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: capacity=8160',
575 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 0+32',
576 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 1+31',
577 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 31+1',
578 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 32+0',
579 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 32+32',
580 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 64+0',
581 'PSA key derivation: ECDH on P256 with HKDF-SHA256, info first',
582 'PSA key derivation: ECDH on P256 with HKDF-SHA256, key output',
583 'PSA key derivation: ECDH on P256 with HKDF-SHA256, missing info',
584 'PSA key derivation: ECDH on P256 with HKDF-SHA256, omitted salt',
585 'PSA key derivation: ECDH on P256 with HKDF-SHA256, raw output',
586 'PSA key derivation: ECDH on P256 with HKDF-SHA256, salt after secret',
587 'PSA key derivation: ECDH with TLS 1.2 PRF SHA-256, good case',
588 'PSA key derivation: ECDH with TLS 1.2 PRF SHA-256, missing label',
589 'PSA key derivation: ECDH with TLS 1.2 PRF SHA-256, missing label and secret',
590 'PSA key derivation: ECDH with TLS 1.2 PRF SHA-256, no inputs',
591 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
592 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
593 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
594 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, SHA-256, 0+48, ka',
595 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, SHA-256, 24+24, ka',
596 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, SHA-256, 48+0, ka',
597 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, bad state #1, ka',
598 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, bad state #3, ka',
599 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, bad state #4, ka',
600 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)',
601 'PSA key derivation: bits=7 invalid for ECC MONTGOMERY (ECC enabled)',
602 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)',
603 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)',
604 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)',
605 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)',
606 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)',
607 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)',
608 'PSA raw key agreement: ECDH SECP256R1 (RFC 5903)',
609 ],
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200610 'test_suite_random': [
611 'PSA classic wrapper: ECDSA signature (SECP256R1)',
612 ],
Valerio Settif01d6482023-08-04 13:51:18 +0200613 'test_suite_psa_crypto_pake': [
614 'PSA PAKE: ecjpake size macros',
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200615 ],
616 'test_suite_asn1parse': [
617 # This test depends on BIGNUM_C
618 'INTEGER too large for mpi',
619 ],
620 'test_suite_asn1write': [
621 # Following tests depends on BIGNUM_C
622 'ASN.1 Write mpi 0 (1 limb)',
623 'ASN.1 Write mpi 0 (null)',
624 'ASN.1 Write mpi 0x100',
625 'ASN.1 Write mpi 0x7f',
626 'ASN.1 Write mpi 0x7f with leading 0 limb',
627 'ASN.1 Write mpi 0x80',
628 'ASN.1 Write mpi 0x80 with leading 0 limb',
629 'ASN.1 Write mpi 0xff',
630 'ASN.1 Write mpi 1',
631 'ASN.1 Write mpi, 127*8 bits',
632 'ASN.1 Write mpi, 127*8+1 bits',
633 'ASN.1 Write mpi, 127*8-1 bits',
634 'ASN.1 Write mpi, 255*8 bits',
635 'ASN.1 Write mpi, 255*8-1 bits',
636 'ASN.1 Write mpi, 256*8-1 bits',
637 ],
Valerio Settif01d6482023-08-04 13:51:18 +0200638 }
639 }
640 }
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200641}
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200642
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200643def main():
Valerio Settif075e472023-10-17 11:03:16 +0200644 main_results = Results()
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200645
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200646 try:
647 parser = argparse.ArgumentParser(description=__doc__)
Przemek Stekiel58bbc232022-10-24 08:10:10 +0200648 parser.add_argument('outcomes', metavar='OUTCOMES.CSV',
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200649 help='Outcome file to analyze')
Valerio Settidfd7ca62023-10-09 16:30:11 +0200650 parser.add_argument('specified_tasks', default='all', nargs='?',
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100651 help='Analysis to be done. By default, run all tasks. '
652 'With one or more TASK, run only those. '
653 'TASK can be the name of a single task or '
Przemek Stekiel85c54ea2022-11-17 11:50:23 +0100654 'comma/space-separated list of tasks. ')
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100655 parser.add_argument('--list', action='store_true',
656 help='List all available tasks and exit.')
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100657 parser.add_argument('--require-full-coverage', action='store_true',
658 dest='full_coverage', help="Require all available "
659 "test cases to be executed and issue an error "
660 "otherwise. This flag is ignored if 'task' is "
661 "neither 'all' nor 'analyze_coverage'")
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200662 options = parser.parse_args()
Przemek Stekiel4e955902022-10-21 13:42:08 +0200663
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100664 if options.list:
Valerio Settidfd7ca62023-10-09 16:30:11 +0200665 for task in KNOWN_TASKS:
Valerio Setti5329ff02023-10-17 09:44:36 +0200666 print(task)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100667 sys.exit(0)
668
Valerio Settidfd7ca62023-10-09 16:30:11 +0200669 if options.specified_tasks == 'all':
670 tasks_list = KNOWN_TASKS.keys()
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100671 else:
Valerio Settidfd7ca62023-10-09 16:30:11 +0200672 tasks_list = re.split(r'[, ]+', options.specified_tasks)
Valerio Settidfd7ca62023-10-09 16:30:11 +0200673 for task in tasks_list:
674 if task not in KNOWN_TASKS:
Valerio Settifb2750e2023-10-17 10:11:45 +0200675 sys.stderr.write('invalid task: {}'.format(task))
676 sys.exit(2)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100677
Valerio Settidfd7ca62023-10-09 16:30:11 +0200678 KNOWN_TASKS['analyze_coverage']['args']['full_coverage'] = options.full_coverage
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100679
Valerio Settifb2750e2023-10-17 10:11:45 +0200680 for task in tasks_list:
681 test_function = KNOWN_TASKS[task]['test_function']
682 test_args = KNOWN_TASKS[task]['args']
Valerio Setti781c2342023-10-17 12:47:35 +0200683 test_function(main_results, options.outcomes, test_args)
Valerio Settidfd7ca62023-10-09 16:30:11 +0200684
Valerio Settif6f64cf2023-10-17 12:28:26 +0200685 main_results.info("Overall results: {} warnings and {} errors",
686 main_results.warning_count, main_results.error_count)
Valerio Settif075e472023-10-17 11:03:16 +0200687
Valerio Setti8d178be2023-10-17 12:23:55 +0200688 sys.exit(0 if (main_results.error_count == 0) else 1)
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200689
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200690 except Exception: # pylint: disable=broad-except
691 # Print the backtrace and exit explicitly with our chosen status.
692 traceback.print_exc()
693 sys.exit(120)
694
695if __name__ == '__main__':
696 main()