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