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