blob: af246664de03db7f52831a67f2cd85d7c21af247 [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
3351
3352support_build_tfm_armcc () {
3353 support_build_armcc
3354}
3355
3356component_build_tfm_armcc () {
3357 # test the TF-M configuration can build cleanly with various warning flags enabled
3358 cp configs/config-tfm.h "$CONFIG_H"
3359
3360 msg "build: TF-M config, armclang armv7-m thumb2"
3361 armc6_build_test "--target=arm-arm-none-eabi -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"
3362}
3363
3364component_build_tfm () {
3365 # Check that the TF-M configuration can build cleanly with various
3366 # warning flags enabled. We don't build or run tests, since the
3367 # TF-M configuration needs a TF-M platform. A tweaked version of
3368 # the configuration that works on mainstream platforms is in
3369 # configs/config-tfm.h, tested via test-ref-configs.pl.
3370 cp configs/config-tfm.h "$CONFIG_H"
3371
3372 msg "build: TF-M config, clang, armv7-m thumb2"
3373 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"
3374
3375 msg "build: TF-M config, gcc native build"
3376 make clean
3377 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"
3378}
3379
3380# Test that the given .o file builds with all (valid) combinations of the given options.
3381#
3382# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
3383#
3384# The validator function is the name of a function to validate the combination of options.
3385# It may be "" if all combinations are valid.
3386# It receives a string containing a combination of options, as passed to the compiler,
3387# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
3388build_test_config_combos () {
3389 file=$1
3390 shift
3391 validate_options=$1
3392 shift
3393 options=("$@")
3394
3395 # clear all of the options so that they can be overridden on the clang commandline
3396 for opt in "${options[@]}"; do
3397 ./scripts/config.py unset ${opt}
3398 done
3399
3400 # enter the directory containing the target file & strip the dir from the filename
3401 cd $(dirname ${file})
3402 file=$(basename ${file})
3403
3404 # The most common issue is unused variables/functions, so ensure -Wunused is set.
3405 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
3406
3407 # Extract the command generated by the Makefile to build the target file.
3408 # This ensures that we have any include paths, macro definitions, etc
3409 # that may be applied by make.
3410 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
3411 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
3412
3413 makefile=$(TMPDIR=. mktemp)
3414 deps=""
3415
3416 len=${#options[@]}
3417 source_file=${file%.o}.c
3418
3419 targets=0
3420 echo 'include Makefile' >${makefile}
3421
3422 for ((i = 0; i < $((2**${len})); i++)); do
3423 # generate each of 2^n combinations of options
3424 # each bit of $i is used to determine if options[i] will be set or not
3425 target="t"
3426 clang_args=""
3427 for ((j = 0; j < ${len}; j++)); do
3428 if (((i >> j) & 1)); then
3429 opt=-D${options[$j]}
3430 clang_args="${clang_args} ${opt}"
3431 target="${target}${opt}"
3432 fi
3433 done
3434
3435 # if combination is not known to be invalid, add it to the makefile
3436 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
3437 cmd="${compile_cmd} ${clang_args}"
3438 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
3439
3440 deps="${deps} ${target}"
3441 ((++targets))
3442 fi
3443 done
3444
3445 echo "build_test_config_combos: ${deps}" >> ${makefile}
3446
3447 # execute all of the commands via Make (probably in parallel)
3448 make -s -f ${makefile} build_test_config_combos
3449 echo "$targets targets checked"
3450
3451 # clean up the temporary makefile
3452 rm ${makefile}
3453}
3454
3455validate_aes_config_variations () {
3456 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
3457 if [[ "$1" == *"MBEDTLS_PADLOCK_C"* ]]; then
3458 return 1
3459 fi
3460 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
3461 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
3462 return 1
3463 fi
3464 fi
3465 return 0
3466}
3467
3468component_build_aes_variations () {
3469 # 18s - around 90ms per clang invocation on M1 Pro
3470 #
3471 # aes.o has many #if defined(...) guards that intersect in complex ways.
3472 # Test that all the combinations build cleanly.
3473
3474 MBEDTLS_ROOT_DIR="$PWD"
3475 msg "build: aes.o for all combinations of relevant config options"
3476
3477 build_test_config_combos library/aes.o validate_aes_config_variations \
3478 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
3479 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
3480 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
3481 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
3482
3483 cd "$MBEDTLS_ROOT_DIR"
3484 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
3485
3486 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES,
3487 # manually set or unset those configurations to check
3488 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
3489 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
3490 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3491 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
3492 scripts/config.py unset MBEDTLS_DES_C
3493 scripts/config.py unset MBEDTLS_NIST_KW_C
3494 build_test_config_combos library/aes.o validate_aes_config_variations \
3495 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
3496 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
3497 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
3498 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
3499}
3500
3501component_test_no_platform () {
3502 # Full configuration build, without platform support, file IO and net sockets.
3503 # This should catch missing mbedtls_printf definitions, and by disabling file
3504 # IO, it should catch missing '#include <stdio.h>'
3505 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
3506 scripts/config.py full_no_platform
3507 scripts/config.py unset MBEDTLS_PLATFORM_C
3508 scripts/config.py unset MBEDTLS_NET_C
3509 scripts/config.py unset MBEDTLS_FS_IO
3510 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
3511 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
3512 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
3513 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
3514 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
3515 # to re-enable platform integration features otherwise disabled in C99 builds
3516 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
3517 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
3518}
3519
3520component_build_no_std_function () {
3521 # catch compile bugs in _uninit functions
3522 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
3523 scripts/config.py full
3524 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
3525 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
3526 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
3527 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
3528 make
3529}
3530
3531component_build_no_ssl_srv () {
3532 msg "build: full config except SSL server, make, gcc" # ~ 30s
3533 scripts/config.py full
3534 scripts/config.py unset MBEDTLS_SSL_SRV_C
3535 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
3536}
3537
3538component_build_no_ssl_cli () {
3539 msg "build: full config except SSL client, make, gcc" # ~ 30s
3540 scripts/config.py full
3541 scripts/config.py unset MBEDTLS_SSL_CLI_C
3542 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
3543}
3544
3545component_build_no_sockets () {
3546 # Note, C99 compliance can also be tested with the sockets support disabled,
3547 # as that requires a POSIX platform (which isn't the same as C99).
3548 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
3549 scripts/config.py full
3550 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
3551 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
3552 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
3553}
3554
3555component_test_memory_buffer_allocator_backtrace () {
3556 msg "build: default config with memory buffer allocator and backtrace enabled"
3557 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
3558 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
3559 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
3560 scripts/config.py set MBEDTLS_MEMORY_DEBUG
3561 cmake -DCMAKE_BUILD_TYPE:String=Release .
3562 make
3563
3564 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
3565 make test
3566}
3567
3568component_test_memory_buffer_allocator () {
3569 msg "build: default config with memory buffer allocator"
3570 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
3571 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
3572 cmake -DCMAKE_BUILD_TYPE:String=Release .
3573 make
3574
3575 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
3576 make test
3577
3578 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
3579 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
3580 tests/ssl-opt.sh -e '^DTLS proxy'
3581}
3582
3583component_test_no_max_fragment_length () {
3584 # Run max fragment length tests with MFL disabled
3585 msg "build: default config except MFL extension (ASan build)" # ~ 30s
3586 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
3587 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3588 make
3589
3590 msg "test: ssl-opt.sh, MFL-related tests"
3591 tests/ssl-opt.sh -f "Max fragment length"
3592}
3593
3594component_test_asan_remove_peer_certificate () {
3595 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
3596 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
3597 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3598 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3599 make
3600
3601 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
3602 make test
3603
3604 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
3605 tests/ssl-opt.sh
3606
3607 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
3608 tests/compat.sh
3609
3610 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
3611 tests/context-info.sh
3612}
3613
3614component_test_no_max_fragment_length_small_ssl_out_content_len () {
3615 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
3616 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
3617 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
3618 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
3619 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3620 make
3621
3622 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
3623 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
3624
3625 msg "test: context-info.sh (disabled MFL extension case)"
3626 tests/context-info.sh
3627}
3628
3629component_test_variable_ssl_in_out_buffer_len () {
3630 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
3631 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
3632 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3633 make
3634
3635 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
3636 make test
3637
3638 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
3639 tests/ssl-opt.sh
3640
3641 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
3642 tests/compat.sh
3643}
3644
3645component_test_dtls_cid_legacy () {
3646 msg "build: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled (ASan build)"
3647 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 1
3648
3649 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3650 make
3651
3652 msg "test: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy)"
3653 make test
3654
3655 msg "test: ssl-opt.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
3656 tests/ssl-opt.sh
3657
3658 msg "test: compat.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
3659 tests/compat.sh
3660}
3661
3662component_test_ssl_alloc_buffer_and_mfl () {
3663 msg "build: default config with memory buffer allocator and MFL extension"
3664 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
3665 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
3666 scripts/config.py set MBEDTLS_MEMORY_DEBUG
3667 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
3668 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
3669 cmake -DCMAKE_BUILD_TYPE:String=Release .
3670 make
3671
3672 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
3673 make test
3674
3675 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
3676 tests/ssl-opt.sh -f "Handshake memory usage"
3677}
3678
3679component_test_when_no_ciphersuites_have_mac () {
3680 msg "build: when no ciphersuites have MAC"
3681 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
3682 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3683 scripts/config.py unset MBEDTLS_CMAC_C
3684 make
3685
3686 msg "test: !MBEDTLS_SSL_SOME_SUITES_USE_MAC"
3687 make test
3688
3689 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_SUITES_USE_MAC"
3690 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
3691}
3692
3693component_test_no_date_time () {
3694 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
3695 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
3696 cmake -D CMAKE_BUILD_TYPE:String=Check .
3697 make
3698
3699 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
3700 make test
3701}
3702
3703component_test_platform_calloc_macro () {
3704 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
3705 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
3706 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
3707 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
3708 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
3709 make
3710
3711 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
3712 make test
3713}
3714
3715component_test_malloc_0_null () {
3716 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
3717 scripts/config.py full
3718 make CC=$ASAN_CC CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"$PWD/tests/configs/user-config-malloc-0-null.h\"' $ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
3719
3720 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
3721 make test
3722
3723 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
3724 # Just the calloc selftest. "make test" ran the others as part of the
3725 # test suites.
3726 programs/test/selftest calloc
3727
3728 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
3729 # Run a subset of the tests. The choice is a balance between coverage
3730 # and time (including time indirectly wasted due to flaky tests).
3731 # The current choice is to skip tests whose description includes
3732 # "proxy", which is an approximation of skipping tests that use the
3733 # UDP proxy, which tend to be slower and flakier.
3734 tests/ssl-opt.sh -e 'proxy'
3735}
3736
3737support_test_aesni () {
3738 # Check that gcc targets x86_64 (we can build AESNI), and check for
3739 # AESNI support on the host (we can run AESNI).
3740 #
3741 # The name of this function is possibly slightly misleading, but needs to align
3742 # with the name of the corresponding test, component_test_aesni.
3743 #
3744 # In principle 32-bit x86 can support AESNI, but our implementation does not
3745 # support 32-bit x86, so we check for x86-64.
3746 # We can only grep /proc/cpuinfo on Linux, so this also checks for Linux
3747 (gcc -v 2>&1 | grep Target | grep -q x86_64) &&
3748 [[ "$HOSTTYPE" == "x86_64" && "$OSTYPE" == "linux-gnu" ]] &&
3749 (lscpu | grep -qw aes)
3750}
3751
3752component_test_aesni () { # ~ 60s
3753 # This tests the two AESNI implementations (intrinsics and assembly), and also the plain C
3754 # fallback. It also tests the logic that is used to select which implementation(s) to build.
3755 #
3756 # This test does not require the host to have support for AESNI (if it doesn't, the run-time
3757 # AESNI detection will fallback to the plain C implementation, so the tests will instead
3758 # exercise the plain C impl).
3759
3760 msg "build: default config with different AES implementations"
3761 scripts/config.py set MBEDTLS_AESNI_C
3762 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
3763 scripts/config.py set MBEDTLS_HAVE_ASM
3764
3765 # test the intrinsics implementation
3766 msg "AES tests, test intrinsics"
3767 make clean
3768 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
3769 # check that we built intrinsics - this should be used by default when supported by the compiler
3770 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
3771
3772 # test the asm implementation
3773 msg "AES tests, test assembly"
3774 make clean
3775 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mno-pclmul -mno-sse2 -mno-aes'
3776 # check that we built assembly - this should be built if the compiler does not support intrinsics
3777 ./programs/test/selftest aes | grep "AESNI code" | grep -q "assembly"
3778
3779 # test the plain C implementation
3780 scripts/config.py unset MBEDTLS_AESNI_C
3781 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
3782 msg "AES tests, plain C"
3783 make clean
3784 make CC=gcc CFLAGS='-O2 -Werror'
3785 # check that there is no AESNI code present
3786 ./programs/test/selftest aes | not grep -q "AESNI code"
3787 not grep -q "AES note: using AESNI" ./programs/test/selftest
3788 grep -q "AES note: built-in implementation." ./programs/test/selftest
3789
3790 # test the intrinsics implementation
3791 scripts/config.py set MBEDTLS_AESNI_C
3792 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
3793 msg "AES tests, test AESNI only"
3794 make clean
3795 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
3796 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
3797 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
3798 grep -q "AES note: using AESNI" ./programs/test/selftest
3799 not grep -q "AES note: built-in implementation." ./programs/test/selftest
3800}
3801
3802component_test_sha3_variations () {
3803 msg "sha3 loop unroll variations"
3804
3805 # define minimal config sufficient to test SHA3
3806 cat > include/mbedtls/mbedtls_config.h << END
3807 #define MBEDTLS_SELF_TEST
3808 #define MBEDTLS_SHA3_C
3809END
3810
3811 msg "all loops unrolled"
3812 make clean
3813 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"
3814 ./tests/test_suite_shax
3815
3816 msg "all loops rolled up"
3817 make clean
3818 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"
3819 ./tests/test_suite_shax
3820}
3821
3822support_test_aesni_m32 () {
3823 support_test_m32_no_asm && (lscpu | grep -qw aes)
3824}
3825
3826component_test_aesni_m32 () { # ~ 60s
3827 # This tests are duplicated from component_test_aesni for i386 target
3828 #
3829 # AESNI intrinsic code supports i386 and assembly code does not support it.
3830
3831 msg "build: default config with different AES implementations"
3832 scripts/config.py set MBEDTLS_AESNI_C
3833 scripts/config.py set MBEDTLS_PADLOCK_C
3834 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
3835 scripts/config.py set MBEDTLS_HAVE_ASM
3836
3837 # test the intrinsics implementation with gcc
3838 msg "AES tests, test intrinsics (gcc)"
3839 make clean
3840 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra' LDFLAGS='-m32'
3841 # check that we built intrinsics - this should be used by default when supported by the compiler
3842 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
3843 grep -q "AES note: using AESNI" ./programs/test/selftest
3844 grep -q "AES note: built-in implementation." ./programs/test/selftest
3845 grep -q "AES note: using VIA Padlock" ./programs/test/selftest
3846 grep -q mbedtls_aesni_has_support ./programs/test/selftest
3847
3848 scripts/config.py set MBEDTLS_AESNI_C
3849 scripts/config.py unset MBEDTLS_PADLOCK_C
3850 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
3851 msg "AES tests, test AESNI only"
3852 make clean
3853 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
3854 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
3855 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
3856 grep -q "AES note: using AESNI" ./programs/test/selftest
3857 not grep -q "AES note: built-in implementation." ./programs/test/selftest
3858 not grep -q "AES note: using VIA Padlock" ./programs/test/selftest
3859 not grep -q mbedtls_aesni_has_support ./programs/test/selftest
3860}
3861
3862support_test_aesni_m32_clang () {
3863 # clang >= 4 is required to build with target attributes
3864 support_test_aesni_m32 && [[ $(clang_version) -ge 4 ]]
3865}
3866
3867component_test_aesni_m32_clang () {
3868
3869 scripts/config.py set MBEDTLS_AESNI_C
3870 scripts/config.py set MBEDTLS_PADLOCK_C
3871 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
3872 scripts/config.py set MBEDTLS_HAVE_ASM
3873
3874 # test the intrinsics implementation with clang
3875 msg "AES tests, test intrinsics (clang)"
3876 make clean
3877 make CC=clang CFLAGS='-m32 -Werror -Wall -Wextra' LDFLAGS='-m32'
3878 # check that we built intrinsics - this should be used by default when supported by the compiler
3879 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
3880 grep -q "AES note: using AESNI" ./programs/test/selftest
3881 grep -q "AES note: built-in implementation." ./programs/test/selftest
3882 grep -q "AES note: using VIA Padlock" ./programs/test/selftest
3883 grep -q mbedtls_aesni_has_support ./programs/test/selftest
3884}
3885
3886# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
3887component_build_aes_aesce_armcc () {
3888 msg "Build: AESCE test on arm64 platform without plain C."
3889 scripts/config.py baremetal
3890
3891 # armc[56] don't support SHA-512 intrinsics
3892 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
3893
3894 # Stop armclang warning about feature detection for A64_CRYPTO.
3895 # With this enabled, the library does build correctly under armclang,
3896 # but in baremetal builds (as tested here), feature detection is
3897 # unavailable, and the user is notified via a #warning. So enabling
3898 # this feature would prevent us from building with -Werror on
3899 # armclang. Tracked in #7198.
3900 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
3901 scripts/config.py set MBEDTLS_HAVE_ASM
3902
3903 msg "AESCE, build with default configuration."
3904 scripts/config.py set MBEDTLS_AESCE_C
3905 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
3906 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
3907
3908 msg "AESCE, build AESCE only"
3909 scripts/config.py set MBEDTLS_AESCE_C
3910 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
3911 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
3912}
3913
3914support_build_aes_armce () {
3915 # clang >= 11 is required to build with AES extensions
3916 [[ $(clang_version) -ge 11 ]]
3917}
3918
3919component_build_aes_armce () {
3920 # Test variations of AES with Armv8 crypto extensions
3921 scripts/config.py set MBEDTLS_AESCE_C
3922 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
3923
3924 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, aarch64"
3925 make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
3926
3927 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, arm"
3928 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
3929
3930 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, thumb"
3931 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
3932
3933 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
3934
3935 msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, aarch64"
3936 make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
3937
3938 msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, arm"
3939 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
3940
3941 msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, thumb"
3942 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
3943
3944 # test for presence of AES instructions
3945 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
3946 msg "clang, test A32 crypto instructions built"
3947 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
3948 grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
3949 msg "clang, test T32 crypto instructions built"
3950 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
3951 grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
3952 msg "clang, test aarch64 crypto instructions built"
3953 make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
3954 grep -E 'aes[a-z]+\s*[qv]' library/aesce.o
3955
3956 # test for absence of AES instructions
3957 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
3958 scripts/config.py unset MBEDTLS_AESCE_C
3959 msg "clang, test A32 crypto instructions not built"
3960 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
3961 not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
3962 msg "clang, test T32 crypto instructions not built"
3963 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
3964 not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
3965 msg "clang, test aarch64 crypto instructions not built"
3966 make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
3967 not grep -E 'aes[a-z]+\s*[qv]' library/aesce.o
3968}
3969
3970support_build_sha_armce () {
3971 # clang >= 4 is required to build with SHA extensions
3972 [[ $(clang_version) -ge 4 ]]
3973}
3974
3975component_build_sha_armce () {
3976 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
3977
3978
3979 # Test variations of SHA256 Armv8 crypto extensions
3980 scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
3981 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, aarch64"
3982 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
3983 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, arm"
3984 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
3985 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
3986
3987
3988 # test the deprecated form of the config option
3989 scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
3990 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY clang, thumb"
3991 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
3992 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
3993
3994 scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
3995 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT clang, aarch64"
3996 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
3997 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
3998
3999
4000 # test the deprecated form of the config option
4001 scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
4002 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, arm"
4003 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -std=c99"
4004 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, thumb"
4005 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
4006 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
4007
4008
4009 # examine the disassembly for presence of SHA instructions
4010 for opt in MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT; do
4011 scripts/config.py set ${opt}
4012 msg "${opt} clang, test A32 crypto instructions built"
4013 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
4014 grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4015
4016 msg "${opt} clang, test T32 crypto instructions built"
4017 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
4018 grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4019
4020 msg "${opt} clang, test aarch64 crypto instructions built"
4021 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
4022 grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.o
4023 scripts/config.py unset ${opt}
4024 done
4025
4026
4027 # examine the disassembly for absence of SHA instructions
4028 msg "clang, test A32 crypto instructions not built"
4029 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
4030 not grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4031
4032 msg "clang, test T32 crypto instructions not built"
4033 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
4034 not grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4035
4036 msg "clang, test aarch64 crypto instructions not built"
4037 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
4038 not grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.o
4039}
4040
4041# For timebeing, no VIA Padlock platform available.
4042component_build_aes_via_padlock () {
4043
4044 msg "AES:VIA PadLock, build with default configuration."
4045 scripts/config.py unset MBEDTLS_AESNI_C
4046 scripts/config.py set MBEDTLS_PADLOCK_C
4047 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4048 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
4049 grep -q mbedtls_padlock_has_support ./programs/test/selftest
4050
4051}
4052
4053support_build_aes_via_padlock_only () {
4054 ( [ "$MBEDTLS_TEST_PLATFORM" == "Linux-x86_64" ] || \
4055 [ "$MBEDTLS_TEST_PLATFORM" == "Linux-amd64" ] ) && \
4056 [ "`dpkg --print-foreign-architectures`" == "i386" ]
4057}
4058
4059support_build_aes_aesce_armcc () {
4060 support_build_armcc
4061}
4062
4063component_test_aes_only_128_bit_keys () {
4064 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
4065 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4066 scripts/config.py unset MBEDTLS_PADLOCK_C
4067
4068 make CFLAGS='-O2 -Werror -Wall -Wextra'
4069
4070 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
4071 make test
4072}
4073
4074component_test_no_ctr_drbg_aes_only_128_bit_keys () {
4075 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
4076 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4077 scripts/config.py unset MBEDTLS_CTR_DRBG_C
4078 scripts/config.py unset MBEDTLS_PADLOCK_C
4079
4080 make CC=clang CFLAGS='-Werror -Wall -Wextra'
4081
4082 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
4083 make test
4084}
4085
4086component_test_aes_only_128_bit_keys_have_builtins () {
4087 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4088 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4089 scripts/config.py unset MBEDTLS_PADLOCK_C
4090 scripts/config.py unset MBEDTLS_AESNI_C
4091 scripts/config.py unset MBEDTLS_AESCE_C
4092
4093 make CFLAGS='-O2 -Werror -Wall -Wextra'
4094
4095 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4096 make test
4097
4098 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4099 programs/test/selftest
4100}
4101
4102component_test_gcm_largetable () {
4103 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
4104 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
4105 scripts/config.py unset MBEDTLS_PADLOCK_C
4106 scripts/config.py unset MBEDTLS_AESNI_C
4107 scripts/config.py unset MBEDTLS_AESCE_C
4108
4109 make CFLAGS='-O2 -Werror -Wall -Wextra'
4110
4111 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
4112 make test
4113}
4114
4115component_test_aes_fewer_tables () {
4116 msg "build: default config with AES_FEWER_TABLES enabled"
4117 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
4118 make CFLAGS='-O2 -Werror -Wall -Wextra'
4119
4120 msg "test: AES_FEWER_TABLES"
4121 make test
4122}
4123
4124component_test_aes_rom_tables () {
4125 msg "build: default config with AES_ROM_TABLES enabled"
4126 scripts/config.py set MBEDTLS_AES_ROM_TABLES
4127 make CFLAGS='-O2 -Werror -Wall -Wextra'
4128
4129 msg "test: AES_ROM_TABLES"
4130 make test
4131}
4132
4133component_test_aes_fewer_tables_and_rom_tables () {
4134 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
4135 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
4136 scripts/config.py set MBEDTLS_AES_ROM_TABLES
4137 make CFLAGS='-O2 -Werror -Wall -Wextra'
4138
4139 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
4140 make test
4141}
4142
4143# helper for common_block_cipher_no_decrypt() which:
4144# - enable/disable the list of config options passed from -s/-u respectively.
4145# - build
4146# - test for tests_suite_xxx
4147# - selftest
4148#
4149# Usage: helper_block_cipher_no_decrypt_build_test
4150# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
4151# Options: -s set_opts the list of config options to enable
4152# -u unset_opts the list of config options to disable
4153# -c cflags the list of options passed to CFLAGS
4154# -l ldflags the list of options passed to LDFLAGS
4155helper_block_cipher_no_decrypt_build_test () {
4156 while [ $# -gt 0 ]; do
4157 case "$1" in
4158 -s)
4159 shift; local set_opts="$1";;
4160 -u)
4161 shift; local unset_opts="$1";;
4162 -c)
4163 shift; local cflags="-Werror -Wall -Wextra $1";;
4164 -l)
4165 shift; local ldflags="$1";;
4166 esac
4167 shift
4168 done
4169 set_opts="${set_opts:-}"
4170 unset_opts="${unset_opts:-}"
4171 cflags="${cflags:-}"
4172 ldflags="${ldflags:-}"
4173
4174 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
4175 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
4176
4177 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
4178 make clean
4179 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
4180
4181 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
4182 not grep mbedtls_aes_setkey_dec library/aes.o
4183 not grep mbedtls_aria_setkey_dec library/aria.o
4184 not grep mbedtls_camellia_setkey_dec library/camellia.o
4185 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
4186 not grep mbedtls_internal_aes_decrypt library/aes.o
4187 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
4188 not grep mbedtls_aesni_inverse_key library/aesni.o
4189
4190 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
4191 make test
4192
4193 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
4194 programs/test/selftest
4195}
4196
4197# This is a common configuration function used in:
4198# - component_test_block_cipher_no_decrypt_aesni_legacy()
4199# - component_test_block_cipher_no_decrypt_aesni_use_psa()
4200# in order to test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics,
4201# AESNI assembly and AES C implementation on x86_64 and with AESNI intrinsics
4202# on x86.
4203common_block_cipher_no_decrypt () {
4204 # test AESNI intrinsics
4205 helper_block_cipher_no_decrypt_build_test \
4206 -s "MBEDTLS_AESNI_C" \
4207 -c "-mpclmul -msse2 -maes"
4208
4209 # test AESNI assembly
4210 helper_block_cipher_no_decrypt_build_test \
4211 -s "MBEDTLS_AESNI_C" \
4212 -c "-mno-pclmul -mno-sse2 -mno-aes"
4213
4214 # test AES C implementation
4215 helper_block_cipher_no_decrypt_build_test \
4216 -u "MBEDTLS_AESNI_C"
4217
4218 # test AESNI intrinsics for i386 target
4219 helper_block_cipher_no_decrypt_build_test \
4220 -s "MBEDTLS_AESNI_C" \
4221 -c "-m32 -mpclmul -msse2 -maes" \
4222 -l "-m32"
4223}
4224
4225# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
4226# usage: 0: no PSA crypto configuration
4227# 1: use PSA crypto configuration
4228config_block_cipher_no_decrypt () {
4229 use_psa=$1
4230
4231 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
4232 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
4233 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
4234 scripts/config.py unset MBEDTLS_DES_C
4235 scripts/config.py unset MBEDTLS_NIST_KW_C
4236
4237 if [ "$use_psa" -eq 1 ]; then
4238 # Enable support for cryptographic mechanisms through the PSA API.
4239 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
4240 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
4241 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
4242 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
4243 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
4244 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
4245 fi
4246}
4247
4248component_test_block_cipher_no_decrypt_aesni () {
4249 # This consistently causes an llvm crash on clang 3.8, so use gcc
4250 export CC=gcc
4251 config_block_cipher_no_decrypt 0
4252 common_block_cipher_no_decrypt
4253}
4254
4255component_test_block_cipher_no_decrypt_aesni_use_psa () {
4256 # This consistently causes an llvm crash on clang 3.8, so use gcc
4257 export CC=gcc
4258 config_block_cipher_no_decrypt 1
4259 common_block_cipher_no_decrypt
4260}
4261
4262support_test_block_cipher_no_decrypt_aesce_armcc () {
4263 support_build_armcc
4264}
4265
4266component_test_block_cipher_no_decrypt_aesce_armcc () {
4267 scripts/config.py baremetal
4268
4269 # armc[56] don't support SHA-512 intrinsics
4270 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
4271
4272 # Stop armclang warning about feature detection for A64_CRYPTO.
4273 # With this enabled, the library does build correctly under armclang,
4274 # but in baremetal builds (as tested here), feature detection is
4275 # unavailable, and the user is notified via a #warning. So enabling
4276 # this feature would prevent us from building with -Werror on
4277 # armclang. Tracked in #7198.
4278 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
4279 scripts/config.py set MBEDTLS_HAVE_ASM
4280
4281 config_block_cipher_no_decrypt 1
4282
4283 # test AESCE baremetal build
4284 scripts/config.py set MBEDTLS_AESCE_C
4285 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
4286 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
4287
4288 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
4289 not grep mbedtls_aes_setkey_dec library/aes.o
4290 not grep mbedtls_aria_setkey_dec library/aria.o
4291 not grep mbedtls_camellia_setkey_dec library/camellia.o
4292 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
4293 not grep mbedtls_internal_aes_decrypt library/aes.o
4294 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
4295 not grep mbedtls_aesce_inverse_key library/aesce.o
4296 not grep aesce_decrypt_block library/aesce.o
4297}
4298
4299component_test_ctr_drbg_aes_256_sha_256 () {
4300 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4301 scripts/config.py full
4302 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4303 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
4304 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
4305 make
4306
4307 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4308 make test
4309}
4310
4311component_test_ctr_drbg_aes_128_sha_512 () {
4312 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
4313 scripts/config.py full
4314 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4315 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
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 (ASan build)"
4320 make test
4321}
4322
4323component_test_ctr_drbg_aes_128_sha_256 () {
4324 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4325 scripts/config.py full
4326 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4327 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
4328 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
4329 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
4330 make
4331
4332 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4333 make test
4334}
4335
4336component_test_se_default () {
4337 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
4338 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
4339 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
4340
4341 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
4342 make test
4343}
4344
4345component_test_psa_crypto_drivers () {
4346 msg "build: full + test drivers dispatching to builtins"
4347 scripts/config.py full
4348 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
4349 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
4350 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
4351 loc_cflags="${loc_cflags} -I../tests/include -O2"
4352
4353 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
4354
4355 msg "test: full + test drivers dispatching to builtins"
4356 make test
4357}
4358
4359component_test_make_shared () {
4360 msg "build/test: make shared" # ~ 40s
4361 make SHARED=1 all check
4362 ldd programs/util/strerror | grep libmbedcrypto
4363 programs/test/dlopen_demo.sh
4364}
4365
4366component_test_cmake_shared () {
4367 msg "build/test: cmake shared" # ~ 2min
4368 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
4369 make
4370 ldd programs/util/strerror | grep libmbedcrypto
4371 make test
4372 programs/test/dlopen_demo.sh
4373}
4374
4375test_build_opt () {
4376 info=$1 cc=$2; shift 2
4377 $cc --version
4378 for opt in "$@"; do
4379 msg "build/test: $cc $opt, $info" # ~ 30s
4380 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
4381 # We're confident enough in compilers to not run _all_ the tests,
4382 # but at least run the unit tests. In particular, runs with
4383 # optimizations use inline assembly whereas runs with -O0
4384 # skip inline assembly.
4385 make test # ~30s
4386 make clean
4387 done
4388}
4389
4390# For FreeBSD we invoke the function by name so this condition is added
4391# to disable the existing test_clang_opt function for linux.
4392if [[ $(uname) != "Linux" ]]; then
4393 component_test_clang_opt () {
4394 scripts/config.py full
4395 test_build_opt 'full config' clang -O0 -Os -O2
4396 }
4397fi
4398
4399component_test_clang_latest_opt () {
4400 scripts/config.py full
4401 test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2
4402}
4403support_test_clang_latest_opt () {
4404 type "$CLANG_LATEST" >/dev/null 2>/dev/null
4405}
4406
4407component_test_clang_earliest_opt () {
4408 scripts/config.py full
4409 test_build_opt 'full config' "$CLANG_EARLIEST" -O0
4410}
4411support_test_clang_earliest_opt () {
4412 type "$CLANG_EARLIEST" >/dev/null 2>/dev/null
4413}
4414
4415component_test_gcc_latest_opt () {
4416 scripts/config.py full
4417 test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2
4418}
4419support_test_gcc_latest_opt () {
4420 type "$GCC_LATEST" >/dev/null 2>/dev/null
4421}
4422
4423component_test_gcc_earliest_opt () {
4424 scripts/config.py full
4425 test_build_opt 'full config' "$GCC_EARLIEST" -O0
4426}
4427support_test_gcc_earliest_opt () {
4428 type "$GCC_EARLIEST" >/dev/null 2>/dev/null
4429}
4430
4431component_build_mbedtls_config_file () {
4432 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
4433 scripts/config.py -w full_config.h full
4434 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
4435 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
4436 # Make sure this feature is enabled. We'll disable it in the next phase.
4437 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
4438 make clean
4439
4440 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
4441 # In the user config, disable one feature (for simplicity, pick a feature
4442 # that nothing else depends on).
4443 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
4444 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
4445 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
4446
4447 rm -f user_config.h full_config.h
4448}
4449
4450component_build_psa_config_file () {
4451 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
4452 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
4453 cp "$CRYPTO_CONFIG_H" psa_test_config.h
4454 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
4455 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
4456 # Make sure this feature is enabled. We'll disable it in the next phase.
4457 programs/test/query_compile_time_config MBEDTLS_CMAC_C
4458 make clean
4459
4460 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
4461 # In the user config, disable one feature and its dependencies, which will
4462 # reflect on the mbedtls configuration so we can query it with
4463 # query_compile_time_config.
4464 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
4465 echo '#undef PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128' >> psa_user_config.h
4466 scripts/config.py unset MBEDTLS_CMAC_C
4467 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
4468 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
4469
4470 rm -f psa_test_config.h psa_user_config.h
4471}
4472
4473component_build_psa_alt_headers () {
4474 msg "build: make with PSA alt headers" # ~20s
4475
4476 # Generate alternative versions of the substitutable headers with the
4477 # same content except different include guards.
4478 make -C tests include/alt-extra/psa/crypto_platform_alt.h include/alt-extra/psa/crypto_struct_alt.h
4479
4480 # Build the library and some programs.
4481 # Don't build the fuzzers to avoid having to go through hoops to set
4482 # a correct include path for programs/fuzz/Makefile.
4483 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
4484 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\"'"
4485
4486 # Check that we're getting the alternative include guards and not the
4487 # original include guards.
4488 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
4489 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
4490 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
4491 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
4492}
4493
4494component_test_m32_no_asm () {
4495 # Build without assembly, so as to use portable C code (in a 32-bit
4496 # build) and not the i386-specific inline assembly.
4497 #
4498 # Note that we require gcc, because clang Asan builds fail to link for
4499 # this target (cannot find libclang_rt.lsan-i386.a - this is a known clang issue).
4500 msg "build: i386, make, gcc, no asm (ASan build)" # ~ 30s
4501 scripts/config.py full
4502 scripts/config.py unset MBEDTLS_HAVE_ASM
4503 scripts/config.py unset MBEDTLS_PADLOCK_C
4504 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
4505 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
4506
4507 msg "test: i386, make, gcc, no asm (ASan build)"
4508 make test
4509}
4510support_test_m32_no_asm () {
4511 case $(uname -m) in
4512 amd64|x86_64) true;;
4513 *) false;;
4514 esac
4515}
4516
4517component_test_m32_o2 () {
4518 # Build with optimization, to use the i386 specific inline assembly
4519 # and go faster for tests.
4520 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
4521 scripts/config.py full
4522 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
4523 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
4524
4525 msg "test: i386, make, gcc -O2 (ASan build)"
4526 make test
4527
4528 msg "test ssl-opt.sh, i386, make, gcc-O2"
4529 tests/ssl-opt.sh
4530}
4531support_test_m32_o2 () {
4532 support_test_m32_no_asm "$@"
4533}
4534
4535component_test_m32_everest () {
4536 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
4537 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
4538 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
4539 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
4540
4541 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
4542 make test
4543
4544 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
4545 tests/ssl-opt.sh -f ECDH
4546
4547 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
4548 # Exclude some symmetric ciphers that are redundant here to gain time.
4549 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
4550}
4551support_test_m32_everest () {
4552 support_test_m32_no_asm "$@"
4553}
4554
4555component_test_mx32 () {
4556 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
4557 scripts/config.py full
4558 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
4559
4560 msg "test: 64-bit ILP32, make, gcc"
4561 make test
4562}
4563support_test_mx32 () {
4564 case $(uname -m) in
4565 amd64|x86_64) true;;
4566 *) false;;
4567 esac
4568}
4569
4570component_test_min_mpi_window_size () {
4571 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
4572 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
4573 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
4574 make
4575
4576 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
4577 make test
4578}
4579
4580component_test_have_int32 () {
4581 msg "build: gcc, force 32-bit bignum limbs"
4582 scripts/config.py unset MBEDTLS_HAVE_ASM
4583 scripts/config.py unset MBEDTLS_AESNI_C
4584 scripts/config.py unset MBEDTLS_PADLOCK_C
4585 scripts/config.py unset MBEDTLS_AESCE_C
4586 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
4587
4588 msg "test: gcc, force 32-bit bignum limbs"
4589 make test
4590}
4591
4592component_test_have_int64 () {
4593 msg "build: gcc, force 64-bit bignum limbs"
4594 scripts/config.py unset MBEDTLS_HAVE_ASM
4595 scripts/config.py unset MBEDTLS_AESNI_C
4596 scripts/config.py unset MBEDTLS_PADLOCK_C
4597 scripts/config.py unset MBEDTLS_AESCE_C
4598 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
4599
4600 msg "test: gcc, force 64-bit bignum limbs"
4601 make test
4602}
4603
4604component_test_have_int32_cmake_new_bignum () {
4605 msg "build: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
4606 scripts/config.py unset MBEDTLS_HAVE_ASM
4607 scripts/config.py unset MBEDTLS_AESNI_C
4608 scripts/config.py unset MBEDTLS_PADLOCK_C
4609 scripts/config.py unset MBEDTLS_AESCE_C
4610 scripts/config.py set MBEDTLS_TEST_HOOKS
4611 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
4612 make CC=gcc CFLAGS="$ASAN_CFLAGS -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32" LDFLAGS="$ASAN_CFLAGS"
4613
4614 msg "test: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
4615 make test
4616}
4617
4618component_test_no_udbl_division () {
4619 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
4620 scripts/config.py full
4621 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
4622 make CFLAGS='-Werror -O1'
4623
4624 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
4625 make test
4626}
4627
4628component_test_no_64bit_multiplication () {
4629 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
4630 scripts/config.py full
4631 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
4632 make CFLAGS='-Werror -O1'
4633
4634 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
4635 make test
4636}
4637
4638component_test_no_strings () {
4639 msg "build: no strings" # ~10s
4640 scripts/config.py full
4641 # Disable options that activate a large amount of string constants.
4642 scripts/config.py unset MBEDTLS_DEBUG_C
4643 scripts/config.py unset MBEDTLS_ERROR_C
4644 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
4645 scripts/config.py unset MBEDTLS_VERSION_FEATURES
4646 make CFLAGS='-Werror -Os'
4647
4648 msg "test: no strings" # ~ 10s
4649 make test
4650}
4651
4652component_test_no_x509_info () {
4653 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
4654 scripts/config.pl full
4655 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
4656 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
4657 make CFLAGS='-Werror -O2'
4658
4659 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
4660 make test
4661
4662 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
4663 tests/ssl-opt.sh
4664}
4665
4666component_build_arm_none_eabi_gcc () {
4667 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
4668 scripts/config.py baremetal
4669 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
4670
4671 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
4672 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
4673}
4674
4675component_build_arm_linux_gnueabi_gcc_arm5vte () {
4676 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
4677 scripts/config.py baremetal
4678 # Build for a target platform that's close to what Debian uses
4679 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
4680 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
4681 # Build everything including programs, see for example
4682 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
4683 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'
4684
4685 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
4686 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t library/*.o
4687}
4688support_build_arm_linux_gnueabi_gcc_arm5vte () {
4689 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
4690}
4691
4692component_build_arm_none_eabi_gcc_arm5vte () {
4693 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
4694 scripts/config.py baremetal
4695 # This is an imperfect substitute for
4696 # component_build_arm_linux_gnueabi_gcc_arm5vte
4697 # in case the gcc-arm-linux-gnueabi toolchain is not available
4698 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
4699
4700 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
4701 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
4702}
4703
4704component_build_arm_none_eabi_gcc_m0plus () {
4705 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
4706 scripts/config.py baremetal_size
4707 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
4708
4709 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
4710 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
4711 for lib in library/*.a; do
4712 echo "$lib:"
4713 ${ARM_NONE_EABI_GCC_PREFIX}size -t $lib | grep TOTALS
4714 done
4715}
4716
4717component_build_arm_none_eabi_gcc_no_udbl_division () {
4718 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
4719 scripts/config.py baremetal
4720 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
4721 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
4722 echo "Checking that software 64-bit division is not required"
4723 not grep __aeabi_uldiv library/*.o
4724}
4725
4726component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
4727 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
4728 scripts/config.py baremetal
4729 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
4730 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
4731 echo "Checking that software 64-bit multiplication is not required"
4732 not grep __aeabi_lmul library/*.o
4733}
4734
4735component_build_arm_clang_thumb () {
4736 # ~ 30s
4737
4738 scripts/config.py baremetal
4739
4740 msg "build: clang thumb 2, make"
4741 make clean
4742 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
4743
4744 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
4745 msg "build: clang thumb 1 -O0, make"
4746 make clean
4747 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
4748
4749 msg "build: clang thumb 1 -Os, make"
4750 make clean
4751 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
4752}
4753
4754component_build_armcc () {
4755 msg "build: ARM Compiler 5"
4756 scripts/config.py baremetal
4757 # armc[56] don't support SHA-512 intrinsics
4758 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
4759
4760 # older versions of armcc/armclang don't support AESCE_C on 32-bit Arm
4761 scripts/config.py unset MBEDTLS_AESCE_C
4762
4763 # Stop armclang warning about feature detection for A64_CRYPTO.
4764 # With this enabled, the library does build correctly under armclang,
4765 # but in baremetal builds (as tested here), feature detection is
4766 # unavailable, and the user is notified via a #warning. So enabling
4767 # this feature would prevent us from building with -Werror on
4768 # armclang. Tracked in #7198.
4769 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
4770
4771 scripts/config.py set MBEDTLS_HAVE_ASM
4772
4773 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
4774
4775 msg "size: ARM Compiler 5"
4776 "$ARMC5_FROMELF" -z library/*.o
4777
4778 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
4779
4780 # ARM Compiler 6 - Target ARMv7-A
4781 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-a"
4782
4783 # ARM Compiler 6 - Target ARMv7-M
4784 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m"
4785
4786 # ARM Compiler 6 - Target ARMv7-M+DSP
4787 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m+dsp"
4788
4789 # ARM Compiler 6 - Target ARMv8-A - AArch32
4790 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8.2-a"
4791
4792 # ARM Compiler 6 - Target ARMv8-M
4793 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
4794
4795 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
4796 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
4797
4798 # ARM Compiler 6 - Target Cortex-M0
4799 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
4800
4801 # ARM Compiler 6 - Target ARMv8.2-A - AArch64
4802 #
4803 # Re-enable MBEDTLS_AESCE_C as this should be supported by the version of armclang
4804 # that we have in our CI
4805 scripts/config.py set MBEDTLS_AESCE_C
4806 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
4807}
4808
4809support_build_armcc () {
4810 armc5_cc="$ARMC5_BIN_DIR/armcc"
4811 armc6_cc="$ARMC6_BIN_DIR/armclang"
4812 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
4813}
4814
4815component_test_tls12_only () {
4816 msg "build: default config without MBEDTLS_SSL_PROTO_TLS1_3, cmake, gcc, ASan"
4817 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4818 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4819 make
4820
4821 msg "test: main suites (inc. selftests) (ASan build)"
4822 make test
4823
4824 msg "test: ssl-opt.sh (ASan build)"
4825 tests/ssl-opt.sh
4826
4827 msg "test: compat.sh (ASan build)"
4828 tests/compat.sh
4829}
4830
4831component_test_tls13_only () {
4832 msg "build: default config without MBEDTLS_SSL_PROTO_TLS1_2"
4833 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
4834 scripts/config.py set MBEDTLS_SSL_RECORD_SIZE_LIMIT
4835 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4836
4837 msg "test: TLS 1.3 only, all key exchange modes enabled"
4838 make test
4839
4840 msg "ssl-opt.sh: TLS 1.3 only, all key exchange modes enabled"
4841 tests/ssl-opt.sh
4842}
4843
4844component_test_tls13_only_psk () {
4845 msg "build: TLS 1.3 only from default, only PSK key exchange mode"
4846 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4847 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
4848 scripts/config.py unset MBEDTLS_ECDH_C
4849 scripts/config.py unset MBEDTLS_DHM_C
4850 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
4851 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
4852 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
4853 scripts/config.py unset MBEDTLS_ECDSA_C
4854 scripts/config.py unset MBEDTLS_PKCS1_V21
4855 scripts/config.py unset MBEDTLS_PKCS7_C
4856 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
4857 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4858
4859 msg "test_suite_ssl: TLS 1.3 only, only PSK key exchange mode enabled"
4860 cd tests; ./test_suite_ssl; cd ..
4861
4862 msg "ssl-opt.sh: TLS 1.3 only, only PSK key exchange mode enabled"
4863 tests/ssl-opt.sh
4864}
4865
4866component_test_tls13_only_ephemeral () {
4867 msg "build: TLS 1.3 only from default, only ephemeral key exchange mode"
4868 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4869 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
4870 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
4871 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4872
4873 msg "test_suite_ssl: TLS 1.3 only, only ephemeral key exchange mode"
4874 cd tests; ./test_suite_ssl; cd ..
4875
4876 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral key exchange mode"
4877 tests/ssl-opt.sh
4878}
4879
4880component_test_tls13_only_ephemeral_ffdh () {
4881 msg "build: TLS 1.3 only from default, only ephemeral ffdh key exchange mode"
4882 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4883 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
4884 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
4885 scripts/config.py unset MBEDTLS_ECDH_C
4886
4887 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4888
4889 msg "test_suite_ssl: TLS 1.3 only, only ephemeral ffdh key exchange mode"
4890 cd tests; ./test_suite_ssl; cd ..
4891
4892 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral ffdh key exchange mode"
4893 tests/ssl-opt.sh
4894}
4895
4896component_test_tls13_only_psk_ephemeral () {
4897 msg "build: TLS 1.3 only from default, only PSK ephemeral key exchange mode"
4898 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4899 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4900 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
4901 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
4902 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
4903 scripts/config.py unset MBEDTLS_ECDSA_C
4904 scripts/config.py unset MBEDTLS_PKCS1_V21
4905 scripts/config.py unset MBEDTLS_PKCS7_C
4906 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
4907 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4908
4909 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral key exchange mode"
4910 cd tests; ./test_suite_ssl; cd ..
4911
4912 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral key exchange mode"
4913 tests/ssl-opt.sh
4914}
4915
4916component_test_tls13_only_psk_ephemeral_ffdh () {
4917 msg "build: TLS 1.3 only from default, only PSK ephemeral ffdh key exchange mode"
4918 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4919 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4920 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
4921 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
4922 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
4923 scripts/config.py unset MBEDTLS_ECDSA_C
4924 scripts/config.py unset MBEDTLS_PKCS1_V21
4925 scripts/config.py unset MBEDTLS_PKCS7_C
4926 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
4927 scripts/config.py unset MBEDTLS_ECDH_C
4928 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4929
4930 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
4931 cd tests; ./test_suite_ssl; cd ..
4932
4933 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
4934 tests/ssl-opt.sh
4935}
4936
4937component_test_tls13_only_psk_all () {
4938 msg "build: TLS 1.3 only from default, without ephemeral key exchange mode"
4939 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4940 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
4941 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
4942 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
4943 scripts/config.py unset MBEDTLS_ECDSA_C
4944 scripts/config.py unset MBEDTLS_PKCS1_V21
4945 scripts/config.py unset MBEDTLS_PKCS7_C
4946 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
4947 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4948
4949 msg "test_suite_ssl: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
4950 cd tests; ./test_suite_ssl; cd ..
4951
4952 msg "ssl-opt.sh: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
4953 tests/ssl-opt.sh
4954}
4955
4956component_test_tls13_only_ephemeral_all () {
4957 msg "build: TLS 1.3 only from default, without PSK key exchange mode"
4958 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4959 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
4960 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4961
4962 msg "test_suite_ssl: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
4963 cd tests; ./test_suite_ssl; cd ..
4964
4965 msg "ssl-opt.sh: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
4966 tests/ssl-opt.sh
4967}
4968
4969component_test_tls13_no_padding () {
4970 msg "build: default config plus early data minus padding"
4971 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
4972 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
4973 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
4974 make
4975 msg "test: default config plus early data minus padding"
4976 make test
4977 msg "ssl-opt.sh (TLS 1.3 no padding)"
4978 tests/ssl-opt.sh
4979}
4980
4981component_test_tls13_no_compatibility_mode () {
4982 msg "build: default config plus early data minus middlebox compatibility mode"
4983 scripts/config.py unset MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
4984 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
4985 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
4986 make
4987 msg "test: default config plus early data minus middlebox compatibility mode"
4988 make test
4989 msg "ssl-opt.sh (TLS 1.3 no compatibility mode)"
4990 tests/ssl-opt.sh
4991}
4992
4993component_test_full_minus_session_tickets () {
4994 msg "build: full config without session tickets"
4995 scripts/config.py full
4996 scripts/config.py unset MBEDTLS_SSL_SESSION_TICKETS
4997 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
4998 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4999 make
5000 msg "test: full config without session tickets"
5001 make test
5002 msg "ssl-opt.sh (full config without session tickets)"
5003 tests/ssl-opt.sh
5004}
5005
5006component_build_mingw () {
5007 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
5008 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 lib programs
5009
5010 # note Make tests only builds the tests, but doesn't run them
5011 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -maes -msse2 -mpclmul' WINDOWS_BUILD=1 tests
5012 make WINDOWS_BUILD=1 clean
5013
5014 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
5015 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 SHARED=1 lib programs
5016 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 SHARED=1 tests
5017 make WINDOWS_BUILD=1 clean
5018
5019 msg "build: Windows cross build - mingw64, make (Library only, default config without MBEDTLS_AESNI_C)" # ~ 30s
5020 ./scripts/config.py unset MBEDTLS_AESNI_C #
5021 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib
5022 make WINDOWS_BUILD=1 clean
5023}
5024support_build_mingw () {
5025 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
5026 [0-5]*|"") false;;
5027 *) true;;
5028 esac
5029}
5030
5031component_test_memsan () {
5032 msg "build: MSan (clang)" # ~ 1 min 20s
5033 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
5034 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
5035 make
5036
5037 msg "test: main suites (MSan)" # ~ 10s
5038 make test
5039
5040 msg "test: metatests (MSan)"
5041 tests/scripts/run-metatests.sh any msan
5042
5043 msg "program demos (MSan)" # ~20s
5044 tests/scripts/run_demos.py
5045
5046 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
5047 tests/ssl-opt.sh
5048
5049 # Optional part(s)
5050
5051 if [ "$MEMORY" -gt 0 ]; then
5052 msg "test: compat.sh (MSan)" # ~ 6 min 20s
5053 tests/compat.sh
5054 fi
5055}
5056
5057component_release_test_valgrind () {
5058 msg "build: Release (clang)"
5059 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
5060 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
5061 make
5062
5063 msg "test: main suites, Valgrind (default config)"
5064 make memcheck
5065
5066 # Optional parts (slow; currently broken on OS X because programs don't
5067 # seem to receive signals under valgrind on OS X).
5068 # These optional parts don't run on the CI.
5069 if [ "$MEMORY" -gt 0 ]; then
5070 msg "test: ssl-opt.sh --memcheck (default config)"
5071 tests/ssl-opt.sh --memcheck
5072 fi
5073
5074 if [ "$MEMORY" -gt 1 ]; then
5075 msg "test: compat.sh --memcheck (default config)"
5076 tests/compat.sh --memcheck
5077 fi
5078
5079 if [ "$MEMORY" -gt 0 ]; then
5080 msg "test: context-info.sh --memcheck (default config)"
5081 tests/context-info.sh --memcheck
5082 fi
5083}
5084
5085component_release_test_valgrind_psa () {
5086 msg "build: Release, full (clang)"
5087 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
5088 scripts/config.py full
5089 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
5090 make
5091
5092 msg "test: main suites, Valgrind (full config)"
5093 make memcheck
5094}
5095
5096support_test_cmake_out_of_source () {
5097 distrib_id=""
5098 distrib_ver=""
5099 distrib_ver_minor=""
5100 distrib_ver_major=""
5101
5102 # Attempt to parse lsb-release to find out distribution and version. If not
5103 # found this should fail safe (test is supported).
5104 if [[ -f /etc/lsb-release ]]; then
5105
5106 while read -r lsb_line; do
5107 case "$lsb_line" in
5108 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
5109 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
5110 esac
5111 done < /etc/lsb-release
5112
5113 distrib_ver_major="${distrib_ver%%.*}"
5114 distrib_ver="${distrib_ver#*.}"
5115 distrib_ver_minor="${distrib_ver%%.*}"
5116 fi
5117
5118 # Running the out of source CMake test on Ubuntu 16.04 using more than one
5119 # processor (as the CI does) can create a race condition whereby the build
5120 # fails to see a generated file, despite that file actually having been
5121 # generated. This problem appears to go away with 18.04 or newer, so make
5122 # the out of source tests unsupported on Ubuntu 16.04.
5123 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
5124}
5125
5126component_test_cmake_out_of_source () {
5127 # Remove existing generated files so that we use the ones cmake
5128 # generates
5129 make neat
5130
5131 msg "build: cmake 'out-of-source' build"
5132 MBEDTLS_ROOT_DIR="$PWD"
5133 mkdir "$OUT_OF_SOURCE_DIR"
5134 cd "$OUT_OF_SOURCE_DIR"
5135 # Note: Explicitly generate files as these are turned off in releases
5136 cmake -D CMAKE_BUILD_TYPE:String=Check -D GEN_FILES=ON "$MBEDTLS_ROOT_DIR"
5137 make
5138
5139 msg "test: cmake 'out-of-source' build"
5140 make test
5141 # Check that ssl-opt.sh can find the test programs.
5142 # Also ensure that there are no error messages such as
5143 # "No such file or directory", which would indicate that some required
5144 # file is missing (ssl-opt.sh tolerates the absence of some files so
5145 # may exit with status 0 but emit errors).
5146 ./tests/ssl-opt.sh -f 'Default' >ssl-opt.out 2>ssl-opt.err
5147 grep PASS ssl-opt.out
5148 cat ssl-opt.err >&2
5149 # If ssl-opt.err is non-empty, record an error and keep going.
5150 [ ! -s ssl-opt.err ]
5151 rm ssl-opt.out ssl-opt.err
5152 cd "$MBEDTLS_ROOT_DIR"
5153 rm -rf "$OUT_OF_SOURCE_DIR"
5154}
5155
5156component_test_cmake_as_subdirectory () {
5157 # Remove existing generated files so that we use the ones CMake
5158 # generates
5159 make neat
5160
5161 msg "build: cmake 'as-subdirectory' build"
5162 cd programs/test/cmake_subproject
5163 # Note: Explicitly generate files as these are turned off in releases
5164 cmake -D GEN_FILES=ON .
5165 make
5166 ./cmake_subproject
5167}
5168support_test_cmake_as_subdirectory () {
5169 support_test_cmake_out_of_source
5170}
5171
5172component_test_cmake_as_package () {
5173 # Remove existing generated files so that we use the ones CMake
5174 # generates
5175 make neat
5176
5177 msg "build: cmake 'as-package' build"
5178 cd programs/test/cmake_package
5179 cmake .
5180 make
5181 ./cmake_package
5182}
5183support_test_cmake_as_package () {
5184 support_test_cmake_out_of_source
5185}
5186
5187component_test_cmake_as_package_install () {
5188 # Remove existing generated files so that we use the ones CMake
5189 # generates
5190 make neat
5191
5192 msg "build: cmake 'as-installed-package' build"
5193 cd programs/test/cmake_package_install
5194 cmake .
5195 make
5196 ./cmake_package_install
5197}
5198support_test_cmake_as_package_install () {
5199 support_test_cmake_out_of_source
5200}
5201
5202component_build_cmake_custom_config_file () {
5203 # Make a copy of config file to use for the in-tree test
5204 cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h
5205
5206 MBEDTLS_ROOT_DIR="$PWD"
5207 mkdir "$OUT_OF_SOURCE_DIR"
5208 cd "$OUT_OF_SOURCE_DIR"
5209
5210 # Build once to get the generated files (which need an intact config file)
5211 cmake "$MBEDTLS_ROOT_DIR"
5212 make
5213
5214 msg "build: cmake with -DMBEDTLS_CONFIG_FILE"
5215 scripts/config.py -w full_config.h full
5216 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
5217 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR"
5218 make
5219
5220 msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
5221 # In the user config, disable one feature (for simplicity, pick a feature
5222 # that nothing else depends on).
5223 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
5224
5225 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR"
5226 make
5227 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5228
5229 rm -f user_config.h full_config.h
5230
5231 cd "$MBEDTLS_ROOT_DIR"
5232 rm -rf "$OUT_OF_SOURCE_DIR"
5233
5234 # Now repeat the test for an in-tree build:
5235
5236 # Restore config for the in-tree test
5237 mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H"
5238
5239 # Build once to get the generated files (which need an intact config)
5240 cmake .
5241 make
5242
5243 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE"
5244 scripts/config.py -w full_config.h full
5245 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
5246 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h .
5247 make
5248
5249 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
5250 # In the user config, disable one feature (for simplicity, pick a feature
5251 # that nothing else depends on).
5252 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
5253
5254 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h .
5255 make
5256 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5257
5258 rm -f user_config.h full_config.h
5259}
5260support_build_cmake_custom_config_file () {
5261 support_test_cmake_out_of_source
5262}
5263
5264component_build_cmake_programs_no_testing () {
5265 # Verify that the type of builds performed by oss-fuzz don't get accidentally broken
5266 msg "build: cmake with -DENABLE_PROGRAMS=ON and -DENABLE_TESTING=OFF"
5267 cmake -DENABLE_PROGRAMS=ON -DENABLE_TESTING=OFF .
5268 make
5269}
5270support_build_cmake_programs_no_testing () {
5271 support_test_cmake_out_of_source
5272}
5273
5274component_build_zeroize_checks () {
5275 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
5276
5277 scripts/config.py full
5278
5279 # Only compile - we're looking for sizeof-pointer-memaccess warnings
5280 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess"
5281}
5282
5283
5284component_test_zeroize () {
5285 # Test that the function mbedtls_platform_zeroize() is not optimized away by
5286 # different combinations of compilers and optimization flags by using an
5287 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
5288 # system in all cases that the script fails, so we must manually search the
5289 # output to check whether the pass string is present and no failure strings
5290 # were printed.
5291
5292 # Don't try to disable ASLR. We don't care about ASLR here. We do care
5293 # about a spurious message if Gdb tries and fails, so suppress that.
5294 gdb_disable_aslr=
5295 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
5296 gdb_disable_aslr='set disable-randomization off'
5297 fi
5298
5299 for optimization_flag in -O2 -O3 -Ofast -Os; do
5300 for compiler in clang gcc; do
5301 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
5302 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
5303 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
5304 grep "The buffer was correctly zeroized" test_zeroize.log
5305 not grep -i "error" test_zeroize.log
5306 rm -f test_zeroize.log
5307 make clean
5308 done
5309 done
5310}
5311
5312component_test_psa_compliance () {
5313 # The arch tests build with gcc, so require use of gcc here to link properly
5314 msg "build: make, default config (out-of-box), libmbedcrypto.a only"
5315 CC=gcc make -C library libmbedcrypto.a
5316
5317 msg "unit test: test_psa_compliance.py"
5318 CC=gcc ./tests/scripts/test_psa_compliance.py
5319}
5320
5321support_test_psa_compliance () {
5322 # psa-compliance-tests only supports CMake >= 3.10.0
5323 ver="$(cmake --version)"
5324 ver="${ver#cmake version }"
5325 ver_major="${ver%%.*}"
5326
5327 ver="${ver#*.}"
5328 ver_minor="${ver%%.*}"
5329
5330 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
5331}
5332