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