blob: d5efbffde8d81ec82ec3fceef1ff23069426fff7 [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 () {
254 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
255 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
258 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
259
260 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
261 make test
262
263 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
264 tests/ssl-opt.sh -f 'Default\|opaque'
265}
266
Minos Galanakisf78447f2024-07-26 20:49:51 +0100267component_full_no_pkparse_pkwrite () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100268 msg "build: full without pkparse and pkwrite"
269
270 scripts/config.py crypto_full
271 scripts/config.py unset MBEDTLS_PK_PARSE_C
272 scripts/config.py unset MBEDTLS_PK_WRITE_C
273
274 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
275
276 # Ensure that PK_[PARSE|WRITE]_C were not re-enabled accidentally (additive config).
277 not grep mbedtls_pk_parse_key ${BUILTIN_SRC_PATH}/pkparse.o
278 not grep mbedtls_pk_write_key_der ${BUILTIN_SRC_PATH}/pkwrite.o
279
280 msg "test: full without pkparse and pkwrite"
281 make test
282}
283
284component_test_crypto_full_md_light_only () {
285 msg "build: crypto_full with only the light subset of MD"
286 scripts/config.py crypto_full
287
288 # Disable MD
289 scripts/config.py unset MBEDTLS_MD_C
290 # Disable direct dependencies of MD_C
291 scripts/config.py unset MBEDTLS_HKDF_C
292 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
293 scripts/config.py unset MBEDTLS_PKCS7_C
294 # Disable indirect dependencies of MD_C
David Horstmann7cbeedc2025-08-26 17:26:45 +0100295 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
Minos Galanakis471b34c2024-07-26 15:39:24 +0100296 # Disable things that would auto-enable MD_C
297 scripts/config.py unset MBEDTLS_PKCS5_C
298
299 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
300 # which we haven't disabled, so no need to explicitly enable it.
301 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
302
303 # Make sure we don't have the HMAC functions, but the hashing functions
304 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
305 grep mbedtls_md ${BUILTIN_SRC_PATH}/md.o
306
307 msg "test: crypto_full with only the light subset of MD"
308 make test
309}
310
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100311component_test_full_no_cipher () {
312 msg "build: full no CIPHER"
313
314 scripts/config.py full
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100315
316 # The built-in implementation of the following algs/key-types depends
317 # on CIPHER_C so we disable them.
318 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
319 # so we keep them enabled.
David Horstmann7cbeedc2025-08-26 17:26:45 +0100320 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
321 scripts/config.py unset PSA_WANT_ALG_CMAC
322 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
323 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
324 scripts/config.py unset PSA_WANT_ALG_CFB
325 scripts/config.py unset PSA_WANT_ALG_CTR
326 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
327 scripts/config.py unset PSA_WANT_ALG_OFB
328 scripts/config.py unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
329 scripts/config.py unset PSA_WANT_ALG_STREAM_CIPHER
330 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100331
332 # The following modules directly depends on CIPHER_C
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100333 scripts/config.py unset MBEDTLS_NIST_KW_C
334
335 make
336
337 # Ensure that CIPHER_C was not re-enabled
338 not grep mbedtls_cipher_init ${BUILTIN_SRC_PATH}/cipher.o
339
340 msg "test: full no CIPHER"
341 make test
342}
343
Minos Galanakisf78447f2024-07-26 20:49:51 +0100344component_test_full_no_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100345 msg "build: full no PSA_WANT_ALG_CCM"
346
347 # Full config enables:
348 # - USE_PSA_CRYPTO so that TLS code dispatches cipher/AEAD to PSA
349 # - CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
350 scripts/config.py full
351
352 # Disable PSA_WANT_ALG_CCM so that CCM is not supported in PSA. CCM_C is still
353 # enabled, but not used from TLS since USE_PSA is set.
354 # This is helpful to ensure that TLS tests below have proper dependencies.
355 #
356 # Note: also PSA_WANT_ALG_CCM_STAR_NO_TAG is enabled, but it does not cause
357 # PSA_WANT_ALG_CCM to be re-enabled.
David Horstmannb907dbc2025-08-27 15:19:40 +0100358 scripts/config.py unset PSA_WANT_ALG_CCM
Minos Galanakis471b34c2024-07-26 15:39:24 +0100359
360 make
361
362 msg "test: full no PSA_WANT_ALG_CCM"
363 make test
364}
365
Minos Galanakisf78447f2024-07-26 20:49:51 +0100366component_test_full_no_ccm_star_no_tag () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100367 msg "build: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
368
369 # Full config enables CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
370 scripts/config.py full
371
372 # Disable CCM_STAR_NO_TAG, which is the target of this test, as well as all
373 # other components that enable MBEDTLS_PSA_BUILTIN_CIPHER internal symbol.
374 # This basically disables all unauthenticated ciphers on the PSA side, while
375 # keeping AEADs enabled.
376 #
377 # Note: PSA_WANT_ALG_CCM is enabled, but it does not cause
378 # PSA_WANT_ALG_CCM_STAR_NO_TAG to be re-enabled.
David Horstmannb907dbc2025-08-27 15:19:40 +0100379 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
380 scripts/config.py unset PSA_WANT_ALG_STREAM_CIPHER
381 scripts/config.py unset PSA_WANT_ALG_CTR
382 scripts/config.py unset PSA_WANT_ALG_CFB
383 scripts/config.py unset PSA_WANT_ALG_OFB
384 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
Ben Taylor1948c942025-03-04 09:11:11 +0000385 # NOTE unsettting PSA_WANT_ALG_ECB_NO_PADDING without unsetting NIST_KW_C will
386 # mean PSA_WANT_ALG_ECB_NO_PADDING is re-enabled, so disabling it also.
David Horstmannb907dbc2025-08-27 15:19:40 +0100387 scripts/config.py unset MBEDTLS_NIST_KW_C
388 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
389 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
Minos Galanakis471b34c2024-07-26 15:39:24 +0100390
391 make
392
393 # Ensure MBEDTLS_PSA_BUILTIN_CIPHER was not enabled
394 not grep mbedtls_psa_cipher ${PSA_CORE_PATH}/psa_crypto_cipher.o
395
396 msg "test: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
397 make test
398}
399
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200400component_test_config_symmetric_only () {
401 msg "build: configs/config-symmetric-only.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +0000402 MBEDTLS_CONFIG="configs/config-symmetric-only.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +0000403 CRYPTO_CONFIG="tf-psa-crypto/configs/crypto-config-symmetric-only.h"
Ronald Cronfaadfc22024-12-07 17:24:28 +0100404 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 +0200405 make
406
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200407 msg "test: configs/config-symmetric-only.h - unit tests"
Gilles Peskineaf5a8992024-09-14 11:27:44 +0200408 make test
409}
410
Minos Galanakisc06fd302024-08-01 12:16:59 +0100411component_test_everest () {
412 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
413 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
414 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
415 make
416
417 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
418 make test
419
420 msg "test: metatests (clang, ASan)"
421 tests/scripts/run-metatests.sh any asan poison
422
423 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
424 tests/ssl-opt.sh -f ECDH
425
426 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
427 # Exclude some symmetric ciphers that are redundant here to gain time.
428 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
429}
430
431component_test_everest_curve25519_only () {
432 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
Minos Galanakisc06fd302024-08-01 12:16:59 +0100433 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
434 scripts/config.py unset MBEDTLS_ECDSA_C
David Horstmann7cbeedc2025-08-26 17:26:45 +0100435 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
436 scripts/config.py unset PSA_WANT_ALG_ECDSA
437 scripts/config.py set PSA_WANT_ALG_ECDH
Minos Galanakisc06fd302024-08-01 12:16:59 +0100438 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
439 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
440 scripts/config.py unset MBEDTLS_ECJPAKE_C
David Horstmann7cbeedc2025-08-26 17:26:45 +0100441 scripts/config.py unset PSA_WANT_ALG_JPAKE
Minos Galanakisc06fd302024-08-01 12:16:59 +0100442
443 # Disable all curves
444 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
David Horstmann7cbeedc2025-08-26 17:26:45 +0100445 scripts/config.py unset-all "PSA_WANT_ECC_[0-9A-Z_a-z]*$"
446 scripts/config.py set PSA_WANT_ECC_MONTGOMERY_255
Minos Galanakisc06fd302024-08-01 12:16:59 +0100447
448 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
449
450 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
451 make test
452}
453
Minos Galanakis471b34c2024-07-26 15:39:24 +0100454component_test_psa_collect_statuses () {
455 msg "build+test: psa_collect_statuses" # ~30s
456 scripts/config.py full
457 tests/scripts/psa_collect_statuses.py
458 # Check that psa_crypto_init() succeeded at least once
459 grep -q '^0:psa_crypto_init:' tests/statuses.log
460 rm -f tests/statuses.log
461}
462
463# Check that the specified libraries exist and are empty.
464are_empty_libraries () {
465 nm "$@" >/dev/null 2>/dev/null
466 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
467}
468
Minos Galanakis471b34c2024-07-26 15:39:24 +0100469component_test_crypto_for_psa_service () {
470 msg "build: make, config for PSA crypto service"
471 scripts/config.py crypto
472 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
473 # Disable things that are not needed for just cryptography, to
474 # reach a configuration that would be typical for a PSA cryptography
475 # service providing all implemented PSA algorithms.
476 # System stuff
477 scripts/config.py unset MBEDTLS_ERROR_C
478 scripts/config.py unset MBEDTLS_TIMING_C
479 scripts/config.py unset MBEDTLS_VERSION_FEATURES
480 # Crypto stuff with no PSA interface
481 scripts/config.py unset MBEDTLS_BASE64_C
Minos Galanakis471b34c2024-07-26 15:39:24 +0100482 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
483 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
484 scripts/config.py unset MBEDTLS_NIST_KW_C
485 scripts/config.py unset MBEDTLS_PEM_PARSE_C
486 scripts/config.py unset MBEDTLS_PEM_WRITE_C
487 scripts/config.py unset MBEDTLS_PKCS12_C
488 scripts/config.py unset MBEDTLS_PKCS5_C
489 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
490 # in PSA code to work with RSA keys. We don't require users to set those:
491 # they will be reenabled in build_info.h.
492 scripts/config.py unset MBEDTLS_PK_C
493 scripts/config.py unset MBEDTLS_PK_PARSE_C
494 scripts/config.py unset MBEDTLS_PK_WRITE_C
495 make CFLAGS='-O1 -Werror' all test
496 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
497}
498
499component_build_crypto_baremetal () {
500 msg "build: make, crypto only, baremetal config"
501 scripts/config.py crypto_baremetal
David Horstmann5b93d972024-10-31 15:36:05 +0000502 make CFLAGS="-O1 -Werror -I$PWD/framework/tests/include/baremetal-override/"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100503 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
504}
505
506support_build_crypto_baremetal () {
507 support_build_baremetal "$@"
508}
509
510# depends.py family of tests
511component_test_depends_py_cipher_id () {
512 msg "test/build: depends.py cipher_id (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200513 tests/scripts/depends.py cipher_id
Minos Galanakis471b34c2024-07-26 15:39:24 +0100514}
515
516component_test_depends_py_cipher_chaining () {
517 msg "test/build: depends.py cipher_chaining (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200518 tests/scripts/depends.py cipher_chaining
Minos Galanakis471b34c2024-07-26 15:39:24 +0100519}
520
Minos Galanakis471b34c2024-07-26 15:39:24 +0100521component_test_depends_py_curves () {
522 msg "test/build: depends.py curves (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200523 tests/scripts/depends.py curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100524}
525
526component_test_depends_py_hashes () {
527 msg "test/build: depends.py hashes (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200528 tests/scripts/depends.py hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +0100529}
530
Minos Galanakis471b34c2024-07-26 15:39:24 +0100531component_test_depends_py_pkalgs () {
532 msg "test/build: depends.py pkalgs (gcc)"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100533 tests/scripts/depends.py pkalgs
534}
535
536component_test_psa_crypto_config_ffdh_2048_only () {
537 msg "build: full config - only DH 2048"
538
539 scripts/config.py full
540
541 # Disable all DH groups other than 2048.
David Horstmannb907dbc2025-08-27 15:19:40 +0100542 scripts/config.py unset PSA_WANT_DH_RFC7919_3072
543 scripts/config.py unset PSA_WANT_DH_RFC7919_4096
544 scripts/config.py unset PSA_WANT_DH_RFC7919_6144
545 scripts/config.py unset PSA_WANT_DH_RFC7919_8192
Minos Galanakis471b34c2024-07-26 15:39:24 +0100546
547 make CFLAGS="$ASAN_CFLAGS -Werror" LDFLAGS="$ASAN_CFLAGS"
548
549 msg "test: full config - only DH 2048"
550 make test
551
552 msg "ssl-opt: full config - only DH 2048"
553 tests/ssl-opt.sh -f "ffdh"
554}
555
Minos Galanakis471b34c2024-07-26 15:39:24 +0100556component_test_psa_crypto_config_accel_ecdsa () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200557 msg "build: accelerated ECDSA"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100558
Minos Galanakis471b34c2024-07-26 15:39:24 +0100559 # Configure
560 # ---------
561
Elena Uziunaite91d83862024-09-04 14:51:31 +0100562 # Start from default config + TLS 1.3
Minos Galanakis471b34c2024-07-26 15:39:24 +0100563 helper_libtestdriver1_adjust_config "default"
564
Valerio Setti37a42812025-08-11 12:52:49 +0200565 # Algorithms and key types to accelerate
566 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
567 $(helper_get_psa_key_type_list "ECC") \
568 $(helper_get_psa_curve_list)"
569
Minos Galanakis471b34c2024-07-26 15:39:24 +0100570 # Disable the module that's accelerated
571 scripts/config.py unset MBEDTLS_ECDSA_C
572
573 # Disable things that depend on it
574 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
575 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
576
577 # Build
578 # -----
579
580 # These hashes are needed for some ECDSA signature tests.
Elena Uziunaiteffce45c2024-09-12 14:58:52 +0100581 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 +0100582 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
583
584 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
585
586 helper_libtestdriver1_make_main "$loc_accel_list"
587
588 # Make sure this was not re-enabled by accident (additive config)
589 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
590
591 # Run the tests
592 # -------------
593
Ronald Cron93ba6252024-09-05 10:37:14 +0200594 msg "test: accelerated ECDSA"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100595 make test
596}
597
598component_test_psa_crypto_config_accel_ecdh () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200599 msg "build: accelerated ECDH"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100600
Minos Galanakis471b34c2024-07-26 15:39:24 +0100601 # Configure
602 # ---------
603
604 # Start from default config (no USE_PSA)
605 helper_libtestdriver1_adjust_config "default"
606
Valerio Setti37a42812025-08-11 12:52:49 +0200607 # Algorithms and key types to accelerate
608 loc_accel_list="ALG_ECDH \
609 $(helper_get_psa_key_type_list "ECC") \
610 $(helper_get_psa_curve_list)"
611
Minos Galanakis471b34c2024-07-26 15:39:24 +0100612 # Disable the module that's accelerated
613 scripts/config.py unset MBEDTLS_ECDH_C
614
615 # Disable things that depend on it
616 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
617 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
618 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
619 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
620 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
621
622 # Build
623 # -----
624
625 helper_libtestdriver1_make_drivers "$loc_accel_list"
626
627 helper_libtestdriver1_make_main "$loc_accel_list"
628
629 # Make sure this was not re-enabled by accident (additive config)
630 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
631
632 # Run the tests
633 # -------------
634
Ronald Cron93ba6252024-09-05 10:37:14 +0200635 msg "test: accelerated ECDH"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100636 make test
637}
638
639component_test_psa_crypto_config_accel_ffdh () {
640 msg "build: full with accelerated FFDH"
641
Minos Galanakis471b34c2024-07-26 15:39:24 +0100642 # Configure
643 # ---------
644
645 # start with full (USE_PSA and TLS 1.3)
646 helper_libtestdriver1_adjust_config "full"
647
Valerio Setti37a42812025-08-11 12:52:49 +0200648 # Algorithms and key types to accelerate
649 loc_accel_list="ALG_FFDH \
650 $(helper_get_psa_key_type_list "DH") \
651 $(helper_get_psa_dh_group_list)"
652
Minos Galanakis471b34c2024-07-26 15:39:24 +0100653 # Build
654 # -----
655
656 helper_libtestdriver1_make_drivers "$loc_accel_list"
657
658 helper_libtestdriver1_make_main "$loc_accel_list"
659
660 # Make sure this was not re-enabled by accident (additive config)
Valerio Settieb63eb22025-02-12 13:32:49 +0100661 not grep mbedtls_psa_ffdh_key_agreement ${BUILTIN_SRC_PATH}/psa_crypto_ffdh.o
Minos Galanakis471b34c2024-07-26 15:39:24 +0100662
663 # Run the tests
664 # -------------
665
666 msg "test: full with accelerated FFDH"
667 make test
668
669 msg "ssl-opt: full with accelerated FFDH alg"
670 tests/ssl-opt.sh -f "ffdh"
671}
672
673component_test_psa_crypto_config_reference_ffdh () {
674 msg "build: full with non-accelerated FFDH"
675
676 # Start with full (USE_PSA and TLS 1.3)
677 helper_libtestdriver1_adjust_config "full"
678
Minos Galanakis471b34c2024-07-26 15:39:24 +0100679 make
680
681 msg "test suites: full with non-accelerated FFDH alg"
682 make test
683
684 msg "ssl-opt: full with non-accelerated FFDH alg"
685 tests/ssl-opt.sh -f "ffdh"
686}
687
Minos Galanakisf78447f2024-07-26 20:49:51 +0100688component_test_psa_crypto_config_accel_pake () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100689 msg "build: full with accelerated PAKE"
690
Minos Galanakis471b34c2024-07-26 15:39:24 +0100691 # Configure
692 # ---------
693
694 helper_libtestdriver1_adjust_config "full"
695
Valerio Setti37a42812025-08-11 12:52:49 +0200696 loc_accel_list="ALG_JPAKE \
697 $(helper_get_psa_key_type_list "ECC") \
698 $(helper_get_psa_curve_list)"
699
Minos Galanakis471b34c2024-07-26 15:39:24 +0100700 # Make built-in fallback not available
701 scripts/config.py unset MBEDTLS_ECJPAKE_C
702 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
703
704 # Build
705 # -----
706
707 helper_libtestdriver1_make_drivers "$loc_accel_list"
708
709 helper_libtestdriver1_make_main "$loc_accel_list"
710
711 # Make sure this was not re-enabled by accident (additive config)
712 not grep mbedtls_ecjpake_init ${BUILTIN_SRC_PATH}/ecjpake.o
713
714 # Run the tests
715 # -------------
716
717 msg "test: full with accelerated PAKE"
718 make test
719}
720
721component_test_psa_crypto_config_accel_ecc_some_key_types () {
722 msg "build: full with accelerated EC algs and some key types"
723
Valerio Setti37a42812025-08-11 12:52:49 +0200724 # Configure
725 # ---------
726
727 # start with config full for maximum coverage (also enables USE_PSA)
728 helper_libtestdriver1_adjust_config "full"
729
Minos Galanakis471b34c2024-07-26 15:39:24 +0100730 # Algorithms and key types to accelerate
731 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
732 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
733 ALG_ECDH \
734 ALG_JPAKE \
735 KEY_TYPE_ECC_PUBLIC_KEY \
736 KEY_TYPE_ECC_KEY_PAIR_BASIC \
737 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
738 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
739 $(helper_get_psa_curve_list)"
740
Minos Galanakis471b34c2024-07-26 15:39:24 +0100741 # Disable modules that are accelerated - some will be re-enabled
742 scripts/config.py unset MBEDTLS_ECDSA_C
743 scripts/config.py unset MBEDTLS_ECDH_C
744 scripts/config.py unset MBEDTLS_ECJPAKE_C
745 scripts/config.py unset MBEDTLS_ECP_C
746
747 # Disable all curves - those that aren't accelerated should be re-enabled
748 helper_disable_builtin_curves
749
750 # Restartable feature is not yet supported by PSA. Once it will in
751 # the future, the following line could be removed (see issues
752 # 6061, 6332 and following ones)
753 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
754
755 # this is not supported by the driver API yet
David Horstmannb907dbc2025-08-27 15:19:40 +0100756 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +0100757
758 # Build
759 # -----
760
761 # These hashes are needed for some ECDSA signature tests.
762 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
763 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
764 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
765
766 helper_libtestdriver1_make_main "$loc_accel_list"
767
768 # ECP should be re-enabled but not the others
769 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
770 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
771 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
772 grep mbedtls_ecp ${BUILTIN_SRC_PATH}/ecp.o
773
774 # Run the tests
775 # -------------
776
777 msg "test suites: full with accelerated EC algs and some key types"
778 make test
779}
780
781# Run tests with only (non-)Weierstrass accelerated
782# Common code used in:
783# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
784# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100785common_test_psa_crypto_config_accel_ecc_some_curves () {
786 weierstrass=$1
787 if [ $weierstrass -eq 1 ]; then
788 desc="Weierstrass"
789 else
790 desc="non-Weierstrass"
791 fi
792
793 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
794
Valerio Setti37a42812025-08-11 12:52:49 +0200795 # Configure
796 # ---------
797
798 # Start with config crypto_full and remove PK_C:
799 # that's what's supported now, see docs/driver-only-builds.md.
800 helper_libtestdriver1_adjust_config "crypto_full"
801 scripts/config.py unset MBEDTLS_PK_C
802 scripts/config.py unset MBEDTLS_PK_PARSE_C
803 scripts/config.py unset MBEDTLS_PK_WRITE_C
804
805 # Disable modules that are accelerated - some will be re-enabled
806 scripts/config.py unset MBEDTLS_ECDSA_C
807 scripts/config.py unset MBEDTLS_ECDH_C
808 scripts/config.py unset MBEDTLS_ECJPAKE_C
809 scripts/config.py unset MBEDTLS_ECP_C
810
811 # Disable all curves - those that aren't accelerated should be re-enabled
812 helper_disable_builtin_curves
813
Valerio Setti981a0c42025-08-12 11:31:11 +0200814 # Note: Curves are handled in a special way by the libtestdriver machinery,
Minos Galanakis471b34c2024-07-26 15:39:24 +0100815 # so we only want to include them in the accel list when building the main
816 # libraries, hence the use of a separate variable.
817 # Note: the following loop is a modified version of
818 # helper_get_psa_curve_list that only keeps Weierstrass families.
819 loc_weierstrass_list=""
820 loc_non_weierstrass_list=""
821 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
822 case $item in
823 ECC_BRAINPOOL*|ECC_SECP*)
824 loc_weierstrass_list="$loc_weierstrass_list $item"
825 ;;
826 *)
827 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
828 ;;
829 esac
830 done
831 if [ $weierstrass -eq 1 ]; then
832 loc_curve_list=$loc_weierstrass_list
833 else
834 loc_curve_list=$loc_non_weierstrass_list
835 fi
836
837 # Algorithms and key types to accelerate
838 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
839 ALG_ECDH \
840 ALG_JPAKE \
841 $(helper_get_psa_key_type_list "ECC") \
842 $loc_curve_list"
843
Minos Galanakis471b34c2024-07-26 15:39:24 +0100844 # Restartable feature is not yet supported by PSA. Once it will in
845 # the future, the following line could be removed (see issues
846 # 6061, 6332 and following ones)
847 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
848
849 # this is not supported by the driver API yet
David Horstmannb907dbc2025-08-27 15:19:40 +0100850 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +0100851
852 # Build
853 # -----
854
855 # These hashes are needed for some ECDSA signature tests.
856 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
857 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
858 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
859
860 helper_libtestdriver1_make_main "$loc_accel_list"
861
862 # We expect ECDH to be re-enabled for the missing curves
863 grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
864 # We expect ECP to be re-enabled, however the parts specific to the
865 # families of curves that are accelerated should be ommited.
866 # - functions with mxz in the name are specific to Montgomery curves
867 # - ecp_muladd is specific to Weierstrass curves
868 ##nm ${BUILTIN_SRC_PATH}/ecp.o | tee ecp.syms
869 if [ $weierstrass -eq 1 ]; then
870 not grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
871 grep mxz ${BUILTIN_SRC_PATH}/ecp.o
872 else
873 grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
874 not grep mxz ${BUILTIN_SRC_PATH}/ecp.o
875 fi
876 # We expect ECDSA and ECJPAKE to be re-enabled only when
877 # Weierstrass curves are not accelerated
878 if [ $weierstrass -eq 1 ]; then
879 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
880 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
881 else
882 grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
883 grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
884 fi
885
886 # Run the tests
887 # -------------
888
889 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
Valerio Setti981a0c42025-08-12 11:31:11 +0200890 make test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100891}
892
893component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
894 common_test_psa_crypto_config_accel_ecc_some_curves 1
895}
896
897component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
898 common_test_psa_crypto_config_accel_ecc_some_curves 0
899}
900
901# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
902# ECDH, ECDSA) with and without drivers.
903# The input parameter is a boolean value which indicates:
904# - 0 keep built-in EC algs,
905# - 1 exclude built-in EC algs (driver only).
906#
907# This is used by the two following components to ensure they always use the
908# same config, except for the use of driver or built-in EC algorithms:
909# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
910# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
911# This supports comparing their test coverage with analyze_outcomes.py.
Minos Galanakis471b34c2024-07-26 15:39:24 +0100912config_psa_crypto_config_ecp_light_only () {
913 driver_only="$1"
914 # start with config full for maximum coverage (also enables USE_PSA)
915 helper_libtestdriver1_adjust_config "full"
916 if [ "$driver_only" -eq 1 ]; then
917 # Disable modules that are accelerated
918 scripts/config.py unset MBEDTLS_ECDSA_C
919 scripts/config.py unset MBEDTLS_ECDH_C
920 scripts/config.py unset MBEDTLS_ECJPAKE_C
921 scripts/config.py unset MBEDTLS_ECP_C
922 fi
923
924 # Restartable feature is not yet supported by PSA. Once it will in
925 # the future, the following line could be removed (see issues
926 # 6061, 6332 and following ones)
927 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
928}
929
930# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100931component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
932 msg "build: full with accelerated EC algs"
933
Valerio Setti37a42812025-08-11 12:52:49 +0200934 # Configure
935 # ---------
936
937 # Use the same config as reference, only without built-in EC algs
938 config_psa_crypto_config_ecp_light_only 1
939
Minos Galanakis471b34c2024-07-26 15:39:24 +0100940 # Algorithms and key types to accelerate
941 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
942 ALG_ECDH \
943 ALG_JPAKE \
944 $(helper_get_psa_key_type_list "ECC") \
945 $(helper_get_psa_curve_list)"
946
Minos Galanakis471b34c2024-07-26 15:39:24 +0100947 # Do not disable builtin curves because that support is required for:
948 # - MBEDTLS_PK_PARSE_EC_EXTENDED
949 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
950
951 # Build
952 # -----
953
954 # These hashes are needed for some ECDSA signature tests.
955 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
956 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
957 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
958
959 helper_libtestdriver1_make_main "$loc_accel_list"
960
961 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
962 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
963 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
964 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
965 not grep mbedtls_ecp_mul ${BUILTIN_SRC_PATH}/ecp.o
966
967 # Run the tests
968 # -------------
969
970 msg "test suites: full with accelerated EC algs"
971 make test
972
973 msg "ssl-opt: full with accelerated EC algs"
974 tests/ssl-opt.sh
975}
976
977# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100978component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200979 msg "build: non-accelerated EC algs"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100980
981 config_psa_crypto_config_ecp_light_only 0
982
983 make
984
985 msg "test suites: full with non-accelerated EC algs"
986 make test
987
988 msg "ssl-opt: full with non-accelerated EC algs"
989 tests/ssl-opt.sh
990}
991
992# This helper function is used by:
993# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
994# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
995# to ensure that both tests use the same underlying configuration when testing
996# driver's coverage with analyze_outcomes.py.
997#
998# This functions accepts 1 boolean parameter as follows:
999# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
1000# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
1001# - 0: include built-in implementation of EC algorithms.
1002#
1003# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
1004# on the ECP module.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001005config_psa_crypto_no_ecp_at_all () {
1006 driver_only="$1"
1007 # start with full config for maximum coverage (also enables USE_PSA)
1008 helper_libtestdriver1_adjust_config "full"
1009
1010 if [ "$driver_only" -eq 1 ]; then
1011 # Disable modules that are accelerated
1012 scripts/config.py unset MBEDTLS_ECDSA_C
1013 scripts/config.py unset MBEDTLS_ECDH_C
1014 scripts/config.py unset MBEDTLS_ECJPAKE_C
1015 # Disable ECP module (entirely)
1016 scripts/config.py unset MBEDTLS_ECP_C
1017 fi
1018
1019 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1020 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1021 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
David Horstmannb907dbc2025-08-27 15:19:40 +01001022 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +01001023
1024 # Restartable feature is not yet supported by PSA. Once it will in
1025 # the future, the following line could be removed (see issues
1026 # 6061, 6332 and following ones)
1027 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1028}
1029
1030# Build and test a configuration where driver accelerates all EC algs while
1031# all support and dependencies from ECP and ECP_LIGHT are removed on the library
1032# side.
1033#
1034# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001035component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
1036 msg "build: full + accelerated EC algs - ECP"
1037
Minos Galanakis471b34c2024-07-26 15:39:24 +01001038 # Configure
1039 # ---------
1040
1041 # Set common configurations between library's and driver's builds
1042 config_psa_crypto_no_ecp_at_all 1
1043 # Disable all the builtin curves. All the required algs are accelerated.
1044 helper_disable_builtin_curves
1045
Valerio Setti37a42812025-08-11 12:52:49 +02001046 # Algorithms and key types to accelerate
1047 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1048 ALG_ECDH \
1049 ALG_JPAKE \
1050 $(helper_get_psa_key_type_list "ECC") \
1051 $(helper_get_psa_curve_list)"
1052
Minos Galanakis471b34c2024-07-26 15:39:24 +01001053 # Build
1054 # -----
1055
1056 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1057 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1058 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1059 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1060
1061 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1062
1063 helper_libtestdriver1_make_main "$loc_accel_list"
1064
1065 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1066 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1067 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1068 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1069 # Also ensure that ECP module was not re-enabled
1070 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1071
1072 # Run the tests
1073 # -------------
1074
1075 msg "test: full + accelerated EC algs - ECP"
1076 make test
1077
1078 msg "ssl-opt: full + accelerated EC algs - ECP"
1079 tests/ssl-opt.sh
1080}
1081
1082# Reference function used for driver's coverage analysis in analyze_outcomes.py
1083# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
1084# Keep in sync with its accelerated counterpart.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001085component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
1086 msg "build: full + non accelerated EC algs"
1087
1088 config_psa_crypto_no_ecp_at_all 0
1089
1090 make
1091
1092 msg "test: full + non accelerated EC algs"
1093 make test
1094
1095 msg "ssl-opt: full + non accelerated EC algs"
1096 tests/ssl-opt.sh
1097}
1098
1099# This is a common configuration helper used directly from:
1100# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1101# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1102# and indirectly from:
1103# - component_test_psa_crypto_config_accel_ecc_no_bignum
1104# - accelerate all EC algs, disable RSA and FFDH
1105# - component_test_psa_crypto_config_reference_ecc_no_bignum
1106# - this is the reference component of the above
1107# - it still disables RSA and FFDH, but it uses builtin EC algs
1108# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1109# - accelerate all EC and FFDH algs, disable only RSA
1110# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1111# - this is the reference component of the above
1112# - it still disables RSA, but it uses builtin EC and FFDH algs
1113#
1114# This function accepts 2 parameters:
1115# $1: a boolean value which states if we are testing an accelerated scenario
1116# or not.
1117# $2: a string value which states which components are tested. Allowed values
1118# are "ECC" or "ECC_DH".
Minos Galanakisf78447f2024-07-26 20:49:51 +01001119config_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001120 driver_only="$1"
1121 test_target="$2"
1122 # start with full config for maximum coverage (also enables USE_PSA)
1123 helper_libtestdriver1_adjust_config "full"
1124
1125 if [ "$driver_only" -eq 1 ]; then
1126 # Disable modules that are accelerated
1127 scripts/config.py unset MBEDTLS_ECDSA_C
1128 scripts/config.py unset MBEDTLS_ECDH_C
1129 scripts/config.py unset MBEDTLS_ECJPAKE_C
1130 # Disable ECP module (entirely)
1131 scripts/config.py unset MBEDTLS_ECP_C
1132 # Also disable bignum
1133 scripts/config.py unset MBEDTLS_BIGNUM_C
1134 fi
1135
1136 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1137 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1138 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
David Horstmannb907dbc2025-08-27 15:19:40 +01001139 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +01001140
1141 # RSA support is intentionally disabled on this test because RSA_C depends
1142 # on BIGNUM_C.
David Horstmannb907dbc2025-08-27 15:19:40 +01001143 scripts/config.py unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
1144 scripts/config.py unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001145 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1146 # Also disable key exchanges that depend on RSA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001147 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1148 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1149
1150 if [ "$test_target" = "ECC" ]; then
1151 # When testing ECC only, we disable FFDH support, both from builtin and
Valerio Setti8438c632025-01-22 11:56:40 +01001152 # PSA sides.
David Horstmannb907dbc2025-08-27 15:19:40 +01001153 scripts/config.py unset PSA_WANT_ALG_FFDH
1154 scripts/config.py unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
1155 scripts/config.py unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001156 fi
1157
1158 # Restartable feature is not yet supported by PSA. Once it will in
1159 # the future, the following line could be removed (see issues
1160 # 6061, 6332 and following ones)
1161 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1162}
1163
1164# Common helper used by:
1165# - component_test_psa_crypto_config_accel_ecc_no_bignum
1166# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1167#
1168# The goal is to build and test accelerating either:
1169# - ECC only or
1170# - both ECC and FFDH
1171#
1172# It is meant to be used in conjunction with
1173# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
1174# coverage analysis in the "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001175common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1176 test_target="$1"
1177
1178 # This is an internal helper to simplify text message handling
1179 if [ "$test_target" = "ECC_DH" ]; then
1180 accel_text="ECC/FFDH"
1181 removed_text="ECP - DH"
1182 else
1183 accel_text="ECC"
1184 removed_text="ECP"
1185 fi
1186
1187 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1188
Valerio Setti37a42812025-08-11 12:52:49 +02001189 # Configure
1190 # ---------
1191
1192 # Set common configurations between library's and driver's builds
1193 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
1194 # Disable all the builtin curves. All the required algs are accelerated.
1195 helper_disable_builtin_curves
1196
Minos Galanakis471b34c2024-07-26 15:39:24 +01001197 # By default we accelerate all EC keys/algs
1198 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1199 ALG_ECDH \
1200 ALG_JPAKE \
1201 $(helper_get_psa_key_type_list "ECC") \
1202 $(helper_get_psa_curve_list)"
1203 # Optionally we can also add DH to the list of accelerated items
1204 if [ "$test_target" = "ECC_DH" ]; then
1205 loc_accel_list="$loc_accel_list \
1206 ALG_FFDH \
1207 $(helper_get_psa_key_type_list "DH") \
1208 $(helper_get_psa_dh_group_list)"
1209 fi
1210
Minos Galanakis471b34c2024-07-26 15:39:24 +01001211 # Build
1212 # -----
1213
1214 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1215 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1216 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1217 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1218
1219 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1220
1221 helper_libtestdriver1_make_main "$loc_accel_list"
1222
1223 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1224 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1225 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1226 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001227 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001228 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1229 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1230 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001231
1232 # Run the tests
1233 # -------------
1234
Valerio Settieb63eb22025-02-12 13:32:49 +01001235 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001236
1237 make test
1238
1239 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1240 tests/ssl-opt.sh
1241}
1242
1243# Common helper used by:
1244# - component_test_psa_crypto_config_reference_ecc_no_bignum
1245# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1246#
1247# The goal is to build and test a reference scenario (i.e. with builtin
1248# components) compared to the ones used in
1249# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
1250#
1251# It is meant to be used in conjunction with
1252# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
1253# coverage analysis in "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001254common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1255 test_target="$1"
1256
1257 # This is an internal helper to simplify text message handling
1258 if [ "$test_target" = "ECC_DH" ]; then
1259 accel_text="ECC/FFDH"
1260 else
1261 accel_text="ECC"
1262 fi
1263
1264 msg "build: full + non accelerated $accel_text algs + USE_PSA"
1265
1266 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
1267
1268 make
1269
1270 msg "test suites: full + non accelerated EC algs + USE_PSA"
1271 make test
1272
1273 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
1274 tests/ssl-opt.sh
1275}
1276
1277component_test_psa_crypto_config_accel_ecc_no_bignum () {
1278 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
1279}
1280
1281component_test_psa_crypto_config_reference_ecc_no_bignum () {
1282 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
1283}
1284
1285component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1286 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
1287}
1288
1289component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1290 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
1291}
1292
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001293component_test_tfm_config_as_is () {
1294 msg "build: configs/config-tfm.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +00001295 MBEDTLS_CONFIG="configs/config-tfm.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001296 CRYPTO_CONFIG="tf-psa-crypto/configs/ext/crypto_config_profile_medium.h"
Minos Galanakis4f619e12024-11-14 14:56:47 +00001297 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 +02001298 make
1299
1300 msg "test: configs/config-tfm.h - unit tests"
1301 make test
1302}
1303
Minos Galanakis471b34c2024-07-26 15:39:24 +01001304# Helper for setting common configurations between:
1305# - component_test_tfm_config_p256m_driver_accel_ec()
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001306# - component_test_tfm_config_no_p256m()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001307common_tfm_config () {
1308 # Enable TF-M config
1309 cp configs/config-tfm.h "$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001310 cp tf-psa-crypto/configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001311
Minos Galanakis471b34c2024-07-26 15:39:24 +01001312 # Config adjustment for better test coverage in our environment.
1313 # This is not needed just to build and pass tests.
1314 #
1315 # Enable filesystem I/O for the benefit of PK parse/write tests.
Minos Galanakis5da58e52024-11-07 15:35:33 +00001316 sed -i '/PROFILE_M_PSA_CRYPTO_CONFIG_H/i #define MBEDTLS_FS_IO' "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001317}
1318
1319# Keep this in sync with component_test_tfm_config() as they are both meant
1320# to be used in analyze_outcomes.py for driver's coverage analysis.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001321component_test_tfm_config_p256m_driver_accel_ec () {
1322 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1323
1324 common_tfm_config
1325
1326 # Build crypto library
David Horstmann5b93d972024-10-31 15:36:05 +00001327 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../framework/tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001328
1329 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1330 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1331 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1332 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001333 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001334 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1335 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001336 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1337 # Check that p256m was built
1338 grep -q p256_ecdsa_ library/libmbedcrypto.a
1339
1340 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1341 # files, so we want to ensure that it has not be re-enabled accidentally.
1342 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1343
1344 # Run the tests
1345 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1346 make test
1347}
1348
1349# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1350# they are both meant to be used in analyze_outcomes.py for driver's coverage
1351# analysis.
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001352component_test_tfm_config_no_p256m () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001353 common_tfm_config
1354
1355 # Disable P256M driver, which is on by default, so that analyze_outcomes
1356 # can compare this test with test_tfm_config_p256m_driver_accel_ec
Minos Galanakis5da58e52024-11-07 15:35:33 +00001357 sed -i '/PROFILE_M_PSA_CRYPTO_CONFIG_H/i #undef MBEDTLS_PSA_P256M_DRIVER_ENABLED' "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001358
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001359 msg "build: TF-M config without p256m"
David Horstmann5b93d972024-10-31 15:36:05 +00001360 make CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' tests
Minos Galanakis471b34c2024-07-26 15:39:24 +01001361
1362 # Check that p256m was not built
1363 not grep p256_ecdsa_ library/libmbedcrypto.a
1364
1365 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1366 # files, so we want to ensure that it has not be re-enabled accidentally.
1367 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1368
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001369 msg "test: TF-M config without p256m"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001370 make test
1371}
1372
Minos Galanakis471b34c2024-07-26 15:39:24 +01001373# This is an helper used by:
1374# - component_test_psa_ecc_key_pair_no_derive
1375# - component_test_psa_ecc_key_pair_no_generate
1376# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1377# enabled, but one. Input arguments are as follows:
Gilles Peskinefef912c2024-09-20 16:07:09 +02001378# - $1 is the configuration to start from
1379# - $2 is the key type under test, i.e. ECC/RSA/DH
1380# - $3 is the key option to be unset (i.e. generate, derive, etc)
Minos Galanakisf78447f2024-07-26 20:49:51 +01001381build_and_test_psa_want_key_pair_partial () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001382 base_config=$1
1383 key_type=$2
1384 unset_option=$3
Minos Galanakis471b34c2024-07-26 15:39:24 +01001385 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1386
Gilles Peskinefef912c2024-09-20 16:07:09 +02001387 msg "build: $base_config - ${disabled_psa_want}"
1388 scripts/config.py "$base_config"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001389
1390 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1391 # crypto_config.h so we just disable the one we don't want.
David Horstmannb907dbc2025-08-27 15:19:40 +01001392 scripts/config.py unset "$disabled_psa_want"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001393
1394 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1395
Gilles Peskinefef912c2024-09-20 16:07:09 +02001396 msg "test: $base_config - ${disabled_psa_want}"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001397 make test
1398}
1399
Minos Galanakisf78447f2024-07-26 20:49:51 +01001400component_test_psa_ecc_key_pair_no_derive () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001401 build_and_test_psa_want_key_pair_partial full "ECC" "DERIVE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001402}
1403
Minos Galanakisf78447f2024-07-26 20:49:51 +01001404component_test_psa_ecc_key_pair_no_generate () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001405 # TLS needs ECC key generation whenever ephemeral ECDH is enabled.
1406 # We don't have proper guards for configurations with ECC key generation
1407 # disabled (https://github.com/Mbed-TLS/mbedtls/issues/9481). Until
1408 # then (if ever), just test the crypto part of the library.
1409 build_and_test_psa_want_key_pair_partial crypto_full "ECC" "GENERATE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001410}
1411
1412config_psa_crypto_accel_rsa () {
1413 driver_only=$1
1414
1415 # Start from crypto_full config (no X.509, no TLS)
1416 helper_libtestdriver1_adjust_config "crypto_full"
1417
1418 if [ "$driver_only" -eq 1 ]; then
Minos Galanakis471b34c2024-07-26 15:39:24 +01001419 # We need PEM parsing in the test library as well to support the import
1420 # of PEM encoded RSA keys.
Minos Galanakis23452f52024-11-28 17:48:14 +00001421 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1422 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
Minos Galanakis471b34c2024-07-26 15:39:24 +01001423 fi
1424}
1425
1426component_test_psa_crypto_config_accel_rsa_crypto () {
1427 msg "build: crypto_full with accelerated RSA"
1428
1429 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1430 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1431 KEY_TYPE_RSA_PUBLIC_KEY \
1432 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1433 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1434 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1435 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1436
1437 # Configure
1438 # ---------
1439
1440 config_psa_crypto_accel_rsa 1
1441
1442 # Build
1443 # -----
1444
1445 # These hashes are needed for unit tests.
1446 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1447 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1448 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1449
1450 helper_libtestdriver1_make_main "$loc_accel_list"
1451
1452 # Make sure this was not re-enabled by accident (additive config)
1453 not grep mbedtls_rsa ${BUILTIN_SRC_PATH}/rsa.o
1454
1455 # Run the tests
1456 # -------------
1457
1458 msg "test: crypto_full with accelerated RSA"
1459 make test
1460}
1461
1462component_test_psa_crypto_config_reference_rsa_crypto () {
1463 msg "build: crypto_full with non-accelerated RSA"
1464
1465 # Configure
1466 # ---------
1467 config_psa_crypto_accel_rsa 0
1468
1469 # Build
1470 # -----
1471 make
1472
1473 # Run the tests
1474 # -------------
1475 msg "test: crypto_full with non-accelerated RSA"
1476 make test
1477}
1478
1479# This is a temporary test to verify that full RSA support is present even when
1480# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001481component_test_new_psa_want_key_pair_symbol () {
Ronald Cron892bb612025-07-21 14:26:27 +02001482 msg "Build: crypto config - PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001483
1484 # Create a temporary output file unless there is already one set
1485 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1486 REMOVE_OUTCOME_ON_EXIT="no"
1487 else
1488 REMOVE_OUTCOME_ON_EXIT="yes"
1489 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1490 export MBEDTLS_TEST_OUTCOME_FILE
1491 fi
1492
1493 # Start from crypto configuration
1494 scripts/config.py crypto
1495
1496 # Remove RSA support and its dependencies
Minos Galanakis471b34c2024-07-26 15:39:24 +01001497 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1498 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001499 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1500
Minos Galanakis471b34c2024-07-26 15:39:24 +01001501 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
1502 # that proper translations is done in crypto_legacy.h.
David Horstmannb907dbc2025-08-27 15:19:40 +01001503 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
1504 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
1505 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Minos Galanakis471b34c2024-07-26 15:39:24 +01001506
1507 make
1508
Ronald Cron892bb612025-07-21 14:26:27 +02001509 msg "Test: crypto config - PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001510 make test
1511
1512 # Parse only 1 relevant line from the outcome file, i.e. a test which is
1513 # performing RSA signature.
1514 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
1515 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
1516
1517 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
1518 rm $MBEDTLS_TEST_OUTCOME_FILE
1519 fi
1520}
1521
1522component_test_psa_crypto_config_accel_hash () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001523 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001524
1525 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1526 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1527 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1528
1529 # Configure
1530 # ---------
1531
1532 # Start from default config (no USE_PSA)
1533 helper_libtestdriver1_adjust_config "default"
1534
Minos Galanakis471b34c2024-07-26 15:39:24 +01001535 # Build
1536 # -----
1537
1538 helper_libtestdriver1_make_drivers "$loc_accel_list"
1539
1540 helper_libtestdriver1_make_main "$loc_accel_list"
1541
1542 # There's a risk of something getting re-enabled via config_psa.h;
1543 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1544 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1545 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1546 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1547 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1548 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1549
1550 # Run the tests
1551 # -------------
1552
Ronald Cron93ba6252024-09-05 10:37:14 +02001553 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001554 make test
1555}
1556
1557# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001558config_psa_crypto_hash_use_psa () {
1559 driver_only="$1"
1560 # start with config full for maximum coverage (also enables USE_PSA)
1561 helper_libtestdriver1_adjust_config "full"
1562 if [ "$driver_only" -eq 1 ]; then
1563 # disable the built-in implementation of hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +01001564 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Minos Galanakis471b34c2024-07-26 15:39:24 +01001565 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Minos Galanakis471b34c2024-07-26 15:39:24 +01001566 fi
1567}
1568
1569# Note that component_test_psa_crypto_config_reference_hash_use_psa
1570# is related to this component and both components need to be kept in sync.
1571# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001572component_test_psa_crypto_config_accel_hash_use_psa () {
1573 msg "test: full with accelerated hashes"
1574
1575 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1576 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1577 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1578
1579 # Configure
1580 # ---------
1581
1582 config_psa_crypto_hash_use_psa 1
1583
1584 # Build
1585 # -----
1586
1587 helper_libtestdriver1_make_drivers "$loc_accel_list"
1588
1589 helper_libtestdriver1_make_main "$loc_accel_list"
1590
1591 # There's a risk of something getting re-enabled via config_psa.h;
1592 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1593 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1594 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1595 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1596 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1597 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1598
1599 # Run the tests
1600 # -------------
1601
1602 msg "test: full with accelerated hashes"
1603 make test
1604
1605 # This is mostly useful so that we can later compare outcome files with
1606 # the reference config in analyze_outcomes.py, to check that the
1607 # dependency declarations in ssl-opt.sh and in TLS code are correct.
1608 msg "test: ssl-opt.sh, full with accelerated hashes"
1609 tests/ssl-opt.sh
1610
1611 # This is to make sure all ciphersuites are exercised, but we don't need
1612 # interop testing (besides, we already got some from ssl-opt.sh).
1613 msg "test: compat.sh, full with accelerated hashes"
1614 tests/compat.sh -p mbedTLS -V YES
1615}
1616
1617# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
1618# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
1619# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
1620# Both components need to be kept in sync.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001621component_test_psa_crypto_config_reference_hash_use_psa () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001622 msg "test: full without accelerated hashes"
1623
1624 config_psa_crypto_hash_use_psa 0
1625
1626 make
1627
1628 msg "test: full without accelerated hashes"
1629 make test
1630
1631 msg "test: ssl-opt.sh, full without accelerated hashes"
1632 tests/ssl-opt.sh
1633}
1634
1635# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001636config_psa_crypto_hmac_use_psa () {
1637 driver_only="$1"
1638 # start with config full for maximum coverage (also enables USE_PSA)
1639 helper_libtestdriver1_adjust_config "full"
1640
1641 if [ "$driver_only" -eq 1 ]; then
1642 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
1643 # is still enabled though (for ENTROPY_C among others).
1644 scripts/config.py unset MBEDTLS_MD_C
Ronald Cron772a8ad2025-07-21 12:36:29 +02001645 # Also disable the configuration options that tune the builtin hashes,
1646 # since those hashes are disabled.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001647 scripts/config.py unset-all MBEDTLS_SHA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001648 fi
1649
1650 # Direct dependencies of MD_C. We disable them also in the reference
1651 # component to work with the same set of features.
1652 scripts/config.py unset MBEDTLS_PKCS7_C
1653 scripts/config.py unset MBEDTLS_PKCS5_C
1654 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1655 scripts/config.py unset MBEDTLS_HKDF_C
1656 # Dependencies of HMAC_DRBG
David Horstmannb907dbc2025-08-27 15:19:40 +01001657 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001658}
1659
Minos Galanakisf78447f2024-07-26 20:49:51 +01001660component_test_psa_crypto_config_accel_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001661 msg "test: full with accelerated hmac"
1662
1663 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
1664 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1665 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1666 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1667
1668 # Configure
1669 # ---------
1670
1671 config_psa_crypto_hmac_use_psa 1
1672
1673 # Build
1674 # -----
1675
1676 helper_libtestdriver1_make_drivers "$loc_accel_list"
1677
1678 helper_libtestdriver1_make_main "$loc_accel_list"
1679
1680 # Ensure that built-in support for HMAC is disabled.
1681 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
1682
1683 # Run the tests
1684 # -------------
1685
1686 msg "test: full with accelerated hmac"
1687 make test
1688}
1689
Minos Galanakisf78447f2024-07-26 20:49:51 +01001690component_test_psa_crypto_config_reference_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001691 msg "test: full without accelerated hmac"
1692
1693 config_psa_crypto_hmac_use_psa 0
1694
1695 make
1696
1697 msg "test: full without accelerated hmac"
1698 make test
1699}
1700
Minos Galanakis471b34c2024-07-26 15:39:24 +01001701component_test_psa_crypto_config_accel_aead () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001702 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001703
1704 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
1705 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1706
1707 # Configure
1708 # ---------
1709
1710 # Start from full config
1711 helper_libtestdriver1_adjust_config "full"
1712
Minos Galanakis471b34c2024-07-26 15:39:24 +01001713 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
David Horstmannb907dbc2025-08-27 15:19:40 +01001714 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
Minos Galanakis471b34c2024-07-26 15:39:24 +01001715
1716 # Build
1717 # -----
1718
1719 helper_libtestdriver1_make_drivers "$loc_accel_list"
1720
1721 helper_libtestdriver1_make_main "$loc_accel_list"
1722
1723 # Make sure this was not re-enabled by accident (additive config)
1724 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1725 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1726 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1727
1728 # Run the tests
1729 # -------------
1730
Ronald Cron93ba6252024-09-05 10:37:14 +02001731 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001732 make test
1733}
1734
1735# This is a common configuration function used in:
1736# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1737# - component_test_psa_crypto_config_reference_cipher_aead_cmac
Minos Galanakisf78447f2024-07-26 20:49:51 +01001738common_psa_crypto_config_accel_cipher_aead_cmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001739 # Start from the full config
1740 helper_libtestdriver1_adjust_config "full"
1741
1742 scripts/config.py unset MBEDTLS_NIST_KW_C
1743}
1744
1745# The 2 following test components, i.e.
1746# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1747# - component_test_psa_crypto_config_reference_cipher_aead_cmac
1748# are meant to be used together in analyze_outcomes.py script in order to test
1749# driver's coverage for ciphers and AEADs.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001750component_test_psa_crypto_config_accel_cipher_aead_cmac () {
1751 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
1752
1753 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
1754 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
1755 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
Ari Weiler-Ofek86422e52025-07-04 14:43:30 +01001756 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001757
1758 # Configure
1759 # ---------
1760
1761 common_psa_crypto_config_accel_cipher_aead_cmac
1762
Ari Weiler-Ofek5d8d2992025-07-07 23:20:29 +01001763 # Disable DES, if it still exists.
1764 # This can be removed once we remove DES from the library.
1765 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
1766
Minos Galanakis471b34c2024-07-26 15:39:24 +01001767 # Build
1768 # -----
1769
1770 helper_libtestdriver1_make_drivers "$loc_accel_list"
1771
1772 helper_libtestdriver1_make_main "$loc_accel_list"
1773
1774 # Make sure this was not re-enabled by accident (additive config)
1775 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001776 not grep mbedtls_aes ${BUILTIN_SRC_PATH}/aes.o
1777 not grep mbedtls_aria ${BUILTIN_SRC_PATH}/aria.o
1778 not grep mbedtls_camellia ${BUILTIN_SRC_PATH}/camellia.o
1779 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1780 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1781 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1782 not grep mbedtls_cmac ${BUILTIN_SRC_PATH}/cmac.o
Ronald Cronb5c6fcc2025-07-10 13:40:00 +02001783 not grep mbedtls_poly1305 ${BUILTIN_SRC_PATH}/poly1305.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001784
1785 # Run the tests
1786 # -------------
1787
1788 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
1789 make test
1790
1791 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
Ronald Cronbd28acf2025-07-10 09:53:50 +02001792 # Exclude password-protected key tests — they require built-in CBC and AES.
1793 tests/ssl-opt.sh -e "TLS: password protected"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001794
1795 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
1796 tests/compat.sh -V NO -p mbedTLS
1797}
1798
1799component_test_psa_crypto_config_reference_cipher_aead_cmac () {
1800 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
1801 common_psa_crypto_config_accel_cipher_aead_cmac
1802
Ari Weiler-Ofek5d8d2992025-07-07 23:20:29 +01001803 # Disable DES, if it still exists.
1804 # This can be removed once we remove DES from the library.
1805 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
1806
Minos Galanakis471b34c2024-07-26 15:39:24 +01001807 make
1808
1809 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
1810 make test
1811
1812 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
Ronald Cronbd28acf2025-07-10 09:53:50 +02001813 # Exclude password-protected key tests as in test_psa_crypto_config_accel_cipher_aead_cmac.
1814 tests/ssl-opt.sh -e "TLS: password protected"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001815
1816 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
1817 tests/compat.sh -V NO -p mbedTLS
1818}
1819
Minos Galanakisf78447f2024-07-26 20:49:51 +01001820common_block_cipher_dispatch () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001821 TEST_WITH_DRIVER="$1"
1822
1823 # Start from the full config
1824 helper_libtestdriver1_adjust_config "full"
1825
Minos Galanakis471b34c2024-07-26 15:39:24 +01001826 # Disable cipher's modes that, when not accelerated, cause
1827 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
1828 # Keep this also in the reference component in order to skip the same tests
1829 # that were skipped in the accelerated one.
David Horstmannb907dbc2025-08-27 15:19:40 +01001830 scripts/config.py unset PSA_WANT_ALG_CTR
1831 scripts/config.py unset PSA_WANT_ALG_CFB
1832 scripts/config.py unset PSA_WANT_ALG_OFB
1833 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
1834 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
1835 scripts/config.py unset PSA_WANT_ALG_CMAC
1836 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1837 scripts/config.py unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
Minos Galanakis471b34c2024-07-26 15:39:24 +01001838
1839 # Disable direct dependency on AES_C
1840 scripts/config.py unset MBEDTLS_NIST_KW_C
1841
1842 # Prevent the cipher module from using deprecated PSA path. The reason is
1843 # that otherwise there will be tests relying on "aes_info" (defined in
1844 # "cipher_wrap.c") whose functions are not available when AES_C is
1845 # not defined. ARIA and Camellia are not a problem in this case because
1846 # the PSA path is not tested for these key types.
1847 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1848}
1849
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02001850component_test_full_block_cipher_psa_dispatch_static_keystore () {
1851 msg "build: full + PSA dispatch in block_cipher with static keystore"
1852 # Check that the static key store works well when CTR_DRBG uses a
1853 # PSA key for AES.
1854 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
1855
1856 loc_accel_list="ALG_ECB_NO_PADDING \
1857 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1858
1859 # Configure
1860 # ---------
1861
1862 common_block_cipher_dispatch 1
1863
1864 # Build
1865 # -----
1866
1867 helper_libtestdriver1_make_drivers "$loc_accel_list"
1868
1869 helper_libtestdriver1_make_main "$loc_accel_list"
1870
1871 # Make sure disabled components were not re-enabled by accident (additive
1872 # config)
1873 not grep mbedtls_aes_ library/aes.o
1874 not grep mbedtls_aria_ library/aria.o
1875 not grep mbedtls_camellia_ library/camellia.o
1876
1877 # Run the tests
1878 # -------------
1879
1880 msg "test: full + PSA dispatch in block_cipher with static keystore"
1881 make test
1882}
1883
Minos Galanakis471b34c2024-07-26 15:39:24 +01001884component_test_full_block_cipher_psa_dispatch () {
1885 msg "build: full + PSA dispatch in block_cipher"
1886
1887 loc_accel_list="ALG_ECB_NO_PADDING \
1888 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1889
1890 # Configure
1891 # ---------
1892
1893 common_block_cipher_dispatch 1
1894
1895 # Build
1896 # -----
1897
1898 helper_libtestdriver1_make_drivers "$loc_accel_list"
1899
1900 helper_libtestdriver1_make_main "$loc_accel_list"
1901
1902 # Make sure disabled components were not re-enabled by accident (additive
1903 # config)
1904 not grep mbedtls_aes_ ${BUILTIN_SRC_PATH}/aes.o
1905 not grep mbedtls_aria_ ${BUILTIN_SRC_PATH}/aria.o
1906 not grep mbedtls_camellia_ ${BUILTIN_SRC_PATH}/camellia.o
1907
1908 # Run the tests
1909 # -------------
1910
1911 msg "test: full + PSA dispatch in block_cipher"
1912 make test
1913}
1914
1915# This is the reference component of component_test_full_block_cipher_psa_dispatch
Minos Galanakis471b34c2024-07-26 15:39:24 +01001916component_test_full_block_cipher_legacy_dispatch () {
1917 msg "build: full + legacy dispatch in block_cipher"
1918
1919 common_block_cipher_dispatch 0
1920
1921 make
1922
1923 msg "test: full + legacy dispatch in block_cipher"
1924 make test
1925}
1926
Minos Galanakisf78447f2024-07-26 20:49:51 +01001927component_test_aead_chachapoly_disabled () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001928 msg "build: full minus CHACHAPOLY"
1929 scripts/config.py full
David Horstmannb907dbc2025-08-27 15:19:40 +01001930 scripts/config.py unset PSA_WANT_ALG_CHACHA20_POLY1305
Minos Galanakis471b34c2024-07-26 15:39:24 +01001931 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1932
1933 msg "test: full minus CHACHAPOLY"
1934 make test
1935}
1936
Minos Galanakisf78447f2024-07-26 20:49:51 +01001937component_test_aead_only_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001938 msg "build: full minus CHACHAPOLY and GCM"
1939 scripts/config.py full
David Horstmannb907dbc2025-08-27 15:19:40 +01001940 scripts/config.py unset PSA_WANT_ALG_CHACHA20_POLY1305
1941 scripts/config.py unset PSA_WANT_ALG_GCM
Minos Galanakis471b34c2024-07-26 15:39:24 +01001942 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1943
1944 msg "test: full minus CHACHAPOLY and GCM"
1945 make test
1946}
1947
Minos Galanakisf78447f2024-07-26 20:49:51 +01001948component_test_ccm_aes_sha256 () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001949 msg "build: CCM + AES + SHA256 configuration"
1950
Minos Galanakisa17ffc72024-12-02 23:57:30 +00001951 # Setting a blank config disables everyhing in the library side.
1952 echo '#define MBEDTLS_CONFIG_H ' >"$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001953 cp tf-psa-crypto/configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
Ronald Cron9d262d72024-12-06 17:41:26 +01001954
Minos Galanakis471b34c2024-07-26 15:39:24 +01001955 make
Minos Galanakis471b34c2024-07-26 15:39:24 +01001956 msg "test: CCM + AES + SHA256 configuration"
1957 make test
1958}
1959
1960# Test that the given .o file builds with all (valid) combinations of the given options.
1961#
1962# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
1963#
1964# The validator function is the name of a function to validate the combination of options.
1965# It may be "" if all combinations are valid.
1966# It receives a string containing a combination of options, as passed to the compiler,
1967# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001968build_test_config_combos () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001969 file=$1
1970 shift
1971 validate_options=$1
1972 shift
1973 options=("$@")
1974
1975 # clear all of the options so that they can be overridden on the clang commandline
1976 for opt in "${options[@]}"; do
1977 ./scripts/config.py unset ${opt}
1978 done
1979
1980 # enter the library directory
1981 cd library
1982
1983 # The most common issue is unused variables/functions, so ensure -Wunused is set.
1984 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
1985
1986 # Extract the command generated by the Makefile to build the target file.
1987 # This ensures that we have any include paths, macro definitions, etc
1988 # that may be applied by make.
1989 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
1990 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
1991
1992 makefile=$(TMPDIR=. mktemp)
1993 deps=""
1994
1995 len=${#options[@]}
1996 source_file=../${file%.o}.c
1997
1998 targets=0
1999 echo 'include Makefile' >${makefile}
2000
2001 for ((i = 0; i < $((2**${len})); i++)); do
2002 # generate each of 2^n combinations of options
2003 # each bit of $i is used to determine if options[i] will be set or not
2004 target="t"
2005 clang_args=""
2006 for ((j = 0; j < ${len}; j++)); do
2007 if (((i >> j) & 1)); then
2008 opt=-D${options[$j]}
2009 clang_args="${clang_args} ${opt}"
2010 target="${target}${opt}"
2011 fi
2012 done
2013
2014 # if combination is not known to be invalid, add it to the makefile
2015 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
2016 cmd="${compile_cmd} ${clang_args}"
2017 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
2018
2019 deps="${deps} ${target}"
2020 ((++targets))
2021 fi
2022 done
2023
2024 echo "build_test_config_combos: ${deps}" >> ${makefile}
2025
2026 # execute all of the commands via Make (probably in parallel)
2027 make -s -f ${makefile} build_test_config_combos
2028 echo "$targets targets checked"
2029
2030 # clean up the temporary makefile
2031 rm ${makefile}
2032}
2033
Minos Galanakisf78447f2024-07-26 20:49:51 +01002034validate_aes_config_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002035 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
2036 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
2037 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
2038 return 1
2039 fi
2040 fi
2041 return 0
2042}
2043
Minos Galanakisf78447f2024-07-26 20:49:51 +01002044component_build_aes_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002045 # 18s - around 90ms per clang invocation on M1 Pro
2046 #
2047 # aes.o has many #if defined(...) guards that intersect in complex ways.
2048 # Test that all the combinations build cleanly.
2049
2050 MBEDTLS_ROOT_DIR="$PWD"
2051 msg "build: aes.o for all combinations of relevant config options"
2052
2053 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002054 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002055 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2056 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2057
2058 cd "$MBEDTLS_ROOT_DIR"
2059 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
2060
Ari Weiler-Ofek86422e52025-07-04 14:43:30 +01002061 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW,
Minos Galanakis471b34c2024-07-26 15:39:24 +01002062 # manually set or unset those configurations to check
2063 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
2064 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Minos Galanakis471b34c2024-07-26 15:39:24 +01002065 scripts/config.py unset MBEDTLS_NIST_KW_C
Ronald Cron54d1eec2024-09-06 09:55:38 +02002066
David Horstmann7cbeedc2025-08-26 17:26:45 +01002067 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
2068 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
2069 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
2070 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
Ronald Cron54d1eec2024-09-06 09:55:38 +02002071
Minos Galanakis471b34c2024-07-26 15:39:24 +01002072 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002073 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002074 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2075 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2076}
2077
Minos Galanakisf78447f2024-07-26 20:49:51 +01002078component_test_sha3_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002079 msg "sha3 loop unroll variations"
2080
2081 # define minimal config sufficient to test SHA3
Ronald Crone7f289e2024-09-06 11:02:47 +02002082 cat > include/mbedtls/mbedtls_config.h << END
Ronald Crone7f289e2024-09-06 11:02:47 +02002083END
2084
2085 cat > tf-psa-crypto/include/psa/crypto_config.h << END
2086 #define PSA_WANT_ALG_SHA_256 1
2087 #define PSA_WANT_ALG_SHA3_224 1
2088 #define PSA_WANT_ALG_SHA3_256 1
2089 #define PSA_WANT_ALG_SHA3_384 1
2090 #define PSA_WANT_ALG_SHA3_512 1
Ronald Cron06680362025-07-21 15:21:22 +02002091 #define PSA_WANT_KEY_TYPE_AES 1
Ronald Cron3dd1d3d2024-12-05 15:12:06 +01002092 #define MBEDTLS_CTR_DRBG_C
Ronald Cron3dd1d3d2024-12-05 15:12:06 +01002093 #define MBEDTLS_PSA_CRYPTO_C
2094 #define MBEDTLS_SELF_TEST
Minos Galanakis471b34c2024-07-26 15:39:24 +01002095END
2096
2097 msg "all loops unrolled"
2098 make clean
2099 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"
2100 ./tf-psa-crypto/tests/test_suite_shax
2101
2102 msg "all loops rolled up"
2103 make clean
2104 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"
2105 ./tf-psa-crypto/tests/test_suite_shax
2106}
2107
Minos Galanakisf699d512024-08-01 11:32:30 +01002108support_build_aes_aesce_armcc () {
2109 support_build_armcc
2110}
2111
Minos Galanakis471b34c2024-07-26 15:39:24 +01002112# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2113component_build_aes_aesce_armcc () {
2114 msg "Build: AESCE test on arm64 platform without plain C."
2115 scripts/config.py baremetal
2116
2117 # armc[56] don't support SHA-512 intrinsics
2118 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2119
2120 # Stop armclang warning about feature detection for A64_CRYPTO.
2121 # With this enabled, the library does build correctly under armclang,
2122 # but in baremetal builds (as tested here), feature detection is
2123 # unavailable, and the user is notified via a #warning. So enabling
2124 # this feature would prevent us from building with -Werror on
2125 # armclang. Tracked in #7198.
2126 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2127 scripts/config.py set MBEDTLS_HAVE_ASM
2128
2129 msg "AESCE, build with default configuration."
2130 scripts/config.py set MBEDTLS_AESCE_C
2131 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002132 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002133
2134 msg "AESCE, build AESCE only"
2135 scripts/config.py set MBEDTLS_AESCE_C
2136 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002137 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002138}
2139
Minos Galanakis471b34c2024-07-26 15:39:24 +01002140component_test_aes_only_128_bit_keys () {
2141 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2142 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002143 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002144
2145 make CFLAGS='-O2 -Werror -Wall -Wextra'
2146
2147 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2148 make test
2149}
2150
2151component_test_no_ctr_drbg_aes_only_128_bit_keys () {
2152 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2153 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002154 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002155 scripts/config.py unset MBEDTLS_CTR_DRBG_C
2156
2157 make CC=clang CFLAGS='-Werror -Wall -Wextra'
2158
2159 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2160 make test
2161}
2162
2163component_test_aes_only_128_bit_keys_have_builtins () {
2164 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2165 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002166 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002167 scripts/config.py unset MBEDTLS_AESNI_C
2168 scripts/config.py unset MBEDTLS_AESCE_C
2169
2170 make CFLAGS='-O2 -Werror -Wall -Wextra'
2171
2172 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2173 make test
2174
2175 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2176 programs/test/selftest
2177}
2178
2179component_test_gcm_largetable () {
2180 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2181 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
2182 scripts/config.py unset MBEDTLS_AESNI_C
2183 scripts/config.py unset MBEDTLS_AESCE_C
2184
2185 make CFLAGS='-O2 -Werror -Wall -Wextra'
2186
2187 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2188 make test
2189}
2190
2191component_test_aes_fewer_tables () {
2192 msg "build: default config with AES_FEWER_TABLES enabled"
2193 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2194 make CFLAGS='-O2 -Werror -Wall -Wextra'
2195
2196 msg "test: AES_FEWER_TABLES"
2197 make test
2198}
2199
2200component_test_aes_rom_tables () {
2201 msg "build: default config with AES_ROM_TABLES enabled"
2202 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2203 make CFLAGS='-O2 -Werror -Wall -Wextra'
2204
2205 msg "test: AES_ROM_TABLES"
2206 make test
2207}
2208
2209component_test_aes_fewer_tables_and_rom_tables () {
2210 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
2211 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2212 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2213 make CFLAGS='-O2 -Werror -Wall -Wextra'
2214
2215 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2216 make test
2217}
2218
Ronald Cron66040472024-09-06 10:14:38 +02002219# helper for component_test_block_cipher_no_decrypt_aesni() which:
Minos Galanakis471b34c2024-07-26 15:39:24 +01002220# - enable/disable the list of config options passed from -s/-u respectively.
2221# - build
2222# - test for tests_suite_xxx
2223# - selftest
2224#
2225# Usage: helper_block_cipher_no_decrypt_build_test
2226# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
2227# Options: -s set_opts the list of config options to enable
2228# -u unset_opts the list of config options to disable
2229# -c cflags the list of options passed to CFLAGS
2230# -l ldflags the list of options passed to LDFLAGS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002231helper_block_cipher_no_decrypt_build_test () {
2232 while [ $# -gt 0 ]; do
2233 case "$1" in
2234 -s)
2235 shift; local set_opts="$1";;
2236 -u)
2237 shift; local unset_opts="$1";;
2238 -c)
2239 shift; local cflags="-Werror -Wall -Wextra $1";;
2240 -l)
2241 shift; local ldflags="$1";;
2242 esac
2243 shift
2244 done
2245 set_opts="${set_opts:-}"
2246 unset_opts="${unset_opts:-}"
2247 cflags="${cflags:-}"
2248 ldflags="${ldflags:-}"
2249
2250 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
2251 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
2252
2253 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2254 make clean
2255 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
2256
2257 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2258 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2259 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2260 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2261 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2262 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2263 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
2264 not grep mbedtls_aesni_inverse_key ${BUILTIN_SRC_PATH}/aesni.o
2265
2266 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2267 make test
2268
2269 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2270 programs/test/selftest
2271}
2272
Ronald Cron66040472024-09-06 10:14:38 +02002273# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
2274config_block_cipher_no_decrypt () {
2275 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Ronald Cron66040472024-09-06 10:14:38 +02002276 scripts/config.py unset MBEDTLS_NIST_KW_C
2277
2278 # Enable support for cryptographic mechanisms through the PSA API.
2279 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
David Horstmannb907dbc2025-08-27 15:19:40 +01002280 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
2281 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
2282 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
2283 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
Ronald Cron66040472024-09-06 10:14:38 +02002284}
2285
2286component_test_block_cipher_no_decrypt_aesni () {
2287 # Test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics, AESNI assembly and
2288 # AES C implementation on x86_64 and with AESNI intrinsics on x86.
2289
2290 # This consistently causes an llvm crash on clang 3.8, so use gcc
2291 export CC=gcc
2292 config_block_cipher_no_decrypt
2293
Minos Galanakis471b34c2024-07-26 15:39:24 +01002294 # test AESNI intrinsics
2295 helper_block_cipher_no_decrypt_build_test \
2296 -s "MBEDTLS_AESNI_C" \
2297 -c "-mpclmul -msse2 -maes"
2298
2299 # test AESNI assembly
2300 helper_block_cipher_no_decrypt_build_test \
2301 -s "MBEDTLS_AESNI_C" \
2302 -c "-mno-pclmul -mno-sse2 -mno-aes"
2303
2304 # test AES C implementation
2305 helper_block_cipher_no_decrypt_build_test \
2306 -u "MBEDTLS_AESNI_C"
2307
2308 # test AESNI intrinsics for i386 target
2309 helper_block_cipher_no_decrypt_build_test \
2310 -s "MBEDTLS_AESNI_C" \
2311 -c "-m32 -mpclmul -msse2 -maes" \
2312 -l "-m32"
2313}
2314
Minos Galanakisf699d512024-08-01 11:32:30 +01002315support_test_block_cipher_no_decrypt_aesce_armcc () {
2316 support_build_armcc
2317}
2318
Minos Galanakis471b34c2024-07-26 15:39:24 +01002319component_test_block_cipher_no_decrypt_aesce_armcc () {
2320 scripts/config.py baremetal
2321
2322 # armc[56] don't support SHA-512 intrinsics
2323 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2324
2325 # Stop armclang warning about feature detection for A64_CRYPTO.
2326 # With this enabled, the library does build correctly under armclang,
2327 # but in baremetal builds (as tested here), feature detection is
2328 # unavailable, and the user is notified via a #warning. So enabling
2329 # this feature would prevent us from building with -Werror on
2330 # armclang. Tracked in #7198.
2331 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2332 scripts/config.py set MBEDTLS_HAVE_ASM
2333
Ronald Cron66040472024-09-06 10:14:38 +02002334 config_block_cipher_no_decrypt
Minos Galanakis471b34c2024-07-26 15:39:24 +01002335
2336 # test AESCE baremetal build
2337 scripts/config.py set MBEDTLS_AESCE_C
2338 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002339 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002340
2341 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2342 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2343 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2344 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2345 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2346 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2347 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
2348 not grep mbedtls_aesce_inverse_key ${BUILTIN_SRC_PATH}/aesce.o
2349 not grep aesce_decrypt_block ${BUILTIN_SRC_PATH}/aesce.o
2350}
2351
Ronald Cronaad5f1b2025-08-25 15:32:48 +02002352component_test_ctr_drbg_aes_256_sha_512 () {
2353 msg "build: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512 (ASan build)"
2354 scripts/config.py full
2355 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2356 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512
2357 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2358 make
2359
2360 msg "test: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512 (ASan build)"
2361 make test
2362}
2363
Minos Galanakis471b34c2024-07-26 15:39:24 +01002364component_test_ctr_drbg_aes_256_sha_256 () {
Minos Galanakisf3486e12025-08-18 14:09:26 +01002365 msg "build: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002366 scripts/config.py full
2367 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakisf3486e12025-08-18 14:09:26 +01002368 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256
Minos Galanakis471b34c2024-07-26 15:39:24 +01002369 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2370 make
2371
Minos Galanakisf3486e12025-08-18 14:09:26 +01002372 msg "test: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002373 make test
2374}
2375
2376component_test_ctr_drbg_aes_128_sha_512 () {
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002377 msg "build: full + set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002378 scripts/config.py full
2379 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002380 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Ronald Cronaad5f1b2025-08-25 15:32:48 +02002381 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512
Minos Galanakis471b34c2024-07-26 15:39:24 +01002382 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2383 make
2384
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002385 msg "test: full + set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002386 make test
2387}
2388
2389component_test_ctr_drbg_aes_128_sha_256 () {
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002390 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 +01002391 scripts/config.py full
2392 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002393 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakisf3486e12025-08-18 14:09:26 +01002394 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256
Minos Galanakis471b34c2024-07-26 15:39:24 +01002395 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2396 make
2397
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002398 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 +01002399 make test
2400}
2401
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002402component_test_full_static_keystore () {
2403 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2404 scripts/config.py full
2405 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2406 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
2407
2408 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2409 make test
2410}
2411
Minos Galanakis471b34c2024-07-26 15:39:24 +01002412component_test_psa_crypto_drivers () {
Ronald Crona0afbfb2024-10-15 13:20:31 +02002413 # Test dispatch to drivers and fallbacks with
2414 # test_suite_psa_crypto_driver_wrappers test suite. The test drivers that
2415 # are wrappers around the builtin drivers are activated by
2416 # PSA_CRYPTO_DRIVER_TEST.
2417 #
2418 # For the time being, some test cases in test_suite_block_cipher and
2419 # test_suite_md.psa rely on this component to be run at least once by the
2420 # CI. This should disappear as we progress the 4.x work. See
2421 # config_adjust_test_accelerators.h for more information.
Minos Galanakis471b34c2024-07-26 15:39:24 +01002422 msg "build: full + test drivers dispatching to builtins"
2423 scripts/config.py full
Ronald Cron67cc6a72024-10-14 10:55:24 +02002424 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_CONFIG_ADJUST_TEST_ACCELERATORS"
David Horstmann5b93d972024-10-31 15:36:05 +00002425 loc_cflags="${loc_cflags} -I../framework/tests/include"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002426
2427 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
2428
2429 msg "test: full + test drivers dispatching to builtins"
2430 make test
2431}
2432
2433component_build_psa_config_file () {
Minos Galanakis4f619e12024-11-14 14:56:47 +00002434 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002435 cp "$CRYPTO_CONFIG_H" psa_test_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002436 echo '#error "TF_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
2437 make CFLAGS="-I '$PWD' -DTF_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002438 # Make sure this feature is enabled. We'll disable it in the next phase.
Ronald Cron3f120062025-07-03 14:45:51 +02002439 programs/test/query_compile_time_config PSA_WANT_ALG_CMAC
Minos Galanakis471b34c2024-07-26 15:39:24 +01002440 make clean
2441
Minos Galanakis4f619e12024-11-14 14:56:47 +00002442 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE + TF_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002443 # In the user config, disable one feature and its dependencies, which will
2444 # reflect on the mbedtls configuration so we can query it with
2445 # query_compile_time_config.
2446 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
2447 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002448 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 +02002449 not programs/test/query_compile_time_config PSA_WANT_ALG_CMAC
Minos Galanakis471b34c2024-07-26 15:39:24 +01002450
2451 rm -f psa_test_config.h psa_user_config.h
2452}
2453
2454component_build_psa_alt_headers () {
2455 msg "build: make with PSA alt headers" # ~20s
2456
2457 # Generate alternative versions of the substitutable headers with the
2458 # same content except different include guards.
David Horstmanndc459512024-11-07 17:08:11 +00002459 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 +01002460
2461 # Build the library and some programs.
2462 # Don't build the fuzzers to avoid having to go through hoops to set
2463 # a correct include path for programs/fuzz/Makefile.
David Horstmann5b93d972024-10-31 15:36:05 +00002464 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
2465 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 +01002466
2467 # Check that we're getting the alternative include guards and not the
2468 # original include guards.
2469 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
2470 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
2471 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
2472 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
2473}
2474
2475component_test_min_mpi_window_size () {
2476 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
2477 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
2478 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2479 make
2480
2481 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2482 make test
2483}
Ronald Cronf256f8a2025-07-10 17:37:18 +02002484
2485component_test_xts () {
2486 # Component dedicated to run XTS unit test cases while XTS is not
2487 # supported through the PSA API.
2488 msg "build: Default + MBEDTLS_CIPHER_MODE_XTS"
2489
2490 echo "#define MBEDTLS_CIPHER_MODE_XTS" > psa_user_config.h
2491 cmake -DTF_PSA_CRYPTO_USER_CONFIG_FILE="psa_user_config.h"
2492 make
2493
Ronald Crone0b06eb2025-07-15 08:58:32 +02002494 rm -f psa_user_config.h
2495
Ronald Cronf256f8a2025-07-10 17:37:18 +02002496 msg "test: Default + MBEDTLS_CIPHER_MODE_XTS"
2497 make test
Ronald Cronf256f8a2025-07-10 17:37:18 +02002498}