blob: eaa0bcab99b534e69dfde8c09e843176dba9f0b6 [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.
70 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
71
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"
75 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
76}
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
540 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
541 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
1246 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1247 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1248 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1249 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1250 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1251
1252 if [ "$test_target" = "ECC" ]; then
1253 # When testing ECC only, we disable FFDH support, both from builtin and
1254 # PSA sides, and also disable the key exchanges that depend on DHM.
1255 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_FFDH
1256 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
1257 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
1258 scripts/config.py unset MBEDTLS_DHM_C
1259 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1260 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1261 else
1262 # When testing ECC and DH instead, we disable DHM and depending key
1263 # exchanges only in the accelerated build
1264 if [ "$driver_only" -eq 1 ]; then
1265 scripts/config.py unset MBEDTLS_DHM_C
1266 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1267 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1268 fi
1269 fi
1270
1271 # Restartable feature is not yet supported by PSA. Once it will in
1272 # the future, the following line could be removed (see issues
1273 # 6061, 6332 and following ones)
1274 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1275}
1276
1277# Common helper used by:
1278# - component_test_psa_crypto_config_accel_ecc_no_bignum
1279# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1280#
1281# The goal is to build and test accelerating either:
1282# - ECC only or
1283# - both ECC and FFDH
1284#
1285# It is meant to be used in conjunction with
1286# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
1287# coverage analysis in the "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001288common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1289 test_target="$1"
1290
1291 # This is an internal helper to simplify text message handling
1292 if [ "$test_target" = "ECC_DH" ]; then
1293 accel_text="ECC/FFDH"
1294 removed_text="ECP - DH"
1295 else
1296 accel_text="ECC"
1297 removed_text="ECP"
1298 fi
1299
1300 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1301
1302 # By default we accelerate all EC keys/algs
1303 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1304 ALG_ECDH \
1305 ALG_JPAKE \
1306 $(helper_get_psa_key_type_list "ECC") \
1307 $(helper_get_psa_curve_list)"
1308 # Optionally we can also add DH to the list of accelerated items
1309 if [ "$test_target" = "ECC_DH" ]; then
1310 loc_accel_list="$loc_accel_list \
1311 ALG_FFDH \
1312 $(helper_get_psa_key_type_list "DH") \
1313 $(helper_get_psa_dh_group_list)"
1314 fi
1315
1316 # Configure
1317 # ---------
1318
1319 # Set common configurations between library's and driver's builds
1320 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
1321 # Disable all the builtin curves. All the required algs are accelerated.
1322 helper_disable_builtin_curves
1323
1324 # Build
1325 # -----
1326
1327 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1328 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1329 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1330 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1331
1332 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1333
1334 helper_libtestdriver1_make_main "$loc_accel_list"
1335
1336 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1337 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1338 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1339 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1340 # Also ensure that ECP, RSA, [DHM] or BIGNUM modules were not re-enabled
1341 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1342 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1343 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1344 not grep mbedtls_dhm_ ${BUILTIN_SRC_PATH}/dhm.o
1345
1346 # Run the tests
1347 # -------------
1348
1349 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - DHM - BIGNUM"
1350
1351 make test
1352
1353 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1354 tests/ssl-opt.sh
1355}
1356
1357# Common helper used by:
1358# - component_test_psa_crypto_config_reference_ecc_no_bignum
1359# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1360#
1361# The goal is to build and test a reference scenario (i.e. with builtin
1362# components) compared to the ones used in
1363# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
1364#
1365# It is meant to be used in conjunction with
1366# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
1367# coverage analysis in "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001368common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1369 test_target="$1"
1370
1371 # This is an internal helper to simplify text message handling
1372 if [ "$test_target" = "ECC_DH" ]; then
1373 accel_text="ECC/FFDH"
1374 else
1375 accel_text="ECC"
1376 fi
1377
1378 msg "build: full + non accelerated $accel_text algs + USE_PSA"
1379
1380 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
1381
1382 make
1383
1384 msg "test suites: full + non accelerated EC algs + USE_PSA"
1385 make test
1386
1387 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
1388 tests/ssl-opt.sh
1389}
1390
1391component_test_psa_crypto_config_accel_ecc_no_bignum () {
1392 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
1393}
1394
1395component_test_psa_crypto_config_reference_ecc_no_bignum () {
1396 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
1397}
1398
1399component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1400 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
1401}
1402
1403component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1404 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
1405}
1406
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001407component_test_tfm_config_as_is () {
1408 msg "build: configs/config-tfm.h"
1409 cp configs/config-tfm.h "$CONFIG_H"
1410 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1411 make
1412
1413 msg "test: configs/config-tfm.h - unit tests"
1414 make test
1415}
1416
Minos Galanakis471b34c2024-07-26 15:39:24 +01001417# Helper for setting common configurations between:
1418# - component_test_tfm_config_p256m_driver_accel_ec()
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001419# - component_test_tfm_config_no_p256m()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001420common_tfm_config () {
1421 # Enable TF-M config
1422 cp configs/config-tfm.h "$CONFIG_H"
1423 echo "#undef MBEDTLS_PSA_CRYPTO_CONFIG_FILE" >> "$CONFIG_H"
1424 cp configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
1425
Minos Galanakis471b34c2024-07-26 15:39:24 +01001426 # Config adjustment for better test coverage in our environment.
1427 # This is not needed just to build and pass tests.
1428 #
1429 # Enable filesystem I/O for the benefit of PK parse/write tests.
1430 echo "#define MBEDTLS_FS_IO" >> "$CONFIG_H"
1431}
1432
1433# Keep this in sync with component_test_tfm_config() as they are both meant
1434# to be used in analyze_outcomes.py for driver's coverage analysis.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001435component_test_tfm_config_p256m_driver_accel_ec () {
1436 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1437
1438 common_tfm_config
1439
1440 # Build crypto library
1441 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
1442
1443 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1444 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1445 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1446 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1447 # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
1448 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1449 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1450 not grep mbedtls_dhm_ ${BUILTIN_SRC_PATH}/dhm.o
1451 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1452 # Check that p256m was built
1453 grep -q p256_ecdsa_ library/libmbedcrypto.a
1454
1455 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1456 # files, so we want to ensure that it has not be re-enabled accidentally.
1457 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1458
1459 # Run the tests
1460 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1461 make test
1462}
1463
1464# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1465# they are both meant to be used in analyze_outcomes.py for driver's coverage
1466# analysis.
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001467component_test_tfm_config_no_p256m () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001468 common_tfm_config
1469
1470 # Disable P256M driver, which is on by default, so that analyze_outcomes
1471 # can compare this test with test_tfm_config_p256m_driver_accel_ec
1472 echo "#undef MBEDTLS_PSA_P256M_DRIVER_ENABLED" >> "$CONFIG_H"
1473
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001474 msg "build: TF-M config without p256m"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001475 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' tests
1476
1477 # Check that p256m was not built
1478 not grep p256_ecdsa_ library/libmbedcrypto.a
1479
1480 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1481 # files, so we want to ensure that it has not be re-enabled accidentally.
1482 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1483
Gilles Peskineeffa6a02024-09-14 11:35:36 +02001484 msg "test: TF-M config without p256m"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001485 make test
1486}
1487
Minos Galanakis471b34c2024-07-26 15:39:24 +01001488# This is an helper used by:
1489# - component_test_psa_ecc_key_pair_no_derive
1490# - component_test_psa_ecc_key_pair_no_generate
1491# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1492# enabled, but one. Input arguments are as follows:
Gilles Peskinefef912c2024-09-20 16:07:09 +02001493# - $1 is the configuration to start from
1494# - $2 is the key type under test, i.e. ECC/RSA/DH
1495# - $3 is the key option to be unset (i.e. generate, derive, etc)
Minos Galanakisf78447f2024-07-26 20:49:51 +01001496build_and_test_psa_want_key_pair_partial () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001497 base_config=$1
1498 key_type=$2
1499 unset_option=$3
Minos Galanakis471b34c2024-07-26 15:39:24 +01001500 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1501
Gilles Peskinefef912c2024-09-20 16:07:09 +02001502 msg "build: $base_config - ${disabled_psa_want}"
1503 scripts/config.py "$base_config"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001504
1505 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1506 # crypto_config.h so we just disable the one we don't want.
1507 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
1508
1509 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1510
Gilles Peskinefef912c2024-09-20 16:07:09 +02001511 msg "test: $base_config - ${disabled_psa_want}"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001512 make test
1513}
1514
Minos Galanakisf78447f2024-07-26 20:49:51 +01001515component_test_psa_ecc_key_pair_no_derive () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001516 build_and_test_psa_want_key_pair_partial full "ECC" "DERIVE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001517}
1518
Minos Galanakisf78447f2024-07-26 20:49:51 +01001519component_test_psa_ecc_key_pair_no_generate () {
Gilles Peskinefef912c2024-09-20 16:07:09 +02001520 # TLS needs ECC key generation whenever ephemeral ECDH is enabled.
1521 # We don't have proper guards for configurations with ECC key generation
1522 # disabled (https://github.com/Mbed-TLS/mbedtls/issues/9481). Until
1523 # then (if ever), just test the crypto part of the library.
1524 build_and_test_psa_want_key_pair_partial crypto_full "ECC" "GENERATE"
Minos Galanakis471b34c2024-07-26 15:39:24 +01001525}
1526
1527config_psa_crypto_accel_rsa () {
1528 driver_only=$1
1529
1530 # Start from crypto_full config (no X.509, no TLS)
1531 helper_libtestdriver1_adjust_config "crypto_full"
1532
1533 if [ "$driver_only" -eq 1 ]; then
1534 # Remove RSA support and its dependencies
1535 scripts/config.py unset MBEDTLS_RSA_C
1536 scripts/config.py unset MBEDTLS_PKCS1_V15
1537 scripts/config.py unset MBEDTLS_PKCS1_V21
1538
1539 # We need PEM parsing in the test library as well to support the import
1540 # of PEM encoded RSA keys.
1541 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1542 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
1543 fi
1544}
1545
1546component_test_psa_crypto_config_accel_rsa_crypto () {
1547 msg "build: crypto_full with accelerated RSA"
1548
1549 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1550 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1551 KEY_TYPE_RSA_PUBLIC_KEY \
1552 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1553 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1554 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1555 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1556
1557 # Configure
1558 # ---------
1559
1560 config_psa_crypto_accel_rsa 1
1561
1562 # Build
1563 # -----
1564
1565 # These hashes are needed for unit tests.
1566 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1567 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1568 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1569
1570 helper_libtestdriver1_make_main "$loc_accel_list"
1571
1572 # Make sure this was not re-enabled by accident (additive config)
1573 not grep mbedtls_rsa ${BUILTIN_SRC_PATH}/rsa.o
1574
1575 # Run the tests
1576 # -------------
1577
1578 msg "test: crypto_full with accelerated RSA"
1579 make test
1580}
1581
1582component_test_psa_crypto_config_reference_rsa_crypto () {
1583 msg "build: crypto_full with non-accelerated RSA"
1584
1585 # Configure
1586 # ---------
1587 config_psa_crypto_accel_rsa 0
1588
1589 # Build
1590 # -----
1591 make
1592
1593 # Run the tests
1594 # -------------
1595 msg "test: crypto_full with non-accelerated RSA"
1596 make test
1597}
1598
1599# This is a temporary test to verify that full RSA support is present even when
1600# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001601component_test_new_psa_want_key_pair_symbol () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001602 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1603
1604 # Create a temporary output file unless there is already one set
1605 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1606 REMOVE_OUTCOME_ON_EXIT="no"
1607 else
1608 REMOVE_OUTCOME_ON_EXIT="yes"
1609 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1610 export MBEDTLS_TEST_OUTCOME_FILE
1611 fi
1612
1613 # Start from crypto configuration
1614 scripts/config.py crypto
1615
1616 # Remove RSA support and its dependencies
1617 scripts/config.py unset MBEDTLS_PKCS1_V15
1618 scripts/config.py unset MBEDTLS_PKCS1_V21
1619 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1620 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1621 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1622 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1623 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1624 scripts/config.py unset MBEDTLS_RSA_C
1625 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1626
1627 # Enable PSA support
1628 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1629
1630 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
1631 # that proper translations is done in crypto_legacy.h.
1632 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
1633 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
1634 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
1635
1636 make
1637
1638 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1639 make test
1640
1641 # Parse only 1 relevant line from the outcome file, i.e. a test which is
1642 # performing RSA signature.
1643 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
1644 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
1645
1646 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
1647 rm $MBEDTLS_TEST_OUTCOME_FILE
1648 fi
1649}
1650
1651component_test_psa_crypto_config_accel_hash () {
1652 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
1653
1654 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1655 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1656 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1657
1658 # Configure
1659 # ---------
1660
1661 # Start from default config (no USE_PSA)
1662 helper_libtestdriver1_adjust_config "default"
1663
1664 # Disable the things that are being accelerated
1665 scripts/config.py unset MBEDTLS_MD5_C
1666 scripts/config.py unset MBEDTLS_RIPEMD160_C
1667 scripts/config.py unset MBEDTLS_SHA1_C
1668 scripts/config.py unset MBEDTLS_SHA224_C
1669 scripts/config.py unset MBEDTLS_SHA256_C
1670 scripts/config.py unset MBEDTLS_SHA384_C
1671 scripts/config.py unset MBEDTLS_SHA512_C
1672 scripts/config.py unset MBEDTLS_SHA3_C
1673
1674 # Build
1675 # -----
1676
1677 helper_libtestdriver1_make_drivers "$loc_accel_list"
1678
1679 helper_libtestdriver1_make_main "$loc_accel_list"
1680
1681 # There's a risk of something getting re-enabled via config_psa.h;
1682 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1683 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1684 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1685 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1686 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1687 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1688
1689 # Run the tests
1690 # -------------
1691
1692 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
1693 make test
1694}
1695
1696# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001697config_psa_crypto_hash_use_psa () {
1698 driver_only="$1"
1699 # start with config full for maximum coverage (also enables USE_PSA)
1700 helper_libtestdriver1_adjust_config "full"
1701 if [ "$driver_only" -eq 1 ]; then
1702 # disable the built-in implementation of hashes
1703 scripts/config.py unset MBEDTLS_MD5_C
1704 scripts/config.py unset MBEDTLS_RIPEMD160_C
1705 scripts/config.py unset MBEDTLS_SHA1_C
1706 scripts/config.py unset MBEDTLS_SHA224_C
1707 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
1708 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
1709 scripts/config.py unset MBEDTLS_SHA384_C
1710 scripts/config.py unset MBEDTLS_SHA512_C
1711 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
1712 scripts/config.py unset MBEDTLS_SHA3_C
1713 fi
1714}
1715
1716# Note that component_test_psa_crypto_config_reference_hash_use_psa
1717# is related to this component and both components need to be kept in sync.
1718# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001719component_test_psa_crypto_config_accel_hash_use_psa () {
1720 msg "test: full with accelerated hashes"
1721
1722 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1723 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1724 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1725
1726 # Configure
1727 # ---------
1728
1729 config_psa_crypto_hash_use_psa 1
1730
1731 # Build
1732 # -----
1733
1734 helper_libtestdriver1_make_drivers "$loc_accel_list"
1735
1736 helper_libtestdriver1_make_main "$loc_accel_list"
1737
1738 # There's a risk of something getting re-enabled via config_psa.h;
1739 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1740 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1741 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1742 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1743 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1744 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1745
1746 # Run the tests
1747 # -------------
1748
1749 msg "test: full with accelerated hashes"
1750 make test
1751
1752 # This is mostly useful so that we can later compare outcome files with
1753 # the reference config in analyze_outcomes.py, to check that the
1754 # dependency declarations in ssl-opt.sh and in TLS code are correct.
1755 msg "test: ssl-opt.sh, full with accelerated hashes"
1756 tests/ssl-opt.sh
1757
1758 # This is to make sure all ciphersuites are exercised, but we don't need
1759 # interop testing (besides, we already got some from ssl-opt.sh).
1760 msg "test: compat.sh, full with accelerated hashes"
1761 tests/compat.sh -p mbedTLS -V YES
1762}
1763
1764# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
1765# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
1766# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
1767# Both components need to be kept in sync.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001768component_test_psa_crypto_config_reference_hash_use_psa () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001769 msg "test: full without accelerated hashes"
1770
1771 config_psa_crypto_hash_use_psa 0
1772
1773 make
1774
1775 msg "test: full without accelerated hashes"
1776 make test
1777
1778 msg "test: ssl-opt.sh, full without accelerated hashes"
1779 tests/ssl-opt.sh
1780}
1781
1782# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001783config_psa_crypto_hmac_use_psa () {
1784 driver_only="$1"
1785 # start with config full for maximum coverage (also enables USE_PSA)
1786 helper_libtestdriver1_adjust_config "full"
1787
1788 if [ "$driver_only" -eq 1 ]; then
1789 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
1790 # is still enabled though (for ENTROPY_C among others).
1791 scripts/config.py unset MBEDTLS_MD_C
1792 # Disable also the builtin hashes since they are supported by the driver
1793 # and MD module is able to perform PSA dispathing.
1794 scripts/config.py unset-all MBEDTLS_SHA
1795 scripts/config.py unset MBEDTLS_MD5_C
1796 scripts/config.py unset MBEDTLS_RIPEMD160_C
1797 fi
1798
1799 # Direct dependencies of MD_C. We disable them also in the reference
1800 # component to work with the same set of features.
1801 scripts/config.py unset MBEDTLS_PKCS7_C
1802 scripts/config.py unset MBEDTLS_PKCS5_C
1803 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1804 scripts/config.py unset MBEDTLS_HKDF_C
1805 # Dependencies of HMAC_DRBG
1806 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
1807 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
1808}
1809
Minos Galanakisf78447f2024-07-26 20:49:51 +01001810component_test_psa_crypto_config_accel_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001811 msg "test: full with accelerated hmac"
1812
1813 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
1814 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1815 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1816 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1817
1818 # Configure
1819 # ---------
1820
1821 config_psa_crypto_hmac_use_psa 1
1822
1823 # Build
1824 # -----
1825
1826 helper_libtestdriver1_make_drivers "$loc_accel_list"
1827
1828 helper_libtestdriver1_make_main "$loc_accel_list"
1829
1830 # Ensure that built-in support for HMAC is disabled.
1831 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
1832
1833 # Run the tests
1834 # -------------
1835
1836 msg "test: full with accelerated hmac"
1837 make test
1838}
1839
Minos Galanakisf78447f2024-07-26 20:49:51 +01001840component_test_psa_crypto_config_reference_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001841 msg "test: full without accelerated hmac"
1842
1843 config_psa_crypto_hmac_use_psa 0
1844
1845 make
1846
1847 msg "test: full without accelerated hmac"
1848 make test
1849}
1850
1851component_test_psa_crypto_config_accel_des () {
1852 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
1853
1854 # Albeit this components aims at accelerating DES which should only support
1855 # CBC and ECB modes, we need to accelerate more than that otherwise DES_C
1856 # would automatically be re-enabled by "config_adjust_legacy_from_psa.c"
1857 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 \
1858 ALG_CTR ALG_CFB ALG_OFB ALG_XTS ALG_CMAC \
1859 KEY_TYPE_DES"
1860
1861 # Note: we cannot accelerate all ciphers' key types otherwise we would also
1862 # have to either disable CCM/GCM or accelerate them, but that's out of scope
1863 # of this component. This limitation will be addressed by #8598.
1864
1865 # Configure
1866 # ---------
1867
1868 # Start from the full config
1869 helper_libtestdriver1_adjust_config "full"
1870
1871 # Disable the things that are being accelerated
1872 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1873 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
1874 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
1875 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
1876 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
1877 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
1878 scripts/config.py unset MBEDTLS_DES_C
1879 scripts/config.py unset MBEDTLS_CMAC_C
1880
1881 # Build
1882 # -----
1883
1884 helper_libtestdriver1_make_drivers "$loc_accel_list"
1885
1886 helper_libtestdriver1_make_main "$loc_accel_list"
1887
1888 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine29e86ca2024-06-19 15:09:27 +02001889 not grep mbedtls_des ${BUILTIN_SRC_PATH}/des.o
Minos Galanakis471b34c2024-07-26 15:39:24 +01001890
1891 # Run the tests
1892 # -------------
1893
1894 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
1895 make test
1896}
1897
1898component_test_psa_crypto_config_accel_aead () {
1899 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
1900
1901 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
1902 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1903
1904 # Configure
1905 # ---------
1906
1907 # Start from full config
1908 helper_libtestdriver1_adjust_config "full"
1909
1910 # Disable things that are being accelerated
1911 scripts/config.py unset MBEDTLS_GCM_C
1912 scripts/config.py unset MBEDTLS_CCM_C
1913 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1914
1915 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
1916 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1917
1918 # Build
1919 # -----
1920
1921 helper_libtestdriver1_make_drivers "$loc_accel_list"
1922
1923 helper_libtestdriver1_make_main "$loc_accel_list"
1924
1925 # Make sure this was not re-enabled by accident (additive config)
1926 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1927 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1928 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1929
1930 # Run the tests
1931 # -------------
1932
1933 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
1934 make test
1935}
1936
1937# This is a common configuration function used in:
1938# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1939# - component_test_psa_crypto_config_reference_cipher_aead_cmac
Minos Galanakisf78447f2024-07-26 20:49:51 +01001940common_psa_crypto_config_accel_cipher_aead_cmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001941 # Start from the full config
1942 helper_libtestdriver1_adjust_config "full"
1943
1944 scripts/config.py unset MBEDTLS_NIST_KW_C
1945}
1946
1947# The 2 following test components, i.e.
1948# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1949# - component_test_psa_crypto_config_reference_cipher_aead_cmac
1950# are meant to be used together in analyze_outcomes.py script in order to test
1951# driver's coverage for ciphers and AEADs.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001952component_test_psa_crypto_config_accel_cipher_aead_cmac () {
1953 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
1954
1955 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
1956 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
1957 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
1958 KEY_TYPE_DES KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
1959
1960 # Configure
1961 # ---------
1962
1963 common_psa_crypto_config_accel_cipher_aead_cmac
1964
1965 # Disable the things that are being accelerated
1966 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1967 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
1968 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
1969 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
1970 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
1971 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
1972 scripts/config.py unset MBEDTLS_GCM_C
1973 scripts/config.py unset MBEDTLS_CCM_C
1974 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1975 scripts/config.py unset MBEDTLS_CMAC_C
1976 scripts/config.py unset MBEDTLS_DES_C
1977 scripts/config.py unset MBEDTLS_AES_C
1978 scripts/config.py unset MBEDTLS_ARIA_C
1979 scripts/config.py unset MBEDTLS_CHACHA20_C
1980 scripts/config.py unset MBEDTLS_CAMELLIA_C
1981
1982 # Disable CIPHER_C entirely as all ciphers/AEADs are accelerated and PSA
1983 # does not depend on it.
1984 scripts/config.py unset MBEDTLS_CIPHER_C
1985
1986 # Build
1987 # -----
1988
1989 helper_libtestdriver1_make_drivers "$loc_accel_list"
1990
1991 helper_libtestdriver1_make_main "$loc_accel_list"
1992
1993 # Make sure this was not re-enabled by accident (additive config)
1994 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1995 not grep mbedtls_des ${BUILTIN_SRC_PATH}/des.o
1996 not grep mbedtls_aes ${BUILTIN_SRC_PATH}/aes.o
1997 not grep mbedtls_aria ${BUILTIN_SRC_PATH}/aria.o
1998 not grep mbedtls_camellia ${BUILTIN_SRC_PATH}/camellia.o
1999 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
2000 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
2001 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
2002 not grep mbedtls_cmac ${BUILTIN_SRC_PATH}/cmac.o
2003
2004 # Run the tests
2005 # -------------
2006
2007 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
2008 make test
2009
2010 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
2011 tests/ssl-opt.sh
2012
2013 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
2014 tests/compat.sh -V NO -p mbedTLS
2015}
2016
2017component_test_psa_crypto_config_reference_cipher_aead_cmac () {
2018 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
2019 common_psa_crypto_config_accel_cipher_aead_cmac
2020
2021 make
2022
2023 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
2024 make test
2025
2026 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
2027 tests/ssl-opt.sh
2028
2029 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
2030 tests/compat.sh -V NO -p mbedTLS
2031}
2032
Minos Galanakisf78447f2024-07-26 20:49:51 +01002033common_block_cipher_dispatch () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002034 TEST_WITH_DRIVER="$1"
2035
2036 # Start from the full config
2037 helper_libtestdriver1_adjust_config "full"
2038
2039 if [ "$TEST_WITH_DRIVER" -eq 1 ]; then
2040 # Disable key types that are accelerated (there is no legacy equivalent
2041 # symbol for ECB)
2042 scripts/config.py unset MBEDTLS_AES_C
2043 scripts/config.py unset MBEDTLS_ARIA_C
2044 scripts/config.py unset MBEDTLS_CAMELLIA_C
2045 fi
2046
2047 # Disable cipher's modes that, when not accelerated, cause
2048 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
2049 # Keep this also in the reference component in order to skip the same tests
2050 # that were skipped in the accelerated one.
2051 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
2052 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
2053 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
2054 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
2055 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
2056 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
2057 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
2058 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
2059
2060 # Disable direct dependency on AES_C
2061 scripts/config.py unset MBEDTLS_NIST_KW_C
2062
2063 # Prevent the cipher module from using deprecated PSA path. The reason is
2064 # that otherwise there will be tests relying on "aes_info" (defined in
2065 # "cipher_wrap.c") whose functions are not available when AES_C is
2066 # not defined. ARIA and Camellia are not a problem in this case because
2067 # the PSA path is not tested for these key types.
2068 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
2069}
2070
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002071component_test_full_block_cipher_psa_dispatch_static_keystore () {
2072 msg "build: full + PSA dispatch in block_cipher with static keystore"
2073 # Check that the static key store works well when CTR_DRBG uses a
2074 # PSA key for AES.
2075 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2076
2077 loc_accel_list="ALG_ECB_NO_PADDING \
2078 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2079
2080 # Configure
2081 # ---------
2082
2083 common_block_cipher_dispatch 1
2084
2085 # Build
2086 # -----
2087
2088 helper_libtestdriver1_make_drivers "$loc_accel_list"
2089
2090 helper_libtestdriver1_make_main "$loc_accel_list"
2091
2092 # Make sure disabled components were not re-enabled by accident (additive
2093 # config)
2094 not grep mbedtls_aes_ library/aes.o
2095 not grep mbedtls_aria_ library/aria.o
2096 not grep mbedtls_camellia_ library/camellia.o
2097
2098 # Run the tests
2099 # -------------
2100
2101 msg "test: full + PSA dispatch in block_cipher with static keystore"
2102 make test
2103}
2104
Minos Galanakis471b34c2024-07-26 15:39:24 +01002105component_test_full_block_cipher_psa_dispatch () {
2106 msg "build: full + PSA dispatch in block_cipher"
2107
2108 loc_accel_list="ALG_ECB_NO_PADDING \
2109 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2110
2111 # Configure
2112 # ---------
2113
2114 common_block_cipher_dispatch 1
2115
2116 # Build
2117 # -----
2118
2119 helper_libtestdriver1_make_drivers "$loc_accel_list"
2120
2121 helper_libtestdriver1_make_main "$loc_accel_list"
2122
2123 # Make sure disabled components were not re-enabled by accident (additive
2124 # config)
2125 not grep mbedtls_aes_ ${BUILTIN_SRC_PATH}/aes.o
2126 not grep mbedtls_aria_ ${BUILTIN_SRC_PATH}/aria.o
2127 not grep mbedtls_camellia_ ${BUILTIN_SRC_PATH}/camellia.o
2128
2129 # Run the tests
2130 # -------------
2131
2132 msg "test: full + PSA dispatch in block_cipher"
2133 make test
2134}
2135
2136# This is the reference component of component_test_full_block_cipher_psa_dispatch
Minos Galanakis471b34c2024-07-26 15:39:24 +01002137component_test_full_block_cipher_legacy_dispatch () {
2138 msg "build: full + legacy dispatch in block_cipher"
2139
2140 common_block_cipher_dispatch 0
2141
2142 make
2143
2144 msg "test: full + legacy dispatch in block_cipher"
2145 make test
2146}
2147
Minos Galanakisf78447f2024-07-26 20:49:51 +01002148component_test_aead_chachapoly_disabled () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002149 msg "build: full minus CHACHAPOLY"
2150 scripts/config.py full
2151 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2152 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2153 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2154
2155 msg "test: full minus CHACHAPOLY"
2156 make test
2157}
2158
Minos Galanakisf78447f2024-07-26 20:49:51 +01002159component_test_aead_only_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002160 msg "build: full minus CHACHAPOLY and GCM"
2161 scripts/config.py full
2162 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2163 scripts/config.py unset MBEDTLS_GCM_C
2164 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2165 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2166 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2167
2168 msg "test: full minus CHACHAPOLY and GCM"
2169 make test
2170}
2171
Minos Galanakisf78447f2024-07-26 20:49:51 +01002172component_test_ccm_aes_sha256 () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002173 msg "build: CCM + AES + SHA256 configuration"
2174
2175 cp "$CONFIG_TEST_DRIVER_H" "$CONFIG_H"
2176 cp configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
2177
2178 make
2179
2180 msg "test: CCM + AES + SHA256 configuration"
2181 make test
2182}
2183
2184# Test that the given .o file builds with all (valid) combinations of the given options.
2185#
2186# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
2187#
2188# The validator function is the name of a function to validate the combination of options.
2189# It may be "" if all combinations are valid.
2190# It receives a string containing a combination of options, as passed to the compiler,
2191# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Minos Galanakisf78447f2024-07-26 20:49:51 +01002192build_test_config_combos () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002193 file=$1
2194 shift
2195 validate_options=$1
2196 shift
2197 options=("$@")
2198
2199 # clear all of the options so that they can be overridden on the clang commandline
2200 for opt in "${options[@]}"; do
2201 ./scripts/config.py unset ${opt}
2202 done
2203
2204 # enter the library directory
2205 cd library
2206
2207 # The most common issue is unused variables/functions, so ensure -Wunused is set.
2208 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
2209
2210 # Extract the command generated by the Makefile to build the target file.
2211 # This ensures that we have any include paths, macro definitions, etc
2212 # that may be applied by make.
2213 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
2214 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
2215
2216 makefile=$(TMPDIR=. mktemp)
2217 deps=""
2218
2219 len=${#options[@]}
2220 source_file=../${file%.o}.c
2221
2222 targets=0
2223 echo 'include Makefile' >${makefile}
2224
2225 for ((i = 0; i < $((2**${len})); i++)); do
2226 # generate each of 2^n combinations of options
2227 # each bit of $i is used to determine if options[i] will be set or not
2228 target="t"
2229 clang_args=""
2230 for ((j = 0; j < ${len}; j++)); do
2231 if (((i >> j) & 1)); then
2232 opt=-D${options[$j]}
2233 clang_args="${clang_args} ${opt}"
2234 target="${target}${opt}"
2235 fi
2236 done
2237
2238 # if combination is not known to be invalid, add it to the makefile
2239 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
2240 cmd="${compile_cmd} ${clang_args}"
2241 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
2242
2243 deps="${deps} ${target}"
2244 ((++targets))
2245 fi
2246 done
2247
2248 echo "build_test_config_combos: ${deps}" >> ${makefile}
2249
2250 # execute all of the commands via Make (probably in parallel)
2251 make -s -f ${makefile} build_test_config_combos
2252 echo "$targets targets checked"
2253
2254 # clean up the temporary makefile
2255 rm ${makefile}
2256}
2257
Minos Galanakisf78447f2024-07-26 20:49:51 +01002258validate_aes_config_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002259 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
2260 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
2261 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
2262 return 1
2263 fi
2264 fi
2265 return 0
2266}
2267
Minos Galanakisf78447f2024-07-26 20:49:51 +01002268component_build_aes_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002269 # 18s - around 90ms per clang invocation on M1 Pro
2270 #
2271 # aes.o has many #if defined(...) guards that intersect in complex ways.
2272 # Test that all the combinations build cleanly.
2273
2274 MBEDTLS_ROOT_DIR="$PWD"
2275 msg "build: aes.o for all combinations of relevant config options"
2276
2277 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002278 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002279 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2280 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2281
2282 cd "$MBEDTLS_ROOT_DIR"
2283 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
2284
2285 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES,
2286 # manually set or unset those configurations to check
2287 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
Ronald Cron54d1eec2024-09-06 09:55:38 +02002288 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
Minos Galanakis471b34c2024-07-26 15:39:24 +01002289 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Minos Galanakis471b34c2024-07-26 15:39:24 +01002290 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002291 scripts/config.py unset MBEDTLS_NIST_KW_C
Ronald Cron54d1eec2024-09-06 09:55:38 +02002292
2293 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
2294 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
2295 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
2296 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
Ronald Cron4153ebb2024-09-11 15:32:48 +02002297 # Note: The two unsets below are to be removed for Mbed TLS 4.0
Ronald Cron54d1eec2024-09-06 09:55:38 +02002298 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2299 scripts/config.py unset MBEDTLS_DES_C
2300
Minos Galanakis471b34c2024-07-26 15:39:24 +01002301 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002302 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002303 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2304 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2305}
2306
Minos Galanakisf78447f2024-07-26 20:49:51 +01002307component_test_sha3_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002308 msg "sha3 loop unroll variations"
2309
2310 # define minimal config sufficient to test SHA3
Ronald Crone7f289e2024-09-06 11:02:47 +02002311 cat > include/mbedtls/mbedtls_config.h << END
2312 #define MBEDTLS_AES_C
2313 #define MBEDTLS_CTR_DRBG_C
2314 #define MBEDTLS_ENTROPY_C
2315 #define MBEDTLS_PSA_CRYPTO_C
2316 #define MBEDTLS_PSA_CRYPTO_CONFIG
2317 #define MBEDTLS_SELF_TEST
2318END
2319
2320 cat > tf-psa-crypto/include/psa/crypto_config.h << END
2321 #define PSA_WANT_ALG_SHA_256 1
2322 #define PSA_WANT_ALG_SHA3_224 1
2323 #define PSA_WANT_ALG_SHA3_256 1
2324 #define PSA_WANT_ALG_SHA3_384 1
2325 #define PSA_WANT_ALG_SHA3_512 1
Minos Galanakis471b34c2024-07-26 15:39:24 +01002326END
2327
2328 msg "all loops unrolled"
2329 make clean
2330 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"
2331 ./tf-psa-crypto/tests/test_suite_shax
2332
2333 msg "all loops rolled up"
2334 make clean
2335 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"
2336 ./tf-psa-crypto/tests/test_suite_shax
2337}
2338
Minos Galanakisf699d512024-08-01 11:32:30 +01002339support_build_aes_aesce_armcc () {
2340 support_build_armcc
2341}
2342
Minos Galanakis471b34c2024-07-26 15:39:24 +01002343# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2344component_build_aes_aesce_armcc () {
2345 msg "Build: AESCE test on arm64 platform without plain C."
2346 scripts/config.py baremetal
2347
2348 # armc[56] don't support SHA-512 intrinsics
2349 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2350
2351 # Stop armclang warning about feature detection for A64_CRYPTO.
2352 # With this enabled, the library does build correctly under armclang,
2353 # but in baremetal builds (as tested here), feature detection is
2354 # unavailable, and the user is notified via a #warning. So enabling
2355 # this feature would prevent us from building with -Werror on
2356 # armclang. Tracked in #7198.
2357 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2358 scripts/config.py set MBEDTLS_HAVE_ASM
2359
2360 msg "AESCE, build with default configuration."
2361 scripts/config.py set MBEDTLS_AESCE_C
2362 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002363 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002364
2365 msg "AESCE, build AESCE only"
2366 scripts/config.py set MBEDTLS_AESCE_C
2367 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002368 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002369}
2370
Minos Galanakis471b34c2024-07-26 15:39:24 +01002371component_test_aes_only_128_bit_keys () {
2372 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2373 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2374
2375 make CFLAGS='-O2 -Werror -Wall -Wextra'
2376
2377 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2378 make test
2379}
2380
2381component_test_no_ctr_drbg_aes_only_128_bit_keys () {
2382 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2383 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2384 scripts/config.py unset MBEDTLS_CTR_DRBG_C
2385
2386 make CC=clang CFLAGS='-Werror -Wall -Wextra'
2387
2388 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2389 make test
2390}
2391
2392component_test_aes_only_128_bit_keys_have_builtins () {
2393 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2394 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2395 scripts/config.py unset MBEDTLS_AESNI_C
2396 scripts/config.py unset MBEDTLS_AESCE_C
2397
2398 make CFLAGS='-O2 -Werror -Wall -Wextra'
2399
2400 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2401 make test
2402
2403 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2404 programs/test/selftest
2405}
2406
2407component_test_gcm_largetable () {
2408 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2409 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
2410 scripts/config.py unset MBEDTLS_AESNI_C
2411 scripts/config.py unset MBEDTLS_AESCE_C
2412
2413 make CFLAGS='-O2 -Werror -Wall -Wextra'
2414
2415 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2416 make test
2417}
2418
2419component_test_aes_fewer_tables () {
2420 msg "build: default config with AES_FEWER_TABLES enabled"
2421 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2422 make CFLAGS='-O2 -Werror -Wall -Wextra'
2423
2424 msg "test: AES_FEWER_TABLES"
2425 make test
2426}
2427
2428component_test_aes_rom_tables () {
2429 msg "build: default config with AES_ROM_TABLES enabled"
2430 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2431 make CFLAGS='-O2 -Werror -Wall -Wextra'
2432
2433 msg "test: AES_ROM_TABLES"
2434 make test
2435}
2436
2437component_test_aes_fewer_tables_and_rom_tables () {
2438 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
2439 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2440 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2441 make CFLAGS='-O2 -Werror -Wall -Wextra'
2442
2443 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2444 make test
2445}
2446
Ronald Cron66040472024-09-06 10:14:38 +02002447# helper for component_test_block_cipher_no_decrypt_aesni() which:
Minos Galanakis471b34c2024-07-26 15:39:24 +01002448# - enable/disable the list of config options passed from -s/-u respectively.
2449# - build
2450# - test for tests_suite_xxx
2451# - selftest
2452#
2453# Usage: helper_block_cipher_no_decrypt_build_test
2454# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
2455# Options: -s set_opts the list of config options to enable
2456# -u unset_opts the list of config options to disable
2457# -c cflags the list of options passed to CFLAGS
2458# -l ldflags the list of options passed to LDFLAGS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002459helper_block_cipher_no_decrypt_build_test () {
2460 while [ $# -gt 0 ]; do
2461 case "$1" in
2462 -s)
2463 shift; local set_opts="$1";;
2464 -u)
2465 shift; local unset_opts="$1";;
2466 -c)
2467 shift; local cflags="-Werror -Wall -Wextra $1";;
2468 -l)
2469 shift; local ldflags="$1";;
2470 esac
2471 shift
2472 done
2473 set_opts="${set_opts:-}"
2474 unset_opts="${unset_opts:-}"
2475 cflags="${cflags:-}"
2476 ldflags="${ldflags:-}"
2477
2478 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
2479 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
2480
2481 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2482 make clean
2483 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
2484
2485 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2486 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2487 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2488 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2489 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2490 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2491 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
2492 not grep mbedtls_aesni_inverse_key ${BUILTIN_SRC_PATH}/aesni.o
2493
2494 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2495 make test
2496
2497 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2498 programs/test/selftest
2499}
2500
Ronald Cron66040472024-09-06 10:14:38 +02002501# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
2502config_block_cipher_no_decrypt () {
2503 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
2504 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2505 scripts/config.py unset MBEDTLS_NIST_KW_C
2506
2507 # Enable support for cryptographic mechanisms through the PSA API.
2508 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
2509 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2510 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
2511 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
2512 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
2513 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
Ronald Cron4153ebb2024-09-11 15:32:48 +02002514 # Note: The two unsets below are to be removed for Mbed TLS 4.0
Ronald Cron66040472024-09-06 10:14:38 +02002515 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2516 scripts/config.py unset MBEDTLS_DES_C
2517}
2518
2519component_test_block_cipher_no_decrypt_aesni () {
2520 # Test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics, AESNI assembly and
2521 # AES C implementation on x86_64 and with AESNI intrinsics on x86.
2522
2523 # This consistently causes an llvm crash on clang 3.8, so use gcc
2524 export CC=gcc
2525 config_block_cipher_no_decrypt
2526
Minos Galanakis471b34c2024-07-26 15:39:24 +01002527 # test AESNI intrinsics
2528 helper_block_cipher_no_decrypt_build_test \
2529 -s "MBEDTLS_AESNI_C" \
2530 -c "-mpclmul -msse2 -maes"
2531
2532 # test AESNI assembly
2533 helper_block_cipher_no_decrypt_build_test \
2534 -s "MBEDTLS_AESNI_C" \
2535 -c "-mno-pclmul -mno-sse2 -mno-aes"
2536
2537 # test AES C implementation
2538 helper_block_cipher_no_decrypt_build_test \
2539 -u "MBEDTLS_AESNI_C"
2540
2541 # test AESNI intrinsics for i386 target
2542 helper_block_cipher_no_decrypt_build_test \
2543 -s "MBEDTLS_AESNI_C" \
2544 -c "-m32 -mpclmul -msse2 -maes" \
2545 -l "-m32"
2546}
2547
Minos Galanakisf699d512024-08-01 11:32:30 +01002548support_test_block_cipher_no_decrypt_aesce_armcc () {
2549 support_build_armcc
2550}
2551
Minos Galanakis471b34c2024-07-26 15:39:24 +01002552component_test_block_cipher_no_decrypt_aesce_armcc () {
2553 scripts/config.py baremetal
2554
2555 # armc[56] don't support SHA-512 intrinsics
2556 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2557
2558 # Stop armclang warning about feature detection for A64_CRYPTO.
2559 # With this enabled, the library does build correctly under armclang,
2560 # but in baremetal builds (as tested here), feature detection is
2561 # unavailable, and the user is notified via a #warning. So enabling
2562 # this feature would prevent us from building with -Werror on
2563 # armclang. Tracked in #7198.
2564 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2565 scripts/config.py set MBEDTLS_HAVE_ASM
2566
Ronald Cron66040472024-09-06 10:14:38 +02002567 config_block_cipher_no_decrypt
Minos Galanakis471b34c2024-07-26 15:39:24 +01002568
2569 # test AESCE baremetal build
2570 scripts/config.py set MBEDTLS_AESCE_C
2571 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
Manuel Pégourié-Gonnard8f08bcd2024-10-01 13:01:54 +02002572 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002573
2574 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2575 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2576 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2577 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2578 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2579 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2580 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
2581 not grep mbedtls_aesce_inverse_key ${BUILTIN_SRC_PATH}/aesce.o
2582 not grep aesce_decrypt_block ${BUILTIN_SRC_PATH}/aesce.o
2583}
2584
2585component_test_ctr_drbg_aes_256_sha_256 () {
2586 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2587 scripts/config.py full
2588 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2589 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
2590 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2591 make
2592
2593 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2594 make test
2595}
2596
2597component_test_ctr_drbg_aes_128_sha_512 () {
2598 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2599 scripts/config.py full
2600 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2601 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2602 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2603 make
2604
2605 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2606 make test
2607}
2608
2609component_test_ctr_drbg_aes_128_sha_256 () {
2610 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2611 scripts/config.py full
2612 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2613 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2614 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
2615 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2616 make
2617
2618 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2619 make test
2620}
2621
2622component_test_se_default () {
2623 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2624 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
2625 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
2626
2627 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2628 make test
2629}
2630
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002631component_test_full_static_keystore () {
2632 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2633 scripts/config.py full
2634 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2635 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
2636
2637 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2638 make test
2639}
2640
Minos Galanakis471b34c2024-07-26 15:39:24 +01002641component_test_psa_crypto_drivers () {
Ronald Crona0afbfb2024-10-15 13:20:31 +02002642 # Test dispatch to drivers and fallbacks with
2643 # test_suite_psa_crypto_driver_wrappers test suite. The test drivers that
2644 # are wrappers around the builtin drivers are activated by
2645 # PSA_CRYPTO_DRIVER_TEST.
2646 #
2647 # For the time being, some test cases in test_suite_block_cipher and
2648 # test_suite_md.psa rely on this component to be run at least once by the
2649 # CI. This should disappear as we progress the 4.x work. See
2650 # config_adjust_test_accelerators.h for more information.
Minos Galanakis471b34c2024-07-26 15:39:24 +01002651 msg "build: full + test drivers dispatching to builtins"
2652 scripts/config.py full
Ronald Cron67cc6a72024-10-14 10:55:24 +02002653 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_CONFIG_ADJUST_TEST_ACCELERATORS"
Ronald Cronede04b32024-10-16 10:47:15 +02002654 loc_cflags="${loc_cflags} -I../tests/include"
Minos Galanakis471b34c2024-07-26 15:39:24 +01002655
2656 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
2657
2658 msg "test: full + test drivers dispatching to builtins"
2659 make test
2660}
2661
2662component_build_psa_config_file () {
2663 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
2664 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2665 cp "$CRYPTO_CONFIG_H" psa_test_config.h
2666 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
2667 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
2668 # Make sure this feature is enabled. We'll disable it in the next phase.
2669 programs/test/query_compile_time_config MBEDTLS_CMAC_C
2670 make clean
2671
2672 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
2673 # In the user config, disable one feature and its dependencies, which will
2674 # reflect on the mbedtls configuration so we can query it with
2675 # query_compile_time_config.
2676 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
2677 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
2678 scripts/config.py unset MBEDTLS_CMAC_C
2679 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
2680 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
2681
2682 rm -f psa_test_config.h psa_user_config.h
2683}
2684
2685component_build_psa_alt_headers () {
2686 msg "build: make with PSA alt headers" # ~20s
2687
2688 # Generate alternative versions of the substitutable headers with the
2689 # same content except different include guards.
2690 make -C tests include/alt-extra/psa/crypto_platform_alt.h include/alt-extra/psa/crypto_struct_alt.h
2691
2692 # Build the library and some programs.
2693 # Don't build the fuzzers to avoid having to go through hoops to set
2694 # a correct include path for programs/fuzz/Makefile.
2695 make CFLAGS="-I ../tests/include/alt-extra -DMBEDTLS_PSA_CRYPTO_PLATFORM_FILE='\"psa/crypto_platform_alt.h\"' -DMBEDTLS_PSA_CRYPTO_STRUCT_FILE='\"psa/crypto_struct_alt.h\"'" lib
2696 make -C programs -o fuzz CFLAGS="-I ../tests/include/alt-extra -DMBEDTLS_PSA_CRYPTO_PLATFORM_FILE='\"psa/crypto_platform_alt.h\"' -DMBEDTLS_PSA_CRYPTO_STRUCT_FILE='\"psa/crypto_struct_alt.h\"'"
2697
2698 # Check that we're getting the alternative include guards and not the
2699 # original include guards.
2700 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
2701 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
2702 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
2703 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
2704}
2705
2706component_test_min_mpi_window_size () {
2707 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
2708 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
2709 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2710 make
2711
2712 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2713 make test
2714}