blob: 022e72f1eb9dab21974f05417be31bc8428a58a0 [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 () {
Dave Rodgmana0b7c082024-01-16 17:33:27 +0000127 special_options="--list-components|--list-all-components|-h|--help"
128 if [[ ! "$@" =~ $special_options ]]; then
129 # skip wrappers for "special options" which don't actually run any tests
130
131 # Pick up "quiet" wrappers for make and cmake, which don't output very much
132 # unless there is an error. This reduces logging overhead in the CI.
133 #
134 # Note that the cmake wrapper breaks unless we use an absolute path here.
135 export PATH=${PWD}/tests/scripts/quiet:$PATH
136 if [[ ! -x ${PWD}/tests/scripts/quiet/make ]]; then
137 echo "can't find quiet/make"
138 exit 1
139 fi
140 if [[ ! -x ${PWD}/tests/scripts/quiet/cmake ]]; then
141 echo "can't find quiet/cmake"
142 exit 1
143 fi
144 fi
145
Gilles Peskine8f073122018-11-27 15:58:47 +0100146 CONFIG_H='include/mbedtls/config.h'
John Durkopbd069d32020-10-31 22:14:03 -0700147 CRYPTO_CONFIG_H='include/psa/crypto_config.h'
Gilles Peskine24bdf022020-03-30 20:11:39 +0200148
149 # Files that are clobbered by some jobs will be backed up. Use a different
150 # suffix from auxiliary scripts so that all.sh and auxiliary scripts can
151 # independently decide when to remove the backup file.
152 backup_suffix='.all.bak'
153 # Files clobbered by config.py
154 files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H"
Gilles Peskineef64e7f2021-07-12 18:16:01 +0200155 # Files clobbered by in-tree cmake
156 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 +0200157
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200158 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100159 MEMORY=0
160 FORCE=0
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200161 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100162 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100163
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200164 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard54304472020-06-22 10:11:47 +0200165 #
166 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
167 # both values are kept in sync. If you change the value here because it
168 # breaks some tests, you'll definitely want to change it in
169 # basic-build-test.sh as well.
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200170 RELEASE_SEED=1
171
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200172 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200173 : ${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 +0200174 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200175 export MBEDTLS_TEST_PLATFORM
176
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000177 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100178 : ${OPENSSL:="openssl"}
179 : ${OPENSSL_LEGACY:="$OPENSSL"}
180 : ${OPENSSL_NEXT:="$OPENSSL"}
181 : ${GNUTLS_CLI:="gnutls-cli"}
182 : ${GNUTLS_SERV:="gnutls-serv"}
Gilles Peskine8f073122018-11-27 15:58:47 +0100183 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
184 : ${ARMC5_BIN_DIR:=/usr/bin}
185 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskine6d061342020-04-30 18:19:32 +0200186 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200187 : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
Gowtham Suresh Kumarcc029af2023-08-01 09:48:32 +0100188 : ${CLANG_LATEST:="clang-latest"}
189 : ${CLANG_EARLIEST:="clang-earliest"}
190 : ${GCC_LATEST:="gcc-latest"}
191 : ${GCC_EARLIEST:="gcc-earliest"}
Andres AGdc192212016-08-31 17:33:13 +0100192
Gilles Peskine8f073122018-11-27 15:58:47 +0100193 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000194 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine85229ac2021-09-30 18:24:21 +0200195 export MAKEFLAGS="-j$(all_sh_nproc)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100196 fi
Dave Rodgmane0a2f6d2023-12-18 19:53:25 +0000197 # if CC is not set, use clang by default (if present) to improve build times
198 if [ -z "${CC+set}" ] && (type clang > /dev/null 2>&1); then
Dave Rodgmane42c2352023-12-19 16:08:19 +0000199 export CC="clang"
Dave Rodgman62be4562023-12-18 18:34:50 +0000200 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000201
Gilles Peskinec761d8f2021-09-20 18:57:55 +0200202 # Include more verbose output for failing tests run by CMake or make
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000203 export CTEST_OUTPUT_ON_FAILURE=1
204
Gilles Peskine8fd59422019-10-21 17:11:33 +0200205 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Manuel Pégourié-Gonnard717f2302022-11-30 10:42:03 +0100206 # default to -O2, use -Ox _after_ this if you want another level
Manuel Pégourié-Gonnard154b84e2022-11-28 13:12:10 +0100207 ASAN_CFLAGS='-O2 -Werror -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200208
Andrzej Kurekd95b8ed2023-06-27 10:02:09 -0400209 # Platform tests have an allocation that returns null
210 export ASAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurek6e4a9be2023-07-05 08:32:43 -0400211 export MSAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurekd95b8ed2023-06-27 10:02:09 -0400212
Gilles Peskine878cf602019-01-06 20:50:38 +0000213 # Gather the list of available components. These are the functions
214 # defined in this script whose name starts with "component_".
Gowtham Suresh Kumar13850f32023-07-28 16:41:21 +0100215 ALL_COMPONENTS=$(compgen -A function component_ | sed 's/component_//')
Gilles Peskine878cf602019-01-06 20:50:38 +0000216
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100217 # Delay determinig SUPPORTED_COMPONENTS until the command line options have a chance to override
218 # the commands set by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100219}
Andres AG38495a32016-07-12 16:54:33 +0100220
Gilles Peskinea28db922019-01-10 00:05:18 +0100221# Test whether the component $1 is included in the command line patterns.
222is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100223{
Gilles Peskine6702ce92021-08-06 11:35:17 +0200224 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
225 # only does word splitting.
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100226 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000227 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100228 set +f
229 case ${1#component_} in $pattern) return 0;; esac
230 done
231 set +f
232 return 1
233}
Andres AG7770ea82016-10-10 15:46:20 +0100234
Simon Butcher41eeccf2016-09-07 00:07:09 +0100235usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100236{
Gilles Peskine709346a2017-12-10 23:43:39 +0100237 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100238Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100239Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100240By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100241COMPONENT can be the name of a component or a shell wildcard pattern.
242
243Examples:
244 $0 "check_*"
245 Run all sanity checks.
246 $0 --no-armcc --except test_memsan
247 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100248
249Special options:
250 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000251 --list-all-components List all available test components and exit.
252 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100253
254General options:
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200255 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100256 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100257 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100258 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200259 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200260 --arm-none-eabi-gcc-prefix=<string>
261 Prefix for a cross-compiler for arm-none-eabi
262 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200263 --arm-linux-gnueabi-gcc-prefix=<string>
264 Prefix for a cross-compiler for arm-linux-gnueabi
265 (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100266 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200267 --restore First clean up the build tree, restoring backed up
268 files. Do not run any components unless they are
269 explicitly specified.
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100270 --error-test Error test mode: run a failing function in addition
Gilles Peskinea25c5672021-08-05 15:11:33 +0200271 to any specified component. May be repeated.
Gilles Peskinea28db922019-01-10 00:05:18 +0100272 --except Exclude the COMPONENTs listed on the command line,
273 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200274 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100275 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100276 --no-force Refuse to overwrite modified files (default).
277 --no-keep-going Stop at the first error (default).
278 --no-memory No additional memory tests (default).
Shaun Case0e7791f2021-12-20 21:14:10 -0800279 --no-quiet Print full output from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100280 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200281 --outcome-file=<path> File where test outcomes are written (not done if
282 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100283 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200284 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100285 -s|--seed Integer seed value to use for this test run.
286
287Tool path options:
288 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
289 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100290 --clang-earliest=<Clang_earliest_path> Earliest version of clang available
291 --clang-latest=<Clang_latest_path> Latest version of clang available
292 --gcc-earliest=<GCC_earliest_path> Earliest version of GCC available
293 --gcc-latest=<GCC_latest_path> Latest version of GCC available
Gilles Peskine709346a2017-12-10 23:43:39 +0100294 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
295 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
Gilles Peskine709346a2017-12-10 23:43:39 +0100296 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
297 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100298 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100299EOF
SimonB2e23c822016-04-16 21:54:39 +0100300}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100301
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200302# Cleanup before/after running a component.
303# Remove built files as well as the cmake cache/config.
304# Does not remove generated source files.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100305cleanup()
306{
Gilles Peskine7c652162017-12-11 00:01:40 +0100307 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200308
Gilles Peskine31b07e22018-03-21 12:15:06 +0100309 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000310 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100311 -iname CMakeFiles -exec rm -rf {} \+ -o \
312 \( -iname cmake_install.cmake -o \
313 -iname CTestTestfile.cmake -o \
314 -iname CMakeCache.txt \) -exec rm {} \+
315 # Recover files overwritten by in-tree CMake builds
Gilles Peskine79598582022-08-30 21:02:44 +0200316 rm -f include/Makefile include/mbedtls/Makefile programs/!(fuzz)/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200317
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100318 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
319 rm -rf programs/test/cmake_subproject/build
320 rm -f programs/test/cmake_subproject/Makefile
321 rm -f programs/test/cmake_subproject/cmake_subproject
322
Gilles Peskine24bdf022020-03-30 20:11:39 +0200323 # Restore files that may have been clobbered by the job
324 for x in $files_to_back_up; do
Gilles Peskine423dd132022-08-30 21:02:00 +0200325 if [[ -e "$x$backup_suffix" ]]; then
326 cp -p "$x$backup_suffix" "$x"
327 fi
Gilles Peskine24bdf022020-03-30 20:11:39 +0200328 done
329}
John Durkopbd069d32020-10-31 22:14:03 -0700330
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200331# Final cleanup when this script exits (except when exiting on a failure
332# in non-keep-going mode).
Gilles Peskine24bdf022020-03-30 20:11:39 +0200333final_cleanup () {
334 cleanup
335
336 for x in $files_to_back_up; do
337 rm -f "$x$backup_suffix"
338 done
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100339}
340
Gilles Peskine7c652162017-12-11 00:01:40 +0100341# Executed on exit. May be redefined depending on command line options.
342final_report () {
343 :
344}
345
346fatal_signal () {
Gilles Peskine24bdf022020-03-30 20:11:39 +0200347 final_cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100348 final_report $1
349 trap - $1
350 kill -$1 $$
351}
352
353trap 'fatal_signal HUP' HUP
354trap 'fatal_signal INT' INT
355trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200356
Gilles Peskine85229ac2021-09-30 18:24:21 +0200357# Number of processors on this machine. Used as the default setting
358# for parallel make.
359all_sh_nproc ()
360{
361 {
362 nproc || # Linux
363 sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
364 sysctl -n hw.ncpu || # FreeBSD
365 echo 1
366 } 2>/dev/null
367}
368
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100369msg()
370{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100371 if [ -n "${current_component:-}" ]; then
372 current_section="${current_component#component_}: $1"
373 else
374 current_section="$1"
375 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200376
377 if [ $QUIET -eq 1 ]; then
378 return
379 fi
380
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100381 echo ""
382 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100383 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000384 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100385 echo "******************************************************************"
386}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100387
Gilles Peskine8f073122018-11-27 15:58:47 +0100388armc6_build_test()
389{
390 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100391
Gilles Peskine18487f62020-04-30 23:11:54 +0200392 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100393 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
Dave Rodgman6cda3d32023-03-02 13:39:04 +0000394 WARNING_CFLAGS='-Werror -xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200395
396 msg "size: ARM Compiler 6 ($FLAGS)"
397 "$ARMC6_FROMELF" -z library/*.o
398
Gilles Peskine8f073122018-11-27 15:58:47 +0100399 make clean
400}
Andres AGa5cd9732016-10-17 15:23:10 +0100401
Andres AGd9eba4b2016-08-26 14:42:14 +0100402err_msg()
403{
404 echo "$1" >&2
405}
406
407check_tools()
408{
409 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000410 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100411 err_msg "$TOOL not found!"
412 exit 1
413 fi
414 done
415}
416
Gilles Peskine8f073122018-11-27 15:58:47 +0100417pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000418 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100419 all_except=0
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100420 error_test=0
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100421 list_components=0
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200422 restore_first=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000423 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100424
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000425 # Note that legacy options are ignored instead of being omitted from this
426 # list of options, so invocations that worked with previous version of
427 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100428 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100429 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200430 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200431 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200432 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000433 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100434 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
435 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100436 --clang-earliest) shift; CLANG_EARLIEST="$1";;
437 --clang-latest) shift; CLANG_LATEST="$1";;
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100438 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000439 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100440 --force|-f) FORCE=1;;
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100441 --gcc-earliest) shift; GCC_EARLIEST="$1";;
442 --gcc-latest) shift; GCC_LATEST="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100443 --gnutls-cli) shift; GNUTLS_CLI="$1";;
Gilles Peskine549a9612023-08-27 21:39:21 +0200444 --gnutls-legacy-cli) shift;; # ignored for backward compatibility
445 --gnutls-legacy-serv) shift;; # ignored for backward compatibility
Gilles Peskine55f7c942019-01-09 22:28:21 +0100446 --gnutls-serv) shift; GNUTLS_SERV="$1";;
447 --help|-h) usage; exit;;
448 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000449 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100450 --list-components) list_components=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100451 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200452 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000453 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100454 --no-force) FORCE=0;;
455 --no-keep-going) KEEP_GOING=0;;
456 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200457 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100458 --openssl) shift; OPENSSL="$1";;
459 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
460 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200461 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100462 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200463 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100464 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200465 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200466 --restore) restore_first=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100467 --seed|-s) shift; SEED="$1";;
468 -*)
469 echo >&2 "Unknown option: $1"
470 echo >&2 "Run $0 --help for usage."
471 exit 120
472 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000473 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100474 esac
475 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100476 done
SimonB2e23c822016-04-16 21:54:39 +0100477
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100478 # Exclude components that are not supported on this platform.
479 SUPPORTED_COMPONENTS=
480 for component in $ALL_COMPONENTS; do
481 case $(type "support_$component" 2>&1) in
482 *' function'*)
483 if ! support_$component; then continue; fi;;
484 esac
485 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
486 done
487
488 if [ $list_components -eq 1 ]; then
489 printf '%s\n' $SUPPORTED_COMPONENTS
490 exit
491 fi
492
Gilles Peskinea28db922019-01-10 00:05:18 +0100493 # With no list of components, run everything.
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200494 if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000495 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100496 fi
497
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000498 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
499 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100500 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000501 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100502 fi
SimonB2e23c822016-04-16 21:54:39 +0100503
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200504 # Error out if an explicitly requested component doesn't exist.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100505 if [ $all_except -eq 0 ]; then
506 unsupported=0
Gilles Peskine6702ce92021-08-06 11:35:17 +0200507 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
508 # only does word splitting.
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200509 set -f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100510 for component in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200511 set +f
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200512 # If the requested name includes a wildcard character, don't
513 # check it. Accept wildcard patterns that don't match anything.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100514 case $component in
515 *[*?\[]*) continue;;
516 esac
517 case " $SUPPORTED_COMPONENTS " in
518 *" $component "*) :;;
519 *)
520 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
521 unsupported=$((unsupported + 1));;
522 esac
523 done
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200524 set +f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100525 if [ $unsupported -ne 0 ]; then
526 exit 2
527 fi
528 fi
529
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000530 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100531 RUN_COMPONENTS=
532 for component in $SUPPORTED_COMPONENTS; do
533 if is_component_included "$component"; [ $? -eq $all_except ]; then
534 RUN_COMPONENTS="$RUN_COMPONENTS $component"
535 fi
536 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000537
538 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000539 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100540}
SimonB2e23c822016-04-16 21:54:39 +0100541
Gilles Peskine8f073122018-11-27 15:58:47 +0100542pre_check_git () {
543 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100544 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100545 git checkout-index -f -q $CONFIG_H
546 cleanup
547 else
SimonB2e23c822016-04-16 21:54:39 +0100548
Gilles Peskine8f073122018-11-27 15:58:47 +0100549 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
550 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
551 echo "You can either delete this directory manually, or force the test by rerunning"
552 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
553 exit 1
554 fi
555
Gilles Peskined1174cf2019-01-09 22:30:01 +0100556 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100557 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
558 echo "You can either delete or preserve your work, or force the test by rerunning the"
559 echo "script as: $0 --force"
560 exit 1
561 fi
SimonB2e23c822016-04-16 21:54:39 +0100562 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500563}
564
Gilles Peskineef64e7f2021-07-12 18:16:01 +0200565pre_restore_files () {
566 # If the makefiles have been generated by a framework such as cmake,
567 # restore them from git. If the makefiles look like modifications from
568 # the ones checked into git, take care not to modify them. Whatever
569 # this function leaves behind is what the script will restore before
570 # each component.
571 case "$(head -n1 Makefile)" in
572 *[Gg]enerated*)
573 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
574 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
575 ;;
576 esac
577}
578
Gilles Peskine24bdf022020-03-30 20:11:39 +0200579pre_back_up () {
580 for x in $files_to_back_up; do
581 cp -p "$x" "$x$backup_suffix"
582 done
583}
584
Gilles Peskine8f073122018-11-27 15:58:47 +0100585pre_setup_keep_going () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100586 failure_count=0 # Number of failed components
587 last_failure_status=0 # Last failure status in this component
588
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100589 # See err_trap
590 previous_failure_status=0
591 previous_failed_command=
592 previous_failure_funcall_depth=0
Gilles Peskine39a3b112020-03-28 21:27:40 +0100593 unset report_failed_command
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100594
Gilles Peskine7c652162017-12-11 00:01:40 +0100595 start_red=
596 end_color=
597 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100598 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100599 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
600 start_red=$(printf '\033[31m')
601 end_color=$(printf '\033[0m')
602 ;;
603 esac
604 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100605
606 # Keep a summary of failures in a file. We'll print it out at the end.
607 failure_summary_file=$PWD/all-sh-failures-$$.log
608 : >"$failure_summary_file"
609
610 # Whether it makes sense to keep a component going after the specified
611 # command fails (test command) or not (configure or build).
Gilles Peskine6702ce92021-08-06 11:35:17 +0200612 # This function normally receives the failing simple command
613 # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
614 # this is passed instead.
Gilles Peskine7105a332020-03-28 18:50:43 +0100615 # This doesn't have to be 100% accurate: all failures are recorded anyway.
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200616 # False positives result in running things that can't be expected to
617 # work. False negatives result in things not running after something else
618 # failed even though they might have given useful feedback.
Gilles Peskine7105a332020-03-28 18:50:43 +0100619 can_keep_going_after_failure () {
620 case "$1" in
621 "msg "*) false;;
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200622 "cd "*) false;;
623 *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
624 *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
625 *make*check*) true;;
626 "grep "*) true;;
627 "[ "*) true;;
628 "! "*) true;;
Gilles Peskine7105a332020-03-28 18:50:43 +0100629 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100630 esac
631 }
Gilles Peskine7105a332020-03-28 18:50:43 +0100632
633 # This function runs if there is any error in a component.
634 # It must either exit with a nonzero status, or set
635 # last_failure_status to a nonzero value.
636 err_trap () {
637 # Save $? (status of the failing command). This must be the very
638 # first thing, before $? is overridden.
639 last_failure_status=$?
Gilles Peskine39a3b112020-03-28 21:27:40 +0100640 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskine7105a332020-03-28 18:50:43 +0100641
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100642 if [[ $last_failure_status -eq $previous_failure_status &&
643 "$failed_command" == "$previous_failed_command" &&
644 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
645 then
646 # The same command failed twice in a row, but this time one level
647 # less deep in the function call stack. This happens when the last
648 # command of a function returns a nonzero status, and the function
649 # returns that same status. Ignore the second failure.
650 previous_failure_funcall_depth=${#FUNCNAME[@]}
651 return
652 fi
653 previous_failure_status=$last_failure_status
654 previous_failed_command=$failed_command
655 previous_failure_funcall_depth=${#FUNCNAME[@]}
656
Gilles Peskine7105a332020-03-28 18:50:43 +0100657 text="$current_section: $failed_command -> $last_failure_status"
658 echo "${start_red}^^^^$text^^^^${end_color}" >&2
659 echo "$text" >>"$failure_summary_file"
660
661 # If the command is fatal (configure or build command), stop this
662 # component. Otherwise (test command) keep the component running
663 # (run more tests from the same build).
664 if ! can_keep_going_after_failure "$failed_command"; then
665 exit $last_failure_status
666 fi
667 }
668
Gilles Peskine7c652162017-12-11 00:01:40 +0100669 final_report () {
670 if [ $failure_count -gt 0 ]; then
671 echo
672 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskine7105a332020-03-28 18:50:43 +0100673 echo "${start_red}FAILED: $failure_count components${end_color}"
674 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100675 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
676 elif [ -z "${1-}" ]; then
677 echo "SUCCESS :)"
678 fi
679 if [ -n "${1-}" ]; then
680 echo "Killed by SIG$1."
681 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100682 rm -f "$failure_summary_file"
683 if [ $failure_count -gt 0 ]; then
684 exit 1
685 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100686 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100687}
688
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200689# record_status() and if_build_succeeded() are kept temporarily for backward
690# compatibility. Don't use them in new components.
Gilles Peskine7105a332020-03-28 18:50:43 +0100691record_status () {
692 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100693}
Gilles Peskine7c652162017-12-11 00:01:40 +0100694if_build_succeeded () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100695 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100696}
697
Gilles Peskine39a3b112020-03-28 21:27:40 +0100698# '! true' does not trigger the ERR trap. Arrange to trigger it, with
699# a reasonably informative error message (not just "$@").
700not () {
701 if "$@"; then
702 report_failed_command="! $*"
703 false
704 unset report_failed_command
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200705 fi
706}
707
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200708pre_prepare_outcome_file () {
709 case "$MBEDTLS_TEST_OUTCOME_FILE" in
710 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
711 esac
712 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
713 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
714 fi
715}
716
Gilles Peskine8f073122018-11-27 15:58:47 +0100717pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200718 if [ $QUIET -eq 1 ]; then
719 return
720 fi
721
Gilles Peskine8f073122018-11-27 15:58:47 +0100722 msg "info: $0 configuration"
723 echo "MEMORY: $MEMORY"
724 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200725 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100726 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100727 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100728 echo "OPENSSL: $OPENSSL"
729 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
730 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
731 echo "GNUTLS_CLI: $GNUTLS_CLI"
732 echo "GNUTLS_SERV: $GNUTLS_SERV"
Gilles Peskine8f073122018-11-27 15:58:47 +0100733 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
734 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
735}
Andres AG7770ea82016-10-10 15:46:20 +0100736
Andres AGd9eba4b2016-08-26 14:42:14 +0100737# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100738pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000739 # Build the list of variables to pass to output_env.sh.
740 set env
SimonB2e23c822016-04-16 21:54:39 +0100741
Gilles Peskine87964262019-01-06 22:40:00 +0000742 case " $RUN_COMPONENTS " in
743 # Require OpenSSL and GnuTLS if running any tests (as opposed to
744 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
745 # is a good enough approximation in practice.
Bence Szépkúticb89fbd2023-12-15 20:58:15 +0100746 *" test_"* | *" release_test_"*)
Gilles Peskine87964262019-01-06 22:40:00 +0000747 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
748 # and ssl-opt.sh, we just export the variables they require.
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +0100749 export OPENSSL="$OPENSSL"
Gilles Peskine87964262019-01-06 22:40:00 +0000750 export GNUTLS_CLI="$GNUTLS_CLI"
751 export GNUTLS_SERV="$GNUTLS_SERV"
752 # Avoid passing --seed flag in every call to ssl-opt.sh
753 if [ -n "${SEED-}" ]; then
754 export SEED
755 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000756 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
757 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000758 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
Gilles Peskine549a9612023-08-27 21:39:21 +0200759 "$GNUTLS_CLI" "$GNUTLS_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000760 ;;
761 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200762
Gilles Peskine87964262019-01-06 22:40:00 +0000763 case " $RUN_COMPONENTS " in
764 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
765 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100766
Gilles Peskine87964262019-01-06 22:40:00 +0000767 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200768 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000769 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100770
Gilles Peskine87964262019-01-06 22:40:00 +0000771 case " $RUN_COMPONENTS " in
772 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
773 esac
774
775 case " $RUN_COMPONENTS " in
776 *" test_zeroize "*) check_tools "gdb";;
777 esac
778
779 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000780 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000781 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
782 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200783 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000784 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
785 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200786 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
787 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
788 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000789 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000790
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200791 # past this point, no call to check_tool, only printing output
792 if [ $QUIET -eq 1 ]; then
793 return
794 fi
795
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000796 msg "info: output_env.sh"
797 case $RUN_COMPONENTS in
798 *_armcc*)
799 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
800 *) set "$@" RUN_ARMCC=0;;
801 esac
802 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100803}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100804
Gilles Peskine192c72f2017-12-21 15:59:21 +0100805
806
807################################################################
808#### Basic checks
809################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100810
811#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200812# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100813#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100814# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200815# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100816# 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 +0200817# time, so start with a GCC build).
818# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100819#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100820# Indicative running times are given for reference.
821
Gilles Peskine8f073122018-11-27 15:58:47 +0100822component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200823 msg "Check: recursion.pl" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200824 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100825}
Janos Follathb72c6782016-07-19 14:54:17 +0100826
Gilles Peskine8f073122018-11-27 15:58:47 +0100827component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200828 msg "Check: freshness of generated source files" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200829 tests/scripts/check-generated-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100830}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200831
Gilles Peskine8f073122018-11-27 15:58:47 +0100832component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200833 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200834 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +0100835}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200836
Gilles Peskine8f073122018-11-27 15:58:47 +0100837component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200838 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200839 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100840}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200841
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200842component_check_changelog () {
843 msg "Check: changelog entries" # < 1s
844 rm -f ChangeLog.new
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200845 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200846 if [ -e ChangeLog.new ]; then
847 # Show the diff for information. It isn't an error if the diff is
848 # non-empty.
849 diff -u ChangeLog ChangeLog.new || true
850 rm ChangeLog.new
851 fi
852}
853
Gilles Peskine8f073122018-11-27 15:58:47 +0100854component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200855 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200856 tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100857}
Darryl Greena07039c2018-03-13 16:48:16 +0000858
Gilles Peskine895868b2019-09-19 21:30:05 +0200859component_check_test_cases () {
860 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200861 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200862 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200863 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200864 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200865 fi
Gilles Peskine58987962022-12-15 14:46:31 +0100866 tests/scripts/check_test_cases.py -q $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200867 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +0200868}
869
Gilles Peskine8f073122018-11-27 15:58:47 +0100870component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200871 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200872 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100873}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200874
Gilles Peskine192c72f2017-12-21 15:59:21 +0100875
Gilles Peskine636c26a2020-03-04 20:46:15 +0100876
Gilles Peskine192c72f2017-12-21 15:59:21 +0100877################################################################
878#### Build and test many configurations and targets
879################################################################
880
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200881component_test_default_out_of_box () {
882 msg "build: make, default config (out-of-box)" # ~1min
883 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200884 # Disable fancy stuff
885 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200886
887 msg "test: main suites make, default config (out-of-box)" # ~10s
888 make test
889
890 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200891 programs/test/selftest
Gilles Peskine93aaf2e2019-06-14 18:27:03 +0200892
893 msg "program demos: make, default config (out-of-box)" # ~10s
894 tests/scripts/run_demos.py
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200895}
896
Gilles Peskine8f073122018-11-27 15:58:47 +0100897component_test_default_cmake_gcc_asan () {
898 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100899 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
900 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200901
Gilles Peskine8f073122018-11-27 15:58:47 +0100902 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
903 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200904
Gilles Peskine93aaf2e2019-06-14 18:27:03 +0200905 msg "program demos (ASan build)" # ~10s
906 tests/scripts/run_demos.py
907
Gilles Peskine97bea012020-04-23 23:37:45 +0200908 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200909 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200910
Gilles Peskineee8af062023-11-02 19:58:03 +0100911 msg "test: metatests (GCC, ASan build)"
912 tests/scripts/run-metatests.sh any asan
913
Gilles Peskine8f073122018-11-27 15:58:47 +0100914 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200915 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200916
Gilles Peskine8f073122018-11-27 15:58:47 +0100917 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200918 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200919
920 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200921 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100922}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200923
Hanno Becker01635512019-02-26 14:27:09 +0000924component_test_full_cmake_gcc_asan () {
925 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200926 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000927 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
928 make
929
930 msg "test: main suites (inc. selftests) (full config, ASan build)"
931 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +0100932
Gilles Peskine97bea012020-04-23 23:37:45 +0200933 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200934 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200935
Gilles Peskine636c26a2020-03-04 20:46:15 +0100936 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200937 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100938
939 msg "test: compat.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200940 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200941
942 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200943 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100944}
945
Ronald Cronc3623db2020-10-29 10:51:32 +0100946component_test_psa_crypto_key_id_encodes_owner () {
947 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
948 scripts/config.py full
949 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
950 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
951 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
952 make
953
954 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
955 make test
956}
957
Gilles Peskine99a34622021-06-17 11:37:52 +0200958# check_renamed_symbols HEADER LIB
959# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
960# name is LIB.
961check_renamed_symbols () {
962 ! nm "$2" | sed 's/.* //' |
963 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
964}
965
Gilles Peskine984c19f2021-06-15 18:37:38 +0200966component_build_psa_crypto_spm () {
967 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
968 scripts/config.py full
969 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
970 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
971 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
972 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
973 # We can only compile, not link, since our test and sample programs
974 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
975 # is active.
976 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskine99a34622021-06-17 11:37:52 +0200977
978 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
979 # version is not present.
980 echo "Checking for renamed symbols in the library"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200981 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskine984c19f2021-06-15 18:37:38 +0200982}
983
Ronald Cron336678b2021-01-28 17:54:24 +0100984component_test_psa_crypto_client () {
985 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
986 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
987 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
988 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
989 make
990
991 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
992 make test
993}
994
Gilles Peskine636c26a2020-03-04 20:46:15 +0100995component_test_zlib_make() {
996 msg "build: zlib enabled, make"
997 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine6fa69862021-10-05 09:36:03 +0200998 make ZLIB=1 CFLAGS='-Werror -O2'
Gilles Peskine636c26a2020-03-04 20:46:15 +0100999
1000 msg "test: main suites (zlib, make)"
1001 make test
1002
1003 msg "test: ssl-opt.sh (zlib, make)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001004 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001005}
1006support_test_zlib_make () {
1007 base=support_test_zlib_$$
1008 cat <<'EOF' > ${base}.c
1009#include "zlib.h"
1010int main(void) { return 0; }
1011EOF
1012 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
1013 ret=$?
1014 rm -f ${base}.*
1015 return $ret
1016}
1017
1018component_test_zlib_cmake() {
1019 msg "build: zlib enabled, cmake"
1020 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine25319702021-10-07 19:34:57 +02001021 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Release .
Gilles Peskine636c26a2020-03-04 20:46:15 +01001022 make
1023
1024 msg "test: main suites (zlib, cmake)"
1025 make test
1026
1027 msg "test: ssl-opt.sh (zlib, cmake)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001028 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001029}
1030support_test_zlib_cmake () {
1031 support_test_zlib_make "$@"
Manuel Pégourié-Gonnardf2e29022020-01-24 10:17:20 +01001032}
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +01001033
Jaeden Ameroc17f2932021-05-14 08:34:32 +01001034component_test_psa_crypto_rsa_no_genprime() {
1035 msg "build: default config minus MBEDTLS_GENPRIME"
1036 scripts/config.py unset MBEDTLS_GENPRIME
1037 make
1038
1039 msg "test: default config minus MBEDTLS_GENPRIME"
1040 make test
1041}
1042
Gilles Peskine782f4112018-11-27 16:11:09 +01001043component_test_ref_configs () {
1044 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
1045 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001046 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +01001047}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001048
Gilles Peskine8f073122018-11-27 15:58:47 +01001049component_test_sslv3 () {
1050 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001051 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +01001052 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1053 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001054
Gilles Peskine8f073122018-11-27 15:58:47 +01001055 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
1056 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +00001057
Gilles Peskine8f073122018-11-27 15:58:47 +01001058 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001059 tests/compat.sh -m 'ssl3 tls1 tls1_1 tls12 dtls1 dtls12'
Simon Butcher3ea7f522016-03-07 23:22:10 +00001060
Gilles Peskine8f073122018-11-27 15:58:47 +01001061 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001062 tests/ssl-opt.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001063
1064 msg "build: SSLv3 - context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001065 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001066}
Simon Butcher3ea7f522016-03-07 23:22:10 +00001067
Gilles Peskine8f073122018-11-27 15:58:47 +01001068component_test_no_renegotiation () {
1069 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001070 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001071 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1072 make
Simon Butcher3ea7f522016-03-07 23:22:10 +00001073
Gilles Peskine8f073122018-11-27 15:58:47 +01001074 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1075 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +01001076
Gilles Peskine8f073122018-11-27 15:58:47 +01001077 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001078 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001079}
Hanno Becker134c2ab2017-10-12 15:29:50 +01001080
Gilles Peskine56194432023-02-01 18:44:11 +01001081component_test_no_certs () {
1082 msg "build: full minus MBEDTLS_CERTS_C"
1083 scripts/config.py full
1084 scripts/config.py unset MBEDTLS_CERTS_C
1085 # Quick build+test (we're checking for stray uses of the test certs,
1086 # not expecting their absence to lead to subtle problems).
1087 make
1088
1089 msg "test: full minus MBEDTLS_CERTS_C - main suites"
1090 make test
1091}
1092
Gilles Peskine636c26a2020-03-04 20:46:15 +01001093component_test_no_pem_no_fs () {
1094 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1095 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1096 scripts/config.py unset MBEDTLS_FS_IO
1097 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1098 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
1099 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1100 make
1101
1102 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1103 make test
1104
1105 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001106 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001107}
1108
Gilles Peskine8f073122018-11-27 15:58:47 +01001109component_test_rsa_no_crt () {
1110 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001111 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +01001112 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1113 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +01001114
Gilles Peskine8f073122018-11-27 15:58:47 +01001115 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1116 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001117
Gilles Peskine8f073122018-11-27 15:58:47 +01001118 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001119 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001120
Gilles Peskine8f073122018-11-27 15:58:47 +01001121 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001122 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001123
1124 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001125 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001126}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001127
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001128component_test_no_ctr_drbg_classic () {
1129 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001130 scripts/config.py full
1131 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001132 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001133
1134 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1135 make
1136
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001137 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001138 make test
1139
Gilles Peskineba749042021-01-13 20:02:03 +01001140 # In this configuration, the TLS test programs use HMAC_DRBG.
1141 # The SSL tests are slow, so run a small subset, just enough to get
1142 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001143 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001144 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001145
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001146 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001147 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001148}
1149
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001150component_test_no_ctr_drbg_use_psa () {
1151 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001152 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001153 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1154 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001155
1156 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1157 make
1158
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001159 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1160 make test
1161
1162 # In this configuration, the TLS test programs use HMAC_DRBG.
1163 # The SSL tests are slow, so run a small subset, just enough to get
1164 # confidence that the SSL code copes with HMAC_DRBG.
1165 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001166 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001167
1168 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001169 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001170}
1171
1172component_test_no_hmac_drbg_classic () {
1173 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1174 scripts/config.py full
1175 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1176 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1177 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1178
1179 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1180 make
1181
1182 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001183 make test
1184
Gilles Peskinea2224342020-11-19 22:14:34 +01001185 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1186 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1187 # instead.
1188 # Test SSL with non-deterministic ECDSA. Only test features that
1189 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001190 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001191 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001192
1193 # To save time, only test one protocol version, since this part of
1194 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001195 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001196 tests/compat.sh -m tls12 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001197}
1198
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001199component_test_no_hmac_drbg_use_psa () {
1200 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1201 scripts/config.py full
1202 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1203 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1204 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1205
1206 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1207 make
1208
1209 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1210 make test
1211
1212 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1213 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1214 # instead.
1215 # Test SSL with non-deterministic ECDSA. Only test features that
1216 # might be affected by how ECDSA signature is performed.
1217 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001218 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001219
1220 # To save time, only test one protocol version, since this part of
1221 # the protocol is identical in (D)TLS up to 1.2.
1222 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001223 tests/compat.sh -m tls12 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001224}
1225
1226component_test_psa_external_rng_no_drbg_classic () {
1227 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1228 scripts/config.py full
1229 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1230 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001231 scripts/config.py unset MBEDTLS_ENTROPY_C
1232 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1233 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001234 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1235 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1236 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1237 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001238 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1239 # the SSL test programs don't have an RNG and can't work. Explicitly
1240 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1241 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001242
1243 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1244 make test
1245
Gilles Peskine8eb29432021-02-03 20:07:11 +01001246 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001247 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001248}
1249
1250component_test_psa_external_rng_no_drbg_use_psa () {
1251 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001252 scripts/config.py full
1253 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001254 scripts/config.py unset MBEDTLS_ENTROPY_C
1255 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1256 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001257 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1258 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1259 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1260 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1261 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1262
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001263 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001264 make test
1265
Gilles Peskine8eb29432021-02-03 20:07:11 +01001266 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001267 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001268}
1269
1270component_test_psa_external_rng_use_psa_crypto () {
1271 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1272 scripts/config.py full
1273 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1274 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1275 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1276 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1277
1278 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1279 make test
1280
Gilles Peskineba749042021-01-13 20:02:03 +01001281 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001282 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001283}
1284
Gilles Peskine55e89982023-04-28 21:04:28 +02001285component_test_psa_inject_entropy () {
1286 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
1287 scripts/config.py full
1288 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
1289 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
1290 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1291 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1292 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
1293 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
1294 make CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
1295
1296 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
1297 make test
1298}
1299
Manuel Pégourié-Gonnard1a3f9ed2020-05-19 12:38:31 +02001300component_test_ecp_no_internal_rng () {
1301 msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
1302 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
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 a 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_NO_INTERNAL_RNG, no DRBG module"
1313 make test
1314
1315 # no SSL tests as they all depend on having a DRBG
1316}
1317
Manuel Pégourié-Gonnard53fb66d2020-06-04 09:43:14 +02001318component_test_ecp_restartable_no_internal_rng () {
1319 msg "build: Default plus ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG"
1320 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1321 scripts/config.py set MBEDTLS_ECP_RESTARTABLE
1322 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1323 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1324 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1325 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
1326 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1327
1328 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1329 make
1330
1331 msg "test: ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG module"
1332 make test
1333
1334 # no SSL tests as they all depend on having a DRBG
1335}
1336
Przemek Stekiele5352702022-10-05 11:37:54 +02001337component_test_tls1_2_default_stream_cipher_only () {
1338 msg "build: default with only stream cipher"
1339
1340 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
1341 scripts/config.py unset MBEDTLS_GCM_C
1342 scripts/config.py unset MBEDTLS_CCM_C
1343 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1344 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1345 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1346 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1347 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1348 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1349 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1350 # Modules that depend on AEAD
1351 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001352 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001353
1354 make
1355
1356 msg "test: default with only stream cipher"
1357 make test
1358
1359 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1360}
1361
1362component_test_tls1_2_default_stream_cipher_only_use_psa () {
1363 msg "build: default with only stream cipher use psa"
1364
1365 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1366 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1367 scripts/config.py unset MBEDTLS_GCM_C
1368 scripts/config.py unset MBEDTLS_CCM_C
1369 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1370 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1371 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1372 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1373 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1374 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1375 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1376 # Modules that depend on AEAD
1377 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001378 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001379
1380 make
1381
1382 msg "test: default with only stream cipher use psa"
1383 make test
1384
1385 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1386}
1387
1388component_test_tls1_2_default_cbc_legacy_cipher_only () {
1389 msg "build: default with only CBC-legacy cipher"
1390
1391 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1392 scripts/config.py unset MBEDTLS_GCM_C
1393 scripts/config.py unset MBEDTLS_CCM_C
1394 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1395 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1396 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1397 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1398 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1399 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1400 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1401 # Modules that depend on AEAD
1402 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001403 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001404
1405 make
1406
1407 msg "test: default with only CBC-legacy cipher"
1408 make test
1409
1410 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1411 tests/ssl-opt.sh -f "TLS 1.2"
1412}
1413
1414component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
1415 msg "build: default with only CBC-legacy cipher use psa"
1416
1417 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1418 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1419 scripts/config.py unset MBEDTLS_GCM_C
1420 scripts/config.py unset MBEDTLS_CCM_C
1421 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1422 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1423 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1424 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1425 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1426 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1427 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1428 # Modules that depend on AEAD
1429 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001430 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001431
1432 make
1433
1434 msg "test: default with only CBC-legacy cipher use psa"
1435 make test
1436
1437 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1438 tests/ssl-opt.sh -f "TLS 1.2"
1439}
1440
1441component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
1442 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1443
1444 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1445 scripts/config.py unset MBEDTLS_GCM_C
1446 scripts/config.py unset MBEDTLS_CCM_C
1447 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1448 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1449 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1450 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1451 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1452 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1453 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1454 # Modules that depend on AEAD
1455 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001456 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001457
1458 make
1459
1460 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1461 make test
1462
1463 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1464 tests/ssl-opt.sh -f "TLS 1.2"
1465}
1466
1467component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
1468 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
1469
1470 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1471 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1472 scripts/config.py unset MBEDTLS_GCM_C
1473 scripts/config.py unset MBEDTLS_CCM_C
1474 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1475 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1476 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1477 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1478 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1479 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1480 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1481 # Modules that depend on AEAD
1482 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001483 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001484
1485 make
1486
1487 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
1488 make test
1489
1490 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
1491 tests/ssl-opt.sh -f "TLS 1.2"
1492}
1493
Gilles Peskine636c26a2020-03-04 20:46:15 +01001494component_test_new_ecdh_context () {
1495 msg "build: new ECDH context (ASan build)" # ~ 6 min
1496 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1497 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1498 make
1499
1500 msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1501 make test
1502
1503 msg "test: new ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001504 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001505
1506 msg "test: new ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1507 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001508 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001509}
1510
1511component_test_everest () {
1512 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
1513 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1514 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1515 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1516 make
1517
1518 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1519 make test
1520
Gilles Peskineee8af062023-11-02 19:58:03 +01001521 msg "test: metatests (clang, ASan)"
1522 tests/scripts/run-metatests.sh any asan
1523
Gilles Peskine636c26a2020-03-04 20:46:15 +01001524 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001525 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001526
1527 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1528 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001529 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001530}
1531
Gilles Peskined3beca92020-07-03 00:15:37 +02001532component_test_everest_curve25519_only () {
1533 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
1534 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1535 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1536 scripts/config.py unset MBEDTLS_ECDSA_C
1537 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1538 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1539 # Disable all curves
1540 for c in $(sed -n 's/#define \(MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED\).*/\1/p' <"$CONFIG_H"); do
1541 scripts/config.py unset "$c"
1542 done
1543 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1544
1545 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1546
1547 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1548 make test
1549}
1550
Gilles Peskine8f073122018-11-27 15:58:47 +01001551component_test_small_ssl_out_content_len () {
1552 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001553 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1554 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001555 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1556 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001557
Gilles Peskine8f073122018-11-27 15:58:47 +01001558 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001559 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001560}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001561
Gilles Peskine8f073122018-11-27 15:58:47 +01001562component_test_small_ssl_in_content_len () {
1563 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001564 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1565 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001566 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1567 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001568
Gilles Peskine8f073122018-11-27 15:58:47 +01001569 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001570 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001571}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001572
Gilles Peskine8f073122018-11-27 15:58:47 +01001573component_test_small_ssl_dtls_max_buffering () {
1574 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001575 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001576 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1577 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001578
Gilles Peskine8f073122018-11-27 15:58:47 +01001579 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001580 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 +01001581}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001582
Gilles Peskine8f073122018-11-27 15:58:47 +01001583component_test_small_mbedtls_ssl_dtls_max_buffering () {
1584 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001585 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001586 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1587 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001588
Gilles Peskine8f073122018-11-27 15:58:47 +01001589 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001590 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001591}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001592
Gilles Peskine75cc7712019-09-06 19:47:17 +02001593component_test_psa_collect_statuses () {
1594 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001595 scripts/config.py full
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001596 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001597 # Check that psa_crypto_init() succeeded at least once
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001598 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001599 rm -f tests/statuses.log
1600}
1601
Gilles Peskine8f073122018-11-27 15:58:47 +01001602component_test_full_cmake_clang () {
1603 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001604 scripts/config.py full
Gilles Peskine83264be2022-10-30 21:02:40 +01001605 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 +01001606 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001607
k-stachowiak0291cb72019-06-26 15:52:12 +02001608 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001609 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001610
Gilles Peskine83264be2022-10-30 21:02:40 +01001611 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
1612 programs/test/cpp_dummy_build
1613
Gilles Peskineee8af062023-11-02 19:58:03 +01001614 msg "test: metatests (clang)"
Gilles Peskinee38eb792023-11-03 18:05:38 +01001615 tests/scripts/run-metatests.sh any pthread
Gilles Peskineee8af062023-11-02 19:58:03 +01001616
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02001617 msg "program demos (full config, clang)" # ~10s
1618 tests/scripts/run_demos.py
1619
k-stachowiak0291cb72019-06-26 15:52:12 +02001620 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001621 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001622
Gilles Peskine8f073122018-11-27 15:58:47 +01001623 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001624 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001625
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001626 msg "test: compat.sh RC4, 3DES & NULL (full config)" # ~ 2min
1627 tests/compat.sh -e '^$' -f 'NULL\|3DES\|DES-CBC3\|RC4\|ARCFOUR'
1628
1629 msg "test: compat.sh single-DES (full config)" # ~ 30s
1630 env OPENSSL="$OPENSSL_LEGACY" tests/compat.sh -e '3DES\|DES-CBC3' -f 'DES'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001631
Gilles Peskine8f073122018-11-27 15:58:47 +01001632 msg "test: compat.sh ARIA + ChachaPoly"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001633 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001634}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001635
Gilles Peskine9603a442022-11-29 16:01:41 +01001636skip_suites_without_constant_flow () {
1637 # Skip the test suites that don't have any constant-flow annotations.
1638 # This will need to be adjusted if we ever start declaring things as
1639 # secret from macros or functions inside tests/include or tests/src.
1640 SKIP_TEST_SUITES=$(
1641 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
1642 sed 's/test_suite_//; s/\.function$//' |
1643 tr '\n' ,)
1644 export SKIP_TEST_SUITES
1645}
1646
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001647component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001648 # This tests both (1) accesses to undefined memory, and (2) branches or
1649 # memory access depending on secret values. To distinguish between those:
1650 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1651 # - or alternatively, change the build type to MemSanDbg, which enables
1652 # origin tracking and nicer stack traces (which are useful for debugging
1653 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1654 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001655 scripts/config.py full
1656 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1657 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1658 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1659 make
1660
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001661 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001662 make test
1663}
1664
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01001665component_release_test_valgrind_constant_flow () {
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001666 # This tests both (1) everything that valgrind's memcheck usually checks
1667 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1668 # etc.) and (2) branches or memory access depending on secret values,
1669 # which will be reported as uninitialized memory. To distinguish between
1670 # secret and actually uninitialized:
1671 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1672 # - or alternatively, build with debug info and manually run the offending
1673 # test suite with valgrind --track-origins=yes, then check if the origin
1674 # was TEST_CF_SECRET() or something else.
1675 msg "build: cmake release GCC, full config with constant flow testing"
1676 scripts/config.py full
1677 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Gilles Peskine9603a442022-11-29 16:01:41 +01001678 skip_suites_without_constant_flow
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001679 cmake -D CMAKE_BUILD_TYPE:String=Release .
1680 make
1681
1682 # this only shows a summary of the results (how many of each type)
1683 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine9603a442022-11-29 16:01:41 +01001684 msg "test: some suites (valgrind + constant flow)"
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001685 make memcheck
1686}
1687
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001688component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02001689 # Test that removing the deprecated features from the default
1690 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001691 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1692 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
Dave Rodgman374b1882024-01-04 10:30:57 +00001693 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001694
1695 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1696 make test
1697}
1698
1699component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02001700 msg "build: make, full_no_deprecated config" # ~ 30s
1701 scripts/config.py full_no_deprecated
Dave Rodgman374b1882024-01-04 10:30:57 +00001702 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001703
Gilles Peskine30de2e82020-04-20 21:39:22 +02001704 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001705 make test
1706}
1707
Gilles Peskine8386ea22020-04-30 09:07:29 +02001708component_test_full_no_deprecated_deprecated_warning () {
1709 # Test that there is nothing deprecated in "full_no_deprecated".
1710 # A deprecated feature would trigger a warning (made fatal) from
1711 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02001712 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1713 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001714 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
1715 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Dave Rodgman374b1882024-01-04 10:30:57 +00001716 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001717
Gilles Peskine30de2e82020-04-20 21:39:22 +02001718 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001719 make test
1720}
1721
Gilles Peskine8386ea22020-04-30 09:07:29 +02001722component_test_full_deprecated_warning () {
1723 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
1724 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001725 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001726 scripts/config.py full
1727 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001728 # Expect warnings from '#warning' directives in check_config.h.
Dave Rodgman9d2c67f2023-12-19 14:07:15 +00001729 # Note that gcc is required to allow the use of -Wno-error=cpp, which allows us to
1730 # display #warning messages without them being treated as errors.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001731 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001732
Gilles Peskine8386ea22020-04-30 09:07:29 +02001733 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1734 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
1735 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001736 # Expect warnings from '#warning' directives in check_config.h and
1737 # from the use of deprecated functions in test suites.
1738 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 +01001739
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001740 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
1741 make test
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02001742
1743 msg "program demos: full config + MBEDTLS_TEST_DEPRECATED" # ~10s
1744 tests/scripts/run_demos.py
Gilles Peskine8f073122018-11-27 15:58:47 +01001745}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00001746
Gilles Peskineec541fe2020-01-31 14:24:14 +01001747# Check that the specified libraries exist and are empty.
1748are_empty_libraries () {
1749 nm "$@" >/dev/null 2>/dev/null
1750 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
1751}
1752
1753component_build_crypto_default () {
1754 msg "build: make, crypto only"
1755 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01001756 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001757 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001758}
1759
1760component_build_crypto_full () {
1761 msg "build: make, crypto only, full config"
1762 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01001763 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001764 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001765}
1766
Gilles Peskine8df27482022-10-21 19:34:54 +02001767component_test_crypto_for_psa_service () {
Gilles Peskine21503df2022-10-11 21:05:06 +02001768 msg "build: make, config for PSA crypto service"
1769 scripts/config.py crypto
1770 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1771 # Disable things that are not needed for just cryptography, to
1772 # reach a configuration that would be typical for a PSA cryptography
1773 # service providing all implemented PSA algorithms.
1774 # System stuff
1775 scripts/config.py unset MBEDTLS_ERROR_C
1776 scripts/config.py unset MBEDTLS_TIMING_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001777 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskine21503df2022-10-11 21:05:06 +02001778 # Crypto stuff with no PSA interface
1779 scripts/config.py unset MBEDTLS_BASE64_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001780 scripts/config.py unset MBEDTLS_BLOWFISH_C
1781 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
1782 # Keep MBEDTLS_MD_C because RSA and ECDSA need it, also HMAC_DRBG which
1783 # is needed for deterministic ECDSA.
1784 scripts/config.py unset MBEDTLS_ECJPAKE_C
1785 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
Gilles Peskine21503df2022-10-11 21:05:06 +02001786 scripts/config.py unset MBEDTLS_NIST_KW_C
1787 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1788 scripts/config.py unset MBEDTLS_PEM_WRITE_C
1789 scripts/config.py unset MBEDTLS_PKCS12_C
1790 scripts/config.py unset MBEDTLS_PKCS5_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001791 # We keep MBEDTLS_PK_{,PARSE,WRITE}_C because PSA with RSA needs it.
1792 scripts/config.py unset MBEDTLS_XTEA_C
Gilles Peskine21503df2022-10-11 21:05:06 +02001793 make CFLAGS='-O1 -Werror' all test
1794 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1795}
1796
Gilles Peskineec541fe2020-01-31 14:24:14 +01001797component_build_crypto_baremetal () {
1798 msg "build: make, crypto only, baremetal config"
1799 scripts/config.py crypto_baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001800 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001801 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001802}
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001803support_build_crypto_baremetal () {
Daniel Axtens1a021af2020-08-31 14:22:58 +10001804 support_build_baremetal "$@"
1805}
1806
1807component_build_baremetal () {
1808 msg "build: make, baremetal config"
1809 scripts/config.py baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001810 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Daniel Axtens1a021af2020-08-31 14:22:58 +10001811}
1812support_build_baremetal () {
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001813 # Older Glibc versions include time.h from other headers such as stdlib.h,
1814 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
1815 # problem, Ubuntu 18.04 is ok.
1816 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
1817}
Gilles Peskineec541fe2020-01-31 14:24:14 +01001818
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001819# depends.py family of tests
Andrzej Kurek85d69302022-10-05 09:14:07 -04001820component_test_depends_py_cipher_id () {
1821 msg "test/build: depends.py cipher_id (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001822 tests/scripts/depends.py cipher_id --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001823}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001824
Andrzej Kurek85d69302022-10-05 09:14:07 -04001825component_test_depends_py_cipher_chaining () {
1826 msg "test/build: depends.py cipher_chaining (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001827 tests/scripts/depends.py cipher_chaining --unset-use-psa
John Durkopc14be902020-08-20 06:16:41 -07001828}
1829
Andrzej Kurek85d69302022-10-05 09:14:07 -04001830component_test_depends_py_cipher_padding () {
1831 msg "test/build: depends.py cipher_padding (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001832 tests/scripts/depends.py cipher_padding --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001833}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001834
Andrzej Kurek85d69302022-10-05 09:14:07 -04001835component_test_depends_py_curves () {
1836 msg "test/build: depends.py curves (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001837 tests/scripts/depends.py curves --unset-use-psa
John Durkop2ec2eaa2020-08-24 18:29:15 -07001838}
1839
Andrzej Kurek85d69302022-10-05 09:14:07 -04001840component_test_depends_py_hashes () {
1841 msg "test/build: depends.py hashes (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001842 tests/scripts/depends.py hashes --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001843}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001844
Andrzej Kurek85d69302022-10-05 09:14:07 -04001845component_test_depends_py_kex () {
1846 msg "test/build: depends.py kex (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001847 tests/scripts/depends.py kex --unset-use-psa
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001848}
1849
Andrzej Kurek85d69302022-10-05 09:14:07 -04001850component_test_depends_py_pkalgs () {
1851 msg "test/build: depends.py pkalgs (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001852 tests/scripts/depends.py pkalgs --unset-use-psa
1853}
1854
1855# PSA equivalents of the depends.py tests
1856component_test_depends_py_cipher_id_psa () {
1857 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1858 tests/scripts/depends.py cipher_id
1859}
1860
1861component_test_depends_py_cipher_chaining_psa () {
1862 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1863 tests/scripts/depends.py cipher_chaining
1864}
1865
1866component_test_depends_py_cipher_padding_psa () {
1867 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1868 tests/scripts/depends.py cipher_padding
1869}
1870
1871component_test_depends_py_curves_psa () {
1872 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1873 tests/scripts/depends.py curves
1874}
1875
1876component_test_depends_py_hashes_psa () {
1877 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1878 tests/scripts/depends.py hashes
1879}
1880
1881component_test_depends_py_kex_psa () {
1882 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1883 tests/scripts/depends.py kex
1884}
1885
1886component_test_depends_py_pkalgs_psa () {
1887 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Andrzej Kurek85d69302022-10-05 09:14:07 -04001888 tests/scripts/depends.py pkalgs
Gilles Peskine8f073122018-11-27 15:58:47 +01001889}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001890
Dave Rodgman5fce4f62023-01-20 13:18:05 +00001891component_build_no_pk_rsa_alt_support () {
1892 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
1893
1894 scripts/config.py full
1895 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
1896 scripts/config.py set MBEDTLS_RSA_C
1897 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
1898
1899 # Only compile - this is primarily to test for compile issues
Dave Rodgman374b1882024-01-04 10:30:57 +00001900 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
Dave Rodgman5fce4f62023-01-20 13:18:05 +00001901}
1902
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001903component_test_no_use_psa_crypto_full_cmake_asan() {
1904 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02001905 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001906 scripts/config.py full
1907 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
1908 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1909 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1910 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02001911 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001912 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01001913 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001914 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001915
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001916 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001917 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001918
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001919 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001920 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001921
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001922 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001923 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001924
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001925 msg "test: compat.sh RC4, 3DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
1926 tests/compat.sh -e '^$' -f 'NULL\|3DES\|DES-CBC3\|RC4\|ARCFOUR'
1927
1928 msg "test: compat.sh single-DES (full minus MBEDTLS_USE_PSA_CRYPTO)"
1929 env OPENSSL="$OPENSSL_LEGACY" tests/compat.sh -e '3DES\|DES-CBC3' -f 'DES'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001930
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001931 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001932 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001933}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001934
Ronald Crond2c53e62021-09-13 09:38:05 +02001935component_test_psa_crypto_config_accel_ecdsa () {
1936 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1937
1938 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1939 # partial support for cipher operations in the driver test library.
1940 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1941 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Gilles Peskine62de7672022-04-21 11:05:16 +02001942 # Disable obsolete hashes (alternatively we could enable support for them
1943 # in the driver test library).
1944 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1945 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
Ronald Crond2c53e62021-09-13 09:38:05 +02001946
1947 # SHA384 needed for some ECDSA signature tests.
1948 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
1949
1950 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
1951 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1952 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1953
1954 # Restore test driver base configuration
1955 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
1956
1957 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1958 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1959 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1960 scripts/config.py unset MBEDTLS_ECDSA_C
1961 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1962 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1963
1964 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
1965 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"
1966
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01001967 not grep mbedtls_ecdsa_ library/ecdsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02001968
1969 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1970 make test
1971}
1972
1973component_test_psa_crypto_config_accel_rsa_signature () {
1974 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
1975
1976 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1977 # partial support for cipher operations in the driver test library.
1978 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1979 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1980
1981 # It seems it is not possible to remove only the support for RSA signature
1982 # in the library. Thus we have to remove all RSA support (signature and
1983 # encryption/decryption). AS there is no driver support for asymmetric
1984 # encryption/decryption so far remove RSA encryption/decryption from the
1985 # application algorithm list.
1986 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1987 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1988
1989 # Make sure both the library and the test library support the SHA hash
1990 # algorithms and only those ones (SHA256 is included by default). That way:
1991 # - the test library can compute the RSA signatures even in the case of a
1992 # composite RSA signature algorithm based on a SHA hash (no other hash
1993 # used in the unit tests).
1994 # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
1995 # fulfilled as the hash SHA algorithm is supported by the library, and
1996 # thus the tests are run, not skipped.
1997 # - when testing a signature key with an algorithm wildcard built from
1998 # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
1999 # algorithm based on the hashes supported by the library is also
2000 # supported by the test library.
2001 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2002 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2003 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2004 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160_C
2005
2006 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA1_C
2007 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
2008 # We need PEM parsing in the test library as well to support the import
2009 # of PEM encoded RSA keys.
2010 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_PEM_PARSE_C
2011 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_BASE64_C
2012
2013 loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
2014 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2015 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2016
2017 # Restore test driver base configuration
2018 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA1_C
2019 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
2020 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_PEM_PARSE_C
2021 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_BASE64_C
2022
2023
2024 # Mbed TLS library build
2025 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2026 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2027
2028 # Remove RSA support and its dependencies
2029 scripts/config.py unset MBEDTLS_PKCS1_V15
2030 scripts/config.py unset MBEDTLS_PKCS1_V21
2031 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2032 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2033 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2034 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2035 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2036 scripts/config.py unset MBEDTLS_RSA_C
2037 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2038
2039 scripts/config.py unset MBEDTLS_MD2_C
2040 scripts/config.py unset MBEDTLS_MD4_C
2041 scripts/config.py unset MBEDTLS_MD5_C
2042 scripts/config.py unset MBEDTLS_RIPEMD160_C
2043 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
2044 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
2045 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
2046
2047 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2048 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2049
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002050 not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
2051 not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02002052
2053 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
2054 make test
2055}
2056
Ronald Cronf7e483c2021-05-08 14:32:59 +02002057component_test_psa_crypto_config_accel_hash () {
2058 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2059
2060 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
2061 # partial support for cipher operations in the driver test library.
2062 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2063 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
2064
2065 loc_accel_list="ALG_MD4 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
2066 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2067 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2068
2069 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2070 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2071 scripts/config.py unset MBEDTLS_MD2_C
2072 scripts/config.py unset MBEDTLS_MD4_C
2073 scripts/config.py unset MBEDTLS_MD5_C
2074 scripts/config.py unset MBEDTLS_RIPEMD160_C
2075 scripts/config.py unset MBEDTLS_SHA1_C
2076 # Don't unset MBEDTLS_SHA256_C as it is needed by PSA crypto core.
2077 scripts/config.py unset MBEDTLS_SHA512_C
2078 # Unset MBEDTLS_SSL_PROTO_SSL3, MBEDTLS_SSL_PROTO_TLS1 and MBEDTLS_SSL_PROTO_TLS1_1 as they depend on MBEDTLS_SHA1_C
2079 scripts/config.py unset MBEDTLS_SSL_PROTO_SSL3
2080 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
2081 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
2082 # Unset MBEDTLS_SSL_CBC_RECORD_SPLITTING as it depends on MBEDTLS_SSL_PROTO_TLS1 in the default configuration.
2083 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
2084 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2085 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2086
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002087 not grep mbedtls_sha512_init library/sha512.o
2088 not grep mbedtls_sha1_init library/sha1.o
Ronald Cronf7e483c2021-05-08 14:32:59 +02002089
2090 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2091 make test
2092}
2093
Ronald Cron09623702021-10-18 11:26:01 +02002094component_test_psa_crypto_config_accel_cipher () {
2095 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
2096
Gilles Peskine186331872022-04-12 15:58:03 +02002097 # This test case focuses on cipher+AEAD. We don't yet support all
2098 # combinations of configurations, so deactivate block-cipher-based MACs.
2099 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CMAC
2100
Ronald Cron09623702021-10-18 11:26:01 +02002101 loc_accel_list="ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB ALG_OFB ALG_XTS KEY_TYPE_DES"
2102 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2103 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2104
2105 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2106 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2107
2108 # There is no intended accelerator support for ALG STREAM_CIPHER and
2109 # ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
2110 # inclusion of the Mbed TLS cipher operations. As we want to test here with
2111 # cipher operations solely supported by accelerators, disabled those
2112 # PSA configuration options.
2113 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2114 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Ronald Cron09623702021-10-18 11:26:01 +02002115
2116 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2117 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2118 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2119 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2120 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2121 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2122 scripts/config.py unset MBEDTLS_DES_C
2123
2124 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2125 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2126
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002127 not grep mbedtls_des* library/des.o
Ronald Cron09623702021-10-18 11:26:01 +02002128
2129 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2130 make test
2131}
2132
Przemek Stekiel8b56f232022-10-02 20:58:39 +02002133component_test_psa_crypto_config_accel_aead () {
2134 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2135
2136 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
2137 # partial support for cipher operations in the driver test library.
2138 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2139 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
2140
2141 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2142 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2143 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2144
2145 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2146 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2147
2148 scripts/config.py unset MBEDTLS_GCM_C
2149 scripts/config.py unset MBEDTLS_CCM_C
2150 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2151 # Features that depend on AEAD
2152 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
2153 scripts/config.py unset MBEDTLS_SSL_TICKET_C
2154
2155 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2156 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"
2157
2158 # There's a risk of something getting re-enabled via config_psa.h
2159 # make sure it did not happen.
2160 not grep mbedtls_ccm library/ccm.o
2161 not grep mbedtls_gcm library/gcm.o
2162 not grep mbedtls_chachapoly library/chachapoly.o
2163
2164 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2165 make test
2166}
2167
John Durkop4377bf72020-10-23 01:26:57 -07002168component_test_psa_crypto_config_no_driver() {
John Durkop4377bf72020-10-23 01:26:57 -07002169 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
2170 scripts/config.py full
2171 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2172 scripts/config.py unset MBEDTLS_PSA_CRYPTO_DRIVERS
2173 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkope7012c72020-10-26 09:55:01 -07002174 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop4377bf72020-10-23 01:26:57 -07002175
2176 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
John Durkopd8959392020-09-20 23:09:17 -07002177 make test
2178}
2179
Gilles Peskined4c85af2023-07-20 22:19:45 +02002180component_test_aead_chachapoly_disabled() {
2181 msg "build: full minus CHACHAPOLY"
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002182 scripts/config.py full
2183 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Gilles Peskined4c85af2023-07-20 22:19:45 +02002184 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002185 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
2186
Gilles Peskined4c85af2023-07-20 22:19:45 +02002187 msg "test: full minus CHACHAPOLY"
2188 make test
2189}
2190
2191component_test_aead_only_ccm() {
2192 msg "build: full minus CHACHAPOLY and GCM"
2193 scripts/config.py full
2194 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2195 scripts/config.py unset MBEDTLS_GCM_C
2196 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2197 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2198 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
2199
2200 msg "test: full minus CHACHAPOLY and GCM"
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002201 make test
2202}
2203
John Durkopd0321952020-10-29 21:37:36 -07002204# 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 -08002205component_build_psa_accel_alg_ecdh() {
Gilles Peskine168be012023-07-19 19:36:55 +02002206 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
John Durkopd0321952020-10-29 21:37:36 -07002207 scripts/config.py full
2208 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2209 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2210 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2211 scripts/config.py unset MBEDTLS_ECDH_C
2212 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2213 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2214 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2215 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2216 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2217 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2218 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2219}
2220
John Durkopf4c4cb02020-10-28 20:09:55 -07002221# 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 -08002222component_build_psa_accel_key_type_ecc_key_pair() {
Gilles Peskine168be012023-07-19 19:36:55 +02002223 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR"
John Durkopf4c4cb02020-10-28 20:09:55 -07002224 scripts/config.py full
2225 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2226 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2227 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002228 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 -08002229 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 -07002230 # 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 -08002231 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 -07002232}
2233
2234# 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 -08002235component_build_psa_accel_key_type_ecc_public_key() {
Gilles Peskine168be012023-07-19 19:36:55 +02002236 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
John Durkopf4c4cb02020-10-28 20:09:55 -07002237 scripts/config.py full
2238 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2239 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2240 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002241 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
2242 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
John Durkopf4c4cb02020-10-28 20:09:55 -07002243 # 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 -08002244 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 -07002245}
2246
John Durkopd0321952020-10-29 21:37:36 -07002247# 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 -08002248component_build_psa_accel_alg_hmac() {
Gilles Peskine168be012023-07-19 19:36:55 +02002249 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
John Durkopd0321952020-10-29 21:37:36 -07002250 scripts/config.py full
2251 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2252 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2253 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2254 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2255 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2256}
2257
2258# 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 -08002259component_build_psa_accel_alg_hkdf() {
Gilles Peskine168be012023-07-19 19:36:55 +02002260 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
John Durkopd0321952020-10-29 21:37:36 -07002261 scripts/config.py full
2262 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2263 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2264 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2265 scripts/config.py unset MBEDTLS_HKDF_C
John Durkopbd069d32020-10-31 22:14:03 -07002266 # Make sure to unset TLS1_3_EXPERIMENTAL since it requires HKDF_C and will not build properly without it.
2267 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
John Durkopd0321952020-10-29 21:37:36 -07002268 # 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_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2270}
2271
John Durkop1b7ee052020-11-27 08:51:22 -08002272# This should be renamed to test and updated once the accelerator MD2 code is in place and ready to test.
2273component_build_psa_accel_alg_md2() {
Gilles Peskine168be012023-07-19 19:36:55 +02002274 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD2 - 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_MD4
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_MD2 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2289}
2290
2291# This should be renamed to test and updated once the accelerator MD4 code is in place and ready to test.
2292component_build_psa_accel_alg_md4() {
Gilles Peskine168be012023-07-19 19:36:55 +02002293 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD4 - 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_MD5
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_MD4 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2308}
2309
2310# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
2311component_build_psa_accel_alg_md5() {
Gilles Peskine168be012023-07-19 19:36:55 +02002312 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - 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_RIPEMD160
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_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2327}
2328
2329# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
2330component_build_psa_accel_alg_ripemd160() {
Gilles Peskine168be012023-07-19 19:36:55 +02002331 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - 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_SHA_1
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_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2346}
2347
2348# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
2349component_build_psa_accel_alg_sha1() {
Gilles Peskine168be012023-07-19 19:36:55 +02002350 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - 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_224
2360 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2361 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2362 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2363 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2364 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2365}
2366
2367# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
2368component_build_psa_accel_alg_sha224() {
Gilles Peskine168be012023-07-19 19:36:55 +02002369 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002370 scripts/config.py full
2371 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2372 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2373 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2374 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2375 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2376 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2377 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2378 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
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_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2383}
2384
2385# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
2386component_build_psa_accel_alg_sha256() {
Gilles Peskine168be012023-07-19 19:36:55 +02002387 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - 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_384
2399 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2400 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2401 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2402}
2403
2404# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
2405component_build_psa_accel_alg_sha384() {
Gilles Peskine168be012023-07-19 19:36:55 +02002406 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002407 scripts/config.py full
2408 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2409 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2410 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2411 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2412 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2413 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2414 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2415 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2416 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2417 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
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_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2420}
2421
2422# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
2423component_build_psa_accel_alg_sha512() {
Gilles Peskine168be012023-07-19 19:36:55 +02002424 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002425 scripts/config.py full
2426 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2427 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2428 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2429 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2430 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2431 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2432 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2433 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2434 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2435 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2436 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2437 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2438 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2439}
2440
John Durkopd0321952020-10-29 21:37:36 -07002441# 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 -08002442component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
Gilles Peskine168be012023-07-19 19:36:55 +02002443 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 -07002444 scripts/config.py full
2445 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2446 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2447 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkopbd069d32020-10-31 22:14:03 -07002448 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002449 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2450 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2451 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07002452 # 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 -07002453 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2454}
2455
2456# 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 -08002457component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
Gilles Peskine168be012023-07-19 19:36:55 +02002458 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 -07002459 scripts/config.py full
2460 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2461 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2462 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2463 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002464 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2465 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2466 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002467 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2468 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2469}
2470
2471# 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 -08002472component_build_psa_accel_alg_rsa_oaep() {
Gilles Peskine168be012023-07-19 19:36:55 +02002473 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 -07002474 scripts/config.py full
2475 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2476 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2477 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2478 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_OAEP 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002479 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2480 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2481 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002482 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2483 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2484}
2485
2486# 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 -08002487component_build_psa_accel_alg_rsa_pss() {
Gilles Peskine168be012023-07-19 19:36:55 +02002488 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 -07002489 scripts/config.py full
2490 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2491 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2492 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2493 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002494 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2495 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2496 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07002497 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2498 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2499}
2500
2501# 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 -08002502component_build_psa_accel_key_type_rsa_key_pair() {
Gilles Peskine168be012023-07-19 19:36:55 +02002503 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 -07002504 scripts/config.py full
2505 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2506 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2507 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2508 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2509 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
2510 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2511 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"
2512}
2513
2514# 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 -08002515component_build_psa_accel_key_type_rsa_public_key() {
Gilles Peskine168be012023-07-19 19:36:55 +02002516 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 -07002517 scripts/config.py full
2518 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2519 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2520 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2521 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2522 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
2523 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2524 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 -07002525}
2526
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002527component_test_check_params_functionality () {
2528 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002529 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002530 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002531 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Ronald Crona1236142020-07-01 16:01:21 +02002532 make CC=gcc CFLAGS='-Werror -O1' all test
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002533}
2534
Gilles Peskineb28636b2019-01-02 19:06:24 +01002535component_test_check_params_without_platform () {
2536 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002537 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002538 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002539 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
2540 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
2541 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
2542 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
Gilles Peskine32e889d2020-04-12 23:43:28 +02002543 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002544 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
2545 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskine9c764bf2022-09-18 14:05:23 +02002546 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002547 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
2548 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +01002549 make CC=gcc CFLAGS='-Werror -O1' all test
2550}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002551
Gilles Peskineb28636b2019-01-02 19:06:24 +01002552component_test_check_params_silent () {
2553 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002554 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002555 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01002556 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
2557 make CC=gcc CFLAGS='-Werror -O1' all test
2558}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002559
Dave Rodgman173227d2023-06-29 09:29:00 +01002560component_build_aes_variations() { # ~45s
2561 msg "build: aes.o for all combinations of relevant config options"
Dave Rodgmanbf998282023-06-29 12:10:45 +01002562
Dave Rodgman173227d2023-06-29 09:29:00 +01002563 for a in set unset; do
2564 for b in set unset; do
2565 for c in set unset; do
2566 for d in set unset; do
2567 for e in set unset; do
2568 for f in set unset; do
2569 for g in set unset; do
Dave Rodgmanbf998282023-06-29 12:10:45 +01002570 echo ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
2571 echo ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
2572 echo ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
2573 echo ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
2574 echo ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
2575 echo ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
2576 echo ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman173227d2023-06-29 09:29:00 +01002577
Dave Rodgmanbf998282023-06-29 12:10:45 +01002578 ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
2579 ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
2580 ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
2581 ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
2582 ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
2583 ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
2584 ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman173227d2023-06-29 09:29:00 +01002585
Dave Rodgmanbf998282023-06-29 12:10:45 +01002586 rm -f library/aes.o
2587 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 +01002588 done
2589 done
2590 done
2591 done
2592 done
2593 done
2594 done
2595}
2596
Gilles Peskine8f073122018-11-27 15:58:47 +01002597component_test_no_platform () {
2598 # Full configuration build, without platform support, file IO and net sockets.
2599 # This should catch missing mbedtls_printf definitions, and by disabling file
2600 # IO, it should catch missing '#include <stdio.h>'
2601 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Paul Elliott68050372023-11-03 19:24:56 +00002602 scripts/config.py full_no_platform
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002603 scripts/config.py unset MBEDTLS_PLATFORM_C
2604 scripts/config.py unset MBEDTLS_NET_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002605 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002606 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002607 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
2608 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Paul Elliott68050372023-11-03 19:24:56 +00002609 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +01002610 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
2611 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002612 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
2613 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01002614}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00002615
Gilles Peskine8f073122018-11-27 15:58:47 +01002616component_build_no_std_function () {
2617 # catch compile bugs in _uninit functions
2618 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002619 scripts/config.py full
2620 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
2621 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002622 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine31fdda12021-10-08 11:45:47 +02002623 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskine25319702021-10-07 19:34:57 +02002624 make
Gilles Peskine8f073122018-11-27 15:58:47 +01002625}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01002626
Gilles Peskine8f073122018-11-27 15:58:47 +01002627component_build_no_ssl_srv () {
2628 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002629 scripts/config.py full
2630 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002631 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002632}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002633
Gilles Peskine8f073122018-11-27 15:58:47 +01002634component_build_no_ssl_cli () {
2635 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002636 scripts/config.py full
2637 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002638 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002639}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002640
Gilles Peskine8f073122018-11-27 15:58:47 +01002641component_build_no_sockets () {
2642 # Note, C99 compliance can also be tested with the sockets support disabled,
2643 # as that requires a POSIX platform (which isn't the same as C99).
2644 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002645 scripts/config.py full
2646 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
2647 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002648 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01002649}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02002650
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002651component_test_memory_buffer_allocator_backtrace () {
2652 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002653 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2654 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2655 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
2656 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Dave Rodgman374b1882024-01-04 10:30:57 +00002657 cmake -DCMAKE_BUILD_TYPE:String=Release .
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002658 make
2659
2660 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
2661 make test
2662}
2663
2664component_test_memory_buffer_allocator () {
2665 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002666 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2667 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Dave Rodgman374b1882024-01-04 10:30:57 +00002668 cmake -DCMAKE_BUILD_TYPE:String=Release .
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002669 make
2670
2671 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2672 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002673
2674 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2675 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002676 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002677}
2678
Gilles Peskine8f073122018-11-27 15:58:47 +01002679component_test_no_max_fragment_length () {
2680 # Run max fragment length tests with MFL disabled
2681 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002682 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01002683 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2684 make
Hanno Becker5175ac62017-09-18 15:36:25 +01002685
Gilles Peskine8f073122018-11-27 15:58:47 +01002686 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002687 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01002688}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002689
Hanno Becker545ced42019-02-19 11:10:48 +00002690component_test_asan_remove_peer_certificate () {
2691 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002692 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00002693 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2694 make
2695
2696 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2697 make test
2698
2699 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002700 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002701
2702 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002703 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002704
2705 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002706 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002707}
2708
Gilles Peskine8f073122018-11-27 15:58:47 +01002709component_test_no_max_fragment_length_small_ssl_out_content_len () {
2710 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002711 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2712 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
2713 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01002714 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2715 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10002716
Gilles Peskine8f073122018-11-27 15:58:47 +01002717 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002718 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002719
2720 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002721 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002722}
Angus Grattonc4dd0732018-04-11 16:28:39 +10002723
Darryl Greenaad82f92019-12-02 10:53:11 +00002724component_test_variable_ssl_in_out_buffer_len () {
2725 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
2726 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2727 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2728 make
2729
2730 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2731 make test
2732
2733 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002734 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002735
2736 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002737 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002738}
2739
2740component_test_variable_ssl_in_out_buffer_len_CID () {
2741 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
2742 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2743 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
2744
2745 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2746 make
2747
2748 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
2749 make test
2750
2751 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002752 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002753
2754 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002755 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002756}
2757
2758component_test_variable_ssl_in_out_buffer_len_record_splitting () {
2759 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled (ASan build)"
2760 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2761 scripts/config.py set MBEDTLS_SSL_CBC_RECORD_SPLITTING
2762
2763 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2764 make
2765
2766 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING"
2767 make test
2768
2769 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002770 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002771
2772 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002773 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002774}
2775
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002776component_test_ssl_alloc_buffer_and_mfl () {
2777 msg "build: default config with memory buffer allocator and MFL extension"
2778 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2779 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2780 scripts/config.py set MBEDTLS_MEMORY_DEBUG
2781 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2782 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
Dave Rodgman374b1882024-01-04 10:30:57 +00002783 cmake -DCMAKE_BUILD_TYPE:String=Release .
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002784 make
2785
2786 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
2787 make test
2788
2789 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 +02002790 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002791}
2792
Gilles Peskine636c26a2020-03-04 20:46:15 +01002793component_test_when_no_ciphersuites_have_mac () {
2794 msg "build: when no ciphersuites have MAC"
2795 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
2796 scripts/config.py unset MBEDTLS_ARC4_C
2797 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2798 make
2799
2800 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
2801 make test
2802
2803 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002804 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01002805}
2806
Gilles Peskine8f073122018-11-27 15:58:47 +01002807component_test_null_entropy () {
2808 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002809 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
2810 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
2811 scripts/config.py set MBEDTLS_ENTROPY_C
2812 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002813 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002814 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
2815 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00002816 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01002817 make
Janos Follath06c54002016-06-09 13:57:40 +01002818
Gilles Peskine8f073122018-11-27 15:58:47 +01002819 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
2820 make test
2821}
Janos Follath06c54002016-06-09 13:57:40 +01002822
Raoul Strackxa4e86142020-06-15 17:03:13 +02002823component_test_no_date_time () {
2824 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
2825 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
Gilles Peskine31fdda12021-10-08 11:45:47 +02002826 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Raoul Strackxa4e86142020-06-15 17:03:13 +02002827 make
2828
2829 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
2830 make test
2831}
2832
Andrzej Kurekc890b222023-01-17 04:03:19 -05002833component_test_alt_timing() {
2834 msg "build: alternate timing implementation"
2835 scripts/config.py set MBEDTLS_TIMING_ALT
2836 make lib TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
2837
2838 msg "test: MBEDTLS_TIMING_ALT - test suites"
2839 make test TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
Andrzej Kurek3a261a42023-01-26 04:33:59 -05002840
2841 msg "selftest - MBEDTLS-TIMING_ALT"
2842 make programs TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../../tests/src/external_timing -I../tests/src/external_timing"
2843 programs/test/selftest
Andrzej Kurekc890b222023-01-17 04:03:19 -05002844}
2845
Gilles Peskine8f073122018-11-27 15:58:47 +01002846component_test_platform_calloc_macro () {
2847 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002848 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2849 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
2850 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01002851 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2852 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01002853
Gilles Peskine8f073122018-11-27 15:58:47 +01002854 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
2855 make test
2856}
Hanno Beckere5fecec2018-10-11 11:02:52 +01002857
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002858component_test_malloc_0_null () {
2859 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002860 scripts/config.py full
Gilles Peskine2e70f1c2023-07-20 19:00:15 +02002861 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 +02002862
2863 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
2864 make test
2865
2866 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
2867 # Just the calloc selftest. "make test" ran the others as part of the
2868 # test suites.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002869 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01002870
2871 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
2872 # Run a subset of the tests. The choice is a balance between coverage
2873 # and time (including time indirectly wasted due to flaky tests).
2874 # The current choice is to skip tests whose description includes
2875 # "proxy", which is an approximation of skipping tests that use the
2876 # UDP proxy, which tend to be slower and flakier.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002877 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002878}
2879
Gilles Peskine8f073122018-11-27 15:58:47 +01002880component_test_aes_fewer_tables () {
2881 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002882 scripts/config.py set MBEDTLS_AES_FEWER_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"
2886 make test
2887}
Hanno Becker83ebf782017-07-07 12:29:15 +01002888
Gilles Peskine8f073122018-11-27 15:58:47 +01002889component_test_aes_rom_tables () {
2890 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002891 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Dave Rodgmance04f242024-01-04 10:34:31 +00002892 make CFLAGS='-O2 -Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002893
Gilles Peskine8f073122018-11-27 15:58:47 +01002894 msg "test: AES_ROM_TABLES"
2895 make test
2896}
Hanno Becker83ebf782017-07-07 12:29:15 +01002897
Gilles Peskine8f073122018-11-27 15:58:47 +01002898component_test_aes_fewer_tables_and_rom_tables () {
2899 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002900 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2901 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Dave Rodgmance04f242024-01-04 10:34:31 +00002902 make CFLAGS='-O2 -Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002903
Gilles Peskine8f073122018-11-27 15:58:47 +01002904 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2905 make test
2906}
2907
Gilles Peskine592f5912019-10-07 18:49:32 +02002908component_test_ctr_drbg_aes_256_sha_256 () {
2909 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002910 scripts/config.py full
2911 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2912 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002913 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2914 make
2915
2916 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2917 make test
2918}
2919
2920component_test_ctr_drbg_aes_128_sha_512 () {
2921 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002922 scripts/config.py full
2923 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2924 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02002925 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2926 make
2927
2928 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2929 make test
2930}
2931
2932component_test_ctr_drbg_aes_128_sha_256 () {
2933 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002934 scripts/config.py full
2935 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2936 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2937 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002938 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2939 make
2940
2941 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2942 make test
2943}
2944
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002945component_test_se_default () {
2946 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002947 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02002948 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002949
2950 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2951 make test
2952}
2953
Steven Cooremand57203d2020-07-16 20:28:59 +02002954component_test_psa_crypto_drivers () {
Gilles Peskine8d77ec22023-07-26 18:45:20 +02002955 msg "build: full + test drivers dispatching to builtins"
Steven Cooreman753f9732021-03-15 11:38:44 +01002956 scripts/config.py full
Steven Cooremand57203d2020-07-16 20:28:59 +02002957 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
Gilles Peskinefe0acc62021-09-20 19:20:04 +02002958 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
2959 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002960 loc_cflags="${loc_cflags} -I../tests/include -O2"
2961
2962 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002963
Gilles Peskine8d77ec22023-07-26 18:45:20 +02002964 msg "test: full + test drivers dispatching to builtins"
Steven Cooremand57203d2020-07-16 20:28:59 +02002965 make test
2966}
2967
Gilles Peskine8f073122018-11-27 15:58:47 +01002968component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002969 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002970 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02002971 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine27482f12021-11-04 12:52:14 +01002972 programs/test/dlopen_demo.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002973}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02002974
Gilles Peskinecf740502019-07-03 20:43:05 +02002975component_test_cmake_shared () {
2976 msg "build/test: cmake shared" # ~ 2min
2977 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
2978 make
Gilles Peskine56c01612019-07-03 20:43:32 +02002979 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02002980 make test
Gilles Peskine27482f12021-11-04 12:52:14 +01002981 programs/test/dlopen_demo.sh
Gilles Peskinecf740502019-07-03 20:43:05 +02002982}
2983
Gilles Peskineec10bf12019-09-20 19:56:06 +02002984test_build_opt () {
2985 info=$1 cc=$2; shift 2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002986 $cc --version
Gilles Peskineec10bf12019-09-20 19:56:06 +02002987 for opt in "$@"; do
2988 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskinee094a182020-04-14 20:08:41 +02002989 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02002990 # We're confident enough in compilers to not run _all_ the tests,
2991 # but at least run the unit tests. In particular, runs with
2992 # optimizations use inline assembly whereas runs with -O0
2993 # skip inline assembly.
2994 make test # ~30s
2995 make clean
2996 done
2997}
2998
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002999# For FreeBSD we invoke the function by name so this condition is added
3000# to disable the existing test_clang_opt function for linux.
3001if [[ $(uname) != "Linux" ]]; then
3002 component_test_clang_opt () {
3003 scripts/config.py full
3004 test_build_opt 'full config' clang -O0 -Os -O2
3005 }
3006fi
3007
3008component_test_clang_latest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01003009 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003010 test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003011}
3012support_test_clang_latest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003013 type "$CLANG_LATEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02003014}
3015
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003016component_test_clang_earliest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01003017 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003018 test_build_opt 'full config' "$CLANG_EARLIEST" -O0
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003019}
3020support_test_clang_earliest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003021 type "$CLANG_EARLIEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003022}
3023
3024component_test_gcc_latest_opt () {
3025 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003026 test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003027}
3028support_test_gcc_latest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003029 type "$GCC_LATEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003030}
3031
3032component_test_gcc_earliest_opt () {
3033 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003034 test_build_opt 'full config' "$GCC_EARLIEST" -O0
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003035}
3036support_test_gcc_earliest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003037 type "$GCC_EARLIEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02003038}
3039
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02003040component_build_mbedtls_config_file () {
3041 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
Gilles Peskine6af9dc92022-04-07 20:55:57 +02003042 scripts/config.py -w full_config.h full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02003043 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
3044 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02003045 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine036a9bb2022-04-07 21:06:41 +02003046 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3047 make clean
3048
3049 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
3050 # In the user config, disable one feature (for simplicity, pick a feature
3051 # that nothing else depends on).
3052 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3053 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
3054 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3055
3056 rm -f user_config.h full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003057}
3058
Gilles Peskine690a2ef2022-04-07 21:59:14 +02003059component_build_psa_config_file () {
3060 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
3061 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3062 cp "$CRYPTO_CONFIG_H" psa_test_config.h
3063 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
3064 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02003065 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine690a2ef2022-04-07 21:59:14 +02003066 programs/test/query_compile_time_config MBEDTLS_CMAC_C
3067 make clean
3068
3069 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
3070 # In the user config, disable one feature, which will reflect on the
3071 # mbedtls configuration so we can query it with query_compile_time_config.
3072 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
3073 scripts/config.py unset MBEDTLS_CMAC_C
3074 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
3075 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
3076
3077 rm -f psa_test_config.h psa_user_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003078}
3079
Gilles Peskine8f073122018-11-27 15:58:47 +01003080component_test_m32_o0 () {
Gilles Peskinea0c51fb2021-10-07 19:27:16 +02003081 # Build without optimization, so as to use portable C code (in a 32-bit
3082 # build) and not the i386-specific inline assembly.
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003083 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003084 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02003085 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01003086
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003087 msg "test: i386, make, gcc -O0 (ASan build)"
3088 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01003089}
Gilles Peskine878cf602019-01-06 20:50:38 +00003090support_test_m32_o0 () {
3091 case $(uname -m) in
Pengyu Lva89b3672022-10-21 10:50:26 +00003092 amd64|x86_64) true;;
Gilles Peskine878cf602019-01-06 20:50:38 +00003093 *) false;;
3094 esac
3095}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003096
Gilles Peskine6fa69862021-10-05 09:36:03 +02003097component_test_m32_o2 () {
3098 # Build with optimization, to use the i386 specific inline assembly
3099 # and go faster for tests.
3100 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003101 scripts/config.py full
Gilles Peskine6fa69862021-10-05 09:36:03 +02003102 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003103
Gilles Peskine6fa69862021-10-05 09:36:03 +02003104 msg "test: i386, make, gcc -O2 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003105 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003106
Gilles Peskine6fa69862021-10-05 09:36:03 +02003107 msg "test ssl-opt.sh, i386, make, gcc-O2"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003108 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003109}
Gilles Peskine3daa83e2021-10-07 19:25:29 +02003110support_test_m32_o2 () {
Gilles Peskine878cf602019-01-06 20:50:38 +00003111 support_test_m32_o0 "$@"
3112}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003113
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003114component_test_m32_everest () {
3115 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003116 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
3117 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02003118 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003119
3120 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
3121 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003122
3123 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003124 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01003125
3126 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
3127 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003128 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003129}
3130support_test_m32_everest () {
3131 support_test_m32_o0 "$@"
3132}
3133
Gilles Peskine8f073122018-11-27 15:58:47 +01003134component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003135 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003136 scripts/config.py full
Dave Rodgmance04f242024-01-04 10:34:31 +00003137 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003138
3139 msg "test: 64-bit ILP32, make, gcc"
3140 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01003141}
Gilles Peskine878cf602019-01-06 20:50:38 +00003142support_test_mx32 () {
3143 case $(uname -m) in
3144 amd64|x86_64) true;;
3145 *) false;;
3146 esac
3147}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003148
Peter Kolbus60c6da22018-12-27 06:59:04 -06003149component_test_min_mpi_window_size () {
3150 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003151 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06003152 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3153 make
3154
3155 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
3156 make test
3157}
3158
Gilles Peskine8f073122018-11-27 15:58:47 +01003159component_test_have_int32 () {
3160 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003161 scripts/config.py unset MBEDTLS_HAVE_ASM
3162 scripts/config.py unset MBEDTLS_AESNI_C
3163 scripts/config.py unset MBEDTLS_PADLOCK_C
Dave Rodgmance04f242024-01-04 10:34:31 +00003164 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01003165
Gilles Peskine8f073122018-11-27 15:58:47 +01003166 msg "test: gcc, force 32-bit bignum limbs"
3167 make test
3168}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01003169
Gilles Peskine8f073122018-11-27 15:58:47 +01003170component_test_have_int64 () {
3171 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003172 scripts/config.py unset MBEDTLS_HAVE_ASM
3173 scripts/config.py unset MBEDTLS_AESNI_C
3174 scripts/config.py unset MBEDTLS_PADLOCK_C
Dave Rodgmance04f242024-01-04 10:34:31 +00003175 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01003176
Gilles Peskine8f073122018-11-27 15:58:47 +01003177 msg "test: gcc, force 64-bit bignum limbs"
3178 make test
3179}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003180
Gilles Peskine8f073122018-11-27 15:58:47 +01003181component_test_no_udbl_division () {
3182 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003183 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003184 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01003185 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003186
Gilles Peskine8f073122018-11-27 15:58:47 +01003187 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
3188 make test
3189}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003190
Gilles Peskine8f073122018-11-27 15:58:47 +01003191component_test_no_64bit_multiplication () {
3192 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003193 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003194 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01003195 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003196
Gilles Peskine8f073122018-11-27 15:58:47 +01003197 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
3198 make test
3199}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003200
Gilles Peskine3809f5f2020-11-09 15:40:05 +01003201component_test_no_strings () {
3202 msg "build: no strings" # ~10s
3203 scripts/config.py full
3204 # Disable options that activate a large amount of string constants.
3205 scripts/config.py unset MBEDTLS_DEBUG_C
3206 scripts/config.py unset MBEDTLS_ERROR_C
3207 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
3208 scripts/config.py unset MBEDTLS_VERSION_FEATURES
3209 make CFLAGS='-Werror -Os'
3210
3211 msg "test: no strings" # ~ 10s
3212 make test
3213}
3214
Gilles Peskine8f073122018-11-27 15:58:47 +01003215component_build_arm_none_eabi_gcc () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003216 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003217 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02003218 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 +02003219
Gilles Peskine60d99472021-09-01 20:00:33 +02003220 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003221 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003222}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003223
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003224component_build_arm_linux_gnueabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003225 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003226 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02003227 # Build for a target platform that's close to what Debian uses
3228 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
Dave Rodgman52af7692022-03-31 14:27:24 +01003229 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003230 # Build everything including programs, see for example
Dave Rodgman52af7692022-03-31 14:27:24 +01003231 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003232 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'
3233
Gilles Peskine60d99472021-09-01 20:00:33 +02003234 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003235 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size library/*.o
3236}
3237support_build_arm_linux_gnueabi_gcc_arm5vte () {
3238 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
3239}
3240
3241component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003242 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003243 scripts/config.py baremetal
3244 # This is an imperfect substitute for
3245 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnard9a260a62021-07-06 09:44:59 +02003246 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02003247 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 +02003248
Gilles Peskine60d99472021-09-01 20:00:33 +02003249 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003250 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02003251}
3252
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003253component_build_arm_none_eabi_gcc_m0plus () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003254 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
3255 scripts/config.py baremetal_size
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 -Wall -Wextra -mthumb -mcpu=cortex-m0plus -Os' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02003257
Gilles Peskine60d99472021-09-01 20:00:33 +02003258 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
Gilles Peskine18487f62020-04-30 23:11:54 +02003259 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003260}
3261
Gilles Peskine8f073122018-11-27 15:58:47 +01003262component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003263 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003264 scripts/config.py baremetal
3265 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003266 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 +01003267 echo "Checking that software 64-bit division is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003268 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003269}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003270
Gilles Peskine8f073122018-11-27 15:58:47 +01003271component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003272 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003273 scripts/config.py baremetal
3274 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003275 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 +01003276 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003277 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003278}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003279
Dave Rodgman43ea9ab2023-06-02 10:26:24 -04003280component_build_arm_clang_thumb () {
3281 # ~ 30s
3282
3283 scripts/config.py baremetal
3284
3285 msg "build: clang thumb 2, make"
3286 make clean
3287 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
3288
3289 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
3290 msg "build: clang thumb 1 -O0, make"
3291 make clean
3292 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
3293
3294 msg "build: clang thumb 1 -Os, make"
3295 make clean
3296 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
3297}
3298
Gilles Peskine8f073122018-11-27 15:58:47 +01003299component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02003300 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003301 scripts/config.py baremetal
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003302 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02003303
3304 msg "size: ARM Compiler 5"
3305 "$ARMC5_FROMELF" -z library/*.o
3306
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003307 make clean
Andres AG87bb5772016-09-27 15:05:15 +01003308
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003309 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
3310
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003311 # ARM Compiler 6 - Target ARMv7-A
3312 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003313
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003314 # ARM Compiler 6 - Target ARMv7-M
3315 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02003316
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003317 # ARM Compiler 6 - Target ARMv8-A - AArch32
3318 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003319
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003320 # ARM Compiler 6 - Target ARMv8-M
3321 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02003322
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003323 # ARM Compiler 6 - Target ARMv8-A - AArch64
3324 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003325
3326 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
3327 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
3328
3329 # ARM Compiler 6 - Target Cortex-M0
3330 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
Gilles Peskine8f073122018-11-27 15:58:47 +01003331}
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003332
Pengyu Lvd216c042023-03-03 18:23:35 +08003333support_build_armcc () {
3334 armc5_cc="$ARMC5_BIN_DIR/armcc"
3335 armc6_cc="$ARMC6_BIN_DIR/armclang"
3336 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
3337}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01003338
Manuel Pégourié-Gonnarddd8807f2020-02-26 09:56:27 +01003339component_build_ssl_hw_record_accel() {
3340 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
3341 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
3342 make CFLAGS='-Werror -O1'
3343}
3344
Hanno Beckera711f6e2020-05-04 12:03:51 +01003345component_test_tls13_experimental () {
3346 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3347 scripts/config.pl set MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
3348 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3349 make
3350 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3351 make test
3352}
3353
Gilles Peskine8f073122018-11-27 15:58:47 +01003354component_build_mingw () {
3355 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003356 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 +00003357
Gilles Peskine8f073122018-11-27 15:58:47 +01003358 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003359 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 +01003360 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02003361
Gilles Peskine8f073122018-11-27 15:58:47 +01003362 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003363 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
3364 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 +01003365 make WINDOWS_BUILD=1 clean
Pengyu Lvb2ca0322023-10-19 17:17:19 +08003366
3367 msg "build: Windows cross build - mingw64, make (Library only, AESNI intrinsics)" # ~ 30s
3368 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 +08003369 make WINDOWS_BUILD=1 clean
3370
3371 msg "build: Windows cross build - mingw64, make (Library only, default config without MBEDTLS_AESNI_C)" # ~ 30s
3372 ./scripts/config.py unset MBEDTLS_AESNI_C
3373 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib
3374 make WINDOWS_BUILD=1 clean
Pengyu Lvb2ca0322023-10-19 17:17:19 +08003375 }
Jaeden Amero117b8a42019-04-17 15:19:26 +01003376support_build_mingw() {
Pengyu Lva19ce122023-02-24 15:38:52 +08003377 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
3378 [0-5]*|"") false;;
Jaeden Amero117b8a42019-04-17 15:19:26 +01003379 *) true;;
3380 esac
3381}
Simon Butcher91aef332016-11-17 09:20:50 +00003382
Gilles Peskine8f073122018-11-27 15:58:47 +01003383component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003384 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003385 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003386 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
3387 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02003388
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003389 msg "test: main suites (MSan)" # ~ 10s
3390 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003391
Gilles Peskineee8af062023-11-02 19:58:03 +01003392 msg "test: metatests (MSan)"
3393 tests/scripts/run-metatests.sh any msan
3394
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02003395 msg "program demos (MSan)" # ~20s
3396 tests/scripts/run_demos.py
3397
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003398 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003399 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003400
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003401 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003402
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003403 if [ "$MEMORY" -gt 0 ]; then
3404 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003405 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003406 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003407}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003408
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01003409component_release_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003410 msg "build: Release (clang)"
Gilles Peskine619b73d2022-11-29 16:45:30 +01003411 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003412 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3413 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003414
Gilles Peskine619b73d2022-11-29 16:45:30 +01003415 msg "test: main suites, Valgrind (default config)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003416 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003417
Gilles Peskine636c26a2020-03-04 20:46:15 +01003418 # Optional parts (slow; currently broken on OS X because programs don't
3419 # seem to receive signals under valgrind on OS X).
Gilles Peskine619b73d2022-11-29 16:45:30 +01003420 # These optional parts don't run on the CI.
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003421 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003422 msg "test: ssl-opt.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003423 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003424 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003425
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003426 if [ "$MEMORY" -gt 1 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003427 msg "test: compat.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003428 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003429 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003430
3431 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003432 msg "test: context-info.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003433 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003434 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003435}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003436
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01003437component_release_test_valgrind_psa () {
Gilles Peskine619b73d2022-11-29 16:45:30 +01003438 msg "build: Release, full (clang)"
3439 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
3440 scripts/config.py full
3441 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3442 make
3443
3444 msg "test: main suites, Valgrind (full config)"
3445 make memcheck
3446}
3447
Paul Elliott2ab9a7a2021-11-25 17:29:40 +00003448support_test_cmake_out_of_source () {
3449 distrib_id=""
3450 distrib_ver=""
3451 distrib_ver_minor=""
3452 distrib_ver_major=""
3453
3454 # Attempt to parse lsb-release to find out distribution and version. If not
3455 # found this should fail safe (test is supported).
3456 if [[ -f /etc/lsb-release ]]; then
3457
3458 while read -r lsb_line; do
3459 case "$lsb_line" in
3460 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
3461 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
3462 esac
3463 done < /etc/lsb-release
3464
3465 distrib_ver_major="${distrib_ver%%.*}"
3466 distrib_ver="${distrib_ver#*.}"
3467 distrib_ver_minor="${distrib_ver%%.*}"
3468 fi
3469
3470 # Running the out of source CMake test on Ubuntu 16.04 using more than one
3471 # processor (as the CI does) can create a race condition whereby the build
3472 # fails to see a generated file, despite that file actually having been
3473 # generated. This problem appears to go away with 18.04 or newer, so make
3474 # the out of source tests unsupported on Ubuntu 16.04.
3475 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
3476}
3477
Gilles Peskine8f073122018-11-27 15:58:47 +01003478component_test_cmake_out_of_source () {
3479 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01003480 MBEDTLS_ROOT_DIR="$PWD"
3481 mkdir "$OUT_OF_SOURCE_DIR"
3482 cd "$OUT_OF_SOURCE_DIR"
Gilles Peskine25319702021-10-07 19:34:57 +02003483 cmake -D CMAKE_BUILD_TYPE:String=Check "$MBEDTLS_ROOT_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003484 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003485
Gilles Peskine8f073122018-11-27 15:58:47 +01003486 msg "test: cmake 'out-of-source' build"
3487 make test
3488 # Test an SSL option that requires an auxiliary script in test/scripts/.
3489 # Also ensure that there are no error messages such as
3490 # "No such file or directory", which would indicate that some required
3491 # file is missing (ssl-opt.sh tolerates the absence of some files so
3492 # may exit with status 0 but emit errors).
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003493 ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' >ssl-opt.out 2>ssl-opt.err
3494 grep PASS ssl-opt.out
Gilles Peskine0a7984f2020-03-28 18:56:09 +01003495 cat ssl-opt.err >&2
3496 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003497 [ ! -s ssl-opt.err ]
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003498 rm ssl-opt.out ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01003499 cd "$MBEDTLS_ROOT_DIR"
3500 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003501}
Andres AGdc192212016-08-31 17:33:13 +01003502
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003503component_test_cmake_as_subdirectory () {
3504 msg "build: cmake 'as-subdirectory' build"
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003505 cd programs/test/cmake_subproject
3506 cmake .
3507 make
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003508 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003509}
Gilles Peskineca9cfca2022-02-04 00:21:12 +01003510support_test_cmake_as_subdirectory () {
3511 support_test_cmake_out_of_source
3512}
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003513
David Horstmann175afbd2023-01-12 14:17:01 +00003514component_build_cmake_custom_config_file () {
David Horstmann67622312023-01-31 10:34:44 +00003515 # Make a copy of config file to use for the in-tree test
3516 cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h
David Horstmann175afbd2023-01-12 14:17:01 +00003517
3518 MBEDTLS_ROOT_DIR="$PWD"
3519 mkdir "$OUT_OF_SOURCE_DIR"
3520 cd "$OUT_OF_SOURCE_DIR"
3521
David Horstmann67622312023-01-31 10:34:44 +00003522 # Build once to get the generated files (which need an intact config file)
David Horstmann175afbd2023-01-12 14:17:01 +00003523 cmake "$MBEDTLS_ROOT_DIR"
3524 make
3525
3526 msg "build: cmake with -DMBEDTLS_CONFIG_FILE"
3527 scripts/config.py -w full_config.h full
David Horstmann67622312023-01-31 10:34:44 +00003528 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003529 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR"
3530 make
3531
3532 msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
3533 # In the user config, disable one feature (for simplicity, pick a feature
3534 # that nothing else depends on).
3535 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3536
3537 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR"
3538 make
3539 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3540
3541 rm -f user_config.h full_config.h
3542
3543 cd "$MBEDTLS_ROOT_DIR"
3544 rm -rf "$OUT_OF_SOURCE_DIR"
3545
3546 # Now repeat the test for an in-tree build:
3547
David Horstmann67622312023-01-31 10:34:44 +00003548 # Restore config for the in-tree test
3549 mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003550
David Horstmann67622312023-01-31 10:34:44 +00003551 # Build once to get the generated files (which need an intact config)
David Horstmann175afbd2023-01-12 14:17:01 +00003552 cmake .
3553 make
3554
3555 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE"
3556 scripts/config.py -w full_config.h full
David Horstmann67622312023-01-31 10:34:44 +00003557 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003558 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h .
3559 make
3560
3561 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
3562 # In the user config, disable one feature (for simplicity, pick a feature
3563 # that nothing else depends on).
3564 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3565
3566 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h .
3567 make
3568 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3569
3570 rm -f user_config.h full_config.h
3571}
3572support_build_cmake_custom_config_file () {
3573 support_test_cmake_out_of_source
3574}
3575
3576
Tom Cosgrove51170622023-09-01 10:40:15 +01003577component_build_zeroize_checks () {
3578 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
3579
3580 scripts/config.py full
3581
3582 # Only compile - we're looking for sizeof-pointer-memaccess warnings
Dave Rodgman374b1882024-01-04 10:30:57 +00003583 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 +01003584}
3585
3586
Gilles Peskine8f073122018-11-27 15:58:47 +01003587component_test_zeroize () {
3588 # Test that the function mbedtls_platform_zeroize() is not optimized away by
3589 # different combinations of compilers and optimization flags by using an
3590 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
3591 # system in all cases that the script fails, so we must manually search the
3592 # output to check whether the pass string is present and no failure strings
3593 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01003594
Gilles Peskine4976e822019-01-06 19:52:22 +00003595 # Don't try to disable ASLR. We don't care about ASLR here. We do care
3596 # about a spurious message if Gdb tries and fails, so suppress that.
3597 gdb_disable_aslr=
3598 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
3599 gdb_disable_aslr='set disable-randomization off'
3600 fi
3601
Gilles Peskine8f073122018-11-27 15:58:47 +01003602 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01003603 for compiler in clang gcc; do
3604 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
3605 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003606 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
3607 grep "The buffer was correctly zeroized" test_zeroize.log
3608 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01003609 rm -f test_zeroize.log
3610 make clean
3611 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01003612 done
Gilles Peskine8f073122018-11-27 15:58:47 +01003613}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003614
Bence Szépkúti9f849112021-10-19 15:05:36 +02003615component_test_psa_compliance () {
Dave Rodgmanb0660c22023-12-18 19:55:40 +00003616 # The arch tests build with gcc, so require use of gcc here to link properly
Bence Szépkútic1e79fd2021-11-11 20:13:14 +01003617 msg "build: make, default config + CMAC, libmbedcrypto.a only"
3618 scripts/config.py set MBEDTLS_CMAC_C
Dave Rodgmanb0660c22023-12-18 19:55:40 +00003619 CC=gcc make -C library libmbedcrypto.a
Bence Szépkúti9f849112021-10-19 15:05:36 +02003620
3621 msg "unit test: test_psa_compliance.py"
Dave Rodgman5b00fb12023-12-18 22:29:56 +00003622 CC=gcc ./tests/scripts/test_psa_compliance.py
Bence Szépkúti9f849112021-10-19 15:05:36 +02003623}
3624
3625support_test_psa_compliance () {
Bence Szépkútid6cf0892021-11-03 11:36:09 +01003626 # psa-compliance-tests only supports CMake >= 3.10.0
Bence Szépkútiab796e62021-10-25 19:29:07 +02003627 ver="$(cmake --version)"
3628 ver="${ver#cmake version }"
3629 ver_major="${ver%%.*}"
3630
3631 ver="${ver#*.}"
3632 ver_minor="${ver%%.*}"
3633
3634 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
Bence Szépkúti9f849112021-10-19 15:05:36 +02003635}
3636
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003637component_check_code_style () {
3638 msg "Check C code style"
3639 ./scripts/code_style.py
David Horstmanne09c4762022-11-10 18:30:52 +00003640}
3641
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003642support_check_code_style() {
David Horstmanne09c4762022-11-10 18:30:52 +00003643 case $(uncrustify --version) in
3644 *0.75.1*) true;;
3645 *) false;;
3646 esac
3647}
3648
Gilles Peskine8f073122018-11-27 15:58:47 +01003649component_check_python_files () {
3650 msg "Lint: Python scripts"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003651 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003652}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003653
Gilles Peskine8f073122018-11-27 15:58:47 +01003654component_check_generate_test_code () {
3655 msg "uint test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02003656 # unittest writes out mundane stuff like number or tests run on stderr.
3657 # Our convention is to reserve stderr for actual errors, and write
3658 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003659 ./tests/scripts/test_generate_test_code.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01003660}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003661
3662################################################################
3663#### Termination
3664################################################################
3665
Gilles Peskine8f073122018-11-27 15:58:47 +01003666post_report () {
3667 msg "Done, cleaning up"
Gilles Peskine24bdf022020-03-30 20:11:39 +02003668 final_cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003669
Gilles Peskine8f073122018-11-27 15:58:47 +01003670 final_report
3671}
3672
3673
3674
3675################################################################
3676#### Run all the things
3677################################################################
3678
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003679# Function invoked by --error-test to test error reporting.
3680pseudo_component_error_test () {
Gilles Peskine202e9b42021-08-02 23:28:00 +02003681 msg "Testing error reporting $error_test_i"
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003682 if [ $KEEP_GOING -ne 0 ]; then
3683 echo "Expect three failing commands."
3684 fi
Gilles Peskine202e9b42021-08-02 23:28:00 +02003685 # If the component doesn't run in a subshell, changing error_test_i to an
3686 # invalid integer will cause an error in the loop that runs this function.
3687 error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003688 # Expected error: 'grep non_existent /dev/null -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003689 grep non_existent /dev/null
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003690 # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003691 not grep -q . "$0"
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003692 # Expected error: 'make unknown_target -> 2'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003693 make unknown_target
3694 false "this should not be executed"
3695}
3696
Gilles Peskinee48351a2018-11-27 16:06:30 +01003697# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01003698run_component () {
Gilles Peskineffcdeff2018-12-04 12:49:28 +01003699 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02003700 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003701
3702 # Unconditionally create a seedfile that's sufficiently long.
3703 # Do this before each component, because a previous component may
3704 # have messed it up or shortened it.
Gilles Peskinef3133362021-07-08 19:03:50 +02003705 local dd_cmd
3706 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
3707 case $OSTYPE in
3708 linux*|freebsd*|openbsd*|darwin*) dd_cmd+=(status=none)
3709 esac
3710 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003711
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003712 # Run the component in a subshell, with error trapping and output
3713 # redirection set up based on the relevant options.
Gilles Peskine7105a332020-03-28 18:50:43 +01003714 if [ $KEEP_GOING -eq 1 ]; then
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003715 # We want to keep running if the subshell fails, so 'set -e' must
3716 # be off when the subshell runs.
Gilles Peskine7105a332020-03-28 18:50:43 +01003717 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02003718 fi
Gilles Peskine7105a332020-03-28 18:50:43 +01003719 (
3720 if [ $QUIET -eq 1 ]; then
3721 # msg() will be silenced, so just print the component name here.
3722 echo "${current_component#component_}"
3723 exec >/dev/null
3724 fi
3725 if [ $KEEP_GOING -eq 1 ]; then
3726 # Keep "set -e" off, and run an ERR trap instead to record failures.
3727 set -E
3728 trap err_trap ERR
3729 fi
3730 # The next line is what runs the component
3731 "$@"
3732 if [ $KEEP_GOING -eq 1 ]; then
3733 trap - ERR
3734 exit $last_failure_status
3735 fi
3736 )
3737 component_status=$?
3738 if [ $KEEP_GOING -eq 1 ]; then
3739 set -e
3740 if [ $component_status -ne 0 ]; then
3741 failure_count=$((failure_count + 1))
3742 fi
3743 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003744
3745 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01003746 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02003747 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01003748}
3749
3750# Preliminary setup
3751pre_check_environment
Dave Rodgmana0b7c082024-01-16 17:33:27 +00003752pre_initialize_variables "$@"
Gilles Peskine8f073122018-11-27 15:58:47 +01003753pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01003754
Gilles Peskine878cf602019-01-06 20:50:38 +00003755pre_check_git
Gilles Peskineef64e7f2021-07-12 18:16:01 +02003756pre_restore_files
Gilles Peskine24bdf022020-03-30 20:11:39 +02003757pre_back_up
Andrzej Kurekeb508712019-02-14 07:18:59 -05003758
Gilles Peskine878cf602019-01-06 20:50:38 +00003759build_status=0
3760if [ $KEEP_GOING -eq 1 ]; then
3761 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01003762fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02003763pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00003764pre_print_configuration
3765pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003766cleanup
3767
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003768# Run the requested tests.
Gilles Peskine202e9b42021-08-02 23:28:00 +02003769for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003770 run_component pseudo_component_error_test
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003771done
Gilles Peskine202e9b42021-08-02 23:28:00 +02003772unset error_test_i
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003773for component in $RUN_COMPONENTS; do
3774 run_component "component_$component"
3775done
Gilles Peskine8f073122018-11-27 15:58:47 +01003776
3777# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00003778post_report