blob: 11a37059c337ea88c8a65ee140e8ec71a1cb4e9d [file] [log] [blame]
Minos Galanakis77711192024-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
6# This file contains test components that are executed by all.sh
7
8################################################################
9#### Configuration Testing - Crypto
10################################################################
Minos Galanakis3ece57e2024-08-01 17:09:49 +010011
12component_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 Setti168d24a2024-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 Settiba98d5b2024-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 Setti92f1d2d2024-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 Setti168d24a2024-06-20 14:40:54 +020048
Valerio Settibc611712024-08-13 13:13:23 +020049 msg "test: crypto full + MBEDTLS_PSA_STATIC_KEY_SLOTS"
Valerio Setti291532f2024-08-14 06:37:02 +020050 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" test
Valerio Setti168d24a2024-06-20 14:40:54 +020051}
52
Minos Galanakis3ece57e2024-08-01 17:09:49 +010053# check_renamed_symbols HEADER LIB
54# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
55# name in LIB.
56check_renamed_symbols () {
57 ! nm "$2" | sed 's/.* //' |
58 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
59}
60
61component_build_psa_crypto_spm () {
62 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
63 scripts/config.py full
64 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
65 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
66 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
67 # We can only compile, not link, since our test and sample programs
68 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
69 # is active.
David Horstmanndcf42a02024-11-08 14:40:12 +000070 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' lib
Minos Galanakis3ece57e2024-08-01 17:09:49 +010071
72 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
73 # version is not present.
74 echo "Checking for renamed symbols in the library"
David Horstmanndcf42a02024-11-08 14:40:12 +000075 check_renamed_symbols framework/tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Minos Galanakis3ece57e2024-08-01 17:09:49 +010076}
77
Valerio Settiefce6052024-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 Settibc611712024-08-13 13:13:23 +020082 msg "crypto without heap: build libtestdriver1"
Valerio Settiefce6052024-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 Settibc611712024-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 Settiefce6052024-06-25 18:31:36 +020089 # RSA key support requires ASN1 parse/write support for testing, but ASN1
90 # is disabled below.
Valerio Settibc611712024-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 Settiefce6052024-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 Settiefce6052024-06-25 18:31:36 +0200103 helper_libtestdriver1_adjust_config crypto
104 helper_libtestdriver1_make_drivers "$loc_accel_list"
105
Valerio Settibc611712024-08-13 13:13:23 +0200106 msg "crypto without heap: build main library"
Valerio Settif7485fb2024-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 Settiefce6052024-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 Settif7485fb2024-08-13 13:36:50 +0200114 # Prevent PSA core from creating a copy of input/output buffers.
Valerio Settiefce6052024-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 Settibc611712024-08-13 13:13:23 +0200118 # Set calloc/free as null pointer functions. Calling them would crash
Valerio Settiefce6052024-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 Settif7485fb2024-08-13 13:36:50 +0200121 scripts/config.py set MBEDTLS_PLATFORM_C
Valerio Settiefce6052024-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 Settiefce6052024-06-25 18:31:36 +0200126 helper_libtestdriver1_make_main "$loc_accel_list" lib
127
Valerio Settibc611712024-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 Settiefce6052024-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 Settibc611712024-08-13 13:13:23 +0200136 msg "crypto without heap: test"
Valerio Settiefce6052024-06-25 18:31:36 +0200137 make test
138}
139
Minos Galanakis0c0c3e12024-08-01 22:59:12 +0100140# Get a list of library-wise undefined symbols and ensure that they only
141# belong to psa_xxx() functions and not to mbedtls_yyy() ones.
142# This function is a common helper used by both:
143# - component_test_default_psa_crypto_client_without_crypto_provider
144# - component_build_full_psa_crypto_client_without_crypto_provider.
145common_check_mbedtls_missing_symbols () {
146 nm library/libmbedcrypto.a | grep ' [TRrDC] ' | grep -Eo '(mbedtls_|psa_).*' | sort -u > sym_def.txt
147 nm library/libmbedcrypto.a | grep ' U ' | grep -Eo '(mbedtls_|psa_).*' | sort -u > sym_undef.txt
148 comm sym_def.txt sym_undef.txt -13 > linking_errors.txt
149 not grep mbedtls_ linking_errors.txt
150
151 rm sym_def.txt sym_undef.txt linking_errors.txt
152}
153
154component_test_default_psa_crypto_client_without_crypto_provider () {
155 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
156
157 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
158 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
159 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
160 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
161 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
162 scripts/config.py unset MBEDTLS_LMS_C
David Horstmanncbf530d2024-11-12 14:18:37 +0000163 # Test hooks may rely on functions defined in test helpers, which would
164 # not be built here, leading to a spurious undefined symbol.
165 scripts/config.py unset MBEDTLS_TEST_HOOKS
Minos Galanakis0c0c3e12024-08-01 22:59:12 +0100166
167 make
168
169 msg "check missing symbols: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
170 common_check_mbedtls_missing_symbols
171
172 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
173 make test
174}
175
176component_build_full_psa_crypto_client_without_crypto_provider () {
177 msg "build: full config - PSA_CRYPTO_C"
178
179 # Use full config which includes USE_PSA and CRYPTO_CLIENT.
180 scripts/config.py full
181
182 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
183 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
184 # Dynamic secure element support is a deprecated feature and it is not
185 # available when CRYPTO_C and PSA_CRYPTO_STORAGE_C are disabled.
186 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
David Horstmanncbf530d2024-11-12 14:18:37 +0000187 # Test hooks may rely on functions defined in test helpers, which would
188 # not be built here, leading to a spurious undefined symbol.
189 scripts/config.py unset MBEDTLS_TEST_HOOKS
Minos Galanakis0c0c3e12024-08-01 22:59:12 +0100190
191 # Since there is no crypto provider in this build it is not possible to
192 # build all the test executables and progrems due to missing PSA functions
193 # at link time. Therefore we will just build libraries and we'll check
194 # that symbols of interest are there.
195 make lib
196
197 msg "check missing symbols: full config - PSA_CRYPTO_C"
198
199 common_check_mbedtls_missing_symbols
200
201 # Ensure that desired functions are included into the build (extend the
202 # following list as required).
203 grep mbedtls_pk_get_psa_attributes library/libmbedcrypto.a
204 grep mbedtls_pk_import_into_psa library/libmbedcrypto.a
205 grep mbedtls_pk_copy_from_psa library/libmbedcrypto.a
206}
207
208component_test_psa_crypto_rsa_no_genprime () {
209 msg "build: default config minus MBEDTLS_GENPRIME"
210 scripts/config.py unset MBEDTLS_GENPRIME
211 make
212
213 msg "test: default config minus MBEDTLS_GENPRIME"
214 make test
215}
216
Minos Galanakis3ece57e2024-08-01 17:09:49 +0100217component_test_no_pem_no_fs () {
218 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
219 scripts/config.py unset MBEDTLS_PEM_PARSE_C
220 scripts/config.py unset MBEDTLS_FS_IO
221 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
222 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
223 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
224 make
225
226 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
227 make test
228
229 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
230 tests/ssl-opt.sh
231}
232
233component_test_rsa_no_crt () {
234 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
235 scripts/config.py set MBEDTLS_RSA_NO_CRT
236 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
237 make
238
239 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
240 make test
241
242 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
243 tests/ssl-opt.sh -f RSA
244
245 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
246 tests/compat.sh -t RSA
247
248 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
249 tests/context-info.sh
250}
251
Gilles Peskine4d347aa2024-09-19 18:55:08 +0200252component_test_config_no_entropy () {
253 msg "build: configs/config-no-entropy.h"
254 cp configs/config-no-entropy.h "$CONFIG_H"
255 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
256 # want to re-generate generated files that depend on it, quite correctly.
257 # However this doesn't work as the generation script expects a specific
258 # format for mbedtls_config.h, which the other files don't follow. Also,
259 # cmake can't know this, but re-generation is actually not necessary as
260 # the generated files only depend on the list of available options, not
261 # whether they're on or off. So, disable cmake's (over-sensitive here)
262 # dependency resolution for generated files and just rely on them being
263 # present (thanks to pre_generate_files) by turning GEN_FILES off.
264 CC=$ASAN_CC cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
265 make
266
267 msg "test: configs/config-no-entropy.h - unit tests"
268 make test
269}
270
Minos Galanakis3ece57e2024-08-01 17:09:49 +0100271component_test_no_ctr_drbg_classic () {
272 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
273 scripts/config.py full
274 scripts/config.py unset MBEDTLS_CTR_DRBG_C
275 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
276 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
277
278 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
279 make
280
281 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
282 make test
283
284 # In this configuration, the TLS test programs use HMAC_DRBG.
285 # The SSL tests are slow, so run a small subset, just enough to get
286 # confidence that the SSL code copes with HMAC_DRBG.
287 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
288 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
289
290 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
291 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
292}
293
294component_test_no_ctr_drbg_use_psa () {
295 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
296 scripts/config.py full
297 scripts/config.py unset MBEDTLS_CTR_DRBG_C
298 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
299
300 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
301 make
302
303 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
304 make test
305
306 # In this configuration, the TLS test programs use HMAC_DRBG.
307 # The SSL tests are slow, so run a small subset, just enough to get
308 # confidence that the SSL code copes with HMAC_DRBG.
309 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
310 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
311
312 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
313 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
314}
315
316component_test_no_hmac_drbg_classic () {
317 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
318 scripts/config.py full
319 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
320 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
321 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
322 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
323
324 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
325 make
326
327 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
328 make test
329
330 # Normally our ECDSA implementation uses deterministic ECDSA. But since
331 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
332 # instead.
333 # Test SSL with non-deterministic ECDSA. Only test features that
334 # might be affected by how ECDSA signature is performed.
335 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
336 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
337
338 # To save time, only test one protocol version, since this part of
339 # the protocol is identical in (D)TLS up to 1.2.
340 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
341 tests/compat.sh -m tls12 -t 'ECDSA'
342}
343
344component_test_no_hmac_drbg_use_psa () {
345 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
346 scripts/config.py full
347 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
348 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
349 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
350
351 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
352 make
353
354 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
355 make test
356
357 # Normally our ECDSA implementation uses deterministic ECDSA. But since
358 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
359 # instead.
360 # Test SSL with non-deterministic ECDSA. Only test features that
361 # might be affected by how ECDSA signature is performed.
362 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
363 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
364
365 # To save time, only test one protocol version, since this part of
366 # the protocol is identical in (D)TLS up to 1.2.
367 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
368 tests/compat.sh -m tls12 -t 'ECDSA'
369}
370
371component_test_psa_external_rng_no_drbg_classic () {
372 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
373 scripts/config.py full
374 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
375 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
376 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
377 scripts/config.py unset MBEDTLS_ENTROPY_C
378 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
379 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
380 scripts/config.py unset MBEDTLS_CTR_DRBG_C
381 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
382 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
383 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
384 # the SSL test programs don't have an RNG and can't work. Explicitly
385 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
386 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
387
388 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
389 make test
390
391 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
392 tests/ssl-opt.sh -f 'Default'
393}
394
395component_test_psa_external_rng_no_drbg_use_psa () {
396 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
397 scripts/config.py full
398 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
399 scripts/config.py unset MBEDTLS_ENTROPY_C
400 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
401 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
402 scripts/config.py unset MBEDTLS_CTR_DRBG_C
403 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
404 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
405 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
406
407 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
408 make test
409
410 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
411 tests/ssl-opt.sh -f 'Default\|opaque'
412}
413
414component_test_psa_external_rng_use_psa_crypto () {
415 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
416 scripts/config.py full
417 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
418 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
419 scripts/config.py unset MBEDTLS_CTR_DRBG_C
420 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
421
422 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
423 make test
424
425 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
426 tests/ssl-opt.sh -f 'Default\|opaque'
427}
428
Gilles Peskinebd6fb462025-06-06 10:18:36 +0200429component_test_entropy_nv_seed_only () {
Gilles Peskine361799a2025-06-06 14:51:54 +0200430 msg "build: full minus platform entropy (NV seed only)"
Gilles Peskinebd6fb462025-06-06 10:18:36 +0200431 scripts/config.py full
432 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY
433 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
434
Gilles Peskine361799a2025-06-06 14:51:54 +0200435 msg "build: full minus platform entropy (NV seed only)"
Gilles Peskinebd6fb462025-06-06 10:18:36 +0200436 make test
437
438 # Check that the library seems to refer to the seedfile, but not to
439 # platform entropy sources.
440 grep seedfile library/platform.o
441 not grep getrandom library/entropy*.o
442 not grep /dev/random library/entropy*.o
443 not grep /dev/.random library/entropy*.o
444}
445
Minos Galanakis3ece57e2024-08-01 17:09:49 +0100446component_test_psa_inject_entropy () {
447 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
448 scripts/config.py full
449 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
450 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
451 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
452 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
453 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
454 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
455 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
456
457 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
458 make test
459}
460
461component_full_no_pkparse_pkwrite () {
462 msg "build: full without pkparse and pkwrite"
463
464 scripts/config.py crypto_full
465 scripts/config.py unset MBEDTLS_PK_PARSE_C
466 scripts/config.py unset MBEDTLS_PK_WRITE_C
467
468 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
469
470 # Ensure that PK_[PARSE|WRITE]_C were not re-enabled accidentally (additive config).
471 not grep mbedtls_pk_parse_key library/pkparse.o
472 not grep mbedtls_pk_write_key_der library/pkwrite.o
473
474 msg "test: full without pkparse and pkwrite"
475 make test
476}
477
478component_test_crypto_full_md_light_only () {
479 msg "build: crypto_full with only the light subset of MD"
480 scripts/config.py crypto_full
481 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
482 # Disable MD
483 scripts/config.py unset MBEDTLS_MD_C
484 # Disable direct dependencies of MD_C
485 scripts/config.py unset MBEDTLS_HKDF_C
486 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
487 scripts/config.py unset MBEDTLS_PKCS7_C
488 # Disable indirect dependencies of MD_C
489 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG
490 # Disable things that would auto-enable MD_C
491 scripts/config.py unset MBEDTLS_PKCS5_C
492
493 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
494 # which we haven't disabled, so no need to explicitly enable it.
495 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
496
497 # Make sure we don't have the HMAC functions, but the hashing functions
498 not grep mbedtls_md_hmac library/md.o
499 grep mbedtls_md library/md.o
500
501 msg "test: crypto_full with only the light subset of MD"
502 make test
503}
504
Minos Galanakis0c0c3e12024-08-01 22:59:12 +0100505component_test_full_no_cipher_no_psa_crypto () {
506 msg "build: full no CIPHER no PSA_CRYPTO_C"
507 scripts/config.py full
508 scripts/config.py unset MBEDTLS_CIPHER_C
509 # Don't pull in cipher via PSA mechanisms
510 # (currently ignored anyway because we completely disable PSA)
511 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
512 # Disable features that depend on CIPHER_C
513 scripts/config.py unset MBEDTLS_CMAC_C
514 scripts/config.py unset MBEDTLS_NIST_KW_C
515 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
516 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CLIENT
517 scripts/config.py unset MBEDTLS_SSL_TLS_C
518 scripts/config.py unset MBEDTLS_SSL_TICKET_C
519 # Disable features that depend on PSA_CRYPTO_C
520 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
521 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
522 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
523 scripts/config.py unset MBEDTLS_LMS_C
524 scripts/config.py unset MBEDTLS_LMS_PRIVATE
525
526 msg "test: full no CIPHER no PSA_CRYPTO_C"
527 make test
528}
529
530# This is a common configurator and test function that is used in:
531# - component_test_full_no_cipher_with_psa_crypto
532# - component_test_full_no_cipher_with_psa_crypto_config
533# It accepts 2 input parameters:
534# - $1: boolean value which basically reflects status of MBEDTLS_PSA_CRYPTO_CONFIG
535# - $2: a text string which describes the test component
536common_test_full_no_cipher_with_psa_crypto () {
537 USE_CRYPTO_CONFIG="$1"
538 COMPONENT_DESCRIPTION="$2"
539
540 msg "build: $COMPONENT_DESCRIPTION"
541
542 scripts/config.py full
543 scripts/config.py unset MBEDTLS_CIPHER_C
544
545 if [ "$USE_CRYPTO_CONFIG" -eq 1 ]; then
546 # The built-in implementation of the following algs/key-types depends
547 # on CIPHER_C so we disable them.
548 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
549 # so we keep them enabled.
550 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
551 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CMAC
552 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
553 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
554 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CFB
555 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CTR
556 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
557 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_OFB
558 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
559 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_STREAM_CIPHER
560 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
561 else
562 # Don't pull in cipher via PSA mechanisms
563 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
564 # Disable cipher modes/keys that make PSA depend on CIPHER_C.
565 # Keep CHACHA20 and CHACHAPOLY enabled since they do not depend on CIPHER_C.
566 scripts/config.py unset-all MBEDTLS_CIPHER_MODE
567 fi
568 # The following modules directly depends on CIPHER_C
569 scripts/config.py unset MBEDTLS_CMAC_C
570 scripts/config.py unset MBEDTLS_NIST_KW_C
571
572 make
573
574 # Ensure that CIPHER_C was not re-enabled
575 not grep mbedtls_cipher_init library/cipher.o
576
577 msg "test: $COMPONENT_DESCRIPTION"
578 make test
579}
580
581component_test_full_no_cipher_with_psa_crypto () {
582 common_test_full_no_cipher_with_psa_crypto 0 "full no CIPHER no CRYPTO_CONFIG"
583}
584
585component_test_full_no_cipher_with_psa_crypto_config () {
586 common_test_full_no_cipher_with_psa_crypto 1 "full no CIPHER"
587}
588
Minos Galanakis3ece57e2024-08-01 17:09:49 +0100589component_test_full_no_ccm () {
590 msg "build: full no PSA_WANT_ALG_CCM"
591
592 # Full config enables:
593 # - USE_PSA_CRYPTO so that TLS code dispatches cipher/AEAD to PSA
594 # - CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
595 scripts/config.py full
596
597 # Disable PSA_WANT_ALG_CCM so that CCM is not supported in PSA. CCM_C is still
598 # enabled, but not used from TLS since USE_PSA is set.
599 # This is helpful to ensure that TLS tests below have proper dependencies.
600 #
601 # Note: also PSA_WANT_ALG_CCM_STAR_NO_TAG is enabled, but it does not cause
602 # PSA_WANT_ALG_CCM to be re-enabled.
603 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM
604
605 make
606
607 msg "test: full no PSA_WANT_ALG_CCM"
608 make test
609}
610
611component_test_full_no_ccm_star_no_tag () {
612 msg "build: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
613
614 # Full config enables CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
615 scripts/config.py full
616
617 # Disable CCM_STAR_NO_TAG, which is the target of this test, as well as all
618 # other components that enable MBEDTLS_PSA_BUILTIN_CIPHER internal symbol.
619 # This basically disables all unauthenticated ciphers on the PSA side, while
620 # keeping AEADs enabled.
621 #
622 # Note: PSA_WANT_ALG_CCM is enabled, but it does not cause
623 # PSA_WANT_ALG_CCM_STAR_NO_TAG to be re-enabled.
624 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
625 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_STREAM_CIPHER
626 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
627 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
628 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
629 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
630 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
631 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
632
633 make
634
635 # Ensure MBEDTLS_PSA_BUILTIN_CIPHER was not enabled
636 not grep mbedtls_psa_cipher library/psa_crypto_cipher.o
637
638 msg "test: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
639 make test
640}
641
Gilles Peskinedbd0f422024-09-14 11:27:44 +0200642component_test_config_symmetric_only_legacy () {
643 msg "build: configs/config-symmetric-only.h"
644 cp configs/config-symmetric-only.h "$CONFIG_H"
645 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
646 # want to re-generate generated files that depend on it, quite correctly.
647 # However this doesn't work as the generation script expects a specific
648 # format for mbedtls_config.h, which the other files don't follow. Also,
649 # cmake can't know this, but re-generation is actually not necessary as
650 # the generated files only depend on the list of available options, not
651 # whether they're on or off. So, disable cmake's (over-sensitive here)
652 # dependency resolution for generated files and just rely on them being
653 # present (thanks to pre_generate_files) by turning GEN_FILES off.
654 CC=$ASAN_CC cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
655 make
656
657 msg "test: configs/config-symmetric-only.h - unit tests"
658 make test
659}
660
661component_test_config_symmetric_only_psa () {
662 msg "build: configs/config-symmetric-only.h + USE_PSA_CRYPTO"
663 cp configs/config-symmetric-only.h "$CONFIG_H"
664 scripts/config.py set MBEDTLS_PSA_CRYPTO_C
665 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
666 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
667 # want to re-generate generated files that depend on it, quite correctly.
668 # However this doesn't work as the generation script expects a specific
669 # format for mbedtls_config.h, which the other files don't follow. Also,
670 # cmake can't know this, but re-generation is actually not necessary as
671 # the generated files only depend on the list of available options, not
672 # whether they're on or off. So, disable cmake's (over-sensitive here)
673 # dependency resolution for generated files and just rely on them being
674 # present (thanks to pre_generate_files) by turning GEN_FILES off.
675 CC=$ASAN_CC cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
676 make
677
678 msg "test: configs/config-symmetric-only.h + USE_PSA_CRYPTO - unit tests"
679 make test
680}
681
Minos Galanakis0c0c3e12024-08-01 22:59:12 +0100682component_test_full_no_bignum () {
683 msg "build: full minus bignum"
684 scripts/config.py full
685 scripts/config.py unset MBEDTLS_BIGNUM_C
686 # Direct dependencies of bignum
687 scripts/config.py unset MBEDTLS_ECP_C
688 scripts/config.py unset MBEDTLS_RSA_C
689 scripts/config.py unset MBEDTLS_DHM_C
690 # Direct dependencies of ECP
691 scripts/config.py unset MBEDTLS_ECDH_C
692 scripts/config.py unset MBEDTLS_ECDSA_C
693 scripts/config.py unset MBEDTLS_ECJPAKE_C
694 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
695 # Disable what auto-enables ECP_LIGHT
696 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
697 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
698 # Indirect dependencies of ECP
699 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
700 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
701 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
702 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
703 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
704 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
705 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
706 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
707 # Direct dependencies of DHM
708 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
709 # Direct dependencies of RSA
710 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
711 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
712 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
713 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
714 # PK and its dependencies
715 scripts/config.py unset MBEDTLS_PK_C
716 scripts/config.py unset MBEDTLS_PK_PARSE_C
717 scripts/config.py unset MBEDTLS_PK_WRITE_C
718 scripts/config.py unset MBEDTLS_X509_USE_C
719 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
720 scripts/config.py unset MBEDTLS_X509_CRL_PARSE_C
721 scripts/config.py unset MBEDTLS_X509_CSR_PARSE_C
722 scripts/config.py unset MBEDTLS_X509_CREATE_C
723 scripts/config.py unset MBEDTLS_X509_CRT_WRITE_C
724 scripts/config.py unset MBEDTLS_X509_CSR_WRITE_C
725 scripts/config.py unset MBEDTLS_PKCS7_C
726 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
727 scripts/config.py unset MBEDTLS_SSL_ASYNC_PRIVATE
728 scripts/config.py unset MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
729
730 make
731
732 msg "test: full minus bignum"
733 make test
734}
735
736component_build_dhm_alt () {
737 msg "build: MBEDTLS_DHM_ALT" # ~30s
738 scripts/config.py full
739 scripts/config.py set MBEDTLS_DHM_ALT
740 # debug.c currently references mbedtls_dhm_context fields directly.
741 scripts/config.py unset MBEDTLS_DEBUG_C
742 # We can only compile, not link, since we don't have any implementations
743 # suitable for testing with the dummy alt headers.
744 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
745}
746
Minos Galanakis3ece57e2024-08-01 17:09:49 +0100747component_test_everest () {
748 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
749 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
750 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
751 make
752
753 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
754 make test
755
756 msg "test: metatests (clang, ASan)"
757 tests/scripts/run-metatests.sh any asan poison
758
759 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
760 tests/ssl-opt.sh -f ECDH
761
762 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
763 # Exclude some symmetric ciphers that are redundant here to gain time.
764 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
765}
766
767component_test_everest_curve25519_only () {
768 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
769 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
770 scripts/config.py unset MBEDTLS_ECDSA_C
771 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
772 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
773 scripts/config.py unset MBEDTLS_ECJPAKE_C
774 # Disable all curves
775 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
776 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
777
778 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
779
780 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
781 make test
782}
783
784component_test_psa_collect_statuses () {
785 msg "build+test: psa_collect_statuses" # ~30s
786 scripts/config.py full
787 tests/scripts/psa_collect_statuses.py
788 # Check that psa_crypto_init() succeeded at least once
789 grep -q '^0:psa_crypto_init:' tests/statuses.log
790 rm -f tests/statuses.log
791}
792
793# Check that the specified libraries exist and are empty.
794are_empty_libraries () {
795 nm "$@" >/dev/null 2>/dev/null
796 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
797}
798
799component_build_crypto_default () {
800 msg "build: make, crypto only"
801 scripts/config.py crypto
802 make CFLAGS='-O1 -Werror'
803 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
804}
805
806component_build_crypto_full () {
807 msg "build: make, crypto only, full config"
808 scripts/config.py crypto_full
809 make CFLAGS='-O1 -Werror'
810 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
811}
812
813component_test_crypto_for_psa_service () {
814 msg "build: make, config for PSA crypto service"
815 scripts/config.py crypto
816 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
817 # Disable things that are not needed for just cryptography, to
818 # reach a configuration that would be typical for a PSA cryptography
819 # service providing all implemented PSA algorithms.
820 # System stuff
821 scripts/config.py unset MBEDTLS_ERROR_C
822 scripts/config.py unset MBEDTLS_TIMING_C
823 scripts/config.py unset MBEDTLS_VERSION_FEATURES
824 # Crypto stuff with no PSA interface
825 scripts/config.py unset MBEDTLS_BASE64_C
826 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
827 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
828 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
829 scripts/config.py unset MBEDTLS_NIST_KW_C
830 scripts/config.py unset MBEDTLS_PEM_PARSE_C
831 scripts/config.py unset MBEDTLS_PEM_WRITE_C
832 scripts/config.py unset MBEDTLS_PKCS12_C
833 scripts/config.py unset MBEDTLS_PKCS5_C
834 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
835 # in PSA code to work with RSA keys. We don't require users to set those:
836 # they will be reenabled in build_info.h.
837 scripts/config.py unset MBEDTLS_PK_C
838 scripts/config.py unset MBEDTLS_PK_PARSE_C
839 scripts/config.py unset MBEDTLS_PK_WRITE_C
840 make CFLAGS='-O1 -Werror' all test
841 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
842}
843
844component_build_crypto_baremetal () {
845 msg "build: make, crypto only, baremetal config"
846 scripts/config.py crypto_baremetal
David Horstmanndcf42a02024-11-08 14:40:12 +0000847 make CFLAGS="-O1 -Werror -I$PWD/framework/tests/include/baremetal-override/"
Minos Galanakis3ece57e2024-08-01 17:09:49 +0100848 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
849}
850
851support_build_crypto_baremetal () {
852 support_build_baremetal "$@"
853}
854
855# depends.py family of tests
856component_test_depends_py_cipher_id () {
857 msg "test/build: depends.py cipher_id (gcc)"
858 tests/scripts/depends.py cipher_id --unset-use-psa
859}
860
861component_test_depends_py_cipher_chaining () {
862 msg "test/build: depends.py cipher_chaining (gcc)"
863 tests/scripts/depends.py cipher_chaining --unset-use-psa
864}
865
866component_test_depends_py_cipher_padding () {
867 msg "test/build: depends.py cipher_padding (gcc)"
868 tests/scripts/depends.py cipher_padding --unset-use-psa
869}
870
871component_test_depends_py_curves () {
872 msg "test/build: depends.py curves (gcc)"
873 tests/scripts/depends.py curves --unset-use-psa
874}
875
876component_test_depends_py_hashes () {
877 msg "test/build: depends.py hashes (gcc)"
878 tests/scripts/depends.py hashes --unset-use-psa
879}
880
881component_test_depends_py_pkalgs () {
882 msg "test/build: depends.py pkalgs (gcc)"
883 tests/scripts/depends.py pkalgs --unset-use-psa
884}
885
886# PSA equivalents of the depends.py tests
887component_test_depends_py_cipher_id_psa () {
888 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
889 tests/scripts/depends.py cipher_id
890}
891
892component_test_depends_py_cipher_chaining_psa () {
893 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
894 tests/scripts/depends.py cipher_chaining
895}
896
897component_test_depends_py_cipher_padding_psa () {
898 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
899 tests/scripts/depends.py cipher_padding
900}
901
902component_test_depends_py_curves_psa () {
903 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
904 tests/scripts/depends.py curves
905}
906
907component_test_depends_py_hashes_psa () {
908 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
909 tests/scripts/depends.py hashes
910}
911
912component_test_depends_py_pkalgs_psa () {
913 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
914 tests/scripts/depends.py pkalgs
915}
916
917component_test_psa_crypto_config_ffdh_2048_only () {
918 msg "build: full config - only DH 2048"
919
920 scripts/config.py full
921
922 # Disable all DH groups other than 2048.
923 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_3072
924 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_4096
925 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_6144
926 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_8192
927
928 make CFLAGS="$ASAN_CFLAGS -Werror" LDFLAGS="$ASAN_CFLAGS"
929
930 msg "test: full config - only DH 2048"
931 make test
932
933 msg "ssl-opt: full config - only DH 2048"
934 tests/ssl-opt.sh -f "ffdh"
935}
936
937component_build_no_pk_rsa_alt_support () {
938 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
939
940 scripts/config.py full
941 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
942 scripts/config.py set MBEDTLS_RSA_C
943 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
944
945 # Only compile - this is primarily to test for compile issues
946 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
947}
948
949component_build_module_alt () {
950 msg "build: MBEDTLS_XXX_ALT" # ~30s
951 scripts/config.py full
952
953 # Disable options that are incompatible with some ALT implementations:
954 # aesni.c and padlock.c reference mbedtls_aes_context fields directly.
955 scripts/config.py unset MBEDTLS_AESNI_C
956 scripts/config.py unset MBEDTLS_PADLOCK_C
957 scripts/config.py unset MBEDTLS_AESCE_C
958 # MBEDTLS_ECP_RESTARTABLE is documented as incompatible.
959 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
960 # You can only have one threading implementation: alt or pthread, not both.
961 scripts/config.py unset MBEDTLS_THREADING_PTHREAD
962 # The SpecifiedECDomain parsing code accesses mbedtls_ecp_group fields
963 # directly and assumes the implementation works with partial groups.
964 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
965 # MBEDTLS_SHA256_*ALT can't be used with MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*
966 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
967 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
968 # MBEDTLS_SHA512_*ALT can't be used with MBEDTLS_SHA512_USE_A64_CRYPTO_*
969 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
970 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
971
972 # Enable all MBEDTLS_XXX_ALT for whole modules. Do not enable
973 # MBEDTLS_XXX_YYY_ALT which are for single functions.
974 scripts/config.py set-all 'MBEDTLS_([A-Z0-9]*|NIST_KW)_ALT'
975 scripts/config.py unset MBEDTLS_DHM_ALT #incompatible with MBEDTLS_DEBUG_C
976
977 # We can only compile, not link, since we don't have any implementations
978 # suitable for testing with the dummy alt headers.
979 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
980}
981
982component_test_psa_crypto_config_accel_ecdsa () {
983 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
984
985 # Algorithms and key types to accelerate
986 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
987 $(helper_get_psa_key_type_list "ECC") \
988 $(helper_get_psa_curve_list)"
989
990 # Configure
991 # ---------
992
993 # Start from default config (no USE_PSA) + TLS 1.3
994 helper_libtestdriver1_adjust_config "default"
995
996 # Disable the module that's accelerated
997 scripts/config.py unset MBEDTLS_ECDSA_C
998
999 # Disable things that depend on it
1000 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1001 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1002
1003 # Build
1004 # -----
1005
1006 # These hashes are needed for some ECDSA signature tests.
Elena Uziunaitefbab4f82024-09-12 14:58:52 +01001007 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001008 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1009
1010 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1011
1012 helper_libtestdriver1_make_main "$loc_accel_list"
1013
1014 # Make sure this was not re-enabled by accident (additive config)
1015 not grep mbedtls_ecdsa_ library/ecdsa.o
1016
1017 # Run the tests
1018 # -------------
1019
1020 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1021 make test
1022}
1023
1024component_test_psa_crypto_config_accel_ecdh () {
1025 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
1026
1027 # Algorithms and key types to accelerate
1028 loc_accel_list="ALG_ECDH \
1029 $(helper_get_psa_key_type_list "ECC") \
1030 $(helper_get_psa_curve_list)"
1031
1032 # Configure
1033 # ---------
1034
1035 # Start from default config (no USE_PSA)
1036 helper_libtestdriver1_adjust_config "default"
1037
1038 # Disable the module that's accelerated
1039 scripts/config.py unset MBEDTLS_ECDH_C
1040
1041 # Disable things that depend on it
1042 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1043 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1044 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1045 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1046 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1047
1048 # Build
1049 # -----
1050
1051 helper_libtestdriver1_make_drivers "$loc_accel_list"
1052
1053 helper_libtestdriver1_make_main "$loc_accel_list"
1054
1055 # Make sure this was not re-enabled by accident (additive config)
1056 not grep mbedtls_ecdh_ library/ecdh.o
1057
1058 # Run the tests
1059 # -------------
1060
1061 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
1062 make test
1063}
1064
1065component_test_psa_crypto_config_accel_ffdh () {
1066 msg "build: full with accelerated FFDH"
1067
1068 # Algorithms and key types to accelerate
1069 loc_accel_list="ALG_FFDH \
1070 $(helper_get_psa_key_type_list "DH") \
1071 $(helper_get_psa_dh_group_list)"
1072
1073 # Configure
1074 # ---------
1075
1076 # start with full (USE_PSA and TLS 1.3)
1077 helper_libtestdriver1_adjust_config "full"
1078
1079 # Disable the module that's accelerated
1080 scripts/config.py unset MBEDTLS_DHM_C
1081
1082 # Disable things that depend on it
1083 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1084 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1085
1086 # Build
1087 # -----
1088
1089 helper_libtestdriver1_make_drivers "$loc_accel_list"
1090
1091 helper_libtestdriver1_make_main "$loc_accel_list"
1092
1093 # Make sure this was not re-enabled by accident (additive config)
1094 not grep mbedtls_dhm_ library/dhm.o
1095
1096 # Run the tests
1097 # -------------
1098
1099 msg "test: full with accelerated FFDH"
1100 make test
1101
1102 msg "ssl-opt: full with accelerated FFDH alg"
1103 tests/ssl-opt.sh -f "ffdh"
1104}
1105
1106component_test_psa_crypto_config_reference_ffdh () {
1107 msg "build: full with non-accelerated FFDH"
1108
1109 # Start with full (USE_PSA and TLS 1.3)
1110 helper_libtestdriver1_adjust_config "full"
1111
1112 # Disable things that are not supported
1113 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1114 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1115 make
1116
1117 msg "test suites: full with non-accelerated FFDH alg"
1118 make test
1119
1120 msg "ssl-opt: full with non-accelerated FFDH alg"
1121 tests/ssl-opt.sh -f "ffdh"
1122}
1123
1124component_test_psa_crypto_config_accel_pake () {
1125 msg "build: full with accelerated PAKE"
1126
1127 loc_accel_list="ALG_JPAKE \
1128 $(helper_get_psa_key_type_list "ECC") \
1129 $(helper_get_psa_curve_list)"
1130
1131 # Configure
1132 # ---------
1133
1134 helper_libtestdriver1_adjust_config "full"
1135
1136 # Make built-in fallback not available
1137 scripts/config.py unset MBEDTLS_ECJPAKE_C
1138 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
1139
1140 # Build
1141 # -----
1142
1143 helper_libtestdriver1_make_drivers "$loc_accel_list"
1144
1145 helper_libtestdriver1_make_main "$loc_accel_list"
1146
1147 # Make sure this was not re-enabled by accident (additive config)
1148 not grep mbedtls_ecjpake_init library/ecjpake.o
1149
1150 # Run the tests
1151 # -------------
1152
1153 msg "test: full with accelerated PAKE"
1154 make test
1155}
1156
1157component_test_psa_crypto_config_accel_ecc_some_key_types () {
1158 msg "build: full with accelerated EC algs and some key types"
1159
1160 # Algorithms and key types to accelerate
1161 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
1162 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1163 ALG_ECDH \
1164 ALG_JPAKE \
1165 KEY_TYPE_ECC_PUBLIC_KEY \
1166 KEY_TYPE_ECC_KEY_PAIR_BASIC \
1167 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
1168 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
1169 $(helper_get_psa_curve_list)"
1170
1171 # Configure
1172 # ---------
1173
1174 # start with config full for maximum coverage (also enables USE_PSA)
1175 helper_libtestdriver1_adjust_config "full"
1176
1177 # Disable modules that are accelerated - some will be re-enabled
1178 scripts/config.py unset MBEDTLS_ECDSA_C
1179 scripts/config.py unset MBEDTLS_ECDH_C
1180 scripts/config.py unset MBEDTLS_ECJPAKE_C
1181 scripts/config.py unset MBEDTLS_ECP_C
1182
1183 # Disable all curves - those that aren't accelerated should be re-enabled
1184 helper_disable_builtin_curves
1185
1186 # Restartable feature is not yet supported by PSA. Once it will in
1187 # the future, the following line could be removed (see issues
1188 # 6061, 6332 and following ones)
1189 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1190
1191 # this is not supported by the driver API yet
1192 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1193
1194 # Build
1195 # -----
1196
1197 # These hashes are needed for some ECDSA signature tests.
1198 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1199 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1200 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1201
1202 helper_libtestdriver1_make_main "$loc_accel_list"
1203
1204 # ECP should be re-enabled but not the others
1205 not grep mbedtls_ecdh_ library/ecdh.o
1206 not grep mbedtls_ecdsa library/ecdsa.o
1207 not grep mbedtls_ecjpake library/ecjpake.o
1208 grep mbedtls_ecp library/ecp.o
1209
1210 # Run the tests
1211 # -------------
1212
1213 msg "test suites: full with accelerated EC algs and some key types"
1214 make test
1215}
1216
1217# Run tests with only (non-)Weierstrass accelerated
1218# Common code used in:
1219# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
1220# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
1221common_test_psa_crypto_config_accel_ecc_some_curves () {
1222 weierstrass=$1
1223 if [ $weierstrass -eq 1 ]; then
1224 desc="Weierstrass"
1225 else
1226 desc="non-Weierstrass"
1227 fi
1228
1229 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
1230
1231 # Note: Curves are handled in a special way by the libtestdriver machinery,
1232 # so we only want to include them in the accel list when building the main
1233 # libraries, hence the use of a separate variable.
1234 # Note: the following loop is a modified version of
1235 # helper_get_psa_curve_list that only keeps Weierstrass families.
1236 loc_weierstrass_list=""
1237 loc_non_weierstrass_list=""
1238 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
1239 case $item in
1240 ECC_BRAINPOOL*|ECC_SECP*)
1241 loc_weierstrass_list="$loc_weierstrass_list $item"
1242 ;;
1243 *)
1244 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
1245 ;;
1246 esac
1247 done
1248 if [ $weierstrass -eq 1 ]; then
1249 loc_curve_list=$loc_weierstrass_list
1250 else
1251 loc_curve_list=$loc_non_weierstrass_list
1252 fi
1253
1254 # Algorithms and key types to accelerate
1255 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1256 ALG_ECDH \
1257 ALG_JPAKE \
1258 $(helper_get_psa_key_type_list "ECC") \
1259 $loc_curve_list"
1260
1261 # Configure
1262 # ---------
1263
1264 # Start with config crypto_full and remove PK_C:
1265 # that's what's supported now, see docs/driver-only-builds.md.
1266 helper_libtestdriver1_adjust_config "crypto_full"
1267 scripts/config.py unset MBEDTLS_PK_C
1268 scripts/config.py unset MBEDTLS_PK_PARSE_C
1269 scripts/config.py unset MBEDTLS_PK_WRITE_C
1270
1271 # Disable modules that are accelerated - some will be re-enabled
1272 scripts/config.py unset MBEDTLS_ECDSA_C
1273 scripts/config.py unset MBEDTLS_ECDH_C
1274 scripts/config.py unset MBEDTLS_ECJPAKE_C
1275 scripts/config.py unset MBEDTLS_ECP_C
1276
1277 # Disable all curves - those that aren't accelerated should be re-enabled
1278 helper_disable_builtin_curves
1279
1280 # Restartable feature is not yet supported by PSA. Once it will in
1281 # the future, the following line could be removed (see issues
1282 # 6061, 6332 and following ones)
1283 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1284
1285 # this is not supported by the driver API yet
1286 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1287
1288 # Build
1289 # -----
1290
1291 # These hashes are needed for some ECDSA signature tests.
1292 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1293 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1294 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1295
Manuel Pégourié-Gonnardf35d3072025-07-10 21:54:38 +02001296 # For grep to work below we need less inlining in ecp.c
1297 ASAN_CFLAGS="$ASAN_CFLAGS -O0" helper_libtestdriver1_make_main "$loc_accel_list"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001298
1299 # We expect ECDH to be re-enabled for the missing curves
1300 grep mbedtls_ecdh_ library/ecdh.o
1301 # We expect ECP to be re-enabled, however the parts specific to the
1302 # families of curves that are accelerated should be ommited.
1303 # - functions with mxz in the name are specific to Montgomery curves
1304 # - ecp_muladd is specific to Weierstrass curves
1305 ##nm library/ecp.o | tee ecp.syms
1306 if [ $weierstrass -eq 1 ]; then
1307 not grep mbedtls_ecp_muladd library/ecp.o
1308 grep mxz library/ecp.o
1309 else
1310 grep mbedtls_ecp_muladd library/ecp.o
1311 not grep mxz library/ecp.o
1312 fi
1313 # We expect ECDSA and ECJPAKE to be re-enabled only when
1314 # Weierstrass curves are not accelerated
1315 if [ $weierstrass -eq 1 ]; then
1316 not grep mbedtls_ecdsa library/ecdsa.o
1317 not grep mbedtls_ecjpake library/ecjpake.o
1318 else
1319 grep mbedtls_ecdsa library/ecdsa.o
1320 grep mbedtls_ecjpake library/ecjpake.o
1321 fi
1322
1323 # Run the tests
1324 # -------------
1325
1326 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
1327 make test
1328}
1329
1330component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
1331 common_test_psa_crypto_config_accel_ecc_some_curves 1
1332}
1333
1334component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
1335 common_test_psa_crypto_config_accel_ecc_some_curves 0
1336}
1337
1338# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
1339# ECDH, ECDSA) with and without drivers.
1340# The input parameter is a boolean value which indicates:
1341# - 0 keep built-in EC algs,
1342# - 1 exclude built-in EC algs (driver only).
1343#
1344# This is used by the two following components to ensure they always use the
1345# same config, except for the use of driver or built-in EC algorithms:
1346# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
1347# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
1348# This supports comparing their test coverage with analyze_outcomes.py.
1349config_psa_crypto_config_ecp_light_only () {
1350 driver_only="$1"
1351 # start with config full for maximum coverage (also enables USE_PSA)
1352 helper_libtestdriver1_adjust_config "full"
1353 if [ "$driver_only" -eq 1 ]; then
1354 # Disable modules that are accelerated
1355 scripts/config.py unset MBEDTLS_ECDSA_C
1356 scripts/config.py unset MBEDTLS_ECDH_C
1357 scripts/config.py unset MBEDTLS_ECJPAKE_C
1358 scripts/config.py unset MBEDTLS_ECP_C
1359 fi
1360
1361 # Restartable feature is not yet supported by PSA. Once it will in
1362 # the future, the following line could be removed (see issues
1363 # 6061, 6332 and following ones)
1364 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1365}
1366
1367# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
1368component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
1369 msg "build: full with accelerated EC algs"
1370
1371 # Algorithms and key types to accelerate
1372 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1373 ALG_ECDH \
1374 ALG_JPAKE \
1375 $(helper_get_psa_key_type_list "ECC") \
1376 $(helper_get_psa_curve_list)"
1377
1378 # Configure
1379 # ---------
1380
1381 # Use the same config as reference, only without built-in EC algs
1382 config_psa_crypto_config_ecp_light_only 1
1383
1384 # Do not disable builtin curves because that support is required for:
1385 # - MBEDTLS_PK_PARSE_EC_EXTENDED
1386 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
1387
1388 # Build
1389 # -----
1390
1391 # These hashes are needed for some ECDSA signature tests.
1392 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1393 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1394 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1395
1396 helper_libtestdriver1_make_main "$loc_accel_list"
1397
1398 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1399 not grep mbedtls_ecdsa_ library/ecdsa.o
1400 not grep mbedtls_ecdh_ library/ecdh.o
1401 not grep mbedtls_ecjpake_ library/ecjpake.o
1402 not grep mbedtls_ecp_mul library/ecp.o
1403
1404 # Run the tests
1405 # -------------
1406
1407 msg "test suites: full with accelerated EC algs"
1408 make test
1409
1410 msg "ssl-opt: full with accelerated EC algs"
1411 tests/ssl-opt.sh
1412}
1413
1414# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
1415component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
1416 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated EC algs"
1417
1418 config_psa_crypto_config_ecp_light_only 0
1419
1420 make
1421
1422 msg "test suites: full with non-accelerated EC algs"
1423 make test
1424
1425 msg "ssl-opt: full with non-accelerated EC algs"
1426 tests/ssl-opt.sh
1427}
1428
1429# This helper function is used by:
1430# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
1431# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
1432# to ensure that both tests use the same underlying configuration when testing
1433# driver's coverage with analyze_outcomes.py.
1434#
1435# This functions accepts 1 boolean parameter as follows:
1436# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
1437# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
1438# - 0: include built-in implementation of EC algorithms.
1439#
1440# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
1441# on the ECP module.
1442config_psa_crypto_no_ecp_at_all () {
1443 driver_only="$1"
1444 # start with full config for maximum coverage (also enables USE_PSA)
1445 helper_libtestdriver1_adjust_config "full"
1446
1447 if [ "$driver_only" -eq 1 ]; then
1448 # Disable modules that are accelerated
1449 scripts/config.py unset MBEDTLS_ECDSA_C
1450 scripts/config.py unset MBEDTLS_ECDH_C
1451 scripts/config.py unset MBEDTLS_ECJPAKE_C
1452 # Disable ECP module (entirely)
1453 scripts/config.py unset MBEDTLS_ECP_C
1454 fi
1455
1456 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1457 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1458 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1459 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1460
1461 # Restartable feature is not yet supported by PSA. Once it will in
1462 # the future, the following line could be removed (see issues
1463 # 6061, 6332 and following ones)
1464 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1465}
1466
1467# Build and test a configuration where driver accelerates all EC algs while
1468# all support and dependencies from ECP and ECP_LIGHT are removed on the library
1469# side.
1470#
1471# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
1472component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
1473 msg "build: full + accelerated EC algs - ECP"
1474
1475 # Algorithms and key types to accelerate
1476 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1477 ALG_ECDH \
1478 ALG_JPAKE \
1479 $(helper_get_psa_key_type_list "ECC") \
1480 $(helper_get_psa_curve_list)"
1481
1482 # Configure
1483 # ---------
1484
1485 # Set common configurations between library's and driver's builds
1486 config_psa_crypto_no_ecp_at_all 1
1487 # Disable all the builtin curves. All the required algs are accelerated.
1488 helper_disable_builtin_curves
1489
1490 # Build
1491 # -----
1492
1493 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1494 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1495 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1496 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1497
1498 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1499
1500 helper_libtestdriver1_make_main "$loc_accel_list"
1501
1502 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1503 not grep mbedtls_ecdsa_ library/ecdsa.o
1504 not grep mbedtls_ecdh_ library/ecdh.o
1505 not grep mbedtls_ecjpake_ library/ecjpake.o
1506 # Also ensure that ECP module was not re-enabled
1507 not grep mbedtls_ecp_ library/ecp.o
1508
1509 # Run the tests
1510 # -------------
1511
1512 msg "test: full + accelerated EC algs - ECP"
1513 make test
1514
1515 msg "ssl-opt: full + accelerated EC algs - ECP"
1516 tests/ssl-opt.sh
1517}
1518
1519# Reference function used for driver's coverage analysis in analyze_outcomes.py
1520# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
1521# Keep in sync with its accelerated counterpart.
1522component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
1523 msg "build: full + non accelerated EC algs"
1524
1525 config_psa_crypto_no_ecp_at_all 0
1526
1527 make
1528
1529 msg "test: full + non accelerated EC algs"
1530 make test
1531
1532 msg "ssl-opt: full + non accelerated EC algs"
1533 tests/ssl-opt.sh
1534}
1535
1536# This is a common configuration helper used directly from:
1537# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1538# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1539# and indirectly from:
1540# - component_test_psa_crypto_config_accel_ecc_no_bignum
1541# - accelerate all EC algs, disable RSA and FFDH
1542# - component_test_psa_crypto_config_reference_ecc_no_bignum
1543# - this is the reference component of the above
1544# - it still disables RSA and FFDH, but it uses builtin EC algs
1545# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1546# - accelerate all EC and FFDH algs, disable only RSA
1547# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1548# - this is the reference component of the above
1549# - it still disables RSA, but it uses builtin EC and FFDH algs
1550#
1551# This function accepts 2 parameters:
1552# $1: a boolean value which states if we are testing an accelerated scenario
1553# or not.
1554# $2: a string value which states which components are tested. Allowed values
1555# are "ECC" or "ECC_DH".
1556config_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1557 driver_only="$1"
1558 test_target="$2"
1559 # start with full config for maximum coverage (also enables USE_PSA)
1560 helper_libtestdriver1_adjust_config "full"
1561
1562 if [ "$driver_only" -eq 1 ]; then
1563 # Disable modules that are accelerated
1564 scripts/config.py unset MBEDTLS_ECDSA_C
1565 scripts/config.py unset MBEDTLS_ECDH_C
1566 scripts/config.py unset MBEDTLS_ECJPAKE_C
1567 # Disable ECP module (entirely)
1568 scripts/config.py unset MBEDTLS_ECP_C
1569 # Also disable bignum
1570 scripts/config.py unset MBEDTLS_BIGNUM_C
1571 fi
1572
1573 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1574 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1575 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1576 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1577
1578 # RSA support is intentionally disabled on this test because RSA_C depends
1579 # on BIGNUM_C.
1580 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
1581 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
1582 scripts/config.py unset MBEDTLS_RSA_C
1583 scripts/config.py unset MBEDTLS_PKCS1_V15
1584 scripts/config.py unset MBEDTLS_PKCS1_V21
1585 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1586 # Also disable key exchanges that depend on RSA
1587 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1588 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1589 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1590 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1591 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1592
1593 if [ "$test_target" = "ECC" ]; then
1594 # When testing ECC only, we disable FFDH support, both from builtin and
1595 # PSA sides, and also disable the key exchanges that depend on DHM.
1596 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_FFDH
1597 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
1598 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
1599 scripts/config.py unset MBEDTLS_DHM_C
1600 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1601 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1602 else
1603 # When testing ECC and DH instead, we disable DHM and depending key
1604 # exchanges only in the accelerated build
1605 if [ "$driver_only" -eq 1 ]; then
1606 scripts/config.py unset MBEDTLS_DHM_C
1607 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1608 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1609 fi
1610 fi
1611
1612 # Restartable feature is not yet supported by PSA. Once it will in
1613 # the future, the following line could be removed (see issues
1614 # 6061, 6332 and following ones)
1615 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1616}
1617
1618# Common helper used by:
1619# - component_test_psa_crypto_config_accel_ecc_no_bignum
1620# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1621#
1622# The goal is to build and test accelerating either:
1623# - ECC only or
1624# - both ECC and FFDH
1625#
1626# It is meant to be used in conjunction with
1627# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
1628# coverage analysis in the "analyze_outcomes.py" script.
1629common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1630 test_target="$1"
1631
1632 # This is an internal helper to simplify text message handling
1633 if [ "$test_target" = "ECC_DH" ]; then
1634 accel_text="ECC/FFDH"
1635 removed_text="ECP - DH"
1636 else
1637 accel_text="ECC"
1638 removed_text="ECP"
1639 fi
1640
1641 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1642
1643 # By default we accelerate all EC keys/algs
1644 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1645 ALG_ECDH \
1646 ALG_JPAKE \
1647 $(helper_get_psa_key_type_list "ECC") \
1648 $(helper_get_psa_curve_list)"
1649 # Optionally we can also add DH to the list of accelerated items
1650 if [ "$test_target" = "ECC_DH" ]; then
1651 loc_accel_list="$loc_accel_list \
1652 ALG_FFDH \
1653 $(helper_get_psa_key_type_list "DH") \
1654 $(helper_get_psa_dh_group_list)"
1655 fi
1656
1657 # Configure
1658 # ---------
1659
1660 # Set common configurations between library's and driver's builds
1661 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
1662 # Disable all the builtin curves. All the required algs are accelerated.
1663 helper_disable_builtin_curves
1664
1665 # Build
1666 # -----
1667
1668 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1669 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1670 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1671 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1672
1673 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1674
1675 helper_libtestdriver1_make_main "$loc_accel_list"
1676
1677 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1678 not grep mbedtls_ecdsa_ library/ecdsa.o
1679 not grep mbedtls_ecdh_ library/ecdh.o
1680 not grep mbedtls_ecjpake_ library/ecjpake.o
1681 # Also ensure that ECP, RSA, [DHM] or BIGNUM modules were not re-enabled
1682 not grep mbedtls_ecp_ library/ecp.o
1683 not grep mbedtls_rsa_ library/rsa.o
1684 not grep mbedtls_mpi_ library/bignum.o
1685 not grep mbedtls_dhm_ library/dhm.o
1686
1687 # Run the tests
1688 # -------------
1689
1690 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - DHM - BIGNUM"
1691
1692 make test
1693
1694 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1695 tests/ssl-opt.sh
1696}
1697
1698# Common helper used by:
1699# - component_test_psa_crypto_config_reference_ecc_no_bignum
1700# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1701#
1702# The goal is to build and test a reference scenario (i.e. with builtin
1703# components) compared to the ones used in
1704# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
1705#
1706# It is meant to be used in conjunction with
1707# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
1708# coverage analysis in "analyze_outcomes.py" script.
1709common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1710 test_target="$1"
1711
1712 # This is an internal helper to simplify text message handling
1713 if [ "$test_target" = "ECC_DH" ]; then
1714 accel_text="ECC/FFDH"
1715 else
1716 accel_text="ECC"
1717 fi
1718
1719 msg "build: full + non accelerated $accel_text algs + USE_PSA"
1720
1721 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
1722
1723 make
1724
1725 msg "test suites: full + non accelerated EC algs + USE_PSA"
1726 make test
1727
1728 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
1729 tests/ssl-opt.sh
1730}
1731
1732component_test_psa_crypto_config_accel_ecc_no_bignum () {
1733 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
1734}
1735
1736component_test_psa_crypto_config_reference_ecc_no_bignum () {
1737 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
1738}
1739
1740component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1741 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
1742}
1743
1744component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1745 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
1746}
1747
Gilles Peskineced0edc2024-09-14 11:35:36 +02001748component_test_tfm_config_as_is () {
1749 msg "build: configs/config-tfm.h"
1750 cp configs/config-tfm.h "$CONFIG_H"
1751 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1752 make
1753
1754 msg "test: configs/config-tfm.h - unit tests"
1755 make test
1756}
1757
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001758# Helper for setting common configurations between:
1759# - component_test_tfm_config_p256m_driver_accel_ec()
Gilles Peskineced0edc2024-09-14 11:35:36 +02001760# - component_test_tfm_config_no_p256m()
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001761common_tfm_config () {
1762 # Enable TF-M config
1763 cp configs/config-tfm.h "$CONFIG_H"
1764 echo "#undef MBEDTLS_PSA_CRYPTO_CONFIG_FILE" >> "$CONFIG_H"
1765 cp configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
1766
1767 # Other config adjustment to make the tests pass.
1768 # This should probably be adopted upstream.
1769 #
1770 # - USE_PSA_CRYPTO for PK_HAVE_ECC_KEYS
1771 echo "#define MBEDTLS_USE_PSA_CRYPTO" >> "$CONFIG_H"
1772
1773 # Config adjustment for better test coverage in our environment.
1774 # This is not needed just to build and pass tests.
1775 #
1776 # Enable filesystem I/O for the benefit of PK parse/write tests.
1777 echo "#define MBEDTLS_FS_IO" >> "$CONFIG_H"
1778}
1779
1780# Keep this in sync with component_test_tfm_config() as they are both meant
1781# to be used in analyze_outcomes.py for driver's coverage analysis.
1782component_test_tfm_config_p256m_driver_accel_ec () {
1783 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1784
1785 common_tfm_config
1786
1787 # Build crypto library
David Horstmanndcf42a02024-11-08 14:40:12 +00001788 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../framework/tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001789
1790 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1791 not grep mbedtls_ecdsa_ library/ecdsa.o
1792 not grep mbedtls_ecdh_ library/ecdh.o
1793 not grep mbedtls_ecjpake_ library/ecjpake.o
1794 # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
1795 not grep mbedtls_ecp_ library/ecp.o
1796 not grep mbedtls_rsa_ library/rsa.o
1797 not grep mbedtls_dhm_ library/dhm.o
1798 not grep mbedtls_mpi_ library/bignum.o
1799 # Check that p256m was built
1800 grep -q p256_ecdsa_ library/libmbedcrypto.a
1801
1802 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1803 # files, so we want to ensure that it has not be re-enabled accidentally.
1804 not grep mbedtls_cipher library/cipher.o
1805
1806 # Run the tests
1807 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1808 make test
1809}
1810
1811# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1812# they are both meant to be used in analyze_outcomes.py for driver's coverage
1813# analysis.
Gilles Peskineced0edc2024-09-14 11:35:36 +02001814component_test_tfm_config_no_p256m () {
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001815 common_tfm_config
1816
1817 # Disable P256M driver, which is on by default, so that analyze_outcomes
1818 # can compare this test with test_tfm_config_p256m_driver_accel_ec
1819 echo "#undef MBEDTLS_PSA_P256M_DRIVER_ENABLED" >> "$CONFIG_H"
1820
Gilles Peskineced0edc2024-09-14 11:35:36 +02001821 msg "build: TF-M config without p256m"
David Horstmanndcf42a02024-11-08 14:40:12 +00001822 make CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' tests
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001823
1824 # Check that p256m was not built
1825 not grep p256_ecdsa_ library/libmbedcrypto.a
1826
1827 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1828 # files, so we want to ensure that it has not be re-enabled accidentally.
1829 not grep mbedtls_cipher library/cipher.o
1830
Gilles Peskineced0edc2024-09-14 11:35:36 +02001831 msg "test: TF-M config without p256m"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001832 make test
1833}
1834
1835# This is an helper used by:
1836# - component_test_psa_ecc_key_pair_no_derive
1837# - component_test_psa_ecc_key_pair_no_generate
1838# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1839# enabled, but one. Input arguments are as follows:
1840# - $1 is the key type under test, i.e. ECC/RSA/DH
1841# - $2 is the key option to be unset (i.e. generate, derive, etc)
1842build_and_test_psa_want_key_pair_partial () {
1843 key_type=$1
1844 unset_option=$2
1845 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1846
1847 msg "build: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
1848 scripts/config.py full
1849 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1850 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1851
1852 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1853 # crypto_config.h so we just disable the one we don't want.
1854 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
1855
1856 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1857
1858 msg "test: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
1859 make test
1860}
1861
1862component_test_psa_ecc_key_pair_no_derive () {
1863 build_and_test_psa_want_key_pair_partial "ECC" "DERIVE"
1864}
1865
1866component_test_psa_ecc_key_pair_no_generate () {
1867 build_and_test_psa_want_key_pair_partial "ECC" "GENERATE"
1868}
1869
1870config_psa_crypto_accel_rsa () {
1871 driver_only=$1
1872
1873 # Start from crypto_full config (no X.509, no TLS)
Manuel Pégourié-Gonnardb50b6382024-07-23 10:12:01 +02001874 # Note: PK will be ignored when comparing driver to reference in
1875 # analyze_outcomes.py
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001876 helper_libtestdriver1_adjust_config "crypto_full"
1877
1878 if [ "$driver_only" -eq 1 ]; then
1879 # Remove RSA support and its dependencies
1880 scripts/config.py unset MBEDTLS_RSA_C
1881 scripts/config.py unset MBEDTLS_PKCS1_V15
1882 scripts/config.py unset MBEDTLS_PKCS1_V21
1883
1884 # We need PEM parsing in the test library as well to support the import
1885 # of PEM encoded RSA keys.
1886 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1887 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
1888 fi
1889}
1890
1891component_test_psa_crypto_config_accel_rsa_crypto () {
1892 msg "build: crypto_full with accelerated RSA"
1893
1894 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1895 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1896 KEY_TYPE_RSA_PUBLIC_KEY \
1897 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1898 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1899 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1900 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1901
1902 # Configure
1903 # ---------
1904
1905 config_psa_crypto_accel_rsa 1
1906
1907 # Build
1908 # -----
1909
1910 # These hashes are needed for unit tests.
1911 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1912 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1913 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1914
1915 helper_libtestdriver1_make_main "$loc_accel_list"
1916
1917 # Make sure this was not re-enabled by accident (additive config)
1918 not grep mbedtls_rsa library/rsa.o
1919
1920 # Run the tests
1921 # -------------
1922
1923 msg "test: crypto_full with accelerated RSA"
1924 make test
1925}
1926
1927component_test_psa_crypto_config_reference_rsa_crypto () {
1928 msg "build: crypto_full with non-accelerated RSA"
1929
1930 # Configure
1931 # ---------
1932 config_psa_crypto_accel_rsa 0
1933
1934 # Build
1935 # -----
1936 make
1937
1938 # Run the tests
1939 # -------------
1940 msg "test: crypto_full with non-accelerated RSA"
1941 make test
1942}
1943
1944# This is a temporary test to verify that full RSA support is present even when
1945# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
1946component_test_new_psa_want_key_pair_symbol () {
1947 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1948
1949 # Create a temporary output file unless there is already one set
1950 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1951 REMOVE_OUTCOME_ON_EXIT="no"
1952 else
1953 REMOVE_OUTCOME_ON_EXIT="yes"
1954 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1955 export MBEDTLS_TEST_OUTCOME_FILE
1956 fi
1957
1958 # Start from crypto configuration
1959 scripts/config.py crypto
1960
1961 # Remove RSA support and its dependencies
1962 scripts/config.py unset MBEDTLS_PKCS1_V15
1963 scripts/config.py unset MBEDTLS_PKCS1_V21
1964 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1965 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1966 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1967 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1968 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1969 scripts/config.py unset MBEDTLS_RSA_C
1970 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1971
1972 # Enable PSA support
1973 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1974
1975 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
1976 # that proper translations is done in crypto_legacy.h.
1977 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
1978 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
1979 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
1980
1981 make
1982
1983 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1984 make test
1985
1986 # Parse only 1 relevant line from the outcome file, i.e. a test which is
1987 # performing RSA signature.
1988 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
1989 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
1990
1991 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
1992 rm $MBEDTLS_TEST_OUTCOME_FILE
1993 fi
1994}
1995
1996component_test_psa_crypto_config_accel_hash () {
1997 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
1998
1999 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
2000 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2001 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2002
2003 # Configure
2004 # ---------
2005
2006 # Start from default config (no USE_PSA)
2007 helper_libtestdriver1_adjust_config "default"
2008
2009 # Disable the things that are being accelerated
2010 scripts/config.py unset MBEDTLS_MD5_C
2011 scripts/config.py unset MBEDTLS_RIPEMD160_C
2012 scripts/config.py unset MBEDTLS_SHA1_C
2013 scripts/config.py unset MBEDTLS_SHA224_C
2014 scripts/config.py unset MBEDTLS_SHA256_C
2015 scripts/config.py unset MBEDTLS_SHA384_C
2016 scripts/config.py unset MBEDTLS_SHA512_C
2017 scripts/config.py unset MBEDTLS_SHA3_C
2018
2019 # Build
2020 # -----
2021
2022 helper_libtestdriver1_make_drivers "$loc_accel_list"
2023
2024 helper_libtestdriver1_make_main "$loc_accel_list"
2025
2026 # There's a risk of something getting re-enabled via config_psa.h;
2027 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
2028 not grep mbedtls_md5 library/md5.o
2029 not grep mbedtls_sha1 library/sha1.o
2030 not grep mbedtls_sha256 library/sha256.o
2031 not grep mbedtls_sha512 library/sha512.o
2032 not grep mbedtls_ripemd160 library/ripemd160.o
2033
2034 # Run the tests
2035 # -------------
2036
2037 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2038 make test
2039}
2040
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002041component_test_psa_crypto_config_accel_hash_keep_builtins () {
2042 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
2043 # This component ensures that all the test cases for
2044 # md_psa_dynamic_dispatch with legacy+driver in test_suite_md are run.
2045
2046 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
2047 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2048 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2049
2050 # Start from default config (no USE_PSA)
2051 helper_libtestdriver1_adjust_config "default"
2052
2053 helper_libtestdriver1_make_drivers "$loc_accel_list"
2054
2055 helper_libtestdriver1_make_main "$loc_accel_list"
2056
2057 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
2058 make test
2059}
2060
2061# This should be renamed to test and updated once the accelerator ECDH code is in place and ready to test.
2062component_build_psa_accel_alg_ecdh () {
2063 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
2064 scripts/config.py full
2065 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2066 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2067 scripts/config.py unset MBEDTLS_ECDH_C
2068 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2069 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2070 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2071 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2072 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2073 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002074 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002075}
2076
2077# This should be renamed to test and updated once the accelerator HMAC code is in place and ready to test.
2078component_build_psa_accel_alg_hmac () {
2079 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
2080 scripts/config.py full
2081 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2082 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2083 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002084 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002085}
2086
2087# This should be renamed to test and updated once the accelerator HKDF code is in place and ready to test.
2088component_build_psa_accel_alg_hkdf () {
2089 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
2090 scripts/config.py full
2091 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2092 scripts/config.py unset MBEDTLS_HKDF_C
2093 # Make sure to unset TLS1_3 since it requires HKDF_C and will not build properly without it.
2094 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2095 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002096 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002097}
2098
2099# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
2100component_build_psa_accel_alg_md5 () {
2101 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - other hashes"
2102 scripts/config.py full
2103 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2104 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2105 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2106 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2107 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2108 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2109 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2110 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2111 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2112 scripts/config.py unset MBEDTLS_LMS_C
2113 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2114 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002115 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002116}
2117
2118# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
2119component_build_psa_accel_alg_ripemd160 () {
2120 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - other hashes"
2121 scripts/config.py full
2122 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2123 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2124 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2125 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2126 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2127 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2128 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2129 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2130 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2131 scripts/config.py unset MBEDTLS_LMS_C
2132 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2133 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002134 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002135}
2136
2137# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
2138component_build_psa_accel_alg_sha1 () {
2139 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - other hashes"
2140 scripts/config.py full
2141 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2142 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2143 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2144 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2145 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2146 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2147 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2148 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2149 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2150 scripts/config.py unset MBEDTLS_LMS_C
2151 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2152 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002153 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002154}
2155
2156# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
2157component_build_psa_accel_alg_sha224 () {
2158 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
2159 scripts/config.py full
2160 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2161 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2162 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2163 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2164 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2165 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2166 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2167 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2168 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002169 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002170}
2171
2172# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
2173component_build_psa_accel_alg_sha256 () {
2174 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - other hashes"
2175 scripts/config.py full
2176 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2177 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2178 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2179 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2180 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2181 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2182 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2183 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2184 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002185 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002186}
2187
2188# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
2189component_build_psa_accel_alg_sha384 () {
2190 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
2191 scripts/config.py full
2192 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2193 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2194 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2195 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2196 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2197 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2198 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2199 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2200 scripts/config.py unset MBEDTLS_LMS_C
2201 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2202 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002203 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002204}
2205
2206# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
2207component_build_psa_accel_alg_sha512 () {
2208 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
2209 scripts/config.py full
2210 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2211 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2212 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2213 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2214 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2215 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2216 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2217 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2218 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2219 scripts/config.py unset MBEDTLS_LMS_C
2220 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2221 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002222 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002223}
2224
2225# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2226component_build_psa_accel_alg_rsa_pkcs1v15_crypt () {
2227 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2228 scripts/config.py full
2229 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2230 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2231 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
2232 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2233 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
2234 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
2235 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002236 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002237}
2238
2239# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2240component_build_psa_accel_alg_rsa_pkcs1v15_sign () {
2241 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2242 scripts/config.py full
2243 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2244 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2245 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
2246 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2247 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
2248 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
2249 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002250 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002251}
2252
2253# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2254component_build_psa_accel_alg_rsa_oaep () {
2255 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2256 scripts/config.py full
2257 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2258 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2259 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_OAEP 1
2260 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2261 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2262 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
2263 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002264 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002265}
2266
2267# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2268component_build_psa_accel_alg_rsa_pss () {
2269 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2270 scripts/config.py full
2271 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2272 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2273 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
2274 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2275 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2276 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
2277 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002278 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002279}
2280
2281# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2282component_build_psa_accel_key_type_rsa_key_pair () {
2283 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_xxx + PSA_WANT_ALG_RSA_PSS"
2284 scripts/config.py full
2285 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2286 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2287 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
2288 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC 1
2289 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT 1
2290 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT 1
2291 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE 1
2292 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002293 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002294}
2295
2296# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2297component_build_psa_accel_key_type_rsa_public_key () {
2298 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
2299 scripts/config.py full
2300 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2301 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2302 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
2303 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
2304 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
David Horstmanndcf42a02024-11-08 14:40:12 +00002305 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY -I../framework/tests/include" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002306}
2307
Minos Galanakis3ece57e2024-08-01 17:09:49 +01002308# Auxiliary function to build config for hashes with and without drivers
2309config_psa_crypto_hash_use_psa () {
2310 driver_only="$1"
2311 # start with config full for maximum coverage (also enables USE_PSA)
2312 helper_libtestdriver1_adjust_config "full"
2313 if [ "$driver_only" -eq 1 ]; then
2314 # disable the built-in implementation of hashes
2315 scripts/config.py unset MBEDTLS_MD5_C
2316 scripts/config.py unset MBEDTLS_RIPEMD160_C
2317 scripts/config.py unset MBEDTLS_SHA1_C
2318 scripts/config.py unset MBEDTLS_SHA224_C
2319 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
2320 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2321 scripts/config.py unset MBEDTLS_SHA384_C
2322 scripts/config.py unset MBEDTLS_SHA512_C
2323 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2324 scripts/config.py unset MBEDTLS_SHA3_C
2325 fi
2326}
2327
2328# Note that component_test_psa_crypto_config_reference_hash_use_psa
2329# is related to this component and both components need to be kept in sync.
2330# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
2331component_test_psa_crypto_config_accel_hash_use_psa () {
2332 msg "test: full with accelerated hashes"
2333
2334 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
2335 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2336 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2337
2338 # Configure
2339 # ---------
2340
2341 config_psa_crypto_hash_use_psa 1
2342
2343 # Build
2344 # -----
2345
2346 helper_libtestdriver1_make_drivers "$loc_accel_list"
2347
2348 helper_libtestdriver1_make_main "$loc_accel_list"
2349
2350 # There's a risk of something getting re-enabled via config_psa.h;
2351 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
2352 not grep mbedtls_md5 library/md5.o
2353 not grep mbedtls_sha1 library/sha1.o
2354 not grep mbedtls_sha256 library/sha256.o
2355 not grep mbedtls_sha512 library/sha512.o
2356 not grep mbedtls_ripemd160 library/ripemd160.o
2357
2358 # Run the tests
2359 # -------------
2360
2361 msg "test: full with accelerated hashes"
2362 make test
2363
2364 # This is mostly useful so that we can later compare outcome files with
2365 # the reference config in analyze_outcomes.py, to check that the
2366 # dependency declarations in ssl-opt.sh and in TLS code are correct.
2367 msg "test: ssl-opt.sh, full with accelerated hashes"
2368 tests/ssl-opt.sh
2369
2370 # This is to make sure all ciphersuites are exercised, but we don't need
2371 # interop testing (besides, we already got some from ssl-opt.sh).
2372 msg "test: compat.sh, full with accelerated hashes"
2373 tests/compat.sh -p mbedTLS -V YES
2374}
2375
2376# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
2377# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
2378# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
2379# Both components need to be kept in sync.
2380component_test_psa_crypto_config_reference_hash_use_psa () {
2381 msg "test: full without accelerated hashes"
2382
2383 config_psa_crypto_hash_use_psa 0
2384
2385 make
2386
2387 msg "test: full without accelerated hashes"
2388 make test
2389
2390 msg "test: ssl-opt.sh, full without accelerated hashes"
2391 tests/ssl-opt.sh
2392}
2393
2394# Auxiliary function to build config for hashes with and without drivers
2395config_psa_crypto_hmac_use_psa () {
2396 driver_only="$1"
2397 # start with config full for maximum coverage (also enables USE_PSA)
2398 helper_libtestdriver1_adjust_config "full"
2399
2400 if [ "$driver_only" -eq 1 ]; then
2401 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
2402 # is still enabled though (for ENTROPY_C among others).
2403 scripts/config.py unset MBEDTLS_MD_C
2404 # Disable also the builtin hashes since they are supported by the driver
2405 # and MD module is able to perform PSA dispathing.
2406 scripts/config.py unset-all MBEDTLS_SHA
2407 scripts/config.py unset MBEDTLS_MD5_C
2408 scripts/config.py unset MBEDTLS_RIPEMD160_C
2409 fi
2410
2411 # Direct dependencies of MD_C. We disable them also in the reference
2412 # component to work with the same set of features.
2413 scripts/config.py unset MBEDTLS_PKCS7_C
2414 scripts/config.py unset MBEDTLS_PKCS5_C
2415 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
2416 scripts/config.py unset MBEDTLS_HKDF_C
2417 # Dependencies of HMAC_DRBG
2418 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
2419 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
2420}
2421
2422component_test_psa_crypto_config_accel_hmac () {
2423 msg "test: full with accelerated hmac"
2424
2425 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
2426 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
2427 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2428 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2429
2430 # Configure
2431 # ---------
2432
2433 config_psa_crypto_hmac_use_psa 1
2434
2435 # Build
2436 # -----
2437
2438 helper_libtestdriver1_make_drivers "$loc_accel_list"
2439
2440 helper_libtestdriver1_make_main "$loc_accel_list"
2441
2442 # Ensure that built-in support for HMAC is disabled.
2443 not grep mbedtls_md_hmac library/md.o
2444
2445 # Run the tests
2446 # -------------
2447
2448 msg "test: full with accelerated hmac"
2449 make test
2450}
2451
2452component_test_psa_crypto_config_reference_hmac () {
2453 msg "test: full without accelerated hmac"
2454
2455 config_psa_crypto_hmac_use_psa 0
2456
2457 make
2458
2459 msg "test: full without accelerated hmac"
2460 make test
2461}
2462
2463component_test_psa_crypto_config_accel_des () {
2464 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
2465
2466 # Albeit this components aims at accelerating DES which should only support
2467 # CBC and ECB modes, we need to accelerate more than that otherwise DES_C
2468 # would automatically be re-enabled by "config_adjust_legacy_from_psa.c"
2469 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 \
2470 ALG_CTR ALG_CFB ALG_OFB ALG_XTS ALG_CMAC \
2471 KEY_TYPE_DES"
2472
2473 # Note: we cannot accelerate all ciphers' key types otherwise we would also
2474 # have to either disable CCM/GCM or accelerate them, but that's out of scope
2475 # of this component. This limitation will be addressed by #8598.
2476
2477 # Configure
2478 # ---------
2479
2480 # Start from the full config
2481 helper_libtestdriver1_adjust_config "full"
2482
2483 # Disable the things that are being accelerated
2484 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2485 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2486 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2487 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2488 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2489 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2490 scripts/config.py unset MBEDTLS_DES_C
2491 scripts/config.py unset MBEDTLS_CMAC_C
2492
2493 # Build
2494 # -----
2495
2496 helper_libtestdriver1_make_drivers "$loc_accel_list"
2497
2498 helper_libtestdriver1_make_main "$loc_accel_list"
2499
2500 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine5ea32982024-06-19 15:09:27 +02002501 not grep mbedtls_des library/des.o
Minos Galanakis3ece57e2024-08-01 17:09:49 +01002502
2503 # Run the tests
2504 # -------------
2505
2506 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
2507 make test
2508}
2509
2510component_test_psa_crypto_config_accel_aead () {
2511 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2512
2513 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
2514 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2515
2516 # Configure
2517 # ---------
2518
2519 # Start from full config
2520 helper_libtestdriver1_adjust_config "full"
2521
2522 # Disable things that are being accelerated
2523 scripts/config.py unset MBEDTLS_GCM_C
2524 scripts/config.py unset MBEDTLS_CCM_C
2525 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2526
2527 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
2528 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
2529
2530 # Build
2531 # -----
2532
2533 helper_libtestdriver1_make_drivers "$loc_accel_list"
2534
2535 helper_libtestdriver1_make_main "$loc_accel_list"
2536
2537 # Make sure this was not re-enabled by accident (additive config)
2538 not grep mbedtls_ccm library/ccm.o
2539 not grep mbedtls_gcm library/gcm.o
2540 not grep mbedtls_chachapoly library/chachapoly.o
2541
2542 # Run the tests
2543 # -------------
2544
2545 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2546 make test
2547}
2548
2549# This is a common configuration function used in:
2550# - component_test_psa_crypto_config_accel_cipher_aead_cmac
2551# - component_test_psa_crypto_config_reference_cipher_aead_cmac
2552common_psa_crypto_config_accel_cipher_aead_cmac () {
2553 # Start from the full config
2554 helper_libtestdriver1_adjust_config "full"
2555
2556 scripts/config.py unset MBEDTLS_NIST_KW_C
2557}
2558
2559# The 2 following test components, i.e.
2560# - component_test_psa_crypto_config_accel_cipher_aead_cmac
2561# - component_test_psa_crypto_config_reference_cipher_aead_cmac
2562# are meant to be used together in analyze_outcomes.py script in order to test
2563# driver's coverage for ciphers and AEADs.
2564component_test_psa_crypto_config_accel_cipher_aead_cmac () {
2565 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
2566
2567 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
2568 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
2569 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
2570 KEY_TYPE_DES KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
2571
2572 # Configure
2573 # ---------
2574
2575 common_psa_crypto_config_accel_cipher_aead_cmac
2576
2577 # Disable the things that are being accelerated
2578 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2579 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2580 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2581 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2582 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2583 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2584 scripts/config.py unset MBEDTLS_GCM_C
2585 scripts/config.py unset MBEDTLS_CCM_C
2586 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2587 scripts/config.py unset MBEDTLS_CMAC_C
2588 scripts/config.py unset MBEDTLS_DES_C
2589 scripts/config.py unset MBEDTLS_AES_C
2590 scripts/config.py unset MBEDTLS_ARIA_C
2591 scripts/config.py unset MBEDTLS_CHACHA20_C
2592 scripts/config.py unset MBEDTLS_CAMELLIA_C
2593
2594 # Disable CIPHER_C entirely as all ciphers/AEADs are accelerated and PSA
2595 # does not depend on it.
2596 scripts/config.py unset MBEDTLS_CIPHER_C
2597
2598 # Build
2599 # -----
2600
2601 helper_libtestdriver1_make_drivers "$loc_accel_list"
2602
2603 helper_libtestdriver1_make_main "$loc_accel_list"
2604
2605 # Make sure this was not re-enabled by accident (additive config)
2606 not grep mbedtls_cipher library/cipher.o
2607 not grep mbedtls_des library/des.o
2608 not grep mbedtls_aes library/aes.o
2609 not grep mbedtls_aria library/aria.o
2610 not grep mbedtls_camellia library/camellia.o
2611 not grep mbedtls_ccm library/ccm.o
2612 not grep mbedtls_gcm library/gcm.o
2613 not grep mbedtls_chachapoly library/chachapoly.o
2614 not grep mbedtls_cmac library/cmac.o
2615
2616 # Run the tests
2617 # -------------
2618
2619 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
2620 make test
2621
2622 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
2623 tests/ssl-opt.sh
2624
2625 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
2626 tests/compat.sh -V NO -p mbedTLS
2627}
2628
2629component_test_psa_crypto_config_reference_cipher_aead_cmac () {
2630 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
2631 common_psa_crypto_config_accel_cipher_aead_cmac
2632
2633 make
2634
2635 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
2636 make test
2637
2638 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
2639 tests/ssl-opt.sh
2640
2641 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
2642 tests/compat.sh -V NO -p mbedTLS
2643}
2644
2645common_block_cipher_dispatch () {
2646 TEST_WITH_DRIVER="$1"
2647
2648 # Start from the full config
2649 helper_libtestdriver1_adjust_config "full"
2650
2651 if [ "$TEST_WITH_DRIVER" -eq 1 ]; then
2652 # Disable key types that are accelerated (there is no legacy equivalent
2653 # symbol for ECB)
2654 scripts/config.py unset MBEDTLS_AES_C
2655 scripts/config.py unset MBEDTLS_ARIA_C
2656 scripts/config.py unset MBEDTLS_CAMELLIA_C
2657 fi
2658
2659 # Disable cipher's modes that, when not accelerated, cause
2660 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
2661 # Keep this also in the reference component in order to skip the same tests
2662 # that were skipped in the accelerated one.
2663 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
2664 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
2665 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
2666 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
2667 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
2668 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
2669 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
2670 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
2671
2672 # Disable direct dependency on AES_C
2673 scripts/config.py unset MBEDTLS_NIST_KW_C
2674
2675 # Prevent the cipher module from using deprecated PSA path. The reason is
2676 # that otherwise there will be tests relying on "aes_info" (defined in
2677 # "cipher_wrap.c") whose functions are not available when AES_C is
2678 # not defined. ARIA and Camellia are not a problem in this case because
2679 # the PSA path is not tested for these key types.
2680 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
2681}
2682
Gilles Peskine9dc903a2024-06-21 11:25:01 +02002683component_test_full_block_cipher_psa_dispatch_static_keystore () {
2684 msg "build: full + PSA dispatch in block_cipher with static keystore"
2685 # Check that the static key store works well when CTR_DRBG uses a
2686 # PSA key for AES.
2687 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2688
2689 loc_accel_list="ALG_ECB_NO_PADDING \
2690 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2691
2692 # Configure
2693 # ---------
2694
2695 common_block_cipher_dispatch 1
2696
2697 # Build
2698 # -----
2699
2700 helper_libtestdriver1_make_drivers "$loc_accel_list"
2701
2702 helper_libtestdriver1_make_main "$loc_accel_list"
2703
2704 # Make sure disabled components were not re-enabled by accident (additive
2705 # config)
2706 not grep mbedtls_aes_ library/aes.o
2707 not grep mbedtls_aria_ library/aria.o
2708 not grep mbedtls_camellia_ library/camellia.o
2709
2710 # Run the tests
2711 # -------------
2712
2713 msg "test: full + PSA dispatch in block_cipher with static keystore"
2714 make test
2715}
2716
Minos Galanakis3ece57e2024-08-01 17:09:49 +01002717component_test_full_block_cipher_psa_dispatch () {
2718 msg "build: full + PSA dispatch in block_cipher"
2719
2720 loc_accel_list="ALG_ECB_NO_PADDING \
2721 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2722
2723 # Configure
2724 # ---------
2725
2726 common_block_cipher_dispatch 1
2727
2728 # Build
2729 # -----
2730
2731 helper_libtestdriver1_make_drivers "$loc_accel_list"
2732
2733 helper_libtestdriver1_make_main "$loc_accel_list"
2734
2735 # Make sure disabled components were not re-enabled by accident (additive
2736 # config)
2737 not grep mbedtls_aes_ library/aes.o
2738 not grep mbedtls_aria_ library/aria.o
2739 not grep mbedtls_camellia_ library/camellia.o
2740
2741 # Run the tests
2742 # -------------
2743
2744 msg "test: full + PSA dispatch in block_cipher"
2745 make test
2746}
2747
2748# This is the reference component of component_test_full_block_cipher_psa_dispatch
2749component_test_full_block_cipher_legacy_dispatch () {
2750 msg "build: full + legacy dispatch in block_cipher"
2751
2752 common_block_cipher_dispatch 0
2753
2754 make
2755
2756 msg "test: full + legacy dispatch in block_cipher"
2757 make test
2758}
2759
2760component_test_aead_chachapoly_disabled () {
2761 msg "build: full minus CHACHAPOLY"
2762 scripts/config.py full
2763 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2764 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2765 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2766
2767 msg "test: full minus CHACHAPOLY"
2768 make test
2769}
2770
2771component_test_aead_only_ccm () {
2772 msg "build: full minus CHACHAPOLY and GCM"
2773 scripts/config.py full
2774 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2775 scripts/config.py unset MBEDTLS_GCM_C
2776 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2777 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2778 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2779
2780 msg "test: full minus CHACHAPOLY and GCM"
2781 make test
2782}
2783
2784component_test_ccm_aes_sha256 () {
2785 msg "build: CCM + AES + SHA256 configuration"
2786
2787 cp "$CONFIG_TEST_DRIVER_H" "$CONFIG_H"
2788 cp configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
2789
2790 make
2791
2792 msg "test: CCM + AES + SHA256 configuration"
2793 make test
2794}
2795
2796# Test that the given .o file builds with all (valid) combinations of the given options.
2797#
2798# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
2799#
2800# The validator function is the name of a function to validate the combination of options.
2801# It may be "" if all combinations are valid.
2802# It receives a string containing a combination of options, as passed to the compiler,
2803# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
2804build_test_config_combos () {
2805 file=$1
2806 shift
2807 validate_options=$1
2808 shift
2809 options=("$@")
2810
2811 # clear all of the options so that they can be overridden on the clang commandline
2812 for opt in "${options[@]}"; do
2813 ./scripts/config.py unset ${opt}
2814 done
2815
2816 # enter the directory containing the target file & strip the dir from the filename
2817 cd $(dirname ${file})
2818 file=$(basename ${file})
2819
2820 # The most common issue is unused variables/functions, so ensure -Wunused is set.
2821 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
2822
2823 # Extract the command generated by the Makefile to build the target file.
2824 # This ensures that we have any include paths, macro definitions, etc
2825 # that may be applied by make.
2826 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
2827 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
2828
2829 makefile=$(TMPDIR=. mktemp)
2830 deps=""
2831
2832 len=${#options[@]}
2833 source_file=${file%.o}.c
2834
2835 targets=0
2836 echo 'include Makefile' >${makefile}
2837
2838 for ((i = 0; i < $((2**${len})); i++)); do
2839 # generate each of 2^n combinations of options
2840 # each bit of $i is used to determine if options[i] will be set or not
2841 target="t"
2842 clang_args=""
2843 for ((j = 0; j < ${len}; j++)); do
2844 if (((i >> j) & 1)); then
2845 opt=-D${options[$j]}
2846 clang_args="${clang_args} ${opt}"
2847 target="${target}${opt}"
2848 fi
2849 done
2850
2851 # if combination is not known to be invalid, add it to the makefile
2852 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
2853 cmd="${compile_cmd} ${clang_args}"
2854 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
2855
2856 deps="${deps} ${target}"
2857 ((++targets))
2858 fi
2859 done
2860
2861 echo "build_test_config_combos: ${deps}" >> ${makefile}
2862
2863 # execute all of the commands via Make (probably in parallel)
2864 make -s -f ${makefile} build_test_config_combos
2865 echo "$targets targets checked"
2866
2867 # clean up the temporary makefile
2868 rm ${makefile}
2869}
2870
2871validate_aes_config_variations () {
2872 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
2873 if [[ "$1" == *"MBEDTLS_PADLOCK_C"* ]]; then
2874 return 1
2875 fi
2876 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
2877 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
2878 return 1
2879 fi
2880 fi
2881 return 0
2882}
2883
2884component_build_aes_variations () {
2885 # 18s - around 90ms per clang invocation on M1 Pro
2886 #
2887 # aes.o has many #if defined(...) guards that intersect in complex ways.
2888 # Test that all the combinations build cleanly.
2889
2890 MBEDTLS_ROOT_DIR="$PWD"
2891 msg "build: aes.o for all combinations of relevant config options"
2892
2893 build_test_config_combos library/aes.o validate_aes_config_variations \
2894 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
2895 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
2896 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2897 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2898
2899 cd "$MBEDTLS_ROOT_DIR"
2900 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
2901
2902 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES,
2903 # manually set or unset those configurations to check
2904 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
2905 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
2906 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2907 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2908 scripts/config.py unset MBEDTLS_DES_C
2909 scripts/config.py unset MBEDTLS_NIST_KW_C
2910 build_test_config_combos library/aes.o validate_aes_config_variations \
2911 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
2912 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
2913 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2914 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2915}
2916
2917component_test_sha3_variations () {
2918 msg "sha3 loop unroll variations"
2919
2920 # define minimal config sufficient to test SHA3
2921 cat > include/mbedtls/mbedtls_config.h << END
2922 #define MBEDTLS_SELF_TEST
2923 #define MBEDTLS_SHA3_C
2924END
2925
2926 msg "all loops unrolled"
2927 make clean
2928 make -C 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"
2929 ./tests/test_suite_shax
2930
2931 msg "all loops rolled up"
2932 make clean
2933 make -C 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"
2934 ./tests/test_suite_shax
2935}
2936
2937# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2938component_build_aes_aesce_armcc () {
2939 msg "Build: AESCE test on arm64 platform without plain C."
2940 scripts/config.py baremetal
2941
2942 # armc[56] don't support SHA-512 intrinsics
2943 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2944
2945 # Stop armclang warning about feature detection for A64_CRYPTO.
2946 # With this enabled, the library does build correctly under armclang,
2947 # but in baremetal builds (as tested here), feature detection is
2948 # unavailable, and the user is notified via a #warning. So enabling
2949 # this feature would prevent us from building with -Werror on
2950 # armclang. Tracked in #7198.
2951 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2952 scripts/config.py set MBEDTLS_HAVE_ASM
2953
2954 msg "AESCE, build with default configuration."
2955 scripts/config.py set MBEDTLS_AESCE_C
2956 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard452db602024-10-01 13:01:54 +02002957 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01002958
2959 msg "AESCE, build AESCE only"
2960 scripts/config.py set MBEDTLS_AESCE_C
2961 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard452db602024-10-01 13:01:54 +02002962 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01002963}
2964
2965support_build_aes_aesce_armcc () {
2966 support_build_armcc
2967}
2968
2969component_test_aes_only_128_bit_keys () {
2970 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2971 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2972 scripts/config.py unset MBEDTLS_PADLOCK_C
2973
2974 make CFLAGS='-O2 -Werror -Wall -Wextra'
2975
2976 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2977 make test
2978}
2979
2980component_test_no_ctr_drbg_aes_only_128_bit_keys () {
2981 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2982 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2983 scripts/config.py unset MBEDTLS_CTR_DRBG_C
2984 scripts/config.py unset MBEDTLS_PADLOCK_C
2985
2986 make CC=clang CFLAGS='-Werror -Wall -Wextra'
2987
2988 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2989 make test
2990}
2991
2992component_test_aes_only_128_bit_keys_have_builtins () {
2993 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2994 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2995 scripts/config.py unset MBEDTLS_PADLOCK_C
2996 scripts/config.py unset MBEDTLS_AESNI_C
2997 scripts/config.py unset MBEDTLS_AESCE_C
2998
2999 make CFLAGS='-O2 -Werror -Wall -Wextra'
3000
3001 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
3002 make test
3003
3004 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
3005 programs/test/selftest
3006}
3007
3008component_test_gcm_largetable () {
3009 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
3010 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
3011 scripts/config.py unset MBEDTLS_PADLOCK_C
3012 scripts/config.py unset MBEDTLS_AESNI_C
3013 scripts/config.py unset MBEDTLS_AESCE_C
3014
3015 make CFLAGS='-O2 -Werror -Wall -Wextra'
3016
3017 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
3018 make test
3019}
3020
3021component_test_aes_fewer_tables () {
3022 msg "build: default config with AES_FEWER_TABLES enabled"
3023 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
3024 make CFLAGS='-O2 -Werror -Wall -Wextra'
3025
3026 msg "test: AES_FEWER_TABLES"
3027 make test
3028}
3029
3030component_test_aes_rom_tables () {
3031 msg "build: default config with AES_ROM_TABLES enabled"
3032 scripts/config.py set MBEDTLS_AES_ROM_TABLES
3033 make CFLAGS='-O2 -Werror -Wall -Wextra'
3034
3035 msg "test: AES_ROM_TABLES"
3036 make test
3037}
3038
3039component_test_aes_fewer_tables_and_rom_tables () {
3040 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
3041 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
3042 scripts/config.py set MBEDTLS_AES_ROM_TABLES
3043 make CFLAGS='-O2 -Werror -Wall -Wextra'
3044
3045 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
3046 make test
3047}
3048
3049# helper for common_block_cipher_no_decrypt() which:
3050# - enable/disable the list of config options passed from -s/-u respectively.
3051# - build
3052# - test for tests_suite_xxx
3053# - selftest
3054#
3055# Usage: helper_block_cipher_no_decrypt_build_test
3056# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
3057# Options: -s set_opts the list of config options to enable
3058# -u unset_opts the list of config options to disable
3059# -c cflags the list of options passed to CFLAGS
3060# -l ldflags the list of options passed to LDFLAGS
3061helper_block_cipher_no_decrypt_build_test () {
3062 while [ $# -gt 0 ]; do
3063 case "$1" in
3064 -s)
3065 shift; local set_opts="$1";;
3066 -u)
3067 shift; local unset_opts="$1";;
3068 -c)
3069 shift; local cflags="-Werror -Wall -Wextra $1";;
3070 -l)
3071 shift; local ldflags="$1";;
3072 esac
3073 shift
3074 done
3075 set_opts="${set_opts:-}"
3076 unset_opts="${unset_opts:-}"
3077 cflags="${cflags:-}"
3078 ldflags="${ldflags:-}"
3079
3080 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
3081 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
3082
3083 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
3084 make clean
3085 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
3086
3087 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
3088 not grep mbedtls_aes_setkey_dec library/aes.o
3089 not grep mbedtls_aria_setkey_dec library/aria.o
3090 not grep mbedtls_camellia_setkey_dec library/camellia.o
3091 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
3092 not grep mbedtls_internal_aes_decrypt library/aes.o
3093 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
3094 not grep mbedtls_aesni_inverse_key library/aesni.o
3095
3096 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
3097 make test
3098
3099 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
3100 programs/test/selftest
3101}
3102
3103# This is a common configuration function used in:
3104# - component_test_block_cipher_no_decrypt_aesni_legacy()
3105# - component_test_block_cipher_no_decrypt_aesni_use_psa()
3106# in order to test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics,
3107# AESNI assembly and AES C implementation on x86_64 and with AESNI intrinsics
3108# on x86.
3109common_block_cipher_no_decrypt () {
3110 # test AESNI intrinsics
3111 helper_block_cipher_no_decrypt_build_test \
3112 -s "MBEDTLS_AESNI_C" \
3113 -c "-mpclmul -msse2 -maes"
3114
3115 # test AESNI assembly
3116 helper_block_cipher_no_decrypt_build_test \
3117 -s "MBEDTLS_AESNI_C" \
3118 -c "-mno-pclmul -mno-sse2 -mno-aes"
3119
3120 # test AES C implementation
3121 helper_block_cipher_no_decrypt_build_test \
3122 -u "MBEDTLS_AESNI_C"
3123
3124 # test AESNI intrinsics for i386 target
3125 helper_block_cipher_no_decrypt_build_test \
3126 -s "MBEDTLS_AESNI_C" \
3127 -c "-m32 -mpclmul -msse2 -maes" \
3128 -l "-m32"
3129}
3130
3131# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
3132# usage: 0: no PSA crypto configuration
3133# 1: use PSA crypto configuration
3134config_block_cipher_no_decrypt () {
3135 use_psa=$1
3136
3137 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
3138 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3139 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
3140 scripts/config.py unset MBEDTLS_DES_C
3141 scripts/config.py unset MBEDTLS_NIST_KW_C
3142
3143 if [ "$use_psa" -eq 1 ]; then
3144 # Enable support for cryptographic mechanisms through the PSA API.
3145 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
3146 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3147 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
3148 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
3149 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
3150 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
3151 fi
3152}
3153
3154component_test_block_cipher_no_decrypt_aesni () {
3155 # This consistently causes an llvm crash on clang 3.8, so use gcc
3156 export CC=gcc
3157 config_block_cipher_no_decrypt 0
3158 common_block_cipher_no_decrypt
3159}
3160
3161component_test_block_cipher_no_decrypt_aesni_use_psa () {
3162 # This consistently causes an llvm crash on clang 3.8, so use gcc
3163 export CC=gcc
3164 config_block_cipher_no_decrypt 1
3165 common_block_cipher_no_decrypt
3166}
3167
3168support_test_block_cipher_no_decrypt_aesce_armcc () {
3169 support_build_armcc
3170}
3171
3172component_test_block_cipher_no_decrypt_aesce_armcc () {
3173 scripts/config.py baremetal
3174
3175 # armc[56] don't support SHA-512 intrinsics
3176 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
3177
3178 # Stop armclang warning about feature detection for A64_CRYPTO.
3179 # With this enabled, the library does build correctly under armclang,
3180 # but in baremetal builds (as tested here), feature detection is
3181 # unavailable, and the user is notified via a #warning. So enabling
3182 # this feature would prevent us from building with -Werror on
3183 # armclang. Tracked in #7198.
3184 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
3185 scripts/config.py set MBEDTLS_HAVE_ASM
3186
3187 config_block_cipher_no_decrypt 1
3188
3189 # test AESCE baremetal build
3190 scripts/config.py set MBEDTLS_AESCE_C
3191 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
Manuel Pégourié-Gonnard452db602024-10-01 13:01:54 +02003192 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01003193
3194 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
3195 not grep mbedtls_aes_setkey_dec library/aes.o
3196 not grep mbedtls_aria_setkey_dec library/aria.o
3197 not grep mbedtls_camellia_setkey_dec library/camellia.o
3198 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
3199 not grep mbedtls_internal_aes_decrypt library/aes.o
3200 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
3201 not grep mbedtls_aesce_inverse_key library/aesce.o
3202 not grep aesce_decrypt_block library/aesce.o
3203}
3204
3205component_test_ctr_drbg_aes_256_sha_256 () {
3206 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
3207 scripts/config.py full
3208 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
3209 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
3210 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3211 make
3212
3213 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
3214 make test
3215}
3216
3217component_test_ctr_drbg_aes_128_sha_512 () {
3218 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
3219 scripts/config.py full
3220 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
3221 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
3222 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3223 make
3224
3225 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
3226 make test
3227}
3228
3229component_test_ctr_drbg_aes_128_sha_256 () {
3230 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
3231 scripts/config.py full
3232 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
3233 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
3234 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
3235 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3236 make
3237
3238 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
3239 make test
3240}
3241
3242component_test_se_default () {
3243 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
3244 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
3245 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
3246
3247 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
3248 make test
3249}
3250
Gilles Peskine9dc903a2024-06-21 11:25:01 +02003251component_test_full_static_keystore () {
3252 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
3253 scripts/config.py full
3254 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
3255 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
3256
3257 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
3258 make test
3259}
3260
Minos Galanakis3ece57e2024-08-01 17:09:49 +01003261component_test_psa_crypto_drivers () {
3262 msg "build: full + test drivers dispatching to builtins"
3263 scripts/config.py full
3264 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
3265 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
3266 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
David Horstmanndcf42a02024-11-08 14:40:12 +00003267 loc_cflags="${loc_cflags} -I../framework/tests/include -O2"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01003268
3269 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
3270
3271 msg "test: full + test drivers dispatching to builtins"
3272 make test
3273}
3274
3275component_build_psa_config_file () {
3276 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
3277 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3278 cp "$CRYPTO_CONFIG_H" psa_test_config.h
3279 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
3280 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
3281 # Make sure this feature is enabled. We'll disable it in the next phase.
3282 programs/test/query_compile_time_config MBEDTLS_CMAC_C
3283 make clean
3284
3285 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
3286 # In the user config, disable one feature and its dependencies, which will
3287 # reflect on the mbedtls configuration so we can query it with
3288 # query_compile_time_config.
3289 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
3290 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
3291 scripts/config.py unset MBEDTLS_CMAC_C
3292 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
3293 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
3294
3295 rm -f psa_test_config.h psa_user_config.h
3296}
3297
3298component_build_psa_alt_headers () {
3299 msg "build: make with PSA alt headers" # ~20s
3300
3301 # Generate alternative versions of the substitutable headers with the
3302 # same content except different include guards.
David Horstmannb19374f2024-11-07 17:08:11 +00003303 make -C tests ../framework/tests/include/alt-extra/psa/crypto_platform_alt.h ../framework/tests/include/alt-extra/psa/crypto_struct_alt.h
Minos Galanakis3ece57e2024-08-01 17:09:49 +01003304
3305 # Build the library and some programs.
3306 # Don't build the fuzzers to avoid having to go through hoops to set
3307 # a correct include path for programs/fuzz/Makefile.
David Horstmanndcf42a02024-11-08 14:40:12 +00003308 make CFLAGS="-I ../framework/tests/include/alt-extra -DMBEDTLS_PSA_CRYPTO_PLATFORM_FILE='\"psa/crypto_platform_alt.h\"' -DMBEDTLS_PSA_CRYPTO_STRUCT_FILE='\"psa/crypto_struct_alt.h\"'" lib
3309 make -C programs -o fuzz CFLAGS="-I ../framework/tests/include/alt-extra -DMBEDTLS_PSA_CRYPTO_PLATFORM_FILE='\"psa/crypto_platform_alt.h\"' -DMBEDTLS_PSA_CRYPTO_STRUCT_FILE='\"psa/crypto_struct_alt.h\"'"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01003310
3311 # Check that we're getting the alternative include guards and not the
3312 # original include guards.
3313 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
3314 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
3315 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
3316 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
3317}
3318
3319component_test_min_mpi_window_size () {
3320 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
3321 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
3322 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3323 make
3324
3325 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
3326 make test
3327}