blob: cb66e371cbdde91f7f399837ec0d63aaab43f379 [file] [log] [blame]
Minos Galanakis6aab5b72024-07-25 14:24:37 +01001# components-configuration-crypto.sh
2#
3# Copyright The Mbed TLS Contributors
4# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
5
Minos Galanakis609f7492024-07-31 16:39:28 +01006# This file contains test components that are executed by all.sh
Minos Galanakis6aab5b72024-07-25 14:24:37 +01007
8################################################################
9#### Configuration Testing - Crypto
10################################################################
11
Minos Galanakis471b34c2024-07-26 15:39:24 +010012component_test_psa_crypto_key_id_encodes_owner () {
13 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
14 scripts/config.py full
15 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
16 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
17 make
18
19 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
20 make test
21}
22
23component_test_psa_assume_exclusive_buffers () {
24 msg "build: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
25 scripts/config.py full
26 scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
27 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
28 make
29
30 msg "test: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
31 make test
32}
33
Valerio Settidbb646b2024-06-20 14:40:54 +020034component_test_crypto_with_static_key_slots() {
35 msg "build: crypto full + MBEDTLS_PSA_STATIC_KEY_SLOTS"
36 scripts/config.py crypto_full
37 scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOTS
Valerio Setti4d9a8212024-08-16 12:35:24 +020038 # Intentionally set MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE to a value that
39 # is enough to contain:
40 # - all RSA public keys up to 4096 bits (max of PSA_VENDOR_RSA_MAX_KEY_BITS).
41 # - RSA key pairs up to 1024 bits, but not 2048 or larger.
42 # - all FFDH key pairs and public keys up to 8192 bits (max of PSA_VENDOR_FFDH_MAX_KEY_BITS).
43 # - all EC key pairs and public keys up to 521 bits (max of PSA_VENDOR_ECC_MAX_CURVE_BITS).
44 scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE 1212
Valerio Setti8bc81722024-08-28 05:50:45 +020045 # Disable the fully dynamic key store (default on) since it conflicts
46 # with the static behavior that we're testing here.
47 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
Valerio Settidbb646b2024-06-20 14:40:54 +020048
Valerio Setti13aadd72024-08-13 13:13:23 +020049 msg "test: crypto full + MBEDTLS_PSA_STATIC_KEY_SLOTS"
Valerio Setti2a3c9b32024-08-14 06:37:02 +020050 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" test
Valerio Settidbb646b2024-06-20 14:40:54 +020051}
52
Minos Galanakis471b34c2024-07-26 15:39:24 +010053# check_renamed_symbols HEADER LIB
54# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
Minos Galanakis609f7492024-07-31 16:39:28 +010055# name in LIB.
Minos Galanakis471b34c2024-07-26 15:39:24 +010056check_renamed_symbols () {
57 ! nm "$2" | sed 's/.* //' |
58 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
59}
60
61component_build_psa_crypto_spm () {
62 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
63 scripts/config.py full
64 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
65 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
66 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
67 # We can only compile, not link, since our test and sample programs
68 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
69 # is active.
David Horstmann5b93d972024-10-31 15:36:05 +000070 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' lib
Minos Galanakis471b34c2024-07-26 15:39:24 +010071
72 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
73 # version is not present.
74 echo "Checking for renamed symbols in the library"
David Horstmann5b93d972024-10-31 15:36:05 +000075 check_renamed_symbols framework/tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Minos Galanakis471b34c2024-07-26 15:39:24 +010076}
77
Valerio Settia47b0452024-06-25 18:31:36 +020078# The goal of this component is to build a configuration where:
79# - test code and libtestdriver1 can make use of calloc/free and
80# - core library (including PSA core) cannot use calloc/free.
81component_test_psa_crypto_without_heap() {
Valerio Setti13aadd72024-08-13 13:13:23 +020082 msg "crypto without heap: build libtestdriver1"
Valerio Settia47b0452024-06-25 18:31:36 +020083 # Disable PSA features that cannot be accelerated and whose builtin support
84 # requires calloc/free.
Minos Galanakis00b641c2024-11-28 23:05:10 +000085 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
86 scripts/config.py -c $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_HKDF"
87 scripts/config.py -c $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_PBKDF2_"
88 scripts/config.py -c $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_TLS12_"
Valerio Settia47b0452024-06-25 18:31:36 +020089 # RSA key support requires ASN1 parse/write support for testing, but ASN1
90 # is disabled below.
Minos Galanakis00b641c2024-11-28 23:05:10 +000091 scripts/config.py -c $CRYPTO_CONFIG_H unset-all "^PSA_WANT_KEY_TYPE_RSA_"
92 scripts/config.py -c $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_RSA_"
Valerio Settia47b0452024-06-25 18:31:36 +020093 # DES requires built-in support for key generation (parity check) so it
94 # cannot be accelerated
Minos Galanakis00b641c2024-11-28 23:05:10 +000095 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
Valerio Settia47b0452024-06-25 18:31:36 +020096 # EC-JPAKE use calloc/free in PSA core
Minos Galanakis00b641c2024-11-28 23:05:10 +000097 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE
Valerio Settia47b0452024-06-25 18:31:36 +020098
99 # Accelerate all PSA features (which are still enabled in CRYPTO_CONFIG_H).
Minos Galanakis00b641c2024-11-28 23:05:10 +0000100 PSA_SYM_LIST=$(./scripts/config.py -c $CRYPTO_CONFIG_H get-all-enabled PSA_WANT)
Valerio Settia47b0452024-06-25 18:31:36 +0200101 loc_accel_list=$(echo $PSA_SYM_LIST | sed 's/PSA_WANT_//g')
102
Valerio Settia47b0452024-06-25 18:31:36 +0200103 helper_libtestdriver1_adjust_config crypto
104 helper_libtestdriver1_make_drivers "$loc_accel_list"
105
Valerio Setti13aadd72024-08-13 13:13:23 +0200106 msg "crypto without heap: build main library"
Valerio Setti35b0b022024-08-13 13:36:50 +0200107 # Disable all legacy MBEDTLS_xxx symbols.
108 scripts/config.py unset-all "^MBEDTLS_"
109 # Build the PSA core using the proper config file.
110 scripts/config.py set MBEDTLS_PSA_CRYPTO_C
Valerio Settia47b0452024-06-25 18:31:36 +0200111 # Enable fully-static key slots in PSA core.
112 scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOTS
Valerio Setti35b0b022024-08-13 13:36:50 +0200113 # Prevent PSA core from creating a copy of input/output buffers.
Valerio Settia47b0452024-06-25 18:31:36 +0200114 scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
115 # Prevent PSA core from using CTR-DRBG or HMAC-DRBG for random generation.
116 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Valerio Setti13aadd72024-08-13 13:13:23 +0200117 # Set calloc/free as null pointer functions. Calling them would crash
Valerio Settia47b0452024-06-25 18:31:36 +0200118 # the program so we can use this as a "sentinel" for being sure no module
119 # is making use of these functions in the library.
Valerio Setti35b0b022024-08-13 13:36:50 +0200120 scripts/config.py set MBEDTLS_PLATFORM_C
Valerio Settia47b0452024-06-25 18:31:36 +0200121 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
122 scripts/config.py set MBEDTLS_PLATFORM_STD_CALLOC NULL
123 scripts/config.py set MBEDTLS_PLATFORM_STD_FREE NULL
124
Valerio Settia47b0452024-06-25 18:31:36 +0200125 helper_libtestdriver1_make_main "$loc_accel_list" lib
126
Valerio Setti13aadd72024-08-13 13:13:23 +0200127 msg "crypto without heap: build test suites and helpers"
128 # Reset calloc/free functions to normal operations so that test code can
Valerio Settia47b0452024-06-25 18:31:36 +0200129 # freely use them.
130 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
131 scripts/config.py unset MBEDTLS_PLATFORM_STD_CALLOC
132 scripts/config.py unset MBEDTLS_PLATFORM_STD_FREE
133 helper_libtestdriver1_make_main "$loc_accel_list" tests
134
Valerio Setti13aadd72024-08-13 13:13:23 +0200135 msg "crypto without heap: test"
Valerio Settia47b0452024-06-25 18:31:36 +0200136 make test
137}
138
Minos Galanakisf78447f2024-07-26 20:49:51 +0100139component_test_no_rsa_key_pair_generation () {
Minos Galanakisdc0f73a2024-07-26 20:41:42 +0100140 msg "build: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
Minos Galanakisdc0f73a2024-07-26 20:41:42 +0100141 scripts/config.py unset MBEDTLS_GENPRIME
Minos Galanakis00b641c2024-11-28 23:05:10 +0000142 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Minos Galanakisdc0f73a2024-07-26 20:41:42 +0100143 make
144
145 msg "test: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
146 make test
147}
148
Minos Galanakisc06fd302024-08-01 12:16:59 +0100149component_test_no_pem_no_fs () {
150 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
151 scripts/config.py unset MBEDTLS_PEM_PARSE_C
152 scripts/config.py unset MBEDTLS_FS_IO
153 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
154 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
155 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
156 make
157
158 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
159 make test
160
161 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
162 tests/ssl-opt.sh
163}
164
165component_test_rsa_no_crt () {
166 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
167 scripts/config.py set MBEDTLS_RSA_NO_CRT
168 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
169 make
170
171 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
172 make test
173
174 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
175 tests/ssl-opt.sh -f RSA
176
177 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
178 tests/compat.sh -t RSA
179
180 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
181 tests/context-info.sh
182}
183
Minos Galanakisc06fd302024-08-01 12:16:59 +0100184component_test_no_ctr_drbg_use_psa () {
185 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
186 scripts/config.py full
187 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Minos Galanakisc06fd302024-08-01 12:16:59 +0100188
189 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
190 make
191
192 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
193 make test
194
195 # In this configuration, the TLS test programs use HMAC_DRBG.
196 # The SSL tests are slow, so run a small subset, just enough to get
197 # confidence that the SSL code copes with HMAC_DRBG.
198 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
199 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
200
201 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
202 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
203}
204
Minos Galanakisc06fd302024-08-01 12:16:59 +0100205component_test_no_hmac_drbg_use_psa () {
206 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
207 scripts/config.py full
208 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
209 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Minos Galanakisc06fd302024-08-01 12:16:59 +0100210
211 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
212 make
213
214 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
215 make test
216
217 # Normally our ECDSA implementation uses deterministic ECDSA. But since
218 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
219 # instead.
220 # Test SSL with non-deterministic ECDSA. Only test features that
221 # might be affected by how ECDSA signature is performed.
222 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
223 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
224
225 # To save time, only test one protocol version, since this part of
226 # the protocol is identical in (D)TLS up to 1.2.
227 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
228 tests/compat.sh -m tls12 -t 'ECDSA'
229}
230
Minos Galanakisc06fd302024-08-01 12:16:59 +0100231component_test_psa_external_rng_no_drbg_use_psa () {
232 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
233 scripts/config.py full
234 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
235 scripts/config.py unset MBEDTLS_ENTROPY_C
236 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
237 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
238 scripts/config.py unset MBEDTLS_CTR_DRBG_C
239 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
240 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
241 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
242
243 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
244 make test
245
246 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
247 tests/ssl-opt.sh -f 'Default\|opaque'
248}
249
Minos Galanakis471b34c2024-07-26 15:39:24 +0100250component_test_psa_external_rng_use_psa_crypto () {
251 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
252 scripts/config.py full
253 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Minos Galanakis471b34c2024-07-26 15:39:24 +0100254 scripts/config.py unset MBEDTLS_CTR_DRBG_C
255 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
256
257 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
258 make test
259
260 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
261 tests/ssl-opt.sh -f 'Default\|opaque'
262}
263
Minos Galanakisf78447f2024-07-26 20:49:51 +0100264component_full_no_pkparse_pkwrite () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100265 msg "build: full without pkparse and pkwrite"
266
267 scripts/config.py crypto_full
268 scripts/config.py unset MBEDTLS_PK_PARSE_C
269 scripts/config.py unset MBEDTLS_PK_WRITE_C
270
271 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
272
273 # Ensure that PK_[PARSE|WRITE]_C were not re-enabled accidentally (additive config).
274 not grep mbedtls_pk_parse_key ${BUILTIN_SRC_PATH}/pkparse.o
275 not grep mbedtls_pk_write_key_der ${BUILTIN_SRC_PATH}/pkwrite.o
276
277 msg "test: full without pkparse and pkwrite"
278 make test
279}
280
281component_test_crypto_full_md_light_only () {
282 msg "build: crypto_full with only the light subset of MD"
283 scripts/config.py crypto_full
284
285 # Disable MD
286 scripts/config.py unset MBEDTLS_MD_C
287 # Disable direct dependencies of MD_C
288 scripts/config.py unset MBEDTLS_HKDF_C
289 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
290 scripts/config.py unset MBEDTLS_PKCS7_C
291 # Disable indirect dependencies of MD_C
292 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG
Minos Galanakis00b641c2024-11-28 23:05:10 +0000293 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
Minos Galanakis471b34c2024-07-26 15:39:24 +0100294 # Disable things that would auto-enable MD_C
295 scripts/config.py unset MBEDTLS_PKCS5_C
296
297 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
298 # which we haven't disabled, so no need to explicitly enable it.
299 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
300
301 # Make sure we don't have the HMAC functions, but the hashing functions
302 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
303 grep mbedtls_md ${BUILTIN_SRC_PATH}/md.o
304
305 msg "test: crypto_full with only the light subset of MD"
306 make test
307}
308
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100309component_test_full_no_cipher () {
310 msg "build: full no CIPHER"
311
312 scripts/config.py full
313 scripts/config.py unset MBEDTLS_CIPHER_C
314
315 # The built-in implementation of the following algs/key-types depends
316 # on CIPHER_C so we disable them.
317 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
318 # so we keep them enabled.
Minos Galanakis00b641c2024-11-28 23:05:10 +0000319 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
320 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CMAC
321 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
322 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
323 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CFB
324 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CTR
325 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
326 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_OFB
327 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
328 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_STREAM_CIPHER
329 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100330
331 # The following modules directly depends on CIPHER_C
332 scripts/config.py unset MBEDTLS_CMAC_C
333 scripts/config.py unset MBEDTLS_NIST_KW_C
334
335 make
336
337 # Ensure that CIPHER_C was not re-enabled
338 not grep mbedtls_cipher_init ${BUILTIN_SRC_PATH}/cipher.o
339
340 msg "test: full no CIPHER"
341 make test
342}
343
Minos Galanakisf78447f2024-07-26 20:49:51 +0100344component_test_full_no_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100345 msg "build: full no PSA_WANT_ALG_CCM"
346
347 # Full config enables:
348 # - USE_PSA_CRYPTO so that TLS code dispatches cipher/AEAD to PSA
349 # - CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
350 scripts/config.py full
351
352 # Disable PSA_WANT_ALG_CCM so that CCM is not supported in PSA. CCM_C is still
353 # enabled, but not used from TLS since USE_PSA is set.
354 # This is helpful to ensure that TLS tests below have proper dependencies.
355 #
356 # Note: also PSA_WANT_ALG_CCM_STAR_NO_TAG is enabled, but it does not cause
357 # PSA_WANT_ALG_CCM to be re-enabled.
358 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM
359
360 make
361
362 msg "test: full no PSA_WANT_ALG_CCM"
363 make test
364}
365
Minos Galanakisf78447f2024-07-26 20:49:51 +0100366component_test_full_no_ccm_star_no_tag () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100367 msg "build: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
368
369 # Full config enables CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
370 scripts/config.py full
371
372 # Disable CCM_STAR_NO_TAG, which is the target of this test, as well as all
373 # other components that enable MBEDTLS_PSA_BUILTIN_CIPHER internal symbol.
374 # This basically disables all unauthenticated ciphers on the PSA side, while
375 # keeping AEADs enabled.
376 #
377 # Note: PSA_WANT_ALG_CCM is enabled, but it does not cause
378 # PSA_WANT_ALG_CCM_STAR_NO_TAG to be re-enabled.
379 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
380 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_STREAM_CIPHER
381 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
382 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
383 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
384 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
385 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
386 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
387
388 make
389
390 # Ensure MBEDTLS_PSA_BUILTIN_CIPHER was not enabled
391 not grep mbedtls_psa_cipher ${PSA_CORE_PATH}/psa_crypto_cipher.o
392
393 msg "test: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
394 make test
395}
396
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200397component_test_config_symmetric_only () {
398 msg "build: configs/config-symmetric-only.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +0000399 MBEDTLS_CONFIG="configs/config-symmetric-only.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +0000400 CRYPTO_CONFIG="tf-psa-crypto/configs/crypto-config-symmetric-only.h"
Ronald Cronfaadfc22024-12-07 17:24:28 +0100401 CC=$ASAN_CC cmake -DMBEDTLS_CONFIG_FILE="$MBEDTLS_CONFIG" -DTF_PSA_CRYPTO_CONFIG_FILE="$CRYPTO_CONFIG" -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskineaf5a8992024-09-14 11:27:44 +0200402 make
403
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200404 msg "test: configs/config-symmetric-only.h - unit tests"
Gilles Peskineaf5a8992024-09-14 11:27:44 +0200405 make test
406}
407
Minos Galanakisc06fd302024-08-01 12:16:59 +0100408component_test_everest () {
409 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
410 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
411 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
412 make
413
414 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
415 make test
416
417 msg "test: metatests (clang, ASan)"
418 tests/scripts/run-metatests.sh any asan poison
419
420 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
421 tests/ssl-opt.sh -f ECDH
422
423 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
424 # Exclude some symmetric ciphers that are redundant here to gain time.
425 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
426}
427
428component_test_everest_curve25519_only () {
429 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
Minos Galanakisc06fd302024-08-01 12:16:59 +0100430 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
431 scripts/config.py unset MBEDTLS_ECDSA_C
Minos Galanakis00b641c2024-11-28 23:05:10 +0000432 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
433 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECDSA
434 scripts/config.py -c $CRYPTO_CONFIG_H set PSA_WANT_ALG_ECDH
Minos Galanakisc06fd302024-08-01 12:16:59 +0100435 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
436 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
437 scripts/config.py unset MBEDTLS_ECJPAKE_C
Minos Galanakis00b641c2024-11-28 23:05:10 +0000438 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE
Minos Galanakisc06fd302024-08-01 12:16:59 +0100439
440 # Disable all curves
441 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
Minos Galanakis00b641c2024-11-28 23:05:10 +0000442 scripts/config.py -c $CRYPTO_CONFIG_H unset-all "PSA_WANT_ECC_[0-9A-Z_a-z]*$"
443 scripts/config.py -c $CRYPTO_CONFIG_H set PSA_WANT_ECC_MONTGOMERY_255
Minos Galanakisc06fd302024-08-01 12:16:59 +0100444
445 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
446
447 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
448 make test
449}
450
Minos Galanakis471b34c2024-07-26 15:39:24 +0100451component_test_psa_collect_statuses () {
452 msg "build+test: psa_collect_statuses" # ~30s
453 scripts/config.py full
454 tests/scripts/psa_collect_statuses.py
455 # Check that psa_crypto_init() succeeded at least once
456 grep -q '^0:psa_crypto_init:' tests/statuses.log
457 rm -f tests/statuses.log
458}
459
460# Check that the specified libraries exist and are empty.
461are_empty_libraries () {
462 nm "$@" >/dev/null 2>/dev/null
463 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
464}
465
Minos Galanakis471b34c2024-07-26 15:39:24 +0100466component_test_crypto_for_psa_service () {
467 msg "build: make, config for PSA crypto service"
468 scripts/config.py crypto
469 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
470 # Disable things that are not needed for just cryptography, to
471 # reach a configuration that would be typical for a PSA cryptography
472 # service providing all implemented PSA algorithms.
473 # System stuff
474 scripts/config.py unset MBEDTLS_ERROR_C
475 scripts/config.py unset MBEDTLS_TIMING_C
476 scripts/config.py unset MBEDTLS_VERSION_FEATURES
477 # Crypto stuff with no PSA interface
478 scripts/config.py unset MBEDTLS_BASE64_C
479 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
480 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
481 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
482 scripts/config.py unset MBEDTLS_NIST_KW_C
483 scripts/config.py unset MBEDTLS_PEM_PARSE_C
484 scripts/config.py unset MBEDTLS_PEM_WRITE_C
485 scripts/config.py unset MBEDTLS_PKCS12_C
486 scripts/config.py unset MBEDTLS_PKCS5_C
487 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
488 # in PSA code to work with RSA keys. We don't require users to set those:
489 # they will be reenabled in build_info.h.
490 scripts/config.py unset MBEDTLS_PK_C
491 scripts/config.py unset MBEDTLS_PK_PARSE_C
492 scripts/config.py unset MBEDTLS_PK_WRITE_C
493 make CFLAGS='-O1 -Werror' all test
494 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
495}
496
497component_build_crypto_baremetal () {
498 msg "build: make, crypto only, baremetal config"
499 scripts/config.py crypto_baremetal
David Horstmann5b93d972024-10-31 15:36:05 +0000500 make CFLAGS="-O1 -Werror -I$PWD/framework/tests/include/baremetal-override/"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100501 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
502}
503
504support_build_crypto_baremetal () {
505 support_build_baremetal "$@"
506}
507
508# depends.py family of tests
509component_test_depends_py_cipher_id () {
510 msg "test/build: depends.py cipher_id (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200511 tests/scripts/depends.py cipher_id
Minos Galanakis471b34c2024-07-26 15:39:24 +0100512}
513
514component_test_depends_py_cipher_chaining () {
515 msg "test/build: depends.py cipher_chaining (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200516 tests/scripts/depends.py cipher_chaining
Minos Galanakis471b34c2024-07-26 15:39:24 +0100517}
518
519component_test_depends_py_cipher_padding () {
520 msg "test/build: depends.py cipher_padding (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200521 tests/scripts/depends.py cipher_padding
Minos Galanakis471b34c2024-07-26 15:39:24 +0100522}
523
524component_test_depends_py_curves () {
525 msg "test/build: depends.py curves (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200526 tests/scripts/depends.py curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100527}
528
529component_test_depends_py_hashes () {
530 msg "test/build: depends.py hashes (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200531 tests/scripts/depends.py hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +0100532}
533
Minos Galanakis471b34c2024-07-26 15:39:24 +0100534component_test_depends_py_pkalgs () {
535 msg "test/build: depends.py pkalgs (gcc)"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100536 tests/scripts/depends.py pkalgs
537}
538
539component_test_psa_crypto_config_ffdh_2048_only () {
540 msg "build: full config - only DH 2048"
541
542 scripts/config.py full
543
544 # Disable all DH groups other than 2048.
545 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_3072
546 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_4096
547 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_6144
548 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_8192
549
550 make CFLAGS="$ASAN_CFLAGS -Werror" LDFLAGS="$ASAN_CFLAGS"
551
552 msg "test: full config - only DH 2048"
553 make test
554
555 msg "ssl-opt: full config - only DH 2048"
556 tests/ssl-opt.sh -f "ffdh"
557}
558
Minos Galanakis471b34c2024-07-26 15:39:24 +0100559component_test_psa_crypto_config_accel_ecdsa () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200560 msg "build: accelerated ECDSA"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100561
562 # Algorithms and key types to accelerate
563 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
564 $(helper_get_psa_key_type_list "ECC") \
565 $(helper_get_psa_curve_list)"
566
567 # Configure
568 # ---------
569
Elena Uziunaite91d83862024-09-04 14:51:31 +0100570 # Start from default config + TLS 1.3
Minos Galanakis471b34c2024-07-26 15:39:24 +0100571 helper_libtestdriver1_adjust_config "default"
572
573 # Disable the module that's accelerated
574 scripts/config.py unset MBEDTLS_ECDSA_C
575
576 # Disable things that depend on it
577 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
578 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
579
580 # Build
581 # -----
582
583 # These hashes are needed for some ECDSA signature tests.
Elena Uziunaiteffce45c2024-09-12 14:58:52 +0100584 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 +0100585 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
586
587 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
588
589 helper_libtestdriver1_make_main "$loc_accel_list"
590
591 # Make sure this was not re-enabled by accident (additive config)
592 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
593
594 # Run the tests
595 # -------------
596
Ronald Cron93ba6252024-09-05 10:37:14 +0200597 msg "test: accelerated ECDSA"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100598 make test
599}
600
601component_test_psa_crypto_config_accel_ecdh () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200602 msg "build: accelerated ECDH"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100603
604 # Algorithms and key types to accelerate
605 loc_accel_list="ALG_ECDH \
606 $(helper_get_psa_key_type_list "ECC") \
607 $(helper_get_psa_curve_list)"
608
609 # Configure
610 # ---------
611
612 # Start from default config (no USE_PSA)
613 helper_libtestdriver1_adjust_config "default"
614
615 # Disable the module that's accelerated
616 scripts/config.py unset MBEDTLS_ECDH_C
617
618 # Disable things that depend on it
619 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
620 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
621 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
622 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
623 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
624
625 # Build
626 # -----
627
628 helper_libtestdriver1_make_drivers "$loc_accel_list"
629
630 helper_libtestdriver1_make_main "$loc_accel_list"
631
632 # Make sure this was not re-enabled by accident (additive config)
633 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
634
635 # Run the tests
636 # -------------
637
Ronald Cron93ba6252024-09-05 10:37:14 +0200638 msg "test: accelerated ECDH"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100639 make test
640}
641
642component_test_psa_crypto_config_accel_ffdh () {
643 msg "build: full with accelerated FFDH"
644
645 # Algorithms and key types to accelerate
646 loc_accel_list="ALG_FFDH \
647 $(helper_get_psa_key_type_list "DH") \
648 $(helper_get_psa_dh_group_list)"
649
650 # Configure
651 # ---------
652
653 # start with full (USE_PSA and TLS 1.3)
654 helper_libtestdriver1_adjust_config "full"
655
Minos Galanakis471b34c2024-07-26 15:39:24 +0100656 # Build
657 # -----
658
659 helper_libtestdriver1_make_drivers "$loc_accel_list"
660
661 helper_libtestdriver1_make_main "$loc_accel_list"
662
663 # Make sure this was not re-enabled by accident (additive config)
Valerio Settieb63eb22025-02-12 13:32:49 +0100664 not grep mbedtls_psa_ffdh_key_agreement ${BUILTIN_SRC_PATH}/psa_crypto_ffdh.o
Minos Galanakis471b34c2024-07-26 15:39:24 +0100665
666 # Run the tests
667 # -------------
668
669 msg "test: full with accelerated FFDH"
670 make test
671
672 msg "ssl-opt: full with accelerated FFDH alg"
673 tests/ssl-opt.sh -f "ffdh"
674}
675
676component_test_psa_crypto_config_reference_ffdh () {
677 msg "build: full with non-accelerated FFDH"
678
679 # Start with full (USE_PSA and TLS 1.3)
680 helper_libtestdriver1_adjust_config "full"
681
Minos Galanakis471b34c2024-07-26 15:39:24 +0100682 make
683
684 msg "test suites: full with non-accelerated FFDH alg"
685 make test
686
687 msg "ssl-opt: full with non-accelerated FFDH alg"
688 tests/ssl-opt.sh -f "ffdh"
689}
690
Minos Galanakisf78447f2024-07-26 20:49:51 +0100691component_test_psa_crypto_config_accel_pake () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100692 msg "build: full with accelerated PAKE"
693
694 loc_accel_list="ALG_JPAKE \
695 $(helper_get_psa_key_type_list "ECC") \
696 $(helper_get_psa_curve_list)"
697
698 # Configure
699 # ---------
700
701 helper_libtestdriver1_adjust_config "full"
702
703 # Make built-in fallback not available
704 scripts/config.py unset MBEDTLS_ECJPAKE_C
705 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
706
707 # Build
708 # -----
709
710 helper_libtestdriver1_make_drivers "$loc_accel_list"
711
712 helper_libtestdriver1_make_main "$loc_accel_list"
713
714 # Make sure this was not re-enabled by accident (additive config)
715 not grep mbedtls_ecjpake_init ${BUILTIN_SRC_PATH}/ecjpake.o
716
717 # Run the tests
718 # -------------
719
720 msg "test: full with accelerated PAKE"
721 make test
722}
723
724component_test_psa_crypto_config_accel_ecc_some_key_types () {
725 msg "build: full with accelerated EC algs and some key types"
726
727 # Algorithms and key types to accelerate
728 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
729 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
730 ALG_ECDH \
731 ALG_JPAKE \
732 KEY_TYPE_ECC_PUBLIC_KEY \
733 KEY_TYPE_ECC_KEY_PAIR_BASIC \
734 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
735 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
736 $(helper_get_psa_curve_list)"
737
738 # Configure
739 # ---------
740
741 # start with config full for maximum coverage (also enables USE_PSA)
742 helper_libtestdriver1_adjust_config "full"
743
744 # Disable modules that are accelerated - some will be re-enabled
745 scripts/config.py unset MBEDTLS_ECDSA_C
746 scripts/config.py unset MBEDTLS_ECDH_C
747 scripts/config.py unset MBEDTLS_ECJPAKE_C
748 scripts/config.py unset MBEDTLS_ECP_C
749
750 # Disable all curves - those that aren't accelerated should be re-enabled
751 helper_disable_builtin_curves
752
753 # Restartable feature is not yet supported by PSA. Once it will in
754 # the future, the following line could be removed (see issues
755 # 6061, 6332 and following ones)
756 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
757
758 # this is not supported by the driver API yet
759 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
760
761 # Build
762 # -----
763
764 # These hashes are needed for some ECDSA signature tests.
765 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
766 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
767 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
768
769 helper_libtestdriver1_make_main "$loc_accel_list"
770
771 # ECP should be re-enabled but not the others
772 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
773 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
774 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
775 grep mbedtls_ecp ${BUILTIN_SRC_PATH}/ecp.o
776
777 # Run the tests
778 # -------------
779
780 msg "test suites: full with accelerated EC algs and some key types"
781 make test
782}
783
784# Run tests with only (non-)Weierstrass accelerated
785# Common code used in:
786# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
787# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100788common_test_psa_crypto_config_accel_ecc_some_curves () {
789 weierstrass=$1
790 if [ $weierstrass -eq 1 ]; then
791 desc="Weierstrass"
792 else
793 desc="non-Weierstrass"
794 fi
795
796 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
797
798 # Note: Curves are handled in a special way by the libtestdriver machinery,
799 # so we only want to include them in the accel list when building the main
800 # libraries, hence the use of a separate variable.
801 # Note: the following loop is a modified version of
802 # helper_get_psa_curve_list that only keeps Weierstrass families.
803 loc_weierstrass_list=""
804 loc_non_weierstrass_list=""
805 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
806 case $item in
807 ECC_BRAINPOOL*|ECC_SECP*)
808 loc_weierstrass_list="$loc_weierstrass_list $item"
809 ;;
810 *)
811 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
812 ;;
813 esac
814 done
815 if [ $weierstrass -eq 1 ]; then
816 loc_curve_list=$loc_weierstrass_list
817 else
818 loc_curve_list=$loc_non_weierstrass_list
819 fi
820
821 # Algorithms and key types to accelerate
822 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
823 ALG_ECDH \
824 ALG_JPAKE \
825 $(helper_get_psa_key_type_list "ECC") \
826 $loc_curve_list"
827
828 # Configure
829 # ---------
830
831 # Start with config crypto_full and remove PK_C:
832 # that's what's supported now, see docs/driver-only-builds.md.
833 helper_libtestdriver1_adjust_config "crypto_full"
834 scripts/config.py unset MBEDTLS_PK_C
835 scripts/config.py unset MBEDTLS_PK_PARSE_C
836 scripts/config.py unset MBEDTLS_PK_WRITE_C
837
838 # Disable modules that are accelerated - some will be re-enabled
839 scripts/config.py unset MBEDTLS_ECDSA_C
840 scripts/config.py unset MBEDTLS_ECDH_C
841 scripts/config.py unset MBEDTLS_ECJPAKE_C
842 scripts/config.py unset MBEDTLS_ECP_C
843
844 # Disable all curves - those that aren't accelerated should be re-enabled
845 helper_disable_builtin_curves
846
847 # Restartable feature is not yet supported by PSA. Once it will in
848 # the future, the following line could be removed (see issues
849 # 6061, 6332 and following ones)
850 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
851
852 # this is not supported by the driver API yet
853 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
854
855 # Build
856 # -----
857
858 # These hashes are needed for some ECDSA signature tests.
859 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
860 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
861 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
862
863 helper_libtestdriver1_make_main "$loc_accel_list"
864
865 # We expect ECDH to be re-enabled for the missing curves
866 grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
867 # We expect ECP to be re-enabled, however the parts specific to the
868 # families of curves that are accelerated should be ommited.
869 # - functions with mxz in the name are specific to Montgomery curves
870 # - ecp_muladd is specific to Weierstrass curves
871 ##nm ${BUILTIN_SRC_PATH}/ecp.o | tee ecp.syms
872 if [ $weierstrass -eq 1 ]; then
873 not grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
874 grep mxz ${BUILTIN_SRC_PATH}/ecp.o
875 else
876 grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
877 not grep mxz ${BUILTIN_SRC_PATH}/ecp.o
878 fi
879 # We expect ECDSA and ECJPAKE to be re-enabled only when
880 # Weierstrass curves are not accelerated
881 if [ $weierstrass -eq 1 ]; then
882 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
883 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
884 else
885 grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
886 grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
887 fi
888
889 # Run the tests
890 # -------------
891
892 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
893 make test
894}
895
896component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
897 common_test_psa_crypto_config_accel_ecc_some_curves 1
898}
899
900component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
901 common_test_psa_crypto_config_accel_ecc_some_curves 0
902}
903
904# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
905# ECDH, ECDSA) with and without drivers.
906# The input parameter is a boolean value which indicates:
907# - 0 keep built-in EC algs,
908# - 1 exclude built-in EC algs (driver only).
909#
910# This is used by the two following components to ensure they always use the
911# same config, except for the use of driver or built-in EC algorithms:
912# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
913# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
914# This supports comparing their test coverage with analyze_outcomes.py.
Minos Galanakis471b34c2024-07-26 15:39:24 +0100915config_psa_crypto_config_ecp_light_only () {
916 driver_only="$1"
917 # start with config full for maximum coverage (also enables USE_PSA)
918 helper_libtestdriver1_adjust_config "full"
919 if [ "$driver_only" -eq 1 ]; then
920 # Disable modules that are accelerated
921 scripts/config.py unset MBEDTLS_ECDSA_C
922 scripts/config.py unset MBEDTLS_ECDH_C
923 scripts/config.py unset MBEDTLS_ECJPAKE_C
924 scripts/config.py unset MBEDTLS_ECP_C
925 fi
926
927 # Restartable feature is not yet supported by PSA. Once it will in
928 # the future, the following line could be removed (see issues
929 # 6061, 6332 and following ones)
930 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
931}
932
933# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100934component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
935 msg "build: full with accelerated EC algs"
936
937 # Algorithms and key types to accelerate
938 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
939 ALG_ECDH \
940 ALG_JPAKE \
941 $(helper_get_psa_key_type_list "ECC") \
942 $(helper_get_psa_curve_list)"
943
944 # Configure
945 # ---------
946
947 # Use the same config as reference, only without built-in EC algs
948 config_psa_crypto_config_ecp_light_only 1
949
950 # Do not disable builtin curves because that support is required for:
951 # - MBEDTLS_PK_PARSE_EC_EXTENDED
952 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
953
954 # Build
955 # -----
956
957 # These hashes are needed for some ECDSA signature tests.
958 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
959 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
960 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
961
962 helper_libtestdriver1_make_main "$loc_accel_list"
963
964 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
965 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
966 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
967 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
968 not grep mbedtls_ecp_mul ${BUILTIN_SRC_PATH}/ecp.o
969
970 # Run the tests
971 # -------------
972
973 msg "test suites: full with accelerated EC algs"
974 make test
975
976 msg "ssl-opt: full with accelerated EC algs"
977 tests/ssl-opt.sh
978}
979
980# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100981component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200982 msg "build: non-accelerated EC algs"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100983
984 config_psa_crypto_config_ecp_light_only 0
985
986 make
987
988 msg "test suites: full with non-accelerated EC algs"
989 make test
990
991 msg "ssl-opt: full with non-accelerated EC algs"
992 tests/ssl-opt.sh
993}
994
995# This helper function is used by:
996# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
997# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
998# to ensure that both tests use the same underlying configuration when testing
999# driver's coverage with analyze_outcomes.py.
1000#
1001# This functions accepts 1 boolean parameter as follows:
1002# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
1003# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
1004# - 0: include built-in implementation of EC algorithms.
1005#
1006# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
1007# on the ECP module.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001008config_psa_crypto_no_ecp_at_all () {
1009 driver_only="$1"
1010 # start with full config for maximum coverage (also enables USE_PSA)
1011 helper_libtestdriver1_adjust_config "full"
1012
1013 if [ "$driver_only" -eq 1 ]; then
1014 # Disable modules that are accelerated
1015 scripts/config.py unset MBEDTLS_ECDSA_C
1016 scripts/config.py unset MBEDTLS_ECDH_C
1017 scripts/config.py unset MBEDTLS_ECJPAKE_C
1018 # Disable ECP module (entirely)
1019 scripts/config.py unset MBEDTLS_ECP_C
1020 fi
1021
1022 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1023 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1024 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1025 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1026
1027 # Restartable feature is not yet supported by PSA. Once it will in
1028 # the future, the following line could be removed (see issues
1029 # 6061, 6332 and following ones)
1030 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1031}
1032
1033# Build and test a configuration where driver accelerates all EC algs while
1034# all support and dependencies from ECP and ECP_LIGHT are removed on the library
1035# side.
1036#
1037# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001038component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
1039 msg "build: full + accelerated EC algs - ECP"
1040
1041 # Algorithms and key types to accelerate
1042 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1043 ALG_ECDH \
1044 ALG_JPAKE \
1045 $(helper_get_psa_key_type_list "ECC") \
1046 $(helper_get_psa_curve_list)"
1047
1048 # Configure
1049 # ---------
1050
1051 # Set common configurations between library's and driver's builds
1052 config_psa_crypto_no_ecp_at_all 1
1053 # Disable all the builtin curves. All the required algs are accelerated.
1054 helper_disable_builtin_curves
1055
1056 # Build
1057 # -----
1058
1059 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1060 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1061 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1062 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1063
1064 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1065
1066 helper_libtestdriver1_make_main "$loc_accel_list"
1067
1068 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1069 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1070 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1071 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1072 # Also ensure that ECP module was not re-enabled
1073 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1074
1075 # Run the tests
1076 # -------------
1077
1078 msg "test: full + accelerated EC algs - ECP"
1079 make test
1080
1081 msg "ssl-opt: full + accelerated EC algs - ECP"
1082 tests/ssl-opt.sh
1083}
1084
1085# Reference function used for driver's coverage analysis in analyze_outcomes.py
1086# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
1087# Keep in sync with its accelerated counterpart.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001088component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
1089 msg "build: full + non accelerated EC algs"
1090
1091 config_psa_crypto_no_ecp_at_all 0
1092
1093 make
1094
1095 msg "test: full + non accelerated EC algs"
1096 make test
1097
1098 msg "ssl-opt: full + non accelerated EC algs"
1099 tests/ssl-opt.sh
1100}
1101
1102# This is a common configuration helper used directly from:
1103# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1104# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1105# and indirectly from:
1106# - component_test_psa_crypto_config_accel_ecc_no_bignum
1107# - accelerate all EC algs, disable RSA and FFDH
1108# - component_test_psa_crypto_config_reference_ecc_no_bignum
1109# - this is the reference component of the above
1110# - it still disables RSA and FFDH, but it uses builtin EC algs
1111# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1112# - accelerate all EC and FFDH algs, disable only RSA
1113# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1114# - this is the reference component of the above
1115# - it still disables RSA, but it uses builtin EC and FFDH algs
1116#
1117# This function accepts 2 parameters:
1118# $1: a boolean value which states if we are testing an accelerated scenario
1119# or not.
1120# $2: a string value which states which components are tested. Allowed values
1121# are "ECC" or "ECC_DH".
Minos Galanakisf78447f2024-07-26 20:49:51 +01001122config_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001123 driver_only="$1"
1124 test_target="$2"
1125 # start with full config for maximum coverage (also enables USE_PSA)
1126 helper_libtestdriver1_adjust_config "full"
1127
1128 if [ "$driver_only" -eq 1 ]; then
1129 # Disable modules that are accelerated
1130 scripts/config.py unset MBEDTLS_ECDSA_C
1131 scripts/config.py unset MBEDTLS_ECDH_C
1132 scripts/config.py unset MBEDTLS_ECJPAKE_C
1133 # Disable ECP module (entirely)
1134 scripts/config.py unset MBEDTLS_ECP_C
1135 # Also disable bignum
1136 scripts/config.py unset MBEDTLS_BIGNUM_C
1137 fi
1138
1139 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1140 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1141 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1142 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1143
1144 # RSA support is intentionally disabled on this test because RSA_C depends
1145 # on BIGNUM_C.
1146 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
1147 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
1148 scripts/config.py unset MBEDTLS_RSA_C
1149 scripts/config.py unset MBEDTLS_PKCS1_V15
1150 scripts/config.py unset MBEDTLS_PKCS1_V21
1151 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1152 # Also disable key exchanges that depend on RSA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001153 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1154 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1155
1156 if [ "$test_target" = "ECC" ]; then
1157 # When testing ECC only, we disable FFDH support, both from builtin and
Valerio Setti8438c632025-01-22 11:56:40 +01001158 # PSA sides.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001159 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_FFDH
1160 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
1161 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001162 fi
1163
1164 # Restartable feature is not yet supported by PSA. Once it will in
1165 # the future, the following line could be removed (see issues
1166 # 6061, 6332 and following ones)
1167 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1168}
1169
1170# Common helper used by:
1171# - component_test_psa_crypto_config_accel_ecc_no_bignum
1172# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1173#
1174# The goal is to build and test accelerating either:
1175# - ECC only or
1176# - both ECC and FFDH
1177#
1178# It is meant to be used in conjunction with
1179# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
1180# coverage analysis in the "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001181common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1182 test_target="$1"
1183
1184 # This is an internal helper to simplify text message handling
1185 if [ "$test_target" = "ECC_DH" ]; then
1186 accel_text="ECC/FFDH"
1187 removed_text="ECP - DH"
1188 else
1189 accel_text="ECC"
1190 removed_text="ECP"
1191 fi
1192
1193 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1194
1195 # By default we accelerate all EC keys/algs
1196 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1197 ALG_ECDH \
1198 ALG_JPAKE \
1199 $(helper_get_psa_key_type_list "ECC") \
1200 $(helper_get_psa_curve_list)"
1201 # Optionally we can also add DH to the list of accelerated items
1202 if [ "$test_target" = "ECC_DH" ]; then
1203 loc_accel_list="$loc_accel_list \
1204 ALG_FFDH \
1205 $(helper_get_psa_key_type_list "DH") \
1206 $(helper_get_psa_dh_group_list)"
1207 fi
1208
1209 # Configure
1210 # ---------
1211
1212 # Set common configurations between library's and driver's builds
1213 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
1214 # Disable all the builtin curves. All the required algs are accelerated.
1215 helper_disable_builtin_curves
1216
1217 # Build
1218 # -----
1219
1220 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1221 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1222 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1223 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1224
1225 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1226
1227 helper_libtestdriver1_make_main "$loc_accel_list"
1228
1229 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1230 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1231 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1232 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001233 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001234 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1235 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1236 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001237
1238 # Run the tests
1239 # -------------
1240
Valerio Settieb63eb22025-02-12 13:32:49 +01001241 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001242
1243 make test
1244
1245 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1246 tests/ssl-opt.sh
1247}
1248
1249# Common helper used by:
1250# - component_test_psa_crypto_config_reference_ecc_no_bignum
1251# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1252#
1253# The goal is to build and test a reference scenario (i.e. with builtin
1254# components) compared to the ones used in
1255# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
1256#
1257# It is meant to be used in conjunction with
1258# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
1259# coverage analysis in "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001260common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1261 test_target="$1"
1262
1263 # This is an internal helper to simplify text message handling
1264 if [ "$test_target" = "ECC_DH" ]; then
1265 accel_text="ECC/FFDH"
1266 else
1267 accel_text="ECC"
1268 fi
1269
1270 msg "build: full + non accelerated $accel_text algs + USE_PSA"
1271
1272 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
1273
1274 make
1275
1276 msg "test suites: full + non accelerated EC algs + USE_PSA"
1277 make test
1278
1279 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
1280 tests/ssl-opt.sh
1281}
1282
1283component_test_psa_crypto_config_accel_ecc_no_bignum () {
1284 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
1285}
1286
1287component_test_psa_crypto_config_reference_ecc_no_bignum () {
1288 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
1289}
1290
1291component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1292 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
1293}
1294
1295component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1296 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
1297}
1298
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001299component_test_tfm_config_as_is () {
1300 msg "build: configs/config-tfm.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +00001301 MBEDTLS_CONFIG="configs/config-tfm.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001302 CRYPTO_CONFIG="tf-psa-crypto/configs/ext/crypto_config_profile_medium.h"
Minos Galanakis4f619e12024-11-14 14:56:47 +00001303 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 +02001304 make
1305
1306 msg "test: configs/config-tfm.h - unit tests"
1307 make test
1308}
1309
Minos Galanakis471b34c2024-07-26 15:39:24 +01001310# Helper for setting common configurations between:
1311# - component_test_tfm_config_p256m_driver_accel_ec()
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001312# - component_test_tfm_config_no_p256m()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001313common_tfm_config () {
1314 # Enable TF-M config
1315 cp configs/config-tfm.h "$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001316 cp tf-psa-crypto/configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001317
Minos Galanakis471b34c2024-07-26 15:39:24 +01001318 # Config adjustment for better test coverage in our environment.
1319 # This is not needed just to build and pass tests.
1320 #
1321 # Enable filesystem I/O for the benefit of PK parse/write tests.
Minos Galanakis5da58e52024-11-07 15:35:33 +00001322 sed -i '/PROFILE_M_PSA_CRYPTO_CONFIG_H/i #define MBEDTLS_FS_IO' "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001323}
1324
1325# Keep this in sync with component_test_tfm_config() as they are both meant
1326# to be used in analyze_outcomes.py for driver's coverage analysis.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001327component_test_tfm_config_p256m_driver_accel_ec () {
1328 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1329
1330 common_tfm_config
1331
1332 # Build crypto library
David Horstmann5b93d972024-10-31 15:36:05 +00001333 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../framework/tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001334
1335 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1336 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1337 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1338 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001339 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001340 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1341 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001342 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1343 # Check that p256m was built
1344 grep -q p256_ecdsa_ library/libmbedcrypto.a
1345
1346 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1347 # files, so we want to ensure that it has not be re-enabled accidentally.
1348 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1349
1350 # Run the tests
1351 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1352 make test
1353}
1354
1355# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1356# they are both meant to be used in analyze_outcomes.py for driver's coverage
1357# analysis.
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001358component_test_tfm_config_no_p256m () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001359 common_tfm_config
1360
1361 # Disable P256M driver, which is on by default, so that analyze_outcomes
1362 # can compare this test with test_tfm_config_p256m_driver_accel_ec
Minos Galanakis5da58e52024-11-07 15:35:33 +00001363 sed -i '/PROFILE_M_PSA_CRYPTO_CONFIG_H/i #undef MBEDTLS_PSA_P256M_DRIVER_ENABLED' "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001364
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001365 msg "build: TF-M config without p256m"
David Horstmann5b93d972024-10-31 15:36:05 +00001366 make CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' tests
Minos Galanakis471b34c2024-07-26 15:39:24 +01001367
1368 # Check that p256m was not built
1369 not grep p256_ecdsa_ library/libmbedcrypto.a
1370
1371 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1372 # files, so we want to ensure that it has not be re-enabled accidentally.
1373 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1374
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001375 msg "test: TF-M config without p256m"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001376 make test
1377}
1378
Minos Galanakis471b34c2024-07-26 15:39:24 +01001379# This is an helper used by:
1380# - component_test_psa_ecc_key_pair_no_derive
1381# - component_test_psa_ecc_key_pair_no_generate
1382# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1383# enabled, but one. Input arguments are as follows:
Gilles Peskinefef912c2024-09-20 16:07:09 +02001384# - $1 is the configuration to start from
1385# - $2 is the key type under test, i.e. ECC/RSA/DH
1386# - $3 is the key option to be unset (i.e. generate, derive, etc)
Minos Galanakisf78447f2024-07-26 20:49:51 +01001387build_and_test_psa_want_key_pair_partial () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001388 base_config=$1
1389 key_type=$2
1390 unset_option=$3
Minos Galanakis471b34c2024-07-26 15:39:24 +01001391 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1392
Gilles Peskinefef912c2024-09-20 16:07:09 +02001393 msg "build: $base_config - ${disabled_psa_want}"
1394 scripts/config.py "$base_config"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001395
1396 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1397 # crypto_config.h so we just disable the one we don't want.
1398 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
1399
1400 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1401
Gilles Peskinefef912c2024-09-20 16:07:09 +02001402 msg "test: $base_config - ${disabled_psa_want}"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001403 make test
1404}
1405
Minos Galanakisf78447f2024-07-26 20:49:51 +01001406component_test_psa_ecc_key_pair_no_derive () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001407 build_and_test_psa_want_key_pair_partial full "ECC" "DERIVE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001408}
1409
Minos Galanakisf78447f2024-07-26 20:49:51 +01001410component_test_psa_ecc_key_pair_no_generate () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001411 # TLS needs ECC key generation whenever ephemeral ECDH is enabled.
1412 # We don't have proper guards for configurations with ECC key generation
1413 # disabled (https://github.com/Mbed-TLS/mbedtls/issues/9481). Until
1414 # then (if ever), just test the crypto part of the library.
1415 build_and_test_psa_want_key_pair_partial crypto_full "ECC" "GENERATE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001416}
1417
1418config_psa_crypto_accel_rsa () {
1419 driver_only=$1
1420
1421 # Start from crypto_full config (no X.509, no TLS)
1422 helper_libtestdriver1_adjust_config "crypto_full"
1423
1424 if [ "$driver_only" -eq 1 ]; then
1425 # Remove RSA support and its dependencies
1426 scripts/config.py unset MBEDTLS_RSA_C
1427 scripts/config.py unset MBEDTLS_PKCS1_V15
1428 scripts/config.py unset MBEDTLS_PKCS1_V21
1429
1430 # We need PEM parsing in the test library as well to support the import
1431 # of PEM encoded RSA keys.
Minos Galanakis23452f52024-11-28 17:48:14 +00001432 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1433 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
Minos Galanakis471b34c2024-07-26 15:39:24 +01001434 fi
1435}
1436
1437component_test_psa_crypto_config_accel_rsa_crypto () {
1438 msg "build: crypto_full with accelerated RSA"
1439
1440 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1441 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1442 KEY_TYPE_RSA_PUBLIC_KEY \
1443 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1444 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1445 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1446 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1447
1448 # Configure
1449 # ---------
1450
1451 config_psa_crypto_accel_rsa 1
1452
1453 # Build
1454 # -----
1455
1456 # These hashes are needed for unit tests.
1457 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1458 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1459 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1460
1461 helper_libtestdriver1_make_main "$loc_accel_list"
1462
1463 # Make sure this was not re-enabled by accident (additive config)
1464 not grep mbedtls_rsa ${BUILTIN_SRC_PATH}/rsa.o
1465
1466 # Run the tests
1467 # -------------
1468
1469 msg "test: crypto_full with accelerated RSA"
1470 make test
1471}
1472
1473component_test_psa_crypto_config_reference_rsa_crypto () {
1474 msg "build: crypto_full with non-accelerated RSA"
1475
1476 # Configure
1477 # ---------
1478 config_psa_crypto_accel_rsa 0
1479
1480 # Build
1481 # -----
1482 make
1483
1484 # Run the tests
1485 # -------------
1486 msg "test: crypto_full with non-accelerated RSA"
1487 make test
1488}
1489
1490# This is a temporary test to verify that full RSA support is present even when
1491# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001492component_test_new_psa_want_key_pair_symbol () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001493 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1494
1495 # Create a temporary output file unless there is already one set
1496 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1497 REMOVE_OUTCOME_ON_EXIT="no"
1498 else
1499 REMOVE_OUTCOME_ON_EXIT="yes"
1500 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1501 export MBEDTLS_TEST_OUTCOME_FILE
1502 fi
1503
1504 # Start from crypto configuration
1505 scripts/config.py crypto
1506
1507 # Remove RSA support and its dependencies
1508 scripts/config.py unset MBEDTLS_PKCS1_V15
1509 scripts/config.py unset MBEDTLS_PKCS1_V21
Minos Galanakis471b34c2024-07-26 15:39:24 +01001510 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1511 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001512 scripts/config.py unset MBEDTLS_RSA_C
1513 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1514
Minos Galanakis471b34c2024-07-26 15:39:24 +01001515 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
1516 # that proper translations is done in crypto_legacy.h.
1517 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
1518 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
1519 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
1520
1521 make
1522
1523 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1524 make test
1525
1526 # Parse only 1 relevant line from the outcome file, i.e. a test which is
1527 # performing RSA signature.
1528 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
1529 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
1530
1531 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
1532 rm $MBEDTLS_TEST_OUTCOME_FILE
1533 fi
1534}
1535
1536component_test_psa_crypto_config_accel_hash () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001537 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001538
1539 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1540 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1541 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1542
1543 # Configure
1544 # ---------
1545
1546 # Start from default config (no USE_PSA)
1547 helper_libtestdriver1_adjust_config "default"
1548
1549 # Disable the things that are being accelerated
1550 scripts/config.py unset MBEDTLS_MD5_C
1551 scripts/config.py unset MBEDTLS_RIPEMD160_C
1552 scripts/config.py unset MBEDTLS_SHA1_C
1553 scripts/config.py unset MBEDTLS_SHA224_C
1554 scripts/config.py unset MBEDTLS_SHA256_C
1555 scripts/config.py unset MBEDTLS_SHA384_C
1556 scripts/config.py unset MBEDTLS_SHA512_C
1557 scripts/config.py unset MBEDTLS_SHA3_C
1558
1559 # Build
1560 # -----
1561
1562 helper_libtestdriver1_make_drivers "$loc_accel_list"
1563
1564 helper_libtestdriver1_make_main "$loc_accel_list"
1565
1566 # There's a risk of something getting re-enabled via config_psa.h;
1567 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1568 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1569 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1570 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1571 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1572 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1573
1574 # Run the tests
1575 # -------------
1576
Ronald Cron93ba6252024-09-05 10:37:14 +02001577 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001578 make test
1579}
1580
1581# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001582config_psa_crypto_hash_use_psa () {
1583 driver_only="$1"
1584 # start with config full for maximum coverage (also enables USE_PSA)
1585 helper_libtestdriver1_adjust_config "full"
1586 if [ "$driver_only" -eq 1 ]; then
1587 # disable the built-in implementation of hashes
1588 scripts/config.py unset MBEDTLS_MD5_C
1589 scripts/config.py unset MBEDTLS_RIPEMD160_C
1590 scripts/config.py unset MBEDTLS_SHA1_C
1591 scripts/config.py unset MBEDTLS_SHA224_C
1592 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
1593 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
1594 scripts/config.py unset MBEDTLS_SHA384_C
1595 scripts/config.py unset MBEDTLS_SHA512_C
1596 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
1597 scripts/config.py unset MBEDTLS_SHA3_C
1598 fi
1599}
1600
1601# Note that component_test_psa_crypto_config_reference_hash_use_psa
1602# is related to this component and both components need to be kept in sync.
1603# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001604component_test_psa_crypto_config_accel_hash_use_psa () {
1605 msg "test: full with accelerated hashes"
1606
1607 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1608 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1609 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1610
1611 # Configure
1612 # ---------
1613
1614 config_psa_crypto_hash_use_psa 1
1615
1616 # Build
1617 # -----
1618
1619 helper_libtestdriver1_make_drivers "$loc_accel_list"
1620
1621 helper_libtestdriver1_make_main "$loc_accel_list"
1622
1623 # There's a risk of something getting re-enabled via config_psa.h;
1624 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1625 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1626 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1627 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1628 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1629 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1630
1631 # Run the tests
1632 # -------------
1633
1634 msg "test: full with accelerated hashes"
1635 make test
1636
1637 # This is mostly useful so that we can later compare outcome files with
1638 # the reference config in analyze_outcomes.py, to check that the
1639 # dependency declarations in ssl-opt.sh and in TLS code are correct.
1640 msg "test: ssl-opt.sh, full with accelerated hashes"
1641 tests/ssl-opt.sh
1642
1643 # This is to make sure all ciphersuites are exercised, but we don't need
1644 # interop testing (besides, we already got some from ssl-opt.sh).
1645 msg "test: compat.sh, full with accelerated hashes"
1646 tests/compat.sh -p mbedTLS -V YES
1647}
1648
1649# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
1650# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
1651# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
1652# Both components need to be kept in sync.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001653component_test_psa_crypto_config_reference_hash_use_psa () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001654 msg "test: full without accelerated hashes"
1655
1656 config_psa_crypto_hash_use_psa 0
1657
1658 make
1659
1660 msg "test: full without accelerated hashes"
1661 make test
1662
1663 msg "test: ssl-opt.sh, full without accelerated hashes"
1664 tests/ssl-opt.sh
1665}
1666
1667# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001668config_psa_crypto_hmac_use_psa () {
1669 driver_only="$1"
1670 # start with config full for maximum coverage (also enables USE_PSA)
1671 helper_libtestdriver1_adjust_config "full"
1672
1673 if [ "$driver_only" -eq 1 ]; then
1674 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
1675 # is still enabled though (for ENTROPY_C among others).
1676 scripts/config.py unset MBEDTLS_MD_C
1677 # Disable also the builtin hashes since they are supported by the driver
1678 # and MD module is able to perform PSA dispathing.
1679 scripts/config.py unset-all MBEDTLS_SHA
1680 scripts/config.py unset MBEDTLS_MD5_C
1681 scripts/config.py unset MBEDTLS_RIPEMD160_C
1682 fi
1683
1684 # Direct dependencies of MD_C. We disable them also in the reference
1685 # component to work with the same set of features.
1686 scripts/config.py unset MBEDTLS_PKCS7_C
1687 scripts/config.py unset MBEDTLS_PKCS5_C
1688 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1689 scripts/config.py unset MBEDTLS_HKDF_C
1690 # Dependencies of HMAC_DRBG
1691 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
1692 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
1693}
1694
Minos Galanakisf78447f2024-07-26 20:49:51 +01001695component_test_psa_crypto_config_accel_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001696 msg "test: full with accelerated hmac"
1697
1698 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
1699 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1700 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1701 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1702
1703 # Configure
1704 # ---------
1705
1706 config_psa_crypto_hmac_use_psa 1
1707
1708 # Build
1709 # -----
1710
1711 helper_libtestdriver1_make_drivers "$loc_accel_list"
1712
1713 helper_libtestdriver1_make_main "$loc_accel_list"
1714
1715 # Ensure that built-in support for HMAC is disabled.
1716 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
1717
1718 # Run the tests
1719 # -------------
1720
1721 msg "test: full with accelerated hmac"
1722 make test
1723}
1724
Minos Galanakisf78447f2024-07-26 20:49:51 +01001725component_test_psa_crypto_config_reference_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001726 msg "test: full without accelerated hmac"
1727
1728 config_psa_crypto_hmac_use_psa 0
1729
1730 make
1731
1732 msg "test: full without accelerated hmac"
1733 make test
1734}
1735
1736component_test_psa_crypto_config_accel_des () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001737 msg "test: accelerated DES"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001738
1739 # Albeit this components aims at accelerating DES which should only support
1740 # CBC and ECB modes, we need to accelerate more than that otherwise DES_C
1741 # would automatically be re-enabled by "config_adjust_legacy_from_psa.c"
1742 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 \
1743 ALG_CTR ALG_CFB ALG_OFB ALG_XTS ALG_CMAC \
1744 KEY_TYPE_DES"
1745
1746 # Note: we cannot accelerate all ciphers' key types otherwise we would also
1747 # have to either disable CCM/GCM or accelerate them, but that's out of scope
1748 # of this component. This limitation will be addressed by #8598.
1749
1750 # Configure
1751 # ---------
1752
1753 # Start from the full config
1754 helper_libtestdriver1_adjust_config "full"
1755
1756 # Disable the things that are being accelerated
1757 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1758 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
1759 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
1760 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
1761 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
1762 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
1763 scripts/config.py unset MBEDTLS_DES_C
1764 scripts/config.py unset MBEDTLS_CMAC_C
1765
1766 # Build
1767 # -----
1768
1769 helper_libtestdriver1_make_drivers "$loc_accel_list"
1770
1771 helper_libtestdriver1_make_main "$loc_accel_list"
1772
1773 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine29e86ca2024-06-19 15:09:27 +02001774 not grep mbedtls_des ${BUILTIN_SRC_PATH}/des.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001775
1776 # Run the tests
1777 # -------------
1778
Ronald Cron93ba6252024-09-05 10:37:14 +02001779 msg "test: accelerated DES"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001780 make test
1781}
1782
1783component_test_psa_crypto_config_accel_aead () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001784 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001785
1786 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
1787 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1788
1789 # Configure
1790 # ---------
1791
1792 # Start from full config
1793 helper_libtestdriver1_adjust_config "full"
1794
1795 # Disable things that are being accelerated
1796 scripts/config.py unset MBEDTLS_GCM_C
1797 scripts/config.py unset MBEDTLS_CCM_C
1798 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1799
1800 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
1801 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1802
1803 # Build
1804 # -----
1805
1806 helper_libtestdriver1_make_drivers "$loc_accel_list"
1807
1808 helper_libtestdriver1_make_main "$loc_accel_list"
1809
1810 # Make sure this was not re-enabled by accident (additive config)
1811 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1812 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1813 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1814
1815 # Run the tests
1816 # -------------
1817
Ronald Cron93ba6252024-09-05 10:37:14 +02001818 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001819 make test
1820}
1821
1822# This is a common configuration function used in:
1823# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1824# - component_test_psa_crypto_config_reference_cipher_aead_cmac
Minos Galanakisf78447f2024-07-26 20:49:51 +01001825common_psa_crypto_config_accel_cipher_aead_cmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001826 # Start from the full config
1827 helper_libtestdriver1_adjust_config "full"
1828
1829 scripts/config.py unset MBEDTLS_NIST_KW_C
1830}
1831
1832# The 2 following test components, i.e.
1833# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1834# - component_test_psa_crypto_config_reference_cipher_aead_cmac
1835# are meant to be used together in analyze_outcomes.py script in order to test
1836# driver's coverage for ciphers and AEADs.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001837component_test_psa_crypto_config_accel_cipher_aead_cmac () {
1838 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
1839
1840 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
1841 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
1842 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
1843 KEY_TYPE_DES KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
1844
1845 # Configure
1846 # ---------
1847
1848 common_psa_crypto_config_accel_cipher_aead_cmac
1849
1850 # Disable the things that are being accelerated
1851 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1852 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
1853 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
1854 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
1855 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
1856 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
1857 scripts/config.py unset MBEDTLS_GCM_C
1858 scripts/config.py unset MBEDTLS_CCM_C
1859 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1860 scripts/config.py unset MBEDTLS_CMAC_C
1861 scripts/config.py unset MBEDTLS_DES_C
1862 scripts/config.py unset MBEDTLS_AES_C
1863 scripts/config.py unset MBEDTLS_ARIA_C
1864 scripts/config.py unset MBEDTLS_CHACHA20_C
1865 scripts/config.py unset MBEDTLS_CAMELLIA_C
1866
1867 # Disable CIPHER_C entirely as all ciphers/AEADs are accelerated and PSA
1868 # does not depend on it.
1869 scripts/config.py unset MBEDTLS_CIPHER_C
1870
1871 # Build
1872 # -----
1873
1874 helper_libtestdriver1_make_drivers "$loc_accel_list"
1875
1876 helper_libtestdriver1_make_main "$loc_accel_list"
1877
1878 # Make sure this was not re-enabled by accident (additive config)
1879 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1880 not grep mbedtls_des ${BUILTIN_SRC_PATH}/des.o
1881 not grep mbedtls_aes ${BUILTIN_SRC_PATH}/aes.o
1882 not grep mbedtls_aria ${BUILTIN_SRC_PATH}/aria.o
1883 not grep mbedtls_camellia ${BUILTIN_SRC_PATH}/camellia.o
1884 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1885 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1886 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1887 not grep mbedtls_cmac ${BUILTIN_SRC_PATH}/cmac.o
1888
1889 # Run the tests
1890 # -------------
1891
1892 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
1893 make test
1894
1895 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
1896 tests/ssl-opt.sh
1897
1898 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
1899 tests/compat.sh -V NO -p mbedTLS
1900}
1901
1902component_test_psa_crypto_config_reference_cipher_aead_cmac () {
1903 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
1904 common_psa_crypto_config_accel_cipher_aead_cmac
1905
1906 make
1907
1908 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
1909 make test
1910
1911 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
1912 tests/ssl-opt.sh
1913
1914 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
1915 tests/compat.sh -V NO -p mbedTLS
1916}
1917
Minos Galanakisf78447f2024-07-26 20:49:51 +01001918common_block_cipher_dispatch () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001919 TEST_WITH_DRIVER="$1"
1920
1921 # Start from the full config
1922 helper_libtestdriver1_adjust_config "full"
1923
1924 if [ "$TEST_WITH_DRIVER" -eq 1 ]; then
1925 # Disable key types that are accelerated (there is no legacy equivalent
1926 # symbol for ECB)
1927 scripts/config.py unset MBEDTLS_AES_C
1928 scripts/config.py unset MBEDTLS_ARIA_C
1929 scripts/config.py unset MBEDTLS_CAMELLIA_C
1930 fi
1931
1932 # Disable cipher's modes that, when not accelerated, cause
1933 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
1934 # Keep this also in the reference component in order to skip the same tests
1935 # that were skipped in the accelerated one.
1936 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
1937 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
1938 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
1939 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
1940 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
1941 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
1942 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1943 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
1944
1945 # Disable direct dependency on AES_C
1946 scripts/config.py unset MBEDTLS_NIST_KW_C
1947
1948 # Prevent the cipher module from using deprecated PSA path. The reason is
1949 # that otherwise there will be tests relying on "aes_info" (defined in
1950 # "cipher_wrap.c") whose functions are not available when AES_C is
1951 # not defined. ARIA and Camellia are not a problem in this case because
1952 # the PSA path is not tested for these key types.
1953 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1954}
1955
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02001956component_test_full_block_cipher_psa_dispatch_static_keystore () {
1957 msg "build: full + PSA dispatch in block_cipher with static keystore"
1958 # Check that the static key store works well when CTR_DRBG uses a
1959 # PSA key for AES.
1960 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
1961
1962 loc_accel_list="ALG_ECB_NO_PADDING \
1963 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1964
1965 # Configure
1966 # ---------
1967
1968 common_block_cipher_dispatch 1
1969
1970 # Build
1971 # -----
1972
1973 helper_libtestdriver1_make_drivers "$loc_accel_list"
1974
1975 helper_libtestdriver1_make_main "$loc_accel_list"
1976
1977 # Make sure disabled components were not re-enabled by accident (additive
1978 # config)
1979 not grep mbedtls_aes_ library/aes.o
1980 not grep mbedtls_aria_ library/aria.o
1981 not grep mbedtls_camellia_ library/camellia.o
1982
1983 # Run the tests
1984 # -------------
1985
1986 msg "test: full + PSA dispatch in block_cipher with static keystore"
1987 make test
1988}
1989
Minos Galanakis471b34c2024-07-26 15:39:24 +01001990component_test_full_block_cipher_psa_dispatch () {
1991 msg "build: full + PSA dispatch in block_cipher"
1992
1993 loc_accel_list="ALG_ECB_NO_PADDING \
1994 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1995
1996 # Configure
1997 # ---------
1998
1999 common_block_cipher_dispatch 1
2000
2001 # Build
2002 # -----
2003
2004 helper_libtestdriver1_make_drivers "$loc_accel_list"
2005
2006 helper_libtestdriver1_make_main "$loc_accel_list"
2007
2008 # Make sure disabled components were not re-enabled by accident (additive
2009 # config)
2010 not grep mbedtls_aes_ ${BUILTIN_SRC_PATH}/aes.o
2011 not grep mbedtls_aria_ ${BUILTIN_SRC_PATH}/aria.o
2012 not grep mbedtls_camellia_ ${BUILTIN_SRC_PATH}/camellia.o
2013
2014 # Run the tests
2015 # -------------
2016
2017 msg "test: full + PSA dispatch in block_cipher"
2018 make test
2019}
2020
2021# This is the reference component of component_test_full_block_cipher_psa_dispatch
Minos Galanakis471b34c2024-07-26 15:39:24 +01002022component_test_full_block_cipher_legacy_dispatch () {
2023 msg "build: full + legacy dispatch in block_cipher"
2024
2025 common_block_cipher_dispatch 0
2026
2027 make
2028
2029 msg "test: full + legacy dispatch in block_cipher"
2030 make test
2031}
2032
Minos Galanakisf78447f2024-07-26 20:49:51 +01002033component_test_aead_chachapoly_disabled () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002034 msg "build: full minus CHACHAPOLY"
2035 scripts/config.py full
2036 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2037 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2038 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2039
2040 msg "test: full minus CHACHAPOLY"
2041 make test
2042}
2043
Minos Galanakisf78447f2024-07-26 20:49:51 +01002044component_test_aead_only_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002045 msg "build: full minus CHACHAPOLY and GCM"
2046 scripts/config.py full
2047 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2048 scripts/config.py unset MBEDTLS_GCM_C
2049 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2050 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2051 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2052
2053 msg "test: full minus CHACHAPOLY and GCM"
2054 make test
2055}
2056
Minos Galanakisf78447f2024-07-26 20:49:51 +01002057component_test_ccm_aes_sha256 () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002058 msg "build: CCM + AES + SHA256 configuration"
2059
Minos Galanakisa17ffc72024-12-02 23:57:30 +00002060 # Setting a blank config disables everyhing in the library side.
2061 echo '#define MBEDTLS_CONFIG_H ' >"$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00002062 cp tf-psa-crypto/configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
Ronald Cron9d262d72024-12-06 17:41:26 +01002063
Minos Galanakis471b34c2024-07-26 15:39:24 +01002064 make
Minos Galanakis471b34c2024-07-26 15:39:24 +01002065 msg "test: CCM + AES + SHA256 configuration"
2066 make test
2067}
2068
2069# Test that the given .o file builds with all (valid) combinations of the given options.
2070#
2071# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
2072#
2073# The validator function is the name of a function to validate the combination of options.
2074# It may be "" if all combinations are valid.
2075# It receives a string containing a combination of options, as passed to the compiler,
2076# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Minos Galanakisf78447f2024-07-26 20:49:51 +01002077build_test_config_combos () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002078 file=$1
2079 shift
2080 validate_options=$1
2081 shift
2082 options=("$@")
2083
2084 # clear all of the options so that they can be overridden on the clang commandline
2085 for opt in "${options[@]}"; do
2086 ./scripts/config.py unset ${opt}
2087 done
2088
2089 # enter the library directory
2090 cd library
2091
2092 # The most common issue is unused variables/functions, so ensure -Wunused is set.
2093 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
2094
2095 # Extract the command generated by the Makefile to build the target file.
2096 # This ensures that we have any include paths, macro definitions, etc
2097 # that may be applied by make.
2098 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
2099 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
2100
2101 makefile=$(TMPDIR=. mktemp)
2102 deps=""
2103
2104 len=${#options[@]}
2105 source_file=../${file%.o}.c
2106
2107 targets=0
2108 echo 'include Makefile' >${makefile}
2109
2110 for ((i = 0; i < $((2**${len})); i++)); do
2111 # generate each of 2^n combinations of options
2112 # each bit of $i is used to determine if options[i] will be set or not
2113 target="t"
2114 clang_args=""
2115 for ((j = 0; j < ${len}; j++)); do
2116 if (((i >> j) & 1)); then
2117 opt=-D${options[$j]}
2118 clang_args="${clang_args} ${opt}"
2119 target="${target}${opt}"
2120 fi
2121 done
2122
2123 # if combination is not known to be invalid, add it to the makefile
2124 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
2125 cmd="${compile_cmd} ${clang_args}"
2126 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
2127
2128 deps="${deps} ${target}"
2129 ((++targets))
2130 fi
2131 done
2132
2133 echo "build_test_config_combos: ${deps}" >> ${makefile}
2134
2135 # execute all of the commands via Make (probably in parallel)
2136 make -s -f ${makefile} build_test_config_combos
2137 echo "$targets targets checked"
2138
2139 # clean up the temporary makefile
2140 rm ${makefile}
2141}
2142
Minos Galanakisf78447f2024-07-26 20:49:51 +01002143validate_aes_config_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002144 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
2145 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
2146 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
2147 return 1
2148 fi
2149 fi
2150 return 0
2151}
2152
Minos Galanakisf78447f2024-07-26 20:49:51 +01002153component_build_aes_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002154 # 18s - around 90ms per clang invocation on M1 Pro
2155 #
2156 # aes.o has many #if defined(...) guards that intersect in complex ways.
2157 # Test that all the combinations build cleanly.
2158
2159 MBEDTLS_ROOT_DIR="$PWD"
2160 msg "build: aes.o for all combinations of relevant config options"
2161
2162 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002163 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002164 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2165 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2166
2167 cd "$MBEDTLS_ROOT_DIR"
2168 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
2169
2170 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES,
2171 # manually set or unset those configurations to check
2172 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
2173 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Minos Galanakis471b34c2024-07-26 15:39:24 +01002174 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002175 scripts/config.py unset MBEDTLS_NIST_KW_C
Ronald Cron54d1eec2024-09-06 09:55:38 +02002176
Minos Galanakis00b641c2024-11-28 23:05:10 +00002177 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
2178 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
2179 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
2180 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
Ronald Cron4153ebb2024-09-11 15:32:48 +02002181 # Note: The two unsets below are to be removed for Mbed TLS 4.0
Ronald Cron54d1eec2024-09-06 09:55:38 +02002182 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2183 scripts/config.py unset MBEDTLS_DES_C
2184
Minos Galanakis471b34c2024-07-26 15:39:24 +01002185 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002186 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002187 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2188 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2189}
2190
Minos Galanakisf78447f2024-07-26 20:49:51 +01002191component_test_sha3_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002192 msg "sha3 loop unroll variations"
2193
2194 # define minimal config sufficient to test SHA3
Ronald Crone7f289e2024-09-06 11:02:47 +02002195 cat > include/mbedtls/mbedtls_config.h << END
Ronald Crone7f289e2024-09-06 11:02:47 +02002196END
2197
2198 cat > tf-psa-crypto/include/psa/crypto_config.h << END
2199 #define PSA_WANT_ALG_SHA_256 1
2200 #define PSA_WANT_ALG_SHA3_224 1
2201 #define PSA_WANT_ALG_SHA3_256 1
2202 #define PSA_WANT_ALG_SHA3_384 1
2203 #define PSA_WANT_ALG_SHA3_512 1
Ronald Cron3dd1d3d2024-12-05 15:12:06 +01002204 #define MBEDTLS_AES_C
2205 #define MBEDTLS_CTR_DRBG_C
2206 #define MBEDTLS_ENTROPY_C
2207 #define MBEDTLS_PSA_CRYPTO_C
2208 #define MBEDTLS_SELF_TEST
Minos Galanakis471b34c2024-07-26 15:39:24 +01002209END
2210
2211 msg "all loops unrolled"
2212 make clean
2213 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"
2214 ./tf-psa-crypto/tests/test_suite_shax
2215
2216 msg "all loops rolled up"
2217 make clean
2218 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"
2219 ./tf-psa-crypto/tests/test_suite_shax
2220}
2221
Minos Galanakisf699d512024-08-01 11:32:30 +01002222support_build_aes_aesce_armcc () {
2223 support_build_armcc
2224}
2225
Minos Galanakis471b34c2024-07-26 15:39:24 +01002226# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2227component_build_aes_aesce_armcc () {
2228 msg "Build: AESCE test on arm64 platform without plain C."
2229 scripts/config.py baremetal
2230
2231 # armc[56] don't support SHA-512 intrinsics
2232 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2233
2234 # Stop armclang warning about feature detection for A64_CRYPTO.
2235 # With this enabled, the library does build correctly under armclang,
2236 # but in baremetal builds (as tested here), feature detection is
2237 # unavailable, and the user is notified via a #warning. So enabling
2238 # this feature would prevent us from building with -Werror on
2239 # armclang. Tracked in #7198.
2240 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2241 scripts/config.py set MBEDTLS_HAVE_ASM
2242
2243 msg "AESCE, build with default configuration."
2244 scripts/config.py set MBEDTLS_AESCE_C
2245 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002246 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002247
2248 msg "AESCE, build AESCE only"
2249 scripts/config.py set MBEDTLS_AESCE_C
2250 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002251 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002252}
2253
Minos Galanakis471b34c2024-07-26 15:39:24 +01002254component_test_aes_only_128_bit_keys () {
2255 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2256 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2257
2258 make CFLAGS='-O2 -Werror -Wall -Wextra'
2259
2260 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2261 make test
2262}
2263
2264component_test_no_ctr_drbg_aes_only_128_bit_keys () {
2265 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2266 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2267 scripts/config.py unset MBEDTLS_CTR_DRBG_C
2268
2269 make CC=clang CFLAGS='-Werror -Wall -Wextra'
2270
2271 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2272 make test
2273}
2274
2275component_test_aes_only_128_bit_keys_have_builtins () {
2276 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2277 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2278 scripts/config.py unset MBEDTLS_AESNI_C
2279 scripts/config.py unset MBEDTLS_AESCE_C
2280
2281 make CFLAGS='-O2 -Werror -Wall -Wextra'
2282
2283 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2284 make test
2285
2286 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2287 programs/test/selftest
2288}
2289
2290component_test_gcm_largetable () {
2291 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2292 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
2293 scripts/config.py unset MBEDTLS_AESNI_C
2294 scripts/config.py unset MBEDTLS_AESCE_C
2295
2296 make CFLAGS='-O2 -Werror -Wall -Wextra'
2297
2298 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2299 make test
2300}
2301
2302component_test_aes_fewer_tables () {
2303 msg "build: default config with AES_FEWER_TABLES enabled"
2304 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2305 make CFLAGS='-O2 -Werror -Wall -Wextra'
2306
2307 msg "test: AES_FEWER_TABLES"
2308 make test
2309}
2310
2311component_test_aes_rom_tables () {
2312 msg "build: default config with AES_ROM_TABLES enabled"
2313 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2314 make CFLAGS='-O2 -Werror -Wall -Wextra'
2315
2316 msg "test: AES_ROM_TABLES"
2317 make test
2318}
2319
2320component_test_aes_fewer_tables_and_rom_tables () {
2321 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
2322 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2323 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2324 make CFLAGS='-O2 -Werror -Wall -Wextra'
2325
2326 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2327 make test
2328}
2329
Ronald Cron66040472024-09-06 10:14:38 +02002330# helper for component_test_block_cipher_no_decrypt_aesni() which:
Minos Galanakis471b34c2024-07-26 15:39:24 +01002331# - enable/disable the list of config options passed from -s/-u respectively.
2332# - build
2333# - test for tests_suite_xxx
2334# - selftest
2335#
2336# Usage: helper_block_cipher_no_decrypt_build_test
2337# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
2338# Options: -s set_opts the list of config options to enable
2339# -u unset_opts the list of config options to disable
2340# -c cflags the list of options passed to CFLAGS
2341# -l ldflags the list of options passed to LDFLAGS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002342helper_block_cipher_no_decrypt_build_test () {
2343 while [ $# -gt 0 ]; do
2344 case "$1" in
2345 -s)
2346 shift; local set_opts="$1";;
2347 -u)
2348 shift; local unset_opts="$1";;
2349 -c)
2350 shift; local cflags="-Werror -Wall -Wextra $1";;
2351 -l)
2352 shift; local ldflags="$1";;
2353 esac
2354 shift
2355 done
2356 set_opts="${set_opts:-}"
2357 unset_opts="${unset_opts:-}"
2358 cflags="${cflags:-}"
2359 ldflags="${ldflags:-}"
2360
2361 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
2362 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
2363
2364 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2365 make clean
2366 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
2367
2368 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2369 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2370 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2371 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2372 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2373 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2374 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
2375 not grep mbedtls_aesni_inverse_key ${BUILTIN_SRC_PATH}/aesni.o
2376
2377 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2378 make test
2379
2380 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2381 programs/test/selftest
2382}
2383
Ronald Cron66040472024-09-06 10:14:38 +02002384# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
2385config_block_cipher_no_decrypt () {
2386 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
2387 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2388 scripts/config.py unset MBEDTLS_NIST_KW_C
2389
2390 # Enable support for cryptographic mechanisms through the PSA API.
2391 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
Ronald Cron66040472024-09-06 10:14:38 +02002392 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
2393 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
2394 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
2395 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
Ronald Cron4153ebb2024-09-11 15:32:48 +02002396 # Note: The two unsets below are to be removed for Mbed TLS 4.0
Ronald Cron66040472024-09-06 10:14:38 +02002397 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2398 scripts/config.py unset MBEDTLS_DES_C
2399}
2400
2401component_test_block_cipher_no_decrypt_aesni () {
2402 # Test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics, AESNI assembly and
2403 # AES C implementation on x86_64 and with AESNI intrinsics on x86.
2404
2405 # This consistently causes an llvm crash on clang 3.8, so use gcc
2406 export CC=gcc
2407 config_block_cipher_no_decrypt
2408
Minos Galanakis471b34c2024-07-26 15:39:24 +01002409 # test AESNI intrinsics
2410 helper_block_cipher_no_decrypt_build_test \
2411 -s "MBEDTLS_AESNI_C" \
2412 -c "-mpclmul -msse2 -maes"
2413
2414 # test AESNI assembly
2415 helper_block_cipher_no_decrypt_build_test \
2416 -s "MBEDTLS_AESNI_C" \
2417 -c "-mno-pclmul -mno-sse2 -mno-aes"
2418
2419 # test AES C implementation
2420 helper_block_cipher_no_decrypt_build_test \
2421 -u "MBEDTLS_AESNI_C"
2422
2423 # test AESNI intrinsics for i386 target
2424 helper_block_cipher_no_decrypt_build_test \
2425 -s "MBEDTLS_AESNI_C" \
2426 -c "-m32 -mpclmul -msse2 -maes" \
2427 -l "-m32"
2428}
2429
Minos Galanakisf699d512024-08-01 11:32:30 +01002430support_test_block_cipher_no_decrypt_aesce_armcc () {
2431 support_build_armcc
2432}
2433
Minos Galanakis471b34c2024-07-26 15:39:24 +01002434component_test_block_cipher_no_decrypt_aesce_armcc () {
2435 scripts/config.py baremetal
2436
2437 # armc[56] don't support SHA-512 intrinsics
2438 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2439
2440 # Stop armclang warning about feature detection for A64_CRYPTO.
2441 # With this enabled, the library does build correctly under armclang,
2442 # but in baremetal builds (as tested here), feature detection is
2443 # unavailable, and the user is notified via a #warning. So enabling
2444 # this feature would prevent us from building with -Werror on
2445 # armclang. Tracked in #7198.
2446 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2447 scripts/config.py set MBEDTLS_HAVE_ASM
2448
Ronald Cron66040472024-09-06 10:14:38 +02002449 config_block_cipher_no_decrypt
Minos Galanakis471b34c2024-07-26 15:39:24 +01002450
2451 # test AESCE baremetal build
2452 scripts/config.py set MBEDTLS_AESCE_C
2453 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002454 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002455
2456 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2457 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2458 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2459 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2460 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2461 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2462 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
2463 not grep mbedtls_aesce_inverse_key ${BUILTIN_SRC_PATH}/aesce.o
2464 not grep aesce_decrypt_block ${BUILTIN_SRC_PATH}/aesce.o
2465}
2466
2467component_test_ctr_drbg_aes_256_sha_256 () {
2468 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2469 scripts/config.py full
2470 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2471 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
2472 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2473 make
2474
2475 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2476 make test
2477}
2478
2479component_test_ctr_drbg_aes_128_sha_512 () {
2480 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2481 scripts/config.py full
2482 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2483 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2484 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2485 make
2486
2487 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2488 make test
2489}
2490
2491component_test_ctr_drbg_aes_128_sha_256 () {
2492 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2493 scripts/config.py full
2494 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2495 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2496 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
2497 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2498 make
2499
2500 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2501 make test
2502}
2503
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002504component_test_full_static_keystore () {
2505 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2506 scripts/config.py full
2507 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2508 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
2509
2510 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2511 make test
2512}
2513
Minos Galanakis471b34c2024-07-26 15:39:24 +01002514component_test_psa_crypto_drivers () {
Ronald Crona0afbfb2024-10-15 13:20:31 +02002515 # Test dispatch to drivers and fallbacks with
2516 # test_suite_psa_crypto_driver_wrappers test suite. The test drivers that
2517 # are wrappers around the builtin drivers are activated by
2518 # PSA_CRYPTO_DRIVER_TEST.
2519 #
2520 # For the time being, some test cases in test_suite_block_cipher and
2521 # test_suite_md.psa rely on this component to be run at least once by the
2522 # CI. This should disappear as we progress the 4.x work. See
2523 # config_adjust_test_accelerators.h for more information.
Minos Galanakis471b34c2024-07-26 15:39:24 +01002524 msg "build: full + test drivers dispatching to builtins"
2525 scripts/config.py full
Ronald Cron67cc6a72024-10-14 10:55:24 +02002526 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_CONFIG_ADJUST_TEST_ACCELERATORS"
David Horstmann5b93d972024-10-31 15:36:05 +00002527 loc_cflags="${loc_cflags} -I../framework/tests/include"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002528
2529 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
2530
2531 msg "test: full + test drivers dispatching to builtins"
2532 make test
2533}
2534
2535component_build_psa_config_file () {
Minos Galanakis4f619e12024-11-14 14:56:47 +00002536 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002537 cp "$CRYPTO_CONFIG_H" psa_test_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002538 echo '#error "TF_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
2539 make CFLAGS="-I '$PWD' -DTF_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002540 # Make sure this feature is enabled. We'll disable it in the next phase.
2541 programs/test/query_compile_time_config MBEDTLS_CMAC_C
2542 make clean
2543
Minos Galanakis4f619e12024-11-14 14:56:47 +00002544 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE + TF_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002545 # In the user config, disable one feature and its dependencies, which will
2546 # reflect on the mbedtls configuration so we can query it with
2547 # query_compile_time_config.
2548 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
2549 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
Minos Galanakisaa2f12c2024-10-22 15:31:07 +01002550 echo '#undef MBEDTLS_CMAC_C' >> psa_user_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002551 make CFLAGS="-I '$PWD' -DTF_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DTF_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002552 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
2553
2554 rm -f psa_test_config.h psa_user_config.h
2555}
2556
2557component_build_psa_alt_headers () {
2558 msg "build: make with PSA alt headers" # ~20s
2559
2560 # Generate alternative versions of the substitutable headers with the
2561 # same content except different include guards.
David Horstmanndc459512024-11-07 17:08:11 +00002562 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 +01002563
2564 # Build the library and some programs.
2565 # Don't build the fuzzers to avoid having to go through hoops to set
2566 # a correct include path for programs/fuzz/Makefile.
David Horstmann5b93d972024-10-31 15:36:05 +00002567 make CFLAGS="-I ../framework/tests/include/alt-extra -DMBEDTLS_PSA_CRYPTO_PLATFORM_FILE='\"psa/crypto_platform_alt.h\"' -DMBEDTLS_PSA_CRYPTO_STRUCT_FILE='\"psa/crypto_struct_alt.h\"'" lib
2568 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 +01002569
2570 # Check that we're getting the alternative include guards and not the
2571 # original include guards.
2572 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
2573 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
2574 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
2575 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
2576}
2577
2578component_test_min_mpi_window_size () {
2579 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
2580 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
2581 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2582 make
2583
2584 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2585 make test
2586}