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