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