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