Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | """Analyze the test outcomes from a full CI run. |
| 4 | |
| 5 | This script can also run on outcomes from a partial run, but the results are |
| 6 | less likely to be useful. |
| 7 | """ |
| 8 | |
| 9 | import argparse |
| 10 | import sys |
| 11 | import traceback |
Przemek Stekiel | 85c54ea | 2022-11-17 11:50:23 +0100 | [diff] [blame] | 12 | import re |
Valerio Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 13 | import subprocess |
| 14 | import os |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 15 | |
Gilles Peskine | 8d3c70a | 2020-06-25 18:37:43 +0200 | [diff] [blame] | 16 | import check_test_cases |
| 17 | |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 18 | class Results: |
| 19 | """Process analysis results.""" |
| 20 | |
| 21 | def __init__(self): |
| 22 | self.error_count = 0 |
| 23 | self.warning_count = 0 |
| 24 | |
| 25 | @staticmethod |
| 26 | def log(fmt, *args, **kwargs): |
| 27 | sys.stderr.write((fmt + '\n').format(*args, **kwargs)) |
| 28 | |
| 29 | def error(self, fmt, *args, **kwargs): |
| 30 | self.log('Error: ' + fmt, *args, **kwargs) |
| 31 | self.error_count += 1 |
| 32 | |
| 33 | def warning(self, fmt, *args, **kwargs): |
| 34 | self.log('Warning: ' + fmt, *args, **kwargs) |
| 35 | self.warning_count += 1 |
| 36 | |
| 37 | class TestCaseOutcomes: |
| 38 | """The outcomes of one test case across many configurations.""" |
| 39 | # pylint: disable=too-few-public-methods |
| 40 | |
| 41 | def __init__(self): |
Gilles Peskine | 3d863f2 | 2020-06-26 13:02:30 +0200 | [diff] [blame] | 42 | # Collect a list of witnesses of the test case succeeding or failing. |
| 43 | # Currently we don't do anything with witnesses except count them. |
| 44 | # The format of a witness is determined by the read_outcome_file |
| 45 | # function; it's the platform and configuration joined by ';'. |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 46 | self.successes = [] |
| 47 | self.failures = [] |
| 48 | |
| 49 | def hits(self): |
| 50 | """Return the number of times a test case has been run. |
| 51 | |
| 52 | This includes passes and failures, but not skips. |
| 53 | """ |
| 54 | return len(self.successes) + len(self.failures) |
| 55 | |
Valerio Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 56 | def execute_reference_driver_tests(ref_component, driver_component, outcome_file): |
Valerio Setti | 22992a0 | 2023-03-29 11:15:28 +0200 | [diff] [blame] | 57 | """Run the tests specified in ref_component and driver_component. Results |
| 58 | are stored in the output_file and they will be used for the following |
Valerio Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 59 | coverage analysis""" |
| 60 | # If the outcome file already exists, we assume that the user wants to |
| 61 | # perform the comparison analysis again without repeating the tests. |
| 62 | if os.path.exists(outcome_file): |
| 63 | Results.log("Outcome file (" + outcome_file + ") already exists. " + \ |
| 64 | "Tests will be skipped.") |
| 65 | return |
| 66 | |
| 67 | shell_command = "tests/scripts/all.sh --outcome-file " + outcome_file + \ |
| 68 | " " + ref_component + " " + driver_component |
Valerio Setti | f109c66 | 2023-03-29 11:15:44 +0200 | [diff] [blame] | 69 | Results.log("Running: " + shell_command) |
Valerio Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 70 | ret_val = subprocess.run(shell_command.split(), check=False).returncode |
| 71 | |
| 72 | if ret_val != 0: |
| 73 | Results.log("Error: failed to run reference/driver components") |
| 74 | sys.exit(ret_val) |
| 75 | |
Gilles Peskine | 8d3c70a | 2020-06-25 18:37:43 +0200 | [diff] [blame] | 76 | def analyze_coverage(results, outcomes): |
| 77 | """Check that all available test cases are executed at least once.""" |
Gilles Peskine | 686c292 | 2022-01-07 15:58:38 +0100 | [diff] [blame] | 78 | available = check_test_cases.collect_available_test_cases() |
Gilles Peskine | 8d3c70a | 2020-06-25 18:37:43 +0200 | [diff] [blame] | 79 | for key in available: |
| 80 | hits = outcomes[key].hits() if key in outcomes else 0 |
| 81 | if hits == 0: |
| 82 | # Make this a warning, not an error, as long as we haven't |
| 83 | # fixed this branch to have full coverage of test cases. |
| 84 | results.warning('Test case not executed: {}', key) |
| 85 | |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 86 | def analyze_driver_vs_reference(outcomes, component_ref, component_driver, |
| 87 | ignored_suites, ignored_test=None): |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 88 | """Check that all tests executed in the reference component are also |
| 89 | executed in the corresponding driver component. |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 90 | Skip: |
| 91 | - full test suites provided in ignored_suites list |
| 92 | - only some specific test inside a test suite, for which the corresponding |
| 93 | output string is provided |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 94 | """ |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 95 | available = check_test_cases.collect_available_test_cases() |
| 96 | result = True |
| 97 | |
| 98 | for key in available: |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 99 | # Continue if test was not executed by any component |
| 100 | hits = outcomes[key].hits() if key in outcomes else 0 |
Przemek Stekiel | c86dedf | 2022-10-24 09:16:04 +0200 | [diff] [blame] | 101 | if hits == 0: |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 102 | continue |
Valerio Setti | 00c1ccb | 2023-02-02 11:33:31 +0100 | [diff] [blame] | 103 | # Skip ignored test suites |
| 104 | full_test_suite = key.split(';')[0] # retrieve full test suite name |
| 105 | test_string = key.split(';')[1] # retrieve the text string of this test |
| 106 | test_suite = full_test_suite.split('.')[0] # retrieve main part of test suite name |
Manuel Pégourié-Gonnard | 7d381f5 | 2023-03-17 15:13:08 +0100 | [diff] [blame] | 107 | if test_suite in ignored_suites or full_test_suite in ignored_suites: |
Valerio Setti | 00c1ccb | 2023-02-02 11:33:31 +0100 | [diff] [blame] | 108 | continue |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 109 | if ((full_test_suite in ignored_test) and |
| 110 | (test_string in ignored_test[full_test_suite])): |
| 111 | continue |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 112 | # Search for tests that run in reference component and not in driver component |
| 113 | driver_test_passed = False |
| 114 | reference_test_passed = False |
| 115 | for entry in outcomes[key].successes: |
Przemek Stekiel | 51f30ff | 2022-11-09 12:07:29 +0100 | [diff] [blame] | 116 | if component_driver in entry: |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 117 | driver_test_passed = True |
Przemek Stekiel | 51f30ff | 2022-11-09 12:07:29 +0100 | [diff] [blame] | 118 | if component_ref in entry: |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 119 | reference_test_passed = True |
Manuel Pégourié-Gonnard | c6967d2 | 2022-12-30 13:40:34 +0100 | [diff] [blame] | 120 | if(reference_test_passed and not driver_test_passed): |
Valerio Setti | 3951d1b | 2023-03-13 18:37:34 +0100 | [diff] [blame] | 121 | Results.log(key) |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 122 | result = False |
| 123 | return result |
| 124 | |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 125 | def analyze_outcomes(outcomes): |
| 126 | """Run all analyses on the given outcome collection.""" |
| 127 | results = Results() |
Gilles Peskine | 8d3c70a | 2020-06-25 18:37:43 +0200 | [diff] [blame] | 128 | analyze_coverage(results, outcomes) |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 129 | return results |
| 130 | |
| 131 | def read_outcome_file(outcome_file): |
| 132 | """Parse an outcome file and return an outcome collection. |
| 133 | |
| 134 | An outcome collection is a dictionary mapping keys to TestCaseOutcomes objects. |
| 135 | The keys are the test suite name and the test case description, separated |
| 136 | by a semicolon. |
| 137 | """ |
| 138 | outcomes = {} |
| 139 | with open(outcome_file, 'r', encoding='utf-8') as input_file: |
| 140 | for line in input_file: |
| 141 | (platform, config, suite, case, result, _cause) = line.split(';') |
| 142 | key = ';'.join([suite, case]) |
| 143 | setup = ';'.join([platform, config]) |
| 144 | if key not in outcomes: |
| 145 | outcomes[key] = TestCaseOutcomes() |
| 146 | if result == 'PASS': |
| 147 | outcomes[key].successes.append(setup) |
| 148 | elif result == 'FAIL': |
| 149 | outcomes[key].failures.append(setup) |
| 150 | return outcomes |
| 151 | |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 152 | def do_analyze_coverage(outcome_file, args): |
Przemek Stekiel | 6856f4c | 2022-11-09 10:50:29 +0100 | [diff] [blame] | 153 | """Perform coverage analysis.""" |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 154 | del args # unused |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 155 | outcomes = read_outcome_file(outcome_file) |
Valerio Setti | 3951d1b | 2023-03-13 18:37:34 +0100 | [diff] [blame] | 156 | Results.log("\n*** Analyze coverage ***\n") |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 157 | results = analyze_outcomes(outcomes) |
Przemek Stekiel | c86dedf | 2022-10-24 09:16:04 +0200 | [diff] [blame] | 158 | return results.error_count == 0 |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 159 | |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 160 | def do_analyze_driver_vs_reference(outcome_file, args): |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 161 | """Perform driver vs reference analyze.""" |
Valerio Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 162 | execute_reference_driver_tests(args['component_ref'], \ |
| 163 | args['component_driver'], outcome_file) |
| 164 | |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 165 | ignored_suites = ['test_suite_' + x for x in args['ignored_suites']] |
Przemek Stekiel | 51f30ff | 2022-11-09 12:07:29 +0100 | [diff] [blame] | 166 | |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 167 | outcomes = read_outcome_file(outcome_file) |
Valerio Setti | 3951d1b | 2023-03-13 18:37:34 +0100 | [diff] [blame] | 168 | Results.log("\n*** Analyze driver {} vs reference {} ***\n".format( |
Manuel Pégourié-Gonnard | c6967d2 | 2022-12-30 13:40:34 +0100 | [diff] [blame] | 169 | args['component_driver'], args['component_ref'])) |
Przemek Stekiel | 51f30ff | 2022-11-09 12:07:29 +0100 | [diff] [blame] | 170 | return analyze_driver_vs_reference(outcomes, args['component_ref'], |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 171 | args['component_driver'], ignored_suites, |
| 172 | args['ignored_tests']) |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 173 | |
Przemek Stekiel | 6856f4c | 2022-11-09 10:50:29 +0100 | [diff] [blame] | 174 | # List of tasks with a function that can handle this task and additional arguments if required |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 175 | TASKS = { |
| 176 | 'analyze_coverage': { |
| 177 | 'test_function': do_analyze_coverage, |
Manuel Pégourié-Gonnard | 10e3963 | 2022-12-29 12:29:09 +0100 | [diff] [blame] | 178 | 'args': {} |
| 179 | }, |
Valerio Setti | a266332 | 2023-03-24 08:20:18 +0100 | [diff] [blame] | 180 | # There are 2 options to use analyze_driver_vs_reference_xxx locally: |
| 181 | # 1. Run tests and then analysis: |
| 182 | # - tests/scripts/all.sh --outcome-file "$PWD/out.csv" <component_ref> <component_driver> |
| 183 | # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx |
| 184 | # 2. Let this script run both automatically: |
| 185 | # - tests/scripts/analyze_outcomes.py out.csv analyze_driver_vs_reference_xxx |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 186 | 'analyze_driver_vs_reference_hash': { |
| 187 | 'test_function': do_analyze_driver_vs_reference, |
| 188 | 'args': { |
Przemek Stekiel | 51f30ff | 2022-11-09 12:07:29 +0100 | [diff] [blame] | 189 | 'component_ref': 'test_psa_crypto_config_reference_hash_use_psa', |
| 190 | 'component_driver': 'test_psa_crypto_config_accel_hash_use_psa', |
Manuel Pégourié-Gonnard | 10e3963 | 2022-12-29 12:29:09 +0100 | [diff] [blame] | 191 | 'ignored_suites': [ |
| 192 | 'shax', 'mdx', # the software implementations that are being excluded |
Manuel Pégourié-Gonnard | 7d381f5 | 2023-03-17 15:13:08 +0100 | [diff] [blame] | 193 | 'md.psa', # purposefully depends on whether drivers are present |
Valerio Setti | 3002c99 | 2023-01-18 17:28:36 +0100 | [diff] [blame] | 194 | ], |
| 195 | 'ignored_tests': { |
| 196 | } |
| 197 | } |
| 198 | }, |
Valerio Setti | 4d25a8d | 2023-06-14 10:33:10 +0200 | [diff] [blame] | 199 | 'analyze_driver_vs_reference_ecp_light_only': { |
Valerio Setti | 42d5f19 | 2023-03-20 13:54:41 +0100 | [diff] [blame] | 200 | 'test_function': do_analyze_driver_vs_reference, |
| 201 | 'args': { |
Valerio Setti | 4d25a8d | 2023-06-14 10:33:10 +0200 | [diff] [blame] | 202 | 'component_ref': 'test_psa_crypto_config_reference_ecc_ecp_light_only', |
| 203 | 'component_driver': 'test_psa_crypto_config_accel_ecc_ecp_light_only', |
Valerio Setti | 42d5f19 | 2023-03-20 13:54:41 +0100 | [diff] [blame] | 204 | 'ignored_suites': [ |
| 205 | 'ecdsa', |
| 206 | 'ecdh', |
| 207 | 'ecjpake', |
| 208 | ], |
| 209 | 'ignored_tests': { |
| 210 | 'test_suite_random': [ |
| 211 | 'PSA classic wrapper: ECDSA signature (SECP256R1)', |
| 212 | ], |
Valerio Setti | 0c477d3 | 2023-04-07 15:54:20 +0200 | [diff] [blame] | 213 | # In the accelerated test ECP_C is not set (only ECP_LIGHT is) |
| 214 | # so we must ignore disparities in the tests for which ECP_C |
| 215 | # is required. |
| 216 | 'test_suite_ecp': [ |
| 217 | 'ECP check public-private #1 (OK)', |
| 218 | 'ECP check public-private #2 (group none)', |
| 219 | 'ECP check public-private #3 (group mismatch)', |
| 220 | 'ECP check public-private #4 (Qx mismatch)', |
| 221 | 'ECP check public-private #5 (Qy mismatch)', |
| 222 | 'ECP check public-private #6 (wrong Qx)', |
| 223 | 'ECP check public-private #7 (wrong Qy)', |
| 224 | 'ECP gen keypair [#1]', |
| 225 | 'ECP gen keypair [#2]', |
| 226 | 'ECP gen keypair [#3]', |
| 227 | 'ECP gen keypair wrapper', |
| 228 | 'ECP point muladd secp256r1 #1', |
| 229 | 'ECP point muladd secp256r1 #2', |
| 230 | 'ECP point multiplication Curve25519 (element of order 2: origin) #3', |
| 231 | 'ECP point multiplication Curve25519 (element of order 4: 1) #4', |
| 232 | 'ECP point multiplication Curve25519 (element of order 8) #5', |
| 233 | 'ECP point multiplication Curve25519 (normalized) #1', |
| 234 | 'ECP point multiplication Curve25519 (not normalized) #2', |
| 235 | 'ECP point multiplication rng fail Curve25519', |
| 236 | 'ECP point multiplication rng fail secp256r1', |
| 237 | 'ECP test vectors Curve25519', |
| 238 | 'ECP test vectors Curve448 (RFC 7748 6.2, after decodeUCoordinate)', |
| 239 | 'ECP test vectors brainpoolP256r1 rfc 7027', |
| 240 | 'ECP test vectors brainpoolP384r1 rfc 7027', |
| 241 | 'ECP test vectors brainpoolP512r1 rfc 7027', |
| 242 | 'ECP test vectors secp192k1', |
| 243 | 'ECP test vectors secp192r1 rfc 5114', |
| 244 | 'ECP test vectors secp224k1', |
| 245 | 'ECP test vectors secp224r1 rfc 5114', |
| 246 | 'ECP test vectors secp256k1', |
| 247 | 'ECP test vectors secp256r1 rfc 5114', |
| 248 | 'ECP test vectors secp384r1 rfc 5114', |
| 249 | 'ECP test vectors secp521r1 rfc 5114', |
Valerio Setti | e50a75f | 2023-05-19 17:43:06 +0200 | [diff] [blame] | 250 | ], |
Valerio Setti | 5f54020 | 2023-06-30 17:20:49 +0200 | [diff] [blame] | 251 | } |
Valerio Setti | 42d5f19 | 2023-03-20 13:54:41 +0100 | [diff] [blame] | 252 | } |
| 253 | }, |
Valerio Setti | 4d25a8d | 2023-06-14 10:33:10 +0200 | [diff] [blame] | 254 | 'analyze_driver_vs_reference_no_ecp_at_all': { |
Valerio Setti | e618cb0 | 2023-04-12 14:59:16 +0200 | [diff] [blame] | 255 | 'test_function': do_analyze_driver_vs_reference, |
| 256 | 'args': { |
Valerio Setti | 4d25a8d | 2023-06-14 10:33:10 +0200 | [diff] [blame] | 257 | 'component_ref': 'test_psa_crypto_config_reference_ecc_no_ecp_at_all', |
| 258 | 'component_driver': 'test_psa_crypto_config_accel_ecc_no_ecp_at_all', |
Valerio Setti | e618cb0 | 2023-04-12 14:59:16 +0200 | [diff] [blame] | 259 | 'ignored_suites': [ |
| 260 | # Ignore test suites for the modules that are disabled in the |
| 261 | # accelerated test case. |
| 262 | 'ecp', |
| 263 | 'ecdsa', |
| 264 | 'ecdh', |
| 265 | 'ecjpake', |
| 266 | ], |
| 267 | 'ignored_tests': { |
| 268 | 'test_suite_random': [ |
| 269 | 'PSA classic wrapper: ECDSA signature (SECP256R1)', |
| 270 | ], |
| 271 | 'test_suite_psa_crypto': [ |
| 272 | 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1', |
| 273 | 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)', |
| 274 | 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA', |
| 275 | 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1', |
| 276 | 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0', |
| 277 | 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1', |
| 278 | 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)', |
| 279 | 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)', |
| 280 | 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)', |
| 281 | 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)', |
| 282 | 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)', |
| 283 | 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)', |
| 284 | 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)', |
Valerio Setti | addeee4 | 2023-06-14 10:46:55 +0200 | [diff] [blame] | 285 | ], |
| 286 | 'test_suite_pkparse': [ |
Valerio Setti | 5bd2523 | 2023-06-19 19:32:14 +0200 | [diff] [blame] | 287 | # When PK_PARSE_C and ECP_C are defined then PK_PARSE_EC_COMPRESSED |
| 288 | # is automatically enabled in build_info.h (backward compatibility) |
| 289 | # even if it is disabled in config_psa_crypto_no_ecp_at_all(). As a |
| 290 | # consequence compressed points are supported in the reference |
| 291 | # component but not in the accelerated one, so they should be skipped |
| 292 | # while checking driver's coverage. |
| 293 | 'Parse EC Key #10a (SEC1 PEM, secp384r1, compressed)', |
| 294 | 'Parse EC Key #11a (SEC1 PEM, secp521r1, compressed)', |
| 295 | 'Parse EC Key #12a (SEC1 PEM, bp256r1, compressed)', |
| 296 | 'Parse EC Key #13a (SEC1 PEM, bp384r1, compressed)', |
| 297 | 'Parse EC Key #14a (SEC1 PEM, bp512r1, compressed)', |
| 298 | 'Parse EC Key #2a (SEC1 PEM, secp192r1, compressed)', |
| 299 | 'Parse EC Key #8a (SEC1 PEM, secp224r1, compressed)', |
| 300 | 'Parse EC Key #9a (SEC1 PEM, secp256r1, compressed)', |
| 301 | 'Parse Public EC Key #2a (RFC 5480, PEM, secp192r1, compressed)', |
| 302 | 'Parse Public EC Key #3a (RFC 5480, secp224r1, compressed)', |
| 303 | 'Parse Public EC Key #4a (RFC 5480, secp256r1, compressed)', |
| 304 | 'Parse Public EC Key #5a (RFC 5480, secp384r1, compressed)', |
| 305 | 'Parse Public EC Key #6a (RFC 5480, secp521r1, compressed)', |
| 306 | 'Parse Public EC Key #7a (RFC 5480, brainpoolP256r1, compressed)', |
| 307 | 'Parse Public EC Key #8a (RFC 5480, brainpoolP384r1, compressed)', |
| 308 | 'Parse Public EC Key #9a (RFC 5480, brainpoolP512r1, compressed)', |
Valerio Setti | addeee4 | 2023-06-14 10:46:55 +0200 | [diff] [blame] | 309 | ], |
Valerio Setti | e618cb0 | 2023-04-12 14:59:16 +0200 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | }, |
Manuel Pégourié-Gonnard | abd00d0 | 2023-06-12 17:51:33 +0200 | [diff] [blame] | 313 | 'analyze_driver_vs_reference_no_bignum': { |
| 314 | 'test_function': do_analyze_driver_vs_reference, |
| 315 | 'args': { |
| 316 | 'component_ref': 'test_psa_crypto_config_reference_ecc_no_bignum', |
| 317 | 'component_driver': 'test_psa_crypto_config_accel_ecc_no_bignum', |
| 318 | 'ignored_suites': [ |
| 319 | # Ignore test suites for the modules that are disabled in the |
| 320 | # accelerated test case. |
| 321 | 'ecp', |
| 322 | 'ecdsa', |
| 323 | 'ecdh', |
| 324 | 'ecjpake', |
| 325 | ], |
| 326 | 'ignored_tests': { |
| 327 | 'test_suite_random': [ |
| 328 | 'PSA classic wrapper: ECDSA signature (SECP256R1)', |
| 329 | ], |
| 330 | 'test_suite_psa_crypto': [ |
| 331 | 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1', |
| 332 | 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1 (1 redraw)', |
| 333 | 'PSA key derivation: HKDF-SHA-256 -> ECC secp256r1, exercise ECDSA', |
| 334 | 'PSA key derivation: HKDF-SHA-256 -> ECC secp384r1', |
| 335 | 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #0', |
| 336 | 'PSA key derivation: HKDF-SHA-256 -> ECC secp521r1 #1', |
| 337 | 'PSA key derivation: bits=7 invalid for ECC BRAINPOOL_P_R1 (ECC enabled)', |
| 338 | 'PSA key derivation: bits=7 invalid for ECC SECP_K1 (ECC enabled)', |
| 339 | 'PSA key derivation: bits=7 invalid for ECC SECP_R1 (ECC enabled)', |
| 340 | 'PSA key derivation: bits=7 invalid for ECC SECP_R2 (ECC enabled)', |
| 341 | 'PSA key derivation: bits=7 invalid for ECC SECT_K1 (ECC enabled)', |
| 342 | 'PSA key derivation: bits=7 invalid for ECC SECT_R1 (ECC enabled)', |
| 343 | 'PSA key derivation: bits=7 invalid for ECC SECT_R2 (ECC enabled)', |
| 344 | ], |
| 345 | 'test_suite_pkparse': [ |
| 346 | # See the description provided above in the |
| 347 | # analyze_driver_vs_reference_no_ecp_at_all component. |
| 348 | 'Parse EC Key #10a (SEC1 PEM, secp384r1, compressed)', |
| 349 | 'Parse EC Key #11a (SEC1 PEM, secp521r1, compressed)', |
| 350 | 'Parse EC Key #12a (SEC1 PEM, bp256r1, compressed)', |
| 351 | 'Parse EC Key #13a (SEC1 PEM, bp384r1, compressed)', |
| 352 | 'Parse EC Key #14a (SEC1 PEM, bp512r1, compressed)', |
| 353 | 'Parse EC Key #2a (SEC1 PEM, secp192r1, compressed)', |
| 354 | 'Parse EC Key #8a (SEC1 PEM, secp224r1, compressed)', |
| 355 | 'Parse EC Key #9a (SEC1 PEM, secp256r1, compressed)', |
| 356 | 'Parse Public EC Key #2a (RFC 5480, PEM, secp192r1, compressed)', |
| 357 | 'Parse Public EC Key #3a (RFC 5480, secp224r1, compressed)', |
| 358 | 'Parse Public EC Key #4a (RFC 5480, secp256r1, compressed)', |
| 359 | 'Parse Public EC Key #5a (RFC 5480, secp384r1, compressed)', |
| 360 | 'Parse Public EC Key #6a (RFC 5480, secp521r1, compressed)', |
| 361 | 'Parse Public EC Key #7a (RFC 5480, brainpoolP256r1, compressed)', |
| 362 | 'Parse Public EC Key #8a (RFC 5480, brainpoolP384r1, compressed)', |
| 363 | 'Parse Public EC Key #9a (RFC 5480, brainpoolP512r1, compressed)', |
| 364 | ], |
| 365 | } |
| 366 | } |
| 367 | }, |
Przemek Stekiel | 85b6442 | 2023-05-26 09:55:23 +0200 | [diff] [blame] | 368 | 'analyze_driver_vs_reference_ffdh_alg': { |
| 369 | 'test_function': do_analyze_driver_vs_reference, |
| 370 | 'args': { |
| 371 | 'component_ref': 'test_psa_crypto_config_reference_ffdh', |
| 372 | 'component_driver': 'test_psa_crypto_config_accel_ffdh', |
Przemek Stekiel | 84f4ff1 | 2023-07-04 12:35:31 +0200 | [diff] [blame] | 373 | 'ignored_suites': ['dhm'], |
Przemek Stekiel | 565353e | 2023-07-05 11:07:07 +0200 | [diff] [blame] | 374 | 'ignored_tests': {} |
Przemek Stekiel | 85b6442 | 2023-05-26 09:55:23 +0200 | [diff] [blame] | 375 | } |
| 376 | }, |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 377 | } |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 378 | |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 379 | def main(): |
| 380 | try: |
| 381 | parser = argparse.ArgumentParser(description=__doc__) |
Przemek Stekiel | 58bbc23 | 2022-10-24 08:10:10 +0200 | [diff] [blame] | 382 | parser.add_argument('outcomes', metavar='OUTCOMES.CSV', |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 383 | help='Outcome file to analyze') |
Przemek Stekiel | 542d932 | 2022-11-17 09:43:34 +0100 | [diff] [blame] | 384 | parser.add_argument('task', default='all', nargs='?', |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 385 | help='Analysis to be done. By default, run all tasks. ' |
| 386 | 'With one or more TASK, run only those. ' |
| 387 | 'TASK can be the name of a single task or ' |
Przemek Stekiel | 85c54ea | 2022-11-17 11:50:23 +0100 | [diff] [blame] | 388 | 'comma/space-separated list of tasks. ') |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 389 | parser.add_argument('--list', action='store_true', |
| 390 | help='List all available tasks and exit.') |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 391 | options = parser.parse_args() |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 392 | |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 393 | if options.list: |
| 394 | for task in TASKS: |
Valerio Setti | 3951d1b | 2023-03-13 18:37:34 +0100 | [diff] [blame] | 395 | Results.log(task) |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 396 | sys.exit(0) |
| 397 | |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 398 | result = True |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 399 | |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 400 | if options.task == 'all': |
Przemek Stekiel | d3068af | 2022-11-14 16:15:19 +0100 | [diff] [blame] | 401 | tasks = TASKS.keys() |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 402 | else: |
Przemek Stekiel | 85c54ea | 2022-11-17 11:50:23 +0100 | [diff] [blame] | 403 | tasks = re.split(r'[, ]+', options.task) |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 404 | |
Przemek Stekiel | d3068af | 2022-11-14 16:15:19 +0100 | [diff] [blame] | 405 | for task in tasks: |
| 406 | if task not in TASKS: |
Valerio Setti | 3951d1b | 2023-03-13 18:37:34 +0100 | [diff] [blame] | 407 | Results.log('Error: invalid task: {}'.format(task)) |
Przemek Stekiel | d3068af | 2022-11-14 16:15:19 +0100 | [diff] [blame] | 408 | sys.exit(1) |
Przemek Stekiel | 992de3c | 2022-11-09 13:54:49 +0100 | [diff] [blame] | 409 | |
| 410 | for task in TASKS: |
| 411 | if task in tasks: |
Przemek Stekiel | 4d13c83 | 2022-10-26 16:11:26 +0200 | [diff] [blame] | 412 | if not TASKS[task]['test_function'](options.outcomes, TASKS[task]['args']): |
| 413 | result = False |
Przemek Stekiel | 4e95590 | 2022-10-21 13:42:08 +0200 | [diff] [blame] | 414 | |
Przemek Stekiel | c86dedf | 2022-10-24 09:16:04 +0200 | [diff] [blame] | 415 | if result is False: |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 416 | sys.exit(1) |
Valerio Setti | 3951d1b | 2023-03-13 18:37:34 +0100 | [diff] [blame] | 417 | Results.log("SUCCESS :-)") |
Gilles Peskine | 15c2cbf | 2020-06-25 18:36:28 +0200 | [diff] [blame] | 418 | except Exception: # pylint: disable=broad-except |
| 419 | # Print the backtrace and exit explicitly with our chosen status. |
| 420 | traceback.print_exc() |
| 421 | sys.exit(120) |
| 422 | |
| 423 | if __name__ == '__main__': |
| 424 | main() |