Minos Galanakis | 6aab5b7 | 2024-07-25 14:24:37 +0100 | [diff] [blame] | 1 | # components-configuration-crypto.sh |
| 2 | # |
| 3 | # Copyright The Mbed TLS Contributors |
| 4 | # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 5 | |
Minos Galanakis | 609f749 | 2024-07-31 16:39:28 +0100 | [diff] [blame] | 6 | # This file contains test components that are executed by all.sh |
Minos Galanakis | 6aab5b7 | 2024-07-25 14:24:37 +0100 | [diff] [blame] | 7 | |
| 8 | ################################################################ |
| 9 | #### Configuration Testing - Crypto |
| 10 | ################################################################ |
| 11 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 12 | component_test_psa_crypto_key_id_encodes_owner () { |
| 13 | msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan" |
| 14 | scripts/config.py full |
| 15 | scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER |
| 16 | CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . |
| 17 | make |
| 18 | |
| 19 | msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan" |
| 20 | make test |
| 21 | } |
| 22 | |
| 23 | component_test_psa_assume_exclusive_buffers () { |
| 24 | msg "build: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan" |
| 25 | scripts/config.py full |
| 26 | scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS |
| 27 | CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . |
| 28 | make |
| 29 | |
| 30 | msg "test: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan" |
| 31 | make test |
| 32 | } |
| 33 | |
Valerio Setti | dbb646b | 2024-06-20 14:40:54 +0200 | [diff] [blame] | 34 | component_test_crypto_with_static_key_slots() { |
| 35 | msg "build: crypto full + MBEDTLS_PSA_STATIC_KEY_SLOTS" |
| 36 | scripts/config.py crypto_full |
| 37 | scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOTS |
Valerio Setti | 4d9a821 | 2024-08-16 12:35:24 +0200 | [diff] [blame] | 38 | # Intentionally set MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE to a value that |
| 39 | # is enough to contain: |
| 40 | # - all RSA public keys up to 4096 bits (max of PSA_VENDOR_RSA_MAX_KEY_BITS). |
| 41 | # - RSA key pairs up to 1024 bits, but not 2048 or larger. |
| 42 | # - all FFDH key pairs and public keys up to 8192 bits (max of PSA_VENDOR_FFDH_MAX_KEY_BITS). |
| 43 | # - all EC key pairs and public keys up to 521 bits (max of PSA_VENDOR_ECC_MAX_CURVE_BITS). |
| 44 | scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE 1212 |
Valerio Setti | 8bc8172 | 2024-08-28 05:50:45 +0200 | [diff] [blame] | 45 | # Disable the fully dynamic key store (default on) since it conflicts |
| 46 | # with the static behavior that we're testing here. |
| 47 | scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC |
Valerio Setti | dbb646b | 2024-06-20 14:40:54 +0200 | [diff] [blame] | 48 | |
Valerio Setti | 13aadd7 | 2024-08-13 13:13:23 +0200 | [diff] [blame] | 49 | msg "test: crypto full + MBEDTLS_PSA_STATIC_KEY_SLOTS" |
Valerio Setti | 2a3c9b3 | 2024-08-14 06:37:02 +0200 | [diff] [blame] | 50 | make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" test |
Valerio Setti | dbb646b | 2024-06-20 14:40:54 +0200 | [diff] [blame] | 51 | } |
| 52 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 53 | # check_renamed_symbols HEADER LIB |
| 54 | # Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol |
Minos Galanakis | 609f749 | 2024-07-31 16:39:28 +0100 | [diff] [blame] | 55 | # name in LIB. |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 56 | check_renamed_symbols () { |
| 57 | ! nm "$2" | sed 's/.* //' | |
| 58 | grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")" |
| 59 | } |
| 60 | |
| 61 | component_build_psa_crypto_spm () { |
| 62 | msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc" |
| 63 | scripts/config.py full |
| 64 | scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS |
| 65 | scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER |
| 66 | scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM |
| 67 | # We can only compile, not link, since our test and sample programs |
| 68 | # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM |
| 69 | # is active. |
David Horstmann | 5b93d97 | 2024-10-31 15:36:05 +0000 | [diff] [blame] | 70 | make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' lib |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 71 | |
| 72 | # Check that if a symbol is renamed by crypto_spe.h, the non-renamed |
| 73 | # version is not present. |
| 74 | echo "Checking for renamed symbols in the library" |
David Horstmann | 5b93d97 | 2024-10-31 15:36:05 +0000 | [diff] [blame] | 75 | check_renamed_symbols framework/tests/include/spe/crypto_spe.h library/libmbedcrypto.a |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 76 | } |
| 77 | |
Valerio Setti | a47b045 | 2024-06-25 18:31:36 +0200 | [diff] [blame] | 78 | # The goal of this component is to build a configuration where: |
| 79 | # - test code and libtestdriver1 can make use of calloc/free and |
| 80 | # - core library (including PSA core) cannot use calloc/free. |
| 81 | component_test_psa_crypto_without_heap() { |
Valerio Setti | 13aadd7 | 2024-08-13 13:13:23 +0200 | [diff] [blame] | 82 | msg "crypto without heap: build libtestdriver1" |
Valerio Setti | a47b045 | 2024-06-25 18:31:36 +0200 | [diff] [blame] | 83 | # Disable PSA features that cannot be accelerated and whose builtin support |
| 84 | # requires calloc/free. |
Minos Galanakis | 00b641c | 2024-11-28 23:05:10 +0000 | [diff] [blame] | 85 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE |
| 86 | scripts/config.py -c $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_HKDF" |
| 87 | scripts/config.py -c $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_PBKDF2_" |
| 88 | scripts/config.py -c $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_TLS12_" |
Valerio Setti | a47b045 | 2024-06-25 18:31:36 +0200 | [diff] [blame] | 89 | # RSA key support requires ASN1 parse/write support for testing, but ASN1 |
| 90 | # is disabled below. |
Minos Galanakis | 00b641c | 2024-11-28 23:05:10 +0000 | [diff] [blame] | 91 | scripts/config.py -c $CRYPTO_CONFIG_H unset-all "^PSA_WANT_KEY_TYPE_RSA_" |
| 92 | scripts/config.py -c $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_RSA_" |
Valerio Setti | a47b045 | 2024-06-25 18:31:36 +0200 | [diff] [blame] | 93 | # DES requires built-in support for key generation (parity check) so it |
| 94 | # cannot be accelerated |
Minos Galanakis | 00b641c | 2024-11-28 23:05:10 +0000 | [diff] [blame] | 95 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES |
Valerio Setti | a47b045 | 2024-06-25 18:31:36 +0200 | [diff] [blame] | 96 | # EC-JPAKE use calloc/free in PSA core |
Minos Galanakis | 00b641c | 2024-11-28 23:05:10 +0000 | [diff] [blame] | 97 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE |
Valerio Setti | a47b045 | 2024-06-25 18:31:36 +0200 | [diff] [blame] | 98 | |
| 99 | # Accelerate all PSA features (which are still enabled in CRYPTO_CONFIG_H). |
Minos Galanakis | 00b641c | 2024-11-28 23:05:10 +0000 | [diff] [blame] | 100 | PSA_SYM_LIST=$(./scripts/config.py -c $CRYPTO_CONFIG_H get-all-enabled PSA_WANT) |
Valerio Setti | a47b045 | 2024-06-25 18:31:36 +0200 | [diff] [blame] | 101 | loc_accel_list=$(echo $PSA_SYM_LIST | sed 's/PSA_WANT_//g') |
| 102 | |
Valerio Setti | a47b045 | 2024-06-25 18:31:36 +0200 | [diff] [blame] | 103 | helper_libtestdriver1_adjust_config crypto |
| 104 | helper_libtestdriver1_make_drivers "$loc_accel_list" |
| 105 | |
Valerio Setti | 13aadd7 | 2024-08-13 13:13:23 +0200 | [diff] [blame] | 106 | msg "crypto without heap: build main library" |
Valerio Setti | 35b0b02 | 2024-08-13 13:36:50 +0200 | [diff] [blame] | 107 | # Disable all legacy MBEDTLS_xxx symbols. |
| 108 | scripts/config.py unset-all "^MBEDTLS_" |
| 109 | # Build the PSA core using the proper config file. |
| 110 | scripts/config.py set MBEDTLS_PSA_CRYPTO_C |
Valerio Setti | a47b045 | 2024-06-25 18:31:36 +0200 | [diff] [blame] | 111 | # Enable fully-static key slots in PSA core. |
| 112 | scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOTS |
Valerio Setti | 35b0b02 | 2024-08-13 13:36:50 +0200 | [diff] [blame] | 113 | # Prevent PSA core from creating a copy of input/output buffers. |
Valerio Setti | a47b045 | 2024-06-25 18:31:36 +0200 | [diff] [blame] | 114 | scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS |
| 115 | # Prevent PSA core from using CTR-DRBG or HMAC-DRBG for random generation. |
| 116 | scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG |
Valerio Setti | 13aadd7 | 2024-08-13 13:13:23 +0200 | [diff] [blame] | 117 | # Set calloc/free as null pointer functions. Calling them would crash |
Valerio Setti | a47b045 | 2024-06-25 18:31:36 +0200 | [diff] [blame] | 118 | # the program so we can use this as a "sentinel" for being sure no module |
| 119 | # is making use of these functions in the library. |
Valerio Setti | 35b0b02 | 2024-08-13 13:36:50 +0200 | [diff] [blame] | 120 | scripts/config.py set MBEDTLS_PLATFORM_C |
Valerio Setti | a47b045 | 2024-06-25 18:31:36 +0200 | [diff] [blame] | 121 | scripts/config.py set MBEDTLS_PLATFORM_MEMORY |
| 122 | scripts/config.py set MBEDTLS_PLATFORM_STD_CALLOC NULL |
| 123 | scripts/config.py set MBEDTLS_PLATFORM_STD_FREE NULL |
| 124 | |
Valerio Setti | a47b045 | 2024-06-25 18:31:36 +0200 | [diff] [blame] | 125 | helper_libtestdriver1_make_main "$loc_accel_list" lib |
| 126 | |
Valerio Setti | 13aadd7 | 2024-08-13 13:13:23 +0200 | [diff] [blame] | 127 | msg "crypto without heap: build test suites and helpers" |
| 128 | # Reset calloc/free functions to normal operations so that test code can |
Valerio Setti | a47b045 | 2024-06-25 18:31:36 +0200 | [diff] [blame] | 129 | # freely use them. |
| 130 | scripts/config.py unset MBEDTLS_PLATFORM_MEMORY |
| 131 | scripts/config.py unset MBEDTLS_PLATFORM_STD_CALLOC |
| 132 | scripts/config.py unset MBEDTLS_PLATFORM_STD_FREE |
| 133 | helper_libtestdriver1_make_main "$loc_accel_list" tests |
| 134 | |
Valerio Setti | 13aadd7 | 2024-08-13 13:13:23 +0200 | [diff] [blame] | 135 | msg "crypto without heap: test" |
Valerio Setti | a47b045 | 2024-06-25 18:31:36 +0200 | [diff] [blame] | 136 | make test |
| 137 | } |
| 138 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 139 | component_test_no_rsa_key_pair_generation () { |
Minos Galanakis | dc0f73a | 2024-07-26 20:41:42 +0100 | [diff] [blame] | 140 | msg "build: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE" |
Minos Galanakis | dc0f73a | 2024-07-26 20:41:42 +0100 | [diff] [blame] | 141 | scripts/config.py unset MBEDTLS_GENPRIME |
Minos Galanakis | 00b641c | 2024-11-28 23:05:10 +0000 | [diff] [blame] | 142 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE |
Minos Galanakis | dc0f73a | 2024-07-26 20:41:42 +0100 | [diff] [blame] | 143 | make |
| 144 | |
| 145 | msg "test: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE" |
| 146 | make test |
| 147 | } |
| 148 | |
Minos Galanakis | c06fd30 | 2024-08-01 12:16:59 +0100 | [diff] [blame] | 149 | component_test_no_pem_no_fs () { |
| 150 | msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)" |
| 151 | scripts/config.py unset MBEDTLS_PEM_PARSE_C |
| 152 | scripts/config.py unset MBEDTLS_FS_IO |
| 153 | scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem |
| 154 | scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS |
| 155 | CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan . |
| 156 | make |
| 157 | |
| 158 | msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s |
| 159 | make test |
| 160 | |
| 161 | msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min |
| 162 | tests/ssl-opt.sh |
| 163 | } |
| 164 | |
| 165 | component_test_rsa_no_crt () { |
| 166 | msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min |
| 167 | scripts/config.py set MBEDTLS_RSA_NO_CRT |
| 168 | CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan . |
| 169 | make |
| 170 | |
| 171 | msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s |
| 172 | make test |
| 173 | |
| 174 | msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s |
| 175 | tests/ssl-opt.sh -f RSA |
| 176 | |
| 177 | msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min |
| 178 | tests/compat.sh -t RSA |
| 179 | |
| 180 | msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec |
| 181 | tests/context-info.sh |
| 182 | } |
| 183 | |
Minos Galanakis | c06fd30 | 2024-08-01 12:16:59 +0100 | [diff] [blame] | 184 | component_test_no_ctr_drbg_use_psa () { |
| 185 | msg "build: Full minus CTR_DRBG, PSA crypto in TLS" |
| 186 | scripts/config.py full |
| 187 | scripts/config.py unset MBEDTLS_CTR_DRBG_C |
Minos Galanakis | c06fd30 | 2024-08-01 12:16:59 +0100 | [diff] [blame] | 188 | |
| 189 | CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan . |
| 190 | make |
| 191 | |
| 192 | msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites" |
| 193 | make test |
| 194 | |
| 195 | # In this configuration, the TLS test programs use HMAC_DRBG. |
| 196 | # The SSL tests are slow, so run a small subset, just enough to get |
| 197 | # confidence that the SSL code copes with HMAC_DRBG. |
| 198 | msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)" |
| 199 | tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server' |
| 200 | |
| 201 | msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)" |
| 202 | tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL |
| 203 | } |
| 204 | |
Minos Galanakis | c06fd30 | 2024-08-01 12:16:59 +0100 | [diff] [blame] | 205 | component_test_no_hmac_drbg_use_psa () { |
| 206 | msg "build: Full minus HMAC_DRBG, PSA crypto in TLS" |
| 207 | scripts/config.py full |
| 208 | scripts/config.py unset MBEDTLS_HMAC_DRBG_C |
| 209 | scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG |
Minos Galanakis | c06fd30 | 2024-08-01 12:16:59 +0100 | [diff] [blame] | 210 | |
| 211 | CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan . |
| 212 | make |
| 213 | |
| 214 | msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites" |
| 215 | make test |
| 216 | |
| 217 | # Normally our ECDSA implementation uses deterministic ECDSA. But since |
| 218 | # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used |
| 219 | # instead. |
| 220 | # Test SSL with non-deterministic ECDSA. Only test features that |
| 221 | # might be affected by how ECDSA signature is performed. |
| 222 | msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)" |
| 223 | tests/ssl-opt.sh -f 'Default\|SSL async private: sign' |
| 224 | |
| 225 | # To save time, only test one protocol version, since this part of |
| 226 | # the protocol is identical in (D)TLS up to 1.2. |
| 227 | msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)" |
| 228 | tests/compat.sh -m tls12 -t 'ECDSA' |
| 229 | } |
| 230 | |
Minos Galanakis | c06fd30 | 2024-08-01 12:16:59 +0100 | [diff] [blame] | 231 | component_test_psa_external_rng_no_drbg_use_psa () { |
| 232 | msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS" |
| 233 | scripts/config.py full |
| 234 | scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG |
| 235 | scripts/config.py unset MBEDTLS_ENTROPY_C |
| 236 | scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED |
| 237 | scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT |
| 238 | scripts/config.py unset MBEDTLS_CTR_DRBG_C |
| 239 | scripts/config.py unset MBEDTLS_HMAC_DRBG_C |
| 240 | scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG |
| 241 | make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" |
| 242 | |
| 243 | msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites" |
| 244 | make test |
| 245 | |
| 246 | msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)" |
| 247 | tests/ssl-opt.sh -f 'Default\|opaque' |
| 248 | } |
| 249 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 250 | component_test_psa_external_rng_use_psa_crypto () { |
| 251 | msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG" |
| 252 | scripts/config.py full |
| 253 | scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 254 | scripts/config.py unset MBEDTLS_CTR_DRBG_C |
| 255 | make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" |
| 256 | |
| 257 | msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG" |
| 258 | make test |
| 259 | |
| 260 | msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG" |
| 261 | tests/ssl-opt.sh -f 'Default\|opaque' |
| 262 | } |
| 263 | |
| 264 | component_test_psa_inject_entropy () { |
| 265 | msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY" |
| 266 | scripts/config.py full |
| 267 | scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY |
| 268 | scripts/config.py set MBEDTLS_ENTROPY_NV_SEED |
| 269 | scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES |
| 270 | scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT |
| 271 | scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ |
| 272 | scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE |
Minos Galanakis | 4f619e1 | 2024-11-14 14:56:47 +0000 | [diff] [blame] | 273 | make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS '-DTF_PSA_CRYPTO_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 274 | |
| 275 | msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY" |
| 276 | make test |
| 277 | } |
| 278 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 279 | component_full_no_pkparse_pkwrite () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 280 | msg "build: full without pkparse and pkwrite" |
| 281 | |
| 282 | scripts/config.py crypto_full |
| 283 | scripts/config.py unset MBEDTLS_PK_PARSE_C |
| 284 | scripts/config.py unset MBEDTLS_PK_WRITE_C |
| 285 | |
| 286 | make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" |
| 287 | |
| 288 | # Ensure that PK_[PARSE|WRITE]_C were not re-enabled accidentally (additive config). |
| 289 | not grep mbedtls_pk_parse_key ${BUILTIN_SRC_PATH}/pkparse.o |
| 290 | not grep mbedtls_pk_write_key_der ${BUILTIN_SRC_PATH}/pkwrite.o |
| 291 | |
| 292 | msg "test: full without pkparse and pkwrite" |
| 293 | make test |
| 294 | } |
| 295 | |
| 296 | component_test_crypto_full_md_light_only () { |
| 297 | msg "build: crypto_full with only the light subset of MD" |
| 298 | scripts/config.py crypto_full |
| 299 | |
| 300 | # Disable MD |
| 301 | scripts/config.py unset MBEDTLS_MD_C |
| 302 | # Disable direct dependencies of MD_C |
| 303 | scripts/config.py unset MBEDTLS_HKDF_C |
| 304 | scripts/config.py unset MBEDTLS_HMAC_DRBG_C |
| 305 | scripts/config.py unset MBEDTLS_PKCS7_C |
| 306 | # Disable indirect dependencies of MD_C |
| 307 | scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG |
Minos Galanakis | 00b641c | 2024-11-28 23:05:10 +0000 | [diff] [blame] | 308 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_DETERMINISTIC_ECDSA |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 309 | # Disable things that would auto-enable MD_C |
| 310 | scripts/config.py unset MBEDTLS_PKCS5_C |
| 311 | |
| 312 | # Note: MD-light is auto-enabled in build_info.h by modules that need it, |
| 313 | # which we haven't disabled, so no need to explicitly enable it. |
| 314 | make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" |
| 315 | |
| 316 | # Make sure we don't have the HMAC functions, but the hashing functions |
| 317 | not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o |
| 318 | grep mbedtls_md ${BUILTIN_SRC_PATH}/md.o |
| 319 | |
| 320 | msg "test: crypto_full with only the light subset of MD" |
| 321 | make test |
| 322 | } |
| 323 | |
Minos Galanakis | cd5668f | 2024-07-26 20:36:23 +0100 | [diff] [blame] | 324 | component_test_full_no_cipher () { |
| 325 | msg "build: full no CIPHER" |
| 326 | |
| 327 | scripts/config.py full |
| 328 | scripts/config.py unset MBEDTLS_CIPHER_C |
| 329 | |
| 330 | # The built-in implementation of the following algs/key-types depends |
| 331 | # on CIPHER_C so we disable them. |
| 332 | # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305 |
| 333 | # so we keep them enabled. |
Minos Galanakis | 00b641c | 2024-11-28 23:05:10 +0000 | [diff] [blame] | 334 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG |
| 335 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CMAC |
| 336 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING |
| 337 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7 |
| 338 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CFB |
| 339 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CTR |
| 340 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING |
| 341 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_OFB |
| 342 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128 |
| 343 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_STREAM_CIPHER |
| 344 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES |
Minos Galanakis | cd5668f | 2024-07-26 20:36:23 +0100 | [diff] [blame] | 345 | |
| 346 | # The following modules directly depends on CIPHER_C |
| 347 | scripts/config.py unset MBEDTLS_CMAC_C |
| 348 | scripts/config.py unset MBEDTLS_NIST_KW_C |
| 349 | |
| 350 | make |
| 351 | |
| 352 | # Ensure that CIPHER_C was not re-enabled |
| 353 | not grep mbedtls_cipher_init ${BUILTIN_SRC_PATH}/cipher.o |
| 354 | |
| 355 | msg "test: full no CIPHER" |
| 356 | make test |
| 357 | } |
| 358 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 359 | component_test_full_no_ccm () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 360 | msg "build: full no PSA_WANT_ALG_CCM" |
| 361 | |
| 362 | # Full config enables: |
| 363 | # - USE_PSA_CRYPTO so that TLS code dispatches cipher/AEAD to PSA |
| 364 | # - CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated |
| 365 | scripts/config.py full |
| 366 | |
| 367 | # Disable PSA_WANT_ALG_CCM so that CCM is not supported in PSA. CCM_C is still |
| 368 | # enabled, but not used from TLS since USE_PSA is set. |
| 369 | # This is helpful to ensure that TLS tests below have proper dependencies. |
| 370 | # |
| 371 | # Note: also PSA_WANT_ALG_CCM_STAR_NO_TAG is enabled, but it does not cause |
| 372 | # PSA_WANT_ALG_CCM to be re-enabled. |
| 373 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM |
| 374 | |
| 375 | make |
| 376 | |
| 377 | msg "test: full no PSA_WANT_ALG_CCM" |
| 378 | make test |
| 379 | } |
| 380 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 381 | component_test_full_no_ccm_star_no_tag () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 382 | msg "build: full no PSA_WANT_ALG_CCM_STAR_NO_TAG" |
| 383 | |
| 384 | # Full config enables CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated |
| 385 | scripts/config.py full |
| 386 | |
| 387 | # Disable CCM_STAR_NO_TAG, which is the target of this test, as well as all |
| 388 | # other components that enable MBEDTLS_PSA_BUILTIN_CIPHER internal symbol. |
| 389 | # This basically disables all unauthenticated ciphers on the PSA side, while |
| 390 | # keeping AEADs enabled. |
| 391 | # |
| 392 | # Note: PSA_WANT_ALG_CCM is enabled, but it does not cause |
| 393 | # PSA_WANT_ALG_CCM_STAR_NO_TAG to be re-enabled. |
| 394 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG |
| 395 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_STREAM_CIPHER |
| 396 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR |
| 397 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB |
| 398 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB |
| 399 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING |
| 400 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING |
| 401 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7 |
| 402 | |
| 403 | make |
| 404 | |
| 405 | # Ensure MBEDTLS_PSA_BUILTIN_CIPHER was not enabled |
| 406 | not grep mbedtls_psa_cipher ${PSA_CORE_PATH}/psa_crypto_cipher.o |
| 407 | |
| 408 | msg "test: full no PSA_WANT_ALG_CCM_STAR_NO_TAG" |
| 409 | make test |
| 410 | } |
| 411 | |
Gilles Peskine | ea5de2b | 2024-09-19 18:41:55 +0200 | [diff] [blame] | 412 | component_test_config_symmetric_only () { |
| 413 | msg "build: configs/config-symmetric-only.h" |
Minos Galanakis | 5da58e5 | 2024-11-07 15:35:33 +0000 | [diff] [blame] | 414 | MBEDTLS_CONFIG="configs/config-symmetric-only.h" |
Harry Ramsey | 94c386a | 2025-01-16 16:08:34 +0000 | [diff] [blame^] | 415 | CRYPTO_CONFIG="tf-psa-crypto/configs/crypto-config-symmetric-only.h" |
Ronald Cron | faadfc2 | 2024-12-07 17:24:28 +0100 | [diff] [blame] | 416 | CC=$ASAN_CC cmake -DMBEDTLS_CONFIG_FILE="$MBEDTLS_CONFIG" -DTF_PSA_CRYPTO_CONFIG_FILE="$CRYPTO_CONFIG" -D CMAKE_BUILD_TYPE:String=Asan . |
Gilles Peskine | af5a899 | 2024-09-14 11:27:44 +0200 | [diff] [blame] | 417 | make |
| 418 | |
Gilles Peskine | ea5de2b | 2024-09-19 18:41:55 +0200 | [diff] [blame] | 419 | msg "test: configs/config-symmetric-only.h - unit tests" |
Gilles Peskine | af5a899 | 2024-09-14 11:27:44 +0200 | [diff] [blame] | 420 | make test |
| 421 | } |
| 422 | |
Minos Galanakis | c06fd30 | 2024-08-01 12:16:59 +0100 | [diff] [blame] | 423 | component_test_everest () { |
| 424 | msg "build: Everest ECDH context (ASan build)" # ~ 6 min |
| 425 | scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED |
| 426 | CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan . |
| 427 | make |
| 428 | |
| 429 | msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s |
| 430 | make test |
| 431 | |
| 432 | msg "test: metatests (clang, ASan)" |
| 433 | tests/scripts/run-metatests.sh any asan poison |
| 434 | |
| 435 | msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s |
| 436 | tests/ssl-opt.sh -f ECDH |
| 437 | |
| 438 | msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min |
| 439 | # Exclude some symmetric ciphers that are redundant here to gain time. |
| 440 | tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA' |
| 441 | } |
| 442 | |
| 443 | component_test_everest_curve25519_only () { |
| 444 | msg "build: Everest ECDH context, only Curve25519" # ~ 6 min |
Minos Galanakis | c06fd30 | 2024-08-01 12:16:59 +0100 | [diff] [blame] | 445 | scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED |
| 446 | scripts/config.py unset MBEDTLS_ECDSA_C |
Minos Galanakis | 00b641c | 2024-11-28 23:05:10 +0000 | [diff] [blame] | 447 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_DETERMINISTIC_ECDSA |
| 448 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECDSA |
| 449 | scripts/config.py -c $CRYPTO_CONFIG_H set PSA_WANT_ALG_ECDH |
Minos Galanakis | c06fd30 | 2024-08-01 12:16:59 +0100 | [diff] [blame] | 450 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED |
| 451 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED |
| 452 | scripts/config.py unset MBEDTLS_ECJPAKE_C |
Minos Galanakis | 00b641c | 2024-11-28 23:05:10 +0000 | [diff] [blame] | 453 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE |
Minos Galanakis | c06fd30 | 2024-08-01 12:16:59 +0100 | [diff] [blame] | 454 | |
| 455 | # Disable all curves |
| 456 | scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED" |
Minos Galanakis | 00b641c | 2024-11-28 23:05:10 +0000 | [diff] [blame] | 457 | scripts/config.py -c $CRYPTO_CONFIG_H unset-all "PSA_WANT_ECC_[0-9A-Z_a-z]*$" |
| 458 | scripts/config.py -c $CRYPTO_CONFIG_H set PSA_WANT_ECC_MONTGOMERY_255 |
Minos Galanakis | c06fd30 | 2024-08-01 12:16:59 +0100 | [diff] [blame] | 459 | |
| 460 | make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" |
| 461 | |
| 462 | msg "test: Everest ECDH context, only Curve25519" # ~ 50s |
| 463 | make test |
| 464 | } |
| 465 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 466 | component_test_psa_collect_statuses () { |
| 467 | msg "build+test: psa_collect_statuses" # ~30s |
| 468 | scripts/config.py full |
| 469 | tests/scripts/psa_collect_statuses.py |
| 470 | # Check that psa_crypto_init() succeeded at least once |
| 471 | grep -q '^0:psa_crypto_init:' tests/statuses.log |
| 472 | rm -f tests/statuses.log |
| 473 | } |
| 474 | |
| 475 | # Check that the specified libraries exist and are empty. |
| 476 | are_empty_libraries () { |
| 477 | nm "$@" >/dev/null 2>/dev/null |
| 478 | ! nm "$@" 2>/dev/null | grep -v ':$' | grep . |
| 479 | } |
| 480 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 481 | component_test_crypto_for_psa_service () { |
| 482 | msg "build: make, config for PSA crypto service" |
| 483 | scripts/config.py crypto |
| 484 | scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER |
| 485 | # Disable things that are not needed for just cryptography, to |
| 486 | # reach a configuration that would be typical for a PSA cryptography |
| 487 | # service providing all implemented PSA algorithms. |
| 488 | # System stuff |
| 489 | scripts/config.py unset MBEDTLS_ERROR_C |
| 490 | scripts/config.py unset MBEDTLS_TIMING_C |
| 491 | scripts/config.py unset MBEDTLS_VERSION_FEATURES |
| 492 | # Crypto stuff with no PSA interface |
| 493 | scripts/config.py unset MBEDTLS_BASE64_C |
| 494 | # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it. |
| 495 | scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent |
| 496 | # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG. |
| 497 | scripts/config.py unset MBEDTLS_NIST_KW_C |
| 498 | scripts/config.py unset MBEDTLS_PEM_PARSE_C |
| 499 | scripts/config.py unset MBEDTLS_PEM_WRITE_C |
| 500 | scripts/config.py unset MBEDTLS_PKCS12_C |
| 501 | scripts/config.py unset MBEDTLS_PKCS5_C |
| 502 | # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed |
| 503 | # in PSA code to work with RSA keys. We don't require users to set those: |
| 504 | # they will be reenabled in build_info.h. |
| 505 | scripts/config.py unset MBEDTLS_PK_C |
| 506 | scripts/config.py unset MBEDTLS_PK_PARSE_C |
| 507 | scripts/config.py unset MBEDTLS_PK_WRITE_C |
| 508 | make CFLAGS='-O1 -Werror' all test |
| 509 | are_empty_libraries library/libmbedx509.* library/libmbedtls.* |
| 510 | } |
| 511 | |
| 512 | component_build_crypto_baremetal () { |
| 513 | msg "build: make, crypto only, baremetal config" |
| 514 | scripts/config.py crypto_baremetal |
David Horstmann | 5b93d97 | 2024-10-31 15:36:05 +0000 | [diff] [blame] | 515 | make CFLAGS="-O1 -Werror -I$PWD/framework/tests/include/baremetal-override/" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 516 | are_empty_libraries library/libmbedx509.* library/libmbedtls.* |
| 517 | } |
| 518 | |
| 519 | support_build_crypto_baremetal () { |
| 520 | support_build_baremetal "$@" |
| 521 | } |
| 522 | |
| 523 | # depends.py family of tests |
| 524 | component_test_depends_py_cipher_id () { |
| 525 | msg "test/build: depends.py cipher_id (gcc)" |
Gabor Mezei | 9ce6d24 | 2024-06-19 17:47:05 +0200 | [diff] [blame] | 526 | tests/scripts/depends.py cipher_id |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | component_test_depends_py_cipher_chaining () { |
| 530 | msg "test/build: depends.py cipher_chaining (gcc)" |
Gabor Mezei | 9ce6d24 | 2024-06-19 17:47:05 +0200 | [diff] [blame] | 531 | tests/scripts/depends.py cipher_chaining |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | component_test_depends_py_cipher_padding () { |
| 535 | msg "test/build: depends.py cipher_padding (gcc)" |
Gabor Mezei | 9ce6d24 | 2024-06-19 17:47:05 +0200 | [diff] [blame] | 536 | tests/scripts/depends.py cipher_padding |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | component_test_depends_py_curves () { |
| 540 | msg "test/build: depends.py curves (gcc)" |
Gabor Mezei | 9ce6d24 | 2024-06-19 17:47:05 +0200 | [diff] [blame] | 541 | tests/scripts/depends.py curves |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | component_test_depends_py_hashes () { |
| 545 | msg "test/build: depends.py hashes (gcc)" |
Gabor Mezei | 9ce6d24 | 2024-06-19 17:47:05 +0200 | [diff] [blame] | 546 | tests/scripts/depends.py hashes |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 547 | } |
| 548 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 549 | component_test_depends_py_pkalgs () { |
| 550 | msg "test/build: depends.py pkalgs (gcc)" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 551 | tests/scripts/depends.py pkalgs |
| 552 | } |
| 553 | |
| 554 | component_test_psa_crypto_config_ffdh_2048_only () { |
| 555 | msg "build: full config - only DH 2048" |
| 556 | |
| 557 | scripts/config.py full |
| 558 | |
| 559 | # Disable all DH groups other than 2048. |
| 560 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_3072 |
| 561 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_4096 |
| 562 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_6144 |
| 563 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_8192 |
| 564 | |
| 565 | make CFLAGS="$ASAN_CFLAGS -Werror" LDFLAGS="$ASAN_CFLAGS" |
| 566 | |
| 567 | msg "test: full config - only DH 2048" |
| 568 | make test |
| 569 | |
| 570 | msg "ssl-opt: full config - only DH 2048" |
| 571 | tests/ssl-opt.sh -f "ffdh" |
| 572 | } |
| 573 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 574 | component_test_psa_crypto_config_accel_ecdsa () { |
Ronald Cron | 93ba625 | 2024-09-05 10:37:14 +0200 | [diff] [blame] | 575 | msg "build: accelerated ECDSA" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 576 | |
| 577 | # Algorithms and key types to accelerate |
| 578 | loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \ |
| 579 | $(helper_get_psa_key_type_list "ECC") \ |
| 580 | $(helper_get_psa_curve_list)" |
| 581 | |
| 582 | # Configure |
| 583 | # --------- |
| 584 | |
Elena Uziunaite | 91d8386 | 2024-09-04 14:51:31 +0100 | [diff] [blame] | 585 | # Start from default config + TLS 1.3 |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 586 | helper_libtestdriver1_adjust_config "default" |
| 587 | |
| 588 | # Disable the module that's accelerated |
| 589 | scripts/config.py unset MBEDTLS_ECDSA_C |
| 590 | |
| 591 | # Disable things that depend on it |
| 592 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED |
| 593 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED |
| 594 | |
| 595 | # Build |
| 596 | # ----- |
| 597 | |
| 598 | # These hashes are needed for some ECDSA signature tests. |
Elena Uziunaite | ffce45c | 2024-09-12 14:58:52 +0100 | [diff] [blame] | 599 | loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \ |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 600 | ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512" |
| 601 | |
| 602 | helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list" |
| 603 | |
| 604 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 605 | |
| 606 | # Make sure this was not re-enabled by accident (additive config) |
| 607 | not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o |
| 608 | |
| 609 | # Run the tests |
| 610 | # ------------- |
| 611 | |
Ronald Cron | 93ba625 | 2024-09-05 10:37:14 +0200 | [diff] [blame] | 612 | msg "test: accelerated ECDSA" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 613 | make test |
| 614 | } |
| 615 | |
| 616 | component_test_psa_crypto_config_accel_ecdh () { |
Ronald Cron | 93ba625 | 2024-09-05 10:37:14 +0200 | [diff] [blame] | 617 | msg "build: accelerated ECDH" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 618 | |
| 619 | # Algorithms and key types to accelerate |
| 620 | loc_accel_list="ALG_ECDH \ |
| 621 | $(helper_get_psa_key_type_list "ECC") \ |
| 622 | $(helper_get_psa_curve_list)" |
| 623 | |
| 624 | # Configure |
| 625 | # --------- |
| 626 | |
| 627 | # Start from default config (no USE_PSA) |
| 628 | helper_libtestdriver1_adjust_config "default" |
| 629 | |
| 630 | # Disable the module that's accelerated |
| 631 | scripts/config.py unset MBEDTLS_ECDH_C |
| 632 | |
| 633 | # Disable things that depend on it |
| 634 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED |
| 635 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED |
| 636 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED |
| 637 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED |
| 638 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED |
| 639 | |
| 640 | # Build |
| 641 | # ----- |
| 642 | |
| 643 | helper_libtestdriver1_make_drivers "$loc_accel_list" |
| 644 | |
| 645 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 646 | |
| 647 | # Make sure this was not re-enabled by accident (additive config) |
| 648 | not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o |
| 649 | |
| 650 | # Run the tests |
| 651 | # ------------- |
| 652 | |
Ronald Cron | 93ba625 | 2024-09-05 10:37:14 +0200 | [diff] [blame] | 653 | msg "test: accelerated ECDH" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 654 | make test |
| 655 | } |
| 656 | |
| 657 | component_test_psa_crypto_config_accel_ffdh () { |
| 658 | msg "build: full with accelerated FFDH" |
| 659 | |
| 660 | # Algorithms and key types to accelerate |
| 661 | loc_accel_list="ALG_FFDH \ |
| 662 | $(helper_get_psa_key_type_list "DH") \ |
| 663 | $(helper_get_psa_dh_group_list)" |
| 664 | |
| 665 | # Configure |
| 666 | # --------- |
| 667 | |
| 668 | # start with full (USE_PSA and TLS 1.3) |
| 669 | helper_libtestdriver1_adjust_config "full" |
| 670 | |
| 671 | # Disable the module that's accelerated |
| 672 | scripts/config.py unset MBEDTLS_DHM_C |
| 673 | |
| 674 | # Disable things that depend on it |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 675 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED |
| 676 | |
| 677 | # Build |
| 678 | # ----- |
| 679 | |
| 680 | helper_libtestdriver1_make_drivers "$loc_accel_list" |
| 681 | |
| 682 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 683 | |
| 684 | # Make sure this was not re-enabled by accident (additive config) |
| 685 | not grep mbedtls_dhm_ ${BUILTIN_SRC_PATH}/dhm.o |
| 686 | |
| 687 | # Run the tests |
| 688 | # ------------- |
| 689 | |
| 690 | msg "test: full with accelerated FFDH" |
| 691 | make test |
| 692 | |
| 693 | msg "ssl-opt: full with accelerated FFDH alg" |
| 694 | tests/ssl-opt.sh -f "ffdh" |
| 695 | } |
| 696 | |
| 697 | component_test_psa_crypto_config_reference_ffdh () { |
| 698 | msg "build: full with non-accelerated FFDH" |
| 699 | |
| 700 | # Start with full (USE_PSA and TLS 1.3) |
| 701 | helper_libtestdriver1_adjust_config "full" |
| 702 | |
| 703 | # Disable things that are not supported |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 704 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED |
| 705 | make |
| 706 | |
| 707 | msg "test suites: full with non-accelerated FFDH alg" |
| 708 | make test |
| 709 | |
| 710 | msg "ssl-opt: full with non-accelerated FFDH alg" |
| 711 | tests/ssl-opt.sh -f "ffdh" |
| 712 | } |
| 713 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 714 | component_test_psa_crypto_config_accel_pake () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 715 | msg "build: full with accelerated PAKE" |
| 716 | |
| 717 | loc_accel_list="ALG_JPAKE \ |
| 718 | $(helper_get_psa_key_type_list "ECC") \ |
| 719 | $(helper_get_psa_curve_list)" |
| 720 | |
| 721 | # Configure |
| 722 | # --------- |
| 723 | |
| 724 | helper_libtestdriver1_adjust_config "full" |
| 725 | |
| 726 | # Make built-in fallback not available |
| 727 | scripts/config.py unset MBEDTLS_ECJPAKE_C |
| 728 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED |
| 729 | |
| 730 | # Build |
| 731 | # ----- |
| 732 | |
| 733 | helper_libtestdriver1_make_drivers "$loc_accel_list" |
| 734 | |
| 735 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 736 | |
| 737 | # Make sure this was not re-enabled by accident (additive config) |
| 738 | not grep mbedtls_ecjpake_init ${BUILTIN_SRC_PATH}/ecjpake.o |
| 739 | |
| 740 | # Run the tests |
| 741 | # ------------- |
| 742 | |
| 743 | msg "test: full with accelerated PAKE" |
| 744 | make test |
| 745 | } |
| 746 | |
| 747 | component_test_psa_crypto_config_accel_ecc_some_key_types () { |
| 748 | msg "build: full with accelerated EC algs and some key types" |
| 749 | |
| 750 | # Algorithms and key types to accelerate |
| 751 | # For key types, use an explicitly list to omit GENERATE (and DERIVE) |
| 752 | loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \ |
| 753 | ALG_ECDH \ |
| 754 | ALG_JPAKE \ |
| 755 | KEY_TYPE_ECC_PUBLIC_KEY \ |
| 756 | KEY_TYPE_ECC_KEY_PAIR_BASIC \ |
| 757 | KEY_TYPE_ECC_KEY_PAIR_IMPORT \ |
| 758 | KEY_TYPE_ECC_KEY_PAIR_EXPORT \ |
| 759 | $(helper_get_psa_curve_list)" |
| 760 | |
| 761 | # Configure |
| 762 | # --------- |
| 763 | |
| 764 | # start with config full for maximum coverage (also enables USE_PSA) |
| 765 | helper_libtestdriver1_adjust_config "full" |
| 766 | |
| 767 | # Disable modules that are accelerated - some will be re-enabled |
| 768 | scripts/config.py unset MBEDTLS_ECDSA_C |
| 769 | scripts/config.py unset MBEDTLS_ECDH_C |
| 770 | scripts/config.py unset MBEDTLS_ECJPAKE_C |
| 771 | scripts/config.py unset MBEDTLS_ECP_C |
| 772 | |
| 773 | # Disable all curves - those that aren't accelerated should be re-enabled |
| 774 | helper_disable_builtin_curves |
| 775 | |
| 776 | # Restartable feature is not yet supported by PSA. Once it will in |
| 777 | # the future, the following line could be removed (see issues |
| 778 | # 6061, 6332 and following ones) |
| 779 | scripts/config.py unset MBEDTLS_ECP_RESTARTABLE |
| 780 | |
| 781 | # this is not supported by the driver API yet |
| 782 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE |
| 783 | |
| 784 | # Build |
| 785 | # ----- |
| 786 | |
| 787 | # These hashes are needed for some ECDSA signature tests. |
| 788 | loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \ |
| 789 | ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512" |
| 790 | helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list" |
| 791 | |
| 792 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 793 | |
| 794 | # ECP should be re-enabled but not the others |
| 795 | not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o |
| 796 | not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o |
| 797 | not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o |
| 798 | grep mbedtls_ecp ${BUILTIN_SRC_PATH}/ecp.o |
| 799 | |
| 800 | # Run the tests |
| 801 | # ------------- |
| 802 | |
| 803 | msg "test suites: full with accelerated EC algs and some key types" |
| 804 | make test |
| 805 | } |
| 806 | |
| 807 | # Run tests with only (non-)Weierstrass accelerated |
| 808 | # Common code used in: |
| 809 | # - component_test_psa_crypto_config_accel_ecc_weierstrass_curves |
| 810 | # - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 811 | common_test_psa_crypto_config_accel_ecc_some_curves () { |
| 812 | weierstrass=$1 |
| 813 | if [ $weierstrass -eq 1 ]; then |
| 814 | desc="Weierstrass" |
| 815 | else |
| 816 | desc="non-Weierstrass" |
| 817 | fi |
| 818 | |
| 819 | msg "build: crypto_full minus PK with accelerated EC algs and $desc curves" |
| 820 | |
| 821 | # Note: Curves are handled in a special way by the libtestdriver machinery, |
| 822 | # so we only want to include them in the accel list when building the main |
| 823 | # libraries, hence the use of a separate variable. |
| 824 | # Note: the following loop is a modified version of |
| 825 | # helper_get_psa_curve_list that only keeps Weierstrass families. |
| 826 | loc_weierstrass_list="" |
| 827 | loc_non_weierstrass_list="" |
| 828 | for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do |
| 829 | case $item in |
| 830 | ECC_BRAINPOOL*|ECC_SECP*) |
| 831 | loc_weierstrass_list="$loc_weierstrass_list $item" |
| 832 | ;; |
| 833 | *) |
| 834 | loc_non_weierstrass_list="$loc_non_weierstrass_list $item" |
| 835 | ;; |
| 836 | esac |
| 837 | done |
| 838 | if [ $weierstrass -eq 1 ]; then |
| 839 | loc_curve_list=$loc_weierstrass_list |
| 840 | else |
| 841 | loc_curve_list=$loc_non_weierstrass_list |
| 842 | fi |
| 843 | |
| 844 | # Algorithms and key types to accelerate |
| 845 | loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \ |
| 846 | ALG_ECDH \ |
| 847 | ALG_JPAKE \ |
| 848 | $(helper_get_psa_key_type_list "ECC") \ |
| 849 | $loc_curve_list" |
| 850 | |
| 851 | # Configure |
| 852 | # --------- |
| 853 | |
| 854 | # Start with config crypto_full and remove PK_C: |
| 855 | # that's what's supported now, see docs/driver-only-builds.md. |
| 856 | helper_libtestdriver1_adjust_config "crypto_full" |
| 857 | scripts/config.py unset MBEDTLS_PK_C |
| 858 | scripts/config.py unset MBEDTLS_PK_PARSE_C |
| 859 | scripts/config.py unset MBEDTLS_PK_WRITE_C |
| 860 | |
| 861 | # Disable modules that are accelerated - some will be re-enabled |
| 862 | scripts/config.py unset MBEDTLS_ECDSA_C |
| 863 | scripts/config.py unset MBEDTLS_ECDH_C |
| 864 | scripts/config.py unset MBEDTLS_ECJPAKE_C |
| 865 | scripts/config.py unset MBEDTLS_ECP_C |
| 866 | |
| 867 | # Disable all curves - those that aren't accelerated should be re-enabled |
| 868 | helper_disable_builtin_curves |
| 869 | |
| 870 | # Restartable feature is not yet supported by PSA. Once it will in |
| 871 | # the future, the following line could be removed (see issues |
| 872 | # 6061, 6332 and following ones) |
| 873 | scripts/config.py unset MBEDTLS_ECP_RESTARTABLE |
| 874 | |
| 875 | # this is not supported by the driver API yet |
| 876 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE |
| 877 | |
| 878 | # Build |
| 879 | # ----- |
| 880 | |
| 881 | # These hashes are needed for some ECDSA signature tests. |
| 882 | loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \ |
| 883 | ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512" |
| 884 | helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list" |
| 885 | |
| 886 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 887 | |
| 888 | # We expect ECDH to be re-enabled for the missing curves |
| 889 | grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o |
| 890 | # We expect ECP to be re-enabled, however the parts specific to the |
| 891 | # families of curves that are accelerated should be ommited. |
| 892 | # - functions with mxz in the name are specific to Montgomery curves |
| 893 | # - ecp_muladd is specific to Weierstrass curves |
| 894 | ##nm ${BUILTIN_SRC_PATH}/ecp.o | tee ecp.syms |
| 895 | if [ $weierstrass -eq 1 ]; then |
| 896 | not grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o |
| 897 | grep mxz ${BUILTIN_SRC_PATH}/ecp.o |
| 898 | else |
| 899 | grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o |
| 900 | not grep mxz ${BUILTIN_SRC_PATH}/ecp.o |
| 901 | fi |
| 902 | # We expect ECDSA and ECJPAKE to be re-enabled only when |
| 903 | # Weierstrass curves are not accelerated |
| 904 | if [ $weierstrass -eq 1 ]; then |
| 905 | not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o |
| 906 | not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o |
| 907 | else |
| 908 | grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o |
| 909 | grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o |
| 910 | fi |
| 911 | |
| 912 | # Run the tests |
| 913 | # ------------- |
| 914 | |
| 915 | msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves" |
| 916 | make test |
| 917 | } |
| 918 | |
| 919 | component_test_psa_crypto_config_accel_ecc_weierstrass_curves () { |
| 920 | common_test_psa_crypto_config_accel_ecc_some_curves 1 |
| 921 | } |
| 922 | |
| 923 | component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () { |
| 924 | common_test_psa_crypto_config_accel_ecc_some_curves 0 |
| 925 | } |
| 926 | |
| 927 | # Auxiliary function to build config for all EC based algorithms (EC-JPAKE, |
| 928 | # ECDH, ECDSA) with and without drivers. |
| 929 | # The input parameter is a boolean value which indicates: |
| 930 | # - 0 keep built-in EC algs, |
| 931 | # - 1 exclude built-in EC algs (driver only). |
| 932 | # |
| 933 | # This is used by the two following components to ensure they always use the |
| 934 | # same config, except for the use of driver or built-in EC algorithms: |
| 935 | # - component_test_psa_crypto_config_accel_ecc_ecp_light_only; |
| 936 | # - component_test_psa_crypto_config_reference_ecc_ecp_light_only. |
| 937 | # This supports comparing their test coverage with analyze_outcomes.py. |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 938 | config_psa_crypto_config_ecp_light_only () { |
| 939 | driver_only="$1" |
| 940 | # start with config full for maximum coverage (also enables USE_PSA) |
| 941 | helper_libtestdriver1_adjust_config "full" |
| 942 | if [ "$driver_only" -eq 1 ]; then |
| 943 | # Disable modules that are accelerated |
| 944 | scripts/config.py unset MBEDTLS_ECDSA_C |
| 945 | scripts/config.py unset MBEDTLS_ECDH_C |
| 946 | scripts/config.py unset MBEDTLS_ECJPAKE_C |
| 947 | scripts/config.py unset MBEDTLS_ECP_C |
| 948 | fi |
| 949 | |
| 950 | # Restartable feature is not yet supported by PSA. Once it will in |
| 951 | # the future, the following line could be removed (see issues |
| 952 | # 6061, 6332 and following ones) |
| 953 | scripts/config.py unset MBEDTLS_ECP_RESTARTABLE |
| 954 | } |
| 955 | |
| 956 | # Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 957 | component_test_psa_crypto_config_accel_ecc_ecp_light_only () { |
| 958 | msg "build: full with accelerated EC algs" |
| 959 | |
| 960 | # Algorithms and key types to accelerate |
| 961 | loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \ |
| 962 | ALG_ECDH \ |
| 963 | ALG_JPAKE \ |
| 964 | $(helper_get_psa_key_type_list "ECC") \ |
| 965 | $(helper_get_psa_curve_list)" |
| 966 | |
| 967 | # Configure |
| 968 | # --------- |
| 969 | |
| 970 | # Use the same config as reference, only without built-in EC algs |
| 971 | config_psa_crypto_config_ecp_light_only 1 |
| 972 | |
| 973 | # Do not disable builtin curves because that support is required for: |
| 974 | # - MBEDTLS_PK_PARSE_EC_EXTENDED |
| 975 | # - MBEDTLS_PK_PARSE_EC_COMPRESSED |
| 976 | |
| 977 | # Build |
| 978 | # ----- |
| 979 | |
| 980 | # These hashes are needed for some ECDSA signature tests. |
| 981 | loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \ |
| 982 | ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512" |
| 983 | helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list" |
| 984 | |
| 985 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 986 | |
| 987 | # Make sure any built-in EC alg was not re-enabled by accident (additive config) |
| 988 | not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o |
| 989 | not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o |
| 990 | not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o |
| 991 | not grep mbedtls_ecp_mul ${BUILTIN_SRC_PATH}/ecp.o |
| 992 | |
| 993 | # Run the tests |
| 994 | # ------------- |
| 995 | |
| 996 | msg "test suites: full with accelerated EC algs" |
| 997 | make test |
| 998 | |
| 999 | msg "ssl-opt: full with accelerated EC algs" |
| 1000 | tests/ssl-opt.sh |
| 1001 | } |
| 1002 | |
| 1003 | # Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1004 | component_test_psa_crypto_config_reference_ecc_ecp_light_only () { |
Ronald Cron | 93ba625 | 2024-09-05 10:37:14 +0200 | [diff] [blame] | 1005 | msg "build: non-accelerated EC algs" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1006 | |
| 1007 | config_psa_crypto_config_ecp_light_only 0 |
| 1008 | |
| 1009 | make |
| 1010 | |
| 1011 | msg "test suites: full with non-accelerated EC algs" |
| 1012 | make test |
| 1013 | |
| 1014 | msg "ssl-opt: full with non-accelerated EC algs" |
| 1015 | tests/ssl-opt.sh |
| 1016 | } |
| 1017 | |
| 1018 | # This helper function is used by: |
| 1019 | # - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all() |
| 1020 | # - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all() |
| 1021 | # to ensure that both tests use the same underlying configuration when testing |
| 1022 | # driver's coverage with analyze_outcomes.py. |
| 1023 | # |
| 1024 | # This functions accepts 1 boolean parameter as follows: |
| 1025 | # - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore |
| 1026 | # excluding their built-in implementation as well as ECP_C & ECP_LIGHT |
| 1027 | # - 0: include built-in implementation of EC algorithms. |
| 1028 | # |
| 1029 | # PK_C and RSA_C are always disabled to ensure there is no remaining dependency |
| 1030 | # on the ECP module. |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1031 | config_psa_crypto_no_ecp_at_all () { |
| 1032 | driver_only="$1" |
| 1033 | # start with full config for maximum coverage (also enables USE_PSA) |
| 1034 | helper_libtestdriver1_adjust_config "full" |
| 1035 | |
| 1036 | if [ "$driver_only" -eq 1 ]; then |
| 1037 | # Disable modules that are accelerated |
| 1038 | scripts/config.py unset MBEDTLS_ECDSA_C |
| 1039 | scripts/config.py unset MBEDTLS_ECDH_C |
| 1040 | scripts/config.py unset MBEDTLS_ECJPAKE_C |
| 1041 | # Disable ECP module (entirely) |
| 1042 | scripts/config.py unset MBEDTLS_ECP_C |
| 1043 | fi |
| 1044 | |
| 1045 | # Disable all the features that auto-enable ECP_LIGHT (see build_info.h) |
| 1046 | scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED |
| 1047 | scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED |
| 1048 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE |
| 1049 | |
| 1050 | # Restartable feature is not yet supported by PSA. Once it will in |
| 1051 | # the future, the following line could be removed (see issues |
| 1052 | # 6061, 6332 and following ones) |
| 1053 | scripts/config.py unset MBEDTLS_ECP_RESTARTABLE |
| 1054 | } |
| 1055 | |
| 1056 | # Build and test a configuration where driver accelerates all EC algs while |
| 1057 | # all support and dependencies from ECP and ECP_LIGHT are removed on the library |
| 1058 | # side. |
| 1059 | # |
| 1060 | # Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all() |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1061 | component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () { |
| 1062 | msg "build: full + accelerated EC algs - ECP" |
| 1063 | |
| 1064 | # Algorithms and key types to accelerate |
| 1065 | loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \ |
| 1066 | ALG_ECDH \ |
| 1067 | ALG_JPAKE \ |
| 1068 | $(helper_get_psa_key_type_list "ECC") \ |
| 1069 | $(helper_get_psa_curve_list)" |
| 1070 | |
| 1071 | # Configure |
| 1072 | # --------- |
| 1073 | |
| 1074 | # Set common configurations between library's and driver's builds |
| 1075 | config_psa_crypto_no_ecp_at_all 1 |
| 1076 | # Disable all the builtin curves. All the required algs are accelerated. |
| 1077 | helper_disable_builtin_curves |
| 1078 | |
| 1079 | # Build |
| 1080 | # ----- |
| 1081 | |
| 1082 | # Things we wanted supported in libtestdriver1, but not accelerated in the main library: |
| 1083 | # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic. |
| 1084 | loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \ |
| 1085 | ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512" |
| 1086 | |
| 1087 | helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list" |
| 1088 | |
| 1089 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 1090 | |
| 1091 | # Make sure any built-in EC alg was not re-enabled by accident (additive config) |
| 1092 | not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o |
| 1093 | not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o |
| 1094 | not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o |
| 1095 | # Also ensure that ECP module was not re-enabled |
| 1096 | not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o |
| 1097 | |
| 1098 | # Run the tests |
| 1099 | # ------------- |
| 1100 | |
| 1101 | msg "test: full + accelerated EC algs - ECP" |
| 1102 | make test |
| 1103 | |
| 1104 | msg "ssl-opt: full + accelerated EC algs - ECP" |
| 1105 | tests/ssl-opt.sh |
| 1106 | } |
| 1107 | |
| 1108 | # Reference function used for driver's coverage analysis in analyze_outcomes.py |
| 1109 | # in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all(). |
| 1110 | # Keep in sync with its accelerated counterpart. |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1111 | component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () { |
| 1112 | msg "build: full + non accelerated EC algs" |
| 1113 | |
| 1114 | config_psa_crypto_no_ecp_at_all 0 |
| 1115 | |
| 1116 | make |
| 1117 | |
| 1118 | msg "test: full + non accelerated EC algs" |
| 1119 | make test |
| 1120 | |
| 1121 | msg "ssl-opt: full + non accelerated EC algs" |
| 1122 | tests/ssl-opt.sh |
| 1123 | } |
| 1124 | |
| 1125 | # This is a common configuration helper used directly from: |
| 1126 | # - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum |
| 1127 | # - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum |
| 1128 | # and indirectly from: |
| 1129 | # - component_test_psa_crypto_config_accel_ecc_no_bignum |
| 1130 | # - accelerate all EC algs, disable RSA and FFDH |
| 1131 | # - component_test_psa_crypto_config_reference_ecc_no_bignum |
| 1132 | # - this is the reference component of the above |
| 1133 | # - it still disables RSA and FFDH, but it uses builtin EC algs |
| 1134 | # - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum |
| 1135 | # - accelerate all EC and FFDH algs, disable only RSA |
| 1136 | # - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum |
| 1137 | # - this is the reference component of the above |
| 1138 | # - it still disables RSA, but it uses builtin EC and FFDH algs |
| 1139 | # |
| 1140 | # This function accepts 2 parameters: |
| 1141 | # $1: a boolean value which states if we are testing an accelerated scenario |
| 1142 | # or not. |
| 1143 | # $2: a string value which states which components are tested. Allowed values |
| 1144 | # are "ECC" or "ECC_DH". |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 1145 | config_psa_crypto_config_accel_ecc_ffdh_no_bignum () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1146 | driver_only="$1" |
| 1147 | test_target="$2" |
| 1148 | # start with full config for maximum coverage (also enables USE_PSA) |
| 1149 | helper_libtestdriver1_adjust_config "full" |
| 1150 | |
| 1151 | if [ "$driver_only" -eq 1 ]; then |
| 1152 | # Disable modules that are accelerated |
| 1153 | scripts/config.py unset MBEDTLS_ECDSA_C |
| 1154 | scripts/config.py unset MBEDTLS_ECDH_C |
| 1155 | scripts/config.py unset MBEDTLS_ECJPAKE_C |
| 1156 | # Disable ECP module (entirely) |
| 1157 | scripts/config.py unset MBEDTLS_ECP_C |
| 1158 | # Also disable bignum |
| 1159 | scripts/config.py unset MBEDTLS_BIGNUM_C |
| 1160 | fi |
| 1161 | |
| 1162 | # Disable all the features that auto-enable ECP_LIGHT (see build_info.h) |
| 1163 | scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED |
| 1164 | scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED |
| 1165 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE |
| 1166 | |
| 1167 | # RSA support is intentionally disabled on this test because RSA_C depends |
| 1168 | # on BIGNUM_C. |
| 1169 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*" |
| 1170 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*" |
| 1171 | scripts/config.py unset MBEDTLS_RSA_C |
| 1172 | scripts/config.py unset MBEDTLS_PKCS1_V15 |
| 1173 | scripts/config.py unset MBEDTLS_PKCS1_V21 |
| 1174 | scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT |
| 1175 | # Also disable key exchanges that depend on RSA |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1176 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED |
| 1177 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED |
| 1178 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED |
| 1179 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED |
| 1180 | |
| 1181 | if [ "$test_target" = "ECC" ]; then |
| 1182 | # When testing ECC only, we disable FFDH support, both from builtin and |
| 1183 | # PSA sides, and also disable the key exchanges that depend on DHM. |
| 1184 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_FFDH |
| 1185 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*" |
| 1186 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_DH_RFC7919_[0-9]*" |
| 1187 | scripts/config.py unset MBEDTLS_DHM_C |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1188 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED |
| 1189 | else |
| 1190 | # When testing ECC and DH instead, we disable DHM and depending key |
| 1191 | # exchanges only in the accelerated build |
| 1192 | if [ "$driver_only" -eq 1 ]; then |
| 1193 | scripts/config.py unset MBEDTLS_DHM_C |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1194 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED |
| 1195 | fi |
| 1196 | fi |
| 1197 | |
| 1198 | # Restartable feature is not yet supported by PSA. Once it will in |
| 1199 | # the future, the following line could be removed (see issues |
| 1200 | # 6061, 6332 and following ones) |
| 1201 | scripts/config.py unset MBEDTLS_ECP_RESTARTABLE |
| 1202 | } |
| 1203 | |
| 1204 | # Common helper used by: |
| 1205 | # - component_test_psa_crypto_config_accel_ecc_no_bignum |
| 1206 | # - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum |
| 1207 | # |
| 1208 | # The goal is to build and test accelerating either: |
| 1209 | # - ECC only or |
| 1210 | # - both ECC and FFDH |
| 1211 | # |
| 1212 | # It is meant to be used in conjunction with |
| 1213 | # common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers |
| 1214 | # coverage analysis in the "analyze_outcomes.py" script. |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1215 | common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () { |
| 1216 | test_target="$1" |
| 1217 | |
| 1218 | # This is an internal helper to simplify text message handling |
| 1219 | if [ "$test_target" = "ECC_DH" ]; then |
| 1220 | accel_text="ECC/FFDH" |
| 1221 | removed_text="ECP - DH" |
| 1222 | else |
| 1223 | accel_text="ECC" |
| 1224 | removed_text="ECP" |
| 1225 | fi |
| 1226 | |
| 1227 | msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM" |
| 1228 | |
| 1229 | # By default we accelerate all EC keys/algs |
| 1230 | loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \ |
| 1231 | ALG_ECDH \ |
| 1232 | ALG_JPAKE \ |
| 1233 | $(helper_get_psa_key_type_list "ECC") \ |
| 1234 | $(helper_get_psa_curve_list)" |
| 1235 | # Optionally we can also add DH to the list of accelerated items |
| 1236 | if [ "$test_target" = "ECC_DH" ]; then |
| 1237 | loc_accel_list="$loc_accel_list \ |
| 1238 | ALG_FFDH \ |
| 1239 | $(helper_get_psa_key_type_list "DH") \ |
| 1240 | $(helper_get_psa_dh_group_list)" |
| 1241 | fi |
| 1242 | |
| 1243 | # Configure |
| 1244 | # --------- |
| 1245 | |
| 1246 | # Set common configurations between library's and driver's builds |
| 1247 | config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target" |
| 1248 | # Disable all the builtin curves. All the required algs are accelerated. |
| 1249 | helper_disable_builtin_curves |
| 1250 | |
| 1251 | # Build |
| 1252 | # ----- |
| 1253 | |
| 1254 | # Things we wanted supported in libtestdriver1, but not accelerated in the main library: |
| 1255 | # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic. |
| 1256 | loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \ |
| 1257 | ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512" |
| 1258 | |
| 1259 | helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list" |
| 1260 | |
| 1261 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 1262 | |
| 1263 | # Make sure any built-in EC alg was not re-enabled by accident (additive config) |
| 1264 | not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o |
| 1265 | not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o |
| 1266 | not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o |
| 1267 | # Also ensure that ECP, RSA, [DHM] or BIGNUM modules were not re-enabled |
| 1268 | not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o |
| 1269 | not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o |
| 1270 | not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o |
| 1271 | not grep mbedtls_dhm_ ${BUILTIN_SRC_PATH}/dhm.o |
| 1272 | |
| 1273 | # Run the tests |
| 1274 | # ------------- |
| 1275 | |
| 1276 | msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - DHM - BIGNUM" |
| 1277 | |
| 1278 | make test |
| 1279 | |
| 1280 | msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM" |
| 1281 | tests/ssl-opt.sh |
| 1282 | } |
| 1283 | |
| 1284 | # Common helper used by: |
| 1285 | # - component_test_psa_crypto_config_reference_ecc_no_bignum |
| 1286 | # - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum |
| 1287 | # |
| 1288 | # The goal is to build and test a reference scenario (i.e. with builtin |
| 1289 | # components) compared to the ones used in |
| 1290 | # common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above. |
| 1291 | # |
| 1292 | # It is meant to be used in conjunction with |
| 1293 | # common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers' |
| 1294 | # coverage analysis in "analyze_outcomes.py" script. |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1295 | common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () { |
| 1296 | test_target="$1" |
| 1297 | |
| 1298 | # This is an internal helper to simplify text message handling |
| 1299 | if [ "$test_target" = "ECC_DH" ]; then |
| 1300 | accel_text="ECC/FFDH" |
| 1301 | else |
| 1302 | accel_text="ECC" |
| 1303 | fi |
| 1304 | |
| 1305 | msg "build: full + non accelerated $accel_text algs + USE_PSA" |
| 1306 | |
| 1307 | config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target" |
| 1308 | |
| 1309 | make |
| 1310 | |
| 1311 | msg "test suites: full + non accelerated EC algs + USE_PSA" |
| 1312 | make test |
| 1313 | |
| 1314 | msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA" |
| 1315 | tests/ssl-opt.sh |
| 1316 | } |
| 1317 | |
| 1318 | component_test_psa_crypto_config_accel_ecc_no_bignum () { |
| 1319 | common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC" |
| 1320 | } |
| 1321 | |
| 1322 | component_test_psa_crypto_config_reference_ecc_no_bignum () { |
| 1323 | common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC" |
| 1324 | } |
| 1325 | |
| 1326 | component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () { |
| 1327 | common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH" |
| 1328 | } |
| 1329 | |
| 1330 | component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () { |
| 1331 | common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH" |
| 1332 | } |
| 1333 | |
Gilles Peskine | effa6a0 | 2024-09-14 11:35:36 +0200 | [diff] [blame] | 1334 | component_test_tfm_config_as_is () { |
| 1335 | msg "build: configs/config-tfm.h" |
Minos Galanakis | 5da58e5 | 2024-11-07 15:35:33 +0000 | [diff] [blame] | 1336 | MBEDTLS_CONFIG="configs/config-tfm.h" |
Harry Ramsey | 94c386a | 2025-01-16 16:08:34 +0000 | [diff] [blame^] | 1337 | CRYPTO_CONFIG="tf-psa-crypto/configs/ext/crypto_config_profile_medium.h" |
Minos Galanakis | 4f619e1 | 2024-11-14 14:56:47 +0000 | [diff] [blame] | 1338 | CC=$ASAN_CC cmake -DMBEDTLS_CONFIG_FILE="$MBEDTLS_CONFIG" -DTF_PSA_CRYPTO_CONFIG_FILE="$CRYPTO_CONFIG" -D CMAKE_BUILD_TYPE:String=Asan . |
Gilles Peskine | effa6a0 | 2024-09-14 11:35:36 +0200 | [diff] [blame] | 1339 | make |
| 1340 | |
| 1341 | msg "test: configs/config-tfm.h - unit tests" |
| 1342 | make test |
| 1343 | } |
| 1344 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1345 | # Helper for setting common configurations between: |
| 1346 | # - component_test_tfm_config_p256m_driver_accel_ec() |
Gilles Peskine | effa6a0 | 2024-09-14 11:35:36 +0200 | [diff] [blame] | 1347 | # - component_test_tfm_config_no_p256m() |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1348 | common_tfm_config () { |
| 1349 | # Enable TF-M config |
| 1350 | cp configs/config-tfm.h "$CONFIG_H" |
Harry Ramsey | 94c386a | 2025-01-16 16:08:34 +0000 | [diff] [blame^] | 1351 | cp tf-psa-crypto/configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1352 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1353 | # Config adjustment for better test coverage in our environment. |
| 1354 | # This is not needed just to build and pass tests. |
| 1355 | # |
| 1356 | # Enable filesystem I/O for the benefit of PK parse/write tests. |
Minos Galanakis | 5da58e5 | 2024-11-07 15:35:33 +0000 | [diff] [blame] | 1357 | sed -i '/PROFILE_M_PSA_CRYPTO_CONFIG_H/i #define MBEDTLS_FS_IO' "$CRYPTO_CONFIG_H" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | # Keep this in sync with component_test_tfm_config() as they are both meant |
| 1361 | # to be used in analyze_outcomes.py for driver's coverage analysis. |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1362 | component_test_tfm_config_p256m_driver_accel_ec () { |
| 1363 | msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA" |
| 1364 | |
| 1365 | common_tfm_config |
| 1366 | |
| 1367 | # Build crypto library |
David Horstmann | 5b93d97 | 2024-10-31 15:36:05 +0000 | [diff] [blame] | 1368 | make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../framework/tests/include/spe" LDFLAGS="$ASAN_CFLAGS" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1369 | |
| 1370 | # Make sure any built-in EC alg was not re-enabled by accident (additive config) |
| 1371 | not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o |
| 1372 | not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o |
| 1373 | not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o |
| 1374 | # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled |
| 1375 | not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o |
| 1376 | not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o |
| 1377 | not grep mbedtls_dhm_ ${BUILTIN_SRC_PATH}/dhm.o |
| 1378 | not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o |
| 1379 | # Check that p256m was built |
| 1380 | grep -q p256_ecdsa_ library/libmbedcrypto.a |
| 1381 | |
| 1382 | # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration |
| 1383 | # files, so we want to ensure that it has not be re-enabled accidentally. |
| 1384 | not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o |
| 1385 | |
| 1386 | # Run the tests |
| 1387 | msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA" |
| 1388 | make test |
| 1389 | } |
| 1390 | |
| 1391 | # Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as |
| 1392 | # they are both meant to be used in analyze_outcomes.py for driver's coverage |
| 1393 | # analysis. |
Gilles Peskine | effa6a0 | 2024-09-14 11:35:36 +0200 | [diff] [blame] | 1394 | component_test_tfm_config_no_p256m () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1395 | common_tfm_config |
| 1396 | |
| 1397 | # Disable P256M driver, which is on by default, so that analyze_outcomes |
| 1398 | # can compare this test with test_tfm_config_p256m_driver_accel_ec |
Minos Galanakis | 5da58e5 | 2024-11-07 15:35:33 +0000 | [diff] [blame] | 1399 | sed -i '/PROFILE_M_PSA_CRYPTO_CONFIG_H/i #undef MBEDTLS_PSA_P256M_DRIVER_ENABLED' "$CRYPTO_CONFIG_H" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1400 | |
Gilles Peskine | effa6a0 | 2024-09-14 11:35:36 +0200 | [diff] [blame] | 1401 | msg "build: TF-M config without p256m" |
David Horstmann | 5b93d97 | 2024-10-31 15:36:05 +0000 | [diff] [blame] | 1402 | make CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' tests |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1403 | |
| 1404 | # Check that p256m was not built |
| 1405 | not grep p256_ecdsa_ library/libmbedcrypto.a |
| 1406 | |
| 1407 | # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration |
| 1408 | # files, so we want to ensure that it has not be re-enabled accidentally. |
| 1409 | not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o |
| 1410 | |
Gilles Peskine | effa6a0 | 2024-09-14 11:35:36 +0200 | [diff] [blame] | 1411 | msg "test: TF-M config without p256m" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1412 | make test |
| 1413 | } |
| 1414 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1415 | # This is an helper used by: |
| 1416 | # - component_test_psa_ecc_key_pair_no_derive |
| 1417 | # - component_test_psa_ecc_key_pair_no_generate |
| 1418 | # The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols |
| 1419 | # enabled, but one. Input arguments are as follows: |
Gilles Peskine | fef912c | 2024-09-20 16:07:09 +0200 | [diff] [blame] | 1420 | # - $1 is the configuration to start from |
| 1421 | # - $2 is the key type under test, i.e. ECC/RSA/DH |
| 1422 | # - $3 is the key option to be unset (i.e. generate, derive, etc) |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 1423 | build_and_test_psa_want_key_pair_partial () { |
Gilles Peskine | fef912c | 2024-09-20 16:07:09 +0200 | [diff] [blame] | 1424 | base_config=$1 |
| 1425 | key_type=$2 |
| 1426 | unset_option=$3 |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1427 | disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}" |
| 1428 | |
Gilles Peskine | fef912c | 2024-09-20 16:07:09 +0200 | [diff] [blame] | 1429 | msg "build: $base_config - ${disabled_psa_want}" |
| 1430 | scripts/config.py "$base_config" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1431 | |
| 1432 | # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in |
| 1433 | # crypto_config.h so we just disable the one we don't want. |
| 1434 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want" |
| 1435 | |
| 1436 | make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" |
| 1437 | |
Gilles Peskine | fef912c | 2024-09-20 16:07:09 +0200 | [diff] [blame] | 1438 | msg "test: $base_config - ${disabled_psa_want}" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1439 | make test |
| 1440 | } |
| 1441 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 1442 | component_test_psa_ecc_key_pair_no_derive () { |
Gilles Peskine | fef912c | 2024-09-20 16:07:09 +0200 | [diff] [blame] | 1443 | build_and_test_psa_want_key_pair_partial full "ECC" "DERIVE" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1444 | } |
| 1445 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 1446 | component_test_psa_ecc_key_pair_no_generate () { |
Gilles Peskine | fef912c | 2024-09-20 16:07:09 +0200 | [diff] [blame] | 1447 | # TLS needs ECC key generation whenever ephemeral ECDH is enabled. |
| 1448 | # We don't have proper guards for configurations with ECC key generation |
| 1449 | # disabled (https://github.com/Mbed-TLS/mbedtls/issues/9481). Until |
| 1450 | # then (if ever), just test the crypto part of the library. |
| 1451 | build_and_test_psa_want_key_pair_partial crypto_full "ECC" "GENERATE" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | config_psa_crypto_accel_rsa () { |
| 1455 | driver_only=$1 |
| 1456 | |
| 1457 | # Start from crypto_full config (no X.509, no TLS) |
| 1458 | helper_libtestdriver1_adjust_config "crypto_full" |
| 1459 | |
| 1460 | if [ "$driver_only" -eq 1 ]; then |
| 1461 | # Remove RSA support and its dependencies |
| 1462 | scripts/config.py unset MBEDTLS_RSA_C |
| 1463 | scripts/config.py unset MBEDTLS_PKCS1_V15 |
| 1464 | scripts/config.py unset MBEDTLS_PKCS1_V21 |
| 1465 | |
| 1466 | # We need PEM parsing in the test library as well to support the import |
| 1467 | # of PEM encoded RSA keys. |
Minos Galanakis | 23452f5 | 2024-11-28 17:48:14 +0000 | [diff] [blame] | 1468 | scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C |
| 1469 | scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1470 | fi |
| 1471 | } |
| 1472 | |
| 1473 | component_test_psa_crypto_config_accel_rsa_crypto () { |
| 1474 | msg "build: crypto_full with accelerated RSA" |
| 1475 | |
| 1476 | loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \ |
| 1477 | ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \ |
| 1478 | KEY_TYPE_RSA_PUBLIC_KEY \ |
| 1479 | KEY_TYPE_RSA_KEY_PAIR_BASIC \ |
| 1480 | KEY_TYPE_RSA_KEY_PAIR_GENERATE \ |
| 1481 | KEY_TYPE_RSA_KEY_PAIR_IMPORT \ |
| 1482 | KEY_TYPE_RSA_KEY_PAIR_EXPORT" |
| 1483 | |
| 1484 | # Configure |
| 1485 | # --------- |
| 1486 | |
| 1487 | config_psa_crypto_accel_rsa 1 |
| 1488 | |
| 1489 | # Build |
| 1490 | # ----- |
| 1491 | |
| 1492 | # These hashes are needed for unit tests. |
| 1493 | loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \ |
| 1494 | ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5" |
| 1495 | helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list" |
| 1496 | |
| 1497 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 1498 | |
| 1499 | # Make sure this was not re-enabled by accident (additive config) |
| 1500 | not grep mbedtls_rsa ${BUILTIN_SRC_PATH}/rsa.o |
| 1501 | |
| 1502 | # Run the tests |
| 1503 | # ------------- |
| 1504 | |
| 1505 | msg "test: crypto_full with accelerated RSA" |
| 1506 | make test |
| 1507 | } |
| 1508 | |
| 1509 | component_test_psa_crypto_config_reference_rsa_crypto () { |
| 1510 | msg "build: crypto_full with non-accelerated RSA" |
| 1511 | |
| 1512 | # Configure |
| 1513 | # --------- |
| 1514 | config_psa_crypto_accel_rsa 0 |
| 1515 | |
| 1516 | # Build |
| 1517 | # ----- |
| 1518 | make |
| 1519 | |
| 1520 | # Run the tests |
| 1521 | # ------------- |
| 1522 | msg "test: crypto_full with non-accelerated RSA" |
| 1523 | make test |
| 1524 | } |
| 1525 | |
| 1526 | # This is a temporary test to verify that full RSA support is present even when |
| 1527 | # only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined. |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 1528 | component_test_new_psa_want_key_pair_symbol () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1529 | msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC" |
| 1530 | |
| 1531 | # Create a temporary output file unless there is already one set |
| 1532 | if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then |
| 1533 | REMOVE_OUTCOME_ON_EXIT="no" |
| 1534 | else |
| 1535 | REMOVE_OUTCOME_ON_EXIT="yes" |
| 1536 | MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv" |
| 1537 | export MBEDTLS_TEST_OUTCOME_FILE |
| 1538 | fi |
| 1539 | |
| 1540 | # Start from crypto configuration |
| 1541 | scripts/config.py crypto |
| 1542 | |
| 1543 | # Remove RSA support and its dependencies |
| 1544 | scripts/config.py unset MBEDTLS_PKCS1_V15 |
| 1545 | scripts/config.py unset MBEDTLS_PKCS1_V21 |
| 1546 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED |
| 1547 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED |
| 1548 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1549 | scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED |
| 1550 | scripts/config.py unset MBEDTLS_RSA_C |
| 1551 | scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT |
| 1552 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1553 | # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure |
| 1554 | # that proper translations is done in crypto_legacy.h. |
| 1555 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT |
| 1556 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT |
| 1557 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE |
| 1558 | |
| 1559 | make |
| 1560 | |
| 1561 | msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC" |
| 1562 | make test |
| 1563 | |
| 1564 | # Parse only 1 relevant line from the outcome file, i.e. a test which is |
| 1565 | # performing RSA signature. |
| 1566 | msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS" |
| 1567 | cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS" |
| 1568 | |
| 1569 | if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then |
| 1570 | rm $MBEDTLS_TEST_OUTCOME_FILE |
| 1571 | fi |
| 1572 | } |
| 1573 | |
| 1574 | component_test_psa_crypto_config_accel_hash () { |
Ronald Cron | 93ba625 | 2024-09-05 10:37:14 +0200 | [diff] [blame] | 1575 | msg "test: accelerated hash" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1576 | |
| 1577 | loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \ |
| 1578 | ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \ |
| 1579 | ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512" |
| 1580 | |
| 1581 | # Configure |
| 1582 | # --------- |
| 1583 | |
| 1584 | # Start from default config (no USE_PSA) |
| 1585 | helper_libtestdriver1_adjust_config "default" |
| 1586 | |
| 1587 | # Disable the things that are being accelerated |
| 1588 | scripts/config.py unset MBEDTLS_MD5_C |
| 1589 | scripts/config.py unset MBEDTLS_RIPEMD160_C |
| 1590 | scripts/config.py unset MBEDTLS_SHA1_C |
| 1591 | scripts/config.py unset MBEDTLS_SHA224_C |
| 1592 | scripts/config.py unset MBEDTLS_SHA256_C |
| 1593 | scripts/config.py unset MBEDTLS_SHA384_C |
| 1594 | scripts/config.py unset MBEDTLS_SHA512_C |
| 1595 | scripts/config.py unset MBEDTLS_SHA3_C |
| 1596 | |
| 1597 | # Build |
| 1598 | # ----- |
| 1599 | |
| 1600 | helper_libtestdriver1_make_drivers "$loc_accel_list" |
| 1601 | |
| 1602 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 1603 | |
| 1604 | # There's a risk of something getting re-enabled via config_psa.h; |
| 1605 | # make sure it did not happen. Note: it's OK for MD_C to be enabled. |
| 1606 | not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o |
| 1607 | not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o |
| 1608 | not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o |
| 1609 | not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o |
| 1610 | not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o |
| 1611 | |
| 1612 | # Run the tests |
| 1613 | # ------------- |
| 1614 | |
Ronald Cron | 93ba625 | 2024-09-05 10:37:14 +0200 | [diff] [blame] | 1615 | msg "test: accelerated hash" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1616 | make test |
| 1617 | } |
| 1618 | |
| 1619 | # Auxiliary function to build config for hashes with and without drivers |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1620 | config_psa_crypto_hash_use_psa () { |
| 1621 | driver_only="$1" |
| 1622 | # start with config full for maximum coverage (also enables USE_PSA) |
| 1623 | helper_libtestdriver1_adjust_config "full" |
| 1624 | if [ "$driver_only" -eq 1 ]; then |
| 1625 | # disable the built-in implementation of hashes |
| 1626 | scripts/config.py unset MBEDTLS_MD5_C |
| 1627 | scripts/config.py unset MBEDTLS_RIPEMD160_C |
| 1628 | scripts/config.py unset MBEDTLS_SHA1_C |
| 1629 | scripts/config.py unset MBEDTLS_SHA224_C |
| 1630 | scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below |
| 1631 | scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT |
| 1632 | scripts/config.py unset MBEDTLS_SHA384_C |
| 1633 | scripts/config.py unset MBEDTLS_SHA512_C |
| 1634 | scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT |
| 1635 | scripts/config.py unset MBEDTLS_SHA3_C |
| 1636 | fi |
| 1637 | } |
| 1638 | |
| 1639 | # Note that component_test_psa_crypto_config_reference_hash_use_psa |
| 1640 | # is related to this component and both components need to be kept in sync. |
| 1641 | # For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa. |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1642 | component_test_psa_crypto_config_accel_hash_use_psa () { |
| 1643 | msg "test: full with accelerated hashes" |
| 1644 | |
| 1645 | loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \ |
| 1646 | ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \ |
| 1647 | ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512" |
| 1648 | |
| 1649 | # Configure |
| 1650 | # --------- |
| 1651 | |
| 1652 | config_psa_crypto_hash_use_psa 1 |
| 1653 | |
| 1654 | # Build |
| 1655 | # ----- |
| 1656 | |
| 1657 | helper_libtestdriver1_make_drivers "$loc_accel_list" |
| 1658 | |
| 1659 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 1660 | |
| 1661 | # There's a risk of something getting re-enabled via config_psa.h; |
| 1662 | # make sure it did not happen. Note: it's OK for MD_C to be enabled. |
| 1663 | not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o |
| 1664 | not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o |
| 1665 | not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o |
| 1666 | not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o |
| 1667 | not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o |
| 1668 | |
| 1669 | # Run the tests |
| 1670 | # ------------- |
| 1671 | |
| 1672 | msg "test: full with accelerated hashes" |
| 1673 | make test |
| 1674 | |
| 1675 | # This is mostly useful so that we can later compare outcome files with |
| 1676 | # the reference config in analyze_outcomes.py, to check that the |
| 1677 | # dependency declarations in ssl-opt.sh and in TLS code are correct. |
| 1678 | msg "test: ssl-opt.sh, full with accelerated hashes" |
| 1679 | tests/ssl-opt.sh |
| 1680 | |
| 1681 | # This is to make sure all ciphersuites are exercised, but we don't need |
| 1682 | # interop testing (besides, we already got some from ssl-opt.sh). |
| 1683 | msg "test: compat.sh, full with accelerated hashes" |
| 1684 | tests/compat.sh -p mbedTLS -V YES |
| 1685 | } |
| 1686 | |
| 1687 | # This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa |
| 1688 | # without accelerated hash. The outcome from both components are used by the analyze_outcomes.py |
| 1689 | # script to find regression in test coverage when accelerated hash is used (tests and ssl-opt). |
| 1690 | # Both components need to be kept in sync. |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 1691 | component_test_psa_crypto_config_reference_hash_use_psa () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1692 | msg "test: full without accelerated hashes" |
| 1693 | |
| 1694 | config_psa_crypto_hash_use_psa 0 |
| 1695 | |
| 1696 | make |
| 1697 | |
| 1698 | msg "test: full without accelerated hashes" |
| 1699 | make test |
| 1700 | |
| 1701 | msg "test: ssl-opt.sh, full without accelerated hashes" |
| 1702 | tests/ssl-opt.sh |
| 1703 | } |
| 1704 | |
| 1705 | # Auxiliary function to build config for hashes with and without drivers |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1706 | config_psa_crypto_hmac_use_psa () { |
| 1707 | driver_only="$1" |
| 1708 | # start with config full for maximum coverage (also enables USE_PSA) |
| 1709 | helper_libtestdriver1_adjust_config "full" |
| 1710 | |
| 1711 | if [ "$driver_only" -eq 1 ]; then |
| 1712 | # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT |
| 1713 | # is still enabled though (for ENTROPY_C among others). |
| 1714 | scripts/config.py unset MBEDTLS_MD_C |
| 1715 | # Disable also the builtin hashes since they are supported by the driver |
| 1716 | # and MD module is able to perform PSA dispathing. |
| 1717 | scripts/config.py unset-all MBEDTLS_SHA |
| 1718 | scripts/config.py unset MBEDTLS_MD5_C |
| 1719 | scripts/config.py unset MBEDTLS_RIPEMD160_C |
| 1720 | fi |
| 1721 | |
| 1722 | # Direct dependencies of MD_C. We disable them also in the reference |
| 1723 | # component to work with the same set of features. |
| 1724 | scripts/config.py unset MBEDTLS_PKCS7_C |
| 1725 | scripts/config.py unset MBEDTLS_PKCS5_C |
| 1726 | scripts/config.py unset MBEDTLS_HMAC_DRBG_C |
| 1727 | scripts/config.py unset MBEDTLS_HKDF_C |
| 1728 | # Dependencies of HMAC_DRBG |
| 1729 | scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC |
| 1730 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA |
| 1731 | } |
| 1732 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 1733 | component_test_psa_crypto_config_accel_hmac () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1734 | msg "test: full with accelerated hmac" |
| 1735 | |
| 1736 | loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \ |
| 1737 | ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \ |
| 1738 | ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \ |
| 1739 | ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512" |
| 1740 | |
| 1741 | # Configure |
| 1742 | # --------- |
| 1743 | |
| 1744 | config_psa_crypto_hmac_use_psa 1 |
| 1745 | |
| 1746 | # Build |
| 1747 | # ----- |
| 1748 | |
| 1749 | helper_libtestdriver1_make_drivers "$loc_accel_list" |
| 1750 | |
| 1751 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 1752 | |
| 1753 | # Ensure that built-in support for HMAC is disabled. |
| 1754 | not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o |
| 1755 | |
| 1756 | # Run the tests |
| 1757 | # ------------- |
| 1758 | |
| 1759 | msg "test: full with accelerated hmac" |
| 1760 | make test |
| 1761 | } |
| 1762 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 1763 | component_test_psa_crypto_config_reference_hmac () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1764 | msg "test: full without accelerated hmac" |
| 1765 | |
| 1766 | config_psa_crypto_hmac_use_psa 0 |
| 1767 | |
| 1768 | make |
| 1769 | |
| 1770 | msg "test: full without accelerated hmac" |
| 1771 | make test |
| 1772 | } |
| 1773 | |
| 1774 | component_test_psa_crypto_config_accel_des () { |
Ronald Cron | 93ba625 | 2024-09-05 10:37:14 +0200 | [diff] [blame] | 1775 | msg "test: accelerated DES" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1776 | |
| 1777 | # Albeit this components aims at accelerating DES which should only support |
| 1778 | # CBC and ECB modes, we need to accelerate more than that otherwise DES_C |
| 1779 | # would automatically be re-enabled by "config_adjust_legacy_from_psa.c" |
| 1780 | loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 \ |
| 1781 | ALG_CTR ALG_CFB ALG_OFB ALG_XTS ALG_CMAC \ |
| 1782 | KEY_TYPE_DES" |
| 1783 | |
| 1784 | # Note: we cannot accelerate all ciphers' key types otherwise we would also |
| 1785 | # have to either disable CCM/GCM or accelerate them, but that's out of scope |
| 1786 | # of this component. This limitation will be addressed by #8598. |
| 1787 | |
| 1788 | # Configure |
| 1789 | # --------- |
| 1790 | |
| 1791 | # Start from the full config |
| 1792 | helper_libtestdriver1_adjust_config "full" |
| 1793 | |
| 1794 | # Disable the things that are being accelerated |
| 1795 | scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC |
| 1796 | scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7 |
| 1797 | scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR |
| 1798 | scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB |
| 1799 | scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB |
| 1800 | scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS |
| 1801 | scripts/config.py unset MBEDTLS_DES_C |
| 1802 | scripts/config.py unset MBEDTLS_CMAC_C |
| 1803 | |
| 1804 | # Build |
| 1805 | # ----- |
| 1806 | |
| 1807 | helper_libtestdriver1_make_drivers "$loc_accel_list" |
| 1808 | |
| 1809 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 1810 | |
| 1811 | # Make sure this was not re-enabled by accident (additive config) |
Gilles Peskine | 29e86ca | 2024-06-19 15:09:27 +0200 | [diff] [blame] | 1812 | not grep mbedtls_des ${BUILTIN_SRC_PATH}/des.o |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1813 | |
| 1814 | # Run the tests |
| 1815 | # ------------- |
| 1816 | |
Ronald Cron | 93ba625 | 2024-09-05 10:37:14 +0200 | [diff] [blame] | 1817 | msg "test: accelerated DES" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1818 | make test |
| 1819 | } |
| 1820 | |
| 1821 | component_test_psa_crypto_config_accel_aead () { |
Ronald Cron | 93ba625 | 2024-09-05 10:37:14 +0200 | [diff] [blame] | 1822 | msg "test: accelerated AEAD" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1823 | |
| 1824 | loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \ |
| 1825 | KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA" |
| 1826 | |
| 1827 | # Configure |
| 1828 | # --------- |
| 1829 | |
| 1830 | # Start from full config |
| 1831 | helper_libtestdriver1_adjust_config "full" |
| 1832 | |
| 1833 | # Disable things that are being accelerated |
| 1834 | scripts/config.py unset MBEDTLS_GCM_C |
| 1835 | scripts/config.py unset MBEDTLS_CCM_C |
| 1836 | scripts/config.py unset MBEDTLS_CHACHAPOLY_C |
| 1837 | |
| 1838 | # Disable CCM_STAR_NO_TAG because this re-enables CCM_C. |
| 1839 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG |
| 1840 | |
| 1841 | # Build |
| 1842 | # ----- |
| 1843 | |
| 1844 | helper_libtestdriver1_make_drivers "$loc_accel_list" |
| 1845 | |
| 1846 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 1847 | |
| 1848 | # Make sure this was not re-enabled by accident (additive config) |
| 1849 | not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o |
| 1850 | not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o |
| 1851 | not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o |
| 1852 | |
| 1853 | # Run the tests |
| 1854 | # ------------- |
| 1855 | |
Ronald Cron | 93ba625 | 2024-09-05 10:37:14 +0200 | [diff] [blame] | 1856 | msg "test: accelerated AEAD" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1857 | make test |
| 1858 | } |
| 1859 | |
| 1860 | # This is a common configuration function used in: |
| 1861 | # - component_test_psa_crypto_config_accel_cipher_aead_cmac |
| 1862 | # - component_test_psa_crypto_config_reference_cipher_aead_cmac |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 1863 | common_psa_crypto_config_accel_cipher_aead_cmac () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1864 | # Start from the full config |
| 1865 | helper_libtestdriver1_adjust_config "full" |
| 1866 | |
| 1867 | scripts/config.py unset MBEDTLS_NIST_KW_C |
| 1868 | } |
| 1869 | |
| 1870 | # The 2 following test components, i.e. |
| 1871 | # - component_test_psa_crypto_config_accel_cipher_aead_cmac |
| 1872 | # - component_test_psa_crypto_config_reference_cipher_aead_cmac |
| 1873 | # are meant to be used together in analyze_outcomes.py script in order to test |
| 1874 | # driver's coverage for ciphers and AEADs. |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1875 | component_test_psa_crypto_config_accel_cipher_aead_cmac () { |
| 1876 | msg "build: full config with accelerated cipher inc. AEAD and CMAC" |
| 1877 | |
| 1878 | loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \ |
| 1879 | ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \ |
| 1880 | ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \ |
| 1881 | KEY_TYPE_DES KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA" |
| 1882 | |
| 1883 | # Configure |
| 1884 | # --------- |
| 1885 | |
| 1886 | common_psa_crypto_config_accel_cipher_aead_cmac |
| 1887 | |
| 1888 | # Disable the things that are being accelerated |
| 1889 | scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC |
| 1890 | scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7 |
| 1891 | scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR |
| 1892 | scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB |
| 1893 | scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB |
| 1894 | scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS |
| 1895 | scripts/config.py unset MBEDTLS_GCM_C |
| 1896 | scripts/config.py unset MBEDTLS_CCM_C |
| 1897 | scripts/config.py unset MBEDTLS_CHACHAPOLY_C |
| 1898 | scripts/config.py unset MBEDTLS_CMAC_C |
| 1899 | scripts/config.py unset MBEDTLS_DES_C |
| 1900 | scripts/config.py unset MBEDTLS_AES_C |
| 1901 | scripts/config.py unset MBEDTLS_ARIA_C |
| 1902 | scripts/config.py unset MBEDTLS_CHACHA20_C |
| 1903 | scripts/config.py unset MBEDTLS_CAMELLIA_C |
| 1904 | |
| 1905 | # Disable CIPHER_C entirely as all ciphers/AEADs are accelerated and PSA |
| 1906 | # does not depend on it. |
| 1907 | scripts/config.py unset MBEDTLS_CIPHER_C |
| 1908 | |
| 1909 | # Build |
| 1910 | # ----- |
| 1911 | |
| 1912 | helper_libtestdriver1_make_drivers "$loc_accel_list" |
| 1913 | |
| 1914 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 1915 | |
| 1916 | # Make sure this was not re-enabled by accident (additive config) |
| 1917 | not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o |
| 1918 | not grep mbedtls_des ${BUILTIN_SRC_PATH}/des.o |
| 1919 | not grep mbedtls_aes ${BUILTIN_SRC_PATH}/aes.o |
| 1920 | not grep mbedtls_aria ${BUILTIN_SRC_PATH}/aria.o |
| 1921 | not grep mbedtls_camellia ${BUILTIN_SRC_PATH}/camellia.o |
| 1922 | not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o |
| 1923 | not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o |
| 1924 | not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o |
| 1925 | not grep mbedtls_cmac ${BUILTIN_SRC_PATH}/cmac.o |
| 1926 | |
| 1927 | # Run the tests |
| 1928 | # ------------- |
| 1929 | |
| 1930 | msg "test: full config with accelerated cipher inc. AEAD and CMAC" |
| 1931 | make test |
| 1932 | |
| 1933 | msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC" |
| 1934 | tests/ssl-opt.sh |
| 1935 | |
| 1936 | msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC" |
| 1937 | tests/compat.sh -V NO -p mbedTLS |
| 1938 | } |
| 1939 | |
| 1940 | component_test_psa_crypto_config_reference_cipher_aead_cmac () { |
| 1941 | msg "build: full config with non-accelerated cipher inc. AEAD and CMAC" |
| 1942 | common_psa_crypto_config_accel_cipher_aead_cmac |
| 1943 | |
| 1944 | make |
| 1945 | |
| 1946 | msg "test: full config with non-accelerated cipher inc. AEAD and CMAC" |
| 1947 | make test |
| 1948 | |
| 1949 | msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC" |
| 1950 | tests/ssl-opt.sh |
| 1951 | |
| 1952 | msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC" |
| 1953 | tests/compat.sh -V NO -p mbedTLS |
| 1954 | } |
| 1955 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 1956 | common_block_cipher_dispatch () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 1957 | TEST_WITH_DRIVER="$1" |
| 1958 | |
| 1959 | # Start from the full config |
| 1960 | helper_libtestdriver1_adjust_config "full" |
| 1961 | |
| 1962 | if [ "$TEST_WITH_DRIVER" -eq 1 ]; then |
| 1963 | # Disable key types that are accelerated (there is no legacy equivalent |
| 1964 | # symbol for ECB) |
| 1965 | scripts/config.py unset MBEDTLS_AES_C |
| 1966 | scripts/config.py unset MBEDTLS_ARIA_C |
| 1967 | scripts/config.py unset MBEDTLS_CAMELLIA_C |
| 1968 | fi |
| 1969 | |
| 1970 | # Disable cipher's modes that, when not accelerated, cause |
| 1971 | # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h". |
| 1972 | # Keep this also in the reference component in order to skip the same tests |
| 1973 | # that were skipped in the accelerated one. |
| 1974 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR |
| 1975 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB |
| 1976 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB |
| 1977 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING |
| 1978 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7 |
| 1979 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC |
| 1980 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG |
| 1981 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128 |
| 1982 | |
| 1983 | # Disable direct dependency on AES_C |
| 1984 | scripts/config.py unset MBEDTLS_NIST_KW_C |
| 1985 | |
| 1986 | # Prevent the cipher module from using deprecated PSA path. The reason is |
| 1987 | # that otherwise there will be tests relying on "aes_info" (defined in |
| 1988 | # "cipher_wrap.c") whose functions are not available when AES_C is |
| 1989 | # not defined. ARIA and Camellia are not a problem in this case because |
| 1990 | # the PSA path is not tested for these key types. |
| 1991 | scripts/config.py set MBEDTLS_DEPRECATED_REMOVED |
| 1992 | } |
| 1993 | |
Gilles Peskine | a9dda7e | 2024-06-21 11:25:01 +0200 | [diff] [blame] | 1994 | component_test_full_block_cipher_psa_dispatch_static_keystore () { |
| 1995 | msg "build: full + PSA dispatch in block_cipher with static keystore" |
| 1996 | # Check that the static key store works well when CTR_DRBG uses a |
| 1997 | # PSA key for AES. |
| 1998 | scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC |
| 1999 | |
| 2000 | loc_accel_list="ALG_ECB_NO_PADDING \ |
| 2001 | KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA" |
| 2002 | |
| 2003 | # Configure |
| 2004 | # --------- |
| 2005 | |
| 2006 | common_block_cipher_dispatch 1 |
| 2007 | |
| 2008 | # Build |
| 2009 | # ----- |
| 2010 | |
| 2011 | helper_libtestdriver1_make_drivers "$loc_accel_list" |
| 2012 | |
| 2013 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 2014 | |
| 2015 | # Make sure disabled components were not re-enabled by accident (additive |
| 2016 | # config) |
| 2017 | not grep mbedtls_aes_ library/aes.o |
| 2018 | not grep mbedtls_aria_ library/aria.o |
| 2019 | not grep mbedtls_camellia_ library/camellia.o |
| 2020 | |
| 2021 | # Run the tests |
| 2022 | # ------------- |
| 2023 | |
| 2024 | msg "test: full + PSA dispatch in block_cipher with static keystore" |
| 2025 | make test |
| 2026 | } |
| 2027 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2028 | component_test_full_block_cipher_psa_dispatch () { |
| 2029 | msg "build: full + PSA dispatch in block_cipher" |
| 2030 | |
| 2031 | loc_accel_list="ALG_ECB_NO_PADDING \ |
| 2032 | KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA" |
| 2033 | |
| 2034 | # Configure |
| 2035 | # --------- |
| 2036 | |
| 2037 | common_block_cipher_dispatch 1 |
| 2038 | |
| 2039 | # Build |
| 2040 | # ----- |
| 2041 | |
| 2042 | helper_libtestdriver1_make_drivers "$loc_accel_list" |
| 2043 | |
| 2044 | helper_libtestdriver1_make_main "$loc_accel_list" |
| 2045 | |
| 2046 | # Make sure disabled components were not re-enabled by accident (additive |
| 2047 | # config) |
| 2048 | not grep mbedtls_aes_ ${BUILTIN_SRC_PATH}/aes.o |
| 2049 | not grep mbedtls_aria_ ${BUILTIN_SRC_PATH}/aria.o |
| 2050 | not grep mbedtls_camellia_ ${BUILTIN_SRC_PATH}/camellia.o |
| 2051 | |
| 2052 | # Run the tests |
| 2053 | # ------------- |
| 2054 | |
| 2055 | msg "test: full + PSA dispatch in block_cipher" |
| 2056 | make test |
| 2057 | } |
| 2058 | |
| 2059 | # This is the reference component of component_test_full_block_cipher_psa_dispatch |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2060 | component_test_full_block_cipher_legacy_dispatch () { |
| 2061 | msg "build: full + legacy dispatch in block_cipher" |
| 2062 | |
| 2063 | common_block_cipher_dispatch 0 |
| 2064 | |
| 2065 | make |
| 2066 | |
| 2067 | msg "test: full + legacy dispatch in block_cipher" |
| 2068 | make test |
| 2069 | } |
| 2070 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 2071 | component_test_aead_chachapoly_disabled () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2072 | msg "build: full minus CHACHAPOLY" |
| 2073 | scripts/config.py full |
| 2074 | scripts/config.py unset MBEDTLS_CHACHAPOLY_C |
| 2075 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305 |
| 2076 | make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" |
| 2077 | |
| 2078 | msg "test: full minus CHACHAPOLY" |
| 2079 | make test |
| 2080 | } |
| 2081 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 2082 | component_test_aead_only_ccm () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2083 | msg "build: full minus CHACHAPOLY and GCM" |
| 2084 | scripts/config.py full |
| 2085 | scripts/config.py unset MBEDTLS_CHACHAPOLY_C |
| 2086 | scripts/config.py unset MBEDTLS_GCM_C |
| 2087 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305 |
| 2088 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM |
| 2089 | make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" |
| 2090 | |
| 2091 | msg "test: full minus CHACHAPOLY and GCM" |
| 2092 | make test |
| 2093 | } |
| 2094 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 2095 | component_test_ccm_aes_sha256 () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2096 | msg "build: CCM + AES + SHA256 configuration" |
| 2097 | |
Minos Galanakis | a17ffc7 | 2024-12-02 23:57:30 +0000 | [diff] [blame] | 2098 | # Setting a blank config disables everyhing in the library side. |
| 2099 | echo '#define MBEDTLS_CONFIG_H ' >"$CONFIG_H" |
Harry Ramsey | 94c386a | 2025-01-16 16:08:34 +0000 | [diff] [blame^] | 2100 | cp tf-psa-crypto/configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H" |
Ronald Cron | 9d262d7 | 2024-12-06 17:41:26 +0100 | [diff] [blame] | 2101 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2102 | make |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2103 | msg "test: CCM + AES + SHA256 configuration" |
| 2104 | make test |
| 2105 | } |
| 2106 | |
| 2107 | # Test that the given .o file builds with all (valid) combinations of the given options. |
| 2108 | # |
| 2109 | # Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ... |
| 2110 | # |
| 2111 | # The validator function is the name of a function to validate the combination of options. |
| 2112 | # It may be "" if all combinations are valid. |
| 2113 | # It receives a string containing a combination of options, as passed to the compiler, |
| 2114 | # e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid. |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 2115 | build_test_config_combos () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2116 | file=$1 |
| 2117 | shift |
| 2118 | validate_options=$1 |
| 2119 | shift |
| 2120 | options=("$@") |
| 2121 | |
| 2122 | # clear all of the options so that they can be overridden on the clang commandline |
| 2123 | for opt in "${options[@]}"; do |
| 2124 | ./scripts/config.py unset ${opt} |
| 2125 | done |
| 2126 | |
| 2127 | # enter the library directory |
| 2128 | cd library |
| 2129 | |
| 2130 | # The most common issue is unused variables/functions, so ensure -Wunused is set. |
| 2131 | warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused" |
| 2132 | |
| 2133 | # Extract the command generated by the Makefile to build the target file. |
| 2134 | # This ensures that we have any include paths, macro definitions, etc |
| 2135 | # that may be applied by make. |
| 2136 | # Add -fsyntax-only as we only want a syntax check and don't need to generate a file. |
| 2137 | compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c" |
| 2138 | |
| 2139 | makefile=$(TMPDIR=. mktemp) |
| 2140 | deps="" |
| 2141 | |
| 2142 | len=${#options[@]} |
| 2143 | source_file=../${file%.o}.c |
| 2144 | |
| 2145 | targets=0 |
| 2146 | echo 'include Makefile' >${makefile} |
| 2147 | |
| 2148 | for ((i = 0; i < $((2**${len})); i++)); do |
| 2149 | # generate each of 2^n combinations of options |
| 2150 | # each bit of $i is used to determine if options[i] will be set or not |
| 2151 | target="t" |
| 2152 | clang_args="" |
| 2153 | for ((j = 0; j < ${len}; j++)); do |
| 2154 | if (((i >> j) & 1)); then |
| 2155 | opt=-D${options[$j]} |
| 2156 | clang_args="${clang_args} ${opt}" |
| 2157 | target="${target}${opt}" |
| 2158 | fi |
| 2159 | done |
| 2160 | |
| 2161 | # if combination is not known to be invalid, add it to the makefile |
| 2162 | if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then |
| 2163 | cmd="${compile_cmd} ${clang_args}" |
| 2164 | echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile} |
| 2165 | |
| 2166 | deps="${deps} ${target}" |
| 2167 | ((++targets)) |
| 2168 | fi |
| 2169 | done |
| 2170 | |
| 2171 | echo "build_test_config_combos: ${deps}" >> ${makefile} |
| 2172 | |
| 2173 | # execute all of the commands via Make (probably in parallel) |
| 2174 | make -s -f ${makefile} build_test_config_combos |
| 2175 | echo "$targets targets checked" |
| 2176 | |
| 2177 | # clean up the temporary makefile |
| 2178 | rm ${makefile} |
| 2179 | } |
| 2180 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 2181 | validate_aes_config_variations () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2182 | if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then |
| 2183 | if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \ |
| 2184 | ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then |
| 2185 | return 1 |
| 2186 | fi |
| 2187 | fi |
| 2188 | return 0 |
| 2189 | } |
| 2190 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 2191 | component_build_aes_variations () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2192 | # 18s - around 90ms per clang invocation on M1 Pro |
| 2193 | # |
| 2194 | # aes.o has many #if defined(...) guards that intersect in complex ways. |
| 2195 | # Test that all the combinations build cleanly. |
| 2196 | |
| 2197 | MBEDTLS_ROOT_DIR="$PWD" |
| 2198 | msg "build: aes.o for all combinations of relevant config options" |
| 2199 | |
| 2200 | build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \ |
Thomas Daubney | 6cf05f9 | 2024-07-18 11:30:22 +0100 | [diff] [blame] | 2201 | "MBEDTLS_AES_ROM_TABLES" \ |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2202 | "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \ |
| 2203 | "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH" |
| 2204 | |
| 2205 | cd "$MBEDTLS_ROOT_DIR" |
| 2206 | msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT" |
| 2207 | |
| 2208 | # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES, |
| 2209 | # manually set or unset those configurations to check |
| 2210 | # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o. |
| 2211 | scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2212 | scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2213 | scripts/config.py unset MBEDTLS_NIST_KW_C |
Ronald Cron | 54d1eec | 2024-09-06 09:55:38 +0200 | [diff] [blame] | 2214 | |
Minos Galanakis | 00b641c | 2024-11-28 23:05:10 +0000 | [diff] [blame] | 2215 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING |
| 2216 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7 |
| 2217 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING |
| 2218 | scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES |
Ronald Cron | 4153ebb | 2024-09-11 15:32:48 +0200 | [diff] [blame] | 2219 | # Note: The two unsets below are to be removed for Mbed TLS 4.0 |
Ronald Cron | 54d1eec | 2024-09-06 09:55:38 +0200 | [diff] [blame] | 2220 | scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC |
| 2221 | scripts/config.py unset MBEDTLS_DES_C |
| 2222 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2223 | build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \ |
Thomas Daubney | 6cf05f9 | 2024-07-18 11:30:22 +0100 | [diff] [blame] | 2224 | "MBEDTLS_AES_ROM_TABLES" \ |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2225 | "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \ |
| 2226 | "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH" |
| 2227 | } |
| 2228 | |
Minos Galanakis | f78447f | 2024-07-26 20:49:51 +0100 | [diff] [blame] | 2229 | component_test_sha3_variations () { |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2230 | msg "sha3 loop unroll variations" |
| 2231 | |
| 2232 | # define minimal config sufficient to test SHA3 |
Ronald Cron | e7f289e | 2024-09-06 11:02:47 +0200 | [diff] [blame] | 2233 | cat > include/mbedtls/mbedtls_config.h << END |
Ronald Cron | e7f289e | 2024-09-06 11:02:47 +0200 | [diff] [blame] | 2234 | END |
| 2235 | |
| 2236 | cat > tf-psa-crypto/include/psa/crypto_config.h << END |
| 2237 | #define PSA_WANT_ALG_SHA_256 1 |
| 2238 | #define PSA_WANT_ALG_SHA3_224 1 |
| 2239 | #define PSA_WANT_ALG_SHA3_256 1 |
| 2240 | #define PSA_WANT_ALG_SHA3_384 1 |
| 2241 | #define PSA_WANT_ALG_SHA3_512 1 |
Ronald Cron | 3dd1d3d | 2024-12-05 15:12:06 +0100 | [diff] [blame] | 2242 | #define MBEDTLS_AES_C |
| 2243 | #define MBEDTLS_CTR_DRBG_C |
| 2244 | #define MBEDTLS_ENTROPY_C |
| 2245 | #define MBEDTLS_PSA_CRYPTO_C |
| 2246 | #define MBEDTLS_SELF_TEST |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2247 | END |
| 2248 | |
| 2249 | msg "all loops unrolled" |
| 2250 | make clean |
| 2251 | make -C tests ../tf-psa-crypto/tests/test_suite_shax CFLAGS="-DMBEDTLS_SHA3_THETA_UNROLL=1 -DMBEDTLS_SHA3_PI_UNROLL=1 -DMBEDTLS_SHA3_CHI_UNROLL=1 -DMBEDTLS_SHA3_RHO_UNROLL=1" |
| 2252 | ./tf-psa-crypto/tests/test_suite_shax |
| 2253 | |
| 2254 | msg "all loops rolled up" |
| 2255 | make clean |
| 2256 | make -C tests ../tf-psa-crypto/tests/test_suite_shax CFLAGS="-DMBEDTLS_SHA3_THETA_UNROLL=0 -DMBEDTLS_SHA3_PI_UNROLL=0 -DMBEDTLS_SHA3_CHI_UNROLL=0 -DMBEDTLS_SHA3_RHO_UNROLL=0" |
| 2257 | ./tf-psa-crypto/tests/test_suite_shax |
| 2258 | } |
| 2259 | |
Minos Galanakis | f699d51 | 2024-08-01 11:32:30 +0100 | [diff] [blame] | 2260 | support_build_aes_aesce_armcc () { |
| 2261 | support_build_armcc |
| 2262 | } |
| 2263 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2264 | # For timebeing, no aarch64 gcc available in CI and no arm64 CI node. |
| 2265 | component_build_aes_aesce_armcc () { |
| 2266 | msg "Build: AESCE test on arm64 platform without plain C." |
| 2267 | scripts/config.py baremetal |
| 2268 | |
| 2269 | # armc[56] don't support SHA-512 intrinsics |
| 2270 | scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT |
| 2271 | |
| 2272 | # Stop armclang warning about feature detection for A64_CRYPTO. |
| 2273 | # With this enabled, the library does build correctly under armclang, |
| 2274 | # but in baremetal builds (as tested here), feature detection is |
| 2275 | # unavailable, and the user is notified via a #warning. So enabling |
| 2276 | # this feature would prevent us from building with -Werror on |
| 2277 | # armclang. Tracked in #7198. |
| 2278 | scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT |
| 2279 | scripts/config.py set MBEDTLS_HAVE_ASM |
| 2280 | |
| 2281 | msg "AESCE, build with default configuration." |
| 2282 | scripts/config.py set MBEDTLS_AESCE_C |
| 2283 | scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY |
Manuel Pégourié-Gonnard | 8f08bcd | 2024-10-01 13:01:54 +0200 | [diff] [blame] | 2284 | helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2285 | |
| 2286 | msg "AESCE, build AESCE only" |
| 2287 | scripts/config.py set MBEDTLS_AESCE_C |
| 2288 | scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY |
Manuel Pégourié-Gonnard | 8f08bcd | 2024-10-01 13:01:54 +0200 | [diff] [blame] | 2289 | helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2290 | } |
| 2291 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2292 | component_test_aes_only_128_bit_keys () { |
| 2293 | msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH" |
| 2294 | scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH |
| 2295 | |
| 2296 | make CFLAGS='-O2 -Werror -Wall -Wextra' |
| 2297 | |
| 2298 | msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH" |
| 2299 | make test |
| 2300 | } |
| 2301 | |
| 2302 | component_test_no_ctr_drbg_aes_only_128_bit_keys () { |
| 2303 | msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C" |
| 2304 | scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH |
| 2305 | scripts/config.py unset MBEDTLS_CTR_DRBG_C |
| 2306 | |
| 2307 | make CC=clang CFLAGS='-Werror -Wall -Wextra' |
| 2308 | |
| 2309 | msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C" |
| 2310 | make test |
| 2311 | } |
| 2312 | |
| 2313 | component_test_aes_only_128_bit_keys_have_builtins () { |
| 2314 | msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C" |
| 2315 | scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH |
| 2316 | scripts/config.py unset MBEDTLS_AESNI_C |
| 2317 | scripts/config.py unset MBEDTLS_AESCE_C |
| 2318 | |
| 2319 | make CFLAGS='-O2 -Werror -Wall -Wextra' |
| 2320 | |
| 2321 | msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C" |
| 2322 | make test |
| 2323 | |
| 2324 | msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C" |
| 2325 | programs/test/selftest |
| 2326 | } |
| 2327 | |
| 2328 | component_test_gcm_largetable () { |
| 2329 | msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C" |
| 2330 | scripts/config.py set MBEDTLS_GCM_LARGE_TABLE |
| 2331 | scripts/config.py unset MBEDTLS_AESNI_C |
| 2332 | scripts/config.py unset MBEDTLS_AESCE_C |
| 2333 | |
| 2334 | make CFLAGS='-O2 -Werror -Wall -Wextra' |
| 2335 | |
| 2336 | msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C" |
| 2337 | make test |
| 2338 | } |
| 2339 | |
| 2340 | component_test_aes_fewer_tables () { |
| 2341 | msg "build: default config with AES_FEWER_TABLES enabled" |
| 2342 | scripts/config.py set MBEDTLS_AES_FEWER_TABLES |
| 2343 | make CFLAGS='-O2 -Werror -Wall -Wextra' |
| 2344 | |
| 2345 | msg "test: AES_FEWER_TABLES" |
| 2346 | make test |
| 2347 | } |
| 2348 | |
| 2349 | component_test_aes_rom_tables () { |
| 2350 | msg "build: default config with AES_ROM_TABLES enabled" |
| 2351 | scripts/config.py set MBEDTLS_AES_ROM_TABLES |
| 2352 | make CFLAGS='-O2 -Werror -Wall -Wextra' |
| 2353 | |
| 2354 | msg "test: AES_ROM_TABLES" |
| 2355 | make test |
| 2356 | } |
| 2357 | |
| 2358 | component_test_aes_fewer_tables_and_rom_tables () { |
| 2359 | msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled" |
| 2360 | scripts/config.py set MBEDTLS_AES_FEWER_TABLES |
| 2361 | scripts/config.py set MBEDTLS_AES_ROM_TABLES |
| 2362 | make CFLAGS='-O2 -Werror -Wall -Wextra' |
| 2363 | |
| 2364 | msg "test: AES_FEWER_TABLES + AES_ROM_TABLES" |
| 2365 | make test |
| 2366 | } |
| 2367 | |
Ronald Cron | 6604047 | 2024-09-06 10:14:38 +0200 | [diff] [blame] | 2368 | # helper for component_test_block_cipher_no_decrypt_aesni() which: |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2369 | # - enable/disable the list of config options passed from -s/-u respectively. |
| 2370 | # - build |
| 2371 | # - test for tests_suite_xxx |
| 2372 | # - selftest |
| 2373 | # |
| 2374 | # Usage: helper_block_cipher_no_decrypt_build_test |
| 2375 | # [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]] |
| 2376 | # Options: -s set_opts the list of config options to enable |
| 2377 | # -u unset_opts the list of config options to disable |
| 2378 | # -c cflags the list of options passed to CFLAGS |
| 2379 | # -l ldflags the list of options passed to LDFLAGS |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2380 | helper_block_cipher_no_decrypt_build_test () { |
| 2381 | while [ $# -gt 0 ]; do |
| 2382 | case "$1" in |
| 2383 | -s) |
| 2384 | shift; local set_opts="$1";; |
| 2385 | -u) |
| 2386 | shift; local unset_opts="$1";; |
| 2387 | -c) |
| 2388 | shift; local cflags="-Werror -Wall -Wextra $1";; |
| 2389 | -l) |
| 2390 | shift; local ldflags="$1";; |
| 2391 | esac |
| 2392 | shift |
| 2393 | done |
| 2394 | set_opts="${set_opts:-}" |
| 2395 | unset_opts="${unset_opts:-}" |
| 2396 | cflags="${cflags:-}" |
| 2397 | ldflags="${ldflags:-}" |
| 2398 | |
| 2399 | [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts |
| 2400 | [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts |
| 2401 | |
| 2402 | msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}" |
| 2403 | make clean |
| 2404 | make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags" |
| 2405 | |
| 2406 | # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA |
| 2407 | not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o |
| 2408 | not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o |
| 2409 | not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o |
| 2410 | # Make sure we don't have mbedtls_internal_aes_decrypt in AES |
| 2411 | not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o |
| 2412 | # Make sure we don't have mbedtls_aesni_inverse_key in AESNI |
| 2413 | not grep mbedtls_aesni_inverse_key ${BUILTIN_SRC_PATH}/aesni.o |
| 2414 | |
| 2415 | msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}" |
| 2416 | make test |
| 2417 | |
| 2418 | msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}" |
| 2419 | programs/test/selftest |
| 2420 | } |
| 2421 | |
Ronald Cron | 6604047 | 2024-09-06 10:14:38 +0200 | [diff] [blame] | 2422 | # This is a configuration function used in component_test_block_cipher_no_decrypt_xxx: |
| 2423 | config_block_cipher_no_decrypt () { |
| 2424 | scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT |
| 2425 | scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS |
| 2426 | scripts/config.py unset MBEDTLS_NIST_KW_C |
| 2427 | |
| 2428 | # Enable support for cryptographic mechanisms through the PSA API. |
| 2429 | # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS. |
Ronald Cron | 6604047 | 2024-09-06 10:14:38 +0200 | [diff] [blame] | 2430 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING |
| 2431 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7 |
| 2432 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING |
| 2433 | scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES |
Ronald Cron | 4153ebb | 2024-09-11 15:32:48 +0200 | [diff] [blame] | 2434 | # Note: The two unsets below are to be removed for Mbed TLS 4.0 |
Ronald Cron | 6604047 | 2024-09-06 10:14:38 +0200 | [diff] [blame] | 2435 | scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC |
| 2436 | scripts/config.py unset MBEDTLS_DES_C |
| 2437 | } |
| 2438 | |
| 2439 | component_test_block_cipher_no_decrypt_aesni () { |
| 2440 | # Test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics, AESNI assembly and |
| 2441 | # AES C implementation on x86_64 and with AESNI intrinsics on x86. |
| 2442 | |
| 2443 | # This consistently causes an llvm crash on clang 3.8, so use gcc |
| 2444 | export CC=gcc |
| 2445 | config_block_cipher_no_decrypt |
| 2446 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2447 | # test AESNI intrinsics |
| 2448 | helper_block_cipher_no_decrypt_build_test \ |
| 2449 | -s "MBEDTLS_AESNI_C" \ |
| 2450 | -c "-mpclmul -msse2 -maes" |
| 2451 | |
| 2452 | # test AESNI assembly |
| 2453 | helper_block_cipher_no_decrypt_build_test \ |
| 2454 | -s "MBEDTLS_AESNI_C" \ |
| 2455 | -c "-mno-pclmul -mno-sse2 -mno-aes" |
| 2456 | |
| 2457 | # test AES C implementation |
| 2458 | helper_block_cipher_no_decrypt_build_test \ |
| 2459 | -u "MBEDTLS_AESNI_C" |
| 2460 | |
| 2461 | # test AESNI intrinsics for i386 target |
| 2462 | helper_block_cipher_no_decrypt_build_test \ |
| 2463 | -s "MBEDTLS_AESNI_C" \ |
| 2464 | -c "-m32 -mpclmul -msse2 -maes" \ |
| 2465 | -l "-m32" |
| 2466 | } |
| 2467 | |
Minos Galanakis | f699d51 | 2024-08-01 11:32:30 +0100 | [diff] [blame] | 2468 | support_test_block_cipher_no_decrypt_aesce_armcc () { |
| 2469 | support_build_armcc |
| 2470 | } |
| 2471 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2472 | component_test_block_cipher_no_decrypt_aesce_armcc () { |
| 2473 | scripts/config.py baremetal |
| 2474 | |
| 2475 | # armc[56] don't support SHA-512 intrinsics |
| 2476 | scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT |
| 2477 | |
| 2478 | # Stop armclang warning about feature detection for A64_CRYPTO. |
| 2479 | # With this enabled, the library does build correctly under armclang, |
| 2480 | # but in baremetal builds (as tested here), feature detection is |
| 2481 | # unavailable, and the user is notified via a #warning. So enabling |
| 2482 | # this feature would prevent us from building with -Werror on |
| 2483 | # armclang. Tracked in #7198. |
| 2484 | scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT |
| 2485 | scripts/config.py set MBEDTLS_HAVE_ASM |
| 2486 | |
Ronald Cron | 6604047 | 2024-09-06 10:14:38 +0200 | [diff] [blame] | 2487 | config_block_cipher_no_decrypt |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2488 | |
| 2489 | # test AESCE baremetal build |
| 2490 | scripts/config.py set MBEDTLS_AESCE_C |
| 2491 | msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE" |
Manuel Pégourié-Gonnard | 8f08bcd | 2024-10-01 13:01:54 +0200 | [diff] [blame] | 2492 | helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2493 | |
| 2494 | # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA |
| 2495 | not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o |
| 2496 | not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o |
| 2497 | not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o |
| 2498 | # Make sure we don't have mbedtls_internal_aes_decrypt in AES |
| 2499 | not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o |
| 2500 | # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE |
| 2501 | not grep mbedtls_aesce_inverse_key ${BUILTIN_SRC_PATH}/aesce.o |
| 2502 | not grep aesce_decrypt_block ${BUILTIN_SRC_PATH}/aesce.o |
| 2503 | } |
| 2504 | |
| 2505 | component_test_ctr_drbg_aes_256_sha_256 () { |
| 2506 | msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)" |
| 2507 | scripts/config.py full |
| 2508 | scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C |
| 2509 | scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256 |
| 2510 | CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan . |
| 2511 | make |
| 2512 | |
| 2513 | msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)" |
| 2514 | make test |
| 2515 | } |
| 2516 | |
| 2517 | component_test_ctr_drbg_aes_128_sha_512 () { |
| 2518 | msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)" |
| 2519 | scripts/config.py full |
| 2520 | scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C |
| 2521 | scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY |
| 2522 | CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan . |
| 2523 | make |
| 2524 | |
| 2525 | msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)" |
| 2526 | make test |
| 2527 | } |
| 2528 | |
| 2529 | component_test_ctr_drbg_aes_128_sha_256 () { |
| 2530 | msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)" |
| 2531 | scripts/config.py full |
| 2532 | scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C |
| 2533 | scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY |
| 2534 | scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256 |
| 2535 | CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan . |
| 2536 | make |
| 2537 | |
| 2538 | msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)" |
| 2539 | make test |
| 2540 | } |
| 2541 | |
Gilles Peskine | a9dda7e | 2024-06-21 11:25:01 +0200 | [diff] [blame] | 2542 | component_test_full_static_keystore () { |
| 2543 | msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC" |
| 2544 | scripts/config.py full |
| 2545 | scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC |
| 2546 | make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS" |
| 2547 | |
| 2548 | msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC" |
| 2549 | make test |
| 2550 | } |
| 2551 | |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2552 | component_test_psa_crypto_drivers () { |
Ronald Cron | a0afbfb | 2024-10-15 13:20:31 +0200 | [diff] [blame] | 2553 | # Test dispatch to drivers and fallbacks with |
| 2554 | # test_suite_psa_crypto_driver_wrappers test suite. The test drivers that |
| 2555 | # are wrappers around the builtin drivers are activated by |
| 2556 | # PSA_CRYPTO_DRIVER_TEST. |
| 2557 | # |
| 2558 | # For the time being, some test cases in test_suite_block_cipher and |
| 2559 | # test_suite_md.psa rely on this component to be run at least once by the |
| 2560 | # CI. This should disappear as we progress the 4.x work. See |
| 2561 | # config_adjust_test_accelerators.h for more information. |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2562 | msg "build: full + test drivers dispatching to builtins" |
| 2563 | scripts/config.py full |
Ronald Cron | 67cc6a7 | 2024-10-14 10:55:24 +0200 | [diff] [blame] | 2564 | loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_CONFIG_ADJUST_TEST_ACCELERATORS" |
David Horstmann | 5b93d97 | 2024-10-31 15:36:05 +0000 | [diff] [blame] | 2565 | loc_cflags="${loc_cflags} -I../framework/tests/include" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2566 | |
| 2567 | make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS" |
| 2568 | |
| 2569 | msg "test: full + test drivers dispatching to builtins" |
| 2570 | make test |
| 2571 | } |
| 2572 | |
| 2573 | component_build_psa_config_file () { |
Minos Galanakis | 4f619e1 | 2024-11-14 14:56:47 +0000 | [diff] [blame] | 2574 | msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE" # ~40s |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2575 | cp "$CRYPTO_CONFIG_H" psa_test_config.h |
Minos Galanakis | 4f619e1 | 2024-11-14 14:56:47 +0000 | [diff] [blame] | 2576 | echo '#error "TF_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H" |
| 2577 | make CFLAGS="-I '$PWD' -DTF_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2578 | # Make sure this feature is enabled. We'll disable it in the next phase. |
| 2579 | programs/test/query_compile_time_config MBEDTLS_CMAC_C |
| 2580 | make clean |
| 2581 | |
Minos Galanakis | 4f619e1 | 2024-11-14 14:56:47 +0000 | [diff] [blame] | 2582 | msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE + TF_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2583 | # In the user config, disable one feature and its dependencies, which will |
| 2584 | # reflect on the mbedtls configuration so we can query it with |
| 2585 | # query_compile_time_config. |
| 2586 | echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h |
| 2587 | echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h |
Minos Galanakis | aa2f12c | 2024-10-22 15:31:07 +0100 | [diff] [blame] | 2588 | echo '#undef MBEDTLS_CMAC_C' >> psa_user_config.h |
Minos Galanakis | 4f619e1 | 2024-11-14 14:56:47 +0000 | [diff] [blame] | 2589 | make CFLAGS="-I '$PWD' -DTF_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DTF_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2590 | not programs/test/query_compile_time_config MBEDTLS_CMAC_C |
| 2591 | |
| 2592 | rm -f psa_test_config.h psa_user_config.h |
| 2593 | } |
| 2594 | |
| 2595 | component_build_psa_alt_headers () { |
| 2596 | msg "build: make with PSA alt headers" # ~20s |
| 2597 | |
| 2598 | # Generate alternative versions of the substitutable headers with the |
| 2599 | # same content except different include guards. |
David Horstmann | dc45951 | 2024-11-07 17:08:11 +0000 | [diff] [blame] | 2600 | make -C tests ../framework/tests/include/alt-extra/psa/crypto_platform_alt.h ../framework/tests/include/alt-extra/psa/crypto_struct_alt.h |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2601 | |
| 2602 | # Build the library and some programs. |
| 2603 | # Don't build the fuzzers to avoid having to go through hoops to set |
| 2604 | # a correct include path for programs/fuzz/Makefile. |
David Horstmann | 5b93d97 | 2024-10-31 15:36:05 +0000 | [diff] [blame] | 2605 | make CFLAGS="-I ../framework/tests/include/alt-extra -DMBEDTLS_PSA_CRYPTO_PLATFORM_FILE='\"psa/crypto_platform_alt.h\"' -DMBEDTLS_PSA_CRYPTO_STRUCT_FILE='\"psa/crypto_struct_alt.h\"'" lib |
| 2606 | make -C programs -o fuzz CFLAGS="-I ../framework/tests/include/alt-extra -DMBEDTLS_PSA_CRYPTO_PLATFORM_FILE='\"psa/crypto_platform_alt.h\"' -DMBEDTLS_PSA_CRYPTO_STRUCT_FILE='\"psa/crypto_struct_alt.h\"'" |
Minos Galanakis | 471b34c | 2024-07-26 15:39:24 +0100 | [diff] [blame] | 2607 | |
| 2608 | # Check that we're getting the alternative include guards and not the |
| 2609 | # original include guards. |
| 2610 | programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H |
| 2611 | programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H |
| 2612 | programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H |
| 2613 | programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H |
| 2614 | } |
| 2615 | |
| 2616 | component_test_min_mpi_window_size () { |
| 2617 | msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s |
| 2618 | scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1 |
| 2619 | CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan . |
| 2620 | make |
| 2621 | |
| 2622 | msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s |
| 2623 | make test |
| 2624 | } |