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