blob: c330ccd8143e6f735d19e46e802b6e005b4982d3 [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"
Ronald Cron401f20f2025-09-02 14:50:10 +020050 $MAKE_COMMAND 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.
Ronald Cron401f20f2025-09-02 14:50:10 +020070 $MAKE_COMMAND 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 # EC-JPAKE use calloc/free in PSA core
David Horstmann7cbeedc2025-08-26 17:26:45 +010094 scripts/config.py unset PSA_WANT_ALG_JPAKE
Valerio Settia785eea2025-08-13 10:57:46 +020095 # Enable p192[k|r]1 curves which are disabled by default in tf-psa-crypto.
96 # This is required to get the proper test coverage otherwise there are
97 # tests in 'test_suite_psa_crypto_op_fail' that would never be executed.
98 scripts/config.py set PSA_WANT_ECC_SECP_K1_192
99 scripts/config.py set PSA_WANT_ECC_SECP_R1_192
Manuel Pégourié-Gonnard9114d4a2025-09-29 11:49:40 +0200100 scripts/config.py set TF_PSA_CRYPTO_ALLOW_REMOVED_MECHANISMS || true
Valerio Settia47b0452024-06-25 18:31:36 +0200101
102 # Accelerate all PSA features (which are still enabled in CRYPTO_CONFIG_H).
David Horstmann7cbeedc2025-08-26 17:26:45 +0100103 PSA_SYM_LIST=$(./scripts/config.py get-all-enabled PSA_WANT)
Valerio Settia47b0452024-06-25 18:31:36 +0200104 loc_accel_list=$(echo $PSA_SYM_LIST | sed 's/PSA_WANT_//g')
105
Valerio Settia47b0452024-06-25 18:31:36 +0200106 helper_libtestdriver1_adjust_config crypto
107 helper_libtestdriver1_make_drivers "$loc_accel_list"
108
Valerio Setti13aadd72024-08-13 13:13:23 +0200109 msg "crypto without heap: build main library"
Valerio Setti35b0b022024-08-13 13:36:50 +0200110 # Disable all legacy MBEDTLS_xxx symbols.
111 scripts/config.py unset-all "^MBEDTLS_"
112 # Build the PSA core using the proper config file.
113 scripts/config.py set MBEDTLS_PSA_CRYPTO_C
Valerio Settia47b0452024-06-25 18:31:36 +0200114 # Enable fully-static key slots in PSA core.
115 scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOTS
Valerio Setti35b0b022024-08-13 13:36:50 +0200116 # Prevent PSA core from creating a copy of input/output buffers.
Valerio Settia47b0452024-06-25 18:31:36 +0200117 scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
118 # Prevent PSA core from using CTR-DRBG or HMAC-DRBG for random generation.
119 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Valerio Setti13aadd72024-08-13 13:13:23 +0200120 # Set calloc/free as null pointer functions. Calling them would crash
Valerio Settia47b0452024-06-25 18:31:36 +0200121 # the program so we can use this as a "sentinel" for being sure no module
122 # is making use of these functions in the library.
Valerio Setti35b0b022024-08-13 13:36:50 +0200123 scripts/config.py set MBEDTLS_PLATFORM_C
Valerio Settia47b0452024-06-25 18:31:36 +0200124 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
125 scripts/config.py set MBEDTLS_PLATFORM_STD_CALLOC NULL
126 scripts/config.py set MBEDTLS_PLATFORM_STD_FREE NULL
127
Valerio Settia47b0452024-06-25 18:31:36 +0200128 helper_libtestdriver1_make_main "$loc_accel_list" lib
129
Valerio Setti13aadd72024-08-13 13:13:23 +0200130 msg "crypto without heap: build test suites and helpers"
131 # Reset calloc/free functions to normal operations so that test code can
Valerio Settia47b0452024-06-25 18:31:36 +0200132 # freely use them.
133 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
134 scripts/config.py unset MBEDTLS_PLATFORM_STD_CALLOC
135 scripts/config.py unset MBEDTLS_PLATFORM_STD_FREE
136 helper_libtestdriver1_make_main "$loc_accel_list" tests
137
Valerio Setti13aadd72024-08-13 13:13:23 +0200138 msg "crypto without heap: test"
Ronald Cron401f20f2025-09-02 14:50:10 +0200139 $MAKE_COMMAND test
Valerio Settia47b0452024-06-25 18:31:36 +0200140}
141
Minos Galanakisf78447f2024-07-26 20:49:51 +0100142component_test_no_rsa_key_pair_generation () {
Minos Galanakisdc0f73a2024-07-26 20:41:42 +0100143 msg "build: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
David Horstmann7cbeedc2025-08-26 17:26:45 +0100144 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Ronald Cron401f20f2025-09-02 14:50:10 +0200145 $MAKE_COMMAND
Minos Galanakisdc0f73a2024-07-26 20:41:42 +0100146
147 msg "test: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
Ronald Cron401f20f2025-09-02 14:50:10 +0200148 $MAKE_COMMAND test
Minos Galanakisdc0f73a2024-07-26 20:41:42 +0100149}
150
Minos Galanakisc06fd302024-08-01 12:16:59 +0100151component_test_no_pem_no_fs () {
152 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
153 scripts/config.py unset MBEDTLS_PEM_PARSE_C
154 scripts/config.py unset MBEDTLS_FS_IO
155 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
156 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
157 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
158 make
159
160 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
161 make test
162
163 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
164 tests/ssl-opt.sh
165}
166
167component_test_rsa_no_crt () {
168 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
169 scripts/config.py set MBEDTLS_RSA_NO_CRT
170 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
171 make
172
173 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
174 make test
175
176 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
177 tests/ssl-opt.sh -f RSA
178
179 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
180 tests/compat.sh -t RSA
181
182 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
183 tests/context-info.sh
184}
185
Minos Galanakisc06fd302024-08-01 12:16:59 +0100186component_test_no_ctr_drbg_use_psa () {
187 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
188 scripts/config.py full
189 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Minos Galanakisc06fd302024-08-01 12:16:59 +0100190
191 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
192 make
193
194 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
195 make test
196
197 # In this configuration, the TLS test programs use HMAC_DRBG.
198 # The SSL tests are slow, so run a small subset, just enough to get
199 # confidence that the SSL code copes with HMAC_DRBG.
200 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
201 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
202
203 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
204 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
205}
206
Minos Galanakisc06fd302024-08-01 12:16:59 +0100207component_test_no_hmac_drbg_use_psa () {
208 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
209 scripts/config.py full
210 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
David Horstmann7cbeedc2025-08-26 17:26:45 +0100211 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA # requires HMAC_DRBG
Minos Galanakisc06fd302024-08-01 12:16:59 +0100212
213 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
214 make
215
216 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
217 make test
218
219 # Normally our ECDSA implementation uses deterministic ECDSA. But since
220 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
221 # instead.
222 # Test SSL with non-deterministic ECDSA. Only test features that
223 # might be affected by how ECDSA signature is performed.
224 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
225 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
226
227 # To save time, only test one protocol version, since this part of
228 # the protocol is identical in (D)TLS up to 1.2.
229 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
230 tests/compat.sh -m tls12 -t 'ECDSA'
231}
232
Minos Galanakisc06fd302024-08-01 12:16:59 +0100233component_test_psa_external_rng_no_drbg_use_psa () {
234 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
235 scripts/config.py full
236 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Minos Galanakisc06fd302024-08-01 12:16:59 +0100237 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
238 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
239 scripts/config.py unset MBEDTLS_CTR_DRBG_C
240 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
David Horstmann7cbeedc2025-08-26 17:26:45 +0100241 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA # Requires HMAC_DRBG
Ronald Cron401f20f2025-09-02 14:50:10 +0200242 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakisc06fd302024-08-01 12:16:59 +0100243
244 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Ronald Cron401f20f2025-09-02 14:50:10 +0200245 $MAKE_COMMAND test
Minos Galanakisc06fd302024-08-01 12:16:59 +0100246
247 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
248 tests/ssl-opt.sh -f 'Default\|opaque'
249}
250
Minos Galanakis471b34c2024-07-26 15:39:24 +0100251component_test_psa_external_rng_use_psa_crypto () {
Ronald Cron3b306432025-09-02 18:30:08 +0200252 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG/NV_SEED"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100253 scripts/config.py full
254 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Minos Galanakis471b34c2024-07-26 15:39:24 +0100255 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Ronald Cron3b306432025-09-02 18:30:08 +0200256 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
257 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Ronald Cron401f20f2025-09-02 14:50:10 +0200258 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100259
Ronald Cron3b306432025-09-02 18:30:08 +0200260 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG/NV_SEED"
Ronald Cron401f20f2025-09-02 14:50:10 +0200261 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100262
Ronald Cron3b306432025-09-02 18:30:08 +0200263 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG/NV_SEED"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100264 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
Ronald Cron401f20f2025-09-02 14:50:10 +0200274 $MAKE_COMMAND CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100275
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"
Ronald Cron401f20f2025-09-02 14:50:10 +0200281 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100282}
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.
Ronald Cron401f20f2025-09-02 14:50:10 +0200301 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100302
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"
Ronald Cron401f20f2025-09-02 14:50:10 +0200308 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100309}
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
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100330
331 # The following modules directly depends on CIPHER_C
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100332 scripts/config.py unset MBEDTLS_NIST_KW_C
333
Ronald Cron401f20f2025-09-02 14:50:10 +0200334 $MAKE_COMMAND
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100335
336 # Ensure that CIPHER_C was not re-enabled
337 not grep mbedtls_cipher_init ${BUILTIN_SRC_PATH}/cipher.o
338
339 msg "test: full no CIPHER"
Ronald Cron401f20f2025-09-02 14:50:10 +0200340 $MAKE_COMMAND test
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100341}
342
Minos Galanakisf78447f2024-07-26 20:49:51 +0100343component_test_full_no_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100344 msg "build: full no PSA_WANT_ALG_CCM"
345
346 # Full config enables:
347 # - USE_PSA_CRYPTO so that TLS code dispatches cipher/AEAD to PSA
348 # - CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
349 scripts/config.py full
350
351 # Disable PSA_WANT_ALG_CCM so that CCM is not supported in PSA. CCM_C is still
352 # enabled, but not used from TLS since USE_PSA is set.
353 # This is helpful to ensure that TLS tests below have proper dependencies.
354 #
355 # Note: also PSA_WANT_ALG_CCM_STAR_NO_TAG is enabled, but it does not cause
356 # PSA_WANT_ALG_CCM to be re-enabled.
David Horstmannb907dbc2025-08-27 15:19:40 +0100357 scripts/config.py unset PSA_WANT_ALG_CCM
Minos Galanakis471b34c2024-07-26 15:39:24 +0100358
Ronald Cron401f20f2025-09-02 14:50:10 +0200359 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +0100360
361 msg "test: full no PSA_WANT_ALG_CCM"
Ronald Cron401f20f2025-09-02 14:50:10 +0200362 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100363}
364
Minos Galanakisf78447f2024-07-26 20:49:51 +0100365component_test_full_no_ccm_star_no_tag () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100366 msg "build: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
367
368 # Full config enables CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
369 scripts/config.py full
370
371 # Disable CCM_STAR_NO_TAG, which is the target of this test, as well as all
372 # other components that enable MBEDTLS_PSA_BUILTIN_CIPHER internal symbol.
373 # This basically disables all unauthenticated ciphers on the PSA side, while
374 # keeping AEADs enabled.
375 #
376 # Note: PSA_WANT_ALG_CCM is enabled, but it does not cause
377 # PSA_WANT_ALG_CCM_STAR_NO_TAG to be re-enabled.
David Horstmannb907dbc2025-08-27 15:19:40 +0100378 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
379 scripts/config.py unset PSA_WANT_ALG_STREAM_CIPHER
380 scripts/config.py unset PSA_WANT_ALG_CTR
381 scripts/config.py unset PSA_WANT_ALG_CFB
382 scripts/config.py unset PSA_WANT_ALG_OFB
383 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
Ben Taylor1948c942025-03-04 09:11:11 +0000384 # NOTE unsettting PSA_WANT_ALG_ECB_NO_PADDING without unsetting NIST_KW_C will
385 # mean PSA_WANT_ALG_ECB_NO_PADDING is re-enabled, so disabling it also.
David Horstmannb907dbc2025-08-27 15:19:40 +0100386 scripts/config.py unset MBEDTLS_NIST_KW_C
387 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
388 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
Minos Galanakis471b34c2024-07-26 15:39:24 +0100389
Ronald Cron401f20f2025-09-02 14:50:10 +0200390 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +0100391
392 # Ensure MBEDTLS_PSA_BUILTIN_CIPHER was not enabled
393 not grep mbedtls_psa_cipher ${PSA_CORE_PATH}/psa_crypto_cipher.o
394
395 msg "test: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
Ronald Cron401f20f2025-09-02 14:50:10 +0200396 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100397}
398
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200399component_test_config_symmetric_only () {
400 msg "build: configs/config-symmetric-only.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +0000401 MBEDTLS_CONFIG="configs/config-symmetric-only.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +0000402 CRYPTO_CONFIG="tf-psa-crypto/configs/crypto-config-symmetric-only.h"
Ronald Cronfaadfc22024-12-07 17:24:28 +0100403 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 +0200404 make
405
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200406 msg "test: configs/config-symmetric-only.h - unit tests"
Gilles Peskineaf5a8992024-09-14 11:27:44 +0200407 make test
408}
409
Minos Galanakisc06fd302024-08-01 12:16:59 +0100410component_test_everest () {
411 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
412 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
413 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
414 make
415
416 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
417 make test
418
419 msg "test: metatests (clang, ASan)"
420 tests/scripts/run-metatests.sh any asan poison
421
422 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
423 tests/ssl-opt.sh -f ECDH
424
425 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
426 # Exclude some symmetric ciphers that are redundant here to gain time.
427 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
428}
429
Ben Taylor59213b62025-08-14 10:01:06 +0100430component_test_everest_curve25519_only () {
Ben Taylorf5729362025-09-02 13:10:52 +0100431 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
Ben Taylor59213b62025-08-14 10:01:06 +0100432 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Ronald Cronfeb5e262025-09-15 18:36:39 +0200433 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
434 scripts/config.py unset PSA_WANT_ALG_ECDSA
435 scripts/config.py set PSA_WANT_ALG_ECDH
Ben Taylor59213b62025-08-14 10:01:06 +0100436 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
437 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
Ronald Cronfeb5e262025-09-15 18:36:39 +0200438 scripts/config.py unset PSA_WANT_ALG_JPAKE
Ben Taylor59213b62025-08-14 10:01:06 +0100439
440 # Disable all curves
Ronald Cronfeb5e262025-09-15 18:36:39 +0200441 scripts/config.py unset-all "PSA_WANT_ECC_[0-9A-Z_a-z]*$"
442 scripts/config.py set PSA_WANT_ECC_MONTGOMERY_255
Ben Taylor59213b62025-08-14 10:01:06 +0100443
Ronald Cron401f20f2025-09-02 14:50:10 +0200444 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Ben Taylor59213b62025-08-14 10:01:06 +0100445
446 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
Ronald Cron401f20f2025-09-02 14:50:10 +0200447 $MAKE_COMMAND test
Ben Taylor59213b62025-08-14 10:01:06 +0100448}
449
Minos Galanakis471b34c2024-07-26 15:39:24 +0100450component_test_psa_collect_statuses () {
451 msg "build+test: psa_collect_statuses" # ~30s
452 scripts/config.py full
453 tests/scripts/psa_collect_statuses.py
454 # Check that psa_crypto_init() succeeded at least once
455 grep -q '^0:psa_crypto_init:' tests/statuses.log
456 rm -f tests/statuses.log
457}
458
459# Check that the specified libraries exist and are empty.
460are_empty_libraries () {
461 nm "$@" >/dev/null 2>/dev/null
462 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
463}
464
Minos Galanakis471b34c2024-07-26 15:39:24 +0100465component_test_crypto_for_psa_service () {
466 msg "build: make, config for PSA crypto service"
467 scripts/config.py crypto
468 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
469 # Disable things that are not needed for just cryptography, to
470 # reach a configuration that would be typical for a PSA cryptography
471 # service providing all implemented PSA algorithms.
472 # System stuff
473 scripts/config.py unset MBEDTLS_ERROR_C
474 scripts/config.py unset MBEDTLS_TIMING_C
475 scripts/config.py unset MBEDTLS_VERSION_FEATURES
476 # Crypto stuff with no PSA interface
477 scripts/config.py unset MBEDTLS_BASE64_C
Minos Galanakis471b34c2024-07-26 15:39:24 +0100478 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
479 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
480 scripts/config.py unset MBEDTLS_NIST_KW_C
481 scripts/config.py unset MBEDTLS_PEM_PARSE_C
482 scripts/config.py unset MBEDTLS_PEM_WRITE_C
483 scripts/config.py unset MBEDTLS_PKCS12_C
484 scripts/config.py unset MBEDTLS_PKCS5_C
485 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
486 # in PSA code to work with RSA keys. We don't require users to set those:
487 # they will be reenabled in build_info.h.
488 scripts/config.py unset MBEDTLS_PK_C
489 scripts/config.py unset MBEDTLS_PK_PARSE_C
490 scripts/config.py unset MBEDTLS_PK_WRITE_C
Ronald Cron401f20f2025-09-02 14:50:10 +0200491 $MAKE_COMMAND CFLAGS='-O1 -Werror' all test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100492 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
493}
494
495component_build_crypto_baremetal () {
496 msg "build: make, crypto only, baremetal config"
497 scripts/config.py crypto_baremetal
Ronald Cron401f20f2025-09-02 14:50:10 +0200498 $MAKE_COMMAND CFLAGS="-O1 -Werror -I$PWD/framework/tests/include/baremetal-override/"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100499 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
500}
501
502support_build_crypto_baremetal () {
503 support_build_baremetal "$@"
504}
505
506# depends.py family of tests
507component_test_depends_py_cipher_id () {
508 msg "test/build: depends.py cipher_id (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200509 tests/scripts/depends.py cipher_id
Minos Galanakis471b34c2024-07-26 15:39:24 +0100510}
511
512component_test_depends_py_cipher_chaining () {
513 msg "test/build: depends.py cipher_chaining (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200514 tests/scripts/depends.py cipher_chaining
Minos Galanakis471b34c2024-07-26 15:39:24 +0100515}
516
Minos Galanakis471b34c2024-07-26 15:39:24 +0100517component_test_depends_py_curves () {
518 msg "test/build: depends.py curves (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200519 tests/scripts/depends.py curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100520}
521
522component_test_depends_py_hashes () {
523 msg "test/build: depends.py hashes (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200524 tests/scripts/depends.py hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +0100525}
526
Minos Galanakis471b34c2024-07-26 15:39:24 +0100527component_test_depends_py_pkalgs () {
528 msg "test/build: depends.py pkalgs (gcc)"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100529 tests/scripts/depends.py pkalgs
530}
531
532component_test_psa_crypto_config_ffdh_2048_only () {
533 msg "build: full config - only DH 2048"
534
535 scripts/config.py full
536
537 # Disable all DH groups other than 2048.
David Horstmannb907dbc2025-08-27 15:19:40 +0100538 scripts/config.py unset PSA_WANT_DH_RFC7919_3072
539 scripts/config.py unset PSA_WANT_DH_RFC7919_4096
540 scripts/config.py unset PSA_WANT_DH_RFC7919_6144
541 scripts/config.py unset PSA_WANT_DH_RFC7919_8192
Minos Galanakis471b34c2024-07-26 15:39:24 +0100542
Ronald Cron401f20f2025-09-02 14:50:10 +0200543 $MAKE_COMMAND CFLAGS="$ASAN_CFLAGS -Werror" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100544
545 msg "test: full config - only DH 2048"
Ronald Cron401f20f2025-09-02 14:50:10 +0200546 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100547
548 msg "ssl-opt: full config - only DH 2048"
549 tests/ssl-opt.sh -f "ffdh"
550}
551
Minos Galanakis471b34c2024-07-26 15:39:24 +0100552component_test_psa_crypto_config_accel_ecdsa () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200553 msg "build: accelerated ECDSA"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100554
Minos Galanakis471b34c2024-07-26 15:39:24 +0100555 # Configure
556 # ---------
557
Elena Uziunaite91d83862024-09-04 14:51:31 +0100558 # Start from default config + TLS 1.3
Minos Galanakis471b34c2024-07-26 15:39:24 +0100559 helper_libtestdriver1_adjust_config "default"
560
Valerio Setti37a42812025-08-11 12:52:49 +0200561 # Algorithms and key types to accelerate
562 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
563 $(helper_get_psa_key_type_list "ECC") \
564 $(helper_get_psa_curve_list)"
565
Minos Galanakis471b34c2024-07-26 15:39:24 +0100566 # Disable things that depend on it
567 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +0100568
569 # Build
570 # -----
571
572 # These hashes are needed for some ECDSA signature tests.
Elena Uziunaiteffce45c2024-09-12 14:58:52 +0100573 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 +0100574 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
575
576 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
577
578 helper_libtestdriver1_make_main "$loc_accel_list"
579
580 # Make sure this was not re-enabled by accident (additive config)
581 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
582
583 # Run the tests
584 # -------------
585
Ronald Cron93ba6252024-09-05 10:37:14 +0200586 msg "test: accelerated ECDSA"
Ronald Cron401f20f2025-09-02 14:50:10 +0200587 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100588}
589
590component_test_psa_crypto_config_accel_ecdh () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200591 msg "build: accelerated ECDH"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100592
Minos Galanakis471b34c2024-07-26 15:39:24 +0100593 # Configure
594 # ---------
595
596 # Start from default config (no USE_PSA)
597 helper_libtestdriver1_adjust_config "default"
598
Valerio Setti37a42812025-08-11 12:52:49 +0200599 # Algorithms and key types to accelerate
600 loc_accel_list="ALG_ECDH \
601 $(helper_get_psa_key_type_list "ECC") \
602 $(helper_get_psa_curve_list)"
603
Minos Galanakis471b34c2024-07-26 15:39:24 +0100604 # Disable things that depend on it
Minos Galanakis471b34c2024-07-26 15:39:24 +0100605 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
606 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
607 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
608
609 # Build
610 # -----
611
612 helper_libtestdriver1_make_drivers "$loc_accel_list"
613
614 helper_libtestdriver1_make_main "$loc_accel_list"
615
616 # Make sure this was not re-enabled by accident (additive config)
617 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
618
619 # Run the tests
620 # -------------
621
Ronald Cron93ba6252024-09-05 10:37:14 +0200622 msg "test: accelerated ECDH"
Ronald Cron401f20f2025-09-02 14:50:10 +0200623 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100624}
625
626component_test_psa_crypto_config_accel_ffdh () {
627 msg "build: full with accelerated FFDH"
628
Minos Galanakis471b34c2024-07-26 15:39:24 +0100629 # Configure
630 # ---------
631
632 # start with full (USE_PSA and TLS 1.3)
633 helper_libtestdriver1_adjust_config "full"
634
Valerio Setti37a42812025-08-11 12:52:49 +0200635 # Algorithms and key types to accelerate
636 loc_accel_list="ALG_FFDH \
637 $(helper_get_psa_key_type_list "DH") \
638 $(helper_get_psa_dh_group_list)"
639
Minos Galanakis471b34c2024-07-26 15:39:24 +0100640 # Build
641 # -----
642
643 helper_libtestdriver1_make_drivers "$loc_accel_list"
644
645 helper_libtestdriver1_make_main "$loc_accel_list"
646
647 # Make sure this was not re-enabled by accident (additive config)
Valerio Settieb63eb22025-02-12 13:32:49 +0100648 not grep mbedtls_psa_ffdh_key_agreement ${BUILTIN_SRC_PATH}/psa_crypto_ffdh.o
Minos Galanakis471b34c2024-07-26 15:39:24 +0100649
650 # Run the tests
651 # -------------
652
653 msg "test: full with accelerated FFDH"
Ronald Cron401f20f2025-09-02 14:50:10 +0200654 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100655
656 msg "ssl-opt: full with accelerated FFDH alg"
657 tests/ssl-opt.sh -f "ffdh"
658}
659
660component_test_psa_crypto_config_reference_ffdh () {
661 msg "build: full with non-accelerated FFDH"
662
663 # Start with full (USE_PSA and TLS 1.3)
664 helper_libtestdriver1_adjust_config "full"
665
Ronald Cron401f20f2025-09-02 14:50:10 +0200666 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +0100667
668 msg "test suites: full with non-accelerated FFDH alg"
Ronald Cron401f20f2025-09-02 14:50:10 +0200669 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100670
671 msg "ssl-opt: full with non-accelerated FFDH alg"
672 tests/ssl-opt.sh -f "ffdh"
673}
674
Minos Galanakisf78447f2024-07-26 20:49:51 +0100675component_test_psa_crypto_config_accel_pake () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100676 msg "build: full with accelerated PAKE"
677
Minos Galanakis471b34c2024-07-26 15:39:24 +0100678 # Configure
679 # ---------
680
681 helper_libtestdriver1_adjust_config "full"
682
Valerio Setti37a42812025-08-11 12:52:49 +0200683 loc_accel_list="ALG_JPAKE \
684 $(helper_get_psa_key_type_list "ECC") \
685 $(helper_get_psa_curve_list)"
686
Minos Galanakis471b34c2024-07-26 15:39:24 +0100687 # Make built-in fallback not available
Minos Galanakis471b34c2024-07-26 15:39:24 +0100688 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
689
690 # Build
691 # -----
692
693 helper_libtestdriver1_make_drivers "$loc_accel_list"
694
695 helper_libtestdriver1_make_main "$loc_accel_list"
696
697 # Make sure this was not re-enabled by accident (additive config)
698 not grep mbedtls_ecjpake_init ${BUILTIN_SRC_PATH}/ecjpake.o
699
700 # Run the tests
701 # -------------
702
703 msg "test: full with accelerated PAKE"
Ronald Cron401f20f2025-09-02 14:50:10 +0200704 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100705}
706
707component_test_psa_crypto_config_accel_ecc_some_key_types () {
708 msg "build: full with accelerated EC algs and some key types"
709
Valerio Setti37a42812025-08-11 12:52:49 +0200710 # Configure
711 # ---------
712
713 # start with config full for maximum coverage (also enables USE_PSA)
714 helper_libtestdriver1_adjust_config "full"
715
Minos Galanakis471b34c2024-07-26 15:39:24 +0100716 # Algorithms and key types to accelerate
717 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
718 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
719 ALG_ECDH \
720 ALG_JPAKE \
721 KEY_TYPE_ECC_PUBLIC_KEY \
722 KEY_TYPE_ECC_KEY_PAIR_BASIC \
723 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
724 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
725 $(helper_get_psa_curve_list)"
726
Minos Galanakis471b34c2024-07-26 15:39:24 +0100727 # Disable all curves - those that aren't accelerated should be re-enabled
728 helper_disable_builtin_curves
729
730 # Restartable feature is not yet supported by PSA. Once it will in
731 # the future, the following line could be removed (see issues
732 # 6061, 6332 and following ones)
733 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
734
735 # this is not supported by the driver API yet
David Horstmannb907dbc2025-08-27 15:19:40 +0100736 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +0100737
738 # Build
739 # -----
740
741 # These hashes are needed for some ECDSA signature tests.
742 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
743 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
744 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
745
746 helper_libtestdriver1_make_main "$loc_accel_list"
747
748 # ECP should be re-enabled but not the others
749 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
750 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
751 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
752 grep mbedtls_ecp ${BUILTIN_SRC_PATH}/ecp.o
753
754 # Run the tests
755 # -------------
756
757 msg "test suites: full with accelerated EC algs and some key types"
Ronald Cron401f20f2025-09-02 14:50:10 +0200758 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100759}
760
761# Run tests with only (non-)Weierstrass accelerated
762# Common code used in:
763# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
764# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100765common_test_psa_crypto_config_accel_ecc_some_curves () {
766 weierstrass=$1
767 if [ $weierstrass -eq 1 ]; then
768 desc="Weierstrass"
769 else
770 desc="non-Weierstrass"
771 fi
772
773 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
774
Valerio Setti37a42812025-08-11 12:52:49 +0200775 # Configure
776 # ---------
777
778 # Start with config crypto_full and remove PK_C:
779 # that's what's supported now, see docs/driver-only-builds.md.
780 helper_libtestdriver1_adjust_config "crypto_full"
781 scripts/config.py unset MBEDTLS_PK_C
782 scripts/config.py unset MBEDTLS_PK_PARSE_C
783 scripts/config.py unset MBEDTLS_PK_WRITE_C
784
Valerio Setti37a42812025-08-11 12:52:49 +0200785 # Disable all curves - those that aren't accelerated should be re-enabled
786 helper_disable_builtin_curves
787
Valerio Setti981a0c42025-08-12 11:31:11 +0200788 # Note: Curves are handled in a special way by the libtestdriver machinery,
Minos Galanakis471b34c2024-07-26 15:39:24 +0100789 # so we only want to include them in the accel list when building the main
790 # libraries, hence the use of a separate variable.
791 # Note: the following loop is a modified version of
792 # helper_get_psa_curve_list that only keeps Weierstrass families.
793 loc_weierstrass_list=""
794 loc_non_weierstrass_list=""
795 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
796 case $item in
797 ECC_BRAINPOOL*|ECC_SECP*)
798 loc_weierstrass_list="$loc_weierstrass_list $item"
799 ;;
800 *)
801 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
802 ;;
803 esac
804 done
805 if [ $weierstrass -eq 1 ]; then
806 loc_curve_list=$loc_weierstrass_list
807 else
808 loc_curve_list=$loc_non_weierstrass_list
809 fi
810
811 # Algorithms and key types to accelerate
812 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
813 ALG_ECDH \
814 ALG_JPAKE \
815 $(helper_get_psa_key_type_list "ECC") \
816 $loc_curve_list"
817
Minos Galanakis471b34c2024-07-26 15:39:24 +0100818 # Restartable feature is not yet supported by PSA. Once it will in
819 # the future, the following line could be removed (see issues
820 # 6061, 6332 and following ones)
821 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
822
823 # this is not supported by the driver API yet
David Horstmannb907dbc2025-08-27 15:19:40 +0100824 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +0100825
826 # Build
827 # -----
828
829 # These hashes are needed for some ECDSA signature tests.
830 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
831 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
832 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
833
834 helper_libtestdriver1_make_main "$loc_accel_list"
835
836 # We expect ECDH to be re-enabled for the missing curves
837 grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
838 # We expect ECP to be re-enabled, however the parts specific to the
839 # families of curves that are accelerated should be ommited.
840 # - functions with mxz in the name are specific to Montgomery curves
841 # - ecp_muladd is specific to Weierstrass curves
842 ##nm ${BUILTIN_SRC_PATH}/ecp.o | tee ecp.syms
843 if [ $weierstrass -eq 1 ]; then
844 not grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
845 grep mxz ${BUILTIN_SRC_PATH}/ecp.o
846 else
847 grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
848 not grep mxz ${BUILTIN_SRC_PATH}/ecp.o
849 fi
850 # We expect ECDSA and ECJPAKE to be re-enabled only when
851 # Weierstrass curves are not accelerated
852 if [ $weierstrass -eq 1 ]; then
853 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
854 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
855 else
856 grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
857 grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
858 fi
859
860 # Run the tests
861 # -------------
862
863 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
Ronald Cron401f20f2025-09-02 14:50:10 +0200864 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100865}
866
867component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
868 common_test_psa_crypto_config_accel_ecc_some_curves 1
869}
870
871component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
872 common_test_psa_crypto_config_accel_ecc_some_curves 0
873}
874
875# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
876# ECDH, ECDSA) with and without drivers.
877# The input parameter is a boolean value which indicates:
878# - 0 keep built-in EC algs,
879# - 1 exclude built-in EC algs (driver only).
880#
881# This is used by the two following components to ensure they always use the
882# same config, except for the use of driver or built-in EC algorithms:
883# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
884# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
885# This supports comparing their test coverage with analyze_outcomes.py.
Minos Galanakis471b34c2024-07-26 15:39:24 +0100886config_psa_crypto_config_ecp_light_only () {
887 driver_only="$1"
888 # start with config full for maximum coverage (also enables USE_PSA)
889 helper_libtestdriver1_adjust_config "full"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100890
891 # Restartable feature is not yet supported by PSA. Once it will in
892 # the future, the following line could be removed (see issues
893 # 6061, 6332 and following ones)
894 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
895}
896
897# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100898component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
899 msg "build: full with accelerated EC algs"
900
Valerio Setti37a42812025-08-11 12:52:49 +0200901 # Configure
902 # ---------
903
904 # Use the same config as reference, only without built-in EC algs
905 config_psa_crypto_config_ecp_light_only 1
906
Minos Galanakis471b34c2024-07-26 15:39:24 +0100907 # Algorithms and key types to accelerate
908 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
909 ALG_ECDH \
910 ALG_JPAKE \
911 $(helper_get_psa_key_type_list "ECC") \
912 $(helper_get_psa_curve_list)"
913
Minos Galanakis471b34c2024-07-26 15:39:24 +0100914 # Do not disable builtin curves because that support is required for:
915 # - MBEDTLS_PK_PARSE_EC_EXTENDED
916 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
917
918 # Build
919 # -----
920
921 # These hashes are needed for some ECDSA signature tests.
922 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
923 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
924 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
925
926 helper_libtestdriver1_make_main "$loc_accel_list"
927
928 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
929 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
930 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
931 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
932 not grep mbedtls_ecp_mul ${BUILTIN_SRC_PATH}/ecp.o
933
934 # Run the tests
935 # -------------
936
937 msg "test suites: full with accelerated EC algs"
Ronald Cron401f20f2025-09-02 14:50:10 +0200938 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100939
940 msg "ssl-opt: full with accelerated EC algs"
941 tests/ssl-opt.sh
942}
943
944# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100945component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200946 msg "build: non-accelerated EC algs"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100947
948 config_psa_crypto_config_ecp_light_only 0
949
Ronald Cron401f20f2025-09-02 14:50:10 +0200950 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +0100951
952 msg "test suites: full with non-accelerated EC algs"
Ronald Cron401f20f2025-09-02 14:50:10 +0200953 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100954
955 msg "ssl-opt: full with non-accelerated EC algs"
956 tests/ssl-opt.sh
957}
958
959# This helper function is used by:
960# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
961# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
962# to ensure that both tests use the same underlying configuration when testing
963# driver's coverage with analyze_outcomes.py.
964#
965# This functions accepts 1 boolean parameter as follows:
966# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
967# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
968# - 0: include built-in implementation of EC algorithms.
969#
970# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
971# on the ECP module.
Minos Galanakis471b34c2024-07-26 15:39:24 +0100972config_psa_crypto_no_ecp_at_all () {
973 driver_only="$1"
974 # start with full config for maximum coverage (also enables USE_PSA)
975 helper_libtestdriver1_adjust_config "full"
976
Minos Galanakis471b34c2024-07-26 15:39:24 +0100977 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
978 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
979 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
David Horstmannb907dbc2025-08-27 15:19:40 +0100980 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +0100981
982 # Restartable feature is not yet supported by PSA. Once it will in
983 # the future, the following line could be removed (see issues
984 # 6061, 6332 and following ones)
985 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
986}
987
988# Build and test a configuration where driver accelerates all EC algs while
989# all support and dependencies from ECP and ECP_LIGHT are removed on the library
990# side.
991#
992# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Minos Galanakis471b34c2024-07-26 15:39:24 +0100993component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
994 msg "build: full + accelerated EC algs - ECP"
995
Minos Galanakis471b34c2024-07-26 15:39:24 +0100996 # Configure
997 # ---------
998
999 # Set common configurations between library's and driver's builds
1000 config_psa_crypto_no_ecp_at_all 1
1001 # Disable all the builtin curves. All the required algs are accelerated.
1002 helper_disable_builtin_curves
1003
Valerio Setti37a42812025-08-11 12:52:49 +02001004 # Algorithms and key types to accelerate
1005 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1006 ALG_ECDH \
1007 ALG_JPAKE \
1008 $(helper_get_psa_key_type_list "ECC") \
1009 $(helper_get_psa_curve_list)"
1010
Minos Galanakis471b34c2024-07-26 15:39:24 +01001011 # Build
1012 # -----
1013
1014 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1015 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1016 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1017 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1018
1019 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1020
1021 helper_libtestdriver1_make_main "$loc_accel_list"
1022
1023 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1024 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1025 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1026 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1027 # Also ensure that ECP module was not re-enabled
1028 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1029
1030 # Run the tests
1031 # -------------
1032
1033 msg "test: full + accelerated EC algs - ECP"
Ronald Cron401f20f2025-09-02 14:50:10 +02001034 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001035
1036 msg "ssl-opt: full + accelerated EC algs - ECP"
1037 tests/ssl-opt.sh
1038}
1039
1040# Reference function used for driver's coverage analysis in analyze_outcomes.py
1041# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
1042# Keep in sync with its accelerated counterpart.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001043component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
1044 msg "build: full + non accelerated EC algs"
1045
1046 config_psa_crypto_no_ecp_at_all 0
1047
Ronald Cron401f20f2025-09-02 14:50:10 +02001048 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001049
1050 msg "test: full + non accelerated EC algs"
Ronald Cron401f20f2025-09-02 14:50:10 +02001051 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001052
1053 msg "ssl-opt: full + non accelerated EC algs"
1054 tests/ssl-opt.sh
1055}
1056
1057# This is a common configuration helper used directly from:
1058# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1059# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1060# and indirectly from:
1061# - component_test_psa_crypto_config_accel_ecc_no_bignum
1062# - accelerate all EC algs, disable RSA and FFDH
1063# - component_test_psa_crypto_config_reference_ecc_no_bignum
1064# - this is the reference component of the above
1065# - it still disables RSA and FFDH, but it uses builtin EC algs
1066# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1067# - accelerate all EC and FFDH algs, disable only RSA
1068# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1069# - this is the reference component of the above
1070# - it still disables RSA, but it uses builtin EC and FFDH algs
1071#
1072# This function accepts 2 parameters:
1073# $1: a boolean value which states if we are testing an accelerated scenario
1074# or not.
1075# $2: a string value which states which components are tested. Allowed values
1076# are "ECC" or "ECC_DH".
Minos Galanakisf78447f2024-07-26 20:49:51 +01001077config_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001078 driver_only="$1"
1079 test_target="$2"
1080 # start with full config for maximum coverage (also enables USE_PSA)
1081 helper_libtestdriver1_adjust_config "full"
1082
Minos Galanakis471b34c2024-07-26 15:39:24 +01001083 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1084 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1085 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
David Horstmannb907dbc2025-08-27 15:19:40 +01001086 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +01001087
1088 # RSA support is intentionally disabled on this test because RSA_C depends
1089 # on BIGNUM_C.
David Horstmannb907dbc2025-08-27 15:19:40 +01001090 scripts/config.py unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
1091 scripts/config.py unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001092 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1093 # Also disable key exchanges that depend on RSA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001094 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001095
1096 if [ "$test_target" = "ECC" ]; then
1097 # When testing ECC only, we disable FFDH support, both from builtin and
Valerio Setti8438c632025-01-22 11:56:40 +01001098 # PSA sides.
David Horstmannb907dbc2025-08-27 15:19:40 +01001099 scripts/config.py unset PSA_WANT_ALG_FFDH
1100 scripts/config.py unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
1101 scripts/config.py unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001102 fi
1103
1104 # Restartable feature is not yet supported by PSA. Once it will in
1105 # the future, the following line could be removed (see issues
1106 # 6061, 6332 and following ones)
1107 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1108}
1109
1110# Common helper used by:
1111# - component_test_psa_crypto_config_accel_ecc_no_bignum
1112# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1113#
1114# The goal is to build and test accelerating either:
1115# - ECC only or
1116# - both ECC and FFDH
1117#
1118# It is meant to be used in conjunction with
1119# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
1120# coverage analysis in the "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001121common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1122 test_target="$1"
1123
1124 # This is an internal helper to simplify text message handling
1125 if [ "$test_target" = "ECC_DH" ]; then
1126 accel_text="ECC/FFDH"
1127 removed_text="ECP - DH"
1128 else
1129 accel_text="ECC"
1130 removed_text="ECP"
1131 fi
1132
1133 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1134
Valerio Setti37a42812025-08-11 12:52:49 +02001135 # Configure
1136 # ---------
1137
1138 # Set common configurations between library's and driver's builds
1139 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
1140 # Disable all the builtin curves. All the required algs are accelerated.
1141 helper_disable_builtin_curves
1142
Minos Galanakis471b34c2024-07-26 15:39:24 +01001143 # By default we accelerate all EC keys/algs
1144 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1145 ALG_ECDH \
1146 ALG_JPAKE \
1147 $(helper_get_psa_key_type_list "ECC") \
1148 $(helper_get_psa_curve_list)"
1149 # Optionally we can also add DH to the list of accelerated items
1150 if [ "$test_target" = "ECC_DH" ]; then
1151 loc_accel_list="$loc_accel_list \
1152 ALG_FFDH \
1153 $(helper_get_psa_key_type_list "DH") \
1154 $(helper_get_psa_dh_group_list)"
1155 fi
1156
Minos Galanakis471b34c2024-07-26 15:39:24 +01001157 # Build
1158 # -----
1159
1160 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1161 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1162 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1163 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1164
1165 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1166
1167 helper_libtestdriver1_make_main "$loc_accel_list"
1168
1169 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1170 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1171 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1172 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001173 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001174 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1175 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1176 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001177
1178 # Run the tests
1179 # -------------
1180
Valerio Settieb63eb22025-02-12 13:32:49 +01001181 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001182
Ronald Cron401f20f2025-09-02 14:50:10 +02001183 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001184
1185 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1186 tests/ssl-opt.sh
1187}
1188
1189# Common helper used by:
1190# - component_test_psa_crypto_config_reference_ecc_no_bignum
1191# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1192#
1193# The goal is to build and test a reference scenario (i.e. with builtin
1194# components) compared to the ones used in
1195# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
1196#
1197# It is meant to be used in conjunction with
1198# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
1199# coverage analysis in "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001200common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1201 test_target="$1"
1202
1203 # This is an internal helper to simplify text message handling
1204 if [ "$test_target" = "ECC_DH" ]; then
1205 accel_text="ECC/FFDH"
1206 else
1207 accel_text="ECC"
1208 fi
1209
1210 msg "build: full + non accelerated $accel_text algs + USE_PSA"
1211
1212 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
1213
Ronald Cron401f20f2025-09-02 14:50:10 +02001214 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001215
1216 msg "test suites: full + non accelerated EC algs + USE_PSA"
Ronald Cron401f20f2025-09-02 14:50:10 +02001217 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001218
1219 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
1220 tests/ssl-opt.sh
1221}
1222
1223component_test_psa_crypto_config_accel_ecc_no_bignum () {
1224 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
1225}
1226
1227component_test_psa_crypto_config_reference_ecc_no_bignum () {
1228 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
1229}
1230
1231component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1232 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
1233}
1234
1235component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1236 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
1237}
1238
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001239component_test_tfm_config_as_is () {
1240 msg "build: configs/config-tfm.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +00001241 MBEDTLS_CONFIG="configs/config-tfm.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001242 CRYPTO_CONFIG="tf-psa-crypto/configs/ext/crypto_config_profile_medium.h"
Minos Galanakis4f619e12024-11-14 14:56:47 +00001243 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 +02001244 make
1245
1246 msg "test: configs/config-tfm.h - unit tests"
1247 make test
1248}
1249
Minos Galanakis471b34c2024-07-26 15:39:24 +01001250# Helper for setting common configurations between:
1251# - component_test_tfm_config_p256m_driver_accel_ec()
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001252# - component_test_tfm_config_no_p256m()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001253common_tfm_config () {
1254 # Enable TF-M config
1255 cp configs/config-tfm.h "$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001256 cp tf-psa-crypto/configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001257
Minos Galanakis471b34c2024-07-26 15:39:24 +01001258 # Config adjustment for better test coverage in our environment.
1259 # This is not needed just to build and pass tests.
1260 #
1261 # Enable filesystem I/O for the benefit of PK parse/write tests.
Minos Galanakis5da58e52024-11-07 15:35:33 +00001262 sed -i '/PROFILE_M_PSA_CRYPTO_CONFIG_H/i #define MBEDTLS_FS_IO' "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001263}
1264
1265# Keep this in sync with component_test_tfm_config() as they are both meant
1266# to be used in analyze_outcomes.py for driver's coverage analysis.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001267component_test_tfm_config_p256m_driver_accel_ec () {
1268 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1269
1270 common_tfm_config
1271
1272 # Build crypto library
Ronald Cron401f20f2025-09-02 14:50:10 +02001273 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../framework/tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001274
1275 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1276 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1277 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1278 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001279 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001280 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1281 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001282 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1283 # Check that p256m was built
1284 grep -q p256_ecdsa_ library/libmbedcrypto.a
1285
1286 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1287 # files, so we want to ensure that it has not be re-enabled accidentally.
1288 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1289
1290 # Run the tests
1291 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
Ronald Cron401f20f2025-09-02 14:50:10 +02001292 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001293}
1294
1295# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1296# they are both meant to be used in analyze_outcomes.py for driver's coverage
1297# analysis.
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001298component_test_tfm_config_no_p256m () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001299 common_tfm_config
1300
1301 # Disable P256M driver, which is on by default, so that analyze_outcomes
1302 # can compare this test with test_tfm_config_p256m_driver_accel_ec
Ben Taylora2aa7da2025-09-04 11:22:52 +01001303 scripts/config.py -f "$CRYPTO_CONFIG_H" unset MBEDTLS_PSA_P256M_DRIVER_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001304
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001305 msg "build: TF-M config without p256m"
Ronald Cron401f20f2025-09-02 14:50:10 +02001306 $MAKE_COMMAND CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' tests
Minos Galanakis471b34c2024-07-26 15:39:24 +01001307
1308 # Check that p256m was not built
1309 not grep p256_ecdsa_ library/libmbedcrypto.a
1310
1311 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1312 # files, so we want to ensure that it has not be re-enabled accidentally.
1313 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1314
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001315 msg "test: TF-M config without p256m"
Ronald Cron401f20f2025-09-02 14:50:10 +02001316 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001317}
1318
Minos Galanakis471b34c2024-07-26 15:39:24 +01001319# This is an helper used by:
1320# - component_test_psa_ecc_key_pair_no_derive
1321# - component_test_psa_ecc_key_pair_no_generate
1322# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1323# enabled, but one. Input arguments are as follows:
Gilles Peskinefef912c2024-09-20 16:07:09 +02001324# - $1 is the configuration to start from
1325# - $2 is the key type under test, i.e. ECC/RSA/DH
1326# - $3 is the key option to be unset (i.e. generate, derive, etc)
Minos Galanakisf78447f2024-07-26 20:49:51 +01001327build_and_test_psa_want_key_pair_partial () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001328 base_config=$1
1329 key_type=$2
1330 unset_option=$3
Minos Galanakis471b34c2024-07-26 15:39:24 +01001331 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1332
Gilles Peskinefef912c2024-09-20 16:07:09 +02001333 msg "build: $base_config - ${disabled_psa_want}"
1334 scripts/config.py "$base_config"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001335
1336 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1337 # crypto_config.h so we just disable the one we don't want.
David Horstmannb907dbc2025-08-27 15:19:40 +01001338 scripts/config.py unset "$disabled_psa_want"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001339
Ronald Cron401f20f2025-09-02 14:50:10 +02001340 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001341
Gilles Peskinefef912c2024-09-20 16:07:09 +02001342 msg "test: $base_config - ${disabled_psa_want}"
Ronald Cron401f20f2025-09-02 14:50:10 +02001343 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001344}
1345
Minos Galanakisf78447f2024-07-26 20:49:51 +01001346component_test_psa_ecc_key_pair_no_derive () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001347 build_and_test_psa_want_key_pair_partial full "ECC" "DERIVE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001348}
1349
Minos Galanakisf78447f2024-07-26 20:49:51 +01001350component_test_psa_ecc_key_pair_no_generate () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001351 # TLS needs ECC key generation whenever ephemeral ECDH is enabled.
1352 # We don't have proper guards for configurations with ECC key generation
1353 # disabled (https://github.com/Mbed-TLS/mbedtls/issues/9481). Until
1354 # then (if ever), just test the crypto part of the library.
1355 build_and_test_psa_want_key_pair_partial crypto_full "ECC" "GENERATE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001356}
1357
1358config_psa_crypto_accel_rsa () {
1359 driver_only=$1
1360
1361 # Start from crypto_full config (no X.509, no TLS)
1362 helper_libtestdriver1_adjust_config "crypto_full"
1363
1364 if [ "$driver_only" -eq 1 ]; then
Minos Galanakis471b34c2024-07-26 15:39:24 +01001365 # We need PEM parsing in the test library as well to support the import
1366 # of PEM encoded RSA keys.
Minos Galanakis23452f52024-11-28 17:48:14 +00001367 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1368 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
Minos Galanakis471b34c2024-07-26 15:39:24 +01001369 fi
1370}
1371
1372component_test_psa_crypto_config_accel_rsa_crypto () {
1373 msg "build: crypto_full with accelerated RSA"
1374
1375 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1376 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1377 KEY_TYPE_RSA_PUBLIC_KEY \
1378 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1379 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1380 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1381 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1382
1383 # Configure
1384 # ---------
1385
1386 config_psa_crypto_accel_rsa 1
1387
1388 # Build
1389 # -----
1390
1391 # These hashes are needed for unit tests.
1392 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1393 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1394 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1395
1396 helper_libtestdriver1_make_main "$loc_accel_list"
1397
1398 # Make sure this was not re-enabled by accident (additive config)
1399 not grep mbedtls_rsa ${BUILTIN_SRC_PATH}/rsa.o
1400
1401 # Run the tests
1402 # -------------
1403
1404 msg "test: crypto_full with accelerated RSA"
Ronald Cron401f20f2025-09-02 14:50:10 +02001405 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001406}
1407
1408component_test_psa_crypto_config_reference_rsa_crypto () {
1409 msg "build: crypto_full with non-accelerated RSA"
1410
1411 # Configure
1412 # ---------
1413 config_psa_crypto_accel_rsa 0
1414
1415 # Build
1416 # -----
Ronald Cron401f20f2025-09-02 14:50:10 +02001417 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001418
1419 # Run the tests
1420 # -------------
1421 msg "test: crypto_full with non-accelerated RSA"
Ronald Cron401f20f2025-09-02 14:50:10 +02001422 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001423}
1424
1425# This is a temporary test to verify that full RSA support is present even when
1426# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001427component_test_new_psa_want_key_pair_symbol () {
Ronald Cron892bb612025-07-21 14:26:27 +02001428 msg "Build: crypto config - PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001429
1430 # Create a temporary output file unless there is already one set
1431 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1432 REMOVE_OUTCOME_ON_EXIT="no"
1433 else
1434 REMOVE_OUTCOME_ON_EXIT="yes"
1435 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1436 export MBEDTLS_TEST_OUTCOME_FILE
1437 fi
1438
1439 # Start from crypto configuration
1440 scripts/config.py crypto
1441
Ronald Cron919a1e42025-09-15 14:39:26 +02001442 # Remove RSA dependencies
Minos Galanakis471b34c2024-07-26 15:39:24 +01001443 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001444 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1445
Minos Galanakis471b34c2024-07-26 15:39:24 +01001446 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
1447 # that proper translations is done in crypto_legacy.h.
David Horstmannb907dbc2025-08-27 15:19:40 +01001448 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
1449 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
1450 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Minos Galanakis471b34c2024-07-26 15:39:24 +01001451
Ronald Cron401f20f2025-09-02 14:50:10 +02001452 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001453
Ronald Cron892bb612025-07-21 14:26:27 +02001454 msg "Test: crypto config - PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Ronald Cron401f20f2025-09-02 14:50:10 +02001455 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001456
1457 # Parse only 1 relevant line from the outcome file, i.e. a test which is
1458 # performing RSA signature.
1459 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
1460 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
1461
1462 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
1463 rm $MBEDTLS_TEST_OUTCOME_FILE
1464 fi
1465}
1466
1467component_test_psa_crypto_config_accel_hash () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001468 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001469
1470 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1471 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1472 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1473
1474 # Configure
1475 # ---------
1476
1477 # Start from default config (no USE_PSA)
1478 helper_libtestdriver1_adjust_config "default"
1479
Minos Galanakis471b34c2024-07-26 15:39:24 +01001480 # Build
1481 # -----
1482
1483 helper_libtestdriver1_make_drivers "$loc_accel_list"
1484
1485 helper_libtestdriver1_make_main "$loc_accel_list"
1486
1487 # There's a risk of something getting re-enabled via config_psa.h;
1488 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1489 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1490 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1491 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1492 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1493 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1494
1495 # Run the tests
1496 # -------------
1497
Ronald Cron93ba6252024-09-05 10:37:14 +02001498 msg "test: accelerated hash"
Ronald Cron401f20f2025-09-02 14:50:10 +02001499 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001500}
1501
1502# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001503config_psa_crypto_hash_use_psa () {
1504 driver_only="$1"
1505 # start with config full for maximum coverage (also enables USE_PSA)
1506 helper_libtestdriver1_adjust_config "full"
1507 if [ "$driver_only" -eq 1 ]; then
1508 # disable the built-in implementation of hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +01001509 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Minos Galanakis471b34c2024-07-26 15:39:24 +01001510 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Minos Galanakis471b34c2024-07-26 15:39:24 +01001511 fi
1512}
1513
1514# Note that component_test_psa_crypto_config_reference_hash_use_psa
1515# is related to this component and both components need to be kept in sync.
1516# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001517component_test_psa_crypto_config_accel_hash_use_psa () {
1518 msg "test: full with accelerated hashes"
1519
1520 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1521 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1522 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1523
1524 # Configure
1525 # ---------
1526
1527 config_psa_crypto_hash_use_psa 1
1528
1529 # Build
1530 # -----
1531
1532 helper_libtestdriver1_make_drivers "$loc_accel_list"
1533
1534 helper_libtestdriver1_make_main "$loc_accel_list"
1535
1536 # There's a risk of something getting re-enabled via config_psa.h;
1537 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1538 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1539 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1540 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1541 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1542 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1543
1544 # Run the tests
1545 # -------------
1546
1547 msg "test: full with accelerated hashes"
Ronald Cron401f20f2025-09-02 14:50:10 +02001548 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001549
1550 # This is mostly useful so that we can later compare outcome files with
1551 # the reference config in analyze_outcomes.py, to check that the
1552 # dependency declarations in ssl-opt.sh and in TLS code are correct.
1553 msg "test: ssl-opt.sh, full with accelerated hashes"
1554 tests/ssl-opt.sh
1555
1556 # This is to make sure all ciphersuites are exercised, but we don't need
1557 # interop testing (besides, we already got some from ssl-opt.sh).
1558 msg "test: compat.sh, full with accelerated hashes"
1559 tests/compat.sh -p mbedTLS -V YES
1560}
1561
1562# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
1563# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
1564# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
1565# Both components need to be kept in sync.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001566component_test_psa_crypto_config_reference_hash_use_psa () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001567 msg "test: full without accelerated hashes"
1568
1569 config_psa_crypto_hash_use_psa 0
1570
Ronald Cron401f20f2025-09-02 14:50:10 +02001571 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001572
1573 msg "test: full without accelerated hashes"
Ronald Cron401f20f2025-09-02 14:50:10 +02001574 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001575
1576 msg "test: ssl-opt.sh, full without accelerated hashes"
1577 tests/ssl-opt.sh
1578}
1579
1580# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001581config_psa_crypto_hmac_use_psa () {
1582 driver_only="$1"
1583 # start with config full for maximum coverage (also enables USE_PSA)
1584 helper_libtestdriver1_adjust_config "full"
1585
1586 if [ "$driver_only" -eq 1 ]; then
1587 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
1588 # is still enabled though (for ENTROPY_C among others).
1589 scripts/config.py unset MBEDTLS_MD_C
Ronald Cron772a8ad2025-07-21 12:36:29 +02001590 # Also disable the configuration options that tune the builtin hashes,
1591 # since those hashes are disabled.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001592 scripts/config.py unset-all MBEDTLS_SHA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001593 fi
1594
1595 # Direct dependencies of MD_C. We disable them also in the reference
1596 # component to work with the same set of features.
1597 scripts/config.py unset MBEDTLS_PKCS7_C
1598 scripts/config.py unset MBEDTLS_PKCS5_C
1599 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1600 scripts/config.py unset MBEDTLS_HKDF_C
1601 # Dependencies of HMAC_DRBG
David Horstmannb907dbc2025-08-27 15:19:40 +01001602 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001603}
1604
Minos Galanakisf78447f2024-07-26 20:49:51 +01001605component_test_psa_crypto_config_accel_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001606 msg "test: full with accelerated hmac"
1607
1608 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
1609 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1610 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1611 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1612
1613 # Configure
1614 # ---------
1615
1616 config_psa_crypto_hmac_use_psa 1
1617
1618 # Build
1619 # -----
1620
1621 helper_libtestdriver1_make_drivers "$loc_accel_list"
1622
1623 helper_libtestdriver1_make_main "$loc_accel_list"
1624
1625 # Ensure that built-in support for HMAC is disabled.
1626 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
1627
1628 # Run the tests
1629 # -------------
1630
1631 msg "test: full with accelerated hmac"
Ronald Cron401f20f2025-09-02 14:50:10 +02001632 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001633}
1634
Minos Galanakisf78447f2024-07-26 20:49:51 +01001635component_test_psa_crypto_config_reference_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001636 msg "test: full without accelerated hmac"
1637
1638 config_psa_crypto_hmac_use_psa 0
1639
Ronald Cron401f20f2025-09-02 14:50:10 +02001640 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001641
1642 msg "test: full without accelerated hmac"
Ronald Cron401f20f2025-09-02 14:50:10 +02001643 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001644}
1645
Minos Galanakis471b34c2024-07-26 15:39:24 +01001646component_test_psa_crypto_config_accel_aead () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001647 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001648
1649 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
1650 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1651
1652 # Configure
1653 # ---------
1654
1655 # Start from full config
1656 helper_libtestdriver1_adjust_config "full"
1657
Minos Galanakis471b34c2024-07-26 15:39:24 +01001658 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
David Horstmannb907dbc2025-08-27 15:19:40 +01001659 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
Minos Galanakis471b34c2024-07-26 15:39:24 +01001660
1661 # Build
1662 # -----
1663
1664 helper_libtestdriver1_make_drivers "$loc_accel_list"
1665
1666 helper_libtestdriver1_make_main "$loc_accel_list"
1667
1668 # Make sure this was not re-enabled by accident (additive config)
1669 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1670 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1671 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1672
1673 # Run the tests
1674 # -------------
1675
Ronald Cron93ba6252024-09-05 10:37:14 +02001676 msg "test: accelerated AEAD"
Ronald Cron401f20f2025-09-02 14:50:10 +02001677 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001678}
1679
1680# This is a common configuration function used in:
1681# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1682# - component_test_psa_crypto_config_reference_cipher_aead_cmac
Minos Galanakisf78447f2024-07-26 20:49:51 +01001683common_psa_crypto_config_accel_cipher_aead_cmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001684 # Start from the full config
1685 helper_libtestdriver1_adjust_config "full"
1686
1687 scripts/config.py unset MBEDTLS_NIST_KW_C
1688}
1689
1690# The 2 following test components, i.e.
1691# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1692# - component_test_psa_crypto_config_reference_cipher_aead_cmac
1693# are meant to be used together in analyze_outcomes.py script in order to test
1694# driver's coverage for ciphers and AEADs.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001695component_test_psa_crypto_config_accel_cipher_aead_cmac () {
1696 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
1697
1698 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
1699 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
1700 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
Ari Weiler-Ofek86422e52025-07-04 14:43:30 +01001701 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001702
1703 # Configure
1704 # ---------
1705
1706 common_psa_crypto_config_accel_cipher_aead_cmac
1707
Minos Galanakis471b34c2024-07-26 15:39:24 +01001708 # Build
1709 # -----
1710
1711 helper_libtestdriver1_make_drivers "$loc_accel_list"
1712
1713 helper_libtestdriver1_make_main "$loc_accel_list"
1714
1715 # Make sure this was not re-enabled by accident (additive config)
1716 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001717 not grep mbedtls_aes ${BUILTIN_SRC_PATH}/aes.o
1718 not grep mbedtls_aria ${BUILTIN_SRC_PATH}/aria.o
1719 not grep mbedtls_camellia ${BUILTIN_SRC_PATH}/camellia.o
1720 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1721 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1722 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1723 not grep mbedtls_cmac ${BUILTIN_SRC_PATH}/cmac.o
Ronald Cronb5c6fcc2025-07-10 13:40:00 +02001724 not grep mbedtls_poly1305 ${BUILTIN_SRC_PATH}/poly1305.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001725
1726 # Run the tests
1727 # -------------
1728
1729 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
Ronald Cron401f20f2025-09-02 14:50:10 +02001730 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001731
1732 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
Ronald Cronbd28acf2025-07-10 09:53:50 +02001733 # Exclude password-protected key tests — they require built-in CBC and AES.
1734 tests/ssl-opt.sh -e "TLS: password protected"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001735
1736 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
1737 tests/compat.sh -V NO -p mbedTLS
1738}
1739
1740component_test_psa_crypto_config_reference_cipher_aead_cmac () {
1741 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
1742 common_psa_crypto_config_accel_cipher_aead_cmac
1743
Ronald Cron401f20f2025-09-02 14:50:10 +02001744 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001745
1746 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
Ronald Cron401f20f2025-09-02 14:50:10 +02001747 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001748
1749 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
Ronald Cronbd28acf2025-07-10 09:53:50 +02001750 # Exclude password-protected key tests as in test_psa_crypto_config_accel_cipher_aead_cmac.
1751 tests/ssl-opt.sh -e "TLS: password protected"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001752
1753 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
1754 tests/compat.sh -V NO -p mbedTLS
1755}
1756
Minos Galanakisf78447f2024-07-26 20:49:51 +01001757common_block_cipher_dispatch () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001758 TEST_WITH_DRIVER="$1"
1759
1760 # Start from the full config
1761 helper_libtestdriver1_adjust_config "full"
1762
Minos Galanakis471b34c2024-07-26 15:39:24 +01001763 # Disable cipher's modes that, when not accelerated, cause
1764 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
1765 # Keep this also in the reference component in order to skip the same tests
1766 # that were skipped in the accelerated one.
David Horstmannb907dbc2025-08-27 15:19:40 +01001767 scripts/config.py unset PSA_WANT_ALG_CTR
1768 scripts/config.py unset PSA_WANT_ALG_CFB
1769 scripts/config.py unset PSA_WANT_ALG_OFB
1770 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
1771 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
1772 scripts/config.py unset PSA_WANT_ALG_CMAC
1773 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1774 scripts/config.py unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
Minos Galanakis471b34c2024-07-26 15:39:24 +01001775
1776 # Disable direct dependency on AES_C
1777 scripts/config.py unset MBEDTLS_NIST_KW_C
1778
1779 # Prevent the cipher module from using deprecated PSA path. The reason is
1780 # that otherwise there will be tests relying on "aes_info" (defined in
1781 # "cipher_wrap.c") whose functions are not available when AES_C is
1782 # not defined. ARIA and Camellia are not a problem in this case because
1783 # the PSA path is not tested for these key types.
1784 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1785}
1786
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02001787component_test_full_block_cipher_psa_dispatch_static_keystore () {
1788 msg "build: full + PSA dispatch in block_cipher with static keystore"
1789 # Check that the static key store works well when CTR_DRBG uses a
1790 # PSA key for AES.
1791 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
1792
1793 loc_accel_list="ALG_ECB_NO_PADDING \
1794 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1795
1796 # Configure
1797 # ---------
1798
1799 common_block_cipher_dispatch 1
1800
1801 # Build
1802 # -----
1803
1804 helper_libtestdriver1_make_drivers "$loc_accel_list"
1805
1806 helper_libtestdriver1_make_main "$loc_accel_list"
1807
1808 # Make sure disabled components were not re-enabled by accident (additive
1809 # config)
1810 not grep mbedtls_aes_ library/aes.o
1811 not grep mbedtls_aria_ library/aria.o
1812 not grep mbedtls_camellia_ library/camellia.o
1813
1814 # Run the tests
1815 # -------------
1816
1817 msg "test: full + PSA dispatch in block_cipher with static keystore"
Ronald Cron401f20f2025-09-02 14:50:10 +02001818 $MAKE_COMMAND test
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02001819}
1820
Minos Galanakis471b34c2024-07-26 15:39:24 +01001821component_test_full_block_cipher_psa_dispatch () {
1822 msg "build: full + PSA dispatch in block_cipher"
1823
1824 loc_accel_list="ALG_ECB_NO_PADDING \
1825 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1826
1827 # Configure
1828 # ---------
1829
1830 common_block_cipher_dispatch 1
1831
1832 # Build
1833 # -----
1834
1835 helper_libtestdriver1_make_drivers "$loc_accel_list"
1836
1837 helper_libtestdriver1_make_main "$loc_accel_list"
1838
1839 # Make sure disabled components were not re-enabled by accident (additive
1840 # config)
1841 not grep mbedtls_aes_ ${BUILTIN_SRC_PATH}/aes.o
1842 not grep mbedtls_aria_ ${BUILTIN_SRC_PATH}/aria.o
1843 not grep mbedtls_camellia_ ${BUILTIN_SRC_PATH}/camellia.o
1844
1845 # Run the tests
1846 # -------------
1847
1848 msg "test: full + PSA dispatch in block_cipher"
Ronald Cron401f20f2025-09-02 14:50:10 +02001849 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001850}
1851
1852# This is the reference component of component_test_full_block_cipher_psa_dispatch
Minos Galanakis471b34c2024-07-26 15:39:24 +01001853component_test_full_block_cipher_legacy_dispatch () {
1854 msg "build: full + legacy dispatch in block_cipher"
1855
1856 common_block_cipher_dispatch 0
1857
Ronald Cron401f20f2025-09-02 14:50:10 +02001858 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001859
1860 msg "test: full + legacy dispatch in block_cipher"
Ronald Cron401f20f2025-09-02 14:50:10 +02001861 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001862}
1863
Minos Galanakisf78447f2024-07-26 20:49:51 +01001864component_test_aead_chachapoly_disabled () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001865 msg "build: full minus CHACHAPOLY"
1866 scripts/config.py full
David Horstmannb907dbc2025-08-27 15:19:40 +01001867 scripts/config.py unset PSA_WANT_ALG_CHACHA20_POLY1305
Ronald Cron401f20f2025-09-02 14:50:10 +02001868 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001869
1870 msg "test: full minus CHACHAPOLY"
Ronald Cron401f20f2025-09-02 14:50:10 +02001871 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001872}
1873
Minos Galanakisf78447f2024-07-26 20:49:51 +01001874component_test_aead_only_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001875 msg "build: full minus CHACHAPOLY and GCM"
1876 scripts/config.py full
David Horstmannb907dbc2025-08-27 15:19:40 +01001877 scripts/config.py unset PSA_WANT_ALG_CHACHA20_POLY1305
1878 scripts/config.py unset PSA_WANT_ALG_GCM
Ronald Cron401f20f2025-09-02 14:50:10 +02001879 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001880
1881 msg "test: full minus CHACHAPOLY and GCM"
Ronald Cron401f20f2025-09-02 14:50:10 +02001882 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001883}
1884
Minos Galanakisf78447f2024-07-26 20:49:51 +01001885component_test_ccm_aes_sha256 () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001886 msg "build: CCM + AES + SHA256 configuration"
1887
Minos Galanakisa17ffc72024-12-02 23:57:30 +00001888 # Setting a blank config disables everyhing in the library side.
1889 echo '#define MBEDTLS_CONFIG_H ' >"$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001890 cp tf-psa-crypto/configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
Ronald Cron9d262d72024-12-06 17:41:26 +01001891
Ronald Cron401f20f2025-09-02 14:50:10 +02001892 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001893 msg "test: CCM + AES + SHA256 configuration"
Ronald Cron401f20f2025-09-02 14:50:10 +02001894 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001895}
1896
1897# Test that the given .o file builds with all (valid) combinations of the given options.
1898#
1899# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
1900#
1901# The validator function is the name of a function to validate the combination of options.
1902# It may be "" if all combinations are valid.
1903# It receives a string containing a combination of options, as passed to the compiler,
1904# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001905build_test_config_combos () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001906 file=$1
1907 shift
1908 validate_options=$1
1909 shift
1910 options=("$@")
1911
1912 # clear all of the options so that they can be overridden on the clang commandline
1913 for opt in "${options[@]}"; do
1914 ./scripts/config.py unset ${opt}
1915 done
1916
1917 # enter the library directory
1918 cd library
1919
1920 # The most common issue is unused variables/functions, so ensure -Wunused is set.
1921 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
1922
1923 # Extract the command generated by the Makefile to build the target file.
1924 # This ensures that we have any include paths, macro definitions, etc
1925 # that may be applied by make.
1926 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
1927 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
1928
1929 makefile=$(TMPDIR=. mktemp)
1930 deps=""
1931
1932 len=${#options[@]}
1933 source_file=../${file%.o}.c
1934
1935 targets=0
1936 echo 'include Makefile' >${makefile}
1937
1938 for ((i = 0; i < $((2**${len})); i++)); do
1939 # generate each of 2^n combinations of options
1940 # each bit of $i is used to determine if options[i] will be set or not
1941 target="t"
1942 clang_args=""
1943 for ((j = 0; j < ${len}; j++)); do
1944 if (((i >> j) & 1)); then
1945 opt=-D${options[$j]}
1946 clang_args="${clang_args} ${opt}"
1947 target="${target}${opt}"
1948 fi
1949 done
1950
1951 # if combination is not known to be invalid, add it to the makefile
1952 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
1953 cmd="${compile_cmd} ${clang_args}"
1954 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
1955
1956 deps="${deps} ${target}"
1957 ((++targets))
1958 fi
1959 done
1960
1961 echo "build_test_config_combos: ${deps}" >> ${makefile}
1962
1963 # execute all of the commands via Make (probably in parallel)
1964 make -s -f ${makefile} build_test_config_combos
1965 echo "$targets targets checked"
1966
1967 # clean up the temporary makefile
1968 rm ${makefile}
1969}
1970
Minos Galanakisf78447f2024-07-26 20:49:51 +01001971validate_aes_config_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001972 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
1973 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
1974 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
1975 return 1
1976 fi
1977 fi
1978 return 0
1979}
1980
Minos Galanakisf78447f2024-07-26 20:49:51 +01001981component_build_aes_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001982 # 18s - around 90ms per clang invocation on M1 Pro
1983 #
1984 # aes.o has many #if defined(...) guards that intersect in complex ways.
1985 # Test that all the combinations build cleanly.
1986
1987 MBEDTLS_ROOT_DIR="$PWD"
1988 msg "build: aes.o for all combinations of relevant config options"
1989
1990 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01001991 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01001992 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
1993 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
1994
1995 cd "$MBEDTLS_ROOT_DIR"
1996 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
1997
Ari Weiler-Ofek86422e52025-07-04 14:43:30 +01001998 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW,
Minos Galanakis471b34c2024-07-26 15:39:24 +01001999 # manually set or unset those configurations to check
2000 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
2001 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Minos Galanakis471b34c2024-07-26 15:39:24 +01002002 scripts/config.py unset MBEDTLS_NIST_KW_C
Ronald Cron54d1eec2024-09-06 09:55:38 +02002003
David Horstmann7cbeedc2025-08-26 17:26:45 +01002004 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
2005 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
2006 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
Ronald Cron54d1eec2024-09-06 09:55:38 +02002007
Minos Galanakis471b34c2024-07-26 15:39:24 +01002008 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002009 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002010 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2011 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2012}
2013
Minos Galanakisf78447f2024-07-26 20:49:51 +01002014component_test_sha3_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002015 msg "sha3 loop unroll variations"
2016
2017 # define minimal config sufficient to test SHA3
Ronald Crone7f289e2024-09-06 11:02:47 +02002018 cat > include/mbedtls/mbedtls_config.h << END
Ronald Crone7f289e2024-09-06 11:02:47 +02002019END
2020
2021 cat > tf-psa-crypto/include/psa/crypto_config.h << END
2022 #define PSA_WANT_ALG_SHA_256 1
2023 #define PSA_WANT_ALG_SHA3_224 1
2024 #define PSA_WANT_ALG_SHA3_256 1
2025 #define PSA_WANT_ALG_SHA3_384 1
2026 #define PSA_WANT_ALG_SHA3_512 1
Ronald Cron06680362025-07-21 15:21:22 +02002027 #define PSA_WANT_KEY_TYPE_AES 1
Ronald Cron3dd1d3d2024-12-05 15:12:06 +01002028 #define MBEDTLS_PSA_CRYPTO_C
Ronald Cron3b306432025-09-02 18:30:08 +02002029 #define MBEDTLS_CTR_DRBG_C
2030 #define MBEDTLS_PSA_BUILTIN_GET_ENTROPY
Ronald Cron3dd1d3d2024-12-05 15:12:06 +01002031 #define MBEDTLS_SELF_TEST
Minos Galanakis471b34c2024-07-26 15:39:24 +01002032END
2033
2034 msg "all loops unrolled"
Ronald Cron401f20f2025-09-02 14:50:10 +02002035 $MAKE_COMMAND clean
Minos Galanakis471b34c2024-07-26 15:39:24 +01002036 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"
2037 ./tf-psa-crypto/tests/test_suite_shax
2038
2039 msg "all loops rolled up"
Ronald Cron401f20f2025-09-02 14:50:10 +02002040 $MAKE_COMMAND clean
Minos Galanakis471b34c2024-07-26 15:39:24 +01002041 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"
2042 ./tf-psa-crypto/tests/test_suite_shax
2043}
2044
Minos Galanakisf699d512024-08-01 11:32:30 +01002045support_build_aes_aesce_armcc () {
2046 support_build_armcc
2047}
2048
Minos Galanakis471b34c2024-07-26 15:39:24 +01002049# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2050component_build_aes_aesce_armcc () {
2051 msg "Build: AESCE test on arm64 platform without plain C."
2052 scripts/config.py baremetal
2053
2054 # armc[56] don't support SHA-512 intrinsics
2055 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2056
2057 # Stop armclang warning about feature detection for A64_CRYPTO.
2058 # With this enabled, the library does build correctly under armclang,
2059 # but in baremetal builds (as tested here), feature detection is
2060 # unavailable, and the user is notified via a #warning. So enabling
2061 # this feature would prevent us from building with -Werror on
2062 # armclang. Tracked in #7198.
2063 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2064 scripts/config.py set MBEDTLS_HAVE_ASM
2065
2066 msg "AESCE, build with default configuration."
2067 scripts/config.py set MBEDTLS_AESCE_C
2068 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002069 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002070
2071 msg "AESCE, build AESCE only"
2072 scripts/config.py set MBEDTLS_AESCE_C
2073 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002074 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002075}
2076
Minos Galanakis471b34c2024-07-26 15:39:24 +01002077component_test_aes_only_128_bit_keys () {
2078 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2079 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002080 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002081
Ronald Cron401f20f2025-09-02 14:50:10 +02002082 $MAKE_COMMAND CFLAGS='-O2 -Werror -Wall -Wextra'
Minos Galanakis471b34c2024-07-26 15:39:24 +01002083
2084 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
Ronald Cron401f20f2025-09-02 14:50:10 +02002085 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002086}
2087
2088component_test_no_ctr_drbg_aes_only_128_bit_keys () {
2089 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2090 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002091 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002092 scripts/config.py unset MBEDTLS_CTR_DRBG_C
2093
Ronald Cron401f20f2025-09-02 14:50:10 +02002094 $MAKE_COMMAND CC=clang CFLAGS='-Werror -Wall -Wextra'
Minos Galanakis471b34c2024-07-26 15:39:24 +01002095
2096 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
Ronald Cron401f20f2025-09-02 14:50:10 +02002097 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002098}
2099
2100component_test_aes_only_128_bit_keys_have_builtins () {
2101 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2102 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002103 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002104 scripts/config.py unset MBEDTLS_AESNI_C
2105 scripts/config.py unset MBEDTLS_AESCE_C
2106
Ronald Cron401f20f2025-09-02 14:50:10 +02002107 $MAKE_COMMAND CFLAGS='-O2 -Werror -Wall -Wextra'
Minos Galanakis471b34c2024-07-26 15:39:24 +01002108
2109 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
Ronald Cron401f20f2025-09-02 14:50:10 +02002110 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002111
2112 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2113 programs/test/selftest
2114}
2115
2116component_test_gcm_largetable () {
2117 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2118 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
2119 scripts/config.py unset MBEDTLS_AESNI_C
2120 scripts/config.py unset MBEDTLS_AESCE_C
2121
Ronald Cron401f20f2025-09-02 14:50:10 +02002122 $MAKE_COMMAND CFLAGS='-O2 -Werror -Wall -Wextra'
Minos Galanakis471b34c2024-07-26 15:39:24 +01002123
2124 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
Ronald Cron401f20f2025-09-02 14:50:10 +02002125 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002126}
2127
2128component_test_aes_fewer_tables () {
2129 msg "build: default config with AES_FEWER_TABLES enabled"
2130 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Ronald Cron401f20f2025-09-02 14:50:10 +02002131 $MAKE_COMMAND CFLAGS='-O2 -Werror -Wall -Wextra'
Minos Galanakis471b34c2024-07-26 15:39:24 +01002132
2133 msg "test: AES_FEWER_TABLES"
Ronald Cron401f20f2025-09-02 14:50:10 +02002134 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002135}
2136
2137component_test_aes_rom_tables () {
2138 msg "build: default config with AES_ROM_TABLES enabled"
2139 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Ronald Cron401f20f2025-09-02 14:50:10 +02002140 $MAKE_COMMAND CFLAGS='-O2 -Werror -Wall -Wextra'
Minos Galanakis471b34c2024-07-26 15:39:24 +01002141
2142 msg "test: AES_ROM_TABLES"
Ronald Cron401f20f2025-09-02 14:50:10 +02002143 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002144}
2145
2146component_test_aes_fewer_tables_and_rom_tables () {
2147 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
2148 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2149 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Ronald Cron401f20f2025-09-02 14:50:10 +02002150 $MAKE_COMMAND CFLAGS='-O2 -Werror -Wall -Wextra'
Minos Galanakis471b34c2024-07-26 15:39:24 +01002151
2152 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
Ronald Cron401f20f2025-09-02 14:50:10 +02002153 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002154}
2155
Ronald Cron66040472024-09-06 10:14:38 +02002156# helper for component_test_block_cipher_no_decrypt_aesni() which:
Minos Galanakis471b34c2024-07-26 15:39:24 +01002157# - enable/disable the list of config options passed from -s/-u respectively.
2158# - build
2159# - test for tests_suite_xxx
2160# - selftest
2161#
2162# Usage: helper_block_cipher_no_decrypt_build_test
2163# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
2164# Options: -s set_opts the list of config options to enable
2165# -u unset_opts the list of config options to disable
2166# -c cflags the list of options passed to CFLAGS
2167# -l ldflags the list of options passed to LDFLAGS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002168helper_block_cipher_no_decrypt_build_test () {
2169 while [ $# -gt 0 ]; do
2170 case "$1" in
2171 -s)
2172 shift; local set_opts="$1";;
2173 -u)
2174 shift; local unset_opts="$1";;
2175 -c)
2176 shift; local cflags="-Werror -Wall -Wextra $1";;
2177 -l)
2178 shift; local ldflags="$1";;
2179 esac
2180 shift
2181 done
2182 set_opts="${set_opts:-}"
2183 unset_opts="${unset_opts:-}"
2184 cflags="${cflags:-}"
2185 ldflags="${ldflags:-}"
2186
2187 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
2188 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
2189
2190 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
Ronald Cron401f20f2025-09-02 14:50:10 +02002191 $MAKE_COMMAND clean
2192 $MAKE_COMMAND CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002193
2194 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2195 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2196 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2197 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2198 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2199 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2200 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
2201 not grep mbedtls_aesni_inverse_key ${BUILTIN_SRC_PATH}/aesni.o
2202
2203 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
Ronald Cron401f20f2025-09-02 14:50:10 +02002204 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002205
2206 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2207 programs/test/selftest
2208}
2209
Ronald Cron66040472024-09-06 10:14:38 +02002210# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
2211config_block_cipher_no_decrypt () {
2212 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Ronald Cron66040472024-09-06 10:14:38 +02002213 scripts/config.py unset MBEDTLS_NIST_KW_C
2214
2215 # Enable support for cryptographic mechanisms through the PSA API.
2216 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
David Horstmannb907dbc2025-08-27 15:19:40 +01002217 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
2218 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
2219 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
Ronald Cron66040472024-09-06 10:14:38 +02002220}
2221
2222component_test_block_cipher_no_decrypt_aesni () {
2223 # Test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics, AESNI assembly and
2224 # AES C implementation on x86_64 and with AESNI intrinsics on x86.
2225
2226 # This consistently causes an llvm crash on clang 3.8, so use gcc
2227 export CC=gcc
2228 config_block_cipher_no_decrypt
2229
Minos Galanakis471b34c2024-07-26 15:39:24 +01002230 # test AESNI intrinsics
2231 helper_block_cipher_no_decrypt_build_test \
2232 -s "MBEDTLS_AESNI_C" \
2233 -c "-mpclmul -msse2 -maes"
2234
2235 # test AESNI assembly
2236 helper_block_cipher_no_decrypt_build_test \
2237 -s "MBEDTLS_AESNI_C" \
2238 -c "-mno-pclmul -mno-sse2 -mno-aes"
2239
2240 # test AES C implementation
2241 helper_block_cipher_no_decrypt_build_test \
2242 -u "MBEDTLS_AESNI_C"
2243
2244 # test AESNI intrinsics for i386 target
2245 helper_block_cipher_no_decrypt_build_test \
2246 -s "MBEDTLS_AESNI_C" \
2247 -c "-m32 -mpclmul -msse2 -maes" \
2248 -l "-m32"
2249}
2250
Minos Galanakisf699d512024-08-01 11:32:30 +01002251support_test_block_cipher_no_decrypt_aesce_armcc () {
2252 support_build_armcc
2253}
2254
Minos Galanakis471b34c2024-07-26 15:39:24 +01002255component_test_block_cipher_no_decrypt_aesce_armcc () {
2256 scripts/config.py baremetal
2257
2258 # armc[56] don't support SHA-512 intrinsics
2259 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2260
2261 # Stop armclang warning about feature detection for A64_CRYPTO.
2262 # With this enabled, the library does build correctly under armclang,
2263 # but in baremetal builds (as tested here), feature detection is
2264 # unavailable, and the user is notified via a #warning. So enabling
2265 # this feature would prevent us from building with -Werror on
2266 # armclang. Tracked in #7198.
2267 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2268 scripts/config.py set MBEDTLS_HAVE_ASM
2269
Ronald Cron66040472024-09-06 10:14:38 +02002270 config_block_cipher_no_decrypt
Minos Galanakis471b34c2024-07-26 15:39:24 +01002271
2272 # test AESCE baremetal build
2273 scripts/config.py set MBEDTLS_AESCE_C
2274 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002275 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002276
2277 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2278 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2279 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2280 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2281 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2282 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2283 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
2284 not grep mbedtls_aesce_inverse_key ${BUILTIN_SRC_PATH}/aesce.o
2285 not grep aesce_decrypt_block ${BUILTIN_SRC_PATH}/aesce.o
2286}
2287
Ronald Cronaad5f1b2025-08-25 15:32:48 +02002288component_test_ctr_drbg_aes_256_sha_512 () {
2289 msg "build: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512 (ASan build)"
2290 scripts/config.py full
2291 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2292 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512
2293 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2294 make
2295
2296 msg "test: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512 (ASan build)"
2297 make test
2298}
2299
Minos Galanakis471b34c2024-07-26 15:39:24 +01002300component_test_ctr_drbg_aes_256_sha_256 () {
Minos Galanakisf3486e12025-08-18 14:09:26 +01002301 msg "build: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002302 scripts/config.py full
2303 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakisf3486e12025-08-18 14:09:26 +01002304 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256
Minos Galanakis471b34c2024-07-26 15:39:24 +01002305 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2306 make
2307
Minos Galanakisf3486e12025-08-18 14:09:26 +01002308 msg "test: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002309 make test
2310}
2311
2312component_test_ctr_drbg_aes_128_sha_512 () {
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002313 msg "build: full + set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002314 scripts/config.py full
2315 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002316 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Ronald Cronaad5f1b2025-08-25 15:32:48 +02002317 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512
Minos Galanakis471b34c2024-07-26 15:39:24 +01002318 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2319 make
2320
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002321 msg "test: full + set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002322 make test
2323}
2324
2325component_test_ctr_drbg_aes_128_sha_256 () {
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002326 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 +01002327 scripts/config.py full
2328 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002329 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakisf3486e12025-08-18 14:09:26 +01002330 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256
Minos Galanakis471b34c2024-07-26 15:39:24 +01002331 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2332 make
2333
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002334 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 +01002335 make test
2336}
2337
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002338component_test_full_static_keystore () {
2339 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2340 scripts/config.py full
2341 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
Ronald Cron401f20f2025-09-02 14:50:10 +02002342 $MAKE_COMMAND CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002343
2344 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
Ronald Cron401f20f2025-09-02 14:50:10 +02002345 $MAKE_COMMAND test
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002346}
2347
Minos Galanakis471b34c2024-07-26 15:39:24 +01002348component_test_psa_crypto_drivers () {
Ronald Crona0afbfb2024-10-15 13:20:31 +02002349 # Test dispatch to drivers and fallbacks with
2350 # test_suite_psa_crypto_driver_wrappers test suite. The test drivers that
2351 # are wrappers around the builtin drivers are activated by
2352 # PSA_CRYPTO_DRIVER_TEST.
2353 #
2354 # For the time being, some test cases in test_suite_block_cipher and
2355 # test_suite_md.psa rely on this component to be run at least once by the
2356 # CI. This should disappear as we progress the 4.x work. See
2357 # config_adjust_test_accelerators.h for more information.
Minos Galanakis471b34c2024-07-26 15:39:24 +01002358 msg "build: full + test drivers dispatching to builtins"
2359 scripts/config.py full
Ronald Cron67cc6a72024-10-14 10:55:24 +02002360 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_CONFIG_ADJUST_TEST_ACCELERATORS"
David Horstmann5b93d972024-10-31 15:36:05 +00002361 loc_cflags="${loc_cflags} -I../framework/tests/include"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002362
Ronald Cron401f20f2025-09-02 14:50:10 +02002363 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002364
2365 msg "test: full + test drivers dispatching to builtins"
Ronald Cron401f20f2025-09-02 14:50:10 +02002366 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002367}
2368
2369component_build_psa_config_file () {
Minos Galanakis4f619e12024-11-14 14:56:47 +00002370 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002371 cp "$CRYPTO_CONFIG_H" psa_test_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002372 echo '#error "TF_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
Ronald Cron401f20f2025-09-02 14:50:10 +02002373 $MAKE_COMMAND CFLAGS="-I '$PWD' -DTF_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002374 # Make sure this feature is enabled. We'll disable it in the next phase.
Ronald Cron3f120062025-07-03 14:45:51 +02002375 programs/test/query_compile_time_config PSA_WANT_ALG_CMAC
Ronald Cron401f20f2025-09-02 14:50:10 +02002376 $MAKE_COMMAND clean
Minos Galanakis471b34c2024-07-26 15:39:24 +01002377
Minos Galanakis4f619e12024-11-14 14:56:47 +00002378 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE + TF_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002379 # In the user config, disable one feature and its dependencies, which will
2380 # reflect on the mbedtls configuration so we can query it with
2381 # query_compile_time_config.
2382 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
2383 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
Ronald Cron401f20f2025-09-02 14:50:10 +02002384 $MAKE_COMMAND 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 +02002385 not programs/test/query_compile_time_config PSA_WANT_ALG_CMAC
Minos Galanakis471b34c2024-07-26 15:39:24 +01002386
2387 rm -f psa_test_config.h psa_user_config.h
2388}
2389
2390component_build_psa_alt_headers () {
2391 msg "build: make with PSA alt headers" # ~20s
2392
2393 # Generate alternative versions of the substitutable headers with the
2394 # same content except different include guards.
David Horstmanndc459512024-11-07 17:08:11 +00002395 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 +01002396
2397 # Build the library and some programs.
2398 # Don't build the fuzzers to avoid having to go through hoops to set
2399 # a correct include path for programs/fuzz/Makefile.
Ronald Cron401f20f2025-09-02 14:50:10 +02002400 $MAKE_COMMAND 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
David Horstmann5b93d972024-10-31 15:36:05 +00002401 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 +01002402
2403 # Check that we're getting the alternative include guards and not the
2404 # original include guards.
2405 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
2406 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
2407 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
2408 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
2409}
2410
2411component_test_min_mpi_window_size () {
2412 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
2413 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
2414 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2415 make
2416
2417 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2418 make test
2419}
Ronald Cronf256f8a2025-07-10 17:37:18 +02002420
2421component_test_xts () {
2422 # Component dedicated to run XTS unit test cases while XTS is not
2423 # supported through the PSA API.
2424 msg "build: Default + MBEDTLS_CIPHER_MODE_XTS"
2425
Gilles Peskine9da0dce2025-09-22 15:55:10 +02002426 cat <<'EOF' >psa_user_config.h
2427#define MBEDTLS_CIPHER_MODE_XTS
2428#define TF_PSA_CRYPTO_CONFIG_CHECK_BYPASS
2429EOF
Ronald Cronf256f8a2025-07-10 17:37:18 +02002430 cmake -DTF_PSA_CRYPTO_USER_CONFIG_FILE="psa_user_config.h"
2431 make
2432
Ronald Crone0b06eb2025-07-15 08:58:32 +02002433 rm -f psa_user_config.h
2434
Ronald Cronf256f8a2025-07-10 17:37:18 +02002435 msg "test: Default + MBEDTLS_CIPHER_MODE_XTS"
2436 make test
Ronald Cronf256f8a2025-07-10 17:37:18 +02002437}