blob: de9f0e78bc62af794c243cd544ad1ca92c8f88c6 [file] [log] [blame]
Minos Galanakis6aab5b72024-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
Minos Galanakis609f7492024-07-31 16:39:28 +01006# This file contains test components that are executed by all.sh
Minos Galanakis6aab5b72024-07-25 14:24:37 +01007
8################################################################
9#### Configuration Testing - Crypto
10################################################################
11
Minos Galanakis471b34c2024-07-26 15:39:24 +010012component_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 Settidbb646b2024-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 Galanakis471b34c2024-07-26 15:39:24 +010042# check_renamed_symbols HEADER LIB
43# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
Minos Galanakis609f7492024-07-31 16:39:28 +010044# name in LIB.
Minos Galanakis471b34c2024-07-26 15:39:24 +010045check_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 Galanakisf78447f2024-07-26 20:49:51 +010067component_test_no_rsa_key_pair_generation () {
Minos Galanakisdc0f73a2024-07-26 20:41:42 +010068 msg "build: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
69 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
70 scripts/config.py unset MBEDTLS_GENPRIME
71 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
72 make
73
74 msg "test: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
75 make test
76}
77
Minos Galanakisc06fd302024-08-01 12:16:59 +010078component_test_no_pem_no_fs () {
79 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
80 scripts/config.py unset MBEDTLS_PEM_PARSE_C
81 scripts/config.py unset MBEDTLS_FS_IO
82 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
83 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
84 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
85 make
86
87 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
88 make test
89
90 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
91 tests/ssl-opt.sh
92}
93
94component_test_rsa_no_crt () {
95 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
96 scripts/config.py set MBEDTLS_RSA_NO_CRT
97 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
98 make
99
100 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
101 make test
102
103 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
104 tests/ssl-opt.sh -f RSA
105
106 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
107 tests/compat.sh -t RSA
108
109 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
110 tests/context-info.sh
111}
112
113component_test_no_ctr_drbg_classic () {
114 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
115 scripts/config.py full
116 scripts/config.py unset MBEDTLS_CTR_DRBG_C
117 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
118 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
119
120 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
121 make
122
123 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
124 make test
125
126 # In this configuration, the TLS test programs use HMAC_DRBG.
127 # The SSL tests are slow, so run a small subset, just enough to get
128 # confidence that the SSL code copes with HMAC_DRBG.
129 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
130 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
131
132 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
133 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
134}
135
136component_test_no_ctr_drbg_use_psa () {
137 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
138 scripts/config.py full
139 scripts/config.py unset MBEDTLS_CTR_DRBG_C
140 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
141
142 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
143 make
144
145 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
146 make test
147
148 # In this configuration, the TLS test programs use HMAC_DRBG.
149 # The SSL tests are slow, so run a small subset, just enough to get
150 # confidence that the SSL code copes with HMAC_DRBG.
151 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
152 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
153
154 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
155 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
156}
157
158component_test_no_hmac_drbg_classic () {
159 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
160 scripts/config.py full
161 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
162 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
163 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
164 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
165
166 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
167 make
168
169 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
170 make test
171
172 # Normally our ECDSA implementation uses deterministic ECDSA. But since
173 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
174 # instead.
175 # Test SSL with non-deterministic ECDSA. Only test features that
176 # might be affected by how ECDSA signature is performed.
177 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
178 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
179
180 # To save time, only test one protocol version, since this part of
181 # the protocol is identical in (D)TLS up to 1.2.
182 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
183 tests/compat.sh -m tls12 -t 'ECDSA'
184}
185
186component_test_no_hmac_drbg_use_psa () {
187 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
188 scripts/config.py full
189 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
190 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
191 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
192
193 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
194 make
195
196 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
197 make test
198
199 # Normally our ECDSA implementation uses deterministic ECDSA. But since
200 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
201 # instead.
202 # Test SSL with non-deterministic ECDSA. Only test features that
203 # might be affected by how ECDSA signature is performed.
204 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
205 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
206
207 # To save time, only test one protocol version, since this part of
208 # the protocol is identical in (D)TLS up to 1.2.
209 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
210 tests/compat.sh -m tls12 -t 'ECDSA'
211}
212
213component_test_psa_external_rng_no_drbg_classic () {
214 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
215 scripts/config.py full
216 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
217 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
218 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
219 scripts/config.py unset MBEDTLS_ENTROPY_C
220 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
221 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
222 scripts/config.py unset MBEDTLS_CTR_DRBG_C
223 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
224 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
225 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
226 # the SSL test programs don't have an RNG and can't work. Explicitly
227 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
228 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
229
230 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
231 make test
232
233 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
234 tests/ssl-opt.sh -f 'Default'
235}
236
237component_test_psa_external_rng_no_drbg_use_psa () {
238 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
239 scripts/config.py full
240 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
241 scripts/config.py unset MBEDTLS_ENTROPY_C
242 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
243 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
244 scripts/config.py unset MBEDTLS_CTR_DRBG_C
245 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
246 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
247 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
248
249 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
250 make test
251
252 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
253 tests/ssl-opt.sh -f 'Default\|opaque'
254}
255
Minos Galanakis471b34c2024-07-26 15:39:24 +0100256component_test_psa_external_rng_use_psa_crypto () {
257 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
258 scripts/config.py full
259 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
260 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
261 scripts/config.py unset MBEDTLS_CTR_DRBG_C
262 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
263
264 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
265 make test
266
267 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
268 tests/ssl-opt.sh -f 'Default\|opaque'
269}
270
271component_test_psa_inject_entropy () {
272 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
273 scripts/config.py full
274 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
275 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
276 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
277 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
278 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
279 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
280 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
281
282 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
283 make test
284}
285
Minos Galanakisf78447f2024-07-26 20:49:51 +0100286component_full_no_pkparse_pkwrite () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100287 msg "build: full without pkparse and pkwrite"
288
289 scripts/config.py crypto_full
290 scripts/config.py unset MBEDTLS_PK_PARSE_C
291 scripts/config.py unset MBEDTLS_PK_WRITE_C
292
293 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
294
295 # Ensure that PK_[PARSE|WRITE]_C were not re-enabled accidentally (additive config).
296 not grep mbedtls_pk_parse_key ${BUILTIN_SRC_PATH}/pkparse.o
297 not grep mbedtls_pk_write_key_der ${BUILTIN_SRC_PATH}/pkwrite.o
298
299 msg "test: full without pkparse and pkwrite"
300 make test
301}
302
303component_test_crypto_full_md_light_only () {
304 msg "build: crypto_full with only the light subset of MD"
305 scripts/config.py crypto_full
306
307 # Disable MD
308 scripts/config.py unset MBEDTLS_MD_C
309 # Disable direct dependencies of MD_C
310 scripts/config.py unset MBEDTLS_HKDF_C
311 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
312 scripts/config.py unset MBEDTLS_PKCS7_C
313 # Disable indirect dependencies of MD_C
314 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG
315 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
316 # Disable things that would auto-enable MD_C
317 scripts/config.py unset MBEDTLS_PKCS5_C
318
319 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
320 # which we haven't disabled, so no need to explicitly enable it.
321 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
322
323 # Make sure we don't have the HMAC functions, but the hashing functions
324 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
325 grep mbedtls_md ${BUILTIN_SRC_PATH}/md.o
326
327 msg "test: crypto_full with only the light subset of MD"
328 make test
329}
330
Minos Galanakiscd5668f2024-07-26 20:36:23 +0100331component_test_full_no_cipher () {
332 msg "build: full no CIPHER"
333
334 scripts/config.py full
335 scripts/config.py unset MBEDTLS_CIPHER_C
336
337 # The built-in implementation of the following algs/key-types depends
338 # on CIPHER_C so we disable them.
339 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
340 # so we keep them enabled.
341 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
342 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CMAC
343 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
344 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
345 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CFB
346 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CTR
347 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
348 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_OFB
349 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
350 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_STREAM_CIPHER
351 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
352
353 # The following modules directly depends on CIPHER_C
354 scripts/config.py unset MBEDTLS_CMAC_C
355 scripts/config.py unset MBEDTLS_NIST_KW_C
356
357 make
358
359 # Ensure that CIPHER_C was not re-enabled
360 not grep mbedtls_cipher_init ${BUILTIN_SRC_PATH}/cipher.o
361
362 msg "test: full no CIPHER"
363 make test
364}
365
Minos Galanakisf78447f2024-07-26 20:49:51 +0100366component_test_full_no_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100367 msg "build: full no PSA_WANT_ALG_CCM"
368
369 # Full config enables:
370 # - USE_PSA_CRYPTO so that TLS code dispatches cipher/AEAD to PSA
371 # - CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
372 scripts/config.py full
373
374 # Disable PSA_WANT_ALG_CCM so that CCM is not supported in PSA. CCM_C is still
375 # enabled, but not used from TLS since USE_PSA is set.
376 # This is helpful to ensure that TLS tests below have proper dependencies.
377 #
378 # Note: also PSA_WANT_ALG_CCM_STAR_NO_TAG is enabled, but it does not cause
379 # PSA_WANT_ALG_CCM to be re-enabled.
380 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM
381
382 make
383
384 msg "test: full no PSA_WANT_ALG_CCM"
385 make test
386}
387
Minos Galanakisf78447f2024-07-26 20:49:51 +0100388component_test_full_no_ccm_star_no_tag () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100389 msg "build: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
390
391 # Full config enables CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
392 scripts/config.py full
393
394 # Disable CCM_STAR_NO_TAG, which is the target of this test, as well as all
395 # other components that enable MBEDTLS_PSA_BUILTIN_CIPHER internal symbol.
396 # This basically disables all unauthenticated ciphers on the PSA side, while
397 # keeping AEADs enabled.
398 #
399 # Note: PSA_WANT_ALG_CCM is enabled, but it does not cause
400 # PSA_WANT_ALG_CCM_STAR_NO_TAG to be re-enabled.
401 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
402 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_STREAM_CIPHER
403 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
404 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
405 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
406 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
407 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
408 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
409
410 make
411
412 # Ensure MBEDTLS_PSA_BUILTIN_CIPHER was not enabled
413 not grep mbedtls_psa_cipher ${PSA_CORE_PATH}/psa_crypto_cipher.o
414
415 msg "test: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
416 make test
417}
418
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200419component_test_config_symmetric_only () {
420 msg "build: configs/config-symmetric-only.h"
Gilles Peskineaf5a8992024-09-14 11:27:44 +0200421 cp configs/config-symmetric-only.h "$CONFIG_H"
Gilles Peskineaf5a8992024-09-14 11:27:44 +0200422 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
423 # want to re-generate generated files that depend on it, quite correctly.
424 # However this doesn't work as the generation script expects a specific
425 # format for mbedtls_config.h, which the other files don't follow. Also,
426 # cmake can't know this, but re-generation is actually not necessary as
427 # the generated files only depend on the list of available options, not
428 # whether they're on or off. So, disable cmake's (over-sensitive here)
429 # dependency resolution for generated files and just rely on them being
430 # present (thanks to pre_generate_files) by turning GEN_FILES off.
431 CC=$ASAN_CC cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
432 make
433
Gilles Peskineea5de2b2024-09-19 18:41:55 +0200434 msg "test: configs/config-symmetric-only.h - unit tests"
Gilles Peskineaf5a8992024-09-14 11:27:44 +0200435 make test
436}
437
Minos Galanakisc06fd302024-08-01 12:16:59 +0100438component_test_everest () {
439 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
440 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
441 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
442 make
443
444 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
445 make test
446
447 msg "test: metatests (clang, ASan)"
448 tests/scripts/run-metatests.sh any asan poison
449
450 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
451 tests/ssl-opt.sh -f ECDH
452
453 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
454 # Exclude some symmetric ciphers that are redundant here to gain time.
455 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
456}
457
458component_test_everest_curve25519_only () {
459 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
460 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
461 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
462 scripts/config.py unset MBEDTLS_ECDSA_C
463 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
464 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECDSA
465 scripts/config.py -f $CRYPTO_CONFIG_H set PSA_WANT_ALG_ECDH
466 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
467 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
468 scripts/config.py unset MBEDTLS_ECJPAKE_C
469 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE
470
471 # Disable all curves
472 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
473 scripts/config.py -f $CRYPTO_CONFIG_H unset-all "PSA_WANT_ECC_[0-9A-Z_a-z]*$"
474 scripts/config.py -f $CRYPTO_CONFIG_H set PSA_WANT_ECC_MONTGOMERY_255
475
476 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
477
478 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
479 make test
480}
481
Minos Galanakis471b34c2024-07-26 15:39:24 +0100482component_test_psa_collect_statuses () {
483 msg "build+test: psa_collect_statuses" # ~30s
484 scripts/config.py full
485 tests/scripts/psa_collect_statuses.py
486 # Check that psa_crypto_init() succeeded at least once
487 grep -q '^0:psa_crypto_init:' tests/statuses.log
488 rm -f tests/statuses.log
489}
490
491# Check that the specified libraries exist and are empty.
492are_empty_libraries () {
493 nm "$@" >/dev/null 2>/dev/null
494 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
495}
496
497component_build_crypto_default () {
498 msg "build: make, crypto only"
499 scripts/config.py crypto
500 make CFLAGS='-O1 -Werror'
501 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
502}
503
504component_build_crypto_full () {
505 msg "build: make, crypto only, full config"
506 scripts/config.py crypto_full
507 make CFLAGS='-O1 -Werror'
508 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
509}
510
511component_test_crypto_for_psa_service () {
512 msg "build: make, config for PSA crypto service"
513 scripts/config.py crypto
514 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
515 # Disable things that are not needed for just cryptography, to
516 # reach a configuration that would be typical for a PSA cryptography
517 # service providing all implemented PSA algorithms.
518 # System stuff
519 scripts/config.py unset MBEDTLS_ERROR_C
520 scripts/config.py unset MBEDTLS_TIMING_C
521 scripts/config.py unset MBEDTLS_VERSION_FEATURES
522 # Crypto stuff with no PSA interface
523 scripts/config.py unset MBEDTLS_BASE64_C
524 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
525 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
526 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
527 scripts/config.py unset MBEDTLS_NIST_KW_C
528 scripts/config.py unset MBEDTLS_PEM_PARSE_C
529 scripts/config.py unset MBEDTLS_PEM_WRITE_C
530 scripts/config.py unset MBEDTLS_PKCS12_C
531 scripts/config.py unset MBEDTLS_PKCS5_C
532 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
533 # in PSA code to work with RSA keys. We don't require users to set those:
534 # they will be reenabled in build_info.h.
535 scripts/config.py unset MBEDTLS_PK_C
536 scripts/config.py unset MBEDTLS_PK_PARSE_C
537 scripts/config.py unset MBEDTLS_PK_WRITE_C
538 make CFLAGS='-O1 -Werror' all test
539 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
540}
541
542component_build_crypto_baremetal () {
543 msg "build: make, crypto only, baremetal config"
544 scripts/config.py crypto_baremetal
545 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
546 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
547}
548
549support_build_crypto_baremetal () {
550 support_build_baremetal "$@"
551}
552
553# depends.py family of tests
554component_test_depends_py_cipher_id () {
555 msg "test/build: depends.py cipher_id (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200556 tests/scripts/depends.py cipher_id
Minos Galanakis471b34c2024-07-26 15:39:24 +0100557}
558
559component_test_depends_py_cipher_chaining () {
560 msg "test/build: depends.py cipher_chaining (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200561 tests/scripts/depends.py cipher_chaining
Minos Galanakis471b34c2024-07-26 15:39:24 +0100562}
563
564component_test_depends_py_cipher_padding () {
565 msg "test/build: depends.py cipher_padding (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200566 tests/scripts/depends.py cipher_padding
Minos Galanakis471b34c2024-07-26 15:39:24 +0100567}
568
569component_test_depends_py_curves () {
570 msg "test/build: depends.py curves (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200571 tests/scripts/depends.py curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100572}
573
574component_test_depends_py_hashes () {
575 msg "test/build: depends.py hashes (gcc)"
Gabor Mezei9ce6d242024-06-19 17:47:05 +0200576 tests/scripts/depends.py hashes
Minos Galanakis471b34c2024-07-26 15:39:24 +0100577}
578
Minos Galanakis471b34c2024-07-26 15:39:24 +0100579component_test_depends_py_pkalgs () {
580 msg "test/build: depends.py pkalgs (gcc)"
Minos Galanakis471b34c2024-07-26 15:39:24 +0100581 tests/scripts/depends.py pkalgs
582}
583
584component_test_psa_crypto_config_ffdh_2048_only () {
585 msg "build: full config - only DH 2048"
586
587 scripts/config.py full
588
589 # Disable all DH groups other than 2048.
590 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_3072
591 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_4096
592 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_6144
593 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_8192
594
595 make CFLAGS="$ASAN_CFLAGS -Werror" LDFLAGS="$ASAN_CFLAGS"
596
597 msg "test: full config - only DH 2048"
598 make test
599
600 msg "ssl-opt: full config - only DH 2048"
601 tests/ssl-opt.sh -f "ffdh"
602}
603
604component_build_no_pk_rsa_alt_support () {
605 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
606
607 scripts/config.py full
608 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
609 scripts/config.py set MBEDTLS_RSA_C
610 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
611
612 # Only compile - this is primarily to test for compile issues
613 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
614}
615
616component_build_module_alt () {
617 msg "build: MBEDTLS_XXX_ALT" # ~30s
618 scripts/config.py full
619
620 # Disable options that are incompatible with some ALT implementations:
621 # aesni.c references mbedtls_aes_context fields directly.
622 scripts/config.py unset MBEDTLS_AESNI_C
623 scripts/config.py unset MBEDTLS_AESCE_C
624 # MBEDTLS_ECP_RESTARTABLE is documented as incompatible.
625 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
626 # You can only have one threading implementation: alt or pthread, not both.
627 scripts/config.py unset MBEDTLS_THREADING_PTHREAD
628 # The SpecifiedECDomain parsing code accesses mbedtls_ecp_group fields
629 # directly and assumes the implementation works with partial groups.
630 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
631 # MBEDTLS_SHA256_*ALT can't be used with MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*
632 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
633 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
634 # MBEDTLS_SHA512_*ALT can't be used with MBEDTLS_SHA512_USE_A64_CRYPTO_*
635 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
636 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
637
638 # Enable all MBEDTLS_XXX_ALT for whole modules. Do not enable
639 # MBEDTLS_XXX_YYY_ALT which are for single functions.
640 scripts/config.py set-all 'MBEDTLS_([A-Z0-9]*|NIST_KW)_ALT'
641
642 # We can only compile, not link, since we don't have any implementations
643 # suitable for testing with the dummy alt headers.
644 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
645}
646
647component_test_psa_crypto_config_accel_ecdsa () {
648 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
649
650 # Algorithms and key types to accelerate
651 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
652 $(helper_get_psa_key_type_list "ECC") \
653 $(helper_get_psa_curve_list)"
654
655 # Configure
656 # ---------
657
Elena Uziunaite91d83862024-09-04 14:51:31 +0100658 # Start from default config + TLS 1.3
Minos Galanakis471b34c2024-07-26 15:39:24 +0100659 helper_libtestdriver1_adjust_config "default"
660
Elena Uziunaite91d83862024-09-04 14:51:31 +0100661 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
662
Minos Galanakis471b34c2024-07-26 15:39:24 +0100663 # Disable the module that's accelerated
664 scripts/config.py unset MBEDTLS_ECDSA_C
665
666 # Disable things that depend on it
667 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
668 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
669
670 # Build
671 # -----
672
673 # These hashes are needed for some ECDSA signature tests.
Elena Uziunaiteffce45c2024-09-12 14:58:52 +0100674 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
Minos Galanakis471b34c2024-07-26 15:39:24 +0100675 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
676
677 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
678
679 helper_libtestdriver1_make_main "$loc_accel_list"
680
681 # Make sure this was not re-enabled by accident (additive config)
682 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
683
684 # Run the tests
685 # -------------
686
687 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
688 make test
689}
690
691component_test_psa_crypto_config_accel_ecdh () {
692 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
693
694 # Algorithms and key types to accelerate
695 loc_accel_list="ALG_ECDH \
696 $(helper_get_psa_key_type_list "ECC") \
697 $(helper_get_psa_curve_list)"
698
699 # Configure
700 # ---------
701
702 # Start from default config (no USE_PSA)
703 helper_libtestdriver1_adjust_config "default"
704
705 # Disable the module that's accelerated
706 scripts/config.py unset MBEDTLS_ECDH_C
707
708 # Disable things that depend on it
709 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
710 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
711 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
712 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
713 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
714
715 # Build
716 # -----
717
718 helper_libtestdriver1_make_drivers "$loc_accel_list"
719
720 helper_libtestdriver1_make_main "$loc_accel_list"
721
722 # Make sure this was not re-enabled by accident (additive config)
723 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
724
725 # Run the tests
726 # -------------
727
728 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
729 make test
730}
731
732component_test_psa_crypto_config_accel_ffdh () {
733 msg "build: full with accelerated FFDH"
734
735 # Algorithms and key types to accelerate
736 loc_accel_list="ALG_FFDH \
737 $(helper_get_psa_key_type_list "DH") \
738 $(helper_get_psa_dh_group_list)"
739
740 # Configure
741 # ---------
742
743 # start with full (USE_PSA and TLS 1.3)
744 helper_libtestdriver1_adjust_config "full"
745
746 # Disable the module that's accelerated
747 scripts/config.py unset MBEDTLS_DHM_C
748
749 # Disable things that depend on it
750 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
751 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
752
753 # Build
754 # -----
755
756 helper_libtestdriver1_make_drivers "$loc_accel_list"
757
758 helper_libtestdriver1_make_main "$loc_accel_list"
759
760 # Make sure this was not re-enabled by accident (additive config)
761 not grep mbedtls_dhm_ ${BUILTIN_SRC_PATH}/dhm.o
762
763 # Run the tests
764 # -------------
765
766 msg "test: full with accelerated FFDH"
767 make test
768
769 msg "ssl-opt: full with accelerated FFDH alg"
770 tests/ssl-opt.sh -f "ffdh"
771}
772
773component_test_psa_crypto_config_reference_ffdh () {
774 msg "build: full with non-accelerated FFDH"
775
776 # Start with full (USE_PSA and TLS 1.3)
777 helper_libtestdriver1_adjust_config "full"
778
779 # Disable things that are not supported
780 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
781 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
782 make
783
784 msg "test suites: full with non-accelerated FFDH alg"
785 make test
786
787 msg "ssl-opt: full with non-accelerated FFDH alg"
788 tests/ssl-opt.sh -f "ffdh"
789}
790
Minos Galanakisf78447f2024-07-26 20:49:51 +0100791component_test_psa_crypto_config_accel_pake () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100792 msg "build: full with accelerated PAKE"
793
794 loc_accel_list="ALG_JPAKE \
795 $(helper_get_psa_key_type_list "ECC") \
796 $(helper_get_psa_curve_list)"
797
798 # Configure
799 # ---------
800
801 helper_libtestdriver1_adjust_config "full"
802
803 # Make built-in fallback not available
804 scripts/config.py unset MBEDTLS_ECJPAKE_C
805 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
806
807 # Build
808 # -----
809
810 helper_libtestdriver1_make_drivers "$loc_accel_list"
811
812 helper_libtestdriver1_make_main "$loc_accel_list"
813
814 # Make sure this was not re-enabled by accident (additive config)
815 not grep mbedtls_ecjpake_init ${BUILTIN_SRC_PATH}/ecjpake.o
816
817 # Run the tests
818 # -------------
819
820 msg "test: full with accelerated PAKE"
821 make test
822}
823
824component_test_psa_crypto_config_accel_ecc_some_key_types () {
825 msg "build: full with accelerated EC algs and some key types"
826
827 # Algorithms and key types to accelerate
828 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
829 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
830 ALG_ECDH \
831 ALG_JPAKE \
832 KEY_TYPE_ECC_PUBLIC_KEY \
833 KEY_TYPE_ECC_KEY_PAIR_BASIC \
834 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
835 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
836 $(helper_get_psa_curve_list)"
837
838 # Configure
839 # ---------
840
841 # start with config full for maximum coverage (also enables USE_PSA)
842 helper_libtestdriver1_adjust_config "full"
843
844 # Disable modules that are accelerated - some will be re-enabled
845 scripts/config.py unset MBEDTLS_ECDSA_C
846 scripts/config.py unset MBEDTLS_ECDH_C
847 scripts/config.py unset MBEDTLS_ECJPAKE_C
848 scripts/config.py unset MBEDTLS_ECP_C
849
850 # Disable all curves - those that aren't accelerated should be re-enabled
851 helper_disable_builtin_curves
852
853 # Restartable feature is not yet supported by PSA. Once it will in
854 # the future, the following line could be removed (see issues
855 # 6061, 6332 and following ones)
856 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
857
858 # this is not supported by the driver API yet
859 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
860
861 # Build
862 # -----
863
864 # These hashes are needed for some ECDSA signature tests.
865 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
866 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
867 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
868
869 helper_libtestdriver1_make_main "$loc_accel_list"
870
871 # ECP should be re-enabled but not the others
872 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
873 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
874 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
875 grep mbedtls_ecp ${BUILTIN_SRC_PATH}/ecp.o
876
877 # Run the tests
878 # -------------
879
880 msg "test suites: full with accelerated EC algs and some key types"
881 make test
882}
883
884# Run tests with only (non-)Weierstrass accelerated
885# Common code used in:
886# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
887# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100888common_test_psa_crypto_config_accel_ecc_some_curves () {
889 weierstrass=$1
890 if [ $weierstrass -eq 1 ]; then
891 desc="Weierstrass"
892 else
893 desc="non-Weierstrass"
894 fi
895
896 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
897
898 # Note: Curves are handled in a special way by the libtestdriver machinery,
899 # so we only want to include them in the accel list when building the main
900 # libraries, hence the use of a separate variable.
901 # Note: the following loop is a modified version of
902 # helper_get_psa_curve_list that only keeps Weierstrass families.
903 loc_weierstrass_list=""
904 loc_non_weierstrass_list=""
905 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
906 case $item in
907 ECC_BRAINPOOL*|ECC_SECP*)
908 loc_weierstrass_list="$loc_weierstrass_list $item"
909 ;;
910 *)
911 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
912 ;;
913 esac
914 done
915 if [ $weierstrass -eq 1 ]; then
916 loc_curve_list=$loc_weierstrass_list
917 else
918 loc_curve_list=$loc_non_weierstrass_list
919 fi
920
921 # Algorithms and key types to accelerate
922 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
923 ALG_ECDH \
924 ALG_JPAKE \
925 $(helper_get_psa_key_type_list "ECC") \
926 $loc_curve_list"
927
928 # Configure
929 # ---------
930
931 # Start with config crypto_full and remove PK_C:
932 # that's what's supported now, see docs/driver-only-builds.md.
933 helper_libtestdriver1_adjust_config "crypto_full"
934 scripts/config.py unset MBEDTLS_PK_C
935 scripts/config.py unset MBEDTLS_PK_PARSE_C
936 scripts/config.py unset MBEDTLS_PK_WRITE_C
937
938 # Disable modules that are accelerated - some will be re-enabled
939 scripts/config.py unset MBEDTLS_ECDSA_C
940 scripts/config.py unset MBEDTLS_ECDH_C
941 scripts/config.py unset MBEDTLS_ECJPAKE_C
942 scripts/config.py unset MBEDTLS_ECP_C
943
944 # Disable all curves - those that aren't accelerated should be re-enabled
945 helper_disable_builtin_curves
946
947 # Restartable feature is not yet supported by PSA. Once it will in
948 # the future, the following line could be removed (see issues
949 # 6061, 6332 and following ones)
950 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
951
952 # this is not supported by the driver API yet
953 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
954
955 # Build
956 # -----
957
958 # These hashes are needed for some ECDSA signature tests.
959 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
960 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
961 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
962
963 helper_libtestdriver1_make_main "$loc_accel_list"
964
965 # We expect ECDH to be re-enabled for the missing curves
966 grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
967 # We expect ECP to be re-enabled, however the parts specific to the
968 # families of curves that are accelerated should be ommited.
969 # - functions with mxz in the name are specific to Montgomery curves
970 # - ecp_muladd is specific to Weierstrass curves
971 ##nm ${BUILTIN_SRC_PATH}/ecp.o | tee ecp.syms
972 if [ $weierstrass -eq 1 ]; then
973 not grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
974 grep mxz ${BUILTIN_SRC_PATH}/ecp.o
975 else
976 grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
977 not grep mxz ${BUILTIN_SRC_PATH}/ecp.o
978 fi
979 # We expect ECDSA and ECJPAKE to be re-enabled only when
980 # Weierstrass curves are not accelerated
981 if [ $weierstrass -eq 1 ]; then
982 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
983 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
984 else
985 grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
986 grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
987 fi
988
989 # Run the tests
990 # -------------
991
992 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
993 make test
994}
995
996component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
997 common_test_psa_crypto_config_accel_ecc_some_curves 1
998}
999
1000component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
1001 common_test_psa_crypto_config_accel_ecc_some_curves 0
1002}
1003
1004# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
1005# ECDH, ECDSA) with and without drivers.
1006# The input parameter is a boolean value which indicates:
1007# - 0 keep built-in EC algs,
1008# - 1 exclude built-in EC algs (driver only).
1009#
1010# This is used by the two following components to ensure they always use the
1011# same config, except for the use of driver or built-in EC algorithms:
1012# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
1013# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
1014# This supports comparing their test coverage with analyze_outcomes.py.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001015config_psa_crypto_config_ecp_light_only () {
1016 driver_only="$1"
1017 # start with config full for maximum coverage (also enables USE_PSA)
1018 helper_libtestdriver1_adjust_config "full"
1019 if [ "$driver_only" -eq 1 ]; then
1020 # Disable modules that are accelerated
1021 scripts/config.py unset MBEDTLS_ECDSA_C
1022 scripts/config.py unset MBEDTLS_ECDH_C
1023 scripts/config.py unset MBEDTLS_ECJPAKE_C
1024 scripts/config.py unset MBEDTLS_ECP_C
1025 fi
1026
1027 # Restartable feature is not yet supported by PSA. Once it will in
1028 # the future, the following line could be removed (see issues
1029 # 6061, 6332 and following ones)
1030 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1031}
1032
1033# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +01001034component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
1035 msg "build: full with accelerated EC algs"
1036
1037 # Algorithms and key types to accelerate
1038 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1039 ALG_ECDH \
1040 ALG_JPAKE \
1041 $(helper_get_psa_key_type_list "ECC") \
1042 $(helper_get_psa_curve_list)"
1043
1044 # Configure
1045 # ---------
1046
1047 # Use the same config as reference, only without built-in EC algs
1048 config_psa_crypto_config_ecp_light_only 1
1049
1050 # Do not disable builtin curves because that support is required for:
1051 # - MBEDTLS_PK_PARSE_EC_EXTENDED
1052 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
1053
1054 # Build
1055 # -----
1056
1057 # These hashes are needed for some ECDSA signature tests.
1058 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1059 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1060 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1061
1062 helper_libtestdriver1_make_main "$loc_accel_list"
1063
1064 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1065 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1066 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1067 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1068 not grep mbedtls_ecp_mul ${BUILTIN_SRC_PATH}/ecp.o
1069
1070 # Run the tests
1071 # -------------
1072
1073 msg "test suites: full with accelerated EC algs"
1074 make test
1075
1076 msg "ssl-opt: full with accelerated EC algs"
1077 tests/ssl-opt.sh
1078}
1079
1080# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +01001081component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
1082 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated EC algs"
1083
1084 config_psa_crypto_config_ecp_light_only 0
1085
1086 make
1087
1088 msg "test suites: full with non-accelerated EC algs"
1089 make test
1090
1091 msg "ssl-opt: full with non-accelerated EC algs"
1092 tests/ssl-opt.sh
1093}
1094
1095# This helper function is used by:
1096# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
1097# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
1098# to ensure that both tests use the same underlying configuration when testing
1099# driver's coverage with analyze_outcomes.py.
1100#
1101# This functions accepts 1 boolean parameter as follows:
1102# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
1103# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
1104# - 0: include built-in implementation of EC algorithms.
1105#
1106# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
1107# on the ECP module.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001108config_psa_crypto_no_ecp_at_all () {
1109 driver_only="$1"
1110 # start with full config for maximum coverage (also enables USE_PSA)
1111 helper_libtestdriver1_adjust_config "full"
1112
1113 if [ "$driver_only" -eq 1 ]; then
1114 # Disable modules that are accelerated
1115 scripts/config.py unset MBEDTLS_ECDSA_C
1116 scripts/config.py unset MBEDTLS_ECDH_C
1117 scripts/config.py unset MBEDTLS_ECJPAKE_C
1118 # Disable ECP module (entirely)
1119 scripts/config.py unset MBEDTLS_ECP_C
1120 fi
1121
1122 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1123 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1124 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1125 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1126
1127 # Restartable feature is not yet supported by PSA. Once it will in
1128 # the future, the following line could be removed (see issues
1129 # 6061, 6332 and following ones)
1130 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1131}
1132
1133# Build and test a configuration where driver accelerates all EC algs while
1134# all support and dependencies from ECP and ECP_LIGHT are removed on the library
1135# side.
1136#
1137# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001138component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
1139 msg "build: full + accelerated EC algs - ECP"
1140
1141 # Algorithms and key types to accelerate
1142 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1143 ALG_ECDH \
1144 ALG_JPAKE \
1145 $(helper_get_psa_key_type_list "ECC") \
1146 $(helper_get_psa_curve_list)"
1147
1148 # Configure
1149 # ---------
1150
1151 # Set common configurations between library's and driver's builds
1152 config_psa_crypto_no_ecp_at_all 1
1153 # Disable all the builtin curves. All the required algs are accelerated.
1154 helper_disable_builtin_curves
1155
1156 # Build
1157 # -----
1158
1159 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1160 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1161 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1162 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1163
1164 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1165
1166 helper_libtestdriver1_make_main "$loc_accel_list"
1167
1168 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1169 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1170 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1171 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1172 # Also ensure that ECP module was not re-enabled
1173 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1174
1175 # Run the tests
1176 # -------------
1177
1178 msg "test: full + accelerated EC algs - ECP"
1179 make test
1180
1181 msg "ssl-opt: full + accelerated EC algs - ECP"
1182 tests/ssl-opt.sh
1183}
1184
1185# Reference function used for driver's coverage analysis in analyze_outcomes.py
1186# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
1187# Keep in sync with its accelerated counterpart.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001188component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
1189 msg "build: full + non accelerated EC algs"
1190
1191 config_psa_crypto_no_ecp_at_all 0
1192
1193 make
1194
1195 msg "test: full + non accelerated EC algs"
1196 make test
1197
1198 msg "ssl-opt: full + non accelerated EC algs"
1199 tests/ssl-opt.sh
1200}
1201
1202# This is a common configuration helper used directly from:
1203# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1204# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1205# and indirectly from:
1206# - component_test_psa_crypto_config_accel_ecc_no_bignum
1207# - accelerate all EC algs, disable RSA and FFDH
1208# - component_test_psa_crypto_config_reference_ecc_no_bignum
1209# - this is the reference component of the above
1210# - it still disables RSA and FFDH, but it uses builtin EC algs
1211# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1212# - accelerate all EC and FFDH algs, disable only RSA
1213# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1214# - this is the reference component of the above
1215# - it still disables RSA, but it uses builtin EC and FFDH algs
1216#
1217# This function accepts 2 parameters:
1218# $1: a boolean value which states if we are testing an accelerated scenario
1219# or not.
1220# $2: a string value which states which components are tested. Allowed values
1221# are "ECC" or "ECC_DH".
Minos Galanakisf78447f2024-07-26 20:49:51 +01001222config_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001223 driver_only="$1"
1224 test_target="$2"
1225 # start with full config for maximum coverage (also enables USE_PSA)
1226 helper_libtestdriver1_adjust_config "full"
1227
1228 if [ "$driver_only" -eq 1 ]; then
1229 # Disable modules that are accelerated
1230 scripts/config.py unset MBEDTLS_ECDSA_C
1231 scripts/config.py unset MBEDTLS_ECDH_C
1232 scripts/config.py unset MBEDTLS_ECJPAKE_C
1233 # Disable ECP module (entirely)
1234 scripts/config.py unset MBEDTLS_ECP_C
1235 # Also disable bignum
1236 scripts/config.py unset MBEDTLS_BIGNUM_C
1237 fi
1238
1239 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1240 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1241 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1242 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1243
1244 # RSA support is intentionally disabled on this test because RSA_C depends
1245 # on BIGNUM_C.
1246 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
1247 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
1248 scripts/config.py unset MBEDTLS_RSA_C
1249 scripts/config.py unset MBEDTLS_PKCS1_V15
1250 scripts/config.py unset MBEDTLS_PKCS1_V21
1251 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1252 # Also disable key exchanges that depend on RSA
1253 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1254 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1255 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1256 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1257 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1258
1259 if [ "$test_target" = "ECC" ]; then
1260 # When testing ECC only, we disable FFDH support, both from builtin and
1261 # PSA sides, and also disable the key exchanges that depend on DHM.
1262 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_FFDH
1263 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
1264 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
1265 scripts/config.py unset MBEDTLS_DHM_C
1266 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1267 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1268 else
1269 # When testing ECC and DH instead, we disable DHM and depending key
1270 # exchanges only in the accelerated build
1271 if [ "$driver_only" -eq 1 ]; then
1272 scripts/config.py unset MBEDTLS_DHM_C
1273 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1274 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1275 fi
1276 fi
1277
1278 # Restartable feature is not yet supported by PSA. Once it will in
1279 # the future, the following line could be removed (see issues
1280 # 6061, 6332 and following ones)
1281 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1282}
1283
1284# Common helper used by:
1285# - component_test_psa_crypto_config_accel_ecc_no_bignum
1286# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1287#
1288# The goal is to build and test accelerating either:
1289# - ECC only or
1290# - both ECC and FFDH
1291#
1292# It is meant to be used in conjunction with
1293# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
1294# coverage analysis in the "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001295common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1296 test_target="$1"
1297
1298 # This is an internal helper to simplify text message handling
1299 if [ "$test_target" = "ECC_DH" ]; then
1300 accel_text="ECC/FFDH"
1301 removed_text="ECP - DH"
1302 else
1303 accel_text="ECC"
1304 removed_text="ECP"
1305 fi
1306
1307 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1308
1309 # By default we accelerate all EC keys/algs
1310 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1311 ALG_ECDH \
1312 ALG_JPAKE \
1313 $(helper_get_psa_key_type_list "ECC") \
1314 $(helper_get_psa_curve_list)"
1315 # Optionally we can also add DH to the list of accelerated items
1316 if [ "$test_target" = "ECC_DH" ]; then
1317 loc_accel_list="$loc_accel_list \
1318 ALG_FFDH \
1319 $(helper_get_psa_key_type_list "DH") \
1320 $(helper_get_psa_dh_group_list)"
1321 fi
1322
1323 # Configure
1324 # ---------
1325
1326 # Set common configurations between library's and driver's builds
1327 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
1328 # Disable all the builtin curves. All the required algs are accelerated.
1329 helper_disable_builtin_curves
1330
1331 # Build
1332 # -----
1333
1334 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1335 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1336 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1337 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1338
1339 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1340
1341 helper_libtestdriver1_make_main "$loc_accel_list"
1342
1343 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1344 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1345 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1346 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1347 # Also ensure that ECP, RSA, [DHM] or BIGNUM modules were not re-enabled
1348 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1349 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1350 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1351 not grep mbedtls_dhm_ ${BUILTIN_SRC_PATH}/dhm.o
1352
1353 # Run the tests
1354 # -------------
1355
1356 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - DHM - BIGNUM"
1357
1358 make test
1359
1360 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1361 tests/ssl-opt.sh
1362}
1363
1364# Common helper used by:
1365# - component_test_psa_crypto_config_reference_ecc_no_bignum
1366# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1367#
1368# The goal is to build and test a reference scenario (i.e. with builtin
1369# components) compared to the ones used in
1370# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
1371#
1372# It is meant to be used in conjunction with
1373# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
1374# coverage analysis in "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001375common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1376 test_target="$1"
1377
1378 # This is an internal helper to simplify text message handling
1379 if [ "$test_target" = "ECC_DH" ]; then
1380 accel_text="ECC/FFDH"
1381 else
1382 accel_text="ECC"
1383 fi
1384
1385 msg "build: full + non accelerated $accel_text algs + USE_PSA"
1386
1387 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
1388
1389 make
1390
1391 msg "test suites: full + non accelerated EC algs + USE_PSA"
1392 make test
1393
1394 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
1395 tests/ssl-opt.sh
1396}
1397
1398component_test_psa_crypto_config_accel_ecc_no_bignum () {
1399 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
1400}
1401
1402component_test_psa_crypto_config_reference_ecc_no_bignum () {
1403 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
1404}
1405
1406component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1407 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
1408}
1409
1410component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1411 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
1412}
1413
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001414component_test_tfm_config_as_is () {
1415 msg "build: configs/config-tfm.h"
1416 cp configs/config-tfm.h "$CONFIG_H"
1417 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1418 make
1419
1420 msg "test: configs/config-tfm.h - unit tests"
1421 make test
1422}
1423
Minos Galanakis471b34c2024-07-26 15:39:24 +01001424# Helper for setting common configurations between:
1425# - component_test_tfm_config_p256m_driver_accel_ec()
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001426# - component_test_tfm_config_no_p256m()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001427common_tfm_config () {
1428 # Enable TF-M config
1429 cp configs/config-tfm.h "$CONFIG_H"
1430 echo "#undef MBEDTLS_PSA_CRYPTO_CONFIG_FILE" >> "$CONFIG_H"
1431 cp configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
1432
1433 # Other config adjustment to make the tests pass.
1434 # This should probably be adopted upstream.
1435 #
1436 # - USE_PSA_CRYPTO for PK_HAVE_ECC_KEYS
1437 echo "#define MBEDTLS_USE_PSA_CRYPTO" >> "$CONFIG_H"
1438
1439 # Config adjustment for better test coverage in our environment.
1440 # This is not needed just to build and pass tests.
1441 #
1442 # Enable filesystem I/O for the benefit of PK parse/write tests.
1443 echo "#define MBEDTLS_FS_IO" >> "$CONFIG_H"
1444}
1445
1446# Keep this in sync with component_test_tfm_config() as they are both meant
1447# to be used in analyze_outcomes.py for driver's coverage analysis.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001448component_test_tfm_config_p256m_driver_accel_ec () {
1449 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1450
1451 common_tfm_config
1452
1453 # Build crypto library
1454 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
1455
1456 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1457 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1458 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1459 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1460 # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
1461 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1462 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1463 not grep mbedtls_dhm_ ${BUILTIN_SRC_PATH}/dhm.o
1464 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1465 # Check that p256m was built
1466 grep -q p256_ecdsa_ library/libmbedcrypto.a
1467
1468 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1469 # files, so we want to ensure that it has not be re-enabled accidentally.
1470 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1471
1472 # Run the tests
1473 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1474 make test
1475}
1476
1477# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1478# they are both meant to be used in analyze_outcomes.py for driver's coverage
1479# analysis.
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001480component_test_tfm_config_no_p256m () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001481 common_tfm_config
1482
1483 # Disable P256M driver, which is on by default, so that analyze_outcomes
1484 # can compare this test with test_tfm_config_p256m_driver_accel_ec
1485 echo "#undef MBEDTLS_PSA_P256M_DRIVER_ENABLED" >> "$CONFIG_H"
1486
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001487 msg "build: TF-M config without p256m"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001488 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' tests
1489
1490 # Check that p256m was not built
1491 not grep p256_ecdsa_ library/libmbedcrypto.a
1492
1493 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1494 # files, so we want to ensure that it has not be re-enabled accidentally.
1495 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1496
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001497 msg "test: TF-M config without p256m"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001498 make test
1499}
1500
Minos Galanakis471b34c2024-07-26 15:39:24 +01001501# This is an helper used by:
1502# - component_test_psa_ecc_key_pair_no_derive
1503# - component_test_psa_ecc_key_pair_no_generate
1504# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1505# enabled, but one. Input arguments are as follows:
1506# - $1 is the key type under test, i.e. ECC/RSA/DH
1507# - $2 is the key option to be unset (i.e. generate, derive, etc)
Minos Galanakisf78447f2024-07-26 20:49:51 +01001508build_and_test_psa_want_key_pair_partial () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001509 key_type=$1
1510 unset_option=$2
1511 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1512
1513 msg "build: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
1514 scripts/config.py full
1515 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1516 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1517
1518 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1519 # crypto_config.h so we just disable the one we don't want.
1520 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
1521
1522 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1523
1524 msg "test: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
1525 make test
1526}
1527
Minos Galanakisf78447f2024-07-26 20:49:51 +01001528component_test_psa_ecc_key_pair_no_derive () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001529 build_and_test_psa_want_key_pair_partial "ECC" "DERIVE"
1530}
1531
Minos Galanakisf78447f2024-07-26 20:49:51 +01001532component_test_psa_ecc_key_pair_no_generate () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001533 build_and_test_psa_want_key_pair_partial "ECC" "GENERATE"
1534}
1535
1536config_psa_crypto_accel_rsa () {
1537 driver_only=$1
1538
1539 # Start from crypto_full config (no X.509, no TLS)
1540 helper_libtestdriver1_adjust_config "crypto_full"
1541
1542 if [ "$driver_only" -eq 1 ]; then
1543 # Remove RSA support and its dependencies
1544 scripts/config.py unset MBEDTLS_RSA_C
1545 scripts/config.py unset MBEDTLS_PKCS1_V15
1546 scripts/config.py unset MBEDTLS_PKCS1_V21
1547
1548 # We need PEM parsing in the test library as well to support the import
1549 # of PEM encoded RSA keys.
1550 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1551 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
1552 fi
1553}
1554
1555component_test_psa_crypto_config_accel_rsa_crypto () {
1556 msg "build: crypto_full with accelerated RSA"
1557
1558 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1559 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1560 KEY_TYPE_RSA_PUBLIC_KEY \
1561 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1562 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1563 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1564 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1565
1566 # Configure
1567 # ---------
1568
1569 config_psa_crypto_accel_rsa 1
1570
1571 # Build
1572 # -----
1573
1574 # These hashes are needed for unit tests.
1575 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1576 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1577 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1578
1579 helper_libtestdriver1_make_main "$loc_accel_list"
1580
1581 # Make sure this was not re-enabled by accident (additive config)
1582 not grep mbedtls_rsa ${BUILTIN_SRC_PATH}/rsa.o
1583
1584 # Run the tests
1585 # -------------
1586
1587 msg "test: crypto_full with accelerated RSA"
1588 make test
1589}
1590
1591component_test_psa_crypto_config_reference_rsa_crypto () {
1592 msg "build: crypto_full with non-accelerated RSA"
1593
1594 # Configure
1595 # ---------
1596 config_psa_crypto_accel_rsa 0
1597
1598 # Build
1599 # -----
1600 make
1601
1602 # Run the tests
1603 # -------------
1604 msg "test: crypto_full with non-accelerated RSA"
1605 make test
1606}
1607
1608# This is a temporary test to verify that full RSA support is present even when
1609# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001610component_test_new_psa_want_key_pair_symbol () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001611 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1612
1613 # Create a temporary output file unless there is already one set
1614 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1615 REMOVE_OUTCOME_ON_EXIT="no"
1616 else
1617 REMOVE_OUTCOME_ON_EXIT="yes"
1618 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1619 export MBEDTLS_TEST_OUTCOME_FILE
1620 fi
1621
1622 # Start from crypto configuration
1623 scripts/config.py crypto
1624
1625 # Remove RSA support and its dependencies
1626 scripts/config.py unset MBEDTLS_PKCS1_V15
1627 scripts/config.py unset MBEDTLS_PKCS1_V21
1628 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1629 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1630 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1631 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1632 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1633 scripts/config.py unset MBEDTLS_RSA_C
1634 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1635
1636 # Enable PSA support
1637 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1638
1639 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
1640 # that proper translations is done in crypto_legacy.h.
1641 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
1642 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
1643 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
1644
1645 make
1646
1647 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1648 make test
1649
1650 # Parse only 1 relevant line from the outcome file, i.e. a test which is
1651 # performing RSA signature.
1652 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
1653 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
1654
1655 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
1656 rm $MBEDTLS_TEST_OUTCOME_FILE
1657 fi
1658}
1659
1660component_test_psa_crypto_config_accel_hash () {
1661 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
1662
1663 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1664 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1665 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1666
1667 # Configure
1668 # ---------
1669
1670 # Start from default config (no USE_PSA)
1671 helper_libtestdriver1_adjust_config "default"
1672
1673 # Disable the things that are being accelerated
1674 scripts/config.py unset MBEDTLS_MD5_C
1675 scripts/config.py unset MBEDTLS_RIPEMD160_C
1676 scripts/config.py unset MBEDTLS_SHA1_C
1677 scripts/config.py unset MBEDTLS_SHA224_C
1678 scripts/config.py unset MBEDTLS_SHA256_C
1679 scripts/config.py unset MBEDTLS_SHA384_C
1680 scripts/config.py unset MBEDTLS_SHA512_C
1681 scripts/config.py unset MBEDTLS_SHA3_C
1682
1683 # Build
1684 # -----
1685
1686 helper_libtestdriver1_make_drivers "$loc_accel_list"
1687
1688 helper_libtestdriver1_make_main "$loc_accel_list"
1689
1690 # There's a risk of something getting re-enabled via config_psa.h;
1691 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1692 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1693 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1694 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1695 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1696 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1697
1698 # Run the tests
1699 # -------------
1700
1701 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
1702 make test
1703}
1704
1705# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001706config_psa_crypto_hash_use_psa () {
1707 driver_only="$1"
1708 # start with config full for maximum coverage (also enables USE_PSA)
1709 helper_libtestdriver1_adjust_config "full"
1710 if [ "$driver_only" -eq 1 ]; then
1711 # disable the built-in implementation of hashes
1712 scripts/config.py unset MBEDTLS_MD5_C
1713 scripts/config.py unset MBEDTLS_RIPEMD160_C
1714 scripts/config.py unset MBEDTLS_SHA1_C
1715 scripts/config.py unset MBEDTLS_SHA224_C
1716 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
1717 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
1718 scripts/config.py unset MBEDTLS_SHA384_C
1719 scripts/config.py unset MBEDTLS_SHA512_C
1720 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
1721 scripts/config.py unset MBEDTLS_SHA3_C
1722 fi
1723}
1724
1725# Note that component_test_psa_crypto_config_reference_hash_use_psa
1726# is related to this component and both components need to be kept in sync.
1727# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001728component_test_psa_crypto_config_accel_hash_use_psa () {
1729 msg "test: full with accelerated hashes"
1730
1731 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1732 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1733 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1734
1735 # Configure
1736 # ---------
1737
1738 config_psa_crypto_hash_use_psa 1
1739
1740 # Build
1741 # -----
1742
1743 helper_libtestdriver1_make_drivers "$loc_accel_list"
1744
1745 helper_libtestdriver1_make_main "$loc_accel_list"
1746
1747 # There's a risk of something getting re-enabled via config_psa.h;
1748 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1749 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1750 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1751 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1752 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1753 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1754
1755 # Run the tests
1756 # -------------
1757
1758 msg "test: full with accelerated hashes"
1759 make test
1760
1761 # This is mostly useful so that we can later compare outcome files with
1762 # the reference config in analyze_outcomes.py, to check that the
1763 # dependency declarations in ssl-opt.sh and in TLS code are correct.
1764 msg "test: ssl-opt.sh, full with accelerated hashes"
1765 tests/ssl-opt.sh
1766
1767 # This is to make sure all ciphersuites are exercised, but we don't need
1768 # interop testing (besides, we already got some from ssl-opt.sh).
1769 msg "test: compat.sh, full with accelerated hashes"
1770 tests/compat.sh -p mbedTLS -V YES
1771}
1772
1773# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
1774# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
1775# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
1776# Both components need to be kept in sync.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001777component_test_psa_crypto_config_reference_hash_use_psa () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001778 msg "test: full without accelerated hashes"
1779
1780 config_psa_crypto_hash_use_psa 0
1781
1782 make
1783
1784 msg "test: full without accelerated hashes"
1785 make test
1786
1787 msg "test: ssl-opt.sh, full without accelerated hashes"
1788 tests/ssl-opt.sh
1789}
1790
1791# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001792config_psa_crypto_hmac_use_psa () {
1793 driver_only="$1"
1794 # start with config full for maximum coverage (also enables USE_PSA)
1795 helper_libtestdriver1_adjust_config "full"
1796
1797 if [ "$driver_only" -eq 1 ]; then
1798 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
1799 # is still enabled though (for ENTROPY_C among others).
1800 scripts/config.py unset MBEDTLS_MD_C
1801 # Disable also the builtin hashes since they are supported by the driver
1802 # and MD module is able to perform PSA dispathing.
1803 scripts/config.py unset-all MBEDTLS_SHA
1804 scripts/config.py unset MBEDTLS_MD5_C
1805 scripts/config.py unset MBEDTLS_RIPEMD160_C
1806 fi
1807
1808 # Direct dependencies of MD_C. We disable them also in the reference
1809 # component to work with the same set of features.
1810 scripts/config.py unset MBEDTLS_PKCS7_C
1811 scripts/config.py unset MBEDTLS_PKCS5_C
1812 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1813 scripts/config.py unset MBEDTLS_HKDF_C
1814 # Dependencies of HMAC_DRBG
1815 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
1816 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
1817}
1818
Minos Galanakisf78447f2024-07-26 20:49:51 +01001819component_test_psa_crypto_config_accel_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001820 msg "test: full with accelerated hmac"
1821
1822 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
1823 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1824 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1825 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1826
1827 # Configure
1828 # ---------
1829
1830 config_psa_crypto_hmac_use_psa 1
1831
1832 # Build
1833 # -----
1834
1835 helper_libtestdriver1_make_drivers "$loc_accel_list"
1836
1837 helper_libtestdriver1_make_main "$loc_accel_list"
1838
1839 # Ensure that built-in support for HMAC is disabled.
1840 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
1841
1842 # Run the tests
1843 # -------------
1844
1845 msg "test: full with accelerated hmac"
1846 make test
1847}
1848
Minos Galanakisf78447f2024-07-26 20:49:51 +01001849component_test_psa_crypto_config_reference_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001850 msg "test: full without accelerated hmac"
1851
1852 config_psa_crypto_hmac_use_psa 0
1853
1854 make
1855
1856 msg "test: full without accelerated hmac"
1857 make test
1858}
1859
1860component_test_psa_crypto_config_accel_des () {
1861 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
1862
1863 # Albeit this components aims at accelerating DES which should only support
1864 # CBC and ECB modes, we need to accelerate more than that otherwise DES_C
1865 # would automatically be re-enabled by "config_adjust_legacy_from_psa.c"
1866 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 \
1867 ALG_CTR ALG_CFB ALG_OFB ALG_XTS ALG_CMAC \
1868 KEY_TYPE_DES"
1869
1870 # Note: we cannot accelerate all ciphers' key types otherwise we would also
1871 # have to either disable CCM/GCM or accelerate them, but that's out of scope
1872 # of this component. This limitation will be addressed by #8598.
1873
1874 # Configure
1875 # ---------
1876
1877 # Start from the full config
1878 helper_libtestdriver1_adjust_config "full"
1879
1880 # Disable the things that are being accelerated
1881 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1882 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
1883 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
1884 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
1885 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
1886 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
1887 scripts/config.py unset MBEDTLS_DES_C
1888 scripts/config.py unset MBEDTLS_CMAC_C
1889
1890 # Build
1891 # -----
1892
1893 helper_libtestdriver1_make_drivers "$loc_accel_list"
1894
1895 helper_libtestdriver1_make_main "$loc_accel_list"
1896
1897 # Make sure this was not re-enabled by accident (additive config)
1898 not grep mbedtls_des* ${BUILTIN_SRC_PATH}/des.o
1899
1900 # Run the tests
1901 # -------------
1902
1903 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
1904 make test
1905}
1906
1907component_test_psa_crypto_config_accel_aead () {
1908 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
1909
1910 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
1911 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1912
1913 # Configure
1914 # ---------
1915
1916 # Start from full config
1917 helper_libtestdriver1_adjust_config "full"
1918
1919 # Disable things that are being accelerated
1920 scripts/config.py unset MBEDTLS_GCM_C
1921 scripts/config.py unset MBEDTLS_CCM_C
1922 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1923
1924 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
1925 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1926
1927 # Build
1928 # -----
1929
1930 helper_libtestdriver1_make_drivers "$loc_accel_list"
1931
1932 helper_libtestdriver1_make_main "$loc_accel_list"
1933
1934 # Make sure this was not re-enabled by accident (additive config)
1935 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1936 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1937 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1938
1939 # Run the tests
1940 # -------------
1941
1942 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
1943 make test
1944}
1945
1946# This is a common configuration function used in:
1947# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1948# - component_test_psa_crypto_config_reference_cipher_aead_cmac
Minos Galanakisf78447f2024-07-26 20:49:51 +01001949common_psa_crypto_config_accel_cipher_aead_cmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001950 # Start from the full config
1951 helper_libtestdriver1_adjust_config "full"
1952
1953 scripts/config.py unset MBEDTLS_NIST_KW_C
1954}
1955
1956# The 2 following test components, i.e.
1957# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1958# - component_test_psa_crypto_config_reference_cipher_aead_cmac
1959# are meant to be used together in analyze_outcomes.py script in order to test
1960# driver's coverage for ciphers and AEADs.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001961component_test_psa_crypto_config_accel_cipher_aead_cmac () {
1962 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
1963
1964 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
1965 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
1966 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
1967 KEY_TYPE_DES KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
1968
1969 # Configure
1970 # ---------
1971
1972 common_psa_crypto_config_accel_cipher_aead_cmac
1973
1974 # Disable the things that are being accelerated
1975 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1976 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
1977 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
1978 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
1979 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
1980 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
1981 scripts/config.py unset MBEDTLS_GCM_C
1982 scripts/config.py unset MBEDTLS_CCM_C
1983 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1984 scripts/config.py unset MBEDTLS_CMAC_C
1985 scripts/config.py unset MBEDTLS_DES_C
1986 scripts/config.py unset MBEDTLS_AES_C
1987 scripts/config.py unset MBEDTLS_ARIA_C
1988 scripts/config.py unset MBEDTLS_CHACHA20_C
1989 scripts/config.py unset MBEDTLS_CAMELLIA_C
1990
1991 # Disable CIPHER_C entirely as all ciphers/AEADs are accelerated and PSA
1992 # does not depend on it.
1993 scripts/config.py unset MBEDTLS_CIPHER_C
1994
1995 # Build
1996 # -----
1997
1998 helper_libtestdriver1_make_drivers "$loc_accel_list"
1999
2000 helper_libtestdriver1_make_main "$loc_accel_list"
2001
2002 # Make sure this was not re-enabled by accident (additive config)
2003 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
2004 not grep mbedtls_des ${BUILTIN_SRC_PATH}/des.o
2005 not grep mbedtls_aes ${BUILTIN_SRC_PATH}/aes.o
2006 not grep mbedtls_aria ${BUILTIN_SRC_PATH}/aria.o
2007 not grep mbedtls_camellia ${BUILTIN_SRC_PATH}/camellia.o
2008 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
2009 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
2010 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
2011 not grep mbedtls_cmac ${BUILTIN_SRC_PATH}/cmac.o
2012
2013 # Run the tests
2014 # -------------
2015
2016 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
2017 make test
2018
2019 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
2020 tests/ssl-opt.sh
2021
2022 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
2023 tests/compat.sh -V NO -p mbedTLS
2024}
2025
2026component_test_psa_crypto_config_reference_cipher_aead_cmac () {
2027 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
2028 common_psa_crypto_config_accel_cipher_aead_cmac
2029
2030 make
2031
2032 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
2033 make test
2034
2035 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
2036 tests/ssl-opt.sh
2037
2038 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
2039 tests/compat.sh -V NO -p mbedTLS
2040}
2041
Minos Galanakisf78447f2024-07-26 20:49:51 +01002042common_block_cipher_dispatch () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002043 TEST_WITH_DRIVER="$1"
2044
2045 # Start from the full config
2046 helper_libtestdriver1_adjust_config "full"
2047
2048 if [ "$TEST_WITH_DRIVER" -eq 1 ]; then
2049 # Disable key types that are accelerated (there is no legacy equivalent
2050 # symbol for ECB)
2051 scripts/config.py unset MBEDTLS_AES_C
2052 scripts/config.py unset MBEDTLS_ARIA_C
2053 scripts/config.py unset MBEDTLS_CAMELLIA_C
2054 fi
2055
2056 # Disable cipher's modes that, when not accelerated, cause
2057 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
2058 # Keep this also in the reference component in order to skip the same tests
2059 # that were skipped in the accelerated one.
2060 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
2061 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
2062 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
2063 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
2064 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
2065 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
2066 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
2067 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
2068
2069 # Disable direct dependency on AES_C
2070 scripts/config.py unset MBEDTLS_NIST_KW_C
2071
2072 # Prevent the cipher module from using deprecated PSA path. The reason is
2073 # that otherwise there will be tests relying on "aes_info" (defined in
2074 # "cipher_wrap.c") whose functions are not available when AES_C is
2075 # not defined. ARIA and Camellia are not a problem in this case because
2076 # the PSA path is not tested for these key types.
2077 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
2078}
2079
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002080component_test_full_block_cipher_psa_dispatch_static_keystore () {
2081 msg "build: full + PSA dispatch in block_cipher with static keystore"
2082 # Check that the static key store works well when CTR_DRBG uses a
2083 # PSA key for AES.
2084 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2085
2086 loc_accel_list="ALG_ECB_NO_PADDING \
2087 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2088
2089 # Configure
2090 # ---------
2091
2092 common_block_cipher_dispatch 1
2093
2094 # Build
2095 # -----
2096
2097 helper_libtestdriver1_make_drivers "$loc_accel_list"
2098
2099 helper_libtestdriver1_make_main "$loc_accel_list"
2100
2101 # Make sure disabled components were not re-enabled by accident (additive
2102 # config)
2103 not grep mbedtls_aes_ library/aes.o
2104 not grep mbedtls_aria_ library/aria.o
2105 not grep mbedtls_camellia_ library/camellia.o
2106
2107 # Run the tests
2108 # -------------
2109
2110 msg "test: full + PSA dispatch in block_cipher with static keystore"
2111 make test
2112}
2113
Minos Galanakis471b34c2024-07-26 15:39:24 +01002114component_test_full_block_cipher_psa_dispatch () {
2115 msg "build: full + PSA dispatch in block_cipher"
2116
2117 loc_accel_list="ALG_ECB_NO_PADDING \
2118 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2119
2120 # Configure
2121 # ---------
2122
2123 common_block_cipher_dispatch 1
2124
2125 # Build
2126 # -----
2127
2128 helper_libtestdriver1_make_drivers "$loc_accel_list"
2129
2130 helper_libtestdriver1_make_main "$loc_accel_list"
2131
2132 # Make sure disabled components were not re-enabled by accident (additive
2133 # config)
2134 not grep mbedtls_aes_ ${BUILTIN_SRC_PATH}/aes.o
2135 not grep mbedtls_aria_ ${BUILTIN_SRC_PATH}/aria.o
2136 not grep mbedtls_camellia_ ${BUILTIN_SRC_PATH}/camellia.o
2137
2138 # Run the tests
2139 # -------------
2140
2141 msg "test: full + PSA dispatch in block_cipher"
2142 make test
2143}
2144
2145# This is the reference component of component_test_full_block_cipher_psa_dispatch
Minos Galanakis471b34c2024-07-26 15:39:24 +01002146component_test_full_block_cipher_legacy_dispatch () {
2147 msg "build: full + legacy dispatch in block_cipher"
2148
2149 common_block_cipher_dispatch 0
2150
2151 make
2152
2153 msg "test: full + legacy dispatch in block_cipher"
2154 make test
2155}
2156
Minos Galanakisf78447f2024-07-26 20:49:51 +01002157component_test_aead_chachapoly_disabled () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002158 msg "build: full minus CHACHAPOLY"
2159 scripts/config.py full
2160 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2161 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2162 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2163
2164 msg "test: full minus CHACHAPOLY"
2165 make test
2166}
2167
Minos Galanakisf78447f2024-07-26 20:49:51 +01002168component_test_aead_only_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002169 msg "build: full minus CHACHAPOLY and GCM"
2170 scripts/config.py full
2171 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2172 scripts/config.py unset MBEDTLS_GCM_C
2173 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2174 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2175 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2176
2177 msg "test: full minus CHACHAPOLY and GCM"
2178 make test
2179}
2180
Minos Galanakisf78447f2024-07-26 20:49:51 +01002181component_test_ccm_aes_sha256 () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002182 msg "build: CCM + AES + SHA256 configuration"
2183
2184 cp "$CONFIG_TEST_DRIVER_H" "$CONFIG_H"
2185 cp configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
2186
2187 make
2188
2189 msg "test: CCM + AES + SHA256 configuration"
2190 make test
2191}
2192
2193# Test that the given .o file builds with all (valid) combinations of the given options.
2194#
2195# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
2196#
2197# The validator function is the name of a function to validate the combination of options.
2198# It may be "" if all combinations are valid.
2199# It receives a string containing a combination of options, as passed to the compiler,
2200# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Minos Galanakisf78447f2024-07-26 20:49:51 +01002201build_test_config_combos () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002202 file=$1
2203 shift
2204 validate_options=$1
2205 shift
2206 options=("$@")
2207
2208 # clear all of the options so that they can be overridden on the clang commandline
2209 for opt in "${options[@]}"; do
2210 ./scripts/config.py unset ${opt}
2211 done
2212
2213 # enter the library directory
2214 cd library
2215
2216 # The most common issue is unused variables/functions, so ensure -Wunused is set.
2217 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
2218
2219 # Extract the command generated by the Makefile to build the target file.
2220 # This ensures that we have any include paths, macro definitions, etc
2221 # that may be applied by make.
2222 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
2223 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
2224
2225 makefile=$(TMPDIR=. mktemp)
2226 deps=""
2227
2228 len=${#options[@]}
2229 source_file=../${file%.o}.c
2230
2231 targets=0
2232 echo 'include Makefile' >${makefile}
2233
2234 for ((i = 0; i < $((2**${len})); i++)); do
2235 # generate each of 2^n combinations of options
2236 # each bit of $i is used to determine if options[i] will be set or not
2237 target="t"
2238 clang_args=""
2239 for ((j = 0; j < ${len}; j++)); do
2240 if (((i >> j) & 1)); then
2241 opt=-D${options[$j]}
2242 clang_args="${clang_args} ${opt}"
2243 target="${target}${opt}"
2244 fi
2245 done
2246
2247 # if combination is not known to be invalid, add it to the makefile
2248 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
2249 cmd="${compile_cmd} ${clang_args}"
2250 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
2251
2252 deps="${deps} ${target}"
2253 ((++targets))
2254 fi
2255 done
2256
2257 echo "build_test_config_combos: ${deps}" >> ${makefile}
2258
2259 # execute all of the commands via Make (probably in parallel)
2260 make -s -f ${makefile} build_test_config_combos
2261 echo "$targets targets checked"
2262
2263 # clean up the temporary makefile
2264 rm ${makefile}
2265}
2266
Minos Galanakisf78447f2024-07-26 20:49:51 +01002267validate_aes_config_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002268 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
2269 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
2270 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
2271 return 1
2272 fi
2273 fi
2274 return 0
2275}
2276
Minos Galanakisf78447f2024-07-26 20:49:51 +01002277component_build_aes_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002278 # 18s - around 90ms per clang invocation on M1 Pro
2279 #
2280 # aes.o has many #if defined(...) guards that intersect in complex ways.
2281 # Test that all the combinations build cleanly.
2282
2283 MBEDTLS_ROOT_DIR="$PWD"
2284 msg "build: aes.o for all combinations of relevant config options"
2285
2286 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002287 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002288 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2289 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2290
2291 cd "$MBEDTLS_ROOT_DIR"
2292 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
2293
2294 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES,
2295 # manually set or unset those configurations to check
2296 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
Ronald Cron54d1eec2024-09-06 09:55:38 +02002297 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
Minos Galanakis471b34c2024-07-26 15:39:24 +01002298 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Minos Galanakis471b34c2024-07-26 15:39:24 +01002299 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002300 scripts/config.py unset MBEDTLS_NIST_KW_C
Ronald Cron54d1eec2024-09-06 09:55:38 +02002301
2302 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
2303 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
2304 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
2305 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
Ronald Cron4153ebb2024-09-11 15:32:48 +02002306 # Note: The two unsets below are to be removed for Mbed TLS 4.0
Ronald Cron54d1eec2024-09-06 09:55:38 +02002307 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2308 scripts/config.py unset MBEDTLS_DES_C
2309
Minos Galanakis471b34c2024-07-26 15:39:24 +01002310 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002311 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002312 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2313 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2314}
2315
Minos Galanakisf78447f2024-07-26 20:49:51 +01002316component_test_sha3_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002317 msg "sha3 loop unroll variations"
2318
2319 # define minimal config sufficient to test SHA3
Ronald Crone7f289e2024-09-06 11:02:47 +02002320 cat > include/mbedtls/mbedtls_config.h << END
2321 #define MBEDTLS_AES_C
2322 #define MBEDTLS_CTR_DRBG_C
2323 #define MBEDTLS_ENTROPY_C
2324 #define MBEDTLS_PSA_CRYPTO_C
2325 #define MBEDTLS_PSA_CRYPTO_CONFIG
2326 #define MBEDTLS_SELF_TEST
2327END
2328
2329 cat > tf-psa-crypto/include/psa/crypto_config.h << END
2330 #define PSA_WANT_ALG_SHA_256 1
2331 #define PSA_WANT_ALG_SHA3_224 1
2332 #define PSA_WANT_ALG_SHA3_256 1
2333 #define PSA_WANT_ALG_SHA3_384 1
2334 #define PSA_WANT_ALG_SHA3_512 1
Minos Galanakis471b34c2024-07-26 15:39:24 +01002335END
2336
2337 msg "all loops unrolled"
2338 make clean
2339 make -C tests ../tf-psa-crypto/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"
2340 ./tf-psa-crypto/tests/test_suite_shax
2341
2342 msg "all loops rolled up"
2343 make clean
2344 make -C tests ../tf-psa-crypto/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"
2345 ./tf-psa-crypto/tests/test_suite_shax
2346}
2347
Minos Galanakisf699d512024-08-01 11:32:30 +01002348support_build_aes_aesce_armcc () {
2349 support_build_armcc
2350}
2351
Minos Galanakis471b34c2024-07-26 15:39:24 +01002352# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2353component_build_aes_aesce_armcc () {
2354 msg "Build: AESCE test on arm64 platform without plain C."
2355 scripts/config.py baremetal
2356
2357 # armc[56] don't support SHA-512 intrinsics
2358 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2359
2360 # Stop armclang warning about feature detection for A64_CRYPTO.
2361 # With this enabled, the library does build correctly under armclang,
2362 # but in baremetal builds (as tested here), feature detection is
2363 # unavailable, and the user is notified via a #warning. So enabling
2364 # this feature would prevent us from building with -Werror on
2365 # armclang. Tracked in #7198.
2366 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2367 scripts/config.py set MBEDTLS_HAVE_ASM
2368
2369 msg "AESCE, build with default configuration."
2370 scripts/config.py set MBEDTLS_AESCE_C
2371 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002372 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002373
2374 msg "AESCE, build AESCE only"
2375 scripts/config.py set MBEDTLS_AESCE_C
2376 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002377 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002378}
2379
Minos Galanakis471b34c2024-07-26 15:39:24 +01002380component_test_aes_only_128_bit_keys () {
2381 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2382 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2383
2384 make CFLAGS='-O2 -Werror -Wall -Wextra'
2385
2386 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2387 make test
2388}
2389
2390component_test_no_ctr_drbg_aes_only_128_bit_keys () {
2391 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2392 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2393 scripts/config.py unset MBEDTLS_CTR_DRBG_C
2394
2395 make CC=clang CFLAGS='-Werror -Wall -Wextra'
2396
2397 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2398 make test
2399}
2400
2401component_test_aes_only_128_bit_keys_have_builtins () {
2402 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2403 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2404 scripts/config.py unset MBEDTLS_AESNI_C
2405 scripts/config.py unset MBEDTLS_AESCE_C
2406
2407 make CFLAGS='-O2 -Werror -Wall -Wextra'
2408
2409 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2410 make test
2411
2412 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2413 programs/test/selftest
2414}
2415
2416component_test_gcm_largetable () {
2417 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2418 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
2419 scripts/config.py unset MBEDTLS_AESNI_C
2420 scripts/config.py unset MBEDTLS_AESCE_C
2421
2422 make CFLAGS='-O2 -Werror -Wall -Wextra'
2423
2424 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2425 make test
2426}
2427
2428component_test_aes_fewer_tables () {
2429 msg "build: default config with AES_FEWER_TABLES enabled"
2430 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2431 make CFLAGS='-O2 -Werror -Wall -Wextra'
2432
2433 msg "test: AES_FEWER_TABLES"
2434 make test
2435}
2436
2437component_test_aes_rom_tables () {
2438 msg "build: default config with AES_ROM_TABLES enabled"
2439 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2440 make CFLAGS='-O2 -Werror -Wall -Wextra'
2441
2442 msg "test: AES_ROM_TABLES"
2443 make test
2444}
2445
2446component_test_aes_fewer_tables_and_rom_tables () {
2447 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
2448 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2449 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2450 make CFLAGS='-O2 -Werror -Wall -Wextra'
2451
2452 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2453 make test
2454}
2455
Ronald Cron66040472024-09-06 10:14:38 +02002456# helper for component_test_block_cipher_no_decrypt_aesni() which:
Minos Galanakis471b34c2024-07-26 15:39:24 +01002457# - enable/disable the list of config options passed from -s/-u respectively.
2458# - build
2459# - test for tests_suite_xxx
2460# - selftest
2461#
2462# Usage: helper_block_cipher_no_decrypt_build_test
2463# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
2464# Options: -s set_opts the list of config options to enable
2465# -u unset_opts the list of config options to disable
2466# -c cflags the list of options passed to CFLAGS
2467# -l ldflags the list of options passed to LDFLAGS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002468helper_block_cipher_no_decrypt_build_test () {
2469 while [ $# -gt 0 ]; do
2470 case "$1" in
2471 -s)
2472 shift; local set_opts="$1";;
2473 -u)
2474 shift; local unset_opts="$1";;
2475 -c)
2476 shift; local cflags="-Werror -Wall -Wextra $1";;
2477 -l)
2478 shift; local ldflags="$1";;
2479 esac
2480 shift
2481 done
2482 set_opts="${set_opts:-}"
2483 unset_opts="${unset_opts:-}"
2484 cflags="${cflags:-}"
2485 ldflags="${ldflags:-}"
2486
2487 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
2488 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
2489
2490 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2491 make clean
2492 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
2493
2494 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2495 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2496 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2497 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2498 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2499 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2500 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
2501 not grep mbedtls_aesni_inverse_key ${BUILTIN_SRC_PATH}/aesni.o
2502
2503 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2504 make test
2505
2506 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2507 programs/test/selftest
2508}
2509
Ronald Cron66040472024-09-06 10:14:38 +02002510# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
2511config_block_cipher_no_decrypt () {
2512 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
2513 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2514 scripts/config.py unset MBEDTLS_NIST_KW_C
2515
2516 # Enable support for cryptographic mechanisms through the PSA API.
2517 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
2518 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2519 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
2520 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
2521 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
2522 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
Ronald Cron4153ebb2024-09-11 15:32:48 +02002523 # Note: The two unsets below are to be removed for Mbed TLS 4.0
Ronald Cron66040472024-09-06 10:14:38 +02002524 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2525 scripts/config.py unset MBEDTLS_DES_C
2526}
2527
2528component_test_block_cipher_no_decrypt_aesni () {
2529 # Test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics, AESNI assembly and
2530 # AES C implementation on x86_64 and with AESNI intrinsics on x86.
2531
2532 # This consistently causes an llvm crash on clang 3.8, so use gcc
2533 export CC=gcc
2534 config_block_cipher_no_decrypt
2535
Minos Galanakis471b34c2024-07-26 15:39:24 +01002536 # test AESNI intrinsics
2537 helper_block_cipher_no_decrypt_build_test \
2538 -s "MBEDTLS_AESNI_C" \
2539 -c "-mpclmul -msse2 -maes"
2540
2541 # test AESNI assembly
2542 helper_block_cipher_no_decrypt_build_test \
2543 -s "MBEDTLS_AESNI_C" \
2544 -c "-mno-pclmul -mno-sse2 -mno-aes"
2545
2546 # test AES C implementation
2547 helper_block_cipher_no_decrypt_build_test \
2548 -u "MBEDTLS_AESNI_C"
2549
2550 # test AESNI intrinsics for i386 target
2551 helper_block_cipher_no_decrypt_build_test \
2552 -s "MBEDTLS_AESNI_C" \
2553 -c "-m32 -mpclmul -msse2 -maes" \
2554 -l "-m32"
2555}
2556
Minos Galanakisf699d512024-08-01 11:32:30 +01002557support_test_block_cipher_no_decrypt_aesce_armcc () {
2558 support_build_armcc
2559}
2560
Minos Galanakis471b34c2024-07-26 15:39:24 +01002561component_test_block_cipher_no_decrypt_aesce_armcc () {
2562 scripts/config.py baremetal
2563
2564 # armc[56] don't support SHA-512 intrinsics
2565 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2566
2567 # Stop armclang warning about feature detection for A64_CRYPTO.
2568 # With this enabled, the library does build correctly under armclang,
2569 # but in baremetal builds (as tested here), feature detection is
2570 # unavailable, and the user is notified via a #warning. So enabling
2571 # this feature would prevent us from building with -Werror on
2572 # armclang. Tracked in #7198.
2573 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2574 scripts/config.py set MBEDTLS_HAVE_ASM
2575
Ronald Cron66040472024-09-06 10:14:38 +02002576 config_block_cipher_no_decrypt
Minos Galanakis471b34c2024-07-26 15:39:24 +01002577
2578 # test AESCE baremetal build
2579 scripts/config.py set MBEDTLS_AESCE_C
2580 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002581 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002582
2583 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2584 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2585 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2586 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2587 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2588 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2589 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
2590 not grep mbedtls_aesce_inverse_key ${BUILTIN_SRC_PATH}/aesce.o
2591 not grep aesce_decrypt_block ${BUILTIN_SRC_PATH}/aesce.o
2592}
2593
2594component_test_ctr_drbg_aes_256_sha_256 () {
2595 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2596 scripts/config.py full
2597 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2598 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
2599 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2600 make
2601
2602 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2603 make test
2604}
2605
2606component_test_ctr_drbg_aes_128_sha_512 () {
2607 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2608 scripts/config.py full
2609 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2610 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2611 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2612 make
2613
2614 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2615 make test
2616}
2617
2618component_test_ctr_drbg_aes_128_sha_256 () {
2619 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2620 scripts/config.py full
2621 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2622 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2623 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
2624 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2625 make
2626
2627 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2628 make test
2629}
2630
2631component_test_se_default () {
2632 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2633 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
2634 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
2635
2636 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2637 make test
2638}
2639
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002640component_test_full_static_keystore () {
2641 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2642 scripts/config.py full
2643 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2644 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
2645
2646 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2647 make test
2648}
2649
Minos Galanakis471b34c2024-07-26 15:39:24 +01002650component_test_psa_crypto_drivers () {
Ronald Crona0afbfb2024-10-15 13:20:31 +02002651 # Test dispatch to drivers and fallbacks with
2652 # test_suite_psa_crypto_driver_wrappers test suite. The test drivers that
2653 # are wrappers around the builtin drivers are activated by
2654 # PSA_CRYPTO_DRIVER_TEST.
2655 #
2656 # For the time being, some test cases in test_suite_block_cipher and
2657 # test_suite_md.psa rely on this component to be run at least once by the
2658 # CI. This should disappear as we progress the 4.x work. See
2659 # config_adjust_test_accelerators.h for more information.
Minos Galanakis471b34c2024-07-26 15:39:24 +01002660 msg "build: full + test drivers dispatching to builtins"
2661 scripts/config.py full
Ronald Cron67cc6a72024-10-14 10:55:24 +02002662 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_CONFIG_ADJUST_TEST_ACCELERATORS"
Ronald Cronede04b32024-10-16 10:47:15 +02002663 loc_cflags="${loc_cflags} -I../tests/include"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002664
2665 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
2666
2667 msg "test: full + test drivers dispatching to builtins"
2668 make test
2669}
2670
2671component_build_psa_config_file () {
2672 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
2673 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2674 cp "$CRYPTO_CONFIG_H" psa_test_config.h
2675 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
2676 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
2677 # Make sure this feature is enabled. We'll disable it in the next phase.
2678 programs/test/query_compile_time_config MBEDTLS_CMAC_C
2679 make clean
2680
2681 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
2682 # In the user config, disable one feature and its dependencies, which will
2683 # reflect on the mbedtls configuration so we can query it with
2684 # query_compile_time_config.
2685 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
2686 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
2687 scripts/config.py unset MBEDTLS_CMAC_C
2688 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
2689 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
2690
2691 rm -f psa_test_config.h psa_user_config.h
2692}
2693
2694component_build_psa_alt_headers () {
2695 msg "build: make with PSA alt headers" # ~20s
2696
2697 # Generate alternative versions of the substitutable headers with the
2698 # same content except different include guards.
2699 make -C tests include/alt-extra/psa/crypto_platform_alt.h include/alt-extra/psa/crypto_struct_alt.h
2700
2701 # Build the library and some programs.
2702 # Don't build the fuzzers to avoid having to go through hoops to set
2703 # a correct include path for programs/fuzz/Makefile.
2704 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
2705 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\"'"
2706
2707 # Check that we're getting the alternative include guards and not the
2708 # original include guards.
2709 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
2710 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
2711 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
2712 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
2713}
2714
2715component_test_min_mpi_window_size () {
2716 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
2717 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
2718 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2719 make
2720
2721 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2722 make test
2723}