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