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