blob: 8e9df371cf7157d100bb7f9c850748c64f16a2b1 [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.
Minos Galanakis00b641c2024-11-28 23:05:10 +000085 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
86 scripts/config.py -c $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_HKDF"
87 scripts/config.py -c $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_PBKDF2_"
88 scripts/config.py -c $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_TLS12_"
Valerio Settia47b0452024-06-25 18:31:36 +020089 # RSA key support requires ASN1 parse/write support for testing, but ASN1
90 # is disabled below.
Minos Galanakis00b641c2024-11-28 23:05:10 +000091 scripts/config.py -c $CRYPTO_CONFIG_H unset-all "^PSA_WANT_KEY_TYPE_RSA_"
92 scripts/config.py -c $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_RSA_"
Valerio Settia47b0452024-06-25 18:31:36 +020093 # DES requires built-in support for key generation (parity check) so it
94 # cannot be accelerated
Minos Galanakis00b641c2024-11-28 23:05:10 +000095 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
Valerio Settia47b0452024-06-25 18:31:36 +020096 # EC-JPAKE use calloc/free in PSA core
Minos Galanakis00b641c2024-11-28 23:05:10 +000097 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE
Valerio Settia47b0452024-06-25 18:31:36 +020098
99 # Accelerate all PSA features (which are still enabled in CRYPTO_CONFIG_H).
Minos Galanakis00b641c2024-11-28 23:05:10 +0000100 PSA_SYM_LIST=$(./scripts/config.py -c $CRYPTO_CONFIG_H get-all-enabled PSA_WANT)
Valerio Settia47b0452024-06-25 18:31:36 +0200101 loc_accel_list=$(echo $PSA_SYM_LIST | sed 's/PSA_WANT_//g')
102
Valerio Settia47b0452024-06-25 18:31:36 +0200103 helper_libtestdriver1_adjust_config crypto
104 helper_libtestdriver1_make_drivers "$loc_accel_list"
105
Valerio Setti13aadd72024-08-13 13:13:23 +0200106 msg "crypto without heap: build main library"
Valerio Setti35b0b022024-08-13 13:36:50 +0200107 # Disable all legacy MBEDTLS_xxx symbols.
108 scripts/config.py unset-all "^MBEDTLS_"
109 # Build the PSA core using the proper config file.
110 scripts/config.py set MBEDTLS_PSA_CRYPTO_C
Valerio Settia47b0452024-06-25 18:31:36 +0200111 # Enable fully-static key slots in PSA core.
112 scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOTS
Valerio Setti35b0b022024-08-13 13:36:50 +0200113 # Prevent PSA core from creating a copy of input/output buffers.
Valerio Settia47b0452024-06-25 18:31:36 +0200114 scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
115 # Prevent PSA core from using CTR-DRBG or HMAC-DRBG for random generation.
116 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Valerio Setti13aadd72024-08-13 13:13:23 +0200117 # Set calloc/free as null pointer functions. Calling them would crash
Valerio Settia47b0452024-06-25 18:31:36 +0200118 # the program so we can use this as a "sentinel" for being sure no module
119 # is making use of these functions in the library.
Valerio Setti35b0b022024-08-13 13:36:50 +0200120 scripts/config.py set MBEDTLS_PLATFORM_C
Valerio Settia47b0452024-06-25 18:31:36 +0200121 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
122 scripts/config.py set MBEDTLS_PLATFORM_STD_CALLOC NULL
123 scripts/config.py set MBEDTLS_PLATFORM_STD_FREE NULL
124
Valerio Settia47b0452024-06-25 18:31:36 +0200125 helper_libtestdriver1_make_main "$loc_accel_list" lib
126
Valerio Setti13aadd72024-08-13 13:13:23 +0200127 msg "crypto without heap: build test suites and helpers"
128 # Reset calloc/free functions to normal operations so that test code can
Valerio Settia47b0452024-06-25 18:31:36 +0200129 # freely use them.
130 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
131 scripts/config.py unset MBEDTLS_PLATFORM_STD_CALLOC
132 scripts/config.py unset MBEDTLS_PLATFORM_STD_FREE
133 helper_libtestdriver1_make_main "$loc_accel_list" tests
134
Valerio Setti13aadd72024-08-13 13:13:23 +0200135 msg "crypto without heap: test"
Valerio Settia47b0452024-06-25 18:31:36 +0200136 make test
137}
138
Minos Galanakisf78447f2024-07-26 20:49:51 +0100139component_test_no_rsa_key_pair_generation () {
Minos Galanakisdc0f73a2024-07-26 20:41:42 +0100140 msg "build: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
Minos Galanakis00b641c2024-11-28 23:05:10 +0000141 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Minos Galanakisdc0f73a2024-07-26 20:41:42 +0100142 make
143
144 msg "test: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
145 make test
146}
147
Minos Galanakisc06fd302024-08-01 12:16:59 +0100148component_test_no_pem_no_fs () {
149 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
150 scripts/config.py unset MBEDTLS_PEM_PARSE_C
151 scripts/config.py unset MBEDTLS_FS_IO
152 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
153 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
154 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
155 make
156
157 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
158 make test
159
160 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
161 tests/ssl-opt.sh
162}
163
164component_test_rsa_no_crt () {
165 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
166 scripts/config.py set MBEDTLS_RSA_NO_CRT
167 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
168 make
169
170 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
171 make test
172
173 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
174 tests/ssl-opt.sh -f RSA
175
176 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
177 tests/compat.sh -t RSA
178
179 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
180 tests/context-info.sh
181}
182
Minos Galanakisc06fd302024-08-01 12:16:59 +0100183component_test_no_ctr_drbg_use_psa () {
184 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
185 scripts/config.py full
186 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Minos Galanakisc06fd302024-08-01 12:16:59 +0100187
188 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
189 make
190
191 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
192 make test
193
194 # In this configuration, the TLS test programs use HMAC_DRBG.
195 # The SSL tests are slow, so run a small subset, just enough to get
196 # confidence that the SSL code copes with HMAC_DRBG.
197 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
198 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
199
200 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
201 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
202}
203
Minos Galanakisc06fd302024-08-01 12:16:59 +0100204component_test_no_hmac_drbg_use_psa () {
205 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
206 scripts/config.py full
207 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
208 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Minos Galanakisc06fd302024-08-01 12:16:59 +0100209
210 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
211 make
212
213 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
214 make test
215
216 # Normally our ECDSA implementation uses deterministic ECDSA. But since
217 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
218 # instead.
219 # Test SSL with non-deterministic ECDSA. Only test features that
220 # might be affected by how ECDSA signature is performed.
221 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
222 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
223
224 # To save time, only test one protocol version, since this part of
225 # the protocol is identical in (D)TLS up to 1.2.
226 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
227 tests/compat.sh -m tls12 -t 'ECDSA'
228}
229
Minos Galanakisc06fd302024-08-01 12:16:59 +0100230component_test_psa_external_rng_no_drbg_use_psa () {
231 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
232 scripts/config.py full
233 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
234 scripts/config.py unset MBEDTLS_ENTROPY_C
235 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
236 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
237 scripts/config.py unset MBEDTLS_CTR_DRBG_C
238 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
239 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
240 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
241
242 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
243 make test
244
245 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
246 tests/ssl-opt.sh -f 'Default\|opaque'
247}
248
Minos Galanakis471b34c2024-07-26 15:39:24 +0100249component_test_psa_external_rng_use_psa_crypto () {
250 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
251 scripts/config.py full
252 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Minos Galanakis471b34c2024-07-26 15:39:24 +0100253 scripts/config.py unset MBEDTLS_CTR_DRBG_C
254 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
255
256 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
257 make test
258
259 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
260 tests/ssl-opt.sh -f 'Default\|opaque'
261}
262
Minos Galanakisf78447f2024-07-26 20:49:51 +0100263component_full_no_pkparse_pkwrite () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100264 msg "build: full without pkparse and pkwrite"
265
266 scripts/config.py crypto_full
267 scripts/config.py unset MBEDTLS_PK_PARSE_C
268 scripts/config.py unset MBEDTLS_PK_WRITE_C
269
270 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
271
272 # Ensure that PK_[PARSE|WRITE]_C were not re-enabled accidentally (additive config).
273 not grep mbedtls_pk_parse_key ${BUILTIN_SRC_PATH}/pkparse.o
274 not grep mbedtls_pk_write_key_der ${BUILTIN_SRC_PATH}/pkwrite.o
275
276 msg "test: full without pkparse and pkwrite"
277 make test
278}
279
280component_test_crypto_full_md_light_only () {
281 msg "build: crypto_full with only the light subset of MD"
282 scripts/config.py crypto_full
283
284 # Disable MD
285 scripts/config.py unset MBEDTLS_MD_C
286 # Disable direct dependencies of MD_C
287 scripts/config.py unset MBEDTLS_HKDF_C
288 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
289 scripts/config.py unset MBEDTLS_PKCS7_C
290 # Disable indirect dependencies of MD_C
291 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG
Minos Galanakis00b641c2024-11-28 23:05:10 +0000292 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
Minos Galanakis471b34c2024-07-26 15:39:24 +0100293 # Disable things that would auto-enable MD_C
294 scripts/config.py unset MBEDTLS_PKCS5_C
295
296 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
297 # which we haven't disabled, so no need to explicitly enable it.
298 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
299
300 # Make sure we don't have the HMAC functions, but the hashing functions
301 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
302 grep mbedtls_md ${BUILTIN_SRC_PATH}/md.o
303
304 msg "test: crypto_full with only the light subset of MD"
305 make test
306}
307
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100308component_test_full_no_cipher () {
309 msg "build: full no CIPHER"
310
311 scripts/config.py full
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100312
313 # The built-in implementation of the following algs/key-types depends
314 # on CIPHER_C so we disable them.
315 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
316 # so we keep them enabled.
Minos Galanakis00b641c2024-11-28 23:05:10 +0000317 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
318 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CMAC
319 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
320 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
321 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CFB
322 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CTR
323 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
324 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_OFB
325 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
326 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_STREAM_CIPHER
327 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100328
329 # The following modules directly depends on CIPHER_C
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100330 scripts/config.py unset MBEDTLS_NIST_KW_C
331
332 make
333
334 # Ensure that CIPHER_C was not re-enabled
335 not grep mbedtls_cipher_init ${BUILTIN_SRC_PATH}/cipher.o
336
337 msg "test: full no CIPHER"
338 make test
339}
340
Minos Galanakisf78447f2024-07-26 20:49:51 +0100341component_test_full_no_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100342 msg "build: full no PSA_WANT_ALG_CCM"
343
344 # Full config enables:
345 # - USE_PSA_CRYPTO so that TLS code dispatches cipher/AEAD to PSA
346 # - CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
347 scripts/config.py full
348
349 # Disable PSA_WANT_ALG_CCM so that CCM is not supported in PSA. CCM_C is still
350 # enabled, but not used from TLS since USE_PSA is set.
351 # This is helpful to ensure that TLS tests below have proper dependencies.
352 #
353 # Note: also PSA_WANT_ALG_CCM_STAR_NO_TAG is enabled, but it does not cause
354 # PSA_WANT_ALG_CCM to be re-enabled.
355 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM
356
357 make
358
359 msg "test: full no PSA_WANT_ALG_CCM"
360 make test
361}
362
Minos Galanakisf78447f2024-07-26 20:49:51 +0100363component_test_full_no_ccm_star_no_tag () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100364 msg "build: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
365
366 # Full config enables CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
367 scripts/config.py full
368
369 # Disable CCM_STAR_NO_TAG, which is the target of this test, as well as all
370 # other components that enable MBEDTLS_PSA_BUILTIN_CIPHER internal symbol.
371 # This basically disables all unauthenticated ciphers on the PSA side, while
372 # keeping AEADs enabled.
373 #
374 # Note: PSA_WANT_ALG_CCM is enabled, but it does not cause
375 # PSA_WANT_ALG_CCM_STAR_NO_TAG to be re-enabled.
376 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
377 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_STREAM_CIPHER
378 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
379 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
380 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
381 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
Ben Taylor1948c942025-03-04 09:11:11 +0000382 # NOTE unsettting PSA_WANT_ALG_ECB_NO_PADDING without unsetting NIST_KW_C will
383 # mean PSA_WANT_ALG_ECB_NO_PADDING is re-enabled, so disabling it also.
384 scripts/config.py -f "$CRYPTO_CONFIG_H" unset MBEDTLS_NIST_KW_C
Minos Galanakis471b34c2024-07-26 15:39:24 +0100385 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
386 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
387
388 make
389
390 # Ensure MBEDTLS_PSA_BUILTIN_CIPHER was not enabled
391 not grep mbedtls_psa_cipher ${PSA_CORE_PATH}/psa_crypto_cipher.o
392
393 msg "test: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
394 make test
395}
396
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200397component_test_config_symmetric_only () {
398 msg "build: configs/config-symmetric-only.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +0000399 MBEDTLS_CONFIG="configs/config-symmetric-only.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +0000400 CRYPTO_CONFIG="tf-psa-crypto/configs/crypto-config-symmetric-only.h"
Ronald Cronfaadfc22024-12-07 17:24:28 +0100401 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 +0200402 make
403
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200404 msg "test: configs/config-symmetric-only.h - unit tests"
Gilles Peskineaf5a8992024-09-14 11:27:44 +0200405 make test
406}
407
Minos Galanakisc06fd302024-08-01 12:16:59 +0100408component_test_everest () {
409 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
410 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
411 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
412 make
413
414 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
415 make test
416
417 msg "test: metatests (clang, ASan)"
418 tests/scripts/run-metatests.sh any asan poison
419
420 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
421 tests/ssl-opt.sh -f ECDH
422
423 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
424 # Exclude some symmetric ciphers that are redundant here to gain time.
425 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
426}
427
428component_test_everest_curve25519_only () {
429 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
Minos Galanakisc06fd302024-08-01 12:16:59 +0100430 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
431 scripts/config.py unset MBEDTLS_ECDSA_C
Minos Galanakis00b641c2024-11-28 23:05:10 +0000432 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
433 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECDSA
434 scripts/config.py -c $CRYPTO_CONFIG_H set PSA_WANT_ALG_ECDH
Minos Galanakisc06fd302024-08-01 12:16:59 +0100435 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
436 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
437 scripts/config.py unset MBEDTLS_ECJPAKE_C
Minos Galanakis00b641c2024-11-28 23:05:10 +0000438 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE
Minos Galanakisc06fd302024-08-01 12:16:59 +0100439
440 # Disable all curves
441 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
Minos Galanakis00b641c2024-11-28 23:05:10 +0000442 scripts/config.py -c $CRYPTO_CONFIG_H unset-all "PSA_WANT_ECC_[0-9A-Z_a-z]*$"
443 scripts/config.py -c $CRYPTO_CONFIG_H set PSA_WANT_ECC_MONTGOMERY_255
Minos Galanakisc06fd302024-08-01 12:16:59 +0100444
445 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
446
447 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
448 make test
449}
450
Minos Galanakis471b34c2024-07-26 15:39:24 +0100451component_test_psa_collect_statuses () {
452 msg "build+test: psa_collect_statuses" # ~30s
453 scripts/config.py full
454 tests/scripts/psa_collect_statuses.py
455 # Check that psa_crypto_init() succeeded at least once
456 grep -q '^0:psa_crypto_init:' tests/statuses.log
457 rm -f tests/statuses.log
458}
459
460# Check that the specified libraries exist and are empty.
461are_empty_libraries () {
462 nm "$@" >/dev/null 2>/dev/null
463 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
464}
465
Minos Galanakis471b34c2024-07-26 15:39:24 +0100466component_test_crypto_for_psa_service () {
467 msg "build: make, config for PSA crypto service"
468 scripts/config.py crypto
469 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
470 # Disable things that are not needed for just cryptography, to
471 # reach a configuration that would be typical for a PSA cryptography
472 # service providing all implemented PSA algorithms.
473 # System stuff
474 scripts/config.py unset MBEDTLS_ERROR_C
475 scripts/config.py unset MBEDTLS_TIMING_C
476 scripts/config.py unset MBEDTLS_VERSION_FEATURES
477 # Crypto stuff with no PSA interface
478 scripts/config.py unset MBEDTLS_BASE64_C
Minos Galanakis471b34c2024-07-26 15:39:24 +0100479 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
480 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
481 scripts/config.py unset MBEDTLS_NIST_KW_C
482 scripts/config.py unset MBEDTLS_PEM_PARSE_C
483 scripts/config.py unset MBEDTLS_PEM_WRITE_C
484 scripts/config.py unset MBEDTLS_PKCS12_C
485 scripts/config.py unset MBEDTLS_PKCS5_C
486 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
487 # in PSA code to work with RSA keys. We don't require users to set those:
488 # they will be reenabled in build_info.h.
489 scripts/config.py unset MBEDTLS_PK_C
490 scripts/config.py unset MBEDTLS_PK_PARSE_C
491 scripts/config.py unset MBEDTLS_PK_WRITE_C
492 make CFLAGS='-O1 -Werror' all test
493 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
494}
495
496component_build_crypto_baremetal () {
497 msg "build: make, crypto only, baremetal config"
498 scripts/config.py crypto_baremetal
David Horstmann5b93d972024-10-31 15:36:05 +0000499 make CFLAGS="-O1 -Werror -I$PWD/framework/tests/include/baremetal-override/"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100500 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
501}
502
503support_build_crypto_baremetal () {
504 support_build_baremetal "$@"
505}
506
507# depends.py family of tests
508component_test_depends_py_cipher_id () {
509 msg "test/build: depends.py cipher_id (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200510 tests/scripts/depends.py cipher_id
Minos Galanakis471b34c2024-07-26 15:39:24 +0100511}
512
513component_test_depends_py_cipher_chaining () {
514 msg "test/build: depends.py cipher_chaining (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200515 tests/scripts/depends.py cipher_chaining
Minos Galanakis471b34c2024-07-26 15:39:24 +0100516}
517
Minos Galanakis471b34c2024-07-26 15:39:24 +0100518component_test_depends_py_curves () {
519 msg "test/build: depends.py curves (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200520 tests/scripts/depends.py curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100521}
522
523component_test_depends_py_hashes () {
524 msg "test/build: depends.py hashes (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200525 tests/scripts/depends.py hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +0100526}
527
Minos Galanakis471b34c2024-07-26 15:39:24 +0100528component_test_depends_py_pkalgs () {
529 msg "test/build: depends.py pkalgs (gcc)"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100530 tests/scripts/depends.py pkalgs
531}
532
533component_test_psa_crypto_config_ffdh_2048_only () {
534 msg "build: full config - only DH 2048"
535
536 scripts/config.py full
537
538 # Disable all DH groups other than 2048.
539 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_3072
540 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_4096
541 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_6144
542 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_8192
543
544 make CFLAGS="$ASAN_CFLAGS -Werror" LDFLAGS="$ASAN_CFLAGS"
545
546 msg "test: full config - only DH 2048"
547 make test
548
549 msg "ssl-opt: full config - only DH 2048"
550 tests/ssl-opt.sh -f "ffdh"
551}
552
Minos Galanakis471b34c2024-07-26 15:39:24 +0100553component_test_psa_crypto_config_accel_ecdsa () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200554 msg "build: accelerated ECDSA"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100555
Minos Galanakis471b34c2024-07-26 15:39:24 +0100556 # Configure
557 # ---------
558
Elena Uziunaite91d83862024-09-04 14:51:31 +0100559 # Start from default config + TLS 1.3
Minos Galanakis471b34c2024-07-26 15:39:24 +0100560 helper_libtestdriver1_adjust_config "default"
561
Valerio Setti37a42812025-08-11 12:52:49 +0200562 # Algorithms and key types to accelerate
563 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
564 $(helper_get_psa_key_type_list "ECC") \
565 $(helper_get_psa_curve_list)"
566
Minos Galanakis471b34c2024-07-26 15:39:24 +0100567 # Disable the module that's accelerated
568 scripts/config.py unset MBEDTLS_ECDSA_C
569
570 # Disable things that depend on it
571 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
572 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
573
574 # Build
575 # -----
576
577 # These hashes are needed for some ECDSA signature tests.
Elena Uziunaiteffce45c2024-09-12 14:58:52 +0100578 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 +0100579 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
580
581 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
582
583 helper_libtestdriver1_make_main "$loc_accel_list"
584
585 # Make sure this was not re-enabled by accident (additive config)
586 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
587
588 # Run the tests
589 # -------------
590
Ronald Cron93ba6252024-09-05 10:37:14 +0200591 msg "test: accelerated ECDSA"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100592 make test
593}
594
595component_test_psa_crypto_config_accel_ecdh () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200596 msg "build: accelerated ECDH"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100597
Minos Galanakis471b34c2024-07-26 15:39:24 +0100598 # Configure
599 # ---------
600
601 # Start from default config (no USE_PSA)
602 helper_libtestdriver1_adjust_config "default"
603
Valerio Setti37a42812025-08-11 12:52:49 +0200604 # Algorithms and key types to accelerate
605 loc_accel_list="ALG_ECDH \
606 $(helper_get_psa_key_type_list "ECC") \
607 $(helper_get_psa_curve_list)"
608
Minos Galanakis471b34c2024-07-26 15:39:24 +0100609 # Disable the module that's accelerated
610 scripts/config.py unset MBEDTLS_ECDH_C
611
612 # Disable things that depend on it
613 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
614 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
615 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
616 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
617 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
618
619 # Build
620 # -----
621
622 helper_libtestdriver1_make_drivers "$loc_accel_list"
623
624 helper_libtestdriver1_make_main "$loc_accel_list"
625
626 # Make sure this was not re-enabled by accident (additive config)
627 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
628
629 # Run the tests
630 # -------------
631
Ronald Cron93ba6252024-09-05 10:37:14 +0200632 msg "test: accelerated ECDH"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100633 make test
634}
635
636component_test_psa_crypto_config_accel_ffdh () {
637 msg "build: full with accelerated FFDH"
638
Minos Galanakis471b34c2024-07-26 15:39:24 +0100639 # Configure
640 # ---------
641
642 # start with full (USE_PSA and TLS 1.3)
643 helper_libtestdriver1_adjust_config "full"
644
Valerio Setti37a42812025-08-11 12:52:49 +0200645 # Algorithms and key types to accelerate
646 loc_accel_list="ALG_FFDH \
647 $(helper_get_psa_key_type_list "DH") \
648 $(helper_get_psa_dh_group_list)"
649
Minos Galanakis471b34c2024-07-26 15:39:24 +0100650 # Build
651 # -----
652
653 helper_libtestdriver1_make_drivers "$loc_accel_list"
654
655 helper_libtestdriver1_make_main "$loc_accel_list"
656
657 # Make sure this was not re-enabled by accident (additive config)
Valerio Settieb63eb22025-02-12 13:32:49 +0100658 not grep mbedtls_psa_ffdh_key_agreement ${BUILTIN_SRC_PATH}/psa_crypto_ffdh.o
Minos Galanakis471b34c2024-07-26 15:39:24 +0100659
660 # Run the tests
661 # -------------
662
663 msg "test: full with accelerated FFDH"
664 make test
665
666 msg "ssl-opt: full with accelerated FFDH alg"
667 tests/ssl-opt.sh -f "ffdh"
668}
669
670component_test_psa_crypto_config_reference_ffdh () {
671 msg "build: full with non-accelerated FFDH"
672
673 # Start with full (USE_PSA and TLS 1.3)
674 helper_libtestdriver1_adjust_config "full"
675
Minos Galanakis471b34c2024-07-26 15:39:24 +0100676 make
677
678 msg "test suites: full with non-accelerated FFDH alg"
679 make test
680
681 msg "ssl-opt: full with non-accelerated FFDH alg"
682 tests/ssl-opt.sh -f "ffdh"
683}
684
Minos Galanakisf78447f2024-07-26 20:49:51 +0100685component_test_psa_crypto_config_accel_pake () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100686 msg "build: full with accelerated PAKE"
687
Minos Galanakis471b34c2024-07-26 15:39:24 +0100688 # Configure
689 # ---------
690
691 helper_libtestdriver1_adjust_config "full"
692
Valerio Setti37a42812025-08-11 12:52:49 +0200693 loc_accel_list="ALG_JPAKE \
694 $(helper_get_psa_key_type_list "ECC") \
695 $(helper_get_psa_curve_list)"
696
Minos Galanakis471b34c2024-07-26 15:39:24 +0100697 # Make built-in fallback not available
698 scripts/config.py unset MBEDTLS_ECJPAKE_C
699 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
700
701 # Build
702 # -----
703
704 helper_libtestdriver1_make_drivers "$loc_accel_list"
705
706 helper_libtestdriver1_make_main "$loc_accel_list"
707
708 # Make sure this was not re-enabled by accident (additive config)
709 not grep mbedtls_ecjpake_init ${BUILTIN_SRC_PATH}/ecjpake.o
710
711 # Run the tests
712 # -------------
713
714 msg "test: full with accelerated PAKE"
715 make test
716}
717
718component_test_psa_crypto_config_accel_ecc_some_key_types () {
719 msg "build: full with accelerated EC algs and some key types"
720
Valerio Setti37a42812025-08-11 12:52:49 +0200721 # Configure
722 # ---------
723
724 # start with config full for maximum coverage (also enables USE_PSA)
725 helper_libtestdriver1_adjust_config "full"
726
Minos Galanakis471b34c2024-07-26 15:39:24 +0100727 # Algorithms and key types to accelerate
728 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
729 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
730 ALG_ECDH \
731 ALG_JPAKE \
732 KEY_TYPE_ECC_PUBLIC_KEY \
733 KEY_TYPE_ECC_KEY_PAIR_BASIC \
734 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
735 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
736 $(helper_get_psa_curve_list)"
737
Minos Galanakis471b34c2024-07-26 15:39:24 +0100738 # Disable modules that are accelerated - some will be re-enabled
739 scripts/config.py unset MBEDTLS_ECDSA_C
740 scripts/config.py unset MBEDTLS_ECDH_C
741 scripts/config.py unset MBEDTLS_ECJPAKE_C
742 scripts/config.py unset MBEDTLS_ECP_C
743
744 # Disable all curves - those that aren't accelerated should be re-enabled
745 helper_disable_builtin_curves
746
747 # Restartable feature is not yet supported by PSA. Once it will in
748 # the future, the following line could be removed (see issues
749 # 6061, 6332 and following ones)
750 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
751
752 # this is not supported by the driver API yet
753 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
754
755 # Build
756 # -----
757
758 # These hashes are needed for some ECDSA signature tests.
759 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
760 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
761 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
762
763 helper_libtestdriver1_make_main "$loc_accel_list"
764
765 # ECP should be re-enabled but not the others
766 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
767 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
768 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
769 grep mbedtls_ecp ${BUILTIN_SRC_PATH}/ecp.o
770
771 # Run the tests
772 # -------------
773
774 msg "test suites: full with accelerated EC algs and some key types"
775 make test
776}
777
778# Run tests with only (non-)Weierstrass accelerated
779# Common code used in:
780# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
781# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100782common_test_psa_crypto_config_accel_ecc_some_curves () {
783 weierstrass=$1
784 if [ $weierstrass -eq 1 ]; then
785 desc="Weierstrass"
786 else
787 desc="non-Weierstrass"
788 fi
789
790 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
791
Valerio Setti37a42812025-08-11 12:52:49 +0200792 # Configure
793 # ---------
794
795 # Start with config crypto_full and remove PK_C:
796 # that's what's supported now, see docs/driver-only-builds.md.
797 helper_libtestdriver1_adjust_config "crypto_full"
798 scripts/config.py unset MBEDTLS_PK_C
799 scripts/config.py unset MBEDTLS_PK_PARSE_C
800 scripts/config.py unset MBEDTLS_PK_WRITE_C
801
802 # Disable modules that are accelerated - some will be re-enabled
803 scripts/config.py unset MBEDTLS_ECDSA_C
804 scripts/config.py unset MBEDTLS_ECDH_C
805 scripts/config.py unset MBEDTLS_ECJPAKE_C
806 scripts/config.py unset MBEDTLS_ECP_C
807
808 # Disable all curves - those that aren't accelerated should be re-enabled
809 helper_disable_builtin_curves
810
811 # Note: Curves are handled in a special way by the libtestdriver machinery,
Minos Galanakis471b34c2024-07-26 15:39:24 +0100812 # so we only want to include them in the accel list when building the main
813 # libraries, hence the use of a separate variable.
814 # Note: the following loop is a modified version of
815 # helper_get_psa_curve_list that only keeps Weierstrass families.
816 loc_weierstrass_list=""
817 loc_non_weierstrass_list=""
818 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
819 case $item in
820 ECC_BRAINPOOL*|ECC_SECP*)
821 loc_weierstrass_list="$loc_weierstrass_list $item"
822 ;;
823 *)
824 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
825 ;;
826 esac
827 done
828 if [ $weierstrass -eq 1 ]; then
829 loc_curve_list=$loc_weierstrass_list
830 else
831 loc_curve_list=$loc_non_weierstrass_list
832 fi
833
834 # Algorithms and key types to accelerate
835 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
836 ALG_ECDH \
837 ALG_JPAKE \
838 $(helper_get_psa_key_type_list "ECC") \
839 $loc_curve_list"
840
Minos Galanakis471b34c2024-07-26 15:39:24 +0100841 # Restartable feature is not yet supported by PSA. Once it will in
842 # the future, the following line could be removed (see issues
843 # 6061, 6332 and following ones)
844 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
845
846 # this is not supported by the driver API yet
847 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
848
849 # Build
850 # -----
851
852 # These hashes are needed for some ECDSA signature tests.
853 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
854 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
855 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
856
857 helper_libtestdriver1_make_main "$loc_accel_list"
858
859 # We expect ECDH to be re-enabled for the missing curves
860 grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
861 # We expect ECP to be re-enabled, however the parts specific to the
862 # families of curves that are accelerated should be ommited.
863 # - functions with mxz in the name are specific to Montgomery curves
864 # - ecp_muladd is specific to Weierstrass curves
865 ##nm ${BUILTIN_SRC_PATH}/ecp.o | tee ecp.syms
866 if [ $weierstrass -eq 1 ]; then
867 not grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
868 grep mxz ${BUILTIN_SRC_PATH}/ecp.o
869 else
870 grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
871 not grep mxz ${BUILTIN_SRC_PATH}/ecp.o
872 fi
873 # We expect ECDSA and ECJPAKE to be re-enabled only when
874 # Weierstrass curves are not accelerated
875 if [ $weierstrass -eq 1 ]; then
876 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
877 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
878 else
879 grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
880 grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
881 fi
882
883 # Run the tests
884 # -------------
885
886 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
Valerio Setti37a42812025-08-11 12:52:49 +0200887 # make test
888 (
889 cd tf-psa-crypto/tests
890 ./test_suite_psa_crypto_driver_wrappers
891 )
Minos Galanakis471b34c2024-07-26 15:39:24 +0100892}
893
894component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
895 common_test_psa_crypto_config_accel_ecc_some_curves 1
896}
897
898component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
899 common_test_psa_crypto_config_accel_ecc_some_curves 0
900}
901
902# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
903# ECDH, ECDSA) with and without drivers.
904# The input parameter is a boolean value which indicates:
905# - 0 keep built-in EC algs,
906# - 1 exclude built-in EC algs (driver only).
907#
908# This is used by the two following components to ensure they always use the
909# same config, except for the use of driver or built-in EC algorithms:
910# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
911# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
912# This supports comparing their test coverage with analyze_outcomes.py.
Minos Galanakis471b34c2024-07-26 15:39:24 +0100913config_psa_crypto_config_ecp_light_only () {
914 driver_only="$1"
915 # start with config full for maximum coverage (also enables USE_PSA)
916 helper_libtestdriver1_adjust_config "full"
917 if [ "$driver_only" -eq 1 ]; then
918 # Disable modules that are accelerated
919 scripts/config.py unset MBEDTLS_ECDSA_C
920 scripts/config.py unset MBEDTLS_ECDH_C
921 scripts/config.py unset MBEDTLS_ECJPAKE_C
922 scripts/config.py unset MBEDTLS_ECP_C
923 fi
924
925 # Restartable feature is not yet supported by PSA. Once it will in
926 # the future, the following line could be removed (see issues
927 # 6061, 6332 and following ones)
928 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
929}
930
931# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100932component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
933 msg "build: full with accelerated EC algs"
934
Valerio Setti37a42812025-08-11 12:52:49 +0200935 # Configure
936 # ---------
937
938 # Use the same config as reference, only without built-in EC algs
939 config_psa_crypto_config_ecp_light_only 1
940
Minos Galanakis471b34c2024-07-26 15:39:24 +0100941 # Algorithms and key types to accelerate
942 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
943 ALG_ECDH \
944 ALG_JPAKE \
945 $(helper_get_psa_key_type_list "ECC") \
946 $(helper_get_psa_curve_list)"
947
Minos Galanakis471b34c2024-07-26 15:39:24 +0100948 # Do not disable builtin curves because that support is required for:
949 # - MBEDTLS_PK_PARSE_EC_EXTENDED
950 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
951
952 # Build
953 # -----
954
955 # These hashes are needed for some ECDSA signature tests.
956 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
957 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
958 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
959
960 helper_libtestdriver1_make_main "$loc_accel_list"
961
962 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
963 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
964 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
965 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
966 not grep mbedtls_ecp_mul ${BUILTIN_SRC_PATH}/ecp.o
967
968 # Run the tests
969 # -------------
970
971 msg "test suites: full with accelerated EC algs"
972 make test
973
974 msg "ssl-opt: full with accelerated EC algs"
975 tests/ssl-opt.sh
976}
977
978# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100979component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200980 msg "build: non-accelerated EC algs"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100981
982 config_psa_crypto_config_ecp_light_only 0
983
984 make
985
986 msg "test suites: full with non-accelerated EC algs"
987 make test
988
989 msg "ssl-opt: full with non-accelerated EC algs"
990 tests/ssl-opt.sh
991}
992
993# This helper function is used by:
994# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
995# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
996# to ensure that both tests use the same underlying configuration when testing
997# driver's coverage with analyze_outcomes.py.
998#
999# This functions accepts 1 boolean parameter as follows:
1000# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
1001# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
1002# - 0: include built-in implementation of EC algorithms.
1003#
1004# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
1005# on the ECP module.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001006config_psa_crypto_no_ecp_at_all () {
1007 driver_only="$1"
1008 # start with full config for maximum coverage (also enables USE_PSA)
1009 helper_libtestdriver1_adjust_config "full"
1010
1011 if [ "$driver_only" -eq 1 ]; then
1012 # Disable modules that are accelerated
1013 scripts/config.py unset MBEDTLS_ECDSA_C
1014 scripts/config.py unset MBEDTLS_ECDH_C
1015 scripts/config.py unset MBEDTLS_ECJPAKE_C
1016 # Disable ECP module (entirely)
1017 scripts/config.py unset MBEDTLS_ECP_C
1018 fi
1019
1020 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1021 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1022 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1023 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1024
1025 # Restartable feature is not yet supported by PSA. Once it will in
1026 # the future, the following line could be removed (see issues
1027 # 6061, 6332 and following ones)
1028 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1029}
1030
1031# Build and test a configuration where driver accelerates all EC algs while
1032# all support and dependencies from ECP and ECP_LIGHT are removed on the library
1033# side.
1034#
1035# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001036component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
1037 msg "build: full + accelerated EC algs - ECP"
1038
Minos Galanakis471b34c2024-07-26 15:39:24 +01001039 # Configure
1040 # ---------
1041
1042 # Set common configurations between library's and driver's builds
1043 config_psa_crypto_no_ecp_at_all 1
1044 # Disable all the builtin curves. All the required algs are accelerated.
1045 helper_disable_builtin_curves
1046
Valerio Setti37a42812025-08-11 12:52:49 +02001047 # Algorithms and key types to accelerate
1048 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1049 ALG_ECDH \
1050 ALG_JPAKE \
1051 $(helper_get_psa_key_type_list "ECC") \
1052 $(helper_get_psa_curve_list)"
1053
Minos Galanakis471b34c2024-07-26 15:39:24 +01001054 # Build
1055 # -----
1056
1057 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1058 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1059 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1060 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1061
1062 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1063
1064 helper_libtestdriver1_make_main "$loc_accel_list"
1065
1066 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1067 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1068 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1069 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1070 # Also ensure that ECP module was not re-enabled
1071 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1072
1073 # Run the tests
1074 # -------------
1075
1076 msg "test: full + accelerated EC algs - ECP"
1077 make test
1078
1079 msg "ssl-opt: full + accelerated EC algs - ECP"
1080 tests/ssl-opt.sh
1081}
1082
1083# Reference function used for driver's coverage analysis in analyze_outcomes.py
1084# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
1085# Keep in sync with its accelerated counterpart.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001086component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
1087 msg "build: full + non accelerated EC algs"
1088
1089 config_psa_crypto_no_ecp_at_all 0
1090
1091 make
1092
1093 msg "test: full + non accelerated EC algs"
1094 make test
1095
1096 msg "ssl-opt: full + non accelerated EC algs"
1097 tests/ssl-opt.sh
1098}
1099
1100# This is a common configuration helper used directly from:
1101# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1102# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1103# and indirectly from:
1104# - component_test_psa_crypto_config_accel_ecc_no_bignum
1105# - accelerate all EC algs, disable RSA and FFDH
1106# - component_test_psa_crypto_config_reference_ecc_no_bignum
1107# - this is the reference component of the above
1108# - it still disables RSA and FFDH, but it uses builtin EC algs
1109# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1110# - accelerate all EC and FFDH algs, disable only RSA
1111# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1112# - this is the reference component of the above
1113# - it still disables RSA, but it uses builtin EC and FFDH algs
1114#
1115# This function accepts 2 parameters:
1116# $1: a boolean value which states if we are testing an accelerated scenario
1117# or not.
1118# $2: a string value which states which components are tested. Allowed values
1119# are "ECC" or "ECC_DH".
Minos Galanakisf78447f2024-07-26 20:49:51 +01001120config_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001121 driver_only="$1"
1122 test_target="$2"
1123 # start with full config for maximum coverage (also enables USE_PSA)
1124 helper_libtestdriver1_adjust_config "full"
1125
1126 if [ "$driver_only" -eq 1 ]; then
1127 # Disable modules that are accelerated
1128 scripts/config.py unset MBEDTLS_ECDSA_C
1129 scripts/config.py unset MBEDTLS_ECDH_C
1130 scripts/config.py unset MBEDTLS_ECJPAKE_C
1131 # Disable ECP module (entirely)
1132 scripts/config.py unset MBEDTLS_ECP_C
1133 # Also disable bignum
1134 scripts/config.py unset MBEDTLS_BIGNUM_C
1135 fi
1136
1137 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1138 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1139 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1140 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1141
1142 # RSA support is intentionally disabled on this test because RSA_C depends
1143 # on BIGNUM_C.
1144 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
1145 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001146 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1147 # Also disable key exchanges that depend on RSA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001148 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1149 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1150
1151 if [ "$test_target" = "ECC" ]; then
1152 # When testing ECC only, we disable FFDH support, both from builtin and
Valerio Setti8438c632025-01-22 11:56:40 +01001153 # PSA sides.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001154 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_FFDH
1155 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
1156 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001157 fi
1158
1159 # Restartable feature is not yet supported by PSA. Once it will in
1160 # the future, the following line could be removed (see issues
1161 # 6061, 6332 and following ones)
1162 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1163}
1164
1165# Common helper used by:
1166# - component_test_psa_crypto_config_accel_ecc_no_bignum
1167# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1168#
1169# The goal is to build and test accelerating either:
1170# - ECC only or
1171# - both ECC and FFDH
1172#
1173# It is meant to be used in conjunction with
1174# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
1175# coverage analysis in the "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001176common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1177 test_target="$1"
1178
1179 # This is an internal helper to simplify text message handling
1180 if [ "$test_target" = "ECC_DH" ]; then
1181 accel_text="ECC/FFDH"
1182 removed_text="ECP - DH"
1183 else
1184 accel_text="ECC"
1185 removed_text="ECP"
1186 fi
1187
1188 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1189
Valerio Setti37a42812025-08-11 12:52:49 +02001190 # Configure
1191 # ---------
1192
1193 # Set common configurations between library's and driver's builds
1194 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
1195 # Disable all the builtin curves. All the required algs are accelerated.
1196 helper_disable_builtin_curves
1197
Minos Galanakis471b34c2024-07-26 15:39:24 +01001198 # By default we accelerate all EC keys/algs
1199 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1200 ALG_ECDH \
1201 ALG_JPAKE \
1202 $(helper_get_psa_key_type_list "ECC") \
1203 $(helper_get_psa_curve_list)"
1204 # Optionally we can also add DH to the list of accelerated items
1205 if [ "$test_target" = "ECC_DH" ]; then
1206 loc_accel_list="$loc_accel_list \
1207 ALG_FFDH \
1208 $(helper_get_psa_key_type_list "DH") \
1209 $(helper_get_psa_dh_group_list)"
1210 fi
1211
Minos Galanakis471b34c2024-07-26 15:39:24 +01001212 # Build
1213 # -----
1214
1215 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1216 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1217 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1218 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1219
1220 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1221
1222 helper_libtestdriver1_make_main "$loc_accel_list"
1223
1224 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1225 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1226 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1227 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001228 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001229 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1230 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1231 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001232
1233 # Run the tests
1234 # -------------
1235
Valerio Settieb63eb22025-02-12 13:32:49 +01001236 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001237
1238 make test
1239
1240 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1241 tests/ssl-opt.sh
1242}
1243
1244# Common helper used by:
1245# - component_test_psa_crypto_config_reference_ecc_no_bignum
1246# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1247#
1248# The goal is to build and test a reference scenario (i.e. with builtin
1249# components) compared to the ones used in
1250# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
1251#
1252# It is meant to be used in conjunction with
1253# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
1254# coverage analysis in "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001255common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1256 test_target="$1"
1257
1258 # This is an internal helper to simplify text message handling
1259 if [ "$test_target" = "ECC_DH" ]; then
1260 accel_text="ECC/FFDH"
1261 else
1262 accel_text="ECC"
1263 fi
1264
1265 msg "build: full + non accelerated $accel_text algs + USE_PSA"
1266
1267 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
1268
1269 make
1270
1271 msg "test suites: full + non accelerated EC algs + USE_PSA"
1272 make test
1273
1274 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
1275 tests/ssl-opt.sh
1276}
1277
1278component_test_psa_crypto_config_accel_ecc_no_bignum () {
1279 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
1280}
1281
1282component_test_psa_crypto_config_reference_ecc_no_bignum () {
1283 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
1284}
1285
1286component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1287 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
1288}
1289
1290component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1291 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
1292}
1293
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001294component_test_tfm_config_as_is () {
1295 msg "build: configs/config-tfm.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +00001296 MBEDTLS_CONFIG="configs/config-tfm.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001297 CRYPTO_CONFIG="tf-psa-crypto/configs/ext/crypto_config_profile_medium.h"
Minos Galanakis4f619e12024-11-14 14:56:47 +00001298 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 +02001299 make
1300
1301 msg "test: configs/config-tfm.h - unit tests"
1302 make test
1303}
1304
Minos Galanakis471b34c2024-07-26 15:39:24 +01001305# Helper for setting common configurations between:
1306# - component_test_tfm_config_p256m_driver_accel_ec()
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001307# - component_test_tfm_config_no_p256m()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001308common_tfm_config () {
1309 # Enable TF-M config
1310 cp configs/config-tfm.h "$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001311 cp tf-psa-crypto/configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001312
Minos Galanakis471b34c2024-07-26 15:39:24 +01001313 # Config adjustment for better test coverage in our environment.
1314 # This is not needed just to build and pass tests.
1315 #
1316 # Enable filesystem I/O for the benefit of PK parse/write tests.
Minos Galanakis5da58e52024-11-07 15:35:33 +00001317 sed -i '/PROFILE_M_PSA_CRYPTO_CONFIG_H/i #define MBEDTLS_FS_IO' "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001318}
1319
1320# Keep this in sync with component_test_tfm_config() as they are both meant
1321# to be used in analyze_outcomes.py for driver's coverage analysis.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001322component_test_tfm_config_p256m_driver_accel_ec () {
1323 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1324
1325 common_tfm_config
1326
1327 # Build crypto library
David Horstmann5b93d972024-10-31 15:36:05 +00001328 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../framework/tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001329
1330 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1331 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1332 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1333 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001334 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001335 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1336 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001337 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1338 # Check that p256m was built
1339 grep -q p256_ecdsa_ library/libmbedcrypto.a
1340
1341 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1342 # files, so we want to ensure that it has not be re-enabled accidentally.
1343 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1344
1345 # Run the tests
1346 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1347 make test
1348}
1349
1350# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1351# they are both meant to be used in analyze_outcomes.py for driver's coverage
1352# analysis.
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001353component_test_tfm_config_no_p256m () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001354 common_tfm_config
1355
1356 # Disable P256M driver, which is on by default, so that analyze_outcomes
1357 # can compare this test with test_tfm_config_p256m_driver_accel_ec
Minos Galanakis5da58e52024-11-07 15:35:33 +00001358 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 +01001359
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001360 msg "build: TF-M config without p256m"
David Horstmann5b93d972024-10-31 15:36:05 +00001361 make CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' tests
Minos Galanakis471b34c2024-07-26 15:39:24 +01001362
1363 # Check that p256m was not built
1364 not grep p256_ecdsa_ library/libmbedcrypto.a
1365
1366 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1367 # files, so we want to ensure that it has not be re-enabled accidentally.
1368 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1369
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001370 msg "test: TF-M config without p256m"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001371 make test
1372}
1373
Minos Galanakis471b34c2024-07-26 15:39:24 +01001374# This is an helper used by:
1375# - component_test_psa_ecc_key_pair_no_derive
1376# - component_test_psa_ecc_key_pair_no_generate
1377# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1378# enabled, but one. Input arguments are as follows:
Gilles Peskinefef912c2024-09-20 16:07:09 +02001379# - $1 is the configuration to start from
1380# - $2 is the key type under test, i.e. ECC/RSA/DH
1381# - $3 is the key option to be unset (i.e. generate, derive, etc)
Minos Galanakisf78447f2024-07-26 20:49:51 +01001382build_and_test_psa_want_key_pair_partial () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001383 base_config=$1
1384 key_type=$2
1385 unset_option=$3
Minos Galanakis471b34c2024-07-26 15:39:24 +01001386 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1387
Gilles Peskinefef912c2024-09-20 16:07:09 +02001388 msg "build: $base_config - ${disabled_psa_want}"
1389 scripts/config.py "$base_config"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001390
1391 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1392 # crypto_config.h so we just disable the one we don't want.
1393 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
1394
1395 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1396
Gilles Peskinefef912c2024-09-20 16:07:09 +02001397 msg "test: $base_config - ${disabled_psa_want}"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001398 make test
1399}
1400
Minos Galanakisf78447f2024-07-26 20:49:51 +01001401component_test_psa_ecc_key_pair_no_derive () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001402 build_and_test_psa_want_key_pair_partial full "ECC" "DERIVE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001403}
1404
Minos Galanakisf78447f2024-07-26 20:49:51 +01001405component_test_psa_ecc_key_pair_no_generate () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001406 # TLS needs ECC key generation whenever ephemeral ECDH is enabled.
1407 # We don't have proper guards for configurations with ECC key generation
1408 # disabled (https://github.com/Mbed-TLS/mbedtls/issues/9481). Until
1409 # then (if ever), just test the crypto part of the library.
1410 build_and_test_psa_want_key_pair_partial crypto_full "ECC" "GENERATE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001411}
1412
1413config_psa_crypto_accel_rsa () {
1414 driver_only=$1
1415
1416 # Start from crypto_full config (no X.509, no TLS)
1417 helper_libtestdriver1_adjust_config "crypto_full"
1418
1419 if [ "$driver_only" -eq 1 ]; then
Minos Galanakis471b34c2024-07-26 15:39:24 +01001420 # We need PEM parsing in the test library as well to support the import
1421 # of PEM encoded RSA keys.
Minos Galanakis23452f52024-11-28 17:48:14 +00001422 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1423 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
Minos Galanakis471b34c2024-07-26 15:39:24 +01001424 fi
1425}
1426
1427component_test_psa_crypto_config_accel_rsa_crypto () {
1428 msg "build: crypto_full with accelerated RSA"
1429
1430 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1431 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1432 KEY_TYPE_RSA_PUBLIC_KEY \
1433 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1434 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1435 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1436 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1437
1438 # Configure
1439 # ---------
1440
1441 config_psa_crypto_accel_rsa 1
1442
1443 # Build
1444 # -----
1445
1446 # These hashes are needed for unit tests.
1447 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1448 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1449 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1450
1451 helper_libtestdriver1_make_main "$loc_accel_list"
1452
1453 # Make sure this was not re-enabled by accident (additive config)
1454 not grep mbedtls_rsa ${BUILTIN_SRC_PATH}/rsa.o
1455
1456 # Run the tests
1457 # -------------
1458
1459 msg "test: crypto_full with accelerated RSA"
1460 make test
1461}
1462
1463component_test_psa_crypto_config_reference_rsa_crypto () {
1464 msg "build: crypto_full with non-accelerated RSA"
1465
1466 # Configure
1467 # ---------
1468 config_psa_crypto_accel_rsa 0
1469
1470 # Build
1471 # -----
1472 make
1473
1474 # Run the tests
1475 # -------------
1476 msg "test: crypto_full with non-accelerated RSA"
1477 make test
1478}
1479
1480# This is a temporary test to verify that full RSA support is present even when
1481# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001482component_test_new_psa_want_key_pair_symbol () {
Ronald Cron892bb612025-07-21 14:26:27 +02001483 msg "Build: crypto config - PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001484
1485 # Create a temporary output file unless there is already one set
1486 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1487 REMOVE_OUTCOME_ON_EXIT="no"
1488 else
1489 REMOVE_OUTCOME_ON_EXIT="yes"
1490 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1491 export MBEDTLS_TEST_OUTCOME_FILE
1492 fi
1493
1494 # Start from crypto configuration
1495 scripts/config.py crypto
1496
1497 # Remove RSA support and its dependencies
Minos Galanakis471b34c2024-07-26 15:39:24 +01001498 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1499 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001500 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1501
Minos Galanakis471b34c2024-07-26 15:39:24 +01001502 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
1503 # that proper translations is done in crypto_legacy.h.
1504 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
1505 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
1506 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
1507
1508 make
1509
Ronald Cron892bb612025-07-21 14:26:27 +02001510 msg "Test: crypto config - PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001511 make test
1512
1513 # Parse only 1 relevant line from the outcome file, i.e. a test which is
1514 # performing RSA signature.
1515 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
1516 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
1517
1518 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
1519 rm $MBEDTLS_TEST_OUTCOME_FILE
1520 fi
1521}
1522
1523component_test_psa_crypto_config_accel_hash () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001524 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001525
1526 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1527 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1528 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1529
1530 # Configure
1531 # ---------
1532
1533 # Start from default config (no USE_PSA)
1534 helper_libtestdriver1_adjust_config "default"
1535
Minos Galanakis471b34c2024-07-26 15:39:24 +01001536 # Build
1537 # -----
1538
1539 helper_libtestdriver1_make_drivers "$loc_accel_list"
1540
1541 helper_libtestdriver1_make_main "$loc_accel_list"
1542
1543 # There's a risk of something getting re-enabled via config_psa.h;
1544 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1545 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1546 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1547 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1548 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1549 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1550
1551 # Run the tests
1552 # -------------
1553
Ronald Cron93ba6252024-09-05 10:37:14 +02001554 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001555 make test
1556}
1557
1558# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001559config_psa_crypto_hash_use_psa () {
1560 driver_only="$1"
1561 # start with config full for maximum coverage (also enables USE_PSA)
1562 helper_libtestdriver1_adjust_config "full"
1563 if [ "$driver_only" -eq 1 ]; then
1564 # disable the built-in implementation of hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +01001565 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Minos Galanakis471b34c2024-07-26 15:39:24 +01001566 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Minos Galanakis471b34c2024-07-26 15:39:24 +01001567 fi
1568}
1569
1570# Note that component_test_psa_crypto_config_reference_hash_use_psa
1571# is related to this component and both components need to be kept in sync.
1572# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001573component_test_psa_crypto_config_accel_hash_use_psa () {
1574 msg "test: full with accelerated hashes"
1575
1576 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1577 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1578 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1579
1580 # Configure
1581 # ---------
1582
1583 config_psa_crypto_hash_use_psa 1
1584
1585 # Build
1586 # -----
1587
1588 helper_libtestdriver1_make_drivers "$loc_accel_list"
1589
1590 helper_libtestdriver1_make_main "$loc_accel_list"
1591
1592 # There's a risk of something getting re-enabled via config_psa.h;
1593 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1594 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1595 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1596 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1597 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1598 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1599
1600 # Run the tests
1601 # -------------
1602
1603 msg "test: full with accelerated hashes"
1604 make test
1605
1606 # This is mostly useful so that we can later compare outcome files with
1607 # the reference config in analyze_outcomes.py, to check that the
1608 # dependency declarations in ssl-opt.sh and in TLS code are correct.
1609 msg "test: ssl-opt.sh, full with accelerated hashes"
1610 tests/ssl-opt.sh
1611
1612 # This is to make sure all ciphersuites are exercised, but we don't need
1613 # interop testing (besides, we already got some from ssl-opt.sh).
1614 msg "test: compat.sh, full with accelerated hashes"
1615 tests/compat.sh -p mbedTLS -V YES
1616}
1617
1618# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
1619# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
1620# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
1621# Both components need to be kept in sync.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001622component_test_psa_crypto_config_reference_hash_use_psa () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001623 msg "test: full without accelerated hashes"
1624
1625 config_psa_crypto_hash_use_psa 0
1626
1627 make
1628
1629 msg "test: full without accelerated hashes"
1630 make test
1631
1632 msg "test: ssl-opt.sh, full without accelerated hashes"
1633 tests/ssl-opt.sh
1634}
1635
1636# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001637config_psa_crypto_hmac_use_psa () {
1638 driver_only="$1"
1639 # start with config full for maximum coverage (also enables USE_PSA)
1640 helper_libtestdriver1_adjust_config "full"
1641
1642 if [ "$driver_only" -eq 1 ]; then
1643 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
1644 # is still enabled though (for ENTROPY_C among others).
1645 scripts/config.py unset MBEDTLS_MD_C
Ronald Cron772a8ad2025-07-21 12:36:29 +02001646 # Also disable the configuration options that tune the builtin hashes,
1647 # since those hashes are disabled.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001648 scripts/config.py unset-all MBEDTLS_SHA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001649 fi
1650
1651 # Direct dependencies of MD_C. We disable them also in the reference
1652 # component to work with the same set of features.
1653 scripts/config.py unset MBEDTLS_PKCS7_C
1654 scripts/config.py unset MBEDTLS_PKCS5_C
1655 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1656 scripts/config.py unset MBEDTLS_HKDF_C
1657 # Dependencies of HMAC_DRBG
1658 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
1659 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
1660}
1661
Minos Galanakisf78447f2024-07-26 20:49:51 +01001662component_test_psa_crypto_config_accel_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001663 msg "test: full with accelerated hmac"
1664
1665 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
1666 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1667 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1668 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1669
1670 # Configure
1671 # ---------
1672
1673 config_psa_crypto_hmac_use_psa 1
1674
1675 # Build
1676 # -----
1677
1678 helper_libtestdriver1_make_drivers "$loc_accel_list"
1679
1680 helper_libtestdriver1_make_main "$loc_accel_list"
1681
1682 # Ensure that built-in support for HMAC is disabled.
1683 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
1684
1685 # Run the tests
1686 # -------------
1687
1688 msg "test: full with accelerated hmac"
1689 make test
1690}
1691
Minos Galanakisf78447f2024-07-26 20:49:51 +01001692component_test_psa_crypto_config_reference_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001693 msg "test: full without accelerated hmac"
1694
1695 config_psa_crypto_hmac_use_psa 0
1696
1697 make
1698
1699 msg "test: full without accelerated hmac"
1700 make test
1701}
1702
Minos Galanakis471b34c2024-07-26 15:39:24 +01001703component_test_psa_crypto_config_accel_aead () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001704 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001705
1706 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
1707 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1708
1709 # Configure
1710 # ---------
1711
1712 # Start from full config
1713 helper_libtestdriver1_adjust_config "full"
1714
Minos Galanakis471b34c2024-07-26 15:39:24 +01001715 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
1716 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1717
1718 # Build
1719 # -----
1720
1721 helper_libtestdriver1_make_drivers "$loc_accel_list"
1722
1723 helper_libtestdriver1_make_main "$loc_accel_list"
1724
1725 # Make sure this was not re-enabled by accident (additive config)
1726 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1727 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1728 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1729
1730 # Run the tests
1731 # -------------
1732
Ronald Cron93ba6252024-09-05 10:37:14 +02001733 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001734 make test
1735}
1736
1737# This is a common configuration function used in:
1738# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1739# - component_test_psa_crypto_config_reference_cipher_aead_cmac
Minos Galanakisf78447f2024-07-26 20:49:51 +01001740common_psa_crypto_config_accel_cipher_aead_cmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001741 # Start from the full config
1742 helper_libtestdriver1_adjust_config "full"
1743
1744 scripts/config.py unset MBEDTLS_NIST_KW_C
1745}
1746
1747# The 2 following test components, i.e.
1748# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1749# - component_test_psa_crypto_config_reference_cipher_aead_cmac
1750# are meant to be used together in analyze_outcomes.py script in order to test
1751# driver's coverage for ciphers and AEADs.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001752component_test_psa_crypto_config_accel_cipher_aead_cmac () {
1753 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
1754
1755 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
1756 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
1757 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
Ari Weiler-Ofek86422e52025-07-04 14:43:30 +01001758 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001759
1760 # Configure
1761 # ---------
1762
1763 common_psa_crypto_config_accel_cipher_aead_cmac
1764
Ari Weiler-Ofek5d8d2992025-07-07 23:20:29 +01001765 # Disable DES, if it still exists.
1766 # This can be removed once we remove DES from the library.
1767 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
1768
Minos Galanakis471b34c2024-07-26 15:39:24 +01001769 # Build
1770 # -----
1771
1772 helper_libtestdriver1_make_drivers "$loc_accel_list"
1773
1774 helper_libtestdriver1_make_main "$loc_accel_list"
1775
1776 # Make sure this was not re-enabled by accident (additive config)
1777 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001778 not grep mbedtls_aes ${BUILTIN_SRC_PATH}/aes.o
1779 not grep mbedtls_aria ${BUILTIN_SRC_PATH}/aria.o
1780 not grep mbedtls_camellia ${BUILTIN_SRC_PATH}/camellia.o
1781 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1782 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1783 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1784 not grep mbedtls_cmac ${BUILTIN_SRC_PATH}/cmac.o
Ronald Cronb5c6fcc2025-07-10 13:40:00 +02001785 not grep mbedtls_poly1305 ${BUILTIN_SRC_PATH}/poly1305.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001786
1787 # Run the tests
1788 # -------------
1789
1790 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
1791 make test
1792
1793 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
Ronald Cronbd28acf2025-07-10 09:53:50 +02001794 # Exclude password-protected key tests — they require built-in CBC and AES.
1795 tests/ssl-opt.sh -e "TLS: password protected"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001796
1797 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
1798 tests/compat.sh -V NO -p mbedTLS
1799}
1800
1801component_test_psa_crypto_config_reference_cipher_aead_cmac () {
1802 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
1803 common_psa_crypto_config_accel_cipher_aead_cmac
1804
Ari Weiler-Ofek5d8d2992025-07-07 23:20:29 +01001805 # Disable DES, if it still exists.
1806 # This can be removed once we remove DES from the library.
1807 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
1808
Minos Galanakis471b34c2024-07-26 15:39:24 +01001809 make
1810
1811 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
1812 make test
1813
1814 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
Ronald Cronbd28acf2025-07-10 09:53:50 +02001815 # Exclude password-protected key tests as in test_psa_crypto_config_accel_cipher_aead_cmac.
1816 tests/ssl-opt.sh -e "TLS: password protected"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001817
1818 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
1819 tests/compat.sh -V NO -p mbedTLS
1820}
1821
Minos Galanakisf78447f2024-07-26 20:49:51 +01001822common_block_cipher_dispatch () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001823 TEST_WITH_DRIVER="$1"
1824
1825 # Start from the full config
1826 helper_libtestdriver1_adjust_config "full"
1827
Minos Galanakis471b34c2024-07-26 15:39:24 +01001828 # Disable cipher's modes that, when not accelerated, cause
1829 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
1830 # Keep this also in the reference component in order to skip the same tests
1831 # that were skipped in the accelerated one.
1832 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
1833 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
1834 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
1835 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
1836 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
1837 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
1838 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1839 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
1840
1841 # Disable direct dependency on AES_C
1842 scripts/config.py unset MBEDTLS_NIST_KW_C
1843
1844 # Prevent the cipher module from using deprecated PSA path. The reason is
1845 # that otherwise there will be tests relying on "aes_info" (defined in
1846 # "cipher_wrap.c") whose functions are not available when AES_C is
1847 # not defined. ARIA and Camellia are not a problem in this case because
1848 # the PSA path is not tested for these key types.
1849 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1850}
1851
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02001852component_test_full_block_cipher_psa_dispatch_static_keystore () {
1853 msg "build: full + PSA dispatch in block_cipher with static keystore"
1854 # Check that the static key store works well when CTR_DRBG uses a
1855 # PSA key for AES.
1856 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
1857
1858 loc_accel_list="ALG_ECB_NO_PADDING \
1859 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1860
1861 # Configure
1862 # ---------
1863
1864 common_block_cipher_dispatch 1
1865
1866 # Build
1867 # -----
1868
1869 helper_libtestdriver1_make_drivers "$loc_accel_list"
1870
1871 helper_libtestdriver1_make_main "$loc_accel_list"
1872
1873 # Make sure disabled components were not re-enabled by accident (additive
1874 # config)
1875 not grep mbedtls_aes_ library/aes.o
1876 not grep mbedtls_aria_ library/aria.o
1877 not grep mbedtls_camellia_ library/camellia.o
1878
1879 # Run the tests
1880 # -------------
1881
1882 msg "test: full + PSA dispatch in block_cipher with static keystore"
1883 make test
1884}
1885
Minos Galanakis471b34c2024-07-26 15:39:24 +01001886component_test_full_block_cipher_psa_dispatch () {
1887 msg "build: full + PSA dispatch in block_cipher"
1888
1889 loc_accel_list="ALG_ECB_NO_PADDING \
1890 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1891
1892 # Configure
1893 # ---------
1894
1895 common_block_cipher_dispatch 1
1896
1897 # Build
1898 # -----
1899
1900 helper_libtestdriver1_make_drivers "$loc_accel_list"
1901
1902 helper_libtestdriver1_make_main "$loc_accel_list"
1903
1904 # Make sure disabled components were not re-enabled by accident (additive
1905 # config)
1906 not grep mbedtls_aes_ ${BUILTIN_SRC_PATH}/aes.o
1907 not grep mbedtls_aria_ ${BUILTIN_SRC_PATH}/aria.o
1908 not grep mbedtls_camellia_ ${BUILTIN_SRC_PATH}/camellia.o
1909
1910 # Run the tests
1911 # -------------
1912
1913 msg "test: full + PSA dispatch in block_cipher"
1914 make test
1915}
1916
1917# This is the reference component of component_test_full_block_cipher_psa_dispatch
Minos Galanakis471b34c2024-07-26 15:39:24 +01001918component_test_full_block_cipher_legacy_dispatch () {
1919 msg "build: full + legacy dispatch in block_cipher"
1920
1921 common_block_cipher_dispatch 0
1922
1923 make
1924
1925 msg "test: full + legacy dispatch in block_cipher"
1926 make test
1927}
1928
Minos Galanakisf78447f2024-07-26 20:49:51 +01001929component_test_aead_chachapoly_disabled () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001930 msg "build: full minus CHACHAPOLY"
1931 scripts/config.py full
Minos Galanakis471b34c2024-07-26 15:39:24 +01001932 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
1933 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1934
1935 msg "test: full minus CHACHAPOLY"
1936 make test
1937}
1938
Minos Galanakisf78447f2024-07-26 20:49:51 +01001939component_test_aead_only_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001940 msg "build: full minus CHACHAPOLY and GCM"
1941 scripts/config.py full
Minos Galanakis471b34c2024-07-26 15:39:24 +01001942 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
1943 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
1944 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1945
1946 msg "test: full minus CHACHAPOLY and GCM"
1947 make test
1948}
1949
Minos Galanakisf78447f2024-07-26 20:49:51 +01001950component_test_ccm_aes_sha256 () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001951 msg "build: CCM + AES + SHA256 configuration"
1952
Minos Galanakisa17ffc72024-12-02 23:57:30 +00001953 # Setting a blank config disables everyhing in the library side.
1954 echo '#define MBEDTLS_CONFIG_H ' >"$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001955 cp tf-psa-crypto/configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
Ronald Cron9d262d72024-12-06 17:41:26 +01001956
Minos Galanakis471b34c2024-07-26 15:39:24 +01001957 make
Minos Galanakis471b34c2024-07-26 15:39:24 +01001958 msg "test: CCM + AES + SHA256 configuration"
1959 make test
1960}
1961
1962# Test that the given .o file builds with all (valid) combinations of the given options.
1963#
1964# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
1965#
1966# The validator function is the name of a function to validate the combination of options.
1967# It may be "" if all combinations are valid.
1968# It receives a string containing a combination of options, as passed to the compiler,
1969# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001970build_test_config_combos () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001971 file=$1
1972 shift
1973 validate_options=$1
1974 shift
1975 options=("$@")
1976
1977 # clear all of the options so that they can be overridden on the clang commandline
1978 for opt in "${options[@]}"; do
1979 ./scripts/config.py unset ${opt}
1980 done
1981
1982 # enter the library directory
1983 cd library
1984
1985 # The most common issue is unused variables/functions, so ensure -Wunused is set.
1986 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
1987
1988 # Extract the command generated by the Makefile to build the target file.
1989 # This ensures that we have any include paths, macro definitions, etc
1990 # that may be applied by make.
1991 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
1992 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
1993
1994 makefile=$(TMPDIR=. mktemp)
1995 deps=""
1996
1997 len=${#options[@]}
1998 source_file=../${file%.o}.c
1999
2000 targets=0
2001 echo 'include Makefile' >${makefile}
2002
2003 for ((i = 0; i < $((2**${len})); i++)); do
2004 # generate each of 2^n combinations of options
2005 # each bit of $i is used to determine if options[i] will be set or not
2006 target="t"
2007 clang_args=""
2008 for ((j = 0; j < ${len}; j++)); do
2009 if (((i >> j) & 1)); then
2010 opt=-D${options[$j]}
2011 clang_args="${clang_args} ${opt}"
2012 target="${target}${opt}"
2013 fi
2014 done
2015
2016 # if combination is not known to be invalid, add it to the makefile
2017 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
2018 cmd="${compile_cmd} ${clang_args}"
2019 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
2020
2021 deps="${deps} ${target}"
2022 ((++targets))
2023 fi
2024 done
2025
2026 echo "build_test_config_combos: ${deps}" >> ${makefile}
2027
2028 # execute all of the commands via Make (probably in parallel)
2029 make -s -f ${makefile} build_test_config_combos
2030 echo "$targets targets checked"
2031
2032 # clean up the temporary makefile
2033 rm ${makefile}
2034}
2035
Minos Galanakisf78447f2024-07-26 20:49:51 +01002036validate_aes_config_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002037 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
2038 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
2039 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
2040 return 1
2041 fi
2042 fi
2043 return 0
2044}
2045
Minos Galanakisf78447f2024-07-26 20:49:51 +01002046component_build_aes_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002047 # 18s - around 90ms per clang invocation on M1 Pro
2048 #
2049 # aes.o has many #if defined(...) guards that intersect in complex ways.
2050 # Test that all the combinations build cleanly.
2051
2052 MBEDTLS_ROOT_DIR="$PWD"
2053 msg "build: aes.o for all combinations of relevant config options"
2054
2055 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002056 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002057 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2058 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2059
2060 cd "$MBEDTLS_ROOT_DIR"
2061 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
2062
Ari Weiler-Ofek86422e52025-07-04 14:43:30 +01002063 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW,
Minos Galanakis471b34c2024-07-26 15:39:24 +01002064 # manually set or unset those configurations to check
2065 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
2066 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Minos Galanakis471b34c2024-07-26 15:39:24 +01002067 scripts/config.py unset MBEDTLS_NIST_KW_C
Ronald Cron54d1eec2024-09-06 09:55:38 +02002068
Minos Galanakis00b641c2024-11-28 23:05:10 +00002069 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
2070 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
2071 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
2072 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
Ronald Cron54d1eec2024-09-06 09:55:38 +02002073
Minos Galanakis471b34c2024-07-26 15:39:24 +01002074 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002075 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002076 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2077 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2078}
2079
Minos Galanakisf78447f2024-07-26 20:49:51 +01002080component_test_sha3_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002081 msg "sha3 loop unroll variations"
2082
2083 # define minimal config sufficient to test SHA3
Ronald Crone7f289e2024-09-06 11:02:47 +02002084 cat > include/mbedtls/mbedtls_config.h << END
Ronald Crone7f289e2024-09-06 11:02:47 +02002085END
2086
2087 cat > tf-psa-crypto/include/psa/crypto_config.h << END
2088 #define PSA_WANT_ALG_SHA_256 1
2089 #define PSA_WANT_ALG_SHA3_224 1
2090 #define PSA_WANT_ALG_SHA3_256 1
2091 #define PSA_WANT_ALG_SHA3_384 1
2092 #define PSA_WANT_ALG_SHA3_512 1
Ronald Cron06680362025-07-21 15:21:22 +02002093 #define PSA_WANT_KEY_TYPE_AES 1
Ronald Cron3dd1d3d2024-12-05 15:12:06 +01002094 #define MBEDTLS_CTR_DRBG_C
2095 #define MBEDTLS_ENTROPY_C
2096 #define MBEDTLS_PSA_CRYPTO_C
2097 #define MBEDTLS_SELF_TEST
Minos Galanakis471b34c2024-07-26 15:39:24 +01002098END
2099
2100 msg "all loops unrolled"
2101 make clean
2102 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"
2103 ./tf-psa-crypto/tests/test_suite_shax
2104
2105 msg "all loops rolled up"
2106 make clean
2107 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"
2108 ./tf-psa-crypto/tests/test_suite_shax
2109}
2110
Minos Galanakisf699d512024-08-01 11:32:30 +01002111support_build_aes_aesce_armcc () {
2112 support_build_armcc
2113}
2114
Minos Galanakis471b34c2024-07-26 15:39:24 +01002115# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2116component_build_aes_aesce_armcc () {
2117 msg "Build: AESCE test on arm64 platform without plain C."
2118 scripts/config.py baremetal
2119
2120 # armc[56] don't support SHA-512 intrinsics
2121 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2122
2123 # Stop armclang warning about feature detection for A64_CRYPTO.
2124 # With this enabled, the library does build correctly under armclang,
2125 # but in baremetal builds (as tested here), feature detection is
2126 # unavailable, and the user is notified via a #warning. So enabling
2127 # this feature would prevent us from building with -Werror on
2128 # armclang. Tracked in #7198.
2129 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2130 scripts/config.py set MBEDTLS_HAVE_ASM
2131
2132 msg "AESCE, build with default configuration."
2133 scripts/config.py set MBEDTLS_AESCE_C
2134 scripts/config.py unset 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 msg "AESCE, build AESCE only"
2138 scripts/config.py set MBEDTLS_AESCE_C
2139 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002140 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002141}
2142
Minos Galanakis471b34c2024-07-26 15:39:24 +01002143component_test_aes_only_128_bit_keys () {
2144 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2145 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002146 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002147
2148 make CFLAGS='-O2 -Werror -Wall -Wextra'
2149
2150 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2151 make test
2152}
2153
2154component_test_no_ctr_drbg_aes_only_128_bit_keys () {
2155 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2156 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002157 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002158 scripts/config.py unset MBEDTLS_CTR_DRBG_C
2159
2160 make CC=clang CFLAGS='-Werror -Wall -Wextra'
2161
2162 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2163 make test
2164}
2165
2166component_test_aes_only_128_bit_keys_have_builtins () {
2167 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2168 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002169 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002170 scripts/config.py unset MBEDTLS_AESNI_C
2171 scripts/config.py unset MBEDTLS_AESCE_C
2172
2173 make CFLAGS='-O2 -Werror -Wall -Wextra'
2174
2175 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2176 make test
2177
2178 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2179 programs/test/selftest
2180}
2181
2182component_test_gcm_largetable () {
2183 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2184 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
2185 scripts/config.py unset MBEDTLS_AESNI_C
2186 scripts/config.py unset MBEDTLS_AESCE_C
2187
2188 make CFLAGS='-O2 -Werror -Wall -Wextra'
2189
2190 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2191 make test
2192}
2193
2194component_test_aes_fewer_tables () {
2195 msg "build: default config with AES_FEWER_TABLES enabled"
2196 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2197 make CFLAGS='-O2 -Werror -Wall -Wextra'
2198
2199 msg "test: AES_FEWER_TABLES"
2200 make test
2201}
2202
2203component_test_aes_rom_tables () {
2204 msg "build: default config with AES_ROM_TABLES enabled"
2205 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2206 make CFLAGS='-O2 -Werror -Wall -Wextra'
2207
2208 msg "test: AES_ROM_TABLES"
2209 make test
2210}
2211
2212component_test_aes_fewer_tables_and_rom_tables () {
2213 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
2214 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2215 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2216 make CFLAGS='-O2 -Werror -Wall -Wextra'
2217
2218 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2219 make test
2220}
2221
Ronald Cron66040472024-09-06 10:14:38 +02002222# helper for component_test_block_cipher_no_decrypt_aesni() which:
Minos Galanakis471b34c2024-07-26 15:39:24 +01002223# - enable/disable the list of config options passed from -s/-u respectively.
2224# - build
2225# - test for tests_suite_xxx
2226# - selftest
2227#
2228# Usage: helper_block_cipher_no_decrypt_build_test
2229# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
2230# Options: -s set_opts the list of config options to enable
2231# -u unset_opts the list of config options to disable
2232# -c cflags the list of options passed to CFLAGS
2233# -l ldflags the list of options passed to LDFLAGS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002234helper_block_cipher_no_decrypt_build_test () {
2235 while [ $# -gt 0 ]; do
2236 case "$1" in
2237 -s)
2238 shift; local set_opts="$1";;
2239 -u)
2240 shift; local unset_opts="$1";;
2241 -c)
2242 shift; local cflags="-Werror -Wall -Wextra $1";;
2243 -l)
2244 shift; local ldflags="$1";;
2245 esac
2246 shift
2247 done
2248 set_opts="${set_opts:-}"
2249 unset_opts="${unset_opts:-}"
2250 cflags="${cflags:-}"
2251 ldflags="${ldflags:-}"
2252
2253 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
2254 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
2255
2256 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2257 make clean
2258 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
2259
2260 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2261 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2262 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2263 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2264 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2265 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2266 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
2267 not grep mbedtls_aesni_inverse_key ${BUILTIN_SRC_PATH}/aesni.o
2268
2269 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2270 make test
2271
2272 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2273 programs/test/selftest
2274}
2275
Ronald Cron66040472024-09-06 10:14:38 +02002276# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
2277config_block_cipher_no_decrypt () {
2278 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Ronald Cron66040472024-09-06 10:14:38 +02002279 scripts/config.py unset MBEDTLS_NIST_KW_C
2280
2281 # Enable support for cryptographic mechanisms through the PSA API.
2282 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
Ronald Cron66040472024-09-06 10:14:38 +02002283 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
2284 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
2285 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
2286 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
Ronald Cron66040472024-09-06 10:14:38 +02002287}
2288
2289component_test_block_cipher_no_decrypt_aesni () {
2290 # Test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics, AESNI assembly and
2291 # AES C implementation on x86_64 and with AESNI intrinsics on x86.
2292
2293 # This consistently causes an llvm crash on clang 3.8, so use gcc
2294 export CC=gcc
2295 config_block_cipher_no_decrypt
2296
Minos Galanakis471b34c2024-07-26 15:39:24 +01002297 # test AESNI intrinsics
2298 helper_block_cipher_no_decrypt_build_test \
2299 -s "MBEDTLS_AESNI_C" \
2300 -c "-mpclmul -msse2 -maes"
2301
2302 # test AESNI assembly
2303 helper_block_cipher_no_decrypt_build_test \
2304 -s "MBEDTLS_AESNI_C" \
2305 -c "-mno-pclmul -mno-sse2 -mno-aes"
2306
2307 # test AES C implementation
2308 helper_block_cipher_no_decrypt_build_test \
2309 -u "MBEDTLS_AESNI_C"
2310
2311 # test AESNI intrinsics for i386 target
2312 helper_block_cipher_no_decrypt_build_test \
2313 -s "MBEDTLS_AESNI_C" \
2314 -c "-m32 -mpclmul -msse2 -maes" \
2315 -l "-m32"
2316}
2317
Minos Galanakisf699d512024-08-01 11:32:30 +01002318support_test_block_cipher_no_decrypt_aesce_armcc () {
2319 support_build_armcc
2320}
2321
Minos Galanakis471b34c2024-07-26 15:39:24 +01002322component_test_block_cipher_no_decrypt_aesce_armcc () {
2323 scripts/config.py baremetal
2324
2325 # armc[56] don't support SHA-512 intrinsics
2326 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2327
2328 # Stop armclang warning about feature detection for A64_CRYPTO.
2329 # With this enabled, the library does build correctly under armclang,
2330 # but in baremetal builds (as tested here), feature detection is
2331 # unavailable, and the user is notified via a #warning. So enabling
2332 # this feature would prevent us from building with -Werror on
2333 # armclang. Tracked in #7198.
2334 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2335 scripts/config.py set MBEDTLS_HAVE_ASM
2336
Ronald Cron66040472024-09-06 10:14:38 +02002337 config_block_cipher_no_decrypt
Minos Galanakis471b34c2024-07-26 15:39:24 +01002338
2339 # test AESCE baremetal build
2340 scripts/config.py set MBEDTLS_AESCE_C
2341 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002342 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002343
2344 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2345 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2346 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2347 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2348 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2349 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2350 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
2351 not grep mbedtls_aesce_inverse_key ${BUILTIN_SRC_PATH}/aesce.o
2352 not grep aesce_decrypt_block ${BUILTIN_SRC_PATH}/aesce.o
2353}
2354
2355component_test_ctr_drbg_aes_256_sha_256 () {
2356 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2357 scripts/config.py full
2358 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2359 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
2360 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2361 make
2362
2363 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2364 make test
2365}
2366
2367component_test_ctr_drbg_aes_128_sha_512 () {
2368 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2369 scripts/config.py full
2370 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2371 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2372 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2373 make
2374
2375 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2376 make test
2377}
2378
2379component_test_ctr_drbg_aes_128_sha_256 () {
2380 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2381 scripts/config.py full
2382 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2383 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2384 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
2385 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2386 make
2387
2388 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2389 make test
2390}
2391
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002392component_test_full_static_keystore () {
2393 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2394 scripts/config.py full
2395 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2396 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
2397
2398 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2399 make test
2400}
2401
Minos Galanakis471b34c2024-07-26 15:39:24 +01002402component_test_psa_crypto_drivers () {
Ronald Crona0afbfb2024-10-15 13:20:31 +02002403 # Test dispatch to drivers and fallbacks with
2404 # test_suite_psa_crypto_driver_wrappers test suite. The test drivers that
2405 # are wrappers around the builtin drivers are activated by
2406 # PSA_CRYPTO_DRIVER_TEST.
2407 #
2408 # For the time being, some test cases in test_suite_block_cipher and
2409 # test_suite_md.psa rely on this component to be run at least once by the
2410 # CI. This should disappear as we progress the 4.x work. See
2411 # config_adjust_test_accelerators.h for more information.
Minos Galanakis471b34c2024-07-26 15:39:24 +01002412 msg "build: full + test drivers dispatching to builtins"
2413 scripts/config.py full
Ronald Cron67cc6a72024-10-14 10:55:24 +02002414 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_CONFIG_ADJUST_TEST_ACCELERATORS"
David Horstmann5b93d972024-10-31 15:36:05 +00002415 loc_cflags="${loc_cflags} -I../framework/tests/include"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002416
2417 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
2418
2419 msg "test: full + test drivers dispatching to builtins"
2420 make test
2421}
2422
2423component_build_psa_config_file () {
Minos Galanakis4f619e12024-11-14 14:56:47 +00002424 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002425 cp "$CRYPTO_CONFIG_H" psa_test_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002426 echo '#error "TF_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
2427 make CFLAGS="-I '$PWD' -DTF_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002428 # Make sure this feature is enabled. We'll disable it in the next phase.
Ronald Cron3f120062025-07-03 14:45:51 +02002429 programs/test/query_compile_time_config PSA_WANT_ALG_CMAC
Minos Galanakis471b34c2024-07-26 15:39:24 +01002430 make clean
2431
Minos Galanakis4f619e12024-11-14 14:56:47 +00002432 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE + TF_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002433 # In the user config, disable one feature and its dependencies, which will
2434 # reflect on the mbedtls configuration so we can query it with
2435 # query_compile_time_config.
2436 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
2437 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002438 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 +02002439 not programs/test/query_compile_time_config PSA_WANT_ALG_CMAC
Minos Galanakis471b34c2024-07-26 15:39:24 +01002440
2441 rm -f psa_test_config.h psa_user_config.h
2442}
2443
2444component_build_psa_alt_headers () {
2445 msg "build: make with PSA alt headers" # ~20s
2446
2447 # Generate alternative versions of the substitutable headers with the
2448 # same content except different include guards.
David Horstmanndc459512024-11-07 17:08:11 +00002449 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 +01002450
2451 # Build the library and some programs.
2452 # Don't build the fuzzers to avoid having to go through hoops to set
2453 # a correct include path for programs/fuzz/Makefile.
David Horstmann5b93d972024-10-31 15:36:05 +00002454 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
2455 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 +01002456
2457 # Check that we're getting the alternative include guards and not the
2458 # original include guards.
2459 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
2460 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
2461 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
2462 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
2463}
2464
2465component_test_min_mpi_window_size () {
2466 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
2467 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
2468 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2469 make
2470
2471 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2472 make test
2473}
Ronald Cronf256f8a2025-07-10 17:37:18 +02002474
2475component_test_xts () {
2476 # Component dedicated to run XTS unit test cases while XTS is not
2477 # supported through the PSA API.
2478 msg "build: Default + MBEDTLS_CIPHER_MODE_XTS"
2479
2480 echo "#define MBEDTLS_CIPHER_MODE_XTS" > psa_user_config.h
2481 cmake -DTF_PSA_CRYPTO_USER_CONFIG_FILE="psa_user_config.h"
2482 make
2483
Ronald Crone0b06eb2025-07-15 08:58:32 +02002484 rm -f psa_user_config.h
2485
Ronald Cronf256f8a2025-07-10 17:37:18 +02002486 msg "test: Default + MBEDTLS_CIPHER_MODE_XTS"
2487 make test
Ronald Cronf256f8a2025-07-10 17:37:18 +02002488}