blob: 51f813d16e1c04f04629f44b223255967886cee8 [file] [log] [blame]
Minos Galanakis6aab5b72024-07-25 14:24:37 +01001# components-configuration-crypto.sh
2#
3# Copyright The Mbed TLS Contributors
4# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
5
Minos Galanakis609f7492024-07-31 16:39:28 +01006# This file contains test components that are executed by all.sh
Minos Galanakis6aab5b72024-07-25 14:24:37 +01007
8################################################################
9#### Configuration Testing - Crypto
10################################################################
11
Minos Galanakis471b34c2024-07-26 15:39:24 +010012component_test_psa_crypto_key_id_encodes_owner () {
13 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
14 scripts/config.py full
15 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
16 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
17 make
18
19 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
20 make test
21}
22
23component_test_psa_assume_exclusive_buffers () {
24 msg "build: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
25 scripts/config.py full
26 scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
27 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
28 make
29
30 msg "test: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
31 make test
32}
33
Valerio Settidbb646b2024-06-20 14:40:54 +020034component_test_crypto_with_static_key_slots() {
35 msg "build: crypto full + MBEDTLS_PSA_STATIC_KEY_SLOTS"
36 scripts/config.py crypto_full
37 scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOTS
Valerio Setti4d9a8212024-08-16 12:35:24 +020038 # Intentionally set MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE to a value that
39 # is enough to contain:
40 # - all RSA public keys up to 4096 bits (max of PSA_VENDOR_RSA_MAX_KEY_BITS).
41 # - RSA key pairs up to 1024 bits, but not 2048 or larger.
42 # - all FFDH key pairs and public keys up to 8192 bits (max of PSA_VENDOR_FFDH_MAX_KEY_BITS).
43 # - all EC key pairs and public keys up to 521 bits (max of PSA_VENDOR_ECC_MAX_CURVE_BITS).
44 scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE 1212
Valerio Setti8bc81722024-08-28 05:50:45 +020045 # Disable the fully dynamic key store (default on) since it conflicts
46 # with the static behavior that we're testing here.
47 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
Valerio Settidbb646b2024-06-20 14:40:54 +020048
Valerio Setti13aadd72024-08-13 13:13:23 +020049 msg "test: crypto full + MBEDTLS_PSA_STATIC_KEY_SLOTS"
Valerio Setti2a3c9b32024-08-14 06:37:02 +020050 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" test
Valerio Settidbb646b2024-06-20 14:40:54 +020051}
52
Minos Galanakis471b34c2024-07-26 15:39:24 +010053# check_renamed_symbols HEADER LIB
54# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
Minos Galanakis609f7492024-07-31 16:39:28 +010055# name in LIB.
Minos Galanakis471b34c2024-07-26 15:39:24 +010056check_renamed_symbols () {
57 ! nm "$2" | sed 's/.* //' |
58 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
59}
60
61component_build_psa_crypto_spm () {
62 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
63 scripts/config.py full
64 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
65 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
66 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
67 # We can only compile, not link, since our test and sample programs
68 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
69 # is active.
David Horstmann5b93d972024-10-31 15:36:05 +000070 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' lib
Minos Galanakis471b34c2024-07-26 15:39:24 +010071
72 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
73 # version is not present.
74 echo "Checking for renamed symbols in the library"
David Horstmann5b93d972024-10-31 15:36:05 +000075 check_renamed_symbols framework/tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Minos Galanakis471b34c2024-07-26 15:39:24 +010076}
77
Valerio Settia47b0452024-06-25 18:31:36 +020078# The goal of this component is to build a configuration where:
79# - test code and libtestdriver1 can make use of calloc/free and
80# - core library (including PSA core) cannot use calloc/free.
81component_test_psa_crypto_without_heap() {
Valerio Setti13aadd72024-08-13 13:13:23 +020082 msg "crypto without heap: build libtestdriver1"
Valerio Settia47b0452024-06-25 18:31:36 +020083 # Disable PSA features that cannot be accelerated and whose builtin support
84 # requires calloc/free.
David Horstmann7cbeedc2025-08-26 17:26:45 +010085 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
86 scripts/config.py unset-all "^PSA_WANT_ALG_HKDF"
87 scripts/config.py unset-all "^PSA_WANT_ALG_PBKDF2_"
88 scripts/config.py unset-all "^PSA_WANT_ALG_TLS12_"
Valerio Settia47b0452024-06-25 18:31:36 +020089 # RSA key support requires ASN1 parse/write support for testing, but ASN1
90 # is disabled below.
David Horstmann7cbeedc2025-08-26 17:26:45 +010091 scripts/config.py unset-all "^PSA_WANT_KEY_TYPE_RSA_"
92 scripts/config.py unset-all "^PSA_WANT_ALG_RSA_"
Valerio Settia47b0452024-06-25 18:31:36 +020093 # DES requires built-in support for key generation (parity check) so it
94 # cannot be accelerated
David Horstmann7cbeedc2025-08-26 17:26:45 +010095 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
Valerio Settia47b0452024-06-25 18:31:36 +020096 # EC-JPAKE use calloc/free in PSA core
David Horstmann7cbeedc2025-08-26 17:26:45 +010097 scripts/config.py unset PSA_WANT_ALG_JPAKE
Valerio Settia785eea2025-08-13 10:57:46 +020098 # Enable p192[k|r]1 curves which are disabled by default in tf-psa-crypto.
99 # This is required to get the proper test coverage otherwise there are
100 # tests in 'test_suite_psa_crypto_op_fail' that would never be executed.
101 scripts/config.py set PSA_WANT_ECC_SECP_K1_192
102 scripts/config.py set PSA_WANT_ECC_SECP_R1_192
Valerio Settia47b0452024-06-25 18:31:36 +0200103
104 # Accelerate all PSA features (which are still enabled in CRYPTO_CONFIG_H).
David Horstmann7cbeedc2025-08-26 17:26:45 +0100105 PSA_SYM_LIST=$(./scripts/config.py get-all-enabled PSA_WANT)
Valerio Settia47b0452024-06-25 18:31:36 +0200106 loc_accel_list=$(echo $PSA_SYM_LIST | sed 's/PSA_WANT_//g')
107
Valerio Settia47b0452024-06-25 18:31:36 +0200108 helper_libtestdriver1_adjust_config crypto
109 helper_libtestdriver1_make_drivers "$loc_accel_list"
110
Valerio Setti13aadd72024-08-13 13:13:23 +0200111 msg "crypto without heap: build main library"
Valerio Setti35b0b022024-08-13 13:36:50 +0200112 # Disable all legacy MBEDTLS_xxx symbols.
113 scripts/config.py unset-all "^MBEDTLS_"
114 # Build the PSA core using the proper config file.
115 scripts/config.py set MBEDTLS_PSA_CRYPTO_C
Valerio Settia47b0452024-06-25 18:31:36 +0200116 # Enable fully-static key slots in PSA core.
117 scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOTS
Valerio Setti35b0b022024-08-13 13:36:50 +0200118 # Prevent PSA core from creating a copy of input/output buffers.
Valerio Settia47b0452024-06-25 18:31:36 +0200119 scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
120 # Prevent PSA core from using CTR-DRBG or HMAC-DRBG for random generation.
121 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Valerio Setti13aadd72024-08-13 13:13:23 +0200122 # Set calloc/free as null pointer functions. Calling them would crash
Valerio Settia47b0452024-06-25 18:31:36 +0200123 # the program so we can use this as a "sentinel" for being sure no module
124 # is making use of these functions in the library.
Valerio Setti35b0b022024-08-13 13:36:50 +0200125 scripts/config.py set MBEDTLS_PLATFORM_C
Valerio Settia47b0452024-06-25 18:31:36 +0200126 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
127 scripts/config.py set MBEDTLS_PLATFORM_STD_CALLOC NULL
128 scripts/config.py set MBEDTLS_PLATFORM_STD_FREE NULL
129
Valerio Settia47b0452024-06-25 18:31:36 +0200130 helper_libtestdriver1_make_main "$loc_accel_list" lib
131
Valerio Setti13aadd72024-08-13 13:13:23 +0200132 msg "crypto without heap: build test suites and helpers"
133 # Reset calloc/free functions to normal operations so that test code can
Valerio Settia47b0452024-06-25 18:31:36 +0200134 # freely use them.
135 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
136 scripts/config.py unset MBEDTLS_PLATFORM_STD_CALLOC
137 scripts/config.py unset MBEDTLS_PLATFORM_STD_FREE
138 helper_libtestdriver1_make_main "$loc_accel_list" tests
139
Valerio Setti13aadd72024-08-13 13:13:23 +0200140 msg "crypto without heap: test"
Valerio Settia47b0452024-06-25 18:31:36 +0200141 make test
142}
143
Minos Galanakisf78447f2024-07-26 20:49:51 +0100144component_test_no_rsa_key_pair_generation () {
Minos Galanakisdc0f73a2024-07-26 20:41:42 +0100145 msg "build: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
David Horstmann7cbeedc2025-08-26 17:26:45 +0100146 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Minos Galanakisdc0f73a2024-07-26 20:41:42 +0100147 make
148
149 msg "test: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
150 make test
151}
152
Minos Galanakisc06fd302024-08-01 12:16:59 +0100153component_test_no_pem_no_fs () {
154 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
155 scripts/config.py unset MBEDTLS_PEM_PARSE_C
156 scripts/config.py unset MBEDTLS_FS_IO
157 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
158 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
159 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
160 make
161
162 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
163 make test
164
165 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
166 tests/ssl-opt.sh
167}
168
169component_test_rsa_no_crt () {
170 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
171 scripts/config.py set MBEDTLS_RSA_NO_CRT
172 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
173 make
174
175 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
176 make test
177
178 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
179 tests/ssl-opt.sh -f RSA
180
181 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
182 tests/compat.sh -t RSA
183
184 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
185 tests/context-info.sh
186}
187
Minos Galanakisc06fd302024-08-01 12:16:59 +0100188component_test_no_ctr_drbg_use_psa () {
189 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
190 scripts/config.py full
191 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Minos Galanakisc06fd302024-08-01 12:16:59 +0100192
193 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
194 make
195
196 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
197 make test
198
199 # In this configuration, the TLS test programs use HMAC_DRBG.
200 # The SSL tests are slow, so run a small subset, just enough to get
201 # confidence that the SSL code copes with HMAC_DRBG.
202 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
203 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
204
205 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
206 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
207}
208
Minos Galanakisc06fd302024-08-01 12:16:59 +0100209component_test_no_hmac_drbg_use_psa () {
210 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
211 scripts/config.py full
212 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
David Horstmann7cbeedc2025-08-26 17:26:45 +0100213 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA # requires HMAC_DRBG
Minos Galanakisc06fd302024-08-01 12:16:59 +0100214
215 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
216 make
217
218 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
219 make test
220
221 # Normally our ECDSA implementation uses deterministic ECDSA. But since
222 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
223 # instead.
224 # Test SSL with non-deterministic ECDSA. Only test features that
225 # might be affected by how ECDSA signature is performed.
226 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
227 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
228
229 # To save time, only test one protocol version, since this part of
230 # the protocol is identical in (D)TLS up to 1.2.
231 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
232 tests/compat.sh -m tls12 -t 'ECDSA'
233}
234
Minos Galanakisc06fd302024-08-01 12:16:59 +0100235component_test_psa_external_rng_no_drbg_use_psa () {
236 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
237 scripts/config.py full
238 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Minos Galanakisc06fd302024-08-01 12:16:59 +0100239 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
240 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
241 scripts/config.py unset MBEDTLS_CTR_DRBG_C
242 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
David Horstmann7cbeedc2025-08-26 17:26:45 +0100243 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA # Requires HMAC_DRBG
Minos Galanakisc06fd302024-08-01 12:16:59 +0100244 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
245
246 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
247 make test
248
249 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
250 tests/ssl-opt.sh -f 'Default\|opaque'
251}
252
Minos Galanakis471b34c2024-07-26 15:39:24 +0100253component_test_psa_external_rng_use_psa_crypto () {
Ronald Cron3b306432025-09-02 18:30:08 +0200254 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG/NV_SEED"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100255 scripts/config.py full
256 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Minos Galanakis471b34c2024-07-26 15:39:24 +0100257 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Ronald Cron3b306432025-09-02 18:30:08 +0200258 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
259 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Minos Galanakis471b34c2024-07-26 15:39:24 +0100260 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
261
Ronald Cron3b306432025-09-02 18:30:08 +0200262 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG/NV_SEED"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100263 make test
264
Ronald Cron3b306432025-09-02 18:30:08 +0200265 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG/NV_SEED"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100266 tests/ssl-opt.sh -f 'Default\|opaque'
267}
268
Minos Galanakisf78447f2024-07-26 20:49:51 +0100269component_full_no_pkparse_pkwrite () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100270 msg "build: full without pkparse and pkwrite"
271
272 scripts/config.py crypto_full
273 scripts/config.py unset MBEDTLS_PK_PARSE_C
274 scripts/config.py unset MBEDTLS_PK_WRITE_C
275
276 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
277
278 # Ensure that PK_[PARSE|WRITE]_C were not re-enabled accidentally (additive config).
279 not grep mbedtls_pk_parse_key ${BUILTIN_SRC_PATH}/pkparse.o
280 not grep mbedtls_pk_write_key_der ${BUILTIN_SRC_PATH}/pkwrite.o
281
282 msg "test: full without pkparse and pkwrite"
283 make test
284}
285
286component_test_crypto_full_md_light_only () {
287 msg "build: crypto_full with only the light subset of MD"
288 scripts/config.py crypto_full
289
290 # Disable MD
291 scripts/config.py unset MBEDTLS_MD_C
292 # Disable direct dependencies of MD_C
293 scripts/config.py unset MBEDTLS_HKDF_C
294 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
295 scripts/config.py unset MBEDTLS_PKCS7_C
296 # Disable indirect dependencies of MD_C
David Horstmann7cbeedc2025-08-26 17:26:45 +0100297 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
Minos Galanakis471b34c2024-07-26 15:39:24 +0100298 # Disable things that would auto-enable MD_C
299 scripts/config.py unset MBEDTLS_PKCS5_C
300
301 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
302 # which we haven't disabled, so no need to explicitly enable it.
303 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
304
305 # Make sure we don't have the HMAC functions, but the hashing functions
306 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
307 grep mbedtls_md ${BUILTIN_SRC_PATH}/md.o
308
309 msg "test: crypto_full with only the light subset of MD"
310 make test
311}
312
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100313component_test_full_no_cipher () {
314 msg "build: full no CIPHER"
315
316 scripts/config.py full
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100317
318 # The built-in implementation of the following algs/key-types depends
319 # on CIPHER_C so we disable them.
320 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
321 # so we keep them enabled.
David Horstmann7cbeedc2025-08-26 17:26:45 +0100322 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
323 scripts/config.py unset PSA_WANT_ALG_CMAC
324 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
325 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
326 scripts/config.py unset PSA_WANT_ALG_CFB
327 scripts/config.py unset PSA_WANT_ALG_CTR
328 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
329 scripts/config.py unset PSA_WANT_ALG_OFB
330 scripts/config.py unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
331 scripts/config.py unset PSA_WANT_ALG_STREAM_CIPHER
332 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100333
334 # The following modules directly depends on CIPHER_C
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100335 scripts/config.py unset MBEDTLS_NIST_KW_C
336
337 make
338
339 # Ensure that CIPHER_C was not re-enabled
340 not grep mbedtls_cipher_init ${BUILTIN_SRC_PATH}/cipher.o
341
342 msg "test: full no CIPHER"
343 make test
344}
345
Minos Galanakisf78447f2024-07-26 20:49:51 +0100346component_test_full_no_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100347 msg "build: full no PSA_WANT_ALG_CCM"
348
349 # Full config enables:
350 # - USE_PSA_CRYPTO so that TLS code dispatches cipher/AEAD to PSA
351 # - CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
352 scripts/config.py full
353
354 # Disable PSA_WANT_ALG_CCM so that CCM is not supported in PSA. CCM_C is still
355 # enabled, but not used from TLS since USE_PSA is set.
356 # This is helpful to ensure that TLS tests below have proper dependencies.
357 #
358 # Note: also PSA_WANT_ALG_CCM_STAR_NO_TAG is enabled, but it does not cause
359 # PSA_WANT_ALG_CCM to be re-enabled.
David Horstmannb907dbc2025-08-27 15:19:40 +0100360 scripts/config.py unset PSA_WANT_ALG_CCM
Minos Galanakis471b34c2024-07-26 15:39:24 +0100361
362 make
363
364 msg "test: full no PSA_WANT_ALG_CCM"
365 make test
366}
367
Minos Galanakisf78447f2024-07-26 20:49:51 +0100368component_test_full_no_ccm_star_no_tag () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100369 msg "build: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
370
371 # Full config enables CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
372 scripts/config.py full
373
374 # Disable CCM_STAR_NO_TAG, which is the target of this test, as well as all
375 # other components that enable MBEDTLS_PSA_BUILTIN_CIPHER internal symbol.
376 # This basically disables all unauthenticated ciphers on the PSA side, while
377 # keeping AEADs enabled.
378 #
379 # Note: PSA_WANT_ALG_CCM is enabled, but it does not cause
380 # PSA_WANT_ALG_CCM_STAR_NO_TAG to be re-enabled.
David Horstmannb907dbc2025-08-27 15:19:40 +0100381 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
382 scripts/config.py unset PSA_WANT_ALG_STREAM_CIPHER
383 scripts/config.py unset PSA_WANT_ALG_CTR
384 scripts/config.py unset PSA_WANT_ALG_CFB
385 scripts/config.py unset PSA_WANT_ALG_OFB
386 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
Ben Taylor1948c942025-03-04 09:11:11 +0000387 # NOTE unsettting PSA_WANT_ALG_ECB_NO_PADDING without unsetting NIST_KW_C will
388 # mean PSA_WANT_ALG_ECB_NO_PADDING is re-enabled, so disabling it also.
David Horstmannb907dbc2025-08-27 15:19:40 +0100389 scripts/config.py unset MBEDTLS_NIST_KW_C
390 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
391 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
Minos Galanakis471b34c2024-07-26 15:39:24 +0100392
393 make
394
395 # Ensure MBEDTLS_PSA_BUILTIN_CIPHER was not enabled
396 not grep mbedtls_psa_cipher ${PSA_CORE_PATH}/psa_crypto_cipher.o
397
398 msg "test: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
399 make test
400}
401
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200402component_test_config_symmetric_only () {
403 msg "build: configs/config-symmetric-only.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +0000404 MBEDTLS_CONFIG="configs/config-symmetric-only.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +0000405 CRYPTO_CONFIG="tf-psa-crypto/configs/crypto-config-symmetric-only.h"
Ronald Cronfaadfc22024-12-07 17:24:28 +0100406 CC=$ASAN_CC cmake -DMBEDTLS_CONFIG_FILE="$MBEDTLS_CONFIG" -DTF_PSA_CRYPTO_CONFIG_FILE="$CRYPTO_CONFIG" -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskineaf5a8992024-09-14 11:27:44 +0200407 make
408
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200409 msg "test: configs/config-symmetric-only.h - unit tests"
Gilles Peskineaf5a8992024-09-14 11:27:44 +0200410 make test
411}
412
Minos Galanakisc06fd302024-08-01 12:16:59 +0100413component_test_everest () {
414 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
415 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
416 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
417 make
418
419 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
420 make test
421
422 msg "test: metatests (clang, ASan)"
423 tests/scripts/run-metatests.sh any asan poison
424
425 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
426 tests/ssl-opt.sh -f ECDH
427
428 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
429 # Exclude some symmetric ciphers that are redundant here to gain time.
430 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
431}
432
Ben Taylor59213b62025-08-14 10:01:06 +0100433component_test_everest_curve25519_only () {
Ben Taylorf5729362025-09-02 13:10:52 +0100434 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
Ben Taylor59213b62025-08-14 10:01:06 +0100435 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Ben Taylor59213b62025-08-14 10:01:06 +0100436 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
437 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECDSA
438 scripts/config.py -c $CRYPTO_CONFIG_H set PSA_WANT_ALG_ECDH
439 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
440 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
441 scripts/config.py unset MBEDTLS_ECJPAKE_C
442 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE
443
444 # Disable all curves
445 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
446 scripts/config.py -c $CRYPTO_CONFIG_H unset-all "PSA_WANT_ECC_[0-9A-Z_a-z]*$"
447 scripts/config.py -c $CRYPTO_CONFIG_H set PSA_WANT_ECC_MONTGOMERY_255
448
449 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
450
451 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
452 make test
453}
454
Minos Galanakis471b34c2024-07-26 15:39:24 +0100455component_test_psa_collect_statuses () {
456 msg "build+test: psa_collect_statuses" # ~30s
457 scripts/config.py full
458 tests/scripts/psa_collect_statuses.py
459 # Check that psa_crypto_init() succeeded at least once
460 grep -q '^0:psa_crypto_init:' tests/statuses.log
461 rm -f tests/statuses.log
462}
463
464# Check that the specified libraries exist and are empty.
465are_empty_libraries () {
466 nm "$@" >/dev/null 2>/dev/null
467 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
468}
469
Minos Galanakis471b34c2024-07-26 15:39:24 +0100470component_test_crypto_for_psa_service () {
471 msg "build: make, config for PSA crypto service"
472 scripts/config.py crypto
473 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
474 # Disable things that are not needed for just cryptography, to
475 # reach a configuration that would be typical for a PSA cryptography
476 # service providing all implemented PSA algorithms.
477 # System stuff
478 scripts/config.py unset MBEDTLS_ERROR_C
479 scripts/config.py unset MBEDTLS_TIMING_C
480 scripts/config.py unset MBEDTLS_VERSION_FEATURES
481 # Crypto stuff with no PSA interface
482 scripts/config.py unset MBEDTLS_BASE64_C
Minos Galanakis471b34c2024-07-26 15:39:24 +0100483 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
484 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
485 scripts/config.py unset MBEDTLS_NIST_KW_C
486 scripts/config.py unset MBEDTLS_PEM_PARSE_C
487 scripts/config.py unset MBEDTLS_PEM_WRITE_C
488 scripts/config.py unset MBEDTLS_PKCS12_C
489 scripts/config.py unset MBEDTLS_PKCS5_C
490 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
491 # in PSA code to work with RSA keys. We don't require users to set those:
492 # they will be reenabled in build_info.h.
493 scripts/config.py unset MBEDTLS_PK_C
494 scripts/config.py unset MBEDTLS_PK_PARSE_C
495 scripts/config.py unset MBEDTLS_PK_WRITE_C
496 make CFLAGS='-O1 -Werror' all test
497 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
498}
499
500component_build_crypto_baremetal () {
501 msg "build: make, crypto only, baremetal config"
502 scripts/config.py crypto_baremetal
David Horstmann5b93d972024-10-31 15:36:05 +0000503 make CFLAGS="-O1 -Werror -I$PWD/framework/tests/include/baremetal-override/"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100504 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
505}
506
507support_build_crypto_baremetal () {
508 support_build_baremetal "$@"
509}
510
511# depends.py family of tests
512component_test_depends_py_cipher_id () {
513 msg "test/build: depends.py cipher_id (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200514 tests/scripts/depends.py cipher_id
Minos Galanakis471b34c2024-07-26 15:39:24 +0100515}
516
517component_test_depends_py_cipher_chaining () {
518 msg "test/build: depends.py cipher_chaining (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200519 tests/scripts/depends.py cipher_chaining
Minos Galanakis471b34c2024-07-26 15:39:24 +0100520}
521
Minos Galanakis471b34c2024-07-26 15:39:24 +0100522component_test_depends_py_curves () {
523 msg "test/build: depends.py curves (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200524 tests/scripts/depends.py curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100525}
526
527component_test_depends_py_hashes () {
528 msg "test/build: depends.py hashes (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200529 tests/scripts/depends.py hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +0100530}
531
Minos Galanakis471b34c2024-07-26 15:39:24 +0100532component_test_depends_py_pkalgs () {
533 msg "test/build: depends.py pkalgs (gcc)"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100534 tests/scripts/depends.py pkalgs
535}
536
537component_test_psa_crypto_config_ffdh_2048_only () {
538 msg "build: full config - only DH 2048"
539
540 scripts/config.py full
541
542 # Disable all DH groups other than 2048.
David Horstmannb907dbc2025-08-27 15:19:40 +0100543 scripts/config.py unset PSA_WANT_DH_RFC7919_3072
544 scripts/config.py unset PSA_WANT_DH_RFC7919_4096
545 scripts/config.py unset PSA_WANT_DH_RFC7919_6144
546 scripts/config.py unset PSA_WANT_DH_RFC7919_8192
Minos Galanakis471b34c2024-07-26 15:39:24 +0100547
548 make CFLAGS="$ASAN_CFLAGS -Werror" LDFLAGS="$ASAN_CFLAGS"
549
550 msg "test: full config - only DH 2048"
551 make test
552
553 msg "ssl-opt: full config - only DH 2048"
554 tests/ssl-opt.sh -f "ffdh"
555}
556
Minos Galanakis471b34c2024-07-26 15:39:24 +0100557component_test_psa_crypto_config_accel_ecdsa () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200558 msg "build: accelerated ECDSA"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100559
Minos Galanakis471b34c2024-07-26 15:39:24 +0100560 # Configure
561 # ---------
562
Elena Uziunaite91d83862024-09-04 14:51:31 +0100563 # Start from default config + TLS 1.3
Minos Galanakis471b34c2024-07-26 15:39:24 +0100564 helper_libtestdriver1_adjust_config "default"
565
Valerio Setti37a42812025-08-11 12:52:49 +0200566 # Algorithms and key types to accelerate
567 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
568 $(helper_get_psa_key_type_list "ECC") \
569 $(helper_get_psa_curve_list)"
570
Minos Galanakis471b34c2024-07-26 15:39:24 +0100571 # Disable things that depend on it
572 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +0100573
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 things that depend on it
Minos Galanakis471b34c2024-07-26 15:39:24 +0100610 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
611 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
612 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
613
614 # Build
615 # -----
616
617 helper_libtestdriver1_make_drivers "$loc_accel_list"
618
619 helper_libtestdriver1_make_main "$loc_accel_list"
620
621 # Make sure this was not re-enabled by accident (additive config)
622 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
623
624 # Run the tests
625 # -------------
626
Ronald Cron93ba6252024-09-05 10:37:14 +0200627 msg "test: accelerated ECDH"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100628 make test
629}
630
631component_test_psa_crypto_config_accel_ffdh () {
632 msg "build: full with accelerated FFDH"
633
Minos Galanakis471b34c2024-07-26 15:39:24 +0100634 # Configure
635 # ---------
636
637 # start with full (USE_PSA and TLS 1.3)
638 helper_libtestdriver1_adjust_config "full"
639
Valerio Setti37a42812025-08-11 12:52:49 +0200640 # Algorithms and key types to accelerate
641 loc_accel_list="ALG_FFDH \
642 $(helper_get_psa_key_type_list "DH") \
643 $(helper_get_psa_dh_group_list)"
644
Minos Galanakis471b34c2024-07-26 15:39:24 +0100645 # Build
646 # -----
647
648 helper_libtestdriver1_make_drivers "$loc_accel_list"
649
650 helper_libtestdriver1_make_main "$loc_accel_list"
651
652 # Make sure this was not re-enabled by accident (additive config)
Valerio Settieb63eb22025-02-12 13:32:49 +0100653 not grep mbedtls_psa_ffdh_key_agreement ${BUILTIN_SRC_PATH}/psa_crypto_ffdh.o
Minos Galanakis471b34c2024-07-26 15:39:24 +0100654
655 # Run the tests
656 # -------------
657
658 msg "test: full with accelerated FFDH"
659 make test
660
661 msg "ssl-opt: full with accelerated FFDH alg"
662 tests/ssl-opt.sh -f "ffdh"
663}
664
665component_test_psa_crypto_config_reference_ffdh () {
666 msg "build: full with non-accelerated FFDH"
667
668 # Start with full (USE_PSA and TLS 1.3)
669 helper_libtestdriver1_adjust_config "full"
670
Minos Galanakis471b34c2024-07-26 15:39:24 +0100671 make
672
673 msg "test suites: full with non-accelerated FFDH alg"
674 make test
675
676 msg "ssl-opt: full with non-accelerated FFDH alg"
677 tests/ssl-opt.sh -f "ffdh"
678}
679
Minos Galanakisf78447f2024-07-26 20:49:51 +0100680component_test_psa_crypto_config_accel_pake () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100681 msg "build: full with accelerated PAKE"
682
Minos Galanakis471b34c2024-07-26 15:39:24 +0100683 # Configure
684 # ---------
685
686 helper_libtestdriver1_adjust_config "full"
687
Valerio Setti37a42812025-08-11 12:52:49 +0200688 loc_accel_list="ALG_JPAKE \
689 $(helper_get_psa_key_type_list "ECC") \
690 $(helper_get_psa_curve_list)"
691
Minos Galanakis471b34c2024-07-26 15:39:24 +0100692 # Make built-in fallback not available
693 scripts/config.py unset MBEDTLS_ECJPAKE_C
694 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
695
696 # Build
697 # -----
698
699 helper_libtestdriver1_make_drivers "$loc_accel_list"
700
701 helper_libtestdriver1_make_main "$loc_accel_list"
702
703 # Make sure this was not re-enabled by accident (additive config)
704 not grep mbedtls_ecjpake_init ${BUILTIN_SRC_PATH}/ecjpake.o
705
706 # Run the tests
707 # -------------
708
709 msg "test: full with accelerated PAKE"
710 make test
711}
712
713component_test_psa_crypto_config_accel_ecc_some_key_types () {
714 msg "build: full with accelerated EC algs and some key types"
715
Valerio Setti37a42812025-08-11 12:52:49 +0200716 # Configure
717 # ---------
718
719 # start with config full for maximum coverage (also enables USE_PSA)
720 helper_libtestdriver1_adjust_config "full"
721
Minos Galanakis471b34c2024-07-26 15:39:24 +0100722 # Algorithms and key types to accelerate
723 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
724 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
725 ALG_ECDH \
726 ALG_JPAKE \
727 KEY_TYPE_ECC_PUBLIC_KEY \
728 KEY_TYPE_ECC_KEY_PAIR_BASIC \
729 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
730 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
731 $(helper_get_psa_curve_list)"
732
Minos Galanakis471b34c2024-07-26 15:39:24 +0100733 # Disable modules that are accelerated - some will be re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +0100734 scripts/config.py unset MBEDTLS_ECJPAKE_C
735 scripts/config.py unset MBEDTLS_ECP_C
736
737 # Disable all curves - those that aren't accelerated should be re-enabled
738 helper_disable_builtin_curves
739
740 # Restartable feature is not yet supported by PSA. Once it will in
741 # the future, the following line could be removed (see issues
742 # 6061, 6332 and following ones)
743 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
744
745 # this is not supported by the driver API yet
David Horstmannb907dbc2025-08-27 15:19:40 +0100746 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +0100747
748 # Build
749 # -----
750
751 # These hashes are needed for some ECDSA signature tests.
752 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
753 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
754 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
755
756 helper_libtestdriver1_make_main "$loc_accel_list"
757
758 # ECP should be re-enabled but not the others
759 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
760 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
761 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
762 grep mbedtls_ecp ${BUILTIN_SRC_PATH}/ecp.o
763
764 # Run the tests
765 # -------------
766
767 msg "test suites: full with accelerated EC algs and some key types"
768 make test
769}
770
771# Run tests with only (non-)Weierstrass accelerated
772# Common code used in:
773# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
774# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100775common_test_psa_crypto_config_accel_ecc_some_curves () {
776 weierstrass=$1
777 if [ $weierstrass -eq 1 ]; then
778 desc="Weierstrass"
779 else
780 desc="non-Weierstrass"
781 fi
782
783 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
784
Valerio Setti37a42812025-08-11 12:52:49 +0200785 # Configure
786 # ---------
787
788 # Start with config crypto_full and remove PK_C:
789 # that's what's supported now, see docs/driver-only-builds.md.
790 helper_libtestdriver1_adjust_config "crypto_full"
791 scripts/config.py unset MBEDTLS_PK_C
792 scripts/config.py unset MBEDTLS_PK_PARSE_C
793 scripts/config.py unset MBEDTLS_PK_WRITE_C
794
795 # Disable modules that are accelerated - some will be re-enabled
Valerio Setti37a42812025-08-11 12:52:49 +0200796 scripts/config.py unset MBEDTLS_ECJPAKE_C
797 scripts/config.py unset MBEDTLS_ECP_C
798
799 # Disable all curves - those that aren't accelerated should be re-enabled
800 helper_disable_builtin_curves
801
Valerio Setti981a0c42025-08-12 11:31:11 +0200802 # Note: Curves are handled in a special way by the libtestdriver machinery,
Minos Galanakis471b34c2024-07-26 15:39:24 +0100803 # so we only want to include them in the accel list when building the main
804 # libraries, hence the use of a separate variable.
805 # Note: the following loop is a modified version of
806 # helper_get_psa_curve_list that only keeps Weierstrass families.
807 loc_weierstrass_list=""
808 loc_non_weierstrass_list=""
809 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
810 case $item in
811 ECC_BRAINPOOL*|ECC_SECP*)
812 loc_weierstrass_list="$loc_weierstrass_list $item"
813 ;;
814 *)
815 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
816 ;;
817 esac
818 done
819 if [ $weierstrass -eq 1 ]; then
820 loc_curve_list=$loc_weierstrass_list
821 else
822 loc_curve_list=$loc_non_weierstrass_list
823 fi
824
825 # Algorithms and key types to accelerate
826 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
827 ALG_ECDH \
828 ALG_JPAKE \
829 $(helper_get_psa_key_type_list "ECC") \
830 $loc_curve_list"
831
Minos Galanakis471b34c2024-07-26 15:39:24 +0100832 # Restartable feature is not yet supported by PSA. Once it will in
833 # the future, the following line could be removed (see issues
834 # 6061, 6332 and following ones)
835 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
836
837 # this is not supported by the driver API yet
David Horstmannb907dbc2025-08-27 15:19:40 +0100838 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +0100839
840 # Build
841 # -----
842
843 # These hashes are needed for some ECDSA signature tests.
844 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
845 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
846 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
847
848 helper_libtestdriver1_make_main "$loc_accel_list"
849
850 # We expect ECDH to be re-enabled for the missing curves
851 grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
852 # We expect ECP to be re-enabled, however the parts specific to the
853 # families of curves that are accelerated should be ommited.
854 # - functions with mxz in the name are specific to Montgomery curves
855 # - ecp_muladd is specific to Weierstrass curves
856 ##nm ${BUILTIN_SRC_PATH}/ecp.o | tee ecp.syms
857 if [ $weierstrass -eq 1 ]; then
858 not grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
859 grep mxz ${BUILTIN_SRC_PATH}/ecp.o
860 else
861 grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
862 not grep mxz ${BUILTIN_SRC_PATH}/ecp.o
863 fi
864 # We expect ECDSA and ECJPAKE to be re-enabled only when
865 # Weierstrass curves are not accelerated
866 if [ $weierstrass -eq 1 ]; then
867 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
868 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
869 else
870 grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
871 grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
872 fi
873
874 # Run the tests
875 # -------------
876
877 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
Valerio Setti981a0c42025-08-12 11:31:11 +0200878 make test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100879}
880
881component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
882 common_test_psa_crypto_config_accel_ecc_some_curves 1
883}
884
885component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
886 common_test_psa_crypto_config_accel_ecc_some_curves 0
887}
888
889# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
890# ECDH, ECDSA) with and without drivers.
891# The input parameter is a boolean value which indicates:
892# - 0 keep built-in EC algs,
893# - 1 exclude built-in EC algs (driver only).
894#
895# This is used by the two following components to ensure they always use the
896# same config, except for the use of driver or built-in EC algorithms:
897# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
898# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
899# This supports comparing their test coverage with analyze_outcomes.py.
Minos Galanakis471b34c2024-07-26 15:39:24 +0100900config_psa_crypto_config_ecp_light_only () {
901 driver_only="$1"
902 # start with config full for maximum coverage (also enables USE_PSA)
903 helper_libtestdriver1_adjust_config "full"
904 if [ "$driver_only" -eq 1 ]; then
905 # Disable modules that are accelerated
Minos Galanakis471b34c2024-07-26 15:39:24 +0100906 scripts/config.py unset MBEDTLS_ECJPAKE_C
907 scripts/config.py unset MBEDTLS_ECP_C
908 fi
909
910 # Restartable feature is not yet supported by PSA. Once it will in
911 # the future, the following line could be removed (see issues
912 # 6061, 6332 and following ones)
913 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
914}
915
916# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100917component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
918 msg "build: full with accelerated EC algs"
919
Valerio Setti37a42812025-08-11 12:52:49 +0200920 # Configure
921 # ---------
922
923 # Use the same config as reference, only without built-in EC algs
924 config_psa_crypto_config_ecp_light_only 1
925
Minos Galanakis471b34c2024-07-26 15:39:24 +0100926 # Algorithms and key types to accelerate
927 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
928 ALG_ECDH \
929 ALG_JPAKE \
930 $(helper_get_psa_key_type_list "ECC") \
931 $(helper_get_psa_curve_list)"
932
Minos Galanakis471b34c2024-07-26 15:39:24 +0100933 # Do not disable builtin curves because that support is required for:
934 # - MBEDTLS_PK_PARSE_EC_EXTENDED
935 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
936
937 # Build
938 # -----
939
940 # These hashes are needed for some ECDSA signature tests.
941 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
942 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
943 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
944
945 helper_libtestdriver1_make_main "$loc_accel_list"
946
947 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
948 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
949 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
950 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
951 not grep mbedtls_ecp_mul ${BUILTIN_SRC_PATH}/ecp.o
952
953 # Run the tests
954 # -------------
955
956 msg "test suites: full with accelerated EC algs"
957 make test
958
959 msg "ssl-opt: full with accelerated EC algs"
960 tests/ssl-opt.sh
961}
962
963# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100964component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200965 msg "build: non-accelerated EC algs"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100966
967 config_psa_crypto_config_ecp_light_only 0
968
969 make
970
971 msg "test suites: full with non-accelerated EC algs"
972 make test
973
974 msg "ssl-opt: full with non-accelerated EC algs"
975 tests/ssl-opt.sh
976}
977
978# This helper function is used by:
979# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
980# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
981# to ensure that both tests use the same underlying configuration when testing
982# driver's coverage with analyze_outcomes.py.
983#
984# This functions accepts 1 boolean parameter as follows:
985# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
986# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
987# - 0: include built-in implementation of EC algorithms.
988#
989# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
990# on the ECP module.
Minos Galanakis471b34c2024-07-26 15:39:24 +0100991config_psa_crypto_no_ecp_at_all () {
992 driver_only="$1"
993 # start with full config for maximum coverage (also enables USE_PSA)
994 helper_libtestdriver1_adjust_config "full"
995
996 if [ "$driver_only" -eq 1 ]; then
997 # Disable modules that are accelerated
Minos Galanakis471b34c2024-07-26 15:39:24 +0100998 scripts/config.py unset MBEDTLS_ECJPAKE_C
999 # Disable ECP module (entirely)
1000 scripts/config.py unset MBEDTLS_ECP_C
1001 fi
1002
1003 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1004 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1005 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
David Horstmannb907dbc2025-08-27 15:19:40 +01001006 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +01001007
1008 # Restartable feature is not yet supported by PSA. Once it will in
1009 # the future, the following line could be removed (see issues
1010 # 6061, 6332 and following ones)
1011 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1012}
1013
1014# Build and test a configuration where driver accelerates all EC algs while
1015# all support and dependencies from ECP and ECP_LIGHT are removed on the library
1016# side.
1017#
1018# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001019component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
1020 msg "build: full + accelerated EC algs - ECP"
1021
Minos Galanakis471b34c2024-07-26 15:39:24 +01001022 # Configure
1023 # ---------
1024
1025 # Set common configurations between library's and driver's builds
1026 config_psa_crypto_no_ecp_at_all 1
1027 # Disable all the builtin curves. All the required algs are accelerated.
1028 helper_disable_builtin_curves
1029
Valerio Setti37a42812025-08-11 12:52:49 +02001030 # Algorithms and key types to accelerate
1031 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1032 ALG_ECDH \
1033 ALG_JPAKE \
1034 $(helper_get_psa_key_type_list "ECC") \
1035 $(helper_get_psa_curve_list)"
1036
Minos Galanakis471b34c2024-07-26 15:39:24 +01001037 # Build
1038 # -----
1039
1040 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1041 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1042 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1043 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1044
1045 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1046
1047 helper_libtestdriver1_make_main "$loc_accel_list"
1048
1049 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1050 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1051 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1052 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1053 # Also ensure that ECP module was not re-enabled
1054 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1055
1056 # Run the tests
1057 # -------------
1058
1059 msg "test: full + accelerated EC algs - ECP"
1060 make test
1061
1062 msg "ssl-opt: full + accelerated EC algs - ECP"
1063 tests/ssl-opt.sh
1064}
1065
1066# Reference function used for driver's coverage analysis in analyze_outcomes.py
1067# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
1068# Keep in sync with its accelerated counterpart.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001069component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
1070 msg "build: full + non accelerated EC algs"
1071
1072 config_psa_crypto_no_ecp_at_all 0
1073
1074 make
1075
1076 msg "test: full + non accelerated EC algs"
1077 make test
1078
1079 msg "ssl-opt: full + non accelerated EC algs"
1080 tests/ssl-opt.sh
1081}
1082
1083# This is a common configuration helper used directly from:
1084# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1085# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1086# and indirectly from:
1087# - component_test_psa_crypto_config_accel_ecc_no_bignum
1088# - accelerate all EC algs, disable RSA and FFDH
1089# - component_test_psa_crypto_config_reference_ecc_no_bignum
1090# - this is the reference component of the above
1091# - it still disables RSA and FFDH, but it uses builtin EC algs
1092# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1093# - accelerate all EC and FFDH algs, disable only RSA
1094# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1095# - this is the reference component of the above
1096# - it still disables RSA, but it uses builtin EC and FFDH algs
1097#
1098# This function accepts 2 parameters:
1099# $1: a boolean value which states if we are testing an accelerated scenario
1100# or not.
1101# $2: a string value which states which components are tested. Allowed values
1102# are "ECC" or "ECC_DH".
Minos Galanakisf78447f2024-07-26 20:49:51 +01001103config_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001104 driver_only="$1"
1105 test_target="$2"
1106 # start with full config for maximum coverage (also enables USE_PSA)
1107 helper_libtestdriver1_adjust_config "full"
1108
1109 if [ "$driver_only" -eq 1 ]; then
1110 # Disable modules that are accelerated
Minos Galanakis471b34c2024-07-26 15:39:24 +01001111 scripts/config.py unset MBEDTLS_ECJPAKE_C
1112 # Disable ECP module (entirely)
1113 scripts/config.py unset MBEDTLS_ECP_C
1114 # Also disable bignum
1115 scripts/config.py unset MBEDTLS_BIGNUM_C
1116 fi
1117
1118 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1119 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1120 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
David Horstmannb907dbc2025-08-27 15:19:40 +01001121 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +01001122
1123 # RSA support is intentionally disabled on this test because RSA_C depends
1124 # on BIGNUM_C.
David Horstmannb907dbc2025-08-27 15:19:40 +01001125 scripts/config.py unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
1126 scripts/config.py unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001127 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1128 # Also disable key exchanges that depend on RSA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001129 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001130
1131 if [ "$test_target" = "ECC" ]; then
1132 # When testing ECC only, we disable FFDH support, both from builtin and
Valerio Setti8438c632025-01-22 11:56:40 +01001133 # PSA sides.
David Horstmannb907dbc2025-08-27 15:19:40 +01001134 scripts/config.py unset PSA_WANT_ALG_FFDH
1135 scripts/config.py unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
1136 scripts/config.py unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001137 fi
1138
1139 # Restartable feature is not yet supported by PSA. Once it will in
1140 # the future, the following line could be removed (see issues
1141 # 6061, 6332 and following ones)
1142 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1143}
1144
1145# Common helper used by:
1146# - component_test_psa_crypto_config_accel_ecc_no_bignum
1147# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1148#
1149# The goal is to build and test accelerating either:
1150# - ECC only or
1151# - both ECC and FFDH
1152#
1153# It is meant to be used in conjunction with
1154# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
1155# coverage analysis in the "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001156common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1157 test_target="$1"
1158
1159 # This is an internal helper to simplify text message handling
1160 if [ "$test_target" = "ECC_DH" ]; then
1161 accel_text="ECC/FFDH"
1162 removed_text="ECP - DH"
1163 else
1164 accel_text="ECC"
1165 removed_text="ECP"
1166 fi
1167
1168 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1169
Valerio Setti37a42812025-08-11 12:52:49 +02001170 # Configure
1171 # ---------
1172
1173 # Set common configurations between library's and driver's builds
1174 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
1175 # Disable all the builtin curves. All the required algs are accelerated.
1176 helper_disable_builtin_curves
1177
Minos Galanakis471b34c2024-07-26 15:39:24 +01001178 # By default we accelerate all EC keys/algs
1179 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1180 ALG_ECDH \
1181 ALG_JPAKE \
1182 $(helper_get_psa_key_type_list "ECC") \
1183 $(helper_get_psa_curve_list)"
1184 # Optionally we can also add DH to the list of accelerated items
1185 if [ "$test_target" = "ECC_DH" ]; then
1186 loc_accel_list="$loc_accel_list \
1187 ALG_FFDH \
1188 $(helper_get_psa_key_type_list "DH") \
1189 $(helper_get_psa_dh_group_list)"
1190 fi
1191
Minos Galanakis471b34c2024-07-26 15:39:24 +01001192 # Build
1193 # -----
1194
1195 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1196 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1197 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1198 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1199
1200 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1201
1202 helper_libtestdriver1_make_main "$loc_accel_list"
1203
1204 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1205 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1206 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1207 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001208 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001209 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1210 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1211 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001212
1213 # Run the tests
1214 # -------------
1215
Valerio Settieb63eb22025-02-12 13:32:49 +01001216 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001217
1218 make test
1219
1220 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1221 tests/ssl-opt.sh
1222}
1223
1224# Common helper used by:
1225# - component_test_psa_crypto_config_reference_ecc_no_bignum
1226# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1227#
1228# The goal is to build and test a reference scenario (i.e. with builtin
1229# components) compared to the ones used in
1230# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
1231#
1232# It is meant to be used in conjunction with
1233# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
1234# coverage analysis in "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001235common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1236 test_target="$1"
1237
1238 # This is an internal helper to simplify text message handling
1239 if [ "$test_target" = "ECC_DH" ]; then
1240 accel_text="ECC/FFDH"
1241 else
1242 accel_text="ECC"
1243 fi
1244
1245 msg "build: full + non accelerated $accel_text algs + USE_PSA"
1246
1247 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
1248
1249 make
1250
1251 msg "test suites: full + non accelerated EC algs + USE_PSA"
1252 make test
1253
1254 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
1255 tests/ssl-opt.sh
1256}
1257
1258component_test_psa_crypto_config_accel_ecc_no_bignum () {
1259 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
1260}
1261
1262component_test_psa_crypto_config_reference_ecc_no_bignum () {
1263 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
1264}
1265
1266component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1267 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
1268}
1269
1270component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1271 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
1272}
1273
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001274component_test_tfm_config_as_is () {
1275 msg "build: configs/config-tfm.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +00001276 MBEDTLS_CONFIG="configs/config-tfm.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001277 CRYPTO_CONFIG="tf-psa-crypto/configs/ext/crypto_config_profile_medium.h"
Minos Galanakis4f619e12024-11-14 14:56:47 +00001278 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 +02001279 make
1280
1281 msg "test: configs/config-tfm.h - unit tests"
1282 make test
1283}
1284
Minos Galanakis471b34c2024-07-26 15:39:24 +01001285# Helper for setting common configurations between:
1286# - component_test_tfm_config_p256m_driver_accel_ec()
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001287# - component_test_tfm_config_no_p256m()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001288common_tfm_config () {
1289 # Enable TF-M config
1290 cp configs/config-tfm.h "$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001291 cp tf-psa-crypto/configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001292
Minos Galanakis471b34c2024-07-26 15:39:24 +01001293 # Config adjustment for better test coverage in our environment.
1294 # This is not needed just to build and pass tests.
1295 #
1296 # Enable filesystem I/O for the benefit of PK parse/write tests.
Minos Galanakis5da58e52024-11-07 15:35:33 +00001297 sed -i '/PROFILE_M_PSA_CRYPTO_CONFIG_H/i #define MBEDTLS_FS_IO' "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001298}
1299
1300# Keep this in sync with component_test_tfm_config() as they are both meant
1301# to be used in analyze_outcomes.py for driver's coverage analysis.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001302component_test_tfm_config_p256m_driver_accel_ec () {
1303 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1304
1305 common_tfm_config
1306
1307 # Build crypto library
David Horstmann5b93d972024-10-31 15:36:05 +00001308 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../framework/tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001309
1310 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1311 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1312 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1313 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001314 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001315 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1316 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001317 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1318 # Check that p256m was built
1319 grep -q p256_ecdsa_ library/libmbedcrypto.a
1320
1321 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1322 # files, so we want to ensure that it has not be re-enabled accidentally.
1323 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1324
1325 # Run the tests
1326 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1327 make test
1328}
1329
1330# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1331# they are both meant to be used in analyze_outcomes.py for driver's coverage
1332# analysis.
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001333component_test_tfm_config_no_p256m () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001334 common_tfm_config
1335
1336 # Disable P256M driver, which is on by default, so that analyze_outcomes
1337 # can compare this test with test_tfm_config_p256m_driver_accel_ec
Ben Taylora2aa7da2025-09-04 11:22:52 +01001338 scripts/config.py -f "$CRYPTO_CONFIG_H" unset MBEDTLS_PSA_P256M_DRIVER_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001339
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001340 msg "build: TF-M config without p256m"
David Horstmann5b93d972024-10-31 15:36:05 +00001341 make CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' tests
Minos Galanakis471b34c2024-07-26 15:39:24 +01001342
1343 # Check that p256m was not built
1344 not grep p256_ecdsa_ library/libmbedcrypto.a
1345
1346 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1347 # files, so we want to ensure that it has not be re-enabled accidentally.
1348 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1349
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001350 msg "test: TF-M config without p256m"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001351 make test
1352}
1353
Minos Galanakis471b34c2024-07-26 15:39:24 +01001354# This is an helper used by:
1355# - component_test_psa_ecc_key_pair_no_derive
1356# - component_test_psa_ecc_key_pair_no_generate
1357# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1358# enabled, but one. Input arguments are as follows:
Gilles Peskinefef912c2024-09-20 16:07:09 +02001359# - $1 is the configuration to start from
1360# - $2 is the key type under test, i.e. ECC/RSA/DH
1361# - $3 is the key option to be unset (i.e. generate, derive, etc)
Minos Galanakisf78447f2024-07-26 20:49:51 +01001362build_and_test_psa_want_key_pair_partial () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001363 base_config=$1
1364 key_type=$2
1365 unset_option=$3
Minos Galanakis471b34c2024-07-26 15:39:24 +01001366 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1367
Gilles Peskinefef912c2024-09-20 16:07:09 +02001368 msg "build: $base_config - ${disabled_psa_want}"
1369 scripts/config.py "$base_config"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001370
1371 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1372 # crypto_config.h so we just disable the one we don't want.
David Horstmannb907dbc2025-08-27 15:19:40 +01001373 scripts/config.py unset "$disabled_psa_want"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001374
1375 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1376
Gilles Peskinefef912c2024-09-20 16:07:09 +02001377 msg "test: $base_config - ${disabled_psa_want}"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001378 make test
1379}
1380
Minos Galanakisf78447f2024-07-26 20:49:51 +01001381component_test_psa_ecc_key_pair_no_derive () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001382 build_and_test_psa_want_key_pair_partial full "ECC" "DERIVE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001383}
1384
Minos Galanakisf78447f2024-07-26 20:49:51 +01001385component_test_psa_ecc_key_pair_no_generate () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001386 # TLS needs ECC key generation whenever ephemeral ECDH is enabled.
1387 # We don't have proper guards for configurations with ECC key generation
1388 # disabled (https://github.com/Mbed-TLS/mbedtls/issues/9481). Until
1389 # then (if ever), just test the crypto part of the library.
1390 build_and_test_psa_want_key_pair_partial crypto_full "ECC" "GENERATE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001391}
1392
1393config_psa_crypto_accel_rsa () {
1394 driver_only=$1
1395
1396 # Start from crypto_full config (no X.509, no TLS)
1397 helper_libtestdriver1_adjust_config "crypto_full"
1398
1399 if [ "$driver_only" -eq 1 ]; then
Minos Galanakis471b34c2024-07-26 15:39:24 +01001400 # We need PEM parsing in the test library as well to support the import
1401 # of PEM encoded RSA keys.
Minos Galanakis23452f52024-11-28 17:48:14 +00001402 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1403 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
Minos Galanakis471b34c2024-07-26 15:39:24 +01001404 fi
1405}
1406
1407component_test_psa_crypto_config_accel_rsa_crypto () {
1408 msg "build: crypto_full with accelerated RSA"
1409
1410 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1411 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1412 KEY_TYPE_RSA_PUBLIC_KEY \
1413 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1414 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1415 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1416 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1417
1418 # Configure
1419 # ---------
1420
1421 config_psa_crypto_accel_rsa 1
1422
1423 # Build
1424 # -----
1425
1426 # These hashes are needed for unit tests.
1427 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1428 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1429 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1430
1431 helper_libtestdriver1_make_main "$loc_accel_list"
1432
1433 # Make sure this was not re-enabled by accident (additive config)
1434 not grep mbedtls_rsa ${BUILTIN_SRC_PATH}/rsa.o
1435
1436 # Run the tests
1437 # -------------
1438
1439 msg "test: crypto_full with accelerated RSA"
1440 make test
1441}
1442
1443component_test_psa_crypto_config_reference_rsa_crypto () {
1444 msg "build: crypto_full with non-accelerated RSA"
1445
1446 # Configure
1447 # ---------
1448 config_psa_crypto_accel_rsa 0
1449
1450 # Build
1451 # -----
1452 make
1453
1454 # Run the tests
1455 # -------------
1456 msg "test: crypto_full with non-accelerated RSA"
1457 make test
1458}
1459
1460# This is a temporary test to verify that full RSA support is present even when
1461# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001462component_test_new_psa_want_key_pair_symbol () {
Ronald Cron892bb612025-07-21 14:26:27 +02001463 msg "Build: crypto config - PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001464
1465 # Create a temporary output file unless there is already one set
1466 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1467 REMOVE_OUTCOME_ON_EXIT="no"
1468 else
1469 REMOVE_OUTCOME_ON_EXIT="yes"
1470 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1471 export MBEDTLS_TEST_OUTCOME_FILE
1472 fi
1473
1474 # Start from crypto configuration
1475 scripts/config.py crypto
1476
Ronald Cron919a1e42025-09-15 14:39:26 +02001477 # Remove RSA dependencies
Minos Galanakis471b34c2024-07-26 15:39:24 +01001478 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001479 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1480
Minos Galanakis471b34c2024-07-26 15:39:24 +01001481 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
1482 # that proper translations is done in crypto_legacy.h.
David Horstmannb907dbc2025-08-27 15:19:40 +01001483 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
1484 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
1485 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Minos Galanakis471b34c2024-07-26 15:39:24 +01001486
1487 make
1488
Ronald Cron892bb612025-07-21 14:26:27 +02001489 msg "Test: crypto config - PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001490 make test
1491
1492 # Parse only 1 relevant line from the outcome file, i.e. a test which is
1493 # performing RSA signature.
1494 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
1495 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
1496
1497 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
1498 rm $MBEDTLS_TEST_OUTCOME_FILE
1499 fi
1500}
1501
1502component_test_psa_crypto_config_accel_hash () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001503 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001504
1505 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1506 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1507 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1508
1509 # Configure
1510 # ---------
1511
1512 # Start from default config (no USE_PSA)
1513 helper_libtestdriver1_adjust_config "default"
1514
Minos Galanakis471b34c2024-07-26 15:39:24 +01001515 # Build
1516 # -----
1517
1518 helper_libtestdriver1_make_drivers "$loc_accel_list"
1519
1520 helper_libtestdriver1_make_main "$loc_accel_list"
1521
1522 # There's a risk of something getting re-enabled via config_psa.h;
1523 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1524 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1525 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1526 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1527 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1528 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1529
1530 # Run the tests
1531 # -------------
1532
Ronald Cron93ba6252024-09-05 10:37:14 +02001533 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001534 make test
1535}
1536
1537# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001538config_psa_crypto_hash_use_psa () {
1539 driver_only="$1"
1540 # start with config full for maximum coverage (also enables USE_PSA)
1541 helper_libtestdriver1_adjust_config "full"
1542 if [ "$driver_only" -eq 1 ]; then
1543 # disable the built-in implementation of hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +01001544 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Minos Galanakis471b34c2024-07-26 15:39:24 +01001545 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Minos Galanakis471b34c2024-07-26 15:39:24 +01001546 fi
1547}
1548
1549# Note that component_test_psa_crypto_config_reference_hash_use_psa
1550# is related to this component and both components need to be kept in sync.
1551# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001552component_test_psa_crypto_config_accel_hash_use_psa () {
1553 msg "test: full with accelerated hashes"
1554
1555 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1556 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1557 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1558
1559 # Configure
1560 # ---------
1561
1562 config_psa_crypto_hash_use_psa 1
1563
1564 # Build
1565 # -----
1566
1567 helper_libtestdriver1_make_drivers "$loc_accel_list"
1568
1569 helper_libtestdriver1_make_main "$loc_accel_list"
1570
1571 # There's a risk of something getting re-enabled via config_psa.h;
1572 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1573 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1574 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1575 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1576 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1577 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1578
1579 # Run the tests
1580 # -------------
1581
1582 msg "test: full with accelerated hashes"
1583 make test
1584
1585 # This is mostly useful so that we can later compare outcome files with
1586 # the reference config in analyze_outcomes.py, to check that the
1587 # dependency declarations in ssl-opt.sh and in TLS code are correct.
1588 msg "test: ssl-opt.sh, full with accelerated hashes"
1589 tests/ssl-opt.sh
1590
1591 # This is to make sure all ciphersuites are exercised, but we don't need
1592 # interop testing (besides, we already got some from ssl-opt.sh).
1593 msg "test: compat.sh, full with accelerated hashes"
1594 tests/compat.sh -p mbedTLS -V YES
1595}
1596
1597# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
1598# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
1599# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
1600# Both components need to be kept in sync.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001601component_test_psa_crypto_config_reference_hash_use_psa () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001602 msg "test: full without accelerated hashes"
1603
1604 config_psa_crypto_hash_use_psa 0
1605
1606 make
1607
1608 msg "test: full without accelerated hashes"
1609 make test
1610
1611 msg "test: ssl-opt.sh, full without accelerated hashes"
1612 tests/ssl-opt.sh
1613}
1614
1615# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001616config_psa_crypto_hmac_use_psa () {
1617 driver_only="$1"
1618 # start with config full for maximum coverage (also enables USE_PSA)
1619 helper_libtestdriver1_adjust_config "full"
1620
1621 if [ "$driver_only" -eq 1 ]; then
1622 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
1623 # is still enabled though (for ENTROPY_C among others).
1624 scripts/config.py unset MBEDTLS_MD_C
Ronald Cron772a8ad2025-07-21 12:36:29 +02001625 # Also disable the configuration options that tune the builtin hashes,
1626 # since those hashes are disabled.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001627 scripts/config.py unset-all MBEDTLS_SHA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001628 fi
1629
1630 # Direct dependencies of MD_C. We disable them also in the reference
1631 # component to work with the same set of features.
1632 scripts/config.py unset MBEDTLS_PKCS7_C
1633 scripts/config.py unset MBEDTLS_PKCS5_C
1634 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1635 scripts/config.py unset MBEDTLS_HKDF_C
1636 # Dependencies of HMAC_DRBG
David Horstmannb907dbc2025-08-27 15:19:40 +01001637 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001638}
1639
Minos Galanakisf78447f2024-07-26 20:49:51 +01001640component_test_psa_crypto_config_accel_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001641 msg "test: full with accelerated hmac"
1642
1643 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
1644 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1645 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1646 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1647
1648 # Configure
1649 # ---------
1650
1651 config_psa_crypto_hmac_use_psa 1
1652
1653 # Build
1654 # -----
1655
1656 helper_libtestdriver1_make_drivers "$loc_accel_list"
1657
1658 helper_libtestdriver1_make_main "$loc_accel_list"
1659
1660 # Ensure that built-in support for HMAC is disabled.
1661 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
1662
1663 # Run the tests
1664 # -------------
1665
1666 msg "test: full with accelerated hmac"
1667 make test
1668}
1669
Minos Galanakisf78447f2024-07-26 20:49:51 +01001670component_test_psa_crypto_config_reference_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001671 msg "test: full without accelerated hmac"
1672
1673 config_psa_crypto_hmac_use_psa 0
1674
1675 make
1676
1677 msg "test: full without accelerated hmac"
1678 make test
1679}
1680
Minos Galanakis471b34c2024-07-26 15:39:24 +01001681component_test_psa_crypto_config_accel_aead () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001682 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001683
1684 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
1685 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1686
1687 # Configure
1688 # ---------
1689
1690 # Start from full config
1691 helper_libtestdriver1_adjust_config "full"
1692
Minos Galanakis471b34c2024-07-26 15:39:24 +01001693 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
David Horstmannb907dbc2025-08-27 15:19:40 +01001694 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
Minos Galanakis471b34c2024-07-26 15:39:24 +01001695
1696 # Build
1697 # -----
1698
1699 helper_libtestdriver1_make_drivers "$loc_accel_list"
1700
1701 helper_libtestdriver1_make_main "$loc_accel_list"
1702
1703 # Make sure this was not re-enabled by accident (additive config)
1704 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1705 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1706 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1707
1708 # Run the tests
1709 # -------------
1710
Ronald Cron93ba6252024-09-05 10:37:14 +02001711 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001712 make test
1713}
1714
1715# This is a common configuration function used in:
1716# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1717# - component_test_psa_crypto_config_reference_cipher_aead_cmac
Minos Galanakisf78447f2024-07-26 20:49:51 +01001718common_psa_crypto_config_accel_cipher_aead_cmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001719 # Start from the full config
1720 helper_libtestdriver1_adjust_config "full"
1721
1722 scripts/config.py unset MBEDTLS_NIST_KW_C
1723}
1724
1725# The 2 following test components, i.e.
1726# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1727# - component_test_psa_crypto_config_reference_cipher_aead_cmac
1728# are meant to be used together in analyze_outcomes.py script in order to test
1729# driver's coverage for ciphers and AEADs.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001730component_test_psa_crypto_config_accel_cipher_aead_cmac () {
1731 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
1732
1733 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
1734 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
1735 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
Ari Weiler-Ofek86422e52025-07-04 14:43:30 +01001736 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001737
1738 # Configure
1739 # ---------
1740
1741 common_psa_crypto_config_accel_cipher_aead_cmac
1742
Ari Weiler-Ofek5d8d2992025-07-07 23:20:29 +01001743 # Disable DES, if it still exists.
1744 # This can be removed once we remove DES from the library.
1745 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
1746
Minos Galanakis471b34c2024-07-26 15:39:24 +01001747 # Build
1748 # -----
1749
1750 helper_libtestdriver1_make_drivers "$loc_accel_list"
1751
1752 helper_libtestdriver1_make_main "$loc_accel_list"
1753
1754 # Make sure this was not re-enabled by accident (additive config)
1755 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001756 not grep mbedtls_aes ${BUILTIN_SRC_PATH}/aes.o
1757 not grep mbedtls_aria ${BUILTIN_SRC_PATH}/aria.o
1758 not grep mbedtls_camellia ${BUILTIN_SRC_PATH}/camellia.o
1759 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1760 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1761 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1762 not grep mbedtls_cmac ${BUILTIN_SRC_PATH}/cmac.o
Ronald Cronb5c6fcc2025-07-10 13:40:00 +02001763 not grep mbedtls_poly1305 ${BUILTIN_SRC_PATH}/poly1305.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001764
1765 # Run the tests
1766 # -------------
1767
1768 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
1769 make test
1770
1771 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
Ronald Cronbd28acf2025-07-10 09:53:50 +02001772 # Exclude password-protected key tests — they require built-in CBC and AES.
1773 tests/ssl-opt.sh -e "TLS: password protected"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001774
1775 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
1776 tests/compat.sh -V NO -p mbedTLS
1777}
1778
1779component_test_psa_crypto_config_reference_cipher_aead_cmac () {
1780 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
1781 common_psa_crypto_config_accel_cipher_aead_cmac
1782
Ari Weiler-Ofek5d8d2992025-07-07 23:20:29 +01001783 # Disable DES, if it still exists.
1784 # This can be removed once we remove DES from the library.
1785 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
1786
Minos Galanakis471b34c2024-07-26 15:39:24 +01001787 make
1788
1789 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
1790 make test
1791
1792 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
Ronald Cronbd28acf2025-07-10 09:53:50 +02001793 # Exclude password-protected key tests as in test_psa_crypto_config_accel_cipher_aead_cmac.
1794 tests/ssl-opt.sh -e "TLS: password protected"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001795
1796 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
1797 tests/compat.sh -V NO -p mbedTLS
1798}
1799
Minos Galanakisf78447f2024-07-26 20:49:51 +01001800common_block_cipher_dispatch () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001801 TEST_WITH_DRIVER="$1"
1802
1803 # Start from the full config
1804 helper_libtestdriver1_adjust_config "full"
1805
Minos Galanakis471b34c2024-07-26 15:39:24 +01001806 # Disable cipher's modes that, when not accelerated, cause
1807 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
1808 # Keep this also in the reference component in order to skip the same tests
1809 # that were skipped in the accelerated one.
David Horstmannb907dbc2025-08-27 15:19:40 +01001810 scripts/config.py unset PSA_WANT_ALG_CTR
1811 scripts/config.py unset PSA_WANT_ALG_CFB
1812 scripts/config.py unset PSA_WANT_ALG_OFB
1813 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
1814 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
1815 scripts/config.py unset PSA_WANT_ALG_CMAC
1816 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1817 scripts/config.py unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
Minos Galanakis471b34c2024-07-26 15:39:24 +01001818
1819 # Disable direct dependency on AES_C
1820 scripts/config.py unset MBEDTLS_NIST_KW_C
1821
1822 # Prevent the cipher module from using deprecated PSA path. The reason is
1823 # that otherwise there will be tests relying on "aes_info" (defined in
1824 # "cipher_wrap.c") whose functions are not available when AES_C is
1825 # not defined. ARIA and Camellia are not a problem in this case because
1826 # the PSA path is not tested for these key types.
1827 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1828}
1829
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02001830component_test_full_block_cipher_psa_dispatch_static_keystore () {
1831 msg "build: full + PSA dispatch in block_cipher with static keystore"
1832 # Check that the static key store works well when CTR_DRBG uses a
1833 # PSA key for AES.
1834 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
1835
1836 loc_accel_list="ALG_ECB_NO_PADDING \
1837 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1838
1839 # Configure
1840 # ---------
1841
1842 common_block_cipher_dispatch 1
1843
1844 # Build
1845 # -----
1846
1847 helper_libtestdriver1_make_drivers "$loc_accel_list"
1848
1849 helper_libtestdriver1_make_main "$loc_accel_list"
1850
1851 # Make sure disabled components were not re-enabled by accident (additive
1852 # config)
1853 not grep mbedtls_aes_ library/aes.o
1854 not grep mbedtls_aria_ library/aria.o
1855 not grep mbedtls_camellia_ library/camellia.o
1856
1857 # Run the tests
1858 # -------------
1859
1860 msg "test: full + PSA dispatch in block_cipher with static keystore"
1861 make test
1862}
1863
Minos Galanakis471b34c2024-07-26 15:39:24 +01001864component_test_full_block_cipher_psa_dispatch () {
1865 msg "build: full + PSA dispatch in block_cipher"
1866
1867 loc_accel_list="ALG_ECB_NO_PADDING \
1868 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1869
1870 # Configure
1871 # ---------
1872
1873 common_block_cipher_dispatch 1
1874
1875 # Build
1876 # -----
1877
1878 helper_libtestdriver1_make_drivers "$loc_accel_list"
1879
1880 helper_libtestdriver1_make_main "$loc_accel_list"
1881
1882 # Make sure disabled components were not re-enabled by accident (additive
1883 # config)
1884 not grep mbedtls_aes_ ${BUILTIN_SRC_PATH}/aes.o
1885 not grep mbedtls_aria_ ${BUILTIN_SRC_PATH}/aria.o
1886 not grep mbedtls_camellia_ ${BUILTIN_SRC_PATH}/camellia.o
1887
1888 # Run the tests
1889 # -------------
1890
1891 msg "test: full + PSA dispatch in block_cipher"
1892 make test
1893}
1894
1895# This is the reference component of component_test_full_block_cipher_psa_dispatch
Minos Galanakis471b34c2024-07-26 15:39:24 +01001896component_test_full_block_cipher_legacy_dispatch () {
1897 msg "build: full + legacy dispatch in block_cipher"
1898
1899 common_block_cipher_dispatch 0
1900
1901 make
1902
1903 msg "test: full + legacy dispatch in block_cipher"
1904 make test
1905}
1906
Minos Galanakisf78447f2024-07-26 20:49:51 +01001907component_test_aead_chachapoly_disabled () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001908 msg "build: full minus CHACHAPOLY"
1909 scripts/config.py full
David Horstmannb907dbc2025-08-27 15:19:40 +01001910 scripts/config.py unset PSA_WANT_ALG_CHACHA20_POLY1305
Minos Galanakis471b34c2024-07-26 15:39:24 +01001911 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1912
1913 msg "test: full minus CHACHAPOLY"
1914 make test
1915}
1916
Minos Galanakisf78447f2024-07-26 20:49:51 +01001917component_test_aead_only_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001918 msg "build: full minus CHACHAPOLY and GCM"
1919 scripts/config.py full
David Horstmannb907dbc2025-08-27 15:19:40 +01001920 scripts/config.py unset PSA_WANT_ALG_CHACHA20_POLY1305
1921 scripts/config.py unset PSA_WANT_ALG_GCM
Minos Galanakis471b34c2024-07-26 15:39:24 +01001922 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1923
1924 msg "test: full minus CHACHAPOLY and GCM"
1925 make test
1926}
1927
Minos Galanakisf78447f2024-07-26 20:49:51 +01001928component_test_ccm_aes_sha256 () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001929 msg "build: CCM + AES + SHA256 configuration"
1930
Minos Galanakisa17ffc72024-12-02 23:57:30 +00001931 # Setting a blank config disables everyhing in the library side.
1932 echo '#define MBEDTLS_CONFIG_H ' >"$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001933 cp tf-psa-crypto/configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
Ronald Cron9d262d72024-12-06 17:41:26 +01001934
Minos Galanakis471b34c2024-07-26 15:39:24 +01001935 make
Minos Galanakis471b34c2024-07-26 15:39:24 +01001936 msg "test: CCM + AES + SHA256 configuration"
1937 make test
1938}
1939
1940# Test that the given .o file builds with all (valid) combinations of the given options.
1941#
1942# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
1943#
1944# The validator function is the name of a function to validate the combination of options.
1945# It may be "" if all combinations are valid.
1946# It receives a string containing a combination of options, as passed to the compiler,
1947# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001948build_test_config_combos () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001949 file=$1
1950 shift
1951 validate_options=$1
1952 shift
1953 options=("$@")
1954
1955 # clear all of the options so that they can be overridden on the clang commandline
1956 for opt in "${options[@]}"; do
1957 ./scripts/config.py unset ${opt}
1958 done
1959
1960 # enter the library directory
1961 cd library
1962
1963 # The most common issue is unused variables/functions, so ensure -Wunused is set.
1964 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
1965
1966 # Extract the command generated by the Makefile to build the target file.
1967 # This ensures that we have any include paths, macro definitions, etc
1968 # that may be applied by make.
1969 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
1970 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
1971
1972 makefile=$(TMPDIR=. mktemp)
1973 deps=""
1974
1975 len=${#options[@]}
1976 source_file=../${file%.o}.c
1977
1978 targets=0
1979 echo 'include Makefile' >${makefile}
1980
1981 for ((i = 0; i < $((2**${len})); i++)); do
1982 # generate each of 2^n combinations of options
1983 # each bit of $i is used to determine if options[i] will be set or not
1984 target="t"
1985 clang_args=""
1986 for ((j = 0; j < ${len}; j++)); do
1987 if (((i >> j) & 1)); then
1988 opt=-D${options[$j]}
1989 clang_args="${clang_args} ${opt}"
1990 target="${target}${opt}"
1991 fi
1992 done
1993
1994 # if combination is not known to be invalid, add it to the makefile
1995 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
1996 cmd="${compile_cmd} ${clang_args}"
1997 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
1998
1999 deps="${deps} ${target}"
2000 ((++targets))
2001 fi
2002 done
2003
2004 echo "build_test_config_combos: ${deps}" >> ${makefile}
2005
2006 # execute all of the commands via Make (probably in parallel)
2007 make -s -f ${makefile} build_test_config_combos
2008 echo "$targets targets checked"
2009
2010 # clean up the temporary makefile
2011 rm ${makefile}
2012}
2013
Minos Galanakisf78447f2024-07-26 20:49:51 +01002014validate_aes_config_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002015 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
2016 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
2017 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
2018 return 1
2019 fi
2020 fi
2021 return 0
2022}
2023
Minos Galanakisf78447f2024-07-26 20:49:51 +01002024component_build_aes_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002025 # 18s - around 90ms per clang invocation on M1 Pro
2026 #
2027 # aes.o has many #if defined(...) guards that intersect in complex ways.
2028 # Test that all the combinations build cleanly.
2029
2030 MBEDTLS_ROOT_DIR="$PWD"
2031 msg "build: aes.o for all combinations of relevant config options"
2032
2033 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002034 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002035 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2036 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2037
2038 cd "$MBEDTLS_ROOT_DIR"
2039 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
2040
Ari Weiler-Ofek86422e52025-07-04 14:43:30 +01002041 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW,
Minos Galanakis471b34c2024-07-26 15:39:24 +01002042 # manually set or unset those configurations to check
2043 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
2044 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Minos Galanakis471b34c2024-07-26 15:39:24 +01002045 scripts/config.py unset MBEDTLS_NIST_KW_C
Ronald Cron54d1eec2024-09-06 09:55:38 +02002046
David Horstmann7cbeedc2025-08-26 17:26:45 +01002047 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
2048 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
2049 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
2050 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
Ronald Cron54d1eec2024-09-06 09:55:38 +02002051
Minos Galanakis471b34c2024-07-26 15:39:24 +01002052 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002053 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002054 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2055 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2056}
2057
Minos Galanakisf78447f2024-07-26 20:49:51 +01002058component_test_sha3_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002059 msg "sha3 loop unroll variations"
2060
2061 # define minimal config sufficient to test SHA3
Ronald Crone7f289e2024-09-06 11:02:47 +02002062 cat > include/mbedtls/mbedtls_config.h << END
Ronald Crone7f289e2024-09-06 11:02:47 +02002063END
2064
2065 cat > tf-psa-crypto/include/psa/crypto_config.h << END
2066 #define PSA_WANT_ALG_SHA_256 1
2067 #define PSA_WANT_ALG_SHA3_224 1
2068 #define PSA_WANT_ALG_SHA3_256 1
2069 #define PSA_WANT_ALG_SHA3_384 1
2070 #define PSA_WANT_ALG_SHA3_512 1
Ronald Cron06680362025-07-21 15:21:22 +02002071 #define PSA_WANT_KEY_TYPE_AES 1
Ronald Cron3dd1d3d2024-12-05 15:12:06 +01002072 #define MBEDTLS_PSA_CRYPTO_C
Ronald Cron3b306432025-09-02 18:30:08 +02002073 #define MBEDTLS_CTR_DRBG_C
2074 #define MBEDTLS_PSA_BUILTIN_GET_ENTROPY
Ronald Cron3dd1d3d2024-12-05 15:12:06 +01002075 #define MBEDTLS_SELF_TEST
Minos Galanakis471b34c2024-07-26 15:39:24 +01002076END
2077
2078 msg "all loops unrolled"
2079 make clean
2080 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"
2081 ./tf-psa-crypto/tests/test_suite_shax
2082
2083 msg "all loops rolled up"
2084 make clean
2085 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"
2086 ./tf-psa-crypto/tests/test_suite_shax
2087}
2088
Minos Galanakisf699d512024-08-01 11:32:30 +01002089support_build_aes_aesce_armcc () {
2090 support_build_armcc
2091}
2092
Minos Galanakis471b34c2024-07-26 15:39:24 +01002093# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2094component_build_aes_aesce_armcc () {
2095 msg "Build: AESCE test on arm64 platform without plain C."
2096 scripts/config.py baremetal
2097
2098 # armc[56] don't support SHA-512 intrinsics
2099 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2100
2101 # Stop armclang warning about feature detection for A64_CRYPTO.
2102 # With this enabled, the library does build correctly under armclang,
2103 # but in baremetal builds (as tested here), feature detection is
2104 # unavailable, and the user is notified via a #warning. So enabling
2105 # this feature would prevent us from building with -Werror on
2106 # armclang. Tracked in #7198.
2107 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2108 scripts/config.py set MBEDTLS_HAVE_ASM
2109
2110 msg "AESCE, build with default configuration."
2111 scripts/config.py set MBEDTLS_AESCE_C
2112 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002113 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002114
2115 msg "AESCE, build AESCE only"
2116 scripts/config.py set MBEDTLS_AESCE_C
2117 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002118 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002119}
2120
Minos Galanakis471b34c2024-07-26 15:39:24 +01002121component_test_aes_only_128_bit_keys () {
2122 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2123 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002124 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002125
2126 make CFLAGS='-O2 -Werror -Wall -Wextra'
2127
2128 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2129 make test
2130}
2131
2132component_test_no_ctr_drbg_aes_only_128_bit_keys () {
2133 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2134 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002135 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002136 scripts/config.py unset MBEDTLS_CTR_DRBG_C
2137
2138 make CC=clang CFLAGS='-Werror -Wall -Wextra'
2139
2140 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2141 make test
2142}
2143
2144component_test_aes_only_128_bit_keys_have_builtins () {
2145 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2146 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002147 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002148 scripts/config.py unset MBEDTLS_AESNI_C
2149 scripts/config.py unset MBEDTLS_AESCE_C
2150
2151 make CFLAGS='-O2 -Werror -Wall -Wextra'
2152
2153 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2154 make test
2155
2156 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2157 programs/test/selftest
2158}
2159
2160component_test_gcm_largetable () {
2161 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2162 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
2163 scripts/config.py unset MBEDTLS_AESNI_C
2164 scripts/config.py unset MBEDTLS_AESCE_C
2165
2166 make CFLAGS='-O2 -Werror -Wall -Wextra'
2167
2168 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2169 make test
2170}
2171
2172component_test_aes_fewer_tables () {
2173 msg "build: default config with AES_FEWER_TABLES enabled"
2174 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2175 make CFLAGS='-O2 -Werror -Wall -Wextra'
2176
2177 msg "test: AES_FEWER_TABLES"
2178 make test
2179}
2180
2181component_test_aes_rom_tables () {
2182 msg "build: default config with AES_ROM_TABLES enabled"
2183 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2184 make CFLAGS='-O2 -Werror -Wall -Wextra'
2185
2186 msg "test: AES_ROM_TABLES"
2187 make test
2188}
2189
2190component_test_aes_fewer_tables_and_rom_tables () {
2191 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
2192 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2193 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2194 make CFLAGS='-O2 -Werror -Wall -Wextra'
2195
2196 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2197 make test
2198}
2199
Ronald Cron66040472024-09-06 10:14:38 +02002200# helper for component_test_block_cipher_no_decrypt_aesni() which:
Minos Galanakis471b34c2024-07-26 15:39:24 +01002201# - enable/disable the list of config options passed from -s/-u respectively.
2202# - build
2203# - test for tests_suite_xxx
2204# - selftest
2205#
2206# Usage: helper_block_cipher_no_decrypt_build_test
2207# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
2208# Options: -s set_opts the list of config options to enable
2209# -u unset_opts the list of config options to disable
2210# -c cflags the list of options passed to CFLAGS
2211# -l ldflags the list of options passed to LDFLAGS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002212helper_block_cipher_no_decrypt_build_test () {
2213 while [ $# -gt 0 ]; do
2214 case "$1" in
2215 -s)
2216 shift; local set_opts="$1";;
2217 -u)
2218 shift; local unset_opts="$1";;
2219 -c)
2220 shift; local cflags="-Werror -Wall -Wextra $1";;
2221 -l)
2222 shift; local ldflags="$1";;
2223 esac
2224 shift
2225 done
2226 set_opts="${set_opts:-}"
2227 unset_opts="${unset_opts:-}"
2228 cflags="${cflags:-}"
2229 ldflags="${ldflags:-}"
2230
2231 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
2232 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
2233
2234 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2235 make clean
2236 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
2237
2238 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2239 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2240 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2241 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2242 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2243 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2244 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
2245 not grep mbedtls_aesni_inverse_key ${BUILTIN_SRC_PATH}/aesni.o
2246
2247 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2248 make test
2249
2250 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2251 programs/test/selftest
2252}
2253
Ronald Cron66040472024-09-06 10:14:38 +02002254# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
2255config_block_cipher_no_decrypt () {
2256 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Ronald Cron66040472024-09-06 10:14:38 +02002257 scripts/config.py unset MBEDTLS_NIST_KW_C
2258
2259 # Enable support for cryptographic mechanisms through the PSA API.
2260 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
David Horstmannb907dbc2025-08-27 15:19:40 +01002261 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
2262 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
2263 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
2264 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
Ronald Cron66040472024-09-06 10:14:38 +02002265}
2266
2267component_test_block_cipher_no_decrypt_aesni () {
2268 # Test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics, AESNI assembly and
2269 # AES C implementation on x86_64 and with AESNI intrinsics on x86.
2270
2271 # This consistently causes an llvm crash on clang 3.8, so use gcc
2272 export CC=gcc
2273 config_block_cipher_no_decrypt
2274
Minos Galanakis471b34c2024-07-26 15:39:24 +01002275 # test AESNI intrinsics
2276 helper_block_cipher_no_decrypt_build_test \
2277 -s "MBEDTLS_AESNI_C" \
2278 -c "-mpclmul -msse2 -maes"
2279
2280 # test AESNI assembly
2281 helper_block_cipher_no_decrypt_build_test \
2282 -s "MBEDTLS_AESNI_C" \
2283 -c "-mno-pclmul -mno-sse2 -mno-aes"
2284
2285 # test AES C implementation
2286 helper_block_cipher_no_decrypt_build_test \
2287 -u "MBEDTLS_AESNI_C"
2288
2289 # test AESNI intrinsics for i386 target
2290 helper_block_cipher_no_decrypt_build_test \
2291 -s "MBEDTLS_AESNI_C" \
2292 -c "-m32 -mpclmul -msse2 -maes" \
2293 -l "-m32"
2294}
2295
Minos Galanakisf699d512024-08-01 11:32:30 +01002296support_test_block_cipher_no_decrypt_aesce_armcc () {
2297 support_build_armcc
2298}
2299
Minos Galanakis471b34c2024-07-26 15:39:24 +01002300component_test_block_cipher_no_decrypt_aesce_armcc () {
2301 scripts/config.py baremetal
2302
2303 # armc[56] don't support SHA-512 intrinsics
2304 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2305
2306 # Stop armclang warning about feature detection for A64_CRYPTO.
2307 # With this enabled, the library does build correctly under armclang,
2308 # but in baremetal builds (as tested here), feature detection is
2309 # unavailable, and the user is notified via a #warning. So enabling
2310 # this feature would prevent us from building with -Werror on
2311 # armclang. Tracked in #7198.
2312 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2313 scripts/config.py set MBEDTLS_HAVE_ASM
2314
Ronald Cron66040472024-09-06 10:14:38 +02002315 config_block_cipher_no_decrypt
Minos Galanakis471b34c2024-07-26 15:39:24 +01002316
2317 # test AESCE baremetal build
2318 scripts/config.py set MBEDTLS_AESCE_C
2319 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002320 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002321
2322 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2323 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2324 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2325 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2326 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2327 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2328 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
2329 not grep mbedtls_aesce_inverse_key ${BUILTIN_SRC_PATH}/aesce.o
2330 not grep aesce_decrypt_block ${BUILTIN_SRC_PATH}/aesce.o
2331}
2332
Ronald Cronaad5f1b2025-08-25 15:32:48 +02002333component_test_ctr_drbg_aes_256_sha_512 () {
2334 msg "build: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512 (ASan build)"
2335 scripts/config.py full
2336 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2337 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512
2338 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2339 make
2340
2341 msg "test: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512 (ASan build)"
2342 make test
2343}
2344
Minos Galanakis471b34c2024-07-26 15:39:24 +01002345component_test_ctr_drbg_aes_256_sha_256 () {
Minos Galanakisf3486e12025-08-18 14:09:26 +01002346 msg "build: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002347 scripts/config.py full
2348 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakisf3486e12025-08-18 14:09:26 +01002349 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256
Minos Galanakis471b34c2024-07-26 15:39:24 +01002350 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2351 make
2352
Minos Galanakisf3486e12025-08-18 14:09:26 +01002353 msg "test: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002354 make test
2355}
2356
2357component_test_ctr_drbg_aes_128_sha_512 () {
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002358 msg "build: full + set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002359 scripts/config.py full
2360 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002361 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Ronald Cronaad5f1b2025-08-25 15:32:48 +02002362 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512
Minos Galanakis471b34c2024-07-26 15:39:24 +01002363 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2364 make
2365
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002366 msg "test: full + set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002367 make test
2368}
2369
2370component_test_ctr_drbg_aes_128_sha_256 () {
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002371 msg "build: full + set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128 + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002372 scripts/config.py full
2373 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002374 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakisf3486e12025-08-18 14:09:26 +01002375 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256
Minos Galanakis471b34c2024-07-26 15:39:24 +01002376 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2377 make
2378
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002379 msg "test: full + set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128 + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002380 make test
2381}
2382
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002383component_test_full_static_keystore () {
2384 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2385 scripts/config.py full
2386 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2387 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
2388
2389 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2390 make test
2391}
2392
Minos Galanakis471b34c2024-07-26 15:39:24 +01002393component_test_psa_crypto_drivers () {
Ronald Crona0afbfb2024-10-15 13:20:31 +02002394 # Test dispatch to drivers and fallbacks with
2395 # test_suite_psa_crypto_driver_wrappers test suite. The test drivers that
2396 # are wrappers around the builtin drivers are activated by
2397 # PSA_CRYPTO_DRIVER_TEST.
2398 #
2399 # For the time being, some test cases in test_suite_block_cipher and
2400 # test_suite_md.psa rely on this component to be run at least once by the
2401 # CI. This should disappear as we progress the 4.x work. See
2402 # config_adjust_test_accelerators.h for more information.
Minos Galanakis471b34c2024-07-26 15:39:24 +01002403 msg "build: full + test drivers dispatching to builtins"
2404 scripts/config.py full
Ronald Cron67cc6a72024-10-14 10:55:24 +02002405 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_CONFIG_ADJUST_TEST_ACCELERATORS"
David Horstmann5b93d972024-10-31 15:36:05 +00002406 loc_cflags="${loc_cflags} -I../framework/tests/include"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002407
2408 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
2409
2410 msg "test: full + test drivers dispatching to builtins"
2411 make test
2412}
2413
2414component_build_psa_config_file () {
Minos Galanakis4f619e12024-11-14 14:56:47 +00002415 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002416 cp "$CRYPTO_CONFIG_H" psa_test_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002417 echo '#error "TF_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
2418 make CFLAGS="-I '$PWD' -DTF_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002419 # Make sure this feature is enabled. We'll disable it in the next phase.
Ronald Cron3f120062025-07-03 14:45:51 +02002420 programs/test/query_compile_time_config PSA_WANT_ALG_CMAC
Minos Galanakis471b34c2024-07-26 15:39:24 +01002421 make clean
2422
Minos Galanakis4f619e12024-11-14 14:56:47 +00002423 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE + TF_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002424 # In the user config, disable one feature and its dependencies, which will
2425 # reflect on the mbedtls configuration so we can query it with
2426 # query_compile_time_config.
2427 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
2428 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002429 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 +02002430 not programs/test/query_compile_time_config PSA_WANT_ALG_CMAC
Minos Galanakis471b34c2024-07-26 15:39:24 +01002431
2432 rm -f psa_test_config.h psa_user_config.h
2433}
2434
2435component_build_psa_alt_headers () {
2436 msg "build: make with PSA alt headers" # ~20s
2437
2438 # Generate alternative versions of the substitutable headers with the
2439 # same content except different include guards.
David Horstmanndc459512024-11-07 17:08:11 +00002440 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 +01002441
2442 # Build the library and some programs.
2443 # Don't build the fuzzers to avoid having to go through hoops to set
2444 # a correct include path for programs/fuzz/Makefile.
David Horstmann5b93d972024-10-31 15:36:05 +00002445 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
2446 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 +01002447
2448 # Check that we're getting the alternative include guards and not the
2449 # original include guards.
2450 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
2451 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
2452 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
2453 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
2454}
2455
2456component_test_min_mpi_window_size () {
2457 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
2458 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
2459 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2460 make
2461
2462 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2463 make test
2464}
Ronald Cronf256f8a2025-07-10 17:37:18 +02002465
2466component_test_xts () {
2467 # Component dedicated to run XTS unit test cases while XTS is not
2468 # supported through the PSA API.
2469 msg "build: Default + MBEDTLS_CIPHER_MODE_XTS"
2470
2471 echo "#define MBEDTLS_CIPHER_MODE_XTS" > psa_user_config.h
2472 cmake -DTF_PSA_CRYPTO_USER_CONFIG_FILE="psa_user_config.h"
2473 make
2474
Ronald Crone0b06eb2025-07-15 08:58:32 +02002475 rm -f psa_user_config.h
2476
Ronald Cronf256f8a2025-07-10 17:37:18 +02002477 msg "test: Default + MBEDTLS_CIPHER_MODE_XTS"
2478 make test
Ronald Cronf256f8a2025-07-10 17:37:18 +02002479}