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