blob: fcca5ffa0a45539b17aaab0c3f8cc3c9baddf308 [file] [log] [blame]
Minos Galanakis6aab5b72024-07-25 14:24:37 +01001# 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 Galanakis609f7492024-07-31 16:39:28 +01006# This file contains test components that are executed by all.sh
Minos Galanakis6aab5b72024-07-25 14:24:37 +01007
8################################################################
9#### Configuration Testing - Crypto
10################################################################
11
Minos Galanakis471b34c2024-07-26 15:39:24 +010012component_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
23component_test_psa_assume_exclusive_buffers () {
24 msg "build: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
25 scripts/config.py full
26 scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
27 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
28 make
29
30 msg "test: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
31 make test
32}
33
Valerio Settidbb646b2024-06-20 14:40:54 +020034component_test_crypto_with_static_key_slots() {
35 msg "build: crypto full + MBEDTLS_PSA_STATIC_KEY_SLOTS"
36 scripts/config.py crypto_full
37 scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOTS
Valerio Setti4d9a8212024-08-16 12:35:24 +020038 # Intentionally set MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE to a value that
39 # is enough to contain:
40 # - all RSA public keys up to 4096 bits (max of PSA_VENDOR_RSA_MAX_KEY_BITS).
41 # - RSA key pairs up to 1024 bits, but not 2048 or larger.
42 # - all FFDH key pairs and public keys up to 8192 bits (max of PSA_VENDOR_FFDH_MAX_KEY_BITS).
43 # - all EC key pairs and public keys up to 521 bits (max of PSA_VENDOR_ECC_MAX_CURVE_BITS).
44 scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE 1212
Valerio Setti8bc81722024-08-28 05:50:45 +020045 # Disable the fully dynamic key store (default on) since it conflicts
46 # with the static behavior that we're testing here.
47 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
Valerio Settidbb646b2024-06-20 14:40:54 +020048
Valerio Setti13aadd72024-08-13 13:13:23 +020049 msg "test: crypto full + MBEDTLS_PSA_STATIC_KEY_SLOTS"
Valerio Setti2a3c9b32024-08-14 06:37:02 +020050 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" test
Valerio Settidbb646b2024-06-20 14:40:54 +020051}
52
Minos Galanakis471b34c2024-07-26 15:39:24 +010053# check_renamed_symbols HEADER LIB
54# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
Minos Galanakis609f7492024-07-31 16:39:28 +010055# name in LIB.
Minos Galanakis471b34c2024-07-26 15:39:24 +010056check_renamed_symbols () {
57 ! nm "$2" | sed 's/.* //' |
58 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
59}
60
61component_build_psa_crypto_spm () {
62 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
63 scripts/config.py full
64 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
65 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
66 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
67 # We can only compile, not link, since our test and sample programs
68 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
69 # is active.
David Horstmann5b93d972024-10-31 15:36:05 +000070 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' lib
Minos Galanakis471b34c2024-07-26 15:39:24 +010071
72 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
73 # version is not present.
74 echo "Checking for renamed symbols in the library"
David Horstmann5b93d972024-10-31 15:36:05 +000075 check_renamed_symbols framework/tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Minos Galanakis471b34c2024-07-26 15:39:24 +010076}
77
Valerio Settia47b0452024-06-25 18:31:36 +020078# The goal of this component is to build a configuration where:
79# - test code and libtestdriver1 can make use of calloc/free and
80# - core library (including PSA core) cannot use calloc/free.
81component_test_psa_crypto_without_heap() {
Valerio Setti13aadd72024-08-13 13:13:23 +020082 msg "crypto without heap: build libtestdriver1"
Valerio Settia47b0452024-06-25 18:31:36 +020083 # Disable PSA features that cannot be accelerated and whose builtin support
84 # requires calloc/free.
David Horstmann7cbeedc2025-08-26 17:26:45 +010085 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
86 scripts/config.py unset-all "^PSA_WANT_ALG_HKDF"
87 scripts/config.py unset-all "^PSA_WANT_ALG_PBKDF2_"
88 scripts/config.py unset-all "^PSA_WANT_ALG_TLS12_"
Valerio Settia47b0452024-06-25 18:31:36 +020089 # RSA key support requires ASN1 parse/write support for testing, but ASN1
90 # is disabled below.
David Horstmann7cbeedc2025-08-26 17:26:45 +010091 scripts/config.py unset-all "^PSA_WANT_KEY_TYPE_RSA_"
92 scripts/config.py unset-all "^PSA_WANT_ALG_RSA_"
Valerio Settia47b0452024-06-25 18:31:36 +020093 # DES requires built-in support for key generation (parity check) so it
94 # cannot be accelerated
David Horstmann7cbeedc2025-08-26 17:26:45 +010095 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
Valerio Settia47b0452024-06-25 18:31:36 +020096 # EC-JPAKE use calloc/free in PSA core
David Horstmann7cbeedc2025-08-26 17:26:45 +010097 scripts/config.py unset PSA_WANT_ALG_JPAKE
Valerio Settia785eea2025-08-13 10:57:46 +020098 # Enable p192[k|r]1 curves which are disabled by default in tf-psa-crypto.
99 # This is required to get the proper test coverage otherwise there are
100 # tests in 'test_suite_psa_crypto_op_fail' that would never be executed.
101 scripts/config.py set PSA_WANT_ECC_SECP_K1_192
102 scripts/config.py set PSA_WANT_ECC_SECP_R1_192
Valerio Settia47b0452024-06-25 18:31:36 +0200103
104 # Accelerate all PSA features (which are still enabled in CRYPTO_CONFIG_H).
David Horstmann7cbeedc2025-08-26 17:26:45 +0100105 PSA_SYM_LIST=$(./scripts/config.py get-all-enabled PSA_WANT)
Valerio Settia47b0452024-06-25 18:31:36 +0200106 loc_accel_list=$(echo $PSA_SYM_LIST | sed 's/PSA_WANT_//g')
107
Valerio Settia47b0452024-06-25 18:31:36 +0200108 helper_libtestdriver1_adjust_config crypto
109 helper_libtestdriver1_make_drivers "$loc_accel_list"
110
Valerio Setti13aadd72024-08-13 13:13:23 +0200111 msg "crypto without heap: build main library"
Valerio Setti35b0b022024-08-13 13:36:50 +0200112 # Disable all legacy MBEDTLS_xxx symbols.
113 scripts/config.py unset-all "^MBEDTLS_"
114 # Build the PSA core using the proper config file.
115 scripts/config.py set MBEDTLS_PSA_CRYPTO_C
Valerio Settia47b0452024-06-25 18:31:36 +0200116 # Enable fully-static key slots in PSA core.
117 scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOTS
Valerio Setti35b0b022024-08-13 13:36:50 +0200118 # Prevent PSA core from creating a copy of input/output buffers.
Valerio Settia47b0452024-06-25 18:31:36 +0200119 scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
120 # Prevent PSA core from using CTR-DRBG or HMAC-DRBG for random generation.
121 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Valerio Setti13aadd72024-08-13 13:13:23 +0200122 # Set calloc/free as null pointer functions. Calling them would crash
Valerio Settia47b0452024-06-25 18:31:36 +0200123 # the program so we can use this as a "sentinel" for being sure no module
124 # is making use of these functions in the library.
Valerio Setti35b0b022024-08-13 13:36:50 +0200125 scripts/config.py set MBEDTLS_PLATFORM_C
Valerio Settia47b0452024-06-25 18:31:36 +0200126 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
127 scripts/config.py set MBEDTLS_PLATFORM_STD_CALLOC NULL
128 scripts/config.py set MBEDTLS_PLATFORM_STD_FREE NULL
129
Valerio Settia47b0452024-06-25 18:31:36 +0200130 helper_libtestdriver1_make_main "$loc_accel_list" lib
131
Valerio Setti13aadd72024-08-13 13:13:23 +0200132 msg "crypto without heap: build test suites and helpers"
133 # Reset calloc/free functions to normal operations so that test code can
Valerio Settia47b0452024-06-25 18:31:36 +0200134 # freely use them.
135 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
136 scripts/config.py unset MBEDTLS_PLATFORM_STD_CALLOC
137 scripts/config.py unset MBEDTLS_PLATFORM_STD_FREE
138 helper_libtestdriver1_make_main "$loc_accel_list" tests
139
Valerio Setti13aadd72024-08-13 13:13:23 +0200140 msg "crypto without heap: test"
Valerio Settia47b0452024-06-25 18:31:36 +0200141 make test
142}
143
Minos Galanakisf78447f2024-07-26 20:49:51 +0100144component_test_no_rsa_key_pair_generation () {
Minos Galanakisdc0f73a2024-07-26 20:41:42 +0100145 msg "build: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
David Horstmann7cbeedc2025-08-26 17:26:45 +0100146 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Minos Galanakisdc0f73a2024-07-26 20:41:42 +0100147 make
148
149 msg "test: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
150 make test
151}
152
Minos Galanakisc06fd302024-08-01 12:16:59 +0100153component_test_no_pem_no_fs () {
154 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
155 scripts/config.py unset MBEDTLS_PEM_PARSE_C
156 scripts/config.py unset MBEDTLS_FS_IO
157 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
158 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
159 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
160 make
161
162 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
163 make test
164
165 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
166 tests/ssl-opt.sh
167}
168
169component_test_rsa_no_crt () {
170 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
171 scripts/config.py set MBEDTLS_RSA_NO_CRT
172 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
173 make
174
175 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
176 make test
177
178 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
179 tests/ssl-opt.sh -f RSA
180
181 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
182 tests/compat.sh -t RSA
183
184 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
185 tests/context-info.sh
186}
187
Minos Galanakisc06fd302024-08-01 12:16:59 +0100188component_test_no_ctr_drbg_use_psa () {
189 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
190 scripts/config.py full
191 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Minos Galanakisc06fd302024-08-01 12:16:59 +0100192
193 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
194 make
195
196 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
197 make test
198
199 # In this configuration, the TLS test programs use HMAC_DRBG.
200 # The SSL tests are slow, so run a small subset, just enough to get
201 # confidence that the SSL code copes with HMAC_DRBG.
202 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
203 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
204
205 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
206 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
207}
208
Minos Galanakisc06fd302024-08-01 12:16:59 +0100209component_test_no_hmac_drbg_use_psa () {
210 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
211 scripts/config.py full
212 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
David Horstmann7cbeedc2025-08-26 17:26:45 +0100213 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA # requires HMAC_DRBG
Minos Galanakisc06fd302024-08-01 12:16:59 +0100214
215 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
216 make
217
218 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
219 make test
220
221 # Normally our ECDSA implementation uses deterministic ECDSA. But since
222 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
223 # instead.
224 # Test SSL with non-deterministic ECDSA. Only test features that
225 # might be affected by how ECDSA signature is performed.
226 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
227 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
228
229 # To save time, only test one protocol version, since this part of
230 # the protocol is identical in (D)TLS up to 1.2.
231 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
232 tests/compat.sh -m tls12 -t 'ECDSA'
233}
234
Minos Galanakisc06fd302024-08-01 12:16:59 +0100235component_test_psa_external_rng_no_drbg_use_psa () {
236 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
237 scripts/config.py full
238 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Minos Galanakisc06fd302024-08-01 12:16:59 +0100239 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
240 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
241 scripts/config.py unset MBEDTLS_CTR_DRBG_C
242 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
David Horstmann7cbeedc2025-08-26 17:26:45 +0100243 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA # Requires HMAC_DRBG
Minos Galanakisc06fd302024-08-01 12:16:59 +0100244 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
245
246 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
247 make test
248
249 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
250 tests/ssl-opt.sh -f 'Default\|opaque'
251}
252
Minos Galanakis471b34c2024-07-26 15:39:24 +0100253component_test_psa_external_rng_use_psa_crypto () {
Ronald Cron3b306432025-09-02 18:30:08 +0200254 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG/NV_SEED"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100255 scripts/config.py full
256 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Minos Galanakis471b34c2024-07-26 15:39:24 +0100257 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Ronald Cron3b306432025-09-02 18:30:08 +0200258 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
259 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Minos Galanakis471b34c2024-07-26 15:39:24 +0100260 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
261
Ronald Cron3b306432025-09-02 18:30:08 +0200262 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG/NV_SEED"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100263 make test
264
Ronald Cron3b306432025-09-02 18:30:08 +0200265 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG/NV_SEED"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100266 tests/ssl-opt.sh -f 'Default\|opaque'
267}
268
Minos Galanakisf78447f2024-07-26 20:49:51 +0100269component_full_no_pkparse_pkwrite () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100270 msg "build: full without pkparse and pkwrite"
271
272 scripts/config.py crypto_full
273 scripts/config.py unset MBEDTLS_PK_PARSE_C
274 scripts/config.py unset MBEDTLS_PK_WRITE_C
275
276 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
277
278 # Ensure that PK_[PARSE|WRITE]_C were not re-enabled accidentally (additive config).
279 not grep mbedtls_pk_parse_key ${BUILTIN_SRC_PATH}/pkparse.o
280 not grep mbedtls_pk_write_key_der ${BUILTIN_SRC_PATH}/pkwrite.o
281
282 msg "test: full without pkparse and pkwrite"
283 make test
284}
285
286component_test_crypto_full_md_light_only () {
287 msg "build: crypto_full with only the light subset of MD"
288 scripts/config.py crypto_full
289
290 # Disable MD
291 scripts/config.py unset MBEDTLS_MD_C
292 # Disable direct dependencies of MD_C
293 scripts/config.py unset MBEDTLS_HKDF_C
294 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
295 scripts/config.py unset MBEDTLS_PKCS7_C
296 # Disable indirect dependencies of MD_C
David Horstmann7cbeedc2025-08-26 17:26:45 +0100297 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
Minos Galanakis471b34c2024-07-26 15:39:24 +0100298 # Disable things that would auto-enable MD_C
299 scripts/config.py unset MBEDTLS_PKCS5_C
300
301 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
302 # which we haven't disabled, so no need to explicitly enable it.
303 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
304
305 # Make sure we don't have the HMAC functions, but the hashing functions
306 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
307 grep mbedtls_md ${BUILTIN_SRC_PATH}/md.o
308
309 msg "test: crypto_full with only the light subset of MD"
310 make test
311}
312
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100313component_test_full_no_cipher () {
314 msg "build: full no CIPHER"
315
316 scripts/config.py full
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100317
318 # The built-in implementation of the following algs/key-types depends
319 # on CIPHER_C so we disable them.
320 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
321 # so we keep them enabled.
David Horstmann7cbeedc2025-08-26 17:26:45 +0100322 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
323 scripts/config.py unset PSA_WANT_ALG_CMAC
324 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
325 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
326 scripts/config.py unset PSA_WANT_ALG_CFB
327 scripts/config.py unset PSA_WANT_ALG_CTR
328 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
329 scripts/config.py unset PSA_WANT_ALG_OFB
330 scripts/config.py unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
331 scripts/config.py unset PSA_WANT_ALG_STREAM_CIPHER
332 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100333
334 # The following modules directly depends on CIPHER_C
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100335 scripts/config.py unset MBEDTLS_NIST_KW_C
336
337 make
338
339 # Ensure that CIPHER_C was not re-enabled
340 not grep mbedtls_cipher_init ${BUILTIN_SRC_PATH}/cipher.o
341
342 msg "test: full no CIPHER"
343 make test
344}
345
Minos Galanakisf78447f2024-07-26 20:49:51 +0100346component_test_full_no_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100347 msg "build: full no PSA_WANT_ALG_CCM"
348
349 # Full config enables:
350 # - USE_PSA_CRYPTO so that TLS code dispatches cipher/AEAD to PSA
351 # - CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
352 scripts/config.py full
353
354 # Disable PSA_WANT_ALG_CCM so that CCM is not supported in PSA. CCM_C is still
355 # enabled, but not used from TLS since USE_PSA is set.
356 # This is helpful to ensure that TLS tests below have proper dependencies.
357 #
358 # Note: also PSA_WANT_ALG_CCM_STAR_NO_TAG is enabled, but it does not cause
359 # PSA_WANT_ALG_CCM to be re-enabled.
David Horstmannb907dbc2025-08-27 15:19:40 +0100360 scripts/config.py unset PSA_WANT_ALG_CCM
Minos Galanakis471b34c2024-07-26 15:39:24 +0100361
362 make
363
364 msg "test: full no PSA_WANT_ALG_CCM"
365 make test
366}
367
Minos Galanakisf78447f2024-07-26 20:49:51 +0100368component_test_full_no_ccm_star_no_tag () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100369 msg "build: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
370
371 # Full config enables CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
372 scripts/config.py full
373
374 # Disable CCM_STAR_NO_TAG, which is the target of this test, as well as all
375 # other components that enable MBEDTLS_PSA_BUILTIN_CIPHER internal symbol.
376 # This basically disables all unauthenticated ciphers on the PSA side, while
377 # keeping AEADs enabled.
378 #
379 # Note: PSA_WANT_ALG_CCM is enabled, but it does not cause
380 # PSA_WANT_ALG_CCM_STAR_NO_TAG to be re-enabled.
David Horstmannb907dbc2025-08-27 15:19:40 +0100381 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
382 scripts/config.py unset PSA_WANT_ALG_STREAM_CIPHER
383 scripts/config.py unset PSA_WANT_ALG_CTR
384 scripts/config.py unset PSA_WANT_ALG_CFB
385 scripts/config.py unset PSA_WANT_ALG_OFB
386 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
Ben Taylor1948c942025-03-04 09:11:11 +0000387 # NOTE unsettting PSA_WANT_ALG_ECB_NO_PADDING without unsetting NIST_KW_C will
388 # mean PSA_WANT_ALG_ECB_NO_PADDING is re-enabled, so disabling it also.
David Horstmannb907dbc2025-08-27 15:19:40 +0100389 scripts/config.py unset MBEDTLS_NIST_KW_C
390 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
391 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
Minos Galanakis471b34c2024-07-26 15:39:24 +0100392
393 make
394
395 # Ensure MBEDTLS_PSA_BUILTIN_CIPHER was not enabled
396 not grep mbedtls_psa_cipher ${PSA_CORE_PATH}/psa_crypto_cipher.o
397
398 msg "test: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
399 make test
400}
401
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200402component_test_config_symmetric_only () {
403 msg "build: configs/config-symmetric-only.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +0000404 MBEDTLS_CONFIG="configs/config-symmetric-only.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +0000405 CRYPTO_CONFIG="tf-psa-crypto/configs/crypto-config-symmetric-only.h"
Ronald Cronfaadfc22024-12-07 17:24:28 +0100406 CC=$ASAN_CC cmake -DMBEDTLS_CONFIG_FILE="$MBEDTLS_CONFIG" -DTF_PSA_CRYPTO_CONFIG_FILE="$CRYPTO_CONFIG" -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskineaf5a8992024-09-14 11:27:44 +0200407 make
408
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200409 msg "test: configs/config-symmetric-only.h - unit tests"
Gilles Peskineaf5a8992024-09-14 11:27:44 +0200410 make test
411}
412
Minos Galanakisc06fd302024-08-01 12:16:59 +0100413component_test_everest () {
414 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
415 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
416 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
417 make
418
419 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
420 make test
421
422 msg "test: metatests (clang, ASan)"
423 tests/scripts/run-metatests.sh any asan poison
424
425 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
426 tests/ssl-opt.sh -f ECDH
427
428 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
429 # Exclude some symmetric ciphers that are redundant here to gain time.
430 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
431}
432
Minos Galanakis471b34c2024-07-26 15:39:24 +0100433component_test_psa_collect_statuses () {
434 msg "build+test: psa_collect_statuses" # ~30s
435 scripts/config.py full
436 tests/scripts/psa_collect_statuses.py
437 # Check that psa_crypto_init() succeeded at least once
438 grep -q '^0:psa_crypto_init:' tests/statuses.log
439 rm -f tests/statuses.log
440}
441
442# Check that the specified libraries exist and are empty.
443are_empty_libraries () {
444 nm "$@" >/dev/null 2>/dev/null
445 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
446}
447
Minos Galanakis471b34c2024-07-26 15:39:24 +0100448component_test_crypto_for_psa_service () {
449 msg "build: make, config for PSA crypto service"
450 scripts/config.py crypto
451 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
452 # Disable things that are not needed for just cryptography, to
453 # reach a configuration that would be typical for a PSA cryptography
454 # service providing all implemented PSA algorithms.
455 # System stuff
456 scripts/config.py unset MBEDTLS_ERROR_C
457 scripts/config.py unset MBEDTLS_TIMING_C
458 scripts/config.py unset MBEDTLS_VERSION_FEATURES
459 # Crypto stuff with no PSA interface
460 scripts/config.py unset MBEDTLS_BASE64_C
Minos Galanakis471b34c2024-07-26 15:39:24 +0100461 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
462 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
463 scripts/config.py unset MBEDTLS_NIST_KW_C
464 scripts/config.py unset MBEDTLS_PEM_PARSE_C
465 scripts/config.py unset MBEDTLS_PEM_WRITE_C
466 scripts/config.py unset MBEDTLS_PKCS12_C
467 scripts/config.py unset MBEDTLS_PKCS5_C
468 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
469 # in PSA code to work with RSA keys. We don't require users to set those:
470 # they will be reenabled in build_info.h.
471 scripts/config.py unset MBEDTLS_PK_C
472 scripts/config.py unset MBEDTLS_PK_PARSE_C
473 scripts/config.py unset MBEDTLS_PK_WRITE_C
474 make CFLAGS='-O1 -Werror' all test
475 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
476}
477
478component_build_crypto_baremetal () {
479 msg "build: make, crypto only, baremetal config"
480 scripts/config.py crypto_baremetal
David Horstmann5b93d972024-10-31 15:36:05 +0000481 make CFLAGS="-O1 -Werror -I$PWD/framework/tests/include/baremetal-override/"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100482 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
483}
484
485support_build_crypto_baremetal () {
486 support_build_baremetal "$@"
487}
488
489# depends.py family of tests
490component_test_depends_py_cipher_id () {
491 msg "test/build: depends.py cipher_id (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200492 tests/scripts/depends.py cipher_id
Minos Galanakis471b34c2024-07-26 15:39:24 +0100493}
494
495component_test_depends_py_cipher_chaining () {
496 msg "test/build: depends.py cipher_chaining (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200497 tests/scripts/depends.py cipher_chaining
Minos Galanakis471b34c2024-07-26 15:39:24 +0100498}
499
Minos Galanakis471b34c2024-07-26 15:39:24 +0100500component_test_depends_py_curves () {
501 msg "test/build: depends.py curves (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200502 tests/scripts/depends.py curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100503}
504
505component_test_depends_py_hashes () {
506 msg "test/build: depends.py hashes (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200507 tests/scripts/depends.py hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +0100508}
509
Minos Galanakis471b34c2024-07-26 15:39:24 +0100510component_test_depends_py_pkalgs () {
511 msg "test/build: depends.py pkalgs (gcc)"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100512 tests/scripts/depends.py pkalgs
513}
514
515component_test_psa_crypto_config_ffdh_2048_only () {
516 msg "build: full config - only DH 2048"
517
518 scripts/config.py full
519
520 # Disable all DH groups other than 2048.
David Horstmannb907dbc2025-08-27 15:19:40 +0100521 scripts/config.py unset PSA_WANT_DH_RFC7919_3072
522 scripts/config.py unset PSA_WANT_DH_RFC7919_4096
523 scripts/config.py unset PSA_WANT_DH_RFC7919_6144
524 scripts/config.py unset PSA_WANT_DH_RFC7919_8192
Minos Galanakis471b34c2024-07-26 15:39:24 +0100525
526 make CFLAGS="$ASAN_CFLAGS -Werror" LDFLAGS="$ASAN_CFLAGS"
527
528 msg "test: full config - only DH 2048"
529 make test
530
531 msg "ssl-opt: full config - only DH 2048"
532 tests/ssl-opt.sh -f "ffdh"
533}
534
Minos Galanakis471b34c2024-07-26 15:39:24 +0100535component_test_psa_crypto_config_accel_ecdsa () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200536 msg "build: accelerated ECDSA"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100537
Minos Galanakis471b34c2024-07-26 15:39:24 +0100538 # Configure
539 # ---------
540
Elena Uziunaite91d83862024-09-04 14:51:31 +0100541 # Start from default config + TLS 1.3
Minos Galanakis471b34c2024-07-26 15:39:24 +0100542 helper_libtestdriver1_adjust_config "default"
543
Valerio Setti37a42812025-08-11 12:52:49 +0200544 # Algorithms and key types to accelerate
545 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
546 $(helper_get_psa_key_type_list "ECC") \
547 $(helper_get_psa_curve_list)"
548
Minos Galanakis471b34c2024-07-26 15:39:24 +0100549 # Disable the module that's accelerated
550 scripts/config.py unset MBEDTLS_ECDSA_C
551
552 # Disable things that depend on it
553 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +0100554
555 # Build
556 # -----
557
558 # These hashes are needed for some ECDSA signature tests.
Elena Uziunaiteffce45c2024-09-12 14:58:52 +0100559 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
Minos Galanakis471b34c2024-07-26 15:39:24 +0100560 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
561
562 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
563
564 helper_libtestdriver1_make_main "$loc_accel_list"
565
566 # Make sure this was not re-enabled by accident (additive config)
567 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
568
569 # Run the tests
570 # -------------
571
Ronald Cron93ba6252024-09-05 10:37:14 +0200572 msg "test: accelerated ECDSA"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100573 make test
574}
575
576component_test_psa_crypto_config_accel_ecdh () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200577 msg "build: accelerated ECDH"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100578
Minos Galanakis471b34c2024-07-26 15:39:24 +0100579 # Configure
580 # ---------
581
582 # Start from default config (no USE_PSA)
583 helper_libtestdriver1_adjust_config "default"
584
Valerio Setti37a42812025-08-11 12:52:49 +0200585 # Algorithms and key types to accelerate
586 loc_accel_list="ALG_ECDH \
587 $(helper_get_psa_key_type_list "ECC") \
588 $(helper_get_psa_curve_list)"
589
Minos Galanakis471b34c2024-07-26 15:39:24 +0100590 # Disable the module that's accelerated
591 scripts/config.py unset MBEDTLS_ECDH_C
592
593 # Disable things that depend on it
Minos Galanakis471b34c2024-07-26 15:39:24 +0100594 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
595 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
596 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
597
598 # Build
599 # -----
600
601 helper_libtestdriver1_make_drivers "$loc_accel_list"
602
603 helper_libtestdriver1_make_main "$loc_accel_list"
604
605 # Make sure this was not re-enabled by accident (additive config)
606 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
607
608 # Run the tests
609 # -------------
610
Ronald Cron93ba6252024-09-05 10:37:14 +0200611 msg "test: accelerated ECDH"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100612 make test
613}
614
615component_test_psa_crypto_config_accel_ffdh () {
616 msg "build: full with accelerated FFDH"
617
Minos Galanakis471b34c2024-07-26 15:39:24 +0100618 # Configure
619 # ---------
620
621 # start with full (USE_PSA and TLS 1.3)
622 helper_libtestdriver1_adjust_config "full"
623
Valerio Setti37a42812025-08-11 12:52:49 +0200624 # Algorithms and key types to accelerate
625 loc_accel_list="ALG_FFDH \
626 $(helper_get_psa_key_type_list "DH") \
627 $(helper_get_psa_dh_group_list)"
628
Minos Galanakis471b34c2024-07-26 15:39:24 +0100629 # Build
630 # -----
631
632 helper_libtestdriver1_make_drivers "$loc_accel_list"
633
634 helper_libtestdriver1_make_main "$loc_accel_list"
635
636 # Make sure this was not re-enabled by accident (additive config)
Valerio Settieb63eb22025-02-12 13:32:49 +0100637 not grep mbedtls_psa_ffdh_key_agreement ${BUILTIN_SRC_PATH}/psa_crypto_ffdh.o
Minos Galanakis471b34c2024-07-26 15:39:24 +0100638
639 # Run the tests
640 # -------------
641
642 msg "test: full with accelerated FFDH"
643 make test
644
645 msg "ssl-opt: full with accelerated FFDH alg"
646 tests/ssl-opt.sh -f "ffdh"
647}
648
649component_test_psa_crypto_config_reference_ffdh () {
650 msg "build: full with non-accelerated FFDH"
651
652 # Start with full (USE_PSA and TLS 1.3)
653 helper_libtestdriver1_adjust_config "full"
654
Minos Galanakis471b34c2024-07-26 15:39:24 +0100655 make
656
657 msg "test suites: full with non-accelerated FFDH alg"
658 make test
659
660 msg "ssl-opt: full with non-accelerated FFDH alg"
661 tests/ssl-opt.sh -f "ffdh"
662}
663
Minos Galanakisf78447f2024-07-26 20:49:51 +0100664component_test_psa_crypto_config_accel_pake () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100665 msg "build: full with accelerated PAKE"
666
Minos Galanakis471b34c2024-07-26 15:39:24 +0100667 # Configure
668 # ---------
669
670 helper_libtestdriver1_adjust_config "full"
671
Valerio Setti37a42812025-08-11 12:52:49 +0200672 loc_accel_list="ALG_JPAKE \
673 $(helper_get_psa_key_type_list "ECC") \
674 $(helper_get_psa_curve_list)"
675
Minos Galanakis471b34c2024-07-26 15:39:24 +0100676 # Make built-in fallback not available
677 scripts/config.py unset MBEDTLS_ECJPAKE_C
678 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
679
680 # Build
681 # -----
682
683 helper_libtestdriver1_make_drivers "$loc_accel_list"
684
685 helper_libtestdriver1_make_main "$loc_accel_list"
686
687 # Make sure this was not re-enabled by accident (additive config)
688 not grep mbedtls_ecjpake_init ${BUILTIN_SRC_PATH}/ecjpake.o
689
690 # Run the tests
691 # -------------
692
693 msg "test: full with accelerated PAKE"
694 make test
695}
696
697component_test_psa_crypto_config_accel_ecc_some_key_types () {
698 msg "build: full with accelerated EC algs and some key types"
699
Valerio Setti37a42812025-08-11 12:52:49 +0200700 # Configure
701 # ---------
702
703 # start with config full for maximum coverage (also enables USE_PSA)
704 helper_libtestdriver1_adjust_config "full"
705
Minos Galanakis471b34c2024-07-26 15:39:24 +0100706 # Algorithms and key types to accelerate
707 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
708 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
709 ALG_ECDH \
710 ALG_JPAKE \
711 KEY_TYPE_ECC_PUBLIC_KEY \
712 KEY_TYPE_ECC_KEY_PAIR_BASIC \
713 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
714 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
715 $(helper_get_psa_curve_list)"
716
Minos Galanakis471b34c2024-07-26 15:39:24 +0100717 # Disable modules that are accelerated - some will be re-enabled
718 scripts/config.py unset MBEDTLS_ECDSA_C
719 scripts/config.py unset MBEDTLS_ECDH_C
720 scripts/config.py unset MBEDTLS_ECJPAKE_C
721 scripts/config.py unset MBEDTLS_ECP_C
722
723 # Disable all curves - those that aren't accelerated should be re-enabled
724 helper_disable_builtin_curves
725
726 # Restartable feature is not yet supported by PSA. Once it will in
727 # the future, the following line could be removed (see issues
728 # 6061, 6332 and following ones)
729 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
730
731 # this is not supported by the driver API yet
David Horstmannb907dbc2025-08-27 15:19:40 +0100732 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +0100733
734 # Build
735 # -----
736
737 # These hashes are needed for some ECDSA signature tests.
738 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
739 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
740 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
741
742 helper_libtestdriver1_make_main "$loc_accel_list"
743
744 # ECP should be re-enabled but not the others
745 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
746 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
747 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
748 grep mbedtls_ecp ${BUILTIN_SRC_PATH}/ecp.o
749
750 # Run the tests
751 # -------------
752
753 msg "test suites: full with accelerated EC algs and some key types"
754 make test
755}
756
757# Run tests with only (non-)Weierstrass accelerated
758# Common code used in:
759# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
760# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100761common_test_psa_crypto_config_accel_ecc_some_curves () {
762 weierstrass=$1
763 if [ $weierstrass -eq 1 ]; then
764 desc="Weierstrass"
765 else
766 desc="non-Weierstrass"
767 fi
768
769 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
770
Valerio Setti37a42812025-08-11 12:52:49 +0200771 # Configure
772 # ---------
773
774 # Start with config crypto_full and remove PK_C:
775 # that's what's supported now, see docs/driver-only-builds.md.
776 helper_libtestdriver1_adjust_config "crypto_full"
777 scripts/config.py unset MBEDTLS_PK_C
778 scripts/config.py unset MBEDTLS_PK_PARSE_C
779 scripts/config.py unset MBEDTLS_PK_WRITE_C
780
781 # Disable modules that are accelerated - some will be re-enabled
782 scripts/config.py unset MBEDTLS_ECDSA_C
783 scripts/config.py unset MBEDTLS_ECDH_C
784 scripts/config.py unset MBEDTLS_ECJPAKE_C
785 scripts/config.py unset MBEDTLS_ECP_C
786
787 # Disable all curves - those that aren't accelerated should be re-enabled
788 helper_disable_builtin_curves
789
Valerio Setti981a0c42025-08-12 11:31:11 +0200790 # Note: Curves are handled in a special way by the libtestdriver machinery,
Minos Galanakis471b34c2024-07-26 15:39:24 +0100791 # so we only want to include them in the accel list when building the main
792 # libraries, hence the use of a separate variable.
793 # Note: the following loop is a modified version of
794 # helper_get_psa_curve_list that only keeps Weierstrass families.
795 loc_weierstrass_list=""
796 loc_non_weierstrass_list=""
797 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
798 case $item in
799 ECC_BRAINPOOL*|ECC_SECP*)
800 loc_weierstrass_list="$loc_weierstrass_list $item"
801 ;;
802 *)
803 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
804 ;;
805 esac
806 done
807 if [ $weierstrass -eq 1 ]; then
808 loc_curve_list=$loc_weierstrass_list
809 else
810 loc_curve_list=$loc_non_weierstrass_list
811 fi
812
813 # Algorithms and key types to accelerate
814 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
815 ALG_ECDH \
816 ALG_JPAKE \
817 $(helper_get_psa_key_type_list "ECC") \
818 $loc_curve_list"
819
Minos Galanakis471b34c2024-07-26 15:39:24 +0100820 # Restartable feature is not yet supported by PSA. Once it will in
821 # the future, the following line could be removed (see issues
822 # 6061, 6332 and following ones)
823 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
824
825 # this is not supported by the driver API yet
David Horstmannb907dbc2025-08-27 15:19:40 +0100826 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +0100827
828 # Build
829 # -----
830
831 # These hashes are needed for some ECDSA signature tests.
832 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
833 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
834 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
835
836 helper_libtestdriver1_make_main "$loc_accel_list"
837
838 # We expect ECDH to be re-enabled for the missing curves
839 grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
840 # We expect ECP to be re-enabled, however the parts specific to the
841 # families of curves that are accelerated should be ommited.
842 # - functions with mxz in the name are specific to Montgomery curves
843 # - ecp_muladd is specific to Weierstrass curves
844 ##nm ${BUILTIN_SRC_PATH}/ecp.o | tee ecp.syms
845 if [ $weierstrass -eq 1 ]; then
846 not grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
847 grep mxz ${BUILTIN_SRC_PATH}/ecp.o
848 else
849 grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
850 not grep mxz ${BUILTIN_SRC_PATH}/ecp.o
851 fi
852 # We expect ECDSA and ECJPAKE to be re-enabled only when
853 # Weierstrass curves are not accelerated
854 if [ $weierstrass -eq 1 ]; then
855 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
856 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
857 else
858 grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
859 grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
860 fi
861
862 # Run the tests
863 # -------------
864
865 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
Valerio Setti981a0c42025-08-12 11:31:11 +0200866 make test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100867}
868
869component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
870 common_test_psa_crypto_config_accel_ecc_some_curves 1
871}
872
873component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
874 common_test_psa_crypto_config_accel_ecc_some_curves 0
875}
876
877# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
878# ECDH, ECDSA) with and without drivers.
879# The input parameter is a boolean value which indicates:
880# - 0 keep built-in EC algs,
881# - 1 exclude built-in EC algs (driver only).
882#
883# This is used by the two following components to ensure they always use the
884# same config, except for the use of driver or built-in EC algorithms:
885# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
886# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
887# This supports comparing their test coverage with analyze_outcomes.py.
Minos Galanakis471b34c2024-07-26 15:39:24 +0100888config_psa_crypto_config_ecp_light_only () {
889 driver_only="$1"
890 # start with config full for maximum coverage (also enables USE_PSA)
891 helper_libtestdriver1_adjust_config "full"
892 if [ "$driver_only" -eq 1 ]; then
893 # Disable modules that are accelerated
894 scripts/config.py unset MBEDTLS_ECDSA_C
895 scripts/config.py unset MBEDTLS_ECDH_C
896 scripts/config.py unset MBEDTLS_ECJPAKE_C
897 scripts/config.py unset MBEDTLS_ECP_C
898 fi
899
900 # Restartable feature is not yet supported by PSA. Once it will in
901 # the future, the following line could be removed (see issues
902 # 6061, 6332 and following ones)
903 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
904}
905
906# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100907component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
908 msg "build: full with accelerated EC algs"
909
Valerio Setti37a42812025-08-11 12:52:49 +0200910 # Configure
911 # ---------
912
913 # Use the same config as reference, only without built-in EC algs
914 config_psa_crypto_config_ecp_light_only 1
915
Minos Galanakis471b34c2024-07-26 15:39:24 +0100916 # Algorithms and key types to accelerate
917 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
918 ALG_ECDH \
919 ALG_JPAKE \
920 $(helper_get_psa_key_type_list "ECC") \
921 $(helper_get_psa_curve_list)"
922
Minos Galanakis471b34c2024-07-26 15:39:24 +0100923 # Do not disable builtin curves because that support is required for:
924 # - MBEDTLS_PK_PARSE_EC_EXTENDED
925 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
926
927 # Build
928 # -----
929
930 # These hashes are needed for some ECDSA signature tests.
931 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
932 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
933 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
934
935 helper_libtestdriver1_make_main "$loc_accel_list"
936
937 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
938 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
939 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
940 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
941 not grep mbedtls_ecp_mul ${BUILTIN_SRC_PATH}/ecp.o
942
943 # Run the tests
944 # -------------
945
946 msg "test suites: full with accelerated EC algs"
947 make test
948
949 msg "ssl-opt: full with accelerated EC algs"
950 tests/ssl-opt.sh
951}
952
953# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100954component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200955 msg "build: non-accelerated EC algs"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100956
957 config_psa_crypto_config_ecp_light_only 0
958
959 make
960
961 msg "test suites: full with non-accelerated EC algs"
962 make test
963
964 msg "ssl-opt: full with non-accelerated EC algs"
965 tests/ssl-opt.sh
966}
967
968# This helper function is used by:
969# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
970# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
971# to ensure that both tests use the same underlying configuration when testing
972# driver's coverage with analyze_outcomes.py.
973#
974# This functions accepts 1 boolean parameter as follows:
975# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
976# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
977# - 0: include built-in implementation of EC algorithms.
978#
979# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
980# on the ECP module.
Minos Galanakis471b34c2024-07-26 15:39:24 +0100981config_psa_crypto_no_ecp_at_all () {
982 driver_only="$1"
983 # start with full config for maximum coverage (also enables USE_PSA)
984 helper_libtestdriver1_adjust_config "full"
985
986 if [ "$driver_only" -eq 1 ]; then
987 # Disable modules that are accelerated
988 scripts/config.py unset MBEDTLS_ECDSA_C
989 scripts/config.py unset MBEDTLS_ECDH_C
990 scripts/config.py unset MBEDTLS_ECJPAKE_C
991 # Disable ECP module (entirely)
992 scripts/config.py unset MBEDTLS_ECP_C
993 fi
994
995 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
996 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
997 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
David Horstmannb907dbc2025-08-27 15:19:40 +0100998 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +0100999
1000 # Restartable feature is not yet supported by PSA. Once it will in
1001 # the future, the following line could be removed (see issues
1002 # 6061, 6332 and following ones)
1003 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1004}
1005
1006# Build and test a configuration where driver accelerates all EC algs while
1007# all support and dependencies from ECP and ECP_LIGHT are removed on the library
1008# side.
1009#
1010# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001011component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
1012 msg "build: full + accelerated EC algs - ECP"
1013
Minos Galanakis471b34c2024-07-26 15:39:24 +01001014 # Configure
1015 # ---------
1016
1017 # Set common configurations between library's and driver's builds
1018 config_psa_crypto_no_ecp_at_all 1
1019 # Disable all the builtin curves. All the required algs are accelerated.
1020 helper_disable_builtin_curves
1021
Valerio Setti37a42812025-08-11 12:52:49 +02001022 # Algorithms and key types to accelerate
1023 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1024 ALG_ECDH \
1025 ALG_JPAKE \
1026 $(helper_get_psa_key_type_list "ECC") \
1027 $(helper_get_psa_curve_list)"
1028
Minos Galanakis471b34c2024-07-26 15:39:24 +01001029 # Build
1030 # -----
1031
1032 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1033 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1034 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1035 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1036
1037 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1038
1039 helper_libtestdriver1_make_main "$loc_accel_list"
1040
1041 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1042 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1043 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1044 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1045 # Also ensure that ECP module was not re-enabled
1046 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1047
1048 # Run the tests
1049 # -------------
1050
1051 msg "test: full + accelerated EC algs - ECP"
1052 make test
1053
1054 msg "ssl-opt: full + accelerated EC algs - ECP"
1055 tests/ssl-opt.sh
1056}
1057
1058# Reference function used for driver's coverage analysis in analyze_outcomes.py
1059# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
1060# Keep in sync with its accelerated counterpart.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001061component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
1062 msg "build: full + non accelerated EC algs"
1063
1064 config_psa_crypto_no_ecp_at_all 0
1065
1066 make
1067
1068 msg "test: full + non accelerated EC algs"
1069 make test
1070
1071 msg "ssl-opt: full + non accelerated EC algs"
1072 tests/ssl-opt.sh
1073}
1074
1075# This is a common configuration helper used directly from:
1076# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1077# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1078# and indirectly from:
1079# - component_test_psa_crypto_config_accel_ecc_no_bignum
1080# - accelerate all EC algs, disable RSA and FFDH
1081# - component_test_psa_crypto_config_reference_ecc_no_bignum
1082# - this is the reference component of the above
1083# - it still disables RSA and FFDH, but it uses builtin EC algs
1084# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1085# - accelerate all EC and FFDH algs, disable only RSA
1086# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1087# - this is the reference component of the above
1088# - it still disables RSA, but it uses builtin EC and FFDH algs
1089#
1090# This function accepts 2 parameters:
1091# $1: a boolean value which states if we are testing an accelerated scenario
1092# or not.
1093# $2: a string value which states which components are tested. Allowed values
1094# are "ECC" or "ECC_DH".
Minos Galanakisf78447f2024-07-26 20:49:51 +01001095config_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001096 driver_only="$1"
1097 test_target="$2"
1098 # start with full config for maximum coverage (also enables USE_PSA)
1099 helper_libtestdriver1_adjust_config "full"
1100
1101 if [ "$driver_only" -eq 1 ]; then
1102 # Disable modules that are accelerated
1103 scripts/config.py unset MBEDTLS_ECDSA_C
1104 scripts/config.py unset MBEDTLS_ECDH_C
1105 scripts/config.py unset MBEDTLS_ECJPAKE_C
1106 # Disable ECP module (entirely)
1107 scripts/config.py unset MBEDTLS_ECP_C
1108 # Also disable bignum
1109 scripts/config.py unset MBEDTLS_BIGNUM_C
1110 fi
1111
1112 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1113 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1114 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
David Horstmannb907dbc2025-08-27 15:19:40 +01001115 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +01001116
1117 # RSA support is intentionally disabled on this test because RSA_C depends
1118 # on BIGNUM_C.
David Horstmannb907dbc2025-08-27 15:19:40 +01001119 scripts/config.py unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
1120 scripts/config.py unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001121 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1122 # Also disable key exchanges that depend on RSA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001123 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001124
1125 if [ "$test_target" = "ECC" ]; then
1126 # When testing ECC only, we disable FFDH support, both from builtin and
Valerio Setti8438c632025-01-22 11:56:40 +01001127 # PSA sides.
David Horstmannb907dbc2025-08-27 15:19:40 +01001128 scripts/config.py unset PSA_WANT_ALG_FFDH
1129 scripts/config.py unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
1130 scripts/config.py unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001131 fi
1132
1133 # Restartable feature is not yet supported by PSA. Once it will in
1134 # the future, the following line could be removed (see issues
1135 # 6061, 6332 and following ones)
1136 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1137}
1138
1139# Common helper used by:
1140# - component_test_psa_crypto_config_accel_ecc_no_bignum
1141# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1142#
1143# The goal is to build and test accelerating either:
1144# - ECC only or
1145# - both ECC and FFDH
1146#
1147# It is meant to be used in conjunction with
1148# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
1149# coverage analysis in the "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001150common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1151 test_target="$1"
1152
1153 # This is an internal helper to simplify text message handling
1154 if [ "$test_target" = "ECC_DH" ]; then
1155 accel_text="ECC/FFDH"
1156 removed_text="ECP - DH"
1157 else
1158 accel_text="ECC"
1159 removed_text="ECP"
1160 fi
1161
1162 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1163
Valerio Setti37a42812025-08-11 12:52:49 +02001164 # Configure
1165 # ---------
1166
1167 # Set common configurations between library's and driver's builds
1168 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
1169 # Disable all the builtin curves. All the required algs are accelerated.
1170 helper_disable_builtin_curves
1171
Minos Galanakis471b34c2024-07-26 15:39:24 +01001172 # By default we accelerate all EC keys/algs
1173 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1174 ALG_ECDH \
1175 ALG_JPAKE \
1176 $(helper_get_psa_key_type_list "ECC") \
1177 $(helper_get_psa_curve_list)"
1178 # Optionally we can also add DH to the list of accelerated items
1179 if [ "$test_target" = "ECC_DH" ]; then
1180 loc_accel_list="$loc_accel_list \
1181 ALG_FFDH \
1182 $(helper_get_psa_key_type_list "DH") \
1183 $(helper_get_psa_dh_group_list)"
1184 fi
1185
Minos Galanakis471b34c2024-07-26 15:39:24 +01001186 # Build
1187 # -----
1188
1189 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1190 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1191 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1192 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1193
1194 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1195
1196 helper_libtestdriver1_make_main "$loc_accel_list"
1197
1198 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1199 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1200 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1201 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001202 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001203 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1204 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1205 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001206
1207 # Run the tests
1208 # -------------
1209
Valerio Settieb63eb22025-02-12 13:32:49 +01001210 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001211
1212 make test
1213
1214 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1215 tests/ssl-opt.sh
1216}
1217
1218# Common helper used by:
1219# - component_test_psa_crypto_config_reference_ecc_no_bignum
1220# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1221#
1222# The goal is to build and test a reference scenario (i.e. with builtin
1223# components) compared to the ones used in
1224# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
1225#
1226# It is meant to be used in conjunction with
1227# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
1228# coverage analysis in "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001229common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1230 test_target="$1"
1231
1232 # This is an internal helper to simplify text message handling
1233 if [ "$test_target" = "ECC_DH" ]; then
1234 accel_text="ECC/FFDH"
1235 else
1236 accel_text="ECC"
1237 fi
1238
1239 msg "build: full + non accelerated $accel_text algs + USE_PSA"
1240
1241 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
1242
1243 make
1244
1245 msg "test suites: full + non accelerated EC algs + USE_PSA"
1246 make test
1247
1248 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
1249 tests/ssl-opt.sh
1250}
1251
1252component_test_psa_crypto_config_accel_ecc_no_bignum () {
1253 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
1254}
1255
1256component_test_psa_crypto_config_reference_ecc_no_bignum () {
1257 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
1258}
1259
1260component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1261 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
1262}
1263
1264component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1265 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
1266}
1267
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001268component_test_tfm_config_as_is () {
1269 msg "build: configs/config-tfm.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +00001270 MBEDTLS_CONFIG="configs/config-tfm.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001271 CRYPTO_CONFIG="tf-psa-crypto/configs/ext/crypto_config_profile_medium.h"
Minos Galanakis4f619e12024-11-14 14:56:47 +00001272 CC=$ASAN_CC cmake -DMBEDTLS_CONFIG_FILE="$MBEDTLS_CONFIG" -DTF_PSA_CRYPTO_CONFIG_FILE="$CRYPTO_CONFIG" -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001273 make
1274
1275 msg "test: configs/config-tfm.h - unit tests"
1276 make test
1277}
1278
Minos Galanakis471b34c2024-07-26 15:39:24 +01001279# Helper for setting common configurations between:
1280# - component_test_tfm_config_p256m_driver_accel_ec()
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001281# - component_test_tfm_config_no_p256m()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001282common_tfm_config () {
1283 # Enable TF-M config
1284 cp configs/config-tfm.h "$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001285 cp tf-psa-crypto/configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001286
Minos Galanakis471b34c2024-07-26 15:39:24 +01001287 # Config adjustment for better test coverage in our environment.
1288 # This is not needed just to build and pass tests.
1289 #
1290 # Enable filesystem I/O for the benefit of PK parse/write tests.
Minos Galanakis5da58e52024-11-07 15:35:33 +00001291 sed -i '/PROFILE_M_PSA_CRYPTO_CONFIG_H/i #define MBEDTLS_FS_IO' "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001292}
1293
1294# Keep this in sync with component_test_tfm_config() as they are both meant
1295# to be used in analyze_outcomes.py for driver's coverage analysis.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001296component_test_tfm_config_p256m_driver_accel_ec () {
1297 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1298
1299 common_tfm_config
1300
1301 # Build crypto library
David Horstmann5b93d972024-10-31 15:36:05 +00001302 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../framework/tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001303
1304 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1305 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1306 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1307 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001308 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001309 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1310 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001311 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1312 # Check that p256m was built
1313 grep -q p256_ecdsa_ library/libmbedcrypto.a
1314
1315 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1316 # files, so we want to ensure that it has not be re-enabled accidentally.
1317 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1318
1319 # Run the tests
1320 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1321 make test
1322}
1323
1324# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1325# they are both meant to be used in analyze_outcomes.py for driver's coverage
1326# analysis.
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001327component_test_tfm_config_no_p256m () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001328 common_tfm_config
1329
1330 # Disable P256M driver, which is on by default, so that analyze_outcomes
1331 # can compare this test with test_tfm_config_p256m_driver_accel_ec
Minos Galanakis5da58e52024-11-07 15:35:33 +00001332 sed -i '/PROFILE_M_PSA_CRYPTO_CONFIG_H/i #undef MBEDTLS_PSA_P256M_DRIVER_ENABLED' "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001333
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001334 msg "build: TF-M config without p256m"
David Horstmann5b93d972024-10-31 15:36:05 +00001335 make CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' tests
Minos Galanakis471b34c2024-07-26 15:39:24 +01001336
1337 # Check that p256m was not built
1338 not grep p256_ecdsa_ library/libmbedcrypto.a
1339
1340 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1341 # files, so we want to ensure that it has not be re-enabled accidentally.
1342 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1343
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001344 msg "test: TF-M config without p256m"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001345 make test
1346}
1347
Minos Galanakis471b34c2024-07-26 15:39:24 +01001348# This is an helper used by:
1349# - component_test_psa_ecc_key_pair_no_derive
1350# - component_test_psa_ecc_key_pair_no_generate
1351# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1352# enabled, but one. Input arguments are as follows:
Gilles Peskinefef912c2024-09-20 16:07:09 +02001353# - $1 is the configuration to start from
1354# - $2 is the key type under test, i.e. ECC/RSA/DH
1355# - $3 is the key option to be unset (i.e. generate, derive, etc)
Minos Galanakisf78447f2024-07-26 20:49:51 +01001356build_and_test_psa_want_key_pair_partial () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001357 base_config=$1
1358 key_type=$2
1359 unset_option=$3
Minos Galanakis471b34c2024-07-26 15:39:24 +01001360 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1361
Gilles Peskinefef912c2024-09-20 16:07:09 +02001362 msg "build: $base_config - ${disabled_psa_want}"
1363 scripts/config.py "$base_config"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001364
1365 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1366 # crypto_config.h so we just disable the one we don't want.
David Horstmannb907dbc2025-08-27 15:19:40 +01001367 scripts/config.py unset "$disabled_psa_want"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001368
1369 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1370
Gilles Peskinefef912c2024-09-20 16:07:09 +02001371 msg "test: $base_config - ${disabled_psa_want}"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001372 make test
1373}
1374
Minos Galanakisf78447f2024-07-26 20:49:51 +01001375component_test_psa_ecc_key_pair_no_derive () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001376 build_and_test_psa_want_key_pair_partial full "ECC" "DERIVE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001377}
1378
Minos Galanakisf78447f2024-07-26 20:49:51 +01001379component_test_psa_ecc_key_pair_no_generate () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001380 # TLS needs ECC key generation whenever ephemeral ECDH is enabled.
1381 # We don't have proper guards for configurations with ECC key generation
1382 # disabled (https://github.com/Mbed-TLS/mbedtls/issues/9481). Until
1383 # then (if ever), just test the crypto part of the library.
1384 build_and_test_psa_want_key_pair_partial crypto_full "ECC" "GENERATE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001385}
1386
1387config_psa_crypto_accel_rsa () {
1388 driver_only=$1
1389
1390 # Start from crypto_full config (no X.509, no TLS)
1391 helper_libtestdriver1_adjust_config "crypto_full"
1392
1393 if [ "$driver_only" -eq 1 ]; then
Minos Galanakis471b34c2024-07-26 15:39:24 +01001394 # We need PEM parsing in the test library as well to support the import
1395 # of PEM encoded RSA keys.
Minos Galanakis23452f52024-11-28 17:48:14 +00001396 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1397 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
Minos Galanakis471b34c2024-07-26 15:39:24 +01001398 fi
1399}
1400
1401component_test_psa_crypto_config_accel_rsa_crypto () {
1402 msg "build: crypto_full with accelerated RSA"
1403
1404 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1405 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1406 KEY_TYPE_RSA_PUBLIC_KEY \
1407 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1408 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1409 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1410 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1411
1412 # Configure
1413 # ---------
1414
1415 config_psa_crypto_accel_rsa 1
1416
1417 # Build
1418 # -----
1419
1420 # These hashes are needed for unit tests.
1421 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1422 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1423 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1424
1425 helper_libtestdriver1_make_main "$loc_accel_list"
1426
1427 # Make sure this was not re-enabled by accident (additive config)
1428 not grep mbedtls_rsa ${BUILTIN_SRC_PATH}/rsa.o
1429
1430 # Run the tests
1431 # -------------
1432
1433 msg "test: crypto_full with accelerated RSA"
1434 make test
1435}
1436
1437component_test_psa_crypto_config_reference_rsa_crypto () {
1438 msg "build: crypto_full with non-accelerated RSA"
1439
1440 # Configure
1441 # ---------
1442 config_psa_crypto_accel_rsa 0
1443
1444 # Build
1445 # -----
1446 make
1447
1448 # Run the tests
1449 # -------------
1450 msg "test: crypto_full with non-accelerated RSA"
1451 make test
1452}
1453
1454# This is a temporary test to verify that full RSA support is present even when
1455# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001456component_test_new_psa_want_key_pair_symbol () {
Ronald Cron892bb612025-07-21 14:26:27 +02001457 msg "Build: crypto config - PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001458
1459 # Create a temporary output file unless there is already one set
1460 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1461 REMOVE_OUTCOME_ON_EXIT="no"
1462 else
1463 REMOVE_OUTCOME_ON_EXIT="yes"
1464 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1465 export MBEDTLS_TEST_OUTCOME_FILE
1466 fi
1467
1468 # Start from crypto configuration
1469 scripts/config.py crypto
1470
1471 # Remove RSA support and its dependencies
Minos Galanakis471b34c2024-07-26 15:39:24 +01001472 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001473 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1474
Minos Galanakis471b34c2024-07-26 15:39:24 +01001475 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
1476 # that proper translations is done in crypto_legacy.h.
David Horstmannb907dbc2025-08-27 15:19:40 +01001477 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
1478 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
1479 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Minos Galanakis471b34c2024-07-26 15:39:24 +01001480
1481 make
1482
Ronald Cron892bb612025-07-21 14:26:27 +02001483 msg "Test: crypto config - PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001484 make test
1485
1486 # Parse only 1 relevant line from the outcome file, i.e. a test which is
1487 # performing RSA signature.
1488 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
1489 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
1490
1491 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
1492 rm $MBEDTLS_TEST_OUTCOME_FILE
1493 fi
1494}
1495
1496component_test_psa_crypto_config_accel_hash () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001497 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001498
1499 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1500 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1501 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1502
1503 # Configure
1504 # ---------
1505
1506 # Start from default config (no USE_PSA)
1507 helper_libtestdriver1_adjust_config "default"
1508
Minos Galanakis471b34c2024-07-26 15:39:24 +01001509 # Build
1510 # -----
1511
1512 helper_libtestdriver1_make_drivers "$loc_accel_list"
1513
1514 helper_libtestdriver1_make_main "$loc_accel_list"
1515
1516 # There's a risk of something getting re-enabled via config_psa.h;
1517 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1518 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1519 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1520 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1521 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1522 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1523
1524 # Run the tests
1525 # -------------
1526
Ronald Cron93ba6252024-09-05 10:37:14 +02001527 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001528 make test
1529}
1530
1531# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001532config_psa_crypto_hash_use_psa () {
1533 driver_only="$1"
1534 # start with config full for maximum coverage (also enables USE_PSA)
1535 helper_libtestdriver1_adjust_config "full"
1536 if [ "$driver_only" -eq 1 ]; then
1537 # disable the built-in implementation of hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +01001538 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Minos Galanakis471b34c2024-07-26 15:39:24 +01001539 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Minos Galanakis471b34c2024-07-26 15:39:24 +01001540 fi
1541}
1542
1543# Note that component_test_psa_crypto_config_reference_hash_use_psa
1544# is related to this component and both components need to be kept in sync.
1545# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001546component_test_psa_crypto_config_accel_hash_use_psa () {
1547 msg "test: full with accelerated hashes"
1548
1549 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1550 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1551 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1552
1553 # Configure
1554 # ---------
1555
1556 config_psa_crypto_hash_use_psa 1
1557
1558 # Build
1559 # -----
1560
1561 helper_libtestdriver1_make_drivers "$loc_accel_list"
1562
1563 helper_libtestdriver1_make_main "$loc_accel_list"
1564
1565 # There's a risk of something getting re-enabled via config_psa.h;
1566 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1567 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1568 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1569 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1570 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1571 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1572
1573 # Run the tests
1574 # -------------
1575
1576 msg "test: full with accelerated hashes"
1577 make test
1578
1579 # This is mostly useful so that we can later compare outcome files with
1580 # the reference config in analyze_outcomes.py, to check that the
1581 # dependency declarations in ssl-opt.sh and in TLS code are correct.
1582 msg "test: ssl-opt.sh, full with accelerated hashes"
1583 tests/ssl-opt.sh
1584
1585 # This is to make sure all ciphersuites are exercised, but we don't need
1586 # interop testing (besides, we already got some from ssl-opt.sh).
1587 msg "test: compat.sh, full with accelerated hashes"
1588 tests/compat.sh -p mbedTLS -V YES
1589}
1590
1591# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
1592# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
1593# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
1594# Both components need to be kept in sync.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001595component_test_psa_crypto_config_reference_hash_use_psa () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001596 msg "test: full without accelerated hashes"
1597
1598 config_psa_crypto_hash_use_psa 0
1599
1600 make
1601
1602 msg "test: full without accelerated hashes"
1603 make test
1604
1605 msg "test: ssl-opt.sh, full without accelerated hashes"
1606 tests/ssl-opt.sh
1607}
1608
1609# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001610config_psa_crypto_hmac_use_psa () {
1611 driver_only="$1"
1612 # start with config full for maximum coverage (also enables USE_PSA)
1613 helper_libtestdriver1_adjust_config "full"
1614
1615 if [ "$driver_only" -eq 1 ]; then
1616 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
1617 # is still enabled though (for ENTROPY_C among others).
1618 scripts/config.py unset MBEDTLS_MD_C
Ronald Cron772a8ad2025-07-21 12:36:29 +02001619 # Also disable the configuration options that tune the builtin hashes,
1620 # since those hashes are disabled.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001621 scripts/config.py unset-all MBEDTLS_SHA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001622 fi
1623
1624 # Direct dependencies of MD_C. We disable them also in the reference
1625 # component to work with the same set of features.
1626 scripts/config.py unset MBEDTLS_PKCS7_C
1627 scripts/config.py unset MBEDTLS_PKCS5_C
1628 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1629 scripts/config.py unset MBEDTLS_HKDF_C
1630 # Dependencies of HMAC_DRBG
David Horstmannb907dbc2025-08-27 15:19:40 +01001631 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001632}
1633
Minos Galanakisf78447f2024-07-26 20:49:51 +01001634component_test_psa_crypto_config_accel_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001635 msg "test: full with accelerated hmac"
1636
1637 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
1638 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1639 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1640 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1641
1642 # Configure
1643 # ---------
1644
1645 config_psa_crypto_hmac_use_psa 1
1646
1647 # Build
1648 # -----
1649
1650 helper_libtestdriver1_make_drivers "$loc_accel_list"
1651
1652 helper_libtestdriver1_make_main "$loc_accel_list"
1653
1654 # Ensure that built-in support for HMAC is disabled.
1655 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
1656
1657 # Run the tests
1658 # -------------
1659
1660 msg "test: full with accelerated hmac"
1661 make test
1662}
1663
Minos Galanakisf78447f2024-07-26 20:49:51 +01001664component_test_psa_crypto_config_reference_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001665 msg "test: full without accelerated hmac"
1666
1667 config_psa_crypto_hmac_use_psa 0
1668
1669 make
1670
1671 msg "test: full without accelerated hmac"
1672 make test
1673}
1674
Minos Galanakis471b34c2024-07-26 15:39:24 +01001675component_test_psa_crypto_config_accel_aead () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001676 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001677
1678 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
1679 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1680
1681 # Configure
1682 # ---------
1683
1684 # Start from full config
1685 helper_libtestdriver1_adjust_config "full"
1686
Minos Galanakis471b34c2024-07-26 15:39:24 +01001687 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
David Horstmannb907dbc2025-08-27 15:19:40 +01001688 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
Minos Galanakis471b34c2024-07-26 15:39:24 +01001689
1690 # Build
1691 # -----
1692
1693 helper_libtestdriver1_make_drivers "$loc_accel_list"
1694
1695 helper_libtestdriver1_make_main "$loc_accel_list"
1696
1697 # Make sure this was not re-enabled by accident (additive config)
1698 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1699 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1700 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1701
1702 # Run the tests
1703 # -------------
1704
Ronald Cron93ba6252024-09-05 10:37:14 +02001705 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001706 make test
1707}
1708
1709# This is a common configuration function used in:
1710# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1711# - component_test_psa_crypto_config_reference_cipher_aead_cmac
Minos Galanakisf78447f2024-07-26 20:49:51 +01001712common_psa_crypto_config_accel_cipher_aead_cmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001713 # Start from the full config
1714 helper_libtestdriver1_adjust_config "full"
1715
1716 scripts/config.py unset MBEDTLS_NIST_KW_C
1717}
1718
1719# The 2 following test components, i.e.
1720# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1721# - component_test_psa_crypto_config_reference_cipher_aead_cmac
1722# are meant to be used together in analyze_outcomes.py script in order to test
1723# driver's coverage for ciphers and AEADs.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001724component_test_psa_crypto_config_accel_cipher_aead_cmac () {
1725 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
1726
1727 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
1728 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
1729 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
Ari Weiler-Ofek86422e52025-07-04 14:43:30 +01001730 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001731
1732 # Configure
1733 # ---------
1734
1735 common_psa_crypto_config_accel_cipher_aead_cmac
1736
Ari Weiler-Ofek5d8d2992025-07-07 23:20:29 +01001737 # Disable DES, if it still exists.
1738 # This can be removed once we remove DES from the library.
1739 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
1740
Minos Galanakis471b34c2024-07-26 15:39:24 +01001741 # Build
1742 # -----
1743
1744 helper_libtestdriver1_make_drivers "$loc_accel_list"
1745
1746 helper_libtestdriver1_make_main "$loc_accel_list"
1747
1748 # Make sure this was not re-enabled by accident (additive config)
1749 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001750 not grep mbedtls_aes ${BUILTIN_SRC_PATH}/aes.o
1751 not grep mbedtls_aria ${BUILTIN_SRC_PATH}/aria.o
1752 not grep mbedtls_camellia ${BUILTIN_SRC_PATH}/camellia.o
1753 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1754 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1755 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1756 not grep mbedtls_cmac ${BUILTIN_SRC_PATH}/cmac.o
Ronald Cronb5c6fcc2025-07-10 13:40:00 +02001757 not grep mbedtls_poly1305 ${BUILTIN_SRC_PATH}/poly1305.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001758
1759 # Run the tests
1760 # -------------
1761
1762 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
1763 make test
1764
1765 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
Ronald Cronbd28acf2025-07-10 09:53:50 +02001766 # Exclude password-protected key tests — they require built-in CBC and AES.
1767 tests/ssl-opt.sh -e "TLS: password protected"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001768
1769 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
1770 tests/compat.sh -V NO -p mbedTLS
1771}
1772
1773component_test_psa_crypto_config_reference_cipher_aead_cmac () {
1774 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
1775 common_psa_crypto_config_accel_cipher_aead_cmac
1776
Ari Weiler-Ofek5d8d2992025-07-07 23:20:29 +01001777 # Disable DES, if it still exists.
1778 # This can be removed once we remove DES from the library.
1779 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
1780
Minos Galanakis471b34c2024-07-26 15:39:24 +01001781 make
1782
1783 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
1784 make test
1785
1786 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
Ronald Cronbd28acf2025-07-10 09:53:50 +02001787 # Exclude password-protected key tests as in test_psa_crypto_config_accel_cipher_aead_cmac.
1788 tests/ssl-opt.sh -e "TLS: password protected"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001789
1790 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
1791 tests/compat.sh -V NO -p mbedTLS
1792}
1793
Minos Galanakisf78447f2024-07-26 20:49:51 +01001794common_block_cipher_dispatch () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001795 TEST_WITH_DRIVER="$1"
1796
1797 # Start from the full config
1798 helper_libtestdriver1_adjust_config "full"
1799
Minos Galanakis471b34c2024-07-26 15:39:24 +01001800 # Disable cipher's modes that, when not accelerated, cause
1801 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
1802 # Keep this also in the reference component in order to skip the same tests
1803 # that were skipped in the accelerated one.
David Horstmannb907dbc2025-08-27 15:19:40 +01001804 scripts/config.py unset PSA_WANT_ALG_CTR
1805 scripts/config.py unset PSA_WANT_ALG_CFB
1806 scripts/config.py unset PSA_WANT_ALG_OFB
1807 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
1808 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
1809 scripts/config.py unset PSA_WANT_ALG_CMAC
1810 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1811 scripts/config.py unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
Minos Galanakis471b34c2024-07-26 15:39:24 +01001812
1813 # Disable direct dependency on AES_C
1814 scripts/config.py unset MBEDTLS_NIST_KW_C
1815
1816 # Prevent the cipher module from using deprecated PSA path. The reason is
1817 # that otherwise there will be tests relying on "aes_info" (defined in
1818 # "cipher_wrap.c") whose functions are not available when AES_C is
1819 # not defined. ARIA and Camellia are not a problem in this case because
1820 # the PSA path is not tested for these key types.
1821 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1822}
1823
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02001824component_test_full_block_cipher_psa_dispatch_static_keystore () {
1825 msg "build: full + PSA dispatch in block_cipher with static keystore"
1826 # Check that the static key store works well when CTR_DRBG uses a
1827 # PSA key for AES.
1828 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
1829
1830 loc_accel_list="ALG_ECB_NO_PADDING \
1831 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1832
1833 # Configure
1834 # ---------
1835
1836 common_block_cipher_dispatch 1
1837
1838 # Build
1839 # -----
1840
1841 helper_libtestdriver1_make_drivers "$loc_accel_list"
1842
1843 helper_libtestdriver1_make_main "$loc_accel_list"
1844
1845 # Make sure disabled components were not re-enabled by accident (additive
1846 # config)
1847 not grep mbedtls_aes_ library/aes.o
1848 not grep mbedtls_aria_ library/aria.o
1849 not grep mbedtls_camellia_ library/camellia.o
1850
1851 # Run the tests
1852 # -------------
1853
1854 msg "test: full + PSA dispatch in block_cipher with static keystore"
1855 make test
1856}
1857
Minos Galanakis471b34c2024-07-26 15:39:24 +01001858component_test_full_block_cipher_psa_dispatch () {
1859 msg "build: full + PSA dispatch in block_cipher"
1860
1861 loc_accel_list="ALG_ECB_NO_PADDING \
1862 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1863
1864 # Configure
1865 # ---------
1866
1867 common_block_cipher_dispatch 1
1868
1869 # Build
1870 # -----
1871
1872 helper_libtestdriver1_make_drivers "$loc_accel_list"
1873
1874 helper_libtestdriver1_make_main "$loc_accel_list"
1875
1876 # Make sure disabled components were not re-enabled by accident (additive
1877 # config)
1878 not grep mbedtls_aes_ ${BUILTIN_SRC_PATH}/aes.o
1879 not grep mbedtls_aria_ ${BUILTIN_SRC_PATH}/aria.o
1880 not grep mbedtls_camellia_ ${BUILTIN_SRC_PATH}/camellia.o
1881
1882 # Run the tests
1883 # -------------
1884
1885 msg "test: full + PSA dispatch in block_cipher"
1886 make test
1887}
1888
1889# This is the reference component of component_test_full_block_cipher_psa_dispatch
Minos Galanakis471b34c2024-07-26 15:39:24 +01001890component_test_full_block_cipher_legacy_dispatch () {
1891 msg "build: full + legacy dispatch in block_cipher"
1892
1893 common_block_cipher_dispatch 0
1894
1895 make
1896
1897 msg "test: full + legacy dispatch in block_cipher"
1898 make test
1899}
1900
Minos Galanakisf78447f2024-07-26 20:49:51 +01001901component_test_aead_chachapoly_disabled () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001902 msg "build: full minus CHACHAPOLY"
1903 scripts/config.py full
David Horstmannb907dbc2025-08-27 15:19:40 +01001904 scripts/config.py unset PSA_WANT_ALG_CHACHA20_POLY1305
Minos Galanakis471b34c2024-07-26 15:39:24 +01001905 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1906
1907 msg "test: full minus CHACHAPOLY"
1908 make test
1909}
1910
Minos Galanakisf78447f2024-07-26 20:49:51 +01001911component_test_aead_only_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001912 msg "build: full minus CHACHAPOLY and GCM"
1913 scripts/config.py full
David Horstmannb907dbc2025-08-27 15:19:40 +01001914 scripts/config.py unset PSA_WANT_ALG_CHACHA20_POLY1305
1915 scripts/config.py unset PSA_WANT_ALG_GCM
Minos Galanakis471b34c2024-07-26 15:39:24 +01001916 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1917
1918 msg "test: full minus CHACHAPOLY and GCM"
1919 make test
1920}
1921
Minos Galanakisf78447f2024-07-26 20:49:51 +01001922component_test_ccm_aes_sha256 () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001923 msg "build: CCM + AES + SHA256 configuration"
1924
Minos Galanakisa17ffc72024-12-02 23:57:30 +00001925 # Setting a blank config disables everyhing in the library side.
1926 echo '#define MBEDTLS_CONFIG_H ' >"$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001927 cp tf-psa-crypto/configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
Ronald Cron9d262d72024-12-06 17:41:26 +01001928
Minos Galanakis471b34c2024-07-26 15:39:24 +01001929 make
Minos Galanakis471b34c2024-07-26 15:39:24 +01001930 msg "test: CCM + AES + SHA256 configuration"
1931 make test
1932}
1933
1934# Test that the given .o file builds with all (valid) combinations of the given options.
1935#
1936# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
1937#
1938# The validator function is the name of a function to validate the combination of options.
1939# It may be "" if all combinations are valid.
1940# It receives a string containing a combination of options, as passed to the compiler,
1941# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001942build_test_config_combos () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001943 file=$1
1944 shift
1945 validate_options=$1
1946 shift
1947 options=("$@")
1948
1949 # clear all of the options so that they can be overridden on the clang commandline
1950 for opt in "${options[@]}"; do
1951 ./scripts/config.py unset ${opt}
1952 done
1953
1954 # enter the library directory
1955 cd library
1956
1957 # The most common issue is unused variables/functions, so ensure -Wunused is set.
1958 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
1959
1960 # Extract the command generated by the Makefile to build the target file.
1961 # This ensures that we have any include paths, macro definitions, etc
1962 # that may be applied by make.
1963 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
1964 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
1965
1966 makefile=$(TMPDIR=. mktemp)
1967 deps=""
1968
1969 len=${#options[@]}
1970 source_file=../${file%.o}.c
1971
1972 targets=0
1973 echo 'include Makefile' >${makefile}
1974
1975 for ((i = 0; i < $((2**${len})); i++)); do
1976 # generate each of 2^n combinations of options
1977 # each bit of $i is used to determine if options[i] will be set or not
1978 target="t"
1979 clang_args=""
1980 for ((j = 0; j < ${len}; j++)); do
1981 if (((i >> j) & 1)); then
1982 opt=-D${options[$j]}
1983 clang_args="${clang_args} ${opt}"
1984 target="${target}${opt}"
1985 fi
1986 done
1987
1988 # if combination is not known to be invalid, add it to the makefile
1989 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
1990 cmd="${compile_cmd} ${clang_args}"
1991 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
1992
1993 deps="${deps} ${target}"
1994 ((++targets))
1995 fi
1996 done
1997
1998 echo "build_test_config_combos: ${deps}" >> ${makefile}
1999
2000 # execute all of the commands via Make (probably in parallel)
2001 make -s -f ${makefile} build_test_config_combos
2002 echo "$targets targets checked"
2003
2004 # clean up the temporary makefile
2005 rm ${makefile}
2006}
2007
Minos Galanakisf78447f2024-07-26 20:49:51 +01002008validate_aes_config_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002009 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
2010 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
2011 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
2012 return 1
2013 fi
2014 fi
2015 return 0
2016}
2017
Minos Galanakisf78447f2024-07-26 20:49:51 +01002018component_build_aes_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002019 # 18s - around 90ms per clang invocation on M1 Pro
2020 #
2021 # aes.o has many #if defined(...) guards that intersect in complex ways.
2022 # Test that all the combinations build cleanly.
2023
2024 MBEDTLS_ROOT_DIR="$PWD"
2025 msg "build: aes.o for all combinations of relevant config options"
2026
2027 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002028 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002029 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2030 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2031
2032 cd "$MBEDTLS_ROOT_DIR"
2033 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
2034
Ari Weiler-Ofek86422e52025-07-04 14:43:30 +01002035 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW,
Minos Galanakis471b34c2024-07-26 15:39:24 +01002036 # manually set or unset those configurations to check
2037 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
2038 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Minos Galanakis471b34c2024-07-26 15:39:24 +01002039 scripts/config.py unset MBEDTLS_NIST_KW_C
Ronald Cron54d1eec2024-09-06 09:55:38 +02002040
David Horstmann7cbeedc2025-08-26 17:26:45 +01002041 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
2042 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
2043 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
2044 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
Ronald Cron54d1eec2024-09-06 09:55:38 +02002045
Minos Galanakis471b34c2024-07-26 15:39:24 +01002046 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002047 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002048 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2049 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2050}
2051
Minos Galanakisf78447f2024-07-26 20:49:51 +01002052component_test_sha3_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002053 msg "sha3 loop unroll variations"
2054
2055 # define minimal config sufficient to test SHA3
Ronald Crone7f289e2024-09-06 11:02:47 +02002056 cat > include/mbedtls/mbedtls_config.h << END
Ronald Crone7f289e2024-09-06 11:02:47 +02002057END
2058
2059 cat > tf-psa-crypto/include/psa/crypto_config.h << END
2060 #define PSA_WANT_ALG_SHA_256 1
2061 #define PSA_WANT_ALG_SHA3_224 1
2062 #define PSA_WANT_ALG_SHA3_256 1
2063 #define PSA_WANT_ALG_SHA3_384 1
2064 #define PSA_WANT_ALG_SHA3_512 1
Ronald Cron06680362025-07-21 15:21:22 +02002065 #define PSA_WANT_KEY_TYPE_AES 1
Ronald Cron3dd1d3d2024-12-05 15:12:06 +01002066 #define MBEDTLS_PSA_CRYPTO_C
Ronald Cron3b306432025-09-02 18:30:08 +02002067 #define MBEDTLS_CTR_DRBG_C
2068 #define MBEDTLS_PSA_BUILTIN_GET_ENTROPY
Ronald Cron3dd1d3d2024-12-05 15:12:06 +01002069 #define MBEDTLS_SELF_TEST
Minos Galanakis471b34c2024-07-26 15:39:24 +01002070END
2071
2072 msg "all loops unrolled"
2073 make clean
2074 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"
2075 ./tf-psa-crypto/tests/test_suite_shax
2076
2077 msg "all loops rolled up"
2078 make clean
2079 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"
2080 ./tf-psa-crypto/tests/test_suite_shax
2081}
2082
Minos Galanakisf699d512024-08-01 11:32:30 +01002083support_build_aes_aesce_armcc () {
2084 support_build_armcc
2085}
2086
Minos Galanakis471b34c2024-07-26 15:39:24 +01002087# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2088component_build_aes_aesce_armcc () {
2089 msg "Build: AESCE test on arm64 platform without plain C."
2090 scripts/config.py baremetal
2091
2092 # armc[56] don't support SHA-512 intrinsics
2093 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2094
2095 # Stop armclang warning about feature detection for A64_CRYPTO.
2096 # With this enabled, the library does build correctly under armclang,
2097 # but in baremetal builds (as tested here), feature detection is
2098 # unavailable, and the user is notified via a #warning. So enabling
2099 # this feature would prevent us from building with -Werror on
2100 # armclang. Tracked in #7198.
2101 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2102 scripts/config.py set MBEDTLS_HAVE_ASM
2103
2104 msg "AESCE, build with default configuration."
2105 scripts/config.py set MBEDTLS_AESCE_C
2106 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002107 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002108
2109 msg "AESCE, build AESCE only"
2110 scripts/config.py set MBEDTLS_AESCE_C
2111 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002112 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002113}
2114
Minos Galanakis471b34c2024-07-26 15:39:24 +01002115component_test_aes_only_128_bit_keys () {
2116 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2117 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002118 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002119
2120 make CFLAGS='-O2 -Werror -Wall -Wextra'
2121
2122 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2123 make test
2124}
2125
2126component_test_no_ctr_drbg_aes_only_128_bit_keys () {
2127 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2128 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002129 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002130 scripts/config.py unset MBEDTLS_CTR_DRBG_C
2131
2132 make CC=clang CFLAGS='-Werror -Wall -Wextra'
2133
2134 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2135 make test
2136}
2137
2138component_test_aes_only_128_bit_keys_have_builtins () {
2139 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2140 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002141 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002142 scripts/config.py unset MBEDTLS_AESNI_C
2143 scripts/config.py unset MBEDTLS_AESCE_C
2144
2145 make CFLAGS='-O2 -Werror -Wall -Wextra'
2146
2147 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2148 make test
2149
2150 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2151 programs/test/selftest
2152}
2153
2154component_test_gcm_largetable () {
2155 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2156 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
2157 scripts/config.py unset MBEDTLS_AESNI_C
2158 scripts/config.py unset MBEDTLS_AESCE_C
2159
2160 make CFLAGS='-O2 -Werror -Wall -Wextra'
2161
2162 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2163 make test
2164}
2165
2166component_test_aes_fewer_tables () {
2167 msg "build: default config with AES_FEWER_TABLES enabled"
2168 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2169 make CFLAGS='-O2 -Werror -Wall -Wextra'
2170
2171 msg "test: AES_FEWER_TABLES"
2172 make test
2173}
2174
2175component_test_aes_rom_tables () {
2176 msg "build: default config with AES_ROM_TABLES enabled"
2177 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2178 make CFLAGS='-O2 -Werror -Wall -Wextra'
2179
2180 msg "test: AES_ROM_TABLES"
2181 make test
2182}
2183
2184component_test_aes_fewer_tables_and_rom_tables () {
2185 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
2186 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2187 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2188 make CFLAGS='-O2 -Werror -Wall -Wextra'
2189
2190 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2191 make test
2192}
2193
Ronald Cron66040472024-09-06 10:14:38 +02002194# helper for component_test_block_cipher_no_decrypt_aesni() which:
Minos Galanakis471b34c2024-07-26 15:39:24 +01002195# - enable/disable the list of config options passed from -s/-u respectively.
2196# - build
2197# - test for tests_suite_xxx
2198# - selftest
2199#
2200# Usage: helper_block_cipher_no_decrypt_build_test
2201# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
2202# Options: -s set_opts the list of config options to enable
2203# -u unset_opts the list of config options to disable
2204# -c cflags the list of options passed to CFLAGS
2205# -l ldflags the list of options passed to LDFLAGS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002206helper_block_cipher_no_decrypt_build_test () {
2207 while [ $# -gt 0 ]; do
2208 case "$1" in
2209 -s)
2210 shift; local set_opts="$1";;
2211 -u)
2212 shift; local unset_opts="$1";;
2213 -c)
2214 shift; local cflags="-Werror -Wall -Wextra $1";;
2215 -l)
2216 shift; local ldflags="$1";;
2217 esac
2218 shift
2219 done
2220 set_opts="${set_opts:-}"
2221 unset_opts="${unset_opts:-}"
2222 cflags="${cflags:-}"
2223 ldflags="${ldflags:-}"
2224
2225 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
2226 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
2227
2228 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2229 make clean
2230 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
2231
2232 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2233 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2234 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2235 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2236 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2237 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2238 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
2239 not grep mbedtls_aesni_inverse_key ${BUILTIN_SRC_PATH}/aesni.o
2240
2241 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2242 make test
2243
2244 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2245 programs/test/selftest
2246}
2247
Ronald Cron66040472024-09-06 10:14:38 +02002248# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
2249config_block_cipher_no_decrypt () {
2250 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Ronald Cron66040472024-09-06 10:14:38 +02002251 scripts/config.py unset MBEDTLS_NIST_KW_C
2252
2253 # Enable support for cryptographic mechanisms through the PSA API.
2254 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
David Horstmannb907dbc2025-08-27 15:19:40 +01002255 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
2256 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
2257 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
2258 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
Ronald Cron66040472024-09-06 10:14:38 +02002259}
2260
2261component_test_block_cipher_no_decrypt_aesni () {
2262 # Test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics, AESNI assembly and
2263 # AES C implementation on x86_64 and with AESNI intrinsics on x86.
2264
2265 # This consistently causes an llvm crash on clang 3.8, so use gcc
2266 export CC=gcc
2267 config_block_cipher_no_decrypt
2268
Minos Galanakis471b34c2024-07-26 15:39:24 +01002269 # test AESNI intrinsics
2270 helper_block_cipher_no_decrypt_build_test \
2271 -s "MBEDTLS_AESNI_C" \
2272 -c "-mpclmul -msse2 -maes"
2273
2274 # test AESNI assembly
2275 helper_block_cipher_no_decrypt_build_test \
2276 -s "MBEDTLS_AESNI_C" \
2277 -c "-mno-pclmul -mno-sse2 -mno-aes"
2278
2279 # test AES C implementation
2280 helper_block_cipher_no_decrypt_build_test \
2281 -u "MBEDTLS_AESNI_C"
2282
2283 # test AESNI intrinsics for i386 target
2284 helper_block_cipher_no_decrypt_build_test \
2285 -s "MBEDTLS_AESNI_C" \
2286 -c "-m32 -mpclmul -msse2 -maes" \
2287 -l "-m32"
2288}
2289
Minos Galanakisf699d512024-08-01 11:32:30 +01002290support_test_block_cipher_no_decrypt_aesce_armcc () {
2291 support_build_armcc
2292}
2293
Minos Galanakis471b34c2024-07-26 15:39:24 +01002294component_test_block_cipher_no_decrypt_aesce_armcc () {
2295 scripts/config.py baremetal
2296
2297 # armc[56] don't support SHA-512 intrinsics
2298 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2299
2300 # Stop armclang warning about feature detection for A64_CRYPTO.
2301 # With this enabled, the library does build correctly under armclang,
2302 # but in baremetal builds (as tested here), feature detection is
2303 # unavailable, and the user is notified via a #warning. So enabling
2304 # this feature would prevent us from building with -Werror on
2305 # armclang. Tracked in #7198.
2306 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2307 scripts/config.py set MBEDTLS_HAVE_ASM
2308
Ronald Cron66040472024-09-06 10:14:38 +02002309 config_block_cipher_no_decrypt
Minos Galanakis471b34c2024-07-26 15:39:24 +01002310
2311 # test AESCE baremetal build
2312 scripts/config.py set MBEDTLS_AESCE_C
2313 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002314 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002315
2316 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2317 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2318 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2319 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2320 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2321 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2322 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
2323 not grep mbedtls_aesce_inverse_key ${BUILTIN_SRC_PATH}/aesce.o
2324 not grep aesce_decrypt_block ${BUILTIN_SRC_PATH}/aesce.o
2325}
2326
Ronald Cronaad5f1b2025-08-25 15:32:48 +02002327component_test_ctr_drbg_aes_256_sha_512 () {
2328 msg "build: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512 (ASan build)"
2329 scripts/config.py full
2330 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2331 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512
2332 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2333 make
2334
2335 msg "test: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512 (ASan build)"
2336 make test
2337}
2338
Minos Galanakis471b34c2024-07-26 15:39:24 +01002339component_test_ctr_drbg_aes_256_sha_256 () {
Minos Galanakisf3486e12025-08-18 14:09:26 +01002340 msg "build: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002341 scripts/config.py full
2342 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakisf3486e12025-08-18 14:09:26 +01002343 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256
Minos Galanakis471b34c2024-07-26 15:39:24 +01002344 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2345 make
2346
Minos Galanakisf3486e12025-08-18 14:09:26 +01002347 msg "test: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002348 make test
2349}
2350
2351component_test_ctr_drbg_aes_128_sha_512 () {
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002352 msg "build: full + set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002353 scripts/config.py full
2354 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002355 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Ronald Cronaad5f1b2025-08-25 15:32:48 +02002356 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512
Minos Galanakis471b34c2024-07-26 15:39:24 +01002357 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2358 make
2359
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002360 msg "test: full + set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002361 make test
2362}
2363
2364component_test_ctr_drbg_aes_128_sha_256 () {
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002365 msg "build: full + set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128 + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002366 scripts/config.py full
2367 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002368 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakisf3486e12025-08-18 14:09:26 +01002369 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256
Minos Galanakis471b34c2024-07-26 15:39:24 +01002370 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2371 make
2372
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002373 msg "test: full + set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128 + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002374 make test
2375}
2376
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002377component_test_full_static_keystore () {
2378 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2379 scripts/config.py full
2380 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2381 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
2382
2383 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2384 make test
2385}
2386
Minos Galanakis471b34c2024-07-26 15:39:24 +01002387component_test_psa_crypto_drivers () {
Ronald Crona0afbfb2024-10-15 13:20:31 +02002388 # Test dispatch to drivers and fallbacks with
2389 # test_suite_psa_crypto_driver_wrappers test suite. The test drivers that
2390 # are wrappers around the builtin drivers are activated by
2391 # PSA_CRYPTO_DRIVER_TEST.
2392 #
2393 # For the time being, some test cases in test_suite_block_cipher and
2394 # test_suite_md.psa rely on this component to be run at least once by the
2395 # CI. This should disappear as we progress the 4.x work. See
2396 # config_adjust_test_accelerators.h for more information.
Minos Galanakis471b34c2024-07-26 15:39:24 +01002397 msg "build: full + test drivers dispatching to builtins"
2398 scripts/config.py full
Ronald Cron67cc6a72024-10-14 10:55:24 +02002399 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_CONFIG_ADJUST_TEST_ACCELERATORS"
David Horstmann5b93d972024-10-31 15:36:05 +00002400 loc_cflags="${loc_cflags} -I../framework/tests/include"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002401
2402 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
2403
2404 msg "test: full + test drivers dispatching to builtins"
2405 make test
2406}
2407
2408component_build_psa_config_file () {
Minos Galanakis4f619e12024-11-14 14:56:47 +00002409 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002410 cp "$CRYPTO_CONFIG_H" psa_test_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002411 echo '#error "TF_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
2412 make CFLAGS="-I '$PWD' -DTF_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002413 # Make sure this feature is enabled. We'll disable it in the next phase.
Ronald Cron3f120062025-07-03 14:45:51 +02002414 programs/test/query_compile_time_config PSA_WANT_ALG_CMAC
Minos Galanakis471b34c2024-07-26 15:39:24 +01002415 make clean
2416
Minos Galanakis4f619e12024-11-14 14:56:47 +00002417 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE + TF_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002418 # In the user config, disable one feature and its dependencies, which will
2419 # reflect on the mbedtls configuration so we can query it with
2420 # query_compile_time_config.
2421 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
2422 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002423 make CFLAGS="-I '$PWD' -DTF_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DTF_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
Ronald Cron3f120062025-07-03 14:45:51 +02002424 not programs/test/query_compile_time_config PSA_WANT_ALG_CMAC
Minos Galanakis471b34c2024-07-26 15:39:24 +01002425
2426 rm -f psa_test_config.h psa_user_config.h
2427}
2428
2429component_build_psa_alt_headers () {
2430 msg "build: make with PSA alt headers" # ~20s
2431
2432 # Generate alternative versions of the substitutable headers with the
2433 # same content except different include guards.
David Horstmanndc459512024-11-07 17:08:11 +00002434 make -C tests ../framework/tests/include/alt-extra/psa/crypto_platform_alt.h ../framework/tests/include/alt-extra/psa/crypto_struct_alt.h
Minos Galanakis471b34c2024-07-26 15:39:24 +01002435
2436 # Build the library and some programs.
2437 # Don't build the fuzzers to avoid having to go through hoops to set
2438 # a correct include path for programs/fuzz/Makefile.
David Horstmann5b93d972024-10-31 15:36:05 +00002439 make CFLAGS="-I ../framework/tests/include/alt-extra -DMBEDTLS_PSA_CRYPTO_PLATFORM_FILE='\"psa/crypto_platform_alt.h\"' -DMBEDTLS_PSA_CRYPTO_STRUCT_FILE='\"psa/crypto_struct_alt.h\"'" lib
2440 make -C programs -o fuzz CFLAGS="-I ../framework/tests/include/alt-extra -DMBEDTLS_PSA_CRYPTO_PLATFORM_FILE='\"psa/crypto_platform_alt.h\"' -DMBEDTLS_PSA_CRYPTO_STRUCT_FILE='\"psa/crypto_struct_alt.h\"'"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002441
2442 # Check that we're getting the alternative include guards and not the
2443 # original include guards.
2444 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
2445 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
2446 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
2447 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
2448}
2449
2450component_test_min_mpi_window_size () {
2451 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
2452 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
2453 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2454 make
2455
2456 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2457 make test
2458}
Ronald Cronf256f8a2025-07-10 17:37:18 +02002459
2460component_test_xts () {
2461 # Component dedicated to run XTS unit test cases while XTS is not
2462 # supported through the PSA API.
2463 msg "build: Default + MBEDTLS_CIPHER_MODE_XTS"
2464
2465 echo "#define MBEDTLS_CIPHER_MODE_XTS" > psa_user_config.h
2466 cmake -DTF_PSA_CRYPTO_USER_CONFIG_FILE="psa_user_config.h"
2467 make
2468
Ronald Crone0b06eb2025-07-15 08:58:32 +02002469 rm -f psa_user_config.h
2470
Ronald Cronf256f8a2025-07-10 17:37:18 +02002471 msg "test: Default + MBEDTLS_CIPHER_MODE_XTS"
2472 make test
Ronald Cronf256f8a2025-07-10 17:37:18 +02002473}