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