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