blob: e674296bd88474f21d2727b31f6047f2e86d8bd3 [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
662 # Start from default config (no USE_PSA) + TLS 1.3
663 helper_libtestdriver1_adjust_config "default"
664
665 # Disable the module that's accelerated
666 scripts/config.py unset MBEDTLS_ECDSA_C
667
668 # Disable things that depend on it
669 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
670 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
671
672 # Build
673 # -----
674
675 # These hashes are needed for some ECDSA signature tests.
676 loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
677 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
678
679 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
680
681 helper_libtestdriver1_make_main "$loc_accel_list"
682
683 # Make sure this was not re-enabled by accident (additive config)
684 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
685
686 # Run the tests
687 # -------------
688
689 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
690 make test
691}
692
693component_test_psa_crypto_config_accel_ecdh () {
694 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
695
696 # Algorithms and key types to accelerate
697 loc_accel_list="ALG_ECDH \
698 $(helper_get_psa_key_type_list "ECC") \
699 $(helper_get_psa_curve_list)"
700
701 # Configure
702 # ---------
703
704 # Start from default config (no USE_PSA)
705 helper_libtestdriver1_adjust_config "default"
706
707 # Disable the module that's accelerated
708 scripts/config.py unset MBEDTLS_ECDH_C
709
710 # Disable things that depend on it
711 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
712 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
713 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
714 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
715 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
716
717 # Build
718 # -----
719
720 helper_libtestdriver1_make_drivers "$loc_accel_list"
721
722 helper_libtestdriver1_make_main "$loc_accel_list"
723
724 # Make sure this was not re-enabled by accident (additive config)
725 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
726
727 # Run the tests
728 # -------------
729
730 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
731 make test
732}
733
734component_test_psa_crypto_config_accel_ffdh () {
735 msg "build: full with accelerated FFDH"
736
737 # Algorithms and key types to accelerate
738 loc_accel_list="ALG_FFDH \
739 $(helper_get_psa_key_type_list "DH") \
740 $(helper_get_psa_dh_group_list)"
741
742 # Configure
743 # ---------
744
745 # start with full (USE_PSA and TLS 1.3)
746 helper_libtestdriver1_adjust_config "full"
747
748 # Disable the module that's accelerated
749 scripts/config.py unset MBEDTLS_DHM_C
750
751 # Disable things that depend on it
752 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
753 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
754
755 # Build
756 # -----
757
758 helper_libtestdriver1_make_drivers "$loc_accel_list"
759
760 helper_libtestdriver1_make_main "$loc_accel_list"
761
762 # Make sure this was not re-enabled by accident (additive config)
763 not grep mbedtls_dhm_ ${BUILTIN_SRC_PATH}/dhm.o
764
765 # Run the tests
766 # -------------
767
768 msg "test: full with accelerated FFDH"
769 make test
770
771 msg "ssl-opt: full with accelerated FFDH alg"
772 tests/ssl-opt.sh -f "ffdh"
773}
774
775component_test_psa_crypto_config_reference_ffdh () {
776 msg "build: full with non-accelerated FFDH"
777
778 # Start with full (USE_PSA and TLS 1.3)
779 helper_libtestdriver1_adjust_config "full"
780
781 # Disable things that are not supported
782 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
783 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
784 make
785
786 msg "test suites: full with non-accelerated FFDH alg"
787 make test
788
789 msg "ssl-opt: full with non-accelerated FFDH alg"
790 tests/ssl-opt.sh -f "ffdh"
791}
792
Minos Galanakisf78447f2024-07-26 20:49:51 +0100793component_test_psa_crypto_config_accel_pake () {
Minos Galanakis471b34c2024-07-26 15:39:24 +0100794 msg "build: full with accelerated PAKE"
795
796 loc_accel_list="ALG_JPAKE \
797 $(helper_get_psa_key_type_list "ECC") \
798 $(helper_get_psa_curve_list)"
799
800 # Configure
801 # ---------
802
803 helper_libtestdriver1_adjust_config "full"
804
805 # Make built-in fallback not available
806 scripts/config.py unset MBEDTLS_ECJPAKE_C
807 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
808
809 # Build
810 # -----
811
812 helper_libtestdriver1_make_drivers "$loc_accel_list"
813
814 helper_libtestdriver1_make_main "$loc_accel_list"
815
816 # Make sure this was not re-enabled by accident (additive config)
817 not grep mbedtls_ecjpake_init ${BUILTIN_SRC_PATH}/ecjpake.o
818
819 # Run the tests
820 # -------------
821
822 msg "test: full with accelerated PAKE"
823 make test
824}
825
826component_test_psa_crypto_config_accel_ecc_some_key_types () {
827 msg "build: full with accelerated EC algs and some key types"
828
829 # Algorithms and key types to accelerate
830 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
831 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
832 ALG_ECDH \
833 ALG_JPAKE \
834 KEY_TYPE_ECC_PUBLIC_KEY \
835 KEY_TYPE_ECC_KEY_PAIR_BASIC \
836 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
837 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
838 $(helper_get_psa_curve_list)"
839
840 # Configure
841 # ---------
842
843 # start with config full for maximum coverage (also enables USE_PSA)
844 helper_libtestdriver1_adjust_config "full"
845
846 # Disable modules that are accelerated - some will be re-enabled
847 scripts/config.py unset MBEDTLS_ECDSA_C
848 scripts/config.py unset MBEDTLS_ECDH_C
849 scripts/config.py unset MBEDTLS_ECJPAKE_C
850 scripts/config.py unset MBEDTLS_ECP_C
851
852 # Disable all curves - those that aren't accelerated should be re-enabled
853 helper_disable_builtin_curves
854
855 # Restartable feature is not yet supported by PSA. Once it will in
856 # the future, the following line could be removed (see issues
857 # 6061, 6332 and following ones)
858 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
859
860 # this is not supported by the driver API yet
861 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
862
863 # Build
864 # -----
865
866 # These hashes are needed for some ECDSA signature tests.
867 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
868 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
869 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
870
871 helper_libtestdriver1_make_main "$loc_accel_list"
872
873 # ECP should be re-enabled but not the others
874 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
875 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
876 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
877 grep mbedtls_ecp ${BUILTIN_SRC_PATH}/ecp.o
878
879 # Run the tests
880 # -------------
881
882 msg "test suites: full with accelerated EC algs and some key types"
883 make test
884}
885
886# Run tests with only (non-)Weierstrass accelerated
887# Common code used in:
888# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
889# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Minos Galanakis471b34c2024-07-26 15:39:24 +0100890common_test_psa_crypto_config_accel_ecc_some_curves () {
891 weierstrass=$1
892 if [ $weierstrass -eq 1 ]; then
893 desc="Weierstrass"
894 else
895 desc="non-Weierstrass"
896 fi
897
898 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
899
900 # Note: Curves are handled in a special way by the libtestdriver machinery,
901 # so we only want to include them in the accel list when building the main
902 # libraries, hence the use of a separate variable.
903 # Note: the following loop is a modified version of
904 # helper_get_psa_curve_list that only keeps Weierstrass families.
905 loc_weierstrass_list=""
906 loc_non_weierstrass_list=""
907 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
908 case $item in
909 ECC_BRAINPOOL*|ECC_SECP*)
910 loc_weierstrass_list="$loc_weierstrass_list $item"
911 ;;
912 *)
913 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
914 ;;
915 esac
916 done
917 if [ $weierstrass -eq 1 ]; then
918 loc_curve_list=$loc_weierstrass_list
919 else
920 loc_curve_list=$loc_non_weierstrass_list
921 fi
922
923 # Algorithms and key types to accelerate
924 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
925 ALG_ECDH \
926 ALG_JPAKE \
927 $(helper_get_psa_key_type_list "ECC") \
928 $loc_curve_list"
929
930 # Configure
931 # ---------
932
933 # Start with config crypto_full and remove PK_C:
934 # that's what's supported now, see docs/driver-only-builds.md.
935 helper_libtestdriver1_adjust_config "crypto_full"
936 scripts/config.py unset MBEDTLS_PK_C
937 scripts/config.py unset MBEDTLS_PK_PARSE_C
938 scripts/config.py unset MBEDTLS_PK_WRITE_C
939
940 # Disable modules that are accelerated - some will be re-enabled
941 scripts/config.py unset MBEDTLS_ECDSA_C
942 scripts/config.py unset MBEDTLS_ECDH_C
943 scripts/config.py unset MBEDTLS_ECJPAKE_C
944 scripts/config.py unset MBEDTLS_ECP_C
945
946 # Disable all curves - those that aren't accelerated should be re-enabled
947 helper_disable_builtin_curves
948
949 # Restartable feature is not yet supported by PSA. Once it will in
950 # the future, the following line could be removed (see issues
951 # 6061, 6332 and following ones)
952 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
953
954 # this is not supported by the driver API yet
955 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
956
957 # Build
958 # -----
959
960 # These hashes are needed for some ECDSA signature tests.
961 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
962 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
963 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
964
965 helper_libtestdriver1_make_main "$loc_accel_list"
966
967 # We expect ECDH to be re-enabled for the missing curves
968 grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
969 # We expect ECP to be re-enabled, however the parts specific to the
970 # families of curves that are accelerated should be ommited.
971 # - functions with mxz in the name are specific to Montgomery curves
972 # - ecp_muladd is specific to Weierstrass curves
973 ##nm ${BUILTIN_SRC_PATH}/ecp.o | tee ecp.syms
974 if [ $weierstrass -eq 1 ]; then
975 not grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
976 grep mxz ${BUILTIN_SRC_PATH}/ecp.o
977 else
978 grep mbedtls_ecp_muladd ${BUILTIN_SRC_PATH}/ecp.o
979 not grep mxz ${BUILTIN_SRC_PATH}/ecp.o
980 fi
981 # We expect ECDSA and ECJPAKE to be re-enabled only when
982 # Weierstrass curves are not accelerated
983 if [ $weierstrass -eq 1 ]; then
984 not grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
985 not grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
986 else
987 grep mbedtls_ecdsa ${BUILTIN_SRC_PATH}/ecdsa.o
988 grep mbedtls_ecjpake ${BUILTIN_SRC_PATH}/ecjpake.o
989 fi
990
991 # Run the tests
992 # -------------
993
994 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
995 make test
996}
997
998component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
999 common_test_psa_crypto_config_accel_ecc_some_curves 1
1000}
1001
1002component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
1003 common_test_psa_crypto_config_accel_ecc_some_curves 0
1004}
1005
1006# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
1007# ECDH, ECDSA) with and without drivers.
1008# The input parameter is a boolean value which indicates:
1009# - 0 keep built-in EC algs,
1010# - 1 exclude built-in EC algs (driver only).
1011#
1012# This is used by the two following components to ensure they always use the
1013# same config, except for the use of driver or built-in EC algorithms:
1014# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
1015# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
1016# This supports comparing their test coverage with analyze_outcomes.py.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001017config_psa_crypto_config_ecp_light_only () {
1018 driver_only="$1"
1019 # start with config full for maximum coverage (also enables USE_PSA)
1020 helper_libtestdriver1_adjust_config "full"
1021 if [ "$driver_only" -eq 1 ]; then
1022 # Disable modules that are accelerated
1023 scripts/config.py unset MBEDTLS_ECDSA_C
1024 scripts/config.py unset MBEDTLS_ECDH_C
1025 scripts/config.py unset MBEDTLS_ECJPAKE_C
1026 scripts/config.py unset MBEDTLS_ECP_C
1027 fi
1028
1029 # Restartable feature is not yet supported by PSA. Once it will in
1030 # the future, the following line could be removed (see issues
1031 # 6061, 6332 and following ones)
1032 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1033}
1034
1035# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +01001036component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
1037 msg "build: full with accelerated EC algs"
1038
1039 # Algorithms and key types to accelerate
1040 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1041 ALG_ECDH \
1042 ALG_JPAKE \
1043 $(helper_get_psa_key_type_list "ECC") \
1044 $(helper_get_psa_curve_list)"
1045
1046 # Configure
1047 # ---------
1048
1049 # Use the same config as reference, only without built-in EC algs
1050 config_psa_crypto_config_ecp_light_only 1
1051
1052 # Do not disable builtin curves because that support is required for:
1053 # - MBEDTLS_PK_PARSE_EC_EXTENDED
1054 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
1055
1056 # Build
1057 # -----
1058
1059 # These hashes are needed for some ECDSA signature tests.
1060 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1061 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1062 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1063
1064 helper_libtestdriver1_make_main "$loc_accel_list"
1065
1066 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1067 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1068 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1069 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1070 not grep mbedtls_ecp_mul ${BUILTIN_SRC_PATH}/ecp.o
1071
1072 # Run the tests
1073 # -------------
1074
1075 msg "test suites: full with accelerated EC algs"
1076 make test
1077
1078 msg "ssl-opt: full with accelerated EC algs"
1079 tests/ssl-opt.sh
1080}
1081
1082# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
Minos Galanakis471b34c2024-07-26 15:39:24 +01001083component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
1084 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated EC algs"
1085
1086 config_psa_crypto_config_ecp_light_only 0
1087
1088 make
1089
1090 msg "test suites: full with non-accelerated EC algs"
1091 make test
1092
1093 msg "ssl-opt: full with non-accelerated EC algs"
1094 tests/ssl-opt.sh
1095}
1096
1097# This helper function is used by:
1098# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
1099# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
1100# to ensure that both tests use the same underlying configuration when testing
1101# driver's coverage with analyze_outcomes.py.
1102#
1103# This functions accepts 1 boolean parameter as follows:
1104# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
1105# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
1106# - 0: include built-in implementation of EC algorithms.
1107#
1108# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
1109# on the ECP module.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001110config_psa_crypto_no_ecp_at_all () {
1111 driver_only="$1"
1112 # start with full config for maximum coverage (also enables USE_PSA)
1113 helper_libtestdriver1_adjust_config "full"
1114
1115 if [ "$driver_only" -eq 1 ]; then
1116 # Disable modules that are accelerated
1117 scripts/config.py unset MBEDTLS_ECDSA_C
1118 scripts/config.py unset MBEDTLS_ECDH_C
1119 scripts/config.py unset MBEDTLS_ECJPAKE_C
1120 # Disable ECP module (entirely)
1121 scripts/config.py unset MBEDTLS_ECP_C
1122 fi
1123
1124 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1125 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1126 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1127 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1128
1129 # Restartable feature is not yet supported by PSA. Once it will in
1130 # the future, the following line could be removed (see issues
1131 # 6061, 6332 and following ones)
1132 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1133}
1134
1135# Build and test a configuration where driver accelerates all EC algs while
1136# all support and dependencies from ECP and ECP_LIGHT are removed on the library
1137# side.
1138#
1139# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001140component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
1141 msg "build: full + accelerated EC algs - ECP"
1142
1143 # Algorithms and key types to accelerate
1144 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1145 ALG_ECDH \
1146 ALG_JPAKE \
1147 $(helper_get_psa_key_type_list "ECC") \
1148 $(helper_get_psa_curve_list)"
1149
1150 # Configure
1151 # ---------
1152
1153 # Set common configurations between library's and driver's builds
1154 config_psa_crypto_no_ecp_at_all 1
1155 # Disable all the builtin curves. All the required algs are accelerated.
1156 helper_disable_builtin_curves
1157
1158 # Build
1159 # -----
1160
1161 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1162 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1163 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1164 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1165
1166 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1167
1168 helper_libtestdriver1_make_main "$loc_accel_list"
1169
1170 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1171 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1172 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1173 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1174 # Also ensure that ECP module was not re-enabled
1175 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1176
1177 # Run the tests
1178 # -------------
1179
1180 msg "test: full + accelerated EC algs - ECP"
1181 make test
1182
1183 msg "ssl-opt: full + accelerated EC algs - ECP"
1184 tests/ssl-opt.sh
1185}
1186
1187# Reference function used for driver's coverage analysis in analyze_outcomes.py
1188# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
1189# Keep in sync with its accelerated counterpart.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001190component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
1191 msg "build: full + non accelerated EC algs"
1192
1193 config_psa_crypto_no_ecp_at_all 0
1194
1195 make
1196
1197 msg "test: full + non accelerated EC algs"
1198 make test
1199
1200 msg "ssl-opt: full + non accelerated EC algs"
1201 tests/ssl-opt.sh
1202}
1203
1204# This is a common configuration helper used directly from:
1205# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1206# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1207# and indirectly from:
1208# - component_test_psa_crypto_config_accel_ecc_no_bignum
1209# - accelerate all EC algs, disable RSA and FFDH
1210# - component_test_psa_crypto_config_reference_ecc_no_bignum
1211# - this is the reference component of the above
1212# - it still disables RSA and FFDH, but it uses builtin EC algs
1213# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1214# - accelerate all EC and FFDH algs, disable only RSA
1215# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1216# - this is the reference component of the above
1217# - it still disables RSA, but it uses builtin EC and FFDH algs
1218#
1219# This function accepts 2 parameters:
1220# $1: a boolean value which states if we are testing an accelerated scenario
1221# or not.
1222# $2: a string value which states which components are tested. Allowed values
1223# are "ECC" or "ECC_DH".
Minos Galanakisf78447f2024-07-26 20:49:51 +01001224config_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001225 driver_only="$1"
1226 test_target="$2"
1227 # start with full config for maximum coverage (also enables USE_PSA)
1228 helper_libtestdriver1_adjust_config "full"
1229
1230 if [ "$driver_only" -eq 1 ]; then
1231 # Disable modules that are accelerated
1232 scripts/config.py unset MBEDTLS_ECDSA_C
1233 scripts/config.py unset MBEDTLS_ECDH_C
1234 scripts/config.py unset MBEDTLS_ECJPAKE_C
1235 # Disable ECP module (entirely)
1236 scripts/config.py unset MBEDTLS_ECP_C
1237 # Also disable bignum
1238 scripts/config.py unset MBEDTLS_BIGNUM_C
1239 fi
1240
1241 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
1242 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1243 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1244 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1245
1246 # RSA support is intentionally disabled on this test because RSA_C depends
1247 # on BIGNUM_C.
1248 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
1249 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
1250 scripts/config.py unset MBEDTLS_RSA_C
1251 scripts/config.py unset MBEDTLS_PKCS1_V15
1252 scripts/config.py unset MBEDTLS_PKCS1_V21
1253 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1254 # Also disable key exchanges that depend on RSA
1255 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1256 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1257 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1258 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1259 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1260
1261 if [ "$test_target" = "ECC" ]; then
1262 # When testing ECC only, we disable FFDH support, both from builtin and
1263 # PSA sides, and also disable the key exchanges that depend on DHM.
1264 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_FFDH
1265 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
1266 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
1267 scripts/config.py unset MBEDTLS_DHM_C
1268 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1269 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1270 else
1271 # When testing ECC and DH instead, we disable DHM and depending key
1272 # exchanges only in the accelerated build
1273 if [ "$driver_only" -eq 1 ]; then
1274 scripts/config.py unset MBEDTLS_DHM_C
1275 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1276 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1277 fi
1278 fi
1279
1280 # Restartable feature is not yet supported by PSA. Once it will in
1281 # the future, the following line could be removed (see issues
1282 # 6061, 6332 and following ones)
1283 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1284}
1285
1286# Common helper used by:
1287# - component_test_psa_crypto_config_accel_ecc_no_bignum
1288# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
1289#
1290# The goal is to build and test accelerating either:
1291# - ECC only or
1292# - both ECC and FFDH
1293#
1294# It is meant to be used in conjunction with
1295# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
1296# coverage analysis in the "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001297common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1298 test_target="$1"
1299
1300 # This is an internal helper to simplify text message handling
1301 if [ "$test_target" = "ECC_DH" ]; then
1302 accel_text="ECC/FFDH"
1303 removed_text="ECP - DH"
1304 else
1305 accel_text="ECC"
1306 removed_text="ECP"
1307 fi
1308
1309 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1310
1311 # By default we accelerate all EC keys/algs
1312 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1313 ALG_ECDH \
1314 ALG_JPAKE \
1315 $(helper_get_psa_key_type_list "ECC") \
1316 $(helper_get_psa_curve_list)"
1317 # Optionally we can also add DH to the list of accelerated items
1318 if [ "$test_target" = "ECC_DH" ]; then
1319 loc_accel_list="$loc_accel_list \
1320 ALG_FFDH \
1321 $(helper_get_psa_key_type_list "DH") \
1322 $(helper_get_psa_dh_group_list)"
1323 fi
1324
1325 # Configure
1326 # ---------
1327
1328 # Set common configurations between library's and driver's builds
1329 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
1330 # Disable all the builtin curves. All the required algs are accelerated.
1331 helper_disable_builtin_curves
1332
1333 # Build
1334 # -----
1335
1336 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
1337 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
1338 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1339 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1340
1341 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1342
1343 helper_libtestdriver1_make_main "$loc_accel_list"
1344
1345 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1346 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1347 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1348 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1349 # Also ensure that ECP, RSA, [DHM] or BIGNUM modules were not re-enabled
1350 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1351 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1352 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1353 not grep mbedtls_dhm_ ${BUILTIN_SRC_PATH}/dhm.o
1354
1355 # Run the tests
1356 # -------------
1357
1358 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - DHM - BIGNUM"
1359
1360 make test
1361
1362 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
1363 tests/ssl-opt.sh
1364}
1365
1366# Common helper used by:
1367# - component_test_psa_crypto_config_reference_ecc_no_bignum
1368# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
1369#
1370# The goal is to build and test a reference scenario (i.e. with builtin
1371# components) compared to the ones used in
1372# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
1373#
1374# It is meant to be used in conjunction with
1375# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
1376# coverage analysis in "analyze_outcomes.py" script.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001377common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1378 test_target="$1"
1379
1380 # This is an internal helper to simplify text message handling
1381 if [ "$test_target" = "ECC_DH" ]; then
1382 accel_text="ECC/FFDH"
1383 else
1384 accel_text="ECC"
1385 fi
1386
1387 msg "build: full + non accelerated $accel_text algs + USE_PSA"
1388
1389 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
1390
1391 make
1392
1393 msg "test suites: full + non accelerated EC algs + USE_PSA"
1394 make test
1395
1396 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
1397 tests/ssl-opt.sh
1398}
1399
1400component_test_psa_crypto_config_accel_ecc_no_bignum () {
1401 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
1402}
1403
1404component_test_psa_crypto_config_reference_ecc_no_bignum () {
1405 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
1406}
1407
1408component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
1409 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
1410}
1411
1412component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
1413 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
1414}
1415
1416# Helper for setting common configurations between:
1417# - component_test_tfm_config_p256m_driver_accel_ec()
1418# - component_test_tfm_config()
Minos Galanakis471b34c2024-07-26 15:39:24 +01001419common_tfm_config () {
1420 # Enable TF-M config
1421 cp configs/config-tfm.h "$CONFIG_H"
1422 echo "#undef MBEDTLS_PSA_CRYPTO_CONFIG_FILE" >> "$CONFIG_H"
1423 cp configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
1424
1425 # Other config adjustment to make the tests pass.
1426 # This should probably be adopted upstream.
1427 #
1428 # - USE_PSA_CRYPTO for PK_HAVE_ECC_KEYS
1429 echo "#define MBEDTLS_USE_PSA_CRYPTO" >> "$CONFIG_H"
1430
1431 # Config adjustment for better test coverage in our environment.
1432 # This is not needed just to build and pass tests.
1433 #
1434 # Enable filesystem I/O for the benefit of PK parse/write tests.
1435 echo "#define MBEDTLS_FS_IO" >> "$CONFIG_H"
1436}
1437
1438# Keep this in sync with component_test_tfm_config() as they are both meant
1439# to be used in analyze_outcomes.py for driver's coverage analysis.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001440component_test_tfm_config_p256m_driver_accel_ec () {
1441 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1442
1443 common_tfm_config
1444
1445 # Build crypto library
1446 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
1447
1448 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1449 not grep mbedtls_ecdsa_ ${BUILTIN_SRC_PATH}/ecdsa.o
1450 not grep mbedtls_ecdh_ ${BUILTIN_SRC_PATH}/ecdh.o
1451 not grep mbedtls_ecjpake_ ${BUILTIN_SRC_PATH}/ecjpake.o
1452 # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
1453 not grep mbedtls_ecp_ ${BUILTIN_SRC_PATH}/ecp.o
1454 not grep mbedtls_rsa_ ${BUILTIN_SRC_PATH}/rsa.o
1455 not grep mbedtls_dhm_ ${BUILTIN_SRC_PATH}/dhm.o
1456 not grep mbedtls_mpi_ ${BUILTIN_SRC_PATH}/bignum.o
1457 # Check that p256m was built
1458 grep -q p256_ecdsa_ library/libmbedcrypto.a
1459
1460 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1461 # files, so we want to ensure that it has not be re-enabled accidentally.
1462 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1463
1464 # Run the tests
1465 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
1466 make test
1467}
1468
1469# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
1470# they are both meant to be used in analyze_outcomes.py for driver's coverage
1471# analysis.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001472component_test_tfm_config () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001473 common_tfm_config
1474
1475 # Disable P256M driver, which is on by default, so that analyze_outcomes
1476 # can compare this test with test_tfm_config_p256m_driver_accel_ec
1477 echo "#undef MBEDTLS_PSA_P256M_DRIVER_ENABLED" >> "$CONFIG_H"
1478
1479 msg "build: TF-M config"
1480 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' tests
1481
1482 # Check that p256m was not built
1483 not grep p256_ecdsa_ library/libmbedcrypto.a
1484
1485 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
1486 # files, so we want to ensure that it has not be re-enabled accidentally.
1487 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1488
1489 msg "test: TF-M config"
1490 make test
1491}
1492
Minos Galanakis471b34c2024-07-26 15:39:24 +01001493# This is an helper used by:
1494# - component_test_psa_ecc_key_pair_no_derive
1495# - component_test_psa_ecc_key_pair_no_generate
1496# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
1497# enabled, but one. Input arguments are as follows:
1498# - $1 is the key type under test, i.e. ECC/RSA/DH
1499# - $2 is the key option to be unset (i.e. generate, derive, etc)
Minos Galanakisf78447f2024-07-26 20:49:51 +01001500build_and_test_psa_want_key_pair_partial () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001501 key_type=$1
1502 unset_option=$2
1503 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
1504
1505 msg "build: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
1506 scripts/config.py full
1507 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1508 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1509
1510 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
1511 # crypto_config.h so we just disable the one we don't want.
1512 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
1513
1514 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1515
1516 msg "test: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
1517 make test
1518}
1519
Minos Galanakisf78447f2024-07-26 20:49:51 +01001520component_test_psa_ecc_key_pair_no_derive () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001521 build_and_test_psa_want_key_pair_partial "ECC" "DERIVE"
1522}
1523
Minos Galanakisf78447f2024-07-26 20:49:51 +01001524component_test_psa_ecc_key_pair_no_generate () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001525 build_and_test_psa_want_key_pair_partial "ECC" "GENERATE"
1526}
1527
1528config_psa_crypto_accel_rsa () {
1529 driver_only=$1
1530
1531 # Start from crypto_full config (no X.509, no TLS)
1532 helper_libtestdriver1_adjust_config "crypto_full"
1533
1534 if [ "$driver_only" -eq 1 ]; then
1535 # Remove RSA support and its dependencies
1536 scripts/config.py unset MBEDTLS_RSA_C
1537 scripts/config.py unset MBEDTLS_PKCS1_V15
1538 scripts/config.py unset MBEDTLS_PKCS1_V21
1539
1540 # We need PEM parsing in the test library as well to support the import
1541 # of PEM encoded RSA keys.
1542 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
1543 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
1544 fi
1545}
1546
1547component_test_psa_crypto_config_accel_rsa_crypto () {
1548 msg "build: crypto_full with accelerated RSA"
1549
1550 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
1551 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
1552 KEY_TYPE_RSA_PUBLIC_KEY \
1553 KEY_TYPE_RSA_KEY_PAIR_BASIC \
1554 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
1555 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
1556 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
1557
1558 # Configure
1559 # ---------
1560
1561 config_psa_crypto_accel_rsa 1
1562
1563 # Build
1564 # -----
1565
1566 # These hashes are needed for unit tests.
1567 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1568 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
1569 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1570
1571 helper_libtestdriver1_make_main "$loc_accel_list"
1572
1573 # Make sure this was not re-enabled by accident (additive config)
1574 not grep mbedtls_rsa ${BUILTIN_SRC_PATH}/rsa.o
1575
1576 # Run the tests
1577 # -------------
1578
1579 msg "test: crypto_full with accelerated RSA"
1580 make test
1581}
1582
1583component_test_psa_crypto_config_reference_rsa_crypto () {
1584 msg "build: crypto_full with non-accelerated RSA"
1585
1586 # Configure
1587 # ---------
1588 config_psa_crypto_accel_rsa 0
1589
1590 # Build
1591 # -----
1592 make
1593
1594 # Run the tests
1595 # -------------
1596 msg "test: crypto_full with non-accelerated RSA"
1597 make test
1598}
1599
1600# This is a temporary test to verify that full RSA support is present even when
1601# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001602component_test_new_psa_want_key_pair_symbol () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001603 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1604
1605 # Create a temporary output file unless there is already one set
1606 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
1607 REMOVE_OUTCOME_ON_EXIT="no"
1608 else
1609 REMOVE_OUTCOME_ON_EXIT="yes"
1610 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
1611 export MBEDTLS_TEST_OUTCOME_FILE
1612 fi
1613
1614 # Start from crypto configuration
1615 scripts/config.py crypto
1616
1617 # Remove RSA support and its dependencies
1618 scripts/config.py unset MBEDTLS_PKCS1_V15
1619 scripts/config.py unset MBEDTLS_PKCS1_V21
1620 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1621 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1622 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1623 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1624 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1625 scripts/config.py unset MBEDTLS_RSA_C
1626 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1627
1628 # Enable PSA support
1629 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1630
1631 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
1632 # that proper translations is done in crypto_legacy.h.
1633 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
1634 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
1635 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
1636
1637 make
1638
1639 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
1640 make test
1641
1642 # Parse only 1 relevant line from the outcome file, i.e. a test which is
1643 # performing RSA signature.
1644 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
1645 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
1646
1647 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
1648 rm $MBEDTLS_TEST_OUTCOME_FILE
1649 fi
1650}
1651
1652component_test_psa_crypto_config_accel_hash () {
1653 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
1654
1655 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1656 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1657 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1658
1659 # Configure
1660 # ---------
1661
1662 # Start from default config (no USE_PSA)
1663 helper_libtestdriver1_adjust_config "default"
1664
1665 # Disable the things that are being accelerated
1666 scripts/config.py unset MBEDTLS_MD5_C
1667 scripts/config.py unset MBEDTLS_RIPEMD160_C
1668 scripts/config.py unset MBEDTLS_SHA1_C
1669 scripts/config.py unset MBEDTLS_SHA224_C
1670 scripts/config.py unset MBEDTLS_SHA256_C
1671 scripts/config.py unset MBEDTLS_SHA384_C
1672 scripts/config.py unset MBEDTLS_SHA512_C
1673 scripts/config.py unset MBEDTLS_SHA3_C
1674
1675 # Build
1676 # -----
1677
1678 helper_libtestdriver1_make_drivers "$loc_accel_list"
1679
1680 helper_libtestdriver1_make_main "$loc_accel_list"
1681
1682 # There's a risk of something getting re-enabled via config_psa.h;
1683 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1684 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1685 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1686 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1687 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1688 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1689
1690 # Run the tests
1691 # -------------
1692
1693 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
1694 make test
1695}
1696
1697# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001698config_psa_crypto_hash_use_psa () {
1699 driver_only="$1"
1700 # start with config full for maximum coverage (also enables USE_PSA)
1701 helper_libtestdriver1_adjust_config "full"
1702 if [ "$driver_only" -eq 1 ]; then
1703 # disable the built-in implementation of hashes
1704 scripts/config.py unset MBEDTLS_MD5_C
1705 scripts/config.py unset MBEDTLS_RIPEMD160_C
1706 scripts/config.py unset MBEDTLS_SHA1_C
1707 scripts/config.py unset MBEDTLS_SHA224_C
1708 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
1709 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
1710 scripts/config.py unset MBEDTLS_SHA384_C
1711 scripts/config.py unset MBEDTLS_SHA512_C
1712 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
1713 scripts/config.py unset MBEDTLS_SHA3_C
1714 fi
1715}
1716
1717# Note that component_test_psa_crypto_config_reference_hash_use_psa
1718# is related to this component and both components need to be kept in sync.
1719# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001720component_test_psa_crypto_config_accel_hash_use_psa () {
1721 msg "test: full with accelerated hashes"
1722
1723 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1724 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1725 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1726
1727 # Configure
1728 # ---------
1729
1730 config_psa_crypto_hash_use_psa 1
1731
1732 # Build
1733 # -----
1734
1735 helper_libtestdriver1_make_drivers "$loc_accel_list"
1736
1737 helper_libtestdriver1_make_main "$loc_accel_list"
1738
1739 # There's a risk of something getting re-enabled via config_psa.h;
1740 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
1741 not grep mbedtls_md5 ${BUILTIN_SRC_PATH}/md5.o
1742 not grep mbedtls_sha1 ${BUILTIN_SRC_PATH}/sha1.o
1743 not grep mbedtls_sha256 ${BUILTIN_SRC_PATH}/sha256.o
1744 not grep mbedtls_sha512 ${BUILTIN_SRC_PATH}/sha512.o
1745 not grep mbedtls_ripemd160 ${BUILTIN_SRC_PATH}/ripemd160.o
1746
1747 # Run the tests
1748 # -------------
1749
1750 msg "test: full with accelerated hashes"
1751 make test
1752
1753 # This is mostly useful so that we can later compare outcome files with
1754 # the reference config in analyze_outcomes.py, to check that the
1755 # dependency declarations in ssl-opt.sh and in TLS code are correct.
1756 msg "test: ssl-opt.sh, full with accelerated hashes"
1757 tests/ssl-opt.sh
1758
1759 # This is to make sure all ciphersuites are exercised, but we don't need
1760 # interop testing (besides, we already got some from ssl-opt.sh).
1761 msg "test: compat.sh, full with accelerated hashes"
1762 tests/compat.sh -p mbedTLS -V YES
1763}
1764
1765# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
1766# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
1767# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
1768# Both components need to be kept in sync.
Minos Galanakisf78447f2024-07-26 20:49:51 +01001769component_test_psa_crypto_config_reference_hash_use_psa () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001770 msg "test: full without accelerated hashes"
1771
1772 config_psa_crypto_hash_use_psa 0
1773
1774 make
1775
1776 msg "test: full without accelerated hashes"
1777 make test
1778
1779 msg "test: ssl-opt.sh, full without accelerated hashes"
1780 tests/ssl-opt.sh
1781}
1782
1783# Auxiliary function to build config for hashes with and without drivers
Minos Galanakis471b34c2024-07-26 15:39:24 +01001784config_psa_crypto_hmac_use_psa () {
1785 driver_only="$1"
1786 # start with config full for maximum coverage (also enables USE_PSA)
1787 helper_libtestdriver1_adjust_config "full"
1788
1789 if [ "$driver_only" -eq 1 ]; then
1790 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
1791 # is still enabled though (for ENTROPY_C among others).
1792 scripts/config.py unset MBEDTLS_MD_C
1793 # Disable also the builtin hashes since they are supported by the driver
1794 # and MD module is able to perform PSA dispathing.
1795 scripts/config.py unset-all MBEDTLS_SHA
1796 scripts/config.py unset MBEDTLS_MD5_C
1797 scripts/config.py unset MBEDTLS_RIPEMD160_C
1798 fi
1799
1800 # Direct dependencies of MD_C. We disable them also in the reference
1801 # component to work with the same set of features.
1802 scripts/config.py unset MBEDTLS_PKCS7_C
1803 scripts/config.py unset MBEDTLS_PKCS5_C
1804 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1805 scripts/config.py unset MBEDTLS_HKDF_C
1806 # Dependencies of HMAC_DRBG
1807 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
1808 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
1809}
1810
Minos Galanakisf78447f2024-07-26 20:49:51 +01001811component_test_psa_crypto_config_accel_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001812 msg "test: full with accelerated hmac"
1813
1814 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
1815 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1816 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1817 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1818
1819 # Configure
1820 # ---------
1821
1822 config_psa_crypto_hmac_use_psa 1
1823
1824 # Build
1825 # -----
1826
1827 helper_libtestdriver1_make_drivers "$loc_accel_list"
1828
1829 helper_libtestdriver1_make_main "$loc_accel_list"
1830
1831 # Ensure that built-in support for HMAC is disabled.
1832 not grep mbedtls_md_hmac ${BUILTIN_SRC_PATH}/md.o
1833
1834 # Run the tests
1835 # -------------
1836
1837 msg "test: full with accelerated hmac"
1838 make test
1839}
1840
Minos Galanakisf78447f2024-07-26 20:49:51 +01001841component_test_psa_crypto_config_reference_hmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001842 msg "test: full without accelerated hmac"
1843
1844 config_psa_crypto_hmac_use_psa 0
1845
1846 make
1847
1848 msg "test: full without accelerated hmac"
1849 make test
1850}
1851
1852component_test_psa_crypto_config_accel_des () {
1853 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
1854
1855 # Albeit this components aims at accelerating DES which should only support
1856 # CBC and ECB modes, we need to accelerate more than that otherwise DES_C
1857 # would automatically be re-enabled by "config_adjust_legacy_from_psa.c"
1858 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 \
1859 ALG_CTR ALG_CFB ALG_OFB ALG_XTS ALG_CMAC \
1860 KEY_TYPE_DES"
1861
1862 # Note: we cannot accelerate all ciphers' key types otherwise we would also
1863 # have to either disable CCM/GCM or accelerate them, but that's out of scope
1864 # of this component. This limitation will be addressed by #8598.
1865
1866 # Configure
1867 # ---------
1868
1869 # Start from the full config
1870 helper_libtestdriver1_adjust_config "full"
1871
1872 # Disable the things that are being accelerated
1873 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1874 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
1875 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
1876 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
1877 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
1878 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
1879 scripts/config.py unset MBEDTLS_DES_C
1880 scripts/config.py unset MBEDTLS_CMAC_C
1881
1882 # Build
1883 # -----
1884
1885 helper_libtestdriver1_make_drivers "$loc_accel_list"
1886
1887 helper_libtestdriver1_make_main "$loc_accel_list"
1888
1889 # Make sure this was not re-enabled by accident (additive config)
1890 not grep mbedtls_des* ${BUILTIN_SRC_PATH}/des.o
1891
1892 # Run the tests
1893 # -------------
1894
1895 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
1896 make test
1897}
1898
1899component_test_psa_crypto_config_accel_aead () {
1900 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
1901
1902 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
1903 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
1904
1905 # Configure
1906 # ---------
1907
1908 # Start from full config
1909 helper_libtestdriver1_adjust_config "full"
1910
1911 # Disable things that are being accelerated
1912 scripts/config.py unset MBEDTLS_GCM_C
1913 scripts/config.py unset MBEDTLS_CCM_C
1914 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1915
1916 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
1917 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1918
1919 # Build
1920 # -----
1921
1922 helper_libtestdriver1_make_drivers "$loc_accel_list"
1923
1924 helper_libtestdriver1_make_main "$loc_accel_list"
1925
1926 # Make sure this was not re-enabled by accident (additive config)
1927 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
1928 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
1929 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
1930
1931 # Run the tests
1932 # -------------
1933
1934 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
1935 make test
1936}
1937
1938# This is a common configuration function used in:
1939# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1940# - component_test_psa_crypto_config_reference_cipher_aead_cmac
Minos Galanakisf78447f2024-07-26 20:49:51 +01001941common_psa_crypto_config_accel_cipher_aead_cmac () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01001942 # Start from the full config
1943 helper_libtestdriver1_adjust_config "full"
1944
1945 scripts/config.py unset MBEDTLS_NIST_KW_C
1946}
1947
1948# The 2 following test components, i.e.
1949# - component_test_psa_crypto_config_accel_cipher_aead_cmac
1950# - component_test_psa_crypto_config_reference_cipher_aead_cmac
1951# are meant to be used together in analyze_outcomes.py script in order to test
1952# driver's coverage for ciphers and AEADs.
Minos Galanakis471b34c2024-07-26 15:39:24 +01001953component_test_psa_crypto_config_accel_cipher_aead_cmac () {
1954 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
1955
1956 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
1957 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
1958 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
1959 KEY_TYPE_DES KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
1960
1961 # Configure
1962 # ---------
1963
1964 common_psa_crypto_config_accel_cipher_aead_cmac
1965
1966 # Disable the things that are being accelerated
1967 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1968 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
1969 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
1970 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
1971 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
1972 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
1973 scripts/config.py unset MBEDTLS_GCM_C
1974 scripts/config.py unset MBEDTLS_CCM_C
1975 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1976 scripts/config.py unset MBEDTLS_CMAC_C
1977 scripts/config.py unset MBEDTLS_DES_C
1978 scripts/config.py unset MBEDTLS_AES_C
1979 scripts/config.py unset MBEDTLS_ARIA_C
1980 scripts/config.py unset MBEDTLS_CHACHA20_C
1981 scripts/config.py unset MBEDTLS_CAMELLIA_C
1982
1983 # Disable CIPHER_C entirely as all ciphers/AEADs are accelerated and PSA
1984 # does not depend on it.
1985 scripts/config.py unset MBEDTLS_CIPHER_C
1986
1987 # Build
1988 # -----
1989
1990 helper_libtestdriver1_make_drivers "$loc_accel_list"
1991
1992 helper_libtestdriver1_make_main "$loc_accel_list"
1993
1994 # Make sure this was not re-enabled by accident (additive config)
1995 not grep mbedtls_cipher ${BUILTIN_SRC_PATH}/cipher.o
1996 not grep mbedtls_des ${BUILTIN_SRC_PATH}/des.o
1997 not grep mbedtls_aes ${BUILTIN_SRC_PATH}/aes.o
1998 not grep mbedtls_aria ${BUILTIN_SRC_PATH}/aria.o
1999 not grep mbedtls_camellia ${BUILTIN_SRC_PATH}/camellia.o
2000 not grep mbedtls_ccm ${BUILTIN_SRC_PATH}/ccm.o
2001 not grep mbedtls_gcm ${BUILTIN_SRC_PATH}/gcm.o
2002 not grep mbedtls_chachapoly ${BUILTIN_SRC_PATH}/chachapoly.o
2003 not grep mbedtls_cmac ${BUILTIN_SRC_PATH}/cmac.o
2004
2005 # Run the tests
2006 # -------------
2007
2008 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
2009 make test
2010
2011 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
2012 tests/ssl-opt.sh
2013
2014 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
2015 tests/compat.sh -V NO -p mbedTLS
2016}
2017
2018component_test_psa_crypto_config_reference_cipher_aead_cmac () {
2019 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
2020 common_psa_crypto_config_accel_cipher_aead_cmac
2021
2022 make
2023
2024 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
2025 make test
2026
2027 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
2028 tests/ssl-opt.sh
2029
2030 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
2031 tests/compat.sh -V NO -p mbedTLS
2032}
2033
Minos Galanakisf78447f2024-07-26 20:49:51 +01002034common_block_cipher_dispatch () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002035 TEST_WITH_DRIVER="$1"
2036
2037 # Start from the full config
2038 helper_libtestdriver1_adjust_config "full"
2039
2040 if [ "$TEST_WITH_DRIVER" -eq 1 ]; then
2041 # Disable key types that are accelerated (there is no legacy equivalent
2042 # symbol for ECB)
2043 scripts/config.py unset MBEDTLS_AES_C
2044 scripts/config.py unset MBEDTLS_ARIA_C
2045 scripts/config.py unset MBEDTLS_CAMELLIA_C
2046 fi
2047
2048 # Disable cipher's modes that, when not accelerated, cause
2049 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
2050 # Keep this also in the reference component in order to skip the same tests
2051 # that were skipped in the accelerated one.
2052 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
2053 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
2054 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
2055 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
2056 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
2057 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
2058 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
2059 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
2060
2061 # Disable direct dependency on AES_C
2062 scripts/config.py unset MBEDTLS_NIST_KW_C
2063
2064 # Prevent the cipher module from using deprecated PSA path. The reason is
2065 # that otherwise there will be tests relying on "aes_info" (defined in
2066 # "cipher_wrap.c") whose functions are not available when AES_C is
2067 # not defined. ARIA and Camellia are not a problem in this case because
2068 # the PSA path is not tested for these key types.
2069 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
2070}
2071
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002072component_test_full_block_cipher_psa_dispatch_static_keystore () {
2073 msg "build: full + PSA dispatch in block_cipher with static keystore"
2074 # Check that the static key store works well when CTR_DRBG uses a
2075 # PSA key for AES.
2076 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2077
2078 loc_accel_list="ALG_ECB_NO_PADDING \
2079 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2080
2081 # Configure
2082 # ---------
2083
2084 common_block_cipher_dispatch 1
2085
2086 # Build
2087 # -----
2088
2089 helper_libtestdriver1_make_drivers "$loc_accel_list"
2090
2091 helper_libtestdriver1_make_main "$loc_accel_list"
2092
2093 # Make sure disabled components were not re-enabled by accident (additive
2094 # config)
2095 not grep mbedtls_aes_ library/aes.o
2096 not grep mbedtls_aria_ library/aria.o
2097 not grep mbedtls_camellia_ library/camellia.o
2098
2099 # Run the tests
2100 # -------------
2101
2102 msg "test: full + PSA dispatch in block_cipher with static keystore"
2103 make test
2104}
2105
Minos Galanakis471b34c2024-07-26 15:39:24 +01002106component_test_full_block_cipher_psa_dispatch () {
2107 msg "build: full + PSA dispatch in block_cipher"
2108
2109 loc_accel_list="ALG_ECB_NO_PADDING \
2110 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2111
2112 # Configure
2113 # ---------
2114
2115 common_block_cipher_dispatch 1
2116
2117 # Build
2118 # -----
2119
2120 helper_libtestdriver1_make_drivers "$loc_accel_list"
2121
2122 helper_libtestdriver1_make_main "$loc_accel_list"
2123
2124 # Make sure disabled components were not re-enabled by accident (additive
2125 # config)
2126 not grep mbedtls_aes_ ${BUILTIN_SRC_PATH}/aes.o
2127 not grep mbedtls_aria_ ${BUILTIN_SRC_PATH}/aria.o
2128 not grep mbedtls_camellia_ ${BUILTIN_SRC_PATH}/camellia.o
2129
2130 # Run the tests
2131 # -------------
2132
2133 msg "test: full + PSA dispatch in block_cipher"
2134 make test
2135}
2136
2137# This is the reference component of component_test_full_block_cipher_psa_dispatch
Minos Galanakis471b34c2024-07-26 15:39:24 +01002138component_test_full_block_cipher_legacy_dispatch () {
2139 msg "build: full + legacy dispatch in block_cipher"
2140
2141 common_block_cipher_dispatch 0
2142
2143 make
2144
2145 msg "test: full + legacy dispatch in block_cipher"
2146 make test
2147}
2148
Minos Galanakisf78447f2024-07-26 20:49:51 +01002149component_test_aead_chachapoly_disabled () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002150 msg "build: full minus CHACHAPOLY"
2151 scripts/config.py full
2152 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2153 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2154 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2155
2156 msg "test: full minus CHACHAPOLY"
2157 make test
2158}
2159
Minos Galanakisf78447f2024-07-26 20:49:51 +01002160component_test_aead_only_ccm () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002161 msg "build: full minus CHACHAPOLY and GCM"
2162 scripts/config.py full
2163 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2164 scripts/config.py unset MBEDTLS_GCM_C
2165 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2166 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2167 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2168
2169 msg "test: full minus CHACHAPOLY and GCM"
2170 make test
2171}
2172
Minos Galanakisf78447f2024-07-26 20:49:51 +01002173component_test_ccm_aes_sha256 () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002174 msg "build: CCM + AES + SHA256 configuration"
2175
2176 cp "$CONFIG_TEST_DRIVER_H" "$CONFIG_H"
2177 cp configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
2178
2179 make
2180
2181 msg "test: CCM + AES + SHA256 configuration"
2182 make test
2183}
2184
2185# Test that the given .o file builds with all (valid) combinations of the given options.
2186#
2187# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
2188#
2189# The validator function is the name of a function to validate the combination of options.
2190# It may be "" if all combinations are valid.
2191# It receives a string containing a combination of options, as passed to the compiler,
2192# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Minos Galanakisf78447f2024-07-26 20:49:51 +01002193build_test_config_combos () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002194 file=$1
2195 shift
2196 validate_options=$1
2197 shift
2198 options=("$@")
2199
2200 # clear all of the options so that they can be overridden on the clang commandline
2201 for opt in "${options[@]}"; do
2202 ./scripts/config.py unset ${opt}
2203 done
2204
2205 # enter the library directory
2206 cd library
2207
2208 # The most common issue is unused variables/functions, so ensure -Wunused is set.
2209 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
2210
2211 # Extract the command generated by the Makefile to build the target file.
2212 # This ensures that we have any include paths, macro definitions, etc
2213 # that may be applied by make.
2214 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
2215 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
2216
2217 makefile=$(TMPDIR=. mktemp)
2218 deps=""
2219
2220 len=${#options[@]}
2221 source_file=../${file%.o}.c
2222
2223 targets=0
2224 echo 'include Makefile' >${makefile}
2225
2226 for ((i = 0; i < $((2**${len})); i++)); do
2227 # generate each of 2^n combinations of options
2228 # each bit of $i is used to determine if options[i] will be set or not
2229 target="t"
2230 clang_args=""
2231 for ((j = 0; j < ${len}; j++)); do
2232 if (((i >> j) & 1)); then
2233 opt=-D${options[$j]}
2234 clang_args="${clang_args} ${opt}"
2235 target="${target}${opt}"
2236 fi
2237 done
2238
2239 # if combination is not known to be invalid, add it to the makefile
2240 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
2241 cmd="${compile_cmd} ${clang_args}"
2242 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
2243
2244 deps="${deps} ${target}"
2245 ((++targets))
2246 fi
2247 done
2248
2249 echo "build_test_config_combos: ${deps}" >> ${makefile}
2250
2251 # execute all of the commands via Make (probably in parallel)
2252 make -s -f ${makefile} build_test_config_combos
2253 echo "$targets targets checked"
2254
2255 # clean up the temporary makefile
2256 rm ${makefile}
2257}
2258
Minos Galanakisf78447f2024-07-26 20:49:51 +01002259validate_aes_config_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002260 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
2261 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
2262 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
2263 return 1
2264 fi
2265 fi
2266 return 0
2267}
2268
Minos Galanakisf78447f2024-07-26 20:49:51 +01002269component_build_aes_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002270 # 18s - around 90ms per clang invocation on M1 Pro
2271 #
2272 # aes.o has many #if defined(...) guards that intersect in complex ways.
2273 # Test that all the combinations build cleanly.
2274
2275 MBEDTLS_ROOT_DIR="$PWD"
2276 msg "build: aes.o for all combinations of relevant config options"
2277
2278 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002279 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002280 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2281 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2282
2283 cd "$MBEDTLS_ROOT_DIR"
2284 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
2285
2286 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES,
2287 # manually set or unset those configurations to check
2288 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
Ronald Cron54d1eec2024-09-06 09:55:38 +02002289 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
Minos Galanakis471b34c2024-07-26 15:39:24 +01002290 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Minos Galanakis471b34c2024-07-26 15:39:24 +01002291 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002292 scripts/config.py unset MBEDTLS_NIST_KW_C
Ronald Cron54d1eec2024-09-06 09:55:38 +02002293
2294 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
2295 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
2296 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
2297 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
2298 # Note: The three unsets below are to be removed for Mbed TLS 4.0
2299 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2300 scripts/config.py unset MBEDTLS_DES_C
2301
Minos Galanakis471b34c2024-07-26 15:39:24 +01002302 build_test_config_combos ${BUILTIN_SRC_PATH}/aes.o validate_aes_config_variations \
Thomas Daubney6cf05f92024-07-18 11:30:22 +01002303 "MBEDTLS_AES_ROM_TABLES" \
Minos Galanakis471b34c2024-07-26 15:39:24 +01002304 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
2305 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
2306}
2307
Minos Galanakisf78447f2024-07-26 20:49:51 +01002308component_test_sha3_variations () {
Minos Galanakis471b34c2024-07-26 15:39:24 +01002309 msg "sha3 loop unroll variations"
2310
2311 # define minimal config sufficient to test SHA3
2312 cat > include/mbedtls/mbedtls_config.h << END
2313 #define MBEDTLS_SELF_TEST
2314 #define MBEDTLS_SHA3_C
2315END
2316
2317 msg "all loops unrolled"
2318 make clean
2319 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"
2320 ./tf-psa-crypto/tests/test_suite_shax
2321
2322 msg "all loops rolled up"
2323 make clean
2324 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"
2325 ./tf-psa-crypto/tests/test_suite_shax
2326}
2327
Minos Galanakisf699d512024-08-01 11:32:30 +01002328support_build_aes_aesce_armcc () {
2329 support_build_armcc
2330}
2331
Minos Galanakis471b34c2024-07-26 15:39:24 +01002332# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
2333component_build_aes_aesce_armcc () {
2334 msg "Build: AESCE test on arm64 platform without plain C."
2335 scripts/config.py baremetal
2336
2337 # armc[56] don't support SHA-512 intrinsics
2338 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2339
2340 # Stop armclang warning about feature detection for A64_CRYPTO.
2341 # With this enabled, the library does build correctly under armclang,
2342 # but in baremetal builds (as tested here), feature detection is
2343 # unavailable, and the user is notified via a #warning. So enabling
2344 # this feature would prevent us from building with -Werror on
2345 # armclang. Tracked in #7198.
2346 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2347 scripts/config.py set MBEDTLS_HAVE_ASM
2348
2349 msg "AESCE, build with default configuration."
2350 scripts/config.py set MBEDTLS_AESCE_C
2351 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
2352 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
2353
2354 msg "AESCE, build AESCE only"
2355 scripts/config.py set MBEDTLS_AESCE_C
2356 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
2357 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
2358}
2359
Minos Galanakis471b34c2024-07-26 15:39:24 +01002360component_test_aes_only_128_bit_keys () {
2361 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2362 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2363
2364 make CFLAGS='-O2 -Werror -Wall -Wextra'
2365
2366 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
2367 make test
2368}
2369
2370component_test_no_ctr_drbg_aes_only_128_bit_keys () {
2371 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2372 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2373 scripts/config.py unset MBEDTLS_CTR_DRBG_C
2374
2375 make CC=clang CFLAGS='-Werror -Wall -Wextra'
2376
2377 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
2378 make test
2379}
2380
2381component_test_aes_only_128_bit_keys_have_builtins () {
2382 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2383 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
2384 scripts/config.py unset MBEDTLS_AESNI_C
2385 scripts/config.py unset MBEDTLS_AESCE_C
2386
2387 make CFLAGS='-O2 -Werror -Wall -Wextra'
2388
2389 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2390 make test
2391
2392 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
2393 programs/test/selftest
2394}
2395
2396component_test_gcm_largetable () {
2397 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2398 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
2399 scripts/config.py unset MBEDTLS_AESNI_C
2400 scripts/config.py unset MBEDTLS_AESCE_C
2401
2402 make CFLAGS='-O2 -Werror -Wall -Wextra'
2403
2404 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
2405 make test
2406}
2407
2408component_test_aes_fewer_tables () {
2409 msg "build: default config with AES_FEWER_TABLES enabled"
2410 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2411 make CFLAGS='-O2 -Werror -Wall -Wextra'
2412
2413 msg "test: AES_FEWER_TABLES"
2414 make test
2415}
2416
2417component_test_aes_rom_tables () {
2418 msg "build: default config with AES_ROM_TABLES enabled"
2419 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2420 make CFLAGS='-O2 -Werror -Wall -Wextra'
2421
2422 msg "test: AES_ROM_TABLES"
2423 make test
2424}
2425
2426component_test_aes_fewer_tables_and_rom_tables () {
2427 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
2428 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2429 scripts/config.py set MBEDTLS_AES_ROM_TABLES
2430 make CFLAGS='-O2 -Werror -Wall -Wextra'
2431
2432 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2433 make test
2434}
2435
Ronald Cron66040472024-09-06 10:14:38 +02002436# helper for component_test_block_cipher_no_decrypt_aesni() which:
Minos Galanakis471b34c2024-07-26 15:39:24 +01002437# - enable/disable the list of config options passed from -s/-u respectively.
2438# - build
2439# - test for tests_suite_xxx
2440# - selftest
2441#
2442# Usage: helper_block_cipher_no_decrypt_build_test
2443# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
2444# Options: -s set_opts the list of config options to enable
2445# -u unset_opts the list of config options to disable
2446# -c cflags the list of options passed to CFLAGS
2447# -l ldflags the list of options passed to LDFLAGS
Minos Galanakis471b34c2024-07-26 15:39:24 +01002448helper_block_cipher_no_decrypt_build_test () {
2449 while [ $# -gt 0 ]; do
2450 case "$1" in
2451 -s)
2452 shift; local set_opts="$1";;
2453 -u)
2454 shift; local unset_opts="$1";;
2455 -c)
2456 shift; local cflags="-Werror -Wall -Wextra $1";;
2457 -l)
2458 shift; local ldflags="$1";;
2459 esac
2460 shift
2461 done
2462 set_opts="${set_opts:-}"
2463 unset_opts="${unset_opts:-}"
2464 cflags="${cflags:-}"
2465 ldflags="${ldflags:-}"
2466
2467 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
2468 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
2469
2470 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2471 make clean
2472 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
2473
2474 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2475 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2476 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2477 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2478 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2479 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2480 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
2481 not grep mbedtls_aesni_inverse_key ${BUILTIN_SRC_PATH}/aesni.o
2482
2483 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2484 make test
2485
2486 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
2487 programs/test/selftest
2488}
2489
Ronald Cron66040472024-09-06 10:14:38 +02002490# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
2491config_block_cipher_no_decrypt () {
2492 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
2493 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2494 scripts/config.py unset MBEDTLS_NIST_KW_C
2495
2496 # Enable support for cryptographic mechanisms through the PSA API.
2497 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
2498 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2499 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
2500 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
2501 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
2502 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
2503 # Note: The three unsets below are to be removed for Mbed TLS 4.0
2504 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2505 scripts/config.py unset MBEDTLS_DES_C
2506}
2507
2508component_test_block_cipher_no_decrypt_aesni () {
2509 # Test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics, AESNI assembly and
2510 # AES C implementation on x86_64 and with AESNI intrinsics on x86.
2511
2512 # This consistently causes an llvm crash on clang 3.8, so use gcc
2513 export CC=gcc
2514 config_block_cipher_no_decrypt
2515
Minos Galanakis471b34c2024-07-26 15:39:24 +01002516 # test AESNI intrinsics
2517 helper_block_cipher_no_decrypt_build_test \
2518 -s "MBEDTLS_AESNI_C" \
2519 -c "-mpclmul -msse2 -maes"
2520
2521 # test AESNI assembly
2522 helper_block_cipher_no_decrypt_build_test \
2523 -s "MBEDTLS_AESNI_C" \
2524 -c "-mno-pclmul -mno-sse2 -mno-aes"
2525
2526 # test AES C implementation
2527 helper_block_cipher_no_decrypt_build_test \
2528 -u "MBEDTLS_AESNI_C"
2529
2530 # test AESNI intrinsics for i386 target
2531 helper_block_cipher_no_decrypt_build_test \
2532 -s "MBEDTLS_AESNI_C" \
2533 -c "-m32 -mpclmul -msse2 -maes" \
2534 -l "-m32"
2535}
2536
Minos Galanakisf699d512024-08-01 11:32:30 +01002537support_test_block_cipher_no_decrypt_aesce_armcc () {
2538 support_build_armcc
2539}
2540
Minos Galanakis471b34c2024-07-26 15:39:24 +01002541component_test_block_cipher_no_decrypt_aesce_armcc () {
2542 scripts/config.py baremetal
2543
2544 # armc[56] don't support SHA-512 intrinsics
2545 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2546
2547 # Stop armclang warning about feature detection for A64_CRYPTO.
2548 # With this enabled, the library does build correctly under armclang,
2549 # but in baremetal builds (as tested here), feature detection is
2550 # unavailable, and the user is notified via a #warning. So enabling
2551 # this feature would prevent us from building with -Werror on
2552 # armclang. Tracked in #7198.
2553 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2554 scripts/config.py set MBEDTLS_HAVE_ASM
2555
Ronald Cron66040472024-09-06 10:14:38 +02002556 config_block_cipher_no_decrypt
Minos Galanakis471b34c2024-07-26 15:39:24 +01002557
2558 # test AESCE baremetal build
2559 scripts/config.py set MBEDTLS_AESCE_C
2560 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
2561 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
2562
2563 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
2564 not grep mbedtls_aes_setkey_dec ${BUILTIN_SRC_PATH}/aes.o
2565 not grep mbedtls_aria_setkey_dec ${BUILTIN_SRC_PATH}/aria.o
2566 not grep mbedtls_camellia_setkey_dec ${BUILTIN_SRC_PATH}/camellia.o
2567 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
2568 not grep mbedtls_internal_aes_decrypt ${BUILTIN_SRC_PATH}/aes.o
2569 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
2570 not grep mbedtls_aesce_inverse_key ${BUILTIN_SRC_PATH}/aesce.o
2571 not grep aesce_decrypt_block ${BUILTIN_SRC_PATH}/aesce.o
2572}
2573
2574component_test_ctr_drbg_aes_256_sha_256 () {
2575 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2576 scripts/config.py full
2577 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2578 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
2579 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2580 make
2581
2582 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2583 make test
2584}
2585
2586component_test_ctr_drbg_aes_128_sha_512 () {
2587 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2588 scripts/config.py full
2589 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2590 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2591 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2592 make
2593
2594 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2595 make test
2596}
2597
2598component_test_ctr_drbg_aes_128_sha_256 () {
2599 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (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 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
2604 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2605 make
2606
2607 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2608 make test
2609}
2610
2611component_test_se_default () {
2612 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2613 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
2614 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
2615
2616 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2617 make test
2618}
2619
Gilles Peskinea9dda7e2024-06-21 11:25:01 +02002620component_test_full_static_keystore () {
2621 msg "build: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2622 scripts/config.py full
2623 scripts/config.py unset MBEDTLS_PSA_KEY_STORE_DYNAMIC
2624 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
2625
2626 msg "test: full config - MBEDTLS_PSA_KEY_STORE_DYNAMIC"
2627 make test
2628}
2629
Minos Galanakis471b34c2024-07-26 15:39:24 +01002630component_test_psa_crypto_drivers () {
2631 msg "build: full + test drivers dispatching to builtins"
2632 scripts/config.py full
2633 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
2634 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
2635 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
2636 loc_cflags="${loc_cflags} -I../tests/include -O2"
2637
2638 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
2639
2640 msg "test: full + test drivers dispatching to builtins"
2641 make test
2642}
2643
2644component_build_psa_config_file () {
2645 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
2646 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2647 cp "$CRYPTO_CONFIG_H" psa_test_config.h
2648 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
2649 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
2650 # Make sure this feature is enabled. We'll disable it in the next phase.
2651 programs/test/query_compile_time_config MBEDTLS_CMAC_C
2652 make clean
2653
2654 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
2655 # In the user config, disable one feature and its dependencies, which will
2656 # reflect on the mbedtls configuration so we can query it with
2657 # query_compile_time_config.
2658 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
2659 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
2660 scripts/config.py unset MBEDTLS_CMAC_C
2661 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
2662 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
2663
2664 rm -f psa_test_config.h psa_user_config.h
2665}
2666
2667component_build_psa_alt_headers () {
2668 msg "build: make with PSA alt headers" # ~20s
2669
2670 # Generate alternative versions of the substitutable headers with the
2671 # same content except different include guards.
2672 make -C tests include/alt-extra/psa/crypto_platform_alt.h include/alt-extra/psa/crypto_struct_alt.h
2673
2674 # Build the library and some programs.
2675 # Don't build the fuzzers to avoid having to go through hoops to set
2676 # a correct include path for programs/fuzz/Makefile.
2677 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
2678 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\"'"
2679
2680 # Check that we're getting the alternative include guards and not the
2681 # original include guards.
2682 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
2683 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
2684 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
2685 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
2686}
2687
2688component_test_min_mpi_window_size () {
2689 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
2690 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
2691 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2692 make
2693
2694 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2695 make test
2696}
2697
Minos Galanakis6aab5b72024-07-25 14:24:37 +01002698