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