blob: 6b12bb9af5171a9980476f4cefa72bd97f5a9024 [file] [log] [blame]
Minos Galanakis77711192024-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
6# This file contains test components that are executed by all.sh
7
Gilles Peskine580d1f42025-08-08 00:06:06 +02008## test_with_valgrind tests/suites/SUITE.data [...]
9## Run the specified test suite(s) with Valgrind.
10test_with_valgrind () {
11 for data_file in "$@"; do
12 suite="${data_file##*/}"; suite="${suite%.data}"
13 exe="tests/$suite"
14 log_file="tests/MemoryChecker.$suite.log"
15 make -C tests "$suite"
16 valgrind -q --tool=memcheck --track-origins=yes --log-file="$log_file" "$exe"
17 not grep . -- "$log_file"
18 done
19}
20
21## Run a small set of dedicated constant-time tests with Valgrind.
22## Exclude very slow suites.
23## Exclude suites that contain some constant-time tests, but whose focus
24## isn't on constant-time tests.
25test_with_valgrind_constant_time () {
26 declare GLOBIGNORE="tests/suites/test_suite_constant_time_hmac.data"
27 test_with_valgrind tests/suites/*constant_time*.data
28}
29
Minos Galanakis77711192024-07-25 14:24:37 +010030################################################################
31#### Configuration Testing - Crypto
32################################################################
Minos Galanakis3ece57e2024-08-01 17:09:49 +010033
34component_test_psa_crypto_key_id_encodes_owner () {
35 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
36 scripts/config.py full
37 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
38 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
39 make
40
41 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
42 make test
43}
44
45component_test_psa_assume_exclusive_buffers () {
46 msg "build: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
47 scripts/config.py full
48 scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
49 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
50 make
51
52 msg "test: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
53 make test
54}
55
Gilles Peskine580d1f42025-08-08 00:06:06 +020056component_test_psa_assume_exclusive_buffers_valgrind_cf () {
57 msg "build: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, constant flow with Valgrind"
58 scripts/config.py full
59 scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
60 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
61 make lib
62
63 msg "test: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, constant flow with Valgrind, selected suites"
64 test_with_valgrind_constant_time tests/suites/*constant_time*.data
65}
66
Valerio Setti168d24a2024-06-20 14:40:54 +020067component_test_crypto_with_static_key_slots() {
68 msg "build: crypto full + MBEDTLS_PSA_STATIC_KEY_SLOTS"
69 scripts/config.py crypto_full
70 scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOTS
Valerio Settiba98d5b2024-08-16 12:35:24 +020071 # Intentionally set MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE to a value that
72 # is enough to contain:
73 # - all RSA public keys up to 4096 bits (max of PSA_VENDOR_RSA_MAX_KEY_BITS).
74 # - RSA key pairs up to 1024 bits, but not 2048 or larger.
75 # - all FFDH key pairs and public keys up to 8192 bits (max of PSA_VENDOR_FFDH_MAX_KEY_BITS).
76 # - all EC key pairs and public keys up to 521 bits (max of PSA_VENDOR_ECC_MAX_CURVE_BITS).
77 scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE 1212
Valerio Setti92f1d2d2024-08-28 05:50:45 +020078 # Disable the fully dynamic key store (default on) since it conflicts
79 # with the static behavior that we're testing here.
80 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
Valerio Setti168d24a2024-06-20 14:40:54 +020081
Valerio Settibc611712024-08-13 13:13:23 +020082 msg "test: crypto full + MBEDTLS_PSA_STATIC_KEY_SLOTS"
Valerio Setti291532f2024-08-14 06:37:02 +020083 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" test
Valerio Setti168d24a2024-06-20 14:40:54 +020084}
85
Minos Galanakis3ece57e2024-08-01 17:09:49 +010086# check_renamed_symbols HEADER LIB
87# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
88# name in LIB.
89check_renamed_symbols () {
90 ! nm "$2" | sed 's/.* //' |
91 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
92}
93
94component_build_psa_crypto_spm () {
95 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
96 scripts/config.py full
97 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
98 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
99 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
100 # We can only compile, not link, since our test and sample programs
101 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
102 # is active.
David Horstmanndcf42a02024-11-08 14:40:12 +0000103 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' lib
Minos Galanakis3ece57e2024-08-01 17:09:49 +0100104
105 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
106 # version is not present.
107 echo "Checking for renamed symbols in the library"
David Horstmanndcf42a02024-11-08 14:40:12 +0000108 check_renamed_symbols framework/tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Minos Galanakis3ece57e2024-08-01 17:09:49 +0100109}
110
Valerio Settiefce6052024-06-25 18:31:36 +0200111# The goal of this component is to build a configuration where:
112# - test code and libtestdriver1 can make use of calloc/free and
113# - core library (including PSA core) cannot use calloc/free.
114component_test_psa_crypto_without_heap() {
Valerio Settibc611712024-08-13 13:13:23 +0200115 msg "crypto without heap: build libtestdriver1"
Valerio Settiefce6052024-06-25 18:31:36 +0200116 # Disable PSA features that cannot be accelerated and whose builtin support
117 # requires calloc/free.
118 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Valerio Settibc611712024-08-13 13:13:23 +0200119 scripts/config.py -f $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_HKDF"
120 scripts/config.py -f $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_PBKDF2_"
121 scripts/config.py -f $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_TLS12_"
Valerio Settiefce6052024-06-25 18:31:36 +0200122 # RSA key support requires ASN1 parse/write support for testing, but ASN1
123 # is disabled below.
Valerio Settibc611712024-08-13 13:13:23 +0200124 scripts/config.py -f $CRYPTO_CONFIG_H unset-all "^PSA_WANT_KEY_TYPE_RSA_"
125 scripts/config.py -f $CRYPTO_CONFIG_H unset-all "^PSA_WANT_ALG_RSA_"
Valerio Settiefce6052024-06-25 18:31:36 +0200126 # DES requires built-in support for key generation (parity check) so it
127 # cannot be accelerated
128 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
129 # EC-JPAKE use calloc/free in PSA core
130 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE
131
132 # Accelerate all PSA features (which are still enabled in CRYPTO_CONFIG_H).
133 PSA_SYM_LIST=$(./scripts/config.py -f $CRYPTO_CONFIG_H get-all-enabled PSA_WANT)
134 loc_accel_list=$(echo $PSA_SYM_LIST | sed 's/PSA_WANT_//g')
135
Valerio Settiefce6052024-06-25 18:31:36 +0200136 helper_libtestdriver1_adjust_config crypto
137 helper_libtestdriver1_make_drivers "$loc_accel_list"
138
Valerio Settibc611712024-08-13 13:13:23 +0200139 msg "crypto without heap: build main library"
Valerio Settif7485fb2024-08-13 13:36:50 +0200140 # Disable all legacy MBEDTLS_xxx symbols.
141 scripts/config.py unset-all "^MBEDTLS_"
142 # Build the PSA core using the proper config file.
143 scripts/config.py set MBEDTLS_PSA_CRYPTO_C
144 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
Valerio Settiefce6052024-06-25 18:31:36 +0200145 # Enable fully-static key slots in PSA core.
146 scripts/config.py set MBEDTLS_PSA_STATIC_KEY_SLOTS
Valerio Settif7485fb2024-08-13 13:36:50 +0200147 # Prevent PSA core from creating a copy of input/output buffers.
Valerio Settiefce6052024-06-25 18:31:36 +0200148 scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
149 # Prevent PSA core from using CTR-DRBG or HMAC-DRBG for random generation.
150 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Valerio Settibc611712024-08-13 13:13:23 +0200151 # Set calloc/free as null pointer functions. Calling them would crash
Valerio Settiefce6052024-06-25 18:31:36 +0200152 # the program so we can use this as a "sentinel" for being sure no module
153 # is making use of these functions in the library.
Valerio Settif7485fb2024-08-13 13:36:50 +0200154 scripts/config.py set MBEDTLS_PLATFORM_C
Valerio Settiefce6052024-06-25 18:31:36 +0200155 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
156 scripts/config.py set MBEDTLS_PLATFORM_STD_CALLOC NULL
157 scripts/config.py set MBEDTLS_PLATFORM_STD_FREE NULL
158
Valerio Settiefce6052024-06-25 18:31:36 +0200159 helper_libtestdriver1_make_main "$loc_accel_list" lib
160
Valerio Settibc611712024-08-13 13:13:23 +0200161 msg "crypto without heap: build test suites and helpers"
162 # Reset calloc/free functions to normal operations so that test code can
Valerio Settiefce6052024-06-25 18:31:36 +0200163 # freely use them.
164 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
165 scripts/config.py unset MBEDTLS_PLATFORM_STD_CALLOC
166 scripts/config.py unset MBEDTLS_PLATFORM_STD_FREE
167 helper_libtestdriver1_make_main "$loc_accel_list" tests
168
Valerio Settibc611712024-08-13 13:13:23 +0200169 msg "crypto without heap: test"
Valerio Settiefce6052024-06-25 18:31:36 +0200170 make test
171}
172
Minos Galanakis0c0c3e12024-08-01 22:59:12 +0100173# Get a list of library-wise undefined symbols and ensure that they only
174# belong to psa_xxx() functions and not to mbedtls_yyy() ones.
175# This function is a common helper used by both:
176# - component_test_default_psa_crypto_client_without_crypto_provider
177# - component_build_full_psa_crypto_client_without_crypto_provider.
178common_check_mbedtls_missing_symbols () {
179 nm library/libmbedcrypto.a | grep ' [TRrDC] ' | grep -Eo '(mbedtls_|psa_).*' | sort -u > sym_def.txt
180 nm library/libmbedcrypto.a | grep ' U ' | grep -Eo '(mbedtls_|psa_).*' | sort -u > sym_undef.txt
181 comm sym_def.txt sym_undef.txt -13 > linking_errors.txt
182 not grep mbedtls_ linking_errors.txt
183
184 rm sym_def.txt sym_undef.txt linking_errors.txt
185}
186
187component_test_default_psa_crypto_client_without_crypto_provider () {
188 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
189
190 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
191 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
192 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
193 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
194 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
195 scripts/config.py unset MBEDTLS_LMS_C
David Horstmanncbf530d2024-11-12 14:18:37 +0000196 # Test hooks may rely on functions defined in test helpers, which would
197 # not be built here, leading to a spurious undefined symbol.
198 scripts/config.py unset MBEDTLS_TEST_HOOKS
Minos Galanakis0c0c3e12024-08-01 22:59:12 +0100199
200 make
201
202 msg "check missing symbols: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
203 common_check_mbedtls_missing_symbols
204
205 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
206 make test
207}
208
209component_build_full_psa_crypto_client_without_crypto_provider () {
210 msg "build: full config - PSA_CRYPTO_C"
211
212 # Use full config which includes USE_PSA and CRYPTO_CLIENT.
213 scripts/config.py full
214
215 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
216 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
217 # Dynamic secure element support is a deprecated feature and it is not
218 # available when CRYPTO_C and PSA_CRYPTO_STORAGE_C are disabled.
219 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
David Horstmanncbf530d2024-11-12 14:18:37 +0000220 # Test hooks may rely on functions defined in test helpers, which would
221 # not be built here, leading to a spurious undefined symbol.
222 scripts/config.py unset MBEDTLS_TEST_HOOKS
Minos Galanakis0c0c3e12024-08-01 22:59:12 +0100223
224 # Since there is no crypto provider in this build it is not possible to
225 # build all the test executables and progrems due to missing PSA functions
226 # at link time. Therefore we will just build libraries and we'll check
227 # that symbols of interest are there.
228 make lib
229
230 msg "check missing symbols: full config - PSA_CRYPTO_C"
231
232 common_check_mbedtls_missing_symbols
233
234 # Ensure that desired functions are included into the build (extend the
235 # following list as required).
236 grep mbedtls_pk_get_psa_attributes library/libmbedcrypto.a
237 grep mbedtls_pk_import_into_psa library/libmbedcrypto.a
238 grep mbedtls_pk_copy_from_psa library/libmbedcrypto.a
239}
240
241component_test_psa_crypto_rsa_no_genprime () {
242 msg "build: default config minus MBEDTLS_GENPRIME"
243 scripts/config.py unset MBEDTLS_GENPRIME
244 make
245
246 msg "test: default config minus MBEDTLS_GENPRIME"
247 make test
248}
249
Minos Galanakis3ece57e2024-08-01 17:09:49 +0100250component_test_no_pem_no_fs () {
251 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
252 scripts/config.py unset MBEDTLS_PEM_PARSE_C
253 scripts/config.py unset MBEDTLS_FS_IO
254 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
255 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
256 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
257 make
258
259 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
260 make test
261
262 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
263 tests/ssl-opt.sh
264}
265
266component_test_rsa_no_crt () {
267 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
268 scripts/config.py set MBEDTLS_RSA_NO_CRT
269 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
270 make
271
272 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
273 make test
274
275 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
276 tests/ssl-opt.sh -f RSA
277
278 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
279 tests/compat.sh -t RSA
280
281 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
282 tests/context-info.sh
283}
284
Gilles Peskine4d347aa2024-09-19 18:55:08 +0200285component_test_config_no_entropy () {
286 msg "build: configs/config-no-entropy.h"
287 cp configs/config-no-entropy.h "$CONFIG_H"
288 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
289 # want to re-generate generated files that depend on it, quite correctly.
290 # However this doesn't work as the generation script expects a specific
291 # format for mbedtls_config.h, which the other files don't follow. Also,
292 # cmake can't know this, but re-generation is actually not necessary as
293 # the generated files only depend on the list of available options, not
294 # whether they're on or off. So, disable cmake's (over-sensitive here)
295 # dependency resolution for generated files and just rely on them being
296 # present (thanks to pre_generate_files) by turning GEN_FILES off.
297 CC=$ASAN_CC cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
298 make
299
300 msg "test: configs/config-no-entropy.h - unit tests"
301 make test
302}
303
Minos Galanakis3ece57e2024-08-01 17:09:49 +0100304component_test_no_ctr_drbg_classic () {
305 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
306 scripts/config.py full
307 scripts/config.py unset MBEDTLS_CTR_DRBG_C
308 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
309 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
310
311 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
312 make
313
314 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
315 make test
316
317 # In this configuration, the TLS test programs use HMAC_DRBG.
318 # The SSL tests are slow, so run a small subset, just enough to get
319 # confidence that the SSL code copes with HMAC_DRBG.
320 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
321 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
322
323 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
324 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
325}
326
327component_test_no_ctr_drbg_use_psa () {
328 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
329 scripts/config.py full
330 scripts/config.py unset MBEDTLS_CTR_DRBG_C
331 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
332
333 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
334 make
335
336 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
337 make test
338
339 # In this configuration, the TLS test programs use HMAC_DRBG.
340 # The SSL tests are slow, so run a small subset, just enough to get
341 # confidence that the SSL code copes with HMAC_DRBG.
342 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
343 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
344
345 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
346 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
347}
348
349component_test_no_hmac_drbg_classic () {
350 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
351 scripts/config.py full
352 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
353 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
354 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
355 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
356
357 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
358 make
359
360 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
361 make test
362
363 # Normally our ECDSA implementation uses deterministic ECDSA. But since
364 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
365 # instead.
366 # Test SSL with non-deterministic ECDSA. Only test features that
367 # might be affected by how ECDSA signature is performed.
368 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
369 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
370
371 # To save time, only test one protocol version, since this part of
372 # the protocol is identical in (D)TLS up to 1.2.
373 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
374 tests/compat.sh -m tls12 -t 'ECDSA'
375}
376
377component_test_no_hmac_drbg_use_psa () {
378 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
379 scripts/config.py full
380 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
381 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
382 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
383
384 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
385 make
386
387 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
388 make test
389
390 # Normally our ECDSA implementation uses deterministic ECDSA. But since
391 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
392 # instead.
393 # Test SSL with non-deterministic ECDSA. Only test features that
394 # might be affected by how ECDSA signature is performed.
395 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
396 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
397
398 # To save time, only test one protocol version, since this part of
399 # the protocol is identical in (D)TLS up to 1.2.
400 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
401 tests/compat.sh -m tls12 -t 'ECDSA'
402}
403
404component_test_psa_external_rng_no_drbg_classic () {
405 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
406 scripts/config.py full
407 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
408 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
409 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
410 scripts/config.py unset MBEDTLS_ENTROPY_C
411 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
412 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
413 scripts/config.py unset MBEDTLS_CTR_DRBG_C
414 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
415 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
416 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
417 # the SSL test programs don't have an RNG and can't work. Explicitly
418 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
419 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
420
421 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
422 make test
423
424 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
425 tests/ssl-opt.sh -f 'Default'
426}
427
428component_test_psa_external_rng_no_drbg_use_psa () {
429 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
430 scripts/config.py full
431 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
432 scripts/config.py unset MBEDTLS_ENTROPY_C
433 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
434 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
435 scripts/config.py unset MBEDTLS_CTR_DRBG_C
436 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
437 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
438 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
439
440 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
441 make test
442
443 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
444 tests/ssl-opt.sh -f 'Default\|opaque'
445}
446
447component_test_psa_external_rng_use_psa_crypto () {
448 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
449 scripts/config.py full
450 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
451 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
452 scripts/config.py unset MBEDTLS_CTR_DRBG_C
453 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
454
455 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
456 make test
457
458 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
459 tests/ssl-opt.sh -f 'Default\|opaque'
460}
461
Gilles Peskinebd6fb462025-06-06 10:18:36 +0200462component_test_entropy_nv_seed_only () {
Gilles Peskine361799a2025-06-06 14:51:54 +0200463 msg "build: full minus platform entropy (NV seed only)"
Gilles Peskinebd6fb462025-06-06 10:18:36 +0200464 scripts/config.py full
465 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY
466 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
467
Gilles Peskine361799a2025-06-06 14:51:54 +0200468 msg "build: full minus platform entropy (NV seed only)"
Gilles Peskinebd6fb462025-06-06 10:18:36 +0200469 make test
470
471 # Check that the library seems to refer to the seedfile, but not to
472 # platform entropy sources.
473 grep seedfile library/platform.o
474 not grep getrandom library/entropy*.o
475 not grep /dev/random library/entropy*.o
476 not grep /dev/.random library/entropy*.o
477}
478
Minos Galanakis3ece57e2024-08-01 17:09:49 +0100479component_test_psa_inject_entropy () {
480 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
481 scripts/config.py full
482 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
483 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
484 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
485 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
486 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
487 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
488 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
489
490 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
491 make test
492}
493
494component_full_no_pkparse_pkwrite () {
495 msg "build: full without pkparse and pkwrite"
496
497 scripts/config.py crypto_full
498 scripts/config.py unset MBEDTLS_PK_PARSE_C
499 scripts/config.py unset MBEDTLS_PK_WRITE_C
500
501 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
502
503 # Ensure that PK_[PARSE|WRITE]_C were not re-enabled accidentally (additive config).
504 not grep mbedtls_pk_parse_key library/pkparse.o
505 not grep mbedtls_pk_write_key_der library/pkwrite.o
506
507 msg "test: full without pkparse and pkwrite"
508 make test
509}
510
511component_test_crypto_full_md_light_only () {
512 msg "build: crypto_full with only the light subset of MD"
513 scripts/config.py crypto_full
514 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
515 # Disable MD
516 scripts/config.py unset MBEDTLS_MD_C
517 # Disable direct dependencies of MD_C
518 scripts/config.py unset MBEDTLS_HKDF_C
519 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
520 scripts/config.py unset MBEDTLS_PKCS7_C
521 # Disable indirect dependencies of MD_C
522 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG
523 # Disable things that would auto-enable MD_C
524 scripts/config.py unset MBEDTLS_PKCS5_C
525
526 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
527 # which we haven't disabled, so no need to explicitly enable it.
528 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
529
530 # Make sure we don't have the HMAC functions, but the hashing functions
531 not grep mbedtls_md_hmac library/md.o
532 grep mbedtls_md library/md.o
533
534 msg "test: crypto_full with only the light subset of MD"
535 make test
536}
537
Minos Galanakis0c0c3e12024-08-01 22:59:12 +0100538component_test_full_no_cipher_no_psa_crypto () {
539 msg "build: full no CIPHER no PSA_CRYPTO_C"
540 scripts/config.py full
541 scripts/config.py unset MBEDTLS_CIPHER_C
542 # Don't pull in cipher via PSA mechanisms
543 # (currently ignored anyway because we completely disable PSA)
544 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
545 # Disable features that depend on CIPHER_C
546 scripts/config.py unset MBEDTLS_CMAC_C
547 scripts/config.py unset MBEDTLS_NIST_KW_C
548 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
549 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CLIENT
550 scripts/config.py unset MBEDTLS_SSL_TLS_C
551 scripts/config.py unset MBEDTLS_SSL_TICKET_C
552 # Disable features that depend on PSA_CRYPTO_C
553 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
554 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
555 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
556 scripts/config.py unset MBEDTLS_LMS_C
557 scripts/config.py unset MBEDTLS_LMS_PRIVATE
558
559 msg "test: full no CIPHER no PSA_CRYPTO_C"
560 make test
561}
562
563# This is a common configurator and test function that is used in:
564# - component_test_full_no_cipher_with_psa_crypto
565# - component_test_full_no_cipher_with_psa_crypto_config
566# It accepts 2 input parameters:
567# - $1: boolean value which basically reflects status of MBEDTLS_PSA_CRYPTO_CONFIG
568# - $2: a text string which describes the test component
569common_test_full_no_cipher_with_psa_crypto () {
570 USE_CRYPTO_CONFIG="$1"
571 COMPONENT_DESCRIPTION="$2"
572
573 msg "build: $COMPONENT_DESCRIPTION"
574
575 scripts/config.py full
576 scripts/config.py unset MBEDTLS_CIPHER_C
577
578 if [ "$USE_CRYPTO_CONFIG" -eq 1 ]; then
579 # The built-in implementation of the following algs/key-types depends
580 # on CIPHER_C so we disable them.
581 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
582 # so we keep them enabled.
583 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
584 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CMAC
585 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
586 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
587 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CFB
588 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CTR
589 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
590 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_OFB
591 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
592 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_STREAM_CIPHER
593 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
594 else
595 # Don't pull in cipher via PSA mechanisms
596 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
597 # Disable cipher modes/keys that make PSA depend on CIPHER_C.
598 # Keep CHACHA20 and CHACHAPOLY enabled since they do not depend on CIPHER_C.
599 scripts/config.py unset-all MBEDTLS_CIPHER_MODE
600 fi
601 # The following modules directly depends on CIPHER_C
602 scripts/config.py unset MBEDTLS_CMAC_C
603 scripts/config.py unset MBEDTLS_NIST_KW_C
604
605 make
606
607 # Ensure that CIPHER_C was not re-enabled
608 not grep mbedtls_cipher_init library/cipher.o
609
610 msg "test: $COMPONENT_DESCRIPTION"
611 make test
612}
613
614component_test_full_no_cipher_with_psa_crypto () {
615 common_test_full_no_cipher_with_psa_crypto 0 "full no CIPHER no CRYPTO_CONFIG"
616}
617
618component_test_full_no_cipher_with_psa_crypto_config () {
619 common_test_full_no_cipher_with_psa_crypto 1 "full no CIPHER"
620}
621
Minos Galanakis3ece57e2024-08-01 17:09:49 +0100622component_test_full_no_ccm () {
623 msg "build: full no PSA_WANT_ALG_CCM"
624
625 # Full config enables:
626 # - USE_PSA_CRYPTO so that TLS code dispatches cipher/AEAD to PSA
627 # - CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
628 scripts/config.py full
629
630 # Disable PSA_WANT_ALG_CCM so that CCM is not supported in PSA. CCM_C is still
631 # enabled, but not used from TLS since USE_PSA is set.
632 # This is helpful to ensure that TLS tests below have proper dependencies.
633 #
634 # Note: also PSA_WANT_ALG_CCM_STAR_NO_TAG is enabled, but it does not cause
635 # PSA_WANT_ALG_CCM to be re-enabled.
636 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM
637
638 make
639
640 msg "test: full no PSA_WANT_ALG_CCM"
641 make test
642}
643
644component_test_full_no_ccm_star_no_tag () {
645 msg "build: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
646
647 # Full config enables CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
648 scripts/config.py full
649
650 # Disable CCM_STAR_NO_TAG, which is the target of this test, as well as all
651 # other components that enable MBEDTLS_PSA_BUILTIN_CIPHER internal symbol.
652 # This basically disables all unauthenticated ciphers on the PSA side, while
653 # keeping AEADs enabled.
654 #
655 # Note: PSA_WANT_ALG_CCM is enabled, but it does not cause
656 # PSA_WANT_ALG_CCM_STAR_NO_TAG to be re-enabled.
657 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
658 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_STREAM_CIPHER
659 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
660 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
661 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
662 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
663 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
664 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
665
666 make
667
668 # Ensure MBEDTLS_PSA_BUILTIN_CIPHER was not enabled
669 not grep mbedtls_psa_cipher library/psa_crypto_cipher.o
670
671 msg "test: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
672 make test
673}
674
Gilles Peskinedbd0f422024-09-14 11:27:44 +0200675component_test_config_symmetric_only_legacy () {
676 msg "build: configs/config-symmetric-only.h"
677 cp configs/config-symmetric-only.h "$CONFIG_H"
678 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
679 # want to re-generate generated files that depend on it, quite correctly.
680 # However this doesn't work as the generation script expects a specific
681 # format for mbedtls_config.h, which the other files don't follow. Also,
682 # cmake can't know this, but re-generation is actually not necessary as
683 # the generated files only depend on the list of available options, not
684 # whether they're on or off. So, disable cmake's (over-sensitive here)
685 # dependency resolution for generated files and just rely on them being
686 # present (thanks to pre_generate_files) by turning GEN_FILES off.
687 CC=$ASAN_CC cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
688 make
689
690 msg "test: configs/config-symmetric-only.h - unit tests"
691 make test
692}
693
694component_test_config_symmetric_only_psa () {
695 msg "build: configs/config-symmetric-only.h + USE_PSA_CRYPTO"
696 cp configs/config-symmetric-only.h "$CONFIG_H"
697 scripts/config.py set MBEDTLS_PSA_CRYPTO_C
698 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
699 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
700 # want to re-generate generated files that depend on it, quite correctly.
701 # However this doesn't work as the generation script expects a specific
702 # format for mbedtls_config.h, which the other files don't follow. Also,
703 # cmake can't know this, but re-generation is actually not necessary as
704 # the generated files only depend on the list of available options, not
705 # whether they're on or off. So, disable cmake's (over-sensitive here)
706 # dependency resolution for generated files and just rely on them being
707 # present (thanks to pre_generate_files) by turning GEN_FILES off.
708 CC=$ASAN_CC cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
709 make
710
711 msg "test: configs/config-symmetric-only.h + USE_PSA_CRYPTO - unit tests"
712 make test
713}
714
Minos Galanakis0c0c3e12024-08-01 22:59:12 +0100715component_test_full_no_bignum () {
716 msg "build: full minus bignum"
717 scripts/config.py full
718 scripts/config.py unset MBEDTLS_BIGNUM_C
719 # Direct dependencies of bignum
720 scripts/config.py unset MBEDTLS_ECP_C
721 scripts/config.py unset MBEDTLS_RSA_C
722 scripts/config.py unset MBEDTLS_DHM_C
723 # Direct dependencies of ECP
724 scripts/config.py unset MBEDTLS_ECDH_C
725 scripts/config.py unset MBEDTLS_ECDSA_C
726 scripts/config.py unset MBEDTLS_ECJPAKE_C
727 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
728 # Disable what auto-enables ECP_LIGHT
729 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
730 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
731 # Indirect dependencies of ECP
732 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
733 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
734 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
735 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
736 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
737 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
738 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
739 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
740 # Direct dependencies of DHM
741 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
742 # Direct dependencies of RSA
743 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
744 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
745 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
746 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
747 # PK and its dependencies
748 scripts/config.py unset MBEDTLS_PK_C
749 scripts/config.py unset MBEDTLS_PK_PARSE_C
750 scripts/config.py unset MBEDTLS_PK_WRITE_C
751 scripts/config.py unset MBEDTLS_X509_USE_C
752 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
753 scripts/config.py unset MBEDTLS_X509_CRL_PARSE_C
754 scripts/config.py unset MBEDTLS_X509_CSR_PARSE_C
755 scripts/config.py unset MBEDTLS_X509_CREATE_C
756 scripts/config.py unset MBEDTLS_X509_CRT_WRITE_C
757 scripts/config.py unset MBEDTLS_X509_CSR_WRITE_C
758 scripts/config.py unset MBEDTLS_PKCS7_C
759 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
760 scripts/config.py unset MBEDTLS_SSL_ASYNC_PRIVATE
761 scripts/config.py unset MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
762
763 make
764
765 msg "test: full minus bignum"
766 make test
767}
768
769component_build_dhm_alt () {
770 msg "build: MBEDTLS_DHM_ALT" # ~30s
771 scripts/config.py full
772 scripts/config.py set MBEDTLS_DHM_ALT
773 # debug.c currently references mbedtls_dhm_context fields directly.
774 scripts/config.py unset MBEDTLS_DEBUG_C
775 # We can only compile, not link, since we don't have any implementations
776 # suitable for testing with the dummy alt headers.
777 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
778}
779
Minos Galanakis3ece57e2024-08-01 17:09:49 +0100780component_test_everest () {
781 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
782 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
783 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
784 make
785
786 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
787 make test
788
789 msg "test: metatests (clang, ASan)"
790 tests/scripts/run-metatests.sh any asan poison
791
792 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
793 tests/ssl-opt.sh -f ECDH
794
795 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
796 # Exclude some symmetric ciphers that are redundant here to gain time.
797 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
798}
799
800component_test_everest_curve25519_only () {
801 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
802 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
803 scripts/config.py unset MBEDTLS_ECDSA_C
804 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
805 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
806 scripts/config.py unset MBEDTLS_ECJPAKE_C
807 # Disable all curves
808 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
809 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
810
811 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
812
813 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
814 make test
815}
816
817component_test_psa_collect_statuses () {
818 msg "build+test: psa_collect_statuses" # ~30s
819 scripts/config.py full
820 tests/scripts/psa_collect_statuses.py
821 # Check that psa_crypto_init() succeeded at least once
822 grep -q '^0:psa_crypto_init:' tests/statuses.log
823 rm -f tests/statuses.log
824}
825
826# Check that the specified libraries exist and are empty.
827are_empty_libraries () {
828 nm "$@" >/dev/null 2>/dev/null
829 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
830}
831
832component_build_crypto_default () {
833 msg "build: make, crypto only"
834 scripts/config.py crypto
835 make CFLAGS='-O1 -Werror'
836 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
837}
838
839component_build_crypto_full () {
840 msg "build: make, crypto only, full config"
841 scripts/config.py crypto_full
842 make CFLAGS='-O1 -Werror'
843 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
844}
845
846component_test_crypto_for_psa_service () {
847 msg "build: make, config for PSA crypto service"
848 scripts/config.py crypto
849 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
850 # Disable things that are not needed for just cryptography, to
851 # reach a configuration that would be typical for a PSA cryptography
852 # service providing all implemented PSA algorithms.
853 # System stuff
854 scripts/config.py unset MBEDTLS_ERROR_C
855 scripts/config.py unset MBEDTLS_TIMING_C
856 scripts/config.py unset MBEDTLS_VERSION_FEATURES
857 # Crypto stuff with no PSA interface
858 scripts/config.py unset MBEDTLS_BASE64_C
859 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
860 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
861 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
862 scripts/config.py unset MBEDTLS_NIST_KW_C
863 scripts/config.py unset MBEDTLS_PEM_PARSE_C
864 scripts/config.py unset MBEDTLS_PEM_WRITE_C
865 scripts/config.py unset MBEDTLS_PKCS12_C
866 scripts/config.py unset MBEDTLS_PKCS5_C
867 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
868 # in PSA code to work with RSA keys. We don't require users to set those:
869 # they will be reenabled in build_info.h.
870 scripts/config.py unset MBEDTLS_PK_C
871 scripts/config.py unset MBEDTLS_PK_PARSE_C
872 scripts/config.py unset MBEDTLS_PK_WRITE_C
873 make CFLAGS='-O1 -Werror' all test
874 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
875}
876
877component_build_crypto_baremetal () {
878 msg "build: make, crypto only, baremetal config"
879 scripts/config.py crypto_baremetal
David Horstmanndcf42a02024-11-08 14:40:12 +0000880 make CFLAGS="-O1 -Werror -I$PWD/framework/tests/include/baremetal-override/"
Minos Galanakis3ece57e2024-08-01 17:09:49 +0100881 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
882}
883
884support_build_crypto_baremetal () {
885 support_build_baremetal "$@"
886}
887
888# depends.py family of tests
889component_test_depends_py_cipher_id () {
890 msg "test/build: depends.py cipher_id (gcc)"
891 tests/scripts/depends.py cipher_id --unset-use-psa
892}
893
894component_test_depends_py_cipher_chaining () {
895 msg "test/build: depends.py cipher_chaining (gcc)"
896 tests/scripts/depends.py cipher_chaining --unset-use-psa
897}
898
899component_test_depends_py_cipher_padding () {
900 msg "test/build: depends.py cipher_padding (gcc)"
901 tests/scripts/depends.py cipher_padding --unset-use-psa
902}
903
904component_test_depends_py_curves () {
905 msg "test/build: depends.py curves (gcc)"
906 tests/scripts/depends.py curves --unset-use-psa
907}
908
909component_test_depends_py_hashes () {
910 msg "test/build: depends.py hashes (gcc)"
911 tests/scripts/depends.py hashes --unset-use-psa
912}
913
914component_test_depends_py_pkalgs () {
915 msg "test/build: depends.py pkalgs (gcc)"
916 tests/scripts/depends.py pkalgs --unset-use-psa
917}
918
919# PSA equivalents of the depends.py tests
920component_test_depends_py_cipher_id_psa () {
921 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
922 tests/scripts/depends.py cipher_id
923}
924
925component_test_depends_py_cipher_chaining_psa () {
926 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
927 tests/scripts/depends.py cipher_chaining
928}
929
930component_test_depends_py_cipher_padding_psa () {
931 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
932 tests/scripts/depends.py cipher_padding
933}
934
935component_test_depends_py_curves_psa () {
936 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
937 tests/scripts/depends.py curves
938}
939
940component_test_depends_py_hashes_psa () {
941 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
942 tests/scripts/depends.py hashes
943}
944
945component_test_depends_py_pkalgs_psa () {
946 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
947 tests/scripts/depends.py pkalgs
948}
949
950component_test_psa_crypto_config_ffdh_2048_only () {
951 msg "build: full config - only DH 2048"
952
953 scripts/config.py full
954
955 # Disable all DH groups other than 2048.
956 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_3072
957 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_4096
958 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_6144
959 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_8192
960
961 make CFLAGS="$ASAN_CFLAGS -Werror" LDFLAGS="$ASAN_CFLAGS"
962
963 msg "test: full config - only DH 2048"
964 make test
965
966 msg "ssl-opt: full config - only DH 2048"
967 tests/ssl-opt.sh -f "ffdh"
968}
969
970component_build_no_pk_rsa_alt_support () {
971 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
972
973 scripts/config.py full
974 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
975 scripts/config.py set MBEDTLS_RSA_C
976 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
977
978 # Only compile - this is primarily to test for compile issues
979 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
980}
981
982component_build_module_alt () {
983 msg "build: MBEDTLS_XXX_ALT" # ~30s
984 scripts/config.py full
985
986 # Disable options that are incompatible with some ALT implementations:
987 # aesni.c and padlock.c reference mbedtls_aes_context fields directly.
988 scripts/config.py unset MBEDTLS_AESNI_C
989 scripts/config.py unset MBEDTLS_PADLOCK_C
990 scripts/config.py unset MBEDTLS_AESCE_C
991 # MBEDTLS_ECP_RESTARTABLE is documented as incompatible.
992 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
993 # You can only have one threading implementation: alt or pthread, not both.
994 scripts/config.py unset MBEDTLS_THREADING_PTHREAD
995 # The SpecifiedECDomain parsing code accesses mbedtls_ecp_group fields
996 # directly and assumes the implementation works with partial groups.
997 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
998 # MBEDTLS_SHA256_*ALT can't be used with MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*
999 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
1000 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
1001 # MBEDTLS_SHA512_*ALT can't be used with MBEDTLS_SHA512_USE_A64_CRYPTO_*
1002 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
1003 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
1004
1005 # Enable all MBEDTLS_XXX_ALT for whole modules. Do not enable
1006 # MBEDTLS_XXX_YYY_ALT which are for single functions.
1007 scripts/config.py set-all 'MBEDTLS_([A-Z0-9]*|NIST_KW)_ALT'
1008 scripts/config.py unset MBEDTLS_DHM_ALT #incompatible with MBEDTLS_DEBUG_C
1009
1010 # We can only compile, not link, since we don't have any implementations
1011 # suitable for testing with the dummy alt headers.
1012 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
1013}
1014
1015component_test_psa_crypto_config_accel_ecdsa () {
1016 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1017
1018 # Algorithms and key types to accelerate
1019 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1020 $(helper_get_psa_key_type_list "ECC") \
1021 $(helper_get_psa_curve_list)"
1022
1023 # Configure
1024 # ---------
1025
1026 # Start from default config (no USE_PSA) + TLS 1.3
1027 helper_libtestdriver1_adjust_config "default"
1028
1029 # Disable the module that's accelerated
1030 scripts/config.py unset MBEDTLS_ECDSA_C
1031
1032 # Disable things that depend on it
1033 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1034 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1035
1036 # Build
1037 # -----
1038
1039 # These hashes are needed for some ECDSA signature tests.
Elena Uziunaitefbab4f82024-09-12 14:58:52 +01001040 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001041 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1042
1043 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1044
1045 helper_libtestdriver1_make_main "$loc_accel_list"
1046
1047 # Make sure this was not re-enabled by accident (additive config)
1048 not grep mbedtls_ecdsa_ library/ecdsa.o
1049
1050 # Run the tests
1051 # -------------
1052
1053 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1054 make test
1055}
1056
1057component_test_psa_crypto_config_accel_ecdh () {
1058 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
1059
1060 # Algorithms and key types to accelerate
1061 loc_accel_list="ALG_ECDH \
1062 $(helper_get_psa_key_type_list "ECC") \
1063 $(helper_get_psa_curve_list)"
1064
1065 # Configure
1066 # ---------
1067
1068 # Start from default config (no USE_PSA)
1069 helper_libtestdriver1_adjust_config "default"
1070
1071 # Disable the module that's accelerated
1072 scripts/config.py unset MBEDTLS_ECDH_C
1073
1074 # Disable things that depend on it
1075 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1076 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1077 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1078 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1079 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1080
1081 # Build
1082 # -----
1083
1084 helper_libtestdriver1_make_drivers "$loc_accel_list"
1085
1086 helper_libtestdriver1_make_main "$loc_accel_list"
1087
1088 # Make sure this was not re-enabled by accident (additive config)
1089 not grep mbedtls_ecdh_ library/ecdh.o
1090
1091 # Run the tests
1092 # -------------
1093
1094 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
1095 make test
1096}
1097
1098component_test_psa_crypto_config_accel_ffdh () {
1099 msg "build: full with accelerated FFDH"
1100
1101 # Algorithms and key types to accelerate
1102 loc_accel_list="ALG_FFDH \
1103 $(helper_get_psa_key_type_list "DH") \
1104 $(helper_get_psa_dh_group_list)"
1105
1106 # Configure
1107 # ---------
1108
1109 # start with full (USE_PSA and TLS 1.3)
1110 helper_libtestdriver1_adjust_config "full"
1111
1112 # Disable the module that's accelerated
1113 scripts/config.py unset MBEDTLS_DHM_C
1114
1115 # Disable things that depend on it
1116 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1117 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1118
1119 # Build
1120 # -----
1121
1122 helper_libtestdriver1_make_drivers "$loc_accel_list"
1123
1124 helper_libtestdriver1_make_main "$loc_accel_list"
1125
1126 # Make sure this was not re-enabled by accident (additive config)
1127 not grep mbedtls_dhm_ library/dhm.o
1128
1129 # Run the tests
1130 # -------------
1131
1132 msg "test: full with accelerated FFDH"
1133 make test
1134
1135 msg "ssl-opt: full with accelerated FFDH alg"
1136 tests/ssl-opt.sh -f "ffdh"
1137}
1138
1139component_test_psa_crypto_config_reference_ffdh () {
1140 msg "build: full with non-accelerated FFDH"
1141
1142 # Start with full (USE_PSA and TLS 1.3)
1143 helper_libtestdriver1_adjust_config "full"
1144
1145 # Disable things that are not supported
1146 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1147 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1148 make
1149
1150 msg "test suites: full with non-accelerated FFDH alg"
1151 make test
1152
1153 msg "ssl-opt: full with non-accelerated FFDH alg"
1154 tests/ssl-opt.sh -f "ffdh"
1155}
1156
1157component_test_psa_crypto_config_accel_pake () {
1158 msg "build: full with accelerated PAKE"
1159
1160 loc_accel_list="ALG_JPAKE \
1161 $(helper_get_psa_key_type_list "ECC") \
1162 $(helper_get_psa_curve_list)"
1163
1164 # Configure
1165 # ---------
1166
1167 helper_libtestdriver1_adjust_config "full"
1168
1169 # Make built-in fallback not available
1170 scripts/config.py unset MBEDTLS_ECJPAKE_C
1171 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
1172
1173 # Build
1174 # -----
1175
1176 helper_libtestdriver1_make_drivers "$loc_accel_list"
1177
1178 helper_libtestdriver1_make_main "$loc_accel_list"
1179
1180 # Make sure this was not re-enabled by accident (additive config)
1181 not grep mbedtls_ecjpake_init library/ecjpake.o
1182
1183 # Run the tests
1184 # -------------
1185
1186 msg "test: full with accelerated PAKE"
1187 make test
1188}
1189
1190component_test_psa_crypto_config_accel_ecc_some_key_types () {
1191 msg "build: full with accelerated EC algs and some key types"
1192
1193 # Algorithms and key types to accelerate
1194 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
1195 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1196 ALG_ECDH \
1197 ALG_JPAKE \
1198 KEY_TYPE_ECC_PUBLIC_KEY \
1199 KEY_TYPE_ECC_KEY_PAIR_BASIC \
1200 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
1201 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
1202 $(helper_get_psa_curve_list)"
1203
1204 # Configure
1205 # ---------
1206
1207 # start with config full for maximum coverage (also enables USE_PSA)
1208 helper_libtestdriver1_adjust_config "full"
1209
1210 # Disable modules that are accelerated - some will be re-enabled
1211 scripts/config.py unset MBEDTLS_ECDSA_C
1212 scripts/config.py unset MBEDTLS_ECDH_C
1213 scripts/config.py unset MBEDTLS_ECJPAKE_C
1214 scripts/config.py unset MBEDTLS_ECP_C
1215
1216 # Disable all curves - those that aren't accelerated should be re-enabled
1217 helper_disable_builtin_curves
1218
1219 # Restartable feature is not yet supported by PSA. Once it will in
1220 # the future, the following line could be removed (see issues
1221 # 6061, 6332 and following ones)
1222 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1223
1224 # this is not supported by the driver API yet
1225 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1226
1227 # Build
1228 # -----
1229
1230 # These hashes are needed for some ECDSA signature tests.
1231 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1232 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1233 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1234
1235 helper_libtestdriver1_make_main "$loc_accel_list"
1236
1237 # ECP should be re-enabled but not the others
1238 not grep mbedtls_ecdh_ library/ecdh.o
1239 not grep mbedtls_ecdsa library/ecdsa.o
1240 not grep mbedtls_ecjpake library/ecjpake.o
1241 grep mbedtls_ecp library/ecp.o
1242
1243 # Run the tests
1244 # -------------
1245
1246 msg "test suites: full with accelerated EC algs and some key types"
1247 make test
1248}
1249
1250# Run tests with only (non-)Weierstrass accelerated
1251# Common code used in:
1252# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
1253# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
1254common_test_psa_crypto_config_accel_ecc_some_curves () {
1255 weierstrass=$1
1256 if [ $weierstrass -eq 1 ]; then
1257 desc="Weierstrass"
1258 else
1259 desc="non-Weierstrass"
1260 fi
1261
1262 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
1263
1264 # Note: Curves are handled in a special way by the libtestdriver machinery,
1265 # so we only want to include them in the accel list when building the main
1266 # libraries, hence the use of a separate variable.
1267 # Note: the following loop is a modified version of
1268 # helper_get_psa_curve_list that only keeps Weierstrass families.
1269 loc_weierstrass_list=""
1270 loc_non_weierstrass_list=""
1271 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
1272 case $item in
1273 ECC_BRAINPOOL*|ECC_SECP*)
1274 loc_weierstrass_list="$loc_weierstrass_list $item"
1275 ;;
1276 *)
1277 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
1278 ;;
1279 esac
1280 done
1281 if [ $weierstrass -eq 1 ]; then
1282 loc_curve_list=$loc_weierstrass_list
1283 else
1284 loc_curve_list=$loc_non_weierstrass_list
1285 fi
1286
1287 # Algorithms and key types to accelerate
1288 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1289 ALG_ECDH \
1290 ALG_JPAKE \
1291 $(helper_get_psa_key_type_list "ECC") \
1292 $loc_curve_list"
1293
1294 # Configure
1295 # ---------
1296
1297 # Start with config crypto_full and remove PK_C:
1298 # that's what's supported now, see docs/driver-only-builds.md.
1299 helper_libtestdriver1_adjust_config "crypto_full"
1300 scripts/config.py unset MBEDTLS_PK_C
1301 scripts/config.py unset MBEDTLS_PK_PARSE_C
1302 scripts/config.py unset MBEDTLS_PK_WRITE_C
1303
1304 # Disable modules that are accelerated - some will be re-enabled
1305 scripts/config.py unset MBEDTLS_ECDSA_C
1306 scripts/config.py unset MBEDTLS_ECDH_C
1307 scripts/config.py unset MBEDTLS_ECJPAKE_C
1308 scripts/config.py unset MBEDTLS_ECP_C
1309
1310 # Disable all curves - those that aren't accelerated should be re-enabled
1311 helper_disable_builtin_curves
1312
1313 # Restartable feature is not yet supported by PSA. Once it will in
1314 # the future, the following line could be removed (see issues
1315 # 6061, 6332 and following ones)
1316 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1317
1318 # this is not supported by the driver API yet
1319 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1320
1321 # Build
1322 # -----
1323
1324 # These hashes are needed for some ECDSA signature tests.
1325 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1326 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1327 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1328
1329 helper_libtestdriver1_make_main "$loc_accel_list"
1330
1331 # We expect ECDH to be re-enabled for the missing curves
1332 grep mbedtls_ecdh_ library/ecdh.o
1333 # We expect ECP to be re-enabled, however the parts specific to the
1334 # families of curves that are accelerated should be ommited.
1335 # - functions with mxz in the name are specific to Montgomery curves
1336 # - ecp_muladd is specific to Weierstrass curves
1337 ##nm library/ecp.o | tee ecp.syms
1338 if [ $weierstrass -eq 1 ]; then
1339 not grep mbedtls_ecp_muladd library/ecp.o
1340 grep mxz library/ecp.o
1341 else
1342 grep mbedtls_ecp_muladd library/ecp.o
1343 not grep mxz library/ecp.o
1344 fi
1345 # We expect ECDSA and ECJPAKE to be re-enabled only when
1346 # Weierstrass curves are not accelerated
1347 if [ $weierstrass -eq 1 ]; then
1348 not grep mbedtls_ecdsa library/ecdsa.o
1349 not grep mbedtls_ecjpake library/ecjpake.o
1350 else
1351 grep mbedtls_ecdsa library/ecdsa.o
1352 grep mbedtls_ecjpake library/ecjpake.o
1353 fi
1354
1355 # Run the tests
1356 # -------------
1357
1358 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
1359 make test
1360}
1361
1362component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
1363 common_test_psa_crypto_config_accel_ecc_some_curves 1
1364}
1365
1366component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
1367 common_test_psa_crypto_config_accel_ecc_some_curves 0
1368}
1369
1370# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
1371# ECDH, ECDSA) with and without drivers.
1372# The input parameter is a boolean value which indicates:
1373# - 0 keep built-in EC algs,
1374# - 1 exclude built-in EC algs (driver only).
1375#
1376# This is used by the two following components to ensure they always use the
1377# same config, except for the use of driver or built-in EC algorithms:
1378# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
1379# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
1380# This supports comparing their test coverage with analyze_outcomes.py.
1381config_psa_crypto_config_ecp_light_only () {
1382 driver_only="$1"
1383 # start with config full for maximum coverage (also enables USE_PSA)
1384 helper_libtestdriver1_adjust_config "full"
1385 if [ "$driver_only" -eq 1 ]; then
1386 # Disable modules that are accelerated
1387 scripts/config.py unset MBEDTLS_ECDSA_C
1388 scripts/config.py unset MBEDTLS_ECDH_C
1389 scripts/config.py unset MBEDTLS_ECJPAKE_C
1390 scripts/config.py unset MBEDTLS_ECP_C
1391 fi
1392
1393 # Restartable feature is not yet supported by PSA. Once it will in
1394 # the future, the following line could be removed (see issues
1395 # 6061, 6332 and following ones)
1396 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1397}
1398
1399# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
1400component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
1401 msg "build: full with accelerated EC algs"
1402
1403 # Algorithms and key types to accelerate
1404 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1405 ALG_ECDH \
1406 ALG_JPAKE \
1407 $(helper_get_psa_key_type_list "ECC") \
1408 $(helper_get_psa_curve_list)"
1409
1410 # Configure
1411 # ---------
1412
1413 # Use the same config as reference, only without built-in EC algs
1414 config_psa_crypto_config_ecp_light_only 1
1415
1416 # Do not disable builtin curves because that support is required for:
1417 # - MBEDTLS_PK_PARSE_EC_EXTENDED
1418 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
1419
1420 # Build
1421 # -----
1422
1423 # These hashes are needed for some ECDSA signature tests.
1424 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1425 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
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_ library/ecdsa.o
1432 not grep mbedtls_ecdh_ library/ecdh.o
1433 not grep mbedtls_ecjpake_ library/ecjpake.o
1434 not grep mbedtls_ecp_mul library/ecp.o
1435
1436 # Run the tests
1437 # -------------
1438
1439 msg "test suites: full with accelerated EC algs"
1440 make test
1441
1442 msg "ssl-opt: full with accelerated EC algs"
1443 tests/ssl-opt.sh
1444}
1445
1446# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
1447component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
1448 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated EC algs"
1449
1450 config_psa_crypto_config_ecp_light_only 0
1451
1452 make
1453
1454 msg "test suites: full with non-accelerated EC algs"
1455 make test
1456
1457 msg "ssl-opt: full with non-accelerated EC algs"
1458 tests/ssl-opt.sh
1459}
1460
1461# This helper function is used by:
1462# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
1463# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
1464# to ensure that both tests use the same underlying configuration when testing
1465# driver's coverage with analyze_outcomes.py.
1466#
1467# This functions accepts 1 boolean parameter as follows:
1468# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
1469# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
1470# - 0: include built-in implementation of EC algorithms.
1471#
1472# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
1473# on the ECP module.
1474config_psa_crypto_no_ecp_at_all () {
1475 driver_only="$1"
1476 # start with full config for maximum coverage (also enables USE_PSA)
1477 helper_libtestdriver1_adjust_config "full"
1478
1479 if [ "$driver_only" -eq 1 ]; then
1480 # Disable modules that are accelerated
1481 scripts/config.py unset MBEDTLS_ECDSA_C
1482 scripts/config.py unset MBEDTLS_ECDH_C
1483 scripts/config.py unset MBEDTLS_ECJPAKE_C
1484 # Disable ECP module (entirely)
1485 scripts/config.py unset MBEDTLS_ECP_C
1486 fi
1487
1488 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1489 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1490 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1491 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1492
1493 # Restartable feature is not yet supported by PSA. Once it will in
1494 # the future, the following line could be removed (see issues
1495 # 6061, 6332 and following ones)
1496 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1497}
1498
1499# Build and test a configuration where driver accelerates all EC algs while
1500# all support and dependencies from ECP and ECP_LIGHT are removed on the library
1501# side.
1502#
1503# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
1504component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
1505 msg "build: full + accelerated EC algs - ECP"
1506
1507 # Algorithms and key types to accelerate
1508 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1509 ALG_ECDH \
1510 ALG_JPAKE \
1511 $(helper_get_psa_key_type_list "ECC") \
1512 $(helper_get_psa_curve_list)"
1513
1514 # Configure
1515 # ---------
1516
1517 # Set common configurations between library's and driver's builds
1518 config_psa_crypto_no_ecp_at_all 1
1519 # Disable all the builtin curves. All the required algs are accelerated.
1520 helper_disable_builtin_curves
1521
1522 # Build
1523 # -----
1524
1525 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1526 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1527 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1528 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1529
1530 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1531
1532 helper_libtestdriver1_make_main "$loc_accel_list"
1533
1534 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1535 not grep mbedtls_ecdsa_ library/ecdsa.o
1536 not grep mbedtls_ecdh_ library/ecdh.o
1537 not grep mbedtls_ecjpake_ library/ecjpake.o
1538 # Also ensure that ECP module was not re-enabled
1539 not grep mbedtls_ecp_ library/ecp.o
1540
1541 # Run the tests
1542 # -------------
1543
1544 msg "test: full + accelerated EC algs - ECP"
1545 make test
1546
1547 msg "ssl-opt: full + accelerated EC algs - ECP"
1548 tests/ssl-opt.sh
1549}
1550
1551# Reference function used for driver's coverage analysis in analyze_outcomes.py
1552# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
1553# Keep in sync with its accelerated counterpart.
1554component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
1555 msg "build: full + non accelerated EC algs"
1556
1557 config_psa_crypto_no_ecp_at_all 0
1558
1559 make
1560
1561 msg "test: full + non accelerated EC algs"
1562 make test
1563
1564 msg "ssl-opt: full + non accelerated EC algs"
1565 tests/ssl-opt.sh
1566}
1567
1568# This is a common configuration helper used directly from:
1569# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1570# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1571# and indirectly from:
1572# - component_test_psa_crypto_config_accel_ecc_no_bignum
1573# - accelerate all EC algs, disable RSA and FFDH
1574# - component_test_psa_crypto_config_reference_ecc_no_bignum
1575# - this is the reference component of the above
1576# - it still disables RSA and FFDH, but it uses builtin EC algs
1577# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1578# - accelerate all EC and FFDH algs, disable only RSA
1579# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1580# - this is the reference component of the above
1581# - it still disables RSA, but it uses builtin EC and FFDH algs
1582#
1583# This function accepts 2 parameters:
1584# $1: a boolean value which states if we are testing an accelerated scenario
1585# or not.
1586# $2: a string value which states which components are tested. Allowed values
1587# are "ECC" or "ECC_DH".
1588config_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1589 driver_only="$1"
1590 test_target="$2"
1591 # start with full config for maximum coverage (also enables USE_PSA)
1592 helper_libtestdriver1_adjust_config "full"
1593
1594 if [ "$driver_only" -eq 1 ]; then
1595 # Disable modules that are accelerated
1596 scripts/config.py unset MBEDTLS_ECDSA_C
1597 scripts/config.py unset MBEDTLS_ECDH_C
1598 scripts/config.py unset MBEDTLS_ECJPAKE_C
1599 # Disable ECP module (entirely)
1600 scripts/config.py unset MBEDTLS_ECP_C
1601 # Also disable bignum
1602 scripts/config.py unset MBEDTLS_BIGNUM_C
1603 fi
1604
1605 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1606 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1607 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1608 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1609
1610 # RSA support is intentionally disabled on this test because RSA_C depends
1611 # on BIGNUM_C.
1612 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
1613 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
1614 scripts/config.py unset MBEDTLS_RSA_C
1615 scripts/config.py unset MBEDTLS_PKCS1_V15
1616 scripts/config.py unset MBEDTLS_PKCS1_V21
1617 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1618 # Also disable key exchanges that depend on RSA
1619 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1620 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1621 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1622 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1623 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1624
1625 if [ "$test_target" = "ECC" ]; then
1626 # When testing ECC only, we disable FFDH support, both from builtin and
1627 # PSA sides, and also disable the key exchanges that depend on DHM.
1628 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_FFDH
1629 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
1630 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
1631 scripts/config.py unset MBEDTLS_DHM_C
1632 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1633 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1634 else
1635 # When testing ECC and DH instead, we disable DHM and depending key
1636 # exchanges only in the accelerated build
1637 if [ "$driver_only" -eq 1 ]; then
1638 scripts/config.py unset MBEDTLS_DHM_C
1639 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1640 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1641 fi
1642 fi
1643
1644 # Restartable feature is not yet supported by PSA. Once it will in
1645 # the future, the following line could be removed (see issues
1646 # 6061, 6332 and following ones)
1647 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1648}
1649
1650# Common helper used by:
1651# - component_test_psa_crypto_config_accel_ecc_no_bignum
1652# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1653#
1654# The goal is to build and test accelerating either:
1655# - ECC only or
1656# - both ECC and FFDH
1657#
1658# It is meant to be used in conjunction with
1659# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
1660# coverage analysis in the "analyze_outcomes.py" script.
1661common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1662 test_target="$1"
1663
1664 # This is an internal helper to simplify text message handling
1665 if [ "$test_target" = "ECC_DH" ]; then
1666 accel_text="ECC/FFDH"
1667 removed_text="ECP - DH"
1668 else
1669 accel_text="ECC"
1670 removed_text="ECP"
1671 fi
1672
1673 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1674
1675 # By default we accelerate all EC keys/algs
1676 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1677 ALG_ECDH \
1678 ALG_JPAKE \
1679 $(helper_get_psa_key_type_list "ECC") \
1680 $(helper_get_psa_curve_list)"
1681 # Optionally we can also add DH to the list of accelerated items
1682 if [ "$test_target" = "ECC_DH" ]; then
1683 loc_accel_list="$loc_accel_list \
1684 ALG_FFDH \
1685 $(helper_get_psa_key_type_list "DH") \
1686 $(helper_get_psa_dh_group_list)"
1687 fi
1688
1689 # Configure
1690 # ---------
1691
1692 # Set common configurations between library's and driver's builds
1693 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
1694 # Disable all the builtin curves. All the required algs are accelerated.
1695 helper_disable_builtin_curves
1696
1697 # Build
1698 # -----
1699
1700 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1701 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1702 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1703 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1704
1705 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1706
1707 helper_libtestdriver1_make_main "$loc_accel_list"
1708
1709 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1710 not grep mbedtls_ecdsa_ library/ecdsa.o
1711 not grep mbedtls_ecdh_ library/ecdh.o
1712 not grep mbedtls_ecjpake_ library/ecjpake.o
1713 # Also ensure that ECP, RSA, [DHM] or BIGNUM modules were not re-enabled
1714 not grep mbedtls_ecp_ library/ecp.o
1715 not grep mbedtls_rsa_ library/rsa.o
1716 not grep mbedtls_mpi_ library/bignum.o
1717 not grep mbedtls_dhm_ library/dhm.o
1718
1719 # Run the tests
1720 # -------------
1721
1722 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - DHM - BIGNUM"
1723
1724 make test
1725
1726 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1727 tests/ssl-opt.sh
1728}
1729
1730# Common helper used by:
1731# - component_test_psa_crypto_config_reference_ecc_no_bignum
1732# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1733#
1734# The goal is to build and test a reference scenario (i.e. with builtin
1735# components) compared to the ones used in
1736# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
1737#
1738# It is meant to be used in conjunction with
1739# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
1740# coverage analysis in "analyze_outcomes.py" script.
1741common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1742 test_target="$1"
1743
1744 # This is an internal helper to simplify text message handling
1745 if [ "$test_target" = "ECC_DH" ]; then
1746 accel_text="ECC/FFDH"
1747 else
1748 accel_text="ECC"
1749 fi
1750
1751 msg "build: full + non accelerated $accel_text algs + USE_PSA"
1752
1753 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
1754
1755 make
1756
1757 msg "test suites: full + non accelerated EC algs + USE_PSA"
1758 make test
1759
1760 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
1761 tests/ssl-opt.sh
1762}
1763
1764component_test_psa_crypto_config_accel_ecc_no_bignum () {
1765 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
1766}
1767
1768component_test_psa_crypto_config_reference_ecc_no_bignum () {
1769 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
1770}
1771
1772component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1773 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
1774}
1775
1776component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1777 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
1778}
1779
Gilles Peskineced0edc2024-09-14 11:35:36 +02001780component_test_tfm_config_as_is () {
1781 msg "build: configs/config-tfm.h"
1782 cp configs/config-tfm.h "$CONFIG_H"
1783 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1784 make
1785
1786 msg "test: configs/config-tfm.h - unit tests"
1787 make test
1788}
1789
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001790# Helper for setting common configurations between:
1791# - component_test_tfm_config_p256m_driver_accel_ec()
Gilles Peskineced0edc2024-09-14 11:35:36 +02001792# - component_test_tfm_config_no_p256m()
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001793common_tfm_config () {
1794 # Enable TF-M config
1795 cp configs/config-tfm.h "$CONFIG_H"
1796 echo "#undef MBEDTLS_PSA_CRYPTO_CONFIG_FILE" >> "$CONFIG_H"
1797 cp configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
1798
1799 # Other config adjustment to make the tests pass.
1800 # This should probably be adopted upstream.
1801 #
1802 # - USE_PSA_CRYPTO for PK_HAVE_ECC_KEYS
1803 echo "#define MBEDTLS_USE_PSA_CRYPTO" >> "$CONFIG_H"
1804
1805 # Config adjustment for better test coverage in our environment.
1806 # This is not needed just to build and pass tests.
1807 #
1808 # Enable filesystem I/O for the benefit of PK parse/write tests.
1809 echo "#define MBEDTLS_FS_IO" >> "$CONFIG_H"
1810}
1811
1812# Keep this in sync with component_test_tfm_config() as they are both meant
1813# to be used in analyze_outcomes.py for driver's coverage analysis.
1814component_test_tfm_config_p256m_driver_accel_ec () {
1815 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1816
1817 common_tfm_config
1818
1819 # Build crypto library
David Horstmanndcf42a02024-11-08 14:40:12 +00001820 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../framework/tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001821
1822 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1823 not grep mbedtls_ecdsa_ library/ecdsa.o
1824 not grep mbedtls_ecdh_ library/ecdh.o
1825 not grep mbedtls_ecjpake_ library/ecjpake.o
1826 # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
1827 not grep mbedtls_ecp_ library/ecp.o
1828 not grep mbedtls_rsa_ library/rsa.o
1829 not grep mbedtls_dhm_ library/dhm.o
1830 not grep mbedtls_mpi_ library/bignum.o
1831 # Check that p256m was built
1832 grep -q p256_ecdsa_ library/libmbedcrypto.a
1833
1834 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1835 # files, so we want to ensure that it has not be re-enabled accidentally.
1836 not grep mbedtls_cipher library/cipher.o
1837
1838 # Run the tests
1839 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1840 make test
1841}
1842
1843# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1844# they are both meant to be used in analyze_outcomes.py for driver's coverage
1845# analysis.
Gilles Peskineced0edc2024-09-14 11:35:36 +02001846component_test_tfm_config_no_p256m () {
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001847 common_tfm_config
1848
1849 # Disable P256M driver, which is on by default, so that analyze_outcomes
1850 # can compare this test with test_tfm_config_p256m_driver_accel_ec
1851 echo "#undef MBEDTLS_PSA_P256M_DRIVER_ENABLED" >> "$CONFIG_H"
1852
Gilles Peskineced0edc2024-09-14 11:35:36 +02001853 msg "build: TF-M config without p256m"
David Horstmanndcf42a02024-11-08 14:40:12 +00001854 make CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' tests
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001855
1856 # Check that p256m was not built
1857 not grep p256_ecdsa_ library/libmbedcrypto.a
1858
1859 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1860 # files, so we want to ensure that it has not be re-enabled accidentally.
1861 not grep mbedtls_cipher library/cipher.o
1862
Gilles Peskineced0edc2024-09-14 11:35:36 +02001863 msg "test: TF-M config without p256m"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001864 make test
1865}
1866
1867# This is an helper used by:
1868# - component_test_psa_ecc_key_pair_no_derive
1869# - component_test_psa_ecc_key_pair_no_generate
1870# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1871# enabled, but one. Input arguments are as follows:
1872# - $1 is the key type under test, i.e. ECC/RSA/DH
1873# - $2 is the key option to be unset (i.e. generate, derive, etc)
1874build_and_test_psa_want_key_pair_partial () {
1875 key_type=$1
1876 unset_option=$2
1877 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1878
1879 msg "build: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
1880 scripts/config.py full
1881 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1882 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1883
1884 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1885 # crypto_config.h so we just disable the one we don't want.
1886 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
1887
1888 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1889
1890 msg "test: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
1891 make test
1892}
1893
1894component_test_psa_ecc_key_pair_no_derive () {
1895 build_and_test_psa_want_key_pair_partial "ECC" "DERIVE"
1896}
1897
1898component_test_psa_ecc_key_pair_no_generate () {
1899 build_and_test_psa_want_key_pair_partial "ECC" "GENERATE"
1900}
1901
1902config_psa_crypto_accel_rsa () {
1903 driver_only=$1
1904
1905 # Start from crypto_full config (no X.509, no TLS)
Manuel Pégourié-Gonnardb50b6382024-07-23 10:12:01 +02001906 # Note: PK will be ignored when comparing driver to reference in
1907 # analyze_outcomes.py
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001908 helper_libtestdriver1_adjust_config "crypto_full"
1909
1910 if [ "$driver_only" -eq 1 ]; then
1911 # Remove RSA support and its dependencies
1912 scripts/config.py unset MBEDTLS_RSA_C
1913 scripts/config.py unset MBEDTLS_PKCS1_V15
1914 scripts/config.py unset MBEDTLS_PKCS1_V21
1915
1916 # We need PEM parsing in the test library as well to support the import
1917 # of PEM encoded RSA keys.
1918 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1919 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
1920 fi
1921}
1922
1923component_test_psa_crypto_config_accel_rsa_crypto () {
1924 msg "build: crypto_full with accelerated RSA"
1925
1926 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1927 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1928 KEY_TYPE_RSA_PUBLIC_KEY \
1929 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1930 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1931 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1932 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1933
1934 # Configure
1935 # ---------
1936
1937 config_psa_crypto_accel_rsa 1
1938
1939 # Build
1940 # -----
1941
1942 # These hashes are needed for unit tests.
1943 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1944 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1945 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1946
1947 helper_libtestdriver1_make_main "$loc_accel_list"
1948
1949 # Make sure this was not re-enabled by accident (additive config)
1950 not grep mbedtls_rsa library/rsa.o
1951
1952 # Run the tests
1953 # -------------
1954
1955 msg "test: crypto_full with accelerated RSA"
1956 make test
1957}
1958
1959component_test_psa_crypto_config_reference_rsa_crypto () {
1960 msg "build: crypto_full with non-accelerated RSA"
1961
1962 # Configure
1963 # ---------
1964 config_psa_crypto_accel_rsa 0
1965
1966 # Build
1967 # -----
1968 make
1969
1970 # Run the tests
1971 # -------------
1972 msg "test: crypto_full with non-accelerated RSA"
1973 make test
1974}
1975
1976# This is a temporary test to verify that full RSA support is present even when
1977# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
1978component_test_new_psa_want_key_pair_symbol () {
1979 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1980
1981 # Create a temporary output file unless there is already one set
1982 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1983 REMOVE_OUTCOME_ON_EXIT="no"
1984 else
1985 REMOVE_OUTCOME_ON_EXIT="yes"
1986 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1987 export MBEDTLS_TEST_OUTCOME_FILE
1988 fi
1989
1990 # Start from crypto configuration
1991 scripts/config.py crypto
1992
1993 # Remove RSA support and its dependencies
1994 scripts/config.py unset MBEDTLS_PKCS1_V15
1995 scripts/config.py unset MBEDTLS_PKCS1_V21
1996 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1997 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1998 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1999 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2000 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2001 scripts/config.py unset MBEDTLS_RSA_C
2002 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2003
2004 # Enable PSA support
2005 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2006
2007 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
2008 # that proper translations is done in crypto_legacy.h.
2009 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
2010 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
2011 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
2012
2013 make
2014
2015 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
2016 make test
2017
2018 # Parse only 1 relevant line from the outcome file, i.e. a test which is
2019 # performing RSA signature.
2020 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
2021 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
2022
2023 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
2024 rm $MBEDTLS_TEST_OUTCOME_FILE
2025 fi
2026}
2027
2028component_test_psa_crypto_config_accel_hash () {
2029 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2030
2031 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
2032 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2033 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2034
2035 # Configure
2036 # ---------
2037
2038 # Start from default config (no USE_PSA)
2039 helper_libtestdriver1_adjust_config "default"
2040
2041 # Disable the things that are being accelerated
2042 scripts/config.py unset MBEDTLS_MD5_C
2043 scripts/config.py unset MBEDTLS_RIPEMD160_C
2044 scripts/config.py unset MBEDTLS_SHA1_C
2045 scripts/config.py unset MBEDTLS_SHA224_C
2046 scripts/config.py unset MBEDTLS_SHA256_C
2047 scripts/config.py unset MBEDTLS_SHA384_C
2048 scripts/config.py unset MBEDTLS_SHA512_C
2049 scripts/config.py unset MBEDTLS_SHA3_C
2050
2051 # Build
2052 # -----
2053
2054 helper_libtestdriver1_make_drivers "$loc_accel_list"
2055
2056 helper_libtestdriver1_make_main "$loc_accel_list"
2057
2058 # There's a risk of something getting re-enabled via config_psa.h;
2059 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
2060 not grep mbedtls_md5 library/md5.o
2061 not grep mbedtls_sha1 library/sha1.o
2062 not grep mbedtls_sha256 library/sha256.o
2063 not grep mbedtls_sha512 library/sha512.o
2064 not grep mbedtls_ripemd160 library/ripemd160.o
2065
2066 # Run the tests
2067 # -------------
2068
2069 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2070 make test
2071}
2072
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002073component_test_psa_crypto_config_accel_hash_keep_builtins () {
2074 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
2075 # This component ensures that all the test cases for
2076 # md_psa_dynamic_dispatch with legacy+driver in test_suite_md are run.
2077
2078 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
2079 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2080 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2081
2082 # Start from default config (no USE_PSA)
2083 helper_libtestdriver1_adjust_config "default"
2084
2085 helper_libtestdriver1_make_drivers "$loc_accel_list"
2086
2087 helper_libtestdriver1_make_main "$loc_accel_list"
2088
2089 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
2090 make test
2091}
2092
2093# This should be renamed to test and updated once the accelerator ECDH code is in place and ready to test.
2094component_build_psa_accel_alg_ecdh () {
2095 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
2096 scripts/config.py full
2097 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2098 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2099 scripts/config.py unset MBEDTLS_ECDH_C
2100 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2101 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2102 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2103 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2104 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2105 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002106 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002107}
2108
2109# This should be renamed to test and updated once the accelerator HMAC code is in place and ready to test.
2110component_build_psa_accel_alg_hmac () {
2111 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
2112 scripts/config.py full
2113 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2114 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2115 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002116 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002117}
2118
2119# This should be renamed to test and updated once the accelerator HKDF code is in place and ready to test.
2120component_build_psa_accel_alg_hkdf () {
2121 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
2122 scripts/config.py full
2123 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2124 scripts/config.py unset MBEDTLS_HKDF_C
2125 # Make sure to unset TLS1_3 since it requires HKDF_C and will not build properly without it.
2126 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2127 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002128 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002129}
2130
2131# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
2132component_build_psa_accel_alg_md5 () {
2133 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - other hashes"
2134 scripts/config.py full
2135 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2136 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2137 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2138 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2139 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2140 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2141 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2142 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2143 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2144 scripts/config.py unset MBEDTLS_LMS_C
2145 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2146 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002147 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002148}
2149
2150# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
2151component_build_psa_accel_alg_ripemd160 () {
2152 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - other hashes"
2153 scripts/config.py full
2154 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2155 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2156 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2157 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2158 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2159 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2160 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2161 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2162 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2163 scripts/config.py unset MBEDTLS_LMS_C
2164 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2165 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002166 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002167}
2168
2169# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
2170component_build_psa_accel_alg_sha1 () {
2171 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - other hashes"
2172 scripts/config.py full
2173 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2174 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2175 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2176 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2177 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2178 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2179 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2180 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2181 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2182 scripts/config.py unset MBEDTLS_LMS_C
2183 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2184 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002185 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002186}
2187
2188# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
2189component_build_psa_accel_alg_sha224 () {
2190 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
2191 scripts/config.py full
2192 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2193 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2194 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2195 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2196 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2197 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2198 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2199 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2200 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002201 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002202}
2203
2204# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
2205component_build_psa_accel_alg_sha256 () {
2206 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - other hashes"
2207 scripts/config.py full
2208 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2209 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2210 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2211 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2212 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2213 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2214 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2215 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2216 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002217 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002218}
2219
2220# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
2221component_build_psa_accel_alg_sha384 () {
2222 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
2223 scripts/config.py full
2224 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2225 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2226 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2227 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2228 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2229 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2230 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2231 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2232 scripts/config.py unset MBEDTLS_LMS_C
2233 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2234 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002235 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002236}
2237
2238# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
2239component_build_psa_accel_alg_sha512 () {
2240 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
2241 scripts/config.py full
2242 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2243 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2244 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2245 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2246 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2247 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2248 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2249 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2250 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2251 scripts/config.py unset MBEDTLS_LMS_C
2252 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2253 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002254 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002255}
2256
2257# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2258component_build_psa_accel_alg_rsa_pkcs1v15_crypt () {
2259 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2260 scripts/config.py full
2261 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2262 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2263 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
2264 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2265 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
2266 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
2267 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002268 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002269}
2270
2271# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2272component_build_psa_accel_alg_rsa_pkcs1v15_sign () {
2273 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2274 scripts/config.py full
2275 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2276 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2277 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
2278 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2279 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
2280 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
2281 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002282 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002283}
2284
2285# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2286component_build_psa_accel_alg_rsa_oaep () {
2287 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2288 scripts/config.py full
2289 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2290 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2291 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_OAEP 1
2292 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2293 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2294 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
2295 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002296 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002297}
2298
2299# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2300component_build_psa_accel_alg_rsa_pss () {
2301 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2302 scripts/config.py full
2303 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2304 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2305 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
2306 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2307 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2308 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
2309 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002310 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002311}
2312
2313# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2314component_build_psa_accel_key_type_rsa_key_pair () {
2315 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_xxx + PSA_WANT_ALG_RSA_PSS"
2316 scripts/config.py full
2317 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2318 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2319 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
2320 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC 1
2321 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT 1
2322 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT 1
2323 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE 1
2324 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002325 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002326}
2327
2328# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2329component_build_psa_accel_key_type_rsa_public_key () {
2330 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
2331 scripts/config.py full
2332 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2333 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2334 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
2335 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
2336 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002337 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002338}
2339
Minos Galanakis3ece57e2024-08-01 17:09:49 +01002340# Auxiliary function to build config for hashes with and without drivers
2341config_psa_crypto_hash_use_psa () {
2342 driver_only="$1"
2343 # start with config full for maximum coverage (also enables USE_PSA)
2344 helper_libtestdriver1_adjust_config "full"
2345 if [ "$driver_only" -eq 1 ]; then
2346 # disable the built-in implementation of hashes
2347 scripts/config.py unset MBEDTLS_MD5_C
2348 scripts/config.py unset MBEDTLS_RIPEMD160_C
2349 scripts/config.py unset MBEDTLS_SHA1_C
2350 scripts/config.py unset MBEDTLS_SHA224_C
2351 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
2352 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2353 scripts/config.py unset MBEDTLS_SHA384_C
2354 scripts/config.py unset MBEDTLS_SHA512_C
2355 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2356 scripts/config.py unset MBEDTLS_SHA3_C
2357 fi
2358}
2359
2360# Note that component_test_psa_crypto_config_reference_hash_use_psa
2361# is related to this component and both components need to be kept in sync.
2362# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
2363component_test_psa_crypto_config_accel_hash_use_psa () {
2364 msg "test: full with accelerated hashes"
2365
2366 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
2367 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2368 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2369
2370 # Configure
2371 # ---------
2372
2373 config_psa_crypto_hash_use_psa 1
2374
2375 # Build
2376 # -----
2377
2378 helper_libtestdriver1_make_drivers "$loc_accel_list"
2379
2380 helper_libtestdriver1_make_main "$loc_accel_list"
2381
2382 # There's a risk of something getting re-enabled via config_psa.h;
2383 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
2384 not grep mbedtls_md5 library/md5.o
2385 not grep mbedtls_sha1 library/sha1.o
2386 not grep mbedtls_sha256 library/sha256.o
2387 not grep mbedtls_sha512 library/sha512.o
2388 not grep mbedtls_ripemd160 library/ripemd160.o
2389
2390 # Run the tests
2391 # -------------
2392
2393 msg "test: full with accelerated hashes"
2394 make test
2395
2396 # This is mostly useful so that we can later compare outcome files with
2397 # the reference config in analyze_outcomes.py, to check that the
2398 # dependency declarations in ssl-opt.sh and in TLS code are correct.
2399 msg "test: ssl-opt.sh, full with accelerated hashes"
2400 tests/ssl-opt.sh
2401
2402 # This is to make sure all ciphersuites are exercised, but we don't need
2403 # interop testing (besides, we already got some from ssl-opt.sh).
2404 msg "test: compat.sh, full with accelerated hashes"
2405 tests/compat.sh -p mbedTLS -V YES
2406}
2407
2408# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
2409# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
2410# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
2411# Both components need to be kept in sync.
2412component_test_psa_crypto_config_reference_hash_use_psa () {
2413 msg "test: full without accelerated hashes"
2414
2415 config_psa_crypto_hash_use_psa 0
2416
2417 make
2418
2419 msg "test: full without accelerated hashes"
2420 make test
2421
2422 msg "test: ssl-opt.sh, full without accelerated hashes"
2423 tests/ssl-opt.sh
2424}
2425
2426# Auxiliary function to build config for hashes with and without drivers
2427config_psa_crypto_hmac_use_psa () {
2428 driver_only="$1"
2429 # start with config full for maximum coverage (also enables USE_PSA)
2430 helper_libtestdriver1_adjust_config "full"
2431
2432 if [ "$driver_only" -eq 1 ]; then
2433 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
2434 # is still enabled though (for ENTROPY_C among others).
2435 scripts/config.py unset MBEDTLS_MD_C
2436 # Disable also the builtin hashes since they are supported by the driver
2437 # and MD module is able to perform PSA dispathing.
2438 scripts/config.py unset-all MBEDTLS_SHA
2439 scripts/config.py unset MBEDTLS_MD5_C
2440 scripts/config.py unset MBEDTLS_RIPEMD160_C
2441 fi
2442
2443 # Direct dependencies of MD_C. We disable them also in the reference
2444 # component to work with the same set of features.
2445 scripts/config.py unset MBEDTLS_PKCS7_C
2446 scripts/config.py unset MBEDTLS_PKCS5_C
2447 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
2448 scripts/config.py unset MBEDTLS_HKDF_C
2449 # Dependencies of HMAC_DRBG
2450 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
2451 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
2452}
2453
2454component_test_psa_crypto_config_accel_hmac () {
2455 msg "test: full with accelerated hmac"
2456
2457 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
2458 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
2459 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2460 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2461
2462 # Configure
2463 # ---------
2464
2465 config_psa_crypto_hmac_use_psa 1
2466
2467 # Build
2468 # -----
2469
2470 helper_libtestdriver1_make_drivers "$loc_accel_list"
2471
2472 helper_libtestdriver1_make_main "$loc_accel_list"
2473
2474 # Ensure that built-in support for HMAC is disabled.
2475 not grep mbedtls_md_hmac library/md.o
2476
2477 # Run the tests
2478 # -------------
2479
2480 msg "test: full with accelerated hmac"
2481 make test
2482}
2483
2484component_test_psa_crypto_config_reference_hmac () {
2485 msg "test: full without accelerated hmac"
2486
2487 config_psa_crypto_hmac_use_psa 0
2488
2489 make
2490
2491 msg "test: full without accelerated hmac"
2492 make test
2493}
2494
2495component_test_psa_crypto_config_accel_des () {
2496 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
2497
2498 # Albeit this components aims at accelerating DES which should only support
2499 # CBC and ECB modes, we need to accelerate more than that otherwise DES_C
2500 # would automatically be re-enabled by "config_adjust_legacy_from_psa.c"
2501 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 \
2502 ALG_CTR ALG_CFB ALG_OFB ALG_XTS ALG_CMAC \
2503 KEY_TYPE_DES"
2504
2505 # Note: we cannot accelerate all ciphers' key types otherwise we would also
2506 # have to either disable CCM/GCM or accelerate them, but that's out of scope
2507 # of this component. This limitation will be addressed by #8598.
2508
2509 # Configure
2510 # ---------
2511
2512 # Start from the full config
2513 helper_libtestdriver1_adjust_config "full"
2514
2515 # Disable the things that are being accelerated
2516 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2517 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2518 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2519 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2520 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2521 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2522 scripts/config.py unset MBEDTLS_DES_C
2523 scripts/config.py unset MBEDTLS_CMAC_C
2524
2525 # Build
2526 # -----
2527
2528 helper_libtestdriver1_make_drivers "$loc_accel_list"
2529
2530 helper_libtestdriver1_make_main "$loc_accel_list"
2531
2532 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine5ea32982024-06-19 15:09:27 +02002533 not grep mbedtls_des library/des.o
Minos Galanakis3ece57e2024-08-01 17:09:49 +01002534
2535 # Run the tests
2536 # -------------
2537
2538 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
2539 make test
2540}
2541
2542component_test_psa_crypto_config_accel_aead () {
2543 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2544
2545 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
2546 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2547
2548 # Configure
2549 # ---------
2550
2551 # Start from full config
2552 helper_libtestdriver1_adjust_config "full"
2553
2554 # Disable things that are being accelerated
2555 scripts/config.py unset MBEDTLS_GCM_C
2556 scripts/config.py unset MBEDTLS_CCM_C
2557 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2558
2559 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
2560 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
2561
2562 # Build
2563 # -----
2564
2565 helper_libtestdriver1_make_drivers "$loc_accel_list"
2566
2567 helper_libtestdriver1_make_main "$loc_accel_list"
2568
2569 # Make sure this was not re-enabled by accident (additive config)
2570 not grep mbedtls_ccm library/ccm.o
2571 not grep mbedtls_gcm library/gcm.o
2572 not grep mbedtls_chachapoly library/chachapoly.o
2573
2574 # Run the tests
2575 # -------------
2576
2577 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2578 make test
2579}
2580
2581# This is a common configuration function used in:
2582# - component_test_psa_crypto_config_accel_cipher_aead_cmac
2583# - component_test_psa_crypto_config_reference_cipher_aead_cmac
2584common_psa_crypto_config_accel_cipher_aead_cmac () {
2585 # Start from the full config
2586 helper_libtestdriver1_adjust_config "full"
2587
2588 scripts/config.py unset MBEDTLS_NIST_KW_C
2589}
2590
2591# The 2 following test components, i.e.
2592# - component_test_psa_crypto_config_accel_cipher_aead_cmac
2593# - component_test_psa_crypto_config_reference_cipher_aead_cmac
2594# are meant to be used together in analyze_outcomes.py script in order to test
2595# driver's coverage for ciphers and AEADs.
2596component_test_psa_crypto_config_accel_cipher_aead_cmac () {
2597 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
2598
2599 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
2600 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
2601 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
2602 KEY_TYPE_DES KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
2603
2604 # Configure
2605 # ---------
2606
2607 common_psa_crypto_config_accel_cipher_aead_cmac
2608
2609 # Disable the things that are being accelerated
2610 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2611 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2612 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2613 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2614 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2615 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2616 scripts/config.py unset MBEDTLS_GCM_C
2617 scripts/config.py unset MBEDTLS_CCM_C
2618 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2619 scripts/config.py unset MBEDTLS_CMAC_C
2620 scripts/config.py unset MBEDTLS_DES_C
2621 scripts/config.py unset MBEDTLS_AES_C
2622 scripts/config.py unset MBEDTLS_ARIA_C
2623 scripts/config.py unset MBEDTLS_CHACHA20_C
2624 scripts/config.py unset MBEDTLS_CAMELLIA_C
2625
2626 # Disable CIPHER_C entirely as all ciphers/AEADs are accelerated and PSA
2627 # does not depend on it.
2628 scripts/config.py unset MBEDTLS_CIPHER_C
2629
2630 # Build
2631 # -----
2632
2633 helper_libtestdriver1_make_drivers "$loc_accel_list"
2634
2635 helper_libtestdriver1_make_main "$loc_accel_list"
2636
2637 # Make sure this was not re-enabled by accident (additive config)
2638 not grep mbedtls_cipher library/cipher.o
2639 not grep mbedtls_des library/des.o
2640 not grep mbedtls_aes library/aes.o
2641 not grep mbedtls_aria library/aria.o
2642 not grep mbedtls_camellia library/camellia.o
2643 not grep mbedtls_ccm library/ccm.o
2644 not grep mbedtls_gcm library/gcm.o
2645 not grep mbedtls_chachapoly library/chachapoly.o
2646 not grep mbedtls_cmac library/cmac.o
2647
2648 # Run the tests
2649 # -------------
2650
2651 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
2652 make test
2653
2654 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
2655 tests/ssl-opt.sh
2656
2657 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
2658 tests/compat.sh -V NO -p mbedTLS
2659}
2660
2661component_test_psa_crypto_config_reference_cipher_aead_cmac () {
2662 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
2663 common_psa_crypto_config_accel_cipher_aead_cmac
2664
2665 make
2666
2667 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
2668 make test
2669
2670 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
2671 tests/ssl-opt.sh
2672
2673 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
2674 tests/compat.sh -V NO -p mbedTLS
2675}
2676
2677common_block_cipher_dispatch () {
2678 TEST_WITH_DRIVER="$1"
2679
2680 # Start from the full config
2681 helper_libtestdriver1_adjust_config "full"
2682
2683 if [ "$TEST_WITH_DRIVER" -eq 1 ]; then
2684 # Disable key types that are accelerated (there is no legacy equivalent
2685 # symbol for ECB)
2686 scripts/config.py unset MBEDTLS_AES_C
2687 scripts/config.py unset MBEDTLS_ARIA_C
2688 scripts/config.py unset MBEDTLS_CAMELLIA_C
2689 fi
2690
2691 # Disable cipher's modes that, when not accelerated, cause
2692 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
2693 # Keep this also in the reference component in order to skip the same tests
2694 # that were skipped in the accelerated one.
2695 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
2696 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
2697 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
2698 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
2699 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
2700 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
2701 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
2702 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
2703
2704 # Disable direct dependency on AES_C
2705 scripts/config.py unset MBEDTLS_NIST_KW_C
2706
2707 # Prevent the cipher module from using deprecated PSA path. The reason is
2708 # that otherwise there will be tests relying on "aes_info" (defined in
2709 # "cipher_wrap.c") whose functions are not available when AES_C is
2710 # not defined. ARIA and Camellia are not a problem in this case because
2711 # the PSA path is not tested for these key types.
2712 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
2713}
2714
Gilles Peskine9dc903a2024-06-21 11:25:01 +02002715component_test_full_block_cipher_psa_dispatch_static_keystore () {
2716 msg "build: full + PSA dispatch in block_cipher with static keystore"
2717 # Check that the static key store works well when CTR_DRBG uses a
2718 # PSA key for AES.
2719 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2720
2721 loc_accel_list="ALG_ECB_NO_PADDING \
2722 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2723
2724 # Configure
2725 # ---------
2726
2727 common_block_cipher_dispatch 1
2728
2729 # Build
2730 # -----
2731
2732 helper_libtestdriver1_make_drivers "$loc_accel_list"
2733
2734 helper_libtestdriver1_make_main "$loc_accel_list"
2735
2736 # Make sure disabled components were not re-enabled by accident (additive
2737 # config)
2738 not grep mbedtls_aes_ library/aes.o
2739 not grep mbedtls_aria_ library/aria.o
2740 not grep mbedtls_camellia_ library/camellia.o
2741
2742 # Run the tests
2743 # -------------
2744
2745 msg "test: full + PSA dispatch in block_cipher with static keystore"
2746 make test
2747}
2748
Minos Galanakis3ece57e2024-08-01 17:09:49 +01002749component_test_full_block_cipher_psa_dispatch () {
2750 msg "build: full + PSA dispatch in block_cipher"
2751
2752 loc_accel_list="ALG_ECB_NO_PADDING \
2753 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2754
2755 # Configure
2756 # ---------
2757
2758 common_block_cipher_dispatch 1
2759
2760 # Build
2761 # -----
2762
2763 helper_libtestdriver1_make_drivers "$loc_accel_list"
2764
2765 helper_libtestdriver1_make_main "$loc_accel_list"
2766
2767 # Make sure disabled components were not re-enabled by accident (additive
2768 # config)
2769 not grep mbedtls_aes_ library/aes.o
2770 not grep mbedtls_aria_ library/aria.o
2771 not grep mbedtls_camellia_ library/camellia.o
2772
2773 # Run the tests
2774 # -------------
2775
2776 msg "test: full + PSA dispatch in block_cipher"
2777 make test
2778}
2779
2780# This is the reference component of component_test_full_block_cipher_psa_dispatch
2781component_test_full_block_cipher_legacy_dispatch () {
2782 msg "build: full + legacy dispatch in block_cipher"
2783
2784 common_block_cipher_dispatch 0
2785
2786 make
2787
2788 msg "test: full + legacy dispatch in block_cipher"
2789 make test
2790}
2791
2792component_test_aead_chachapoly_disabled () {
2793 msg "build: full minus CHACHAPOLY"
2794 scripts/config.py full
2795 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2796 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2797 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2798
2799 msg "test: full minus CHACHAPOLY"
2800 make test
2801}
2802
2803component_test_aead_only_ccm () {
2804 msg "build: full minus CHACHAPOLY and GCM"
2805 scripts/config.py full
2806 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2807 scripts/config.py unset MBEDTLS_GCM_C
2808 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2809 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2810 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2811
2812 msg "test: full minus CHACHAPOLY and GCM"
2813 make test
2814}
2815
2816component_test_ccm_aes_sha256 () {
2817 msg "build: CCM + AES + SHA256 configuration"
2818
2819 cp "$CONFIG_TEST_DRIVER_H" "$CONFIG_H"
2820 cp configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
2821
2822 make
2823
2824 msg "test: CCM + AES + SHA256 configuration"
2825 make test
2826}
2827
2828# Test that the given .o file builds with all (valid) combinations of the given options.
2829#
2830# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
2831#
2832# The validator function is the name of a function to validate the combination of options.
2833# It may be "" if all combinations are valid.
2834# It receives a string containing a combination of options, as passed to the compiler,
2835# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
2836build_test_config_combos () {
2837 file=$1
2838 shift
2839 validate_options=$1
2840 shift
2841 options=("$@")
2842
2843 # clear all of the options so that they can be overridden on the clang commandline
2844 for opt in "${options[@]}"; do
2845 ./scripts/config.py unset ${opt}
2846 done
2847
2848 # enter the directory containing the target file & strip the dir from the filename
2849 cd $(dirname ${file})
2850 file=$(basename ${file})
2851
2852 # The most common issue is unused variables/functions, so ensure -Wunused is set.
2853 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
2854
2855 # Extract the command generated by the Makefile to build the target file.
2856 # This ensures that we have any include paths, macro definitions, etc
2857 # that may be applied by make.
2858 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
2859 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
2860
2861 makefile=$(TMPDIR=. mktemp)
2862 deps=""
2863
2864 len=${#options[@]}
2865 source_file=${file%.o}.c
2866
2867 targets=0
2868 echo 'include Makefile' >${makefile}
2869
2870 for ((i = 0; i < $((2**${len})); i++)); do
2871 # generate each of 2^n combinations of options
2872 # each bit of $i is used to determine if options[i] will be set or not
2873 target="t"
2874 clang_args=""
2875 for ((j = 0; j < ${len}; j++)); do
2876 if (((i >> j) & 1)); then
2877 opt=-D${options[$j]}
2878 clang_args="${clang_args} ${opt}"
2879 target="${target}${opt}"
2880 fi
2881 done
2882
2883 # if combination is not known to be invalid, add it to the makefile
2884 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
2885 cmd="${compile_cmd} ${clang_args}"
2886 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
2887
2888 deps="${deps} ${target}"
2889 ((++targets))
2890 fi
2891 done
2892
2893 echo "build_test_config_combos: ${deps}" >> ${makefile}
2894
2895 # execute all of the commands via Make (probably in parallel)
2896 make -s -f ${makefile} build_test_config_combos
2897 echo "$targets targets checked"
2898
2899 # clean up the temporary makefile
2900 rm ${makefile}
2901}
2902
2903validate_aes_config_variations () {
2904 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
2905 if [[ "$1" == *"MBEDTLS_PADLOCK_C"* ]]; then
2906 return 1
2907 fi
2908 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
2909 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
2910 return 1
2911 fi
2912 fi
2913 return 0
2914}
2915
2916component_build_aes_variations () {
2917 # 18s - around 90ms per clang invocation on M1 Pro
2918 #
2919 # aes.o has many #if defined(...) guards that intersect in complex ways.
2920 # Test that all the combinations build cleanly.
2921
2922 MBEDTLS_ROOT_DIR="$PWD"
2923 msg "build: aes.o for all combinations of relevant config options"
2924
2925 build_test_config_combos library/aes.o validate_aes_config_variations \
2926 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
2927 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
2928 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2929 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2930
2931 cd "$MBEDTLS_ROOT_DIR"
2932 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
2933
2934 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES,
2935 # manually set or unset those configurations to check
2936 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
2937 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
2938 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2939 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2940 scripts/config.py unset MBEDTLS_DES_C
2941 scripts/config.py unset MBEDTLS_NIST_KW_C
2942 build_test_config_combos library/aes.o validate_aes_config_variations \
2943 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
2944 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
2945 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2946 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2947}
2948
2949component_test_sha3_variations () {
2950 msg "sha3 loop unroll variations"
2951
2952 # define minimal config sufficient to test SHA3
2953 cat > include/mbedtls/mbedtls_config.h << END
2954 #define MBEDTLS_SELF_TEST
2955 #define MBEDTLS_SHA3_C
2956END
2957
2958 msg "all loops unrolled"
2959 make clean
2960 make -C 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"
2961 ./tests/test_suite_shax
2962
2963 msg "all loops rolled up"
2964 make clean
2965 make -C 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"
2966 ./tests/test_suite_shax
2967}
2968
2969# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2970component_build_aes_aesce_armcc () {
2971 msg "Build: AESCE test on arm64 platform without plain C."
2972 scripts/config.py baremetal
2973
2974 # armc[56] don't support SHA-512 intrinsics
2975 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2976
2977 # Stop armclang warning about feature detection for A64_CRYPTO.
2978 # With this enabled, the library does build correctly under armclang,
2979 # but in baremetal builds (as tested here), feature detection is
2980 # unavailable, and the user is notified via a #warning. So enabling
2981 # this feature would prevent us from building with -Werror on
2982 # armclang. Tracked in #7198.
2983 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2984 scripts/config.py set MBEDTLS_HAVE_ASM
2985
2986 msg "AESCE, build with default configuration."
2987 scripts/config.py set MBEDTLS_AESCE_C
2988 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard452db602024-10-01 13:01:54 +02002989 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01002990
2991 msg "AESCE, build AESCE only"
2992 scripts/config.py set MBEDTLS_AESCE_C
2993 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard452db602024-10-01 13:01:54 +02002994 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01002995}
2996
2997support_build_aes_aesce_armcc () {
2998 support_build_armcc
2999}
3000
3001component_test_aes_only_128_bit_keys () {
3002 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
3003 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
3004 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine580d1f42025-08-08 00:06:06 +02003005 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Minos Galanakis3ece57e2024-08-01 17:09:49 +01003006
3007 make CFLAGS='-O2 -Werror -Wall -Wextra'
3008
3009 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
3010 make test
Gilles Peskine580d1f42025-08-08 00:06:06 +02003011
3012 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH constant flow with Valgrind, selected suites"
3013 test_with_valgrind_constant_time
Minos Galanakis3ece57e2024-08-01 17:09:49 +01003014}
3015
3016component_test_no_ctr_drbg_aes_only_128_bit_keys () {
3017 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
3018 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
3019 scripts/config.py unset MBEDTLS_CTR_DRBG_C
3020 scripts/config.py unset MBEDTLS_PADLOCK_C
3021
3022 make CC=clang CFLAGS='-Werror -Wall -Wextra'
3023
3024 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
3025 make test
3026}
3027
3028component_test_aes_only_128_bit_keys_have_builtins () {
3029 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
3030 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
3031 scripts/config.py unset MBEDTLS_PADLOCK_C
3032 scripts/config.py unset MBEDTLS_AESNI_C
3033 scripts/config.py unset MBEDTLS_AESCE_C
3034
3035 make CFLAGS='-O2 -Werror -Wall -Wextra'
3036
3037 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
3038 make test
3039
3040 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
3041 programs/test/selftest
3042}
3043
3044component_test_gcm_largetable () {
3045 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
3046 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
3047 scripts/config.py unset MBEDTLS_PADLOCK_C
3048 scripts/config.py unset MBEDTLS_AESNI_C
3049 scripts/config.py unset MBEDTLS_AESCE_C
3050
3051 make CFLAGS='-O2 -Werror -Wall -Wextra'
3052
3053 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
3054 make test
3055}
3056
3057component_test_aes_fewer_tables () {
3058 msg "build: default config with AES_FEWER_TABLES enabled"
3059 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
3060 make CFLAGS='-O2 -Werror -Wall -Wextra'
3061
3062 msg "test: AES_FEWER_TABLES"
3063 make test
3064}
3065
3066component_test_aes_rom_tables () {
3067 msg "build: default config with AES_ROM_TABLES enabled"
3068 scripts/config.py set MBEDTLS_AES_ROM_TABLES
3069 make CFLAGS='-O2 -Werror -Wall -Wextra'
3070
3071 msg "test: AES_ROM_TABLES"
3072 make test
3073}
3074
3075component_test_aes_fewer_tables_and_rom_tables () {
3076 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
3077 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
3078 scripts/config.py set MBEDTLS_AES_ROM_TABLES
3079 make CFLAGS='-O2 -Werror -Wall -Wextra'
3080
3081 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
3082 make test
3083}
3084
3085# helper for common_block_cipher_no_decrypt() which:
3086# - enable/disable the list of config options passed from -s/-u respectively.
3087# - build
3088# - test for tests_suite_xxx
3089# - selftest
3090#
3091# Usage: helper_block_cipher_no_decrypt_build_test
3092# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
3093# Options: -s set_opts the list of config options to enable
3094# -u unset_opts the list of config options to disable
3095# -c cflags the list of options passed to CFLAGS
3096# -l ldflags the list of options passed to LDFLAGS
3097helper_block_cipher_no_decrypt_build_test () {
3098 while [ $# -gt 0 ]; do
3099 case "$1" in
3100 -s)
3101 shift; local set_opts="$1";;
3102 -u)
3103 shift; local unset_opts="$1";;
3104 -c)
3105 shift; local cflags="-Werror -Wall -Wextra $1";;
3106 -l)
3107 shift; local ldflags="$1";;
3108 esac
3109 shift
3110 done
3111 set_opts="${set_opts:-}"
3112 unset_opts="${unset_opts:-}"
3113 cflags="${cflags:-}"
3114 ldflags="${ldflags:-}"
3115
3116 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
3117 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
3118
3119 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
3120 make clean
3121 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
3122
3123 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
3124 not grep mbedtls_aes_setkey_dec library/aes.o
3125 not grep mbedtls_aria_setkey_dec library/aria.o
3126 not grep mbedtls_camellia_setkey_dec library/camellia.o
3127 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
3128 not grep mbedtls_internal_aes_decrypt library/aes.o
3129 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
3130 not grep mbedtls_aesni_inverse_key library/aesni.o
3131
3132 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
3133 make test
3134
3135 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
3136 programs/test/selftest
3137}
3138
3139# This is a common configuration function used in:
3140# - component_test_block_cipher_no_decrypt_aesni_legacy()
3141# - component_test_block_cipher_no_decrypt_aesni_use_psa()
3142# in order to test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics,
3143# AESNI assembly and AES C implementation on x86_64 and with AESNI intrinsics
3144# on x86.
3145common_block_cipher_no_decrypt () {
3146 # test AESNI intrinsics
3147 helper_block_cipher_no_decrypt_build_test \
3148 -s "MBEDTLS_AESNI_C" \
3149 -c "-mpclmul -msse2 -maes"
3150
3151 # test AESNI assembly
3152 helper_block_cipher_no_decrypt_build_test \
3153 -s "MBEDTLS_AESNI_C" \
3154 -c "-mno-pclmul -mno-sse2 -mno-aes"
3155
3156 # test AES C implementation
3157 helper_block_cipher_no_decrypt_build_test \
3158 -u "MBEDTLS_AESNI_C"
3159
3160 # test AESNI intrinsics for i386 target
3161 helper_block_cipher_no_decrypt_build_test \
3162 -s "MBEDTLS_AESNI_C" \
3163 -c "-m32 -mpclmul -msse2 -maes" \
3164 -l "-m32"
3165}
3166
3167# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
3168# usage: 0: no PSA crypto configuration
3169# 1: use PSA crypto configuration
3170config_block_cipher_no_decrypt () {
3171 use_psa=$1
3172
3173 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
3174 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3175 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
3176 scripts/config.py unset MBEDTLS_DES_C
3177 scripts/config.py unset MBEDTLS_NIST_KW_C
3178
3179 if [ "$use_psa" -eq 1 ]; then
3180 # Enable support for cryptographic mechanisms through the PSA API.
3181 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
3182 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3183 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
3184 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
3185 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
3186 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
3187 fi
3188}
3189
3190component_test_block_cipher_no_decrypt_aesni () {
3191 # This consistently causes an llvm crash on clang 3.8, so use gcc
3192 export CC=gcc
3193 config_block_cipher_no_decrypt 0
3194 common_block_cipher_no_decrypt
3195}
3196
3197component_test_block_cipher_no_decrypt_aesni_use_psa () {
3198 # This consistently causes an llvm crash on clang 3.8, so use gcc
3199 export CC=gcc
3200 config_block_cipher_no_decrypt 1
3201 common_block_cipher_no_decrypt
3202}
3203
3204support_test_block_cipher_no_decrypt_aesce_armcc () {
3205 support_build_armcc
3206}
3207
3208component_test_block_cipher_no_decrypt_aesce_armcc () {
3209 scripts/config.py baremetal
3210
3211 # armc[56] don't support SHA-512 intrinsics
3212 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
3213
3214 # Stop armclang warning about feature detection for A64_CRYPTO.
3215 # With this enabled, the library does build correctly under armclang,
3216 # but in baremetal builds (as tested here), feature detection is
3217 # unavailable, and the user is notified via a #warning. So enabling
3218 # this feature would prevent us from building with -Werror on
3219 # armclang. Tracked in #7198.
3220 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
3221 scripts/config.py set MBEDTLS_HAVE_ASM
3222
3223 config_block_cipher_no_decrypt 1
3224
3225 # test AESCE baremetal build
3226 scripts/config.py set MBEDTLS_AESCE_C
3227 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
Manuel Pégourié-Gonnard452db602024-10-01 13:01:54 +02003228 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01003229
3230 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
3231 not grep mbedtls_aes_setkey_dec library/aes.o
3232 not grep mbedtls_aria_setkey_dec library/aria.o
3233 not grep mbedtls_camellia_setkey_dec library/camellia.o
3234 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
3235 not grep mbedtls_internal_aes_decrypt library/aes.o
3236 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
3237 not grep mbedtls_aesce_inverse_key library/aesce.o
3238 not grep aesce_decrypt_block library/aesce.o
3239}
3240
3241component_test_ctr_drbg_aes_256_sha_256 () {
3242 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
3243 scripts/config.py full
3244 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
3245 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
3246 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3247 make
3248
3249 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
3250 make test
3251}
3252
3253component_test_ctr_drbg_aes_128_sha_512 () {
3254 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
3255 scripts/config.py full
3256 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
3257 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
3258 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3259 make
3260
3261 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
3262 make test
3263}
3264
3265component_test_ctr_drbg_aes_128_sha_256 () {
3266 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
3267 scripts/config.py full
3268 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
3269 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
3270 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
3271 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3272 make
3273
3274 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
3275 make test
3276}
3277
3278component_test_se_default () {
3279 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
3280 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
3281 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
3282
3283 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
3284 make test
3285}
3286
Gilles Peskine9dc903a2024-06-21 11:25:01 +02003287component_test_full_static_keystore () {
3288 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
3289 scripts/config.py full
3290 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
3291 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
3292
3293 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
3294 make test
3295}
3296
Minos Galanakis3ece57e2024-08-01 17:09:49 +01003297component_test_psa_crypto_drivers () {
3298 msg "build: full + test drivers dispatching to builtins"
3299 scripts/config.py full
3300 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
3301 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
3302 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
David Horstmanndcf42a02024-11-08 14:40:12 +00003303 loc_cflags="${loc_cflags} -I../framework/tests/include -O2"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01003304
3305 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
3306
3307 msg "test: full + test drivers dispatching to builtins"
3308 make test
3309}
3310
3311component_build_psa_config_file () {
3312 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
3313 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3314 cp "$CRYPTO_CONFIG_H" psa_test_config.h
3315 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
3316 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
3317 # Make sure this feature is enabled. We'll disable it in the next phase.
3318 programs/test/query_compile_time_config MBEDTLS_CMAC_C
3319 make clean
3320
3321 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
3322 # In the user config, disable one feature and its dependencies, which will
3323 # reflect on the mbedtls configuration so we can query it with
3324 # query_compile_time_config.
3325 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
3326 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
3327 scripts/config.py unset MBEDTLS_CMAC_C
3328 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
3329 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
3330
3331 rm -f psa_test_config.h psa_user_config.h
3332}
3333
3334component_build_psa_alt_headers () {
3335 msg "build: make with PSA alt headers" # ~20s
3336
3337 # Generate alternative versions of the substitutable headers with the
3338 # same content except different include guards.
David Horstmannb19374f2024-11-07 17:08:11 +00003339 make -C tests ../framework/tests/include/alt-extra/psa/crypto_platform_alt.h ../framework/tests/include/alt-extra/psa/crypto_struct_alt.h
Minos Galanakis3ece57e2024-08-01 17:09:49 +01003340
3341 # Build the library and some programs.
3342 # Don't build the fuzzers to avoid having to go through hoops to set
3343 # a correct include path for programs/fuzz/Makefile.
David Horstmanndcf42a02024-11-08 14:40:12 +00003344 make CFLAGS="-I ../framework/tests/include/alt-extra -DMBEDTLS_PSA_CRYPTO_PLATFORM_FILE='\"psa/crypto_platform_alt.h\"' -DMBEDTLS_PSA_CRYPTO_STRUCT_FILE='\"psa/crypto_struct_alt.h\"'" lib
3345 make -C programs -o fuzz CFLAGS="-I ../framework/tests/include/alt-extra -DMBEDTLS_PSA_CRYPTO_PLATFORM_FILE='\"psa/crypto_platform_alt.h\"' -DMBEDTLS_PSA_CRYPTO_STRUCT_FILE='\"psa/crypto_struct_alt.h\"'"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01003346
3347 # Check that we're getting the alternative include guards and not the
3348 # original include guards.
3349 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
3350 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
3351 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
3352 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
3353}
3354
3355component_test_min_mpi_window_size () {
3356 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
3357 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
3358 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3359 make
3360
3361 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
3362 make test
3363}