blob: 6b4b4e4a3ecd06b1d7f265ed0968756394372b3c [file] [log] [blame]
Gilles Peskine3de7be82020-03-27 16:35:23 +01001#! /usr/bin/env bash
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
Bence Szépkúti1e148272020-08-07 13:07:28 +02005# Copyright The Mbed TLS Contributors
Dave Rodgman7ff79652023-11-03 12:04:52 +00006# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskine192c72f2017-12-21 15:59:21 +01007
8
9
10################################################################
11#### Documentation
12################################################################
13
Simon Butcher3ea7f522016-03-07 23:22:10 +000014# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010015# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000016#
SimonB2e23c822016-04-16 21:54:39 +010017# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010018#
Gilles Peskine192c72f2017-12-21 15:59:21 +010019# Notes for users
20# ---------------
21#
SimonB2e23c822016-04-16 21:54:39 +010022# Warning: the test is destructive. It includes various build modes and
23# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010024# configuration. The following files must be committed into git:
25# * include/mbedtls/config.h
Gilles Peskine636c26a2020-03-04 20:46:15 +010026# * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
27# programs/fuzz/Makefile
Gilles Peskine192c72f2017-12-21 15:59:21 +010028# After running this script, the CMake cache will be lost and CMake
29# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# The script assumes the presence of a number of tools:
32# * Basic Unix tools (Windows users note: a Unix-style find must be before
33# the Windows find in the PATH)
34# * Perl
35# * GNU Make
36# * CMake
37# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040038# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010039# * arm-gcc and mingw-gcc
40# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine549a9612023-08-27 21:39:21 +020041# * OpenSSL and GnuTLS command line tools, in suitable versions for the
42# interoperability tests. The following are the official versions at the
43# time of writing:
44# * GNUTLS_{CLI,SERV} = 3.4.10
45# * GNUTLS_NEXT_{CLI,SERV} = 3.7.2
46# * OPENSSL_LEGACY = 1.0.1j
47# * OPENSSL = 1.0.2g (without Debian/Ubuntu patches)
48# * OPENSSL_NEXT = 1.1.1a
Gilles Peskine192c72f2017-12-21 15:59:21 +010049# See the invocation of check_tools below for details.
50#
51# This script must be invoked from the toplevel directory of a git
52# working copy of Mbed TLS.
53#
Gilles Peskine7105a332020-03-28 18:50:43 +010054# The behavior on an error depends on whether --keep-going (alias -k)
55# is in effect.
56# * Without --keep-going: the script stops on the first error without
57# cleaning up. This lets you work in the configuration of the failing
58# component.
59# * With --keep-going: the script runs all requested components and
60# reports failures at the end. In particular the script always cleans
61# up on exit.
62#
Gilles Peskine192c72f2017-12-21 15:59:21 +010063# Note that the output is not saved. You may want to run
64# script -c tests/scripts/all.sh
65# or
66# tests/scripts/all.sh >all.log 2>&1
67#
68# Notes for maintainers
69# ---------------------
70#
Gilles Peskine8f073122018-11-27 15:58:47 +010071# The bulk of the code is organized into functions that follow one of the
72# following naming conventions:
73# * pre_XXX: things to do before running the tests, in order.
74# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010075# * component_check_XXX: quick tests that aren't worth parallelizing.
76# * component_build_XXX: build things but don't run them.
77# * component_test_XXX: build and test.
Bence Szépkúti44043ed2023-12-15 17:05:15 +010078# * component_release_XXX: tests that the CI should skip during PR testing.
Gilles Peskine878cf602019-01-06 20:50:38 +000079# * support_XXX: if support_XXX exists and returns false then
80# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010081# * post_XXX: things to do after running the tests.
82# * other: miscellaneous support functions.
83#
Gilles Peskinec70637a2019-01-09 22:29:17 +010084# Each component must start by invoking `msg` with a short informative message.
85#
Gilles Peskine39a3b112020-03-28 21:27:40 +010086# Warning: due to the way bash detects errors, the failure of a command
87# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
88#
Gilles Peskine7105a332020-03-28 18:50:43 +010089# Each component is executed in a separate shell process. The component
90# fails if any command in it returns a non-zero status.
91#
Gilles Peskinec70637a2019-01-09 22:29:17 +010092# The framework performs some cleanup tasks after each component. This
93# means that components can assume that the working directory is in a
94# cleaned-up state, and don't need to perform the cleanup themselves.
95# * Run `make clean`.
96# * Restore `include/mbedtks/config.h` from a backup made before running
97# the component.
Gilles Peskine636c26a2020-03-04 20:46:15 +010098# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
99# `tests/Makefile` and `programs/fuzz/Makefile` from git.
100# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +0100101#
Gilles Peskine192c72f2017-12-21 15:59:21 +0100102# The tests are roughly in order from fastest to slowest. This doesn't
103# have to be exact, but in general you should add slower tests towards
104# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100105
106
107
108################################################################
109#### Initialization and command line parsing
110################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100111
Gilles Peskine8ab29942020-03-28 18:50:49 +0100112# Abort on errors (even on the left-hand side of a pipe).
113# Treat uninitialised variables as errors.
114set -e -o pipefail -u
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100115
Gilles Peskine79598582022-08-30 21:02:44 +0200116# Enable ksh/bash extended file matching patterns
117shopt -s extglob
118
Gilles Peskine8f073122018-11-27 15:58:47 +0100119pre_check_environment () {
Gilles Peskinea16c2b12019-01-06 19:58:02 +0000120 if [ -d library -a -d include -a -d tests ]; then :; else
Gilles Peskinef08ca832023-09-12 19:21:54 +0200121 echo "Must be run from Mbed TLS root" >&2
Gilles Peskine8f073122018-11-27 15:58:47 +0100122 exit 1
123 fi
124}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100125
Gilles Peskine8f073122018-11-27 15:58:47 +0100126pre_initialize_variables () {
127 CONFIG_H='include/mbedtls/config.h'
John Durkopbd069d32020-10-31 22:14:03 -0700128 CRYPTO_CONFIG_H='include/psa/crypto_config.h'
Gilles Peskine24bdf022020-03-30 20:11:39 +0200129
130 # Files that are clobbered by some jobs will be backed up. Use a different
131 # suffix from auxiliary scripts so that all.sh and auxiliary scripts can
132 # independently decide when to remove the backup file.
133 backup_suffix='.all.bak'
134 # Files clobbered by config.py
135 files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H"
Gilles Peskineef64e7f2021-07-12 18:16:01 +0200136 # Files clobbered by in-tree cmake
137 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 +0200138
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200139 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100140 MEMORY=0
141 FORCE=0
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200142 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100143 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100144
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200145 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard54304472020-06-22 10:11:47 +0200146 #
147 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
148 # both values are kept in sync. If you change the value here because it
149 # breaks some tests, you'll definitely want to change it in
150 # basic-build-test.sh as well.
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200151 RELEASE_SEED=1
152
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200153 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200154 : ${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 +0200155 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200156 export MBEDTLS_TEST_PLATFORM
157
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000158 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100159 : ${OPENSSL:="openssl"}
160 : ${OPENSSL_LEGACY:="$OPENSSL"}
161 : ${OPENSSL_NEXT:="$OPENSSL"}
162 : ${GNUTLS_CLI:="gnutls-cli"}
163 : ${GNUTLS_SERV:="gnutls-serv"}
Gilles Peskine8f073122018-11-27 15:58:47 +0100164 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
165 : ${ARMC5_BIN_DIR:=/usr/bin}
166 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskine6d061342020-04-30 18:19:32 +0200167 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200168 : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
Gowtham Suresh Kumarcc029af2023-08-01 09:48:32 +0100169 : ${CLANG_LATEST:="clang-latest"}
170 : ${CLANG_EARLIEST:="clang-earliest"}
171 : ${GCC_LATEST:="gcc-latest"}
172 : ${GCC_EARLIEST:="gcc-earliest"}
Andres AGdc192212016-08-31 17:33:13 +0100173
Gilles Peskine8f073122018-11-27 15:58:47 +0100174 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000175 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine85229ac2021-09-30 18:24:21 +0200176 export MAKEFLAGS="-j$(all_sh_nproc)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100177 fi
Dave Rodgmane0a2f6d2023-12-18 19:53:25 +0000178 # if CC is not set, use clang by default (if present) to improve build times
179 if [ -z "${CC+set}" ] && (type clang > /dev/null 2>&1); then
Dave Rodgmane42c2352023-12-19 16:08:19 +0000180 export CC="clang"
Dave Rodgman62be4562023-12-18 18:34:50 +0000181 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000182
Gilles Peskinec761d8f2021-09-20 18:57:55 +0200183 # Include more verbose output for failing tests run by CMake or make
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000184 export CTEST_OUTPUT_ON_FAILURE=1
185
Gilles Peskine8fd59422019-10-21 17:11:33 +0200186 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Manuel Pégourié-Gonnard717f2302022-11-30 10:42:03 +0100187 # default to -O2, use -Ox _after_ this if you want another level
Manuel Pégourié-Gonnard154b84e2022-11-28 13:12:10 +0100188 ASAN_CFLAGS='-O2 -Werror -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200189
Andrzej Kurekd95b8ed2023-06-27 10:02:09 -0400190 # Platform tests have an allocation that returns null
191 export ASAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurek6e4a9be2023-07-05 08:32:43 -0400192 export MSAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurekd95b8ed2023-06-27 10:02:09 -0400193
Gilles Peskine878cf602019-01-06 20:50:38 +0000194 # Gather the list of available components. These are the functions
195 # defined in this script whose name starts with "component_".
Gowtham Suresh Kumar13850f32023-07-28 16:41:21 +0100196 ALL_COMPONENTS=$(compgen -A function component_ | sed 's/component_//')
Gilles Peskine878cf602019-01-06 20:50:38 +0000197
Dave Rodgman8470d112024-01-16 17:33:34 +0000198 # Delay determining SUPPORTED_COMPONENTS until the command line options have a chance to override
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100199 # the commands set by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100200}
Andres AG38495a32016-07-12 16:54:33 +0100201
Dave Rodgman4cb98a92024-02-26 11:41:19 +0000202setup_quiet_wrappers()
203{
204 # Pick up "quiet" wrappers for make and cmake, which don't output very much
205 # unless there is an error. This reduces logging overhead in the CI.
206 #
207 # Note that the cmake wrapper breaks unless we use an absolute path here.
Dave Rodgmane2317642024-02-26 17:27:18 +0000208 if [[ -e ${PWD}/tests/scripts/quiet ]]; then
209 export PATH=${PWD}/tests/scripts/quiet:$PATH
Dave Rodgman4cb98a92024-02-26 11:41:19 +0000210 fi
211}
212
Gilles Peskinea28db922019-01-10 00:05:18 +0100213# Test whether the component $1 is included in the command line patterns.
214is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100215{
Gilles Peskine6702ce92021-08-06 11:35:17 +0200216 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
217 # only does word splitting.
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100218 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000219 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100220 set +f
221 case ${1#component_} in $pattern) return 0;; esac
222 done
223 set +f
224 return 1
225}
Andres AG7770ea82016-10-10 15:46:20 +0100226
Simon Butcher41eeccf2016-09-07 00:07:09 +0100227usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100228{
Gilles Peskine709346a2017-12-10 23:43:39 +0100229 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100230Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100231Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100232By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100233COMPONENT can be the name of a component or a shell wildcard pattern.
234
235Examples:
236 $0 "check_*"
237 Run all sanity checks.
238 $0 --no-armcc --except test_memsan
239 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100240
241Special options:
242 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000243 --list-all-components List all available test components and exit.
244 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100245
246General options:
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200247 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100248 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100249 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100250 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200251 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200252 --arm-none-eabi-gcc-prefix=<string>
253 Prefix for a cross-compiler for arm-none-eabi
254 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200255 --arm-linux-gnueabi-gcc-prefix=<string>
256 Prefix for a cross-compiler for arm-linux-gnueabi
257 (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100258 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200259 --restore First clean up the build tree, restoring backed up
260 files. Do not run any components unless they are
261 explicitly specified.
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100262 --error-test Error test mode: run a failing function in addition
Gilles Peskinea25c5672021-08-05 15:11:33 +0200263 to any specified component. May be repeated.
Gilles Peskinea28db922019-01-10 00:05:18 +0100264 --except Exclude the COMPONENTs listed on the command line,
265 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200266 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100267 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100268 --no-force Refuse to overwrite modified files (default).
269 --no-keep-going Stop at the first error (default).
270 --no-memory No additional memory tests (default).
Shaun Case0e7791f2021-12-20 21:14:10 -0800271 --no-quiet Print full output from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100272 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200273 --outcome-file=<path> File where test outcomes are written (not done if
274 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100275 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200276 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100277 -s|--seed Integer seed value to use for this test run.
278
279Tool path options:
280 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
281 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100282 --clang-earliest=<Clang_earliest_path> Earliest version of clang available
283 --clang-latest=<Clang_latest_path> Latest version of clang available
284 --gcc-earliest=<GCC_earliest_path> Earliest version of GCC available
285 --gcc-latest=<GCC_latest_path> Latest version of GCC available
Gilles Peskine709346a2017-12-10 23:43:39 +0100286 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
287 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
Gilles Peskine709346a2017-12-10 23:43:39 +0100288 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
289 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests e.g. SSLv3.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100290 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100291EOF
SimonB2e23c822016-04-16 21:54:39 +0100292}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100293
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200294# Cleanup before/after running a component.
295# Remove built files as well as the cmake cache/config.
296# Does not remove generated source files.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100297cleanup()
298{
Gilles Peskine7c652162017-12-11 00:01:40 +0100299 command make clean
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200300
Gilles Peskine31b07e22018-03-21 12:15:06 +0100301 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000302 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100303 -iname CMakeFiles -exec rm -rf {} \+ -o \
304 \( -iname cmake_install.cmake -o \
305 -iname CTestTestfile.cmake -o \
306 -iname CMakeCache.txt \) -exec rm {} \+
307 # Recover files overwritten by in-tree CMake builds
Gilles Peskine79598582022-08-30 21:02:44 +0200308 rm -f include/Makefile include/mbedtls/Makefile programs/!(fuzz)/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200309
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100310 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
311 rm -rf programs/test/cmake_subproject/build
312 rm -f programs/test/cmake_subproject/Makefile
313 rm -f programs/test/cmake_subproject/cmake_subproject
314
Gilles Peskine24bdf022020-03-30 20:11:39 +0200315 # Restore files that may have been clobbered by the job
316 for x in $files_to_back_up; do
Gilles Peskine423dd132022-08-30 21:02:00 +0200317 if [[ -e "$x$backup_suffix" ]]; then
318 cp -p "$x$backup_suffix" "$x"
319 fi
Gilles Peskine24bdf022020-03-30 20:11:39 +0200320 done
321}
John Durkopbd069d32020-10-31 22:14:03 -0700322
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200323# Final cleanup when this script exits (except when exiting on a failure
324# in non-keep-going mode).
Gilles Peskine24bdf022020-03-30 20:11:39 +0200325final_cleanup () {
326 cleanup
327
328 for x in $files_to_back_up; do
329 rm -f "$x$backup_suffix"
330 done
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100331}
332
Gilles Peskine7c652162017-12-11 00:01:40 +0100333# Executed on exit. May be redefined depending on command line options.
334final_report () {
335 :
336}
337
338fatal_signal () {
Gilles Peskine24bdf022020-03-30 20:11:39 +0200339 final_cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100340 final_report $1
341 trap - $1
342 kill -$1 $$
343}
344
345trap 'fatal_signal HUP' HUP
346trap 'fatal_signal INT' INT
347trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200348
Gilles Peskine85229ac2021-09-30 18:24:21 +0200349# Number of processors on this machine. Used as the default setting
350# for parallel make.
351all_sh_nproc ()
352{
353 {
354 nproc || # Linux
355 sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
356 sysctl -n hw.ncpu || # FreeBSD
357 echo 1
358 } 2>/dev/null
359}
360
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100361msg()
362{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100363 if [ -n "${current_component:-}" ]; then
364 current_section="${current_component#component_}: $1"
365 else
366 current_section="$1"
367 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200368
369 if [ $QUIET -eq 1 ]; then
370 return
371 fi
372
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100373 echo ""
374 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100375 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000376 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100377 echo "******************************************************************"
378}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100379
Gilles Peskine8f073122018-11-27 15:58:47 +0100380armc6_build_test()
381{
382 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100383
Gilles Peskine18487f62020-04-30 23:11:54 +0200384 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100385 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
Dave Rodgman6cda3d32023-03-02 13:39:04 +0000386 WARNING_CFLAGS='-Werror -xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200387
388 msg "size: ARM Compiler 6 ($FLAGS)"
389 "$ARMC6_FROMELF" -z library/*.o
390
Gilles Peskine8f073122018-11-27 15:58:47 +0100391 make clean
392}
Andres AGa5cd9732016-10-17 15:23:10 +0100393
Andres AGd9eba4b2016-08-26 14:42:14 +0100394err_msg()
395{
396 echo "$1" >&2
397}
398
399check_tools()
400{
401 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000402 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100403 err_msg "$TOOL not found!"
404 exit 1
405 fi
406 done
407}
408
Gilles Peskine8f073122018-11-27 15:58:47 +0100409pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000410 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100411 all_except=0
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100412 error_test=0
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100413 list_components=0
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200414 restore_first=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000415 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100416
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000417 # Note that legacy options are ignored instead of being omitted from this
418 # list of options, so invocations that worked with previous version of
419 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100420 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100421 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200422 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200423 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200424 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000425 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100426 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
427 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100428 --clang-earliest) shift; CLANG_EARLIEST="$1";;
429 --clang-latest) shift; CLANG_LATEST="$1";;
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100430 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000431 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100432 --force|-f) FORCE=1;;
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100433 --gcc-earliest) shift; GCC_EARLIEST="$1";;
434 --gcc-latest) shift; GCC_LATEST="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100435 --gnutls-cli) shift; GNUTLS_CLI="$1";;
Gilles Peskine549a9612023-08-27 21:39:21 +0200436 --gnutls-legacy-cli) shift;; # ignored for backward compatibility
437 --gnutls-legacy-serv) shift;; # ignored for backward compatibility
Gilles Peskine55f7c942019-01-09 22:28:21 +0100438 --gnutls-serv) shift; GNUTLS_SERV="$1";;
439 --help|-h) usage; exit;;
440 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000441 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100442 --list-components) list_components=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100443 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200444 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000445 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100446 --no-force) FORCE=0;;
447 --no-keep-going) KEEP_GOING=0;;
448 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200449 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100450 --openssl) shift; OPENSSL="$1";;
451 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
452 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200453 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100454 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200455 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100456 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200457 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200458 --restore) restore_first=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100459 --seed|-s) shift; SEED="$1";;
460 -*)
461 echo >&2 "Unknown option: $1"
462 echo >&2 "Run $0 --help for usage."
463 exit 120
464 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000465 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100466 esac
467 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100468 done
SimonB2e23c822016-04-16 21:54:39 +0100469
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100470 # Exclude components that are not supported on this platform.
471 SUPPORTED_COMPONENTS=
472 for component in $ALL_COMPONENTS; do
473 case $(type "support_$component" 2>&1) in
474 *' function'*)
475 if ! support_$component; then continue; fi;;
476 esac
477 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
478 done
479
480 if [ $list_components -eq 1 ]; then
481 printf '%s\n' $SUPPORTED_COMPONENTS
482 exit
483 fi
484
Gilles Peskinea28db922019-01-10 00:05:18 +0100485 # With no list of components, run everything.
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200486 if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000487 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100488 fi
489
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000490 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
491 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100492 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000493 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100494 fi
SimonB2e23c822016-04-16 21:54:39 +0100495
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200496 # Error out if an explicitly requested component doesn't exist.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100497 if [ $all_except -eq 0 ]; then
498 unsupported=0
Gilles Peskine6702ce92021-08-06 11:35:17 +0200499 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
500 # only does word splitting.
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200501 set -f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100502 for component in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200503 set +f
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200504 # If the requested name includes a wildcard character, don't
505 # check it. Accept wildcard patterns that don't match anything.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100506 case $component in
507 *[*?\[]*) continue;;
508 esac
509 case " $SUPPORTED_COMPONENTS " in
510 *" $component "*) :;;
511 *)
512 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
513 unsupported=$((unsupported + 1));;
514 esac
515 done
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200516 set +f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100517 if [ $unsupported -ne 0 ]; then
518 exit 2
519 fi
520 fi
521
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000522 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100523 RUN_COMPONENTS=
524 for component in $SUPPORTED_COMPONENTS; do
525 if is_component_included "$component"; [ $? -eq $all_except ]; then
526 RUN_COMPONENTS="$RUN_COMPONENTS $component"
527 fi
528 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000529
530 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000531 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100532}
SimonB2e23c822016-04-16 21:54:39 +0100533
Gilles Peskine8f073122018-11-27 15:58:47 +0100534pre_check_git () {
535 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100536 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100537 git checkout-index -f -q $CONFIG_H
538 cleanup
539 else
SimonB2e23c822016-04-16 21:54:39 +0100540
Gilles Peskine8f073122018-11-27 15:58:47 +0100541 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
542 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
543 echo "You can either delete this directory manually, or force the test by rerunning"
544 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
545 exit 1
546 fi
547
Gilles Peskined1174cf2019-01-09 22:30:01 +0100548 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100549 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
550 echo "You can either delete or preserve your work, or force the test by rerunning the"
551 echo "script as: $0 --force"
552 exit 1
553 fi
SimonB2e23c822016-04-16 21:54:39 +0100554 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500555}
556
Gilles Peskineef64e7f2021-07-12 18:16:01 +0200557pre_restore_files () {
558 # If the makefiles have been generated by a framework such as cmake,
559 # restore them from git. If the makefiles look like modifications from
560 # the ones checked into git, take care not to modify them. Whatever
561 # this function leaves behind is what the script will restore before
562 # each component.
563 case "$(head -n1 Makefile)" in
564 *[Gg]enerated*)
565 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
566 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
567 ;;
568 esac
569}
570
Gilles Peskine24bdf022020-03-30 20:11:39 +0200571pre_back_up () {
572 for x in $files_to_back_up; do
573 cp -p "$x" "$x$backup_suffix"
574 done
575}
576
Gilles Peskine8f073122018-11-27 15:58:47 +0100577pre_setup_keep_going () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100578 failure_count=0 # Number of failed components
579 last_failure_status=0 # Last failure status in this component
580
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100581 # See err_trap
582 previous_failure_status=0
583 previous_failed_command=
584 previous_failure_funcall_depth=0
Gilles Peskine39a3b112020-03-28 21:27:40 +0100585 unset report_failed_command
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100586
Gilles Peskine7c652162017-12-11 00:01:40 +0100587 start_red=
588 end_color=
589 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100590 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100591 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
592 start_red=$(printf '\033[31m')
593 end_color=$(printf '\033[0m')
594 ;;
595 esac
596 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100597
598 # Keep a summary of failures in a file. We'll print it out at the end.
599 failure_summary_file=$PWD/all-sh-failures-$$.log
600 : >"$failure_summary_file"
601
602 # Whether it makes sense to keep a component going after the specified
603 # command fails (test command) or not (configure or build).
Gilles Peskine6702ce92021-08-06 11:35:17 +0200604 # This function normally receives the failing simple command
605 # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
606 # this is passed instead.
Gilles Peskine7105a332020-03-28 18:50:43 +0100607 # This doesn't have to be 100% accurate: all failures are recorded anyway.
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200608 # False positives result in running things that can't be expected to
609 # work. False negatives result in things not running after something else
610 # failed even though they might have given useful feedback.
Gilles Peskine7105a332020-03-28 18:50:43 +0100611 can_keep_going_after_failure () {
612 case "$1" in
613 "msg "*) false;;
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200614 "cd "*) false;;
615 *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
616 *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
617 *make*check*) true;;
618 "grep "*) true;;
619 "[ "*) true;;
620 "! "*) true;;
Gilles Peskine7105a332020-03-28 18:50:43 +0100621 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100622 esac
623 }
Gilles Peskine7105a332020-03-28 18:50:43 +0100624
625 # This function runs if there is any error in a component.
626 # It must either exit with a nonzero status, or set
627 # last_failure_status to a nonzero value.
628 err_trap () {
629 # Save $? (status of the failing command). This must be the very
630 # first thing, before $? is overridden.
631 last_failure_status=$?
Gilles Peskine39a3b112020-03-28 21:27:40 +0100632 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskine7105a332020-03-28 18:50:43 +0100633
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100634 if [[ $last_failure_status -eq $previous_failure_status &&
635 "$failed_command" == "$previous_failed_command" &&
636 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
637 then
638 # The same command failed twice in a row, but this time one level
639 # less deep in the function call stack. This happens when the last
640 # command of a function returns a nonzero status, and the function
641 # returns that same status. Ignore the second failure.
642 previous_failure_funcall_depth=${#FUNCNAME[@]}
643 return
644 fi
645 previous_failure_status=$last_failure_status
646 previous_failed_command=$failed_command
647 previous_failure_funcall_depth=${#FUNCNAME[@]}
648
Gilles Peskine7105a332020-03-28 18:50:43 +0100649 text="$current_section: $failed_command -> $last_failure_status"
650 echo "${start_red}^^^^$text^^^^${end_color}" >&2
651 echo "$text" >>"$failure_summary_file"
652
653 # If the command is fatal (configure or build command), stop this
654 # component. Otherwise (test command) keep the component running
655 # (run more tests from the same build).
656 if ! can_keep_going_after_failure "$failed_command"; then
657 exit $last_failure_status
658 fi
659 }
660
Gilles Peskine7c652162017-12-11 00:01:40 +0100661 final_report () {
662 if [ $failure_count -gt 0 ]; then
663 echo
664 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskine7105a332020-03-28 18:50:43 +0100665 echo "${start_red}FAILED: $failure_count components${end_color}"
666 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100667 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
668 elif [ -z "${1-}" ]; then
669 echo "SUCCESS :)"
670 fi
671 if [ -n "${1-}" ]; then
672 echo "Killed by SIG$1."
673 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100674 rm -f "$failure_summary_file"
675 if [ $failure_count -gt 0 ]; then
676 exit 1
677 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100678 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100679}
680
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200681# record_status() and if_build_succeeded() are kept temporarily for backward
682# compatibility. Don't use them in new components.
Gilles Peskine7105a332020-03-28 18:50:43 +0100683record_status () {
684 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100685}
Gilles Peskine7c652162017-12-11 00:01:40 +0100686if_build_succeeded () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100687 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100688}
689
Gilles Peskine39a3b112020-03-28 21:27:40 +0100690# '! true' does not trigger the ERR trap. Arrange to trigger it, with
691# a reasonably informative error message (not just "$@").
692not () {
693 if "$@"; then
694 report_failed_command="! $*"
695 false
696 unset report_failed_command
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200697 fi
698}
699
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200700pre_prepare_outcome_file () {
701 case "$MBEDTLS_TEST_OUTCOME_FILE" in
702 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
703 esac
704 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
705 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
706 fi
707}
708
Gilles Peskine8f073122018-11-27 15:58:47 +0100709pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200710 if [ $QUIET -eq 1 ]; then
711 return
712 fi
713
Gilles Peskine8f073122018-11-27 15:58:47 +0100714 msg "info: $0 configuration"
715 echo "MEMORY: $MEMORY"
716 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200717 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100718 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100719 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100720 echo "OPENSSL: $OPENSSL"
721 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
722 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
723 echo "GNUTLS_CLI: $GNUTLS_CLI"
724 echo "GNUTLS_SERV: $GNUTLS_SERV"
Gilles Peskine8f073122018-11-27 15:58:47 +0100725 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
726 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
727}
Andres AG7770ea82016-10-10 15:46:20 +0100728
Andres AGd9eba4b2016-08-26 14:42:14 +0100729# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100730pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000731 # Build the list of variables to pass to output_env.sh.
732 set env
SimonB2e23c822016-04-16 21:54:39 +0100733
Gilles Peskine87964262019-01-06 22:40:00 +0000734 case " $RUN_COMPONENTS " in
735 # Require OpenSSL and GnuTLS if running any tests (as opposed to
736 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
737 # is a good enough approximation in practice.
Bence Szépkúticb89fbd2023-12-15 20:58:15 +0100738 *" test_"* | *" release_test_"*)
Gilles Peskine87964262019-01-06 22:40:00 +0000739 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
740 # and ssl-opt.sh, we just export the variables they require.
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +0100741 export OPENSSL="$OPENSSL"
Gilles Peskine87964262019-01-06 22:40:00 +0000742 export GNUTLS_CLI="$GNUTLS_CLI"
743 export GNUTLS_SERV="$GNUTLS_SERV"
744 # Avoid passing --seed flag in every call to ssl-opt.sh
745 if [ -n "${SEED-}" ]; then
746 export SEED
747 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000748 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
749 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000750 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
Gilles Peskine549a9612023-08-27 21:39:21 +0200751 "$GNUTLS_CLI" "$GNUTLS_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000752 ;;
753 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200754
Gilles Peskine87964262019-01-06 22:40:00 +0000755 case " $RUN_COMPONENTS " in
756 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
757 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100758
Gilles Peskine87964262019-01-06 22:40:00 +0000759 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200760 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000761 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100762
Gilles Peskine87964262019-01-06 22:40:00 +0000763 case " $RUN_COMPONENTS " in
764 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
765 esac
766
767 case " $RUN_COMPONENTS " in
768 *" test_zeroize "*) check_tools "gdb";;
769 esac
770
771 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000772 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000773 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
774 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200775 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000776 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
777 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200778 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
779 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
780 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000781 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000782
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200783 # past this point, no call to check_tool, only printing output
784 if [ $QUIET -eq 1 ]; then
785 return
786 fi
787
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000788 msg "info: output_env.sh"
789 case $RUN_COMPONENTS in
790 *_armcc*)
791 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
792 *) set "$@" RUN_ARMCC=0;;
793 esac
794 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100795}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100796
Gilles Peskine192c72f2017-12-21 15:59:21 +0100797
798
799################################################################
800#### Basic checks
801################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100802
803#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200804# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100805#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100806# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200807# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100808# 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 +0200809# time, so start with a GCC build).
810# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100811#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100812# Indicative running times are given for reference.
813
Gilles Peskine8f073122018-11-27 15:58:47 +0100814component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200815 msg "Check: recursion.pl" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200816 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100817}
Janos Follathb72c6782016-07-19 14:54:17 +0100818
Gilles Peskine8f073122018-11-27 15:58:47 +0100819component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200820 msg "Check: freshness of generated source files" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200821 tests/scripts/check-generated-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100822}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200823
Gilles Peskine8f073122018-11-27 15:58:47 +0100824component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200825 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200826 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +0100827}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200828
Gilles Peskine8f073122018-11-27 15:58:47 +0100829component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200830 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200831 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100832}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200833
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200834component_check_changelog () {
835 msg "Check: changelog entries" # < 1s
836 rm -f ChangeLog.new
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200837 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200838 if [ -e ChangeLog.new ]; then
839 # Show the diff for information. It isn't an error if the diff is
840 # non-empty.
841 diff -u ChangeLog ChangeLog.new || true
842 rm ChangeLog.new
843 fi
844}
845
Gilles Peskine8f073122018-11-27 15:58:47 +0100846component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200847 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200848 tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100849}
Darryl Greena07039c2018-03-13 16:48:16 +0000850
Gilles Peskine895868b2019-09-19 21:30:05 +0200851component_check_test_cases () {
852 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200853 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200854 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200855 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200856 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200857 fi
Gilles Peskine58987962022-12-15 14:46:31 +0100858 tests/scripts/check_test_cases.py -q $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200859 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +0200860}
861
Gilles Peskine8f073122018-11-27 15:58:47 +0100862component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200863 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200864 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100865}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200866
Gilles Peskine192c72f2017-12-21 15:59:21 +0100867
Gilles Peskine636c26a2020-03-04 20:46:15 +0100868
Gilles Peskine192c72f2017-12-21 15:59:21 +0100869################################################################
870#### Build and test many configurations and targets
871################################################################
872
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200873component_test_default_out_of_box () {
874 msg "build: make, default config (out-of-box)" # ~1min
875 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200876 # Disable fancy stuff
877 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200878
879 msg "test: main suites make, default config (out-of-box)" # ~10s
880 make test
881
882 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200883 programs/test/selftest
Gilles Peskine93aaf2e2019-06-14 18:27:03 +0200884
885 msg "program demos: make, default config (out-of-box)" # ~10s
886 tests/scripts/run_demos.py
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200887}
888
Gilles Peskine8f073122018-11-27 15:58:47 +0100889component_test_default_cmake_gcc_asan () {
890 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100891 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
892 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200893
Gilles Peskine8f073122018-11-27 15:58:47 +0100894 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
895 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200896
Gilles Peskine93aaf2e2019-06-14 18:27:03 +0200897 msg "program demos (ASan build)" # ~10s
898 tests/scripts/run_demos.py
899
Gilles Peskine97bea012020-04-23 23:37:45 +0200900 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200901 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200902
Gilles Peskineee8af062023-11-02 19:58:03 +0100903 msg "test: metatests (GCC, ASan build)"
David Horstmann1b421b12024-01-17 14:53:08 +0000904 tests/scripts/run-metatests.sh any asan poison
Gilles Peskineee8af062023-11-02 19:58:03 +0100905
Gilles Peskine8f073122018-11-27 15:58:47 +0100906 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200907 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200908
Gilles Peskine8f073122018-11-27 15:58:47 +0100909 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200910 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200911
912 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200913 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100914}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200915
Hanno Becker01635512019-02-26 14:27:09 +0000916component_test_full_cmake_gcc_asan () {
917 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200918 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000919 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
920 make
921
922 msg "test: main suites (inc. selftests) (full config, ASan build)"
923 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +0100924
Gilles Peskine97bea012020-04-23 23:37:45 +0200925 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200926 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200927
Gilles Peskine636c26a2020-03-04 20:46:15 +0100928 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200929 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100930
931 msg "test: compat.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200932 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200933
934 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200935 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100936}
937
Ronald Cronc3623db2020-10-29 10:51:32 +0100938component_test_psa_crypto_key_id_encodes_owner () {
939 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
940 scripts/config.py full
941 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
942 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
943 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
944 make
945
946 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
947 make test
948}
949
David Horstmann42015332024-03-13 15:42:31 +0000950component_test_psa_assume_exclusive_buffers () {
951 msg "build: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
David Horstmanndda52ae2023-12-20 11:10:16 +0000952 scripts/config.py full
David Horstmann42015332024-03-13 15:42:31 +0000953 scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
David Horstmanndda52ae2023-12-20 11:10:16 +0000954 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
955 make
956
David Horstmann42015332024-03-13 15:42:31 +0000957 msg "test: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
David Horstmanndda52ae2023-12-20 11:10:16 +0000958 make test
959}
960
Gilles Peskine99a34622021-06-17 11:37:52 +0200961# check_renamed_symbols HEADER LIB
962# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
963# name is LIB.
964check_renamed_symbols () {
965 ! nm "$2" | sed 's/.* //' |
966 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
967}
968
Gilles Peskine984c19f2021-06-15 18:37:38 +0200969component_build_psa_crypto_spm () {
970 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
971 scripts/config.py full
972 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
973 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
974 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
975 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
976 # We can only compile, not link, since our test and sample programs
977 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
978 # is active.
979 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskine99a34622021-06-17 11:37:52 +0200980
981 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
982 # version is not present.
983 echo "Checking for renamed symbols in the library"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200984 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskine984c19f2021-06-15 18:37:38 +0200985}
986
Ronald Cron336678b2021-01-28 17:54:24 +0100987component_test_psa_crypto_client () {
988 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
989 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
990 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
991 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
992 make
993
994 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
995 make test
996}
997
Gilles Peskine636c26a2020-03-04 20:46:15 +0100998component_test_zlib_make() {
999 msg "build: zlib enabled, make"
1000 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine6fa69862021-10-05 09:36:03 +02001001 make ZLIB=1 CFLAGS='-Werror -O2'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001002
1003 msg "test: main suites (zlib, make)"
1004 make test
1005
1006 msg "test: ssl-opt.sh (zlib, make)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001007 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001008}
1009support_test_zlib_make () {
1010 base=support_test_zlib_$$
1011 cat <<'EOF' > ${base}.c
1012#include "zlib.h"
1013int main(void) { return 0; }
1014EOF
1015 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
1016 ret=$?
1017 rm -f ${base}.*
1018 return $ret
1019}
1020
1021component_test_zlib_cmake() {
Dave Rodgmandff18da2024-03-01 15:53:52 +00001022 # This is needed due to something parsing the output from make
1023 export VERBOSE_LOGS=1
1024
Gilles Peskine636c26a2020-03-04 20:46:15 +01001025 msg "build: zlib enabled, cmake"
1026 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine25319702021-10-07 19:34:57 +02001027 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Release .
Gilles Peskine636c26a2020-03-04 20:46:15 +01001028 make
1029
1030 msg "test: main suites (zlib, cmake)"
1031 make test
1032
1033 msg "test: ssl-opt.sh (zlib, cmake)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001034 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001035}
1036support_test_zlib_cmake () {
1037 support_test_zlib_make "$@"
Manuel Pégourié-Gonnardf2e29022020-01-24 10:17:20 +01001038}
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +01001039
Jaeden Ameroc17f2932021-05-14 08:34:32 +01001040component_test_psa_crypto_rsa_no_genprime() {
1041 msg "build: default config minus MBEDTLS_GENPRIME"
1042 scripts/config.py unset MBEDTLS_GENPRIME
1043 make
1044
1045 msg "test: default config minus MBEDTLS_GENPRIME"
1046 make test
1047}
1048
Gilles Peskine782f4112018-11-27 16:11:09 +01001049component_test_ref_configs () {
1050 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
1051 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001052 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +01001053}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001054
Gilles Peskine8f073122018-11-27 15:58:47 +01001055component_test_sslv3 () {
1056 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001057 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +01001058 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1059 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001060
Gilles Peskine8f073122018-11-27 15:58:47 +01001061 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
1062 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +00001063
Gilles Peskine8f073122018-11-27 15:58:47 +01001064 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001065 tests/compat.sh -m 'ssl3 tls1 tls1_1 tls12 dtls1 dtls12'
Simon Butcher3ea7f522016-03-07 23:22:10 +00001066
Gilles Peskine8f073122018-11-27 15:58:47 +01001067 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001068 tests/ssl-opt.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001069
1070 msg "build: SSLv3 - context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001071 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001072}
Simon Butcher3ea7f522016-03-07 23:22:10 +00001073
Gilles Peskine8f073122018-11-27 15:58:47 +01001074component_test_no_renegotiation () {
1075 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001076 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001077 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1078 make
Simon Butcher3ea7f522016-03-07 23:22:10 +00001079
Gilles Peskine8f073122018-11-27 15:58:47 +01001080 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1081 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +01001082
Gilles Peskine8f073122018-11-27 15:58:47 +01001083 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001084 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001085}
Hanno Becker134c2ab2017-10-12 15:29:50 +01001086
Gilles Peskine56194432023-02-01 18:44:11 +01001087component_test_no_certs () {
1088 msg "build: full minus MBEDTLS_CERTS_C"
1089 scripts/config.py full
1090 scripts/config.py unset MBEDTLS_CERTS_C
1091 # Quick build+test (we're checking for stray uses of the test certs,
1092 # not expecting their absence to lead to subtle problems).
1093 make
1094
1095 msg "test: full minus MBEDTLS_CERTS_C - main suites"
1096 make test
1097}
1098
Gilles Peskine636c26a2020-03-04 20:46:15 +01001099component_test_no_pem_no_fs () {
1100 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1101 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1102 scripts/config.py unset MBEDTLS_FS_IO
1103 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1104 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
1105 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1106 make
1107
1108 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1109 make test
1110
1111 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001112 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001113}
1114
Gilles Peskine8f073122018-11-27 15:58:47 +01001115component_test_rsa_no_crt () {
1116 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001117 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +01001118 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1119 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +01001120
Gilles Peskine8f073122018-11-27 15:58:47 +01001121 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1122 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001123
Gilles Peskine8f073122018-11-27 15:58:47 +01001124 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001125 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001126
Gilles Peskine8f073122018-11-27 15:58:47 +01001127 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001128 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001129
1130 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001131 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001132}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001133
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001134component_test_no_ctr_drbg_classic () {
1135 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001136 scripts/config.py full
1137 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001138 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001139
1140 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1141 make
1142
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001143 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001144 make test
1145
Gilles Peskineba749042021-01-13 20:02:03 +01001146 # In this configuration, the TLS test programs use HMAC_DRBG.
1147 # The SSL tests are slow, so run a small subset, just enough to get
1148 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001149 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001150 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001151
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001152 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001153 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001154}
1155
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001156component_test_no_ctr_drbg_use_psa () {
1157 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001158 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001159 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1160 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001161
1162 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1163 make
1164
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001165 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1166 make test
1167
1168 # In this configuration, the TLS test programs use HMAC_DRBG.
1169 # The SSL tests are slow, so run a small subset, just enough to get
1170 # confidence that the SSL code copes with HMAC_DRBG.
1171 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001172 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001173
1174 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001175 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001176}
1177
1178component_test_no_hmac_drbg_classic () {
1179 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1180 scripts/config.py full
1181 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1182 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1183 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1184
1185 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1186 make
1187
1188 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001189 make test
1190
Gilles Peskinea2224342020-11-19 22:14:34 +01001191 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1192 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1193 # instead.
1194 # Test SSL with non-deterministic ECDSA. Only test features that
1195 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001196 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001197 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001198
1199 # To save time, only test one protocol version, since this part of
1200 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001201 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001202 tests/compat.sh -m tls12 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001203}
1204
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001205component_test_no_hmac_drbg_use_psa () {
1206 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1207 scripts/config.py full
1208 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1209 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1210 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1211
1212 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1213 make
1214
1215 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1216 make test
1217
1218 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1219 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1220 # instead.
1221 # Test SSL with non-deterministic ECDSA. Only test features that
1222 # might be affected by how ECDSA signature is performed.
1223 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001224 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001225
1226 # To save time, only test one protocol version, since this part of
1227 # the protocol is identical in (D)TLS up to 1.2.
1228 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001229 tests/compat.sh -m tls12 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001230}
1231
1232component_test_psa_external_rng_no_drbg_classic () {
1233 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1234 scripts/config.py full
1235 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1236 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001237 scripts/config.py unset MBEDTLS_ENTROPY_C
1238 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1239 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001240 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1241 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1242 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1243 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001244 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1245 # the SSL test programs don't have an RNG and can't work. Explicitly
1246 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1247 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001248
1249 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1250 make test
1251
Gilles Peskine8eb29432021-02-03 20:07:11 +01001252 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001253 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001254}
1255
1256component_test_psa_external_rng_no_drbg_use_psa () {
1257 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001258 scripts/config.py full
1259 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001260 scripts/config.py unset MBEDTLS_ENTROPY_C
1261 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1262 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001263 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1264 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1265 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1266 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1267 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1268
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001269 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001270 make test
1271
Gilles Peskine8eb29432021-02-03 20:07:11 +01001272 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001273 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001274}
1275
1276component_test_psa_external_rng_use_psa_crypto () {
1277 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1278 scripts/config.py full
1279 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1280 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1281 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1282 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1283
1284 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1285 make test
1286
Gilles Peskineba749042021-01-13 20:02:03 +01001287 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001288 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001289}
1290
Gilles Peskine55e89982023-04-28 21:04:28 +02001291component_test_psa_inject_entropy () {
1292 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
1293 scripts/config.py full
1294 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
1295 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
1296 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1297 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1298 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
1299 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
1300 make CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
1301
1302 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
1303 make test
1304}
1305
Manuel Pégourié-Gonnard1a3f9ed2020-05-19 12:38:31 +02001306component_test_ecp_no_internal_rng () {
1307 msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
1308 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1309 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1310 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1311 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1312 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
1313 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1314
1315 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1316 make
1317
1318 msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
1319 make test
1320
1321 # no SSL tests as they all depend on having a DRBG
1322}
1323
Manuel Pégourié-Gonnard53fb66d2020-06-04 09:43:14 +02001324component_test_ecp_restartable_no_internal_rng () {
1325 msg "build: Default plus ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG"
1326 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1327 scripts/config.py set MBEDTLS_ECP_RESTARTABLE
1328 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1329 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1330 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1331 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
1332 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1333
1334 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1335 make
1336
1337 msg "test: ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG module"
1338 make test
1339
1340 # no SSL tests as they all depend on having a DRBG
1341}
1342
Przemek Stekiele5352702022-10-05 11:37:54 +02001343component_test_tls1_2_default_stream_cipher_only () {
1344 msg "build: default with only stream cipher"
1345
1346 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
1347 scripts/config.py unset MBEDTLS_GCM_C
1348 scripts/config.py unset MBEDTLS_CCM_C
1349 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1350 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1351 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1352 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1353 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1354 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1355 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1356 # Modules that depend on AEAD
1357 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001358 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001359
1360 make
1361
1362 msg "test: default with only stream cipher"
1363 make test
1364
1365 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1366}
1367
1368component_test_tls1_2_default_stream_cipher_only_use_psa () {
1369 msg "build: default with only stream cipher use psa"
1370
1371 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1372 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1373 scripts/config.py unset MBEDTLS_GCM_C
1374 scripts/config.py unset MBEDTLS_CCM_C
1375 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1376 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1377 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1378 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1379 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1380 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1381 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1382 # Modules that depend on AEAD
1383 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001384 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001385
1386 make
1387
1388 msg "test: default with only stream cipher use psa"
1389 make test
1390
1391 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1392}
1393
1394component_test_tls1_2_default_cbc_legacy_cipher_only () {
1395 msg "build: default with only CBC-legacy cipher"
1396
1397 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1398 scripts/config.py unset MBEDTLS_GCM_C
1399 scripts/config.py unset MBEDTLS_CCM_C
1400 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1401 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1402 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1403 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1404 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1405 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1406 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1407 # Modules that depend on AEAD
1408 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001409 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001410
1411 make
1412
1413 msg "test: default with only CBC-legacy cipher"
1414 make test
1415
1416 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1417 tests/ssl-opt.sh -f "TLS 1.2"
1418}
1419
1420component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
1421 msg "build: default with only CBC-legacy cipher use psa"
1422
1423 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1424 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1425 scripts/config.py unset MBEDTLS_GCM_C
1426 scripts/config.py unset MBEDTLS_CCM_C
1427 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1428 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1429 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1430 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1431 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1432 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1433 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1434 # Modules that depend on AEAD
1435 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001436 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001437
1438 make
1439
1440 msg "test: default with only CBC-legacy cipher use psa"
1441 make test
1442
1443 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1444 tests/ssl-opt.sh -f "TLS 1.2"
1445}
1446
1447component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
1448 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1449
1450 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1451 scripts/config.py unset MBEDTLS_GCM_C
1452 scripts/config.py unset MBEDTLS_CCM_C
1453 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1454 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1455 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1456 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1457 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1458 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1459 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1460 # Modules that depend on AEAD
1461 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001462 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001463
1464 make
1465
1466 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1467 make test
1468
1469 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1470 tests/ssl-opt.sh -f "TLS 1.2"
1471}
1472
1473component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
1474 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
1475
1476 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1477 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1478 scripts/config.py unset MBEDTLS_GCM_C
1479 scripts/config.py unset MBEDTLS_CCM_C
1480 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1481 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1482 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1483 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1484 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1485 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1486 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1487 # Modules that depend on AEAD
1488 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001489 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001490
1491 make
1492
1493 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
1494 make test
1495
1496 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
1497 tests/ssl-opt.sh -f "TLS 1.2"
1498}
1499
Gilles Peskine636c26a2020-03-04 20:46:15 +01001500component_test_new_ecdh_context () {
1501 msg "build: new ECDH context (ASan build)" # ~ 6 min
1502 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1503 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1504 make
1505
1506 msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1507 make test
1508
1509 msg "test: new ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001510 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001511
1512 msg "test: new ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1513 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001514 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001515}
1516
1517component_test_everest () {
1518 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
1519 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1520 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1521 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1522 make
1523
1524 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1525 make test
1526
Gilles Peskineee8af062023-11-02 19:58:03 +01001527 msg "test: metatests (clang, ASan)"
David Horstmann1b421b12024-01-17 14:53:08 +00001528 tests/scripts/run-metatests.sh any asan poison
Gilles Peskineee8af062023-11-02 19:58:03 +01001529
Gilles Peskine636c26a2020-03-04 20:46:15 +01001530 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001531 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001532
1533 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1534 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001535 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001536}
1537
Gilles Peskined3beca92020-07-03 00:15:37 +02001538component_test_everest_curve25519_only () {
1539 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
1540 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1541 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1542 scripts/config.py unset MBEDTLS_ECDSA_C
1543 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1544 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1545 # Disable all curves
1546 for c in $(sed -n 's/#define \(MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED\).*/\1/p' <"$CONFIG_H"); do
1547 scripts/config.py unset "$c"
1548 done
1549 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1550
1551 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1552
1553 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1554 make test
1555}
1556
Gilles Peskine8f073122018-11-27 15:58:47 +01001557component_test_small_ssl_out_content_len () {
1558 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001559 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1560 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001561 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1562 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001563
Gilles Peskine8f073122018-11-27 15:58:47 +01001564 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001565 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001566}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001567
Gilles Peskine8f073122018-11-27 15:58:47 +01001568component_test_small_ssl_in_content_len () {
1569 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001570 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1571 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001572 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1573 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001574
Gilles Peskine8f073122018-11-27 15:58:47 +01001575 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001576 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001577}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001578
Gilles Peskine8f073122018-11-27 15:58:47 +01001579component_test_small_ssl_dtls_max_buffering () {
1580 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001581 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001582 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1583 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001584
Gilles Peskine8f073122018-11-27 15:58:47 +01001585 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001586 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 +01001587}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001588
Gilles Peskine8f073122018-11-27 15:58:47 +01001589component_test_small_mbedtls_ssl_dtls_max_buffering () {
1590 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001591 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001592 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1593 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001594
Gilles Peskine8f073122018-11-27 15:58:47 +01001595 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001596 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001597}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001598
Gilles Peskine75cc7712019-09-06 19:47:17 +02001599component_test_psa_collect_statuses () {
1600 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001601 scripts/config.py full
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001602 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001603 # Check that psa_crypto_init() succeeded at least once
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001604 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001605 rm -f tests/statuses.log
1606}
1607
Gilles Peskine8f073122018-11-27 15:58:47 +01001608component_test_full_cmake_clang () {
1609 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001610 scripts/config.py full
Gilles Peskine83264be2022-10-30 21:02:40 +01001611 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 +01001612 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001613
k-stachowiak0291cb72019-06-26 15:52:12 +02001614 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001615 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001616
Gilles Peskine83264be2022-10-30 21:02:40 +01001617 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
1618 programs/test/cpp_dummy_build
1619
Gilles Peskineee8af062023-11-02 19:58:03 +01001620 msg "test: metatests (clang)"
Gilles Peskinee38eb792023-11-03 18:05:38 +01001621 tests/scripts/run-metatests.sh any pthread
Gilles Peskineee8af062023-11-02 19:58:03 +01001622
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02001623 msg "program demos (full config, clang)" # ~10s
1624 tests/scripts/run_demos.py
1625
k-stachowiak0291cb72019-06-26 15:52:12 +02001626 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001627 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001628
Gilles Peskine8f073122018-11-27 15:58:47 +01001629 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001630 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001631
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001632 msg "test: compat.sh RC4, 3DES & NULL (full config)" # ~ 2min
1633 tests/compat.sh -e '^$' -f 'NULL\|3DES\|DES-CBC3\|RC4\|ARCFOUR'
1634
1635 msg "test: compat.sh single-DES (full config)" # ~ 30s
1636 env OPENSSL="$OPENSSL_LEGACY" tests/compat.sh -e '3DES\|DES-CBC3' -f 'DES'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001637
Gilles Peskine8f073122018-11-27 15:58:47 +01001638 msg "test: compat.sh ARIA + ChachaPoly"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001639 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001640}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001641
Gilles Peskine9603a442022-11-29 16:01:41 +01001642skip_suites_without_constant_flow () {
1643 # Skip the test suites that don't have any constant-flow annotations.
1644 # This will need to be adjusted if we ever start declaring things as
1645 # secret from macros or functions inside tests/include or tests/src.
1646 SKIP_TEST_SUITES=$(
1647 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
1648 sed 's/test_suite_//; s/\.function$//' |
1649 tr '\n' ,)
1650 export SKIP_TEST_SUITES
1651}
1652
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001653component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001654 # This tests both (1) accesses to undefined memory, and (2) branches or
1655 # memory access depending on secret values. To distinguish between those:
1656 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1657 # - or alternatively, change the build type to MemSanDbg, which enables
1658 # origin tracking and nicer stack traces (which are useful for debugging
1659 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1660 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001661 scripts/config.py full
1662 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1663 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1664 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1665 make
1666
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001667 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001668 make test
1669}
1670
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01001671component_release_test_valgrind_constant_flow () {
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001672 # This tests both (1) everything that valgrind's memcheck usually checks
1673 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1674 # etc.) and (2) branches or memory access depending on secret values,
1675 # which will be reported as uninitialized memory. To distinguish between
1676 # secret and actually uninitialized:
1677 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1678 # - or alternatively, build with debug info and manually run the offending
1679 # test suite with valgrind --track-origins=yes, then check if the origin
1680 # was TEST_CF_SECRET() or something else.
1681 msg "build: cmake release GCC, full config with constant flow testing"
1682 scripts/config.py full
1683 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Gilles Peskine9603a442022-11-29 16:01:41 +01001684 skip_suites_without_constant_flow
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001685 cmake -D CMAKE_BUILD_TYPE:String=Release .
1686 make
1687
1688 # this only shows a summary of the results (how many of each type)
1689 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine9603a442022-11-29 16:01:41 +01001690 msg "test: some suites (valgrind + constant flow)"
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001691 make memcheck
1692}
1693
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001694component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02001695 # Test that removing the deprecated features from the default
1696 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001697 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1698 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
Dave Rodgman374b1882024-01-04 10:30:57 +00001699 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001700
1701 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1702 make test
1703}
1704
1705component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02001706 msg "build: make, full_no_deprecated config" # ~ 30s
1707 scripts/config.py full_no_deprecated
Dave Rodgman374b1882024-01-04 10:30:57 +00001708 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001709
Gilles Peskine30de2e82020-04-20 21:39:22 +02001710 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001711 make test
1712}
1713
Gilles Peskine8386ea22020-04-30 09:07:29 +02001714component_test_full_no_deprecated_deprecated_warning () {
1715 # Test that there is nothing deprecated in "full_no_deprecated".
1716 # A deprecated feature would trigger a warning (made fatal) from
1717 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02001718 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1719 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001720 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
1721 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Dave Rodgman374b1882024-01-04 10:30:57 +00001722 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001723
Gilles Peskine30de2e82020-04-20 21:39:22 +02001724 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001725 make test
1726}
1727
Gilles Peskine8386ea22020-04-30 09:07:29 +02001728component_test_full_deprecated_warning () {
1729 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
1730 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001731 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001732 scripts/config.py full
1733 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001734 # Expect warnings from '#warning' directives in check_config.h.
Dave Rodgman9d2c67f2023-12-19 14:07:15 +00001735 # Note that gcc is required to allow the use of -Wno-error=cpp, which allows us to
1736 # display #warning messages without them being treated as errors.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001737 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001738
Gilles Peskine8386ea22020-04-30 09:07:29 +02001739 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1740 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
1741 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001742 # Expect warnings from '#warning' directives in check_config.h and
1743 # from the use of deprecated functions in test suites.
1744 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 +01001745
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001746 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
1747 make test
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02001748
1749 msg "program demos: full config + MBEDTLS_TEST_DEPRECATED" # ~10s
1750 tests/scripts/run_demos.py
Gilles Peskine8f073122018-11-27 15:58:47 +01001751}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00001752
Gilles Peskineec541fe2020-01-31 14:24:14 +01001753# Check that the specified libraries exist and are empty.
1754are_empty_libraries () {
1755 nm "$@" >/dev/null 2>/dev/null
1756 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
1757}
1758
1759component_build_crypto_default () {
1760 msg "build: make, crypto only"
1761 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01001762 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001763 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001764}
1765
1766component_build_crypto_full () {
1767 msg "build: make, crypto only, full config"
1768 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01001769 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001770 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001771}
1772
Gilles Peskine8df27482022-10-21 19:34:54 +02001773component_test_crypto_for_psa_service () {
Gilles Peskine21503df2022-10-11 21:05:06 +02001774 msg "build: make, config for PSA crypto service"
1775 scripts/config.py crypto
1776 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1777 # Disable things that are not needed for just cryptography, to
1778 # reach a configuration that would be typical for a PSA cryptography
1779 # service providing all implemented PSA algorithms.
1780 # System stuff
1781 scripts/config.py unset MBEDTLS_ERROR_C
1782 scripts/config.py unset MBEDTLS_TIMING_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001783 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskine21503df2022-10-11 21:05:06 +02001784 # Crypto stuff with no PSA interface
1785 scripts/config.py unset MBEDTLS_BASE64_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001786 scripts/config.py unset MBEDTLS_BLOWFISH_C
1787 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
1788 # Keep MBEDTLS_MD_C because RSA and ECDSA need it, also HMAC_DRBG which
1789 # is needed for deterministic ECDSA.
1790 scripts/config.py unset MBEDTLS_ECJPAKE_C
1791 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
Gilles Peskine21503df2022-10-11 21:05:06 +02001792 scripts/config.py unset MBEDTLS_NIST_KW_C
1793 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1794 scripts/config.py unset MBEDTLS_PEM_WRITE_C
1795 scripts/config.py unset MBEDTLS_PKCS12_C
1796 scripts/config.py unset MBEDTLS_PKCS5_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001797 # We keep MBEDTLS_PK_{,PARSE,WRITE}_C because PSA with RSA needs it.
1798 scripts/config.py unset MBEDTLS_XTEA_C
Gilles Peskine21503df2022-10-11 21:05:06 +02001799 make CFLAGS='-O1 -Werror' all test
1800 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1801}
1802
Gilles Peskineec541fe2020-01-31 14:24:14 +01001803component_build_crypto_baremetal () {
1804 msg "build: make, crypto only, baremetal config"
1805 scripts/config.py crypto_baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001806 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001807 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001808}
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001809support_build_crypto_baremetal () {
Daniel Axtens1a021af2020-08-31 14:22:58 +10001810 support_build_baremetal "$@"
1811}
1812
1813component_build_baremetal () {
1814 msg "build: make, baremetal config"
1815 scripts/config.py baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001816 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Daniel Axtens1a021af2020-08-31 14:22:58 +10001817}
1818support_build_baremetal () {
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001819 # Older Glibc versions include time.h from other headers such as stdlib.h,
1820 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
1821 # problem, Ubuntu 18.04 is ok.
1822 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
1823}
Gilles Peskineec541fe2020-01-31 14:24:14 +01001824
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001825# depends.py family of tests
Andrzej Kurek85d69302022-10-05 09:14:07 -04001826component_test_depends_py_cipher_id () {
1827 msg "test/build: depends.py cipher_id (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001828 tests/scripts/depends.py cipher_id --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001829}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001830
Andrzej Kurek85d69302022-10-05 09:14:07 -04001831component_test_depends_py_cipher_chaining () {
1832 msg "test/build: depends.py cipher_chaining (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001833 tests/scripts/depends.py cipher_chaining --unset-use-psa
John Durkopc14be902020-08-20 06:16:41 -07001834}
1835
Andrzej Kurek85d69302022-10-05 09:14:07 -04001836component_test_depends_py_cipher_padding () {
1837 msg "test/build: depends.py cipher_padding (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001838 tests/scripts/depends.py cipher_padding --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001839}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001840
Andrzej Kurek85d69302022-10-05 09:14:07 -04001841component_test_depends_py_curves () {
1842 msg "test/build: depends.py curves (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001843 tests/scripts/depends.py curves --unset-use-psa
John Durkop2ec2eaa2020-08-24 18:29:15 -07001844}
1845
Andrzej Kurek85d69302022-10-05 09:14:07 -04001846component_test_depends_py_hashes () {
1847 msg "test/build: depends.py hashes (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001848 tests/scripts/depends.py hashes --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001849}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001850
Andrzej Kurek85d69302022-10-05 09:14:07 -04001851component_test_depends_py_kex () {
1852 msg "test/build: depends.py kex (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001853 tests/scripts/depends.py kex --unset-use-psa
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001854}
1855
Andrzej Kurek85d69302022-10-05 09:14:07 -04001856component_test_depends_py_pkalgs () {
1857 msg "test/build: depends.py pkalgs (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001858 tests/scripts/depends.py pkalgs --unset-use-psa
1859}
1860
1861# PSA equivalents of the depends.py tests
1862component_test_depends_py_cipher_id_psa () {
1863 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1864 tests/scripts/depends.py cipher_id
1865}
1866
1867component_test_depends_py_cipher_chaining_psa () {
1868 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1869 tests/scripts/depends.py cipher_chaining
1870}
1871
1872component_test_depends_py_cipher_padding_psa () {
1873 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1874 tests/scripts/depends.py cipher_padding
1875}
1876
1877component_test_depends_py_curves_psa () {
1878 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1879 tests/scripts/depends.py curves
1880}
1881
1882component_test_depends_py_hashes_psa () {
1883 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1884 tests/scripts/depends.py hashes
1885}
1886
1887component_test_depends_py_kex_psa () {
1888 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1889 tests/scripts/depends.py kex
1890}
1891
1892component_test_depends_py_pkalgs_psa () {
1893 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Andrzej Kurek85d69302022-10-05 09:14:07 -04001894 tests/scripts/depends.py pkalgs
Gilles Peskine8f073122018-11-27 15:58:47 +01001895}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001896
Dave Rodgman5fce4f62023-01-20 13:18:05 +00001897component_build_no_pk_rsa_alt_support () {
1898 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
1899
1900 scripts/config.py full
1901 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
1902 scripts/config.py set MBEDTLS_RSA_C
1903 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
1904
1905 # Only compile - this is primarily to test for compile issues
Dave Rodgman374b1882024-01-04 10:30:57 +00001906 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
Dave Rodgman5fce4f62023-01-20 13:18:05 +00001907}
1908
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001909component_test_no_use_psa_crypto_full_cmake_asan() {
1910 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02001911 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001912 scripts/config.py full
1913 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
1914 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1915 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1916 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02001917 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001918 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01001919 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001920 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001921
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001922 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001923 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001924
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001925 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001926 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001927
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001928 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001929 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04001930
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001931 msg "test: compat.sh RC4, 3DES & NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
1932 tests/compat.sh -e '^$' -f 'NULL\|3DES\|DES-CBC3\|RC4\|ARCFOUR'
1933
1934 msg "test: compat.sh single-DES (full minus MBEDTLS_USE_PSA_CRYPTO)"
1935 env OPENSSL="$OPENSSL_LEGACY" tests/compat.sh -e '3DES\|DES-CBC3' -f 'DES'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001936
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001937 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +01001938 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001939}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001940
Ronald Crond2c53e62021-09-13 09:38:05 +02001941component_test_psa_crypto_config_accel_ecdsa () {
1942 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1943
1944 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1945 # partial support for cipher operations in the driver test library.
1946 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1947 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Gilles Peskine62de7672022-04-21 11:05:16 +02001948 # Disable obsolete hashes (alternatively we could enable support for them
1949 # in the driver test library).
1950 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1951 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
Ronald Crond2c53e62021-09-13 09:38:05 +02001952
1953 # SHA384 needed for some ECDSA signature tests.
1954 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
1955
1956 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
1957 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1958 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1959
1960 # Restore test driver base configuration
1961 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
1962
1963 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1964 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1965 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1966 scripts/config.py unset MBEDTLS_ECDSA_C
1967 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1968 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1969
1970 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
1971 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"
1972
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01001973 not grep mbedtls_ecdsa_ library/ecdsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02001974
1975 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1976 make test
1977}
1978
1979component_test_psa_crypto_config_accel_rsa_signature () {
1980 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
1981
1982 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1983 # partial support for cipher operations in the driver test library.
1984 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1985 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1986
1987 # It seems it is not possible to remove only the support for RSA signature
1988 # in the library. Thus we have to remove all RSA support (signature and
1989 # encryption/decryption). AS there is no driver support for asymmetric
1990 # encryption/decryption so far remove RSA encryption/decryption from the
1991 # application algorithm list.
1992 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
1993 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
1994
1995 # Make sure both the library and the test library support the SHA hash
1996 # algorithms and only those ones (SHA256 is included by default). That way:
1997 # - the test library can compute the RSA signatures even in the case of a
1998 # composite RSA signature algorithm based on a SHA hash (no other hash
1999 # used in the unit tests).
2000 # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
2001 # fulfilled as the hash SHA algorithm is supported by the library, and
2002 # thus the tests are run, not skipped.
2003 # - when testing a signature key with an algorithm wildcard built from
2004 # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
2005 # algorithm based on the hashes supported by the library is also
2006 # supported by the test library.
2007 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2008 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2009 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2010 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160_C
2011
2012 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA1_C
2013 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
2014 # We need PEM parsing in the test library as well to support the import
2015 # of PEM encoded RSA keys.
2016 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_PEM_PARSE_C
2017 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_BASE64_C
2018
2019 loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
2020 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2021 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2022
2023 # Restore test driver base configuration
2024 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA1_C
2025 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
2026 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_PEM_PARSE_C
2027 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_BASE64_C
2028
2029
2030 # Mbed TLS library build
2031 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2032 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2033
2034 # Remove RSA support and its dependencies
2035 scripts/config.py unset MBEDTLS_PKCS1_V15
2036 scripts/config.py unset MBEDTLS_PKCS1_V21
2037 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2038 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2039 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2040 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2041 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2042 scripts/config.py unset MBEDTLS_RSA_C
2043 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2044
2045 scripts/config.py unset MBEDTLS_MD2_C
2046 scripts/config.py unset MBEDTLS_MD4_C
2047 scripts/config.py unset MBEDTLS_MD5_C
2048 scripts/config.py unset MBEDTLS_RIPEMD160_C
2049 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
2050 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
2051 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
2052
2053 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2054 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2055
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002056 not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
2057 not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02002058
2059 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
2060 make test
2061}
2062
Ronald Cronf7e483c2021-05-08 14:32:59 +02002063component_test_psa_crypto_config_accel_hash () {
2064 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2065
2066 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
2067 # partial support for cipher operations in the driver test library.
2068 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2069 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
2070
2071 loc_accel_list="ALG_MD4 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
2072 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2073 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2074
2075 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2076 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2077 scripts/config.py unset MBEDTLS_MD2_C
2078 scripts/config.py unset MBEDTLS_MD4_C
2079 scripts/config.py unset MBEDTLS_MD5_C
2080 scripts/config.py unset MBEDTLS_RIPEMD160_C
2081 scripts/config.py unset MBEDTLS_SHA1_C
2082 # Don't unset MBEDTLS_SHA256_C as it is needed by PSA crypto core.
2083 scripts/config.py unset MBEDTLS_SHA512_C
2084 # Unset MBEDTLS_SSL_PROTO_SSL3, MBEDTLS_SSL_PROTO_TLS1 and MBEDTLS_SSL_PROTO_TLS1_1 as they depend on MBEDTLS_SHA1_C
2085 scripts/config.py unset MBEDTLS_SSL_PROTO_SSL3
2086 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
2087 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
2088 # Unset MBEDTLS_SSL_CBC_RECORD_SPLITTING as it depends on MBEDTLS_SSL_PROTO_TLS1 in the default configuration.
2089 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
2090 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2091 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2092
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002093 not grep mbedtls_sha512_init library/sha512.o
2094 not grep mbedtls_sha1_init library/sha1.o
Ronald Cronf7e483c2021-05-08 14:32:59 +02002095
2096 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2097 make test
2098}
2099
Ronald Cron09623702021-10-18 11:26:01 +02002100component_test_psa_crypto_config_accel_cipher () {
2101 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
2102
Gilles Peskine186331872022-04-12 15:58:03 +02002103 # This test case focuses on cipher+AEAD. We don't yet support all
2104 # combinations of configurations, so deactivate block-cipher-based MACs.
2105 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CMAC
2106
Ronald Cron09623702021-10-18 11:26:01 +02002107 loc_accel_list="ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB ALG_OFB ALG_XTS KEY_TYPE_DES"
2108 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2109 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2110
2111 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2112 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2113
2114 # There is no intended accelerator support for ALG STREAM_CIPHER and
2115 # ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
2116 # inclusion of the Mbed TLS cipher operations. As we want to test here with
2117 # cipher operations solely supported by accelerators, disabled those
2118 # PSA configuration options.
2119 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2120 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Ronald Cron09623702021-10-18 11:26:01 +02002121
2122 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2123 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2124 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2125 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2126 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2127 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2128 scripts/config.py unset MBEDTLS_DES_C
2129
2130 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2131 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2132
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002133 not grep mbedtls_des* library/des.o
Ronald Cron09623702021-10-18 11:26:01 +02002134
2135 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2136 make test
2137}
2138
Przemek Stekiel8b56f232022-10-02 20:58:39 +02002139component_test_psa_crypto_config_accel_aead () {
2140 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2141
2142 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
2143 # partial support for cipher operations in the driver test library.
2144 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2145 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
2146
2147 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2148 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2149 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2150
2151 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2152 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2153
2154 scripts/config.py unset MBEDTLS_GCM_C
2155 scripts/config.py unset MBEDTLS_CCM_C
2156 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2157 # Features that depend on AEAD
2158 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
2159 scripts/config.py unset MBEDTLS_SSL_TICKET_C
2160
2161 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2162 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"
2163
2164 # There's a risk of something getting re-enabled via config_psa.h
2165 # make sure it did not happen.
2166 not grep mbedtls_ccm library/ccm.o
2167 not grep mbedtls_gcm library/gcm.o
2168 not grep mbedtls_chachapoly library/chachapoly.o
2169
2170 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2171 make test
2172}
2173
John Durkop4377bf72020-10-23 01:26:57 -07002174component_test_psa_crypto_config_no_driver() {
John Durkop4377bf72020-10-23 01:26:57 -07002175 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
2176 scripts/config.py full
2177 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2178 scripts/config.py unset MBEDTLS_PSA_CRYPTO_DRIVERS
2179 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkope7012c72020-10-26 09:55:01 -07002180 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop4377bf72020-10-23 01:26:57 -07002181
2182 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
John Durkopd8959392020-09-20 23:09:17 -07002183 make test
2184}
2185
Gilles Peskined4c85af2023-07-20 22:19:45 +02002186component_test_aead_chachapoly_disabled() {
2187 msg "build: full minus CHACHAPOLY"
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002188 scripts/config.py full
2189 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Gilles Peskined4c85af2023-07-20 22:19:45 +02002190 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002191 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
2192
Gilles Peskined4c85af2023-07-20 22:19:45 +02002193 msg "test: full minus CHACHAPOLY"
2194 make test
2195}
2196
2197component_test_aead_only_ccm() {
2198 msg "build: full minus CHACHAPOLY and GCM"
2199 scripts/config.py full
2200 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2201 scripts/config.py unset MBEDTLS_GCM_C
2202 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2203 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2204 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
2205
2206 msg "test: full minus CHACHAPOLY and GCM"
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002207 make test
2208}
2209
John Durkopd0321952020-10-29 21:37:36 -07002210# 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 -08002211component_build_psa_accel_alg_ecdh() {
Gilles Peskine168be012023-07-19 19:36:55 +02002212 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
John Durkopd0321952020-10-29 21:37:36 -07002213 scripts/config.py full
2214 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2215 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2216 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2217 scripts/config.py unset MBEDTLS_ECDH_C
2218 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2219 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2220 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2221 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2222 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2223 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2224 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2225}
2226
John Durkopf4c4cb02020-10-28 20:09:55 -07002227# 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 -08002228component_build_psa_accel_key_type_ecc_key_pair() {
Gilles Peskine168be012023-07-19 19:36:55 +02002229 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR"
John Durkopf4c4cb02020-10-28 20:09:55 -07002230 scripts/config.py full
2231 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2232 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2233 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002234 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 -08002235 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 -07002236 # 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 -08002237 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 -07002238}
2239
2240# 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 -08002241component_build_psa_accel_key_type_ecc_public_key() {
Gilles Peskine168be012023-07-19 19:36:55 +02002242 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
John Durkopf4c4cb02020-10-28 20:09:55 -07002243 scripts/config.py full
2244 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2245 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2246 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002247 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
2248 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
John Durkopf4c4cb02020-10-28 20:09:55 -07002249 # 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 -08002250 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 -07002251}
2252
John Durkopd0321952020-10-29 21:37:36 -07002253# 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 -08002254component_build_psa_accel_alg_hmac() {
Gilles Peskine168be012023-07-19 19:36:55 +02002255 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
John Durkopd0321952020-10-29 21:37:36 -07002256 scripts/config.py full
2257 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2258 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2259 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2260 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2261 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2262}
2263
2264# 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 -08002265component_build_psa_accel_alg_hkdf() {
Gilles Peskine168be012023-07-19 19:36:55 +02002266 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
John Durkopd0321952020-10-29 21:37:36 -07002267 scripts/config.py full
2268 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2269 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2270 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2271 scripts/config.py unset MBEDTLS_HKDF_C
John Durkopbd069d32020-10-31 22:14:03 -07002272 # Make sure to unset TLS1_3_EXPERIMENTAL since it requires HKDF_C and will not build properly without it.
2273 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
John Durkopd0321952020-10-29 21:37:36 -07002274 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2275 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2276}
2277
John Durkop1b7ee052020-11-27 08:51:22 -08002278# This should be renamed to test and updated once the accelerator MD2 code is in place and ready to test.
2279component_build_psa_accel_alg_md2() {
Gilles Peskine168be012023-07-19 19:36:55 +02002280 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD2 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002281 scripts/config.py full
2282 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2283 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2284 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2285 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2286 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2287 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2288 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2289 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2290 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2291 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2292 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2293 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2294 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD2 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2295}
2296
2297# This should be renamed to test and updated once the accelerator MD4 code is in place and ready to test.
2298component_build_psa_accel_alg_md4() {
Gilles Peskine168be012023-07-19 19:36:55 +02002299 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD4 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002300 scripts/config.py full
2301 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2302 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2303 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2304 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2305 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2306 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2307 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2308 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2309 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2310 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2311 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2312 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2313 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD4 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2314}
2315
2316# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
2317component_build_psa_accel_alg_md5() {
Gilles Peskine168be012023-07-19 19:36:55 +02002318 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002319 scripts/config.py full
2320 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2321 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2322 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2323 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2324 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2325 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2326 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2327 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2328 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2329 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2330 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2331 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2332 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2333}
2334
2335# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
2336component_build_psa_accel_alg_ripemd160() {
Gilles Peskine168be012023-07-19 19:36:55 +02002337 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002338 scripts/config.py full
2339 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2340 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2341 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2342 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2343 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2344 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
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 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2349 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2350 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2351 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2352}
2353
2354# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
2355component_build_psa_accel_alg_sha1() {
Gilles Peskine168be012023-07-19 19:36:55 +02002356 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002357 scripts/config.py full
2358 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2359 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2360 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2361 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2362 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2363 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2364 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
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 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2369 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2370 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2371}
2372
2373# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
2374component_build_psa_accel_alg_sha224() {
Gilles Peskine168be012023-07-19 19:36:55 +02002375 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002376 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
2380 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2381 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2382 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2383 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2384 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2385 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2386 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2387 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2388 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2389}
2390
2391# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
2392component_build_psa_accel_alg_sha256() {
Gilles Peskine168be012023-07-19 19:36:55 +02002393 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002394 scripts/config.py full
2395 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2396 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2397 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2398 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2399 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2400 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2401 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2402 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2403 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2404 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2405 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2406 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2407 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2408}
2409
2410# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
2411component_build_psa_accel_alg_sha384() {
Gilles Peskine168be012023-07-19 19:36:55 +02002412 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002413 scripts/config.py full
2414 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2415 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2416 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2417 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2418 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2419 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2420 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2421 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2422 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2423 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2424 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2425 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2426}
2427
2428# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
2429component_build_psa_accel_alg_sha512() {
Gilles Peskine168be012023-07-19 19:36:55 +02002430 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002431 scripts/config.py full
2432 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2433 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2434 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2435 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2436 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2437 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2438 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2439 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2440 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2441 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2442 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2443 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2444 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2445}
2446
John Durkopd0321952020-10-29 21:37:36 -07002447# 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 -08002448component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
Gilles Peskine168be012023-07-19 19:36:55 +02002449 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
John Durkopd0321952020-10-29 21:37:36 -07002450 scripts/config.py full
2451 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2452 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2453 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkopbd069d32020-10-31 22:14:03 -07002454 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002455 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2456 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2457 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07002458 # 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 -07002459 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2460}
2461
2462# 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 -08002463component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
Gilles Peskine168be012023-07-19 19:36:55 +02002464 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
John Durkopbd069d32020-10-31 22:14:03 -07002465 scripts/config.py full
2466 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2467 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2468 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2469 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002470 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2471 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2472 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002473 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2474 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2475}
2476
2477# 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 -08002478component_build_psa_accel_alg_rsa_oaep() {
Gilles Peskine168be012023-07-19 19:36:55 +02002479 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
John Durkopbd069d32020-10-31 22:14:03 -07002480 scripts/config.py full
2481 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2482 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2483 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2484 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_OAEP 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002485 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2486 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2487 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002488 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2489 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2490}
2491
2492# 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 -08002493component_build_psa_accel_alg_rsa_pss() {
Gilles Peskine168be012023-07-19 19:36:55 +02002494 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
John Durkopbd069d32020-10-31 22:14:03 -07002495 scripts/config.py full
2496 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2497 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2498 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2499 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002500 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2501 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2502 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07002503 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2504 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2505}
2506
2507# 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 -08002508component_build_psa_accel_key_type_rsa_key_pair() {
Gilles Peskine168be012023-07-19 19:36:55 +02002509 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR + PSA_WANT_ALG_RSA_PSS"
John Durkopbd069d32020-10-31 22:14:03 -07002510 scripts/config.py full
2511 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2512 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2513 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2514 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2515 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
2516 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2517 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"
2518}
2519
2520# 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 -08002521component_build_psa_accel_key_type_rsa_public_key() {
Gilles Peskine168be012023-07-19 19:36:55 +02002522 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
John Durkopbd069d32020-10-31 22:14:03 -07002523 scripts/config.py full
2524 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2525 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2526 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2527 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2528 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
2529 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2530 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 -07002531}
2532
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002533component_test_check_params_functionality () {
2534 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002535 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002536 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002537 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Ronald Crona1236142020-07-01 16:01:21 +02002538 make CC=gcc CFLAGS='-Werror -O1' all test
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002539}
2540
Gilles Peskineb28636b2019-01-02 19:06:24 +01002541component_test_check_params_without_platform () {
2542 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002543 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002544 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002545 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
2546 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
2547 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
2548 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
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_PLATFORM_PRINTF_ALT
2551 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskine9c764bf2022-09-18 14:05:23 +02002552 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002553 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
2554 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +01002555 make CC=gcc CFLAGS='-Werror -O1' all test
2556}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002557
Gilles Peskineb28636b2019-01-02 19:06:24 +01002558component_test_check_params_silent () {
2559 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002560 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002561 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01002562 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
2563 make CC=gcc CFLAGS='-Werror -O1' all test
2564}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002565
Dave Rodgman173227d2023-06-29 09:29:00 +01002566component_build_aes_variations() { # ~45s
2567 msg "build: aes.o for all combinations of relevant config options"
Dave Rodgmanbf998282023-06-29 12:10:45 +01002568
Dave Rodgman173227d2023-06-29 09:29:00 +01002569 for a in set unset; do
2570 for b in set unset; do
2571 for c in set unset; do
2572 for d in set unset; do
2573 for e in set unset; do
2574 for f in set unset; do
2575 for g in set unset; do
Dave Rodgmanbf998282023-06-29 12:10:45 +01002576 echo ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
2577 echo ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
2578 echo ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
2579 echo ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
2580 echo ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
2581 echo ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
2582 echo ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman173227d2023-06-29 09:29:00 +01002583
Dave Rodgmanbf998282023-06-29 12:10:45 +01002584 ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
2585 ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
2586 ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
2587 ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
2588 ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
2589 ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
2590 ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman173227d2023-06-29 09:29:00 +01002591
Dave Rodgmanbf998282023-06-29 12:10:45 +01002592 rm -f library/aes.o
2593 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 +01002594 done
2595 done
2596 done
2597 done
2598 done
2599 done
2600 done
2601}
2602
Gilles Peskine8f073122018-11-27 15:58:47 +01002603component_test_no_platform () {
2604 # Full configuration build, without platform support, file IO and net sockets.
2605 # This should catch missing mbedtls_printf definitions, and by disabling file
2606 # IO, it should catch missing '#include <stdio.h>'
2607 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Paul Elliott68050372023-11-03 19:24:56 +00002608 scripts/config.py full_no_platform
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002609 scripts/config.py unset MBEDTLS_PLATFORM_C
2610 scripts/config.py unset MBEDTLS_NET_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002611 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002612 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002613 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
2614 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Paul Elliott68050372023-11-03 19:24:56 +00002615 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +01002616 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
2617 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002618 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
2619 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01002620}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00002621
Gilles Peskine8f073122018-11-27 15:58:47 +01002622component_build_no_std_function () {
2623 # catch compile bugs in _uninit functions
2624 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002625 scripts/config.py full
2626 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
2627 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002628 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine31fdda12021-10-08 11:45:47 +02002629 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskine25319702021-10-07 19:34:57 +02002630 make
Gilles Peskine8f073122018-11-27 15:58:47 +01002631}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01002632
Gilles Peskine8f073122018-11-27 15:58:47 +01002633component_build_no_ssl_srv () {
2634 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002635 scripts/config.py full
2636 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002637 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002638}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002639
Gilles Peskine8f073122018-11-27 15:58:47 +01002640component_build_no_ssl_cli () {
2641 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002642 scripts/config.py full
2643 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002644 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002645}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002646
Gilles Peskine8f073122018-11-27 15:58:47 +01002647component_build_no_sockets () {
2648 # Note, C99 compliance can also be tested with the sockets support disabled,
2649 # as that requires a POSIX platform (which isn't the same as C99).
2650 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002651 scripts/config.py full
2652 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
2653 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002654 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01002655}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02002656
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002657component_test_memory_buffer_allocator_backtrace () {
2658 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002659 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2660 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2661 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
2662 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Dave Rodgman374b1882024-01-04 10:30:57 +00002663 cmake -DCMAKE_BUILD_TYPE:String=Release .
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002664 make
2665
2666 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
2667 make test
2668}
2669
2670component_test_memory_buffer_allocator () {
2671 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002672 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2673 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Dave Rodgman374b1882024-01-04 10:30:57 +00002674 cmake -DCMAKE_BUILD_TYPE:String=Release .
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002675 make
2676
2677 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2678 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002679
2680 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2681 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002682 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002683}
2684
Gilles Peskine8f073122018-11-27 15:58:47 +01002685component_test_no_max_fragment_length () {
2686 # Run max fragment length tests with MFL disabled
2687 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002688 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01002689 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2690 make
Hanno Becker5175ac62017-09-18 15:36:25 +01002691
Gilles Peskine8f073122018-11-27 15:58:47 +01002692 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002693 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01002694}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002695
Hanno Becker545ced42019-02-19 11:10:48 +00002696component_test_asan_remove_peer_certificate () {
2697 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002698 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00002699 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2700 make
2701
2702 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2703 make test
2704
2705 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002706 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002707
2708 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002709 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002710
2711 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002712 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002713}
2714
Gilles Peskine8f073122018-11-27 15:58:47 +01002715component_test_no_max_fragment_length_small_ssl_out_content_len () {
2716 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002717 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2718 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
2719 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01002720 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2721 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10002722
Gilles Peskine8f073122018-11-27 15:58:47 +01002723 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002724 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002725
2726 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002727 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002728}
Angus Grattonc4dd0732018-04-11 16:28:39 +10002729
Darryl Greenaad82f92019-12-02 10:53:11 +00002730component_test_variable_ssl_in_out_buffer_len () {
2731 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
2732 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2733 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2734 make
2735
2736 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2737 make test
2738
2739 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002740 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002741
2742 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002743 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002744}
2745
2746component_test_variable_ssl_in_out_buffer_len_CID () {
2747 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
2748 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2749 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
2750
2751 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2752 make
2753
2754 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
2755 make test
2756
2757 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002758 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002759
2760 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002761 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002762}
2763
2764component_test_variable_ssl_in_out_buffer_len_record_splitting () {
2765 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled (ASan build)"
2766 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2767 scripts/config.py set MBEDTLS_SSL_CBC_RECORD_SPLITTING
2768
2769 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2770 make
2771
2772 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING"
2773 make test
2774
2775 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002776 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002777
2778 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002779 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002780}
2781
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002782component_test_ssl_alloc_buffer_and_mfl () {
2783 msg "build: default config with memory buffer allocator and MFL extension"
2784 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2785 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2786 scripts/config.py set MBEDTLS_MEMORY_DEBUG
2787 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2788 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
Dave Rodgman374b1882024-01-04 10:30:57 +00002789 cmake -DCMAKE_BUILD_TYPE:String=Release .
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002790 make
2791
2792 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
2793 make test
2794
2795 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 +02002796 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002797}
2798
Gilles Peskine636c26a2020-03-04 20:46:15 +01002799component_test_when_no_ciphersuites_have_mac () {
2800 msg "build: when no ciphersuites have MAC"
2801 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
2802 scripts/config.py unset MBEDTLS_ARC4_C
2803 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2804 make
2805
2806 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
2807 make test
2808
2809 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002810 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01002811}
2812
Gilles Peskine8f073122018-11-27 15:58:47 +01002813component_test_null_entropy () {
2814 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002815 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
2816 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
2817 scripts/config.py set MBEDTLS_ENTROPY_C
2818 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002819 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002820 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
2821 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00002822 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01002823 make
Janos Follath06c54002016-06-09 13:57:40 +01002824
Gilles Peskine8f073122018-11-27 15:58:47 +01002825 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
2826 make test
2827}
Janos Follath06c54002016-06-09 13:57:40 +01002828
Raoul Strackxa4e86142020-06-15 17:03:13 +02002829component_test_no_date_time () {
2830 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
2831 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
Gilles Peskine31fdda12021-10-08 11:45:47 +02002832 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Raoul Strackxa4e86142020-06-15 17:03:13 +02002833 make
2834
2835 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
2836 make test
2837}
2838
Andrzej Kurekc890b222023-01-17 04:03:19 -05002839component_test_alt_timing() {
2840 msg "build: alternate timing implementation"
2841 scripts/config.py set MBEDTLS_TIMING_ALT
2842 make lib TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
2843
2844 msg "test: MBEDTLS_TIMING_ALT - test suites"
2845 make test TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
Andrzej Kurek3a261a42023-01-26 04:33:59 -05002846
2847 msg "selftest - MBEDTLS-TIMING_ALT"
2848 make programs TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../../tests/src/external_timing -I../tests/src/external_timing"
2849 programs/test/selftest
Andrzej Kurekc890b222023-01-17 04:03:19 -05002850}
2851
Gilles Peskine8f073122018-11-27 15:58:47 +01002852component_test_platform_calloc_macro () {
2853 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002854 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2855 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
2856 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01002857 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2858 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01002859
Gilles Peskine8f073122018-11-27 15:58:47 +01002860 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
2861 make test
2862}
Hanno Beckere5fecec2018-10-11 11:02:52 +01002863
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002864component_test_malloc_0_null () {
2865 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002866 scripts/config.py full
Gilles Peskine2e70f1c2023-07-20 19:00:15 +02002867 make CC=gcc CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"$PWD/tests/configs/user-config-malloc-0-null.h\"' $ASAN_CFLAGS -O" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002868
2869 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
2870 make test
2871
2872 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
2873 # Just the calloc selftest. "make test" ran the others as part of the
2874 # test suites.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002875 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01002876
2877 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
2878 # Run a subset of the tests. The choice is a balance between coverage
2879 # and time (including time indirectly wasted due to flaky tests).
2880 # The current choice is to skip tests whose description includes
2881 # "proxy", which is an approximation of skipping tests that use the
2882 # UDP proxy, which tend to be slower and flakier.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002883 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002884}
2885
Gilles Peskine8f073122018-11-27 15:58:47 +01002886component_test_aes_fewer_tables () {
2887 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002888 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Dave Rodgmance04f242024-01-04 10:34:31 +00002889 make CFLAGS='-O2 -Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002890
Gilles Peskine8f073122018-11-27 15:58:47 +01002891 msg "test: AES_FEWER_TABLES"
2892 make test
2893}
Hanno Becker83ebf782017-07-07 12:29:15 +01002894
Gilles Peskine8f073122018-11-27 15:58:47 +01002895component_test_aes_rom_tables () {
2896 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002897 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Dave Rodgmance04f242024-01-04 10:34:31 +00002898 make CFLAGS='-O2 -Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002899
Gilles Peskine8f073122018-11-27 15:58:47 +01002900 msg "test: AES_ROM_TABLES"
2901 make test
2902}
Hanno Becker83ebf782017-07-07 12:29:15 +01002903
Gilles Peskine8f073122018-11-27 15:58:47 +01002904component_test_aes_fewer_tables_and_rom_tables () {
2905 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002906 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2907 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Dave Rodgmance04f242024-01-04 10:34:31 +00002908 make CFLAGS='-O2 -Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002909
Gilles Peskine8f073122018-11-27 15:58:47 +01002910 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2911 make test
2912}
2913
Gilles Peskine592f5912019-10-07 18:49:32 +02002914component_test_ctr_drbg_aes_256_sha_256 () {
2915 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002916 scripts/config.py full
2917 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2918 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002919 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2920 make
2921
2922 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2923 make test
2924}
2925
2926component_test_ctr_drbg_aes_128_sha_512 () {
2927 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002928 scripts/config.py full
2929 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2930 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02002931 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2932 make
2933
2934 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2935 make test
2936}
2937
2938component_test_ctr_drbg_aes_128_sha_256 () {
2939 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002940 scripts/config.py full
2941 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2942 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2943 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002944 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2945 make
2946
2947 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2948 make test
2949}
2950
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002951component_test_se_default () {
2952 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002953 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02002954 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002955
2956 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2957 make test
2958}
2959
Steven Cooremand57203d2020-07-16 20:28:59 +02002960component_test_psa_crypto_drivers () {
Gilles Peskine8d77ec22023-07-26 18:45:20 +02002961 msg "build: full + test drivers dispatching to builtins"
Steven Cooreman753f9732021-03-15 11:38:44 +01002962 scripts/config.py full
Steven Cooremand57203d2020-07-16 20:28:59 +02002963 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
Gilles Peskinefe0acc62021-09-20 19:20:04 +02002964 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
2965 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002966 loc_cflags="${loc_cflags} -I../tests/include -O2"
2967
2968 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002969
Gilles Peskine8d77ec22023-07-26 18:45:20 +02002970 msg "test: full + test drivers dispatching to builtins"
Steven Cooremand57203d2020-07-16 20:28:59 +02002971 make test
2972}
2973
Gilles Peskine8f073122018-11-27 15:58:47 +01002974component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002975 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002976 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02002977 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine27482f12021-11-04 12:52:14 +01002978 programs/test/dlopen_demo.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002979}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02002980
Gilles Peskinecf740502019-07-03 20:43:05 +02002981component_test_cmake_shared () {
2982 msg "build/test: cmake shared" # ~ 2min
2983 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
2984 make
Gilles Peskine56c01612019-07-03 20:43:32 +02002985 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02002986 make test
Gilles Peskine27482f12021-11-04 12:52:14 +01002987 programs/test/dlopen_demo.sh
Gilles Peskinecf740502019-07-03 20:43:05 +02002988}
2989
Gilles Peskineec10bf12019-09-20 19:56:06 +02002990test_build_opt () {
2991 info=$1 cc=$2; shift 2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01002992 $cc --version
Gilles Peskineec10bf12019-09-20 19:56:06 +02002993 for opt in "$@"; do
2994 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskinee094a182020-04-14 20:08:41 +02002995 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02002996 # We're confident enough in compilers to not run _all_ the tests,
2997 # but at least run the unit tests. In particular, runs with
2998 # optimizations use inline assembly whereas runs with -O0
2999 # skip inline assembly.
3000 make test # ~30s
3001 make clean
3002 done
3003}
3004
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003005# For FreeBSD we invoke the function by name so this condition is added
3006# to disable the existing test_clang_opt function for linux.
3007if [[ $(uname) != "Linux" ]]; then
3008 component_test_clang_opt () {
3009 scripts/config.py full
3010 test_build_opt 'full config' clang -O0 -Os -O2
3011 }
3012fi
3013
3014component_test_clang_latest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01003015 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003016 test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003017}
3018support_test_clang_latest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003019 type "$CLANG_LATEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02003020}
3021
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003022component_test_clang_earliest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01003023 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003024 test_build_opt 'full config' "$CLANG_EARLIEST" -O0
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003025}
3026support_test_clang_earliest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003027 type "$CLANG_EARLIEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003028}
3029
3030component_test_gcc_latest_opt () {
3031 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003032 test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003033}
3034support_test_gcc_latest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003035 type "$GCC_LATEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003036}
3037
3038component_test_gcc_earliest_opt () {
3039 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003040 test_build_opt 'full config' "$GCC_EARLIEST" -O0
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003041}
3042support_test_gcc_earliest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003043 type "$GCC_EARLIEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02003044}
3045
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02003046component_build_mbedtls_config_file () {
3047 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
Gilles Peskine6af9dc92022-04-07 20:55:57 +02003048 scripts/config.py -w full_config.h full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02003049 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
3050 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02003051 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine036a9bb2022-04-07 21:06:41 +02003052 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3053 make clean
3054
3055 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
3056 # In the user config, disable one feature (for simplicity, pick a feature
3057 # that nothing else depends on).
3058 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3059 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
3060 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3061
3062 rm -f user_config.h full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003063}
3064
Gilles Peskine690a2ef2022-04-07 21:59:14 +02003065component_build_psa_config_file () {
3066 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
3067 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3068 cp "$CRYPTO_CONFIG_H" psa_test_config.h
3069 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
3070 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02003071 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine690a2ef2022-04-07 21:59:14 +02003072 programs/test/query_compile_time_config MBEDTLS_CMAC_C
3073 make clean
3074
3075 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
3076 # In the user config, disable one feature, which will reflect on the
3077 # mbedtls configuration so we can query it with query_compile_time_config.
3078 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
3079 scripts/config.py unset MBEDTLS_CMAC_C
3080 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
3081 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
3082
3083 rm -f psa_test_config.h psa_user_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003084}
3085
Gilles Peskine8f073122018-11-27 15:58:47 +01003086component_test_m32_o0 () {
Gilles Peskinea0c51fb2021-10-07 19:27:16 +02003087 # Build without optimization, so as to use portable C code (in a 32-bit
3088 # build) and not the i386-specific inline assembly.
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003089 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003090 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02003091 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01003092
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003093 msg "test: i386, make, gcc -O0 (ASan build)"
3094 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01003095}
Gilles Peskine878cf602019-01-06 20:50:38 +00003096support_test_m32_o0 () {
3097 case $(uname -m) in
Pengyu Lva89b3672022-10-21 10:50:26 +00003098 amd64|x86_64) true;;
Gilles Peskine878cf602019-01-06 20:50:38 +00003099 *) false;;
3100 esac
3101}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003102
Gilles Peskine6fa69862021-10-05 09:36:03 +02003103component_test_m32_o2 () {
3104 # Build with optimization, to use the i386 specific inline assembly
3105 # and go faster for tests.
3106 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003107 scripts/config.py full
Gilles Peskine6fa69862021-10-05 09:36:03 +02003108 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003109
Gilles Peskine6fa69862021-10-05 09:36:03 +02003110 msg "test: i386, make, gcc -O2 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003111 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003112
Gilles Peskine6fa69862021-10-05 09:36:03 +02003113 msg "test ssl-opt.sh, i386, make, gcc-O2"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003114 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003115}
Gilles Peskine3daa83e2021-10-07 19:25:29 +02003116support_test_m32_o2 () {
Gilles Peskine878cf602019-01-06 20:50:38 +00003117 support_test_m32_o0 "$@"
3118}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003119
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003120component_test_m32_everest () {
3121 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003122 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
3123 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02003124 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003125
3126 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
3127 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003128
3129 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003130 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01003131
3132 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
3133 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003134 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003135}
3136support_test_m32_everest () {
3137 support_test_m32_o0 "$@"
3138}
3139
Gilles Peskine8f073122018-11-27 15:58:47 +01003140component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003141 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003142 scripts/config.py full
Dave Rodgmance04f242024-01-04 10:34:31 +00003143 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003144
3145 msg "test: 64-bit ILP32, make, gcc"
3146 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01003147}
Gilles Peskine878cf602019-01-06 20:50:38 +00003148support_test_mx32 () {
3149 case $(uname -m) in
3150 amd64|x86_64) true;;
3151 *) false;;
3152 esac
3153}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003154
Peter Kolbus60c6da22018-12-27 06:59:04 -06003155component_test_min_mpi_window_size () {
3156 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003157 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06003158 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3159 make
3160
3161 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
3162 make test
3163}
3164
Gilles Peskine8f073122018-11-27 15:58:47 +01003165component_test_have_int32 () {
3166 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003167 scripts/config.py unset MBEDTLS_HAVE_ASM
3168 scripts/config.py unset MBEDTLS_AESNI_C
3169 scripts/config.py unset MBEDTLS_PADLOCK_C
Dave Rodgmance04f242024-01-04 10:34:31 +00003170 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01003171
Gilles Peskine8f073122018-11-27 15:58:47 +01003172 msg "test: gcc, force 32-bit bignum limbs"
3173 make test
3174}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01003175
Gilles Peskine8f073122018-11-27 15:58:47 +01003176component_test_have_int64 () {
3177 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003178 scripts/config.py unset MBEDTLS_HAVE_ASM
3179 scripts/config.py unset MBEDTLS_AESNI_C
3180 scripts/config.py unset MBEDTLS_PADLOCK_C
Dave Rodgmance04f242024-01-04 10:34:31 +00003181 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01003182
Gilles Peskine8f073122018-11-27 15:58:47 +01003183 msg "test: gcc, force 64-bit bignum limbs"
3184 make test
3185}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003186
Gilles Peskine8f073122018-11-27 15:58:47 +01003187component_test_no_udbl_division () {
3188 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003189 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003190 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01003191 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003192
Gilles Peskine8f073122018-11-27 15:58:47 +01003193 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
3194 make test
3195}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003196
Gilles Peskine8f073122018-11-27 15:58:47 +01003197component_test_no_64bit_multiplication () {
3198 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003199 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003200 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01003201 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003202
Gilles Peskine8f073122018-11-27 15:58:47 +01003203 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
3204 make test
3205}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003206
Gilles Peskine3809f5f2020-11-09 15:40:05 +01003207component_test_no_strings () {
3208 msg "build: no strings" # ~10s
3209 scripts/config.py full
3210 # Disable options that activate a large amount of string constants.
3211 scripts/config.py unset MBEDTLS_DEBUG_C
3212 scripts/config.py unset MBEDTLS_ERROR_C
3213 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
3214 scripts/config.py unset MBEDTLS_VERSION_FEATURES
3215 make CFLAGS='-Werror -Os'
3216
3217 msg "test: no strings" # ~ 10s
3218 make test
3219}
3220
Gilles Peskine8f073122018-11-27 15:58:47 +01003221component_build_arm_none_eabi_gcc () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003222 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003223 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02003224 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 +02003225
Gilles Peskine60d99472021-09-01 20:00:33 +02003226 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003227 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003228}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003229
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003230component_build_arm_linux_gnueabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003231 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003232 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02003233 # Build for a target platform that's close to what Debian uses
3234 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
Dave Rodgman52af7692022-03-31 14:27:24 +01003235 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003236 # Build everything including programs, see for example
Dave Rodgman52af7692022-03-31 14:27:24 +01003237 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003238 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'
3239
Gilles Peskine60d99472021-09-01 20:00:33 +02003240 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003241 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size library/*.o
3242}
3243support_build_arm_linux_gnueabi_gcc_arm5vte () {
3244 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
3245}
3246
3247component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003248 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003249 scripts/config.py baremetal
3250 # This is an imperfect substitute for
3251 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnard9a260a62021-07-06 09:44:59 +02003252 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02003253 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 +02003254
Gilles Peskine60d99472021-09-01 20:00:33 +02003255 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003256 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02003257}
3258
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003259component_build_arm_none_eabi_gcc_m0plus () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003260 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
3261 scripts/config.py baremetal_size
Gilles Peskineaeedd742020-09-02 11:03:04 +02003262 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 +02003263
Gilles Peskine60d99472021-09-01 20:00:33 +02003264 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
Gilles Peskine18487f62020-04-30 23:11:54 +02003265 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003266}
3267
Gilles Peskine8f073122018-11-27 15:58:47 +01003268component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003269 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003270 scripts/config.py baremetal
3271 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003272 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 +01003273 echo "Checking that software 64-bit division is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003274 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003275}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003276
Gilles Peskine8f073122018-11-27 15:58:47 +01003277component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003278 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003279 scripts/config.py baremetal
3280 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003281 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 +01003282 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003283 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003284}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003285
Dave Rodgman43ea9ab2023-06-02 10:26:24 -04003286component_build_arm_clang_thumb () {
3287 # ~ 30s
3288
3289 scripts/config.py baremetal
3290
3291 msg "build: clang thumb 2, make"
3292 make clean
3293 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
3294
3295 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
3296 msg "build: clang thumb 1 -O0, make"
3297 make clean
3298 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
3299
3300 msg "build: clang thumb 1 -Os, make"
3301 make clean
3302 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
3303}
3304
Gilles Peskine8f073122018-11-27 15:58:47 +01003305component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02003306 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003307 scripts/config.py baremetal
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003308 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02003309
3310 msg "size: ARM Compiler 5"
3311 "$ARMC5_FROMELF" -z library/*.o
3312
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003313 make clean
Andres AG87bb5772016-09-27 15:05:15 +01003314
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003315 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
3316
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003317 # ARM Compiler 6 - Target ARMv7-A
3318 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003319
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003320 # ARM Compiler 6 - Target ARMv7-M
3321 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02003322
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003323 # ARM Compiler 6 - Target ARMv8-A - AArch32
3324 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003325
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003326 # ARM Compiler 6 - Target ARMv8-M
3327 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02003328
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003329 # ARM Compiler 6 - Target ARMv8-A - AArch64
3330 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003331
3332 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
3333 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
3334
3335 # ARM Compiler 6 - Target Cortex-M0
3336 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
Gilles Peskine8f073122018-11-27 15:58:47 +01003337}
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003338
Pengyu Lvd216c042023-03-03 18:23:35 +08003339support_build_armcc () {
3340 armc5_cc="$ARMC5_BIN_DIR/armcc"
3341 armc6_cc="$ARMC6_BIN_DIR/armclang"
3342 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
3343}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01003344
Manuel Pégourié-Gonnarddd8807f2020-02-26 09:56:27 +01003345component_build_ssl_hw_record_accel() {
3346 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
3347 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
3348 make CFLAGS='-Werror -O1'
3349}
3350
Hanno Beckera711f6e2020-05-04 12:03:51 +01003351component_test_tls13_experimental () {
3352 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3353 scripts/config.pl set MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
3354 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3355 make
3356 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3357 make test
3358}
3359
Gilles Peskine8f073122018-11-27 15:58:47 +01003360component_build_mingw () {
3361 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003362 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 +00003363
Gilles Peskine8f073122018-11-27 15:58:47 +01003364 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003365 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 +01003366 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02003367
Gilles Peskine8f073122018-11-27 15:58:47 +01003368 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04003369 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
3370 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 +01003371 make WINDOWS_BUILD=1 clean
Pengyu Lvb2ca0322023-10-19 17:17:19 +08003372
3373 msg "build: Windows cross build - mingw64, make (Library only, AESNI intrinsics)" # ~ 30s
3374 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 lib
Pengyu Lve6cbec82023-10-20 09:49:01 +08003375 make WINDOWS_BUILD=1 clean
3376
3377 msg "build: Windows cross build - mingw64, make (Library only, default config without MBEDTLS_AESNI_C)" # ~ 30s
3378 ./scripts/config.py unset MBEDTLS_AESNI_C
3379 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib
3380 make WINDOWS_BUILD=1 clean
Pengyu Lvb2ca0322023-10-19 17:17:19 +08003381 }
Jaeden Amero117b8a42019-04-17 15:19:26 +01003382support_build_mingw() {
Pengyu Lva19ce122023-02-24 15:38:52 +08003383 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
3384 [0-5]*|"") false;;
Jaeden Amero117b8a42019-04-17 15:19:26 +01003385 *) true;;
3386 esac
3387}
Simon Butcher91aef332016-11-17 09:20:50 +00003388
Gilles Peskine8f073122018-11-27 15:58:47 +01003389component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003390 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003391 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003392 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
3393 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02003394
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003395 msg "test: main suites (MSan)" # ~ 10s
3396 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003397
Gilles Peskineee8af062023-11-02 19:58:03 +01003398 msg "test: metatests (MSan)"
3399 tests/scripts/run-metatests.sh any msan
3400
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02003401 msg "program demos (MSan)" # ~20s
3402 tests/scripts/run_demos.py
3403
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003404 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003405 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003406
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003407 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003408
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003409 if [ "$MEMORY" -gt 0 ]; then
3410 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003411 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003412 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003413}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003414
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01003415component_release_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003416 msg "build: Release (clang)"
Gilles Peskine619b73d2022-11-29 16:45:30 +01003417 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003418 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3419 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003420
Gilles Peskine619b73d2022-11-29 16:45:30 +01003421 msg "test: main suites, Valgrind (default config)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003422 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003423
Gilles Peskine636c26a2020-03-04 20:46:15 +01003424 # Optional parts (slow; currently broken on OS X because programs don't
3425 # seem to receive signals under valgrind on OS X).
Gilles Peskine619b73d2022-11-29 16:45:30 +01003426 # These optional parts don't run on the CI.
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003427 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003428 msg "test: ssl-opt.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003429 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003430 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003431
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003432 if [ "$MEMORY" -gt 1 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003433 msg "test: compat.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003434 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003435 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003436
3437 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003438 msg "test: context-info.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003439 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003440 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003441}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003442
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01003443component_release_test_valgrind_psa () {
Gilles Peskine619b73d2022-11-29 16:45:30 +01003444 msg "build: Release, full (clang)"
3445 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
3446 scripts/config.py full
3447 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3448 make
3449
3450 msg "test: main suites, Valgrind (full config)"
3451 make memcheck
3452}
3453
Paul Elliott2ab9a7a2021-11-25 17:29:40 +00003454support_test_cmake_out_of_source () {
3455 distrib_id=""
3456 distrib_ver=""
3457 distrib_ver_minor=""
3458 distrib_ver_major=""
3459
3460 # Attempt to parse lsb-release to find out distribution and version. If not
3461 # found this should fail safe (test is supported).
3462 if [[ -f /etc/lsb-release ]]; then
3463
3464 while read -r lsb_line; do
3465 case "$lsb_line" in
3466 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
3467 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
3468 esac
3469 done < /etc/lsb-release
3470
3471 distrib_ver_major="${distrib_ver%%.*}"
3472 distrib_ver="${distrib_ver#*.}"
3473 distrib_ver_minor="${distrib_ver%%.*}"
3474 fi
3475
3476 # Running the out of source CMake test on Ubuntu 16.04 using more than one
3477 # processor (as the CI does) can create a race condition whereby the build
3478 # fails to see a generated file, despite that file actually having been
3479 # generated. This problem appears to go away with 18.04 or newer, so make
3480 # the out of source tests unsupported on Ubuntu 16.04.
3481 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
3482}
3483
Gilles Peskine8f073122018-11-27 15:58:47 +01003484component_test_cmake_out_of_source () {
3485 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01003486 MBEDTLS_ROOT_DIR="$PWD"
3487 mkdir "$OUT_OF_SOURCE_DIR"
3488 cd "$OUT_OF_SOURCE_DIR"
Gilles Peskine25319702021-10-07 19:34:57 +02003489 cmake -D CMAKE_BUILD_TYPE:String=Check "$MBEDTLS_ROOT_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003490 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003491
Gilles Peskine8f073122018-11-27 15:58:47 +01003492 msg "test: cmake 'out-of-source' build"
3493 make test
3494 # Test an SSL option that requires an auxiliary script in test/scripts/.
3495 # Also ensure that there are no error messages such as
3496 # "No such file or directory", which would indicate that some required
3497 # file is missing (ssl-opt.sh tolerates the absence of some files so
3498 # may exit with status 0 but emit errors).
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003499 ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' >ssl-opt.out 2>ssl-opt.err
3500 grep PASS ssl-opt.out
Gilles Peskine0a7984f2020-03-28 18:56:09 +01003501 cat ssl-opt.err >&2
3502 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003503 [ ! -s ssl-opt.err ]
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003504 rm ssl-opt.out ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01003505 cd "$MBEDTLS_ROOT_DIR"
3506 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003507}
Andres AGdc192212016-08-31 17:33:13 +01003508
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003509component_test_cmake_as_subdirectory () {
3510 msg "build: cmake 'as-subdirectory' build"
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003511 cd programs/test/cmake_subproject
3512 cmake .
3513 make
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003514 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003515}
Gilles Peskineca9cfca2022-02-04 00:21:12 +01003516support_test_cmake_as_subdirectory () {
3517 support_test_cmake_out_of_source
3518}
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003519
David Horstmann175afbd2023-01-12 14:17:01 +00003520component_build_cmake_custom_config_file () {
David Horstmann67622312023-01-31 10:34:44 +00003521 # Make a copy of config file to use for the in-tree test
3522 cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h
David Horstmann175afbd2023-01-12 14:17:01 +00003523
3524 MBEDTLS_ROOT_DIR="$PWD"
3525 mkdir "$OUT_OF_SOURCE_DIR"
3526 cd "$OUT_OF_SOURCE_DIR"
3527
David Horstmann67622312023-01-31 10:34:44 +00003528 # Build once to get the generated files (which need an intact config file)
David Horstmann175afbd2023-01-12 14:17:01 +00003529 cmake "$MBEDTLS_ROOT_DIR"
3530 make
3531
3532 msg "build: cmake with -DMBEDTLS_CONFIG_FILE"
3533 scripts/config.py -w full_config.h full
David Horstmann67622312023-01-31 10:34:44 +00003534 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003535 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR"
3536 make
3537
3538 msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
3539 # In the user config, disable one feature (for simplicity, pick a feature
3540 # that nothing else depends on).
3541 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3542
3543 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR"
3544 make
3545 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3546
3547 rm -f user_config.h full_config.h
3548
3549 cd "$MBEDTLS_ROOT_DIR"
3550 rm -rf "$OUT_OF_SOURCE_DIR"
3551
3552 # Now repeat the test for an in-tree build:
3553
David Horstmann67622312023-01-31 10:34:44 +00003554 # Restore config for the in-tree test
3555 mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003556
David Horstmann67622312023-01-31 10:34:44 +00003557 # Build once to get the generated files (which need an intact config)
David Horstmann175afbd2023-01-12 14:17:01 +00003558 cmake .
3559 make
3560
3561 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE"
3562 scripts/config.py -w full_config.h full
David Horstmann67622312023-01-31 10:34:44 +00003563 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003564 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h .
3565 make
3566
3567 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
3568 # In the user config, disable one feature (for simplicity, pick a feature
3569 # that nothing else depends on).
3570 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3571
3572 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h .
3573 make
3574 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3575
3576 rm -f user_config.h full_config.h
3577}
3578support_build_cmake_custom_config_file () {
3579 support_test_cmake_out_of_source
3580}
3581
3582
Tom Cosgrove51170622023-09-01 10:40:15 +01003583component_build_zeroize_checks () {
3584 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
3585
3586 scripts/config.py full
3587
3588 # Only compile - we're looking for sizeof-pointer-memaccess warnings
Dave Rodgman374b1882024-01-04 10:30:57 +00003589 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess"
Tom Cosgrove51170622023-09-01 10:40:15 +01003590}
3591
3592
Gilles Peskine8f073122018-11-27 15:58:47 +01003593component_test_zeroize () {
3594 # Test that the function mbedtls_platform_zeroize() is not optimized away by
3595 # different combinations of compilers and optimization flags by using an
3596 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
3597 # system in all cases that the script fails, so we must manually search the
3598 # output to check whether the pass string is present and no failure strings
3599 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01003600
Gilles Peskine4976e822019-01-06 19:52:22 +00003601 # Don't try to disable ASLR. We don't care about ASLR here. We do care
3602 # about a spurious message if Gdb tries and fails, so suppress that.
3603 gdb_disable_aslr=
3604 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
3605 gdb_disable_aslr='set disable-randomization off'
3606 fi
3607
Gilles Peskine8f073122018-11-27 15:58:47 +01003608 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01003609 for compiler in clang gcc; do
3610 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
3611 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003612 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
3613 grep "The buffer was correctly zeroized" test_zeroize.log
3614 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01003615 rm -f test_zeroize.log
3616 make clean
3617 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01003618 done
Gilles Peskine8f073122018-11-27 15:58:47 +01003619}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003620
Bence Szépkúti9f849112021-10-19 15:05:36 +02003621component_test_psa_compliance () {
Dave Rodgmanb0660c22023-12-18 19:55:40 +00003622 # The arch tests build with gcc, so require use of gcc here to link properly
Bence Szépkútic1e79fd2021-11-11 20:13:14 +01003623 msg "build: make, default config + CMAC, libmbedcrypto.a only"
3624 scripts/config.py set MBEDTLS_CMAC_C
Dave Rodgmanb0660c22023-12-18 19:55:40 +00003625 CC=gcc make -C library libmbedcrypto.a
Bence Szépkúti9f849112021-10-19 15:05:36 +02003626
3627 msg "unit test: test_psa_compliance.py"
Dave Rodgman5b00fb12023-12-18 22:29:56 +00003628 CC=gcc ./tests/scripts/test_psa_compliance.py
Bence Szépkúti9f849112021-10-19 15:05:36 +02003629}
3630
3631support_test_psa_compliance () {
Bence Szépkútid6cf0892021-11-03 11:36:09 +01003632 # psa-compliance-tests only supports CMake >= 3.10.0
Bence Szépkútiab796e62021-10-25 19:29:07 +02003633 ver="$(cmake --version)"
3634 ver="${ver#cmake version }"
3635 ver_major="${ver%%.*}"
3636
3637 ver="${ver#*.}"
3638 ver_minor="${ver%%.*}"
3639
3640 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
Bence Szépkúti9f849112021-10-19 15:05:36 +02003641}
3642
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003643component_check_code_style () {
3644 msg "Check C code style"
3645 ./scripts/code_style.py
David Horstmanne09c4762022-11-10 18:30:52 +00003646}
3647
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003648support_check_code_style() {
David Horstmanne09c4762022-11-10 18:30:52 +00003649 case $(uncrustify --version) in
3650 *0.75.1*) true;;
3651 *) false;;
3652 esac
3653}
3654
Gilles Peskine8f073122018-11-27 15:58:47 +01003655component_check_python_files () {
3656 msg "Lint: Python scripts"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003657 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003658}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003659
Gilles Peskine8f073122018-11-27 15:58:47 +01003660component_check_generate_test_code () {
3661 msg "uint test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02003662 # unittest writes out mundane stuff like number or tests run on stderr.
3663 # Our convention is to reserve stderr for actual errors, and write
3664 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003665 ./tests/scripts/test_generate_test_code.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01003666}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003667
3668################################################################
3669#### Termination
3670################################################################
3671
Gilles Peskine8f073122018-11-27 15:58:47 +01003672post_report () {
3673 msg "Done, cleaning up"
Gilles Peskine24bdf022020-03-30 20:11:39 +02003674 final_cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003675
Gilles Peskine8f073122018-11-27 15:58:47 +01003676 final_report
3677}
3678
3679
3680
3681################################################################
3682#### Run all the things
3683################################################################
3684
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003685# Function invoked by --error-test to test error reporting.
3686pseudo_component_error_test () {
Gilles Peskine202e9b42021-08-02 23:28:00 +02003687 msg "Testing error reporting $error_test_i"
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003688 if [ $KEEP_GOING -ne 0 ]; then
3689 echo "Expect three failing commands."
3690 fi
Gilles Peskine202e9b42021-08-02 23:28:00 +02003691 # If the component doesn't run in a subshell, changing error_test_i to an
3692 # invalid integer will cause an error in the loop that runs this function.
3693 error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003694 # Expected error: 'grep non_existent /dev/null -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003695 grep non_existent /dev/null
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003696 # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003697 not grep -q . "$0"
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003698 # Expected error: 'make unknown_target -> 2'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003699 make unknown_target
3700 false "this should not be executed"
3701}
3702
Gilles Peskinee48351a2018-11-27 16:06:30 +01003703# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01003704run_component () {
Gilles Peskineffcdeff2018-12-04 12:49:28 +01003705 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02003706 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003707
3708 # Unconditionally create a seedfile that's sufficiently long.
3709 # Do this before each component, because a previous component may
3710 # have messed it up or shortened it.
Gilles Peskinef3133362021-07-08 19:03:50 +02003711 local dd_cmd
3712 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
3713 case $OSTYPE in
3714 linux*|freebsd*|openbsd*|darwin*) dd_cmd+=(status=none)
3715 esac
3716 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003717
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003718 # Run the component in a subshell, with error trapping and output
3719 # redirection set up based on the relevant options.
Gilles Peskine7105a332020-03-28 18:50:43 +01003720 if [ $KEEP_GOING -eq 1 ]; then
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003721 # We want to keep running if the subshell fails, so 'set -e' must
3722 # be off when the subshell runs.
Gilles Peskine7105a332020-03-28 18:50:43 +01003723 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02003724 fi
Gilles Peskine7105a332020-03-28 18:50:43 +01003725 (
3726 if [ $QUIET -eq 1 ]; then
3727 # msg() will be silenced, so just print the component name here.
3728 echo "${current_component#component_}"
3729 exec >/dev/null
3730 fi
3731 if [ $KEEP_GOING -eq 1 ]; then
3732 # Keep "set -e" off, and run an ERR trap instead to record failures.
3733 set -E
3734 trap err_trap ERR
3735 fi
3736 # The next line is what runs the component
3737 "$@"
3738 if [ $KEEP_GOING -eq 1 ]; then
3739 trap - ERR
3740 exit $last_failure_status
3741 fi
3742 )
3743 component_status=$?
3744 if [ $KEEP_GOING -eq 1 ]; then
3745 set -e
3746 if [ $component_status -ne 0 ]; then
3747 failure_count=$((failure_count + 1))
3748 fi
3749 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003750
3751 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01003752 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02003753 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01003754}
3755
3756# Preliminary setup
3757pre_check_environment
3758pre_initialize_variables
3759pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01003760
Dave Rodgman4cb98a92024-02-26 11:41:19 +00003761setup_quiet_wrappers
Gilles Peskine878cf602019-01-06 20:50:38 +00003762pre_check_git
Gilles Peskineef64e7f2021-07-12 18:16:01 +02003763pre_restore_files
Gilles Peskine24bdf022020-03-30 20:11:39 +02003764pre_back_up
Andrzej Kurekeb508712019-02-14 07:18:59 -05003765
Gilles Peskine878cf602019-01-06 20:50:38 +00003766build_status=0
3767if [ $KEEP_GOING -eq 1 ]; then
3768 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01003769fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02003770pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00003771pre_print_configuration
3772pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003773cleanup
3774
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003775# Run the requested tests.
Gilles Peskine202e9b42021-08-02 23:28:00 +02003776for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003777 run_component pseudo_component_error_test
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003778done
Gilles Peskine202e9b42021-08-02 23:28:00 +02003779unset error_test_i
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003780for component in $RUN_COMPONENTS; do
3781 run_component "component_$component"
3782done
Gilles Peskine8f073122018-11-27 15:58:47 +01003783
3784# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00003785post_report