blob: b522efb31630a93a7f68ede2399b74fcaae2e07f [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 Setti39d4b9d2023-10-18 14:30:03 +020067 results.info("Outcome file ({}) already exists. Tests will be skipped.", outcome_file)
Valerio Setti781c2342023-10-17 12:47:35 +020068 return
Valerio Settia2663322023-03-24 08:20:18 +010069
70 shell_command = "tests/scripts/all.sh --outcome-file " + outcome_file + \
71 " " + ref_component + " " + driver_component
Valerio Setti39d4b9d2023-10-18 14:30:03 +020072 results.info("Running: {}", shell_command)
Valerio Settia2663322023-03-24 08:20:18 +010073 ret_val = subprocess.run(shell_command.split(), check=False).returncode
74
75 if ret_val != 0:
Valerio Settif075e472023-10-17 11:03:16 +020076 results.error("failed to run reference/driver components")
Valerio Settiaaef0bc2023-10-10 09:42:13 +020077
Tomás Gonzálezb401e112023-08-11 15:22:04 +010078def analyze_coverage(results, outcomes, allow_list, full_coverage):
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020079 """Check that all available test cases are executed at least once."""
Gilles Peskine686c2922022-01-07 15:58:38 +010080 available = check_test_cases.collect_available_test_cases()
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020081 for key in available:
82 hits = outcomes[key].hits() if key in outcomes else 0
Tomás González07bdcc22023-08-11 14:59:03 +010083 if hits == 0 and key not in allow_list:
Tomás Gonzálezb401e112023-08-11 15:22:04 +010084 if full_coverage:
85 results.error('Test case not executed: {}', key)
86 else:
87 results.warning('Test case not executed: {}', key)
Tomás González07bdcc22023-08-11 14:59:03 +010088 elif hits != 0 and key in allow_list:
89 # Test Case should be removed from the allow list.
Tomás González7ebb18f2023-08-22 09:40:23 +010090 if full_coverage:
Tomás Gonzáleza0631442023-08-22 12:17:57 +010091 results.error('Allow listed test case was executed: {}', key)
Tomás González7ebb18f2023-08-22 09:40:23 +010092 else:
93 results.warning('Allow listed test case was executed: {}', key)
Gilles Peskine8d3c70a2020-06-25 18:37:43 +020094
Valerio Settif075e472023-10-17 11:03:16 +020095def analyze_driver_vs_reference(results: Results, outcomes,
Valerio Settiaaef0bc2023-10-10 09:42:13 +020096 component_ref, component_driver,
Valerio Setti3002c992023-01-18 17:28:36 +010097 ignored_suites, ignored_test=None):
Przemek Stekiel4e955902022-10-21 13:42:08 +020098 """Check that all tests executed in the reference component are also
99 executed in the corresponding driver component.
Valerio Setti3002c992023-01-18 17:28:36 +0100100 Skip:
101 - full test suites provided in ignored_suites list
102 - only some specific test inside a test suite, for which the corresponding
103 output string is provided
Przemek Stekiel4e955902022-10-21 13:42:08 +0200104 """
Przemek Stekiel4e955902022-10-21 13:42:08 +0200105 available = check_test_cases.collect_available_test_cases()
Przemek Stekiel4e955902022-10-21 13:42:08 +0200106
107 for key in available:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200108 # Continue if test was not executed by any component
109 hits = outcomes[key].hits() if key in outcomes else 0
Przemek Stekielc86dedf2022-10-24 09:16:04 +0200110 if hits == 0:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200111 continue
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100112 # Skip ignored test suites
113 full_test_suite = key.split(';')[0] # retrieve full test suite name
114 test_string = key.split(';')[1] # retrieve the text string of this test
115 test_suite = full_test_suite.split('.')[0] # retrieve main part of test suite name
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100116 if test_suite in ignored_suites or full_test_suite in ignored_suites:
Valerio Setti00c1ccb2023-02-02 11:33:31 +0100117 continue
Valerio Setti3002c992023-01-18 17:28:36 +0100118 if ((full_test_suite in ignored_test) and
119 (test_string in ignored_test[full_test_suite])):
120 continue
Przemek Stekiel4e955902022-10-21 13:42:08 +0200121 # Search for tests that run in reference component and not in driver component
122 driver_test_passed = False
123 reference_test_passed = False
124 for entry in outcomes[key].successes:
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100125 if component_driver in entry:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200126 driver_test_passed = True
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100127 if component_ref in entry:
Przemek Stekiel4e955902022-10-21 13:42:08 +0200128 reference_test_passed = True
Manuel Pégourié-Gonnardc6967d22022-12-30 13:40:34 +0100129 if(reference_test_passed and not driver_test_passed):
Valerio Setti39d4b9d2023-10-18 14:30:03 +0200130 results.error("Did not pass with driver: {}", key)
Przemek Stekiel4e955902022-10-21 13:42:08 +0200131
Valerio Setti781c2342023-10-17 12:47:35 +0200132def analyze_outcomes(results: Results, outcomes, args):
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200133 """Run all analyses on the given outcome collection."""
Valerio Settif075e472023-10-17 11:03:16 +0200134 analyze_coverage(results, outcomes, args['allow_list'],
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100135 args['full_coverage'])
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200136
137def read_outcome_file(outcome_file):
138 """Parse an outcome file and return an outcome collection.
139
140An outcome collection is a dictionary mapping keys to TestCaseOutcomes objects.
141The keys are the test suite name and the test case description, separated
142by a semicolon.
143"""
144 outcomes = {}
145 with open(outcome_file, 'r', encoding='utf-8') as input_file:
146 for line in input_file:
147 (platform, config, suite, case, result, _cause) = line.split(';')
148 key = ';'.join([suite, case])
149 setup = ';'.join([platform, config])
150 if key not in outcomes:
151 outcomes[key] = TestCaseOutcomes()
152 if result == 'PASS':
153 outcomes[key].successes.append(setup)
154 elif result == 'FAIL':
155 outcomes[key].failures.append(setup)
156 return outcomes
157
Valerio Setti781c2342023-10-17 12:47:35 +0200158def do_analyze_coverage(results: Results, outcome_file, args):
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100159 """Perform coverage analysis."""
Valerio Setti40314fc2023-10-17 11:34:31 +0200160 results.info("*** Analyze coverage ***")
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200161 outcomes = read_outcome_file(outcome_file)
Valerio Setti781c2342023-10-17 12:47:35 +0200162 analyze_outcomes(results, outcomes, args)
Przemek Stekiel4e955902022-10-21 13:42:08 +0200163
Valerio Setti781c2342023-10-17 12:47:35 +0200164def do_analyze_driver_vs_reference(results: Results, outcome_file, args):
Przemek Stekiel4e955902022-10-21 13:42:08 +0200165 """Perform driver vs reference analyze."""
Valerio Setti39d4b9d2023-10-18 14:30:03 +0200166 results.info("*** Analyze driver {} vs reference {} ***",
167 args['component_driver'], args['component_ref'])
Valerio Settib0c618e2023-10-16 14:19:49 +0200168
Valerio Setti781c2342023-10-17 12:47:35 +0200169 execute_reference_driver_tests(results, args['component_ref'], \
170 args['component_driver'], outcome_file)
Valerio Settia2663322023-03-24 08:20:18 +0100171
Valerio Setti3002c992023-01-18 17:28:36 +0100172 ignored_suites = ['test_suite_' + x for x in args['ignored_suites']]
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100173
Przemek Stekiel4e955902022-10-21 13:42:08 +0200174 outcomes = read_outcome_file(outcome_file)
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200175
Valerio Setti781c2342023-10-17 12:47:35 +0200176 analyze_driver_vs_reference(results, outcomes,
177 args['component_ref'], args['component_driver'],
178 ignored_suites, args['ignored_tests'])
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200179
Przemek Stekiel6856f4c2022-11-09 10:50:29 +0100180# List of tasks with a function that can handle this task and additional arguments if required
Valerio Settidfd7ca62023-10-09 16:30:11 +0200181KNOWN_TASKS = {
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200182 'analyze_coverage': {
183 'test_function': do_analyze_coverage,
Tomás González07bdcc22023-08-11 14:59:03 +0100184 'args': {
Tomás González358c6c62023-08-14 15:43:46 +0100185 'allow_list': [
Tomás González50223112023-08-22 09:52:06 +0100186 # Algorithm not supported yet
187 'test_suite_psa_crypto_metadata;Asymmetric signature: pure EdDSA',
188 # Algorithm not supported yet
189 'test_suite_psa_crypto_metadata;Cipher: XTS',
Tomás Gonzálezd43cab32023-08-24 09:12:40 +0100190 ],
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100191 'full_coverage': False,
Tomás González07bdcc22023-08-11 14:59:03 +0100192 }
Tomás Gonzálezd43cab32023-08-24 09:12:40 +0100193 },
Valerio Settia2663322023-03-24 08:20:18 +0100194 # There are 2 options to use analyze_driver_vs_reference_xxx locally:
195 # 1. Run tests and then analysis:
196 # - tests/scripts/all.sh --outcome-file "$PWD/out.csv" <component_ref> <component_driver>
197 # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
198 # 2. Let this script run both automatically:
199 # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200200 'analyze_driver_vs_reference_hash': {
201 'test_function': do_analyze_driver_vs_reference,
202 'args': {
Przemek Stekiel51f30ff2022-11-09 12:07:29 +0100203 'component_ref': 'test_psa_crypto_config_reference_hash_use_psa',
204 'component_driver': 'test_psa_crypto_config_accel_hash_use_psa',
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +0100205 'ignored_suites': [
206 'shax', 'mdx', # the software implementations that are being excluded
Manuel Pégourié-Gonnard7d381f52023-03-17 15:13:08 +0100207 'md.psa', # purposefully depends on whether drivers are present
Gilles Peskine35b49c42023-10-04 12:28:41 +0200208 'psa_crypto_low_hash.generated', # testing the builtins
Valerio Setti3002c992023-01-18 17:28:36 +0100209 ],
210 'ignored_tests': {
211 }
212 }
213 },
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200214 'analyze_driver_vs_reference_ecp_light_only': {
Valerio Setti42d5f192023-03-20 13:54:41 +0100215 'test_function': do_analyze_driver_vs_reference,
216 'args': {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200217 'component_ref': 'test_psa_crypto_config_reference_ecc_ecp_light_only',
218 'component_driver': 'test_psa_crypto_config_accel_ecc_ecp_light_only',
Valerio Setti42d5f192023-03-20 13:54:41 +0100219 'ignored_suites': [
220 'ecdsa',
221 'ecdh',
222 'ecjpake',
223 ],
224 'ignored_tests': {
225 'test_suite_random': [
226 'PSA classic wrapper: ECDSA signature (SECP256R1)',
227 ],
Valerio Setti0c477d32023-04-07 15:54:20 +0200228 # In the accelerated test ECP_C is not set (only ECP_LIGHT is)
229 # so we must ignore disparities in the tests for which ECP_C
230 # is required.
231 'test_suite_ecp': [
232 'ECP check public-private #1 (OK)',
233 'ECP check public-private #2 (group none)',
234 'ECP check public-private #3 (group mismatch)',
235 'ECP check public-private #4 (Qx mismatch)',
236 'ECP check public-private #5 (Qy mismatch)',
237 'ECP check public-private #6 (wrong Qx)',
238 'ECP check public-private #7 (wrong Qy)',
239 'ECP gen keypair [#1]',
240 'ECP gen keypair [#2]',
241 'ECP gen keypair [#3]',
242 'ECP gen keypair wrapper',
243 'ECP point muladd secp256r1 #1',
244 'ECP point muladd secp256r1 #2',
245 'ECP point multiplication Curve25519 (element of order 2: origin) #3',
246 'ECP point multiplication Curve25519 (element of order 4: 1) #4',
247 'ECP point multiplication Curve25519 (element of order 8) #5',
248 'ECP point multiplication Curve25519 (normalized) #1',
249 'ECP point multiplication Curve25519 (not normalized) #2',
250 'ECP point multiplication rng fail Curve25519',
251 'ECP point multiplication rng fail secp256r1',
252 'ECP test vectors Curve25519',
253 'ECP test vectors Curve448 (RFC 7748 6.2, after decodeUCoordinate)',
254 'ECP test vectors brainpoolP256r1 rfc 7027',
255 'ECP test vectors brainpoolP384r1 rfc 7027',
256 'ECP test vectors brainpoolP512r1 rfc 7027',
257 'ECP test vectors secp192k1',
258 'ECP test vectors secp192r1 rfc 5114',
259 'ECP test vectors secp224k1',
260 'ECP test vectors secp224r1 rfc 5114',
261 'ECP test vectors secp256k1',
262 'ECP test vectors secp256r1 rfc 5114',
263 'ECP test vectors secp384r1 rfc 5114',
264 'ECP test vectors secp521r1 rfc 5114',
Valerio Settie50a75f2023-05-19 17:43:06 +0200265 ],
Valerio Setti482a0b92023-08-18 15:55:10 +0200266 'test_suite_psa_crypto': [
267 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
268 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
269 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
270 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1',
271 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0',
272 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1',
273 ],
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200274 'test_suite_ssl': [
275 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
276 ],
Valerio Setti5f540202023-06-30 17:20:49 +0200277 }
Valerio Setti42d5f192023-03-20 13:54:41 +0100278 }
279 },
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200280 'analyze_driver_vs_reference_no_ecp_at_all': {
Valerio Settie618cb02023-04-12 14:59:16 +0200281 'test_function': do_analyze_driver_vs_reference,
282 'args': {
Valerio Setti4d25a8d2023-06-14 10:33:10 +0200283 'component_ref': 'test_psa_crypto_config_reference_ecc_no_ecp_at_all',
284 'component_driver': 'test_psa_crypto_config_accel_ecc_no_ecp_at_all',
Valerio Settie618cb02023-04-12 14:59:16 +0200285 'ignored_suites': [
286 # Ignore test suites for the modules that are disabled in the
287 # accelerated test case.
288 'ecp',
289 'ecdsa',
290 'ecdh',
291 'ecjpake',
292 ],
293 'ignored_tests': {
294 'test_suite_random': [
295 'PSA classic wrapper: ECDSA signature (SECP256R1)',
296 ],
297 'test_suite_psa_crypto': [
298 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
299 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
300 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
301 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1',
302 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0',
303 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1',
304 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)',
305 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)',
306 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)',
307 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)',
308 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)',
309 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)',
310 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)',
Valerio Settiaddeee42023-06-14 10:46:55 +0200311 ],
312 'test_suite_pkparse': [
Valerio Setti5bd25232023-06-19 19:32:14 +0200313 # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED
314 # is automatically enabled in build_info.h (backward compatibility)
315 # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a
316 # consequence compressed points are supported in the reference
317 # component but not in the accelerated one, so they should be skipped
318 # while checking driver's coverage.
319 'Parse EC Key #10a (SEC1 PEM, secp384r1, compressed)',
320 'Parse EC Key #11a (SEC1 PEM, secp521r1, compressed)',
321 'Parse EC Key #12a (SEC1 PEM, bp256r1, compressed)',
322 'Parse EC Key #13a (SEC1 PEM, bp384r1, compressed)',
323 'Parse EC Key #14a (SEC1 PEM, bp512r1, compressed)',
324 'Parse EC Key #2a (SEC1 PEM, secp192r1, compressed)',
325 'Parse EC Key #8a (SEC1 PEM, secp224r1, compressed)',
326 'Parse EC Key #9a (SEC1 PEM, secp256r1, compressed)',
327 'Parse Public EC Key #2a (RFC 5480, PEM, secp192r1, compressed)',
328 'Parse Public EC Key #3a (RFC 5480, secp224r1, compressed)',
329 'Parse Public EC Key #4a (RFC 5480, secp256r1, compressed)',
330 'Parse Public EC Key #5a (RFC 5480, secp384r1, compressed)',
331 'Parse Public EC Key #6a (RFC 5480, secp521r1, compressed)',
332 'Parse Public EC Key #7a (RFC 5480, brainpoolP256r1, compressed)',
333 'Parse Public EC Key #8a (RFC 5480, brainpoolP384r1, compressed)',
334 'Parse Public EC Key #9a (RFC 5480, brainpoolP512r1, compressed)',
Valerio Settiaddeee42023-06-14 10:46:55 +0200335 ],
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200336 'test_suite_ssl': [
337 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
338 ],
Valerio Settie618cb02023-04-12 14:59:16 +0200339 }
340 }
341 },
Valerio Setti307810b2023-08-15 10:12:25 +0200342 'analyze_driver_vs_reference_ecc_no_bignum': {
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200343 'test_function': do_analyze_driver_vs_reference,
344 'args': {
345 'component_ref': 'test_psa_crypto_config_reference_ecc_no_bignum',
346 'component_driver': 'test_psa_crypto_config_accel_ecc_no_bignum',
347 'ignored_suites': [
348 # Ignore test suites for the modules that are disabled in the
349 # accelerated test case.
350 'ecp',
351 'ecdsa',
352 'ecdh',
353 'ecjpake',
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200354 'bignum_core',
355 'bignum_random',
356 'bignum_mod',
357 'bignum_mod_raw',
358 'bignum.generated',
359 'bignum.misc',
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200360 ],
361 'ignored_tests': {
362 'test_suite_random': [
363 'PSA classic wrapper: ECDSA signature (SECP256R1)',
364 ],
365 'test_suite_psa_crypto': [
366 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
367 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
368 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
369 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1',
370 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0',
371 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1',
372 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)',
373 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)',
374 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)',
375 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)',
376 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)',
377 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)',
378 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)',
379 ],
380 'test_suite_pkparse': [
381 # See the description provided above in the
382 # analyze_driver_vs_reference_no_ecp_at_all component.
383 'Parse EC Key #10a (SEC1 PEM, secp384r1, compressed)',
384 'Parse EC Key #11a (SEC1 PEM, secp521r1, compressed)',
385 'Parse EC Key #12a (SEC1 PEM, bp256r1, compressed)',
386 'Parse EC Key #13a (SEC1 PEM, bp384r1, compressed)',
387 'Parse EC Key #14a (SEC1 PEM, bp512r1, compressed)',
388 'Parse EC Key #2a (SEC1 PEM, secp192r1, compressed)',
389 'Parse EC Key #8a (SEC1 PEM, secp224r1, compressed)',
390 'Parse EC Key #9a (SEC1 PEM, secp256r1, compressed)',
391 'Parse Public EC Key #2a (RFC 5480, PEM, secp192r1, compressed)',
392 'Parse Public EC Key #3a (RFC 5480, secp224r1, compressed)',
393 'Parse Public EC Key #4a (RFC 5480, secp256r1, compressed)',
394 'Parse Public EC Key #5a (RFC 5480, secp384r1, compressed)',
395 'Parse Public EC Key #6a (RFC 5480, secp521r1, compressed)',
396 'Parse Public EC Key #7a (RFC 5480, brainpoolP256r1, compressed)',
397 'Parse Public EC Key #8a (RFC 5480, brainpoolP384r1, compressed)',
398 'Parse Public EC Key #9a (RFC 5480, brainpoolP512r1, compressed)',
399 ],
Valerio Setti9b3dbcc2023-07-26 18:00:31 +0200400 'test_suite_asn1parse': [
401 # This test depends on BIGNUM_C
402 'INTEGER too large for mpi',
403 ],
404 'test_suite_asn1write': [
405 # Following tests depends on BIGNUM_C
406 'ASN.1 Write mpi 0 (1 limb)',
407 'ASN.1 Write mpi 0 (null)',
408 'ASN.1 Write mpi 0x100',
409 'ASN.1 Write mpi 0x7f',
410 'ASN.1 Write mpi 0x7f with leading 0 limb',
411 'ASN.1 Write mpi 0x80',
412 'ASN.1 Write mpi 0x80 with leading 0 limb',
413 'ASN.1 Write mpi 0xff',
414 'ASN.1 Write mpi 1',
415 'ASN.1 Write mpi, 127*8 bits',
416 'ASN.1 Write mpi, 127*8+1 bits',
417 'ASN.1 Write mpi, 127*8-1 bits',
418 'ASN.1 Write mpi, 255*8 bits',
419 'ASN.1 Write mpi, 255*8-1 bits',
420 'ASN.1 Write mpi, 256*8-1 bits',
421 ],
Valerio Settie0be95e2023-08-01 09:07:43 +0200422 'test_suite_debug': [
423 # Following tests depends on BIGNUM_C
424 'Debug print mbedtls_mpi #2: 3 bits',
425 'Debug print mbedtls_mpi: 0 (empty representation)',
426 'Debug print mbedtls_mpi: 0 (non-empty representation)',
427 'Debug print mbedtls_mpi: 49 bits',
428 'Debug print mbedtls_mpi: 759 bits',
429 'Debug print mbedtls_mpi: 764 bits #1',
430 'Debug print mbedtls_mpi: 764 bits #2',
431 ],
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200432 'test_suite_ssl': [
433 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
434 ],
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +0200435 }
436 }
437 },
Valerio Setti307810b2023-08-15 10:12:25 +0200438 'analyze_driver_vs_reference_ecc_ffdh_no_bignum': {
439 'test_function': do_analyze_driver_vs_reference,
440 'args': {
441 'component_ref': 'test_psa_crypto_config_reference_ecc_ffdh_no_bignum',
442 'component_driver': 'test_psa_crypto_config_accel_ecc_ffdh_no_bignum',
443 'ignored_suites': [
444 # Ignore test suites for the modules that are disabled in the
445 # accelerated test case.
446 'ecp',
447 'ecdsa',
448 'ecdh',
449 'ecjpake',
450 'bignum_core',
451 'bignum_random',
452 'bignum_mod',
453 'bignum_mod_raw',
454 'bignum.generated',
455 'bignum.misc',
456 'dhm',
457 ],
458 'ignored_tests': {
459 'test_suite_random': [
460 'PSA classic wrapper: ECDSA signature (SECP256R1)',
461 ],
462 'test_suite_psa_crypto': [
463 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
464 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
465 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
466 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1',
467 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0',
468 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1',
469 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)',
470 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)',
471 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)',
472 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)',
473 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)',
474 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)',
475 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)',
476 ],
477 'test_suite_pkparse': [
478 # See the description provided above in the
479 # analyze_driver_vs_reference_no_ecp_at_all component.
480 'Parse EC Key #10a (SEC1 PEM, secp384r1, compressed)',
481 'Parse EC Key #11a (SEC1 PEM, secp521r1, compressed)',
482 'Parse EC Key #12a (SEC1 PEM, bp256r1, compressed)',
483 'Parse EC Key #13a (SEC1 PEM, bp384r1, compressed)',
484 'Parse EC Key #14a (SEC1 PEM, bp512r1, compressed)',
485 'Parse EC Key #2a (SEC1 PEM, secp192r1, compressed)',
486 'Parse EC Key #8a (SEC1 PEM, secp224r1, compressed)',
487 'Parse EC Key #9a (SEC1 PEM, secp256r1, compressed)',
488 'Parse Public EC Key #2a (RFC 5480, PEM, secp192r1, compressed)',
489 'Parse Public EC Key #3a (RFC 5480, secp224r1, compressed)',
490 'Parse Public EC Key #4a (RFC 5480, secp256r1, compressed)',
491 'Parse Public EC Key #5a (RFC 5480, secp384r1, compressed)',
492 'Parse Public EC Key #6a (RFC 5480, secp521r1, compressed)',
493 'Parse Public EC Key #7a (RFC 5480, brainpoolP256r1, compressed)',
494 'Parse Public EC Key #8a (RFC 5480, brainpoolP384r1, compressed)',
495 'Parse Public EC Key #9a (RFC 5480, brainpoolP512r1, compressed)',
496 ],
497 'test_suite_asn1parse': [
498 # This test depends on BIGNUM_C
499 'INTEGER too large for mpi',
500 ],
501 'test_suite_asn1write': [
502 # Following tests depends on BIGNUM_C
503 'ASN.1 Write mpi 0 (1 limb)',
504 'ASN.1 Write mpi 0 (null)',
505 'ASN.1 Write mpi 0x100',
506 'ASN.1 Write mpi 0x7f',
507 'ASN.1 Write mpi 0x7f with leading 0 limb',
508 'ASN.1 Write mpi 0x80',
509 'ASN.1 Write mpi 0x80 with leading 0 limb',
510 'ASN.1 Write mpi 0xff',
511 'ASN.1 Write mpi 1',
512 'ASN.1 Write mpi, 127*8 bits',
513 'ASN.1 Write mpi, 127*8+1 bits',
514 'ASN.1 Write mpi, 127*8-1 bits',
515 'ASN.1 Write mpi, 255*8 bits',
516 'ASN.1 Write mpi, 255*8-1 bits',
517 'ASN.1 Write mpi, 256*8-1 bits',
518 ],
519 'test_suite_debug': [
520 # Following tests depends on BIGNUM_C
521 'Debug print mbedtls_mpi #2: 3 bits',
522 'Debug print mbedtls_mpi: 0 (empty representation)',
523 'Debug print mbedtls_mpi: 0 (non-empty representation)',
524 'Debug print mbedtls_mpi: 49 bits',
525 'Debug print mbedtls_mpi: 759 bits',
526 'Debug print mbedtls_mpi: 764 bits #1',
527 'Debug print mbedtls_mpi: 764 bits #2',
528 ],
Manuel Pégourié-Gonnardf07ce3b2023-09-22 11:53:41 +0200529 'test_suite_ssl': [
530 'Test configuration of groups for DHE through mbedtls_ssl_conf_curves()',
531 ],
Valerio Setti307810b2023-08-15 10:12:25 +0200532 }
533 }
534 },
Przemek Stekiel85b64422023-05-26 09:55:23 +0200535 'analyze_driver_vs_reference_ffdh_alg': {
536 'test_function': do_analyze_driver_vs_reference,
537 'args': {
538 'component_ref': 'test_psa_crypto_config_reference_ffdh',
539 'component_driver': 'test_psa_crypto_config_accel_ffdh',
Przemek Stekiel84f4ff12023-07-04 12:35:31 +0200540 'ignored_suites': ['dhm'],
Przemek Stekiel565353e2023-07-05 11:07:07 +0200541 'ignored_tests': {}
Przemek Stekiel85b64422023-05-26 09:55:23 +0200542 }
543 },
Valerio Settif01d6482023-08-04 13:51:18 +0200544 'analyze_driver_vs_reference_tfm_config': {
545 'test_function': do_analyze_driver_vs_reference,
546 'args': {
547 'component_ref': 'test_tfm_config',
548 'component_driver': 'test_tfm_config_p256m_driver_accel_ec',
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200549 'ignored_suites': [
550 # Ignore test suites for the modules that are disabled in the
551 # accelerated test case.
552 'ecp',
553 'ecdsa',
554 'ecdh',
555 'ecjpake',
556 'bignum_core',
557 'bignum_random',
558 'bignum_mod',
559 'bignum_mod_raw',
560 'bignum.generated',
561 'bignum.misc',
562 ],
Valerio Settif01d6482023-08-04 13:51:18 +0200563 'ignored_tests': {
564 # Ignore all tests that require DERIVE support which is disabled
565 # in the driver version
566 'test_suite_psa_crypto': [
567 'PSA key agreement setup: ECDH + HKDF-SHA-256: good',
568 ('PSA key agreement setup: ECDH + HKDF-SHA-256: good, key algorithm broader '
569 'than required'),
570 'PSA key agreement setup: ECDH + HKDF-SHA-256: public key not on curve',
571 'PSA key agreement setup: KDF instead of a key agreement algorithm',
572 'PSA key agreement setup: bad key agreement algorithm',
573 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: capacity=8160',
574 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 0+32',
575 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 1+31',
576 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 31+1',
577 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 32+0',
578 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 32+32',
579 'PSA key agreement: ECDH SECP256R1 (RFC 5903) + HKDF-SHA-256: read 64+0',
580 'PSA key derivation: ECDH on P256 with HKDF-SHA256, info first',
581 'PSA key derivation: ECDH on P256 with HKDF-SHA256, key output',
582 'PSA key derivation: ECDH on P256 with HKDF-SHA256, missing info',
583 'PSA key derivation: ECDH on P256 with HKDF-SHA256, omitted salt',
584 'PSA key derivation: ECDH on P256 with HKDF-SHA256, raw output',
585 'PSA key derivation: ECDH on P256 with HKDF-SHA256, salt after secret',
586 'PSA key derivation: ECDH with TLS 1.2 PRF SHA-256, good case',
587 'PSA key derivation: ECDH with TLS 1.2 PRF SHA-256, missing label',
588 'PSA key derivation: ECDH with TLS 1.2 PRF SHA-256, missing label and secret',
589 'PSA key derivation: ECDH with TLS 1.2 PRF SHA-256, no inputs',
590 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1',
591 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)',
592 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA',
593 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, SHA-256, 0+48, ka',
594 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, SHA-256, 24+24, ka',
595 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, SHA-256, 48+0, ka',
596 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, bad state #1, ka',
597 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, bad state #3, ka',
598 'PSA key derivation: TLS 1.2 Mix-PSK-to-MS, bad state #4, ka',
599 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)',
600 'PSA key derivation: bits=7 invalid for ECC MONTGOMERY (ECC enabled)',
601 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)',
602 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)',
603 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)',
604 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)',
605 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)',
606 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)',
607 'PSA raw key agreement: ECDH SECP256R1 (RFC 5903)',
608 ],
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200609 'test_suite_random': [
610 'PSA classic wrapper: ECDSA signature (SECP256R1)',
611 ],
Valerio Settif01d6482023-08-04 13:51:18 +0200612 'test_suite_psa_crypto_pake': [
613 'PSA PAKE: ecjpake size macros',
Manuel Pégourié-Gonnarde9d97972023-08-08 18:34:47 +0200614 ],
615 'test_suite_asn1parse': [
616 # This test depends on BIGNUM_C
617 'INTEGER too large for mpi',
618 ],
619 'test_suite_asn1write': [
620 # Following tests depends on BIGNUM_C
621 'ASN.1 Write mpi 0 (1 limb)',
622 'ASN.1 Write mpi 0 (null)',
623 'ASN.1 Write mpi 0x100',
624 'ASN.1 Write mpi 0x7f',
625 'ASN.1 Write mpi 0x7f with leading 0 limb',
626 'ASN.1 Write mpi 0x80',
627 'ASN.1 Write mpi 0x80 with leading 0 limb',
628 'ASN.1 Write mpi 0xff',
629 'ASN.1 Write mpi 1',
630 'ASN.1 Write mpi, 127*8 bits',
631 'ASN.1 Write mpi, 127*8+1 bits',
632 'ASN.1 Write mpi, 127*8-1 bits',
633 'ASN.1 Write mpi, 255*8 bits',
634 'ASN.1 Write mpi, 255*8-1 bits',
635 'ASN.1 Write mpi, 256*8-1 bits',
636 ],
Valerio Settif01d6482023-08-04 13:51:18 +0200637 }
638 }
639 }
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200640}
Przemek Stekiel4d13c832022-10-26 16:11:26 +0200641
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200642def main():
Valerio Settif075e472023-10-17 11:03:16 +0200643 main_results = Results()
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200644
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200645 try:
646 parser = argparse.ArgumentParser(description=__doc__)
Przemek Stekiel58bbc232022-10-24 08:10:10 +0200647 parser.add_argument('outcomes', metavar='OUTCOMES.CSV',
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200648 help='Outcome file to analyze')
Valerio Settidfd7ca62023-10-09 16:30:11 +0200649 parser.add_argument('specified_tasks', default='all', nargs='?',
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100650 help='Analysis to be done. By default, run all tasks. '
651 'With one or more TASK, run only those. '
652 'TASK can be the name of a single task or '
Przemek Stekiel85c54ea2022-11-17 11:50:23 +0100653 'comma/space-separated list of tasks. ')
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100654 parser.add_argument('--list', action='store_true',
655 help='List all available tasks and exit.')
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100656 parser.add_argument('--require-full-coverage', action='store_true',
657 dest='full_coverage', help="Require all available "
658 "test cases to be executed and issue an error "
659 "otherwise. This flag is ignored if 'task' is "
660 "neither 'all' nor 'analyze_coverage'")
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200661 options = parser.parse_args()
Przemek Stekiel4e955902022-10-21 13:42:08 +0200662
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100663 if options.list:
Valerio Settidfd7ca62023-10-09 16:30:11 +0200664 for task in KNOWN_TASKS:
Valerio Setti5329ff02023-10-17 09:44:36 +0200665 print(task)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100666 sys.exit(0)
667
Valerio Settidfd7ca62023-10-09 16:30:11 +0200668 if options.specified_tasks == 'all':
669 tasks_list = KNOWN_TASKS.keys()
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100670 else:
Valerio Settidfd7ca62023-10-09 16:30:11 +0200671 tasks_list = re.split(r'[, ]+', options.specified_tasks)
Valerio Settidfd7ca62023-10-09 16:30:11 +0200672 for task in tasks_list:
673 if task not in KNOWN_TASKS:
Valerio Settifb2750e2023-10-17 10:11:45 +0200674 sys.stderr.write('invalid task: {}'.format(task))
675 sys.exit(2)
Przemek Stekiel992de3c2022-11-09 13:54:49 +0100676
Valerio Settidfd7ca62023-10-09 16:30:11 +0200677 KNOWN_TASKS['analyze_coverage']['args']['full_coverage'] = options.full_coverage
Tomás Gonzálezb401e112023-08-11 15:22:04 +0100678
Valerio Settifb2750e2023-10-17 10:11:45 +0200679 for task in tasks_list:
680 test_function = KNOWN_TASKS[task]['test_function']
681 test_args = KNOWN_TASKS[task]['args']
Valerio Setti781c2342023-10-17 12:47:35 +0200682 test_function(main_results, options.outcomes, test_args)
Valerio Settidfd7ca62023-10-09 16:30:11 +0200683
Valerio Settif6f64cf2023-10-17 12:28:26 +0200684 main_results.info("Overall results: {} warnings and {} errors",
685 main_results.warning_count, main_results.error_count)
Valerio Settif075e472023-10-17 11:03:16 +0200686
Valerio Setti8d178be2023-10-17 12:23:55 +0200687 sys.exit(0 if (main_results.error_count == 0) else 1)
Valerio Settiaaef0bc2023-10-10 09:42:13 +0200688
Gilles Peskine15c2cbf2020-06-25 18:36:28 +0200689 except Exception: # pylint: disable=broad-except
690 # Print the backtrace and exit explicitly with our chosen status.
691 traceback.print_exc()
692 sys.exit(120)
693
694if __name__ == '__main__':
695 main()