blob: 04c38f6c36315c2b506d6244c78d77491b624415 [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
1296 helper_libtestdriver1_make_main "$loc_accel_list"
1297
1298 # We expect ECDH to be re-enabled for the missing curves
1299 grep mbedtls_ecdh_ library/ecdh.o
1300 # We expect ECP to be re-enabled, however the parts specific to the
1301 # families of curves that are accelerated should be ommited.
1302 # - functions with mxz in the name are specific to Montgomery curves
1303 # - ecp_muladd is specific to Weierstrass curves
1304 ##nm library/ecp.o | tee ecp.syms
1305 if [ $weierstrass -eq 1 ]; then
1306 not grep mbedtls_ecp_muladd library/ecp.o
1307 grep mxz library/ecp.o
1308 else
1309 grep mbedtls_ecp_muladd library/ecp.o
1310 not grep mxz library/ecp.o
1311 fi
1312 # We expect ECDSA and ECJPAKE to be re-enabled only when
1313 # Weierstrass curves are not accelerated
1314 if [ $weierstrass -eq 1 ]; then
1315 not grep mbedtls_ecdsa library/ecdsa.o
1316 not grep mbedtls_ecjpake library/ecjpake.o
1317 else
1318 grep mbedtls_ecdsa library/ecdsa.o
1319 grep mbedtls_ecjpake library/ecjpake.o
1320 fi
1321
1322 # Run the tests
1323 # -------------
1324
1325 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
1326 make test
1327}
1328
1329component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
1330 common_test_psa_crypto_config_accel_ecc_some_curves 1
1331}
1332
1333component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
1334 common_test_psa_crypto_config_accel_ecc_some_curves 0
1335}
1336
1337# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
1338# ECDH, ECDSA) with and without drivers.
1339# The input parameter is a boolean value which indicates:
1340# - 0 keep built-in EC algs,
1341# - 1 exclude built-in EC algs (driver only).
1342#
1343# This is used by the two following components to ensure they always use the
1344# same config, except for the use of driver or built-in EC algorithms:
1345# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
1346# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
1347# This supports comparing their test coverage with analyze_outcomes.py.
1348config_psa_crypto_config_ecp_light_only () {
1349 driver_only="$1"
1350 # start with config full for maximum coverage (also enables USE_PSA)
1351 helper_libtestdriver1_adjust_config "full"
1352 if [ "$driver_only" -eq 1 ]; then
1353 # Disable modules that are accelerated
1354 scripts/config.py unset MBEDTLS_ECDSA_C
1355 scripts/config.py unset MBEDTLS_ECDH_C
1356 scripts/config.py unset MBEDTLS_ECJPAKE_C
1357 scripts/config.py unset MBEDTLS_ECP_C
1358 fi
1359
1360 # Restartable feature is not yet supported by PSA. Once it will in
1361 # the future, the following line could be removed (see issues
1362 # 6061, 6332 and following ones)
1363 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1364}
1365
1366# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
1367component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
1368 msg "build: full with accelerated EC algs"
1369
1370 # Algorithms and key types to accelerate
1371 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1372 ALG_ECDH \
1373 ALG_JPAKE \
1374 $(helper_get_psa_key_type_list "ECC") \
1375 $(helper_get_psa_curve_list)"
1376
1377 # Configure
1378 # ---------
1379
1380 # Use the same config as reference, only without built-in EC algs
1381 config_psa_crypto_config_ecp_light_only 1
1382
1383 # Do not disable builtin curves because that support is required for:
1384 # - MBEDTLS_PK_PARSE_EC_EXTENDED
1385 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
1386
1387 # Build
1388 # -----
1389
1390 # These hashes are needed for some ECDSA signature tests.
1391 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1392 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1393 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1394
1395 helper_libtestdriver1_make_main "$loc_accel_list"
1396
1397 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1398 not grep mbedtls_ecdsa_ library/ecdsa.o
1399 not grep mbedtls_ecdh_ library/ecdh.o
1400 not grep mbedtls_ecjpake_ library/ecjpake.o
1401 not grep mbedtls_ecp_mul library/ecp.o
1402
1403 # Run the tests
1404 # -------------
1405
1406 msg "test suites: full with accelerated EC algs"
1407 make test
1408
1409 msg "ssl-opt: full with accelerated EC algs"
1410 tests/ssl-opt.sh
1411}
1412
1413# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
1414component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
1415 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated EC algs"
1416
1417 config_psa_crypto_config_ecp_light_only 0
1418
1419 make
1420
1421 msg "test suites: full with non-accelerated EC algs"
1422 make test
1423
1424 msg "ssl-opt: full with non-accelerated EC algs"
1425 tests/ssl-opt.sh
1426}
1427
1428# This helper function is used by:
1429# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
1430# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
1431# to ensure that both tests use the same underlying configuration when testing
1432# driver's coverage with analyze_outcomes.py.
1433#
1434# This functions accepts 1 boolean parameter as follows:
1435# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
1436# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
1437# - 0: include built-in implementation of EC algorithms.
1438#
1439# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
1440# on the ECP module.
1441config_psa_crypto_no_ecp_at_all () {
1442 driver_only="$1"
1443 # start with full config for maximum coverage (also enables USE_PSA)
1444 helper_libtestdriver1_adjust_config "full"
1445
1446 if [ "$driver_only" -eq 1 ]; then
1447 # Disable modules that are accelerated
1448 scripts/config.py unset MBEDTLS_ECDSA_C
1449 scripts/config.py unset MBEDTLS_ECDH_C
1450 scripts/config.py unset MBEDTLS_ECJPAKE_C
1451 # Disable ECP module (entirely)
1452 scripts/config.py unset MBEDTLS_ECP_C
1453 fi
1454
1455 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1456 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1457 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1458 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1459
1460 # Restartable feature is not yet supported by PSA. Once it will in
1461 # the future, the following line could be removed (see issues
1462 # 6061, 6332 and following ones)
1463 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1464}
1465
1466# Build and test a configuration where driver accelerates all EC algs while
1467# all support and dependencies from ECP and ECP_LIGHT are removed on the library
1468# side.
1469#
1470# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
1471component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
1472 msg "build: full + accelerated EC algs - ECP"
1473
1474 # Algorithms and key types to accelerate
1475 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1476 ALG_ECDH \
1477 ALG_JPAKE \
1478 $(helper_get_psa_key_type_list "ECC") \
1479 $(helper_get_psa_curve_list)"
1480
1481 # Configure
1482 # ---------
1483
1484 # Set common configurations between library's and driver's builds
1485 config_psa_crypto_no_ecp_at_all 1
1486 # Disable all the builtin curves. All the required algs are accelerated.
1487 helper_disable_builtin_curves
1488
1489 # Build
1490 # -----
1491
1492 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1493 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1494 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1495 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1496
1497 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1498
1499 helper_libtestdriver1_make_main "$loc_accel_list"
1500
1501 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1502 not grep mbedtls_ecdsa_ library/ecdsa.o
1503 not grep mbedtls_ecdh_ library/ecdh.o
1504 not grep mbedtls_ecjpake_ library/ecjpake.o
1505 # Also ensure that ECP module was not re-enabled
1506 not grep mbedtls_ecp_ library/ecp.o
1507
1508 # Run the tests
1509 # -------------
1510
1511 msg "test: full + accelerated EC algs - ECP"
1512 make test
1513
1514 msg "ssl-opt: full + accelerated EC algs - ECP"
1515 tests/ssl-opt.sh
1516}
1517
1518# Reference function used for driver's coverage analysis in analyze_outcomes.py
1519# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
1520# Keep in sync with its accelerated counterpart.
1521component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
1522 msg "build: full + non accelerated EC algs"
1523
1524 config_psa_crypto_no_ecp_at_all 0
1525
1526 make
1527
1528 msg "test: full + non accelerated EC algs"
1529 make test
1530
1531 msg "ssl-opt: full + non accelerated EC algs"
1532 tests/ssl-opt.sh
1533}
1534
1535# This is a common configuration helper used directly from:
1536# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1537# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1538# and indirectly from:
1539# - component_test_psa_crypto_config_accel_ecc_no_bignum
1540# - accelerate all EC algs, disable RSA and FFDH
1541# - component_test_psa_crypto_config_reference_ecc_no_bignum
1542# - this is the reference component of the above
1543# - it still disables RSA and FFDH, but it uses builtin EC algs
1544# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1545# - accelerate all EC and FFDH algs, disable only RSA
1546# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1547# - this is the reference component of the above
1548# - it still disables RSA, but it uses builtin EC and FFDH algs
1549#
1550# This function accepts 2 parameters:
1551# $1: a boolean value which states if we are testing an accelerated scenario
1552# or not.
1553# $2: a string value which states which components are tested. Allowed values
1554# are "ECC" or "ECC_DH".
1555config_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1556 driver_only="$1"
1557 test_target="$2"
1558 # start with full config for maximum coverage (also enables USE_PSA)
1559 helper_libtestdriver1_adjust_config "full"
1560
1561 if [ "$driver_only" -eq 1 ]; then
1562 # Disable modules that are accelerated
1563 scripts/config.py unset MBEDTLS_ECDSA_C
1564 scripts/config.py unset MBEDTLS_ECDH_C
1565 scripts/config.py unset MBEDTLS_ECJPAKE_C
1566 # Disable ECP module (entirely)
1567 scripts/config.py unset MBEDTLS_ECP_C
1568 # Also disable bignum
1569 scripts/config.py unset MBEDTLS_BIGNUM_C
1570 fi
1571
1572 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1573 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1574 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1575 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1576
1577 # RSA support is intentionally disabled on this test because RSA_C depends
1578 # on BIGNUM_C.
1579 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
1580 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
1581 scripts/config.py unset MBEDTLS_RSA_C
1582 scripts/config.py unset MBEDTLS_PKCS1_V15
1583 scripts/config.py unset MBEDTLS_PKCS1_V21
1584 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1585 # Also disable key exchanges that depend on RSA
1586 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1587 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1588 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1589 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1590 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1591
1592 if [ "$test_target" = "ECC" ]; then
1593 # When testing ECC only, we disable FFDH support, both from builtin and
1594 # PSA sides, and also disable the key exchanges that depend on DHM.
1595 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_FFDH
1596 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
1597 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
1598 scripts/config.py unset MBEDTLS_DHM_C
1599 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1600 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1601 else
1602 # When testing ECC and DH instead, we disable DHM and depending key
1603 # exchanges only in the accelerated build
1604 if [ "$driver_only" -eq 1 ]; then
1605 scripts/config.py unset MBEDTLS_DHM_C
1606 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1607 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1608 fi
1609 fi
1610
1611 # Restartable feature is not yet supported by PSA. Once it will in
1612 # the future, the following line could be removed (see issues
1613 # 6061, 6332 and following ones)
1614 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1615}
1616
1617# Common helper used by:
1618# - component_test_psa_crypto_config_accel_ecc_no_bignum
1619# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1620#
1621# The goal is to build and test accelerating either:
1622# - ECC only or
1623# - both ECC and FFDH
1624#
1625# It is meant to be used in conjunction with
1626# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
1627# coverage analysis in the "analyze_outcomes.py" script.
1628common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1629 test_target="$1"
1630
1631 # This is an internal helper to simplify text message handling
1632 if [ "$test_target" = "ECC_DH" ]; then
1633 accel_text="ECC/FFDH"
1634 removed_text="ECP - DH"
1635 else
1636 accel_text="ECC"
1637 removed_text="ECP"
1638 fi
1639
1640 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1641
1642 # By default we accelerate all EC keys/algs
1643 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1644 ALG_ECDH \
1645 ALG_JPAKE \
1646 $(helper_get_psa_key_type_list "ECC") \
1647 $(helper_get_psa_curve_list)"
1648 # Optionally we can also add DH to the list of accelerated items
1649 if [ "$test_target" = "ECC_DH" ]; then
1650 loc_accel_list="$loc_accel_list \
1651 ALG_FFDH \
1652 $(helper_get_psa_key_type_list "DH") \
1653 $(helper_get_psa_dh_group_list)"
1654 fi
1655
1656 # Configure
1657 # ---------
1658
1659 # Set common configurations between library's and driver's builds
1660 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
1661 # Disable all the builtin curves. All the required algs are accelerated.
1662 helper_disable_builtin_curves
1663
1664 # Build
1665 # -----
1666
1667 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1668 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1669 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1670 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1671
1672 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1673
1674 helper_libtestdriver1_make_main "$loc_accel_list"
1675
1676 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1677 not grep mbedtls_ecdsa_ library/ecdsa.o
1678 not grep mbedtls_ecdh_ library/ecdh.o
1679 not grep mbedtls_ecjpake_ library/ecjpake.o
1680 # Also ensure that ECP, RSA, [DHM] or BIGNUM modules were not re-enabled
1681 not grep mbedtls_ecp_ library/ecp.o
1682 not grep mbedtls_rsa_ library/rsa.o
1683 not grep mbedtls_mpi_ library/bignum.o
1684 not grep mbedtls_dhm_ library/dhm.o
1685
1686 # Run the tests
1687 # -------------
1688
1689 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - DHM - BIGNUM"
1690
1691 make test
1692
1693 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1694 tests/ssl-opt.sh
1695}
1696
1697# Common helper used by:
1698# - component_test_psa_crypto_config_reference_ecc_no_bignum
1699# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1700#
1701# The goal is to build and test a reference scenario (i.e. with builtin
1702# components) compared to the ones used in
1703# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
1704#
1705# It is meant to be used in conjunction with
1706# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
1707# coverage analysis in "analyze_outcomes.py" script.
1708common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1709 test_target="$1"
1710
1711 # This is an internal helper to simplify text message handling
1712 if [ "$test_target" = "ECC_DH" ]; then
1713 accel_text="ECC/FFDH"
1714 else
1715 accel_text="ECC"
1716 fi
1717
1718 msg "build: full + non accelerated $accel_text algs + USE_PSA"
1719
1720 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
1721
1722 make
1723
1724 msg "test suites: full + non accelerated EC algs + USE_PSA"
1725 make test
1726
1727 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
1728 tests/ssl-opt.sh
1729}
1730
1731component_test_psa_crypto_config_accel_ecc_no_bignum () {
1732 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
1733}
1734
1735component_test_psa_crypto_config_reference_ecc_no_bignum () {
1736 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
1737}
1738
1739component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1740 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
1741}
1742
1743component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1744 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
1745}
1746
Gilles Peskineced0edc2024-09-14 11:35:36 +02001747component_test_tfm_config_as_is () {
1748 msg "build: configs/config-tfm.h"
1749 cp configs/config-tfm.h "$CONFIG_H"
1750 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1751 make
1752
1753 msg "test: configs/config-tfm.h - unit tests"
1754 make test
1755}
1756
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001757# Helper for setting common configurations between:
1758# - component_test_tfm_config_p256m_driver_accel_ec()
Gilles Peskineced0edc2024-09-14 11:35:36 +02001759# - component_test_tfm_config_no_p256m()
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001760common_tfm_config () {
1761 # Enable TF-M config
1762 cp configs/config-tfm.h "$CONFIG_H"
1763 echo "#undef MBEDTLS_PSA_CRYPTO_CONFIG_FILE" >> "$CONFIG_H"
1764 cp configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
1765
1766 # Other config adjustment to make the tests pass.
1767 # This should probably be adopted upstream.
1768 #
1769 # - USE_PSA_CRYPTO for PK_HAVE_ECC_KEYS
1770 echo "#define MBEDTLS_USE_PSA_CRYPTO" >> "$CONFIG_H"
1771
1772 # Config adjustment for better test coverage in our environment.
1773 # This is not needed just to build and pass tests.
1774 #
1775 # Enable filesystem I/O for the benefit of PK parse/write tests.
1776 echo "#define MBEDTLS_FS_IO" >> "$CONFIG_H"
1777}
1778
1779# Keep this in sync with component_test_tfm_config() as they are both meant
1780# to be used in analyze_outcomes.py for driver's coverage analysis.
1781component_test_tfm_config_p256m_driver_accel_ec () {
1782 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1783
1784 common_tfm_config
1785
1786 # Build crypto library
David Horstmanndcf42a02024-11-08 14:40:12 +00001787 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../framework/tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001788
1789 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1790 not grep mbedtls_ecdsa_ library/ecdsa.o
1791 not grep mbedtls_ecdh_ library/ecdh.o
1792 not grep mbedtls_ecjpake_ library/ecjpake.o
1793 # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
1794 not grep mbedtls_ecp_ library/ecp.o
1795 not grep mbedtls_rsa_ library/rsa.o
1796 not grep mbedtls_dhm_ library/dhm.o
1797 not grep mbedtls_mpi_ library/bignum.o
1798 # Check that p256m was built
1799 grep -q p256_ecdsa_ library/libmbedcrypto.a
1800
1801 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1802 # files, so we want to ensure that it has not be re-enabled accidentally.
1803 not grep mbedtls_cipher library/cipher.o
1804
1805 # Run the tests
1806 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1807 make test
1808}
1809
1810# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1811# they are both meant to be used in analyze_outcomes.py for driver's coverage
1812# analysis.
Gilles Peskineced0edc2024-09-14 11:35:36 +02001813component_test_tfm_config_no_p256m () {
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001814 common_tfm_config
1815
1816 # Disable P256M driver, which is on by default, so that analyze_outcomes
1817 # can compare this test with test_tfm_config_p256m_driver_accel_ec
1818 echo "#undef MBEDTLS_PSA_P256M_DRIVER_ENABLED" >> "$CONFIG_H"
1819
Gilles Peskineced0edc2024-09-14 11:35:36 +02001820 msg "build: TF-M config without p256m"
David Horstmanndcf42a02024-11-08 14:40:12 +00001821 make CFLAGS='-Werror -Wall -Wextra -I../framework/tests/include/spe' tests
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001822
1823 # Check that p256m was not built
1824 not grep p256_ecdsa_ library/libmbedcrypto.a
1825
1826 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1827 # files, so we want to ensure that it has not be re-enabled accidentally.
1828 not grep mbedtls_cipher library/cipher.o
1829
Gilles Peskineced0edc2024-09-14 11:35:36 +02001830 msg "test: TF-M config without p256m"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001831 make test
1832}
1833
1834# This is an helper used by:
1835# - component_test_psa_ecc_key_pair_no_derive
1836# - component_test_psa_ecc_key_pair_no_generate
1837# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1838# enabled, but one. Input arguments are as follows:
1839# - $1 is the key type under test, i.e. ECC/RSA/DH
1840# - $2 is the key option to be unset (i.e. generate, derive, etc)
1841build_and_test_psa_want_key_pair_partial () {
1842 key_type=$1
1843 unset_option=$2
1844 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1845
1846 msg "build: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
1847 scripts/config.py full
1848 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1849 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1850
1851 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1852 # crypto_config.h so we just disable the one we don't want.
1853 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
1854
1855 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1856
1857 msg "test: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
1858 make test
1859}
1860
1861component_test_psa_ecc_key_pair_no_derive () {
1862 build_and_test_psa_want_key_pair_partial "ECC" "DERIVE"
1863}
1864
1865component_test_psa_ecc_key_pair_no_generate () {
1866 build_and_test_psa_want_key_pair_partial "ECC" "GENERATE"
1867}
1868
1869config_psa_crypto_accel_rsa () {
1870 driver_only=$1
1871
1872 # Start from crypto_full config (no X.509, no TLS)
Manuel Pégourié-Gonnardb50b6382024-07-23 10:12:01 +02001873 # Note: PK will be ignored when comparing driver to reference in
1874 # analyze_outcomes.py
Minos Galanakis3ece57e2024-08-01 17:09:49 +01001875 helper_libtestdriver1_adjust_config "crypto_full"
1876
1877 if [ "$driver_only" -eq 1 ]; then
1878 # Remove RSA support and its dependencies
1879 scripts/config.py unset MBEDTLS_RSA_C
1880 scripts/config.py unset MBEDTLS_PKCS1_V15
1881 scripts/config.py unset MBEDTLS_PKCS1_V21
1882
1883 # We need PEM parsing in the test library as well to support the import
1884 # of PEM encoded RSA keys.
1885 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1886 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
1887 fi
1888}
1889
1890component_test_psa_crypto_config_accel_rsa_crypto () {
1891 msg "build: crypto_full with accelerated RSA"
1892
1893 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1894 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1895 KEY_TYPE_RSA_PUBLIC_KEY \
1896 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1897 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1898 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1899 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1900
1901 # Configure
1902 # ---------
1903
1904 config_psa_crypto_accel_rsa 1
1905
1906 # Build
1907 # -----
1908
1909 # These hashes are needed for unit tests.
1910 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1911 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1912 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1913
1914 helper_libtestdriver1_make_main "$loc_accel_list"
1915
1916 # Make sure this was not re-enabled by accident (additive config)
1917 not grep mbedtls_rsa library/rsa.o
1918
1919 # Run the tests
1920 # -------------
1921
1922 msg "test: crypto_full with accelerated RSA"
1923 make test
1924}
1925
1926component_test_psa_crypto_config_reference_rsa_crypto () {
1927 msg "build: crypto_full with non-accelerated RSA"
1928
1929 # Configure
1930 # ---------
1931 config_psa_crypto_accel_rsa 0
1932
1933 # Build
1934 # -----
1935 make
1936
1937 # Run the tests
1938 # -------------
1939 msg "test: crypto_full with non-accelerated RSA"
1940 make test
1941}
1942
1943# This is a temporary test to verify that full RSA support is present even when
1944# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
1945component_test_new_psa_want_key_pair_symbol () {
1946 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1947
1948 # Create a temporary output file unless there is already one set
1949 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1950 REMOVE_OUTCOME_ON_EXIT="no"
1951 else
1952 REMOVE_OUTCOME_ON_EXIT="yes"
1953 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1954 export MBEDTLS_TEST_OUTCOME_FILE
1955 fi
1956
1957 # Start from crypto configuration
1958 scripts/config.py crypto
1959
1960 # Remove RSA support and its dependencies
1961 scripts/config.py unset MBEDTLS_PKCS1_V15
1962 scripts/config.py unset MBEDTLS_PKCS1_V21
1963 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1964 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1965 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1966 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1967 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1968 scripts/config.py unset MBEDTLS_RSA_C
1969 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1970
1971 # Enable PSA support
1972 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1973
1974 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
1975 # that proper translations is done in crypto_legacy.h.
1976 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
1977 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
1978 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
1979
1980 make
1981
1982 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1983 make test
1984
1985 # Parse only 1 relevant line from the outcome file, i.e. a test which is
1986 # performing RSA signature.
1987 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
1988 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
1989
1990 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
1991 rm $MBEDTLS_TEST_OUTCOME_FILE
1992 fi
1993}
1994
1995component_test_psa_crypto_config_accel_hash () {
1996 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
1997
1998 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1999 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2000 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2001
2002 # Configure
2003 # ---------
2004
2005 # Start from default config (no USE_PSA)
2006 helper_libtestdriver1_adjust_config "default"
2007
2008 # Disable the things that are being accelerated
2009 scripts/config.py unset MBEDTLS_MD5_C
2010 scripts/config.py unset MBEDTLS_RIPEMD160_C
2011 scripts/config.py unset MBEDTLS_SHA1_C
2012 scripts/config.py unset MBEDTLS_SHA224_C
2013 scripts/config.py unset MBEDTLS_SHA256_C
2014 scripts/config.py unset MBEDTLS_SHA384_C
2015 scripts/config.py unset MBEDTLS_SHA512_C
2016 scripts/config.py unset MBEDTLS_SHA3_C
2017
2018 # Build
2019 # -----
2020
2021 helper_libtestdriver1_make_drivers "$loc_accel_list"
2022
2023 helper_libtestdriver1_make_main "$loc_accel_list"
2024
2025 # There's a risk of something getting re-enabled via config_psa.h;
2026 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
2027 not grep mbedtls_md5 library/md5.o
2028 not grep mbedtls_sha1 library/sha1.o
2029 not grep mbedtls_sha256 library/sha256.o
2030 not grep mbedtls_sha512 library/sha512.o
2031 not grep mbedtls_ripemd160 library/ripemd160.o
2032
2033 # Run the tests
2034 # -------------
2035
2036 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2037 make test
2038}
2039
Minos Galanakis5f6d2e32024-08-01 23:19:50 +01002040component_test_psa_crypto_config_accel_hash_keep_builtins () {
2041 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
2042 # This component ensures that all the test cases for
2043 # md_psa_dynamic_dispatch with legacy+driver in test_suite_md are run.
2044
2045 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
2046 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2047 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2048
2049 # Start from default config (no USE_PSA)
2050 helper_libtestdriver1_adjust_config "default"
2051
2052 helper_libtestdriver1_make_drivers "$loc_accel_list"
2053
2054 helper_libtestdriver1_make_main "$loc_accel_list"
2055
2056 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
2057 make test
2058}
2059
2060# This should be renamed to test and updated once the accelerator ECDH code is in place and ready to test.
2061component_build_psa_accel_alg_ecdh () {
2062 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
2063 scripts/config.py full
2064 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2065 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2066 scripts/config.py unset MBEDTLS_ECDH_C
2067 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2068 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2069 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2070 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2071 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2072 # 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 +00002073 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 +01002074}
2075
2076# This should be renamed to test and updated once the accelerator HMAC code is in place and ready to test.
2077component_build_psa_accel_alg_hmac () {
2078 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
2079 scripts/config.py full
2080 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2081 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2082 # 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 +00002083 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 +01002084}
2085
2086# This should be renamed to test and updated once the accelerator HKDF code is in place and ready to test.
2087component_build_psa_accel_alg_hkdf () {
2088 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
2089 scripts/config.py full
2090 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2091 scripts/config.py unset MBEDTLS_HKDF_C
2092 # Make sure to unset TLS1_3 since it requires HKDF_C and will not build properly without it.
2093 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2094 # 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 +00002095 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 +01002096}
2097
2098# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
2099component_build_psa_accel_alg_md5 () {
2100 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - other hashes"
2101 scripts/config.py full
2102 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2103 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2104 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2105 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2106 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2107 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2108 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2109 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2110 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2111 scripts/config.py unset MBEDTLS_LMS_C
2112 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2113 # 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 +00002114 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 +01002115}
2116
2117# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
2118component_build_psa_accel_alg_ripemd160 () {
2119 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - other hashes"
2120 scripts/config.py full
2121 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2122 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2123 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2124 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2125 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2126 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2127 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2128 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2129 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2130 scripts/config.py unset MBEDTLS_LMS_C
2131 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2132 # 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 +00002133 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 +01002134}
2135
2136# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
2137component_build_psa_accel_alg_sha1 () {
2138 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - other hashes"
2139 scripts/config.py full
2140 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2141 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2142 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2143 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2144 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2145 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2146 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2147 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2148 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2149 scripts/config.py unset MBEDTLS_LMS_C
2150 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2151 # 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 +00002152 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 +01002153}
2154
2155# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
2156component_build_psa_accel_alg_sha224 () {
2157 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
2158 scripts/config.py full
2159 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2160 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2161 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2162 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2163 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2164 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2165 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2166 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2167 # 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 +00002168 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 +01002169}
2170
2171# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
2172component_build_psa_accel_alg_sha256 () {
2173 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - other hashes"
2174 scripts/config.py full
2175 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2176 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2177 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2178 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2179 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2180 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2181 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2182 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
2183 # 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 +00002184 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 +01002185}
2186
2187# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
2188component_build_psa_accel_alg_sha384 () {
2189 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
2190 scripts/config.py full
2191 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2192 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2193 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2194 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2195 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2196 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2197 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2198 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2199 scripts/config.py unset MBEDTLS_LMS_C
2200 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2201 # 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 +00002202 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 +01002203}
2204
2205# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
2206component_build_psa_accel_alg_sha512 () {
2207 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
2208 scripts/config.py full
2209 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2210 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2211 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2212 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
2213 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
2214 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
2215 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
2216 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
2217 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
2218 scripts/config.py unset MBEDTLS_LMS_C
2219 scripts/config.py unset MBEDTLS_LMS_PRIVATE
2220 # 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 +00002221 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 +01002222}
2223
2224# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2225component_build_psa_accel_alg_rsa_pkcs1v15_crypt () {
2226 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2227 scripts/config.py full
2228 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2229 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2230 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
2231 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2232 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
2233 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
2234 # 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 +00002235 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 +01002236}
2237
2238# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2239component_build_psa_accel_alg_rsa_pkcs1v15_sign () {
2240 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2241 scripts/config.py full
2242 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2243 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2244 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
2245 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2246 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
2247 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
2248 # 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 +00002249 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 +01002250}
2251
2252# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2253component_build_psa_accel_alg_rsa_oaep () {
2254 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2255 scripts/config.py full
2256 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2257 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2258 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_OAEP 1
2259 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2260 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2261 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
2262 # 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 +00002263 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 +01002264}
2265
2266# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2267component_build_psa_accel_alg_rsa_pss () {
2268 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2269 scripts/config.py full
2270 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2271 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2272 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
2273 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2274 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2275 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
2276 # 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 +00002277 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 +01002278}
2279
2280# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2281component_build_psa_accel_key_type_rsa_key_pair () {
2282 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_xxx + PSA_WANT_ALG_RSA_PSS"
2283 scripts/config.py full
2284 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2285 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2286 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
2287 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC 1
2288 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT 1
2289 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT 1
2290 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE 1
2291 # 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 +00002292 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 +01002293}
2294
2295# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
2296component_build_psa_accel_key_type_rsa_public_key () {
2297 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
2298 scripts/config.py full
2299 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2300 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2301 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
2302 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
2303 # 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 +00002304 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 +01002305}
2306
Minos Galanakis3ece57e2024-08-01 17:09:49 +01002307# Auxiliary function to build config for hashes with and without drivers
2308config_psa_crypto_hash_use_psa () {
2309 driver_only="$1"
2310 # start with config full for maximum coverage (also enables USE_PSA)
2311 helper_libtestdriver1_adjust_config "full"
2312 if [ "$driver_only" -eq 1 ]; then
2313 # disable the built-in implementation of hashes
2314 scripts/config.py unset MBEDTLS_MD5_C
2315 scripts/config.py unset MBEDTLS_RIPEMD160_C
2316 scripts/config.py unset MBEDTLS_SHA1_C
2317 scripts/config.py unset MBEDTLS_SHA224_C
2318 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
2319 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2320 scripts/config.py unset MBEDTLS_SHA384_C
2321 scripts/config.py unset MBEDTLS_SHA512_C
2322 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2323 scripts/config.py unset MBEDTLS_SHA3_C
2324 fi
2325}
2326
2327# Note that component_test_psa_crypto_config_reference_hash_use_psa
2328# is related to this component and both components need to be kept in sync.
2329# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
2330component_test_psa_crypto_config_accel_hash_use_psa () {
2331 msg "test: full with accelerated hashes"
2332
2333 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
2334 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2335 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2336
2337 # Configure
2338 # ---------
2339
2340 config_psa_crypto_hash_use_psa 1
2341
2342 # Build
2343 # -----
2344
2345 helper_libtestdriver1_make_drivers "$loc_accel_list"
2346
2347 helper_libtestdriver1_make_main "$loc_accel_list"
2348
2349 # There's a risk of something getting re-enabled via config_psa.h;
2350 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
2351 not grep mbedtls_md5 library/md5.o
2352 not grep mbedtls_sha1 library/sha1.o
2353 not grep mbedtls_sha256 library/sha256.o
2354 not grep mbedtls_sha512 library/sha512.o
2355 not grep mbedtls_ripemd160 library/ripemd160.o
2356
2357 # Run the tests
2358 # -------------
2359
2360 msg "test: full with accelerated hashes"
2361 make test
2362
2363 # This is mostly useful so that we can later compare outcome files with
2364 # the reference config in analyze_outcomes.py, to check that the
2365 # dependency declarations in ssl-opt.sh and in TLS code are correct.
2366 msg "test: ssl-opt.sh, full with accelerated hashes"
2367 tests/ssl-opt.sh
2368
2369 # This is to make sure all ciphersuites are exercised, but we don't need
2370 # interop testing (besides, we already got some from ssl-opt.sh).
2371 msg "test: compat.sh, full with accelerated hashes"
2372 tests/compat.sh -p mbedTLS -V YES
2373}
2374
2375# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
2376# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
2377# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
2378# Both components need to be kept in sync.
2379component_test_psa_crypto_config_reference_hash_use_psa () {
2380 msg "test: full without accelerated hashes"
2381
2382 config_psa_crypto_hash_use_psa 0
2383
2384 make
2385
2386 msg "test: full without accelerated hashes"
2387 make test
2388
2389 msg "test: ssl-opt.sh, full without accelerated hashes"
2390 tests/ssl-opt.sh
2391}
2392
2393# Auxiliary function to build config for hashes with and without drivers
2394config_psa_crypto_hmac_use_psa () {
2395 driver_only="$1"
2396 # start with config full for maximum coverage (also enables USE_PSA)
2397 helper_libtestdriver1_adjust_config "full"
2398
2399 if [ "$driver_only" -eq 1 ]; then
2400 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
2401 # is still enabled though (for ENTROPY_C among others).
2402 scripts/config.py unset MBEDTLS_MD_C
2403 # Disable also the builtin hashes since they are supported by the driver
2404 # and MD module is able to perform PSA dispathing.
2405 scripts/config.py unset-all MBEDTLS_SHA
2406 scripts/config.py unset MBEDTLS_MD5_C
2407 scripts/config.py unset MBEDTLS_RIPEMD160_C
2408 fi
2409
2410 # Direct dependencies of MD_C. We disable them also in the reference
2411 # component to work with the same set of features.
2412 scripts/config.py unset MBEDTLS_PKCS7_C
2413 scripts/config.py unset MBEDTLS_PKCS5_C
2414 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
2415 scripts/config.py unset MBEDTLS_HKDF_C
2416 # Dependencies of HMAC_DRBG
2417 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
2418 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
2419}
2420
2421component_test_psa_crypto_config_accel_hmac () {
2422 msg "test: full with accelerated hmac"
2423
2424 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
2425 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
2426 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2427 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2428
2429 # Configure
2430 # ---------
2431
2432 config_psa_crypto_hmac_use_psa 1
2433
2434 # Build
2435 # -----
2436
2437 helper_libtestdriver1_make_drivers "$loc_accel_list"
2438
2439 helper_libtestdriver1_make_main "$loc_accel_list"
2440
2441 # Ensure that built-in support for HMAC is disabled.
2442 not grep mbedtls_md_hmac library/md.o
2443
2444 # Run the tests
2445 # -------------
2446
2447 msg "test: full with accelerated hmac"
2448 make test
2449}
2450
2451component_test_psa_crypto_config_reference_hmac () {
2452 msg "test: full without accelerated hmac"
2453
2454 config_psa_crypto_hmac_use_psa 0
2455
2456 make
2457
2458 msg "test: full without accelerated hmac"
2459 make test
2460}
2461
2462component_test_psa_crypto_config_accel_des () {
2463 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
2464
2465 # Albeit this components aims at accelerating DES which should only support
2466 # CBC and ECB modes, we need to accelerate more than that otherwise DES_C
2467 # would automatically be re-enabled by "config_adjust_legacy_from_psa.c"
2468 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 \
2469 ALG_CTR ALG_CFB ALG_OFB ALG_XTS ALG_CMAC \
2470 KEY_TYPE_DES"
2471
2472 # Note: we cannot accelerate all ciphers' key types otherwise we would also
2473 # have to either disable CCM/GCM or accelerate them, but that's out of scope
2474 # of this component. This limitation will be addressed by #8598.
2475
2476 # Configure
2477 # ---------
2478
2479 # Start from the full config
2480 helper_libtestdriver1_adjust_config "full"
2481
2482 # Disable the things that are being accelerated
2483 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2484 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2485 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2486 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2487 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2488 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2489 scripts/config.py unset MBEDTLS_DES_C
2490 scripts/config.py unset MBEDTLS_CMAC_C
2491
2492 # Build
2493 # -----
2494
2495 helper_libtestdriver1_make_drivers "$loc_accel_list"
2496
2497 helper_libtestdriver1_make_main "$loc_accel_list"
2498
2499 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine5ea32982024-06-19 15:09:27 +02002500 not grep mbedtls_des library/des.o
Minos Galanakis3ece57e2024-08-01 17:09:49 +01002501
2502 # Run the tests
2503 # -------------
2504
2505 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
2506 make test
2507}
2508
2509component_test_psa_crypto_config_accel_aead () {
2510 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2511
2512 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
2513 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2514
2515 # Configure
2516 # ---------
2517
2518 # Start from full config
2519 helper_libtestdriver1_adjust_config "full"
2520
2521 # Disable things that are being accelerated
2522 scripts/config.py unset MBEDTLS_GCM_C
2523 scripts/config.py unset MBEDTLS_CCM_C
2524 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2525
2526 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
2527 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
2528
2529 # Build
2530 # -----
2531
2532 helper_libtestdriver1_make_drivers "$loc_accel_list"
2533
2534 helper_libtestdriver1_make_main "$loc_accel_list"
2535
2536 # Make sure this was not re-enabled by accident (additive config)
2537 not grep mbedtls_ccm library/ccm.o
2538 not grep mbedtls_gcm library/gcm.o
2539 not grep mbedtls_chachapoly library/chachapoly.o
2540
2541 # Run the tests
2542 # -------------
2543
2544 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2545 make test
2546}
2547
2548# This is a common configuration function used in:
2549# - component_test_psa_crypto_config_accel_cipher_aead_cmac
2550# - component_test_psa_crypto_config_reference_cipher_aead_cmac
2551common_psa_crypto_config_accel_cipher_aead_cmac () {
2552 # Start from the full config
2553 helper_libtestdriver1_adjust_config "full"
2554
2555 scripts/config.py unset MBEDTLS_NIST_KW_C
2556}
2557
2558# The 2 following test components, i.e.
2559# - component_test_psa_crypto_config_accel_cipher_aead_cmac
2560# - component_test_psa_crypto_config_reference_cipher_aead_cmac
2561# are meant to be used together in analyze_outcomes.py script in order to test
2562# driver's coverage for ciphers and AEADs.
2563component_test_psa_crypto_config_accel_cipher_aead_cmac () {
2564 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
2565
2566 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
2567 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
2568 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
2569 KEY_TYPE_DES KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
2570
2571 # Configure
2572 # ---------
2573
2574 common_psa_crypto_config_accel_cipher_aead_cmac
2575
2576 # Disable the things that are being accelerated
2577 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2578 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2579 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2580 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2581 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2582 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2583 scripts/config.py unset MBEDTLS_GCM_C
2584 scripts/config.py unset MBEDTLS_CCM_C
2585 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2586 scripts/config.py unset MBEDTLS_CMAC_C
2587 scripts/config.py unset MBEDTLS_DES_C
2588 scripts/config.py unset MBEDTLS_AES_C
2589 scripts/config.py unset MBEDTLS_ARIA_C
2590 scripts/config.py unset MBEDTLS_CHACHA20_C
2591 scripts/config.py unset MBEDTLS_CAMELLIA_C
2592
2593 # Disable CIPHER_C entirely as all ciphers/AEADs are accelerated and PSA
2594 # does not depend on it.
2595 scripts/config.py unset MBEDTLS_CIPHER_C
2596
2597 # Build
2598 # -----
2599
2600 helper_libtestdriver1_make_drivers "$loc_accel_list"
2601
2602 helper_libtestdriver1_make_main "$loc_accel_list"
2603
2604 # Make sure this was not re-enabled by accident (additive config)
2605 not grep mbedtls_cipher library/cipher.o
2606 not grep mbedtls_des library/des.o
2607 not grep mbedtls_aes library/aes.o
2608 not grep mbedtls_aria library/aria.o
2609 not grep mbedtls_camellia library/camellia.o
2610 not grep mbedtls_ccm library/ccm.o
2611 not grep mbedtls_gcm library/gcm.o
2612 not grep mbedtls_chachapoly library/chachapoly.o
2613 not grep mbedtls_cmac library/cmac.o
2614
2615 # Run the tests
2616 # -------------
2617
2618 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
2619 make test
2620
2621 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
2622 tests/ssl-opt.sh
2623
2624 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
2625 tests/compat.sh -V NO -p mbedTLS
2626}
2627
2628component_test_psa_crypto_config_reference_cipher_aead_cmac () {
2629 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
2630 common_psa_crypto_config_accel_cipher_aead_cmac
2631
2632 make
2633
2634 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
2635 make test
2636
2637 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
2638 tests/ssl-opt.sh
2639
2640 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
2641 tests/compat.sh -V NO -p mbedTLS
2642}
2643
2644common_block_cipher_dispatch () {
2645 TEST_WITH_DRIVER="$1"
2646
2647 # Start from the full config
2648 helper_libtestdriver1_adjust_config "full"
2649
2650 if [ "$TEST_WITH_DRIVER" -eq 1 ]; then
2651 # Disable key types that are accelerated (there is no legacy equivalent
2652 # symbol for ECB)
2653 scripts/config.py unset MBEDTLS_AES_C
2654 scripts/config.py unset MBEDTLS_ARIA_C
2655 scripts/config.py unset MBEDTLS_CAMELLIA_C
2656 fi
2657
2658 # Disable cipher's modes that, when not accelerated, cause
2659 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
2660 # Keep this also in the reference component in order to skip the same tests
2661 # that were skipped in the accelerated one.
2662 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
2663 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
2664 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
2665 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
2666 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
2667 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
2668 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
2669 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
2670
2671 # Disable direct dependency on AES_C
2672 scripts/config.py unset MBEDTLS_NIST_KW_C
2673
2674 # Prevent the cipher module from using deprecated PSA path. The reason is
2675 # that otherwise there will be tests relying on "aes_info" (defined in
2676 # "cipher_wrap.c") whose functions are not available when AES_C is
2677 # not defined. ARIA and Camellia are not a problem in this case because
2678 # the PSA path is not tested for these key types.
2679 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
2680}
2681
Gilles Peskine9dc903a2024-06-21 11:25:01 +02002682component_test_full_block_cipher_psa_dispatch_static_keystore () {
2683 msg "build: full + PSA dispatch in block_cipher with static keystore"
2684 # Check that the static key store works well when CTR_DRBG uses a
2685 # PSA key for AES.
2686 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2687
2688 loc_accel_list="ALG_ECB_NO_PADDING \
2689 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2690
2691 # Configure
2692 # ---------
2693
2694 common_block_cipher_dispatch 1
2695
2696 # Build
2697 # -----
2698
2699 helper_libtestdriver1_make_drivers "$loc_accel_list"
2700
2701 helper_libtestdriver1_make_main "$loc_accel_list"
2702
2703 # Make sure disabled components were not re-enabled by accident (additive
2704 # config)
2705 not grep mbedtls_aes_ library/aes.o
2706 not grep mbedtls_aria_ library/aria.o
2707 not grep mbedtls_camellia_ library/camellia.o
2708
2709 # Run the tests
2710 # -------------
2711
2712 msg "test: full + PSA dispatch in block_cipher with static keystore"
2713 make test
2714}
2715
Minos Galanakis3ece57e2024-08-01 17:09:49 +01002716component_test_full_block_cipher_psa_dispatch () {
2717 msg "build: full + PSA dispatch in block_cipher"
2718
2719 loc_accel_list="ALG_ECB_NO_PADDING \
2720 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2721
2722 # Configure
2723 # ---------
2724
2725 common_block_cipher_dispatch 1
2726
2727 # Build
2728 # -----
2729
2730 helper_libtestdriver1_make_drivers "$loc_accel_list"
2731
2732 helper_libtestdriver1_make_main "$loc_accel_list"
2733
2734 # Make sure disabled components were not re-enabled by accident (additive
2735 # config)
2736 not grep mbedtls_aes_ library/aes.o
2737 not grep mbedtls_aria_ library/aria.o
2738 not grep mbedtls_camellia_ library/camellia.o
2739
2740 # Run the tests
2741 # -------------
2742
2743 msg "test: full + PSA dispatch in block_cipher"
2744 make test
2745}
2746
2747# This is the reference component of component_test_full_block_cipher_psa_dispatch
2748component_test_full_block_cipher_legacy_dispatch () {
2749 msg "build: full + legacy dispatch in block_cipher"
2750
2751 common_block_cipher_dispatch 0
2752
2753 make
2754
2755 msg "test: full + legacy dispatch in block_cipher"
2756 make test
2757}
2758
2759component_test_aead_chachapoly_disabled () {
2760 msg "build: full minus CHACHAPOLY"
2761 scripts/config.py full
2762 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2763 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2764 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2765
2766 msg "test: full minus CHACHAPOLY"
2767 make test
2768}
2769
2770component_test_aead_only_ccm () {
2771 msg "build: full minus CHACHAPOLY and GCM"
2772 scripts/config.py full
2773 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2774 scripts/config.py unset MBEDTLS_GCM_C
2775 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2776 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2777 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2778
2779 msg "test: full minus CHACHAPOLY and GCM"
2780 make test
2781}
2782
2783component_test_ccm_aes_sha256 () {
2784 msg "build: CCM + AES + SHA256 configuration"
2785
2786 cp "$CONFIG_TEST_DRIVER_H" "$CONFIG_H"
2787 cp configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
2788
2789 make
2790
2791 msg "test: CCM + AES + SHA256 configuration"
2792 make test
2793}
2794
2795# Test that the given .o file builds with all (valid) combinations of the given options.
2796#
2797# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
2798#
2799# The validator function is the name of a function to validate the combination of options.
2800# It may be "" if all combinations are valid.
2801# It receives a string containing a combination of options, as passed to the compiler,
2802# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
2803build_test_config_combos () {
2804 file=$1
2805 shift
2806 validate_options=$1
2807 shift
2808 options=("$@")
2809
2810 # clear all of the options so that they can be overridden on the clang commandline
2811 for opt in "${options[@]}"; do
2812 ./scripts/config.py unset ${opt}
2813 done
2814
2815 # enter the directory containing the target file & strip the dir from the filename
2816 cd $(dirname ${file})
2817 file=$(basename ${file})
2818
2819 # The most common issue is unused variables/functions, so ensure -Wunused is set.
2820 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
2821
2822 # Extract the command generated by the Makefile to build the target file.
2823 # This ensures that we have any include paths, macro definitions, etc
2824 # that may be applied by make.
2825 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
2826 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
2827
2828 makefile=$(TMPDIR=. mktemp)
2829 deps=""
2830
2831 len=${#options[@]}
2832 source_file=${file%.o}.c
2833
2834 targets=0
2835 echo 'include Makefile' >${makefile}
2836
2837 for ((i = 0; i < $((2**${len})); i++)); do
2838 # generate each of 2^n combinations of options
2839 # each bit of $i is used to determine if options[i] will be set or not
2840 target="t"
2841 clang_args=""
2842 for ((j = 0; j < ${len}; j++)); do
2843 if (((i >> j) & 1)); then
2844 opt=-D${options[$j]}
2845 clang_args="${clang_args} ${opt}"
2846 target="${target}${opt}"
2847 fi
2848 done
2849
2850 # if combination is not known to be invalid, add it to the makefile
2851 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
2852 cmd="${compile_cmd} ${clang_args}"
2853 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
2854
2855 deps="${deps} ${target}"
2856 ((++targets))
2857 fi
2858 done
2859
2860 echo "build_test_config_combos: ${deps}" >> ${makefile}
2861
2862 # execute all of the commands via Make (probably in parallel)
2863 make -s -f ${makefile} build_test_config_combos
2864 echo "$targets targets checked"
2865
2866 # clean up the temporary makefile
2867 rm ${makefile}
2868}
2869
2870validate_aes_config_variations () {
2871 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
2872 if [[ "$1" == *"MBEDTLS_PADLOCK_C"* ]]; then
2873 return 1
2874 fi
2875 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
2876 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
2877 return 1
2878 fi
2879 fi
2880 return 0
2881}
2882
2883component_build_aes_variations () {
2884 # 18s - around 90ms per clang invocation on M1 Pro
2885 #
2886 # aes.o has many #if defined(...) guards that intersect in complex ways.
2887 # Test that all the combinations build cleanly.
2888
2889 MBEDTLS_ROOT_DIR="$PWD"
2890 msg "build: aes.o for all combinations of relevant config options"
2891
2892 build_test_config_combos library/aes.o validate_aes_config_variations \
2893 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
2894 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
2895 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2896 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2897
2898 cd "$MBEDTLS_ROOT_DIR"
2899 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
2900
2901 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES,
2902 # manually set or unset those configurations to check
2903 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
2904 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
2905 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2906 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2907 scripts/config.py unset MBEDTLS_DES_C
2908 scripts/config.py unset MBEDTLS_NIST_KW_C
2909 build_test_config_combos library/aes.o validate_aes_config_variations \
2910 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
2911 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
2912 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2913 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2914}
2915
2916component_test_sha3_variations () {
2917 msg "sha3 loop unroll variations"
2918
2919 # define minimal config sufficient to test SHA3
2920 cat > include/mbedtls/mbedtls_config.h << END
2921 #define MBEDTLS_SELF_TEST
2922 #define MBEDTLS_SHA3_C
2923END
2924
2925 msg "all loops unrolled"
2926 make clean
2927 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"
2928 ./tests/test_suite_shax
2929
2930 msg "all loops rolled up"
2931 make clean
2932 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"
2933 ./tests/test_suite_shax
2934}
2935
2936# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2937component_build_aes_aesce_armcc () {
2938 msg "Build: AESCE test on arm64 platform without plain C."
2939 scripts/config.py baremetal
2940
2941 # armc[56] don't support SHA-512 intrinsics
2942 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2943
2944 # Stop armclang warning about feature detection for A64_CRYPTO.
2945 # With this enabled, the library does build correctly under armclang,
2946 # but in baremetal builds (as tested here), feature detection is
2947 # unavailable, and the user is notified via a #warning. So enabling
2948 # this feature would prevent us from building with -Werror on
2949 # armclang. Tracked in #7198.
2950 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2951 scripts/config.py set MBEDTLS_HAVE_ASM
2952
2953 msg "AESCE, build with default configuration."
2954 scripts/config.py set MBEDTLS_AESCE_C
2955 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard452db602024-10-01 13:01:54 +02002956 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01002957
2958 msg "AESCE, build AESCE only"
2959 scripts/config.py set MBEDTLS_AESCE_C
2960 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
Manuel Pégourié-Gonnard452db602024-10-01 13:01:54 +02002961 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01002962}
2963
2964support_build_aes_aesce_armcc () {
2965 support_build_armcc
2966}
2967
2968component_test_aes_only_128_bit_keys () {
2969 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2970 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2971 scripts/config.py unset MBEDTLS_PADLOCK_C
2972
2973 make CFLAGS='-O2 -Werror -Wall -Wextra'
2974
2975 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2976 make test
2977}
2978
2979component_test_no_ctr_drbg_aes_only_128_bit_keys () {
2980 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2981 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2982 scripts/config.py unset MBEDTLS_CTR_DRBG_C
2983 scripts/config.py unset MBEDTLS_PADLOCK_C
2984
2985 make CC=clang CFLAGS='-Werror -Wall -Wextra'
2986
2987 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2988 make test
2989}
2990
2991component_test_aes_only_128_bit_keys_have_builtins () {
2992 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2993 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2994 scripts/config.py unset MBEDTLS_PADLOCK_C
2995 scripts/config.py unset MBEDTLS_AESNI_C
2996 scripts/config.py unset MBEDTLS_AESCE_C
2997
2998 make CFLAGS='-O2 -Werror -Wall -Wextra'
2999
3000 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
3001 make test
3002
3003 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
3004 programs/test/selftest
3005}
3006
3007component_test_gcm_largetable () {
3008 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
3009 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
3010 scripts/config.py unset MBEDTLS_PADLOCK_C
3011 scripts/config.py unset MBEDTLS_AESNI_C
3012 scripts/config.py unset MBEDTLS_AESCE_C
3013
3014 make CFLAGS='-O2 -Werror -Wall -Wextra'
3015
3016 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
3017 make test
3018}
3019
3020component_test_aes_fewer_tables () {
3021 msg "build: default config with AES_FEWER_TABLES enabled"
3022 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
3023 make CFLAGS='-O2 -Werror -Wall -Wextra'
3024
3025 msg "test: AES_FEWER_TABLES"
3026 make test
3027}
3028
3029component_test_aes_rom_tables () {
3030 msg "build: default config with AES_ROM_TABLES enabled"
3031 scripts/config.py set MBEDTLS_AES_ROM_TABLES
3032 make CFLAGS='-O2 -Werror -Wall -Wextra'
3033
3034 msg "test: AES_ROM_TABLES"
3035 make test
3036}
3037
3038component_test_aes_fewer_tables_and_rom_tables () {
3039 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
3040 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
3041 scripts/config.py set MBEDTLS_AES_ROM_TABLES
3042 make CFLAGS='-O2 -Werror -Wall -Wextra'
3043
3044 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
3045 make test
3046}
3047
3048# helper for common_block_cipher_no_decrypt() which:
3049# - enable/disable the list of config options passed from -s/-u respectively.
3050# - build
3051# - test for tests_suite_xxx
3052# - selftest
3053#
3054# Usage: helper_block_cipher_no_decrypt_build_test
3055# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
3056# Options: -s set_opts the list of config options to enable
3057# -u unset_opts the list of config options to disable
3058# -c cflags the list of options passed to CFLAGS
3059# -l ldflags the list of options passed to LDFLAGS
3060helper_block_cipher_no_decrypt_build_test () {
3061 while [ $# -gt 0 ]; do
3062 case "$1" in
3063 -s)
3064 shift; local set_opts="$1";;
3065 -u)
3066 shift; local unset_opts="$1";;
3067 -c)
3068 shift; local cflags="-Werror -Wall -Wextra $1";;
3069 -l)
3070 shift; local ldflags="$1";;
3071 esac
3072 shift
3073 done
3074 set_opts="${set_opts:-}"
3075 unset_opts="${unset_opts:-}"
3076 cflags="${cflags:-}"
3077 ldflags="${ldflags:-}"
3078
3079 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
3080 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
3081
3082 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
3083 make clean
3084 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
3085
3086 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
3087 not grep mbedtls_aes_setkey_dec library/aes.o
3088 not grep mbedtls_aria_setkey_dec library/aria.o
3089 not grep mbedtls_camellia_setkey_dec library/camellia.o
3090 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
3091 not grep mbedtls_internal_aes_decrypt library/aes.o
3092 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
3093 not grep mbedtls_aesni_inverse_key library/aesni.o
3094
3095 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
3096 make test
3097
3098 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
3099 programs/test/selftest
3100}
3101
3102# This is a common configuration function used in:
3103# - component_test_block_cipher_no_decrypt_aesni_legacy()
3104# - component_test_block_cipher_no_decrypt_aesni_use_psa()
3105# in order to test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics,
3106# AESNI assembly and AES C implementation on x86_64 and with AESNI intrinsics
3107# on x86.
3108common_block_cipher_no_decrypt () {
3109 # test AESNI intrinsics
3110 helper_block_cipher_no_decrypt_build_test \
3111 -s "MBEDTLS_AESNI_C" \
3112 -c "-mpclmul -msse2 -maes"
3113
3114 # test AESNI assembly
3115 helper_block_cipher_no_decrypt_build_test \
3116 -s "MBEDTLS_AESNI_C" \
3117 -c "-mno-pclmul -mno-sse2 -mno-aes"
3118
3119 # test AES C implementation
3120 helper_block_cipher_no_decrypt_build_test \
3121 -u "MBEDTLS_AESNI_C"
3122
3123 # test AESNI intrinsics for i386 target
3124 helper_block_cipher_no_decrypt_build_test \
3125 -s "MBEDTLS_AESNI_C" \
3126 -c "-m32 -mpclmul -msse2 -maes" \
3127 -l "-m32"
3128}
3129
3130# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
3131# usage: 0: no PSA crypto configuration
3132# 1: use PSA crypto configuration
3133config_block_cipher_no_decrypt () {
3134 use_psa=$1
3135
3136 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
3137 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3138 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
3139 scripts/config.py unset MBEDTLS_DES_C
3140 scripts/config.py unset MBEDTLS_NIST_KW_C
3141
3142 if [ "$use_psa" -eq 1 ]; then
3143 # Enable support for cryptographic mechanisms through the PSA API.
3144 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
3145 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3146 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
3147 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
3148 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
3149 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
3150 fi
3151}
3152
3153component_test_block_cipher_no_decrypt_aesni () {
3154 # This consistently causes an llvm crash on clang 3.8, so use gcc
3155 export CC=gcc
3156 config_block_cipher_no_decrypt 0
3157 common_block_cipher_no_decrypt
3158}
3159
3160component_test_block_cipher_no_decrypt_aesni_use_psa () {
3161 # This consistently causes an llvm crash on clang 3.8, so use gcc
3162 export CC=gcc
3163 config_block_cipher_no_decrypt 1
3164 common_block_cipher_no_decrypt
3165}
3166
3167support_test_block_cipher_no_decrypt_aesce_armcc () {
3168 support_build_armcc
3169}
3170
3171component_test_block_cipher_no_decrypt_aesce_armcc () {
3172 scripts/config.py baremetal
3173
3174 # armc[56] don't support SHA-512 intrinsics
3175 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
3176
3177 # Stop armclang warning about feature detection for A64_CRYPTO.
3178 # With this enabled, the library does build correctly under armclang,
3179 # but in baremetal builds (as tested here), feature detection is
3180 # unavailable, and the user is notified via a #warning. So enabling
3181 # this feature would prevent us from building with -Werror on
3182 # armclang. Tracked in #7198.
3183 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
3184 scripts/config.py set MBEDTLS_HAVE_ASM
3185
3186 config_block_cipher_no_decrypt 1
3187
3188 # test AESCE baremetal build
3189 scripts/config.py set MBEDTLS_AESCE_C
3190 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
Manuel Pégourié-Gonnard452db602024-10-01 13:01:54 +02003191 helper_armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01003192
3193 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
3194 not grep mbedtls_aes_setkey_dec library/aes.o
3195 not grep mbedtls_aria_setkey_dec library/aria.o
3196 not grep mbedtls_camellia_setkey_dec library/camellia.o
3197 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
3198 not grep mbedtls_internal_aes_decrypt library/aes.o
3199 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
3200 not grep mbedtls_aesce_inverse_key library/aesce.o
3201 not grep aesce_decrypt_block library/aesce.o
3202}
3203
3204component_test_ctr_drbg_aes_256_sha_256 () {
3205 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
3206 scripts/config.py full
3207 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
3208 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
3209 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3210 make
3211
3212 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
3213 make test
3214}
3215
3216component_test_ctr_drbg_aes_128_sha_512 () {
3217 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
3218 scripts/config.py full
3219 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
3220 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
3221 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3222 make
3223
3224 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
3225 make test
3226}
3227
3228component_test_ctr_drbg_aes_128_sha_256 () {
3229 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
3230 scripts/config.py full
3231 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
3232 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
3233 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
3234 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3235 make
3236
3237 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
3238 make test
3239}
3240
3241component_test_se_default () {
3242 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
3243 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
3244 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
3245
3246 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
3247 make test
3248}
3249
Gilles Peskine9dc903a2024-06-21 11:25:01 +02003250component_test_full_static_keystore () {
3251 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
3252 scripts/config.py full
3253 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
3254 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
3255
3256 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
3257 make test
3258}
3259
Minos Galanakis3ece57e2024-08-01 17:09:49 +01003260component_test_psa_crypto_drivers () {
3261 msg "build: full + test drivers dispatching to builtins"
3262 scripts/config.py full
3263 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
3264 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
3265 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
David Horstmanndcf42a02024-11-08 14:40:12 +00003266 loc_cflags="${loc_cflags} -I../framework/tests/include -O2"
Minos Galanakis3ece57e2024-08-01 17:09:49 +01003267
3268 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
3269
3270 msg "test: full + test drivers dispatching to builtins"
3271 make test
3272}
3273
3274component_build_psa_config_file () {
3275 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
3276 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3277 cp "$CRYPTO_CONFIG_H" psa_test_config.h
3278 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
3279 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
3280 # Make sure this feature is enabled. We'll disable it in the next phase.
3281 programs/test/query_compile_time_config MBEDTLS_CMAC_C
3282 make clean
3283
3284 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
3285 # In the user config, disable one feature and its dependencies, which will
3286 # reflect on the mbedtls configuration so we can query it with
3287 # query_compile_time_config.
3288 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
3289 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
3290 scripts/config.py unset MBEDTLS_CMAC_C
3291 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
3292 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
3293
3294 rm -f psa_test_config.h psa_user_config.h
3295}
3296
3297component_build_psa_alt_headers () {
3298 msg "build: make with PSA alt headers" # ~20s
3299
3300 # Generate alternative versions of the substitutable headers with the
3301 # same content except different include guards.
David Horstmannb19374f2024-11-07 17:08:11 +00003302 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 +01003303
3304 # Build the library and some programs.
3305 # Don't build the fuzzers to avoid having to go through hoops to set
3306 # a correct include path for programs/fuzz/Makefile.
David Horstmanndcf42a02024-11-08 14:40:12 +00003307 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
3308 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 +01003309
3310 # Check that we're getting the alternative include guards and not the
3311 # original include guards.
3312 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
3313 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
3314 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
3315 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
3316}
3317
3318component_test_min_mpi_window_size () {
3319 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
3320 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
3321 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3322 make
3323
3324 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
3325 make test
3326}