blob: b5c8cd374200c616fe94c4646d5fbc7d4b33944b [file] [log] [blame]
Gilles Peskine3de7be82020-03-27 16:35:23 +01001#! /usr/bin/env bash
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
Bence Szépkúti1e148272020-08-07 13:07:28 +02005# Copyright The Mbed TLS Contributors
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02006# SPDX-License-Identifier: Apache-2.0
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
Gilles Peskine192c72f2017-12-21 15:59:21 +010019
20
21
22################################################################
23#### Documentation
24################################################################
25
Simon Butcher3ea7f522016-03-07 23:22:10 +000026# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010027# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000028#
SimonB2e23c822016-04-16 21:54:39 +010029# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# Notes for users
32# ---------------
33#
SimonB2e23c822016-04-16 21:54:39 +010034# Warning: the test is destructive. It includes various build modes and
35# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010036# configuration. The following files must be committed into git:
37# * include/mbedtls/config.h
Gilles Peskine636c26a2020-03-04 20:46:15 +010038# * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
39# programs/fuzz/Makefile
Gilles Peskine192c72f2017-12-21 15:59:21 +010040# After running this script, the CMake cache will be lost and CMake
41# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010042#
Gilles Peskine192c72f2017-12-21 15:59:21 +010043# The script assumes the presence of a number of tools:
44# * Basic Unix tools (Windows users note: a Unix-style find must be before
45# the Windows find in the PATH)
46# * Perl
47# * GNU Make
48# * CMake
49# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040050# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010051# * arm-gcc and mingw-gcc
52# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010053# * OpenSSL and GnuTLS command line tools, recent enough for the
54# interoperability tests. If they don't support SSLv3 then a legacy
55# version of these tools must be present as well (search for LEGACY
56# below).
57# See the invocation of check_tools below for details.
58#
59# This script must be invoked from the toplevel directory of a git
60# working copy of Mbed TLS.
61#
Gilles Peskine7105a332020-03-28 18:50:43 +010062# The behavior on an error depends on whether --keep-going (alias -k)
63# is in effect.
64# * Without --keep-going: the script stops on the first error without
65# cleaning up. This lets you work in the configuration of the failing
66# component.
67# * With --keep-going: the script runs all requested components and
68# reports failures at the end. In particular the script always cleans
69# up on exit.
70#
Gilles Peskine192c72f2017-12-21 15:59:21 +010071# Note that the output is not saved. You may want to run
72# script -c tests/scripts/all.sh
73# or
74# tests/scripts/all.sh >all.log 2>&1
75#
76# Notes for maintainers
77# ---------------------
78#
Gilles Peskine8f073122018-11-27 15:58:47 +010079# The bulk of the code is organized into functions that follow one of the
80# following naming conventions:
81# * pre_XXX: things to do before running the tests, in order.
82# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010083# * component_check_XXX: quick tests that aren't worth parallelizing.
84# * component_build_XXX: build things but don't run them.
85# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000086# * support_XXX: if support_XXX exists and returns false then
87# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010088# * post_XXX: things to do after running the tests.
89# * other: miscellaneous support functions.
90#
Gilles Peskinec70637a2019-01-09 22:29:17 +010091# Each component must start by invoking `msg` with a short informative message.
92#
Gilles Peskine39a3b112020-03-28 21:27:40 +010093# Warning: due to the way bash detects errors, the failure of a command
94# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
95#
Gilles Peskine7105a332020-03-28 18:50:43 +010096# Each component is executed in a separate shell process. The component
97# fails if any command in it returns a non-zero status.
98#
Gilles Peskinec70637a2019-01-09 22:29:17 +010099# The framework performs some cleanup tasks after each component. This
100# means that components can assume that the working directory is in a
101# cleaned-up state, and don't need to perform the cleanup themselves.
102# * Run `make clean`.
103# * Restore `include/mbedtks/config.h` from a backup made before running
104# the component.
Gilles Peskine636c26a2020-03-04 20:46:15 +0100105# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
106# `tests/Makefile` and `programs/fuzz/Makefile` from git.
107# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +0100108#
Gilles Peskine192c72f2017-12-21 15:59:21 +0100109# The tests are roughly in order from fastest to slowest. This doesn't
110# have to be exact, but in general you should add slower tests towards
111# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100112
113
114
115################################################################
116#### Initialization and command line parsing
117################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100118
Gilles Peskine8ab29942020-03-28 18:50:49 +0100119# Abort on errors (even on the left-hand side of a pipe).
120# Treat uninitialised variables as errors.
121set -e -o pipefail -u
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100122
Gilles Peskine79598582022-08-30 21:02:44 +0200123# Enable ksh/bash extended file matching patterns
124shopt -s extglob
125
Gilles Peskine8f073122018-11-27 15:58:47 +0100126pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000127 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskine8f073122018-11-27 15:58:47 +0100128 echo "Must be run from mbed TLS root" >&2
129 exit 1
130 fi
131}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100132
Gilles Peskine8f073122018-11-27 15:58:47 +0100133pre_initialize_variables () {
134 CONFIG_H='include/mbedtls/config.h'
John Durkopbd069d32020-10-31 22:14:03 -0700135 CRYPTO_CONFIG_H='include/psa/crypto_config.h'
Gilles Peskine24bdf022020-03-30 20:11:39 +0200136
137 # Files that are clobbered by some jobs will be backed up. Use a different
138 # suffix from auxiliary scripts so that all.sh and auxiliary scripts can
139 # independently decide when to remove the backup file.
140 backup_suffix='.all.bak'
141 # Files clobbered by config.py
142 files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H"
Gilles Peskineef64e7f2021-07-12 18:16:01 +0200143 # Files clobbered by in-tree cmake
144 files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile"
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200145
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200146 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100147 MEMORY=0
148 FORCE=0
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200149 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100150 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100151
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200152 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard54304472020-06-22 10:11:47 +0200153 #
154 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
155 # both values are kept in sync. If you change the value here because it
156 # breaks some tests, you'll definitely want to change it in
157 # basic-build-test.sh as well.
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200158 RELEASE_SEED=1
159
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200160 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200161 : ${MBEDTLS_TEST_PLATFORM="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200162 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200163 export MBEDTLS_TEST_PLATFORM
164
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000165 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100166 : ${OPENSSL:="openssl"}
167 : ${OPENSSL_LEGACY:="$OPENSSL"}
168 : ${OPENSSL_NEXT:="$OPENSSL"}
169 : ${GNUTLS_CLI:="gnutls-cli"}
170 : ${GNUTLS_SERV:="gnutls-serv"}
171 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
172 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
173 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
174 : ${ARMC5_BIN_DIR:=/usr/bin}
175 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskine6d061342020-04-30 18:19:32 +0200176 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200177 : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
Andres AGdc192212016-08-31 17:33:13 +0100178
Gilles Peskine8f073122018-11-27 15:58:47 +0100179 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000180 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine85229ac2021-09-30 18:24:21 +0200181 export MAKEFLAGS="-j$(all_sh_nproc)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100182 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000183
Gilles Peskinec761d8f2021-09-20 18:57:55 +0200184 # Include more verbose output for failing tests run by CMake or make
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000185 export CTEST_OUTPUT_ON_FAILURE=1
186
Gilles Peskine8fd59422019-10-21 17:11:33 +0200187 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Manuel Pégourié-Gonnard717f2302022-11-30 10:42:03 +0100188 # default to -O2, use -Ox _after_ this if you want another level
Manuel Pégourié-Gonnard154b84e2022-11-28 13:12:10 +0100189 ASAN_CFLAGS='-O2 -Werror -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200190
Gilles Peskine878cf602019-01-06 20:50:38 +0000191 # Gather the list of available components. These are the functions
192 # defined in this script whose name starts with "component_".
Gowtham Suresh Kumar13850f32023-07-28 16:41:21 +0100193 ALL_COMPONENTS=$(compgen -A function component_ | sed 's/component_//')
Gilles Peskine878cf602019-01-06 20:50:38 +0000194
195 # Exclude components that are not supported on this platform.
196 SUPPORTED_COMPONENTS=
197 for component in $ALL_COMPONENTS; do
198 case $(type "support_$component" 2>&1) in
199 *' function'*)
200 if ! support_$component; then continue; fi;;
201 esac
202 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
203 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100204}
Andres AG38495a32016-07-12 16:54:33 +0100205
Gilles Peskinea28db922019-01-10 00:05:18 +0100206# Test whether the component $1 is included in the command line patterns.
207is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100208{
Gilles Peskine6702ce92021-08-06 11:35:17 +0200209 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
210 # only does word splitting.
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100211 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000212 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100213 set +f
214 case ${1#component_} in $pattern) return 0;; esac
215 done
216 set +f
217 return 1
218}
Andres AG7770ea82016-10-10 15:46:20 +0100219
Simon Butcher41eeccf2016-09-07 00:07:09 +0100220usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100221{
Gilles Peskine709346a2017-12-10 23:43:39 +0100222 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100223Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100224Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100225By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100226COMPONENT can be the name of a component or a shell wildcard pattern.
227
228Examples:
229 $0 "check_*"
230 Run all sanity checks.
231 $0 --no-armcc --except test_memsan
232 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100233
234Special options:
235 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000236 --list-all-components List all available test components and exit.
237 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100238
239General options:
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200240 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100241 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100242 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100243 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200244 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200245 --arm-none-eabi-gcc-prefix=<string>
246 Prefix for a cross-compiler for arm-none-eabi
247 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200248 --arm-linux-gnueabi-gcc-prefix=<string>
249 Prefix for a cross-compiler for arm-linux-gnueabi
250 (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100251 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200252 --restore First clean up the build tree, restoring backed up
253 files. Do not run any components unless they are
254 explicitly specified.
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100255 --error-test Error test mode: run a failing function in addition
Gilles Peskinea25c5672021-08-05 15:11:33 +0200256 to any specified component. May be repeated.
Gilles Peskinea28db922019-01-10 00:05:18 +0100257 --except Exclude the COMPONENTs listed on the command line,
258 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200259 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100260 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100261 --no-force Refuse to overwrite modified files (default).
262 --no-keep-going Stop at the first error (default).
263 --no-memory No additional memory tests (default).
Shaun Case0e7791f2021-12-20 21:14:10 -0800264 --no-quiet Print full output from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100265 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200266 --outcome-file=<path> File where test outcomes are written (not done if
267 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100268 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200269 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100270 -s|--seed Integer seed value to use for this test run.
271
272Tool path options:
273 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
274 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
275 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
276 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
277 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
278 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
279 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
280 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100281 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100282EOF
SimonB2e23c822016-04-16 21:54:39 +0100283}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100284
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200285# Cleanup before/after running a component.
286# Remove built files as well as the cmake cache/config.
287# Does not remove generated source files.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100288cleanup()
289{
Gilles Peskine7c652162017-12-11 00:01:40 +0100290 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200291
Gilles Peskine31b07e22018-03-21 12:15:06 +0100292 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000293 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100294 -iname CMakeFiles -exec rm -rf {} \+ -o \
295 \( -iname cmake_install.cmake -o \
296 -iname CTestTestfile.cmake -o \
297 -iname CMakeCache.txt \) -exec rm {} \+
298 # Recover files overwritten by in-tree CMake builds
Gilles Peskine79598582022-08-30 21:02:44 +0200299 rm -f include/Makefile include/mbedtls/Makefile programs/!(fuzz)/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200300
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100301 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
302 rm -rf programs/test/cmake_subproject/build
303 rm -f programs/test/cmake_subproject/Makefile
304 rm -f programs/test/cmake_subproject/cmake_subproject
305
Gilles Peskine24bdf022020-03-30 20:11:39 +0200306 # Restore files that may have been clobbered by the job
307 for x in $files_to_back_up; do
Gilles Peskine423dd132022-08-30 21:02:00 +0200308 if [[ -e "$x$backup_suffix" ]]; then
309 cp -p "$x$backup_suffix" "$x"
310 fi
Gilles Peskine24bdf022020-03-30 20:11:39 +0200311 done
312}
John Durkopbd069d32020-10-31 22:14:03 -0700313
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200314# Final cleanup when this script exits (except when exiting on a failure
315# in non-keep-going mode).
Gilles Peskine24bdf022020-03-30 20:11:39 +0200316final_cleanup () {
317 cleanup
318
319 for x in $files_to_back_up; do
320 rm -f "$x$backup_suffix"
321 done
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100322}
323
Gilles Peskine7c652162017-12-11 00:01:40 +0100324# Executed on exit. May be redefined depending on command line options.
325final_report () {
326 :
327}
328
329fatal_signal () {
Gilles Peskine24bdf022020-03-30 20:11:39 +0200330 final_cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100331 final_report $1
332 trap - $1
333 kill -$1 $$
334}
335
336trap 'fatal_signal HUP' HUP
337trap 'fatal_signal INT' INT
338trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200339
Gilles Peskine85229ac2021-09-30 18:24:21 +0200340# Number of processors on this machine. Used as the default setting
341# for parallel make.
342all_sh_nproc ()
343{
344 {
345 nproc || # Linux
346 sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
347 sysctl -n hw.ncpu || # FreeBSD
348 echo 1
349 } 2>/dev/null
350}
351
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100352msg()
353{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100354 if [ -n "${current_component:-}" ]; then
355 current_section="${current_component#component_}: $1"
356 else
357 current_section="$1"
358 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200359
360 if [ $QUIET -eq 1 ]; then
361 return
362 fi
363
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100364 echo ""
365 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100366 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000367 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100368 echo "******************************************************************"
369}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100370
Gilles Peskine8f073122018-11-27 15:58:47 +0100371armc6_build_test()
372{
373 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100374
Gilles Peskine18487f62020-04-30 23:11:54 +0200375 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100376 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
Dave Rodgman6cda3d32023-03-02 13:39:04 +0000377 WARNING_CFLAGS='-Werror -xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200378
379 msg "size: ARM Compiler 6 ($FLAGS)"
380 "$ARMC6_FROMELF" -z library/*.o
381
Gilles Peskine8f073122018-11-27 15:58:47 +0100382 make clean
383}
Andres AGa5cd9732016-10-17 15:23:10 +0100384
Andres AGd9eba4b2016-08-26 14:42:14 +0100385err_msg()
386{
387 echo "$1" >&2
388}
389
390check_tools()
391{
392 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000393 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100394 err_msg "$TOOL not found!"
395 exit 1
396 fi
397 done
398}
399
Gilles Peskine8f073122018-11-27 15:58:47 +0100400pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000401 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100402 all_except=0
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100403 error_test=0
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200404 restore_first=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000405 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100406
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000407 # Note that legacy options are ignored instead of being omitted from this
408 # list of options, so invocations that worked with previous version of
409 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100410 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100411 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200412 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200413 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200414 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000415 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100416 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
417 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100418 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000419 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100420 --force|-f) FORCE=1;;
421 --gnutls-cli) shift; GNUTLS_CLI="$1";;
422 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
423 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
424 --gnutls-serv) shift; GNUTLS_SERV="$1";;
425 --help|-h) usage; exit;;
426 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000427 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
428 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100429 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200430 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000431 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100432 --no-force) FORCE=0;;
433 --no-keep-going) KEEP_GOING=0;;
434 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200435 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100436 --openssl) shift; OPENSSL="$1";;
437 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
438 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200439 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100440 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200441 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100442 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200443 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200444 --restore) restore_first=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100445 --seed|-s) shift; SEED="$1";;
446 -*)
447 echo >&2 "Unknown option: $1"
448 echo >&2 "Run $0 --help for usage."
449 exit 120
450 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000451 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100452 esac
453 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100454 done
SimonB2e23c822016-04-16 21:54:39 +0100455
Gilles Peskinea28db922019-01-10 00:05:18 +0100456 # With no list of components, run everything.
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200457 if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000458 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100459 fi
460
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000461 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
462 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100463 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000464 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100465 fi
SimonB2e23c822016-04-16 21:54:39 +0100466
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200467 # Error out if an explicitly requested component doesn't exist.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100468 if [ $all_except -eq 0 ]; then
469 unsupported=0
Gilles Peskine6702ce92021-08-06 11:35:17 +0200470 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
471 # only does word splitting.
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200472 set -f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100473 for component in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200474 set +f
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200475 # If the requested name includes a wildcard character, don't
476 # check it. Accept wildcard patterns that don't match anything.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100477 case $component in
478 *[*?\[]*) continue;;
479 esac
480 case " $SUPPORTED_COMPONENTS " in
481 *" $component "*) :;;
482 *)
483 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
484 unsupported=$((unsupported + 1));;
485 esac
486 done
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200487 set +f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100488 if [ $unsupported -ne 0 ]; then
489 exit 2
490 fi
491 fi
492
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000493 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100494 RUN_COMPONENTS=
495 for component in $SUPPORTED_COMPONENTS; do
496 if is_component_included "$component"; [ $? -eq $all_except ]; then
497 RUN_COMPONENTS="$RUN_COMPONENTS $component"
498 fi
499 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000500
501 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000502 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100503}
SimonB2e23c822016-04-16 21:54:39 +0100504
Gilles Peskine8f073122018-11-27 15:58:47 +0100505pre_check_git () {
506 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100507 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100508 git checkout-index -f -q $CONFIG_H
509 cleanup
510 else
SimonB2e23c822016-04-16 21:54:39 +0100511
Gilles Peskine8f073122018-11-27 15:58:47 +0100512 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
513 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
514 echo "You can either delete this directory manually, or force the test by rerunning"
515 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
516 exit 1
517 fi
518
Gilles Peskined1174cf2019-01-09 22:30:01 +0100519 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100520 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
521 echo "You can either delete or preserve your work, or force the test by rerunning the"
522 echo "script as: $0 --force"
523 exit 1
524 fi
SimonB2e23c822016-04-16 21:54:39 +0100525 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500526}
527
Gilles Peskineef64e7f2021-07-12 18:16:01 +0200528pre_restore_files () {
529 # If the makefiles have been generated by a framework such as cmake,
530 # restore them from git. If the makefiles look like modifications from
531 # the ones checked into git, take care not to modify them. Whatever
532 # this function leaves behind is what the script will restore before
533 # each component.
534 case "$(head -n1 Makefile)" in
535 *[Gg]enerated*)
536 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
537 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
538 ;;
539 esac
540}
541
Gilles Peskine24bdf022020-03-30 20:11:39 +0200542pre_back_up () {
543 for x in $files_to_back_up; do
544 cp -p "$x" "$x$backup_suffix"
545 done
546}
547
Gilles Peskine8f073122018-11-27 15:58:47 +0100548pre_setup_keep_going () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100549 failure_count=0 # Number of failed components
550 last_failure_status=0 # Last failure status in this component
551
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100552 # See err_trap
553 previous_failure_status=0
554 previous_failed_command=
555 previous_failure_funcall_depth=0
Gilles Peskine39a3b112020-03-28 21:27:40 +0100556 unset report_failed_command
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100557
Gilles Peskine7c652162017-12-11 00:01:40 +0100558 start_red=
559 end_color=
560 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100561 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100562 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
563 start_red=$(printf '\033[31m')
564 end_color=$(printf '\033[0m')
565 ;;
566 esac
567 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100568
569 # Keep a summary of failures in a file. We'll print it out at the end.
570 failure_summary_file=$PWD/all-sh-failures-$$.log
571 : >"$failure_summary_file"
572
573 # Whether it makes sense to keep a component going after the specified
574 # command fails (test command) or not (configure or build).
Gilles Peskine6702ce92021-08-06 11:35:17 +0200575 # This function normally receives the failing simple command
576 # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
577 # this is passed instead.
Gilles Peskine7105a332020-03-28 18:50:43 +0100578 # This doesn't have to be 100% accurate: all failures are recorded anyway.
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200579 # False positives result in running things that can't be expected to
580 # work. False negatives result in things not running after something else
581 # failed even though they might have given useful feedback.
Gilles Peskine7105a332020-03-28 18:50:43 +0100582 can_keep_going_after_failure () {
583 case "$1" in
584 "msg "*) false;;
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200585 "cd "*) false;;
586 *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
587 *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
588 *make*check*) true;;
589 "grep "*) true;;
590 "[ "*) true;;
591 "! "*) true;;
Gilles Peskine7105a332020-03-28 18:50:43 +0100592 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100593 esac
594 }
Gilles Peskine7105a332020-03-28 18:50:43 +0100595
596 # This function runs if there is any error in a component.
597 # It must either exit with a nonzero status, or set
598 # last_failure_status to a nonzero value.
599 err_trap () {
600 # Save $? (status of the failing command). This must be the very
601 # first thing, before $? is overridden.
602 last_failure_status=$?
Gilles Peskine39a3b112020-03-28 21:27:40 +0100603 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskine7105a332020-03-28 18:50:43 +0100604
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100605 if [[ $last_failure_status -eq $previous_failure_status &&
606 "$failed_command" == "$previous_failed_command" &&
607 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
608 then
609 # The same command failed twice in a row, but this time one level
610 # less deep in the function call stack. This happens when the last
611 # command of a function returns a nonzero status, and the function
612 # returns that same status. Ignore the second failure.
613 previous_failure_funcall_depth=${#FUNCNAME[@]}
614 return
615 fi
616 previous_failure_status=$last_failure_status
617 previous_failed_command=$failed_command
618 previous_failure_funcall_depth=${#FUNCNAME[@]}
619
Gilles Peskine7105a332020-03-28 18:50:43 +0100620 text="$current_section: $failed_command -> $last_failure_status"
621 echo "${start_red}^^^^$text^^^^${end_color}" >&2
622 echo "$text" >>"$failure_summary_file"
623
624 # If the command is fatal (configure or build command), stop this
625 # component. Otherwise (test command) keep the component running
626 # (run more tests from the same build).
627 if ! can_keep_going_after_failure "$failed_command"; then
628 exit $last_failure_status
629 fi
630 }
631
Gilles Peskine7c652162017-12-11 00:01:40 +0100632 final_report () {
633 if [ $failure_count -gt 0 ]; then
634 echo
635 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskine7105a332020-03-28 18:50:43 +0100636 echo "${start_red}FAILED: $failure_count components${end_color}"
637 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100638 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
639 elif [ -z "${1-}" ]; then
640 echo "SUCCESS :)"
641 fi
642 if [ -n "${1-}" ]; then
643 echo "Killed by SIG$1."
644 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100645 rm -f "$failure_summary_file"
646 if [ $failure_count -gt 0 ]; then
647 exit 1
648 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100649 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100650}
651
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200652# record_status() and if_build_succeeded() are kept temporarily for backward
653# compatibility. Don't use them in new components.
Gilles Peskine7105a332020-03-28 18:50:43 +0100654record_status () {
655 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100656}
Gilles Peskine7c652162017-12-11 00:01:40 +0100657if_build_succeeded () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100658 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100659}
660
Gilles Peskine39a3b112020-03-28 21:27:40 +0100661# '! true' does not trigger the ERR trap. Arrange to trigger it, with
662# a reasonably informative error message (not just "$@").
663not () {
664 if "$@"; then
665 report_failed_command="! $*"
666 false
667 unset report_failed_command
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200668 fi
669}
670
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200671pre_prepare_outcome_file () {
672 case "$MBEDTLS_TEST_OUTCOME_FILE" in
673 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
674 esac
675 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
676 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
677 fi
678}
679
Gilles Peskine8f073122018-11-27 15:58:47 +0100680pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200681 if [ $QUIET -eq 1 ]; then
682 return
683 fi
684
Gilles Peskine8f073122018-11-27 15:58:47 +0100685 msg "info: $0 configuration"
686 echo "MEMORY: $MEMORY"
687 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200688 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100689 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100690 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100691 echo "OPENSSL: $OPENSSL"
692 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
693 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
694 echo "GNUTLS_CLI: $GNUTLS_CLI"
695 echo "GNUTLS_SERV: $GNUTLS_SERV"
696 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
697 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
698 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
699 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
700}
Andres AG7770ea82016-10-10 15:46:20 +0100701
Andres AGd9eba4b2016-08-26 14:42:14 +0100702# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100703pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000704 # Build the list of variables to pass to output_env.sh.
705 set env
SimonB2e23c822016-04-16 21:54:39 +0100706
Gilles Peskine87964262019-01-06 22:40:00 +0000707 case " $RUN_COMPONENTS " in
708 # Require OpenSSL and GnuTLS if running any tests (as opposed to
709 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
710 # is a good enough approximation in practice.
711 *" test_"*)
712 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
713 # and ssl-opt.sh, we just export the variables they require.
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +0100714 export OPENSSL="$OPENSSL"
Gilles Peskine87964262019-01-06 22:40:00 +0000715 export GNUTLS_CLI="$GNUTLS_CLI"
716 export GNUTLS_SERV="$GNUTLS_SERV"
717 # Avoid passing --seed flag in every call to ssl-opt.sh
718 if [ -n "${SEED-}" ]; then
719 export SEED
720 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000721 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
722 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
723 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
724 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000725 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
726 "$GNUTLS_CLI" "$GNUTLS_SERV" \
727 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
728 ;;
729 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200730
Gilles Peskine87964262019-01-06 22:40:00 +0000731 case " $RUN_COMPONENTS " in
732 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
733 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100734
Gilles Peskine87964262019-01-06 22:40:00 +0000735 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200736 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000737 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100738
Gilles Peskine87964262019-01-06 22:40:00 +0000739 case " $RUN_COMPONENTS " in
740 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
741 esac
742
743 case " $RUN_COMPONENTS " in
744 *" test_zeroize "*) check_tools "gdb";;
745 esac
746
747 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000748 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000749 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
750 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200751 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000752 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
753 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200754 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
755 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
756 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000757 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000758
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200759 # past this point, no call to check_tool, only printing output
760 if [ $QUIET -eq 1 ]; then
761 return
762 fi
763
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000764 msg "info: output_env.sh"
765 case $RUN_COMPONENTS in
766 *_armcc*)
767 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
768 *) set "$@" RUN_ARMCC=0;;
769 esac
770 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100771}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100772
Gilles Peskine192c72f2017-12-21 15:59:21 +0100773
774
775################################################################
776#### Basic checks
777################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100778
779#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200780# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100781#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100782# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200783# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100784# 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 +0200785# time, so start with a GCC build).
786# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100787#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100788# Indicative running times are given for reference.
789
Gilles Peskine8f073122018-11-27 15:58:47 +0100790component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200791 msg "Check: recursion.pl" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200792 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100793}
Janos Follathb72c6782016-07-19 14:54:17 +0100794
Gilles Peskine8f073122018-11-27 15:58:47 +0100795component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200796 msg "Check: freshness of generated source files" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200797 tests/scripts/check-generated-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100798}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200799
Gilles Peskine8f073122018-11-27 15:58:47 +0100800component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200801 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200802 tests/scripts/check-doxy-blocks.pl
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_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200806 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200807 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100808}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200809
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200810component_check_changelog () {
811 msg "Check: changelog entries" # < 1s
812 rm -f ChangeLog.new
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200813 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200814 if [ -e ChangeLog.new ]; then
815 # Show the diff for information. It isn't an error if the diff is
816 # non-empty.
817 diff -u ChangeLog ChangeLog.new || true
818 rm ChangeLog.new
819 fi
820}
821
Gilles Peskine8f073122018-11-27 15:58:47 +0100822component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200823 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200824 tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100825}
Darryl Greena07039c2018-03-13 16:48:16 +0000826
Gilles Peskine895868b2019-09-19 21:30:05 +0200827component_check_test_cases () {
828 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200829 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200830 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200831 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200832 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200833 fi
Gilles Peskine58987962022-12-15 14:46:31 +0100834 tests/scripts/check_test_cases.py -q $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200835 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +0200836}
837
Gilles Peskine8f073122018-11-27 15:58:47 +0100838component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200839 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200840 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100841}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200842
Gilles Peskine192c72f2017-12-21 15:59:21 +0100843
Gilles Peskine636c26a2020-03-04 20:46:15 +0100844
Gilles Peskine192c72f2017-12-21 15:59:21 +0100845################################################################
846#### Build and test many configurations and targets
847################################################################
848
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200849component_test_default_out_of_box () {
850 msg "build: make, default config (out-of-box)" # ~1min
851 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200852 # Disable fancy stuff
853 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200854
855 msg "test: main suites make, default config (out-of-box)" # ~10s
856 make test
857
858 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200859 programs/test/selftest
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200860}
861
Gilles Peskine8f073122018-11-27 15:58:47 +0100862component_test_default_cmake_gcc_asan () {
863 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100864 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
865 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200866
Gilles Peskine8f073122018-11-27 15:58:47 +0100867 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
868 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200869
Gilles Peskine97bea012020-04-23 23:37:45 +0200870 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200871 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200872
Gilles Peskine8f073122018-11-27 15:58:47 +0100873 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200874 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200875
Gilles Peskine8f073122018-11-27 15:58:47 +0100876 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200877 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200878
879 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200880 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100881}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200882
Hanno Becker01635512019-02-26 14:27:09 +0000883component_test_full_cmake_gcc_asan () {
884 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200885 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000886 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
887 make
888
889 msg "test: main suites (inc. selftests) (full config, ASan build)"
890 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +0100891
Gilles Peskine97bea012020-04-23 23:37:45 +0200892 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200893 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200894
Gilles Peskine636c26a2020-03-04 20:46:15 +0100895 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200896 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100897
898 msg "test: compat.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200899 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200900
901 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200902 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100903}
904
Ronald Cronc3623db2020-10-29 10:51:32 +0100905component_test_psa_crypto_key_id_encodes_owner () {
906 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
907 scripts/config.py full
908 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
909 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
910 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
911 make
912
913 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
914 make test
915}
916
Gilles Peskine99a34622021-06-17 11:37:52 +0200917# check_renamed_symbols HEADER LIB
918# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
919# name is LIB.
920check_renamed_symbols () {
921 ! nm "$2" | sed 's/.* //' |
922 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
923}
924
Gilles Peskine984c19f2021-06-15 18:37:38 +0200925component_build_psa_crypto_spm () {
926 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
927 scripts/config.py full
928 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
929 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
930 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
931 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
932 # We can only compile, not link, since our test and sample programs
933 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
934 # is active.
935 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskine99a34622021-06-17 11:37:52 +0200936
937 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
938 # version is not present.
939 echo "Checking for renamed symbols in the library"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200940 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskine984c19f2021-06-15 18:37:38 +0200941}
942
Ronald Cron336678b2021-01-28 17:54:24 +0100943component_test_psa_crypto_client () {
944 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
945 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
946 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
947 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
948 make
949
950 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
951 make test
952}
953
Gilles Peskine636c26a2020-03-04 20:46:15 +0100954component_test_zlib_make() {
955 msg "build: zlib enabled, make"
956 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine6fa69862021-10-05 09:36:03 +0200957 make ZLIB=1 CFLAGS='-Werror -O2'
Gilles Peskine636c26a2020-03-04 20:46:15 +0100958
959 msg "test: main suites (zlib, make)"
960 make test
961
962 msg "test: ssl-opt.sh (zlib, make)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200963 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100964}
965support_test_zlib_make () {
966 base=support_test_zlib_$$
967 cat <<'EOF' > ${base}.c
968#include "zlib.h"
969int main(void) { return 0; }
970EOF
971 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
972 ret=$?
973 rm -f ${base}.*
974 return $ret
975}
976
977component_test_zlib_cmake() {
978 msg "build: zlib enabled, cmake"
979 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine25319702021-10-07 19:34:57 +0200980 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Release .
Gilles Peskine636c26a2020-03-04 20:46:15 +0100981 make
982
983 msg "test: main suites (zlib, cmake)"
984 make test
985
986 msg "test: ssl-opt.sh (zlib, cmake)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200987 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100988}
989support_test_zlib_cmake () {
990 support_test_zlib_make "$@"
Manuel Pégourié-Gonnardf2e29022020-01-24 10:17:20 +0100991}
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +0100992
Jaeden Ameroc17f2932021-05-14 08:34:32 +0100993component_test_psa_crypto_rsa_no_genprime() {
994 msg "build: default config minus MBEDTLS_GENPRIME"
995 scripts/config.py unset MBEDTLS_GENPRIME
996 make
997
998 msg "test: default config minus MBEDTLS_GENPRIME"
999 make test
1000}
1001
Gilles Peskine782f4112018-11-27 16:11:09 +01001002component_test_ref_configs () {
1003 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
1004 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001005 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +01001006}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001007
Gilles Peskine8f073122018-11-27 15:58:47 +01001008component_test_sslv3 () {
1009 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001010 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +01001011 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1012 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001013
Gilles Peskine8f073122018-11-27 15:58:47 +01001014 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
1015 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +00001016
Gilles Peskine8f073122018-11-27 15:58:47 +01001017 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Xiaofei Baif40545d2021-12-02 08:43:35 +00001018 tests/compat.sh -m 'tls1 tls1_1 tls12 dtls1 dtls12'
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001019 env OPENSSL="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3'
Simon Butcher3ea7f522016-03-07 23:22:10 +00001020
Gilles Peskine8f073122018-11-27 15:58:47 +01001021 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001022 tests/ssl-opt.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001023
1024 msg "build: SSLv3 - context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001025 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001026}
Simon Butcher3ea7f522016-03-07 23:22:10 +00001027
Gilles Peskine8f073122018-11-27 15:58:47 +01001028component_test_no_renegotiation () {
1029 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001030 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001031 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1032 make
Simon Butcher3ea7f522016-03-07 23:22:10 +00001033
Gilles Peskine8f073122018-11-27 15:58:47 +01001034 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1035 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +01001036
Gilles Peskine8f073122018-11-27 15:58:47 +01001037 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001038 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001039}
Hanno Becker134c2ab2017-10-12 15:29:50 +01001040
Gilles Peskine56194432023-02-01 18:44:11 +01001041component_test_no_certs () {
1042 msg "build: full minus MBEDTLS_CERTS_C"
1043 scripts/config.py full
1044 scripts/config.py unset MBEDTLS_CERTS_C
1045 # Quick build+test (we're checking for stray uses of the test certs,
1046 # not expecting their absence to lead to subtle problems).
1047 make
1048
1049 msg "test: full minus MBEDTLS_CERTS_C - main suites"
1050 make test
1051}
1052
Gilles Peskine636c26a2020-03-04 20:46:15 +01001053component_test_no_pem_no_fs () {
1054 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1055 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1056 scripts/config.py unset MBEDTLS_FS_IO
1057 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1058 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
1059 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1060 make
1061
1062 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1063 make test
1064
1065 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001066 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001067}
1068
Gilles Peskine8f073122018-11-27 15:58:47 +01001069component_test_rsa_no_crt () {
1070 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001071 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +01001072 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1073 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +01001074
Gilles Peskine8f073122018-11-27 15:58:47 +01001075 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1076 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001077
Gilles Peskine8f073122018-11-27 15:58:47 +01001078 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001079 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001080
Gilles Peskine8f073122018-11-27 15:58:47 +01001081 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001082 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001083
1084 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001085 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001086}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001087
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001088component_test_no_ctr_drbg_classic () {
1089 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001090 scripts/config.py full
1091 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001092 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001093
1094 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1095 make
1096
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001097 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001098 make test
1099
Gilles Peskineba749042021-01-13 20:02:03 +01001100 # In this configuration, the TLS test programs use HMAC_DRBG.
1101 # The SSL tests are slow, so run a small subset, just enough to get
1102 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001103 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001104 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001105
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001106 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001107 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001108}
1109
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001110component_test_no_ctr_drbg_use_psa () {
1111 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001112 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001113 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1114 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001115
1116 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1117 make
1118
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001119 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1120 make test
1121
1122 # In this configuration, the TLS test programs use HMAC_DRBG.
1123 # The SSL tests are slow, so run a small subset, just enough to get
1124 # confidence that the SSL code copes with HMAC_DRBG.
1125 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001126 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001127
1128 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001129 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001130}
1131
1132component_test_no_hmac_drbg_classic () {
1133 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1134 scripts/config.py full
1135 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1136 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1137 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1138
1139 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1140 make
1141
1142 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001143 make test
1144
Gilles Peskinea2224342020-11-19 22:14:34 +01001145 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1146 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1147 # instead.
1148 # Test SSL with non-deterministic ECDSA. Only test features that
1149 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001150 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001151 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001152
1153 # To save time, only test one protocol version, since this part of
1154 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001155 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001156 tests/compat.sh -m tls12 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001157}
1158
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001159component_test_no_hmac_drbg_use_psa () {
1160 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1161 scripts/config.py full
1162 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1163 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1164 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1165
1166 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1167 make
1168
1169 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1170 make test
1171
1172 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1173 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1174 # instead.
1175 # Test SSL with non-deterministic ECDSA. Only test features that
1176 # might be affected by how ECDSA signature is performed.
1177 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001178 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001179
1180 # To save time, only test one protocol version, since this part of
1181 # the protocol is identical in (D)TLS up to 1.2.
1182 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001183 tests/compat.sh -m tls12 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001184}
1185
1186component_test_psa_external_rng_no_drbg_classic () {
1187 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1188 scripts/config.py full
1189 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1190 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001191 scripts/config.py unset MBEDTLS_ENTROPY_C
1192 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1193 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001194 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1195 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1196 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1197 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001198 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1199 # the SSL test programs don't have an RNG and can't work. Explicitly
1200 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1201 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001202
1203 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1204 make test
1205
Gilles Peskine8eb29432021-02-03 20:07:11 +01001206 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001207 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001208}
1209
1210component_test_psa_external_rng_no_drbg_use_psa () {
1211 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001212 scripts/config.py full
1213 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001214 scripts/config.py unset MBEDTLS_ENTROPY_C
1215 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1216 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001217 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1218 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1219 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1220 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1221 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1222
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001223 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001224 make test
1225
Gilles Peskine8eb29432021-02-03 20:07:11 +01001226 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001227 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001228}
1229
1230component_test_psa_external_rng_use_psa_crypto () {
1231 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1232 scripts/config.py full
1233 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1234 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1235 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1236 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1237
1238 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1239 make test
1240
Gilles Peskineba749042021-01-13 20:02:03 +01001241 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001242 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001243}
1244
Manuel Pégourié-Gonnard1a3f9ed2020-05-19 12:38:31 +02001245component_test_ecp_no_internal_rng () {
1246 msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
1247 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1248 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1249 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1250 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1251 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
1252 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1253
1254 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1255 make
1256
1257 msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
1258 make test
1259
1260 # no SSL tests as they all depend on having a DRBG
1261}
1262
Manuel Pégourié-Gonnard53fb66d2020-06-04 09:43:14 +02001263component_test_ecp_restartable_no_internal_rng () {
1264 msg "build: Default plus ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG"
1265 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1266 scripts/config.py set MBEDTLS_ECP_RESTARTABLE
1267 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1268 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1269 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1270 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
1271 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1272
1273 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1274 make
1275
1276 msg "test: ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG module"
1277 make test
1278
1279 # no SSL tests as they all depend on having a DRBG
1280}
1281
Przemek Stekiele5352702022-10-05 11:37:54 +02001282component_test_tls1_2_default_stream_cipher_only () {
1283 msg "build: default with only stream cipher"
1284
1285 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
1286 scripts/config.py unset MBEDTLS_GCM_C
1287 scripts/config.py unset MBEDTLS_CCM_C
1288 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1289 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1290 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1291 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1292 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1293 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1294 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1295 # Modules that depend on AEAD
1296 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001297 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001298
1299 make
1300
1301 msg "test: default with only stream cipher"
1302 make test
1303
1304 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1305}
1306
1307component_test_tls1_2_default_stream_cipher_only_use_psa () {
1308 msg "build: default with only stream cipher use psa"
1309
1310 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1311 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1312 scripts/config.py unset MBEDTLS_GCM_C
1313 scripts/config.py unset MBEDTLS_CCM_C
1314 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1315 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1316 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1317 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1318 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1319 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1320 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1321 # Modules that depend on AEAD
1322 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001323 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001324
1325 make
1326
1327 msg "test: default with only stream cipher use psa"
1328 make test
1329
1330 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1331}
1332
1333component_test_tls1_2_default_cbc_legacy_cipher_only () {
1334 msg "build: default with only CBC-legacy cipher"
1335
1336 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1337 scripts/config.py unset MBEDTLS_GCM_C
1338 scripts/config.py unset MBEDTLS_CCM_C
1339 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1340 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1341 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1342 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1343 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1344 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1345 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1346 # Modules that depend on AEAD
1347 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001348 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001349
1350 make
1351
1352 msg "test: default with only CBC-legacy cipher"
1353 make test
1354
1355 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1356 tests/ssl-opt.sh -f "TLS 1.2"
1357}
1358
1359component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
1360 msg "build: default with only CBC-legacy cipher use psa"
1361
1362 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1363 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1364 scripts/config.py unset MBEDTLS_GCM_C
1365 scripts/config.py unset MBEDTLS_CCM_C
1366 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1367 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1368 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1369 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1370 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1371 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1372 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1373 # Modules that depend on AEAD
1374 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001375 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001376
1377 make
1378
1379 msg "test: default with only CBC-legacy cipher use psa"
1380 make test
1381
1382 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1383 tests/ssl-opt.sh -f "TLS 1.2"
1384}
1385
1386component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
1387 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1388
1389 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1390 scripts/config.py unset MBEDTLS_GCM_C
1391 scripts/config.py unset MBEDTLS_CCM_C
1392 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1393 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1394 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1395 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1396 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1397 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1398 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1399 # Modules that depend on AEAD
1400 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001401 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001402
1403 make
1404
1405 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1406 make test
1407
1408 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1409 tests/ssl-opt.sh -f "TLS 1.2"
1410}
1411
1412component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
1413 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
1414
1415 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1416 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1417 scripts/config.py unset MBEDTLS_GCM_C
1418 scripts/config.py unset MBEDTLS_CCM_C
1419 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1420 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1421 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1422 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1423 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1424 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1425 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1426 # Modules that depend on AEAD
1427 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001428 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001429
1430 make
1431
1432 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
1433 make test
1434
1435 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
1436 tests/ssl-opt.sh -f "TLS 1.2"
1437}
1438
Gilles Peskine636c26a2020-03-04 20:46:15 +01001439component_test_new_ecdh_context () {
1440 msg "build: new ECDH context (ASan build)" # ~ 6 min
1441 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1442 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1443 make
1444
1445 msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1446 make test
1447
1448 msg "test: new ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001449 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001450
1451 msg "test: new ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1452 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001453 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001454}
1455
1456component_test_everest () {
1457 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
1458 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1459 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1460 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1461 make
1462
1463 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1464 make test
1465
1466 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001467 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001468
1469 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1470 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001471 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001472}
1473
Gilles Peskined3beca92020-07-03 00:15:37 +02001474component_test_everest_curve25519_only () {
1475 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
1476 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1477 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1478 scripts/config.py unset MBEDTLS_ECDSA_C
1479 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1480 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1481 # Disable all curves
1482 for c in $(sed -n 's/#define \(MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED\).*/\1/p' <"$CONFIG_H"); do
1483 scripts/config.py unset "$c"
1484 done
1485 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1486
1487 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1488
1489 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1490 make test
1491}
1492
Gilles Peskine8f073122018-11-27 15:58:47 +01001493component_test_small_ssl_out_content_len () {
1494 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001495 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1496 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001497 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1498 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001499
Gilles Peskine8f073122018-11-27 15:58:47 +01001500 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001501 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001502}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001503
Gilles Peskine8f073122018-11-27 15:58:47 +01001504component_test_small_ssl_in_content_len () {
1505 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001506 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1507 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001508 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1509 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001510
Gilles Peskine8f073122018-11-27 15:58:47 +01001511 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001512 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001513}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001514
Gilles Peskine8f073122018-11-27 15:58:47 +01001515component_test_small_ssl_dtls_max_buffering () {
1516 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001517 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001518 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1519 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001520
Gilles Peskine8f073122018-11-27 15:58:47 +01001521 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001522 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 +01001523}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001524
Gilles Peskine8f073122018-11-27 15:58:47 +01001525component_test_small_mbedtls_ssl_dtls_max_buffering () {
1526 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001527 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001528 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1529 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001530
Gilles Peskine8f073122018-11-27 15:58:47 +01001531 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001532 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001533}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001534
Gilles Peskine75cc7712019-09-06 19:47:17 +02001535component_test_psa_collect_statuses () {
1536 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001537 scripts/config.py full
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001538 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001539 # Check that psa_crypto_init() succeeded at least once
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001540 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001541 rm -f tests/statuses.log
1542}
1543
Gilles Peskine8f073122018-11-27 15:58:47 +01001544component_test_full_cmake_clang () {
1545 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001546 scripts/config.py full
Gilles Peskine83264be2022-10-30 21:02:40 +01001547 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 +01001548 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001549
k-stachowiak0291cb72019-06-26 15:52:12 +02001550 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001551 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001552
Gilles Peskine83264be2022-10-30 21:02:40 +01001553 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
1554 programs/test/cpp_dummy_build
1555
k-stachowiak0291cb72019-06-26 15:52:12 +02001556 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001557 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001558
Gilles Peskine8f073122018-11-27 15:58:47 +01001559 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001560 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001561
Andres Amaya Garcia2dadab72019-01-08 21:42:27 +00001562 msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001563 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 +02001564
Gilles Peskine8f073122018-11-27 15:58:47 +01001565 msg "test: compat.sh ARIA + ChachaPoly"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001566 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001567}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001568
Gilles Peskine9603a442022-11-29 16:01:41 +01001569skip_suites_without_constant_flow () {
1570 # Skip the test suites that don't have any constant-flow annotations.
1571 # This will need to be adjusted if we ever start declaring things as
1572 # secret from macros or functions inside tests/include or tests/src.
1573 SKIP_TEST_SUITES=$(
1574 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
1575 sed 's/test_suite_//; s/\.function$//' |
1576 tr '\n' ,)
1577 export SKIP_TEST_SUITES
1578}
1579
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001580component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001581 # This tests both (1) accesses to undefined memory, and (2) branches or
1582 # memory access depending on secret values. To distinguish between those:
1583 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1584 # - or alternatively, change the build type to MemSanDbg, which enables
1585 # origin tracking and nicer stack traces (which are useful for debugging
1586 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1587 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001588 scripts/config.py full
1589 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1590 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1591 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1592 make
1593
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001594 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001595 make test
1596}
1597
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001598component_test_valgrind_constant_flow () {
1599 # This tests both (1) everything that valgrind's memcheck usually checks
1600 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1601 # etc.) and (2) branches or memory access depending on secret values,
1602 # which will be reported as uninitialized memory. To distinguish between
1603 # secret and actually uninitialized:
1604 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1605 # - or alternatively, build with debug info and manually run the offending
1606 # test suite with valgrind --track-origins=yes, then check if the origin
1607 # was TEST_CF_SECRET() or something else.
1608 msg "build: cmake release GCC, full config with constant flow testing"
1609 scripts/config.py full
1610 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Gilles Peskine9603a442022-11-29 16:01:41 +01001611 skip_suites_without_constant_flow
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001612 cmake -D CMAKE_BUILD_TYPE:String=Release .
1613 make
1614
1615 # this only shows a summary of the results (how many of each type)
1616 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine9603a442022-11-29 16:01:41 +01001617 msg "test: some suites (valgrind + constant flow)"
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001618 make memcheck
1619}
1620
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001621component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02001622 # Test that removing the deprecated features from the default
1623 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001624 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1625 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1626 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1627
1628 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1629 make test
1630}
1631
1632component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02001633 msg "build: make, full_no_deprecated config" # ~ 30s
1634 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001635 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1636
Gilles Peskine30de2e82020-04-20 21:39:22 +02001637 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001638 make test
1639}
1640
Gilles Peskine8386ea22020-04-30 09:07:29 +02001641component_test_full_no_deprecated_deprecated_warning () {
1642 # Test that there is nothing deprecated in "full_no_deprecated".
1643 # A deprecated feature would trigger a warning (made fatal) from
1644 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02001645 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1646 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001647 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
1648 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
1649 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1650
Gilles Peskine30de2e82020-04-20 21:39:22 +02001651 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001652 make test
1653}
1654
Gilles Peskine8386ea22020-04-30 09:07:29 +02001655component_test_full_deprecated_warning () {
1656 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
1657 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001658 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001659 scripts/config.py full
1660 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001661 # Expect warnings from '#warning' directives in check_config.h.
1662 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001663
Gilles Peskine8386ea22020-04-30 09:07:29 +02001664 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1665 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
1666 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001667 # Expect warnings from '#warning' directives in check_config.h and
1668 # from the use of deprecated functions in test suites.
1669 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 +01001670
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001671 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
1672 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01001673}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00001674
Gilles Peskineec541fe2020-01-31 14:24:14 +01001675# Check that the specified libraries exist and are empty.
1676are_empty_libraries () {
1677 nm "$@" >/dev/null 2>/dev/null
1678 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
1679}
1680
1681component_build_crypto_default () {
1682 msg "build: make, crypto only"
1683 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01001684 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001685 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001686}
1687
1688component_build_crypto_full () {
1689 msg "build: make, crypto only, full config"
1690 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01001691 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001692 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001693}
1694
Gilles Peskine8df27482022-10-21 19:34:54 +02001695component_test_crypto_for_psa_service () {
Gilles Peskine21503df2022-10-11 21:05:06 +02001696 msg "build: make, config for PSA crypto service"
1697 scripts/config.py crypto
1698 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1699 # Disable things that are not needed for just cryptography, to
1700 # reach a configuration that would be typical for a PSA cryptography
1701 # service providing all implemented PSA algorithms.
1702 # System stuff
1703 scripts/config.py unset MBEDTLS_ERROR_C
1704 scripts/config.py unset MBEDTLS_TIMING_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001705 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskine21503df2022-10-11 21:05:06 +02001706 # Crypto stuff with no PSA interface
1707 scripts/config.py unset MBEDTLS_BASE64_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001708 scripts/config.py unset MBEDTLS_BLOWFISH_C
1709 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
1710 # Keep MBEDTLS_MD_C because RSA and ECDSA need it, also HMAC_DRBG which
1711 # is needed for deterministic ECDSA.
1712 scripts/config.py unset MBEDTLS_ECJPAKE_C
1713 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
Gilles Peskine21503df2022-10-11 21:05:06 +02001714 scripts/config.py unset MBEDTLS_NIST_KW_C
1715 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1716 scripts/config.py unset MBEDTLS_PEM_WRITE_C
1717 scripts/config.py unset MBEDTLS_PKCS12_C
1718 scripts/config.py unset MBEDTLS_PKCS5_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001719 # We keep MBEDTLS_PK_{,PARSE,WRITE}_C because PSA with RSA needs it.
1720 scripts/config.py unset MBEDTLS_XTEA_C
Gilles Peskine21503df2022-10-11 21:05:06 +02001721 make CFLAGS='-O1 -Werror' all test
1722 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1723}
1724
Gilles Peskineec541fe2020-01-31 14:24:14 +01001725component_build_crypto_baremetal () {
1726 msg "build: make, crypto only, baremetal config"
1727 scripts/config.py crypto_baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001728 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001729 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001730}
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001731support_build_crypto_baremetal () {
Daniel Axtens1a021af2020-08-31 14:22:58 +10001732 support_build_baremetal "$@"
1733}
1734
1735component_build_baremetal () {
1736 msg "build: make, baremetal config"
1737 scripts/config.py baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001738 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Daniel Axtens1a021af2020-08-31 14:22:58 +10001739}
1740support_build_baremetal () {
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001741 # Older Glibc versions include time.h from other headers such as stdlib.h,
1742 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
1743 # problem, Ubuntu 18.04 is ok.
1744 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
1745}
Gilles Peskineec541fe2020-01-31 14:24:14 +01001746
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001747# depends.py family of tests
Andrzej Kurek85d69302022-10-05 09:14:07 -04001748component_test_depends_py_cipher_id () {
1749 msg "test/build: depends.py cipher_id (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001750 tests/scripts/depends.py cipher_id --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001751}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001752
Andrzej Kurek85d69302022-10-05 09:14:07 -04001753component_test_depends_py_cipher_chaining () {
1754 msg "test/build: depends.py cipher_chaining (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001755 tests/scripts/depends.py cipher_chaining --unset-use-psa
John Durkopc14be902020-08-20 06:16:41 -07001756}
1757
Andrzej Kurek85d69302022-10-05 09:14:07 -04001758component_test_depends_py_cipher_padding () {
1759 msg "test/build: depends.py cipher_padding (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001760 tests/scripts/depends.py cipher_padding --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001761}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001762
Andrzej Kurek85d69302022-10-05 09:14:07 -04001763component_test_depends_py_curves () {
1764 msg "test/build: depends.py curves (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001765 tests/scripts/depends.py curves --unset-use-psa
John Durkop2ec2eaa2020-08-24 18:29:15 -07001766}
1767
Andrzej Kurek85d69302022-10-05 09:14:07 -04001768component_test_depends_py_hashes () {
1769 msg "test/build: depends.py hashes (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001770 tests/scripts/depends.py hashes --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001771}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001772
Andrzej Kurek85d69302022-10-05 09:14:07 -04001773component_test_depends_py_kex () {
1774 msg "test/build: depends.py kex (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001775 tests/scripts/depends.py kex --unset-use-psa
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001776}
1777
Andrzej Kurek85d69302022-10-05 09:14:07 -04001778component_test_depends_py_pkalgs () {
1779 msg "test/build: depends.py pkalgs (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001780 tests/scripts/depends.py pkalgs --unset-use-psa
1781}
1782
1783# PSA equivalents of the depends.py tests
1784component_test_depends_py_cipher_id_psa () {
1785 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1786 tests/scripts/depends.py cipher_id
1787}
1788
1789component_test_depends_py_cipher_chaining_psa () {
1790 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1791 tests/scripts/depends.py cipher_chaining
1792}
1793
1794component_test_depends_py_cipher_padding_psa () {
1795 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1796 tests/scripts/depends.py cipher_padding
1797}
1798
1799component_test_depends_py_curves_psa () {
1800 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1801 tests/scripts/depends.py curves
1802}
1803
1804component_test_depends_py_hashes_psa () {
1805 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1806 tests/scripts/depends.py hashes
1807}
1808
1809component_test_depends_py_kex_psa () {
1810 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1811 tests/scripts/depends.py kex
1812}
1813
1814component_test_depends_py_pkalgs_psa () {
1815 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Andrzej Kurek85d69302022-10-05 09:14:07 -04001816 tests/scripts/depends.py pkalgs
Gilles Peskine8f073122018-11-27 15:58:47 +01001817}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001818
Dave Rodgman5fce4f62023-01-20 13:18:05 +00001819component_build_no_pk_rsa_alt_support () {
1820 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
1821
1822 scripts/config.py full
1823 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
1824 scripts/config.py set MBEDTLS_RSA_C
1825 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
1826
1827 # Only compile - this is primarily to test for compile issues
1828 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
1829}
1830
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001831component_test_no_use_psa_crypto_full_cmake_asan() {
1832 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02001833 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001834 scripts/config.py full
1835 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
1836 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1837 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1838 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02001839 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001840 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01001841 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001842 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001843
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001844 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001845 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001846
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001847 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001848 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001849
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001850 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001851 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001852
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001853 msg "test: compat.sh RC4, DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001854 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 -05001855
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001856 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001857 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001858}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001859
Ronald Crond2c53e62021-09-13 09:38:05 +02001860component_test_psa_crypto_config_accel_ecdsa () {
1861 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1862
1863 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1864 # partial support for cipher operations in the driver test library.
1865 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1866 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Gilles Peskine62de7672022-04-21 11:05:16 +02001867 # Disable obsolete hashes (alternatively we could enable support for them
1868 # in the driver test library).
1869 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1870 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
Ronald Crond2c53e62021-09-13 09:38:05 +02001871
1872 # SHA384 needed for some ECDSA signature tests.
1873 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
1874
1875 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
1876 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1877 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1878
1879 # Restore test driver base configuration
1880 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
1881
1882 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1883 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1884 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1885 scripts/config.py unset MBEDTLS_ECDSA_C
1886 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1887 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1888
1889 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
1890 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"
1891
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01001892 not grep mbedtls_ecdsa_ library/ecdsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02001893
1894 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1895 make test
1896}
1897
1898component_test_psa_crypto_config_accel_rsa_signature () {
1899 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
1900
1901 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1902 # partial support for cipher operations in the driver test library.
1903 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1904 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1905
1906 # It seems it is not possible to remove only the support for RSA signature
1907 # in the library. Thus we have to remove all RSA support (signature and
1908 # encryption/decryption). AS there is no driver support for asymmetric
1909 # encryption/decryption so far remove RSA encryption/decryption from the
1910 # application algorithm list.
1911 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1912 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1913
1914 # Make sure both the library and the test library support the SHA hash
1915 # algorithms and only those ones (SHA256 is included by default). That way:
1916 # - the test library can compute the RSA signatures even in the case of a
1917 # composite RSA signature algorithm based on a SHA hash (no other hash
1918 # used in the unit tests).
1919 # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
1920 # fulfilled as the hash SHA algorithm is supported by the library, and
1921 # thus the tests are run, not skipped.
1922 # - when testing a signature key with an algorithm wildcard built from
1923 # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
1924 # algorithm based on the hashes supported by the library is also
1925 # supported by the test library.
1926 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1927 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
1928 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
1929 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160_C
1930
1931 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA1_C
1932 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
1933 # We need PEM parsing in the test library as well to support the import
1934 # of PEM encoded RSA keys.
1935 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_PEM_PARSE_C
1936 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_BASE64_C
1937
1938 loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
1939 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1940 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1941
1942 # Restore test driver base configuration
1943 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA1_C
1944 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
1945 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_PEM_PARSE_C
1946 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_BASE64_C
1947
1948
1949 # Mbed TLS library build
1950 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1951 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1952
1953 # Remove RSA support and its dependencies
1954 scripts/config.py unset MBEDTLS_PKCS1_V15
1955 scripts/config.py unset MBEDTLS_PKCS1_V21
1956 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1957 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1958 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1959 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1960 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1961 scripts/config.py unset MBEDTLS_RSA_C
1962 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1963
1964 scripts/config.py unset MBEDTLS_MD2_C
1965 scripts/config.py unset MBEDTLS_MD4_C
1966 scripts/config.py unset MBEDTLS_MD5_C
1967 scripts/config.py unset MBEDTLS_RIPEMD160_C
1968 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
1969 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
1970 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
1971
1972 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
1973 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
1974
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01001975 not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
1976 not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02001977
1978 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
1979 make test
1980}
1981
Ronald Cronf7e483c2021-05-08 14:32:59 +02001982component_test_psa_crypto_config_accel_hash () {
1983 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
1984
1985 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1986 # partial support for cipher operations in the driver test library.
1987 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1988 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1989
1990 loc_accel_list="ALG_MD4 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
1991 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1992 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1993
1994 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1995 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1996 scripts/config.py unset MBEDTLS_MD2_C
1997 scripts/config.py unset MBEDTLS_MD4_C
1998 scripts/config.py unset MBEDTLS_MD5_C
1999 scripts/config.py unset MBEDTLS_RIPEMD160_C
2000 scripts/config.py unset MBEDTLS_SHA1_C
2001 # Don't unset MBEDTLS_SHA256_C as it is needed by PSA crypto core.
2002 scripts/config.py unset MBEDTLS_SHA512_C
2003 # Unset MBEDTLS_SSL_PROTO_SSL3, MBEDTLS_SSL_PROTO_TLS1 and MBEDTLS_SSL_PROTO_TLS1_1 as they depend on MBEDTLS_SHA1_C
2004 scripts/config.py unset MBEDTLS_SSL_PROTO_SSL3
2005 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
2006 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
2007 # Unset MBEDTLS_SSL_CBC_RECORD_SPLITTING as it depends on MBEDTLS_SSL_PROTO_TLS1 in the default configuration.
2008 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
2009 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2010 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2011
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002012 not grep mbedtls_sha512_init library/sha512.o
2013 not grep mbedtls_sha1_init library/sha1.o
Ronald Cronf7e483c2021-05-08 14:32:59 +02002014
2015 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2016 make test
2017}
2018
Ronald Cron09623702021-10-18 11:26:01 +02002019component_test_psa_crypto_config_accel_cipher () {
2020 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
2021
Gilles Peskine186331872022-04-12 15:58:03 +02002022 # This test case focuses on cipher+AEAD. We don't yet support all
2023 # combinations of configurations, so deactivate block-cipher-based MACs.
2024 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CMAC
2025
Ronald Cron09623702021-10-18 11:26:01 +02002026 loc_accel_list="ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB ALG_OFB ALG_XTS KEY_TYPE_DES"
2027 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2028 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2029
2030 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2031 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2032
2033 # There is no intended accelerator support for ALG STREAM_CIPHER and
2034 # ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
2035 # inclusion of the Mbed TLS cipher operations. As we want to test here with
2036 # cipher operations solely supported by accelerators, disabled those
2037 # PSA configuration options.
2038 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2039 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Ronald Cron09623702021-10-18 11:26:01 +02002040
2041 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2042 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2043 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2044 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2045 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2046 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2047 scripts/config.py unset MBEDTLS_DES_C
2048
2049 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2050 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2051
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002052 not grep mbedtls_des* library/des.o
Ronald Cron09623702021-10-18 11:26:01 +02002053
2054 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2055 make test
2056}
2057
Przemek Stekiel8b56f232022-10-02 20:58:39 +02002058component_test_psa_crypto_config_accel_aead () {
2059 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2060
2061 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
2062 # partial support for cipher operations in the driver test library.
2063 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2064 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
2065
2066 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2067 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2068 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2069
2070 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2071 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2072
2073 scripts/config.py unset MBEDTLS_GCM_C
2074 scripts/config.py unset MBEDTLS_CCM_C
2075 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2076 # Features that depend on AEAD
2077 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
2078 scripts/config.py unset MBEDTLS_SSL_TICKET_C
2079
2080 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2081 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"
2082
2083 # There's a risk of something getting re-enabled via config_psa.h
2084 # make sure it did not happen.
2085 not grep mbedtls_ccm library/ccm.o
2086 not grep mbedtls_gcm library/gcm.o
2087 not grep mbedtls_chachapoly library/chachapoly.o
2088
2089 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2090 make test
2091}
2092
John Durkop4377bf72020-10-23 01:26:57 -07002093component_test_psa_crypto_config_no_driver() {
2094 # full plus MBEDTLS_PSA_CRYPTO_CONFIG
2095 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
2096 scripts/config.py full
2097 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2098 scripts/config.py unset MBEDTLS_PSA_CRYPTO_DRIVERS
2099 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkope7012c72020-10-26 09:55:01 -07002100 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop4377bf72020-10-23 01:26:57 -07002101
2102 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
John Durkopd8959392020-09-20 23:09:17 -07002103 make test
2104}
2105
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002106component_test_psa_crypto_config_chachapoly_disabled() {
2107 # full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305
2108 msg "build: full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305"
2109 scripts/config.py full
2110 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2111 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_GCM
2112 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CHACHA20_POLY1305
2113 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
2114
2115 msg "test: full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305"
2116 make test
2117}
2118
John Durkopd0321952020-10-29 21:37:36 -07002119# 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 -08002120component_build_psa_accel_alg_ecdh() {
John Durkopd0321952020-10-29 21:37:36 -07002121 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_ECDH
2122 # without MBEDTLS_ECDH_C
2123 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
2124 scripts/config.py full
2125 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2126 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2127 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2128 scripts/config.py unset MBEDTLS_ECDH_C
2129 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2130 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2131 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2132 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2133 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2134 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2135 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2136}
2137
John Durkopf4c4cb02020-10-28 20:09:55 -07002138# 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 -08002139component_build_psa_accel_key_type_ecc_key_pair() {
John Durkop9814fa22020-11-04 12:28:15 -08002140 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
2141 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR"
John Durkopf4c4cb02020-10-28 20:09:55 -07002142 scripts/config.py full
2143 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2144 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2145 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002146 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 -08002147 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 -07002148 # 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 -08002149 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 -07002150}
2151
2152# 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 -08002153component_build_psa_accel_key_type_ecc_public_key() {
John Durkop9814fa22020-11-04 12:28:15 -08002154 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY
2155 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
John Durkopf4c4cb02020-10-28 20:09:55 -07002156 scripts/config.py full
2157 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2158 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2159 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002160 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
2161 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
John Durkopf4c4cb02020-10-28 20:09:55 -07002162 # 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 -08002163 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 -07002164}
2165
John Durkopd0321952020-10-29 21:37:36 -07002166# 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 -08002167component_build_psa_accel_alg_hmac() {
John Durkopd0321952020-10-29 21:37:36 -07002168 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HMAC
2169 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HMAC"
2170 scripts/config.py full
2171 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2172 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2173 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2174 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2175 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2176}
2177
2178# 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 -08002179component_build_psa_accel_alg_hkdf() {
John Durkopd0321952020-10-29 21:37:36 -07002180 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HKDF
2181 # without MBEDTLS_HKDF_C
2182 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
2183 scripts/config.py full
2184 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2185 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2186 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2187 scripts/config.py unset MBEDTLS_HKDF_C
John Durkopbd069d32020-10-31 22:14:03 -07002188 # Make sure to unset TLS1_3_EXPERIMENTAL since it requires HKDF_C and will not build properly without it.
2189 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
John Durkopd0321952020-10-29 21:37:36 -07002190 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2191 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2192}
2193
John Durkop1b7ee052020-11-27 08:51:22 -08002194# This should be renamed to test and updated once the accelerator MD2 code is in place and ready to test.
2195component_build_psa_accel_alg_md2() {
2196 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD2 without other hashes
2197 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD2 - other hashes"
2198 scripts/config.py full
2199 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2200 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2201 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2202 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2203 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2204 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2205 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2206 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2207 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2208 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2209 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2210 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2211 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD2 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2212}
2213
2214# This should be renamed to test and updated once the accelerator MD4 code is in place and ready to test.
2215component_build_psa_accel_alg_md4() {
2216 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD4 without other hashes
2217 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD4 - other hashes"
2218 scripts/config.py full
2219 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2220 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2221 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2222 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2223 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2224 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2225 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2226 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2227 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2228 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2229 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2230 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2231 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD4 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2232}
2233
2234# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
2235component_build_psa_accel_alg_md5() {
2236 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD5 without other hashes
2237 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD5 - other hashes"
2238 scripts/config.py full
2239 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2240 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2241 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2242 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2243 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2244 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2245 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2246 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2247 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2248 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2249 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2250 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2251 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2252}
2253
2254# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
2255component_build_psa_accel_alg_ripemd160() {
2256 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RIPEMD160 without other hashes
2257 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RIPEMD160 - other hashes"
2258 scripts/config.py full
2259 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2260 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2261 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2262 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2263 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2264 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2265 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2266 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2267 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2268 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2269 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2270 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2271 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2272}
2273
2274# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
2275component_build_psa_accel_alg_sha1() {
2276 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_1 without other hashes
2277 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_1 - other hashes"
2278 scripts/config.py full
2279 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2280 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2281 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2282 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2283 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2284 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2285 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2286 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2287 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2288 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2289 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2290 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2291 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2292}
2293
2294# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
2295component_build_psa_accel_alg_sha224() {
2296 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_224 without other hashes
2297 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_224 - other hashes"
2298 scripts/config.py full
2299 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2300 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2301 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2302 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2303 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2304 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2305 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2306 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2307 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2308 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2309 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2310 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2311}
2312
2313# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
2314component_build_psa_accel_alg_sha256() {
2315 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_256 without other hashes
2316 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_256 - other hashes"
2317 scripts/config.py full
2318 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2319 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2320 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2321 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2322 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2323 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2324 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2325 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2326 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2327 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2328 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2329 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2330 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2331}
2332
2333# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
2334component_build_psa_accel_alg_sha384() {
2335 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_384 without other hashes
2336 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_384 - other hashes"
2337 scripts/config.py full
2338 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2339 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2340 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2341 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2342 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2343 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2344 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2345 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2346 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2347 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2348 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2349 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2350}
2351
2352# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
2353component_build_psa_accel_alg_sha512() {
2354 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_512 without other hashes
2355 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_512 - other hashes"
2356 scripts/config.py full
2357 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2358 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2359 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2360 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2361 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2362 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2363 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2364 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2365 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2366 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2367 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2368 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2369 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2370}
2371
John Durkopd0321952020-10-29 21:37:36 -07002372# 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 -08002373component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
John Durkopbd069d32020-10-31 22:14:03 -07002374 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2375 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 -07002376 scripts/config.py full
2377 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2378 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2379 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkopbd069d32020-10-31 22:14:03 -07002380 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002381 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2382 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2383 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07002384 # 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 -07002385 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2386}
2387
2388# 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 -08002389component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
John Durkopbd069d32020-10-31 22:14:03 -07002390 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_SIGN and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
2391 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2392 scripts/config.py full
2393 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2394 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2395 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2396 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002397 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2398 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2399 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002400 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2401 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2402}
2403
2404# 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 -08002405component_build_psa_accel_alg_rsa_oaep() {
John Durkopbd069d32020-10-31 22:14:03 -07002406 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_OAEP and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
2407 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2408 scripts/config.py full
2409 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2410 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2411 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2412 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_OAEP 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002413 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2414 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2415 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002416 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2417 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2418}
2419
2420# 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 -08002421component_build_psa_accel_alg_rsa_pss() {
John Durkopbd069d32020-10-31 22:14:03 -07002422 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PSS and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
2423 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
2424 scripts/config.py full
2425 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2426 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2427 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2428 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002429 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2430 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2431 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07002432 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2433 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2434}
2435
2436# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
John Durkop6ba40d12020-11-10 08:50:04 -08002437component_build_psa_accel_key_type_rsa_key_pair() {
John Durkopbd069d32020-10-31 22:14:03 -07002438 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_KEY_PAIR and PSA_WANT_ALG_RSA_PSS
2439 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR + PSA_WANT_ALG_RSA_PSS"
2440 scripts/config.py full
2441 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2442 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2443 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2444 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2445 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
2446 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2447 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"
2448}
2449
2450# 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 -08002451component_build_psa_accel_key_type_rsa_public_key() {
John Durkopbd069d32020-10-31 22:14:03 -07002452 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY and PSA_WANT_ALG_RSA_PSS
2453 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
2454 scripts/config.py full
2455 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2456 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2457 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2458 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2459 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
2460 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2461 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 -07002462}
2463
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002464component_test_check_params_functionality () {
2465 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002466 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002467 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002468 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Ronald Crona1236142020-07-01 16:01:21 +02002469 make CC=gcc CFLAGS='-Werror -O1' all test
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002470}
2471
Gilles Peskineb28636b2019-01-02 19:06:24 +01002472component_test_check_params_without_platform () {
2473 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002474 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002475 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002476 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
2477 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
2478 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
2479 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
Gilles Peskine32e889d2020-04-12 23:43:28 +02002480 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002481 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
2482 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskine9c764bf2022-09-18 14:05:23 +02002483 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002484 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
2485 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +01002486 make CC=gcc CFLAGS='-Werror -O1' all test
2487}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002488
Gilles Peskineb28636b2019-01-02 19:06:24 +01002489component_test_check_params_silent () {
2490 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002491 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002492 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01002493 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
2494 make CC=gcc CFLAGS='-Werror -O1' all test
2495}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002496
Dave Rodgman173227d2023-06-29 09:29:00 +01002497component_build_aes_variations() { # ~45s
2498 msg "build: aes.o for all combinations of relevant config options"
Dave Rodgmanbf998282023-06-29 12:10:45 +01002499
Dave Rodgman173227d2023-06-29 09:29:00 +01002500 for a in set unset; do
2501 for b in set unset; do
2502 for c in set unset; do
2503 for d in set unset; do
2504 for e in set unset; do
2505 for f in set unset; do
2506 for g in set unset; do
Dave Rodgmanbf998282023-06-29 12:10:45 +01002507 echo ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
2508 echo ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
2509 echo ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
2510 echo ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
2511 echo ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
2512 echo ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
2513 echo ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman173227d2023-06-29 09:29:00 +01002514
Dave Rodgmanbf998282023-06-29 12:10:45 +01002515 ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
2516 ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
2517 ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
2518 ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
2519 ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
2520 ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
2521 ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman173227d2023-06-29 09:29:00 +01002522
Dave Rodgmanbf998282023-06-29 12:10:45 +01002523 rm -f library/aes.o
2524 make -C library aes.o CC="clang" CFLAGS="-O0 -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
Dave Rodgman173227d2023-06-29 09:29:00 +01002525 done
2526 done
2527 done
2528 done
2529 done
2530 done
2531 done
2532}
2533
Gilles Peskine8f073122018-11-27 15:58:47 +01002534component_test_no_platform () {
2535 # Full configuration build, without platform support, file IO and net sockets.
2536 # This should catch missing mbedtls_printf definitions, and by disabling file
2537 # IO, it should catch missing '#include <stdio.h>'
2538 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002539 scripts/config.py full
2540 scripts/config.py unset MBEDTLS_PLATFORM_C
2541 scripts/config.py unset MBEDTLS_NET_C
2542 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
2543 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
2544 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
2545 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskine9c764bf2022-09-18 14:05:23 +02002546 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002547 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
2548 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskine32e889d2020-04-12 23:43:28 +02002549 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002550 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
2551 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002552 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002553 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
2554 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01002555 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
2556 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002557 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
2558 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01002559}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00002560
Gilles Peskine8f073122018-11-27 15:58:47 +01002561component_build_no_std_function () {
2562 # catch compile bugs in _uninit functions
2563 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002564 scripts/config.py full
2565 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
2566 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002567 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine31fdda12021-10-08 11:45:47 +02002568 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskine25319702021-10-07 19:34:57 +02002569 make
Gilles Peskine8f073122018-11-27 15:58:47 +01002570}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01002571
Gilles Peskine8f073122018-11-27 15:58:47 +01002572component_build_no_ssl_srv () {
2573 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002574 scripts/config.py full
2575 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002576 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002577}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002578
Gilles Peskine8f073122018-11-27 15:58:47 +01002579component_build_no_ssl_cli () {
2580 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002581 scripts/config.py full
2582 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002583 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002584}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002585
Gilles Peskine8f073122018-11-27 15:58:47 +01002586component_build_no_sockets () {
2587 # Note, C99 compliance can also be tested with the sockets support disabled,
2588 # as that requires a POSIX platform (which isn't the same as C99).
2589 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002590 scripts/config.py full
2591 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
2592 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002593 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01002594}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02002595
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002596component_test_memory_buffer_allocator_backtrace () {
2597 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002598 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2599 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2600 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
2601 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Gilles Peskineff30bd02021-10-19 21:33:32 +02002602 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002603 make
2604
2605 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
2606 make test
2607}
2608
2609component_test_memory_buffer_allocator () {
2610 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002611 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2612 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Gilles Peskineff30bd02021-10-19 21:33:32 +02002613 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002614 make
2615
2616 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2617 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002618
2619 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2620 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002621 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002622}
2623
Gilles Peskine8f073122018-11-27 15:58:47 +01002624component_test_no_max_fragment_length () {
2625 # Run max fragment length tests with MFL disabled
2626 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002627 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01002628 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2629 make
Hanno Becker5175ac62017-09-18 15:36:25 +01002630
Gilles Peskine8f073122018-11-27 15:58:47 +01002631 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002632 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01002633}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002634
Hanno Becker545ced42019-02-19 11:10:48 +00002635component_test_asan_remove_peer_certificate () {
2636 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002637 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00002638 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2639 make
2640
2641 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2642 make test
2643
2644 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002645 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002646
2647 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002648 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002649
2650 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002651 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002652}
2653
Gilles Peskine8f073122018-11-27 15:58:47 +01002654component_test_no_max_fragment_length_small_ssl_out_content_len () {
2655 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002656 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2657 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
2658 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01002659 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2660 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10002661
Gilles Peskine8f073122018-11-27 15:58:47 +01002662 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002663 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002664
2665 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002666 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002667}
Angus Grattonc4dd0732018-04-11 16:28:39 +10002668
Darryl Greenaad82f92019-12-02 10:53:11 +00002669component_test_variable_ssl_in_out_buffer_len () {
2670 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
2671 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2672 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2673 make
2674
2675 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2676 make test
2677
2678 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002679 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002680
2681 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002682 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002683}
2684
2685component_test_variable_ssl_in_out_buffer_len_CID () {
2686 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
2687 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2688 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
2689
2690 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2691 make
2692
2693 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
2694 make test
2695
2696 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002697 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002698
2699 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002700 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002701}
2702
2703component_test_variable_ssl_in_out_buffer_len_record_splitting () {
2704 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled (ASan build)"
2705 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2706 scripts/config.py set MBEDTLS_SSL_CBC_RECORD_SPLITTING
2707
2708 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2709 make
2710
2711 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING"
2712 make test
2713
2714 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002715 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002716
2717 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002718 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002719}
2720
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002721component_test_ssl_alloc_buffer_and_mfl () {
2722 msg "build: default config with memory buffer allocator and MFL extension"
2723 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2724 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2725 scripts/config.py set MBEDTLS_MEMORY_DEBUG
2726 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2727 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
Gilles Peskineff30bd02021-10-19 21:33:32 +02002728 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002729 make
2730
2731 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
2732 make test
2733
2734 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 +02002735 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002736}
2737
Gilles Peskine636c26a2020-03-04 20:46:15 +01002738component_test_when_no_ciphersuites_have_mac () {
2739 msg "build: when no ciphersuites have MAC"
2740 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
2741 scripts/config.py unset MBEDTLS_ARC4_C
2742 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2743 make
2744
2745 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
2746 make test
2747
2748 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002749 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01002750}
2751
Gilles Peskine8f073122018-11-27 15:58:47 +01002752component_test_null_entropy () {
2753 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002754 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
2755 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
2756 scripts/config.py set MBEDTLS_ENTROPY_C
2757 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002758 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002759 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
2760 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00002761 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01002762 make
Janos Follath06c54002016-06-09 13:57:40 +01002763
Gilles Peskine8f073122018-11-27 15:58:47 +01002764 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
2765 make test
2766}
Janos Follath06c54002016-06-09 13:57:40 +01002767
Raoul Strackxa4e86142020-06-15 17:03:13 +02002768component_test_no_date_time () {
2769 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
2770 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
Gilles Peskine31fdda12021-10-08 11:45:47 +02002771 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Raoul Strackxa4e86142020-06-15 17:03:13 +02002772 make
2773
2774 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
2775 make test
2776}
2777
Andrzej Kurekc890b222023-01-17 04:03:19 -05002778component_test_alt_timing() {
2779 msg "build: alternate timing implementation"
2780 scripts/config.py set MBEDTLS_TIMING_ALT
2781 make lib TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
2782
2783 msg "test: MBEDTLS_TIMING_ALT - test suites"
2784 make test TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
Andrzej Kurek3a261a42023-01-26 04:33:59 -05002785
2786 msg "selftest - MBEDTLS-TIMING_ALT"
2787 make programs TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../../tests/src/external_timing -I../tests/src/external_timing"
2788 programs/test/selftest
Andrzej Kurekc890b222023-01-17 04:03:19 -05002789}
2790
Gilles Peskine8f073122018-11-27 15:58:47 +01002791component_test_platform_calloc_macro () {
2792 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002793 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2794 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
2795 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01002796 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2797 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01002798
Gilles Peskine8f073122018-11-27 15:58:47 +01002799 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
2800 make test
2801}
Hanno Beckere5fecec2018-10-11 11:02:52 +01002802
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002803component_test_malloc_0_null () {
2804 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002805 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +02002806 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 +02002807
2808 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
2809 make test
2810
2811 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
2812 # Just the calloc selftest. "make test" ran the others as part of the
2813 # test suites.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002814 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01002815
2816 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
2817 # Run a subset of the tests. The choice is a balance between coverage
2818 # and time (including time indirectly wasted due to flaky tests).
2819 # The current choice is to skip tests whose description includes
2820 # "proxy", which is an approximation of skipping tests that use the
2821 # UDP proxy, which tend to be slower and flakier.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002822 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002823}
2824
Gilles Peskine8f073122018-11-27 15:58:47 +01002825component_test_aes_fewer_tables () {
2826 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002827 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002828 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002829
Gilles Peskine8f073122018-11-27 15:58:47 +01002830 msg "test: AES_FEWER_TABLES"
2831 make test
2832}
Hanno Becker83ebf782017-07-07 12:29:15 +01002833
Gilles Peskine8f073122018-11-27 15:58:47 +01002834component_test_aes_rom_tables () {
2835 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002836 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002837 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002838
Gilles Peskine8f073122018-11-27 15:58:47 +01002839 msg "test: AES_ROM_TABLES"
2840 make test
2841}
Hanno Becker83ebf782017-07-07 12:29:15 +01002842
Gilles Peskine8f073122018-11-27 15:58:47 +01002843component_test_aes_fewer_tables_and_rom_tables () {
2844 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002845 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2846 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Gilles Peskine8f073122018-11-27 15:58:47 +01002847 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002848
Gilles Peskine8f073122018-11-27 15:58:47 +01002849 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2850 make test
2851}
2852
Gilles Peskine592f5912019-10-07 18:49:32 +02002853component_test_ctr_drbg_aes_256_sha_256 () {
2854 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002855 scripts/config.py full
2856 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2857 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002858 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2859 make
2860
2861 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2862 make test
2863}
2864
2865component_test_ctr_drbg_aes_128_sha_512 () {
2866 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002867 scripts/config.py full
2868 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2869 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02002870 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2871 make
2872
2873 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2874 make test
2875}
2876
2877component_test_ctr_drbg_aes_128_sha_256 () {
2878 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002879 scripts/config.py full
2880 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2881 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2882 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002883 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2884 make
2885
2886 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2887 make test
2888}
2889
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002890component_test_se_default () {
2891 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002892 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02002893 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002894
2895 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2896 make test
2897}
2898
Steven Cooremand57203d2020-07-16 20:28:59 +02002899component_test_psa_crypto_drivers () {
Steven Cooreman55ae2172020-07-17 19:46:15 +02002900 msg "build: MBEDTLS_PSA_CRYPTO_DRIVERS w/ driver hooks"
Steven Cooreman753f9732021-03-15 11:38:44 +01002901 scripts/config.py full
Steven Cooremand57203d2020-07-16 20:28:59 +02002902 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
Steven Cooreman6801f082021-02-19 17:21:22 +01002903 scripts/config.py set MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
Gilles Peskinefe0acc62021-09-20 19:20:04 +02002904 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
2905 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002906 loc_cflags="${loc_cflags} -I../tests/include -O2"
2907
2908 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002909
Steven Cooreman753f9732021-03-15 11:38:44 +01002910 msg "test: full + MBEDTLS_PSA_CRYPTO_DRIVERS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002911 make test
2912}
2913
Gilles Peskine8f073122018-11-27 15:58:47 +01002914component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002915 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002916 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02002917 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine27482f12021-11-04 12:52:14 +01002918 programs/test/dlopen_demo.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002919}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02002920
Gilles Peskinecf740502019-07-03 20:43:05 +02002921component_test_cmake_shared () {
2922 msg "build/test: cmake shared" # ~ 2min
2923 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
2924 make
Gilles Peskine56c01612019-07-03 20:43:32 +02002925 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02002926 make test
Gilles Peskine27482f12021-11-04 12:52:14 +01002927 programs/test/dlopen_demo.sh
Gilles Peskinecf740502019-07-03 20:43:05 +02002928}
2929
Gilles Peskineec10bf12019-09-20 19:56:06 +02002930test_build_opt () {
2931 info=$1 cc=$2; shift 2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002932 $cc --version
Gilles Peskineec10bf12019-09-20 19:56:06 +02002933 for opt in "$@"; do
2934 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskinee094a182020-04-14 20:08:41 +02002935 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02002936 # We're confident enough in compilers to not run _all_ the tests,
2937 # but at least run the unit tests. In particular, runs with
2938 # optimizations use inline assembly whereas runs with -O0
2939 # skip inline assembly.
2940 make test # ~30s
2941 make clean
2942 done
2943}
2944
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002945# For FreeBSD we invoke the function by name so this condition is added
2946# to disable the existing test_clang_opt function for linux.
2947if [[ $(uname) != "Linux" ]]; then
2948 component_test_clang_opt () {
2949 scripts/config.py full
2950 test_build_opt 'full config' clang -O0 -Os -O2
2951 }
2952fi
2953
2954component_test_clang_latest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002955 scripts/config.py full
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002956 test_build_opt 'full config' clang-latest -O0 -Os -O2
2957}
2958support_test_clang_latest_opt () {
2959 type clang-latest >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02002960}
2961
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002962component_test_clang_earliest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002963 scripts/config.py full
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002964 test_build_opt 'full config' clang-earliest -O0
2965}
2966support_test_clang_earliest_opt () {
2967 type clang-earliest >/dev/null 2>/dev/null
2968}
2969
2970component_test_gcc_latest_opt () {
2971 scripts/config.py full
2972 test_build_opt 'full config' gcc-latest -O0 -Os -O2
2973}
2974support_test_gcc_latest_opt () {
2975 type gcc-latest >/dev/null 2>/dev/null
2976}
2977
2978component_test_gcc_earliest_opt () {
2979 scripts/config.py full
2980 test_build_opt 'full config' gcc-earliest -O0
2981}
2982support_test_gcc_earliest_opt () {
2983 type gcc-earliest >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02002984}
2985
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02002986component_build_mbedtls_config_file () {
2987 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
Gilles Peskine6af9dc92022-04-07 20:55:57 +02002988 scripts/config.py -w full_config.h full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02002989 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
2990 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02002991 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine036a9bb2022-04-07 21:06:41 +02002992 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
2993 make clean
2994
2995 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
2996 # In the user config, disable one feature (for simplicity, pick a feature
2997 # that nothing else depends on).
2998 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
2999 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
3000 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3001
3002 rm -f user_config.h full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003003}
3004
Gilles Peskine690a2ef2022-04-07 21:59:14 +02003005component_build_psa_config_file () {
3006 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
3007 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3008 cp "$CRYPTO_CONFIG_H" psa_test_config.h
3009 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
3010 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02003011 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine690a2ef2022-04-07 21:59:14 +02003012 programs/test/query_compile_time_config MBEDTLS_CMAC_C
3013 make clean
3014
3015 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
3016 # In the user config, disable one feature, which will reflect on the
3017 # mbedtls configuration so we can query it with query_compile_time_config.
3018 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
3019 scripts/config.py unset MBEDTLS_CMAC_C
3020 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
3021 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
3022
3023 rm -f psa_test_config.h psa_user_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003024}
3025
Gilles Peskine8f073122018-11-27 15:58:47 +01003026component_test_m32_o0 () {
Gilles Peskinea0c51fb2021-10-07 19:27:16 +02003027 # Build without optimization, so as to use portable C code (in a 32-bit
3028 # build) and not the i386-specific inline assembly.
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003029 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003030 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02003031 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01003032
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003033 msg "test: i386, make, gcc -O0 (ASan build)"
3034 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01003035}
Gilles Peskine878cf602019-01-06 20:50:38 +00003036support_test_m32_o0 () {
3037 case $(uname -m) in
Pengyu Lva89b3672022-10-21 10:50:26 +00003038 amd64|x86_64) true;;
Gilles Peskine878cf602019-01-06 20:50:38 +00003039 *) false;;
3040 esac
3041}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003042
Gilles Peskine6fa69862021-10-05 09:36:03 +02003043component_test_m32_o2 () {
3044 # Build with optimization, to use the i386 specific inline assembly
3045 # and go faster for tests.
3046 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003047 scripts/config.py full
Gilles Peskine6fa69862021-10-05 09:36:03 +02003048 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003049
Gilles Peskine6fa69862021-10-05 09:36:03 +02003050 msg "test: i386, make, gcc -O2 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003051 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003052
Gilles Peskine6fa69862021-10-05 09:36:03 +02003053 msg "test ssl-opt.sh, i386, make, gcc-O2"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003054 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003055}
Gilles Peskine3daa83e2021-10-07 19:25:29 +02003056support_test_m32_o2 () {
Gilles Peskine878cf602019-01-06 20:50:38 +00003057 support_test_m32_o0 "$@"
3058}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003059
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003060component_test_m32_everest () {
3061 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003062 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
3063 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02003064 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003065
3066 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
3067 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003068
3069 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003070 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01003071
3072 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
3073 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003074 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003075}
3076support_test_m32_everest () {
3077 support_test_m32_o0 "$@"
3078}
3079
Gilles Peskine8f073122018-11-27 15:58:47 +01003080component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003081 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003082 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02003083 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003084
3085 msg "test: 64-bit ILP32, make, gcc"
3086 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01003087}
Gilles Peskine878cf602019-01-06 20:50:38 +00003088support_test_mx32 () {
3089 case $(uname -m) in
3090 amd64|x86_64) true;;
3091 *) false;;
3092 esac
3093}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003094
Peter Kolbus60c6da22018-12-27 06:59:04 -06003095component_test_min_mpi_window_size () {
3096 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003097 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06003098 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3099 make
3100
3101 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
3102 make test
3103}
3104
Gilles Peskine8f073122018-11-27 15:58:47 +01003105component_test_have_int32 () {
3106 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003107 scripts/config.py unset MBEDTLS_HAVE_ASM
3108 scripts/config.py unset MBEDTLS_AESNI_C
3109 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01003110 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01003111
Gilles Peskine8f073122018-11-27 15:58:47 +01003112 msg "test: gcc, force 32-bit bignum limbs"
3113 make test
3114}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01003115
Gilles Peskine8f073122018-11-27 15:58:47 +01003116component_test_have_int64 () {
3117 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003118 scripts/config.py unset MBEDTLS_HAVE_ASM
3119 scripts/config.py unset MBEDTLS_AESNI_C
3120 scripts/config.py unset MBEDTLS_PADLOCK_C
Gilles Peskine8f073122018-11-27 15:58:47 +01003121 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01003122
Gilles Peskine8f073122018-11-27 15:58:47 +01003123 msg "test: gcc, force 64-bit bignum limbs"
3124 make test
3125}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003126
Gilles Peskine8f073122018-11-27 15:58:47 +01003127component_test_no_udbl_division () {
3128 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003129 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003130 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01003131 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003132
Gilles Peskine8f073122018-11-27 15:58:47 +01003133 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
3134 make test
3135}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003136
Gilles Peskine8f073122018-11-27 15:58:47 +01003137component_test_no_64bit_multiplication () {
3138 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003139 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003140 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01003141 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003142
Gilles Peskine8f073122018-11-27 15:58:47 +01003143 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
3144 make test
3145}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003146
Gilles Peskine3809f5f2020-11-09 15:40:05 +01003147component_test_no_strings () {
3148 msg "build: no strings" # ~10s
3149 scripts/config.py full
3150 # Disable options that activate a large amount of string constants.
3151 scripts/config.py unset MBEDTLS_DEBUG_C
3152 scripts/config.py unset MBEDTLS_ERROR_C
3153 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
3154 scripts/config.py unset MBEDTLS_VERSION_FEATURES
3155 make CFLAGS='-Werror -Os'
3156
3157 msg "test: no strings" # ~ 10s
3158 make test
3159}
3160
Gilles Peskine8f073122018-11-27 15:58:47 +01003161component_build_arm_none_eabi_gcc () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003162 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003163 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02003164 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 +02003165
Gilles Peskine60d99472021-09-01 20:00:33 +02003166 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003167 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003168}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003169
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003170component_build_arm_linux_gnueabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003171 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003172 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02003173 # Build for a target platform that's close to what Debian uses
3174 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
Dave Rodgman52af7692022-03-31 14:27:24 +01003175 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003176 # Build everything including programs, see for example
Dave Rodgman52af7692022-03-31 14:27:24 +01003177 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003178 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'
3179
Gilles Peskine60d99472021-09-01 20:00:33 +02003180 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003181 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size library/*.o
3182}
3183support_build_arm_linux_gnueabi_gcc_arm5vte () {
3184 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
3185}
3186
3187component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003188 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003189 scripts/config.py baremetal
3190 # This is an imperfect substitute for
3191 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnard9a260a62021-07-06 09:44:59 +02003192 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02003193 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 +02003194
Gilles Peskine60d99472021-09-01 20:00:33 +02003195 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003196 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02003197}
3198
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003199component_build_arm_none_eabi_gcc_m0plus () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003200 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
3201 scripts/config.py baremetal_size
Gilles Peskineaeedd742020-09-02 11:03:04 +02003202 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 +02003203
Gilles Peskine60d99472021-09-01 20:00:33 +02003204 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
Gilles Peskine18487f62020-04-30 23:11:54 +02003205 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003206}
3207
Gilles Peskine8f073122018-11-27 15:58:47 +01003208component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003209 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003210 scripts/config.py baremetal
3211 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003212 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 +01003213 echo "Checking that software 64-bit division is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003214 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003215}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003216
Gilles Peskine8f073122018-11-27 15:58:47 +01003217component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003218 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003219 scripts/config.py baremetal
3220 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003221 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 +01003222 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003223 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003224}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003225
Dave Rodgman43ea9ab2023-06-02 10:26:24 -04003226component_build_arm_clang_thumb () {
3227 # ~ 30s
3228
3229 scripts/config.py baremetal
3230
3231 msg "build: clang thumb 2, make"
3232 make clean
3233 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
3234
3235 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
3236 msg "build: clang thumb 1 -O0, make"
3237 make clean
3238 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
3239
3240 msg "build: clang thumb 1 -Os, make"
3241 make clean
3242 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
3243}
3244
Gilles Peskine8f073122018-11-27 15:58:47 +01003245component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02003246 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003247 scripts/config.py baremetal
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003248 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02003249
3250 msg "size: ARM Compiler 5"
3251 "$ARMC5_FROMELF" -z library/*.o
3252
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003253 make clean
Andres AG87bb5772016-09-27 15:05:15 +01003254
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003255 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
3256
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003257 # ARM Compiler 6 - Target ARMv7-A
3258 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003259
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003260 # ARM Compiler 6 - Target ARMv7-M
3261 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02003262
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003263 # ARM Compiler 6 - Target ARMv8-A - AArch32
3264 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003265
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003266 # ARM Compiler 6 - Target ARMv8-M
3267 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02003268
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003269 # ARM Compiler 6 - Target ARMv8-A - AArch64
3270 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003271
3272 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
3273 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
3274
3275 # ARM Compiler 6 - Target Cortex-M0
3276 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
Gilles Peskine8f073122018-11-27 15:58:47 +01003277}
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003278
Pengyu Lvd216c042023-03-03 18:23:35 +08003279support_build_armcc () {
3280 armc5_cc="$ARMC5_BIN_DIR/armcc"
3281 armc6_cc="$ARMC6_BIN_DIR/armclang"
3282 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
3283}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01003284
Manuel Pégourié-Gonnarddd8807f2020-02-26 09:56:27 +01003285component_build_ssl_hw_record_accel() {
3286 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
3287 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
3288 make CFLAGS='-Werror -O1'
3289}
3290
Hanno Beckera711f6e2020-05-04 12:03:51 +01003291component_test_tls13_experimental () {
3292 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3293 scripts/config.pl set MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
3294 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3295 make
3296 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3297 make test
3298}
3299
Gilles Peskine8f073122018-11-27 15:58:47 +01003300component_build_mingw () {
3301 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003302 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 +00003303
Gilles Peskine8f073122018-11-27 15:58:47 +01003304 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003305 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 +01003306 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02003307
Gilles Peskine8f073122018-11-27 15:58:47 +01003308 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003309 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
3310 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 +01003311 make WINDOWS_BUILD=1 clean
3312}
Jaeden Amero117b8a42019-04-17 15:19:26 +01003313support_build_mingw() {
Pengyu Lva19ce122023-02-24 15:38:52 +08003314 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
3315 [0-5]*|"") false;;
Jaeden Amero117b8a42019-04-17 15:19:26 +01003316 *) true;;
3317 esac
3318}
Simon Butcher91aef332016-11-17 09:20:50 +00003319
Gilles Peskine8f073122018-11-27 15:58:47 +01003320component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003321 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003322 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003323 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
3324 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02003325
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003326 msg "test: main suites (MSan)" # ~ 10s
3327 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003328
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003329 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003330 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003331
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003332 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003333
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003334 if [ "$MEMORY" -gt 0 ]; then
3335 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003336 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003337 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003338}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003339
Gilles Peskine69f190e2019-01-10 00:11:42 +01003340component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003341 msg "build: Release (clang)"
Gilles Peskine619b73d2022-11-29 16:45:30 +01003342 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003343 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3344 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003345
Gilles Peskine619b73d2022-11-29 16:45:30 +01003346 msg "test: main suites, Valgrind (default config)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003347 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003348
Gilles Peskine636c26a2020-03-04 20:46:15 +01003349 # Optional parts (slow; currently broken on OS X because programs don't
3350 # seem to receive signals under valgrind on OS X).
Gilles Peskine619b73d2022-11-29 16:45:30 +01003351 # These optional parts don't run on the CI.
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003352 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003353 msg "test: ssl-opt.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003354 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003355 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003356
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003357 if [ "$MEMORY" -gt 1 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003358 msg "test: compat.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003359 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003360 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003361
3362 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003363 msg "test: context-info.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003364 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003365 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003366}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003367
Gilles Peskine619b73d2022-11-29 16:45:30 +01003368component_test_valgrind_psa () {
3369 msg "build: Release, full (clang)"
3370 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
3371 scripts/config.py full
3372 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3373 make
3374
3375 msg "test: main suites, Valgrind (full config)"
3376 make memcheck
3377}
3378
Paul Elliott2ab9a7a2021-11-25 17:29:40 +00003379support_test_cmake_out_of_source () {
3380 distrib_id=""
3381 distrib_ver=""
3382 distrib_ver_minor=""
3383 distrib_ver_major=""
3384
3385 # Attempt to parse lsb-release to find out distribution and version. If not
3386 # found this should fail safe (test is supported).
3387 if [[ -f /etc/lsb-release ]]; then
3388
3389 while read -r lsb_line; do
3390 case "$lsb_line" in
3391 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
3392 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
3393 esac
3394 done < /etc/lsb-release
3395
3396 distrib_ver_major="${distrib_ver%%.*}"
3397 distrib_ver="${distrib_ver#*.}"
3398 distrib_ver_minor="${distrib_ver%%.*}"
3399 fi
3400
3401 # Running the out of source CMake test on Ubuntu 16.04 using more than one
3402 # processor (as the CI does) can create a race condition whereby the build
3403 # fails to see a generated file, despite that file actually having been
3404 # generated. This problem appears to go away with 18.04 or newer, so make
3405 # the out of source tests unsupported on Ubuntu 16.04.
3406 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
3407}
3408
Gilles Peskine8f073122018-11-27 15:58:47 +01003409component_test_cmake_out_of_source () {
3410 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01003411 MBEDTLS_ROOT_DIR="$PWD"
3412 mkdir "$OUT_OF_SOURCE_DIR"
3413 cd "$OUT_OF_SOURCE_DIR"
Gilles Peskine25319702021-10-07 19:34:57 +02003414 cmake -D CMAKE_BUILD_TYPE:String=Check "$MBEDTLS_ROOT_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003415 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003416
Gilles Peskine8f073122018-11-27 15:58:47 +01003417 msg "test: cmake 'out-of-source' build"
3418 make test
3419 # Test an SSL option that requires an auxiliary script in test/scripts/.
3420 # Also ensure that there are no error messages such as
3421 # "No such file or directory", which would indicate that some required
3422 # file is missing (ssl-opt.sh tolerates the absence of some files so
3423 # may exit with status 0 but emit errors).
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003424 ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' >ssl-opt.out 2>ssl-opt.err
3425 grep PASS ssl-opt.out
Gilles Peskine0a7984f2020-03-28 18:56:09 +01003426 cat ssl-opt.err >&2
3427 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003428 [ ! -s ssl-opt.err ]
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003429 rm ssl-opt.out ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01003430 cd "$MBEDTLS_ROOT_DIR"
3431 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003432}
Andres AGdc192212016-08-31 17:33:13 +01003433
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003434component_test_cmake_as_subdirectory () {
3435 msg "build: cmake 'as-subdirectory' build"
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003436 cd programs/test/cmake_subproject
3437 cmake .
3438 make
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003439 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003440}
Gilles Peskineca9cfca2022-02-04 00:21:12 +01003441support_test_cmake_as_subdirectory () {
3442 support_test_cmake_out_of_source
3443}
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003444
David Horstmann175afbd2023-01-12 14:17:01 +00003445component_build_cmake_custom_config_file () {
David Horstmann67622312023-01-31 10:34:44 +00003446 # Make a copy of config file to use for the in-tree test
3447 cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h
David Horstmann175afbd2023-01-12 14:17:01 +00003448
3449 MBEDTLS_ROOT_DIR="$PWD"
3450 mkdir "$OUT_OF_SOURCE_DIR"
3451 cd "$OUT_OF_SOURCE_DIR"
3452
David Horstmann67622312023-01-31 10:34:44 +00003453 # Build once to get the generated files (which need an intact config file)
David Horstmann175afbd2023-01-12 14:17:01 +00003454 cmake "$MBEDTLS_ROOT_DIR"
3455 make
3456
3457 msg "build: cmake with -DMBEDTLS_CONFIG_FILE"
3458 scripts/config.py -w full_config.h full
David Horstmann67622312023-01-31 10:34:44 +00003459 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003460 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR"
3461 make
3462
3463 msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
3464 # In the user config, disable one feature (for simplicity, pick a feature
3465 # that nothing else depends on).
3466 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3467
3468 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR"
3469 make
3470 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3471
3472 rm -f user_config.h full_config.h
3473
3474 cd "$MBEDTLS_ROOT_DIR"
3475 rm -rf "$OUT_OF_SOURCE_DIR"
3476
3477 # Now repeat the test for an in-tree build:
3478
David Horstmann67622312023-01-31 10:34:44 +00003479 # Restore config for the in-tree test
3480 mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003481
David Horstmann67622312023-01-31 10:34:44 +00003482 # Build once to get the generated files (which need an intact config)
David Horstmann175afbd2023-01-12 14:17:01 +00003483 cmake .
3484 make
3485
3486 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE"
3487 scripts/config.py -w full_config.h full
David Horstmann67622312023-01-31 10:34:44 +00003488 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003489 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h .
3490 make
3491
3492 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
3493 # In the user config, disable one feature (for simplicity, pick a feature
3494 # that nothing else depends on).
3495 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3496
3497 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h .
3498 make
3499 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3500
3501 rm -f user_config.h full_config.h
3502}
3503support_build_cmake_custom_config_file () {
3504 support_test_cmake_out_of_source
3505}
3506
3507
Gilles Peskine8f073122018-11-27 15:58:47 +01003508component_test_zeroize () {
3509 # Test that the function mbedtls_platform_zeroize() is not optimized away by
3510 # different combinations of compilers and optimization flags by using an
3511 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
3512 # system in all cases that the script fails, so we must manually search the
3513 # output to check whether the pass string is present and no failure strings
3514 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01003515
Gilles Peskine4976e822019-01-06 19:52:22 +00003516 # Don't try to disable ASLR. We don't care about ASLR here. We do care
3517 # about a spurious message if Gdb tries and fails, so suppress that.
3518 gdb_disable_aslr=
3519 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
3520 gdb_disable_aslr='set disable-randomization off'
3521 fi
3522
Gilles Peskine8f073122018-11-27 15:58:47 +01003523 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01003524 for compiler in clang gcc; do
3525 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
3526 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003527 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
3528 grep "The buffer was correctly zeroized" test_zeroize.log
3529 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01003530 rm -f test_zeroize.log
3531 make clean
3532 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01003533 done
Gilles Peskine8f073122018-11-27 15:58:47 +01003534}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003535
Bence Szépkúti9f849112021-10-19 15:05:36 +02003536component_test_psa_compliance () {
Bence Szépkútic1e79fd2021-11-11 20:13:14 +01003537 msg "build: make, default config + CMAC, libmbedcrypto.a only"
3538 scripts/config.py set MBEDTLS_CMAC_C
Bence Szépkútiab796e62021-10-25 19:29:07 +02003539 make -C library libmbedcrypto.a
Bence Szépkúti9f849112021-10-19 15:05:36 +02003540
3541 msg "unit test: test_psa_compliance.py"
3542 ./tests/scripts/test_psa_compliance.py
3543}
3544
3545support_test_psa_compliance () {
Bence Szépkútid6cf0892021-11-03 11:36:09 +01003546 # psa-compliance-tests only supports CMake >= 3.10.0
Bence Szépkútiab796e62021-10-25 19:29:07 +02003547 ver="$(cmake --version)"
3548 ver="${ver#cmake version }"
3549 ver_major="${ver%%.*}"
3550
3551 ver="${ver#*.}"
3552 ver_minor="${ver%%.*}"
3553
3554 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
Bence Szépkúti9f849112021-10-19 15:05:36 +02003555}
3556
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003557component_check_code_style () {
3558 msg "Check C code style"
3559 ./scripts/code_style.py
David Horstmanne09c4762022-11-10 18:30:52 +00003560}
3561
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003562support_check_code_style() {
David Horstmanne09c4762022-11-10 18:30:52 +00003563 case $(uncrustify --version) in
3564 *0.75.1*) true;;
3565 *) false;;
3566 esac
3567}
3568
Gilles Peskine8f073122018-11-27 15:58:47 +01003569component_check_python_files () {
3570 msg "Lint: Python scripts"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003571 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003572}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003573
Gilles Peskine8f073122018-11-27 15:58:47 +01003574component_check_generate_test_code () {
3575 msg "uint test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02003576 # unittest writes out mundane stuff like number or tests run on stderr.
3577 # Our convention is to reserve stderr for actual errors, and write
3578 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003579 ./tests/scripts/test_generate_test_code.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01003580}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003581
3582################################################################
3583#### Termination
3584################################################################
3585
Gilles Peskine8f073122018-11-27 15:58:47 +01003586post_report () {
3587 msg "Done, cleaning up"
Gilles Peskine24bdf022020-03-30 20:11:39 +02003588 final_cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003589
Gilles Peskine8f073122018-11-27 15:58:47 +01003590 final_report
3591}
3592
3593
3594
3595################################################################
3596#### Run all the things
3597################################################################
3598
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003599# Function invoked by --error-test to test error reporting.
3600pseudo_component_error_test () {
Gilles Peskine202e9b42021-08-02 23:28:00 +02003601 msg "Testing error reporting $error_test_i"
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003602 if [ $KEEP_GOING -ne 0 ]; then
3603 echo "Expect three failing commands."
3604 fi
Gilles Peskine202e9b42021-08-02 23:28:00 +02003605 # If the component doesn't run in a subshell, changing error_test_i to an
3606 # invalid integer will cause an error in the loop that runs this function.
3607 error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003608 # Expected error: 'grep non_existent /dev/null -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003609 grep non_existent /dev/null
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003610 # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003611 not grep -q . "$0"
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003612 # Expected error: 'make unknown_target -> 2'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003613 make unknown_target
3614 false "this should not be executed"
3615}
3616
Gilles Peskinee48351a2018-11-27 16:06:30 +01003617# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01003618run_component () {
Gilles Peskineffcdeff2018-12-04 12:49:28 +01003619 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02003620 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003621
3622 # Unconditionally create a seedfile that's sufficiently long.
3623 # Do this before each component, because a previous component may
3624 # have messed it up or shortened it.
Gilles Peskinef3133362021-07-08 19:03:50 +02003625 local dd_cmd
3626 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
3627 case $OSTYPE in
3628 linux*|freebsd*|openbsd*|darwin*) dd_cmd+=(status=none)
3629 esac
3630 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003631
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003632 # Run the component in a subshell, with error trapping and output
3633 # redirection set up based on the relevant options.
Gilles Peskine7105a332020-03-28 18:50:43 +01003634 if [ $KEEP_GOING -eq 1 ]; then
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003635 # We want to keep running if the subshell fails, so 'set -e' must
3636 # be off when the subshell runs.
Gilles Peskine7105a332020-03-28 18:50:43 +01003637 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02003638 fi
Gilles Peskine7105a332020-03-28 18:50:43 +01003639 (
3640 if [ $QUIET -eq 1 ]; then
3641 # msg() will be silenced, so just print the component name here.
3642 echo "${current_component#component_}"
3643 exec >/dev/null
3644 fi
3645 if [ $KEEP_GOING -eq 1 ]; then
3646 # Keep "set -e" off, and run an ERR trap instead to record failures.
3647 set -E
3648 trap err_trap ERR
3649 fi
3650 # The next line is what runs the component
3651 "$@"
3652 if [ $KEEP_GOING -eq 1 ]; then
3653 trap - ERR
3654 exit $last_failure_status
3655 fi
3656 )
3657 component_status=$?
3658 if [ $KEEP_GOING -eq 1 ]; then
3659 set -e
3660 if [ $component_status -ne 0 ]; then
3661 failure_count=$((failure_count + 1))
3662 fi
3663 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003664
3665 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01003666 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02003667 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01003668}
3669
3670# Preliminary setup
3671pre_check_environment
3672pre_initialize_variables
3673pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01003674
Gilles Peskine878cf602019-01-06 20:50:38 +00003675pre_check_git
Gilles Peskineef64e7f2021-07-12 18:16:01 +02003676pre_restore_files
Gilles Peskine24bdf022020-03-30 20:11:39 +02003677pre_back_up
Andrzej Kurekeb508712019-02-14 07:18:59 -05003678
Gilles Peskine878cf602019-01-06 20:50:38 +00003679build_status=0
3680if [ $KEEP_GOING -eq 1 ]; then
3681 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01003682fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02003683pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00003684pre_print_configuration
3685pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003686cleanup
3687
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003688# Run the requested tests.
Gilles Peskine202e9b42021-08-02 23:28:00 +02003689for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003690 run_component pseudo_component_error_test
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003691done
Gilles Peskine202e9b42021-08-02 23:28:00 +02003692unset error_test_i
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003693for component in $RUN_COMPONENTS; do
3694 run_component "component_$component"
3695done
Gilles Peskine8f073122018-11-27 15:58:47 +01003696
3697# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00003698post_report