blob: 459aa6fe5a19777c58eec818253a34915679296c [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
Gilles Peskineced0edc2024-09-14 11:35:36 +02001643component_test_tfm_config_as_is () {
1644 msg "build: configs/config-tfm.h"
1645 cp configs/config-tfm.h "$CONFIG_H"
1646 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1647 make
1648
1649 msg "test: configs/config-tfm.h - unit tests"
1650 make test
1651}
1652
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001653# Helper for setting common configurations between:
1654# - component_test_tfm_config_p256m_driver_accel_ec()
Gilles Peskineced0edc2024-09-14 11:35:36 +02001655# - component_test_tfm_config_no_p256m()
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001656common_tfm_config () {
1657 # Enable TF-M config
1658 cp configs/config-tfm.h "$CONFIG_H"
1659 echo "#undef MBEDTLS_PSA_CRYPTO_CONFIG_FILE" >> "$CONFIG_H"
1660 cp configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
1661
1662 # Other config adjustment to make the tests pass.
1663 # This should probably be adopted upstream.
1664 #
1665 # - USE_PSA_CRYPTO for PK_HAVE_ECC_KEYS
1666 echo "#define MBEDTLS_USE_PSA_CRYPTO" >> "$CONFIG_H"
1667
1668 # Config adjustment for better test coverage in our environment.
1669 # This is not needed just to build and pass tests.
1670 #
1671 # Enable filesystem I/O for the benefit of PK parse/write tests.
1672 echo "#define MBEDTLS_FS_IO" >> "$CONFIG_H"
1673}
1674
1675# Keep this in sync with component_test_tfm_config() as they are both meant
1676# to be used in analyze_outcomes.py for driver's coverage analysis.
1677component_test_tfm_config_p256m_driver_accel_ec () {
1678 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1679
1680 common_tfm_config
1681
1682 # Build crypto library
1683 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
1684
1685 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1686 not grep mbedtls_ecdsa_ library/ecdsa.o
1687 not grep mbedtls_ecdh_ library/ecdh.o
1688 not grep mbedtls_ecjpake_ library/ecjpake.o
1689 # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
1690 not grep mbedtls_ecp_ library/ecp.o
1691 not grep mbedtls_rsa_ library/rsa.o
1692 not grep mbedtls_dhm_ library/dhm.o
1693 not grep mbedtls_mpi_ library/bignum.o
1694 # Check that p256m was built
1695 grep -q p256_ecdsa_ library/libmbedcrypto.a
1696
1697 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1698 # files, so we want to ensure that it has not be re-enabled accidentally.
1699 not grep mbedtls_cipher library/cipher.o
1700
1701 # Run the tests
1702 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1703 make test
1704}
1705
1706# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1707# they are both meant to be used in analyze_outcomes.py for driver's coverage
1708# analysis.
Gilles Peskineced0edc2024-09-14 11:35:36 +02001709component_test_tfm_config_no_p256m () {
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001710 common_tfm_config
1711
1712 # Disable P256M driver, which is on by default, so that analyze_outcomes
1713 # can compare this test with test_tfm_config_p256m_driver_accel_ec
1714 echo "#undef MBEDTLS_PSA_P256M_DRIVER_ENABLED" >> "$CONFIG_H"
1715
Gilles Peskineced0edc2024-09-14 11:35:36 +02001716 msg "build: TF-M config without p256m"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001717 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' tests
1718
1719 # Check that p256m was not built
1720 not grep p256_ecdsa_ library/libmbedcrypto.a
1721
1722 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1723 # files, so we want to ensure that it has not be re-enabled accidentally.
1724 not grep mbedtls_cipher library/cipher.o
1725
Gilles Peskineced0edc2024-09-14 11:35:36 +02001726 msg "test: TF-M config without p256m"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001727 make test
1728}
1729
1730# This is an helper used by:
1731# - component_test_psa_ecc_key_pair_no_derive
1732# - component_test_psa_ecc_key_pair_no_generate
1733# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1734# enabled, but one. Input arguments are as follows:
1735# - $1 is the key type under test, i.e. ECC/RSA/DH
1736# - $2 is the key option to be unset (i.e. generate, derive, etc)
1737build_and_test_psa_want_key_pair_partial () {
1738 key_type=$1
1739 unset_option=$2
1740 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1741
1742 msg "build: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
1743 scripts/config.py full
1744 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1745 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1746
1747 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1748 # crypto_config.h so we just disable the one we don't want.
1749 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
1750
1751 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1752
1753 msg "test: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
1754 make test
1755}
1756
1757component_test_psa_ecc_key_pair_no_derive () {
1758 build_and_test_psa_want_key_pair_partial "ECC" "DERIVE"
1759}
1760
1761component_test_psa_ecc_key_pair_no_generate () {
1762 build_and_test_psa_want_key_pair_partial "ECC" "GENERATE"
1763}
1764
1765config_psa_crypto_accel_rsa () {
1766 driver_only=$1
1767
1768 # Start from crypto_full config (no X.509, no TLS)
1769 helper_libtestdriver1_adjust_config "crypto_full"
1770
1771 if [ "$driver_only" -eq 1 ]; then
1772 # Remove RSA support and its dependencies
1773 scripts/config.py unset MBEDTLS_RSA_C
1774 scripts/config.py unset MBEDTLS_PKCS1_V15
1775 scripts/config.py unset MBEDTLS_PKCS1_V21
1776
1777 # We need PEM parsing in the test library as well to support the import
1778 # of PEM encoded RSA keys.
1779 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1780 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
1781 fi
1782}
1783
1784component_test_psa_crypto_config_accel_rsa_crypto () {
1785 msg "build: crypto_full with accelerated RSA"
1786
1787 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1788 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1789 KEY_TYPE_RSA_PUBLIC_KEY \
1790 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1791 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1792 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1793 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1794
1795 # Configure
1796 # ---------
1797
1798 config_psa_crypto_accel_rsa 1
1799
1800 # Build
1801 # -----
1802
1803 # These hashes are needed for unit tests.
1804 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1805 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1806 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1807
1808 helper_libtestdriver1_make_main "$loc_accel_list"
1809
1810 # Make sure this was not re-enabled by accident (additive config)
1811 not grep mbedtls_rsa library/rsa.o
1812
1813 # Run the tests
1814 # -------------
1815
1816 msg "test: crypto_full with accelerated RSA"
1817 make test
1818}
1819
1820component_test_psa_crypto_config_reference_rsa_crypto () {
1821 msg "build: crypto_full with non-accelerated RSA"
1822
1823 # Configure
1824 # ---------
1825 config_psa_crypto_accel_rsa 0
1826
1827 # Build
1828 # -----
1829 make
1830
1831 # Run the tests
1832 # -------------
1833 msg "test: crypto_full with non-accelerated RSA"
1834 make test
1835}
1836
1837# This is a temporary test to verify that full RSA support is present even when
1838# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
1839component_test_new_psa_want_key_pair_symbol () {
1840 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1841
1842 # Create a temporary output file unless there is already one set
1843 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1844 REMOVE_OUTCOME_ON_EXIT="no"
1845 else
1846 REMOVE_OUTCOME_ON_EXIT="yes"
1847 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1848 export MBEDTLS_TEST_OUTCOME_FILE
1849 fi
1850
1851 # Start from crypto configuration
1852 scripts/config.py crypto
1853
1854 # Remove RSA support and its dependencies
1855 scripts/config.py unset MBEDTLS_PKCS1_V15
1856 scripts/config.py unset MBEDTLS_PKCS1_V21
1857 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1858 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1859 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1860 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1861 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1862 scripts/config.py unset MBEDTLS_RSA_C
1863 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1864
1865 # Enable PSA support
1866 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1867
1868 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
1869 # that proper translations is done in crypto_legacy.h.
1870 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
1871 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
1872 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
1873
1874 make
1875
1876 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1877 make test
1878
1879 # Parse only 1 relevant line from the outcome file, i.e. a test which is
1880 # performing RSA signature.
1881 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
1882 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
1883
1884 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
1885 rm $MBEDTLS_TEST_OUTCOME_FILE
1886 fi
1887}
1888
1889component_test_psa_crypto_config_accel_hash () {
1890 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
1891
1892 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1893 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1894 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1895
1896 # Configure
1897 # ---------
1898
1899 # Start from default config (no USE_PSA)
1900 helper_libtestdriver1_adjust_config "default"
1901
1902 # Disable the things that are being accelerated
1903 scripts/config.py unset MBEDTLS_MD5_C
1904 scripts/config.py unset MBEDTLS_RIPEMD160_C
1905 scripts/config.py unset MBEDTLS_SHA1_C
1906 scripts/config.py unset MBEDTLS_SHA224_C
1907 scripts/config.py unset MBEDTLS_SHA256_C
1908 scripts/config.py unset MBEDTLS_SHA384_C
1909 scripts/config.py unset MBEDTLS_SHA512_C
1910 scripts/config.py unset MBEDTLS_SHA3_C
1911
1912 # Build
1913 # -----
1914
1915 helper_libtestdriver1_make_drivers "$loc_accel_list"
1916
1917 helper_libtestdriver1_make_main "$loc_accel_list"
1918
1919 # There's a risk of something getting re-enabled via config_psa.h;
1920 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1921 not grep mbedtls_md5 library/md5.o
1922 not grep mbedtls_sha1 library/sha1.o
1923 not grep mbedtls_sha256 library/sha256.o
1924 not grep mbedtls_sha512 library/sha512.o
1925 not grep mbedtls_ripemd160 library/ripemd160.o
1926
1927 # Run the tests
1928 # -------------
1929
1930 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
1931 make test
1932}
1933
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01001934component_test_psa_crypto_config_accel_hash_keep_builtins () {
1935 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
1936 # This component ensures that all the test cases for
1937 # md_psa_dynamic_dispatch with legacy+driver in test_suite_md are run.
1938
1939 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1940 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1941 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1942
1943 # Start from default config (no USE_PSA)
1944 helper_libtestdriver1_adjust_config "default"
1945
1946 helper_libtestdriver1_make_drivers "$loc_accel_list"
1947
1948 helper_libtestdriver1_make_main "$loc_accel_list"
1949
1950 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
1951 make test
1952}
1953
1954# This should be renamed to test and updated once the accelerator ECDH code is in place and ready to test.
1955component_build_psa_accel_alg_ecdh () {
1956 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
1957 scripts/config.py full
1958 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1959 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1960 scripts/config.py unset MBEDTLS_ECDH_C
1961 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1962 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1963 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1964 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1965 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
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_ECDH -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
1968}
1969
1970# This should be renamed to test and updated once the accelerator HMAC code is in place and ready to test.
1971component_build_psa_accel_alg_hmac () {
1972 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
1973 scripts/config.py full
1974 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1975 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1976 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1977 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
1978}
1979
1980# This should be renamed to test and updated once the accelerator HKDF code is in place and ready to test.
1981component_build_psa_accel_alg_hkdf () {
1982 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
1983 scripts/config.py full
1984 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1985 scripts/config.py unset MBEDTLS_HKDF_C
1986 # Make sure to unset TLS1_3 since it requires HKDF_C and will not build properly without it.
1987 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1988 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1989 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
1990}
1991
1992# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
1993component_build_psa_accel_alg_md5 () {
1994 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - other hashes"
1995 scripts/config.py full
1996 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1997 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1998 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
1999 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2000 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2001 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2002 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2003 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2004 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2005 scripts/config.py unset MBEDTLS_LMS_C
2006 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2007 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2008 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
2009}
2010
2011# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
2012component_build_psa_accel_alg_ripemd160 () {
2013 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - other hashes"
2014 scripts/config.py full
2015 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2016 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2017 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2018 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2019 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2020 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2021 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2022 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2023 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2024 scripts/config.py unset MBEDTLS_LMS_C
2025 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2026 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2027 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
2028}
2029
2030# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
2031component_build_psa_accel_alg_sha1 () {
2032 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - other hashes"
2033 scripts/config.py full
2034 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2035 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2036 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2037 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2038 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2039 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2040 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2041 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2042 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2043 scripts/config.py unset MBEDTLS_LMS_C
2044 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2045 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2046 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
2047}
2048
2049# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
2050component_build_psa_accel_alg_sha224 () {
2051 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
2052 scripts/config.py full
2053 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2054 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2055 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2056 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2057 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2058 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2059 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2060 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2061 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2062 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
2063}
2064
2065# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
2066component_build_psa_accel_alg_sha256 () {
2067 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - other hashes"
2068 scripts/config.py full
2069 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2070 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2071 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2072 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2073 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2074 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2075 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2076 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2077 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2078 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
2079}
2080
2081# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
2082component_build_psa_accel_alg_sha384 () {
2083 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
2084 scripts/config.py full
2085 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2086 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2087 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2088 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2089 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2090 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2091 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2092 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2093 scripts/config.py unset MBEDTLS_LMS_C
2094 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2095 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2096 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
2097}
2098
2099# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
2100component_build_psa_accel_alg_sha512 () {
2101 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
2102 scripts/config.py full
2103 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2104 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2105 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2106 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2107 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2108 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2109 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2110 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2111 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2112 scripts/config.py unset MBEDTLS_LMS_C
2113 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2114 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2115 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
2116}
2117
2118# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2119component_build_psa_accel_alg_rsa_pkcs1v15_crypt () {
2120 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2121 scripts/config.py full
2122 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2123 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2124 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
2125 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2126 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
2127 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
2128 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2129 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
2130}
2131
2132# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2133component_build_psa_accel_alg_rsa_pkcs1v15_sign () {
2134 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2135 scripts/config.py full
2136 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2137 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2138 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
2139 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2140 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
2141 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
2142 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2143 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
2144}
2145
2146# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2147component_build_psa_accel_alg_rsa_oaep () {
2148 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2149 scripts/config.py full
2150 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2151 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2152 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_OAEP 1
2153 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2154 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2155 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
2156 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2157 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
2158}
2159
2160# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2161component_build_psa_accel_alg_rsa_pss () {
2162 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2163 scripts/config.py full
2164 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2165 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2166 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
2167 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2168 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2169 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
2170 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2171 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
2172}
2173
2174# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2175component_build_psa_accel_key_type_rsa_key_pair () {
2176 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_xxx + PSA_WANT_ALG_RSA_PSS"
2177 scripts/config.py full
2178 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2179 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2180 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
2181 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC 1
2182 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT 1
2183 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT 1
2184 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE 1
2185 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2186 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"
2187}
2188
2189# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2190component_build_psa_accel_key_type_rsa_public_key () {
2191 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
2192 scripts/config.py full
2193 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2194 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2195 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
2196 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
2197 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2198 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"
2199}
2200
Minos Galanakis3ece57e2024-08-01 17:09:49 +01002201# Auxiliary function to build config for hashes with and without drivers
2202config_psa_crypto_hash_use_psa () {
2203 driver_only="$1"
2204 # start with config full for maximum coverage (also enables USE_PSA)
2205 helper_libtestdriver1_adjust_config "full"
2206 if [ "$driver_only" -eq 1 ]; then
2207 # disable the built-in implementation of hashes
2208 scripts/config.py unset MBEDTLS_MD5_C
2209 scripts/config.py unset MBEDTLS_RIPEMD160_C
2210 scripts/config.py unset MBEDTLS_SHA1_C
2211 scripts/config.py unset MBEDTLS_SHA224_C
2212 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
2213 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2214 scripts/config.py unset MBEDTLS_SHA384_C
2215 scripts/config.py unset MBEDTLS_SHA512_C
2216 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2217 scripts/config.py unset MBEDTLS_SHA3_C
2218 fi
2219}
2220
2221# Note that component_test_psa_crypto_config_reference_hash_use_psa
2222# is related to this component and both components need to be kept in sync.
2223# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
2224component_test_psa_crypto_config_accel_hash_use_psa () {
2225 msg "test: full with accelerated hashes"
2226
2227 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
2228 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2229 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2230
2231 # Configure
2232 # ---------
2233
2234 config_psa_crypto_hash_use_psa 1
2235
2236 # Build
2237 # -----
2238
2239 helper_libtestdriver1_make_drivers "$loc_accel_list"
2240
2241 helper_libtestdriver1_make_main "$loc_accel_list"
2242
2243 # There's a risk of something getting re-enabled via config_psa.h;
2244 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
2245 not grep mbedtls_md5 library/md5.o
2246 not grep mbedtls_sha1 library/sha1.o
2247 not grep mbedtls_sha256 library/sha256.o
2248 not grep mbedtls_sha512 library/sha512.o
2249 not grep mbedtls_ripemd160 library/ripemd160.o
2250
2251 # Run the tests
2252 # -------------
2253
2254 msg "test: full with accelerated hashes"
2255 make test
2256
2257 # This is mostly useful so that we can later compare outcome files with
2258 # the reference config in analyze_outcomes.py, to check that the
2259 # dependency declarations in ssl-opt.sh and in TLS code are correct.
2260 msg "test: ssl-opt.sh, full with accelerated hashes"
2261 tests/ssl-opt.sh
2262
2263 # This is to make sure all ciphersuites are exercised, but we don't need
2264 # interop testing (besides, we already got some from ssl-opt.sh).
2265 msg "test: compat.sh, full with accelerated hashes"
2266 tests/compat.sh -p mbedTLS -V YES
2267}
2268
2269# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
2270# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
2271# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
2272# Both components need to be kept in sync.
2273component_test_psa_crypto_config_reference_hash_use_psa () {
2274 msg "test: full without accelerated hashes"
2275
2276 config_psa_crypto_hash_use_psa 0
2277
2278 make
2279
2280 msg "test: full without accelerated hashes"
2281 make test
2282
2283 msg "test: ssl-opt.sh, full without accelerated hashes"
2284 tests/ssl-opt.sh
2285}
2286
2287# Auxiliary function to build config for hashes with and without drivers
2288config_psa_crypto_hmac_use_psa () {
2289 driver_only="$1"
2290 # start with config full for maximum coverage (also enables USE_PSA)
2291 helper_libtestdriver1_adjust_config "full"
2292
2293 if [ "$driver_only" -eq 1 ]; then
2294 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
2295 # is still enabled though (for ENTROPY_C among others).
2296 scripts/config.py unset MBEDTLS_MD_C
2297 # Disable also the builtin hashes since they are supported by the driver
2298 # and MD module is able to perform PSA dispathing.
2299 scripts/config.py unset-all MBEDTLS_SHA
2300 scripts/config.py unset MBEDTLS_MD5_C
2301 scripts/config.py unset MBEDTLS_RIPEMD160_C
2302 fi
2303
2304 # Direct dependencies of MD_C. We disable them also in the reference
2305 # component to work with the same set of features.
2306 scripts/config.py unset MBEDTLS_PKCS7_C
2307 scripts/config.py unset MBEDTLS_PKCS5_C
2308 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
2309 scripts/config.py unset MBEDTLS_HKDF_C
2310 # Dependencies of HMAC_DRBG
2311 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
2312 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
2313}
2314
2315component_test_psa_crypto_config_accel_hmac () {
2316 msg "test: full with accelerated hmac"
2317
2318 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
2319 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
2320 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2321 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2322
2323 # Configure
2324 # ---------
2325
2326 config_psa_crypto_hmac_use_psa 1
2327
2328 # Build
2329 # -----
2330
2331 helper_libtestdriver1_make_drivers "$loc_accel_list"
2332
2333 helper_libtestdriver1_make_main "$loc_accel_list"
2334
2335 # Ensure that built-in support for HMAC is disabled.
2336 not grep mbedtls_md_hmac library/md.o
2337
2338 # Run the tests
2339 # -------------
2340
2341 msg "test: full with accelerated hmac"
2342 make test
2343}
2344
2345component_test_psa_crypto_config_reference_hmac () {
2346 msg "test: full without accelerated hmac"
2347
2348 config_psa_crypto_hmac_use_psa 0
2349
2350 make
2351
2352 msg "test: full without accelerated hmac"
2353 make test
2354}
2355
2356component_test_psa_crypto_config_accel_des () {
2357 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
2358
2359 # Albeit this components aims at accelerating DES which should only support
2360 # CBC and ECB modes, we need to accelerate more than that otherwise DES_C
2361 # would automatically be re-enabled by "config_adjust_legacy_from_psa.c"
2362 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 \
2363 ALG_CTR ALG_CFB ALG_OFB ALG_XTS ALG_CMAC \
2364 KEY_TYPE_DES"
2365
2366 # Note: we cannot accelerate all ciphers' key types otherwise we would also
2367 # have to either disable CCM/GCM or accelerate them, but that's out of scope
2368 # of this component. This limitation will be addressed by #8598.
2369
2370 # Configure
2371 # ---------
2372
2373 # Start from the full config
2374 helper_libtestdriver1_adjust_config "full"
2375
2376 # Disable the things that are being accelerated
2377 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2378 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2379 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2380 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2381 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2382 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2383 scripts/config.py unset MBEDTLS_DES_C
2384 scripts/config.py unset MBEDTLS_CMAC_C
2385
2386 # Build
2387 # -----
2388
2389 helper_libtestdriver1_make_drivers "$loc_accel_list"
2390
2391 helper_libtestdriver1_make_main "$loc_accel_list"
2392
2393 # Make sure this was not re-enabled by accident (additive config)
2394 not grep mbedtls_des* library/des.o
2395
2396 # Run the tests
2397 # -------------
2398
2399 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
2400 make test
2401}
2402
2403component_test_psa_crypto_config_accel_aead () {
2404 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2405
2406 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
2407 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2408
2409 # Configure
2410 # ---------
2411
2412 # Start from full config
2413 helper_libtestdriver1_adjust_config "full"
2414
2415 # Disable things that are being accelerated
2416 scripts/config.py unset MBEDTLS_GCM_C
2417 scripts/config.py unset MBEDTLS_CCM_C
2418 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2419
2420 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
2421 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
2422
2423 # Build
2424 # -----
2425
2426 helper_libtestdriver1_make_drivers "$loc_accel_list"
2427
2428 helper_libtestdriver1_make_main "$loc_accel_list"
2429
2430 # Make sure this was not re-enabled by accident (additive config)
2431 not grep mbedtls_ccm library/ccm.o
2432 not grep mbedtls_gcm library/gcm.o
2433 not grep mbedtls_chachapoly library/chachapoly.o
2434
2435 # Run the tests
2436 # -------------
2437
2438 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2439 make test
2440}
2441
2442# This is a common configuration function used in:
2443# - component_test_psa_crypto_config_accel_cipher_aead_cmac
2444# - component_test_psa_crypto_config_reference_cipher_aead_cmac
2445common_psa_crypto_config_accel_cipher_aead_cmac () {
2446 # Start from the full config
2447 helper_libtestdriver1_adjust_config "full"
2448
2449 scripts/config.py unset MBEDTLS_NIST_KW_C
2450}
2451
2452# The 2 following test components, i.e.
2453# - component_test_psa_crypto_config_accel_cipher_aead_cmac
2454# - component_test_psa_crypto_config_reference_cipher_aead_cmac
2455# are meant to be used together in analyze_outcomes.py script in order to test
2456# driver's coverage for ciphers and AEADs.
2457component_test_psa_crypto_config_accel_cipher_aead_cmac () {
2458 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
2459
2460 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
2461 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
2462 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
2463 KEY_TYPE_DES KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
2464
2465 # Configure
2466 # ---------
2467
2468 common_psa_crypto_config_accel_cipher_aead_cmac
2469
2470 # Disable the things that are being accelerated
2471 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2472 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2473 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2474 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2475 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2476 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2477 scripts/config.py unset MBEDTLS_GCM_C
2478 scripts/config.py unset MBEDTLS_CCM_C
2479 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2480 scripts/config.py unset MBEDTLS_CMAC_C
2481 scripts/config.py unset MBEDTLS_DES_C
2482 scripts/config.py unset MBEDTLS_AES_C
2483 scripts/config.py unset MBEDTLS_ARIA_C
2484 scripts/config.py unset MBEDTLS_CHACHA20_C
2485 scripts/config.py unset MBEDTLS_CAMELLIA_C
2486
2487 # Disable CIPHER_C entirely as all ciphers/AEADs are accelerated and PSA
2488 # does not depend on it.
2489 scripts/config.py unset MBEDTLS_CIPHER_C
2490
2491 # Build
2492 # -----
2493
2494 helper_libtestdriver1_make_drivers "$loc_accel_list"
2495
2496 helper_libtestdriver1_make_main "$loc_accel_list"
2497
2498 # Make sure this was not re-enabled by accident (additive config)
2499 not grep mbedtls_cipher library/cipher.o
2500 not grep mbedtls_des library/des.o
2501 not grep mbedtls_aes library/aes.o
2502 not grep mbedtls_aria library/aria.o
2503 not grep mbedtls_camellia library/camellia.o
2504 not grep mbedtls_ccm library/ccm.o
2505 not grep mbedtls_gcm library/gcm.o
2506 not grep mbedtls_chachapoly library/chachapoly.o
2507 not grep mbedtls_cmac library/cmac.o
2508
2509 # Run the tests
2510 # -------------
2511
2512 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
2513 make test
2514
2515 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
2516 tests/ssl-opt.sh
2517
2518 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
2519 tests/compat.sh -V NO -p mbedTLS
2520}
2521
2522component_test_psa_crypto_config_reference_cipher_aead_cmac () {
2523 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
2524 common_psa_crypto_config_accel_cipher_aead_cmac
2525
2526 make
2527
2528 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
2529 make test
2530
2531 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
2532 tests/ssl-opt.sh
2533
2534 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
2535 tests/compat.sh -V NO -p mbedTLS
2536}
2537
2538common_block_cipher_dispatch () {
2539 TEST_WITH_DRIVER="$1"
2540
2541 # Start from the full config
2542 helper_libtestdriver1_adjust_config "full"
2543
2544 if [ "$TEST_WITH_DRIVER" -eq 1 ]; then
2545 # Disable key types that are accelerated (there is no legacy equivalent
2546 # symbol for ECB)
2547 scripts/config.py unset MBEDTLS_AES_C
2548 scripts/config.py unset MBEDTLS_ARIA_C
2549 scripts/config.py unset MBEDTLS_CAMELLIA_C
2550 fi
2551
2552 # Disable cipher's modes that, when not accelerated, cause
2553 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
2554 # Keep this also in the reference component in order to skip the same tests
2555 # that were skipped in the accelerated one.
2556 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
2557 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
2558 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
2559 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
2560 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
2561 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
2562 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
2563 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
2564
2565 # Disable direct dependency on AES_C
2566 scripts/config.py unset MBEDTLS_NIST_KW_C
2567
2568 # Prevent the cipher module from using deprecated PSA path. The reason is
2569 # that otherwise there will be tests relying on "aes_info" (defined in
2570 # "cipher_wrap.c") whose functions are not available when AES_C is
2571 # not defined. ARIA and Camellia are not a problem in this case because
2572 # the PSA path is not tested for these key types.
2573 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
2574}
2575
Gilles Peskine9dc903a2024-06-21 11:25:01 +02002576component_test_full_block_cipher_psa_dispatch_static_keystore () {
2577 msg "build: full + PSA dispatch in block_cipher with static keystore"
2578 # Check that the static key store works well when CTR_DRBG uses a
2579 # PSA key for AES.
2580 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2581
2582 loc_accel_list="ALG_ECB_NO_PADDING \
2583 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2584
2585 # Configure
2586 # ---------
2587
2588 common_block_cipher_dispatch 1
2589
2590 # Build
2591 # -----
2592
2593 helper_libtestdriver1_make_drivers "$loc_accel_list"
2594
2595 helper_libtestdriver1_make_main "$loc_accel_list"
2596
2597 # Make sure disabled components were not re-enabled by accident (additive
2598 # config)
2599 not grep mbedtls_aes_ library/aes.o
2600 not grep mbedtls_aria_ library/aria.o
2601 not grep mbedtls_camellia_ library/camellia.o
2602
2603 # Run the tests
2604 # -------------
2605
2606 msg "test: full + PSA dispatch in block_cipher with static keystore"
2607 make test
2608}
2609
Minos Galanakis3ece57e2024-08-01 17:09:49 +01002610component_test_full_block_cipher_psa_dispatch () {
2611 msg "build: full + PSA dispatch in block_cipher"
2612
2613 loc_accel_list="ALG_ECB_NO_PADDING \
2614 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2615
2616 # Configure
2617 # ---------
2618
2619 common_block_cipher_dispatch 1
2620
2621 # Build
2622 # -----
2623
2624 helper_libtestdriver1_make_drivers "$loc_accel_list"
2625
2626 helper_libtestdriver1_make_main "$loc_accel_list"
2627
2628 # Make sure disabled components were not re-enabled by accident (additive
2629 # config)
2630 not grep mbedtls_aes_ library/aes.o
2631 not grep mbedtls_aria_ library/aria.o
2632 not grep mbedtls_camellia_ library/camellia.o
2633
2634 # Run the tests
2635 # -------------
2636
2637 msg "test: full + PSA dispatch in block_cipher"
2638 make test
2639}
2640
2641# This is the reference component of component_test_full_block_cipher_psa_dispatch
2642component_test_full_block_cipher_legacy_dispatch () {
2643 msg "build: full + legacy dispatch in block_cipher"
2644
2645 common_block_cipher_dispatch 0
2646
2647 make
2648
2649 msg "test: full + legacy dispatch in block_cipher"
2650 make test
2651}
2652
2653component_test_aead_chachapoly_disabled () {
2654 msg "build: full minus CHACHAPOLY"
2655 scripts/config.py full
2656 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2657 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2658 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2659
2660 msg "test: full minus CHACHAPOLY"
2661 make test
2662}
2663
2664component_test_aead_only_ccm () {
2665 msg "build: full minus CHACHAPOLY and GCM"
2666 scripts/config.py full
2667 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2668 scripts/config.py unset MBEDTLS_GCM_C
2669 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2670 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2671 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2672
2673 msg "test: full minus CHACHAPOLY and GCM"
2674 make test
2675}
2676
2677component_test_ccm_aes_sha256 () {
2678 msg "build: CCM + AES + SHA256 configuration"
2679
2680 cp "$CONFIG_TEST_DRIVER_H" "$CONFIG_H"
2681 cp configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
2682
2683 make
2684
2685 msg "test: CCM + AES + SHA256 configuration"
2686 make test
2687}
2688
2689# Test that the given .o file builds with all (valid) combinations of the given options.
2690#
2691# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
2692#
2693# The validator function is the name of a function to validate the combination of options.
2694# It may be "" if all combinations are valid.
2695# It receives a string containing a combination of options, as passed to the compiler,
2696# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
2697build_test_config_combos () {
2698 file=$1
2699 shift
2700 validate_options=$1
2701 shift
2702 options=("$@")
2703
2704 # clear all of the options so that they can be overridden on the clang commandline
2705 for opt in "${options[@]}"; do
2706 ./scripts/config.py unset ${opt}
2707 done
2708
2709 # enter the directory containing the target file & strip the dir from the filename
2710 cd $(dirname ${file})
2711 file=$(basename ${file})
2712
2713 # The most common issue is unused variables/functions, so ensure -Wunused is set.
2714 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
2715
2716 # Extract the command generated by the Makefile to build the target file.
2717 # This ensures that we have any include paths, macro definitions, etc
2718 # that may be applied by make.
2719 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
2720 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
2721
2722 makefile=$(TMPDIR=. mktemp)
2723 deps=""
2724
2725 len=${#options[@]}
2726 source_file=${file%.o}.c
2727
2728 targets=0
2729 echo 'include Makefile' >${makefile}
2730
2731 for ((i = 0; i < $((2**${len})); i++)); do
2732 # generate each of 2^n combinations of options
2733 # each bit of $i is used to determine if options[i] will be set or not
2734 target="t"
2735 clang_args=""
2736 for ((j = 0; j < ${len}; j++)); do
2737 if (((i >> j) & 1)); then
2738 opt=-D${options[$j]}
2739 clang_args="${clang_args} ${opt}"
2740 target="${target}${opt}"
2741 fi
2742 done
2743
2744 # if combination is not known to be invalid, add it to the makefile
2745 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
2746 cmd="${compile_cmd} ${clang_args}"
2747 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
2748
2749 deps="${deps} ${target}"
2750 ((++targets))
2751 fi
2752 done
2753
2754 echo "build_test_config_combos: ${deps}" >> ${makefile}
2755
2756 # execute all of the commands via Make (probably in parallel)
2757 make -s -f ${makefile} build_test_config_combos
2758 echo "$targets targets checked"
2759
2760 # clean up the temporary makefile
2761 rm ${makefile}
2762}
2763
2764validate_aes_config_variations () {
2765 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
2766 if [[ "$1" == *"MBEDTLS_PADLOCK_C"* ]]; then
2767 return 1
2768 fi
2769 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
2770 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
2771 return 1
2772 fi
2773 fi
2774 return 0
2775}
2776
2777component_build_aes_variations () {
2778 # 18s - around 90ms per clang invocation on M1 Pro
2779 #
2780 # aes.o has many #if defined(...) guards that intersect in complex ways.
2781 # Test that all the combinations build cleanly.
2782
2783 MBEDTLS_ROOT_DIR="$PWD"
2784 msg "build: aes.o for all combinations of relevant config options"
2785
2786 build_test_config_combos library/aes.o validate_aes_config_variations \
2787 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
2788 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
2789 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2790 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2791
2792 cd "$MBEDTLS_ROOT_DIR"
2793 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
2794
2795 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES,
2796 # manually set or unset those configurations to check
2797 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
2798 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
2799 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2800 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2801 scripts/config.py unset MBEDTLS_DES_C
2802 scripts/config.py unset MBEDTLS_NIST_KW_C
2803 build_test_config_combos library/aes.o validate_aes_config_variations \
2804 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
2805 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
2806 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2807 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2808}
2809
2810component_test_sha3_variations () {
2811 msg "sha3 loop unroll variations"
2812
2813 # define minimal config sufficient to test SHA3
2814 cat > include/mbedtls/mbedtls_config.h << END
2815 #define MBEDTLS_SELF_TEST
2816 #define MBEDTLS_SHA3_C
2817END
2818
2819 msg "all loops unrolled"
2820 make clean
2821 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"
2822 ./tests/test_suite_shax
2823
2824 msg "all loops rolled up"
2825 make clean
2826 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"
2827 ./tests/test_suite_shax
2828}
2829
2830# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2831component_build_aes_aesce_armcc () {
2832 msg "Build: AESCE test on arm64 platform without plain C."
2833 scripts/config.py baremetal
2834
2835 # armc[56] don't support SHA-512 intrinsics
2836 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2837
2838 # Stop armclang warning about feature detection for A64_CRYPTO.
2839 # With this enabled, the library does build correctly under armclang,
2840 # but in baremetal builds (as tested here), feature detection is
2841 # unavailable, and the user is notified via a #warning. So enabling
2842 # this feature would prevent us from building with -Werror on
2843 # armclang. Tracked in #7198.
2844 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2845 scripts/config.py set MBEDTLS_HAVE_ASM
2846
2847 msg "AESCE, build with default configuration."
2848 scripts/config.py set MBEDTLS_AESCE_C
2849 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
2850 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
2851
2852 msg "AESCE, build AESCE only"
2853 scripts/config.py set MBEDTLS_AESCE_C
2854 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
2855 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
2856}
2857
2858support_build_aes_aesce_armcc () {
2859 support_build_armcc
2860}
2861
2862component_test_aes_only_128_bit_keys () {
2863 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2864 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2865 scripts/config.py unset MBEDTLS_PADLOCK_C
2866
2867 make CFLAGS='-O2 -Werror -Wall -Wextra'
2868
2869 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2870 make test
2871}
2872
2873component_test_no_ctr_drbg_aes_only_128_bit_keys () {
2874 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2875 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2876 scripts/config.py unset MBEDTLS_CTR_DRBG_C
2877 scripts/config.py unset MBEDTLS_PADLOCK_C
2878
2879 make CC=clang CFLAGS='-Werror -Wall -Wextra'
2880
2881 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2882 make test
2883}
2884
2885component_test_aes_only_128_bit_keys_have_builtins () {
2886 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2887 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2888 scripts/config.py unset MBEDTLS_PADLOCK_C
2889 scripts/config.py unset MBEDTLS_AESNI_C
2890 scripts/config.py unset MBEDTLS_AESCE_C
2891
2892 make CFLAGS='-O2 -Werror -Wall -Wextra'
2893
2894 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2895 make test
2896
2897 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2898 programs/test/selftest
2899}
2900
2901component_test_gcm_largetable () {
2902 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2903 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
2904 scripts/config.py unset MBEDTLS_PADLOCK_C
2905 scripts/config.py unset MBEDTLS_AESNI_C
2906 scripts/config.py unset MBEDTLS_AESCE_C
2907
2908 make CFLAGS='-O2 -Werror -Wall -Wextra'
2909
2910 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2911 make test
2912}
2913
2914component_test_aes_fewer_tables () {
2915 msg "build: default config with AES_FEWER_TABLES enabled"
2916 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2917 make CFLAGS='-O2 -Werror -Wall -Wextra'
2918
2919 msg "test: AES_FEWER_TABLES"
2920 make test
2921}
2922
2923component_test_aes_rom_tables () {
2924 msg "build: default config with AES_ROM_TABLES enabled"
2925 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2926 make CFLAGS='-O2 -Werror -Wall -Wextra'
2927
2928 msg "test: AES_ROM_TABLES"
2929 make test
2930}
2931
2932component_test_aes_fewer_tables_and_rom_tables () {
2933 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
2934 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2935 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2936 make CFLAGS='-O2 -Werror -Wall -Wextra'
2937
2938 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2939 make test
2940}
2941
2942# helper for common_block_cipher_no_decrypt() which:
2943# - enable/disable the list of config options passed from -s/-u respectively.
2944# - build
2945# - test for tests_suite_xxx
2946# - selftest
2947#
2948# Usage: helper_block_cipher_no_decrypt_build_test
2949# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
2950# Options: -s set_opts the list of config options to enable
2951# -u unset_opts the list of config options to disable
2952# -c cflags the list of options passed to CFLAGS
2953# -l ldflags the list of options passed to LDFLAGS
2954helper_block_cipher_no_decrypt_build_test () {
2955 while [ $# -gt 0 ]; do
2956 case "$1" in
2957 -s)
2958 shift; local set_opts="$1";;
2959 -u)
2960 shift; local unset_opts="$1";;
2961 -c)
2962 shift; local cflags="-Werror -Wall -Wextra $1";;
2963 -l)
2964 shift; local ldflags="$1";;
2965 esac
2966 shift
2967 done
2968 set_opts="${set_opts:-}"
2969 unset_opts="${unset_opts:-}"
2970 cflags="${cflags:-}"
2971 ldflags="${ldflags:-}"
2972
2973 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
2974 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
2975
2976 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2977 make clean
2978 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
2979
2980 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2981 not grep mbedtls_aes_setkey_dec library/aes.o
2982 not grep mbedtls_aria_setkey_dec library/aria.o
2983 not grep mbedtls_camellia_setkey_dec library/camellia.o
2984 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2985 not grep mbedtls_internal_aes_decrypt library/aes.o
2986 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
2987 not grep mbedtls_aesni_inverse_key library/aesni.o
2988
2989 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2990 make test
2991
2992 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2993 programs/test/selftest
2994}
2995
2996# This is a common configuration function used in:
2997# - component_test_block_cipher_no_decrypt_aesni_legacy()
2998# - component_test_block_cipher_no_decrypt_aesni_use_psa()
2999# in order to test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics,
3000# AESNI assembly and AES C implementation on x86_64 and with AESNI intrinsics
3001# on x86.
3002common_block_cipher_no_decrypt () {
3003 # test AESNI intrinsics
3004 helper_block_cipher_no_decrypt_build_test \
3005 -s "MBEDTLS_AESNI_C" \
3006 -c "-mpclmul -msse2 -maes"
3007
3008 # test AESNI assembly
3009 helper_block_cipher_no_decrypt_build_test \
3010 -s "MBEDTLS_AESNI_C" \
3011 -c "-mno-pclmul -mno-sse2 -mno-aes"
3012
3013 # test AES C implementation
3014 helper_block_cipher_no_decrypt_build_test \
3015 -u "MBEDTLS_AESNI_C"
3016
3017 # test AESNI intrinsics for i386 target
3018 helper_block_cipher_no_decrypt_build_test \
3019 -s "MBEDTLS_AESNI_C" \
3020 -c "-m32 -mpclmul -msse2 -maes" \
3021 -l "-m32"
3022}
3023
3024# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
3025# usage: 0: no PSA crypto configuration
3026# 1: use PSA crypto configuration
3027config_block_cipher_no_decrypt () {
3028 use_psa=$1
3029
3030 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
3031 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3032 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
3033 scripts/config.py unset MBEDTLS_DES_C
3034 scripts/config.py unset MBEDTLS_NIST_KW_C
3035
3036 if [ "$use_psa" -eq 1 ]; then
3037 # Enable support for cryptographic mechanisms through the PSA API.
3038 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
3039 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3040 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
3041 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
3042 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
3043 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
3044 fi
3045}
3046
3047component_test_block_cipher_no_decrypt_aesni () {
3048 # This consistently causes an llvm crash on clang 3.8, so use gcc
3049 export CC=gcc
3050 config_block_cipher_no_decrypt 0
3051 common_block_cipher_no_decrypt
3052}
3053
3054component_test_block_cipher_no_decrypt_aesni_use_psa () {
3055 # This consistently causes an llvm crash on clang 3.8, so use gcc
3056 export CC=gcc
3057 config_block_cipher_no_decrypt 1
3058 common_block_cipher_no_decrypt
3059}
3060
3061support_test_block_cipher_no_decrypt_aesce_armcc () {
3062 support_build_armcc
3063}
3064
3065component_test_block_cipher_no_decrypt_aesce_armcc () {
3066 scripts/config.py baremetal
3067
3068 # armc[56] don't support SHA-512 intrinsics
3069 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
3070
3071 # Stop armclang warning about feature detection for A64_CRYPTO.
3072 # With this enabled, the library does build correctly under armclang,
3073 # but in baremetal builds (as tested here), feature detection is
3074 # unavailable, and the user is notified via a #warning. So enabling
3075 # this feature would prevent us from building with -Werror on
3076 # armclang. Tracked in #7198.
3077 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
3078 scripts/config.py set MBEDTLS_HAVE_ASM
3079
3080 config_block_cipher_no_decrypt 1
3081
3082 # test AESCE baremetal build
3083 scripts/config.py set MBEDTLS_AESCE_C
3084 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
3085 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
3086
3087 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
3088 not grep mbedtls_aes_setkey_dec library/aes.o
3089 not grep mbedtls_aria_setkey_dec library/aria.o
3090 not grep mbedtls_camellia_setkey_dec library/camellia.o
3091 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
3092 not grep mbedtls_internal_aes_decrypt library/aes.o
3093 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
3094 not grep mbedtls_aesce_inverse_key library/aesce.o
3095 not grep aesce_decrypt_block library/aesce.o
3096}
3097
3098component_test_ctr_drbg_aes_256_sha_256 () {
3099 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
3100 scripts/config.py full
3101 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
3102 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
3103 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3104 make
3105
3106 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
3107 make test
3108}
3109
3110component_test_ctr_drbg_aes_128_sha_512 () {
3111 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
3112 scripts/config.py full
3113 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
3114 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
3115 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3116 make
3117
3118 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
3119 make test
3120}
3121
3122component_test_ctr_drbg_aes_128_sha_256 () {
3123 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
3124 scripts/config.py full
3125 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
3126 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
3127 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
3128 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3129 make
3130
3131 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
3132 make test
3133}
3134
3135component_test_se_default () {
3136 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
3137 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
3138 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
3139
3140 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
3141 make test
3142}
3143
Gilles Peskine9dc903a2024-06-21 11:25:01 +02003144component_test_full_static_keystore () {
3145 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
3146 scripts/config.py full
3147 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
3148 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
3149
3150 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
3151 make test
3152}
3153
Minos Galanakis3ece57e2024-08-01 17:09:49 +01003154component_test_psa_crypto_drivers () {
3155 msg "build: full + test drivers dispatching to builtins"
3156 scripts/config.py full
3157 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
3158 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
3159 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
3160 loc_cflags="${loc_cflags} -I../tests/include -O2"
3161
3162 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
3163
3164 msg "test: full + test drivers dispatching to builtins"
3165 make test
3166}
3167
3168component_build_psa_config_file () {
3169 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
3170 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3171 cp "$CRYPTO_CONFIG_H" psa_test_config.h
3172 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
3173 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
3174 # Make sure this feature is enabled. We'll disable it in the next phase.
3175 programs/test/query_compile_time_config MBEDTLS_CMAC_C
3176 make clean
3177
3178 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
3179 # In the user config, disable one feature and its dependencies, which will
3180 # reflect on the mbedtls configuration so we can query it with
3181 # query_compile_time_config.
3182 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
3183 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
3184 scripts/config.py unset MBEDTLS_CMAC_C
3185 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
3186 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
3187
3188 rm -f psa_test_config.h psa_user_config.h
3189}
3190
3191component_build_psa_alt_headers () {
3192 msg "build: make with PSA alt headers" # ~20s
3193
3194 # Generate alternative versions of the substitutable headers with the
3195 # same content except different include guards.
3196 make -C tests include/alt-extra/psa/crypto_platform_alt.h include/alt-extra/psa/crypto_struct_alt.h
3197
3198 # Build the library and some programs.
3199 # Don't build the fuzzers to avoid having to go through hoops to set
3200 # a correct include path for programs/fuzz/Makefile.
3201 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
3202 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\"'"
3203
3204 # Check that we're getting the alternative include guards and not the
3205 # original include guards.
3206 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
3207 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
3208 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
3209 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
3210}
3211
3212component_test_min_mpi_window_size () {
3213 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
3214 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
3215 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3216 make
3217
3218 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
3219 make test
3220}