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