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