blob: 229e6dff8c52aa5026acfc4292d1e8325c373a18 [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 {} \+
Ronald Crone3bdbd52024-06-12 10:04:22 +0200307 # Remove Makefiles generated by in-tree CMake builds
308 rm -f 3rdparty/Makefile 3rdparty/*/Makefile pkgconfig/Makefile
309 rm -f include/Makefile programs/!(fuzz)/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200310
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100311 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
312 rm -rf programs/test/cmake_subproject/build
313 rm -f programs/test/cmake_subproject/Makefile
314 rm -f programs/test/cmake_subproject/cmake_subproject
315
Gilles Peskine24bdf022020-03-30 20:11:39 +0200316 # Restore files that may have been clobbered by the job
317 for x in $files_to_back_up; do
Gilles Peskine423dd132022-08-30 21:02:00 +0200318 if [[ -e "$x$backup_suffix" ]]; then
319 cp -p "$x$backup_suffix" "$x"
320 fi
Gilles Peskine24bdf022020-03-30 20:11:39 +0200321 done
322}
John Durkopbd069d32020-10-31 22:14:03 -0700323
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200324# Final cleanup when this script exits (except when exiting on a failure
325# in non-keep-going mode).
Gilles Peskine24bdf022020-03-30 20:11:39 +0200326final_cleanup () {
327 cleanup
328
329 for x in $files_to_back_up; do
330 rm -f "$x$backup_suffix"
331 done
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100332}
333
Gilles Peskine7c652162017-12-11 00:01:40 +0100334# Executed on exit. May be redefined depending on command line options.
335final_report () {
336 :
337}
338
339fatal_signal () {
Gilles Peskine24bdf022020-03-30 20:11:39 +0200340 final_cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100341 final_report $1
342 trap - $1
343 kill -$1 $$
344}
345
346trap 'fatal_signal HUP' HUP
347trap 'fatal_signal INT' INT
348trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200349
Gilles Peskine85229ac2021-09-30 18:24:21 +0200350# Number of processors on this machine. Used as the default setting
351# for parallel make.
352all_sh_nproc ()
353{
354 {
355 nproc || # Linux
356 sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
357 sysctl -n hw.ncpu || # FreeBSD
358 echo 1
359 } 2>/dev/null
360}
361
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100362msg()
363{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100364 if [ -n "${current_component:-}" ]; then
365 current_section="${current_component#component_}: $1"
366 else
367 current_section="$1"
368 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200369
370 if [ $QUIET -eq 1 ]; then
371 return
372 fi
373
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100374 echo ""
375 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100376 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000377 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100378 echo "******************************************************************"
379}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100380
Gilles Peskine8f073122018-11-27 15:58:47 +0100381armc6_build_test()
382{
383 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100384
Gilles Peskine18487f62020-04-30 23:11:54 +0200385 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100386 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
Dave Rodgman6cda3d32023-03-02 13:39:04 +0000387 WARNING_CFLAGS='-Werror -xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200388
389 msg "size: ARM Compiler 6 ($FLAGS)"
390 "$ARMC6_FROMELF" -z library/*.o
391
Gilles Peskine8f073122018-11-27 15:58:47 +0100392 make clean
393}
Andres AGa5cd9732016-10-17 15:23:10 +0100394
Andres AGd9eba4b2016-08-26 14:42:14 +0100395err_msg()
396{
397 echo "$1" >&2
398}
399
400check_tools()
401{
402 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000403 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100404 err_msg "$TOOL not found!"
405 exit 1
406 fi
407 done
408}
409
Gilles Peskine8f073122018-11-27 15:58:47 +0100410pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000411 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100412 all_except=0
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100413 error_test=0
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100414 list_components=0
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200415 restore_first=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000416 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100417
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000418 # Note that legacy options are ignored instead of being omitted from this
419 # list of options, so invocations that worked with previous version of
420 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100421 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100422 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200423 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200424 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +0200425 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000426 --armcc) no_armcc=;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100427 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
428 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100429 --clang-earliest) shift; CLANG_EARLIEST="$1";;
430 --clang-latest) shift; CLANG_LATEST="$1";;
Gilles Peskinea5eb22d2020-03-28 21:09:21 +0100431 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000432 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100433 --force|-f) FORCE=1;;
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +0100434 --gcc-earliest) shift; GCC_EARLIEST="$1";;
435 --gcc-latest) shift; GCC_LATEST="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100436 --gnutls-cli) shift; GNUTLS_CLI="$1";;
Gilles Peskine549a9612023-08-27 21:39:21 +0200437 --gnutls-legacy-cli) shift;; # ignored for backward compatibility
438 --gnutls-legacy-serv) shift;; # ignored for backward compatibility
Gilles Peskine55f7c942019-01-09 22:28:21 +0100439 --gnutls-serv) shift; GNUTLS_SERV="$1";;
440 --help|-h) usage; exit;;
441 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000442 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100443 --list-components) list_components=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100444 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200445 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000446 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100447 --no-force) FORCE=0;;
448 --no-keep-going) KEEP_GOING=0;;
449 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200450 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100451 --openssl) shift; OPENSSL="$1";;
452 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
453 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200454 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100455 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200456 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100457 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200458 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200459 --restore) restore_first=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100460 --seed|-s) shift; SEED="$1";;
461 -*)
462 echo >&2 "Unknown option: $1"
463 echo >&2 "Run $0 --help for usage."
464 exit 120
465 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000466 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100467 esac
468 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100469 done
SimonB2e23c822016-04-16 21:54:39 +0100470
Bence Szépkúti2064c9b2023-12-15 19:20:31 +0100471 # Exclude components that are not supported on this platform.
472 SUPPORTED_COMPONENTS=
473 for component in $ALL_COMPONENTS; do
474 case $(type "support_$component" 2>&1) in
475 *' function'*)
476 if ! support_$component; then continue; fi;;
477 esac
478 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
479 done
480
481 if [ $list_components -eq 1 ]; then
482 printf '%s\n' $SUPPORTED_COMPONENTS
483 exit
484 fi
485
Gilles Peskinea28db922019-01-10 00:05:18 +0100486 # With no list of components, run everything.
Gilles Peskine8eb3c952021-08-06 11:51:59 +0200487 if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000488 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100489 fi
490
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000491 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
492 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100493 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000494 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100495 fi
SimonB2e23c822016-04-16 21:54:39 +0100496
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200497 # Error out if an explicitly requested component doesn't exist.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100498 if [ $all_except -eq 0 ]; then
499 unsupported=0
Gilles Peskine6702ce92021-08-06 11:35:17 +0200500 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
501 # only does word splitting.
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200502 set -f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100503 for component in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200504 set +f
Gilles Peskine4fa948f2021-08-03 13:44:28 +0200505 # If the requested name includes a wildcard character, don't
506 # check it. Accept wildcard patterns that don't match anything.
Gilles Peskinee8056c52020-03-28 21:37:59 +0100507 case $component in
508 *[*?\[]*) continue;;
509 esac
510 case " $SUPPORTED_COMPONENTS " in
511 *" $component "*) :;;
512 *)
513 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
514 unsupported=$((unsupported + 1));;
515 esac
516 done
Gilles Peskine8bfe15f2021-08-03 13:43:36 +0200517 set +f
Gilles Peskinee8056c52020-03-28 21:37:59 +0100518 if [ $unsupported -ne 0 ]; then
519 exit 2
520 fi
521 fi
522
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000523 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100524 RUN_COMPONENTS=
525 for component in $SUPPORTED_COMPONENTS; do
526 if is_component_included "$component"; [ $? -eq $all_except ]; then
527 RUN_COMPONENTS="$RUN_COMPONENTS $component"
528 fi
529 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000530
531 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000532 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100533}
SimonB2e23c822016-04-16 21:54:39 +0100534
Gilles Peskine8f073122018-11-27 15:58:47 +0100535pre_check_git () {
536 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100537 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100538 git checkout-index -f -q $CONFIG_H
539 cleanup
540 else
SimonB2e23c822016-04-16 21:54:39 +0100541
Gilles Peskine8f073122018-11-27 15:58:47 +0100542 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
543 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
544 echo "You can either delete this directory manually, or force the test by rerunning"
545 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
546 exit 1
547 fi
548
Gilles Peskined1174cf2019-01-09 22:30:01 +0100549 if ! git diff --quiet include/mbedtls/config.h; then
Gilles Peskine8f073122018-11-27 15:58:47 +0100550 err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. "
551 echo "You can either delete or preserve your work, or force the test by rerunning the"
552 echo "script as: $0 --force"
553 exit 1
554 fi
SimonB2e23c822016-04-16 21:54:39 +0100555 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500556}
557
Gilles Peskineef64e7f2021-07-12 18:16:01 +0200558pre_restore_files () {
559 # If the makefiles have been generated by a framework such as cmake,
560 # restore them from git. If the makefiles look like modifications from
561 # the ones checked into git, take care not to modify them. Whatever
562 # this function leaves behind is what the script will restore before
563 # each component.
564 case "$(head -n1 Makefile)" in
565 *[Gg]enerated*)
566 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
567 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
568 ;;
569 esac
570}
571
Gilles Peskine24bdf022020-03-30 20:11:39 +0200572pre_back_up () {
573 for x in $files_to_back_up; do
574 cp -p "$x" "$x$backup_suffix"
575 done
576}
577
Gilles Peskine8f073122018-11-27 15:58:47 +0100578pre_setup_keep_going () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100579 failure_count=0 # Number of failed components
580 last_failure_status=0 # Last failure status in this component
581
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100582 # See err_trap
583 previous_failure_status=0
584 previous_failed_command=
585 previous_failure_funcall_depth=0
Gilles Peskine39a3b112020-03-28 21:27:40 +0100586 unset report_failed_command
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100587
Gilles Peskine7c652162017-12-11 00:01:40 +0100588 start_red=
589 end_color=
590 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100591 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100592 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
593 start_red=$(printf '\033[31m')
594 end_color=$(printf '\033[0m')
595 ;;
596 esac
597 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100598
599 # Keep a summary of failures in a file. We'll print it out at the end.
600 failure_summary_file=$PWD/all-sh-failures-$$.log
601 : >"$failure_summary_file"
602
603 # Whether it makes sense to keep a component going after the specified
604 # command fails (test command) or not (configure or build).
Gilles Peskine6702ce92021-08-06 11:35:17 +0200605 # This function normally receives the failing simple command
606 # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
607 # this is passed instead.
Gilles Peskine7105a332020-03-28 18:50:43 +0100608 # This doesn't have to be 100% accurate: all failures are recorded anyway.
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200609 # False positives result in running things that can't be expected to
610 # work. False negatives result in things not running after something else
611 # failed even though they might have given useful feedback.
Gilles Peskine7105a332020-03-28 18:50:43 +0100612 can_keep_going_after_failure () {
613 case "$1" in
614 "msg "*) false;;
Gilles Peskine76d40fa2021-08-02 23:29:53 +0200615 "cd "*) false;;
616 *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
617 *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
618 *make*check*) true;;
619 "grep "*) true;;
620 "[ "*) true;;
621 "! "*) true;;
Gilles Peskine7105a332020-03-28 18:50:43 +0100622 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100623 esac
624 }
Gilles Peskine7105a332020-03-28 18:50:43 +0100625
626 # This function runs if there is any error in a component.
627 # It must either exit with a nonzero status, or set
628 # last_failure_status to a nonzero value.
629 err_trap () {
630 # Save $? (status of the failing command). This must be the very
631 # first thing, before $? is overridden.
632 last_failure_status=$?
Gilles Peskine39a3b112020-03-28 21:27:40 +0100633 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskine7105a332020-03-28 18:50:43 +0100634
Gilles Peskine4848d7b2020-03-28 19:34:23 +0100635 if [[ $last_failure_status -eq $previous_failure_status &&
636 "$failed_command" == "$previous_failed_command" &&
637 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
638 then
639 # The same command failed twice in a row, but this time one level
640 # less deep in the function call stack. This happens when the last
641 # command of a function returns a nonzero status, and the function
642 # returns that same status. Ignore the second failure.
643 previous_failure_funcall_depth=${#FUNCNAME[@]}
644 return
645 fi
646 previous_failure_status=$last_failure_status
647 previous_failed_command=$failed_command
648 previous_failure_funcall_depth=${#FUNCNAME[@]}
649
Gilles Peskine7105a332020-03-28 18:50:43 +0100650 text="$current_section: $failed_command -> $last_failure_status"
651 echo "${start_red}^^^^$text^^^^${end_color}" >&2
652 echo "$text" >>"$failure_summary_file"
653
654 # If the command is fatal (configure or build command), stop this
655 # component. Otherwise (test command) keep the component running
656 # (run more tests from the same build).
657 if ! can_keep_going_after_failure "$failed_command"; then
658 exit $last_failure_status
659 fi
660 }
661
Gilles Peskine7c652162017-12-11 00:01:40 +0100662 final_report () {
663 if [ $failure_count -gt 0 ]; then
664 echo
665 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskine7105a332020-03-28 18:50:43 +0100666 echo "${start_red}FAILED: $failure_count components${end_color}"
667 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100668 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
669 elif [ -z "${1-}" ]; then
670 echo "SUCCESS :)"
671 fi
672 if [ -n "${1-}" ]; then
673 echo "Killed by SIG$1."
674 fi
Gilles Peskine7105a332020-03-28 18:50:43 +0100675 rm -f "$failure_summary_file"
676 if [ $failure_count -gt 0 ]; then
677 exit 1
678 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100679 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100680}
681
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200682# record_status() and if_build_succeeded() are kept temporarily for backward
683# compatibility. Don't use them in new components.
Gilles Peskine7105a332020-03-28 18:50:43 +0100684record_status () {
685 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100686}
Gilles Peskine7c652162017-12-11 00:01:40 +0100687if_build_succeeded () {
Gilles Peskine7105a332020-03-28 18:50:43 +0100688 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100689}
690
Gilles Peskine39a3b112020-03-28 21:27:40 +0100691# '! true' does not trigger the ERR trap. Arrange to trigger it, with
692# a reasonably informative error message (not just "$@").
693not () {
694 if "$@"; then
695 report_failed_command="! $*"
696 false
697 unset report_failed_command
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200698 fi
699}
700
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200701pre_prepare_outcome_file () {
702 case "$MBEDTLS_TEST_OUTCOME_FILE" in
703 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
704 esac
705 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
706 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
707 fi
708}
709
Gilles Peskine8f073122018-11-27 15:58:47 +0100710pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200711 if [ $QUIET -eq 1 ]; then
712 return
713 fi
714
Gilles Peskine8f073122018-11-27 15:58:47 +0100715 msg "info: $0 configuration"
716 echo "MEMORY: $MEMORY"
717 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200718 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100719 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100720 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100721 echo "OPENSSL: $OPENSSL"
722 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
723 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
724 echo "GNUTLS_CLI: $GNUTLS_CLI"
725 echo "GNUTLS_SERV: $GNUTLS_SERV"
Gilles Peskine8f073122018-11-27 15:58:47 +0100726 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
727 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
728}
Andres AG7770ea82016-10-10 15:46:20 +0100729
Andres AGd9eba4b2016-08-26 14:42:14 +0100730# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100731pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000732 # Build the list of variables to pass to output_env.sh.
733 set env
SimonB2e23c822016-04-16 21:54:39 +0100734
Gilles Peskine87964262019-01-06 22:40:00 +0000735 case " $RUN_COMPONENTS " in
736 # Require OpenSSL and GnuTLS if running any tests (as opposed to
737 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
738 # is a good enough approximation in practice.
Bence Szépkúticb89fbd2023-12-15 20:58:15 +0100739 *" test_"* | *" release_test_"*)
Gilles Peskine87964262019-01-06 22:40:00 +0000740 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
741 # and ssl-opt.sh, we just export the variables they require.
Manuel Pégourié-Gonnard89d40272022-12-19 11:42:12 +0100742 export OPENSSL="$OPENSSL"
Gilles Peskine87964262019-01-06 22:40:00 +0000743 export GNUTLS_CLI="$GNUTLS_CLI"
744 export GNUTLS_SERV="$GNUTLS_SERV"
745 # Avoid passing --seed flag in every call to ssl-opt.sh
746 if [ -n "${SEED-}" ]; then
747 export SEED
748 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000749 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
750 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000751 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
Gilles Peskine549a9612023-08-27 21:39:21 +0200752 "$GNUTLS_CLI" "$GNUTLS_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000753 ;;
754 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200755
Gilles Peskine87964262019-01-06 22:40:00 +0000756 case " $RUN_COMPONENTS " in
757 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
758 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100759
Gilles Peskine87964262019-01-06 22:40:00 +0000760 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200761 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000762 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100763
Gilles Peskine87964262019-01-06 22:40:00 +0000764 case " $RUN_COMPONENTS " in
765 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
766 esac
767
768 case " $RUN_COMPONENTS " in
769 *" test_zeroize "*) check_tools "gdb";;
770 esac
771
772 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000773 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000774 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
775 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200776 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000777 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
778 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200779 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
780 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
781 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000782 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000783
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200784 # past this point, no call to check_tool, only printing output
785 if [ $QUIET -eq 1 ]; then
786 return
787 fi
788
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000789 msg "info: output_env.sh"
790 case $RUN_COMPONENTS in
791 *_armcc*)
792 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
793 *) set "$@" RUN_ARMCC=0;;
794 esac
795 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100796}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100797
Gilles Peskine192c72f2017-12-21 15:59:21 +0100798
799
800################################################################
801#### Basic checks
802################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100803
804#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200805# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100806#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100807# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200808# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100809# 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 +0200810# time, so start with a GCC build).
811# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100812#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100813# Indicative running times are given for reference.
814
Gilles Peskine8f073122018-11-27 15:58:47 +0100815component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200816 msg "Check: recursion.pl" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200817 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100818}
Janos Follathb72c6782016-07-19 14:54:17 +0100819
Gilles Peskine8f073122018-11-27 15:58:47 +0100820component_check_generated_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200821 msg "Check: freshness of generated source files" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200822 tests/scripts/check-generated-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100823}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200824
Gilles Peskine8f073122018-11-27 15:58:47 +0100825component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200826 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200827 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +0100828}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200829
Gilles Peskine8f073122018-11-27 15:58:47 +0100830component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200831 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200832 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100833}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200834
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200835component_check_changelog () {
836 msg "Check: changelog entries" # < 1s
837 rm -f ChangeLog.new
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200838 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200839 if [ -e ChangeLog.new ]; then
840 # Show the diff for information. It isn't an error if the diff is
841 # non-empty.
842 diff -u ChangeLog ChangeLog.new || true
843 rm ChangeLog.new
844 fi
845}
846
Gilles Peskine8f073122018-11-27 15:58:47 +0100847component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200848 msg "Check: declared and exported names (builds the library)" # < 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200849 tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100850}
Darryl Greena07039c2018-03-13 16:48:16 +0000851
Gilles Peskine895868b2019-09-19 21:30:05 +0200852component_check_test_cases () {
853 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200854 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200855 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200856 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200857 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +0200858 fi
Gilles Peskine58987962022-12-15 14:46:31 +0100859 tests/scripts/check_test_cases.py -q $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +0200860 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +0200861}
862
Gilles Peskine8f073122018-11-27 15:58:47 +0100863component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200864 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200865 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100866}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200867
Gilles Peskine192c72f2017-12-21 15:59:21 +0100868
Gilles Peskine636c26a2020-03-04 20:46:15 +0100869
Gilles Peskine192c72f2017-12-21 15:59:21 +0100870################################################################
871#### Build and test many configurations and targets
872################################################################
873
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200874component_test_default_out_of_box () {
875 msg "build: make, default config (out-of-box)" # ~1min
876 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200877 # Disable fancy stuff
878 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200879
880 msg "test: main suites make, default config (out-of-box)" # ~10s
881 make test
882
883 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200884 programs/test/selftest
Gilles Peskine93aaf2e2019-06-14 18:27:03 +0200885
886 msg "program demos: make, default config (out-of-box)" # ~10s
887 tests/scripts/run_demos.py
Gilles Peskine7832c9f2019-04-08 17:00:15 +0200888}
889
Gilles Peskinea8cd2e62024-05-17 19:00:46 +0200890component_build_without_check_config () {
891 msg "build: full without check_config.h"
892 scripts/config.py full
893 sed -i '/#include.*check_config\.h/ s!^!//!' "$CONFIG_H"
894 make
895}
896
Gilles Peskine8f073122018-11-27 15:58:47 +0100897component_test_default_cmake_gcc_asan () {
898 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +0100899 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
900 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200901
Gilles Peskine8f073122018-11-27 15:58:47 +0100902 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
903 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200904
Gilles Peskine93aaf2e2019-06-14 18:27:03 +0200905 msg "program demos (ASan build)" # ~10s
906 tests/scripts/run_demos.py
907
Gilles Peskine97bea012020-04-23 23:37:45 +0200908 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200909 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200910
Gilles Peskineee8af062023-11-02 19:58:03 +0100911 msg "test: metatests (GCC, ASan build)"
David Horstmann1b421b12024-01-17 14:53:08 +0000912 tests/scripts/run-metatests.sh any asan poison
Gilles Peskineee8af062023-11-02 19:58:03 +0100913
Gilles Peskine8f073122018-11-27 15:58:47 +0100914 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200915 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200916
Gilles Peskine8f073122018-11-27 15:58:47 +0100917 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200918 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200919
920 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200921 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100922}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200923
Hanno Becker01635512019-02-26 14:27:09 +0000924component_test_full_cmake_gcc_asan () {
925 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +0200926 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +0000927 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
928 make
929
930 msg "test: main suites (inc. selftests) (full config, ASan build)"
931 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +0100932
Gilles Peskine97bea012020-04-23 23:37:45 +0200933 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200934 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +0200935
Gilles Peskine636c26a2020-03-04 20:46:15 +0100936 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200937 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100938
Manuel Pégourié-Gonnardb76606c2024-04-17 12:15:51 +0200939 msg "test: compat.sh all except legacy/next (full config, ASan build)"
940 tests/compat.sh -e '^DES-CBC-\|-DES-CBC-\|ARIA\|CHACHA' \
941 -m 'ssl3 tls1 tls1_1 tls12 dtls1 dtls12'
942
943 msg "test: compat.sh single-DES (full config, ASan build)"
944 env OPENSSL="$OPENSSL_LEGACY" tests/compat.sh -e '^$' -f '^DES-CBC\|-DES-CBC-' \
945 -m 'ssl3 tls1 tls1_1 tls12 dtls1 dtls12'
946
947 # ARIA and ChachaPoly are both (D)TLS 1.2 only
948 msg "test: compat.sh ARIA + ChachaPoly (full config, ASan build)"
949 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA' \
Manuel Pégourié-Gonnardde887ba2024-04-18 10:05:04 +0200950 -m 'tls12 dtls12'
Piotr Nowicki9978e6e2020-04-07 16:07:05 +0200951
952 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +0200953 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +0100954}
955
Ronald Cronc3623db2020-10-29 10:51:32 +0100956component_test_psa_crypto_key_id_encodes_owner () {
957 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
958 scripts/config.py full
959 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
960 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
961 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
962 make
963
964 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
965 make test
966}
967
David Horstmann42015332024-03-13 15:42:31 +0000968component_test_psa_assume_exclusive_buffers () {
969 msg "build: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
David Horstmanndda52ae2023-12-20 11:10:16 +0000970 scripts/config.py full
David Horstmann42015332024-03-13 15:42:31 +0000971 scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
David Horstmanndda52ae2023-12-20 11:10:16 +0000972 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
973 make
974
David Horstmann42015332024-03-13 15:42:31 +0000975 msg "test: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
David Horstmanndda52ae2023-12-20 11:10:16 +0000976 make test
977}
978
Gilles Peskine99a34622021-06-17 11:37:52 +0200979# check_renamed_symbols HEADER LIB
980# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
981# name is LIB.
982check_renamed_symbols () {
983 ! nm "$2" | sed 's/.* //' |
984 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
985}
986
Gilles Peskine984c19f2021-06-15 18:37:38 +0200987component_build_psa_crypto_spm () {
988 msg "build: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
989 scripts/config.py full
990 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
991 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
992 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
993 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
994 # We can only compile, not link, since our test and sample programs
995 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
996 # is active.
997 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskine99a34622021-06-17 11:37:52 +0200998
999 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
1000 # version is not present.
1001 echo "Checking for renamed symbols in the library"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001002 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskine984c19f2021-06-15 18:37:38 +02001003}
1004
Ronald Cron336678b2021-01-28 17:54:24 +01001005component_test_psa_crypto_client () {
1006 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
1007 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1008 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1009 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
1010 make
1011
1012 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
1013 make test
1014}
1015
Gilles Peskine636c26a2020-03-04 20:46:15 +01001016component_test_zlib_make() {
1017 msg "build: zlib enabled, make"
1018 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine6fa69862021-10-05 09:36:03 +02001019 make ZLIB=1 CFLAGS='-Werror -O2'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001020
1021 msg "test: main suites (zlib, make)"
1022 make test
1023
1024 msg "test: ssl-opt.sh (zlib, make)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001025 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001026}
1027support_test_zlib_make () {
1028 base=support_test_zlib_$$
1029 cat <<'EOF' > ${base}.c
1030#include "zlib.h"
1031int main(void) { return 0; }
1032EOF
1033 gcc -o ${base}.exe ${base}.c -lz 2>/dev/null
1034 ret=$?
1035 rm -f ${base}.*
1036 return $ret
1037}
1038
1039component_test_zlib_cmake() {
Dave Rodgmandff18da2024-03-01 15:53:52 +00001040 # This is needed due to something parsing the output from make
1041 export VERBOSE_LOGS=1
1042
Gilles Peskine636c26a2020-03-04 20:46:15 +01001043 msg "build: zlib enabled, cmake"
1044 scripts/config.py set MBEDTLS_ZLIB_SUPPORT
Gilles Peskine25319702021-10-07 19:34:57 +02001045 cmake -D ENABLE_ZLIB_SUPPORT=On -D CMAKE_BUILD_TYPE:String=Release .
Gilles Peskine636c26a2020-03-04 20:46:15 +01001046 make
1047
1048 msg "test: main suites (zlib, cmake)"
1049 make test
1050
1051 msg "test: ssl-opt.sh (zlib, cmake)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001052 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001053}
1054support_test_zlib_cmake () {
1055 support_test_zlib_make "$@"
Manuel Pégourié-Gonnardf2e29022020-01-24 10:17:20 +01001056}
Manuel Pégourié-Gonnard95e04492020-01-02 11:45:12 +01001057
Jaeden Ameroc17f2932021-05-14 08:34:32 +01001058component_test_psa_crypto_rsa_no_genprime() {
1059 msg "build: default config minus MBEDTLS_GENPRIME"
1060 scripts/config.py unset MBEDTLS_GENPRIME
1061 make
1062
1063 msg "test: default config minus MBEDTLS_GENPRIME"
1064 make test
1065}
1066
Gilles Peskine782f4112018-11-27 16:11:09 +01001067component_test_ref_configs () {
1068 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
1069 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001070 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +01001071}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001072
Gilles Peskine8f073122018-11-27 15:58:47 +01001073component_test_sslv3 () {
1074 msg "build: Default + SSLv3 (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001075 scripts/config.py set MBEDTLS_SSL_PROTO_SSL3
Gilles Peskine8f073122018-11-27 15:58:47 +01001076 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1077 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001078
Gilles Peskine8f073122018-11-27 15:58:47 +01001079 msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s
1080 make test
Simon Butcher3ea7f522016-03-07 23:22:10 +00001081
Gilles Peskine8f073122018-11-27 15:58:47 +01001082 msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001083 tests/compat.sh -m 'ssl3 tls1 tls1_1 tls12 dtls1 dtls12'
Simon Butcher3ea7f522016-03-07 23:22:10 +00001084
Gilles Peskine8f073122018-11-27 15:58:47 +01001085 msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001086 tests/ssl-opt.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001087
1088 msg "build: SSLv3 - context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001089 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001090}
Simon Butcher3ea7f522016-03-07 23:22:10 +00001091
Gilles Peskine8f073122018-11-27 15:58:47 +01001092component_test_no_renegotiation () {
1093 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001094 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001095 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1096 make
Simon Butcher3ea7f522016-03-07 23:22:10 +00001097
Gilles Peskine8f073122018-11-27 15:58:47 +01001098 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1099 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +01001100
Gilles Peskine8f073122018-11-27 15:58:47 +01001101 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001102 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001103}
Hanno Becker134c2ab2017-10-12 15:29:50 +01001104
Gilles Peskine56194432023-02-01 18:44:11 +01001105component_test_no_certs () {
1106 msg "build: full minus MBEDTLS_CERTS_C"
1107 scripts/config.py full
1108 scripts/config.py unset MBEDTLS_CERTS_C
1109 # Quick build+test (we're checking for stray uses of the test certs,
1110 # not expecting their absence to lead to subtle problems).
1111 make
1112
1113 msg "test: full minus MBEDTLS_CERTS_C - main suites"
1114 make test
1115}
1116
Gilles Peskine636c26a2020-03-04 20:46:15 +01001117component_test_no_pem_no_fs () {
1118 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1119 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1120 scripts/config.py unset MBEDTLS_FS_IO
1121 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1122 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
1123 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1124 make
1125
1126 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1127 make test
1128
1129 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001130 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001131}
1132
Gilles Peskine8f073122018-11-27 15:58:47 +01001133component_test_rsa_no_crt () {
1134 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001135 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +01001136 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1137 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +01001138
Gilles Peskine8f073122018-11-27 15:58:47 +01001139 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1140 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001141
Gilles Peskine8f073122018-11-27 15:58:47 +01001142 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001143 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001144
Gilles Peskine8f073122018-11-27 15:58:47 +01001145 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001146 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001147
1148 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001149 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001150}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001151
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001152component_test_no_ctr_drbg_classic () {
1153 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001154 scripts/config.py full
1155 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001156 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001157
1158 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1159 make
1160
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001161 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001162 make test
1163
Gilles Peskineba749042021-01-13 20:02:03 +01001164 # In this configuration, the TLS test programs use HMAC_DRBG.
1165 # The SSL tests are slow, so run a small subset, just enough to get
1166 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001167 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001168 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001169
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001170 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001171 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001172}
1173
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001174component_test_no_ctr_drbg_use_psa () {
1175 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001176 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001177 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1178 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001179
1180 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1181 make
1182
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001183 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1184 make test
1185
1186 # In this configuration, the TLS test programs use HMAC_DRBG.
1187 # The SSL tests are slow, so run a small subset, just enough to get
1188 # confidence that the SSL code copes with HMAC_DRBG.
1189 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001190 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001191
1192 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001193 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001194}
1195
1196component_test_no_hmac_drbg_classic () {
1197 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1198 scripts/config.py full
1199 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1200 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1201 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1202
1203 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1204 make
1205
1206 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001207 make test
1208
Gilles Peskinea2224342020-11-19 22:14:34 +01001209 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1210 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1211 # instead.
1212 # Test SSL with non-deterministic ECDSA. Only test features that
1213 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001214 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001215 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001216
1217 # To save time, only test one protocol version, since this part of
1218 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001219 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001220 tests/compat.sh -m tls12 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001221}
1222
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001223component_test_no_hmac_drbg_use_psa () {
1224 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1225 scripts/config.py full
1226 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1227 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1228 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1229
1230 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1231 make
1232
1233 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1234 make test
1235
1236 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1237 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1238 # instead.
1239 # Test SSL with non-deterministic ECDSA. Only test features that
1240 # might be affected by how ECDSA signature is performed.
1241 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001242 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001243
1244 # To save time, only test one protocol version, since this part of
1245 # the protocol is identical in (D)TLS up to 1.2.
1246 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Xiaofei Baif40545d2021-12-02 08:43:35 +00001247 tests/compat.sh -m tls12 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001248}
1249
1250component_test_psa_external_rng_no_drbg_classic () {
1251 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1252 scripts/config.py full
1253 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1254 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001255 scripts/config.py unset MBEDTLS_ENTROPY_C
1256 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1257 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001258 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1259 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1260 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1261 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001262 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1263 # the SSL test programs don't have an RNG and can't work. Explicitly
1264 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1265 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001266
1267 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1268 make test
1269
Gilles Peskine8eb29432021-02-03 20:07:11 +01001270 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001271 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001272}
1273
1274component_test_psa_external_rng_no_drbg_use_psa () {
1275 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001276 scripts/config.py full
1277 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001278 scripts/config.py unset MBEDTLS_ENTROPY_C
1279 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1280 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001281 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1282 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1283 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1284 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1285 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1286
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001287 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001288 make test
1289
Gilles Peskine8eb29432021-02-03 20:07:11 +01001290 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001291 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001292}
1293
1294component_test_psa_external_rng_use_psa_crypto () {
1295 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1296 scripts/config.py full
1297 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1298 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1299 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1300 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1301
1302 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1303 make test
1304
Gilles Peskineba749042021-01-13 20:02:03 +01001305 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001306 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001307}
1308
Gilles Peskine55e89982023-04-28 21:04:28 +02001309component_test_psa_inject_entropy () {
1310 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
1311 scripts/config.py full
1312 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
1313 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
1314 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1315 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1316 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
1317 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
1318 make CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
1319
1320 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
1321 make test
1322}
1323
Manuel Pégourié-Gonnard1a3f9ed2020-05-19 12:38:31 +02001324component_test_ecp_no_internal_rng () {
1325 msg "build: Default plus ECP_NO_INTERNAL_RNG minus DRBG modules"
1326 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1327 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1328 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1329 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1330 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires a DRBG
1331 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1332
1333 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1334 make
1335
1336 msg "test: ECP_NO_INTERNAL_RNG, no DRBG module"
1337 make test
1338
1339 # no SSL tests as they all depend on having a DRBG
1340}
1341
Manuel Pégourié-Gonnard53fb66d2020-06-04 09:43:14 +02001342component_test_ecp_restartable_no_internal_rng () {
1343 msg "build: Default plus ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG"
1344 scripts/config.py set MBEDTLS_ECP_NO_INTERNAL_RNG
1345 scripts/config.py set MBEDTLS_ECP_RESTARTABLE
1346 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1347 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1348 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1349 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C # requires CTR_DRBG
1350 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA Crypto
1351
1352 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1353 make
1354
1355 msg "test: ECP_RESTARTABLE and ECP_NO_INTERNAL_RNG, no DRBG module"
1356 make test
1357
1358 # no SSL tests as they all depend on having a DRBG
1359}
1360
Przemek Stekiele5352702022-10-05 11:37:54 +02001361component_test_tls1_2_default_stream_cipher_only () {
1362 msg "build: default with only stream cipher"
1363
1364 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
1365 scripts/config.py unset MBEDTLS_GCM_C
1366 scripts/config.py unset MBEDTLS_CCM_C
1367 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1368 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1369 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1370 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1371 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1372 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1373 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1374 # Modules that depend on AEAD
1375 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001376 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001377
1378 make
1379
1380 msg "test: default with only stream cipher"
1381 make test
1382
1383 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1384}
1385
1386component_test_tls1_2_default_stream_cipher_only_use_psa () {
1387 msg "build: default with only stream cipher use psa"
1388
1389 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1390 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1391 scripts/config.py unset MBEDTLS_GCM_C
1392 scripts/config.py unset MBEDTLS_CCM_C
1393 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1394 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1395 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1396 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1397 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1398 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1399 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1400 # Modules that depend on AEAD
1401 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001402 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001403
1404 make
1405
1406 msg "test: default with only stream cipher use psa"
1407 make test
1408
1409 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1410}
1411
1412component_test_tls1_2_default_cbc_legacy_cipher_only () {
1413 msg "build: default with only CBC-legacy cipher"
1414
1415 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1416 scripts/config.py unset MBEDTLS_GCM_C
1417 scripts/config.py unset MBEDTLS_CCM_C
1418 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1419 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1420 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1421 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1422 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1423 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1424 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1425 # Modules that depend on AEAD
1426 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001427 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001428
1429 make
1430
1431 msg "test: default with only CBC-legacy cipher"
1432 make test
1433
1434 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1435 tests/ssl-opt.sh -f "TLS 1.2"
1436}
1437
1438component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
1439 msg "build: default with only CBC-legacy cipher use psa"
1440
1441 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1442 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1443 scripts/config.py unset MBEDTLS_GCM_C
1444 scripts/config.py unset MBEDTLS_CCM_C
1445 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1446 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1447 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1448 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1449 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1450 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1451 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1452 # Modules that depend on AEAD
1453 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001454 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001455
1456 make
1457
1458 msg "test: default with only CBC-legacy cipher use psa"
1459 make test
1460
1461 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1462 tests/ssl-opt.sh -f "TLS 1.2"
1463}
1464
1465component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
1466 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1467
1468 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1469 scripts/config.py unset MBEDTLS_GCM_C
1470 scripts/config.py unset MBEDTLS_CCM_C
1471 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1472 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1473 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1474 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1475 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1476 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1477 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1478 # Modules that depend on AEAD
1479 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001480 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001481
1482 make
1483
1484 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1485 make test
1486
1487 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1488 tests/ssl-opt.sh -f "TLS 1.2"
1489}
1490
1491component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
1492 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
1493
1494 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1495 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1496 scripts/config.py unset MBEDTLS_GCM_C
1497 scripts/config.py unset MBEDTLS_CCM_C
1498 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1499 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1500 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1501 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1502 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1503 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1504 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1505 # Modules that depend on AEAD
1506 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel97d57402022-10-10 14:08:51 +02001507 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele5352702022-10-05 11:37:54 +02001508
1509 make
1510
1511 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
1512 make test
1513
1514 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
1515 tests/ssl-opt.sh -f "TLS 1.2"
1516}
1517
Gilles Peskine636c26a2020-03-04 20:46:15 +01001518component_test_new_ecdh_context () {
1519 msg "build: new ECDH context (ASan build)" # ~ 6 min
1520 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1521 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1522 make
1523
1524 msg "test: new ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1525 make test
1526
1527 msg "test: new ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001528 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001529
1530 msg "test: new ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1531 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001532 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001533}
1534
1535component_test_everest () {
1536 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
1537 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1538 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1539 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1540 make
1541
1542 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1543 make test
1544
Gilles Peskineee8af062023-11-02 19:58:03 +01001545 msg "test: metatests (clang, ASan)"
David Horstmann1b421b12024-01-17 14:53:08 +00001546 tests/scripts/run-metatests.sh any asan poison
Gilles Peskineee8af062023-11-02 19:58:03 +01001547
Gilles Peskine636c26a2020-03-04 20:46:15 +01001548 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001549 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001550
1551 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1552 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001553 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001554}
1555
Gilles Peskined3beca92020-07-03 00:15:37 +02001556component_test_everest_curve25519_only () {
1557 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
1558 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
1559 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1560 scripts/config.py unset MBEDTLS_ECDSA_C
1561 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1562 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1563 # Disable all curves
1564 for c in $(sed -n 's/#define \(MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED\).*/\1/p' <"$CONFIG_H"); do
1565 scripts/config.py unset "$c"
1566 done
1567 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1568
1569 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1570
1571 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1572 make test
1573}
1574
Gilles Peskine8f073122018-11-27 15:58:47 +01001575component_test_small_ssl_out_content_len () {
1576 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001577 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1578 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001579 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1580 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001581
Gilles Peskine8f073122018-11-27 15:58:47 +01001582 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001583 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001584}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001585
Gilles Peskine8f073122018-11-27 15:58:47 +01001586component_test_small_ssl_in_content_len () {
1587 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001588 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1589 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001590 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1591 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001592
Gilles Peskine8f073122018-11-27 15:58:47 +01001593 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001594 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001595}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001596
Gilles Peskine8f073122018-11-27 15:58:47 +01001597component_test_small_ssl_dtls_max_buffering () {
1598 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001599 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001600 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1601 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001602
Gilles Peskine8f073122018-11-27 15:58:47 +01001603 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001604 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 +01001605}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001606
Gilles Peskine8f073122018-11-27 15:58:47 +01001607component_test_small_mbedtls_ssl_dtls_max_buffering () {
1608 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001609 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001610 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1611 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001612
Gilles Peskine8f073122018-11-27 15:58:47 +01001613 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001614 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001615}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001616
Gilles Peskine75cc7712019-09-06 19:47:17 +02001617component_test_psa_collect_statuses () {
1618 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001619 scripts/config.py full
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001620 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001621 # Check that psa_crypto_init() succeeded at least once
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001622 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001623 rm -f tests/statuses.log
1624}
1625
Gilles Peskine8f073122018-11-27 15:58:47 +01001626component_test_full_cmake_clang () {
1627 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001628 scripts/config.py full
Gilles Peskine83264be2022-10-30 21:02:40 +01001629 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 +01001630 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001631
k-stachowiak0291cb72019-06-26 15:52:12 +02001632 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001633 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001634
Gilles Peskine83264be2022-10-30 21:02:40 +01001635 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
1636 programs/test/cpp_dummy_build
1637
Gilles Peskineee8af062023-11-02 19:58:03 +01001638 msg "test: metatests (clang)"
Gilles Peskinee38eb792023-11-03 18:05:38 +01001639 tests/scripts/run-metatests.sh any pthread
Gilles Peskineee8af062023-11-02 19:58:03 +01001640
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02001641 msg "program demos (full config, clang)" # ~10s
1642 tests/scripts/run_demos.py
1643
k-stachowiak0291cb72019-06-26 15:52:12 +02001644 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001645 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001646
Gilles Peskine8f073122018-11-27 15:58:47 +01001647 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001648 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Gilles Peskine8f073122018-11-27 15:58:47 +01001649}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001650
Gilles Peskine9603a442022-11-29 16:01:41 +01001651skip_suites_without_constant_flow () {
1652 # Skip the test suites that don't have any constant-flow annotations.
1653 # This will need to be adjusted if we ever start declaring things as
1654 # secret from macros or functions inside tests/include or tests/src.
1655 SKIP_TEST_SUITES=$(
1656 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
1657 sed 's/test_suite_//; s/\.function$//' |
1658 tr '\n' ,)
1659 export SKIP_TEST_SUITES
1660}
1661
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001662component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001663 # This tests both (1) accesses to undefined memory, and (2) branches or
1664 # memory access depending on secret values. To distinguish between those:
1665 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1666 # - or alternatively, change the build type to MemSanDbg, which enables
1667 # origin tracking and nicer stack traces (which are useful for debugging
1668 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
1669 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001670 scripts/config.py full
1671 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1672 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1673 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1674 make
1675
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001676 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001677 make test
1678}
1679
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01001680component_release_test_valgrind_constant_flow () {
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001681 # This tests both (1) everything that valgrind's memcheck usually checks
1682 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1683 # etc.) and (2) branches or memory access depending on secret values,
1684 # which will be reported as uninitialized memory. To distinguish between
1685 # secret and actually uninitialized:
1686 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1687 # - or alternatively, build with debug info and manually run the offending
1688 # test suite with valgrind --track-origins=yes, then check if the origin
1689 # was TEST_CF_SECRET() or something else.
1690 msg "build: cmake release GCC, full config with constant flow testing"
1691 scripts/config.py full
1692 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Gilles Peskine9603a442022-11-29 16:01:41 +01001693 skip_suites_without_constant_flow
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001694 cmake -D CMAKE_BUILD_TYPE:String=Release .
1695 make
1696
1697 # this only shows a summary of the results (how many of each type)
1698 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine9603a442022-11-29 16:01:41 +01001699 msg "test: some suites (valgrind + constant flow)"
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001700 make memcheck
1701}
1702
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001703component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02001704 # Test that removing the deprecated features from the default
1705 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001706 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1707 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
Dave Rodgman374b1882024-01-04 10:30:57 +00001708 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001709
1710 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1711 make test
1712}
1713
1714component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02001715 msg "build: make, full_no_deprecated config" # ~ 30s
1716 scripts/config.py full_no_deprecated
Dave Rodgman374b1882024-01-04 10:30:57 +00001717 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001718
Gilles Peskine30de2e82020-04-20 21:39:22 +02001719 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001720 make test
1721}
1722
Gilles Peskine8386ea22020-04-30 09:07:29 +02001723component_test_full_no_deprecated_deprecated_warning () {
1724 # Test that there is nothing deprecated in "full_no_deprecated".
1725 # A deprecated feature would trigger a warning (made fatal) from
1726 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02001727 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1728 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001729 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
1730 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Dave Rodgman374b1882024-01-04 10:30:57 +00001731 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001732
Gilles Peskine30de2e82020-04-20 21:39:22 +02001733 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001734 make test
1735}
1736
Gilles Peskine8386ea22020-04-30 09:07:29 +02001737component_test_full_deprecated_warning () {
1738 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
1739 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001740 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001741 scripts/config.py full
1742 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001743 # Expect warnings from '#warning' directives in check_config.h.
Dave Rodgman9d2c67f2023-12-19 14:07:15 +00001744 # Note that gcc is required to allow the use of -Wno-error=cpp, which allows us to
1745 # display #warning messages without them being treated as errors.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001746 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01001747
Gilles Peskine8386ea22020-04-30 09:07:29 +02001748 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
1749 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
1750 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001751 # Expect warnings from '#warning' directives in check_config.h and
1752 # from the use of deprecated functions in test suites.
1753 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 +01001754
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001755 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
1756 make test
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02001757
1758 msg "program demos: full config + MBEDTLS_TEST_DEPRECATED" # ~10s
1759 tests/scripts/run_demos.py
Gilles Peskine8f073122018-11-27 15:58:47 +01001760}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00001761
Gilles Peskineec541fe2020-01-31 14:24:14 +01001762# Check that the specified libraries exist and are empty.
1763are_empty_libraries () {
1764 nm "$@" >/dev/null 2>/dev/null
1765 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
1766}
1767
1768component_build_crypto_default () {
1769 msg "build: make, crypto only"
1770 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01001771 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001772 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001773}
1774
1775component_build_crypto_full () {
1776 msg "build: make, crypto only, full config"
1777 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01001778 make CFLAGS='-O1 -Werror'
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001779 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001780}
1781
Gilles Peskine8df27482022-10-21 19:34:54 +02001782component_test_crypto_for_psa_service () {
Gilles Peskine21503df2022-10-11 21:05:06 +02001783 msg "build: make, config for PSA crypto service"
1784 scripts/config.py crypto
1785 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1786 # Disable things that are not needed for just cryptography, to
1787 # reach a configuration that would be typical for a PSA cryptography
1788 # service providing all implemented PSA algorithms.
1789 # System stuff
1790 scripts/config.py unset MBEDTLS_ERROR_C
1791 scripts/config.py unset MBEDTLS_TIMING_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001792 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskine21503df2022-10-11 21:05:06 +02001793 # Crypto stuff with no PSA interface
1794 scripts/config.py unset MBEDTLS_BASE64_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001795 scripts/config.py unset MBEDTLS_BLOWFISH_C
1796 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
1797 # Keep MBEDTLS_MD_C because RSA and ECDSA need it, also HMAC_DRBG which
1798 # is needed for deterministic ECDSA.
1799 scripts/config.py unset MBEDTLS_ECJPAKE_C
1800 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
Gilles Peskine21503df2022-10-11 21:05:06 +02001801 scripts/config.py unset MBEDTLS_NIST_KW_C
1802 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1803 scripts/config.py unset MBEDTLS_PEM_WRITE_C
1804 scripts/config.py unset MBEDTLS_PKCS12_C
1805 scripts/config.py unset MBEDTLS_PKCS5_C
Gilles Peskine031c8c22022-10-25 21:09:49 +02001806 # We keep MBEDTLS_PK_{,PARSE,WRITE}_C because PSA with RSA needs it.
1807 scripts/config.py unset MBEDTLS_XTEA_C
Gilles Peskine21503df2022-10-11 21:05:06 +02001808 make CFLAGS='-O1 -Werror' all test
1809 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
1810}
1811
Gilles Peskineec541fe2020-01-31 14:24:14 +01001812component_build_crypto_baremetal () {
1813 msg "build: make, crypto only, baremetal config"
1814 scripts/config.py crypto_baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001815 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001816 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01001817}
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001818support_build_crypto_baremetal () {
Daniel Axtens1a021af2020-08-31 14:22:58 +10001819 support_build_baremetal "$@"
1820}
1821
1822component_build_baremetal () {
1823 msg "build: make, baremetal config"
1824 scripts/config.py baremetal
David Horstmann3cb5e9b2021-11-30 11:40:54 +00001825 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Daniel Axtens1a021af2020-08-31 14:22:58 +10001826}
1827support_build_baremetal () {
Daniel Axtens6f63cc72020-09-02 21:30:13 +10001828 # Older Glibc versions include time.h from other headers such as stdlib.h,
1829 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
1830 # problem, Ubuntu 18.04 is ok.
1831 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
1832}
Gilles Peskineec541fe2020-01-31 14:24:14 +01001833
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001834# depends.py family of tests
Andrzej Kurek85d69302022-10-05 09:14:07 -04001835component_test_depends_py_cipher_id () {
1836 msg "test/build: depends.py cipher_id (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001837 tests/scripts/depends.py cipher_id --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001838}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001839
Andrzej Kurek85d69302022-10-05 09:14:07 -04001840component_test_depends_py_cipher_chaining () {
1841 msg "test/build: depends.py cipher_chaining (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001842 tests/scripts/depends.py cipher_chaining --unset-use-psa
John Durkopc14be902020-08-20 06:16:41 -07001843}
1844
Andrzej Kurek85d69302022-10-05 09:14:07 -04001845component_test_depends_py_cipher_padding () {
1846 msg "test/build: depends.py cipher_padding (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001847 tests/scripts/depends.py cipher_padding --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001848}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00001849
Andrzej Kurek85d69302022-10-05 09:14:07 -04001850component_test_depends_py_curves () {
1851 msg "test/build: depends.py curves (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001852 tests/scripts/depends.py curves --unset-use-psa
John Durkop2ec2eaa2020-08-24 18:29:15 -07001853}
1854
Andrzej Kurek85d69302022-10-05 09:14:07 -04001855component_test_depends_py_hashes () {
1856 msg "test/build: depends.py hashes (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001857 tests/scripts/depends.py hashes --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01001858}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001859
Andrzej Kurek85d69302022-10-05 09:14:07 -04001860component_test_depends_py_kex () {
1861 msg "test/build: depends.py kex (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001862 tests/scripts/depends.py kex --unset-use-psa
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001863}
1864
Andrzej Kurek85d69302022-10-05 09:14:07 -04001865component_test_depends_py_pkalgs () {
1866 msg "test/build: depends.py pkalgs (gcc)"
Andrzej Kurek20d8a5f2022-10-24 10:49:22 -04001867 tests/scripts/depends.py pkalgs --unset-use-psa
1868}
1869
1870# PSA equivalents of the depends.py tests
1871component_test_depends_py_cipher_id_psa () {
1872 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1873 tests/scripts/depends.py cipher_id
1874}
1875
1876component_test_depends_py_cipher_chaining_psa () {
1877 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1878 tests/scripts/depends.py cipher_chaining
1879}
1880
1881component_test_depends_py_cipher_padding_psa () {
1882 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1883 tests/scripts/depends.py cipher_padding
1884}
1885
1886component_test_depends_py_curves_psa () {
1887 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1888 tests/scripts/depends.py curves
1889}
1890
1891component_test_depends_py_hashes_psa () {
1892 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1893 tests/scripts/depends.py hashes
1894}
1895
1896component_test_depends_py_kex_psa () {
1897 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
1898 tests/scripts/depends.py kex
1899}
1900
1901component_test_depends_py_pkalgs_psa () {
1902 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Andrzej Kurek85d69302022-10-05 09:14:07 -04001903 tests/scripts/depends.py pkalgs
Gilles Peskine8f073122018-11-27 15:58:47 +01001904}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01001905
Dave Rodgman5fce4f62023-01-20 13:18:05 +00001906component_build_no_pk_rsa_alt_support () {
1907 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
1908
1909 scripts/config.py full
1910 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
1911 scripts/config.py set MBEDTLS_RSA_C
1912 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
1913
1914 # Only compile - this is primarily to test for compile issues
Dave Rodgman374b1882024-01-04 10:30:57 +00001915 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
Dave Rodgman5fce4f62023-01-20 13:18:05 +00001916}
1917
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001918component_test_no_use_psa_crypto_full_cmake_asan() {
1919 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02001920 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001921 scripts/config.py full
1922 scripts/config.py set MBEDTLS_ECP_RESTARTABLE # not using PSA, so enable restartable ECC
1923 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1924 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1925 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02001926 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001927 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01001928 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001929 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02001930
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001931 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001932 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02001933
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001934 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02001935 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01001936
Manuel Pégourié-Gonnardaefbb662024-04-17 11:51:13 +02001937 msg "test: compat.sh all except legacy/next (full minus MBEDTLS_USE_PSA_CRYPTO)"
1938 tests/compat.sh -e '^DES-CBC-\|-DES-CBC-\|ARIA\|CHACHA' \
Manuel Pégourié-Gonnard2cd43a72024-04-09 23:01:09 +02001939 -m 'ssl3 tls1 tls1_1 tls12 dtls1 dtls12'
Gilles Peskinec67c3b32023-08-27 21:33:41 +02001940
1941 msg "test: compat.sh single-DES (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnardaefbb662024-04-17 11:51:13 +02001942 env OPENSSL="$OPENSSL_LEGACY" tests/compat.sh -e '^$' -f '^DES-CBC\|-DES-CBC-' \
Manuel Pégourié-Gonnard2cd43a72024-04-09 23:01:09 +02001943 -m 'ssl3 tls1 tls1_1 tls12 dtls1 dtls12'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001944
Manuel Pégourié-Gonnardaefbb662024-04-17 11:51:13 +02001945 # ARIA and ChachaPoly are both (D)TLS 1.2 only
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01001946 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnardaefbb662024-04-17 11:51:13 +02001947 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA' \
Manuel Pégourié-Gonnardde887ba2024-04-18 10:05:04 +02001948 -m 'tls12 dtls12'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05001949}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05001950
Ronald Crond2c53e62021-09-13 09:38:05 +02001951component_test_psa_crypto_config_accel_ecdsa () {
1952 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1953
1954 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1955 # partial support for cipher operations in the driver test library.
1956 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1957 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Gilles Peskine62de7672022-04-21 11:05:16 +02001958 # Disable obsolete hashes (alternatively we could enable support for them
1959 # in the driver test library).
1960 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
1961 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
Ronald Crond2c53e62021-09-13 09:38:05 +02001962
1963 # SHA384 needed for some ECDSA signature tests.
1964 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
1965
1966 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA KEY_TYPE_ECC_KEY_PAIR KEY_TYPE_ECC_PUBLIC_KEY"
1967 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
1968 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
1969
1970 # Restore test driver base configuration
1971 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
1972
1973 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
1974 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
1975 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1976 scripts/config.py unset MBEDTLS_ECDSA_C
1977 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1978 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1979
1980 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
1981 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"
1982
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01001983 not grep mbedtls_ecdsa_ library/ecdsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02001984
1985 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
1986 make test
1987}
1988
1989component_test_psa_crypto_config_accel_rsa_signature () {
1990 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
1991
1992 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
1993 # partial support for cipher operations in the driver test library.
1994 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
1995 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
1996
1997 # It seems it is not possible to remove only the support for RSA signature
1998 # in the library. Thus we have to remove all RSA support (signature and
1999 # encryption/decryption). AS there is no driver support for asymmetric
2000 # encryption/decryption so far remove RSA encryption/decryption from the
2001 # application algorithm list.
2002 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2003 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2004
2005 # Make sure both the library and the test library support the SHA hash
2006 # algorithms and only those ones (SHA256 is included by default). That way:
2007 # - the test library can compute the RSA signatures even in the case of a
2008 # composite RSA signature algorithm based on a SHA hash (no other hash
2009 # used in the unit tests).
2010 # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
2011 # fulfilled as the hash SHA algorithm is supported by the library, and
2012 # thus the tests are run, not skipped.
2013 # - when testing a signature key with an algorithm wildcard built from
2014 # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
2015 # algorithm based on the hashes supported by the library is also
2016 # supported by the test library.
2017 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2018 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2019 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2020 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160_C
2021
2022 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA1_C
2023 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_SHA512_C
2024 # We need PEM parsing in the test library as well to support the import
2025 # of PEM encoded RSA keys.
2026 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_PEM_PARSE_C
2027 scripts/config.py -f tests/include/test/drivers/config_test_driver.h set MBEDTLS_BASE64_C
2028
2029 loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
2030 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2031 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2032
2033 # Restore test driver base configuration
2034 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA1_C
2035 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_SHA512_C
2036 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_PEM_PARSE_C
2037 scripts/config.py -f tests/include/test/drivers/config_test_driver.h unset MBEDTLS_BASE64_C
2038
2039
2040 # Mbed TLS library build
2041 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2042 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2043
2044 # Remove RSA support and its dependencies
2045 scripts/config.py unset MBEDTLS_PKCS1_V15
2046 scripts/config.py unset MBEDTLS_PKCS1_V21
2047 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2048 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2049 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2050 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2051 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2052 scripts/config.py unset MBEDTLS_RSA_C
2053 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2054
2055 scripts/config.py unset MBEDTLS_MD2_C
2056 scripts/config.py unset MBEDTLS_MD4_C
2057 scripts/config.py unset MBEDTLS_MD5_C
2058 scripts/config.py unset MBEDTLS_RIPEMD160_C
2059 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
2060 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
2061 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
2062
2063 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2064 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2065
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002066 not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
2067 not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
Ronald Crond2c53e62021-09-13 09:38:05 +02002068
2069 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
2070 make test
2071}
2072
Ronald Cronf7e483c2021-05-08 14:32:59 +02002073component_test_psa_crypto_config_accel_hash () {
2074 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2075
2076 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
2077 # partial support for cipher operations in the driver test library.
2078 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2079 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
2080
2081 loc_accel_list="ALG_MD4 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
2082 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2083 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2084
2085 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2086 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2087 scripts/config.py unset MBEDTLS_MD2_C
2088 scripts/config.py unset MBEDTLS_MD4_C
2089 scripts/config.py unset MBEDTLS_MD5_C
2090 scripts/config.py unset MBEDTLS_RIPEMD160_C
2091 scripts/config.py unset MBEDTLS_SHA1_C
2092 # Don't unset MBEDTLS_SHA256_C as it is needed by PSA crypto core.
2093 scripts/config.py unset MBEDTLS_SHA512_C
2094 # Unset MBEDTLS_SSL_PROTO_SSL3, MBEDTLS_SSL_PROTO_TLS1 and MBEDTLS_SSL_PROTO_TLS1_1 as they depend on MBEDTLS_SHA1_C
2095 scripts/config.py unset MBEDTLS_SSL_PROTO_SSL3
2096 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1
2097 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_1
2098 # Unset MBEDTLS_SSL_CBC_RECORD_SPLITTING as it depends on MBEDTLS_SSL_PROTO_TLS1 in the default configuration.
2099 scripts/config.py unset MBEDTLS_SSL_CBC_RECORD_SPLITTING
2100 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2101 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2102
Gilles Peskined4c5c3d2022-02-04 00:30:54 +01002103 not grep mbedtls_sha512_init library/sha512.o
2104 not grep mbedtls_sha1_init library/sha1.o
Ronald Cronf7e483c2021-05-08 14:32:59 +02002105
2106 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2107 make test
2108}
2109
Ronald Cron09623702021-10-18 11:26:01 +02002110component_test_psa_crypto_config_accel_cipher () {
2111 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
2112
Gilles Peskine186331872022-04-12 15:58:03 +02002113 # This test case focuses on cipher+AEAD. We don't yet support all
2114 # combinations of configurations, so deactivate block-cipher-based MACs.
2115 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_CMAC
2116
Ronald Cron09623702021-10-18 11:26:01 +02002117 loc_accel_list="ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB ALG_OFB ALG_XTS KEY_TYPE_DES"
2118 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2119 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2120
2121 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2122 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2123
2124 # There is no intended accelerator support for ALG STREAM_CIPHER and
2125 # ALG_ECB_NO_PADDING. Therefore, asking for them in the build implies the
2126 # inclusion of the Mbed TLS cipher operations. As we want to test here with
2127 # cipher operations solely supported by accelerators, disabled those
2128 # PSA configuration options.
2129 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2130 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
Ronald Cron09623702021-10-18 11:26:01 +02002131
2132 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2133 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
2134 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
2135 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
2136 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
2137 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
2138 scripts/config.py unset MBEDTLS_DES_C
2139
2140 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2141 make CFLAGS="$ASAN_CFLAGS -Werror -I../tests/include -I../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS"
2142
Gilles Peskine82143402024-06-19 15:09:27 +02002143 not grep mbedtls_des library/des.o
Ronald Cron09623702021-10-18 11:26:01 +02002144
2145 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
2146 make test
2147}
2148
Przemek Stekiel8b56f232022-10-02 20:58:39 +02002149component_test_psa_crypto_config_accel_aead () {
2150 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2151
2152 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
2153 # partial support for cipher operations in the driver test library.
2154 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_STREAM_CIPHER
2155 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_ECB_NO_PADDING
2156
2157 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
2158 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
2159 make -C tests libtestdriver1.a CFLAGS="$ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
2160
2161 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2162 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2163
2164 scripts/config.py unset MBEDTLS_GCM_C
2165 scripts/config.py unset MBEDTLS_CCM_C
2166 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2167 # Features that depend on AEAD
2168 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
2169 scripts/config.py unset MBEDTLS_SSL_TICKET_C
2170
2171 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
2172 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"
2173
2174 # There's a risk of something getting re-enabled via config_psa.h
2175 # make sure it did not happen.
2176 not grep mbedtls_ccm library/ccm.o
2177 not grep mbedtls_gcm library/gcm.o
2178 not grep mbedtls_chachapoly library/chachapoly.o
2179
2180 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
2181 make test
2182}
2183
John Durkop4377bf72020-10-23 01:26:57 -07002184component_test_psa_crypto_config_no_driver() {
John Durkop4377bf72020-10-23 01:26:57 -07002185 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
2186 scripts/config.py full
2187 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2188 scripts/config.py unset MBEDTLS_PSA_CRYPTO_DRIVERS
2189 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkope7012c72020-10-26 09:55:01 -07002190 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop4377bf72020-10-23 01:26:57 -07002191
2192 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG minus MBEDTLS_PSA_CRYPTO_DRIVERS"
John Durkopd8959392020-09-20 23:09:17 -07002193 make test
2194}
2195
Gilles Peskined4c85af2023-07-20 22:19:45 +02002196component_test_aead_chachapoly_disabled() {
2197 msg "build: full minus CHACHAPOLY"
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002198 scripts/config.py full
2199 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Gilles Peskined4c85af2023-07-20 22:19:45 +02002200 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002201 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
2202
Gilles Peskined4c85af2023-07-20 22:19:45 +02002203 msg "test: full minus CHACHAPOLY"
2204 make test
2205}
2206
2207component_test_aead_only_ccm() {
2208 msg "build: full minus CHACHAPOLY and GCM"
2209 scripts/config.py full
2210 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
2211 scripts/config.py unset MBEDTLS_GCM_C
2212 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
2213 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
2214 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
2215
2216 msg "test: full minus CHACHAPOLY and GCM"
Przemyslaw Stekiel7ce979a2021-10-13 11:09:44 +02002217 make test
2218}
2219
John Durkopd0321952020-10-29 21:37:36 -07002220# 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 -08002221component_build_psa_accel_alg_ecdh() {
Gilles Peskine168be012023-07-19 19:36:55 +02002222 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
John Durkopd0321952020-10-29 21:37:36 -07002223 scripts/config.py full
2224 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2225 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2226 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2227 scripts/config.py unset MBEDTLS_ECDH_C
2228 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2229 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2230 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2231 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2232 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2233 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2234 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2235}
2236
John Durkopf4c4cb02020-10-28 20:09:55 -07002237# 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 -08002238component_build_psa_accel_key_type_ecc_key_pair() {
Gilles Peskine168be012023-07-19 19:36:55 +02002239 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR"
John Durkopf4c4cb02020-10-28 20:09:55 -07002240 scripts/config.py full
2241 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2242 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2243 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002244 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 -08002245 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 -07002246 # 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 -08002247 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 -07002248}
2249
2250# 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 -08002251component_build_psa_accel_key_type_ecc_public_key() {
Gilles Peskine168be012023-07-19 19:36:55 +02002252 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
John Durkopf4c4cb02020-10-28 20:09:55 -07002253 scripts/config.py full
2254 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2255 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2256 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkop9814fa22020-11-04 12:28:15 -08002257 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
2258 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR
John Durkopf4c4cb02020-10-28 20:09:55 -07002259 # 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 -08002260 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 -07002261}
2262
John Durkopd0321952020-10-29 21:37:36 -07002263# 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 -08002264component_build_psa_accel_alg_hmac() {
Gilles Peskine168be012023-07-19 19:36:55 +02002265 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
John Durkopd0321952020-10-29 21:37:36 -07002266 scripts/config.py full
2267 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2268 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2269 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2270 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2271 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2272}
2273
2274# 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 -08002275component_build_psa_accel_alg_hkdf() {
Gilles Peskine168be012023-07-19 19:36:55 +02002276 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
John Durkopd0321952020-10-29 21:37:36 -07002277 scripts/config.py full
2278 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2279 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2280 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2281 scripts/config.py unset MBEDTLS_HKDF_C
John Durkopbd069d32020-10-31 22:14:03 -07002282 # Make sure to unset TLS1_3_EXPERIMENTAL since it requires HKDF_C and will not build properly without it.
2283 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
John Durkopd0321952020-10-29 21:37:36 -07002284 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2285 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2286}
2287
John Durkop1b7ee052020-11-27 08:51:22 -08002288# This should be renamed to test and updated once the accelerator MD2 code is in place and ready to test.
2289component_build_psa_accel_alg_md2() {
Gilles Peskine168be012023-07-19 19:36:55 +02002290 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD2 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002291 scripts/config.py full
2292 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2293 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2294 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2295 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2296 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2297 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2298 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2299 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2300 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2301 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2302 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2303 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2304 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD2 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2305}
2306
2307# This should be renamed to test and updated once the accelerator MD4 code is in place and ready to test.
2308component_build_psa_accel_alg_md4() {
Gilles Peskine168be012023-07-19 19:36:55 +02002309 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD4 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002310 scripts/config.py full
2311 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2312 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2313 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2314 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2315 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2316 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2317 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2318 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2319 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2320 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2321 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2322 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2323 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD4 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2324}
2325
2326# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
2327component_build_psa_accel_alg_md5() {
Gilles Peskine168be012023-07-19 19:36:55 +02002328 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002329 scripts/config.py full
2330 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2331 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2332 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2333 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2334 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2335 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2336 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2337 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2338 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2339 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2340 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2341 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2342 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2343}
2344
2345# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
2346component_build_psa_accel_alg_ripemd160() {
Gilles Peskine168be012023-07-19 19:36:55 +02002347 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002348 scripts/config.py full
2349 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2350 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2351 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2352 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2353 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2354 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2355 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2356 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2357 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2358 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2359 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2360 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2361 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2362}
2363
2364# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
2365component_build_psa_accel_alg_sha1() {
Gilles Peskine168be012023-07-19 19:36:55 +02002366 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002367 scripts/config.py full
2368 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2369 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2370 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2371 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2372 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2373 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2374 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2375 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2376 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2377 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2378 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2379 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2380 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2381}
2382
2383# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
2384component_build_psa_accel_alg_sha224() {
Gilles Peskine168be012023-07-19 19:36:55 +02002385 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002386 scripts/config.py full
2387 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2388 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2389 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2390 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2391 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2392 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2393 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2394 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2395 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2396 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2397 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2398 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2399}
2400
2401# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
2402component_build_psa_accel_alg_sha256() {
Gilles Peskine168be012023-07-19 19:36:55 +02002403 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002404 scripts/config.py full
2405 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2406 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2407 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2408 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2409 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2410 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2411 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2412 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2413 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2414 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2415 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_512
2416 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2417 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2418}
2419
2420# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
2421component_build_psa_accel_alg_sha384() {
Gilles Peskine168be012023-07-19 19:36:55 +02002422 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002423 scripts/config.py full
2424 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2425 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2426 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2427 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2428 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2429 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2430 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2431 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2432 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2433 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2434 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2435 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2436}
2437
2438# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
2439component_build_psa_accel_alg_sha512() {
Gilles Peskine168be012023-07-19 19:36:55 +02002440 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08002441 scripts/config.py full
2442 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2443 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2444 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2445 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD2
2446 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD4
2447 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_MD5
2448 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RIPEMD160
2449 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_1
2450 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_224
2451 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_256
2452 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_SHA_384
2453 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2454 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2455}
2456
John Durkopd0321952020-10-29 21:37:36 -07002457# 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 -08002458component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
Gilles Peskine168be012023-07-19 19:36:55 +02002459 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 -07002460 scripts/config.py full
2461 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2462 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2463 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
John Durkopbd069d32020-10-31 22:14:03 -07002464 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002465 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2466 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2467 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07002468 # 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 -07002469 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2470}
2471
2472# 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 -08002473component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
Gilles Peskine168be012023-07-19 19:36:55 +02002474 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 -07002475 scripts/config.py full
2476 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2477 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2478 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2479 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002480 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2481 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
2482 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002483 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2484 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2485}
2486
2487# 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 -08002488component_build_psa_accel_alg_rsa_oaep() {
Gilles Peskine168be012023-07-19 19:36:55 +02002489 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 -07002490 scripts/config.py full
2491 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2492 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2493 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2494 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_OAEP 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002495 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2496 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2497 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07002498 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2499 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2500}
2501
2502# 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 -08002503component_build_psa_accel_alg_rsa_pss() {
Gilles Peskine168be012023-07-19 19:36:55 +02002504 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 -07002505 scripts/config.py full
2506 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2507 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2508 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2509 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
John Durkop7fc75ea2020-11-03 19:05:36 -08002510 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
2511 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
2512 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07002513 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2514 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
2515}
2516
2517# 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 -08002518component_build_psa_accel_key_type_rsa_key_pair() {
Gilles Peskine168be012023-07-19 19:36:55 +02002519 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 -07002520 scripts/config.py full
2521 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2522 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2523 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2524 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2525 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR 1
2526 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2527 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"
2528}
2529
2530# 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 -08002531component_build_psa_accel_key_type_rsa_public_key() {
Gilles Peskine168be012023-07-19 19:36:55 +02002532 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 -07002533 scripts/config.py full
2534 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2535 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
2536 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2537 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_ALG_RSA_PSS 1
2538 scripts/config.py -f include/psa/crypto_config.h set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
2539 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
2540 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 -07002541}
2542
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002543component_test_check_params_functionality () {
2544 msg "build+test: MBEDTLS_CHECK_PARAMS functionality"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002545 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002546 # Make MBEDTLS_PARAM_FAILED call mbedtls_param_failed().
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002547 scripts/config.py unset MBEDTLS_CHECK_PARAMS_ASSERT
Ronald Crona1236142020-07-01 16:01:21 +02002548 make CC=gcc CFLAGS='-Werror -O1' all test
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002549}
2550
Gilles Peskineb28636b2019-01-02 19:06:24 +01002551component_test_check_params_without_platform () {
2552 msg "build+test: MBEDTLS_CHECK_PARAMS without MBEDTLS_PLATFORM_C"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002553 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002554 # Keep MBEDTLS_PARAM_FAILED as assert.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002555 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
2556 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
2557 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
2558 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
Gilles Peskine32e889d2020-04-12 23:43:28 +02002559 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002560 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
2561 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskine9c764bf2022-09-18 14:05:23 +02002562 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002563 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
2564 scripts/config.py unset MBEDTLS_PLATFORM_C
Gilles Peskineb28636b2019-01-02 19:06:24 +01002565 make CC=gcc CFLAGS='-Werror -O1' all test
2566}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002567
Gilles Peskineb28636b2019-01-02 19:06:24 +01002568component_test_check_params_silent () {
2569 msg "build+test: MBEDTLS_CHECK_PARAMS with alternative MBEDTLS_PARAM_FAILED()"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002570 scripts/config.py full # includes CHECK_PARAMS
Gilles Peskineadcde5e2019-06-12 16:05:50 +02002571 # Set MBEDTLS_PARAM_FAILED to nothing.
Gilles Peskineb28636b2019-01-02 19:06:24 +01002572 sed -i 's/.*\(#define MBEDTLS_PARAM_FAILED( cond )\).*/\1/' "$CONFIG_H"
2573 make CC=gcc CFLAGS='-Werror -O1' all test
2574}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002575
Dave Rodgman173227d2023-06-29 09:29:00 +01002576component_build_aes_variations() { # ~45s
2577 msg "build: aes.o for all combinations of relevant config options"
Dave Rodgmanbf998282023-06-29 12:10:45 +01002578
Dave Rodgman173227d2023-06-29 09:29:00 +01002579 for a in set unset; do
2580 for b in set unset; do
2581 for c in set unset; do
2582 for d in set unset; do
2583 for e in set unset; do
2584 for f in set unset; do
2585 for g in set unset; do
Dave Rodgmanbf998282023-06-29 12:10:45 +01002586 echo ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
2587 echo ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
2588 echo ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
2589 echo ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
2590 echo ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
2591 echo ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
2592 echo ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman173227d2023-06-29 09:29:00 +01002593
Dave Rodgmanbf998282023-06-29 12:10:45 +01002594 ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
2595 ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
2596 ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
2597 ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
2598 ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
2599 ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
2600 ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman173227d2023-06-29 09:29:00 +01002601
Dave Rodgmanbf998282023-06-29 12:10:45 +01002602 rm -f library/aes.o
2603 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 +01002604 done
2605 done
2606 done
2607 done
2608 done
2609 done
2610 done
2611}
2612
Gilles Peskine8f073122018-11-27 15:58:47 +01002613component_test_no_platform () {
2614 # Full configuration build, without platform support, file IO and net sockets.
2615 # This should catch missing mbedtls_printf definitions, and by disabling file
2616 # IO, it should catch missing '#include <stdio.h>'
2617 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Paul Elliott68050372023-11-03 19:24:56 +00002618 scripts/config.py full_no_platform
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002619 scripts/config.py unset MBEDTLS_PLATFORM_C
2620 scripts/config.py unset MBEDTLS_NET_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002621 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002622 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002623 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
2624 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Paul Elliott68050372023-11-03 19:24:56 +00002625 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine8f073122018-11-27 15:58:47 +01002626 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
2627 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002628 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
2629 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01002630}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00002631
Gilles Peskine8f073122018-11-27 15:58:47 +01002632component_build_no_std_function () {
2633 # catch compile bugs in _uninit functions
2634 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002635 scripts/config.py full
2636 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
2637 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002638 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine31fdda12021-10-08 11:45:47 +02002639 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskine25319702021-10-07 19:34:57 +02002640 make
Gilles Peskine8f073122018-11-27 15:58:47 +01002641}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01002642
Gilles Peskine8f073122018-11-27 15:58:47 +01002643component_build_no_ssl_srv () {
2644 msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002645 scripts/config.py full
2646 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002647 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002648}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002649
Gilles Peskine8f073122018-11-27 15:58:47 +01002650component_build_no_ssl_cli () {
2651 msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002652 scripts/config.py full
2653 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002654 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01002655}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02002656
Gilles Peskine8f073122018-11-27 15:58:47 +01002657component_build_no_sockets () {
2658 # Note, C99 compliance can also be tested with the sockets support disabled,
2659 # as that requires a POSIX platform (which isn't the same as C99).
2660 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002661 scripts/config.py full
2662 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
2663 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02002664 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01002665}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02002666
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002667component_test_memory_buffer_allocator_backtrace () {
2668 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002669 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2670 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2671 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
2672 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Dave Rodgman374b1882024-01-04 10:30:57 +00002673 cmake -DCMAKE_BUILD_TYPE:String=Release .
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04002674 make
2675
2676 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
2677 make test
2678}
2679
2680component_test_memory_buffer_allocator () {
2681 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002682 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2683 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Dave Rodgman374b1882024-01-04 10:30:57 +00002684 cmake -DCMAKE_BUILD_TYPE:String=Release .
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002685 make
2686
2687 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2688 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01002689
2690 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
2691 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002692 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00002693}
2694
Gilles Peskine8f073122018-11-27 15:58:47 +01002695component_test_no_max_fragment_length () {
2696 # Run max fragment length tests with MFL disabled
2697 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002698 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01002699 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2700 make
Hanno Becker5175ac62017-09-18 15:36:25 +01002701
Gilles Peskine8f073122018-11-27 15:58:47 +01002702 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002703 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01002704}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00002705
Hanno Becker545ced42019-02-19 11:10:48 +00002706component_test_asan_remove_peer_certificate () {
2707 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002708 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00002709 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2710 make
2711
2712 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
2713 make test
2714
2715 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002716 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002717
2718 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002719 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002720
2721 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002722 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00002723}
2724
Gilles Peskine8f073122018-11-27 15:58:47 +01002725component_test_no_max_fragment_length_small_ssl_out_content_len () {
2726 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002727 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2728 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
2729 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01002730 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2731 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10002732
Gilles Peskine8f073122018-11-27 15:58:47 +01002733 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002734 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02002735
2736 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002737 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002738}
Angus Grattonc4dd0732018-04-11 16:28:39 +10002739
Darryl Greenaad82f92019-12-02 10:53:11 +00002740component_test_variable_ssl_in_out_buffer_len () {
2741 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
2742 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2743 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2744 make
2745
2746 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
2747 make test
2748
2749 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002750 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002751
2752 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002753 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002754}
2755
2756component_test_variable_ssl_in_out_buffer_len_CID () {
2757 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled (ASan build)"
2758 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2759 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID
2760
2761 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2762 make
2763
2764 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID"
2765 make test
2766
2767 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002768 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002769
2770 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_DTLS_CONNECTION_ID enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002771 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002772}
2773
2774component_test_variable_ssl_in_out_buffer_len_record_splitting () {
2775 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled (ASan build)"
2776 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
2777 scripts/config.py set MBEDTLS_SSL_CBC_RECORD_SPLITTING
2778
2779 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2780 make
2781
2782 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING"
2783 make test
2784
2785 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002786 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002787
2788 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH and MBEDTLS_SSL_CBC_RECORD_SPLITTING enabled"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002789 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00002790}
2791
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002792component_test_ssl_alloc_buffer_and_mfl () {
2793 msg "build: default config with memory buffer allocator and MFL extension"
2794 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
2795 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2796 scripts/config.py set MBEDTLS_MEMORY_DEBUG
2797 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
2798 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
Dave Rodgman374b1882024-01-04 10:30:57 +00002799 cmake -DCMAKE_BUILD_TYPE:String=Release .
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002800 make
2801
2802 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
2803 make test
2804
2805 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 +02002806 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01002807}
2808
Gilles Peskine636c26a2020-03-04 20:46:15 +01002809component_test_when_no_ciphersuites_have_mac () {
2810 msg "build: when no ciphersuites have MAC"
2811 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
2812 scripts/config.py unset MBEDTLS_ARC4_C
2813 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
2814 make
2815
2816 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
2817 make test
2818
2819 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002820 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01002821}
2822
Gilles Peskine8f073122018-11-27 15:58:47 +01002823component_test_null_entropy () {
2824 msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002825 scripts/config.py set MBEDTLS_TEST_NULL_ENTROPY
2826 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
2827 scripts/config.py set MBEDTLS_ENTROPY_C
2828 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02002829 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002830 scripts/config.py unset MBEDTLS_ENTROPY_HARDWARE_ALT
2831 scripts/config.py unset MBEDTLS_HAVEGE_C
Gilles Peskine5fa32a72019-01-06 19:48:30 +00002832 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON .
Gilles Peskine8f073122018-11-27 15:58:47 +01002833 make
Janos Follath06c54002016-06-09 13:57:40 +01002834
Gilles Peskine8f073122018-11-27 15:58:47 +01002835 msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)"
2836 make test
2837}
Janos Follath06c54002016-06-09 13:57:40 +01002838
Raoul Strackxa4e86142020-06-15 17:03:13 +02002839component_test_no_date_time () {
2840 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
2841 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
Gilles Peskine31fdda12021-10-08 11:45:47 +02002842 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Raoul Strackxa4e86142020-06-15 17:03:13 +02002843 make
2844
2845 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
2846 make test
2847}
2848
Andrzej Kurekc890b222023-01-17 04:03:19 -05002849component_test_alt_timing() {
2850 msg "build: alternate timing implementation"
2851 scripts/config.py set MBEDTLS_TIMING_ALT
2852 make lib TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
2853
2854 msg "test: MBEDTLS_TIMING_ALT - test suites"
2855 make test TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../tests/src/external_timing"
Andrzej Kurek3a261a42023-01-26 04:33:59 -05002856
2857 msg "selftest - MBEDTLS-TIMING_ALT"
2858 make programs TEST_TIMING_ALT_IMPL=1 CFLAGS="-I../../tests/src/external_timing -I../tests/src/external_timing"
2859 programs/test/selftest
Andrzej Kurekc890b222023-01-17 04:03:19 -05002860}
2861
Gilles Peskine8f073122018-11-27 15:58:47 +01002862component_test_platform_calloc_macro () {
2863 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002864 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
2865 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
2866 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01002867 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2868 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01002869
Gilles Peskine8f073122018-11-27 15:58:47 +01002870 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
2871 make test
2872}
Hanno Beckere5fecec2018-10-11 11:02:52 +01002873
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002874component_test_malloc_0_null () {
2875 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01002876 scripts/config.py full
Gilles Peskine2e70f1c2023-07-20 19:00:15 +02002877 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 +02002878
2879 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
2880 make test
2881
2882 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
2883 # Just the calloc selftest. "make test" ran the others as part of the
2884 # test suites.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002885 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01002886
2887 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
2888 # Run a subset of the tests. The choice is a balance between coverage
2889 # and time (including time indirectly wasted due to flaky tests).
2890 # The current choice is to skip tests whose description includes
2891 # "proxy", which is an approximation of skipping tests that use the
2892 # UDP proxy, which tend to be slower and flakier.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02002893 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02002894}
2895
Gilles Peskine8f073122018-11-27 15:58:47 +01002896component_test_aes_fewer_tables () {
2897 msg "build: default config with AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002898 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Dave Rodgmance04f242024-01-04 10:34:31 +00002899 make CFLAGS='-O2 -Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002900
Gilles Peskine8f073122018-11-27 15:58:47 +01002901 msg "test: AES_FEWER_TABLES"
2902 make test
2903}
Hanno Becker83ebf782017-07-07 12:29:15 +01002904
Gilles Peskine8f073122018-11-27 15:58:47 +01002905component_test_aes_rom_tables () {
2906 msg "build: default config with AES_ROM_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002907 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_ROM_TABLES"
2911 make test
2912}
Hanno Becker83ebf782017-07-07 12:29:15 +01002913
Gilles Peskine8f073122018-11-27 15:58:47 +01002914component_test_aes_fewer_tables_and_rom_tables () {
2915 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002916 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
2917 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Dave Rodgmance04f242024-01-04 10:34:31 +00002918 make CFLAGS='-O2 -Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01002919
Gilles Peskine8f073122018-11-27 15:58:47 +01002920 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
2921 make test
2922}
2923
Gilles Peskine592f5912019-10-07 18:49:32 +02002924component_test_ctr_drbg_aes_256_sha_256 () {
2925 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002926 scripts/config.py full
2927 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2928 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002929 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2930 make
2931
2932 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2933 make test
2934}
2935
2936component_test_ctr_drbg_aes_128_sha_512 () {
2937 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002938 scripts/config.py full
2939 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2940 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskine592f5912019-10-07 18:49:32 +02002941 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2942 make
2943
2944 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
2945 make test
2946}
2947
2948component_test_ctr_drbg_aes_128_sha_256 () {
2949 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01002950 scripts/config.py full
2951 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
2952 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
2953 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskine592f5912019-10-07 18:49:32 +02002954 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
2955 make
2956
2957 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
2958 make test
2959}
2960
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002961component_test_se_default () {
2962 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002963 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02002964 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02002965
2966 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
2967 make test
2968}
2969
Steven Cooremand57203d2020-07-16 20:28:59 +02002970component_test_psa_crypto_drivers () {
Gilles Peskine8d77ec22023-07-26 18:45:20 +02002971 msg "build: full + test drivers dispatching to builtins"
Steven Cooreman753f9732021-03-15 11:38:44 +01002972 scripts/config.py full
Steven Cooremand57203d2020-07-16 20:28:59 +02002973 scripts/config.py set MBEDTLS_PSA_CRYPTO_DRIVERS
Gilles Peskinefe0acc62021-09-20 19:20:04 +02002974 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
2975 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
Ronald Cron17b3afc2020-12-10 18:17:09 +01002976 loc_cflags="${loc_cflags} -I../tests/include -O2"
2977
2978 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
Steven Cooremand57203d2020-07-16 20:28:59 +02002979
Gilles Peskine8d77ec22023-07-26 18:45:20 +02002980 msg "test: full + test drivers dispatching to builtins"
Steven Cooremand57203d2020-07-16 20:28:59 +02002981 make test
2982}
2983
Gilles Peskine8f073122018-11-27 15:58:47 +01002984component_test_make_shared () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01002985 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04002986 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02002987 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine27482f12021-11-04 12:52:14 +01002988 programs/test/dlopen_demo.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01002989}
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02002990
Gilles Peskinecf740502019-07-03 20:43:05 +02002991component_test_cmake_shared () {
2992 msg "build/test: cmake shared" # ~ 2min
2993 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
2994 make
Gilles Peskine56c01612019-07-03 20:43:32 +02002995 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02002996 make test
Gilles Peskine27482f12021-11-04 12:52:14 +01002997 programs/test/dlopen_demo.sh
Gilles Peskinecf740502019-07-03 20:43:05 +02002998}
2999
Gilles Peskineec10bf12019-09-20 19:56:06 +02003000test_build_opt () {
3001 info=$1 cc=$2; shift 2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003002 $cc --version
Gilles Peskineec10bf12019-09-20 19:56:06 +02003003 for opt in "$@"; do
3004 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskinee094a182020-04-14 20:08:41 +02003005 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02003006 # We're confident enough in compilers to not run _all_ the tests,
3007 # but at least run the unit tests. In particular, runs with
3008 # optimizations use inline assembly whereas runs with -O0
3009 # skip inline assembly.
3010 make test # ~30s
3011 make clean
3012 done
3013}
3014
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003015# For FreeBSD we invoke the function by name so this condition is added
3016# to disable the existing test_clang_opt function for linux.
3017if [[ $(uname) != "Linux" ]]; then
3018 component_test_clang_opt () {
3019 scripts/config.py full
3020 test_build_opt 'full config' clang -O0 -Os -O2
3021 }
3022fi
3023
3024component_test_clang_latest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01003025 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003026 test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003027}
3028support_test_clang_latest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003029 type "$CLANG_LATEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02003030}
3031
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003032component_test_clang_earliest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01003033 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003034 test_build_opt 'full config' "$CLANG_EARLIEST" -O0
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003035}
3036support_test_clang_earliest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003037 type "$CLANG_EARLIEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003038}
3039
3040component_test_gcc_latest_opt () {
3041 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003042 test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003043}
3044support_test_gcc_latest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003045 type "$GCC_LATEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003046}
3047
3048component_test_gcc_earliest_opt () {
3049 scripts/config.py full
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003050 test_build_opt 'full config' "$GCC_EARLIEST" -O0
Gowtham Suresh Kumar1e3af242023-07-19 08:39:20 +01003051}
3052support_test_gcc_earliest_opt () {
Gowtham Suresh Kumar2afb24f2023-08-01 09:45:57 +01003053 type "$GCC_EARLIEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02003054}
3055
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02003056component_build_mbedtls_config_file () {
3057 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
Gilles Peskine6af9dc92022-04-07 20:55:57 +02003058 scripts/config.py -w full_config.h full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02003059 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
3060 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02003061 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine036a9bb2022-04-07 21:06:41 +02003062 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3063 make clean
3064
3065 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
3066 # In the user config, disable one feature (for simplicity, pick a feature
3067 # that nothing else depends on).
3068 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3069 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
3070 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3071
3072 rm -f user_config.h full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003073}
3074
Gilles Peskine690a2ef2022-04-07 21:59:14 +02003075component_build_psa_config_file () {
3076 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
3077 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3078 cp "$CRYPTO_CONFIG_H" psa_test_config.h
3079 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
3080 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Gilles Peskine932b30b2022-04-13 23:23:21 +02003081 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine690a2ef2022-04-07 21:59:14 +02003082 programs/test/query_compile_time_config MBEDTLS_CMAC_C
3083 make clean
3084
3085 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
3086 # In the user config, disable one feature, which will reflect on the
3087 # mbedtls configuration so we can query it with query_compile_time_config.
3088 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
3089 scripts/config.py unset MBEDTLS_CMAC_C
3090 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
3091 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
3092
3093 rm -f psa_test_config.h psa_user_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003094}
3095
Gilles Peskine8f073122018-11-27 15:58:47 +01003096component_test_m32_o0 () {
Gilles Peskinea0c51fb2021-10-07 19:27:16 +02003097 # Build without optimization, so as to use portable C code (in a 32-bit
3098 # build) and not the i386-specific inline assembly.
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003099 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003100 scripts/config.py full
Gilles Peskine8fd59422019-10-21 17:11:33 +02003101 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01003102
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003103 msg "test: i386, make, gcc -O0 (ASan build)"
3104 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01003105}
Gilles Peskine878cf602019-01-06 20:50:38 +00003106support_test_m32_o0 () {
3107 case $(uname -m) in
Pengyu Lva89b3672022-10-21 10:50:26 +00003108 amd64|x86_64) true;;
Gilles Peskine878cf602019-01-06 20:50:38 +00003109 *) false;;
3110 esac
3111}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003112
Gilles Peskine6fa69862021-10-05 09:36:03 +02003113component_test_m32_o2 () {
3114 # Build with optimization, to use the i386 specific inline assembly
3115 # and go faster for tests.
3116 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003117 scripts/config.py full
Gilles Peskine6fa69862021-10-05 09:36:03 +02003118 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01003119
Gilles Peskine6fa69862021-10-05 09:36:03 +02003120 msg "test: i386, make, gcc -O2 (ASan build)"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003121 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003122
Gilles Peskine6fa69862021-10-05 09:36:03 +02003123 msg "test ssl-opt.sh, i386, make, gcc-O2"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003124 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003125}
Gilles Peskine3daa83e2021-10-07 19:25:29 +02003126support_test_m32_o2 () {
Gilles Peskine878cf602019-01-06 20:50:38 +00003127 support_test_m32_o0 "$@"
3128}
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003129
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003130component_test_m32_everest () {
3131 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003132 scripts/config.py unset MBEDTLS_ECDH_LEGACY_CONTEXT
3133 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Gilles Peskine8fd59422019-10-21 17:11:33 +02003134 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003135
3136 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
3137 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003138
3139 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003140 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01003141
3142 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
3143 # Exclude some symmetric ciphers that are redundant here to gain time.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003144 tests/compat.sh -f ECDH -V NO -e 'ARCFOUR\|ARIA\|CAMELLIA\|CHACHA\|DES\|RC4'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02003145}
3146support_test_m32_everest () {
3147 support_test_m32_o0 "$@"
3148}
3149
Gilles Peskine8f073122018-11-27 15:58:47 +01003150component_test_mx32 () {
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003151 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003152 scripts/config.py full
Dave Rodgmance04f242024-01-04 10:34:31 +00003153 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01003154
3155 msg "test: 64-bit ILP32, make, gcc"
3156 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01003157}
Gilles Peskine878cf602019-01-06 20:50:38 +00003158support_test_mx32 () {
3159 case $(uname -m) in
3160 amd64|x86_64) true;;
3161 *) false;;
3162 esac
3163}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003164
Peter Kolbus60c6da22018-12-27 06:59:04 -06003165component_test_min_mpi_window_size () {
3166 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003167 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06003168 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3169 make
3170
3171 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
3172 make test
3173}
3174
Gilles Peskine8f073122018-11-27 15:58:47 +01003175component_test_have_int32 () {
3176 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003177 scripts/config.py unset MBEDTLS_HAVE_ASM
3178 scripts/config.py unset MBEDTLS_AESNI_C
3179 scripts/config.py unset MBEDTLS_PADLOCK_C
Dave Rodgmance04f242024-01-04 10:34:31 +00003180 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01003181
Gilles Peskine8f073122018-11-27 15:58:47 +01003182 msg "test: gcc, force 32-bit bignum limbs"
3183 make test
3184}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01003185
Gilles Peskine8f073122018-11-27 15:58:47 +01003186component_test_have_int64 () {
3187 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003188 scripts/config.py unset MBEDTLS_HAVE_ASM
3189 scripts/config.py unset MBEDTLS_AESNI_C
3190 scripts/config.py unset MBEDTLS_PADLOCK_C
Dave Rodgmance04f242024-01-04 10:34:31 +00003191 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01003192
Gilles Peskine8f073122018-11-27 15:58:47 +01003193 msg "test: gcc, force 64-bit bignum limbs"
3194 make test
3195}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003196
Gilles Peskine8f073122018-11-27 15:58:47 +01003197component_test_no_udbl_division () {
3198 msg "build: MBEDTLS_NO_UDBL_DIVISION 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_UDBL_DIVISION
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_UDBL_DIVISION native" # ~ 10s
3204 make test
3205}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003206
Gilles Peskine8f073122018-11-27 15:58:47 +01003207component_test_no_64bit_multiplication () {
3208 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003209 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003210 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01003211 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003212
Gilles Peskine8f073122018-11-27 15:58:47 +01003213 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
3214 make test
3215}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003216
Gilles Peskine3809f5f2020-11-09 15:40:05 +01003217component_test_no_strings () {
3218 msg "build: no strings" # ~10s
3219 scripts/config.py full
3220 # Disable options that activate a large amount of string constants.
3221 scripts/config.py unset MBEDTLS_DEBUG_C
3222 scripts/config.py unset MBEDTLS_ERROR_C
3223 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
3224 scripts/config.py unset MBEDTLS_VERSION_FEATURES
3225 make CFLAGS='-Werror -Os'
3226
3227 msg "test: no strings" # ~ 10s
3228 make test
3229}
3230
Gilles Peskine8f073122018-11-27 15:58:47 +01003231component_build_arm_none_eabi_gcc () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003232 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003233 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02003234 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 +02003235
Gilles Peskine60d99472021-09-01 20:00:33 +02003236 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003237 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003238}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003239
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003240component_build_arm_linux_gnueabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003241 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003242 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02003243 # Build for a target platform that's close to what Debian uses
3244 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
Dave Rodgman52af7692022-03-31 14:27:24 +01003245 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003246 # Build everything including programs, see for example
Dave Rodgman52af7692022-03-31 14:27:24 +01003247 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003248 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'
3249
Gilles Peskine60d99472021-09-01 20:00:33 +02003250 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003251 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size library/*.o
3252}
3253support_build_arm_linux_gnueabi_gcc_arm5vte () {
3254 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
3255}
3256
3257component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003258 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Manuel Pégourié-Gonnard71930162020-08-18 10:28:51 +02003259 scripts/config.py baremetal
3260 # This is an imperfect substitute for
3261 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnard9a260a62021-07-06 09:44:59 +02003262 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02003263 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 +02003264
Gilles Peskine60d99472021-09-01 20:00:33 +02003265 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Gilles Peskine18487f62020-04-30 23:11:54 +02003266 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02003267}
3268
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003269component_build_arm_none_eabi_gcc_m0plus () {
Gilles Peskine60d99472021-09-01 20:00:33 +02003270 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
3271 scripts/config.py baremetal_size
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 -mthumb -mcpu=cortex-m0plus -Os' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02003273
Gilles Peskine60d99472021-09-01 20:00:33 +02003274 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
Gilles Peskine18487f62020-04-30 23:11:54 +02003275 ${ARM_NONE_EABI_GCC_PREFIX}size library/*.o
Gilles Peskine6e2fb862020-04-30 23:00:53 +02003276}
3277
Gilles Peskine8f073122018-11-27 15:58:47 +01003278component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003279 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003280 scripts/config.py baremetal
3281 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003282 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 +01003283 echo "Checking that software 64-bit division is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003284 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003285}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003286
Gilles Peskine8f073122018-11-27 15:58:47 +01003287component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02003288 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003289 scripts/config.py baremetal
3290 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02003291 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 +01003292 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003293 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01003294}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02003295
Dave Rodgman43ea9ab2023-06-02 10:26:24 -04003296component_build_arm_clang_thumb () {
3297 # ~ 30s
3298
3299 scripts/config.py baremetal
3300
3301 msg "build: clang thumb 2, make"
3302 make clean
3303 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
3304
3305 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
3306 msg "build: clang thumb 1 -O0, make"
3307 make clean
3308 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
3309
3310 msg "build: clang thumb 1 -Os, make"
3311 make clean
3312 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
3313}
3314
Gilles Peskine8f073122018-11-27 15:58:47 +01003315component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02003316 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003317 scripts/config.py baremetal
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003318 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02003319
3320 msg "size: ARM Compiler 5"
3321 "$ARMC5_FROMELF" -z library/*.o
3322
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003323 make clean
Andres AG87bb5772016-09-27 15:05:15 +01003324
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003325 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
3326
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003327 # ARM Compiler 6 - Target ARMv7-A
3328 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003329
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003330 # ARM Compiler 6 - Target ARMv7-M
3331 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m"
Simon Butcher940737f2017-07-23 13:42:36 +02003332
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003333 # ARM Compiler 6 - Target ARMv8-A - AArch32
3334 armc6_build_test "--target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02003335
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003336 # ARM Compiler 6 - Target ARMv8-M
3337 armc6_build_test "--target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02003338
Gilles Peskinebca6ab92017-12-19 18:24:31 +01003339 # ARM Compiler 6 - Target ARMv8-A - AArch64
3340 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a"
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003341
3342 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
3343 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
3344
3345 # ARM Compiler 6 - Target Cortex-M0
3346 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
Gilles Peskine8f073122018-11-27 15:58:47 +01003347}
Dave Rodgmanc2e225b2023-06-02 13:54:00 -04003348
Pengyu Lvd216c042023-03-03 18:23:35 +08003349support_build_armcc () {
3350 armc5_cc="$ARMC5_BIN_DIR/armcc"
3351 armc6_cc="$ARMC6_BIN_DIR/armclang"
3352 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
3353}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01003354
Manuel Pégourié-Gonnarddd8807f2020-02-26 09:56:27 +01003355component_build_ssl_hw_record_accel() {
3356 msg "build: default config with MBEDTLS_SSL_HW_RECORD_ACCEL enabled"
3357 scripts/config.pl set MBEDTLS_SSL_HW_RECORD_ACCEL
3358 make CFLAGS='-Werror -O1'
3359}
3360
Hanno Beckera711f6e2020-05-04 12:03:51 +01003361component_test_tls13_experimental () {
3362 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3363 scripts/config.pl set MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
3364 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3365 make
3366 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL enabled"
3367 make test
3368}
3369
Gilles Peskine8f073122018-11-27 15:58:47 +01003370component_build_mingw () {
3371 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Gilles Peskinec61187f2024-06-19 16:34:29 +02003372 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs
Hanno Beckere963efa2018-01-03 10:03:43 +00003373
Gilles Peskine8f073122018-11-27 15:58:47 +01003374 # note Make tests only builds the tests, but doesn't run them
Gilles Peskinec61187f2024-06-19 16:34:29 +02003375 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar CFLAGS='-Werror' WINDOWS_BUILD=1 tests
Gilles Peskine8f073122018-11-27 15:58:47 +01003376 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02003377
Gilles Peskine8f073122018-11-27 15:58:47 +01003378 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Gilles Peskinec61187f2024-06-19 16:34:29 +02003379 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 lib programs
3380 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 tests
Gilles Peskine8f073122018-11-27 15:58:47 +01003381 make WINDOWS_BUILD=1 clean
Pengyu Lvb2ca0322023-10-19 17:17:19 +08003382
3383 msg "build: Windows cross build - mingw64, make (Library only, AESNI intrinsics)" # ~ 30s
Gilles Peskinec61187f2024-06-19 16:34:29 +02003384 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 lib
Pengyu Lve6cbec82023-10-20 09:49:01 +08003385 make WINDOWS_BUILD=1 clean
3386
3387 msg "build: Windows cross build - mingw64, make (Library only, default config without MBEDTLS_AESNI_C)" # ~ 30s
3388 ./scripts/config.py unset MBEDTLS_AESNI_C
Gilles Peskinec61187f2024-06-19 16:34:29 +02003389 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib
Pengyu Lve6cbec82023-10-20 09:49:01 +08003390 make WINDOWS_BUILD=1 clean
Gilles Peskinec61187f2024-06-19 16:34:29 +02003391}
3392
Jaeden Amero117b8a42019-04-17 15:19:26 +01003393support_build_mingw() {
Pengyu Lva19ce122023-02-24 15:38:52 +08003394 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
3395 [0-5]*|"") false;;
Jaeden Amero117b8a42019-04-17 15:19:26 +01003396 *) true;;
3397 esac
3398}
Simon Butcher91aef332016-11-17 09:20:50 +00003399
Gilles Peskine8f073122018-11-27 15:58:47 +01003400component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003401 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003402 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003403 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
3404 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02003405
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003406 msg "test: main suites (MSan)" # ~ 10s
3407 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003408
Gilles Peskineee8af062023-11-02 19:58:03 +01003409 msg "test: metatests (MSan)"
3410 tests/scripts/run-metatests.sh any msan
3411
Gilles Peskine93aaf2e2019-06-14 18:27:03 +02003412 msg "program demos (MSan)" # ~20s
3413 tests/scripts/run_demos.py
3414
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003415 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003416 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003417
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003418 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01003419
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003420 if [ "$MEMORY" -gt 0 ]; then
3421 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003422 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003423 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003424}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003425
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01003426component_release_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003427 msg "build: Release (clang)"
Gilles Peskine619b73d2022-11-29 16:45:30 +01003428 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003429 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3430 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003431
Gilles Peskine619b73d2022-11-29 16:45:30 +01003432 msg "test: main suites, Valgrind (default config)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003433 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003434
Gilles Peskine636c26a2020-03-04 20:46:15 +01003435 # Optional parts (slow; currently broken on OS X because programs don't
3436 # seem to receive signals under valgrind on OS X).
Gilles Peskine619b73d2022-11-29 16:45:30 +01003437 # These optional parts don't run on the CI.
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003438 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003439 msg "test: ssl-opt.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003440 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003441 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003442
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003443 if [ "$MEMORY" -gt 1 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003444 msg "test: compat.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003445 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01003446 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003447
3448 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskine619b73d2022-11-29 16:45:30 +01003449 msg "test: context-info.sh --memcheck (default config)"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003450 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003451 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01003452}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003453
Bence Szépkútie1c6c4c2023-12-06 16:14:37 +01003454component_release_test_valgrind_psa () {
Gilles Peskine619b73d2022-11-29 16:45:30 +01003455 msg "build: Release, full (clang)"
3456 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
3457 scripts/config.py full
3458 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
3459 make
3460
3461 msg "test: main suites, Valgrind (full config)"
3462 make memcheck
3463}
3464
Paul Elliott2ab9a7a2021-11-25 17:29:40 +00003465support_test_cmake_out_of_source () {
3466 distrib_id=""
3467 distrib_ver=""
3468 distrib_ver_minor=""
3469 distrib_ver_major=""
3470
3471 # Attempt to parse lsb-release to find out distribution and version. If not
3472 # found this should fail safe (test is supported).
3473 if [[ -f /etc/lsb-release ]]; then
3474
3475 while read -r lsb_line; do
3476 case "$lsb_line" in
3477 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
3478 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
3479 esac
3480 done < /etc/lsb-release
3481
3482 distrib_ver_major="${distrib_ver%%.*}"
3483 distrib_ver="${distrib_ver#*.}"
3484 distrib_ver_minor="${distrib_ver%%.*}"
3485 fi
3486
3487 # Running the out of source CMake test on Ubuntu 16.04 using more than one
3488 # processor (as the CI does) can create a race condition whereby the build
3489 # fails to see a generated file, despite that file actually having been
3490 # generated. This problem appears to go away with 18.04 or newer, so make
3491 # the out of source tests unsupported on Ubuntu 16.04.
3492 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
3493}
3494
Gilles Peskine8f073122018-11-27 15:58:47 +01003495component_test_cmake_out_of_source () {
3496 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01003497 MBEDTLS_ROOT_DIR="$PWD"
3498 mkdir "$OUT_OF_SOURCE_DIR"
3499 cd "$OUT_OF_SOURCE_DIR"
Gilles Peskine25319702021-10-07 19:34:57 +02003500 cmake -D CMAKE_BUILD_TYPE:String=Check "$MBEDTLS_ROOT_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003501 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00003502
Gilles Peskine8f073122018-11-27 15:58:47 +01003503 msg "test: cmake 'out-of-source' build"
3504 make test
3505 # Test an SSL option that requires an auxiliary script in test/scripts/.
3506 # Also ensure that there are no error messages such as
3507 # "No such file or directory", which would indicate that some required
3508 # file is missing (ssl-opt.sh tolerates the absence of some files so
3509 # may exit with status 0 but emit errors).
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003510 ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' >ssl-opt.out 2>ssl-opt.err
3511 grep PASS ssl-opt.out
Gilles Peskine0a7984f2020-03-28 18:56:09 +01003512 cat ssl-opt.err >&2
3513 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003514 [ ! -s ssl-opt.err ]
Gilles Peskinee8133cb2022-04-15 22:43:38 +02003515 rm ssl-opt.out ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01003516 cd "$MBEDTLS_ROOT_DIR"
3517 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01003518}
Andres AGdc192212016-08-31 17:33:13 +01003519
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003520component_test_cmake_as_subdirectory () {
3521 msg "build: cmake 'as-subdirectory' build"
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003522 cd programs/test/cmake_subproject
3523 cmake .
3524 make
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003525 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003526}
Gilles Peskineca9cfca2022-02-04 00:21:12 +01003527support_test_cmake_as_subdirectory () {
3528 support_test_cmake_out_of_source
3529}
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01003530
David Horstmann175afbd2023-01-12 14:17:01 +00003531component_build_cmake_custom_config_file () {
David Horstmann67622312023-01-31 10:34:44 +00003532 # Make a copy of config file to use for the in-tree test
3533 cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h
David Horstmann175afbd2023-01-12 14:17:01 +00003534
3535 MBEDTLS_ROOT_DIR="$PWD"
3536 mkdir "$OUT_OF_SOURCE_DIR"
3537 cd "$OUT_OF_SOURCE_DIR"
3538
David Horstmann67622312023-01-31 10:34:44 +00003539 # Build once to get the generated files (which need an intact config file)
David Horstmann175afbd2023-01-12 14:17:01 +00003540 cmake "$MBEDTLS_ROOT_DIR"
3541 make
3542
3543 msg "build: cmake with -DMBEDTLS_CONFIG_FILE"
3544 scripts/config.py -w full_config.h full
David Horstmann67622312023-01-31 10:34:44 +00003545 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003546 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR"
3547 make
3548
3549 msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
3550 # In the user config, disable one feature (for simplicity, pick a feature
3551 # that nothing else depends on).
3552 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3553
3554 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR"
3555 make
3556 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3557
3558 rm -f user_config.h full_config.h
3559
3560 cd "$MBEDTLS_ROOT_DIR"
3561 rm -rf "$OUT_OF_SOURCE_DIR"
3562
3563 # Now repeat the test for an in-tree build:
3564
David Horstmann67622312023-01-31 10:34:44 +00003565 # Restore config for the in-tree test
3566 mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003567
David Horstmann67622312023-01-31 10:34:44 +00003568 # Build once to get the generated files (which need an intact config)
David Horstmann175afbd2023-01-12 14:17:01 +00003569 cmake .
3570 make
3571
3572 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE"
3573 scripts/config.py -w full_config.h full
David Horstmann67622312023-01-31 10:34:44 +00003574 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann175afbd2023-01-12 14:17:01 +00003575 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h .
3576 make
3577
3578 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
3579 # In the user config, disable one feature (for simplicity, pick a feature
3580 # that nothing else depends on).
3581 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
3582
3583 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h .
3584 make
3585 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
3586
3587 rm -f user_config.h full_config.h
3588}
3589support_build_cmake_custom_config_file () {
3590 support_test_cmake_out_of_source
3591}
3592
3593
Tom Cosgrove51170622023-09-01 10:40:15 +01003594component_build_zeroize_checks () {
3595 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
3596
3597 scripts/config.py full
3598
3599 # Only compile - we're looking for sizeof-pointer-memaccess warnings
Dave Rodgman374b1882024-01-04 10:30:57 +00003600 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 +01003601}
3602
3603
Gilles Peskine8f073122018-11-27 15:58:47 +01003604component_test_zeroize () {
3605 # Test that the function mbedtls_platform_zeroize() is not optimized away by
3606 # different combinations of compilers and optimization flags by using an
3607 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
3608 # system in all cases that the script fails, so we must manually search the
3609 # output to check whether the pass string is present and no failure strings
3610 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01003611
Gilles Peskine4976e822019-01-06 19:52:22 +00003612 # Don't try to disable ASLR. We don't care about ASLR here. We do care
3613 # about a spurious message if Gdb tries and fails, so suppress that.
3614 gdb_disable_aslr=
3615 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
3616 gdb_disable_aslr='set disable-randomization off'
3617 fi
3618
Gilles Peskine8f073122018-11-27 15:58:47 +01003619 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01003620 for compiler in clang gcc; do
3621 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
3622 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003623 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
3624 grep "The buffer was correctly zeroized" test_zeroize.log
3625 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01003626 rm -f test_zeroize.log
3627 make clean
3628 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01003629 done
Gilles Peskine8f073122018-11-27 15:58:47 +01003630}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003631
Bence Szépkúti9f849112021-10-19 15:05:36 +02003632component_test_psa_compliance () {
Dave Rodgmanb0660c22023-12-18 19:55:40 +00003633 # The arch tests build with gcc, so require use of gcc here to link properly
Bence Szépkútic1e79fd2021-11-11 20:13:14 +01003634 msg "build: make, default config + CMAC, libmbedcrypto.a only"
3635 scripts/config.py set MBEDTLS_CMAC_C
Dave Rodgmanb0660c22023-12-18 19:55:40 +00003636 CC=gcc make -C library libmbedcrypto.a
Bence Szépkúti9f849112021-10-19 15:05:36 +02003637
3638 msg "unit test: test_psa_compliance.py"
Dave Rodgman5b00fb12023-12-18 22:29:56 +00003639 CC=gcc ./tests/scripts/test_psa_compliance.py
Bence Szépkúti9f849112021-10-19 15:05:36 +02003640}
3641
3642support_test_psa_compliance () {
Bence Szépkútid6cf0892021-11-03 11:36:09 +01003643 # psa-compliance-tests only supports CMake >= 3.10.0
Bence Szépkútiab796e62021-10-25 19:29:07 +02003644 ver="$(cmake --version)"
3645 ver="${ver#cmake version }"
3646 ver_major="${ver%%.*}"
3647
3648 ver="${ver#*.}"
3649 ver_minor="${ver%%.*}"
3650
3651 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
Bence Szépkúti9f849112021-10-19 15:05:36 +02003652}
3653
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003654component_check_code_style () {
3655 msg "Check C code style"
3656 ./scripts/code_style.py
David Horstmanne09c4762022-11-10 18:30:52 +00003657}
3658
Gilles Peskineb9e56fb2022-12-09 12:23:35 +01003659support_check_code_style() {
David Horstmanne09c4762022-11-10 18:30:52 +00003660 case $(uncrustify --version) in
3661 *0.75.1*) true;;
3662 *) false;;
3663 esac
3664}
3665
Gilles Peskine8f073122018-11-27 15:58:47 +01003666component_check_python_files () {
3667 msg "Lint: Python scripts"
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003668 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003669}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003670
Gilles Peskine8f073122018-11-27 15:58:47 +01003671component_check_generate_test_code () {
3672 msg "uint test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02003673 # unittest writes out mundane stuff like number or tests run on stderr.
3674 # Our convention is to reserve stderr for actual errors, and write
3675 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskinef6d29c62021-07-08 18:41:16 +02003676 ./tests/scripts/test_generate_test_code.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01003677}
Gilles Peskine192c72f2017-12-21 15:59:21 +01003678
3679################################################################
3680#### Termination
3681################################################################
3682
Gilles Peskine8f073122018-11-27 15:58:47 +01003683post_report () {
3684 msg "Done, cleaning up"
Gilles Peskine24bdf022020-03-30 20:11:39 +02003685 final_cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003686
Gilles Peskine8f073122018-11-27 15:58:47 +01003687 final_report
3688}
3689
3690
3691
3692################################################################
3693#### Run all the things
3694################################################################
3695
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003696# Function invoked by --error-test to test error reporting.
3697pseudo_component_error_test () {
Gilles Peskine202e9b42021-08-02 23:28:00 +02003698 msg "Testing error reporting $error_test_i"
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003699 if [ $KEEP_GOING -ne 0 ]; then
3700 echo "Expect three failing commands."
3701 fi
Gilles Peskine202e9b42021-08-02 23:28:00 +02003702 # If the component doesn't run in a subshell, changing error_test_i to an
3703 # invalid integer will cause an error in the loop that runs this function.
3704 error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003705 # Expected error: 'grep non_existent /dev/null -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003706 grep non_existent /dev/null
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003707 # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003708 not grep -q . "$0"
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003709 # Expected error: 'make unknown_target -> 2'
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003710 make unknown_target
3711 false "this should not be executed"
3712}
3713
Gilles Peskinee48351a2018-11-27 16:06:30 +01003714# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01003715run_component () {
Gilles Peskineffcdeff2018-12-04 12:49:28 +01003716 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02003717 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003718
3719 # Unconditionally create a seedfile that's sufficiently long.
3720 # Do this before each component, because a previous component may
3721 # have messed it up or shortened it.
Gilles Peskinef3133362021-07-08 19:03:50 +02003722 local dd_cmd
3723 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
3724 case $OSTYPE in
3725 linux*|freebsd*|openbsd*|darwin*) dd_cmd+=(status=none)
3726 esac
3727 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003728
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003729 # Run the component in a subshell, with error trapping and output
3730 # redirection set up based on the relevant options.
Gilles Peskine7105a332020-03-28 18:50:43 +01003731 if [ $KEEP_GOING -eq 1 ]; then
Gilles Peskinecb4bfac2021-08-02 23:14:03 +02003732 # We want to keep running if the subshell fails, so 'set -e' must
3733 # be off when the subshell runs.
Gilles Peskine7105a332020-03-28 18:50:43 +01003734 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02003735 fi
Gilles Peskine7105a332020-03-28 18:50:43 +01003736 (
3737 if [ $QUIET -eq 1 ]; then
3738 # msg() will be silenced, so just print the component name here.
3739 echo "${current_component#component_}"
3740 exec >/dev/null
3741 fi
3742 if [ $KEEP_GOING -eq 1 ]; then
3743 # Keep "set -e" off, and run an ERR trap instead to record failures.
3744 set -E
3745 trap err_trap ERR
3746 fi
3747 # The next line is what runs the component
3748 "$@"
3749 if [ $KEEP_GOING -eq 1 ]; then
3750 trap - ERR
3751 exit $last_failure_status
3752 fi
3753 )
3754 component_status=$?
3755 if [ $KEEP_GOING -eq 1 ]; then
3756 set -e
3757 if [ $component_status -ne 0 ]; then
3758 failure_count=$((failure_count + 1))
3759 fi
3760 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02003761
3762 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01003763 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02003764 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01003765}
3766
3767# Preliminary setup
3768pre_check_environment
3769pre_initialize_variables
3770pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01003771
Dave Rodgman4cb98a92024-02-26 11:41:19 +00003772setup_quiet_wrappers
Gilles Peskine878cf602019-01-06 20:50:38 +00003773pre_check_git
Gilles Peskineef64e7f2021-07-12 18:16:01 +02003774pre_restore_files
Gilles Peskine24bdf022020-03-30 20:11:39 +02003775pre_back_up
Andrzej Kurekeb508712019-02-14 07:18:59 -05003776
Gilles Peskine878cf602019-01-06 20:50:38 +00003777build_status=0
3778if [ $KEEP_GOING -eq 1 ]; then
3779 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01003780fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02003781pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00003782pre_print_configuration
3783pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01003784cleanup
3785
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003786# Run the requested tests.
Gilles Peskine202e9b42021-08-02 23:28:00 +02003787for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003788 run_component pseudo_component_error_test
Gilles Peskinea5eb22d2020-03-28 21:09:21 +01003789done
Gilles Peskine202e9b42021-08-02 23:28:00 +02003790unset error_test_i
Gilles Peskinebeb3a812019-01-06 22:11:25 +00003791for component in $RUN_COMPONENTS; do
3792 run_component "component_$component"
3793done
Gilles Peskine8f073122018-11-27 15:58:47 +01003794
3795# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00003796post_report