blob: 34ba5251ad7f234152c776a38af3e20c64012fff [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
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02006# SPDX-License-Identifier: Apache-2.0
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
Gilles Peskine192c72f2017-12-21 15:59:21 +010019
20
21
22################################################################
23#### Documentation
24################################################################
25
Simon Butcher3ea7f522016-03-07 23:22:10 +000026# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010027# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000028#
SimonB2e23c822016-04-16 21:54:39 +010029# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# Notes for users
32# ---------------
33#
SimonB2e23c822016-04-16 21:54:39 +010034# Warning: the test is destructive. It includes various build modes and
35# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010036# configuration. The following files must be committed into git:
37# * include/mbedtls/config.h
Gilles Peskine636c26a2020-03-04 20:46:15 +010038# * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
39# programs/fuzz/Makefile
Gilles Peskine192c72f2017-12-21 15:59:21 +010040# After running this script, the CMake cache will be lost and CMake
41# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010042#
Gilles Peskine192c72f2017-12-21 15:59:21 +010043# The script assumes the presence of a number of tools:
44# * Basic Unix tools (Windows users note: a Unix-style find must be before
45# the Windows find in the PATH)
46# * Perl
47# * GNU Make
48# * CMake
49# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040050# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010051# * arm-gcc and mingw-gcc
52# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010053# * OpenSSL and GnuTLS command line tools, recent enough for the
54# interoperability tests. If they don't support SSLv3 then a legacy
55# version of these tools must be present as well (search for LEGACY
56# below).
57# See the invocation of check_tools below for details.
58#
59# This script must be invoked from the toplevel directory of a git
60# working copy of Mbed TLS.
61#
62# Note that the output is not saved. You may want to run
63# script -c tests/scripts/all.sh
64# or
65# tests/scripts/all.sh >all.log 2>&1
66#
67# Notes for maintainers
68# ---------------------
69#
Gilles Peskine8f073122018-11-27 15:58:47 +010070# The bulk of the code is organized into functions that follow one of the
71# following naming conventions:
72# * pre_XXX: things to do before running the tests, in order.
73# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010074# * component_check_XXX: quick tests that aren't worth parallelizing.
75# * component_build_XXX: build things but don't run them.
76# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000077# * support_XXX: if support_XXX exists and returns false then
78# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010079# * post_XXX: things to do after running the tests.
80# * other: miscellaneous support functions.
81#
Gilles Peskinec70637a2019-01-09 22:29:17 +010082# Each component must start by invoking `msg` with a short informative message.
83#
84# The framework performs some cleanup tasks after each component. This
85# means that components can assume that the working directory is in a
86# cleaned-up state, and don't need to perform the cleanup themselves.
87# * Run `make clean`.
88# * Restore `include/mbedtks/config.h` from a backup made before running
89# the component.
Gilles Peskine636c26a2020-03-04 20:46:15 +010090# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
91# `tests/Makefile` and `programs/fuzz/Makefile` from git.
92# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +010093#
94# Any command that is expected to fail must be protected so that the
95# script keeps running in --keep-going mode despite `set -e`. In keep-going
96# mode, if a protected command fails, this is logged as a failure and the
97# script will exit with a failure status once it has run all components.
98# Commands can be protected in any of the following ways:
99# * `make` is a function which runs the `make` command with protection.
100# Note that you must write `make VAR=value`, not `VAR=value make`,
101# because the `VAR=value make` syntax doesn't work with functions.
102# * Put `report_status` before the command to protect it.
103# * Put `if_build_successful` before a command. This protects it, and
104# additionally skips it if a prior invocation of `make` in the same
105# component failed.
106#
Gilles Peskine192c72f2017-12-21 15:59:21 +0100107# The tests are roughly in order from fastest to slowest. This doesn't
108# have to be exact, but in general you should add slower tests towards
109# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100110
111
112
113################################################################
114#### Initialization and command line parsing
115################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100116
SimonB2e23c822016-04-16 21:54:39 +0100117# Abort on errors (and uninitialised variables)
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100118set -eu
119
Gilles Peskine8f073122018-11-27 15:58:47 +0100120pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000121 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100122 echo "Must be run from mbed TLS root" >&2
123 exit 1
124 fi
125}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100126
Gilles Peskine8f073122018-11-27 15:58:47 +0100127pre_initialize_variables () {
128 CONFIG_H='include/mbedtls/config.h'
129 CONFIG_BAK="$CONFIG_H.bak"
John Durkopbd069d32020-10-31 22:14:03 -0700130 CRYPTO_CONFIG_H='include/psa/crypto_config.h'
131 CRYPTO_CONFIG_BAK="$CRYPTO_CONFIG_H.bak"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200132
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200133 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100134 MEMORY=0
135 FORCE=0
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200136 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100137 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100138
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200139 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard54304472020-06-22 10:11:47 +0200140 #
141 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
142 # both values are kept in sync. If you change the value here because it
143 # breaks some tests, you'll definitely want to change it in
144 # basic-build-test.sh as well.
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200145 RELEASE_SEED=1
146
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200147 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200148 : ${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 +0200149 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200150 export MBEDTLS_TEST_PLATFORM
151
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000152 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100153 : ${OPENSSL:="openssl"}
154 : ${OPENSSL_LEGACY:="$OPENSSL"}
155 : ${OPENSSL_NEXT:="$OPENSSL"}
156 : ${GNUTLS_CLI:="gnutls-cli"}
157 : ${GNUTLS_SERV:="gnutls-serv"}
158 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
159 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
160 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
161 : ${ARMC5_BIN_DIR:=/usr/bin}
162 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskine6d061342020-04-30 18:19:32 +0200163 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200164 : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
Andres AGdc192212016-08-31 17:33:13 +0100165
Gilles Peskine8f073122018-11-27 15:58:47 +0100166 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000167 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100168 export MAKEFLAGS="-j"
169 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000170
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000171 # Include more verbose output for failing tests run by CMake
172 export CTEST_OUTPUT_ON_FAILURE=1
173
Gilles Peskine8fd59422019-10-21 17:11:33 +0200174 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Gilles Peskine5ca393f2019-10-21 19:06:33 +0200175 ASAN_CFLAGS='-Werror -Wall -Wextra -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200176
Gilles Peskine878cf602019-01-06 20:50:38 +0000177 # Gather the list of available components. These are the functions
178 # defined in this script whose name starts with "component_".
Gilles Peskine3de7be82020-03-27 16:35:23 +0100179 # Parse the script with sed. This way we get the functions in the order
180 # they are defined.
Gilles Peskine878cf602019-01-06 20:50:38 +0000181 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
182
183 # Exclude components that are not supported on this platform.
184 SUPPORTED_COMPONENTS=
185 for component in $ALL_COMPONENTS; do
186 case $(type "support_$component" 2>&1) in
187 *' function'*)
188 if ! support_$component; then continue; fi;;
189 esac
190 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
191 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100192}
Andres AG38495a32016-07-12 16:54:33 +0100193
Gilles Peskinea28db922019-01-10 00:05:18 +0100194# Test whether the component $1 is included in the command line patterns.
195is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100196{
197 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000198 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100199 set +f
200 case ${1#component_} in $pattern) return 0;; esac
201 done
202 set +f
203 return 1
204}
Andres AG7770ea82016-10-10 15:46:20 +0100205
Simon Butcher41eeccf2016-09-07 00:07:09 +0100206usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100207{
Gilles Peskine709346a2017-12-10 23:43:39 +0100208 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100209Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100210Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100211By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100212COMPONENT can be the name of a component or a shell wildcard pattern.
213
214Examples:
215 $0 "check_*"
216 Run all sanity checks.
217 $0 --no-armcc --except test_memsan
218 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100219
220Special options:
221 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000222 --list-all-components List all available test components and exit.
223 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100224
225General options:
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200226 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100227 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100228 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100229 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200230 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200231 --arm-none-eabi-gcc-prefix=<string>
232 Prefix for a cross-compiler for arm-none-eabi
233 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200234 --arm-linux-gnueabi-gcc-prefix=<string>
235 Prefix for a cross-compiler for arm-linux-gnueabi
236 (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100237 --armcc Run ARM Compiler builds (on by default).
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100238 --error-test Error test mode: run a failing function in addition
239 to any specified component.
Gilles Peskinea28db922019-01-10 00:05:18 +0100240 --except Exclude the COMPONENTs listed on the command line,
241 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200242 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100243 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100244 --no-force Refuse to overwrite modified files (default).
245 --no-keep-going Stop at the first error (default).
246 --no-memory No additional memory tests (default).
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200247 --no-quiet Print full ouput from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100248 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200249 --outcome-file=<path> File where test outcomes are written (not done if
250 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100251 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200252 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100253 -s|--seed Integer seed value to use for this test run.
254
255Tool path options:
256 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
257 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
258 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
259 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
260 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
261 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
262 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
263 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100264 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100265EOF
SimonB2e23c822016-04-16 21:54:39 +0100266}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100267
268# remove built files as well as the cmake cache/config
269cleanup()
270{
Gilles Peskinea71d64c2018-03-21 12:16:57 +0100271 if [ -n "${MBEDTLS_ROOT_DIR+set}" ]; then
272 cd "$MBEDTLS_ROOT_DIR"
273 fi
274
Gilles Peskine7c652162017-12-11 00:01:40 +0100275 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200276
Gilles Peskine31b07e22018-03-21 12:15:06 +0100277 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000278 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100279 -iname CMakeFiles -exec rm -rf {} \+ -o \
280 \( -iname cmake_install.cmake -o \
281 -iname CTestTestfile.cmake -o \
282 -iname CMakeCache.txt \) -exec rm {} \+
283 # Recover files overwritten by in-tree CMake builds
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000284 rm -f include/Makefile include/mbedtls/Makefile programs/*/Makefile
Gilles Peskine636c26a2020-03-04 20:46:15 +0100285 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
286 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200287
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100288 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
289 rm -rf programs/test/cmake_subproject/build
290 rm -f programs/test/cmake_subproject/Makefile
291 rm -f programs/test/cmake_subproject/cmake_subproject
292
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200293 if [ -f "$CONFIG_BAK" ]; then
294 mv "$CONFIG_BAK" "$CONFIG_H"
295 fi
John Durkopbd069d32020-10-31 22:14:03 -0700296
297 if [ -f "$CRYPTO_CONFIG_BAK" ]; then
298 mv "$CRYPTO_CONFIG_BAK" "$CRYPTO_CONFIG_H"
299 fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100300}
301
Gilles Peskine7c652162017-12-11 00:01:40 +0100302# Executed on exit. May be redefined depending on command line options.
303final_report () {
304 :
305}
306
307fatal_signal () {
308 cleanup
309 final_report $1
310 trap - $1
311 kill -$1 $$
312}
313
314trap 'fatal_signal HUP' HUP
315trap 'fatal_signal INT' INT
316trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200317
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100318msg()
319{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100320 if [ -n "${current_component:-}" ]; then
321 current_section="${current_component#component_}: $1"
322 else
323 current_section="$1"
324 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200325
326 if [ $QUIET -eq 1 ]; then
327 return
328 fi
329
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100330 echo ""
331 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100332 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000333 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100334 echo "******************************************************************"
335}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100336
Gilles Peskine8f073122018-11-27 15:58:47 +0100337armc6_build_test()
338{
339 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100340
Gilles Peskine18487f62020-04-30 23:11:54 +0200341 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100342 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
343 WARNING_CFLAGS='-xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200344
345 msg "size: ARM Compiler 6 ($FLAGS)"
346 "$ARMC6_FROMELF" -z library/*.o
347
Gilles Peskine8f073122018-11-27 15:58:47 +0100348 make clean
349}
Andres AGa5cd9732016-10-17 15:23:10 +0100350
Andres AGd9eba4b2016-08-26 14:42:14 +0100351err_msg()
352{
353 echo "$1" >&2
354}
355
356check_tools()
357{
358 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000359 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100360 err_msg "$TOOL not found!"
361 exit 1
362 fi
363 done
364}
365
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400366check_headers_in_cpp () {
Peter Kolbus1bc1a4c2019-02-01 17:19:08 -0600367 ls include/mbedtls | grep "\.h$" >headers.txt
Andrzej Kurek991f9fe2018-07-02 09:08:21 -0400368 <programs/test/cpp_dummy_build.cpp sed -n 's/"$//; s!^#include "mbedtls/!!p' |
369 sort |
370 diff headers.txt -
371 rm headers.txt
372}
373
Gilles Peskine8f073122018-11-27 15:58:47 +0100374pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000375 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100376 all_except=0
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100377 error_test=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000378 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100379
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000380 # Note that legacy options are ignored instead of being omitted from this
381 # list of options, so invocations that worked with previous version of
382 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100383 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100384 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200385 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200386 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200387 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000388 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100389 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
390 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100391 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000392 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100393 --force|-f) FORCE=1;;
394 --gnutls-cli) shift; GNUTLS_CLI="$1";;
395 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
396 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
397 --gnutls-serv) shift; GNUTLS_SERV="$1";;
398 --help|-h) usage; exit;;
399 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000400 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
401 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100402 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200403 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000404 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100405 --no-force) FORCE=0;;
406 --no-keep-going) KEEP_GOING=0;;
407 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200408 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100409 --openssl) shift; OPENSSL="$1";;
410 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
411 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200412 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100413 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200414 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100415 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200416 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100417 --seed|-s) shift; SEED="$1";;
418 -*)
419 echo >&2 "Unknown option: $1"
420 echo >&2 "Run $0 --help for usage."
421 exit 120
422 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000423 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100424 esac
425 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100426 done
SimonB2e23c822016-04-16 21:54:39 +0100427
Gilles Peskinea28db922019-01-10 00:05:18 +0100428 # With no list of components, run everything.
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000429 if [ -z "$COMMAND_LINE_COMPONENTS" ]; then
430 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100431 fi
432
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000433 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
434 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100435 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000436 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100437 fi
SimonB2e23c822016-04-16 21:54:39 +0100438
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000439 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100440 RUN_COMPONENTS=
441 for component in $SUPPORTED_COMPONENTS; do
442 if is_component_included "$component"; [ $? -eq $all_except ]; then
443 RUN_COMPONENTS="$RUN_COMPONENTS $component"
444 fi
445 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000446
447 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000448 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100449}
SimonB2e23c822016-04-16 21:54:39 +0100450
Gilles Peskine8f073122018-11-27 15:58:47 +0100451pre_check_git () {
452 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100453 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100454 git checkout-index -f -q $CONFIG_H
455 cleanup
456 else
SimonB2e23c822016-04-16 21:54:39 +0100457
Gilles Peskine8f073122018-11-27 15:58:47 +0100458 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
459 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
460 echo "You can either delete this directory manually, or force the test by rerunning"
461 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
462 exit 1
463 fi
464
Gilles Peskined1174cf2019-01-09 22:30:01 +0100465 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100466 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
467 echo "You can either delete or preserve your work, or force the test by rerunning the"
468 echo "script as: $0 --force"
469 exit 1
470 fi
SimonB2e23c822016-04-16 21:54:39 +0100471 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500472}
473
Gilles Peskine8f073122018-11-27 15:58:47 +0100474pre_setup_keep_going () {
Gilles Peskine7c652162017-12-11 00:01:40 +0100475 failure_summary=
476 failure_count=0
477 start_red=
478 end_color=
479 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100480 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100481 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
482 start_red=$(printf '\033[31m')
483 end_color=$(printf '\033[0m')
484 ;;
485 esac
486 fi
487 record_status () {
488 if "$@"; then
489 last_status=0
490 else
491 last_status=$?
492 text="$current_section: $* -> $last_status"
493 failure_summary="$failure_summary
494$text"
495 failure_count=$((failure_count + 1))
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200496 echo "${start_red}^^^^$text^^^^${end_color}" >&2
Gilles Peskine7c652162017-12-11 00:01:40 +0100497 fi
498 }
499 make () {
500 case "$*" in
501 *test|*check)
502 if [ $build_status -eq 0 ]; then
503 record_status command make "$@"
504 else
505 echo "(skipped because the build failed)"
506 fi
507 ;;
508 *)
509 record_status command make "$@"
510 build_status=$last_status
511 ;;
512 esac
513 }
514 final_report () {
515 if [ $failure_count -gt 0 ]; then
516 echo
517 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
518 echo "${start_red}FAILED: $failure_count${end_color}$failure_summary"
519 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Jaeden Amero7c1258d2018-07-20 16:42:14 +0100520 exit 1
Gilles Peskine7c652162017-12-11 00:01:40 +0100521 elif [ -z "${1-}" ]; then
522 echo "SUCCESS :)"
523 fi
524 if [ -n "${1-}" ]; then
525 echo "Killed by SIG$1."
526 fi
527 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100528}
529
Gilles Peskine7c652162017-12-11 00:01:40 +0100530if_build_succeeded () {
531 if [ $build_status -eq 0 ]; then
532 record_status "$@"
533 fi
534}
535
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +0200536# to be used instead of ! for commands run with
537# record_status or if_build_succeeded
538not() {
539 ! "$@"
540}
541
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200542pre_setup_quiet_redirect () {
543 if [ $QUIET -ne 1 ]; then
544 redirect_out () {
545 "$@"
546 }
Manuel Pégourié-Gonnardf1f180a2020-06-08 10:46:35 +0200547 redirect_err () {
548 "$@"
549 }
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200550 else
551 redirect_out () {
552 "$@" >/dev/null
553 }
Manuel Pégourié-Gonnardf1f180a2020-06-08 10:46:35 +0200554 redirect_err () {
555 "$@" 2>/dev/null
556 }
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200557 fi
558}
559
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200560pre_prepare_outcome_file () {
561 case "$MBEDTLS_TEST_OUTCOME_FILE" in
562 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
563 esac
564 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
565 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
566 fi
567}
568
Gilles Peskine8f073122018-11-27 15:58:47 +0100569pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200570 if [ $QUIET -eq 1 ]; then
571 return
572 fi
573
Gilles Peskine8f073122018-11-27 15:58:47 +0100574 msg "info: $0 configuration"
575 echo "MEMORY: $MEMORY"
576 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200577 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100578 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100579 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100580 echo "OPENSSL: $OPENSSL"
581 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
582 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
583 echo "GNUTLS_CLI: $GNUTLS_CLI"
584 echo "GNUTLS_SERV: $GNUTLS_SERV"
585 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
586 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
587 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
588 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
589}
Andres AG7770ea82016-10-10 15:46:20 +0100590
Andres AGd9eba4b2016-08-26 14:42:14 +0100591# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100592pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000593 # Build the list of variables to pass to output_env.sh.
594 set env
SimonB2e23c822016-04-16 21:54:39 +0100595
Gilles Peskine87964262019-01-06 22:40:00 +0000596 case " $RUN_COMPONENTS " in
597 # Require OpenSSL and GnuTLS if running any tests (as opposed to
598 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
599 # is a good enough approximation in practice.
600 *" test_"*)
601 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
602 # and ssl-opt.sh, we just export the variables they require.
603 export OPENSSL_CMD="$OPENSSL"
604 export GNUTLS_CLI="$GNUTLS_CLI"
605 export GNUTLS_SERV="$GNUTLS_SERV"
606 # Avoid passing --seed flag in every call to ssl-opt.sh
607 if [ -n "${SEED-}" ]; then
608 export SEED
609 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000610 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
611 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
612 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
613 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000614 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
615 "$GNUTLS_CLI" "$GNUTLS_SERV" \
616 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
617 ;;
618 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200619
Gilles Peskine87964262019-01-06 22:40:00 +0000620 case " $RUN_COMPONENTS " in
621 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
622 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100623
Gilles Peskine87964262019-01-06 22:40:00 +0000624 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200625 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000626 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100627
Gilles Peskine87964262019-01-06 22:40:00 +0000628 case " $RUN_COMPONENTS " in
629 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
630 esac
631
632 case " $RUN_COMPONENTS " in
633 *" test_zeroize "*) check_tools "gdb";;
634 esac
635
636 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000637 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000638 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
639 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200640 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000641 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
642 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200643 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
644 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
645 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000646 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000647
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200648 # past this point, no call to check_tool, only printing output
649 if [ $QUIET -eq 1 ]; then
650 return
651 fi
652
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000653 msg "info: output_env.sh"
654 case $RUN_COMPONENTS in
655 *_armcc*)
656 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
657 *) set "$@" RUN_ARMCC=0;;
658 esac
659 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100660}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100661
Gilles Peskine192c72f2017-12-21 15:59:21 +0100662
663
664################################################################
665#### Basic checks
666################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100667
668#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200669# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100670#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100671# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200672# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100673# 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 +0200674# time, so start with a GCC build).
675# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100676#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100677# Indicative running times are given for reference.
678
Gilles Peskine8f073122018-11-27 15:58:47 +0100679component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200680 msg "Check: recursion.pl" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100681 record_status tests/scripts/recursion.pl library/*.c
682}
Janos Follathb72c6782016-07-19 14:54:17 +0100683
Gilles Peskine8f073122018-11-27 15:58:47 +0100684component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200685 msg "Check: freshness of generated source files" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100686 record_status tests/scripts/check-generated-files.sh
687}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200688
Gilles Peskine8f073122018-11-27 15:58:47 +0100689component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200690 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine8f073122018-11-27 15:58:47 +0100691 record_status tests/scripts/check-doxy-blocks.pl
692}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200693
Gilles Peskine8f073122018-11-27 15:58:47 +0100694component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200695 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskinefb4f9332020-06-25 14:18:34 +0200696 record_status tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100697}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200698
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200699component_check_changelog () {
700 msg "Check: changelog entries" # < 1s
701 rm -f ChangeLog.new
702 record_status scripts/assemble_changelog.py -o ChangeLog.new
703 if [ -e ChangeLog.new ]; then
704 # Show the diff for information. It isn't an error if the diff is
705 # non-empty.
706 diff -u ChangeLog ChangeLog.new || true
707 rm ChangeLog.new
708 fi
709}
710
Gilles Peskine8f073122018-11-27 15:58:47 +0100711component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200712 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskine31da67b2021-09-27 20:13:00 +0200713 record_status tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100714}
Darryl Greena07039c2018-03-13 16:48:16 +0000715
Gilles Peskine895868b2019-09-19 21:30:05 +0200716component_check_test_cases () {
717 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200718 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200719 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200720 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200721 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200722 fi
Gilles Peskinefb4f9332020-06-25 14:18:34 +0200723 record_status tests/scripts/check_test_cases.py $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200724 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +0200725}
726
Gilles Peskine8f073122018-11-27 15:58:47 +0100727component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200728 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine8f073122018-11-27 15:58:47 +0100729 record_status tests/scripts/doxygen.sh
730}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200731
Gilles Peskine192c72f2017-12-21 15:59:21 +0100732
Gilles Peskine636c26a2020-03-04 20:46:15 +0100733
Gilles Peskine192c72f2017-12-21 15:59:21 +0100734################################################################
735#### Build and test many configurations and targets
736################################################################
737
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200738component_test_default_out_of_box () {
739 msg "build: make, default config (out-of-box)" # ~1min
740 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200741 # Disable fancy stuff
Gilles Peskine717cd762019-09-27 20:21:11 +0200742 SAVE_MBEDTLS_TEST_OUTCOME_FILE="$MBEDTLS_TEST_OUTCOME_FILE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200743 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200744
745 msg "test: main suites make, default config (out-of-box)" # ~10s
746 make test
747
748 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine97bea012020-04-23 23:37:45 +0200749 if_build_succeeded programs/test/selftest
Gilles Peskine717cd762019-09-27 20:21:11 +0200750
751 export MBEDTLS_TEST_OUTCOME_FILE="$SAVE_MBEDTLS_TEST_OUTCOME_FILE"
752 unset SAVE_MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200753}
754
Gilles Peskine8f073122018-11-27 15:58:47 +0100755component_test_default_cmake_gcc_asan () {
756 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100757 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
758 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200759
Gilles Peskine8f073122018-11-27 15:58:47 +0100760 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
761 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200762
Gilles Peskine97bea012020-04-23 23:37:45 +0200763 msg "test: selftest (ASan build)" # ~ 10s
764 if_build_succeeded programs/test/selftest
765
Gilles Peskine8f073122018-11-27 15:58:47 +0100766 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
767 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200768
Gilles Peskine8f073122018-11-27 15:58:47 +0100769 msg "test: compat.sh (ASan build)" # ~ 6 min
770 if_build_succeeded tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200771
772 msg "test: context-info.sh (ASan build)" # ~ 15 sec
773 if_build_succeeded tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100774}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200775
Hanno Becker01635512019-02-26 14:27:09 +0000776component_test_full_cmake_gcc_asan () {
777 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200778 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000779 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
780 make
781
782 msg "test: main suites (inc. selftests) (full config, ASan build)"
783 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +0100784
Gilles Peskine97bea012020-04-23 23:37:45 +0200785 msg "test: selftest (ASan build)" # ~ 10s
786 if_build_succeeded programs/test/selftest
787
Gilles Peskine636c26a2020-03-04 20:46:15 +0100788 msg "test: ssl-opt.sh (full config, ASan build)"
789 if_build_succeeded tests/ssl-opt.sh
790
791 msg "test: compat.sh (full config, ASan build)"
792 if_build_succeeded tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200793
794 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
795 if_build_succeeded tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100796}
797
Ronald Cronc3623db2020-10-29 10:51:32 +0100798component_test_psa_crypto_key_id_encodes_owner () {
799 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
800 scripts/config.py full
801 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
802 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
803 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
804 make
805
806 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
807 make test
808}
809
Gilles Peskine99a34622021-06-17 11:37:52 +0200810# check_renamed_symbols HEADER LIB
811# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
812# name is LIB.
813check_renamed_symbols () {
814 ! nm "$2" | sed 's/.* //' |
815 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
816}
817
Gilles Peskine984c19f2021-06-15 18:37:38 +0200818component_build_psa_crypto_spm () {
819 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
820 scripts/config.py full
821 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
822 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
823 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
824 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
825 # We can only compile, not link, since our test and sample programs
826 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
827 # is active.
828 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskine99a34622021-06-17 11:37:52 +0200829
830 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
831 # version is not present.
832 echo "Checking for renamed symbols in the library"
833 if_build_succeeded check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskine984c19f2021-06-15 18:37:38 +0200834}
835
Ronald Cron336678b2021-01-28 17:54:24 +0100836component_test_psa_crypto_client () {
837 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
838 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
839 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
840 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
841 make
842
843 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
844 make test
845}
846
Gilles Peskine636c26a2020-03-04 20:46:15 +0100847component_test_zlib_make() {
848 msg "build: zlib enabled, make"
849 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
850 make ZLIB=1 CFLAGS='-Werror -O1'
851
852 msg "test: main suites (zlib, make)"
853 make test
854
855 msg "test: ssl-opt.sh (zlib, make)"
856 if_build_succeeded tests/ssl-opt.sh
857}
858support_test_zlib_make () {
859 base=support_test_zlib_$$
860 cat <<'EOF' > ${base}.c
861#include "zlib.h"
862int main(void) { return 0; }
863EOF
864 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
865 ret=$?
866 rm -f ${base}.*
867 return $ret
868}
869
870component_test_zlib_cmake() {
871 msg "build: zlib enabled, cmake"
872 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
873 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Check .
874 make
875
876 msg "test: main suites (zlib, cmake)"
877 make test
878
879 msg "test: ssl-opt.sh (zlib, cmake)"
880 if_build_succeeded tests/ssl-opt.sh
881}
882support_test_zlib_cmake () {
883 support_test_zlib_make "$@"
Manuel Pégourié-Gonnardf2e29022020-01-24 10:17:20 +0100884}
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +0100885
Jaeden Ameroc17f2932021-05-14 08:34:32 +0100886component_test_psa_crypto_rsa_no_genprime() {
887 msg "build: default config minus MBEDTLS_GENPRIME"
888 scripts/config.py unset MBEDTLS_GENPRIME
889 make
890
891 msg "test: default config minus MBEDTLS_GENPRIME"
892 make test
893}
894
Gilles Peskine782f4112018-11-27 16:11:09 +0100895component_test_ref_configs () {
896 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
897 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
898 record_status tests/scripts/test-ref-configs.pl
899}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200900
Gilles Peskine8f073122018-11-27 15:58:47 +0100901component_test_sslv3 () {
902 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200903 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +0100904 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
905 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200906
Gilles Peskine8f073122018-11-27 15:58:47 +0100907 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
908 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +0000909
Gilles Peskine8f073122018-11-27 15:58:47 +0100910 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
911 if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2'
912 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +0000913
Gilles Peskine8f073122018-11-27 15:58:47 +0100914 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
915 if_build_succeeded tests/ssl-opt.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200916
917 msg "build: SSLv3 - context-info.sh (ASan build)" # ~ 15 sec
918 if_build_succeeded tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100919}
Simon Butcher3ea7f522016-03-07 23:22:10 +0000920
Gilles Peskine8f073122018-11-27 15:58:47 +0100921component_test_no_renegotiation () {
922 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200923 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +0100924 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
925 make
Simon Butcher3ea7f522016-03-07 23:22:10 +0000926
Gilles Peskine8f073122018-11-27 15:58:47 +0100927 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
928 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +0100929
Gilles Peskine8f073122018-11-27 15:58:47 +0100930 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
931 if_build_succeeded tests/ssl-opt.sh
932}
Hanno Becker134c2ab2017-10-12 15:29:50 +0100933
Gilles Peskine636c26a2020-03-04 20:46:15 +0100934component_test_no_pem_no_fs () {
935 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
936 scripts/config.py unset MBEDTLS_PEM_PARSE_C
937 scripts/config.py unset MBEDTLS_FS_IO
938 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
939 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
940 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
941 make
942
943 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
944 make test
945
946 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
947 if_build_succeeded tests/ssl-opt.sh
948}
949
Gilles Peskine8f073122018-11-27 15:58:47 +0100950component_test_rsa_no_crt () {
951 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200952 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +0100953 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
954 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +0100955
Gilles Peskine8f073122018-11-27 15:58:47 +0100956 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
957 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100958
Gilles Peskine8f073122018-11-27 15:58:47 +0100959 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
960 if_build_succeeded tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100961
Gilles Peskine8f073122018-11-27 15:58:47 +0100962 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
963 if_build_succeeded tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200964
965 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
966 if_build_succeeded tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100967}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +0100968
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100969component_test_no_ctr_drbg_classic () {
970 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +0200971 scripts/config.py full
972 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100973 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +0200974
975 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
976 make
977
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100978 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +0200979 make test
980
Gilles Peskineba749042021-01-13 20:02:03 +0100981 # In this configuration, the TLS test programs use HMAC_DRBG.
982 # The SSL tests are slow, so run a small subset, just enough to get
983 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100984 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskineba749042021-01-13 20:02:03 +0100985 if_build_succeeded tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
986
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100987 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Gilles Peskineba749042021-01-13 20:02:03 +0100988 if_build_succeeded tests/compat.sh -m tls1_2 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +0200989}
990
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100991component_test_no_ctr_drbg_use_psa () {
992 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +0200993 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +0100994 scripts/config.py unset MBEDTLS_CTR_DRBG_C
995 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +0200996
997 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
998 make
999
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001000 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1001 make test
1002
1003 # In this configuration, the TLS test programs use HMAC_DRBG.
1004 # The SSL tests are slow, so run a small subset, just enough to get
1005 # confidence that the SSL code copes with HMAC_DRBG.
1006 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
1007 if_build_succeeded tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
1008
1009 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
1010 if_build_succeeded tests/compat.sh -m tls1_2 -t 'ECDSA PSK' -V NO -p OpenSSL
1011}
1012
1013component_test_no_hmac_drbg_classic () {
1014 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1015 scripts/config.py full
1016 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1017 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1018 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1019
1020 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1021 make
1022
1023 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001024 make test
1025
Gilles Peskinea2224342020-11-19 22:14:34 +01001026 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1027 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1028 # instead.
1029 # Test SSL with non-deterministic ECDSA. Only test features that
1030 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001031 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinea2224342020-11-19 22:14:34 +01001032 if_build_succeeded tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
1033
1034 # To save time, only test one protocol version, since this part of
1035 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001036 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Gilles Peskinea2224342020-11-19 22:14:34 +01001037 if_build_succeeded tests/compat.sh -m tls1_2 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001038}
1039
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001040component_test_no_hmac_drbg_use_psa () {
1041 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1042 scripts/config.py full
1043 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1044 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1045 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1046
1047 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1048 make
1049
1050 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1051 make test
1052
1053 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1054 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1055 # instead.
1056 # Test SSL with non-deterministic ECDSA. Only test features that
1057 # might be affected by how ECDSA signature is performed.
1058 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
1059 if_build_succeeded tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
1060
1061 # To save time, only test one protocol version, since this part of
1062 # the protocol is identical in (D)TLS up to 1.2.
1063 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
1064 if_build_succeeded tests/compat.sh -m tls1_2 -t 'ECDSA'
1065}
1066
1067component_test_psa_external_rng_no_drbg_classic () {
1068 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1069 scripts/config.py full
1070 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1071 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001072 scripts/config.py unset MBEDTLS_ENTROPY_C
1073 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1074 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001075 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1076 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1077 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1078 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001079 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1080 # the SSL test programs don't have an RNG and can't work. Explicitly
1081 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1082 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001083
1084 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1085 make test
1086
Gilles Peskine8eb29432021-02-03 20:07:11 +01001087 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
1088 if_build_succeeded tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001089}
1090
1091component_test_psa_external_rng_no_drbg_use_psa () {
1092 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001093 scripts/config.py full
1094 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001095 scripts/config.py unset MBEDTLS_ENTROPY_C
1096 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1097 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001098 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1099 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1100 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1101 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1102 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1103
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001104 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001105 make test
1106
Gilles Peskine8eb29432021-02-03 20:07:11 +01001107 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
1108 if_build_succeeded tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001109}
1110
1111component_test_psa_external_rng_use_psa_crypto () {
1112 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1113 scripts/config.py full
1114 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1115 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1116 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1117 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1118
1119 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1120 make test
1121
Gilles Peskineba749042021-01-13 20:02:03 +01001122 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1123 if_build_succeeded tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001124}
1125
Manuel Pégourié-Gonnard1a3f9ed2020-05-19 12:38:31 +02001126component_test_ecp_no_internal_rng () {
1127 msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
1128 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1129 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1130 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1131 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1132 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
1133 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1134
1135 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1136 make
1137
1138 msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
1139 make test
1140
1141 # no SSL tests as they all depend on having a DRBG
1142}
1143
Manuel Pégourié-Gonnard53fb66d2020-06-04 09:43:14 +02001144component_test_ecp_restartable_no_internal_rng () {
1145 msg "build: Default plus ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG"
1146 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1147 scripts/config.py set MBEDTLS_ECP_RESTARTABLE
1148 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1149 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1150 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1151 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
1152 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1153
1154 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1155 make
1156
1157 msg "test: ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG module"
1158 make test
1159
1160 # no SSL tests as they all depend on having a DRBG
1161}
1162
Gilles Peskine636c26a2020-03-04 20:46:15 +01001163component_test_new_ecdh_context () {
1164 msg "build: new ECDH context (ASan build)" # ~ 6 min
1165 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1166 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1167 make
1168
1169 msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1170 make test
1171
1172 msg "test: new ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
1173 if_build_succeeded tests/ssl-opt.sh -f ECDH
1174
1175 msg "test: new ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1176 # Exclude some symmetric ciphers that are redundant here to gain time.
1177 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
1178}
1179
1180component_test_everest () {
1181 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
1182 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1183 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1184 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1185 make
1186
1187 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1188 make test
1189
1190 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
1191 if_build_succeeded tests/ssl-opt.sh -f ECDH
1192
1193 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1194 # Exclude some symmetric ciphers that are redundant here to gain time.
1195 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
1196}
1197
Gilles Peskined3beca92020-07-03 00:15:37 +02001198component_test_everest_curve25519_only () {
1199 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
1200 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1201 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1202 scripts/config.py unset MBEDTLS_ECDSA_C
1203 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1204 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1205 # Disable all curves
1206 for c in $(sed -n 's/#define \(MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED\).*/\1/p' <"$CONFIG_H"); do
1207 scripts/config.py unset "$c"
1208 done
1209 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1210
1211 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1212
1213 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1214 make test
1215}
1216
Gilles Peskine8f073122018-11-27 15:58:47 +01001217component_test_small_ssl_out_content_len () {
1218 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001219 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1220 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001221 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1222 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001223
Gilles Peskine8f073122018-11-27 15:58:47 +01001224 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
1225 if_build_succeeded tests/ssl-opt.sh -f "Max fragment\|Large packet"
1226}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001227
Gilles Peskine8f073122018-11-27 15:58:47 +01001228component_test_small_ssl_in_content_len () {
1229 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001230 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1231 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001232 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1233 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001234
Gilles Peskine8f073122018-11-27 15:58:47 +01001235 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
1236 if_build_succeeded tests/ssl-opt.sh -f "Max fragment"
1237}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001238
Gilles Peskine8f073122018-11-27 15:58:47 +01001239component_test_small_ssl_dtls_max_buffering () {
1240 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001241 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001242 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1243 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001244
Gilles Peskine8f073122018-11-27 15:58:47 +01001245 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
1246 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
1247}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001248
Gilles Peskine8f073122018-11-27 15:58:47 +01001249component_test_small_mbedtls_ssl_dtls_max_buffering () {
1250 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001251 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001252 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1253 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001254
Gilles Peskine8f073122018-11-27 15:58:47 +01001255 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
1256 if_build_succeeded tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
1257}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001258
Gilles Peskine75cc7712019-09-06 19:47:17 +02001259component_test_psa_collect_statuses () {
1260 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001261 scripts/config.py full
Gilles Peskine75cc7712019-09-06 19:47:17 +02001262 record_status tests/scripts/psa_collect_statuses.py
1263 # Check that psa_crypto_init() succeeded at least once
1264 record_status grep -q '^0:psa_crypto_init:' tests/statuses.log
1265 rm -f tests/statuses.log
1266}
1267
Gilles Peskine8f073122018-11-27 15:58:47 +01001268component_test_full_cmake_clang () {
1269 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001270 scripts/config.py full
Gilles Peskine8f073122018-11-27 15:58:47 +01001271 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On .
1272 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001273
k-stachowiak0291cb72019-06-26 15:52:12 +02001274 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001275 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001276
k-stachowiak0291cb72019-06-26 15:52:12 +02001277 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Darryl Green45010a32019-02-06 13:43:58 +00001278 record_status tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001279
Gilles Peskine8f073122018-11-27 15:58:47 +01001280 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
1281 if_build_succeeded tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001282
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +00001283 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Andres Amaya Garcia419bd002019-02-19 20:20:57 +00001284 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001285
Gilles Peskine8f073122018-11-27 15:58:47 +01001286 msg "test: compat.sh ARIA + ChachaPoly"
1287 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
1288}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001289
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001290component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001291 # This tests both (1) accesses to undefined memory, and (2) branches or
1292 # memory access depending on secret values. To distinguish between those:
1293 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1294 # - or alternatively, change the build type to MemSanDbg, which enables
1295 # origin tracking and nicer stack traces (which are useful for debugging
1296 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1297 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001298 scripts/config.py full
1299 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1300 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1301 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1302 make
1303
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001304 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001305 make test
1306}
1307
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001308component_test_valgrind_constant_flow () {
1309 # This tests both (1) everything that valgrind's memcheck usually checks
1310 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1311 # etc.) and (2) branches or memory access depending on secret values,
1312 # which will be reported as uninitialized memory. To distinguish between
1313 # secret and actually uninitialized:
1314 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1315 # - or alternatively, build with debug info and manually run the offending
1316 # test suite with valgrind --track-origins=yes, then check if the origin
1317 # was TEST_CF_SECRET() or something else.
1318 msg "build: cmake release GCC, full config with constant flow testing"
1319 scripts/config.py full
1320 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
1321 cmake -D CMAKE_BUILD_TYPE:String=Release .
1322 make
1323
1324 # this only shows a summary of the results (how many of each type)
1325 # details are left in Testing/<date>/DynamicAnalysis.xml
1326 msg "test: main suites (valgrind + constant flow)"
1327 make memcheck
1328}
1329
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001330component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02001331 # Test that removing the deprecated features from the default
1332 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001333 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1334 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1335 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1336
1337 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1338 make test
1339}
1340
1341component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02001342 msg "build: make, full_no_deprecated config" # ~ 30s
1343 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001344 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1345
Gilles Peskine30de2e82020-04-20 21:39:22 +02001346 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001347 make test
1348}
1349
Gilles Peskine8386ea22020-04-30 09:07:29 +02001350component_test_full_no_deprecated_deprecated_warning () {
1351 # Test that there is nothing deprecated in "full_no_deprecated".
1352 # A deprecated feature would trigger a warning (made fatal) from
1353 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02001354 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1355 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001356 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
1357 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
1358 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1359
Gilles Peskine30de2e82020-04-20 21:39:22 +02001360 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001361 make test
1362}
1363
Gilles Peskine8386ea22020-04-30 09:07:29 +02001364component_test_full_deprecated_warning () {
1365 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
1366 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001367 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001368 scripts/config.py full
1369 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001370 # Expect warnings from '#warning' directives in check_config.h.
1371 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001372
Gilles Peskine8386ea22020-04-30 09:07:29 +02001373 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1374 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
1375 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001376 # Expect warnings from '#warning' directives in check_config.h and
1377 # from the use of deprecated functions in test suites.
1378 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 +01001379
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001380 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
1381 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001382}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00001383
Gilles Peskineec541fe2020-01-31 14:24:14 +01001384# Check that the specified libraries exist and are empty.
1385are_empty_libraries () {
1386 nm "$@" >/dev/null 2>/dev/null
1387 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
1388}
1389
1390component_build_crypto_default () {
1391 msg "build: make, crypto only"
1392 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01001393 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +01001394 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1395}
1396
1397component_build_crypto_full () {
1398 msg "build: make, crypto only, full config"
1399 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01001400 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +01001401 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1402}
1403
1404component_build_crypto_baremetal () {
1405 msg "build: make, crypto only, baremetal config"
1406 scripts/config.py crypto_baremetal
Gilles Peskine6bb39152020-02-03 11:59:20 +01001407 make CFLAGS='-O1 -Werror'
Gilles Peskineec541fe2020-01-31 14:24:14 +01001408 if_build_succeeded are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1409}
1410
Gilles Peskine8f073122018-11-27 15:58:47 +01001411component_test_depends_curves () {
1412 msg "test/build: curves.pl (gcc)" # ~ 4 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001413 record_status tests/scripts/curves.pl
1414}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001415
John Durkopc14be902020-08-20 06:16:41 -07001416component_test_depends_curves_psa () {
1417 msg "test/build: curves.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
1418 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1419 record_status tests/scripts/curves.pl
1420}
1421
Gilles Peskine8f073122018-11-27 15:58:47 +01001422component_test_depends_hashes () {
1423 msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001424 record_status tests/scripts/depends-hashes.pl
1425}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001426
John Durkop2ec2eaa2020-08-24 18:29:15 -07001427component_test_depends_hashes_psa () {
1428 msg "test/build: depends-hashes.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
1429 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1430 record_status tests/scripts/depends-hashes.pl
1431}
1432
Gilles Peskine8f073122018-11-27 15:58:47 +01001433component_test_depends_pkalgs () {
1434 msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001435 record_status tests/scripts/depends-pkalgs.pl
1436}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001437
John Durkop619e09e2020-09-08 22:19:56 -07001438component_test_depends_pkalgs_psa () {
1439 msg "test/build: depends-pkalgs.pl with MBEDTLS_USE_PSA_CRYPTO defined (gcc)"
1440 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001441 record_status tests/scripts/depends-pkalgs.pl
1442}
1443
Gilles Peskine8f073122018-11-27 15:58:47 +01001444component_build_key_exchanges () {
1445 msg "test/build: key-exchanges (gcc)" # ~ 1 min
Gilles Peskine8f073122018-11-27 15:58:47 +01001446 record_status tests/scripts/key-exchanges.pl
1447}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001448
Gilles Peskine8f073122018-11-27 15:58:47 +01001449component_build_default_make_gcc_and_cxx () {
1450 msg "build: Unix make, -Os (gcc)" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01001451 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001452
Gilles Peskine8f073122018-11-27 15:58:47 +01001453 msg "test: verify header list in cpp_dummy_build.cpp"
1454 record_status check_headers_in_cpp
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001455
Gilles Peskine8f073122018-11-27 15:58:47 +01001456 msg "build: Unix make, incremental g++"
1457 make TEST_CPP=1
1458}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001459
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001460component_test_no_use_psa_crypto_full_cmake_asan() {
1461 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02001462 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001463 scripts/config.py full
1464 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
1465 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1466 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1467 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02001468 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001469 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01001470 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001471 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001472
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001473 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001474 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001475
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001476 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001477 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001478
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001479 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001480 if_build_succeeded tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001481
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001482 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001483 if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '3DES\|DES-CBC3' -f 'NULL\|DES\|RC4\|ARCFOUR'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001484
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001485 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001486 if_build_succeeded env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
1487}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001488
John Durkopd8959392020-09-20 23:09:17 -07001489component_test_psa_crypto_config_basic() {
Ronald Cron067de3b2021-03-11 11:49:03 +01001490 # Test the library excluding all Mbed TLS cryptographic support for which
1491 # we have an accelerator support. Acceleration is faked with the
1492 # transparent test driver.
1493 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG + as much acceleration as supported"
John Durkopd8959392020-09-20 23:09:17 -07001494 scripts/config.py full
1495 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1496 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1497 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cron067de3b2021-03-11 11:49:03 +01001498
1499 # There is no intended accelerator support for ALG STREAM_CIPHER and
1500 # ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
1501 # inclusion of the Mbed TLS cipher operations. As we want to test here with
1502 # cipher operations solely supported by accelerators, disabled those
1503 # PSA configuration options.
1504 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1505 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1506
1507 # Don't test DES encryption as:
1508 # 1) It is not an issue if we don't test all cipher types here.
1509 # 2) That way we don't have to modify in psa_crypto.c the compilation
1510 # guards MBEDTLS_PSA_BUILTIN_KEY_TYPE_DES for the code they guard to be
1511 # available to the test driver. Modifications that we would need to
1512 # revert when we move to compile the test driver separately.
1513 # We also disable MBEDTLS_DES_C as the dependencies on DES in PSA test
1514 # suites are still based on MBEDTLS_DES_C and not PSA_WANT_KEY_TYPE_DES.
1515 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_DES
1516 scripts/config.py unset MBEDTLS_DES_C
1517
John Durkopd8959392020-09-20 23:09:17 -07001518 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
Ronald Cron17b3afc2020-12-10 18:17:09 +01001519 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST"
Ronald Cron067de3b2021-03-11 11:49:03 +01001520 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_AES"
1521 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA"
Ronald Cron17b3afc2020-12-10 18:17:09 +01001522 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR"
Ronald Cron067de3b2021-03-11 11:49:03 +01001523 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR"
1524 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING"
1525 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7"
1526 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CTR"
1527 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CFB"
Ronald Cron17b3afc2020-12-10 18:17:09 +01001528 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_ECDSA"
1529 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA"
Steven Cooremand50db942021-03-08 17:17:15 +01001530 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_MD2"
1531 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_MD4"
1532 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_MD5"
Ronald Cron067de3b2021-03-11 11:49:03 +01001533 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_OFB"
Steven Cooremand50db942021-03-08 17:17:15 +01001534 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160"
Ronald Cron067de3b2021-03-11 11:49:03 +01001535 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN"
1536 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS"
Steven Cooremand50db942021-03-08 17:17:15 +01001537 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_1"
1538 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_224"
1539 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_256"
1540 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_384"
1541 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_512"
Ronald Cron067de3b2021-03-11 11:49:03 +01001542 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_XTS"
Steven Cooreman6f32bca2021-03-19 19:36:38 +01001543 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CMAC"
1544 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_HMAC"
Ronald Cron17b3afc2020-12-10 18:17:09 +01001545 loc_cflags="${loc_cflags} -I../tests/include -O2"
1546
1547 make CC=gcc CFLAGS="$loc_cflags" LDFLAGS="$ASAN_CFLAGS"
1548 unset loc_cflags
John Durkopd8959392020-09-20 23:09:17 -07001549
John Durkop4377bf72020-10-23 01:26:57 -07001550 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG"
1551 make test
1552}
1553
1554component_test_psa_crypto_config_no_driver() {
1555 # full plus MBEDTLS_PSA_CRYPTO_CONFIG
1556 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
1557 scripts/config.py full
1558 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1559 scripts/config.py unset MBEDTLS_PSA_CRYPTO_DRIVERS
1560 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkope7012c72020-10-26 09:55:01 -07001561 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop4377bf72020-10-23 01:26:57 -07001562
1563 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
John Durkopd8959392020-09-20 23:09:17 -07001564 make test
1565}
1566
John Durkop8ac0b802020-10-23 01:32:15 -07001567# This should be renamed to test and updated once the accelerator ECDSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08001568component_build_psa_accel_alg_ecdsa() {
John Durkopdd544e12020-10-12 21:47:19 -07001569 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_ECDSA
1570 # without MBEDTLS_ECDSA_C
John Durkop28baa1f2020-10-23 00:51:52 -07001571 # PSA_WANT_ALG_ECDSA and PSA_WANT_ALG_DETERMINISTIC_ECDSA are already
1572 # set in include/psa/crypto_config.h
John Durkopdd544e12020-10-12 21:47:19 -07001573 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_ECDSA without MBEDTLS_ECDSA_C"
John Durkopd8959392020-09-20 23:09:17 -07001574 scripts/config.py full
1575 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1576 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1577 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1578 scripts/config.py unset MBEDTLS_ECDSA_C
John Durkop28baa1f2020-10-23 00:51:52 -07001579 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1580 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
John Durkopd8959392020-09-20 23:09:17 -07001581 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
John Durkop28baa1f2020-10-23 00:51:52 -07001582 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDSA -DMBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkopd8959392020-09-20 23:09:17 -07001583}
1584
John Durkopd0321952020-10-29 21:37:36 -07001585# 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 -08001586component_build_psa_accel_alg_ecdh() {
John Durkopd0321952020-10-29 21:37:36 -07001587 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_ECDH
1588 # without MBEDTLS_ECDH_C
1589 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
1590 scripts/config.py full
1591 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1592 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1593 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1594 scripts/config.py unset MBEDTLS_ECDH_C
1595 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1596 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1597 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1598 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1599 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1600 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1601 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1602}
1603
John Durkopf4c4cb02020-10-28 20:09:55 -07001604# 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 -08001605component_build_psa_accel_key_type_ecc_key_pair() {
John Durkop9814fa22020-11-04 12:28:15 -08001606 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
1607 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR"
John Durkopf4c4cb02020-10-28 20:09:55 -07001608 scripts/config.py full
1609 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1610 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1611 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08001612 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 -08001613 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 -07001614 # 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 -08001615 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 -07001616}
1617
1618# 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 -08001619component_build_psa_accel_key_type_ecc_public_key() {
John Durkop9814fa22020-11-04 12:28:15 -08001620 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY
1621 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
John Durkopf4c4cb02020-10-28 20:09:55 -07001622 scripts/config.py full
1623 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1624 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1625 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08001626 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
1627 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
John Durkopf4c4cb02020-10-28 20:09:55 -07001628 # 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 -08001629 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 -07001630}
1631
John Durkopd0321952020-10-29 21:37:36 -07001632# 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 -08001633component_build_psa_accel_alg_hmac() {
John Durkopd0321952020-10-29 21:37:36 -07001634 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HMAC
1635 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HMAC"
1636 scripts/config.py full
1637 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1638 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1639 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1640 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1641 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1642}
1643
1644# 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 -08001645component_build_psa_accel_alg_hkdf() {
John Durkopd0321952020-10-29 21:37:36 -07001646 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HKDF
1647 # without MBEDTLS_HKDF_C
1648 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
1649 scripts/config.py full
1650 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1651 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1652 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1653 scripts/config.py unset MBEDTLS_HKDF_C
John Durkopbd069d32020-10-31 22:14:03 -07001654 # Make sure to unset TLS1_3_EXPERIMENTAL since it requires HKDF_C and will not build properly without it.
1655 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
John Durkopd0321952020-10-29 21:37:36 -07001656 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1657 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1658}
1659
John Durkop1b7ee052020-11-27 08:51:22 -08001660# This should be renamed to test and updated once the accelerator MD2 code is in place and ready to test.
1661component_build_psa_accel_alg_md2() {
1662 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD2 without other hashes
1663 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD2 - other hashes"
1664 scripts/config.py full
1665 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1666 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1667 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1668 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1669 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1670 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1671 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1672 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1673 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1674 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1675 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1676 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1677 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD2 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1678}
1679
1680# This should be renamed to test and updated once the accelerator MD4 code is in place and ready to test.
1681component_build_psa_accel_alg_md4() {
1682 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD4 without other hashes
1683 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD4 - other hashes"
1684 scripts/config.py full
1685 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1686 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1687 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1688 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1689 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1690 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1691 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1692 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1693 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1694 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1695 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1696 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1697 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD4 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1698}
1699
1700# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
1701component_build_psa_accel_alg_md5() {
1702 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD5 without other hashes
1703 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD5 - other hashes"
1704 scripts/config.py full
1705 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1706 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1707 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1708 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1709 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1710 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1711 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1712 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1713 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1714 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1715 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1716 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1717 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1718}
1719
1720# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
1721component_build_psa_accel_alg_ripemd160() {
1722 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RIPEMD160 without other hashes
1723 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RIPEMD160 - other hashes"
1724 scripts/config.py full
1725 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1726 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1727 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1728 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1729 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1730 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1731 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1732 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1733 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1734 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1735 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1736 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1737 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1738}
1739
1740# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
1741component_build_psa_accel_alg_sha1() {
1742 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_1 without other hashes
1743 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_1 - other hashes"
1744 scripts/config.py full
1745 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1746 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1747 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1748 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1749 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1750 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1751 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1752 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1753 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1754 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1755 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1756 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1757 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1758}
1759
1760# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
1761component_build_psa_accel_alg_sha224() {
1762 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_224 without other hashes
1763 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_224 - other hashes"
1764 scripts/config.py full
1765 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1766 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1767 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1768 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1769 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1770 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1771 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1772 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1773 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1774 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1775 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1776 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1777}
1778
1779# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
1780component_build_psa_accel_alg_sha256() {
1781 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_256 without other hashes
1782 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_256 - other hashes"
1783 scripts/config.py full
1784 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1785 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1786 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1787 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1788 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1789 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1790 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1791 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1792 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1793 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1794 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
1795 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1796 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1797}
1798
1799# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
1800component_build_psa_accel_alg_sha384() {
1801 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_384 without other hashes
1802 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_384 - other hashes"
1803 scripts/config.py full
1804 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1805 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1806 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1807 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1808 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1809 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1810 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1811 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1812 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1813 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1814 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1815 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1816}
1817
1818# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
1819component_build_psa_accel_alg_sha512() {
1820 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_512 without other hashes
1821 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_512 - other hashes"
1822 scripts/config.py full
1823 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1824 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1825 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1826 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1827 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1828 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1829 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
1830 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
1831 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
1832 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
1833 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
1834 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1835 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1836}
1837
John Durkopd0321952020-10-29 21:37:36 -07001838# 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 -08001839component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
John Durkopbd069d32020-10-31 22:14:03 -07001840 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1841 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
John Durkopd0321952020-10-29 21:37:36 -07001842 scripts/config.py full
1843 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1844 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1845 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkopbd069d32020-10-31 22:14:03 -07001846 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001847 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1848 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1849 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07001850 # 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 -07001851 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1852}
1853
1854# 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 -08001855component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
John Durkopbd069d32020-10-31 22:14:03 -07001856 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_SIGN and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
1857 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1858 scripts/config.py full
1859 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1860 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1861 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1862 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001863 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1864 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1865 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07001866 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1867 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1868}
1869
1870# 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 -08001871component_build_psa_accel_alg_rsa_oaep() {
John Durkopbd069d32020-10-31 22:14:03 -07001872 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_OAEP and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
1873 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1874 scripts/config.py full
1875 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1876 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1877 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1878 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_OAEP 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001879 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1880 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1881 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07001882 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1883 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1884}
1885
1886# 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 -08001887component_build_psa_accel_alg_rsa_pss() {
John Durkopbd069d32020-10-31 22:14:03 -07001888 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PSS and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
1889 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
1890 scripts/config.py full
1891 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1892 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1893 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1894 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
John Durkop7fc75ea2020-11-03 19:05:36 -08001895 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1896 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
1897 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07001898 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1899 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
1900}
1901
1902# 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 -08001903component_build_psa_accel_key_type_rsa_key_pair() {
John Durkopbd069d32020-10-31 22:14:03 -07001904 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_KEY_PAIR and PSA_WANT_ALG_RSA_PSS
1905 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR + PSA_WANT_ALG_RSA_PSS"
1906 scripts/config.py full
1907 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1908 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1909 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1910 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
1911 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
1912 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1913 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"
1914}
1915
1916# 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 -08001917component_build_psa_accel_key_type_rsa_public_key() {
John Durkopbd069d32020-10-31 22:14:03 -07001918 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY and PSA_WANT_ALG_RSA_PSS
1919 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
1920 scripts/config.py full
1921 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1922 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1923 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1924 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
1925 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
1926 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
1927 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 -07001928}
1929
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001930component_test_check_params_functionality () {
1931 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001932 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001933 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001934 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Ronald Crona1236142020-07-01 16:01:21 +02001935 make CC=gcc CFLAGS='-Werror -O1' all test
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001936}
1937
Gilles Peskineb28636b2019-01-02 19:06:24 +01001938component_test_check_params_without_platform () {
1939 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001940 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001941 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001942 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
1943 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
1944 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
1945 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
Gilles Peskine32e889d2020-04-12 23:43:28 +02001946 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001947 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
1948 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1949 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1950 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +01001951 make CC=gcc CFLAGS='-Werror -O1' all test
1952}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001953
Gilles Peskineb28636b2019-01-02 19:06:24 +01001954component_test_check_params_silent () {
1955 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001956 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02001957 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01001958 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
1959 make CC=gcc CFLAGS='-Werror -O1' all test
1960}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001961
Gilles Peskine8f073122018-11-27 15:58:47 +01001962component_test_no_platform () {
1963 # Full configuration build, without platform support, file IO and net sockets.
1964 # This should catch missing mbedtls_printf definitions, and by disabling file
1965 # IO, it should catch missing '#include <stdio.h>'
1966 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001967 scripts/config.py full
1968 scripts/config.py unset MBEDTLS_PLATFORM_C
1969 scripts/config.py unset MBEDTLS_NET_C
1970 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
1971 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
1972 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
1973 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
1974 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
1975 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskine32e889d2020-04-12 23:43:28 +02001976 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001977 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1978 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001979 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001980 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1981 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01001982 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
1983 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001984 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
1985 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01001986}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00001987
Gilles Peskine8f073122018-11-27 15:58:47 +01001988component_build_no_std_function () {
1989 # catch compile bugs in _uninit functions
1990 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001991 scripts/config.py full
1992 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
1993 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02001994 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02001995 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os'
Gilles Peskine8f073122018-11-27 15:58:47 +01001996}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01001997
Gilles Peskine8f073122018-11-27 15:58:47 +01001998component_build_no_ssl_srv () {
1999 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002000 scripts/config.py full
2001 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002002 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002003}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002004
Gilles Peskine8f073122018-11-27 15:58:47 +01002005component_build_no_ssl_cli () {
2006 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002007 scripts/config.py full
2008 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002009 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002010}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002011
Gilles Peskine8f073122018-11-27 15:58:47 +01002012component_build_no_sockets () {
2013 # Note, C99 compliance can also be tested with the sockets support disabled,
2014 # as that requires a POSIX platform (which isn't the same as C99).
2015 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002016 scripts/config.py full
2017 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
2018 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002019 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01002020}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02002021
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002022component_test_memory_buffer_allocator_backtrace () {
2023 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002024 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2025 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2026 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
2027 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002028 CC=gcc cmake .
2029 make
2030
2031 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
2032 make test
2033}
2034
2035component_test_memory_buffer_allocator () {
2036 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002037 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2038 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002039 CC=gcc cmake .
2040 make
2041
2042 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2043 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002044
2045 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2046 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
2047 if_build_succeeded tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002048}
2049
Gilles Peskine8f073122018-11-27 15:58:47 +01002050component_test_no_max_fragment_length () {
2051 # Run max fragment length tests with MFL disabled
2052 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002053 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01002054 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2055 make
Hanno Becker5175ac62017-09-18 15:36:25 +01002056
Gilles Peskine8f073122018-11-27 15:58:47 +01002057 msg "test: ssl-opt.sh, MFL-related tests"
2058 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
2059}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002060
Hanno Becker545ced42019-02-19 11:10:48 +00002061component_test_asan_remove_peer_certificate () {
2062 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002063 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00002064 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2065 make
2066
2067 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2068 make test
2069
2070 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2071 if_build_succeeded tests/ssl-opt.sh
2072
2073 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2074 if_build_succeeded tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002075
2076 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2077 if_build_succeeded tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002078}
2079
Gilles Peskine8f073122018-11-27 15:58:47 +01002080component_test_no_max_fragment_length_small_ssl_out_content_len () {
2081 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002082 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2083 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
2084 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01002085 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2086 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10002087
Gilles Peskine8f073122018-11-27 15:58:47 +01002088 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
2089 if_build_succeeded tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002090
2091 msg "test: context-info.sh (disabled MFL extension case)"
2092 if_build_succeeded tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002093}
Angus Grattonc4dd0732018-04-11 16:28:39 +10002094
Darryl Greenaad82f92019-12-02 10:53:11 +00002095component_test_variable_ssl_in_out_buffer_len () {
2096 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
2097 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2098 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2099 make
2100
2101 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2102 make test
2103
2104 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2105 if_build_succeeded tests/ssl-opt.sh
2106
2107 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2108 if_build_succeeded tests/compat.sh
2109}
2110
2111component_test_variable_ssl_in_out_buffer_len_CID () {
2112 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
2113 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2114 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
2115
2116 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2117 make
2118
2119 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
2120 make test
2121
2122 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
2123 if_build_succeeded tests/ssl-opt.sh
2124
2125 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
2126 if_build_succeeded tests/compat.sh
2127}
2128
2129component_test_variable_ssl_in_out_buffer_len_record_splitting () {
2130 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled (ASan build)"
2131 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2132 scripts/config.py set MBEDTLS_SSL_CBC_RECORD_SPLITTING
2133
2134 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2135 make
2136
2137 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING"
2138 make test
2139
2140 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
2141 if_build_succeeded tests/ssl-opt.sh
2142
2143 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
2144 if_build_succeeded tests/compat.sh
2145}
2146
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002147component_test_ssl_alloc_buffer_and_mfl () {
2148 msg "build: default config with memory buffer allocator and MFL extension"
2149 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2150 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2151 scripts/config.py set MBEDTLS_MEMORY_DEBUG
2152 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2153 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2154 CC=gcc cmake .
2155 make
2156
2157 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
2158 make test
2159
2160 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
2161 if_build_succeeded tests/ssl-opt.sh -f "Handshake memory usage"
2162}
2163
Gilles Peskine636c26a2020-03-04 20:46:15 +01002164component_test_when_no_ciphersuites_have_mac () {
2165 msg "build: when no ciphersuites have MAC"
2166 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
2167 scripts/config.py unset MBEDTLS_ARC4_C
2168 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2169 make
2170
2171 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
2172 make test
2173
2174 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
2175 if_build_succeeded tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
2176}
2177
Gilles Peskine8f073122018-11-27 15:58:47 +01002178component_test_null_entropy () {
2179 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002180 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
2181 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
2182 scripts/config.py set MBEDTLS_ENTROPY_C
2183 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002184 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002185 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
2186 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00002187 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01002188 make
Janos Follath06c54002016-06-09 13:57:40 +01002189
Gilles Peskine8f073122018-11-27 15:58:47 +01002190 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
2191 make test
2192}
Janos Follath06c54002016-06-09 13:57:40 +01002193
Raoul Strackxa4e86142020-06-15 17:03:13 +02002194component_test_no_date_time () {
2195 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
2196 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
2197 CC=gcc cmake
2198 make
2199
2200 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
2201 make test
2202}
2203
Gilles Peskine8f073122018-11-27 15:58:47 +01002204component_test_platform_calloc_macro () {
2205 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002206 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2207 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
2208 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01002209 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2210 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01002211
Gilles Peskine8f073122018-11-27 15:58:47 +01002212 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
2213 make test
2214}
Hanno Beckere5fecec2018-10-11 11:02:52 +01002215
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002216component_test_malloc_0_null () {
2217 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002218 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +02002219 make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' $ASAN_CFLAGS -O" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002220
2221 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
2222 make test
2223
2224 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
2225 # Just the calloc selftest. "make test" ran the others as part of the
2226 # test suites.
2227 if_build_succeeded programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01002228
2229 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
2230 # Run a subset of the tests. The choice is a balance between coverage
2231 # and time (including time indirectly wasted due to flaky tests).
2232 # The current choice is to skip tests whose description includes
2233 # "proxy", which is an approximation of skipping tests that use the
2234 # UDP proxy, which tend to be slower and flakier.
2235 if_build_succeeded tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002236}
2237
Gilles Peskine8f073122018-11-27 15:58:47 +01002238component_test_aes_fewer_tables () {
2239 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002240 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002241 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002242
Gilles Peskine8f073122018-11-27 15:58:47 +01002243 msg "test: AES_FEWER_TABLES"
2244 make test
2245}
Hanno Becker83ebf782017-07-07 12:29:15 +01002246
Gilles Peskine8f073122018-11-27 15:58:47 +01002247component_test_aes_rom_tables () {
2248 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002249 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002250 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002251
Gilles Peskine8f073122018-11-27 15:58:47 +01002252 msg "test: AES_ROM_TABLES"
2253 make test
2254}
Hanno Becker83ebf782017-07-07 12:29:15 +01002255
Gilles Peskine8f073122018-11-27 15:58:47 +01002256component_test_aes_fewer_tables_and_rom_tables () {
2257 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002258 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2259 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002260 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002261
Gilles Peskine8f073122018-11-27 15:58:47 +01002262 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2263 make test
2264}
2265
Gilles Peskine592f5912019-10-07 18:49:32 +02002266component_test_ctr_drbg_aes_256_sha_256 () {
2267 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002268 scripts/config.py full
2269 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2270 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002271 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2272 make
2273
2274 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2275 make test
2276}
2277
2278component_test_ctr_drbg_aes_128_sha_512 () {
2279 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002280 scripts/config.py full
2281 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2282 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02002283 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2284 make
2285
2286 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2287 make test
2288}
2289
2290component_test_ctr_drbg_aes_128_sha_256 () {
2291 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002292 scripts/config.py full
2293 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2294 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2295 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002296 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2297 make
2298
2299 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2300 make test
2301}
2302
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002303component_test_se_default () {
2304 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002305 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02002306 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002307
2308 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2309 make test
2310}
2311
Steven Cooremand57203d2020-07-16 20:28:59 +02002312component_test_psa_crypto_drivers () {
Steven Cooreman55ae2172020-07-17 19:46:15 +02002313 msg "build: MBEDTLS_PSA_CRYPTO_DRIVERS w/ driver hooks"
Steven Cooreman753f9732021-03-15 11:38:44 +01002314 scripts/config.py full
Steven Cooremand57203d2020-07-16 20:28:59 +02002315 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
Steven Cooreman6801f082021-02-19 17:21:22 +01002316 scripts/config.py set MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
Steven Cooreman1cd39d52020-07-23 16:26:08 +02002317 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
Ronald Cron17b3afc2020-12-10 18:17:09 +01002318 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST"
Ronald Crone6f63012021-03-19 14:57:08 +01002319 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_AES"
2320 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_CAMELLIA"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002321 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR"
Ronald Crone6f63012021-03-19 14:57:08 +01002322 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR"
2323 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CBC_NO_PADDING"
2324 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CBC_PKCS7"
2325 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CTR"
2326 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CFB"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002327 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_ECDSA"
2328 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_DETERMINISTIC_ECDSA"
Steven Cooremand50db942021-03-08 17:17:15 +01002329 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_MD2"
2330 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_MD4"
2331 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_MD5"
Ronald Crone6f63012021-03-19 14:57:08 +01002332 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_OFB"
Steven Cooremand50db942021-03-08 17:17:15 +01002333 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160"
Ronald Crone6f63012021-03-19 14:57:08 +01002334 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN"
2335 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS"
Steven Cooremand50db942021-03-08 17:17:15 +01002336 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_1"
2337 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_224"
2338 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_256"
2339 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_384"
2340 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_SHA_512"
Ronald Crone6f63012021-03-19 14:57:08 +01002341 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_XTS"
Steven Cooreman6f32bca2021-03-19 19:36:38 +01002342 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_CMAC"
2343 loc_cflags="${loc_cflags} -DMBEDTLS_PSA_ACCEL_ALG_HMAC"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002344 loc_cflags="${loc_cflags} -I../tests/include -O2"
2345
2346 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
2347 unset loc_cflags
Steven Cooremand57203d2020-07-16 20:28:59 +02002348
Steven Cooreman753f9732021-03-15 11:38:44 +01002349 msg "test: full + MBEDTLS_PSA_CRYPTO_DRIVERS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002350 make test
2351}
2352
Gilles Peskine8f073122018-11-27 15:58:47 +01002353component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002354 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002355 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02002356 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine8f073122018-11-27 15:58:47 +01002357}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02002358
Gilles Peskinecf740502019-07-03 20:43:05 +02002359component_test_cmake_shared () {
2360 msg "build/test: cmake shared" # ~ 2min
2361 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
2362 make
Gilles Peskine56c01612019-07-03 20:43:32 +02002363 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02002364 make test
2365}
2366
Gilles Peskineec10bf12019-09-20 19:56:06 +02002367test_build_opt () {
2368 info=$1 cc=$2; shift 2
2369 for opt in "$@"; do
2370 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskinee094a182020-04-14 20:08:41 +02002371 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02002372 # We're confident enough in compilers to not run _all_ the tests,
2373 # but at least run the unit tests. In particular, runs with
2374 # optimizations use inline assembly whereas runs with -O0
2375 # skip inline assembly.
2376 make test # ~30s
2377 make clean
2378 done
2379}
2380
2381component_test_clang_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002382 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02002383 test_build_opt 'full config' clang -O0 -Os -O2
2384}
2385
2386component_test_gcc_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002387 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02002388 test_build_opt 'full config' gcc -O0 -Os -O2
2389}
2390
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02002391component_build_mbedtls_config_file () {
2392 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
2393 # Use the full config so as to catch a maximum of places where
2394 # the check of MBEDTLS_CONFIG_FILE might be missing.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002395 scripts/config.py full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02002396 sed 's!"check_config.h"!"mbedtls/check_config.h"!' <"$CONFIG_H" >full_config.h
2397 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
2398 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
2399 rm -f full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002400}
2401
Gilles Peskine8f073122018-11-27 15:58:47 +01002402component_test_m32_o0 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002403 # Build once with -O0, to compile out the i386 specific inline assembly
2404 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002405 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02002406 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01002407
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002408 msg "test: i386, make, gcc -O0 (ASan build)"
2409 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01002410}
Gilles Peskine878cf602019-01-06 20:50:38 +00002411support_test_m32_o0 () {
2412 case $(uname -m) in
2413 *64*) true;;
2414 *) false;;
2415 esac
2416}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002417
Gilles Peskine8f073122018-11-27 15:58:47 +01002418component_test_m32_o1 () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002419 # Build again with -O1, to compile in the i386 specific inline assembly
2420 msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002421 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02002422 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O1" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002423
2424 msg "test: i386, make, gcc -O1 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002425 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002426
2427 msg "test ssl-opt.sh, i386, make, gcc-O1"
2428 if_build_succeeded tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002429}
Gilles Peskine878cf602019-01-06 20:50:38 +00002430support_test_m32_o1 () {
2431 support_test_m32_o0 "$@"
2432}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002433
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002434component_test_m32_everest () {
2435 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002436 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
2437 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02002438 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002439
2440 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
2441 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002442
2443 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
2444 if_build_succeeded tests/ssl-opt.sh -f ECDH
2445
2446 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
2447 # Exclude some symmetric ciphers that are redundant here to gain time.
2448 if_build_succeeded tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002449}
2450support_test_m32_everest () {
2451 support_test_m32_o0 "$@"
2452}
2453
Gilles Peskine8f073122018-11-27 15:58:47 +01002454component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002455 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002456 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02002457 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002458
2459 msg "test: 64-bit ILP32, make, gcc"
2460 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01002461}
Gilles Peskine878cf602019-01-06 20:50:38 +00002462support_test_mx32 () {
2463 case $(uname -m) in
2464 amd64|x86_64) true;;
2465 *) false;;
2466 esac
2467}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002468
Peter Kolbus60c6da22018-12-27 06:59:04 -06002469component_test_min_mpi_window_size () {
2470 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002471 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06002472 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2473 make
2474
2475 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2476 make test
2477}
2478
Gilles Peskine8f073122018-11-27 15:58:47 +01002479component_test_have_int32 () {
2480 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002481 scripts/config.py unset MBEDTLS_HAVE_ASM
2482 scripts/config.py unset MBEDTLS_AESNI_C
2483 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01002484 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01002485
Gilles Peskine8f073122018-11-27 15:58:47 +01002486 msg "test: gcc, force 32-bit bignum limbs"
2487 make test
2488}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01002489
Gilles Peskine8f073122018-11-27 15:58:47 +01002490component_test_have_int64 () {
2491 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002492 scripts/config.py unset MBEDTLS_HAVE_ASM
2493 scripts/config.py unset MBEDTLS_AESNI_C
2494 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01002495 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01002496
Gilles Peskine8f073122018-11-27 15:58:47 +01002497 msg "test: gcc, force 64-bit bignum limbs"
2498 make test
2499}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002500
Gilles Peskine8f073122018-11-27 15:58:47 +01002501component_test_no_udbl_division () {
2502 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002503 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002504 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01002505 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002506
Gilles Peskine8f073122018-11-27 15:58:47 +01002507 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
2508 make test
2509}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002510
Gilles Peskine8f073122018-11-27 15:58:47 +01002511component_test_no_64bit_multiplication () {
2512 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002513 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002514 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01002515 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002516
Gilles Peskine8f073122018-11-27 15:58:47 +01002517 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
2518 make test
2519}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002520
Gilles Peskine3809f5f2020-11-09 15:40:05 +01002521component_test_no_strings () {
2522 msg "build: no strings" # ~10s
2523 scripts/config.py full
2524 # Disable options that activate a large amount of string constants.
2525 scripts/config.py unset MBEDTLS_DEBUG_C
2526 scripts/config.py unset MBEDTLS_ERROR_C
2527 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
2528 scripts/config.py unset MBEDTLS_VERSION_FEATURES
2529 make CFLAGS='-Werror -Os'
2530
2531 msg "test: no strings" # ~ 10s
2532 make test
2533}
2534
Gilles Peskine8f073122018-11-27 15:58:47 +01002535component_build_arm_none_eabi_gcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02002536 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002537 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02002538 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 +02002539
2540 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1"
2541 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01002542}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002543
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02002544component_build_arm_linux_gnueabi_gcc_arm5vte () {
2545 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002546 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02002547 # Build for a target platform that's close to what Debian uses
2548 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
2549 # See https://github.com/ARMmbed/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02002550 # Build everything including programs, see for example
2551 # https://github.com/ARMmbed/mbedtls/pull/3449#issuecomment-675313720
2552 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'
2553
2554 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1"
2555 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size library/*.o
2556}
2557support_build_arm_linux_gnueabi_gcc_arm5vte () {
2558 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
2559}
2560
2561component_build_arm_none_eabi_gcc_arm5vte () {
2562 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte" # ~ 10s
2563 scripts/config.py baremetal
2564 # This is an imperfect substitute for
2565 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnard9a260a62021-07-06 09:44:59 +02002566 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02002567 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 +02002568
2569 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1"
2570 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02002571}
2572
Gilles Peskine6e2fb862020-04-30 23:00:53 +02002573component_build_arm_none_eabi_gcc_m0plus () {
2574 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus" # ~ 10s
2575 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02002576 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 +02002577
2578 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os"
2579 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine6e2fb862020-04-30 23:00:53 +02002580}
2581
Gilles Peskine8f073122018-11-27 15:58:47 +01002582component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02002583 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002584 scripts/config.py baremetal
2585 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02002586 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 +01002587 echo "Checking that software 64-bit division is not required"
2588 if_build_succeeded not grep __aeabi_uldiv library/*.o
2589}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002590
Gilles Peskine8f073122018-11-27 15:58:47 +01002591component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02002592 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002593 scripts/config.py baremetal
2594 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02002595 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 +01002596 echo "Checking that software 64-bit multiplication is not required"
2597 if_build_succeeded not grep __aeabi_lmul library/*.o
2598}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02002599
Gilles Peskine8f073122018-11-27 15:58:47 +01002600component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02002601 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002602 scripts/config.py baremetal
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002603 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02002604
2605 msg "size: ARM Compiler 5"
2606 "$ARMC5_FROMELF" -z library/*.o
2607
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002608 make clean
Andres AG87bb5772016-09-27 15:05:15 +01002609
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002610 # ARM Compiler 6 - Target ARMv7-A
2611 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02002612
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002613 # ARM Compiler 6 - Target ARMv7-M
2614 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02002615
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002616 # ARM Compiler 6 - Target ARMv8-A - AArch32
2617 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02002618
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002619 # ARM Compiler 6 - Target ARMv8-M
2620 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02002621
Gilles Peskinebca6ab92017-12-19 18:24:31 +01002622 # ARM Compiler 6 - Target ARMv8-A - AArch64
2623 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01002624}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01002625
Manuel Pégourié-Gonnarddd8807f2020-02-26 09:56:27 +01002626component_build_ssl_hw_record_accel() {
2627 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
2628 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
2629 make CFLAGS='-Werror -O1'
2630}
2631
Hanno Beckera711f6e2020-05-04 12:03:51 +01002632component_test_tls13_experimental () {
2633 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
2634 scripts/config.pl set MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
2635 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2636 make
2637 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
2638 make test
2639}
2640
Gilles Peskine8f073122018-11-27 15:58:47 +01002641component_build_mingw () {
2642 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002643 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 +00002644
Gilles Peskine8f073122018-11-27 15:58:47 +01002645 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002646 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 +01002647 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02002648
Gilles Peskine8f073122018-11-27 15:58:47 +01002649 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002650 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
2651 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 +01002652 make WINDOWS_BUILD=1 clean
2653}
Jaeden Amero117b8a42019-04-17 15:19:26 +01002654support_build_mingw() {
2655 case $(i686-w64-mingw32-gcc -dumpversion) in
2656 [0-5]*) false;;
2657 *) true;;
2658 esac
2659}
Simon Butcher91aef332016-11-17 09:20:50 +00002660
Gilles Peskine8f073122018-11-27 15:58:47 +01002661component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002662 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002663 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002664 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
2665 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02002666
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002667 msg "test: main suites (MSan)" # ~ 10s
2668 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01002669
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002670 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine7c652162017-12-11 00:01:40 +01002671 if_build_succeeded tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01002672
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002673 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01002674
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002675 if [ "$MEMORY" -gt 0 ]; then
2676 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine7c652162017-12-11 00:01:40 +01002677 if_build_succeeded tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002678 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01002679}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002680
Gilles Peskine69f190e2019-01-10 00:11:42 +01002681component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002682 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002683 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
2684 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002685
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002686 msg "test: main suites valgrind (Release)"
2687 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002688
Gilles Peskine636c26a2020-03-04 20:46:15 +01002689 # Optional parts (slow; currently broken on OS X because programs don't
2690 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002691 if [ "$MEMORY" -gt 0 ]; then
2692 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01002693 if_build_succeeded tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002694 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002695
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002696 if [ "$MEMORY" -gt 1 ]; then
2697 msg "test: compat.sh --memcheck (Release)"
Gilles Peskine7c652162017-12-11 00:01:40 +01002698 if_build_succeeded tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002699 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002700
2701 if [ "$MEMORY" -gt 0 ]; then
2702 msg "test: context-info.sh --memcheck (Release)"
2703 if_build_succeeded tests/context-info.sh --memcheck
2704 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01002705}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002706
Gilles Peskine8f073122018-11-27 15:58:47 +01002707component_test_cmake_out_of_source () {
2708 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01002709 MBEDTLS_ROOT_DIR="$PWD"
2710 mkdir "$OUT_OF_SOURCE_DIR"
2711 cd "$OUT_OF_SOURCE_DIR"
2712 cmake "$MBEDTLS_ROOT_DIR"
2713 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00002714
Gilles Peskine8f073122018-11-27 15:58:47 +01002715 msg "test: cmake 'out-of-source' build"
2716 make test
2717 # Test an SSL option that requires an auxiliary script in test/scripts/.
2718 # Also ensure that there are no error messages such as
2719 # "No such file or directory", which would indicate that some required
2720 # file is missing (ssl-opt.sh tolerates the absence of some files so
2721 # may exit with status 0 but emit errors).
2722 if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err
2723 if [ -s ssl-opt.err ]; then
2724 cat ssl-opt.err >&2
2725 record_status [ ! -s ssl-opt.err ]
2726 rm ssl-opt.err
2727 fi
2728 cd "$MBEDTLS_ROOT_DIR"
2729 rm -rf "$OUT_OF_SOURCE_DIR"
2730 unset MBEDTLS_ROOT_DIR
2731}
Andres AGdc192212016-08-31 17:33:13 +01002732
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01002733component_test_cmake_as_subdirectory () {
2734 msg "build: cmake 'as-subdirectory' build"
2735 MBEDTLS_ROOT_DIR="$PWD"
2736
2737 cd programs/test/cmake_subproject
2738 cmake .
2739 make
2740 if_build_succeeded ./cmake_subproject
2741
2742 cd "$MBEDTLS_ROOT_DIR"
2743 unset MBEDTLS_ROOT_DIR
2744}
2745
Gilles Peskine8f073122018-11-27 15:58:47 +01002746component_test_zeroize () {
2747 # Test that the function mbedtls_platform_zeroize() is not optimized away by
2748 # different combinations of compilers and optimization flags by using an
2749 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
2750 # system in all cases that the script fails, so we must manually search the
2751 # output to check whether the pass string is present and no failure strings
2752 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01002753
Gilles Peskine4976e822019-01-06 19:52:22 +00002754 # Don't try to disable ASLR. We don't care about ASLR here. We do care
2755 # about a spurious message if Gdb tries and fails, so suppress that.
2756 gdb_disable_aslr=
2757 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
2758 gdb_disable_aslr='set disable-randomization off'
2759 fi
2760
Gilles Peskine8f073122018-11-27 15:58:47 +01002761 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01002762 for compiler in clang gcc; do
2763 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
2764 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine4976e822019-01-06 19:52:22 +00002765 if_build_succeeded gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01002766 if_build_succeeded grep "The buffer was correctly zeroized" test_zeroize.log
2767 if_build_succeeded not grep -i "error" test_zeroize.log
2768 rm -f test_zeroize.log
2769 make clean
2770 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01002771 done
Andres Amaya Garciad0d7bf62017-10-25 09:01:31 +01002772
Gilles Peskine4976e822019-01-06 19:52:22 +00002773 unset gdb_disable_aslr
Gilles Peskine8f073122018-11-27 15:58:47 +01002774}
Gilles Peskine192c72f2017-12-21 15:59:21 +01002775
Gilles Peskine8f073122018-11-27 15:58:47 +01002776component_check_python_files () {
2777 msg "Lint: Python scripts"
2778 record_status tests/scripts/check-python-files.sh
2779}
Gilles Peskine192c72f2017-12-21 15:59:21 +01002780
Gilles Peskine8f073122018-11-27 15:58:47 +01002781component_check_generate_test_code () {
2782 msg "uint test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02002783 # unittest writes out mundane stuff like number or tests run on stderr.
2784 # Our convention is to reserve stderr for actual errors, and write
2785 # harmless info on stdout so it can be suppress with --quiet.
2786 record_status ./tests/scripts/test_generate_test_code.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01002787}
Gilles Peskine192c72f2017-12-21 15:59:21 +01002788
2789################################################################
2790#### Termination
2791################################################################
2792
Gilles Peskine8f073122018-11-27 15:58:47 +01002793post_report () {
2794 msg "Done, cleaning up"
2795 cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002796
Gilles Peskine8f073122018-11-27 15:58:47 +01002797 final_report
2798}
2799
2800
2801
2802################################################################
2803#### Run all the things
2804################################################################
2805
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01002806# Function invoked by --error-test to test error reporting.
2807pseudo_component_error_test () {
2808 msg "Testing error reporting $error_test"
2809 if [ $KEEP_GOING -ne 0 ]; then
2810 echo "Expect three failing commands."
2811 fi
2812 error_test='this should not be used since the component runs in a subshell'
2813 grep non_existent /dev/null
2814 not grep -q . "$0"
2815 make unknown_target
2816 false "this should not be executed"
2817}
2818
Gilles Peskinee48351a2018-11-27 16:06:30 +01002819# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01002820run_component () {
Gilles Peskine608953e2019-01-02 18:57:02 +01002821 # Back up the configuration in case the component modifies it.
2822 # The cleanup function will restore it.
2823 cp -p "$CONFIG_H" "$CONFIG_BAK"
John Durkopbd069d32020-10-31 22:14:03 -07002824 cp -p "$CRYPTO_CONFIG_H" "$CRYPTO_CONFIG_BAK"
Gilles Peskineffcdeff2018-12-04 12:49:28 +01002825 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02002826 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02002827
2828 # Unconditionally create a seedfile that's sufficiently long.
2829 # Do this before each component, because a previous component may
2830 # have messed it up or shortened it.
Manuel Pégourié-Gonnardf1f180a2020-06-08 10:46:35 +02002831 redirect_err dd if=/dev/urandom of=./tests/seedfile bs=64 count=1
Gilles Peskine2ef377d2019-10-07 18:44:21 +02002832
2833 # Run the component code.
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02002834 if [ $QUIET -eq 1 ]; then
2835 # msg() is silenced, so just print the component name here
2836 echo "${current_component#component_}"
2837 fi
2838 redirect_out "$@"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02002839
2840 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01002841 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02002842 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01002843}
2844
2845# Preliminary setup
2846pre_check_environment
2847pre_initialize_variables
2848pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01002849
Gilles Peskine878cf602019-01-06 20:50:38 +00002850pre_check_git
Andrzej Kurekeb508712019-02-14 07:18:59 -05002851
Gilles Peskine878cf602019-01-06 20:50:38 +00002852build_status=0
2853if [ $KEEP_GOING -eq 1 ]; then
2854 pre_setup_keep_going
Gilles Peskine92525112018-11-27 18:15:35 +01002855else
Gilles Peskine878cf602019-01-06 20:50:38 +00002856 record_status () {
2857 "$@"
2858 }
Gilles Peskine8f073122018-11-27 15:58:47 +01002859fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02002860pre_setup_quiet_redirect
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02002861pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00002862pre_print_configuration
2863pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002864cleanup
2865
Gilles Peskinebeb3a812019-01-06 22:11:25 +00002866# Run the requested tests.
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01002867while [ $error_test -gt 0 ]; do
2868 run_component pseudo_component_error_test
2869 error_test=$((error_test - 1))
2870done
Gilles Peskinebeb3a812019-01-06 22:11:25 +00002871for component in $RUN_COMPONENTS; do
2872 run_component "component_$component"
2873done
Gilles Peskine8f073122018-11-27 15:58:47 +01002874
2875# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00002876post_report