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