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