blob: ca2df4d3043a78a7dadfe9479b9afc7c0d0e4479 [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
Dave Rodgmane0a2f6d2023-12-18 19:53:25 +0000178 # if CC is not set, use clang by default (if present) to improve build times
179 if [ -z "${CC+set}" ] && (type clang > /dev/null 2>&1); then
Dave Rodgmane42c2352023-12-19 16:08:19 +0000180 export CC="clang"
Dave Rodgman62be4562023-12-18 18:34:50 +0000181 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000182
Gilles Peskinec761d8f2021-09-20 18:57:55 +0200183 # Include more verbose output for failing tests run by CMake or make
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000184 export CTEST_OUTPUT_ON_FAILURE=1
185
Gilles Peskine8fd59422019-10-21 17:11:33 +0200186 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Manuel Pégourié-Gonnard717f2302022-11-30 10:42:03 +0100187 # default to -O2, use -Ox _after_ this if you want another level
Manuel Pégourié-Gonnard154b84e2022-11-28 13:12:10 +0100188 ASAN_CFLAGS='-O2 -Werror -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200189
Andrzej Kurekd95b8ed2023-06-27 10:02:09 -0400190 # Platform tests have an allocation that returns null
191 export ASAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurek6e4a9be2023-07-05 08:32:43 -0400192 export MSAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurekd95b8ed2023-06-27 10:02:09 -0400193
Gilles Peskine878cf602019-01-06 20:50:38 +0000194 # Gather the list of available components. These are the functions
195 # defined in this script whose name starts with "component_".
Gowtham Suresh Kumar13850f32023-07-28 16:41:21 +0100196 ALL_COMPONENTS=$(compgen -A function component_ | sed 's/component_//')
Gilles Peskine878cf602019-01-06 20:50:38 +0000197
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100198 # Delay determinig SUPPORTED_COMPONENTS until the command line options have a chance to override
199 # the commands set by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100200}
Andres AG38495a32016-07-12 16:54:33 +0100201
Gilles Peskinea28db922019-01-10 00:05:18 +0100202# Test whether the component $1 is included in the command line patterns.
203is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100204{
Gilles Peskine6702ce92021-08-06 11:35:17 +0200205 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
206 # only does word splitting.
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100207 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000208 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100209 set +f
210 case ${1#component_} in $pattern) return 0;; esac
211 done
212 set +f
213 return 1
214}
Andres AG7770ea82016-10-10 15:46:20 +0100215
Simon Butcher41eeccf2016-09-07 00:07:09 +0100216usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100217{
Gilles Peskine709346a2017-12-10 23:43:39 +0100218 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100219Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100220Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100221By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100222COMPONENT can be the name of a component or a shell wildcard pattern.
223
224Examples:
225 $0 "check_*"
226 Run all sanity checks.
227 $0 --no-armcc --except test_memsan
228 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100229
230Special options:
231 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000232 --list-all-components List all available test components and exit.
233 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100234
235General options:
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200236 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100237 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100238 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100239 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200240 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200241 --arm-none-eabi-gcc-prefix=<string>
242 Prefix for a cross-compiler for arm-none-eabi
243 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200244 --arm-linux-gnueabi-gcc-prefix=<string>
245 Prefix for a cross-compiler for arm-linux-gnueabi
246 (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100247 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200248 --restore First clean up the build tree, restoring backed up
249 files. Do not run any components unless they are
250 explicitly specified.
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100251 --error-test Error test mode: run a failing function in addition
Gilles Peskinea25c5672021-08-05 15:11:33 +0200252 to any specified component. May be repeated.
Gilles Peskinea28db922019-01-10 00:05:18 +0100253 --except Exclude the COMPONENTs listed on the command line,
254 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200255 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100256 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100257 --no-force Refuse to overwrite modified files (default).
258 --no-keep-going Stop at the first error (default).
259 --no-memory No additional memory tests (default).
Shaun Case0e7791f2021-12-20 21:14:10 -0800260 --no-quiet Print full output from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100261 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200262 --outcome-file=<path> File where test outcomes are written (not done if
263 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100264 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200265 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100266 -s|--seed Integer seed value to use for this test run.
267
268Tool path options:
269 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
270 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100271 --clang-earliest=<Clang_earliest_path> Earliest version of clang available
272 --clang-latest=<Clang_latest_path> Latest version of clang available
273 --gcc-earliest=<GCC_earliest_path> Earliest version of GCC available
274 --gcc-latest=<GCC_latest_path> Latest version of GCC available
Gilles Peskine709346a2017-12-10 23:43:39 +0100275 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
276 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
Gilles Peskine709346a2017-12-10 23:43:39 +0100277 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
278 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100279 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100280EOF
SimonB2e23c822016-04-16 21:54:39 +0100281}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100282
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200283# Cleanup before/after running a component.
284# Remove built files as well as the cmake cache/config.
285# Does not remove generated source files.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100286cleanup()
287{
Gilles Peskine7c652162017-12-11 00:01:40 +0100288 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200289
Gilles Peskine31b07e22018-03-21 12:15:06 +0100290 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000291 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100292 -iname CMakeFiles -exec rm -rf {} \+ -o \
293 \( -iname cmake_install.cmake -o \
294 -iname CTestTestfile.cmake -o \
295 -iname CMakeCache.txt \) -exec rm {} \+
296 # Recover files overwritten by in-tree CMake builds
Gilles Peskine79598582022-08-30 21:02:44 +0200297 rm -f include/Makefile include/mbedtls/Makefile programs/!(fuzz)/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200298
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100299 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
300 rm -rf programs/test/cmake_subproject/build
301 rm -f programs/test/cmake_subproject/Makefile
302 rm -f programs/test/cmake_subproject/cmake_subproject
303
Gilles Peskine24bdf022020-03-30 20:11:39 +0200304 # Restore files that may have been clobbered by the job
305 for x in $files_to_back_up; do
Gilles Peskine423dd132022-08-30 21:02:00 +0200306 if [[ -e "$x$backup_suffix" ]]; then
307 cp -p "$x$backup_suffix" "$x"
308 fi
Gilles Peskine24bdf022020-03-30 20:11:39 +0200309 done
310}
John Durkopbd069d32020-10-31 22:14:03 -0700311
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200312# Final cleanup when this script exits (except when exiting on a failure
313# in non-keep-going mode).
Gilles Peskine24bdf022020-03-30 20:11:39 +0200314final_cleanup () {
315 cleanup
316
317 for x in $files_to_back_up; do
318 rm -f "$x$backup_suffix"
319 done
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100320}
321
Gilles Peskine7c652162017-12-11 00:01:40 +0100322# Executed on exit. May be redefined depending on command line options.
323final_report () {
324 :
325}
326
327fatal_signal () {
Gilles Peskine24bdf022020-03-30 20:11:39 +0200328 final_cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100329 final_report $1
330 trap - $1
331 kill -$1 $$
332}
333
334trap 'fatal_signal HUP' HUP
335trap 'fatal_signal INT' INT
336trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200337
Gilles Peskine85229ac2021-09-30 18:24:21 +0200338# Number of processors on this machine. Used as the default setting
339# for parallel make.
340all_sh_nproc ()
341{
342 {
343 nproc || # Linux
344 sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
345 sysctl -n hw.ncpu || # FreeBSD
346 echo 1
347 } 2>/dev/null
348}
349
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100350msg()
351{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100352 if [ -n "${current_component:-}" ]; then
353 current_section="${current_component#component_}: $1"
354 else
355 current_section="$1"
356 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200357
358 if [ $QUIET -eq 1 ]; then
359 return
360 fi
361
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100362 echo ""
363 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100364 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000365 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100366 echo "******************************************************************"
367}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100368
Gilles Peskine8f073122018-11-27 15:58:47 +0100369armc6_build_test()
370{
371 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100372
Gilles Peskine18487f62020-04-30 23:11:54 +0200373 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100374 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
Dave Rodgman6cda3d32023-03-02 13:39:04 +0000375 WARNING_CFLAGS='-Werror -xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200376
377 msg "size: ARM Compiler 6 ($FLAGS)"
378 "$ARMC6_FROMELF" -z library/*.o
379
Gilles Peskine8f073122018-11-27 15:58:47 +0100380 make clean
381}
Andres AGa5cd9732016-10-17 15:23:10 +0100382
Andres AGd9eba4b2016-08-26 14:42:14 +0100383err_msg()
384{
385 echo "$1" >&2
386}
387
388check_tools()
389{
390 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000391 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100392 err_msg "$TOOL not found!"
393 exit 1
394 fi
395 done
396}
397
Gilles Peskine8f073122018-11-27 15:58:47 +0100398pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000399 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100400 all_except=0
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100401 error_test=0
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100402 list_components=0
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200403 restore_first=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000404 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100405
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000406 # Note that legacy options are ignored instead of being omitted from this
407 # list of options, so invocations that worked with previous version of
408 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100409 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100410 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200411 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200412 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200413 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000414 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100415 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
416 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100417 --clang-earliest) shift; CLANG_EARLIEST="$1";;
418 --clang-latest) shift; CLANG_LATEST="$1";;
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100419 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000420 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100421 --force|-f) FORCE=1;;
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100422 --gcc-earliest) shift; GCC_EARLIEST="$1";;
423 --gcc-latest) shift; GCC_LATEST="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100424 --gnutls-cli) shift; GNUTLS_CLI="$1";;
Gilles Peskine549a9612023-08-27 21:39:21 +0200425 --gnutls-legacy-cli) shift;; # ignored for backward compatibility
426 --gnutls-legacy-serv) shift;; # ignored for backward compatibility
Gilles Peskine55f7c942019-01-09 22:28:21 +0100427 --gnutls-serv) shift; GNUTLS_SERV="$1";;
428 --help|-h) usage; exit;;
429 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000430 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100431 --list-components) list_components=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100432 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200433 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000434 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100435 --no-force) FORCE=0;;
436 --no-keep-going) KEEP_GOING=0;;
437 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200438 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100439 --openssl) shift; OPENSSL="$1";;
440 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
441 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200442 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100443 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200444 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100445 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200446 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200447 --restore) restore_first=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100448 --seed|-s) shift; SEED="$1";;
449 -*)
450 echo >&2 "Unknown option: $1"
451 echo >&2 "Run $0 --help for usage."
452 exit 120
453 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000454 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100455 esac
456 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100457 done
SimonB2e23c822016-04-16 21:54:39 +0100458
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100459 # Exclude components that are not supported on this platform.
460 SUPPORTED_COMPONENTS=
461 for component in $ALL_COMPONENTS; do
462 case $(type "support_$component" 2>&1) in
463 *' function'*)
464 if ! support_$component; then continue; fi;;
465 esac
466 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
467 done
468
469 if [ $list_components -eq 1 ]; then
470 printf '%s\n' $SUPPORTED_COMPONENTS
471 exit
472 fi
473
Gilles Peskinea28db922019-01-10 00:05:18 +0100474 # With no list of components, run everything.
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200475 if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000476 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100477 fi
478
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000479 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
480 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100481 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000482 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100483 fi
SimonB2e23c822016-04-16 21:54:39 +0100484
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200485 # Error out if an explicitly requested component doesn't exist.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100486 if [ $all_except -eq 0 ]; then
487 unsupported=0
Gilles Peskine6702ce92021-08-06 11:35:17 +0200488 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
489 # only does word splitting.
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200490 set -f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100491 for component in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200492 set +f
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200493 # If the requested name includes a wildcard character, don't
494 # check it. Accept wildcard patterns that don't match anything.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100495 case $component in
496 *[*?\[]*) continue;;
497 esac
498 case " $SUPPORTED_COMPONENTS " in
499 *" $component "*) :;;
500 *)
501 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
502 unsupported=$((unsupported + 1));;
503 esac
504 done
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200505 set +f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100506 if [ $unsupported -ne 0 ]; then
507 exit 2
508 fi
509 fi
510
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000511 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100512 RUN_COMPONENTS=
513 for component in $SUPPORTED_COMPONENTS; do
514 if is_component_included "$component"; [ $? -eq $all_except ]; then
515 RUN_COMPONENTS="$RUN_COMPONENTS $component"
516 fi
517 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000518
519 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000520 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100521}
SimonB2e23c822016-04-16 21:54:39 +0100522
Gilles Peskine8f073122018-11-27 15:58:47 +0100523pre_check_git () {
524 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100525 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100526 git checkout-index -f -q $CONFIG_H
527 cleanup
528 else
SimonB2e23c822016-04-16 21:54:39 +0100529
Gilles Peskine8f073122018-11-27 15:58:47 +0100530 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
531 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
532 echo "You can either delete this directory manually, or force the test by rerunning"
533 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
534 exit 1
535 fi
536
Gilles Peskined1174cf2019-01-09 22:30:01 +0100537 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100538 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
539 echo "You can either delete or preserve your work, or force the test by rerunning the"
540 echo "script as: $0 --force"
541 exit 1
542 fi
SimonB2e23c822016-04-16 21:54:39 +0100543 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500544}
545
Gilles Peskineef64e7f2021-07-12 18:16:01 +0200546pre_restore_files () {
547 # If the makefiles have been generated by a framework such as cmake,
548 # restore them from git. If the makefiles look like modifications from
549 # the ones checked into git, take care not to modify them. Whatever
550 # this function leaves behind is what the script will restore before
551 # each component.
552 case "$(head -n1 Makefile)" in
553 *[Gg]enerated*)
554 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
555 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
556 ;;
557 esac
558}
559
Gilles Peskine24bdf022020-03-30 20:11:39 +0200560pre_back_up () {
561 for x in $files_to_back_up; do
562 cp -p "$x" "$x$backup_suffix"
563 done
564}
565
Gilles Peskine8f073122018-11-27 15:58:47 +0100566pre_setup_keep_going () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100567 failure_count=0 # Number of failed components
568 last_failure_status=0 # Last failure status in this component
569
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100570 # See err_trap
571 previous_failure_status=0
572 previous_failed_command=
573 previous_failure_funcall_depth=0
Gilles Peskine39a3b112020-03-28 21:27:40 +0100574 unset report_failed_command
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100575
Gilles Peskine7c652162017-12-11 00:01:40 +0100576 start_red=
577 end_color=
578 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100579 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100580 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
581 start_red=$(printf '\033[31m')
582 end_color=$(printf '\033[0m')
583 ;;
584 esac
585 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100586
587 # Keep a summary of failures in a file. We'll print it out at the end.
588 failure_summary_file=$PWD/all-sh-failures-$$.log
589 : >"$failure_summary_file"
590
591 # Whether it makes sense to keep a component going after the specified
592 # command fails (test command) or not (configure or build).
Gilles Peskine6702ce92021-08-06 11:35:17 +0200593 # This function normally receives the failing simple command
594 # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
595 # this is passed instead.
Gilles Peskine7105a332020-03-28 18:50:43 +0100596 # This doesn't have to be 100% accurate: all failures are recorded anyway.
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200597 # False positives result in running things that can't be expected to
598 # work. False negatives result in things not running after something else
599 # failed even though they might have given useful feedback.
Gilles Peskine7105a332020-03-28 18:50:43 +0100600 can_keep_going_after_failure () {
601 case "$1" in
602 "msg "*) false;;
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200603 "cd "*) false;;
604 *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
605 *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
606 *make*check*) true;;
607 "grep "*) true;;
608 "[ "*) true;;
609 "! "*) true;;
Gilles Peskine7105a332020-03-28 18:50:43 +0100610 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100611 esac
612 }
Gilles Peskine7105a332020-03-28 18:50:43 +0100613
614 # This function runs if there is any error in a component.
615 # It must either exit with a nonzero status, or set
616 # last_failure_status to a nonzero value.
617 err_trap () {
618 # Save $? (status of the failing command). This must be the very
619 # first thing, before $? is overridden.
620 last_failure_status=$?
Gilles Peskine39a3b112020-03-28 21:27:40 +0100621 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskine7105a332020-03-28 18:50:43 +0100622
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100623 if [[ $last_failure_status -eq $previous_failure_status &&
624 "$failed_command" == "$previous_failed_command" &&
625 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
626 then
627 # The same command failed twice in a row, but this time one level
628 # less deep in the function call stack. This happens when the last
629 # command of a function returns a nonzero status, and the function
630 # returns that same status. Ignore the second failure.
631 previous_failure_funcall_depth=${#FUNCNAME[@]}
632 return
633 fi
634 previous_failure_status=$last_failure_status
635 previous_failed_command=$failed_command
636 previous_failure_funcall_depth=${#FUNCNAME[@]}
637
Gilles Peskine7105a332020-03-28 18:50:43 +0100638 text="$current_section: $failed_command -> $last_failure_status"
639 echo "${start_red}^^^^$text^^^^${end_color}" >&2
640 echo "$text" >>"$failure_summary_file"
641
642 # If the command is fatal (configure or build command), stop this
643 # component. Otherwise (test command) keep the component running
644 # (run more tests from the same build).
645 if ! can_keep_going_after_failure "$failed_command"; then
646 exit $last_failure_status
647 fi
648 }
649
Gilles Peskine7c652162017-12-11 00:01:40 +0100650 final_report () {
651 if [ $failure_count -gt 0 ]; then
652 echo
653 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskine7105a332020-03-28 18:50:43 +0100654 echo "${start_red}FAILED: $failure_count components${end_color}"
655 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100656 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
657 elif [ -z "${1-}" ]; then
658 echo "SUCCESS :)"
659 fi
660 if [ -n "${1-}" ]; then
661 echo "Killed by SIG$1."
662 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100663 rm -f "$failure_summary_file"
664 if [ $failure_count -gt 0 ]; then
665 exit 1
666 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100667 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100668}
669
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200670# record_status() and if_build_succeeded() are kept temporarily for backward
671# compatibility. Don't use them in new components.
Gilles Peskine7105a332020-03-28 18:50:43 +0100672record_status () {
673 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100674}
Gilles Peskine7c652162017-12-11 00:01:40 +0100675if_build_succeeded () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100676 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100677}
678
Gilles Peskine39a3b112020-03-28 21:27:40 +0100679# '! true' does not trigger the ERR trap. Arrange to trigger it, with
680# a reasonably informative error message (not just "$@").
681not () {
682 if "$@"; then
683 report_failed_command="! $*"
684 false
685 unset report_failed_command
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200686 fi
687}
688
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200689pre_prepare_outcome_file () {
690 case "$MBEDTLS_TEST_OUTCOME_FILE" in
691 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
692 esac
693 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
694 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
695 fi
696}
697
Gilles Peskine8f073122018-11-27 15:58:47 +0100698pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200699 if [ $QUIET -eq 1 ]; then
700 return
701 fi
702
Gilles Peskine8f073122018-11-27 15:58:47 +0100703 msg "info: $0 configuration"
704 echo "MEMORY: $MEMORY"
705 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200706 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100707 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100708 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100709 echo "OPENSSL: $OPENSSL"
710 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
711 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
712 echo "GNUTLS_CLI: $GNUTLS_CLI"
713 echo "GNUTLS_SERV: $GNUTLS_SERV"
Gilles Peskine8f073122018-11-27 15:58:47 +0100714 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
715 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
716}
Andres AG7770ea82016-10-10 15:46:20 +0100717
Andres AGd9eba4b2016-08-26 14:42:14 +0100718# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100719pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000720 # Build the list of variables to pass to output_env.sh.
721 set env
SimonB2e23c822016-04-16 21:54:39 +0100722
Gilles Peskine87964262019-01-06 22:40:00 +0000723 case " $RUN_COMPONENTS " in
724 # Require OpenSSL and GnuTLS if running any tests (as opposed to
725 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
726 # is a good enough approximation in practice.
Bence Szépkúticb89fbd2023-12-15 20:58:15 +0100727 *" test_"* | *" release_test_"*)
Gilles Peskine87964262019-01-06 22:40:00 +0000728 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
729 # and ssl-opt.sh, we just export the variables they require.
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +0100730 export OPENSSL="$OPENSSL"
Gilles Peskine87964262019-01-06 22:40:00 +0000731 export GNUTLS_CLI="$GNUTLS_CLI"
732 export GNUTLS_SERV="$GNUTLS_SERV"
733 # Avoid passing --seed flag in every call to ssl-opt.sh
734 if [ -n "${SEED-}" ]; then
735 export SEED
736 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000737 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
738 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000739 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
Gilles Peskine549a9612023-08-27 21:39:21 +0200740 "$GNUTLS_CLI" "$GNUTLS_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000741 ;;
742 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200743
Gilles Peskine87964262019-01-06 22:40:00 +0000744 case " $RUN_COMPONENTS " in
745 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
746 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100747
Gilles Peskine87964262019-01-06 22:40:00 +0000748 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200749 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000750 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100751
Gilles Peskine87964262019-01-06 22:40:00 +0000752 case " $RUN_COMPONENTS " in
753 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
754 esac
755
756 case " $RUN_COMPONENTS " in
757 *" test_zeroize "*) check_tools "gdb";;
758 esac
759
760 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000761 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000762 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
763 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200764 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000765 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
766 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200767 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
768 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
769 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000770 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000771
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200772 # past this point, no call to check_tool, only printing output
773 if [ $QUIET -eq 1 ]; then
774 return
775 fi
776
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000777 msg "info: output_env.sh"
778 case $RUN_COMPONENTS in
779 *_armcc*)
780 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
781 *) set "$@" RUN_ARMCC=0;;
782 esac
783 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100784}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100785
Gilles Peskine192c72f2017-12-21 15:59:21 +0100786
787
788################################################################
789#### Basic checks
790################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100791
792#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200793# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100794#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100795# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200796# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100797# 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 +0200798# time, so start with a GCC build).
799# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100800#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100801# Indicative running times are given for reference.
802
Gilles Peskine8f073122018-11-27 15:58:47 +0100803component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200804 msg "Check: recursion.pl" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200805 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100806}
Janos Follathb72c6782016-07-19 14:54:17 +0100807
Gilles Peskine8f073122018-11-27 15:58:47 +0100808component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200809 msg "Check: freshness of generated source files" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200810 tests/scripts/check-generated-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100811}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200812
Gilles Peskine8f073122018-11-27 15:58:47 +0100813component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200814 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200815 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +0100816}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200817
Gilles Peskine8f073122018-11-27 15:58:47 +0100818component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200819 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200820 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100821}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200822
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200823component_check_changelog () {
824 msg "Check: changelog entries" # < 1s
825 rm -f ChangeLog.new
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200826 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200827 if [ -e ChangeLog.new ]; then
828 # Show the diff for information. It isn't an error if the diff is
829 # non-empty.
830 diff -u ChangeLog ChangeLog.new || true
831 rm ChangeLog.new
832 fi
833}
834
Gilles Peskine8f073122018-11-27 15:58:47 +0100835component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200836 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200837 tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100838}
Darryl Greena07039c2018-03-13 16:48:16 +0000839
Gilles Peskine895868b2019-09-19 21:30:05 +0200840component_check_test_cases () {
841 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200842 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200843 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200844 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200845 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200846 fi
Gilles Peskine58987962022-12-15 14:46:31 +0100847 tests/scripts/check_test_cases.py -q $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200848 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +0200849}
850
Gilles Peskine8f073122018-11-27 15:58:47 +0100851component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200852 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200853 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100854}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200855
Gilles Peskine192c72f2017-12-21 15:59:21 +0100856
Gilles Peskine636c26a2020-03-04 20:46:15 +0100857
Gilles Peskine192c72f2017-12-21 15:59:21 +0100858################################################################
859#### Build and test many configurations and targets
860################################################################
861
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200862component_test_default_out_of_box () {
863 msg "build: make, default config (out-of-box)" # ~1min
864 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200865 # Disable fancy stuff
866 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200867
868 msg "test: main suites make, default config (out-of-box)" # ~10s
869 make test
870
871 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200872 programs/test/selftest
Gilles Peskine93aaf2e2019-06-14 18:27:03 +0200873
874 msg "program demos: make, default config (out-of-box)" # ~10s
875 tests/scripts/run_demos.py
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200876}
877
Gilles Peskine8f073122018-11-27 15:58:47 +0100878component_test_default_cmake_gcc_asan () {
879 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100880 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
881 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200882
Gilles Peskine8f073122018-11-27 15:58:47 +0100883 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
884 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200885
Gilles Peskine93aaf2e2019-06-14 18:27:03 +0200886 msg "program demos (ASan build)" # ~10s
887 tests/scripts/run_demos.py
888
Gilles Peskine97bea012020-04-23 23:37:45 +0200889 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200890 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200891
Gilles Peskineee8af062023-11-02 19:58:03 +0100892 msg "test: metatests (GCC, ASan build)"
893 tests/scripts/run-metatests.sh any asan
894
Gilles Peskine8f073122018-11-27 15:58:47 +0100895 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200896 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200897
Gilles Peskine8f073122018-11-27 15:58:47 +0100898 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200899 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200900
901 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200902 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100903}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200904
Hanno Becker01635512019-02-26 14:27:09 +0000905component_test_full_cmake_gcc_asan () {
906 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200907 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000908 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
909 make
910
911 msg "test: main suites (inc. selftests) (full config, ASan build)"
912 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +0100913
Gilles Peskine97bea012020-04-23 23:37:45 +0200914 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200915 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200916
Gilles Peskine636c26a2020-03-04 20:46:15 +0100917 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200918 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100919
920 msg "test: compat.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200921 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200922
923 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200924 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100925}
926
Ronald Cronc3623db2020-10-29 10:51:32 +0100927component_test_psa_crypto_key_id_encodes_owner () {
928 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
929 scripts/config.py full
930 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
931 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
932 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
933 make
934
935 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
936 make test
937}
938
Gilles Peskine99a34622021-06-17 11:37:52 +0200939# check_renamed_symbols HEADER LIB
940# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
941# name is LIB.
942check_renamed_symbols () {
943 ! nm "$2" | sed 's/.* //' |
944 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
945}
946
Gilles Peskine984c19f2021-06-15 18:37:38 +0200947component_build_psa_crypto_spm () {
948 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
949 scripts/config.py full
950 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
951 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
952 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
953 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
954 # We can only compile, not link, since our test and sample programs
955 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
956 # is active.
957 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskine99a34622021-06-17 11:37:52 +0200958
959 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
960 # version is not present.
961 echo "Checking for renamed symbols in the library"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200962 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskine984c19f2021-06-15 18:37:38 +0200963}
964
Ronald Cron336678b2021-01-28 17:54:24 +0100965component_test_psa_crypto_client () {
966 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
967 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
968 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
969 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
970 make
971
972 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
973 make test
974}
975
Gilles Peskine636c26a2020-03-04 20:46:15 +0100976component_test_zlib_make() {
977 msg "build: zlib enabled, make"
978 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine6fa69862021-10-05 09:36:03 +0200979 make ZLIB=1 CFLAGS='-Werror -O2'
Gilles Peskine636c26a2020-03-04 20:46:15 +0100980
981 msg "test: main suites (zlib, make)"
982 make test
983
984 msg "test: ssl-opt.sh (zlib, make)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200985 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100986}
987support_test_zlib_make () {
988 base=support_test_zlib_$$
989 cat <<'EOF' > ${base}.c
990#include "zlib.h"
991int main(void) { return 0; }
992EOF
993 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
994 ret=$?
995 rm -f ${base}.*
996 return $ret
997}
998
999component_test_zlib_cmake() {
1000 msg "build: zlib enabled, cmake"
1001 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine25319702021-10-07 19:34:57 +02001002 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Release .
Gilles Peskine636c26a2020-03-04 20:46:15 +01001003 make
1004
1005 msg "test: main suites (zlib, cmake)"
1006 make test
1007
1008 msg "test: ssl-opt.sh (zlib, cmake)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001009 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001010}
1011support_test_zlib_cmake () {
1012 support_test_zlib_make "$@"
Manuel Pégourié-Gonnardf2e29022020-01-24 10:17:20 +01001013}
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +01001014
Jaeden Ameroc17f2932021-05-14 08:34:32 +01001015component_test_psa_crypto_rsa_no_genprime() {
1016 msg "build: default config minus MBEDTLS_GENPRIME"
1017 scripts/config.py unset MBEDTLS_GENPRIME
1018 make
1019
1020 msg "test: default config minus MBEDTLS_GENPRIME"
1021 make test
1022}
1023
Gilles Peskine782f4112018-11-27 16:11:09 +01001024component_test_ref_configs () {
1025 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
1026 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001027 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +01001028}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001029
Gilles Peskine8f073122018-11-27 15:58:47 +01001030component_test_sslv3 () {
1031 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001032 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +01001033 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1034 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001035
Gilles Peskine8f073122018-11-27 15:58:47 +01001036 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
1037 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +00001038
Gilles Peskine8f073122018-11-27 15:58:47 +01001039 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001040 tests/compat.sh -m 'ssl3 tls1 tls1_1 tls12 dtls1 dtls12'
Simon Butcher3ea7f522016-03-07 23:22:10 +00001041
Gilles Peskine8f073122018-11-27 15:58:47 +01001042 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001043 tests/ssl-opt.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001044
1045 msg "build: SSLv3 - context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001046 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001047}
Simon Butcher3ea7f522016-03-07 23:22:10 +00001048
Gilles Peskine8f073122018-11-27 15:58:47 +01001049component_test_no_renegotiation () {
1050 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001051 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001052 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1053 make
Simon Butcher3ea7f522016-03-07 23:22:10 +00001054
Gilles Peskine8f073122018-11-27 15:58:47 +01001055 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1056 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +01001057
Gilles Peskine8f073122018-11-27 15:58:47 +01001058 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001059 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001060}
Hanno Becker134c2ab2017-10-12 15:29:50 +01001061
Gilles Peskine56194432023-02-01 18:44:11 +01001062component_test_no_certs () {
1063 msg "build: full minus MBEDTLS_CERTS_C"
1064 scripts/config.py full
1065 scripts/config.py unset MBEDTLS_CERTS_C
1066 # Quick build+test (we're checking for stray uses of the test certs,
1067 # not expecting their absence to lead to subtle problems).
1068 make
1069
1070 msg "test: full minus MBEDTLS_CERTS_C - main suites"
1071 make test
1072}
1073
Gilles Peskine636c26a2020-03-04 20:46:15 +01001074component_test_no_pem_no_fs () {
1075 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1076 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1077 scripts/config.py unset MBEDTLS_FS_IO
1078 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1079 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
1080 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1081 make
1082
1083 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1084 make test
1085
1086 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001087 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001088}
1089
Gilles Peskine8f073122018-11-27 15:58:47 +01001090component_test_rsa_no_crt () {
1091 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001092 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +01001093 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1094 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +01001095
Gilles Peskine8f073122018-11-27 15:58:47 +01001096 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1097 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001098
Gilles Peskine8f073122018-11-27 15:58:47 +01001099 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001100 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001101
Gilles Peskine8f073122018-11-27 15:58:47 +01001102 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001103 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001104
1105 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001106 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001107}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001108
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001109component_test_no_ctr_drbg_classic () {
1110 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001111 scripts/config.py full
1112 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001113 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001114
1115 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1116 make
1117
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001118 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001119 make test
1120
Gilles Peskineba749042021-01-13 20:02:03 +01001121 # In this configuration, the TLS test programs use HMAC_DRBG.
1122 # The SSL tests are slow, so run a small subset, just enough to get
1123 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001124 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001125 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001126
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001127 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001128 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001129}
1130
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001131component_test_no_ctr_drbg_use_psa () {
1132 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001133 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001134 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1135 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001136
1137 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1138 make
1139
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001140 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1141 make test
1142
1143 # In this configuration, the TLS test programs use HMAC_DRBG.
1144 # The SSL tests are slow, so run a small subset, just enough to get
1145 # confidence that the SSL code copes with HMAC_DRBG.
1146 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001147 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001148
1149 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001150 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001151}
1152
1153component_test_no_hmac_drbg_classic () {
1154 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1155 scripts/config.py full
1156 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1157 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1158 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1159
1160 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1161 make
1162
1163 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001164 make test
1165
Gilles Peskinea2224342020-11-19 22:14:34 +01001166 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1167 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1168 # instead.
1169 # Test SSL with non-deterministic ECDSA. Only test features that
1170 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001171 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001172 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001173
1174 # To save time, only test one protocol version, since this part of
1175 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001176 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001177 tests/compat.sh -m tls12 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001178}
1179
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001180component_test_no_hmac_drbg_use_psa () {
1181 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1182 scripts/config.py full
1183 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1184 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1185 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1186
1187 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1188 make
1189
1190 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1191 make test
1192
1193 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1194 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1195 # instead.
1196 # Test SSL with non-deterministic ECDSA. Only test features that
1197 # might be affected by how ECDSA signature is performed.
1198 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001199 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001200
1201 # To save time, only test one protocol version, since this part of
1202 # the protocol is identical in (D)TLS up to 1.2.
1203 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001204 tests/compat.sh -m tls12 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001205}
1206
1207component_test_psa_external_rng_no_drbg_classic () {
1208 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1209 scripts/config.py full
1210 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1211 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001212 scripts/config.py unset MBEDTLS_ENTROPY_C
1213 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1214 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001215 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1216 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1217 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1218 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001219 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1220 # the SSL test programs don't have an RNG and can't work. Explicitly
1221 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1222 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001223
1224 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1225 make test
1226
Gilles Peskine8eb29432021-02-03 20:07:11 +01001227 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001228 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001229}
1230
1231component_test_psa_external_rng_no_drbg_use_psa () {
1232 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001233 scripts/config.py full
1234 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001235 scripts/config.py unset MBEDTLS_ENTROPY_C
1236 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1237 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001238 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1239 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1240 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1241 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1242 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1243
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001244 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001245 make test
1246
Gilles Peskine8eb29432021-02-03 20:07:11 +01001247 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001248 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001249}
1250
1251component_test_psa_external_rng_use_psa_crypto () {
1252 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1253 scripts/config.py full
1254 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1255 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1256 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1257 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1258
1259 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1260 make test
1261
Gilles Peskineba749042021-01-13 20:02:03 +01001262 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001263 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001264}
1265
Gilles Peskine55e89982023-04-28 21:04:28 +02001266component_test_psa_inject_entropy () {
1267 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
1268 scripts/config.py full
1269 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
1270 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
1271 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1272 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1273 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
1274 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
1275 make CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
1276
1277 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
1278 make test
1279}
1280
Manuel Pégourié-Gonnard1a3f9ed2020-05-19 12:38:31 +02001281component_test_ecp_no_internal_rng () {
1282 msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
1283 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1284 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1285 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1286 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1287 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
1288 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1289
1290 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1291 make
1292
1293 msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
1294 make test
1295
1296 # no SSL tests as they all depend on having a DRBG
1297}
1298
Manuel Pégourié-Gonnard53fb66d2020-06-04 09:43:14 +02001299component_test_ecp_restartable_no_internal_rng () {
1300 msg "build: Default plus ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG"
1301 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1302 scripts/config.py set MBEDTLS_ECP_RESTARTABLE
1303 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1304 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1305 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1306 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
1307 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1308
1309 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1310 make
1311
1312 msg "test: ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG module"
1313 make test
1314
1315 # no SSL tests as they all depend on having a DRBG
1316}
1317
Przemek Stekiele5352702022-10-05 11:37:54 +02001318component_test_tls1_2_default_stream_cipher_only () {
1319 msg "build: default with only stream cipher"
1320
1321 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
1322 scripts/config.py unset MBEDTLS_GCM_C
1323 scripts/config.py unset MBEDTLS_CCM_C
1324 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1325 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1326 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1327 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1328 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1329 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1330 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1331 # Modules that depend on AEAD
1332 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001333 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001334
1335 make
1336
1337 msg "test: default with only stream cipher"
1338 make test
1339
1340 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1341}
1342
1343component_test_tls1_2_default_stream_cipher_only_use_psa () {
1344 msg "build: default with only stream cipher use psa"
1345
1346 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1347 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1348 scripts/config.py unset MBEDTLS_GCM_C
1349 scripts/config.py unset MBEDTLS_CCM_C
1350 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1351 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1352 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1353 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1354 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1355 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1356 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1357 # Modules that depend on AEAD
1358 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001359 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001360
1361 make
1362
1363 msg "test: default with only stream cipher use psa"
1364 make test
1365
1366 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1367}
1368
1369component_test_tls1_2_default_cbc_legacy_cipher_only () {
1370 msg "build: default with only CBC-legacy cipher"
1371
1372 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1373 scripts/config.py unset MBEDTLS_GCM_C
1374 scripts/config.py unset MBEDTLS_CCM_C
1375 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1376 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1377 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1378 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1379 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1380 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1381 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1382 # Modules that depend on AEAD
1383 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001384 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001385
1386 make
1387
1388 msg "test: default with only CBC-legacy cipher"
1389 make test
1390
1391 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1392 tests/ssl-opt.sh -f "TLS 1.2"
1393}
1394
1395component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
1396 msg "build: default with only CBC-legacy cipher use psa"
1397
1398 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1399 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1400 scripts/config.py unset MBEDTLS_GCM_C
1401 scripts/config.py unset MBEDTLS_CCM_C
1402 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1403 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1404 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1405 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1406 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1407 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1408 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1409 # Modules that depend on AEAD
1410 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001411 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001412
1413 make
1414
1415 msg "test: default with only CBC-legacy cipher use psa"
1416 make test
1417
1418 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1419 tests/ssl-opt.sh -f "TLS 1.2"
1420}
1421
1422component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
1423 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1424
1425 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1426 scripts/config.py unset MBEDTLS_GCM_C
1427 scripts/config.py unset MBEDTLS_CCM_C
1428 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1429 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1430 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1431 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1432 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1433 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1434 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1435 # Modules that depend on AEAD
1436 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001437 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001438
1439 make
1440
1441 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1442 make test
1443
1444 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1445 tests/ssl-opt.sh -f "TLS 1.2"
1446}
1447
1448component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
1449 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
1450
1451 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1452 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1453 scripts/config.py unset MBEDTLS_GCM_C
1454 scripts/config.py unset MBEDTLS_CCM_C
1455 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1456 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1457 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1458 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1459 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1460 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1461 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1462 # Modules that depend on AEAD
1463 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001464 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001465
1466 make
1467
1468 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
1469 make test
1470
1471 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
1472 tests/ssl-opt.sh -f "TLS 1.2"
1473}
1474
Gilles Peskine636c26a2020-03-04 20:46:15 +01001475component_test_new_ecdh_context () {
1476 msg "build: new ECDH context (ASan build)" # ~ 6 min
1477 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1478 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1479 make
1480
1481 msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1482 make test
1483
1484 msg "test: new ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001485 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001486
1487 msg "test: new ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1488 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001489 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001490}
1491
1492component_test_everest () {
1493 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
1494 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1495 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1496 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1497 make
1498
1499 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1500 make test
1501
Gilles Peskineee8af062023-11-02 19:58:03 +01001502 msg "test: metatests (clang, ASan)"
1503 tests/scripts/run-metatests.sh any asan
1504
Gilles Peskine636c26a2020-03-04 20:46:15 +01001505 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001506 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001507
1508 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1509 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001510 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001511}
1512
Gilles Peskined3beca92020-07-03 00:15:37 +02001513component_test_everest_curve25519_only () {
1514 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
1515 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1516 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1517 scripts/config.py unset MBEDTLS_ECDSA_C
1518 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1519 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1520 # Disable all curves
1521 for c in $(sed -n 's/#define \(MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED\).*/\1/p' <"$CONFIG_H"); do
1522 scripts/config.py unset "$c"
1523 done
1524 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1525
1526 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1527
1528 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1529 make test
1530}
1531
Gilles Peskine8f073122018-11-27 15:58:47 +01001532component_test_small_ssl_out_content_len () {
1533 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001534 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1535 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001536 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1537 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001538
Gilles Peskine8f073122018-11-27 15:58:47 +01001539 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001540 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001541}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001542
Gilles Peskine8f073122018-11-27 15:58:47 +01001543component_test_small_ssl_in_content_len () {
1544 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001545 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1546 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001547 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1548 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001549
Gilles Peskine8f073122018-11-27 15:58:47 +01001550 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001551 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001552}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001553
Gilles Peskine8f073122018-11-27 15:58:47 +01001554component_test_small_ssl_dtls_max_buffering () {
1555 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001556 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001557 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1558 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001559
Gilles Peskine8f073122018-11-27 15:58:47 +01001560 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001561 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 +01001562}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001563
Gilles Peskine8f073122018-11-27 15:58:47 +01001564component_test_small_mbedtls_ssl_dtls_max_buffering () {
1565 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001566 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001567 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1568 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001569
Gilles Peskine8f073122018-11-27 15:58:47 +01001570 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001571 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001572}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001573
Gilles Peskine75cc7712019-09-06 19:47:17 +02001574component_test_psa_collect_statuses () {
1575 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001576 scripts/config.py full
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001577 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001578 # Check that psa_crypto_init() succeeded at least once
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001579 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001580 rm -f tests/statuses.log
1581}
1582
Gilles Peskine8f073122018-11-27 15:58:47 +01001583component_test_full_cmake_clang () {
1584 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001585 scripts/config.py full
Gilles Peskine83264be2022-10-30 21:02:40 +01001586 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 +01001587 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001588
k-stachowiak0291cb72019-06-26 15:52:12 +02001589 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001590 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001591
Gilles Peskine83264be2022-10-30 21:02:40 +01001592 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
1593 programs/test/cpp_dummy_build
1594
Gilles Peskineee8af062023-11-02 19:58:03 +01001595 msg "test: metatests (clang)"
Gilles Peskinee38eb792023-11-03 18:05:38 +01001596 tests/scripts/run-metatests.sh any pthread
Gilles Peskineee8af062023-11-02 19:58:03 +01001597
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02001598 msg "program demos (full config, clang)" # ~10s
1599 tests/scripts/run_demos.py
1600
k-stachowiak0291cb72019-06-26 15:52:12 +02001601 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001602 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001603
Gilles Peskine8f073122018-11-27 15:58:47 +01001604 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001605 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001606
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001607 msg "test: compat.sh RC4, 3DES & NULL (full config)" # ~ 2min
1608 tests/compat.sh -e '^$' -f 'NULL\|3DES\|DES-CBC3\|RC4\|ARCFOUR'
1609
1610 msg "test: compat.sh single-DES (full config)" # ~ 30s
1611 env OPENSSL="$OPENSSL_LEGACY" tests/compat.sh -e '3DES\|DES-CBC3' -f 'DES'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001612
Gilles Peskine8f073122018-11-27 15:58:47 +01001613 msg "test: compat.sh ARIA + ChachaPoly"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001614 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001615}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001616
Gilles Peskine9603a442022-11-29 16:01:41 +01001617skip_suites_without_constant_flow () {
1618 # Skip the test suites that don't have any constant-flow annotations.
1619 # This will need to be adjusted if we ever start declaring things as
1620 # secret from macros or functions inside tests/include or tests/src.
1621 SKIP_TEST_SUITES=$(
1622 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
1623 sed 's/test_suite_//; s/\.function$//' |
1624 tr '\n' ,)
1625 export SKIP_TEST_SUITES
1626}
1627
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001628component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001629 # This tests both (1) accesses to undefined memory, and (2) branches or
1630 # memory access depending on secret values. To distinguish between those:
1631 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1632 # - or alternatively, change the build type to MemSanDbg, which enables
1633 # origin tracking and nicer stack traces (which are useful for debugging
1634 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1635 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001636 scripts/config.py full
1637 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1638 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1639 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1640 make
1641
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001642 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001643 make test
1644}
1645
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01001646component_release_test_valgrind_constant_flow () {
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001647 # This tests both (1) everything that valgrind's memcheck usually checks
1648 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1649 # etc.) and (2) branches or memory access depending on secret values,
1650 # which will be reported as uninitialized memory. To distinguish between
1651 # secret and actually uninitialized:
1652 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1653 # - or alternatively, build with debug info and manually run the offending
1654 # test suite with valgrind --track-origins=yes, then check if the origin
1655 # was TEST_CF_SECRET() or something else.
1656 msg "build: cmake release GCC, full config with constant flow testing"
1657 scripts/config.py full
1658 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Gilles Peskine9603a442022-11-29 16:01:41 +01001659 skip_suites_without_constant_flow
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001660 cmake -D CMAKE_BUILD_TYPE:String=Release .
1661 make
1662
1663 # this only shows a summary of the results (how many of each type)
1664 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine9603a442022-11-29 16:01:41 +01001665 msg "test: some suites (valgrind + constant flow)"
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001666 make memcheck
1667}
1668
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001669component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02001670 # Test that removing the deprecated features from the default
1671 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001672 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1673 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
Dave Rodgman374b1882024-01-04 10:30:57 +00001674 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001675
1676 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1677 make test
1678}
1679
1680component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02001681 msg "build: make, full_no_deprecated config" # ~ 30s
1682 scripts/config.py full_no_deprecated
Dave Rodgman374b1882024-01-04 10:30:57 +00001683 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001684
Gilles Peskine30de2e82020-04-20 21:39:22 +02001685 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001686 make test
1687}
1688
Gilles Peskine8386ea22020-04-30 09:07:29 +02001689component_test_full_no_deprecated_deprecated_warning () {
1690 # Test that there is nothing deprecated in "full_no_deprecated".
1691 # A deprecated feature would trigger a warning (made fatal) from
1692 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02001693 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1694 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001695 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
1696 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Dave Rodgman374b1882024-01-04 10:30:57 +00001697 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001698
Gilles Peskine30de2e82020-04-20 21:39:22 +02001699 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001700 make test
1701}
1702
Gilles Peskine8386ea22020-04-30 09:07:29 +02001703component_test_full_deprecated_warning () {
1704 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
1705 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001706 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001707 scripts/config.py full
1708 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001709 # Expect warnings from '#warning' directives in check_config.h.
Dave Rodgman9d2c67f2023-12-19 14:07:15 +00001710 # Note that gcc is required to allow the use of -Wno-error=cpp, which allows us to
1711 # display #warning messages without them being treated as errors.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001712 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001713
Gilles Peskine8386ea22020-04-30 09:07:29 +02001714 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1715 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
1716 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001717 # Expect warnings from '#warning' directives in check_config.h and
1718 # from the use of deprecated functions in test suites.
1719 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 +01001720
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001721 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
1722 make test
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02001723
1724 msg "program demos: full config + MBEDTLS_TEST_DEPRECATED" # ~10s
1725 tests/scripts/run_demos.py
Gilles Peskine8f073122018-11-27 15:58:47 +01001726}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00001727
Gilles Peskineec541fe2020-01-31 14:24:14 +01001728# Check that the specified libraries exist and are empty.
1729are_empty_libraries () {
1730 nm "$@" >/dev/null 2>/dev/null
1731 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
1732}
1733
1734component_build_crypto_default () {
1735 msg "build: make, crypto only"
1736 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01001737 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001738 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001739}
1740
1741component_build_crypto_full () {
1742 msg "build: make, crypto only, full config"
1743 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01001744 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001745 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001746}
1747
Gilles Peskine8df27482022-10-21 19:34:54 +02001748component_test_crypto_for_psa_service () {
Gilles Peskine21503df2022-10-11 21:05:06 +02001749 msg "build: make, config for PSA crypto service"
1750 scripts/config.py crypto
1751 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1752 # Disable things that are not needed for just cryptography, to
1753 # reach a configuration that would be typical for a PSA cryptography
1754 # service providing all implemented PSA algorithms.
1755 # System stuff
1756 scripts/config.py unset MBEDTLS_ERROR_C
1757 scripts/config.py unset MBEDTLS_TIMING_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001758 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskine21503df2022-10-11 21:05:06 +02001759 # Crypto stuff with no PSA interface
1760 scripts/config.py unset MBEDTLS_BASE64_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001761 scripts/config.py unset MBEDTLS_BLOWFISH_C
1762 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
1763 # Keep MBEDTLS_MD_C because RSA and ECDSA need it, also HMAC_DRBG which
1764 # is needed for deterministic ECDSA.
1765 scripts/config.py unset MBEDTLS_ECJPAKE_C
1766 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
Gilles Peskine21503df2022-10-11 21:05:06 +02001767 scripts/config.py unset MBEDTLS_NIST_KW_C
1768 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1769 scripts/config.py unset MBEDTLS_PEM_WRITE_C
1770 scripts/config.py unset MBEDTLS_PKCS12_C
1771 scripts/config.py unset MBEDTLS_PKCS5_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001772 # We keep MBEDTLS_PK_{,PARSE,WRITE}_C because PSA with RSA needs it.
1773 scripts/config.py unset MBEDTLS_XTEA_C
Gilles Peskine21503df2022-10-11 21:05:06 +02001774 make CFLAGS='-O1 -Werror' all test
1775 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1776}
1777
Gilles Peskineec541fe2020-01-31 14:24:14 +01001778component_build_crypto_baremetal () {
1779 msg "build: make, crypto only, baremetal config"
1780 scripts/config.py crypto_baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001781 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001782 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001783}
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001784support_build_crypto_baremetal () {
Daniel Axtens1a021af2020-08-31 14:22:58 +10001785 support_build_baremetal "$@"
1786}
1787
1788component_build_baremetal () {
1789 msg "build: make, baremetal config"
1790 scripts/config.py baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001791 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Daniel Axtens1a021af2020-08-31 14:22:58 +10001792}
1793support_build_baremetal () {
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001794 # Older Glibc versions include time.h from other headers such as stdlib.h,
1795 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
1796 # problem, Ubuntu 18.04 is ok.
1797 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
1798}
Gilles Peskineec541fe2020-01-31 14:24:14 +01001799
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001800# depends.py family of tests
Andrzej Kurek85d69302022-10-05 09:14:07 -04001801component_test_depends_py_cipher_id () {
1802 msg "test/build: depends.py cipher_id (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001803 tests/scripts/depends.py cipher_id --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001804}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001805
Andrzej Kurek85d69302022-10-05 09:14:07 -04001806component_test_depends_py_cipher_chaining () {
1807 msg "test/build: depends.py cipher_chaining (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001808 tests/scripts/depends.py cipher_chaining --unset-use-psa
John Durkopc14be902020-08-20 06:16:41 -07001809}
1810
Andrzej Kurek85d69302022-10-05 09:14:07 -04001811component_test_depends_py_cipher_padding () {
1812 msg "test/build: depends.py cipher_padding (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001813 tests/scripts/depends.py cipher_padding --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001814}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001815
Andrzej Kurek85d69302022-10-05 09:14:07 -04001816component_test_depends_py_curves () {
1817 msg "test/build: depends.py curves (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001818 tests/scripts/depends.py curves --unset-use-psa
John Durkop2ec2eaa2020-08-24 18:29:15 -07001819}
1820
Andrzej Kurek85d69302022-10-05 09:14:07 -04001821component_test_depends_py_hashes () {
1822 msg "test/build: depends.py hashes (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001823 tests/scripts/depends.py hashes --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001824}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001825
Andrzej Kurek85d69302022-10-05 09:14:07 -04001826component_test_depends_py_kex () {
1827 msg "test/build: depends.py kex (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001828 tests/scripts/depends.py kex --unset-use-psa
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001829}
1830
Andrzej Kurek85d69302022-10-05 09:14:07 -04001831component_test_depends_py_pkalgs () {
1832 msg "test/build: depends.py pkalgs (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001833 tests/scripts/depends.py pkalgs --unset-use-psa
1834}
1835
1836# PSA equivalents of the depends.py tests
1837component_test_depends_py_cipher_id_psa () {
1838 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1839 tests/scripts/depends.py cipher_id
1840}
1841
1842component_test_depends_py_cipher_chaining_psa () {
1843 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1844 tests/scripts/depends.py cipher_chaining
1845}
1846
1847component_test_depends_py_cipher_padding_psa () {
1848 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1849 tests/scripts/depends.py cipher_padding
1850}
1851
1852component_test_depends_py_curves_psa () {
1853 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1854 tests/scripts/depends.py curves
1855}
1856
1857component_test_depends_py_hashes_psa () {
1858 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1859 tests/scripts/depends.py hashes
1860}
1861
1862component_test_depends_py_kex_psa () {
1863 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1864 tests/scripts/depends.py kex
1865}
1866
1867component_test_depends_py_pkalgs_psa () {
1868 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Andrzej Kurek85d69302022-10-05 09:14:07 -04001869 tests/scripts/depends.py pkalgs
Gilles Peskine8f073122018-11-27 15:58:47 +01001870}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001871
Dave Rodgman5fce4f62023-01-20 13:18:05 +00001872component_build_no_pk_rsa_alt_support () {
1873 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
1874
1875 scripts/config.py full
1876 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
1877 scripts/config.py set MBEDTLS_RSA_C
1878 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
1879
1880 # Only compile - this is primarily to test for compile issues
Dave Rodgman374b1882024-01-04 10:30:57 +00001881 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
Dave Rodgman5fce4f62023-01-20 13:18:05 +00001882}
1883
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001884component_test_no_use_psa_crypto_full_cmake_asan() {
1885 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02001886 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001887 scripts/config.py full
1888 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
1889 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1890 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1891 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02001892 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001893 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01001894 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001895 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001896
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001897 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001898 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001899
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001900 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001901 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001902
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001903 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001904 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001905
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001906 msg "test: compat.sh RC4, 3DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
1907 tests/compat.sh -e '^$' -f 'NULL\|3DES\|DES-CBC3\|RC4\|ARCFOUR'
1908
1909 msg "test: compat.sh single-DES (full minus MBEDTLS_USE_PSA_CRYPTO)"
1910 env OPENSSL="$OPENSSL_LEGACY" tests/compat.sh -e '3DES\|DES-CBC3' -f 'DES'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001911
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001912 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001913 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001914}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001915
Ronald Crond2c53e62021-09-13 09:38:05 +02001916component_test_psa_crypto_config_accel_ecdsa () {
1917 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1918
1919 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1920 # partial support for cipher operations in the driver test library.
1921 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1922 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Gilles Peskine62de7672022-04-21 11:05:16 +02001923 # Disable obsolete hashes (alternatively we could enable support for them
1924 # in the driver test library).
1925 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1926 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
Ronald Crond2c53e62021-09-13 09:38:05 +02001927
1928 # SHA384 needed for some ECDSA signature tests.
1929 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
1930
1931 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
1932 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1933 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1934
1935 # Restore test driver base configuration
1936 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
1937
1938 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1939 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1940 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1941 scripts/config.py unset MBEDTLS_ECDSA_C
1942 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1943 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1944
1945 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
1946 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"
1947
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01001948 not grep mbedtls_ecdsa_ library/ecdsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02001949
1950 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1951 make test
1952}
1953
1954component_test_psa_crypto_config_accel_rsa_signature () {
1955 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
1956
1957 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1958 # partial support for cipher operations in the driver test library.
1959 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1960 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1961
1962 # It seems it is not possible to remove only the support for RSA signature
1963 # in the library. Thus we have to remove all RSA support (signature and
1964 # encryption/decryption). AS there is no driver support for asymmetric
1965 # encryption/decryption so far remove RSA encryption/decryption from the
1966 # application algorithm list.
1967 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1968 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1969
1970 # Make sure both the library and the test library support the SHA hash
1971 # algorithms and only those ones (SHA256 is included by default). That way:
1972 # - the test library can compute the RSA signatures even in the case of a
1973 # composite RSA signature algorithm based on a SHA hash (no other hash
1974 # used in the unit tests).
1975 # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
1976 # fulfilled as the hash SHA algorithm is supported by the library, and
1977 # thus the tests are run, not skipped.
1978 # - when testing a signature key with an algorithm wildcard built from
1979 # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
1980 # algorithm based on the hashes supported by the library is also
1981 # supported by the test library.
1982 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1983 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1984 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1985 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160_C
1986
1987 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA1_C
1988 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
1989 # We need PEM parsing in the test library as well to support the import
1990 # of PEM encoded RSA keys.
1991 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_PEM_PARSE_C
1992 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_BASE64_C
1993
1994 loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
1995 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1996 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1997
1998 # Restore test driver base configuration
1999 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA1_C
2000 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
2001 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_PEM_PARSE_C
2002 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_BASE64_C
2003
2004
2005 # Mbed TLS library build
2006 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2007 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2008
2009 # Remove RSA support and its dependencies
2010 scripts/config.py unset MBEDTLS_PKCS1_V15
2011 scripts/config.py unset MBEDTLS_PKCS1_V21
2012 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2013 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2014 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2015 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2016 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2017 scripts/config.py unset MBEDTLS_RSA_C
2018 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2019
2020 scripts/config.py unset MBEDTLS_MD2_C
2021 scripts/config.py unset MBEDTLS_MD4_C
2022 scripts/config.py unset MBEDTLS_MD5_C
2023 scripts/config.py unset MBEDTLS_RIPEMD160_C
2024 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
2025 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
2026 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
2027
2028 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2029 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2030
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002031 not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
2032 not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02002033
2034 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
2035 make test
2036}
2037
Ronald Cronf7e483c2021-05-08 14:32:59 +02002038component_test_psa_crypto_config_accel_hash () {
2039 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2040
2041 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
2042 # partial support for cipher operations in the driver test library.
2043 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2044 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
2045
2046 loc_accel_list="ALG_MD4 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
2047 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2048 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2049
2050 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2051 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2052 scripts/config.py unset MBEDTLS_MD2_C
2053 scripts/config.py unset MBEDTLS_MD4_C
2054 scripts/config.py unset MBEDTLS_MD5_C
2055 scripts/config.py unset MBEDTLS_RIPEMD160_C
2056 scripts/config.py unset MBEDTLS_SHA1_C
2057 # Don't unset MBEDTLS_SHA256_C as it is needed by PSA crypto core.
2058 scripts/config.py unset MBEDTLS_SHA512_C
2059 # Unset MBEDTLS_SSL_PROTO_SSL3, MBEDTLS_SSL_PROTO_TLS1 and MBEDTLS_SSL_PROTO_TLS1_1 as they depend on MBEDTLS_SHA1_C
2060 scripts/config.py unset MBEDTLS_SSL_PROTO_SSL3
2061 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
2062 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
2063 # Unset MBEDTLS_SSL_CBC_RECORD_SPLITTING as it depends on MBEDTLS_SSL_PROTO_TLS1 in the default configuration.
2064 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
2065 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2066 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2067
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002068 not grep mbedtls_sha512_init library/sha512.o
2069 not grep mbedtls_sha1_init library/sha1.o
Ronald Cronf7e483c2021-05-08 14:32:59 +02002070
2071 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2072 make test
2073}
2074
Ronald Cron09623702021-10-18 11:26:01 +02002075component_test_psa_crypto_config_accel_cipher () {
2076 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
2077
Gilles Peskine186331872022-04-12 15:58:03 +02002078 # This test case focuses on cipher+AEAD. We don't yet support all
2079 # combinations of configurations, so deactivate block-cipher-based MACs.
2080 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CMAC
2081
Ronald Cron09623702021-10-18 11:26:01 +02002082 loc_accel_list="ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB ALG_OFB ALG_XTS KEY_TYPE_DES"
2083 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2084 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2085
2086 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2087 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2088
2089 # There is no intended accelerator support for ALG STREAM_CIPHER and
2090 # ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
2091 # inclusion of the Mbed TLS cipher operations. As we want to test here with
2092 # cipher operations solely supported by accelerators, disabled those
2093 # PSA configuration options.
2094 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2095 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Ronald Cron09623702021-10-18 11:26:01 +02002096
2097 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2098 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2099 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2100 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2101 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2102 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2103 scripts/config.py unset MBEDTLS_DES_C
2104
2105 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2106 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2107
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002108 not grep mbedtls_des* library/des.o
Ronald Cron09623702021-10-18 11:26:01 +02002109
2110 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2111 make test
2112}
2113
Przemek Stekiel8b56f232022-10-02 20:58:39 +02002114component_test_psa_crypto_config_accel_aead () {
2115 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2116
2117 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
2118 # partial support for cipher operations in the driver test library.
2119 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2120 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
2121
2122 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2123 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2124 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2125
2126 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2127 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2128
2129 scripts/config.py unset MBEDTLS_GCM_C
2130 scripts/config.py unset MBEDTLS_CCM_C
2131 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2132 # Features that depend on AEAD
2133 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
2134 scripts/config.py unset MBEDTLS_SSL_TICKET_C
2135
2136 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2137 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"
2138
2139 # There's a risk of something getting re-enabled via config_psa.h
2140 # make sure it did not happen.
2141 not grep mbedtls_ccm library/ccm.o
2142 not grep mbedtls_gcm library/gcm.o
2143 not grep mbedtls_chachapoly library/chachapoly.o
2144
2145 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2146 make test
2147}
2148
John Durkop4377bf72020-10-23 01:26:57 -07002149component_test_psa_crypto_config_no_driver() {
John Durkop4377bf72020-10-23 01:26:57 -07002150 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
2151 scripts/config.py full
2152 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2153 scripts/config.py unset MBEDTLS_PSA_CRYPTO_DRIVERS
2154 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkope7012c72020-10-26 09:55:01 -07002155 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop4377bf72020-10-23 01:26:57 -07002156
2157 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
John Durkopd8959392020-09-20 23:09:17 -07002158 make test
2159}
2160
Gilles Peskined4c85af2023-07-20 22:19:45 +02002161component_test_aead_chachapoly_disabled() {
2162 msg "build: full minus CHACHAPOLY"
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002163 scripts/config.py full
2164 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Gilles Peskined4c85af2023-07-20 22:19:45 +02002165 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002166 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
2167
Gilles Peskined4c85af2023-07-20 22:19:45 +02002168 msg "test: full minus CHACHAPOLY"
2169 make test
2170}
2171
2172component_test_aead_only_ccm() {
2173 msg "build: full minus CHACHAPOLY and GCM"
2174 scripts/config.py full
2175 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2176 scripts/config.py unset MBEDTLS_GCM_C
2177 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2178 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2179 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
2180
2181 msg "test: full minus CHACHAPOLY and GCM"
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002182 make test
2183}
2184
John Durkopd0321952020-10-29 21:37:36 -07002185# 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 -08002186component_build_psa_accel_alg_ecdh() {
Gilles Peskine168be012023-07-19 19:36:55 +02002187 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
John Durkopd0321952020-10-29 21:37:36 -07002188 scripts/config.py full
2189 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2190 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2191 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2192 scripts/config.py unset MBEDTLS_ECDH_C
2193 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2194 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2195 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2196 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2197 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2198 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2199 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2200}
2201
John Durkopf4c4cb02020-10-28 20:09:55 -07002202# 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 -08002203component_build_psa_accel_key_type_ecc_key_pair() {
Gilles Peskine168be012023-07-19 19:36:55 +02002204 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR"
John Durkopf4c4cb02020-10-28 20:09:55 -07002205 scripts/config.py full
2206 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2207 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2208 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002209 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 -08002210 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 -07002211 # 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 -08002212 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 -07002213}
2214
2215# 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 -08002216component_build_psa_accel_key_type_ecc_public_key() {
Gilles Peskine168be012023-07-19 19:36:55 +02002217 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
John Durkopf4c4cb02020-10-28 20:09:55 -07002218 scripts/config.py full
2219 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2220 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2221 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002222 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
2223 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
John Durkopf4c4cb02020-10-28 20:09:55 -07002224 # 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 -08002225 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 -07002226}
2227
John Durkopd0321952020-10-29 21:37:36 -07002228# 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 -08002229component_build_psa_accel_alg_hmac() {
Gilles Peskine168be012023-07-19 19:36:55 +02002230 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
John Durkopd0321952020-10-29 21:37:36 -07002231 scripts/config.py full
2232 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2233 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2234 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2235 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2236 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2237}
2238
2239# 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 -08002240component_build_psa_accel_alg_hkdf() {
Gilles Peskine168be012023-07-19 19:36:55 +02002241 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
John Durkopd0321952020-10-29 21:37:36 -07002242 scripts/config.py full
2243 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2244 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2245 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2246 scripts/config.py unset MBEDTLS_HKDF_C
John Durkopbd069d32020-10-31 22:14:03 -07002247 # Make sure to unset TLS1_3_EXPERIMENTAL since it requires HKDF_C and will not build properly without it.
2248 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
John Durkopd0321952020-10-29 21:37:36 -07002249 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2250 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2251}
2252
John Durkop1b7ee052020-11-27 08:51:22 -08002253# This should be renamed to test and updated once the accelerator MD2 code is in place and ready to test.
2254component_build_psa_accel_alg_md2() {
Gilles Peskine168be012023-07-19 19:36:55 +02002255 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD2 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002256 scripts/config.py full
2257 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2258 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2259 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2260 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2261 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2262 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2263 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2264 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2265 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2266 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2267 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2268 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2269 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD2 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2270}
2271
2272# This should be renamed to test and updated once the accelerator MD4 code is in place and ready to test.
2273component_build_psa_accel_alg_md4() {
Gilles Peskine168be012023-07-19 19:36:55 +02002274 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD4 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002275 scripts/config.py full
2276 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2277 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2278 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2279 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2280 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2281 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2282 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2283 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2284 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2285 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2286 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2287 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2288 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD4 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2289}
2290
2291# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
2292component_build_psa_accel_alg_md5() {
Gilles Peskine168be012023-07-19 19:36:55 +02002293 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002294 scripts/config.py full
2295 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2296 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2297 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2298 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2299 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2300 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2301 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2302 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2303 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2304 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2305 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2306 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2307 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2308}
2309
2310# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
2311component_build_psa_accel_alg_ripemd160() {
Gilles Peskine168be012023-07-19 19:36:55 +02002312 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002313 scripts/config.py full
2314 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2315 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2316 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2317 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2318 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2319 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2320 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2321 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2322 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2323 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2324 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2325 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2326 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2327}
2328
2329# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
2330component_build_psa_accel_alg_sha1() {
Gilles Peskine168be012023-07-19 19:36:55 +02002331 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002332 scripts/config.py full
2333 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2334 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2335 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2336 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2337 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2338 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2339 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2340 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2341 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2342 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2343 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2344 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2345 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2346}
2347
2348# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
2349component_build_psa_accel_alg_sha224() {
Gilles Peskine168be012023-07-19 19:36:55 +02002350 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002351 scripts/config.py full
2352 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2353 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2354 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2355 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2356 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2357 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2358 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2359 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2360 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2361 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2362 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2363 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2364}
2365
2366# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
2367component_build_psa_accel_alg_sha256() {
Gilles Peskine168be012023-07-19 19:36:55 +02002368 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002369 scripts/config.py full
2370 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2371 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2372 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2373 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2374 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2375 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2376 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2377 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2378 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2379 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2380 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2381 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2382 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2383}
2384
2385# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
2386component_build_psa_accel_alg_sha384() {
Gilles Peskine168be012023-07-19 19:36:55 +02002387 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002388 scripts/config.py full
2389 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2390 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2391 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2392 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2393 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2394 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2395 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2396 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2397 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2398 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2399 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2400 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2401}
2402
2403# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
2404component_build_psa_accel_alg_sha512() {
Gilles Peskine168be012023-07-19 19:36:55 +02002405 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002406 scripts/config.py full
2407 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2408 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2409 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2410 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2411 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2412 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2413 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2414 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2415 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2416 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2417 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2418 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2419 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2420}
2421
John Durkopd0321952020-10-29 21:37:36 -07002422# 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_crypt() {
Gilles Peskine168be012023-07-19 19:36:55 +02002424 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 -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
John Durkopbd069d32020-10-31 22:14:03 -07002429 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002430 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
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 Durkopd0321952020-10-29 21:37:36 -07002433 # 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 -07002434 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -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_pkcs1v15_sign() {
Gilles Peskine168be012023-07-19 19:36:55 +02002439 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 -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_PKCS1V15_SIGN 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_OAEP
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_PKCS1V15_SIGN -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_oaep() {
Gilles Peskine168be012023-07-19 19:36:55 +02002454 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 -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_OAEP 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_PSS
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_OAEP -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_alg_rsa_pss() {
Gilles Peskine168be012023-07-19 19:36:55 +02002469 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 -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
John Durkop7fc75ea2020-11-03 19:05:36 -08002475 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2476 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2477 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07002478 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2479 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2480}
2481
2482# 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 -08002483component_build_psa_accel_key_type_rsa_key_pair() {
Gilles Peskine168be012023-07-19 19:36:55 +02002484 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 -07002485 scripts/config.py full
2486 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2487 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2488 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2489 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2490 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
2491 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2492 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"
2493}
2494
2495# 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 -08002496component_build_psa_accel_key_type_rsa_public_key() {
Gilles Peskine168be012023-07-19 19:36:55 +02002497 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 -07002498 scripts/config.py full
2499 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2500 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2501 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2502 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2503 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
2504 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2505 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 -07002506}
2507
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002508component_test_check_params_functionality () {
2509 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002510 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002511 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002512 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Ronald Crona1236142020-07-01 16:01:21 +02002513 make CC=gcc CFLAGS='-Werror -O1' all test
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002514}
2515
Gilles Peskineb28636b2019-01-02 19:06:24 +01002516component_test_check_params_without_platform () {
2517 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002518 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002519 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002520 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
2521 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
2522 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
2523 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
Gilles Peskine32e889d2020-04-12 23:43:28 +02002524 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002525 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
2526 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskine9c764bf2022-09-18 14:05:23 +02002527 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002528 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
2529 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +01002530 make CC=gcc CFLAGS='-Werror -O1' all test
2531}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002532
Gilles Peskineb28636b2019-01-02 19:06:24 +01002533component_test_check_params_silent () {
2534 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002535 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002536 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01002537 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
2538 make CC=gcc CFLAGS='-Werror -O1' all test
2539}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002540
Dave Rodgman173227d2023-06-29 09:29:00 +01002541component_build_aes_variations() { # ~45s
2542 msg "build: aes.o for all combinations of relevant config options"
Dave Rodgmanbf998282023-06-29 12:10:45 +01002543
Dave Rodgman173227d2023-06-29 09:29:00 +01002544 for a in set unset; do
2545 for b in set unset; do
2546 for c in set unset; do
2547 for d in set unset; do
2548 for e in set unset; do
2549 for f in set unset; do
2550 for g in set unset; do
Dave Rodgmanbf998282023-06-29 12:10:45 +01002551 echo ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
2552 echo ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
2553 echo ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
2554 echo ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
2555 echo ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
2556 echo ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
2557 echo ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman173227d2023-06-29 09:29:00 +01002558
Dave Rodgmanbf998282023-06-29 12:10:45 +01002559 ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
2560 ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
2561 ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
2562 ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
2563 ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
2564 ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
2565 ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman173227d2023-06-29 09:29:00 +01002566
Dave Rodgmanbf998282023-06-29 12:10:45 +01002567 rm -f library/aes.o
2568 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 +01002569 done
2570 done
2571 done
2572 done
2573 done
2574 done
2575 done
2576}
2577
Gilles Peskine8f073122018-11-27 15:58:47 +01002578component_test_no_platform () {
2579 # Full configuration build, without platform support, file IO and net sockets.
2580 # This should catch missing mbedtls_printf definitions, and by disabling file
2581 # IO, it should catch missing '#include <stdio.h>'
2582 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Paul Elliott68050372023-11-03 19:24:56 +00002583 scripts/config.py full_no_platform
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002584 scripts/config.py unset MBEDTLS_PLATFORM_C
2585 scripts/config.py unset MBEDTLS_NET_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002586 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002587 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002588 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
2589 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Paul Elliott68050372023-11-03 19:24:56 +00002590 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +01002591 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
2592 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002593 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
2594 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01002595}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00002596
Gilles Peskine8f073122018-11-27 15:58:47 +01002597component_build_no_std_function () {
2598 # catch compile bugs in _uninit functions
2599 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002600 scripts/config.py full
2601 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
2602 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002603 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine31fdda12021-10-08 11:45:47 +02002604 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskine25319702021-10-07 19:34:57 +02002605 make
Gilles Peskine8f073122018-11-27 15:58:47 +01002606}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01002607
Gilles Peskine8f073122018-11-27 15:58:47 +01002608component_build_no_ssl_srv () {
2609 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002610 scripts/config.py full
2611 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002612 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002613}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002614
Gilles Peskine8f073122018-11-27 15:58:47 +01002615component_build_no_ssl_cli () {
2616 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002617 scripts/config.py full
2618 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002619 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002620}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002621
Gilles Peskine8f073122018-11-27 15:58:47 +01002622component_build_no_sockets () {
2623 # Note, C99 compliance can also be tested with the sockets support disabled,
2624 # as that requires a POSIX platform (which isn't the same as C99).
2625 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002626 scripts/config.py full
2627 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
2628 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002629 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01002630}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02002631
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002632component_test_memory_buffer_allocator_backtrace () {
2633 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002634 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2635 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2636 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
2637 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Dave Rodgman374b1882024-01-04 10:30:57 +00002638 cmake -DCMAKE_BUILD_TYPE:String=Release .
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002639 make
2640
2641 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
2642 make test
2643}
2644
2645component_test_memory_buffer_allocator () {
2646 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002647 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2648 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Dave Rodgman374b1882024-01-04 10:30:57 +00002649 cmake -DCMAKE_BUILD_TYPE:String=Release .
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002650 make
2651
2652 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2653 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002654
2655 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2656 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002657 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002658}
2659
Gilles Peskine8f073122018-11-27 15:58:47 +01002660component_test_no_max_fragment_length () {
2661 # Run max fragment length tests with MFL disabled
2662 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002663 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01002664 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2665 make
Hanno Becker5175ac62017-09-18 15:36:25 +01002666
Gilles Peskine8f073122018-11-27 15:58:47 +01002667 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002668 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01002669}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002670
Hanno Becker545ced42019-02-19 11:10:48 +00002671component_test_asan_remove_peer_certificate () {
2672 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002673 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00002674 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2675 make
2676
2677 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2678 make test
2679
2680 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002681 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002682
2683 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002684 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002685
2686 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002687 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002688}
2689
Gilles Peskine8f073122018-11-27 15:58:47 +01002690component_test_no_max_fragment_length_small_ssl_out_content_len () {
2691 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002692 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2693 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
2694 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01002695 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2696 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10002697
Gilles Peskine8f073122018-11-27 15:58:47 +01002698 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002699 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002700
2701 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002702 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002703}
Angus Grattonc4dd0732018-04-11 16:28:39 +10002704
Darryl Greenaad82f92019-12-02 10:53:11 +00002705component_test_variable_ssl_in_out_buffer_len () {
2706 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
2707 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2708 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2709 make
2710
2711 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2712 make test
2713
2714 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002715 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002716
2717 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002718 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002719}
2720
2721component_test_variable_ssl_in_out_buffer_len_CID () {
2722 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
2723 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2724 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
2725
2726 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2727 make
2728
2729 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
2730 make test
2731
2732 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002733 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002734
2735 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002736 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002737}
2738
2739component_test_variable_ssl_in_out_buffer_len_record_splitting () {
2740 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled (ASan build)"
2741 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2742 scripts/config.py set MBEDTLS_SSL_CBC_RECORD_SPLITTING
2743
2744 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2745 make
2746
2747 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING"
2748 make test
2749
2750 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002751 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002752
2753 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002754 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002755}
2756
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002757component_test_ssl_alloc_buffer_and_mfl () {
2758 msg "build: default config with memory buffer allocator and MFL extension"
2759 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2760 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2761 scripts/config.py set MBEDTLS_MEMORY_DEBUG
2762 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2763 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
Dave Rodgman374b1882024-01-04 10:30:57 +00002764 cmake -DCMAKE_BUILD_TYPE:String=Release .
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002765 make
2766
2767 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
2768 make test
2769
2770 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 +02002771 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002772}
2773
Gilles Peskine636c26a2020-03-04 20:46:15 +01002774component_test_when_no_ciphersuites_have_mac () {
2775 msg "build: when no ciphersuites have MAC"
2776 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
2777 scripts/config.py unset MBEDTLS_ARC4_C
2778 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2779 make
2780
2781 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
2782 make test
2783
2784 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002785 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01002786}
2787
Gilles Peskine8f073122018-11-27 15:58:47 +01002788component_test_null_entropy () {
2789 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002790 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
2791 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
2792 scripts/config.py set MBEDTLS_ENTROPY_C
2793 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002794 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002795 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
2796 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00002797 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01002798 make
Janos Follath06c54002016-06-09 13:57:40 +01002799
Gilles Peskine8f073122018-11-27 15:58:47 +01002800 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
2801 make test
2802}
Janos Follath06c54002016-06-09 13:57:40 +01002803
Raoul Strackxa4e86142020-06-15 17:03:13 +02002804component_test_no_date_time () {
2805 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
2806 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
Gilles Peskine31fdda12021-10-08 11:45:47 +02002807 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Raoul Strackxa4e86142020-06-15 17:03:13 +02002808 make
2809
2810 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
2811 make test
2812}
2813
Andrzej Kurekc890b222023-01-17 04:03:19 -05002814component_test_alt_timing() {
2815 msg "build: alternate timing implementation"
2816 scripts/config.py set MBEDTLS_TIMING_ALT
2817 make lib TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
2818
2819 msg "test: MBEDTLS_TIMING_ALT - test suites"
2820 make test TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
Andrzej Kurek3a261a42023-01-26 04:33:59 -05002821
2822 msg "selftest - MBEDTLS-TIMING_ALT"
2823 make programs TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../../tests/src/external_timing -I../tests/src/external_timing"
2824 programs/test/selftest
Andrzej Kurekc890b222023-01-17 04:03:19 -05002825}
2826
Gilles Peskine8f073122018-11-27 15:58:47 +01002827component_test_platform_calloc_macro () {
2828 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002829 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2830 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
2831 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01002832 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2833 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01002834
Gilles Peskine8f073122018-11-27 15:58:47 +01002835 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
2836 make test
2837}
Hanno Beckere5fecec2018-10-11 11:02:52 +01002838
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002839component_test_malloc_0_null () {
2840 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002841 scripts/config.py full
Gilles Peskine2e70f1c2023-07-20 19:00:15 +02002842 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 +02002843
2844 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
2845 make test
2846
2847 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
2848 # Just the calloc selftest. "make test" ran the others as part of the
2849 # test suites.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002850 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01002851
2852 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
2853 # Run a subset of the tests. The choice is a balance between coverage
2854 # and time (including time indirectly wasted due to flaky tests).
2855 # The current choice is to skip tests whose description includes
2856 # "proxy", which is an approximation of skipping tests that use the
2857 # UDP proxy, which tend to be slower and flakier.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002858 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002859}
2860
Gilles Peskine8f073122018-11-27 15:58:47 +01002861component_test_aes_fewer_tables () {
2862 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002863 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Dave Rodgmance04f242024-01-04 10:34:31 +00002864 make CFLAGS='-O2 -Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002865
Gilles Peskine8f073122018-11-27 15:58:47 +01002866 msg "test: AES_FEWER_TABLES"
2867 make test
2868}
Hanno Becker83ebf782017-07-07 12:29:15 +01002869
Gilles Peskine8f073122018-11-27 15:58:47 +01002870component_test_aes_rom_tables () {
2871 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002872 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Dave Rodgmance04f242024-01-04 10:34:31 +00002873 make CFLAGS='-O2 -Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002874
Gilles Peskine8f073122018-11-27 15:58:47 +01002875 msg "test: AES_ROM_TABLES"
2876 make test
2877}
Hanno Becker83ebf782017-07-07 12:29:15 +01002878
Gilles Peskine8f073122018-11-27 15:58:47 +01002879component_test_aes_fewer_tables_and_rom_tables () {
2880 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002881 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2882 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Dave Rodgmance04f242024-01-04 10:34:31 +00002883 make CFLAGS='-O2 -Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002884
Gilles Peskine8f073122018-11-27 15:58:47 +01002885 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2886 make test
2887}
2888
Gilles Peskine592f5912019-10-07 18:49:32 +02002889component_test_ctr_drbg_aes_256_sha_256 () {
2890 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002891 scripts/config.py full
2892 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2893 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002894 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2895 make
2896
2897 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2898 make test
2899}
2900
2901component_test_ctr_drbg_aes_128_sha_512 () {
2902 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002903 scripts/config.py full
2904 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2905 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02002906 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2907 make
2908
2909 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2910 make test
2911}
2912
2913component_test_ctr_drbg_aes_128_sha_256 () {
2914 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002915 scripts/config.py full
2916 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2917 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2918 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002919 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2920 make
2921
2922 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2923 make test
2924}
2925
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002926component_test_se_default () {
2927 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002928 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02002929 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002930
2931 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2932 make test
2933}
2934
Steven Cooremand57203d2020-07-16 20:28:59 +02002935component_test_psa_crypto_drivers () {
Gilles Peskine8d77ec22023-07-26 18:45:20 +02002936 msg "build: full + test drivers dispatching to builtins"
Steven Cooreman753f9732021-03-15 11:38:44 +01002937 scripts/config.py full
Steven Cooremand57203d2020-07-16 20:28:59 +02002938 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
Gilles Peskinefe0acc62021-09-20 19:20:04 +02002939 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
2940 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002941 loc_cflags="${loc_cflags} -I../tests/include -O2"
2942
2943 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002944
Gilles Peskine8d77ec22023-07-26 18:45:20 +02002945 msg "test: full + test drivers dispatching to builtins"
Steven Cooremand57203d2020-07-16 20:28:59 +02002946 make test
2947}
2948
Gilles Peskine8f073122018-11-27 15:58:47 +01002949component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002950 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002951 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02002952 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine27482f12021-11-04 12:52:14 +01002953 programs/test/dlopen_demo.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002954}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02002955
Gilles Peskinecf740502019-07-03 20:43:05 +02002956component_test_cmake_shared () {
2957 msg "build/test: cmake shared" # ~ 2min
2958 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
2959 make
Gilles Peskine56c01612019-07-03 20:43:32 +02002960 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02002961 make test
Gilles Peskine27482f12021-11-04 12:52:14 +01002962 programs/test/dlopen_demo.sh
Gilles Peskinecf740502019-07-03 20:43:05 +02002963}
2964
Gilles Peskineec10bf12019-09-20 19:56:06 +02002965test_build_opt () {
2966 info=$1 cc=$2; shift 2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002967 $cc --version
Gilles Peskineec10bf12019-09-20 19:56:06 +02002968 for opt in "$@"; do
2969 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskinee094a182020-04-14 20:08:41 +02002970 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02002971 # We're confident enough in compilers to not run _all_ the tests,
2972 # but at least run the unit tests. In particular, runs with
2973 # optimizations use inline assembly whereas runs with -O0
2974 # skip inline assembly.
2975 make test # ~30s
2976 make clean
2977 done
2978}
2979
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002980# For FreeBSD we invoke the function by name so this condition is added
2981# to disable the existing test_clang_opt function for linux.
2982if [[ $(uname) != "Linux" ]]; then
2983 component_test_clang_opt () {
2984 scripts/config.py full
2985 test_build_opt 'full config' clang -O0 -Os -O2
2986 }
2987fi
2988
2989component_test_clang_latest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002990 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002991 test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002992}
2993support_test_clang_latest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002994 type "$CLANG_LATEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02002995}
2996
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002997component_test_clang_earliest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002998 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002999 test_build_opt 'full config' "$CLANG_EARLIEST" -O0
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003000}
3001support_test_clang_earliest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003002 type "$CLANG_EARLIEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003003}
3004
3005component_test_gcc_latest_opt () {
3006 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003007 test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003008}
3009support_test_gcc_latest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003010 type "$GCC_LATEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003011}
3012
3013component_test_gcc_earliest_opt () {
3014 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003015 test_build_opt 'full config' "$GCC_EARLIEST" -O0
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003016}
3017support_test_gcc_earliest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003018 type "$GCC_EARLIEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02003019}
3020
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02003021component_build_mbedtls_config_file () {
3022 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
Gilles Peskine6af9dc92022-04-07 20:55:57 +02003023 scripts/config.py -w full_config.h full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02003024 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
3025 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02003026 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine036a9bb2022-04-07 21:06:41 +02003027 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3028 make clean
3029
3030 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
3031 # In the user config, disable one feature (for simplicity, pick a feature
3032 # that nothing else depends on).
3033 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3034 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
3035 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3036
3037 rm -f user_config.h full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003038}
3039
Gilles Peskine690a2ef2022-04-07 21:59:14 +02003040component_build_psa_config_file () {
3041 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
3042 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3043 cp "$CRYPTO_CONFIG_H" psa_test_config.h
3044 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
3045 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02003046 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine690a2ef2022-04-07 21:59:14 +02003047 programs/test/query_compile_time_config MBEDTLS_CMAC_C
3048 make clean
3049
3050 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
3051 # In the user config, disable one feature, which will reflect on the
3052 # mbedtls configuration so we can query it with query_compile_time_config.
3053 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
3054 scripts/config.py unset MBEDTLS_CMAC_C
3055 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
3056 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
3057
3058 rm -f psa_test_config.h psa_user_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003059}
3060
Gilles Peskine8f073122018-11-27 15:58:47 +01003061component_test_m32_o0 () {
Gilles Peskinea0c51fb2021-10-07 19:27:16 +02003062 # Build without optimization, so as to use portable C code (in a 32-bit
3063 # build) and not the i386-specific inline assembly.
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003064 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003065 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02003066 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01003067
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003068 msg "test: i386, make, gcc -O0 (ASan build)"
3069 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01003070}
Gilles Peskine878cf602019-01-06 20:50:38 +00003071support_test_m32_o0 () {
3072 case $(uname -m) in
Pengyu Lva89b3672022-10-21 10:50:26 +00003073 amd64|x86_64) true;;
Gilles Peskine878cf602019-01-06 20:50:38 +00003074 *) false;;
3075 esac
3076}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003077
Gilles Peskine6fa69862021-10-05 09:36:03 +02003078component_test_m32_o2 () {
3079 # Build with optimization, to use the i386 specific inline assembly
3080 # and go faster for tests.
3081 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003082 scripts/config.py full
Gilles Peskine6fa69862021-10-05 09:36:03 +02003083 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003084
Gilles Peskine6fa69862021-10-05 09:36:03 +02003085 msg "test: i386, make, gcc -O2 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003086 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003087
Gilles Peskine6fa69862021-10-05 09:36:03 +02003088 msg "test ssl-opt.sh, i386, make, gcc-O2"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003089 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003090}
Gilles Peskine3daa83e2021-10-07 19:25:29 +02003091support_test_m32_o2 () {
Gilles Peskine878cf602019-01-06 20:50:38 +00003092 support_test_m32_o0 "$@"
3093}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003094
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003095component_test_m32_everest () {
3096 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003097 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
3098 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02003099 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003100
3101 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
3102 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003103
3104 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003105 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01003106
3107 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
3108 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003109 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003110}
3111support_test_m32_everest () {
3112 support_test_m32_o0 "$@"
3113}
3114
Gilles Peskine8f073122018-11-27 15:58:47 +01003115component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003116 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003117 scripts/config.py full
Dave Rodgmance04f242024-01-04 10:34:31 +00003118 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003119
3120 msg "test: 64-bit ILP32, make, gcc"
3121 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01003122}
Gilles Peskine878cf602019-01-06 20:50:38 +00003123support_test_mx32 () {
3124 case $(uname -m) in
3125 amd64|x86_64) true;;
3126 *) false;;
3127 esac
3128}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003129
Peter Kolbus60c6da22018-12-27 06:59:04 -06003130component_test_min_mpi_window_size () {
3131 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003132 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06003133 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3134 make
3135
3136 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
3137 make test
3138}
3139
Gilles Peskine8f073122018-11-27 15:58:47 +01003140component_test_have_int32 () {
3141 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003142 scripts/config.py unset MBEDTLS_HAVE_ASM
3143 scripts/config.py unset MBEDTLS_AESNI_C
3144 scripts/config.py unset MBEDTLS_PADLOCK_C
Dave Rodgmance04f242024-01-04 10:34:31 +00003145 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01003146
Gilles Peskine8f073122018-11-27 15:58:47 +01003147 msg "test: gcc, force 32-bit bignum limbs"
3148 make test
3149}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01003150
Gilles Peskine8f073122018-11-27 15:58:47 +01003151component_test_have_int64 () {
3152 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003153 scripts/config.py unset MBEDTLS_HAVE_ASM
3154 scripts/config.py unset MBEDTLS_AESNI_C
3155 scripts/config.py unset MBEDTLS_PADLOCK_C
Dave Rodgmance04f242024-01-04 10:34:31 +00003156 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01003157
Gilles Peskine8f073122018-11-27 15:58:47 +01003158 msg "test: gcc, force 64-bit bignum limbs"
3159 make test
3160}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003161
Gilles Peskine8f073122018-11-27 15:58:47 +01003162component_test_no_udbl_division () {
3163 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003164 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003165 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01003166 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003167
Gilles Peskine8f073122018-11-27 15:58:47 +01003168 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
3169 make test
3170}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003171
Gilles Peskine8f073122018-11-27 15:58:47 +01003172component_test_no_64bit_multiplication () {
3173 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003174 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003175 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01003176 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003177
Gilles Peskine8f073122018-11-27 15:58:47 +01003178 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
3179 make test
3180}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003181
Gilles Peskine3809f5f2020-11-09 15:40:05 +01003182component_test_no_strings () {
3183 msg "build: no strings" # ~10s
3184 scripts/config.py full
3185 # Disable options that activate a large amount of string constants.
3186 scripts/config.py unset MBEDTLS_DEBUG_C
3187 scripts/config.py unset MBEDTLS_ERROR_C
3188 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
3189 scripts/config.py unset MBEDTLS_VERSION_FEATURES
3190 make CFLAGS='-Werror -Os'
3191
3192 msg "test: no strings" # ~ 10s
3193 make test
3194}
3195
Gilles Peskine8f073122018-11-27 15:58:47 +01003196component_build_arm_none_eabi_gcc () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003197 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003198 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02003199 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 +02003200
Gilles Peskine60d99472021-09-01 20:00:33 +02003201 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003202 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003203}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003204
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003205component_build_arm_linux_gnueabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003206 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003207 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02003208 # Build for a target platform that's close to what Debian uses
3209 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
Dave Rodgman52af7692022-03-31 14:27:24 +01003210 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003211 # Build everything including programs, see for example
Dave Rodgman52af7692022-03-31 14:27:24 +01003212 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003213 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'
3214
Gilles Peskine60d99472021-09-01 20:00:33 +02003215 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003216 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size library/*.o
3217}
3218support_build_arm_linux_gnueabi_gcc_arm5vte () {
3219 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
3220}
3221
3222component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003223 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003224 scripts/config.py baremetal
3225 # This is an imperfect substitute for
3226 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnard9a260a62021-07-06 09:44:59 +02003227 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02003228 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 +02003229
Gilles Peskine60d99472021-09-01 20:00:33 +02003230 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003231 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02003232}
3233
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003234component_build_arm_none_eabi_gcc_m0plus () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003235 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
3236 scripts/config.py baremetal_size
Gilles Peskineaeedd742020-09-02 11:03:04 +02003237 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 +02003238
Gilles Peskine60d99472021-09-01 20:00:33 +02003239 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
Gilles Peskine18487f62020-04-30 23:11:54 +02003240 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003241}
3242
Gilles Peskine8f073122018-11-27 15:58:47 +01003243component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003244 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003245 scripts/config.py baremetal
3246 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003247 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 +01003248 echo "Checking that software 64-bit division is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003249 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003250}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003251
Gilles Peskine8f073122018-11-27 15:58:47 +01003252component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003253 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003254 scripts/config.py baremetal
3255 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003256 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 +01003257 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003258 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003259}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003260
Dave Rodgman43ea9ab2023-06-02 10:26:24 -04003261component_build_arm_clang_thumb () {
3262 # ~ 30s
3263
3264 scripts/config.py baremetal
3265
3266 msg "build: clang thumb 2, make"
3267 make clean
3268 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
3269
3270 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
3271 msg "build: clang thumb 1 -O0, make"
3272 make clean
3273 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
3274
3275 msg "build: clang thumb 1 -Os, make"
3276 make clean
3277 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
3278}
3279
Gilles Peskine8f073122018-11-27 15:58:47 +01003280component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02003281 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003282 scripts/config.py baremetal
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003283 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02003284
3285 msg "size: ARM Compiler 5"
3286 "$ARMC5_FROMELF" -z library/*.o
3287
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003288 make clean
Andres AG87bb5772016-09-27 15:05:15 +01003289
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003290 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
3291
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003292 # ARM Compiler 6 - Target ARMv7-A
3293 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003294
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003295 # ARM Compiler 6 - Target ARMv7-M
3296 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02003297
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003298 # ARM Compiler 6 - Target ARMv8-A - AArch32
3299 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003300
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003301 # ARM Compiler 6 - Target ARMv8-M
3302 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02003303
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003304 # ARM Compiler 6 - Target ARMv8-A - AArch64
3305 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003306
3307 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
3308 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
3309
3310 # ARM Compiler 6 - Target Cortex-M0
3311 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
Gilles Peskine8f073122018-11-27 15:58:47 +01003312}
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003313
Pengyu Lvd216c042023-03-03 18:23:35 +08003314support_build_armcc () {
3315 armc5_cc="$ARMC5_BIN_DIR/armcc"
3316 armc6_cc="$ARMC6_BIN_DIR/armclang"
3317 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
3318}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01003319
Manuel Pégourié-Gonnarddd8807f2020-02-26 09:56:27 +01003320component_build_ssl_hw_record_accel() {
3321 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
3322 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
3323 make CFLAGS='-Werror -O1'
3324}
3325
Hanno Beckera711f6e2020-05-04 12:03:51 +01003326component_test_tls13_experimental () {
3327 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3328 scripts/config.pl set MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
3329 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3330 make
3331 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3332 make test
3333}
3334
Gilles Peskine8f073122018-11-27 15:58:47 +01003335component_build_mingw () {
3336 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003337 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 +00003338
Gilles Peskine8f073122018-11-27 15:58:47 +01003339 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003340 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 +01003341 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02003342
Gilles Peskine8f073122018-11-27 15:58:47 +01003343 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003344 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
3345 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 +01003346 make WINDOWS_BUILD=1 clean
Pengyu Lvb2ca0322023-10-19 17:17:19 +08003347
3348 msg "build: Windows cross build - mingw64, make (Library only, AESNI intrinsics)" # ~ 30s
3349 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 +08003350 make WINDOWS_BUILD=1 clean
3351
3352 msg "build: Windows cross build - mingw64, make (Library only, default config without MBEDTLS_AESNI_C)" # ~ 30s
3353 ./scripts/config.py unset MBEDTLS_AESNI_C
3354 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib
3355 make WINDOWS_BUILD=1 clean
Pengyu Lvb2ca0322023-10-19 17:17:19 +08003356 }
Jaeden Amero117b8a42019-04-17 15:19:26 +01003357support_build_mingw() {
Pengyu Lva19ce122023-02-24 15:38:52 +08003358 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
3359 [0-5]*|"") false;;
Jaeden Amero117b8a42019-04-17 15:19:26 +01003360 *) true;;
3361 esac
3362}
Simon Butcher91aef332016-11-17 09:20:50 +00003363
Gilles Peskine8f073122018-11-27 15:58:47 +01003364component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003365 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003366 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003367 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
3368 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02003369
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003370 msg "test: main suites (MSan)" # ~ 10s
3371 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003372
Gilles Peskineee8af062023-11-02 19:58:03 +01003373 msg "test: metatests (MSan)"
3374 tests/scripts/run-metatests.sh any msan
3375
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02003376 msg "program demos (MSan)" # ~20s
3377 tests/scripts/run_demos.py
3378
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003379 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003380 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003381
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003382 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003383
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003384 if [ "$MEMORY" -gt 0 ]; then
3385 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003386 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003387 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003388}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003389
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01003390component_release_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003391 msg "build: Release (clang)"
Gilles Peskine619b73d2022-11-29 16:45:30 +01003392 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003393 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3394 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003395
Gilles Peskine619b73d2022-11-29 16:45:30 +01003396 msg "test: main suites, Valgrind (default config)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003397 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003398
Gilles Peskine636c26a2020-03-04 20:46:15 +01003399 # Optional parts (slow; currently broken on OS X because programs don't
3400 # seem to receive signals under valgrind on OS X).
Gilles Peskine619b73d2022-11-29 16:45:30 +01003401 # These optional parts don't run on the CI.
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003402 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003403 msg "test: ssl-opt.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003404 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003405 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003406
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003407 if [ "$MEMORY" -gt 1 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003408 msg "test: compat.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003409 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003410 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003411
3412 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003413 msg "test: context-info.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003414 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003415 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003416}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003417
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01003418component_release_test_valgrind_psa () {
Gilles Peskine619b73d2022-11-29 16:45:30 +01003419 msg "build: Release, full (clang)"
3420 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
3421 scripts/config.py full
3422 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3423 make
3424
3425 msg "test: main suites, Valgrind (full config)"
3426 make memcheck
3427}
3428
Paul Elliott2ab9a7a2021-11-25 17:29:40 +00003429support_test_cmake_out_of_source () {
3430 distrib_id=""
3431 distrib_ver=""
3432 distrib_ver_minor=""
3433 distrib_ver_major=""
3434
3435 # Attempt to parse lsb-release to find out distribution and version. If not
3436 # found this should fail safe (test is supported).
3437 if [[ -f /etc/lsb-release ]]; then
3438
3439 while read -r lsb_line; do
3440 case "$lsb_line" in
3441 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
3442 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
3443 esac
3444 done < /etc/lsb-release
3445
3446 distrib_ver_major="${distrib_ver%%.*}"
3447 distrib_ver="${distrib_ver#*.}"
3448 distrib_ver_minor="${distrib_ver%%.*}"
3449 fi
3450
3451 # Running the out of source CMake test on Ubuntu 16.04 using more than one
3452 # processor (as the CI does) can create a race condition whereby the build
3453 # fails to see a generated file, despite that file actually having been
3454 # generated. This problem appears to go away with 18.04 or newer, so make
3455 # the out of source tests unsupported on Ubuntu 16.04.
3456 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
3457}
3458
Gilles Peskine8f073122018-11-27 15:58:47 +01003459component_test_cmake_out_of_source () {
3460 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01003461 MBEDTLS_ROOT_DIR="$PWD"
3462 mkdir "$OUT_OF_SOURCE_DIR"
3463 cd "$OUT_OF_SOURCE_DIR"
Gilles Peskine25319702021-10-07 19:34:57 +02003464 cmake -D CMAKE_BUILD_TYPE:String=Check "$MBEDTLS_ROOT_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003465 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003466
Gilles Peskine8f073122018-11-27 15:58:47 +01003467 msg "test: cmake 'out-of-source' build"
3468 make test
3469 # Test an SSL option that requires an auxiliary script in test/scripts/.
3470 # Also ensure that there are no error messages such as
3471 # "No such file or directory", which would indicate that some required
3472 # file is missing (ssl-opt.sh tolerates the absence of some files so
3473 # may exit with status 0 but emit errors).
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003474 ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' >ssl-opt.out 2>ssl-opt.err
3475 grep PASS ssl-opt.out
Gilles Peskine0a7984f2020-03-28 18:56:09 +01003476 cat ssl-opt.err >&2
3477 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003478 [ ! -s ssl-opt.err ]
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003479 rm ssl-opt.out ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01003480 cd "$MBEDTLS_ROOT_DIR"
3481 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003482}
Andres AGdc192212016-08-31 17:33:13 +01003483
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003484component_test_cmake_as_subdirectory () {
3485 msg "build: cmake 'as-subdirectory' build"
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003486 cd programs/test/cmake_subproject
3487 cmake .
3488 make
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003489 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003490}
Gilles Peskineca9cfca2022-02-04 00:21:12 +01003491support_test_cmake_as_subdirectory () {
3492 support_test_cmake_out_of_source
3493}
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003494
David Horstmann175afbd2023-01-12 14:17:01 +00003495component_build_cmake_custom_config_file () {
David Horstmann67622312023-01-31 10:34:44 +00003496 # Make a copy of config file to use for the in-tree test
3497 cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h
David Horstmann175afbd2023-01-12 14:17:01 +00003498
3499 MBEDTLS_ROOT_DIR="$PWD"
3500 mkdir "$OUT_OF_SOURCE_DIR"
3501 cd "$OUT_OF_SOURCE_DIR"
3502
David Horstmann67622312023-01-31 10:34:44 +00003503 # Build once to get the generated files (which need an intact config file)
David Horstmann175afbd2023-01-12 14:17:01 +00003504 cmake "$MBEDTLS_ROOT_DIR"
3505 make
3506
3507 msg "build: cmake with -DMBEDTLS_CONFIG_FILE"
3508 scripts/config.py -w full_config.h full
David Horstmann67622312023-01-31 10:34:44 +00003509 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003510 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR"
3511 make
3512
3513 msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
3514 # In the user config, disable one feature (for simplicity, pick a feature
3515 # that nothing else depends on).
3516 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3517
3518 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR"
3519 make
3520 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3521
3522 rm -f user_config.h full_config.h
3523
3524 cd "$MBEDTLS_ROOT_DIR"
3525 rm -rf "$OUT_OF_SOURCE_DIR"
3526
3527 # Now repeat the test for an in-tree build:
3528
David Horstmann67622312023-01-31 10:34:44 +00003529 # Restore config for the in-tree test
3530 mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003531
David Horstmann67622312023-01-31 10:34:44 +00003532 # Build once to get the generated files (which need an intact config)
David Horstmann175afbd2023-01-12 14:17:01 +00003533 cmake .
3534 make
3535
3536 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE"
3537 scripts/config.py -w full_config.h full
David Horstmann67622312023-01-31 10:34:44 +00003538 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003539 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h .
3540 make
3541
3542 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
3543 # In the user config, disable one feature (for simplicity, pick a feature
3544 # that nothing else depends on).
3545 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3546
3547 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h .
3548 make
3549 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3550
3551 rm -f user_config.h full_config.h
3552}
3553support_build_cmake_custom_config_file () {
3554 support_test_cmake_out_of_source
3555}
3556
3557
Tom Cosgrove51170622023-09-01 10:40:15 +01003558component_build_zeroize_checks () {
3559 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
3560
3561 scripts/config.py full
3562
3563 # Only compile - we're looking for sizeof-pointer-memaccess warnings
Dave Rodgman374b1882024-01-04 10:30:57 +00003564 make 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 +01003565}
3566
3567
Gilles Peskine8f073122018-11-27 15:58:47 +01003568component_test_zeroize () {
3569 # Test that the function mbedtls_platform_zeroize() is not optimized away by
3570 # different combinations of compilers and optimization flags by using an
3571 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
3572 # system in all cases that the script fails, so we must manually search the
3573 # output to check whether the pass string is present and no failure strings
3574 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01003575
Gilles Peskine4976e822019-01-06 19:52:22 +00003576 # Don't try to disable ASLR. We don't care about ASLR here. We do care
3577 # about a spurious message if Gdb tries and fails, so suppress that.
3578 gdb_disable_aslr=
3579 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
3580 gdb_disable_aslr='set disable-randomization off'
3581 fi
3582
Gilles Peskine8f073122018-11-27 15:58:47 +01003583 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01003584 for compiler in clang gcc; do
3585 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
3586 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003587 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
3588 grep "The buffer was correctly zeroized" test_zeroize.log
3589 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01003590 rm -f test_zeroize.log
3591 make clean
3592 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01003593 done
Gilles Peskine8f073122018-11-27 15:58:47 +01003594}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003595
Bence Szépkúti9f849112021-10-19 15:05:36 +02003596component_test_psa_compliance () {
Dave Rodgmanb0660c22023-12-18 19:55:40 +00003597 # The arch tests build with gcc, so require use of gcc here to link properly
Bence Szépkútic1e79fd2021-11-11 20:13:14 +01003598 msg "build: make, default config + CMAC, libmbedcrypto.a only"
3599 scripts/config.py set MBEDTLS_CMAC_C
Dave Rodgmanb0660c22023-12-18 19:55:40 +00003600 CC=gcc make -C library libmbedcrypto.a
Bence Szépkúti9f849112021-10-19 15:05:36 +02003601
3602 msg "unit test: test_psa_compliance.py"
Dave Rodgman5b00fb12023-12-18 22:29:56 +00003603 CC=gcc ./tests/scripts/test_psa_compliance.py
Bence Szépkúti9f849112021-10-19 15:05:36 +02003604}
3605
3606support_test_psa_compliance () {
Bence Szépkútid6cf0892021-11-03 11:36:09 +01003607 # psa-compliance-tests only supports CMake >= 3.10.0
Bence Szépkútiab796e62021-10-25 19:29:07 +02003608 ver="$(cmake --version)"
3609 ver="${ver#cmake version }"
3610 ver_major="${ver%%.*}"
3611
3612 ver="${ver#*.}"
3613 ver_minor="${ver%%.*}"
3614
3615 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
Bence Szépkúti9f849112021-10-19 15:05:36 +02003616}
3617
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003618component_check_code_style () {
3619 msg "Check C code style"
3620 ./scripts/code_style.py
David Horstmanne09c4762022-11-10 18:30:52 +00003621}
3622
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003623support_check_code_style() {
David Horstmanne09c4762022-11-10 18:30:52 +00003624 case $(uncrustify --version) in
3625 *0.75.1*) true;;
3626 *) false;;
3627 esac
3628}
3629
Gilles Peskine8f073122018-11-27 15:58:47 +01003630component_check_python_files () {
3631 msg "Lint: Python scripts"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003632 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003633}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003634
Gilles Peskine8f073122018-11-27 15:58:47 +01003635component_check_generate_test_code () {
3636 msg "uint test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02003637 # unittest writes out mundane stuff like number or tests run on stderr.
3638 # Our convention is to reserve stderr for actual errors, and write
3639 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003640 ./tests/scripts/test_generate_test_code.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01003641}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003642
3643################################################################
3644#### Termination
3645################################################################
3646
Gilles Peskine8f073122018-11-27 15:58:47 +01003647post_report () {
3648 msg "Done, cleaning up"
Gilles Peskine24bdf022020-03-30 20:11:39 +02003649 final_cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003650
Gilles Peskine8f073122018-11-27 15:58:47 +01003651 final_report
3652}
3653
3654
3655
3656################################################################
3657#### Run all the things
3658################################################################
3659
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003660# Function invoked by --error-test to test error reporting.
3661pseudo_component_error_test () {
Gilles Peskine202e9b42021-08-02 23:28:00 +02003662 msg "Testing error reporting $error_test_i"
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003663 if [ $KEEP_GOING -ne 0 ]; then
3664 echo "Expect three failing commands."
3665 fi
Gilles Peskine202e9b42021-08-02 23:28:00 +02003666 # If the component doesn't run in a subshell, changing error_test_i to an
3667 # invalid integer will cause an error in the loop that runs this function.
3668 error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003669 # Expected error: 'grep non_existent /dev/null -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003670 grep non_existent /dev/null
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003671 # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003672 not grep -q . "$0"
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003673 # Expected error: 'make unknown_target -> 2'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003674 make unknown_target
3675 false "this should not be executed"
3676}
3677
Gilles Peskinee48351a2018-11-27 16:06:30 +01003678# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01003679run_component () {
Gilles Peskineffcdeff2018-12-04 12:49:28 +01003680 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02003681 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003682
3683 # Unconditionally create a seedfile that's sufficiently long.
3684 # Do this before each component, because a previous component may
3685 # have messed it up or shortened it.
Gilles Peskinef3133362021-07-08 19:03:50 +02003686 local dd_cmd
3687 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
3688 case $OSTYPE in
3689 linux*|freebsd*|openbsd*|darwin*) dd_cmd+=(status=none)
3690 esac
3691 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003692
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003693 # Run the component in a subshell, with error trapping and output
3694 # redirection set up based on the relevant options.
Gilles Peskine7105a332020-03-28 18:50:43 +01003695 if [ $KEEP_GOING -eq 1 ]; then
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003696 # We want to keep running if the subshell fails, so 'set -e' must
3697 # be off when the subshell runs.
Gilles Peskine7105a332020-03-28 18:50:43 +01003698 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02003699 fi
Gilles Peskine7105a332020-03-28 18:50:43 +01003700 (
3701 if [ $QUIET -eq 1 ]; then
3702 # msg() will be silenced, so just print the component name here.
3703 echo "${current_component#component_}"
3704 exec >/dev/null
3705 fi
3706 if [ $KEEP_GOING -eq 1 ]; then
3707 # Keep "set -e" off, and run an ERR trap instead to record failures.
3708 set -E
3709 trap err_trap ERR
3710 fi
3711 # The next line is what runs the component
3712 "$@"
3713 if [ $KEEP_GOING -eq 1 ]; then
3714 trap - ERR
3715 exit $last_failure_status
3716 fi
3717 )
3718 component_status=$?
3719 if [ $KEEP_GOING -eq 1 ]; then
3720 set -e
3721 if [ $component_status -ne 0 ]; then
3722 failure_count=$((failure_count + 1))
3723 fi
3724 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003725
3726 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01003727 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02003728 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01003729}
3730
3731# Preliminary setup
3732pre_check_environment
3733pre_initialize_variables
3734pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01003735
Gilles Peskine878cf602019-01-06 20:50:38 +00003736pre_check_git
Gilles Peskineef64e7f2021-07-12 18:16:01 +02003737pre_restore_files
Gilles Peskine24bdf022020-03-30 20:11:39 +02003738pre_back_up
Andrzej Kurekeb508712019-02-14 07:18:59 -05003739
Gilles Peskine878cf602019-01-06 20:50:38 +00003740build_status=0
3741if [ $KEEP_GOING -eq 1 ]; then
3742 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01003743fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02003744pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00003745pre_print_configuration
3746pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003747cleanup
3748
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003749# Run the requested tests.
Gilles Peskine202e9b42021-08-02 23:28:00 +02003750for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003751 run_component pseudo_component_error_test
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003752done
Gilles Peskine202e9b42021-08-02 23:28:00 +02003753unset error_test_i
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003754for component in $RUN_COMPONENTS; do
3755 run_component "component_$component"
3756done
Gilles Peskine8f073122018-11-27 15:58:47 +01003757
3758# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00003759post_report