blob: 86259008012f1b358d10cbc2917b08cecc194405 [file] [log] [blame]
Gilles Peskine3de7be82020-03-27 16:35:23 +01001#! /usr/bin/env bash
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
Bence Szépkúti1e148272020-08-07 13:07:28 +02005# Copyright The Mbed TLS Contributors
Dave Rodgman7ff79652023-11-03 12:04:52 +00006# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskine192c72f2017-12-21 15:59:21 +01007
8
9
10################################################################
11#### Documentation
12################################################################
13
Simon Butcher3ea7f522016-03-07 23:22:10 +000014# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010015# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000016#
SimonB2e23c822016-04-16 21:54:39 +010017# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010018#
Gilles Peskine192c72f2017-12-21 15:59:21 +010019# Notes for users
20# ---------------
21#
SimonB2e23c822016-04-16 21:54:39 +010022# Warning: the test is destructive. It includes various build modes and
23# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010024# configuration. The following files must be committed into git:
25# * include/mbedtls/config.h
Gilles Peskine636c26a2020-03-04 20:46:15 +010026# * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
27# programs/fuzz/Makefile
Gilles Peskine192c72f2017-12-21 15:59:21 +010028# After running this script, the CMake cache will be lost and CMake
29# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# The script assumes the presence of a number of tools:
32# * Basic Unix tools (Windows users note: a Unix-style find must be before
33# the Windows find in the PATH)
34# * Perl
35# * GNU Make
36# * CMake
37# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040038# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010039# * arm-gcc and mingw-gcc
40# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine549a9612023-08-27 21:39:21 +020041# * OpenSSL and GnuTLS command line tools, in suitable versions for the
42# interoperability tests. The following are the official versions at the
43# time of writing:
44# * GNUTLS_{CLI,SERV} = 3.4.10
45# * GNUTLS_NEXT_{CLI,SERV} = 3.7.2
46# * OPENSSL_LEGACY = 1.0.1j
47# * OPENSSL = 1.0.2g (without Debian/Ubuntu patches)
48# * OPENSSL_NEXT = 1.1.1a
Gilles Peskine192c72f2017-12-21 15:59:21 +010049# See the invocation of check_tools below for details.
50#
51# This script must be invoked from the toplevel directory of a git
52# working copy of Mbed TLS.
53#
Gilles Peskine7105a332020-03-28 18:50:43 +010054# The behavior on an error depends on whether --keep-going (alias -k)
55# is in effect.
56# * Without --keep-going: the script stops on the first error without
57# cleaning up. This lets you work in the configuration of the failing
58# component.
59# * With --keep-going: the script runs all requested components and
60# reports failures at the end. In particular the script always cleans
61# up on exit.
62#
Gilles Peskine192c72f2017-12-21 15:59:21 +010063# Note that the output is not saved. You may want to run
64# script -c tests/scripts/all.sh
65# or
66# tests/scripts/all.sh >all.log 2>&1
67#
68# Notes for maintainers
69# ---------------------
70#
Gilles Peskine8f073122018-11-27 15:58:47 +010071# The bulk of the code is organized into functions that follow one of the
72# following naming conventions:
73# * pre_XXX: things to do before running the tests, in order.
74# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010075# * component_check_XXX: quick tests that aren't worth parallelizing.
76# * component_build_XXX: build things but don't run them.
77# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000078# * support_XXX: if support_XXX exists and returns false then
79# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010080# * post_XXX: things to do after running the tests.
81# * other: miscellaneous support functions.
82#
Gilles Peskinec70637a2019-01-09 22:29:17 +010083# Each component must start by invoking `msg` with a short informative message.
84#
Gilles Peskine39a3b112020-03-28 21:27:40 +010085# Warning: due to the way bash detects errors, the failure of a command
86# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
87#
Gilles Peskine7105a332020-03-28 18:50:43 +010088# Each component is executed in a separate shell process. The component
89# fails if any command in it returns a non-zero status.
90#
Gilles Peskinec70637a2019-01-09 22:29:17 +010091# The framework performs some cleanup tasks after each component. This
92# means that components can assume that the working directory is in a
93# cleaned-up state, and don't need to perform the cleanup themselves.
94# * Run `make clean`.
95# * Restore `include/mbedtks/config.h` from a backup made before running
96# the component.
Gilles Peskine636c26a2020-03-04 20:46:15 +010097# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
98# `tests/Makefile` and `programs/fuzz/Makefile` from git.
99# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +0100100#
Gilles Peskine192c72f2017-12-21 15:59:21 +0100101# The tests are roughly in order from fastest to slowest. This doesn't
102# have to be exact, but in general you should add slower tests towards
103# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100104
105
106
107################################################################
108#### Initialization and command line parsing
109################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100110
Gilles Peskine8ab29942020-03-28 18:50:49 +0100111# Abort on errors (even on the left-hand side of a pipe).
112# Treat uninitialised variables as errors.
113set -e -o pipefail -u
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100114
Gilles Peskine79598582022-08-30 21:02:44 +0200115# Enable ksh/bash extended file matching patterns
116shopt -s extglob
117
Gilles Peskine8f073122018-11-27 15:58:47 +0100118pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000119 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskinef08ca832023-09-12 19:21:54 +0200120 echo "Must be run from Mbed TLS root" >&2
Gilles Peskine8f073122018-11-27 15:58:47 +0100121 exit 1
122 fi
123}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100124
Gilles Peskine8f073122018-11-27 15:58:47 +0100125pre_initialize_variables () {
126 CONFIG_H='include/mbedtls/config.h'
John Durkopbd069d32020-10-31 22:14:03 -0700127 CRYPTO_CONFIG_H='include/psa/crypto_config.h'
Gilles Peskine24bdf022020-03-30 20:11:39 +0200128
129 # Files that are clobbered by some jobs will be backed up. Use a different
130 # suffix from auxiliary scripts so that all.sh and auxiliary scripts can
131 # independently decide when to remove the backup file.
132 backup_suffix='.all.bak'
133 # Files clobbered by config.py
134 files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H"
Gilles Peskineef64e7f2021-07-12 18:16:01 +0200135 # Files clobbered by in-tree cmake
136 files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200137
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200138 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100139 MEMORY=0
140 FORCE=0
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200141 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100142 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100143
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200144 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard54304472020-06-22 10:11:47 +0200145 #
146 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
147 # both values are kept in sync. If you change the value here because it
148 # breaks some tests, you'll definitely want to change it in
149 # basic-build-test.sh as well.
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200150 RELEASE_SEED=1
151
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200152 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200153 : ${MBEDTLS_TEST_PLATFORM="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200154 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200155 export MBEDTLS_TEST_PLATFORM
156
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000157 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100158 : ${OPENSSL:="openssl"}
159 : ${OPENSSL_LEGACY:="$OPENSSL"}
160 : ${OPENSSL_NEXT:="$OPENSSL"}
161 : ${GNUTLS_CLI:="gnutls-cli"}
162 : ${GNUTLS_SERV:="gnutls-serv"}
Gilles Peskine8f073122018-11-27 15:58:47 +0100163 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
164 : ${ARMC5_BIN_DIR:=/usr/bin}
165 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskine6d061342020-04-30 18:19:32 +0200166 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200167 : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
Gowtham Suresh Kumarcc029af2023-08-01 09:48:32 +0100168 : ${CLANG_LATEST:="clang-latest"}
169 : ${CLANG_EARLIEST:="clang-earliest"}
170 : ${GCC_LATEST:="gcc-latest"}
171 : ${GCC_EARLIEST:="gcc-earliest"}
Andres AGdc192212016-08-31 17:33:13 +0100172
Gilles Peskine8f073122018-11-27 15:58:47 +0100173 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000174 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine85229ac2021-09-30 18:24:21 +0200175 export MAKEFLAGS="-j$(all_sh_nproc)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100176 fi
Dave Rodgmane0a2f6d2023-12-18 19:53:25 +0000177 # if CC is not set, use clang by default (if present) to improve build times
178 if [ -z "${CC+set}" ] && (type clang > /dev/null 2>&1); then
Dave Rodgmane42c2352023-12-19 16:08:19 +0000179 export CC="clang"
Dave Rodgman62be4562023-12-18 18:34:50 +0000180 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000181
Gilles Peskinec761d8f2021-09-20 18:57:55 +0200182 # Include more verbose output for failing tests run by CMake or make
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000183 export CTEST_OUTPUT_ON_FAILURE=1
184
Gilles Peskine8fd59422019-10-21 17:11:33 +0200185 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Manuel Pégourié-Gonnard717f2302022-11-30 10:42:03 +0100186 # default to -O2, use -Ox _after_ this if you want another level
Manuel Pégourié-Gonnard154b84e2022-11-28 13:12:10 +0100187 ASAN_CFLAGS='-O2 -Werror -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200188
Andrzej Kurekd95b8ed2023-06-27 10:02:09 -0400189 # Platform tests have an allocation that returns null
190 export ASAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurek6e4a9be2023-07-05 08:32:43 -0400191 export MSAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurekd95b8ed2023-06-27 10:02:09 -0400192
Gilles Peskine878cf602019-01-06 20:50:38 +0000193 # Gather the list of available components. These are the functions
194 # defined in this script whose name starts with "component_".
Gowtham Suresh Kumar13850f32023-07-28 16:41:21 +0100195 ALL_COMPONENTS=$(compgen -A function component_ | sed 's/component_//')
Gilles Peskine878cf602019-01-06 20:50:38 +0000196
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100197 # Delay determinig SUPPORTED_COMPONENTS until the command line options have a chance to override
198 # the commands set by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100199}
Andres AG38495a32016-07-12 16:54:33 +0100200
Gilles Peskinea28db922019-01-10 00:05:18 +0100201# Test whether the component $1 is included in the command line patterns.
202is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100203{
Gilles Peskine6702ce92021-08-06 11:35:17 +0200204 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
205 # only does word splitting.
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100206 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000207 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100208 set +f
209 case ${1#component_} in $pattern) return 0;; esac
210 done
211 set +f
212 return 1
213}
Andres AG7770ea82016-10-10 15:46:20 +0100214
Simon Butcher41eeccf2016-09-07 00:07:09 +0100215usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100216{
Gilles Peskine709346a2017-12-10 23:43:39 +0100217 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100218Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100219Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100220By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100221COMPONENT can be the name of a component or a shell wildcard pattern.
222
223Examples:
224 $0 "check_*"
225 Run all sanity checks.
226 $0 --no-armcc --except test_memsan
227 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100228
229Special options:
230 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000231 --list-all-components List all available test components and exit.
232 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100233
234General options:
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200235 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100236 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100237 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100238 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200239 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200240 --arm-none-eabi-gcc-prefix=<string>
241 Prefix for a cross-compiler for arm-none-eabi
242 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200243 --arm-linux-gnueabi-gcc-prefix=<string>
244 Prefix for a cross-compiler for arm-linux-gnueabi
245 (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100246 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200247 --restore First clean up the build tree, restoring backed up
248 files. Do not run any components unless they are
249 explicitly specified.
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100250 --error-test Error test mode: run a failing function in addition
Gilles Peskinea25c5672021-08-05 15:11:33 +0200251 to any specified component. May be repeated.
Gilles Peskinea28db922019-01-10 00:05:18 +0100252 --except Exclude the COMPONENTs listed on the command line,
253 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200254 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100255 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100256 --no-force Refuse to overwrite modified files (default).
257 --no-keep-going Stop at the first error (default).
258 --no-memory No additional memory tests (default).
Shaun Case0e7791f2021-12-20 21:14:10 -0800259 --no-quiet Print full output from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100260 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200261 --outcome-file=<path> File where test outcomes are written (not done if
262 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100263 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200264 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100265 -s|--seed Integer seed value to use for this test run.
266
267Tool path options:
268 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
269 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100270 --clang-earliest=<Clang_earliest_path> Earliest version of clang available
271 --clang-latest=<Clang_latest_path> Latest version of clang available
272 --gcc-earliest=<GCC_earliest_path> Earliest version of GCC available
273 --gcc-latest=<GCC_latest_path> Latest version of GCC available
Gilles Peskine709346a2017-12-10 23:43:39 +0100274 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
275 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
Gilles Peskine709346a2017-12-10 23:43:39 +0100276 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
277 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100278 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100279EOF
SimonB2e23c822016-04-16 21:54:39 +0100280}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100281
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200282# Cleanup before/after running a component.
283# Remove built files as well as the cmake cache/config.
284# Does not remove generated source files.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100285cleanup()
286{
Gilles Peskine7c652162017-12-11 00:01:40 +0100287 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200288
Gilles Peskine31b07e22018-03-21 12:15:06 +0100289 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000290 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100291 -iname CMakeFiles -exec rm -rf {} \+ -o \
292 \( -iname cmake_install.cmake -o \
293 -iname CTestTestfile.cmake -o \
294 -iname CMakeCache.txt \) -exec rm {} \+
295 # Recover files overwritten by in-tree CMake builds
Gilles Peskine79598582022-08-30 21:02:44 +0200296 rm -f include/Makefile include/mbedtls/Makefile programs/!(fuzz)/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200297
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100298 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
299 rm -rf programs/test/cmake_subproject/build
300 rm -f programs/test/cmake_subproject/Makefile
301 rm -f programs/test/cmake_subproject/cmake_subproject
302
Gilles Peskine24bdf022020-03-30 20:11:39 +0200303 # Restore files that may have been clobbered by the job
304 for x in $files_to_back_up; do
Gilles Peskine423dd132022-08-30 21:02:00 +0200305 if [[ -e "$x$backup_suffix" ]]; then
306 cp -p "$x$backup_suffix" "$x"
307 fi
Gilles Peskine24bdf022020-03-30 20:11:39 +0200308 done
309}
John Durkopbd069d32020-10-31 22:14:03 -0700310
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200311# Final cleanup when this script exits (except when exiting on a failure
312# in non-keep-going mode).
Gilles Peskine24bdf022020-03-30 20:11:39 +0200313final_cleanup () {
314 cleanup
315
316 for x in $files_to_back_up; do
317 rm -f "$x$backup_suffix"
318 done
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100319}
320
Gilles Peskine7c652162017-12-11 00:01:40 +0100321# Executed on exit. May be redefined depending on command line options.
322final_report () {
323 :
324}
325
326fatal_signal () {
Gilles Peskine24bdf022020-03-30 20:11:39 +0200327 final_cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100328 final_report $1
329 trap - $1
330 kill -$1 $$
331}
332
333trap 'fatal_signal HUP' HUP
334trap 'fatal_signal INT' INT
335trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200336
Gilles Peskine85229ac2021-09-30 18:24:21 +0200337# Number of processors on this machine. Used as the default setting
338# for parallel make.
339all_sh_nproc ()
340{
341 {
342 nproc || # Linux
343 sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
344 sysctl -n hw.ncpu || # FreeBSD
345 echo 1
346 } 2>/dev/null
347}
348
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100349msg()
350{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100351 if [ -n "${current_component:-}" ]; then
352 current_section="${current_component#component_}: $1"
353 else
354 current_section="$1"
355 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200356
357 if [ $QUIET -eq 1 ]; then
358 return
359 fi
360
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100361 echo ""
362 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100363 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000364 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100365 echo "******************************************************************"
366}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100367
Gilles Peskine8f073122018-11-27 15:58:47 +0100368armc6_build_test()
369{
370 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100371
Gilles Peskine18487f62020-04-30 23:11:54 +0200372 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100373 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
Dave Rodgman6cda3d32023-03-02 13:39:04 +0000374 WARNING_CFLAGS='-Werror -xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200375
376 msg "size: ARM Compiler 6 ($FLAGS)"
377 "$ARMC6_FROMELF" -z library/*.o
378
Gilles Peskine8f073122018-11-27 15:58:47 +0100379 make clean
380}
Andres AGa5cd9732016-10-17 15:23:10 +0100381
Andres AGd9eba4b2016-08-26 14:42:14 +0100382err_msg()
383{
384 echo "$1" >&2
385}
386
387check_tools()
388{
389 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000390 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100391 err_msg "$TOOL not found!"
392 exit 1
393 fi
394 done
395}
396
Gilles Peskine8f073122018-11-27 15:58:47 +0100397pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000398 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100399 all_except=0
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100400 error_test=0
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100401 list_components=0
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200402 restore_first=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000403 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100404
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000405 # Note that legacy options are ignored instead of being omitted from this
406 # list of options, so invocations that worked with previous version of
407 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100408 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100409 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200410 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200411 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200412 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000413 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100414 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
415 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100416 --clang-earliest) shift; CLANG_EARLIEST="$1";;
417 --clang-latest) shift; CLANG_LATEST="$1";;
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100418 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000419 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100420 --force|-f) FORCE=1;;
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100421 --gcc-earliest) shift; GCC_EARLIEST="$1";;
422 --gcc-latest) shift; GCC_LATEST="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100423 --gnutls-cli) shift; GNUTLS_CLI="$1";;
Gilles Peskine549a9612023-08-27 21:39:21 +0200424 --gnutls-legacy-cli) shift;; # ignored for backward compatibility
425 --gnutls-legacy-serv) shift;; # ignored for backward compatibility
Gilles Peskine55f7c942019-01-09 22:28:21 +0100426 --gnutls-serv) shift; GNUTLS_SERV="$1";;
427 --help|-h) usage; exit;;
428 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000429 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100430 --list-components) list_components=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100431 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200432 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000433 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100434 --no-force) FORCE=0;;
435 --no-keep-going) KEEP_GOING=0;;
436 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200437 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100438 --openssl) shift; OPENSSL="$1";;
439 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
440 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200441 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100442 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200443 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100444 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200445 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200446 --restore) restore_first=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100447 --seed|-s) shift; SEED="$1";;
448 -*)
449 echo >&2 "Unknown option: $1"
450 echo >&2 "Run $0 --help for usage."
451 exit 120
452 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000453 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100454 esac
455 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100456 done
SimonB2e23c822016-04-16 21:54:39 +0100457
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100458 # Exclude components that are not supported on this platform.
459 SUPPORTED_COMPONENTS=
460 for component in $ALL_COMPONENTS; do
461 case $(type "support_$component" 2>&1) in
462 *' function'*)
463 if ! support_$component; then continue; fi;;
464 esac
465 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
466 done
467
468 if [ $list_components -eq 1 ]; then
469 printf '%s\n' $SUPPORTED_COMPONENTS
470 exit
471 fi
472
Gilles Peskinea28db922019-01-10 00:05:18 +0100473 # With no list of components, run everything.
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200474 if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000475 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100476 fi
477
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000478 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
479 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100480 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000481 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100482 fi
SimonB2e23c822016-04-16 21:54:39 +0100483
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200484 # Error out if an explicitly requested component doesn't exist.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100485 if [ $all_except -eq 0 ]; then
486 unsupported=0
Gilles Peskine6702ce92021-08-06 11:35:17 +0200487 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
488 # only does word splitting.
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200489 set -f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100490 for component in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200491 set +f
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200492 # If the requested name includes a wildcard character, don't
493 # check it. Accept wildcard patterns that don't match anything.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100494 case $component in
495 *[*?\[]*) continue;;
496 esac
497 case " $SUPPORTED_COMPONENTS " in
498 *" $component "*) :;;
499 *)
500 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
501 unsupported=$((unsupported + 1));;
502 esac
503 done
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200504 set +f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100505 if [ $unsupported -ne 0 ]; then
506 exit 2
507 fi
508 fi
509
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000510 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100511 RUN_COMPONENTS=
512 for component in $SUPPORTED_COMPONENTS; do
513 if is_component_included "$component"; [ $? -eq $all_except ]; then
514 RUN_COMPONENTS="$RUN_COMPONENTS $component"
515 fi
516 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000517
518 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000519 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100520}
SimonB2e23c822016-04-16 21:54:39 +0100521
Gilles Peskine8f073122018-11-27 15:58:47 +0100522pre_check_git () {
523 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100524 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100525 git checkout-index -f -q $CONFIG_H
526 cleanup
527 else
SimonB2e23c822016-04-16 21:54:39 +0100528
Gilles Peskine8f073122018-11-27 15:58:47 +0100529 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
530 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
531 echo "You can either delete this directory manually, or force the test by rerunning"
532 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
533 exit 1
534 fi
535
Gilles Peskined1174cf2019-01-09 22:30:01 +0100536 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100537 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
538 echo "You can either delete or preserve your work, or force the test by rerunning the"
539 echo "script as: $0 --force"
540 exit 1
541 fi
SimonB2e23c822016-04-16 21:54:39 +0100542 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500543}
544
Gilles Peskineef64e7f2021-07-12 18:16:01 +0200545pre_restore_files () {
546 # If the makefiles have been generated by a framework such as cmake,
547 # restore them from git. If the makefiles look like modifications from
548 # the ones checked into git, take care not to modify them. Whatever
549 # this function leaves behind is what the script will restore before
550 # each component.
551 case "$(head -n1 Makefile)" in
552 *[Gg]enerated*)
553 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
554 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
555 ;;
556 esac
557}
558
Gilles Peskine24bdf022020-03-30 20:11:39 +0200559pre_back_up () {
560 for x in $files_to_back_up; do
561 cp -p "$x" "$x$backup_suffix"
562 done
563}
564
Gilles Peskine8f073122018-11-27 15:58:47 +0100565pre_setup_keep_going () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100566 failure_count=0 # Number of failed components
567 last_failure_status=0 # Last failure status in this component
568
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100569 # See err_trap
570 previous_failure_status=0
571 previous_failed_command=
572 previous_failure_funcall_depth=0
Gilles Peskine39a3b112020-03-28 21:27:40 +0100573 unset report_failed_command
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100574
Gilles Peskine7c652162017-12-11 00:01:40 +0100575 start_red=
576 end_color=
577 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100578 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100579 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
580 start_red=$(printf '\033[31m')
581 end_color=$(printf '\033[0m')
582 ;;
583 esac
584 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100585
586 # Keep a summary of failures in a file. We'll print it out at the end.
587 failure_summary_file=$PWD/all-sh-failures-$$.log
588 : >"$failure_summary_file"
589
590 # Whether it makes sense to keep a component going after the specified
591 # command fails (test command) or not (configure or build).
Gilles Peskine6702ce92021-08-06 11:35:17 +0200592 # This function normally receives the failing simple command
593 # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
594 # this is passed instead.
Gilles Peskine7105a332020-03-28 18:50:43 +0100595 # This doesn't have to be 100% accurate: all failures are recorded anyway.
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200596 # False positives result in running things that can't be expected to
597 # work. False negatives result in things not running after something else
598 # failed even though they might have given useful feedback.
Gilles Peskine7105a332020-03-28 18:50:43 +0100599 can_keep_going_after_failure () {
600 case "$1" in
601 "msg "*) false;;
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200602 "cd "*) false;;
603 *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
604 *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
605 *make*check*) true;;
606 "grep "*) true;;
607 "[ "*) true;;
608 "! "*) true;;
Gilles Peskine7105a332020-03-28 18:50:43 +0100609 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100610 esac
611 }
Gilles Peskine7105a332020-03-28 18:50:43 +0100612
613 # This function runs if there is any error in a component.
614 # It must either exit with a nonzero status, or set
615 # last_failure_status to a nonzero value.
616 err_trap () {
617 # Save $? (status of the failing command). This must be the very
618 # first thing, before $? is overridden.
619 last_failure_status=$?
Gilles Peskine39a3b112020-03-28 21:27:40 +0100620 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskine7105a332020-03-28 18:50:43 +0100621
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100622 if [[ $last_failure_status -eq $previous_failure_status &&
623 "$failed_command" == "$previous_failed_command" &&
624 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
625 then
626 # The same command failed twice in a row, but this time one level
627 # less deep in the function call stack. This happens when the last
628 # command of a function returns a nonzero status, and the function
629 # returns that same status. Ignore the second failure.
630 previous_failure_funcall_depth=${#FUNCNAME[@]}
631 return
632 fi
633 previous_failure_status=$last_failure_status
634 previous_failed_command=$failed_command
635 previous_failure_funcall_depth=${#FUNCNAME[@]}
636
Gilles Peskine7105a332020-03-28 18:50:43 +0100637 text="$current_section: $failed_command -> $last_failure_status"
638 echo "${start_red}^^^^$text^^^^${end_color}" >&2
639 echo "$text" >>"$failure_summary_file"
640
641 # If the command is fatal (configure or build command), stop this
642 # component. Otherwise (test command) keep the component running
643 # (run more tests from the same build).
644 if ! can_keep_going_after_failure "$failed_command"; then
645 exit $last_failure_status
646 fi
647 }
648
Gilles Peskine7c652162017-12-11 00:01:40 +0100649 final_report () {
650 if [ $failure_count -gt 0 ]; then
651 echo
652 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskine7105a332020-03-28 18:50:43 +0100653 echo "${start_red}FAILED: $failure_count components${end_color}"
654 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100655 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
656 elif [ -z "${1-}" ]; then
657 echo "SUCCESS :)"
658 fi
659 if [ -n "${1-}" ]; then
660 echo "Killed by SIG$1."
661 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100662 rm -f "$failure_summary_file"
663 if [ $failure_count -gt 0 ]; then
664 exit 1
665 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100666 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100667}
668
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200669# record_status() and if_build_succeeded() are kept temporarily for backward
670# compatibility. Don't use them in new components.
Gilles Peskine7105a332020-03-28 18:50:43 +0100671record_status () {
672 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100673}
Gilles Peskine7c652162017-12-11 00:01:40 +0100674if_build_succeeded () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100675 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100676}
677
Gilles Peskine39a3b112020-03-28 21:27:40 +0100678# '! true' does not trigger the ERR trap. Arrange to trigger it, with
679# a reasonably informative error message (not just "$@").
680not () {
681 if "$@"; then
682 report_failed_command="! $*"
683 false
684 unset report_failed_command
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200685 fi
686}
687
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200688pre_prepare_outcome_file () {
689 case "$MBEDTLS_TEST_OUTCOME_FILE" in
690 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
691 esac
692 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
693 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
694 fi
695}
696
Gilles Peskine8f073122018-11-27 15:58:47 +0100697pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200698 if [ $QUIET -eq 1 ]; then
699 return
700 fi
701
Gilles Peskine8f073122018-11-27 15:58:47 +0100702 msg "info: $0 configuration"
703 echo "MEMORY: $MEMORY"
704 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200705 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100706 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100707 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100708 echo "OPENSSL: $OPENSSL"
709 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
710 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
711 echo "GNUTLS_CLI: $GNUTLS_CLI"
712 echo "GNUTLS_SERV: $GNUTLS_SERV"
Gilles Peskine8f073122018-11-27 15:58:47 +0100713 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
714 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
715}
Andres AG7770ea82016-10-10 15:46:20 +0100716
Andres AGd9eba4b2016-08-26 14:42:14 +0100717# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100718pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000719 # Build the list of variables to pass to output_env.sh.
720 set env
SimonB2e23c822016-04-16 21:54:39 +0100721
Gilles Peskine87964262019-01-06 22:40:00 +0000722 case " $RUN_COMPONENTS " in
723 # Require OpenSSL and GnuTLS if running any tests (as opposed to
724 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
725 # is a good enough approximation in practice.
726 *" test_"*)
727 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
728 # and ssl-opt.sh, we just export the variables they require.
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +0100729 export OPENSSL="$OPENSSL"
Gilles Peskine87964262019-01-06 22:40:00 +0000730 export GNUTLS_CLI="$GNUTLS_CLI"
731 export GNUTLS_SERV="$GNUTLS_SERV"
732 # Avoid passing --seed flag in every call to ssl-opt.sh
733 if [ -n "${SEED-}" ]; then
734 export SEED
735 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000736 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
737 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000738 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
Gilles Peskine549a9612023-08-27 21:39:21 +0200739 "$GNUTLS_CLI" "$GNUTLS_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000740 ;;
741 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200742
Gilles Peskine87964262019-01-06 22:40:00 +0000743 case " $RUN_COMPONENTS " in
744 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
745 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100746
Gilles Peskine87964262019-01-06 22:40:00 +0000747 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200748 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000749 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100750
Gilles Peskine87964262019-01-06 22:40:00 +0000751 case " $RUN_COMPONENTS " in
752 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
753 esac
754
755 case " $RUN_COMPONENTS " in
756 *" test_zeroize "*) check_tools "gdb";;
757 esac
758
759 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000760 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000761 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
762 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200763 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000764 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
765 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200766 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
767 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
768 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000769 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000770
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200771 # past this point, no call to check_tool, only printing output
772 if [ $QUIET -eq 1 ]; then
773 return
774 fi
775
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000776 msg "info: output_env.sh"
777 case $RUN_COMPONENTS in
778 *_armcc*)
779 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
780 *) set "$@" RUN_ARMCC=0;;
781 esac
782 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100783}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100784
Gilles Peskine192c72f2017-12-21 15:59:21 +0100785
786
787################################################################
788#### Basic checks
789################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100790
791#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200792# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100793#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100794# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200795# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100796# 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 +0200797# time, so start with a GCC build).
798# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100799#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100800# Indicative running times are given for reference.
801
Gilles Peskine8f073122018-11-27 15:58:47 +0100802component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200803 msg "Check: recursion.pl" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200804 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100805}
Janos Follathb72c6782016-07-19 14:54:17 +0100806
Gilles Peskine8f073122018-11-27 15:58:47 +0100807component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200808 msg "Check: freshness of generated source files" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200809 tests/scripts/check-generated-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100810}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200811
Gilles Peskine8f073122018-11-27 15:58:47 +0100812component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200813 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200814 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +0100815}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200816
Gilles Peskine8f073122018-11-27 15:58:47 +0100817component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200818 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200819 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100820}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200821
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200822component_check_changelog () {
823 msg "Check: changelog entries" # < 1s
824 rm -f ChangeLog.new
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200825 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200826 if [ -e ChangeLog.new ]; then
827 # Show the diff for information. It isn't an error if the diff is
828 # non-empty.
829 diff -u ChangeLog ChangeLog.new || true
830 rm ChangeLog.new
831 fi
832}
833
Gilles Peskine8f073122018-11-27 15:58:47 +0100834component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200835 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200836 tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100837}
Darryl Greena07039c2018-03-13 16:48:16 +0000838
Gilles Peskine895868b2019-09-19 21:30:05 +0200839component_check_test_cases () {
840 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200841 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200842 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200843 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200844 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200845 fi
Gilles Peskine58987962022-12-15 14:46:31 +0100846 tests/scripts/check_test_cases.py -q $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200847 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +0200848}
849
Gilles Peskine8f073122018-11-27 15:58:47 +0100850component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200851 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200852 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100853}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200854
Gilles Peskine192c72f2017-12-21 15:59:21 +0100855
Gilles Peskine636c26a2020-03-04 20:46:15 +0100856
Gilles Peskine192c72f2017-12-21 15:59:21 +0100857################################################################
858#### Build and test many configurations and targets
859################################################################
860
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200861component_test_default_out_of_box () {
862 msg "build: make, default config (out-of-box)" # ~1min
863 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200864 # Disable fancy stuff
865 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200866
867 msg "test: main suites make, default config (out-of-box)" # ~10s
868 make test
869
870 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200871 programs/test/selftest
Gilles Peskine93aaf2e2019-06-14 18:27:03 +0200872
873 msg "program demos: make, default config (out-of-box)" # ~10s
874 tests/scripts/run_demos.py
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200875}
876
Gilles Peskine8f073122018-11-27 15:58:47 +0100877component_test_default_cmake_gcc_asan () {
878 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100879 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
880 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200881
Gilles Peskine8f073122018-11-27 15:58:47 +0100882 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
883 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200884
Gilles Peskine93aaf2e2019-06-14 18:27:03 +0200885 msg "program demos (ASan build)" # ~10s
886 tests/scripts/run_demos.py
887
Gilles Peskine97bea012020-04-23 23:37:45 +0200888 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200889 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200890
Gilles Peskineee8af062023-11-02 19:58:03 +0100891 msg "test: metatests (GCC, ASan build)"
892 tests/scripts/run-metatests.sh any asan
893
Gilles Peskine8f073122018-11-27 15:58:47 +0100894 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200895 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200896
Gilles Peskine8f073122018-11-27 15:58:47 +0100897 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200898 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200899
900 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200901 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100902}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200903
Hanno Becker01635512019-02-26 14:27:09 +0000904component_test_full_cmake_gcc_asan () {
905 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200906 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000907 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
908 make
909
910 msg "test: main suites (inc. selftests) (full config, ASan build)"
911 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +0100912
Gilles Peskine97bea012020-04-23 23:37:45 +0200913 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200914 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200915
Gilles Peskine636c26a2020-03-04 20:46:15 +0100916 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200917 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100918
919 msg "test: compat.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200920 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200921
922 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200923 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100924}
925
Ronald Cronc3623db2020-10-29 10:51:32 +0100926component_test_psa_crypto_key_id_encodes_owner () {
927 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
928 scripts/config.py full
929 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
930 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
931 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
932 make
933
934 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
935 make test
936}
937
Gilles Peskine99a34622021-06-17 11:37:52 +0200938# check_renamed_symbols HEADER LIB
939# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
940# name is LIB.
941check_renamed_symbols () {
942 ! nm "$2" | sed 's/.* //' |
943 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
944}
945
Gilles Peskine984c19f2021-06-15 18:37:38 +0200946component_build_psa_crypto_spm () {
947 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
948 scripts/config.py full
949 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
950 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
951 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
952 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
953 # We can only compile, not link, since our test and sample programs
954 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
955 # is active.
956 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskine99a34622021-06-17 11:37:52 +0200957
958 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
959 # version is not present.
960 echo "Checking for renamed symbols in the library"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200961 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskine984c19f2021-06-15 18:37:38 +0200962}
963
Ronald Cron336678b2021-01-28 17:54:24 +0100964component_test_psa_crypto_client () {
965 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
966 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
967 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
968 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
969 make
970
971 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
972 make test
973}
974
Gilles Peskine636c26a2020-03-04 20:46:15 +0100975component_test_zlib_make() {
976 msg "build: zlib enabled, make"
977 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine6fa69862021-10-05 09:36:03 +0200978 make ZLIB=1 CFLAGS='-Werror -O2'
Gilles Peskine636c26a2020-03-04 20:46:15 +0100979
980 msg "test: main suites (zlib, make)"
981 make test
982
983 msg "test: ssl-opt.sh (zlib, make)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200984 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100985}
986support_test_zlib_make () {
987 base=support_test_zlib_$$
988 cat <<'EOF' > ${base}.c
989#include "zlib.h"
990int main(void) { return 0; }
991EOF
992 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
993 ret=$?
994 rm -f ${base}.*
995 return $ret
996}
997
998component_test_zlib_cmake() {
999 msg "build: zlib enabled, cmake"
1000 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine25319702021-10-07 19:34:57 +02001001 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Release .
Gilles Peskine636c26a2020-03-04 20:46:15 +01001002 make
1003
1004 msg "test: main suites (zlib, cmake)"
1005 make test
1006
1007 msg "test: ssl-opt.sh (zlib, cmake)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001008 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001009}
1010support_test_zlib_cmake () {
1011 support_test_zlib_make "$@"
Manuel Pégourié-Gonnardf2e29022020-01-24 10:17:20 +01001012}
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +01001013
Jaeden Ameroc17f2932021-05-14 08:34:32 +01001014component_test_psa_crypto_rsa_no_genprime() {
1015 msg "build: default config minus MBEDTLS_GENPRIME"
1016 scripts/config.py unset MBEDTLS_GENPRIME
1017 make
1018
1019 msg "test: default config minus MBEDTLS_GENPRIME"
1020 make test
1021}
1022
Gilles Peskine782f4112018-11-27 16:11:09 +01001023component_test_ref_configs () {
1024 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
1025 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001026 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +01001027}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001028
Gilles Peskine8f073122018-11-27 15:58:47 +01001029component_test_sslv3 () {
1030 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001031 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +01001032 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1033 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001034
Gilles Peskine8f073122018-11-27 15:58:47 +01001035 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
1036 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +00001037
Gilles Peskine8f073122018-11-27 15:58:47 +01001038 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001039 tests/compat.sh -m 'ssl3 tls1 tls1_1 tls12 dtls1 dtls12'
Simon Butcher3ea7f522016-03-07 23:22:10 +00001040
Gilles Peskine8f073122018-11-27 15:58:47 +01001041 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001042 tests/ssl-opt.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001043
1044 msg "build: SSLv3 - context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001045 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001046}
Simon Butcher3ea7f522016-03-07 23:22:10 +00001047
Gilles Peskine8f073122018-11-27 15:58:47 +01001048component_test_no_renegotiation () {
1049 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001050 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001051 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1052 make
Simon Butcher3ea7f522016-03-07 23:22:10 +00001053
Gilles Peskine8f073122018-11-27 15:58:47 +01001054 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1055 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +01001056
Gilles Peskine8f073122018-11-27 15:58:47 +01001057 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001058 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001059}
Hanno Becker134c2ab2017-10-12 15:29:50 +01001060
Gilles Peskine56194432023-02-01 18:44:11 +01001061component_test_no_certs () {
1062 msg "build: full minus MBEDTLS_CERTS_C"
1063 scripts/config.py full
1064 scripts/config.py unset MBEDTLS_CERTS_C
1065 # Quick build+test (we're checking for stray uses of the test certs,
1066 # not expecting their absence to lead to subtle problems).
1067 make
1068
1069 msg "test: full minus MBEDTLS_CERTS_C - main suites"
1070 make test
1071}
1072
Gilles Peskine636c26a2020-03-04 20:46:15 +01001073component_test_no_pem_no_fs () {
1074 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1075 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1076 scripts/config.py unset MBEDTLS_FS_IO
1077 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1078 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
1079 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1080 make
1081
1082 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1083 make test
1084
1085 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001086 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001087}
1088
Gilles Peskine8f073122018-11-27 15:58:47 +01001089component_test_rsa_no_crt () {
1090 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001091 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +01001092 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1093 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +01001094
Gilles Peskine8f073122018-11-27 15:58:47 +01001095 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1096 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001097
Gilles Peskine8f073122018-11-27 15:58:47 +01001098 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001099 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001100
Gilles Peskine8f073122018-11-27 15:58:47 +01001101 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001102 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001103
1104 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001105 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001106}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001107
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001108component_test_no_ctr_drbg_classic () {
1109 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001110 scripts/config.py full
1111 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001112 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001113
1114 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1115 make
1116
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001117 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001118 make test
1119
Gilles Peskineba749042021-01-13 20:02:03 +01001120 # In this configuration, the TLS test programs use HMAC_DRBG.
1121 # The SSL tests are slow, so run a small subset, just enough to get
1122 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001123 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001124 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001125
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001126 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001127 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001128}
1129
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001130component_test_no_ctr_drbg_use_psa () {
1131 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001132 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001133 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1134 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001135
1136 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1137 make
1138
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001139 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1140 make test
1141
1142 # In this configuration, the TLS test programs use HMAC_DRBG.
1143 # The SSL tests are slow, so run a small subset, just enough to get
1144 # confidence that the SSL code copes with HMAC_DRBG.
1145 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001146 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001147
1148 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001149 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001150}
1151
1152component_test_no_hmac_drbg_classic () {
1153 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1154 scripts/config.py full
1155 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1156 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1157 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1158
1159 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1160 make
1161
1162 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001163 make test
1164
Gilles Peskinea2224342020-11-19 22:14:34 +01001165 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1166 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1167 # instead.
1168 # Test SSL with non-deterministic ECDSA. Only test features that
1169 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001170 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001171 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001172
1173 # To save time, only test one protocol version, since this part of
1174 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001175 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001176 tests/compat.sh -m tls12 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001177}
1178
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001179component_test_no_hmac_drbg_use_psa () {
1180 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1181 scripts/config.py full
1182 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1183 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1184 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1185
1186 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1187 make
1188
1189 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1190 make test
1191
1192 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1193 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1194 # instead.
1195 # Test SSL with non-deterministic ECDSA. Only test features that
1196 # might be affected by how ECDSA signature is performed.
1197 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001198 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001199
1200 # To save time, only test one protocol version, since this part of
1201 # the protocol is identical in (D)TLS up to 1.2.
1202 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001203 tests/compat.sh -m tls12 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001204}
1205
1206component_test_psa_external_rng_no_drbg_classic () {
1207 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1208 scripts/config.py full
1209 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1210 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001211 scripts/config.py unset MBEDTLS_ENTROPY_C
1212 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1213 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001214 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1215 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1216 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1217 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001218 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1219 # the SSL test programs don't have an RNG and can't work. Explicitly
1220 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1221 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001222
1223 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1224 make test
1225
Gilles Peskine8eb29432021-02-03 20:07:11 +01001226 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001227 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001228}
1229
1230component_test_psa_external_rng_no_drbg_use_psa () {
1231 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001232 scripts/config.py full
1233 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001234 scripts/config.py unset MBEDTLS_ENTROPY_C
1235 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1236 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001237 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1238 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1239 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1240 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1241 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1242
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001243 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001244 make test
1245
Gilles Peskine8eb29432021-02-03 20:07:11 +01001246 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001247 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001248}
1249
1250component_test_psa_external_rng_use_psa_crypto () {
1251 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1252 scripts/config.py full
1253 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1254 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1255 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1256 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1257
1258 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1259 make test
1260
Gilles Peskineba749042021-01-13 20:02:03 +01001261 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001262 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001263}
1264
Gilles Peskine55e89982023-04-28 21:04:28 +02001265component_test_psa_inject_entropy () {
1266 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
1267 scripts/config.py full
1268 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
1269 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
1270 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1271 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1272 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
1273 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
1274 make CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
1275
1276 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
1277 make test
1278}
1279
Manuel Pégourié-Gonnard1a3f9ed2020-05-19 12:38:31 +02001280component_test_ecp_no_internal_rng () {
1281 msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
1282 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1283 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1284 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1285 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1286 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
1287 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1288
1289 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1290 make
1291
1292 msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
1293 make test
1294
1295 # no SSL tests as they all depend on having a DRBG
1296}
1297
Manuel Pégourié-Gonnard53fb66d2020-06-04 09:43:14 +02001298component_test_ecp_restartable_no_internal_rng () {
1299 msg "build: Default plus ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG"
1300 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1301 scripts/config.py set MBEDTLS_ECP_RESTARTABLE
1302 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1303 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1304 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1305 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
1306 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1307
1308 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1309 make
1310
1311 msg "test: ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG module"
1312 make test
1313
1314 # no SSL tests as they all depend on having a DRBG
1315}
1316
Przemek Stekiele5352702022-10-05 11:37:54 +02001317component_test_tls1_2_default_stream_cipher_only () {
1318 msg "build: default with only stream cipher"
1319
1320 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
1321 scripts/config.py unset MBEDTLS_GCM_C
1322 scripts/config.py unset MBEDTLS_CCM_C
1323 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1324 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1325 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1326 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1327 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1328 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1329 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1330 # Modules that depend on AEAD
1331 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001332 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001333
1334 make
1335
1336 msg "test: default with only stream cipher"
1337 make test
1338
1339 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1340}
1341
1342component_test_tls1_2_default_stream_cipher_only_use_psa () {
1343 msg "build: default with only stream cipher use psa"
1344
1345 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1346 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1347 scripts/config.py unset MBEDTLS_GCM_C
1348 scripts/config.py unset MBEDTLS_CCM_C
1349 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1350 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1351 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1352 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1353 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1354 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1355 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1356 # Modules that depend on AEAD
1357 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001358 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001359
1360 make
1361
1362 msg "test: default with only stream cipher use psa"
1363 make test
1364
1365 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1366}
1367
1368component_test_tls1_2_default_cbc_legacy_cipher_only () {
1369 msg "build: default with only CBC-legacy cipher"
1370
1371 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1372 scripts/config.py unset MBEDTLS_GCM_C
1373 scripts/config.py unset MBEDTLS_CCM_C
1374 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1375 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1376 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1377 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1378 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1379 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1380 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1381 # Modules that depend on AEAD
1382 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001383 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001384
1385 make
1386
1387 msg "test: default with only CBC-legacy cipher"
1388 make test
1389
1390 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1391 tests/ssl-opt.sh -f "TLS 1.2"
1392}
1393
1394component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
1395 msg "build: default with only CBC-legacy cipher use psa"
1396
1397 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1398 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1399 scripts/config.py unset MBEDTLS_GCM_C
1400 scripts/config.py unset MBEDTLS_CCM_C
1401 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1402 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1403 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1404 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1405 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1406 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1407 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1408 # Modules that depend on AEAD
1409 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001410 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001411
1412 make
1413
1414 msg "test: default with only CBC-legacy cipher use psa"
1415 make test
1416
1417 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1418 tests/ssl-opt.sh -f "TLS 1.2"
1419}
1420
1421component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
1422 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1423
1424 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1425 scripts/config.py unset MBEDTLS_GCM_C
1426 scripts/config.py unset MBEDTLS_CCM_C
1427 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1428 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1429 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1430 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1431 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1432 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1433 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1434 # Modules that depend on AEAD
1435 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001436 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001437
1438 make
1439
1440 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1441 make test
1442
1443 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1444 tests/ssl-opt.sh -f "TLS 1.2"
1445}
1446
1447component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
1448 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
1449
1450 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1451 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1452 scripts/config.py unset MBEDTLS_GCM_C
1453 scripts/config.py unset MBEDTLS_CCM_C
1454 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1455 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1456 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1457 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1458 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1459 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1460 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1461 # Modules that depend on AEAD
1462 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001463 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001464
1465 make
1466
1467 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
1468 make test
1469
1470 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
1471 tests/ssl-opt.sh -f "TLS 1.2"
1472}
1473
Gilles Peskine636c26a2020-03-04 20:46:15 +01001474component_test_new_ecdh_context () {
1475 msg "build: new ECDH context (ASan build)" # ~ 6 min
1476 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1477 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1478 make
1479
1480 msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1481 make test
1482
1483 msg "test: new ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001484 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001485
1486 msg "test: new ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1487 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001488 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001489}
1490
1491component_test_everest () {
1492 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
1493 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1494 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1495 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1496 make
1497
1498 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1499 make test
1500
Gilles Peskineee8af062023-11-02 19:58:03 +01001501 msg "test: metatests (clang, ASan)"
1502 tests/scripts/run-metatests.sh any asan
1503
Gilles Peskine636c26a2020-03-04 20:46:15 +01001504 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001505 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001506
1507 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1508 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001509 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001510}
1511
Gilles Peskined3beca92020-07-03 00:15:37 +02001512component_test_everest_curve25519_only () {
1513 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
1514 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1515 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1516 scripts/config.py unset MBEDTLS_ECDSA_C
1517 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1518 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1519 # Disable all curves
1520 for c in $(sed -n 's/#define \(MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED\).*/\1/p' <"$CONFIG_H"); do
1521 scripts/config.py unset "$c"
1522 done
1523 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1524
1525 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1526
1527 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1528 make test
1529}
1530
Gilles Peskine8f073122018-11-27 15:58:47 +01001531component_test_small_ssl_out_content_len () {
1532 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001533 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1534 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001535 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1536 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001537
Gilles Peskine8f073122018-11-27 15:58:47 +01001538 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001539 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001540}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001541
Gilles Peskine8f073122018-11-27 15:58:47 +01001542component_test_small_ssl_in_content_len () {
1543 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001544 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1545 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001546 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1547 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001548
Gilles Peskine8f073122018-11-27 15:58:47 +01001549 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001550 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001551}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001552
Gilles Peskine8f073122018-11-27 15:58:47 +01001553component_test_small_ssl_dtls_max_buffering () {
1554 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001555 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001556 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1557 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001558
Gilles Peskine8f073122018-11-27 15:58:47 +01001559 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001560 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 +01001561}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001562
Gilles Peskine8f073122018-11-27 15:58:47 +01001563component_test_small_mbedtls_ssl_dtls_max_buffering () {
1564 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001565 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001566 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1567 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001568
Gilles Peskine8f073122018-11-27 15:58:47 +01001569 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001570 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001571}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001572
Gilles Peskine75cc7712019-09-06 19:47:17 +02001573component_test_psa_collect_statuses () {
1574 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001575 scripts/config.py full
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001576 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001577 # Check that psa_crypto_init() succeeded at least once
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001578 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001579 rm -f tests/statuses.log
1580}
1581
Gilles Peskine8f073122018-11-27 15:58:47 +01001582component_test_full_cmake_clang () {
1583 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001584 scripts/config.py full
Gilles Peskine83264be2022-10-30 21:02:40 +01001585 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 +01001586 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001587
k-stachowiak0291cb72019-06-26 15:52:12 +02001588 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001589 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001590
Gilles Peskine83264be2022-10-30 21:02:40 +01001591 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
1592 programs/test/cpp_dummy_build
1593
Gilles Peskineee8af062023-11-02 19:58:03 +01001594 msg "test: metatests (clang)"
Gilles Peskinee38eb792023-11-03 18:05:38 +01001595 tests/scripts/run-metatests.sh any pthread
Gilles Peskineee8af062023-11-02 19:58:03 +01001596
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02001597 msg "program demos (full config, clang)" # ~10s
1598 tests/scripts/run_demos.py
1599
k-stachowiak0291cb72019-06-26 15:52:12 +02001600 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001601 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001602
Gilles Peskine8f073122018-11-27 15:58:47 +01001603 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001604 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001605
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001606 msg "test: compat.sh RC4, 3DES & NULL (full config)" # ~ 2min
1607 tests/compat.sh -e '^$' -f 'NULL\|3DES\|DES-CBC3\|RC4\|ARCFOUR'
1608
1609 msg "test: compat.sh single-DES (full config)" # ~ 30s
1610 env OPENSSL="$OPENSSL_LEGACY" tests/compat.sh -e '3DES\|DES-CBC3' -f 'DES'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001611
Gilles Peskine8f073122018-11-27 15:58:47 +01001612 msg "test: compat.sh ARIA + ChachaPoly"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001613 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001614}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001615
Gilles Peskine9603a442022-11-29 16:01:41 +01001616skip_suites_without_constant_flow () {
1617 # Skip the test suites that don't have any constant-flow annotations.
1618 # This will need to be adjusted if we ever start declaring things as
1619 # secret from macros or functions inside tests/include or tests/src.
1620 SKIP_TEST_SUITES=$(
1621 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
1622 sed 's/test_suite_//; s/\.function$//' |
1623 tr '\n' ,)
1624 export SKIP_TEST_SUITES
1625}
1626
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001627component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001628 # This tests both (1) accesses to undefined memory, and (2) branches or
1629 # memory access depending on secret values. To distinguish between those:
1630 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1631 # - or alternatively, change the build type to MemSanDbg, which enables
1632 # origin tracking and nicer stack traces (which are useful for debugging
1633 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1634 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001635 scripts/config.py full
1636 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1637 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1638 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1639 make
1640
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001641 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001642 make test
1643}
1644
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01001645component_release_test_valgrind_constant_flow () {
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001646 # This tests both (1) everything that valgrind's memcheck usually checks
1647 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1648 # etc.) and (2) branches or memory access depending on secret values,
1649 # which will be reported as uninitialized memory. To distinguish between
1650 # secret and actually uninitialized:
1651 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1652 # - or alternatively, build with debug info and manually run the offending
1653 # test suite with valgrind --track-origins=yes, then check if the origin
1654 # was TEST_CF_SECRET() or something else.
1655 msg "build: cmake release GCC, full config with constant flow testing"
1656 scripts/config.py full
1657 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Gilles Peskine9603a442022-11-29 16:01:41 +01001658 skip_suites_without_constant_flow
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001659 cmake -D CMAKE_BUILD_TYPE:String=Release .
1660 make
1661
1662 # this only shows a summary of the results (how many of each type)
1663 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine9603a442022-11-29 16:01:41 +01001664 msg "test: some suites (valgrind + constant flow)"
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001665 make memcheck
1666}
1667
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001668component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02001669 # Test that removing the deprecated features from the default
1670 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001671 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1672 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
Dave Rodgman374b1882024-01-04 10:30:57 +00001673 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001674
1675 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1676 make test
1677}
1678
1679component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02001680 msg "build: make, full_no_deprecated config" # ~ 30s
1681 scripts/config.py full_no_deprecated
Dave Rodgman374b1882024-01-04 10:30:57 +00001682 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001683
Gilles Peskine30de2e82020-04-20 21:39:22 +02001684 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001685 make test
1686}
1687
Gilles Peskine8386ea22020-04-30 09:07:29 +02001688component_test_full_no_deprecated_deprecated_warning () {
1689 # Test that there is nothing deprecated in "full_no_deprecated".
1690 # A deprecated feature would trigger a warning (made fatal) from
1691 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02001692 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1693 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001694 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
1695 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Dave Rodgman374b1882024-01-04 10:30:57 +00001696 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001697
Gilles Peskine30de2e82020-04-20 21:39:22 +02001698 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001699 make test
1700}
1701
Gilles Peskine8386ea22020-04-30 09:07:29 +02001702component_test_full_deprecated_warning () {
1703 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
1704 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001705 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001706 scripts/config.py full
1707 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001708 # Expect warnings from '#warning' directives in check_config.h.
Dave Rodgman9d2c67f2023-12-19 14:07:15 +00001709 # Note that gcc is required to allow the use of -Wno-error=cpp, which allows us to
1710 # display #warning messages without them being treated as errors.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001711 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001712
Gilles Peskine8386ea22020-04-30 09:07:29 +02001713 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1714 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
1715 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001716 # Expect warnings from '#warning' directives in check_config.h and
1717 # from the use of deprecated functions in test suites.
1718 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 +01001719
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001720 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
1721 make test
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02001722
1723 msg "program demos: full config + MBEDTLS_TEST_DEPRECATED" # ~10s
1724 tests/scripts/run_demos.py
Gilles Peskine8f073122018-11-27 15:58:47 +01001725}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00001726
Gilles Peskineec541fe2020-01-31 14:24:14 +01001727# Check that the specified libraries exist and are empty.
1728are_empty_libraries () {
1729 nm "$@" >/dev/null 2>/dev/null
1730 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
1731}
1732
1733component_build_crypto_default () {
1734 msg "build: make, crypto only"
1735 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01001736 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001737 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001738}
1739
1740component_build_crypto_full () {
1741 msg "build: make, crypto only, full config"
1742 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01001743 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001744 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001745}
1746
Gilles Peskine8df27482022-10-21 19:34:54 +02001747component_test_crypto_for_psa_service () {
Gilles Peskine21503df2022-10-11 21:05:06 +02001748 msg "build: make, config for PSA crypto service"
1749 scripts/config.py crypto
1750 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1751 # Disable things that are not needed for just cryptography, to
1752 # reach a configuration that would be typical for a PSA cryptography
1753 # service providing all implemented PSA algorithms.
1754 # System stuff
1755 scripts/config.py unset MBEDTLS_ERROR_C
1756 scripts/config.py unset MBEDTLS_TIMING_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001757 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskine21503df2022-10-11 21:05:06 +02001758 # Crypto stuff with no PSA interface
1759 scripts/config.py unset MBEDTLS_BASE64_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001760 scripts/config.py unset MBEDTLS_BLOWFISH_C
1761 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
1762 # Keep MBEDTLS_MD_C because RSA and ECDSA need it, also HMAC_DRBG which
1763 # is needed for deterministic ECDSA.
1764 scripts/config.py unset MBEDTLS_ECJPAKE_C
1765 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
Gilles Peskine21503df2022-10-11 21:05:06 +02001766 scripts/config.py unset MBEDTLS_NIST_KW_C
1767 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1768 scripts/config.py unset MBEDTLS_PEM_WRITE_C
1769 scripts/config.py unset MBEDTLS_PKCS12_C
1770 scripts/config.py unset MBEDTLS_PKCS5_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001771 # We keep MBEDTLS_PK_{,PARSE,WRITE}_C because PSA with RSA needs it.
1772 scripts/config.py unset MBEDTLS_XTEA_C
Gilles Peskine21503df2022-10-11 21:05:06 +02001773 make CFLAGS='-O1 -Werror' all test
1774 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1775}
1776
Gilles Peskineec541fe2020-01-31 14:24:14 +01001777component_build_crypto_baremetal () {
1778 msg "build: make, crypto only, baremetal config"
1779 scripts/config.py crypto_baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001780 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001781 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001782}
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001783support_build_crypto_baremetal () {
Daniel Axtens1a021af2020-08-31 14:22:58 +10001784 support_build_baremetal "$@"
1785}
1786
1787component_build_baremetal () {
1788 msg "build: make, baremetal config"
1789 scripts/config.py baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001790 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Daniel Axtens1a021af2020-08-31 14:22:58 +10001791}
1792support_build_baremetal () {
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001793 # Older Glibc versions include time.h from other headers such as stdlib.h,
1794 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
1795 # problem, Ubuntu 18.04 is ok.
1796 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
1797}
Gilles Peskineec541fe2020-01-31 14:24:14 +01001798
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001799# depends.py family of tests
Andrzej Kurek85d69302022-10-05 09:14:07 -04001800component_test_depends_py_cipher_id () {
1801 msg "test/build: depends.py cipher_id (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001802 tests/scripts/depends.py cipher_id --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001803}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001804
Andrzej Kurek85d69302022-10-05 09:14:07 -04001805component_test_depends_py_cipher_chaining () {
1806 msg "test/build: depends.py cipher_chaining (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001807 tests/scripts/depends.py cipher_chaining --unset-use-psa
John Durkopc14be902020-08-20 06:16:41 -07001808}
1809
Andrzej Kurek85d69302022-10-05 09:14:07 -04001810component_test_depends_py_cipher_padding () {
1811 msg "test/build: depends.py cipher_padding (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001812 tests/scripts/depends.py cipher_padding --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001813}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001814
Andrzej Kurek85d69302022-10-05 09:14:07 -04001815component_test_depends_py_curves () {
1816 msg "test/build: depends.py curves (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001817 tests/scripts/depends.py curves --unset-use-psa
John Durkop2ec2eaa2020-08-24 18:29:15 -07001818}
1819
Andrzej Kurek85d69302022-10-05 09:14:07 -04001820component_test_depends_py_hashes () {
1821 msg "test/build: depends.py hashes (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001822 tests/scripts/depends.py hashes --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001823}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001824
Andrzej Kurek85d69302022-10-05 09:14:07 -04001825component_test_depends_py_kex () {
1826 msg "test/build: depends.py kex (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001827 tests/scripts/depends.py kex --unset-use-psa
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001828}
1829
Andrzej Kurek85d69302022-10-05 09:14:07 -04001830component_test_depends_py_pkalgs () {
1831 msg "test/build: depends.py pkalgs (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001832 tests/scripts/depends.py pkalgs --unset-use-psa
1833}
1834
1835# PSA equivalents of the depends.py tests
1836component_test_depends_py_cipher_id_psa () {
1837 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1838 tests/scripts/depends.py cipher_id
1839}
1840
1841component_test_depends_py_cipher_chaining_psa () {
1842 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1843 tests/scripts/depends.py cipher_chaining
1844}
1845
1846component_test_depends_py_cipher_padding_psa () {
1847 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1848 tests/scripts/depends.py cipher_padding
1849}
1850
1851component_test_depends_py_curves_psa () {
1852 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1853 tests/scripts/depends.py curves
1854}
1855
1856component_test_depends_py_hashes_psa () {
1857 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1858 tests/scripts/depends.py hashes
1859}
1860
1861component_test_depends_py_kex_psa () {
1862 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1863 tests/scripts/depends.py kex
1864}
1865
1866component_test_depends_py_pkalgs_psa () {
1867 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Andrzej Kurek85d69302022-10-05 09:14:07 -04001868 tests/scripts/depends.py pkalgs
Gilles Peskine8f073122018-11-27 15:58:47 +01001869}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001870
Dave Rodgman5fce4f62023-01-20 13:18:05 +00001871component_build_no_pk_rsa_alt_support () {
1872 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
1873
1874 scripts/config.py full
1875 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
1876 scripts/config.py set MBEDTLS_RSA_C
1877 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
1878
1879 # Only compile - this is primarily to test for compile issues
Dave Rodgman374b1882024-01-04 10:30:57 +00001880 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
Dave Rodgman5fce4f62023-01-20 13:18:05 +00001881}
1882
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001883component_test_no_use_psa_crypto_full_cmake_asan() {
1884 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02001885 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001886 scripts/config.py full
1887 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
1888 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1889 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1890 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02001891 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001892 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01001893 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001894 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001895
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001896 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001897 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001898
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001899 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001900 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001901
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001902 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001903 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001904
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001905 msg "test: compat.sh RC4, 3DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
1906 tests/compat.sh -e '^$' -f 'NULL\|3DES\|DES-CBC3\|RC4\|ARCFOUR'
1907
1908 msg "test: compat.sh single-DES (full minus MBEDTLS_USE_PSA_CRYPTO)"
1909 env OPENSSL="$OPENSSL_LEGACY" tests/compat.sh -e '3DES\|DES-CBC3' -f 'DES'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001910
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001911 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001912 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001913}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001914
Ronald Crond2c53e62021-09-13 09:38:05 +02001915component_test_psa_crypto_config_accel_ecdsa () {
1916 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1917
1918 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1919 # partial support for cipher operations in the driver test library.
1920 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1921 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Gilles Peskine62de7672022-04-21 11:05:16 +02001922 # Disable obsolete hashes (alternatively we could enable support for them
1923 # in the driver test library).
1924 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1925 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
Ronald Crond2c53e62021-09-13 09:38:05 +02001926
1927 # SHA384 needed for some ECDSA signature tests.
1928 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
1929
1930 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
1931 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1932 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1933
1934 # Restore test driver base configuration
1935 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
1936
1937 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1938 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1939 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1940 scripts/config.py unset MBEDTLS_ECDSA_C
1941 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1942 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1943
1944 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
1945 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"
1946
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01001947 not grep mbedtls_ecdsa_ library/ecdsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02001948
1949 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1950 make test
1951}
1952
1953component_test_psa_crypto_config_accel_rsa_signature () {
1954 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
1955
1956 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1957 # partial support for cipher operations in the driver test library.
1958 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1959 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1960
1961 # It seems it is not possible to remove only the support for RSA signature
1962 # in the library. Thus we have to remove all RSA support (signature and
1963 # encryption/decryption). AS there is no driver support for asymmetric
1964 # encryption/decryption so far remove RSA encryption/decryption from the
1965 # application algorithm list.
1966 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1967 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1968
1969 # Make sure both the library and the test library support the SHA hash
1970 # algorithms and only those ones (SHA256 is included by default). That way:
1971 # - the test library can compute the RSA signatures even in the case of a
1972 # composite RSA signature algorithm based on a SHA hash (no other hash
1973 # used in the unit tests).
1974 # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
1975 # fulfilled as the hash SHA algorithm is supported by the library, and
1976 # thus the tests are run, not skipped.
1977 # - when testing a signature key with an algorithm wildcard built from
1978 # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
1979 # algorithm based on the hashes supported by the library is also
1980 # supported by the test library.
1981 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1982 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1983 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1984 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160_C
1985
1986 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA1_C
1987 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
1988 # We need PEM parsing in the test library as well to support the import
1989 # of PEM encoded RSA keys.
1990 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_PEM_PARSE_C
1991 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_BASE64_C
1992
1993 loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
1994 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1995 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1996
1997 # Restore test driver base configuration
1998 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA1_C
1999 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
2000 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_PEM_PARSE_C
2001 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_BASE64_C
2002
2003
2004 # Mbed TLS library build
2005 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2006 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2007
2008 # Remove RSA support and its dependencies
2009 scripts/config.py unset MBEDTLS_PKCS1_V15
2010 scripts/config.py unset MBEDTLS_PKCS1_V21
2011 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2012 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2013 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2014 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2015 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2016 scripts/config.py unset MBEDTLS_RSA_C
2017 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2018
2019 scripts/config.py unset MBEDTLS_MD2_C
2020 scripts/config.py unset MBEDTLS_MD4_C
2021 scripts/config.py unset MBEDTLS_MD5_C
2022 scripts/config.py unset MBEDTLS_RIPEMD160_C
2023 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
2024 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
2025 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
2026
2027 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2028 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2029
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002030 not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
2031 not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02002032
2033 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
2034 make test
2035}
2036
Ronald Cronf7e483c2021-05-08 14:32:59 +02002037component_test_psa_crypto_config_accel_hash () {
2038 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2039
2040 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
2041 # partial support for cipher operations in the driver test library.
2042 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2043 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
2044
2045 loc_accel_list="ALG_MD4 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
2046 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2047 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2048
2049 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2050 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2051 scripts/config.py unset MBEDTLS_MD2_C
2052 scripts/config.py unset MBEDTLS_MD4_C
2053 scripts/config.py unset MBEDTLS_MD5_C
2054 scripts/config.py unset MBEDTLS_RIPEMD160_C
2055 scripts/config.py unset MBEDTLS_SHA1_C
2056 # Don't unset MBEDTLS_SHA256_C as it is needed by PSA crypto core.
2057 scripts/config.py unset MBEDTLS_SHA512_C
2058 # Unset MBEDTLS_SSL_PROTO_SSL3, MBEDTLS_SSL_PROTO_TLS1 and MBEDTLS_SSL_PROTO_TLS1_1 as they depend on MBEDTLS_SHA1_C
2059 scripts/config.py unset MBEDTLS_SSL_PROTO_SSL3
2060 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
2061 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
2062 # Unset MBEDTLS_SSL_CBC_RECORD_SPLITTING as it depends on MBEDTLS_SSL_PROTO_TLS1 in the default configuration.
2063 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
2064 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2065 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2066
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002067 not grep mbedtls_sha512_init library/sha512.o
2068 not grep mbedtls_sha1_init library/sha1.o
Ronald Cronf7e483c2021-05-08 14:32:59 +02002069
2070 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2071 make test
2072}
2073
Ronald Cron09623702021-10-18 11:26:01 +02002074component_test_psa_crypto_config_accel_cipher () {
2075 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
2076
Gilles Peskine186331872022-04-12 15:58:03 +02002077 # This test case focuses on cipher+AEAD. We don't yet support all
2078 # combinations of configurations, so deactivate block-cipher-based MACs.
2079 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CMAC
2080
Ronald Cron09623702021-10-18 11:26:01 +02002081 loc_accel_list="ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB ALG_OFB ALG_XTS KEY_TYPE_DES"
2082 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2083 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2084
2085 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2086 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2087
2088 # There is no intended accelerator support for ALG STREAM_CIPHER and
2089 # ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
2090 # inclusion of the Mbed TLS cipher operations. As we want to test here with
2091 # cipher operations solely supported by accelerators, disabled those
2092 # PSA configuration options.
2093 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2094 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Ronald Cron09623702021-10-18 11:26:01 +02002095
2096 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2097 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2098 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2099 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2100 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2101 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2102 scripts/config.py unset MBEDTLS_DES_C
2103
2104 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2105 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2106
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002107 not grep mbedtls_des* library/des.o
Ronald Cron09623702021-10-18 11:26:01 +02002108
2109 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2110 make test
2111}
2112
Przemek Stekiel8b56f232022-10-02 20:58:39 +02002113component_test_psa_crypto_config_accel_aead () {
2114 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2115
2116 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
2117 # partial support for cipher operations in the driver test library.
2118 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2119 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
2120
2121 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2122 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2123 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2124
2125 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2126 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2127
2128 scripts/config.py unset MBEDTLS_GCM_C
2129 scripts/config.py unset MBEDTLS_CCM_C
2130 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2131 # Features that depend on AEAD
2132 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
2133 scripts/config.py unset MBEDTLS_SSL_TICKET_C
2134
2135 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2136 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"
2137
2138 # There's a risk of something getting re-enabled via config_psa.h
2139 # make sure it did not happen.
2140 not grep mbedtls_ccm library/ccm.o
2141 not grep mbedtls_gcm library/gcm.o
2142 not grep mbedtls_chachapoly library/chachapoly.o
2143
2144 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2145 make test
2146}
2147
John Durkop4377bf72020-10-23 01:26:57 -07002148component_test_psa_crypto_config_no_driver() {
John Durkop4377bf72020-10-23 01:26:57 -07002149 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
2150 scripts/config.py full
2151 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2152 scripts/config.py unset MBEDTLS_PSA_CRYPTO_DRIVERS
2153 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkope7012c72020-10-26 09:55:01 -07002154 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop4377bf72020-10-23 01:26:57 -07002155
2156 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
John Durkopd8959392020-09-20 23:09:17 -07002157 make test
2158}
2159
Gilles Peskined4c85af2023-07-20 22:19:45 +02002160component_test_aead_chachapoly_disabled() {
2161 msg "build: full minus CHACHAPOLY"
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002162 scripts/config.py full
2163 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Gilles Peskined4c85af2023-07-20 22:19:45 +02002164 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002165 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
2166
Gilles Peskined4c85af2023-07-20 22:19:45 +02002167 msg "test: full minus CHACHAPOLY"
2168 make test
2169}
2170
2171component_test_aead_only_ccm() {
2172 msg "build: full minus CHACHAPOLY and GCM"
2173 scripts/config.py full
2174 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2175 scripts/config.py unset MBEDTLS_GCM_C
2176 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2177 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2178 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
2179
2180 msg "test: full minus CHACHAPOLY and GCM"
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002181 make test
2182}
2183
John Durkopd0321952020-10-29 21:37:36 -07002184# 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 -08002185component_build_psa_accel_alg_ecdh() {
Gilles Peskine168be012023-07-19 19:36:55 +02002186 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
John Durkopd0321952020-10-29 21:37:36 -07002187 scripts/config.py full
2188 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2189 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2190 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2191 scripts/config.py unset MBEDTLS_ECDH_C
2192 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2193 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2194 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2195 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2196 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2197 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2198 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2199}
2200
John Durkopf4c4cb02020-10-28 20:09:55 -07002201# 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 -08002202component_build_psa_accel_key_type_ecc_key_pair() {
Gilles Peskine168be012023-07-19 19:36:55 +02002203 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR"
John Durkopf4c4cb02020-10-28 20:09:55 -07002204 scripts/config.py full
2205 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2206 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2207 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002208 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 -08002209 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 -07002210 # 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 -08002211 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 -07002212}
2213
2214# 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 -08002215component_build_psa_accel_key_type_ecc_public_key() {
Gilles Peskine168be012023-07-19 19:36:55 +02002216 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
John Durkopf4c4cb02020-10-28 20:09:55 -07002217 scripts/config.py full
2218 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2219 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2220 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002221 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
2222 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
John Durkopf4c4cb02020-10-28 20:09:55 -07002223 # 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 -08002224 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 -07002225}
2226
John Durkopd0321952020-10-29 21:37:36 -07002227# 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 -08002228component_build_psa_accel_alg_hmac() {
Gilles Peskine168be012023-07-19 19:36:55 +02002229 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
John Durkopd0321952020-10-29 21:37:36 -07002230 scripts/config.py full
2231 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2232 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2233 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2234 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2235 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2236}
2237
2238# 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 -08002239component_build_psa_accel_alg_hkdf() {
Gilles Peskine168be012023-07-19 19:36:55 +02002240 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
John Durkopd0321952020-10-29 21:37:36 -07002241 scripts/config.py full
2242 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2243 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2244 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2245 scripts/config.py unset MBEDTLS_HKDF_C
John Durkopbd069d32020-10-31 22:14:03 -07002246 # Make sure to unset TLS1_3_EXPERIMENTAL since it requires HKDF_C and will not build properly without it.
2247 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
John Durkopd0321952020-10-29 21:37:36 -07002248 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2249 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2250}
2251
John Durkop1b7ee052020-11-27 08:51:22 -08002252# This should be renamed to test and updated once the accelerator MD2 code is in place and ready to test.
2253component_build_psa_accel_alg_md2() {
Gilles Peskine168be012023-07-19 19:36:55 +02002254 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD2 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002255 scripts/config.py full
2256 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2257 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2258 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2259 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2260 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2261 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2262 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2263 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2264 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2265 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2266 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2267 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2268 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD2 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2269}
2270
2271# This should be renamed to test and updated once the accelerator MD4 code is in place and ready to test.
2272component_build_psa_accel_alg_md4() {
Gilles Peskine168be012023-07-19 19:36:55 +02002273 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD4 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002274 scripts/config.py full
2275 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2276 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2277 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2278 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2279 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2280 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2281 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2282 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2283 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2284 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2285 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2286 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2287 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD4 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2288}
2289
2290# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
2291component_build_psa_accel_alg_md5() {
Gilles Peskine168be012023-07-19 19:36:55 +02002292 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002293 scripts/config.py full
2294 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2295 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2296 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2297 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2298 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2299 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2300 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2301 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2302 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2303 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2304 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2305 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2306 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2307}
2308
2309# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
2310component_build_psa_accel_alg_ripemd160() {
Gilles Peskine168be012023-07-19 19:36:55 +02002311 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002312 scripts/config.py full
2313 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2314 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2315 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2316 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2317 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2318 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2319 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2320 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2321 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2322 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2323 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2324 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2325 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2326}
2327
2328# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
2329component_build_psa_accel_alg_sha1() {
Gilles Peskine168be012023-07-19 19:36:55 +02002330 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002331 scripts/config.py full
2332 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2333 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2334 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2335 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2336 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2337 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2338 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2339 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2340 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2341 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2342 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2343 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2344 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2345}
2346
2347# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
2348component_build_psa_accel_alg_sha224() {
Gilles Peskine168be012023-07-19 19:36:55 +02002349 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002350 scripts/config.py full
2351 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2352 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2353 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2354 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2355 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2356 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2357 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2358 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2359 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2360 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2361 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2362 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2363}
2364
2365# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
2366component_build_psa_accel_alg_sha256() {
Gilles Peskine168be012023-07-19 19:36:55 +02002367 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002368 scripts/config.py full
2369 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2370 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2371 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2372 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2373 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2374 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2375 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2376 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2377 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2378 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2379 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2380 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2381 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2382}
2383
2384# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
2385component_build_psa_accel_alg_sha384() {
Gilles Peskine168be012023-07-19 19:36:55 +02002386 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002387 scripts/config.py full
2388 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2389 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2390 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2391 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2392 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2393 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2394 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2395 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2396 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2397 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2398 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2399 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2400}
2401
2402# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
2403component_build_psa_accel_alg_sha512() {
Gilles Peskine168be012023-07-19 19:36:55 +02002404 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002405 scripts/config.py full
2406 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2407 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2408 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2409 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2410 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2411 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2412 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2413 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2414 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2415 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2416 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2417 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2418 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2419}
2420
John Durkopd0321952020-10-29 21:37:36 -07002421# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08002422component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
Gilles Peskine168be012023-07-19 19:36:55 +02002423 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 -07002424 scripts/config.py full
2425 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2426 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2427 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkopbd069d32020-10-31 22:14:03 -07002428 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002429 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2430 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2431 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07002432 # 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 -07002433 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2434}
2435
2436# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08002437component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
Gilles Peskine168be012023-07-19 19:36:55 +02002438 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 -07002439 scripts/config.py full
2440 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2441 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2442 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2443 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002444 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2445 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2446 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002447 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2448 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2449}
2450
2451# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08002452component_build_psa_accel_alg_rsa_oaep() {
Gilles Peskine168be012023-07-19 19:36:55 +02002453 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 -07002454 scripts/config.py full
2455 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2456 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2457 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2458 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_OAEP 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002459 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2460 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2461 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002462 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2463 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2464}
2465
2466# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08002467component_build_psa_accel_alg_rsa_pss() {
Gilles Peskine168be012023-07-19 19:36:55 +02002468 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 -07002469 scripts/config.py full
2470 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2471 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2472 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2473 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002474 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2475 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2476 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07002477 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2478 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2479}
2480
2481# 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 -08002482component_build_psa_accel_key_type_rsa_key_pair() {
Gilles Peskine168be012023-07-19 19:36:55 +02002483 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 -07002484 scripts/config.py full
2485 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2486 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2487 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2488 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2489 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
2490 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2491 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"
2492}
2493
2494# 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 -08002495component_build_psa_accel_key_type_rsa_public_key() {
Gilles Peskine168be012023-07-19 19:36:55 +02002496 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 -07002497 scripts/config.py full
2498 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2499 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2500 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2501 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2502 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
2503 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2504 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 -07002505}
2506
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002507component_test_check_params_functionality () {
2508 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002509 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002510 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002511 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Ronald Crona1236142020-07-01 16:01:21 +02002512 make CC=gcc CFLAGS='-Werror -O1' all test
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002513}
2514
Gilles Peskineb28636b2019-01-02 19:06:24 +01002515component_test_check_params_without_platform () {
2516 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002517 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002518 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002519 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
2520 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
2521 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
2522 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
Gilles Peskine32e889d2020-04-12 23:43:28 +02002523 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002524 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
2525 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskine9c764bf2022-09-18 14:05:23 +02002526 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002527 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
2528 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +01002529 make CC=gcc CFLAGS='-Werror -O1' all test
2530}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002531
Gilles Peskineb28636b2019-01-02 19:06:24 +01002532component_test_check_params_silent () {
2533 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002534 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002535 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01002536 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
2537 make CC=gcc CFLAGS='-Werror -O1' all test
2538}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002539
Dave Rodgman173227d2023-06-29 09:29:00 +01002540component_build_aes_variations() { # ~45s
2541 msg "build: aes.o for all combinations of relevant config options"
Dave Rodgmanbf998282023-06-29 12:10:45 +01002542
Dave Rodgman173227d2023-06-29 09:29:00 +01002543 for a in set unset; do
2544 for b in set unset; do
2545 for c in set unset; do
2546 for d in set unset; do
2547 for e in set unset; do
2548 for f in set unset; do
2549 for g in set unset; do
Dave Rodgmanbf998282023-06-29 12:10:45 +01002550 echo ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
2551 echo ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
2552 echo ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
2553 echo ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
2554 echo ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
2555 echo ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
2556 echo ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman173227d2023-06-29 09:29:00 +01002557
Dave Rodgmanbf998282023-06-29 12:10:45 +01002558 ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
2559 ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
2560 ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
2561 ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
2562 ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
2563 ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
2564 ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman173227d2023-06-29 09:29:00 +01002565
Dave Rodgmanbf998282023-06-29 12:10:45 +01002566 rm -f library/aes.o
2567 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 +01002568 done
2569 done
2570 done
2571 done
2572 done
2573 done
2574 done
2575}
2576
Gilles Peskine8f073122018-11-27 15:58:47 +01002577component_test_no_platform () {
2578 # Full configuration build, without platform support, file IO and net sockets.
2579 # This should catch missing mbedtls_printf definitions, and by disabling file
2580 # IO, it should catch missing '#include <stdio.h>'
2581 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Paul Elliott68050372023-11-03 19:24:56 +00002582 scripts/config.py full_no_platform
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002583 scripts/config.py unset MBEDTLS_PLATFORM_C
2584 scripts/config.py unset MBEDTLS_NET_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002585 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002586 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002587 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
2588 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Paul Elliott68050372023-11-03 19:24:56 +00002589 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +01002590 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
2591 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002592 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
2593 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01002594}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00002595
Gilles Peskine8f073122018-11-27 15:58:47 +01002596component_build_no_std_function () {
2597 # catch compile bugs in _uninit functions
2598 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002599 scripts/config.py full
2600 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
2601 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002602 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine31fdda12021-10-08 11:45:47 +02002603 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskine25319702021-10-07 19:34:57 +02002604 make
Gilles Peskine8f073122018-11-27 15:58:47 +01002605}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01002606
Gilles Peskine8f073122018-11-27 15:58:47 +01002607component_build_no_ssl_srv () {
2608 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002609 scripts/config.py full
2610 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002611 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002612}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002613
Gilles Peskine8f073122018-11-27 15:58:47 +01002614component_build_no_ssl_cli () {
2615 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002616 scripts/config.py full
2617 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002618 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002619}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002620
Gilles Peskine8f073122018-11-27 15:58:47 +01002621component_build_no_sockets () {
2622 # Note, C99 compliance can also be tested with the sockets support disabled,
2623 # as that requires a POSIX platform (which isn't the same as C99).
2624 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002625 scripts/config.py full
2626 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
2627 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002628 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01002629}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02002630
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002631component_test_memory_buffer_allocator_backtrace () {
2632 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002633 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2634 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2635 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
2636 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Dave Rodgman374b1882024-01-04 10:30:57 +00002637 cmake -DCMAKE_BUILD_TYPE:String=Release .
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002638 make
2639
2640 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
2641 make test
2642}
2643
2644component_test_memory_buffer_allocator () {
2645 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002646 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2647 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Dave Rodgman374b1882024-01-04 10:30:57 +00002648 cmake -DCMAKE_BUILD_TYPE:String=Release .
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002649 make
2650
2651 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2652 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002653
2654 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2655 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002656 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002657}
2658
Gilles Peskine8f073122018-11-27 15:58:47 +01002659component_test_no_max_fragment_length () {
2660 # Run max fragment length tests with MFL disabled
2661 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002662 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01002663 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2664 make
Hanno Becker5175ac62017-09-18 15:36:25 +01002665
Gilles Peskine8f073122018-11-27 15:58:47 +01002666 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002667 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01002668}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002669
Hanno Becker545ced42019-02-19 11:10:48 +00002670component_test_asan_remove_peer_certificate () {
2671 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002672 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00002673 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2674 make
2675
2676 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2677 make test
2678
2679 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002680 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002681
2682 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002683 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002684
2685 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002686 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002687}
2688
Gilles Peskine8f073122018-11-27 15:58:47 +01002689component_test_no_max_fragment_length_small_ssl_out_content_len () {
2690 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002691 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2692 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
2693 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01002694 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2695 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10002696
Gilles Peskine8f073122018-11-27 15:58:47 +01002697 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002698 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002699
2700 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002701 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002702}
Angus Grattonc4dd0732018-04-11 16:28:39 +10002703
Darryl Greenaad82f92019-12-02 10:53:11 +00002704component_test_variable_ssl_in_out_buffer_len () {
2705 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
2706 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2707 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2708 make
2709
2710 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2711 make test
2712
2713 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002714 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002715
2716 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002717 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002718}
2719
2720component_test_variable_ssl_in_out_buffer_len_CID () {
2721 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
2722 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2723 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
2724
2725 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2726 make
2727
2728 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
2729 make test
2730
2731 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002732 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002733
2734 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002735 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002736}
2737
2738component_test_variable_ssl_in_out_buffer_len_record_splitting () {
2739 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled (ASan build)"
2740 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2741 scripts/config.py set MBEDTLS_SSL_CBC_RECORD_SPLITTING
2742
2743 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2744 make
2745
2746 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING"
2747 make test
2748
2749 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002750 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002751
2752 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002753 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002754}
2755
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002756component_test_ssl_alloc_buffer_and_mfl () {
2757 msg "build: default config with memory buffer allocator and MFL extension"
2758 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2759 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2760 scripts/config.py set MBEDTLS_MEMORY_DEBUG
2761 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2762 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
Dave Rodgman374b1882024-01-04 10:30:57 +00002763 cmake -DCMAKE_BUILD_TYPE:String=Release .
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002764 make
2765
2766 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
2767 make test
2768
2769 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 +02002770 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002771}
2772
Gilles Peskine636c26a2020-03-04 20:46:15 +01002773component_test_when_no_ciphersuites_have_mac () {
2774 msg "build: when no ciphersuites have MAC"
2775 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
2776 scripts/config.py unset MBEDTLS_ARC4_C
2777 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2778 make
2779
2780 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
2781 make test
2782
2783 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002784 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01002785}
2786
Gilles Peskine8f073122018-11-27 15:58:47 +01002787component_test_null_entropy () {
2788 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002789 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
2790 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
2791 scripts/config.py set MBEDTLS_ENTROPY_C
2792 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002793 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002794 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
2795 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00002796 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01002797 make
Janos Follath06c54002016-06-09 13:57:40 +01002798
Gilles Peskine8f073122018-11-27 15:58:47 +01002799 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
2800 make test
2801}
Janos Follath06c54002016-06-09 13:57:40 +01002802
Raoul Strackxa4e86142020-06-15 17:03:13 +02002803component_test_no_date_time () {
2804 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
2805 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
Gilles Peskine31fdda12021-10-08 11:45:47 +02002806 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Raoul Strackxa4e86142020-06-15 17:03:13 +02002807 make
2808
2809 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
2810 make test
2811}
2812
Andrzej Kurekc890b222023-01-17 04:03:19 -05002813component_test_alt_timing() {
2814 msg "build: alternate timing implementation"
2815 scripts/config.py set MBEDTLS_TIMING_ALT
2816 make lib TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
2817
2818 msg "test: MBEDTLS_TIMING_ALT - test suites"
2819 make test TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
Andrzej Kurek3a261a42023-01-26 04:33:59 -05002820
2821 msg "selftest - MBEDTLS-TIMING_ALT"
2822 make programs TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../../tests/src/external_timing -I../tests/src/external_timing"
2823 programs/test/selftest
Andrzej Kurekc890b222023-01-17 04:03:19 -05002824}
2825
Gilles Peskine8f073122018-11-27 15:58:47 +01002826component_test_platform_calloc_macro () {
2827 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002828 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2829 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
2830 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01002831 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2832 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01002833
Gilles Peskine8f073122018-11-27 15:58:47 +01002834 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
2835 make test
2836}
Hanno Beckere5fecec2018-10-11 11:02:52 +01002837
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002838component_test_malloc_0_null () {
2839 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002840 scripts/config.py full
Gilles Peskine2e70f1c2023-07-20 19:00:15 +02002841 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 +02002842
2843 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
2844 make test
2845
2846 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
2847 # Just the calloc selftest. "make test" ran the others as part of the
2848 # test suites.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002849 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01002850
2851 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
2852 # Run a subset of the tests. The choice is a balance between coverage
2853 # and time (including time indirectly wasted due to flaky tests).
2854 # The current choice is to skip tests whose description includes
2855 # "proxy", which is an approximation of skipping tests that use the
2856 # UDP proxy, which tend to be slower and flakier.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002857 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002858}
2859
Gilles Peskine8f073122018-11-27 15:58:47 +01002860component_test_aes_fewer_tables () {
2861 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002862 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Dave Rodgmance04f242024-01-04 10:34:31 +00002863 make CFLAGS='-O2 -Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002864
Gilles Peskine8f073122018-11-27 15:58:47 +01002865 msg "test: AES_FEWER_TABLES"
2866 make test
2867}
Hanno Becker83ebf782017-07-07 12:29:15 +01002868
Gilles Peskine8f073122018-11-27 15:58:47 +01002869component_test_aes_rom_tables () {
2870 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002871 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Dave Rodgmance04f242024-01-04 10:34:31 +00002872 make CFLAGS='-O2 -Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002873
Gilles Peskine8f073122018-11-27 15:58:47 +01002874 msg "test: AES_ROM_TABLES"
2875 make test
2876}
Hanno Becker83ebf782017-07-07 12:29:15 +01002877
Gilles Peskine8f073122018-11-27 15:58:47 +01002878component_test_aes_fewer_tables_and_rom_tables () {
2879 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002880 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2881 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Dave Rodgmance04f242024-01-04 10:34:31 +00002882 make CFLAGS='-O2 -Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002883
Gilles Peskine8f073122018-11-27 15:58:47 +01002884 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2885 make test
2886}
2887
Gilles Peskine592f5912019-10-07 18:49:32 +02002888component_test_ctr_drbg_aes_256_sha_256 () {
2889 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002890 scripts/config.py full
2891 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2892 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002893 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2894 make
2895
2896 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2897 make test
2898}
2899
2900component_test_ctr_drbg_aes_128_sha_512 () {
2901 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002902 scripts/config.py full
2903 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2904 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02002905 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2906 make
2907
2908 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2909 make test
2910}
2911
2912component_test_ctr_drbg_aes_128_sha_256 () {
2913 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002914 scripts/config.py full
2915 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2916 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2917 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002918 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2919 make
2920
2921 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2922 make test
2923}
2924
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002925component_test_se_default () {
2926 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002927 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02002928 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002929
2930 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2931 make test
2932}
2933
Steven Cooremand57203d2020-07-16 20:28:59 +02002934component_test_psa_crypto_drivers () {
Gilles Peskine8d77ec22023-07-26 18:45:20 +02002935 msg "build: full + test drivers dispatching to builtins"
Steven Cooreman753f9732021-03-15 11:38:44 +01002936 scripts/config.py full
Steven Cooremand57203d2020-07-16 20:28:59 +02002937 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
Gilles Peskinefe0acc62021-09-20 19:20:04 +02002938 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
2939 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002940 loc_cflags="${loc_cflags} -I../tests/include -O2"
2941
2942 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002943
Gilles Peskine8d77ec22023-07-26 18:45:20 +02002944 msg "test: full + test drivers dispatching to builtins"
Steven Cooremand57203d2020-07-16 20:28:59 +02002945 make test
2946}
2947
Gilles Peskine8f073122018-11-27 15:58:47 +01002948component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002949 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002950 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02002951 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine27482f12021-11-04 12:52:14 +01002952 programs/test/dlopen_demo.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002953}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02002954
Gilles Peskinecf740502019-07-03 20:43:05 +02002955component_test_cmake_shared () {
2956 msg "build/test: cmake shared" # ~ 2min
2957 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
2958 make
Gilles Peskine56c01612019-07-03 20:43:32 +02002959 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02002960 make test
Gilles Peskine27482f12021-11-04 12:52:14 +01002961 programs/test/dlopen_demo.sh
Gilles Peskinecf740502019-07-03 20:43:05 +02002962}
2963
Gilles Peskineec10bf12019-09-20 19:56:06 +02002964test_build_opt () {
2965 info=$1 cc=$2; shift 2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002966 $cc --version
Gilles Peskineec10bf12019-09-20 19:56:06 +02002967 for opt in "$@"; do
2968 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskinee094a182020-04-14 20:08:41 +02002969 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02002970 # We're confident enough in compilers to not run _all_ the tests,
2971 # but at least run the unit tests. In particular, runs with
2972 # optimizations use inline assembly whereas runs with -O0
2973 # skip inline assembly.
2974 make test # ~30s
2975 make clean
2976 done
2977}
2978
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002979# For FreeBSD we invoke the function by name so this condition is added
2980# to disable the existing test_clang_opt function for linux.
2981if [[ $(uname) != "Linux" ]]; then
2982 component_test_clang_opt () {
2983 scripts/config.py full
2984 test_build_opt 'full config' clang -O0 -Os -O2
2985 }
2986fi
2987
2988component_test_clang_latest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002989 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002990 test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002991}
2992support_test_clang_latest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002993 type "$CLANG_LATEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02002994}
2995
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002996component_test_clang_earliest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002997 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01002998 test_build_opt 'full config' "$CLANG_EARLIEST" -O0
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002999}
3000support_test_clang_earliest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003001 type "$CLANG_EARLIEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003002}
3003
3004component_test_gcc_latest_opt () {
3005 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003006 test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003007}
3008support_test_gcc_latest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003009 type "$GCC_LATEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003010}
3011
3012component_test_gcc_earliest_opt () {
3013 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003014 test_build_opt 'full config' "$GCC_EARLIEST" -O0
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003015}
3016support_test_gcc_earliest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003017 type "$GCC_EARLIEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02003018}
3019
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02003020component_build_mbedtls_config_file () {
3021 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
Gilles Peskine6af9dc92022-04-07 20:55:57 +02003022 scripts/config.py -w full_config.h full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02003023 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
3024 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02003025 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine036a9bb2022-04-07 21:06:41 +02003026 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3027 make clean
3028
3029 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
3030 # In the user config, disable one feature (for simplicity, pick a feature
3031 # that nothing else depends on).
3032 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3033 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
3034 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3035
3036 rm -f user_config.h full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003037}
3038
Gilles Peskine690a2ef2022-04-07 21:59:14 +02003039component_build_psa_config_file () {
3040 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
3041 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3042 cp "$CRYPTO_CONFIG_H" psa_test_config.h
3043 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
3044 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_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 Peskine690a2ef2022-04-07 21:59:14 +02003046 programs/test/query_compile_time_config MBEDTLS_CMAC_C
3047 make clean
3048
3049 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
3050 # In the user config, disable one feature, which will reflect on the
3051 # mbedtls configuration so we can query it with query_compile_time_config.
3052 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
3053 scripts/config.py unset MBEDTLS_CMAC_C
3054 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
3055 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
3056
3057 rm -f psa_test_config.h psa_user_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003058}
3059
Gilles Peskine8f073122018-11-27 15:58:47 +01003060component_test_m32_o0 () {
Gilles Peskinea0c51fb2021-10-07 19:27:16 +02003061 # Build without optimization, so as to use portable C code (in a 32-bit
3062 # build) and not the i386-specific inline assembly.
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003063 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003064 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02003065 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01003066
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003067 msg "test: i386, make, gcc -O0 (ASan build)"
3068 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01003069}
Gilles Peskine878cf602019-01-06 20:50:38 +00003070support_test_m32_o0 () {
3071 case $(uname -m) in
Pengyu Lva89b3672022-10-21 10:50:26 +00003072 amd64|x86_64) true;;
Gilles Peskine878cf602019-01-06 20:50:38 +00003073 *) false;;
3074 esac
3075}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003076
Gilles Peskine6fa69862021-10-05 09:36:03 +02003077component_test_m32_o2 () {
3078 # Build with optimization, to use the i386 specific inline assembly
3079 # and go faster for tests.
3080 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003081 scripts/config.py full
Gilles Peskine6fa69862021-10-05 09:36:03 +02003082 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003083
Gilles Peskine6fa69862021-10-05 09:36:03 +02003084 msg "test: i386, make, gcc -O2 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003085 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003086
Gilles Peskine6fa69862021-10-05 09:36:03 +02003087 msg "test ssl-opt.sh, i386, make, gcc-O2"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003088 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003089}
Gilles Peskine3daa83e2021-10-07 19:25:29 +02003090support_test_m32_o2 () {
Gilles Peskine878cf602019-01-06 20:50:38 +00003091 support_test_m32_o0 "$@"
3092}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003093
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003094component_test_m32_everest () {
3095 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003096 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
3097 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02003098 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003099
3100 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
3101 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003102
3103 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003104 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01003105
3106 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
3107 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003108 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003109}
3110support_test_m32_everest () {
3111 support_test_m32_o0 "$@"
3112}
3113
Gilles Peskine8f073122018-11-27 15:58:47 +01003114component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003115 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003116 scripts/config.py full
Dave Rodgmance04f242024-01-04 10:34:31 +00003117 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003118
3119 msg "test: 64-bit ILP32, make, gcc"
3120 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01003121}
Gilles Peskine878cf602019-01-06 20:50:38 +00003122support_test_mx32 () {
3123 case $(uname -m) in
3124 amd64|x86_64) true;;
3125 *) false;;
3126 esac
3127}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003128
Peter Kolbus60c6da22018-12-27 06:59:04 -06003129component_test_min_mpi_window_size () {
3130 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003131 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06003132 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3133 make
3134
3135 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
3136 make test
3137}
3138
Gilles Peskine8f073122018-11-27 15:58:47 +01003139component_test_have_int32 () {
3140 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003141 scripts/config.py unset MBEDTLS_HAVE_ASM
3142 scripts/config.py unset MBEDTLS_AESNI_C
3143 scripts/config.py unset MBEDTLS_PADLOCK_C
Dave Rodgmance04f242024-01-04 10:34:31 +00003144 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01003145
Gilles Peskine8f073122018-11-27 15:58:47 +01003146 msg "test: gcc, force 32-bit bignum limbs"
3147 make test
3148}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01003149
Gilles Peskine8f073122018-11-27 15:58:47 +01003150component_test_have_int64 () {
3151 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003152 scripts/config.py unset MBEDTLS_HAVE_ASM
3153 scripts/config.py unset MBEDTLS_AESNI_C
3154 scripts/config.py unset MBEDTLS_PADLOCK_C
Dave Rodgmance04f242024-01-04 10:34:31 +00003155 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01003156
Gilles Peskine8f073122018-11-27 15:58:47 +01003157 msg "test: gcc, force 64-bit bignum limbs"
3158 make test
3159}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003160
Gilles Peskine8f073122018-11-27 15:58:47 +01003161component_test_no_udbl_division () {
3162 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003163 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003164 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01003165 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003166
Gilles Peskine8f073122018-11-27 15:58:47 +01003167 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
3168 make test
3169}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003170
Gilles Peskine8f073122018-11-27 15:58:47 +01003171component_test_no_64bit_multiplication () {
3172 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003173 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003174 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01003175 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003176
Gilles Peskine8f073122018-11-27 15:58:47 +01003177 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
3178 make test
3179}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003180
Gilles Peskine3809f5f2020-11-09 15:40:05 +01003181component_test_no_strings () {
3182 msg "build: no strings" # ~10s
3183 scripts/config.py full
3184 # Disable options that activate a large amount of string constants.
3185 scripts/config.py unset MBEDTLS_DEBUG_C
3186 scripts/config.py unset MBEDTLS_ERROR_C
3187 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
3188 scripts/config.py unset MBEDTLS_VERSION_FEATURES
3189 make CFLAGS='-Werror -Os'
3190
3191 msg "test: no strings" # ~ 10s
3192 make test
3193}
3194
Gilles Peskine8f073122018-11-27 15:58:47 +01003195component_build_arm_none_eabi_gcc () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003196 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003197 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02003198 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 +02003199
Gilles Peskine60d99472021-09-01 20:00:33 +02003200 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003201 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003202}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003203
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003204component_build_arm_linux_gnueabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003205 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003206 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02003207 # Build for a target platform that's close to what Debian uses
3208 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
Dave Rodgman52af7692022-03-31 14:27:24 +01003209 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003210 # Build everything including programs, see for example
Dave Rodgman52af7692022-03-31 14:27:24 +01003211 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003212 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'
3213
Gilles Peskine60d99472021-09-01 20:00:33 +02003214 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003215 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size library/*.o
3216}
3217support_build_arm_linux_gnueabi_gcc_arm5vte () {
3218 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
3219}
3220
3221component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003222 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003223 scripts/config.py baremetal
3224 # This is an imperfect substitute for
3225 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnard9a260a62021-07-06 09:44:59 +02003226 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02003227 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 +02003228
Gilles Peskine60d99472021-09-01 20:00:33 +02003229 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003230 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02003231}
3232
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003233component_build_arm_none_eabi_gcc_m0plus () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003234 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
3235 scripts/config.py baremetal_size
Gilles Peskineaeedd742020-09-02 11:03:04 +02003236 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 +02003237
Gilles Peskine60d99472021-09-01 20:00:33 +02003238 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
Gilles Peskine18487f62020-04-30 23:11:54 +02003239 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003240}
3241
Gilles Peskine8f073122018-11-27 15:58:47 +01003242component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003243 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003244 scripts/config.py baremetal
3245 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003246 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 +01003247 echo "Checking that software 64-bit division is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003248 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003249}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003250
Gilles Peskine8f073122018-11-27 15:58:47 +01003251component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003252 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003253 scripts/config.py baremetal
3254 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003255 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 +01003256 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003257 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003258}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003259
Dave Rodgman43ea9ab2023-06-02 10:26:24 -04003260component_build_arm_clang_thumb () {
3261 # ~ 30s
3262
3263 scripts/config.py baremetal
3264
3265 msg "build: clang thumb 2, make"
3266 make clean
3267 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
3268
3269 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
3270 msg "build: clang thumb 1 -O0, make"
3271 make clean
3272 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
3273
3274 msg "build: clang thumb 1 -Os, make"
3275 make clean
3276 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
3277}
3278
Gilles Peskine8f073122018-11-27 15:58:47 +01003279component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02003280 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003281 scripts/config.py baremetal
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003282 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02003283
3284 msg "size: ARM Compiler 5"
3285 "$ARMC5_FROMELF" -z library/*.o
3286
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003287 make clean
Andres AG87bb5772016-09-27 15:05:15 +01003288
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003289 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
3290
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003291 # ARM Compiler 6 - Target ARMv7-A
3292 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003293
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003294 # ARM Compiler 6 - Target ARMv7-M
3295 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02003296
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003297 # ARM Compiler 6 - Target ARMv8-A - AArch32
3298 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003299
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003300 # ARM Compiler 6 - Target ARMv8-M
3301 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02003302
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003303 # ARM Compiler 6 - Target ARMv8-A - AArch64
3304 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003305
3306 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
3307 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
3308
3309 # ARM Compiler 6 - Target Cortex-M0
3310 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
Gilles Peskine8f073122018-11-27 15:58:47 +01003311}
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003312
Pengyu Lvd216c042023-03-03 18:23:35 +08003313support_build_armcc () {
3314 armc5_cc="$ARMC5_BIN_DIR/armcc"
3315 armc6_cc="$ARMC6_BIN_DIR/armclang"
3316 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
3317}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01003318
Manuel Pégourié-Gonnarddd8807f2020-02-26 09:56:27 +01003319component_build_ssl_hw_record_accel() {
3320 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
3321 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
3322 make CFLAGS='-Werror -O1'
3323}
3324
Hanno Beckera711f6e2020-05-04 12:03:51 +01003325component_test_tls13_experimental () {
3326 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3327 scripts/config.pl set MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
3328 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3329 make
3330 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3331 make test
3332}
3333
Gilles Peskine8f073122018-11-27 15:58:47 +01003334component_build_mingw () {
3335 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003336 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 +00003337
Gilles Peskine8f073122018-11-27 15:58:47 +01003338 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003339 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 +01003340 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02003341
Gilles Peskine8f073122018-11-27 15:58:47 +01003342 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003343 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
3344 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 +01003345 make WINDOWS_BUILD=1 clean
Pengyu Lvb2ca0322023-10-19 17:17:19 +08003346
3347 msg "build: Windows cross build - mingw64, make (Library only, AESNI intrinsics)" # ~ 30s
3348 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 +08003349 make WINDOWS_BUILD=1 clean
3350
3351 msg "build: Windows cross build - mingw64, make (Library only, default config without MBEDTLS_AESNI_C)" # ~ 30s
3352 ./scripts/config.py unset MBEDTLS_AESNI_C
3353 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib
3354 make WINDOWS_BUILD=1 clean
Pengyu Lvb2ca0322023-10-19 17:17:19 +08003355 }
Jaeden Amero117b8a42019-04-17 15:19:26 +01003356support_build_mingw() {
Pengyu Lva19ce122023-02-24 15:38:52 +08003357 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
3358 [0-5]*|"") false;;
Jaeden Amero117b8a42019-04-17 15:19:26 +01003359 *) true;;
3360 esac
3361}
Simon Butcher91aef332016-11-17 09:20:50 +00003362
Gilles Peskine8f073122018-11-27 15:58:47 +01003363component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003364 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003365 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003366 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
3367 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02003368
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003369 msg "test: main suites (MSan)" # ~ 10s
3370 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003371
Gilles Peskineee8af062023-11-02 19:58:03 +01003372 msg "test: metatests (MSan)"
3373 tests/scripts/run-metatests.sh any msan
3374
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02003375 msg "program demos (MSan)" # ~20s
3376 tests/scripts/run_demos.py
3377
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003378 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003379 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003380
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003381 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003382
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003383 if [ "$MEMORY" -gt 0 ]; then
3384 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003385 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003386 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003387}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003388
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01003389component_release_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003390 msg "build: Release (clang)"
Gilles Peskine619b73d2022-11-29 16:45:30 +01003391 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003392 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3393 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003394
Gilles Peskine619b73d2022-11-29 16:45:30 +01003395 msg "test: main suites, Valgrind (default config)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003396 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003397
Gilles Peskine636c26a2020-03-04 20:46:15 +01003398 # Optional parts (slow; currently broken on OS X because programs don't
3399 # seem to receive signals under valgrind on OS X).
Gilles Peskine619b73d2022-11-29 16:45:30 +01003400 # These optional parts don't run on the CI.
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003401 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003402 msg "test: ssl-opt.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003403 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003404 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003405
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003406 if [ "$MEMORY" -gt 1 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003407 msg "test: compat.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003408 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003409 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003410
3411 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003412 msg "test: context-info.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003413 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003414 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003415}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003416
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01003417component_release_test_valgrind_psa () {
Gilles Peskine619b73d2022-11-29 16:45:30 +01003418 msg "build: Release, full (clang)"
3419 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
3420 scripts/config.py full
3421 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3422 make
3423
3424 msg "test: main suites, Valgrind (full config)"
3425 make memcheck
3426}
3427
Paul Elliott2ab9a7a2021-11-25 17:29:40 +00003428support_test_cmake_out_of_source () {
3429 distrib_id=""
3430 distrib_ver=""
3431 distrib_ver_minor=""
3432 distrib_ver_major=""
3433
3434 # Attempt to parse lsb-release to find out distribution and version. If not
3435 # found this should fail safe (test is supported).
3436 if [[ -f /etc/lsb-release ]]; then
3437
3438 while read -r lsb_line; do
3439 case "$lsb_line" in
3440 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
3441 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
3442 esac
3443 done < /etc/lsb-release
3444
3445 distrib_ver_major="${distrib_ver%%.*}"
3446 distrib_ver="${distrib_ver#*.}"
3447 distrib_ver_minor="${distrib_ver%%.*}"
3448 fi
3449
3450 # Running the out of source CMake test on Ubuntu 16.04 using more than one
3451 # processor (as the CI does) can create a race condition whereby the build
3452 # fails to see a generated file, despite that file actually having been
3453 # generated. This problem appears to go away with 18.04 or newer, so make
3454 # the out of source tests unsupported on Ubuntu 16.04.
3455 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
3456}
3457
Gilles Peskine8f073122018-11-27 15:58:47 +01003458component_test_cmake_out_of_source () {
3459 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01003460 MBEDTLS_ROOT_DIR="$PWD"
3461 mkdir "$OUT_OF_SOURCE_DIR"
3462 cd "$OUT_OF_SOURCE_DIR"
Gilles Peskine25319702021-10-07 19:34:57 +02003463 cmake -D CMAKE_BUILD_TYPE:String=Check "$MBEDTLS_ROOT_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003464 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003465
Gilles Peskine8f073122018-11-27 15:58:47 +01003466 msg "test: cmake 'out-of-source' build"
3467 make test
3468 # Test an SSL option that requires an auxiliary script in test/scripts/.
3469 # Also ensure that there are no error messages such as
3470 # "No such file or directory", which would indicate that some required
3471 # file is missing (ssl-opt.sh tolerates the absence of some files so
3472 # may exit with status 0 but emit errors).
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003473 ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' >ssl-opt.out 2>ssl-opt.err
3474 grep PASS ssl-opt.out
Gilles Peskine0a7984f2020-03-28 18:56:09 +01003475 cat ssl-opt.err >&2
3476 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003477 [ ! -s ssl-opt.err ]
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003478 rm ssl-opt.out ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01003479 cd "$MBEDTLS_ROOT_DIR"
3480 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003481}
Andres AGdc192212016-08-31 17:33:13 +01003482
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003483component_test_cmake_as_subdirectory () {
3484 msg "build: cmake 'as-subdirectory' build"
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003485 cd programs/test/cmake_subproject
3486 cmake .
3487 make
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003488 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003489}
Gilles Peskineca9cfca2022-02-04 00:21:12 +01003490support_test_cmake_as_subdirectory () {
3491 support_test_cmake_out_of_source
3492}
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003493
David Horstmann175afbd2023-01-12 14:17:01 +00003494component_build_cmake_custom_config_file () {
David Horstmann67622312023-01-31 10:34:44 +00003495 # Make a copy of config file to use for the in-tree test
3496 cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h
David Horstmann175afbd2023-01-12 14:17:01 +00003497
3498 MBEDTLS_ROOT_DIR="$PWD"
3499 mkdir "$OUT_OF_SOURCE_DIR"
3500 cd "$OUT_OF_SOURCE_DIR"
3501
David Horstmann67622312023-01-31 10:34:44 +00003502 # Build once to get the generated files (which need an intact config file)
David Horstmann175afbd2023-01-12 14:17:01 +00003503 cmake "$MBEDTLS_ROOT_DIR"
3504 make
3505
3506 msg "build: cmake with -DMBEDTLS_CONFIG_FILE"
3507 scripts/config.py -w full_config.h full
David Horstmann67622312023-01-31 10:34:44 +00003508 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003509 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR"
3510 make
3511
3512 msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
3513 # In the user config, disable one feature (for simplicity, pick a feature
3514 # that nothing else depends on).
3515 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3516
3517 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR"
3518 make
3519 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3520
3521 rm -f user_config.h full_config.h
3522
3523 cd "$MBEDTLS_ROOT_DIR"
3524 rm -rf "$OUT_OF_SOURCE_DIR"
3525
3526 # Now repeat the test for an in-tree build:
3527
David Horstmann67622312023-01-31 10:34:44 +00003528 # Restore config for the in-tree test
3529 mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003530
David Horstmann67622312023-01-31 10:34:44 +00003531 # Build once to get the generated files (which need an intact config)
David Horstmann175afbd2023-01-12 14:17:01 +00003532 cmake .
3533 make
3534
3535 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE"
3536 scripts/config.py -w full_config.h full
David Horstmann67622312023-01-31 10:34:44 +00003537 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003538 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h .
3539 make
3540
3541 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
3542 # In the user config, disable one feature (for simplicity, pick a feature
3543 # that nothing else depends on).
3544 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3545
3546 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h .
3547 make
3548 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3549
3550 rm -f user_config.h full_config.h
3551}
3552support_build_cmake_custom_config_file () {
3553 support_test_cmake_out_of_source
3554}
3555
3556
Tom Cosgrove51170622023-09-01 10:40:15 +01003557component_build_zeroize_checks () {
3558 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
3559
3560 scripts/config.py full
3561
3562 # Only compile - we're looking for sizeof-pointer-memaccess warnings
Dave Rodgman374b1882024-01-04 10:30:57 +00003563 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 +01003564}
3565
3566
Gilles Peskine8f073122018-11-27 15:58:47 +01003567component_test_zeroize () {
3568 # Test that the function mbedtls_platform_zeroize() is not optimized away by
3569 # different combinations of compilers and optimization flags by using an
3570 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
3571 # system in all cases that the script fails, so we must manually search the
3572 # output to check whether the pass string is present and no failure strings
3573 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01003574
Gilles Peskine4976e822019-01-06 19:52:22 +00003575 # Don't try to disable ASLR. We don't care about ASLR here. We do care
3576 # about a spurious message if Gdb tries and fails, so suppress that.
3577 gdb_disable_aslr=
3578 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
3579 gdb_disable_aslr='set disable-randomization off'
3580 fi
3581
Gilles Peskine8f073122018-11-27 15:58:47 +01003582 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01003583 for compiler in clang gcc; do
3584 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
3585 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003586 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
3587 grep "The buffer was correctly zeroized" test_zeroize.log
3588 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01003589 rm -f test_zeroize.log
3590 make clean
3591 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01003592 done
Gilles Peskine8f073122018-11-27 15:58:47 +01003593}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003594
Bence Szépkúti9f849112021-10-19 15:05:36 +02003595component_test_psa_compliance () {
Dave Rodgmanb0660c22023-12-18 19:55:40 +00003596 # The arch tests build with gcc, so require use of gcc here to link properly
Bence Szépkútic1e79fd2021-11-11 20:13:14 +01003597 msg "build: make, default config + CMAC, libmbedcrypto.a only"
3598 scripts/config.py set MBEDTLS_CMAC_C
Dave Rodgmanb0660c22023-12-18 19:55:40 +00003599 CC=gcc make -C library libmbedcrypto.a
Bence Szépkúti9f849112021-10-19 15:05:36 +02003600
3601 msg "unit test: test_psa_compliance.py"
Dave Rodgman5b00fb12023-12-18 22:29:56 +00003602 CC=gcc ./tests/scripts/test_psa_compliance.py
Bence Szépkúti9f849112021-10-19 15:05:36 +02003603}
3604
3605support_test_psa_compliance () {
Bence Szépkútid6cf0892021-11-03 11:36:09 +01003606 # psa-compliance-tests only supports CMake >= 3.10.0
Bence Szépkútiab796e62021-10-25 19:29:07 +02003607 ver="$(cmake --version)"
3608 ver="${ver#cmake version }"
3609 ver_major="${ver%%.*}"
3610
3611 ver="${ver#*.}"
3612 ver_minor="${ver%%.*}"
3613
3614 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
Bence Szépkúti9f849112021-10-19 15:05:36 +02003615}
3616
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003617component_check_code_style () {
3618 msg "Check C code style"
3619 ./scripts/code_style.py
David Horstmanne09c4762022-11-10 18:30:52 +00003620}
3621
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003622support_check_code_style() {
David Horstmanne09c4762022-11-10 18:30:52 +00003623 case $(uncrustify --version) in
3624 *0.75.1*) true;;
3625 *) false;;
3626 esac
3627}
3628
Gilles Peskine8f073122018-11-27 15:58:47 +01003629component_check_python_files () {
3630 msg "Lint: Python scripts"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003631 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003632}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003633
Gilles Peskine8f073122018-11-27 15:58:47 +01003634component_check_generate_test_code () {
3635 msg "uint test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02003636 # unittest writes out mundane stuff like number or tests run on stderr.
3637 # Our convention is to reserve stderr for actual errors, and write
3638 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003639 ./tests/scripts/test_generate_test_code.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01003640}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003641
3642################################################################
3643#### Termination
3644################################################################
3645
Gilles Peskine8f073122018-11-27 15:58:47 +01003646post_report () {
3647 msg "Done, cleaning up"
Gilles Peskine24bdf022020-03-30 20:11:39 +02003648 final_cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003649
Gilles Peskine8f073122018-11-27 15:58:47 +01003650 final_report
3651}
3652
3653
3654
3655################################################################
3656#### Run all the things
3657################################################################
3658
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003659# Function invoked by --error-test to test error reporting.
3660pseudo_component_error_test () {
Gilles Peskine202e9b42021-08-02 23:28:00 +02003661 msg "Testing error reporting $error_test_i"
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003662 if [ $KEEP_GOING -ne 0 ]; then
3663 echo "Expect three failing commands."
3664 fi
Gilles Peskine202e9b42021-08-02 23:28:00 +02003665 # If the component doesn't run in a subshell, changing error_test_i to an
3666 # invalid integer will cause an error in the loop that runs this function.
3667 error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003668 # Expected error: 'grep non_existent /dev/null -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003669 grep non_existent /dev/null
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003670 # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003671 not grep -q . "$0"
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003672 # Expected error: 'make unknown_target -> 2'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003673 make unknown_target
3674 false "this should not be executed"
3675}
3676
Gilles Peskinee48351a2018-11-27 16:06:30 +01003677# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01003678run_component () {
Gilles Peskineffcdeff2018-12-04 12:49:28 +01003679 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02003680 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003681
3682 # Unconditionally create a seedfile that's sufficiently long.
3683 # Do this before each component, because a previous component may
3684 # have messed it up or shortened it.
Gilles Peskinef3133362021-07-08 19:03:50 +02003685 local dd_cmd
3686 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
3687 case $OSTYPE in
3688 linux*|freebsd*|openbsd*|darwin*) dd_cmd+=(status=none)
3689 esac
3690 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003691
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003692 # Run the component in a subshell, with error trapping and output
3693 # redirection set up based on the relevant options.
Gilles Peskine7105a332020-03-28 18:50:43 +01003694 if [ $KEEP_GOING -eq 1 ]; then
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003695 # We want to keep running if the subshell fails, so 'set -e' must
3696 # be off when the subshell runs.
Gilles Peskine7105a332020-03-28 18:50:43 +01003697 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02003698 fi
Gilles Peskine7105a332020-03-28 18:50:43 +01003699 (
3700 if [ $QUIET -eq 1 ]; then
3701 # msg() will be silenced, so just print the component name here.
3702 echo "${current_component#component_}"
3703 exec >/dev/null
3704 fi
3705 if [ $KEEP_GOING -eq 1 ]; then
3706 # Keep "set -e" off, and run an ERR trap instead to record failures.
3707 set -E
3708 trap err_trap ERR
3709 fi
3710 # The next line is what runs the component
3711 "$@"
3712 if [ $KEEP_GOING -eq 1 ]; then
3713 trap - ERR
3714 exit $last_failure_status
3715 fi
3716 )
3717 component_status=$?
3718 if [ $KEEP_GOING -eq 1 ]; then
3719 set -e
3720 if [ $component_status -ne 0 ]; then
3721 failure_count=$((failure_count + 1))
3722 fi
3723 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003724
3725 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01003726 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02003727 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01003728}
3729
3730# Preliminary setup
3731pre_check_environment
3732pre_initialize_variables
3733pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01003734
Gilles Peskine878cf602019-01-06 20:50:38 +00003735pre_check_git
Gilles Peskineef64e7f2021-07-12 18:16:01 +02003736pre_restore_files
Gilles Peskine24bdf022020-03-30 20:11:39 +02003737pre_back_up
Andrzej Kurekeb508712019-02-14 07:18:59 -05003738
Gilles Peskine878cf602019-01-06 20:50:38 +00003739build_status=0
3740if [ $KEEP_GOING -eq 1 ]; then
3741 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01003742fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02003743pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00003744pre_print_configuration
3745pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003746cleanup
3747
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003748# Run the requested tests.
Gilles Peskine202e9b42021-08-02 23:28:00 +02003749for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003750 run_component pseudo_component_error_test
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003751done
Gilles Peskine202e9b42021-08-02 23:28:00 +02003752unset error_test_i
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003753for component in $RUN_COMPONENTS; do
3754 run_component "component_$component"
3755done
Gilles Peskine8f073122018-11-27 15:58:47 +01003756
3757# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00003758post_report