blob: fa43016d3e72cfc14c4fe3cbbc72f8f4b8c39987 [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.
Bence Szépkúti44043ed2023-12-15 17:05:15 +010078# * component_release_XXX: tests that the CI should skip during PR testing.
Gilles Peskine878cf602019-01-06 20:50:38 +000079# * support_XXX: if support_XXX exists and returns false then
80# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010081# * post_XXX: things to do after running the tests.
82# * other: miscellaneous support functions.
83#
Gilles Peskinec70637a2019-01-09 22:29:17 +010084# Each component must start by invoking `msg` with a short informative message.
85#
Gilles Peskine39a3b112020-03-28 21:27:40 +010086# Warning: due to the way bash detects errors, the failure of a command
87# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
88#
Gilles Peskine7105a332020-03-28 18:50:43 +010089# Each component is executed in a separate shell process. The component
90# fails if any command in it returns a non-zero status.
91#
Gilles Peskinec70637a2019-01-09 22:29:17 +010092# The framework performs some cleanup tasks after each component. This
93# means that components can assume that the working directory is in a
94# cleaned-up state, and don't need to perform the cleanup themselves.
95# * Run `make clean`.
96# * Restore `include/mbedtks/config.h` from a backup made before running
97# the component.
Gilles Peskine636c26a2020-03-04 20:46:15 +010098# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
99# `tests/Makefile` and `programs/fuzz/Makefile` from git.
100# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +0100101#
Gilles Peskine192c72f2017-12-21 15:59:21 +0100102# The tests are roughly in order from fastest to slowest. This doesn't
103# have to be exact, but in general you should add slower tests towards
104# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100105
106
107
108################################################################
109#### Initialization and command line parsing
110################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100111
Gilles Peskine8ab29942020-03-28 18:50:49 +0100112# Abort on errors (even on the left-hand side of a pipe).
113# Treat uninitialised variables as errors.
114set -e -o pipefail -u
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100115
Gilles Peskine79598582022-08-30 21:02:44 +0200116# Enable ksh/bash extended file matching patterns
117shopt -s extglob
118
Gilles Peskine8f073122018-11-27 15:58:47 +0100119pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000120 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskinef08ca832023-09-12 19:21:54 +0200121 echo "Must be run from Mbed TLS root" >&2
Gilles Peskine8f073122018-11-27 15:58:47 +0100122 exit 1
123 fi
124}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100125
Gilles Peskine8f073122018-11-27 15:58:47 +0100126pre_initialize_variables () {
127 CONFIG_H='include/mbedtls/config.h'
John Durkopbd069d32020-10-31 22:14:03 -0700128 CRYPTO_CONFIG_H='include/psa/crypto_config.h'
Gilles Peskine24bdf022020-03-30 20:11:39 +0200129
130 # Files that are clobbered by some jobs will be backed up. Use a different
131 # suffix from auxiliary scripts so that all.sh and auxiliary scripts can
132 # independently decide when to remove the backup file.
133 backup_suffix='.all.bak'
134 # Files clobbered by config.py
135 files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H"
Gilles Peskineef64e7f2021-07-12 18:16:01 +0200136 # Files clobbered by in-tree cmake
137 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 +0200138
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200139 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100140 MEMORY=0
141 FORCE=0
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200142 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100143 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100144
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200145 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard54304472020-06-22 10:11:47 +0200146 #
147 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
148 # both values are kept in sync. If you change the value here because it
149 # breaks some tests, you'll definitely want to change it in
150 # basic-build-test.sh as well.
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200151 RELEASE_SEED=1
152
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200153 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200154 : ${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 +0200155 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200156 export MBEDTLS_TEST_PLATFORM
157
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000158 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100159 : ${OPENSSL:="openssl"}
160 : ${OPENSSL_LEGACY:="$OPENSSL"}
161 : ${OPENSSL_NEXT:="$OPENSSL"}
162 : ${GNUTLS_CLI:="gnutls-cli"}
163 : ${GNUTLS_SERV:="gnutls-serv"}
Gilles Peskine8f073122018-11-27 15:58:47 +0100164 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
165 : ${ARMC5_BIN_DIR:=/usr/bin}
166 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskine6d061342020-04-30 18:19:32 +0200167 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200168 : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
Gowtham Suresh Kumarcc029af2023-08-01 09:48:32 +0100169 : ${CLANG_LATEST:="clang-latest"}
170 : ${CLANG_EARLIEST:="clang-earliest"}
171 : ${GCC_LATEST:="gcc-latest"}
172 : ${GCC_EARLIEST:="gcc-earliest"}
Andres AGdc192212016-08-31 17:33:13 +0100173
Gilles Peskine8f073122018-11-27 15:58:47 +0100174 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000175 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine85229ac2021-09-30 18:24:21 +0200176 export MAKEFLAGS="-j$(all_sh_nproc)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100177 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000178
Gilles Peskinec761d8f2021-09-20 18:57:55 +0200179 # Include more verbose output for failing tests run by CMake or make
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000180 export CTEST_OUTPUT_ON_FAILURE=1
181
Gilles Peskine8fd59422019-10-21 17:11:33 +0200182 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Manuel Pégourié-Gonnard717f2302022-11-30 10:42:03 +0100183 # default to -O2, use -Ox _after_ this if you want another level
Manuel Pégourié-Gonnard154b84e2022-11-28 13:12:10 +0100184 ASAN_CFLAGS='-O2 -Werror -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200185
Andrzej Kurekd95b8ed2023-06-27 10:02:09 -0400186 # Platform tests have an allocation that returns null
187 export ASAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurek6e4a9be2023-07-05 08:32:43 -0400188 export MSAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurekd95b8ed2023-06-27 10:02:09 -0400189
Gilles Peskine878cf602019-01-06 20:50:38 +0000190 # Gather the list of available components. These are the functions
191 # defined in this script whose name starts with "component_".
Gowtham Suresh Kumar13850f32023-07-28 16:41:21 +0100192 ALL_COMPONENTS=$(compgen -A function component_ | sed 's/component_//')
Gilles Peskine878cf602019-01-06 20:50:38 +0000193
194 # Exclude components that are not supported on this platform.
195 SUPPORTED_COMPONENTS=
196 for component in $ALL_COMPONENTS; do
197 case $(type "support_$component" 2>&1) in
198 *' function'*)
199 if ! support_$component; then continue; fi;;
200 esac
201 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
202 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100203}
Andres AG38495a32016-07-12 16:54:33 +0100204
Gilles Peskinea28db922019-01-10 00:05:18 +0100205# Test whether the component $1 is included in the command line patterns.
206is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100207{
Gilles Peskine6702ce92021-08-06 11:35:17 +0200208 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
209 # only does word splitting.
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100210 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000211 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100212 set +f
213 case ${1#component_} in $pattern) return 0;; esac
214 done
215 set +f
216 return 1
217}
Andres AG7770ea82016-10-10 15:46:20 +0100218
Simon Butcher41eeccf2016-09-07 00:07:09 +0100219usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100220{
Gilles Peskine709346a2017-12-10 23:43:39 +0100221 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100222Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100223Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100224By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100225COMPONENT can be the name of a component or a shell wildcard pattern.
226
227Examples:
228 $0 "check_*"
229 Run all sanity checks.
230 $0 --no-armcc --except test_memsan
231 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100232
233Special options:
234 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000235 --list-all-components List all available test components and exit.
236 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100237
238General options:
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200239 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100240 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100241 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100242 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200243 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200244 --arm-none-eabi-gcc-prefix=<string>
245 Prefix for a cross-compiler for arm-none-eabi
246 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200247 --arm-linux-gnueabi-gcc-prefix=<string>
248 Prefix for a cross-compiler for arm-linux-gnueabi
249 (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100250 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200251 --restore First clean up the build tree, restoring backed up
252 files. Do not run any components unless they are
253 explicitly specified.
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100254 --error-test Error test mode: run a failing function in addition
Gilles Peskinea25c5672021-08-05 15:11:33 +0200255 to any specified component. May be repeated.
Gilles Peskinea28db922019-01-10 00:05:18 +0100256 --except Exclude the COMPONENTs listed on the command line,
257 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200258 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100259 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100260 --no-force Refuse to overwrite modified files (default).
261 --no-keep-going Stop at the first error (default).
262 --no-memory No additional memory tests (default).
Shaun Case0e7791f2021-12-20 21:14:10 -0800263 --no-quiet Print full output from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100264 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200265 --outcome-file=<path> File where test outcomes are written (not done if
266 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100267 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200268 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100269 -s|--seed Integer seed value to use for this test run.
270
271Tool path options:
272 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
273 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100274 --clang-earliest=<Clang_earliest_path> Earliest version of clang available
275 --clang-latest=<Clang_latest_path> Latest version of clang available
276 --gcc-earliest=<GCC_earliest_path> Earliest version of GCC available
277 --gcc-latest=<GCC_latest_path> Latest version of GCC available
Gilles Peskine709346a2017-12-10 23:43:39 +0100278 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
279 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
Gilles Peskine709346a2017-12-10 23:43:39 +0100280 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
281 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100282 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100283EOF
SimonB2e23c822016-04-16 21:54:39 +0100284}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100285
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200286# Cleanup before/after running a component.
287# Remove built files as well as the cmake cache/config.
288# Does not remove generated source files.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100289cleanup()
290{
Gilles Peskine7c652162017-12-11 00:01:40 +0100291 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200292
Gilles Peskine31b07e22018-03-21 12:15:06 +0100293 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000294 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100295 -iname CMakeFiles -exec rm -rf {} \+ -o \
296 \( -iname cmake_install.cmake -o \
297 -iname CTestTestfile.cmake -o \
298 -iname CMakeCache.txt \) -exec rm {} \+
299 # Recover files overwritten by in-tree CMake builds
Gilles Peskine79598582022-08-30 21:02:44 +0200300 rm -f include/Makefile include/mbedtls/Makefile programs/!(fuzz)/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200301
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100302 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
303 rm -rf programs/test/cmake_subproject/build
304 rm -f programs/test/cmake_subproject/Makefile
305 rm -f programs/test/cmake_subproject/cmake_subproject
306
Gilles Peskine24bdf022020-03-30 20:11:39 +0200307 # Restore files that may have been clobbered by the job
308 for x in $files_to_back_up; do
Gilles Peskine423dd132022-08-30 21:02:00 +0200309 if [[ -e "$x$backup_suffix" ]]; then
310 cp -p "$x$backup_suffix" "$x"
311 fi
Gilles Peskine24bdf022020-03-30 20:11:39 +0200312 done
313}
John Durkopbd069d32020-10-31 22:14:03 -0700314
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200315# Final cleanup when this script exits (except when exiting on a failure
316# in non-keep-going mode).
Gilles Peskine24bdf022020-03-30 20:11:39 +0200317final_cleanup () {
318 cleanup
319
320 for x in $files_to_back_up; do
321 rm -f "$x$backup_suffix"
322 done
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100323}
324
Gilles Peskine7c652162017-12-11 00:01:40 +0100325# Executed on exit. May be redefined depending on command line options.
326final_report () {
327 :
328}
329
330fatal_signal () {
Gilles Peskine24bdf022020-03-30 20:11:39 +0200331 final_cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100332 final_report $1
333 trap - $1
334 kill -$1 $$
335}
336
337trap 'fatal_signal HUP' HUP
338trap 'fatal_signal INT' INT
339trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200340
Gilles Peskine85229ac2021-09-30 18:24:21 +0200341# Number of processors on this machine. Used as the default setting
342# for parallel make.
343all_sh_nproc ()
344{
345 {
346 nproc || # Linux
347 sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
348 sysctl -n hw.ncpu || # FreeBSD
349 echo 1
350 } 2>/dev/null
351}
352
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100353msg()
354{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100355 if [ -n "${current_component:-}" ]; then
356 current_section="${current_component#component_}: $1"
357 else
358 current_section="$1"
359 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200360
361 if [ $QUIET -eq 1 ]; then
362 return
363 fi
364
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100365 echo ""
366 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100367 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000368 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100369 echo "******************************************************************"
370}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100371
Gilles Peskine8f073122018-11-27 15:58:47 +0100372armc6_build_test()
373{
374 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100375
Gilles Peskine18487f62020-04-30 23:11:54 +0200376 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100377 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
Dave Rodgman6cda3d32023-03-02 13:39:04 +0000378 WARNING_CFLAGS='-Werror -xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200379
380 msg "size: ARM Compiler 6 ($FLAGS)"
381 "$ARMC6_FROMELF" -z library/*.o
382
Gilles Peskine8f073122018-11-27 15:58:47 +0100383 make clean
384}
Andres AGa5cd9732016-10-17 15:23:10 +0100385
Andres AGd9eba4b2016-08-26 14:42:14 +0100386err_msg()
387{
388 echo "$1" >&2
389}
390
391check_tools()
392{
393 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000394 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100395 err_msg "$TOOL not found!"
396 exit 1
397 fi
398 done
399}
400
Gilles Peskine8f073122018-11-27 15:58:47 +0100401pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000402 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100403 all_except=0
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100404 error_test=0
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200405 restore_first=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000406 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100407
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000408 # Note that legacy options are ignored instead of being omitted from this
409 # list of options, so invocations that worked with previous version of
410 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100411 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100412 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200413 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200414 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200415 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000416 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100417 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
418 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100419 --clang-earliest) shift; CLANG_EARLIEST="$1";;
420 --clang-latest) shift; CLANG_LATEST="$1";;
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100421 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000422 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100423 --force|-f) FORCE=1;;
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100424 --gcc-earliest) shift; GCC_EARLIEST="$1";;
425 --gcc-latest) shift; GCC_LATEST="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100426 --gnutls-cli) shift; GNUTLS_CLI="$1";;
Gilles Peskine549a9612023-08-27 21:39:21 +0200427 --gnutls-legacy-cli) shift;; # ignored for backward compatibility
428 --gnutls-legacy-serv) shift;; # ignored for backward compatibility
Gilles Peskine55f7c942019-01-09 22:28:21 +0100429 --gnutls-serv) shift; GNUTLS_SERV="$1";;
430 --help|-h) usage; exit;;
431 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000432 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
433 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100434 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200435 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000436 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100437 --no-force) FORCE=0;;
438 --no-keep-going) KEEP_GOING=0;;
439 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200440 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100441 --openssl) shift; OPENSSL="$1";;
442 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
443 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200444 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100445 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200446 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100447 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200448 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200449 --restore) restore_first=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100450 --seed|-s) shift; SEED="$1";;
451 -*)
452 echo >&2 "Unknown option: $1"
453 echo >&2 "Run $0 --help for usage."
454 exit 120
455 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000456 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100457 esac
458 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100459 done
SimonB2e23c822016-04-16 21:54:39 +0100460
Gilles Peskinea28db922019-01-10 00:05:18 +0100461 # With no list of components, run everything.
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200462 if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000463 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100464 fi
465
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000466 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
467 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100468 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000469 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100470 fi
SimonB2e23c822016-04-16 21:54:39 +0100471
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200472 # Error out if an explicitly requested component doesn't exist.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100473 if [ $all_except -eq 0 ]; then
474 unsupported=0
Gilles Peskine6702ce92021-08-06 11:35:17 +0200475 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
476 # only does word splitting.
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200477 set -f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100478 for component in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200479 set +f
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200480 # If the requested name includes a wildcard character, don't
481 # check it. Accept wildcard patterns that don't match anything.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100482 case $component in
483 *[*?\[]*) continue;;
484 esac
485 case " $SUPPORTED_COMPONENTS " in
486 *" $component "*) :;;
487 *)
488 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
489 unsupported=$((unsupported + 1));;
490 esac
491 done
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200492 set +f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100493 if [ $unsupported -ne 0 ]; then
494 exit 2
495 fi
496 fi
497
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000498 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100499 RUN_COMPONENTS=
500 for component in $SUPPORTED_COMPONENTS; do
501 if is_component_included "$component"; [ $? -eq $all_except ]; then
502 RUN_COMPONENTS="$RUN_COMPONENTS $component"
503 fi
504 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000505
506 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000507 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100508}
SimonB2e23c822016-04-16 21:54:39 +0100509
Gilles Peskine8f073122018-11-27 15:58:47 +0100510pre_check_git () {
511 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100512 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100513 git checkout-index -f -q $CONFIG_H
514 cleanup
515 else
SimonB2e23c822016-04-16 21:54:39 +0100516
Gilles Peskine8f073122018-11-27 15:58:47 +0100517 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
518 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
519 echo "You can either delete this directory manually, or force the test by rerunning"
520 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
521 exit 1
522 fi
523
Gilles Peskined1174cf2019-01-09 22:30:01 +0100524 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100525 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
526 echo "You can either delete or preserve your work, or force the test by rerunning the"
527 echo "script as: $0 --force"
528 exit 1
529 fi
SimonB2e23c822016-04-16 21:54:39 +0100530 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500531}
532
Gilles Peskineef64e7f2021-07-12 18:16:01 +0200533pre_restore_files () {
534 # If the makefiles have been generated by a framework such as cmake,
535 # restore them from git. If the makefiles look like modifications from
536 # the ones checked into git, take care not to modify them. Whatever
537 # this function leaves behind is what the script will restore before
538 # each component.
539 case "$(head -n1 Makefile)" in
540 *[Gg]enerated*)
541 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
542 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
543 ;;
544 esac
545}
546
Gilles Peskine24bdf022020-03-30 20:11:39 +0200547pre_back_up () {
548 for x in $files_to_back_up; do
549 cp -p "$x" "$x$backup_suffix"
550 done
551}
552
Gilles Peskine8f073122018-11-27 15:58:47 +0100553pre_setup_keep_going () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100554 failure_count=0 # Number of failed components
555 last_failure_status=0 # Last failure status in this component
556
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100557 # See err_trap
558 previous_failure_status=0
559 previous_failed_command=
560 previous_failure_funcall_depth=0
Gilles Peskine39a3b112020-03-28 21:27:40 +0100561 unset report_failed_command
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100562
Gilles Peskine7c652162017-12-11 00:01:40 +0100563 start_red=
564 end_color=
565 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100566 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100567 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
568 start_red=$(printf '\033[31m')
569 end_color=$(printf '\033[0m')
570 ;;
571 esac
572 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100573
574 # Keep a summary of failures in a file. We'll print it out at the end.
575 failure_summary_file=$PWD/all-sh-failures-$$.log
576 : >"$failure_summary_file"
577
578 # Whether it makes sense to keep a component going after the specified
579 # command fails (test command) or not (configure or build).
Gilles Peskine6702ce92021-08-06 11:35:17 +0200580 # This function normally receives the failing simple command
581 # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
582 # this is passed instead.
Gilles Peskine7105a332020-03-28 18:50:43 +0100583 # This doesn't have to be 100% accurate: all failures are recorded anyway.
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200584 # False positives result in running things that can't be expected to
585 # work. False negatives result in things not running after something else
586 # failed even though they might have given useful feedback.
Gilles Peskine7105a332020-03-28 18:50:43 +0100587 can_keep_going_after_failure () {
588 case "$1" in
589 "msg "*) false;;
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200590 "cd "*) false;;
591 *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
592 *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
593 *make*check*) true;;
594 "grep "*) true;;
595 "[ "*) true;;
596 "! "*) true;;
Gilles Peskine7105a332020-03-28 18:50:43 +0100597 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100598 esac
599 }
Gilles Peskine7105a332020-03-28 18:50:43 +0100600
601 # This function runs if there is any error in a component.
602 # It must either exit with a nonzero status, or set
603 # last_failure_status to a nonzero value.
604 err_trap () {
605 # Save $? (status of the failing command). This must be the very
606 # first thing, before $? is overridden.
607 last_failure_status=$?
Gilles Peskine39a3b112020-03-28 21:27:40 +0100608 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskine7105a332020-03-28 18:50:43 +0100609
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100610 if [[ $last_failure_status -eq $previous_failure_status &&
611 "$failed_command" == "$previous_failed_command" &&
612 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
613 then
614 # The same command failed twice in a row, but this time one level
615 # less deep in the function call stack. This happens when the last
616 # command of a function returns a nonzero status, and the function
617 # returns that same status. Ignore the second failure.
618 previous_failure_funcall_depth=${#FUNCNAME[@]}
619 return
620 fi
621 previous_failure_status=$last_failure_status
622 previous_failed_command=$failed_command
623 previous_failure_funcall_depth=${#FUNCNAME[@]}
624
Gilles Peskine7105a332020-03-28 18:50:43 +0100625 text="$current_section: $failed_command -> $last_failure_status"
626 echo "${start_red}^^^^$text^^^^${end_color}" >&2
627 echo "$text" >>"$failure_summary_file"
628
629 # If the command is fatal (configure or build command), stop this
630 # component. Otherwise (test command) keep the component running
631 # (run more tests from the same build).
632 if ! can_keep_going_after_failure "$failed_command"; then
633 exit $last_failure_status
634 fi
635 }
636
Gilles Peskine7c652162017-12-11 00:01:40 +0100637 final_report () {
638 if [ $failure_count -gt 0 ]; then
639 echo
640 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskine7105a332020-03-28 18:50:43 +0100641 echo "${start_red}FAILED: $failure_count components${end_color}"
642 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100643 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
644 elif [ -z "${1-}" ]; then
645 echo "SUCCESS :)"
646 fi
647 if [ -n "${1-}" ]; then
648 echo "Killed by SIG$1."
649 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100650 rm -f "$failure_summary_file"
651 if [ $failure_count -gt 0 ]; then
652 exit 1
653 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100654 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100655}
656
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200657# record_status() and if_build_succeeded() are kept temporarily for backward
658# compatibility. Don't use them in new components.
Gilles Peskine7105a332020-03-28 18:50:43 +0100659record_status () {
660 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100661}
Gilles Peskine7c652162017-12-11 00:01:40 +0100662if_build_succeeded () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100663 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100664}
665
Gilles Peskine39a3b112020-03-28 21:27:40 +0100666# '! true' does not trigger the ERR trap. Arrange to trigger it, with
667# a reasonably informative error message (not just "$@").
668not () {
669 if "$@"; then
670 report_failed_command="! $*"
671 false
672 unset report_failed_command
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200673 fi
674}
675
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200676pre_prepare_outcome_file () {
677 case "$MBEDTLS_TEST_OUTCOME_FILE" in
678 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
679 esac
680 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
681 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
682 fi
683}
684
Gilles Peskine8f073122018-11-27 15:58:47 +0100685pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200686 if [ $QUIET -eq 1 ]; then
687 return
688 fi
689
Gilles Peskine8f073122018-11-27 15:58:47 +0100690 msg "info: $0 configuration"
691 echo "MEMORY: $MEMORY"
692 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200693 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100694 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100695 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100696 echo "OPENSSL: $OPENSSL"
697 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
698 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
699 echo "GNUTLS_CLI: $GNUTLS_CLI"
700 echo "GNUTLS_SERV: $GNUTLS_SERV"
Gilles Peskine8f073122018-11-27 15:58:47 +0100701 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
702 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
703}
Andres AG7770ea82016-10-10 15:46:20 +0100704
Andres AGd9eba4b2016-08-26 14:42:14 +0100705# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100706pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000707 # Build the list of variables to pass to output_env.sh.
708 set env
SimonB2e23c822016-04-16 21:54:39 +0100709
Gilles Peskine87964262019-01-06 22:40:00 +0000710 case " $RUN_COMPONENTS " in
711 # Require OpenSSL and GnuTLS if running any tests (as opposed to
712 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
713 # is a good enough approximation in practice.
Bence Szépkúticb89fbd2023-12-15 20:58:15 +0100714 *" test_"* | *" release_test_"*)
Gilles Peskine87964262019-01-06 22:40:00 +0000715 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
716 # and ssl-opt.sh, we just export the variables they require.
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +0100717 export OPENSSL="$OPENSSL"
Gilles Peskine87964262019-01-06 22:40:00 +0000718 export GNUTLS_CLI="$GNUTLS_CLI"
719 export GNUTLS_SERV="$GNUTLS_SERV"
720 # Avoid passing --seed flag in every call to ssl-opt.sh
721 if [ -n "${SEED-}" ]; then
722 export SEED
723 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000724 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
725 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000726 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
Gilles Peskine549a9612023-08-27 21:39:21 +0200727 "$GNUTLS_CLI" "$GNUTLS_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000728 ;;
729 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200730
Gilles Peskine87964262019-01-06 22:40:00 +0000731 case " $RUN_COMPONENTS " in
732 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
733 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100734
Gilles Peskine87964262019-01-06 22:40:00 +0000735 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200736 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000737 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100738
Gilles Peskine87964262019-01-06 22:40:00 +0000739 case " $RUN_COMPONENTS " in
740 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
741 esac
742
743 case " $RUN_COMPONENTS " in
744 *" test_zeroize "*) check_tools "gdb";;
745 esac
746
747 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000748 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000749 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
750 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200751 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000752 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
753 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200754 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
755 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
756 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000757 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000758
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200759 # past this point, no call to check_tool, only printing output
760 if [ $QUIET -eq 1 ]; then
761 return
762 fi
763
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000764 msg "info: output_env.sh"
765 case $RUN_COMPONENTS in
766 *_armcc*)
767 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
768 *) set "$@" RUN_ARMCC=0;;
769 esac
770 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100771}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100772
Gilles Peskine192c72f2017-12-21 15:59:21 +0100773
774
775################################################################
776#### Basic checks
777################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100778
779#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200780# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100781#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100782# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200783# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100784# 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 +0200785# time, so start with a GCC build).
786# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100787#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100788# Indicative running times are given for reference.
789
Gilles Peskine8f073122018-11-27 15:58:47 +0100790component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200791 msg "Check: recursion.pl" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200792 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100793}
Janos Follathb72c6782016-07-19 14:54:17 +0100794
Gilles Peskine8f073122018-11-27 15:58:47 +0100795component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200796 msg "Check: freshness of generated source files" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200797 tests/scripts/check-generated-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100798}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200799
Gilles Peskine8f073122018-11-27 15:58:47 +0100800component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200801 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200802 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +0100803}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200804
Gilles Peskine8f073122018-11-27 15:58:47 +0100805component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200806 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200807 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100808}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200809
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200810component_check_changelog () {
811 msg "Check: changelog entries" # < 1s
812 rm -f ChangeLog.new
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200813 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200814 if [ -e ChangeLog.new ]; then
815 # Show the diff for information. It isn't an error if the diff is
816 # non-empty.
817 diff -u ChangeLog ChangeLog.new || true
818 rm ChangeLog.new
819 fi
820}
821
Gilles Peskine8f073122018-11-27 15:58:47 +0100822component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200823 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200824 tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100825}
Darryl Greena07039c2018-03-13 16:48:16 +0000826
Gilles Peskine895868b2019-09-19 21:30:05 +0200827component_check_test_cases () {
828 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200829 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200830 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200831 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200832 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200833 fi
Gilles Peskine58987962022-12-15 14:46:31 +0100834 tests/scripts/check_test_cases.py -q $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200835 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +0200836}
837
Gilles Peskine8f073122018-11-27 15:58:47 +0100838component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200839 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200840 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100841}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200842
Gilles Peskine192c72f2017-12-21 15:59:21 +0100843
Gilles Peskine636c26a2020-03-04 20:46:15 +0100844
Gilles Peskine192c72f2017-12-21 15:59:21 +0100845################################################################
846#### Build and test many configurations and targets
847################################################################
848
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200849component_test_default_out_of_box () {
850 msg "build: make, default config (out-of-box)" # ~1min
851 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200852 # Disable fancy stuff
853 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200854
855 msg "test: main suites make, default config (out-of-box)" # ~10s
856 make test
857
858 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200859 programs/test/selftest
Gilles Peskine93aaf2e2019-06-14 18:27:03 +0200860
861 msg "program demos: make, default config (out-of-box)" # ~10s
862 tests/scripts/run_demos.py
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200863}
864
Gilles Peskine8f073122018-11-27 15:58:47 +0100865component_test_default_cmake_gcc_asan () {
866 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100867 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
868 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200869
Gilles Peskine8f073122018-11-27 15:58:47 +0100870 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
871 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200872
Gilles Peskine93aaf2e2019-06-14 18:27:03 +0200873 msg "program demos (ASan build)" # ~10s
874 tests/scripts/run_demos.py
875
Gilles Peskine97bea012020-04-23 23:37:45 +0200876 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200877 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200878
Gilles Peskineee8af062023-11-02 19:58:03 +0100879 msg "test: metatests (GCC, ASan build)"
880 tests/scripts/run-metatests.sh any asan
881
Gilles Peskine8f073122018-11-27 15:58:47 +0100882 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200883 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200884
Gilles Peskine8f073122018-11-27 15:58:47 +0100885 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200886 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200887
888 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200889 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100890}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200891
Hanno Becker01635512019-02-26 14:27:09 +0000892component_test_full_cmake_gcc_asan () {
893 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200894 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000895 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
896 make
897
898 msg "test: main suites (inc. selftests) (full config, ASan build)"
899 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +0100900
Gilles Peskine97bea012020-04-23 23:37:45 +0200901 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200902 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200903
Gilles Peskine636c26a2020-03-04 20:46:15 +0100904 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200905 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100906
907 msg "test: compat.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200908 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200909
910 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200911 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100912}
913
Ronald Cronc3623db2020-10-29 10:51:32 +0100914component_test_psa_crypto_key_id_encodes_owner () {
915 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
916 scripts/config.py full
917 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
918 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
919 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
920 make
921
922 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
923 make test
924}
925
Gilles Peskine99a34622021-06-17 11:37:52 +0200926# check_renamed_symbols HEADER LIB
927# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
928# name is LIB.
929check_renamed_symbols () {
930 ! nm "$2" | sed 's/.* //' |
931 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
932}
933
Gilles Peskine984c19f2021-06-15 18:37:38 +0200934component_build_psa_crypto_spm () {
935 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
936 scripts/config.py full
937 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
938 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
939 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
940 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
941 # We can only compile, not link, since our test and sample programs
942 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
943 # is active.
944 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskine99a34622021-06-17 11:37:52 +0200945
946 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
947 # version is not present.
948 echo "Checking for renamed symbols in the library"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200949 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskine984c19f2021-06-15 18:37:38 +0200950}
951
Ronald Cron336678b2021-01-28 17:54:24 +0100952component_test_psa_crypto_client () {
953 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
954 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
955 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
956 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
957 make
958
959 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
960 make test
961}
962
Gilles Peskine636c26a2020-03-04 20:46:15 +0100963component_test_zlib_make() {
964 msg "build: zlib enabled, make"
965 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine6fa69862021-10-05 09:36:03 +0200966 make ZLIB=1 CFLAGS='-Werror -O2'
Gilles Peskine636c26a2020-03-04 20:46:15 +0100967
968 msg "test: main suites (zlib, make)"
969 make test
970
971 msg "test: ssl-opt.sh (zlib, make)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200972 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100973}
974support_test_zlib_make () {
975 base=support_test_zlib_$$
976 cat <<'EOF' > ${base}.c
977#include "zlib.h"
978int main(void) { return 0; }
979EOF
980 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
981 ret=$?
982 rm -f ${base}.*
983 return $ret
984}
985
986component_test_zlib_cmake() {
987 msg "build: zlib enabled, cmake"
988 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine25319702021-10-07 19:34:57 +0200989 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Release .
Gilles Peskine636c26a2020-03-04 20:46:15 +0100990 make
991
992 msg "test: main suites (zlib, cmake)"
993 make test
994
995 msg "test: ssl-opt.sh (zlib, cmake)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200996 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100997}
998support_test_zlib_cmake () {
999 support_test_zlib_make "$@"
Manuel Pégourié-Gonnardf2e29022020-01-24 10:17:20 +01001000}
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +01001001
Jaeden Ameroc17f2932021-05-14 08:34:32 +01001002component_test_psa_crypto_rsa_no_genprime() {
1003 msg "build: default config minus MBEDTLS_GENPRIME"
1004 scripts/config.py unset MBEDTLS_GENPRIME
1005 make
1006
1007 msg "test: default config minus MBEDTLS_GENPRIME"
1008 make test
1009}
1010
Gilles Peskine782f4112018-11-27 16:11:09 +01001011component_test_ref_configs () {
1012 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
1013 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001014 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +01001015}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001016
Gilles Peskine8f073122018-11-27 15:58:47 +01001017component_test_sslv3 () {
1018 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001019 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +01001020 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1021 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001022
Gilles Peskine8f073122018-11-27 15:58:47 +01001023 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
1024 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +00001025
Gilles Peskine8f073122018-11-27 15:58:47 +01001026 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001027 tests/compat.sh -m 'ssl3 tls1 tls1_1 tls12 dtls1 dtls12'
Simon Butcher3ea7f522016-03-07 23:22:10 +00001028
Gilles Peskine8f073122018-11-27 15:58:47 +01001029 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001030 tests/ssl-opt.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001031
1032 msg "build: SSLv3 - context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001033 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001034}
Simon Butcher3ea7f522016-03-07 23:22:10 +00001035
Gilles Peskine8f073122018-11-27 15:58:47 +01001036component_test_no_renegotiation () {
1037 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001038 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001039 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1040 make
Simon Butcher3ea7f522016-03-07 23:22:10 +00001041
Gilles Peskine8f073122018-11-27 15:58:47 +01001042 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1043 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +01001044
Gilles Peskine8f073122018-11-27 15:58:47 +01001045 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001046 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001047}
Hanno Becker134c2ab2017-10-12 15:29:50 +01001048
Gilles Peskine56194432023-02-01 18:44:11 +01001049component_test_no_certs () {
1050 msg "build: full minus MBEDTLS_CERTS_C"
1051 scripts/config.py full
1052 scripts/config.py unset MBEDTLS_CERTS_C
1053 # Quick build+test (we're checking for stray uses of the test certs,
1054 # not expecting their absence to lead to subtle problems).
1055 make
1056
1057 msg "test: full minus MBEDTLS_CERTS_C - main suites"
1058 make test
1059}
1060
Gilles Peskine636c26a2020-03-04 20:46:15 +01001061component_test_no_pem_no_fs () {
1062 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1063 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1064 scripts/config.py unset MBEDTLS_FS_IO
1065 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1066 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
1067 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1068 make
1069
1070 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1071 make test
1072
1073 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001074 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001075}
1076
Gilles Peskine8f073122018-11-27 15:58:47 +01001077component_test_rsa_no_crt () {
1078 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001079 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +01001080 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1081 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +01001082
Gilles Peskine8f073122018-11-27 15:58:47 +01001083 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1084 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001085
Gilles Peskine8f073122018-11-27 15:58:47 +01001086 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001087 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001088
Gilles Peskine8f073122018-11-27 15:58:47 +01001089 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001090 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001091
1092 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001093 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001094}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001095
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001096component_test_no_ctr_drbg_classic () {
1097 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001098 scripts/config.py full
1099 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001100 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001101
1102 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1103 make
1104
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001105 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001106 make test
1107
Gilles Peskineba749042021-01-13 20:02:03 +01001108 # In this configuration, the TLS test programs use HMAC_DRBG.
1109 # The SSL tests are slow, so run a small subset, just enough to get
1110 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001111 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001112 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001113
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001114 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001115 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001116}
1117
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001118component_test_no_ctr_drbg_use_psa () {
1119 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001120 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001121 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1122 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001123
1124 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1125 make
1126
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001127 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1128 make test
1129
1130 # In this configuration, the TLS test programs use HMAC_DRBG.
1131 # The SSL tests are slow, so run a small subset, just enough to get
1132 # confidence that the SSL code copes with HMAC_DRBG.
1133 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001134 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001135
1136 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001137 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001138}
1139
1140component_test_no_hmac_drbg_classic () {
1141 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1142 scripts/config.py full
1143 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1144 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1145 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1146
1147 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1148 make
1149
1150 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001151 make test
1152
Gilles Peskinea2224342020-11-19 22:14:34 +01001153 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1154 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1155 # instead.
1156 # Test SSL with non-deterministic ECDSA. Only test features that
1157 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001158 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001159 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001160
1161 # To save time, only test one protocol version, since this part of
1162 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001163 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001164 tests/compat.sh -m tls12 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001165}
1166
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001167component_test_no_hmac_drbg_use_psa () {
1168 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1169 scripts/config.py full
1170 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1171 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1172 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1173
1174 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1175 make
1176
1177 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1178 make test
1179
1180 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1181 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1182 # instead.
1183 # Test SSL with non-deterministic ECDSA. Only test features that
1184 # might be affected by how ECDSA signature is performed.
1185 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001186 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001187
1188 # To save time, only test one protocol version, since this part of
1189 # the protocol is identical in (D)TLS up to 1.2.
1190 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001191 tests/compat.sh -m tls12 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001192}
1193
1194component_test_psa_external_rng_no_drbg_classic () {
1195 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1196 scripts/config.py full
1197 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1198 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001199 scripts/config.py unset MBEDTLS_ENTROPY_C
1200 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1201 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001202 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1203 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1204 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1205 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001206 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1207 # the SSL test programs don't have an RNG and can't work. Explicitly
1208 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1209 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001210
1211 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1212 make test
1213
Gilles Peskine8eb29432021-02-03 20:07:11 +01001214 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001215 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001216}
1217
1218component_test_psa_external_rng_no_drbg_use_psa () {
1219 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001220 scripts/config.py full
1221 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001222 scripts/config.py unset MBEDTLS_ENTROPY_C
1223 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1224 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001225 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1226 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1227 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1228 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1229 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1230
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001231 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001232 make test
1233
Gilles Peskine8eb29432021-02-03 20:07:11 +01001234 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001235 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001236}
1237
1238component_test_psa_external_rng_use_psa_crypto () {
1239 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1240 scripts/config.py full
1241 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1242 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1243 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1244 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1245
1246 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1247 make test
1248
Gilles Peskineba749042021-01-13 20:02:03 +01001249 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001250 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001251}
1252
Gilles Peskine55e89982023-04-28 21:04:28 +02001253component_test_psa_inject_entropy () {
1254 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
1255 scripts/config.py full
1256 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
1257 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
1258 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1259 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1260 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
1261 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
1262 make CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
1263
1264 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
1265 make test
1266}
1267
Manuel Pégourié-Gonnard1a3f9ed2020-05-19 12:38:31 +02001268component_test_ecp_no_internal_rng () {
1269 msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
1270 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1271 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1272 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1273 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1274 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
1275 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1276
1277 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1278 make
1279
1280 msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
1281 make test
1282
1283 # no SSL tests as they all depend on having a DRBG
1284}
1285
Manuel Pégourié-Gonnard53fb66d2020-06-04 09:43:14 +02001286component_test_ecp_restartable_no_internal_rng () {
1287 msg "build: Default plus ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG"
1288 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1289 scripts/config.py set MBEDTLS_ECP_RESTARTABLE
1290 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1291 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1292 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1293 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
1294 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1295
1296 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1297 make
1298
1299 msg "test: ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG module"
1300 make test
1301
1302 # no SSL tests as they all depend on having a DRBG
1303}
1304
Przemek Stekiele5352702022-10-05 11:37:54 +02001305component_test_tls1_2_default_stream_cipher_only () {
1306 msg "build: default with only stream cipher"
1307
1308 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
1309 scripts/config.py unset MBEDTLS_GCM_C
1310 scripts/config.py unset MBEDTLS_CCM_C
1311 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1312 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1313 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1314 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1315 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1316 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1317 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1318 # Modules that depend on AEAD
1319 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001320 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001321
1322 make
1323
1324 msg "test: default with only stream cipher"
1325 make test
1326
1327 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1328}
1329
1330component_test_tls1_2_default_stream_cipher_only_use_psa () {
1331 msg "build: default with only stream cipher use psa"
1332
1333 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1334 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1335 scripts/config.py unset MBEDTLS_GCM_C
1336 scripts/config.py unset MBEDTLS_CCM_C
1337 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1338 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1339 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1340 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1341 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1342 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1343 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1344 # Modules that depend on AEAD
1345 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001346 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001347
1348 make
1349
1350 msg "test: default with only stream cipher use psa"
1351 make test
1352
1353 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1354}
1355
1356component_test_tls1_2_default_cbc_legacy_cipher_only () {
1357 msg "build: default with only CBC-legacy cipher"
1358
1359 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1360 scripts/config.py unset MBEDTLS_GCM_C
1361 scripts/config.py unset MBEDTLS_CCM_C
1362 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1363 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1364 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1365 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1366 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1367 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1368 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1369 # Modules that depend on AEAD
1370 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001371 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001372
1373 make
1374
1375 msg "test: default with only CBC-legacy cipher"
1376 make test
1377
1378 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1379 tests/ssl-opt.sh -f "TLS 1.2"
1380}
1381
1382component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
1383 msg "build: default with only CBC-legacy cipher use psa"
1384
1385 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1386 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1387 scripts/config.py unset MBEDTLS_GCM_C
1388 scripts/config.py unset MBEDTLS_CCM_C
1389 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1390 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1391 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1392 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1393 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1394 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1395 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1396 # Modules that depend on AEAD
1397 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001398 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001399
1400 make
1401
1402 msg "test: default with only CBC-legacy cipher use psa"
1403 make test
1404
1405 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1406 tests/ssl-opt.sh -f "TLS 1.2"
1407}
1408
1409component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
1410 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1411
1412 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1413 scripts/config.py unset MBEDTLS_GCM_C
1414 scripts/config.py unset MBEDTLS_CCM_C
1415 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1416 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1417 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1418 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1419 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1420 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1421 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1422 # Modules that depend on AEAD
1423 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001424 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001425
1426 make
1427
1428 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1429 make test
1430
1431 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1432 tests/ssl-opt.sh -f "TLS 1.2"
1433}
1434
1435component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
1436 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
1437
1438 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1439 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1440 scripts/config.py unset MBEDTLS_GCM_C
1441 scripts/config.py unset MBEDTLS_CCM_C
1442 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1443 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1444 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1445 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1446 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1447 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1448 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1449 # Modules that depend on AEAD
1450 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001451 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001452
1453 make
1454
1455 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
1456 make test
1457
1458 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
1459 tests/ssl-opt.sh -f "TLS 1.2"
1460}
1461
Gilles Peskine636c26a2020-03-04 20:46:15 +01001462component_test_new_ecdh_context () {
1463 msg "build: new ECDH context (ASan build)" # ~ 6 min
1464 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1465 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1466 make
1467
1468 msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1469 make test
1470
1471 msg "test: new ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001472 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001473
1474 msg "test: new ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1475 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001476 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001477}
1478
1479component_test_everest () {
1480 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
1481 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1482 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1483 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1484 make
1485
1486 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1487 make test
1488
Gilles Peskineee8af062023-11-02 19:58:03 +01001489 msg "test: metatests (clang, ASan)"
1490 tests/scripts/run-metatests.sh any asan
1491
Gilles Peskine636c26a2020-03-04 20:46:15 +01001492 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001493 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001494
1495 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1496 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001497 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001498}
1499
Gilles Peskined3beca92020-07-03 00:15:37 +02001500component_test_everest_curve25519_only () {
1501 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
1502 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1503 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1504 scripts/config.py unset MBEDTLS_ECDSA_C
1505 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1506 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1507 # Disable all curves
1508 for c in $(sed -n 's/#define \(MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED\).*/\1/p' <"$CONFIG_H"); do
1509 scripts/config.py unset "$c"
1510 done
1511 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1512
1513 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1514
1515 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1516 make test
1517}
1518
Gilles Peskine8f073122018-11-27 15:58:47 +01001519component_test_small_ssl_out_content_len () {
1520 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001521 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1522 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001523 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1524 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001525
Gilles Peskine8f073122018-11-27 15:58:47 +01001526 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001527 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001528}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001529
Gilles Peskine8f073122018-11-27 15:58:47 +01001530component_test_small_ssl_in_content_len () {
1531 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001532 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1533 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001534 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1535 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001536
Gilles Peskine8f073122018-11-27 15:58:47 +01001537 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001538 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001539}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001540
Gilles Peskine8f073122018-11-27 15:58:47 +01001541component_test_small_ssl_dtls_max_buffering () {
1542 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001543 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001544 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1545 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001546
Gilles Peskine8f073122018-11-27 15:58:47 +01001547 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001548 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 +01001549}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001550
Gilles Peskine8f073122018-11-27 15:58:47 +01001551component_test_small_mbedtls_ssl_dtls_max_buffering () {
1552 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001553 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001554 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1555 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001556
Gilles Peskine8f073122018-11-27 15:58:47 +01001557 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001558 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001559}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001560
Gilles Peskine75cc7712019-09-06 19:47:17 +02001561component_test_psa_collect_statuses () {
1562 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001563 scripts/config.py full
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001564 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001565 # Check that psa_crypto_init() succeeded at least once
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001566 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001567 rm -f tests/statuses.log
1568}
1569
Gilles Peskine8f073122018-11-27 15:58:47 +01001570component_test_full_cmake_clang () {
1571 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001572 scripts/config.py full
Gilles Peskine83264be2022-10-30 21:02:40 +01001573 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 +01001574 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001575
k-stachowiak0291cb72019-06-26 15:52:12 +02001576 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001577 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001578
Gilles Peskine83264be2022-10-30 21:02:40 +01001579 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
1580 programs/test/cpp_dummy_build
1581
Gilles Peskineee8af062023-11-02 19:58:03 +01001582 msg "test: metatests (clang)"
Gilles Peskinee38eb792023-11-03 18:05:38 +01001583 tests/scripts/run-metatests.sh any pthread
Gilles Peskineee8af062023-11-02 19:58:03 +01001584
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02001585 msg "program demos (full config, clang)" # ~10s
1586 tests/scripts/run_demos.py
1587
k-stachowiak0291cb72019-06-26 15:52:12 +02001588 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001589 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001590
Gilles Peskine8f073122018-11-27 15:58:47 +01001591 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001592 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001593
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001594 msg "test: compat.sh RC4, 3DES & NULL (full config)" # ~ 2min
1595 tests/compat.sh -e '^$' -f 'NULL\|3DES\|DES-CBC3\|RC4\|ARCFOUR'
1596
1597 msg "test: compat.sh single-DES (full config)" # ~ 30s
1598 env OPENSSL="$OPENSSL_LEGACY" tests/compat.sh -e '3DES\|DES-CBC3' -f 'DES'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001599
Gilles Peskine8f073122018-11-27 15:58:47 +01001600 msg "test: compat.sh ARIA + ChachaPoly"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001601 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001602}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001603
Gilles Peskine9603a442022-11-29 16:01:41 +01001604skip_suites_without_constant_flow () {
1605 # Skip the test suites that don't have any constant-flow annotations.
1606 # This will need to be adjusted if we ever start declaring things as
1607 # secret from macros or functions inside tests/include or tests/src.
1608 SKIP_TEST_SUITES=$(
1609 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
1610 sed 's/test_suite_//; s/\.function$//' |
1611 tr '\n' ,)
1612 export SKIP_TEST_SUITES
1613}
1614
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001615component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001616 # This tests both (1) accesses to undefined memory, and (2) branches or
1617 # memory access depending on secret values. To distinguish between those:
1618 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1619 # - or alternatively, change the build type to MemSanDbg, which enables
1620 # origin tracking and nicer stack traces (which are useful for debugging
1621 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1622 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001623 scripts/config.py full
1624 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1625 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1626 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1627 make
1628
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001629 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001630 make test
1631}
1632
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01001633component_release_test_valgrind_constant_flow () {
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001634 # This tests both (1) everything that valgrind's memcheck usually checks
1635 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1636 # etc.) and (2) branches or memory access depending on secret values,
1637 # which will be reported as uninitialized memory. To distinguish between
1638 # secret and actually uninitialized:
1639 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1640 # - or alternatively, build with debug info and manually run the offending
1641 # test suite with valgrind --track-origins=yes, then check if the origin
1642 # was TEST_CF_SECRET() or something else.
1643 msg "build: cmake release GCC, full config with constant flow testing"
1644 scripts/config.py full
1645 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Gilles Peskine9603a442022-11-29 16:01:41 +01001646 skip_suites_without_constant_flow
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001647 cmake -D CMAKE_BUILD_TYPE:String=Release .
1648 make
1649
1650 # this only shows a summary of the results (how many of each type)
1651 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine9603a442022-11-29 16:01:41 +01001652 msg "test: some suites (valgrind + constant flow)"
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001653 make memcheck
1654}
1655
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001656component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02001657 # Test that removing the deprecated features from the default
1658 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001659 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1660 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1661 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1662
1663 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1664 make test
1665}
1666
1667component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02001668 msg "build: make, full_no_deprecated config" # ~ 30s
1669 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001670 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1671
Gilles Peskine30de2e82020-04-20 21:39:22 +02001672 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001673 make test
1674}
1675
Gilles Peskine8386ea22020-04-30 09:07:29 +02001676component_test_full_no_deprecated_deprecated_warning () {
1677 # Test that there is nothing deprecated in "full_no_deprecated".
1678 # A deprecated feature would trigger a warning (made fatal) from
1679 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02001680 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1681 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001682 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
1683 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
1684 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1685
Gilles Peskine30de2e82020-04-20 21:39:22 +02001686 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001687 make test
1688}
1689
Gilles Peskine8386ea22020-04-30 09:07:29 +02001690component_test_full_deprecated_warning () {
1691 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
1692 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001693 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001694 scripts/config.py full
1695 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001696 # Expect warnings from '#warning' directives in check_config.h.
1697 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001698
Gilles Peskine8386ea22020-04-30 09:07:29 +02001699 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1700 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
1701 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001702 # Expect warnings from '#warning' directives in check_config.h and
1703 # from the use of deprecated functions in test suites.
1704 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 +01001705
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001706 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
1707 make test
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02001708
1709 msg "program demos: full config + MBEDTLS_TEST_DEPRECATED" # ~10s
1710 tests/scripts/run_demos.py
Gilles Peskine8f073122018-11-27 15:58:47 +01001711}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00001712
Gilles Peskineec541fe2020-01-31 14:24:14 +01001713# Check that the specified libraries exist and are empty.
1714are_empty_libraries () {
1715 nm "$@" >/dev/null 2>/dev/null
1716 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
1717}
1718
1719component_build_crypto_default () {
1720 msg "build: make, crypto only"
1721 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01001722 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001723 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001724}
1725
1726component_build_crypto_full () {
1727 msg "build: make, crypto only, full config"
1728 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01001729 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001730 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001731}
1732
Gilles Peskine8df27482022-10-21 19:34:54 +02001733component_test_crypto_for_psa_service () {
Gilles Peskine21503df2022-10-11 21:05:06 +02001734 msg "build: make, config for PSA crypto service"
1735 scripts/config.py crypto
1736 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1737 # Disable things that are not needed for just cryptography, to
1738 # reach a configuration that would be typical for a PSA cryptography
1739 # service providing all implemented PSA algorithms.
1740 # System stuff
1741 scripts/config.py unset MBEDTLS_ERROR_C
1742 scripts/config.py unset MBEDTLS_TIMING_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001743 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskine21503df2022-10-11 21:05:06 +02001744 # Crypto stuff with no PSA interface
1745 scripts/config.py unset MBEDTLS_BASE64_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001746 scripts/config.py unset MBEDTLS_BLOWFISH_C
1747 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
1748 # Keep MBEDTLS_MD_C because RSA and ECDSA need it, also HMAC_DRBG which
1749 # is needed for deterministic ECDSA.
1750 scripts/config.py unset MBEDTLS_ECJPAKE_C
1751 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
Gilles Peskine21503df2022-10-11 21:05:06 +02001752 scripts/config.py unset MBEDTLS_NIST_KW_C
1753 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1754 scripts/config.py unset MBEDTLS_PEM_WRITE_C
1755 scripts/config.py unset MBEDTLS_PKCS12_C
1756 scripts/config.py unset MBEDTLS_PKCS5_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001757 # We keep MBEDTLS_PK_{,PARSE,WRITE}_C because PSA with RSA needs it.
1758 scripts/config.py unset MBEDTLS_XTEA_C
Gilles Peskine21503df2022-10-11 21:05:06 +02001759 make CFLAGS='-O1 -Werror' all test
1760 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1761}
1762
Gilles Peskineec541fe2020-01-31 14:24:14 +01001763component_build_crypto_baremetal () {
1764 msg "build: make, crypto only, baremetal config"
1765 scripts/config.py crypto_baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001766 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001767 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001768}
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001769support_build_crypto_baremetal () {
Daniel Axtens1a021af2020-08-31 14:22:58 +10001770 support_build_baremetal "$@"
1771}
1772
1773component_build_baremetal () {
1774 msg "build: make, baremetal config"
1775 scripts/config.py baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001776 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Daniel Axtens1a021af2020-08-31 14:22:58 +10001777}
1778support_build_baremetal () {
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001779 # Older Glibc versions include time.h from other headers such as stdlib.h,
1780 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
1781 # problem, Ubuntu 18.04 is ok.
1782 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
1783}
Gilles Peskineec541fe2020-01-31 14:24:14 +01001784
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001785# depends.py family of tests
Andrzej Kurek85d69302022-10-05 09:14:07 -04001786component_test_depends_py_cipher_id () {
1787 msg "test/build: depends.py cipher_id (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001788 tests/scripts/depends.py cipher_id --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001789}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001790
Andrzej Kurek85d69302022-10-05 09:14:07 -04001791component_test_depends_py_cipher_chaining () {
1792 msg "test/build: depends.py cipher_chaining (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001793 tests/scripts/depends.py cipher_chaining --unset-use-psa
John Durkopc14be902020-08-20 06:16:41 -07001794}
1795
Andrzej Kurek85d69302022-10-05 09:14:07 -04001796component_test_depends_py_cipher_padding () {
1797 msg "test/build: depends.py cipher_padding (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001798 tests/scripts/depends.py cipher_padding --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001799}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001800
Andrzej Kurek85d69302022-10-05 09:14:07 -04001801component_test_depends_py_curves () {
1802 msg "test/build: depends.py curves (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001803 tests/scripts/depends.py curves --unset-use-psa
John Durkop2ec2eaa2020-08-24 18:29:15 -07001804}
1805
Andrzej Kurek85d69302022-10-05 09:14:07 -04001806component_test_depends_py_hashes () {
1807 msg "test/build: depends.py hashes (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001808 tests/scripts/depends.py hashes --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001809}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001810
Andrzej Kurek85d69302022-10-05 09:14:07 -04001811component_test_depends_py_kex () {
1812 msg "test/build: depends.py kex (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001813 tests/scripts/depends.py kex --unset-use-psa
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001814}
1815
Andrzej Kurek85d69302022-10-05 09:14:07 -04001816component_test_depends_py_pkalgs () {
1817 msg "test/build: depends.py pkalgs (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001818 tests/scripts/depends.py pkalgs --unset-use-psa
1819}
1820
1821# PSA equivalents of the depends.py tests
1822component_test_depends_py_cipher_id_psa () {
1823 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1824 tests/scripts/depends.py cipher_id
1825}
1826
1827component_test_depends_py_cipher_chaining_psa () {
1828 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1829 tests/scripts/depends.py cipher_chaining
1830}
1831
1832component_test_depends_py_cipher_padding_psa () {
1833 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1834 tests/scripts/depends.py cipher_padding
1835}
1836
1837component_test_depends_py_curves_psa () {
1838 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1839 tests/scripts/depends.py curves
1840}
1841
1842component_test_depends_py_hashes_psa () {
1843 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1844 tests/scripts/depends.py hashes
1845}
1846
1847component_test_depends_py_kex_psa () {
1848 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1849 tests/scripts/depends.py kex
1850}
1851
1852component_test_depends_py_pkalgs_psa () {
1853 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Andrzej Kurek85d69302022-10-05 09:14:07 -04001854 tests/scripts/depends.py pkalgs
Gilles Peskine8f073122018-11-27 15:58:47 +01001855}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001856
Dave Rodgman5fce4f62023-01-20 13:18:05 +00001857component_build_no_pk_rsa_alt_support () {
1858 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
1859
1860 scripts/config.py full
1861 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
1862 scripts/config.py set MBEDTLS_RSA_C
1863 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
1864
1865 # Only compile - this is primarily to test for compile issues
1866 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
1867}
1868
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001869component_test_no_use_psa_crypto_full_cmake_asan() {
1870 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02001871 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001872 scripts/config.py full
1873 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
1874 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1875 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1876 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02001877 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001878 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01001879 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001880 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001881
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001882 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001883 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001884
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001885 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001886 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001887
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001888 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001889 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001890
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001891 msg "test: compat.sh RC4, 3DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
1892 tests/compat.sh -e '^$' -f 'NULL\|3DES\|DES-CBC3\|RC4\|ARCFOUR'
1893
1894 msg "test: compat.sh single-DES (full minus MBEDTLS_USE_PSA_CRYPTO)"
1895 env OPENSSL="$OPENSSL_LEGACY" tests/compat.sh -e '3DES\|DES-CBC3' -f 'DES'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001896
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001897 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001898 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001899}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001900
Ronald Crond2c53e62021-09-13 09:38:05 +02001901component_test_psa_crypto_config_accel_ecdsa () {
1902 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1903
1904 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1905 # partial support for cipher operations in the driver test library.
1906 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1907 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Gilles Peskine62de7672022-04-21 11:05:16 +02001908 # Disable obsolete hashes (alternatively we could enable support for them
1909 # in the driver test library).
1910 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1911 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
Ronald Crond2c53e62021-09-13 09:38:05 +02001912
1913 # SHA384 needed for some ECDSA signature tests.
1914 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
1915
1916 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
1917 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1918 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1919
1920 # Restore test driver base configuration
1921 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
1922
1923 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1924 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1925 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1926 scripts/config.py unset MBEDTLS_ECDSA_C
1927 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1928 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1929
1930 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
1931 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"
1932
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01001933 not grep mbedtls_ecdsa_ library/ecdsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02001934
1935 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1936 make test
1937}
1938
1939component_test_psa_crypto_config_accel_rsa_signature () {
1940 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
1941
1942 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1943 # partial support for cipher operations in the driver test library.
1944 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1945 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1946
1947 # It seems it is not possible to remove only the support for RSA signature
1948 # in the library. Thus we have to remove all RSA support (signature and
1949 # encryption/decryption). AS there is no driver support for asymmetric
1950 # encryption/decryption so far remove RSA encryption/decryption from the
1951 # application algorithm list.
1952 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1953 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1954
1955 # Make sure both the library and the test library support the SHA hash
1956 # algorithms and only those ones (SHA256 is included by default). That way:
1957 # - the test library can compute the RSA signatures even in the case of a
1958 # composite RSA signature algorithm based on a SHA hash (no other hash
1959 # used in the unit tests).
1960 # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
1961 # fulfilled as the hash SHA algorithm is supported by the library, and
1962 # thus the tests are run, not skipped.
1963 # - when testing a signature key with an algorithm wildcard built from
1964 # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
1965 # algorithm based on the hashes supported by the library is also
1966 # supported by the test library.
1967 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1968 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1969 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1970 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160_C
1971
1972 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA1_C
1973 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
1974 # We need PEM parsing in the test library as well to support the import
1975 # of PEM encoded RSA keys.
1976 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_PEM_PARSE_C
1977 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_BASE64_C
1978
1979 loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
1980 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1981 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1982
1983 # Restore test driver base configuration
1984 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA1_C
1985 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
1986 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_PEM_PARSE_C
1987 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_BASE64_C
1988
1989
1990 # Mbed TLS library build
1991 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1992 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1993
1994 # Remove RSA support and its dependencies
1995 scripts/config.py unset MBEDTLS_PKCS1_V15
1996 scripts/config.py unset MBEDTLS_PKCS1_V21
1997 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1998 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1999 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2000 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2001 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2002 scripts/config.py unset MBEDTLS_RSA_C
2003 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2004
2005 scripts/config.py unset MBEDTLS_MD2_C
2006 scripts/config.py unset MBEDTLS_MD4_C
2007 scripts/config.py unset MBEDTLS_MD5_C
2008 scripts/config.py unset MBEDTLS_RIPEMD160_C
2009 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
2010 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
2011 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
2012
2013 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2014 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2015
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002016 not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
2017 not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02002018
2019 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
2020 make test
2021}
2022
Ronald Cronf7e483c2021-05-08 14:32:59 +02002023component_test_psa_crypto_config_accel_hash () {
2024 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2025
2026 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
2027 # partial support for cipher operations in the driver test library.
2028 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2029 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
2030
2031 loc_accel_list="ALG_MD4 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
2032 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2033 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2034
2035 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2036 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2037 scripts/config.py unset MBEDTLS_MD2_C
2038 scripts/config.py unset MBEDTLS_MD4_C
2039 scripts/config.py unset MBEDTLS_MD5_C
2040 scripts/config.py unset MBEDTLS_RIPEMD160_C
2041 scripts/config.py unset MBEDTLS_SHA1_C
2042 # Don't unset MBEDTLS_SHA256_C as it is needed by PSA crypto core.
2043 scripts/config.py unset MBEDTLS_SHA512_C
2044 # Unset MBEDTLS_SSL_PROTO_SSL3, MBEDTLS_SSL_PROTO_TLS1 and MBEDTLS_SSL_PROTO_TLS1_1 as they depend on MBEDTLS_SHA1_C
2045 scripts/config.py unset MBEDTLS_SSL_PROTO_SSL3
2046 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
2047 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
2048 # Unset MBEDTLS_SSL_CBC_RECORD_SPLITTING as it depends on MBEDTLS_SSL_PROTO_TLS1 in the default configuration.
2049 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
2050 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2051 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2052
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002053 not grep mbedtls_sha512_init library/sha512.o
2054 not grep mbedtls_sha1_init library/sha1.o
Ronald Cronf7e483c2021-05-08 14:32:59 +02002055
2056 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2057 make test
2058}
2059
Ronald Cron09623702021-10-18 11:26:01 +02002060component_test_psa_crypto_config_accel_cipher () {
2061 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
2062
Gilles Peskine186331872022-04-12 15:58:03 +02002063 # This test case focuses on cipher+AEAD. We don't yet support all
2064 # combinations of configurations, so deactivate block-cipher-based MACs.
2065 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CMAC
2066
Ronald Cron09623702021-10-18 11:26:01 +02002067 loc_accel_list="ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB ALG_OFB ALG_XTS KEY_TYPE_DES"
2068 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2069 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2070
2071 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2072 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2073
2074 # There is no intended accelerator support for ALG STREAM_CIPHER and
2075 # ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
2076 # inclusion of the Mbed TLS cipher operations. As we want to test here with
2077 # cipher operations solely supported by accelerators, disabled those
2078 # PSA configuration options.
2079 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2080 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Ronald Cron09623702021-10-18 11:26:01 +02002081
2082 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2083 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2084 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2085 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2086 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2087 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2088 scripts/config.py unset MBEDTLS_DES_C
2089
2090 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2091 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2092
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002093 not grep mbedtls_des* library/des.o
Ronald Cron09623702021-10-18 11:26:01 +02002094
2095 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2096 make test
2097}
2098
Przemek Stekiel8b56f232022-10-02 20:58:39 +02002099component_test_psa_crypto_config_accel_aead () {
2100 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2101
2102 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
2103 # partial support for cipher operations in the driver test library.
2104 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2105 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
2106
2107 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2108 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2109 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2110
2111 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2112 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2113
2114 scripts/config.py unset MBEDTLS_GCM_C
2115 scripts/config.py unset MBEDTLS_CCM_C
2116 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2117 # Features that depend on AEAD
2118 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
2119 scripts/config.py unset MBEDTLS_SSL_TICKET_C
2120
2121 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2122 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"
2123
2124 # There's a risk of something getting re-enabled via config_psa.h
2125 # make sure it did not happen.
2126 not grep mbedtls_ccm library/ccm.o
2127 not grep mbedtls_gcm library/gcm.o
2128 not grep mbedtls_chachapoly library/chachapoly.o
2129
2130 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2131 make test
2132}
2133
John Durkop4377bf72020-10-23 01:26:57 -07002134component_test_psa_crypto_config_no_driver() {
John Durkop4377bf72020-10-23 01:26:57 -07002135 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
2136 scripts/config.py full
2137 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2138 scripts/config.py unset MBEDTLS_PSA_CRYPTO_DRIVERS
2139 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkope7012c72020-10-26 09:55:01 -07002140 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop4377bf72020-10-23 01:26:57 -07002141
2142 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
John Durkopd8959392020-09-20 23:09:17 -07002143 make test
2144}
2145
Gilles Peskined4c85af2023-07-20 22:19:45 +02002146component_test_aead_chachapoly_disabled() {
2147 msg "build: full minus CHACHAPOLY"
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002148 scripts/config.py full
2149 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Gilles Peskined4c85af2023-07-20 22:19:45 +02002150 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002151 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
2152
Gilles Peskined4c85af2023-07-20 22:19:45 +02002153 msg "test: full minus CHACHAPOLY"
2154 make test
2155}
2156
2157component_test_aead_only_ccm() {
2158 msg "build: full minus CHACHAPOLY and GCM"
2159 scripts/config.py full
2160 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2161 scripts/config.py unset MBEDTLS_GCM_C
2162 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2163 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2164 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
2165
2166 msg "test: full minus CHACHAPOLY and GCM"
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002167 make test
2168}
2169
John Durkopd0321952020-10-29 21:37:36 -07002170# 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 -08002171component_build_psa_accel_alg_ecdh() {
Gilles Peskine168be012023-07-19 19:36:55 +02002172 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
John Durkopd0321952020-10-29 21:37:36 -07002173 scripts/config.py full
2174 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2175 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2176 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2177 scripts/config.py unset MBEDTLS_ECDH_C
2178 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2179 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2180 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2181 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2182 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2183 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2184 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2185}
2186
John Durkopf4c4cb02020-10-28 20:09:55 -07002187# 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 -08002188component_build_psa_accel_key_type_ecc_key_pair() {
Gilles Peskine168be012023-07-19 19:36:55 +02002189 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR"
John Durkopf4c4cb02020-10-28 20:09:55 -07002190 scripts/config.py full
2191 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2192 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2193 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002194 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 -08002195 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 -07002196 # 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 -08002197 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 -07002198}
2199
2200# 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 -08002201component_build_psa_accel_key_type_ecc_public_key() {
Gilles Peskine168be012023-07-19 19:36:55 +02002202 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
John Durkopf4c4cb02020-10-28 20:09:55 -07002203 scripts/config.py full
2204 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2205 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2206 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002207 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
2208 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
John Durkopf4c4cb02020-10-28 20:09:55 -07002209 # 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 -08002210 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 -07002211}
2212
John Durkopd0321952020-10-29 21:37:36 -07002213# 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 -08002214component_build_psa_accel_alg_hmac() {
Gilles Peskine168be012023-07-19 19:36:55 +02002215 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
John Durkopd0321952020-10-29 21:37:36 -07002216 scripts/config.py full
2217 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2218 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2219 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2220 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2221 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2222}
2223
2224# 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 -08002225component_build_psa_accel_alg_hkdf() {
Gilles Peskine168be012023-07-19 19:36:55 +02002226 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
John Durkopd0321952020-10-29 21:37:36 -07002227 scripts/config.py full
2228 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2229 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2230 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2231 scripts/config.py unset MBEDTLS_HKDF_C
John Durkopbd069d32020-10-31 22:14:03 -07002232 # Make sure to unset TLS1_3_EXPERIMENTAL since it requires HKDF_C and will not build properly without it.
2233 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
John Durkopd0321952020-10-29 21:37:36 -07002234 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2235 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2236}
2237
John Durkop1b7ee052020-11-27 08:51:22 -08002238# This should be renamed to test and updated once the accelerator MD2 code is in place and ready to test.
2239component_build_psa_accel_alg_md2() {
Gilles Peskine168be012023-07-19 19:36:55 +02002240 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD2 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002241 scripts/config.py full
2242 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2243 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2244 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2245 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2246 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2247 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2248 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2249 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2250 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2251 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2252 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2253 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2254 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD2 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2255}
2256
2257# This should be renamed to test and updated once the accelerator MD4 code is in place and ready to test.
2258component_build_psa_accel_alg_md4() {
Gilles Peskine168be012023-07-19 19:36:55 +02002259 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD4 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002260 scripts/config.py full
2261 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2262 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2263 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2264 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2265 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2266 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2267 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2268 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2269 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2270 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2271 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2272 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2273 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD4 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2274}
2275
2276# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
2277component_build_psa_accel_alg_md5() {
Gilles Peskine168be012023-07-19 19:36:55 +02002278 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002279 scripts/config.py full
2280 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2281 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2282 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2283 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2284 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2285 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2286 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2287 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2288 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2289 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2290 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2291 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2292 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2293}
2294
2295# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
2296component_build_psa_accel_alg_ripemd160() {
Gilles Peskine168be012023-07-19 19:36:55 +02002297 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002298 scripts/config.py full
2299 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2300 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2301 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2302 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2303 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2304 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2305 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2306 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2307 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2308 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2309 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2310 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2311 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2312}
2313
2314# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
2315component_build_psa_accel_alg_sha1() {
Gilles Peskine168be012023-07-19 19:36:55 +02002316 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002317 scripts/config.py full
2318 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2319 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2320 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2321 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2322 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2323 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2324 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2325 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2326 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2327 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2328 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2329 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2330 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2331}
2332
2333# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
2334component_build_psa_accel_alg_sha224() {
Gilles Peskine168be012023-07-19 19:36:55 +02002335 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002336 scripts/config.py full
2337 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2338 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2339 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2340 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2341 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2342 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2343 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2344 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2345 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2346 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2347 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2348 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2349}
2350
2351# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
2352component_build_psa_accel_alg_sha256() {
Gilles Peskine168be012023-07-19 19:36:55 +02002353 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002354 scripts/config.py full
2355 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2356 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2357 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2358 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2359 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2360 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2361 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2362 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2363 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2364 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2365 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2366 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2367 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2368}
2369
2370# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
2371component_build_psa_accel_alg_sha384() {
Gilles Peskine168be012023-07-19 19:36:55 +02002372 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002373 scripts/config.py full
2374 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2375 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2376 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2377 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2378 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2379 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2380 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2381 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2382 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2383 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2384 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2385 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2386}
2387
2388# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
2389component_build_psa_accel_alg_sha512() {
Gilles Peskine168be012023-07-19 19:36:55 +02002390 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002391 scripts/config.py full
2392 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2393 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2394 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2395 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2396 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2397 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2398 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2399 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2400 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2401 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2402 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2403 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2404 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2405}
2406
John Durkopd0321952020-10-29 21:37:36 -07002407# 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 -08002408component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
Gilles Peskine168be012023-07-19 19:36:55 +02002409 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 -07002410 scripts/config.py full
2411 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2412 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2413 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkopbd069d32020-10-31 22:14:03 -07002414 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002415 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2416 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2417 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07002418 # 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 -07002419 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2420}
2421
2422# 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 -08002423component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
Gilles Peskine168be012023-07-19 19:36:55 +02002424 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 -07002425 scripts/config.py full
2426 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2427 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2428 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2429 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002430 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2431 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2432 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002433 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2434 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2435}
2436
2437# 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 -08002438component_build_psa_accel_alg_rsa_oaep() {
Gilles Peskine168be012023-07-19 19:36:55 +02002439 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 -07002440 scripts/config.py full
2441 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2442 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2443 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2444 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_OAEP 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002445 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2446 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2447 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002448 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2449 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2450}
2451
2452# 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 -08002453component_build_psa_accel_alg_rsa_pss() {
Gilles Peskine168be012023-07-19 19:36:55 +02002454 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 -07002455 scripts/config.py full
2456 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2457 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2458 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2459 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002460 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2461 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2462 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07002463 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2464 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2465}
2466
2467# 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 -08002468component_build_psa_accel_key_type_rsa_key_pair() {
Gilles Peskine168be012023-07-19 19:36:55 +02002469 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 -07002470 scripts/config.py full
2471 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2472 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2473 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2474 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2475 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
2476 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2477 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"
2478}
2479
2480# 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 -08002481component_build_psa_accel_key_type_rsa_public_key() {
Gilles Peskine168be012023-07-19 19:36:55 +02002482 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 -07002483 scripts/config.py full
2484 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2485 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2486 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2487 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2488 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
2489 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2490 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 -07002491}
2492
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002493component_test_check_params_functionality () {
2494 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002495 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002496 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002497 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Ronald Crona1236142020-07-01 16:01:21 +02002498 make CC=gcc CFLAGS='-Werror -O1' all test
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002499}
2500
Gilles Peskineb28636b2019-01-02 19:06:24 +01002501component_test_check_params_without_platform () {
2502 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002503 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002504 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002505 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
2506 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
2507 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
2508 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
Gilles Peskine32e889d2020-04-12 23:43:28 +02002509 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002510 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
2511 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskine9c764bf2022-09-18 14:05:23 +02002512 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002513 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
2514 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +01002515 make CC=gcc CFLAGS='-Werror -O1' all test
2516}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002517
Gilles Peskineb28636b2019-01-02 19:06:24 +01002518component_test_check_params_silent () {
2519 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002520 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002521 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01002522 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
2523 make CC=gcc CFLAGS='-Werror -O1' all test
2524}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002525
Dave Rodgman173227d2023-06-29 09:29:00 +01002526component_build_aes_variations() { # ~45s
2527 msg "build: aes.o for all combinations of relevant config options"
Dave Rodgmanbf998282023-06-29 12:10:45 +01002528
Dave Rodgman173227d2023-06-29 09:29:00 +01002529 for a in set unset; do
2530 for b in set unset; do
2531 for c in set unset; do
2532 for d in set unset; do
2533 for e in set unset; do
2534 for f in set unset; do
2535 for g in set unset; do
Dave Rodgmanbf998282023-06-29 12:10:45 +01002536 echo ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
2537 echo ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
2538 echo ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
2539 echo ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
2540 echo ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
2541 echo ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
2542 echo ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman173227d2023-06-29 09:29:00 +01002543
Dave Rodgmanbf998282023-06-29 12:10:45 +01002544 ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
2545 ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
2546 ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
2547 ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
2548 ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
2549 ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
2550 ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman173227d2023-06-29 09:29:00 +01002551
Dave Rodgmanbf998282023-06-29 12:10:45 +01002552 rm -f library/aes.o
2553 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 +01002554 done
2555 done
2556 done
2557 done
2558 done
2559 done
2560 done
2561}
2562
Gilles Peskine8f073122018-11-27 15:58:47 +01002563component_test_no_platform () {
2564 # Full configuration build, without platform support, file IO and net sockets.
2565 # This should catch missing mbedtls_printf definitions, and by disabling file
2566 # IO, it should catch missing '#include <stdio.h>'
2567 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Paul Elliott68050372023-11-03 19:24:56 +00002568 scripts/config.py full_no_platform
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002569 scripts/config.py unset MBEDTLS_PLATFORM_C
2570 scripts/config.py unset MBEDTLS_NET_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002571 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002572 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002573 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
2574 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Paul Elliott68050372023-11-03 19:24:56 +00002575 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +01002576 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
2577 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002578 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
2579 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01002580}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00002581
Gilles Peskine8f073122018-11-27 15:58:47 +01002582component_build_no_std_function () {
2583 # catch compile bugs in _uninit functions
2584 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002585 scripts/config.py full
2586 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
2587 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002588 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine31fdda12021-10-08 11:45:47 +02002589 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskine25319702021-10-07 19:34:57 +02002590 make
Gilles Peskine8f073122018-11-27 15:58:47 +01002591}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01002592
Gilles Peskine8f073122018-11-27 15:58:47 +01002593component_build_no_ssl_srv () {
2594 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002595 scripts/config.py full
2596 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002597 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002598}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002599
Gilles Peskine8f073122018-11-27 15:58:47 +01002600component_build_no_ssl_cli () {
2601 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002602 scripts/config.py full
2603 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002604 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002605}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002606
Gilles Peskine8f073122018-11-27 15:58:47 +01002607component_build_no_sockets () {
2608 # Note, C99 compliance can also be tested with the sockets support disabled,
2609 # as that requires a POSIX platform (which isn't the same as C99).
2610 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002611 scripts/config.py full
2612 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
2613 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002614 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01002615}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02002616
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002617component_test_memory_buffer_allocator_backtrace () {
2618 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002619 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2620 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2621 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
2622 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Gilles Peskineff30bd02021-10-19 21:33:32 +02002623 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002624 make
2625
2626 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
2627 make test
2628}
2629
2630component_test_memory_buffer_allocator () {
2631 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002632 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2633 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Gilles Peskineff30bd02021-10-19 21:33:32 +02002634 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002635 make
2636
2637 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2638 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002639
2640 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2641 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002642 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002643}
2644
Gilles Peskine8f073122018-11-27 15:58:47 +01002645component_test_no_max_fragment_length () {
2646 # Run max fragment length tests with MFL disabled
2647 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002648 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01002649 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2650 make
Hanno Becker5175ac62017-09-18 15:36:25 +01002651
Gilles Peskine8f073122018-11-27 15:58:47 +01002652 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002653 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01002654}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002655
Hanno Becker545ced42019-02-19 11:10:48 +00002656component_test_asan_remove_peer_certificate () {
2657 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002658 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00002659 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2660 make
2661
2662 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2663 make test
2664
2665 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002666 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002667
2668 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002669 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002670
2671 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002672 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002673}
2674
Gilles Peskine8f073122018-11-27 15:58:47 +01002675component_test_no_max_fragment_length_small_ssl_out_content_len () {
2676 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002677 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2678 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
2679 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01002680 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2681 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10002682
Gilles Peskine8f073122018-11-27 15:58:47 +01002683 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002684 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002685
2686 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002687 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002688}
Angus Grattonc4dd0732018-04-11 16:28:39 +10002689
Darryl Greenaad82f92019-12-02 10:53:11 +00002690component_test_variable_ssl_in_out_buffer_len () {
2691 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
2692 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2693 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2694 make
2695
2696 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2697 make test
2698
2699 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002700 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002701
2702 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002703 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002704}
2705
2706component_test_variable_ssl_in_out_buffer_len_CID () {
2707 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
2708 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2709 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
2710
2711 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2712 make
2713
2714 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
2715 make test
2716
2717 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002718 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002719
2720 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002721 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002722}
2723
2724component_test_variable_ssl_in_out_buffer_len_record_splitting () {
2725 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled (ASan build)"
2726 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2727 scripts/config.py set MBEDTLS_SSL_CBC_RECORD_SPLITTING
2728
2729 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2730 make
2731
2732 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING"
2733 make test
2734
2735 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002736 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002737
2738 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002739 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002740}
2741
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002742component_test_ssl_alloc_buffer_and_mfl () {
2743 msg "build: default config with memory buffer allocator and MFL extension"
2744 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2745 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2746 scripts/config.py set MBEDTLS_MEMORY_DEBUG
2747 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2748 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
Gilles Peskineff30bd02021-10-19 21:33:32 +02002749 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002750 make
2751
2752 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
2753 make test
2754
2755 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 +02002756 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002757}
2758
Gilles Peskine636c26a2020-03-04 20:46:15 +01002759component_test_when_no_ciphersuites_have_mac () {
2760 msg "build: when no ciphersuites have MAC"
2761 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
2762 scripts/config.py unset MBEDTLS_ARC4_C
2763 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2764 make
2765
2766 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
2767 make test
2768
2769 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002770 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01002771}
2772
Gilles Peskine8f073122018-11-27 15:58:47 +01002773component_test_null_entropy () {
2774 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002775 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
2776 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
2777 scripts/config.py set MBEDTLS_ENTROPY_C
2778 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002779 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002780 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
2781 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00002782 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01002783 make
Janos Follath06c54002016-06-09 13:57:40 +01002784
Gilles Peskine8f073122018-11-27 15:58:47 +01002785 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
2786 make test
2787}
Janos Follath06c54002016-06-09 13:57:40 +01002788
Raoul Strackxa4e86142020-06-15 17:03:13 +02002789component_test_no_date_time () {
2790 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
2791 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
Gilles Peskine31fdda12021-10-08 11:45:47 +02002792 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Raoul Strackxa4e86142020-06-15 17:03:13 +02002793 make
2794
2795 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
2796 make test
2797}
2798
Andrzej Kurekc890b222023-01-17 04:03:19 -05002799component_test_alt_timing() {
2800 msg "build: alternate timing implementation"
2801 scripts/config.py set MBEDTLS_TIMING_ALT
2802 make lib TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
2803
2804 msg "test: MBEDTLS_TIMING_ALT - test suites"
2805 make test TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
Andrzej Kurek3a261a42023-01-26 04:33:59 -05002806
2807 msg "selftest - MBEDTLS-TIMING_ALT"
2808 make programs TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../../tests/src/external_timing -I../tests/src/external_timing"
2809 programs/test/selftest
Andrzej Kurekc890b222023-01-17 04:03:19 -05002810}
2811
Gilles Peskine8f073122018-11-27 15:58:47 +01002812component_test_platform_calloc_macro () {
2813 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002814 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2815 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
2816 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01002817 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2818 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01002819
Gilles Peskine8f073122018-11-27 15:58:47 +01002820 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
2821 make test
2822}
Hanno Beckere5fecec2018-10-11 11:02:52 +01002823
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002824component_test_malloc_0_null () {
2825 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002826 scripts/config.py full
Gilles Peskine2e70f1c2023-07-20 19:00:15 +02002827 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 +02002828
2829 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
2830 make test
2831
2832 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
2833 # Just the calloc selftest. "make test" ran the others as part of the
2834 # test suites.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002835 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01002836
2837 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
2838 # Run a subset of the tests. The choice is a balance between coverage
2839 # and time (including time indirectly wasted due to flaky tests).
2840 # The current choice is to skip tests whose description includes
2841 # "proxy", which is an approximation of skipping tests that use the
2842 # UDP proxy, which tend to be slower and flakier.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002843 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002844}
2845
Gilles Peskine8f073122018-11-27 15:58:47 +01002846component_test_aes_fewer_tables () {
2847 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002848 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002849 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002850
Gilles Peskine8f073122018-11-27 15:58:47 +01002851 msg "test: AES_FEWER_TABLES"
2852 make test
2853}
Hanno Becker83ebf782017-07-07 12:29:15 +01002854
Gilles Peskine8f073122018-11-27 15:58:47 +01002855component_test_aes_rom_tables () {
2856 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002857 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002858 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002859
Gilles Peskine8f073122018-11-27 15:58:47 +01002860 msg "test: AES_ROM_TABLES"
2861 make test
2862}
Hanno Becker83ebf782017-07-07 12:29:15 +01002863
Gilles Peskine8f073122018-11-27 15:58:47 +01002864component_test_aes_fewer_tables_and_rom_tables () {
2865 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002866 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2867 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002868 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002869
Gilles Peskine8f073122018-11-27 15:58:47 +01002870 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2871 make test
2872}
2873
Gilles Peskine592f5912019-10-07 18:49:32 +02002874component_test_ctr_drbg_aes_256_sha_256 () {
2875 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002876 scripts/config.py full
2877 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2878 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002879 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2880 make
2881
2882 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2883 make test
2884}
2885
2886component_test_ctr_drbg_aes_128_sha_512 () {
2887 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002888 scripts/config.py full
2889 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2890 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02002891 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2892 make
2893
2894 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2895 make test
2896}
2897
2898component_test_ctr_drbg_aes_128_sha_256 () {
2899 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002900 scripts/config.py full
2901 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2902 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2903 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002904 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2905 make
2906
2907 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2908 make test
2909}
2910
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002911component_test_se_default () {
2912 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002913 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02002914 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002915
2916 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2917 make test
2918}
2919
Steven Cooremand57203d2020-07-16 20:28:59 +02002920component_test_psa_crypto_drivers () {
Gilles Peskine8d77ec22023-07-26 18:45:20 +02002921 msg "build: full + test drivers dispatching to builtins"
Steven Cooreman753f9732021-03-15 11:38:44 +01002922 scripts/config.py full
Steven Cooremand57203d2020-07-16 20:28:59 +02002923 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
Gilles Peskinefe0acc62021-09-20 19:20:04 +02002924 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
2925 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002926 loc_cflags="${loc_cflags} -I../tests/include -O2"
2927
2928 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002929
Gilles Peskine8d77ec22023-07-26 18:45:20 +02002930 msg "test: full + test drivers dispatching to builtins"
Steven Cooremand57203d2020-07-16 20:28:59 +02002931 make test
2932}
2933
Gilles Peskine8f073122018-11-27 15:58:47 +01002934component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002935 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002936 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02002937 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine27482f12021-11-04 12:52:14 +01002938 programs/test/dlopen_demo.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002939}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02002940
Gilles Peskinecf740502019-07-03 20:43:05 +02002941component_test_cmake_shared () {
2942 msg "build/test: cmake shared" # ~ 2min
2943 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
2944 make
Gilles Peskine56c01612019-07-03 20:43:32 +02002945 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02002946 make test
Gilles Peskine27482f12021-11-04 12:52:14 +01002947 programs/test/dlopen_demo.sh
Gilles Peskinecf740502019-07-03 20:43:05 +02002948}
2949
Gilles Peskineec10bf12019-09-20 19:56:06 +02002950test_build_opt () {
2951 info=$1 cc=$2; shift 2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002952 $cc --version
Gilles Peskineec10bf12019-09-20 19:56:06 +02002953 for opt in "$@"; do
2954 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskinee094a182020-04-14 20:08:41 +02002955 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02002956 # We're confident enough in compilers to not run _all_ the tests,
2957 # but at least run the unit tests. In particular, runs with
2958 # optimizations use inline assembly whereas runs with -O0
2959 # skip inline assembly.
2960 make test # ~30s
2961 make clean
2962 done
2963}
2964
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002965# For FreeBSD we invoke the function by name so this condition is added
2966# to disable the existing test_clang_opt function for linux.
2967if [[ $(uname) != "Linux" ]]; then
2968 component_test_clang_opt () {
2969 scripts/config.py full
2970 test_build_opt 'full config' clang -O0 -Os -O2
2971 }
2972fi
2973
2974component_test_clang_latest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002975 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002976 test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002977}
2978support_test_clang_latest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002979 type "$CLANG_LATEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02002980}
2981
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002982component_test_clang_earliest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002983 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002984 test_build_opt 'full config' "$CLANG_EARLIEST" -O0
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002985}
2986support_test_clang_earliest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002987 type "$CLANG_EARLIEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002988}
2989
2990component_test_gcc_latest_opt () {
2991 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002992 test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002993}
2994support_test_gcc_latest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002995 type "$GCC_LATEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002996}
2997
2998component_test_gcc_earliest_opt () {
2999 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003000 test_build_opt 'full config' "$GCC_EARLIEST" -O0
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003001}
3002support_test_gcc_earliest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003003 type "$GCC_EARLIEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02003004}
3005
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02003006component_build_mbedtls_config_file () {
3007 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
Gilles Peskine6af9dc92022-04-07 20:55:57 +02003008 scripts/config.py -w full_config.h full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02003009 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
3010 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02003011 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine036a9bb2022-04-07 21:06:41 +02003012 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3013 make clean
3014
3015 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
3016 # In the user config, disable one feature (for simplicity, pick a feature
3017 # that nothing else depends on).
3018 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3019 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
3020 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3021
3022 rm -f user_config.h full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003023}
3024
Gilles Peskine690a2ef2022-04-07 21:59:14 +02003025component_build_psa_config_file () {
3026 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
3027 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3028 cp "$CRYPTO_CONFIG_H" psa_test_config.h
3029 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
3030 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02003031 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine690a2ef2022-04-07 21:59:14 +02003032 programs/test/query_compile_time_config MBEDTLS_CMAC_C
3033 make clean
3034
3035 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
3036 # In the user config, disable one feature, which will reflect on the
3037 # mbedtls configuration so we can query it with query_compile_time_config.
3038 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
3039 scripts/config.py unset MBEDTLS_CMAC_C
3040 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
3041 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
3042
3043 rm -f psa_test_config.h psa_user_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003044}
3045
Gilles Peskine8f073122018-11-27 15:58:47 +01003046component_test_m32_o0 () {
Gilles Peskinea0c51fb2021-10-07 19:27:16 +02003047 # Build without optimization, so as to use portable C code (in a 32-bit
3048 # build) and not the i386-specific inline assembly.
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003049 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003050 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02003051 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01003052
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003053 msg "test: i386, make, gcc -O0 (ASan build)"
3054 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01003055}
Gilles Peskine878cf602019-01-06 20:50:38 +00003056support_test_m32_o0 () {
3057 case $(uname -m) in
Pengyu Lva89b3672022-10-21 10:50:26 +00003058 amd64|x86_64) true;;
Gilles Peskine878cf602019-01-06 20:50:38 +00003059 *) false;;
3060 esac
3061}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003062
Gilles Peskine6fa69862021-10-05 09:36:03 +02003063component_test_m32_o2 () {
3064 # Build with optimization, to use the i386 specific inline assembly
3065 # and go faster for tests.
3066 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003067 scripts/config.py full
Gilles Peskine6fa69862021-10-05 09:36:03 +02003068 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003069
Gilles Peskine6fa69862021-10-05 09:36:03 +02003070 msg "test: i386, make, gcc -O2 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003071 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003072
Gilles Peskine6fa69862021-10-05 09:36:03 +02003073 msg "test ssl-opt.sh, i386, make, gcc-O2"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003074 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003075}
Gilles Peskine3daa83e2021-10-07 19:25:29 +02003076support_test_m32_o2 () {
Gilles Peskine878cf602019-01-06 20:50:38 +00003077 support_test_m32_o0 "$@"
3078}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003079
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003080component_test_m32_everest () {
3081 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003082 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
3083 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02003084 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003085
3086 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
3087 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003088
3089 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003090 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01003091
3092 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
3093 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003094 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003095}
3096support_test_m32_everest () {
3097 support_test_m32_o0 "$@"
3098}
3099
Gilles Peskine8f073122018-11-27 15:58:47 +01003100component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003101 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003102 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02003103 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003104
3105 msg "test: 64-bit ILP32, make, gcc"
3106 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01003107}
Gilles Peskine878cf602019-01-06 20:50:38 +00003108support_test_mx32 () {
3109 case $(uname -m) in
3110 amd64|x86_64) true;;
3111 *) false;;
3112 esac
3113}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003114
Peter Kolbus60c6da22018-12-27 06:59:04 -06003115component_test_min_mpi_window_size () {
3116 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003117 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06003118 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3119 make
3120
3121 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
3122 make test
3123}
3124
Gilles Peskine8f073122018-11-27 15:58:47 +01003125component_test_have_int32 () {
3126 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003127 scripts/config.py unset MBEDTLS_HAVE_ASM
3128 scripts/config.py unset MBEDTLS_AESNI_C
3129 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01003130 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01003131
Gilles Peskine8f073122018-11-27 15:58:47 +01003132 msg "test: gcc, force 32-bit bignum limbs"
3133 make test
3134}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01003135
Gilles Peskine8f073122018-11-27 15:58:47 +01003136component_test_have_int64 () {
3137 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003138 scripts/config.py unset MBEDTLS_HAVE_ASM
3139 scripts/config.py unset MBEDTLS_AESNI_C
3140 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01003141 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01003142
Gilles Peskine8f073122018-11-27 15:58:47 +01003143 msg "test: gcc, force 64-bit bignum limbs"
3144 make test
3145}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003146
Gilles Peskine8f073122018-11-27 15:58:47 +01003147component_test_no_udbl_division () {
3148 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003149 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003150 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01003151 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003152
Gilles Peskine8f073122018-11-27 15:58:47 +01003153 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
3154 make test
3155}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003156
Gilles Peskine8f073122018-11-27 15:58:47 +01003157component_test_no_64bit_multiplication () {
3158 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003159 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003160 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01003161 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003162
Gilles Peskine8f073122018-11-27 15:58:47 +01003163 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
3164 make test
3165}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003166
Gilles Peskine3809f5f2020-11-09 15:40:05 +01003167component_test_no_strings () {
3168 msg "build: no strings" # ~10s
3169 scripts/config.py full
3170 # Disable options that activate a large amount of string constants.
3171 scripts/config.py unset MBEDTLS_DEBUG_C
3172 scripts/config.py unset MBEDTLS_ERROR_C
3173 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
3174 scripts/config.py unset MBEDTLS_VERSION_FEATURES
3175 make CFLAGS='-Werror -Os'
3176
3177 msg "test: no strings" # ~ 10s
3178 make test
3179}
3180
Gilles Peskine8f073122018-11-27 15:58:47 +01003181component_build_arm_none_eabi_gcc () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003182 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003183 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02003184 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 +02003185
Gilles Peskine60d99472021-09-01 20:00:33 +02003186 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003187 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003188}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003189
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003190component_build_arm_linux_gnueabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003191 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003192 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02003193 # Build for a target platform that's close to what Debian uses
3194 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
Dave Rodgman52af7692022-03-31 14:27:24 +01003195 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003196 # Build everything including programs, see for example
Dave Rodgman52af7692022-03-31 14:27:24 +01003197 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003198 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'
3199
Gilles Peskine60d99472021-09-01 20:00:33 +02003200 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003201 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size library/*.o
3202}
3203support_build_arm_linux_gnueabi_gcc_arm5vte () {
3204 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
3205}
3206
3207component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003208 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003209 scripts/config.py baremetal
3210 # This is an imperfect substitute for
3211 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnard9a260a62021-07-06 09:44:59 +02003212 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02003213 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 +02003214
Gilles Peskine60d99472021-09-01 20:00:33 +02003215 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003216 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02003217}
3218
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003219component_build_arm_none_eabi_gcc_m0plus () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003220 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
3221 scripts/config.py baremetal_size
Gilles Peskineaeedd742020-09-02 11:03:04 +02003222 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 +02003223
Gilles Peskine60d99472021-09-01 20:00:33 +02003224 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
Gilles Peskine18487f62020-04-30 23:11:54 +02003225 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003226}
3227
Gilles Peskine8f073122018-11-27 15:58:47 +01003228component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003229 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003230 scripts/config.py baremetal
3231 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003232 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 +01003233 echo "Checking that software 64-bit division is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003234 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003235}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003236
Gilles Peskine8f073122018-11-27 15:58:47 +01003237component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003238 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003239 scripts/config.py baremetal
3240 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003241 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 +01003242 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003243 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003244}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003245
Dave Rodgman43ea9ab2023-06-02 10:26:24 -04003246component_build_arm_clang_thumb () {
3247 # ~ 30s
3248
3249 scripts/config.py baremetal
3250
3251 msg "build: clang thumb 2, make"
3252 make clean
3253 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
3254
3255 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
3256 msg "build: clang thumb 1 -O0, make"
3257 make clean
3258 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
3259
3260 msg "build: clang thumb 1 -Os, make"
3261 make clean
3262 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
3263}
3264
Gilles Peskine8f073122018-11-27 15:58:47 +01003265component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02003266 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003267 scripts/config.py baremetal
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003268 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02003269
3270 msg "size: ARM Compiler 5"
3271 "$ARMC5_FROMELF" -z library/*.o
3272
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003273 make clean
Andres AG87bb5772016-09-27 15:05:15 +01003274
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003275 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
3276
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003277 # ARM Compiler 6 - Target ARMv7-A
3278 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003279
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003280 # ARM Compiler 6 - Target ARMv7-M
3281 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02003282
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003283 # ARM Compiler 6 - Target ARMv8-A - AArch32
3284 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003285
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003286 # ARM Compiler 6 - Target ARMv8-M
3287 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02003288
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003289 # ARM Compiler 6 - Target ARMv8-A - AArch64
3290 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003291
3292 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
3293 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
3294
3295 # ARM Compiler 6 - Target Cortex-M0
3296 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
Gilles Peskine8f073122018-11-27 15:58:47 +01003297}
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003298
Pengyu Lvd216c042023-03-03 18:23:35 +08003299support_build_armcc () {
3300 armc5_cc="$ARMC5_BIN_DIR/armcc"
3301 armc6_cc="$ARMC6_BIN_DIR/armclang"
3302 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
3303}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01003304
Manuel Pégourié-Gonnarddd8807f2020-02-26 09:56:27 +01003305component_build_ssl_hw_record_accel() {
3306 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
3307 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
3308 make CFLAGS='-Werror -O1'
3309}
3310
Hanno Beckera711f6e2020-05-04 12:03:51 +01003311component_test_tls13_experimental () {
3312 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3313 scripts/config.pl set MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
3314 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3315 make
3316 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3317 make test
3318}
3319
Gilles Peskine8f073122018-11-27 15:58:47 +01003320component_build_mingw () {
3321 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003322 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 +00003323
Gilles Peskine8f073122018-11-27 15:58:47 +01003324 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003325 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 +01003326 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02003327
Gilles Peskine8f073122018-11-27 15:58:47 +01003328 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003329 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
3330 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 +01003331 make WINDOWS_BUILD=1 clean
Pengyu Lvb2ca0322023-10-19 17:17:19 +08003332
3333 msg "build: Windows cross build - mingw64, make (Library only, AESNI intrinsics)" # ~ 30s
3334 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 +08003335 make WINDOWS_BUILD=1 clean
3336
3337 msg "build: Windows cross build - mingw64, make (Library only, default config without MBEDTLS_AESNI_C)" # ~ 30s
3338 ./scripts/config.py unset MBEDTLS_AESNI_C
3339 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib
3340 make WINDOWS_BUILD=1 clean
Pengyu Lvb2ca0322023-10-19 17:17:19 +08003341 }
Jaeden Amero117b8a42019-04-17 15:19:26 +01003342support_build_mingw() {
Pengyu Lva19ce122023-02-24 15:38:52 +08003343 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
3344 [0-5]*|"") false;;
Jaeden Amero117b8a42019-04-17 15:19:26 +01003345 *) true;;
3346 esac
3347}
Simon Butcher91aef332016-11-17 09:20:50 +00003348
Gilles Peskine8f073122018-11-27 15:58:47 +01003349component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003350 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003351 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003352 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
3353 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02003354
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003355 msg "test: main suites (MSan)" # ~ 10s
3356 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003357
Gilles Peskineee8af062023-11-02 19:58:03 +01003358 msg "test: metatests (MSan)"
3359 tests/scripts/run-metatests.sh any msan
3360
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02003361 msg "program demos (MSan)" # ~20s
3362 tests/scripts/run_demos.py
3363
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003364 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003365 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003366
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003367 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003368
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003369 if [ "$MEMORY" -gt 0 ]; then
3370 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003371 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003372 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003373}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003374
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01003375component_release_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003376 msg "build: Release (clang)"
Gilles Peskine619b73d2022-11-29 16:45:30 +01003377 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003378 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3379 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003380
Gilles Peskine619b73d2022-11-29 16:45:30 +01003381 msg "test: main suites, Valgrind (default config)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003382 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003383
Gilles Peskine636c26a2020-03-04 20:46:15 +01003384 # Optional parts (slow; currently broken on OS X because programs don't
3385 # seem to receive signals under valgrind on OS X).
Gilles Peskine619b73d2022-11-29 16:45:30 +01003386 # These optional parts don't run on the CI.
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003387 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003388 msg "test: ssl-opt.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003389 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003390 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003391
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003392 if [ "$MEMORY" -gt 1 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003393 msg "test: compat.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003394 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003395 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003396
3397 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003398 msg "test: context-info.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003399 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003400 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003401}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003402
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01003403component_release_test_valgrind_psa () {
Gilles Peskine619b73d2022-11-29 16:45:30 +01003404 msg "build: Release, full (clang)"
3405 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
3406 scripts/config.py full
3407 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3408 make
3409
3410 msg "test: main suites, Valgrind (full config)"
3411 make memcheck
3412}
3413
Paul Elliott2ab9a7a2021-11-25 17:29:40 +00003414support_test_cmake_out_of_source () {
3415 distrib_id=""
3416 distrib_ver=""
3417 distrib_ver_minor=""
3418 distrib_ver_major=""
3419
3420 # Attempt to parse lsb-release to find out distribution and version. If not
3421 # found this should fail safe (test is supported).
3422 if [[ -f /etc/lsb-release ]]; then
3423
3424 while read -r lsb_line; do
3425 case "$lsb_line" in
3426 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
3427 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
3428 esac
3429 done < /etc/lsb-release
3430
3431 distrib_ver_major="${distrib_ver%%.*}"
3432 distrib_ver="${distrib_ver#*.}"
3433 distrib_ver_minor="${distrib_ver%%.*}"
3434 fi
3435
3436 # Running the out of source CMake test on Ubuntu 16.04 using more than one
3437 # processor (as the CI does) can create a race condition whereby the build
3438 # fails to see a generated file, despite that file actually having been
3439 # generated. This problem appears to go away with 18.04 or newer, so make
3440 # the out of source tests unsupported on Ubuntu 16.04.
3441 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
3442}
3443
Gilles Peskine8f073122018-11-27 15:58:47 +01003444component_test_cmake_out_of_source () {
3445 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01003446 MBEDTLS_ROOT_DIR="$PWD"
3447 mkdir "$OUT_OF_SOURCE_DIR"
3448 cd "$OUT_OF_SOURCE_DIR"
Gilles Peskine25319702021-10-07 19:34:57 +02003449 cmake -D CMAKE_BUILD_TYPE:String=Check "$MBEDTLS_ROOT_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003450 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003451
Gilles Peskine8f073122018-11-27 15:58:47 +01003452 msg "test: cmake 'out-of-source' build"
3453 make test
3454 # Test an SSL option that requires an auxiliary script in test/scripts/.
3455 # Also ensure that there are no error messages such as
3456 # "No such file or directory", which would indicate that some required
3457 # file is missing (ssl-opt.sh tolerates the absence of some files so
3458 # may exit with status 0 but emit errors).
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003459 ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' >ssl-opt.out 2>ssl-opt.err
3460 grep PASS ssl-opt.out
Gilles Peskine0a7984f2020-03-28 18:56:09 +01003461 cat ssl-opt.err >&2
3462 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003463 [ ! -s ssl-opt.err ]
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003464 rm ssl-opt.out ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01003465 cd "$MBEDTLS_ROOT_DIR"
3466 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003467}
Andres AGdc192212016-08-31 17:33:13 +01003468
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003469component_test_cmake_as_subdirectory () {
3470 msg "build: cmake 'as-subdirectory' build"
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003471 cd programs/test/cmake_subproject
3472 cmake .
3473 make
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003474 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003475}
Gilles Peskineca9cfca2022-02-04 00:21:12 +01003476support_test_cmake_as_subdirectory () {
3477 support_test_cmake_out_of_source
3478}
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003479
David Horstmann175afbd2023-01-12 14:17:01 +00003480component_build_cmake_custom_config_file () {
David Horstmann67622312023-01-31 10:34:44 +00003481 # Make a copy of config file to use for the in-tree test
3482 cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h
David Horstmann175afbd2023-01-12 14:17:01 +00003483
3484 MBEDTLS_ROOT_DIR="$PWD"
3485 mkdir "$OUT_OF_SOURCE_DIR"
3486 cd "$OUT_OF_SOURCE_DIR"
3487
David Horstmann67622312023-01-31 10:34:44 +00003488 # Build once to get the generated files (which need an intact config file)
David Horstmann175afbd2023-01-12 14:17:01 +00003489 cmake "$MBEDTLS_ROOT_DIR"
3490 make
3491
3492 msg "build: cmake with -DMBEDTLS_CONFIG_FILE"
3493 scripts/config.py -w full_config.h full
David Horstmann67622312023-01-31 10:34:44 +00003494 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003495 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR"
3496 make
3497
3498 msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
3499 # In the user config, disable one feature (for simplicity, pick a feature
3500 # that nothing else depends on).
3501 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3502
3503 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR"
3504 make
3505 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3506
3507 rm -f user_config.h full_config.h
3508
3509 cd "$MBEDTLS_ROOT_DIR"
3510 rm -rf "$OUT_OF_SOURCE_DIR"
3511
3512 # Now repeat the test for an in-tree build:
3513
David Horstmann67622312023-01-31 10:34:44 +00003514 # Restore config for the in-tree test
3515 mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003516
David Horstmann67622312023-01-31 10:34:44 +00003517 # Build once to get the generated files (which need an intact config)
David Horstmann175afbd2023-01-12 14:17:01 +00003518 cmake .
3519 make
3520
3521 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE"
3522 scripts/config.py -w full_config.h full
David Horstmann67622312023-01-31 10:34:44 +00003523 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003524 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h .
3525 make
3526
3527 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
3528 # In the user config, disable one feature (for simplicity, pick a feature
3529 # that nothing else depends on).
3530 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3531
3532 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h .
3533 make
3534 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3535
3536 rm -f user_config.h full_config.h
3537}
3538support_build_cmake_custom_config_file () {
3539 support_test_cmake_out_of_source
3540}
3541
3542
Tom Cosgrove51170622023-09-01 10:40:15 +01003543component_build_zeroize_checks () {
3544 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
3545
3546 scripts/config.py full
3547
3548 # Only compile - we're looking for sizeof-pointer-memaccess warnings
Tom Cosgrove5ffb1972023-09-01 14:40:21 +01003549 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 +01003550}
3551
3552
Gilles Peskine8f073122018-11-27 15:58:47 +01003553component_test_zeroize () {
3554 # Test that the function mbedtls_platform_zeroize() is not optimized away by
3555 # different combinations of compilers and optimization flags by using an
3556 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
3557 # system in all cases that the script fails, so we must manually search the
3558 # output to check whether the pass string is present and no failure strings
3559 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01003560
Gilles Peskine4976e822019-01-06 19:52:22 +00003561 # Don't try to disable ASLR. We don't care about ASLR here. We do care
3562 # about a spurious message if Gdb tries and fails, so suppress that.
3563 gdb_disable_aslr=
3564 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
3565 gdb_disable_aslr='set disable-randomization off'
3566 fi
3567
Gilles Peskine8f073122018-11-27 15:58:47 +01003568 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01003569 for compiler in clang gcc; do
3570 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
3571 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003572 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
3573 grep "The buffer was correctly zeroized" test_zeroize.log
3574 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01003575 rm -f test_zeroize.log
3576 make clean
3577 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01003578 done
Gilles Peskine8f073122018-11-27 15:58:47 +01003579}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003580
Bence Szépkúti9f849112021-10-19 15:05:36 +02003581component_test_psa_compliance () {
Bence Szépkútic1e79fd2021-11-11 20:13:14 +01003582 msg "build: make, default config + CMAC, libmbedcrypto.a only"
3583 scripts/config.py set MBEDTLS_CMAC_C
Bence Szépkútiab796e62021-10-25 19:29:07 +02003584 make -C library libmbedcrypto.a
Bence Szépkúti9f849112021-10-19 15:05:36 +02003585
3586 msg "unit test: test_psa_compliance.py"
3587 ./tests/scripts/test_psa_compliance.py
3588}
3589
3590support_test_psa_compliance () {
Bence Szépkútid6cf0892021-11-03 11:36:09 +01003591 # psa-compliance-tests only supports CMake >= 3.10.0
Bence Szépkútiab796e62021-10-25 19:29:07 +02003592 ver="$(cmake --version)"
3593 ver="${ver#cmake version }"
3594 ver_major="${ver%%.*}"
3595
3596 ver="${ver#*.}"
3597 ver_minor="${ver%%.*}"
3598
3599 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
Bence Szépkúti9f849112021-10-19 15:05:36 +02003600}
3601
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003602component_check_code_style () {
3603 msg "Check C code style"
3604 ./scripts/code_style.py
David Horstmanne09c4762022-11-10 18:30:52 +00003605}
3606
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003607support_check_code_style() {
David Horstmanne09c4762022-11-10 18:30:52 +00003608 case $(uncrustify --version) in
3609 *0.75.1*) true;;
3610 *) false;;
3611 esac
3612}
3613
Gilles Peskine8f073122018-11-27 15:58:47 +01003614component_check_python_files () {
3615 msg "Lint: Python scripts"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003616 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003617}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003618
Gilles Peskine8f073122018-11-27 15:58:47 +01003619component_check_generate_test_code () {
3620 msg "uint test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02003621 # unittest writes out mundane stuff like number or tests run on stderr.
3622 # Our convention is to reserve stderr for actual errors, and write
3623 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003624 ./tests/scripts/test_generate_test_code.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01003625}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003626
3627################################################################
3628#### Termination
3629################################################################
3630
Gilles Peskine8f073122018-11-27 15:58:47 +01003631post_report () {
3632 msg "Done, cleaning up"
Gilles Peskine24bdf022020-03-30 20:11:39 +02003633 final_cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003634
Gilles Peskine8f073122018-11-27 15:58:47 +01003635 final_report
3636}
3637
3638
3639
3640################################################################
3641#### Run all the things
3642################################################################
3643
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003644# Function invoked by --error-test to test error reporting.
3645pseudo_component_error_test () {
Gilles Peskine202e9b42021-08-02 23:28:00 +02003646 msg "Testing error reporting $error_test_i"
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003647 if [ $KEEP_GOING -ne 0 ]; then
3648 echo "Expect three failing commands."
3649 fi
Gilles Peskine202e9b42021-08-02 23:28:00 +02003650 # If the component doesn't run in a subshell, changing error_test_i to an
3651 # invalid integer will cause an error in the loop that runs this function.
3652 error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003653 # Expected error: 'grep non_existent /dev/null -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003654 grep non_existent /dev/null
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003655 # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003656 not grep -q . "$0"
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003657 # Expected error: 'make unknown_target -> 2'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003658 make unknown_target
3659 false "this should not be executed"
3660}
3661
Gilles Peskinee48351a2018-11-27 16:06:30 +01003662# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01003663run_component () {
Gilles Peskineffcdeff2018-12-04 12:49:28 +01003664 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02003665 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003666
3667 # Unconditionally create a seedfile that's sufficiently long.
3668 # Do this before each component, because a previous component may
3669 # have messed it up or shortened it.
Gilles Peskinef3133362021-07-08 19:03:50 +02003670 local dd_cmd
3671 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
3672 case $OSTYPE in
3673 linux*|freebsd*|openbsd*|darwin*) dd_cmd+=(status=none)
3674 esac
3675 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003676
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003677 # Run the component in a subshell, with error trapping and output
3678 # redirection set up based on the relevant options.
Gilles Peskine7105a332020-03-28 18:50:43 +01003679 if [ $KEEP_GOING -eq 1 ]; then
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003680 # We want to keep running if the subshell fails, so 'set -e' must
3681 # be off when the subshell runs.
Gilles Peskine7105a332020-03-28 18:50:43 +01003682 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02003683 fi
Gilles Peskine7105a332020-03-28 18:50:43 +01003684 (
3685 if [ $QUIET -eq 1 ]; then
3686 # msg() will be silenced, so just print the component name here.
3687 echo "${current_component#component_}"
3688 exec >/dev/null
3689 fi
3690 if [ $KEEP_GOING -eq 1 ]; then
3691 # Keep "set -e" off, and run an ERR trap instead to record failures.
3692 set -E
3693 trap err_trap ERR
3694 fi
3695 # The next line is what runs the component
3696 "$@"
3697 if [ $KEEP_GOING -eq 1 ]; then
3698 trap - ERR
3699 exit $last_failure_status
3700 fi
3701 )
3702 component_status=$?
3703 if [ $KEEP_GOING -eq 1 ]; then
3704 set -e
3705 if [ $component_status -ne 0 ]; then
3706 failure_count=$((failure_count + 1))
3707 fi
3708 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003709
3710 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01003711 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02003712 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01003713}
3714
3715# Preliminary setup
3716pre_check_environment
3717pre_initialize_variables
3718pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01003719
Gilles Peskine878cf602019-01-06 20:50:38 +00003720pre_check_git
Gilles Peskineef64e7f2021-07-12 18:16:01 +02003721pre_restore_files
Gilles Peskine24bdf022020-03-30 20:11:39 +02003722pre_back_up
Andrzej Kurekeb508712019-02-14 07:18:59 -05003723
Gilles Peskine878cf602019-01-06 20:50:38 +00003724build_status=0
3725if [ $KEEP_GOING -eq 1 ]; then
3726 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01003727fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02003728pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00003729pre_print_configuration
3730pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003731cleanup
3732
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003733# Run the requested tests.
Gilles Peskine202e9b42021-08-02 23:28:00 +02003734for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003735 run_component pseudo_component_error_test
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003736done
Gilles Peskine202e9b42021-08-02 23:28:00 +02003737unset error_test_i
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003738for component in $RUN_COMPONENTS; do
3739 run_component "component_$component"
3740done
Gilles Peskine8f073122018-11-27 15:58:47 +01003741
3742# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00003743post_report