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