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