blob: 6c50bd2184ca0ebb99828d227a6d1bbe5d52a0ad [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#
Gilles Peskine7105a332020-03-28 18:50:43 +010062# The behavior on an error depends on whether --keep-going (alias -k)
63# is in effect.
64# * Without --keep-going: the script stops on the first error without
65# cleaning up. This lets you work in the configuration of the failing
66# component.
67# * With --keep-going: the script runs all requested components and
68# reports failures at the end. In particular the script always cleans
69# up on exit.
70#
Gilles Peskine192c72f2017-12-21 15:59:21 +010071# Note that the output is not saved. You may want to run
72# script -c tests/scripts/all.sh
73# or
74# tests/scripts/all.sh >all.log 2>&1
75#
76# Notes for maintainers
77# ---------------------
78#
Gilles Peskine8f073122018-11-27 15:58:47 +010079# The bulk of the code is organized into functions that follow one of the
80# following naming conventions:
81# * pre_XXX: things to do before running the tests, in order.
82# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010083# * component_check_XXX: quick tests that aren't worth parallelizing.
84# * component_build_XXX: build things but don't run them.
85# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000086# * support_XXX: if support_XXX exists and returns false then
87# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010088# * post_XXX: things to do after running the tests.
89# * other: miscellaneous support functions.
90#
Gilles Peskinec70637a2019-01-09 22:29:17 +010091# Each component must start by invoking `msg` with a short informative message.
92#
Gilles Peskine39a3b112020-03-28 21:27:40 +010093# Warning: due to the way bash detects errors, the failure of a command
94# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
95#
Gilles Peskine7105a332020-03-28 18:50:43 +010096# Each component is executed in a separate shell process. The component
97# fails if any command in it returns a non-zero status.
98#
Gilles Peskinec70637a2019-01-09 22:29:17 +010099# The framework performs some cleanup tasks after each component. This
100# means that components can assume that the working directory is in a
101# cleaned-up state, and don't need to perform the cleanup themselves.
102# * Run `make clean`.
103# * Restore `include/mbedtks/config.h` from a backup made before running
104# the component.
Gilles Peskine636c26a2020-03-04 20:46:15 +0100105# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
106# `tests/Makefile` and `programs/fuzz/Makefile` from git.
107# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +0100108#
Gilles Peskine192c72f2017-12-21 15:59:21 +0100109# The tests are roughly in order from fastest to slowest. This doesn't
110# have to be exact, but in general you should add slower tests towards
111# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100112
113
114
115################################################################
116#### Initialization and command line parsing
117################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100118
Gilles Peskine8ab29942020-03-28 18:50:49 +0100119# Abort on errors (even on the left-hand side of a pipe).
120# Treat uninitialised variables as errors.
121set -e -o pipefail -u
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100122
Gilles Peskine79598582022-08-30 21:02:44 +0200123# Enable ksh/bash extended file matching patterns
124shopt -s extglob
125
Gilles Peskine8f073122018-11-27 15:58:47 +0100126pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000127 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100128 echo "Must be run from mbed TLS root" >&2
129 exit 1
130 fi
131}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100132
Gilles Peskine8f073122018-11-27 15:58:47 +0100133pre_initialize_variables () {
134 CONFIG_H='include/mbedtls/config.h'
John Durkopbd069d32020-10-31 22:14:03 -0700135 CRYPTO_CONFIG_H='include/psa/crypto_config.h'
Gilles Peskine24bdf022020-03-30 20:11:39 +0200136
137 # Files that are clobbered by some jobs will be backed up. Use a different
138 # suffix from auxiliary scripts so that all.sh and auxiliary scripts can
139 # independently decide when to remove the backup file.
140 backup_suffix='.all.bak'
141 # Files clobbered by config.py
142 files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H"
Gilles Peskineef64e7f2021-07-12 18:16:01 +0200143 # Files clobbered by in-tree cmake
144 files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200145
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200146 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100147 MEMORY=0
148 FORCE=0
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200149 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100150 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100151
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200152 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard54304472020-06-22 10:11:47 +0200153 #
154 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
155 # both values are kept in sync. If you change the value here because it
156 # breaks some tests, you'll definitely want to change it in
157 # basic-build-test.sh as well.
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200158 RELEASE_SEED=1
159
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200160 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200161 : ${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 +0200162 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200163 export MBEDTLS_TEST_PLATFORM
164
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000165 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100166 : ${OPENSSL:="openssl"}
167 : ${OPENSSL_LEGACY:="$OPENSSL"}
168 : ${OPENSSL_NEXT:="$OPENSSL"}
169 : ${GNUTLS_CLI:="gnutls-cli"}
170 : ${GNUTLS_SERV:="gnutls-serv"}
171 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
172 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
173 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
174 : ${ARMC5_BIN_DIR:=/usr/bin}
175 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskine6d061342020-04-30 18:19:32 +0200176 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200177 : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
Andres AGdc192212016-08-31 17:33:13 +0100178
Gilles Peskine8f073122018-11-27 15:58:47 +0100179 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000180 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine85229ac2021-09-30 18:24:21 +0200181 export MAKEFLAGS="-j$(all_sh_nproc)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100182 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000183
Gilles Peskinec761d8f2021-09-20 18:57:55 +0200184 # Include more verbose output for failing tests run by CMake or make
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000185 export CTEST_OUTPUT_ON_FAILURE=1
186
Gilles Peskine8fd59422019-10-21 17:11:33 +0200187 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Manuel Pégourié-Gonnard717f2302022-11-30 10:42:03 +0100188 # default to -O2, use -Ox _after_ this if you want another level
Manuel Pégourié-Gonnard154b84e2022-11-28 13:12:10 +0100189 ASAN_CFLAGS='-O2 -Werror -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200190
Gilles Peskine878cf602019-01-06 20:50:38 +0000191 # Gather the list of available components. These are the functions
192 # defined in this script whose name starts with "component_".
Gilles Peskine3de7be82020-03-27 16:35:23 +0100193 # Parse the script with sed. This way we get the functions in the order
194 # they are defined.
Gilles Peskine878cf602019-01-06 20:50:38 +0000195 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
196
197 # Exclude components that are not supported on this platform.
198 SUPPORTED_COMPONENTS=
199 for component in $ALL_COMPONENTS; do
200 case $(type "support_$component" 2>&1) in
201 *' function'*)
202 if ! support_$component; then continue; fi;;
203 esac
204 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
205 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100206}
Andres AG38495a32016-07-12 16:54:33 +0100207
Gilles Peskinea28db922019-01-10 00:05:18 +0100208# Test whether the component $1 is included in the command line patterns.
209is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100210{
Gilles Peskine6702ce92021-08-06 11:35:17 +0200211 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
212 # only does word splitting.
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100213 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000214 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100215 set +f
216 case ${1#component_} in $pattern) return 0;; esac
217 done
218 set +f
219 return 1
220}
Andres AG7770ea82016-10-10 15:46:20 +0100221
Simon Butcher41eeccf2016-09-07 00:07:09 +0100222usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100223{
Gilles Peskine709346a2017-12-10 23:43:39 +0100224 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100225Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100226Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100227By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100228COMPONENT can be the name of a component or a shell wildcard pattern.
229
230Examples:
231 $0 "check_*"
232 Run all sanity checks.
233 $0 --no-armcc --except test_memsan
234 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100235
236Special options:
237 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000238 --list-all-components List all available test components and exit.
239 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100240
241General options:
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200242 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100243 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100244 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100245 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200246 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200247 --arm-none-eabi-gcc-prefix=<string>
248 Prefix for a cross-compiler for arm-none-eabi
249 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200250 --arm-linux-gnueabi-gcc-prefix=<string>
251 Prefix for a cross-compiler for arm-linux-gnueabi
252 (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100253 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200254 --restore First clean up the build tree, restoring backed up
255 files. Do not run any components unless they are
256 explicitly specified.
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100257 --error-test Error test mode: run a failing function in addition
Gilles Peskinea25c5672021-08-05 15:11:33 +0200258 to any specified component. May be repeated.
Gilles Peskinea28db922019-01-10 00:05:18 +0100259 --except Exclude the COMPONENTs listed on the command line,
260 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200261 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100262 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100263 --no-force Refuse to overwrite modified files (default).
264 --no-keep-going Stop at the first error (default).
265 --no-memory No additional memory tests (default).
Shaun Case0e7791f2021-12-20 21:14:10 -0800266 --no-quiet Print full output from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100267 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200268 --outcome-file=<path> File where test outcomes are written (not done if
269 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100270 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200271 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100272 -s|--seed Integer seed value to use for this test run.
273
274Tool path options:
275 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
276 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
277 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
278 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
279 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
280 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
281 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
282 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100283 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100284EOF
SimonB2e23c822016-04-16 21:54:39 +0100285}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100286
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200287# Cleanup before/after running a component.
288# Remove built files as well as the cmake cache/config.
289# Does not remove generated source files.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100290cleanup()
291{
Gilles Peskine7c652162017-12-11 00:01:40 +0100292 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200293
Gilles Peskine31b07e22018-03-21 12:15:06 +0100294 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000295 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100296 -iname CMakeFiles -exec rm -rf {} \+ -o \
297 \( -iname cmake_install.cmake -o \
298 -iname CTestTestfile.cmake -o \
299 -iname CMakeCache.txt \) -exec rm {} \+
300 # Recover files overwritten by in-tree CMake builds
Gilles Peskine79598582022-08-30 21:02:44 +0200301 rm -f include/Makefile include/mbedtls/Makefile programs/!(fuzz)/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200302
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100303 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
304 rm -rf programs/test/cmake_subproject/build
305 rm -f programs/test/cmake_subproject/Makefile
306 rm -f programs/test/cmake_subproject/cmake_subproject
307
Gilles Peskine24bdf022020-03-30 20:11:39 +0200308 # Restore files that may have been clobbered by the job
309 for x in $files_to_back_up; do
Gilles Peskine423dd132022-08-30 21:02:00 +0200310 if [[ -e "$x$backup_suffix" ]]; then
311 cp -p "$x$backup_suffix" "$x"
312 fi
Gilles Peskine24bdf022020-03-30 20:11:39 +0200313 done
314}
John Durkopbd069d32020-10-31 22:14:03 -0700315
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200316# Final cleanup when this script exits (except when exiting on a failure
317# in non-keep-going mode).
Gilles Peskine24bdf022020-03-30 20:11:39 +0200318final_cleanup () {
319 cleanup
320
321 for x in $files_to_back_up; do
322 rm -f "$x$backup_suffix"
323 done
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100324}
325
Gilles Peskine7c652162017-12-11 00:01:40 +0100326# Executed on exit. May be redefined depending on command line options.
327final_report () {
328 :
329}
330
331fatal_signal () {
Gilles Peskine24bdf022020-03-30 20:11:39 +0200332 final_cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100333 final_report $1
334 trap - $1
335 kill -$1 $$
336}
337
338trap 'fatal_signal HUP' HUP
339trap 'fatal_signal INT' INT
340trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200341
Gilles Peskine85229ac2021-09-30 18:24:21 +0200342# Number of processors on this machine. Used as the default setting
343# for parallel make.
344all_sh_nproc ()
345{
346 {
347 nproc || # Linux
348 sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
349 sysctl -n hw.ncpu || # FreeBSD
350 echo 1
351 } 2>/dev/null
352}
353
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100354msg()
355{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100356 if [ -n "${current_component:-}" ]; then
357 current_section="${current_component#component_}: $1"
358 else
359 current_section="$1"
360 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200361
362 if [ $QUIET -eq 1 ]; then
363 return
364 fi
365
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100366 echo ""
367 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100368 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000369 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100370 echo "******************************************************************"
371}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100372
Gilles Peskine8f073122018-11-27 15:58:47 +0100373armc6_build_test()
374{
375 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100376
Gilles Peskine18487f62020-04-30 23:11:54 +0200377 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100378 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
379 WARNING_CFLAGS='-xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200380
381 msg "size: ARM Compiler 6 ($FLAGS)"
382 "$ARMC6_FROMELF" -z library/*.o
383
Gilles Peskine8f073122018-11-27 15:58:47 +0100384 make clean
385}
Andres AGa5cd9732016-10-17 15:23:10 +0100386
Andres AGd9eba4b2016-08-26 14:42:14 +0100387err_msg()
388{
389 echo "$1" >&2
390}
391
392check_tools()
393{
394 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000395 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100396 err_msg "$TOOL not found!"
397 exit 1
398 fi
399 done
400}
401
Gilles Peskine8f073122018-11-27 15:58:47 +0100402pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000403 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100404 all_except=0
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100405 error_test=0
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200406 restore_first=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000407 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100408
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000409 # Note that legacy options are ignored instead of being omitted from this
410 # list of options, so invocations that worked with previous version of
411 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100412 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100413 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200414 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200415 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200416 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000417 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100418 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
419 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100420 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000421 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100422 --force|-f) FORCE=1;;
423 --gnutls-cli) shift; GNUTLS_CLI="$1";;
424 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
425 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
426 --gnutls-serv) shift; GNUTLS_SERV="$1";;
427 --help|-h) usage; exit;;
428 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000429 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
430 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100431 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200432 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000433 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100434 --no-force) FORCE=0;;
435 --no-keep-going) KEEP_GOING=0;;
436 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200437 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100438 --openssl) shift; OPENSSL="$1";;
439 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
440 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200441 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100442 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200443 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100444 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200445 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200446 --restore) restore_first=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100447 --seed|-s) shift; SEED="$1";;
448 -*)
449 echo >&2 "Unknown option: $1"
450 echo >&2 "Run $0 --help for usage."
451 exit 120
452 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000453 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100454 esac
455 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100456 done
SimonB2e23c822016-04-16 21:54:39 +0100457
Gilles Peskinea28db922019-01-10 00:05:18 +0100458 # With no list of components, run everything.
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200459 if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000460 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100461 fi
462
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000463 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
464 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100465 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000466 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100467 fi
SimonB2e23c822016-04-16 21:54:39 +0100468
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200469 # Error out if an explicitly requested component doesn't exist.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100470 if [ $all_except -eq 0 ]; then
471 unsupported=0
Gilles Peskine6702ce92021-08-06 11:35:17 +0200472 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
473 # only does word splitting.
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200474 set -f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100475 for component in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200476 set +f
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200477 # If the requested name includes a wildcard character, don't
478 # check it. Accept wildcard patterns that don't match anything.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100479 case $component in
480 *[*?\[]*) continue;;
481 esac
482 case " $SUPPORTED_COMPONENTS " in
483 *" $component "*) :;;
484 *)
485 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
486 unsupported=$((unsupported + 1));;
487 esac
488 done
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200489 set +f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100490 if [ $unsupported -ne 0 ]; then
491 exit 2
492 fi
493 fi
494
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000495 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100496 RUN_COMPONENTS=
497 for component in $SUPPORTED_COMPONENTS; do
498 if is_component_included "$component"; [ $? -eq $all_except ]; then
499 RUN_COMPONENTS="$RUN_COMPONENTS $component"
500 fi
501 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000502
503 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000504 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100505}
SimonB2e23c822016-04-16 21:54:39 +0100506
Gilles Peskine8f073122018-11-27 15:58:47 +0100507pre_check_git () {
508 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100509 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100510 git checkout-index -f -q $CONFIG_H
511 cleanup
512 else
SimonB2e23c822016-04-16 21:54:39 +0100513
Gilles Peskine8f073122018-11-27 15:58:47 +0100514 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
515 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
516 echo "You can either delete this directory manually, or force the test by rerunning"
517 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
518 exit 1
519 fi
520
Gilles Peskined1174cf2019-01-09 22:30:01 +0100521 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100522 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
523 echo "You can either delete or preserve your work, or force the test by rerunning the"
524 echo "script as: $0 --force"
525 exit 1
526 fi
SimonB2e23c822016-04-16 21:54:39 +0100527 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500528}
529
Gilles Peskineef64e7f2021-07-12 18:16:01 +0200530pre_restore_files () {
531 # If the makefiles have been generated by a framework such as cmake,
532 # restore them from git. If the makefiles look like modifications from
533 # the ones checked into git, take care not to modify them. Whatever
534 # this function leaves behind is what the script will restore before
535 # each component.
536 case "$(head -n1 Makefile)" in
537 *[Gg]enerated*)
538 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
539 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
540 ;;
541 esac
542}
543
Gilles Peskine24bdf022020-03-30 20:11:39 +0200544pre_back_up () {
545 for x in $files_to_back_up; do
546 cp -p "$x" "$x$backup_suffix"
547 done
548}
549
Gilles Peskine8f073122018-11-27 15:58:47 +0100550pre_setup_keep_going () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100551 failure_count=0 # Number of failed components
552 last_failure_status=0 # Last failure status in this component
553
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100554 # See err_trap
555 previous_failure_status=0
556 previous_failed_command=
557 previous_failure_funcall_depth=0
Gilles Peskine39a3b112020-03-28 21:27:40 +0100558 unset report_failed_command
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100559
Gilles Peskine7c652162017-12-11 00:01:40 +0100560 start_red=
561 end_color=
562 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100563 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100564 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
565 start_red=$(printf '\033[31m')
566 end_color=$(printf '\033[0m')
567 ;;
568 esac
569 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100570
571 # Keep a summary of failures in a file. We'll print it out at the end.
572 failure_summary_file=$PWD/all-sh-failures-$$.log
573 : >"$failure_summary_file"
574
575 # Whether it makes sense to keep a component going after the specified
576 # command fails (test command) or not (configure or build).
Gilles Peskine6702ce92021-08-06 11:35:17 +0200577 # This function normally receives the failing simple command
578 # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
579 # this is passed instead.
Gilles Peskine7105a332020-03-28 18:50:43 +0100580 # This doesn't have to be 100% accurate: all failures are recorded anyway.
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200581 # False positives result in running things that can't be expected to
582 # work. False negatives result in things not running after something else
583 # failed even though they might have given useful feedback.
Gilles Peskine7105a332020-03-28 18:50:43 +0100584 can_keep_going_after_failure () {
585 case "$1" in
586 "msg "*) false;;
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200587 "cd "*) false;;
588 *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
589 *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
590 *make*check*) true;;
591 "grep "*) true;;
592 "[ "*) true;;
593 "! "*) true;;
Gilles Peskine7105a332020-03-28 18:50:43 +0100594 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100595 esac
596 }
Gilles Peskine7105a332020-03-28 18:50:43 +0100597
598 # This function runs if there is any error in a component.
599 # It must either exit with a nonzero status, or set
600 # last_failure_status to a nonzero value.
601 err_trap () {
602 # Save $? (status of the failing command). This must be the very
603 # first thing, before $? is overridden.
604 last_failure_status=$?
Gilles Peskine39a3b112020-03-28 21:27:40 +0100605 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskine7105a332020-03-28 18:50:43 +0100606
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100607 if [[ $last_failure_status -eq $previous_failure_status &&
608 "$failed_command" == "$previous_failed_command" &&
609 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
610 then
611 # The same command failed twice in a row, but this time one level
612 # less deep in the function call stack. This happens when the last
613 # command of a function returns a nonzero status, and the function
614 # returns that same status. Ignore the second failure.
615 previous_failure_funcall_depth=${#FUNCNAME[@]}
616 return
617 fi
618 previous_failure_status=$last_failure_status
619 previous_failed_command=$failed_command
620 previous_failure_funcall_depth=${#FUNCNAME[@]}
621
Gilles Peskine7105a332020-03-28 18:50:43 +0100622 text="$current_section: $failed_command -> $last_failure_status"
623 echo "${start_red}^^^^$text^^^^${end_color}" >&2
624 echo "$text" >>"$failure_summary_file"
625
626 # If the command is fatal (configure or build command), stop this
627 # component. Otherwise (test command) keep the component running
628 # (run more tests from the same build).
629 if ! can_keep_going_after_failure "$failed_command"; then
630 exit $last_failure_status
631 fi
632 }
633
Gilles Peskine7c652162017-12-11 00:01:40 +0100634 final_report () {
635 if [ $failure_count -gt 0 ]; then
636 echo
637 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskine7105a332020-03-28 18:50:43 +0100638 echo "${start_red}FAILED: $failure_count components${end_color}"
639 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100640 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
641 elif [ -z "${1-}" ]; then
642 echo "SUCCESS :)"
643 fi
644 if [ -n "${1-}" ]; then
645 echo "Killed by SIG$1."
646 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100647 rm -f "$failure_summary_file"
648 if [ $failure_count -gt 0 ]; then
649 exit 1
650 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100651 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100652}
653
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200654# record_status() and if_build_succeeded() are kept temporarily for backward
655# compatibility. Don't use them in new components.
Gilles Peskine7105a332020-03-28 18:50:43 +0100656record_status () {
657 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100658}
Gilles Peskine7c652162017-12-11 00:01:40 +0100659if_build_succeeded () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100660 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100661}
662
Gilles Peskine39a3b112020-03-28 21:27:40 +0100663# '! true' does not trigger the ERR trap. Arrange to trigger it, with
664# a reasonably informative error message (not just "$@").
665not () {
666 if "$@"; then
667 report_failed_command="! $*"
668 false
669 unset report_failed_command
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200670 fi
671}
672
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200673pre_prepare_outcome_file () {
674 case "$MBEDTLS_TEST_OUTCOME_FILE" in
675 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
676 esac
677 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
678 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
679 fi
680}
681
Gilles Peskine8f073122018-11-27 15:58:47 +0100682pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200683 if [ $QUIET -eq 1 ]; then
684 return
685 fi
686
Gilles Peskine8f073122018-11-27 15:58:47 +0100687 msg "info: $0 configuration"
688 echo "MEMORY: $MEMORY"
689 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200690 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100691 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100692 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100693 echo "OPENSSL: $OPENSSL"
694 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
695 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
696 echo "GNUTLS_CLI: $GNUTLS_CLI"
697 echo "GNUTLS_SERV: $GNUTLS_SERV"
698 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
699 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
700 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
701 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
702}
Andres AG7770ea82016-10-10 15:46:20 +0100703
Andres AGd9eba4b2016-08-26 14:42:14 +0100704# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100705pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000706 # Build the list of variables to pass to output_env.sh.
707 set env
SimonB2e23c822016-04-16 21:54:39 +0100708
Gilles Peskine87964262019-01-06 22:40:00 +0000709 case " $RUN_COMPONENTS " in
710 # Require OpenSSL and GnuTLS if running any tests (as opposed to
711 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
712 # is a good enough approximation in practice.
713 *" test_"*)
714 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
715 # and ssl-opt.sh, we just export the variables they require.
716 export OPENSSL_CMD="$OPENSSL"
717 export GNUTLS_CLI="$GNUTLS_CLI"
718 export GNUTLS_SERV="$GNUTLS_SERV"
719 # Avoid passing --seed flag in every call to ssl-opt.sh
720 if [ -n "${SEED-}" ]; then
721 export SEED
722 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000723 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
724 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
725 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
726 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000727 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
728 "$GNUTLS_CLI" "$GNUTLS_SERV" \
729 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
730 ;;
731 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200732
Gilles Peskine87964262019-01-06 22:40:00 +0000733 case " $RUN_COMPONENTS " in
734 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
735 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100736
Gilles Peskine87964262019-01-06 22:40:00 +0000737 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200738 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000739 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100740
Gilles Peskine87964262019-01-06 22:40:00 +0000741 case " $RUN_COMPONENTS " in
742 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
743 esac
744
745 case " $RUN_COMPONENTS " in
746 *" test_zeroize "*) check_tools "gdb";;
747 esac
748
749 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000750 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000751 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
752 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200753 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000754 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
755 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200756 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
757 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
758 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000759 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000760
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200761 # past this point, no call to check_tool, only printing output
762 if [ $QUIET -eq 1 ]; then
763 return
764 fi
765
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000766 msg "info: output_env.sh"
767 case $RUN_COMPONENTS in
768 *_armcc*)
769 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
770 *) set "$@" RUN_ARMCC=0;;
771 esac
772 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100773}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100774
Gilles Peskine192c72f2017-12-21 15:59:21 +0100775
776
777################################################################
778#### Basic checks
779################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100780
781#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200782# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100783#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100784# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200785# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100786# 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 +0200787# time, so start with a GCC build).
788# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100789#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100790# Indicative running times are given for reference.
791
Gilles Peskine8f073122018-11-27 15:58:47 +0100792component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200793 msg "Check: recursion.pl" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200794 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100795}
Janos Follathb72c6782016-07-19 14:54:17 +0100796
Gilles Peskine8f073122018-11-27 15:58:47 +0100797component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200798 msg "Check: freshness of generated source files" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200799 tests/scripts/check-generated-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100800}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200801
Gilles Peskine8f073122018-11-27 15:58:47 +0100802component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200803 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200804 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +0100805}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200806
Gilles Peskine8f073122018-11-27 15:58:47 +0100807component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200808 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200809 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100810}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200811
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200812component_check_changelog () {
813 msg "Check: changelog entries" # < 1s
814 rm -f ChangeLog.new
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200815 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200816 if [ -e ChangeLog.new ]; then
817 # Show the diff for information. It isn't an error if the diff is
818 # non-empty.
819 diff -u ChangeLog ChangeLog.new || true
820 rm ChangeLog.new
821 fi
822}
823
Gilles Peskine8f073122018-11-27 15:58:47 +0100824component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200825 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200826 tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100827}
Darryl Greena07039c2018-03-13 16:48:16 +0000828
Gilles Peskine895868b2019-09-19 21:30:05 +0200829component_check_test_cases () {
830 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200831 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200832 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200833 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200834 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200835 fi
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200836 tests/scripts/check_test_cases.py $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200837 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +0200838}
839
Gilles Peskine8f073122018-11-27 15:58:47 +0100840component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200841 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200842 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100843}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200844
Gilles Peskine192c72f2017-12-21 15:59:21 +0100845
Gilles Peskine636c26a2020-03-04 20:46:15 +0100846
Gilles Peskine192c72f2017-12-21 15:59:21 +0100847################################################################
848#### Build and test many configurations and targets
849################################################################
850
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200851component_test_default_out_of_box () {
852 msg "build: make, default config (out-of-box)" # ~1min
853 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200854 # Disable fancy stuff
855 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200856
857 msg "test: main suites make, default config (out-of-box)" # ~10s
858 make test
859
860 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200861 programs/test/selftest
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200862}
863
Gilles Peskine8f073122018-11-27 15:58:47 +0100864component_test_default_cmake_gcc_asan () {
865 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100866 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
867 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200868
Gilles Peskine8f073122018-11-27 15:58:47 +0100869 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
870 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200871
Gilles Peskine97bea012020-04-23 23:37:45 +0200872 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200873 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200874
Gilles Peskine8f073122018-11-27 15:58:47 +0100875 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200876 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200877
Gilles Peskine8f073122018-11-27 15:58:47 +0100878 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200879 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200880
881 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200882 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100883}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200884
Hanno Becker01635512019-02-26 14:27:09 +0000885component_test_full_cmake_gcc_asan () {
886 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200887 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000888 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
889 make
890
891 msg "test: main suites (inc. selftests) (full config, ASan build)"
892 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +0100893
Gilles Peskine97bea012020-04-23 23:37:45 +0200894 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200895 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200896
Gilles Peskine636c26a2020-03-04 20:46:15 +0100897 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200898 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100899
900 msg "test: compat.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200901 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200902
903 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200904 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100905}
906
Ronald Cronc3623db2020-10-29 10:51:32 +0100907component_test_psa_crypto_key_id_encodes_owner () {
908 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
909 scripts/config.py full
910 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
911 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
912 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
913 make
914
915 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
916 make test
917}
918
Gilles Peskine99a34622021-06-17 11:37:52 +0200919# check_renamed_symbols HEADER LIB
920# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
921# name is LIB.
922check_renamed_symbols () {
923 ! nm "$2" | sed 's/.* //' |
924 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
925}
926
Gilles Peskine984c19f2021-06-15 18:37:38 +0200927component_build_psa_crypto_spm () {
928 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
929 scripts/config.py full
930 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
931 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
932 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
933 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
934 # We can only compile, not link, since our test and sample programs
935 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
936 # is active.
937 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskine99a34622021-06-17 11:37:52 +0200938
939 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
940 # version is not present.
941 echo "Checking for renamed symbols in the library"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200942 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskine984c19f2021-06-15 18:37:38 +0200943}
944
Ronald Cron336678b2021-01-28 17:54:24 +0100945component_test_psa_crypto_client () {
946 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
947 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
948 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
949 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
950 make
951
952 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
953 make test
954}
955
Gilles Peskine636c26a2020-03-04 20:46:15 +0100956component_test_zlib_make() {
957 msg "build: zlib enabled, make"
958 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine6fa69862021-10-05 09:36:03 +0200959 make ZLIB=1 CFLAGS='-Werror -O2'
Gilles Peskine636c26a2020-03-04 20:46:15 +0100960
961 msg "test: main suites (zlib, make)"
962 make test
963
964 msg "test: ssl-opt.sh (zlib, make)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200965 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100966}
967support_test_zlib_make () {
968 base=support_test_zlib_$$
969 cat <<'EOF' > ${base}.c
970#include "zlib.h"
971int main(void) { return 0; }
972EOF
973 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
974 ret=$?
975 rm -f ${base}.*
976 return $ret
977}
978
979component_test_zlib_cmake() {
980 msg "build: zlib enabled, cmake"
981 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine25319702021-10-07 19:34:57 +0200982 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Release .
Gilles Peskine636c26a2020-03-04 20:46:15 +0100983 make
984
985 msg "test: main suites (zlib, cmake)"
986 make test
987
988 msg "test: ssl-opt.sh (zlib, cmake)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200989 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100990}
991support_test_zlib_cmake () {
992 support_test_zlib_make "$@"
Manuel Pégourié-Gonnardf2e29022020-01-24 10:17:20 +0100993}
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +0100994
Jaeden Ameroc17f2932021-05-14 08:34:32 +0100995component_test_psa_crypto_rsa_no_genprime() {
996 msg "build: default config minus MBEDTLS_GENPRIME"
997 scripts/config.py unset MBEDTLS_GENPRIME
998 make
999
1000 msg "test: default config minus MBEDTLS_GENPRIME"
1001 make test
1002}
1003
Gilles Peskine782f4112018-11-27 16:11:09 +01001004component_test_ref_configs () {
1005 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
1006 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001007 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +01001008}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001009
Gilles Peskine8f073122018-11-27 15:58:47 +01001010component_test_sslv3 () {
1011 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001012 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +01001013 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1014 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001015
Gilles Peskine8f073122018-11-27 15:58:47 +01001016 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
1017 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +00001018
Gilles Peskine8f073122018-11-27 15:58:47 +01001019 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Xiaofei Baif40545d2021-12-02 08:43:35 +00001020 tests/compat.sh -m 'tls1 tls1_1 tls12 dtls1 dtls12'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001021 env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +00001022
Gilles Peskine8f073122018-11-27 15:58:47 +01001023 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001024 tests/ssl-opt.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001025
1026 msg "build: SSLv3 - context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001027 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001028}
Simon Butcher3ea7f522016-03-07 23:22:10 +00001029
Gilles Peskine8f073122018-11-27 15:58:47 +01001030component_test_no_renegotiation () {
1031 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001032 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001033 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1034 make
Simon Butcher3ea7f522016-03-07 23:22:10 +00001035
Gilles Peskine8f073122018-11-27 15:58:47 +01001036 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1037 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +01001038
Gilles Peskine8f073122018-11-27 15:58:47 +01001039 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001040 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001041}
Hanno Becker134c2ab2017-10-12 15:29:50 +01001042
Gilles Peskine636c26a2020-03-04 20:46:15 +01001043component_test_no_pem_no_fs () {
1044 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1045 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1046 scripts/config.py unset MBEDTLS_FS_IO
1047 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1048 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
1049 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1050 make
1051
1052 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1053 make test
1054
1055 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001056 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001057}
1058
Gilles Peskine8f073122018-11-27 15:58:47 +01001059component_test_rsa_no_crt () {
1060 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001061 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +01001062 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1063 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +01001064
Gilles Peskine8f073122018-11-27 15:58:47 +01001065 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1066 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001067
Gilles Peskine8f073122018-11-27 15:58:47 +01001068 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001069 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001070
Gilles Peskine8f073122018-11-27 15:58:47 +01001071 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001072 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001073
1074 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001075 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001076}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001077
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001078component_test_no_ctr_drbg_classic () {
1079 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001080 scripts/config.py full
1081 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001082 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001083
1084 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1085 make
1086
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001087 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001088 make test
1089
Gilles Peskineba749042021-01-13 20:02:03 +01001090 # In this configuration, the TLS test programs use HMAC_DRBG.
1091 # The SSL tests are slow, so run a small subset, just enough to get
1092 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001093 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001094 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001095
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001096 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001097 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001098}
1099
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001100component_test_no_ctr_drbg_use_psa () {
1101 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001102 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001103 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1104 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001105
1106 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1107 make
1108
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001109 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1110 make test
1111
1112 # In this configuration, the TLS test programs use HMAC_DRBG.
1113 # The SSL tests are slow, so run a small subset, just enough to get
1114 # confidence that the SSL code copes with HMAC_DRBG.
1115 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001116 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001117
1118 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001119 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001120}
1121
1122component_test_no_hmac_drbg_classic () {
1123 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1124 scripts/config.py full
1125 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1126 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1127 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1128
1129 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1130 make
1131
1132 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001133 make test
1134
Gilles Peskinea2224342020-11-19 22:14:34 +01001135 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1136 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1137 # instead.
1138 # Test SSL with non-deterministic ECDSA. Only test features that
1139 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001140 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001141 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001142
1143 # To save time, only test one protocol version, since this part of
1144 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001145 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001146 tests/compat.sh -m tls12 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001147}
1148
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001149component_test_no_hmac_drbg_use_psa () {
1150 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1151 scripts/config.py full
1152 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1153 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1154 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1155
1156 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1157 make
1158
1159 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1160 make test
1161
1162 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1163 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1164 # instead.
1165 # Test SSL with non-deterministic ECDSA. Only test features that
1166 # might be affected by how ECDSA signature is performed.
1167 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001168 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001169
1170 # To save time, only test one protocol version, since this part of
1171 # the protocol is identical in (D)TLS up to 1.2.
1172 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001173 tests/compat.sh -m tls12 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001174}
1175
1176component_test_psa_external_rng_no_drbg_classic () {
1177 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1178 scripts/config.py full
1179 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1180 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001181 scripts/config.py unset MBEDTLS_ENTROPY_C
1182 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1183 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001184 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1185 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1186 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1187 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001188 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1189 # the SSL test programs don't have an RNG and can't work. Explicitly
1190 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1191 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001192
1193 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1194 make test
1195
Gilles Peskine8eb29432021-02-03 20:07:11 +01001196 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001197 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001198}
1199
1200component_test_psa_external_rng_no_drbg_use_psa () {
1201 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001202 scripts/config.py full
1203 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001204 scripts/config.py unset MBEDTLS_ENTROPY_C
1205 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1206 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001207 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1208 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1209 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1210 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1211 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1212
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001213 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001214 make test
1215
Gilles Peskine8eb29432021-02-03 20:07:11 +01001216 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001217 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001218}
1219
1220component_test_psa_external_rng_use_psa_crypto () {
1221 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1222 scripts/config.py full
1223 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1224 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1225 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1226 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1227
1228 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1229 make test
1230
Gilles Peskineba749042021-01-13 20:02:03 +01001231 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001232 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001233}
1234
Manuel Pégourié-Gonnard1a3f9ed2020-05-19 12:38:31 +02001235component_test_ecp_no_internal_rng () {
1236 msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
1237 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1238 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1239 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1240 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1241 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
1242 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1243
1244 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1245 make
1246
1247 msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
1248 make test
1249
1250 # no SSL tests as they all depend on having a DRBG
1251}
1252
Manuel Pégourié-Gonnard53fb66d2020-06-04 09:43:14 +02001253component_test_ecp_restartable_no_internal_rng () {
1254 msg "build: Default plus ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG"
1255 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1256 scripts/config.py set MBEDTLS_ECP_RESTARTABLE
1257 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1258 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1259 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1260 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
1261 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1262
1263 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1264 make
1265
1266 msg "test: ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG module"
1267 make test
1268
1269 # no SSL tests as they all depend on having a DRBG
1270}
1271
Przemek Stekiele5352702022-10-05 11:37:54 +02001272component_test_tls1_2_default_stream_cipher_only () {
1273 msg "build: default with only stream cipher"
1274
1275 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
1276 scripts/config.py unset MBEDTLS_GCM_C
1277 scripts/config.py unset MBEDTLS_CCM_C
1278 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1279 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1280 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1281 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1282 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1283 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1284 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1285 # Modules that depend on AEAD
1286 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001287 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001288
1289 make
1290
1291 msg "test: default with only stream cipher"
1292 make test
1293
1294 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1295}
1296
1297component_test_tls1_2_default_stream_cipher_only_use_psa () {
1298 msg "build: default with only stream cipher use psa"
1299
1300 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1301 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1302 scripts/config.py unset MBEDTLS_GCM_C
1303 scripts/config.py unset MBEDTLS_CCM_C
1304 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1305 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1306 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1307 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1308 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1309 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1310 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1311 # Modules that depend on AEAD
1312 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001313 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001314
1315 make
1316
1317 msg "test: default with only stream cipher use psa"
1318 make test
1319
1320 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1321}
1322
1323component_test_tls1_2_default_cbc_legacy_cipher_only () {
1324 msg "build: default with only CBC-legacy cipher"
1325
1326 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1327 scripts/config.py unset MBEDTLS_GCM_C
1328 scripts/config.py unset MBEDTLS_CCM_C
1329 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1330 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1331 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1332 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1333 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1334 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1335 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1336 # Modules that depend on AEAD
1337 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001338 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001339
1340 make
1341
1342 msg "test: default with only CBC-legacy cipher"
1343 make test
1344
1345 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1346 tests/ssl-opt.sh -f "TLS 1.2"
1347}
1348
1349component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
1350 msg "build: default with only CBC-legacy cipher use psa"
1351
1352 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1353 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1354 scripts/config.py unset MBEDTLS_GCM_C
1355 scripts/config.py unset MBEDTLS_CCM_C
1356 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1357 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1358 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1359 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1360 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1361 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1362 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1363 # Modules that depend on AEAD
1364 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001365 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001366
1367 make
1368
1369 msg "test: default with only CBC-legacy cipher use psa"
1370 make test
1371
1372 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1373 tests/ssl-opt.sh -f "TLS 1.2"
1374}
1375
1376component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
1377 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1378
1379 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1380 scripts/config.py unset MBEDTLS_GCM_C
1381 scripts/config.py unset MBEDTLS_CCM_C
1382 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1383 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1384 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1385 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1386 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1387 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1388 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1389 # Modules that depend on AEAD
1390 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001391 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001392
1393 make
1394
1395 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1396 make test
1397
1398 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1399 tests/ssl-opt.sh -f "TLS 1.2"
1400}
1401
1402component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
1403 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
1404
1405 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1406 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1407 scripts/config.py unset MBEDTLS_GCM_C
1408 scripts/config.py unset MBEDTLS_CCM_C
1409 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1410 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1411 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1412 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1413 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1414 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1415 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1416 # Modules that depend on AEAD
1417 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001418 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001419
1420 make
1421
1422 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
1423 make test
1424
1425 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
1426 tests/ssl-opt.sh -f "TLS 1.2"
1427}
1428
Gilles Peskine636c26a2020-03-04 20:46:15 +01001429component_test_new_ecdh_context () {
1430 msg "build: new ECDH context (ASan build)" # ~ 6 min
1431 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1432 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1433 make
1434
1435 msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1436 make test
1437
1438 msg "test: new ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001439 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001440
1441 msg "test: new ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1442 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001443 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001444}
1445
1446component_test_everest () {
1447 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
1448 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1449 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1450 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1451 make
1452
1453 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1454 make test
1455
1456 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001457 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001458
1459 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1460 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001461 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001462}
1463
Gilles Peskined3beca92020-07-03 00:15:37 +02001464component_test_everest_curve25519_only () {
1465 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
1466 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1467 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1468 scripts/config.py unset MBEDTLS_ECDSA_C
1469 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1470 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1471 # Disable all curves
1472 for c in $(sed -n 's/#define \(MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED\).*/\1/p' <"$CONFIG_H"); do
1473 scripts/config.py unset "$c"
1474 done
1475 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1476
1477 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1478
1479 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1480 make test
1481}
1482
Gilles Peskine8f073122018-11-27 15:58:47 +01001483component_test_small_ssl_out_content_len () {
1484 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001485 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1486 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001487 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1488 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001489
Gilles Peskine8f073122018-11-27 15:58:47 +01001490 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001491 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001492}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001493
Gilles Peskine8f073122018-11-27 15:58:47 +01001494component_test_small_ssl_in_content_len () {
1495 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001496 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1497 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001498 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1499 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001500
Gilles Peskine8f073122018-11-27 15:58:47 +01001501 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001502 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001503}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001504
Gilles Peskine8f073122018-11-27 15:58:47 +01001505component_test_small_ssl_dtls_max_buffering () {
1506 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001507 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001508 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1509 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001510
Gilles Peskine8f073122018-11-27 15:58:47 +01001511 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001512 tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
Gilles Peskine8f073122018-11-27 15:58:47 +01001513}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001514
Gilles Peskine8f073122018-11-27 15:58:47 +01001515component_test_small_mbedtls_ssl_dtls_max_buffering () {
1516 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001517 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001518 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1519 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001520
Gilles Peskine8f073122018-11-27 15:58:47 +01001521 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001522 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001523}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001524
Gilles Peskine75cc7712019-09-06 19:47:17 +02001525component_test_psa_collect_statuses () {
1526 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001527 scripts/config.py full
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001528 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001529 # Check that psa_crypto_init() succeeded at least once
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001530 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001531 rm -f tests/statuses.log
1532}
1533
Gilles Peskine8f073122018-11-27 15:58:47 +01001534component_test_full_cmake_clang () {
1535 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001536 scripts/config.py full
Gilles Peskine83264be2022-10-30 21:02:40 +01001537 CC=clang CXX=clang cmake -D CMAKE_BUILD_TYPE:String=Release -D ENABLE_TESTING=On -D TEST_CPP=1 .
Gilles Peskine8f073122018-11-27 15:58:47 +01001538 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001539
k-stachowiak0291cb72019-06-26 15:52:12 +02001540 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001541 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001542
Gilles Peskine83264be2022-10-30 21:02:40 +01001543 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
1544 programs/test/cpp_dummy_build
1545
k-stachowiak0291cb72019-06-26 15:52:12 +02001546 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001547 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001548
Gilles Peskine8f073122018-11-27 15:58:47 +01001549 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001550 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001551
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +00001552 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001553 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 +02001554
Gilles Peskine8f073122018-11-27 15:58:47 +01001555 msg "test: compat.sh ARIA + ChachaPoly"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001556 env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001557}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001558
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001559component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001560 # This tests both (1) accesses to undefined memory, and (2) branches or
1561 # memory access depending on secret values. To distinguish between those:
1562 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1563 # - or alternatively, change the build type to MemSanDbg, which enables
1564 # origin tracking and nicer stack traces (which are useful for debugging
1565 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1566 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001567 scripts/config.py full
1568 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1569 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1570 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1571 make
1572
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001573 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001574 make test
1575}
1576
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001577component_test_valgrind_constant_flow () {
1578 # This tests both (1) everything that valgrind's memcheck usually checks
1579 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1580 # etc.) and (2) branches or memory access depending on secret values,
1581 # which will be reported as uninitialized memory. To distinguish between
1582 # secret and actually uninitialized:
1583 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1584 # - or alternatively, build with debug info and manually run the offending
1585 # test suite with valgrind --track-origins=yes, then check if the origin
1586 # was TEST_CF_SECRET() or something else.
1587 msg "build: cmake release GCC, full config with constant flow testing"
1588 scripts/config.py full
1589 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
1590 cmake -D CMAKE_BUILD_TYPE:String=Release .
1591 make
1592
1593 # this only shows a summary of the results (how many of each type)
1594 # details are left in Testing/<date>/DynamicAnalysis.xml
1595 msg "test: main suites (valgrind + constant flow)"
1596 make memcheck
1597}
1598
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001599component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02001600 # Test that removing the deprecated features from the default
1601 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001602 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1603 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1604 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1605
1606 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1607 make test
1608}
1609
1610component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02001611 msg "build: make, full_no_deprecated config" # ~ 30s
1612 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001613 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1614
Gilles Peskine30de2e82020-04-20 21:39:22 +02001615 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001616 make test
1617}
1618
Gilles Peskine8386ea22020-04-30 09:07:29 +02001619component_test_full_no_deprecated_deprecated_warning () {
1620 # Test that there is nothing deprecated in "full_no_deprecated".
1621 # A deprecated feature would trigger a warning (made fatal) from
1622 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02001623 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1624 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001625 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
1626 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
1627 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1628
Gilles Peskine30de2e82020-04-20 21:39:22 +02001629 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001630 make test
1631}
1632
Gilles Peskine8386ea22020-04-30 09:07:29 +02001633component_test_full_deprecated_warning () {
1634 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
1635 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001636 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001637 scripts/config.py full
1638 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001639 # Expect warnings from '#warning' directives in check_config.h.
1640 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001641
Gilles Peskine8386ea22020-04-30 09:07:29 +02001642 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1643 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
1644 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001645 # Expect warnings from '#warning' directives in check_config.h and
1646 # from the use of deprecated functions in test suites.
1647 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 +01001648
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001649 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
1650 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001651}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00001652
Gilles Peskineec541fe2020-01-31 14:24:14 +01001653# Check that the specified libraries exist and are empty.
1654are_empty_libraries () {
1655 nm "$@" >/dev/null 2>/dev/null
1656 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
1657}
1658
1659component_build_crypto_default () {
1660 msg "build: make, crypto only"
1661 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01001662 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001663 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001664}
1665
1666component_build_crypto_full () {
1667 msg "build: make, crypto only, full config"
1668 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01001669 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001670 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001671}
1672
Gilles Peskine8df27482022-10-21 19:34:54 +02001673component_test_crypto_for_psa_service () {
Gilles Peskine21503df2022-10-11 21:05:06 +02001674 msg "build: make, config for PSA crypto service"
1675 scripts/config.py crypto
1676 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1677 # Disable things that are not needed for just cryptography, to
1678 # reach a configuration that would be typical for a PSA cryptography
1679 # service providing all implemented PSA algorithms.
1680 # System stuff
1681 scripts/config.py unset MBEDTLS_ERROR_C
1682 scripts/config.py unset MBEDTLS_TIMING_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001683 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskine21503df2022-10-11 21:05:06 +02001684 # Crypto stuff with no PSA interface
1685 scripts/config.py unset MBEDTLS_BASE64_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001686 scripts/config.py unset MBEDTLS_BLOWFISH_C
1687 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
1688 # Keep MBEDTLS_MD_C because RSA and ECDSA need it, also HMAC_DRBG which
1689 # is needed for deterministic ECDSA.
1690 scripts/config.py unset MBEDTLS_ECJPAKE_C
1691 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
Gilles Peskine21503df2022-10-11 21:05:06 +02001692 scripts/config.py unset MBEDTLS_NIST_KW_C
1693 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1694 scripts/config.py unset MBEDTLS_PEM_WRITE_C
1695 scripts/config.py unset MBEDTLS_PKCS12_C
1696 scripts/config.py unset MBEDTLS_PKCS5_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001697 # We keep MBEDTLS_PK_{,PARSE,WRITE}_C because PSA with RSA needs it.
1698 scripts/config.py unset MBEDTLS_XTEA_C
Gilles Peskine21503df2022-10-11 21:05:06 +02001699 make CFLAGS='-O1 -Werror' all test
1700 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1701}
1702
Gilles Peskineec541fe2020-01-31 14:24:14 +01001703component_build_crypto_baremetal () {
1704 msg "build: make, crypto only, baremetal config"
1705 scripts/config.py crypto_baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001706 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001707 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001708}
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001709support_build_crypto_baremetal () {
Daniel Axtens1a021af2020-08-31 14:22:58 +10001710 support_build_baremetal "$@"
1711}
1712
1713component_build_baremetal () {
1714 msg "build: make, baremetal config"
1715 scripts/config.py baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001716 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Daniel Axtens1a021af2020-08-31 14:22:58 +10001717}
1718support_build_baremetal () {
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001719 # Older Glibc versions include time.h from other headers such as stdlib.h,
1720 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
1721 # problem, Ubuntu 18.04 is ok.
1722 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
1723}
Gilles Peskineec541fe2020-01-31 14:24:14 +01001724
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001725# depends.py family of tests
Andrzej Kurek85d69302022-10-05 09:14:07 -04001726component_test_depends_py_cipher_id () {
1727 msg "test/build: depends.py cipher_id (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001728 tests/scripts/depends.py cipher_id --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001729}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001730
Andrzej Kurek85d69302022-10-05 09:14:07 -04001731component_test_depends_py_cipher_chaining () {
1732 msg "test/build: depends.py cipher_chaining (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001733 tests/scripts/depends.py cipher_chaining --unset-use-psa
John Durkopc14be902020-08-20 06:16:41 -07001734}
1735
Andrzej Kurek85d69302022-10-05 09:14:07 -04001736component_test_depends_py_cipher_padding () {
1737 msg "test/build: depends.py cipher_padding (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001738 tests/scripts/depends.py cipher_padding --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001739}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001740
Andrzej Kurek85d69302022-10-05 09:14:07 -04001741component_test_depends_py_curves () {
1742 msg "test/build: depends.py curves (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001743 tests/scripts/depends.py curves --unset-use-psa
John Durkop2ec2eaa2020-08-24 18:29:15 -07001744}
1745
Andrzej Kurek85d69302022-10-05 09:14:07 -04001746component_test_depends_py_hashes () {
1747 msg "test/build: depends.py hashes (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001748 tests/scripts/depends.py hashes --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001749}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001750
Andrzej Kurek85d69302022-10-05 09:14:07 -04001751component_test_depends_py_kex () {
1752 msg "test/build: depends.py kex (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001753 tests/scripts/depends.py kex --unset-use-psa
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001754}
1755
Andrzej Kurek85d69302022-10-05 09:14:07 -04001756component_test_depends_py_pkalgs () {
1757 msg "test/build: depends.py pkalgs (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001758 tests/scripts/depends.py pkalgs --unset-use-psa
1759}
1760
1761# PSA equivalents of the depends.py tests
1762component_test_depends_py_cipher_id_psa () {
1763 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1764 tests/scripts/depends.py cipher_id
1765}
1766
1767component_test_depends_py_cipher_chaining_psa () {
1768 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1769 tests/scripts/depends.py cipher_chaining
1770}
1771
1772component_test_depends_py_cipher_padding_psa () {
1773 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1774 tests/scripts/depends.py cipher_padding
1775}
1776
1777component_test_depends_py_curves_psa () {
1778 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1779 tests/scripts/depends.py curves
1780}
1781
1782component_test_depends_py_hashes_psa () {
1783 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1784 tests/scripts/depends.py hashes
1785}
1786
1787component_test_depends_py_kex_psa () {
1788 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1789 tests/scripts/depends.py kex
1790}
1791
1792component_test_depends_py_pkalgs_psa () {
1793 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Andrzej Kurek85d69302022-10-05 09:14:07 -04001794 tests/scripts/depends.py pkalgs
Gilles Peskine8f073122018-11-27 15:58:47 +01001795}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001796
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001797component_test_no_use_psa_crypto_full_cmake_asan() {
1798 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02001799 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001800 scripts/config.py full
1801 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
1802 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1803 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1804 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02001805 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001806 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01001807 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001808 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001809
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001810 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001811 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001812
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001813 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001814 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001815
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001816 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001817 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001818
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001819 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001820 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 -05001821
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001822 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001823 env OPENSSL_CMD="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001824}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001825
Ronald Crond2c53e62021-09-13 09:38:05 +02001826component_test_psa_crypto_config_accel_ecdsa () {
1827 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1828
1829 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1830 # partial support for cipher operations in the driver test library.
1831 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1832 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Gilles Peskine62de7672022-04-21 11:05:16 +02001833 # Disable obsolete hashes (alternatively we could enable support for them
1834 # in the driver test library).
1835 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1836 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
Ronald Crond2c53e62021-09-13 09:38:05 +02001837
1838 # SHA384 needed for some ECDSA signature tests.
1839 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
1840
1841 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
1842 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1843 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1844
1845 # Restore test driver base configuration
1846 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
1847
1848 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1849 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1850 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1851 scripts/config.py unset MBEDTLS_ECDSA_C
1852 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1853 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1854
1855 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
1856 make CFLAGS="$ASAN_CFLAGS -O -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
1857
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01001858 not grep mbedtls_ecdsa_ library/ecdsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02001859
1860 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1861 make test
1862}
1863
1864component_test_psa_crypto_config_accel_rsa_signature () {
1865 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
1866
1867 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1868 # partial support for cipher operations in the driver test library.
1869 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1870 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1871
1872 # It seems it is not possible to remove only the support for RSA signature
1873 # in the library. Thus we have to remove all RSA support (signature and
1874 # encryption/decryption). AS there is no driver support for asymmetric
1875 # encryption/decryption so far remove RSA encryption/decryption from the
1876 # application algorithm list.
1877 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1878 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1879
1880 # Make sure both the library and the test library support the SHA hash
1881 # algorithms and only those ones (SHA256 is included by default). That way:
1882 # - the test library can compute the RSA signatures even in the case of a
1883 # composite RSA signature algorithm based on a SHA hash (no other hash
1884 # used in the unit tests).
1885 # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
1886 # fulfilled as the hash SHA algorithm is supported by the library, and
1887 # thus the tests are run, not skipped.
1888 # - when testing a signature key with an algorithm wildcard built from
1889 # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
1890 # algorithm based on the hashes supported by the library is also
1891 # supported by the test library.
1892 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1893 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1894 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1895 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160_C
1896
1897 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA1_C
1898 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
1899 # We need PEM parsing in the test library as well to support the import
1900 # of PEM encoded RSA keys.
1901 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_PEM_PARSE_C
1902 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_BASE64_C
1903
1904 loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
1905 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1906 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1907
1908 # Restore test driver base configuration
1909 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA1_C
1910 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
1911 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_PEM_PARSE_C
1912 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_BASE64_C
1913
1914
1915 # Mbed TLS library build
1916 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1917 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1918
1919 # Remove RSA support and its dependencies
1920 scripts/config.py unset MBEDTLS_PKCS1_V15
1921 scripts/config.py unset MBEDTLS_PKCS1_V21
1922 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1923 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1924 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1925 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1926 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1927 scripts/config.py unset MBEDTLS_RSA_C
1928 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1929
1930 scripts/config.py unset MBEDTLS_MD2_C
1931 scripts/config.py unset MBEDTLS_MD4_C
1932 scripts/config.py unset MBEDTLS_MD5_C
1933 scripts/config.py unset MBEDTLS_RIPEMD160_C
1934 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
1935 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
1936 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
1937
1938 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
1939 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
1940
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01001941 not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
1942 not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02001943
1944 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
1945 make test
1946}
1947
Ronald Cronf7e483c2021-05-08 14:32:59 +02001948component_test_psa_crypto_config_accel_hash () {
1949 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
1950
1951 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1952 # partial support for cipher operations in the driver test library.
1953 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1954 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1955
1956 loc_accel_list="ALG_MD4 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
1957 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1958 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1959
1960 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1961 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1962 scripts/config.py unset MBEDTLS_MD2_C
1963 scripts/config.py unset MBEDTLS_MD4_C
1964 scripts/config.py unset MBEDTLS_MD5_C
1965 scripts/config.py unset MBEDTLS_RIPEMD160_C
1966 scripts/config.py unset MBEDTLS_SHA1_C
1967 # Don't unset MBEDTLS_SHA256_C as it is needed by PSA crypto core.
1968 scripts/config.py unset MBEDTLS_SHA512_C
1969 # Unset MBEDTLS_SSL_PROTO_SSL3, MBEDTLS_SSL_PROTO_TLS1 and MBEDTLS_SSL_PROTO_TLS1_1 as they depend on MBEDTLS_SHA1_C
1970 scripts/config.py unset MBEDTLS_SSL_PROTO_SSL3
1971 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
1972 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
1973 # Unset MBEDTLS_SSL_CBC_RECORD_SPLITTING as it depends on MBEDTLS_SSL_PROTO_TLS1 in the default configuration.
1974 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
1975 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
1976 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
1977
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01001978 not grep mbedtls_sha512_init library/sha512.o
1979 not grep mbedtls_sha1_init library/sha1.o
Ronald Cronf7e483c2021-05-08 14:32:59 +02001980
1981 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
1982 make test
1983}
1984
Ronald Cron09623702021-10-18 11:26:01 +02001985component_test_psa_crypto_config_accel_cipher () {
1986 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
1987
Gilles Peskine186331872022-04-12 15:58:03 +02001988 # This test case focuses on cipher+AEAD. We don't yet support all
1989 # combinations of configurations, so deactivate block-cipher-based MACs.
1990 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CMAC
1991
Ronald Cron09623702021-10-18 11:26:01 +02001992 loc_accel_list="ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB ALG_OFB ALG_XTS KEY_TYPE_DES"
1993 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1994 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1995
1996 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1997 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1998
1999 # There is no intended accelerator support for ALG STREAM_CIPHER and
2000 # ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
2001 # inclusion of the Mbed TLS cipher operations. As we want to test here with
2002 # cipher operations solely supported by accelerators, disabled those
2003 # PSA configuration options.
2004 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2005 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Ronald Cron09623702021-10-18 11:26:01 +02002006
2007 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2008 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2009 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2010 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2011 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2012 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2013 scripts/config.py unset MBEDTLS_DES_C
2014
2015 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2016 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2017
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002018 not grep mbedtls_des* library/des.o
Ronald Cron09623702021-10-18 11:26:01 +02002019
2020 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2021 make test
2022}
2023
Przemek Stekiel8b56f232022-10-02 20:58:39 +02002024component_test_psa_crypto_config_accel_aead () {
2025 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2026
2027 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
2028 # partial support for cipher operations in the driver test library.
2029 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2030 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
2031
2032 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2033 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2034 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2035
2036 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2037 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2038
2039 scripts/config.py unset MBEDTLS_GCM_C
2040 scripts/config.py unset MBEDTLS_CCM_C
2041 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2042 # Features that depend on AEAD
2043 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
2044 scripts/config.py unset MBEDTLS_SSL_TICKET_C
2045
2046 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2047 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2048
2049 # There's a risk of something getting re-enabled via config_psa.h
2050 # make sure it did not happen.
2051 not grep mbedtls_ccm library/ccm.o
2052 not grep mbedtls_gcm library/gcm.o
2053 not grep mbedtls_chachapoly library/chachapoly.o
2054
2055 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2056 make test
2057}
2058
John Durkop4377bf72020-10-23 01:26:57 -07002059component_test_psa_crypto_config_no_driver() {
2060 # full plus MBEDTLS_PSA_CRYPTO_CONFIG
2061 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
2062 scripts/config.py full
2063 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2064 scripts/config.py unset MBEDTLS_PSA_CRYPTO_DRIVERS
2065 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkope7012c72020-10-26 09:55:01 -07002066 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop4377bf72020-10-23 01:26:57 -07002067
2068 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
John Durkopd8959392020-09-20 23:09:17 -07002069 make test
2070}
2071
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002072component_test_psa_crypto_config_chachapoly_disabled() {
2073 # full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305
2074 msg "build: full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305"
2075 scripts/config.py full
2076 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2077 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_GCM
2078 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CHACHA20_POLY1305
2079 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
2080
2081 msg "test: full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305"
2082 make test
2083}
2084
John Durkopd0321952020-10-29 21:37:36 -07002085# 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 -08002086component_build_psa_accel_alg_ecdh() {
John Durkopd0321952020-10-29 21:37:36 -07002087 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_ECDH
2088 # without MBEDTLS_ECDH_C
2089 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
2090 scripts/config.py full
2091 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2092 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2093 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2094 scripts/config.py unset MBEDTLS_ECDH_C
2095 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2096 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2097 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2098 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2099 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2100 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2101 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2102}
2103
John Durkopf4c4cb02020-10-28 20:09:55 -07002104# 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 -08002105component_build_psa_accel_key_type_ecc_key_pair() {
John Durkop9814fa22020-11-04 12:28:15 -08002106 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
2107 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR"
John Durkopf4c4cb02020-10-28 20:09:55 -07002108 scripts/config.py full
2109 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2110 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2111 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002112 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 -08002113 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 -07002114 # 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 -08002115 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 -07002116}
2117
2118# 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 -08002119component_build_psa_accel_key_type_ecc_public_key() {
John Durkop9814fa22020-11-04 12:28:15 -08002120 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY
2121 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
John Durkopf4c4cb02020-10-28 20:09:55 -07002122 scripts/config.py full
2123 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2124 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2125 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002126 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
2127 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
John Durkopf4c4cb02020-10-28 20:09:55 -07002128 # 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 -08002129 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 -07002130}
2131
John Durkopd0321952020-10-29 21:37:36 -07002132# 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 -08002133component_build_psa_accel_alg_hmac() {
John Durkopd0321952020-10-29 21:37:36 -07002134 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HMAC
2135 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HMAC"
2136 scripts/config.py full
2137 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2138 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2139 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2140 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2141 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2142}
2143
2144# 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 -08002145component_build_psa_accel_alg_hkdf() {
John Durkopd0321952020-10-29 21:37:36 -07002146 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HKDF
2147 # without MBEDTLS_HKDF_C
2148 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
2149 scripts/config.py full
2150 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2151 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2152 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2153 scripts/config.py unset MBEDTLS_HKDF_C
John Durkopbd069d32020-10-31 22:14:03 -07002154 # Make sure to unset TLS1_3_EXPERIMENTAL since it requires HKDF_C and will not build properly without it.
2155 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
John Durkopd0321952020-10-29 21:37:36 -07002156 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2157 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2158}
2159
John Durkop1b7ee052020-11-27 08:51:22 -08002160# This should be renamed to test and updated once the accelerator MD2 code is in place and ready to test.
2161component_build_psa_accel_alg_md2() {
2162 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD2 without other hashes
2163 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD2 - other hashes"
2164 scripts/config.py full
2165 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2166 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2167 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2168 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2169 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2170 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2171 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2172 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2173 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2174 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2175 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2176 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2177 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD2 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2178}
2179
2180# This should be renamed to test and updated once the accelerator MD4 code is in place and ready to test.
2181component_build_psa_accel_alg_md4() {
2182 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD4 without other hashes
2183 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD4 - other hashes"
2184 scripts/config.py full
2185 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2186 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2187 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2188 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2189 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2190 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2191 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2192 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2193 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2194 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2195 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2196 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2197 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD4 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2198}
2199
2200# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
2201component_build_psa_accel_alg_md5() {
2202 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD5 without other hashes
2203 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD5 - other hashes"
2204 scripts/config.py full
2205 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2206 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2207 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2208 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2209 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2210 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2211 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2212 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2213 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2214 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2215 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2216 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2217 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2218}
2219
2220# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
2221component_build_psa_accel_alg_ripemd160() {
2222 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RIPEMD160 without other hashes
2223 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RIPEMD160 - other hashes"
2224 scripts/config.py full
2225 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2226 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2227 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2228 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2229 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2230 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2231 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2232 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2233 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2234 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2235 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2236 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2237 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2238}
2239
2240# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
2241component_build_psa_accel_alg_sha1() {
2242 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_1 without other hashes
2243 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_1 - other hashes"
2244 scripts/config.py full
2245 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2246 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2247 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2248 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2249 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2250 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2251 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2252 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2253 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2254 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2255 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2256 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2257 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2258}
2259
2260# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
2261component_build_psa_accel_alg_sha224() {
2262 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_224 without other hashes
2263 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_224 - other hashes"
2264 scripts/config.py full
2265 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2266 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2267 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2268 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2269 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2270 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2271 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2272 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2273 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2274 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2275 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2276 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2277}
2278
2279# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
2280component_build_psa_accel_alg_sha256() {
2281 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_256 without other hashes
2282 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_256 - other hashes"
2283 scripts/config.py full
2284 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2285 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2286 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2287 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2288 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2289 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2290 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2291 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2292 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2293 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2294 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2295 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2296 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2297}
2298
2299# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
2300component_build_psa_accel_alg_sha384() {
2301 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_384 without other hashes
2302 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_384 - other hashes"
2303 scripts/config.py full
2304 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2305 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2306 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2307 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2308 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2309 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2310 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2311 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2312 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2313 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2314 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2315 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2316}
2317
2318# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
2319component_build_psa_accel_alg_sha512() {
2320 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_512 without other hashes
2321 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_512 - other hashes"
2322 scripts/config.py full
2323 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2324 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2325 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2326 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2327 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2328 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2329 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2330 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2331 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2332 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2333 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2334 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2335 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2336}
2337
John Durkopd0321952020-10-29 21:37:36 -07002338# 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 -08002339component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
John Durkopbd069d32020-10-31 22:14:03 -07002340 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2341 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 -07002342 scripts/config.py full
2343 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2344 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2345 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkopbd069d32020-10-31 22:14:03 -07002346 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002347 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2348 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2349 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07002350 # 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 -07002351 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2352}
2353
2354# 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 -08002355component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
John Durkopbd069d32020-10-31 22:14:03 -07002356 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_SIGN and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
2357 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2358 scripts/config.py full
2359 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2360 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2361 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2362 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002363 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2364 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2365 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002366 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2367 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2368}
2369
2370# 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 -08002371component_build_psa_accel_alg_rsa_oaep() {
John Durkopbd069d32020-10-31 22:14:03 -07002372 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_OAEP and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
2373 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2374 scripts/config.py full
2375 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2376 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2377 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2378 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_OAEP 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002379 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2380 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2381 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002382 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2383 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2384}
2385
2386# 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 -08002387component_build_psa_accel_alg_rsa_pss() {
John Durkopbd069d32020-10-31 22:14:03 -07002388 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PSS and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
2389 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2390 scripts/config.py full
2391 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2392 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2393 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2394 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002395 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2396 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2397 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07002398 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2399 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2400}
2401
2402# 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 -08002403component_build_psa_accel_key_type_rsa_key_pair() {
John Durkopbd069d32020-10-31 22:14:03 -07002404 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_KEY_PAIR and PSA_WANT_ALG_RSA_PSS
2405 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR + PSA_WANT_ALG_RSA_PSS"
2406 scripts/config.py full
2407 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2408 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2409 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2410 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2411 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
2412 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2413 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"
2414}
2415
2416# 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 -08002417component_build_psa_accel_key_type_rsa_public_key() {
John Durkopbd069d32020-10-31 22:14:03 -07002418 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY and PSA_WANT_ALG_RSA_PSS
2419 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
2420 scripts/config.py full
2421 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2422 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2423 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2424 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2425 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
2426 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2427 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 -07002428}
2429
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002430component_test_check_params_functionality () {
2431 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002432 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002433 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002434 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Ronald Crona1236142020-07-01 16:01:21 +02002435 make CC=gcc CFLAGS='-Werror -O1' all test
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002436}
2437
Gilles Peskineb28636b2019-01-02 19:06:24 +01002438component_test_check_params_without_platform () {
2439 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002440 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002441 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002442 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
2443 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
2444 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
2445 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
Gilles Peskine32e889d2020-04-12 23:43:28 +02002446 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002447 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
2448 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskine9c764bf2022-09-18 14:05:23 +02002449 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002450 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
2451 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +01002452 make CC=gcc CFLAGS='-Werror -O1' all test
2453}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002454
Gilles Peskineb28636b2019-01-02 19:06:24 +01002455component_test_check_params_silent () {
2456 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002457 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002458 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01002459 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
2460 make CC=gcc CFLAGS='-Werror -O1' all test
2461}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002462
Gilles Peskine8f073122018-11-27 15:58:47 +01002463component_test_no_platform () {
2464 # Full configuration build, without platform support, file IO and net sockets.
2465 # This should catch missing mbedtls_printf definitions, and by disabling file
2466 # IO, it should catch missing '#include <stdio.h>'
2467 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002468 scripts/config.py full
2469 scripts/config.py unset MBEDTLS_PLATFORM_C
2470 scripts/config.py unset MBEDTLS_NET_C
2471 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
2472 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
2473 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
2474 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskine9c764bf2022-09-18 14:05:23 +02002475 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002476 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
2477 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskine32e889d2020-04-12 23:43:28 +02002478 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002479 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
2480 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002481 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002482 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
2483 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01002484 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
2485 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002486 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
2487 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01002488}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00002489
Gilles Peskine8f073122018-11-27 15:58:47 +01002490component_build_no_std_function () {
2491 # catch compile bugs in _uninit functions
2492 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002493 scripts/config.py full
2494 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
2495 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002496 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine31fdda12021-10-08 11:45:47 +02002497 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskine25319702021-10-07 19:34:57 +02002498 make
Gilles Peskine8f073122018-11-27 15:58:47 +01002499}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01002500
Gilles Peskine8f073122018-11-27 15:58:47 +01002501component_build_no_ssl_srv () {
2502 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002503 scripts/config.py full
2504 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002505 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002506}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002507
Gilles Peskine8f073122018-11-27 15:58:47 +01002508component_build_no_ssl_cli () {
2509 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002510 scripts/config.py full
2511 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002512 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002513}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002514
Gilles Peskine8f073122018-11-27 15:58:47 +01002515component_build_no_sockets () {
2516 # Note, C99 compliance can also be tested with the sockets support disabled,
2517 # as that requires a POSIX platform (which isn't the same as C99).
2518 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002519 scripts/config.py full
2520 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
2521 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002522 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01002523}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02002524
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002525component_test_memory_buffer_allocator_backtrace () {
2526 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002527 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2528 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2529 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
2530 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Gilles Peskineff30bd02021-10-19 21:33:32 +02002531 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002532 make
2533
2534 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
2535 make test
2536}
2537
2538component_test_memory_buffer_allocator () {
2539 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002540 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2541 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Gilles Peskineff30bd02021-10-19 21:33:32 +02002542 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002543 make
2544
2545 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2546 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002547
2548 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2549 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002550 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002551}
2552
Gilles Peskine8f073122018-11-27 15:58:47 +01002553component_test_no_max_fragment_length () {
2554 # Run max fragment length tests with MFL disabled
2555 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002556 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01002557 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2558 make
Hanno Becker5175ac62017-09-18 15:36:25 +01002559
Gilles Peskine8f073122018-11-27 15:58:47 +01002560 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002561 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01002562}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002563
Hanno Becker545ced42019-02-19 11:10:48 +00002564component_test_asan_remove_peer_certificate () {
2565 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002566 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00002567 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2568 make
2569
2570 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2571 make test
2572
2573 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002574 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002575
2576 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002577 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002578
2579 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002580 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002581}
2582
Gilles Peskine8f073122018-11-27 15:58:47 +01002583component_test_no_max_fragment_length_small_ssl_out_content_len () {
2584 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002585 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2586 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
2587 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01002588 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2589 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10002590
Gilles Peskine8f073122018-11-27 15:58:47 +01002591 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002592 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002593
2594 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002595 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002596}
Angus Grattonc4dd0732018-04-11 16:28:39 +10002597
Darryl Greenaad82f92019-12-02 10:53:11 +00002598component_test_variable_ssl_in_out_buffer_len () {
2599 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
2600 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2601 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2602 make
2603
2604 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2605 make test
2606
2607 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002608 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002609
2610 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002611 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002612}
2613
2614component_test_variable_ssl_in_out_buffer_len_CID () {
2615 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
2616 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2617 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
2618
2619 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2620 make
2621
2622 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
2623 make test
2624
2625 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002626 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002627
2628 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002629 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002630}
2631
2632component_test_variable_ssl_in_out_buffer_len_record_splitting () {
2633 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled (ASan build)"
2634 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2635 scripts/config.py set MBEDTLS_SSL_CBC_RECORD_SPLITTING
2636
2637 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2638 make
2639
2640 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING"
2641 make test
2642
2643 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002644 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002645
2646 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002647 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002648}
2649
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002650component_test_ssl_alloc_buffer_and_mfl () {
2651 msg "build: default config with memory buffer allocator and MFL extension"
2652 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2653 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2654 scripts/config.py set MBEDTLS_MEMORY_DEBUG
2655 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2656 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
Gilles Peskineff30bd02021-10-19 21:33:32 +02002657 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002658 make
2659
2660 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
2661 make test
2662
2663 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002664 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002665}
2666
Gilles Peskine636c26a2020-03-04 20:46:15 +01002667component_test_when_no_ciphersuites_have_mac () {
2668 msg "build: when no ciphersuites have MAC"
2669 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
2670 scripts/config.py unset MBEDTLS_ARC4_C
2671 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2672 make
2673
2674 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
2675 make test
2676
2677 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002678 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01002679}
2680
Gilles Peskine8f073122018-11-27 15:58:47 +01002681component_test_null_entropy () {
2682 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002683 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
2684 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
2685 scripts/config.py set MBEDTLS_ENTROPY_C
2686 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002687 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002688 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
2689 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00002690 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01002691 make
Janos Follath06c54002016-06-09 13:57:40 +01002692
Gilles Peskine8f073122018-11-27 15:58:47 +01002693 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
2694 make test
2695}
Janos Follath06c54002016-06-09 13:57:40 +01002696
Raoul Strackxa4e86142020-06-15 17:03:13 +02002697component_test_no_date_time () {
2698 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
2699 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
Gilles Peskine31fdda12021-10-08 11:45:47 +02002700 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Raoul Strackxa4e86142020-06-15 17:03:13 +02002701 make
2702
2703 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
2704 make test
2705}
2706
Gilles Peskine8f073122018-11-27 15:58:47 +01002707component_test_platform_calloc_macro () {
2708 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002709 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2710 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
2711 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01002712 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2713 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01002714
Gilles Peskine8f073122018-11-27 15:58:47 +01002715 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
2716 make test
2717}
Hanno Beckere5fecec2018-10-11 11:02:52 +01002718
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002719component_test_malloc_0_null () {
2720 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002721 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +02002722 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 +02002723
2724 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
2725 make test
2726
2727 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
2728 # Just the calloc selftest. "make test" ran the others as part of the
2729 # test suites.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002730 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01002731
2732 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
2733 # Run a subset of the tests. The choice is a balance between coverage
2734 # and time (including time indirectly wasted due to flaky tests).
2735 # The current choice is to skip tests whose description includes
2736 # "proxy", which is an approximation of skipping tests that use the
2737 # UDP proxy, which tend to be slower and flakier.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002738 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002739}
2740
Gilles Peskine8f073122018-11-27 15:58:47 +01002741component_test_aes_fewer_tables () {
2742 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002743 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002744 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002745
Gilles Peskine8f073122018-11-27 15:58:47 +01002746 msg "test: AES_FEWER_TABLES"
2747 make test
2748}
Hanno Becker83ebf782017-07-07 12:29:15 +01002749
Gilles Peskine8f073122018-11-27 15:58:47 +01002750component_test_aes_rom_tables () {
2751 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002752 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002753 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002754
Gilles Peskine8f073122018-11-27 15:58:47 +01002755 msg "test: AES_ROM_TABLES"
2756 make test
2757}
Hanno Becker83ebf782017-07-07 12:29:15 +01002758
Gilles Peskine8f073122018-11-27 15:58:47 +01002759component_test_aes_fewer_tables_and_rom_tables () {
2760 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002761 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2762 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002763 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002764
Gilles Peskine8f073122018-11-27 15:58:47 +01002765 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2766 make test
2767}
2768
Gilles Peskine592f5912019-10-07 18:49:32 +02002769component_test_ctr_drbg_aes_256_sha_256 () {
2770 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002771 scripts/config.py full
2772 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2773 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002774 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2775 make
2776
2777 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2778 make test
2779}
2780
2781component_test_ctr_drbg_aes_128_sha_512 () {
2782 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002783 scripts/config.py full
2784 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2785 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02002786 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2787 make
2788
2789 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2790 make test
2791}
2792
2793component_test_ctr_drbg_aes_128_sha_256 () {
2794 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002795 scripts/config.py full
2796 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2797 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2798 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002799 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2800 make
2801
2802 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2803 make test
2804}
2805
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002806component_test_se_default () {
2807 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002808 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02002809 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002810
2811 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2812 make test
2813}
2814
Steven Cooremand57203d2020-07-16 20:28:59 +02002815component_test_psa_crypto_drivers () {
Steven Cooreman55ae2172020-07-17 19:46:15 +02002816 msg "build: MBEDTLS_PSA_CRYPTO_DRIVERS w/ driver hooks"
Steven Cooreman753f9732021-03-15 11:38:44 +01002817 scripts/config.py full
Steven Cooremand57203d2020-07-16 20:28:59 +02002818 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
Steven Cooreman6801f082021-02-19 17:21:22 +01002819 scripts/config.py set MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
Gilles Peskinefe0acc62021-09-20 19:20:04 +02002820 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
2821 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002822 loc_cflags="${loc_cflags} -I../tests/include -O2"
2823
2824 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002825
Steven Cooreman753f9732021-03-15 11:38:44 +01002826 msg "test: full + MBEDTLS_PSA_CRYPTO_DRIVERS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002827 make test
2828}
2829
Gilles Peskine8f073122018-11-27 15:58:47 +01002830component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002831 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002832 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02002833 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine27482f12021-11-04 12:52:14 +01002834 programs/test/dlopen_demo.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002835}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02002836
Gilles Peskinecf740502019-07-03 20:43:05 +02002837component_test_cmake_shared () {
2838 msg "build/test: cmake shared" # ~ 2min
2839 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
2840 make
Gilles Peskine56c01612019-07-03 20:43:32 +02002841 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02002842 make test
Gilles Peskine27482f12021-11-04 12:52:14 +01002843 programs/test/dlopen_demo.sh
Gilles Peskinecf740502019-07-03 20:43:05 +02002844}
2845
Gilles Peskineec10bf12019-09-20 19:56:06 +02002846test_build_opt () {
2847 info=$1 cc=$2; shift 2
2848 for opt in "$@"; do
2849 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskinee094a182020-04-14 20:08:41 +02002850 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02002851 # We're confident enough in compilers to not run _all_ the tests,
2852 # but at least run the unit tests. In particular, runs with
2853 # optimizations use inline assembly whereas runs with -O0
2854 # skip inline assembly.
2855 make test # ~30s
2856 make clean
2857 done
2858}
2859
2860component_test_clang_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002861 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02002862 test_build_opt 'full config' clang -O0 -Os -O2
2863}
2864
2865component_test_gcc_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002866 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02002867 test_build_opt 'full config' gcc -O0 -Os -O2
2868}
2869
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02002870component_build_mbedtls_config_file () {
2871 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
Gilles Peskine6af9dc92022-04-07 20:55:57 +02002872 scripts/config.py -w full_config.h full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02002873 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
2874 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02002875 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine036a9bb2022-04-07 21:06:41 +02002876 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
2877 make clean
2878
2879 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
2880 # In the user config, disable one feature (for simplicity, pick a feature
2881 # that nothing else depends on).
2882 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
2883 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
2884 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
2885
2886 rm -f user_config.h full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002887}
2888
Gilles Peskine690a2ef2022-04-07 21:59:14 +02002889component_build_psa_config_file () {
2890 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
2891 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2892 cp "$CRYPTO_CONFIG_H" psa_test_config.h
2893 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
2894 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02002895 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine690a2ef2022-04-07 21:59:14 +02002896 programs/test/query_compile_time_config MBEDTLS_CMAC_C
2897 make clean
2898
2899 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
2900 # In the user config, disable one feature, which will reflect on the
2901 # mbedtls configuration so we can query it with query_compile_time_config.
2902 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
2903 scripts/config.py unset MBEDTLS_CMAC_C
2904 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
2905 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
2906
2907 rm -f psa_test_config.h psa_user_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002908}
2909
Gilles Peskine8f073122018-11-27 15:58:47 +01002910component_test_m32_o0 () {
Gilles Peskinea0c51fb2021-10-07 19:27:16 +02002911 # Build without optimization, so as to use portable C code (in a 32-bit
2912 # build) and not the i386-specific inline assembly.
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002913 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002914 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02002915 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01002916
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002917 msg "test: i386, make, gcc -O0 (ASan build)"
2918 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01002919}
Gilles Peskine878cf602019-01-06 20:50:38 +00002920support_test_m32_o0 () {
2921 case $(uname -m) in
2922 *64*) true;;
2923 *) false;;
2924 esac
2925}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002926
Gilles Peskine6fa69862021-10-05 09:36:03 +02002927component_test_m32_o2 () {
2928 # Build with optimization, to use the i386 specific inline assembly
2929 # and go faster for tests.
2930 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002931 scripts/config.py full
Gilles Peskine6fa69862021-10-05 09:36:03 +02002932 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002933
Gilles Peskine6fa69862021-10-05 09:36:03 +02002934 msg "test: i386, make, gcc -O2 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002935 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002936
Gilles Peskine6fa69862021-10-05 09:36:03 +02002937 msg "test ssl-opt.sh, i386, make, gcc-O2"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002938 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002939}
Gilles Peskine3daa83e2021-10-07 19:25:29 +02002940support_test_m32_o2 () {
Gilles Peskine878cf602019-01-06 20:50:38 +00002941 support_test_m32_o0 "$@"
2942}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002943
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002944component_test_m32_everest () {
2945 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002946 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
2947 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02002948 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002949
2950 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
2951 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002952
2953 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002954 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01002955
2956 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
2957 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002958 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002959}
2960support_test_m32_everest () {
2961 support_test_m32_o0 "$@"
2962}
2963
Gilles Peskine8f073122018-11-27 15:58:47 +01002964component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002965 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002966 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02002967 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002968
2969 msg "test: 64-bit ILP32, make, gcc"
2970 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01002971}
Gilles Peskine878cf602019-01-06 20:50:38 +00002972support_test_mx32 () {
2973 case $(uname -m) in
2974 amd64|x86_64) true;;
2975 *) false;;
2976 esac
2977}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002978
Peter Kolbus60c6da22018-12-27 06:59:04 -06002979component_test_min_mpi_window_size () {
2980 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002981 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06002982 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2983 make
2984
2985 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
2986 make test
2987}
2988
Gilles Peskine8f073122018-11-27 15:58:47 +01002989component_test_have_int32 () {
2990 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002991 scripts/config.py unset MBEDTLS_HAVE_ASM
2992 scripts/config.py unset MBEDTLS_AESNI_C
2993 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01002994 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01002995
Gilles Peskine8f073122018-11-27 15:58:47 +01002996 msg "test: gcc, force 32-bit bignum limbs"
2997 make test
2998}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01002999
Gilles Peskine8f073122018-11-27 15:58:47 +01003000component_test_have_int64 () {
3001 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003002 scripts/config.py unset MBEDTLS_HAVE_ASM
3003 scripts/config.py unset MBEDTLS_AESNI_C
3004 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01003005 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01003006
Gilles Peskine8f073122018-11-27 15:58:47 +01003007 msg "test: gcc, force 64-bit bignum limbs"
3008 make test
3009}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003010
Gilles Peskine8f073122018-11-27 15:58:47 +01003011component_test_no_udbl_division () {
3012 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003013 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003014 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01003015 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003016
Gilles Peskine8f073122018-11-27 15:58:47 +01003017 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
3018 make test
3019}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003020
Gilles Peskine8f073122018-11-27 15:58:47 +01003021component_test_no_64bit_multiplication () {
3022 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003023 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003024 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01003025 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003026
Gilles Peskine8f073122018-11-27 15:58:47 +01003027 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
3028 make test
3029}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003030
Gilles Peskine3809f5f2020-11-09 15:40:05 +01003031component_test_no_strings () {
3032 msg "build: no strings" # ~10s
3033 scripts/config.py full
3034 # Disable options that activate a large amount of string constants.
3035 scripts/config.py unset MBEDTLS_DEBUG_C
3036 scripts/config.py unset MBEDTLS_ERROR_C
3037 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
3038 scripts/config.py unset MBEDTLS_VERSION_FEATURES
3039 make CFLAGS='-Werror -Os'
3040
3041 msg "test: no strings" # ~ 10s
3042 make test
3043}
3044
Gilles Peskine8f073122018-11-27 15:58:47 +01003045component_build_arm_none_eabi_gcc () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003046 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003047 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02003048 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 +02003049
Gilles Peskine60d99472021-09-01 20:00:33 +02003050 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003051 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003052}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003053
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003054component_build_arm_linux_gnueabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003055 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003056 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02003057 # Build for a target platform that's close to what Debian uses
3058 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
Dave Rodgman52af7692022-03-31 14:27:24 +01003059 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003060 # Build everything including programs, see for example
Dave Rodgman52af7692022-03-31 14:27:24 +01003061 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003062 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'
3063
Gilles Peskine60d99472021-09-01 20:00:33 +02003064 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003065 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size library/*.o
3066}
3067support_build_arm_linux_gnueabi_gcc_arm5vte () {
3068 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
3069}
3070
3071component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003072 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003073 scripts/config.py baremetal
3074 # This is an imperfect substitute for
3075 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnard9a260a62021-07-06 09:44:59 +02003076 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02003077 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 +02003078
Gilles Peskine60d99472021-09-01 20:00:33 +02003079 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003080 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02003081}
3082
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003083component_build_arm_none_eabi_gcc_m0plus () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003084 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
3085 scripts/config.py baremetal_size
Gilles Peskineaeedd742020-09-02 11:03:04 +02003086 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 +02003087
Gilles Peskine60d99472021-09-01 20:00:33 +02003088 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
Gilles Peskine18487f62020-04-30 23:11:54 +02003089 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003090}
3091
Gilles Peskine8f073122018-11-27 15:58:47 +01003092component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003093 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003094 scripts/config.py baremetal
3095 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003096 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 +01003097 echo "Checking that software 64-bit division is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003098 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003099}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003100
Gilles Peskine8f073122018-11-27 15:58:47 +01003101component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003102 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003103 scripts/config.py baremetal
3104 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003105 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 +01003106 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003107 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003108}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003109
Gilles Peskine8f073122018-11-27 15:58:47 +01003110component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02003111 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003112 scripts/config.py baremetal
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003113 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02003114
3115 msg "size: ARM Compiler 5"
3116 "$ARMC5_FROMELF" -z library/*.o
3117
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003118 make clean
Andres AG87bb5772016-09-27 15:05:15 +01003119
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003120 # ARM Compiler 6 - Target ARMv7-A
3121 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003122
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003123 # ARM Compiler 6 - Target ARMv7-M
3124 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02003125
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003126 # ARM Compiler 6 - Target ARMv8-A - AArch32
3127 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003128
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003129 # ARM Compiler 6 - Target ARMv8-M
3130 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02003131
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003132 # ARM Compiler 6 - Target ARMv8-A - AArch64
3133 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01003134}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01003135
Manuel Pégourié-Gonnarddd8807f2020-02-26 09:56:27 +01003136component_build_ssl_hw_record_accel() {
3137 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
3138 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
3139 make CFLAGS='-Werror -O1'
3140}
3141
Hanno Beckera711f6e2020-05-04 12:03:51 +01003142component_test_tls13_experimental () {
3143 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3144 scripts/config.pl set MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
3145 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3146 make
3147 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3148 make test
3149}
3150
Gilles Peskine8f073122018-11-27 15:58:47 +01003151component_build_mingw () {
3152 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003153 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 +00003154
Gilles Peskine8f073122018-11-27 15:58:47 +01003155 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003156 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 +01003157 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02003158
Gilles Peskine8f073122018-11-27 15:58:47 +01003159 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003160 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
3161 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 +01003162 make WINDOWS_BUILD=1 clean
3163}
Jaeden Amero117b8a42019-04-17 15:19:26 +01003164support_build_mingw() {
3165 case $(i686-w64-mingw32-gcc -dumpversion) in
3166 [0-5]*) false;;
3167 *) true;;
3168 esac
3169}
Simon Butcher91aef332016-11-17 09:20:50 +00003170
Gilles Peskine8f073122018-11-27 15:58:47 +01003171component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003172 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003173 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003174 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
3175 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02003176
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003177 msg "test: main suites (MSan)" # ~ 10s
3178 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003179
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003180 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003181 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003182
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003183 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003184
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003185 if [ "$MEMORY" -gt 0 ]; then
3186 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003187 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003188 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003189}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003190
Gilles Peskine69f190e2019-01-10 00:11:42 +01003191component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003192 msg "build: Release (clang)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003193 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3194 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003195
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003196 msg "test: main suites valgrind (Release)"
3197 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003198
Gilles Peskine636c26a2020-03-04 20:46:15 +01003199 # Optional parts (slow; currently broken on OS X because programs don't
3200 # seem to receive signals under valgrind on OS X).
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003201 if [ "$MEMORY" -gt 0 ]; then
3202 msg "test: ssl-opt.sh --memcheck (Release)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003203 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003204 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003205
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003206 if [ "$MEMORY" -gt 1 ]; then
3207 msg "test: compat.sh --memcheck (Release)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003208 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003209 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003210
3211 if [ "$MEMORY" -gt 0 ]; then
3212 msg "test: context-info.sh --memcheck (Release)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003213 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003214 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003215}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003216
Paul Elliott2ab9a7a2021-11-25 17:29:40 +00003217support_test_cmake_out_of_source () {
3218 distrib_id=""
3219 distrib_ver=""
3220 distrib_ver_minor=""
3221 distrib_ver_major=""
3222
3223 # Attempt to parse lsb-release to find out distribution and version. If not
3224 # found this should fail safe (test is supported).
3225 if [[ -f /etc/lsb-release ]]; then
3226
3227 while read -r lsb_line; do
3228 case "$lsb_line" in
3229 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
3230 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
3231 esac
3232 done < /etc/lsb-release
3233
3234 distrib_ver_major="${distrib_ver%%.*}"
3235 distrib_ver="${distrib_ver#*.}"
3236 distrib_ver_minor="${distrib_ver%%.*}"
3237 fi
3238
3239 # Running the out of source CMake test on Ubuntu 16.04 using more than one
3240 # processor (as the CI does) can create a race condition whereby the build
3241 # fails to see a generated file, despite that file actually having been
3242 # generated. This problem appears to go away with 18.04 or newer, so make
3243 # the out of source tests unsupported on Ubuntu 16.04.
3244 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
3245}
3246
Gilles Peskine8f073122018-11-27 15:58:47 +01003247component_test_cmake_out_of_source () {
3248 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01003249 MBEDTLS_ROOT_DIR="$PWD"
3250 mkdir "$OUT_OF_SOURCE_DIR"
3251 cd "$OUT_OF_SOURCE_DIR"
Gilles Peskine25319702021-10-07 19:34:57 +02003252 cmake -D CMAKE_BUILD_TYPE:String=Check "$MBEDTLS_ROOT_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003253 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003254
Gilles Peskine8f073122018-11-27 15:58:47 +01003255 msg "test: cmake 'out-of-source' build"
3256 make test
3257 # Test an SSL option that requires an auxiliary script in test/scripts/.
3258 # Also ensure that there are no error messages such as
3259 # "No such file or directory", which would indicate that some required
3260 # file is missing (ssl-opt.sh tolerates the absence of some files so
3261 # may exit with status 0 but emit errors).
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003262 ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' >ssl-opt.out 2>ssl-opt.err
3263 grep PASS ssl-opt.out
Gilles Peskine0a7984f2020-03-28 18:56:09 +01003264 cat ssl-opt.err >&2
3265 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003266 [ ! -s ssl-opt.err ]
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003267 rm ssl-opt.out ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01003268 cd "$MBEDTLS_ROOT_DIR"
3269 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003270}
Andres AGdc192212016-08-31 17:33:13 +01003271
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003272component_test_cmake_as_subdirectory () {
3273 msg "build: cmake 'as-subdirectory' build"
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003274 cd programs/test/cmake_subproject
3275 cmake .
3276 make
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003277 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003278}
Gilles Peskineca9cfca2022-02-04 00:21:12 +01003279support_test_cmake_as_subdirectory () {
3280 support_test_cmake_out_of_source
3281}
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003282
Gilles Peskine8f073122018-11-27 15:58:47 +01003283component_test_zeroize () {
3284 # Test that the function mbedtls_platform_zeroize() is not optimized away by
3285 # different combinations of compilers and optimization flags by using an
3286 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
3287 # system in all cases that the script fails, so we must manually search the
3288 # output to check whether the pass string is present and no failure strings
3289 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01003290
Gilles Peskine4976e822019-01-06 19:52:22 +00003291 # Don't try to disable ASLR. We don't care about ASLR here. We do care
3292 # about a spurious message if Gdb tries and fails, so suppress that.
3293 gdb_disable_aslr=
3294 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
3295 gdb_disable_aslr='set disable-randomization off'
3296 fi
3297
Gilles Peskine8f073122018-11-27 15:58:47 +01003298 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01003299 for compiler in clang gcc; do
3300 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
3301 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003302 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
3303 grep "The buffer was correctly zeroized" test_zeroize.log
3304 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01003305 rm -f test_zeroize.log
3306 make clean
3307 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01003308 done
Gilles Peskine8f073122018-11-27 15:58:47 +01003309}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003310
Bence Szépkúti9f849112021-10-19 15:05:36 +02003311component_test_psa_compliance () {
Bence Szépkútic1e79fd2021-11-11 20:13:14 +01003312 msg "build: make, default config + CMAC, libmbedcrypto.a only"
3313 scripts/config.py set MBEDTLS_CMAC_C
Bence Szépkútiab796e62021-10-25 19:29:07 +02003314 make -C library libmbedcrypto.a
Bence Szépkúti9f849112021-10-19 15:05:36 +02003315
3316 msg "unit test: test_psa_compliance.py"
3317 ./tests/scripts/test_psa_compliance.py
3318}
3319
3320support_test_psa_compliance () {
Bence Szépkútid6cf0892021-11-03 11:36:09 +01003321 # psa-compliance-tests only supports CMake >= 3.10.0
Bence Szépkútiab796e62021-10-25 19:29:07 +02003322 ver="$(cmake --version)"
3323 ver="${ver#cmake version }"
3324 ver_major="${ver%%.*}"
3325
3326 ver="${ver#*.}"
3327 ver_minor="${ver%%.*}"
3328
3329 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
Bence Szépkúti9f849112021-10-19 15:05:36 +02003330}
3331
Gilles Peskine8f073122018-11-27 15:58:47 +01003332component_check_python_files () {
3333 msg "Lint: Python scripts"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003334 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003335}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003336
Gilles Peskine8f073122018-11-27 15:58:47 +01003337component_check_generate_test_code () {
3338 msg "uint test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02003339 # unittest writes out mundane stuff like number or tests run on stderr.
3340 # Our convention is to reserve stderr for actual errors, and write
3341 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003342 ./tests/scripts/test_generate_test_code.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01003343}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003344
3345################################################################
3346#### Termination
3347################################################################
3348
Gilles Peskine8f073122018-11-27 15:58:47 +01003349post_report () {
3350 msg "Done, cleaning up"
Gilles Peskine24bdf022020-03-30 20:11:39 +02003351 final_cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003352
Gilles Peskine8f073122018-11-27 15:58:47 +01003353 final_report
3354}
3355
3356
3357
3358################################################################
3359#### Run all the things
3360################################################################
3361
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003362# Function invoked by --error-test to test error reporting.
3363pseudo_component_error_test () {
Gilles Peskine202e9b42021-08-02 23:28:00 +02003364 msg "Testing error reporting $error_test_i"
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003365 if [ $KEEP_GOING -ne 0 ]; then
3366 echo "Expect three failing commands."
3367 fi
Gilles Peskine202e9b42021-08-02 23:28:00 +02003368 # If the component doesn't run in a subshell, changing error_test_i to an
3369 # invalid integer will cause an error in the loop that runs this function.
3370 error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003371 # Expected error: 'grep non_existent /dev/null -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003372 grep non_existent /dev/null
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003373 # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003374 not grep -q . "$0"
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003375 # Expected error: 'make unknown_target -> 2'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003376 make unknown_target
3377 false "this should not be executed"
3378}
3379
Gilles Peskinee48351a2018-11-27 16:06:30 +01003380# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01003381run_component () {
Gilles Peskineffcdeff2018-12-04 12:49:28 +01003382 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02003383 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003384
3385 # Unconditionally create a seedfile that's sufficiently long.
3386 # Do this before each component, because a previous component may
3387 # have messed it up or shortened it.
Gilles Peskinef3133362021-07-08 19:03:50 +02003388 local dd_cmd
3389 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
3390 case $OSTYPE in
3391 linux*|freebsd*|openbsd*|darwin*) dd_cmd+=(status=none)
3392 esac
3393 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003394
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003395 # Run the component in a subshell, with error trapping and output
3396 # redirection set up based on the relevant options.
Gilles Peskine7105a332020-03-28 18:50:43 +01003397 if [ $KEEP_GOING -eq 1 ]; then
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003398 # We want to keep running if the subshell fails, so 'set -e' must
3399 # be off when the subshell runs.
Gilles Peskine7105a332020-03-28 18:50:43 +01003400 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02003401 fi
Gilles Peskine7105a332020-03-28 18:50:43 +01003402 (
3403 if [ $QUIET -eq 1 ]; then
3404 # msg() will be silenced, so just print the component name here.
3405 echo "${current_component#component_}"
3406 exec >/dev/null
3407 fi
3408 if [ $KEEP_GOING -eq 1 ]; then
3409 # Keep "set -e" off, and run an ERR trap instead to record failures.
3410 set -E
3411 trap err_trap ERR
3412 fi
3413 # The next line is what runs the component
3414 "$@"
3415 if [ $KEEP_GOING -eq 1 ]; then
3416 trap - ERR
3417 exit $last_failure_status
3418 fi
3419 )
3420 component_status=$?
3421 if [ $KEEP_GOING -eq 1 ]; then
3422 set -e
3423 if [ $component_status -ne 0 ]; then
3424 failure_count=$((failure_count + 1))
3425 fi
3426 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003427
3428 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01003429 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02003430 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01003431}
3432
3433# Preliminary setup
3434pre_check_environment
3435pre_initialize_variables
3436pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01003437
Gilles Peskine878cf602019-01-06 20:50:38 +00003438pre_check_git
Gilles Peskineef64e7f2021-07-12 18:16:01 +02003439pre_restore_files
Gilles Peskine24bdf022020-03-30 20:11:39 +02003440pre_back_up
Andrzej Kurekeb508712019-02-14 07:18:59 -05003441
Gilles Peskine878cf602019-01-06 20:50:38 +00003442build_status=0
3443if [ $KEEP_GOING -eq 1 ]; then
3444 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01003445fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02003446pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00003447pre_print_configuration
3448pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003449cleanup
3450
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003451# Run the requested tests.
Gilles Peskine202e9b42021-08-02 23:28:00 +02003452for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003453 run_component pseudo_component_error_test
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003454done
Gilles Peskine202e9b42021-08-02 23:28:00 +02003455unset error_test_i
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003456for component in $RUN_COMPONENTS; do
3457 run_component "component_$component"
3458done
Gilles Peskine8f073122018-11-27 15:58:47 +01003459
3460# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00003461post_report