blob: ae470deafa725d85346dbbed2a8df5238249f161 [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
38
Valerio Setti13aadd72024-08-13 13:13:23 +020039 msg "test: crypto full + MBEDTLS_PSA_STATIC_KEY_SLOTS"
Valerio Settidbb646b2024-06-20 14:40:54 +020040 make test
41}
42
Minos Galanakis471b34c2024-07-26 15:39:24 +010043# check_renamed_symbols HEADER LIB
44# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
Minos Galanakis609f7492024-07-31 16:39:28 +010045# name in LIB.
Minos Galanakis471b34c2024-07-26 15:39:24 +010046check_renamed_symbols () {
47 ! nm "$2" | sed 's/.* //' |
48 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
49}
50
51component_build_psa_crypto_spm () {
52 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
53 scripts/config.py full
54 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
55 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
56 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
57 # We can only compile, not link, since our test and sample programs
58 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
59 # is active.
60 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
61
62 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
63 # version is not present.
64 echo "Checking for renamed symbols in the library"
65 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
66}
67
Valerio Settia47b0452024-06-25 18:31:36 +020068# The goal of this component is to build a configuration where:
69# - test code and libtestdriver1 can make use of calloc/free and
70# - core library (including PSA core) cannot use calloc/free.
71component_test_psa_crypto_without_heap() {
Valerio Setti13aadd72024-08-13 13:13:23 +020072 msg "crypto without heap: build libtestdriver1"
Valerio Settia47b0452024-06-25 18:31:36 +020073 # Disable PSA features that cannot be accelerated and whose builtin support
74 # requires calloc/free.
75 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Valerio Setti13aadd72024-08-13 13:13:23 +020076 scripts/config.py -f $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_HKDF"
77 scripts/config.py -f $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_PBKDF2_"
78 scripts/config.py -f $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_TLS12_"
Valerio Settia47b0452024-06-25 18:31:36 +020079 # RSA key support requires ASN1 parse/write support for testing, but ASN1
80 # is disabled below.
Valerio Setti13aadd72024-08-13 13:13:23 +020081 scripts/config.py -f $CRYPTO_CONFIG_H unset-all "^PSA_WANT_KEY_TYPE_RSA_"
82 scripts/config.py -f $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_RSA_"
Valerio Settia47b0452024-06-25 18:31:36 +020083 # DES requires built-in support for key generation (parity check) so it
84 # cannot be accelerated
85 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
86 # EC-JPAKE use calloc/free in PSA core
87 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE
88
89 # Accelerate all PSA features (which are still enabled in CRYPTO_CONFIG_H).
90 PSA_SYM_LIST=$(./scripts/config.py -f $CRYPTO_CONFIG_H get-all-enabled PSA_WANT)
91 loc_accel_list=$(echo $PSA_SYM_LIST | sed 's/PSA_WANT_//g')
92
Valerio Settia47b0452024-06-25 18:31:36 +020093 helper_libtestdriver1_adjust_config crypto
94 helper_libtestdriver1_make_drivers "$loc_accel_list"
95
Valerio Setti13aadd72024-08-13 13:13:23 +020096 msg "crypto without heap: build main library"
Valerio Settia47b0452024-06-25 18:31:36 +020097 # Enable fully-static key slots in PSA core.
98 scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOTS
99 # Prevent PSA core from creating a copy of input/output buffers
100 scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
101 # Prevent PSA core from using CTR-DRBG or HMAC-DRBG for random generation.
102 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Valerio Setti13aadd72024-08-13 13:13:23 +0200103 # Set calloc/free as null pointer functions. Calling them would crash
Valerio Settia47b0452024-06-25 18:31:36 +0200104 # the program so we can use this as a "sentinel" for being sure no module
105 # is making use of these functions in the library.
106 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
107 scripts/config.py set MBEDTLS_PLATFORM_STD_CALLOC NULL
108 scripts/config.py set MBEDTLS_PLATFORM_STD_FREE NULL
109
Valerio Setti13aadd72024-08-13 13:13:23 +0200110 # Disable all the modules/features that use calloc directly
Valerio Settia47b0452024-06-25 18:31:36 +0200111 scripts/config.py unset-all MBEDTLS_ASN1_
112 scripts/config.py unset MBEDTLS_BIGNUM_C
113 scripts/config.py unset MBEDTLS_CIPHER_C
114 scripts/config.py unset MBEDTLS_CMAC_C
115 scripts/config.py unset MBEDTLS_DHM_C
116 scripts/config.py unset MBEDTLS_ECDSA_C
117 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
118 scripts/config.py unset MBEDTLS_ECP_C
Valerio Setti13aadd72024-08-13 13:13:23 +0200119 scripts/config.py unset-all "^MBEDTLS_LMS_"
Valerio Settia47b0452024-06-25 18:31:36 +0200120 scripts/config.py unset MBEDTLS_MD_C
121 scripts/config.py unset MBEDTLS_OID_C
Valerio Setti13aadd72024-08-13 13:13:23 +0200122 scripts/config.py unset-all "^MBEDTLS_PEM_"
Valerio Settia47b0452024-06-25 18:31:36 +0200123 scripts/config.py unset MBEDTLS_PKCS7_C
Valerio Setti13aadd72024-08-13 13:13:23 +0200124 scripts/config.py unset-all "^MBEDTLS_PK_"
Valerio Settia47b0452024-06-25 18:31:36 +0200125 scripts/config.py unset MBEDTLS_RSA_C
126 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
127 # Disable all modules that depend on the the previous ones
128 scripts/config.py unset MBEDTLS_NIST_KW_C
129 scripts/config.py unset MBEDTLS_ECDH_C
130 scripts/config.py unset MBEDTLS_ECJPAKE_C
Valerio Setti13aadd72024-08-13 13:13:23 +0200131 scripts/config.py unset-all "^MBEDTLS_PKCS1_"
132 scripts/config.py unset-all "^MBEDTLS_ENTROPY_"
133 scripts/config.py unset-all "^MBEDTLS_SHA"
Valerio Settia47b0452024-06-25 18:31:36 +0200134 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
135 scripts/config.py unset MBEDTLS_HKDF_C
136 scripts/config.py unset MBEDTLS_PKCS5_C
137 scripts/config.py unset MBEDTLS_PKCS12_C
138 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
139 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
140 helper_libtestdriver1_make_main "$loc_accel_list" lib
141
Valerio Setti13aadd72024-08-13 13:13:23 +0200142 msg "crypto without heap: build test suites and helpers"
143 # Reset calloc/free functions to normal operations so that test code can
Valerio Settia47b0452024-06-25 18:31:36 +0200144 # freely use them.
145 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
146 scripts/config.py unset MBEDTLS_PLATFORM_STD_CALLOC
147 scripts/config.py unset MBEDTLS_PLATFORM_STD_FREE
148 helper_libtestdriver1_make_main "$loc_accel_list" tests
149
Valerio Setti13aadd72024-08-13 13:13:23 +0200150 msg "crypto without heap: test"
Valerio Settia47b0452024-06-25 18:31:36 +0200151 make test
152}
153
Minos Galanakisf78447f2024-07-26 20:49:51 +0100154component_test_no_rsa_key_pair_generation () {
Minos Galanakisdc0f73a2024-07-26 20:41:42 +0100155 msg "build: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
156 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
157 scripts/config.py unset MBEDTLS_GENPRIME
158 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
159 make
160
161 msg "test: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
162 make test
163}
164
Minos Galanakisc06fd302024-08-01 12:16:59 +0100165component_test_no_pem_no_fs () {
166 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
167 scripts/config.py unset MBEDTLS_PEM_PARSE_C
168 scripts/config.py unset MBEDTLS_FS_IO
169 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
170 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
171 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
172 make
173
174 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
175 make test
176
177 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
178 tests/ssl-opt.sh
179}
180
181component_test_rsa_no_crt () {
182 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
183 scripts/config.py set MBEDTLS_RSA_NO_CRT
184 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
185 make
186
187 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
188 make test
189
190 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
191 tests/ssl-opt.sh -f RSA
192
193 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
194 tests/compat.sh -t RSA
195
196 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
197 tests/context-info.sh
198}
199
200component_test_no_ctr_drbg_classic () {
201 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
202 scripts/config.py full
203 scripts/config.py unset MBEDTLS_CTR_DRBG_C
204 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
205 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
206
207 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
208 make
209
210 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
211 make test
212
213 # In this configuration, the TLS test programs use HMAC_DRBG.
214 # The SSL tests are slow, so run a small subset, just enough to get
215 # confidence that the SSL code copes with HMAC_DRBG.
216 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
217 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
218
219 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
220 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
221}
222
223component_test_no_ctr_drbg_use_psa () {
224 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
225 scripts/config.py full
226 scripts/config.py unset MBEDTLS_CTR_DRBG_C
227 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
228
229 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
230 make
231
232 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
233 make test
234
235 # In this configuration, the TLS test programs use HMAC_DRBG.
236 # The SSL tests are slow, so run a small subset, just enough to get
237 # confidence that the SSL code copes with HMAC_DRBG.
238 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
239 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
240
241 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
242 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
243}
244
245component_test_no_hmac_drbg_classic () {
246 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
247 scripts/config.py full
248 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
249 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
250 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
251 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
252
253 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
254 make
255
256 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
257 make test
258
259 # Normally our ECDSA implementation uses deterministic ECDSA. But since
260 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
261 # instead.
262 # Test SSL with non-deterministic ECDSA. Only test features that
263 # might be affected by how ECDSA signature is performed.
264 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
265 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
266
267 # To save time, only test one protocol version, since this part of
268 # the protocol is identical in (D)TLS up to 1.2.
269 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
270 tests/compat.sh -m tls12 -t 'ECDSA'
271}
272
273component_test_no_hmac_drbg_use_psa () {
274 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
275 scripts/config.py full
276 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
277 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
278 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
279
280 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
281 make
282
283 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
284 make test
285
286 # Normally our ECDSA implementation uses deterministic ECDSA. But since
287 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
288 # instead.
289 # Test SSL with non-deterministic ECDSA. Only test features that
290 # might be affected by how ECDSA signature is performed.
291 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
292 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
293
294 # To save time, only test one protocol version, since this part of
295 # the protocol is identical in (D)TLS up to 1.2.
296 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
297 tests/compat.sh -m tls12 -t 'ECDSA'
298}
299
300component_test_psa_external_rng_no_drbg_classic () {
301 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
302 scripts/config.py full
303 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
304 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
305 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
306 scripts/config.py unset MBEDTLS_ENTROPY_C
307 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
308 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
309 scripts/config.py unset MBEDTLS_CTR_DRBG_C
310 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
311 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
312 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
313 # the SSL test programs don't have an RNG and can't work. Explicitly
314 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
315 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
316
317 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
318 make test
319
320 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
321 tests/ssl-opt.sh -f 'Default'
322}
323
324component_test_psa_external_rng_no_drbg_use_psa () {
325 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
326 scripts/config.py full
327 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
328 scripts/config.py unset MBEDTLS_ENTROPY_C
329 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
330 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
331 scripts/config.py unset MBEDTLS_CTR_DRBG_C
332 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
333 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
334 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
335
336 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
337 make test
338
339 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
340 tests/ssl-opt.sh -f 'Default\|opaque'
341}
342
Minos Galanakis471b34c2024-07-26 15:39:24 +0100343component_test_psa_external_rng_use_psa_crypto () {
344 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
345 scripts/config.py full
346 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
347 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
348 scripts/config.py unset MBEDTLS_CTR_DRBG_C
349 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
350
351 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
352 make test
353
354 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
355 tests/ssl-opt.sh -f 'Default\|opaque'
356}
357
358component_test_psa_inject_entropy () {
359 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
360 scripts/config.py full
361 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
362 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
363 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
364 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
365 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
366 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
367 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
368
369 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
370 make test
371}
372
Minos Galanakisf78447f2024-07-26 20:49:51 +0100373component_full_no_pkparse_pkwrite () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100374 msg "build: full without pkparse and pkwrite"
375
376 scripts/config.py crypto_full
377 scripts/config.py unset MBEDTLS_PK_PARSE_C
378 scripts/config.py unset MBEDTLS_PK_WRITE_C
379
380 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
381
382 # Ensure that PK_[PARSE|WRITE]_C were not re-enabled accidentally (additive config).
383 not grep mbedtls_pk_parse_key ${BUILTIN_SRC_PATH}/pkparse.o
384 not grep mbedtls_pk_write_key_der ${BUILTIN_SRC_PATH}/pkwrite.o
385
386 msg "test: full without pkparse and pkwrite"
387 make test
388}
389
390component_test_crypto_full_md_light_only () {
391 msg "build: crypto_full with only the light subset of MD"
392 scripts/config.py crypto_full
393
394 # Disable MD
395 scripts/config.py unset MBEDTLS_MD_C
396 # Disable direct dependencies of MD_C
397 scripts/config.py unset MBEDTLS_HKDF_C
398 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
399 scripts/config.py unset MBEDTLS_PKCS7_C
400 # Disable indirect dependencies of MD_C
401 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG
402 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
403 # Disable things that would auto-enable MD_C
404 scripts/config.py unset MBEDTLS_PKCS5_C
405
406 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
407 # which we haven't disabled, so no need to explicitly enable it.
408 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
409
410 # Make sure we don't have the HMAC functions, but the hashing functions
411 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
412 grep mbedtls_md ${BUILTIN_SRC_PATH}/md.o
413
414 msg "test: crypto_full with only the light subset of MD"
415 make test
416}
417
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100418component_test_full_no_cipher () {
419 msg "build: full no CIPHER"
420
421 scripts/config.py full
422 scripts/config.py unset MBEDTLS_CIPHER_C
423
424 # The built-in implementation of the following algs/key-types depends
425 # on CIPHER_C so we disable them.
426 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
427 # so we keep them enabled.
428 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
429 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CMAC
430 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
431 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
432 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CFB
433 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CTR
434 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
435 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_OFB
436 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
437 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_STREAM_CIPHER
438 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
439
440 # The following modules directly depends on CIPHER_C
441 scripts/config.py unset MBEDTLS_CMAC_C
442 scripts/config.py unset MBEDTLS_NIST_KW_C
443
444 make
445
446 # Ensure that CIPHER_C was not re-enabled
447 not grep mbedtls_cipher_init ${BUILTIN_SRC_PATH}/cipher.o
448
449 msg "test: full no CIPHER"
450 make test
451}
452
Minos Galanakisf78447f2024-07-26 20:49:51 +0100453component_test_full_no_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100454 msg "build: full no PSA_WANT_ALG_CCM"
455
456 # Full config enables:
457 # - USE_PSA_CRYPTO so that TLS code dispatches cipher/AEAD to PSA
458 # - CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
459 scripts/config.py full
460
461 # Disable PSA_WANT_ALG_CCM so that CCM is not supported in PSA. CCM_C is still
462 # enabled, but not used from TLS since USE_PSA is set.
463 # This is helpful to ensure that TLS tests below have proper dependencies.
464 #
465 # Note: also PSA_WANT_ALG_CCM_STAR_NO_TAG is enabled, but it does not cause
466 # PSA_WANT_ALG_CCM to be re-enabled.
467 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM
468
469 make
470
471 msg "test: full no PSA_WANT_ALG_CCM"
472 make test
473}
474
Minos Galanakisf78447f2024-07-26 20:49:51 +0100475component_test_full_no_ccm_star_no_tag () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100476 msg "build: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
477
478 # Full config enables CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
479 scripts/config.py full
480
481 # Disable CCM_STAR_NO_TAG, which is the target of this test, as well as all
482 # other components that enable MBEDTLS_PSA_BUILTIN_CIPHER internal symbol.
483 # This basically disables all unauthenticated ciphers on the PSA side, while
484 # keeping AEADs enabled.
485 #
486 # Note: PSA_WANT_ALG_CCM is enabled, but it does not cause
487 # PSA_WANT_ALG_CCM_STAR_NO_TAG to be re-enabled.
488 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
489 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_STREAM_CIPHER
490 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
491 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
492 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
493 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
494 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
495 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
496
497 make
498
499 # Ensure MBEDTLS_PSA_BUILTIN_CIPHER was not enabled
500 not grep mbedtls_psa_cipher ${PSA_CORE_PATH}/psa_crypto_cipher.o
501
502 msg "test: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
503 make test
504}
505
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200506component_test_config_symmetric_only () {
507 msg "build: configs/config-symmetric-only.h"
Gilles Peskineaf5a8992024-09-14 11:27:44 +0200508 cp configs/config-symmetric-only.h "$CONFIG_H"
Gilles Peskineaf5a8992024-09-14 11:27:44 +0200509 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
510 # want to re-generate generated files that depend on it, quite correctly.
511 # However this doesn't work as the generation script expects a specific
512 # format for mbedtls_config.h, which the other files don't follow. Also,
513 # cmake can't know this, but re-generation is actually not necessary as
514 # the generated files only depend on the list of available options, not
515 # whether they're on or off. So, disable cmake's (over-sensitive here)
516 # dependency resolution for generated files and just rely on them being
517 # present (thanks to pre_generate_files) by turning GEN_FILES off.
518 CC=$ASAN_CC cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
519 make
520
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200521 msg "test: configs/config-symmetric-only.h - unit tests"
Gilles Peskineaf5a8992024-09-14 11:27:44 +0200522 make test
523}
524
Minos Galanakisc06fd302024-08-01 12:16:59 +0100525component_test_everest () {
526 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
527 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
528 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
529 make
530
531 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
532 make test
533
534 msg "test: metatests (clang, ASan)"
535 tests/scripts/run-metatests.sh any asan poison
536
537 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
538 tests/ssl-opt.sh -f ECDH
539
540 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
541 # Exclude some symmetric ciphers that are redundant here to gain time.
542 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
543}
544
545component_test_everest_curve25519_only () {
546 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
547 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
548 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
549 scripts/config.py unset MBEDTLS_ECDSA_C
550 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
551 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECDSA
552 scripts/config.py -f $CRYPTO_CONFIG_H set PSA_WANT_ALG_ECDH
553 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
554 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
555 scripts/config.py unset MBEDTLS_ECJPAKE_C
556 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE
557
558 # Disable all curves
559 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
560 scripts/config.py -f $CRYPTO_CONFIG_H unset-all "PSA_WANT_ECC_[0-9A-Z_a-z]*$"
561 scripts/config.py -f $CRYPTO_CONFIG_H set PSA_WANT_ECC_MONTGOMERY_255
562
563 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
564
565 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
566 make test
567}
568
Minos Galanakis471b34c2024-07-26 15:39:24 +0100569component_test_psa_collect_statuses () {
570 msg "build+test: psa_collect_statuses" # ~30s
571 scripts/config.py full
572 tests/scripts/psa_collect_statuses.py
573 # Check that psa_crypto_init() succeeded at least once
574 grep -q '^0:psa_crypto_init:' tests/statuses.log
575 rm -f tests/statuses.log
576}
577
578# Check that the specified libraries exist and are empty.
579are_empty_libraries () {
580 nm "$@" >/dev/null 2>/dev/null
581 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
582}
583
584component_build_crypto_default () {
585 msg "build: make, crypto only"
586 scripts/config.py crypto
587 make CFLAGS='-O1 -Werror'
588 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
589}
590
591component_build_crypto_full () {
592 msg "build: make, crypto only, full config"
593 scripts/config.py crypto_full
594 make CFLAGS='-O1 -Werror'
595 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
596}
597
598component_test_crypto_for_psa_service () {
599 msg "build: make, config for PSA crypto service"
600 scripts/config.py crypto
601 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
602 # Disable things that are not needed for just cryptography, to
603 # reach a configuration that would be typical for a PSA cryptography
604 # service providing all implemented PSA algorithms.
605 # System stuff
606 scripts/config.py unset MBEDTLS_ERROR_C
607 scripts/config.py unset MBEDTLS_TIMING_C
608 scripts/config.py unset MBEDTLS_VERSION_FEATURES
609 # Crypto stuff with no PSA interface
610 scripts/config.py unset MBEDTLS_BASE64_C
611 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
612 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
613 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
614 scripts/config.py unset MBEDTLS_NIST_KW_C
615 scripts/config.py unset MBEDTLS_PEM_PARSE_C
616 scripts/config.py unset MBEDTLS_PEM_WRITE_C
617 scripts/config.py unset MBEDTLS_PKCS12_C
618 scripts/config.py unset MBEDTLS_PKCS5_C
619 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
620 # in PSA code to work with RSA keys. We don't require users to set those:
621 # they will be reenabled in build_info.h.
622 scripts/config.py unset MBEDTLS_PK_C
623 scripts/config.py unset MBEDTLS_PK_PARSE_C
624 scripts/config.py unset MBEDTLS_PK_WRITE_C
625 make CFLAGS='-O1 -Werror' all test
626 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
627}
628
629component_build_crypto_baremetal () {
630 msg "build: make, crypto only, baremetal config"
631 scripts/config.py crypto_baremetal
632 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
633 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
634}
635
636support_build_crypto_baremetal () {
637 support_build_baremetal "$@"
638}
639
640# depends.py family of tests
641component_test_depends_py_cipher_id () {
642 msg "test/build: depends.py cipher_id (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200643 tests/scripts/depends.py cipher_id
Minos Galanakis471b34c2024-07-26 15:39:24 +0100644}
645
646component_test_depends_py_cipher_chaining () {
647 msg "test/build: depends.py cipher_chaining (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200648 tests/scripts/depends.py cipher_chaining
Minos Galanakis471b34c2024-07-26 15:39:24 +0100649}
650
651component_test_depends_py_cipher_padding () {
652 msg "test/build: depends.py cipher_padding (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200653 tests/scripts/depends.py cipher_padding
Minos Galanakis471b34c2024-07-26 15:39:24 +0100654}
655
656component_test_depends_py_curves () {
657 msg "test/build: depends.py curves (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200658 tests/scripts/depends.py curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100659}
660
661component_test_depends_py_hashes () {
662 msg "test/build: depends.py hashes (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200663 tests/scripts/depends.py hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +0100664}
665
Minos Galanakis471b34c2024-07-26 15:39:24 +0100666component_test_depends_py_pkalgs () {
667 msg "test/build: depends.py pkalgs (gcc)"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100668 tests/scripts/depends.py pkalgs
669}
670
671component_test_psa_crypto_config_ffdh_2048_only () {
672 msg "build: full config - only DH 2048"
673
674 scripts/config.py full
675
676 # Disable all DH groups other than 2048.
677 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_3072
678 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_4096
679 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_6144
680 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_8192
681
682 make CFLAGS="$ASAN_CFLAGS -Werror" LDFLAGS="$ASAN_CFLAGS"
683
684 msg "test: full config - only DH 2048"
685 make test
686
687 msg "ssl-opt: full config - only DH 2048"
688 tests/ssl-opt.sh -f "ffdh"
689}
690
691component_build_no_pk_rsa_alt_support () {
692 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
693
694 scripts/config.py full
695 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
696 scripts/config.py set MBEDTLS_RSA_C
697 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
698
699 # Only compile - this is primarily to test for compile issues
700 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
701}
702
703component_build_module_alt () {
704 msg "build: MBEDTLS_XXX_ALT" # ~30s
705 scripts/config.py full
706
707 # Disable options that are incompatible with some ALT implementations:
708 # aesni.c references mbedtls_aes_context fields directly.
709 scripts/config.py unset MBEDTLS_AESNI_C
710 scripts/config.py unset MBEDTLS_AESCE_C
711 # MBEDTLS_ECP_RESTARTABLE is documented as incompatible.
712 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
713 # You can only have one threading implementation: alt or pthread, not both.
714 scripts/config.py unset MBEDTLS_THREADING_PTHREAD
715 # The SpecifiedECDomain parsing code accesses mbedtls_ecp_group fields
716 # directly and assumes the implementation works with partial groups.
717 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
718 # MBEDTLS_SHA256_*ALT can't be used with MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*
719 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
720 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
721 # MBEDTLS_SHA512_*ALT can't be used with MBEDTLS_SHA512_USE_A64_CRYPTO_*
722 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
723 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
724
725 # Enable all MBEDTLS_XXX_ALT for whole modules. Do not enable
726 # MBEDTLS_XXX_YYY_ALT which are for single functions.
727 scripts/config.py set-all 'MBEDTLS_([A-Z0-9]*|NIST_KW)_ALT'
728
729 # We can only compile, not link, since we don't have any implementations
730 # suitable for testing with the dummy alt headers.
731 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
732}
733
734component_test_psa_crypto_config_accel_ecdsa () {
735 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
736
737 # Algorithms and key types to accelerate
738 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
739 $(helper_get_psa_key_type_list "ECC") \
740 $(helper_get_psa_curve_list)"
741
742 # Configure
743 # ---------
744
Elena Uziunaite91d83862024-09-04 14:51:31 +0100745 # Start from default config + TLS 1.3
Minos Galanakis471b34c2024-07-26 15:39:24 +0100746 helper_libtestdriver1_adjust_config "default"
747
Elena Uziunaite91d83862024-09-04 14:51:31 +0100748 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
749
Minos Galanakis471b34c2024-07-26 15:39:24 +0100750 # Disable the module that's accelerated
751 scripts/config.py unset MBEDTLS_ECDSA_C
752
753 # Disable things that depend on it
754 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
755 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
756
757 # Build
758 # -----
759
760 # These hashes are needed for some ECDSA signature tests.
Elena Uziunaiteffce45c2024-09-12 14:58:52 +0100761 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 +0100762 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
763
764 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
765
766 helper_libtestdriver1_make_main "$loc_accel_list"
767
768 # Make sure this was not re-enabled by accident (additive config)
769 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
770
771 # Run the tests
772 # -------------
773
774 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
775 make test
776}
777
778component_test_psa_crypto_config_accel_ecdh () {
779 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
780
781 # Algorithms and key types to accelerate
782 loc_accel_list="ALG_ECDH \
783 $(helper_get_psa_key_type_list "ECC") \
784 $(helper_get_psa_curve_list)"
785
786 # Configure
787 # ---------
788
789 # Start from default config (no USE_PSA)
790 helper_libtestdriver1_adjust_config "default"
791
792 # Disable the module that's accelerated
793 scripts/config.py unset MBEDTLS_ECDH_C
794
795 # Disable things that depend on it
796 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
797 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
798 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
799 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
800 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
801
802 # Build
803 # -----
804
805 helper_libtestdriver1_make_drivers "$loc_accel_list"
806
807 helper_libtestdriver1_make_main "$loc_accel_list"
808
809 # Make sure this was not re-enabled by accident (additive config)
810 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
811
812 # Run the tests
813 # -------------
814
815 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
816 make test
817}
818
819component_test_psa_crypto_config_accel_ffdh () {
820 msg "build: full with accelerated FFDH"
821
822 # Algorithms and key types to accelerate
823 loc_accel_list="ALG_FFDH \
824 $(helper_get_psa_key_type_list "DH") \
825 $(helper_get_psa_dh_group_list)"
826
827 # Configure
828 # ---------
829
830 # start with full (USE_PSA and TLS 1.3)
831 helper_libtestdriver1_adjust_config "full"
832
833 # Disable the module that's accelerated
834 scripts/config.py unset MBEDTLS_DHM_C
835
836 # Disable things that depend on it
837 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
838 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
839
840 # Build
841 # -----
842
843 helper_libtestdriver1_make_drivers "$loc_accel_list"
844
845 helper_libtestdriver1_make_main "$loc_accel_list"
846
847 # Make sure this was not re-enabled by accident (additive config)
848 not grep mbedtls_dhm_ ${BUILTIN_SRC_PATH}/dhm.o
849
850 # Run the tests
851 # -------------
852
853 msg "test: full with accelerated FFDH"
854 make test
855
856 msg "ssl-opt: full with accelerated FFDH alg"
857 tests/ssl-opt.sh -f "ffdh"
858}
859
860component_test_psa_crypto_config_reference_ffdh () {
861 msg "build: full with non-accelerated FFDH"
862
863 # Start with full (USE_PSA and TLS 1.3)
864 helper_libtestdriver1_adjust_config "full"
865
866 # Disable things that are not supported
867 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
868 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
869 make
870
871 msg "test suites: full with non-accelerated FFDH alg"
872 make test
873
874 msg "ssl-opt: full with non-accelerated FFDH alg"
875 tests/ssl-opt.sh -f "ffdh"
876}
877
Minos Galanakisf78447f2024-07-26 20:49:51 +0100878component_test_psa_crypto_config_accel_pake () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100879 msg "build: full with accelerated PAKE"
880
881 loc_accel_list="ALG_JPAKE \
882 $(helper_get_psa_key_type_list "ECC") \
883 $(helper_get_psa_curve_list)"
884
885 # Configure
886 # ---------
887
888 helper_libtestdriver1_adjust_config "full"
889
890 # Make built-in fallback not available
891 scripts/config.py unset MBEDTLS_ECJPAKE_C
892 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
893
894 # Build
895 # -----
896
897 helper_libtestdriver1_make_drivers "$loc_accel_list"
898
899 helper_libtestdriver1_make_main "$loc_accel_list"
900
901 # Make sure this was not re-enabled by accident (additive config)
902 not grep mbedtls_ecjpake_init ${BUILTIN_SRC_PATH}/ecjpake.o
903
904 # Run the tests
905 # -------------
906
907 msg "test: full with accelerated PAKE"
908 make test
909}
910
911component_test_psa_crypto_config_accel_ecc_some_key_types () {
912 msg "build: full with accelerated EC algs and some key types"
913
914 # Algorithms and key types to accelerate
915 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
916 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
917 ALG_ECDH \
918 ALG_JPAKE \
919 KEY_TYPE_ECC_PUBLIC_KEY \
920 KEY_TYPE_ECC_KEY_PAIR_BASIC \
921 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
922 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
923 $(helper_get_psa_curve_list)"
924
925 # Configure
926 # ---------
927
928 # start with config full for maximum coverage (also enables USE_PSA)
929 helper_libtestdriver1_adjust_config "full"
930
931 # Disable modules that are accelerated - some will be re-enabled
932 scripts/config.py unset MBEDTLS_ECDSA_C
933 scripts/config.py unset MBEDTLS_ECDH_C
934 scripts/config.py unset MBEDTLS_ECJPAKE_C
935 scripts/config.py unset MBEDTLS_ECP_C
936
937 # Disable all curves - those that aren't accelerated should be re-enabled
938 helper_disable_builtin_curves
939
940 # Restartable feature is not yet supported by PSA. Once it will in
941 # the future, the following line could be removed (see issues
942 # 6061, 6332 and following ones)
943 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
944
945 # this is not supported by the driver API yet
946 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
947
948 # Build
949 # -----
950
951 # These hashes are needed for some ECDSA signature tests.
952 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
953 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
954 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
955
956 helper_libtestdriver1_make_main "$loc_accel_list"
957
958 # ECP should be re-enabled but not the others
959 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
960 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
961 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
962 grep mbedtls_ecp ${BUILTIN_SRC_PATH}/ecp.o
963
964 # Run the tests
965 # -------------
966
967 msg "test suites: full with accelerated EC algs and some key types"
968 make test
969}
970
971# Run tests with only (non-)Weierstrass accelerated
972# Common code used in:
973# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
974# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100975common_test_psa_crypto_config_accel_ecc_some_curves () {
976 weierstrass=$1
977 if [ $weierstrass -eq 1 ]; then
978 desc="Weierstrass"
979 else
980 desc="non-Weierstrass"
981 fi
982
983 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
984
985 # Note: Curves are handled in a special way by the libtestdriver machinery,
986 # so we only want to include them in the accel list when building the main
987 # libraries, hence the use of a separate variable.
988 # Note: the following loop is a modified version of
989 # helper_get_psa_curve_list that only keeps Weierstrass families.
990 loc_weierstrass_list=""
991 loc_non_weierstrass_list=""
992 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
993 case $item in
994 ECC_BRAINPOOL*|ECC_SECP*)
995 loc_weierstrass_list="$loc_weierstrass_list $item"
996 ;;
997 *)
998 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
999 ;;
1000 esac
1001 done
1002 if [ $weierstrass -eq 1 ]; then
1003 loc_curve_list=$loc_weierstrass_list
1004 else
1005 loc_curve_list=$loc_non_weierstrass_list
1006 fi
1007
1008 # Algorithms and key types to accelerate
1009 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1010 ALG_ECDH \
1011 ALG_JPAKE \
1012 $(helper_get_psa_key_type_list "ECC") \
1013 $loc_curve_list"
1014
1015 # Configure
1016 # ---------
1017
1018 # Start with config crypto_full and remove PK_C:
1019 # that's what's supported now, see docs/driver-only-builds.md.
1020 helper_libtestdriver1_adjust_config "crypto_full"
1021 scripts/config.py unset MBEDTLS_PK_C
1022 scripts/config.py unset MBEDTLS_PK_PARSE_C
1023 scripts/config.py unset MBEDTLS_PK_WRITE_C
1024
1025 # Disable modules that are accelerated - some will be re-enabled
1026 scripts/config.py unset MBEDTLS_ECDSA_C
1027 scripts/config.py unset MBEDTLS_ECDH_C
1028 scripts/config.py unset MBEDTLS_ECJPAKE_C
1029 scripts/config.py unset MBEDTLS_ECP_C
1030
1031 # Disable all curves - those that aren't accelerated should be re-enabled
1032 helper_disable_builtin_curves
1033
1034 # Restartable feature is not yet supported by PSA. Once it will in
1035 # the future, the following line could be removed (see issues
1036 # 6061, 6332 and following ones)
1037 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1038
1039 # this is not supported by the driver API yet
1040 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1041
1042 # Build
1043 # -----
1044
1045 # These hashes are needed for some ECDSA signature tests.
1046 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1047 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1048 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1049
1050 helper_libtestdriver1_make_main "$loc_accel_list"
1051
1052 # We expect ECDH to be re-enabled for the missing curves
1053 grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1054 # We expect ECP to be re-enabled, however the parts specific to the
1055 # families of curves that are accelerated should be ommited.
1056 # - functions with mxz in the name are specific to Montgomery curves
1057 # - ecp_muladd is specific to Weierstrass curves
1058 ##nm ${BUILTIN_SRC_PATH}/ecp.o | tee ecp.syms
1059 if [ $weierstrass -eq 1 ]; then
1060 not grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
1061 grep mxz ${BUILTIN_SRC_PATH}/ecp.o
1062 else
1063 grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
1064 not grep mxz ${BUILTIN_SRC_PATH}/ecp.o
1065 fi
1066 # We expect ECDSA and ECJPAKE to be re-enabled only when
1067 # Weierstrass curves are not accelerated
1068 if [ $weierstrass -eq 1 ]; then
1069 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
1070 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
1071 else
1072 grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
1073 grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
1074 fi
1075
1076 # Run the tests
1077 # -------------
1078
1079 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
1080 make test
1081}
1082
1083component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
1084 common_test_psa_crypto_config_accel_ecc_some_curves 1
1085}
1086
1087component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
1088 common_test_psa_crypto_config_accel_ecc_some_curves 0
1089}
1090
1091# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
1092# ECDH, ECDSA) with and without drivers.
1093# The input parameter is a boolean value which indicates:
1094# - 0 keep built-in EC algs,
1095# - 1 exclude built-in EC algs (driver only).
1096#
1097# This is used by the two following components to ensure they always use the
1098# same config, except for the use of driver or built-in EC algorithms:
1099# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
1100# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
1101# This supports comparing their test coverage with analyze_outcomes.py.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001102config_psa_crypto_config_ecp_light_only () {
1103 driver_only="$1"
1104 # start with config full for maximum coverage (also enables USE_PSA)
1105 helper_libtestdriver1_adjust_config "full"
1106 if [ "$driver_only" -eq 1 ]; then
1107 # Disable modules that are accelerated
1108 scripts/config.py unset MBEDTLS_ECDSA_C
1109 scripts/config.py unset MBEDTLS_ECDH_C
1110 scripts/config.py unset MBEDTLS_ECJPAKE_C
1111 scripts/config.py unset MBEDTLS_ECP_C
1112 fi
1113
1114 # Restartable feature is not yet supported by PSA. Once it will in
1115 # the future, the following line could be removed (see issues
1116 # 6061, 6332 and following ones)
1117 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1118}
1119
1120# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +01001121component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
1122 msg "build: full with accelerated EC algs"
1123
1124 # Algorithms and key types to accelerate
1125 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1126 ALG_ECDH \
1127 ALG_JPAKE \
1128 $(helper_get_psa_key_type_list "ECC") \
1129 $(helper_get_psa_curve_list)"
1130
1131 # Configure
1132 # ---------
1133
1134 # Use the same config as reference, only without built-in EC algs
1135 config_psa_crypto_config_ecp_light_only 1
1136
1137 # Do not disable builtin curves because that support is required for:
1138 # - MBEDTLS_PK_PARSE_EC_EXTENDED
1139 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
1140
1141 # Build
1142 # -----
1143
1144 # These hashes are needed for some ECDSA signature tests.
1145 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1146 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1147 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1148
1149 helper_libtestdriver1_make_main "$loc_accel_list"
1150
1151 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1152 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1153 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1154 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1155 not grep mbedtls_ecp_mul ${BUILTIN_SRC_PATH}/ecp.o
1156
1157 # Run the tests
1158 # -------------
1159
1160 msg "test suites: full with accelerated EC algs"
1161 make test
1162
1163 msg "ssl-opt: full with accelerated EC algs"
1164 tests/ssl-opt.sh
1165}
1166
1167# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +01001168component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
1169 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated EC algs"
1170
1171 config_psa_crypto_config_ecp_light_only 0
1172
1173 make
1174
1175 msg "test suites: full with non-accelerated EC algs"
1176 make test
1177
1178 msg "ssl-opt: full with non-accelerated EC algs"
1179 tests/ssl-opt.sh
1180}
1181
1182# This helper function is used by:
1183# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
1184# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
1185# to ensure that both tests use the same underlying configuration when testing
1186# driver's coverage with analyze_outcomes.py.
1187#
1188# This functions accepts 1 boolean parameter as follows:
1189# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
1190# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
1191# - 0: include built-in implementation of EC algorithms.
1192#
1193# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
1194# on the ECP module.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001195config_psa_crypto_no_ecp_at_all () {
1196 driver_only="$1"
1197 # start with full config for maximum coverage (also enables USE_PSA)
1198 helper_libtestdriver1_adjust_config "full"
1199
1200 if [ "$driver_only" -eq 1 ]; then
1201 # Disable modules that are accelerated
1202 scripts/config.py unset MBEDTLS_ECDSA_C
1203 scripts/config.py unset MBEDTLS_ECDH_C
1204 scripts/config.py unset MBEDTLS_ECJPAKE_C
1205 # Disable ECP module (entirely)
1206 scripts/config.py unset MBEDTLS_ECP_C
1207 fi
1208
1209 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1210 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1211 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1212 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1213
1214 # Restartable feature is not yet supported by PSA. Once it will in
1215 # the future, the following line could be removed (see issues
1216 # 6061, 6332 and following ones)
1217 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1218}
1219
1220# Build and test a configuration where driver accelerates all EC algs while
1221# all support and dependencies from ECP and ECP_LIGHT are removed on the library
1222# side.
1223#
1224# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001225component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
1226 msg "build: full + accelerated EC algs - ECP"
1227
1228 # Algorithms and key types to accelerate
1229 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1230 ALG_ECDH \
1231 ALG_JPAKE \
1232 $(helper_get_psa_key_type_list "ECC") \
1233 $(helper_get_psa_curve_list)"
1234
1235 # Configure
1236 # ---------
1237
1238 # Set common configurations between library's and driver's builds
1239 config_psa_crypto_no_ecp_at_all 1
1240 # Disable all the builtin curves. All the required algs are accelerated.
1241 helper_disable_builtin_curves
1242
1243 # Build
1244 # -----
1245
1246 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1247 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1248 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1249 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1250
1251 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1252
1253 helper_libtestdriver1_make_main "$loc_accel_list"
1254
1255 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1256 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1257 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1258 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1259 # Also ensure that ECP module was not re-enabled
1260 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1261
1262 # Run the tests
1263 # -------------
1264
1265 msg "test: full + accelerated EC algs - ECP"
1266 make test
1267
1268 msg "ssl-opt: full + accelerated EC algs - ECP"
1269 tests/ssl-opt.sh
1270}
1271
1272# Reference function used for driver's coverage analysis in analyze_outcomes.py
1273# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
1274# Keep in sync with its accelerated counterpart.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001275component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
1276 msg "build: full + non accelerated EC algs"
1277
1278 config_psa_crypto_no_ecp_at_all 0
1279
1280 make
1281
1282 msg "test: full + non accelerated EC algs"
1283 make test
1284
1285 msg "ssl-opt: full + non accelerated EC algs"
1286 tests/ssl-opt.sh
1287}
1288
1289# This is a common configuration helper used directly from:
1290# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1291# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1292# and indirectly from:
1293# - component_test_psa_crypto_config_accel_ecc_no_bignum
1294# - accelerate all EC algs, disable RSA and FFDH
1295# - component_test_psa_crypto_config_reference_ecc_no_bignum
1296# - this is the reference component of the above
1297# - it still disables RSA and FFDH, but it uses builtin EC algs
1298# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1299# - accelerate all EC and FFDH algs, disable only RSA
1300# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1301# - this is the reference component of the above
1302# - it still disables RSA, but it uses builtin EC and FFDH algs
1303#
1304# This function accepts 2 parameters:
1305# $1: a boolean value which states if we are testing an accelerated scenario
1306# or not.
1307# $2: a string value which states which components are tested. Allowed values
1308# are "ECC" or "ECC_DH".
Minos Galanakisf78447f2024-07-26 20:49:51 +01001309config_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001310 driver_only="$1"
1311 test_target="$2"
1312 # start with full config for maximum coverage (also enables USE_PSA)
1313 helper_libtestdriver1_adjust_config "full"
1314
1315 if [ "$driver_only" -eq 1 ]; then
1316 # Disable modules that are accelerated
1317 scripts/config.py unset MBEDTLS_ECDSA_C
1318 scripts/config.py unset MBEDTLS_ECDH_C
1319 scripts/config.py unset MBEDTLS_ECJPAKE_C
1320 # Disable ECP module (entirely)
1321 scripts/config.py unset MBEDTLS_ECP_C
1322 # Also disable bignum
1323 scripts/config.py unset MBEDTLS_BIGNUM_C
1324 fi
1325
1326 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1327 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1328 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1329 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1330
1331 # RSA support is intentionally disabled on this test because RSA_C depends
1332 # on BIGNUM_C.
1333 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
1334 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
1335 scripts/config.py unset MBEDTLS_RSA_C
1336 scripts/config.py unset MBEDTLS_PKCS1_V15
1337 scripts/config.py unset MBEDTLS_PKCS1_V21
1338 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1339 # Also disable key exchanges that depend on RSA
1340 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1341 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1342 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1343 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1344 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1345
1346 if [ "$test_target" = "ECC" ]; then
1347 # When testing ECC only, we disable FFDH support, both from builtin and
1348 # PSA sides, and also disable the key exchanges that depend on DHM.
1349 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_FFDH
1350 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
1351 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
1352 scripts/config.py unset MBEDTLS_DHM_C
1353 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1354 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1355 else
1356 # When testing ECC and DH instead, we disable DHM and depending key
1357 # exchanges only in the accelerated build
1358 if [ "$driver_only" -eq 1 ]; then
1359 scripts/config.py unset MBEDTLS_DHM_C
1360 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1361 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1362 fi
1363 fi
1364
1365 # Restartable feature is not yet supported by PSA. Once it will in
1366 # the future, the following line could be removed (see issues
1367 # 6061, 6332 and following ones)
1368 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1369}
1370
1371# Common helper used by:
1372# - component_test_psa_crypto_config_accel_ecc_no_bignum
1373# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1374#
1375# The goal is to build and test accelerating either:
1376# - ECC only or
1377# - both ECC and FFDH
1378#
1379# It is meant to be used in conjunction with
1380# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
1381# coverage analysis in the "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001382common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1383 test_target="$1"
1384
1385 # This is an internal helper to simplify text message handling
1386 if [ "$test_target" = "ECC_DH" ]; then
1387 accel_text="ECC/FFDH"
1388 removed_text="ECP - DH"
1389 else
1390 accel_text="ECC"
1391 removed_text="ECP"
1392 fi
1393
1394 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1395
1396 # By default we accelerate all EC keys/algs
1397 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1398 ALG_ECDH \
1399 ALG_JPAKE \
1400 $(helper_get_psa_key_type_list "ECC") \
1401 $(helper_get_psa_curve_list)"
1402 # Optionally we can also add DH to the list of accelerated items
1403 if [ "$test_target" = "ECC_DH" ]; then
1404 loc_accel_list="$loc_accel_list \
1405 ALG_FFDH \
1406 $(helper_get_psa_key_type_list "DH") \
1407 $(helper_get_psa_dh_group_list)"
1408 fi
1409
1410 # Configure
1411 # ---------
1412
1413 # Set common configurations between library's and driver's builds
1414 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
1415 # Disable all the builtin curves. All the required algs are accelerated.
1416 helper_disable_builtin_curves
1417
1418 # Build
1419 # -----
1420
1421 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1422 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1423 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1424 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1425
1426 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1427
1428 helper_libtestdriver1_make_main "$loc_accel_list"
1429
1430 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1431 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1432 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1433 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1434 # Also ensure that ECP, RSA, [DHM] or BIGNUM modules were not re-enabled
1435 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1436 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1437 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1438 not grep mbedtls_dhm_ ${BUILTIN_SRC_PATH}/dhm.o
1439
1440 # Run the tests
1441 # -------------
1442
1443 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - DHM - BIGNUM"
1444
1445 make test
1446
1447 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1448 tests/ssl-opt.sh
1449}
1450
1451# Common helper used by:
1452# - component_test_psa_crypto_config_reference_ecc_no_bignum
1453# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1454#
1455# The goal is to build and test a reference scenario (i.e. with builtin
1456# components) compared to the ones used in
1457# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
1458#
1459# It is meant to be used in conjunction with
1460# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
1461# coverage analysis in "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001462common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1463 test_target="$1"
1464
1465 # This is an internal helper to simplify text message handling
1466 if [ "$test_target" = "ECC_DH" ]; then
1467 accel_text="ECC/FFDH"
1468 else
1469 accel_text="ECC"
1470 fi
1471
1472 msg "build: full + non accelerated $accel_text algs + USE_PSA"
1473
1474 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
1475
1476 make
1477
1478 msg "test suites: full + non accelerated EC algs + USE_PSA"
1479 make test
1480
1481 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
1482 tests/ssl-opt.sh
1483}
1484
1485component_test_psa_crypto_config_accel_ecc_no_bignum () {
1486 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
1487}
1488
1489component_test_psa_crypto_config_reference_ecc_no_bignum () {
1490 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
1491}
1492
1493component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1494 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
1495}
1496
1497component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1498 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
1499}
1500
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001501component_test_tfm_config_as_is () {
1502 msg "build: configs/config-tfm.h"
1503 cp configs/config-tfm.h "$CONFIG_H"
1504 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1505 make
1506
1507 msg "test: configs/config-tfm.h - unit tests"
1508 make test
1509}
1510
Minos Galanakis471b34c2024-07-26 15:39:24 +01001511# Helper for setting common configurations between:
1512# - component_test_tfm_config_p256m_driver_accel_ec()
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001513# - component_test_tfm_config_no_p256m()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001514common_tfm_config () {
1515 # Enable TF-M config
1516 cp configs/config-tfm.h "$CONFIG_H"
1517 echo "#undef MBEDTLS_PSA_CRYPTO_CONFIG_FILE" >> "$CONFIG_H"
1518 cp configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
1519
1520 # Other config adjustment to make the tests pass.
1521 # This should probably be adopted upstream.
1522 #
1523 # - USE_PSA_CRYPTO for PK_HAVE_ECC_KEYS
1524 echo "#define MBEDTLS_USE_PSA_CRYPTO" >> "$CONFIG_H"
1525
1526 # Config adjustment for better test coverage in our environment.
1527 # This is not needed just to build and pass tests.
1528 #
1529 # Enable filesystem I/O for the benefit of PK parse/write tests.
1530 echo "#define MBEDTLS_FS_IO" >> "$CONFIG_H"
1531}
1532
1533# Keep this in sync with component_test_tfm_config() as they are both meant
1534# to be used in analyze_outcomes.py for driver's coverage analysis.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001535component_test_tfm_config_p256m_driver_accel_ec () {
1536 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1537
1538 common_tfm_config
1539
1540 # Build crypto library
1541 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
1542
1543 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1544 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1545 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1546 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1547 # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
1548 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1549 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1550 not grep mbedtls_dhm_ ${BUILTIN_SRC_PATH}/dhm.o
1551 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1552 # Check that p256m was built
1553 grep -q p256_ecdsa_ library/libmbedcrypto.a
1554
1555 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1556 # files, so we want to ensure that it has not be re-enabled accidentally.
1557 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1558
1559 # Run the tests
1560 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1561 make test
1562}
1563
1564# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1565# they are both meant to be used in analyze_outcomes.py for driver's coverage
1566# analysis.
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001567component_test_tfm_config_no_p256m () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001568 common_tfm_config
1569
1570 # Disable P256M driver, which is on by default, so that analyze_outcomes
1571 # can compare this test with test_tfm_config_p256m_driver_accel_ec
1572 echo "#undef MBEDTLS_PSA_P256M_DRIVER_ENABLED" >> "$CONFIG_H"
1573
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001574 msg "build: TF-M config without p256m"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001575 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' tests
1576
1577 # Check that p256m was not built
1578 not grep p256_ecdsa_ library/libmbedcrypto.a
1579
1580 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1581 # files, so we want to ensure that it has not be re-enabled accidentally.
1582 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1583
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001584 msg "test: TF-M config without p256m"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001585 make test
1586}
1587
Minos Galanakis471b34c2024-07-26 15:39:24 +01001588# This is an helper used by:
1589# - component_test_psa_ecc_key_pair_no_derive
1590# - component_test_psa_ecc_key_pair_no_generate
1591# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1592# enabled, but one. Input arguments are as follows:
1593# - $1 is the key type under test, i.e. ECC/RSA/DH
1594# - $2 is the key option to be unset (i.e. generate, derive, etc)
Minos Galanakisf78447f2024-07-26 20:49:51 +01001595build_and_test_psa_want_key_pair_partial () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001596 key_type=$1
1597 unset_option=$2
1598 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1599
1600 msg "build: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
1601 scripts/config.py full
1602 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1603 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1604
1605 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1606 # crypto_config.h so we just disable the one we don't want.
1607 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
1608
1609 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1610
1611 msg "test: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
1612 make test
1613}
1614
Minos Galanakisf78447f2024-07-26 20:49:51 +01001615component_test_psa_ecc_key_pair_no_derive () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001616 build_and_test_psa_want_key_pair_partial "ECC" "DERIVE"
1617}
1618
Minos Galanakisf78447f2024-07-26 20:49:51 +01001619component_test_psa_ecc_key_pair_no_generate () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001620 build_and_test_psa_want_key_pair_partial "ECC" "GENERATE"
1621}
1622
1623config_psa_crypto_accel_rsa () {
1624 driver_only=$1
1625
1626 # Start from crypto_full config (no X.509, no TLS)
1627 helper_libtestdriver1_adjust_config "crypto_full"
1628
1629 if [ "$driver_only" -eq 1 ]; then
1630 # Remove RSA support and its dependencies
1631 scripts/config.py unset MBEDTLS_RSA_C
1632 scripts/config.py unset MBEDTLS_PKCS1_V15
1633 scripts/config.py unset MBEDTLS_PKCS1_V21
1634
1635 # We need PEM parsing in the test library as well to support the import
1636 # of PEM encoded RSA keys.
1637 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1638 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
1639 fi
1640}
1641
1642component_test_psa_crypto_config_accel_rsa_crypto () {
1643 msg "build: crypto_full with accelerated RSA"
1644
1645 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1646 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1647 KEY_TYPE_RSA_PUBLIC_KEY \
1648 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1649 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1650 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1651 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1652
1653 # Configure
1654 # ---------
1655
1656 config_psa_crypto_accel_rsa 1
1657
1658 # Build
1659 # -----
1660
1661 # These hashes are needed for unit tests.
1662 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1663 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1664 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1665
1666 helper_libtestdriver1_make_main "$loc_accel_list"
1667
1668 # Make sure this was not re-enabled by accident (additive config)
1669 not grep mbedtls_rsa ${BUILTIN_SRC_PATH}/rsa.o
1670
1671 # Run the tests
1672 # -------------
1673
1674 msg "test: crypto_full with accelerated RSA"
1675 make test
1676}
1677
1678component_test_psa_crypto_config_reference_rsa_crypto () {
1679 msg "build: crypto_full with non-accelerated RSA"
1680
1681 # Configure
1682 # ---------
1683 config_psa_crypto_accel_rsa 0
1684
1685 # Build
1686 # -----
1687 make
1688
1689 # Run the tests
1690 # -------------
1691 msg "test: crypto_full with non-accelerated RSA"
1692 make test
1693}
1694
1695# This is a temporary test to verify that full RSA support is present even when
1696# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001697component_test_new_psa_want_key_pair_symbol () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001698 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1699
1700 # Create a temporary output file unless there is already one set
1701 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1702 REMOVE_OUTCOME_ON_EXIT="no"
1703 else
1704 REMOVE_OUTCOME_ON_EXIT="yes"
1705 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1706 export MBEDTLS_TEST_OUTCOME_FILE
1707 fi
1708
1709 # Start from crypto configuration
1710 scripts/config.py crypto
1711
1712 # Remove RSA support and its dependencies
1713 scripts/config.py unset MBEDTLS_PKCS1_V15
1714 scripts/config.py unset MBEDTLS_PKCS1_V21
1715 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1716 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1717 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1718 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1719 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1720 scripts/config.py unset MBEDTLS_RSA_C
1721 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1722
1723 # Enable PSA support
1724 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1725
1726 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
1727 # that proper translations is done in crypto_legacy.h.
1728 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
1729 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
1730 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
1731
1732 make
1733
1734 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1735 make test
1736
1737 # Parse only 1 relevant line from the outcome file, i.e. a test which is
1738 # performing RSA signature.
1739 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
1740 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
1741
1742 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
1743 rm $MBEDTLS_TEST_OUTCOME_FILE
1744 fi
1745}
1746
1747component_test_psa_crypto_config_accel_hash () {
1748 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
1749
1750 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1751 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1752 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1753
1754 # Configure
1755 # ---------
1756
1757 # Start from default config (no USE_PSA)
1758 helper_libtestdriver1_adjust_config "default"
1759
1760 # Disable the things that are being accelerated
1761 scripts/config.py unset MBEDTLS_MD5_C
1762 scripts/config.py unset MBEDTLS_RIPEMD160_C
1763 scripts/config.py unset MBEDTLS_SHA1_C
1764 scripts/config.py unset MBEDTLS_SHA224_C
1765 scripts/config.py unset MBEDTLS_SHA256_C
1766 scripts/config.py unset MBEDTLS_SHA384_C
1767 scripts/config.py unset MBEDTLS_SHA512_C
1768 scripts/config.py unset MBEDTLS_SHA3_C
1769
1770 # Build
1771 # -----
1772
1773 helper_libtestdriver1_make_drivers "$loc_accel_list"
1774
1775 helper_libtestdriver1_make_main "$loc_accel_list"
1776
1777 # There's a risk of something getting re-enabled via config_psa.h;
1778 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1779 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1780 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1781 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1782 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1783 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1784
1785 # Run the tests
1786 # -------------
1787
1788 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
1789 make test
1790}
1791
1792# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001793config_psa_crypto_hash_use_psa () {
1794 driver_only="$1"
1795 # start with config full for maximum coverage (also enables USE_PSA)
1796 helper_libtestdriver1_adjust_config "full"
1797 if [ "$driver_only" -eq 1 ]; then
1798 # disable the built-in implementation of hashes
1799 scripts/config.py unset MBEDTLS_MD5_C
1800 scripts/config.py unset MBEDTLS_RIPEMD160_C
1801 scripts/config.py unset MBEDTLS_SHA1_C
1802 scripts/config.py unset MBEDTLS_SHA224_C
1803 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
1804 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
1805 scripts/config.py unset MBEDTLS_SHA384_C
1806 scripts/config.py unset MBEDTLS_SHA512_C
1807 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
1808 scripts/config.py unset MBEDTLS_SHA3_C
1809 fi
1810}
1811
1812# Note that component_test_psa_crypto_config_reference_hash_use_psa
1813# is related to this component and both components need to be kept in sync.
1814# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001815component_test_psa_crypto_config_accel_hash_use_psa () {
1816 msg "test: full with accelerated hashes"
1817
1818 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1819 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1820 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1821
1822 # Configure
1823 # ---------
1824
1825 config_psa_crypto_hash_use_psa 1
1826
1827 # Build
1828 # -----
1829
1830 helper_libtestdriver1_make_drivers "$loc_accel_list"
1831
1832 helper_libtestdriver1_make_main "$loc_accel_list"
1833
1834 # There's a risk of something getting re-enabled via config_psa.h;
1835 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1836 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1837 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1838 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1839 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1840 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1841
1842 # Run the tests
1843 # -------------
1844
1845 msg "test: full with accelerated hashes"
1846 make test
1847
1848 # This is mostly useful so that we can later compare outcome files with
1849 # the reference config in analyze_outcomes.py, to check that the
1850 # dependency declarations in ssl-opt.sh and in TLS code are correct.
1851 msg "test: ssl-opt.sh, full with accelerated hashes"
1852 tests/ssl-opt.sh
1853
1854 # This is to make sure all ciphersuites are exercised, but we don't need
1855 # interop testing (besides, we already got some from ssl-opt.sh).
1856 msg "test: compat.sh, full with accelerated hashes"
1857 tests/compat.sh -p mbedTLS -V YES
1858}
1859
1860# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
1861# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
1862# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
1863# Both components need to be kept in sync.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001864component_test_psa_crypto_config_reference_hash_use_psa () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001865 msg "test: full without accelerated hashes"
1866
1867 config_psa_crypto_hash_use_psa 0
1868
1869 make
1870
1871 msg "test: full without accelerated hashes"
1872 make test
1873
1874 msg "test: ssl-opt.sh, full without accelerated hashes"
1875 tests/ssl-opt.sh
1876}
1877
1878# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001879config_psa_crypto_hmac_use_psa () {
1880 driver_only="$1"
1881 # start with config full for maximum coverage (also enables USE_PSA)
1882 helper_libtestdriver1_adjust_config "full"
1883
1884 if [ "$driver_only" -eq 1 ]; then
1885 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
1886 # is still enabled though (for ENTROPY_C among others).
1887 scripts/config.py unset MBEDTLS_MD_C
1888 # Disable also the builtin hashes since they are supported by the driver
1889 # and MD module is able to perform PSA dispathing.
1890 scripts/config.py unset-all MBEDTLS_SHA
1891 scripts/config.py unset MBEDTLS_MD5_C
1892 scripts/config.py unset MBEDTLS_RIPEMD160_C
1893 fi
1894
1895 # Direct dependencies of MD_C. We disable them also in the reference
1896 # component to work with the same set of features.
1897 scripts/config.py unset MBEDTLS_PKCS7_C
1898 scripts/config.py unset MBEDTLS_PKCS5_C
1899 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1900 scripts/config.py unset MBEDTLS_HKDF_C
1901 # Dependencies of HMAC_DRBG
1902 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
1903 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
1904}
1905
Minos Galanakisf78447f2024-07-26 20:49:51 +01001906component_test_psa_crypto_config_accel_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001907 msg "test: full with accelerated hmac"
1908
1909 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
1910 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1911 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1912 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1913
1914 # Configure
1915 # ---------
1916
1917 config_psa_crypto_hmac_use_psa 1
1918
1919 # Build
1920 # -----
1921
1922 helper_libtestdriver1_make_drivers "$loc_accel_list"
1923
1924 helper_libtestdriver1_make_main "$loc_accel_list"
1925
1926 # Ensure that built-in support for HMAC is disabled.
1927 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
1928
1929 # Run the tests
1930 # -------------
1931
1932 msg "test: full with accelerated hmac"
1933 make test
1934}
1935
Minos Galanakisf78447f2024-07-26 20:49:51 +01001936component_test_psa_crypto_config_reference_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001937 msg "test: full without accelerated hmac"
1938
1939 config_psa_crypto_hmac_use_psa 0
1940
1941 make
1942
1943 msg "test: full without accelerated hmac"
1944 make test
1945}
1946
1947component_test_psa_crypto_config_accel_des () {
1948 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
1949
1950 # Albeit this components aims at accelerating DES which should only support
1951 # CBC and ECB modes, we need to accelerate more than that otherwise DES_C
1952 # would automatically be re-enabled by "config_adjust_legacy_from_psa.c"
1953 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 \
1954 ALG_CTR ALG_CFB ALG_OFB ALG_XTS ALG_CMAC \
1955 KEY_TYPE_DES"
1956
1957 # Note: we cannot accelerate all ciphers' key types otherwise we would also
1958 # have to either disable CCM/GCM or accelerate them, but that's out of scope
1959 # of this component. This limitation will be addressed by #8598.
1960
1961 # Configure
1962 # ---------
1963
1964 # Start from the full config
1965 helper_libtestdriver1_adjust_config "full"
1966
1967 # Disable the things that are being accelerated
1968 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1969 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
1970 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
1971 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
1972 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
1973 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
1974 scripts/config.py unset MBEDTLS_DES_C
1975 scripts/config.py unset MBEDTLS_CMAC_C
1976
1977 # Build
1978 # -----
1979
1980 helper_libtestdriver1_make_drivers "$loc_accel_list"
1981
1982 helper_libtestdriver1_make_main "$loc_accel_list"
1983
1984 # Make sure this was not re-enabled by accident (additive config)
1985 not grep mbedtls_des* ${BUILTIN_SRC_PATH}/des.o
1986
1987 # Run the tests
1988 # -------------
1989
1990 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
1991 make test
1992}
1993
1994component_test_psa_crypto_config_accel_aead () {
1995 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
1996
1997 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
1998 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1999
2000 # Configure
2001 # ---------
2002
2003 # Start from full config
2004 helper_libtestdriver1_adjust_config "full"
2005
2006 # Disable things that are being accelerated
2007 scripts/config.py unset MBEDTLS_GCM_C
2008 scripts/config.py unset MBEDTLS_CCM_C
2009 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2010
2011 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
2012 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
2013
2014 # Build
2015 # -----
2016
2017 helper_libtestdriver1_make_drivers "$loc_accel_list"
2018
2019 helper_libtestdriver1_make_main "$loc_accel_list"
2020
2021 # Make sure this was not re-enabled by accident (additive config)
2022 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
2023 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
2024 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
2025
2026 # Run the tests
2027 # -------------
2028
2029 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2030 make test
2031}
2032
2033# This is a common configuration function used in:
2034# - component_test_psa_crypto_config_accel_cipher_aead_cmac
2035# - component_test_psa_crypto_config_reference_cipher_aead_cmac
Minos Galanakisf78447f2024-07-26 20:49:51 +01002036common_psa_crypto_config_accel_cipher_aead_cmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002037 # Start from the full config
2038 helper_libtestdriver1_adjust_config "full"
2039
2040 scripts/config.py unset MBEDTLS_NIST_KW_C
2041}
2042
2043# The 2 following test components, i.e.
2044# - component_test_psa_crypto_config_accel_cipher_aead_cmac
2045# - component_test_psa_crypto_config_reference_cipher_aead_cmac
2046# are meant to be used together in analyze_outcomes.py script in order to test
2047# driver's coverage for ciphers and AEADs.
Minos Galanakis471b34c2024-07-26 15:39:24 +01002048component_test_psa_crypto_config_accel_cipher_aead_cmac () {
2049 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
2050
2051 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
2052 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
2053 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
2054 KEY_TYPE_DES KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
2055
2056 # Configure
2057 # ---------
2058
2059 common_psa_crypto_config_accel_cipher_aead_cmac
2060
2061 # Disable the things that are being accelerated
2062 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2063 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2064 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2065 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2066 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2067 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2068 scripts/config.py unset MBEDTLS_GCM_C
2069 scripts/config.py unset MBEDTLS_CCM_C
2070 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2071 scripts/config.py unset MBEDTLS_CMAC_C
2072 scripts/config.py unset MBEDTLS_DES_C
2073 scripts/config.py unset MBEDTLS_AES_C
2074 scripts/config.py unset MBEDTLS_ARIA_C
2075 scripts/config.py unset MBEDTLS_CHACHA20_C
2076 scripts/config.py unset MBEDTLS_CAMELLIA_C
2077
2078 # Disable CIPHER_C entirely as all ciphers/AEADs are accelerated and PSA
2079 # does not depend on it.
2080 scripts/config.py unset MBEDTLS_CIPHER_C
2081
2082 # Build
2083 # -----
2084
2085 helper_libtestdriver1_make_drivers "$loc_accel_list"
2086
2087 helper_libtestdriver1_make_main "$loc_accel_list"
2088
2089 # Make sure this was not re-enabled by accident (additive config)
2090 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
2091 not grep mbedtls_des ${BUILTIN_SRC_PATH}/des.o
2092 not grep mbedtls_aes ${BUILTIN_SRC_PATH}/aes.o
2093 not grep mbedtls_aria ${BUILTIN_SRC_PATH}/aria.o
2094 not grep mbedtls_camellia ${BUILTIN_SRC_PATH}/camellia.o
2095 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
2096 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
2097 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
2098 not grep mbedtls_cmac ${BUILTIN_SRC_PATH}/cmac.o
2099
2100 # Run the tests
2101 # -------------
2102
2103 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
2104 make test
2105
2106 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
2107 tests/ssl-opt.sh
2108
2109 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
2110 tests/compat.sh -V NO -p mbedTLS
2111}
2112
2113component_test_psa_crypto_config_reference_cipher_aead_cmac () {
2114 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
2115 common_psa_crypto_config_accel_cipher_aead_cmac
2116
2117 make
2118
2119 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
2120 make test
2121
2122 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
2123 tests/ssl-opt.sh
2124
2125 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
2126 tests/compat.sh -V NO -p mbedTLS
2127}
2128
Minos Galanakisf78447f2024-07-26 20:49:51 +01002129common_block_cipher_dispatch () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002130 TEST_WITH_DRIVER="$1"
2131
2132 # Start from the full config
2133 helper_libtestdriver1_adjust_config "full"
2134
2135 if [ "$TEST_WITH_DRIVER" -eq 1 ]; then
2136 # Disable key types that are accelerated (there is no legacy equivalent
2137 # symbol for ECB)
2138 scripts/config.py unset MBEDTLS_AES_C
2139 scripts/config.py unset MBEDTLS_ARIA_C
2140 scripts/config.py unset MBEDTLS_CAMELLIA_C
2141 fi
2142
2143 # Disable cipher's modes that, when not accelerated, cause
2144 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
2145 # Keep this also in the reference component in order to skip the same tests
2146 # that were skipped in the accelerated one.
2147 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
2148 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
2149 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
2150 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
2151 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
2152 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
2153 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
2154 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
2155
2156 # Disable direct dependency on AES_C
2157 scripts/config.py unset MBEDTLS_NIST_KW_C
2158
2159 # Prevent the cipher module from using deprecated PSA path. The reason is
2160 # that otherwise there will be tests relying on "aes_info" (defined in
2161 # "cipher_wrap.c") whose functions are not available when AES_C is
2162 # not defined. ARIA and Camellia are not a problem in this case because
2163 # the PSA path is not tested for these key types.
2164 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
2165}
2166
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002167component_test_full_block_cipher_psa_dispatch_static_keystore () {
2168 msg "build: full + PSA dispatch in block_cipher with static keystore"
2169 # Check that the static key store works well when CTR_DRBG uses a
2170 # PSA key for AES.
2171 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2172
2173 loc_accel_list="ALG_ECB_NO_PADDING \
2174 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2175
2176 # Configure
2177 # ---------
2178
2179 common_block_cipher_dispatch 1
2180
2181 # Build
2182 # -----
2183
2184 helper_libtestdriver1_make_drivers "$loc_accel_list"
2185
2186 helper_libtestdriver1_make_main "$loc_accel_list"
2187
2188 # Make sure disabled components were not re-enabled by accident (additive
2189 # config)
2190 not grep mbedtls_aes_ library/aes.o
2191 not grep mbedtls_aria_ library/aria.o
2192 not grep mbedtls_camellia_ library/camellia.o
2193
2194 # Run the tests
2195 # -------------
2196
2197 msg "test: full + PSA dispatch in block_cipher with static keystore"
2198 make test
2199}
2200
Minos Galanakis471b34c2024-07-26 15:39:24 +01002201component_test_full_block_cipher_psa_dispatch () {
2202 msg "build: full + PSA dispatch in block_cipher"
2203
2204 loc_accel_list="ALG_ECB_NO_PADDING \
2205 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2206
2207 # Configure
2208 # ---------
2209
2210 common_block_cipher_dispatch 1
2211
2212 # Build
2213 # -----
2214
2215 helper_libtestdriver1_make_drivers "$loc_accel_list"
2216
2217 helper_libtestdriver1_make_main "$loc_accel_list"
2218
2219 # Make sure disabled components were not re-enabled by accident (additive
2220 # config)
2221 not grep mbedtls_aes_ ${BUILTIN_SRC_PATH}/aes.o
2222 not grep mbedtls_aria_ ${BUILTIN_SRC_PATH}/aria.o
2223 not grep mbedtls_camellia_ ${BUILTIN_SRC_PATH}/camellia.o
2224
2225 # Run the tests
2226 # -------------
2227
2228 msg "test: full + PSA dispatch in block_cipher"
2229 make test
2230}
2231
2232# This is the reference component of component_test_full_block_cipher_psa_dispatch
Minos Galanakis471b34c2024-07-26 15:39:24 +01002233component_test_full_block_cipher_legacy_dispatch () {
2234 msg "build: full + legacy dispatch in block_cipher"
2235
2236 common_block_cipher_dispatch 0
2237
2238 make
2239
2240 msg "test: full + legacy dispatch in block_cipher"
2241 make test
2242}
2243
Minos Galanakisf78447f2024-07-26 20:49:51 +01002244component_test_aead_chachapoly_disabled () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002245 msg "build: full minus CHACHAPOLY"
2246 scripts/config.py full
2247 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2248 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2249 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2250
2251 msg "test: full minus CHACHAPOLY"
2252 make test
2253}
2254
Minos Galanakisf78447f2024-07-26 20:49:51 +01002255component_test_aead_only_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002256 msg "build: full minus CHACHAPOLY and GCM"
2257 scripts/config.py full
2258 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2259 scripts/config.py unset MBEDTLS_GCM_C
2260 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2261 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2262 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2263
2264 msg "test: full minus CHACHAPOLY and GCM"
2265 make test
2266}
2267
Minos Galanakisf78447f2024-07-26 20:49:51 +01002268component_test_ccm_aes_sha256 () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002269 msg "build: CCM + AES + SHA256 configuration"
2270
2271 cp "$CONFIG_TEST_DRIVER_H" "$CONFIG_H"
2272 cp configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
2273
2274 make
2275
2276 msg "test: CCM + AES + SHA256 configuration"
2277 make test
2278}
2279
2280# Test that the given .o file builds with all (valid) combinations of the given options.
2281#
2282# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
2283#
2284# The validator function is the name of a function to validate the combination of options.
2285# It may be "" if all combinations are valid.
2286# It receives a string containing a combination of options, as passed to the compiler,
2287# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Minos Galanakisf78447f2024-07-26 20:49:51 +01002288build_test_config_combos () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002289 file=$1
2290 shift
2291 validate_options=$1
2292 shift
2293 options=("$@")
2294
2295 # clear all of the options so that they can be overridden on the clang commandline
2296 for opt in "${options[@]}"; do
2297 ./scripts/config.py unset ${opt}
2298 done
2299
2300 # enter the library directory
2301 cd library
2302
2303 # The most common issue is unused variables/functions, so ensure -Wunused is set.
2304 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
2305
2306 # Extract the command generated by the Makefile to build the target file.
2307 # This ensures that we have any include paths, macro definitions, etc
2308 # that may be applied by make.
2309 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
2310 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
2311
2312 makefile=$(TMPDIR=. mktemp)
2313 deps=""
2314
2315 len=${#options[@]}
2316 source_file=../${file%.o}.c
2317
2318 targets=0
2319 echo 'include Makefile' >${makefile}
2320
2321 for ((i = 0; i < $((2**${len})); i++)); do
2322 # generate each of 2^n combinations of options
2323 # each bit of $i is used to determine if options[i] will be set or not
2324 target="t"
2325 clang_args=""
2326 for ((j = 0; j < ${len}; j++)); do
2327 if (((i >> j) & 1)); then
2328 opt=-D${options[$j]}
2329 clang_args="${clang_args} ${opt}"
2330 target="${target}${opt}"
2331 fi
2332 done
2333
2334 # if combination is not known to be invalid, add it to the makefile
2335 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
2336 cmd="${compile_cmd} ${clang_args}"
2337 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
2338
2339 deps="${deps} ${target}"
2340 ((++targets))
2341 fi
2342 done
2343
2344 echo "build_test_config_combos: ${deps}" >> ${makefile}
2345
2346 # execute all of the commands via Make (probably in parallel)
2347 make -s -f ${makefile} build_test_config_combos
2348 echo "$targets targets checked"
2349
2350 # clean up the temporary makefile
2351 rm ${makefile}
2352}
2353
Minos Galanakisf78447f2024-07-26 20:49:51 +01002354validate_aes_config_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002355 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
2356 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
2357 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
2358 return 1
2359 fi
2360 fi
2361 return 0
2362}
2363
Minos Galanakisf78447f2024-07-26 20:49:51 +01002364component_build_aes_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002365 # 18s - around 90ms per clang invocation on M1 Pro
2366 #
2367 # aes.o has many #if defined(...) guards that intersect in complex ways.
2368 # Test that all the combinations build cleanly.
2369
2370 MBEDTLS_ROOT_DIR="$PWD"
2371 msg "build: aes.o for all combinations of relevant config options"
2372
2373 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002374 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002375 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2376 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2377
2378 cd "$MBEDTLS_ROOT_DIR"
2379 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
2380
2381 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES,
2382 # manually set or unset those configurations to check
2383 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
Ronald Cron54d1eec2024-09-06 09:55:38 +02002384 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
Minos Galanakis471b34c2024-07-26 15:39:24 +01002385 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Minos Galanakis471b34c2024-07-26 15:39:24 +01002386 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002387 scripts/config.py unset MBEDTLS_NIST_KW_C
Ronald Cron54d1eec2024-09-06 09:55:38 +02002388
2389 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
2390 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
2391 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
2392 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
Ronald Cron4153ebb2024-09-11 15:32:48 +02002393 # Note: The two unsets below are to be removed for Mbed TLS 4.0
Ronald Cron54d1eec2024-09-06 09:55:38 +02002394 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2395 scripts/config.py unset MBEDTLS_DES_C
2396
Minos Galanakis471b34c2024-07-26 15:39:24 +01002397 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002398 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002399 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2400 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2401}
2402
Minos Galanakisf78447f2024-07-26 20:49:51 +01002403component_test_sha3_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002404 msg "sha3 loop unroll variations"
2405
2406 # define minimal config sufficient to test SHA3
Ronald Crone7f289e2024-09-06 11:02:47 +02002407 cat > include/mbedtls/mbedtls_config.h << END
2408 #define MBEDTLS_AES_C
2409 #define MBEDTLS_CTR_DRBG_C
2410 #define MBEDTLS_ENTROPY_C
2411 #define MBEDTLS_PSA_CRYPTO_C
2412 #define MBEDTLS_PSA_CRYPTO_CONFIG
2413 #define MBEDTLS_SELF_TEST
2414END
2415
2416 cat > tf-psa-crypto/include/psa/crypto_config.h << END
2417 #define PSA_WANT_ALG_SHA_256 1
2418 #define PSA_WANT_ALG_SHA3_224 1
2419 #define PSA_WANT_ALG_SHA3_256 1
2420 #define PSA_WANT_ALG_SHA3_384 1
2421 #define PSA_WANT_ALG_SHA3_512 1
Minos Galanakis471b34c2024-07-26 15:39:24 +01002422END
2423
2424 msg "all loops unrolled"
2425 make clean
2426 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"
2427 ./tf-psa-crypto/tests/test_suite_shax
2428
2429 msg "all loops rolled up"
2430 make clean
2431 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"
2432 ./tf-psa-crypto/tests/test_suite_shax
2433}
2434
Minos Galanakisf699d512024-08-01 11:32:30 +01002435support_build_aes_aesce_armcc () {
2436 support_build_armcc
2437}
2438
Minos Galanakis471b34c2024-07-26 15:39:24 +01002439# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2440component_build_aes_aesce_armcc () {
2441 msg "Build: AESCE test on arm64 platform without plain C."
2442 scripts/config.py baremetal
2443
2444 # armc[56] don't support SHA-512 intrinsics
2445 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2446
2447 # Stop armclang warning about feature detection for A64_CRYPTO.
2448 # With this enabled, the library does build correctly under armclang,
2449 # but in baremetal builds (as tested here), feature detection is
2450 # unavailable, and the user is notified via a #warning. So enabling
2451 # this feature would prevent us from building with -Werror on
2452 # armclang. Tracked in #7198.
2453 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2454 scripts/config.py set MBEDTLS_HAVE_ASM
2455
2456 msg "AESCE, build with default configuration."
2457 scripts/config.py set MBEDTLS_AESCE_C
2458 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002459 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002460
2461 msg "AESCE, build AESCE only"
2462 scripts/config.py set MBEDTLS_AESCE_C
2463 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002464 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002465}
2466
Minos Galanakis471b34c2024-07-26 15:39:24 +01002467component_test_aes_only_128_bit_keys () {
2468 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2469 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2470
2471 make CFLAGS='-O2 -Werror -Wall -Wextra'
2472
2473 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2474 make test
2475}
2476
2477component_test_no_ctr_drbg_aes_only_128_bit_keys () {
2478 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2479 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2480 scripts/config.py unset MBEDTLS_CTR_DRBG_C
2481
2482 make CC=clang CFLAGS='-Werror -Wall -Wextra'
2483
2484 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2485 make test
2486}
2487
2488component_test_aes_only_128_bit_keys_have_builtins () {
2489 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2490 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2491 scripts/config.py unset MBEDTLS_AESNI_C
2492 scripts/config.py unset MBEDTLS_AESCE_C
2493
2494 make CFLAGS='-O2 -Werror -Wall -Wextra'
2495
2496 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2497 make test
2498
2499 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2500 programs/test/selftest
2501}
2502
2503component_test_gcm_largetable () {
2504 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2505 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
2506 scripts/config.py unset MBEDTLS_AESNI_C
2507 scripts/config.py unset MBEDTLS_AESCE_C
2508
2509 make CFLAGS='-O2 -Werror -Wall -Wextra'
2510
2511 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2512 make test
2513}
2514
2515component_test_aes_fewer_tables () {
2516 msg "build: default config with AES_FEWER_TABLES enabled"
2517 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2518 make CFLAGS='-O2 -Werror -Wall -Wextra'
2519
2520 msg "test: AES_FEWER_TABLES"
2521 make test
2522}
2523
2524component_test_aes_rom_tables () {
2525 msg "build: default config with AES_ROM_TABLES enabled"
2526 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2527 make CFLAGS='-O2 -Werror -Wall -Wextra'
2528
2529 msg "test: AES_ROM_TABLES"
2530 make test
2531}
2532
2533component_test_aes_fewer_tables_and_rom_tables () {
2534 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
2535 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2536 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2537 make CFLAGS='-O2 -Werror -Wall -Wextra'
2538
2539 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2540 make test
2541}
2542
Ronald Cron66040472024-09-06 10:14:38 +02002543# helper for component_test_block_cipher_no_decrypt_aesni() which:
Minos Galanakis471b34c2024-07-26 15:39:24 +01002544# - enable/disable the list of config options passed from -s/-u respectively.
2545# - build
2546# - test for tests_suite_xxx
2547# - selftest
2548#
2549# Usage: helper_block_cipher_no_decrypt_build_test
2550# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
2551# Options: -s set_opts the list of config options to enable
2552# -u unset_opts the list of config options to disable
2553# -c cflags the list of options passed to CFLAGS
2554# -l ldflags the list of options passed to LDFLAGS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002555helper_block_cipher_no_decrypt_build_test () {
2556 while [ $# -gt 0 ]; do
2557 case "$1" in
2558 -s)
2559 shift; local set_opts="$1";;
2560 -u)
2561 shift; local unset_opts="$1";;
2562 -c)
2563 shift; local cflags="-Werror -Wall -Wextra $1";;
2564 -l)
2565 shift; local ldflags="$1";;
2566 esac
2567 shift
2568 done
2569 set_opts="${set_opts:-}"
2570 unset_opts="${unset_opts:-}"
2571 cflags="${cflags:-}"
2572 ldflags="${ldflags:-}"
2573
2574 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
2575 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
2576
2577 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2578 make clean
2579 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
2580
2581 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2582 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2583 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2584 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2585 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2586 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2587 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
2588 not grep mbedtls_aesni_inverse_key ${BUILTIN_SRC_PATH}/aesni.o
2589
2590 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2591 make test
2592
2593 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2594 programs/test/selftest
2595}
2596
Ronald Cron66040472024-09-06 10:14:38 +02002597# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
2598config_block_cipher_no_decrypt () {
2599 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
2600 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2601 scripts/config.py unset MBEDTLS_NIST_KW_C
2602
2603 # Enable support for cryptographic mechanisms through the PSA API.
2604 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
2605 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2606 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
2607 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
2608 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
2609 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
Ronald Cron4153ebb2024-09-11 15:32:48 +02002610 # Note: The two unsets below are to be removed for Mbed TLS 4.0
Ronald Cron66040472024-09-06 10:14:38 +02002611 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2612 scripts/config.py unset MBEDTLS_DES_C
2613}
2614
2615component_test_block_cipher_no_decrypt_aesni () {
2616 # Test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics, AESNI assembly and
2617 # AES C implementation on x86_64 and with AESNI intrinsics on x86.
2618
2619 # This consistently causes an llvm crash on clang 3.8, so use gcc
2620 export CC=gcc
2621 config_block_cipher_no_decrypt
2622
Minos Galanakis471b34c2024-07-26 15:39:24 +01002623 # test AESNI intrinsics
2624 helper_block_cipher_no_decrypt_build_test \
2625 -s "MBEDTLS_AESNI_C" \
2626 -c "-mpclmul -msse2 -maes"
2627
2628 # test AESNI assembly
2629 helper_block_cipher_no_decrypt_build_test \
2630 -s "MBEDTLS_AESNI_C" \
2631 -c "-mno-pclmul -mno-sse2 -mno-aes"
2632
2633 # test AES C implementation
2634 helper_block_cipher_no_decrypt_build_test \
2635 -u "MBEDTLS_AESNI_C"
2636
2637 # test AESNI intrinsics for i386 target
2638 helper_block_cipher_no_decrypt_build_test \
2639 -s "MBEDTLS_AESNI_C" \
2640 -c "-m32 -mpclmul -msse2 -maes" \
2641 -l "-m32"
2642}
2643
Minos Galanakisf699d512024-08-01 11:32:30 +01002644support_test_block_cipher_no_decrypt_aesce_armcc () {
2645 support_build_armcc
2646}
2647
Minos Galanakis471b34c2024-07-26 15:39:24 +01002648component_test_block_cipher_no_decrypt_aesce_armcc () {
2649 scripts/config.py baremetal
2650
2651 # armc[56] don't support SHA-512 intrinsics
2652 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2653
2654 # Stop armclang warning about feature detection for A64_CRYPTO.
2655 # With this enabled, the library does build correctly under armclang,
2656 # but in baremetal builds (as tested here), feature detection is
2657 # unavailable, and the user is notified via a #warning. So enabling
2658 # this feature would prevent us from building with -Werror on
2659 # armclang. Tracked in #7198.
2660 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2661 scripts/config.py set MBEDTLS_HAVE_ASM
2662
Ronald Cron66040472024-09-06 10:14:38 +02002663 config_block_cipher_no_decrypt
Minos Galanakis471b34c2024-07-26 15:39:24 +01002664
2665 # test AESCE baremetal build
2666 scripts/config.py set MBEDTLS_AESCE_C
2667 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002668 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002669
2670 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2671 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2672 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2673 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2674 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2675 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2676 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
2677 not grep mbedtls_aesce_inverse_key ${BUILTIN_SRC_PATH}/aesce.o
2678 not grep aesce_decrypt_block ${BUILTIN_SRC_PATH}/aesce.o
2679}
2680
2681component_test_ctr_drbg_aes_256_sha_256 () {
2682 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2683 scripts/config.py full
2684 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2685 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
2686 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2687 make
2688
2689 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2690 make test
2691}
2692
2693component_test_ctr_drbg_aes_128_sha_512 () {
2694 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2695 scripts/config.py full
2696 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2697 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2698 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2699 make
2700
2701 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2702 make test
2703}
2704
2705component_test_ctr_drbg_aes_128_sha_256 () {
2706 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2707 scripts/config.py full
2708 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2709 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2710 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
2711 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2712 make
2713
2714 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2715 make test
2716}
2717
2718component_test_se_default () {
2719 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2720 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
2721 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
2722
2723 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2724 make test
2725}
2726
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002727component_test_full_static_keystore () {
2728 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2729 scripts/config.py full
2730 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2731 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
2732
2733 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2734 make test
2735}
2736
Minos Galanakis471b34c2024-07-26 15:39:24 +01002737component_test_psa_crypto_drivers () {
Ronald Crona0afbfb2024-10-15 13:20:31 +02002738 # Test dispatch to drivers and fallbacks with
2739 # test_suite_psa_crypto_driver_wrappers test suite. The test drivers that
2740 # are wrappers around the builtin drivers are activated by
2741 # PSA_CRYPTO_DRIVER_TEST.
2742 #
2743 # For the time being, some test cases in test_suite_block_cipher and
2744 # test_suite_md.psa rely on this component to be run at least once by the
2745 # CI. This should disappear as we progress the 4.x work. See
2746 # config_adjust_test_accelerators.h for more information.
Minos Galanakis471b34c2024-07-26 15:39:24 +01002747 msg "build: full + test drivers dispatching to builtins"
2748 scripts/config.py full
Ronald Cron67cc6a72024-10-14 10:55:24 +02002749 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_CONFIG_ADJUST_TEST_ACCELERATORS"
Ronald Cronede04b32024-10-16 10:47:15 +02002750 loc_cflags="${loc_cflags} -I../tests/include"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002751
2752 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
2753
2754 msg "test: full + test drivers dispatching to builtins"
2755 make test
2756}
2757
2758component_build_psa_config_file () {
2759 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
2760 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2761 cp "$CRYPTO_CONFIG_H" psa_test_config.h
2762 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
2763 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
2764 # Make sure this feature is enabled. We'll disable it in the next phase.
2765 programs/test/query_compile_time_config MBEDTLS_CMAC_C
2766 make clean
2767
2768 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
2769 # In the user config, disable one feature and its dependencies, which will
2770 # reflect on the mbedtls configuration so we can query it with
2771 # query_compile_time_config.
2772 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
2773 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
2774 scripts/config.py unset MBEDTLS_CMAC_C
2775 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
2776 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
2777
2778 rm -f psa_test_config.h psa_user_config.h
2779}
2780
2781component_build_psa_alt_headers () {
2782 msg "build: make with PSA alt headers" # ~20s
2783
2784 # Generate alternative versions of the substitutable headers with the
2785 # same content except different include guards.
2786 make -C tests include/alt-extra/psa/crypto_platform_alt.h include/alt-extra/psa/crypto_struct_alt.h
2787
2788 # Build the library and some programs.
2789 # Don't build the fuzzers to avoid having to go through hoops to set
2790 # a correct include path for programs/fuzz/Makefile.
2791 make CFLAGS="-I ../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
2792 make -C programs -o fuzz CFLAGS="-I ../tests/include/alt-extra -DMBEDTLS_PSA_CRYPTO_PLATFORM_FILE='\"psa/crypto_platform_alt.h\"' -DMBEDTLS_PSA_CRYPTO_STRUCT_FILE='\"psa/crypto_struct_alt.h\"'"
2793
2794 # Check that we're getting the alternative include guards and not the
2795 # original include guards.
2796 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
2797 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
2798 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
2799 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
2800}
2801
2802component_test_min_mpi_window_size () {
2803 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
2804 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
2805 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2806 make
2807
2808 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2809 make test
2810}