blob: 8356ab978e3d6af61773bbb3c80282040784920a [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
Andrzej Kurekd95b8ed2023-06-27 10:02:09 -0400191 # Platform tests have an allocation that returns null
192 export ASAN_OPTIONS="allocator_may_return_null=1"
193
Gilles Peskine878cf602019-01-06 20:50:38 +0000194 # Gather the list of available components. These are the functions
195 # defined in this script whose name starts with "component_".
Gilles Peskine3de7be82020-03-27 16:35:23 +0100196 # Parse the script with sed. This way we get the functions in the order
197 # they are defined.
Gilles Peskine878cf602019-01-06 20:50:38 +0000198 ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0")
199
200 # Exclude components that are not supported on this platform.
201 SUPPORTED_COMPONENTS=
202 for component in $ALL_COMPONENTS; do
203 case $(type "support_$component" 2>&1) in
204 *' function'*)
205 if ! support_$component; then continue; fi;;
206 esac
207 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
208 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100209}
Andres AG38495a32016-07-12 16:54:33 +0100210
Gilles Peskinea28db922019-01-10 00:05:18 +0100211# Test whether the component $1 is included in the command line patterns.
212is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100213{
Gilles Peskine6702ce92021-08-06 11:35:17 +0200214 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
215 # only does word splitting.
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100216 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000217 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100218 set +f
219 case ${1#component_} in $pattern) return 0;; esac
220 done
221 set +f
222 return 1
223}
Andres AG7770ea82016-10-10 15:46:20 +0100224
Simon Butcher41eeccf2016-09-07 00:07:09 +0100225usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100226{
Gilles Peskine709346a2017-12-10 23:43:39 +0100227 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100228Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100229Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100230By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100231COMPONENT can be the name of a component or a shell wildcard pattern.
232
233Examples:
234 $0 "check_*"
235 Run all sanity checks.
236 $0 --no-armcc --except test_memsan
237 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100238
239Special options:
240 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000241 --list-all-components List all available test components and exit.
242 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100243
244General options:
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200245 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100246 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100247 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100248 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200249 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200250 --arm-none-eabi-gcc-prefix=<string>
251 Prefix for a cross-compiler for arm-none-eabi
252 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200253 --arm-linux-gnueabi-gcc-prefix=<string>
254 Prefix for a cross-compiler for arm-linux-gnueabi
255 (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100256 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200257 --restore First clean up the build tree, restoring backed up
258 files. Do not run any components unless they are
259 explicitly specified.
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100260 --error-test Error test mode: run a failing function in addition
Gilles Peskinea25c5672021-08-05 15:11:33 +0200261 to any specified component. May be repeated.
Gilles Peskinea28db922019-01-10 00:05:18 +0100262 --except Exclude the COMPONENTs listed on the command line,
263 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200264 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100265 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100266 --no-force Refuse to overwrite modified files (default).
267 --no-keep-going Stop at the first error (default).
268 --no-memory No additional memory tests (default).
Shaun Case0e7791f2021-12-20 21:14:10 -0800269 --no-quiet Print full output from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100270 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200271 --outcome-file=<path> File where test outcomes are written (not done if
272 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100273 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200274 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100275 -s|--seed Integer seed value to use for this test run.
276
277Tool path options:
278 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
279 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
280 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
281 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
282 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
283 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
284 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
285 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100286 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100287EOF
SimonB2e23c822016-04-16 21:54:39 +0100288}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100289
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200290# Cleanup before/after running a component.
291# Remove built files as well as the cmake cache/config.
292# Does not remove generated source files.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100293cleanup()
294{
Gilles Peskine7c652162017-12-11 00:01:40 +0100295 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200296
Gilles Peskine31b07e22018-03-21 12:15:06 +0100297 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000298 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100299 -iname CMakeFiles -exec rm -rf {} \+ -o \
300 \( -iname cmake_install.cmake -o \
301 -iname CTestTestfile.cmake -o \
302 -iname CMakeCache.txt \) -exec rm {} \+
303 # Recover files overwritten by in-tree CMake builds
Gilles Peskine79598582022-08-30 21:02:44 +0200304 rm -f include/Makefile include/mbedtls/Makefile programs/!(fuzz)/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200305
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100306 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
307 rm -rf programs/test/cmake_subproject/build
308 rm -f programs/test/cmake_subproject/Makefile
309 rm -f programs/test/cmake_subproject/cmake_subproject
310
Gilles Peskine24bdf022020-03-30 20:11:39 +0200311 # Restore files that may have been clobbered by the job
312 for x in $files_to_back_up; do
Gilles Peskine423dd132022-08-30 21:02:00 +0200313 if [[ -e "$x$backup_suffix" ]]; then
314 cp -p "$x$backup_suffix" "$x"
315 fi
Gilles Peskine24bdf022020-03-30 20:11:39 +0200316 done
317}
John Durkopbd069d32020-10-31 22:14:03 -0700318
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200319# Final cleanup when this script exits (except when exiting on a failure
320# in non-keep-going mode).
Gilles Peskine24bdf022020-03-30 20:11:39 +0200321final_cleanup () {
322 cleanup
323
324 for x in $files_to_back_up; do
325 rm -f "$x$backup_suffix"
326 done
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100327}
328
Gilles Peskine7c652162017-12-11 00:01:40 +0100329# Executed on exit. May be redefined depending on command line options.
330final_report () {
331 :
332}
333
334fatal_signal () {
Gilles Peskine24bdf022020-03-30 20:11:39 +0200335 final_cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100336 final_report $1
337 trap - $1
338 kill -$1 $$
339}
340
341trap 'fatal_signal HUP' HUP
342trap 'fatal_signal INT' INT
343trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200344
Gilles Peskine85229ac2021-09-30 18:24:21 +0200345# Number of processors on this machine. Used as the default setting
346# for parallel make.
347all_sh_nproc ()
348{
349 {
350 nproc || # Linux
351 sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
352 sysctl -n hw.ncpu || # FreeBSD
353 echo 1
354 } 2>/dev/null
355}
356
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100357msg()
358{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100359 if [ -n "${current_component:-}" ]; then
360 current_section="${current_component#component_}: $1"
361 else
362 current_section="$1"
363 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200364
365 if [ $QUIET -eq 1 ]; then
366 return
367 fi
368
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100369 echo ""
370 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100371 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000372 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100373 echo "******************************************************************"
374}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100375
Gilles Peskine8f073122018-11-27 15:58:47 +0100376armc6_build_test()
377{
378 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100379
Gilles Peskine18487f62020-04-30 23:11:54 +0200380 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100381 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
Dave Rodgman6cda3d32023-03-02 13:39:04 +0000382 WARNING_CFLAGS='-Werror -xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200383
384 msg "size: ARM Compiler 6 ($FLAGS)"
385 "$ARMC6_FROMELF" -z library/*.o
386
Gilles Peskine8f073122018-11-27 15:58:47 +0100387 make clean
388}
Andres AGa5cd9732016-10-17 15:23:10 +0100389
Andres AGd9eba4b2016-08-26 14:42:14 +0100390err_msg()
391{
392 echo "$1" >&2
393}
394
395check_tools()
396{
397 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000398 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100399 err_msg "$TOOL not found!"
400 exit 1
401 fi
402 done
403}
404
Gilles Peskine8f073122018-11-27 15:58:47 +0100405pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000406 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100407 all_except=0
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100408 error_test=0
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200409 restore_first=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000410 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100411
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000412 # Note that legacy options are ignored instead of being omitted from this
413 # list of options, so invocations that worked with previous version of
414 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100415 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100416 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200417 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200418 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200419 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000420 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100421 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
422 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100423 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000424 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100425 --force|-f) FORCE=1;;
426 --gnutls-cli) shift; GNUTLS_CLI="$1";;
427 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
428 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
429 --gnutls-serv) shift; GNUTLS_SERV="$1";;
430 --help|-h) usage; exit;;
431 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000432 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
433 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100434 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200435 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000436 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100437 --no-force) FORCE=0;;
438 --no-keep-going) KEEP_GOING=0;;
439 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200440 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100441 --openssl) shift; OPENSSL="$1";;
442 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
443 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200444 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100445 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200446 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100447 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200448 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200449 --restore) restore_first=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100450 --seed|-s) shift; SEED="$1";;
451 -*)
452 echo >&2 "Unknown option: $1"
453 echo >&2 "Run $0 --help for usage."
454 exit 120
455 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000456 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100457 esac
458 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100459 done
SimonB2e23c822016-04-16 21:54:39 +0100460
Gilles Peskinea28db922019-01-10 00:05:18 +0100461 # With no list of components, run everything.
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200462 if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000463 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100464 fi
465
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000466 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
467 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100468 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000469 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100470 fi
SimonB2e23c822016-04-16 21:54:39 +0100471
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200472 # Error out if an explicitly requested component doesn't exist.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100473 if [ $all_except -eq 0 ]; then
474 unsupported=0
Gilles Peskine6702ce92021-08-06 11:35:17 +0200475 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
476 # only does word splitting.
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200477 set -f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100478 for component in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200479 set +f
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200480 # If the requested name includes a wildcard character, don't
481 # check it. Accept wildcard patterns that don't match anything.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100482 case $component in
483 *[*?\[]*) continue;;
484 esac
485 case " $SUPPORTED_COMPONENTS " in
486 *" $component "*) :;;
487 *)
488 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
489 unsupported=$((unsupported + 1));;
490 esac
491 done
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200492 set +f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100493 if [ $unsupported -ne 0 ]; then
494 exit 2
495 fi
496 fi
497
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000498 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100499 RUN_COMPONENTS=
500 for component in $SUPPORTED_COMPONENTS; do
501 if is_component_included "$component"; [ $? -eq $all_except ]; then
502 RUN_COMPONENTS="$RUN_COMPONENTS $component"
503 fi
504 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000505
506 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000507 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100508}
SimonB2e23c822016-04-16 21:54:39 +0100509
Gilles Peskine8f073122018-11-27 15:58:47 +0100510pre_check_git () {
511 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100512 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100513 git checkout-index -f -q $CONFIG_H
514 cleanup
515 else
SimonB2e23c822016-04-16 21:54:39 +0100516
Gilles Peskine8f073122018-11-27 15:58:47 +0100517 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
518 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
519 echo "You can either delete this directory manually, or force the test by rerunning"
520 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
521 exit 1
522 fi
523
Gilles Peskined1174cf2019-01-09 22:30:01 +0100524 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100525 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
526 echo "You can either delete or preserve your work, or force the test by rerunning the"
527 echo "script as: $0 --force"
528 exit 1
529 fi
SimonB2e23c822016-04-16 21:54:39 +0100530 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500531}
532
Gilles Peskineef64e7f2021-07-12 18:16:01 +0200533pre_restore_files () {
534 # If the makefiles have been generated by a framework such as cmake,
535 # restore them from git. If the makefiles look like modifications from
536 # the ones checked into git, take care not to modify them. Whatever
537 # this function leaves behind is what the script will restore before
538 # each component.
539 case "$(head -n1 Makefile)" in
540 *[Gg]enerated*)
541 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
542 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
543 ;;
544 esac
545}
546
Gilles Peskine24bdf022020-03-30 20:11:39 +0200547pre_back_up () {
548 for x in $files_to_back_up; do
549 cp -p "$x" "$x$backup_suffix"
550 done
551}
552
Gilles Peskine8f073122018-11-27 15:58:47 +0100553pre_setup_keep_going () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100554 failure_count=0 # Number of failed components
555 last_failure_status=0 # Last failure status in this component
556
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100557 # See err_trap
558 previous_failure_status=0
559 previous_failed_command=
560 previous_failure_funcall_depth=0
Gilles Peskine39a3b112020-03-28 21:27:40 +0100561 unset report_failed_command
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100562
Gilles Peskine7c652162017-12-11 00:01:40 +0100563 start_red=
564 end_color=
565 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100566 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100567 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
568 start_red=$(printf '\033[31m')
569 end_color=$(printf '\033[0m')
570 ;;
571 esac
572 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100573
574 # Keep a summary of failures in a file. We'll print it out at the end.
575 failure_summary_file=$PWD/all-sh-failures-$$.log
576 : >"$failure_summary_file"
577
578 # Whether it makes sense to keep a component going after the specified
579 # command fails (test command) or not (configure or build).
Gilles Peskine6702ce92021-08-06 11:35:17 +0200580 # This function normally receives the failing simple command
581 # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
582 # this is passed instead.
Gilles Peskine7105a332020-03-28 18:50:43 +0100583 # This doesn't have to be 100% accurate: all failures are recorded anyway.
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200584 # False positives result in running things that can't be expected to
585 # work. False negatives result in things not running after something else
586 # failed even though they might have given useful feedback.
Gilles Peskine7105a332020-03-28 18:50:43 +0100587 can_keep_going_after_failure () {
588 case "$1" in
589 "msg "*) false;;
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200590 "cd "*) false;;
591 *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
592 *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
593 *make*check*) true;;
594 "grep "*) true;;
595 "[ "*) true;;
596 "! "*) true;;
Gilles Peskine7105a332020-03-28 18:50:43 +0100597 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100598 esac
599 }
Gilles Peskine7105a332020-03-28 18:50:43 +0100600
601 # This function runs if there is any error in a component.
602 # It must either exit with a nonzero status, or set
603 # last_failure_status to a nonzero value.
604 err_trap () {
605 # Save $? (status of the failing command). This must be the very
606 # first thing, before $? is overridden.
607 last_failure_status=$?
Gilles Peskine39a3b112020-03-28 21:27:40 +0100608 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskine7105a332020-03-28 18:50:43 +0100609
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100610 if [[ $last_failure_status -eq $previous_failure_status &&
611 "$failed_command" == "$previous_failed_command" &&
612 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
613 then
614 # The same command failed twice in a row, but this time one level
615 # less deep in the function call stack. This happens when the last
616 # command of a function returns a nonzero status, and the function
617 # returns that same status. Ignore the second failure.
618 previous_failure_funcall_depth=${#FUNCNAME[@]}
619 return
620 fi
621 previous_failure_status=$last_failure_status
622 previous_failed_command=$failed_command
623 previous_failure_funcall_depth=${#FUNCNAME[@]}
624
Gilles Peskine7105a332020-03-28 18:50:43 +0100625 text="$current_section: $failed_command -> $last_failure_status"
626 echo "${start_red}^^^^$text^^^^${end_color}" >&2
627 echo "$text" >>"$failure_summary_file"
628
629 # If the command is fatal (configure or build command), stop this
630 # component. Otherwise (test command) keep the component running
631 # (run more tests from the same build).
632 if ! can_keep_going_after_failure "$failed_command"; then
633 exit $last_failure_status
634 fi
635 }
636
Gilles Peskine7c652162017-12-11 00:01:40 +0100637 final_report () {
638 if [ $failure_count -gt 0 ]; then
639 echo
640 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskine7105a332020-03-28 18:50:43 +0100641 echo "${start_red}FAILED: $failure_count components${end_color}"
642 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100643 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
644 elif [ -z "${1-}" ]; then
645 echo "SUCCESS :)"
646 fi
647 if [ -n "${1-}" ]; then
648 echo "Killed by SIG$1."
649 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100650 rm -f "$failure_summary_file"
651 if [ $failure_count -gt 0 ]; then
652 exit 1
653 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100654 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100655}
656
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200657# record_status() and if_build_succeeded() are kept temporarily for backward
658# compatibility. Don't use them in new components.
Gilles Peskine7105a332020-03-28 18:50:43 +0100659record_status () {
660 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100661}
Gilles Peskine7c652162017-12-11 00:01:40 +0100662if_build_succeeded () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100663 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100664}
665
Gilles Peskine39a3b112020-03-28 21:27:40 +0100666# '! true' does not trigger the ERR trap. Arrange to trigger it, with
667# a reasonably informative error message (not just "$@").
668not () {
669 if "$@"; then
670 report_failed_command="! $*"
671 false
672 unset report_failed_command
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200673 fi
674}
675
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200676pre_prepare_outcome_file () {
677 case "$MBEDTLS_TEST_OUTCOME_FILE" in
678 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
679 esac
680 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
681 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
682 fi
683}
684
Gilles Peskine8f073122018-11-27 15:58:47 +0100685pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200686 if [ $QUIET -eq 1 ]; then
687 return
688 fi
689
Gilles Peskine8f073122018-11-27 15:58:47 +0100690 msg "info: $0 configuration"
691 echo "MEMORY: $MEMORY"
692 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200693 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100694 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100695 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100696 echo "OPENSSL: $OPENSSL"
697 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
698 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
699 echo "GNUTLS_CLI: $GNUTLS_CLI"
700 echo "GNUTLS_SERV: $GNUTLS_SERV"
701 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
702 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
703 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
704 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
705}
Andres AG7770ea82016-10-10 15:46:20 +0100706
Andres AGd9eba4b2016-08-26 14:42:14 +0100707# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100708pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000709 # Build the list of variables to pass to output_env.sh.
710 set env
SimonB2e23c822016-04-16 21:54:39 +0100711
Gilles Peskine87964262019-01-06 22:40:00 +0000712 case " $RUN_COMPONENTS " in
713 # Require OpenSSL and GnuTLS if running any tests (as opposed to
714 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
715 # is a good enough approximation in practice.
716 *" test_"*)
717 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
718 # and ssl-opt.sh, we just export the variables they require.
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +0100719 export OPENSSL="$OPENSSL"
Gilles Peskine87964262019-01-06 22:40:00 +0000720 export GNUTLS_CLI="$GNUTLS_CLI"
721 export GNUTLS_SERV="$GNUTLS_SERV"
722 # Avoid passing --seed flag in every call to ssl-opt.sh
723 if [ -n "${SEED-}" ]; then
724 export SEED
725 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000726 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
727 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
728 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
729 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000730 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
731 "$GNUTLS_CLI" "$GNUTLS_SERV" \
732 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
733 ;;
734 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200735
Gilles Peskine87964262019-01-06 22:40:00 +0000736 case " $RUN_COMPONENTS " in
737 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
738 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100739
Gilles Peskine87964262019-01-06 22:40:00 +0000740 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200741 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000742 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100743
Gilles Peskine87964262019-01-06 22:40:00 +0000744 case " $RUN_COMPONENTS " in
745 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
746 esac
747
748 case " $RUN_COMPONENTS " in
749 *" test_zeroize "*) check_tools "gdb";;
750 esac
751
752 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000753 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000754 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
755 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200756 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000757 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
758 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200759 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
760 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
761 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000762 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000763
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200764 # past this point, no call to check_tool, only printing output
765 if [ $QUIET -eq 1 ]; then
766 return
767 fi
768
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000769 msg "info: output_env.sh"
770 case $RUN_COMPONENTS in
771 *_armcc*)
772 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
773 *) set "$@" RUN_ARMCC=0;;
774 esac
775 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100776}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100777
Gilles Peskine192c72f2017-12-21 15:59:21 +0100778
779
780################################################################
781#### Basic checks
782################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100783
784#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200785# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100786#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100787# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200788# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100789# 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 +0200790# time, so start with a GCC build).
791# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100792#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100793# Indicative running times are given for reference.
794
Gilles Peskine8f073122018-11-27 15:58:47 +0100795component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200796 msg "Check: recursion.pl" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200797 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100798}
Janos Follathb72c6782016-07-19 14:54:17 +0100799
Gilles Peskine8f073122018-11-27 15:58:47 +0100800component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200801 msg "Check: freshness of generated source files" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200802 tests/scripts/check-generated-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100803}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200804
Gilles Peskine8f073122018-11-27 15:58:47 +0100805component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200806 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200807 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +0100808}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200809
Gilles Peskine8f073122018-11-27 15:58:47 +0100810component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200811 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200812 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100813}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200814
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200815component_check_changelog () {
816 msg "Check: changelog entries" # < 1s
817 rm -f ChangeLog.new
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200818 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200819 if [ -e ChangeLog.new ]; then
820 # Show the diff for information. It isn't an error if the diff is
821 # non-empty.
822 diff -u ChangeLog ChangeLog.new || true
823 rm ChangeLog.new
824 fi
825}
826
Gilles Peskine8f073122018-11-27 15:58:47 +0100827component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200828 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200829 tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100830}
Darryl Greena07039c2018-03-13 16:48:16 +0000831
Gilles Peskine895868b2019-09-19 21:30:05 +0200832component_check_test_cases () {
833 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200834 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200835 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200836 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200837 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200838 fi
Gilles Peskine58987962022-12-15 14:46:31 +0100839 tests/scripts/check_test_cases.py -q $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200840 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +0200841}
842
Gilles Peskine8f073122018-11-27 15:58:47 +0100843component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200844 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200845 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100846}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200847
Gilles Peskine192c72f2017-12-21 15:59:21 +0100848
Gilles Peskine636c26a2020-03-04 20:46:15 +0100849
Gilles Peskine192c72f2017-12-21 15:59:21 +0100850################################################################
851#### Build and test many configurations and targets
852################################################################
853
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200854component_test_default_out_of_box () {
855 msg "build: make, default config (out-of-box)" # ~1min
856 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200857 # Disable fancy stuff
858 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200859
860 msg "test: main suites make, default config (out-of-box)" # ~10s
861 make test
862
863 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200864 programs/test/selftest
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200865}
866
Gilles Peskine8f073122018-11-27 15:58:47 +0100867component_test_default_cmake_gcc_asan () {
868 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100869 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
870 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200871
Gilles Peskine8f073122018-11-27 15:58:47 +0100872 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
873 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200874
Gilles Peskine97bea012020-04-23 23:37:45 +0200875 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200876 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200877
Gilles Peskine8f073122018-11-27 15:58:47 +0100878 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200879 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200880
Gilles Peskine8f073122018-11-27 15:58:47 +0100881 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200882 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200883
884 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200885 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100886}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200887
Hanno Becker01635512019-02-26 14:27:09 +0000888component_test_full_cmake_gcc_asan () {
889 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200890 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000891 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
892 make
893
894 msg "test: main suites (inc. selftests) (full config, ASan build)"
895 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +0100896
Gilles Peskine97bea012020-04-23 23:37:45 +0200897 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200898 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200899
Gilles Peskine636c26a2020-03-04 20:46:15 +0100900 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200901 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100902
903 msg "test: compat.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200904 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200905
906 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200907 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100908}
909
Ronald Cronc3623db2020-10-29 10:51:32 +0100910component_test_psa_crypto_key_id_encodes_owner () {
911 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
912 scripts/config.py full
913 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
914 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
915 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
916 make
917
918 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
919 make test
920}
921
Gilles Peskine99a34622021-06-17 11:37:52 +0200922# check_renamed_symbols HEADER LIB
923# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
924# name is LIB.
925check_renamed_symbols () {
926 ! nm "$2" | sed 's/.* //' |
927 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
928}
929
Gilles Peskine984c19f2021-06-15 18:37:38 +0200930component_build_psa_crypto_spm () {
931 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
932 scripts/config.py full
933 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
934 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
935 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
936 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
937 # We can only compile, not link, since our test and sample programs
938 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
939 # is active.
940 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskine99a34622021-06-17 11:37:52 +0200941
942 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
943 # version is not present.
944 echo "Checking for renamed symbols in the library"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200945 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskine984c19f2021-06-15 18:37:38 +0200946}
947
Ronald Cron336678b2021-01-28 17:54:24 +0100948component_test_psa_crypto_client () {
949 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
950 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
951 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
952 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
953 make
954
955 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
956 make test
957}
958
Gilles Peskine636c26a2020-03-04 20:46:15 +0100959component_test_zlib_make() {
960 msg "build: zlib enabled, make"
961 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine6fa69862021-10-05 09:36:03 +0200962 make ZLIB=1 CFLAGS='-Werror -O2'
Gilles Peskine636c26a2020-03-04 20:46:15 +0100963
964 msg "test: main suites (zlib, make)"
965 make test
966
967 msg "test: ssl-opt.sh (zlib, make)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200968 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100969}
970support_test_zlib_make () {
971 base=support_test_zlib_$$
972 cat <<'EOF' > ${base}.c
973#include "zlib.h"
974int main(void) { return 0; }
975EOF
976 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
977 ret=$?
978 rm -f ${base}.*
979 return $ret
980}
981
982component_test_zlib_cmake() {
983 msg "build: zlib enabled, cmake"
984 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine25319702021-10-07 19:34:57 +0200985 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Release .
Gilles Peskine636c26a2020-03-04 20:46:15 +0100986 make
987
988 msg "test: main suites (zlib, cmake)"
989 make test
990
991 msg "test: ssl-opt.sh (zlib, cmake)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200992 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100993}
994support_test_zlib_cmake () {
995 support_test_zlib_make "$@"
Manuel Pégourié-Gonnardf2e29022020-01-24 10:17:20 +0100996}
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +0100997
Jaeden Ameroc17f2932021-05-14 08:34:32 +0100998component_test_psa_crypto_rsa_no_genprime() {
999 msg "build: default config minus MBEDTLS_GENPRIME"
1000 scripts/config.py unset MBEDTLS_GENPRIME
1001 make
1002
1003 msg "test: default config minus MBEDTLS_GENPRIME"
1004 make test
1005}
1006
Gilles Peskine782f4112018-11-27 16:11:09 +01001007component_test_ref_configs () {
1008 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
1009 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001010 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +01001011}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001012
Gilles Peskine8f073122018-11-27 15:58:47 +01001013component_test_sslv3 () {
1014 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001015 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +01001016 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1017 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001018
Gilles Peskine8f073122018-11-27 15:58:47 +01001019 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
1020 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +00001021
Gilles Peskine8f073122018-11-27 15:58:47 +01001022 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Xiaofei Baif40545d2021-12-02 08:43:35 +00001023 tests/compat.sh -m 'tls1 tls1_1 tls12 dtls1 dtls12'
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001024 env OPENSSL="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +00001025
Gilles Peskine8f073122018-11-27 15:58:47 +01001026 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001027 tests/ssl-opt.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001028
1029 msg "build: SSLv3 - context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001030 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001031}
Simon Butcher3ea7f522016-03-07 23:22:10 +00001032
Gilles Peskine8f073122018-11-27 15:58:47 +01001033component_test_no_renegotiation () {
1034 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001035 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001036 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1037 make
Simon Butcher3ea7f522016-03-07 23:22:10 +00001038
Gilles Peskine8f073122018-11-27 15:58:47 +01001039 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1040 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +01001041
Gilles Peskine8f073122018-11-27 15:58:47 +01001042 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001043 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001044}
Hanno Becker134c2ab2017-10-12 15:29:50 +01001045
Gilles Peskine56194432023-02-01 18:44:11 +01001046component_test_no_certs () {
1047 msg "build: full minus MBEDTLS_CERTS_C"
1048 scripts/config.py full
1049 scripts/config.py unset MBEDTLS_CERTS_C
1050 # Quick build+test (we're checking for stray uses of the test certs,
1051 # not expecting their absence to lead to subtle problems).
1052 make
1053
1054 msg "test: full minus MBEDTLS_CERTS_C - main suites"
1055 make test
1056}
1057
Gilles Peskine636c26a2020-03-04 20:46:15 +01001058component_test_no_pem_no_fs () {
1059 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1060 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1061 scripts/config.py unset MBEDTLS_FS_IO
1062 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1063 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
1064 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1065 make
1066
1067 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1068 make test
1069
1070 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001071 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001072}
1073
Gilles Peskine8f073122018-11-27 15:58:47 +01001074component_test_rsa_no_crt () {
1075 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001076 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +01001077 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1078 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +01001079
Gilles Peskine8f073122018-11-27 15:58:47 +01001080 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1081 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001082
Gilles Peskine8f073122018-11-27 15:58:47 +01001083 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001084 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001085
Gilles Peskine8f073122018-11-27 15:58:47 +01001086 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001087 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001088
1089 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001090 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001091}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001092
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001093component_test_no_ctr_drbg_classic () {
1094 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001095 scripts/config.py full
1096 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001097 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001098
1099 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1100 make
1101
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001102 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001103 make test
1104
Gilles Peskineba749042021-01-13 20:02:03 +01001105 # In this configuration, the TLS test programs use HMAC_DRBG.
1106 # The SSL tests are slow, so run a small subset, just enough to get
1107 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001108 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001109 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001110
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001111 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001112 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001113}
1114
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001115component_test_no_ctr_drbg_use_psa () {
1116 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001117 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001118 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1119 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001120
1121 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1122 make
1123
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001124 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1125 make test
1126
1127 # In this configuration, the TLS test programs use HMAC_DRBG.
1128 # The SSL tests are slow, so run a small subset, just enough to get
1129 # confidence that the SSL code copes with HMAC_DRBG.
1130 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001131 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001132
1133 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001134 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001135}
1136
1137component_test_no_hmac_drbg_classic () {
1138 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1139 scripts/config.py full
1140 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1141 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1142 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1143
1144 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1145 make
1146
1147 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001148 make test
1149
Gilles Peskinea2224342020-11-19 22:14:34 +01001150 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1151 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1152 # instead.
1153 # Test SSL with non-deterministic ECDSA. Only test features that
1154 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001155 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001156 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001157
1158 # To save time, only test one protocol version, since this part of
1159 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001160 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001161 tests/compat.sh -m tls12 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001162}
1163
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001164component_test_no_hmac_drbg_use_psa () {
1165 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1166 scripts/config.py full
1167 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1168 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1169 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1170
1171 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1172 make
1173
1174 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1175 make test
1176
1177 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1178 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1179 # instead.
1180 # Test SSL with non-deterministic ECDSA. Only test features that
1181 # might be affected by how ECDSA signature is performed.
1182 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001183 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001184
1185 # To save time, only test one protocol version, since this part of
1186 # the protocol is identical in (D)TLS up to 1.2.
1187 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001188 tests/compat.sh -m tls12 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001189}
1190
1191component_test_psa_external_rng_no_drbg_classic () {
1192 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1193 scripts/config.py full
1194 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1195 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001196 scripts/config.py unset MBEDTLS_ENTROPY_C
1197 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1198 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001199 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1200 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1201 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1202 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001203 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1204 # the SSL test programs don't have an RNG and can't work. Explicitly
1205 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1206 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001207
1208 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1209 make test
1210
Gilles Peskine8eb29432021-02-03 20:07:11 +01001211 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001212 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001213}
1214
1215component_test_psa_external_rng_no_drbg_use_psa () {
1216 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001217 scripts/config.py full
1218 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001219 scripts/config.py unset MBEDTLS_ENTROPY_C
1220 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1221 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001222 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1223 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1224 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1225 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1226 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1227
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001228 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001229 make test
1230
Gilles Peskine8eb29432021-02-03 20:07:11 +01001231 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001232 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001233}
1234
1235component_test_psa_external_rng_use_psa_crypto () {
1236 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1237 scripts/config.py full
1238 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1239 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1240 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1241 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1242
1243 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1244 make test
1245
Gilles Peskineba749042021-01-13 20:02:03 +01001246 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001247 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001248}
1249
Manuel Pégourié-Gonnard1a3f9ed2020-05-19 12:38:31 +02001250component_test_ecp_no_internal_rng () {
1251 msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
1252 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1253 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1254 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1255 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1256 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
1257 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1258
1259 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1260 make
1261
1262 msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
1263 make test
1264
1265 # no SSL tests as they all depend on having a DRBG
1266}
1267
Manuel Pégourié-Gonnard53fb66d2020-06-04 09:43:14 +02001268component_test_ecp_restartable_no_internal_rng () {
1269 msg "build: Default plus ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG"
1270 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1271 scripts/config.py set MBEDTLS_ECP_RESTARTABLE
1272 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1273 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1274 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1275 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
1276 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1277
1278 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1279 make
1280
1281 msg "test: ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG module"
1282 make test
1283
1284 # no SSL tests as they all depend on having a DRBG
1285}
1286
Przemek Stekiele5352702022-10-05 11:37:54 +02001287component_test_tls1_2_default_stream_cipher_only () {
1288 msg "build: default with only stream cipher"
1289
1290 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
1291 scripts/config.py unset MBEDTLS_GCM_C
1292 scripts/config.py unset MBEDTLS_CCM_C
1293 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1294 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1295 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1296 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1297 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1298 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1299 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1300 # Modules that depend on AEAD
1301 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001302 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001303
1304 make
1305
1306 msg "test: default with only stream cipher"
1307 make test
1308
1309 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1310}
1311
1312component_test_tls1_2_default_stream_cipher_only_use_psa () {
1313 msg "build: default with only stream cipher use psa"
1314
1315 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1316 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1317 scripts/config.py unset MBEDTLS_GCM_C
1318 scripts/config.py unset MBEDTLS_CCM_C
1319 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1320 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1321 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1322 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1323 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1324 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1325 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1326 # Modules that depend on AEAD
1327 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001328 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001329
1330 make
1331
1332 msg "test: default with only stream cipher use psa"
1333 make test
1334
1335 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1336}
1337
1338component_test_tls1_2_default_cbc_legacy_cipher_only () {
1339 msg "build: default with only CBC-legacy cipher"
1340
1341 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1342 scripts/config.py unset MBEDTLS_GCM_C
1343 scripts/config.py unset MBEDTLS_CCM_C
1344 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1345 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1346 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1347 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1348 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1349 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1350 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1351 # Modules that depend on AEAD
1352 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001353 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001354
1355 make
1356
1357 msg "test: default with only CBC-legacy cipher"
1358 make test
1359
1360 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1361 tests/ssl-opt.sh -f "TLS 1.2"
1362}
1363
1364component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
1365 msg "build: default with only CBC-legacy cipher use psa"
1366
1367 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1368 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1369 scripts/config.py unset MBEDTLS_GCM_C
1370 scripts/config.py unset MBEDTLS_CCM_C
1371 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1372 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1373 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1374 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1375 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1376 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1377 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1378 # Modules that depend on AEAD
1379 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001380 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001381
1382 make
1383
1384 msg "test: default with only CBC-legacy cipher use psa"
1385 make test
1386
1387 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1388 tests/ssl-opt.sh -f "TLS 1.2"
1389}
1390
1391component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
1392 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1393
1394 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1395 scripts/config.py unset MBEDTLS_GCM_C
1396 scripts/config.py unset MBEDTLS_CCM_C
1397 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1398 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1399 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1400 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1401 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1402 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1403 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1404 # Modules that depend on AEAD
1405 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001406 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001407
1408 make
1409
1410 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1411 make test
1412
1413 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1414 tests/ssl-opt.sh -f "TLS 1.2"
1415}
1416
1417component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
1418 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
1419
1420 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1421 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1422 scripts/config.py unset MBEDTLS_GCM_C
1423 scripts/config.py unset MBEDTLS_CCM_C
1424 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1425 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1426 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1427 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1428 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1429 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1430 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1431 # Modules that depend on AEAD
1432 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001433 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001434
1435 make
1436
1437 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
1438 make test
1439
1440 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
1441 tests/ssl-opt.sh -f "TLS 1.2"
1442}
1443
Gilles Peskine636c26a2020-03-04 20:46:15 +01001444component_test_new_ecdh_context () {
1445 msg "build: new ECDH context (ASan build)" # ~ 6 min
1446 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1447 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1448 make
1449
1450 msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1451 make test
1452
1453 msg "test: new ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001454 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001455
1456 msg "test: new ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1457 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001458 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001459}
1460
1461component_test_everest () {
1462 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
1463 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1464 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1465 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1466 make
1467
1468 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1469 make test
1470
1471 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001472 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001473
1474 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1475 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001476 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001477}
1478
Gilles Peskined3beca92020-07-03 00:15:37 +02001479component_test_everest_curve25519_only () {
1480 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
1481 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1482 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1483 scripts/config.py unset MBEDTLS_ECDSA_C
1484 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1485 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1486 # Disable all curves
1487 for c in $(sed -n 's/#define \(MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED\).*/\1/p' <"$CONFIG_H"); do
1488 scripts/config.py unset "$c"
1489 done
1490 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1491
1492 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1493
1494 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1495 make test
1496}
1497
Gilles Peskine8f073122018-11-27 15:58:47 +01001498component_test_small_ssl_out_content_len () {
1499 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001500 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1501 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001502 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1503 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001504
Gilles Peskine8f073122018-11-27 15:58:47 +01001505 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001506 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001507}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001508
Gilles Peskine8f073122018-11-27 15:58:47 +01001509component_test_small_ssl_in_content_len () {
1510 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001511 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1512 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001513 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1514 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001515
Gilles Peskine8f073122018-11-27 15:58:47 +01001516 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001517 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001518}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001519
Gilles Peskine8f073122018-11-27 15:58:47 +01001520component_test_small_ssl_dtls_max_buffering () {
1521 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001522 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001523 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1524 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001525
Gilles Peskine8f073122018-11-27 15:58:47 +01001526 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001527 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 +01001528}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001529
Gilles Peskine8f073122018-11-27 15:58:47 +01001530component_test_small_mbedtls_ssl_dtls_max_buffering () {
1531 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001532 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001533 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1534 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001535
Gilles Peskine8f073122018-11-27 15:58:47 +01001536 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001537 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001538}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001539
Gilles Peskine75cc7712019-09-06 19:47:17 +02001540component_test_psa_collect_statuses () {
1541 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001542 scripts/config.py full
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001543 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001544 # Check that psa_crypto_init() succeeded at least once
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001545 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001546 rm -f tests/statuses.log
1547}
1548
Gilles Peskine8f073122018-11-27 15:58:47 +01001549component_test_full_cmake_clang () {
1550 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001551 scripts/config.py full
Gilles Peskine83264be2022-10-30 21:02:40 +01001552 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 +01001553 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001554
k-stachowiak0291cb72019-06-26 15:52:12 +02001555 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001556 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001557
Gilles Peskine83264be2022-10-30 21:02:40 +01001558 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
1559 programs/test/cpp_dummy_build
1560
k-stachowiak0291cb72019-06-26 15:52:12 +02001561 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001562 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001563
Gilles Peskine8f073122018-11-27 15:58:47 +01001564 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001565 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001566
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +00001567 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001568 env OPENSSL="$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 +02001569
Gilles Peskine8f073122018-11-27 15:58:47 +01001570 msg "test: compat.sh ARIA + ChachaPoly"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001571 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001572}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001573
Gilles Peskine9603a442022-11-29 16:01:41 +01001574skip_suites_without_constant_flow () {
1575 # Skip the test suites that don't have any constant-flow annotations.
1576 # This will need to be adjusted if we ever start declaring things as
1577 # secret from macros or functions inside tests/include or tests/src.
1578 SKIP_TEST_SUITES=$(
1579 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
1580 sed 's/test_suite_//; s/\.function$//' |
1581 tr '\n' ,)
1582 export SKIP_TEST_SUITES
1583}
1584
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001585component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001586 # This tests both (1) accesses to undefined memory, and (2) branches or
1587 # memory access depending on secret values. To distinguish between those:
1588 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1589 # - or alternatively, change the build type to MemSanDbg, which enables
1590 # origin tracking and nicer stack traces (which are useful for debugging
1591 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1592 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001593 scripts/config.py full
1594 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1595 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1596 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1597 make
1598
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001599 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001600 make test
1601}
1602
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001603component_test_valgrind_constant_flow () {
1604 # This tests both (1) everything that valgrind's memcheck usually checks
1605 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1606 # etc.) and (2) branches or memory access depending on secret values,
1607 # which will be reported as uninitialized memory. To distinguish between
1608 # secret and actually uninitialized:
1609 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1610 # - or alternatively, build with debug info and manually run the offending
1611 # test suite with valgrind --track-origins=yes, then check if the origin
1612 # was TEST_CF_SECRET() or something else.
1613 msg "build: cmake release GCC, full config with constant flow testing"
1614 scripts/config.py full
1615 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Gilles Peskine9603a442022-11-29 16:01:41 +01001616 skip_suites_without_constant_flow
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001617 cmake -D CMAKE_BUILD_TYPE:String=Release .
1618 make
1619
1620 # this only shows a summary of the results (how many of each type)
1621 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine9603a442022-11-29 16:01:41 +01001622 msg "test: some suites (valgrind + constant flow)"
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001623 make memcheck
1624}
1625
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001626component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02001627 # Test that removing the deprecated features from the default
1628 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001629 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1630 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1631 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1632
1633 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1634 make test
1635}
1636
1637component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02001638 msg "build: make, full_no_deprecated config" # ~ 30s
1639 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001640 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1641
Gilles Peskine30de2e82020-04-20 21:39:22 +02001642 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001643 make test
1644}
1645
Gilles Peskine8386ea22020-04-30 09:07:29 +02001646component_test_full_no_deprecated_deprecated_warning () {
1647 # Test that there is nothing deprecated in "full_no_deprecated".
1648 # A deprecated feature would trigger a warning (made fatal) from
1649 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02001650 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1651 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001652 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
1653 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
1654 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1655
Gilles Peskine30de2e82020-04-20 21:39:22 +02001656 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001657 make test
1658}
1659
Gilles Peskine8386ea22020-04-30 09:07:29 +02001660component_test_full_deprecated_warning () {
1661 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
1662 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001663 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001664 scripts/config.py full
1665 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001666 # Expect warnings from '#warning' directives in check_config.h.
1667 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001668
Gilles Peskine8386ea22020-04-30 09:07:29 +02001669 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1670 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
1671 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001672 # Expect warnings from '#warning' directives in check_config.h and
1673 # from the use of deprecated functions in test suites.
1674 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 +01001675
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001676 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
1677 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001678}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00001679
Gilles Peskineec541fe2020-01-31 14:24:14 +01001680# Check that the specified libraries exist and are empty.
1681are_empty_libraries () {
1682 nm "$@" >/dev/null 2>/dev/null
1683 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
1684}
1685
1686component_build_crypto_default () {
1687 msg "build: make, crypto only"
1688 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01001689 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001690 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001691}
1692
1693component_build_crypto_full () {
1694 msg "build: make, crypto only, full config"
1695 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01001696 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001697 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001698}
1699
Gilles Peskine8df27482022-10-21 19:34:54 +02001700component_test_crypto_for_psa_service () {
Gilles Peskine21503df2022-10-11 21:05:06 +02001701 msg "build: make, config for PSA crypto service"
1702 scripts/config.py crypto
1703 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1704 # Disable things that are not needed for just cryptography, to
1705 # reach a configuration that would be typical for a PSA cryptography
1706 # service providing all implemented PSA algorithms.
1707 # System stuff
1708 scripts/config.py unset MBEDTLS_ERROR_C
1709 scripts/config.py unset MBEDTLS_TIMING_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001710 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskine21503df2022-10-11 21:05:06 +02001711 # Crypto stuff with no PSA interface
1712 scripts/config.py unset MBEDTLS_BASE64_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001713 scripts/config.py unset MBEDTLS_BLOWFISH_C
1714 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
1715 # Keep MBEDTLS_MD_C because RSA and ECDSA need it, also HMAC_DRBG which
1716 # is needed for deterministic ECDSA.
1717 scripts/config.py unset MBEDTLS_ECJPAKE_C
1718 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
Gilles Peskine21503df2022-10-11 21:05:06 +02001719 scripts/config.py unset MBEDTLS_NIST_KW_C
1720 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1721 scripts/config.py unset MBEDTLS_PEM_WRITE_C
1722 scripts/config.py unset MBEDTLS_PKCS12_C
1723 scripts/config.py unset MBEDTLS_PKCS5_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001724 # We keep MBEDTLS_PK_{,PARSE,WRITE}_C because PSA with RSA needs it.
1725 scripts/config.py unset MBEDTLS_XTEA_C
Gilles Peskine21503df2022-10-11 21:05:06 +02001726 make CFLAGS='-O1 -Werror' all test
1727 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1728}
1729
Gilles Peskineec541fe2020-01-31 14:24:14 +01001730component_build_crypto_baremetal () {
1731 msg "build: make, crypto only, baremetal config"
1732 scripts/config.py crypto_baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001733 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001734 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001735}
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001736support_build_crypto_baremetal () {
Daniel Axtens1a021af2020-08-31 14:22:58 +10001737 support_build_baremetal "$@"
1738}
1739
1740component_build_baremetal () {
1741 msg "build: make, baremetal config"
1742 scripts/config.py baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001743 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Daniel Axtens1a021af2020-08-31 14:22:58 +10001744}
1745support_build_baremetal () {
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001746 # Older Glibc versions include time.h from other headers such as stdlib.h,
1747 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
1748 # problem, Ubuntu 18.04 is ok.
1749 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
1750}
Gilles Peskineec541fe2020-01-31 14:24:14 +01001751
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001752# depends.py family of tests
Andrzej Kurek85d69302022-10-05 09:14:07 -04001753component_test_depends_py_cipher_id () {
1754 msg "test/build: depends.py cipher_id (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001755 tests/scripts/depends.py cipher_id --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001756}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001757
Andrzej Kurek85d69302022-10-05 09:14:07 -04001758component_test_depends_py_cipher_chaining () {
1759 msg "test/build: depends.py cipher_chaining (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001760 tests/scripts/depends.py cipher_chaining --unset-use-psa
John Durkopc14be902020-08-20 06:16:41 -07001761}
1762
Andrzej Kurek85d69302022-10-05 09:14:07 -04001763component_test_depends_py_cipher_padding () {
1764 msg "test/build: depends.py cipher_padding (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001765 tests/scripts/depends.py cipher_padding --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001766}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001767
Andrzej Kurek85d69302022-10-05 09:14:07 -04001768component_test_depends_py_curves () {
1769 msg "test/build: depends.py curves (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001770 tests/scripts/depends.py curves --unset-use-psa
John Durkop2ec2eaa2020-08-24 18:29:15 -07001771}
1772
Andrzej Kurek85d69302022-10-05 09:14:07 -04001773component_test_depends_py_hashes () {
1774 msg "test/build: depends.py hashes (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001775 tests/scripts/depends.py hashes --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001776}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001777
Andrzej Kurek85d69302022-10-05 09:14:07 -04001778component_test_depends_py_kex () {
1779 msg "test/build: depends.py kex (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001780 tests/scripts/depends.py kex --unset-use-psa
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001781}
1782
Andrzej Kurek85d69302022-10-05 09:14:07 -04001783component_test_depends_py_pkalgs () {
1784 msg "test/build: depends.py pkalgs (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001785 tests/scripts/depends.py pkalgs --unset-use-psa
1786}
1787
1788# PSA equivalents of the depends.py tests
1789component_test_depends_py_cipher_id_psa () {
1790 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1791 tests/scripts/depends.py cipher_id
1792}
1793
1794component_test_depends_py_cipher_chaining_psa () {
1795 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1796 tests/scripts/depends.py cipher_chaining
1797}
1798
1799component_test_depends_py_cipher_padding_psa () {
1800 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1801 tests/scripts/depends.py cipher_padding
1802}
1803
1804component_test_depends_py_curves_psa () {
1805 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1806 tests/scripts/depends.py curves
1807}
1808
1809component_test_depends_py_hashes_psa () {
1810 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1811 tests/scripts/depends.py hashes
1812}
1813
1814component_test_depends_py_kex_psa () {
1815 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1816 tests/scripts/depends.py kex
1817}
1818
1819component_test_depends_py_pkalgs_psa () {
1820 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Andrzej Kurek85d69302022-10-05 09:14:07 -04001821 tests/scripts/depends.py pkalgs
Gilles Peskine8f073122018-11-27 15:58:47 +01001822}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001823
Dave Rodgman5fce4f62023-01-20 13:18:05 +00001824component_build_no_pk_rsa_alt_support () {
1825 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
1826
1827 scripts/config.py full
1828 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
1829 scripts/config.py set MBEDTLS_RSA_C
1830 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
1831
1832 # Only compile - this is primarily to test for compile issues
1833 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
1834}
1835
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001836component_test_no_use_psa_crypto_full_cmake_asan() {
1837 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02001838 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001839 scripts/config.py full
1840 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
1841 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1842 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1843 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02001844 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001845 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01001846 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001847 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001848
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001849 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001850 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001851
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001852 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001853 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001854
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001855 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001856 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001857
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001858 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001859 env OPENSSL="$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 -05001860
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001861 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001862 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001863}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001864
Ronald Crond2c53e62021-09-13 09:38:05 +02001865component_test_psa_crypto_config_accel_ecdsa () {
1866 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1867
1868 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1869 # partial support for cipher operations in the driver test library.
1870 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1871 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Gilles Peskine62de7672022-04-21 11:05:16 +02001872 # Disable obsolete hashes (alternatively we could enable support for them
1873 # in the driver test library).
1874 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1875 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
Ronald Crond2c53e62021-09-13 09:38:05 +02001876
1877 # SHA384 needed for some ECDSA signature tests.
1878 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
1879
1880 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
1881 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1882 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1883
1884 # Restore test driver base configuration
1885 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
1886
1887 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1888 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1889 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1890 scripts/config.py unset MBEDTLS_ECDSA_C
1891 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1892 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1893
1894 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
1895 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"
1896
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01001897 not grep mbedtls_ecdsa_ library/ecdsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02001898
1899 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1900 make test
1901}
1902
1903component_test_psa_crypto_config_accel_rsa_signature () {
1904 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
1905
1906 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1907 # partial support for cipher operations in the driver test library.
1908 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1909 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1910
1911 # It seems it is not possible to remove only the support for RSA signature
1912 # in the library. Thus we have to remove all RSA support (signature and
1913 # encryption/decryption). AS there is no driver support for asymmetric
1914 # encryption/decryption so far remove RSA encryption/decryption from the
1915 # application algorithm list.
1916 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1917 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1918
1919 # Make sure both the library and the test library support the SHA hash
1920 # algorithms and only those ones (SHA256 is included by default). That way:
1921 # - the test library can compute the RSA signatures even in the case of a
1922 # composite RSA signature algorithm based on a SHA hash (no other hash
1923 # used in the unit tests).
1924 # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
1925 # fulfilled as the hash SHA algorithm is supported by the library, and
1926 # thus the tests are run, not skipped.
1927 # - when testing a signature key with an algorithm wildcard built from
1928 # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
1929 # algorithm based on the hashes supported by the library is also
1930 # supported by the test library.
1931 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1932 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1933 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1934 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160_C
1935
1936 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA1_C
1937 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
1938 # We need PEM parsing in the test library as well to support the import
1939 # of PEM encoded RSA keys.
1940 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_PEM_PARSE_C
1941 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_BASE64_C
1942
1943 loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
1944 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1945 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1946
1947 # Restore test driver base configuration
1948 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA1_C
1949 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
1950 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_PEM_PARSE_C
1951 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_BASE64_C
1952
1953
1954 # Mbed TLS library build
1955 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1956 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1957
1958 # Remove RSA support and its dependencies
1959 scripts/config.py unset MBEDTLS_PKCS1_V15
1960 scripts/config.py unset MBEDTLS_PKCS1_V21
1961 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1962 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1963 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1964 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1965 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1966 scripts/config.py unset MBEDTLS_RSA_C
1967 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1968
1969 scripts/config.py unset MBEDTLS_MD2_C
1970 scripts/config.py unset MBEDTLS_MD4_C
1971 scripts/config.py unset MBEDTLS_MD5_C
1972 scripts/config.py unset MBEDTLS_RIPEMD160_C
1973 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
1974 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
1975 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
1976
1977 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
1978 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
1979
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01001980 not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
1981 not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02001982
1983 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
1984 make test
1985}
1986
Ronald Cronf7e483c2021-05-08 14:32:59 +02001987component_test_psa_crypto_config_accel_hash () {
1988 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
1989
1990 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1991 # partial support for cipher operations in the driver test library.
1992 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1993 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1994
1995 loc_accel_list="ALG_MD4 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
1996 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1997 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1998
1999 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2000 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2001 scripts/config.py unset MBEDTLS_MD2_C
2002 scripts/config.py unset MBEDTLS_MD4_C
2003 scripts/config.py unset MBEDTLS_MD5_C
2004 scripts/config.py unset MBEDTLS_RIPEMD160_C
2005 scripts/config.py unset MBEDTLS_SHA1_C
2006 # Don't unset MBEDTLS_SHA256_C as it is needed by PSA crypto core.
2007 scripts/config.py unset MBEDTLS_SHA512_C
2008 # Unset MBEDTLS_SSL_PROTO_SSL3, MBEDTLS_SSL_PROTO_TLS1 and MBEDTLS_SSL_PROTO_TLS1_1 as they depend on MBEDTLS_SHA1_C
2009 scripts/config.py unset MBEDTLS_SSL_PROTO_SSL3
2010 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
2011 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
2012 # Unset MBEDTLS_SSL_CBC_RECORD_SPLITTING as it depends on MBEDTLS_SSL_PROTO_TLS1 in the default configuration.
2013 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
2014 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2015 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2016
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002017 not grep mbedtls_sha512_init library/sha512.o
2018 not grep mbedtls_sha1_init library/sha1.o
Ronald Cronf7e483c2021-05-08 14:32:59 +02002019
2020 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2021 make test
2022}
2023
Ronald Cron09623702021-10-18 11:26:01 +02002024component_test_psa_crypto_config_accel_cipher () {
2025 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
2026
Gilles Peskine186331872022-04-12 15:58:03 +02002027 # This test case focuses on cipher+AEAD. We don't yet support all
2028 # combinations of configurations, so deactivate block-cipher-based MACs.
2029 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CMAC
2030
Ronald Cron09623702021-10-18 11:26:01 +02002031 loc_accel_list="ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB ALG_OFB ALG_XTS KEY_TYPE_DES"
2032 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2033 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2034
2035 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2036 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2037
2038 # There is no intended accelerator support for ALG STREAM_CIPHER and
2039 # ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
2040 # inclusion of the Mbed TLS cipher operations. As we want to test here with
2041 # cipher operations solely supported by accelerators, disabled those
2042 # PSA configuration options.
2043 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2044 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Ronald Cron09623702021-10-18 11:26:01 +02002045
2046 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2047 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2048 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2049 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2050 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2051 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2052 scripts/config.py unset MBEDTLS_DES_C
2053
2054 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2055 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2056
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002057 not grep mbedtls_des* library/des.o
Ronald Cron09623702021-10-18 11:26:01 +02002058
2059 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2060 make test
2061}
2062
Przemek Stekiel8b56f232022-10-02 20:58:39 +02002063component_test_psa_crypto_config_accel_aead () {
2064 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2065
2066 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
2067 # partial support for cipher operations in the driver test library.
2068 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2069 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
2070
2071 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2072 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2073 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2074
2075 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2076 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2077
2078 scripts/config.py unset MBEDTLS_GCM_C
2079 scripts/config.py unset MBEDTLS_CCM_C
2080 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2081 # Features that depend on AEAD
2082 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
2083 scripts/config.py unset MBEDTLS_SSL_TICKET_C
2084
2085 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2086 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"
2087
2088 # There's a risk of something getting re-enabled via config_psa.h
2089 # make sure it did not happen.
2090 not grep mbedtls_ccm library/ccm.o
2091 not grep mbedtls_gcm library/gcm.o
2092 not grep mbedtls_chachapoly library/chachapoly.o
2093
2094 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2095 make test
2096}
2097
John Durkop4377bf72020-10-23 01:26:57 -07002098component_test_psa_crypto_config_no_driver() {
2099 # full plus MBEDTLS_PSA_CRYPTO_CONFIG
2100 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
2101 scripts/config.py full
2102 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2103 scripts/config.py unset MBEDTLS_PSA_CRYPTO_DRIVERS
2104 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkope7012c72020-10-26 09:55:01 -07002105 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop4377bf72020-10-23 01:26:57 -07002106
2107 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
John Durkopd8959392020-09-20 23:09:17 -07002108 make test
2109}
2110
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002111component_test_psa_crypto_config_chachapoly_disabled() {
2112 # full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305
2113 msg "build: full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305"
2114 scripts/config.py full
2115 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2116 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_GCM
2117 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CHACHA20_POLY1305
2118 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
2119
2120 msg "test: full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305"
2121 make test
2122}
2123
John Durkopd0321952020-10-29 21:37:36 -07002124# 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 -08002125component_build_psa_accel_alg_ecdh() {
John Durkopd0321952020-10-29 21:37:36 -07002126 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_ECDH
2127 # without MBEDTLS_ECDH_C
2128 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
2129 scripts/config.py full
2130 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2131 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2132 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2133 scripts/config.py unset MBEDTLS_ECDH_C
2134 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2135 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2136 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2137 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2138 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2139 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2140 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2141}
2142
John Durkopf4c4cb02020-10-28 20:09:55 -07002143# 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 -08002144component_build_psa_accel_key_type_ecc_key_pair() {
John Durkop9814fa22020-11-04 12:28:15 -08002145 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
2146 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR"
John Durkopf4c4cb02020-10-28 20:09:55 -07002147 scripts/config.py full
2148 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2149 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2150 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002151 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 -08002152 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 -07002153 # 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 -08002154 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 -07002155}
2156
2157# 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 -08002158component_build_psa_accel_key_type_ecc_public_key() {
John Durkop9814fa22020-11-04 12:28:15 -08002159 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY
2160 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
John Durkopf4c4cb02020-10-28 20:09:55 -07002161 scripts/config.py full
2162 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2163 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2164 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002165 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
2166 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
John Durkopf4c4cb02020-10-28 20:09:55 -07002167 # 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 -08002168 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 -07002169}
2170
John Durkopd0321952020-10-29 21:37:36 -07002171# 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 -08002172component_build_psa_accel_alg_hmac() {
John Durkopd0321952020-10-29 21:37:36 -07002173 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HMAC
2174 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HMAC"
2175 scripts/config.py full
2176 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2177 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2178 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2179 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2180 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2181}
2182
2183# 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 -08002184component_build_psa_accel_alg_hkdf() {
John Durkopd0321952020-10-29 21:37:36 -07002185 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HKDF
2186 # without MBEDTLS_HKDF_C
2187 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
2188 scripts/config.py full
2189 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2190 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2191 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2192 scripts/config.py unset MBEDTLS_HKDF_C
John Durkopbd069d32020-10-31 22:14:03 -07002193 # Make sure to unset TLS1_3_EXPERIMENTAL since it requires HKDF_C and will not build properly without it.
2194 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
John Durkopd0321952020-10-29 21:37:36 -07002195 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2196 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2197}
2198
John Durkop1b7ee052020-11-27 08:51:22 -08002199# This should be renamed to test and updated once the accelerator MD2 code is in place and ready to test.
2200component_build_psa_accel_alg_md2() {
2201 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD2 without other hashes
2202 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD2 - other hashes"
2203 scripts/config.py full
2204 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2205 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2206 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2207 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2208 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2209 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2210 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2211 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2212 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2213 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2214 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2215 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2216 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD2 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2217}
2218
2219# This should be renamed to test and updated once the accelerator MD4 code is in place and ready to test.
2220component_build_psa_accel_alg_md4() {
2221 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD4 without other hashes
2222 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD4 - other hashes"
2223 scripts/config.py full
2224 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2225 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2226 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2227 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2228 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2229 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2230 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2231 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2232 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2233 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2234 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2235 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2236 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD4 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2237}
2238
2239# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
2240component_build_psa_accel_alg_md5() {
2241 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD5 without other hashes
2242 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD5 - other hashes"
2243 scripts/config.py full
2244 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2245 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2246 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2247 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2248 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2249 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2250 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2251 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2252 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2253 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2254 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2255 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2256 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2257}
2258
2259# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
2260component_build_psa_accel_alg_ripemd160() {
2261 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RIPEMD160 without other hashes
2262 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RIPEMD160 - other hashes"
2263 scripts/config.py full
2264 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2265 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2266 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2267 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2268 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2269 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2270 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2271 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2272 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
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_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2277}
2278
2279# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
2280component_build_psa_accel_alg_sha1() {
2281 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_1 without other hashes
2282 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_1 - 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_224
2292 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
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_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2297}
2298
2299# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
2300component_build_psa_accel_alg_sha224() {
2301 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_224 without other hashes
2302 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_224 - 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_384
2313 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
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_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2316}
2317
2318# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
2319component_build_psa_accel_alg_sha256() {
2320 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_256 without other hashes
2321 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_256 - 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_384
2333 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
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_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2336}
2337
2338# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
2339component_build_psa_accel_alg_sha384() {
2340 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_384 without other hashes
2341 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_384 - other hashes"
2342 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
2346 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2347 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2348 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2349 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2350 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2351 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2352 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2353 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2354 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2355}
2356
2357# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
2358component_build_psa_accel_alg_sha512() {
2359 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_512 without other hashes
2360 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_512 - other hashes"
2361 scripts/config.py full
2362 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2363 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2364 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2365 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2366 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2367 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2368 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2369 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2370 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2371 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2372 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2373 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2374 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2375}
2376
John Durkopd0321952020-10-29 21:37:36 -07002377# 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 -08002378component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
John Durkopbd069d32020-10-31 22:14:03 -07002379 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2380 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 -07002381 scripts/config.py full
2382 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2383 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2384 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkopbd069d32020-10-31 22:14:03 -07002385 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002386 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2387 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2388 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07002389 # 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 -07002390 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2391}
2392
2393# 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 -08002394component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
John Durkopbd069d32020-10-31 22:14:03 -07002395 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_SIGN and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
2396 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2397 scripts/config.py full
2398 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2399 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2400 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2401 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002402 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2403 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2404 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002405 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2406 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2407}
2408
2409# 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 -08002410component_build_psa_accel_alg_rsa_oaep() {
John Durkopbd069d32020-10-31 22:14:03 -07002411 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_OAEP and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
2412 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2413 scripts/config.py full
2414 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2415 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2416 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2417 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_OAEP 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002418 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2419 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2420 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002421 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2422 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2423}
2424
2425# 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 -08002426component_build_psa_accel_alg_rsa_pss() {
John Durkopbd069d32020-10-31 22:14:03 -07002427 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PSS and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
2428 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2429 scripts/config.py full
2430 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2431 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2432 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2433 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002434 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2435 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2436 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07002437 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2438 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2439}
2440
2441# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08002442component_build_psa_accel_key_type_rsa_key_pair() {
John Durkopbd069d32020-10-31 22:14:03 -07002443 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_KEY_PAIR and PSA_WANT_ALG_RSA_PSS
2444 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR + PSA_WANT_ALG_RSA_PSS"
2445 scripts/config.py full
2446 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2447 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2448 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2449 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2450 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
2451 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2452 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"
2453}
2454
2455# 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 -08002456component_build_psa_accel_key_type_rsa_public_key() {
John Durkopbd069d32020-10-31 22:14:03 -07002457 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY and PSA_WANT_ALG_RSA_PSS
2458 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
2459 scripts/config.py full
2460 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2461 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2462 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2463 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2464 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
2465 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2466 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 -07002467}
2468
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002469component_test_check_params_functionality () {
2470 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002471 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002472 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002473 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Ronald Crona1236142020-07-01 16:01:21 +02002474 make CC=gcc CFLAGS='-Werror -O1' all test
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002475}
2476
Gilles Peskineb28636b2019-01-02 19:06:24 +01002477component_test_check_params_without_platform () {
2478 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002479 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002480 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002481 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
2482 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
2483 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
2484 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
Gilles Peskine32e889d2020-04-12 23:43:28 +02002485 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002486 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
2487 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskine9c764bf2022-09-18 14:05:23 +02002488 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002489 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
2490 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +01002491 make CC=gcc CFLAGS='-Werror -O1' all test
2492}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002493
Gilles Peskineb28636b2019-01-02 19:06:24 +01002494component_test_check_params_silent () {
2495 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002496 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002497 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01002498 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
2499 make CC=gcc CFLAGS='-Werror -O1' all test
2500}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002501
Gilles Peskine8f073122018-11-27 15:58:47 +01002502component_test_no_platform () {
2503 # Full configuration build, without platform support, file IO and net sockets.
2504 # This should catch missing mbedtls_printf definitions, and by disabling file
2505 # IO, it should catch missing '#include <stdio.h>'
2506 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002507 scripts/config.py full
2508 scripts/config.py unset MBEDTLS_PLATFORM_C
2509 scripts/config.py unset MBEDTLS_NET_C
2510 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
2511 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
2512 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
2513 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskine9c764bf2022-09-18 14:05:23 +02002514 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002515 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
2516 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskine32e889d2020-04-12 23:43:28 +02002517 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002518 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
2519 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002520 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002521 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
2522 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01002523 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
2524 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002525 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
2526 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01002527}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00002528
Gilles Peskine8f073122018-11-27 15:58:47 +01002529component_build_no_std_function () {
2530 # catch compile bugs in _uninit functions
2531 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002532 scripts/config.py full
2533 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
2534 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002535 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine31fdda12021-10-08 11:45:47 +02002536 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskine25319702021-10-07 19:34:57 +02002537 make
Gilles Peskine8f073122018-11-27 15:58:47 +01002538}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01002539
Gilles Peskine8f073122018-11-27 15:58:47 +01002540component_build_no_ssl_srv () {
2541 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002542 scripts/config.py full
2543 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002544 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002545}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002546
Gilles Peskine8f073122018-11-27 15:58:47 +01002547component_build_no_ssl_cli () {
2548 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002549 scripts/config.py full
2550 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002551 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002552}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002553
Gilles Peskine8f073122018-11-27 15:58:47 +01002554component_build_no_sockets () {
2555 # Note, C99 compliance can also be tested with the sockets support disabled,
2556 # as that requires a POSIX platform (which isn't the same as C99).
2557 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002558 scripts/config.py full
2559 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
2560 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002561 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01002562}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02002563
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002564component_test_memory_buffer_allocator_backtrace () {
2565 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002566 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2567 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2568 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
2569 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Gilles Peskineff30bd02021-10-19 21:33:32 +02002570 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002571 make
2572
2573 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
2574 make test
2575}
2576
2577component_test_memory_buffer_allocator () {
2578 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002579 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2580 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Gilles Peskineff30bd02021-10-19 21:33:32 +02002581 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002582 make
2583
2584 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2585 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002586
2587 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2588 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002589 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002590}
2591
Gilles Peskine8f073122018-11-27 15:58:47 +01002592component_test_no_max_fragment_length () {
2593 # Run max fragment length tests with MFL disabled
2594 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002595 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01002596 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2597 make
Hanno Becker5175ac62017-09-18 15:36:25 +01002598
Gilles Peskine8f073122018-11-27 15:58:47 +01002599 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002600 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01002601}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002602
Hanno Becker545ced42019-02-19 11:10:48 +00002603component_test_asan_remove_peer_certificate () {
2604 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002605 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00002606 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2607 make
2608
2609 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2610 make test
2611
2612 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002613 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002614
2615 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002616 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002617
2618 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002619 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002620}
2621
Gilles Peskine8f073122018-11-27 15:58:47 +01002622component_test_no_max_fragment_length_small_ssl_out_content_len () {
2623 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002624 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2625 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
2626 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01002627 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2628 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10002629
Gilles Peskine8f073122018-11-27 15:58:47 +01002630 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002631 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002632
2633 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002634 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002635}
Angus Grattonc4dd0732018-04-11 16:28:39 +10002636
Darryl Greenaad82f92019-12-02 10:53:11 +00002637component_test_variable_ssl_in_out_buffer_len () {
2638 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
2639 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2640 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2641 make
2642
2643 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2644 make test
2645
2646 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002647 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002648
2649 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002650 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002651}
2652
2653component_test_variable_ssl_in_out_buffer_len_CID () {
2654 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
2655 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2656 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
2657
2658 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2659 make
2660
2661 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
2662 make test
2663
2664 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002665 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002666
2667 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002668 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002669}
2670
2671component_test_variable_ssl_in_out_buffer_len_record_splitting () {
2672 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled (ASan build)"
2673 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2674 scripts/config.py set MBEDTLS_SSL_CBC_RECORD_SPLITTING
2675
2676 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2677 make
2678
2679 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING"
2680 make test
2681
2682 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002683 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002684
2685 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002686 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002687}
2688
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002689component_test_ssl_alloc_buffer_and_mfl () {
2690 msg "build: default config with memory buffer allocator and MFL extension"
2691 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2692 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2693 scripts/config.py set MBEDTLS_MEMORY_DEBUG
2694 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2695 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
Gilles Peskineff30bd02021-10-19 21:33:32 +02002696 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002697 make
2698
2699 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
2700 make test
2701
2702 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 +02002703 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002704}
2705
Gilles Peskine636c26a2020-03-04 20:46:15 +01002706component_test_when_no_ciphersuites_have_mac () {
2707 msg "build: when no ciphersuites have MAC"
2708 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
2709 scripts/config.py unset MBEDTLS_ARC4_C
2710 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2711 make
2712
2713 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
2714 make test
2715
2716 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002717 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01002718}
2719
Gilles Peskine8f073122018-11-27 15:58:47 +01002720component_test_null_entropy () {
2721 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002722 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
2723 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
2724 scripts/config.py set MBEDTLS_ENTROPY_C
2725 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002726 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002727 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
2728 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00002729 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01002730 make
Janos Follath06c54002016-06-09 13:57:40 +01002731
Gilles Peskine8f073122018-11-27 15:58:47 +01002732 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
2733 make test
2734}
Janos Follath06c54002016-06-09 13:57:40 +01002735
Raoul Strackxa4e86142020-06-15 17:03:13 +02002736component_test_no_date_time () {
2737 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
2738 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
Gilles Peskine31fdda12021-10-08 11:45:47 +02002739 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Raoul Strackxa4e86142020-06-15 17:03:13 +02002740 make
2741
2742 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
2743 make test
2744}
2745
Andrzej Kurekc890b222023-01-17 04:03:19 -05002746component_test_alt_timing() {
2747 msg "build: alternate timing implementation"
2748 scripts/config.py set MBEDTLS_TIMING_ALT
2749 make lib TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
2750
2751 msg "test: MBEDTLS_TIMING_ALT - test suites"
2752 make test TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
Andrzej Kurek3a261a42023-01-26 04:33:59 -05002753
2754 msg "selftest - MBEDTLS-TIMING_ALT"
2755 make programs TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../../tests/src/external_timing -I../tests/src/external_timing"
2756 programs/test/selftest
Andrzej Kurekc890b222023-01-17 04:03:19 -05002757}
2758
Gilles Peskine8f073122018-11-27 15:58:47 +01002759component_test_platform_calloc_macro () {
2760 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002761 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2762 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
2763 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01002764 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2765 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01002766
Gilles Peskine8f073122018-11-27 15:58:47 +01002767 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
2768 make test
2769}
Hanno Beckere5fecec2018-10-11 11:02:52 +01002770
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002771component_test_malloc_0_null () {
2772 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002773 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +02002774 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 +02002775
2776 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
2777 make test
2778
2779 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
2780 # Just the calloc selftest. "make test" ran the others as part of the
2781 # test suites.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002782 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01002783
2784 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
2785 # Run a subset of the tests. The choice is a balance between coverage
2786 # and time (including time indirectly wasted due to flaky tests).
2787 # The current choice is to skip tests whose description includes
2788 # "proxy", which is an approximation of skipping tests that use the
2789 # UDP proxy, which tend to be slower and flakier.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002790 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002791}
2792
Gilles Peskine8f073122018-11-27 15:58:47 +01002793component_test_aes_fewer_tables () {
2794 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002795 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002796 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002797
Gilles Peskine8f073122018-11-27 15:58:47 +01002798 msg "test: AES_FEWER_TABLES"
2799 make test
2800}
Hanno Becker83ebf782017-07-07 12:29:15 +01002801
Gilles Peskine8f073122018-11-27 15:58:47 +01002802component_test_aes_rom_tables () {
2803 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002804 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002805 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002806
Gilles Peskine8f073122018-11-27 15:58:47 +01002807 msg "test: AES_ROM_TABLES"
2808 make test
2809}
Hanno Becker83ebf782017-07-07 12:29:15 +01002810
Gilles Peskine8f073122018-11-27 15:58:47 +01002811component_test_aes_fewer_tables_and_rom_tables () {
2812 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002813 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2814 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002815 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002816
Gilles Peskine8f073122018-11-27 15:58:47 +01002817 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2818 make test
2819}
2820
Gilles Peskine592f5912019-10-07 18:49:32 +02002821component_test_ctr_drbg_aes_256_sha_256 () {
2822 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002823 scripts/config.py full
2824 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2825 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002826 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2827 make
2828
2829 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2830 make test
2831}
2832
2833component_test_ctr_drbg_aes_128_sha_512 () {
2834 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002835 scripts/config.py full
2836 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2837 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02002838 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2839 make
2840
2841 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2842 make test
2843}
2844
2845component_test_ctr_drbg_aes_128_sha_256 () {
2846 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002847 scripts/config.py full
2848 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2849 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2850 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002851 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2852 make
2853
2854 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2855 make test
2856}
2857
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002858component_test_se_default () {
2859 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002860 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02002861 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002862
2863 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2864 make test
2865}
2866
Steven Cooremand57203d2020-07-16 20:28:59 +02002867component_test_psa_crypto_drivers () {
Steven Cooreman55ae2172020-07-17 19:46:15 +02002868 msg "build: MBEDTLS_PSA_CRYPTO_DRIVERS w/ driver hooks"
Steven Cooreman753f9732021-03-15 11:38:44 +01002869 scripts/config.py full
Steven Cooremand57203d2020-07-16 20:28:59 +02002870 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
Steven Cooreman6801f082021-02-19 17:21:22 +01002871 scripts/config.py set MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
Gilles Peskinefe0acc62021-09-20 19:20:04 +02002872 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
2873 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002874 loc_cflags="${loc_cflags} -I../tests/include -O2"
2875
2876 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002877
Steven Cooreman753f9732021-03-15 11:38:44 +01002878 msg "test: full + MBEDTLS_PSA_CRYPTO_DRIVERS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002879 make test
2880}
2881
Gilles Peskine8f073122018-11-27 15:58:47 +01002882component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002883 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002884 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02002885 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine27482f12021-11-04 12:52:14 +01002886 programs/test/dlopen_demo.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002887}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02002888
Gilles Peskinecf740502019-07-03 20:43:05 +02002889component_test_cmake_shared () {
2890 msg "build/test: cmake shared" # ~ 2min
2891 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
2892 make
Gilles Peskine56c01612019-07-03 20:43:32 +02002893 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02002894 make test
Gilles Peskine27482f12021-11-04 12:52:14 +01002895 programs/test/dlopen_demo.sh
Gilles Peskinecf740502019-07-03 20:43:05 +02002896}
2897
Gilles Peskineec10bf12019-09-20 19:56:06 +02002898test_build_opt () {
2899 info=$1 cc=$2; shift 2
2900 for opt in "$@"; do
2901 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskinee094a182020-04-14 20:08:41 +02002902 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02002903 # We're confident enough in compilers to not run _all_ the tests,
2904 # but at least run the unit tests. In particular, runs with
2905 # optimizations use inline assembly whereas runs with -O0
2906 # skip inline assembly.
2907 make test # ~30s
2908 make clean
2909 done
2910}
2911
2912component_test_clang_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002913 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02002914 test_build_opt 'full config' clang -O0 -Os -O2
2915}
2916
2917component_test_gcc_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002918 scripts/config.py full
Gilles Peskineec10bf12019-09-20 19:56:06 +02002919 test_build_opt 'full config' gcc -O0 -Os -O2
2920}
2921
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02002922component_build_mbedtls_config_file () {
2923 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
Gilles Peskine6af9dc92022-04-07 20:55:57 +02002924 scripts/config.py -w full_config.h full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02002925 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
2926 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02002927 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine036a9bb2022-04-07 21:06:41 +02002928 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
2929 make clean
2930
2931 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
2932 # In the user config, disable one feature (for simplicity, pick a feature
2933 # that nothing else depends on).
2934 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
2935 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
2936 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
2937
2938 rm -f user_config.h full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002939}
2940
Gilles Peskine690a2ef2022-04-07 21:59:14 +02002941component_build_psa_config_file () {
2942 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
2943 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2944 cp "$CRYPTO_CONFIG_H" psa_test_config.h
2945 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
2946 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02002947 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine690a2ef2022-04-07 21:59:14 +02002948 programs/test/query_compile_time_config MBEDTLS_CMAC_C
2949 make clean
2950
2951 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
2952 # In the user config, disable one feature, which will reflect on the
2953 # mbedtls configuration so we can query it with query_compile_time_config.
2954 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
2955 scripts/config.py unset MBEDTLS_CMAC_C
2956 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
2957 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
2958
2959 rm -f psa_test_config.h psa_user_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002960}
2961
Gilles Peskine8f073122018-11-27 15:58:47 +01002962component_test_m32_o0 () {
Gilles Peskinea0c51fb2021-10-07 19:27:16 +02002963 # Build without optimization, so as to use portable C code (in a 32-bit
2964 # build) and not the i386-specific inline assembly.
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002965 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002966 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02002967 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01002968
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002969 msg "test: i386, make, gcc -O0 (ASan build)"
2970 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01002971}
Gilles Peskine878cf602019-01-06 20:50:38 +00002972support_test_m32_o0 () {
2973 case $(uname -m) in
Pengyu Lva89b3672022-10-21 10:50:26 +00002974 amd64|x86_64) true;;
Gilles Peskine878cf602019-01-06 20:50:38 +00002975 *) false;;
2976 esac
2977}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002978
Gilles Peskine6fa69862021-10-05 09:36:03 +02002979component_test_m32_o2 () {
2980 # Build with optimization, to use the i386 specific inline assembly
2981 # and go faster for tests.
2982 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002983 scripts/config.py full
Gilles Peskine6fa69862021-10-05 09:36:03 +02002984 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01002985
Gilles Peskine6fa69862021-10-05 09:36:03 +02002986 msg "test: i386, make, gcc -O2 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002987 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002988
Gilles Peskine6fa69862021-10-05 09:36:03 +02002989 msg "test ssl-opt.sh, i386, make, gcc-O2"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002990 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002991}
Gilles Peskine3daa83e2021-10-07 19:25:29 +02002992support_test_m32_o2 () {
Gilles Peskine878cf602019-01-06 20:50:38 +00002993 support_test_m32_o0 "$@"
2994}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01002995
Gilles Peskine0c6b7992019-04-12 20:29:48 +02002996component_test_m32_everest () {
2997 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002998 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
2999 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02003000 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003001
3002 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
3003 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003004
3005 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003006 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01003007
3008 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
3009 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003010 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003011}
3012support_test_m32_everest () {
3013 support_test_m32_o0 "$@"
3014}
3015
Gilles Peskine8f073122018-11-27 15:58:47 +01003016component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003017 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003018 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02003019 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003020
3021 msg "test: 64-bit ILP32, make, gcc"
3022 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01003023}
Gilles Peskine878cf602019-01-06 20:50:38 +00003024support_test_mx32 () {
3025 case $(uname -m) in
3026 amd64|x86_64) true;;
3027 *) false;;
3028 esac
3029}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003030
Peter Kolbus60c6da22018-12-27 06:59:04 -06003031component_test_min_mpi_window_size () {
3032 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003033 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06003034 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3035 make
3036
3037 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
3038 make test
3039}
3040
Gilles Peskine8f073122018-11-27 15:58:47 +01003041component_test_have_int32 () {
3042 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003043 scripts/config.py unset MBEDTLS_HAVE_ASM
3044 scripts/config.py unset MBEDTLS_AESNI_C
3045 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01003046 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01003047
Gilles Peskine8f073122018-11-27 15:58:47 +01003048 msg "test: gcc, force 32-bit bignum limbs"
3049 make test
3050}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01003051
Gilles Peskine8f073122018-11-27 15:58:47 +01003052component_test_have_int64 () {
3053 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003054 scripts/config.py unset MBEDTLS_HAVE_ASM
3055 scripts/config.py unset MBEDTLS_AESNI_C
3056 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01003057 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01003058
Gilles Peskine8f073122018-11-27 15:58:47 +01003059 msg "test: gcc, force 64-bit bignum limbs"
3060 make test
3061}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003062
Gilles Peskine8f073122018-11-27 15:58:47 +01003063component_test_no_udbl_division () {
3064 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003065 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003066 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01003067 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003068
Gilles Peskine8f073122018-11-27 15:58:47 +01003069 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
3070 make test
3071}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003072
Gilles Peskine8f073122018-11-27 15:58:47 +01003073component_test_no_64bit_multiplication () {
3074 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003075 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003076 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01003077 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003078
Gilles Peskine8f073122018-11-27 15:58:47 +01003079 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
3080 make test
3081}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003082
Gilles Peskine3809f5f2020-11-09 15:40:05 +01003083component_test_no_strings () {
3084 msg "build: no strings" # ~10s
3085 scripts/config.py full
3086 # Disable options that activate a large amount of string constants.
3087 scripts/config.py unset MBEDTLS_DEBUG_C
3088 scripts/config.py unset MBEDTLS_ERROR_C
3089 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
3090 scripts/config.py unset MBEDTLS_VERSION_FEATURES
3091 make CFLAGS='-Werror -Os'
3092
3093 msg "test: no strings" # ~ 10s
3094 make test
3095}
3096
Gilles Peskine8f073122018-11-27 15:58:47 +01003097component_build_arm_none_eabi_gcc () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003098 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003099 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02003100 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 +02003101
Gilles Peskine60d99472021-09-01 20:00:33 +02003102 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003103 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003104}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003105
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003106component_build_arm_linux_gnueabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003107 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003108 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02003109 # Build for a target platform that's close to what Debian uses
3110 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
Dave Rodgman52af7692022-03-31 14:27:24 +01003111 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003112 # Build everything including programs, see for example
Dave Rodgman52af7692022-03-31 14:27:24 +01003113 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003114 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'
3115
Gilles Peskine60d99472021-09-01 20:00:33 +02003116 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003117 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size library/*.o
3118}
3119support_build_arm_linux_gnueabi_gcc_arm5vte () {
3120 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
3121}
3122
3123component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003124 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003125 scripts/config.py baremetal
3126 # This is an imperfect substitute for
3127 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnard9a260a62021-07-06 09:44:59 +02003128 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02003129 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 +02003130
Gilles Peskine60d99472021-09-01 20:00:33 +02003131 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003132 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02003133}
3134
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003135component_build_arm_none_eabi_gcc_m0plus () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003136 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
3137 scripts/config.py baremetal_size
Gilles Peskineaeedd742020-09-02 11:03:04 +02003138 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 +02003139
Gilles Peskine60d99472021-09-01 20:00:33 +02003140 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
Gilles Peskine18487f62020-04-30 23:11:54 +02003141 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003142}
3143
Gilles Peskine8f073122018-11-27 15:58:47 +01003144component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003145 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003146 scripts/config.py baremetal
3147 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003148 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 +01003149 echo "Checking that software 64-bit division is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003150 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003151}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003152
Gilles Peskine8f073122018-11-27 15:58:47 +01003153component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003154 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003155 scripts/config.py baremetal
3156 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003157 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 +01003158 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003159 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003160}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003161
Gilles Peskine8f073122018-11-27 15:58:47 +01003162component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02003163 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003164 scripts/config.py baremetal
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003165 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02003166
3167 msg "size: ARM Compiler 5"
3168 "$ARMC5_FROMELF" -z library/*.o
3169
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003170 make clean
Andres AG87bb5772016-09-27 15:05:15 +01003171
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003172 # ARM Compiler 6 - Target ARMv7-A
3173 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003174
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003175 # ARM Compiler 6 - Target ARMv7-M
3176 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02003177
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003178 # ARM Compiler 6 - Target ARMv8-A - AArch32
3179 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003180
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003181 # ARM Compiler 6 - Target ARMv8-M
3182 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02003183
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003184 # ARM Compiler 6 - Target ARMv8-A - AArch64
3185 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Gilles Peskine8f073122018-11-27 15:58:47 +01003186}
Pengyu Lvd216c042023-03-03 18:23:35 +08003187support_build_armcc () {
3188 armc5_cc="$ARMC5_BIN_DIR/armcc"
3189 armc6_cc="$ARMC6_BIN_DIR/armclang"
3190 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
3191}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01003192
Manuel Pégourié-Gonnarddd8807f2020-02-26 09:56:27 +01003193component_build_ssl_hw_record_accel() {
3194 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
3195 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
3196 make CFLAGS='-Werror -O1'
3197}
3198
Hanno Beckera711f6e2020-05-04 12:03:51 +01003199component_test_tls13_experimental () {
3200 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3201 scripts/config.pl set MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
3202 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3203 make
3204 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3205 make test
3206}
3207
Gilles Peskine8f073122018-11-27 15:58:47 +01003208component_build_mingw () {
3209 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003210 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 +00003211
Gilles Peskine8f073122018-11-27 15:58:47 +01003212 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003213 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 +01003214 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02003215
Gilles Peskine8f073122018-11-27 15:58:47 +01003216 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003217 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
3218 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 +01003219 make WINDOWS_BUILD=1 clean
3220}
Jaeden Amero117b8a42019-04-17 15:19:26 +01003221support_build_mingw() {
Pengyu Lva19ce122023-02-24 15:38:52 +08003222 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
3223 [0-5]*|"") false;;
Jaeden Amero117b8a42019-04-17 15:19:26 +01003224 *) true;;
3225 esac
3226}
Simon Butcher91aef332016-11-17 09:20:50 +00003227
Gilles Peskine8f073122018-11-27 15:58:47 +01003228component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003229 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003230 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003231 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
3232 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02003233
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003234 msg "test: main suites (MSan)" # ~ 10s
3235 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003236
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003237 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003238 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003239
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003240 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003241
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003242 if [ "$MEMORY" -gt 0 ]; then
3243 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003244 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003245 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003246}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003247
Gilles Peskine69f190e2019-01-10 00:11:42 +01003248component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003249 msg "build: Release (clang)"
Gilles Peskine619b73d2022-11-29 16:45:30 +01003250 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003251 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3252 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003253
Gilles Peskine619b73d2022-11-29 16:45:30 +01003254 msg "test: main suites, Valgrind (default config)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003255 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003256
Gilles Peskine636c26a2020-03-04 20:46:15 +01003257 # Optional parts (slow; currently broken on OS X because programs don't
3258 # seem to receive signals under valgrind on OS X).
Gilles Peskine619b73d2022-11-29 16:45:30 +01003259 # These optional parts don't run on the CI.
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003260 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003261 msg "test: ssl-opt.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003262 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003263 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003264
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003265 if [ "$MEMORY" -gt 1 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003266 msg "test: compat.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003267 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003268 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003269
3270 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003271 msg "test: context-info.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003272 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003273 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003274}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003275
Gilles Peskine619b73d2022-11-29 16:45:30 +01003276component_test_valgrind_psa () {
3277 msg "build: Release, full (clang)"
3278 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
3279 scripts/config.py full
3280 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3281 make
3282
3283 msg "test: main suites, Valgrind (full config)"
3284 make memcheck
3285}
3286
Paul Elliott2ab9a7a2021-11-25 17:29:40 +00003287support_test_cmake_out_of_source () {
3288 distrib_id=""
3289 distrib_ver=""
3290 distrib_ver_minor=""
3291 distrib_ver_major=""
3292
3293 # Attempt to parse lsb-release to find out distribution and version. If not
3294 # found this should fail safe (test is supported).
3295 if [[ -f /etc/lsb-release ]]; then
3296
3297 while read -r lsb_line; do
3298 case "$lsb_line" in
3299 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
3300 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
3301 esac
3302 done < /etc/lsb-release
3303
3304 distrib_ver_major="${distrib_ver%%.*}"
3305 distrib_ver="${distrib_ver#*.}"
3306 distrib_ver_minor="${distrib_ver%%.*}"
3307 fi
3308
3309 # Running the out of source CMake test on Ubuntu 16.04 using more than one
3310 # processor (as the CI does) can create a race condition whereby the build
3311 # fails to see a generated file, despite that file actually having been
3312 # generated. This problem appears to go away with 18.04 or newer, so make
3313 # the out of source tests unsupported on Ubuntu 16.04.
3314 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
3315}
3316
Gilles Peskine8f073122018-11-27 15:58:47 +01003317component_test_cmake_out_of_source () {
3318 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01003319 MBEDTLS_ROOT_DIR="$PWD"
3320 mkdir "$OUT_OF_SOURCE_DIR"
3321 cd "$OUT_OF_SOURCE_DIR"
Gilles Peskine25319702021-10-07 19:34:57 +02003322 cmake -D CMAKE_BUILD_TYPE:String=Check "$MBEDTLS_ROOT_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003323 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003324
Gilles Peskine8f073122018-11-27 15:58:47 +01003325 msg "test: cmake 'out-of-source' build"
3326 make test
3327 # Test an SSL option that requires an auxiliary script in test/scripts/.
3328 # Also ensure that there are no error messages such as
3329 # "No such file or directory", which would indicate that some required
3330 # file is missing (ssl-opt.sh tolerates the absence of some files so
3331 # may exit with status 0 but emit errors).
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003332 ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' >ssl-opt.out 2>ssl-opt.err
3333 grep PASS ssl-opt.out
Gilles Peskine0a7984f2020-03-28 18:56:09 +01003334 cat ssl-opt.err >&2
3335 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003336 [ ! -s ssl-opt.err ]
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003337 rm ssl-opt.out ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01003338 cd "$MBEDTLS_ROOT_DIR"
3339 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003340}
Andres AGdc192212016-08-31 17:33:13 +01003341
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003342component_test_cmake_as_subdirectory () {
3343 msg "build: cmake 'as-subdirectory' build"
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003344 cd programs/test/cmake_subproject
3345 cmake .
3346 make
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003347 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003348}
Gilles Peskineca9cfca2022-02-04 00:21:12 +01003349support_test_cmake_as_subdirectory () {
3350 support_test_cmake_out_of_source
3351}
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003352
Gilles Peskine8f073122018-11-27 15:58:47 +01003353component_test_zeroize () {
3354 # Test that the function mbedtls_platform_zeroize() is not optimized away by
3355 # different combinations of compilers and optimization flags by using an
3356 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
3357 # system in all cases that the script fails, so we must manually search the
3358 # output to check whether the pass string is present and no failure strings
3359 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01003360
Gilles Peskine4976e822019-01-06 19:52:22 +00003361 # Don't try to disable ASLR. We don't care about ASLR here. We do care
3362 # about a spurious message if Gdb tries and fails, so suppress that.
3363 gdb_disable_aslr=
3364 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
3365 gdb_disable_aslr='set disable-randomization off'
3366 fi
3367
Gilles Peskine8f073122018-11-27 15:58:47 +01003368 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01003369 for compiler in clang gcc; do
3370 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
3371 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003372 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
3373 grep "The buffer was correctly zeroized" test_zeroize.log
3374 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01003375 rm -f test_zeroize.log
3376 make clean
3377 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01003378 done
Gilles Peskine8f073122018-11-27 15:58:47 +01003379}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003380
Bence Szépkúti9f849112021-10-19 15:05:36 +02003381component_test_psa_compliance () {
Bence Szépkútic1e79fd2021-11-11 20:13:14 +01003382 msg "build: make, default config + CMAC, libmbedcrypto.a only"
3383 scripts/config.py set MBEDTLS_CMAC_C
Bence Szépkútiab796e62021-10-25 19:29:07 +02003384 make -C library libmbedcrypto.a
Bence Szépkúti9f849112021-10-19 15:05:36 +02003385
3386 msg "unit test: test_psa_compliance.py"
3387 ./tests/scripts/test_psa_compliance.py
3388}
3389
3390support_test_psa_compliance () {
Bence Szépkútid6cf0892021-11-03 11:36:09 +01003391 # psa-compliance-tests only supports CMake >= 3.10.0
Bence Szépkútiab796e62021-10-25 19:29:07 +02003392 ver="$(cmake --version)"
3393 ver="${ver#cmake version }"
3394 ver_major="${ver%%.*}"
3395
3396 ver="${ver#*.}"
3397 ver_minor="${ver%%.*}"
3398
3399 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
Bence Szépkúti9f849112021-10-19 15:05:36 +02003400}
3401
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003402component_check_code_style () {
3403 msg "Check C code style"
3404 ./scripts/code_style.py
David Horstmanne09c4762022-11-10 18:30:52 +00003405}
3406
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003407support_check_code_style() {
David Horstmanne09c4762022-11-10 18:30:52 +00003408 case $(uncrustify --version) in
3409 *0.75.1*) true;;
3410 *) false;;
3411 esac
3412}
3413
Gilles Peskine8f073122018-11-27 15:58:47 +01003414component_check_python_files () {
3415 msg "Lint: Python scripts"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003416 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003417}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003418
Gilles Peskine8f073122018-11-27 15:58:47 +01003419component_check_generate_test_code () {
3420 msg "uint test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02003421 # unittest writes out mundane stuff like number or tests run on stderr.
3422 # Our convention is to reserve stderr for actual errors, and write
3423 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003424 ./tests/scripts/test_generate_test_code.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01003425}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003426
3427################################################################
3428#### Termination
3429################################################################
3430
Gilles Peskine8f073122018-11-27 15:58:47 +01003431post_report () {
3432 msg "Done, cleaning up"
Gilles Peskine24bdf022020-03-30 20:11:39 +02003433 final_cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003434
Gilles Peskine8f073122018-11-27 15:58:47 +01003435 final_report
3436}
3437
3438
3439
3440################################################################
3441#### Run all the things
3442################################################################
3443
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003444# Function invoked by --error-test to test error reporting.
3445pseudo_component_error_test () {
Gilles Peskine202e9b42021-08-02 23:28:00 +02003446 msg "Testing error reporting $error_test_i"
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003447 if [ $KEEP_GOING -ne 0 ]; then
3448 echo "Expect three failing commands."
3449 fi
Gilles Peskine202e9b42021-08-02 23:28:00 +02003450 # If the component doesn't run in a subshell, changing error_test_i to an
3451 # invalid integer will cause an error in the loop that runs this function.
3452 error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003453 # Expected error: 'grep non_existent /dev/null -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003454 grep non_existent /dev/null
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003455 # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003456 not grep -q . "$0"
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003457 # Expected error: 'make unknown_target -> 2'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003458 make unknown_target
3459 false "this should not be executed"
3460}
3461
Gilles Peskinee48351a2018-11-27 16:06:30 +01003462# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01003463run_component () {
Gilles Peskineffcdeff2018-12-04 12:49:28 +01003464 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02003465 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003466
3467 # Unconditionally create a seedfile that's sufficiently long.
3468 # Do this before each component, because a previous component may
3469 # have messed it up or shortened it.
Gilles Peskinef3133362021-07-08 19:03:50 +02003470 local dd_cmd
3471 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
3472 case $OSTYPE in
3473 linux*|freebsd*|openbsd*|darwin*) dd_cmd+=(status=none)
3474 esac
3475 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003476
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003477 # Run the component in a subshell, with error trapping and output
3478 # redirection set up based on the relevant options.
Gilles Peskine7105a332020-03-28 18:50:43 +01003479 if [ $KEEP_GOING -eq 1 ]; then
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003480 # We want to keep running if the subshell fails, so 'set -e' must
3481 # be off when the subshell runs.
Gilles Peskine7105a332020-03-28 18:50:43 +01003482 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02003483 fi
Gilles Peskine7105a332020-03-28 18:50:43 +01003484 (
3485 if [ $QUIET -eq 1 ]; then
3486 # msg() will be silenced, so just print the component name here.
3487 echo "${current_component#component_}"
3488 exec >/dev/null
3489 fi
3490 if [ $KEEP_GOING -eq 1 ]; then
3491 # Keep "set -e" off, and run an ERR trap instead to record failures.
3492 set -E
3493 trap err_trap ERR
3494 fi
3495 # The next line is what runs the component
3496 "$@"
3497 if [ $KEEP_GOING -eq 1 ]; then
3498 trap - ERR
3499 exit $last_failure_status
3500 fi
3501 )
3502 component_status=$?
3503 if [ $KEEP_GOING -eq 1 ]; then
3504 set -e
3505 if [ $component_status -ne 0 ]; then
3506 failure_count=$((failure_count + 1))
3507 fi
3508 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003509
3510 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01003511 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02003512 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01003513}
3514
3515# Preliminary setup
3516pre_check_environment
3517pre_initialize_variables
3518pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01003519
Gilles Peskine878cf602019-01-06 20:50:38 +00003520pre_check_git
Gilles Peskineef64e7f2021-07-12 18:16:01 +02003521pre_restore_files
Gilles Peskine24bdf022020-03-30 20:11:39 +02003522pre_back_up
Andrzej Kurekeb508712019-02-14 07:18:59 -05003523
Gilles Peskine878cf602019-01-06 20:50:38 +00003524build_status=0
3525if [ $KEEP_GOING -eq 1 ]; then
3526 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01003527fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02003528pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00003529pre_print_configuration
3530pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003531cleanup
3532
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003533# Run the requested tests.
Gilles Peskine202e9b42021-08-02 23:28:00 +02003534for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003535 run_component pseudo_component_error_test
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003536done
Gilles Peskine202e9b42021-08-02 23:28:00 +02003537unset error_test_i
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003538for component in $RUN_COMPONENTS; do
3539 run_component "component_$component"
3540done
Gilles Peskine8f073122018-11-27 15:58:47 +01003541
3542# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00003543post_report