blob: 34b3107815487c8ef0835448928a932410b342df [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
264component_test_psa_inject_entropy () {
265 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
266 scripts/config.py full
267 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
268 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
269 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
270 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
271 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
272 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
Minos Galanakis4f619e12024-11-14 14:56:47 +0000273 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS '-DTF_PSA_CRYPTO_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100274
275 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
276 make test
277}
278
Minos Galanakisf78447f2024-07-26 20:49:51 +0100279component_full_no_pkparse_pkwrite () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100280 msg "build: full without pkparse and pkwrite"
281
282 scripts/config.py crypto_full
283 scripts/config.py unset MBEDTLS_PK_PARSE_C
284 scripts/config.py unset MBEDTLS_PK_WRITE_C
285
286 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
287
288 # Ensure that PK_[PARSE|WRITE]_C were not re-enabled accidentally (additive config).
289 not grep mbedtls_pk_parse_key ${BUILTIN_SRC_PATH}/pkparse.o
290 not grep mbedtls_pk_write_key_der ${BUILTIN_SRC_PATH}/pkwrite.o
291
292 msg "test: full without pkparse and pkwrite"
293 make test
294}
295
296component_test_crypto_full_md_light_only () {
297 msg "build: crypto_full with only the light subset of MD"
298 scripts/config.py crypto_full
299
300 # Disable MD
301 scripts/config.py unset MBEDTLS_MD_C
302 # Disable direct dependencies of MD_C
303 scripts/config.py unset MBEDTLS_HKDF_C
304 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
305 scripts/config.py unset MBEDTLS_PKCS7_C
306 # Disable indirect dependencies of MD_C
307 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG
Minos Galanakis00b641c2024-11-28 23:05:10 +0000308 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
Minos Galanakis471b34c2024-07-26 15:39:24 +0100309 # Disable things that would auto-enable MD_C
310 scripts/config.py unset MBEDTLS_PKCS5_C
311
312 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
313 # which we haven't disabled, so no need to explicitly enable it.
314 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
315
316 # Make sure we don't have the HMAC functions, but the hashing functions
317 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
318 grep mbedtls_md ${BUILTIN_SRC_PATH}/md.o
319
320 msg "test: crypto_full with only the light subset of MD"
321 make test
322}
323
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100324component_test_full_no_cipher () {
325 msg "build: full no CIPHER"
326
327 scripts/config.py full
328 scripts/config.py unset MBEDTLS_CIPHER_C
329
330 # The built-in implementation of the following algs/key-types depends
331 # on CIPHER_C so we disable them.
332 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
333 # so we keep them enabled.
Minos Galanakis00b641c2024-11-28 23:05:10 +0000334 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
335 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CMAC
336 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
337 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
338 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CFB
339 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CTR
340 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
341 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_OFB
342 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
343 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_STREAM_CIPHER
344 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100345
346 # The following modules directly depends on CIPHER_C
347 scripts/config.py unset MBEDTLS_CMAC_C
348 scripts/config.py unset MBEDTLS_NIST_KW_C
349
350 make
351
352 # Ensure that CIPHER_C was not re-enabled
353 not grep mbedtls_cipher_init ${BUILTIN_SRC_PATH}/cipher.o
354
355 msg "test: full no CIPHER"
356 make test
357}
358
Minos Galanakisf78447f2024-07-26 20:49:51 +0100359component_test_full_no_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100360 msg "build: full no PSA_WANT_ALG_CCM"
361
362 # Full config enables:
363 # - USE_PSA_CRYPTO so that TLS code dispatches cipher/AEAD to PSA
364 # - CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
365 scripts/config.py full
366
367 # Disable PSA_WANT_ALG_CCM so that CCM is not supported in PSA. CCM_C is still
368 # enabled, but not used from TLS since USE_PSA is set.
369 # This is helpful to ensure that TLS tests below have proper dependencies.
370 #
371 # Note: also PSA_WANT_ALG_CCM_STAR_NO_TAG is enabled, but it does not cause
372 # PSA_WANT_ALG_CCM to be re-enabled.
373 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM
374
375 make
376
377 msg "test: full no PSA_WANT_ALG_CCM"
378 make test
379}
380
Minos Galanakisf78447f2024-07-26 20:49:51 +0100381component_test_full_no_ccm_star_no_tag () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100382 msg "build: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
383
384 # Full config enables CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
385 scripts/config.py full
386
387 # Disable CCM_STAR_NO_TAG, which is the target of this test, as well as all
388 # other components that enable MBEDTLS_PSA_BUILTIN_CIPHER internal symbol.
389 # This basically disables all unauthenticated ciphers on the PSA side, while
390 # keeping AEADs enabled.
391 #
392 # Note: PSA_WANT_ALG_CCM is enabled, but it does not cause
393 # PSA_WANT_ALG_CCM_STAR_NO_TAG to be re-enabled.
394 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
395 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_STREAM_CIPHER
396 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
397 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
398 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
399 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
400 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
401 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
402
403 make
404
405 # Ensure MBEDTLS_PSA_BUILTIN_CIPHER was not enabled
406 not grep mbedtls_psa_cipher ${PSA_CORE_PATH}/psa_crypto_cipher.o
407
408 msg "test: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
409 make test
410}
411
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200412component_test_config_symmetric_only () {
413 msg "build: configs/config-symmetric-only.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +0000414 MBEDTLS_CONFIG="configs/config-symmetric-only.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +0000415 CRYPTO_CONFIG="tf-psa-crypto/configs/crypto-config-symmetric-only.h"
Ronald Cronfaadfc22024-12-07 17:24:28 +0100416 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 +0200417 make
418
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200419 msg "test: configs/config-symmetric-only.h - unit tests"
Gilles Peskineaf5a8992024-09-14 11:27:44 +0200420 make test
421}
422
Minos Galanakisc06fd302024-08-01 12:16:59 +0100423component_test_everest () {
424 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
425 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
426 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
427 make
428
429 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
430 make test
431
432 msg "test: metatests (clang, ASan)"
433 tests/scripts/run-metatests.sh any asan poison
434
435 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
436 tests/ssl-opt.sh -f ECDH
437
438 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
439 # Exclude some symmetric ciphers that are redundant here to gain time.
440 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
441}
442
443component_test_everest_curve25519_only () {
444 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
Minos Galanakisc06fd302024-08-01 12:16:59 +0100445 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
446 scripts/config.py unset MBEDTLS_ECDSA_C
Minos Galanakis00b641c2024-11-28 23:05:10 +0000447 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
448 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECDSA
449 scripts/config.py -c $CRYPTO_CONFIG_H set PSA_WANT_ALG_ECDH
Minos Galanakisc06fd302024-08-01 12:16:59 +0100450 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
451 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
452 scripts/config.py unset MBEDTLS_ECJPAKE_C
Minos Galanakis00b641c2024-11-28 23:05:10 +0000453 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE
Minos Galanakisc06fd302024-08-01 12:16:59 +0100454
455 # Disable all curves
456 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
Minos Galanakis00b641c2024-11-28 23:05:10 +0000457 scripts/config.py -c $CRYPTO_CONFIG_H unset-all "PSA_WANT_ECC_[0-9A-Z_a-z]*$"
458 scripts/config.py -c $CRYPTO_CONFIG_H set PSA_WANT_ECC_MONTGOMERY_255
Minos Galanakisc06fd302024-08-01 12:16:59 +0100459
460 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
461
462 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
463 make test
464}
465
Minos Galanakis471b34c2024-07-26 15:39:24 +0100466component_test_psa_collect_statuses () {
467 msg "build+test: psa_collect_statuses" # ~30s
468 scripts/config.py full
469 tests/scripts/psa_collect_statuses.py
470 # Check that psa_crypto_init() succeeded at least once
471 grep -q '^0:psa_crypto_init:' tests/statuses.log
472 rm -f tests/statuses.log
473}
474
475# Check that the specified libraries exist and are empty.
476are_empty_libraries () {
477 nm "$@" >/dev/null 2>/dev/null
478 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
479}
480
Minos Galanakis471b34c2024-07-26 15:39:24 +0100481component_test_crypto_for_psa_service () {
482 msg "build: make, config for PSA crypto service"
483 scripts/config.py crypto
484 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
485 # Disable things that are not needed for just cryptography, to
486 # reach a configuration that would be typical for a PSA cryptography
487 # service providing all implemented PSA algorithms.
488 # System stuff
489 scripts/config.py unset MBEDTLS_ERROR_C
490 scripts/config.py unset MBEDTLS_TIMING_C
491 scripts/config.py unset MBEDTLS_VERSION_FEATURES
492 # Crypto stuff with no PSA interface
493 scripts/config.py unset MBEDTLS_BASE64_C
494 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
495 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
496 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
497 scripts/config.py unset MBEDTLS_NIST_KW_C
498 scripts/config.py unset MBEDTLS_PEM_PARSE_C
499 scripts/config.py unset MBEDTLS_PEM_WRITE_C
500 scripts/config.py unset MBEDTLS_PKCS12_C
501 scripts/config.py unset MBEDTLS_PKCS5_C
502 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
503 # in PSA code to work with RSA keys. We don't require users to set those:
504 # they will be reenabled in build_info.h.
505 scripts/config.py unset MBEDTLS_PK_C
506 scripts/config.py unset MBEDTLS_PK_PARSE_C
507 scripts/config.py unset MBEDTLS_PK_WRITE_C
508 make CFLAGS='-O1 -Werror' all test
509 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
510}
511
512component_build_crypto_baremetal () {
513 msg "build: make, crypto only, baremetal config"
514 scripts/config.py crypto_baremetal
David Horstmann5b93d972024-10-31 15:36:05 +0000515 make CFLAGS="-O1 -Werror -I$PWD/framework/tests/include/baremetal-override/"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100516 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
517}
518
519support_build_crypto_baremetal () {
520 support_build_baremetal "$@"
521}
522
523# depends.py family of tests
524component_test_depends_py_cipher_id () {
525 msg "test/build: depends.py cipher_id (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200526 tests/scripts/depends.py cipher_id
Minos Galanakis471b34c2024-07-26 15:39:24 +0100527}
528
529component_test_depends_py_cipher_chaining () {
530 msg "test/build: depends.py cipher_chaining (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200531 tests/scripts/depends.py cipher_chaining
Minos Galanakis471b34c2024-07-26 15:39:24 +0100532}
533
534component_test_depends_py_cipher_padding () {
535 msg "test/build: depends.py cipher_padding (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200536 tests/scripts/depends.py cipher_padding
Minos Galanakis471b34c2024-07-26 15:39:24 +0100537}
538
539component_test_depends_py_curves () {
540 msg "test/build: depends.py curves (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200541 tests/scripts/depends.py curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100542}
543
544component_test_depends_py_hashes () {
545 msg "test/build: depends.py hashes (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200546 tests/scripts/depends.py hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +0100547}
548
Minos Galanakis471b34c2024-07-26 15:39:24 +0100549component_test_depends_py_pkalgs () {
550 msg "test/build: depends.py pkalgs (gcc)"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100551 tests/scripts/depends.py pkalgs
552}
553
554component_test_psa_crypto_config_ffdh_2048_only () {
555 msg "build: full config - only DH 2048"
556
557 scripts/config.py full
558
559 # Disable all DH groups other than 2048.
560 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_3072
561 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_4096
562 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_6144
563 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_8192
564
565 make CFLAGS="$ASAN_CFLAGS -Werror" LDFLAGS="$ASAN_CFLAGS"
566
567 msg "test: full config - only DH 2048"
568 make test
569
570 msg "ssl-opt: full config - only DH 2048"
571 tests/ssl-opt.sh -f "ffdh"
572}
573
Minos Galanakis471b34c2024-07-26 15:39:24 +0100574component_test_psa_crypto_config_accel_ecdsa () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200575 msg "build: accelerated ECDSA"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100576
577 # Algorithms and key types to accelerate
578 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
579 $(helper_get_psa_key_type_list "ECC") \
580 $(helper_get_psa_curve_list)"
581
582 # Configure
583 # ---------
584
Elena Uziunaite91d83862024-09-04 14:51:31 +0100585 # Start from default config + TLS 1.3
Minos Galanakis471b34c2024-07-26 15:39:24 +0100586 helper_libtestdriver1_adjust_config "default"
587
588 # Disable the module that's accelerated
589 scripts/config.py unset MBEDTLS_ECDSA_C
590
591 # Disable things that depend on it
592 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
593 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
594
595 # Build
596 # -----
597
598 # These hashes are needed for some ECDSA signature tests.
Elena Uziunaiteffce45c2024-09-12 14:58:52 +0100599 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 +0100600 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
601
602 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
603
604 helper_libtestdriver1_make_main "$loc_accel_list"
605
606 # Make sure this was not re-enabled by accident (additive config)
607 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
608
609 # Run the tests
610 # -------------
611
Ronald Cron93ba6252024-09-05 10:37:14 +0200612 msg "test: accelerated ECDSA"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100613 make test
614}
615
616component_test_psa_crypto_config_accel_ecdh () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200617 msg "build: accelerated ECDH"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100618
619 # Algorithms and key types to accelerate
620 loc_accel_list="ALG_ECDH \
621 $(helper_get_psa_key_type_list "ECC") \
622 $(helper_get_psa_curve_list)"
623
624 # Configure
625 # ---------
626
627 # Start from default config (no USE_PSA)
628 helper_libtestdriver1_adjust_config "default"
629
630 # Disable the module that's accelerated
631 scripts/config.py unset MBEDTLS_ECDH_C
632
633 # Disable things that depend on it
634 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
635 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
636 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
637 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
638 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
639
640 # Build
641 # -----
642
643 helper_libtestdriver1_make_drivers "$loc_accel_list"
644
645 helper_libtestdriver1_make_main "$loc_accel_list"
646
647 # Make sure this was not re-enabled by accident (additive config)
648 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
649
650 # Run the tests
651 # -------------
652
Ronald Cron93ba6252024-09-05 10:37:14 +0200653 msg "test: accelerated ECDH"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100654 make test
655}
656
657component_test_psa_crypto_config_accel_ffdh () {
658 msg "build: full with accelerated FFDH"
659
660 # Algorithms and key types to accelerate
661 loc_accel_list="ALG_FFDH \
662 $(helper_get_psa_key_type_list "DH") \
663 $(helper_get_psa_dh_group_list)"
664
665 # Configure
666 # ---------
667
668 # start with full (USE_PSA and TLS 1.3)
669 helper_libtestdriver1_adjust_config "full"
670
671 # Disable the module that's accelerated
672 scripts/config.py unset MBEDTLS_DHM_C
673
Minos Galanakis471b34c2024-07-26 15:39:24 +0100674 # Build
675 # -----
676
677 helper_libtestdriver1_make_drivers "$loc_accel_list"
678
679 helper_libtestdriver1_make_main "$loc_accel_list"
680
681 # Make sure this was not re-enabled by accident (additive config)
682 not grep mbedtls_dhm_ ${BUILTIN_SRC_PATH}/dhm.o
683
684 # Run the tests
685 # -------------
686
687 msg "test: full with accelerated FFDH"
688 make test
689
690 msg "ssl-opt: full with accelerated FFDH alg"
691 tests/ssl-opt.sh -f "ffdh"
692}
693
694component_test_psa_crypto_config_reference_ffdh () {
695 msg "build: full with non-accelerated FFDH"
696
697 # Start with full (USE_PSA and TLS 1.3)
698 helper_libtestdriver1_adjust_config "full"
699
Minos Galanakis471b34c2024-07-26 15:39:24 +0100700 make
701
702 msg "test suites: full with non-accelerated FFDH alg"
703 make test
704
705 msg "ssl-opt: full with non-accelerated FFDH alg"
706 tests/ssl-opt.sh -f "ffdh"
707}
708
Minos Galanakisf78447f2024-07-26 20:49:51 +0100709component_test_psa_crypto_config_accel_pake () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100710 msg "build: full with accelerated PAKE"
711
712 loc_accel_list="ALG_JPAKE \
713 $(helper_get_psa_key_type_list "ECC") \
714 $(helper_get_psa_curve_list)"
715
716 # Configure
717 # ---------
718
719 helper_libtestdriver1_adjust_config "full"
720
721 # Make built-in fallback not available
722 scripts/config.py unset MBEDTLS_ECJPAKE_C
723 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
724
725 # Build
726 # -----
727
728 helper_libtestdriver1_make_drivers "$loc_accel_list"
729
730 helper_libtestdriver1_make_main "$loc_accel_list"
731
732 # Make sure this was not re-enabled by accident (additive config)
733 not grep mbedtls_ecjpake_init ${BUILTIN_SRC_PATH}/ecjpake.o
734
735 # Run the tests
736 # -------------
737
738 msg "test: full with accelerated PAKE"
739 make test
740}
741
742component_test_psa_crypto_config_accel_ecc_some_key_types () {
743 msg "build: full with accelerated EC algs and some key types"
744
745 # Algorithms and key types to accelerate
746 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
747 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
748 ALG_ECDH \
749 ALG_JPAKE \
750 KEY_TYPE_ECC_PUBLIC_KEY \
751 KEY_TYPE_ECC_KEY_PAIR_BASIC \
752 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
753 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
754 $(helper_get_psa_curve_list)"
755
756 # Configure
757 # ---------
758
759 # start with config full for maximum coverage (also enables USE_PSA)
760 helper_libtestdriver1_adjust_config "full"
761
762 # Disable modules that are accelerated - some will be re-enabled
763 scripts/config.py unset MBEDTLS_ECDSA_C
764 scripts/config.py unset MBEDTLS_ECDH_C
765 scripts/config.py unset MBEDTLS_ECJPAKE_C
766 scripts/config.py unset MBEDTLS_ECP_C
767
768 # Disable all curves - those that aren't accelerated should be re-enabled
769 helper_disable_builtin_curves
770
771 # Restartable feature is not yet supported by PSA. Once it will in
772 # the future, the following line could be removed (see issues
773 # 6061, 6332 and following ones)
774 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
775
776 # this is not supported by the driver API yet
777 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
778
779 # Build
780 # -----
781
782 # These hashes are needed for some ECDSA signature tests.
783 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
784 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
785 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
786
787 helper_libtestdriver1_make_main "$loc_accel_list"
788
789 # ECP should be re-enabled but not the others
790 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
791 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
792 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
793 grep mbedtls_ecp ${BUILTIN_SRC_PATH}/ecp.o
794
795 # Run the tests
796 # -------------
797
798 msg "test suites: full with accelerated EC algs and some key types"
799 make test
800}
801
802# Run tests with only (non-)Weierstrass accelerated
803# Common code used in:
804# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
805# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100806common_test_psa_crypto_config_accel_ecc_some_curves () {
807 weierstrass=$1
808 if [ $weierstrass -eq 1 ]; then
809 desc="Weierstrass"
810 else
811 desc="non-Weierstrass"
812 fi
813
814 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
815
816 # Note: Curves are handled in a special way by the libtestdriver machinery,
817 # so we only want to include them in the accel list when building the main
818 # libraries, hence the use of a separate variable.
819 # Note: the following loop is a modified version of
820 # helper_get_psa_curve_list that only keeps Weierstrass families.
821 loc_weierstrass_list=""
822 loc_non_weierstrass_list=""
823 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
824 case $item in
825 ECC_BRAINPOOL*|ECC_SECP*)
826 loc_weierstrass_list="$loc_weierstrass_list $item"
827 ;;
828 *)
829 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
830 ;;
831 esac
832 done
833 if [ $weierstrass -eq 1 ]; then
834 loc_curve_list=$loc_weierstrass_list
835 else
836 loc_curve_list=$loc_non_weierstrass_list
837 fi
838
839 # Algorithms and key types to accelerate
840 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
841 ALG_ECDH \
842 ALG_JPAKE \
843 $(helper_get_psa_key_type_list "ECC") \
844 $loc_curve_list"
845
846 # Configure
847 # ---------
848
849 # Start with config crypto_full and remove PK_C:
850 # that's what's supported now, see docs/driver-only-builds.md.
851 helper_libtestdriver1_adjust_config "crypto_full"
852 scripts/config.py unset MBEDTLS_PK_C
853 scripts/config.py unset MBEDTLS_PK_PARSE_C
854 scripts/config.py unset MBEDTLS_PK_WRITE_C
855
856 # Disable modules that are accelerated - some will be re-enabled
857 scripts/config.py unset MBEDTLS_ECDSA_C
858 scripts/config.py unset MBEDTLS_ECDH_C
859 scripts/config.py unset MBEDTLS_ECJPAKE_C
860 scripts/config.py unset MBEDTLS_ECP_C
861
862 # Disable all curves - those that aren't accelerated should be re-enabled
863 helper_disable_builtin_curves
864
865 # Restartable feature is not yet supported by PSA. Once it will in
866 # the future, the following line could be removed (see issues
867 # 6061, 6332 and following ones)
868 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
869
870 # this is not supported by the driver API yet
871 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
872
873 # Build
874 # -----
875
876 # These hashes are needed for some ECDSA signature tests.
877 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
878 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
879 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
880
881 helper_libtestdriver1_make_main "$loc_accel_list"
882
883 # We expect ECDH to be re-enabled for the missing curves
884 grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
885 # We expect ECP to be re-enabled, however the parts specific to the
886 # families of curves that are accelerated should be ommited.
887 # - functions with mxz in the name are specific to Montgomery curves
888 # - ecp_muladd is specific to Weierstrass curves
889 ##nm ${BUILTIN_SRC_PATH}/ecp.o | tee ecp.syms
890 if [ $weierstrass -eq 1 ]; then
891 not grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
892 grep mxz ${BUILTIN_SRC_PATH}/ecp.o
893 else
894 grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
895 not grep mxz ${BUILTIN_SRC_PATH}/ecp.o
896 fi
897 # We expect ECDSA and ECJPAKE to be re-enabled only when
898 # Weierstrass curves are not accelerated
899 if [ $weierstrass -eq 1 ]; then
900 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
901 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
902 else
903 grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
904 grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
905 fi
906
907 # Run the tests
908 # -------------
909
910 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
911 make test
912}
913
914component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
915 common_test_psa_crypto_config_accel_ecc_some_curves 1
916}
917
918component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
919 common_test_psa_crypto_config_accel_ecc_some_curves 0
920}
921
922# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
923# ECDH, ECDSA) with and without drivers.
924# The input parameter is a boolean value which indicates:
925# - 0 keep built-in EC algs,
926# - 1 exclude built-in EC algs (driver only).
927#
928# This is used by the two following components to ensure they always use the
929# same config, except for the use of driver or built-in EC algorithms:
930# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
931# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
932# This supports comparing their test coverage with analyze_outcomes.py.
Minos Galanakis471b34c2024-07-26 15:39:24 +0100933config_psa_crypto_config_ecp_light_only () {
934 driver_only="$1"
935 # start with config full for maximum coverage (also enables USE_PSA)
936 helper_libtestdriver1_adjust_config "full"
937 if [ "$driver_only" -eq 1 ]; then
938 # Disable modules that are accelerated
939 scripts/config.py unset MBEDTLS_ECDSA_C
940 scripts/config.py unset MBEDTLS_ECDH_C
941 scripts/config.py unset MBEDTLS_ECJPAKE_C
942 scripts/config.py unset MBEDTLS_ECP_C
943 fi
944
945 # Restartable feature is not yet supported by PSA. Once it will in
946 # the future, the following line could be removed (see issues
947 # 6061, 6332 and following ones)
948 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
949}
950
951# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100952component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
953 msg "build: full with accelerated EC algs"
954
955 # Algorithms and key types to accelerate
956 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
957 ALG_ECDH \
958 ALG_JPAKE \
959 $(helper_get_psa_key_type_list "ECC") \
960 $(helper_get_psa_curve_list)"
961
962 # Configure
963 # ---------
964
965 # Use the same config as reference, only without built-in EC algs
966 config_psa_crypto_config_ecp_light_only 1
967
968 # Do not disable builtin curves because that support is required for:
969 # - MBEDTLS_PK_PARSE_EC_EXTENDED
970 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
971
972 # Build
973 # -----
974
975 # These hashes are needed for some ECDSA signature tests.
976 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
977 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
978 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
979
980 helper_libtestdriver1_make_main "$loc_accel_list"
981
982 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
983 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
984 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
985 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
986 not grep mbedtls_ecp_mul ${BUILTIN_SRC_PATH}/ecp.o
987
988 # Run the tests
989 # -------------
990
991 msg "test suites: full with accelerated EC algs"
992 make test
993
994 msg "ssl-opt: full with accelerated EC algs"
995 tests/ssl-opt.sh
996}
997
998# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100999component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001000 msg "build: non-accelerated EC algs"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001001
1002 config_psa_crypto_config_ecp_light_only 0
1003
1004 make
1005
1006 msg "test suites: full with non-accelerated EC algs"
1007 make test
1008
1009 msg "ssl-opt: full with non-accelerated EC algs"
1010 tests/ssl-opt.sh
1011}
1012
1013# This helper function is used by:
1014# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
1015# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
1016# to ensure that both tests use the same underlying configuration when testing
1017# driver's coverage with analyze_outcomes.py.
1018#
1019# This functions accepts 1 boolean parameter as follows:
1020# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
1021# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
1022# - 0: include built-in implementation of EC algorithms.
1023#
1024# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
1025# on the ECP module.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001026config_psa_crypto_no_ecp_at_all () {
1027 driver_only="$1"
1028 # start with full config for maximum coverage (also enables USE_PSA)
1029 helper_libtestdriver1_adjust_config "full"
1030
1031 if [ "$driver_only" -eq 1 ]; then
1032 # Disable modules that are accelerated
1033 scripts/config.py unset MBEDTLS_ECDSA_C
1034 scripts/config.py unset MBEDTLS_ECDH_C
1035 scripts/config.py unset MBEDTLS_ECJPAKE_C
1036 # Disable ECP module (entirely)
1037 scripts/config.py unset MBEDTLS_ECP_C
1038 fi
1039
1040 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1041 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1042 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1043 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1044
1045 # Restartable feature is not yet supported by PSA. Once it will in
1046 # the future, the following line could be removed (see issues
1047 # 6061, 6332 and following ones)
1048 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1049}
1050
1051# Build and test a configuration where driver accelerates all EC algs while
1052# all support and dependencies from ECP and ECP_LIGHT are removed on the library
1053# side.
1054#
1055# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001056component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
1057 msg "build: full + accelerated EC algs - ECP"
1058
1059 # Algorithms and key types to accelerate
1060 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1061 ALG_ECDH \
1062 ALG_JPAKE \
1063 $(helper_get_psa_key_type_list "ECC") \
1064 $(helper_get_psa_curve_list)"
1065
1066 # Configure
1067 # ---------
1068
1069 # Set common configurations between library's and driver's builds
1070 config_psa_crypto_no_ecp_at_all 1
1071 # Disable all the builtin curves. All the required algs are accelerated.
1072 helper_disable_builtin_curves
1073
1074 # Build
1075 # -----
1076
1077 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1078 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1079 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1080 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1081
1082 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1083
1084 helper_libtestdriver1_make_main "$loc_accel_list"
1085
1086 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1087 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1088 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1089 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1090 # Also ensure that ECP module was not re-enabled
1091 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1092
1093 # Run the tests
1094 # -------------
1095
1096 msg "test: full + accelerated EC algs - ECP"
1097 make test
1098
1099 msg "ssl-opt: full + accelerated EC algs - ECP"
1100 tests/ssl-opt.sh
1101}
1102
1103# Reference function used for driver's coverage analysis in analyze_outcomes.py
1104# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
1105# Keep in sync with its accelerated counterpart.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001106component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
1107 msg "build: full + non accelerated EC algs"
1108
1109 config_psa_crypto_no_ecp_at_all 0
1110
1111 make
1112
1113 msg "test: full + non accelerated EC algs"
1114 make test
1115
1116 msg "ssl-opt: full + non accelerated EC algs"
1117 tests/ssl-opt.sh
1118}
1119
1120# This is a common configuration helper used directly from:
1121# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1122# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1123# and indirectly from:
1124# - component_test_psa_crypto_config_accel_ecc_no_bignum
1125# - accelerate all EC algs, disable RSA and FFDH
1126# - component_test_psa_crypto_config_reference_ecc_no_bignum
1127# - this is the reference component of the above
1128# - it still disables RSA and FFDH, but it uses builtin EC algs
1129# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1130# - accelerate all EC and FFDH algs, disable only RSA
1131# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1132# - this is the reference component of the above
1133# - it still disables RSA, but it uses builtin EC and FFDH algs
1134#
1135# This function accepts 2 parameters:
1136# $1: a boolean value which states if we are testing an accelerated scenario
1137# or not.
1138# $2: a string value which states which components are tested. Allowed values
1139# are "ECC" or "ECC_DH".
Minos Galanakisf78447f2024-07-26 20:49:51 +01001140config_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001141 driver_only="$1"
1142 test_target="$2"
1143 # start with full config for maximum coverage (also enables USE_PSA)
1144 helper_libtestdriver1_adjust_config "full"
1145
1146 if [ "$driver_only" -eq 1 ]; then
1147 # Disable modules that are accelerated
1148 scripts/config.py unset MBEDTLS_ECDSA_C
1149 scripts/config.py unset MBEDTLS_ECDH_C
1150 scripts/config.py unset MBEDTLS_ECJPAKE_C
1151 # Disable ECP module (entirely)
1152 scripts/config.py unset MBEDTLS_ECP_C
1153 # Also disable bignum
1154 scripts/config.py unset MBEDTLS_BIGNUM_C
1155 fi
1156
1157 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1158 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1159 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1160 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1161
1162 # RSA support is intentionally disabled on this test because RSA_C depends
1163 # on BIGNUM_C.
1164 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
1165 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
1166 scripts/config.py unset MBEDTLS_RSA_C
1167 scripts/config.py unset MBEDTLS_PKCS1_V15
1168 scripts/config.py unset MBEDTLS_PKCS1_V21
1169 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1170 # Also disable key exchanges that depend on RSA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001171 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001172 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1173 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1174
1175 if [ "$test_target" = "ECC" ]; then
1176 # When testing ECC only, we disable FFDH support, both from builtin and
Valerio Setti8438c632025-01-22 11:56:40 +01001177 # PSA sides.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001178 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_FFDH
1179 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
1180 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
1181 scripts/config.py unset MBEDTLS_DHM_C
Minos Galanakis471b34c2024-07-26 15:39:24 +01001182 else
Valerio Setti8438c632025-01-22 11:56:40 +01001183 # When testing ECC and DH instead, we disable DHM.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001184 if [ "$driver_only" -eq 1 ]; then
1185 scripts/config.py unset MBEDTLS_DHM_C
Minos Galanakis471b34c2024-07-26 15:39:24 +01001186 fi
1187 fi
1188
1189 # Restartable feature is not yet supported by PSA. Once it will in
1190 # the future, the following line could be removed (see issues
1191 # 6061, 6332 and following ones)
1192 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1193}
1194
1195# Common helper used by:
1196# - component_test_psa_crypto_config_accel_ecc_no_bignum
1197# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1198#
1199# The goal is to build and test accelerating either:
1200# - ECC only or
1201# - both ECC and FFDH
1202#
1203# It is meant to be used in conjunction with
1204# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
1205# coverage analysis in the "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001206common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1207 test_target="$1"
1208
1209 # This is an internal helper to simplify text message handling
1210 if [ "$test_target" = "ECC_DH" ]; then
1211 accel_text="ECC/FFDH"
1212 removed_text="ECP - DH"
1213 else
1214 accel_text="ECC"
1215 removed_text="ECP"
1216 fi
1217
1218 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1219
1220 # By default we accelerate all EC keys/algs
1221 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1222 ALG_ECDH \
1223 ALG_JPAKE \
1224 $(helper_get_psa_key_type_list "ECC") \
1225 $(helper_get_psa_curve_list)"
1226 # Optionally we can also add DH to the list of accelerated items
1227 if [ "$test_target" = "ECC_DH" ]; then
1228 loc_accel_list="$loc_accel_list \
1229 ALG_FFDH \
1230 $(helper_get_psa_key_type_list "DH") \
1231 $(helper_get_psa_dh_group_list)"
1232 fi
1233
1234 # Configure
1235 # ---------
1236
1237 # Set common configurations between library's and driver's builds
1238 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
1239 # Disable all the builtin curves. All the required algs are accelerated.
1240 helper_disable_builtin_curves
1241
1242 # Build
1243 # -----
1244
1245 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1246 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1247 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1248 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1249
1250 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1251
1252 helper_libtestdriver1_make_main "$loc_accel_list"
1253
1254 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1255 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1256 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1257 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1258 # Also ensure that ECP, RSA, [DHM] or BIGNUM modules were not re-enabled
1259 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1260 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1261 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1262 not grep mbedtls_dhm_ ${BUILTIN_SRC_PATH}/dhm.o
1263
1264 # Run the tests
1265 # -------------
1266
1267 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - DHM - BIGNUM"
1268
1269 make test
1270
1271 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1272 tests/ssl-opt.sh
1273}
1274
1275# Common helper used by:
1276# - component_test_psa_crypto_config_reference_ecc_no_bignum
1277# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1278#
1279# The goal is to build and test a reference scenario (i.e. with builtin
1280# components) compared to the ones used in
1281# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
1282#
1283# It is meant to be used in conjunction with
1284# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
1285# coverage analysis in "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001286common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1287 test_target="$1"
1288
1289 # This is an internal helper to simplify text message handling
1290 if [ "$test_target" = "ECC_DH" ]; then
1291 accel_text="ECC/FFDH"
1292 else
1293 accel_text="ECC"
1294 fi
1295
1296 msg "build: full + non accelerated $accel_text algs + USE_PSA"
1297
1298 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
1299
1300 make
1301
1302 msg "test suites: full + non accelerated EC algs + USE_PSA"
1303 make test
1304
1305 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
1306 tests/ssl-opt.sh
1307}
1308
1309component_test_psa_crypto_config_accel_ecc_no_bignum () {
1310 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
1311}
1312
1313component_test_psa_crypto_config_reference_ecc_no_bignum () {
1314 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
1315}
1316
1317component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1318 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
1319}
1320
1321component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1322 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
1323}
1324
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001325component_test_tfm_config_as_is () {
1326 msg "build: configs/config-tfm.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +00001327 MBEDTLS_CONFIG="configs/config-tfm.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001328 CRYPTO_CONFIG="tf-psa-crypto/configs/ext/crypto_config_profile_medium.h"
Minos Galanakis4f619e12024-11-14 14:56:47 +00001329 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 +02001330 make
1331
1332 msg "test: configs/config-tfm.h - unit tests"
1333 make test
1334}
1335
Minos Galanakis471b34c2024-07-26 15:39:24 +01001336# Helper for setting common configurations between:
1337# - component_test_tfm_config_p256m_driver_accel_ec()
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001338# - component_test_tfm_config_no_p256m()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001339common_tfm_config () {
1340 # Enable TF-M config
1341 cp configs/config-tfm.h "$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001342 cp tf-psa-crypto/configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001343
Minos Galanakis471b34c2024-07-26 15:39:24 +01001344 # Config adjustment for better test coverage in our environment.
1345 # This is not needed just to build and pass tests.
1346 #
1347 # Enable filesystem I/O for the benefit of PK parse/write tests.
Minos Galanakis5da58e52024-11-07 15:35:33 +00001348 sed -i '/PROFILE_M_PSA_CRYPTO_CONFIG_H/i #define MBEDTLS_FS_IO' "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001349}
1350
1351# Keep this in sync with component_test_tfm_config() as they are both meant
1352# to be used in analyze_outcomes.py for driver's coverage analysis.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001353component_test_tfm_config_p256m_driver_accel_ec () {
1354 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1355
1356 common_tfm_config
1357
1358 # Build crypto library
David Horstmann5b93d972024-10-31 15:36:05 +00001359 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../framework/tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001360
1361 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1362 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1363 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1364 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1365 # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
1366 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1367 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1368 not grep mbedtls_dhm_ ${BUILTIN_SRC_PATH}/dhm.o
1369 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1370 # Check that p256m was built
1371 grep -q p256_ecdsa_ library/libmbedcrypto.a
1372
1373 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1374 # files, so we want to ensure that it has not be re-enabled accidentally.
1375 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1376
1377 # Run the tests
1378 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1379 make test
1380}
1381
1382# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1383# they are both meant to be used in analyze_outcomes.py for driver's coverage
1384# analysis.
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001385component_test_tfm_config_no_p256m () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001386 common_tfm_config
1387
1388 # Disable P256M driver, which is on by default, so that analyze_outcomes
1389 # can compare this test with test_tfm_config_p256m_driver_accel_ec
Minos Galanakis5da58e52024-11-07 15:35:33 +00001390 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 +01001391
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001392 msg "build: TF-M config without p256m"
David Horstmann5b93d972024-10-31 15:36:05 +00001393 make CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' tests
Minos Galanakis471b34c2024-07-26 15:39:24 +01001394
1395 # Check that p256m was not built
1396 not grep p256_ecdsa_ library/libmbedcrypto.a
1397
1398 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1399 # files, so we want to ensure that it has not be re-enabled accidentally.
1400 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1401
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001402 msg "test: TF-M config without p256m"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001403 make test
1404}
1405
Minos Galanakis471b34c2024-07-26 15:39:24 +01001406# This is an helper used by:
1407# - component_test_psa_ecc_key_pair_no_derive
1408# - component_test_psa_ecc_key_pair_no_generate
1409# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1410# enabled, but one. Input arguments are as follows:
Gilles Peskinefef912c2024-09-20 16:07:09 +02001411# - $1 is the configuration to start from
1412# - $2 is the key type under test, i.e. ECC/RSA/DH
1413# - $3 is the key option to be unset (i.e. generate, derive, etc)
Minos Galanakisf78447f2024-07-26 20:49:51 +01001414build_and_test_psa_want_key_pair_partial () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001415 base_config=$1
1416 key_type=$2
1417 unset_option=$3
Minos Galanakis471b34c2024-07-26 15:39:24 +01001418 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1419
Gilles Peskinefef912c2024-09-20 16:07:09 +02001420 msg "build: $base_config - ${disabled_psa_want}"
1421 scripts/config.py "$base_config"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001422
1423 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1424 # crypto_config.h so we just disable the one we don't want.
1425 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
1426
1427 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1428
Gilles Peskinefef912c2024-09-20 16:07:09 +02001429 msg "test: $base_config - ${disabled_psa_want}"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001430 make test
1431}
1432
Minos Galanakisf78447f2024-07-26 20:49:51 +01001433component_test_psa_ecc_key_pair_no_derive () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001434 build_and_test_psa_want_key_pair_partial full "ECC" "DERIVE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001435}
1436
Minos Galanakisf78447f2024-07-26 20:49:51 +01001437component_test_psa_ecc_key_pair_no_generate () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001438 # TLS needs ECC key generation whenever ephemeral ECDH is enabled.
1439 # We don't have proper guards for configurations with ECC key generation
1440 # disabled (https://github.com/Mbed-TLS/mbedtls/issues/9481). Until
1441 # then (if ever), just test the crypto part of the library.
1442 build_and_test_psa_want_key_pair_partial crypto_full "ECC" "GENERATE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001443}
1444
1445config_psa_crypto_accel_rsa () {
1446 driver_only=$1
1447
1448 # Start from crypto_full config (no X.509, no TLS)
1449 helper_libtestdriver1_adjust_config "crypto_full"
1450
1451 if [ "$driver_only" -eq 1 ]; then
1452 # Remove RSA support and its dependencies
1453 scripts/config.py unset MBEDTLS_RSA_C
1454 scripts/config.py unset MBEDTLS_PKCS1_V15
1455 scripts/config.py unset MBEDTLS_PKCS1_V21
1456
1457 # We need PEM parsing in the test library as well to support the import
1458 # of PEM encoded RSA keys.
Minos Galanakis23452f52024-11-28 17:48:14 +00001459 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1460 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
Minos Galanakis471b34c2024-07-26 15:39:24 +01001461 fi
1462}
1463
1464component_test_psa_crypto_config_accel_rsa_crypto () {
1465 msg "build: crypto_full with accelerated RSA"
1466
1467 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1468 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1469 KEY_TYPE_RSA_PUBLIC_KEY \
1470 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1471 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1472 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1473 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1474
1475 # Configure
1476 # ---------
1477
1478 config_psa_crypto_accel_rsa 1
1479
1480 # Build
1481 # -----
1482
1483 # These hashes are needed for unit tests.
1484 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1485 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1486 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1487
1488 helper_libtestdriver1_make_main "$loc_accel_list"
1489
1490 # Make sure this was not re-enabled by accident (additive config)
1491 not grep mbedtls_rsa ${BUILTIN_SRC_PATH}/rsa.o
1492
1493 # Run the tests
1494 # -------------
1495
1496 msg "test: crypto_full with accelerated RSA"
1497 make test
1498}
1499
1500component_test_psa_crypto_config_reference_rsa_crypto () {
1501 msg "build: crypto_full with non-accelerated RSA"
1502
1503 # Configure
1504 # ---------
1505 config_psa_crypto_accel_rsa 0
1506
1507 # Build
1508 # -----
1509 make
1510
1511 # Run the tests
1512 # -------------
1513 msg "test: crypto_full with non-accelerated RSA"
1514 make test
1515}
1516
1517# This is a temporary test to verify that full RSA support is present even when
1518# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001519component_test_new_psa_want_key_pair_symbol () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001520 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1521
1522 # Create a temporary output file unless there is already one set
1523 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1524 REMOVE_OUTCOME_ON_EXIT="no"
1525 else
1526 REMOVE_OUTCOME_ON_EXIT="yes"
1527 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1528 export MBEDTLS_TEST_OUTCOME_FILE
1529 fi
1530
1531 # Start from crypto configuration
1532 scripts/config.py crypto
1533
1534 # Remove RSA support and its dependencies
1535 scripts/config.py unset MBEDTLS_PKCS1_V15
1536 scripts/config.py unset MBEDTLS_PKCS1_V21
Minos Galanakis471b34c2024-07-26 15:39:24 +01001537 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1538 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001539 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1540 scripts/config.py unset MBEDTLS_RSA_C
1541 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1542
Minos Galanakis471b34c2024-07-26 15:39:24 +01001543 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
1544 # that proper translations is done in crypto_legacy.h.
1545 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
1546 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
1547 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
1548
1549 make
1550
1551 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1552 make test
1553
1554 # Parse only 1 relevant line from the outcome file, i.e. a test which is
1555 # performing RSA signature.
1556 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
1557 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
1558
1559 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
1560 rm $MBEDTLS_TEST_OUTCOME_FILE
1561 fi
1562}
1563
1564component_test_psa_crypto_config_accel_hash () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001565 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001566
1567 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1568 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1569 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1570
1571 # Configure
1572 # ---------
1573
1574 # Start from default config (no USE_PSA)
1575 helper_libtestdriver1_adjust_config "default"
1576
1577 # Disable the things that are being accelerated
1578 scripts/config.py unset MBEDTLS_MD5_C
1579 scripts/config.py unset MBEDTLS_RIPEMD160_C
1580 scripts/config.py unset MBEDTLS_SHA1_C
1581 scripts/config.py unset MBEDTLS_SHA224_C
1582 scripts/config.py unset MBEDTLS_SHA256_C
1583 scripts/config.py unset MBEDTLS_SHA384_C
1584 scripts/config.py unset MBEDTLS_SHA512_C
1585 scripts/config.py unset MBEDTLS_SHA3_C
1586
1587 # Build
1588 # -----
1589
1590 helper_libtestdriver1_make_drivers "$loc_accel_list"
1591
1592 helper_libtestdriver1_make_main "$loc_accel_list"
1593
1594 # There's a risk of something getting re-enabled via config_psa.h;
1595 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1596 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1597 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1598 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1599 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1600 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1601
1602 # Run the tests
1603 # -------------
1604
Ronald Cron93ba6252024-09-05 10:37:14 +02001605 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001606 make test
1607}
1608
1609# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001610config_psa_crypto_hash_use_psa () {
1611 driver_only="$1"
1612 # start with config full for maximum coverage (also enables USE_PSA)
1613 helper_libtestdriver1_adjust_config "full"
1614 if [ "$driver_only" -eq 1 ]; then
1615 # disable the built-in implementation of hashes
1616 scripts/config.py unset MBEDTLS_MD5_C
1617 scripts/config.py unset MBEDTLS_RIPEMD160_C
1618 scripts/config.py unset MBEDTLS_SHA1_C
1619 scripts/config.py unset MBEDTLS_SHA224_C
1620 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
1621 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
1622 scripts/config.py unset MBEDTLS_SHA384_C
1623 scripts/config.py unset MBEDTLS_SHA512_C
1624 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
1625 scripts/config.py unset MBEDTLS_SHA3_C
1626 fi
1627}
1628
1629# Note that component_test_psa_crypto_config_reference_hash_use_psa
1630# is related to this component and both components need to be kept in sync.
1631# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001632component_test_psa_crypto_config_accel_hash_use_psa () {
1633 msg "test: full with accelerated hashes"
1634
1635 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1636 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1637 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1638
1639 # Configure
1640 # ---------
1641
1642 config_psa_crypto_hash_use_psa 1
1643
1644 # Build
1645 # -----
1646
1647 helper_libtestdriver1_make_drivers "$loc_accel_list"
1648
1649 helper_libtestdriver1_make_main "$loc_accel_list"
1650
1651 # There's a risk of something getting re-enabled via config_psa.h;
1652 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1653 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1654 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1655 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1656 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1657 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1658
1659 # Run the tests
1660 # -------------
1661
1662 msg "test: full with accelerated hashes"
1663 make test
1664
1665 # This is mostly useful so that we can later compare outcome files with
1666 # the reference config in analyze_outcomes.py, to check that the
1667 # dependency declarations in ssl-opt.sh and in TLS code are correct.
1668 msg "test: ssl-opt.sh, full with accelerated hashes"
1669 tests/ssl-opt.sh
1670
1671 # This is to make sure all ciphersuites are exercised, but we don't need
1672 # interop testing (besides, we already got some from ssl-opt.sh).
1673 msg "test: compat.sh, full with accelerated hashes"
1674 tests/compat.sh -p mbedTLS -V YES
1675}
1676
1677# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
1678# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
1679# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
1680# Both components need to be kept in sync.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001681component_test_psa_crypto_config_reference_hash_use_psa () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001682 msg "test: full without accelerated hashes"
1683
1684 config_psa_crypto_hash_use_psa 0
1685
1686 make
1687
1688 msg "test: full without accelerated hashes"
1689 make test
1690
1691 msg "test: ssl-opt.sh, full without accelerated hashes"
1692 tests/ssl-opt.sh
1693}
1694
1695# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001696config_psa_crypto_hmac_use_psa () {
1697 driver_only="$1"
1698 # start with config full for maximum coverage (also enables USE_PSA)
1699 helper_libtestdriver1_adjust_config "full"
1700
1701 if [ "$driver_only" -eq 1 ]; then
1702 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
1703 # is still enabled though (for ENTROPY_C among others).
1704 scripts/config.py unset MBEDTLS_MD_C
1705 # Disable also the builtin hashes since they are supported by the driver
1706 # and MD module is able to perform PSA dispathing.
1707 scripts/config.py unset-all MBEDTLS_SHA
1708 scripts/config.py unset MBEDTLS_MD5_C
1709 scripts/config.py unset MBEDTLS_RIPEMD160_C
1710 fi
1711
1712 # Direct dependencies of MD_C. We disable them also in the reference
1713 # component to work with the same set of features.
1714 scripts/config.py unset MBEDTLS_PKCS7_C
1715 scripts/config.py unset MBEDTLS_PKCS5_C
1716 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1717 scripts/config.py unset MBEDTLS_HKDF_C
1718 # Dependencies of HMAC_DRBG
1719 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
1720 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
1721}
1722
Minos Galanakisf78447f2024-07-26 20:49:51 +01001723component_test_psa_crypto_config_accel_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001724 msg "test: full with accelerated hmac"
1725
1726 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
1727 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1728 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1729 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1730
1731 # Configure
1732 # ---------
1733
1734 config_psa_crypto_hmac_use_psa 1
1735
1736 # Build
1737 # -----
1738
1739 helper_libtestdriver1_make_drivers "$loc_accel_list"
1740
1741 helper_libtestdriver1_make_main "$loc_accel_list"
1742
1743 # Ensure that built-in support for HMAC is disabled.
1744 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
1745
1746 # Run the tests
1747 # -------------
1748
1749 msg "test: full with accelerated hmac"
1750 make test
1751}
1752
Minos Galanakisf78447f2024-07-26 20:49:51 +01001753component_test_psa_crypto_config_reference_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001754 msg "test: full without accelerated hmac"
1755
1756 config_psa_crypto_hmac_use_psa 0
1757
1758 make
1759
1760 msg "test: full without accelerated hmac"
1761 make test
1762}
1763
1764component_test_psa_crypto_config_accel_des () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001765 msg "test: accelerated DES"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001766
1767 # Albeit this components aims at accelerating DES which should only support
1768 # CBC and ECB modes, we need to accelerate more than that otherwise DES_C
1769 # would automatically be re-enabled by "config_adjust_legacy_from_psa.c"
1770 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 \
1771 ALG_CTR ALG_CFB ALG_OFB ALG_XTS ALG_CMAC \
1772 KEY_TYPE_DES"
1773
1774 # Note: we cannot accelerate all ciphers' key types otherwise we would also
1775 # have to either disable CCM/GCM or accelerate them, but that's out of scope
1776 # of this component. This limitation will be addressed by #8598.
1777
1778 # Configure
1779 # ---------
1780
1781 # Start from the full config
1782 helper_libtestdriver1_adjust_config "full"
1783
1784 # Disable the things that are being accelerated
1785 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1786 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
1787 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
1788 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
1789 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
1790 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
1791 scripts/config.py unset MBEDTLS_DES_C
1792 scripts/config.py unset MBEDTLS_CMAC_C
1793
1794 # Build
1795 # -----
1796
1797 helper_libtestdriver1_make_drivers "$loc_accel_list"
1798
1799 helper_libtestdriver1_make_main "$loc_accel_list"
1800
1801 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine29e86ca2024-06-19 15:09:27 +02001802 not grep mbedtls_des ${BUILTIN_SRC_PATH}/des.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001803
1804 # Run the tests
1805 # -------------
1806
Ronald Cron93ba6252024-09-05 10:37:14 +02001807 msg "test: accelerated DES"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001808 make test
1809}
1810
1811component_test_psa_crypto_config_accel_aead () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001812 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001813
1814 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
1815 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1816
1817 # Configure
1818 # ---------
1819
1820 # Start from full config
1821 helper_libtestdriver1_adjust_config "full"
1822
1823 # Disable things that are being accelerated
1824 scripts/config.py unset MBEDTLS_GCM_C
1825 scripts/config.py unset MBEDTLS_CCM_C
1826 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1827
1828 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
1829 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1830
1831 # Build
1832 # -----
1833
1834 helper_libtestdriver1_make_drivers "$loc_accel_list"
1835
1836 helper_libtestdriver1_make_main "$loc_accel_list"
1837
1838 # Make sure this was not re-enabled by accident (additive config)
1839 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1840 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1841 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1842
1843 # Run the tests
1844 # -------------
1845
Ronald Cron93ba6252024-09-05 10:37:14 +02001846 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001847 make test
1848}
1849
1850# This is a common configuration function used in:
1851# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1852# - component_test_psa_crypto_config_reference_cipher_aead_cmac
Minos Galanakisf78447f2024-07-26 20:49:51 +01001853common_psa_crypto_config_accel_cipher_aead_cmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001854 # Start from the full config
1855 helper_libtestdriver1_adjust_config "full"
1856
1857 scripts/config.py unset MBEDTLS_NIST_KW_C
1858}
1859
1860# The 2 following test components, i.e.
1861# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1862# - component_test_psa_crypto_config_reference_cipher_aead_cmac
1863# are meant to be used together in analyze_outcomes.py script in order to test
1864# driver's coverage for ciphers and AEADs.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001865component_test_psa_crypto_config_accel_cipher_aead_cmac () {
1866 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
1867
1868 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
1869 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
1870 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
1871 KEY_TYPE_DES KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
1872
1873 # Configure
1874 # ---------
1875
1876 common_psa_crypto_config_accel_cipher_aead_cmac
1877
1878 # Disable the things that are being accelerated
1879 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1880 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
1881 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
1882 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
1883 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
1884 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
1885 scripts/config.py unset MBEDTLS_GCM_C
1886 scripts/config.py unset MBEDTLS_CCM_C
1887 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1888 scripts/config.py unset MBEDTLS_CMAC_C
1889 scripts/config.py unset MBEDTLS_DES_C
1890 scripts/config.py unset MBEDTLS_AES_C
1891 scripts/config.py unset MBEDTLS_ARIA_C
1892 scripts/config.py unset MBEDTLS_CHACHA20_C
1893 scripts/config.py unset MBEDTLS_CAMELLIA_C
1894
1895 # Disable CIPHER_C entirely as all ciphers/AEADs are accelerated and PSA
1896 # does not depend on it.
1897 scripts/config.py unset MBEDTLS_CIPHER_C
1898
1899 # Build
1900 # -----
1901
1902 helper_libtestdriver1_make_drivers "$loc_accel_list"
1903
1904 helper_libtestdriver1_make_main "$loc_accel_list"
1905
1906 # Make sure this was not re-enabled by accident (additive config)
1907 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1908 not grep mbedtls_des ${BUILTIN_SRC_PATH}/des.o
1909 not grep mbedtls_aes ${BUILTIN_SRC_PATH}/aes.o
1910 not grep mbedtls_aria ${BUILTIN_SRC_PATH}/aria.o
1911 not grep mbedtls_camellia ${BUILTIN_SRC_PATH}/camellia.o
1912 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1913 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1914 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1915 not grep mbedtls_cmac ${BUILTIN_SRC_PATH}/cmac.o
1916
1917 # Run the tests
1918 # -------------
1919
1920 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
1921 make test
1922
1923 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
1924 tests/ssl-opt.sh
1925
1926 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
1927 tests/compat.sh -V NO -p mbedTLS
1928}
1929
1930component_test_psa_crypto_config_reference_cipher_aead_cmac () {
1931 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
1932 common_psa_crypto_config_accel_cipher_aead_cmac
1933
1934 make
1935
1936 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
1937 make test
1938
1939 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
1940 tests/ssl-opt.sh
1941
1942 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
1943 tests/compat.sh -V NO -p mbedTLS
1944}
1945
Minos Galanakisf78447f2024-07-26 20:49:51 +01001946common_block_cipher_dispatch () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001947 TEST_WITH_DRIVER="$1"
1948
1949 # Start from the full config
1950 helper_libtestdriver1_adjust_config "full"
1951
1952 if [ "$TEST_WITH_DRIVER" -eq 1 ]; then
1953 # Disable key types that are accelerated (there is no legacy equivalent
1954 # symbol for ECB)
1955 scripts/config.py unset MBEDTLS_AES_C
1956 scripts/config.py unset MBEDTLS_ARIA_C
1957 scripts/config.py unset MBEDTLS_CAMELLIA_C
1958 fi
1959
1960 # Disable cipher's modes that, when not accelerated, cause
1961 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
1962 # Keep this also in the reference component in order to skip the same tests
1963 # that were skipped in the accelerated one.
1964 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
1965 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
1966 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
1967 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
1968 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
1969 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
1970 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1971 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
1972
1973 # Disable direct dependency on AES_C
1974 scripts/config.py unset MBEDTLS_NIST_KW_C
1975
1976 # Prevent the cipher module from using deprecated PSA path. The reason is
1977 # that otherwise there will be tests relying on "aes_info" (defined in
1978 # "cipher_wrap.c") whose functions are not available when AES_C is
1979 # not defined. ARIA and Camellia are not a problem in this case because
1980 # the PSA path is not tested for these key types.
1981 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1982}
1983
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02001984component_test_full_block_cipher_psa_dispatch_static_keystore () {
1985 msg "build: full + PSA dispatch in block_cipher with static keystore"
1986 # Check that the static key store works well when CTR_DRBG uses a
1987 # PSA key for AES.
1988 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
1989
1990 loc_accel_list="ALG_ECB_NO_PADDING \
1991 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1992
1993 # Configure
1994 # ---------
1995
1996 common_block_cipher_dispatch 1
1997
1998 # Build
1999 # -----
2000
2001 helper_libtestdriver1_make_drivers "$loc_accel_list"
2002
2003 helper_libtestdriver1_make_main "$loc_accel_list"
2004
2005 # Make sure disabled components were not re-enabled by accident (additive
2006 # config)
2007 not grep mbedtls_aes_ library/aes.o
2008 not grep mbedtls_aria_ library/aria.o
2009 not grep mbedtls_camellia_ library/camellia.o
2010
2011 # Run the tests
2012 # -------------
2013
2014 msg "test: full + PSA dispatch in block_cipher with static keystore"
2015 make test
2016}
2017
Minos Galanakis471b34c2024-07-26 15:39:24 +01002018component_test_full_block_cipher_psa_dispatch () {
2019 msg "build: full + PSA dispatch in block_cipher"
2020
2021 loc_accel_list="ALG_ECB_NO_PADDING \
2022 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2023
2024 # Configure
2025 # ---------
2026
2027 common_block_cipher_dispatch 1
2028
2029 # Build
2030 # -----
2031
2032 helper_libtestdriver1_make_drivers "$loc_accel_list"
2033
2034 helper_libtestdriver1_make_main "$loc_accel_list"
2035
2036 # Make sure disabled components were not re-enabled by accident (additive
2037 # config)
2038 not grep mbedtls_aes_ ${BUILTIN_SRC_PATH}/aes.o
2039 not grep mbedtls_aria_ ${BUILTIN_SRC_PATH}/aria.o
2040 not grep mbedtls_camellia_ ${BUILTIN_SRC_PATH}/camellia.o
2041
2042 # Run the tests
2043 # -------------
2044
2045 msg "test: full + PSA dispatch in block_cipher"
2046 make test
2047}
2048
2049# This is the reference component of component_test_full_block_cipher_psa_dispatch
Minos Galanakis471b34c2024-07-26 15:39:24 +01002050component_test_full_block_cipher_legacy_dispatch () {
2051 msg "build: full + legacy dispatch in block_cipher"
2052
2053 common_block_cipher_dispatch 0
2054
2055 make
2056
2057 msg "test: full + legacy dispatch in block_cipher"
2058 make test
2059}
2060
Minos Galanakisf78447f2024-07-26 20:49:51 +01002061component_test_aead_chachapoly_disabled () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002062 msg "build: full minus CHACHAPOLY"
2063 scripts/config.py full
2064 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2065 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2066 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2067
2068 msg "test: full minus CHACHAPOLY"
2069 make test
2070}
2071
Minos Galanakisf78447f2024-07-26 20:49:51 +01002072component_test_aead_only_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002073 msg "build: full minus CHACHAPOLY and GCM"
2074 scripts/config.py full
2075 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2076 scripts/config.py unset MBEDTLS_GCM_C
2077 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2078 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2079 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2080
2081 msg "test: full minus CHACHAPOLY and GCM"
2082 make test
2083}
2084
Minos Galanakisf78447f2024-07-26 20:49:51 +01002085component_test_ccm_aes_sha256 () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002086 msg "build: CCM + AES + SHA256 configuration"
2087
Minos Galanakisa17ffc72024-12-02 23:57:30 +00002088 # Setting a blank config disables everyhing in the library side.
2089 echo '#define MBEDTLS_CONFIG_H ' >"$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00002090 cp tf-psa-crypto/configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
Ronald Cron9d262d72024-12-06 17:41:26 +01002091
Minos Galanakis471b34c2024-07-26 15:39:24 +01002092 make
Minos Galanakis471b34c2024-07-26 15:39:24 +01002093 msg "test: CCM + AES + SHA256 configuration"
2094 make test
2095}
2096
2097# Test that the given .o file builds with all (valid) combinations of the given options.
2098#
2099# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
2100#
2101# The validator function is the name of a function to validate the combination of options.
2102# It may be "" if all combinations are valid.
2103# It receives a string containing a combination of options, as passed to the compiler,
2104# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Minos Galanakisf78447f2024-07-26 20:49:51 +01002105build_test_config_combos () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002106 file=$1
2107 shift
2108 validate_options=$1
2109 shift
2110 options=("$@")
2111
2112 # clear all of the options so that they can be overridden on the clang commandline
2113 for opt in "${options[@]}"; do
2114 ./scripts/config.py unset ${opt}
2115 done
2116
2117 # enter the library directory
2118 cd library
2119
2120 # The most common issue is unused variables/functions, so ensure -Wunused is set.
2121 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
2122
2123 # Extract the command generated by the Makefile to build the target file.
2124 # This ensures that we have any include paths, macro definitions, etc
2125 # that may be applied by make.
2126 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
2127 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
2128
2129 makefile=$(TMPDIR=. mktemp)
2130 deps=""
2131
2132 len=${#options[@]}
2133 source_file=../${file%.o}.c
2134
2135 targets=0
2136 echo 'include Makefile' >${makefile}
2137
2138 for ((i = 0; i < $((2**${len})); i++)); do
2139 # generate each of 2^n combinations of options
2140 # each bit of $i is used to determine if options[i] will be set or not
2141 target="t"
2142 clang_args=""
2143 for ((j = 0; j < ${len}; j++)); do
2144 if (((i >> j) & 1)); then
2145 opt=-D${options[$j]}
2146 clang_args="${clang_args} ${opt}"
2147 target="${target}${opt}"
2148 fi
2149 done
2150
2151 # if combination is not known to be invalid, add it to the makefile
2152 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
2153 cmd="${compile_cmd} ${clang_args}"
2154 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
2155
2156 deps="${deps} ${target}"
2157 ((++targets))
2158 fi
2159 done
2160
2161 echo "build_test_config_combos: ${deps}" >> ${makefile}
2162
2163 # execute all of the commands via Make (probably in parallel)
2164 make -s -f ${makefile} build_test_config_combos
2165 echo "$targets targets checked"
2166
2167 # clean up the temporary makefile
2168 rm ${makefile}
2169}
2170
Minos Galanakisf78447f2024-07-26 20:49:51 +01002171validate_aes_config_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002172 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
2173 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
2174 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
2175 return 1
2176 fi
2177 fi
2178 return 0
2179}
2180
Minos Galanakisf78447f2024-07-26 20:49:51 +01002181component_build_aes_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002182 # 18s - around 90ms per clang invocation on M1 Pro
2183 #
2184 # aes.o has many #if defined(...) guards that intersect in complex ways.
2185 # Test that all the combinations build cleanly.
2186
2187 MBEDTLS_ROOT_DIR="$PWD"
2188 msg "build: aes.o for all combinations of relevant config options"
2189
2190 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002191 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002192 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2193 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2194
2195 cd "$MBEDTLS_ROOT_DIR"
2196 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
2197
2198 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES,
2199 # manually set or unset those configurations to check
2200 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
2201 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Minos Galanakis471b34c2024-07-26 15:39:24 +01002202 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002203 scripts/config.py unset MBEDTLS_NIST_KW_C
Ronald Cron54d1eec2024-09-06 09:55:38 +02002204
Minos Galanakis00b641c2024-11-28 23:05:10 +00002205 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
2206 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
2207 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
2208 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
Ronald Cron4153ebb2024-09-11 15:32:48 +02002209 # Note: The two unsets below are to be removed for Mbed TLS 4.0
Ronald Cron54d1eec2024-09-06 09:55:38 +02002210 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2211 scripts/config.py unset MBEDTLS_DES_C
2212
Minos Galanakis471b34c2024-07-26 15:39:24 +01002213 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002214 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002215 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2216 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2217}
2218
Minos Galanakisf78447f2024-07-26 20:49:51 +01002219component_test_sha3_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002220 msg "sha3 loop unroll variations"
2221
2222 # define minimal config sufficient to test SHA3
Ronald Crone7f289e2024-09-06 11:02:47 +02002223 cat > include/mbedtls/mbedtls_config.h << END
Ronald Crone7f289e2024-09-06 11:02:47 +02002224END
2225
2226 cat > tf-psa-crypto/include/psa/crypto_config.h << END
2227 #define PSA_WANT_ALG_SHA_256 1
2228 #define PSA_WANT_ALG_SHA3_224 1
2229 #define PSA_WANT_ALG_SHA3_256 1
2230 #define PSA_WANT_ALG_SHA3_384 1
2231 #define PSA_WANT_ALG_SHA3_512 1
Ronald Cron3dd1d3d2024-12-05 15:12:06 +01002232 #define MBEDTLS_AES_C
2233 #define MBEDTLS_CTR_DRBG_C
2234 #define MBEDTLS_ENTROPY_C
2235 #define MBEDTLS_PSA_CRYPTO_C
2236 #define MBEDTLS_SELF_TEST
Minos Galanakis471b34c2024-07-26 15:39:24 +01002237END
2238
2239 msg "all loops unrolled"
2240 make clean
2241 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"
2242 ./tf-psa-crypto/tests/test_suite_shax
2243
2244 msg "all loops rolled up"
2245 make clean
2246 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"
2247 ./tf-psa-crypto/tests/test_suite_shax
2248}
2249
Minos Galanakisf699d512024-08-01 11:32:30 +01002250support_build_aes_aesce_armcc () {
2251 support_build_armcc
2252}
2253
Minos Galanakis471b34c2024-07-26 15:39:24 +01002254# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2255component_build_aes_aesce_armcc () {
2256 msg "Build: AESCE test on arm64 platform without plain C."
2257 scripts/config.py baremetal
2258
2259 # armc[56] don't support SHA-512 intrinsics
2260 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2261
2262 # Stop armclang warning about feature detection for A64_CRYPTO.
2263 # With this enabled, the library does build correctly under armclang,
2264 # but in baremetal builds (as tested here), feature detection is
2265 # unavailable, and the user is notified via a #warning. So enabling
2266 # this feature would prevent us from building with -Werror on
2267 # armclang. Tracked in #7198.
2268 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2269 scripts/config.py set MBEDTLS_HAVE_ASM
2270
2271 msg "AESCE, build with default configuration."
2272 scripts/config.py set MBEDTLS_AESCE_C
2273 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002274 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002275
2276 msg "AESCE, build AESCE only"
2277 scripts/config.py set MBEDTLS_AESCE_C
2278 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002279 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002280}
2281
Minos Galanakis471b34c2024-07-26 15:39:24 +01002282component_test_aes_only_128_bit_keys () {
2283 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2284 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2285
2286 make CFLAGS='-O2 -Werror -Wall -Wextra'
2287
2288 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2289 make test
2290}
2291
2292component_test_no_ctr_drbg_aes_only_128_bit_keys () {
2293 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2294 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2295 scripts/config.py unset MBEDTLS_CTR_DRBG_C
2296
2297 make CC=clang CFLAGS='-Werror -Wall -Wextra'
2298
2299 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2300 make test
2301}
2302
2303component_test_aes_only_128_bit_keys_have_builtins () {
2304 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2305 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2306 scripts/config.py unset MBEDTLS_AESNI_C
2307 scripts/config.py unset MBEDTLS_AESCE_C
2308
2309 make CFLAGS='-O2 -Werror -Wall -Wextra'
2310
2311 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2312 make test
2313
2314 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2315 programs/test/selftest
2316}
2317
2318component_test_gcm_largetable () {
2319 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2320 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
2321 scripts/config.py unset MBEDTLS_AESNI_C
2322 scripts/config.py unset MBEDTLS_AESCE_C
2323
2324 make CFLAGS='-O2 -Werror -Wall -Wextra'
2325
2326 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2327 make test
2328}
2329
2330component_test_aes_fewer_tables () {
2331 msg "build: default config with AES_FEWER_TABLES enabled"
2332 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2333 make CFLAGS='-O2 -Werror -Wall -Wextra'
2334
2335 msg "test: AES_FEWER_TABLES"
2336 make test
2337}
2338
2339component_test_aes_rom_tables () {
2340 msg "build: default config with AES_ROM_TABLES enabled"
2341 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2342 make CFLAGS='-O2 -Werror -Wall -Wextra'
2343
2344 msg "test: AES_ROM_TABLES"
2345 make test
2346}
2347
2348component_test_aes_fewer_tables_and_rom_tables () {
2349 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
2350 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2351 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2352 make CFLAGS='-O2 -Werror -Wall -Wextra'
2353
2354 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2355 make test
2356}
2357
Ronald Cron66040472024-09-06 10:14:38 +02002358# helper for component_test_block_cipher_no_decrypt_aesni() which:
Minos Galanakis471b34c2024-07-26 15:39:24 +01002359# - enable/disable the list of config options passed from -s/-u respectively.
2360# - build
2361# - test for tests_suite_xxx
2362# - selftest
2363#
2364# Usage: helper_block_cipher_no_decrypt_build_test
2365# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
2366# Options: -s set_opts the list of config options to enable
2367# -u unset_opts the list of config options to disable
2368# -c cflags the list of options passed to CFLAGS
2369# -l ldflags the list of options passed to LDFLAGS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002370helper_block_cipher_no_decrypt_build_test () {
2371 while [ $# -gt 0 ]; do
2372 case "$1" in
2373 -s)
2374 shift; local set_opts="$1";;
2375 -u)
2376 shift; local unset_opts="$1";;
2377 -c)
2378 shift; local cflags="-Werror -Wall -Wextra $1";;
2379 -l)
2380 shift; local ldflags="$1";;
2381 esac
2382 shift
2383 done
2384 set_opts="${set_opts:-}"
2385 unset_opts="${unset_opts:-}"
2386 cflags="${cflags:-}"
2387 ldflags="${ldflags:-}"
2388
2389 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
2390 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
2391
2392 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2393 make clean
2394 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
2395
2396 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2397 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2398 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2399 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2400 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2401 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2402 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
2403 not grep mbedtls_aesni_inverse_key ${BUILTIN_SRC_PATH}/aesni.o
2404
2405 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2406 make test
2407
2408 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2409 programs/test/selftest
2410}
2411
Ronald Cron66040472024-09-06 10:14:38 +02002412# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
2413config_block_cipher_no_decrypt () {
2414 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
2415 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2416 scripts/config.py unset MBEDTLS_NIST_KW_C
2417
2418 # Enable support for cryptographic mechanisms through the PSA API.
2419 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
Ronald Cron66040472024-09-06 10:14:38 +02002420 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
2421 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
2422 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
2423 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
Ronald Cron4153ebb2024-09-11 15:32:48 +02002424 # Note: The two unsets below are to be removed for Mbed TLS 4.0
Ronald Cron66040472024-09-06 10:14:38 +02002425 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2426 scripts/config.py unset MBEDTLS_DES_C
2427}
2428
2429component_test_block_cipher_no_decrypt_aesni () {
2430 # Test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics, AESNI assembly and
2431 # AES C implementation on x86_64 and with AESNI intrinsics on x86.
2432
2433 # This consistently causes an llvm crash on clang 3.8, so use gcc
2434 export CC=gcc
2435 config_block_cipher_no_decrypt
2436
Minos Galanakis471b34c2024-07-26 15:39:24 +01002437 # test AESNI intrinsics
2438 helper_block_cipher_no_decrypt_build_test \
2439 -s "MBEDTLS_AESNI_C" \
2440 -c "-mpclmul -msse2 -maes"
2441
2442 # test AESNI assembly
2443 helper_block_cipher_no_decrypt_build_test \
2444 -s "MBEDTLS_AESNI_C" \
2445 -c "-mno-pclmul -mno-sse2 -mno-aes"
2446
2447 # test AES C implementation
2448 helper_block_cipher_no_decrypt_build_test \
2449 -u "MBEDTLS_AESNI_C"
2450
2451 # test AESNI intrinsics for i386 target
2452 helper_block_cipher_no_decrypt_build_test \
2453 -s "MBEDTLS_AESNI_C" \
2454 -c "-m32 -mpclmul -msse2 -maes" \
2455 -l "-m32"
2456}
2457
Minos Galanakisf699d512024-08-01 11:32:30 +01002458support_test_block_cipher_no_decrypt_aesce_armcc () {
2459 support_build_armcc
2460}
2461
Minos Galanakis471b34c2024-07-26 15:39:24 +01002462component_test_block_cipher_no_decrypt_aesce_armcc () {
2463 scripts/config.py baremetal
2464
2465 # armc[56] don't support SHA-512 intrinsics
2466 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2467
2468 # Stop armclang warning about feature detection for A64_CRYPTO.
2469 # With this enabled, the library does build correctly under armclang,
2470 # but in baremetal builds (as tested here), feature detection is
2471 # unavailable, and the user is notified via a #warning. So enabling
2472 # this feature would prevent us from building with -Werror on
2473 # armclang. Tracked in #7198.
2474 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2475 scripts/config.py set MBEDTLS_HAVE_ASM
2476
Ronald Cron66040472024-09-06 10:14:38 +02002477 config_block_cipher_no_decrypt
Minos Galanakis471b34c2024-07-26 15:39:24 +01002478
2479 # test AESCE baremetal build
2480 scripts/config.py set MBEDTLS_AESCE_C
2481 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002482 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002483
2484 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2485 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2486 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2487 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2488 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2489 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2490 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
2491 not grep mbedtls_aesce_inverse_key ${BUILTIN_SRC_PATH}/aesce.o
2492 not grep aesce_decrypt_block ${BUILTIN_SRC_PATH}/aesce.o
2493}
2494
2495component_test_ctr_drbg_aes_256_sha_256 () {
2496 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2497 scripts/config.py full
2498 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2499 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
2500 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2501 make
2502
2503 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2504 make test
2505}
2506
2507component_test_ctr_drbg_aes_128_sha_512 () {
2508 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2509 scripts/config.py full
2510 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2511 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2512 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2513 make
2514
2515 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2516 make test
2517}
2518
2519component_test_ctr_drbg_aes_128_sha_256 () {
2520 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2521 scripts/config.py full
2522 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2523 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2524 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
2525 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2526 make
2527
2528 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2529 make test
2530}
2531
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002532component_test_full_static_keystore () {
2533 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2534 scripts/config.py full
2535 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2536 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
2537
2538 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2539 make test
2540}
2541
Minos Galanakis471b34c2024-07-26 15:39:24 +01002542component_test_psa_crypto_drivers () {
Ronald Crona0afbfb2024-10-15 13:20:31 +02002543 # Test dispatch to drivers and fallbacks with
2544 # test_suite_psa_crypto_driver_wrappers test suite. The test drivers that
2545 # are wrappers around the builtin drivers are activated by
2546 # PSA_CRYPTO_DRIVER_TEST.
2547 #
2548 # For the time being, some test cases in test_suite_block_cipher and
2549 # test_suite_md.psa rely on this component to be run at least once by the
2550 # CI. This should disappear as we progress the 4.x work. See
2551 # config_adjust_test_accelerators.h for more information.
Minos Galanakis471b34c2024-07-26 15:39:24 +01002552 msg "build: full + test drivers dispatching to builtins"
2553 scripts/config.py full
Ronald Cron67cc6a72024-10-14 10:55:24 +02002554 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_CONFIG_ADJUST_TEST_ACCELERATORS"
David Horstmann5b93d972024-10-31 15:36:05 +00002555 loc_cflags="${loc_cflags} -I../framework/tests/include"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002556
2557 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
2558
2559 msg "test: full + test drivers dispatching to builtins"
2560 make test
2561}
2562
2563component_build_psa_config_file () {
Minos Galanakis4f619e12024-11-14 14:56:47 +00002564 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002565 cp "$CRYPTO_CONFIG_H" psa_test_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002566 echo '#error "TF_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
2567 make CFLAGS="-I '$PWD' -DTF_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002568 # Make sure this feature is enabled. We'll disable it in the next phase.
2569 programs/test/query_compile_time_config MBEDTLS_CMAC_C
2570 make clean
2571
Minos Galanakis4f619e12024-11-14 14:56:47 +00002572 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE + TF_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002573 # In the user config, disable one feature and its dependencies, which will
2574 # reflect on the mbedtls configuration so we can query it with
2575 # query_compile_time_config.
2576 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
2577 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
Minos Galanakisaa2f12c2024-10-22 15:31:07 +01002578 echo '#undef MBEDTLS_CMAC_C' >> psa_user_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002579 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 +01002580 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
2581
2582 rm -f psa_test_config.h psa_user_config.h
2583}
2584
2585component_build_psa_alt_headers () {
2586 msg "build: make with PSA alt headers" # ~20s
2587
2588 # Generate alternative versions of the substitutable headers with the
2589 # same content except different include guards.
David Horstmanndc459512024-11-07 17:08:11 +00002590 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 +01002591
2592 # Build the library and some programs.
2593 # Don't build the fuzzers to avoid having to go through hoops to set
2594 # a correct include path for programs/fuzz/Makefile.
David Horstmann5b93d972024-10-31 15:36:05 +00002595 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
2596 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 +01002597
2598 # Check that we're getting the alternative include guards and not the
2599 # original include guards.
2600 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
2601 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
2602 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
2603 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
2604}
2605
2606component_test_min_mpi_window_size () {
2607 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
2608 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
2609 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2610 make
2611
2612 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2613 make test
2614}