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