blob: 0551e6a404ff6548c38b7cdca6a3116431d2ba20 [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 # DES requires built-in support for key generation (parity check) so it
94 # cannot be accelerated
David Horstmann7cbeedc2025-08-26 17:26:45 +010095 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
Valerio Settia47b0452024-06-25 18:31:36 +020096 # EC-JPAKE use calloc/free in PSA core
David Horstmann7cbeedc2025-08-26 17:26:45 +010097 scripts/config.py unset PSA_WANT_ALG_JPAKE
Valerio Settia785eea2025-08-13 10:57:46 +020098 # Enable p192[k|r]1 curves which are disabled by default in tf-psa-crypto.
99 # This is required to get the proper test coverage otherwise there are
100 # tests in 'test_suite_psa_crypto_op_fail' that would never be executed.
101 scripts/config.py set PSA_WANT_ECC_SECP_K1_192
102 scripts/config.py set PSA_WANT_ECC_SECP_R1_192
Manuel Pégourié-Gonnard9114d4a2025-09-29 11:49:40 +0200103 scripts/config.py set TF_PSA_CRYPTO_ALLOW_REMOVED_MECHANISMS || true
Valerio Settia47b0452024-06-25 18:31:36 +0200104
105 # Accelerate all PSA features (which are still enabled in CRYPTO_CONFIG_H).
David Horstmann7cbeedc2025-08-26 17:26:45 +0100106 PSA_SYM_LIST=$(./scripts/config.py get-all-enabled PSA_WANT)
Valerio Settia47b0452024-06-25 18:31:36 +0200107 loc_accel_list=$(echo $PSA_SYM_LIST | sed 's/PSA_WANT_//g')
108
Valerio Settia47b0452024-06-25 18:31:36 +0200109 helper_libtestdriver1_adjust_config crypto
110 helper_libtestdriver1_make_drivers "$loc_accel_list"
111
Valerio Setti13aadd72024-08-13 13:13:23 +0200112 msg "crypto without heap: build main library"
Valerio Setti35b0b022024-08-13 13:36:50 +0200113 # Disable all legacy MBEDTLS_xxx symbols.
114 scripts/config.py unset-all "^MBEDTLS_"
115 # Build the PSA core using the proper config file.
116 scripts/config.py set MBEDTLS_PSA_CRYPTO_C
Valerio Settia47b0452024-06-25 18:31:36 +0200117 # Enable fully-static key slots in PSA core.
118 scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOTS
Valerio Setti35b0b022024-08-13 13:36:50 +0200119 # Prevent PSA core from creating a copy of input/output buffers.
Valerio Settia47b0452024-06-25 18:31:36 +0200120 scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
121 # Prevent PSA core from using CTR-DRBG or HMAC-DRBG for random generation.
122 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Valerio Setti13aadd72024-08-13 13:13:23 +0200123 # Set calloc/free as null pointer functions. Calling them would crash
Valerio Settia47b0452024-06-25 18:31:36 +0200124 # the program so we can use this as a "sentinel" for being sure no module
125 # is making use of these functions in the library.
Valerio Setti35b0b022024-08-13 13:36:50 +0200126 scripts/config.py set MBEDTLS_PLATFORM_C
Valerio Settia47b0452024-06-25 18:31:36 +0200127 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
128 scripts/config.py set MBEDTLS_PLATFORM_STD_CALLOC NULL
129 scripts/config.py set MBEDTLS_PLATFORM_STD_FREE NULL
130
Valerio Settia47b0452024-06-25 18:31:36 +0200131 helper_libtestdriver1_make_main "$loc_accel_list" lib
132
Valerio Setti13aadd72024-08-13 13:13:23 +0200133 msg "crypto without heap: build test suites and helpers"
134 # Reset calloc/free functions to normal operations so that test code can
Valerio Settia47b0452024-06-25 18:31:36 +0200135 # freely use them.
136 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
137 scripts/config.py unset MBEDTLS_PLATFORM_STD_CALLOC
138 scripts/config.py unset MBEDTLS_PLATFORM_STD_FREE
139 helper_libtestdriver1_make_main "$loc_accel_list" tests
140
Valerio Setti13aadd72024-08-13 13:13:23 +0200141 msg "crypto without heap: test"
Ronald Cron401f20f2025-09-02 14:50:10 +0200142 $MAKE_COMMAND test
Valerio Settia47b0452024-06-25 18:31:36 +0200143}
144
Minos Galanakisf78447f2024-07-26 20:49:51 +0100145component_test_no_rsa_key_pair_generation () {
Minos Galanakisdc0f73a2024-07-26 20:41:42 +0100146 msg "build: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
David Horstmann7cbeedc2025-08-26 17:26:45 +0100147 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Ronald Cron401f20f2025-09-02 14:50:10 +0200148 $MAKE_COMMAND
Minos Galanakisdc0f73a2024-07-26 20:41:42 +0100149
150 msg "test: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
Ronald Cron401f20f2025-09-02 14:50:10 +0200151 $MAKE_COMMAND test
Minos Galanakisdc0f73a2024-07-26 20:41:42 +0100152}
153
Minos Galanakisc06fd302024-08-01 12:16:59 +0100154component_test_no_pem_no_fs () {
155 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
156 scripts/config.py unset MBEDTLS_PEM_PARSE_C
157 scripts/config.py unset MBEDTLS_FS_IO
158 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
159 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
160 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
161 make
162
163 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
164 make test
165
166 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
167 tests/ssl-opt.sh
168}
169
170component_test_rsa_no_crt () {
171 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
172 scripts/config.py set MBEDTLS_RSA_NO_CRT
173 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
174 make
175
176 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
177 make test
178
179 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
180 tests/ssl-opt.sh -f RSA
181
182 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
183 tests/compat.sh -t RSA
184
185 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
186 tests/context-info.sh
187}
188
Minos Galanakisc06fd302024-08-01 12:16:59 +0100189component_test_no_ctr_drbg_use_psa () {
190 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
191 scripts/config.py full
192 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Minos Galanakisc06fd302024-08-01 12:16:59 +0100193
194 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
195 make
196
197 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
198 make test
199
200 # In this configuration, the TLS test programs use HMAC_DRBG.
201 # The SSL tests are slow, so run a small subset, just enough to get
202 # confidence that the SSL code copes with HMAC_DRBG.
203 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
204 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
205
206 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
207 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
208}
209
Minos Galanakisc06fd302024-08-01 12:16:59 +0100210component_test_no_hmac_drbg_use_psa () {
211 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
212 scripts/config.py full
213 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
David Horstmann7cbeedc2025-08-26 17:26:45 +0100214 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA # requires HMAC_DRBG
Minos Galanakisc06fd302024-08-01 12:16:59 +0100215
216 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
217 make
218
219 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
220 make test
221
222 # Normally our ECDSA implementation uses deterministic ECDSA. But since
223 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
224 # instead.
225 # Test SSL with non-deterministic ECDSA. Only test features that
226 # might be affected by how ECDSA signature is performed.
227 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
228 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
229
230 # To save time, only test one protocol version, since this part of
231 # the protocol is identical in (D)TLS up to 1.2.
232 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
233 tests/compat.sh -m tls12 -t 'ECDSA'
234}
235
Minos Galanakisc06fd302024-08-01 12:16:59 +0100236component_test_psa_external_rng_no_drbg_use_psa () {
237 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
238 scripts/config.py full
239 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Minos Galanakisc06fd302024-08-01 12:16:59 +0100240 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
241 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
242 scripts/config.py unset MBEDTLS_CTR_DRBG_C
243 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
David Horstmann7cbeedc2025-08-26 17:26:45 +0100244 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA # Requires HMAC_DRBG
Ronald Cron401f20f2025-09-02 14:50:10 +0200245 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakisc06fd302024-08-01 12:16:59 +0100246
247 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Ronald Cron401f20f2025-09-02 14:50:10 +0200248 $MAKE_COMMAND test
Minos Galanakisc06fd302024-08-01 12:16:59 +0100249
250 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
251 tests/ssl-opt.sh -f 'Default\|opaque'
252}
253
Minos Galanakis471b34c2024-07-26 15:39:24 +0100254component_test_psa_external_rng_use_psa_crypto () {
Ronald Cron3b306432025-09-02 18:30:08 +0200255 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG/NV_SEED"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100256 scripts/config.py full
257 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Minos Galanakis471b34c2024-07-26 15:39:24 +0100258 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Ronald Cron3b306432025-09-02 18:30:08 +0200259 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
260 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Ronald Cron401f20f2025-09-02 14:50:10 +0200261 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
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"
Ronald Cron401f20f2025-09-02 14:50:10 +0200264 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100265
Ronald Cron3b306432025-09-02 18:30:08 +0200266 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG/NV_SEED"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100267 tests/ssl-opt.sh -f 'Default\|opaque'
268}
269
Minos Galanakisf78447f2024-07-26 20:49:51 +0100270component_full_no_pkparse_pkwrite () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100271 msg "build: full without pkparse and pkwrite"
272
273 scripts/config.py crypto_full
274 scripts/config.py unset MBEDTLS_PK_PARSE_C
275 scripts/config.py unset MBEDTLS_PK_WRITE_C
276
Ronald Cron401f20f2025-09-02 14:50:10 +0200277 $MAKE_COMMAND CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100278
279 # Ensure that PK_[PARSE|WRITE]_C were not re-enabled accidentally (additive config).
280 not grep mbedtls_pk_parse_key ${BUILTIN_SRC_PATH}/pkparse.o
281 not grep mbedtls_pk_write_key_der ${BUILTIN_SRC_PATH}/pkwrite.o
282
283 msg "test: full without pkparse and pkwrite"
Ronald Cron401f20f2025-09-02 14:50:10 +0200284 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100285}
286
287component_test_crypto_full_md_light_only () {
288 msg "build: crypto_full with only the light subset of MD"
289 scripts/config.py crypto_full
290
291 # Disable MD
292 scripts/config.py unset MBEDTLS_MD_C
293 # Disable direct dependencies of MD_C
294 scripts/config.py unset MBEDTLS_HKDF_C
295 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
296 scripts/config.py unset MBEDTLS_PKCS7_C
297 # Disable indirect dependencies of MD_C
David Horstmann7cbeedc2025-08-26 17:26:45 +0100298 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
Minos Galanakis471b34c2024-07-26 15:39:24 +0100299 # Disable things that would auto-enable MD_C
300 scripts/config.py unset MBEDTLS_PKCS5_C
301
302 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
303 # which we haven't disabled, so no need to explicitly enable it.
Ronald Cron401f20f2025-09-02 14:50:10 +0200304 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100305
306 # Make sure we don't have the HMAC functions, but the hashing functions
307 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
308 grep mbedtls_md ${BUILTIN_SRC_PATH}/md.o
309
310 msg "test: crypto_full with only the light subset of MD"
Ronald Cron401f20f2025-09-02 14:50:10 +0200311 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100312}
313
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100314component_test_full_no_cipher () {
315 msg "build: full no CIPHER"
316
317 scripts/config.py full
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100318
319 # The built-in implementation of the following algs/key-types depends
320 # on CIPHER_C so we disable them.
321 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
322 # so we keep them enabled.
David Horstmann7cbeedc2025-08-26 17:26:45 +0100323 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
324 scripts/config.py unset PSA_WANT_ALG_CMAC
325 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
326 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
327 scripts/config.py unset PSA_WANT_ALG_CFB
328 scripts/config.py unset PSA_WANT_ALG_CTR
329 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
330 scripts/config.py unset PSA_WANT_ALG_OFB
331 scripts/config.py unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
332 scripts/config.py unset PSA_WANT_ALG_STREAM_CIPHER
333 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100334
335 # The following modules directly depends on CIPHER_C
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100336 scripts/config.py unset MBEDTLS_NIST_KW_C
337
Ronald Cron401f20f2025-09-02 14:50:10 +0200338 $MAKE_COMMAND
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100339
340 # Ensure that CIPHER_C was not re-enabled
341 not grep mbedtls_cipher_init ${BUILTIN_SRC_PATH}/cipher.o
342
343 msg "test: full no CIPHER"
Ronald Cron401f20f2025-09-02 14:50:10 +0200344 $MAKE_COMMAND test
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100345}
346
Minos Galanakisf78447f2024-07-26 20:49:51 +0100347component_test_full_no_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100348 msg "build: full no PSA_WANT_ALG_CCM"
349
350 # Full config enables:
351 # - USE_PSA_CRYPTO so that TLS code dispatches cipher/AEAD to PSA
352 # - CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
353 scripts/config.py full
354
355 # Disable PSA_WANT_ALG_CCM so that CCM is not supported in PSA. CCM_C is still
356 # enabled, but not used from TLS since USE_PSA is set.
357 # This is helpful to ensure that TLS tests below have proper dependencies.
358 #
359 # Note: also PSA_WANT_ALG_CCM_STAR_NO_TAG is enabled, but it does not cause
360 # PSA_WANT_ALG_CCM to be re-enabled.
David Horstmannb907dbc2025-08-27 15:19:40 +0100361 scripts/config.py unset PSA_WANT_ALG_CCM
Minos Galanakis471b34c2024-07-26 15:39:24 +0100362
Ronald Cron401f20f2025-09-02 14:50:10 +0200363 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +0100364
365 msg "test: full no PSA_WANT_ALG_CCM"
Ronald Cron401f20f2025-09-02 14:50:10 +0200366 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100367}
368
Minos Galanakisf78447f2024-07-26 20:49:51 +0100369component_test_full_no_ccm_star_no_tag () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100370 msg "build: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
371
372 # Full config enables CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
373 scripts/config.py full
374
375 # Disable CCM_STAR_NO_TAG, which is the target of this test, as well as all
376 # other components that enable MBEDTLS_PSA_BUILTIN_CIPHER internal symbol.
377 # This basically disables all unauthenticated ciphers on the PSA side, while
378 # keeping AEADs enabled.
379 #
380 # Note: PSA_WANT_ALG_CCM is enabled, but it does not cause
381 # PSA_WANT_ALG_CCM_STAR_NO_TAG to be re-enabled.
David Horstmannb907dbc2025-08-27 15:19:40 +0100382 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
383 scripts/config.py unset PSA_WANT_ALG_STREAM_CIPHER
384 scripts/config.py unset PSA_WANT_ALG_CTR
385 scripts/config.py unset PSA_WANT_ALG_CFB
386 scripts/config.py unset PSA_WANT_ALG_OFB
387 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
Ben Taylor1948c942025-03-04 09:11:11 +0000388 # NOTE unsettting PSA_WANT_ALG_ECB_NO_PADDING without unsetting NIST_KW_C will
389 # mean PSA_WANT_ALG_ECB_NO_PADDING is re-enabled, so disabling it also.
David Horstmannb907dbc2025-08-27 15:19:40 +0100390 scripts/config.py unset MBEDTLS_NIST_KW_C
391 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
392 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
Minos Galanakis471b34c2024-07-26 15:39:24 +0100393
Ronald Cron401f20f2025-09-02 14:50:10 +0200394 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +0100395
396 # Ensure MBEDTLS_PSA_BUILTIN_CIPHER was not enabled
397 not grep mbedtls_psa_cipher ${PSA_CORE_PATH}/psa_crypto_cipher.o
398
399 msg "test: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
Ronald Cron401f20f2025-09-02 14:50:10 +0200400 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100401}
402
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200403component_test_config_symmetric_only () {
404 msg "build: configs/config-symmetric-only.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +0000405 MBEDTLS_CONFIG="configs/config-symmetric-only.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +0000406 CRYPTO_CONFIG="tf-psa-crypto/configs/crypto-config-symmetric-only.h"
Ronald Cronfaadfc22024-12-07 17:24:28 +0100407 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 +0200408 make
409
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200410 msg "test: configs/config-symmetric-only.h - unit tests"
Gilles Peskineaf5a8992024-09-14 11:27:44 +0200411 make test
412}
413
Minos Galanakisc06fd302024-08-01 12:16:59 +0100414component_test_everest () {
415 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
416 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
417 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
418 make
419
420 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
421 make test
422
423 msg "test: metatests (clang, ASan)"
424 tests/scripts/run-metatests.sh any asan poison
425
426 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
427 tests/ssl-opt.sh -f ECDH
428
429 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
430 # Exclude some symmetric ciphers that are redundant here to gain time.
431 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
432}
433
Ben Taylor59213b62025-08-14 10:01:06 +0100434component_test_everest_curve25519_only () {
Ben Taylorf5729362025-09-02 13:10:52 +0100435 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
Ben Taylor59213b62025-08-14 10:01:06 +0100436 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Ronald Cronfeb5e262025-09-15 18:36:39 +0200437 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
438 scripts/config.py unset PSA_WANT_ALG_ECDSA
439 scripts/config.py set PSA_WANT_ALG_ECDH
Ben Taylor59213b62025-08-14 10:01:06 +0100440 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
441 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
Ronald Cronfeb5e262025-09-15 18:36:39 +0200442 scripts/config.py unset PSA_WANT_ALG_JPAKE
Ben Taylor59213b62025-08-14 10:01:06 +0100443
444 # Disable all curves
Ronald Cronfeb5e262025-09-15 18:36:39 +0200445 scripts/config.py unset-all "PSA_WANT_ECC_[0-9A-Z_a-z]*$"
446 scripts/config.py set PSA_WANT_ECC_MONTGOMERY_255
Ben Taylor59213b62025-08-14 10:01:06 +0100447
Ronald Cron401f20f2025-09-02 14:50:10 +0200448 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Ben Taylor59213b62025-08-14 10:01:06 +0100449
450 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
Ronald Cron401f20f2025-09-02 14:50:10 +0200451 $MAKE_COMMAND test
Ben Taylor59213b62025-08-14 10:01:06 +0100452}
453
Minos Galanakis471b34c2024-07-26 15:39:24 +0100454component_test_psa_collect_statuses () {
455 msg "build+test: psa_collect_statuses" # ~30s
456 scripts/config.py full
457 tests/scripts/psa_collect_statuses.py
458 # Check that psa_crypto_init() succeeded at least once
459 grep -q '^0:psa_crypto_init:' tests/statuses.log
460 rm -f tests/statuses.log
461}
462
463# Check that the specified libraries exist and are empty.
464are_empty_libraries () {
465 nm "$@" >/dev/null 2>/dev/null
466 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
467}
468
Minos Galanakis471b34c2024-07-26 15:39:24 +0100469component_test_crypto_for_psa_service () {
470 msg "build: make, config for PSA crypto service"
471 scripts/config.py crypto
472 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
473 # Disable things that are not needed for just cryptography, to
474 # reach a configuration that would be typical for a PSA cryptography
475 # service providing all implemented PSA algorithms.
476 # System stuff
477 scripts/config.py unset MBEDTLS_ERROR_C
478 scripts/config.py unset MBEDTLS_TIMING_C
479 scripts/config.py unset MBEDTLS_VERSION_FEATURES
480 # Crypto stuff with no PSA interface
481 scripts/config.py unset MBEDTLS_BASE64_C
Minos Galanakis471b34c2024-07-26 15:39:24 +0100482 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
483 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
484 scripts/config.py unset MBEDTLS_NIST_KW_C
485 scripts/config.py unset MBEDTLS_PEM_PARSE_C
486 scripts/config.py unset MBEDTLS_PEM_WRITE_C
487 scripts/config.py unset MBEDTLS_PKCS12_C
488 scripts/config.py unset MBEDTLS_PKCS5_C
489 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
490 # in PSA code to work with RSA keys. We don't require users to set those:
491 # they will be reenabled in build_info.h.
492 scripts/config.py unset MBEDTLS_PK_C
493 scripts/config.py unset MBEDTLS_PK_PARSE_C
494 scripts/config.py unset MBEDTLS_PK_WRITE_C
Ronald Cron401f20f2025-09-02 14:50:10 +0200495 $MAKE_COMMAND CFLAGS='-O1 -Werror' all test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100496 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
497}
498
499component_build_crypto_baremetal () {
500 msg "build: make, crypto only, baremetal config"
501 scripts/config.py crypto_baremetal
Ronald Cron401f20f2025-09-02 14:50:10 +0200502 $MAKE_COMMAND CFLAGS="-O1 -Werror -I$PWD/framework/tests/include/baremetal-override/"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100503 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
504}
505
506support_build_crypto_baremetal () {
507 support_build_baremetal "$@"
508}
509
510# depends.py family of tests
511component_test_depends_py_cipher_id () {
512 msg "test/build: depends.py cipher_id (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200513 tests/scripts/depends.py cipher_id
Minos Galanakis471b34c2024-07-26 15:39:24 +0100514}
515
516component_test_depends_py_cipher_chaining () {
517 msg "test/build: depends.py cipher_chaining (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200518 tests/scripts/depends.py cipher_chaining
Minos Galanakis471b34c2024-07-26 15:39:24 +0100519}
520
Minos Galanakis471b34c2024-07-26 15:39:24 +0100521component_test_depends_py_curves () {
522 msg "test/build: depends.py curves (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200523 tests/scripts/depends.py curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100524}
525
526component_test_depends_py_hashes () {
527 msg "test/build: depends.py hashes (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200528 tests/scripts/depends.py hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +0100529}
530
Minos Galanakis471b34c2024-07-26 15:39:24 +0100531component_test_depends_py_pkalgs () {
532 msg "test/build: depends.py pkalgs (gcc)"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100533 tests/scripts/depends.py pkalgs
534}
535
536component_test_psa_crypto_config_ffdh_2048_only () {
537 msg "build: full config - only DH 2048"
538
539 scripts/config.py full
540
541 # Disable all DH groups other than 2048.
David Horstmannb907dbc2025-08-27 15:19:40 +0100542 scripts/config.py unset PSA_WANT_DH_RFC7919_3072
543 scripts/config.py unset PSA_WANT_DH_RFC7919_4096
544 scripts/config.py unset PSA_WANT_DH_RFC7919_6144
545 scripts/config.py unset PSA_WANT_DH_RFC7919_8192
Minos Galanakis471b34c2024-07-26 15:39:24 +0100546
Ronald Cron401f20f2025-09-02 14:50:10 +0200547 $MAKE_COMMAND CFLAGS="$ASAN_CFLAGS -Werror" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100548
549 msg "test: full config - only DH 2048"
Ronald Cron401f20f2025-09-02 14:50:10 +0200550 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100551
552 msg "ssl-opt: full config - only DH 2048"
553 tests/ssl-opt.sh -f "ffdh"
554}
555
Minos Galanakis471b34c2024-07-26 15:39:24 +0100556component_test_psa_crypto_config_accel_ecdsa () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200557 msg "build: accelerated ECDSA"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100558
Minos Galanakis471b34c2024-07-26 15:39:24 +0100559 # Configure
560 # ---------
561
Elena Uziunaite91d83862024-09-04 14:51:31 +0100562 # Start from default config + TLS 1.3
Minos Galanakis471b34c2024-07-26 15:39:24 +0100563 helper_libtestdriver1_adjust_config "default"
564
Valerio Setti37a42812025-08-11 12:52:49 +0200565 # Algorithms and key types to accelerate
566 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
567 $(helper_get_psa_key_type_list "ECC") \
568 $(helper_get_psa_curve_list)"
569
Minos Galanakis471b34c2024-07-26 15:39:24 +0100570 # Disable things that depend on it
571 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +0100572
573 # Build
574 # -----
575
576 # These hashes are needed for some ECDSA signature tests.
Elena Uziunaiteffce45c2024-09-12 14:58:52 +0100577 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 +0100578 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
579
580 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
581
582 helper_libtestdriver1_make_main "$loc_accel_list"
583
584 # Make sure this was not re-enabled by accident (additive config)
585 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
586
587 # Run the tests
588 # -------------
589
Ronald Cron93ba6252024-09-05 10:37:14 +0200590 msg "test: accelerated ECDSA"
Ronald Cron401f20f2025-09-02 14:50:10 +0200591 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100592}
593
594component_test_psa_crypto_config_accel_ecdh () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200595 msg "build: accelerated ECDH"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100596
Minos Galanakis471b34c2024-07-26 15:39:24 +0100597 # Configure
598 # ---------
599
600 # Start from default config (no USE_PSA)
601 helper_libtestdriver1_adjust_config "default"
602
Valerio Setti37a42812025-08-11 12:52:49 +0200603 # Algorithms and key types to accelerate
604 loc_accel_list="ALG_ECDH \
605 $(helper_get_psa_key_type_list "ECC") \
606 $(helper_get_psa_curve_list)"
607
Minos Galanakis471b34c2024-07-26 15:39:24 +0100608 # Disable things that depend on it
Minos Galanakis471b34c2024-07-26 15:39:24 +0100609 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
610 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
611 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
612
613 # Build
614 # -----
615
616 helper_libtestdriver1_make_drivers "$loc_accel_list"
617
618 helper_libtestdriver1_make_main "$loc_accel_list"
619
620 # Make sure this was not re-enabled by accident (additive config)
621 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
622
623 # Run the tests
624 # -------------
625
Ronald Cron93ba6252024-09-05 10:37:14 +0200626 msg "test: accelerated ECDH"
Ronald Cron401f20f2025-09-02 14:50:10 +0200627 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100628}
629
630component_test_psa_crypto_config_accel_ffdh () {
631 msg "build: full with accelerated FFDH"
632
Minos Galanakis471b34c2024-07-26 15:39:24 +0100633 # Configure
634 # ---------
635
636 # start with full (USE_PSA and TLS 1.3)
637 helper_libtestdriver1_adjust_config "full"
638
Valerio Setti37a42812025-08-11 12:52:49 +0200639 # Algorithms and key types to accelerate
640 loc_accel_list="ALG_FFDH \
641 $(helper_get_psa_key_type_list "DH") \
642 $(helper_get_psa_dh_group_list)"
643
Minos Galanakis471b34c2024-07-26 15:39:24 +0100644 # Build
645 # -----
646
647 helper_libtestdriver1_make_drivers "$loc_accel_list"
648
649 helper_libtestdriver1_make_main "$loc_accel_list"
650
651 # Make sure this was not re-enabled by accident (additive config)
Valerio Settieb63eb22025-02-12 13:32:49 +0100652 not grep mbedtls_psa_ffdh_key_agreement ${BUILTIN_SRC_PATH}/psa_crypto_ffdh.o
Minos Galanakis471b34c2024-07-26 15:39:24 +0100653
654 # Run the tests
655 # -------------
656
657 msg "test: full with accelerated FFDH"
Ronald Cron401f20f2025-09-02 14:50:10 +0200658 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100659
660 msg "ssl-opt: full with accelerated FFDH alg"
661 tests/ssl-opt.sh -f "ffdh"
662}
663
664component_test_psa_crypto_config_reference_ffdh () {
665 msg "build: full with non-accelerated FFDH"
666
667 # Start with full (USE_PSA and TLS 1.3)
668 helper_libtestdriver1_adjust_config "full"
669
Ronald Cron401f20f2025-09-02 14:50:10 +0200670 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +0100671
672 msg "test suites: full with non-accelerated FFDH alg"
Ronald Cron401f20f2025-09-02 14:50:10 +0200673 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100674
675 msg "ssl-opt: full with non-accelerated FFDH alg"
676 tests/ssl-opt.sh -f "ffdh"
677}
678
Minos Galanakisf78447f2024-07-26 20:49:51 +0100679component_test_psa_crypto_config_accel_pake () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100680 msg "build: full with accelerated PAKE"
681
Minos Galanakis471b34c2024-07-26 15:39:24 +0100682 # Configure
683 # ---------
684
685 helper_libtestdriver1_adjust_config "full"
686
Valerio Setti37a42812025-08-11 12:52:49 +0200687 loc_accel_list="ALG_JPAKE \
688 $(helper_get_psa_key_type_list "ECC") \
689 $(helper_get_psa_curve_list)"
690
Minos Galanakis471b34c2024-07-26 15:39:24 +0100691 # Make built-in fallback not available
Minos Galanakis471b34c2024-07-26 15:39:24 +0100692 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
693
694 # Build
695 # -----
696
697 helper_libtestdriver1_make_drivers "$loc_accel_list"
698
699 helper_libtestdriver1_make_main "$loc_accel_list"
700
701 # Make sure this was not re-enabled by accident (additive config)
702 not grep mbedtls_ecjpake_init ${BUILTIN_SRC_PATH}/ecjpake.o
703
704 # Run the tests
705 # -------------
706
707 msg "test: full with accelerated PAKE"
Ronald Cron401f20f2025-09-02 14:50:10 +0200708 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100709}
710
711component_test_psa_crypto_config_accel_ecc_some_key_types () {
712 msg "build: full with accelerated EC algs and some key types"
713
Valerio Setti37a42812025-08-11 12:52:49 +0200714 # Configure
715 # ---------
716
717 # start with config full for maximum coverage (also enables USE_PSA)
718 helper_libtestdriver1_adjust_config "full"
719
Minos Galanakis471b34c2024-07-26 15:39:24 +0100720 # Algorithms and key types to accelerate
721 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
722 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
723 ALG_ECDH \
724 ALG_JPAKE \
725 KEY_TYPE_ECC_PUBLIC_KEY \
726 KEY_TYPE_ECC_KEY_PAIR_BASIC \
727 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
728 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
729 $(helper_get_psa_curve_list)"
730
Minos Galanakis471b34c2024-07-26 15:39:24 +0100731 # Disable all curves - those that aren't accelerated should be re-enabled
732 helper_disable_builtin_curves
733
734 # Restartable feature is not yet supported by PSA. Once it will in
735 # the future, the following line could be removed (see issues
736 # 6061, 6332 and following ones)
737 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
738
739 # this is not supported by the driver API yet
David Horstmannb907dbc2025-08-27 15:19:40 +0100740 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +0100741
742 # Build
743 # -----
744
745 # These hashes are needed for some ECDSA signature tests.
746 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
747 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
748 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
749
750 helper_libtestdriver1_make_main "$loc_accel_list"
751
752 # ECP should be re-enabled but not the others
753 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
754 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
755 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
756 grep mbedtls_ecp ${BUILTIN_SRC_PATH}/ecp.o
757
758 # Run the tests
759 # -------------
760
761 msg "test suites: full with accelerated EC algs and some key types"
Ronald Cron401f20f2025-09-02 14:50:10 +0200762 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100763}
764
765# Run tests with only (non-)Weierstrass accelerated
766# Common code used in:
767# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
768# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100769common_test_psa_crypto_config_accel_ecc_some_curves () {
770 weierstrass=$1
771 if [ $weierstrass -eq 1 ]; then
772 desc="Weierstrass"
773 else
774 desc="non-Weierstrass"
775 fi
776
777 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
778
Valerio Setti37a42812025-08-11 12:52:49 +0200779 # Configure
780 # ---------
781
782 # Start with config crypto_full and remove PK_C:
783 # that's what's supported now, see docs/driver-only-builds.md.
784 helper_libtestdriver1_adjust_config "crypto_full"
785 scripts/config.py unset MBEDTLS_PK_C
786 scripts/config.py unset MBEDTLS_PK_PARSE_C
787 scripts/config.py unset MBEDTLS_PK_WRITE_C
788
Valerio Setti37a42812025-08-11 12:52:49 +0200789 # Disable all curves - those that aren't accelerated should be re-enabled
790 helper_disable_builtin_curves
791
Valerio Setti981a0c42025-08-12 11:31:11 +0200792 # Note: Curves are handled in a special way by the libtestdriver machinery,
Minos Galanakis471b34c2024-07-26 15:39:24 +0100793 # so we only want to include them in the accel list when building the main
794 # libraries, hence the use of a separate variable.
795 # Note: the following loop is a modified version of
796 # helper_get_psa_curve_list that only keeps Weierstrass families.
797 loc_weierstrass_list=""
798 loc_non_weierstrass_list=""
799 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
800 case $item in
801 ECC_BRAINPOOL*|ECC_SECP*)
802 loc_weierstrass_list="$loc_weierstrass_list $item"
803 ;;
804 *)
805 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
806 ;;
807 esac
808 done
809 if [ $weierstrass -eq 1 ]; then
810 loc_curve_list=$loc_weierstrass_list
811 else
812 loc_curve_list=$loc_non_weierstrass_list
813 fi
814
815 # Algorithms and key types to accelerate
816 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
817 ALG_ECDH \
818 ALG_JPAKE \
819 $(helper_get_psa_key_type_list "ECC") \
820 $loc_curve_list"
821
Minos Galanakis471b34c2024-07-26 15:39:24 +0100822 # Restartable feature is not yet supported by PSA. Once it will in
823 # the future, the following line could be removed (see issues
824 # 6061, 6332 and following ones)
825 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
826
827 # this is not supported by the driver API yet
David Horstmannb907dbc2025-08-27 15:19:40 +0100828 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +0100829
830 # Build
831 # -----
832
833 # These hashes are needed for some ECDSA signature tests.
834 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
835 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
836 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
837
838 helper_libtestdriver1_make_main "$loc_accel_list"
839
840 # We expect ECDH to be re-enabled for the missing curves
841 grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
842 # We expect ECP to be re-enabled, however the parts specific to the
843 # families of curves that are accelerated should be ommited.
844 # - functions with mxz in the name are specific to Montgomery curves
845 # - ecp_muladd is specific to Weierstrass curves
846 ##nm ${BUILTIN_SRC_PATH}/ecp.o | tee ecp.syms
847 if [ $weierstrass -eq 1 ]; then
848 not grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
849 grep mxz ${BUILTIN_SRC_PATH}/ecp.o
850 else
851 grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
852 not grep mxz ${BUILTIN_SRC_PATH}/ecp.o
853 fi
854 # We expect ECDSA and ECJPAKE to be re-enabled only when
855 # Weierstrass curves are not accelerated
856 if [ $weierstrass -eq 1 ]; then
857 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
858 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
859 else
860 grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
861 grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
862 fi
863
864 # Run the tests
865 # -------------
866
867 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
Ronald Cron401f20f2025-09-02 14:50:10 +0200868 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100869}
870
871component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
872 common_test_psa_crypto_config_accel_ecc_some_curves 1
873}
874
875component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
876 common_test_psa_crypto_config_accel_ecc_some_curves 0
877}
878
879# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
880# ECDH, ECDSA) with and without drivers.
881# The input parameter is a boolean value which indicates:
882# - 0 keep built-in EC algs,
883# - 1 exclude built-in EC algs (driver only).
884#
885# This is used by the two following components to ensure they always use the
886# same config, except for the use of driver or built-in EC algorithms:
887# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
888# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
889# This supports comparing their test coverage with analyze_outcomes.py.
Minos Galanakis471b34c2024-07-26 15:39:24 +0100890config_psa_crypto_config_ecp_light_only () {
891 driver_only="$1"
892 # start with config full for maximum coverage (also enables USE_PSA)
893 helper_libtestdriver1_adjust_config "full"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100894
895 # Restartable feature is not yet supported by PSA. Once it will in
896 # the future, the following line could be removed (see issues
897 # 6061, 6332 and following ones)
898 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
899}
900
901# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100902component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
903 msg "build: full with accelerated EC algs"
904
Valerio Setti37a42812025-08-11 12:52:49 +0200905 # Configure
906 # ---------
907
908 # Use the same config as reference, only without built-in EC algs
909 config_psa_crypto_config_ecp_light_only 1
910
Minos Galanakis471b34c2024-07-26 15:39:24 +0100911 # Algorithms and key types to accelerate
912 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
913 ALG_ECDH \
914 ALG_JPAKE \
915 $(helper_get_psa_key_type_list "ECC") \
916 $(helper_get_psa_curve_list)"
917
Minos Galanakis471b34c2024-07-26 15:39:24 +0100918 # Do not disable builtin curves because that support is required for:
919 # - MBEDTLS_PK_PARSE_EC_EXTENDED
920 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
921
922 # Build
923 # -----
924
925 # These hashes are needed for some ECDSA signature tests.
926 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
927 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
928 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
929
930 helper_libtestdriver1_make_main "$loc_accel_list"
931
932 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
933 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
934 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
935 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
936 not grep mbedtls_ecp_mul ${BUILTIN_SRC_PATH}/ecp.o
937
938 # Run the tests
939 # -------------
940
941 msg "test suites: full with accelerated EC algs"
Ronald Cron401f20f2025-09-02 14:50:10 +0200942 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100943
944 msg "ssl-opt: full with accelerated EC algs"
945 tests/ssl-opt.sh
946}
947
948# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100949component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200950 msg "build: non-accelerated EC algs"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100951
952 config_psa_crypto_config_ecp_light_only 0
953
Ronald Cron401f20f2025-09-02 14:50:10 +0200954 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +0100955
956 msg "test suites: full with non-accelerated EC algs"
Ronald Cron401f20f2025-09-02 14:50:10 +0200957 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +0100958
959 msg "ssl-opt: full with non-accelerated EC algs"
960 tests/ssl-opt.sh
961}
962
963# This helper function is used by:
964# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
965# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
966# to ensure that both tests use the same underlying configuration when testing
967# driver's coverage with analyze_outcomes.py.
968#
969# This functions accepts 1 boolean parameter as follows:
970# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
971# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
972# - 0: include built-in implementation of EC algorithms.
973#
974# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
975# on the ECP module.
Minos Galanakis471b34c2024-07-26 15:39:24 +0100976config_psa_crypto_no_ecp_at_all () {
977 driver_only="$1"
978 # start with full config for maximum coverage (also enables USE_PSA)
979 helper_libtestdriver1_adjust_config "full"
980
Minos Galanakis471b34c2024-07-26 15:39:24 +0100981 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
982 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
983 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
David Horstmannb907dbc2025-08-27 15:19:40 +0100984 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +0100985
986 # Restartable feature is not yet supported by PSA. Once it will in
987 # the future, the following line could be removed (see issues
988 # 6061, 6332 and following ones)
989 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
990}
991
992# Build and test a configuration where driver accelerates all EC algs while
993# all support and dependencies from ECP and ECP_LIGHT are removed on the library
994# side.
995#
996# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Minos Galanakis471b34c2024-07-26 15:39:24 +0100997component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
998 msg "build: full + accelerated EC algs - ECP"
999
Minos Galanakis471b34c2024-07-26 15:39:24 +01001000 # Configure
1001 # ---------
1002
1003 # Set common configurations between library's and driver's builds
1004 config_psa_crypto_no_ecp_at_all 1
1005 # Disable all the builtin curves. All the required algs are accelerated.
1006 helper_disable_builtin_curves
1007
Valerio Setti37a42812025-08-11 12:52:49 +02001008 # Algorithms and key types to accelerate
1009 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1010 ALG_ECDH \
1011 ALG_JPAKE \
1012 $(helper_get_psa_key_type_list "ECC") \
1013 $(helper_get_psa_curve_list)"
1014
Minos Galanakis471b34c2024-07-26 15:39:24 +01001015 # Build
1016 # -----
1017
1018 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1019 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1020 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1021 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1022
1023 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1024
1025 helper_libtestdriver1_make_main "$loc_accel_list"
1026
1027 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1028 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1029 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1030 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1031 # Also ensure that ECP module was not re-enabled
1032 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1033
1034 # Run the tests
1035 # -------------
1036
1037 msg "test: full + accelerated EC algs - ECP"
Ronald Cron401f20f2025-09-02 14:50:10 +02001038 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001039
1040 msg "ssl-opt: full + accelerated EC algs - ECP"
1041 tests/ssl-opt.sh
1042}
1043
1044# Reference function used for driver's coverage analysis in analyze_outcomes.py
1045# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
1046# Keep in sync with its accelerated counterpart.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001047component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
1048 msg "build: full + non accelerated EC algs"
1049
1050 config_psa_crypto_no_ecp_at_all 0
1051
Ronald Cron401f20f2025-09-02 14:50:10 +02001052 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001053
1054 msg "test: full + non accelerated EC algs"
Ronald Cron401f20f2025-09-02 14:50:10 +02001055 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001056
1057 msg "ssl-opt: full + non accelerated EC algs"
1058 tests/ssl-opt.sh
1059}
1060
1061# This is a common configuration helper used directly from:
1062# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1063# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1064# and indirectly from:
1065# - component_test_psa_crypto_config_accel_ecc_no_bignum
1066# - accelerate all EC algs, disable RSA and FFDH
1067# - component_test_psa_crypto_config_reference_ecc_no_bignum
1068# - this is the reference component of the above
1069# - it still disables RSA and FFDH, but it uses builtin EC algs
1070# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1071# - accelerate all EC and FFDH algs, disable only RSA
1072# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1073# - this is the reference component of the above
1074# - it still disables RSA, but it uses builtin EC and FFDH algs
1075#
1076# This function accepts 2 parameters:
1077# $1: a boolean value which states if we are testing an accelerated scenario
1078# or not.
1079# $2: a string value which states which components are tested. Allowed values
1080# are "ECC" or "ECC_DH".
Minos Galanakisf78447f2024-07-26 20:49:51 +01001081config_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001082 driver_only="$1"
1083 test_target="$2"
1084 # start with full config for maximum coverage (also enables USE_PSA)
1085 helper_libtestdriver1_adjust_config "full"
1086
Minos Galanakis471b34c2024-07-26 15:39:24 +01001087 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1088 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1089 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
David Horstmannb907dbc2025-08-27 15:19:40 +01001090 scripts/config.py unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Minos Galanakis471b34c2024-07-26 15:39:24 +01001091
1092 # RSA support is intentionally disabled on this test because RSA_C depends
1093 # on BIGNUM_C.
David Horstmannb907dbc2025-08-27 15:19:40 +01001094 scripts/config.py unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
1095 scripts/config.py unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001096 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1097 # Also disable key exchanges that depend on RSA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001098 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001099
1100 if [ "$test_target" = "ECC" ]; then
1101 # When testing ECC only, we disable FFDH support, both from builtin and
Valerio Setti8438c632025-01-22 11:56:40 +01001102 # PSA sides.
David Horstmannb907dbc2025-08-27 15:19:40 +01001103 scripts/config.py unset PSA_WANT_ALG_FFDH
1104 scripts/config.py unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
1105 scripts/config.py unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001106 fi
1107
1108 # Restartable feature is not yet supported by PSA. Once it will in
1109 # the future, the following line could be removed (see issues
1110 # 6061, 6332 and following ones)
1111 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1112}
1113
1114# Common helper used by:
1115# - component_test_psa_crypto_config_accel_ecc_no_bignum
1116# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1117#
1118# The goal is to build and test accelerating either:
1119# - ECC only or
1120# - both ECC and FFDH
1121#
1122# It is meant to be used in conjunction with
1123# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
1124# coverage analysis in the "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001125common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1126 test_target="$1"
1127
1128 # This is an internal helper to simplify text message handling
1129 if [ "$test_target" = "ECC_DH" ]; then
1130 accel_text="ECC/FFDH"
1131 removed_text="ECP - DH"
1132 else
1133 accel_text="ECC"
1134 removed_text="ECP"
1135 fi
1136
1137 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1138
Valerio Setti37a42812025-08-11 12:52:49 +02001139 # Configure
1140 # ---------
1141
1142 # Set common configurations between library's and driver's builds
1143 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
1144 # Disable all the builtin curves. All the required algs are accelerated.
1145 helper_disable_builtin_curves
1146
Minos Galanakis471b34c2024-07-26 15:39:24 +01001147 # By default we accelerate all EC keys/algs
1148 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1149 ALG_ECDH \
1150 ALG_JPAKE \
1151 $(helper_get_psa_key_type_list "ECC") \
1152 $(helper_get_psa_curve_list)"
1153 # Optionally we can also add DH to the list of accelerated items
1154 if [ "$test_target" = "ECC_DH" ]; then
1155 loc_accel_list="$loc_accel_list \
1156 ALG_FFDH \
1157 $(helper_get_psa_key_type_list "DH") \
1158 $(helper_get_psa_dh_group_list)"
1159 fi
1160
Minos Galanakis471b34c2024-07-26 15:39:24 +01001161 # Build
1162 # -----
1163
1164 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1165 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1166 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1167 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1168
1169 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1170
1171 helper_libtestdriver1_make_main "$loc_accel_list"
1172
1173 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1174 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1175 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1176 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001177 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001178 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1179 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1180 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001181
1182 # Run the tests
1183 # -------------
1184
Valerio Settieb63eb22025-02-12 13:32:49 +01001185 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001186
Ronald Cron401f20f2025-09-02 14:50:10 +02001187 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001188
1189 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1190 tests/ssl-opt.sh
1191}
1192
1193# Common helper used by:
1194# - component_test_psa_crypto_config_reference_ecc_no_bignum
1195# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1196#
1197# The goal is to build and test a reference scenario (i.e. with builtin
1198# components) compared to the ones used in
1199# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
1200#
1201# It is meant to be used in conjunction with
1202# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
1203# coverage analysis in "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001204common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1205 test_target="$1"
1206
1207 # This is an internal helper to simplify text message handling
1208 if [ "$test_target" = "ECC_DH" ]; then
1209 accel_text="ECC/FFDH"
1210 else
1211 accel_text="ECC"
1212 fi
1213
1214 msg "build: full + non accelerated $accel_text algs + USE_PSA"
1215
1216 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
1217
Ronald Cron401f20f2025-09-02 14:50:10 +02001218 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001219
1220 msg "test suites: full + non accelerated EC algs + USE_PSA"
Ronald Cron401f20f2025-09-02 14:50:10 +02001221 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001222
1223 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
1224 tests/ssl-opt.sh
1225}
1226
1227component_test_psa_crypto_config_accel_ecc_no_bignum () {
1228 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
1229}
1230
1231component_test_psa_crypto_config_reference_ecc_no_bignum () {
1232 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
1233}
1234
1235component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1236 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
1237}
1238
1239component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1240 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
1241}
1242
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001243component_test_tfm_config_as_is () {
1244 msg "build: configs/config-tfm.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +00001245 MBEDTLS_CONFIG="configs/config-tfm.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001246 CRYPTO_CONFIG="tf-psa-crypto/configs/ext/crypto_config_profile_medium.h"
Minos Galanakis4f619e12024-11-14 14:56:47 +00001247 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 +02001248 make
1249
1250 msg "test: configs/config-tfm.h - unit tests"
1251 make test
1252}
1253
Minos Galanakis471b34c2024-07-26 15:39:24 +01001254# Helper for setting common configurations between:
1255# - component_test_tfm_config_p256m_driver_accel_ec()
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001256# - component_test_tfm_config_no_p256m()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001257common_tfm_config () {
1258 # Enable TF-M config
1259 cp configs/config-tfm.h "$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001260 cp tf-psa-crypto/configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001261
Minos Galanakis471b34c2024-07-26 15:39:24 +01001262 # Config adjustment for better test coverage in our environment.
1263 # This is not needed just to build and pass tests.
1264 #
1265 # Enable filesystem I/O for the benefit of PK parse/write tests.
Minos Galanakis5da58e52024-11-07 15:35:33 +00001266 sed -i '/PROFILE_M_PSA_CRYPTO_CONFIG_H/i #define MBEDTLS_FS_IO' "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001267}
1268
1269# Keep this in sync with component_test_tfm_config() as they are both meant
1270# to be used in analyze_outcomes.py for driver's coverage analysis.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001271component_test_tfm_config_p256m_driver_accel_ec () {
1272 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1273
1274 common_tfm_config
1275
1276 # Build crypto library
Ronald Cron401f20f2025-09-02 14:50:10 +02001277 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../framework/tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001278
1279 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1280 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1281 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1282 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001283 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001284 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1285 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001286 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1287 # Check that p256m was built
1288 grep -q p256_ecdsa_ library/libmbedcrypto.a
1289
1290 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1291 # files, so we want to ensure that it has not be re-enabled accidentally.
1292 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1293
1294 # Run the tests
1295 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
Ronald Cron401f20f2025-09-02 14:50:10 +02001296 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001297}
1298
1299# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1300# they are both meant to be used in analyze_outcomes.py for driver's coverage
1301# analysis.
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001302component_test_tfm_config_no_p256m () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001303 common_tfm_config
1304
1305 # Disable P256M driver, which is on by default, so that analyze_outcomes
1306 # can compare this test with test_tfm_config_p256m_driver_accel_ec
Ben Taylora2aa7da2025-09-04 11:22:52 +01001307 scripts/config.py -f "$CRYPTO_CONFIG_H" unset MBEDTLS_PSA_P256M_DRIVER_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001308
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001309 msg "build: TF-M config without p256m"
Ronald Cron401f20f2025-09-02 14:50:10 +02001310 $MAKE_COMMAND CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' tests
Minos Galanakis471b34c2024-07-26 15:39:24 +01001311
1312 # Check that p256m was not built
1313 not grep p256_ecdsa_ library/libmbedcrypto.a
1314
1315 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1316 # files, so we want to ensure that it has not be re-enabled accidentally.
1317 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1318
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001319 msg "test: TF-M config without p256m"
Ronald Cron401f20f2025-09-02 14:50:10 +02001320 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001321}
1322
Minos Galanakis471b34c2024-07-26 15:39:24 +01001323# This is an helper used by:
1324# - component_test_psa_ecc_key_pair_no_derive
1325# - component_test_psa_ecc_key_pair_no_generate
1326# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1327# enabled, but one. Input arguments are as follows:
Gilles Peskinefef912c2024-09-20 16:07:09 +02001328# - $1 is the configuration to start from
1329# - $2 is the key type under test, i.e. ECC/RSA/DH
1330# - $3 is the key option to be unset (i.e. generate, derive, etc)
Minos Galanakisf78447f2024-07-26 20:49:51 +01001331build_and_test_psa_want_key_pair_partial () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001332 base_config=$1
1333 key_type=$2
1334 unset_option=$3
Minos Galanakis471b34c2024-07-26 15:39:24 +01001335 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1336
Gilles Peskinefef912c2024-09-20 16:07:09 +02001337 msg "build: $base_config - ${disabled_psa_want}"
1338 scripts/config.py "$base_config"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001339
1340 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1341 # crypto_config.h so we just disable the one we don't want.
David Horstmannb907dbc2025-08-27 15:19:40 +01001342 scripts/config.py unset "$disabled_psa_want"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001343
Ronald Cron401f20f2025-09-02 14:50:10 +02001344 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001345
Gilles Peskinefef912c2024-09-20 16:07:09 +02001346 msg "test: $base_config - ${disabled_psa_want}"
Ronald Cron401f20f2025-09-02 14:50:10 +02001347 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001348}
1349
Minos Galanakisf78447f2024-07-26 20:49:51 +01001350component_test_psa_ecc_key_pair_no_derive () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001351 build_and_test_psa_want_key_pair_partial full "ECC" "DERIVE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001352}
1353
Minos Galanakisf78447f2024-07-26 20:49:51 +01001354component_test_psa_ecc_key_pair_no_generate () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001355 # TLS needs ECC key generation whenever ephemeral ECDH is enabled.
1356 # We don't have proper guards for configurations with ECC key generation
1357 # disabled (https://github.com/Mbed-TLS/mbedtls/issues/9481). Until
1358 # then (if ever), just test the crypto part of the library.
1359 build_and_test_psa_want_key_pair_partial crypto_full "ECC" "GENERATE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001360}
1361
1362config_psa_crypto_accel_rsa () {
1363 driver_only=$1
1364
1365 # Start from crypto_full config (no X.509, no TLS)
1366 helper_libtestdriver1_adjust_config "crypto_full"
1367
1368 if [ "$driver_only" -eq 1 ]; then
Minos Galanakis471b34c2024-07-26 15:39:24 +01001369 # We need PEM parsing in the test library as well to support the import
1370 # of PEM encoded RSA keys.
Minos Galanakis23452f52024-11-28 17:48:14 +00001371 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1372 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
Minos Galanakis471b34c2024-07-26 15:39:24 +01001373 fi
1374}
1375
1376component_test_psa_crypto_config_accel_rsa_crypto () {
1377 msg "build: crypto_full with accelerated RSA"
1378
1379 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1380 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1381 KEY_TYPE_RSA_PUBLIC_KEY \
1382 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1383 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1384 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1385 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1386
1387 # Configure
1388 # ---------
1389
1390 config_psa_crypto_accel_rsa 1
1391
1392 # Build
1393 # -----
1394
1395 # These hashes are needed for unit tests.
1396 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1397 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1398 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1399
1400 helper_libtestdriver1_make_main "$loc_accel_list"
1401
1402 # Make sure this was not re-enabled by accident (additive config)
1403 not grep mbedtls_rsa ${BUILTIN_SRC_PATH}/rsa.o
1404
1405 # Run the tests
1406 # -------------
1407
1408 msg "test: crypto_full with accelerated RSA"
Ronald Cron401f20f2025-09-02 14:50:10 +02001409 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001410}
1411
1412component_test_psa_crypto_config_reference_rsa_crypto () {
1413 msg "build: crypto_full with non-accelerated RSA"
1414
1415 # Configure
1416 # ---------
1417 config_psa_crypto_accel_rsa 0
1418
1419 # Build
1420 # -----
Ronald Cron401f20f2025-09-02 14:50:10 +02001421 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001422
1423 # Run the tests
1424 # -------------
1425 msg "test: crypto_full with non-accelerated RSA"
Ronald Cron401f20f2025-09-02 14:50:10 +02001426 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001427}
1428
1429# This is a temporary test to verify that full RSA support is present even when
1430# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001431component_test_new_psa_want_key_pair_symbol () {
Ronald Cron892bb612025-07-21 14:26:27 +02001432 msg "Build: crypto config - PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001433
1434 # Create a temporary output file unless there is already one set
1435 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1436 REMOVE_OUTCOME_ON_EXIT="no"
1437 else
1438 REMOVE_OUTCOME_ON_EXIT="yes"
1439 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1440 export MBEDTLS_TEST_OUTCOME_FILE
1441 fi
1442
1443 # Start from crypto configuration
1444 scripts/config.py crypto
1445
Ronald Cron919a1e42025-09-15 14:39:26 +02001446 # Remove RSA dependencies
Minos Galanakis471b34c2024-07-26 15:39:24 +01001447 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001448 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1449
Minos Galanakis471b34c2024-07-26 15:39:24 +01001450 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
1451 # that proper translations is done in crypto_legacy.h.
David Horstmannb907dbc2025-08-27 15:19:40 +01001452 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
1453 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
1454 scripts/config.py unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Minos Galanakis471b34c2024-07-26 15:39:24 +01001455
Ronald Cron401f20f2025-09-02 14:50:10 +02001456 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001457
Ronald Cron892bb612025-07-21 14:26:27 +02001458 msg "Test: crypto config - PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Ronald Cron401f20f2025-09-02 14:50:10 +02001459 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001460
1461 # Parse only 1 relevant line from the outcome file, i.e. a test which is
1462 # performing RSA signature.
1463 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
1464 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
1465
1466 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
1467 rm $MBEDTLS_TEST_OUTCOME_FILE
1468 fi
1469}
1470
1471component_test_psa_crypto_config_accel_hash () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001472 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001473
1474 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1475 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1476 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1477
1478 # Configure
1479 # ---------
1480
1481 # Start from default config (no USE_PSA)
1482 helper_libtestdriver1_adjust_config "default"
1483
Minos Galanakis471b34c2024-07-26 15:39:24 +01001484 # Build
1485 # -----
1486
1487 helper_libtestdriver1_make_drivers "$loc_accel_list"
1488
1489 helper_libtestdriver1_make_main "$loc_accel_list"
1490
1491 # There's a risk of something getting re-enabled via config_psa.h;
1492 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1493 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1494 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1495 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1496 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1497 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1498
1499 # Run the tests
1500 # -------------
1501
Ronald Cron93ba6252024-09-05 10:37:14 +02001502 msg "test: accelerated hash"
Ronald Cron401f20f2025-09-02 14:50:10 +02001503 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001504}
1505
1506# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001507config_psa_crypto_hash_use_psa () {
1508 driver_only="$1"
1509 # start with config full for maximum coverage (also enables USE_PSA)
1510 helper_libtestdriver1_adjust_config "full"
1511 if [ "$driver_only" -eq 1 ]; then
1512 # disable the built-in implementation of hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +01001513 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Minos Galanakis471b34c2024-07-26 15:39:24 +01001514 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Minos Galanakis471b34c2024-07-26 15:39:24 +01001515 fi
1516}
1517
1518# Note that component_test_psa_crypto_config_reference_hash_use_psa
1519# is related to this component and both components need to be kept in sync.
1520# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001521component_test_psa_crypto_config_accel_hash_use_psa () {
1522 msg "test: full with accelerated hashes"
1523
1524 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1525 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1526 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1527
1528 # Configure
1529 # ---------
1530
1531 config_psa_crypto_hash_use_psa 1
1532
1533 # Build
1534 # -----
1535
1536 helper_libtestdriver1_make_drivers "$loc_accel_list"
1537
1538 helper_libtestdriver1_make_main "$loc_accel_list"
1539
1540 # There's a risk of something getting re-enabled via config_psa.h;
1541 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1542 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1543 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1544 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1545 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1546 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1547
1548 # Run the tests
1549 # -------------
1550
1551 msg "test: full with accelerated hashes"
Ronald Cron401f20f2025-09-02 14:50:10 +02001552 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001553
1554 # This is mostly useful so that we can later compare outcome files with
1555 # the reference config in analyze_outcomes.py, to check that the
1556 # dependency declarations in ssl-opt.sh and in TLS code are correct.
1557 msg "test: ssl-opt.sh, full with accelerated hashes"
1558 tests/ssl-opt.sh
1559
1560 # This is to make sure all ciphersuites are exercised, but we don't need
1561 # interop testing (besides, we already got some from ssl-opt.sh).
1562 msg "test: compat.sh, full with accelerated hashes"
1563 tests/compat.sh -p mbedTLS -V YES
1564}
1565
1566# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
1567# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
1568# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
1569# Both components need to be kept in sync.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001570component_test_psa_crypto_config_reference_hash_use_psa () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001571 msg "test: full without accelerated hashes"
1572
1573 config_psa_crypto_hash_use_psa 0
1574
Ronald Cron401f20f2025-09-02 14:50:10 +02001575 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001576
1577 msg "test: full without accelerated hashes"
Ronald Cron401f20f2025-09-02 14:50:10 +02001578 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001579
1580 msg "test: ssl-opt.sh, full without accelerated hashes"
1581 tests/ssl-opt.sh
1582}
1583
1584# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001585config_psa_crypto_hmac_use_psa () {
1586 driver_only="$1"
1587 # start with config full for maximum coverage (also enables USE_PSA)
1588 helper_libtestdriver1_adjust_config "full"
1589
1590 if [ "$driver_only" -eq 1 ]; then
1591 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
1592 # is still enabled though (for ENTROPY_C among others).
1593 scripts/config.py unset MBEDTLS_MD_C
Ronald Cron772a8ad2025-07-21 12:36:29 +02001594 # Also disable the configuration options that tune the builtin hashes,
1595 # since those hashes are disabled.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001596 scripts/config.py unset-all MBEDTLS_SHA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001597 fi
1598
1599 # Direct dependencies of MD_C. We disable them also in the reference
1600 # component to work with the same set of features.
1601 scripts/config.py unset MBEDTLS_PKCS7_C
1602 scripts/config.py unset MBEDTLS_PKCS5_C
1603 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1604 scripts/config.py unset MBEDTLS_HKDF_C
1605 # Dependencies of HMAC_DRBG
David Horstmannb907dbc2025-08-27 15:19:40 +01001606 scripts/config.py unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001607}
1608
Minos Galanakisf78447f2024-07-26 20:49:51 +01001609component_test_psa_crypto_config_accel_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001610 msg "test: full with accelerated hmac"
1611
1612 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
1613 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1614 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1615 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1616
1617 # Configure
1618 # ---------
1619
1620 config_psa_crypto_hmac_use_psa 1
1621
1622 # Build
1623 # -----
1624
1625 helper_libtestdriver1_make_drivers "$loc_accel_list"
1626
1627 helper_libtestdriver1_make_main "$loc_accel_list"
1628
1629 # Ensure that built-in support for HMAC is disabled.
1630 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
1631
1632 # Run the tests
1633 # -------------
1634
1635 msg "test: full with accelerated hmac"
Ronald Cron401f20f2025-09-02 14:50:10 +02001636 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001637}
1638
Minos Galanakisf78447f2024-07-26 20:49:51 +01001639component_test_psa_crypto_config_reference_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001640 msg "test: full without accelerated hmac"
1641
1642 config_psa_crypto_hmac_use_psa 0
1643
Ronald Cron401f20f2025-09-02 14:50:10 +02001644 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001645
1646 msg "test: full without accelerated hmac"
Ronald Cron401f20f2025-09-02 14:50:10 +02001647 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001648}
1649
Minos Galanakis471b34c2024-07-26 15:39:24 +01001650component_test_psa_crypto_config_accel_aead () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001651 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001652
1653 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
1654 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1655
1656 # Configure
1657 # ---------
1658
1659 # Start from full config
1660 helper_libtestdriver1_adjust_config "full"
1661
Minos Galanakis471b34c2024-07-26 15:39:24 +01001662 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
David Horstmannb907dbc2025-08-27 15:19:40 +01001663 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
Minos Galanakis471b34c2024-07-26 15:39:24 +01001664
1665 # Build
1666 # -----
1667
1668 helper_libtestdriver1_make_drivers "$loc_accel_list"
1669
1670 helper_libtestdriver1_make_main "$loc_accel_list"
1671
1672 # Make sure this was not re-enabled by accident (additive config)
1673 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1674 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1675 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1676
1677 # Run the tests
1678 # -------------
1679
Ronald Cron93ba6252024-09-05 10:37:14 +02001680 msg "test: accelerated AEAD"
Ronald Cron401f20f2025-09-02 14:50:10 +02001681 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001682}
1683
1684# This is a common configuration function used in:
1685# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1686# - component_test_psa_crypto_config_reference_cipher_aead_cmac
Minos Galanakisf78447f2024-07-26 20:49:51 +01001687common_psa_crypto_config_accel_cipher_aead_cmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001688 # Start from the full config
1689 helper_libtestdriver1_adjust_config "full"
1690
1691 scripts/config.py unset MBEDTLS_NIST_KW_C
1692}
1693
1694# The 2 following test components, i.e.
1695# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1696# - component_test_psa_crypto_config_reference_cipher_aead_cmac
1697# are meant to be used together in analyze_outcomes.py script in order to test
1698# driver's coverage for ciphers and AEADs.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001699component_test_psa_crypto_config_accel_cipher_aead_cmac () {
1700 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
1701
1702 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
1703 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
1704 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
Ari Weiler-Ofek86422e52025-07-04 14:43:30 +01001705 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001706
1707 # Configure
1708 # ---------
1709
1710 common_psa_crypto_config_accel_cipher_aead_cmac
1711
Ari Weiler-Ofek5d8d2992025-07-07 23:20:29 +01001712 # Disable DES, if it still exists.
1713 # This can be removed once we remove DES from the library.
1714 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
1715
Minos Galanakis471b34c2024-07-26 15:39:24 +01001716 # Build
1717 # -----
1718
1719 helper_libtestdriver1_make_drivers "$loc_accel_list"
1720
1721 helper_libtestdriver1_make_main "$loc_accel_list"
1722
1723 # Make sure this was not re-enabled by accident (additive config)
1724 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001725 not grep mbedtls_aes ${BUILTIN_SRC_PATH}/aes.o
1726 not grep mbedtls_aria ${BUILTIN_SRC_PATH}/aria.o
1727 not grep mbedtls_camellia ${BUILTIN_SRC_PATH}/camellia.o
1728 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1729 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1730 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1731 not grep mbedtls_cmac ${BUILTIN_SRC_PATH}/cmac.o
Ronald Cronb5c6fcc2025-07-10 13:40:00 +02001732 not grep mbedtls_poly1305 ${BUILTIN_SRC_PATH}/poly1305.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001733
1734 # Run the tests
1735 # -------------
1736
1737 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
Ronald Cron401f20f2025-09-02 14:50:10 +02001738 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001739
1740 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
Ronald Cronbd28acf2025-07-10 09:53:50 +02001741 # Exclude password-protected key tests — they require built-in CBC and AES.
1742 tests/ssl-opt.sh -e "TLS: password protected"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001743
1744 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
1745 tests/compat.sh -V NO -p mbedTLS
1746}
1747
1748component_test_psa_crypto_config_reference_cipher_aead_cmac () {
1749 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
1750 common_psa_crypto_config_accel_cipher_aead_cmac
1751
Ari Weiler-Ofek5d8d2992025-07-07 23:20:29 +01001752 # Disable DES, if it still exists.
1753 # This can be removed once we remove DES from the library.
1754 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
1755
Ronald Cron401f20f2025-09-02 14:50:10 +02001756 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001757
1758 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
Ronald Cron401f20f2025-09-02 14:50:10 +02001759 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001760
1761 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
Ronald Cronbd28acf2025-07-10 09:53:50 +02001762 # Exclude password-protected key tests as in test_psa_crypto_config_accel_cipher_aead_cmac.
1763 tests/ssl-opt.sh -e "TLS: password protected"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001764
1765 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
1766 tests/compat.sh -V NO -p mbedTLS
1767}
1768
Minos Galanakisf78447f2024-07-26 20:49:51 +01001769common_block_cipher_dispatch () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001770 TEST_WITH_DRIVER="$1"
1771
1772 # Start from the full config
1773 helper_libtestdriver1_adjust_config "full"
1774
Minos Galanakis471b34c2024-07-26 15:39:24 +01001775 # Disable cipher's modes that, when not accelerated, cause
1776 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
1777 # Keep this also in the reference component in order to skip the same tests
1778 # that were skipped in the accelerated one.
David Horstmannb907dbc2025-08-27 15:19:40 +01001779 scripts/config.py unset PSA_WANT_ALG_CTR
1780 scripts/config.py unset PSA_WANT_ALG_CFB
1781 scripts/config.py unset PSA_WANT_ALG_OFB
1782 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
1783 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
1784 scripts/config.py unset PSA_WANT_ALG_CMAC
1785 scripts/config.py unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1786 scripts/config.py unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
Minos Galanakis471b34c2024-07-26 15:39:24 +01001787
1788 # Disable direct dependency on AES_C
1789 scripts/config.py unset MBEDTLS_NIST_KW_C
1790
1791 # Prevent the cipher module from using deprecated PSA path. The reason is
1792 # that otherwise there will be tests relying on "aes_info" (defined in
1793 # "cipher_wrap.c") whose functions are not available when AES_C is
1794 # not defined. ARIA and Camellia are not a problem in this case because
1795 # the PSA path is not tested for these key types.
1796 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1797}
1798
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02001799component_test_full_block_cipher_psa_dispatch_static_keystore () {
1800 msg "build: full + PSA dispatch in block_cipher with static keystore"
1801 # Check that the static key store works well when CTR_DRBG uses a
1802 # PSA key for AES.
1803 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
1804
1805 loc_accel_list="ALG_ECB_NO_PADDING \
1806 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1807
1808 # Configure
1809 # ---------
1810
1811 common_block_cipher_dispatch 1
1812
1813 # Build
1814 # -----
1815
1816 helper_libtestdriver1_make_drivers "$loc_accel_list"
1817
1818 helper_libtestdriver1_make_main "$loc_accel_list"
1819
1820 # Make sure disabled components were not re-enabled by accident (additive
1821 # config)
1822 not grep mbedtls_aes_ library/aes.o
1823 not grep mbedtls_aria_ library/aria.o
1824 not grep mbedtls_camellia_ library/camellia.o
1825
1826 # Run the tests
1827 # -------------
1828
1829 msg "test: full + PSA dispatch in block_cipher with static keystore"
Ronald Cron401f20f2025-09-02 14:50:10 +02001830 $MAKE_COMMAND test
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02001831}
1832
Minos Galanakis471b34c2024-07-26 15:39:24 +01001833component_test_full_block_cipher_psa_dispatch () {
1834 msg "build: full + PSA dispatch in block_cipher"
1835
1836 loc_accel_list="ALG_ECB_NO_PADDING \
1837 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1838
1839 # Configure
1840 # ---------
1841
1842 common_block_cipher_dispatch 1
1843
1844 # Build
1845 # -----
1846
1847 helper_libtestdriver1_make_drivers "$loc_accel_list"
1848
1849 helper_libtestdriver1_make_main "$loc_accel_list"
1850
1851 # Make sure disabled components were not re-enabled by accident (additive
1852 # config)
1853 not grep mbedtls_aes_ ${BUILTIN_SRC_PATH}/aes.o
1854 not grep mbedtls_aria_ ${BUILTIN_SRC_PATH}/aria.o
1855 not grep mbedtls_camellia_ ${BUILTIN_SRC_PATH}/camellia.o
1856
1857 # Run the tests
1858 # -------------
1859
1860 msg "test: full + PSA dispatch in block_cipher"
Ronald Cron401f20f2025-09-02 14:50:10 +02001861 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001862}
1863
1864# This is the reference component of component_test_full_block_cipher_psa_dispatch
Minos Galanakis471b34c2024-07-26 15:39:24 +01001865component_test_full_block_cipher_legacy_dispatch () {
1866 msg "build: full + legacy dispatch in block_cipher"
1867
1868 common_block_cipher_dispatch 0
1869
Ronald Cron401f20f2025-09-02 14:50:10 +02001870 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001871
1872 msg "test: full + legacy dispatch in block_cipher"
Ronald Cron401f20f2025-09-02 14:50:10 +02001873 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001874}
1875
Minos Galanakisf78447f2024-07-26 20:49:51 +01001876component_test_aead_chachapoly_disabled () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001877 msg "build: full minus CHACHAPOLY"
1878 scripts/config.py full
David Horstmannb907dbc2025-08-27 15:19:40 +01001879 scripts/config.py unset PSA_WANT_ALG_CHACHA20_POLY1305
Ronald Cron401f20f2025-09-02 14:50:10 +02001880 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001881
1882 msg "test: full minus CHACHAPOLY"
Ronald Cron401f20f2025-09-02 14:50:10 +02001883 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001884}
1885
Minos Galanakisf78447f2024-07-26 20:49:51 +01001886component_test_aead_only_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001887 msg "build: full minus CHACHAPOLY and GCM"
1888 scripts/config.py full
David Horstmannb907dbc2025-08-27 15:19:40 +01001889 scripts/config.py unset PSA_WANT_ALG_CHACHA20_POLY1305
1890 scripts/config.py unset PSA_WANT_ALG_GCM
Ronald Cron401f20f2025-09-02 14:50:10 +02001891 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001892
1893 msg "test: full minus CHACHAPOLY and GCM"
Ronald Cron401f20f2025-09-02 14:50:10 +02001894 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001895}
1896
Minos Galanakisf78447f2024-07-26 20:49:51 +01001897component_test_ccm_aes_sha256 () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001898 msg "build: CCM + AES + SHA256 configuration"
1899
Minos Galanakisa17ffc72024-12-02 23:57:30 +00001900 # Setting a blank config disables everyhing in the library side.
1901 echo '#define MBEDTLS_CONFIG_H ' >"$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001902 cp tf-psa-crypto/configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
Ronald Cron9d262d72024-12-06 17:41:26 +01001903
Ronald Cron401f20f2025-09-02 14:50:10 +02001904 $MAKE_COMMAND
Minos Galanakis471b34c2024-07-26 15:39:24 +01001905 msg "test: CCM + AES + SHA256 configuration"
Ronald Cron401f20f2025-09-02 14:50:10 +02001906 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01001907}
1908
1909# Test that the given .o file builds with all (valid) combinations of the given options.
1910#
1911# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
1912#
1913# The validator function is the name of a function to validate the combination of options.
1914# It may be "" if all combinations are valid.
1915# It receives a string containing a combination of options, as passed to the compiler,
1916# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001917build_test_config_combos () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001918 file=$1
1919 shift
1920 validate_options=$1
1921 shift
1922 options=("$@")
1923
1924 # clear all of the options so that they can be overridden on the clang commandline
1925 for opt in "${options[@]}"; do
1926 ./scripts/config.py unset ${opt}
1927 done
1928
1929 # enter the library directory
1930 cd library
1931
1932 # The most common issue is unused variables/functions, so ensure -Wunused is set.
1933 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
1934
1935 # Extract the command generated by the Makefile to build the target file.
1936 # This ensures that we have any include paths, macro definitions, etc
1937 # that may be applied by make.
1938 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
1939 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
1940
1941 makefile=$(TMPDIR=. mktemp)
1942 deps=""
1943
1944 len=${#options[@]}
1945 source_file=../${file%.o}.c
1946
1947 targets=0
1948 echo 'include Makefile' >${makefile}
1949
1950 for ((i = 0; i < $((2**${len})); i++)); do
1951 # generate each of 2^n combinations of options
1952 # each bit of $i is used to determine if options[i] will be set or not
1953 target="t"
1954 clang_args=""
1955 for ((j = 0; j < ${len}; j++)); do
1956 if (((i >> j) & 1)); then
1957 opt=-D${options[$j]}
1958 clang_args="${clang_args} ${opt}"
1959 target="${target}${opt}"
1960 fi
1961 done
1962
1963 # if combination is not known to be invalid, add it to the makefile
1964 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
1965 cmd="${compile_cmd} ${clang_args}"
1966 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
1967
1968 deps="${deps} ${target}"
1969 ((++targets))
1970 fi
1971 done
1972
1973 echo "build_test_config_combos: ${deps}" >> ${makefile}
1974
1975 # execute all of the commands via Make (probably in parallel)
1976 make -s -f ${makefile} build_test_config_combos
1977 echo "$targets targets checked"
1978
1979 # clean up the temporary makefile
1980 rm ${makefile}
1981}
1982
Minos Galanakisf78447f2024-07-26 20:49:51 +01001983validate_aes_config_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001984 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
1985 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
1986 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
1987 return 1
1988 fi
1989 fi
1990 return 0
1991}
1992
Minos Galanakisf78447f2024-07-26 20:49:51 +01001993component_build_aes_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001994 # 18s - around 90ms per clang invocation on M1 Pro
1995 #
1996 # aes.o has many #if defined(...) guards that intersect in complex ways.
1997 # Test that all the combinations build cleanly.
1998
1999 MBEDTLS_ROOT_DIR="$PWD"
2000 msg "build: aes.o for all combinations of relevant config options"
2001
2002 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002003 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002004 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2005 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2006
2007 cd "$MBEDTLS_ROOT_DIR"
2008 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
2009
Ari Weiler-Ofek86422e52025-07-04 14:43:30 +01002010 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW,
Minos Galanakis471b34c2024-07-26 15:39:24 +01002011 # manually set or unset those configurations to check
2012 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
2013 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Minos Galanakis471b34c2024-07-26 15:39:24 +01002014 scripts/config.py unset MBEDTLS_NIST_KW_C
Ronald Cron54d1eec2024-09-06 09:55:38 +02002015
David Horstmann7cbeedc2025-08-26 17:26:45 +01002016 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
2017 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
2018 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
2019 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
Ronald Cron54d1eec2024-09-06 09:55:38 +02002020
Minos Galanakis471b34c2024-07-26 15:39:24 +01002021 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002022 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002023 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2024 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2025}
2026
Minos Galanakisf78447f2024-07-26 20:49:51 +01002027component_test_sha3_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002028 msg "sha3 loop unroll variations"
2029
2030 # define minimal config sufficient to test SHA3
Ronald Crone7f289e2024-09-06 11:02:47 +02002031 cat > include/mbedtls/mbedtls_config.h << END
Ronald Crone7f289e2024-09-06 11:02:47 +02002032END
2033
2034 cat > tf-psa-crypto/include/psa/crypto_config.h << END
2035 #define PSA_WANT_ALG_SHA_256 1
2036 #define PSA_WANT_ALG_SHA3_224 1
2037 #define PSA_WANT_ALG_SHA3_256 1
2038 #define PSA_WANT_ALG_SHA3_384 1
2039 #define PSA_WANT_ALG_SHA3_512 1
Ronald Cron06680362025-07-21 15:21:22 +02002040 #define PSA_WANT_KEY_TYPE_AES 1
Ronald Cron3dd1d3d2024-12-05 15:12:06 +01002041 #define MBEDTLS_PSA_CRYPTO_C
Ronald Cron3b306432025-09-02 18:30:08 +02002042 #define MBEDTLS_CTR_DRBG_C
2043 #define MBEDTLS_PSA_BUILTIN_GET_ENTROPY
Ronald Cron3dd1d3d2024-12-05 15:12:06 +01002044 #define MBEDTLS_SELF_TEST
Minos Galanakis471b34c2024-07-26 15:39:24 +01002045END
2046
2047 msg "all loops unrolled"
Ronald Cron401f20f2025-09-02 14:50:10 +02002048 $MAKE_COMMAND clean
Minos Galanakis471b34c2024-07-26 15:39:24 +01002049 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"
2050 ./tf-psa-crypto/tests/test_suite_shax
2051
2052 msg "all loops rolled up"
Ronald Cron401f20f2025-09-02 14:50:10 +02002053 $MAKE_COMMAND clean
Minos Galanakis471b34c2024-07-26 15:39:24 +01002054 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"
2055 ./tf-psa-crypto/tests/test_suite_shax
2056}
2057
Minos Galanakisf699d512024-08-01 11:32:30 +01002058support_build_aes_aesce_armcc () {
2059 support_build_armcc
2060}
2061
Minos Galanakis471b34c2024-07-26 15:39:24 +01002062# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2063component_build_aes_aesce_armcc () {
2064 msg "Build: AESCE test on arm64 platform without plain C."
2065 scripts/config.py baremetal
2066
2067 # armc[56] don't support SHA-512 intrinsics
2068 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2069
2070 # Stop armclang warning about feature detection for A64_CRYPTO.
2071 # With this enabled, the library does build correctly under armclang,
2072 # but in baremetal builds (as tested here), feature detection is
2073 # unavailable, and the user is notified via a #warning. So enabling
2074 # this feature would prevent us from building with -Werror on
2075 # armclang. Tracked in #7198.
2076 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2077 scripts/config.py set MBEDTLS_HAVE_ASM
2078
2079 msg "AESCE, build with default configuration."
2080 scripts/config.py set MBEDTLS_AESCE_C
2081 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002082 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002083
2084 msg "AESCE, build AESCE only"
2085 scripts/config.py set MBEDTLS_AESCE_C
2086 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002087 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002088}
2089
Minos Galanakis471b34c2024-07-26 15:39:24 +01002090component_test_aes_only_128_bit_keys () {
2091 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2092 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002093 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002094
Ronald Cron401f20f2025-09-02 14:50:10 +02002095 $MAKE_COMMAND CFLAGS='-O2 -Werror -Wall -Wextra'
Minos Galanakis471b34c2024-07-26 15:39:24 +01002096
2097 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
Ronald Cron401f20f2025-09-02 14:50:10 +02002098 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002099}
2100
2101component_test_no_ctr_drbg_aes_only_128_bit_keys () {
2102 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2103 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002104 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002105 scripts/config.py unset MBEDTLS_CTR_DRBG_C
2106
Ronald Cron401f20f2025-09-02 14:50:10 +02002107 $MAKE_COMMAND CC=clang CFLAGS='-Werror -Wall -Wextra'
Minos Galanakis471b34c2024-07-26 15:39:24 +01002108
2109 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
Ronald Cron401f20f2025-09-02 14:50:10 +02002110 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002111}
2112
2113component_test_aes_only_128_bit_keys_have_builtins () {
2114 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2115 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Minos Galanakis2fc59942025-07-09 18:20:48 +03002116 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakis471b34c2024-07-26 15:39:24 +01002117 scripts/config.py unset MBEDTLS_AESNI_C
2118 scripts/config.py unset MBEDTLS_AESCE_C
2119
Ronald Cron401f20f2025-09-02 14:50:10 +02002120 $MAKE_COMMAND CFLAGS='-O2 -Werror -Wall -Wextra'
Minos Galanakis471b34c2024-07-26 15:39:24 +01002121
2122 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
Ronald Cron401f20f2025-09-02 14:50:10 +02002123 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002124
2125 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2126 programs/test/selftest
2127}
2128
2129component_test_gcm_largetable () {
2130 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2131 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
2132 scripts/config.py unset MBEDTLS_AESNI_C
2133 scripts/config.py unset MBEDTLS_AESCE_C
2134
Ronald Cron401f20f2025-09-02 14:50:10 +02002135 $MAKE_COMMAND CFLAGS='-O2 -Werror -Wall -Wextra'
Minos Galanakis471b34c2024-07-26 15:39:24 +01002136
2137 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
Ronald Cron401f20f2025-09-02 14:50:10 +02002138 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002139}
2140
2141component_test_aes_fewer_tables () {
2142 msg "build: default config with AES_FEWER_TABLES enabled"
2143 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Ronald Cron401f20f2025-09-02 14:50:10 +02002144 $MAKE_COMMAND CFLAGS='-O2 -Werror -Wall -Wextra'
Minos Galanakis471b34c2024-07-26 15:39:24 +01002145
2146 msg "test: AES_FEWER_TABLES"
Ronald Cron401f20f2025-09-02 14:50:10 +02002147 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002148}
2149
2150component_test_aes_rom_tables () {
2151 msg "build: default config with AES_ROM_TABLES enabled"
2152 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Ronald Cron401f20f2025-09-02 14:50:10 +02002153 $MAKE_COMMAND CFLAGS='-O2 -Werror -Wall -Wextra'
Minos Galanakis471b34c2024-07-26 15:39:24 +01002154
2155 msg "test: AES_ROM_TABLES"
Ronald Cron401f20f2025-09-02 14:50:10 +02002156 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002157}
2158
2159component_test_aes_fewer_tables_and_rom_tables () {
2160 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
2161 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2162 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Ronald Cron401f20f2025-09-02 14:50:10 +02002163 $MAKE_COMMAND CFLAGS='-O2 -Werror -Wall -Wextra'
Minos Galanakis471b34c2024-07-26 15:39:24 +01002164
2165 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
Ronald Cron401f20f2025-09-02 14:50:10 +02002166 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002167}
2168
Ronald Cron66040472024-09-06 10:14:38 +02002169# helper for component_test_block_cipher_no_decrypt_aesni() which:
Minos Galanakis471b34c2024-07-26 15:39:24 +01002170# - enable/disable the list of config options passed from -s/-u respectively.
2171# - build
2172# - test for tests_suite_xxx
2173# - selftest
2174#
2175# Usage: helper_block_cipher_no_decrypt_build_test
2176# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
2177# Options: -s set_opts the list of config options to enable
2178# -u unset_opts the list of config options to disable
2179# -c cflags the list of options passed to CFLAGS
2180# -l ldflags the list of options passed to LDFLAGS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002181helper_block_cipher_no_decrypt_build_test () {
2182 while [ $# -gt 0 ]; do
2183 case "$1" in
2184 -s)
2185 shift; local set_opts="$1";;
2186 -u)
2187 shift; local unset_opts="$1";;
2188 -c)
2189 shift; local cflags="-Werror -Wall -Wextra $1";;
2190 -l)
2191 shift; local ldflags="$1";;
2192 esac
2193 shift
2194 done
2195 set_opts="${set_opts:-}"
2196 unset_opts="${unset_opts:-}"
2197 cflags="${cflags:-}"
2198 ldflags="${ldflags:-}"
2199
2200 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
2201 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
2202
2203 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 +02002204 $MAKE_COMMAND clean
2205 $MAKE_COMMAND CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002206
2207 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2208 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2209 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2210 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2211 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2212 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2213 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
2214 not grep mbedtls_aesni_inverse_key ${BUILTIN_SRC_PATH}/aesni.o
2215
2216 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 +02002217 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002218
2219 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2220 programs/test/selftest
2221}
2222
Ronald Cron66040472024-09-06 10:14:38 +02002223# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
2224config_block_cipher_no_decrypt () {
2225 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Ronald Cron66040472024-09-06 10:14:38 +02002226 scripts/config.py unset MBEDTLS_NIST_KW_C
2227
2228 # Enable support for cryptographic mechanisms through the PSA API.
2229 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
David Horstmannb907dbc2025-08-27 15:19:40 +01002230 scripts/config.py unset PSA_WANT_ALG_CBC_NO_PADDING
2231 scripts/config.py unset PSA_WANT_ALG_CBC_PKCS7
2232 scripts/config.py unset PSA_WANT_ALG_ECB_NO_PADDING
2233 scripts/config.py unset PSA_WANT_KEY_TYPE_DES
Ronald Cron66040472024-09-06 10:14:38 +02002234}
2235
2236component_test_block_cipher_no_decrypt_aesni () {
2237 # Test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics, AESNI assembly and
2238 # AES C implementation on x86_64 and with AESNI intrinsics on x86.
2239
2240 # This consistently causes an llvm crash on clang 3.8, so use gcc
2241 export CC=gcc
2242 config_block_cipher_no_decrypt
2243
Minos Galanakis471b34c2024-07-26 15:39:24 +01002244 # test AESNI intrinsics
2245 helper_block_cipher_no_decrypt_build_test \
2246 -s "MBEDTLS_AESNI_C" \
2247 -c "-mpclmul -msse2 -maes"
2248
2249 # test AESNI assembly
2250 helper_block_cipher_no_decrypt_build_test \
2251 -s "MBEDTLS_AESNI_C" \
2252 -c "-mno-pclmul -mno-sse2 -mno-aes"
2253
2254 # test AES C implementation
2255 helper_block_cipher_no_decrypt_build_test \
2256 -u "MBEDTLS_AESNI_C"
2257
2258 # test AESNI intrinsics for i386 target
2259 helper_block_cipher_no_decrypt_build_test \
2260 -s "MBEDTLS_AESNI_C" \
2261 -c "-m32 -mpclmul -msse2 -maes" \
2262 -l "-m32"
2263}
2264
Minos Galanakisf699d512024-08-01 11:32:30 +01002265support_test_block_cipher_no_decrypt_aesce_armcc () {
2266 support_build_armcc
2267}
2268
Minos Galanakis471b34c2024-07-26 15:39:24 +01002269component_test_block_cipher_no_decrypt_aesce_armcc () {
2270 scripts/config.py baremetal
2271
2272 # armc[56] don't support SHA-512 intrinsics
2273 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2274
2275 # Stop armclang warning about feature detection for A64_CRYPTO.
2276 # With this enabled, the library does build correctly under armclang,
2277 # but in baremetal builds (as tested here), feature detection is
2278 # unavailable, and the user is notified via a #warning. So enabling
2279 # this feature would prevent us from building with -Werror on
2280 # armclang. Tracked in #7198.
2281 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2282 scripts/config.py set MBEDTLS_HAVE_ASM
2283
Ronald Cron66040472024-09-06 10:14:38 +02002284 config_block_cipher_no_decrypt
Minos Galanakis471b34c2024-07-26 15:39:24 +01002285
2286 # test AESCE baremetal build
2287 scripts/config.py set MBEDTLS_AESCE_C
2288 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002289 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002290
2291 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2292 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2293 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2294 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2295 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2296 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2297 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
2298 not grep mbedtls_aesce_inverse_key ${BUILTIN_SRC_PATH}/aesce.o
2299 not grep aesce_decrypt_block ${BUILTIN_SRC_PATH}/aesce.o
2300}
2301
Ronald Cronaad5f1b2025-08-25 15:32:48 +02002302component_test_ctr_drbg_aes_256_sha_512 () {
2303 msg "build: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512 (ASan build)"
2304 scripts/config.py full
2305 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2306 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512
2307 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2308 make
2309
2310 msg "test: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512 (ASan build)"
2311 make test
2312}
2313
Minos Galanakis471b34c2024-07-26 15:39:24 +01002314component_test_ctr_drbg_aes_256_sha_256 () {
Minos Galanakisf3486e12025-08-18 14:09:26 +01002315 msg "build: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002316 scripts/config.py full
2317 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakisf3486e12025-08-18 14:09:26 +01002318 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256
Minos Galanakis471b34c2024-07-26 15:39:24 +01002319 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2320 make
2321
Minos Galanakisf3486e12025-08-18 14:09:26 +01002322 msg "test: full + MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002323 make test
2324}
2325
2326component_test_ctr_drbg_aes_128_sha_512 () {
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002327 msg "build: full + set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002328 scripts/config.py full
2329 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002330 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Ronald Cronaad5f1b2025-08-25 15:32:48 +02002331 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_512
Minos Galanakis471b34c2024-07-26 15:39:24 +01002332 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2333 make
2334
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002335 msg "test: full + set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128 (ASan build)"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002336 make test
2337}
2338
2339component_test_ctr_drbg_aes_128_sha_256 () {
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002340 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 +01002341 scripts/config.py full
2342 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002343 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_STRENGTH 128
Minos Galanakisf3486e12025-08-18 14:09:26 +01002344 scripts/config.py set MBEDTLS_PSA_CRYPTO_RNG_HASH PSA_ALG_SHA_256
Minos Galanakis471b34c2024-07-26 15:39:24 +01002345 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2346 make
2347
Minos Galanakis5dbc24a2025-08-14 14:38:15 +01002348 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 +01002349 make test
2350}
2351
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002352component_test_full_static_keystore () {
2353 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2354 scripts/config.py full
2355 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
Ronald Cron401f20f2025-09-02 14:50:10 +02002356 $MAKE_COMMAND CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002357
2358 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
Ronald Cron401f20f2025-09-02 14:50:10 +02002359 $MAKE_COMMAND test
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002360}
2361
Minos Galanakis471b34c2024-07-26 15:39:24 +01002362component_test_psa_crypto_drivers () {
Ronald Crona0afbfb2024-10-15 13:20:31 +02002363 # Test dispatch to drivers and fallbacks with
2364 # test_suite_psa_crypto_driver_wrappers test suite. The test drivers that
2365 # are wrappers around the builtin drivers are activated by
2366 # PSA_CRYPTO_DRIVER_TEST.
2367 #
2368 # For the time being, some test cases in test_suite_block_cipher and
2369 # test_suite_md.psa rely on this component to be run at least once by the
2370 # CI. This should disappear as we progress the 4.x work. See
2371 # config_adjust_test_accelerators.h for more information.
Minos Galanakis471b34c2024-07-26 15:39:24 +01002372 msg "build: full + test drivers dispatching to builtins"
2373 scripts/config.py full
Ronald Cron67cc6a72024-10-14 10:55:24 +02002374 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_CONFIG_ADJUST_TEST_ACCELERATORS"
David Horstmann5b93d972024-10-31 15:36:05 +00002375 loc_cflags="${loc_cflags} -I../framework/tests/include"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002376
Ronald Cron401f20f2025-09-02 14:50:10 +02002377 $MAKE_COMMAND CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002378
2379 msg "test: full + test drivers dispatching to builtins"
Ronald Cron401f20f2025-09-02 14:50:10 +02002380 $MAKE_COMMAND test
Minos Galanakis471b34c2024-07-26 15:39:24 +01002381}
2382
2383component_build_psa_config_file () {
Minos Galanakis4f619e12024-11-14 14:56:47 +00002384 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002385 cp "$CRYPTO_CONFIG_H" psa_test_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002386 echo '#error "TF_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
Ronald Cron401f20f2025-09-02 14:50:10 +02002387 $MAKE_COMMAND CFLAGS="-I '$PWD' -DTF_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002388 # Make sure this feature is enabled. We'll disable it in the next phase.
Ronald Cron3f120062025-07-03 14:45:51 +02002389 programs/test/query_compile_time_config PSA_WANT_ALG_CMAC
Ronald Cron401f20f2025-09-02 14:50:10 +02002390 $MAKE_COMMAND clean
Minos Galanakis471b34c2024-07-26 15:39:24 +01002391
Minos Galanakis4f619e12024-11-14 14:56:47 +00002392 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE + TF_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002393 # In the user config, disable one feature and its dependencies, which will
2394 # reflect on the mbedtls configuration so we can query it with
2395 # query_compile_time_config.
2396 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
2397 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
Ronald Cron401f20f2025-09-02 14:50:10 +02002398 $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 +02002399 not programs/test/query_compile_time_config PSA_WANT_ALG_CMAC
Minos Galanakis471b34c2024-07-26 15:39:24 +01002400
2401 rm -f psa_test_config.h psa_user_config.h
2402}
2403
2404component_build_psa_alt_headers () {
2405 msg "build: make with PSA alt headers" # ~20s
2406
2407 # Generate alternative versions of the substitutable headers with the
2408 # same content except different include guards.
David Horstmanndc459512024-11-07 17:08:11 +00002409 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 +01002410
2411 # Build the library and some programs.
2412 # Don't build the fuzzers to avoid having to go through hoops to set
2413 # a correct include path for programs/fuzz/Makefile.
Ronald Cron401f20f2025-09-02 14:50:10 +02002414 $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 +00002415 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 +01002416
2417 # Check that we're getting the alternative include guards and not the
2418 # original include guards.
2419 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
2420 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
2421 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
2422 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
2423}
2424
2425component_test_min_mpi_window_size () {
2426 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
2427 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
2428 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2429 make
2430
2431 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2432 make test
2433}
Ronald Cronf256f8a2025-07-10 17:37:18 +02002434
2435component_test_xts () {
2436 # Component dedicated to run XTS unit test cases while XTS is not
2437 # supported through the PSA API.
2438 msg "build: Default + MBEDTLS_CIPHER_MODE_XTS"
2439
Gilles Peskine9da0dce2025-09-22 15:55:10 +02002440 cat <<'EOF' >psa_user_config.h
2441#define MBEDTLS_CIPHER_MODE_XTS
2442#define TF_PSA_CRYPTO_CONFIG_CHECK_BYPASS
2443EOF
Ronald Cronf256f8a2025-07-10 17:37:18 +02002444 cmake -DTF_PSA_CRYPTO_USER_CONFIG_FILE="psa_user_config.h"
2445 make
2446
Ronald Crone0b06eb2025-07-15 08:58:32 +02002447 rm -f psa_user_config.h
2448
Ronald Cronf256f8a2025-07-10 17:37:18 +02002449 msg "test: Default + MBEDTLS_CIPHER_MODE_XTS"
2450 make test
Ronald Cronf256f8a2025-07-10 17:37:18 +02002451}