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