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