blob: 05c480675ce0d3ac33d2f752922cb069257c4c96 [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
Ben Taylor59213b62025-08-14 10:01:06 +0100433component_test_everest_curve25519_only () {
434 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
435 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
436 scripts/config.py unset MBEDTLS_ECDSA_C
437 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
438 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECDSA
439 scripts/config.py -c $CRYPTO_CONFIG_H set PSA_WANT_ALG_ECDH
440 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
441 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
442 scripts/config.py unset MBEDTLS_ECJPAKE_C
443 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE
444
445 # Disable all curves
446 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
447 scripts/config.py -c $CRYPTO_CONFIG_H unset-all "PSA_WANT_ECC_[0-9A-Z_a-z]*$"
448 scripts/config.py -c $CRYPTO_CONFIG_H set PSA_WANT_ECC_MONTGOMERY_255
449
450 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
451
452 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
453 make test
454}
455
Minos Galanakis471b34c2024-07-26 15:39:24 +0100456component_test_psa_collect_statuses () {
457 msg "build+test: psa_collect_statuses" # ~30s
458 scripts/config.py full
459 tests/scripts/psa_collect_statuses.py
460 # Check that psa_crypto_init() succeeded at least once
461 grep -q '^0:psa_crypto_init:' tests/statuses.log
462 rm -f tests/statuses.log
463}
464
465# Check that the specified libraries exist and are empty.
466are_empty_libraries () {
467 nm "$@" >/dev/null 2>/dev/null
468 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
469}
470
Minos Galanakis471b34c2024-07-26 15:39:24 +0100471component_test_crypto_for_psa_service () {
472 msg "build: make, config for PSA crypto service"
473 scripts/config.py crypto
474 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
475 # Disable things that are not needed for just cryptography, to
476 # reach a configuration that would be typical for a PSA cryptography
477 # service providing all implemented PSA algorithms.
478 # System stuff
479 scripts/config.py unset MBEDTLS_ERROR_C
480 scripts/config.py unset MBEDTLS_TIMING_C
481 scripts/config.py unset MBEDTLS_VERSION_FEATURES
482 # Crypto stuff with no PSA interface
483 scripts/config.py unset MBEDTLS_BASE64_C
Minos Galanakis471b34c2024-07-26 15:39:24 +0100484 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
485 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
486 scripts/config.py unset MBEDTLS_NIST_KW_C
487 scripts/config.py unset MBEDTLS_PEM_PARSE_C
488 scripts/config.py unset MBEDTLS_PEM_WRITE_C
489 scripts/config.py unset MBEDTLS_PKCS12_C
490 scripts/config.py unset MBEDTLS_PKCS5_C
491 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
492 # in PSA code to work with RSA keys. We don't require users to set those:
493 # they will be reenabled in build_info.h.
494 scripts/config.py unset MBEDTLS_PK_C
495 scripts/config.py unset MBEDTLS_PK_PARSE_C
496 scripts/config.py unset MBEDTLS_PK_WRITE_C
497 make CFLAGS='-O1 -Werror' all test
498 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
499}
500
501component_build_crypto_baremetal () {
502 msg "build: make, crypto only, baremetal config"
503 scripts/config.py crypto_baremetal
David Horstmann5b93d972024-10-31 15:36:05 +0000504 make CFLAGS="-O1 -Werror -I$PWD/framework/tests/include/baremetal-override/"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100505 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
506}
507
508support_build_crypto_baremetal () {
509 support_build_baremetal "$@"
510}
511
512# depends.py family of tests
513component_test_depends_py_cipher_id () {
514 msg "test/build: depends.py cipher_id (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200515 tests/scripts/depends.py cipher_id
Minos Galanakis471b34c2024-07-26 15:39:24 +0100516}
517
518component_test_depends_py_cipher_chaining () {
519 msg "test/build: depends.py cipher_chaining (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200520 tests/scripts/depends.py cipher_chaining
Minos Galanakis471b34c2024-07-26 15:39:24 +0100521}
522
Minos Galanakis471b34c2024-07-26 15:39:24 +0100523component_test_depends_py_curves () {
524 msg "test/build: depends.py curves (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200525 tests/scripts/depends.py curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100526}
527
528component_test_depends_py_hashes () {
529 msg "test/build: depends.py hashes (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200530 tests/scripts/depends.py hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +0100531}
532
Minos Galanakis471b34c2024-07-26 15:39:24 +0100533component_test_depends_py_pkalgs () {
534 msg "test/build: depends.py pkalgs (gcc)"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100535 tests/scripts/depends.py pkalgs
536}
537
538component_test_psa_crypto_config_ffdh_2048_only () {
539 msg "build: full config - only DH 2048"
540
541 scripts/config.py full
542
543 # Disable all DH groups other than 2048.
David Horstmannb907dbc2025-08-27 15:19:40 +0100544 scripts/config.py unset PSA_WANT_DH_RFC7919_3072
545 scripts/config.py unset PSA_WANT_DH_RFC7919_4096
546 scripts/config.py unset PSA_WANT_DH_RFC7919_6144
547 scripts/config.py unset PSA_WANT_DH_RFC7919_8192
Minos Galanakis471b34c2024-07-26 15:39:24 +0100548
549 make CFLAGS="$ASAN_CFLAGS -Werror" LDFLAGS="$ASAN_CFLAGS"
550
551 msg "test: full config - only DH 2048"
552 make test
553
554 msg "ssl-opt: full config - only DH 2048"
555 tests/ssl-opt.sh -f "ffdh"
556}
557
Minos Galanakis471b34c2024-07-26 15:39:24 +0100558component_test_psa_crypto_config_accel_ecdsa () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200559 msg "build: accelerated ECDSA"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100560
Minos Galanakis471b34c2024-07-26 15:39:24 +0100561 # Configure
562 # ---------
563
Elena Uziunaite91d83862024-09-04 14:51:31 +0100564 # Start from default config + TLS 1.3
Minos Galanakis471b34c2024-07-26 15:39:24 +0100565 helper_libtestdriver1_adjust_config "default"
566
Valerio Setti37a42812025-08-11 12:52:49 +0200567 # Algorithms and key types to accelerate
568 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
569 $(helper_get_psa_key_type_list "ECC") \
570 $(helper_get_psa_curve_list)"
571
Minos Galanakis471b34c2024-07-26 15:39:24 +0100572 # Disable the module that's accelerated
573 scripts/config.py unset MBEDTLS_ECDSA_C
574
575 # Disable things that depend on it
576 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +0100577
578 # Build
579 # -----
580
581 # These hashes are needed for some ECDSA signature tests.
Elena Uziunaiteffce45c2024-09-12 14:58:52 +0100582 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 +0100583 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
584
585 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
586
587 helper_libtestdriver1_make_main "$loc_accel_list"
588
589 # Make sure this was not re-enabled by accident (additive config)
590 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
591
592 # Run the tests
593 # -------------
594
Ronald Cron93ba6252024-09-05 10:37:14 +0200595 msg "test: accelerated ECDSA"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100596 make test
597}
598
599component_test_psa_crypto_config_accel_ecdh () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200600 msg "build: accelerated ECDH"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100601
Minos Galanakis471b34c2024-07-26 15:39:24 +0100602 # Configure
603 # ---------
604
605 # Start from default config (no USE_PSA)
606 helper_libtestdriver1_adjust_config "default"
607
Valerio Setti37a42812025-08-11 12:52:49 +0200608 # Algorithms and key types to accelerate
609 loc_accel_list="ALG_ECDH \
610 $(helper_get_psa_key_type_list "ECC") \
611 $(helper_get_psa_curve_list)"
612
Minos Galanakis471b34c2024-07-26 15:39:24 +0100613 # Disable the module that's accelerated
614 scripts/config.py unset MBEDTLS_ECDH_C
615
616 # Disable things that depend on it
Minos Galanakis471b34c2024-07-26 15:39:24 +0100617 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
618 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
619 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
620
621 # Build
622 # -----
623
624 helper_libtestdriver1_make_drivers "$loc_accel_list"
625
626 helper_libtestdriver1_make_main "$loc_accel_list"
627
628 # Make sure this was not re-enabled by accident (additive config)
629 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
630
631 # Run the tests
632 # -------------
633
Ronald Cron93ba6252024-09-05 10:37:14 +0200634 msg "test: accelerated ECDH"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100635 make test
636}
637
638component_test_psa_crypto_config_accel_ffdh () {
639 msg "build: full with accelerated FFDH"
640
Minos Galanakis471b34c2024-07-26 15:39:24 +0100641 # Configure
642 # ---------
643
644 # start with full (USE_PSA and TLS 1.3)
645 helper_libtestdriver1_adjust_config "full"
646
Valerio Setti37a42812025-08-11 12:52:49 +0200647 # Algorithms and key types to accelerate
648 loc_accel_list="ALG_FFDH \
649 $(helper_get_psa_key_type_list "DH") \
650 $(helper_get_psa_dh_group_list)"
651
Minos Galanakis471b34c2024-07-26 15:39:24 +0100652 # Build
653 # -----
654
655 helper_libtestdriver1_make_drivers "$loc_accel_list"
656
657 helper_libtestdriver1_make_main "$loc_accel_list"
658
659 # Make sure this was not re-enabled by accident (additive config)
Valerio Settieb63eb22025-02-12 13:32:49 +0100660 not grep mbedtls_psa_ffdh_key_agreement ${BUILTIN_SRC_PATH}/psa_crypto_ffdh.o
Minos Galanakis471b34c2024-07-26 15:39:24 +0100661
662 # Run the tests
663 # -------------
664
665 msg "test: full with accelerated FFDH"
666 make test
667
668 msg "ssl-opt: full with accelerated FFDH alg"
669 tests/ssl-opt.sh -f "ffdh"
670}
671
672component_test_psa_crypto_config_reference_ffdh () {
673 msg "build: full with non-accelerated FFDH"
674
675 # Start with full (USE_PSA and TLS 1.3)
676 helper_libtestdriver1_adjust_config "full"
677
Minos Galanakis471b34c2024-07-26 15:39:24 +0100678 make
679
680 msg "test suites: full with non-accelerated FFDH alg"
681 make test
682
683 msg "ssl-opt: full with non-accelerated FFDH alg"
684 tests/ssl-opt.sh -f "ffdh"
685}
686
Minos Galanakisf78447f2024-07-26 20:49:51 +0100687component_test_psa_crypto_config_accel_pake () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100688 msg "build: full with accelerated PAKE"
689
Minos Galanakis471b34c2024-07-26 15:39:24 +0100690 # Configure
691 # ---------
692
693 helper_libtestdriver1_adjust_config "full"
694
Valerio Setti37a42812025-08-11 12:52:49 +0200695 loc_accel_list="ALG_JPAKE \
696 $(helper_get_psa_key_type_list "ECC") \
697 $(helper_get_psa_curve_list)"
698
Minos Galanakis471b34c2024-07-26 15:39:24 +0100699 # Make built-in fallback not available
700 scripts/config.py unset MBEDTLS_ECJPAKE_C
701 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
702
703 # Build
704 # -----
705
706 helper_libtestdriver1_make_drivers "$loc_accel_list"
707
708 helper_libtestdriver1_make_main "$loc_accel_list"
709
710 # Make sure this was not re-enabled by accident (additive config)
711 not grep mbedtls_ecjpake_init ${BUILTIN_SRC_PATH}/ecjpake.o
712
713 # Run the tests
714 # -------------
715
716 msg "test: full with accelerated PAKE"
717 make test
718}
719
720component_test_psa_crypto_config_accel_ecc_some_key_types () {
721 msg "build: full with accelerated EC algs and some key types"
722
Valerio Setti37a42812025-08-11 12:52:49 +0200723 # Configure
724 # ---------
725
726 # start with config full for maximum coverage (also enables USE_PSA)
727 helper_libtestdriver1_adjust_config "full"
728
Minos Galanakis471b34c2024-07-26 15:39:24 +0100729 # Algorithms and key types to accelerate
730 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
731 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
732 ALG_ECDH \
733 ALG_JPAKE \
734 KEY_TYPE_ECC_PUBLIC_KEY \
735 KEY_TYPE_ECC_KEY_PAIR_BASIC \
736 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
737 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
738 $(helper_get_psa_curve_list)"
739
Minos Galanakis471b34c2024-07-26 15:39:24 +0100740 # Disable modules that are accelerated - some will be re-enabled
741 scripts/config.py unset MBEDTLS_ECDSA_C
742 scripts/config.py unset MBEDTLS_ECDH_C
743 scripts/config.py unset MBEDTLS_ECJPAKE_C
744 scripts/config.py unset MBEDTLS_ECP_C
745
746 # Disable all curves - those that aren't accelerated should be re-enabled
747 helper_disable_builtin_curves
748
749 # Restartable feature is not yet supported by PSA. Once it will in
750 # the future, the following line could be removed (see issues
751 # 6061, 6332 and following ones)
752 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
753
754 # this is not supported by the driver API yet
David Horstmannb907dbc2025-08-27 15:19:40 +0100755 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +0100756
757 # Build
758 # -----
759
760 # These hashes are needed for some ECDSA signature tests.
761 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
762 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
763 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
764
765 helper_libtestdriver1_make_main "$loc_accel_list"
766
767 # ECP should be re-enabled but not the others
768 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
769 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
770 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
771 grep mbedtls_ecp ${BUILTIN_SRC_PATH}/ecp.o
772
773 # Run the tests
774 # -------------
775
776 msg "test suites: full with accelerated EC algs and some key types"
777 make test
778}
779
780# Run tests with only (non-)Weierstrass accelerated
781# Common code used in:
782# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
783# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100784common_test_psa_crypto_config_accel_ecc_some_curves () {
785 weierstrass=$1
786 if [ $weierstrass -eq 1 ]; then
787 desc="Weierstrass"
788 else
789 desc="non-Weierstrass"
790 fi
791
792 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
793
Valerio Setti37a42812025-08-11 12:52:49 +0200794 # Configure
795 # ---------
796
797 # Start with config crypto_full and remove PK_C:
798 # that's what's supported now, see docs/driver-only-builds.md.
799 helper_libtestdriver1_adjust_config "crypto_full"
800 scripts/config.py unset MBEDTLS_PK_C
801 scripts/config.py unset MBEDTLS_PK_PARSE_C
802 scripts/config.py unset MBEDTLS_PK_WRITE_C
803
804 # Disable modules that are accelerated - some will be re-enabled
805 scripts/config.py unset MBEDTLS_ECDSA_C
806 scripts/config.py unset MBEDTLS_ECDH_C
807 scripts/config.py unset MBEDTLS_ECJPAKE_C
808 scripts/config.py unset MBEDTLS_ECP_C
809
810 # Disable all curves - those that aren't accelerated should be re-enabled
811 helper_disable_builtin_curves
812
Valerio Setti981a0c42025-08-12 11:31:11 +0200813 # Note: Curves are handled in a special way by the libtestdriver machinery,
Minos Galanakis471b34c2024-07-26 15:39:24 +0100814 # so we only want to include them in the accel list when building the main
815 # libraries, hence the use of a separate variable.
816 # Note: the following loop is a modified version of
817 # helper_get_psa_curve_list that only keeps Weierstrass families.
818 loc_weierstrass_list=""
819 loc_non_weierstrass_list=""
820 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
821 case $item in
822 ECC_BRAINPOOL*|ECC_SECP*)
823 loc_weierstrass_list="$loc_weierstrass_list $item"
824 ;;
825 *)
826 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
827 ;;
828 esac
829 done
830 if [ $weierstrass -eq 1 ]; then
831 loc_curve_list=$loc_weierstrass_list
832 else
833 loc_curve_list=$loc_non_weierstrass_list
834 fi
835
836 # Algorithms and key types to accelerate
837 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
838 ALG_ECDH \
839 ALG_JPAKE \
840 $(helper_get_psa_key_type_list "ECC") \
841 $loc_curve_list"
842
Minos Galanakis471b34c2024-07-26 15:39:24 +0100843 # Restartable feature is not yet supported by PSA. Once it will in
844 # the future, the following line could be removed (see issues
845 # 6061, 6332 and following ones)
846 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
847
848 # this is not supported by the driver API yet
David Horstmannb907dbc2025-08-27 15:19:40 +0100849 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +0100850
851 # Build
852 # -----
853
854 # These hashes are needed for some ECDSA signature tests.
855 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
856 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
857 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
858
859 helper_libtestdriver1_make_main "$loc_accel_list"
860
861 # We expect ECDH to be re-enabled for the missing curves
862 grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
863 # We expect ECP to be re-enabled, however the parts specific to the
864 # families of curves that are accelerated should be ommited.
865 # - functions with mxz in the name are specific to Montgomery curves
866 # - ecp_muladd is specific to Weierstrass curves
867 ##nm ${BUILTIN_SRC_PATH}/ecp.o | tee ecp.syms
868 if [ $weierstrass -eq 1 ]; then
869 not grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
870 grep mxz ${BUILTIN_SRC_PATH}/ecp.o
871 else
872 grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
873 not grep mxz ${BUILTIN_SRC_PATH}/ecp.o
874 fi
875 # We expect ECDSA and ECJPAKE to be re-enabled only when
876 # Weierstrass curves are not accelerated
877 if [ $weierstrass -eq 1 ]; then
878 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
879 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
880 else
881 grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
882 grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
883 fi
884
885 # Run the tests
886 # -------------
887
888 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
Valerio Setti981a0c42025-08-12 11:31:11 +0200889 make test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100890}
891
892component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
893 common_test_psa_crypto_config_accel_ecc_some_curves 1
894}
895
896component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
897 common_test_psa_crypto_config_accel_ecc_some_curves 0
898}
899
900# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
901# ECDH, ECDSA) with and without drivers.
902# The input parameter is a boolean value which indicates:
903# - 0 keep built-in EC algs,
904# - 1 exclude built-in EC algs (driver only).
905#
906# This is used by the two following components to ensure they always use the
907# same config, except for the use of driver or built-in EC algorithms:
908# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
909# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
910# This supports comparing their test coverage with analyze_outcomes.py.
Minos Galanakis471b34c2024-07-26 15:39:24 +0100911config_psa_crypto_config_ecp_light_only () {
912 driver_only="$1"
913 # start with config full for maximum coverage (also enables USE_PSA)
914 helper_libtestdriver1_adjust_config "full"
915 if [ "$driver_only" -eq 1 ]; then
916 # Disable modules that are accelerated
917 scripts/config.py unset MBEDTLS_ECDSA_C
918 scripts/config.py unset MBEDTLS_ECDH_C
919 scripts/config.py unset MBEDTLS_ECJPAKE_C
920 scripts/config.py unset MBEDTLS_ECP_C
921 fi
922
923 # Restartable feature is not yet supported by PSA. Once it will in
924 # the future, the following line could be removed (see issues
925 # 6061, 6332 and following ones)
926 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
927}
928
929# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100930component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
931 msg "build: full with accelerated EC algs"
932
Valerio Setti37a42812025-08-11 12:52:49 +0200933 # Configure
934 # ---------
935
936 # Use the same config as reference, only without built-in EC algs
937 config_psa_crypto_config_ecp_light_only 1
938
Minos Galanakis471b34c2024-07-26 15:39:24 +0100939 # Algorithms and key types to accelerate
940 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
941 ALG_ECDH \
942 ALG_JPAKE \
943 $(helper_get_psa_key_type_list "ECC") \
944 $(helper_get_psa_curve_list)"
945
Minos Galanakis471b34c2024-07-26 15:39:24 +0100946 # Do not disable builtin curves because that support is required for:
947 # - MBEDTLS_PK_PARSE_EC_EXTENDED
948 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
949
950 # Build
951 # -----
952
953 # These hashes are needed for some ECDSA signature tests.
954 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
955 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
956 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
957
958 helper_libtestdriver1_make_main "$loc_accel_list"
959
960 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
961 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
962 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
963 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
964 not grep mbedtls_ecp_mul ${BUILTIN_SRC_PATH}/ecp.o
965
966 # Run the tests
967 # -------------
968
969 msg "test suites: full with accelerated EC algs"
970 make test
971
972 msg "ssl-opt: full with accelerated EC algs"
973 tests/ssl-opt.sh
974}
975
976# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100977component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200978 msg "build: non-accelerated EC algs"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100979
980 config_psa_crypto_config_ecp_light_only 0
981
982 make
983
984 msg "test suites: full with non-accelerated EC algs"
985 make test
986
987 msg "ssl-opt: full with non-accelerated EC algs"
988 tests/ssl-opt.sh
989}
990
991# This helper function is used by:
992# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
993# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
994# to ensure that both tests use the same underlying configuration when testing
995# driver's coverage with analyze_outcomes.py.
996#
997# This functions accepts 1 boolean parameter as follows:
998# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
999# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
1000# - 0: include built-in implementation of EC algorithms.
1001#
1002# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
1003# on the ECP module.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001004config_psa_crypto_no_ecp_at_all () {
1005 driver_only="$1"
1006 # start with full config for maximum coverage (also enables USE_PSA)
1007 helper_libtestdriver1_adjust_config "full"
1008
1009 if [ "$driver_only" -eq 1 ]; then
1010 # Disable modules that are accelerated
1011 scripts/config.py unset MBEDTLS_ECDSA_C
1012 scripts/config.py unset MBEDTLS_ECDH_C
1013 scripts/config.py unset MBEDTLS_ECJPAKE_C
1014 # Disable ECP module (entirely)
1015 scripts/config.py unset MBEDTLS_ECP_C
1016 fi
1017
1018 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1019 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1020 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
David Horstmannb907dbc2025-08-27 15:19:40 +01001021 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +01001022
1023 # Restartable feature is not yet supported by PSA. Once it will in
1024 # the future, the following line could be removed (see issues
1025 # 6061, 6332 and following ones)
1026 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1027}
1028
1029# Build and test a configuration where driver accelerates all EC algs while
1030# all support and dependencies from ECP and ECP_LIGHT are removed on the library
1031# side.
1032#
1033# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001034component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
1035 msg "build: full + accelerated EC algs - ECP"
1036
Minos Galanakis471b34c2024-07-26 15:39:24 +01001037 # Configure
1038 # ---------
1039
1040 # Set common configurations between library's and driver's builds
1041 config_psa_crypto_no_ecp_at_all 1
1042 # Disable all the builtin curves. All the required algs are accelerated.
1043 helper_disable_builtin_curves
1044
Valerio Setti37a42812025-08-11 12:52:49 +02001045 # Algorithms and key types to accelerate
1046 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1047 ALG_ECDH \
1048 ALG_JPAKE \
1049 $(helper_get_psa_key_type_list "ECC") \
1050 $(helper_get_psa_curve_list)"
1051
Minos Galanakis471b34c2024-07-26 15:39:24 +01001052 # Build
1053 # -----
1054
1055 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1056 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1057 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1058 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1059
1060 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1061
1062 helper_libtestdriver1_make_main "$loc_accel_list"
1063
1064 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1065 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1066 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1067 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1068 # Also ensure that ECP module was not re-enabled
1069 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1070
1071 # Run the tests
1072 # -------------
1073
1074 msg "test: full + accelerated EC algs - ECP"
1075 make test
1076
1077 msg "ssl-opt: full + accelerated EC algs - ECP"
1078 tests/ssl-opt.sh
1079}
1080
1081# Reference function used for driver's coverage analysis in analyze_outcomes.py
1082# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
1083# Keep in sync with its accelerated counterpart.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001084component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
1085 msg "build: full + non accelerated EC algs"
1086
1087 config_psa_crypto_no_ecp_at_all 0
1088
1089 make
1090
1091 msg "test: full + non accelerated EC algs"
1092 make test
1093
1094 msg "ssl-opt: full + non accelerated EC algs"
1095 tests/ssl-opt.sh
1096}
1097
1098# This is a common configuration helper used directly from:
1099# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1100# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1101# and indirectly from:
1102# - component_test_psa_crypto_config_accel_ecc_no_bignum
1103# - accelerate all EC algs, disable RSA and FFDH
1104# - component_test_psa_crypto_config_reference_ecc_no_bignum
1105# - this is the reference component of the above
1106# - it still disables RSA and FFDH, but it uses builtin EC algs
1107# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1108# - accelerate all EC and FFDH algs, disable only RSA
1109# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1110# - this is the reference component of the above
1111# - it still disables RSA, but it uses builtin EC and FFDH algs
1112#
1113# This function accepts 2 parameters:
1114# $1: a boolean value which states if we are testing an accelerated scenario
1115# or not.
1116# $2: a string value which states which components are tested. Allowed values
1117# are "ECC" or "ECC_DH".
Minos Galanakisf78447f2024-07-26 20:49:51 +01001118config_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001119 driver_only="$1"
1120 test_target="$2"
1121 # start with full config for maximum coverage (also enables USE_PSA)
1122 helper_libtestdriver1_adjust_config "full"
1123
1124 if [ "$driver_only" -eq 1 ]; then
1125 # Disable modules that are accelerated
1126 scripts/config.py unset MBEDTLS_ECDSA_C
1127 scripts/config.py unset MBEDTLS_ECDH_C
1128 scripts/config.py unset MBEDTLS_ECJPAKE_C
1129 # Disable ECP module (entirely)
1130 scripts/config.py unset MBEDTLS_ECP_C
1131 # Also disable bignum
1132 scripts/config.py unset MBEDTLS_BIGNUM_C
1133 fi
1134
1135 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1136 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1137 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
David Horstmannb907dbc2025-08-27 15:19:40 +01001138 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +01001139
1140 # RSA support is intentionally disabled on this test because RSA_C depends
1141 # on BIGNUM_C.
David Horstmannb907dbc2025-08-27 15:19:40 +01001142 scripts/config.py unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
1143 scripts/config.py unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001144 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1145 # Also disable key exchanges that depend on RSA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001146 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001147
1148 if [ "$test_target" = "ECC" ]; then
1149 # When testing ECC only, we disable FFDH support, both from builtin and
Valerio Setti8438c632025-01-22 11:56:40 +01001150 # PSA sides.
David Horstmannb907dbc2025-08-27 15:19:40 +01001151 scripts/config.py unset PSA_WANT_ALG_FFDH
1152 scripts/config.py unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
1153 scripts/config.py unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001154 fi
1155
1156 # Restartable feature is not yet supported by PSA. Once it will in
1157 # the future, the following line could be removed (see issues
1158 # 6061, 6332 and following ones)
1159 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1160}
1161
1162# Common helper used by:
1163# - component_test_psa_crypto_config_accel_ecc_no_bignum
1164# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1165#
1166# The goal is to build and test accelerating either:
1167# - ECC only or
1168# - both ECC and FFDH
1169#
1170# It is meant to be used in conjunction with
1171# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
1172# coverage analysis in the "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001173common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1174 test_target="$1"
1175
1176 # This is an internal helper to simplify text message handling
1177 if [ "$test_target" = "ECC_DH" ]; then
1178 accel_text="ECC/FFDH"
1179 removed_text="ECP - DH"
1180 else
1181 accel_text="ECC"
1182 removed_text="ECP"
1183 fi
1184
1185 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1186
Valerio Setti37a42812025-08-11 12:52:49 +02001187 # Configure
1188 # ---------
1189
1190 # Set common configurations between library's and driver's builds
1191 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
1192 # Disable all the builtin curves. All the required algs are accelerated.
1193 helper_disable_builtin_curves
1194
Minos Galanakis471b34c2024-07-26 15:39:24 +01001195 # By default we accelerate all EC keys/algs
1196 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1197 ALG_ECDH \
1198 ALG_JPAKE \
1199 $(helper_get_psa_key_type_list "ECC") \
1200 $(helper_get_psa_curve_list)"
1201 # Optionally we can also add DH to the list of accelerated items
1202 if [ "$test_target" = "ECC_DH" ]; then
1203 loc_accel_list="$loc_accel_list \
1204 ALG_FFDH \
1205 $(helper_get_psa_key_type_list "DH") \
1206 $(helper_get_psa_dh_group_list)"
1207 fi
1208
Minos Galanakis471b34c2024-07-26 15:39:24 +01001209 # Build
1210 # -----
1211
1212 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1213 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1214 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1215 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1216
1217 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1218
1219 helper_libtestdriver1_make_main "$loc_accel_list"
1220
1221 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1222 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1223 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1224 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001225 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001226 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1227 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1228 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001229
1230 # Run the tests
1231 # -------------
1232
Valerio Settieb63eb22025-02-12 13:32:49 +01001233 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001234
1235 make test
1236
1237 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1238 tests/ssl-opt.sh
1239}
1240
1241# Common helper used by:
1242# - component_test_psa_crypto_config_reference_ecc_no_bignum
1243# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1244#
1245# The goal is to build and test a reference scenario (i.e. with builtin
1246# components) compared to the ones used in
1247# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
1248#
1249# It is meant to be used in conjunction with
1250# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
1251# coverage analysis in "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001252common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1253 test_target="$1"
1254
1255 # This is an internal helper to simplify text message handling
1256 if [ "$test_target" = "ECC_DH" ]; then
1257 accel_text="ECC/FFDH"
1258 else
1259 accel_text="ECC"
1260 fi
1261
1262 msg "build: full + non accelerated $accel_text algs + USE_PSA"
1263
1264 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
1265
1266 make
1267
1268 msg "test suites: full + non accelerated EC algs + USE_PSA"
1269 make test
1270
1271 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
1272 tests/ssl-opt.sh
1273}
1274
1275component_test_psa_crypto_config_accel_ecc_no_bignum () {
1276 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
1277}
1278
1279component_test_psa_crypto_config_reference_ecc_no_bignum () {
1280 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
1281}
1282
1283component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1284 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
1285}
1286
1287component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1288 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
1289}
1290
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001291component_test_tfm_config_as_is () {
1292 msg "build: configs/config-tfm.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +00001293 MBEDTLS_CONFIG="configs/config-tfm.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001294 CRYPTO_CONFIG="tf-psa-crypto/configs/ext/crypto_config_profile_medium.h"
Minos Galanakis4f619e12024-11-14 14:56:47 +00001295 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 +02001296 make
1297
1298 msg "test: configs/config-tfm.h - unit tests"
1299 make test
1300}
1301
Minos Galanakis471b34c2024-07-26 15:39:24 +01001302# Helper for setting common configurations between:
1303# - component_test_tfm_config_p256m_driver_accel_ec()
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001304# - component_test_tfm_config_no_p256m()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001305common_tfm_config () {
1306 # Enable TF-M config
1307 cp configs/config-tfm.h "$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001308 cp tf-psa-crypto/configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001309
Minos Galanakis471b34c2024-07-26 15:39:24 +01001310 # Config adjustment for better test coverage in our environment.
1311 # This is not needed just to build and pass tests.
1312 #
1313 # Enable filesystem I/O for the benefit of PK parse/write tests.
Minos Galanakis5da58e52024-11-07 15:35:33 +00001314 sed -i '/PROFILE_M_PSA_CRYPTO_CONFIG_H/i #define MBEDTLS_FS_IO' "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001315}
1316
1317# Keep this in sync with component_test_tfm_config() as they are both meant
1318# to be used in analyze_outcomes.py for driver's coverage analysis.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001319component_test_tfm_config_p256m_driver_accel_ec () {
1320 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1321
1322 common_tfm_config
1323
1324 # Build crypto library
David Horstmann5b93d972024-10-31 15:36:05 +00001325 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../framework/tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001326
1327 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1328 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1329 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1330 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001331 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001332 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1333 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001334 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1335 # Check that p256m was built
1336 grep -q p256_ecdsa_ library/libmbedcrypto.a
1337
1338 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1339 # files, so we want to ensure that it has not be re-enabled accidentally.
1340 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1341
1342 # Run the tests
1343 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1344 make test
1345}
1346
1347# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1348# they are both meant to be used in analyze_outcomes.py for driver's coverage
1349# analysis.
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001350component_test_tfm_config_no_p256m () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001351 common_tfm_config
1352
1353 # Disable P256M driver, which is on by default, so that analyze_outcomes
1354 # can compare this test with test_tfm_config_p256m_driver_accel_ec
Minos Galanakis5da58e52024-11-07 15:35:33 +00001355 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 +01001356
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001357 msg "build: TF-M config without p256m"
David Horstmann5b93d972024-10-31 15:36:05 +00001358 make CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' tests
Minos Galanakis471b34c2024-07-26 15:39:24 +01001359
1360 # Check that p256m was not built
1361 not grep p256_ecdsa_ library/libmbedcrypto.a
1362
1363 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1364 # files, so we want to ensure that it has not be re-enabled accidentally.
1365 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1366
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001367 msg "test: TF-M config without p256m"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001368 make test
1369}
1370
Minos Galanakis471b34c2024-07-26 15:39:24 +01001371# This is an helper used by:
1372# - component_test_psa_ecc_key_pair_no_derive
1373# - component_test_psa_ecc_key_pair_no_generate
1374# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1375# enabled, but one. Input arguments are as follows:
Gilles Peskinefef912c2024-09-20 16:07:09 +02001376# - $1 is the configuration to start from
1377# - $2 is the key type under test, i.e. ECC/RSA/DH
1378# - $3 is the key option to be unset (i.e. generate, derive, etc)
Minos Galanakisf78447f2024-07-26 20:49:51 +01001379build_and_test_psa_want_key_pair_partial () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001380 base_config=$1
1381 key_type=$2
1382 unset_option=$3
Minos Galanakis471b34c2024-07-26 15:39:24 +01001383 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1384
Gilles Peskinefef912c2024-09-20 16:07:09 +02001385 msg "build: $base_config - ${disabled_psa_want}"
1386 scripts/config.py "$base_config"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001387
1388 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1389 # crypto_config.h so we just disable the one we don't want.
David Horstmannb907dbc2025-08-27 15:19:40 +01001390 scripts/config.py unset "$disabled_psa_want"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001391
1392 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1393
Gilles Peskinefef912c2024-09-20 16:07:09 +02001394 msg "test: $base_config - ${disabled_psa_want}"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001395 make test
1396}
1397
Minos Galanakisf78447f2024-07-26 20:49:51 +01001398component_test_psa_ecc_key_pair_no_derive () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001399 build_and_test_psa_want_key_pair_partial full "ECC" "DERIVE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001400}
1401
Minos Galanakisf78447f2024-07-26 20:49:51 +01001402component_test_psa_ecc_key_pair_no_generate () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001403 # TLS needs ECC key generation whenever ephemeral ECDH is enabled.
1404 # We don't have proper guards for configurations with ECC key generation
1405 # disabled (https://github.com/Mbed-TLS/mbedtls/issues/9481). Until
1406 # then (if ever), just test the crypto part of the library.
1407 build_and_test_psa_want_key_pair_partial crypto_full "ECC" "GENERATE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001408}
1409
1410config_psa_crypto_accel_rsa () {
1411 driver_only=$1
1412
1413 # Start from crypto_full config (no X.509, no TLS)
1414 helper_libtestdriver1_adjust_config "crypto_full"
1415
1416 if [ "$driver_only" -eq 1 ]; then
Minos Galanakis471b34c2024-07-26 15:39:24 +01001417 # We need PEM parsing in the test library as well to support the import
1418 # of PEM encoded RSA keys.
Minos Galanakis23452f52024-11-28 17:48:14 +00001419 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1420 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
Minos Galanakis471b34c2024-07-26 15:39:24 +01001421 fi
1422}
1423
1424component_test_psa_crypto_config_accel_rsa_crypto () {
1425 msg "build: crypto_full with accelerated RSA"
1426
1427 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1428 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1429 KEY_TYPE_RSA_PUBLIC_KEY \
1430 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1431 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1432 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1433 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1434
1435 # Configure
1436 # ---------
1437
1438 config_psa_crypto_accel_rsa 1
1439
1440 # Build
1441 # -----
1442
1443 # These hashes are needed for unit tests.
1444 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1445 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1446 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1447
1448 helper_libtestdriver1_make_main "$loc_accel_list"
1449
1450 # Make sure this was not re-enabled by accident (additive config)
1451 not grep mbedtls_rsa ${BUILTIN_SRC_PATH}/rsa.o
1452
1453 # Run the tests
1454 # -------------
1455
1456 msg "test: crypto_full with accelerated RSA"
1457 make test
1458}
1459
1460component_test_psa_crypto_config_reference_rsa_crypto () {
1461 msg "build: crypto_full with non-accelerated RSA"
1462
1463 # Configure
1464 # ---------
1465 config_psa_crypto_accel_rsa 0
1466
1467 # Build
1468 # -----
1469 make
1470
1471 # Run the tests
1472 # -------------
1473 msg "test: crypto_full with non-accelerated RSA"
1474 make test
1475}
1476
1477# This is a temporary test to verify that full RSA support is present even when
1478# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001479component_test_new_psa_want_key_pair_symbol () {
Ronald Cron892bb612025-07-21 14:26:27 +02001480 msg "Build: crypto config - PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001481
1482 # Create a temporary output file unless there is already one set
1483 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1484 REMOVE_OUTCOME_ON_EXIT="no"
1485 else
1486 REMOVE_OUTCOME_ON_EXIT="yes"
1487 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1488 export MBEDTLS_TEST_OUTCOME_FILE
1489 fi
1490
1491 # Start from crypto configuration
1492 scripts/config.py crypto
1493
1494 # Remove RSA support and its dependencies
Minos Galanakis471b34c2024-07-26 15:39:24 +01001495 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001496 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1497
Minos Galanakis471b34c2024-07-26 15:39:24 +01001498 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
1499 # that proper translations is done in crypto_legacy.h.
David Horstmannb907dbc2025-08-27 15:19:40 +01001500 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
1501 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
1502 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Minos Galanakis471b34c2024-07-26 15:39:24 +01001503
1504 make
1505
Ronald Cron892bb612025-07-21 14:26:27 +02001506 msg "Test: crypto config - PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001507 make test
1508
1509 # Parse only 1 relevant line from the outcome file, i.e. a test which is
1510 # performing RSA signature.
1511 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
1512 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
1513
1514 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
1515 rm $MBEDTLS_TEST_OUTCOME_FILE
1516 fi
1517}
1518
1519component_test_psa_crypto_config_accel_hash () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001520 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001521
1522 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1523 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1524 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1525
1526 # Configure
1527 # ---------
1528
1529 # Start from default config (no USE_PSA)
1530 helper_libtestdriver1_adjust_config "default"
1531
Minos Galanakis471b34c2024-07-26 15:39:24 +01001532 # Build
1533 # -----
1534
1535 helper_libtestdriver1_make_drivers "$loc_accel_list"
1536
1537 helper_libtestdriver1_make_main "$loc_accel_list"
1538
1539 # There's a risk of something getting re-enabled via config_psa.h;
1540 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1541 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1542 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1543 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1544 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1545 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1546
1547 # Run the tests
1548 # -------------
1549
Ronald Cron93ba6252024-09-05 10:37:14 +02001550 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001551 make test
1552}
1553
1554# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001555config_psa_crypto_hash_use_psa () {
1556 driver_only="$1"
1557 # start with config full for maximum coverage (also enables USE_PSA)
1558 helper_libtestdriver1_adjust_config "full"
1559 if [ "$driver_only" -eq 1 ]; then
1560 # disable the built-in implementation of hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +01001561 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Minos Galanakis471b34c2024-07-26 15:39:24 +01001562 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Minos Galanakis471b34c2024-07-26 15:39:24 +01001563 fi
1564}
1565
1566# Note that component_test_psa_crypto_config_reference_hash_use_psa
1567# is related to this component and both components need to be kept in sync.
1568# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001569component_test_psa_crypto_config_accel_hash_use_psa () {
1570 msg "test: full with accelerated hashes"
1571
1572 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1573 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1574 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1575
1576 # Configure
1577 # ---------
1578
1579 config_psa_crypto_hash_use_psa 1
1580
1581 # Build
1582 # -----
1583
1584 helper_libtestdriver1_make_drivers "$loc_accel_list"
1585
1586 helper_libtestdriver1_make_main "$loc_accel_list"
1587
1588 # There's a risk of something getting re-enabled via config_psa.h;
1589 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1590 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1591 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1592 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1593 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1594 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1595
1596 # Run the tests
1597 # -------------
1598
1599 msg "test: full with accelerated hashes"
1600 make test
1601
1602 # This is mostly useful so that we can later compare outcome files with
1603 # the reference config in analyze_outcomes.py, to check that the
1604 # dependency declarations in ssl-opt.sh and in TLS code are correct.
1605 msg "test: ssl-opt.sh, full with accelerated hashes"
1606 tests/ssl-opt.sh
1607
1608 # This is to make sure all ciphersuites are exercised, but we don't need
1609 # interop testing (besides, we already got some from ssl-opt.sh).
1610 msg "test: compat.sh, full with accelerated hashes"
1611 tests/compat.sh -p mbedTLS -V YES
1612}
1613
1614# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
1615# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
1616# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
1617# Both components need to be kept in sync.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001618component_test_psa_crypto_config_reference_hash_use_psa () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001619 msg "test: full without accelerated hashes"
1620
1621 config_psa_crypto_hash_use_psa 0
1622
1623 make
1624
1625 msg "test: full without accelerated hashes"
1626 make test
1627
1628 msg "test: ssl-opt.sh, full without accelerated hashes"
1629 tests/ssl-opt.sh
1630}
1631
1632# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001633config_psa_crypto_hmac_use_psa () {
1634 driver_only="$1"
1635 # start with config full for maximum coverage (also enables USE_PSA)
1636 helper_libtestdriver1_adjust_config "full"
1637
1638 if [ "$driver_only" -eq 1 ]; then
1639 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
1640 # is still enabled though (for ENTROPY_C among others).
1641 scripts/config.py unset MBEDTLS_MD_C
Ronald Cron772a8ad2025-07-21 12:36:29 +02001642 # Also disable the configuration options that tune the builtin hashes,
1643 # since those hashes are disabled.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001644 scripts/config.py unset-all MBEDTLS_SHA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001645 fi
1646
1647 # Direct dependencies of MD_C. We disable them also in the reference
1648 # component to work with the same set of features.
1649 scripts/config.py unset MBEDTLS_PKCS7_C
1650 scripts/config.py unset MBEDTLS_PKCS5_C
1651 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1652 scripts/config.py unset MBEDTLS_HKDF_C
1653 # Dependencies of HMAC_DRBG
David Horstmannb907dbc2025-08-27 15:19:40 +01001654 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001655}
1656
Minos Galanakisf78447f2024-07-26 20:49:51 +01001657component_test_psa_crypto_config_accel_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001658 msg "test: full with accelerated hmac"
1659
1660 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
1661 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1662 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1663 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1664
1665 # Configure
1666 # ---------
1667
1668 config_psa_crypto_hmac_use_psa 1
1669
1670 # Build
1671 # -----
1672
1673 helper_libtestdriver1_make_drivers "$loc_accel_list"
1674
1675 helper_libtestdriver1_make_main "$loc_accel_list"
1676
1677 # Ensure that built-in support for HMAC is disabled.
1678 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
1679
1680 # Run the tests
1681 # -------------
1682
1683 msg "test: full with accelerated hmac"
1684 make test
1685}
1686
Minos Galanakisf78447f2024-07-26 20:49:51 +01001687component_test_psa_crypto_config_reference_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001688 msg "test: full without accelerated hmac"
1689
1690 config_psa_crypto_hmac_use_psa 0
1691
1692 make
1693
1694 msg "test: full without accelerated hmac"
1695 make test
1696}
1697
Minos Galanakis471b34c2024-07-26 15:39:24 +01001698component_test_psa_crypto_config_accel_aead () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001699 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001700
1701 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
1702 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1703
1704 # Configure
1705 # ---------
1706
1707 # Start from full config
1708 helper_libtestdriver1_adjust_config "full"
1709
Minos Galanakis471b34c2024-07-26 15:39:24 +01001710 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
David Horstmannb907dbc2025-08-27 15:19:40 +01001711 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
Minos Galanakis471b34c2024-07-26 15:39:24 +01001712
1713 # Build
1714 # -----
1715
1716 helper_libtestdriver1_make_drivers "$loc_accel_list"
1717
1718 helper_libtestdriver1_make_main "$loc_accel_list"
1719
1720 # Make sure this was not re-enabled by accident (additive config)
1721 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1722 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1723 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1724
1725 # Run the tests
1726 # -------------
1727
Ronald Cron93ba6252024-09-05 10:37:14 +02001728 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001729 make test
1730}
1731
1732# This is a common configuration function used in:
1733# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1734# - component_test_psa_crypto_config_reference_cipher_aead_cmac
Minos Galanakisf78447f2024-07-26 20:49:51 +01001735common_psa_crypto_config_accel_cipher_aead_cmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001736 # Start from the full config
1737 helper_libtestdriver1_adjust_config "full"
1738
1739 scripts/config.py unset MBEDTLS_NIST_KW_C
1740}
1741
1742# The 2 following test components, i.e.
1743# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1744# - component_test_psa_crypto_config_reference_cipher_aead_cmac
1745# are meant to be used together in analyze_outcomes.py script in order to test
1746# driver's coverage for ciphers and AEADs.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001747component_test_psa_crypto_config_accel_cipher_aead_cmac () {
1748 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
1749
1750 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
1751 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
1752 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
Ari Weiler-Ofek86422e52025-07-04 14:43:30 +01001753 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001754
1755 # Configure
1756 # ---------
1757
1758 common_psa_crypto_config_accel_cipher_aead_cmac
1759
Ari Weiler-Ofek5d8d2992025-07-07 23:20:29 +01001760 # Disable DES, if it still exists.
1761 # This can be removed once we remove DES from the library.
1762 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
1763
Minos Galanakis471b34c2024-07-26 15:39:24 +01001764 # Build
1765 # -----
1766
1767 helper_libtestdriver1_make_drivers "$loc_accel_list"
1768
1769 helper_libtestdriver1_make_main "$loc_accel_list"
1770
1771 # Make sure this was not re-enabled by accident (additive config)
1772 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001773 not grep mbedtls_aes ${BUILTIN_SRC_PATH}/aes.o
1774 not grep mbedtls_aria ${BUILTIN_SRC_PATH}/aria.o
1775 not grep mbedtls_camellia ${BUILTIN_SRC_PATH}/camellia.o
1776 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1777 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1778 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1779 not grep mbedtls_cmac ${BUILTIN_SRC_PATH}/cmac.o
Ronald Cronb5c6fcc2025-07-10 13:40:00 +02001780 not grep mbedtls_poly1305 ${BUILTIN_SRC_PATH}/poly1305.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001781
1782 # Run the tests
1783 # -------------
1784
1785 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
1786 make test
1787
1788 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
Ronald Cronbd28acf2025-07-10 09:53:50 +02001789 # Exclude password-protected key tests — they require built-in CBC and AES.
1790 tests/ssl-opt.sh -e "TLS: password protected"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001791
1792 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
1793 tests/compat.sh -V NO -p mbedTLS
1794}
1795
1796component_test_psa_crypto_config_reference_cipher_aead_cmac () {
1797 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
1798 common_psa_crypto_config_accel_cipher_aead_cmac
1799
Ari Weiler-Ofek5d8d2992025-07-07 23:20:29 +01001800 # Disable DES, if it still exists.
1801 # This can be removed once we remove DES from the library.
1802 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
1803
Minos Galanakis471b34c2024-07-26 15:39:24 +01001804 make
1805
1806 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
1807 make test
1808
1809 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
Ronald Cronbd28acf2025-07-10 09:53:50 +02001810 # Exclude password-protected key tests as in test_psa_crypto_config_accel_cipher_aead_cmac.
1811 tests/ssl-opt.sh -e "TLS: password protected"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001812
1813 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
1814 tests/compat.sh -V NO -p mbedTLS
1815}
1816
Minos Galanakisf78447f2024-07-26 20:49:51 +01001817common_block_cipher_dispatch () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001818 TEST_WITH_DRIVER="$1"
1819
1820 # Start from the full config
1821 helper_libtestdriver1_adjust_config "full"
1822
Minos Galanakis471b34c2024-07-26 15:39:24 +01001823 # Disable cipher's modes that, when not accelerated, cause
1824 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
1825 # Keep this also in the reference component in order to skip the same tests
1826 # that were skipped in the accelerated one.
David Horstmannb907dbc2025-08-27 15:19:40 +01001827 scripts/config.py unset PSA_WANT_ALG_CTR
1828 scripts/config.py unset PSA_WANT_ALG_CFB
1829 scripts/config.py unset PSA_WANT_ALG_OFB
1830 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
1831 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
1832 scripts/config.py unset PSA_WANT_ALG_CMAC
1833 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1834 scripts/config.py unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
Minos Galanakis471b34c2024-07-26 15:39:24 +01001835
1836 # Disable direct dependency on AES_C
1837 scripts/config.py unset MBEDTLS_NIST_KW_C
1838
1839 # Prevent the cipher module from using deprecated PSA path. The reason is
1840 # that otherwise there will be tests relying on "aes_info" (defined in
1841 # "cipher_wrap.c") whose functions are not available when AES_C is
1842 # not defined. ARIA and Camellia are not a problem in this case because
1843 # the PSA path is not tested for these key types.
1844 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1845}
1846
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02001847component_test_full_block_cipher_psa_dispatch_static_keystore () {
1848 msg "build: full + PSA dispatch in block_cipher with static keystore"
1849 # Check that the static key store works well when CTR_DRBG uses a
1850 # PSA key for AES.
1851 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
1852
1853 loc_accel_list="ALG_ECB_NO_PADDING \
1854 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1855
1856 # Configure
1857 # ---------
1858
1859 common_block_cipher_dispatch 1
1860
1861 # Build
1862 # -----
1863
1864 helper_libtestdriver1_make_drivers "$loc_accel_list"
1865
1866 helper_libtestdriver1_make_main "$loc_accel_list"
1867
1868 # Make sure disabled components were not re-enabled by accident (additive
1869 # config)
1870 not grep mbedtls_aes_ library/aes.o
1871 not grep mbedtls_aria_ library/aria.o
1872 not grep mbedtls_camellia_ library/camellia.o
1873
1874 # Run the tests
1875 # -------------
1876
1877 msg "test: full + PSA dispatch in block_cipher with static keystore"
1878 make test
1879}
1880
Minos Galanakis471b34c2024-07-26 15:39:24 +01001881component_test_full_block_cipher_psa_dispatch () {
1882 msg "build: full + PSA dispatch in block_cipher"
1883
1884 loc_accel_list="ALG_ECB_NO_PADDING \
1885 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1886
1887 # Configure
1888 # ---------
1889
1890 common_block_cipher_dispatch 1
1891
1892 # Build
1893 # -----
1894
1895 helper_libtestdriver1_make_drivers "$loc_accel_list"
1896
1897 helper_libtestdriver1_make_main "$loc_accel_list"
1898
1899 # Make sure disabled components were not re-enabled by accident (additive
1900 # config)
1901 not grep mbedtls_aes_ ${BUILTIN_SRC_PATH}/aes.o
1902 not grep mbedtls_aria_ ${BUILTIN_SRC_PATH}/aria.o
1903 not grep mbedtls_camellia_ ${BUILTIN_SRC_PATH}/camellia.o
1904
1905 # Run the tests
1906 # -------------
1907
1908 msg "test: full + PSA dispatch in block_cipher"
1909 make test
1910}
1911
1912# This is the reference component of component_test_full_block_cipher_psa_dispatch
Minos Galanakis471b34c2024-07-26 15:39:24 +01001913component_test_full_block_cipher_legacy_dispatch () {
1914 msg "build: full + legacy dispatch in block_cipher"
1915
1916 common_block_cipher_dispatch 0
1917
1918 make
1919
1920 msg "test: full + legacy dispatch in block_cipher"
1921 make test
1922}
1923
Minos Galanakisf78447f2024-07-26 20:49:51 +01001924component_test_aead_chachapoly_disabled () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001925 msg "build: full minus CHACHAPOLY"
1926 scripts/config.py full
David Horstmannb907dbc2025-08-27 15:19:40 +01001927 scripts/config.py unset PSA_WANT_ALG_CHACHA20_POLY1305
Minos Galanakis471b34c2024-07-26 15:39:24 +01001928 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1929
1930 msg "test: full minus CHACHAPOLY"
1931 make test
1932}
1933
Minos Galanakisf78447f2024-07-26 20:49:51 +01001934component_test_aead_only_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001935 msg "build: full minus CHACHAPOLY and GCM"
1936 scripts/config.py full
David Horstmannb907dbc2025-08-27 15:19:40 +01001937 scripts/config.py unset PSA_WANT_ALG_CHACHA20_POLY1305
1938 scripts/config.py unset PSA_WANT_ALG_GCM
Minos Galanakis471b34c2024-07-26 15:39:24 +01001939 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1940
1941 msg "test: full minus CHACHAPOLY and GCM"
1942 make test
1943}
1944
Minos Galanakisf78447f2024-07-26 20:49:51 +01001945component_test_ccm_aes_sha256 () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001946 msg "build: CCM + AES + SHA256 configuration"
1947
Minos Galanakisa17ffc72024-12-02 23:57:30 +00001948 # Setting a blank config disables everyhing in the library side.
1949 echo '#define MBEDTLS_CONFIG_H ' >"$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001950 cp tf-psa-crypto/configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
Ronald Cron9d262d72024-12-06 17:41:26 +01001951
Minos Galanakis471b34c2024-07-26 15:39:24 +01001952 make
Minos Galanakis471b34c2024-07-26 15:39:24 +01001953 msg "test: CCM + AES + SHA256 configuration"
1954 make test
1955}
1956
1957# Test that the given .o file builds with all (valid) combinations of the given options.
1958#
1959# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
1960#
1961# The validator function is the name of a function to validate the combination of options.
1962# It may be "" if all combinations are valid.
1963# It receives a string containing a combination of options, as passed to the compiler,
1964# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001965build_test_config_combos () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001966 file=$1
1967 shift
1968 validate_options=$1
1969 shift
1970 options=("$@")
1971
1972 # clear all of the options so that they can be overridden on the clang commandline
1973 for opt in "${options[@]}"; do
1974 ./scripts/config.py unset ${opt}
1975 done
1976
1977 # enter the library directory
1978 cd library
1979
1980 # The most common issue is unused variables/functions, so ensure -Wunused is set.
1981 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
1982
1983 # Extract the command generated by the Makefile to build the target file.
1984 # This ensures that we have any include paths, macro definitions, etc
1985 # that may be applied by make.
1986 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
1987 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
1988
1989 makefile=$(TMPDIR=. mktemp)
1990 deps=""
1991
1992 len=${#options[@]}
1993 source_file=../${file%.o}.c
1994
1995 targets=0
1996 echo 'include Makefile' >${makefile}
1997
1998 for ((i = 0; i < $((2**${len})); i++)); do
1999 # generate each of 2^n combinations of options
2000 # each bit of $i is used to determine if options[i] will be set or not
2001 target="t"
2002 clang_args=""
2003 for ((j = 0; j < ${len}; j++)); do
2004 if (((i >> j) & 1)); then
2005 opt=-D${options[$j]}
2006 clang_args="${clang_args} ${opt}"
2007 target="${target}${opt}"
2008 fi
2009 done
2010
2011 # if combination is not known to be invalid, add it to the makefile
2012 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
2013 cmd="${compile_cmd} ${clang_args}"
2014 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
2015
2016 deps="${deps} ${target}"
2017 ((++targets))
2018 fi
2019 done
2020
2021 echo "build_test_config_combos: ${deps}" >> ${makefile}
2022
2023 # execute all of the commands via Make (probably in parallel)
2024 make -s -f ${makefile} build_test_config_combos
2025 echo "$targets targets checked"
2026
2027 # clean up the temporary makefile
2028 rm ${makefile}
2029}
2030
Minos Galanakisf78447f2024-07-26 20:49:51 +01002031validate_aes_config_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002032 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
2033 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
2034 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
2035 return 1
2036 fi
2037 fi
2038 return 0
2039}
2040
Minos Galanakisf78447f2024-07-26 20:49:51 +01002041component_build_aes_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002042 # 18s - around 90ms per clang invocation on M1 Pro
2043 #
2044 # aes.o has many #if defined(...) guards that intersect in complex ways.
2045 # Test that all the combinations build cleanly.
2046
2047 MBEDTLS_ROOT_DIR="$PWD"
2048 msg "build: aes.o for all combinations of relevant config options"
2049
2050 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002051 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002052 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2053 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2054
2055 cd "$MBEDTLS_ROOT_DIR"
2056 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
2057
Ari Weiler-Ofek86422e52025-07-04 14:43:30 +01002058 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW,
Minos Galanakis471b34c2024-07-26 15:39:24 +01002059 # manually set or unset those configurations to check
2060 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
2061 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Minos Galanakis471b34c2024-07-26 15:39:24 +01002062 scripts/config.py unset MBEDTLS_NIST_KW_C
Ronald Cron54d1eec2024-09-06 09:55:38 +02002063
David Horstmann7cbeedc2025-08-26 17:26:45 +01002064 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
2065 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
2066 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
2067 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
Ronald Cron54d1eec2024-09-06 09:55:38 +02002068
Minos Galanakis471b34c2024-07-26 15:39:24 +01002069 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002070 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002071 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2072 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2073}
2074
Minos Galanakisf78447f2024-07-26 20:49:51 +01002075component_test_sha3_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002076 msg "sha3 loop unroll variations"
2077
2078 # define minimal config sufficient to test SHA3
Ronald Crone7f289e2024-09-06 11:02:47 +02002079 cat > include/mbedtls/mbedtls_config.h << END
Ronald Crone7f289e2024-09-06 11:02:47 +02002080END
2081
2082 cat > tf-psa-crypto/include/psa/crypto_config.h << END
2083 #define PSA_WANT_ALG_SHA_256 1
2084 #define PSA_WANT_ALG_SHA3_224 1
2085 #define PSA_WANT_ALG_SHA3_256 1
2086 #define PSA_WANT_ALG_SHA3_384 1
2087 #define PSA_WANT_ALG_SHA3_512 1
Ronald Cron06680362025-07-21 15:21:22 +02002088 #define PSA_WANT_KEY_TYPE_AES 1
Ronald Cron3dd1d3d2024-12-05 15:12:06 +01002089 #define MBEDTLS_PSA_CRYPTO_C
Ronald Cron3b306432025-09-02 18:30:08 +02002090 #define MBEDTLS_CTR_DRBG_C
2091 #define MBEDTLS_PSA_BUILTIN_GET_ENTROPY
Ronald Cron3dd1d3d2024-12-05 15:12:06 +01002092 #define MBEDTLS_SELF_TEST
Minos Galanakis471b34c2024-07-26 15:39:24 +01002093END
2094
2095 msg "all loops unrolled"
2096 make clean
2097 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"
2098 ./tf-psa-crypto/tests/test_suite_shax
2099
2100 msg "all loops rolled up"
2101 make clean
2102 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"
2103 ./tf-psa-crypto/tests/test_suite_shax
2104}
2105
Minos Galanakisf699d512024-08-01 11:32:30 +01002106support_build_aes_aesce_armcc () {
2107 support_build_armcc
2108}
2109
Minos Galanakis471b34c2024-07-26 15:39:24 +01002110# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2111component_build_aes_aesce_armcc () {
2112 msg "Build: AESCE test on arm64 platform without plain C."
2113 scripts/config.py baremetal
2114
2115 # armc[56] don't support SHA-512 intrinsics
2116 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2117
2118 # Stop armclang warning about feature detection for A64_CRYPTO.
2119 # With this enabled, the library does build correctly under armclang,
2120 # but in baremetal builds (as tested here), feature detection is
2121 # unavailable, and the user is notified via a #warning. So enabling
2122 # this feature would prevent us from building with -Werror on
2123 # armclang. Tracked in #7198.
2124 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2125 scripts/config.py set MBEDTLS_HAVE_ASM
2126
2127 msg "AESCE, build with default configuration."
2128 scripts/config.py set MBEDTLS_AESCE_C
2129 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002130 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002131
2132 msg "AESCE, build AESCE only"
2133 scripts/config.py set MBEDTLS_AESCE_C
2134 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002135 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002136}
2137
Minos Galanakis471b34c2024-07-26 15:39:24 +01002138component_test_aes_only_128_bit_keys () {
2139 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
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
2143 make CFLAGS='-O2 -Werror -Wall -Wextra'
2144
2145 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2146 make test
2147}
2148
2149component_test_no_ctr_drbg_aes_only_128_bit_keys () {
2150 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2151 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002152 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002153 scripts/config.py unset MBEDTLS_CTR_DRBG_C
2154
2155 make CC=clang CFLAGS='-Werror -Wall -Wextra'
2156
2157 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2158 make test
2159}
2160
2161component_test_aes_only_128_bit_keys_have_builtins () {
2162 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2163 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002164 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002165 scripts/config.py unset MBEDTLS_AESNI_C
2166 scripts/config.py unset MBEDTLS_AESCE_C
2167
2168 make CFLAGS='-O2 -Werror -Wall -Wextra'
2169
2170 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2171 make test
2172
2173 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2174 programs/test/selftest
2175}
2176
2177component_test_gcm_largetable () {
2178 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2179 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
2180 scripts/config.py unset MBEDTLS_AESNI_C
2181 scripts/config.py unset MBEDTLS_AESCE_C
2182
2183 make CFLAGS='-O2 -Werror -Wall -Wextra'
2184
2185 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2186 make test
2187}
2188
2189component_test_aes_fewer_tables () {
2190 msg "build: default config with AES_FEWER_TABLES enabled"
2191 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2192 make CFLAGS='-O2 -Werror -Wall -Wextra'
2193
2194 msg "test: AES_FEWER_TABLES"
2195 make test
2196}
2197
2198component_test_aes_rom_tables () {
2199 msg "build: default config with AES_ROM_TABLES enabled"
2200 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2201 make CFLAGS='-O2 -Werror -Wall -Wextra'
2202
2203 msg "test: AES_ROM_TABLES"
2204 make test
2205}
2206
2207component_test_aes_fewer_tables_and_rom_tables () {
2208 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
2209 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2210 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2211 make CFLAGS='-O2 -Werror -Wall -Wextra'
2212
2213 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2214 make test
2215}
2216
Ronald Cron66040472024-09-06 10:14:38 +02002217# helper for component_test_block_cipher_no_decrypt_aesni() which:
Minos Galanakis471b34c2024-07-26 15:39:24 +01002218# - enable/disable the list of config options passed from -s/-u respectively.
2219# - build
2220# - test for tests_suite_xxx
2221# - selftest
2222#
2223# Usage: helper_block_cipher_no_decrypt_build_test
2224# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
2225# Options: -s set_opts the list of config options to enable
2226# -u unset_opts the list of config options to disable
2227# -c cflags the list of options passed to CFLAGS
2228# -l ldflags the list of options passed to LDFLAGS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002229helper_block_cipher_no_decrypt_build_test () {
2230 while [ $# -gt 0 ]; do
2231 case "$1" in
2232 -s)
2233 shift; local set_opts="$1";;
2234 -u)
2235 shift; local unset_opts="$1";;
2236 -c)
2237 shift; local cflags="-Werror -Wall -Wextra $1";;
2238 -l)
2239 shift; local ldflags="$1";;
2240 esac
2241 shift
2242 done
2243 set_opts="${set_opts:-}"
2244 unset_opts="${unset_opts:-}"
2245 cflags="${cflags:-}"
2246 ldflags="${ldflags:-}"
2247
2248 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
2249 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
2250
2251 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2252 make clean
2253 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
2254
2255 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2256 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2257 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2258 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2259 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2260 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2261 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
2262 not grep mbedtls_aesni_inverse_key ${BUILTIN_SRC_PATH}/aesni.o
2263
2264 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2265 make test
2266
2267 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2268 programs/test/selftest
2269}
2270
Ronald Cron66040472024-09-06 10:14:38 +02002271# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
2272config_block_cipher_no_decrypt () {
2273 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Ronald Cron66040472024-09-06 10:14:38 +02002274 scripts/config.py unset MBEDTLS_NIST_KW_C
2275
2276 # Enable support for cryptographic mechanisms through the PSA API.
2277 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
David Horstmannb907dbc2025-08-27 15:19:40 +01002278 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
2279 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
2280 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
2281 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
Ronald Cron66040472024-09-06 10:14:38 +02002282}
2283
2284component_test_block_cipher_no_decrypt_aesni () {
2285 # Test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics, AESNI assembly and
2286 # AES C implementation on x86_64 and with AESNI intrinsics on x86.
2287
2288 # This consistently causes an llvm crash on clang 3.8, so use gcc
2289 export CC=gcc
2290 config_block_cipher_no_decrypt
2291
Minos Galanakis471b34c2024-07-26 15:39:24 +01002292 # test AESNI intrinsics
2293 helper_block_cipher_no_decrypt_build_test \
2294 -s "MBEDTLS_AESNI_C" \
2295 -c "-mpclmul -msse2 -maes"
2296
2297 # test AESNI assembly
2298 helper_block_cipher_no_decrypt_build_test \
2299 -s "MBEDTLS_AESNI_C" \
2300 -c "-mno-pclmul -mno-sse2 -mno-aes"
2301
2302 # test AES C implementation
2303 helper_block_cipher_no_decrypt_build_test \
2304 -u "MBEDTLS_AESNI_C"
2305
2306 # test AESNI intrinsics for i386 target
2307 helper_block_cipher_no_decrypt_build_test \
2308 -s "MBEDTLS_AESNI_C" \
2309 -c "-m32 -mpclmul -msse2 -maes" \
2310 -l "-m32"
2311}
2312
Minos Galanakisf699d512024-08-01 11:32:30 +01002313support_test_block_cipher_no_decrypt_aesce_armcc () {
2314 support_build_armcc
2315}
2316
Minos Galanakis471b34c2024-07-26 15:39:24 +01002317component_test_block_cipher_no_decrypt_aesce_armcc () {
2318 scripts/config.py baremetal
2319
2320 # armc[56] don't support SHA-512 intrinsics
2321 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2322
2323 # Stop armclang warning about feature detection for A64_CRYPTO.
2324 # With this enabled, the library does build correctly under armclang,
2325 # but in baremetal builds (as tested here), feature detection is
2326 # unavailable, and the user is notified via a #warning. So enabling
2327 # this feature would prevent us from building with -Werror on
2328 # armclang. Tracked in #7198.
2329 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2330 scripts/config.py set MBEDTLS_HAVE_ASM
2331
Ronald Cron66040472024-09-06 10:14:38 +02002332 config_block_cipher_no_decrypt
Minos Galanakis471b34c2024-07-26 15:39:24 +01002333
2334 # test AESCE baremetal build
2335 scripts/config.py set MBEDTLS_AESCE_C
2336 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002337 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002338
2339 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2340 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2341 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2342 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2343 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2344 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2345 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
2346 not grep mbedtls_aesce_inverse_key ${BUILTIN_SRC_PATH}/aesce.o
2347 not grep aesce_decrypt_block ${BUILTIN_SRC_PATH}/aesce.o
2348}
2349
Ronald Cronaad5f1b2025-08-25 15:32:48 +02002350component_test_ctr_drbg_aes_256_sha_512 () {
2351 msg "build: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512 (ASan build)"
2352 scripts/config.py full
2353 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2354 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512
2355 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2356 make
2357
2358 msg "test: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512 (ASan build)"
2359 make test
2360}
2361
Minos Galanakis471b34c2024-07-26 15:39:24 +01002362component_test_ctr_drbg_aes_256_sha_256 () {
Minos Galanakisf3486e12025-08-18 14:09:26 +01002363 msg "build: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002364 scripts/config.py full
2365 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakisf3486e12025-08-18 14:09:26 +01002366 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256
Minos Galanakis471b34c2024-07-26 15:39:24 +01002367 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2368 make
2369
Minos Galanakisf3486e12025-08-18 14:09:26 +01002370 msg "test: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002371 make test
2372}
2373
2374component_test_ctr_drbg_aes_128_sha_512 () {
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002375 msg "build: full + set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002376 scripts/config.py full
2377 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002378 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Ronald Cronaad5f1b2025-08-25 15:32:48 +02002379 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512
Minos Galanakis471b34c2024-07-26 15:39:24 +01002380 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2381 make
2382
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002383 msg "test: full + set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002384 make test
2385}
2386
2387component_test_ctr_drbg_aes_128_sha_256 () {
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002388 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 +01002389 scripts/config.py full
2390 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002391 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakisf3486e12025-08-18 14:09:26 +01002392 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256
Minos Galanakis471b34c2024-07-26 15:39:24 +01002393 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2394 make
2395
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002396 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 +01002397 make test
2398}
2399
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002400component_test_full_static_keystore () {
2401 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2402 scripts/config.py full
2403 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2404 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
2405
2406 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2407 make test
2408}
2409
Minos Galanakis471b34c2024-07-26 15:39:24 +01002410component_test_psa_crypto_drivers () {
Ronald Crona0afbfb2024-10-15 13:20:31 +02002411 # Test dispatch to drivers and fallbacks with
2412 # test_suite_psa_crypto_driver_wrappers test suite. The test drivers that
2413 # are wrappers around the builtin drivers are activated by
2414 # PSA_CRYPTO_DRIVER_TEST.
2415 #
2416 # For the time being, some test cases in test_suite_block_cipher and
2417 # test_suite_md.psa rely on this component to be run at least once by the
2418 # CI. This should disappear as we progress the 4.x work. See
2419 # config_adjust_test_accelerators.h for more information.
Minos Galanakis471b34c2024-07-26 15:39:24 +01002420 msg "build: full + test drivers dispatching to builtins"
2421 scripts/config.py full
Ronald Cron67cc6a72024-10-14 10:55:24 +02002422 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_CONFIG_ADJUST_TEST_ACCELERATORS"
David Horstmann5b93d972024-10-31 15:36:05 +00002423 loc_cflags="${loc_cflags} -I../framework/tests/include"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002424
2425 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
2426
2427 msg "test: full + test drivers dispatching to builtins"
2428 make test
2429}
2430
2431component_build_psa_config_file () {
Minos Galanakis4f619e12024-11-14 14:56:47 +00002432 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002433 cp "$CRYPTO_CONFIG_H" psa_test_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002434 echo '#error "TF_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
2435 make CFLAGS="-I '$PWD' -DTF_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002436 # Make sure this feature is enabled. We'll disable it in the next phase.
Ronald Cron3f120062025-07-03 14:45:51 +02002437 programs/test/query_compile_time_config PSA_WANT_ALG_CMAC
Minos Galanakis471b34c2024-07-26 15:39:24 +01002438 make clean
2439
Minos Galanakis4f619e12024-11-14 14:56:47 +00002440 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE + TF_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002441 # In the user config, disable one feature and its dependencies, which will
2442 # reflect on the mbedtls configuration so we can query it with
2443 # query_compile_time_config.
2444 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
2445 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002446 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 +02002447 not programs/test/query_compile_time_config PSA_WANT_ALG_CMAC
Minos Galanakis471b34c2024-07-26 15:39:24 +01002448
2449 rm -f psa_test_config.h psa_user_config.h
2450}
2451
2452component_build_psa_alt_headers () {
2453 msg "build: make with PSA alt headers" # ~20s
2454
2455 # Generate alternative versions of the substitutable headers with the
2456 # same content except different include guards.
David Horstmanndc459512024-11-07 17:08:11 +00002457 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 +01002458
2459 # Build the library and some programs.
2460 # Don't build the fuzzers to avoid having to go through hoops to set
2461 # a correct include path for programs/fuzz/Makefile.
David Horstmann5b93d972024-10-31 15:36:05 +00002462 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
2463 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 +01002464
2465 # Check that we're getting the alternative include guards and not the
2466 # original include guards.
2467 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
2468 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
2469 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
2470 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
2471}
2472
2473component_test_min_mpi_window_size () {
2474 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
2475 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
2476 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2477 make
2478
2479 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2480 make test
2481}
Ronald Cronf256f8a2025-07-10 17:37:18 +02002482
2483component_test_xts () {
2484 # Component dedicated to run XTS unit test cases while XTS is not
2485 # supported through the PSA API.
2486 msg "build: Default + MBEDTLS_CIPHER_MODE_XTS"
2487
2488 echo "#define MBEDTLS_CIPHER_MODE_XTS" > psa_user_config.h
2489 cmake -DTF_PSA_CRYPTO_USER_CONFIG_FILE="psa_user_config.h"
2490 make
2491
Ronald Crone0b06eb2025-07-15 08:58:32 +02002492 rm -f psa_user_config.h
2493
Ronald Cronf256f8a2025-07-10 17:37:18 +02002494 msg "test: Default + MBEDTLS_CIPHER_MODE_XTS"
2495 make test
Ronald Cronf256f8a2025-07-10 17:37:18 +02002496}