blob: 8ba4161870e4df161948175f5b0de80100b4bccc [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
Minos Galanakis471b34c2024-07-26 15:39:24 +0100671 # Build
672 # -----
673
674 helper_libtestdriver1_make_drivers "$loc_accel_list"
675
676 helper_libtestdriver1_make_main "$loc_accel_list"
677
678 # Make sure this was not re-enabled by accident (additive config)
Valerio Settieb63eb22025-02-12 13:32:49 +0100679 not grep mbedtls_psa_ffdh_key_agreement ${BUILTIN_SRC_PATH}/psa_crypto_ffdh.o
Minos Galanakis471b34c2024-07-26 15:39:24 +0100680
681 # Run the tests
682 # -------------
683
684 msg "test: full with accelerated FFDH"
685 make test
686
687 msg "ssl-opt: full with accelerated FFDH alg"
688 tests/ssl-opt.sh -f "ffdh"
689}
690
691component_test_psa_crypto_config_reference_ffdh () {
692 msg "build: full with non-accelerated FFDH"
693
694 # Start with full (USE_PSA and TLS 1.3)
695 helper_libtestdriver1_adjust_config "full"
696
Minos Galanakis471b34c2024-07-26 15:39:24 +0100697 make
698
699 msg "test suites: full with non-accelerated FFDH alg"
700 make test
701
702 msg "ssl-opt: full with non-accelerated FFDH alg"
703 tests/ssl-opt.sh -f "ffdh"
704}
705
Minos Galanakisf78447f2024-07-26 20:49:51 +0100706component_test_psa_crypto_config_accel_pake () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100707 msg "build: full with accelerated PAKE"
708
709 loc_accel_list="ALG_JPAKE \
710 $(helper_get_psa_key_type_list "ECC") \
711 $(helper_get_psa_curve_list)"
712
713 # Configure
714 # ---------
715
716 helper_libtestdriver1_adjust_config "full"
717
718 # Make built-in fallback not available
719 scripts/config.py unset MBEDTLS_ECJPAKE_C
720 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
721
722 # Build
723 # -----
724
725 helper_libtestdriver1_make_drivers "$loc_accel_list"
726
727 helper_libtestdriver1_make_main "$loc_accel_list"
728
729 # Make sure this was not re-enabled by accident (additive config)
730 not grep mbedtls_ecjpake_init ${BUILTIN_SRC_PATH}/ecjpake.o
731
732 # Run the tests
733 # -------------
734
735 msg "test: full with accelerated PAKE"
736 make test
737}
738
739component_test_psa_crypto_config_accel_ecc_some_key_types () {
740 msg "build: full with accelerated EC algs and some key types"
741
742 # Algorithms and key types to accelerate
743 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
744 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
745 ALG_ECDH \
746 ALG_JPAKE \
747 KEY_TYPE_ECC_PUBLIC_KEY \
748 KEY_TYPE_ECC_KEY_PAIR_BASIC \
749 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
750 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
751 $(helper_get_psa_curve_list)"
752
753 # Configure
754 # ---------
755
756 # start with config full for maximum coverage (also enables USE_PSA)
757 helper_libtestdriver1_adjust_config "full"
758
759 # Disable modules that are accelerated - some will be re-enabled
760 scripts/config.py unset MBEDTLS_ECDSA_C
761 scripts/config.py unset MBEDTLS_ECDH_C
762 scripts/config.py unset MBEDTLS_ECJPAKE_C
763 scripts/config.py unset MBEDTLS_ECP_C
764
765 # Disable all curves - those that aren't accelerated should be re-enabled
766 helper_disable_builtin_curves
767
768 # Restartable feature is not yet supported by PSA. Once it will in
769 # the future, the following line could be removed (see issues
770 # 6061, 6332 and following ones)
771 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
772
773 # this is not supported by the driver API yet
774 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
775
776 # Build
777 # -----
778
779 # These hashes are needed for some ECDSA signature tests.
780 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
781 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
782 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
783
784 helper_libtestdriver1_make_main "$loc_accel_list"
785
786 # ECP should be re-enabled but not the others
787 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
788 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
789 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
790 grep mbedtls_ecp ${BUILTIN_SRC_PATH}/ecp.o
791
792 # Run the tests
793 # -------------
794
795 msg "test suites: full with accelerated EC algs and some key types"
796 make test
797}
798
799# Run tests with only (non-)Weierstrass accelerated
800# Common code used in:
801# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
802# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100803common_test_psa_crypto_config_accel_ecc_some_curves () {
804 weierstrass=$1
805 if [ $weierstrass -eq 1 ]; then
806 desc="Weierstrass"
807 else
808 desc="non-Weierstrass"
809 fi
810
811 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
812
813 # Note: Curves are handled in a special way by the libtestdriver machinery,
814 # so we only want to include them in the accel list when building the main
815 # libraries, hence the use of a separate variable.
816 # Note: the following loop is a modified version of
817 # helper_get_psa_curve_list that only keeps Weierstrass families.
818 loc_weierstrass_list=""
819 loc_non_weierstrass_list=""
820 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
821 case $item in
822 ECC_BRAINPOOL*|ECC_SECP*)
823 loc_weierstrass_list="$loc_weierstrass_list $item"
824 ;;
825 *)
826 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
827 ;;
828 esac
829 done
830 if [ $weierstrass -eq 1 ]; then
831 loc_curve_list=$loc_weierstrass_list
832 else
833 loc_curve_list=$loc_non_weierstrass_list
834 fi
835
836 # Algorithms and key types to accelerate
837 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
838 ALG_ECDH \
839 ALG_JPAKE \
840 $(helper_get_psa_key_type_list "ECC") \
841 $loc_curve_list"
842
843 # Configure
844 # ---------
845
846 # Start with config crypto_full and remove PK_C:
847 # that's what's supported now, see docs/driver-only-builds.md.
848 helper_libtestdriver1_adjust_config "crypto_full"
849 scripts/config.py unset MBEDTLS_PK_C
850 scripts/config.py unset MBEDTLS_PK_PARSE_C
851 scripts/config.py unset MBEDTLS_PK_WRITE_C
852
853 # Disable modules that are accelerated - some will be re-enabled
854 scripts/config.py unset MBEDTLS_ECDSA_C
855 scripts/config.py unset MBEDTLS_ECDH_C
856 scripts/config.py unset MBEDTLS_ECJPAKE_C
857 scripts/config.py unset MBEDTLS_ECP_C
858
859 # Disable all curves - those that aren't accelerated should be re-enabled
860 helper_disable_builtin_curves
861
862 # Restartable feature is not yet supported by PSA. Once it will in
863 # the future, the following line could be removed (see issues
864 # 6061, 6332 and following ones)
865 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
866
867 # this is not supported by the driver API yet
868 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
869
870 # Build
871 # -----
872
873 # These hashes are needed for some ECDSA signature tests.
874 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
875 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
876 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
877
878 helper_libtestdriver1_make_main "$loc_accel_list"
879
880 # We expect ECDH to be re-enabled for the missing curves
881 grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
882 # We expect ECP to be re-enabled, however the parts specific to the
883 # families of curves that are accelerated should be ommited.
884 # - functions with mxz in the name are specific to Montgomery curves
885 # - ecp_muladd is specific to Weierstrass curves
886 ##nm ${BUILTIN_SRC_PATH}/ecp.o | tee ecp.syms
887 if [ $weierstrass -eq 1 ]; then
888 not grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
889 grep mxz ${BUILTIN_SRC_PATH}/ecp.o
890 else
891 grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
892 not grep mxz ${BUILTIN_SRC_PATH}/ecp.o
893 fi
894 # We expect ECDSA and ECJPAKE to be re-enabled only when
895 # Weierstrass curves are not accelerated
896 if [ $weierstrass -eq 1 ]; then
897 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
898 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
899 else
900 grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
901 grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
902 fi
903
904 # Run the tests
905 # -------------
906
907 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
908 make test
909}
910
911component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
912 common_test_psa_crypto_config_accel_ecc_some_curves 1
913}
914
915component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
916 common_test_psa_crypto_config_accel_ecc_some_curves 0
917}
918
919# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
920# ECDH, ECDSA) with and without drivers.
921# The input parameter is a boolean value which indicates:
922# - 0 keep built-in EC algs,
923# - 1 exclude built-in EC algs (driver only).
924#
925# This is used by the two following components to ensure they always use the
926# same config, except for the use of driver or built-in EC algorithms:
927# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
928# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
929# This supports comparing their test coverage with analyze_outcomes.py.
Minos Galanakis471b34c2024-07-26 15:39:24 +0100930config_psa_crypto_config_ecp_light_only () {
931 driver_only="$1"
932 # start with config full for maximum coverage (also enables USE_PSA)
933 helper_libtestdriver1_adjust_config "full"
934 if [ "$driver_only" -eq 1 ]; then
935 # Disable modules that are accelerated
936 scripts/config.py unset MBEDTLS_ECDSA_C
937 scripts/config.py unset MBEDTLS_ECDH_C
938 scripts/config.py unset MBEDTLS_ECJPAKE_C
939 scripts/config.py unset MBEDTLS_ECP_C
940 fi
941
942 # Restartable feature is not yet supported by PSA. Once it will in
943 # the future, the following line could be removed (see issues
944 # 6061, 6332 and following ones)
945 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
946}
947
948# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100949component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
950 msg "build: full with accelerated EC algs"
951
952 # Algorithms and key types to accelerate
953 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
954 ALG_ECDH \
955 ALG_JPAKE \
956 $(helper_get_psa_key_type_list "ECC") \
957 $(helper_get_psa_curve_list)"
958
959 # Configure
960 # ---------
961
962 # Use the same config as reference, only without built-in EC algs
963 config_psa_crypto_config_ecp_light_only 1
964
965 # Do not disable builtin curves because that support is required for:
966 # - MBEDTLS_PK_PARSE_EC_EXTENDED
967 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
968
969 # Build
970 # -----
971
972 # These hashes are needed for some ECDSA signature tests.
973 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
974 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
975 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
976
977 helper_libtestdriver1_make_main "$loc_accel_list"
978
979 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
980 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
981 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
982 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
983 not grep mbedtls_ecp_mul ${BUILTIN_SRC_PATH}/ecp.o
984
985 # Run the tests
986 # -------------
987
988 msg "test suites: full with accelerated EC algs"
989 make test
990
991 msg "ssl-opt: full with accelerated EC algs"
992 tests/ssl-opt.sh
993}
994
995# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +0100996component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
Ronald Cron93ba6252024-09-05 10:37:14 +0200997 msg "build: non-accelerated EC algs"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100998
999 config_psa_crypto_config_ecp_light_only 0
1000
1001 make
1002
1003 msg "test suites: full with non-accelerated EC algs"
1004 make test
1005
1006 msg "ssl-opt: full with non-accelerated EC algs"
1007 tests/ssl-opt.sh
1008}
1009
1010# This helper function is used by:
1011# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
1012# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
1013# to ensure that both tests use the same underlying configuration when testing
1014# driver's coverage with analyze_outcomes.py.
1015#
1016# This functions accepts 1 boolean parameter as follows:
1017# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
1018# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
1019# - 0: include built-in implementation of EC algorithms.
1020#
1021# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
1022# on the ECP module.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001023config_psa_crypto_no_ecp_at_all () {
1024 driver_only="$1"
1025 # start with full config for maximum coverage (also enables USE_PSA)
1026 helper_libtestdriver1_adjust_config "full"
1027
1028 if [ "$driver_only" -eq 1 ]; then
1029 # Disable modules that are accelerated
1030 scripts/config.py unset MBEDTLS_ECDSA_C
1031 scripts/config.py unset MBEDTLS_ECDH_C
1032 scripts/config.py unset MBEDTLS_ECJPAKE_C
1033 # Disable ECP module (entirely)
1034 scripts/config.py unset MBEDTLS_ECP_C
1035 fi
1036
1037 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1038 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1039 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1040 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1041
1042 # Restartable feature is not yet supported by PSA. Once it will in
1043 # the future, the following line could be removed (see issues
1044 # 6061, 6332 and following ones)
1045 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1046}
1047
1048# Build and test a configuration where driver accelerates all EC algs while
1049# all support and dependencies from ECP and ECP_LIGHT are removed on the library
1050# side.
1051#
1052# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001053component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
1054 msg "build: full + accelerated EC algs - ECP"
1055
1056 # Algorithms and key types to accelerate
1057 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1058 ALG_ECDH \
1059 ALG_JPAKE \
1060 $(helper_get_psa_key_type_list "ECC") \
1061 $(helper_get_psa_curve_list)"
1062
1063 # Configure
1064 # ---------
1065
1066 # Set common configurations between library's and driver's builds
1067 config_psa_crypto_no_ecp_at_all 1
1068 # Disable all the builtin curves. All the required algs are accelerated.
1069 helper_disable_builtin_curves
1070
1071 # Build
1072 # -----
1073
1074 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1075 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1076 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1077 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1078
1079 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1080
1081 helper_libtestdriver1_make_main "$loc_accel_list"
1082
1083 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1084 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1085 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1086 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1087 # Also ensure that ECP module was not re-enabled
1088 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1089
1090 # Run the tests
1091 # -------------
1092
1093 msg "test: full + accelerated EC algs - ECP"
1094 make test
1095
1096 msg "ssl-opt: full + accelerated EC algs - ECP"
1097 tests/ssl-opt.sh
1098}
1099
1100# Reference function used for driver's coverage analysis in analyze_outcomes.py
1101# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
1102# Keep in sync with its accelerated counterpart.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001103component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
1104 msg "build: full + non accelerated EC algs"
1105
1106 config_psa_crypto_no_ecp_at_all 0
1107
1108 make
1109
1110 msg "test: full + non accelerated EC algs"
1111 make test
1112
1113 msg "ssl-opt: full + non accelerated EC algs"
1114 tests/ssl-opt.sh
1115}
1116
1117# This is a common configuration helper used directly from:
1118# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1119# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1120# and indirectly from:
1121# - component_test_psa_crypto_config_accel_ecc_no_bignum
1122# - accelerate all EC algs, disable RSA and FFDH
1123# - component_test_psa_crypto_config_reference_ecc_no_bignum
1124# - this is the reference component of the above
1125# - it still disables RSA and FFDH, but it uses builtin EC algs
1126# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1127# - accelerate all EC and FFDH algs, disable only RSA
1128# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1129# - this is the reference component of the above
1130# - it still disables RSA, but it uses builtin EC and FFDH algs
1131#
1132# This function accepts 2 parameters:
1133# $1: a boolean value which states if we are testing an accelerated scenario
1134# or not.
1135# $2: a string value which states which components are tested. Allowed values
1136# are "ECC" or "ECC_DH".
Minos Galanakisf78447f2024-07-26 20:49:51 +01001137config_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001138 driver_only="$1"
1139 test_target="$2"
1140 # start with full config for maximum coverage (also enables USE_PSA)
1141 helper_libtestdriver1_adjust_config "full"
1142
1143 if [ "$driver_only" -eq 1 ]; then
1144 # Disable modules that are accelerated
1145 scripts/config.py unset MBEDTLS_ECDSA_C
1146 scripts/config.py unset MBEDTLS_ECDH_C
1147 scripts/config.py unset MBEDTLS_ECJPAKE_C
1148 # Disable ECP module (entirely)
1149 scripts/config.py unset MBEDTLS_ECP_C
1150 # Also disable bignum
1151 scripts/config.py unset MBEDTLS_BIGNUM_C
1152 fi
1153
1154 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1155 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1156 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1157 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1158
1159 # RSA support is intentionally disabled on this test because RSA_C depends
1160 # on BIGNUM_C.
1161 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
1162 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
1163 scripts/config.py unset MBEDTLS_RSA_C
1164 scripts/config.py unset MBEDTLS_PKCS1_V15
1165 scripts/config.py unset MBEDTLS_PKCS1_V21
1166 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1167 # Also disable key exchanges that depend on RSA
Minos Galanakis471b34c2024-07-26 15:39:24 +01001168 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001169 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1170 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1171
1172 if [ "$test_target" = "ECC" ]; then
1173 # When testing ECC only, we disable FFDH support, both from builtin and
Valerio Setti8438c632025-01-22 11:56:40 +01001174 # PSA sides.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001175 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_FFDH
1176 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
1177 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001178 fi
1179
1180 # Restartable feature is not yet supported by PSA. Once it will in
1181 # the future, the following line could be removed (see issues
1182 # 6061, 6332 and following ones)
1183 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1184}
1185
1186# Common helper used by:
1187# - component_test_psa_crypto_config_accel_ecc_no_bignum
1188# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1189#
1190# The goal is to build and test accelerating either:
1191# - ECC only or
1192# - both ECC and FFDH
1193#
1194# It is meant to be used in conjunction with
1195# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
1196# coverage analysis in the "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001197common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1198 test_target="$1"
1199
1200 # This is an internal helper to simplify text message handling
1201 if [ "$test_target" = "ECC_DH" ]; then
1202 accel_text="ECC/FFDH"
1203 removed_text="ECP - DH"
1204 else
1205 accel_text="ECC"
1206 removed_text="ECP"
1207 fi
1208
1209 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1210
1211 # By default we accelerate all EC keys/algs
1212 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1213 ALG_ECDH \
1214 ALG_JPAKE \
1215 $(helper_get_psa_key_type_list "ECC") \
1216 $(helper_get_psa_curve_list)"
1217 # Optionally we can also add DH to the list of accelerated items
1218 if [ "$test_target" = "ECC_DH" ]; then
1219 loc_accel_list="$loc_accel_list \
1220 ALG_FFDH \
1221 $(helper_get_psa_key_type_list "DH") \
1222 $(helper_get_psa_dh_group_list)"
1223 fi
1224
1225 # Configure
1226 # ---------
1227
1228 # Set common configurations between library's and driver's builds
1229 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
1230 # Disable all the builtin curves. All the required algs are accelerated.
1231 helper_disable_builtin_curves
1232
1233 # Build
1234 # -----
1235
1236 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1237 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1238 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1239 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1240
1241 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1242
1243 helper_libtestdriver1_make_main "$loc_accel_list"
1244
1245 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1246 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1247 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1248 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001249 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001250 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1251 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1252 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001253
1254 # Run the tests
1255 # -------------
1256
Valerio Settieb63eb22025-02-12 13:32:49 +01001257 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001258
1259 make test
1260
1261 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1262 tests/ssl-opt.sh
1263}
1264
1265# Common helper used by:
1266# - component_test_psa_crypto_config_reference_ecc_no_bignum
1267# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1268#
1269# The goal is to build and test a reference scenario (i.e. with builtin
1270# components) compared to the ones used in
1271# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
1272#
1273# It is meant to be used in conjunction with
1274# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
1275# coverage analysis in "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001276common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1277 test_target="$1"
1278
1279 # This is an internal helper to simplify text message handling
1280 if [ "$test_target" = "ECC_DH" ]; then
1281 accel_text="ECC/FFDH"
1282 else
1283 accel_text="ECC"
1284 fi
1285
1286 msg "build: full + non accelerated $accel_text algs + USE_PSA"
1287
1288 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
1289
1290 make
1291
1292 msg "test suites: full + non accelerated EC algs + USE_PSA"
1293 make test
1294
1295 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
1296 tests/ssl-opt.sh
1297}
1298
1299component_test_psa_crypto_config_accel_ecc_no_bignum () {
1300 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
1301}
1302
1303component_test_psa_crypto_config_reference_ecc_no_bignum () {
1304 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
1305}
1306
1307component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1308 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
1309}
1310
1311component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1312 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
1313}
1314
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001315component_test_tfm_config_as_is () {
1316 msg "build: configs/config-tfm.h"
Minos Galanakis5da58e52024-11-07 15:35:33 +00001317 MBEDTLS_CONFIG="configs/config-tfm.h"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001318 CRYPTO_CONFIG="tf-psa-crypto/configs/ext/crypto_config_profile_medium.h"
Minos Galanakis4f619e12024-11-14 14:56:47 +00001319 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 +02001320 make
1321
1322 msg "test: configs/config-tfm.h - unit tests"
1323 make test
1324}
1325
Minos Galanakis471b34c2024-07-26 15:39:24 +01001326# Helper for setting common configurations between:
1327# - component_test_tfm_config_p256m_driver_accel_ec()
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001328# - component_test_tfm_config_no_p256m()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001329common_tfm_config () {
1330 # Enable TF-M config
1331 cp configs/config-tfm.h "$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00001332 cp tf-psa-crypto/configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001333
Minos Galanakis471b34c2024-07-26 15:39:24 +01001334 # Config adjustment for better test coverage in our environment.
1335 # This is not needed just to build and pass tests.
1336 #
1337 # Enable filesystem I/O for the benefit of PK parse/write tests.
Minos Galanakis5da58e52024-11-07 15:35:33 +00001338 sed -i '/PROFILE_M_PSA_CRYPTO_CONFIG_H/i #define MBEDTLS_FS_IO' "$CRYPTO_CONFIG_H"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001339}
1340
1341# Keep this in sync with component_test_tfm_config() as they are both meant
1342# to be used in analyze_outcomes.py for driver's coverage analysis.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001343component_test_tfm_config_p256m_driver_accel_ec () {
1344 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1345
1346 common_tfm_config
1347
1348 # Build crypto library
David Horstmann5b93d972024-10-31 15:36:05 +00001349 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../framework/tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001350
1351 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1352 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1353 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1354 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
Valerio Settieb63eb22025-02-12 13:32:49 +01001355 # Also ensure that ECP, RSA or BIGNUM modules were not re-enabled
Minos Galanakis471b34c2024-07-26 15:39:24 +01001356 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1357 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001358 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1359 # Check that p256m was built
1360 grep -q p256_ecdsa_ library/libmbedcrypto.a
1361
1362 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1363 # files, so we want to ensure that it has not be re-enabled accidentally.
1364 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1365
1366 # Run the tests
1367 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1368 make test
1369}
1370
1371# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1372# they are both meant to be used in analyze_outcomes.py for driver's coverage
1373# analysis.
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001374component_test_tfm_config_no_p256m () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001375 common_tfm_config
1376
1377 # Disable P256M driver, which is on by default, so that analyze_outcomes
1378 # can compare this test with test_tfm_config_p256m_driver_accel_ec
Minos Galanakis5da58e52024-11-07 15:35:33 +00001379 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 +01001380
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001381 msg "build: TF-M config without p256m"
David Horstmann5b93d972024-10-31 15:36:05 +00001382 make CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' tests
Minos Galanakis471b34c2024-07-26 15:39:24 +01001383
1384 # Check that p256m was not built
1385 not grep p256_ecdsa_ library/libmbedcrypto.a
1386
1387 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1388 # files, so we want to ensure that it has not be re-enabled accidentally.
1389 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1390
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001391 msg "test: TF-M config without p256m"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001392 make test
1393}
1394
Minos Galanakis471b34c2024-07-26 15:39:24 +01001395# This is an helper used by:
1396# - component_test_psa_ecc_key_pair_no_derive
1397# - component_test_psa_ecc_key_pair_no_generate
1398# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1399# enabled, but one. Input arguments are as follows:
Gilles Peskinefef912c2024-09-20 16:07:09 +02001400# - $1 is the configuration to start from
1401# - $2 is the key type under test, i.e. ECC/RSA/DH
1402# - $3 is the key option to be unset (i.e. generate, derive, etc)
Minos Galanakisf78447f2024-07-26 20:49:51 +01001403build_and_test_psa_want_key_pair_partial () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001404 base_config=$1
1405 key_type=$2
1406 unset_option=$3
Minos Galanakis471b34c2024-07-26 15:39:24 +01001407 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1408
Gilles Peskinefef912c2024-09-20 16:07:09 +02001409 msg "build: $base_config - ${disabled_psa_want}"
1410 scripts/config.py "$base_config"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001411
1412 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1413 # crypto_config.h so we just disable the one we don't want.
1414 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
1415
1416 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1417
Gilles Peskinefef912c2024-09-20 16:07:09 +02001418 msg "test: $base_config - ${disabled_psa_want}"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001419 make test
1420}
1421
Minos Galanakisf78447f2024-07-26 20:49:51 +01001422component_test_psa_ecc_key_pair_no_derive () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001423 build_and_test_psa_want_key_pair_partial full "ECC" "DERIVE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001424}
1425
Minos Galanakisf78447f2024-07-26 20:49:51 +01001426component_test_psa_ecc_key_pair_no_generate () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001427 # TLS needs ECC key generation whenever ephemeral ECDH is enabled.
1428 # We don't have proper guards for configurations with ECC key generation
1429 # disabled (https://github.com/Mbed-TLS/mbedtls/issues/9481). Until
1430 # then (if ever), just test the crypto part of the library.
1431 build_and_test_psa_want_key_pair_partial crypto_full "ECC" "GENERATE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001432}
1433
1434config_psa_crypto_accel_rsa () {
1435 driver_only=$1
1436
1437 # Start from crypto_full config (no X.509, no TLS)
1438 helper_libtestdriver1_adjust_config "crypto_full"
1439
1440 if [ "$driver_only" -eq 1 ]; then
1441 # Remove RSA support and its dependencies
1442 scripts/config.py unset MBEDTLS_RSA_C
1443 scripts/config.py unset MBEDTLS_PKCS1_V15
1444 scripts/config.py unset MBEDTLS_PKCS1_V21
1445
1446 # We need PEM parsing in the test library as well to support the import
1447 # of PEM encoded RSA keys.
Minos Galanakis23452f52024-11-28 17:48:14 +00001448 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1449 scripts/config.py -c "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
Minos Galanakis471b34c2024-07-26 15:39:24 +01001450 fi
1451}
1452
1453component_test_psa_crypto_config_accel_rsa_crypto () {
1454 msg "build: crypto_full with accelerated RSA"
1455
1456 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1457 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1458 KEY_TYPE_RSA_PUBLIC_KEY \
1459 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1460 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1461 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1462 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1463
1464 # Configure
1465 # ---------
1466
1467 config_psa_crypto_accel_rsa 1
1468
1469 # Build
1470 # -----
1471
1472 # These hashes are needed for unit tests.
1473 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1474 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1475 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1476
1477 helper_libtestdriver1_make_main "$loc_accel_list"
1478
1479 # Make sure this was not re-enabled by accident (additive config)
1480 not grep mbedtls_rsa ${BUILTIN_SRC_PATH}/rsa.o
1481
1482 # Run the tests
1483 # -------------
1484
1485 msg "test: crypto_full with accelerated RSA"
1486 make test
1487}
1488
1489component_test_psa_crypto_config_reference_rsa_crypto () {
1490 msg "build: crypto_full with non-accelerated RSA"
1491
1492 # Configure
1493 # ---------
1494 config_psa_crypto_accel_rsa 0
1495
1496 # Build
1497 # -----
1498 make
1499
1500 # Run the tests
1501 # -------------
1502 msg "test: crypto_full with non-accelerated RSA"
1503 make test
1504}
1505
1506# This is a temporary test to verify that full RSA support is present even when
1507# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001508component_test_new_psa_want_key_pair_symbol () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001509 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1510
1511 # Create a temporary output file unless there is already one set
1512 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1513 REMOVE_OUTCOME_ON_EXIT="no"
1514 else
1515 REMOVE_OUTCOME_ON_EXIT="yes"
1516 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1517 export MBEDTLS_TEST_OUTCOME_FILE
1518 fi
1519
1520 # Start from crypto configuration
1521 scripts/config.py crypto
1522
1523 # Remove RSA support and its dependencies
1524 scripts/config.py unset MBEDTLS_PKCS1_V15
1525 scripts/config.py unset MBEDTLS_PKCS1_V21
Minos Galanakis471b34c2024-07-26 15:39:24 +01001526 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1527 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
Minos Galanakis471b34c2024-07-26 15:39:24 +01001528 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1529 scripts/config.py unset MBEDTLS_RSA_C
1530 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1531
Minos Galanakis471b34c2024-07-26 15:39:24 +01001532 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
1533 # that proper translations is done in crypto_legacy.h.
1534 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
1535 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
1536 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
1537
1538 make
1539
1540 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1541 make test
1542
1543 # Parse only 1 relevant line from the outcome file, i.e. a test which is
1544 # performing RSA signature.
1545 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
1546 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
1547
1548 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
1549 rm $MBEDTLS_TEST_OUTCOME_FILE
1550 fi
1551}
1552
1553component_test_psa_crypto_config_accel_hash () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001554 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001555
1556 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1557 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1558 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1559
1560 # Configure
1561 # ---------
1562
1563 # Start from default config (no USE_PSA)
1564 helper_libtestdriver1_adjust_config "default"
1565
1566 # Disable the things that are being accelerated
1567 scripts/config.py unset MBEDTLS_MD5_C
1568 scripts/config.py unset MBEDTLS_RIPEMD160_C
1569 scripts/config.py unset MBEDTLS_SHA1_C
1570 scripts/config.py unset MBEDTLS_SHA224_C
1571 scripts/config.py unset MBEDTLS_SHA256_C
1572 scripts/config.py unset MBEDTLS_SHA384_C
1573 scripts/config.py unset MBEDTLS_SHA512_C
1574 scripts/config.py unset MBEDTLS_SHA3_C
1575
1576 # Build
1577 # -----
1578
1579 helper_libtestdriver1_make_drivers "$loc_accel_list"
1580
1581 helper_libtestdriver1_make_main "$loc_accel_list"
1582
1583 # There's a risk of something getting re-enabled via config_psa.h;
1584 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1585 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1586 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1587 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1588 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1589 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1590
1591 # Run the tests
1592 # -------------
1593
Ronald Cron93ba6252024-09-05 10:37:14 +02001594 msg "test: accelerated hash"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001595 make test
1596}
1597
1598# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001599config_psa_crypto_hash_use_psa () {
1600 driver_only="$1"
1601 # start with config full for maximum coverage (also enables USE_PSA)
1602 helper_libtestdriver1_adjust_config "full"
1603 if [ "$driver_only" -eq 1 ]; then
1604 # disable the built-in implementation of hashes
1605 scripts/config.py unset MBEDTLS_MD5_C
1606 scripts/config.py unset MBEDTLS_RIPEMD160_C
1607 scripts/config.py unset MBEDTLS_SHA1_C
1608 scripts/config.py unset MBEDTLS_SHA224_C
1609 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
1610 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
1611 scripts/config.py unset MBEDTLS_SHA384_C
1612 scripts/config.py unset MBEDTLS_SHA512_C
1613 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
1614 scripts/config.py unset MBEDTLS_SHA3_C
1615 fi
1616}
1617
1618# Note that component_test_psa_crypto_config_reference_hash_use_psa
1619# is related to this component and both components need to be kept in sync.
1620# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001621component_test_psa_crypto_config_accel_hash_use_psa () {
1622 msg "test: full with accelerated hashes"
1623
1624 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1625 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1626 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1627
1628 # Configure
1629 # ---------
1630
1631 config_psa_crypto_hash_use_psa 1
1632
1633 # Build
1634 # -----
1635
1636 helper_libtestdriver1_make_drivers "$loc_accel_list"
1637
1638 helper_libtestdriver1_make_main "$loc_accel_list"
1639
1640 # There's a risk of something getting re-enabled via config_psa.h;
1641 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1642 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1643 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1644 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1645 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1646 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1647
1648 # Run the tests
1649 # -------------
1650
1651 msg "test: full with accelerated hashes"
1652 make test
1653
1654 # This is mostly useful so that we can later compare outcome files with
1655 # the reference config in analyze_outcomes.py, to check that the
1656 # dependency declarations in ssl-opt.sh and in TLS code are correct.
1657 msg "test: ssl-opt.sh, full with accelerated hashes"
1658 tests/ssl-opt.sh
1659
1660 # This is to make sure all ciphersuites are exercised, but we don't need
1661 # interop testing (besides, we already got some from ssl-opt.sh).
1662 msg "test: compat.sh, full with accelerated hashes"
1663 tests/compat.sh -p mbedTLS -V YES
1664}
1665
1666# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
1667# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
1668# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
1669# Both components need to be kept in sync.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001670component_test_psa_crypto_config_reference_hash_use_psa () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001671 msg "test: full without accelerated hashes"
1672
1673 config_psa_crypto_hash_use_psa 0
1674
1675 make
1676
1677 msg "test: full without accelerated hashes"
1678 make test
1679
1680 msg "test: ssl-opt.sh, full without accelerated hashes"
1681 tests/ssl-opt.sh
1682}
1683
1684# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001685config_psa_crypto_hmac_use_psa () {
1686 driver_only="$1"
1687 # start with config full for maximum coverage (also enables USE_PSA)
1688 helper_libtestdriver1_adjust_config "full"
1689
1690 if [ "$driver_only" -eq 1 ]; then
1691 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
1692 # is still enabled though (for ENTROPY_C among others).
1693 scripts/config.py unset MBEDTLS_MD_C
1694 # Disable also the builtin hashes since they are supported by the driver
1695 # and MD module is able to perform PSA dispathing.
1696 scripts/config.py unset-all MBEDTLS_SHA
1697 scripts/config.py unset MBEDTLS_MD5_C
1698 scripts/config.py unset MBEDTLS_RIPEMD160_C
1699 fi
1700
1701 # Direct dependencies of MD_C. We disable them also in the reference
1702 # component to work with the same set of features.
1703 scripts/config.py unset MBEDTLS_PKCS7_C
1704 scripts/config.py unset MBEDTLS_PKCS5_C
1705 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1706 scripts/config.py unset MBEDTLS_HKDF_C
1707 # Dependencies of HMAC_DRBG
1708 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
1709 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
1710}
1711
Minos Galanakisf78447f2024-07-26 20:49:51 +01001712component_test_psa_crypto_config_accel_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001713 msg "test: full with accelerated hmac"
1714
1715 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
1716 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1717 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1718 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1719
1720 # Configure
1721 # ---------
1722
1723 config_psa_crypto_hmac_use_psa 1
1724
1725 # Build
1726 # -----
1727
1728 helper_libtestdriver1_make_drivers "$loc_accel_list"
1729
1730 helper_libtestdriver1_make_main "$loc_accel_list"
1731
1732 # Ensure that built-in support for HMAC is disabled.
1733 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
1734
1735 # Run the tests
1736 # -------------
1737
1738 msg "test: full with accelerated hmac"
1739 make test
1740}
1741
Minos Galanakisf78447f2024-07-26 20:49:51 +01001742component_test_psa_crypto_config_reference_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001743 msg "test: full without accelerated hmac"
1744
1745 config_psa_crypto_hmac_use_psa 0
1746
1747 make
1748
1749 msg "test: full without accelerated hmac"
1750 make test
1751}
1752
1753component_test_psa_crypto_config_accel_des () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001754 msg "test: accelerated DES"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001755
1756 # Albeit this components aims at accelerating DES which should only support
1757 # CBC and ECB modes, we need to accelerate more than that otherwise DES_C
1758 # would automatically be re-enabled by "config_adjust_legacy_from_psa.c"
1759 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 \
1760 ALG_CTR ALG_CFB ALG_OFB ALG_XTS ALG_CMAC \
1761 KEY_TYPE_DES"
1762
1763 # Note: we cannot accelerate all ciphers' key types otherwise we would also
1764 # have to either disable CCM/GCM or accelerate them, but that's out of scope
1765 # of this component. This limitation will be addressed by #8598.
1766
1767 # Configure
1768 # ---------
1769
1770 # Start from the full config
1771 helper_libtestdriver1_adjust_config "full"
1772
1773 # Disable the things that are being accelerated
1774 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1775 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
1776 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
1777 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
1778 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
1779 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
1780 scripts/config.py unset MBEDTLS_DES_C
1781 scripts/config.py unset MBEDTLS_CMAC_C
1782
1783 # Build
1784 # -----
1785
1786 helper_libtestdriver1_make_drivers "$loc_accel_list"
1787
1788 helper_libtestdriver1_make_main "$loc_accel_list"
1789
1790 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine29e86ca2024-06-19 15:09:27 +02001791 not grep mbedtls_des ${BUILTIN_SRC_PATH}/des.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001792
1793 # Run the tests
1794 # -------------
1795
Ronald Cron93ba6252024-09-05 10:37:14 +02001796 msg "test: accelerated DES"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001797 make test
1798}
1799
1800component_test_psa_crypto_config_accel_aead () {
Ronald Cron93ba6252024-09-05 10:37:14 +02001801 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001802
1803 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
1804 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1805
1806 # Configure
1807 # ---------
1808
1809 # Start from full config
1810 helper_libtestdriver1_adjust_config "full"
1811
1812 # Disable things that are being accelerated
1813 scripts/config.py unset MBEDTLS_GCM_C
1814 scripts/config.py unset MBEDTLS_CCM_C
1815 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1816
1817 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
1818 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1819
1820 # Build
1821 # -----
1822
1823 helper_libtestdriver1_make_drivers "$loc_accel_list"
1824
1825 helper_libtestdriver1_make_main "$loc_accel_list"
1826
1827 # Make sure this was not re-enabled by accident (additive config)
1828 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1829 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1830 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1831
1832 # Run the tests
1833 # -------------
1834
Ronald Cron93ba6252024-09-05 10:37:14 +02001835 msg "test: accelerated AEAD"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001836 make test
1837}
1838
1839# This is a common configuration function used in:
1840# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1841# - component_test_psa_crypto_config_reference_cipher_aead_cmac
Minos Galanakisf78447f2024-07-26 20:49:51 +01001842common_psa_crypto_config_accel_cipher_aead_cmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001843 # Start from the full config
1844 helper_libtestdriver1_adjust_config "full"
1845
1846 scripts/config.py unset MBEDTLS_NIST_KW_C
1847}
1848
1849# The 2 following test components, i.e.
1850# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1851# - component_test_psa_crypto_config_reference_cipher_aead_cmac
1852# are meant to be used together in analyze_outcomes.py script in order to test
1853# driver's coverage for ciphers and AEADs.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001854component_test_psa_crypto_config_accel_cipher_aead_cmac () {
1855 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
1856
1857 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
1858 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
1859 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
1860 KEY_TYPE_DES KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
1861
1862 # Configure
1863 # ---------
1864
1865 common_psa_crypto_config_accel_cipher_aead_cmac
1866
1867 # Disable the things that are being accelerated
1868 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1869 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
1870 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
1871 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
1872 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
1873 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
1874 scripts/config.py unset MBEDTLS_GCM_C
1875 scripts/config.py unset MBEDTLS_CCM_C
1876 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1877 scripts/config.py unset MBEDTLS_CMAC_C
1878 scripts/config.py unset MBEDTLS_DES_C
1879 scripts/config.py unset MBEDTLS_AES_C
1880 scripts/config.py unset MBEDTLS_ARIA_C
1881 scripts/config.py unset MBEDTLS_CHACHA20_C
1882 scripts/config.py unset MBEDTLS_CAMELLIA_C
1883
1884 # Disable CIPHER_C entirely as all ciphers/AEADs are accelerated and PSA
1885 # does not depend on it.
1886 scripts/config.py unset MBEDTLS_CIPHER_C
1887
1888 # Build
1889 # -----
1890
1891 helper_libtestdriver1_make_drivers "$loc_accel_list"
1892
1893 helper_libtestdriver1_make_main "$loc_accel_list"
1894
1895 # Make sure this was not re-enabled by accident (additive config)
1896 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1897 not grep mbedtls_des ${BUILTIN_SRC_PATH}/des.o
1898 not grep mbedtls_aes ${BUILTIN_SRC_PATH}/aes.o
1899 not grep mbedtls_aria ${BUILTIN_SRC_PATH}/aria.o
1900 not grep mbedtls_camellia ${BUILTIN_SRC_PATH}/camellia.o
1901 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1902 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1903 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1904 not grep mbedtls_cmac ${BUILTIN_SRC_PATH}/cmac.o
1905
1906 # Run the tests
1907 # -------------
1908
1909 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
1910 make test
1911
1912 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
1913 tests/ssl-opt.sh
1914
1915 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
1916 tests/compat.sh -V NO -p mbedTLS
1917}
1918
1919component_test_psa_crypto_config_reference_cipher_aead_cmac () {
1920 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
1921 common_psa_crypto_config_accel_cipher_aead_cmac
1922
1923 make
1924
1925 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
1926 make test
1927
1928 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
1929 tests/ssl-opt.sh
1930
1931 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
1932 tests/compat.sh -V NO -p mbedTLS
1933}
1934
Minos Galanakisf78447f2024-07-26 20:49:51 +01001935common_block_cipher_dispatch () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001936 TEST_WITH_DRIVER="$1"
1937
1938 # Start from the full config
1939 helper_libtestdriver1_adjust_config "full"
1940
1941 if [ "$TEST_WITH_DRIVER" -eq 1 ]; then
1942 # Disable key types that are accelerated (there is no legacy equivalent
1943 # symbol for ECB)
1944 scripts/config.py unset MBEDTLS_AES_C
1945 scripts/config.py unset MBEDTLS_ARIA_C
1946 scripts/config.py unset MBEDTLS_CAMELLIA_C
1947 fi
1948
1949 # Disable cipher's modes that, when not accelerated, cause
1950 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
1951 # Keep this also in the reference component in order to skip the same tests
1952 # that were skipped in the accelerated one.
1953 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
1954 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
1955 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
1956 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
1957 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
1958 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
1959 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1960 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
1961
1962 # Disable direct dependency on AES_C
1963 scripts/config.py unset MBEDTLS_NIST_KW_C
1964
1965 # Prevent the cipher module from using deprecated PSA path. The reason is
1966 # that otherwise there will be tests relying on "aes_info" (defined in
1967 # "cipher_wrap.c") whose functions are not available when AES_C is
1968 # not defined. ARIA and Camellia are not a problem in this case because
1969 # the PSA path is not tested for these key types.
1970 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1971}
1972
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02001973component_test_full_block_cipher_psa_dispatch_static_keystore () {
1974 msg "build: full + PSA dispatch in block_cipher with static keystore"
1975 # Check that the static key store works well when CTR_DRBG uses a
1976 # PSA key for AES.
1977 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
1978
1979 loc_accel_list="ALG_ECB_NO_PADDING \
1980 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1981
1982 # Configure
1983 # ---------
1984
1985 common_block_cipher_dispatch 1
1986
1987 # Build
1988 # -----
1989
1990 helper_libtestdriver1_make_drivers "$loc_accel_list"
1991
1992 helper_libtestdriver1_make_main "$loc_accel_list"
1993
1994 # Make sure disabled components were not re-enabled by accident (additive
1995 # config)
1996 not grep mbedtls_aes_ library/aes.o
1997 not grep mbedtls_aria_ library/aria.o
1998 not grep mbedtls_camellia_ library/camellia.o
1999
2000 # Run the tests
2001 # -------------
2002
2003 msg "test: full + PSA dispatch in block_cipher with static keystore"
2004 make test
2005}
2006
Minos Galanakis471b34c2024-07-26 15:39:24 +01002007component_test_full_block_cipher_psa_dispatch () {
2008 msg "build: full + PSA dispatch in block_cipher"
2009
2010 loc_accel_list="ALG_ECB_NO_PADDING \
2011 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2012
2013 # Configure
2014 # ---------
2015
2016 common_block_cipher_dispatch 1
2017
2018 # Build
2019 # -----
2020
2021 helper_libtestdriver1_make_drivers "$loc_accel_list"
2022
2023 helper_libtestdriver1_make_main "$loc_accel_list"
2024
2025 # Make sure disabled components were not re-enabled by accident (additive
2026 # config)
2027 not grep mbedtls_aes_ ${BUILTIN_SRC_PATH}/aes.o
2028 not grep mbedtls_aria_ ${BUILTIN_SRC_PATH}/aria.o
2029 not grep mbedtls_camellia_ ${BUILTIN_SRC_PATH}/camellia.o
2030
2031 # Run the tests
2032 # -------------
2033
2034 msg "test: full + PSA dispatch in block_cipher"
2035 make test
2036}
2037
2038# This is the reference component of component_test_full_block_cipher_psa_dispatch
Minos Galanakis471b34c2024-07-26 15:39:24 +01002039component_test_full_block_cipher_legacy_dispatch () {
2040 msg "build: full + legacy dispatch in block_cipher"
2041
2042 common_block_cipher_dispatch 0
2043
2044 make
2045
2046 msg "test: full + legacy dispatch in block_cipher"
2047 make test
2048}
2049
Minos Galanakisf78447f2024-07-26 20:49:51 +01002050component_test_aead_chachapoly_disabled () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002051 msg "build: full minus CHACHAPOLY"
2052 scripts/config.py full
2053 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2054 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2055 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2056
2057 msg "test: full minus CHACHAPOLY"
2058 make test
2059}
2060
Minos Galanakisf78447f2024-07-26 20:49:51 +01002061component_test_aead_only_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002062 msg "build: full minus CHACHAPOLY and GCM"
2063 scripts/config.py full
2064 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2065 scripts/config.py unset MBEDTLS_GCM_C
2066 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2067 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2068 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2069
2070 msg "test: full minus CHACHAPOLY and GCM"
2071 make test
2072}
2073
Minos Galanakisf78447f2024-07-26 20:49:51 +01002074component_test_ccm_aes_sha256 () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002075 msg "build: CCM + AES + SHA256 configuration"
2076
Minos Galanakisa17ffc72024-12-02 23:57:30 +00002077 # Setting a blank config disables everyhing in the library side.
2078 echo '#define MBEDTLS_CONFIG_H ' >"$CONFIG_H"
Harry Ramsey94c386a2025-01-16 16:08:34 +00002079 cp tf-psa-crypto/configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
Ronald Cron9d262d72024-12-06 17:41:26 +01002080
Minos Galanakis471b34c2024-07-26 15:39:24 +01002081 make
Minos Galanakis471b34c2024-07-26 15:39:24 +01002082 msg "test: CCM + AES + SHA256 configuration"
2083 make test
2084}
2085
2086# Test that the given .o file builds with all (valid) combinations of the given options.
2087#
2088# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
2089#
2090# The validator function is the name of a function to validate the combination of options.
2091# It may be "" if all combinations are valid.
2092# It receives a string containing a combination of options, as passed to the compiler,
2093# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Minos Galanakisf78447f2024-07-26 20:49:51 +01002094build_test_config_combos () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002095 file=$1
2096 shift
2097 validate_options=$1
2098 shift
2099 options=("$@")
2100
2101 # clear all of the options so that they can be overridden on the clang commandline
2102 for opt in "${options[@]}"; do
2103 ./scripts/config.py unset ${opt}
2104 done
2105
2106 # enter the library directory
2107 cd library
2108
2109 # The most common issue is unused variables/functions, so ensure -Wunused is set.
2110 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
2111
2112 # Extract the command generated by the Makefile to build the target file.
2113 # This ensures that we have any include paths, macro definitions, etc
2114 # that may be applied by make.
2115 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
2116 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
2117
2118 makefile=$(TMPDIR=. mktemp)
2119 deps=""
2120
2121 len=${#options[@]}
2122 source_file=../${file%.o}.c
2123
2124 targets=0
2125 echo 'include Makefile' >${makefile}
2126
2127 for ((i = 0; i < $((2**${len})); i++)); do
2128 # generate each of 2^n combinations of options
2129 # each bit of $i is used to determine if options[i] will be set or not
2130 target="t"
2131 clang_args=""
2132 for ((j = 0; j < ${len}; j++)); do
2133 if (((i >> j) & 1)); then
2134 opt=-D${options[$j]}
2135 clang_args="${clang_args} ${opt}"
2136 target="${target}${opt}"
2137 fi
2138 done
2139
2140 # if combination is not known to be invalid, add it to the makefile
2141 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
2142 cmd="${compile_cmd} ${clang_args}"
2143 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
2144
2145 deps="${deps} ${target}"
2146 ((++targets))
2147 fi
2148 done
2149
2150 echo "build_test_config_combos: ${deps}" >> ${makefile}
2151
2152 # execute all of the commands via Make (probably in parallel)
2153 make -s -f ${makefile} build_test_config_combos
2154 echo "$targets targets checked"
2155
2156 # clean up the temporary makefile
2157 rm ${makefile}
2158}
2159
Minos Galanakisf78447f2024-07-26 20:49:51 +01002160validate_aes_config_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002161 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
2162 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
2163 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
2164 return 1
2165 fi
2166 fi
2167 return 0
2168}
2169
Minos Galanakisf78447f2024-07-26 20:49:51 +01002170component_build_aes_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002171 # 18s - around 90ms per clang invocation on M1 Pro
2172 #
2173 # aes.o has many #if defined(...) guards that intersect in complex ways.
2174 # Test that all the combinations build cleanly.
2175
2176 MBEDTLS_ROOT_DIR="$PWD"
2177 msg "build: aes.o for all combinations of relevant config options"
2178
2179 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002180 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002181 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2182 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2183
2184 cd "$MBEDTLS_ROOT_DIR"
2185 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
2186
2187 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES,
2188 # manually set or unset those configurations to check
2189 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
2190 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Minos Galanakis471b34c2024-07-26 15:39:24 +01002191 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002192 scripts/config.py unset MBEDTLS_NIST_KW_C
Ronald Cron54d1eec2024-09-06 09:55:38 +02002193
Minos Galanakis00b641c2024-11-28 23:05:10 +00002194 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
2195 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
2196 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
2197 scripts/config.py -c $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
Ronald Cron4153ebb2024-09-11 15:32:48 +02002198 # Note: The two unsets below are to be removed for Mbed TLS 4.0
Ronald Cron54d1eec2024-09-06 09:55:38 +02002199 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2200 scripts/config.py unset MBEDTLS_DES_C
2201
Minos Galanakis471b34c2024-07-26 15:39:24 +01002202 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002203 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002204 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2205 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2206}
2207
Minos Galanakisf78447f2024-07-26 20:49:51 +01002208component_test_sha3_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002209 msg "sha3 loop unroll variations"
2210
2211 # define minimal config sufficient to test SHA3
Ronald Crone7f289e2024-09-06 11:02:47 +02002212 cat > include/mbedtls/mbedtls_config.h << END
Ronald Crone7f289e2024-09-06 11:02:47 +02002213END
2214
2215 cat > tf-psa-crypto/include/psa/crypto_config.h << END
2216 #define PSA_WANT_ALG_SHA_256 1
2217 #define PSA_WANT_ALG_SHA3_224 1
2218 #define PSA_WANT_ALG_SHA3_256 1
2219 #define PSA_WANT_ALG_SHA3_384 1
2220 #define PSA_WANT_ALG_SHA3_512 1
Ronald Cron3dd1d3d2024-12-05 15:12:06 +01002221 #define MBEDTLS_AES_C
2222 #define MBEDTLS_CTR_DRBG_C
2223 #define MBEDTLS_ENTROPY_C
2224 #define MBEDTLS_PSA_CRYPTO_C
2225 #define MBEDTLS_SELF_TEST
Minos Galanakis471b34c2024-07-26 15:39:24 +01002226END
2227
2228 msg "all loops unrolled"
2229 make clean
2230 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"
2231 ./tf-psa-crypto/tests/test_suite_shax
2232
2233 msg "all loops rolled up"
2234 make clean
2235 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"
2236 ./tf-psa-crypto/tests/test_suite_shax
2237}
2238
Minos Galanakisf699d512024-08-01 11:32:30 +01002239support_build_aes_aesce_armcc () {
2240 support_build_armcc
2241}
2242
Minos Galanakis471b34c2024-07-26 15:39:24 +01002243# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2244component_build_aes_aesce_armcc () {
2245 msg "Build: AESCE test on arm64 platform without plain C."
2246 scripts/config.py baremetal
2247
2248 # armc[56] don't support SHA-512 intrinsics
2249 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2250
2251 # Stop armclang warning about feature detection for A64_CRYPTO.
2252 # With this enabled, the library does build correctly under armclang,
2253 # but in baremetal builds (as tested here), feature detection is
2254 # unavailable, and the user is notified via a #warning. So enabling
2255 # this feature would prevent us from building with -Werror on
2256 # armclang. Tracked in #7198.
2257 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2258 scripts/config.py set MBEDTLS_HAVE_ASM
2259
2260 msg "AESCE, build with default configuration."
2261 scripts/config.py set MBEDTLS_AESCE_C
2262 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002263 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002264
2265 msg "AESCE, build AESCE only"
2266 scripts/config.py set MBEDTLS_AESCE_C
2267 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002268 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002269}
2270
Minos Galanakis471b34c2024-07-26 15:39:24 +01002271component_test_aes_only_128_bit_keys () {
2272 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2273 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2274
2275 make CFLAGS='-O2 -Werror -Wall -Wextra'
2276
2277 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2278 make test
2279}
2280
2281component_test_no_ctr_drbg_aes_only_128_bit_keys () {
2282 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2283 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2284 scripts/config.py unset MBEDTLS_CTR_DRBG_C
2285
2286 make CC=clang CFLAGS='-Werror -Wall -Wextra'
2287
2288 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2289 make test
2290}
2291
2292component_test_aes_only_128_bit_keys_have_builtins () {
2293 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2294 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2295 scripts/config.py unset MBEDTLS_AESNI_C
2296 scripts/config.py unset MBEDTLS_AESCE_C
2297
2298 make CFLAGS='-O2 -Werror -Wall -Wextra'
2299
2300 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2301 make test
2302
2303 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2304 programs/test/selftest
2305}
2306
2307component_test_gcm_largetable () {
2308 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2309 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
2310 scripts/config.py unset MBEDTLS_AESNI_C
2311 scripts/config.py unset MBEDTLS_AESCE_C
2312
2313 make CFLAGS='-O2 -Werror -Wall -Wextra'
2314
2315 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2316 make test
2317}
2318
2319component_test_aes_fewer_tables () {
2320 msg "build: default config with AES_FEWER_TABLES enabled"
2321 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2322 make CFLAGS='-O2 -Werror -Wall -Wextra'
2323
2324 msg "test: AES_FEWER_TABLES"
2325 make test
2326}
2327
2328component_test_aes_rom_tables () {
2329 msg "build: default config with AES_ROM_TABLES enabled"
2330 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2331 make CFLAGS='-O2 -Werror -Wall -Wextra'
2332
2333 msg "test: AES_ROM_TABLES"
2334 make test
2335}
2336
2337component_test_aes_fewer_tables_and_rom_tables () {
2338 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
2339 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2340 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2341 make CFLAGS='-O2 -Werror -Wall -Wextra'
2342
2343 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2344 make test
2345}
2346
Ronald Cron66040472024-09-06 10:14:38 +02002347# helper for component_test_block_cipher_no_decrypt_aesni() which:
Minos Galanakis471b34c2024-07-26 15:39:24 +01002348# - enable/disable the list of config options passed from -s/-u respectively.
2349# - build
2350# - test for tests_suite_xxx
2351# - selftest
2352#
2353# Usage: helper_block_cipher_no_decrypt_build_test
2354# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
2355# Options: -s set_opts the list of config options to enable
2356# -u unset_opts the list of config options to disable
2357# -c cflags the list of options passed to CFLAGS
2358# -l ldflags the list of options passed to LDFLAGS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002359helper_block_cipher_no_decrypt_build_test () {
2360 while [ $# -gt 0 ]; do
2361 case "$1" in
2362 -s)
2363 shift; local set_opts="$1";;
2364 -u)
2365 shift; local unset_opts="$1";;
2366 -c)
2367 shift; local cflags="-Werror -Wall -Wextra $1";;
2368 -l)
2369 shift; local ldflags="$1";;
2370 esac
2371 shift
2372 done
2373 set_opts="${set_opts:-}"
2374 unset_opts="${unset_opts:-}"
2375 cflags="${cflags:-}"
2376 ldflags="${ldflags:-}"
2377
2378 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
2379 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
2380
2381 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2382 make clean
2383 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
2384
2385 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2386 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2387 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2388 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2389 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2390 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2391 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
2392 not grep mbedtls_aesni_inverse_key ${BUILTIN_SRC_PATH}/aesni.o
2393
2394 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2395 make test
2396
2397 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2398 programs/test/selftest
2399}
2400
Ronald Cron66040472024-09-06 10:14:38 +02002401# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
2402config_block_cipher_no_decrypt () {
2403 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
2404 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2405 scripts/config.py unset MBEDTLS_NIST_KW_C
2406
2407 # Enable support for cryptographic mechanisms through the PSA API.
2408 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
Ronald Cron66040472024-09-06 10:14:38 +02002409 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
2410 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
2411 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
2412 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
Ronald Cron4153ebb2024-09-11 15:32:48 +02002413 # Note: The two unsets below are to be removed for Mbed TLS 4.0
Ronald Cron66040472024-09-06 10:14:38 +02002414 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2415 scripts/config.py unset MBEDTLS_DES_C
2416}
2417
2418component_test_block_cipher_no_decrypt_aesni () {
2419 # Test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics, AESNI assembly and
2420 # AES C implementation on x86_64 and with AESNI intrinsics on x86.
2421
2422 # This consistently causes an llvm crash on clang 3.8, so use gcc
2423 export CC=gcc
2424 config_block_cipher_no_decrypt
2425
Minos Galanakis471b34c2024-07-26 15:39:24 +01002426 # test AESNI intrinsics
2427 helper_block_cipher_no_decrypt_build_test \
2428 -s "MBEDTLS_AESNI_C" \
2429 -c "-mpclmul -msse2 -maes"
2430
2431 # test AESNI assembly
2432 helper_block_cipher_no_decrypt_build_test \
2433 -s "MBEDTLS_AESNI_C" \
2434 -c "-mno-pclmul -mno-sse2 -mno-aes"
2435
2436 # test AES C implementation
2437 helper_block_cipher_no_decrypt_build_test \
2438 -u "MBEDTLS_AESNI_C"
2439
2440 # test AESNI intrinsics for i386 target
2441 helper_block_cipher_no_decrypt_build_test \
2442 -s "MBEDTLS_AESNI_C" \
2443 -c "-m32 -mpclmul -msse2 -maes" \
2444 -l "-m32"
2445}
2446
Minos Galanakisf699d512024-08-01 11:32:30 +01002447support_test_block_cipher_no_decrypt_aesce_armcc () {
2448 support_build_armcc
2449}
2450
Minos Galanakis471b34c2024-07-26 15:39:24 +01002451component_test_block_cipher_no_decrypt_aesce_armcc () {
2452 scripts/config.py baremetal
2453
2454 # armc[56] don't support SHA-512 intrinsics
2455 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2456
2457 # Stop armclang warning about feature detection for A64_CRYPTO.
2458 # With this enabled, the library does build correctly under armclang,
2459 # but in baremetal builds (as tested here), feature detection is
2460 # unavailable, and the user is notified via a #warning. So enabling
2461 # this feature would prevent us from building with -Werror on
2462 # armclang. Tracked in #7198.
2463 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2464 scripts/config.py set MBEDTLS_HAVE_ASM
2465
Ronald Cron66040472024-09-06 10:14:38 +02002466 config_block_cipher_no_decrypt
Minos Galanakis471b34c2024-07-26 15:39:24 +01002467
2468 # test AESCE baremetal build
2469 scripts/config.py set MBEDTLS_AESCE_C
2470 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002471 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002472
2473 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2474 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2475 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2476 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2477 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2478 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2479 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
2480 not grep mbedtls_aesce_inverse_key ${BUILTIN_SRC_PATH}/aesce.o
2481 not grep aesce_decrypt_block ${BUILTIN_SRC_PATH}/aesce.o
2482}
2483
2484component_test_ctr_drbg_aes_256_sha_256 () {
2485 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2486 scripts/config.py full
2487 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2488 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
2489 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2490 make
2491
2492 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2493 make test
2494}
2495
2496component_test_ctr_drbg_aes_128_sha_512 () {
2497 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2498 scripts/config.py full
2499 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2500 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2501 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2502 make
2503
2504 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2505 make test
2506}
2507
2508component_test_ctr_drbg_aes_128_sha_256 () {
2509 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2510 scripts/config.py full
2511 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2512 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2513 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
2514 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2515 make
2516
2517 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2518 make test
2519}
2520
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002521component_test_full_static_keystore () {
2522 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2523 scripts/config.py full
2524 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2525 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
2526
2527 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2528 make test
2529}
2530
Minos Galanakis471b34c2024-07-26 15:39:24 +01002531component_test_psa_crypto_drivers () {
Ronald Crona0afbfb2024-10-15 13:20:31 +02002532 # Test dispatch to drivers and fallbacks with
2533 # test_suite_psa_crypto_driver_wrappers test suite. The test drivers that
2534 # are wrappers around the builtin drivers are activated by
2535 # PSA_CRYPTO_DRIVER_TEST.
2536 #
2537 # For the time being, some test cases in test_suite_block_cipher and
2538 # test_suite_md.psa rely on this component to be run at least once by the
2539 # CI. This should disappear as we progress the 4.x work. See
2540 # config_adjust_test_accelerators.h for more information.
Minos Galanakis471b34c2024-07-26 15:39:24 +01002541 msg "build: full + test drivers dispatching to builtins"
2542 scripts/config.py full
Ronald Cron67cc6a72024-10-14 10:55:24 +02002543 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_CONFIG_ADJUST_TEST_ACCELERATORS"
David Horstmann5b93d972024-10-31 15:36:05 +00002544 loc_cflags="${loc_cflags} -I../framework/tests/include"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002545
2546 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
2547
2548 msg "test: full + test drivers dispatching to builtins"
2549 make test
2550}
2551
2552component_build_psa_config_file () {
Minos Galanakis4f619e12024-11-14 14:56:47 +00002553 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002554 cp "$CRYPTO_CONFIG_H" psa_test_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002555 echo '#error "TF_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
2556 make CFLAGS="-I '$PWD' -DTF_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002557 # Make sure this feature is enabled. We'll disable it in the next phase.
2558 programs/test/query_compile_time_config MBEDTLS_CMAC_C
2559 make clean
2560
Minos Galanakis4f619e12024-11-14 14:56:47 +00002561 msg "build: make with TF_PSA_CRYPTO_CONFIG_FILE + TF_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
Minos Galanakis471b34c2024-07-26 15:39:24 +01002562 # In the user config, disable one feature and its dependencies, which will
2563 # reflect on the mbedtls configuration so we can query it with
2564 # query_compile_time_config.
2565 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
2566 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
Minos Galanakisaa2f12c2024-10-22 15:31:07 +01002567 echo '#undef MBEDTLS_CMAC_C' >> psa_user_config.h
Minos Galanakis4f619e12024-11-14 14:56:47 +00002568 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 +01002569 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
2570
2571 rm -f psa_test_config.h psa_user_config.h
2572}
2573
2574component_build_psa_alt_headers () {
2575 msg "build: make with PSA alt headers" # ~20s
2576
2577 # Generate alternative versions of the substitutable headers with the
2578 # same content except different include guards.
David Horstmanndc459512024-11-07 17:08:11 +00002579 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 +01002580
2581 # Build the library and some programs.
2582 # Don't build the fuzzers to avoid having to go through hoops to set
2583 # a correct include path for programs/fuzz/Makefile.
David Horstmann5b93d972024-10-31 15:36:05 +00002584 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
2585 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 +01002586
2587 # Check that we're getting the alternative include guards and not the
2588 # original include guards.
2589 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
2590 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
2591 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
2592 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
2593}
2594
2595component_test_min_mpi_window_size () {
2596 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
2597 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
2598 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2599 make
2600
2601 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2602 make test
2603}