blob: 30f95f1b0bcb48cca6521d153f664fed09607ce1 [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
Minos Galanakisf7d1cb02024-07-30 17:25:31 +0100184# Get a list of library-wise undefined symbols and ensure that they only
185# belong to psa_xxx() functions and not to mbedtls_yyy() ones.
186# This function is a common helper used by both:
187# - component_test_default_psa_crypto_client_without_crypto_provider
188# - component_build_full_psa_crypto_client_without_crypto_provider.
189common_check_mbedtls_missing_symbols () {
190 nm library/libmbedcrypto.a | grep ' [TRrDC] ' | grep -Eo '(mbedtls_|psa_).*' | sort -u > sym_def.txt
191 nm library/libmbedcrypto.a | grep ' U ' | grep -Eo '(mbedtls_|psa_).*' | sort -u > sym_undef.txt
192 comm sym_def.txt sym_undef.txt -13 > linking_errors.txt
193 not grep mbedtls_ linking_errors.txt
194
195 rm sym_def.txt sym_undef.txt linking_errors.txt
196}
197
198component_test_default_psa_crypto_client_without_crypto_provider () {
199 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
200
201 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
202 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
203 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
204 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
205 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
206 scripts/config.py unset MBEDTLS_LMS_C
207
208 make
209
210 msg "check missing symbols: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
211 common_check_mbedtls_missing_symbols
212
213 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
214 make test
215}
216
217component_build_full_psa_crypto_client_without_crypto_provider () {
218 msg "build: full config - PSA_CRYPTO_C"
219
220 # Use full config which includes USE_PSA and CRYPTO_CLIENT.
221 scripts/config.py full
222
223 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
224 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
225 # Dynamic secure element support is a deprecated feature and it is not
226 # available when CRYPTO_C and PSA_CRYPTO_STORAGE_C are disabled.
227 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
228
229 # Since there is no crypto provider in this build it is not possible to
230 # build all the test executables and progrems due to missing PSA functions
231 # at link time. Therefore we will just build libraries and we'll check
232 # that symbols of interest are there.
233 make lib
234
235 msg "check missing symbols: full config - PSA_CRYPTO_C"
236
237 common_check_mbedtls_missing_symbols
238
239 # Ensure that desired functions are included into the build (extend the
240 # following list as required).
241 grep mbedtls_pk_get_psa_attributes library/libmbedcrypto.a
242 grep mbedtls_pk_import_into_psa library/libmbedcrypto.a
243 grep mbedtls_pk_copy_from_psa library/libmbedcrypto.a
244}
245
246component_test_psa_crypto_rsa_no_genprime () {
247 msg "build: default config minus MBEDTLS_GENPRIME"
248 scripts/config.py unset MBEDTLS_GENPRIME
249 make
250
251 msg "test: default config minus MBEDTLS_GENPRIME"
252 make test
253}
254
255component_test_ref_configs () {
256 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
257 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
258 # want to re-generate generated files that depend on it, quite correctly.
259 # However this doesn't work as the generation script expects a specific
260 # format for mbedtls_config.h, which the other files don't follow. Also,
261 # cmake can't know this, but re-generation is actually not necessary as
262 # the generated files only depend on the list of available options, not
263 # whether they're on or off. So, disable cmake's (over-sensitive here)
264 # dependency resolution for generated files and just rely on them being
265 # present (thanks to pre_generate_files) by turning GEN_FILES off.
266 CC=$ASAN_CC cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
267 tests/scripts/test-ref-configs.pl
268}
269
270component_test_no_renegotiation () {
271 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
272 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
273 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
274 make
275
276 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
277 make test
278
279 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
280 tests/ssl-opt.sh
281}
282
Minos Galanakisf7d1cb02024-07-30 17:25:31 +0100283component_test_sw_inet_pton () {
284 msg "build: default plus MBEDTLS_TEST_SW_INET_PTON"
285
286 # MBEDTLS_TEST_HOOKS required for x509_crt_parse_cn_inet_pton
287 scripts/config.py set MBEDTLS_TEST_HOOKS
288 make CFLAGS="-DMBEDTLS_TEST_SW_INET_PTON"
289
290 msg "test: default plus MBEDTLS_TEST_SW_INET_PTON"
291 make test
292}
293
Minos Galanakisf7d1cb02024-07-30 17:25:31 +0100294component_test_full_no_cipher_no_psa_crypto () {
295 msg "build: full no CIPHER no PSA_CRYPTO_C"
296 scripts/config.py full
297 scripts/config.py unset MBEDTLS_CIPHER_C
298 # Don't pull in cipher via PSA mechanisms
299 # (currently ignored anyway because we completely disable PSA)
300 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
301 # Disable features that depend on CIPHER_C
302 scripts/config.py unset MBEDTLS_CMAC_C
303 scripts/config.py unset MBEDTLS_NIST_KW_C
304 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
305 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CLIENT
306 scripts/config.py unset MBEDTLS_SSL_TLS_C
307 scripts/config.py unset MBEDTLS_SSL_TICKET_C
308 # Disable features that depend on PSA_CRYPTO_C
309 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
310 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
311 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
312 scripts/config.py unset MBEDTLS_LMS_C
313 scripts/config.py unset MBEDTLS_LMS_PRIVATE
314
315 msg "test: full no CIPHER no PSA_CRYPTO_C"
316 make test
317}
318
319# This is a common configurator and test function that is used in:
320# - component_test_full_no_cipher_with_psa_crypto
321# - component_test_full_no_cipher_with_psa_crypto_config
322# It accepts 2 input parameters:
323# - $1: boolean value which basically reflects status of MBEDTLS_PSA_CRYPTO_CONFIG
324# - $2: a text string which describes the test component
325common_test_full_no_cipher_with_psa_crypto () {
326 USE_CRYPTO_CONFIG="$1"
327 COMPONENT_DESCRIPTION="$2"
328
329 msg "build: $COMPONENT_DESCRIPTION"
330
331 scripts/config.py full
332 scripts/config.py unset MBEDTLS_CIPHER_C
333
334 if [ "$USE_CRYPTO_CONFIG" -eq 1 ]; then
335 # The built-in implementation of the following algs/key-types depends
336 # on CIPHER_C so we disable them.
337 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
338 # so we keep them enabled.
339 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
340 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CMAC
341 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
342 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
343 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CFB
344 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CTR
345 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
346 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_OFB
347 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128
348 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_STREAM_CIPHER
349 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
350 else
351 # Don't pull in cipher via PSA mechanisms
352 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
353 # Disable cipher modes/keys that make PSA depend on CIPHER_C.
354 # Keep CHACHA20 and CHACHAPOLY enabled since they do not depend on CIPHER_C.
355 scripts/config.py unset-all MBEDTLS_CIPHER_MODE
356 fi
357 # The following modules directly depends on CIPHER_C
358 scripts/config.py unset MBEDTLS_CMAC_C
359 scripts/config.py unset MBEDTLS_NIST_KW_C
360
361 make
362
363 # Ensure that CIPHER_C was not re-enabled
364 not grep mbedtls_cipher_init library/cipher.o
365
366 msg "test: $COMPONENT_DESCRIPTION"
367 make test
368}
369
370component_test_full_no_cipher_with_psa_crypto () {
371 common_test_full_no_cipher_with_psa_crypto 0 "full no CIPHER no CRYPTO_CONFIG"
372}
373
374component_test_full_no_cipher_with_psa_crypto_config () {
375 common_test_full_no_cipher_with_psa_crypto 1 "full no CIPHER"
376}
377
Minos Galanakisf7d1cb02024-07-30 17:25:31 +0100378component_test_full_no_bignum () {
379 msg "build: full minus bignum"
380 scripts/config.py full
381 scripts/config.py unset MBEDTLS_BIGNUM_C
382 # Direct dependencies of bignum
383 scripts/config.py unset MBEDTLS_ECP_C
384 scripts/config.py unset MBEDTLS_RSA_C
385 scripts/config.py unset MBEDTLS_DHM_C
386 # Direct dependencies of ECP
387 scripts/config.py unset MBEDTLS_ECDH_C
388 scripts/config.py unset MBEDTLS_ECDSA_C
389 scripts/config.py unset MBEDTLS_ECJPAKE_C
390 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
391 # Disable what auto-enables ECP_LIGHT
392 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
393 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
394 # Indirect dependencies of ECP
395 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
396 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
397 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
398 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
399 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
400 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
401 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
402 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
403 # Direct dependencies of DHM
404 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
405 # Direct dependencies of RSA
406 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
407 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
408 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
409 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
410 # PK and its dependencies
411 scripts/config.py unset MBEDTLS_PK_C
412 scripts/config.py unset MBEDTLS_PK_PARSE_C
413 scripts/config.py unset MBEDTLS_PK_WRITE_C
414 scripts/config.py unset MBEDTLS_X509_USE_C
415 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
416 scripts/config.py unset MBEDTLS_X509_CRL_PARSE_C
417 scripts/config.py unset MBEDTLS_X509_CSR_PARSE_C
418 scripts/config.py unset MBEDTLS_X509_CREATE_C
419 scripts/config.py unset MBEDTLS_X509_CRT_WRITE_C
420 scripts/config.py unset MBEDTLS_X509_CSR_WRITE_C
421 scripts/config.py unset MBEDTLS_PKCS7_C
422 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
423 scripts/config.py unset MBEDTLS_SSL_ASYNC_PRIVATE
424 scripts/config.py unset MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
425
426 make
427
428 msg "test: full minus bignum"
429 make test
430}
431
432component_test_tls1_2_default_stream_cipher_only () {
433 msg "build: default with only stream cipher"
434
435 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
436 scripts/config.py unset MBEDTLS_GCM_C
437 scripts/config.py unset MBEDTLS_CCM_C
438 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
439 #Disable TLS 1.3 (as no AEAD)
440 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
441 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
442 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
443 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
444 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
445 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
446 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
447 # Modules that depend on AEAD
448 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
449 scripts/config.py unset MBEDTLS_SSL_TICKET_C
450
451 make
452
453 msg "test: default with only stream cipher"
454 make test
455
456 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
457}
458
459component_test_tls1_2_default_stream_cipher_only_use_psa () {
460 msg "build: default with only stream cipher use psa"
461
462 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
463 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
464 scripts/config.py unset MBEDTLS_GCM_C
465 scripts/config.py unset MBEDTLS_CCM_C
466 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
467 #Disable TLS 1.3 (as no AEAD)
468 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
469 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
470 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
471 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
472 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
473 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
474 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
475 # Modules that depend on AEAD
476 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
477 scripts/config.py unset MBEDTLS_SSL_TICKET_C
478
479 make
480
481 msg "test: default with only stream cipher use psa"
482 make test
483
484 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
485}
486
487component_test_tls1_2_default_cbc_legacy_cipher_only () {
488 msg "build: default with only CBC-legacy cipher"
489
490 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
491 scripts/config.py unset MBEDTLS_GCM_C
492 scripts/config.py unset MBEDTLS_CCM_C
493 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
494 #Disable TLS 1.3 (as no AEAD)
495 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
496 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
497 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
498 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
499 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
500 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
501 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
502 # Modules that depend on AEAD
503 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
504 scripts/config.py unset MBEDTLS_SSL_TICKET_C
505
506 make
507
508 msg "test: default with only CBC-legacy cipher"
509 make test
510
511 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
512 tests/ssl-opt.sh -f "TLS 1.2"
513}
514
515component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
516 msg "build: default with only CBC-legacy cipher use psa"
517
518 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
519 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
520 scripts/config.py unset MBEDTLS_GCM_C
521 scripts/config.py unset MBEDTLS_CCM_C
522 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
523 #Disable TLS 1.3 (as no AEAD)
524 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
525 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
526 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
527 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
528 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
529 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
530 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
531 # Modules that depend on AEAD
532 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
533 scripts/config.py unset MBEDTLS_SSL_TICKET_C
534
535 make
536
537 msg "test: default with only CBC-legacy cipher use psa"
538 make test
539
540 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
541 tests/ssl-opt.sh -f "TLS 1.2"
542}
543
544component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
545 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
546
547 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
548 scripts/config.py unset MBEDTLS_GCM_C
549 scripts/config.py unset MBEDTLS_CCM_C
550 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
551 #Disable TLS 1.3 (as no AEAD)
552 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
553 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
554 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
555 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
556 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
557 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
558 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
559 # Modules that depend on AEAD
560 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
561 scripts/config.py unset MBEDTLS_SSL_TICKET_C
562
563 make
564
565 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
566 make test
567
568 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
569 tests/ssl-opt.sh -f "TLS 1.2"
570}
571
572component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
573 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
574
575 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
576 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
577 scripts/config.py unset MBEDTLS_GCM_C
578 scripts/config.py unset MBEDTLS_CCM_C
579 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
580 #Disable TLS 1.3 (as no AEAD)
581 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
582 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
583 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
584 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
585 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
586 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
587 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
588 # Modules that depend on AEAD
589 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
590 scripts/config.py unset MBEDTLS_SSL_TICKET_C
591
592 make
593
594 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
595 make test
596
597 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
598 tests/ssl-opt.sh -f "TLS 1.2"
599}
600
601# We're not aware of any other (open source) implementation of EC J-PAKE in TLS
602# that we could use for interop testing. However, we now have sort of two
603# implementations ourselves: one using PSA, the other not. At least test that
604# these two interoperate with each other.
605component_test_tls1_2_ecjpake_compatibility () {
606 msg "build: TLS1.2 server+client w/ EC-JPAKE w/o USE_PSA"
607 scripts/config.py set MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
608 # Explicitly make lib first to avoid a race condition:
609 # https://github.com/Mbed-TLS/mbedtls/issues/8229
610 make lib
611 make -C programs ssl/ssl_server2 ssl/ssl_client2
612 cp programs/ssl/ssl_server2 s2_no_use_psa
613 cp programs/ssl/ssl_client2 c2_no_use_psa
614
615 msg "build: TLS1.2 server+client w/ EC-JPAKE w/ USE_PSA"
616 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
617 make clean
618 make lib
619 make -C programs ssl/ssl_server2 ssl/ssl_client2
620 make -C programs test/udp_proxy test/query_compile_time_config
621
622 msg "test: server w/o USE_PSA - client w/ USE_PSA, text password"
623 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
624 msg "test: server w/o USE_PSA - client w/ USE_PSA, opaque password"
625 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password client only, working, TLS"
626 msg "test: client w/o USE_PSA - server w/ USE_PSA, text password"
627 P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
628 msg "test: client w/o USE_PSA - server w/ USE_PSA, opaque password"
629 P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password server only, working, TLS"
630
631 rm s2_no_use_psa c2_no_use_psa
632}
633
Minos Galanakisf7d1cb02024-07-30 17:25:31 +0100634component_test_small_ssl_out_content_len () {
635 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
636 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
637 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
638 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
639 make
640
641 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
642 tests/ssl-opt.sh -f "Max fragment\|Large packet"
643}
644
645component_test_small_ssl_in_content_len () {
646 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
647 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
648 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
649 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
650 make
651
652 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
653 tests/ssl-opt.sh -f "Max fragment"
654}
655
656component_test_small_ssl_dtls_max_buffering () {
657 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
658 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
659 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
660 make
661
662 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
663 tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
664}
665
666component_test_small_mbedtls_ssl_dtls_max_buffering () {
667 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
668 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
669 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
670 make
671
672 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
673 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
674}
675
Minos Galanakisf7d1cb02024-07-30 17:25:31 +0100676component_test_full_cmake_clang () {
677 msg "build: cmake, full config, clang" # ~ 50s
678 scripts/config.py full
679 CC=clang CXX=clang cmake -D CMAKE_BUILD_TYPE:String=Release -D ENABLE_TESTING=On -D TEST_CPP=1 .
680 make
681
682 msg "test: main suites (full config, clang)" # ~ 5s
683 make test
684
685 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
686 programs/test/cpp_dummy_build
687
688 msg "test: metatests (clang)"
689 tests/scripts/run-metatests.sh any pthread
690
691 msg "program demos (full config, clang)" # ~10s
692 tests/scripts/run_demos.py
693
694 msg "test: psa_constant_names (full config, clang)" # ~ 1s
695 tests/scripts/test_psa_constant_names.py
696
697 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
698 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
699}
700
701skip_suites_without_constant_flow () {
702 # Skip the test suites that don't have any constant-flow annotations.
703 # This will need to be adjusted if we ever start declaring things as
704 # secret from macros or functions inside tests/include or tests/src.
705 SKIP_TEST_SUITES=$(
706 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
707 sed 's/test_suite_//; s/\.function$//' |
708 tr '\n' ,)
709 export SKIP_TEST_SUITES
710}
711
712skip_all_except_given_suite () {
713 # Skip all but the given test suite
714 SKIP_TEST_SUITES=$(
715 ls -1 tests/suites/test_suite_*.function |
716 grep -v $1.function |
717 sed 's/tests.suites.test_suite_//; s/\.function$//' |
718 tr '\n' ,)
719 export SKIP_TEST_SUITES
720}
721
722component_test_memsan_constant_flow () {
723 # This tests both (1) accesses to undefined memory, and (2) branches or
724 # memory access depending on secret values. To distinguish between those:
725 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
726 # - or alternatively, change the build type to MemSanDbg, which enables
727 # origin tracking and nicer stack traces (which are useful for debugging
728 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
729 msg "build: cmake MSan (clang), full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
730 scripts/config.py full
731 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
732 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
733 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
734 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
735 make
736
737 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO, Msan + constant flow)"
738 make test
739}
740
741component_test_memsan_constant_flow_psa () {
742 # This tests both (1) accesses to undefined memory, and (2) branches or
743 # memory access depending on secret values. To distinguish between those:
744 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
745 # - or alternatively, change the build type to MemSanDbg, which enables
746 # origin tracking and nicer stack traces (which are useful for debugging
747 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
748 msg "build: cmake MSan (clang), full config with constant flow testing"
749 scripts/config.py full
750 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
751 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
752 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
753 make
754
755 msg "test: main suites (Msan + constant flow)"
756 make test
757}
758
759component_release_test_valgrind_constant_flow () {
760 # This tests both (1) everything that valgrind's memcheck usually checks
761 # (heap buffer overflows, use of uninitialized memory, use-after-free,
762 # etc.) and (2) branches or memory access depending on secret values,
763 # which will be reported as uninitialized memory. To distinguish between
764 # secret and actually uninitialized:
765 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
766 # - or alternatively, build with debug info and manually run the offending
767 # test suite with valgrind --track-origins=yes, then check if the origin
768 # was TEST_CF_SECRET() or something else.
769 msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
770 scripts/config.py full
771 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
772 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
773 skip_suites_without_constant_flow
774 cmake -D CMAKE_BUILD_TYPE:String=Release .
775 make
776
777 # this only shows a summary of the results (how many of each type)
778 # details are left in Testing/<date>/DynamicAnalysis.xml
779 msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, valgrind + constant flow)"
780 make memcheck
781
782 # Test asm path in constant time module - by default, it will test the plain C
783 # path under Valgrind or Memsan. Running only the constant_time tests is fast (<1s)
784 msg "test: valgrind asm constant_time"
785 scripts/config.py --force set MBEDTLS_TEST_CONSTANT_FLOW_ASM
786 skip_all_except_given_suite test_suite_constant_time
787 cmake -D CMAKE_BUILD_TYPE:String=Release .
788 make clean
789 make
790 make memcheck
791}
792
793component_release_test_valgrind_constant_flow_psa () {
794 # This tests both (1) everything that valgrind's memcheck usually checks
795 # (heap buffer overflows, use of uninitialized memory, use-after-free,
796 # etc.) and (2) branches or memory access depending on secret values,
797 # which will be reported as uninitialized memory. To distinguish between
798 # secret and actually uninitialized:
799 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
800 # - or alternatively, build with debug info and manually run the offending
801 # test suite with valgrind --track-origins=yes, then check if the origin
802 # was TEST_CF_SECRET() or something else.
803 msg "build: cmake release GCC, full config with constant flow testing"
804 scripts/config.py full
805 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
806 skip_suites_without_constant_flow
807 cmake -D CMAKE_BUILD_TYPE:String=Release .
808 make
809
810 # this only shows a summary of the results (how many of each type)
811 # details are left in Testing/<date>/DynamicAnalysis.xml
812 msg "test: some suites (valgrind + constant flow)"
813 make memcheck
814}
815
816component_test_tsan () {
817 msg "build: TSan (clang)"
818 scripts/config.py full
819 scripts/config.py set MBEDTLS_THREADING_C
820 scripts/config.py set MBEDTLS_THREADING_PTHREAD
821 # Self-tests do not currently use multiple threads.
822 scripts/config.py unset MBEDTLS_SELF_TEST
823
824 # The deprecated MBEDTLS_PSA_CRYPTO_SE_C interface is not thread safe.
825 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
826
827 CC=clang cmake -D CMAKE_BUILD_TYPE:String=TSan .
828 make
829
830 msg "test: main suites (TSan)"
831 make test
832}
833
834component_test_default_no_deprecated () {
835 # Test that removing the deprecated features from the default
836 # configuration leaves something consistent.
837 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
838 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
839 make CFLAGS='-O -Werror -Wall -Wextra'
840
841 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
842 make test
843}
844
845component_test_full_no_deprecated () {
846 msg "build: make, full_no_deprecated config" # ~ 30s
847 scripts/config.py full_no_deprecated
848 make CFLAGS='-O -Werror -Wall -Wextra'
849
850 msg "test: make, full_no_deprecated config" # ~ 5s
851 make test
852
853 msg "test: ensure that X509 has no direct dependency on BIGNUM_C"
854 not grep mbedtls_mpi library/libmbedx509.a
855}
856
857component_test_full_no_deprecated_deprecated_warning () {
858 # Test that there is nothing deprecated in "full_no_deprecated".
859 # A deprecated feature would trigger a warning (made fatal) from
860 # MBEDTLS_DEPRECATED_WARNING.
861 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
862 scripts/config.py full_no_deprecated
863 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
864 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
865 make CFLAGS='-O -Werror -Wall -Wextra'
866
867 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
868 make test
869}
870
871component_test_full_deprecated_warning () {
872 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
873 # with only certain whitelisted types of warnings.
874 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
875 scripts/config.py full
876 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
877 # Expect warnings from '#warning' directives in check_config.h.
878 # Note that gcc is required to allow the use of -Wno-error=cpp, which allows us to
879 # display #warning messages without them being treated as errors.
880 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
881
882 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
883 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
884 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
885 # Expect warnings from '#warning' directives in check_config.h and
886 # from the use of deprecated functions in test suites.
887 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -Wno-error=cpp -DMBEDTLS_TEST_DEPRECATED' tests
888
889 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
890 make test
891
892 msg "program demos: full config + MBEDTLS_TEST_DEPRECATED" # ~10s
893 tests/scripts/run_demos.py
894}
895
Minos Galanakisf7d1cb02024-07-30 17:25:31 +0100896component_build_baremetal () {
897 msg "build: make, baremetal config"
898 scripts/config.py baremetal
899 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
900}
901support_build_baremetal () {
902 # Older Glibc versions include time.h from other headers such as stdlib.h,
903 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
904 # problem, Ubuntu 18.04 is ok.
905 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
906}
907
Minos Galanakisf7d1cb02024-07-30 17:25:31 +0100908component_test_depends_py_kex () {
909 msg "test/build: depends.py kex (gcc)"
910 tests/scripts/depends.py kex --unset-use-psa
911}
912
Minos Galanakisf7d1cb02024-07-30 17:25:31 +0100913component_test_depends_py_kex_psa () {
914 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
915 tests/scripts/depends.py kex
916}
917
Minos Galanakisf7d1cb02024-07-30 17:25:31 +0100918component_build_dhm_alt () {
919 msg "build: MBEDTLS_DHM_ALT" # ~30s
920 scripts/config.py full
921 scripts/config.py set MBEDTLS_DHM_ALT
922 # debug.c currently references mbedtls_dhm_context fields directly.
923 scripts/config.py unset MBEDTLS_DEBUG_C
924 # We can only compile, not link, since we don't have any implementations
925 # suitable for testing with the dummy alt headers.
926 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
927}
928
929component_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 Galanakisf7d1cb02024-07-30 17:25:31 +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 Galanakisf7d1cb02024-07-30 17:25:31 +0100998component_test_psa_crypto_config_accel_hash_keep_builtins () {
999 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
1000 # This component ensures that all the test cases for
1001 # md_psa_dynamic_dispatch with legacy+driver in test_suite_md are run.
1002
1003 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
1004 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
1005 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
1006
1007 # Start from default config (no USE_PSA)
1008 helper_libtestdriver1_adjust_config "default"
1009
1010 helper_libtestdriver1_make_drivers "$loc_accel_list"
1011
1012 helper_libtestdriver1_make_main "$loc_accel_list"
1013
1014 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
1015 make test
1016}
1017
Minos Galanakisf7d1cb02024-07-30 17:25:31 +01001018# This should be renamed to test and updated once the accelerator ECDH code is in place and ready to test.
1019component_build_psa_accel_alg_ecdh () {
1020 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
1021 scripts/config.py full
1022 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1023 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1024 scripts/config.py unset MBEDTLS_ECDH_C
1025 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1026 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1027 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1028 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1029 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1030 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1031 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
1032}
1033
1034# This should be renamed to test and updated once the accelerator HMAC code is in place and ready to test.
1035component_build_psa_accel_alg_hmac () {
1036 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
1037 scripts/config.py full
1038 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1039 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1040 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1041 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
1042}
1043
1044# This should be renamed to test and updated once the accelerator HKDF code is in place and ready to test.
1045component_build_psa_accel_alg_hkdf () {
1046 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
1047 scripts/config.py full
1048 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1049 scripts/config.py unset MBEDTLS_HKDF_C
1050 # Make sure to unset TLS1_3 since it requires HKDF_C and will not build properly without it.
1051 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1052 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1053 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
1054}
1055
1056# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
1057component_build_psa_accel_alg_md5 () {
1058 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - other hashes"
1059 scripts/config.py full
1060 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1061 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1062 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
1063 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
1064 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
1065 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
1066 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
1067 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
1068 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
1069 scripts/config.py unset MBEDTLS_LMS_C
1070 scripts/config.py unset MBEDTLS_LMS_PRIVATE
1071 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1072 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
1073}
1074
1075# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
1076component_build_psa_accel_alg_ripemd160 () {
1077 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - other hashes"
1078 scripts/config.py full
1079 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1080 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1081 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
1082 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
1083 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
1084 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
1085 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
1086 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
1087 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
1088 scripts/config.py unset MBEDTLS_LMS_C
1089 scripts/config.py unset MBEDTLS_LMS_PRIVATE
1090 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1091 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
1092}
1093
1094# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
1095component_build_psa_accel_alg_sha1 () {
1096 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - other hashes"
1097 scripts/config.py full
1098 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1099 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1100 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
1101 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
1102 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
1103 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
1104 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
1105 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
1106 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
1107 scripts/config.py unset MBEDTLS_LMS_C
1108 scripts/config.py unset MBEDTLS_LMS_PRIVATE
1109 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1110 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
1111}
1112
1113# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
1114component_build_psa_accel_alg_sha224 () {
1115 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
1116 scripts/config.py full
1117 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1118 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1119 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
1120 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
1121 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
1122 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
1123 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
1124 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
1125 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1126 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
1127}
1128
1129# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
1130component_build_psa_accel_alg_sha256 () {
1131 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - other hashes"
1132 scripts/config.py full
1133 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1134 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1135 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
1136 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
1137 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
1138 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
1139 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
1140 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
1141 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1142 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
1143}
1144
1145# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
1146component_build_psa_accel_alg_sha384 () {
1147 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
1148 scripts/config.py full
1149 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1150 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1151 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
1152 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
1153 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
1154 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
1155 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
1156 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
1157 scripts/config.py unset MBEDTLS_LMS_C
1158 scripts/config.py unset MBEDTLS_LMS_PRIVATE
1159 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1160 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
1161}
1162
1163# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
1164component_build_psa_accel_alg_sha512 () {
1165 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
1166 scripts/config.py full
1167 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1168 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1169 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
1170 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
1171 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
1172 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
1173 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
1174 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
1175 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
1176 scripts/config.py unset MBEDTLS_LMS_C
1177 scripts/config.py unset MBEDTLS_LMS_PRIVATE
1178 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1179 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
1180}
1181
1182# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
1183component_build_psa_accel_alg_rsa_pkcs1v15_crypt () {
1184 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1185 scripts/config.py full
1186 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1187 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1188 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
1189 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1190 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
1191 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
1192 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1193 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
1194}
1195
1196# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
1197component_build_psa_accel_alg_rsa_pkcs1v15_sign () {
1198 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1199 scripts/config.py full
1200 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1201 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1202 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
1203 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1204 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
1205 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
1206 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1207 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
1208}
1209
1210# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
1211component_build_psa_accel_alg_rsa_oaep () {
1212 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1213 scripts/config.py full
1214 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1215 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1216 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_OAEP 1
1217 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1218 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1219 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
1220 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1221 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
1222}
1223
1224# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
1225component_build_psa_accel_alg_rsa_pss () {
1226 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1227 scripts/config.py full
1228 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1229 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1230 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
1231 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1232 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1233 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
1234 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1235 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
1236}
1237
1238# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
1239component_build_psa_accel_key_type_rsa_key_pair () {
1240 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_xxx + PSA_WANT_ALG_RSA_PSS"
1241 scripts/config.py full
1242 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1243 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1244 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
1245 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC 1
1246 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT 1
1247 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT 1
1248 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE 1
1249 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1250 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"
1251}
1252
1253# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
1254component_build_psa_accel_key_type_rsa_public_key () {
1255 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
1256 scripts/config.py full
1257 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1258 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1259 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
1260 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
1261 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1262 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"
1263}
1264
Minos Galanakisf7d1cb02024-07-30 17:25:31 +01001265component_build_tfm () {
1266 # Check that the TF-M configuration can build cleanly with various
1267 # warning flags enabled. We don't build or run tests, since the
1268 # TF-M configuration needs a TF-M platform. A tweaked version of
1269 # the configuration that works on mainstream platforms is in
1270 # configs/config-tfm.h, tested via test-ref-configs.pl.
1271 cp configs/config-tfm.h "$CONFIG_H"
1272
1273 msg "build: TF-M config, clang, armv7-m thumb2"
1274 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"
1275
1276 msg "build: TF-M config, gcc native build"
1277 make clean
1278 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"
1279}
1280
Minos Galanakisf7d1cb02024-07-30 17:25:31 +01001281component_test_no_platform () {
1282 # Full configuration build, without platform support, file IO and net sockets.
1283 # This should catch missing mbedtls_printf definitions, and by disabling file
1284 # IO, it should catch missing '#include <stdio.h>'
1285 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
1286 scripts/config.py full_no_platform
1287 scripts/config.py unset MBEDTLS_PLATFORM_C
1288 scripts/config.py unset MBEDTLS_NET_C
1289 scripts/config.py unset MBEDTLS_FS_IO
1290 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
1291 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1292 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
1293 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1294 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1295 # to re-enable platform integration features otherwise disabled in C99 builds
1296 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1297 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
1298}
1299
1300component_build_no_std_function () {
1301 # catch compile bugs in _uninit functions
1302 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
1303 scripts/config.py full
1304 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1305 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1306 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1307 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
1308 make
1309}
1310
1311component_build_no_ssl_srv () {
1312 msg "build: full config except SSL server, make, gcc" # ~ 30s
1313 scripts/config.py full
1314 scripts/config.py unset MBEDTLS_SSL_SRV_C
1315 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
1316}
1317
1318component_build_no_ssl_cli () {
1319 msg "build: full config except SSL client, make, gcc" # ~ 30s
1320 scripts/config.py full
1321 scripts/config.py unset MBEDTLS_SSL_CLI_C
1322 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
1323}
1324
1325component_build_no_sockets () {
1326 # Note, C99 compliance can also be tested with the sockets support disabled,
1327 # as that requires a POSIX platform (which isn't the same as C99).
1328 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
1329 scripts/config.py full
1330 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
1331 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
1332 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
1333}
1334
1335component_test_memory_buffer_allocator_backtrace () {
1336 msg "build: default config with memory buffer allocator and backtrace enabled"
1337 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1338 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1339 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
1340 scripts/config.py set MBEDTLS_MEMORY_DEBUG
1341 cmake -DCMAKE_BUILD_TYPE:String=Release .
1342 make
1343
1344 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
1345 make test
1346}
1347
1348component_test_memory_buffer_allocator () {
1349 msg "build: default config with memory buffer allocator"
1350 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1351 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1352 cmake -DCMAKE_BUILD_TYPE:String=Release .
1353 make
1354
1355 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1356 make test
1357
1358 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
1359 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
1360 tests/ssl-opt.sh -e '^DTLS proxy'
1361}
1362
1363component_test_no_max_fragment_length () {
1364 # Run max fragment length tests with MFL disabled
1365 msg "build: default config except MFL extension (ASan build)" # ~ 30s
1366 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1367 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1368 make
1369
1370 msg "test: ssl-opt.sh, MFL-related tests"
1371 tests/ssl-opt.sh -f "Max fragment length"
1372}
1373
1374component_test_asan_remove_peer_certificate () {
1375 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
1376 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
1377 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1378 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1379 make
1380
1381 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1382 make test
1383
1384 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1385 tests/ssl-opt.sh
1386
1387 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1388 tests/compat.sh
1389
1390 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
1391 tests/context-info.sh
1392}
1393
1394component_test_no_max_fragment_length_small_ssl_out_content_len () {
1395 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
1396 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1397 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1398 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
1399 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1400 make
1401
1402 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
1403 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
1404
1405 msg "test: context-info.sh (disabled MFL extension case)"
1406 tests/context-info.sh
1407}
1408
1409component_test_variable_ssl_in_out_buffer_len () {
1410 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
1411 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1412 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1413 make
1414
1415 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1416 make test
1417
1418 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1419 tests/ssl-opt.sh
1420
1421 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
1422 tests/compat.sh
1423}
1424
1425component_test_dtls_cid_legacy () {
1426 msg "build: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled (ASan build)"
1427 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 1
1428
1429 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1430 make
1431
1432 msg "test: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy)"
1433 make test
1434
1435 msg "test: ssl-opt.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
1436 tests/ssl-opt.sh
1437
1438 msg "test: compat.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
1439 tests/compat.sh
1440}
1441
1442component_test_ssl_alloc_buffer_and_mfl () {
1443 msg "build: default config with memory buffer allocator and MFL extension"
1444 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
1445 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1446 scripts/config.py set MBEDTLS_MEMORY_DEBUG
1447 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
1448 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
1449 cmake -DCMAKE_BUILD_TYPE:String=Release .
1450 make
1451
1452 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
1453 make test
1454
1455 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
1456 tests/ssl-opt.sh -f "Handshake memory usage"
1457}
1458
1459component_test_when_no_ciphersuites_have_mac () {
1460 msg "build: when no ciphersuites have MAC"
1461 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1462 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1463 scripts/config.py unset MBEDTLS_CMAC_C
1464 make
1465
1466 msg "test: !MBEDTLS_SSL_SOME_SUITES_USE_MAC"
1467 make test
1468
1469 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_SUITES_USE_MAC"
1470 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
1471}
1472
1473component_test_no_date_time () {
1474 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
1475 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
1476 cmake -D CMAKE_BUILD_TYPE:String=Check .
1477 make
1478
1479 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
1480 make test
1481}
1482
1483component_test_platform_calloc_macro () {
1484 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1485 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
1486 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
1487 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
1488 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1489 make
1490
1491 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
1492 make test
1493}
1494
1495component_test_malloc_0_null () {
1496 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
1497 scripts/config.py full
1498 make CC=$ASAN_CC CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"$PWD/tests/configs/user-config-malloc-0-null.h\"' $ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1499
1500 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
1501 make test
1502
1503 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
1504 # Just the calloc selftest. "make test" ran the others as part of the
1505 # test suites.
1506 programs/test/selftest calloc
1507
1508 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
1509 # Run a subset of the tests. The choice is a balance between coverage
1510 # and time (including time indirectly wasted due to flaky tests).
1511 # The current choice is to skip tests whose description includes
1512 # "proxy", which is an approximation of skipping tests that use the
1513 # UDP proxy, which tend to be slower and flakier.
1514 tests/ssl-opt.sh -e 'proxy'
1515}
1516
1517support_test_aesni () {
1518 # Check that gcc targets x86_64 (we can build AESNI), and check for
1519 # AESNI support on the host (we can run AESNI).
1520 #
1521 # The name of this function is possibly slightly misleading, but needs to align
1522 # with the name of the corresponding test, component_test_aesni.
1523 #
1524 # In principle 32-bit x86 can support AESNI, but our implementation does not
1525 # support 32-bit x86, so we check for x86-64.
1526 # We can only grep /proc/cpuinfo on Linux, so this also checks for Linux
1527 (gcc -v 2>&1 | grep Target | grep -q x86_64) &&
1528 [[ "$HOSTTYPE" == "x86_64" && "$OSTYPE" == "linux-gnu" ]] &&
1529 (lscpu | grep -qw aes)
1530}
1531
1532component_test_aesni () { # ~ 60s
1533 # This tests the two AESNI implementations (intrinsics and assembly), and also the plain C
1534 # fallback. It also tests the logic that is used to select which implementation(s) to build.
1535 #
1536 # This test does not require the host to have support for AESNI (if it doesn't, the run-time
1537 # AESNI detection will fallback to the plain C implementation, so the tests will instead
1538 # exercise the plain C impl).
1539
1540 msg "build: default config with different AES implementations"
1541 scripts/config.py set MBEDTLS_AESNI_C
1542 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
1543 scripts/config.py set MBEDTLS_HAVE_ASM
1544
1545 # test the intrinsics implementation
1546 msg "AES tests, test intrinsics"
1547 make clean
1548 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
1549 # check that we built intrinsics - this should be used by default when supported by the compiler
1550 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
1551
1552 # test the asm implementation
1553 msg "AES tests, test assembly"
1554 make clean
1555 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mno-pclmul -mno-sse2 -mno-aes'
1556 # check that we built assembly - this should be built if the compiler does not support intrinsics
1557 ./programs/test/selftest aes | grep "AESNI code" | grep -q "assembly"
1558
1559 # test the plain C implementation
1560 scripts/config.py unset MBEDTLS_AESNI_C
1561 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
1562 msg "AES tests, plain C"
1563 make clean
1564 make CC=gcc CFLAGS='-O2 -Werror'
1565 # check that there is no AESNI code present
1566 ./programs/test/selftest aes | not grep -q "AESNI code"
1567 not grep -q "AES note: using AESNI" ./programs/test/selftest
1568 grep -q "AES note: built-in implementation." ./programs/test/selftest
1569
1570 # test the intrinsics implementation
1571 scripts/config.py set MBEDTLS_AESNI_C
1572 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
1573 msg "AES tests, test AESNI only"
1574 make clean
1575 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
1576 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
1577 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
1578 grep -q "AES note: using AESNI" ./programs/test/selftest
1579 not grep -q "AES note: built-in implementation." ./programs/test/selftest
1580}
1581
Minos Galanakisf7d1cb02024-07-30 17:25:31 +01001582support_test_aesni_m32 () {
1583 support_test_m32_no_asm && (lscpu | grep -qw aes)
1584}
1585
1586component_test_aesni_m32 () { # ~ 60s
1587 # This tests are duplicated from component_test_aesni for i386 target
1588 #
1589 # AESNI intrinsic code supports i386 and assembly code does not support it.
1590
1591 msg "build: default config with different AES implementations"
1592 scripts/config.py set MBEDTLS_AESNI_C
1593 scripts/config.py set MBEDTLS_PADLOCK_C
1594 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
1595 scripts/config.py set MBEDTLS_HAVE_ASM
1596
1597 # test the intrinsics implementation with gcc
1598 msg "AES tests, test intrinsics (gcc)"
1599 make clean
1600 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra' LDFLAGS='-m32'
1601 # check that we built intrinsics - this should be used by default when supported by the compiler
1602 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
1603 grep -q "AES note: using AESNI" ./programs/test/selftest
1604 grep -q "AES note: built-in implementation." ./programs/test/selftest
1605 grep -q "AES note: using VIA Padlock" ./programs/test/selftest
1606 grep -q mbedtls_aesni_has_support ./programs/test/selftest
1607
1608 scripts/config.py set MBEDTLS_AESNI_C
1609 scripts/config.py unset MBEDTLS_PADLOCK_C
1610 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
1611 msg "AES tests, test AESNI only"
1612 make clean
1613 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
1614 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
1615 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
1616 grep -q "AES note: using AESNI" ./programs/test/selftest
1617 not grep -q "AES note: built-in implementation." ./programs/test/selftest
1618 not grep -q "AES note: using VIA Padlock" ./programs/test/selftest
1619 not grep -q mbedtls_aesni_has_support ./programs/test/selftest
1620}
1621
1622support_test_aesni_m32_clang () {
1623 # clang >= 4 is required to build with target attributes
1624 support_test_aesni_m32 && [[ $(clang_version) -ge 4 ]]
1625}
1626
1627component_test_aesni_m32_clang () {
1628
1629 scripts/config.py set MBEDTLS_AESNI_C
1630 scripts/config.py set MBEDTLS_PADLOCK_C
1631 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
1632 scripts/config.py set MBEDTLS_HAVE_ASM
1633
1634 # test the intrinsics implementation with clang
1635 msg "AES tests, test intrinsics (clang)"
1636 make clean
1637 make CC=clang CFLAGS='-m32 -Werror -Wall -Wextra' LDFLAGS='-m32'
1638 # check that we built intrinsics - this should be used by default when supported by the compiler
1639 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
1640 grep -q "AES note: using AESNI" ./programs/test/selftest
1641 grep -q "AES note: built-in implementation." ./programs/test/selftest
1642 grep -q "AES note: using VIA Padlock" ./programs/test/selftest
1643 grep -q mbedtls_aesni_has_support ./programs/test/selftest
1644}
1645
Minos Galanakisf7d1cb02024-07-30 17:25:31 +01001646support_build_aes_armce () {
1647 # clang >= 11 is required to build with AES extensions
1648 [[ $(clang_version) -ge 11 ]]
1649}
1650
1651component_build_aes_armce () {
1652 # Test variations of AES with Armv8 crypto extensions
1653 scripts/config.py set MBEDTLS_AESCE_C
1654 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
1655
1656 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, aarch64"
1657 make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
1658
1659 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, arm"
1660 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
1661
1662 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, thumb"
1663 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
1664
1665 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
1666
1667 msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, aarch64"
1668 make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
1669
1670 msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, arm"
1671 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
1672
1673 msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, thumb"
1674 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
1675
1676 # test for presence of AES instructions
1677 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
1678 msg "clang, test A32 crypto instructions built"
1679 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
1680 grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
1681 msg "clang, test T32 crypto instructions built"
1682 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
1683 grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
1684 msg "clang, test aarch64 crypto instructions built"
1685 make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
1686 grep -E 'aes[a-z]+\s*[qv]' library/aesce.o
1687
1688 # test for absence of AES instructions
1689 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
1690 scripts/config.py unset MBEDTLS_AESCE_C
1691 msg "clang, test A32 crypto instructions not built"
1692 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
1693 not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
1694 msg "clang, test T32 crypto instructions not built"
1695 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
1696 not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
1697 msg "clang, test aarch64 crypto instructions not built"
1698 make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
1699 not grep -E 'aes[a-z]+\s*[qv]' library/aesce.o
1700}
1701
1702support_build_sha_armce () {
1703 # clang >= 4 is required to build with SHA extensions
1704 [[ $(clang_version) -ge 4 ]]
1705}
1706
1707component_build_sha_armce () {
1708 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
1709
1710
1711 # Test variations of SHA256 Armv8 crypto extensions
1712 scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
1713 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, aarch64"
1714 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
1715 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, arm"
1716 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
1717 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
1718
1719
1720 # test the deprecated form of the config option
1721 scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
1722 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY clang, thumb"
1723 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
1724 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
1725
1726 scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
1727 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT clang, aarch64"
1728 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
1729 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
1730
1731
1732 # test the deprecated form of the config option
1733 scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
1734 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, arm"
1735 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -std=c99"
1736 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, thumb"
1737 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
1738 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
1739
1740
1741 # examine the disassembly for presence of SHA instructions
1742 for opt in MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT; do
1743 scripts/config.py set ${opt}
1744 msg "${opt} clang, test A32 crypto instructions built"
1745 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
1746 grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
1747
1748 msg "${opt} clang, test T32 crypto instructions built"
1749 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
1750 grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
1751
1752 msg "${opt} clang, test aarch64 crypto instructions built"
1753 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
1754 grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.o
1755 scripts/config.py unset ${opt}
1756 done
1757
1758
1759 # examine the disassembly for absence of SHA instructions
1760 msg "clang, test A32 crypto instructions not built"
1761 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
1762 not grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
1763
1764 msg "clang, test T32 crypto instructions not built"
1765 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
1766 not grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
1767
1768 msg "clang, test aarch64 crypto instructions not built"
1769 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
1770 not grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.o
1771}
1772
1773# For timebeing, no VIA Padlock platform available.
1774component_build_aes_via_padlock () {
1775
1776 msg "AES:VIA PadLock, build with default configuration."
1777 scripts/config.py unset MBEDTLS_AESNI_C
1778 scripts/config.py set MBEDTLS_PADLOCK_C
1779 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
1780 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
1781 grep -q mbedtls_padlock_has_support ./programs/test/selftest
1782
1783}
1784
1785support_build_aes_via_padlock_only () {
1786 ( [ "$MBEDTLS_TEST_PLATFORM" == "Linux-x86_64" ] || \
1787 [ "$MBEDTLS_TEST_PLATFORM" == "Linux-amd64" ] ) && \
1788 [ "`dpkg --print-foreign-architectures`" == "i386" ]
1789}
1790
Minos Galanakisf7d1cb02024-07-30 17:25:31 +01001791component_build_mbedtls_config_file () {
1792 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
1793 scripts/config.py -w full_config.h full
1794 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
1795 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
1796 # Make sure this feature is enabled. We'll disable it in the next phase.
1797 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
1798 make clean
1799
1800 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
1801 # In the user config, disable one feature (for simplicity, pick a feature
1802 # that nothing else depends on).
1803 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
1804 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
1805 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
1806
1807 rm -f user_config.h full_config.h
1808}
1809
Minos Galanakisf7d1cb02024-07-30 17:25:31 +01001810component_test_m32_no_asm () {
1811 # Build without assembly, so as to use portable C code (in a 32-bit
1812 # build) and not the i386-specific inline assembly.
1813 #
1814 # Note that we require gcc, because clang Asan builds fail to link for
1815 # this target (cannot find libclang_rt.lsan-i386.a - this is a known clang issue).
1816 msg "build: i386, make, gcc, no asm (ASan build)" # ~ 30s
1817 scripts/config.py full
1818 scripts/config.py unset MBEDTLS_HAVE_ASM
1819 scripts/config.py unset MBEDTLS_PADLOCK_C
1820 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
1821 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
1822
1823 msg "test: i386, make, gcc, no asm (ASan build)"
1824 make test
1825}
1826support_test_m32_no_asm () {
1827 case $(uname -m) in
1828 amd64|x86_64) true;;
1829 *) false;;
1830 esac
1831}
1832
1833component_test_m32_o2 () {
1834 # Build with optimization, to use the i386 specific inline assembly
1835 # and go faster for tests.
1836 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
1837 scripts/config.py full
1838 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
1839 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
1840
1841 msg "test: i386, make, gcc -O2 (ASan build)"
1842 make test
1843
1844 msg "test ssl-opt.sh, i386, make, gcc-O2"
1845 tests/ssl-opt.sh
1846}
1847support_test_m32_o2 () {
1848 support_test_m32_no_asm "$@"
1849}
1850
1851component_test_m32_everest () {
1852 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
1853 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1854 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
1855 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
1856
1857 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1858 make test
1859
1860 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
1861 tests/ssl-opt.sh -f ECDH
1862
1863 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1864 # Exclude some symmetric ciphers that are redundant here to gain time.
1865 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
1866}
1867support_test_m32_everest () {
1868 support_test_m32_no_asm "$@"
1869}
1870
1871component_test_mx32 () {
1872 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
1873 scripts/config.py full
1874 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
1875
1876 msg "test: 64-bit ILP32, make, gcc"
1877 make test
1878}
1879support_test_mx32 () {
1880 case $(uname -m) in
1881 amd64|x86_64) true;;
1882 *) false;;
1883 esac
1884}
1885
Minos Galanakisf7d1cb02024-07-30 17:25:31 +01001886component_test_have_int32 () {
1887 msg "build: gcc, force 32-bit bignum limbs"
1888 scripts/config.py unset MBEDTLS_HAVE_ASM
1889 scripts/config.py unset MBEDTLS_AESNI_C
1890 scripts/config.py unset MBEDTLS_PADLOCK_C
1891 scripts/config.py unset MBEDTLS_AESCE_C
1892 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
1893
1894 msg "test: gcc, force 32-bit bignum limbs"
1895 make test
1896}
1897
1898component_test_have_int64 () {
1899 msg "build: gcc, force 64-bit bignum limbs"
1900 scripts/config.py unset MBEDTLS_HAVE_ASM
1901 scripts/config.py unset MBEDTLS_AESNI_C
1902 scripts/config.py unset MBEDTLS_PADLOCK_C
1903 scripts/config.py unset MBEDTLS_AESCE_C
1904 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
1905
1906 msg "test: gcc, force 64-bit bignum limbs"
1907 make test
1908}
1909
1910component_test_have_int32_cmake_new_bignum () {
1911 msg "build: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
1912 scripts/config.py unset MBEDTLS_HAVE_ASM
1913 scripts/config.py unset MBEDTLS_AESNI_C
1914 scripts/config.py unset MBEDTLS_PADLOCK_C
1915 scripts/config.py unset MBEDTLS_AESCE_C
1916 scripts/config.py set MBEDTLS_TEST_HOOKS
1917 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
1918 make CC=gcc CFLAGS="$ASAN_CFLAGS -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32" LDFLAGS="$ASAN_CFLAGS"
1919
1920 msg "test: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
1921 make test
1922}
1923
1924component_test_no_udbl_division () {
1925 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1926 scripts/config.py full
1927 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
1928 make CFLAGS='-Werror -O1'
1929
1930 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
1931 make test
1932}
1933
1934component_test_no_64bit_multiplication () {
1935 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1936 scripts/config.py full
1937 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
1938 make CFLAGS='-Werror -O1'
1939
1940 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
1941 make test
1942}
1943
1944component_test_no_strings () {
1945 msg "build: no strings" # ~10s
1946 scripts/config.py full
1947 # Disable options that activate a large amount of string constants.
1948 scripts/config.py unset MBEDTLS_DEBUG_C
1949 scripts/config.py unset MBEDTLS_ERROR_C
1950 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
1951 scripts/config.py unset MBEDTLS_VERSION_FEATURES
1952 make CFLAGS='-Werror -Os'
1953
1954 msg "test: no strings" # ~ 10s
1955 make test
1956}
1957
1958component_test_no_x509_info () {
1959 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
1960 scripts/config.pl full
1961 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
1962 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
1963 make CFLAGS='-Werror -O2'
1964
1965 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
1966 make test
1967
1968 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
1969 tests/ssl-opt.sh
1970}
1971
1972component_build_arm_none_eabi_gcc () {
1973 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
1974 scripts/config.py baremetal
1975 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
1976
1977 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
1978 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
1979}
1980
1981component_build_arm_linux_gnueabi_gcc_arm5vte () {
1982 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
1983 scripts/config.py baremetal
1984 # Build for a target platform that's close to what Debian uses
1985 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
1986 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
1987 # Build everything including programs, see for example
1988 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
1989 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'
1990
1991 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
1992 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t library/*.o
1993}
1994support_build_arm_linux_gnueabi_gcc_arm5vte () {
1995 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
1996}
1997
1998component_build_arm_none_eabi_gcc_arm5vte () {
1999 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
2000 scripts/config.py baremetal
2001 # This is an imperfect substitute for
2002 # component_build_arm_linux_gnueabi_gcc_arm5vte
2003 # in case the gcc-arm-linux-gnueabi toolchain is not available
2004 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
2005
2006 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
2007 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
2008}
2009
2010component_build_arm_none_eabi_gcc_m0plus () {
2011 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
2012 scripts/config.py baremetal_size
2013 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
2014
2015 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
2016 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
2017 for lib in library/*.a; do
2018 echo "$lib:"
2019 ${ARM_NONE_EABI_GCC_PREFIX}size -t $lib | grep TOTALS
2020 done
2021}
2022
2023component_build_arm_none_eabi_gcc_no_udbl_division () {
2024 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
2025 scripts/config.py baremetal
2026 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
2027 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
2028 echo "Checking that software 64-bit division is not required"
2029 not grep __aeabi_uldiv library/*.o
2030}
2031
2032component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
2033 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
2034 scripts/config.py baremetal
2035 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
2036 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
2037 echo "Checking that software 64-bit multiplication is not required"
2038 not grep __aeabi_lmul library/*.o
2039}
2040
2041component_build_arm_clang_thumb () {
2042 # ~ 30s
2043
2044 scripts/config.py baremetal
2045
2046 msg "build: clang thumb 2, make"
2047 make clean
2048 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
2049
2050 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
2051 msg "build: clang thumb 1 -O0, make"
2052 make clean
2053 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
2054
2055 msg "build: clang thumb 1 -Os, make"
2056 make clean
2057 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
2058}
2059
2060component_build_armcc () {
2061 msg "build: ARM Compiler 5"
2062 scripts/config.py baremetal
2063 # armc[56] don't support SHA-512 intrinsics
2064 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2065
2066 # older versions of armcc/armclang don't support AESCE_C on 32-bit Arm
2067 scripts/config.py unset MBEDTLS_AESCE_C
2068
2069 # Stop armclang warning about feature detection for A64_CRYPTO.
2070 # With this enabled, the library does build correctly under armclang,
2071 # but in baremetal builds (as tested here), feature detection is
2072 # unavailable, and the user is notified via a #warning. So enabling
2073 # this feature would prevent us from building with -Werror on
2074 # armclang. Tracked in #7198.
2075 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2076
2077 scripts/config.py set MBEDTLS_HAVE_ASM
2078
2079 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
2080
2081 msg "size: ARM Compiler 5"
2082 "$ARMC5_FROMELF" -z library/*.o
2083
2084 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
2085
2086 # ARM Compiler 6 - Target ARMv7-A
2087 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-a"
2088
2089 # ARM Compiler 6 - Target ARMv7-M
2090 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m"
2091
2092 # ARM Compiler 6 - Target ARMv7-M+DSP
2093 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m+dsp"
2094
2095 # ARM Compiler 6 - Target ARMv8-A - AArch32
2096 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8.2-a"
2097
2098 # ARM Compiler 6 - Target ARMv8-M
2099 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
2100
2101 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
2102 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
2103
2104 # ARM Compiler 6 - Target Cortex-M0
2105 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
2106
2107 # ARM Compiler 6 - Target ARMv8.2-A - AArch64
2108 #
2109 # Re-enable MBEDTLS_AESCE_C as this should be supported by the version of armclang
2110 # that we have in our CI
2111 scripts/config.py set MBEDTLS_AESCE_C
2112 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
2113}
2114
2115support_build_armcc () {
2116 armc5_cc="$ARMC5_BIN_DIR/armcc"
2117 armc6_cc="$ARMC6_BIN_DIR/armclang"
2118 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
2119}
2120
2121component_test_tls12_only () {
2122 msg "build: default config without MBEDTLS_SSL_PROTO_TLS1_3, cmake, gcc, ASan"
2123 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2124 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2125 make
2126
2127 msg "test: main suites (inc. selftests) (ASan build)"
2128 make test
2129
2130 msg "test: ssl-opt.sh (ASan build)"
2131 tests/ssl-opt.sh
2132
2133 msg "test: compat.sh (ASan build)"
2134 tests/compat.sh
2135}
2136
2137component_test_tls13_only () {
2138 msg "build: default config without MBEDTLS_SSL_PROTO_TLS1_2"
2139 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
2140 scripts/config.py set MBEDTLS_SSL_RECORD_SIZE_LIMIT
2141 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
2142
2143 msg "test: TLS 1.3 only, all key exchange modes enabled"
2144 make test
2145
2146 msg "ssl-opt.sh: TLS 1.3 only, all key exchange modes enabled"
2147 tests/ssl-opt.sh
2148}
2149
2150component_test_tls13_only_psk () {
2151 msg "build: TLS 1.3 only from default, only PSK key exchange mode"
2152 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
2153 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
2154 scripts/config.py unset MBEDTLS_ECDH_C
2155 scripts/config.py unset MBEDTLS_DHM_C
2156 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
2157 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2158 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
2159 scripts/config.py unset MBEDTLS_ECDSA_C
2160 scripts/config.py unset MBEDTLS_PKCS1_V21
2161 scripts/config.py unset MBEDTLS_PKCS7_C
2162 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
2163 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
2164
2165 msg "test_suite_ssl: TLS 1.3 only, only PSK key exchange mode enabled"
2166 cd tests; ./test_suite_ssl; cd ..
2167
2168 msg "ssl-opt.sh: TLS 1.3 only, only PSK key exchange mode enabled"
2169 tests/ssl-opt.sh
2170}
2171
2172component_test_tls13_only_ephemeral () {
2173 msg "build: TLS 1.3 only from default, only ephemeral key exchange mode"
2174 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
2175 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
2176 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
2177 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
2178
2179 msg "test_suite_ssl: TLS 1.3 only, only ephemeral key exchange mode"
2180 cd tests; ./test_suite_ssl; cd ..
2181
2182 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral key exchange mode"
2183 tests/ssl-opt.sh
2184}
2185
2186component_test_tls13_only_ephemeral_ffdh () {
2187 msg "build: TLS 1.3 only from default, only ephemeral ffdh key exchange mode"
2188 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
2189 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
2190 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
2191 scripts/config.py unset MBEDTLS_ECDH_C
2192
2193 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
2194
2195 msg "test_suite_ssl: TLS 1.3 only, only ephemeral ffdh key exchange mode"
2196 cd tests; ./test_suite_ssl; cd ..
2197
2198 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral ffdh key exchange mode"
2199 tests/ssl-opt.sh
2200}
2201
2202component_test_tls13_only_psk_ephemeral () {
2203 msg "build: TLS 1.3 only from default, only PSK ephemeral key exchange mode"
2204 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
2205 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
2206 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
2207 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2208 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
2209 scripts/config.py unset MBEDTLS_ECDSA_C
2210 scripts/config.py unset MBEDTLS_PKCS1_V21
2211 scripts/config.py unset MBEDTLS_PKCS7_C
2212 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
2213 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
2214
2215 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral key exchange mode"
2216 cd tests; ./test_suite_ssl; cd ..
2217
2218 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral key exchange mode"
2219 tests/ssl-opt.sh
2220}
2221
2222component_test_tls13_only_psk_ephemeral_ffdh () {
2223 msg "build: TLS 1.3 only from default, only PSK ephemeral ffdh key exchange mode"
2224 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
2225 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
2226 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
2227 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2228 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
2229 scripts/config.py unset MBEDTLS_ECDSA_C
2230 scripts/config.py unset MBEDTLS_PKCS1_V21
2231 scripts/config.py unset MBEDTLS_PKCS7_C
2232 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
2233 scripts/config.py unset MBEDTLS_ECDH_C
2234 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
2235
2236 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
2237 cd tests; ./test_suite_ssl; cd ..
2238
2239 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
2240 tests/ssl-opt.sh
2241}
2242
2243component_test_tls13_only_psk_all () {
2244 msg "build: TLS 1.3 only from default, without ephemeral key exchange mode"
2245 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
2246 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
2247 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2248 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
2249 scripts/config.py unset MBEDTLS_ECDSA_C
2250 scripts/config.py unset MBEDTLS_PKCS1_V21
2251 scripts/config.py unset MBEDTLS_PKCS7_C
2252 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
2253 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
2254
2255 msg "test_suite_ssl: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
2256 cd tests; ./test_suite_ssl; cd ..
2257
2258 msg "ssl-opt.sh: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
2259 tests/ssl-opt.sh
2260}
2261
2262component_test_tls13_only_ephemeral_all () {
2263 msg "build: TLS 1.3 only from default, without PSK key exchange mode"
2264 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
2265 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
2266 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
2267
2268 msg "test_suite_ssl: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
2269 cd tests; ./test_suite_ssl; cd ..
2270
2271 msg "ssl-opt.sh: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
2272 tests/ssl-opt.sh
2273}
2274
2275component_test_tls13_no_padding () {
2276 msg "build: default config plus early data minus padding"
2277 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
2278 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
2279 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2280 make
2281 msg "test: default config plus early data minus padding"
2282 make test
2283 msg "ssl-opt.sh (TLS 1.3 no padding)"
2284 tests/ssl-opt.sh
2285}
2286
2287component_test_tls13_no_compatibility_mode () {
2288 msg "build: default config plus early data minus middlebox compatibility mode"
2289 scripts/config.py unset MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
2290 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
2291 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2292 make
2293 msg "test: default config plus early data minus middlebox compatibility mode"
2294 make test
2295 msg "ssl-opt.sh (TLS 1.3 no compatibility mode)"
2296 tests/ssl-opt.sh
2297}
2298
2299component_test_full_minus_session_tickets () {
2300 msg "build: full config without session tickets"
2301 scripts/config.py full
2302 scripts/config.py unset MBEDTLS_SSL_SESSION_TICKETS
2303 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
2304 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2305 make
2306 msg "test: full config without session tickets"
2307 make test
2308 msg "ssl-opt.sh (full config without session tickets)"
2309 tests/ssl-opt.sh
2310}
2311
Minos Galanakisf7d1cb02024-07-30 17:25:31 +01002312
Minos Galanakisf7d1cb02024-07-30 17:25:31 +01002313
Minos Galanakisf7d1cb02024-07-30 17:25:31 +01002314
2315component_test_memsan () {
2316 msg "build: MSan (clang)" # ~ 1 min 20s
2317 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
2318 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
2319 make
2320
2321 msg "test: main suites (MSan)" # ~ 10s
2322 make test
2323
2324 msg "test: metatests (MSan)"
2325 tests/scripts/run-metatests.sh any msan
2326
2327 msg "program demos (MSan)" # ~20s
2328 tests/scripts/run_demos.py
2329
2330 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
2331 tests/ssl-opt.sh
2332
2333 # Optional part(s)
2334
2335 if [ "$MEMORY" -gt 0 ]; then
2336 msg "test: compat.sh (MSan)" # ~ 6 min 20s
2337 tests/compat.sh
2338 fi
2339}
2340
2341component_release_test_valgrind () {
2342 msg "build: Release (clang)"
2343 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
2344 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
2345 make
2346
2347 msg "test: main suites, Valgrind (default config)"
2348 make memcheck
2349
2350 # Optional parts (slow; currently broken on OS X because programs don't
2351 # seem to receive signals under valgrind on OS X).
2352 # These optional parts don't run on the CI.
2353 if [ "$MEMORY" -gt 0 ]; then
2354 msg "test: ssl-opt.sh --memcheck (default config)"
2355 tests/ssl-opt.sh --memcheck
2356 fi
2357
2358 if [ "$MEMORY" -gt 1 ]; then
2359 msg "test: compat.sh --memcheck (default config)"
2360 tests/compat.sh --memcheck
2361 fi
2362
2363 if [ "$MEMORY" -gt 0 ]; then
2364 msg "test: context-info.sh --memcheck (default config)"
2365 tests/context-info.sh --memcheck
2366 fi
2367}
2368
2369component_release_test_valgrind_psa () {
2370 msg "build: Release, full (clang)"
2371 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
2372 scripts/config.py full
2373 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
2374 make
2375
2376 msg "test: main suites, Valgrind (full config)"
2377 make memcheck
2378}
2379