blob: 08194722f27d521676cbe9bec8d628f8519aa52f [file] [log] [blame]
Minos Galanakis6aab5b72024-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 Galanakisada21b02024-07-26 12:34:19 +010043
44# Helper function for controlling (start & stop) the psasim server.
45helper_psasim_server() {
46 OPERATION=$1
47 if [ "$OPERATION" == "start" ]; then
48 (
49 cd tests
50 msg "start server in tests"
51 psa-client-server/psasim/test/start_server.sh
52 msg "start server in tf-psa-crypto/tests"
53 cd ../tf-psa-crypto/tests
54 ../../tests/psa-client-server/psasim/test/start_server.sh
55 )
56 else
57 (
58 msg "terminate servers and cleanup"
59 tests/psa-client-server/psasim//test/kill_servers.sh
60
61 # Remove temporary files and logs
62 cd tests
63 rm -f psa_notify_*
64 rm -f psa_service_*
65 rm -f psa_server.log
66
67 cd ../tf-psa-crypto/tests
68 rm -f psa_notify_*
69 rm -f psa_service_*
70 rm -f psa_server.log
71 )
72 fi
73}
74
75################################################################
Minos Galanakisada21b02024-07-26 12:34:19 +010076#### Build and test many configurations and targets
77################################################################
78
79component_test_default_out_of_box () {
80 msg "build: make, default config (out-of-box)" # ~1min
81 make
82 # Disable fancy stuff
83 unset MBEDTLS_TEST_OUTCOME_FILE
84
85 msg "test: main suites make, default config (out-of-box)" # ~10s
86 make test
87
88 msg "selftest: make, default config (out-of-box)" # ~10s
89 programs/test/selftest
90
91 msg "program demos: make, default config (out-of-box)" # ~10s
92 tests/scripts/run_demos.py
93}
94
95component_test_default_cmake_gcc_asan () {
96 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
97 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
98 make
99
100 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
101 make test
102
103 msg "program demos (ASan build)" # ~10s
104 tests/scripts/run_demos.py
105
106 msg "test: selftest (ASan build)" # ~ 10s
107 programs/test/selftest
108
109 msg "test: metatests (GCC, ASan build)"
110 tests/scripts/run-metatests.sh any asan poison
111
112 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
113 tests/ssl-opt.sh
114
115 msg "test: compat.sh (ASan build)" # ~ 6 min
116 tests/compat.sh
117
118 msg "test: context-info.sh (ASan build)" # ~ 15 sec
119 tests/context-info.sh
120}
121
122component_test_default_cmake_gcc_asan_new_bignum () {
123 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
124 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
125 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
126 make
127
128 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
129 make test
130
131 msg "test: selftest (ASan build)" # ~ 10s
132 programs/test/selftest
133
134 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
135 tests/ssl-opt.sh
136
137 msg "test: compat.sh (ASan build)" # ~ 6 min
138 tests/compat.sh
139
140 msg "test: context-info.sh (ASan build)" # ~ 15 sec
141 tests/context-info.sh
142}
143
144component_test_full_cmake_gcc_asan () {
145 msg "build: full config, cmake, gcc, ASan"
146 scripts/config.py full
147 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
148 make
149
150 msg "test: main suites (inc. selftests) (full config, ASan build)"
151 make test
152
153 msg "test: selftest (full config, ASan build)" # ~ 10s
154 programs/test/selftest
155
156 msg "test: ssl-opt.sh (full config, ASan build)"
157 tests/ssl-opt.sh
158
159 # Note: the next two invocations cover all compat.sh test cases.
160 # We should use the same here and in basic-build-test.sh.
161 msg "test: compat.sh: default version (full config, ASan build)"
162 tests/compat.sh -e 'ARIA\|CHACHA'
163
164 msg "test: compat.sh: next: ARIA, Chacha (full config, ASan build)"
165 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
166
167 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
168 tests/context-info.sh
169}
170
171
172component_test_full_cmake_gcc_asan_new_bignum () {
173 msg "build: full config, cmake, gcc, ASan"
174 scripts/config.py full
175 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
176 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
177 make
178
179 msg "test: main suites (inc. selftests) (full config, new bignum, ASan)"
180 make test
181
182 msg "test: selftest (full config, new bignum, ASan)" # ~ 10s
183 programs/test/selftest
184
185 msg "test: ssl-opt.sh (full config, new bignum, ASan)"
186 tests/ssl-opt.sh
187
188 # Note: the next two invocations cover all compat.sh test cases.
189 # We should use the same here and in basic-build-test.sh.
190 msg "test: compat.sh: default version (full config, new bignum, ASan)"
191 tests/compat.sh -e 'ARIA\|CHACHA'
192
193 msg "test: compat.sh: next: ARIA, Chacha (full config, new bignum, ASan)"
194 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
195
196 msg "test: context-info.sh (full config, new bignum, ASan)" # ~ 15 sec
197 tests/context-info.sh
198}
199
Minos Galanakisada21b02024-07-26 12:34:19 +0100200component_test_no_rsa_key_pair_generation() {
201 msg "build: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
202 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
203 scripts/config.py unset MBEDTLS_GENPRIME
204 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
205 make
206
207 msg "test: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
208 make test
209}
210
211component_test_ref_configs () {
212 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
213 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
214 # want to re-generate generated files that depend on it, quite correctly.
215 # However this doesn't work as the generation script expects a specific
216 # format for mbedtls_config.h, which the other files don't follow. Also,
217 # cmake can't know this, but re-generation is actually not necessary as
218 # the generated files only depend on the list of available options, not
219 # whether they're on or off. So, disable cmake's (over-sensitive here)
220 # dependency resolution for generated files and just rely on them being
221 # present (thanks to pre_generate_files) by turning GEN_FILES off.
222 CC=$ASAN_CC cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
223 tests/scripts/test-ref-configs.pl config-tfm.h
224}
225
226component_test_no_renegotiation () {
227 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
228 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
229 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
230 make
231
232 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
233 make test
234
235 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
236 tests/ssl-opt.sh
237}
238
239component_test_no_pem_no_fs () {
240 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
241 scripts/config.py unset MBEDTLS_PEM_PARSE_C
242 scripts/config.py unset MBEDTLS_FS_IO
243 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
244 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
245 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
246 make
247
248 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
249 make test
250
251 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
252 tests/ssl-opt.sh
253}
254
255component_test_rsa_no_crt () {
256 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
257 scripts/config.py set MBEDTLS_RSA_NO_CRT
258 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
259 make
260
261 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
262 make test
263
264 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
265 tests/ssl-opt.sh -f RSA
266
267 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
268 tests/compat.sh -t RSA
269
270 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
271 tests/context-info.sh
272}
273
274component_test_no_ctr_drbg_classic () {
275 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
276 scripts/config.py full
277 scripts/config.py unset MBEDTLS_CTR_DRBG_C
278 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
279 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
280
281 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
282 make
283
284 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
285 make test
286
287 # In this configuration, the TLS test programs use HMAC_DRBG.
288 # The SSL tests are slow, so run a small subset, just enough to get
289 # confidence that the SSL code copes with HMAC_DRBG.
290 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
291 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
292
293 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
294 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
295}
296
297component_test_no_ctr_drbg_use_psa () {
298 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
299 scripts/config.py full
300 scripts/config.py unset MBEDTLS_CTR_DRBG_C
301 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
302
303 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
304 make
305
306 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
307 make test
308
309 # In this configuration, the TLS test programs use HMAC_DRBG.
310 # The SSL tests are slow, so run a small subset, just enough to get
311 # confidence that the SSL code copes with HMAC_DRBG.
312 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
313 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
314
315 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
316 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
317}
318
319component_test_no_hmac_drbg_classic () {
320 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
321 scripts/config.py full
322 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
323 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
324 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
325 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
326
327 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
328 make
329
330 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
331 make test
332
333 # Normally our ECDSA implementation uses deterministic ECDSA. But since
334 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
335 # instead.
336 # Test SSL with non-deterministic ECDSA. Only test features that
337 # might be affected by how ECDSA signature is performed.
338 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
339 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
340
341 # To save time, only test one protocol version, since this part of
342 # the protocol is identical in (D)TLS up to 1.2.
343 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
344 tests/compat.sh -m tls12 -t 'ECDSA'
345}
346
347component_test_no_hmac_drbg_use_psa () {
348 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
349 scripts/config.py full
350 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
351 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
352 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
353
354 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
355 make
356
357 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
358 make test
359
360 # Normally our ECDSA implementation uses deterministic ECDSA. But since
361 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
362 # instead.
363 # Test SSL with non-deterministic ECDSA. Only test features that
364 # might be affected by how ECDSA signature is performed.
365 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
366 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
367
368 # To save time, only test one protocol version, since this part of
369 # the protocol is identical in (D)TLS up to 1.2.
370 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
371 tests/compat.sh -m tls12 -t 'ECDSA'
372}
373
374component_test_psa_external_rng_no_drbg_classic () {
375 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
376 scripts/config.py full
377 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
378 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
379 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
380 scripts/config.py unset MBEDTLS_ENTROPY_C
381 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
382 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
383 scripts/config.py unset MBEDTLS_CTR_DRBG_C
384 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
385 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
386 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
387 # the SSL test programs don't have an RNG and can't work. Explicitly
388 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
389 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
390
391 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
392 make test
393
394 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
395 tests/ssl-opt.sh -f 'Default'
396}
397
398component_test_psa_external_rng_no_drbg_use_psa () {
399 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
400 scripts/config.py full
401 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
402 scripts/config.py unset MBEDTLS_ENTROPY_C
403 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
404 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
405 scripts/config.py unset MBEDTLS_CTR_DRBG_C
406 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
407 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
408 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
409
410 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
411 make test
412
413 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
414 tests/ssl-opt.sh -f 'Default\|opaque'
415}
416
Minos Galanakisada21b02024-07-26 12:34:19 +0100417component_test_sw_inet_pton () {
418 msg "build: default plus MBEDTLS_TEST_SW_INET_PTON"
419
420 # MBEDTLS_TEST_HOOKS required for x509_crt_parse_cn_inet_pton
421 scripts/config.py set MBEDTLS_TEST_HOOKS
422 make CFLAGS="-DMBEDTLS_TEST_SW_INET_PTON"
423
424 msg "test: default plus MBEDTLS_TEST_SW_INET_PTON"
425 make test
426}
427
Minos Galanakisada21b02024-07-26 12:34:19 +0100428component_test_full_no_cipher () {
429 msg "build: full no CIPHER"
430
431 scripts/config.py full
432 scripts/config.py unset MBEDTLS_CIPHER_C
433
434 # The built-in implementation of the following algs/key-types depends
435 # on CIPHER_C so we disable them.
436 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
437 # so we keep them enabled.
438 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
439 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CMAC
440 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
441 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
442 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CFB
443 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CTR
444 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
445 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_OFB
446 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
447 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_STREAM_CIPHER
448 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
449
450 # The following modules directly depends on CIPHER_C
451 scripts/config.py unset MBEDTLS_CMAC_C
452 scripts/config.py unset MBEDTLS_NIST_KW_C
453
454 make
455
456 # Ensure that CIPHER_C was not re-enabled
457 not grep mbedtls_cipher_init ${BUILTIN_SRC_PATH}/cipher.o
458
459 msg "test: full no CIPHER"
460 make test
461}
462
Minos Galanakisada21b02024-07-26 12:34:19 +0100463component_test_tls1_2_default_stream_cipher_only () {
464 msg "build: default with only stream cipher use psa"
465
466 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
467 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
468 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
469 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM
470 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
471 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_GCM
472 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CHACHA20_POLY1305
473 # Note: The three unsets below are to be removed for Mbed TLS 4.0
474 scripts/config.py unset MBEDTLS_GCM_C
475 scripts/config.py unset MBEDTLS_CCM_C
476 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
477 #Disable TLS 1.3 (as no AEAD)
478 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
479 # Disable CBC. Note: When implemented, PSA_WANT_ALG_CBC_MAC will also need to be unset here to fully disable CBC
480 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
481 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
482 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
483 # Note: The unset below is to be removed for 4.0
484 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
485 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
486 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
487 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
488 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
489 # Modules that depend on AEAD
490 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
491 scripts/config.py unset MBEDTLS_SSL_TICKET_C
492
493 make
494
495 msg "test: default with only stream cipher use psa"
496 make test
497
498 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
499}
500
501component_test_tls1_2_default_cbc_legacy_cipher_only () {
502 msg "build: default with only CBC-legacy cipher use psa"
503
504 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
505 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
506 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
507 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM
508 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
509 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_GCM
510 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CHACHA20_POLY1305
511 # Note: The three unsets below are to be removed for Mbed TLS 4.0
512 scripts/config.py unset MBEDTLS_GCM_C
513 scripts/config.py unset MBEDTLS_CCM_C
514 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
515 #Disable TLS 1.3 (as no AEAD)
516 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
517 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
518 scripts/config.py -f $CRYPTO_CONFIG_H set PSA_WANT_ALG_CBC_NO_PADDING
519 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
520 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
521 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
522 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
523 # Modules that depend on AEAD
524 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
525 scripts/config.py unset MBEDTLS_SSL_TICKET_C
526
527 make
528
529 msg "test: default with only CBC-legacy cipher use psa"
530 make test
531
532 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
533 tests/ssl-opt.sh -f "TLS 1.2"
534}
535
536component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
537 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
538
539 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
540 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
541 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
542 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM
543 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
544 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_GCM
545 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CHACHA20_POLY1305
546 # Note: The three unsets below are to be removed for Mbed TLS 4.0
547 scripts/config.py unset MBEDTLS_GCM_C
548 scripts/config.py unset MBEDTLS_CCM_C
549 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
550 #Disable TLS 1.3 (as no AEAD)
551 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
552 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
553 scripts/config.py -f $CRYPTO_CONFIG_H set PSA_WANT_ALG_CBC_NO_PADDING
554 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
555 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
556 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
557 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
558 # Modules that depend on AEAD
559 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
560 scripts/config.py unset MBEDTLS_SSL_TICKET_C
561
562 make
563
564 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
565 make test
566
567 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
568 tests/ssl-opt.sh -f "TLS 1.2"
569}
570
571# We're not aware of any other (open source) implementation of EC J-PAKE in TLS
572# that we could use for interop testing. However, we now have sort of two
573# implementations ourselves: one using PSA, the other not. At least test that
574# these two interoperate with each other.
575component_test_tls1_2_ecjpake_compatibility() {
576 msg "build: TLS1.2 server+client w/ EC-JPAKE w/o USE_PSA"
577 scripts/config.py set MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
578 # Explicitly make lib first to avoid a race condition:
579 # https://github.com/Mbed-TLS/mbedtls/issues/8229
580 make lib
581 make -C programs ssl/ssl_server2 ssl/ssl_client2
582 cp programs/ssl/ssl_server2 s2_no_use_psa
583 cp programs/ssl/ssl_client2 c2_no_use_psa
584
585 msg "build: TLS1.2 server+client w/ EC-JPAKE w/ USE_PSA"
586 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
587 make clean
588 make lib
589 make -C programs ssl/ssl_server2 ssl/ssl_client2
590 make -C programs test/udp_proxy test/query_compile_time_config
591
592 msg "test: server w/o USE_PSA - client w/ USE_PSA, text password"
593 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
594 msg "test: server w/o USE_PSA - client w/ USE_PSA, opaque password"
595 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password client only, working, TLS"
596 msg "test: client w/o USE_PSA - server w/ USE_PSA, text password"
597 P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
598 msg "test: client w/o USE_PSA - server w/ USE_PSA, opaque password"
599 P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password server only, working, TLS"
600
601 rm s2_no_use_psa c2_no_use_psa
602}
603
604component_test_everest () {
605 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
606 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
607 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
608 make
609
610 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
611 make test
612
613 msg "test: metatests (clang, ASan)"
614 tests/scripts/run-metatests.sh any asan poison
615
616 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
617 tests/ssl-opt.sh -f ECDH
618
619 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
620 # Exclude some symmetric ciphers that are redundant here to gain time.
621 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
622}
623
624component_test_everest_curve25519_only () {
625 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
626 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
627 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
628 scripts/config.py unset MBEDTLS_ECDSA_C
629 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
630 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECDSA
631 scripts/config.py -f $CRYPTO_CONFIG_H set PSA_WANT_ALG_ECDH
632 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
633 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
634 scripts/config.py unset MBEDTLS_ECJPAKE_C
635 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE
636
637 # Disable all curves
638 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
639 scripts/config.py -f $CRYPTO_CONFIG_H unset-all "PSA_WANT_ECC_[0-9A-Z_a-z]*$"
640 scripts/config.py -f $CRYPTO_CONFIG_H set PSA_WANT_ECC_MONTGOMERY_255
641
642 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
643
644 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
645 make test
646}
647
648component_test_small_ssl_out_content_len () {
649 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
650 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
651 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
652 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
653 make
654
655 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
656 tests/ssl-opt.sh -f "Max fragment\|Large packet"
657}
658
659component_test_small_ssl_in_content_len () {
660 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
661 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
662 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
663 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
664 make
665
666 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
667 tests/ssl-opt.sh -f "Max fragment"
668}
669
670component_test_small_ssl_dtls_max_buffering () {
671 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
672 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
673 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
674 make
675
676 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
677 tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
678}
679
680component_test_small_mbedtls_ssl_dtls_max_buffering () {
681 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
682 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
683 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
684 make
685
686 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
687 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
688}
689
Minos Galanakisada21b02024-07-26 12:34:19 +0100690component_test_full_cmake_clang () {
691 msg "build: cmake, full config, clang" # ~ 50s
692 scripts/config.py full
693 CC=clang CXX=clang cmake -D CMAKE_BUILD_TYPE:String=Release -D ENABLE_TESTING=On -D TEST_CPP=1 .
694 make
695
696 msg "test: main suites (full config, clang)" # ~ 5s
697 make test
698
699 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
700 programs/test/cpp_dummy_build
701
702 msg "test: metatests (clang)"
703 tests/scripts/run-metatests.sh any pthread
704
705 msg "program demos (full config, clang)" # ~10s
706 tests/scripts/run_demos.py
707
708 msg "test: psa_constant_names (full config, clang)" # ~ 1s
709 tests/scripts/test_psa_constant_names.py
710
711 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
712 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
713}
714
715skip_suites_without_constant_flow () {
716 # Skip the test suites that don't have any constant-flow annotations.
717 # This will need to be adjusted if we ever start declaring things as
718 # secret from macros or functions inside tests/include or tests/src.
719 SKIP_TEST_SUITES=$(
720 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
721 sed 's/test_suite_//; s/\.function$//' |
722 tr '\n' ,),$(
723 git -C tf-psa-crypto/tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
724 sed 's/test_suite_//; s/\.function$//' |
725 tr '\n' ,)
726 export SKIP_TEST_SUITES
727}
728
729skip_all_except_given_suite () {
730 # Skip all but the given test suite
731 SKIP_TEST_SUITES=$(
732 ls -1 tests/suites/test_suite_*.function |
733 grep -v $1.function |
734 sed 's/tests.suites.test_suite_//; s/\.function$//' |
735 tr '\n' ,),$(
736 ls -1 tf-psa-crypto/tests/suites/test_suite_*.function |
737 grep -v $1.function |
738 sed 's/tf-psa-crypto.tests.suites.test_suite_//; s/\.function$//' |
739 tr '\n' ,)
740 export SKIP_TEST_SUITES
741}
742
743component_test_memsan_constant_flow () {
744 # This tests both (1) accesses to undefined memory, and (2) branches or
745 # memory access depending on secret values. To distinguish between those:
746 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
747 # - or alternatively, change the build type to MemSanDbg, which enables
748 # origin tracking and nicer stack traces (which are useful for debugging
749 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
750 msg "build: cmake MSan (clang), full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
751 scripts/config.py full
752 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
753 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
754 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
755 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
756 make
757
758 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO, Msan + constant flow)"
759 make test
760}
761
762component_test_memsan_constant_flow_psa () {
763 # This tests both (1) accesses to undefined memory, and (2) branches or
764 # memory access depending on secret values. To distinguish between those:
765 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
766 # - or alternatively, change the build type to MemSanDbg, which enables
767 # origin tracking and nicer stack traces (which are useful for debugging
768 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
769 msg "build: cmake MSan (clang), full config with constant flow testing"
770 scripts/config.py full
771 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
772 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
773 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
774 make
775
776 msg "test: main suites (Msan + constant flow)"
777 make test
778}
779
780component_release_test_valgrind_constant_flow () {
781 # This tests both (1) everything that valgrind's memcheck usually checks
782 # (heap buffer overflows, use of uninitialized memory, use-after-free,
783 # etc.) and (2) branches or memory access depending on secret values,
784 # which will be reported as uninitialized memory. To distinguish between
785 # secret and actually uninitialized:
786 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
787 # - or alternatively, build with debug info and manually run the offending
788 # test suite with valgrind --track-origins=yes, then check if the origin
789 # was TEST_CF_SECRET() or something else.
790 msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
791 scripts/config.py full
792 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
793 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
794 skip_suites_without_constant_flow
795 cmake -D CMAKE_BUILD_TYPE:String=Release .
796 make
797
798 # this only shows a summary of the results (how many of each type)
799 # details are left in Testing/<date>/DynamicAnalysis.xml
800 msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, valgrind + constant flow)"
801 make memcheck
802
803 # Test asm path in constant time module - by default, it will test the plain C
804 # path under Valgrind or Memsan. Running only the constant_time tests is fast (<1s)
805 msg "test: valgrind asm constant_time"
806 scripts/config.py --force set MBEDTLS_TEST_CONSTANT_FLOW_ASM
807 skip_all_except_given_suite test_suite_constant_time
808 cmake -D CMAKE_BUILD_TYPE:String=Release .
809 make clean
810 make
811 make memcheck
812}
813
814component_release_test_valgrind_constant_flow_psa () {
815 # This tests both (1) everything that valgrind's memcheck usually checks
816 # (heap buffer overflows, use of uninitialized memory, use-after-free,
817 # etc.) and (2) branches or memory access depending on secret values,
818 # which will be reported as uninitialized memory. To distinguish between
819 # secret and actually uninitialized:
820 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
821 # - or alternatively, build with debug info and manually run the offending
822 # test suite with valgrind --track-origins=yes, then check if the origin
823 # was TEST_CF_SECRET() or something else.
824 msg "build: cmake release GCC, full config with constant flow testing"
825 scripts/config.py full
826 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
827 skip_suites_without_constant_flow
828 cmake -D CMAKE_BUILD_TYPE:String=Release .
829 make
830
831 # this only shows a summary of the results (how many of each type)
832 # details are left in Testing/<date>/DynamicAnalysis.xml
833 msg "test: some suites (valgrind + constant flow)"
834 make memcheck
835}
836
837component_test_tsan () {
838 msg "build: TSan (clang)"
839 scripts/config.py full
840 scripts/config.py set MBEDTLS_THREADING_C
841 scripts/config.py set MBEDTLS_THREADING_PTHREAD
842 # Self-tests do not currently use multiple threads.
843 scripts/config.py unset MBEDTLS_SELF_TEST
844
845 # The deprecated MBEDTLS_PSA_CRYPTO_SE_C interface is not thread safe.
846 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
847
848 CC=clang cmake -D CMAKE_BUILD_TYPE:String=TSan .
849 make
850
851 msg "test: main suites (TSan)"
852 make test
853}
854
855component_test_default_no_deprecated () {
856 # Test that removing the deprecated features from the default
857 # configuration leaves something consistent.
858 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
859 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
860 make CFLAGS='-O -Werror -Wall -Wextra'
861
862 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
863 make test
864}
865
866component_test_full_no_deprecated () {
867 msg "build: make, full_no_deprecated config" # ~ 30s
868 scripts/config.py full_no_deprecated
869 make CFLAGS='-O -Werror -Wall -Wextra'
870
871 msg "test: make, full_no_deprecated config" # ~ 5s
872 make test
873
874 msg "test: ensure that X509 has no direct dependency on BIGNUM_C"
875 not grep mbedtls_mpi library/libmbedx509.a
876}
877
878component_test_full_no_deprecated_deprecated_warning () {
879 # Test that there is nothing deprecated in "full_no_deprecated".
880 # A deprecated feature would trigger a warning (made fatal) from
881 # MBEDTLS_DEPRECATED_WARNING.
882 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
883 scripts/config.py full_no_deprecated
884 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
885 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
886 make CFLAGS='-O -Werror -Wall -Wextra'
887
888 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
889 make test
890}
891
892component_test_full_deprecated_warning () {
893 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
894 # with only certain whitelisted types of warnings.
895 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
896 scripts/config.py full
897 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
898 # Expect warnings from '#warning' directives in check_config.h.
899 # Note that gcc is required to allow the use of -Wno-error=cpp, which allows us to
900 # display #warning messages without them being treated as errors.
901 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
902
903 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
904 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
905 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
906 # Expect warnings from '#warning' directives in check_config.h and
907 # from the use of deprecated functions in test suites.
908 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -Wno-error=cpp -DMBEDTLS_TEST_DEPRECATED' tests
909
910 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
911 make test
912
913 msg "program demos: full config + MBEDTLS_TEST_DEPRECATED" # ~10s
914 tests/scripts/run_demos.py
915}
916
Minos Galanakisada21b02024-07-26 12:34:19 +0100917component_build_baremetal () {
918 msg "build: make, baremetal config"
919 scripts/config.py baremetal
920 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
921}
922support_build_baremetal () {
923 # Older Glibc versions include time.h from other headers such as stdlib.h,
924 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
925 # problem, Ubuntu 18.04 is ok.
926 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
927}
928
Minos Galanakisada21b02024-07-26 12:34:19 +0100929component_test_no_psa_crypto_full_cmake_asan() {
930 # full minus MBEDTLS_PSA_CRYPTO_C: run the same set of tests as basic-build-test.sh
931 msg "build: cmake, full config minus PSA crypto, ASan"
932 scripts/config.py full
933 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
934 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CLIENT
935 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
936 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
937 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
938 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
939 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
940 scripts/config.py unset MBEDTLS_LMS_C
941 scripts/config.py unset MBEDTLS_LMS_PRIVATE
942 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
943 make
944
945 msg "test: main suites (full minus PSA crypto)"
946 make test
947
948 # Note: ssl-opt.sh has some test cases that depend on
949 # MBEDTLS_ECP_RESTARTABLE && !MBEDTLS_USE_PSA_CRYPTO
950 # This is the only component where those tests are not skipped.
951 msg "test: ssl-opt.sh (full minus PSA crypto)"
952 tests/ssl-opt.sh
953
954 # Note: the next two invocations cover all compat.sh test cases.
955 # We should use the same here and in basic-build-test.sh.
956 msg "test: compat.sh: default version (full minus PSA crypto)"
957 tests/compat.sh -e 'ARIA\|CHACHA'
958
959 msg "test: compat.sh: next: ARIA, Chacha (full minus PSA crypto)"
960 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
961}
962
Minos Galanakisada21b02024-07-26 12:34:19 +0100963# Common helper for component_full_without_ecdhe_ecdsa() and
964# component_full_without_ecdhe_ecdsa_and_tls13() which:
965# - starts from the "full" configuration minus the list of symbols passed in
966# as 1st parameter
967# - build
968# - test only TLS (i.e. test_suite_tls and ssl-opt)
969build_full_minus_something_and_test_tls () {
970 symbols_to_disable="$1"
971
972 msg "build: full minus something, test TLS"
973
974 scripts/config.py full
975 for sym in $symbols_to_disable; do
976 echo "Disabling $sym"
977 scripts/config.py unset $sym
978 done
979
980 make
981
982 msg "test: full minus something, test TLS"
983 ( cd tests; ./test_suite_ssl )
984
985 msg "ssl-opt: full minus something, test TLS"
986 tests/ssl-opt.sh
987}
988
989component_full_without_ecdhe_ecdsa () {
990 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED"
991}
992
993component_full_without_ecdhe_ecdsa_and_tls13 () {
994 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
995 MBEDTLS_SSL_PROTO_TLS1_3"
996}
997
Minos Galanakisada21b02024-07-26 12:34:19 +0100998component_build_tfm() {
999 # Check that the TF-M configuration can build cleanly with various
1000 # warning flags enabled. We don't build or run tests, since the
1001 # TF-M configuration needs a TF-M platform. A tweaked version of
1002 # the configuration that works on mainstream platforms is in
1003 # configs/config-tfm.h, tested via test-ref-configs.pl.
1004 cp configs/config-tfm.h "$CONFIG_H"
1005
1006 msg "build: TF-M config, clang, armv7-m thumb2"
1007 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"
1008
1009 msg "build: TF-M config, gcc native build"
1010 make clean
1011 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"
1012}
1013
Minos Galanakisada21b02024-07-26 12:34:19 +01001014component_test_no_platform () {
1015 # Full configuration build, without platform support, file IO and net sockets.
1016 # This should catch missing mbedtls_printf definitions, and by disabling file
1017 # IO, it should catch missing '#include <stdio.h>'
1018 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
1019 scripts/config.py full_no_platform
1020 scripts/config.py unset MBEDTLS_PLATFORM_C
1021 scripts/config.py unset MBEDTLS_NET_C
1022 scripts/config.py unset MBEDTLS_FS_IO
1023 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
1024 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1025 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
1026 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1027 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1028 # to re-enable platform integration features otherwise disabled in C99 builds
1029 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1030 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
1031}
1032
1033component_build_no_std_function () {
1034 # catch compile bugs in _uninit functions
1035 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
1036 scripts/config.py full
1037 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1038 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1039 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1040 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
1041 make
1042}
1043
1044component_build_no_ssl_srv () {
1045 msg "build: full config except SSL server, make, gcc" # ~ 30s
1046 scripts/config.py full
1047 scripts/config.py unset MBEDTLS_SSL_SRV_C
1048 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
1049}
1050
1051component_build_no_ssl_cli () {
1052 msg "build: full config except SSL client, make, gcc" # ~ 30s
1053 scripts/config.py full
1054 scripts/config.py unset MBEDTLS_SSL_CLI_C
1055 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
1056}
1057
1058component_build_no_sockets () {
1059 # Note, C99 compliance can also be tested with the sockets support disabled,
1060 # as that requires a POSIX platform (which isn't the same as C99).
1061 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
1062 scripts/config.py full
1063 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1064 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
1065 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
1066}
1067
1068component_test_memory_buffer_allocator_backtrace () {
1069 msg "build: default config with memory buffer allocator and backtrace enabled"
1070 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1071 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1072 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
1073 scripts/config.py set MBEDTLS_MEMORY_DEBUG
1074 cmake -DCMAKE_BUILD_TYPE:String=Release .
1075 make
1076
1077 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1078 make test
1079}
1080
1081component_test_memory_buffer_allocator () {
1082 msg "build: default config with memory buffer allocator"
1083 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1084 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1085 cmake -DCMAKE_BUILD_TYPE:String=Release .
1086 make
1087
1088 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1089 make test
1090
1091 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1092 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1093 tests/ssl-opt.sh -e '^DTLS proxy'
1094}
1095
1096component_test_no_max_fragment_length () {
1097 # Run max fragment length tests with MFL disabled
1098 msg "build: default config except MFL extension (ASan build)" # ~ 30s
1099 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1100 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1101 make
1102
1103 msg "test: ssl-opt.sh, MFL-related tests"
1104 tests/ssl-opt.sh -f "Max fragment length"
1105}
1106
1107component_test_asan_remove_peer_certificate () {
1108 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
1109 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
1110 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1111 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1112 make
1113
1114 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1115 make test
1116
1117 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1118 tests/ssl-opt.sh
1119
1120 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1121 tests/compat.sh
1122
1123 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1124 tests/context-info.sh
1125}
1126
1127component_test_no_max_fragment_length_small_ssl_out_content_len () {
1128 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
1129 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1130 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1131 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1132 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1133 make
1134
1135 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1136 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1137
1138 msg "test: context-info.sh (disabled MFL extension case)"
1139 tests/context-info.sh
1140}
1141
1142component_test_variable_ssl_in_out_buffer_len () {
1143 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
1144 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1145 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1146 make
1147
1148 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1149 make test
1150
1151 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1152 tests/ssl-opt.sh
1153
1154 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1155 tests/compat.sh
1156}
1157
1158component_test_dtls_cid_legacy () {
1159 msg "build: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled (ASan build)"
1160 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 1
1161
1162 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1163 make
1164
1165 msg "test: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy)"
1166 make test
1167
1168 msg "test: ssl-opt.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
1169 tests/ssl-opt.sh
1170
1171 msg "test: compat.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
1172 tests/compat.sh
1173}
1174
1175component_test_ssl_alloc_buffer_and_mfl () {
1176 msg "build: default config with memory buffer allocator and MFL extension"
1177 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1178 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1179 scripts/config.py set MBEDTLS_MEMORY_DEBUG
1180 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1181 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1182 cmake -DCMAKE_BUILD_TYPE:String=Release .
1183 make
1184
1185 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
1186 make test
1187
1188 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
1189 tests/ssl-opt.sh -f "Handshake memory usage"
1190}
1191
1192component_test_when_no_ciphersuites_have_mac () {
1193 msg "build: when no ciphersuites have MAC"
1194 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1195 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
1196 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
1197 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
1198 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
1199
1200 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1201 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1202 scripts/config.py unset MBEDTLS_CMAC_C
1203
1204 make
1205
1206 msg "test: !MBEDTLS_SSL_SOME_SUITES_USE_MAC"
1207 make test
1208
1209 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_SUITES_USE_MAC"
1210 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
1211}
1212
1213component_test_no_date_time () {
1214 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
1215 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
1216 cmake -D CMAKE_BUILD_TYPE:String=Check .
1217 make
1218
1219 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
1220 make test
1221}
1222
1223component_test_platform_calloc_macro () {
1224 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1225 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1226 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1227 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
1228 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1229 make
1230
1231 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1232 make test
1233}
1234
1235component_test_malloc_0_null () {
1236 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
1237 scripts/config.py full
1238 make CC=$ASAN_CC CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"$PWD/tests/configs/user-config-malloc-0-null.h\"' $ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1239
1240 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1241 make test
1242
1243 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1244 # Just the calloc selftest. "make test" ran the others as part of the
1245 # test suites.
1246 programs/test/selftest calloc
1247
1248 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
1249 # Run a subset of the tests. The choice is a balance between coverage
1250 # and time (including time indirectly wasted due to flaky tests).
1251 # The current choice is to skip tests whose description includes
1252 # "proxy", which is an approximation of skipping tests that use the
1253 # UDP proxy, which tend to be slower and flakier.
1254 tests/ssl-opt.sh -e 'proxy'
1255}
1256
Minos Galanakisada21b02024-07-26 12:34:19 +01001257component_build_mbedtls_config_file () {
1258 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1259 scripts/config.py -w full_config.h full
1260 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1261 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1262 # Make sure this feature is enabled. We'll disable it in the next phase.
1263 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
1264 make clean
1265
1266 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
1267 # In the user config, disable one feature (for simplicity, pick a feature
1268 # that nothing else depends on).
1269 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
1270 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
1271 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
1272
1273 rm -f user_config.h full_config.h
1274}
1275
Minos Galanakisada21b02024-07-26 12:34:19 +01001276
Minos Galanakisada21b02024-07-26 12:34:19 +01001277
Minos Galanakisada21b02024-07-26 12:34:19 +01001278
Minos Galanakisada21b02024-07-26 12:34:19 +01001279
1280component_test_m32_no_asm () {
1281 # Build without assembly, so as to use portable C code (in a 32-bit
1282 # build) and not the i386-specific inline assembly.
1283 #
1284 # Note that we require gcc, because clang Asan builds fail to link for
1285 # this target (cannot find libclang_rt.lsan-i386.a - this is a known clang issue).
1286 msg "build: i386, make, gcc, no asm (ASan build)" # ~ 30s
1287 scripts/config.py full
1288 scripts/config.py unset MBEDTLS_HAVE_ASM
1289 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
1290 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
1291
1292 msg "test: i386, make, gcc, no asm (ASan build)"
1293 make test
1294}
1295support_test_m32_no_asm () {
1296 case $(uname -m) in
1297 amd64|x86_64) true;;
1298 *) false;;
1299 esac
1300}
1301
1302component_test_m32_o2 () {
1303 # Build with optimization, to use the i386 specific inline assembly
1304 # and go faster for tests.
1305 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
1306 scripts/config.py full
1307 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
1308 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
1309
1310 msg "test: i386, make, gcc -O2 (ASan build)"
1311 make test
1312
1313 msg "test ssl-opt.sh, i386, make, gcc-O2"
1314 tests/ssl-opt.sh
1315}
1316support_test_m32_o2 () {
1317 support_test_m32_no_asm "$@"
1318}
1319
1320component_test_m32_everest () {
1321 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
1322 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1323 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
1324 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
1325
1326 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1327 make test
1328
1329 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
1330 tests/ssl-opt.sh -f ECDH
1331
1332 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1333 # Exclude some symmetric ciphers that are redundant here to gain time.
1334 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
1335}
1336support_test_m32_everest () {
1337 support_test_m32_no_asm "$@"
1338}
1339
1340component_test_mx32 () {
1341 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
1342 scripts/config.py full
1343 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
1344
1345 msg "test: 64-bit ILP32, make, gcc"
1346 make test
1347}
1348support_test_mx32 () {
1349 case $(uname -m) in
1350 amd64|x86_64) true;;
1351 *) false;;
1352 esac
1353}
1354
Minos Galanakisada21b02024-07-26 12:34:19 +01001355component_test_have_int32 () {
1356 msg "build: gcc, force 32-bit bignum limbs"
1357 scripts/config.py unset MBEDTLS_HAVE_ASM
1358 scripts/config.py unset MBEDTLS_AESNI_C
1359 scripts/config.py unset MBEDTLS_AESCE_C
1360 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
1361
1362 msg "test: gcc, force 32-bit bignum limbs"
1363 make test
1364}
1365
1366component_test_have_int64 () {
1367 msg "build: gcc, force 64-bit bignum limbs"
1368 scripts/config.py unset MBEDTLS_HAVE_ASM
1369 scripts/config.py unset MBEDTLS_AESNI_C
1370 scripts/config.py unset MBEDTLS_AESCE_C
1371 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
1372
1373 msg "test: gcc, force 64-bit bignum limbs"
1374 make test
1375}
1376
1377component_test_have_int32_cmake_new_bignum () {
1378 msg "build: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
1379 scripts/config.py unset MBEDTLS_HAVE_ASM
1380 scripts/config.py unset MBEDTLS_AESNI_C
1381 scripts/config.py unset MBEDTLS_AESCE_C
1382 scripts/config.py set MBEDTLS_TEST_HOOKS
1383 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
1384 make CC=gcc CFLAGS="$ASAN_CFLAGS -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32" LDFLAGS="$ASAN_CFLAGS"
1385
1386 msg "test: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
1387 make test
1388}
1389
1390component_test_no_udbl_division () {
1391 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1392 scripts/config.py full
1393 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
1394 make CFLAGS='-Werror -O1'
1395
1396 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1397 make test
1398}
1399
1400component_test_no_64bit_multiplication () {
1401 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1402 scripts/config.py full
1403 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
1404 make CFLAGS='-Werror -O1'
1405
1406 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1407 make test
1408}
1409
1410component_test_no_strings () {
1411 msg "build: no strings" # ~10s
1412 scripts/config.py full
1413 # Disable options that activate a large amount of string constants.
1414 scripts/config.py unset MBEDTLS_DEBUG_C
1415 scripts/config.py unset MBEDTLS_ERROR_C
1416 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
1417 scripts/config.py unset MBEDTLS_VERSION_FEATURES
1418 make CFLAGS='-Werror -Os'
1419
1420 msg "test: no strings" # ~ 10s
1421 make test
1422}
1423
1424component_test_no_x509_info () {
1425 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
1426 scripts/config.pl full
1427 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1428 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
1429 make CFLAGS='-Werror -O2'
1430
1431 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
1432 make test
1433
1434 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
1435 tests/ssl-opt.sh
1436}
1437
Minos Galanakisada21b02024-07-26 12:34:19 +01001438component_test_tls12_only () {
1439 msg "build: default config without MBEDTLS_SSL_PROTO_TLS1_3, cmake, gcc, ASan"
1440 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1441 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1442 make
1443
1444 msg "test: main suites (inc. selftests) (ASan build)"
1445 make test
1446
1447 msg "test: ssl-opt.sh (ASan build)"
1448 tests/ssl-opt.sh
1449
1450 msg "test: compat.sh (ASan build)"
1451 tests/compat.sh
1452}
1453
1454component_test_tls13_only () {
1455 msg "build: default config without MBEDTLS_SSL_PROTO_TLS1_2"
1456 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
1457 scripts/config.py set MBEDTLS_SSL_RECORD_SIZE_LIMIT
1458 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
1459
1460 msg "test: TLS 1.3 only, all key exchange modes enabled"
1461 make test
1462
1463 msg "ssl-opt.sh: TLS 1.3 only, all key exchange modes enabled"
1464 tests/ssl-opt.sh
1465}
1466
1467component_test_tls13_only_psk () {
1468 msg "build: TLS 1.3 only from default, only PSK key exchange mode"
1469 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
1470 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
1471 scripts/config.py unset MBEDTLS_ECDH_C
1472 scripts/config.py unset MBEDTLS_DHM_C
1473 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
1474 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1475 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
1476 scripts/config.py unset MBEDTLS_ECDSA_C
1477 scripts/config.py unset MBEDTLS_PKCS1_V21
1478 scripts/config.py unset MBEDTLS_PKCS7_C
1479 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
1480 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
1481
1482 msg "test_suite_ssl: TLS 1.3 only, only PSK key exchange mode enabled"
1483 cd tests; ./test_suite_ssl; cd ..
1484
1485 msg "ssl-opt.sh: TLS 1.3 only, only PSK key exchange mode enabled"
1486 tests/ssl-opt.sh
1487}
1488
1489component_test_tls13_only_ephemeral () {
1490 msg "build: TLS 1.3 only from default, only ephemeral key exchange mode"
1491 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
1492 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
1493 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
1494 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
1495
1496 msg "test_suite_ssl: TLS 1.3 only, only ephemeral key exchange mode"
1497 cd tests; ./test_suite_ssl; cd ..
1498
1499 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral key exchange mode"
1500 tests/ssl-opt.sh
1501}
1502
1503component_test_tls13_only_ephemeral_ffdh () {
1504 msg "build: TLS 1.3 only from default, only ephemeral ffdh key exchange mode"
1505 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
1506 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
1507 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
1508 scripts/config.py unset MBEDTLS_ECDH_C
1509
1510 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
1511
1512 msg "test_suite_ssl: TLS 1.3 only, only ephemeral ffdh key exchange mode"
1513 cd tests; ./test_suite_ssl; cd ..
1514
1515 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral ffdh key exchange mode"
1516 tests/ssl-opt.sh
1517}
1518
1519component_test_tls13_only_psk_ephemeral () {
1520 msg "build: TLS 1.3 only from default, only PSK ephemeral key exchange mode"
1521 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
1522 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
1523 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
1524 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1525 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
1526 scripts/config.py unset MBEDTLS_ECDSA_C
1527 scripts/config.py unset MBEDTLS_PKCS1_V21
1528 scripts/config.py unset MBEDTLS_PKCS7_C
1529 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
1530 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
1531
1532 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral key exchange mode"
1533 cd tests; ./test_suite_ssl; cd ..
1534
1535 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral key exchange mode"
1536 tests/ssl-opt.sh
1537}
1538
1539component_test_tls13_only_psk_ephemeral_ffdh () {
1540 msg "build: TLS 1.3 only from default, only PSK ephemeral ffdh key exchange mode"
1541 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
1542 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
1543 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
1544 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1545 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
1546 scripts/config.py unset MBEDTLS_ECDSA_C
1547 scripts/config.py unset MBEDTLS_PKCS1_V21
1548 scripts/config.py unset MBEDTLS_PKCS7_C
1549 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
1550 scripts/config.py unset MBEDTLS_ECDH_C
1551 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
1552
1553 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
1554 cd tests; ./test_suite_ssl; cd ..
1555
1556 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
1557 tests/ssl-opt.sh
1558}
1559
1560component_test_tls13_only_psk_all () {
1561 msg "build: TLS 1.3 only from default, without ephemeral key exchange mode"
1562 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
1563 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
1564 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1565 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
1566 scripts/config.py unset MBEDTLS_ECDSA_C
1567 scripts/config.py unset MBEDTLS_PKCS1_V21
1568 scripts/config.py unset MBEDTLS_PKCS7_C
1569 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
1570 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
1571
1572 msg "test_suite_ssl: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
1573 cd tests; ./test_suite_ssl; cd ..
1574
1575 msg "ssl-opt.sh: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
1576 tests/ssl-opt.sh
1577}
1578
1579component_test_tls13_only_ephemeral_all () {
1580 msg "build: TLS 1.3 only from default, without PSK key exchange mode"
1581 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
1582 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
1583 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
1584
1585 msg "test_suite_ssl: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
1586 cd tests; ./test_suite_ssl; cd ..
1587
1588 msg "ssl-opt.sh: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
1589 tests/ssl-opt.sh
1590}
1591
1592component_test_tls13_no_padding () {
1593 msg "build: default config plus early data minus padding"
1594 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
1595 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
1596 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1597 make
1598 msg "test: default config plus early data minus padding"
1599 make test
1600 msg "ssl-opt.sh (TLS 1.3 no padding)"
1601 tests/ssl-opt.sh
1602}
1603
1604component_test_tls13_no_compatibility_mode () {
1605 msg "build: default config plus early data minus middlebox compatibility mode"
1606 scripts/config.py unset MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
1607 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
1608 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1609 make
1610 msg "test: default config plus early data minus middlebox compatibility mode"
1611 make test
1612 msg "ssl-opt.sh (TLS 1.3 no compatibility mode)"
1613 tests/ssl-opt.sh
1614}
1615
1616component_test_full_minus_session_tickets() {
1617 msg "build: full config without session tickets"
1618 scripts/config.py full
1619 scripts/config.py unset MBEDTLS_SSL_SESSION_TICKETS
1620 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
1621 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1622 make
1623 msg "test: full config without session tickets"
1624 make test
1625 msg "ssl-opt.sh (full config without session tickets)"
1626 tests/ssl-opt.sh
1627}
1628
Minos Galanakisada21b02024-07-26 12:34:19 +01001629component_test_memsan () {
1630 msg "build: MSan (clang)" # ~ 1 min 20s
1631 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1632 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1633 make
1634
1635 msg "test: main suites (MSan)" # ~ 10s
1636 make test
1637
1638 msg "test: metatests (MSan)"
1639 tests/scripts/run-metatests.sh any msan
1640
1641 msg "program demos (MSan)" # ~20s
1642 tests/scripts/run_demos.py
1643
1644 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
1645 tests/ssl-opt.sh
1646
1647 # Optional part(s)
1648
1649 if [ "$MEMORY" -gt 0 ]; then
1650 msg "test: compat.sh (MSan)" # ~ 6 min 20s
1651 tests/compat.sh
1652 fi
1653}
1654
1655component_release_test_valgrind () {
1656 msg "build: Release (clang)"
1657 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
1658 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1659 make
1660
1661 msg "test: main suites, Valgrind (default config)"
1662 make memcheck
1663
1664 # Optional parts (slow; currently broken on OS X because programs don't
1665 # seem to receive signals under valgrind on OS X).
1666 # These optional parts don't run on the CI.
1667 if [ "$MEMORY" -gt 0 ]; then
1668 msg "test: ssl-opt.sh --memcheck (default config)"
1669 tests/ssl-opt.sh --memcheck
1670 fi
1671
1672 if [ "$MEMORY" -gt 1 ]; then
1673 msg "test: compat.sh --memcheck (default config)"
1674 tests/compat.sh --memcheck
1675 fi
1676
1677 if [ "$MEMORY" -gt 0 ]; then
1678 msg "test: context-info.sh --memcheck (default config)"
1679 tests/context-info.sh --memcheck
1680 fi
1681}
1682
1683component_release_test_valgrind_psa () {
1684 msg "build: Release, full (clang)"
1685 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
1686 scripts/config.py full
1687 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
1688 make
1689
1690 msg "test: main suites, Valgrind (full config)"
1691 make memcheck
1692}
1693
Minos Galanakisada21b02024-07-26 12:34:19 +01001694component_build_zeroize_checks () {
1695 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
1696
1697 scripts/config.py full
1698
1699 # Only compile - we're looking for sizeof-pointer-memaccess warnings
1700 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess"
1701}
1702
Minos Galanakisdb7b1bb2024-07-26 13:39:09 +01001703component_test_psasim () {
Minos Galanakisada21b02024-07-26 12:34:19 +01001704 msg "build server library and application"
1705 scripts/config.py crypto
1706 helper_psasim_config server
1707 helper_psasim_build server
1708
1709 helper_psasim_cleanup_before_client
1710
1711 msg "build library for client"
1712 helper_psasim_config client
1713 helper_psasim_build client
1714
1715 msg "build basic psasim client"
1716 make -C tests/psa-client-server/psasim CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" test/psa_client_base
1717 msg "test basic psasim client"
1718 tests/psa-client-server/psasim/test/run_test.sh psa_client_base
1719
1720 msg "build full psasim client"
1721 make -C tests/psa-client-server/psasim CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" test/psa_client_full
1722 msg "test full psasim client"
1723 tests/psa-client-server/psasim/test/run_test.sh psa_client_full
1724
1725 make -C tests/psa-client-server/psasim clean
1726}
1727
Minos Galanakisdb7b1bb2024-07-26 13:39:09 +01001728component_test_suite_with_psasim () {
Minos Galanakisada21b02024-07-26 12:34:19 +01001729 msg "build server library and application"
1730 helper_psasim_config server
1731 # Modify server's library configuration here (if needed)
1732 helper_psasim_build server
1733
1734 helper_psasim_cleanup_before_client
1735
1736 msg "build client library"
1737 helper_psasim_config client
1738 # PAKE functions are still unsupported from PSASIM
1739 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_JPAKE
1740 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
1741 helper_psasim_build client
1742
1743 msg "build test suites"
1744 make PSASIM=1 CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" tests
1745
1746 helper_psasim_server kill
1747 helper_psasim_server start
1748
1749 # psasim takes an extremely long execution time on some test suites so we
1750 # exclude them from the list.
1751 SKIP_TEST_SUITES="constant_time_hmac,lmots,lms"
1752 export SKIP_TEST_SUITES
1753
1754 msg "run test suites"
1755 make PSASIM=1 test
1756
1757 helper_psasim_server kill
Minos Galanakis85c78f52024-07-26 14:11:08 +01001758}