blob: 0c24c703ae018977af46ce9b178be9b7836f2d96 [file] [log] [blame]
Minos Galanakis77711192024-07-25 14:24:37 +01001# components.sh
2#
3# Copyright The Mbed TLS Contributors
4# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
5
6# This file contains the test components that are executed by all.sh
7
8# The functions below are named as follows:
9# * component_XXX: independent components. They can be run in any order.
10# * component_check_XXX: quick tests that aren't worth parallelizing.
11# * component_build_XXX: build things but don't run them.
12# * component_test_XXX: build and test.
13# * component_release_XXX: tests that the CI should skip during PR testing.
14# * support_XXX: if support_XXX exists and returns false then
15# component_XXX is not run by default.
16
17# Each component must start by invoking `msg` with a short informative message.
18#
19# Warning: due to the way bash detects errors, the failure of a command
20# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
21#
22# Each component is executed in a separate shell process. The component
23# fails if any command in it returns a non-zero status.
24#
25# The framework in all.sh performs some cleanup tasks after each component.
26# This means that components can assume that the working directory is in a
27# cleaned-up state, and don't need to perform the cleanup themselves.
28# * Run `make clean`.
29# * Restore `include/mbedtls/mbedtls_config.h` from a backup made before running
30# the component.
31# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
32# `tests/Makefile` and `programs/fuzz/Makefile` from git.
33# This cleans up after an in-tree use of CMake.
34#
35# The tests are roughly in order from fastest to slowest. This doesn't
36# have to be exact, but in general you should add slower tests towards
37# the end and fast checks near the beginning.
38
39
40################################################################
41#### Build and test many configurations and targets
42################################################################
Minos Galanakisf7d1cb02024-07-30 17:25:31 +010043
44################################################################
45#### Basic checks
46################################################################
47
48#
49# Test Suites to be executed
50#
51# The test ordering tries to optimize for the following criteria:
52# 1. Catch possible problems early, by running first tests that run quickly
53# and/or are more likely to fail than others (eg I use Clang most of the
54# time, so start with a GCC build).
55# 2. Minimize total running time, by avoiding useless rebuilds
56#
57# Indicative running times are given for reference.
58
Minos Galanakisf7d1cb02024-07-30 17:25:31 +010059################################################################
60#### Build and test many configurations and targets
61################################################################
62
63component_test_default_out_of_box () {
64 msg "build: make, default config (out-of-box)" # ~1min
65 make
66 # Disable fancy stuff
67 unset MBEDTLS_TEST_OUTCOME_FILE
68
69 msg "test: main suites make, default config (out-of-box)" # ~10s
70 make test
71
72 msg "selftest: make, default config (out-of-box)" # ~10s
73 programs/test/selftest
74
75 msg "program demos: make, default config (out-of-box)" # ~10s
76 tests/scripts/run_demos.py
77}
78
79component_test_default_cmake_gcc_asan () {
80 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
81 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
82 make
83
84 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
85 make test
86
87 msg "program demos (ASan build)" # ~10s
88 tests/scripts/run_demos.py
89
90 msg "test: selftest (ASan build)" # ~ 10s
91 programs/test/selftest
92
93 msg "test: metatests (GCC, ASan build)"
94 tests/scripts/run-metatests.sh any asan poison
95
96 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
97 tests/ssl-opt.sh
98
99 msg "test: compat.sh (ASan build)" # ~ 6 min
100 tests/compat.sh
101
102 msg "test: context-info.sh (ASan build)" # ~ 15 sec
103 tests/context-info.sh
104}
105
106component_test_default_cmake_gcc_asan_new_bignum () {
107 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
108 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
109 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
110 make
111
112 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
113 make test
114
115 msg "test: selftest (ASan build)" # ~ 10s
116 programs/test/selftest
117
118 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
119 tests/ssl-opt.sh
120
121 msg "test: compat.sh (ASan build)" # ~ 6 min
122 tests/compat.sh
123
124 msg "test: context-info.sh (ASan build)" # ~ 15 sec
125 tests/context-info.sh
126}
127
128component_test_full_cmake_gcc_asan () {
129 msg "build: full config, cmake, gcc, ASan"
130 scripts/config.py full
131 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
132 make
133
134 msg "test: main suites (inc. selftests) (full config, ASan build)"
135 make test
136
137 msg "test: selftest (full config, ASan build)" # ~ 10s
138 programs/test/selftest
139
140 msg "test: ssl-opt.sh (full config, ASan build)"
141 tests/ssl-opt.sh
142
143 # Note: the next two invocations cover all compat.sh test cases.
144 # We should use the same here and in basic-build-test.sh.
145 msg "test: compat.sh: default version (full config, ASan build)"
146 tests/compat.sh -e 'ARIA\|CHACHA'
147
148 msg "test: compat.sh: next: ARIA, Chacha (full config, ASan build)"
149 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
150
151 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
152 tests/context-info.sh
153}
154
155
156component_test_full_cmake_gcc_asan_new_bignum () {
157 msg "build: full config, cmake, gcc, ASan"
158 scripts/config.py full
159 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
160 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
161 make
162
163 msg "test: main suites (inc. selftests) (full config, new bignum, ASan)"
164 make test
165
166 msg "test: selftest (full config, new bignum, ASan)" # ~ 10s
167 programs/test/selftest
168
169 msg "test: ssl-opt.sh (full config, new bignum, ASan)"
170 tests/ssl-opt.sh
171
172 # Note: the next two invocations cover all compat.sh test cases.
173 # We should use the same here and in basic-build-test.sh.
174 msg "test: compat.sh: default version (full config, new bignum, ASan)"
175 tests/compat.sh -e 'ARIA\|CHACHA'
176
177 msg "test: compat.sh: next: ARIA, Chacha (full config, new bignum, ASan)"
178 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
179
180 msg "test: context-info.sh (full config, new bignum, ASan)" # ~ 15 sec
181 tests/context-info.sh
182}
183
184component_test_psa_crypto_key_id_encodes_owner () {
185 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
186 scripts/config.py full
187 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
188 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
189 make
190
191 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
192 make test
193}
194
195component_test_psa_assume_exclusive_buffers () {
196 msg "build: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
197 scripts/config.py full
198 scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
199 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
200 make
201
202 msg "test: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
203 make test
204}
205
206# check_renamed_symbols HEADER LIB
207# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
208# name is LIB.
209check_renamed_symbols () {
210 ! nm "$2" | sed 's/.* //' |
211 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
212}
213
214component_build_psa_crypto_spm () {
215 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
216 scripts/config.py full
217 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
218 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
219 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
220 # We can only compile, not link, since our test and sample programs
221 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
222 # is active.
223 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
224
225 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
226 # version is not present.
227 echo "Checking for renamed symbols in the library"
228 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
229}
230
231# Get a list of library-wise undefined symbols and ensure that they only
232# belong to psa_xxx() functions and not to mbedtls_yyy() ones.
233# This function is a common helper used by both:
234# - component_test_default_psa_crypto_client_without_crypto_provider
235# - component_build_full_psa_crypto_client_without_crypto_provider.
236common_check_mbedtls_missing_symbols () {
237 nm library/libmbedcrypto.a | grep ' [TRrDC] ' | grep -Eo '(mbedtls_|psa_).*' | sort -u > sym_def.txt
238 nm library/libmbedcrypto.a | grep ' U ' | grep -Eo '(mbedtls_|psa_).*' | sort -u > sym_undef.txt
239 comm sym_def.txt sym_undef.txt -13 > linking_errors.txt
240 not grep mbedtls_ linking_errors.txt
241
242 rm sym_def.txt sym_undef.txt linking_errors.txt
243}
244
245component_test_default_psa_crypto_client_without_crypto_provider () {
246 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
247
248 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
249 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
250 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
251 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
252 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
253 scripts/config.py unset MBEDTLS_LMS_C
254
255 make
256
257 msg "check missing symbols: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
258 common_check_mbedtls_missing_symbols
259
260 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
261 make test
262}
263
264component_build_full_psa_crypto_client_without_crypto_provider () {
265 msg "build: full config - PSA_CRYPTO_C"
266
267 # Use full config which includes USE_PSA and CRYPTO_CLIENT.
268 scripts/config.py full
269
270 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
271 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
272 # Dynamic secure element support is a deprecated feature and it is not
273 # available when CRYPTO_C and PSA_CRYPTO_STORAGE_C are disabled.
274 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
275
276 # Since there is no crypto provider in this build it is not possible to
277 # build all the test executables and progrems due to missing PSA functions
278 # at link time. Therefore we will just build libraries and we'll check
279 # that symbols of interest are there.
280 make lib
281
282 msg "check missing symbols: full config - PSA_CRYPTO_C"
283
284 common_check_mbedtls_missing_symbols
285
286 # Ensure that desired functions are included into the build (extend the
287 # following list as required).
288 grep mbedtls_pk_get_psa_attributes library/libmbedcrypto.a
289 grep mbedtls_pk_import_into_psa library/libmbedcrypto.a
290 grep mbedtls_pk_copy_from_psa library/libmbedcrypto.a
291}
292
293component_test_psa_crypto_rsa_no_genprime () {
294 msg "build: default config minus MBEDTLS_GENPRIME"
295 scripts/config.py unset MBEDTLS_GENPRIME
296 make
297
298 msg "test: default config minus MBEDTLS_GENPRIME"
299 make test
300}
301
302component_test_ref_configs () {
303 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
304 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
305 # want to re-generate generated files that depend on it, quite correctly.
306 # However this doesn't work as the generation script expects a specific
307 # format for mbedtls_config.h, which the other files don't follow. Also,
308 # cmake can't know this, but re-generation is actually not necessary as
309 # the generated files only depend on the list of available options, not
310 # whether they're on or off. So, disable cmake's (over-sensitive here)
311 # dependency resolution for generated files and just rely on them being
312 # present (thanks to pre_generate_files) by turning GEN_FILES off.
313 CC=$ASAN_CC cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
314 tests/scripts/test-ref-configs.pl
315}
316
317component_test_no_renegotiation () {
318 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
319 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
320 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
321 make
322
323 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
324 make test
325
326 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
327 tests/ssl-opt.sh
328}
329
330component_test_no_pem_no_fs () {
331 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
332 scripts/config.py unset MBEDTLS_PEM_PARSE_C
333 scripts/config.py unset MBEDTLS_FS_IO
334 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
335 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
336 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
337 make
338
339 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
340 make test
341
342 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
343 tests/ssl-opt.sh
344}
345
346component_test_rsa_no_crt () {
347 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
348 scripts/config.py set MBEDTLS_RSA_NO_CRT
349 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
350 make
351
352 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
353 make test
354
355 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
356 tests/ssl-opt.sh -f RSA
357
358 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
359 tests/compat.sh -t RSA
360
361 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
362 tests/context-info.sh
363}
364
365component_test_no_ctr_drbg_classic () {
366 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
367 scripts/config.py full
368 scripts/config.py unset MBEDTLS_CTR_DRBG_C
369 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
370 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
371
372 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
373 make
374
375 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
376 make test
377
378 # In this configuration, the TLS test programs use HMAC_DRBG.
379 # The SSL tests are slow, so run a small subset, just enough to get
380 # confidence that the SSL code copes with HMAC_DRBG.
381 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
382 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
383
384 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
385 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
386}
387
388component_test_no_ctr_drbg_use_psa () {
389 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
390 scripts/config.py full
391 scripts/config.py unset MBEDTLS_CTR_DRBG_C
392 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
393
394 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
395 make
396
397 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
398 make test
399
400 # In this configuration, the TLS test programs use HMAC_DRBG.
401 # The SSL tests are slow, so run a small subset, just enough to get
402 # confidence that the SSL code copes with HMAC_DRBG.
403 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
404 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
405
406 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
407 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
408}
409
410component_test_no_hmac_drbg_classic () {
411 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
412 scripts/config.py full
413 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
414 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
415 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
416 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
417
418 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
419 make
420
421 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
422 make test
423
424 # Normally our ECDSA implementation uses deterministic ECDSA. But since
425 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
426 # instead.
427 # Test SSL with non-deterministic ECDSA. Only test features that
428 # might be affected by how ECDSA signature is performed.
429 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
430 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
431
432 # To save time, only test one protocol version, since this part of
433 # the protocol is identical in (D)TLS up to 1.2.
434 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
435 tests/compat.sh -m tls12 -t 'ECDSA'
436}
437
438component_test_no_hmac_drbg_use_psa () {
439 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
440 scripts/config.py full
441 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
442 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
443 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
444
445 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
446 make
447
448 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
449 make test
450
451 # Normally our ECDSA implementation uses deterministic ECDSA. But since
452 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
453 # instead.
454 # Test SSL with non-deterministic ECDSA. Only test features that
455 # might be affected by how ECDSA signature is performed.
456 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
457 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
458
459 # To save time, only test one protocol version, since this part of
460 # the protocol is identical in (D)TLS up to 1.2.
461 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
462 tests/compat.sh -m tls12 -t 'ECDSA'
463}
464
465component_test_psa_external_rng_no_drbg_classic () {
466 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
467 scripts/config.py full
468 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
469 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
470 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
471 scripts/config.py unset MBEDTLS_ENTROPY_C
472 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
473 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
474 scripts/config.py unset MBEDTLS_CTR_DRBG_C
475 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
476 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
477 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
478 # the SSL test programs don't have an RNG and can't work. Explicitly
479 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
480 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
481
482 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
483 make test
484
485 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
486 tests/ssl-opt.sh -f 'Default'
487}
488
489component_test_psa_external_rng_no_drbg_use_psa () {
490 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
491 scripts/config.py full
492 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
493 scripts/config.py unset MBEDTLS_ENTROPY_C
494 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
495 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
496 scripts/config.py unset MBEDTLS_CTR_DRBG_C
497 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
498 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
499 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
500
501 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
502 make test
503
504 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
505 tests/ssl-opt.sh -f 'Default\|opaque'
506}
507
508component_test_psa_external_rng_use_psa_crypto () {
509 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
510 scripts/config.py full
511 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
512 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
513 scripts/config.py unset MBEDTLS_CTR_DRBG_C
514 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
515
516 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
517 make test
518
519 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
520 tests/ssl-opt.sh -f 'Default\|opaque'
521}
522
523component_test_psa_inject_entropy () {
524 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
525 scripts/config.py full
526 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
527 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
528 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
529 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
530 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
531 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
532 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
533
534 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
535 make test
536}
537
538component_test_sw_inet_pton () {
539 msg "build: default plus MBEDTLS_TEST_SW_INET_PTON"
540
541 # MBEDTLS_TEST_HOOKS required for x509_crt_parse_cn_inet_pton
542 scripts/config.py set MBEDTLS_TEST_HOOKS
543 make CFLAGS="-DMBEDTLS_TEST_SW_INET_PTON"
544
545 msg "test: default plus MBEDTLS_TEST_SW_INET_PTON"
546 make test
547}
548
549component_full_no_pkparse_pkwrite () {
550 msg "build: full without pkparse and pkwrite"
551
552 scripts/config.py crypto_full
553 scripts/config.py unset MBEDTLS_PK_PARSE_C
554 scripts/config.py unset MBEDTLS_PK_WRITE_C
555
556 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
557
558 # Ensure that PK_[PARSE|WRITE]_C were not re-enabled accidentally (additive config).
559 not grep mbedtls_pk_parse_key library/pkparse.o
560 not grep mbedtls_pk_write_key_der library/pkwrite.o
561
562 msg "test: full without pkparse and pkwrite"
563 make test
564}
565
566component_test_crypto_full_md_light_only () {
567 msg "build: crypto_full with only the light subset of MD"
568 scripts/config.py crypto_full
569 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
570 # Disable MD
571 scripts/config.py unset MBEDTLS_MD_C
572 # Disable direct dependencies of MD_C
573 scripts/config.py unset MBEDTLS_HKDF_C
574 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
575 scripts/config.py unset MBEDTLS_PKCS7_C
576 # Disable indirect dependencies of MD_C
577 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG
578 # Disable things that would auto-enable MD_C
579 scripts/config.py unset MBEDTLS_PKCS5_C
580
581 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
582 # which we haven't disabled, so no need to explicitly enable it.
583 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
584
585 # Make sure we don't have the HMAC functions, but the hashing functions
586 not grep mbedtls_md_hmac library/md.o
587 grep mbedtls_md library/md.o
588
589 msg "test: crypto_full with only the light subset of MD"
590 make test
591}
592
593component_test_full_no_cipher_no_psa_crypto () {
594 msg "build: full no CIPHER no PSA_CRYPTO_C"
595 scripts/config.py full
596 scripts/config.py unset MBEDTLS_CIPHER_C
597 # Don't pull in cipher via PSA mechanisms
598 # (currently ignored anyway because we completely disable PSA)
599 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
600 # Disable features that depend on CIPHER_C
601 scripts/config.py unset MBEDTLS_CMAC_C
602 scripts/config.py unset MBEDTLS_NIST_KW_C
603 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
604 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CLIENT
605 scripts/config.py unset MBEDTLS_SSL_TLS_C
606 scripts/config.py unset MBEDTLS_SSL_TICKET_C
607 # Disable features that depend on PSA_CRYPTO_C
608 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
609 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
610 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
611 scripts/config.py unset MBEDTLS_LMS_C
612 scripts/config.py unset MBEDTLS_LMS_PRIVATE
613
614 msg "test: full no CIPHER no PSA_CRYPTO_C"
615 make test
616}
617
618# This is a common configurator and test function that is used in:
619# - component_test_full_no_cipher_with_psa_crypto
620# - component_test_full_no_cipher_with_psa_crypto_config
621# It accepts 2 input parameters:
622# - $1: boolean value which basically reflects status of MBEDTLS_PSA_CRYPTO_CONFIG
623# - $2: a text string which describes the test component
624common_test_full_no_cipher_with_psa_crypto () {
625 USE_CRYPTO_CONFIG="$1"
626 COMPONENT_DESCRIPTION="$2"
627
628 msg "build: $COMPONENT_DESCRIPTION"
629
630 scripts/config.py full
631 scripts/config.py unset MBEDTLS_CIPHER_C
632
633 if [ "$USE_CRYPTO_CONFIG" -eq 1 ]; then
634 # The built-in implementation of the following algs/key-types depends
635 # on CIPHER_C so we disable them.
636 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
637 # so we keep them enabled.
638 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
639 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CMAC
640 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
641 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
642 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CFB
643 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CTR
644 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
645 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_OFB
646 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
647 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_STREAM_CIPHER
648 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
649 else
650 # Don't pull in cipher via PSA mechanisms
651 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
652 # Disable cipher modes/keys that make PSA depend on CIPHER_C.
653 # Keep CHACHA20 and CHACHAPOLY enabled since they do not depend on CIPHER_C.
654 scripts/config.py unset-all MBEDTLS_CIPHER_MODE
655 fi
656 # The following modules directly depends on CIPHER_C
657 scripts/config.py unset MBEDTLS_CMAC_C
658 scripts/config.py unset MBEDTLS_NIST_KW_C
659
660 make
661
662 # Ensure that CIPHER_C was not re-enabled
663 not grep mbedtls_cipher_init library/cipher.o
664
665 msg "test: $COMPONENT_DESCRIPTION"
666 make test
667}
668
669component_test_full_no_cipher_with_psa_crypto () {
670 common_test_full_no_cipher_with_psa_crypto 0 "full no CIPHER no CRYPTO_CONFIG"
671}
672
673component_test_full_no_cipher_with_psa_crypto_config () {
674 common_test_full_no_cipher_with_psa_crypto 1 "full no CIPHER"
675}
676
677component_test_full_no_ccm () {
678 msg "build: full no PSA_WANT_ALG_CCM"
679
680 # Full config enables:
681 # - USE_PSA_CRYPTO so that TLS code dispatches cipher/AEAD to PSA
682 # - CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
683 scripts/config.py full
684
685 # Disable PSA_WANT_ALG_CCM so that CCM is not supported in PSA. CCM_C is still
686 # enabled, but not used from TLS since USE_PSA is set.
687 # This is helpful to ensure that TLS tests below have proper dependencies.
688 #
689 # Note: also PSA_WANT_ALG_CCM_STAR_NO_TAG is enabled, but it does not cause
690 # PSA_WANT_ALG_CCM to be re-enabled.
691 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM
692
693 make
694
695 msg "test: full no PSA_WANT_ALG_CCM"
696 make test
697}
698
699component_test_full_no_ccm_star_no_tag () {
700 msg "build: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
701
702 # Full config enables CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
703 scripts/config.py full
704
705 # Disable CCM_STAR_NO_TAG, which is the target of this test, as well as all
706 # other components that enable MBEDTLS_PSA_BUILTIN_CIPHER internal symbol.
707 # This basically disables all unauthenticated ciphers on the PSA side, while
708 # keeping AEADs enabled.
709 #
710 # Note: PSA_WANT_ALG_CCM is enabled, but it does not cause
711 # PSA_WANT_ALG_CCM_STAR_NO_TAG to be re-enabled.
712 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
713 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_STREAM_CIPHER
714 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
715 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
716 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
717 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
718 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
719 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
720
721 make
722
723 # Ensure MBEDTLS_PSA_BUILTIN_CIPHER was not enabled
724 not grep mbedtls_psa_cipher library/psa_crypto_cipher.o
725
726 msg "test: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
727 make test
728}
729
730component_test_full_no_bignum () {
731 msg "build: full minus bignum"
732 scripts/config.py full
733 scripts/config.py unset MBEDTLS_BIGNUM_C
734 # Direct dependencies of bignum
735 scripts/config.py unset MBEDTLS_ECP_C
736 scripts/config.py unset MBEDTLS_RSA_C
737 scripts/config.py unset MBEDTLS_DHM_C
738 # Direct dependencies of ECP
739 scripts/config.py unset MBEDTLS_ECDH_C
740 scripts/config.py unset MBEDTLS_ECDSA_C
741 scripts/config.py unset MBEDTLS_ECJPAKE_C
742 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
743 # Disable what auto-enables ECP_LIGHT
744 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
745 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
746 # Indirect dependencies of ECP
747 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
748 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
749 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
750 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
751 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
752 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
753 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
754 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
755 # Direct dependencies of DHM
756 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
757 # Direct dependencies of RSA
758 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
759 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
760 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
761 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
762 # PK and its dependencies
763 scripts/config.py unset MBEDTLS_PK_C
764 scripts/config.py unset MBEDTLS_PK_PARSE_C
765 scripts/config.py unset MBEDTLS_PK_WRITE_C
766 scripts/config.py unset MBEDTLS_X509_USE_C
767 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
768 scripts/config.py unset MBEDTLS_X509_CRL_PARSE_C
769 scripts/config.py unset MBEDTLS_X509_CSR_PARSE_C
770 scripts/config.py unset MBEDTLS_X509_CREATE_C
771 scripts/config.py unset MBEDTLS_X509_CRT_WRITE_C
772 scripts/config.py unset MBEDTLS_X509_CSR_WRITE_C
773 scripts/config.py unset MBEDTLS_PKCS7_C
774 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
775 scripts/config.py unset MBEDTLS_SSL_ASYNC_PRIVATE
776 scripts/config.py unset MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
777
778 make
779
780 msg "test: full minus bignum"
781 make test
782}
783
784component_test_tls1_2_default_stream_cipher_only () {
785 msg "build: default with only stream cipher"
786
787 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
788 scripts/config.py unset MBEDTLS_GCM_C
789 scripts/config.py unset MBEDTLS_CCM_C
790 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
791 #Disable TLS 1.3 (as no AEAD)
792 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
793 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
794 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
795 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
796 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
797 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
798 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
799 # Modules that depend on AEAD
800 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
801 scripts/config.py unset MBEDTLS_SSL_TICKET_C
802
803 make
804
805 msg "test: default with only stream cipher"
806 make test
807
808 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
809}
810
811component_test_tls1_2_default_stream_cipher_only_use_psa () {
812 msg "build: default with only stream cipher use psa"
813
814 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
815 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
816 scripts/config.py unset MBEDTLS_GCM_C
817 scripts/config.py unset MBEDTLS_CCM_C
818 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
819 #Disable TLS 1.3 (as no AEAD)
820 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
821 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
822 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
823 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
824 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
825 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
826 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
827 # Modules that depend on AEAD
828 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
829 scripts/config.py unset MBEDTLS_SSL_TICKET_C
830
831 make
832
833 msg "test: default with only stream cipher use psa"
834 make test
835
836 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
837}
838
839component_test_tls1_2_default_cbc_legacy_cipher_only () {
840 msg "build: default with only CBC-legacy cipher"
841
842 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
843 scripts/config.py unset MBEDTLS_GCM_C
844 scripts/config.py unset MBEDTLS_CCM_C
845 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
846 #Disable TLS 1.3 (as no AEAD)
847 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
848 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
849 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
850 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
851 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
852 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
853 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
854 # Modules that depend on AEAD
855 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
856 scripts/config.py unset MBEDTLS_SSL_TICKET_C
857
858 make
859
860 msg "test: default with only CBC-legacy cipher"
861 make test
862
863 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
864 tests/ssl-opt.sh -f "TLS 1.2"
865}
866
867component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
868 msg "build: default with only CBC-legacy cipher use psa"
869
870 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
871 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
872 scripts/config.py unset MBEDTLS_GCM_C
873 scripts/config.py unset MBEDTLS_CCM_C
874 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
875 #Disable TLS 1.3 (as no AEAD)
876 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
877 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
878 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
879 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
880 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
881 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
882 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
883 # Modules that depend on AEAD
884 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
885 scripts/config.py unset MBEDTLS_SSL_TICKET_C
886
887 make
888
889 msg "test: default with only CBC-legacy cipher use psa"
890 make test
891
892 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
893 tests/ssl-opt.sh -f "TLS 1.2"
894}
895
896component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
897 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
898
899 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
900 scripts/config.py unset MBEDTLS_GCM_C
901 scripts/config.py unset MBEDTLS_CCM_C
902 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
903 #Disable TLS 1.3 (as no AEAD)
904 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
905 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
906 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
907 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
908 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
909 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
910 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
911 # Modules that depend on AEAD
912 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
913 scripts/config.py unset MBEDTLS_SSL_TICKET_C
914
915 make
916
917 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
918 make test
919
920 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
921 tests/ssl-opt.sh -f "TLS 1.2"
922}
923
924component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
925 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
926
927 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
928 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
929 scripts/config.py unset MBEDTLS_GCM_C
930 scripts/config.py unset MBEDTLS_CCM_C
931 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
932 #Disable TLS 1.3 (as no AEAD)
933 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
934 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
935 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
936 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
937 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
938 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
939 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
940 # Modules that depend on AEAD
941 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
942 scripts/config.py unset MBEDTLS_SSL_TICKET_C
943
944 make
945
946 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
947 make test
948
949 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
950 tests/ssl-opt.sh -f "TLS 1.2"
951}
952
953# We're not aware of any other (open source) implementation of EC J-PAKE in TLS
954# that we could use for interop testing. However, we now have sort of two
955# implementations ourselves: one using PSA, the other not. At least test that
956# these two interoperate with each other.
957component_test_tls1_2_ecjpake_compatibility () {
958 msg "build: TLS1.2 server+client w/ EC-JPAKE w/o USE_PSA"
959 scripts/config.py set MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
960 # Explicitly make lib first to avoid a race condition:
961 # https://github.com/Mbed-TLS/mbedtls/issues/8229
962 make lib
963 make -C programs ssl/ssl_server2 ssl/ssl_client2
964 cp programs/ssl/ssl_server2 s2_no_use_psa
965 cp programs/ssl/ssl_client2 c2_no_use_psa
966
967 msg "build: TLS1.2 server+client w/ EC-JPAKE w/ USE_PSA"
968 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
969 make clean
970 make lib
971 make -C programs ssl/ssl_server2 ssl/ssl_client2
972 make -C programs test/udp_proxy test/query_compile_time_config
973
974 msg "test: server w/o USE_PSA - client w/ USE_PSA, text password"
975 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
976 msg "test: server w/o USE_PSA - client w/ USE_PSA, opaque password"
977 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password client only, working, TLS"
978 msg "test: client w/o USE_PSA - server w/ USE_PSA, text password"
979 P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
980 msg "test: client w/o USE_PSA - server w/ USE_PSA, opaque password"
981 P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password server only, working, TLS"
982
983 rm s2_no_use_psa c2_no_use_psa
984}
985
986component_test_everest () {
987 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
988 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
989 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
990 make
991
992 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
993 make test
994
995 msg "test: metatests (clang, ASan)"
996 tests/scripts/run-metatests.sh any asan poison
997
998 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
999 tests/ssl-opt.sh -f ECDH
1000
1001 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1002 # Exclude some symmetric ciphers that are redundant here to gain time.
1003 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
1004}
1005
1006component_test_everest_curve25519_only () {
1007 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
1008 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1009 scripts/config.py unset MBEDTLS_ECDSA_C
1010 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1011 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1012 scripts/config.py unset MBEDTLS_ECJPAKE_C
1013 # Disable all curves
1014 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
1015 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1016
1017 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1018
1019 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1020 make test
1021}
1022
1023component_test_small_ssl_out_content_len () {
1024 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
1025 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1026 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1027 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1028 make
1029
1030 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
1031 tests/ssl-opt.sh -f "Max fragment\|Large packet"
1032}
1033
1034component_test_small_ssl_in_content_len () {
1035 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
1036 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1037 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
1038 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1039 make
1040
1041 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
1042 tests/ssl-opt.sh -f "Max fragment"
1043}
1044
1045component_test_small_ssl_dtls_max_buffering () {
1046 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
1047 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
1048 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1049 make
1050
1051 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
1052 tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
1053}
1054
1055component_test_small_mbedtls_ssl_dtls_max_buffering () {
1056 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
1057 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
1058 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1059 make
1060
1061 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
1062 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
1063}
1064
1065component_test_psa_collect_statuses () {
1066 msg "build+test: psa_collect_statuses" # ~30s
1067 scripts/config.py full
1068 tests/scripts/psa_collect_statuses.py
1069 # Check that psa_crypto_init() succeeded at least once
1070 grep -q '^0:psa_crypto_init:' tests/statuses.log
1071 rm -f tests/statuses.log
1072}
1073
1074component_test_full_cmake_clang () {
1075 msg "build: cmake, full config, clang" # ~ 50s
1076 scripts/config.py full
1077 CC=clang CXX=clang cmake -D CMAKE_BUILD_TYPE:String=Release -D ENABLE_TESTING=On -D TEST_CPP=1 .
1078 make
1079
1080 msg "test: main suites (full config, clang)" # ~ 5s
1081 make test
1082
1083 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
1084 programs/test/cpp_dummy_build
1085
1086 msg "test: metatests (clang)"
1087 tests/scripts/run-metatests.sh any pthread
1088
1089 msg "program demos (full config, clang)" # ~10s
1090 tests/scripts/run_demos.py
1091
1092 msg "test: psa_constant_names (full config, clang)" # ~ 1s
1093 tests/scripts/test_psa_constant_names.py
1094
1095 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
1096 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
1097}
1098
1099skip_suites_without_constant_flow () {
1100 # Skip the test suites that don't have any constant-flow annotations.
1101 # This will need to be adjusted if we ever start declaring things as
1102 # secret from macros or functions inside tests/include or tests/src.
1103 SKIP_TEST_SUITES=$(
1104 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
1105 sed 's/test_suite_//; s/\.function$//' |
1106 tr '\n' ,)
1107 export SKIP_TEST_SUITES
1108}
1109
1110skip_all_except_given_suite () {
1111 # Skip all but the given test suite
1112 SKIP_TEST_SUITES=$(
1113 ls -1 tests/suites/test_suite_*.function |
1114 grep -v $1.function |
1115 sed 's/tests.suites.test_suite_//; s/\.function$//' |
1116 tr '\n' ,)
1117 export SKIP_TEST_SUITES
1118}
1119
1120component_test_memsan_constant_flow () {
1121 # This tests both (1) accesses to undefined memory, and (2) branches or
1122 # memory access depending on secret values. To distinguish between those:
1123 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1124 # - or alternatively, change the build type to MemSanDbg, which enables
1125 # origin tracking and nicer stack traces (which are useful for debugging
1126 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1127 msg "build: cmake MSan (clang), full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
1128 scripts/config.py full
1129 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1130 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1131 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1132 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1133 make
1134
1135 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO, Msan + constant flow)"
1136 make test
1137}
1138
1139component_test_memsan_constant_flow_psa () {
1140 # This tests both (1) accesses to undefined memory, and (2) branches or
1141 # memory access depending on secret values. To distinguish between those:
1142 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1143 # - or alternatively, change the build type to MemSanDbg, which enables
1144 # origin tracking and nicer stack traces (which are useful for debugging
1145 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1146 msg "build: cmake MSan (clang), full config with constant flow testing"
1147 scripts/config.py full
1148 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1149 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1150 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1151 make
1152
1153 msg "test: main suites (Msan + constant flow)"
1154 make test
1155}
1156
1157component_release_test_valgrind_constant_flow () {
1158 # This tests both (1) everything that valgrind's memcheck usually checks
1159 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1160 # etc.) and (2) branches or memory access depending on secret values,
1161 # which will be reported as uninitialized memory. To distinguish between
1162 # secret and actually uninitialized:
1163 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1164 # - or alternatively, build with debug info and manually run the offending
1165 # test suite with valgrind --track-origins=yes, then check if the origin
1166 # was TEST_CF_SECRET() or something else.
1167 msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
1168 scripts/config.py full
1169 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
1170 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1171 skip_suites_without_constant_flow
1172 cmake -D CMAKE_BUILD_TYPE:String=Release .
1173 make
1174
1175 # this only shows a summary of the results (how many of each type)
1176 # details are left in Testing/<date>/DynamicAnalysis.xml
1177 msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, valgrind + constant flow)"
1178 make memcheck
1179
1180 # Test asm path in constant time module - by default, it will test the plain C
1181 # path under Valgrind or Memsan. Running only the constant_time tests is fast (<1s)
1182 msg "test: valgrind asm constant_time"
1183 scripts/config.py --force set MBEDTLS_TEST_CONSTANT_FLOW_ASM
1184 skip_all_except_given_suite test_suite_constant_time
1185 cmake -D CMAKE_BUILD_TYPE:String=Release .
1186 make clean
1187 make
1188 make memcheck
1189}
1190
1191component_release_test_valgrind_constant_flow_psa () {
1192 # This tests both (1) everything that valgrind's memcheck usually checks
1193 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1194 # etc.) and (2) branches or memory access depending on secret values,
1195 # which will be reported as uninitialized memory. To distinguish between
1196 # secret and actually uninitialized:
1197 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1198 # - or alternatively, build with debug info and manually run the offending
1199 # test suite with valgrind --track-origins=yes, then check if the origin
1200 # was TEST_CF_SECRET() or something else.
1201 msg "build: cmake release GCC, full config with constant flow testing"
1202 scripts/config.py full
1203 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
1204 skip_suites_without_constant_flow
1205 cmake -D CMAKE_BUILD_TYPE:String=Release .
1206 make
1207
1208 # this only shows a summary of the results (how many of each type)
1209 # details are left in Testing/<date>/DynamicAnalysis.xml
1210 msg "test: some suites (valgrind + constant flow)"
1211 make memcheck
1212}
1213
1214component_test_tsan () {
1215 msg "build: TSan (clang)"
1216 scripts/config.py full
1217 scripts/config.py set MBEDTLS_THREADING_C
1218 scripts/config.py set MBEDTLS_THREADING_PTHREAD
1219 # Self-tests do not currently use multiple threads.
1220 scripts/config.py unset MBEDTLS_SELF_TEST
1221
1222 # The deprecated MBEDTLS_PSA_CRYPTO_SE_C interface is not thread safe.
1223 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
1224
1225 CC=clang cmake -D CMAKE_BUILD_TYPE:String=TSan .
1226 make
1227
1228 msg "test: main suites (TSan)"
1229 make test
1230}
1231
1232component_test_default_no_deprecated () {
1233 # Test that removing the deprecated features from the default
1234 # configuration leaves something consistent.
1235 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1236 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1237 make CFLAGS='-O -Werror -Wall -Wextra'
1238
1239 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1240 make test
1241}
1242
1243component_test_full_no_deprecated () {
1244 msg "build: make, full_no_deprecated config" # ~ 30s
1245 scripts/config.py full_no_deprecated
1246 make CFLAGS='-O -Werror -Wall -Wextra'
1247
1248 msg "test: make, full_no_deprecated config" # ~ 5s
1249 make test
1250
1251 msg "test: ensure that X509 has no direct dependency on BIGNUM_C"
1252 not grep mbedtls_mpi library/libmbedx509.a
1253}
1254
1255component_test_full_no_deprecated_deprecated_warning () {
1256 # Test that there is nothing deprecated in "full_no_deprecated".
1257 # A deprecated feature would trigger a warning (made fatal) from
1258 # MBEDTLS_DEPRECATED_WARNING.
1259 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1260 scripts/config.py full_no_deprecated
1261 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
1262 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
1263 make CFLAGS='-O -Werror -Wall -Wextra'
1264
1265 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
1266 make test
1267}
1268
1269component_test_full_deprecated_warning () {
1270 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
1271 # with only certain whitelisted types of warnings.
1272 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1273 scripts/config.py full
1274 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
1275 # Expect warnings from '#warning' directives in check_config.h.
1276 # Note that gcc is required to allow the use of -Wno-error=cpp, which allows us to
1277 # display #warning messages without them being treated as errors.
1278 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
1279
1280 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1281 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
1282 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
1283 # Expect warnings from '#warning' directives in check_config.h and
1284 # from the use of deprecated functions in test suites.
1285 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -Wno-error=cpp -DMBEDTLS_TEST_DEPRECATED' tests
1286
1287 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
1288 make test
1289
1290 msg "program demos: full config + MBEDTLS_TEST_DEPRECATED" # ~10s
1291 tests/scripts/run_demos.py
1292}
1293
1294# Check that the specified libraries exist and are empty.
1295are_empty_libraries () {
1296 nm "$@" >/dev/null 2>/dev/null
1297 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
1298}
1299
1300component_build_crypto_default () {
1301 msg "build: make, crypto only"
1302 scripts/config.py crypto
1303 make CFLAGS='-O1 -Werror'
1304 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1305}
1306
1307component_build_crypto_full () {
1308 msg "build: make, crypto only, full config"
1309 scripts/config.py crypto_full
1310 make CFLAGS='-O1 -Werror'
1311 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1312}
1313
1314component_test_crypto_for_psa_service () {
1315 msg "build: make, config for PSA crypto service"
1316 scripts/config.py crypto
1317 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1318 # Disable things that are not needed for just cryptography, to
1319 # reach a configuration that would be typical for a PSA cryptography
1320 # service providing all implemented PSA algorithms.
1321 # System stuff
1322 scripts/config.py unset MBEDTLS_ERROR_C
1323 scripts/config.py unset MBEDTLS_TIMING_C
1324 scripts/config.py unset MBEDTLS_VERSION_FEATURES
1325 # Crypto stuff with no PSA interface
1326 scripts/config.py unset MBEDTLS_BASE64_C
1327 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
1328 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
1329 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
1330 scripts/config.py unset MBEDTLS_NIST_KW_C
1331 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1332 scripts/config.py unset MBEDTLS_PEM_WRITE_C
1333 scripts/config.py unset MBEDTLS_PKCS12_C
1334 scripts/config.py unset MBEDTLS_PKCS5_C
1335 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
1336 # in PSA code to work with RSA keys. We don't require users to set those:
1337 # they will be reenabled in build_info.h.
1338 scripts/config.py unset MBEDTLS_PK_C
1339 scripts/config.py unset MBEDTLS_PK_PARSE_C
1340 scripts/config.py unset MBEDTLS_PK_WRITE_C
1341 make CFLAGS='-O1 -Werror' all test
1342 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1343}
1344
1345component_build_crypto_baremetal () {
1346 msg "build: make, crypto only, baremetal config"
1347 scripts/config.py crypto_baremetal
1348 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
1349 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1350}
1351support_build_crypto_baremetal () {
1352 support_build_baremetal "$@"
1353}
1354
1355component_build_baremetal () {
1356 msg "build: make, baremetal config"
1357 scripts/config.py baremetal
1358 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
1359}
1360support_build_baremetal () {
1361 # Older Glibc versions include time.h from other headers such as stdlib.h,
1362 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
1363 # problem, Ubuntu 18.04 is ok.
1364 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
1365}
1366
1367# depends.py family of tests
1368component_test_depends_py_cipher_id () {
1369 msg "test/build: depends.py cipher_id (gcc)"
1370 tests/scripts/depends.py cipher_id --unset-use-psa
1371}
1372
1373component_test_depends_py_cipher_chaining () {
1374 msg "test/build: depends.py cipher_chaining (gcc)"
1375 tests/scripts/depends.py cipher_chaining --unset-use-psa
1376}
1377
1378component_test_depends_py_cipher_padding () {
1379 msg "test/build: depends.py cipher_padding (gcc)"
1380 tests/scripts/depends.py cipher_padding --unset-use-psa
1381}
1382
1383component_test_depends_py_curves () {
1384 msg "test/build: depends.py curves (gcc)"
1385 tests/scripts/depends.py curves --unset-use-psa
1386}
1387
1388component_test_depends_py_hashes () {
1389 msg "test/build: depends.py hashes (gcc)"
1390 tests/scripts/depends.py hashes --unset-use-psa
1391}
1392
1393component_test_depends_py_kex () {
1394 msg "test/build: depends.py kex (gcc)"
1395 tests/scripts/depends.py kex --unset-use-psa
1396}
1397
1398component_test_depends_py_pkalgs () {
1399 msg "test/build: depends.py pkalgs (gcc)"
1400 tests/scripts/depends.py pkalgs --unset-use-psa
1401}
1402
1403# PSA equivalents of the depends.py tests
1404component_test_depends_py_cipher_id_psa () {
1405 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1406 tests/scripts/depends.py cipher_id
1407}
1408
1409component_test_depends_py_cipher_chaining_psa () {
1410 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1411 tests/scripts/depends.py cipher_chaining
1412}
1413
1414component_test_depends_py_cipher_padding_psa () {
1415 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1416 tests/scripts/depends.py cipher_padding
1417}
1418
1419component_test_depends_py_curves_psa () {
1420 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1421 tests/scripts/depends.py curves
1422}
1423
1424component_test_depends_py_hashes_psa () {
1425 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1426 tests/scripts/depends.py hashes
1427}
1428
1429component_test_depends_py_kex_psa () {
1430 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1431 tests/scripts/depends.py kex
1432}
1433
1434component_test_depends_py_pkalgs_psa () {
1435 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1436 tests/scripts/depends.py pkalgs
1437}
1438
1439component_test_psa_crypto_config_ffdh_2048_only () {
1440 msg "build: full config - only DH 2048"
1441
1442 scripts/config.py full
1443
1444 # Disable all DH groups other than 2048.
1445 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_3072
1446 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_4096
1447 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_6144
1448 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_8192
1449
1450 make CFLAGS="$ASAN_CFLAGS -Werror" LDFLAGS="$ASAN_CFLAGS"
1451
1452 msg "test: full config - only DH 2048"
1453 make test
1454
1455 msg "ssl-opt: full config - only DH 2048"
1456 tests/ssl-opt.sh -f "ffdh"
1457}
1458
1459component_build_no_pk_rsa_alt_support () {
1460 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
1461
1462 scripts/config.py full
1463 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
1464 scripts/config.py set MBEDTLS_RSA_C
1465 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
1466
1467 # Only compile - this is primarily to test for compile issues
1468 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
1469}
1470
1471component_build_module_alt () {
1472 msg "build: MBEDTLS_XXX_ALT" # ~30s
1473 scripts/config.py full
1474
1475 # Disable options that are incompatible with some ALT implementations:
1476 # aesni.c and padlock.c reference mbedtls_aes_context fields directly.
1477 scripts/config.py unset MBEDTLS_AESNI_C
1478 scripts/config.py unset MBEDTLS_PADLOCK_C
1479 scripts/config.py unset MBEDTLS_AESCE_C
1480 # MBEDTLS_ECP_RESTARTABLE is documented as incompatible.
1481 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1482 # You can only have one threading implementation: alt or pthread, not both.
1483 scripts/config.py unset MBEDTLS_THREADING_PTHREAD
1484 # The SpecifiedECDomain parsing code accesses mbedtls_ecp_group fields
1485 # directly and assumes the implementation works with partial groups.
1486 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1487 # MBEDTLS_SHA256_*ALT can't be used with MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*
1488 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
1489 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
1490 # MBEDTLS_SHA512_*ALT can't be used with MBEDTLS_SHA512_USE_A64_CRYPTO_*
1491 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
1492 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
1493
1494 # Enable all MBEDTLS_XXX_ALT for whole modules. Do not enable
1495 # MBEDTLS_XXX_YYY_ALT which are for single functions.
1496 scripts/config.py set-all 'MBEDTLS_([A-Z0-9]*|NIST_KW)_ALT'
1497 scripts/config.py unset MBEDTLS_DHM_ALT #incompatible with MBEDTLS_DEBUG_C
1498
1499 # We can only compile, not link, since we don't have any implementations
1500 # suitable for testing with the dummy alt headers.
1501 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
1502}
1503
1504component_build_dhm_alt () {
1505 msg "build: MBEDTLS_DHM_ALT" # ~30s
1506 scripts/config.py full
1507 scripts/config.py set MBEDTLS_DHM_ALT
1508 # debug.c currently references mbedtls_dhm_context fields directly.
1509 scripts/config.py unset MBEDTLS_DEBUG_C
1510 # We can only compile, not link, since we don't have any implementations
1511 # suitable for testing with the dummy alt headers.
1512 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
1513}
1514
1515component_test_no_psa_crypto_full_cmake_asan () {
1516 # full minus MBEDTLS_PSA_CRYPTO_C: run the same set of tests as basic-build-test.sh
1517 msg "build: cmake, full config minus PSA crypto, ASan"
1518 scripts/config.py full
1519 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1520 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CLIENT
1521 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1522 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1523 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
1524 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
1525 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1526 scripts/config.py unset MBEDTLS_LMS_C
1527 scripts/config.py unset MBEDTLS_LMS_PRIVATE
1528 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1529 make
1530
1531 msg "test: main suites (full minus PSA crypto)"
1532 make test
1533
1534 # Note: ssl-opt.sh has some test cases that depend on
1535 # MBEDTLS_ECP_RESTARTABLE && !MBEDTLS_USE_PSA_CRYPTO
1536 # This is the only component where those tests are not skipped.
1537 msg "test: ssl-opt.sh (full minus PSA crypto)"
1538 tests/ssl-opt.sh
1539
1540 # Note: the next two invocations cover all compat.sh test cases.
1541 # We should use the same here and in basic-build-test.sh.
1542 msg "test: compat.sh: default version (full minus PSA crypto)"
1543 tests/compat.sh -e 'ARIA\|CHACHA'
1544
1545 msg "test: compat.sh: next: ARIA, Chacha (full minus PSA crypto)"
1546 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
1547}
1548
1549component_test_psa_crypto_config_accel_ecdsa () {
1550 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1551
1552 # Algorithms and key types to accelerate
1553 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1554 $(helper_get_psa_key_type_list "ECC") \
1555 $(helper_get_psa_curve_list)"
1556
1557 # Configure
1558 # ---------
1559
1560 # Start from default config (no USE_PSA) + TLS 1.3
1561 helper_libtestdriver1_adjust_config "default"
1562
1563 # Disable the module that's accelerated
1564 scripts/config.py unset MBEDTLS_ECDSA_C
1565
1566 # Disable things that depend on it
1567 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1568 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1569
1570 # Build
1571 # -----
1572
1573 # These hashes are needed for some ECDSA signature tests.
1574 loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1575 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1576
1577 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1578
1579 helper_libtestdriver1_make_main "$loc_accel_list"
1580
1581 # Make sure this was not re-enabled by accident (additive config)
1582 not grep mbedtls_ecdsa_ library/ecdsa.o
1583
1584 # Run the tests
1585 # -------------
1586
1587 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1588 make test
1589}
1590
1591component_test_psa_crypto_config_accel_ecdh () {
1592 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
1593
1594 # Algorithms and key types to accelerate
1595 loc_accel_list="ALG_ECDH \
1596 $(helper_get_psa_key_type_list "ECC") \
1597 $(helper_get_psa_curve_list)"
1598
1599 # Configure
1600 # ---------
1601
1602 # Start from default config (no USE_PSA)
1603 helper_libtestdriver1_adjust_config "default"
1604
1605 # Disable the module that's accelerated
1606 scripts/config.py unset MBEDTLS_ECDH_C
1607
1608 # Disable things that depend on it
1609 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1610 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1611 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1612 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1613 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1614
1615 # Build
1616 # -----
1617
1618 helper_libtestdriver1_make_drivers "$loc_accel_list"
1619
1620 helper_libtestdriver1_make_main "$loc_accel_list"
1621
1622 # Make sure this was not re-enabled by accident (additive config)
1623 not grep mbedtls_ecdh_ library/ecdh.o
1624
1625 # Run the tests
1626 # -------------
1627
1628 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
1629 make test
1630}
1631
1632component_test_psa_crypto_config_accel_ffdh () {
1633 msg "build: full with accelerated FFDH"
1634
1635 # Algorithms and key types to accelerate
1636 loc_accel_list="ALG_FFDH \
1637 $(helper_get_psa_key_type_list "DH") \
1638 $(helper_get_psa_dh_group_list)"
1639
1640 # Configure
1641 # ---------
1642
1643 # start with full (USE_PSA and TLS 1.3)
1644 helper_libtestdriver1_adjust_config "full"
1645
1646 # Disable the module that's accelerated
1647 scripts/config.py unset MBEDTLS_DHM_C
1648
1649 # Disable things that depend on it
1650 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1651 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1652
1653 # Build
1654 # -----
1655
1656 helper_libtestdriver1_make_drivers "$loc_accel_list"
1657
1658 helper_libtestdriver1_make_main "$loc_accel_list"
1659
1660 # Make sure this was not re-enabled by accident (additive config)
1661 not grep mbedtls_dhm_ library/dhm.o
1662
1663 # Run the tests
1664 # -------------
1665
1666 msg "test: full with accelerated FFDH"
1667 make test
1668
1669 msg "ssl-opt: full with accelerated FFDH alg"
1670 tests/ssl-opt.sh -f "ffdh"
1671}
1672
1673component_test_psa_crypto_config_reference_ffdh () {
1674 msg "build: full with non-accelerated FFDH"
1675
1676 # Start with full (USE_PSA and TLS 1.3)
1677 helper_libtestdriver1_adjust_config "full"
1678
1679 # Disable things that are not supported
1680 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1681 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1682 make
1683
1684 msg "test suites: full with non-accelerated FFDH alg"
1685 make test
1686
1687 msg "ssl-opt: full with non-accelerated FFDH alg"
1688 tests/ssl-opt.sh -f "ffdh"
1689}
1690
1691component_test_psa_crypto_config_accel_pake () {
1692 msg "build: full with accelerated PAKE"
1693
1694 loc_accel_list="ALG_JPAKE \
1695 $(helper_get_psa_key_type_list "ECC") \
1696 $(helper_get_psa_curve_list)"
1697
1698 # Configure
1699 # ---------
1700
1701 helper_libtestdriver1_adjust_config "full"
1702
1703 # Make built-in fallback not available
1704 scripts/config.py unset MBEDTLS_ECJPAKE_C
1705 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
1706
1707 # Build
1708 # -----
1709
1710 helper_libtestdriver1_make_drivers "$loc_accel_list"
1711
1712 helper_libtestdriver1_make_main "$loc_accel_list"
1713
1714 # Make sure this was not re-enabled by accident (additive config)
1715 not grep mbedtls_ecjpake_init library/ecjpake.o
1716
1717 # Run the tests
1718 # -------------
1719
1720 msg "test: full with accelerated PAKE"
1721 make test
1722}
1723
1724component_test_psa_crypto_config_accel_ecc_some_key_types () {
1725 msg "build: full with accelerated EC algs and some key types"
1726
1727 # Algorithms and key types to accelerate
1728 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
1729 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1730 ALG_ECDH \
1731 ALG_JPAKE \
1732 KEY_TYPE_ECC_PUBLIC_KEY \
1733 KEY_TYPE_ECC_KEY_PAIR_BASIC \
1734 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
1735 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
1736 $(helper_get_psa_curve_list)"
1737
1738 # Configure
1739 # ---------
1740
1741 # start with config full for maximum coverage (also enables USE_PSA)
1742 helper_libtestdriver1_adjust_config "full"
1743
1744 # Disable modules that are accelerated - some will be re-enabled
1745 scripts/config.py unset MBEDTLS_ECDSA_C
1746 scripts/config.py unset MBEDTLS_ECDH_C
1747 scripts/config.py unset MBEDTLS_ECJPAKE_C
1748 scripts/config.py unset MBEDTLS_ECP_C
1749
1750 # Disable all curves - those that aren't accelerated should be re-enabled
1751 helper_disable_builtin_curves
1752
1753 # Restartable feature is not yet supported by PSA. Once it will in
1754 # the future, the following line could be removed (see issues
1755 # 6061, 6332 and following ones)
1756 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1757
1758 # this is not supported by the driver API yet
1759 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1760
1761 # Build
1762 # -----
1763
1764 # These hashes are needed for some ECDSA signature tests.
1765 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1766 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1767 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1768
1769 helper_libtestdriver1_make_main "$loc_accel_list"
1770
1771 # ECP should be re-enabled but not the others
1772 not grep mbedtls_ecdh_ library/ecdh.o
1773 not grep mbedtls_ecdsa library/ecdsa.o
1774 not grep mbedtls_ecjpake library/ecjpake.o
1775 grep mbedtls_ecp library/ecp.o
1776
1777 # Run the tests
1778 # -------------
1779
1780 msg "test suites: full with accelerated EC algs and some key types"
1781 make test
1782}
1783
1784# Run tests with only (non-)Weierstrass accelerated
1785# Common code used in:
1786# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
1787# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
1788common_test_psa_crypto_config_accel_ecc_some_curves () {
1789 weierstrass=$1
1790 if [ $weierstrass -eq 1 ]; then
1791 desc="Weierstrass"
1792 else
1793 desc="non-Weierstrass"
1794 fi
1795
1796 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
1797
1798 # Note: Curves are handled in a special way by the libtestdriver machinery,
1799 # so we only want to include them in the accel list when building the main
1800 # libraries, hence the use of a separate variable.
1801 # Note: the following loop is a modified version of
1802 # helper_get_psa_curve_list that only keeps Weierstrass families.
1803 loc_weierstrass_list=""
1804 loc_non_weierstrass_list=""
1805 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
1806 case $item in
1807 ECC_BRAINPOOL*|ECC_SECP*)
1808 loc_weierstrass_list="$loc_weierstrass_list $item"
1809 ;;
1810 *)
1811 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
1812 ;;
1813 esac
1814 done
1815 if [ $weierstrass -eq 1 ]; then
1816 loc_curve_list=$loc_weierstrass_list
1817 else
1818 loc_curve_list=$loc_non_weierstrass_list
1819 fi
1820
1821 # Algorithms and key types to accelerate
1822 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1823 ALG_ECDH \
1824 ALG_JPAKE \
1825 $(helper_get_psa_key_type_list "ECC") \
1826 $loc_curve_list"
1827
1828 # Configure
1829 # ---------
1830
1831 # Start with config crypto_full and remove PK_C:
1832 # that's what's supported now, see docs/driver-only-builds.md.
1833 helper_libtestdriver1_adjust_config "crypto_full"
1834 scripts/config.py unset MBEDTLS_PK_C
1835 scripts/config.py unset MBEDTLS_PK_PARSE_C
1836 scripts/config.py unset MBEDTLS_PK_WRITE_C
1837
1838 # Disable modules that are accelerated - some will be re-enabled
1839 scripts/config.py unset MBEDTLS_ECDSA_C
1840 scripts/config.py unset MBEDTLS_ECDH_C
1841 scripts/config.py unset MBEDTLS_ECJPAKE_C
1842 scripts/config.py unset MBEDTLS_ECP_C
1843
1844 # Disable all curves - those that aren't accelerated should be re-enabled
1845 helper_disable_builtin_curves
1846
1847 # Restartable feature is not yet supported by PSA. Once it will in
1848 # the future, the following line could be removed (see issues
1849 # 6061, 6332 and following ones)
1850 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1851
1852 # this is not supported by the driver API yet
1853 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
1854
1855 # Build
1856 # -----
1857
1858 # These hashes are needed for some ECDSA signature tests.
1859 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1860 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1861 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1862
1863 helper_libtestdriver1_make_main "$loc_accel_list"
1864
1865 # We expect ECDH to be re-enabled for the missing curves
1866 grep mbedtls_ecdh_ library/ecdh.o
1867 # We expect ECP to be re-enabled, however the parts specific to the
1868 # families of curves that are accelerated should be ommited.
1869 # - functions with mxz in the name are specific to Montgomery curves
1870 # - ecp_muladd is specific to Weierstrass curves
1871 ##nm library/ecp.o | tee ecp.syms
1872 if [ $weierstrass -eq 1 ]; then
1873 not grep mbedtls_ecp_muladd library/ecp.o
1874 grep mxz library/ecp.o
1875 else
1876 grep mbedtls_ecp_muladd library/ecp.o
1877 not grep mxz library/ecp.o
1878 fi
1879 # We expect ECDSA and ECJPAKE to be re-enabled only when
1880 # Weierstrass curves are not accelerated
1881 if [ $weierstrass -eq 1 ]; then
1882 not grep mbedtls_ecdsa library/ecdsa.o
1883 not grep mbedtls_ecjpake library/ecjpake.o
1884 else
1885 grep mbedtls_ecdsa library/ecdsa.o
1886 grep mbedtls_ecjpake library/ecjpake.o
1887 fi
1888
1889 # Run the tests
1890 # -------------
1891
1892 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
1893 make test
1894}
1895
1896component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
1897 common_test_psa_crypto_config_accel_ecc_some_curves 1
1898}
1899
1900component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
1901 common_test_psa_crypto_config_accel_ecc_some_curves 0
1902}
1903
1904# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
1905# ECDH, ECDSA) with and without drivers.
1906# The input parameter is a boolean value which indicates:
1907# - 0 keep built-in EC algs,
1908# - 1 exclude built-in EC algs (driver only).
1909#
1910# This is used by the two following components to ensure they always use the
1911# same config, except for the use of driver or built-in EC algorithms:
1912# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
1913# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
1914# This supports comparing their test coverage with analyze_outcomes.py.
1915config_psa_crypto_config_ecp_light_only () {
1916 driver_only="$1"
1917 # start with config full for maximum coverage (also enables USE_PSA)
1918 helper_libtestdriver1_adjust_config "full"
1919 if [ "$driver_only" -eq 1 ]; then
1920 # Disable modules that are accelerated
1921 scripts/config.py unset MBEDTLS_ECDSA_C
1922 scripts/config.py unset MBEDTLS_ECDH_C
1923 scripts/config.py unset MBEDTLS_ECJPAKE_C
1924 scripts/config.py unset MBEDTLS_ECP_C
1925 fi
1926
1927 # Restartable feature is not yet supported by PSA. Once it will in
1928 # the future, the following line could be removed (see issues
1929 # 6061, 6332 and following ones)
1930 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1931}
1932
1933# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
1934component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
1935 msg "build: full with accelerated EC algs"
1936
1937 # Algorithms and key types to accelerate
1938 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
1939 ALG_ECDH \
1940 ALG_JPAKE \
1941 $(helper_get_psa_key_type_list "ECC") \
1942 $(helper_get_psa_curve_list)"
1943
1944 # Configure
1945 # ---------
1946
1947 # Use the same config as reference, only without built-in EC algs
1948 config_psa_crypto_config_ecp_light_only 1
1949
1950 # Do not disable builtin curves because that support is required for:
1951 # - MBEDTLS_PK_PARSE_EC_EXTENDED
1952 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
1953
1954 # Build
1955 # -----
1956
1957 # These hashes are needed for some ECDSA signature tests.
1958 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1959 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1960 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
1961
1962 helper_libtestdriver1_make_main "$loc_accel_list"
1963
1964 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
1965 not grep mbedtls_ecdsa_ library/ecdsa.o
1966 not grep mbedtls_ecdh_ library/ecdh.o
1967 not grep mbedtls_ecjpake_ library/ecjpake.o
1968 not grep mbedtls_ecp_mul library/ecp.o
1969
1970 # Run the tests
1971 # -------------
1972
1973 msg "test suites: full with accelerated EC algs"
1974 make test
1975
1976 msg "ssl-opt: full with accelerated EC algs"
1977 tests/ssl-opt.sh
1978}
1979
1980# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
1981component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
1982 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated EC algs"
1983
1984 config_psa_crypto_config_ecp_light_only 0
1985
1986 make
1987
1988 msg "test suites: full with non-accelerated EC algs"
1989 make test
1990
1991 msg "ssl-opt: full with non-accelerated EC algs"
1992 tests/ssl-opt.sh
1993}
1994
1995# This helper function is used by:
1996# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
1997# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
1998# to ensure that both tests use the same underlying configuration when testing
1999# driver's coverage with analyze_outcomes.py.
2000#
2001# This functions accepts 1 boolean parameter as follows:
2002# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
2003# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
2004# - 0: include built-in implementation of EC algorithms.
2005#
2006# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
2007# on the ECP module.
2008config_psa_crypto_no_ecp_at_all () {
2009 driver_only="$1"
2010 # start with full config for maximum coverage (also enables USE_PSA)
2011 helper_libtestdriver1_adjust_config "full"
2012
2013 if [ "$driver_only" -eq 1 ]; then
2014 # Disable modules that are accelerated
2015 scripts/config.py unset MBEDTLS_ECDSA_C
2016 scripts/config.py unset MBEDTLS_ECDH_C
2017 scripts/config.py unset MBEDTLS_ECJPAKE_C
2018 # Disable ECP module (entirely)
2019 scripts/config.py unset MBEDTLS_ECP_C
2020 fi
2021
2022 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
2023 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
2024 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
2025 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2026
2027 # Restartable feature is not yet supported by PSA. Once it will in
2028 # the future, the following line could be removed (see issues
2029 # 6061, 6332 and following ones)
2030 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2031}
2032
2033# Build and test a configuration where driver accelerates all EC algs while
2034# all support and dependencies from ECP and ECP_LIGHT are removed on the library
2035# side.
2036#
2037# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
2038component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
2039 msg "build: full + accelerated EC algs - ECP"
2040
2041 # Algorithms and key types to accelerate
2042 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2043 ALG_ECDH \
2044 ALG_JPAKE \
2045 $(helper_get_psa_key_type_list "ECC") \
2046 $(helper_get_psa_curve_list)"
2047
2048 # Configure
2049 # ---------
2050
2051 # Set common configurations between library's and driver's builds
2052 config_psa_crypto_no_ecp_at_all 1
2053 # Disable all the builtin curves. All the required algs are accelerated.
2054 helper_disable_builtin_curves
2055
2056 # Build
2057 # -----
2058
2059 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
2060 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
2061 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2062 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2063
2064 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2065
2066 helper_libtestdriver1_make_main "$loc_accel_list"
2067
2068 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
2069 not grep mbedtls_ecdsa_ library/ecdsa.o
2070 not grep mbedtls_ecdh_ library/ecdh.o
2071 not grep mbedtls_ecjpake_ library/ecjpake.o
2072 # Also ensure that ECP module was not re-enabled
2073 not grep mbedtls_ecp_ library/ecp.o
2074
2075 # Run the tests
2076 # -------------
2077
2078 msg "test: full + accelerated EC algs - ECP"
2079 make test
2080
2081 msg "ssl-opt: full + accelerated EC algs - ECP"
2082 tests/ssl-opt.sh
2083}
2084
2085# Reference function used for driver's coverage analysis in analyze_outcomes.py
2086# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
2087# Keep in sync with its accelerated counterpart.
2088component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
2089 msg "build: full + non accelerated EC algs"
2090
2091 config_psa_crypto_no_ecp_at_all 0
2092
2093 make
2094
2095 msg "test: full + non accelerated EC algs"
2096 make test
2097
2098 msg "ssl-opt: full + non accelerated EC algs"
2099 tests/ssl-opt.sh
2100}
2101
2102# This is a common configuration helper used directly from:
2103# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
2104# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
2105# and indirectly from:
2106# - component_test_psa_crypto_config_accel_ecc_no_bignum
2107# - accelerate all EC algs, disable RSA and FFDH
2108# - component_test_psa_crypto_config_reference_ecc_no_bignum
2109# - this is the reference component of the above
2110# - it still disables RSA and FFDH, but it uses builtin EC algs
2111# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
2112# - accelerate all EC and FFDH algs, disable only RSA
2113# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
2114# - this is the reference component of the above
2115# - it still disables RSA, but it uses builtin EC and FFDH algs
2116#
2117# This function accepts 2 parameters:
2118# $1: a boolean value which states if we are testing an accelerated scenario
2119# or not.
2120# $2: a string value which states which components are tested. Allowed values
2121# are "ECC" or "ECC_DH".
2122config_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
2123 driver_only="$1"
2124 test_target="$2"
2125 # start with full config for maximum coverage (also enables USE_PSA)
2126 helper_libtestdriver1_adjust_config "full"
2127
2128 if [ "$driver_only" -eq 1 ]; then
2129 # Disable modules that are accelerated
2130 scripts/config.py unset MBEDTLS_ECDSA_C
2131 scripts/config.py unset MBEDTLS_ECDH_C
2132 scripts/config.py unset MBEDTLS_ECJPAKE_C
2133 # Disable ECP module (entirely)
2134 scripts/config.py unset MBEDTLS_ECP_C
2135 # Also disable bignum
2136 scripts/config.py unset MBEDTLS_BIGNUM_C
2137 fi
2138
2139 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
2140 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
2141 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
2142 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2143
2144 # RSA support is intentionally disabled on this test because RSA_C depends
2145 # on BIGNUM_C.
2146 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
2147 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
2148 scripts/config.py unset MBEDTLS_RSA_C
2149 scripts/config.py unset MBEDTLS_PKCS1_V15
2150 scripts/config.py unset MBEDTLS_PKCS1_V21
2151 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2152 # Also disable key exchanges that depend on RSA
2153 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2154 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2155 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2156 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2157 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2158
2159 if [ "$test_target" = "ECC" ]; then
2160 # When testing ECC only, we disable FFDH support, both from builtin and
2161 # PSA sides, and also disable the key exchanges that depend on DHM.
2162 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_FFDH
2163 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
2164 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
2165 scripts/config.py unset MBEDTLS_DHM_C
2166 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2167 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2168 else
2169 # When testing ECC and DH instead, we disable DHM and depending key
2170 # exchanges only in the accelerated build
2171 if [ "$driver_only" -eq 1 ]; then
2172 scripts/config.py unset MBEDTLS_DHM_C
2173 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2174 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2175 fi
2176 fi
2177
2178 # Restartable feature is not yet supported by PSA. Once it will in
2179 # the future, the following line could be removed (see issues
2180 # 6061, 6332 and following ones)
2181 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2182}
2183
2184# Common helper used by:
2185# - component_test_psa_crypto_config_accel_ecc_no_bignum
2186# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
2187#
2188# The goal is to build and test accelerating either:
2189# - ECC only or
2190# - both ECC and FFDH
2191#
2192# It is meant to be used in conjunction with
2193# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
2194# coverage analysis in the "analyze_outcomes.py" script.
2195common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
2196 test_target="$1"
2197
2198 # This is an internal helper to simplify text message handling
2199 if [ "$test_target" = "ECC_DH" ]; then
2200 accel_text="ECC/FFDH"
2201 removed_text="ECP - DH"
2202 else
2203 accel_text="ECC"
2204 removed_text="ECP"
2205 fi
2206
2207 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
2208
2209 # By default we accelerate all EC keys/algs
2210 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2211 ALG_ECDH \
2212 ALG_JPAKE \
2213 $(helper_get_psa_key_type_list "ECC") \
2214 $(helper_get_psa_curve_list)"
2215 # Optionally we can also add DH to the list of accelerated items
2216 if [ "$test_target" = "ECC_DH" ]; then
2217 loc_accel_list="$loc_accel_list \
2218 ALG_FFDH \
2219 $(helper_get_psa_key_type_list "DH") \
2220 $(helper_get_psa_dh_group_list)"
2221 fi
2222
2223 # Configure
2224 # ---------
2225
2226 # Set common configurations between library's and driver's builds
2227 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
2228 # Disable all the builtin curves. All the required algs are accelerated.
2229 helper_disable_builtin_curves
2230
2231 # Build
2232 # -----
2233
2234 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
2235 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
2236 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2237 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2238
2239 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2240
2241 helper_libtestdriver1_make_main "$loc_accel_list"
2242
2243 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
2244 not grep mbedtls_ecdsa_ library/ecdsa.o
2245 not grep mbedtls_ecdh_ library/ecdh.o
2246 not grep mbedtls_ecjpake_ library/ecjpake.o
2247 # Also ensure that ECP, RSA, [DHM] or BIGNUM modules were not re-enabled
2248 not grep mbedtls_ecp_ library/ecp.o
2249 not grep mbedtls_rsa_ library/rsa.o
2250 not grep mbedtls_mpi_ library/bignum.o
2251 not grep mbedtls_dhm_ library/dhm.o
2252
2253 # Run the tests
2254 # -------------
2255
2256 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - DHM - BIGNUM"
2257
2258 make test
2259
2260 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
2261 tests/ssl-opt.sh
2262}
2263
2264# Common helper used by:
2265# - component_test_psa_crypto_config_reference_ecc_no_bignum
2266# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
2267#
2268# The goal is to build and test a reference scenario (i.e. with builtin
2269# components) compared to the ones used in
2270# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
2271#
2272# It is meant to be used in conjunction with
2273# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
2274# coverage analysis in "analyze_outcomes.py" script.
2275common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
2276 test_target="$1"
2277
2278 # This is an internal helper to simplify text message handling
2279 if [ "$test_target" = "ECC_DH" ]; then
2280 accel_text="ECC/FFDH"
2281 else
2282 accel_text="ECC"
2283 fi
2284
2285 msg "build: full + non accelerated $accel_text algs + USE_PSA"
2286
2287 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
2288
2289 make
2290
2291 msg "test suites: full + non accelerated EC algs + USE_PSA"
2292 make test
2293
2294 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
2295 tests/ssl-opt.sh
2296}
2297
2298component_test_psa_crypto_config_accel_ecc_no_bignum () {
2299 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
2300}
2301
2302component_test_psa_crypto_config_reference_ecc_no_bignum () {
2303 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
2304}
2305
2306component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
2307 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
2308}
2309
2310component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
2311 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
2312}
2313
2314# Helper for setting common configurations between:
2315# - component_test_tfm_config_p256m_driver_accel_ec()
2316# - component_test_tfm_config()
2317common_tfm_config () {
2318 # Enable TF-M config
2319 cp configs/config-tfm.h "$CONFIG_H"
2320 echo "#undef MBEDTLS_PSA_CRYPTO_CONFIG_FILE" >> "$CONFIG_H"
2321 cp configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
2322
2323 # Other config adjustment to make the tests pass.
2324 # This should probably be adopted upstream.
2325 #
2326 # - USE_PSA_CRYPTO for PK_HAVE_ECC_KEYS
2327 echo "#define MBEDTLS_USE_PSA_CRYPTO" >> "$CONFIG_H"
2328
2329 # Config adjustment for better test coverage in our environment.
2330 # This is not needed just to build and pass tests.
2331 #
2332 # Enable filesystem I/O for the benefit of PK parse/write tests.
2333 echo "#define MBEDTLS_FS_IO" >> "$CONFIG_H"
2334}
2335
2336# Keep this in sync with component_test_tfm_config() as they are both meant
2337# to be used in analyze_outcomes.py for driver's coverage analysis.
2338component_test_tfm_config_p256m_driver_accel_ec () {
2339 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
2340
2341 common_tfm_config
2342
2343 # Build crypto library
2344 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
2345
2346 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
2347 not grep mbedtls_ecdsa_ library/ecdsa.o
2348 not grep mbedtls_ecdh_ library/ecdh.o
2349 not grep mbedtls_ecjpake_ library/ecjpake.o
2350 # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
2351 not grep mbedtls_ecp_ library/ecp.o
2352 not grep mbedtls_rsa_ library/rsa.o
2353 not grep mbedtls_dhm_ library/dhm.o
2354 not grep mbedtls_mpi_ library/bignum.o
2355 # Check that p256m was built
2356 grep -q p256_ecdsa_ library/libmbedcrypto.a
2357
2358 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
2359 # files, so we want to ensure that it has not be re-enabled accidentally.
2360 not grep mbedtls_cipher library/cipher.o
2361
2362 # Run the tests
2363 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
2364 make test
2365}
2366
2367# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
2368# they are both meant to be used in analyze_outcomes.py for driver's coverage
2369# analysis.
2370component_test_tfm_config () {
2371 common_tfm_config
2372
2373 # Disable P256M driver, which is on by default, so that analyze_outcomes
2374 # can compare this test with test_tfm_config_p256m_driver_accel_ec
2375 echo "#undef MBEDTLS_PSA_P256M_DRIVER_ENABLED" >> "$CONFIG_H"
2376
2377 msg "build: TF-M config"
2378 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' tests
2379
2380 # Check that p256m was not built
2381 not grep p256_ecdsa_ library/libmbedcrypto.a
2382
2383 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
2384 # files, so we want to ensure that it has not be re-enabled accidentally.
2385 not grep mbedtls_cipher library/cipher.o
2386
2387 msg "test: TF-M config"
2388 make test
2389}
2390
2391# Common helper for component_full_without_ecdhe_ecdsa() and
2392# component_full_without_ecdhe_ecdsa_and_tls13() which:
2393# - starts from the "full" configuration minus the list of symbols passed in
2394# as 1st parameter
2395# - build
2396# - test only TLS (i.e. test_suite_tls and ssl-opt)
2397build_full_minus_something_and_test_tls () {
2398 symbols_to_disable="$1"
2399
2400 msg "build: full minus something, test TLS"
2401
2402 scripts/config.py full
2403 for sym in $symbols_to_disable; do
2404 echo "Disabling $sym"
2405 scripts/config.py unset $sym
2406 done
2407
2408 make
2409
2410 msg "test: full minus something, test TLS"
2411 ( cd tests; ./test_suite_ssl )
2412
2413 msg "ssl-opt: full minus something, test TLS"
2414 tests/ssl-opt.sh
2415}
2416
2417component_full_without_ecdhe_ecdsa () {
2418 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED"
2419}
2420
2421component_full_without_ecdhe_ecdsa_and_tls13 () {
2422 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2423 MBEDTLS_SSL_PROTO_TLS1_3"
2424}
2425
2426# This is an helper used by:
2427# - component_test_psa_ecc_key_pair_no_derive
2428# - component_test_psa_ecc_key_pair_no_generate
2429# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
2430# enabled, but one. Input arguments are as follows:
2431# - $1 is the key type under test, i.e. ECC/RSA/DH
2432# - $2 is the key option to be unset (i.e. generate, derive, etc)
2433build_and_test_psa_want_key_pair_partial () {
2434 key_type=$1
2435 unset_option=$2
2436 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
2437
2438 msg "build: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
2439 scripts/config.py full
2440 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2441 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2442
2443 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
2444 # crypto_config.h so we just disable the one we don't want.
2445 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
2446
2447 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2448
2449 msg "test: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
2450 make test
2451}
2452
2453component_test_psa_ecc_key_pair_no_derive () {
2454 build_and_test_psa_want_key_pair_partial "ECC" "DERIVE"
2455}
2456
2457component_test_psa_ecc_key_pair_no_generate () {
2458 build_and_test_psa_want_key_pair_partial "ECC" "GENERATE"
2459}
2460
2461config_psa_crypto_accel_rsa () {
2462 driver_only=$1
2463
2464 # Start from crypto_full config (no X.509, no TLS)
2465 helper_libtestdriver1_adjust_config "crypto_full"
2466
2467 if [ "$driver_only" -eq 1 ]; then
2468 # Remove RSA support and its dependencies
2469 scripts/config.py unset MBEDTLS_RSA_C
2470 scripts/config.py unset MBEDTLS_PKCS1_V15
2471 scripts/config.py unset MBEDTLS_PKCS1_V21
2472
2473 # We need PEM parsing in the test library as well to support the import
2474 # of PEM encoded RSA keys.
2475 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
2476 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
2477 fi
2478}
2479
2480component_test_psa_crypto_config_accel_rsa_crypto () {
2481 msg "build: crypto_full with accelerated RSA"
2482
2483 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
2484 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
2485 KEY_TYPE_RSA_PUBLIC_KEY \
2486 KEY_TYPE_RSA_KEY_PAIR_BASIC \
2487 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
2488 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
2489 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
2490
2491 # Configure
2492 # ---------
2493
2494 config_psa_crypto_accel_rsa 1
2495
2496 # Build
2497 # -----
2498
2499 # These hashes are needed for unit tests.
2500 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2501 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
2502 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2503
2504 helper_libtestdriver1_make_main "$loc_accel_list"
2505
2506 # Make sure this was not re-enabled by accident (additive config)
2507 not grep mbedtls_rsa library/rsa.o
2508
2509 # Run the tests
2510 # -------------
2511
2512 msg "test: crypto_full with accelerated RSA"
2513 make test
2514}
2515
2516component_test_psa_crypto_config_reference_rsa_crypto () {
2517 msg "build: crypto_full with non-accelerated RSA"
2518
2519 # Configure
2520 # ---------
2521 config_psa_crypto_accel_rsa 0
2522
2523 # Build
2524 # -----
2525 make
2526
2527 # Run the tests
2528 # -------------
2529 msg "test: crypto_full with non-accelerated RSA"
2530 make test
2531}
2532
2533# This is a temporary test to verify that full RSA support is present even when
2534# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
2535component_test_new_psa_want_key_pair_symbol () {
2536 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
2537
2538 # Create a temporary output file unless there is already one set
2539 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
2540 REMOVE_OUTCOME_ON_EXIT="no"
2541 else
2542 REMOVE_OUTCOME_ON_EXIT="yes"
2543 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
2544 export MBEDTLS_TEST_OUTCOME_FILE
2545 fi
2546
2547 # Start from crypto configuration
2548 scripts/config.py crypto
2549
2550 # Remove RSA support and its dependencies
2551 scripts/config.py unset MBEDTLS_PKCS1_V15
2552 scripts/config.py unset MBEDTLS_PKCS1_V21
2553 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2554 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2555 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2556 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2557 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2558 scripts/config.py unset MBEDTLS_RSA_C
2559 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2560
2561 # Enable PSA support
2562 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2563
2564 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
2565 # that proper translations is done in crypto_legacy.h.
2566 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
2567 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
2568 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
2569
2570 make
2571
2572 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
2573 make test
2574
2575 # Parse only 1 relevant line from the outcome file, i.e. a test which is
2576 # performing RSA signature.
2577 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
2578 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
2579
2580 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
2581 rm $MBEDTLS_TEST_OUTCOME_FILE
2582 fi
2583}
2584
2585component_test_psa_crypto_config_accel_hash () {
2586 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2587
2588 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
2589 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2590 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2591
2592 # Configure
2593 # ---------
2594
2595 # Start from default config (no USE_PSA)
2596 helper_libtestdriver1_adjust_config "default"
2597
2598 # Disable the things that are being accelerated
2599 scripts/config.py unset MBEDTLS_MD5_C
2600 scripts/config.py unset MBEDTLS_RIPEMD160_C
2601 scripts/config.py unset MBEDTLS_SHA1_C
2602 scripts/config.py unset MBEDTLS_SHA224_C
2603 scripts/config.py unset MBEDTLS_SHA256_C
2604 scripts/config.py unset MBEDTLS_SHA384_C
2605 scripts/config.py unset MBEDTLS_SHA512_C
2606 scripts/config.py unset MBEDTLS_SHA3_C
2607
2608 # Build
2609 # -----
2610
2611 helper_libtestdriver1_make_drivers "$loc_accel_list"
2612
2613 helper_libtestdriver1_make_main "$loc_accel_list"
2614
2615 # There's a risk of something getting re-enabled via config_psa.h;
2616 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
2617 not grep mbedtls_md5 library/md5.o
2618 not grep mbedtls_sha1 library/sha1.o
2619 not grep mbedtls_sha256 library/sha256.o
2620 not grep mbedtls_sha512 library/sha512.o
2621 not grep mbedtls_ripemd160 library/ripemd160.o
2622
2623 # Run the tests
2624 # -------------
2625
2626 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2627 make test
2628}
2629
2630component_test_psa_crypto_config_accel_hash_keep_builtins () {
2631 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
2632 # This component ensures that all the test cases for
2633 # md_psa_dynamic_dispatch with legacy+driver in test_suite_md are run.
2634
2635 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
2636 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2637 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2638
2639 # Start from default config (no USE_PSA)
2640 helper_libtestdriver1_adjust_config "default"
2641
2642 helper_libtestdriver1_make_drivers "$loc_accel_list"
2643
2644 helper_libtestdriver1_make_main "$loc_accel_list"
2645
2646 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
2647 make test
2648}
2649
2650# Auxiliary function to build config for hashes with and without drivers
2651config_psa_crypto_hash_use_psa () {
2652 driver_only="$1"
2653 # start with config full for maximum coverage (also enables USE_PSA)
2654 helper_libtestdriver1_adjust_config "full"
2655 if [ "$driver_only" -eq 1 ]; then
2656 # disable the built-in implementation of hashes
2657 scripts/config.py unset MBEDTLS_MD5_C
2658 scripts/config.py unset MBEDTLS_RIPEMD160_C
2659 scripts/config.py unset MBEDTLS_SHA1_C
2660 scripts/config.py unset MBEDTLS_SHA224_C
2661 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
2662 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2663 scripts/config.py unset MBEDTLS_SHA384_C
2664 scripts/config.py unset MBEDTLS_SHA512_C
2665 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2666 scripts/config.py unset MBEDTLS_SHA3_C
2667 fi
2668}
2669
2670# Note that component_test_psa_crypto_config_reference_hash_use_psa
2671# is related to this component and both components need to be kept in sync.
2672# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
2673component_test_psa_crypto_config_accel_hash_use_psa () {
2674 msg "test: full with accelerated hashes"
2675
2676 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
2677 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2678 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2679
2680 # Configure
2681 # ---------
2682
2683 config_psa_crypto_hash_use_psa 1
2684
2685 # Build
2686 # -----
2687
2688 helper_libtestdriver1_make_drivers "$loc_accel_list"
2689
2690 helper_libtestdriver1_make_main "$loc_accel_list"
2691
2692 # There's a risk of something getting re-enabled via config_psa.h;
2693 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
2694 not grep mbedtls_md5 library/md5.o
2695 not grep mbedtls_sha1 library/sha1.o
2696 not grep mbedtls_sha256 library/sha256.o
2697 not grep mbedtls_sha512 library/sha512.o
2698 not grep mbedtls_ripemd160 library/ripemd160.o
2699
2700 # Run the tests
2701 # -------------
2702
2703 msg "test: full with accelerated hashes"
2704 make test
2705
2706 # This is mostly useful so that we can later compare outcome files with
2707 # the reference config in analyze_outcomes.py, to check that the
2708 # dependency declarations in ssl-opt.sh and in TLS code are correct.
2709 msg "test: ssl-opt.sh, full with accelerated hashes"
2710 tests/ssl-opt.sh
2711
2712 # This is to make sure all ciphersuites are exercised, but we don't need
2713 # interop testing (besides, we already got some from ssl-opt.sh).
2714 msg "test: compat.sh, full with accelerated hashes"
2715 tests/compat.sh -p mbedTLS -V YES
2716}
2717
2718# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
2719# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
2720# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
2721# Both components need to be kept in sync.
2722component_test_psa_crypto_config_reference_hash_use_psa () {
2723 msg "test: full without accelerated hashes"
2724
2725 config_psa_crypto_hash_use_psa 0
2726
2727 make
2728
2729 msg "test: full without accelerated hashes"
2730 make test
2731
2732 msg "test: ssl-opt.sh, full without accelerated hashes"
2733 tests/ssl-opt.sh
2734}
2735
2736# Auxiliary function to build config for hashes with and without drivers
2737config_psa_crypto_hmac_use_psa () {
2738 driver_only="$1"
2739 # start with config full for maximum coverage (also enables USE_PSA)
2740 helper_libtestdriver1_adjust_config "full"
2741
2742 if [ "$driver_only" -eq 1 ]; then
2743 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
2744 # is still enabled though (for ENTROPY_C among others).
2745 scripts/config.py unset MBEDTLS_MD_C
2746 # Disable also the builtin hashes since they are supported by the driver
2747 # and MD module is able to perform PSA dispathing.
2748 scripts/config.py unset-all MBEDTLS_SHA
2749 scripts/config.py unset MBEDTLS_MD5_C
2750 scripts/config.py unset MBEDTLS_RIPEMD160_C
2751 fi
2752
2753 # Direct dependencies of MD_C. We disable them also in the reference
2754 # component to work with the same set of features.
2755 scripts/config.py unset MBEDTLS_PKCS7_C
2756 scripts/config.py unset MBEDTLS_PKCS5_C
2757 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
2758 scripts/config.py unset MBEDTLS_HKDF_C
2759 # Dependencies of HMAC_DRBG
2760 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
2761 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
2762}
2763
2764component_test_psa_crypto_config_accel_hmac () {
2765 msg "test: full with accelerated hmac"
2766
2767 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
2768 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
2769 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2770 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2771
2772 # Configure
2773 # ---------
2774
2775 config_psa_crypto_hmac_use_psa 1
2776
2777 # Build
2778 # -----
2779
2780 helper_libtestdriver1_make_drivers "$loc_accel_list"
2781
2782 helper_libtestdriver1_make_main "$loc_accel_list"
2783
2784 # Ensure that built-in support for HMAC is disabled.
2785 not grep mbedtls_md_hmac library/md.o
2786
2787 # Run the tests
2788 # -------------
2789
2790 msg "test: full with accelerated hmac"
2791 make test
2792}
2793
2794component_test_psa_crypto_config_reference_hmac () {
2795 msg "test: full without accelerated hmac"
2796
2797 config_psa_crypto_hmac_use_psa 0
2798
2799 make
2800
2801 msg "test: full without accelerated hmac"
2802 make test
2803}
2804
2805component_test_psa_crypto_config_accel_des () {
2806 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
2807
2808 # Albeit this components aims at accelerating DES which should only support
2809 # CBC and ECB modes, we need to accelerate more than that otherwise DES_C
2810 # would automatically be re-enabled by "config_adjust_legacy_from_psa.c"
2811 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 \
2812 ALG_CTR ALG_CFB ALG_OFB ALG_XTS ALG_CMAC \
2813 KEY_TYPE_DES"
2814
2815 # Note: we cannot accelerate all ciphers' key types otherwise we would also
2816 # have to either disable CCM/GCM or accelerate them, but that's out of scope
2817 # of this component. This limitation will be addressed by #8598.
2818
2819 # Configure
2820 # ---------
2821
2822 # Start from the full config
2823 helper_libtestdriver1_adjust_config "full"
2824
2825 # Disable the things that are being accelerated
2826 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2827 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2828 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2829 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2830 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2831 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2832 scripts/config.py unset MBEDTLS_DES_C
2833 scripts/config.py unset MBEDTLS_CMAC_C
2834
2835 # Build
2836 # -----
2837
2838 helper_libtestdriver1_make_drivers "$loc_accel_list"
2839
2840 helper_libtestdriver1_make_main "$loc_accel_list"
2841
2842 # Make sure this was not re-enabled by accident (additive config)
2843 not grep mbedtls_des* library/des.o
2844
2845 # Run the tests
2846 # -------------
2847
2848 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
2849 make test
2850}
2851
2852component_test_psa_crypto_config_accel_aead () {
2853 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2854
2855 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
2856 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2857
2858 # Configure
2859 # ---------
2860
2861 # Start from full config
2862 helper_libtestdriver1_adjust_config "full"
2863
2864 # Disable things that are being accelerated
2865 scripts/config.py unset MBEDTLS_GCM_C
2866 scripts/config.py unset MBEDTLS_CCM_C
2867 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2868
2869 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
2870 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
2871
2872 # Build
2873 # -----
2874
2875 helper_libtestdriver1_make_drivers "$loc_accel_list"
2876
2877 helper_libtestdriver1_make_main "$loc_accel_list"
2878
2879 # Make sure this was not re-enabled by accident (additive config)
2880 not grep mbedtls_ccm library/ccm.o
2881 not grep mbedtls_gcm library/gcm.o
2882 not grep mbedtls_chachapoly library/chachapoly.o
2883
2884 # Run the tests
2885 # -------------
2886
2887 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2888 make test
2889}
2890
2891# This is a common configuration function used in:
2892# - component_test_psa_crypto_config_accel_cipher_aead_cmac
2893# - component_test_psa_crypto_config_reference_cipher_aead_cmac
2894common_psa_crypto_config_accel_cipher_aead_cmac () {
2895 # Start from the full config
2896 helper_libtestdriver1_adjust_config "full"
2897
2898 scripts/config.py unset MBEDTLS_NIST_KW_C
2899}
2900
2901# The 2 following test components, i.e.
2902# - component_test_psa_crypto_config_accel_cipher_aead_cmac
2903# - component_test_psa_crypto_config_reference_cipher_aead_cmac
2904# are meant to be used together in analyze_outcomes.py script in order to test
2905# driver's coverage for ciphers and AEADs.
2906component_test_psa_crypto_config_accel_cipher_aead_cmac () {
2907 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
2908
2909 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
2910 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
2911 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
2912 KEY_TYPE_DES KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
2913
2914 # Configure
2915 # ---------
2916
2917 common_psa_crypto_config_accel_cipher_aead_cmac
2918
2919 # Disable the things that are being accelerated
2920 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2921 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2922 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2923 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2924 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2925 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2926 scripts/config.py unset MBEDTLS_GCM_C
2927 scripts/config.py unset MBEDTLS_CCM_C
2928 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2929 scripts/config.py unset MBEDTLS_CMAC_C
2930 scripts/config.py unset MBEDTLS_DES_C
2931 scripts/config.py unset MBEDTLS_AES_C
2932 scripts/config.py unset MBEDTLS_ARIA_C
2933 scripts/config.py unset MBEDTLS_CHACHA20_C
2934 scripts/config.py unset MBEDTLS_CAMELLIA_C
2935
2936 # Disable CIPHER_C entirely as all ciphers/AEADs are accelerated and PSA
2937 # does not depend on it.
2938 scripts/config.py unset MBEDTLS_CIPHER_C
2939
2940 # Build
2941 # -----
2942
2943 helper_libtestdriver1_make_drivers "$loc_accel_list"
2944
2945 helper_libtestdriver1_make_main "$loc_accel_list"
2946
2947 # Make sure this was not re-enabled by accident (additive config)
2948 not grep mbedtls_cipher library/cipher.o
2949 not grep mbedtls_des library/des.o
2950 not grep mbedtls_aes library/aes.o
2951 not grep mbedtls_aria library/aria.o
2952 not grep mbedtls_camellia library/camellia.o
2953 not grep mbedtls_ccm library/ccm.o
2954 not grep mbedtls_gcm library/gcm.o
2955 not grep mbedtls_chachapoly library/chachapoly.o
2956 not grep mbedtls_cmac library/cmac.o
2957
2958 # Run the tests
2959 # -------------
2960
2961 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
2962 make test
2963
2964 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
2965 tests/ssl-opt.sh
2966
2967 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
2968 tests/compat.sh -V NO -p mbedTLS
2969}
2970
2971component_test_psa_crypto_config_reference_cipher_aead_cmac () {
2972 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
2973 common_psa_crypto_config_accel_cipher_aead_cmac
2974
2975 make
2976
2977 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
2978 make test
2979
2980 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
2981 tests/ssl-opt.sh
2982
2983 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
2984 tests/compat.sh -V NO -p mbedTLS
2985}
2986
2987common_block_cipher_dispatch () {
2988 TEST_WITH_DRIVER="$1"
2989
2990 # Start from the full config
2991 helper_libtestdriver1_adjust_config "full"
2992
2993 if [ "$TEST_WITH_DRIVER" -eq 1 ]; then
2994 # Disable key types that are accelerated (there is no legacy equivalent
2995 # symbol for ECB)
2996 scripts/config.py unset MBEDTLS_AES_C
2997 scripts/config.py unset MBEDTLS_ARIA_C
2998 scripts/config.py unset MBEDTLS_CAMELLIA_C
2999 fi
3000
3001 # Disable cipher's modes that, when not accelerated, cause
3002 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
3003 # Keep this also in the reference component in order to skip the same tests
3004 # that were skipped in the accelerated one.
3005 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
3006 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
3007 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
3008 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
3009 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
3010 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
3011 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
3012 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
3013
3014 # Disable direct dependency on AES_C
3015 scripts/config.py unset MBEDTLS_NIST_KW_C
3016
3017 # Prevent the cipher module from using deprecated PSA path. The reason is
3018 # that otherwise there will be tests relying on "aes_info" (defined in
3019 # "cipher_wrap.c") whose functions are not available when AES_C is
3020 # not defined. ARIA and Camellia are not a problem in this case because
3021 # the PSA path is not tested for these key types.
3022 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
3023}
3024
3025component_test_full_block_cipher_psa_dispatch () {
3026 msg "build: full + PSA dispatch in block_cipher"
3027
3028 loc_accel_list="ALG_ECB_NO_PADDING \
3029 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
3030
3031 # Configure
3032 # ---------
3033
3034 common_block_cipher_dispatch 1
3035
3036 # Build
3037 # -----
3038
3039 helper_libtestdriver1_make_drivers "$loc_accel_list"
3040
3041 helper_libtestdriver1_make_main "$loc_accel_list"
3042
3043 # Make sure disabled components were not re-enabled by accident (additive
3044 # config)
3045 not grep mbedtls_aes_ library/aes.o
3046 not grep mbedtls_aria_ library/aria.o
3047 not grep mbedtls_camellia_ library/camellia.o
3048
3049 # Run the tests
3050 # -------------
3051
3052 msg "test: full + PSA dispatch in block_cipher"
3053 make test
3054}
3055
3056# This is the reference component of component_test_full_block_cipher_psa_dispatch
3057component_test_full_block_cipher_legacy_dispatch () {
3058 msg "build: full + legacy dispatch in block_cipher"
3059
3060 common_block_cipher_dispatch 0
3061
3062 make
3063
3064 msg "test: full + legacy dispatch in block_cipher"
3065 make test
3066}
3067
3068component_test_aead_chachapoly_disabled () {
3069 msg "build: full minus CHACHAPOLY"
3070 scripts/config.py full
3071 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
3072 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
3073 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
3074
3075 msg "test: full minus CHACHAPOLY"
3076 make test
3077}
3078
3079component_test_aead_only_ccm () {
3080 msg "build: full minus CHACHAPOLY and GCM"
3081 scripts/config.py full
3082 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
3083 scripts/config.py unset MBEDTLS_GCM_C
3084 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
3085 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
3086 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
3087
3088 msg "test: full minus CHACHAPOLY and GCM"
3089 make test
3090}
3091
3092component_test_ccm_aes_sha256 () {
3093 msg "build: CCM + AES + SHA256 configuration"
3094
3095 cp "$CONFIG_TEST_DRIVER_H" "$CONFIG_H"
3096 cp configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
3097
3098 make
3099
3100 msg "test: CCM + AES + SHA256 configuration"
3101 make test
3102}
3103
3104# This should be renamed to test and updated once the accelerator ECDH code is in place and ready to test.
3105component_build_psa_accel_alg_ecdh () {
3106 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
3107 scripts/config.py full
3108 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3109 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3110 scripts/config.py unset MBEDTLS_ECDH_C
3111 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3112 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
3113 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
3114 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3115 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
3116 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3117 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
3118}
3119
3120# This should be renamed to test and updated once the accelerator HMAC code is in place and ready to test.
3121component_build_psa_accel_alg_hmac () {
3122 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
3123 scripts/config.py full
3124 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3125 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3126 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3127 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
3128}
3129
3130# This should be renamed to test and updated once the accelerator HKDF code is in place and ready to test.
3131component_build_psa_accel_alg_hkdf () {
3132 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
3133 scripts/config.py full
3134 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3135 scripts/config.py unset MBEDTLS_HKDF_C
3136 # Make sure to unset TLS1_3 since it requires HKDF_C and will not build properly without it.
3137 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3138 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3139 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
3140}
3141
3142# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
3143component_build_psa_accel_alg_md5 () {
3144 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - other hashes"
3145 scripts/config.py full
3146 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3147 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3148 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3149 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3150 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3151 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3152 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3153 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3154 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
3155 scripts/config.py unset MBEDTLS_LMS_C
3156 scripts/config.py unset MBEDTLS_LMS_PRIVATE
3157 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3158 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
3159}
3160
3161# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
3162component_build_psa_accel_alg_ripemd160 () {
3163 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - other hashes"
3164 scripts/config.py full
3165 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3166 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3167 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3168 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3169 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3170 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3171 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3172 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3173 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
3174 scripts/config.py unset MBEDTLS_LMS_C
3175 scripts/config.py unset MBEDTLS_LMS_PRIVATE
3176 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3177 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
3178}
3179
3180# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
3181component_build_psa_accel_alg_sha1 () {
3182 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - other hashes"
3183 scripts/config.py full
3184 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3185 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3186 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3187 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3188 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3189 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3190 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3191 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3192 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
3193 scripts/config.py unset MBEDTLS_LMS_C
3194 scripts/config.py unset MBEDTLS_LMS_PRIVATE
3195 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3196 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
3197}
3198
3199# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
3200component_build_psa_accel_alg_sha224 () {
3201 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
3202 scripts/config.py full
3203 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3204 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3205 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3206 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3207 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3208 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3209 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3210 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
3211 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3212 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
3213}
3214
3215# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
3216component_build_psa_accel_alg_sha256 () {
3217 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - other hashes"
3218 scripts/config.py full
3219 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3220 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3221 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3222 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3223 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3224 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3225 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3226 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3227 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3228 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
3229}
3230
3231# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
3232component_build_psa_accel_alg_sha384 () {
3233 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
3234 scripts/config.py full
3235 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3236 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3237 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3238 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3239 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3240 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3241 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3242 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
3243 scripts/config.py unset MBEDTLS_LMS_C
3244 scripts/config.py unset MBEDTLS_LMS_PRIVATE
3245 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3246 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
3247}
3248
3249# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
3250component_build_psa_accel_alg_sha512 () {
3251 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
3252 scripts/config.py full
3253 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3254 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3255 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3256 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3257 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3258 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3259 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3260 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3261 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
3262 scripts/config.py unset MBEDTLS_LMS_C
3263 scripts/config.py unset MBEDTLS_LMS_PRIVATE
3264 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3265 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
3266}
3267
3268# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
3269component_build_psa_accel_alg_rsa_pkcs1v15_crypt () {
3270 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
3271 scripts/config.py full
3272 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3273 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3274 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
3275 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3276 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3277 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
3278 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3279 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
3280}
3281
3282# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
3283component_build_psa_accel_alg_rsa_pkcs1v15_sign () {
3284 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
3285 scripts/config.py full
3286 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3287 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3288 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
3289 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3290 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3291 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
3292 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3293 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
3294}
3295
3296# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
3297component_build_psa_accel_alg_rsa_oaep () {
3298 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
3299 scripts/config.py full
3300 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3301 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3302 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_OAEP 1
3303 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3304 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3305 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
3306 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3307 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
3308}
3309
3310# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
3311component_build_psa_accel_alg_rsa_pss () {
3312 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
3313 scripts/config.py full
3314 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3315 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3316 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
3317 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3318 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3319 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3320 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3321 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
3322}
3323
3324# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
3325component_build_psa_accel_key_type_rsa_key_pair () {
3326 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_xxx + PSA_WANT_ALG_RSA_PSS"
3327 scripts/config.py full
3328 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3329 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3330 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
3331 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC 1
3332 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT 1
3333 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT 1
3334 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE 1
3335 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3336 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
3337}
3338
3339# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
3340component_build_psa_accel_key_type_rsa_public_key () {
3341 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
3342 scripts/config.py full
3343 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3344 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3345 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
3346 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
3347 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3348 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
3349}
3350
Minos Galanakisf7d1cb02024-07-30 17:25:31 +01003351component_build_tfm () {
3352 # Check that the TF-M configuration can build cleanly with various
3353 # warning flags enabled. We don't build or run tests, since the
3354 # TF-M configuration needs a TF-M platform. A tweaked version of
3355 # the configuration that works on mainstream platforms is in
3356 # configs/config-tfm.h, tested via test-ref-configs.pl.
3357 cp configs/config-tfm.h "$CONFIG_H"
3358
3359 msg "build: TF-M config, clang, armv7-m thumb2"
3360 make lib CC="clang" CFLAGS="--target=arm-linux-gnueabihf -march=armv7-m -mthumb -Os -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused -I../tests/include/spe"
3361
3362 msg "build: TF-M config, gcc native build"
3363 make clean
3364 make lib CC="gcc" CFLAGS="-Os -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wformat-signedness -Wlogical-op -I../tests/include/spe"
3365}
3366
3367# Test that the given .o file builds with all (valid) combinations of the given options.
3368#
3369# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
3370#
3371# The validator function is the name of a function to validate the combination of options.
3372# It may be "" if all combinations are valid.
3373# It receives a string containing a combination of options, as passed to the compiler,
3374# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
3375build_test_config_combos () {
3376 file=$1
3377 shift
3378 validate_options=$1
3379 shift
3380 options=("$@")
3381
3382 # clear all of the options so that they can be overridden on the clang commandline
3383 for opt in "${options[@]}"; do
3384 ./scripts/config.py unset ${opt}
3385 done
3386
3387 # enter the directory containing the target file & strip the dir from the filename
3388 cd $(dirname ${file})
3389 file=$(basename ${file})
3390
3391 # The most common issue is unused variables/functions, so ensure -Wunused is set.
3392 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
3393
3394 # Extract the command generated by the Makefile to build the target file.
3395 # This ensures that we have any include paths, macro definitions, etc
3396 # that may be applied by make.
3397 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
3398 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
3399
3400 makefile=$(TMPDIR=. mktemp)
3401 deps=""
3402
3403 len=${#options[@]}
3404 source_file=${file%.o}.c
3405
3406 targets=0
3407 echo 'include Makefile' >${makefile}
3408
3409 for ((i = 0; i < $((2**${len})); i++)); do
3410 # generate each of 2^n combinations of options
3411 # each bit of $i is used to determine if options[i] will be set or not
3412 target="t"
3413 clang_args=""
3414 for ((j = 0; j < ${len}; j++)); do
3415 if (((i >> j) & 1)); then
3416 opt=-D${options[$j]}
3417 clang_args="${clang_args} ${opt}"
3418 target="${target}${opt}"
3419 fi
3420 done
3421
3422 # if combination is not known to be invalid, add it to the makefile
3423 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
3424 cmd="${compile_cmd} ${clang_args}"
3425 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
3426
3427 deps="${deps} ${target}"
3428 ((++targets))
3429 fi
3430 done
3431
3432 echo "build_test_config_combos: ${deps}" >> ${makefile}
3433
3434 # execute all of the commands via Make (probably in parallel)
3435 make -s -f ${makefile} build_test_config_combos
3436 echo "$targets targets checked"
3437
3438 # clean up the temporary makefile
3439 rm ${makefile}
3440}
3441
3442validate_aes_config_variations () {
3443 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
3444 if [[ "$1" == *"MBEDTLS_PADLOCK_C"* ]]; then
3445 return 1
3446 fi
3447 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
3448 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
3449 return 1
3450 fi
3451 fi
3452 return 0
3453}
3454
3455component_build_aes_variations () {
3456 # 18s - around 90ms per clang invocation on M1 Pro
3457 #
3458 # aes.o has many #if defined(...) guards that intersect in complex ways.
3459 # Test that all the combinations build cleanly.
3460
3461 MBEDTLS_ROOT_DIR="$PWD"
3462 msg "build: aes.o for all combinations of relevant config options"
3463
3464 build_test_config_combos library/aes.o validate_aes_config_variations \
3465 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
3466 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
3467 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
3468 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
3469
3470 cd "$MBEDTLS_ROOT_DIR"
3471 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
3472
3473 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES,
3474 # manually set or unset those configurations to check
3475 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
3476 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
3477 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3478 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
3479 scripts/config.py unset MBEDTLS_DES_C
3480 scripts/config.py unset MBEDTLS_NIST_KW_C
3481 build_test_config_combos library/aes.o validate_aes_config_variations \
3482 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
3483 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
3484 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
3485 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
3486}
3487
3488component_test_no_platform () {
3489 # Full configuration build, without platform support, file IO and net sockets.
3490 # This should catch missing mbedtls_printf definitions, and by disabling file
3491 # IO, it should catch missing '#include <stdio.h>'
3492 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
3493 scripts/config.py full_no_platform
3494 scripts/config.py unset MBEDTLS_PLATFORM_C
3495 scripts/config.py unset MBEDTLS_NET_C
3496 scripts/config.py unset MBEDTLS_FS_IO
3497 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
3498 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
3499 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
3500 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
3501 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
3502 # to re-enable platform integration features otherwise disabled in C99 builds
3503 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
3504 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
3505}
3506
3507component_build_no_std_function () {
3508 # catch compile bugs in _uninit functions
3509 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
3510 scripts/config.py full
3511 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
3512 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
3513 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
3514 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
3515 make
3516}
3517
3518component_build_no_ssl_srv () {
3519 msg "build: full config except SSL server, make, gcc" # ~ 30s
3520 scripts/config.py full
3521 scripts/config.py unset MBEDTLS_SSL_SRV_C
3522 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
3523}
3524
3525component_build_no_ssl_cli () {
3526 msg "build: full config except SSL client, make, gcc" # ~ 30s
3527 scripts/config.py full
3528 scripts/config.py unset MBEDTLS_SSL_CLI_C
3529 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
3530}
3531
3532component_build_no_sockets () {
3533 # Note, C99 compliance can also be tested with the sockets support disabled,
3534 # as that requires a POSIX platform (which isn't the same as C99).
3535 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
3536 scripts/config.py full
3537 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
3538 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
3539 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
3540}
3541
3542component_test_memory_buffer_allocator_backtrace () {
3543 msg "build: default config with memory buffer allocator and backtrace enabled"
3544 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
3545 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
3546 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
3547 scripts/config.py set MBEDTLS_MEMORY_DEBUG
3548 cmake -DCMAKE_BUILD_TYPE:String=Release .
3549 make
3550
3551 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
3552 make test
3553}
3554
3555component_test_memory_buffer_allocator () {
3556 msg "build: default config with memory buffer allocator"
3557 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
3558 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
3559 cmake -DCMAKE_BUILD_TYPE:String=Release .
3560 make
3561
3562 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
3563 make test
3564
3565 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
3566 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
3567 tests/ssl-opt.sh -e '^DTLS proxy'
3568}
3569
3570component_test_no_max_fragment_length () {
3571 # Run max fragment length tests with MFL disabled
3572 msg "build: default config except MFL extension (ASan build)" # ~ 30s
3573 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
3574 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3575 make
3576
3577 msg "test: ssl-opt.sh, MFL-related tests"
3578 tests/ssl-opt.sh -f "Max fragment length"
3579}
3580
3581component_test_asan_remove_peer_certificate () {
3582 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
3583 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
3584 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3585 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3586 make
3587
3588 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
3589 make test
3590
3591 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
3592 tests/ssl-opt.sh
3593
3594 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
3595 tests/compat.sh
3596
3597 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
3598 tests/context-info.sh
3599}
3600
3601component_test_no_max_fragment_length_small_ssl_out_content_len () {
3602 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
3603 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
3604 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
3605 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
3606 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3607 make
3608
3609 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
3610 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
3611
3612 msg "test: context-info.sh (disabled MFL extension case)"
3613 tests/context-info.sh
3614}
3615
3616component_test_variable_ssl_in_out_buffer_len () {
3617 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
3618 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
3619 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3620 make
3621
3622 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
3623 make test
3624
3625 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
3626 tests/ssl-opt.sh
3627
3628 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
3629 tests/compat.sh
3630}
3631
3632component_test_dtls_cid_legacy () {
3633 msg "build: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled (ASan build)"
3634 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 1
3635
3636 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3637 make
3638
3639 msg "test: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy)"
3640 make test
3641
3642 msg "test: ssl-opt.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
3643 tests/ssl-opt.sh
3644
3645 msg "test: compat.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
3646 tests/compat.sh
3647}
3648
3649component_test_ssl_alloc_buffer_and_mfl () {
3650 msg "build: default config with memory buffer allocator and MFL extension"
3651 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
3652 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
3653 scripts/config.py set MBEDTLS_MEMORY_DEBUG
3654 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
3655 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
3656 cmake -DCMAKE_BUILD_TYPE:String=Release .
3657 make
3658
3659 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
3660 make test
3661
3662 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
3663 tests/ssl-opt.sh -f "Handshake memory usage"
3664}
3665
3666component_test_when_no_ciphersuites_have_mac () {
3667 msg "build: when no ciphersuites have MAC"
3668 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
3669 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3670 scripts/config.py unset MBEDTLS_CMAC_C
3671 make
3672
3673 msg "test: !MBEDTLS_SSL_SOME_SUITES_USE_MAC"
3674 make test
3675
3676 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_SUITES_USE_MAC"
3677 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
3678}
3679
3680component_test_no_date_time () {
3681 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
3682 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
3683 cmake -D CMAKE_BUILD_TYPE:String=Check .
3684 make
3685
3686 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
3687 make test
3688}
3689
3690component_test_platform_calloc_macro () {
3691 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
3692 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
3693 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
3694 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
3695 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3696 make
3697
3698 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
3699 make test
3700}
3701
3702component_test_malloc_0_null () {
3703 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
3704 scripts/config.py full
3705 make CC=$ASAN_CC CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"$PWD/tests/configs/user-config-malloc-0-null.h\"' $ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
3706
3707 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
3708 make test
3709
3710 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
3711 # Just the calloc selftest. "make test" ran the others as part of the
3712 # test suites.
3713 programs/test/selftest calloc
3714
3715 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
3716 # Run a subset of the tests. The choice is a balance between coverage
3717 # and time (including time indirectly wasted due to flaky tests).
3718 # The current choice is to skip tests whose description includes
3719 # "proxy", which is an approximation of skipping tests that use the
3720 # UDP proxy, which tend to be slower and flakier.
3721 tests/ssl-opt.sh -e 'proxy'
3722}
3723
3724support_test_aesni () {
3725 # Check that gcc targets x86_64 (we can build AESNI), and check for
3726 # AESNI support on the host (we can run AESNI).
3727 #
3728 # The name of this function is possibly slightly misleading, but needs to align
3729 # with the name of the corresponding test, component_test_aesni.
3730 #
3731 # In principle 32-bit x86 can support AESNI, but our implementation does not
3732 # support 32-bit x86, so we check for x86-64.
3733 # We can only grep /proc/cpuinfo on Linux, so this also checks for Linux
3734 (gcc -v 2>&1 | grep Target | grep -q x86_64) &&
3735 [[ "$HOSTTYPE" == "x86_64" && "$OSTYPE" == "linux-gnu" ]] &&
3736 (lscpu | grep -qw aes)
3737}
3738
3739component_test_aesni () { # ~ 60s
3740 # This tests the two AESNI implementations (intrinsics and assembly), and also the plain C
3741 # fallback. It also tests the logic that is used to select which implementation(s) to build.
3742 #
3743 # This test does not require the host to have support for AESNI (if it doesn't, the run-time
3744 # AESNI detection will fallback to the plain C implementation, so the tests will instead
3745 # exercise the plain C impl).
3746
3747 msg "build: default config with different AES implementations"
3748 scripts/config.py set MBEDTLS_AESNI_C
3749 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
3750 scripts/config.py set MBEDTLS_HAVE_ASM
3751
3752 # test the intrinsics implementation
3753 msg "AES tests, test intrinsics"
3754 make clean
3755 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
3756 # check that we built intrinsics - this should be used by default when supported by the compiler
3757 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
3758
3759 # test the asm implementation
3760 msg "AES tests, test assembly"
3761 make clean
3762 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mno-pclmul -mno-sse2 -mno-aes'
3763 # check that we built assembly - this should be built if the compiler does not support intrinsics
3764 ./programs/test/selftest aes | grep "AESNI code" | grep -q "assembly"
3765
3766 # test the plain C implementation
3767 scripts/config.py unset MBEDTLS_AESNI_C
3768 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
3769 msg "AES tests, plain C"
3770 make clean
3771 make CC=gcc CFLAGS='-O2 -Werror'
3772 # check that there is no AESNI code present
3773 ./programs/test/selftest aes | not grep -q "AESNI code"
3774 not grep -q "AES note: using AESNI" ./programs/test/selftest
3775 grep -q "AES note: built-in implementation." ./programs/test/selftest
3776
3777 # test the intrinsics implementation
3778 scripts/config.py set MBEDTLS_AESNI_C
3779 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
3780 msg "AES tests, test AESNI only"
3781 make clean
3782 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
3783 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
3784 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
3785 grep -q "AES note: using AESNI" ./programs/test/selftest
3786 not grep -q "AES note: built-in implementation." ./programs/test/selftest
3787}
3788
3789component_test_sha3_variations () {
3790 msg "sha3 loop unroll variations"
3791
3792 # define minimal config sufficient to test SHA3
3793 cat > include/mbedtls/mbedtls_config.h << END
3794 #define MBEDTLS_SELF_TEST
3795 #define MBEDTLS_SHA3_C
3796END
3797
3798 msg "all loops unrolled"
3799 make clean
3800 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"
3801 ./tests/test_suite_shax
3802
3803 msg "all loops rolled up"
3804 make clean
3805 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"
3806 ./tests/test_suite_shax
3807}
3808
3809support_test_aesni_m32 () {
3810 support_test_m32_no_asm && (lscpu | grep -qw aes)
3811}
3812
3813component_test_aesni_m32 () { # ~ 60s
3814 # This tests are duplicated from component_test_aesni for i386 target
3815 #
3816 # AESNI intrinsic code supports i386 and assembly code does not support it.
3817
3818 msg "build: default config with different AES implementations"
3819 scripts/config.py set MBEDTLS_AESNI_C
3820 scripts/config.py set MBEDTLS_PADLOCK_C
3821 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
3822 scripts/config.py set MBEDTLS_HAVE_ASM
3823
3824 # test the intrinsics implementation with gcc
3825 msg "AES tests, test intrinsics (gcc)"
3826 make clean
3827 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra' LDFLAGS='-m32'
3828 # check that we built intrinsics - this should be used by default when supported by the compiler
3829 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
3830 grep -q "AES note: using AESNI" ./programs/test/selftest
3831 grep -q "AES note: built-in implementation." ./programs/test/selftest
3832 grep -q "AES note: using VIA Padlock" ./programs/test/selftest
3833 grep -q mbedtls_aesni_has_support ./programs/test/selftest
3834
3835 scripts/config.py set MBEDTLS_AESNI_C
3836 scripts/config.py unset MBEDTLS_PADLOCK_C
3837 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
3838 msg "AES tests, test AESNI only"
3839 make clean
3840 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
3841 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
3842 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
3843 grep -q "AES note: using AESNI" ./programs/test/selftest
3844 not grep -q "AES note: built-in implementation." ./programs/test/selftest
3845 not grep -q "AES note: using VIA Padlock" ./programs/test/selftest
3846 not grep -q mbedtls_aesni_has_support ./programs/test/selftest
3847}
3848
3849support_test_aesni_m32_clang () {
3850 # clang >= 4 is required to build with target attributes
3851 support_test_aesni_m32 && [[ $(clang_version) -ge 4 ]]
3852}
3853
3854component_test_aesni_m32_clang () {
3855
3856 scripts/config.py set MBEDTLS_AESNI_C
3857 scripts/config.py set MBEDTLS_PADLOCK_C
3858 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
3859 scripts/config.py set MBEDTLS_HAVE_ASM
3860
3861 # test the intrinsics implementation with clang
3862 msg "AES tests, test intrinsics (clang)"
3863 make clean
3864 make CC=clang CFLAGS='-m32 -Werror -Wall -Wextra' LDFLAGS='-m32'
3865 # check that we built intrinsics - this should be used by default when supported by the compiler
3866 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
3867 grep -q "AES note: using AESNI" ./programs/test/selftest
3868 grep -q "AES note: built-in implementation." ./programs/test/selftest
3869 grep -q "AES note: using VIA Padlock" ./programs/test/selftest
3870 grep -q mbedtls_aesni_has_support ./programs/test/selftest
3871}
3872
3873# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
3874component_build_aes_aesce_armcc () {
3875 msg "Build: AESCE test on arm64 platform without plain C."
3876 scripts/config.py baremetal
3877
3878 # armc[56] don't support SHA-512 intrinsics
3879 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
3880
3881 # Stop armclang warning about feature detection for A64_CRYPTO.
3882 # With this enabled, the library does build correctly under armclang,
3883 # but in baremetal builds (as tested here), feature detection is
3884 # unavailable, and the user is notified via a #warning. So enabling
3885 # this feature would prevent us from building with -Werror on
3886 # armclang. Tracked in #7198.
3887 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
3888 scripts/config.py set MBEDTLS_HAVE_ASM
3889
3890 msg "AESCE, build with default configuration."
3891 scripts/config.py set MBEDTLS_AESCE_C
3892 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
3893 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
3894
3895 msg "AESCE, build AESCE only"
3896 scripts/config.py set MBEDTLS_AESCE_C
3897 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
3898 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
3899}
3900
3901support_build_aes_armce () {
3902 # clang >= 11 is required to build with AES extensions
3903 [[ $(clang_version) -ge 11 ]]
3904}
3905
3906component_build_aes_armce () {
3907 # Test variations of AES with Armv8 crypto extensions
3908 scripts/config.py set MBEDTLS_AESCE_C
3909 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
3910
3911 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, aarch64"
3912 make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
3913
3914 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, arm"
3915 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
3916
3917 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, thumb"
3918 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
3919
3920 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
3921
3922 msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, aarch64"
3923 make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
3924
3925 msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, arm"
3926 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
3927
3928 msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, thumb"
3929 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
3930
3931 # test for presence of AES instructions
3932 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
3933 msg "clang, test A32 crypto instructions built"
3934 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
3935 grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
3936 msg "clang, test T32 crypto instructions built"
3937 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
3938 grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
3939 msg "clang, test aarch64 crypto instructions built"
3940 make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
3941 grep -E 'aes[a-z]+\s*[qv]' library/aesce.o
3942
3943 # test for absence of AES instructions
3944 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
3945 scripts/config.py unset MBEDTLS_AESCE_C
3946 msg "clang, test A32 crypto instructions not built"
3947 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
3948 not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
3949 msg "clang, test T32 crypto instructions not built"
3950 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
3951 not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
3952 msg "clang, test aarch64 crypto instructions not built"
3953 make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
3954 not grep -E 'aes[a-z]+\s*[qv]' library/aesce.o
3955}
3956
3957support_build_sha_armce () {
3958 # clang >= 4 is required to build with SHA extensions
3959 [[ $(clang_version) -ge 4 ]]
3960}
3961
3962component_build_sha_armce () {
3963 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
3964
3965
3966 # Test variations of SHA256 Armv8 crypto extensions
3967 scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
3968 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, aarch64"
3969 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
3970 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, arm"
3971 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
3972 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
3973
3974
3975 # test the deprecated form of the config option
3976 scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
3977 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY clang, thumb"
3978 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
3979 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
3980
3981 scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
3982 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT clang, aarch64"
3983 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
3984 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
3985
3986
3987 # test the deprecated form of the config option
3988 scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
3989 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, arm"
3990 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -std=c99"
3991 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, thumb"
3992 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
3993 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
3994
3995
3996 # examine the disassembly for presence of SHA instructions
3997 for opt in MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT; do
3998 scripts/config.py set ${opt}
3999 msg "${opt} clang, test A32 crypto instructions built"
4000 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
4001 grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4002
4003 msg "${opt} clang, test T32 crypto instructions built"
4004 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
4005 grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4006
4007 msg "${opt} clang, test aarch64 crypto instructions built"
4008 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
4009 grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.o
4010 scripts/config.py unset ${opt}
4011 done
4012
4013
4014 # examine the disassembly for absence of SHA instructions
4015 msg "clang, test A32 crypto instructions not built"
4016 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
4017 not grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4018
4019 msg "clang, test T32 crypto instructions not built"
4020 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
4021 not grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4022
4023 msg "clang, test aarch64 crypto instructions not built"
4024 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
4025 not grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.o
4026}
4027
4028# For timebeing, no VIA Padlock platform available.
4029component_build_aes_via_padlock () {
4030
4031 msg "AES:VIA PadLock, build with default configuration."
4032 scripts/config.py unset MBEDTLS_AESNI_C
4033 scripts/config.py set MBEDTLS_PADLOCK_C
4034 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4035 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
4036 grep -q mbedtls_padlock_has_support ./programs/test/selftest
4037
4038}
4039
4040support_build_aes_via_padlock_only () {
4041 ( [ "$MBEDTLS_TEST_PLATFORM" == "Linux-x86_64" ] || \
4042 [ "$MBEDTLS_TEST_PLATFORM" == "Linux-amd64" ] ) && \
4043 [ "`dpkg --print-foreign-architectures`" == "i386" ]
4044}
4045
4046support_build_aes_aesce_armcc () {
4047 support_build_armcc
4048}
4049
4050component_test_aes_only_128_bit_keys () {
4051 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
4052 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4053 scripts/config.py unset MBEDTLS_PADLOCK_C
4054
4055 make CFLAGS='-O2 -Werror -Wall -Wextra'
4056
4057 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
4058 make test
4059}
4060
4061component_test_no_ctr_drbg_aes_only_128_bit_keys () {
4062 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
4063 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4064 scripts/config.py unset MBEDTLS_CTR_DRBG_C
4065 scripts/config.py unset MBEDTLS_PADLOCK_C
4066
4067 make CC=clang CFLAGS='-Werror -Wall -Wextra'
4068
4069 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
4070 make test
4071}
4072
4073component_test_aes_only_128_bit_keys_have_builtins () {
4074 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4075 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4076 scripts/config.py unset MBEDTLS_PADLOCK_C
4077 scripts/config.py unset MBEDTLS_AESNI_C
4078 scripts/config.py unset MBEDTLS_AESCE_C
4079
4080 make CFLAGS='-O2 -Werror -Wall -Wextra'
4081
4082 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4083 make test
4084
4085 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4086 programs/test/selftest
4087}
4088
4089component_test_gcm_largetable () {
4090 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
4091 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
4092 scripts/config.py unset MBEDTLS_PADLOCK_C
4093 scripts/config.py unset MBEDTLS_AESNI_C
4094 scripts/config.py unset MBEDTLS_AESCE_C
4095
4096 make CFLAGS='-O2 -Werror -Wall -Wextra'
4097
4098 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
4099 make test
4100}
4101
4102component_test_aes_fewer_tables () {
4103 msg "build: default config with AES_FEWER_TABLES enabled"
4104 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
4105 make CFLAGS='-O2 -Werror -Wall -Wextra'
4106
4107 msg "test: AES_FEWER_TABLES"
4108 make test
4109}
4110
4111component_test_aes_rom_tables () {
4112 msg "build: default config with AES_ROM_TABLES enabled"
4113 scripts/config.py set MBEDTLS_AES_ROM_TABLES
4114 make CFLAGS='-O2 -Werror -Wall -Wextra'
4115
4116 msg "test: AES_ROM_TABLES"
4117 make test
4118}
4119
4120component_test_aes_fewer_tables_and_rom_tables () {
4121 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
4122 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
4123 scripts/config.py set MBEDTLS_AES_ROM_TABLES
4124 make CFLAGS='-O2 -Werror -Wall -Wextra'
4125
4126 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
4127 make test
4128}
4129
4130# helper for common_block_cipher_no_decrypt() which:
4131# - enable/disable the list of config options passed from -s/-u respectively.
4132# - build
4133# - test for tests_suite_xxx
4134# - selftest
4135#
4136# Usage: helper_block_cipher_no_decrypt_build_test
4137# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
4138# Options: -s set_opts the list of config options to enable
4139# -u unset_opts the list of config options to disable
4140# -c cflags the list of options passed to CFLAGS
4141# -l ldflags the list of options passed to LDFLAGS
4142helper_block_cipher_no_decrypt_build_test () {
4143 while [ $# -gt 0 ]; do
4144 case "$1" in
4145 -s)
4146 shift; local set_opts="$1";;
4147 -u)
4148 shift; local unset_opts="$1";;
4149 -c)
4150 shift; local cflags="-Werror -Wall -Wextra $1";;
4151 -l)
4152 shift; local ldflags="$1";;
4153 esac
4154 shift
4155 done
4156 set_opts="${set_opts:-}"
4157 unset_opts="${unset_opts:-}"
4158 cflags="${cflags:-}"
4159 ldflags="${ldflags:-}"
4160
4161 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
4162 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
4163
4164 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
4165 make clean
4166 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
4167
4168 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
4169 not grep mbedtls_aes_setkey_dec library/aes.o
4170 not grep mbedtls_aria_setkey_dec library/aria.o
4171 not grep mbedtls_camellia_setkey_dec library/camellia.o
4172 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
4173 not grep mbedtls_internal_aes_decrypt library/aes.o
4174 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
4175 not grep mbedtls_aesni_inverse_key library/aesni.o
4176
4177 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
4178 make test
4179
4180 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
4181 programs/test/selftest
4182}
4183
4184# This is a common configuration function used in:
4185# - component_test_block_cipher_no_decrypt_aesni_legacy()
4186# - component_test_block_cipher_no_decrypt_aesni_use_psa()
4187# in order to test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics,
4188# AESNI assembly and AES C implementation on x86_64 and with AESNI intrinsics
4189# on x86.
4190common_block_cipher_no_decrypt () {
4191 # test AESNI intrinsics
4192 helper_block_cipher_no_decrypt_build_test \
4193 -s "MBEDTLS_AESNI_C" \
4194 -c "-mpclmul -msse2 -maes"
4195
4196 # test AESNI assembly
4197 helper_block_cipher_no_decrypt_build_test \
4198 -s "MBEDTLS_AESNI_C" \
4199 -c "-mno-pclmul -mno-sse2 -mno-aes"
4200
4201 # test AES C implementation
4202 helper_block_cipher_no_decrypt_build_test \
4203 -u "MBEDTLS_AESNI_C"
4204
4205 # test AESNI intrinsics for i386 target
4206 helper_block_cipher_no_decrypt_build_test \
4207 -s "MBEDTLS_AESNI_C" \
4208 -c "-m32 -mpclmul -msse2 -maes" \
4209 -l "-m32"
4210}
4211
4212# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
4213# usage: 0: no PSA crypto configuration
4214# 1: use PSA crypto configuration
4215config_block_cipher_no_decrypt () {
4216 use_psa=$1
4217
4218 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
4219 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
4220 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
4221 scripts/config.py unset MBEDTLS_DES_C
4222 scripts/config.py unset MBEDTLS_NIST_KW_C
4223
4224 if [ "$use_psa" -eq 1 ]; then
4225 # Enable support for cryptographic mechanisms through the PSA API.
4226 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
4227 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
4228 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
4229 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
4230 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
4231 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
4232 fi
4233}
4234
4235component_test_block_cipher_no_decrypt_aesni () {
4236 # This consistently causes an llvm crash on clang 3.8, so use gcc
4237 export CC=gcc
4238 config_block_cipher_no_decrypt 0
4239 common_block_cipher_no_decrypt
4240}
4241
4242component_test_block_cipher_no_decrypt_aesni_use_psa () {
4243 # This consistently causes an llvm crash on clang 3.8, so use gcc
4244 export CC=gcc
4245 config_block_cipher_no_decrypt 1
4246 common_block_cipher_no_decrypt
4247}
4248
4249support_test_block_cipher_no_decrypt_aesce_armcc () {
4250 support_build_armcc
4251}
4252
4253component_test_block_cipher_no_decrypt_aesce_armcc () {
4254 scripts/config.py baremetal
4255
4256 # armc[56] don't support SHA-512 intrinsics
4257 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
4258
4259 # Stop armclang warning about feature detection for A64_CRYPTO.
4260 # With this enabled, the library does build correctly under armclang,
4261 # but in baremetal builds (as tested here), feature detection is
4262 # unavailable, and the user is notified via a #warning. So enabling
4263 # this feature would prevent us from building with -Werror on
4264 # armclang. Tracked in #7198.
4265 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
4266 scripts/config.py set MBEDTLS_HAVE_ASM
4267
4268 config_block_cipher_no_decrypt 1
4269
4270 # test AESCE baremetal build
4271 scripts/config.py set MBEDTLS_AESCE_C
4272 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
4273 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
4274
4275 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
4276 not grep mbedtls_aes_setkey_dec library/aes.o
4277 not grep mbedtls_aria_setkey_dec library/aria.o
4278 not grep mbedtls_camellia_setkey_dec library/camellia.o
4279 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
4280 not grep mbedtls_internal_aes_decrypt library/aes.o
4281 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
4282 not grep mbedtls_aesce_inverse_key library/aesce.o
4283 not grep aesce_decrypt_block library/aesce.o
4284}
4285
4286component_test_ctr_drbg_aes_256_sha_256 () {
4287 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4288 scripts/config.py full
4289 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4290 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
4291 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
4292 make
4293
4294 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4295 make test
4296}
4297
4298component_test_ctr_drbg_aes_128_sha_512 () {
4299 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
4300 scripts/config.py full
4301 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4302 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
4303 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
4304 make
4305
4306 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
4307 make test
4308}
4309
4310component_test_ctr_drbg_aes_128_sha_256 () {
4311 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4312 scripts/config.py full
4313 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4314 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
4315 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
4316 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
4317 make
4318
4319 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4320 make test
4321}
4322
4323component_test_se_default () {
4324 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
4325 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
4326 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
4327
4328 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
4329 make test
4330}
4331
4332component_test_psa_crypto_drivers () {
4333 msg "build: full + test drivers dispatching to builtins"
4334 scripts/config.py full
4335 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
4336 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
4337 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
4338 loc_cflags="${loc_cflags} -I../tests/include -O2"
4339
4340 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
4341
4342 msg "test: full + test drivers dispatching to builtins"
4343 make test
4344}
4345
Minos Galanakisf7d1cb02024-07-30 17:25:31 +01004346component_build_mbedtls_config_file () {
4347 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
4348 scripts/config.py -w full_config.h full
4349 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
4350 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
4351 # Make sure this feature is enabled. We'll disable it in the next phase.
4352 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
4353 make clean
4354
4355 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
4356 # In the user config, disable one feature (for simplicity, pick a feature
4357 # that nothing else depends on).
4358 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
4359 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
4360 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
4361
4362 rm -f user_config.h full_config.h
4363}
4364
4365component_build_psa_config_file () {
4366 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
4367 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
4368 cp "$CRYPTO_CONFIG_H" psa_test_config.h
4369 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
4370 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
4371 # Make sure this feature is enabled. We'll disable it in the next phase.
4372 programs/test/query_compile_time_config MBEDTLS_CMAC_C
4373 make clean
4374
4375 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
4376 # In the user config, disable one feature and its dependencies, which will
4377 # reflect on the mbedtls configuration so we can query it with
4378 # query_compile_time_config.
4379 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
4380 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
4381 scripts/config.py unset MBEDTLS_CMAC_C
4382 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
4383 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
4384
4385 rm -f psa_test_config.h psa_user_config.h
4386}
4387
4388component_build_psa_alt_headers () {
4389 msg "build: make with PSA alt headers" # ~20s
4390
4391 # Generate alternative versions of the substitutable headers with the
4392 # same content except different include guards.
4393 make -C tests include/alt-extra/psa/crypto_platform_alt.h include/alt-extra/psa/crypto_struct_alt.h
4394
4395 # Build the library and some programs.
4396 # Don't build the fuzzers to avoid having to go through hoops to set
4397 # a correct include path for programs/fuzz/Makefile.
4398 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
4399 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\"'"
4400
4401 # Check that we're getting the alternative include guards and not the
4402 # original include guards.
4403 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
4404 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
4405 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
4406 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
4407}
4408
4409component_test_m32_no_asm () {
4410 # Build without assembly, so as to use portable C code (in a 32-bit
4411 # build) and not the i386-specific inline assembly.
4412 #
4413 # Note that we require gcc, because clang Asan builds fail to link for
4414 # this target (cannot find libclang_rt.lsan-i386.a - this is a known clang issue).
4415 msg "build: i386, make, gcc, no asm (ASan build)" # ~ 30s
4416 scripts/config.py full
4417 scripts/config.py unset MBEDTLS_HAVE_ASM
4418 scripts/config.py unset MBEDTLS_PADLOCK_C
4419 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
4420 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
4421
4422 msg "test: i386, make, gcc, no asm (ASan build)"
4423 make test
4424}
4425support_test_m32_no_asm () {
4426 case $(uname -m) in
4427 amd64|x86_64) true;;
4428 *) false;;
4429 esac
4430}
4431
4432component_test_m32_o2 () {
4433 # Build with optimization, to use the i386 specific inline assembly
4434 # and go faster for tests.
4435 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
4436 scripts/config.py full
4437 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
4438 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
4439
4440 msg "test: i386, make, gcc -O2 (ASan build)"
4441 make test
4442
4443 msg "test ssl-opt.sh, i386, make, gcc-O2"
4444 tests/ssl-opt.sh
4445}
4446support_test_m32_o2 () {
4447 support_test_m32_no_asm "$@"
4448}
4449
4450component_test_m32_everest () {
4451 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
4452 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
4453 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
4454 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
4455
4456 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
4457 make test
4458
4459 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
4460 tests/ssl-opt.sh -f ECDH
4461
4462 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
4463 # Exclude some symmetric ciphers that are redundant here to gain time.
4464 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
4465}
4466support_test_m32_everest () {
4467 support_test_m32_no_asm "$@"
4468}
4469
4470component_test_mx32 () {
4471 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
4472 scripts/config.py full
4473 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
4474
4475 msg "test: 64-bit ILP32, make, gcc"
4476 make test
4477}
4478support_test_mx32 () {
4479 case $(uname -m) in
4480 amd64|x86_64) true;;
4481 *) false;;
4482 esac
4483}
4484
4485component_test_min_mpi_window_size () {
4486 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
4487 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
4488 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
4489 make
4490
4491 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
4492 make test
4493}
4494
4495component_test_have_int32 () {
4496 msg "build: gcc, force 32-bit bignum limbs"
4497 scripts/config.py unset MBEDTLS_HAVE_ASM
4498 scripts/config.py unset MBEDTLS_AESNI_C
4499 scripts/config.py unset MBEDTLS_PADLOCK_C
4500 scripts/config.py unset MBEDTLS_AESCE_C
4501 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
4502
4503 msg "test: gcc, force 32-bit bignum limbs"
4504 make test
4505}
4506
4507component_test_have_int64 () {
4508 msg "build: gcc, force 64-bit bignum limbs"
4509 scripts/config.py unset MBEDTLS_HAVE_ASM
4510 scripts/config.py unset MBEDTLS_AESNI_C
4511 scripts/config.py unset MBEDTLS_PADLOCK_C
4512 scripts/config.py unset MBEDTLS_AESCE_C
4513 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
4514
4515 msg "test: gcc, force 64-bit bignum limbs"
4516 make test
4517}
4518
4519component_test_have_int32_cmake_new_bignum () {
4520 msg "build: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
4521 scripts/config.py unset MBEDTLS_HAVE_ASM
4522 scripts/config.py unset MBEDTLS_AESNI_C
4523 scripts/config.py unset MBEDTLS_PADLOCK_C
4524 scripts/config.py unset MBEDTLS_AESCE_C
4525 scripts/config.py set MBEDTLS_TEST_HOOKS
4526 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
4527 make CC=gcc CFLAGS="$ASAN_CFLAGS -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32" LDFLAGS="$ASAN_CFLAGS"
4528
4529 msg "test: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
4530 make test
4531}
4532
4533component_test_no_udbl_division () {
4534 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
4535 scripts/config.py full
4536 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
4537 make CFLAGS='-Werror -O1'
4538
4539 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
4540 make test
4541}
4542
4543component_test_no_64bit_multiplication () {
4544 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
4545 scripts/config.py full
4546 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
4547 make CFLAGS='-Werror -O1'
4548
4549 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
4550 make test
4551}
4552
4553component_test_no_strings () {
4554 msg "build: no strings" # ~10s
4555 scripts/config.py full
4556 # Disable options that activate a large amount of string constants.
4557 scripts/config.py unset MBEDTLS_DEBUG_C
4558 scripts/config.py unset MBEDTLS_ERROR_C
4559 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
4560 scripts/config.py unset MBEDTLS_VERSION_FEATURES
4561 make CFLAGS='-Werror -Os'
4562
4563 msg "test: no strings" # ~ 10s
4564 make test
4565}
4566
4567component_test_no_x509_info () {
4568 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
4569 scripts/config.pl full
4570 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
4571 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
4572 make CFLAGS='-Werror -O2'
4573
4574 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
4575 make test
4576
4577 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
4578 tests/ssl-opt.sh
4579}
4580
4581component_build_arm_none_eabi_gcc () {
4582 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
4583 scripts/config.py baremetal
4584 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra -O1' lib
4585
4586 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
4587 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
4588}
4589
4590component_build_arm_linux_gnueabi_gcc_arm5vte () {
4591 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
4592 scripts/config.py baremetal
4593 # Build for a target platform that's close to what Debian uses
4594 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
4595 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
4596 # Build everything including programs, see for example
4597 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
4598 make CC="${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc" AR="${ARM_LINUX_GNUEABI_GCC_PREFIX}ar" CFLAGS='-Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te'
4599
4600 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
4601 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t library/*.o
4602}
4603support_build_arm_linux_gnueabi_gcc_arm5vte () {
4604 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
4605}
4606
4607component_build_arm_none_eabi_gcc_arm5vte () {
4608 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
4609 scripts/config.py baremetal
4610 # This is an imperfect substitute for
4611 # component_build_arm_linux_gnueabi_gcc_arm5vte
4612 # in case the gcc-arm-linux-gnueabi toolchain is not available
4613 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" CFLAGS='-std=c99 -Werror -Wall -Wextra -march=armv5te -O1' LDFLAGS='-march=armv5te' SHELL='sh -x' lib
4614
4615 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
4616 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
4617}
4618
4619component_build_arm_none_eabi_gcc_m0plus () {
4620 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
4621 scripts/config.py baremetal_size
4622 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra -mthumb -mcpu=cortex-m0plus -Os' lib
4623
4624 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
4625 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
4626 for lib in library/*.a; do
4627 echo "$lib:"
4628 ${ARM_NONE_EABI_GCC_PREFIX}size -t $lib | grep TOTALS
4629 done
4630}
4631
4632component_build_arm_none_eabi_gcc_no_udbl_division () {
4633 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
4634 scripts/config.py baremetal
4635 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
4636 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -Wall -Wextra' lib
4637 echo "Checking that software 64-bit division is not required"
4638 not grep __aeabi_uldiv library/*.o
4639}
4640
4641component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
4642 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
4643 scripts/config.py baremetal
4644 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
4645 make CC="${ARM_NONE_EABI_GCC_PREFIX}gcc" AR="${ARM_NONE_EABI_GCC_PREFIX}ar" LD="${ARM_NONE_EABI_GCC_PREFIX}ld" CFLAGS='-std=c99 -Werror -O1 -march=armv6-m -mthumb' lib
4646 echo "Checking that software 64-bit multiplication is not required"
4647 not grep __aeabi_lmul library/*.o
4648}
4649
4650component_build_arm_clang_thumb () {
4651 # ~ 30s
4652
4653 scripts/config.py baremetal
4654
4655 msg "build: clang thumb 2, make"
4656 make clean
4657 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
4658
4659 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
4660 msg "build: clang thumb 1 -O0, make"
4661 make clean
4662 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
4663
4664 msg "build: clang thumb 1 -Os, make"
4665 make clean
4666 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
4667}
4668
4669component_build_armcc () {
4670 msg "build: ARM Compiler 5"
4671 scripts/config.py baremetal
4672 # armc[56] don't support SHA-512 intrinsics
4673 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
4674
4675 # older versions of armcc/armclang don't support AESCE_C on 32-bit Arm
4676 scripts/config.py unset MBEDTLS_AESCE_C
4677
4678 # Stop armclang warning about feature detection for A64_CRYPTO.
4679 # With this enabled, the library does build correctly under armclang,
4680 # but in baremetal builds (as tested here), feature detection is
4681 # unavailable, and the user is notified via a #warning. So enabling
4682 # this feature would prevent us from building with -Werror on
4683 # armclang. Tracked in #7198.
4684 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
4685
4686 scripts/config.py set MBEDTLS_HAVE_ASM
4687
4688 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
4689
4690 msg "size: ARM Compiler 5"
4691 "$ARMC5_FROMELF" -z library/*.o
4692
4693 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
4694
4695 # ARM Compiler 6 - Target ARMv7-A
4696 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-a"
4697
4698 # ARM Compiler 6 - Target ARMv7-M
4699 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m"
4700
4701 # ARM Compiler 6 - Target ARMv7-M+DSP
4702 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m+dsp"
4703
4704 # ARM Compiler 6 - Target ARMv8-A - AArch32
4705 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8.2-a"
4706
4707 # ARM Compiler 6 - Target ARMv8-M
4708 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
4709
4710 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
4711 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
4712
4713 # ARM Compiler 6 - Target Cortex-M0
4714 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
4715
4716 # ARM Compiler 6 - Target ARMv8.2-A - AArch64
4717 #
4718 # Re-enable MBEDTLS_AESCE_C as this should be supported by the version of armclang
4719 # that we have in our CI
4720 scripts/config.py set MBEDTLS_AESCE_C
4721 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
4722}
4723
4724support_build_armcc () {
4725 armc5_cc="$ARMC5_BIN_DIR/armcc"
4726 armc6_cc="$ARMC6_BIN_DIR/armclang"
4727 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
4728}
4729
4730component_test_tls12_only () {
4731 msg "build: default config without MBEDTLS_SSL_PROTO_TLS1_3, cmake, gcc, ASan"
4732 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4733 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4734 make
4735
4736 msg "test: main suites (inc. selftests) (ASan build)"
4737 make test
4738
4739 msg "test: ssl-opt.sh (ASan build)"
4740 tests/ssl-opt.sh
4741
4742 msg "test: compat.sh (ASan build)"
4743 tests/compat.sh
4744}
4745
4746component_test_tls13_only () {
4747 msg "build: default config without MBEDTLS_SSL_PROTO_TLS1_2"
4748 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
4749 scripts/config.py set MBEDTLS_SSL_RECORD_SIZE_LIMIT
4750 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4751
4752 msg "test: TLS 1.3 only, all key exchange modes enabled"
4753 make test
4754
4755 msg "ssl-opt.sh: TLS 1.3 only, all key exchange modes enabled"
4756 tests/ssl-opt.sh
4757}
4758
4759component_test_tls13_only_psk () {
4760 msg "build: TLS 1.3 only from default, only PSK key exchange mode"
4761 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4762 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
4763 scripts/config.py unset MBEDTLS_ECDH_C
4764 scripts/config.py unset MBEDTLS_DHM_C
4765 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
4766 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
4767 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
4768 scripts/config.py unset MBEDTLS_ECDSA_C
4769 scripts/config.py unset MBEDTLS_PKCS1_V21
4770 scripts/config.py unset MBEDTLS_PKCS7_C
4771 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
4772 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4773
4774 msg "test_suite_ssl: TLS 1.3 only, only PSK key exchange mode enabled"
4775 cd tests; ./test_suite_ssl; cd ..
4776
4777 msg "ssl-opt.sh: TLS 1.3 only, only PSK key exchange mode enabled"
4778 tests/ssl-opt.sh
4779}
4780
4781component_test_tls13_only_ephemeral () {
4782 msg "build: TLS 1.3 only from default, only ephemeral key exchange mode"
4783 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4784 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
4785 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
4786 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4787
4788 msg "test_suite_ssl: TLS 1.3 only, only ephemeral key exchange mode"
4789 cd tests; ./test_suite_ssl; cd ..
4790
4791 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral key exchange mode"
4792 tests/ssl-opt.sh
4793}
4794
4795component_test_tls13_only_ephemeral_ffdh () {
4796 msg "build: TLS 1.3 only from default, only ephemeral ffdh key exchange mode"
4797 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4798 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
4799 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
4800 scripts/config.py unset MBEDTLS_ECDH_C
4801
4802 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4803
4804 msg "test_suite_ssl: TLS 1.3 only, only ephemeral ffdh key exchange mode"
4805 cd tests; ./test_suite_ssl; cd ..
4806
4807 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral ffdh key exchange mode"
4808 tests/ssl-opt.sh
4809}
4810
4811component_test_tls13_only_psk_ephemeral () {
4812 msg "build: TLS 1.3 only from default, only PSK ephemeral key exchange mode"
4813 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4814 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4815 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
4816 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
4817 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
4818 scripts/config.py unset MBEDTLS_ECDSA_C
4819 scripts/config.py unset MBEDTLS_PKCS1_V21
4820 scripts/config.py unset MBEDTLS_PKCS7_C
4821 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
4822 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4823
4824 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral key exchange mode"
4825 cd tests; ./test_suite_ssl; cd ..
4826
4827 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral key exchange mode"
4828 tests/ssl-opt.sh
4829}
4830
4831component_test_tls13_only_psk_ephemeral_ffdh () {
4832 msg "build: TLS 1.3 only from default, only PSK ephemeral ffdh key exchange mode"
4833 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4834 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4835 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
4836 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
4837 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
4838 scripts/config.py unset MBEDTLS_ECDSA_C
4839 scripts/config.py unset MBEDTLS_PKCS1_V21
4840 scripts/config.py unset MBEDTLS_PKCS7_C
4841 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
4842 scripts/config.py unset MBEDTLS_ECDH_C
4843 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4844
4845 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
4846 cd tests; ./test_suite_ssl; cd ..
4847
4848 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
4849 tests/ssl-opt.sh
4850}
4851
4852component_test_tls13_only_psk_all () {
4853 msg "build: TLS 1.3 only from default, without ephemeral key exchange mode"
4854 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4855 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
4856 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
4857 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
4858 scripts/config.py unset MBEDTLS_ECDSA_C
4859 scripts/config.py unset MBEDTLS_PKCS1_V21
4860 scripts/config.py unset MBEDTLS_PKCS7_C
4861 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
4862 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4863
4864 msg "test_suite_ssl: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
4865 cd tests; ./test_suite_ssl; cd ..
4866
4867 msg "ssl-opt.sh: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
4868 tests/ssl-opt.sh
4869}
4870
4871component_test_tls13_only_ephemeral_all () {
4872 msg "build: TLS 1.3 only from default, without PSK key exchange mode"
4873 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4874 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
4875 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4876
4877 msg "test_suite_ssl: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
4878 cd tests; ./test_suite_ssl; cd ..
4879
4880 msg "ssl-opt.sh: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
4881 tests/ssl-opt.sh
4882}
4883
4884component_test_tls13_no_padding () {
4885 msg "build: default config plus early data minus padding"
4886 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
4887 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
4888 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
4889 make
4890 msg "test: default config plus early data minus padding"
4891 make test
4892 msg "ssl-opt.sh (TLS 1.3 no padding)"
4893 tests/ssl-opt.sh
4894}
4895
4896component_test_tls13_no_compatibility_mode () {
4897 msg "build: default config plus early data minus middlebox compatibility mode"
4898 scripts/config.py unset MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
4899 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
4900 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
4901 make
4902 msg "test: default config plus early data minus middlebox compatibility mode"
4903 make test
4904 msg "ssl-opt.sh (TLS 1.3 no compatibility mode)"
4905 tests/ssl-opt.sh
4906}
4907
4908component_test_full_minus_session_tickets () {
4909 msg "build: full config without session tickets"
4910 scripts/config.py full
4911 scripts/config.py unset MBEDTLS_SSL_SESSION_TICKETS
4912 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
4913 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4914 make
4915 msg "test: full config without session tickets"
4916 make test
4917 msg "ssl-opt.sh (full config without session tickets)"
4918 tests/ssl-opt.sh
4919}
4920
Minos Galanakisf7d1cb02024-07-30 17:25:31 +01004921
Minos Galanakisf7d1cb02024-07-30 17:25:31 +01004922
Minos Galanakisf7d1cb02024-07-30 17:25:31 +01004923
4924component_test_memsan () {
4925 msg "build: MSan (clang)" # ~ 1 min 20s
4926 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
4927 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
4928 make
4929
4930 msg "test: main suites (MSan)" # ~ 10s
4931 make test
4932
4933 msg "test: metatests (MSan)"
4934 tests/scripts/run-metatests.sh any msan
4935
4936 msg "program demos (MSan)" # ~20s
4937 tests/scripts/run_demos.py
4938
4939 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
4940 tests/ssl-opt.sh
4941
4942 # Optional part(s)
4943
4944 if [ "$MEMORY" -gt 0 ]; then
4945 msg "test: compat.sh (MSan)" # ~ 6 min 20s
4946 tests/compat.sh
4947 fi
4948}
4949
4950component_release_test_valgrind () {
4951 msg "build: Release (clang)"
4952 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
4953 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
4954 make
4955
4956 msg "test: main suites, Valgrind (default config)"
4957 make memcheck
4958
4959 # Optional parts (slow; currently broken on OS X because programs don't
4960 # seem to receive signals under valgrind on OS X).
4961 # These optional parts don't run on the CI.
4962 if [ "$MEMORY" -gt 0 ]; then
4963 msg "test: ssl-opt.sh --memcheck (default config)"
4964 tests/ssl-opt.sh --memcheck
4965 fi
4966
4967 if [ "$MEMORY" -gt 1 ]; then
4968 msg "test: compat.sh --memcheck (default config)"
4969 tests/compat.sh --memcheck
4970 fi
4971
4972 if [ "$MEMORY" -gt 0 ]; then
4973 msg "test: context-info.sh --memcheck (default config)"
4974 tests/context-info.sh --memcheck
4975 fi
4976}
4977
4978component_release_test_valgrind_psa () {
4979 msg "build: Release, full (clang)"
4980 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
4981 scripts/config.py full
4982 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
4983 make
4984
4985 msg "test: main suites, Valgrind (full config)"
4986 make memcheck
4987}
4988
Minos Galanakisf7d1cb02024-07-30 17:25:31 +01004989component_test_psa_compliance () {
4990 # The arch tests build with gcc, so require use of gcc here to link properly
4991 msg "build: make, default config (out-of-box), libmbedcrypto.a only"
4992 CC=gcc make -C library libmbedcrypto.a
4993
4994 msg "unit test: test_psa_compliance.py"
4995 CC=gcc ./tests/scripts/test_psa_compliance.py
4996}
4997
4998support_test_psa_compliance () {
4999 # psa-compliance-tests only supports CMake >= 3.10.0
5000 ver="$(cmake --version)"
5001 ver="${ver#cmake version }"
5002 ver_major="${ver%%.*}"
5003
5004 ver="${ver#*.}"
5005 ver_minor="${ver%%.*}"
5006
5007 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
5008}
5009