blob: aa70f22e2cae54c5b76fe99bbd06fb56362a2430 [file] [log] [blame]
Gilles Peskine3de7be82020-03-27 16:35:23 +01001#! /usr/bin/env bash
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
Bence Szépkúti1e148272020-08-07 13:07:28 +02005# Copyright The Mbed TLS Contributors
Dave Rodgman7ff79652023-11-03 12:04:52 +00006# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskine192c72f2017-12-21 15:59:21 +01007
8
9
10################################################################
11#### Documentation
12################################################################
13
Simon Butcher3ea7f522016-03-07 23:22:10 +000014# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010015# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000016#
SimonB2e23c822016-04-16 21:54:39 +010017# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010018#
Gilles Peskine192c72f2017-12-21 15:59:21 +010019# Notes for users
20# ---------------
21#
SimonB2e23c822016-04-16 21:54:39 +010022# Warning: the test is destructive. It includes various build modes and
23# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010024# configuration. The following files must be committed into git:
25# * include/mbedtls/config.h
Gilles Peskine636c26a2020-03-04 20:46:15 +010026# * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
27# programs/fuzz/Makefile
Gilles Peskine192c72f2017-12-21 15:59:21 +010028# After running this script, the CMake cache will be lost and CMake
29# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# The script assumes the presence of a number of tools:
32# * Basic Unix tools (Windows users note: a Unix-style find must be before
33# the Windows find in the PATH)
34# * Perl
35# * GNU Make
36# * CMake
37# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040038# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010039# * arm-gcc and mingw-gcc
40# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine549a9612023-08-27 21:39:21 +020041# * OpenSSL and GnuTLS command line tools, in suitable versions for the
42# interoperability tests. The following are the official versions at the
43# time of writing:
44# * GNUTLS_{CLI,SERV} = 3.4.10
45# * GNUTLS_NEXT_{CLI,SERV} = 3.7.2
46# * OPENSSL_LEGACY = 1.0.1j
47# * OPENSSL = 1.0.2g (without Debian/Ubuntu patches)
48# * OPENSSL_NEXT = 1.1.1a
Gilles Peskine192c72f2017-12-21 15:59:21 +010049# See the invocation of check_tools below for details.
50#
51# This script must be invoked from the toplevel directory of a git
52# working copy of Mbed TLS.
53#
Gilles Peskine7105a332020-03-28 18:50:43 +010054# The behavior on an error depends on whether --keep-going (alias -k)
55# is in effect.
56# * Without --keep-going: the script stops on the first error without
57# cleaning up. This lets you work in the configuration of the failing
58# component.
59# * With --keep-going: the script runs all requested components and
60# reports failures at the end. In particular the script always cleans
61# up on exit.
62#
Gilles Peskine192c72f2017-12-21 15:59:21 +010063# Note that the output is not saved. You may want to run
64# script -c tests/scripts/all.sh
65# or
66# tests/scripts/all.sh >all.log 2>&1
67#
68# Notes for maintainers
69# ---------------------
70#
Gilles Peskine8f073122018-11-27 15:58:47 +010071# The bulk of the code is organized into functions that follow one of the
72# following naming conventions:
73# * pre_XXX: things to do before running the tests, in order.
74# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010075# * component_check_XXX: quick tests that aren't worth parallelizing.
76# * component_build_XXX: build things but don't run them.
77# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000078# * support_XXX: if support_XXX exists and returns false then
79# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010080# * post_XXX: things to do after running the tests.
81# * other: miscellaneous support functions.
82#
Gilles Peskinec70637a2019-01-09 22:29:17 +010083# Each component must start by invoking `msg` with a short informative message.
84#
Gilles Peskine39a3b112020-03-28 21:27:40 +010085# Warning: due to the way bash detects errors, the failure of a command
86# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
87#
Gilles Peskine7105a332020-03-28 18:50:43 +010088# Each component is executed in a separate shell process. The component
89# fails if any command in it returns a non-zero status.
90#
Gilles Peskinec70637a2019-01-09 22:29:17 +010091# The framework performs some cleanup tasks after each component. This
92# means that components can assume that the working directory is in a
93# cleaned-up state, and don't need to perform the cleanup themselves.
94# * Run `make clean`.
95# * Restore `include/mbedtks/config.h` from a backup made before running
96# the component.
Gilles Peskine636c26a2020-03-04 20:46:15 +010097# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
98# `tests/Makefile` and `programs/fuzz/Makefile` from git.
99# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +0100100#
Gilles Peskine192c72f2017-12-21 15:59:21 +0100101# The tests are roughly in order from fastest to slowest. This doesn't
102# have to be exact, but in general you should add slower tests towards
103# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100104
105
106
107################################################################
108#### Initialization and command line parsing
109################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100110
Gilles Peskine8ab29942020-03-28 18:50:49 +0100111# Abort on errors (even on the left-hand side of a pipe).
112# Treat uninitialised variables as errors.
113set -e -o pipefail -u
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100114
Gilles Peskine79598582022-08-30 21:02:44 +0200115# Enable ksh/bash extended file matching patterns
116shopt -s extglob
117
Gilles Peskine8f073122018-11-27 15:58:47 +0100118pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000119 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskinef08ca832023-09-12 19:21:54 +0200120 echo "Must be run from Mbed TLS root" >&2
Gilles Peskine8f073122018-11-27 15:58:47 +0100121 exit 1
122 fi
123}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100124
Gilles Peskine8f073122018-11-27 15:58:47 +0100125pre_initialize_variables () {
126 CONFIG_H='include/mbedtls/config.h'
John Durkopbd069d32020-10-31 22:14:03 -0700127 CRYPTO_CONFIG_H='include/psa/crypto_config.h'
Gilles Peskine24bdf022020-03-30 20:11:39 +0200128
129 # Files that are clobbered by some jobs will be backed up. Use a different
130 # suffix from auxiliary scripts so that all.sh and auxiliary scripts can
131 # independently decide when to remove the backup file.
132 backup_suffix='.all.bak'
133 # Files clobbered by config.py
134 files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H"
Gilles Peskineef64e7f2021-07-12 18:16:01 +0200135 # Files clobbered by in-tree cmake
136 files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200137
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200138 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100139 MEMORY=0
140 FORCE=0
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200141 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100142 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100143
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200144 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard54304472020-06-22 10:11:47 +0200145 #
146 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
147 # both values are kept in sync. If you change the value here because it
148 # breaks some tests, you'll definitely want to change it in
149 # basic-build-test.sh as well.
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200150 RELEASE_SEED=1
151
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200152 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200153 : ${MBEDTLS_TEST_PLATFORM="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200154 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200155 export MBEDTLS_TEST_PLATFORM
156
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000157 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100158 : ${OPENSSL:="openssl"}
159 : ${OPENSSL_LEGACY:="$OPENSSL"}
160 : ${OPENSSL_NEXT:="$OPENSSL"}
161 : ${GNUTLS_CLI:="gnutls-cli"}
162 : ${GNUTLS_SERV:="gnutls-serv"}
Gilles Peskine8f073122018-11-27 15:58:47 +0100163 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
164 : ${ARMC5_BIN_DIR:=/usr/bin}
165 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskine6d061342020-04-30 18:19:32 +0200166 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200167 : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
Gowtham Suresh Kumarcc029af2023-08-01 09:48:32 +0100168 : ${CLANG_LATEST:="clang-latest"}
169 : ${CLANG_EARLIEST:="clang-earliest"}
170 : ${GCC_LATEST:="gcc-latest"}
171 : ${GCC_EARLIEST:="gcc-earliest"}
Andres AGdc192212016-08-31 17:33:13 +0100172
Gilles Peskine8f073122018-11-27 15:58:47 +0100173 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000174 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine85229ac2021-09-30 18:24:21 +0200175 export MAKEFLAGS="-j$(all_sh_nproc)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100176 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000177
Gilles Peskinec761d8f2021-09-20 18:57:55 +0200178 # Include more verbose output for failing tests run by CMake or make
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000179 export CTEST_OUTPUT_ON_FAILURE=1
180
Gilles Peskine8fd59422019-10-21 17:11:33 +0200181 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Manuel Pégourié-Gonnard717f2302022-11-30 10:42:03 +0100182 # default to -O2, use -Ox _after_ this if you want another level
Manuel Pégourié-Gonnard154b84e2022-11-28 13:12:10 +0100183 ASAN_CFLAGS='-O2 -Werror -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200184
Andrzej Kurekd95b8ed2023-06-27 10:02:09 -0400185 # Platform tests have an allocation that returns null
186 export ASAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurek6e4a9be2023-07-05 08:32:43 -0400187 export MSAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurekd95b8ed2023-06-27 10:02:09 -0400188
Gilles Peskine878cf602019-01-06 20:50:38 +0000189 # Gather the list of available components. These are the functions
190 # defined in this script whose name starts with "component_".
Gowtham Suresh Kumar13850f32023-07-28 16:41:21 +0100191 ALL_COMPONENTS=$(compgen -A function component_ | sed 's/component_//')
Gilles Peskine878cf602019-01-06 20:50:38 +0000192
193 # Exclude components that are not supported on this platform.
194 SUPPORTED_COMPONENTS=
195 for component in $ALL_COMPONENTS; do
196 case $(type "support_$component" 2>&1) in
197 *' function'*)
198 if ! support_$component; then continue; fi;;
199 esac
200 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
201 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100202}
Andres AG38495a32016-07-12 16:54:33 +0100203
Gilles Peskinea28db922019-01-10 00:05:18 +0100204# Test whether the component $1 is included in the command line patterns.
205is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100206{
Gilles Peskine6702ce92021-08-06 11:35:17 +0200207 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
208 # only does word splitting.
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100209 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000210 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100211 set +f
212 case ${1#component_} in $pattern) return 0;; esac
213 done
214 set +f
215 return 1
216}
Andres AG7770ea82016-10-10 15:46:20 +0100217
Simon Butcher41eeccf2016-09-07 00:07:09 +0100218usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100219{
Gilles Peskine709346a2017-12-10 23:43:39 +0100220 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100221Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100222Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100223By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100224COMPONENT can be the name of a component or a shell wildcard pattern.
225
226Examples:
227 $0 "check_*"
228 Run all sanity checks.
229 $0 --no-armcc --except test_memsan
230 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100231
232Special options:
233 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000234 --list-all-components List all available test components and exit.
235 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100236
237General options:
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200238 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100239 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100240 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100241 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200242 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200243 --arm-none-eabi-gcc-prefix=<string>
244 Prefix for a cross-compiler for arm-none-eabi
245 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200246 --arm-linux-gnueabi-gcc-prefix=<string>
247 Prefix for a cross-compiler for arm-linux-gnueabi
248 (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100249 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200250 --restore First clean up the build tree, restoring backed up
251 files. Do not run any components unless they are
252 explicitly specified.
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100253 --error-test Error test mode: run a failing function in addition
Gilles Peskinea25c5672021-08-05 15:11:33 +0200254 to any specified component. May be repeated.
Gilles Peskinea28db922019-01-10 00:05:18 +0100255 --except Exclude the COMPONENTs listed on the command line,
256 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200257 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100258 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100259 --no-force Refuse to overwrite modified files (default).
260 --no-keep-going Stop at the first error (default).
261 --no-memory No additional memory tests (default).
Shaun Case0e7791f2021-12-20 21:14:10 -0800262 --no-quiet Print full output from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100263 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200264 --outcome-file=<path> File where test outcomes are written (not done if
265 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100266 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200267 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100268 -s|--seed Integer seed value to use for this test run.
269
270Tool path options:
271 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
272 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100273 --clang-earliest=<Clang_earliest_path> Earliest version of clang available
274 --clang-latest=<Clang_latest_path> Latest version of clang available
275 --gcc-earliest=<GCC_earliest_path> Earliest version of GCC available
276 --gcc-latest=<GCC_latest_path> Latest version of GCC available
Gilles Peskine709346a2017-12-10 23:43:39 +0100277 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
278 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
Gilles Peskine709346a2017-12-10 23:43:39 +0100279 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
280 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100281 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100282EOF
SimonB2e23c822016-04-16 21:54:39 +0100283}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100284
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200285# Cleanup before/after running a component.
286# Remove built files as well as the cmake cache/config.
287# Does not remove generated source files.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100288cleanup()
289{
Gilles Peskine7c652162017-12-11 00:01:40 +0100290 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200291
Gilles Peskine31b07e22018-03-21 12:15:06 +0100292 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000293 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100294 -iname CMakeFiles -exec rm -rf {} \+ -o \
295 \( -iname cmake_install.cmake -o \
296 -iname CTestTestfile.cmake -o \
297 -iname CMakeCache.txt \) -exec rm {} \+
298 # Recover files overwritten by in-tree CMake builds
Gilles Peskine79598582022-08-30 21:02:44 +0200299 rm -f include/Makefile include/mbedtls/Makefile programs/!(fuzz)/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200300
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100301 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
302 rm -rf programs/test/cmake_subproject/build
303 rm -f programs/test/cmake_subproject/Makefile
304 rm -f programs/test/cmake_subproject/cmake_subproject
305
Gilles Peskine24bdf022020-03-30 20:11:39 +0200306 # Restore files that may have been clobbered by the job
307 for x in $files_to_back_up; do
Gilles Peskine423dd132022-08-30 21:02:00 +0200308 if [[ -e "$x$backup_suffix" ]]; then
309 cp -p "$x$backup_suffix" "$x"
310 fi
Gilles Peskine24bdf022020-03-30 20:11:39 +0200311 done
312}
John Durkopbd069d32020-10-31 22:14:03 -0700313
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200314# Final cleanup when this script exits (except when exiting on a failure
315# in non-keep-going mode).
Gilles Peskine24bdf022020-03-30 20:11:39 +0200316final_cleanup () {
317 cleanup
318
319 for x in $files_to_back_up; do
320 rm -f "$x$backup_suffix"
321 done
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100322}
323
Gilles Peskine7c652162017-12-11 00:01:40 +0100324# Executed on exit. May be redefined depending on command line options.
325final_report () {
326 :
327}
328
329fatal_signal () {
Gilles Peskine24bdf022020-03-30 20:11:39 +0200330 final_cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100331 final_report $1
332 trap - $1
333 kill -$1 $$
334}
335
336trap 'fatal_signal HUP' HUP
337trap 'fatal_signal INT' INT
338trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200339
Gilles Peskine85229ac2021-09-30 18:24:21 +0200340# Number of processors on this machine. Used as the default setting
341# for parallel make.
342all_sh_nproc ()
343{
344 {
345 nproc || # Linux
346 sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
347 sysctl -n hw.ncpu || # FreeBSD
348 echo 1
349 } 2>/dev/null
350}
351
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100352msg()
353{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100354 if [ -n "${current_component:-}" ]; then
355 current_section="${current_component#component_}: $1"
356 else
357 current_section="$1"
358 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200359
360 if [ $QUIET -eq 1 ]; then
361 return
362 fi
363
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100364 echo ""
365 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100366 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000367 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100368 echo "******************************************************************"
369}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100370
Gilles Peskine8f073122018-11-27 15:58:47 +0100371armc6_build_test()
372{
373 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100374
Gilles Peskine18487f62020-04-30 23:11:54 +0200375 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100376 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
Dave Rodgman6cda3d32023-03-02 13:39:04 +0000377 WARNING_CFLAGS='-Werror -xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200378
379 msg "size: ARM Compiler 6 ($FLAGS)"
380 "$ARMC6_FROMELF" -z library/*.o
381
Gilles Peskine8f073122018-11-27 15:58:47 +0100382 make clean
383}
Andres AGa5cd9732016-10-17 15:23:10 +0100384
Andres AGd9eba4b2016-08-26 14:42:14 +0100385err_msg()
386{
387 echo "$1" >&2
388}
389
390check_tools()
391{
392 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000393 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100394 err_msg "$TOOL not found!"
395 exit 1
396 fi
397 done
398}
399
Gilles Peskine8f073122018-11-27 15:58:47 +0100400pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000401 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100402 all_except=0
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100403 error_test=0
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200404 restore_first=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000405 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100406
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000407 # Note that legacy options are ignored instead of being omitted from this
408 # list of options, so invocations that worked with previous version of
409 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100410 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100411 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200412 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200413 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200414 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000415 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100416 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
417 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100418 --clang-earliest) shift; CLANG_EARLIEST="$1";;
419 --clang-latest) shift; CLANG_LATEST="$1";;
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100420 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000421 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100422 --force|-f) FORCE=1;;
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100423 --gcc-earliest) shift; GCC_EARLIEST="$1";;
424 --gcc-latest) shift; GCC_LATEST="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100425 --gnutls-cli) shift; GNUTLS_CLI="$1";;
Gilles Peskine549a9612023-08-27 21:39:21 +0200426 --gnutls-legacy-cli) shift;; # ignored for backward compatibility
427 --gnutls-legacy-serv) shift;; # ignored for backward compatibility
Gilles Peskine55f7c942019-01-09 22:28:21 +0100428 --gnutls-serv) shift; GNUTLS_SERV="$1";;
429 --help|-h) usage; exit;;
430 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000431 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
432 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100433 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200434 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000435 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100436 --no-force) FORCE=0;;
437 --no-keep-going) KEEP_GOING=0;;
438 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200439 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100440 --openssl) shift; OPENSSL="$1";;
441 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
442 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200443 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100444 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200445 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100446 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200447 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200448 --restore) restore_first=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100449 --seed|-s) shift; SEED="$1";;
450 -*)
451 echo >&2 "Unknown option: $1"
452 echo >&2 "Run $0 --help for usage."
453 exit 120
454 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000455 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100456 esac
457 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100458 done
SimonB2e23c822016-04-16 21:54:39 +0100459
Gilles Peskinea28db922019-01-10 00:05:18 +0100460 # With no list of components, run everything.
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200461 if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000462 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100463 fi
464
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000465 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
466 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100467 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000468 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100469 fi
SimonB2e23c822016-04-16 21:54:39 +0100470
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200471 # Error out if an explicitly requested component doesn't exist.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100472 if [ $all_except -eq 0 ]; then
473 unsupported=0
Gilles Peskine6702ce92021-08-06 11:35:17 +0200474 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
475 # only does word splitting.
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200476 set -f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100477 for component in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200478 set +f
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200479 # If the requested name includes a wildcard character, don't
480 # check it. Accept wildcard patterns that don't match anything.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100481 case $component in
482 *[*?\[]*) continue;;
483 esac
484 case " $SUPPORTED_COMPONENTS " in
485 *" $component "*) :;;
486 *)
487 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
488 unsupported=$((unsupported + 1));;
489 esac
490 done
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200491 set +f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100492 if [ $unsupported -ne 0 ]; then
493 exit 2
494 fi
495 fi
496
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000497 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100498 RUN_COMPONENTS=
499 for component in $SUPPORTED_COMPONENTS; do
500 if is_component_included "$component"; [ $? -eq $all_except ]; then
501 RUN_COMPONENTS="$RUN_COMPONENTS $component"
502 fi
503 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000504
505 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000506 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100507}
SimonB2e23c822016-04-16 21:54:39 +0100508
Gilles Peskine8f073122018-11-27 15:58:47 +0100509pre_check_git () {
510 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100511 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100512 git checkout-index -f -q $CONFIG_H
513 cleanup
514 else
SimonB2e23c822016-04-16 21:54:39 +0100515
Gilles Peskine8f073122018-11-27 15:58:47 +0100516 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
517 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
518 echo "You can either delete this directory manually, or force the test by rerunning"
519 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
520 exit 1
521 fi
522
Gilles Peskined1174cf2019-01-09 22:30:01 +0100523 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100524 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
525 echo "You can either delete or preserve your work, or force the test by rerunning the"
526 echo "script as: $0 --force"
527 exit 1
528 fi
SimonB2e23c822016-04-16 21:54:39 +0100529 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500530}
531
Gilles Peskineef64e7f2021-07-12 18:16:01 +0200532pre_restore_files () {
533 # If the makefiles have been generated by a framework such as cmake,
534 # restore them from git. If the makefiles look like modifications from
535 # the ones checked into git, take care not to modify them. Whatever
536 # this function leaves behind is what the script will restore before
537 # each component.
538 case "$(head -n1 Makefile)" in
539 *[Gg]enerated*)
540 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
541 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
542 ;;
543 esac
544}
545
Gilles Peskine24bdf022020-03-30 20:11:39 +0200546pre_back_up () {
547 for x in $files_to_back_up; do
548 cp -p "$x" "$x$backup_suffix"
549 done
550}
551
Gilles Peskine8f073122018-11-27 15:58:47 +0100552pre_setup_keep_going () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100553 failure_count=0 # Number of failed components
554 last_failure_status=0 # Last failure status in this component
555
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100556 # See err_trap
557 previous_failure_status=0
558 previous_failed_command=
559 previous_failure_funcall_depth=0
Gilles Peskine39a3b112020-03-28 21:27:40 +0100560 unset report_failed_command
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100561
Gilles Peskine7c652162017-12-11 00:01:40 +0100562 start_red=
563 end_color=
564 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100565 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100566 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
567 start_red=$(printf '\033[31m')
568 end_color=$(printf '\033[0m')
569 ;;
570 esac
571 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100572
573 # Keep a summary of failures in a file. We'll print it out at the end.
574 failure_summary_file=$PWD/all-sh-failures-$$.log
575 : >"$failure_summary_file"
576
577 # Whether it makes sense to keep a component going after the specified
578 # command fails (test command) or not (configure or build).
Gilles Peskine6702ce92021-08-06 11:35:17 +0200579 # This function normally receives the failing simple command
580 # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
581 # this is passed instead.
Gilles Peskine7105a332020-03-28 18:50:43 +0100582 # This doesn't have to be 100% accurate: all failures are recorded anyway.
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200583 # False positives result in running things that can't be expected to
584 # work. False negatives result in things not running after something else
585 # failed even though they might have given useful feedback.
Gilles Peskine7105a332020-03-28 18:50:43 +0100586 can_keep_going_after_failure () {
587 case "$1" in
588 "msg "*) false;;
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200589 "cd "*) false;;
590 *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
591 *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
592 *make*check*) true;;
593 "grep "*) true;;
594 "[ "*) true;;
595 "! "*) true;;
Gilles Peskine7105a332020-03-28 18:50:43 +0100596 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100597 esac
598 }
Gilles Peskine7105a332020-03-28 18:50:43 +0100599
600 # This function runs if there is any error in a component.
601 # It must either exit with a nonzero status, or set
602 # last_failure_status to a nonzero value.
603 err_trap () {
604 # Save $? (status of the failing command). This must be the very
605 # first thing, before $? is overridden.
606 last_failure_status=$?
Gilles Peskine39a3b112020-03-28 21:27:40 +0100607 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskine7105a332020-03-28 18:50:43 +0100608
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100609 if [[ $last_failure_status -eq $previous_failure_status &&
610 "$failed_command" == "$previous_failed_command" &&
611 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
612 then
613 # The same command failed twice in a row, but this time one level
614 # less deep in the function call stack. This happens when the last
615 # command of a function returns a nonzero status, and the function
616 # returns that same status. Ignore the second failure.
617 previous_failure_funcall_depth=${#FUNCNAME[@]}
618 return
619 fi
620 previous_failure_status=$last_failure_status
621 previous_failed_command=$failed_command
622 previous_failure_funcall_depth=${#FUNCNAME[@]}
623
Gilles Peskine7105a332020-03-28 18:50:43 +0100624 text="$current_section: $failed_command -> $last_failure_status"
625 echo "${start_red}^^^^$text^^^^${end_color}" >&2
626 echo "$text" >>"$failure_summary_file"
627
628 # If the command is fatal (configure or build command), stop this
629 # component. Otherwise (test command) keep the component running
630 # (run more tests from the same build).
631 if ! can_keep_going_after_failure "$failed_command"; then
632 exit $last_failure_status
633 fi
634 }
635
Gilles Peskine7c652162017-12-11 00:01:40 +0100636 final_report () {
637 if [ $failure_count -gt 0 ]; then
638 echo
639 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskine7105a332020-03-28 18:50:43 +0100640 echo "${start_red}FAILED: $failure_count components${end_color}"
641 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100642 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
643 elif [ -z "${1-}" ]; then
644 echo "SUCCESS :)"
645 fi
646 if [ -n "${1-}" ]; then
647 echo "Killed by SIG$1."
648 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100649 rm -f "$failure_summary_file"
650 if [ $failure_count -gt 0 ]; then
651 exit 1
652 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100653 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100654}
655
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200656# record_status() and if_build_succeeded() are kept temporarily for backward
657# compatibility. Don't use them in new components.
Gilles Peskine7105a332020-03-28 18:50:43 +0100658record_status () {
659 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100660}
Gilles Peskine7c652162017-12-11 00:01:40 +0100661if_build_succeeded () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100662 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100663}
664
Gilles Peskine39a3b112020-03-28 21:27:40 +0100665# '! true' does not trigger the ERR trap. Arrange to trigger it, with
666# a reasonably informative error message (not just "$@").
667not () {
668 if "$@"; then
669 report_failed_command="! $*"
670 false
671 unset report_failed_command
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200672 fi
673}
674
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200675pre_prepare_outcome_file () {
676 case "$MBEDTLS_TEST_OUTCOME_FILE" in
677 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
678 esac
679 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
680 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
681 fi
682}
683
Gilles Peskine8f073122018-11-27 15:58:47 +0100684pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200685 if [ $QUIET -eq 1 ]; then
686 return
687 fi
688
Gilles Peskine8f073122018-11-27 15:58:47 +0100689 msg "info: $0 configuration"
690 echo "MEMORY: $MEMORY"
691 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200692 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100693 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100694 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100695 echo "OPENSSL: $OPENSSL"
696 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
697 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
698 echo "GNUTLS_CLI: $GNUTLS_CLI"
699 echo "GNUTLS_SERV: $GNUTLS_SERV"
Gilles Peskine8f073122018-11-27 15:58:47 +0100700 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
701 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
702}
Andres AG7770ea82016-10-10 15:46:20 +0100703
Andres AGd9eba4b2016-08-26 14:42:14 +0100704# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100705pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000706 # Build the list of variables to pass to output_env.sh.
707 set env
SimonB2e23c822016-04-16 21:54:39 +0100708
Gilles Peskine87964262019-01-06 22:40:00 +0000709 case " $RUN_COMPONENTS " in
710 # Require OpenSSL and GnuTLS if running any tests (as opposed to
711 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
712 # is a good enough approximation in practice.
713 *" test_"*)
714 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
715 # and ssl-opt.sh, we just export the variables they require.
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +0100716 export OPENSSL="$OPENSSL"
Gilles Peskine87964262019-01-06 22:40:00 +0000717 export GNUTLS_CLI="$GNUTLS_CLI"
718 export GNUTLS_SERV="$GNUTLS_SERV"
719 # Avoid passing --seed flag in every call to ssl-opt.sh
720 if [ -n "${SEED-}" ]; then
721 export SEED
722 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000723 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
724 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000725 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
Gilles Peskine549a9612023-08-27 21:39:21 +0200726 "$GNUTLS_CLI" "$GNUTLS_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000727 ;;
728 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200729
Gilles Peskine87964262019-01-06 22:40:00 +0000730 case " $RUN_COMPONENTS " in
731 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
732 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100733
Gilles Peskine87964262019-01-06 22:40:00 +0000734 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200735 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000736 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100737
Gilles Peskine87964262019-01-06 22:40:00 +0000738 case " $RUN_COMPONENTS " in
739 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
740 esac
741
742 case " $RUN_COMPONENTS " in
743 *" test_zeroize "*) check_tools "gdb";;
744 esac
745
746 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000747 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000748 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
749 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200750 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000751 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
752 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200753 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
754 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
755 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000756 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000757
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200758 # past this point, no call to check_tool, only printing output
759 if [ $QUIET -eq 1 ]; then
760 return
761 fi
762
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000763 msg "info: output_env.sh"
764 case $RUN_COMPONENTS in
765 *_armcc*)
766 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
767 *) set "$@" RUN_ARMCC=0;;
768 esac
769 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100770}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100771
Gilles Peskine192c72f2017-12-21 15:59:21 +0100772
773
774################################################################
775#### Basic checks
776################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100777
778#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200779# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100780#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100781# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200782# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100783# and/or are more likely to fail than others (eg I use Clang most of the
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200784# time, so start with a GCC build).
785# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100786#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100787# Indicative running times are given for reference.
788
Gilles Peskine8f073122018-11-27 15:58:47 +0100789component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200790 msg "Check: recursion.pl" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200791 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100792}
Janos Follathb72c6782016-07-19 14:54:17 +0100793
Gilles Peskine8f073122018-11-27 15:58:47 +0100794component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200795 msg "Check: freshness of generated source files" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200796 tests/scripts/check-generated-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100797}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200798
Gilles Peskine8f073122018-11-27 15:58:47 +0100799component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200800 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200801 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +0100802}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200803
Gilles Peskine8f073122018-11-27 15:58:47 +0100804component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200805 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200806 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100807}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200808
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200809component_check_changelog () {
810 msg "Check: changelog entries" # < 1s
811 rm -f ChangeLog.new
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200812 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200813 if [ -e ChangeLog.new ]; then
814 # Show the diff for information. It isn't an error if the diff is
815 # non-empty.
816 diff -u ChangeLog ChangeLog.new || true
817 rm ChangeLog.new
818 fi
819}
820
Gilles Peskine8f073122018-11-27 15:58:47 +0100821component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200822 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200823 tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100824}
Darryl Greena07039c2018-03-13 16:48:16 +0000825
Gilles Peskine895868b2019-09-19 21:30:05 +0200826component_check_test_cases () {
827 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200828 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200829 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200830 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200831 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200832 fi
Gilles Peskine58987962022-12-15 14:46:31 +0100833 tests/scripts/check_test_cases.py -q $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200834 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +0200835}
836
Gilles Peskine8f073122018-11-27 15:58:47 +0100837component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200838 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200839 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100840}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200841
Gilles Peskine192c72f2017-12-21 15:59:21 +0100842
Gilles Peskine636c26a2020-03-04 20:46:15 +0100843
Gilles Peskine192c72f2017-12-21 15:59:21 +0100844################################################################
845#### Build and test many configurations and targets
846################################################################
847
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200848component_test_default_out_of_box () {
849 msg "build: make, default config (out-of-box)" # ~1min
850 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200851 # Disable fancy stuff
852 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200853
854 msg "test: main suites make, default config (out-of-box)" # ~10s
855 make test
856
857 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200858 programs/test/selftest
Gilles Peskine93aaf2e2019-06-14 18:27:03 +0200859
860 msg "program demos: make, default config (out-of-box)" # ~10s
861 tests/scripts/run_demos.py
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200862}
863
Gilles Peskine8f073122018-11-27 15:58:47 +0100864component_test_default_cmake_gcc_asan () {
865 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100866 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
867 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200868
Gilles Peskine8f073122018-11-27 15:58:47 +0100869 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
870 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200871
Gilles Peskine93aaf2e2019-06-14 18:27:03 +0200872 msg "program demos (ASan build)" # ~10s
873 tests/scripts/run_demos.py
874
Gilles Peskine97bea012020-04-23 23:37:45 +0200875 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200876 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200877
Gilles Peskineee8af062023-11-02 19:58:03 +0100878 msg "test: metatests (GCC, ASan build)"
879 tests/scripts/run-metatests.sh any asan
880
Gilles Peskine8f073122018-11-27 15:58:47 +0100881 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200882 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200883
Gilles Peskine8f073122018-11-27 15:58:47 +0100884 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200885 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200886
887 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200888 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100889}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200890
Hanno Becker01635512019-02-26 14:27:09 +0000891component_test_full_cmake_gcc_asan () {
892 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200893 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000894 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
895 make
896
897 msg "test: main suites (inc. selftests) (full config, ASan build)"
898 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +0100899
Gilles Peskine97bea012020-04-23 23:37:45 +0200900 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200901 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200902
Gilles Peskine636c26a2020-03-04 20:46:15 +0100903 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200904 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100905
906 msg "test: compat.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200907 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200908
909 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200910 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100911}
912
Ronald Cronc3623db2020-10-29 10:51:32 +0100913component_test_psa_crypto_key_id_encodes_owner () {
914 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
915 scripts/config.py full
916 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
917 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
918 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
919 make
920
921 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
922 make test
923}
924
Gilles Peskine99a34622021-06-17 11:37:52 +0200925# check_renamed_symbols HEADER LIB
926# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
927# name is LIB.
928check_renamed_symbols () {
929 ! nm "$2" | sed 's/.* //' |
930 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
931}
932
Gilles Peskine984c19f2021-06-15 18:37:38 +0200933component_build_psa_crypto_spm () {
934 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
935 scripts/config.py full
936 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
937 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
938 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
939 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
940 # We can only compile, not link, since our test and sample programs
941 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
942 # is active.
943 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskine99a34622021-06-17 11:37:52 +0200944
945 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
946 # version is not present.
947 echo "Checking for renamed symbols in the library"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200948 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskine984c19f2021-06-15 18:37:38 +0200949}
950
Ronald Cron336678b2021-01-28 17:54:24 +0100951component_test_psa_crypto_client () {
952 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
953 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
954 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
955 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
956 make
957
958 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
959 make test
960}
961
Gilles Peskine636c26a2020-03-04 20:46:15 +0100962component_test_zlib_make() {
963 msg "build: zlib enabled, make"
964 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine6fa69862021-10-05 09:36:03 +0200965 make ZLIB=1 CFLAGS='-Werror -O2'
Gilles Peskine636c26a2020-03-04 20:46:15 +0100966
967 msg "test: main suites (zlib, make)"
968 make test
969
970 msg "test: ssl-opt.sh (zlib, make)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200971 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100972}
973support_test_zlib_make () {
974 base=support_test_zlib_$$
975 cat <<'EOF' > ${base}.c
976#include "zlib.h"
977int main(void) { return 0; }
978EOF
979 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
980 ret=$?
981 rm -f ${base}.*
982 return $ret
983}
984
985component_test_zlib_cmake() {
986 msg "build: zlib enabled, cmake"
987 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine25319702021-10-07 19:34:57 +0200988 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Release .
Gilles Peskine636c26a2020-03-04 20:46:15 +0100989 make
990
991 msg "test: main suites (zlib, cmake)"
992 make test
993
994 msg "test: ssl-opt.sh (zlib, cmake)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200995 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100996}
997support_test_zlib_cmake () {
998 support_test_zlib_make "$@"
Manuel Pégourié-Gonnardf2e29022020-01-24 10:17:20 +0100999}
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +01001000
Jaeden Ameroc17f2932021-05-14 08:34:32 +01001001component_test_psa_crypto_rsa_no_genprime() {
1002 msg "build: default config minus MBEDTLS_GENPRIME"
1003 scripts/config.py unset MBEDTLS_GENPRIME
1004 make
1005
1006 msg "test: default config minus MBEDTLS_GENPRIME"
1007 make test
1008}
1009
Gilles Peskine782f4112018-11-27 16:11:09 +01001010component_test_ref_configs () {
1011 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
1012 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001013 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +01001014}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001015
Gilles Peskine8f073122018-11-27 15:58:47 +01001016component_test_sslv3 () {
1017 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001018 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +01001019 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1020 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001021
Gilles Peskine8f073122018-11-27 15:58:47 +01001022 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
1023 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +00001024
Gilles Peskine8f073122018-11-27 15:58:47 +01001025 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001026 tests/compat.sh -m 'ssl3 tls1 tls1_1 tls12 dtls1 dtls12'
Simon Butcher3ea7f522016-03-07 23:22:10 +00001027
Gilles Peskine8f073122018-11-27 15:58:47 +01001028 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001029 tests/ssl-opt.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001030
1031 msg "build: SSLv3 - context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001032 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001033}
Simon Butcher3ea7f522016-03-07 23:22:10 +00001034
Gilles Peskine8f073122018-11-27 15:58:47 +01001035component_test_no_renegotiation () {
1036 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001037 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001038 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1039 make
Simon Butcher3ea7f522016-03-07 23:22:10 +00001040
Gilles Peskine8f073122018-11-27 15:58:47 +01001041 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1042 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +01001043
Gilles Peskine8f073122018-11-27 15:58:47 +01001044 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001045 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001046}
Hanno Becker134c2ab2017-10-12 15:29:50 +01001047
Gilles Peskine56194432023-02-01 18:44:11 +01001048component_test_no_certs () {
1049 msg "build: full minus MBEDTLS_CERTS_C"
1050 scripts/config.py full
1051 scripts/config.py unset MBEDTLS_CERTS_C
1052 # Quick build+test (we're checking for stray uses of the test certs,
1053 # not expecting their absence to lead to subtle problems).
1054 make
1055
1056 msg "test: full minus MBEDTLS_CERTS_C - main suites"
1057 make test
1058}
1059
Gilles Peskine636c26a2020-03-04 20:46:15 +01001060component_test_no_pem_no_fs () {
1061 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1062 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1063 scripts/config.py unset MBEDTLS_FS_IO
1064 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1065 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
1066 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1067 make
1068
1069 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1070 make test
1071
1072 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001073 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001074}
1075
Gilles Peskine8f073122018-11-27 15:58:47 +01001076component_test_rsa_no_crt () {
1077 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001078 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +01001079 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1080 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +01001081
Gilles Peskine8f073122018-11-27 15:58:47 +01001082 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1083 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001084
Gilles Peskine8f073122018-11-27 15:58:47 +01001085 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001086 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001087
Gilles Peskine8f073122018-11-27 15:58:47 +01001088 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001089 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001090
1091 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001092 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001093}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001094
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001095component_test_no_ctr_drbg_classic () {
1096 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001097 scripts/config.py full
1098 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001099 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001100
1101 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1102 make
1103
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001104 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001105 make test
1106
Gilles Peskineba749042021-01-13 20:02:03 +01001107 # In this configuration, the TLS test programs use HMAC_DRBG.
1108 # The SSL tests are slow, so run a small subset, just enough to get
1109 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001110 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001111 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001112
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001113 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001114 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001115}
1116
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001117component_test_no_ctr_drbg_use_psa () {
1118 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001119 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001120 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1121 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001122
1123 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1124 make
1125
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001126 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1127 make test
1128
1129 # In this configuration, the TLS test programs use HMAC_DRBG.
1130 # The SSL tests are slow, so run a small subset, just enough to get
1131 # confidence that the SSL code copes with HMAC_DRBG.
1132 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001133 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001134
1135 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001136 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001137}
1138
1139component_test_no_hmac_drbg_classic () {
1140 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1141 scripts/config.py full
1142 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1143 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1144 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1145
1146 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1147 make
1148
1149 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001150 make test
1151
Gilles Peskinea2224342020-11-19 22:14:34 +01001152 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1153 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1154 # instead.
1155 # Test SSL with non-deterministic ECDSA. Only test features that
1156 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001157 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001158 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001159
1160 # To save time, only test one protocol version, since this part of
1161 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001162 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001163 tests/compat.sh -m tls12 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001164}
1165
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001166component_test_no_hmac_drbg_use_psa () {
1167 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1168 scripts/config.py full
1169 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1170 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1171 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1172
1173 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1174 make
1175
1176 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1177 make test
1178
1179 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1180 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1181 # instead.
1182 # Test SSL with non-deterministic ECDSA. Only test features that
1183 # might be affected by how ECDSA signature is performed.
1184 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001185 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001186
1187 # To save time, only test one protocol version, since this part of
1188 # the protocol is identical in (D)TLS up to 1.2.
1189 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001190 tests/compat.sh -m tls12 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001191}
1192
1193component_test_psa_external_rng_no_drbg_classic () {
1194 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1195 scripts/config.py full
1196 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1197 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001198 scripts/config.py unset MBEDTLS_ENTROPY_C
1199 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1200 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001201 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1202 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1203 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1204 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001205 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1206 # the SSL test programs don't have an RNG and can't work. Explicitly
1207 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1208 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001209
1210 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1211 make test
1212
Gilles Peskine8eb29432021-02-03 20:07:11 +01001213 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001214 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001215}
1216
1217component_test_psa_external_rng_no_drbg_use_psa () {
1218 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001219 scripts/config.py full
1220 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001221 scripts/config.py unset MBEDTLS_ENTROPY_C
1222 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1223 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001224 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1225 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1226 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1227 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1228 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1229
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001230 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001231 make test
1232
Gilles Peskine8eb29432021-02-03 20:07:11 +01001233 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001234 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001235}
1236
1237component_test_psa_external_rng_use_psa_crypto () {
1238 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1239 scripts/config.py full
1240 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1241 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1242 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1243 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1244
1245 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1246 make test
1247
Gilles Peskineba749042021-01-13 20:02:03 +01001248 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001249 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001250}
1251
Gilles Peskine55e89982023-04-28 21:04:28 +02001252component_test_psa_inject_entropy () {
1253 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
1254 scripts/config.py full
1255 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
1256 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
1257 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1258 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1259 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
1260 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
1261 make CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
1262
1263 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
1264 make test
1265}
1266
Manuel Pégourié-Gonnard1a3f9ed2020-05-19 12:38:31 +02001267component_test_ecp_no_internal_rng () {
1268 msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
1269 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1270 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1271 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1272 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1273 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
1274 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1275
1276 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1277 make
1278
1279 msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
1280 make test
1281
1282 # no SSL tests as they all depend on having a DRBG
1283}
1284
Manuel Pégourié-Gonnard53fb66d2020-06-04 09:43:14 +02001285component_test_ecp_restartable_no_internal_rng () {
1286 msg "build: Default plus ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG"
1287 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1288 scripts/config.py set MBEDTLS_ECP_RESTARTABLE
1289 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1290 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1291 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1292 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
1293 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1294
1295 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1296 make
1297
1298 msg "test: ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG module"
1299 make test
1300
1301 # no SSL tests as they all depend on having a DRBG
1302}
1303
Przemek Stekiele5352702022-10-05 11:37:54 +02001304component_test_tls1_2_default_stream_cipher_only () {
1305 msg "build: default with only stream cipher"
1306
1307 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
1308 scripts/config.py unset MBEDTLS_GCM_C
1309 scripts/config.py unset MBEDTLS_CCM_C
1310 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1311 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1312 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1313 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1314 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1315 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1316 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1317 # Modules that depend on AEAD
1318 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001319 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001320
1321 make
1322
1323 msg "test: default with only stream cipher"
1324 make test
1325
1326 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1327}
1328
1329component_test_tls1_2_default_stream_cipher_only_use_psa () {
1330 msg "build: default with only stream cipher use psa"
1331
1332 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1333 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1334 scripts/config.py unset MBEDTLS_GCM_C
1335 scripts/config.py unset MBEDTLS_CCM_C
1336 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1337 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1338 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1339 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1340 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1341 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1342 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1343 # Modules that depend on AEAD
1344 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001345 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001346
1347 make
1348
1349 msg "test: default with only stream cipher use psa"
1350 make test
1351
1352 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1353}
1354
1355component_test_tls1_2_default_cbc_legacy_cipher_only () {
1356 msg "build: default with only CBC-legacy cipher"
1357
1358 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1359 scripts/config.py unset MBEDTLS_GCM_C
1360 scripts/config.py unset MBEDTLS_CCM_C
1361 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1362 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1363 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1364 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1365 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1366 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1367 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1368 # Modules that depend on AEAD
1369 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001370 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001371
1372 make
1373
1374 msg "test: default with only CBC-legacy cipher"
1375 make test
1376
1377 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1378 tests/ssl-opt.sh -f "TLS 1.2"
1379}
1380
1381component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
1382 msg "build: default with only CBC-legacy cipher use psa"
1383
1384 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1385 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1386 scripts/config.py unset MBEDTLS_GCM_C
1387 scripts/config.py unset MBEDTLS_CCM_C
1388 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1389 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1390 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1391 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1392 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1393 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1394 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1395 # Modules that depend on AEAD
1396 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001397 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001398
1399 make
1400
1401 msg "test: default with only CBC-legacy cipher use psa"
1402 make test
1403
1404 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1405 tests/ssl-opt.sh -f "TLS 1.2"
1406}
1407
1408component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
1409 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1410
1411 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1412 scripts/config.py unset MBEDTLS_GCM_C
1413 scripts/config.py unset MBEDTLS_CCM_C
1414 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1415 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1416 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1417 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1418 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1419 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1420 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1421 # Modules that depend on AEAD
1422 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001423 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001424
1425 make
1426
1427 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1428 make test
1429
1430 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1431 tests/ssl-opt.sh -f "TLS 1.2"
1432}
1433
1434component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
1435 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
1436
1437 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1438 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1439 scripts/config.py unset MBEDTLS_GCM_C
1440 scripts/config.py unset MBEDTLS_CCM_C
1441 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1442 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1443 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1444 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1445 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1446 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1447 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1448 # Modules that depend on AEAD
1449 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001450 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001451
1452 make
1453
1454 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
1455 make test
1456
1457 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
1458 tests/ssl-opt.sh -f "TLS 1.2"
1459}
1460
Gilles Peskine636c26a2020-03-04 20:46:15 +01001461component_test_new_ecdh_context () {
1462 msg "build: new ECDH context (ASan build)" # ~ 6 min
1463 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1464 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1465 make
1466
1467 msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1468 make test
1469
1470 msg "test: new ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001471 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001472
1473 msg "test: new ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1474 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001475 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001476}
1477
1478component_test_everest () {
1479 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
1480 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1481 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1482 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1483 make
1484
1485 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1486 make test
1487
Gilles Peskineee8af062023-11-02 19:58:03 +01001488 msg "test: metatests (clang, ASan)"
1489 tests/scripts/run-metatests.sh any asan
1490
Gilles Peskine636c26a2020-03-04 20:46:15 +01001491 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001492 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001493
1494 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1495 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001496 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001497}
1498
Gilles Peskined3beca92020-07-03 00:15:37 +02001499component_test_everest_curve25519_only () {
1500 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
1501 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1502 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1503 scripts/config.py unset MBEDTLS_ECDSA_C
1504 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1505 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1506 # Disable all curves
1507 for c in $(sed -n 's/#define \(MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED\).*/\1/p' <"$CONFIG_H"); do
1508 scripts/config.py unset "$c"
1509 done
1510 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1511
1512 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1513
1514 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1515 make test
1516}
1517
Gilles Peskine8f073122018-11-27 15:58:47 +01001518component_test_small_ssl_out_content_len () {
1519 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001520 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1521 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001522 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1523 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001524
Gilles Peskine8f073122018-11-27 15:58:47 +01001525 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001526 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001527}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001528
Gilles Peskine8f073122018-11-27 15:58:47 +01001529component_test_small_ssl_in_content_len () {
1530 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001531 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1532 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001533 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1534 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001535
Gilles Peskine8f073122018-11-27 15:58:47 +01001536 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001537 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001538}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001539
Gilles Peskine8f073122018-11-27 15:58:47 +01001540component_test_small_ssl_dtls_max_buffering () {
1541 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001542 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001543 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1544 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001545
Gilles Peskine8f073122018-11-27 15:58:47 +01001546 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001547 tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
Gilles Peskine8f073122018-11-27 15:58:47 +01001548}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001549
Gilles Peskine8f073122018-11-27 15:58:47 +01001550component_test_small_mbedtls_ssl_dtls_max_buffering () {
1551 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001552 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001553 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1554 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001555
Gilles Peskine8f073122018-11-27 15:58:47 +01001556 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001557 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001558}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001559
Gilles Peskine75cc7712019-09-06 19:47:17 +02001560component_test_psa_collect_statuses () {
1561 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001562 scripts/config.py full
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001563 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001564 # Check that psa_crypto_init() succeeded at least once
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001565 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001566 rm -f tests/statuses.log
1567}
1568
Gilles Peskine8f073122018-11-27 15:58:47 +01001569component_test_full_cmake_clang () {
1570 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001571 scripts/config.py full
Gilles Peskine83264be2022-10-30 21:02:40 +01001572 CC=clang CXX=clang cmake -D CMAKE_BUILD_TYPE:String=Release -D ENABLE_TESTING=On -D TEST_CPP=1 .
Gilles Peskine8f073122018-11-27 15:58:47 +01001573 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001574
k-stachowiak0291cb72019-06-26 15:52:12 +02001575 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001576 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001577
Gilles Peskine83264be2022-10-30 21:02:40 +01001578 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
1579 programs/test/cpp_dummy_build
1580
Gilles Peskineee8af062023-11-02 19:58:03 +01001581 msg "test: metatests (clang)"
Gilles Peskinee38eb792023-11-03 18:05:38 +01001582 tests/scripts/run-metatests.sh any pthread
Gilles Peskineee8af062023-11-02 19:58:03 +01001583
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02001584 msg "program demos (full config, clang)" # ~10s
1585 tests/scripts/run_demos.py
1586
k-stachowiak0291cb72019-06-26 15:52:12 +02001587 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001588 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001589
Gilles Peskine8f073122018-11-27 15:58:47 +01001590 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001591 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001592
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001593 msg "test: compat.sh RC4, 3DES & NULL (full config)" # ~ 2min
1594 tests/compat.sh -e '^$' -f 'NULL\|3DES\|DES-CBC3\|RC4\|ARCFOUR'
1595
1596 msg "test: compat.sh single-DES (full config)" # ~ 30s
1597 env OPENSSL="$OPENSSL_LEGACY" tests/compat.sh -e '3DES\|DES-CBC3' -f 'DES'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001598
Gilles Peskine8f073122018-11-27 15:58:47 +01001599 msg "test: compat.sh ARIA + ChachaPoly"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001600 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001601}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001602
Gilles Peskine9603a442022-11-29 16:01:41 +01001603skip_suites_without_constant_flow () {
1604 # Skip the test suites that don't have any constant-flow annotations.
1605 # This will need to be adjusted if we ever start declaring things as
1606 # secret from macros or functions inside tests/include or tests/src.
1607 SKIP_TEST_SUITES=$(
1608 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
1609 sed 's/test_suite_//; s/\.function$//' |
1610 tr '\n' ,)
1611 export SKIP_TEST_SUITES
1612}
1613
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001614component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001615 # This tests both (1) accesses to undefined memory, and (2) branches or
1616 # memory access depending on secret values. To distinguish between those:
1617 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1618 # - or alternatively, change the build type to MemSanDbg, which enables
1619 # origin tracking and nicer stack traces (which are useful for debugging
1620 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1621 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001622 scripts/config.py full
1623 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1624 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1625 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1626 make
1627
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001628 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001629 make test
1630}
1631
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01001632component_release_test_valgrind_constant_flow () {
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001633 # This tests both (1) everything that valgrind's memcheck usually checks
1634 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1635 # etc.) and (2) branches or memory access depending on secret values,
1636 # which will be reported as uninitialized memory. To distinguish between
1637 # secret and actually uninitialized:
1638 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1639 # - or alternatively, build with debug info and manually run the offending
1640 # test suite with valgrind --track-origins=yes, then check if the origin
1641 # was TEST_CF_SECRET() or something else.
1642 msg "build: cmake release GCC, full config with constant flow testing"
1643 scripts/config.py full
1644 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Gilles Peskine9603a442022-11-29 16:01:41 +01001645 skip_suites_without_constant_flow
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001646 cmake -D CMAKE_BUILD_TYPE:String=Release .
1647 make
1648
1649 # this only shows a summary of the results (how many of each type)
1650 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine9603a442022-11-29 16:01:41 +01001651 msg "test: some suites (valgrind + constant flow)"
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001652 make memcheck
1653}
1654
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001655component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02001656 # Test that removing the deprecated features from the default
1657 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001658 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1659 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1660 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1661
1662 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1663 make test
1664}
1665
1666component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02001667 msg "build: make, full_no_deprecated config" # ~ 30s
1668 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001669 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1670
Gilles Peskine30de2e82020-04-20 21:39:22 +02001671 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001672 make test
1673}
1674
Gilles Peskine8386ea22020-04-30 09:07:29 +02001675component_test_full_no_deprecated_deprecated_warning () {
1676 # Test that there is nothing deprecated in "full_no_deprecated".
1677 # A deprecated feature would trigger a warning (made fatal) from
1678 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02001679 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1680 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001681 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
1682 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
1683 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1684
Gilles Peskine30de2e82020-04-20 21:39:22 +02001685 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001686 make test
1687}
1688
Gilles Peskine8386ea22020-04-30 09:07:29 +02001689component_test_full_deprecated_warning () {
1690 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
1691 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001692 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001693 scripts/config.py full
1694 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001695 # Expect warnings from '#warning' directives in check_config.h.
1696 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001697
Gilles Peskine8386ea22020-04-30 09:07:29 +02001698 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1699 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
1700 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001701 # Expect warnings from '#warning' directives in check_config.h and
1702 # from the use of deprecated functions in test suites.
1703 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -Wno-error=cpp -DMBEDTLS_TEST_DEPRECATED' tests
Gilles Peskine841b14b2019-11-26 17:37:37 +01001704
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001705 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
1706 make test
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02001707
1708 msg "program demos: full config + MBEDTLS_TEST_DEPRECATED" # ~10s
1709 tests/scripts/run_demos.py
Gilles Peskine8f073122018-11-27 15:58:47 +01001710}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00001711
Gilles Peskineec541fe2020-01-31 14:24:14 +01001712# Check that the specified libraries exist and are empty.
1713are_empty_libraries () {
1714 nm "$@" >/dev/null 2>/dev/null
1715 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
1716}
1717
1718component_build_crypto_default () {
1719 msg "build: make, crypto only"
1720 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01001721 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001722 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001723}
1724
1725component_build_crypto_full () {
1726 msg "build: make, crypto only, full config"
1727 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01001728 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001729 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001730}
1731
Gilles Peskine8df27482022-10-21 19:34:54 +02001732component_test_crypto_for_psa_service () {
Gilles Peskine21503df2022-10-11 21:05:06 +02001733 msg "build: make, config for PSA crypto service"
1734 scripts/config.py crypto
1735 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1736 # Disable things that are not needed for just cryptography, to
1737 # reach a configuration that would be typical for a PSA cryptography
1738 # service providing all implemented PSA algorithms.
1739 # System stuff
1740 scripts/config.py unset MBEDTLS_ERROR_C
1741 scripts/config.py unset MBEDTLS_TIMING_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001742 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskine21503df2022-10-11 21:05:06 +02001743 # Crypto stuff with no PSA interface
1744 scripts/config.py unset MBEDTLS_BASE64_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001745 scripts/config.py unset MBEDTLS_BLOWFISH_C
1746 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
1747 # Keep MBEDTLS_MD_C because RSA and ECDSA need it, also HMAC_DRBG which
1748 # is needed for deterministic ECDSA.
1749 scripts/config.py unset MBEDTLS_ECJPAKE_C
1750 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
Gilles Peskine21503df2022-10-11 21:05:06 +02001751 scripts/config.py unset MBEDTLS_NIST_KW_C
1752 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1753 scripts/config.py unset MBEDTLS_PEM_WRITE_C
1754 scripts/config.py unset MBEDTLS_PKCS12_C
1755 scripts/config.py unset MBEDTLS_PKCS5_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001756 # We keep MBEDTLS_PK_{,PARSE,WRITE}_C because PSA with RSA needs it.
1757 scripts/config.py unset MBEDTLS_XTEA_C
Gilles Peskine21503df2022-10-11 21:05:06 +02001758 make CFLAGS='-O1 -Werror' all test
1759 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1760}
1761
Gilles Peskineec541fe2020-01-31 14:24:14 +01001762component_build_crypto_baremetal () {
1763 msg "build: make, crypto only, baremetal config"
1764 scripts/config.py crypto_baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001765 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001766 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001767}
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001768support_build_crypto_baremetal () {
Daniel Axtens1a021af2020-08-31 14:22:58 +10001769 support_build_baremetal "$@"
1770}
1771
1772component_build_baremetal () {
1773 msg "build: make, baremetal config"
1774 scripts/config.py baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001775 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Daniel Axtens1a021af2020-08-31 14:22:58 +10001776}
1777support_build_baremetal () {
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001778 # Older Glibc versions include time.h from other headers such as stdlib.h,
1779 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
1780 # problem, Ubuntu 18.04 is ok.
1781 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
1782}
Gilles Peskineec541fe2020-01-31 14:24:14 +01001783
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001784# depends.py family of tests
Andrzej Kurek85d69302022-10-05 09:14:07 -04001785component_test_depends_py_cipher_id () {
1786 msg "test/build: depends.py cipher_id (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001787 tests/scripts/depends.py cipher_id --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001788}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001789
Andrzej Kurek85d69302022-10-05 09:14:07 -04001790component_test_depends_py_cipher_chaining () {
1791 msg "test/build: depends.py cipher_chaining (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001792 tests/scripts/depends.py cipher_chaining --unset-use-psa
John Durkopc14be902020-08-20 06:16:41 -07001793}
1794
Andrzej Kurek85d69302022-10-05 09:14:07 -04001795component_test_depends_py_cipher_padding () {
1796 msg "test/build: depends.py cipher_padding (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001797 tests/scripts/depends.py cipher_padding --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001798}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001799
Andrzej Kurek85d69302022-10-05 09:14:07 -04001800component_test_depends_py_curves () {
1801 msg "test/build: depends.py curves (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001802 tests/scripts/depends.py curves --unset-use-psa
John Durkop2ec2eaa2020-08-24 18:29:15 -07001803}
1804
Andrzej Kurek85d69302022-10-05 09:14:07 -04001805component_test_depends_py_hashes () {
1806 msg "test/build: depends.py hashes (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001807 tests/scripts/depends.py hashes --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001808}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001809
Andrzej Kurek85d69302022-10-05 09:14:07 -04001810component_test_depends_py_kex () {
1811 msg "test/build: depends.py kex (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001812 tests/scripts/depends.py kex --unset-use-psa
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001813}
1814
Andrzej Kurek85d69302022-10-05 09:14:07 -04001815component_test_depends_py_pkalgs () {
1816 msg "test/build: depends.py pkalgs (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001817 tests/scripts/depends.py pkalgs --unset-use-psa
1818}
1819
1820# PSA equivalents of the depends.py tests
1821component_test_depends_py_cipher_id_psa () {
1822 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1823 tests/scripts/depends.py cipher_id
1824}
1825
1826component_test_depends_py_cipher_chaining_psa () {
1827 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1828 tests/scripts/depends.py cipher_chaining
1829}
1830
1831component_test_depends_py_cipher_padding_psa () {
1832 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1833 tests/scripts/depends.py cipher_padding
1834}
1835
1836component_test_depends_py_curves_psa () {
1837 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1838 tests/scripts/depends.py curves
1839}
1840
1841component_test_depends_py_hashes_psa () {
1842 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1843 tests/scripts/depends.py hashes
1844}
1845
1846component_test_depends_py_kex_psa () {
1847 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1848 tests/scripts/depends.py kex
1849}
1850
1851component_test_depends_py_pkalgs_psa () {
1852 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Andrzej Kurek85d69302022-10-05 09:14:07 -04001853 tests/scripts/depends.py pkalgs
Gilles Peskine8f073122018-11-27 15:58:47 +01001854}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001855
Dave Rodgman5fce4f62023-01-20 13:18:05 +00001856component_build_no_pk_rsa_alt_support () {
1857 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
1858
1859 scripts/config.py full
1860 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
1861 scripts/config.py set MBEDTLS_RSA_C
1862 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
1863
1864 # Only compile - this is primarily to test for compile issues
1865 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
1866}
1867
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001868component_test_no_use_psa_crypto_full_cmake_asan() {
1869 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02001870 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001871 scripts/config.py full
1872 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
1873 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1874 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1875 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02001876 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001877 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01001878 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001879 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001880
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001881 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001882 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001883
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001884 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001885 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001886
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001887 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001888 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001889
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001890 msg "test: compat.sh RC4, 3DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
1891 tests/compat.sh -e '^$' -f 'NULL\|3DES\|DES-CBC3\|RC4\|ARCFOUR'
1892
1893 msg "test: compat.sh single-DES (full minus MBEDTLS_USE_PSA_CRYPTO)"
1894 env OPENSSL="$OPENSSL_LEGACY" tests/compat.sh -e '3DES\|DES-CBC3' -f 'DES'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001895
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001896 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001897 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001898}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001899
Ronald Crond2c53e62021-09-13 09:38:05 +02001900component_test_psa_crypto_config_accel_ecdsa () {
1901 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1902
1903 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1904 # partial support for cipher operations in the driver test library.
1905 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1906 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Gilles Peskine62de7672022-04-21 11:05:16 +02001907 # Disable obsolete hashes (alternatively we could enable support for them
1908 # in the driver test library).
1909 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1910 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
Ronald Crond2c53e62021-09-13 09:38:05 +02001911
1912 # SHA384 needed for some ECDSA signature tests.
1913 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
1914
1915 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
1916 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1917 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1918
1919 # Restore test driver base configuration
1920 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
1921
1922 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1923 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1924 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1925 scripts/config.py unset MBEDTLS_ECDSA_C
1926 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1927 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1928
1929 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
1930 make CFLAGS="$ASAN_CFLAGS -O -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
1931
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01001932 not grep mbedtls_ecdsa_ library/ecdsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02001933
1934 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1935 make test
1936}
1937
1938component_test_psa_crypto_config_accel_rsa_signature () {
1939 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
1940
1941 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1942 # partial support for cipher operations in the driver test library.
1943 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1944 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1945
1946 # It seems it is not possible to remove only the support for RSA signature
1947 # in the library. Thus we have to remove all RSA support (signature and
1948 # encryption/decryption). AS there is no driver support for asymmetric
1949 # encryption/decryption so far remove RSA encryption/decryption from the
1950 # application algorithm list.
1951 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1952 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1953
1954 # Make sure both the library and the test library support the SHA hash
1955 # algorithms and only those ones (SHA256 is included by default). That way:
1956 # - the test library can compute the RSA signatures even in the case of a
1957 # composite RSA signature algorithm based on a SHA hash (no other hash
1958 # used in the unit tests).
1959 # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
1960 # fulfilled as the hash SHA algorithm is supported by the library, and
1961 # thus the tests are run, not skipped.
1962 # - when testing a signature key with an algorithm wildcard built from
1963 # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
1964 # algorithm based on the hashes supported by the library is also
1965 # supported by the test library.
1966 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1967 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1968 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1969 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160_C
1970
1971 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA1_C
1972 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
1973 # We need PEM parsing in the test library as well to support the import
1974 # of PEM encoded RSA keys.
1975 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_PEM_PARSE_C
1976 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_BASE64_C
1977
1978 loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
1979 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1980 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1981
1982 # Restore test driver base configuration
1983 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA1_C
1984 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
1985 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_PEM_PARSE_C
1986 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_BASE64_C
1987
1988
1989 # Mbed TLS library build
1990 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1991 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1992
1993 # Remove RSA support and its dependencies
1994 scripts/config.py unset MBEDTLS_PKCS1_V15
1995 scripts/config.py unset MBEDTLS_PKCS1_V21
1996 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1997 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1998 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1999 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2000 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2001 scripts/config.py unset MBEDTLS_RSA_C
2002 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2003
2004 scripts/config.py unset MBEDTLS_MD2_C
2005 scripts/config.py unset MBEDTLS_MD4_C
2006 scripts/config.py unset MBEDTLS_MD5_C
2007 scripts/config.py unset MBEDTLS_RIPEMD160_C
2008 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
2009 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
2010 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
2011
2012 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2013 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2014
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002015 not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
2016 not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02002017
2018 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
2019 make test
2020}
2021
Ronald Cronf7e483c2021-05-08 14:32:59 +02002022component_test_psa_crypto_config_accel_hash () {
2023 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2024
2025 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
2026 # partial support for cipher operations in the driver test library.
2027 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2028 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
2029
2030 loc_accel_list="ALG_MD4 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
2031 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2032 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2033
2034 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2035 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2036 scripts/config.py unset MBEDTLS_MD2_C
2037 scripts/config.py unset MBEDTLS_MD4_C
2038 scripts/config.py unset MBEDTLS_MD5_C
2039 scripts/config.py unset MBEDTLS_RIPEMD160_C
2040 scripts/config.py unset MBEDTLS_SHA1_C
2041 # Don't unset MBEDTLS_SHA256_C as it is needed by PSA crypto core.
2042 scripts/config.py unset MBEDTLS_SHA512_C
2043 # Unset MBEDTLS_SSL_PROTO_SSL3, MBEDTLS_SSL_PROTO_TLS1 and MBEDTLS_SSL_PROTO_TLS1_1 as they depend on MBEDTLS_SHA1_C
2044 scripts/config.py unset MBEDTLS_SSL_PROTO_SSL3
2045 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
2046 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
2047 # Unset MBEDTLS_SSL_CBC_RECORD_SPLITTING as it depends on MBEDTLS_SSL_PROTO_TLS1 in the default configuration.
2048 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
2049 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2050 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2051
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002052 not grep mbedtls_sha512_init library/sha512.o
2053 not grep mbedtls_sha1_init library/sha1.o
Ronald Cronf7e483c2021-05-08 14:32:59 +02002054
2055 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2056 make test
2057}
2058
Ronald Cron09623702021-10-18 11:26:01 +02002059component_test_psa_crypto_config_accel_cipher () {
2060 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
2061
Gilles Peskine186331872022-04-12 15:58:03 +02002062 # This test case focuses on cipher+AEAD. We don't yet support all
2063 # combinations of configurations, so deactivate block-cipher-based MACs.
2064 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CMAC
2065
Ronald Cron09623702021-10-18 11:26:01 +02002066 loc_accel_list="ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB ALG_OFB ALG_XTS KEY_TYPE_DES"
2067 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2068 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2069
2070 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2071 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2072
2073 # There is no intended accelerator support for ALG STREAM_CIPHER and
2074 # ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
2075 # inclusion of the Mbed TLS cipher operations. As we want to test here with
2076 # cipher operations solely supported by accelerators, disabled those
2077 # PSA configuration options.
2078 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2079 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Ronald Cron09623702021-10-18 11:26:01 +02002080
2081 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2082 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2083 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2084 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2085 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2086 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2087 scripts/config.py unset MBEDTLS_DES_C
2088
2089 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2090 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2091
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002092 not grep mbedtls_des* library/des.o
Ronald Cron09623702021-10-18 11:26:01 +02002093
2094 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2095 make test
2096}
2097
Przemek Stekiel8b56f232022-10-02 20:58:39 +02002098component_test_psa_crypto_config_accel_aead () {
2099 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2100
2101 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
2102 # partial support for cipher operations in the driver test library.
2103 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2104 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
2105
2106 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2107 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2108 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2109
2110 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2111 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2112
2113 scripts/config.py unset MBEDTLS_GCM_C
2114 scripts/config.py unset MBEDTLS_CCM_C
2115 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2116 # Features that depend on AEAD
2117 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
2118 scripts/config.py unset MBEDTLS_SSL_TICKET_C
2119
2120 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2121 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2122
2123 # There's a risk of something getting re-enabled via config_psa.h
2124 # make sure it did not happen.
2125 not grep mbedtls_ccm library/ccm.o
2126 not grep mbedtls_gcm library/gcm.o
2127 not grep mbedtls_chachapoly library/chachapoly.o
2128
2129 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2130 make test
2131}
2132
John Durkop4377bf72020-10-23 01:26:57 -07002133component_test_psa_crypto_config_no_driver() {
John Durkop4377bf72020-10-23 01:26:57 -07002134 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
2135 scripts/config.py full
2136 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2137 scripts/config.py unset MBEDTLS_PSA_CRYPTO_DRIVERS
2138 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkope7012c72020-10-26 09:55:01 -07002139 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop4377bf72020-10-23 01:26:57 -07002140
2141 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
John Durkopd8959392020-09-20 23:09:17 -07002142 make test
2143}
2144
Gilles Peskined4c85af2023-07-20 22:19:45 +02002145component_test_aead_chachapoly_disabled() {
2146 msg "build: full minus CHACHAPOLY"
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002147 scripts/config.py full
2148 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Gilles Peskined4c85af2023-07-20 22:19:45 +02002149 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002150 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
2151
Gilles Peskined4c85af2023-07-20 22:19:45 +02002152 msg "test: full minus CHACHAPOLY"
2153 make test
2154}
2155
2156component_test_aead_only_ccm() {
2157 msg "build: full minus CHACHAPOLY and GCM"
2158 scripts/config.py full
2159 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2160 scripts/config.py unset MBEDTLS_GCM_C
2161 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2162 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2163 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
2164
2165 msg "test: full minus CHACHAPOLY and GCM"
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002166 make test
2167}
2168
John Durkopd0321952020-10-29 21:37:36 -07002169# This should be renamed to test and updated once the accelerator ECDH code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08002170component_build_psa_accel_alg_ecdh() {
Gilles Peskine168be012023-07-19 19:36:55 +02002171 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
John Durkopd0321952020-10-29 21:37:36 -07002172 scripts/config.py full
2173 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2174 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2175 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2176 scripts/config.py unset MBEDTLS_ECDH_C
2177 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2178 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2179 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2180 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2181 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2182 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2183 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2184}
2185
John Durkopf4c4cb02020-10-28 20:09:55 -07002186# This should be renamed to test and updated once the accelerator ECC key pair code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08002187component_build_psa_accel_key_type_ecc_key_pair() {
Gilles Peskine168be012023-07-19 19:36:55 +02002188 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR"
John Durkopf4c4cb02020-10-28 20:09:55 -07002189 scripts/config.py full
2190 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2191 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2192 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002193 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_KEY_PAIR 1
John Durkop07cc04a2020-11-16 22:08:34 -08002194 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
John Durkopf4c4cb02020-10-28 20:09:55 -07002195 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
John Durkop9814fa22020-11-04 12:28:15 -08002196 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkopf4c4cb02020-10-28 20:09:55 -07002197}
2198
2199# This should be renamed to test and updated once the accelerator ECC public key code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08002200component_build_psa_accel_key_type_ecc_public_key() {
Gilles Peskine168be012023-07-19 19:36:55 +02002201 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
John Durkopf4c4cb02020-10-28 20:09:55 -07002202 scripts/config.py full
2203 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2204 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2205 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002206 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
2207 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
John Durkopf4c4cb02020-10-28 20:09:55 -07002208 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
John Durkop9814fa22020-11-04 12:28:15 -08002209 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkopf4c4cb02020-10-28 20:09:55 -07002210}
2211
John Durkopd0321952020-10-29 21:37:36 -07002212# This should be renamed to test and updated once the accelerator HMAC code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08002213component_build_psa_accel_alg_hmac() {
Gilles Peskine168be012023-07-19 19:36:55 +02002214 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
John Durkopd0321952020-10-29 21:37:36 -07002215 scripts/config.py full
2216 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2217 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2218 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2219 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2220 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2221}
2222
2223# This should be renamed to test and updated once the accelerator HKDF code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08002224component_build_psa_accel_alg_hkdf() {
Gilles Peskine168be012023-07-19 19:36:55 +02002225 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
John Durkopd0321952020-10-29 21:37:36 -07002226 scripts/config.py full
2227 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2228 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2229 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2230 scripts/config.py unset MBEDTLS_HKDF_C
John Durkopbd069d32020-10-31 22:14:03 -07002231 # Make sure to unset TLS1_3_EXPERIMENTAL since it requires HKDF_C and will not build properly without it.
2232 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
John Durkopd0321952020-10-29 21:37:36 -07002233 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2234 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2235}
2236
John Durkop1b7ee052020-11-27 08:51:22 -08002237# This should be renamed to test and updated once the accelerator MD2 code is in place and ready to test.
2238component_build_psa_accel_alg_md2() {
Gilles Peskine168be012023-07-19 19:36:55 +02002239 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD2 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002240 scripts/config.py full
2241 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2242 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2243 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2244 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2245 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2246 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2247 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2248 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2249 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2250 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2251 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2252 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2253 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD2 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2254}
2255
2256# This should be renamed to test and updated once the accelerator MD4 code is in place and ready to test.
2257component_build_psa_accel_alg_md4() {
Gilles Peskine168be012023-07-19 19:36:55 +02002258 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD4 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002259 scripts/config.py full
2260 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2261 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2262 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2263 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2264 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2265 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2266 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2267 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2268 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2269 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2270 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2271 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2272 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD4 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2273}
2274
2275# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
2276component_build_psa_accel_alg_md5() {
Gilles Peskine168be012023-07-19 19:36:55 +02002277 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002278 scripts/config.py full
2279 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2280 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2281 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2282 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2283 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2284 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2285 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2286 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2287 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2288 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2289 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2290 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2291 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2292}
2293
2294# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
2295component_build_psa_accel_alg_ripemd160() {
Gilles Peskine168be012023-07-19 19:36:55 +02002296 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002297 scripts/config.py full
2298 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2299 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2300 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2301 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2302 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2303 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2304 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2305 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2306 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2307 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2308 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2309 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2310 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2311}
2312
2313# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
2314component_build_psa_accel_alg_sha1() {
Gilles Peskine168be012023-07-19 19:36:55 +02002315 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002316 scripts/config.py full
2317 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2318 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2319 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2320 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2321 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2322 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2323 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2324 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2325 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2326 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2327 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2328 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2329 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2330}
2331
2332# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
2333component_build_psa_accel_alg_sha224() {
Gilles Peskine168be012023-07-19 19:36:55 +02002334 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002335 scripts/config.py full
2336 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2337 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2338 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2339 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2340 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2341 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2342 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2343 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2344 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2345 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2346 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2347 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2348}
2349
2350# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
2351component_build_psa_accel_alg_sha256() {
Gilles Peskine168be012023-07-19 19:36:55 +02002352 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002353 scripts/config.py full
2354 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2355 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2356 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2357 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2358 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2359 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2360 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2361 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2362 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2363 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2364 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2365 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2366 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2367}
2368
2369# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
2370component_build_psa_accel_alg_sha384() {
Gilles Peskine168be012023-07-19 19:36:55 +02002371 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002372 scripts/config.py full
2373 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2374 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2375 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2376 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2377 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2378 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2379 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2380 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2381 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2382 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2383 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2384 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2385}
2386
2387# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
2388component_build_psa_accel_alg_sha512() {
Gilles Peskine168be012023-07-19 19:36:55 +02002389 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002390 scripts/config.py full
2391 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2392 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2393 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2394 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2395 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2396 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2397 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2398 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2399 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2400 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2401 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2402 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2403 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2404}
2405
John Durkopd0321952020-10-29 21:37:36 -07002406# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08002407component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
Gilles Peskine168be012023-07-19 19:36:55 +02002408 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
John Durkopd0321952020-10-29 21:37:36 -07002409 scripts/config.py full
2410 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2411 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2412 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkopbd069d32020-10-31 22:14:03 -07002413 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002414 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2415 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2416 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07002417 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
John Durkopbd069d32020-10-31 22:14:03 -07002418 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2419}
2420
2421# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08002422component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
Gilles Peskine168be012023-07-19 19:36:55 +02002423 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
John Durkopbd069d32020-10-31 22:14:03 -07002424 scripts/config.py full
2425 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2426 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2427 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2428 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002429 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2430 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2431 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002432 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2433 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2434}
2435
2436# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08002437component_build_psa_accel_alg_rsa_oaep() {
Gilles Peskine168be012023-07-19 19:36:55 +02002438 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
John Durkopbd069d32020-10-31 22:14:03 -07002439 scripts/config.py full
2440 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2441 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2442 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2443 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_OAEP 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002444 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2445 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2446 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002447 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2448 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2449}
2450
2451# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08002452component_build_psa_accel_alg_rsa_pss() {
Gilles Peskine168be012023-07-19 19:36:55 +02002453 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
John Durkopbd069d32020-10-31 22:14:03 -07002454 scripts/config.py full
2455 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2456 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2457 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2458 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002459 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2460 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2461 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07002462 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2463 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2464}
2465
2466# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08002467component_build_psa_accel_key_type_rsa_key_pair() {
Gilles Peskine168be012023-07-19 19:36:55 +02002468 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR + PSA_WANT_ALG_RSA_PSS"
John Durkopbd069d32020-10-31 22:14:03 -07002469 scripts/config.py full
2470 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2471 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2472 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2473 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2474 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
2475 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2476 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2477}
2478
2479# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08002480component_build_psa_accel_key_type_rsa_public_key() {
Gilles Peskine168be012023-07-19 19:36:55 +02002481 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
John Durkopbd069d32020-10-31 22:14:03 -07002482 scripts/config.py full
2483 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2484 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2485 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2486 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2487 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
2488 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2489 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkopd0321952020-10-29 21:37:36 -07002490}
2491
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002492component_test_check_params_functionality () {
2493 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002494 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002495 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002496 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Ronald Crona1236142020-07-01 16:01:21 +02002497 make CC=gcc CFLAGS='-Werror -O1' all test
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002498}
2499
Gilles Peskineb28636b2019-01-02 19:06:24 +01002500component_test_check_params_without_platform () {
2501 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002502 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002503 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002504 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
2505 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
2506 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
2507 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
Gilles Peskine32e889d2020-04-12 23:43:28 +02002508 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002509 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
2510 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskine9c764bf2022-09-18 14:05:23 +02002511 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002512 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
2513 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +01002514 make CC=gcc CFLAGS='-Werror -O1' all test
2515}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002516
Gilles Peskineb28636b2019-01-02 19:06:24 +01002517component_test_check_params_silent () {
2518 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002519 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002520 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01002521 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
2522 make CC=gcc CFLAGS='-Werror -O1' all test
2523}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002524
Dave Rodgman173227d2023-06-29 09:29:00 +01002525component_build_aes_variations() { # ~45s
2526 msg "build: aes.o for all combinations of relevant config options"
Dave Rodgmanbf998282023-06-29 12:10:45 +01002527
Dave Rodgman173227d2023-06-29 09:29:00 +01002528 for a in set unset; do
2529 for b in set unset; do
2530 for c in set unset; do
2531 for d in set unset; do
2532 for e in set unset; do
2533 for f in set unset; do
2534 for g in set unset; do
Dave Rodgmanbf998282023-06-29 12:10:45 +01002535 echo ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
2536 echo ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
2537 echo ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
2538 echo ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
2539 echo ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
2540 echo ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
2541 echo ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman173227d2023-06-29 09:29:00 +01002542
Dave Rodgmanbf998282023-06-29 12:10:45 +01002543 ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
2544 ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
2545 ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
2546 ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
2547 ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
2548 ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
2549 ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman173227d2023-06-29 09:29:00 +01002550
Dave Rodgmanbf998282023-06-29 12:10:45 +01002551 rm -f library/aes.o
2552 make -C library aes.o CC="clang" CFLAGS="-O0 -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
Dave Rodgman173227d2023-06-29 09:29:00 +01002553 done
2554 done
2555 done
2556 done
2557 done
2558 done
2559 done
2560}
2561
Gilles Peskine8f073122018-11-27 15:58:47 +01002562component_test_no_platform () {
2563 # Full configuration build, without platform support, file IO and net sockets.
2564 # This should catch missing mbedtls_printf definitions, and by disabling file
2565 # IO, it should catch missing '#include <stdio.h>'
2566 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Paul Elliott68050372023-11-03 19:24:56 +00002567 scripts/config.py full_no_platform
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002568 scripts/config.py unset MBEDTLS_PLATFORM_C
2569 scripts/config.py unset MBEDTLS_NET_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002570 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002571 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002572 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
2573 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Paul Elliott68050372023-11-03 19:24:56 +00002574 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +01002575 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
2576 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002577 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
2578 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01002579}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00002580
Gilles Peskine8f073122018-11-27 15:58:47 +01002581component_build_no_std_function () {
2582 # catch compile bugs in _uninit functions
2583 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002584 scripts/config.py full
2585 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
2586 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002587 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine31fdda12021-10-08 11:45:47 +02002588 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskine25319702021-10-07 19:34:57 +02002589 make
Gilles Peskine8f073122018-11-27 15:58:47 +01002590}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01002591
Gilles Peskine8f073122018-11-27 15:58:47 +01002592component_build_no_ssl_srv () {
2593 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002594 scripts/config.py full
2595 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002596 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002597}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002598
Gilles Peskine8f073122018-11-27 15:58:47 +01002599component_build_no_ssl_cli () {
2600 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002601 scripts/config.py full
2602 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002603 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002604}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002605
Gilles Peskine8f073122018-11-27 15:58:47 +01002606component_build_no_sockets () {
2607 # Note, C99 compliance can also be tested with the sockets support disabled,
2608 # as that requires a POSIX platform (which isn't the same as C99).
2609 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002610 scripts/config.py full
2611 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
2612 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002613 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01002614}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02002615
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002616component_test_memory_buffer_allocator_backtrace () {
2617 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002618 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2619 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2620 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
2621 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Gilles Peskineff30bd02021-10-19 21:33:32 +02002622 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002623 make
2624
2625 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
2626 make test
2627}
2628
2629component_test_memory_buffer_allocator () {
2630 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002631 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2632 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Gilles Peskineff30bd02021-10-19 21:33:32 +02002633 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002634 make
2635
2636 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2637 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002638
2639 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2640 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002641 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002642}
2643
Gilles Peskine8f073122018-11-27 15:58:47 +01002644component_test_no_max_fragment_length () {
2645 # Run max fragment length tests with MFL disabled
2646 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002647 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01002648 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2649 make
Hanno Becker5175ac62017-09-18 15:36:25 +01002650
Gilles Peskine8f073122018-11-27 15:58:47 +01002651 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002652 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01002653}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002654
Hanno Becker545ced42019-02-19 11:10:48 +00002655component_test_asan_remove_peer_certificate () {
2656 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002657 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00002658 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2659 make
2660
2661 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2662 make test
2663
2664 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002665 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002666
2667 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002668 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002669
2670 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002671 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002672}
2673
Gilles Peskine8f073122018-11-27 15:58:47 +01002674component_test_no_max_fragment_length_small_ssl_out_content_len () {
2675 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002676 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2677 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
2678 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01002679 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2680 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10002681
Gilles Peskine8f073122018-11-27 15:58:47 +01002682 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002683 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002684
2685 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002686 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002687}
Angus Grattonc4dd0732018-04-11 16:28:39 +10002688
Darryl Greenaad82f92019-12-02 10:53:11 +00002689component_test_variable_ssl_in_out_buffer_len () {
2690 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
2691 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2692 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2693 make
2694
2695 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2696 make test
2697
2698 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002699 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002700
2701 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002702 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002703}
2704
2705component_test_variable_ssl_in_out_buffer_len_CID () {
2706 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
2707 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2708 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
2709
2710 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2711 make
2712
2713 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
2714 make test
2715
2716 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002717 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002718
2719 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002720 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002721}
2722
2723component_test_variable_ssl_in_out_buffer_len_record_splitting () {
2724 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled (ASan build)"
2725 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2726 scripts/config.py set MBEDTLS_SSL_CBC_RECORD_SPLITTING
2727
2728 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2729 make
2730
2731 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING"
2732 make test
2733
2734 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002735 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002736
2737 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002738 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002739}
2740
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002741component_test_ssl_alloc_buffer_and_mfl () {
2742 msg "build: default config with memory buffer allocator and MFL extension"
2743 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2744 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2745 scripts/config.py set MBEDTLS_MEMORY_DEBUG
2746 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2747 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
Gilles Peskineff30bd02021-10-19 21:33:32 +02002748 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002749 make
2750
2751 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
2752 make test
2753
2754 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002755 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002756}
2757
Gilles Peskine636c26a2020-03-04 20:46:15 +01002758component_test_when_no_ciphersuites_have_mac () {
2759 msg "build: when no ciphersuites have MAC"
2760 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
2761 scripts/config.py unset MBEDTLS_ARC4_C
2762 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2763 make
2764
2765 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
2766 make test
2767
2768 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002769 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01002770}
2771
Gilles Peskine8f073122018-11-27 15:58:47 +01002772component_test_null_entropy () {
2773 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002774 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
2775 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
2776 scripts/config.py set MBEDTLS_ENTROPY_C
2777 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002778 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002779 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
2780 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00002781 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01002782 make
Janos Follath06c54002016-06-09 13:57:40 +01002783
Gilles Peskine8f073122018-11-27 15:58:47 +01002784 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
2785 make test
2786}
Janos Follath06c54002016-06-09 13:57:40 +01002787
Raoul Strackxa4e86142020-06-15 17:03:13 +02002788component_test_no_date_time () {
2789 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
2790 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
Gilles Peskine31fdda12021-10-08 11:45:47 +02002791 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Raoul Strackxa4e86142020-06-15 17:03:13 +02002792 make
2793
2794 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
2795 make test
2796}
2797
Andrzej Kurekc890b222023-01-17 04:03:19 -05002798component_test_alt_timing() {
2799 msg "build: alternate timing implementation"
2800 scripts/config.py set MBEDTLS_TIMING_ALT
2801 make lib TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
2802
2803 msg "test: MBEDTLS_TIMING_ALT - test suites"
2804 make test TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
Andrzej Kurek3a261a42023-01-26 04:33:59 -05002805
2806 msg "selftest - MBEDTLS-TIMING_ALT"
2807 make programs TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../../tests/src/external_timing -I../tests/src/external_timing"
2808 programs/test/selftest
Andrzej Kurekc890b222023-01-17 04:03:19 -05002809}
2810
Gilles Peskine8f073122018-11-27 15:58:47 +01002811component_test_platform_calloc_macro () {
2812 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002813 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2814 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
2815 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01002816 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2817 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01002818
Gilles Peskine8f073122018-11-27 15:58:47 +01002819 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
2820 make test
2821}
Hanno Beckere5fecec2018-10-11 11:02:52 +01002822
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002823component_test_malloc_0_null () {
2824 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002825 scripts/config.py full
Gilles Peskine2e70f1c2023-07-20 19:00:15 +02002826 make CC=gcc CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"$PWD/tests/configs/user-config-malloc-0-null.h\"' $ASAN_CFLAGS -O" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002827
2828 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
2829 make test
2830
2831 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
2832 # Just the calloc selftest. "make test" ran the others as part of the
2833 # test suites.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002834 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01002835
2836 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
2837 # Run a subset of the tests. The choice is a balance between coverage
2838 # and time (including time indirectly wasted due to flaky tests).
2839 # The current choice is to skip tests whose description includes
2840 # "proxy", which is an approximation of skipping tests that use the
2841 # UDP proxy, which tend to be slower and flakier.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002842 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002843}
2844
Gilles Peskine8f073122018-11-27 15:58:47 +01002845component_test_aes_fewer_tables () {
2846 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002847 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002848 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002849
Gilles Peskine8f073122018-11-27 15:58:47 +01002850 msg "test: AES_FEWER_TABLES"
2851 make test
2852}
Hanno Becker83ebf782017-07-07 12:29:15 +01002853
Gilles Peskine8f073122018-11-27 15:58:47 +01002854component_test_aes_rom_tables () {
2855 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002856 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002857 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002858
Gilles Peskine8f073122018-11-27 15:58:47 +01002859 msg "test: AES_ROM_TABLES"
2860 make test
2861}
Hanno Becker83ebf782017-07-07 12:29:15 +01002862
Gilles Peskine8f073122018-11-27 15:58:47 +01002863component_test_aes_fewer_tables_and_rom_tables () {
2864 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002865 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2866 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002867 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002868
Gilles Peskine8f073122018-11-27 15:58:47 +01002869 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2870 make test
2871}
2872
Gilles Peskine592f5912019-10-07 18:49:32 +02002873component_test_ctr_drbg_aes_256_sha_256 () {
2874 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002875 scripts/config.py full
2876 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2877 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002878 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2879 make
2880
2881 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2882 make test
2883}
2884
2885component_test_ctr_drbg_aes_128_sha_512 () {
2886 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002887 scripts/config.py full
2888 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2889 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02002890 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2891 make
2892
2893 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2894 make test
2895}
2896
2897component_test_ctr_drbg_aes_128_sha_256 () {
2898 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002899 scripts/config.py full
2900 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2901 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2902 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002903 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2904 make
2905
2906 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2907 make test
2908}
2909
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002910component_test_se_default () {
2911 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002912 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02002913 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002914
2915 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2916 make test
2917}
2918
Steven Cooremand57203d2020-07-16 20:28:59 +02002919component_test_psa_crypto_drivers () {
Gilles Peskine8d77ec22023-07-26 18:45:20 +02002920 msg "build: full + test drivers dispatching to builtins"
Steven Cooreman753f9732021-03-15 11:38:44 +01002921 scripts/config.py full
Steven Cooremand57203d2020-07-16 20:28:59 +02002922 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
Gilles Peskinefe0acc62021-09-20 19:20:04 +02002923 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
2924 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002925 loc_cflags="${loc_cflags} -I../tests/include -O2"
2926
2927 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002928
Gilles Peskine8d77ec22023-07-26 18:45:20 +02002929 msg "test: full + test drivers dispatching to builtins"
Steven Cooremand57203d2020-07-16 20:28:59 +02002930 make test
2931}
2932
Gilles Peskine8f073122018-11-27 15:58:47 +01002933component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002934 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002935 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02002936 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine27482f12021-11-04 12:52:14 +01002937 programs/test/dlopen_demo.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002938}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02002939
Gilles Peskinecf740502019-07-03 20:43:05 +02002940component_test_cmake_shared () {
2941 msg "build/test: cmake shared" # ~ 2min
2942 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
2943 make
Gilles Peskine56c01612019-07-03 20:43:32 +02002944 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02002945 make test
Gilles Peskine27482f12021-11-04 12:52:14 +01002946 programs/test/dlopen_demo.sh
Gilles Peskinecf740502019-07-03 20:43:05 +02002947}
2948
Gilles Peskineec10bf12019-09-20 19:56:06 +02002949test_build_opt () {
2950 info=$1 cc=$2; shift 2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002951 $cc --version
Gilles Peskineec10bf12019-09-20 19:56:06 +02002952 for opt in "$@"; do
2953 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskinee094a182020-04-14 20:08:41 +02002954 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02002955 # We're confident enough in compilers to not run _all_ the tests,
2956 # but at least run the unit tests. In particular, runs with
2957 # optimizations use inline assembly whereas runs with -O0
2958 # skip inline assembly.
2959 make test # ~30s
2960 make clean
2961 done
2962}
2963
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002964# For FreeBSD we invoke the function by name so this condition is added
2965# to disable the existing test_clang_opt function for linux.
2966if [[ $(uname) != "Linux" ]]; then
2967 component_test_clang_opt () {
2968 scripts/config.py full
2969 test_build_opt 'full config' clang -O0 -Os -O2
2970 }
2971fi
2972
2973component_test_clang_latest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002974 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002975 test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002976}
2977support_test_clang_latest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002978 type "$CLANG_LATEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02002979}
2980
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002981component_test_clang_earliest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002982 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002983 test_build_opt 'full config' "$CLANG_EARLIEST" -O0
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002984}
2985support_test_clang_earliest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002986 type "$CLANG_EARLIEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002987}
2988
2989component_test_gcc_latest_opt () {
2990 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002991 test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002992}
2993support_test_gcc_latest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002994 type "$GCC_LATEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002995}
2996
2997component_test_gcc_earliest_opt () {
2998 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002999 test_build_opt 'full config' "$GCC_EARLIEST" -O0
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003000}
3001support_test_gcc_earliest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003002 type "$GCC_EARLIEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02003003}
3004
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02003005component_build_mbedtls_config_file () {
3006 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
Gilles Peskine6af9dc92022-04-07 20:55:57 +02003007 scripts/config.py -w full_config.h full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02003008 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
3009 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02003010 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine036a9bb2022-04-07 21:06:41 +02003011 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3012 make clean
3013
3014 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
3015 # In the user config, disable one feature (for simplicity, pick a feature
3016 # that nothing else depends on).
3017 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3018 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
3019 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3020
3021 rm -f user_config.h full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003022}
3023
Gilles Peskine690a2ef2022-04-07 21:59:14 +02003024component_build_psa_config_file () {
3025 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
3026 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3027 cp "$CRYPTO_CONFIG_H" psa_test_config.h
3028 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
3029 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02003030 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine690a2ef2022-04-07 21:59:14 +02003031 programs/test/query_compile_time_config MBEDTLS_CMAC_C
3032 make clean
3033
3034 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
3035 # In the user config, disable one feature, which will reflect on the
3036 # mbedtls configuration so we can query it with query_compile_time_config.
3037 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
3038 scripts/config.py unset MBEDTLS_CMAC_C
3039 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
3040 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
3041
3042 rm -f psa_test_config.h psa_user_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003043}
3044
Gilles Peskine8f073122018-11-27 15:58:47 +01003045component_test_m32_o0 () {
Gilles Peskinea0c51fb2021-10-07 19:27:16 +02003046 # Build without optimization, so as to use portable C code (in a 32-bit
3047 # build) and not the i386-specific inline assembly.
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003048 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003049 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02003050 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01003051
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003052 msg "test: i386, make, gcc -O0 (ASan build)"
3053 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01003054}
Gilles Peskine878cf602019-01-06 20:50:38 +00003055support_test_m32_o0 () {
3056 case $(uname -m) in
Pengyu Lva89b3672022-10-21 10:50:26 +00003057 amd64|x86_64) true;;
Gilles Peskine878cf602019-01-06 20:50:38 +00003058 *) false;;
3059 esac
3060}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003061
Gilles Peskine6fa69862021-10-05 09:36:03 +02003062component_test_m32_o2 () {
3063 # Build with optimization, to use the i386 specific inline assembly
3064 # and go faster for tests.
3065 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003066 scripts/config.py full
Gilles Peskine6fa69862021-10-05 09:36:03 +02003067 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003068
Gilles Peskine6fa69862021-10-05 09:36:03 +02003069 msg "test: i386, make, gcc -O2 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003070 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003071
Gilles Peskine6fa69862021-10-05 09:36:03 +02003072 msg "test ssl-opt.sh, i386, make, gcc-O2"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003073 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003074}
Gilles Peskine3daa83e2021-10-07 19:25:29 +02003075support_test_m32_o2 () {
Gilles Peskine878cf602019-01-06 20:50:38 +00003076 support_test_m32_o0 "$@"
3077}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003078
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003079component_test_m32_everest () {
3080 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003081 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
3082 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02003083 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003084
3085 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
3086 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003087
3088 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003089 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01003090
3091 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
3092 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003093 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003094}
3095support_test_m32_everest () {
3096 support_test_m32_o0 "$@"
3097}
3098
Gilles Peskine8f073122018-11-27 15:58:47 +01003099component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003100 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003101 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02003102 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003103
3104 msg "test: 64-bit ILP32, make, gcc"
3105 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01003106}
Gilles Peskine878cf602019-01-06 20:50:38 +00003107support_test_mx32 () {
3108 case $(uname -m) in
3109 amd64|x86_64) true;;
3110 *) false;;
3111 esac
3112}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003113
Peter Kolbus60c6da22018-12-27 06:59:04 -06003114component_test_min_mpi_window_size () {
3115 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003116 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06003117 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3118 make
3119
3120 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
3121 make test
3122}
3123
Gilles Peskine8f073122018-11-27 15:58:47 +01003124component_test_have_int32 () {
3125 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003126 scripts/config.py unset MBEDTLS_HAVE_ASM
3127 scripts/config.py unset MBEDTLS_AESNI_C
3128 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01003129 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01003130
Gilles Peskine8f073122018-11-27 15:58:47 +01003131 msg "test: gcc, force 32-bit bignum limbs"
3132 make test
3133}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01003134
Gilles Peskine8f073122018-11-27 15:58:47 +01003135component_test_have_int64 () {
3136 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003137 scripts/config.py unset MBEDTLS_HAVE_ASM
3138 scripts/config.py unset MBEDTLS_AESNI_C
3139 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01003140 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01003141
Gilles Peskine8f073122018-11-27 15:58:47 +01003142 msg "test: gcc, force 64-bit bignum limbs"
3143 make test
3144}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003145
Gilles Peskine8f073122018-11-27 15:58:47 +01003146component_test_no_udbl_division () {
3147 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003148 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003149 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01003150 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003151
Gilles Peskine8f073122018-11-27 15:58:47 +01003152 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
3153 make test
3154}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003155
Gilles Peskine8f073122018-11-27 15:58:47 +01003156component_test_no_64bit_multiplication () {
3157 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003158 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003159 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01003160 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003161
Gilles Peskine8f073122018-11-27 15:58:47 +01003162 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
3163 make test
3164}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003165
Gilles Peskine3809f5f2020-11-09 15:40:05 +01003166component_test_no_strings () {
3167 msg "build: no strings" # ~10s
3168 scripts/config.py full
3169 # Disable options that activate a large amount of string constants.
3170 scripts/config.py unset MBEDTLS_DEBUG_C
3171 scripts/config.py unset MBEDTLS_ERROR_C
3172 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
3173 scripts/config.py unset MBEDTLS_VERSION_FEATURES
3174 make CFLAGS='-Werror -Os'
3175
3176 msg "test: no strings" # ~ 10s
3177 make test
3178}
3179
Gilles Peskine8f073122018-11-27 15:58:47 +01003180component_build_arm_none_eabi_gcc () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003181 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003182 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02003183 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
Gilles Peskine18487f62020-04-30 23:11:54 +02003184
Gilles Peskine60d99472021-09-01 20:00:33 +02003185 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003186 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003187}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003188
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003189component_build_arm_linux_gnueabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003190 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003191 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02003192 # Build for a target platform that's close to what Debian uses
3193 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
Dave Rodgman52af7692022-03-31 14:27:24 +01003194 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003195 # Build everything including programs, see for example
Dave Rodgman52af7692022-03-31 14:27:24 +01003196 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003197 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'
3198
Gilles Peskine60d99472021-09-01 20:00:33 +02003199 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003200 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size library/*.o
3201}
3202support_build_arm_linux_gnueabi_gcc_arm5vte () {
3203 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
3204}
3205
3206component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003207 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003208 scripts/config.py baremetal
3209 # This is an imperfect substitute for
3210 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnard9a260a62021-07-06 09:44:59 +02003211 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02003212 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
Gilles Peskine18487f62020-04-30 23:11:54 +02003213
Gilles Peskine60d99472021-09-01 20:00:33 +02003214 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003215 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02003216}
3217
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003218component_build_arm_none_eabi_gcc_m0plus () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003219 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
3220 scripts/config.py baremetal_size
Gilles Peskineaeedd742020-09-02 11:03:04 +02003221 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
Gilles Peskine18487f62020-04-30 23:11:54 +02003222
Gilles Peskine60d99472021-09-01 20:00:33 +02003223 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
Gilles Peskine18487f62020-04-30 23:11:54 +02003224 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003225}
3226
Gilles Peskine8f073122018-11-27 15:58:47 +01003227component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003228 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003229 scripts/config.py baremetal
3230 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003231 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
Gilles Peskine8f073122018-11-27 15:58:47 +01003232 echo "Checking that software 64-bit division is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003233 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003234}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003235
Gilles Peskine8f073122018-11-27 15:58:47 +01003236component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003237 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003238 scripts/config.py baremetal
3239 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003240 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
Gilles Peskine8f073122018-11-27 15:58:47 +01003241 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003242 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003243}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003244
Dave Rodgman43ea9ab2023-06-02 10:26:24 -04003245component_build_arm_clang_thumb () {
3246 # ~ 30s
3247
3248 scripts/config.py baremetal
3249
3250 msg "build: clang thumb 2, make"
3251 make clean
3252 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
3253
3254 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
3255 msg "build: clang thumb 1 -O0, make"
3256 make clean
3257 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
3258
3259 msg "build: clang thumb 1 -Os, make"
3260 make clean
3261 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
3262}
3263
Gilles Peskine8f073122018-11-27 15:58:47 +01003264component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02003265 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003266 scripts/config.py baremetal
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003267 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02003268
3269 msg "size: ARM Compiler 5"
3270 "$ARMC5_FROMELF" -z library/*.o
3271
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003272 make clean
Andres AG87bb5772016-09-27 15:05:15 +01003273
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003274 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
3275
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003276 # ARM Compiler 6 - Target ARMv7-A
3277 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003278
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003279 # ARM Compiler 6 - Target ARMv7-M
3280 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02003281
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003282 # ARM Compiler 6 - Target ARMv8-A - AArch32
3283 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003284
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003285 # ARM Compiler 6 - Target ARMv8-M
3286 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02003287
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003288 # ARM Compiler 6 - Target ARMv8-A - AArch64
3289 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003290
3291 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
3292 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
3293
3294 # ARM Compiler 6 - Target Cortex-M0
3295 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
Gilles Peskine8f073122018-11-27 15:58:47 +01003296}
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003297
Pengyu Lvd216c042023-03-03 18:23:35 +08003298support_build_armcc () {
3299 armc5_cc="$ARMC5_BIN_DIR/armcc"
3300 armc6_cc="$ARMC6_BIN_DIR/armclang"
3301 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
3302}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01003303
Manuel Pégourié-Gonnarddd8807f2020-02-26 09:56:27 +01003304component_build_ssl_hw_record_accel() {
3305 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
3306 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
3307 make CFLAGS='-Werror -O1'
3308}
3309
Hanno Beckera711f6e2020-05-04 12:03:51 +01003310component_test_tls13_experimental () {
3311 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3312 scripts/config.pl set MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
3313 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3314 make
3315 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3316 make test
3317}
3318
Gilles Peskine8f073122018-11-27 15:58:47 +01003319component_build_mingw () {
3320 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003321 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs
Hanno Beckere963efa2018-01-03 10:03:43 +00003322
Gilles Peskine8f073122018-11-27 15:58:47 +01003323 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003324 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
Gilles Peskine8f073122018-11-27 15:58:47 +01003325 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02003326
Gilles Peskine8f073122018-11-27 15:58:47 +01003327 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003328 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 lib programs
3329 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 tests
Gilles Peskine8f073122018-11-27 15:58:47 +01003330 make WINDOWS_BUILD=1 clean
Pengyu Lvb2ca0322023-10-19 17:17:19 +08003331
3332 msg "build: Windows cross build - mingw64, make (Library only, AESNI intrinsics)" # ~ 30s
3333 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
Pengyu Lve6cbec82023-10-20 09:49:01 +08003334 make WINDOWS_BUILD=1 clean
3335
3336 msg "build: Windows cross build - mingw64, make (Library only, default config without MBEDTLS_AESNI_C)" # ~ 30s
3337 ./scripts/config.py unset MBEDTLS_AESNI_C
3338 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib
3339 make WINDOWS_BUILD=1 clean
Pengyu Lvb2ca0322023-10-19 17:17:19 +08003340 }
Jaeden Amero117b8a42019-04-17 15:19:26 +01003341support_build_mingw() {
Pengyu Lva19ce122023-02-24 15:38:52 +08003342 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
3343 [0-5]*|"") false;;
Jaeden Amero117b8a42019-04-17 15:19:26 +01003344 *) true;;
3345 esac
3346}
Simon Butcher91aef332016-11-17 09:20:50 +00003347
Gilles Peskine8f073122018-11-27 15:58:47 +01003348component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003349 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003350 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003351 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
3352 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02003353
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003354 msg "test: main suites (MSan)" # ~ 10s
3355 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003356
Gilles Peskineee8af062023-11-02 19:58:03 +01003357 msg "test: metatests (MSan)"
3358 tests/scripts/run-metatests.sh any msan
3359
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02003360 msg "program demos (MSan)" # ~20s
3361 tests/scripts/run_demos.py
3362
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003363 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003364 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003365
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003366 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003367
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003368 if [ "$MEMORY" -gt 0 ]; then
3369 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003370 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003371 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003372}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003373
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01003374component_release_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003375 msg "build: Release (clang)"
Gilles Peskine619b73d2022-11-29 16:45:30 +01003376 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003377 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3378 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003379
Gilles Peskine619b73d2022-11-29 16:45:30 +01003380 msg "test: main suites, Valgrind (default config)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003381 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003382
Gilles Peskine636c26a2020-03-04 20:46:15 +01003383 # Optional parts (slow; currently broken on OS X because programs don't
3384 # seem to receive signals under valgrind on OS X).
Gilles Peskine619b73d2022-11-29 16:45:30 +01003385 # These optional parts don't run on the CI.
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003386 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003387 msg "test: ssl-opt.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003388 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003389 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003390
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003391 if [ "$MEMORY" -gt 1 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003392 msg "test: compat.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003393 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003394 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003395
3396 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003397 msg "test: context-info.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003398 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003399 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003400}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003401
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01003402component_release_test_valgrind_psa () {
Gilles Peskine619b73d2022-11-29 16:45:30 +01003403 msg "build: Release, full (clang)"
3404 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
3405 scripts/config.py full
3406 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3407 make
3408
3409 msg "test: main suites, Valgrind (full config)"
3410 make memcheck
3411}
3412
Paul Elliott2ab9a7a2021-11-25 17:29:40 +00003413support_test_cmake_out_of_source () {
3414 distrib_id=""
3415 distrib_ver=""
3416 distrib_ver_minor=""
3417 distrib_ver_major=""
3418
3419 # Attempt to parse lsb-release to find out distribution and version. If not
3420 # found this should fail safe (test is supported).
3421 if [[ -f /etc/lsb-release ]]; then
3422
3423 while read -r lsb_line; do
3424 case "$lsb_line" in
3425 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
3426 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
3427 esac
3428 done < /etc/lsb-release
3429
3430 distrib_ver_major="${distrib_ver%%.*}"
3431 distrib_ver="${distrib_ver#*.}"
3432 distrib_ver_minor="${distrib_ver%%.*}"
3433 fi
3434
3435 # Running the out of source CMake test on Ubuntu 16.04 using more than one
3436 # processor (as the CI does) can create a race condition whereby the build
3437 # fails to see a generated file, despite that file actually having been
3438 # generated. This problem appears to go away with 18.04 or newer, so make
3439 # the out of source tests unsupported on Ubuntu 16.04.
3440 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
3441}
3442
Gilles Peskine8f073122018-11-27 15:58:47 +01003443component_test_cmake_out_of_source () {
3444 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01003445 MBEDTLS_ROOT_DIR="$PWD"
3446 mkdir "$OUT_OF_SOURCE_DIR"
3447 cd "$OUT_OF_SOURCE_DIR"
Gilles Peskine25319702021-10-07 19:34:57 +02003448 cmake -D CMAKE_BUILD_TYPE:String=Check "$MBEDTLS_ROOT_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003449 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003450
Gilles Peskine8f073122018-11-27 15:58:47 +01003451 msg "test: cmake 'out-of-source' build"
3452 make test
3453 # Test an SSL option that requires an auxiliary script in test/scripts/.
3454 # Also ensure that there are no error messages such as
3455 # "No such file or directory", which would indicate that some required
3456 # file is missing (ssl-opt.sh tolerates the absence of some files so
3457 # may exit with status 0 but emit errors).
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003458 ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' >ssl-opt.out 2>ssl-opt.err
3459 grep PASS ssl-opt.out
Gilles Peskine0a7984f2020-03-28 18:56:09 +01003460 cat ssl-opt.err >&2
3461 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003462 [ ! -s ssl-opt.err ]
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003463 rm ssl-opt.out ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01003464 cd "$MBEDTLS_ROOT_DIR"
3465 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003466}
Andres AGdc192212016-08-31 17:33:13 +01003467
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003468component_test_cmake_as_subdirectory () {
3469 msg "build: cmake 'as-subdirectory' build"
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003470 cd programs/test/cmake_subproject
3471 cmake .
3472 make
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003473 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003474}
Gilles Peskineca9cfca2022-02-04 00:21:12 +01003475support_test_cmake_as_subdirectory () {
3476 support_test_cmake_out_of_source
3477}
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003478
David Horstmann175afbd2023-01-12 14:17:01 +00003479component_build_cmake_custom_config_file () {
David Horstmann67622312023-01-31 10:34:44 +00003480 # Make a copy of config file to use for the in-tree test
3481 cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h
David Horstmann175afbd2023-01-12 14:17:01 +00003482
3483 MBEDTLS_ROOT_DIR="$PWD"
3484 mkdir "$OUT_OF_SOURCE_DIR"
3485 cd "$OUT_OF_SOURCE_DIR"
3486
David Horstmann67622312023-01-31 10:34:44 +00003487 # Build once to get the generated files (which need an intact config file)
David Horstmann175afbd2023-01-12 14:17:01 +00003488 cmake "$MBEDTLS_ROOT_DIR"
3489 make
3490
3491 msg "build: cmake with -DMBEDTLS_CONFIG_FILE"
3492 scripts/config.py -w full_config.h full
David Horstmann67622312023-01-31 10:34:44 +00003493 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003494 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR"
3495 make
3496
3497 msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
3498 # In the user config, disable one feature (for simplicity, pick a feature
3499 # that nothing else depends on).
3500 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3501
3502 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR"
3503 make
3504 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3505
3506 rm -f user_config.h full_config.h
3507
3508 cd "$MBEDTLS_ROOT_DIR"
3509 rm -rf "$OUT_OF_SOURCE_DIR"
3510
3511 # Now repeat the test for an in-tree build:
3512
David Horstmann67622312023-01-31 10:34:44 +00003513 # Restore config for the in-tree test
3514 mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003515
David Horstmann67622312023-01-31 10:34:44 +00003516 # Build once to get the generated files (which need an intact config)
David Horstmann175afbd2023-01-12 14:17:01 +00003517 cmake .
3518 make
3519
3520 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE"
3521 scripts/config.py -w full_config.h full
David Horstmann67622312023-01-31 10:34:44 +00003522 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003523 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h .
3524 make
3525
3526 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
3527 # In the user config, disable one feature (for simplicity, pick a feature
3528 # that nothing else depends on).
3529 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3530
3531 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h .
3532 make
3533 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3534
3535 rm -f user_config.h full_config.h
3536}
3537support_build_cmake_custom_config_file () {
3538 support_test_cmake_out_of_source
3539}
3540
3541
Tom Cosgrove51170622023-09-01 10:40:15 +01003542component_build_zeroize_checks () {
3543 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
3544
3545 scripts/config.py full
3546
3547 # Only compile - we're looking for sizeof-pointer-memaccess warnings
Tom Cosgrove5ffb1972023-09-01 14:40:21 +01003548 make CC=gcc CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess"
Tom Cosgrove51170622023-09-01 10:40:15 +01003549}
3550
3551
Gilles Peskine8f073122018-11-27 15:58:47 +01003552component_test_zeroize () {
3553 # Test that the function mbedtls_platform_zeroize() is not optimized away by
3554 # different combinations of compilers and optimization flags by using an
3555 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
3556 # system in all cases that the script fails, so we must manually search the
3557 # output to check whether the pass string is present and no failure strings
3558 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01003559
Gilles Peskine4976e822019-01-06 19:52:22 +00003560 # Don't try to disable ASLR. We don't care about ASLR here. We do care
3561 # about a spurious message if Gdb tries and fails, so suppress that.
3562 gdb_disable_aslr=
3563 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
3564 gdb_disable_aslr='set disable-randomization off'
3565 fi
3566
Gilles Peskine8f073122018-11-27 15:58:47 +01003567 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01003568 for compiler in clang gcc; do
3569 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
3570 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003571 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
3572 grep "The buffer was correctly zeroized" test_zeroize.log
3573 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01003574 rm -f test_zeroize.log
3575 make clean
3576 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01003577 done
Gilles Peskine8f073122018-11-27 15:58:47 +01003578}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003579
Bence Szépkúti9f849112021-10-19 15:05:36 +02003580component_test_psa_compliance () {
Bence Szépkútic1e79fd2021-11-11 20:13:14 +01003581 msg "build: make, default config + CMAC, libmbedcrypto.a only"
3582 scripts/config.py set MBEDTLS_CMAC_C
Bence Szépkútiab796e62021-10-25 19:29:07 +02003583 make -C library libmbedcrypto.a
Bence Szépkúti9f849112021-10-19 15:05:36 +02003584
3585 msg "unit test: test_psa_compliance.py"
3586 ./tests/scripts/test_psa_compliance.py
3587}
3588
3589support_test_psa_compliance () {
Bence Szépkútid6cf0892021-11-03 11:36:09 +01003590 # psa-compliance-tests only supports CMake >= 3.10.0
Bence Szépkútiab796e62021-10-25 19:29:07 +02003591 ver="$(cmake --version)"
3592 ver="${ver#cmake version }"
3593 ver_major="${ver%%.*}"
3594
3595 ver="${ver#*.}"
3596 ver_minor="${ver%%.*}"
3597
3598 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
Bence Szépkúti9f849112021-10-19 15:05:36 +02003599}
3600
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003601component_check_code_style () {
3602 msg "Check C code style"
3603 ./scripts/code_style.py
David Horstmanne09c4762022-11-10 18:30:52 +00003604}
3605
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003606support_check_code_style() {
David Horstmanne09c4762022-11-10 18:30:52 +00003607 case $(uncrustify --version) in
3608 *0.75.1*) true;;
3609 *) false;;
3610 esac
3611}
3612
Gilles Peskine8f073122018-11-27 15:58:47 +01003613component_check_python_files () {
3614 msg "Lint: Python scripts"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003615 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003616}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003617
Gilles Peskine8f073122018-11-27 15:58:47 +01003618component_check_generate_test_code () {
3619 msg "uint test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02003620 # unittest writes out mundane stuff like number or tests run on stderr.
3621 # Our convention is to reserve stderr for actual errors, and write
3622 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003623 ./tests/scripts/test_generate_test_code.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01003624}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003625
3626################################################################
3627#### Termination
3628################################################################
3629
Gilles Peskine8f073122018-11-27 15:58:47 +01003630post_report () {
3631 msg "Done, cleaning up"
Gilles Peskine24bdf022020-03-30 20:11:39 +02003632 final_cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003633
Gilles Peskine8f073122018-11-27 15:58:47 +01003634 final_report
3635}
3636
3637
3638
3639################################################################
3640#### Run all the things
3641################################################################
3642
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003643# Function invoked by --error-test to test error reporting.
3644pseudo_component_error_test () {
Gilles Peskine202e9b42021-08-02 23:28:00 +02003645 msg "Testing error reporting $error_test_i"
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003646 if [ $KEEP_GOING -ne 0 ]; then
3647 echo "Expect three failing commands."
3648 fi
Gilles Peskine202e9b42021-08-02 23:28:00 +02003649 # If the component doesn't run in a subshell, changing error_test_i to an
3650 # invalid integer will cause an error in the loop that runs this function.
3651 error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003652 # Expected error: 'grep non_existent /dev/null -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003653 grep non_existent /dev/null
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003654 # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003655 not grep -q . "$0"
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003656 # Expected error: 'make unknown_target -> 2'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003657 make unknown_target
3658 false "this should not be executed"
3659}
3660
Gilles Peskinee48351a2018-11-27 16:06:30 +01003661# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01003662run_component () {
Gilles Peskineffcdeff2018-12-04 12:49:28 +01003663 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02003664 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003665
3666 # Unconditionally create a seedfile that's sufficiently long.
3667 # Do this before each component, because a previous component may
3668 # have messed it up or shortened it.
Gilles Peskinef3133362021-07-08 19:03:50 +02003669 local dd_cmd
3670 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
3671 case $OSTYPE in
3672 linux*|freebsd*|openbsd*|darwin*) dd_cmd+=(status=none)
3673 esac
3674 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003675
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003676 # Run the component in a subshell, with error trapping and output
3677 # redirection set up based on the relevant options.
Gilles Peskine7105a332020-03-28 18:50:43 +01003678 if [ $KEEP_GOING -eq 1 ]; then
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003679 # We want to keep running if the subshell fails, so 'set -e' must
3680 # be off when the subshell runs.
Gilles Peskine7105a332020-03-28 18:50:43 +01003681 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02003682 fi
Gilles Peskine7105a332020-03-28 18:50:43 +01003683 (
3684 if [ $QUIET -eq 1 ]; then
3685 # msg() will be silenced, so just print the component name here.
3686 echo "${current_component#component_}"
3687 exec >/dev/null
3688 fi
3689 if [ $KEEP_GOING -eq 1 ]; then
3690 # Keep "set -e" off, and run an ERR trap instead to record failures.
3691 set -E
3692 trap err_trap ERR
3693 fi
3694 # The next line is what runs the component
3695 "$@"
3696 if [ $KEEP_GOING -eq 1 ]; then
3697 trap - ERR
3698 exit $last_failure_status
3699 fi
3700 )
3701 component_status=$?
3702 if [ $KEEP_GOING -eq 1 ]; then
3703 set -e
3704 if [ $component_status -ne 0 ]; then
3705 failure_count=$((failure_count + 1))
3706 fi
3707 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003708
3709 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01003710 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02003711 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01003712}
3713
3714# Preliminary setup
3715pre_check_environment
3716pre_initialize_variables
3717pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01003718
Gilles Peskine878cf602019-01-06 20:50:38 +00003719pre_check_git
Gilles Peskineef64e7f2021-07-12 18:16:01 +02003720pre_restore_files
Gilles Peskine24bdf022020-03-30 20:11:39 +02003721pre_back_up
Andrzej Kurekeb508712019-02-14 07:18:59 -05003722
Gilles Peskine878cf602019-01-06 20:50:38 +00003723build_status=0
3724if [ $KEEP_GOING -eq 1 ]; then
3725 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01003726fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02003727pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00003728pre_print_configuration
3729pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003730cleanup
3731
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003732# Run the requested tests.
Gilles Peskine202e9b42021-08-02 23:28:00 +02003733for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003734 run_component pseudo_component_error_test
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003735done
Gilles Peskine202e9b42021-08-02 23:28:00 +02003736unset error_test_i
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003737for component in $RUN_COMPONENTS; do
3738 run_component "component_$component"
3739done
Gilles Peskine8f073122018-11-27 15:58:47 +01003740
3741# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00003742post_report