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