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