blob: 0f653fed19bdcfabce8c95d0a66d2109b2deeb0a [file] [log] [blame]
Gilles Peskine62cf2e82020-03-27 16:35:23 +01001#! /usr/bin/env bash
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
Bence Szépkúti1e148272020-08-07 13:07:28 +02005# Copyright The Mbed TLS Contributors
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02006# SPDX-License-Identifier: Apache-2.0
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
Gilles Peskine192c72f2017-12-21 15:59:21 +010019
20
21
22################################################################
23#### Documentation
24################################################################
25
Simon Butcher3ea7f522016-03-07 23:22:10 +000026# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010027# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000028#
SimonB2e23c822016-04-16 21:54:39 +010029# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# Notes for users
32# ---------------
33#
SimonB2e23c822016-04-16 21:54:39 +010034# Warning: the test is destructive. It includes various build modes and
35# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010036# configuration. The following files must be committed into git:
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +020037# * include/mbedtls/mbedtls_config.h
Gilles Peskine636c26a2020-03-04 20:46:15 +010038# * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
39# programs/fuzz/Makefile
Gilles Peskine192c72f2017-12-21 15:59:21 +010040# After running this script, the CMake cache will be lost and CMake
41# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010042#
Gilles Peskine192c72f2017-12-21 15:59:21 +010043# The script assumes the presence of a number of tools:
44# * Basic Unix tools (Windows users note: a Unix-style find must be before
45# the Windows find in the PATH)
46# * Perl
47# * GNU Make
48# * CMake
49# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040050# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010051# * arm-gcc and mingw-gcc
52# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010053# * OpenSSL and GnuTLS command line tools, recent enough for the
Mateusz Starzykf5c53512021-04-15 13:28:52 +020054# interoperability tests. If they don't support old features which we want
55# to test, then a legacy version of these tools must be present as well
56# (search for LEGACY below).
Gilles Peskine192c72f2017-12-21 15:59:21 +010057# See the invocation of check_tools below for details.
58#
59# This script must be invoked from the toplevel directory of a git
60# working copy of Mbed TLS.
61#
Gilles Peskinece266c42020-03-28 18:50:43 +010062# The behavior on an error depends on whether --keep-going (alias -k)
63# is in effect.
64# * Without --keep-going: the script stops on the first error without
65# cleaning up. This lets you work in the configuration of the failing
66# component.
67# * With --keep-going: the script runs all requested components and
68# reports failures at the end. In particular the script always cleans
69# up on exit.
70#
Gilles Peskine192c72f2017-12-21 15:59:21 +010071# Note that the output is not saved. You may want to run
72# script -c tests/scripts/all.sh
73# or
74# tests/scripts/all.sh >all.log 2>&1
75#
76# Notes for maintainers
77# ---------------------
78#
Gilles Peskine8f073122018-11-27 15:58:47 +010079# The bulk of the code is organized into functions that follow one of the
80# following naming conventions:
81# * pre_XXX: things to do before running the tests, in order.
82# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010083# * component_check_XXX: quick tests that aren't worth parallelizing.
84# * component_build_XXX: build things but don't run them.
85# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000086# * support_XXX: if support_XXX exists and returns false then
87# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010088# * post_XXX: things to do after running the tests.
89# * other: miscellaneous support functions.
90#
Gilles Peskinec70637a2019-01-09 22:29:17 +010091# Each component must start by invoking `msg` with a short informative message.
92#
Gilles Peskinea681c592020-03-28 21:27:40 +010093# Warning: due to the way bash detects errors, the failure of a command
94# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
95#
Gilles Peskinece266c42020-03-28 18:50:43 +010096# Each component is executed in a separate shell process. The component
97# fails if any command in it returns a non-zero status.
98#
Gilles Peskinec70637a2019-01-09 22:29:17 +010099# The framework performs some cleanup tasks after each component. This
100# means that components can assume that the working directory is in a
101# cleaned-up state, and don't need to perform the cleanup themselves.
102# * Run `make clean`.
Bence Szépkúti414d6bd2021-06-28 14:11:11 +0100103# * Restore `include/mbedtls/mbedtls_config.h` from a backup made before running
Gilles Peskinec70637a2019-01-09 22:29:17 +0100104# the component.
Gilles Peskine636c26a2020-03-04 20:46:15 +0100105# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
106# `tests/Makefile` and `programs/fuzz/Makefile` from git.
107# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +0100108#
Gilles Peskine192c72f2017-12-21 15:59:21 +0100109# The tests are roughly in order from fastest to slowest. This doesn't
110# have to be exact, but in general you should add slower tests towards
111# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100112
113
114
115################################################################
116#### Initialization and command line parsing
117################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100118
Gilles Peskine36647802020-03-28 18:50:49 +0100119# Abort on errors (even on the left-hand side of a pipe).
120# Treat uninitialised variables as errors.
121set -e -o pipefail -u
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100122
Gilles Peskine076f7252022-08-30 21:02:44 +0200123# Enable ksh/bash extended file matching patterns
124shopt -s extglob
125
David Horstmann76a77382023-08-17 17:32:26 +0100126in_mbedtls_repo () {
David Horstmannd02b5f82023-08-29 09:53:52 +0100127 test -d include -a -d library -a -d programs -a -d tests
128}
129
Ronald Cron070e8652023-10-09 10:25:45 +0200130in_tf_psa_crypto_repo () {
David Horstmannd02b5f82023-08-29 09:53:52 +0100131 test -d include -a -d core -a -d drivers -a -d programs -a -d tests
David Horstmann9a6c45b2023-07-14 12:30:00 +0100132}
133
Gilles Peskine8f073122018-11-27 15:58:47 +0100134pre_check_environment () {
Ronald Cron070e8652023-10-09 10:25:45 +0200135 if in_mbedtls_repo || in_tf_psa_crypto_repo; then :; else
136 echo "Must be run from Mbed TLS / TF-PSA-Crypto root" >&2
Gilles Peskine8f073122018-11-27 15:58:47 +0100137 exit 1
138 fi
139}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100140
Gilles Peskine8f073122018-11-27 15:58:47 +0100141pre_initialize_variables () {
David Horstmann76a77382023-08-17 17:32:26 +0100142 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100143 CONFIG_H='include/mbedtls/mbedtls_config.h'
David Horstmann76a77382023-08-17 17:32:26 +0100144 else
145 CONFIG_H='drivers/builtin/include/mbedtls/mbedtls_config.h'
David Horstmann9a6c45b2023-07-14 12:30:00 +0100146 fi
John Durkopbd069d32020-10-31 22:14:03 -0700147 CRYPTO_CONFIG_H='include/psa/crypto_config.h'
Manuel Pégourié-Gonnard462e3a92022-12-27 12:35:11 +0100148 CONFIG_TEST_DRIVER_H='tests/include/test/drivers/config_test_driver.h'
Gilles Peskinef83eb822020-03-30 20:11:39 +0200149
150 # Files that are clobbered by some jobs will be backed up. Use a different
151 # suffix from auxiliary scripts so that all.sh and auxiliary scripts can
152 # independently decide when to remove the backup file.
153 backup_suffix='.all.bak'
154 # Files clobbered by config.py
Janos Follath2f045822023-07-31 10:57:16 +0100155 files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H $CONFIG_TEST_DRIVER_H"
David Horstmann76a77382023-08-17 17:32:26 +0100156 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100157 # Files clobbered by in-tree cmake
158 files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile"
159 fi
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200160
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200161 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100162 MEMORY=0
163 FORCE=0
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200164 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100165 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100166
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200167 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard54304472020-06-22 10:11:47 +0200168 #
169 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
170 # both values are kept in sync. If you change the value here because it
171 # breaks some tests, you'll definitely want to change it in
172 # basic-build-test.sh as well.
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200173 RELEASE_SEED=1
174
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200175 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200176 : ${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 +0200177 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200178 export MBEDTLS_TEST_PLATFORM
179
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000180 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100181 : ${OPENSSL:="openssl"}
182 : ${OPENSSL_LEGACY:="$OPENSSL"}
183 : ${OPENSSL_NEXT:="$OPENSSL"}
184 : ${GNUTLS_CLI:="gnutls-cli"}
185 : ${GNUTLS_SERV:="gnutls-serv"}
186 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
187 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
188 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
189 : ${ARMC5_BIN_DIR:=/usr/bin}
190 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskine6d061342020-04-30 18:19:32 +0200191 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +0200192 : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
Gowtham Suresh Kumar9da40b82023-07-31 16:38:10 +0100193 : ${CLANG_LATEST:="clang-latest"}
194 : ${CLANG_EARLIEST:="clang-earliest"}
195 : ${GCC_LATEST:="gcc-latest"}
196 : ${GCC_EARLIEST:="gcc-earliest"}
Gilles Peskine8f073122018-11-27 15:58:47 +0100197 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000198 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine050d2fc2021-09-30 18:24:21 +0200199 export MAKEFLAGS="-j$(all_sh_nproc)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100200 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000201
Gilles Peskine396853a2021-09-20 18:57:55 +0200202 # Include more verbose output for failing tests run by CMake or make
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000203 export CTEST_OUTPUT_ON_FAILURE=1
204
Gilles Peskine8fd59422019-10-21 17:11:33 +0200205 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Manuel Pégourié-Gonnardfe549a72022-11-30 10:42:03 +0100206 # default to -O2, use -Ox _after_ this if you want another level
Przemek Stekiel6efa6082023-05-31 09:38:21 +0200207 ASAN_CFLAGS='-O2 -Werror -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200208
Andrzej Kurek04bfe572023-06-27 10:02:09 -0400209 # Platform tests have an allocation that returns null
210 export ASAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurek026235c2023-07-05 08:32:43 -0400211 export MSAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurek04bfe572023-06-27 10:02:09 -0400212
Gilles Peskine878cf602019-01-06 20:50:38 +0000213 # Gather the list of available components. These are the functions
214 # defined in this script whose name starts with "component_".
Gowtham Suresh Kumar1e829a42023-07-28 16:41:21 +0100215 ALL_COMPONENTS=$(compgen -A function component_ | sed 's/component_//')
Gilles Peskine878cf602019-01-06 20:50:38 +0000216
217 # Exclude components that are not supported on this platform.
218 SUPPORTED_COMPONENTS=
219 for component in $ALL_COMPONENTS; do
220 case $(type "support_$component" 2>&1) in
221 *' function'*)
222 if ! support_$component; then continue; fi;;
223 esac
224 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
225 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100226}
Andres AG38495a32016-07-12 16:54:33 +0100227
Gilles Peskinea28db922019-01-10 00:05:18 +0100228# Test whether the component $1 is included in the command line patterns.
229is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100230{
Gilles Peskine03af6782021-08-06 11:35:17 +0200231 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
232 # only does word splitting.
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100233 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000234 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100235 set +f
236 case ${1#component_} in $pattern) return 0;; esac
237 done
238 set +f
239 return 1
240}
Andres AG7770ea82016-10-10 15:46:20 +0100241
Simon Butcher41eeccf2016-09-07 00:07:09 +0100242usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100243{
Gilles Peskine709346a2017-12-10 23:43:39 +0100244 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100245Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100246Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100247By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100248COMPONENT can be the name of a component or a shell wildcard pattern.
249
250Examples:
251 $0 "check_*"
252 Run all sanity checks.
253 $0 --no-armcc --except test_memsan
254 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100255
256Special options:
257 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000258 --list-all-components List all available test components and exit.
259 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100260
261General options:
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200262 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100263 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100264 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100265 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200266 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200267 --arm-none-eabi-gcc-prefix=<string>
268 Prefix for a cross-compiler for arm-none-eabi
269 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +0200270 --arm-linux-gnueabi-gcc-prefix=<string>
271 Prefix for a cross-compiler for arm-linux-gnueabi
272 (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100273 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine80ddb992021-08-06 11:51:59 +0200274 --restore First clean up the build tree, restoring backed up
275 files. Do not run any components unless they are
276 explicitly specified.
Gilles Peskine5d996822020-03-28 21:09:21 +0100277 --error-test Error test mode: run a failing function in addition
Gilles Peskine86f61292021-08-05 15:11:33 +0200278 to any specified component. May be repeated.
Gilles Peskinea28db922019-01-10 00:05:18 +0100279 --except Exclude the COMPONENTs listed on the command line,
280 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200281 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100282 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100283 --no-force Refuse to overwrite modified files (default).
284 --no-keep-going Stop at the first error (default).
285 --no-memory No additional memory tests (default).
Shaun Case8b0ecbc2021-12-20 21:14:10 -0800286 --no-quiet Print full output from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100287 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200288 --outcome-file=<path> File where test outcomes are written (not done if
289 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100290 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200291 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100292 -s|--seed Integer seed value to use for this test run.
293
294Tool path options:
295 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
296 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +0100297 --clang-earliest=<Clang_earliest_path> Earliest version of clang available
298 --clang-latest=<Clang_latest_path> Latest version of clang available
299 --gcc-earliest=<GCC_earliest_path> Earliest version of GCC available
300 --gcc-latest=<GCC_latest_path> Latest version of GCC available
Gilles Peskine709346a2017-12-10 23:43:39 +0100301 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
302 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
303 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
304 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
305 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
Mateusz Starzyk06b07fb2021-02-18 13:55:21 +0100306 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests..
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100307 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100308EOF
SimonB2e23c822016-04-16 21:54:39 +0100309}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100310
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200311# Cleanup before/after running a component.
312# Remove built files as well as the cmake cache/config.
313# Does not remove generated source files.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100314cleanup()
315{
David Horstmann76a77382023-08-17 17:32:26 +0100316 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100317 command make clean
318 fi
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200319
Gilles Peskine31b07e22018-03-21 12:15:06 +0100320 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000321 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100322 -iname CMakeFiles -exec rm -rf {} \+ -o \
323 \( -iname cmake_install.cmake -o \
324 -iname CTestTestfile.cmake -o \
Manuel Pégourié-Gonnardbfe54d72021-09-09 11:11:44 +0200325 -iname CMakeCache.txt -o \
326 -path './cmake/*.cmake' \) -exec rm -f {} \+
Gilles Peskine31b07e22018-03-21 12:15:06 +0100327 # Recover files overwritten by in-tree CMake builds
Gilles Peskine076f7252022-08-30 21:02:44 +0200328 rm -f include/Makefile include/mbedtls/Makefile programs/!(fuzz)/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200329
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100330 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
331 rm -rf programs/test/cmake_subproject/build
332 rm -f programs/test/cmake_subproject/Makefile
333 rm -f programs/test/cmake_subproject/cmake_subproject
334
Chris Kayd259e342021-03-25 16:03:25 +0000335 # Remove any artifacts from the component_test_cmake_as_package test.
336 rm -rf programs/test/cmake_package/build
337 rm -f programs/test/cmake_package/Makefile
338 rm -f programs/test/cmake_package/cmake_package
339
340 # Remove any artifacts from the component_test_cmake_as_installed_package test.
341 rm -rf programs/test/cmake_package_install/build
342 rm -f programs/test/cmake_package_install/Makefile
343 rm -f programs/test/cmake_package_install/cmake_package_install
344
Gilles Peskinef83eb822020-03-30 20:11:39 +0200345 # Restore files that may have been clobbered by the job
346 for x in $files_to_back_up; do
Gilles Peskinedd06efb2022-08-30 21:02:00 +0200347 if [[ -e "$x$backup_suffix" ]]; then
348 cp -p "$x$backup_suffix" "$x"
349 fi
Gilles Peskinef83eb822020-03-30 20:11:39 +0200350 done
351}
John Durkopbd069d32020-10-31 22:14:03 -0700352
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200353# Final cleanup when this script exits (except when exiting on a failure
354# in non-keep-going mode).
Gilles Peskinef83eb822020-03-30 20:11:39 +0200355final_cleanup () {
356 cleanup
357
358 for x in $files_to_back_up; do
359 rm -f "$x$backup_suffix"
360 done
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100361}
362
Gilles Peskine7c652162017-12-11 00:01:40 +0100363# Executed on exit. May be redefined depending on command line options.
364final_report () {
365 :
366}
367
368fatal_signal () {
Gilles Peskinef83eb822020-03-30 20:11:39 +0200369 final_cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100370 final_report $1
371 trap - $1
372 kill -$1 $$
373}
374
375trap 'fatal_signal HUP' HUP
376trap 'fatal_signal INT' INT
377trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200378
Gilles Peskine050d2fc2021-09-30 18:24:21 +0200379# Number of processors on this machine. Used as the default setting
380# for parallel make.
381all_sh_nproc ()
382{
383 {
384 nproc || # Linux
385 sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
386 sysctl -n hw.ncpu || # FreeBSD
387 echo 1
388 } 2>/dev/null
389}
390
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100391msg()
392{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100393 if [ -n "${current_component:-}" ]; then
394 current_section="${current_component#component_}: $1"
395 else
396 current_section="$1"
397 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200398
399 if [ $QUIET -eq 1 ]; then
400 return
401 fi
402
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100403 echo ""
404 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100405 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000406 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100407 echo "******************************************************************"
408}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100409
Gilles Peskine8f073122018-11-27 15:58:47 +0100410armc6_build_test()
411{
412 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100413
Gilles Peskine18487f62020-04-30 23:11:54 +0200414 msg "build: ARM Compiler 6 ($FLAGS)"
Yanray Wangbc7716c2023-09-08 11:20:59 +0800415 make clean
Gilles Peskine8f073122018-11-27 15:58:47 +0100416 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
Dave Rodgman1c232a82023-03-02 13:39:04 +0000417 WARNING_CFLAGS='-Werror -xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200418
419 msg "size: ARM Compiler 6 ($FLAGS)"
420 "$ARMC6_FROMELF" -z library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +0100421}
Andres AGa5cd9732016-10-17 15:23:10 +0100422
Andres AGd9eba4b2016-08-26 14:42:14 +0100423err_msg()
424{
425 echo "$1" >&2
426}
427
428check_tools()
429{
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200430 for tool in "$@"; do
431 if ! `type "$tool" >/dev/null 2>&1`; then
432 err_msg "$tool not found!"
Andres AGd9eba4b2016-08-26 14:42:14 +0100433 exit 1
434 fi
435 done
436}
437
Tom Cosgrove730addc2023-06-09 14:20:18 +0100438pre_parse_command_line_for_dirs () {
439 # Make an early pass through the options given, so we can set directories
440 # for Arm compilers, before SUPPORTED_COMPONENTS is determined.
441 while [ $# -gt 0 ]; do
442 case "$1" in
443 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
444 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
445 esac
446 shift
447 done
448}
449
Gilles Peskine8f073122018-11-27 15:58:47 +0100450pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000451 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100452 all_except=0
Gilles Peskine5d996822020-03-28 21:09:21 +0100453 error_test=0
Gilles Peskine80ddb992021-08-06 11:51:59 +0200454 restore_first=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000455 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100456
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000457 # Note that legacy options are ignored instead of being omitted from this
458 # list of options, so invocations that worked with previous version of
459 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100460 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100461 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200462 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200463 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +0200464 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000465 --armcc) no_armcc=;;
Tom Cosgrove730addc2023-06-09 14:20:18 +0100466 --armc5-bin-dir) shift; ;; # assignment to ARMC5_BIN_DIR done in pre_parse_command_line_for_dirs
467 --armc6-bin-dir) shift; ;; # assignment to ARMC6_BIN_DIR done in pre_parse_command_line_for_dirs
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +0100468 --clang-earliest) shift; CLANG_EARLIEST="$1";;
469 --clang-latest) shift; CLANG_LATEST="$1";;
Gilles Peskine5d996822020-03-28 21:09:21 +0100470 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000471 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100472 --force|-f) FORCE=1;;
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +0100473 --gcc-earliest) shift; GCC_EARLIEST="$1";;
474 --gcc-latest) shift; GCC_LATEST="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100475 --gnutls-cli) shift; GNUTLS_CLI="$1";;
476 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
477 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
478 --gnutls-serv) shift; GNUTLS_SERV="$1";;
479 --help|-h) usage; exit;;
480 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000481 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
482 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100483 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200484 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000485 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100486 --no-force) FORCE=0;;
487 --no-keep-going) KEEP_GOING=0;;
488 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200489 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100490 --openssl) shift; OPENSSL="$1";;
491 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
492 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200493 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100494 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200495 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100496 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200497 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine80ddb992021-08-06 11:51:59 +0200498 --restore) restore_first=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100499 --seed|-s) shift; SEED="$1";;
500 -*)
501 echo >&2 "Unknown option: $1"
502 echo >&2 "Run $0 --help for usage."
503 exit 120
504 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000505 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100506 esac
507 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100508 done
SimonB2e23c822016-04-16 21:54:39 +0100509
Gilles Peskinea28db922019-01-10 00:05:18 +0100510 # With no list of components, run everything.
Gilles Peskine80ddb992021-08-06 11:51:59 +0200511 if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000512 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100513 fi
514
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000515 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
516 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100517 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000518 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100519 fi
SimonB2e23c822016-04-16 21:54:39 +0100520
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200521 # Error out if an explicitly requested component doesn't exist.
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100522 if [ $all_except -eq 0 ]; then
523 unsupported=0
Gilles Peskine03af6782021-08-06 11:35:17 +0200524 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
525 # only does word splitting.
Gilles Peskine1d475b62021-08-03 13:43:36 +0200526 set -f
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100527 for component in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine1d475b62021-08-03 13:43:36 +0200528 set +f
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200529 # If the requested name includes a wildcard character, don't
530 # check it. Accept wildcard patterns that don't match anything.
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100531 case $component in
532 *[*?\[]*) continue;;
533 esac
534 case " $SUPPORTED_COMPONENTS " in
535 *" $component "*) :;;
536 *)
537 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
538 unsupported=$((unsupported + 1));;
539 esac
540 done
Gilles Peskine1d475b62021-08-03 13:43:36 +0200541 set +f
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100542 if [ $unsupported -ne 0 ]; then
543 exit 2
544 fi
545 fi
546
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000547 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100548 RUN_COMPONENTS=
549 for component in $SUPPORTED_COMPONENTS; do
550 if is_component_included "$component"; [ $? -eq $all_except ]; then
551 RUN_COMPONENTS="$RUN_COMPONENTS $component"
552 fi
553 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000554
555 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000556 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100557}
SimonB2e23c822016-04-16 21:54:39 +0100558
Gilles Peskine8f073122018-11-27 15:58:47 +0100559pre_check_git () {
560 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100561 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100562 git checkout-index -f -q $CONFIG_H
563 cleanup
564 else
SimonB2e23c822016-04-16 21:54:39 +0100565
Gilles Peskine8f073122018-11-27 15:58:47 +0100566 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
567 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
568 echo "You can either delete this directory manually, or force the test by rerunning"
569 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
570 exit 1
571 fi
572
Ronald Cron7a93ac52023-07-20 09:49:12 +0200573 if ! git diff --quiet "$CONFIG_H"; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100574 err_msg "Warning - the configuration file '$CONFIG_H' has been edited. "
Gilles Peskine8f073122018-11-27 15:58:47 +0100575 echo "You can either delete or preserve your work, or force the test by rerunning the"
576 echo "script as: $0 --force"
577 exit 1
578 fi
SimonB2e23c822016-04-16 21:54:39 +0100579 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500580}
581
Gilles Peskine568f53a2021-07-12 18:16:01 +0200582pre_restore_files () {
583 # If the makefiles have been generated by a framework such as cmake,
584 # restore them from git. If the makefiles look like modifications from
585 # the ones checked into git, take care not to modify them. Whatever
586 # this function leaves behind is what the script will restore before
587 # each component.
588 case "$(head -n1 Makefile)" in
589 *[Gg]enerated*)
590 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
591 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
592 ;;
593 esac
594}
595
Gilles Peskinef83eb822020-03-30 20:11:39 +0200596pre_back_up () {
597 for x in $files_to_back_up; do
598 cp -p "$x" "$x$backup_suffix"
599 done
600}
601
Gilles Peskine8f073122018-11-27 15:58:47 +0100602pre_setup_keep_going () {
Gilles Peskinece266c42020-03-28 18:50:43 +0100603 failure_count=0 # Number of failed components
604 last_failure_status=0 # Last failure status in this component
605
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100606 # See err_trap
607 previous_failure_status=0
608 previous_failed_command=
609 previous_failure_funcall_depth=0
Gilles Peskinea681c592020-03-28 21:27:40 +0100610 unset report_failed_command
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100611
Gilles Peskine7c652162017-12-11 00:01:40 +0100612 start_red=
613 end_color=
614 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100615 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100616 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
617 start_red=$(printf '\033[31m')
618 end_color=$(printf '\033[0m')
619 ;;
620 esac
621 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100622
623 # Keep a summary of failures in a file. We'll print it out at the end.
624 failure_summary_file=$PWD/all-sh-failures-$$.log
625 : >"$failure_summary_file"
626
627 # Whether it makes sense to keep a component going after the specified
628 # command fails (test command) or not (configure or build).
Gilles Peskine03af6782021-08-06 11:35:17 +0200629 # This function normally receives the failing simple command
630 # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
631 # this is passed instead.
Gilles Peskinece266c42020-03-28 18:50:43 +0100632 # This doesn't have to be 100% accurate: all failures are recorded anyway.
Gilles Peskinec111e242021-08-02 23:29:53 +0200633 # False positives result in running things that can't be expected to
634 # work. False negatives result in things not running after something else
635 # failed even though they might have given useful feedback.
Gilles Peskinece266c42020-03-28 18:50:43 +0100636 can_keep_going_after_failure () {
637 case "$1" in
638 "msg "*) false;;
Gilles Peskinec111e242021-08-02 23:29:53 +0200639 "cd "*) false;;
640 *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
641 *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
642 *make*check*) true;;
643 "grep "*) true;;
644 "[ "*) true;;
645 "! "*) true;;
Gilles Peskinece266c42020-03-28 18:50:43 +0100646 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100647 esac
648 }
Gilles Peskinece266c42020-03-28 18:50:43 +0100649
650 # This function runs if there is any error in a component.
651 # It must either exit with a nonzero status, or set
652 # last_failure_status to a nonzero value.
653 err_trap () {
654 # Save $? (status of the failing command). This must be the very
655 # first thing, before $? is overridden.
656 last_failure_status=$?
Gilles Peskinea681c592020-03-28 21:27:40 +0100657 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskinece266c42020-03-28 18:50:43 +0100658
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100659 if [[ $last_failure_status -eq $previous_failure_status &&
660 "$failed_command" == "$previous_failed_command" &&
661 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
662 then
663 # The same command failed twice in a row, but this time one level
664 # less deep in the function call stack. This happens when the last
665 # command of a function returns a nonzero status, and the function
666 # returns that same status. Ignore the second failure.
667 previous_failure_funcall_depth=${#FUNCNAME[@]}
668 return
669 fi
670 previous_failure_status=$last_failure_status
671 previous_failed_command=$failed_command
672 previous_failure_funcall_depth=${#FUNCNAME[@]}
673
Gilles Peskinece266c42020-03-28 18:50:43 +0100674 text="$current_section: $failed_command -> $last_failure_status"
675 echo "${start_red}^^^^$text^^^^${end_color}" >&2
676 echo "$text" >>"$failure_summary_file"
677
678 # If the command is fatal (configure or build command), stop this
679 # component. Otherwise (test command) keep the component running
680 # (run more tests from the same build).
681 if ! can_keep_going_after_failure "$failed_command"; then
682 exit $last_failure_status
683 fi
684 }
685
Gilles Peskine7c652162017-12-11 00:01:40 +0100686 final_report () {
687 if [ $failure_count -gt 0 ]; then
688 echo
689 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskinece266c42020-03-28 18:50:43 +0100690 echo "${start_red}FAILED: $failure_count components${end_color}"
691 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100692 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
693 elif [ -z "${1-}" ]; then
694 echo "SUCCESS :)"
695 fi
696 if [ -n "${1-}" ]; then
697 echo "Killed by SIG$1."
698 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100699 rm -f "$failure_summary_file"
700 if [ $failure_count -gt 0 ]; then
701 exit 1
702 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100703 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100704}
705
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200706# record_status() and if_build_succeeded() are kept temporarily for backward
707# compatibility. Don't use them in new components.
Gilles Peskinece266c42020-03-28 18:50:43 +0100708record_status () {
709 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100710}
Gilles Peskine7c652162017-12-11 00:01:40 +0100711if_build_succeeded () {
Gilles Peskinece266c42020-03-28 18:50:43 +0100712 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100713}
714
Gilles Peskinea681c592020-03-28 21:27:40 +0100715# '! true' does not trigger the ERR trap. Arrange to trigger it, with
716# a reasonably informative error message (not just "$@").
717not () {
718 if "$@"; then
719 report_failed_command="! $*"
720 false
721 unset report_failed_command
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200722 fi
723}
724
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200725pre_prepare_outcome_file () {
726 case "$MBEDTLS_TEST_OUTCOME_FILE" in
727 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
728 esac
729 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
730 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
731 fi
732}
733
Gilles Peskine8f073122018-11-27 15:58:47 +0100734pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200735 if [ $QUIET -eq 1 ]; then
736 return
737 fi
738
Gilles Peskine8f073122018-11-27 15:58:47 +0100739 msg "info: $0 configuration"
740 echo "MEMORY: $MEMORY"
741 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200742 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100743 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100744 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100745 echo "OPENSSL: $OPENSSL"
746 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
747 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
748 echo "GNUTLS_CLI: $GNUTLS_CLI"
749 echo "GNUTLS_SERV: $GNUTLS_SERV"
750 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
751 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
752 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
753 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
754}
Andres AG7770ea82016-10-10 15:46:20 +0100755
Andres AGd9eba4b2016-08-26 14:42:14 +0100756# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100757pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000758 # Build the list of variables to pass to output_env.sh.
759 set env
SimonB2e23c822016-04-16 21:54:39 +0100760
Gilles Peskine87964262019-01-06 22:40:00 +0000761 case " $RUN_COMPONENTS " in
762 # Require OpenSSL and GnuTLS if running any tests (as opposed to
763 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
764 # is a good enough approximation in practice.
765 *" test_"*)
766 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
767 # and ssl-opt.sh, we just export the variables they require.
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +0100768 export OPENSSL="$OPENSSL"
Gilles Peskine87964262019-01-06 22:40:00 +0000769 export GNUTLS_CLI="$GNUTLS_CLI"
770 export GNUTLS_SERV="$GNUTLS_SERV"
771 # Avoid passing --seed flag in every call to ssl-opt.sh
772 if [ -n "${SEED-}" ]; then
773 export SEED
774 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000775 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
776 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
777 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
778 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000779 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
780 "$GNUTLS_CLI" "$GNUTLS_SERV" \
781 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
782 ;;
783 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200784
Gilles Peskine87964262019-01-06 22:40:00 +0000785 case " $RUN_COMPONENTS " in
786 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
787 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100788
Gilles Peskine87964262019-01-06 22:40:00 +0000789 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200790 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000791 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100792
Gilles Peskine87964262019-01-06 22:40:00 +0000793 case " $RUN_COMPONENTS " in
794 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
795 esac
796
797 case " $RUN_COMPONENTS " in
798 *" test_zeroize "*) check_tools "gdb";;
799 esac
800
801 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000802 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000803 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
804 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200805 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000806 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
807 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200808 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
809 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
810 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000811 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000812
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200813 # past this point, no call to check_tool, only printing output
814 if [ $QUIET -eq 1 ]; then
815 return
816 fi
817
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000818 msg "info: output_env.sh"
819 case $RUN_COMPONENTS in
820 *_armcc*)
821 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
822 *) set "$@" RUN_ARMCC=0;;
823 esac
824 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100825}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100826
Gilles Peskine1570b592021-04-22 01:10:12 +0200827pre_generate_files() {
Manuel Pégourié-Gonnard87db8a22021-06-18 13:30:14 +0200828 # since make doesn't have proper dependencies, remove any possibly outdate
829 # file that might be around before generating fresh ones
830 make neat
Gilles Peskine72385032021-07-08 19:07:07 +0200831 if [ $QUIET -eq 1 ]; then
Gilles Peskine75301632021-08-05 15:10:47 +0200832 make generated_files >/dev/null
Gilles Peskine72385032021-07-08 19:07:07 +0200833 else
834 make generated_files
835 fi
Gilles Peskine1570b592021-04-22 01:10:12 +0200836}
837
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200838################################################################
839#### Helpers for components using libtestdriver1
840################################################################
Gilles Peskine192c72f2017-12-21 15:59:21 +0100841
Manuel Pégourié-Gonnardf5c5d972023-06-06 11:14:57 +0200842# How to use libtestdriver1
843# -------------------------
844#
845# 1. Define the list algorithms and key types to accelerate,
846# designated the same way as PSA_WANT_ macros but without PSA_WANT_.
847# Examples:
848# - loc_accel_list="ALG_JPAKE"
849# - loc_accel_list="ALG_FFDH KEY_TYPE_DH_KEY_PAIR KEY_TYPE_DH_PUBLIC_KEY"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200850# 2. Make configurations changes for the driver and/or main libraries.
851# 2a. Call helper_libtestdriver1_adjust_config <base>, where the argument
852# can be either "default" to start with the default config, or a name
853# supported by scripts/config.py (for example, "full"). This selects
Manuel Pégourié-Gonnard2336c8e2023-06-12 17:17:54 +0200854# the base to use, and makes common adjustments.
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200855# 2b. If desired, adjust the PSA_WANT symbols in psa/crypto_config.h.
856# These changes affect both the driver and the main libraries.
857# (Note: they need to have the same set of PSA_WANT symbols, as that
858# determines the ABI between them.)
859# 2c. Adjust MBEDTLS_ symbols in mbedtls_config.h. This only affects the
860# main libraries. Typically, you want to disable the module(s) that are
861# being accelerated. You may need to also disable modules that depend
862# on them or options that are not supported with drivers.
863# 2d. On top of psa/crypto_config.h, the driver library uses its own config
864# file: tests/include/test/drivers/config_test_driver.h. You usually
865# don't need to edit it: using loc_extra_list (see below) is preferred.
866# However, when there's no PSA symbol for what you want to enable,
867# calling scripts/config.py on this file remains the only option.
868# 3. Build the driver library, then the main libraries, test, and programs.
869# 3a. Call helper_libtestdriver1_make_drivers "$loc_accel_list". You may
870# need to enable more algorithms here, typically hash algorithms when
871# accelerating some signature algorithms (ECDSA, RSAv2). This is done
872# by passing a 2nd argument listing the extra algorithms.
873# Example:
874# loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
875# helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
876# 4b. Call helper_libtestdriver1_make_main "$loc_accel_list". Any
877# additional arguments will be passed to make: this can be useful if
878# you don't want to build everything when iterating during development.
879# Example:
880# helper_libtestdriver1_make_main "$loc_accel_list" -C tests test_suite_foo
881# 4. Run the tests you want.
Manuel Pégourié-Gonnardf5c5d972023-06-06 11:14:57 +0200882
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200883# Adjust the configuration - for both libtestdriver1 and main library,
884# as they should have the same PSA_WANT macros.
885helper_libtestdriver1_adjust_config() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200886 base_config=$1
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200887 # Select the base configuration
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200888 if [ "$base_config" != "default" ]; then
889 scripts/config.py "$base_config"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200890 fi
891
892 # Enable PSA-based config (necessary to use drivers)
893 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
894
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200895 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
896 # partial support for cipher operations in the driver test library.
Ronald Cron6b49b552023-07-20 09:57:54 +0200897 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_STREAM_CIPHER
898 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
Manuel Pégourié-Gonnard2336c8e2023-06-12 17:17:54 +0200899
900 # Dynamic secure element support is a deprecated feature and needs to be disabled here.
901 # This is done to have the same form of psa_key_attributes_s for libdriver and library.
902 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200903}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100904
Valerio Settib2fd6732023-08-15 17:10:47 +0200905# When called with no parameter this function disables all builtin curves.
Valerio Setti4ca250b2023-09-04 14:01:41 +0200906# The function optionally accepts 1 parameter: a space-separated list of the
907# curves that should be kept enabled.
Valerio Settib2fd6732023-08-15 17:10:47 +0200908helper_disable_builtin_curves() {
909 allowed_list="${1:-}"
910 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
911
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200912 for curve in $allowed_list; do
913 scripts/config.py set $curve
Valerio Settib2fd6732023-08-15 17:10:47 +0200914 done
915}
916
917# Helper returning the list of supported elliptic curves from CRYPTO_CONFIG_H,
918# without the "PSA_WANT_" prefix. This becomes handy for accelerating curves
919# in the following helpers.
920helper_get_psa_curve_list () {
921 loc_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200922 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
923 loc_list="$loc_list $item"
Valerio Settib2fd6732023-08-15 17:10:47 +0200924 done
925
926 echo "$loc_list"
927}
928
929# Get the list of uncommented PSA_WANT_KEY_TYPE_xxx_ from CRYPTO_CONFIG_H. This
Valerio Setti0a342c92023-09-01 09:12:31 +0200930# is useful to easily get a list of key type symbols to accelerate.
Valerio Settib2fd6732023-08-15 17:10:47 +0200931# The function accepts a single argument which is the key type: ECC, DH, RSA.
Valerio Setti0a342c92023-09-01 09:12:31 +0200932helper_get_psa_key_type_list() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200933 key_type="$1"
Valerio Settib2fd6732023-08-15 17:10:47 +0200934 loc_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200935 for item in $(sed -n "s/^#define PSA_WANT_\(KEY_TYPE_${key_type}_[0-9A-Z_a-z]*\).*/\1/p" <"$CRYPTO_CONFIG_H"); do
Valerio Settib2fd6732023-08-15 17:10:47 +0200936 # Skip DERIVE for elliptic keys since there is no driver dispatch for
937 # it so it cannot be accelerated.
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200938 if [ "$item" != "KEY_TYPE_ECC_KEY_PAIR_DERIVE" ]; then
939 loc_list="$loc_list $item"
Valerio Settib2fd6732023-08-15 17:10:47 +0200940 fi
941 done
942
943 echo "$loc_list"
944}
945
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +0200946# Build the drivers library libtestdriver1.a (with ASan).
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +0200947#
948# Parameters:
949# 1. a space-separated list of things to accelerate;
950# 2. optional: a space-separate list of things to also support.
951# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
952helper_libtestdriver1_make_drivers() {
953 loc_accel_flags=$( echo "$1 ${2-}" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
954 make -C tests libtestdriver1.a CFLAGS=" $ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
955}
956
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +0200957# Build the main libraries, programs and tests,
958# linking to the drivers library (with ASan).
959#
960# Parameters:
961# 1. a space-separated list of things to accelerate;
962# *. remaining arguments if any are passed directly to make
963# (examples: lib, -C tests test_suite_xxx, etc.)
964# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
965helper_libtestdriver1_make_main() {
966 loc_accel_list=$1
967 shift
968
969 # we need flags both with and without the LIBTESTDRIVER1_ prefix
970 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
971 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
972 make CFLAGS="$ASAN_CFLAGS -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS" "$@"
973}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100974
975################################################################
976#### Basic checks
977################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100978
979#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200980# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100981#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100982# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200983# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100984# 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 +0200985# time, so start with a GCC build).
986# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100987#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100988# Indicative running times are given for reference.
989
Gilles Peskine8f073122018-11-27 15:58:47 +0100990component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200991 msg "Check: recursion.pl" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200992 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100993}
Janos Follathb72c6782016-07-19 14:54:17 +0100994
Gilles Peskine67debb62021-05-18 16:09:50 +0200995component_check_generated_files () {
996 msg "Check: check-generated-files, files generated with make" # 2s
997 make generated_files
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200998 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200999
1000 msg "Check: check-generated-files -u, files present" # 2s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001001 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +02001002 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001003 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +02001004
1005 msg "Check: check-generated-files -u, files absent" # 2s
1006 command make neat
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001007 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +02001008 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001009 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +02001010
1011 # This component ends with the generated files present in the source tree.
1012 # This is necessary for subsequent components!
1013}
1014
Gilles Peskine8f073122018-11-27 15:58:47 +01001015component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001016 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001017 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001018}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001019
Gilles Peskine8f073122018-11-27 15:58:47 +01001020component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001021 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001022 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +01001023}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001024
Gilles Peskine30e0bb42020-05-10 17:40:49 +02001025component_check_changelog () {
1026 msg "Check: changelog entries" # < 1s
1027 rm -f ChangeLog.new
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001028 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +02001029 if [ -e ChangeLog.new ]; then
1030 # Show the diff for information. It isn't an error if the diff is
1031 # non-empty.
1032 diff -u ChangeLog ChangeLog.new || true
1033 rm ChangeLog.new
1034 fi
1035}
1036
Gilles Peskine8f073122018-11-27 15:58:47 +01001037component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001038 msg "Check: declared and exported names (builds the library)" # < 3s
Yuto Takanoc3a6f632021-09-24 18:02:56 +01001039 tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +01001040}
Darryl Greena07039c2018-03-13 16:48:16 +00001041
Gilles Peskine895868b2019-09-19 21:30:05 +02001042component_check_test_cases () {
1043 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001044 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001045 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001046 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001047 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001048 fi
Gilles Peskine031114d2022-12-15 14:46:31 +01001049 tests/scripts/check_test_cases.py -q $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001050 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +02001051}
1052
Gilles Peskine8f073122018-11-27 15:58:47 +01001053component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001054 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001055 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001056}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001057
Gilles Peskine192c72f2017-12-21 15:59:21 +01001058
Gilles Peskine636c26a2020-03-04 20:46:15 +01001059
Gilles Peskine192c72f2017-12-21 15:59:21 +01001060################################################################
1061#### Build and test many configurations and targets
1062################################################################
1063
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001064component_test_default_out_of_box () {
1065 msg "build: make, default config (out-of-box)" # ~1min
1066 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02001067 # Disable fancy stuff
1068 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001069
1070 msg "test: main suites make, default config (out-of-box)" # ~10s
1071 make test
1072
1073 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001074 programs/test/selftest
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001075}
1076
Gilles Peskine8f073122018-11-27 15:58:47 +01001077component_test_default_cmake_gcc_asan () {
1078 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +01001079 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1080 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001081
Gilles Peskine8f073122018-11-27 15:58:47 +01001082 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
1083 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001084
Gilles Peskine97bea012020-04-23 23:37:45 +02001085 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001086 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +02001087
Gilles Peskine8f073122018-11-27 15:58:47 +01001088 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001089 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001090
Gilles Peskine8f073122018-11-27 15:58:47 +01001091 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001092 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001093
1094 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001095 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001096}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001097
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001098component_test_default_cmake_gcc_asan_new_bignum () {
1099 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Janos Follath2f045822023-07-31 10:57:16 +01001100 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001101 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Janos Follath82823b22023-07-27 12:25:05 +01001102 make
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001103
1104 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
1105 make test
1106
1107 msg "test: selftest (ASan build)" # ~ 10s
1108 programs/test/selftest
1109
1110 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
1111 tests/ssl-opt.sh
1112
1113 msg "test: compat.sh (ASan build)" # ~ 6 min
1114 tests/compat.sh
1115
1116 msg "test: context-info.sh (ASan build)" # ~ 15 sec
1117 tests/context-info.sh
1118}
1119
Hanno Becker01635512019-02-26 14:27:09 +00001120component_test_full_cmake_gcc_asan () {
1121 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001122 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +00001123 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1124 make
1125
1126 msg "test: main suites (inc. selftests) (full config, ASan build)"
1127 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01001128
Gilles Peskine97bea012020-04-23 23:37:45 +02001129 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001130 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +02001131
Gilles Peskine636c26a2020-03-04 20:46:15 +01001132 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001133 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001134
1135 msg "test: compat.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001136 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001137
1138 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001139 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001140}
1141
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001142
1143component_test_full_cmake_gcc_asan_new_bignum () {
1144 msg "build: full config, cmake, gcc, ASan"
1145 scripts/config.py full
Janos Follath2f045822023-07-31 10:57:16 +01001146 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001147 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Janos Follath82823b22023-07-27 12:25:05 +01001148 make
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001149
1150 msg "test: main suites (inc. selftests) (full config, ASan build)"
1151 make test
1152
1153 msg "test: selftest (ASan build)" # ~ 10s
1154 programs/test/selftest
1155
1156 msg "test: ssl-opt.sh (full config, ASan build)"
1157 tests/ssl-opt.sh
1158
1159 msg "test: compat.sh (full config, ASan build)"
1160 tests/compat.sh
1161
1162 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
1163 tests/context-info.sh
Gabor Mezei6db60472023-07-05 16:38:42 +02001164}
1165
Ronald Cronc3623db2020-10-29 10:51:32 +01001166component_test_psa_crypto_key_id_encodes_owner () {
Andrzej Kurek03e01462022-01-03 12:53:24 +01001167 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
Ronald Cronc3623db2020-10-29 10:51:32 +01001168 scripts/config.py full
Ronald Cronc3623db2020-10-29 10:51:32 +01001169 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1170 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1171 make
1172
1173 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
1174 make test
1175}
1176
Gilles Peskinea3548672021-06-17 11:37:52 +02001177# check_renamed_symbols HEADER LIB
1178# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
1179# name is LIB.
1180check_renamed_symbols () {
1181 ! nm "$2" | sed 's/.* //' |
1182 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
1183}
1184
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001185component_build_psa_crypto_spm () {
Andrzej Kurek03e01462022-01-03 12:53:24 +01001186 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001187 scripts/config.py full
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001188 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
1189 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1190 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
1191 # We can only compile, not link, since our test and sample programs
1192 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
1193 # is active.
1194 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskinea3548672021-06-17 11:37:52 +02001195
1196 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
1197 # version is not present.
1198 echo "Checking for renamed symbols in the library"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001199 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001200}
1201
Ronald Cron336678b2021-01-28 17:54:24 +01001202component_test_psa_crypto_client () {
1203 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
1204 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1205 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1206 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
Raef Colesb4568c52022-09-28 17:11:42 +01001207 scripts/config.py unset MBEDTLS_LMS_C
1208 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Ronald Cron336678b2021-01-28 17:54:24 +01001209 make
1210
1211 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
1212 make test
1213}
1214
Jaeden Amero424fa932021-05-14 08:34:32 +01001215component_test_psa_crypto_rsa_no_genprime() {
1216 msg "build: default config minus MBEDTLS_GENPRIME"
1217 scripts/config.py unset MBEDTLS_GENPRIME
1218 make
1219
1220 msg "test: default config minus MBEDTLS_GENPRIME"
1221 make test
1222}
1223
Gilles Peskine782f4112018-11-27 16:11:09 +01001224component_test_ref_configs () {
1225 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Manuel Pégourié-Gonnard9327fb32021-09-09 11:46:25 +02001226 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
1227 # want to re-generate generated files that depend on it, quite correctly.
1228 # However this doesn't work as the generation script expects a specific
1229 # format for mbedtls_config.h, which the other files don't follow. Also,
1230 # cmake can't know this, but re-generation is actually not necessary as
David Horstmannd64f4b22021-10-20 12:29:47 +01001231 # the generated files only depend on the list of available options, not
Manuel Pégourié-Gonnard9327fb32021-09-09 11:46:25 +02001232 # whether they're on or off. So, disable cmake's (over-sensitive here)
1233 # dependency resolution for generated files and just rely on them being
David Horstmanna8d14062021-10-20 17:14:23 +01001234 # present (thanks to pre_generate_files) by turning GEN_FILES off.
1235 CC=gcc cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001236 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +01001237}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001238
Gilles Peskine8f073122018-11-27 15:58:47 +01001239component_test_no_renegotiation () {
1240 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001241 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001242 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1243 make
Simon Butcher3ea7f522016-03-07 23:22:10 +00001244
Gilles Peskine8f073122018-11-27 15:58:47 +01001245 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1246 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +01001247
Gilles Peskine8f073122018-11-27 15:58:47 +01001248 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001249 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001250}
Hanno Becker134c2ab2017-10-12 15:29:50 +01001251
Gilles Peskine636c26a2020-03-04 20:46:15 +01001252component_test_no_pem_no_fs () {
1253 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1254 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1255 scripts/config.py unset MBEDTLS_FS_IO
1256 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1257 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
1258 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1259 make
1260
1261 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1262 make test
1263
1264 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001265 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001266}
1267
Gilles Peskine8f073122018-11-27 15:58:47 +01001268component_test_rsa_no_crt () {
1269 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001270 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +01001271 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1272 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +01001273
Gilles Peskine8f073122018-11-27 15:58:47 +01001274 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1275 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001276
Gilles Peskine8f073122018-11-27 15:58:47 +01001277 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001278 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001279
Gilles Peskine8f073122018-11-27 15:58:47 +01001280 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001281 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001282
1283 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001284 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001285}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001286
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001287component_test_no_ctr_drbg_classic () {
1288 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001289 scripts/config.py full
1290 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001291 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001292 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001293
1294 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1295 make
1296
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001297 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001298 make test
1299
Gilles Peskineba749042021-01-13 20:02:03 +01001300 # In this configuration, the TLS test programs use HMAC_DRBG.
1301 # The SSL tests are slow, so run a small subset, just enough to get
1302 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001303 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001304 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001305
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001306 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001307 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001308}
1309
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001310component_test_no_ctr_drbg_use_psa () {
1311 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001312 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001313 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1314 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001315
1316 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1317 make
1318
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001319 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1320 make test
1321
1322 # In this configuration, the TLS test programs use HMAC_DRBG.
1323 # The SSL tests are slow, so run a small subset, just enough to get
1324 # confidence that the SSL code copes with HMAC_DRBG.
1325 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001326 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001327
1328 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001329 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001330}
1331
1332component_test_no_hmac_drbg_classic () {
1333 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1334 scripts/config.py full
1335 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1336 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1337 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001338 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001339
1340 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1341 make
1342
1343 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001344 make test
1345
Gilles Peskinea2224342020-11-19 22:14:34 +01001346 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1347 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1348 # instead.
1349 # Test SSL with non-deterministic ECDSA. Only test features that
1350 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001351 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001352 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001353
1354 # To save time, only test one protocol version, since this part of
1355 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001356 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001357 tests/compat.sh -m tls12 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001358}
1359
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001360component_test_no_hmac_drbg_use_psa () {
1361 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1362 scripts/config.py full
1363 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1364 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1365 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1366
1367 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1368 make
1369
1370 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1371 make test
1372
1373 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1374 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1375 # instead.
1376 # Test SSL with non-deterministic ECDSA. Only test features that
1377 # might be affected by how ECDSA signature is performed.
1378 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001379 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001380
1381 # To save time, only test one protocol version, since this part of
1382 # the protocol is identical in (D)TLS up to 1.2.
1383 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001384 tests/compat.sh -m tls12 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001385}
1386
1387component_test_psa_external_rng_no_drbg_classic () {
1388 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1389 scripts/config.py full
1390 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001391 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001392 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001393 scripts/config.py unset MBEDTLS_ENTROPY_C
1394 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1395 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001396 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1397 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1398 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001399 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1400 # the SSL test programs don't have an RNG and can't work. Explicitly
1401 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1402 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001403
1404 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1405 make test
1406
Gilles Peskine8eb29432021-02-03 20:07:11 +01001407 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001408 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001409}
1410
1411component_test_psa_external_rng_no_drbg_use_psa () {
1412 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001413 scripts/config.py full
1414 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001415 scripts/config.py unset MBEDTLS_ENTROPY_C
1416 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1417 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001418 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1419 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1420 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskinec109b372020-11-23 17:39:04 +01001421 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1422
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001423 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001424 make test
1425
Gilles Peskine8eb29432021-02-03 20:07:11 +01001426 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001427 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001428}
1429
Gilles Peskine4bdb2542023-04-28 19:25:25 +02001430component_test_psa_external_rng_use_psa_crypto () {
1431 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1432 scripts/config.py full
1433 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1434 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1435 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1436 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1437
1438 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1439 make test
1440
1441 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1442 tests/ssl-opt.sh -f 'Default\|opaque'
1443}
1444
Gilles Peskine801c4332023-04-28 21:04:28 +02001445component_test_psa_inject_entropy () {
1446 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
1447 scripts/config.py full
1448 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
1449 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
1450 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1451 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1452 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
1453 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
1454 make CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
1455
1456 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
1457 make test
1458}
1459
Andrzej Kurek06969fc2023-04-12 10:34:50 -04001460component_test_sw_inet_pton () {
1461 msg "build: default plus MBEDTLS_TEST_SW_INET_PTON"
1462
1463 # MBEDTLS_TEST_HOOKS required for x509_crt_parse_cn_inet_pton
1464 scripts/config.py set MBEDTLS_TEST_HOOKS
1465 make CFLAGS="-DMBEDTLS_TEST_SW_INET_PTON"
1466
1467 msg "test: default plus MBEDTLS_TEST_SW_INET_PTON"
1468 make test
1469}
1470
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001471component_test_crypto_full_md_light_only () {
1472 msg "build: crypto_full with only the light subset of MD"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001473 scripts/config.py crypto_full
Gilles Peskine884b4622023-07-20 20:11:51 +02001474 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001475 # Disable MD
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001476 scripts/config.py unset MBEDTLS_MD_C
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001477 # Disable direct dependencies of MD_C
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001478 scripts/config.py unset MBEDTLS_HKDF_C
1479 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
Nick Child89e82e12022-11-09 10:36:10 -06001480 scripts/config.py unset MBEDTLS_PKCS7_C
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001481 # Disable indirect dependencies of MD_C
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001482 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001483 # Disable things that would auto-enable MD_C
1484 scripts/config.py unset MBEDTLS_PKCS5_C
1485
Manuel Pégourié-Gonnard1b5ffc62023-03-14 10:11:20 +01001486 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
1487 # which we haven't disabled, so no need to explicitly enable it.
1488 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001489
Manuel Pégourié-Gonnard0d415212023-02-23 13:02:13 +01001490 # Make sure we don't have the HMAC functions, but the hashing functions
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001491 not grep mbedtls_md_hmac library/md.o
Manuel Pégourié-Gonnard0d415212023-02-23 13:02:13 +01001492 grep mbedtls_md library/md.o
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001493
1494 msg "test: crypto_full with only the light subset of MD"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001495 make test
1496}
1497
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001498component_test_full_no_cipher () {
1499 msg "build: full minus CIPHER"
1500 scripts/config.py full
1501 scripts/config.py unset MBEDTLS_CIPHER_C
Gilles Peskine9b8dead2023-08-09 19:48:42 +02001502 # Don't pull in cipher via PSA mechanisms
1503 # (currently ignored anyway because we completely disable PSA)
1504 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Przemek Stekielda5f4832022-05-12 09:46:29 +02001505 # Direct dependencies
1506 scripts/config.py unset MBEDTLS_CCM_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001507 scripts/config.py unset MBEDTLS_CMAC_C
Przemek Stekielda5f4832022-05-12 09:46:29 +02001508 scripts/config.py unset MBEDTLS_GCM_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001509 scripts/config.py unset MBEDTLS_NIST_KW_C
1510 scripts/config.py unset MBEDTLS_PKCS12_C
1511 scripts/config.py unset MBEDTLS_PKCS5_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001512 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1513 scripts/config.py unset MBEDTLS_SSL_TLS_C
1514 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielda5f4832022-05-12 09:46:29 +02001515 # Indirect dependencies
1516 scripts/config.py unset MBEDTLS_SSL_CLI_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001517 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
1518 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001519 scripts/config.py unset MBEDTLS_SSL_DTLS_ANTI_REPLAY
1520 scripts/config.py unset MBEDTLS_SSL_DTLS_CONNECTION_ID
Dave Rodgman1df70702022-10-26 17:08:54 +01001521 scripts/config.py unset MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT
Przemek Stekielda5f4832022-05-12 09:46:29 +02001522 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1523 scripts/config.py unset MBEDTLS_SSL_SRV_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001524 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Raef Colesa7e03ad2022-09-28 09:32:48 +01001525 scripts/config.py unset MBEDTLS_LMS_C
Raef Coles47bccb72022-09-28 12:00:20 +01001526 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001527 make
1528
1529 msg "test: full minus CIPHER"
1530 make test
1531}
1532
Valerio Settie1655b82023-01-03 15:35:25 +01001533component_test_full_no_bignum () {
1534 msg "build: full minus bignum"
1535 scripts/config.py full
1536 scripts/config.py unset MBEDTLS_BIGNUM_C
1537 # Direct dependencies of bignum
1538 scripts/config.py unset MBEDTLS_ECP_C
1539 scripts/config.py unset MBEDTLS_RSA_C
1540 scripts/config.py unset MBEDTLS_DHM_C
1541 # Direct dependencies of ECP
1542 scripts/config.py unset MBEDTLS_ECDH_C
1543 scripts/config.py unset MBEDTLS_ECDSA_C
1544 scripts/config.py unset MBEDTLS_ECJPAKE_C
1545 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Setti22d0a792023-06-14 17:23:19 +02001546 # Disable what auto-enables ECP_LIGHT
1547 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1548 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
Valerio Settie1655b82023-01-03 15:35:25 +01001549 # Indirect dependencies of ECP
1550 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1551 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1552 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1553 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1554 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1555 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
1556 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
1557 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
1558 # Direct dependencies of DHM
1559 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1560 # Direct dependencies of RSA
1561 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1562 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1563 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1564 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1565 # PK and its dependencies
1566 scripts/config.py unset MBEDTLS_PK_C
1567 scripts/config.py unset MBEDTLS_PK_PARSE_C
1568 scripts/config.py unset MBEDTLS_PK_WRITE_C
1569 scripts/config.py unset MBEDTLS_X509_USE_C
1570 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
1571 scripts/config.py unset MBEDTLS_X509_CRL_PARSE_C
1572 scripts/config.py unset MBEDTLS_X509_CSR_PARSE_C
1573 scripts/config.py unset MBEDTLS_X509_CREATE_C
1574 scripts/config.py unset MBEDTLS_X509_CRT_WRITE_C
1575 scripts/config.py unset MBEDTLS_X509_CSR_WRITE_C
1576 scripts/config.py unset MBEDTLS_PKCS7_C
1577 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
1578 scripts/config.py unset MBEDTLS_SSL_ASYNC_PRIVATE
1579 scripts/config.py unset MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
1580
1581 make
1582
1583 msg "test: full minus bignum"
1584 make test
1585}
1586
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001587component_test_tls1_2_default_stream_cipher_only () {
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001588 msg "build: default with only stream cipher"
1589
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001590 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001591 scripts/config.py unset MBEDTLS_GCM_C
1592 scripts/config.py unset MBEDTLS_CCM_C
1593 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001594 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001595 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001596 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001597 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001598 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1599 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001600 # Modules that depend on AEAD
Przemek Stekield582a012022-09-28 07:59:01 +02001601 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001602 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001603
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001604 make
1605
1606 msg "test: default with only stream cipher"
1607 make test
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001608
1609 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001610}
1611
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001612component_test_tls1_2_default_stream_cipher_only_use_psa () {
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001613 msg "build: default with only stream cipher use psa"
Przemek Stekiel9550c052022-09-28 09:51:55 +02001614
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001615 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001616 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel9550c052022-09-28 09:51:55 +02001617 scripts/config.py unset MBEDTLS_GCM_C
1618 scripts/config.py unset MBEDTLS_CCM_C
1619 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001620 # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
Przemek Stekiel9550c052022-09-28 09:51:55 +02001621 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001622 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekiel9550c052022-09-28 09:51:55 +02001623 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001624 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1625 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001626 # Modules that depend on AEAD
Przemek Stekiel9550c052022-09-28 09:51:55 +02001627 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001628 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel9550c052022-09-28 09:51:55 +02001629
Przemek Stekiel9550c052022-09-28 09:51:55 +02001630 make
1631
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001632 msg "test: default with only stream cipher use psa"
Przemek Stekiel9550c052022-09-28 09:51:55 +02001633 make test
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001634
1635 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
Przemek Stekiel9550c052022-09-28 09:51:55 +02001636}
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001637
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001638component_test_tls1_2_default_cbc_legacy_cipher_only () {
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001639 msg "build: default with only CBC-legacy cipher"
1640
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001641 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001642 scripts/config.py unset MBEDTLS_GCM_C
1643 scripts/config.py unset MBEDTLS_CCM_C
1644 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001645 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1646 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1647 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001648 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001649 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001650 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001651 # Modules that depend on AEAD
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001652 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001653 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001654
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001655 make
1656
1657 msg "test: default with only CBC-legacy cipher"
1658 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001659
1660 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1661 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001662}
1663
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001664component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001665 msg "build: default with only CBC-legacy cipher use psa"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001666
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001667 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001668 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001669 scripts/config.py unset MBEDTLS_GCM_C
1670 scripts/config.py unset MBEDTLS_CCM_C
1671 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001672 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1673 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1674 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001675 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001676 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001677 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001678 # Modules that depend on AEAD
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001679 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001680 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001681
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001682 make
1683
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001684 msg "test: default with only CBC-legacy cipher use psa"
1685 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001686
1687 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1688 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001689}
1690
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001691component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001692 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1693
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001694 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001695 scripts/config.py unset MBEDTLS_GCM_C
1696 scripts/config.py unset MBEDTLS_CCM_C
1697 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001698 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1699 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1700 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1701 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1702 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001703 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001704 # Modules that depend on AEAD
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001705 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001706 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001707
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001708 make
1709
1710 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1711 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001712
1713 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1714 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001715}
1716
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001717component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
1718 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001719
1720 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001721 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001722 scripts/config.py unset MBEDTLS_GCM_C
1723 scripts/config.py unset MBEDTLS_CCM_C
1724 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001725 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1726 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1727 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1728 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1729 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001730 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001731 # Modules that depend on AEAD
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001732 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001733 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001734
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001735 make
1736
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001737 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001738 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001739
1740 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
1741 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001742}
1743
Valerio Setti9f0ec532022-11-08 13:03:24 +01001744# We're not aware of any other (open source) implementation of EC J-PAKE in TLS
1745# that we could use for interop testing. However, we now have sort of two
1746# implementations ourselves: one using PSA, the other not. At least test that
1747# these two interoperate with each other.
1748component_test_tls1_2_ecjpake_compatibility() {
1749 msg "build: TLS1.2 server+client w/ EC-JPAKE w/o USE_PSA"
1750 scripts/config.py set MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
Gilles Peskineedc84562023-09-20 15:03:18 +02001751 # Explicitly make lib first to avoid a race condition:
1752 # https://github.com/Mbed-TLS/mbedtls/issues/8229
1753 make lib
Valerio Setti9f0ec532022-11-08 13:03:24 +01001754 make -C programs ssl/ssl_server2 ssl/ssl_client2
1755 cp programs/ssl/ssl_server2 s2_no_use_psa
1756 cp programs/ssl/ssl_client2 c2_no_use_psa
1757
1758 msg "build: TLS1.2 server+client w/ EC-JPAKE w/ USE_PSA"
1759 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1760 make clean
Gilles Peskineedc84562023-09-20 15:03:18 +02001761 make lib
Valerio Setti9f0ec532022-11-08 13:03:24 +01001762 make -C programs ssl/ssl_server2 ssl/ssl_client2
1763 make -C programs test/udp_proxy test/query_compile_time_config
1764
Valerio Setti70e02902022-12-02 16:21:56 +01001765 msg "test: server w/o USE_PSA - client w/ USE_PSA, text password"
1766 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
1767 msg "test: server w/o USE_PSA - client w/ USE_PSA, opaque password"
1768 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password client only, working, TLS"
1769 msg "test: client w/o USE_PSA - server w/ USE_PSA, text password"
1770 P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
1771 msg "test: client w/o USE_PSA - server w/ USE_PSA, opaque password"
1772 P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password server only, working, TLS"
Valerio Setti9f0ec532022-11-08 13:03:24 +01001773
1774 rm s2_no_use_psa c2_no_use_psa
1775}
1776
Gilles Peskine636c26a2020-03-04 20:46:15 +01001777component_test_everest () {
1778 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine636c26a2020-03-04 20:46:15 +01001779 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1780 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1781 make
1782
1783 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1784 make test
1785
1786 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001787 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001788
1789 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1790 # Exclude some symmetric ciphers that are redundant here to gain time.
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02001791 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001792}
1793
Gilles Peskined3beca92020-07-03 00:15:37 +02001794component_test_everest_curve25519_only () {
1795 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
Gilles Peskined3beca92020-07-03 00:15:37 +02001796 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1797 scripts/config.py unset MBEDTLS_ECDSA_C
1798 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1799 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
TRodziewicz7c1d41d2021-04-23 13:33:44 +02001800 scripts/config.py unset MBEDTLS_ECJPAKE_C
Gilles Peskined3beca92020-07-03 00:15:37 +02001801 # Disable all curves
Valerio Setti2e0275d2023-07-28 16:33:13 +02001802 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
Gilles Peskined3beca92020-07-03 00:15:37 +02001803 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1804
1805 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1806
1807 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1808 make test
1809}
1810
Gilles Peskine8f073122018-11-27 15:58:47 +01001811component_test_small_ssl_out_content_len () {
1812 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001813 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1814 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001815 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1816 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001817
Gilles Peskine8f073122018-11-27 15:58:47 +01001818 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001819 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001820}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001821
Gilles Peskine8f073122018-11-27 15:58:47 +01001822component_test_small_ssl_in_content_len () {
1823 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001824 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1825 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001826 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1827 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001828
Gilles Peskine8f073122018-11-27 15:58:47 +01001829 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001830 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001831}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001832
Gilles Peskine8f073122018-11-27 15:58:47 +01001833component_test_small_ssl_dtls_max_buffering () {
1834 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001835 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001836 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1837 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001838
Gilles Peskine8f073122018-11-27 15:58:47 +01001839 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001840 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 +01001841}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001842
Gilles Peskine8f073122018-11-27 15:58:47 +01001843component_test_small_mbedtls_ssl_dtls_max_buffering () {
1844 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001845 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001846 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1847 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001848
Gilles Peskine8f073122018-11-27 15:58:47 +01001849 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001850 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001851}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001852
Gilles Peskine75cc7712019-09-06 19:47:17 +02001853component_test_psa_collect_statuses () {
1854 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001855 scripts/config.py full
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001856 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001857 # Check that psa_crypto_init() succeeded at least once
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001858 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001859 rm -f tests/statuses.log
1860}
1861
Gilles Peskine8f073122018-11-27 15:58:47 +01001862component_test_full_cmake_clang () {
1863 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001864 scripts/config.py full
Gilles Peskineda6017c2022-10-30 21:02:40 +01001865 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 +01001866 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001867
k-stachowiak0291cb72019-06-26 15:52:12 +02001868 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001869 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001870
Gilles Peskineda6017c2022-10-30 21:02:40 +01001871 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
1872 programs/test/cpp_dummy_build
1873
k-stachowiak0291cb72019-06-26 15:52:12 +02001874 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001875 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001876
Gilles Peskine8f073122018-11-27 15:58:47 +01001877 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001878 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001879
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02001880 msg "test: compat.sh NULL (full config)" # ~ 2 min
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01001881 env OPENSSL="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '^$' -f 'NULL'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001882
Gilles Peskine8f073122018-11-27 15:58:47 +01001883 msg "test: compat.sh ARIA + ChachaPoly"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01001884 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001885}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001886
Gilles Peskine0c671602022-11-29 16:01:41 +01001887skip_suites_without_constant_flow () {
1888 # Skip the test suites that don't have any constant-flow annotations.
1889 # This will need to be adjusted if we ever start declaring things as
1890 # secret from macros or functions inside tests/include or tests/src.
1891 SKIP_TEST_SUITES=$(
1892 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
1893 sed 's/test_suite_//; s/\.function$//' |
1894 tr '\n' ,)
1895 export SKIP_TEST_SUITES
1896}
1897
Dave Rodgman246210e2023-07-31 18:07:44 +01001898skip_all_except_given_suite () {
1899 # Skip all but the given test suite
1900 SKIP_TEST_SUITES=$(
1901 ls -1 tests/suites/test_suite_*.function |
1902 grep -v $1.function |
1903 sed 's/tests.suites.test_suite_//; s/\.function$//' |
1904 tr '\n' ,)
1905 export SKIP_TEST_SUITES
1906}
1907
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001908component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001909 # This tests both (1) accesses to undefined memory, and (2) branches or
1910 # memory access depending on secret values. To distinguish between those:
1911 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1912 # - or alternatively, change the build type to MemSanDbg, which enables
1913 # origin tracking and nicer stack traces (which are useful for debugging
1914 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001915 msg "build: cmake MSan (clang), full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
1916 scripts/config.py full
1917 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1918 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1919 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1920 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1921 make
1922
1923 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO, Msan + constant flow)"
1924 make test
1925}
1926
1927component_test_memsan_constant_flow_psa () {
1928 # This tests both (1) accesses to undefined memory, and (2) branches or
1929 # memory access depending on secret values. To distinguish between those:
1930 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1931 # - or alternatively, change the build type to MemSanDbg, which enables
1932 # origin tracking and nicer stack traces (which are useful for debugging
1933 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001934 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001935 scripts/config.py full
1936 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1937 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1938 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1939 make
1940
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001941 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001942 make test
1943}
1944
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001945component_test_valgrind_constant_flow () {
1946 # This tests both (1) everything that valgrind's memcheck usually checks
1947 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1948 # etc.) and (2) branches or memory access depending on secret values,
1949 # which will be reported as uninitialized memory. To distinguish between
1950 # secret and actually uninitialized:
1951 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1952 # - or alternatively, build with debug info and manually run the offending
1953 # test suite with valgrind --track-origins=yes, then check if the origin
1954 # was TEST_CF_SECRET() or something else.
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001955 msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
1956 scripts/config.py full
1957 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
1958 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine0c671602022-11-29 16:01:41 +01001959 skip_suites_without_constant_flow
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001960 cmake -D CMAKE_BUILD_TYPE:String=Release .
1961 make
1962
1963 # this only shows a summary of the results (how many of each type)
1964 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine0c671602022-11-29 16:01:41 +01001965 msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, valgrind + constant flow)"
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001966 make memcheck
Dave Rodgman246210e2023-07-31 18:07:44 +01001967
1968 # Test asm path in constant time module - by default, it will test the plain C
1969 # path under Valgrind or Memsan. Running only the constant_time tests is fast (<1s)
1970 msg "test: valgrind asm constant_time"
1971 scripts/config.py --force set MBEDTLS_TEST_CONSTANT_FLOW_ASM
1972 skip_all_except_given_suite test_suite_constant_time
1973 cmake -D CMAKE_BUILD_TYPE:String=Release .
1974 make clean
1975 make
1976 make memcheck
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001977}
1978
1979component_test_valgrind_constant_flow_psa () {
1980 # This tests both (1) everything that valgrind's memcheck usually checks
1981 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1982 # etc.) and (2) branches or memory access depending on secret values,
1983 # which will be reported as uninitialized memory. To distinguish between
1984 # secret and actually uninitialized:
1985 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1986 # - or alternatively, build with debug info and manually run the offending
1987 # test suite with valgrind --track-origins=yes, then check if the origin
1988 # was TEST_CF_SECRET() or something else.
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001989 msg "build: cmake release GCC, full config with constant flow testing"
1990 scripts/config.py full
1991 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Gilles Peskine0c671602022-11-29 16:01:41 +01001992 skip_suites_without_constant_flow
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001993 cmake -D CMAKE_BUILD_TYPE:String=Release .
1994 make
1995
1996 # this only shows a summary of the results (how many of each type)
1997 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine0c671602022-11-29 16:01:41 +01001998 msg "test: some suites (valgrind + constant flow)"
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001999 make memcheck
2000}
2001
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002002component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02002003 # Test that removing the deprecated features from the default
2004 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002005 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
2006 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
2007 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
2008
2009 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
2010 make test
2011}
2012
2013component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02002014 msg "build: make, full_no_deprecated config" # ~ 30s
2015 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002016 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
2017
Gilles Peskine30de2e82020-04-20 21:39:22 +02002018 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002019 make test
Valerio Setti41b5fb62023-01-09 12:20:45 +01002020
2021 msg "test: ensure that X509 has no direct dependency on BIGNUM_C"
2022 not grep mbedtls_mpi library/libmbedx509.a
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002023}
2024
Gilles Peskine8386ea22020-04-30 09:07:29 +02002025component_test_full_no_deprecated_deprecated_warning () {
2026 # Test that there is nothing deprecated in "full_no_deprecated".
2027 # A deprecated feature would trigger a warning (made fatal) from
2028 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02002029 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
2030 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002031 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
2032 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
2033 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
2034
Gilles Peskine30de2e82020-04-20 21:39:22 +02002035 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002036 make test
2037}
2038
Gilles Peskine8386ea22020-04-30 09:07:29 +02002039component_test_full_deprecated_warning () {
2040 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
2041 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002042 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002043 scripts/config.py full
2044 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002045 # Expect warnings from '#warning' directives in check_config.h.
2046 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01002047
Gilles Peskine8386ea22020-04-30 09:07:29 +02002048 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
2049 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
2050 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002051 # Expect warnings from '#warning' directives in check_config.h and
2052 # from the use of deprecated functions in test suites.
2053 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 +01002054
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002055 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
2056 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01002057}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00002058
Gilles Peskineec541fe2020-01-31 14:24:14 +01002059# Check that the specified libraries exist and are empty.
2060are_empty_libraries () {
2061 nm "$@" >/dev/null 2>/dev/null
2062 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
2063}
2064
2065component_build_crypto_default () {
2066 msg "build: make, crypto only"
2067 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01002068 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002069 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002070}
2071
2072component_build_crypto_full () {
2073 msg "build: make, crypto only, full config"
2074 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01002075 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002076 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002077}
2078
Gilles Peskinefc4f11b2022-10-21 19:34:54 +02002079component_test_crypto_for_psa_service () {
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002080 msg "build: make, config for PSA crypto service"
2081 scripts/config.py crypto
2082 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
2083 # Disable things that are not needed for just cryptography, to
2084 # reach a configuration that would be typical for a PSA cryptography
2085 # service providing all implemented PSA algorithms.
2086 # System stuff
2087 scripts/config.py unset MBEDTLS_ERROR_C
2088 scripts/config.py unset MBEDTLS_TIMING_C
Gilles Peskine78bffd12022-10-25 21:02:33 +02002089 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002090 # Crypto stuff with no PSA interface
2091 scripts/config.py unset MBEDTLS_BASE64_C
Gilles Peskine649e04e2022-10-25 21:05:57 +02002092 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
Gilles Peskineb06f0712022-10-25 21:06:11 +02002093 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
Gilles Peskine649e04e2022-10-25 21:05:57 +02002094 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002095 scripts/config.py unset MBEDTLS_NIST_KW_C
2096 scripts/config.py unset MBEDTLS_PEM_PARSE_C
2097 scripts/config.py unset MBEDTLS_PEM_WRITE_C
2098 scripts/config.py unset MBEDTLS_PKCS12_C
2099 scripts/config.py unset MBEDTLS_PKCS5_C
Gilles Peskinefcee7402022-10-11 21:15:24 +02002100 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
2101 # in PSA code to work with RSA keys. We don't require users to set those:
2102 # they will be reenabled in build_info.h.
Gilles Peskine1f108072022-10-25 21:02:56 +02002103 scripts/config.py unset MBEDTLS_PK_C
Gilles Peskinefcee7402022-10-11 21:15:24 +02002104 scripts/config.py unset MBEDTLS_PK_PARSE_C
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002105 scripts/config.py unset MBEDTLS_PK_WRITE_C
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002106 make CFLAGS='-O1 -Werror' all test
2107 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
2108}
2109
Gilles Peskineec541fe2020-01-31 14:24:14 +01002110component_build_crypto_baremetal () {
2111 msg "build: make, crypto only, baremetal config"
2112 scripts/config.py crypto_baremetal
David Horstmann61faf662021-11-30 11:40:54 +00002113 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002114 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002115}
Daniel Axtens446af202020-09-02 21:30:13 +10002116support_build_crypto_baremetal () {
Daniel Axtens814c8132020-08-31 14:22:58 +10002117 support_build_baremetal "$@"
2118}
2119
2120component_build_baremetal () {
2121 msg "build: make, baremetal config"
2122 scripts/config.py baremetal
David Horstmann61faf662021-11-30 11:40:54 +00002123 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Daniel Axtens814c8132020-08-31 14:22:58 +10002124}
2125support_build_baremetal () {
Daniel Axtens446af202020-09-02 21:30:13 +10002126 # Older Glibc versions include time.h from other headers such as stdlib.h,
2127 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
2128 # problem, Ubuntu 18.04 is ok.
2129 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
2130}
Gilles Peskineec541fe2020-01-31 14:24:14 +01002131
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002132# depends.py family of tests
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002133component_test_depends_py_cipher_id () {
2134 msg "test/build: depends.py cipher_id (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002135 tests/scripts/depends.py cipher_id --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002136}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00002137
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002138component_test_depends_py_cipher_chaining () {
2139 msg "test/build: depends.py cipher_chaining (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002140 tests/scripts/depends.py cipher_chaining --unset-use-psa
John Durkopc14be902020-08-20 06:16:41 -07002141}
2142
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002143component_test_depends_py_cipher_padding () {
2144 msg "test/build: depends.py cipher_padding (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002145 tests/scripts/depends.py cipher_padding --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002146}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00002147
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002148component_test_depends_py_curves () {
2149 msg "test/build: depends.py curves (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002150 tests/scripts/depends.py curves --unset-use-psa
John Durkop2ec2eaa2020-08-24 18:29:15 -07002151}
2152
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002153component_test_depends_py_hashes () {
2154 msg "test/build: depends.py hashes (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002155 tests/scripts/depends.py hashes --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002156}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002157
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002158component_test_depends_py_kex () {
2159 msg "test/build: depends.py kex (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002160 tests/scripts/depends.py kex --unset-use-psa
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002161}
2162
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002163component_test_depends_py_pkalgs () {
2164 msg "test/build: depends.py pkalgs (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002165 tests/scripts/depends.py pkalgs --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002166}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002167
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002168# PSA equivalents of the depends.py tests
2169component_test_depends_py_cipher_id_psa () {
2170 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2171 tests/scripts/depends.py cipher_id
2172}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002173
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002174component_test_depends_py_cipher_chaining_psa () {
2175 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2176 tests/scripts/depends.py cipher_chaining
2177}
2178
2179component_test_depends_py_cipher_padding_psa () {
2180 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2181 tests/scripts/depends.py cipher_padding
2182}
2183
2184component_test_depends_py_curves_psa () {
2185 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2186 tests/scripts/depends.py curves
2187}
2188
2189component_test_depends_py_hashes_psa () {
2190 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2191 tests/scripts/depends.py hashes
2192}
2193
2194component_test_depends_py_kex_psa () {
2195 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2196 tests/scripts/depends.py kex
2197}
2198
2199component_test_depends_py_pkalgs_psa () {
2200 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002201 tests/scripts/depends.py pkalgs
Gilles Peskine8f073122018-11-27 15:58:47 +01002202}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002203
Dave Rodgman1a034dc2023-01-20 13:18:05 +00002204component_build_no_pk_rsa_alt_support () {
2205 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
2206
2207 scripts/config.py full
2208 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
2209 scripts/config.py set MBEDTLS_RSA_C
2210 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
2211
2212 # Only compile - this is primarily to test for compile issues
2213 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
2214}
2215
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002216component_build_module_alt () {
2217 msg "build: MBEDTLS_XXX_ALT" # ~30s
2218 scripts/config.py full
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002219
2220 # Disable options that are incompatible with some ALT implementations:
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002221 # aesni.c and padlock.c reference mbedtls_aes_context fields directly.
2222 scripts/config.py unset MBEDTLS_AESNI_C
2223 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08002224 scripts/config.py unset MBEDTLS_AESCE_C
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002225 # MBEDTLS_ECP_RESTARTABLE is documented as incompatible.
2226 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002227 # You can only have one threading implementation: alt or pthread, not both.
2228 scripts/config.py unset MBEDTLS_THREADING_PTHREAD
Gilles Peskine5c3f18d2021-05-31 21:21:12 +02002229 # The SpecifiedECDomain parsing code accesses mbedtls_ecp_group fields
2230 # directly and assumes the implementation works with partial groups.
2231 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
Tom Cosgrovef3ebd902022-02-20 22:25:31 +00002232 # MBEDTLS_SHA256_*ALT can't be used with MBEDTLS_SHA256_USE_A64_CRYPTO_*
2233 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2234 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00002235 # MBEDTLS_SHA512_*ALT can't be used with MBEDTLS_SHA512_USE_A64_CRYPTO_*
2236 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2237 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002238
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002239 # Enable all MBEDTLS_XXX_ALT for whole modules. Do not enable
2240 # MBEDTLS_XXX_YYY_ALT which are for single functions.
2241 scripts/config.py set-all 'MBEDTLS_([A-Z0-9]*|NIST_KW)_ALT'
Gilles Peskine1628a9c2021-05-31 22:09:58 +02002242 scripts/config.py unset MBEDTLS_DHM_ALT #incompatible with MBEDTLS_DEBUG_C
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002243
Gilles Peskine1628a9c2021-05-31 22:09:58 +02002244 # We can only compile, not link, since we don't have any implementations
2245 # suitable for testing with the dummy alt headers.
2246 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
2247}
2248
2249component_build_dhm_alt () {
2250 msg "build: MBEDTLS_DHM_ALT" # ~30s
2251 scripts/config.py full
2252 scripts/config.py set MBEDTLS_DHM_ALT
2253 # debug.c currently references mbedtls_dhm_context fields directly.
2254 scripts/config.py unset MBEDTLS_DEBUG_C
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002255 # We can only compile, not link, since we don't have any implementations
2256 # suitable for testing with the dummy alt headers.
2257 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
2258}
2259
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002260component_test_no_use_psa_crypto_full_cmake_asan() {
2261 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02002262 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002263 scripts/config.py full
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002264 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
2265 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cron6f135e12021-12-08 16:57:54 +01002266 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002267 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02002268 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002269 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Raef Colesa7e03ad2022-09-28 09:32:48 +01002270 scripts/config.py unset MBEDTLS_LMS_C
Raef Coles47bccb72022-09-28 12:00:20 +01002271 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01002272 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002273 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02002274
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002275 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002276 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02002277
Manuel Pégourié-Gonnard182a23b2022-12-07 10:38:43 +01002278 # Note: ssl-opt.sh has some test cases that depend on
2279 # MBEDTLS_ECP_RESTARTABLE && !MBEDTLS_USE_PSA_CRYPTO
2280 # This is the only component where those tests are not skipped.
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002281 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002282 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002283
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002284 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002285 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04002286
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02002287 msg "test: compat.sh NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01002288 env OPENSSL="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -f 'NULL'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002289
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002290 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01002291 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002292}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002293
Ronald Cron403c15c2021-09-13 09:38:05 +02002294component_test_psa_crypto_config_accel_ecdsa () {
Valerio Setti5aab43f2023-03-29 10:42:07 +02002295 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
Ronald Cron403c15c2021-09-13 09:38:05 +02002296
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002297 # Algorithms and key types to accelerate
Valerio Settic0d2f842023-06-28 10:48:08 +02002298 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
Valerio Setti0a342c92023-09-01 09:12:31 +02002299 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002300
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002301 # Note: Those are handled in a special way by the libtestdriver machinery,
2302 # so we only want to include them in the accel list when building the main
2303 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002304 loc_curve_list="$(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002305
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002306 # Configure
2307 # ---------
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002308
Manuel Pégourié-Gonnard8d645dc2023-06-15 09:07:10 +02002309 # Start from default config (no USE_PSA) + TLS 1.3
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002310 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard6d7db932022-12-28 09:48:01 +01002311 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002312
2313 # Disable the module that's accelerated
Ronald Cron403c15c2021-09-13 09:38:05 +02002314 scripts/config.py unset MBEDTLS_ECDSA_C
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002315
2316 # Disable things that depend on it
Ronald Cron403c15c2021-09-13 09:38:05 +02002317 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2318 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2319
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002320 # Build
2321 # -----
2322
2323 # These hashes are needed for some ECDSA signature tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02002324 loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2325 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002326
2327 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2328
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002329 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02002330
Manuel Pégourié-Gonnarde3095e72022-12-28 10:09:53 +01002331 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine827dbd92022-02-04 00:30:54 +01002332 not grep mbedtls_ecdsa_ library/ecdsa.o
Ronald Cron403c15c2021-09-13 09:38:05 +02002333
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002334 # Run the tests
2335 # -------------
2336
Ronald Cron403c15c2021-09-13 09:38:05 +02002337 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
2338 make test
2339}
2340
Valerio Setti44b178c2023-03-22 14:02:57 +01002341component_test_psa_crypto_config_accel_ecdh () {
Valerio Setti5aab43f2023-03-29 10:42:07 +02002342 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002343
2344 # Algorithms and key types to accelerate
Valerio Settic0d2f842023-06-28 10:48:08 +02002345 loc_accel_list="ALG_ECDH \
Valerio Setti0a342c92023-09-01 09:12:31 +02002346 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002347
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002348 # Note: Those are handled in a special way by the libtestdriver machinery,
2349 # so we only want to include them in the accel list when building the main
2350 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002351 loc_curve_list="$(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002352
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002353 # Configure
2354 # ---------
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002355
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002356 # Start from default config (no TLS 1.3, no USE_PSA)
2357 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002358
Valerio Setti44b178c2023-03-22 14:02:57 +01002359 # Disable the module that's accelerated
2360 scripts/config.py unset MBEDTLS_ECDH_C
2361
2362 # Disable things that depend on it
2363 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2364 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2365 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2366 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2367 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2368
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002369 # Build
2370 # -----
2371
2372 helper_libtestdriver1_make_drivers "$loc_accel_list"
2373
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002374 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002375
Valerio Setti44b178c2023-03-22 14:02:57 +01002376 # Make sure this was not re-enabled by accident (additive config)
2377 not grep mbedtls_ecdh_ library/ecdh.o
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002378
2379 # Run the tests
2380 # -------------
2381
Valerio Setti44b178c2023-03-22 14:02:57 +01002382 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002383 make test
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +01002384}
2385
Przemek Stekieldccb2022023-05-11 10:48:50 +02002386component_test_psa_crypto_config_accel_ffdh () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002387 msg "build: full with accelerated FFDH"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002388
2389 # Algorithms and key types to accelerate
Valerio Setti27602c32023-07-10 16:38:59 +02002390 loc_accel_list="ALG_FFDH \
Valerio Setti0a342c92023-09-01 09:12:31 +02002391 $(helper_get_psa_key_type_list "DH")"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002392
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002393 # Configure
2394 # ---------
Przemek Stekieldccb2022023-05-11 10:48:50 +02002395
Przemek Stekiel565353e2023-07-05 11:07:07 +02002396 # start with full (USE_PSA and TLS 1.3)
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002397 helper_libtestdriver1_adjust_config "full"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002398
2399 # Disable the module that's accelerated
2400 scripts/config.py unset MBEDTLS_DHM_C
2401
2402 # Disable things that depend on it
2403 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2404 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2405
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002406 # Build
2407 # -----
2408
2409 helper_libtestdriver1_make_drivers "$loc_accel_list"
2410
Manuel Pégourié-Gonnard981732e2023-06-08 09:15:59 +02002411 helper_libtestdriver1_make_main "$loc_accel_list"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002412
2413 # Make sure this was not re-enabled by accident (additive config)
2414 not grep mbedtls_dhm_ library/dhm.o
2415
2416 # Run the tests
2417 # -------------
2418
Gilles Peskine14302ed2023-07-19 19:30:04 +02002419 msg "test: full with accelerated FFDH"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002420 make test
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002421
Gilles Peskine14302ed2023-07-19 19:30:04 +02002422 msg "ssl-opt: full with accelerated FFDH alg"
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002423 tests/ssl-opt.sh -f "ffdh"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002424}
2425
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002426component_test_psa_crypto_config_reference_ffdh () {
Gilles Peskineb7d577e2023-08-09 19:48:58 +02002427 msg "build: full with non-accelerated FFDH"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002428
2429 # Start with full (USE_PSA and TLS 1.3)
Przemek Stekiel565353e2023-07-05 11:07:07 +02002430 helper_libtestdriver1_adjust_config "full"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002431
2432 # Disable things that are not supported
2433 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2434 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002435 make
2436
Gilles Peskine14302ed2023-07-19 19:30:04 +02002437 msg "test suites: full with non-accelerated FFDH alg"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002438 make test
2439
Gilles Peskine14302ed2023-07-19 19:30:04 +02002440 msg "ssl-opt: full with non-accelerated FFDH alg"
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002441 tests/ssl-opt.sh -f "ffdh"
Valerio Setti42d5f192023-03-20 13:54:41 +01002442}
2443
Valerio Setti44b178c2023-03-22 14:02:57 +01002444component_test_psa_crypto_config_accel_pake() {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002445 msg "build: full with accelerated PAKE"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002446
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002447 loc_accel_list="ALG_JPAKE \
2448 $(helper_get_psa_key_type_list "ECC")"
2449
2450 # Note: Those are handled in a special way by the libtestdriver machinery,
2451 # so we only want to include them in the accel list when building the main
2452 # libraries, hence the use of a separate variable.
2453 loc_curve_list="$(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002454
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002455 # Configure
2456 # ---------
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002457
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002458 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002459
2460 # Make built-in fallback not available
2461 scripts/config.py unset MBEDTLS_ECJPAKE_C
2462 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
2463
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002464 # Build
2465 # -----
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002466
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002467 helper_libtestdriver1_make_drivers "$loc_accel_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002468
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002469 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002470
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002471 # Make sure this was not re-enabled by accident (additive config)
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002472 not grep mbedtls_ecjpake_init library/ecjpake.o
2473
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002474 # Run the tests
2475 # -------------
2476
Gilles Peskine14302ed2023-07-19 19:30:04 +02002477 msg "test: full with accelerated PAKE"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002478 make test
2479}
2480
Manuel Pégourié-Gonnard5c210362023-09-26 12:03:10 +02002481component_test_psa_crypto_config_accel_ecc_some_key_types () {
2482 msg "build: full with accelerated EC algs and some key types"
2483
2484 # Algorithms and key types to accelerate
2485 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
2486 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2487 ALG_ECDH \
2488 ALG_JPAKE \
2489 KEY_TYPE_ECC_PUBLIC_KEY \
2490 KEY_TYPE_ECC_KEY_PAIR_BASIC \
2491 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
2492 KEY_TYPE_ECC_KEY_PAIR_EXPORT"
2493
2494 # Note: Curves are handled in a special way by the libtestdriver machinery,
2495 # so we only want to include them in the accel list when building the main
2496 # libraries, hence the use of a separate variable.
2497 loc_curve_list="$(helper_get_psa_curve_list)"
2498
2499 # Configure
2500 # ---------
2501
2502 # start with config full for maximum coverage (also enables USE_PSA)
2503 helper_libtestdriver1_adjust_config "full"
2504
2505 # Disable modules that are accelerated - some will be re-enabled
2506 scripts/config.py unset MBEDTLS_ECDSA_C
2507 scripts/config.py unset MBEDTLS_ECDH_C
2508 scripts/config.py unset MBEDTLS_ECJPAKE_C
2509 scripts/config.py unset MBEDTLS_ECP_C
2510
2511 # Disable all curves - those that aren't accelerated should be re-enabled
2512 helper_disable_builtin_curves
2513
2514 # Restartable feature is not yet supported by PSA. Once it will in
2515 # the future, the following line could be removed (see issues
2516 # 6061, 6332 and following ones)
2517 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2518
2519 # this is not supported by the driver API yet
2520 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2521
2522 # Build
2523 # -----
2524
2525 # These hashes are needed for some ECDSA signature tests.
2526 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2527 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2528 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2529
2530 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
2531
2532 # ECP should be re-enabled but not the others
2533 not grep mbedtls_ecdh_ library/ecdh.o
2534 not grep mbedtls_ecdsa library/ecdsa.o
2535 not grep mbedtls_ecjpake library/ecjpake.o
2536 grep mbedtls_ecp library/ecp.o
2537
2538 # Run the tests
2539 # -------------
2540
2541 msg "test suites: full with accelerated EC algs and some key types"
2542 make test
2543}
2544
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002545# Run tests with only (non-)Weierstrass accelerated
2546# Common code used in:
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002547# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
2548# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002549common_test_psa_crypto_config_accel_ecc_some_curves () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002550 weierstrass=$1
2551 if [ $weierstrass -eq 1 ]; then
2552 desc="Weierstrass"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002553 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002554 desc="non-Weierstrass"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002555 fi
2556
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002557 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002558
2559 # Algorithms and key types to accelerate
2560 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2561 ALG_ECDH \
2562 ALG_JPAKE \
2563 $(helper_get_psa_key_type_list "ECC")"
2564
2565 # Note: Curves are handled in a special way by the libtestdriver machinery,
2566 # so we only want to include them in the accel list when building the main
2567 # libraries, hence the use of a separate variable.
2568 # Note: the following loop is a modified version of
2569 # helper_get_psa_curve_list that only keeps Weierstrass families.
2570 loc_weierstrass_list=""
2571 loc_non_weierstrass_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002572 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
2573 case $item in
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002574 ECC_BRAINPOOL*|ECC_SECP*)
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002575 loc_weierstrass_list="$loc_weierstrass_list $item"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002576 ;;
2577 *)
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002578 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002579 ;;
2580 esac
2581 done
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002582 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002583 loc_curve_list=$loc_weierstrass_list
2584 else
2585 loc_curve_list=$loc_non_weierstrass_list
2586 fi
2587
2588 # Configure
2589 # ---------
2590
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002591 # Start with config crypto_full and remove PK_C:
2592 # that's what's supported now, see docs/driver-only-builds.md.
2593 helper_libtestdriver1_adjust_config "crypto_full"
2594 scripts/config.py unset MBEDTLS_PK_C
2595 scripts/config.py unset MBEDTLS_PK_PARSE_C
2596 scripts/config.py unset MBEDTLS_PK_WRITE_C
2597 # We need to disable RSA too or PK will be re-enabled.
2598 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
2599 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
2600 scripts/config.py unset MBEDTLS_RSA_C
2601 scripts/config.py unset MBEDTLS_PKCS1_V15
2602 scripts/config.py unset MBEDTLS_PKCS1_V21
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002603
2604 # Disable modules that are accelerated - some will be re-enabled
2605 scripts/config.py unset MBEDTLS_ECDSA_C
2606 scripts/config.py unset MBEDTLS_ECDH_C
2607 scripts/config.py unset MBEDTLS_ECJPAKE_C
2608 scripts/config.py unset MBEDTLS_ECP_C
2609
2610 # Disable all curves - those that aren't accelerated should be re-enabled
2611 helper_disable_builtin_curves
2612
2613 # Restartable feature is not yet supported by PSA. Once it will in
2614 # the future, the following line could be removed (see issues
2615 # 6061, 6332 and following ones)
2616 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2617
2618 # this is not supported by the driver API yet
2619 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2620
2621 # Build
2622 # -----
2623
2624 # These hashes are needed for some ECDSA signature tests.
2625 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2626 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2627 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2628
2629 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
2630
2631 # We expect ECDH to be re-enabled for the missing curves
2632 grep mbedtls_ecdh_ library/ecdh.o
2633 # We expect ECP to be re-enabled, however the parts specific to the
2634 # families of curves that are accelerated should be ommited.
2635 # - functions with mxz in the name are specific to Montgomery curves
2636 # - ecp_muladd is specific to Weierstrass curves
2637 ##nm library/ecp.o | tee ecp.syms
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002638 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002639 not grep mbedtls_ecp_muladd library/ecp.o
2640 grep mxz library/ecp.o
2641 else
2642 grep mbedtls_ecp_muladd library/ecp.o
2643 not grep mxz library/ecp.o
2644 fi
2645 # We expect ECDSA and ECJPAKE to be re-enabled only when
2646 # Weierstrass curves are not accelerated
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002647 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002648 not grep mbedtls_ecdsa library/ecdsa.o
2649 not grep mbedtls_ecjpake library/ecjpake.o
2650 else
2651 grep mbedtls_ecdsa library/ecdsa.o
2652 grep mbedtls_ecjpake library/ecjpake.o
2653 fi
2654
2655 # Run the tests
2656 # -------------
2657
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002658 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
2659 make test
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002660}
2661
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002662component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002663 common_test_psa_crypto_config_accel_ecc_some_curves 1
2664}
2665
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002666component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002667 common_test_psa_crypto_config_accel_ecc_some_curves 0
2668}
2669
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002670# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
2671# ECDH, ECDSA) with and without drivers.
2672# The input parameter is a boolean value which indicates:
2673# - 0 keep built-in EC algs,
2674# - 1 exclude built-in EC algs (driver only).
2675#
2676# This is used by the two following components to ensure they always use the
2677# same config, except for the use of driver or built-in EC algorithms:
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002678# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
2679# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002680# This supports comparing their test coverage with analyze_outcomes.py.
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02002681config_psa_crypto_config_ecp_light_only () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002682 driver_only="$1"
Valerio Setti42d5f192023-03-20 13:54:41 +01002683 # start with config full for maximum coverage (also enables USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002684 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002685 if [ "$driver_only" -eq 1 ]; then
Valerio Setti42d5f192023-03-20 13:54:41 +01002686 # Disable modules that are accelerated
2687 scripts/config.py unset MBEDTLS_ECDSA_C
2688 scripts/config.py unset MBEDTLS_ECDH_C
2689 scripts/config.py unset MBEDTLS_ECJPAKE_C
Valerio Setti29b395c2023-04-05 18:20:30 +02002690 scripts/config.py unset MBEDTLS_ECP_C
Valerio Setti42d5f192023-03-20 13:54:41 +01002691 fi
2692
2693 # Restartable feature is not yet supported by PSA. Once it will in
2694 # the future, the following line could be removed (see issues
2695 # 6061, 6332 and following ones)
2696 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Setti42d5f192023-03-20 13:54:41 +01002697}
2698
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002699# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
2700component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002701 msg "build: full with accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002702
2703 # Algorithms and key types to accelerate
2704 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2705 ALG_ECDH \
2706 ALG_JPAKE \
Valerio Setti0a342c92023-09-01 09:12:31 +02002707 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002708
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002709 # Note: Those are handled in a special way by the libtestdriver machinery,
2710 # so we only want to include them in the accel list when building the main
2711 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002712 loc_curve_list="$(helper_get_psa_curve_list)"
Valerio Setti42d5f192023-03-20 13:54:41 +01002713
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002714 # Configure
2715 # ---------
Valerio Setti42d5f192023-03-20 13:54:41 +01002716
2717 # Use the same config as reference, only without built-in EC algs
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02002718 config_psa_crypto_config_ecp_light_only 1
Valerio Setti42d5f192023-03-20 13:54:41 +01002719
Valerio Setti0a342c92023-09-01 09:12:31 +02002720 # Do not disable builtin curves because that support is required for:
Valerio Settib2fd6732023-08-15 17:10:47 +02002721 # - MBEDTLS_PK_PARSE_EC_EXTENDED
2722 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
Valerio Setti42d5f192023-03-20 13:54:41 +01002723
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002724 # Build
2725 # -----
2726
2727 # These hashes are needed for some ECDSA signature tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02002728 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2729 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002730 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2731
Valerio Settib2fd6732023-08-15 17:10:47 +02002732 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Valerio Setti42d5f192023-03-20 13:54:41 +01002733
2734 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
2735 not grep mbedtls_ecdsa_ library/ecdsa.o
2736 not grep mbedtls_ecdh_ library/ecdh.o
2737 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Setti29b395c2023-04-05 18:20:30 +02002738 not grep mbedtls_ecp_mul library/ecp.o
Valerio Setti42d5f192023-03-20 13:54:41 +01002739
2740 # Run the tests
2741 # -------------
2742
Gilles Peskine14302ed2023-07-19 19:30:04 +02002743 msg "test suites: full with accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002744 make test
2745
Gilles Peskine14302ed2023-07-19 19:30:04 +02002746 msg "ssl-opt: full with accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002747 tests/ssl-opt.sh
2748}
2749
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002750# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
2751component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002752 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002753
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02002754 config_psa_crypto_config_ecp_light_only 0
Valerio Setti42d5f192023-03-20 13:54:41 +01002755
2756 make
2757
Gilles Peskine14302ed2023-07-19 19:30:04 +02002758 msg "test suites: full with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002759 make test
2760
Gilles Peskine14302ed2023-07-19 19:30:04 +02002761 msg "ssl-opt: full with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002762 tests/ssl-opt.sh
2763}
2764
Valerio Settie618cb02023-04-12 14:59:16 +02002765# This helper function is used by:
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002766# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
2767# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Valerio Settie618cb02023-04-12 14:59:16 +02002768# to ensure that both tests use the same underlying configuration when testing
2769# driver's coverage with analyze_outcomes.py.
2770#
2771# This functions accepts 1 boolean parameter as follows:
2772# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
2773# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
2774# - 0: include built-in implementation of EC algorithms.
2775#
2776# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
2777# on the ECP module.
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002778config_psa_crypto_no_ecp_at_all () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002779 driver_only="$1"
Valerio Settiaafe9002023-06-26 15:23:44 +02002780 # start with full config for maximum coverage (also enables USE_PSA)
2781 helper_libtestdriver1_adjust_config "full"
2782
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002783 if [ "$driver_only" -eq 1 ]; then
Valerio Settie618cb02023-04-12 14:59:16 +02002784 # Disable modules that are accelerated
2785 scripts/config.py unset MBEDTLS_ECDSA_C
2786 scripts/config.py unset MBEDTLS_ECDH_C
2787 scripts/config.py unset MBEDTLS_ECJPAKE_C
2788 # Disable ECP module (entirely)
2789 scripts/config.py unset MBEDTLS_ECP_C
Valerio Settie618cb02023-04-12 14:59:16 +02002790 fi
2791
Valerio Settiaecd32c2023-06-14 10:42:31 +02002792 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
2793 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
Valerio Settiaddeee42023-06-14 10:46:55 +02002794 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
Ronald Cron6b49b552023-07-20 09:57:54 +02002795 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Valerio Settiaecd32c2023-06-14 10:42:31 +02002796
Valerio Settie618cb02023-04-12 14:59:16 +02002797 # Restartable feature is not yet supported by PSA. Once it will in
2798 # the future, the following line could be removed (see issues
2799 # 6061, 6332 and following ones)
2800 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Settie618cb02023-04-12 14:59:16 +02002801}
2802
2803# Build and test a configuration where driver accelerates all EC algs while
2804# all support and dependencies from ECP and ECP_LIGHT are removed on the library
2805# side.
2806#
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002807# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
2808component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002809 msg "build: full + accelerated EC algs - ECP"
Valerio Settie618cb02023-04-12 14:59:16 +02002810
2811 # Algorithms and key types to accelerate
2812 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2813 ALG_ECDH \
2814 ALG_JPAKE \
Valerio Setti0a342c92023-09-01 09:12:31 +02002815 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002816
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002817 # Note: Those are handled in a special way by the libtestdriver machinery,
2818 # so we only want to include them in the accel list when building the main
2819 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002820 loc_curve_list="$(helper_get_psa_curve_list)"
Valerio Settie618cb02023-04-12 14:59:16 +02002821
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002822 # Configure
2823 # ---------
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002824
Valerio Settie618cb02023-04-12 14:59:16 +02002825 # Set common configurations between library's and driver's builds
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002826 config_psa_crypto_no_ecp_at_all 1
Valerio Settib2fd6732023-08-15 17:10:47 +02002827 # Disable all the builtin curves. All the required algs are accelerated.
2828 helper_disable_builtin_curves
Valerio Settie618cb02023-04-12 14:59:16 +02002829
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002830 # Build
2831 # -----
Valerio Settie618cb02023-04-12 14:59:16 +02002832
2833 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02002834 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
2835 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2836 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Valerio Settie618cb02023-04-12 14:59:16 +02002837
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +02002838 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
Valerio Settie618cb02023-04-12 14:59:16 +02002839
Valerio Settib2fd6732023-08-15 17:10:47 +02002840 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Valerio Settie618cb02023-04-12 14:59:16 +02002841
2842 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
2843 not grep mbedtls_ecdsa_ library/ecdsa.o
2844 not grep mbedtls_ecdh_ library/ecdh.o
2845 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Settib2fd6732023-08-15 17:10:47 +02002846 # Also ensure that ECP module was not re-enabled
Valerio Settie618cb02023-04-12 14:59:16 +02002847 not grep mbedtls_ecp_ library/ecp.o
Valerio Settie618cb02023-04-12 14:59:16 +02002848
2849 # Run the tests
2850 # -------------
2851
Gilles Peskine14302ed2023-07-19 19:30:04 +02002852 msg "test: full + accelerated EC algs - ECP"
Valerio Settie618cb02023-04-12 14:59:16 +02002853 make test
Valerio Setti16b70f22023-06-27 17:45:49 +02002854
Gilles Peskine14302ed2023-07-19 19:30:04 +02002855 msg "ssl-opt: full + accelerated EC algs - ECP"
Valerio Setti16b70f22023-06-27 17:45:49 +02002856 tests/ssl-opt.sh
Valerio Settie618cb02023-04-12 14:59:16 +02002857}
2858
2859# Reference function used for driver's coverage analysis in analyze_outcomes.py
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002860# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
Valerio Settie618cb02023-04-12 14:59:16 +02002861# Keep in sync with its accelerated counterpart.
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002862component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002863 msg "build: full + non accelerated EC algs"
Valerio Settie618cb02023-04-12 14:59:16 +02002864
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002865 config_psa_crypto_no_ecp_at_all 0
Valerio Settie618cb02023-04-12 14:59:16 +02002866
2867 make
2868
Gilles Peskine14302ed2023-07-19 19:30:04 +02002869 msg "test: full + non accelerated EC algs"
Valerio Settie618cb02023-04-12 14:59:16 +02002870 make test
Valerio Setti16b70f22023-06-27 17:45:49 +02002871
Gilles Peskine14302ed2023-07-19 19:30:04 +02002872 msg "ssl-opt: full + non accelerated EC algs"
Valerio Setti16b70f22023-06-27 17:45:49 +02002873 tests/ssl-opt.sh
Valerio Settie618cb02023-04-12 14:59:16 +02002874}
2875
Valerio Setti4e2f2442023-08-15 10:10:26 +02002876# This is a common configuration helper used directly from:
2877# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
2878# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
2879# and indirectly from:
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002880# - component_test_psa_crypto_config_accel_ecc_no_bignum
Valerio Setti4e2f2442023-08-15 10:10:26 +02002881# - accelerate all EC algs, disable RSA and FFDH
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002882# - component_test_psa_crypto_config_reference_ecc_no_bignum
Valerio Setti4e2f2442023-08-15 10:10:26 +02002883# - this is the reference component of the above
2884# - it still disables RSA and FFDH, but it uses builtin EC algs
2885# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
2886# - accelerate all EC and FFDH algs, disable only RSA
2887# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
2888# - this is the reference component of the above
2889# - it still disables RSA, but it uses builtin EC and FFDH algs
2890#
2891# This function accepts 2 parameters:
Valerio Setti5dfaca42023-09-05 08:48:51 +02002892# $1: a boolean value which states if we are testing an accelerated scenario
2893# or not.
2894# $2: a string value which states which components are tested. Allowed values
2895# are "ECC" or "ECC_DH".
Valerio Setti4e2f2442023-08-15 10:10:26 +02002896config_psa_crypto_config_accel_ecc_ffdh_no_bignum() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002897 driver_only="$1"
2898 test_target="$2"
Valerio Setti18535c32023-07-31 11:27:17 +02002899 # start with full config for maximum coverage (also enables USE_PSA)
Valerio Setti29c1b4d2023-07-27 10:08:45 +02002900 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002901
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002902 if [ "$driver_only" -eq 1 ]; then
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002903 # Disable modules that are accelerated
2904 scripts/config.py unset MBEDTLS_ECDSA_C
2905 scripts/config.py unset MBEDTLS_ECDH_C
2906 scripts/config.py unset MBEDTLS_ECJPAKE_C
2907 # Disable ECP module (entirely)
2908 scripts/config.py unset MBEDTLS_ECP_C
Manuel Pégourié-Gonnard660bbf22023-06-12 18:42:40 +02002909 # Also disable bignum
2910 scripts/config.py unset MBEDTLS_BIGNUM_C
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002911 fi
2912
2913 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
2914 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
2915 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
2916 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2917
Manuel Pégourié-Gonnard7dccb662023-06-12 18:28:42 +02002918 # RSA support is intentionally disabled on this test because RSA_C depends
2919 # on BIGNUM_C.
Valerio Setti2e0275d2023-07-28 16:33:13 +02002920 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
2921 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
Manuel Pégourié-Gonnard7dccb662023-06-12 18:28:42 +02002922 scripts/config.py unset MBEDTLS_RSA_C
2923 scripts/config.py unset MBEDTLS_PKCS1_V15
2924 scripts/config.py unset MBEDTLS_PKCS1_V21
2925 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2926 # Also disable key exchanges that depend on RSA
2927 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2928 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2929 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2930 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2931 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2932
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002933 if [ "$test_target" = "ECC" ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02002934 # When testing ECC only, we disable FFDH support, both from builtin and
2935 # PSA sides, and also disable the key exchanges that depend on DHM.
2936 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_FFDH
2937 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
2938 scripts/config.py unset MBEDTLS_DHM_C
2939 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2940 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2941 else
2942 # When testing ECC and DH instead, we disable DHM and depending key
2943 # exchanges only in the accelerated build
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002944 if [ "$driver_only" -eq 1 ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02002945 scripts/config.py unset MBEDTLS_DHM_C
2946 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2947 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2948 fi
2949 fi
Manuel Pégourié-Gonnard7dccb662023-06-12 18:28:42 +02002950
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002951 # Restartable feature is not yet supported by PSA. Once it will in
2952 # the future, the following line could be removed (see issues
2953 # 6061, 6332 and following ones)
2954 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2955}
2956
Valerio Setti4e2f2442023-08-15 10:10:26 +02002957# Common helper used by:
2958# - component_test_psa_crypto_config_accel_ecc_no_bignum
2959# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002960#
Valerio Setti4e2f2442023-08-15 10:10:26 +02002961# The goal is to build and test accelerating either:
2962# - ECC only or
2963# - both ECC and FFDH
2964#
2965# It is meant to be used in conjunction with
Valerio Setti5dfaca42023-09-05 08:48:51 +02002966# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
2967# coverage analysis in the "analyze_outcomes.py" script.
Valerio Setti4e2f2442023-08-15 10:10:26 +02002968common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002969 test_target="$1"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002970
Valerio Setti5dfaca42023-09-05 08:48:51 +02002971 # This is an internal helper to simplify text message handling
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002972 if [ "$test_target" = "ECC_DH" ]; then
2973 accel_text="ECC/FFDH"
2974 removed_text="ECP - DH"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002975 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002976 accel_text="ECC"
2977 removed_text="ECP"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002978 fi
2979
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002980 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002981
2982 # By default we accelerate all EC keys/algs
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002983 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2984 ALG_ECDH \
2985 ALG_JPAKE \
Valerio Setti0a342c92023-09-01 09:12:31 +02002986 $(helper_get_psa_key_type_list "ECC")"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002987 # Optionally we can also add DH to the list of accelerated items
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002988 if [ "$test_target" = "ECC_DH" ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02002989 loc_accel_list="$loc_accel_list \
2990 ALG_FFDH \
Manuel Pégourié-Gonnard85ff5e62023-09-22 09:05:48 +02002991 $(helper_get_psa_key_type_list "DH")"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002992 fi
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002993
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002994 # Note: Those are handled in a special way by the libtestdriver machinery,
2995 # so we only want to include them in the accel list when building the main
2996 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002997 loc_curve_list="$(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002998
2999 # Configure
3000 # ---------
3001
3002 # Set common configurations between library's and driver's builds
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003003 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
Valerio Settib2fd6732023-08-15 17:10:47 +02003004 # Disable all the builtin curves. All the required algs are accelerated.
3005 helper_disable_builtin_curves
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003006
3007 # Build
3008 # -----
3009
3010 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02003011 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
3012 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3013 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003014
3015 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
3016
Valerio Settib2fd6732023-08-15 17:10:47 +02003017 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003018
3019 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
3020 not grep mbedtls_ecdsa_ library/ecdsa.o
3021 not grep mbedtls_ecdh_ library/ecdh.o
3022 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Setti4e2f2442023-08-15 10:10:26 +02003023 # Also ensure that ECP, RSA, [DHM] or BIGNUM modules were not re-enabled
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003024 not grep mbedtls_ecp_ library/ecp.o
Manuel Pégourié-Gonnard06aebe42023-06-12 18:33:34 +02003025 not grep mbedtls_rsa_ library/rsa.o
Manuel Pégourié-Gonnard660bbf22023-06-12 18:42:40 +02003026 not grep mbedtls_mpi_ library/bignum.o
Valerio Setti4e2f2442023-08-15 10:10:26 +02003027 not grep mbedtls_dhm_ library/dhm.o
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003028
3029 # Run the tests
3030 # -------------
3031
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003032 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - DHM - BIGNUM"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003033
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003034 make test
3035
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003036 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Valerio Setti18535c32023-07-31 11:27:17 +02003037 tests/ssl-opt.sh
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003038}
3039
Valerio Setti4e2f2442023-08-15 10:10:26 +02003040# Common helper used by:
3041# - component_test_psa_crypto_config_reference_ecc_no_bignum
3042# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
3043#
3044# The goal is to build and test a reference scenario (i.e. with builtin
3045# components) compared to the ones used in
3046# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
3047#
3048# It is meant to be used in conjunction with
3049# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
3050# coverage analysis in "analyze_outcomes.py" script.
3051common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003052 test_target="$1"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003053
Valerio Setti5dfaca42023-09-05 08:48:51 +02003054 # This is an internal helper to simplify text message handling
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003055 if [ "$test_target" = "ECC_DH" ]; then
3056 accel_text="ECC/FFDH"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003057 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003058 accel_text="ECC"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003059 fi
3060
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003061 msg "build: full + non accelerated $accel_text algs + USE_PSA"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003062
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003063 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003064
3065 make
3066
Valerio Setti29c1b4d2023-07-27 10:08:45 +02003067 msg "test suites: full + non accelerated EC algs + USE_PSA"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003068 make test
3069
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003070 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
Valerio Setti18535c32023-07-31 11:27:17 +02003071 tests/ssl-opt.sh
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003072}
3073
Valerio Setti4e2f2442023-08-15 10:10:26 +02003074component_test_psa_crypto_config_accel_ecc_no_bignum () {
3075 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
3076}
3077
3078component_test_psa_crypto_config_reference_ecc_no_bignum () {
3079 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
3080}
3081
3082component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
3083 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
3084}
3085
3086component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
3087 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
3088}
3089
Valerio Settiac6d35f2023-08-04 12:49:11 +02003090# Helper for setting common configurations between:
3091# - component_test_tfm_config_p256m_driver_accel_ec()
3092# - component_test_tfm_config()
Valerio Setti52ba0e32023-08-04 12:43:03 +02003093common_tfm_config () {
3094 # Enable TF-M config
Valerio Settic5c4bd22023-08-03 14:28:20 +02003095 cp configs/tfm_mbedcrypto_config_profile_medium.h "$CONFIG_H"
3096 cp configs/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
3097
Valerio Setti52ba0e32023-08-04 12:43:03 +02003098 # Adjust for the fact that we're building outside the TF-M environment.
3099 #
3100 # TF-M has separation, our build doesn't
3101 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SPM
3102 scripts/config.py unset MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
3103 # TF-M provdes its own (dummy) implemenation, from their tree
3104 scripts/config.py unset MBEDTLS_AES_DECRYPT_ALT
3105 scripts/config.py unset MBEDTLS_AES_SETKEY_DEC_ALT
3106 # We have an OS that provides entropy, use it
3107 scripts/config.py unset MBEDTLS_NO_PLATFORM_ENTROPY
3108
3109 # Other config adjustments to make the tests pass.
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003110 # Those should probably be adopted upstream.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003111 #
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003112 # - USE_PSA_CRYPTO for PK_HAVE_ECC_KEYS
3113 echo "#define MBEDTLS_USE_PSA_CRYPTO" >> "$CONFIG_H"
Valerio Setti52ba0e32023-08-04 12:43:03 +02003114 # pkparse.c and pkwrite.c fail to link without this
3115 echo "#define MBEDTLS_OID_C" >> "$CONFIG_H"
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003116 # - ASN1_[PARSE/WRITE]_C found by check_config.h for pkparse/pkwrite
3117 echo "#define MBEDTLS_ASN1_PARSE_C" >> "$CONFIG_H"
3118 echo "#define MBEDTLS_ASN1_WRITE_C" >> "$CONFIG_H"
3119 # - MD_C for HKDF_C
3120 echo "#define MBEDTLS_MD_C" >> "$CONFIG_H"
Valerio Setti52ba0e32023-08-04 12:43:03 +02003121
Manuel Pégourié-Gonnardf7298cd2023-09-18 09:55:24 +02003122 # Config adjustments for better test coverage in our environment.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003123 # These are not needed just to build and pass tests.
3124 #
3125 # Enable filesystem I/O for the benefit of PK parse/write tests.
3126 echo "#define MBEDTLS_FS_IO" >> "$CONFIG_H"
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003127 # Disable this for maximal ASan efficiency
3128 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
3129
Manuel Pégourié-Gonnardf7298cd2023-09-18 09:55:24 +02003130 # Config adjustments for features that are not supported
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003131 # when using only drivers / by p256-m
3132 #
3133 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
3134 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
3135 # Disable deterministic ECDSA as p256-m only does randomized
3136 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
3137
Valerio Setti52ba0e32023-08-04 12:43:03 +02003138}
3139
Valerio Settiac6d35f2023-08-04 12:49:11 +02003140# Keep this in sync with component_test_tfm_config() as they are both meant
3141# to be used in analyze_outcomes.py for driver's coverage analysis.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003142component_test_tfm_config_p256m_driver_accel_ec () {
3143 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
3144
3145 common_tfm_config
Valerio Settic5c4bd22023-08-03 14:28:20 +02003146
Valerio Settic5c4bd22023-08-03 14:28:20 +02003147 # Build crypto library specifying we want to use P256M code for EC operations
Manuel Pégourié-Gonnardeda70862023-09-22 12:17:50 +02003148 make CFLAGS="$ASAN_CFLAGS -DMBEDTLS_PSA_P256M_DRIVER_ENABLED -I../tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003149
Manuel Pégourié-Gonnardf8930e22023-06-13 09:51:32 +02003150 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
3151 not grep mbedtls_ecdsa_ library/ecdsa.o
Valerio Settib7e95442023-03-21 11:52:33 +01003152 not grep mbedtls_ecdh_ library/ecdh.o
3153 not grep mbedtls_ecjpake_ library/ecjpake.o
3154 # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
3155 not grep mbedtls_ecp_ library/ecp.o
3156 not grep mbedtls_rsa_ library/rsa.o
Valerio Settie4758aa2023-03-24 16:51:17 +01003157 not grep mbedtls_dhm_ library/dhm.o
Valerio Settiee97a1e2023-03-27 12:44:15 +02003158 not grep mbedtls_mpi_ library/bignum.o
3159
3160 # Run the tests
Valerio Setti52ba0e32023-08-04 12:43:03 +02003161 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
Valerio Settib7e95442023-03-21 11:52:33 +01003162 make test
Valerio Settib7e95442023-03-21 11:52:33 +01003163}
Valerio Settie4758aa2023-03-24 16:51:17 +01003164
Valerio Settiac6d35f2023-08-04 12:49:11 +02003165# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
3166# they are both meant to be used in analyze_outcomes.py for driver's coverage
3167# analysis.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003168component_test_tfm_config() {
3169 common_tfm_config
Valerio Settiee97a1e2023-03-27 12:44:15 +02003170
Valerio Setti52ba0e32023-08-04 12:43:03 +02003171 msg "build: TF-M config"
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02003172 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' tests
Valerio Setti52ba0e32023-08-04 12:43:03 +02003173
3174 msg "test: TF-M config"
3175 make test
Valerio Settic5c4bd22023-08-03 14:28:20 +02003176}
3177
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003178# Common helper for component_full_without_ecdhe_ecdsa() and
3179# component_full_without_ecdhe_ecdsa_and_tls13() which:
3180# - starts from the "full" configuration minus the list of symbols passed in
3181# as 1st parameter
3182# - build
3183# - test only TLS (i.e. test_suite_tls and ssl-opt)
3184build_full_minus_something_and_test_tls () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003185 symbols_to_disable="$1"
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003186
3187 msg "build: full minus something, test TLS"
3188
3189 scripts/config.py full
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003190 for sym in $symbols_to_disable; do
3191 echo "Disabling $sym"
3192 scripts/config.py unset $sym
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003193 done
Valerio Settie4758aa2023-03-24 16:51:17 +01003194
Valerio Settiee97a1e2023-03-27 12:44:15 +02003195 make
3196
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003197 msg "test: full minus something, test TLS"
3198 ( cd tests; ./test_suite_ssl )
Valerio Settib7e95442023-03-21 11:52:33 +01003199
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003200 msg "ssl-opt: full minus something, test TLS"
Valerio Settib7e95442023-03-21 11:52:33 +01003201 tests/ssl-opt.sh
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003202}
Valerio Setti1f1420d2023-03-28 10:35:45 +02003203
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003204component_full_without_ecdhe_ecdsa () {
3205 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED"
Valerio Settib7e95442023-03-21 11:52:33 +01003206}
3207
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003208component_full_without_ecdhe_ecdsa_and_tls13 () {
3209 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
3210 MBEDTLS_SSL_PROTO_TLS1_3"
Valerio Settie4758aa2023-03-24 16:51:17 +01003211}
3212
Valerio Setti249b18a2023-06-20 12:08:30 +02003213# This is an helper used by:
3214# - component_test_psa_ecc_key_pair_no_derive
3215# - component_test_psa_ecc_key_pair_no_generate
3216# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
3217# enabled, but one. Input arguments are as follows:
3218# - $1 is the key type under test, i.e. ECC/RSA/DH
3219# - $2 is the key option to be unset (i.e. generate, derive, etc)
Valerio Settia9836552023-06-22 11:22:23 +02003220build_and_test_psa_want_key_pair_partial() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003221 key_type=$1
3222 unset_option=$2
3223 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003224
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003225 msg "build: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003226 scripts/config.py full
Valerio Setti249b18a2023-06-20 12:08:30 +02003227 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3228 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3229
3230 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
3231 # crypto_config.h so we just disable the one we don't want.
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003232 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
Valerio Setti249b18a2023-06-20 12:08:30 +02003233
Valerio Settif6587be2023-06-22 11:33:14 +02003234 make CC=gcc CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Valerio Setti249b18a2023-06-20 12:08:30 +02003235
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003236 msg "test: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003237 make test
3238}
3239
3240component_test_psa_ecc_key_pair_no_derive() {
Valerio Settia9836552023-06-22 11:22:23 +02003241 build_and_test_psa_want_key_pair_partial "ECC" "DERIVE"
Valerio Setti249b18a2023-06-20 12:08:30 +02003242}
3243
3244component_test_psa_ecc_key_pair_no_generate() {
Valerio Settia9836552023-06-22 11:22:23 +02003245 build_and_test_psa_want_key_pair_partial "ECC" "GENERATE"
Valerio Setti249b18a2023-06-20 12:08:30 +02003246}
3247
Ronald Cron403c15c2021-09-13 09:38:05 +02003248component_test_psa_crypto_config_accel_rsa_signature () {
3249 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
3250
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003251 loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
3252
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003253 # Configure
3254 # ---------
Ronald Cron403c15c2021-09-13 09:38:05 +02003255
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003256 # Start from default config (no TLS 1.3, no USE_PSA)
3257 helper_libtestdriver1_adjust_config "default"
Ronald Cron403c15c2021-09-13 09:38:05 +02003258
3259 # It seems it is not possible to remove only the support for RSA signature
3260 # in the library. Thus we have to remove all RSA support (signature and
3261 # encryption/decryption). AS there is no driver support for asymmetric
3262 # encryption/decryption so far remove RSA encryption/decryption from the
3263 # application algorithm list.
Ronald Cron6b49b552023-07-20 09:57:54 +02003264 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3265 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
Ronald Cron403c15c2021-09-13 09:38:05 +02003266
Manuel Pégourié-Gonnardaed1d782023-06-12 17:22:24 +02003267 # Remove RSA support and its dependencies
3268 scripts/config.py unset MBEDTLS_RSA_C
3269 scripts/config.py unset MBEDTLS_PKCS1_V15
3270 scripts/config.py unset MBEDTLS_PKCS1_V21
3271 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
3272 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3273 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3274 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3275 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
3276 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
3277
Ronald Cron403c15c2021-09-13 09:38:05 +02003278 # Make sure both the library and the test library support the SHA hash
3279 # algorithms and only those ones (SHA256 is included by default). That way:
3280 # - the test library can compute the RSA signatures even in the case of a
3281 # composite RSA signature algorithm based on a SHA hash (no other hash
3282 # used in the unit tests).
3283 # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
3284 # fulfilled as the hash SHA algorithm is supported by the library, and
3285 # thus the tests are run, not skipped.
3286 # - when testing a signature key with an algorithm wildcard built from
3287 # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
3288 # algorithm based on the hashes supported by the library is also
3289 # supported by the test library.
Manuel Pégourié-Gonnardaed1d782023-06-12 17:22:24 +02003290 # Disable unwanted hashes here, we'll enable hashes we want in loc_extra_list.
Ronald Cron6b49b552023-07-20 09:57:54 +02003291 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3292 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160_C
Ronald Cron403c15c2021-09-13 09:38:05 +02003293 scripts/config.py unset MBEDTLS_MD5_C
3294 scripts/config.py unset MBEDTLS_RIPEMD160_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003295
3296 # We need PEM parsing in the test library as well to support the import
3297 # of PEM encoded RSA keys.
Ronald Cron7612d8c2023-07-20 10:03:54 +02003298 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
3299 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003300
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003301 # Build
3302 # -----
3303
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003304 # These hashes are needed for some RSA-PSS signature tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02003305 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3306 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003307 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02003308
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003309 helper_libtestdriver1_make_main "$loc_accel_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02003310
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003311 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine827dbd92022-02-04 00:30:54 +01003312 not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
3313 not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
Ronald Cron403c15c2021-09-13 09:38:05 +02003314
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003315 # Run the tests
3316 # -------------
3317
Ronald Cron403c15c2021-09-13 09:38:05 +02003318 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
3319 make test
3320}
3321
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003322# This is a temporary test to verify that full RSA support is present even when
Valerio Setti01cc88a2023-06-15 11:53:08 +02003323# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003324component_test_new_psa_want_key_pair_symbol() {
Valerio Setti01cc88a2023-06-15 11:53:08 +02003325 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003326
Valerio Setti4590bc22023-06-13 15:39:23 +02003327 # Create a temporary output file unless there is already one set
3328 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
3329 REMOVE_OUTCOME_ON_EXIT="no"
3330 else
3331 REMOVE_OUTCOME_ON_EXIT="yes"
3332 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
3333 export MBEDTLS_TEST_OUTCOME_FILE
3334 fi
3335
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003336 # Start from crypto configuration
3337 scripts/config.py crypto
3338
3339 # Remove RSA support and its dependencies
3340 scripts/config.py unset MBEDTLS_PKCS1_V15
3341 scripts/config.py unset MBEDTLS_PKCS1_V21
3342 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3343 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3344 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3345 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
3346 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
3347 scripts/config.py unset MBEDTLS_RSA_C
3348 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
3349
3350 # Enable PSA support
3351 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3352
Valerio Setti01cc88a2023-06-15 11:53:08 +02003353 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003354 # that proper translations is done in crypto_legacy.h.
Ronald Cron6b49b552023-07-20 09:57:54 +02003355 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
3356 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
3357 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003358
3359 make
3360
Valerio Setti01cc88a2023-06-15 11:53:08 +02003361 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Valerio Setti4590bc22023-06-13 15:39:23 +02003362 make test
3363
3364 # Parse only 1 relevant line from the outcome file, i.e. a test which is
3365 # performing RSA signature.
3366 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
3367 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
3368
3369 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
3370 rm $MBEDTLS_TEST_OUTCOME_FILE
3371 fi
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003372}
3373
Ronald Cronb2312452021-05-08 14:32:59 +02003374component_test_psa_crypto_config_accel_hash () {
3375 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
3376
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003377 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3378 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3379 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Ronald Cronb2312452021-05-08 14:32:59 +02003380
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003381 # Configure
3382 # ---------
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003383
3384 # Start from default config (no TLS 1.3, no USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003385 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003386
3387 # Disable the things that are being accelerated
Ronald Cronb2312452021-05-08 14:32:59 +02003388 scripts/config.py unset MBEDTLS_MD5_C
3389 scripts/config.py unset MBEDTLS_RIPEMD160_C
3390 scripts/config.py unset MBEDTLS_SHA1_C
Manuel Pégourié-Gonnardc584c272023-03-22 00:32:04 +01003391 scripts/config.py unset MBEDTLS_SHA224_C
3392 scripts/config.py unset MBEDTLS_SHA256_C
Ronald Cronb2312452021-05-08 14:32:59 +02003393 scripts/config.py unset MBEDTLS_SHA384_C
3394 scripts/config.py unset MBEDTLS_SHA512_C
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003395 scripts/config.py unset MBEDTLS_SHA3_C
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003396
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003397 # Build
3398 # -----
3399
3400 helper_libtestdriver1_make_drivers "$loc_accel_list"
3401
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003402 helper_libtestdriver1_make_main "$loc_accel_list"
Ronald Cronb2312452021-05-08 14:32:59 +02003403
Manuel Pégourié-Gonnardc584c272023-03-22 00:32:04 +01003404 # There's a risk of something getting re-enabled via config_psa.h;
3405 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
3406 not grep mbedtls_md5 library/md5.o
3407 not grep mbedtls_sha1 library/sha1.o
3408 not grep mbedtls_sha256 library/sha256.o
3409 not grep mbedtls_sha512 library/sha512.o
3410 not grep mbedtls_ripemd160 library/ripemd160.o
Ronald Cronb2312452021-05-08 14:32:59 +02003411
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003412 # Run the tests
3413 # -------------
3414
Ronald Cronb2312452021-05-08 14:32:59 +02003415 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
3416 make test
3417}
3418
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003419component_test_psa_crypto_config_accel_hash_keep_builtins () {
3420 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
3421 # This component ensures that all the test cases for
3422 # md_psa_dynamic_dispatch with legacy+driver in test_suite_md are run.
3423
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003424 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3425 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3426 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003427
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003428 # Start from default config (no TLS 1.3, no USE_PSA)
3429 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003430
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +02003431 helper_libtestdriver1_make_drivers "$loc_accel_list"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003432
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003433 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003434
3435 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
3436 make test
3437}
3438
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003439# Auxiliary function to build config for hashes with and without drivers
3440config_psa_crypto_hash_use_psa () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003441 driver_only="$1"
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003442 # start with config full for maximum coverage (also enables USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003443 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003444 if [ "$driver_only" -eq 1 ]; then
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003445 # disable the built-in implementation of hashes
3446 scripts/config.py unset MBEDTLS_MD5_C
3447 scripts/config.py unset MBEDTLS_RIPEMD160_C
3448 scripts/config.py unset MBEDTLS_SHA1_C
3449 scripts/config.py unset MBEDTLS_SHA224_C
3450 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
3451 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
3452 scripts/config.py unset MBEDTLS_SHA384_C
3453 scripts/config.py unset MBEDTLS_SHA512_C
3454 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003455 scripts/config.py unset MBEDTLS_SHA3_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003456 fi
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003457}
3458
Przemek Stekiel120ed8f2022-10-27 10:29:15 +02003459# Note that component_test_psa_crypto_config_reference_hash_use_psa
3460# is related to this component and both components need to be kept in sync.
3461# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003462component_test_psa_crypto_config_accel_hash_use_psa () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02003463 msg "test: full with accelerated hashes"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003464
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003465 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3466 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3467 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003468
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003469 # Configure
3470 # ---------
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003471
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003472 config_psa_crypto_hash_use_psa 1
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003473
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003474 # Build
3475 # -----
3476
3477 helper_libtestdriver1_make_drivers "$loc_accel_list"
3478
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003479 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003480
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003481 # There's a risk of something getting re-enabled via config_psa.h;
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01003482 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003483 not grep mbedtls_md5 library/md5.o
3484 not grep mbedtls_sha1 library/sha1.o
Manuel Pégourié-Gonnard7b0825d2022-07-11 11:06:09 +02003485 not grep mbedtls_sha256 library/sha256.o
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003486 not grep mbedtls_sha512 library/sha512.o
3487 not grep mbedtls_ripemd160 library/ripemd160.o
3488
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003489 # Run the tests
3490 # -------------
3491
Gilles Peskine14302ed2023-07-19 19:30:04 +02003492 msg "test: full with accelerated hashes"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003493 make test
Andrzej Kurek07e35702022-09-05 15:39:23 -04003494
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003495 # This is mostly useful so that we can later compare outcome files with
3496 # the reference config in analyze_outcomes.py, to check that the
3497 # dependency declarations in ssl-opt.sh and in TLS code are correct.
Gilles Peskine14302ed2023-07-19 19:30:04 +02003498 msg "test: ssl-opt.sh, full with accelerated hashes"
Przemek Stekiel5f6f32a2022-10-27 08:24:43 +02003499 tests/ssl-opt.sh
Andrzej Kurek07e35702022-09-05 15:39:23 -04003500
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003501 # This is to make sure all ciphersuites are exercised, but we don't need
3502 # interop testing (besides, we already got some from ssl-opt.sh).
Gilles Peskine14302ed2023-07-19 19:30:04 +02003503 msg "test: compat.sh, full with accelerated hashes"
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003504 tests/compat.sh -p mbedTLS -V YES
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003505}
3506
Przemek Stekiel120ed8f2022-10-27 10:29:15 +02003507# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
3508# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
3509# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
3510# Both components need to be kept in sync.
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003511component_test_psa_crypto_config_reference_hash_use_psa() {
Gilles Peskine14302ed2023-07-19 19:30:04 +02003512 msg "test: full without accelerated hashes"
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003513
3514 config_psa_crypto_hash_use_psa 0
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003515
Przemek Stekielab0451b2022-10-24 11:29:35 +02003516 make
3517
Gilles Peskine14302ed2023-07-19 19:30:04 +02003518 msg "test: full without accelerated hashes"
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003519 make test
3520
Gilles Peskine14302ed2023-07-19 19:30:04 +02003521 msg "test: ssl-opt.sh, full without accelerated hashes"
Przemek Stekiel5f6f32a2022-10-27 08:24:43 +02003522 tests/ssl-opt.sh
Ronald Cron3a8714d2021-10-18 11:26:01 +02003523}
Manuel Pégourié-Gonnard97ab2a32022-07-06 10:46:57 +02003524
John Durkop4377bf72020-10-23 01:26:57 -07003525component_test_psa_crypto_config_accel_cipher () {
3526 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
3527
3528 loc_accel_list="ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB ALG_OFB ALG_XTS KEY_TYPE_DES"
John Durkop1b7ee052020-11-27 08:51:22 -08003529
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003530 # Configure
3531 # ---------
John Durkop1b7ee052020-11-27 08:51:22 -08003532
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003533 # Start from the default config (no TLS 1.3, no USE_PSA)
3534 helper_libtestdriver1_adjust_config "default"
John Durkop1b7ee052020-11-27 08:51:22 -08003535
Manuel Pégourié-Gonnard7ae342f2023-06-08 09:26:04 +02003536 # There is no intended accelerator support for ALG CMAC. Therefore, asking
3537 # for it in the build implies the inclusion of the Mbed TLS cipher
3538 # operations. As we want to test here with cipher operations solely
3539 # supported by accelerators, disabled this PSA configuration option.
3540 # (Note: the same applies to STREAM_CIPHER and ECB_NO_PADDING, which are
3541 # already disabled by helper_libtestdriver1_adjust_config above.)
Ronald Cron6b49b552023-07-20 09:57:54 +02003542 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
John Durkop1b7ee052020-11-27 08:51:22 -08003543
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003544 # Disable the things that are being accelerated
John Durkop1b7ee052020-11-27 08:51:22 -08003545 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3546 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
3547 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
3548 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
3549 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
3550 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
3551 scripts/config.py unset MBEDTLS_DES_C
3552
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003553 # Build
3554 # -----
John Durkop1b7ee052020-11-27 08:51:22 -08003555
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003556 helper_libtestdriver1_make_drivers "$loc_accel_list"
3557
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003558 helper_libtestdriver1_make_main "$loc_accel_list"
John Durkop1b7ee052020-11-27 08:51:22 -08003559
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003560 # Make sure this was not re-enabled by accident (additive config)
John Durkop1b7ee052020-11-27 08:51:22 -08003561 not grep mbedtls_des* library/des.o
3562
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003563 # Run the tests
3564 # -------------
3565
John Durkop1b7ee052020-11-27 08:51:22 -08003566 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
3567 make test
3568}
3569
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003570component_test_psa_crypto_config_accel_aead () {
3571 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
3572
Przemek Stekielee1bb412022-10-11 11:52:25 +02003573 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003574
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003575 # Configure
3576 # ---------
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003577
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003578 # Start from default config (no TLS 1.3, no USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003579 helper_libtestdriver1_adjust_config "default"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003580
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003581 # Disable things that are being accelerated
Przemek Stekielee1bb412022-10-11 11:52:25 +02003582 scripts/config.py unset MBEDTLS_GCM_C
3583 scripts/config.py unset MBEDTLS_CCM_C
3584 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
3585 # Features that depend on AEAD
3586 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel072fad12022-10-13 09:59:52 +02003587 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003588
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003589 # Build
3590 # -----
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003591
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003592 helper_libtestdriver1_make_drivers "$loc_accel_list"
3593
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003594 helper_libtestdriver1_make_main "$loc_accel_list"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003595
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003596 # Make sure this was not re-enabled by accident (additive config)
Przemek Stekielee1bb412022-10-11 11:52:25 +02003597 not grep mbedtls_ccm library/ccm.o
3598 not grep mbedtls_gcm library/gcm.o
3599 not grep mbedtls_chachapoly library/chachapoly.o
3600
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003601 # Run the tests
3602 # -------------
3603
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003604 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
3605 make test
3606}
3607
Gilles Peskine36dea152023-07-20 22:19:45 +02003608component_test_aead_chachapoly_disabled() {
3609 msg "build: full minus CHACHAPOLY"
John Durkopf4c4cb02020-10-28 20:09:55 -07003610 scripts/config.py full
John Durkop9814fa22020-11-04 12:28:15 -08003611 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Ronald Cron6b49b552023-07-20 09:57:54 +02003612 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
John Durkopf4c4cb02020-10-28 20:09:55 -07003613 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop6ba40d12020-11-10 08:50:04 -08003614
Gilles Peskine36dea152023-07-20 22:19:45 +02003615 msg "test: full minus CHACHAPOLY"
3616 make test
3617}
3618
3619component_test_aead_only_ccm() {
3620 msg "build: full minus CHACHAPOLY and GCM"
3621 scripts/config.py full
3622 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
3623 scripts/config.py unset MBEDTLS_GCM_C
3624 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
3625 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
3626 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
3627
3628 msg "test: full minus CHACHAPOLY and GCM"
John Durkop9814fa22020-11-04 12:28:15 -08003629 make test
John Durkopf4c4cb02020-10-28 20:09:55 -07003630}
3631
Ronald Crone501d0e2023-07-10 08:31:19 +02003632component_test_ccm_aes_sha256() {
3633 msg "build: CCM + AES + SHA256 configuration"
3634
Ronald Cron7612d8c2023-07-20 10:03:54 +02003635 cp "$CONFIG_TEST_DRIVER_H" "$CONFIG_H"
Ronald Cron6b49b552023-07-20 09:57:54 +02003636 cp configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
Ronald Crone501d0e2023-07-10 08:31:19 +02003637
3638 make CC=gcc
3639
3640 msg "test: CCM + AES + SHA256 configuration"
3641 make test
3642}
3643
John Durkop9814fa22020-11-04 12:28:15 -08003644# This should be renamed to test and updated once the accelerator ECDH code is in place and ready to test.
John Durkopf4c4cb02020-10-28 20:09:55 -07003645component_build_psa_accel_alg_ecdh() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003646 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
John Durkopd0321952020-10-29 21:37:36 -07003647 scripts/config.py full
John Durkopd0321952020-10-29 21:37:36 -07003648 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003649 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkopd0321952020-10-29 21:37:36 -07003650 scripts/config.py unset MBEDTLS_ECDH_C
3651 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3652 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
3653 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
3654 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3655 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
3656 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
John Durkop6ba40d12020-11-10 08:50:04 -08003657 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkopd0321952020-10-29 21:37:36 -07003658}
3659
John Durkop1b7ee052020-11-27 08:51:22 -08003660# This should be renamed to test and updated once the accelerator HMAC code is in place and ready to test.
3661component_build_psa_accel_alg_hmac() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003662 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
John Durkop1b7ee052020-11-27 08:51:22 -08003663 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003664 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003665 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkop1b7ee052020-11-27 08:51:22 -08003666 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3667 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3668}
3669
3670# This should be renamed to test and updated once the accelerator HKDF code is in place and ready to test.
3671component_build_psa_accel_alg_hkdf() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003672 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
John Durkop1b7ee052020-11-27 08:51:22 -08003673 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003674 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003675 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkop1b7ee052020-11-27 08:51:22 -08003676 scripts/config.py unset MBEDTLS_HKDF_C
Ronald Cron6f135e12021-12-08 16:57:54 +01003677 # Make sure to unset TLS1_3 since it requires HKDF_C and will not build properly without it.
3678 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkop1b7ee052020-11-27 08:51:22 -08003679 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3680 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3681}
3682
3683# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
3684component_build_psa_accel_alg_md5() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003685 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003686 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003687 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003688 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003689 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3690 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3691 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3692 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3693 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3694 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3695 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003696 scripts/config.py unset MBEDTLS_LMS_C
3697 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003698 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3699 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3700}
3701
3702# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
3703component_build_psa_accel_alg_ripemd160() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003704 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003705 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003706 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003707 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003708 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3709 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3710 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3711 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3712 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3713 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3714 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003715 scripts/config.py unset MBEDTLS_LMS_C
3716 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003717 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3718 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3719}
3720
3721# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
3722component_build_psa_accel_alg_sha1() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003723 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003724 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003725 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003726 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003727 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3728 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3729 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3730 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3731 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3732 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3733 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003734 scripts/config.py unset MBEDTLS_LMS_C
3735 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003736 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3737 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3738}
3739
3740# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
3741component_build_psa_accel_alg_sha224() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003742 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003743 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003744 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003745 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003746 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3747 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3748 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3749 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3750 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3751 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
John Durkop1b7ee052020-11-27 08:51:22 -08003752 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3753 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3754}
3755
3756# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
3757component_build_psa_accel_alg_sha256() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003758 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003759 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003760 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003761 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003762 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3763 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3764 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3765 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3766 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3767 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
John Durkop1b7ee052020-11-27 08:51:22 -08003768 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3769 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3770}
3771
3772# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
3773component_build_psa_accel_alg_sha384() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003774 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003775 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003776 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003777 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003778 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3779 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3780 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3781 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3782 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3783 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003784 scripts/config.py unset MBEDTLS_LMS_C
3785 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003786 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3787 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3788}
3789
3790# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
3791component_build_psa_accel_alg_sha512() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003792 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003793 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003794 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003795 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003796 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3797 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3798 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3799 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3800 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3801 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3802 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003803 scripts/config.py unset MBEDTLS_LMS_C
3804 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003805 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3806 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3807}
3808
John Durkopd0321952020-10-29 21:37:36 -07003809# 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 -08003810component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003811 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 -07003812 scripts/config.py full
John Durkopd0321952020-10-29 21:37:36 -07003813 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003814 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003815 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
3816 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3817 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3818 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07003819 # 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 -07003820 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3821}
3822
3823# 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 -08003824component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003825 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 -07003826 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003827 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003828 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003829 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
3830 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3831 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3832 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07003833 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3834 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3835}
3836
3837# 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 -08003838component_build_psa_accel_alg_rsa_oaep() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003839 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 -07003840 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003841 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003842 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003843 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_OAEP 1
3844 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3845 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3846 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07003847 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3848 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3849}
3850
3851# 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 -08003852component_build_psa_accel_alg_rsa_pss() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003853 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 -07003854 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003855 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003856 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003857 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
3858 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3859 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3860 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07003861 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3862 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3863}
3864
3865# 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 -08003866component_build_psa_accel_key_type_rsa_key_pair() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003867 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_xxx + PSA_WANT_ALG_RSA_PSS"
John Durkopbd069d32020-10-31 22:14:03 -07003868 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003869 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003870 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003871 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
3872 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC 1
3873 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT 1
3874 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT 1
3875 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE 1
John Durkopbd069d32020-10-31 22:14:03 -07003876 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3877 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"
3878}
3879
3880# 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 -08003881component_build_psa_accel_key_type_rsa_public_key() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003882 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 -07003883 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003884 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003885 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003886 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
3887 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
John Durkopbd069d32020-10-31 22:14:03 -07003888 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3889 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 -07003890}
3891
Dave Rodgmanc164c072023-06-28 09:43:23 +01003892
Dave Rodgman904c5892023-06-28 17:36:02 +01003893support_build_tfm_armcc () {
Yanray Wang799bd842023-11-10 12:21:35 +08003894 support_build_armcc
Dave Rodgmanc164c072023-06-28 09:43:23 +01003895}
3896
Dave Rodgman904c5892023-06-28 17:36:02 +01003897component_build_tfm_armcc() {
3898 # test the TF-M configuration can build cleanly with various warning flags enabled
Ronald Cron7a93ac52023-07-20 09:49:12 +02003899 cp configs/tfm_mbedcrypto_config_profile_medium.h "$CONFIG_H"
Ronald Cron6b49b552023-07-20 09:57:54 +02003900 cp configs/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Dave Rodgmanc164c072023-06-28 09:43:23 +01003901
Dave Rodgman88651c42023-06-29 12:35:51 +01003902 msg "build: TF-M config, armclang armv7-m thumb2"
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02003903 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m -mthumb -Os -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused -I../tests/include/spe"
Dave Rodgmanfb374e62023-06-29 11:58:16 +01003904}
3905
3906component_build_tfm() {
3907 # test the TF-M configuration can build cleanly with various warning flags enabled
Ronald Cron7a93ac52023-07-20 09:49:12 +02003908 cp configs/tfm_mbedcrypto_config_profile_medium.h "$CONFIG_H"
Ronald Cron6b49b552023-07-20 09:57:54 +02003909 cp configs/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Dave Rodgmanfb374e62023-06-29 11:58:16 +01003910
Dave Rodgman88651c42023-06-29 12:35:51 +01003911 msg "build: TF-M config, clang, armv7-m thumb2"
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02003912 make lib CC="clang" CFLAGS="--target=arm-linux-gnueabihf -march=armv7-m -mthumb -Os -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused -I../tests/include/spe"
Dave Rodgmanc164c072023-06-28 09:43:23 +01003913
Dave Rodgman904c5892023-06-28 17:36:02 +01003914 msg "build: TF-M config, gcc native build"
3915 make clean
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02003916 make lib CC="gcc" CFLAGS="-Os -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wformat-signedness -Wlogical-op -I../tests/include/spe"
Dave Rodgmanc164c072023-06-28 09:43:23 +01003917}
3918
Dave Rodgman54ada8b2023-10-04 11:55:25 +01003919# Test that the given .o file builds with all (valid) combinations of the given options.
3920#
3921# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
3922#
3923# The validator function is the name of a function to validate the combination of options.
3924# It may be "" if all combinations are valid.
3925# It receives a string containing a combination of options, as passed to the compiler,
Dave Rodgmanf3803a12023-10-16 13:47:15 +01003926# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Dave Rodgman920343a2023-10-01 18:41:09 +01003927build_test_config_combos() {
Dave Rodgman28e38d82023-10-04 11:50:30 +01003928 file=$1
Dave Rodgman920343a2023-10-01 18:41:09 +01003929 shift
Dave Rodgman28e38d82023-10-04 11:50:30 +01003930 validate_options=$1
Dave Rodgman920343a2023-10-01 18:41:09 +01003931 shift
Dave Rodgman28e38d82023-10-04 11:50:30 +01003932 options=("$@")
Dave Rodgman0f0f7692023-06-29 12:10:45 +01003933
Dave Rodgman42436102023-10-03 15:47:05 +01003934 # clear all of the options so that they can be overridden on the clang commandline
Dave Rodgman28e38d82023-10-04 11:50:30 +01003935 for opt in "${options[@]}"; do
3936 ./scripts/config.py unset ${opt}
Dave Rodgman42436102023-10-03 15:47:05 +01003937 done
3938
3939 # enter the directory containing the target file & strip the dir from the filename
Dave Rodgman28e38d82023-10-04 11:50:30 +01003940 cd $(dirname ${file})
3941 file=$(basename ${file})
Dave Rodgman42436102023-10-03 15:47:05 +01003942
Dave Rodgman920343a2023-10-01 18:41:09 +01003943 # The most common issue is unused variables/functions, so ensure -Wunused is set.
Dave Rodgman28e38d82023-10-04 11:50:30 +01003944 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
Dave Rodgman97285622023-09-29 17:32:06 +01003945
Dave Rodgman42436102023-10-03 15:47:05 +01003946 # Extract the command generated by the Makefile to build the target file.
3947 # This ensures that we have any include paths, macro definitions, etc
3948 # that may be applied by make.
3949 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01003950 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
Dave Rodgman42436102023-10-03 15:47:05 +01003951
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01003952 makefile=$(TMPDIR=. mktemp)
Dave Rodgman28e38d82023-10-04 11:50:30 +01003953 deps=""
Dave Rodgman97285622023-09-29 17:32:06 +01003954
Dave Rodgman28e38d82023-10-04 11:50:30 +01003955 len=${#options[@]}
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01003956 source_file=${file%.o}.c
3957
3958 targets=0
3959 echo 'include Makefile' >${makefile}
Dave Rodgman97285622023-09-29 17:32:06 +01003960
Dave Rodgman28e38d82023-10-04 11:50:30 +01003961 for ((i = 0; i < $((2**${len})); i++)); do
Dave Rodgman920343a2023-10-01 18:41:09 +01003962 # generate each of 2^n combinations of options
Dave Rodgman28e38d82023-10-04 11:50:30 +01003963 # each bit of $i is used to determine if options[i] will be set or not
3964 target="t"
3965 clang_args=""
3966 for ((j = 0; j < ${len}; j++)); do
Dave Rodgmanb1107ae2023-10-04 12:30:23 +01003967 if (((i >> j) & 1)); then
Dave Rodgmana7127eb2023-10-04 13:38:41 +01003968 opt=-D${options[$j]}
Dave Rodgman7a8a2492023-10-04 13:14:20 +01003969 clang_args="${clang_args} ${opt}"
3970 target="${target}${opt}"
Dave Rodgmanb1107ae2023-10-04 12:30:23 +01003971 fi
Dave Rodgman920343a2023-10-01 18:41:09 +01003972 done
3973
Dave Rodgmanb1107ae2023-10-04 12:30:23 +01003974 # if combination is not known to be invalid, add it to the makefile
Dave Rodgmanf3803a12023-10-16 13:47:15 +01003975 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
Dave Rodgman28e38d82023-10-04 11:50:30 +01003976 cmd="${compile_cmd} ${clang_args}"
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01003977 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
Dave Rodgman920343a2023-10-01 18:41:09 +01003978
Dave Rodgman28e38d82023-10-04 11:50:30 +01003979 deps="${deps} ${target}"
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01003980 ((++targets))
Dave Rodgman745af9f2023-09-29 15:47:07 +01003981 fi
Dave Rodgman97285622023-09-29 17:32:06 +01003982 done
Dave Rodgman6001fb22023-06-29 09:29:00 +01003983
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01003984 echo "build_test_config_combos: ${deps}" >> ${makefile}
Dave Rodgmanaea01c92023-09-29 18:54:49 +01003985
Dave Rodgman920343a2023-10-01 18:41:09 +01003986 # execute all of the commands via Make (probably in parallel)
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01003987 make -s -f ${makefile} build_test_config_combos
3988 echo "$targets targets checked"
Dave Rodgman920343a2023-10-01 18:41:09 +01003989
3990 # clean up the temporary makefile
Dave Rodgman28e38d82023-10-04 11:50:30 +01003991 rm ${makefile}
Dave Rodgman6001fb22023-06-29 09:29:00 +01003992}
3993
Dave Rodgman43a5ce82023-10-02 17:09:37 +01003994validate_aes_config_variations() {
Dave Rodgman920343a2023-10-01 18:41:09 +01003995 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
3996 if [[ "$1" == *"MBEDTLS_PADLOCK_C"* ]]; then
Dave Rodgman41bc7982023-10-16 14:04:21 +01003997 return 1
Dave Rodgman920343a2023-10-01 18:41:09 +01003998 fi
3999 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
4000 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
Dave Rodgman41bc7982023-10-16 14:04:21 +01004001 return 1
Dave Rodgman920343a2023-10-01 18:41:09 +01004002 fi
4003 fi
Dave Rodgman41bc7982023-10-16 14:04:21 +01004004 return 0
Dave Rodgman920343a2023-10-01 18:41:09 +01004005}
4006
4007component_build_aes_variations() {
4008 # 18s - around 90ms per clang invocation on M1 Pro
4009 #
Gilles Peskine8f073122018-11-27 15:58:47 +01004010 # aes.o has many #if defined(...) guards that intersect in complex ways.
Dave Rodgman920343a2023-10-01 18:41:09 +01004011 # Test that all the combinations build cleanly.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004012
Yanray Wangbc29aef2023-11-06 11:08:17 +08004013 MBEDTLS_ROOT_DIR="$PWD"
Gilles Peskine32e889d2020-04-12 23:43:28 +02004014 msg "build: aes.o for all combinations of relevant config options"
Gilles Peskinef4d2fd42021-10-08 11:45:47 +02004015
Dave Rodgman42436102023-10-03 15:47:05 +01004016 build_test_config_combos library/aes.o validate_aes_config_variations \
Dave Rodgman920343a2023-10-01 18:41:09 +01004017 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
4018 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
4019 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
4020 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
Yanray Wangbc29aef2023-11-06 11:08:17 +08004021
4022 cd "$MBEDTLS_ROOT_DIR"
4023 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
4024
4025 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with CBC/XTS/DES/NIST_KW,
4026 # manually set or unset those configurations to check
4027 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
Yanray Wangbc29aef2023-11-06 11:08:17 +08004028 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
4029 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
4030 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
4031 scripts/config.py unset MBEDTLS_DES_C
4032 scripts/config.py unset MBEDTLS_NIST_KW_C
4033 build_test_config_combos library/aes.o validate_aes_config_variations \
4034 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
4035 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
4036 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
4037 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004038}
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02004039
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04004040component_test_no_platform () {
4041 # Full configuration build, without platform support, file IO and net sockets.
4042 # This should catch missing mbedtls_printf definitions, and by disabling file
4043 # IO, it should catch missing '#include <stdio.h>'
4044 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
4045 scripts/config.py full
4046 scripts/config.py unset MBEDTLS_PLATFORM_C
4047 scripts/config.py unset MBEDTLS_NET_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004048 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
4049 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02004050 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
Hanno Becker0fb9ba22019-02-26 14:34:13 +00004051 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
4052 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
4053 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
4054 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskine636c26a2020-03-04 20:46:15 +01004055 scripts/config.py unset MBEDTLS_PLATFORM_SETBUF_ALT
4056 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
4057 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004058 scripts/config.py unset MBEDTLS_FS_IO
Hanno Becker0fb9ba22019-02-26 14:34:13 +00004059 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
4060 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01004061 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
4062 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
4063 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004064 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
Gilles Peskine8f073122018-11-27 15:58:47 +01004065 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
4066}
Hanno Becker5175ac62017-09-18 15:36:25 +01004067
Gilles Peskine8f073122018-11-27 15:58:47 +01004068component_build_no_std_function () {
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004069 # catch compile bugs in _uninit functions
Gilles Peskine8f073122018-11-27 15:58:47 +01004070 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02004071 scripts/config.py full
Hanno Becker545ced42019-02-19 11:10:48 +00004072 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
4073 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004074 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Hanno Becker545ced42019-02-19 11:10:48 +00004075 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
4076 make
4077}
4078
4079component_build_no_ssl_srv () {
4080 msg "build: full config except SSL server, make, gcc" # ~ 30s
4081 scripts/config.py full
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004082 scripts/config.py unset MBEDTLS_SSL_SRV_C
Hanno Becker545ced42019-02-19 11:10:48 +00004083 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
4084}
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004085
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02004086component_build_no_ssl_cli () {
4087 msg "build: full config except SSL client, make, gcc" # ~ 30s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004088 scripts/config.py full
Hanno Becker545ced42019-02-19 11:10:48 +00004089 scripts/config.py unset MBEDTLS_SSL_CLI_C
4090 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01004091}
4092
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004093component_build_no_sockets () {
4094 # Note, C99 compliance can also be tested with the sockets support disabled,
4095 # as that requires a POSIX platform (which isn't the same as C99).
Gilles Peskine8f073122018-11-27 15:58:47 +01004096 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
4097 scripts/config.py full
Angus Grattonc4dd0732018-04-11 16:28:39 +10004098 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
Gilles Peskine8f073122018-11-27 15:58:47 +01004099 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004100 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02004101}
4102
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004103component_test_memory_buffer_allocator_backtrace () {
Gilles Peskine8f073122018-11-27 15:58:47 +01004104 msg "build: default config with memory buffer allocator and backtrace enabled"
Angus Grattonc4dd0732018-04-11 16:28:39 +10004105 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Darryl Greenaad82f92019-12-02 10:53:11 +00004106 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4107 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
4108 scripts/config.py set MBEDTLS_MEMORY_DEBUG
4109 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
4110 make
4111
4112 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
4113 make test
4114}
4115
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004116component_test_memory_buffer_allocator () {
Darryl Greenaad82f92019-12-02 10:53:11 +00004117 msg "build: default config with memory buffer allocator"
4118 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004119 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Darryl Greenaad82f92019-12-02 10:53:11 +00004120 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
4121 make
Manuel Pégourié-Gonnard6a543ba2022-11-25 11:30:10 +01004122
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004123 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
Hannes Tschofenigfd6cca42021-10-12 09:22:33 +02004124 make test
Darryl Greenaad82f92019-12-02 10:53:11 +00004125
4126 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
4127 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
4128 tests/ssl-opt.sh -e '^DTLS proxy'
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004129}
Darryl Greenaad82f92019-12-02 10:53:11 +00004130
4131component_test_no_max_fragment_length () {
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004132 # Run max fragment length tests with MFL disabled
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004133 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Darryl Greenaad82f92019-12-02 10:53:11 +00004134 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Manuel Pégourié-Gonnard6a543ba2022-11-25 11:30:10 +01004135 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004136 make
Darryl Greenaad82f92019-12-02 10:53:11 +00004137
4138 msg "test: ssl-opt.sh, MFL-related tests"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004139 tests/ssl-opt.sh -f "Max fragment length"
4140}
4141
4142component_test_asan_remove_peer_certificate () {
4143 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
4144 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
4145 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02004146 make
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004147
4148 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
4149 make test
4150
4151 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
4152 tests/ssl-opt.sh
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004153
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004154 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
4155 tests/compat.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01004156
4157 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
4158 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01004159}
TRodziewicz2add5c12021-04-28 16:50:20 +02004160
Gilles Peskine636c26a2020-03-04 20:46:15 +01004161component_test_no_max_fragment_length_small_ssl_out_content_len () {
4162 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
4163 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4164 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
4165 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
4166 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004167 make
Gilles Peskine636c26a2020-03-04 20:46:15 +01004168
4169 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Raoul Strackxa4e86142020-06-15 17:03:13 +02004170 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
4171
4172 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskinef4d2fd42021-10-08 11:45:47 +02004173 tests/context-info.sh
Raoul Strackxa4e86142020-06-15 17:03:13 +02004174}
4175
4176component_test_variable_ssl_in_out_buffer_len () {
4177 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
4178 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
4179 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine8f073122018-11-27 15:58:47 +01004180 make
4181
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004182 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
4183 make test
4184
Gilles Peskine8f073122018-11-27 15:58:47 +01004185 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
4186 tests/ssl-opt.sh
Hanno Beckere5fecec2018-10-11 11:02:52 +01004187
Gilles Peskine8f073122018-11-27 15:58:47 +01004188 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
4189 tests/compat.sh
4190}
Hanno Beckere5fecec2018-10-11 11:02:52 +01004191
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02004192component_test_dtls_cid_legacy () {
4193 msg "build: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled (ASan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004194 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 1
Gilles Peskine004206c2019-10-21 17:11:33 +02004195
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02004196 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4197 make
4198
4199 msg "test: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy)"
4200 make test
4201
4202 msg "test: ssl-opt.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004203 tests/ssl-opt.sh
Gilles Peskine765d2402020-02-11 18:26:34 +01004204
4205 msg "test: compat.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
4206 tests/compat.sh
4207}
4208
4209component_test_ssl_alloc_buffer_and_mfl () {
4210 msg "build: default config with memory buffer allocator and MFL extension"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004211 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02004212 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4213 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Dave Rodgman6a08b682023-06-19 11:51:33 +01004214 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4215 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
4216 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
4217 make
4218
4219 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
Dave Rodgmanf8986e32023-06-19 10:55:59 +01004220 make test
4221
4222 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
4223 tests/ssl-opt.sh -f "Handshake memory usage"
Dave Rodgman6a08b682023-06-19 11:51:33 +01004224}
4225
Dave Rodgman3d9af472023-06-19 12:10:11 +01004226component_test_when_no_ciphersuites_have_mac () {
Dave Rodgmanf8986e32023-06-19 10:55:59 +01004227 msg "build: when no ciphersuites have MAC"
4228 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004229 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
4230 scripts/config.py unset MBEDTLS_CMAC_C
4231 make
4232
4233 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
4234 make test
4235
4236 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004237 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Dave Rodgman838dc462023-06-16 13:18:19 +01004238}
4239
4240component_test_no_date_time () {
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004241 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
4242 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
Dave Rodgman838dc462023-06-16 13:18:19 +01004243 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004244 make
4245
Dave Rodgman20cc5632023-06-19 10:27:31 +01004246 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004247 make test
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004248}
4249
4250component_test_platform_calloc_macro () {
4251 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
4252 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Dave Rodgmanb9590272023-06-19 10:28:45 +01004253 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004254 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
4255 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004256 make
4257
4258 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Dave Rodgmanf18a7e12023-06-16 22:41:18 +01004259 make test
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004260}
Dave Rodgman20cc5632023-06-19 10:27:31 +01004261
Dave Rodgman838dc462023-06-16 13:18:19 +01004262component_test_malloc_0_null () {
4263 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Arto Kinnunen3eb50e72023-04-14 17:43:36 +08004264 scripts/config.py full
Gilles Peskinecf4fe582023-07-20 19:00:15 +02004265 make CC=gcc CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"$PWD/tests/configs/user-config-malloc-0-null.h\"' $ASAN_CFLAGS -O" LDFLAGS="$ASAN_CFLAGS"
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02004266
Gilles Peskinecf740502019-07-03 20:43:05 +02004267 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
4268 make test
4269
4270 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
Gilles Peskine56c01612019-07-03 20:43:32 +02004271 # Just the calloc selftest. "make test" ran the others as part of the
Gilles Peskinecf740502019-07-03 20:43:05 +02004272 # test suites.
4273 programs/test/selftest calloc
4274
Gilles Peskineec10bf12019-09-20 19:56:06 +02004275 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
4276 # Run a subset of the tests. The choice is a balance between coverage
4277 # and time (including time indirectly wasted due to flaky tests).
4278 # The current choice is to skip tests whose description includes
4279 # "proxy", which is an approximation of skipping tests that use the
4280 # UDP proxy, which tend to be slower and flakier.
4281 tests/ssl-opt.sh -e 'proxy'
4282}
4283
Arto Kinnunen3eb50e72023-04-14 17:43:36 +08004284support_test_aesni() {
Yanray Wang012b6bb2023-05-11 17:47:56 +08004285 # Check that gcc targets x86_64 (we can build AESNI), and check for
Arto Kinnunen3eb50e72023-04-14 17:43:36 +08004286 # AESNI support on the host (we can run AESNI).
Arto Kinnunen3eb50e72023-04-14 17:43:36 +08004287 #
4288 # The name of this function is possibly slightly misleading, but needs to align
4289 # with the name of the corresponding test, component_test_aesni.
4290 #
Yanray Wang012b6bb2023-05-11 17:47:56 +08004291 # In principle 32-bit x86 can support AESNI, but our implementation does not
Arto Kinnunen3eb50e72023-04-14 17:43:36 +08004292 # support 32-bit x86, so we check for x86-64.
4293 # We can only grep /proc/cpuinfo on Linux, so this also checks for Linux
4294 (gcc -v 2>&1 | grep Target | grep -q x86_64) &&
Yanray Wang374c3ae2023-05-05 12:46:48 +08004295 [[ "$HOSTTYPE" == "x86_64" && "$OSTYPE" == "linux-gnu" ]] &&
Jerry Yua7de78d2023-08-08 12:57:35 +08004296 (lscpu | grep -qw aes)
Yanray Wang374c3ae2023-05-05 12:46:48 +08004297}
4298
4299component_test_aesni () { # ~ 60s
4300 # This tests the two AESNI implementations (intrinsics and assembly), and also the plain C
Yanray Wang42924412023-06-14 17:10:13 +08004301 # fallback. It also tests the logic that is used to select which implementation(s) to build.
Yanray Wang374c3ae2023-05-05 12:46:48 +08004302 #
Yanray Wang012b6bb2023-05-11 17:47:56 +08004303 # This test does not require the host to have support for AESNI (if it doesn't, the run-time
Yanray Wang374c3ae2023-05-05 12:46:48 +08004304 # AESNI detection will fallback to the plain C implementation, so the tests will instead
4305 # exercise the plain C impl).
4306
Yanray Wang012b6bb2023-05-11 17:47:56 +08004307 msg "build: default config with different AES implementations"
4308 scripts/config.py set MBEDTLS_AESNI_C
Jerry Yu17a9d2e2023-08-03 16:14:18 +08004309 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Yanray Wang012b6bb2023-05-11 17:47:56 +08004310 scripts/config.py set MBEDTLS_HAVE_ASM
4311
4312 # test the intrinsics implementation
4313 msg "AES tests, test intrinsics"
4314 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004315 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
Yanray Wang012b6bb2023-05-11 17:47:56 +08004316 # check that we built intrinsics - this should be used by default when supported by the compiler
Jerry Yu1221a312023-08-03 16:09:07 +08004317 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
Yanray Wang012b6bb2023-05-11 17:47:56 +08004318
4319 # test the asm implementation
4320 msg "AES tests, test assembly"
4321 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004322 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mno-pclmul -mno-sse2 -mno-aes'
Yanray Wang012b6bb2023-05-11 17:47:56 +08004323 # check that we built assembly - this should be built if the compiler does not support intrinsics
Jerry Yu1221a312023-08-03 16:09:07 +08004324 ./programs/test/selftest aes | grep "AESNI code" | grep -q "assembly"
Gilles Peskine8f073122018-11-27 15:58:47 +01004325
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004326 # test the plain C implementation
Gilles Peskine8f073122018-11-27 15:58:47 +01004327 scripts/config.py unset MBEDTLS_AESNI_C
Jerry Yu17a9d2e2023-08-03 16:14:18 +08004328 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004329 msg "AES tests, plain C"
Gilles Peskine8f073122018-11-27 15:58:47 +01004330 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004331 make CC=gcc CFLAGS='-O2 -Werror'
Gilles Peskine8f073122018-11-27 15:58:47 +01004332 # check that there is no AESNI code present
Jerry Yu1221a312023-08-03 16:09:07 +08004333 ./programs/test/selftest aes | not grep -q "AESNI code"
Jerry Yu76a51b92023-08-08 16:03:55 +08004334 not grep -q "AES note: using AESNI" ./programs/test/selftest
4335 grep -q "AES note: built-in implementation." ./programs/test/selftest
Jerry Yu8a599c02023-08-03 17:01:02 +08004336
4337 # test the intrinsics implementation
4338 scripts/config.py set MBEDTLS_AESNI_C
4339 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4340 msg "AES tests, test AESNI only"
4341 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004342 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
Jerry Yua7de78d2023-08-08 12:57:35 +08004343 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
4344 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
Jerry Yu76a51b92023-08-08 16:03:55 +08004345 grep -q "AES note: using AESNI" ./programs/test/selftest
4346 not grep -q "AES note: built-in implementation." ./programs/test/selftest
Gilles Peskine8f073122018-11-27 15:58:47 +01004347}
4348
Jerry Yu193cbc02023-08-03 17:06:29 +08004349
Jerry Yub6d39c22023-08-16 15:11:48 +08004350
4351support_test_aesni_m32() {
4352 support_test_m32_o0 && (lscpu | grep -qw aes)
4353}
4354
4355component_test_aesni_m32 () { # ~ 60s
4356 # This tests are duplicated from component_test_aesni for i386 target
4357 #
4358 # AESNI intrinsic code supports i386 and assembly code does not support it.
4359
4360 msg "build: default config with different AES implementations"
4361 scripts/config.py set MBEDTLS_AESNI_C
4362 scripts/config.py set MBEDTLS_PADLOCK_C
4363 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4364 scripts/config.py set MBEDTLS_HAVE_ASM
4365
4366 # test the intrinsics implementation
4367 msg "AES tests, test intrinsics"
4368 make clean
4369 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
4370 # check that we built intrinsics - this should be used by default when supported by the compiler
4371 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
4372 grep -q "AES note: using AESNI" ./programs/test/selftest
4373 grep -q "AES note: built-in implementation." ./programs/test/selftest
4374 grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4375 grep -q mbedtls_aesni_has_support ./programs/test/selftest
4376
4377 scripts/config.py set MBEDTLS_AESNI_C
Jerry Yub6d39c22023-08-16 15:11:48 +08004378 scripts/config.py unset MBEDTLS_PADLOCK_C
4379 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4380 msg "AES tests, test AESNI only"
4381 make clean
4382 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
4383 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
4384 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
4385 grep -q "AES note: using AESNI" ./programs/test/selftest
4386 not grep -q "AES note: built-in implementation." ./programs/test/selftest
4387 not grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4388 not grep -q mbedtls_aesni_has_support ./programs/test/selftest
4389}
4390
Jerry Yu193cbc02023-08-03 17:06:29 +08004391# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
4392component_build_aes_aesce_armcc () {
4393 msg "Build: AESCE test on arm64 platform without plain C."
4394 scripts/config.py baremetal
4395
4396 # armc[56] don't support SHA-512 intrinsics
4397 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
4398
4399 # Stop armclang warning about feature detection for A64_CRYPTO.
4400 # With this enabled, the library does build correctly under armclang,
4401 # but in baremetal builds (as tested here), feature detection is
4402 # unavailable, and the user is notified via a #warning. So enabling
4403 # this feature would prevent us from building with -Werror on
4404 # armclang. Tracked in #7198.
4405 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
4406 scripts/config.py set MBEDTLS_HAVE_ASM
4407
4408 msg "AESCE, build with default configuration."
4409 scripts/config.py set MBEDTLS_AESCE_C
4410 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4411 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
4412
4413 msg "AESCE, build AESCE only"
4414 scripts/config.py set MBEDTLS_AESCE_C
4415 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4416 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
4417}
4418
Jerry Yuc935aa62023-08-03 17:08:27 +08004419# For timebeing, no VIA Padlock platform available.
4420component_build_aes_via_padlock () {
4421
4422 msg "AES:VIA PadLock, build with default configuration."
Jerry Yu506759f2023-08-16 17:11:22 +08004423 scripts/config.py unset MBEDTLS_AESNI_C
Jerry Yuc935aa62023-08-03 17:08:27 +08004424 scripts/config.py set MBEDTLS_PADLOCK_C
4425 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4426 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Jerry Yu506759f2023-08-16 17:11:22 +08004427 grep -q mbedtls_padlock_has_support ./programs/test/selftest
Jerry Yuc935aa62023-08-03 17:08:27 +08004428
4429}
4430
4431support_build_aes_via_padlock_only () {
4432 ( [ "$MBEDTLS_TEST_PLATFORM" == "Linux-x86_64" ] || \
4433 [ "$MBEDTLS_TEST_PLATFORM" == "Linux-amd64" ] ) && \
4434 [ "`dpkg --print-foreign-architectures`" == "i386" ]
4435}
4436
Jerry Yu193cbc02023-08-03 17:06:29 +08004437support_build_aes_aesce_armcc () {
4438 support_build_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +01004439}
4440
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004441component_test_aes_only_128_bit_keys () {
Gilles Peskine8f073122018-11-27 15:58:47 +01004442 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01004443 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01004444 scripts/config.py unset MBEDTLS_PADLOCK_C
4445
4446 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004447
Gilles Peskine8f073122018-11-27 15:58:47 +01004448 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
4449 make test
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004450}
4451
Gilles Peskine8f073122018-11-27 15:58:47 +01004452component_test_no_ctr_drbg_aes_only_128_bit_keys () {
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004453 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
Gilles Peskine8f073122018-11-27 15:58:47 +01004454 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4455 scripts/config.py unset MBEDTLS_CTR_DRBG_C
4456 scripts/config.py unset MBEDTLS_PADLOCK_C
4457
Gilles Peskine592f5912019-10-07 18:49:32 +02004458 make CC=clang CFLAGS='-Werror -Wall -Wextra'
4459
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004460 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
4461 make test
4462}
Gilles Peskine592f5912019-10-07 18:49:32 +02004463
4464component_test_aes_only_128_bit_keys_have_builtins () {
4465 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4466 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4467 scripts/config.py unset MBEDTLS_PADLOCK_C
4468 scripts/config.py unset MBEDTLS_AESNI_C
4469 scripts/config.py unset MBEDTLS_AESCE_C
4470
4471 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004472
4473 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4474 make test
Gilles Peskine592f5912019-10-07 18:49:32 +02004475
4476 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4477 programs/test/selftest
4478}
4479
4480component_test_aes_fewer_tables () {
4481 msg "build: default config with AES_FEWER_TABLES enabled"
4482 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
4483 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004484
4485 msg "test: AES_FEWER_TABLES"
4486 make test
4487}
Gilles Peskine592f5912019-10-07 18:49:32 +02004488
4489component_test_aes_rom_tables () {
4490 msg "build: default config with AES_ROM_TABLES enabled"
4491 scripts/config.py set MBEDTLS_AES_ROM_TABLES
4492 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
4493
4494 msg "test: AES_ROM_TABLES"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02004495 make test
4496}
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004497
Gilles Peskine004206c2019-10-21 17:11:33 +02004498component_test_aes_fewer_tables_and_rom_tables () {
Gilles Peskinef96aefe2019-07-24 14:58:38 +02004499 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
4500 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
4501 scripts/config.py set MBEDTLS_AES_ROM_TABLES
4502 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
4503
Steven Cooremand57203d2020-07-16 20:28:59 +02004504 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
Ronald Cron32a432a2023-03-28 09:19:04 +02004505 make test
Steven Cooreman753f9732021-03-15 11:38:44 +01004506}
Steven Cooreman6801f082021-02-19 17:21:22 +01004507
Yanray Wang49cd4b52023-11-10 11:58:37 +08004508# helper for common_block_cipher_no_decrypt() which:
4509# - enable/disable the list of config options passed from -s/-u respectively.
4510# - build
4511# - test for tests_suite_xxx
4512# - selftest
4513#
4514# Usage: helper_block_cipher_no_decrypt_build_test
4515# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
4516# Options: -s set_opts the list of config options to enable
4517# -u unset_opts the list of config options to disable
4518# -c cflags the list of options passed to CFLAGS
4519# -l ldflags the list of options passed to LDFLAGS
4520helper_block_cipher_no_decrypt_build_test () {
4521 while [ $# -gt 0 ]; do
4522 case "$1" in
4523 -s)
4524 shift; local set_opts="$1";;
4525 -u)
4526 shift; local unset_opts="$1";;
4527 -c)
Yanray Wang07e663d2023-11-13 17:15:39 +08004528 shift; local cflags="-Werror -Wall -Wextra $1";;
Yanray Wang49cd4b52023-11-10 11:58:37 +08004529 -l)
4530 shift; local ldflags="$1";;
4531 esac
4532 shift
4533 done
4534 set_opts="${set_opts:-}"
4535 unset_opts="${unset_opts:-}"
4536 cflags="${cflags:-}"
4537 ldflags="${ldflags:-}"
4538
Yanray Wangb2d6e522023-11-13 16:57:47 +08004539 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
4540 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
Yanray Wang49cd4b52023-11-10 11:58:37 +08004541
4542 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
4543 make clean
4544 make CC=gcc CFLAGS="$cflags" LDFLAGS="$ldflags"
4545
4546 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
4547 not grep mbedtls_aes_setkey_dec library/aes.o
4548 not grep mbedtls_aria_setkey_dec library/aria.o
4549 not grep mbedtls_camellia_setkey_dec library/camellia.o
4550 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
4551 not grep mbedtls_internal_aes_decrypt library/aes.o
Yanray Wang85b74652023-11-13 16:48:36 +08004552 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
4553 not grep mbedtls_aesni_inverse_key library/aesni.o
Yanray Wang49cd4b52023-11-10 11:58:37 +08004554
4555 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
4556 make test
4557
4558 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
4559 programs/test/selftest
4560}
4561
4562# This is a common configuration function used in:
4563# - component_test_block_cipher_no_decrypt_aesni_legacy()
4564# - component_test_block_cipher_no_decrypt_aesni_use_psa()
4565# in order to test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics,
4566# AESNI assembly and AES C implementation on x86_64 and with AESNI intrinsics
4567# on x86.
4568common_block_cipher_no_decrypt () {
4569 # test AESNI intrinsics
4570 helper_block_cipher_no_decrypt_build_test \
4571 -s "MBEDTLS_AESNI_C" \
Yanray Wang07e663d2023-11-13 17:15:39 +08004572 -c "-mpclmul -msse2 -maes"
Yanray Wang49cd4b52023-11-10 11:58:37 +08004573
4574 # test AESNI assembly
4575 helper_block_cipher_no_decrypt_build_test \
4576 -s "MBEDTLS_AESNI_C" \
Yanray Wang07e663d2023-11-13 17:15:39 +08004577 -c "-mno-pclmul -mno-sse2 -mno-aes"
Yanray Wang49cd4b52023-11-10 11:58:37 +08004578
4579 # test AES C implementation
4580 helper_block_cipher_no_decrypt_build_test \
Yanray Wang07e663d2023-11-13 17:15:39 +08004581 -u "MBEDTLS_AESNI_C"
Yanray Wang49cd4b52023-11-10 11:58:37 +08004582
4583 # test AESNI intrinsics for i386 target
4584 helper_block_cipher_no_decrypt_build_test \
4585 -s "MBEDTLS_AESNI_C" \
Yanray Wang07e663d2023-11-13 17:15:39 +08004586 -c "-m32 -mpclmul -msse2 -maes" \
Yanray Wang49cd4b52023-11-10 11:58:37 +08004587 -l "-m32"
4588}
4589
Yanray Wang3ae11992023-11-13 17:32:09 +08004590# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
4591# usage: 0: no PSA crypto configuration
4592# 1: use PSA crypto configuration
4593config_block_cipher_no_decrypt () {
4594 use_psa=$1
4595
Yanray Wang66111392023-10-31 18:54:54 +08004596 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Yanray Wanga8ac23a2023-05-15 18:03:10 +08004597 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
4598 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
Yanray Wang3caaf0c2023-09-07 17:50:14 +08004599 scripts/config.py unset MBEDTLS_DES_C
Yanray Wanga8ac23a2023-05-15 18:03:10 +08004600 scripts/config.py unset MBEDTLS_NIST_KW_C
4601
Yanray Wang3ae11992023-11-13 17:32:09 +08004602 if [ "$use_psa" -eq 1 ]; then
4603 # Enable support for cryptographic mechanisms through the PSA API.
4604 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
4605 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
4606 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
4607 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
4608 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
4609 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
4610 fi
4611}
4612
4613component_test_block_cipher_no_decrypt_aesni () {
4614 config_block_cipher_no_decrypt 0
Yanray Wang49cd4b52023-11-10 11:58:37 +08004615 common_block_cipher_no_decrypt
Yanray Wanga8ac23a2023-05-15 18:03:10 +08004616}
4617
Yanray Wangf1496402023-11-01 18:55:13 +08004618component_test_block_cipher_no_decrypt_aesni_use_psa () {
Yanray Wang3ae11992023-11-13 17:32:09 +08004619 config_block_cipher_no_decrypt 1
Yanray Wang49cd4b52023-11-10 11:58:37 +08004620 common_block_cipher_no_decrypt
Yanray Wang78219042023-08-31 15:00:57 +08004621}
4622
Yanray Wang66111392023-10-31 18:54:54 +08004623support_test_block_cipher_no_decrypt_aesce_armcc () {
Yanray Wang799bd842023-11-10 12:21:35 +08004624 support_build_armcc
Yanray Wangbf66ef92023-08-31 14:47:01 +08004625}
4626
Yanray Wang66111392023-10-31 18:54:54 +08004627component_test_block_cipher_no_decrypt_aesce_armcc () {
Yanray Wangbf66ef92023-08-31 14:47:01 +08004628 scripts/config.py baremetal
4629
4630 # armc[56] don't support SHA-512 intrinsics
4631 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
4632
4633 # Stop armclang warning about feature detection for A64_CRYPTO.
4634 # With this enabled, the library does build correctly under armclang,
4635 # but in baremetal builds (as tested here), feature detection is
4636 # unavailable, and the user is notified via a #warning. So enabling
4637 # this feature would prevent us from building with -Werror on
4638 # armclang. Tracked in #7198.
4639 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
4640 scripts/config.py set MBEDTLS_HAVE_ASM
4641
Yanray Wang3ae11992023-11-13 17:32:09 +08004642 config_block_cipher_no_decrypt 1
Yanray Wangbf66ef92023-08-31 14:47:01 +08004643
4644 # test AESCE baremetal build
4645 scripts/config.py set MBEDTLS_AESCE_C
Yanray Wang66111392023-10-31 18:54:54 +08004646 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
4647 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
Yanray Wangbf66ef92023-08-31 14:47:01 +08004648
Yanray Wangef1b04d2023-09-08 11:09:26 +08004649 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
4650 not grep mbedtls_aes_setkey_dec library/aes.o
4651 not grep mbedtls_aria_setkey_dec library/aria.o
4652 not grep mbedtls_camellia_setkey_dec library/camellia.o
4653 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
4654 not grep mbedtls_internal_aes_decrypt library/aes.o
Yanray Wang85b74652023-11-13 16:48:36 +08004655 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
Yanray Wang4cd1b162023-11-10 12:18:29 +08004656 not grep mbedtls_aesce_inverse_key library/aesce.o
4657 not grep aesce_decrypt_block library/aesce.o
Yanray Wangbf66ef92023-08-31 14:47:01 +08004658}
4659
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004660component_test_ctr_drbg_aes_256_sha_256 () {
4661 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02004662 scripts/config.py full
4663 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4664 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Simon Butcherbc6a4862016-03-07 17:35:59 +00004665 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004666 make
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02004667
4668 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4669 make test
Simon Butcherf95c1762016-11-10 17:25:58 +00004670}
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004671
4672component_test_ctr_drbg_aes_128_sha_512 () {
4673 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
4674 scripts/config.py full
4675 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4676 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
4677 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine8f073122018-11-27 15:58:47 +01004678 make
4679
4680 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
4681 make test
Gilles Peskinef96aefe2019-07-24 14:58:38 +02004682}
4683
4684component_test_ctr_drbg_aes_128_sha_256 () {
4685 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4686 scripts/config.py full
4687 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4688 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
4689 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
4690 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4691 make
4692
4693 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4694 make test
4695}
4696
4697component_test_se_default () {
4698 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
4699 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01004700 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004701
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004702 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
4703 make test
4704}
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02004705
Steven Cooremand57203d2020-07-16 20:28:59 +02004706component_test_psa_crypto_drivers () {
Gilles Peskine1997f302023-07-26 18:45:20 +02004707 msg "build: full + test drivers dispatching to builtins"
Steven Cooremand57203d2020-07-16 20:28:59 +02004708 scripts/config.py full
Gilles Peskine1997f302023-07-26 18:45:20 +02004709 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Gilles Peskine3587dfd2021-09-20 19:20:04 +02004710 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
4711 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
Ronald Cron17b3afc2020-12-10 18:17:09 +01004712 loc_cflags="${loc_cflags} -I../tests/include -O2"
4713
4714 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
Steven Cooremand57203d2020-07-16 20:28:59 +02004715
Gilles Peskine1997f302023-07-26 18:45:20 +02004716 msg "test: full + test drivers dispatching to builtins"
Steven Cooremand57203d2020-07-16 20:28:59 +02004717 make test
4718}
4719
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004720component_test_make_shared () {
4721 msg "build/test: make shared" # ~ 40s
4722 make SHARED=1 all check
4723 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskineca144592021-11-04 12:52:14 +01004724 programs/test/dlopen_demo.sh
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004725}
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02004726
4727component_test_cmake_shared () {
4728 msg "build/test: cmake shared" # ~ 2min
4729 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
4730 make
4731 ldd programs/util/strerror | grep libmbedcrypto
4732 make test
Gilles Peskineca144592021-11-04 12:52:14 +01004733 programs/test/dlopen_demo.sh
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02004734}
4735
Gilles Peskineec10bf12019-09-20 19:56:06 +02004736test_build_opt () {
4737 info=$1 cc=$2; shift 2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004738 $cc --version
Gilles Peskineec10bf12019-09-20 19:56:06 +02004739 for opt in "$@"; do
4740 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskinee094a182020-04-14 20:08:41 +02004741 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02004742 # We're confident enough in compilers to not run _all_ the tests,
4743 # but at least run the unit tests. In particular, runs with
4744 # optimizations use inline assembly whereas runs with -O0
4745 # skip inline assembly.
4746 make test # ~30s
4747 make clean
4748 done
4749}
4750
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004751# For FreeBSD we invoke the function by name so this condition is added
4752# to disable the existing test_clang_opt function for linux.
4753if [[ $(uname) != "Linux" ]]; then
4754 component_test_clang_opt () {
4755 scripts/config.py full
4756 test_build_opt 'full config' clang -O0 -Os -O2
4757 }
4758fi
4759
4760component_test_clang_latest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004761 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004762 test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004763}
4764support_test_clang_latest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004765 type "$CLANG_LATEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02004766}
4767
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004768component_test_clang_earliest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004769 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004770 test_build_opt 'full config' "$CLANG_EARLIEST" -O0
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004771}
4772support_test_clang_earliest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004773 type "$CLANG_EARLIEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004774}
4775
4776component_test_gcc_latest_opt () {
4777 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004778 test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004779}
4780support_test_gcc_latest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004781 type "$GCC_LATEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004782}
4783
4784component_test_gcc_earliest_opt () {
4785 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004786 test_build_opt 'full config' "$GCC_EARLIEST" -O0
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004787}
4788support_test_gcc_earliest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004789 type "$GCC_EARLIEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02004790}
4791
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02004792component_build_mbedtls_config_file () {
4793 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
Gilles Peskine2003c2f2022-04-07 20:55:57 +02004794 scripts/config.py -w full_config.h full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02004795 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
4796 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
Gilles Peskine45e680e2022-04-13 23:23:21 +02004797 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskinee10df772022-04-07 21:06:41 +02004798 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
4799 make clean
4800
4801 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
4802 # In the user config, disable one feature (for simplicity, pick a feature
4803 # that nothing else depends on).
4804 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
4805 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
4806 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
4807
4808 rm -f user_config.h full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004809}
4810
Gilles Peskine7d904e72022-04-07 21:59:14 +02004811component_build_psa_config_file () {
4812 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
4813 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
4814 cp "$CRYPTO_CONFIG_H" psa_test_config.h
4815 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
4816 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Gilles Peskine45e680e2022-04-13 23:23:21 +02004817 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine7d904e72022-04-07 21:59:14 +02004818 programs/test/query_compile_time_config MBEDTLS_CMAC_C
4819 make clean
4820
4821 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
4822 # In the user config, disable one feature, which will reflect on the
4823 # mbedtls configuration so we can query it with query_compile_time_config.
4824 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
4825 scripts/config.py unset MBEDTLS_CMAC_C
4826 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
4827 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
4828
4829 rm -f psa_test_config.h psa_user_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004830}
4831
Gilles Peskinedf6e84a2023-02-22 22:09:51 +01004832component_build_psa_alt_headers () {
4833 msg "build: make with PSA alt headers" # ~20s
4834
4835 # Generate alternative versions of the substitutable headers with the
4836 # same content except different include guards.
4837 make -C tests include/alt-extra/psa/crypto_platform_alt.h include/alt-extra/psa/crypto_struct_alt.h
4838
4839 # Build the library and some programs.
4840 # Don't build the fuzzers to avoid having to go through hoops to set
4841 # a correct include path for programs/fuzz/Makefile.
4842 make CFLAGS="-I ../tests/include/alt-extra -DMBEDTLS_PSA_CRYPTO_PLATFORM_FILE='\"psa/crypto_platform_alt.h\"' -DMBEDTLS_PSA_CRYPTO_STRUCT_FILE='\"psa/crypto_struct_alt.h\"'" lib
4843 make -C programs -o fuzz CFLAGS="-I ../tests/include/alt-extra -DMBEDTLS_PSA_CRYPTO_PLATFORM_FILE='\"psa/crypto_platform_alt.h\"' -DMBEDTLS_PSA_CRYPTO_STRUCT_FILE='\"psa/crypto_struct_alt.h\"'"
4844
4845 # Check that we're getting the alternative include guards and not the
4846 # original include guards.
4847 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
4848 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
4849 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
4850 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
4851}
4852
Gilles Peskine8f073122018-11-27 15:58:47 +01004853component_test_m32_o0 () {
Gilles Peskine77f05352021-10-07 19:27:16 +02004854 # Build without optimization, so as to use portable C code (in a 32-bit
4855 # build) and not the i386-specific inline assembly.
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004856 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004857 scripts/config.py full
Jerry Yubdd96b92023-08-16 17:34:27 +08004858 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Gilles Peskine8fd59422019-10-21 17:11:33 +02004859 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004860
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004861 msg "test: i386, make, gcc -O0 (ASan build)"
4862 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01004863}
Gilles Peskine878cf602019-01-06 20:50:38 +00004864support_test_m32_o0 () {
4865 case $(uname -m) in
Pengyu Lvc92df3b2022-10-21 10:50:26 +00004866 amd64|x86_64) true;;
Gilles Peskine878cf602019-01-06 20:50:38 +00004867 *) false;;
4868 esac
4869}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004870
Gilles Peskineff0aee02021-10-05 09:36:03 +02004871component_test_m32_o2 () {
4872 # Build with optimization, to use the i386 specific inline assembly
4873 # and go faster for tests.
4874 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004875 scripts/config.py full
Jerry Yubdd96b92023-08-16 17:34:27 +08004876 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Gilles Peskineff0aee02021-10-05 09:36:03 +02004877 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004878
Gilles Peskineff0aee02021-10-05 09:36:03 +02004879 msg "test: i386, make, gcc -O2 (ASan build)"
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004880 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01004881
Gilles Peskineff0aee02021-10-05 09:36:03 +02004882 msg "test ssl-opt.sh, i386, make, gcc-O2"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004883 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01004884}
Gilles Peskinecf522222021-10-07 19:25:29 +02004885support_test_m32_o2 () {
Gilles Peskine878cf602019-01-06 20:50:38 +00004886 support_test_m32_o0 "$@"
4887}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004888
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004889component_test_m32_everest () {
4890 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004891 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Jerry Yubdd96b92023-08-16 17:34:27 +08004892 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Gilles Peskine8fd59422019-10-21 17:11:33 +02004893 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004894
4895 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
4896 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01004897
4898 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004899 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01004900
4901 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
4902 # Exclude some symmetric ciphers that are redundant here to gain time.
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02004903 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004904}
4905support_test_m32_everest () {
4906 support_test_m32_o0 "$@"
4907}
4908
Gilles Peskine8f073122018-11-27 15:58:47 +01004909component_test_mx32 () {
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004910 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004911 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02004912 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004913
4914 msg "test: 64-bit ILP32, make, gcc"
4915 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01004916}
Gilles Peskine878cf602019-01-06 20:50:38 +00004917support_test_mx32 () {
4918 case $(uname -m) in
4919 amd64|x86_64) true;;
4920 *) false;;
4921 esac
4922}
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004923
Peter Kolbus60c6da22018-12-27 06:59:04 -06004924component_test_min_mpi_window_size () {
4925 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004926 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06004927 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4928 make
4929
4930 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
4931 make test
4932}
4933
Gilles Peskine8f073122018-11-27 15:58:47 +01004934component_test_have_int32 () {
4935 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004936 scripts/config.py unset MBEDTLS_HAVE_ASM
4937 scripts/config.py unset MBEDTLS_AESNI_C
4938 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08004939 scripts/config.py unset MBEDTLS_AESCE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01004940 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004941
Gilles Peskine8f073122018-11-27 15:58:47 +01004942 msg "test: gcc, force 32-bit bignum limbs"
4943 make test
4944}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01004945
Gilles Peskine8f073122018-11-27 15:58:47 +01004946component_test_have_int64 () {
4947 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004948 scripts/config.py unset MBEDTLS_HAVE_ASM
4949 scripts/config.py unset MBEDTLS_AESNI_C
4950 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08004951 scripts/config.py unset MBEDTLS_AESCE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01004952 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01004953
Gilles Peskine8f073122018-11-27 15:58:47 +01004954 msg "test: gcc, force 64-bit bignum limbs"
4955 make test
4956}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004957
Gabor Mezeie256cc12023-07-26 17:28:48 +02004958component_test_have_int32_cmake_new_bignum () {
4959 msg "build: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
4960 scripts/config.py unset MBEDTLS_HAVE_ASM
4961 scripts/config.py unset MBEDTLS_AESNI_C
4962 scripts/config.py unset MBEDTLS_PADLOCK_C
4963 scripts/config.py unset MBEDTLS_AESCE_C
4964 scripts/config.py set MBEDTLS_TEST_HOOKS
Janos Follath2f045822023-07-31 10:57:16 +01004965 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Janos Follathf3135af2023-07-31 10:07:57 +01004966 make CC=gcc CFLAGS="$ASAN_CFLAGS -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32" LDFLAGS="$ASAN_CFLAGS"
Gabor Mezeie256cc12023-07-26 17:28:48 +02004967
4968 msg "test: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
4969 make test
4970}
4971
Gilles Peskine8f073122018-11-27 15:58:47 +01004972component_test_no_udbl_division () {
4973 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004974 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004975 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01004976 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004977
Gilles Peskine8f073122018-11-27 15:58:47 +01004978 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
4979 make test
4980}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004981
Gilles Peskine8f073122018-11-27 15:58:47 +01004982component_test_no_64bit_multiplication () {
4983 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004984 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004985 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01004986 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004987
Gilles Peskine8f073122018-11-27 15:58:47 +01004988 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
4989 make test
4990}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004991
Gilles Peskine3809f5f2020-11-09 15:40:05 +01004992component_test_no_strings () {
4993 msg "build: no strings" # ~10s
4994 scripts/config.py full
4995 # Disable options that activate a large amount of string constants.
4996 scripts/config.py unset MBEDTLS_DEBUG_C
4997 scripts/config.py unset MBEDTLS_ERROR_C
4998 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
4999 scripts/config.py unset MBEDTLS_VERSION_FEATURES
5000 make CFLAGS='-Werror -Os'
5001
5002 msg "test: no strings" # ~ 10s
5003 make test
5004}
5005
Hanno Beckerc5722d12020-10-09 11:10:42 +01005006component_test_no_x509_info () {
5007 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
5008 scripts/config.pl full
5009 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
5010 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
Gilles Peskineff0aee02021-10-05 09:36:03 +02005011 make CFLAGS='-Werror -O2'
Hanno Beckerc5722d12020-10-09 11:10:42 +01005012
5013 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
5014 make test
5015
5016 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005017 tests/ssl-opt.sh
Hanno Beckerc5722d12020-10-09 11:10:42 +01005018}
5019
Gilles Peskine8f073122018-11-27 15:58:47 +01005020component_build_arm_none_eabi_gcc () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02005021 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005022 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02005023 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 +02005024
Gilles Peskinee36fe812021-09-01 20:00:33 +02005025 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02005026 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01005027}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02005028
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02005029component_build_arm_linux_gnueabi_gcc_arm5vte () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02005030 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005031 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02005032 # Build for a target platform that's close to what Debian uses
5033 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
Dave Rodgman017a1992022-03-31 14:07:01 +01005034 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02005035 # Build everything including programs, see for example
Dave Rodgman017a1992022-03-31 14:07:01 +01005036 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02005037 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'
5038
Gilles Peskinee36fe812021-09-01 20:00:33 +02005039 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02005040 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t library/*.o
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02005041}
5042support_build_arm_linux_gnueabi_gcc_arm5vte () {
5043 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
5044}
5045
5046component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02005047 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02005048 scripts/config.py baremetal
5049 # This is an imperfect substitute for
5050 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnardae505ee2021-07-06 09:44:59 +02005051 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02005052 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 +02005053
Gilles Peskinee36fe812021-09-01 20:00:33 +02005054 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02005055 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02005056}
5057
Gilles Peskine6e2fb862020-04-30 23:00:53 +02005058component_build_arm_none_eabi_gcc_m0plus () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02005059 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
5060 scripts/config.py baremetal_size
Gilles Peskineaeedd742020-09-02 11:03:04 +02005061 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 +02005062
Gilles Peskinee36fe812021-09-01 20:00:33 +02005063 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02005064 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Manuel Pégourié-Gonnard67f80372023-06-06 13:01:18 +02005065 for lib in library/*.a; do
5066 echo "$lib:"
5067 ${ARM_NONE_EABI_GCC_PREFIX}size -t $lib | grep TOTALS
5068 done
Gilles Peskine6e2fb862020-04-30 23:00:53 +02005069}
5070
Gilles Peskine8f073122018-11-27 15:58:47 +01005071component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02005072 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005073 scripts/config.py baremetal
5074 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02005075 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 +01005076 echo "Checking that software 64-bit division is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005077 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01005078}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02005079
Gilles Peskine8f073122018-11-27 15:58:47 +01005080component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02005081 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005082 scripts/config.py baremetal
5083 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02005084 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 +01005085 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005086 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01005087}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02005088
Dave Rodgman8c315f22023-06-02 10:26:24 -04005089component_build_arm_clang_thumb () {
5090 # ~ 30s
5091
5092 scripts/config.py baremetal
5093
5094 msg "build: clang thumb 2, make"
5095 make clean
5096 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
5097
5098 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
5099 msg "build: clang thumb 1 -O0, make"
5100 make clean
5101 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
5102
5103 msg "build: clang thumb 1 -Os, make"
5104 make clean
5105 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
5106}
5107
Gilles Peskine8f073122018-11-27 15:58:47 +01005108component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02005109 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005110 scripts/config.py baremetal
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00005111 # armc[56] don't support SHA-512 intrinsics
5112 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Dave Rodgman2f386c52023-03-02 13:38:33 +00005113
Dave Rodgman0fddf822023-03-02 15:32:12 +00005114 # Stop armclang warning about feature detection for A64_CRYPTO.
5115 # With this enabled, the library does build correctly under armclang,
5116 # but in baremetal builds (as tested here), feature detection is
5117 # unavailable, and the user is notified via a #warning. So enabling
5118 # this feature would prevent us from building with -Werror on
5119 # armclang. Tracked in #7198.
Dave Rodgman2f386c52023-03-02 13:38:33 +00005120 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
5121
Hanno Beckerf0762e92022-07-15 12:08:19 +01005122 scripts/config.py set MBEDTLS_HAVE_ASM
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00005123
Gilles Peskinebca6ab92017-12-19 18:24:31 +01005124 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02005125
5126 msg "size: ARM Compiler 5"
5127 "$ARMC5_FROMELF" -z library/*.o
5128
Dave Rodgmanb45d58b2023-06-02 13:54:00 -04005129 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
Hanno Beckerf0762e92022-07-15 12:08:19 +01005130
Gilles Peskinebca6ab92017-12-19 18:24:31 +01005131 # ARM Compiler 6 - Target ARMv7-A
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01005132 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02005133
Gilles Peskinebca6ab92017-12-19 18:24:31 +01005134 # ARM Compiler 6 - Target ARMv7-M
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01005135 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m"
5136
5137 # ARM Compiler 6 - Target ARMv7-M+DSP
5138 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m+dsp"
Simon Butcher940737f2017-07-23 13:42:36 +02005139
Gilles Peskinebca6ab92017-12-19 18:24:31 +01005140 # ARM Compiler 6 - Target ARMv8-A - AArch32
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01005141 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02005142
Gilles Peskinebca6ab92017-12-19 18:24:31 +01005143 # ARM Compiler 6 - Target ARMv8-M
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01005144 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02005145
Tom Cosgrove6ec39ca2023-06-09 15:34:31 +01005146 # ARM Compiler 6 - Target ARMv8.2-A - AArch64
5147 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
5148
Dave Rodgmanb45d58b2023-06-02 13:54:00 -04005149 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
5150 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
5151
Dave Rodgman99318e62023-05-24 12:27:42 +01005152 # ARM Compiler 6 - Target Cortex-M0
5153 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
Gilles Peskine8f073122018-11-27 15:58:47 +01005154}
Tom Cosgrove6ec39ca2023-06-09 15:34:31 +01005155
Pengyu Lvdf070032023-02-24 16:03:31 +08005156support_build_armcc () {
Pengyu Lvc6298ad2023-03-01 10:31:29 +08005157 armc5_cc="$ARMC5_BIN_DIR/armcc"
5158 armc6_cc="$ARMC6_BIN_DIR/armclang"
5159 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
Pengyu Lvdf070032023-02-24 16:03:31 +08005160}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01005161
Jerry Yu81d5e1f2022-01-27 13:01:01 +08005162component_test_tls13_only () {
5163 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3, without MBEDTLS_SSL_PROTO_TLS1_2"
Ronald Cronc2e110f2022-11-22 09:01:46 +01005164 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Jerry Yuda5af222021-12-24 18:45:45 +08005165 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5166
Gilles Peskine4bb369c2022-10-29 17:44:19 +02005167 msg "test: TLS 1.3 only, all key exchange modes enabled"
5168 make test
Jerry Yubaa49342022-02-15 10:26:40 +08005169
Ronald Cronc3f43b62022-10-17 17:35:32 +02005170 msg "ssl-opt.sh: TLS 1.3 only, all key exchange modes enabled"
5171 tests/ssl-opt.sh
Jerry Yuda5af222021-12-24 18:45:45 +08005172}
5173
Ronald Cronc3f43b62022-10-17 17:35:32 +02005174component_test_tls13_only_psk () {
5175 msg "build: TLS 1.3 only from default, only PSK key exchange mode"
5176 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5177 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
5178 scripts/config.py unset MBEDTLS_ECDH_C
Przemek Stekiel0c231472023-06-14 11:12:45 +02005179 scripts/config.py unset MBEDTLS_DHM_C
Ronald Cronc3f43b62022-10-17 17:35:32 +02005180 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5181 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5182 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5183 scripts/config.py unset MBEDTLS_ECDSA_C
5184 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00005185 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01005186 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Crone3dac4a2022-06-10 17:21:51 +02005187 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5188
Ronald Cronc3f43b62022-10-17 17:35:32 +02005189 msg "test_suite_ssl: TLS 1.3 only, only PSK key exchange mode enabled"
5190 cd tests; ./test_suite_ssl; cd ..
Ronald Crone3dac4a2022-06-10 17:21:51 +02005191
Ronald Cronc3f43b62022-10-17 17:35:32 +02005192 msg "ssl-opt.sh: TLS 1.3 only, only PSK key exchange mode enabled"
5193 tests/ssl-opt.sh
5194}
5195
5196component_test_tls13_only_ephemeral () {
5197 msg "build: TLS 1.3 only from default, only ephemeral key exchange mode"
5198 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5199 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
Xiaokang Qian2dbfeda2022-11-15 10:52:57 +00005200 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005201 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5202
5203 msg "test_suite_ssl: TLS 1.3 only, only ephemeral key exchange mode"
5204 cd tests; ./test_suite_ssl; cd ..
5205
5206 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral key exchange mode"
5207 tests/ssl-opt.sh
5208}
5209
Przemek Stekiela01c2422023-06-13 10:46:48 +02005210component_test_tls13_only_ephemeral_ffdh () {
5211 msg "build: TLS 1.3 only from default, only ephemeral ffdh key exchange mode"
5212 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5213 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
5214 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
Przemek Stekielce05f542023-06-15 16:44:08 +02005215 scripts/config.py unset MBEDTLS_ECDH_C
5216
Przemek Stekiela01c2422023-06-13 10:46:48 +02005217 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5218
5219 msg "test_suite_ssl: TLS 1.3 only, only ephemeral ffdh key exchange mode"
5220 cd tests; ./test_suite_ssl; cd ..
5221
5222 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral ffdh key exchange mode"
5223 tests/ssl-opt.sh
5224}
5225
Ronald Cronc3f43b62022-10-17 17:35:32 +02005226component_test_tls13_only_psk_ephemeral () {
5227 msg "build: TLS 1.3 only from default, only PSK ephemeral key exchange mode"
5228 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5229 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5230 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5231 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5232 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5233 scripts/config.py unset MBEDTLS_ECDSA_C
5234 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00005235 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01005236 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005237 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5238
5239 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral key exchange mode"
5240 cd tests; ./test_suite_ssl; cd ..
5241
5242 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral key exchange mode"
5243 tests/ssl-opt.sh
5244}
5245
Przemek Stekiela01c2422023-06-13 10:46:48 +02005246component_test_tls13_only_psk_ephemeral_ffdh () {
5247 msg "build: TLS 1.3 only from default, only PSK ephemeral ffdh key exchange mode"
5248 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5249 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5250 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5251 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5252 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5253 scripts/config.py unset MBEDTLS_ECDSA_C
5254 scripts/config.py unset MBEDTLS_PKCS1_V21
5255 scripts/config.py unset MBEDTLS_PKCS7_C
5256 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Przemek Stekielce05f542023-06-15 16:44:08 +02005257 scripts/config.py unset MBEDTLS_ECDH_C
Przemek Stekiela01c2422023-06-13 10:46:48 +02005258 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5259
5260 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
5261 cd tests; ./test_suite_ssl; cd ..
5262
5263 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
5264 tests/ssl-opt.sh
5265}
5266
Ronald Cronc3f43b62022-10-17 17:35:32 +02005267component_test_tls13_only_psk_all () {
5268 msg "build: TLS 1.3 only from default, without ephemeral key exchange mode"
5269 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5270 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5271 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5272 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5273 scripts/config.py unset MBEDTLS_ECDSA_C
5274 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00005275 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01005276 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005277 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5278
5279 msg "test_suite_ssl: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
5280 cd tests; ./test_suite_ssl; cd ..
5281
5282 msg "ssl-opt.sh: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
5283 tests/ssl-opt.sh
5284}
5285
5286component_test_tls13_only_ephemeral_all () {
5287 msg "build: TLS 1.3 only from default, without PSK key exchange mode"
5288 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
Ronald Cronc2e110f2022-11-22 09:01:46 +01005289 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005290 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5291
5292 msg "test_suite_ssl: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
5293 cd tests; ./test_suite_ssl; cd ..
5294
5295 msg "ssl-opt.sh: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
5296 tests/ssl-opt.sh
Ronald Crone3dac4a2022-06-10 17:21:51 +02005297}
5298
Ronald Cron6f135e12021-12-08 16:57:54 +01005299component_test_tls13 () {
5300 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
5301 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005302 scripts/config.py set MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
5303 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
Ronald Cronc2e110f2022-11-22 09:01:46 +01005304 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005305 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
5306 make
Ronald Cron6f135e12021-12-08 16:57:54 +01005307 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005308 make test
Ronald Cron6f135e12021-12-08 16:57:54 +01005309 msg "ssl-opt.sh (TLS 1.3)"
Gilles Peskine827dbd92022-02-04 00:30:54 +01005310 tests/ssl-opt.sh
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005311}
5312
Ronald Cron6f135e12021-12-08 16:57:54 +01005313component_test_tls13_no_compatibility_mode () {
5314 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
5315 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005316 scripts/config.py unset MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
5317 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
Ronald Cronc2e110f2022-11-22 09:01:46 +01005318 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Hanno Beckera711f6e2020-05-04 12:03:51 +01005319 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
5320 make
Ronald Cron6f135e12021-12-08 16:57:54 +01005321 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
Hanno Becker6c53ecc2021-08-01 19:20:10 +01005322 make test
Ronald Cron6f135e12021-12-08 16:57:54 +01005323 msg "ssl-opt.sh (TLS 1.3 no compatibility mode)"
Gilles Peskine827dbd92022-02-04 00:30:54 +01005324 tests/ssl-opt.sh
Hanno Becker6c53ecc2021-08-01 19:20:10 +01005325}
5326
Jan Bruckner151f6422023-02-10 12:45:19 +01005327component_test_tls13_only_record_size_limit () {
5328 msg "build: TLS 1.3 only from default, record size limit extension enabled"
5329 scripts/config.py set MBEDTLS_SSL_RECORD_SIZE_LIMIT
5330 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5331
5332 msg "test_suite_ssl: TLS 1.3 only, record size limit extension enabled"
5333 cd tests; ./test_suite_ssl; cd ..
5334
5335 msg "ssl-opt.sh: (TLS 1.3 only, record size limit extension tests only)"
5336 # Both the server and the client will currently abort the handshake when they encounter the
5337 # record size limit extension. There is no way to prevent gnutls-cli from sending the extension
5338 # which makes all G_NEXT_CLI + P_SRV tests fail. Thus, run only the tests for the this extension.
5339 tests/ssl-opt.sh -f "Record Size Limit"
5340}
5341
Gilles Peskine8f073122018-11-27 15:58:47 +01005342component_build_mingw () {
5343 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Jerry Yubdd96b92023-08-16 17:34:27 +08005344 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Andrzej Kurek232e8f92019-10-03 03:18:01 -04005345 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs
Hanno Beckere963efa2018-01-03 10:03:43 +00005346
Gilles Peskine8f073122018-11-27 15:58:47 +01005347 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04005348 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
Gilles Peskine8f073122018-11-27 15:58:47 +01005349 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02005350
Gilles Peskine8f073122018-11-27 15:58:47 +01005351 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04005352 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 lib programs
5353 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 tests
Gilles Peskine8f073122018-11-27 15:58:47 +01005354 make WINDOWS_BUILD=1 clean
5355}
Jaeden Amero117b8a42019-04-17 15:19:26 +01005356support_build_mingw() {
Pengyu Lv51b5f002023-02-24 15:38:52 +08005357 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
5358 [0-5]*|"") false;;
Jaeden Amero117b8a42019-04-17 15:19:26 +01005359 *) true;;
5360 esac
5361}
Simon Butcher91aef332016-11-17 09:20:50 +00005362
Gilles Peskine8f073122018-11-27 15:58:47 +01005363component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005364 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005365 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005366 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
5367 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02005368
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005369 msg "test: main suites (MSan)" # ~ 10s
5370 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005371
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005372 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005373 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005374
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005375 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005376
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005377 if [ "$MEMORY" -gt 0 ]; then
5378 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005379 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005380 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01005381}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005382
Gilles Peskine69f190e2019-01-10 00:11:42 +01005383component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005384 msg "build: Release (clang)"
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005385 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005386 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
5387 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005388
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005389 msg "test: main suites, Valgrind (default config)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005390 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005391
Gilles Peskine636c26a2020-03-04 20:46:15 +01005392 # Optional parts (slow; currently broken on OS X because programs don't
5393 # seem to receive signals under valgrind on OS X).
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005394 # These optional parts don't run on the CI.
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005395 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005396 msg "test: ssl-opt.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005397 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005398 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005399
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005400 if [ "$MEMORY" -gt 1 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005401 msg "test: compat.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005402 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005403 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02005404
5405 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005406 msg "test: context-info.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005407 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02005408 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01005409}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005410
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005411component_test_valgrind_psa () {
5412 msg "build: Release, full (clang)"
5413 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
5414 scripts/config.py full
5415 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
5416 make
5417
5418 msg "test: main suites, Valgrind (full config)"
5419 make memcheck
5420}
5421
Paul Elliott62dc3922021-11-25 17:29:40 +00005422support_test_cmake_out_of_source () {
5423 distrib_id=""
5424 distrib_ver=""
5425 distrib_ver_minor=""
5426 distrib_ver_major=""
5427
5428 # Attempt to parse lsb-release to find out distribution and version. If not
5429 # found this should fail safe (test is supported).
5430 if [[ -f /etc/lsb-release ]]; then
5431
5432 while read -r lsb_line; do
5433 case "$lsb_line" in
5434 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
5435 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
5436 esac
5437 done < /etc/lsb-release
5438
5439 distrib_ver_major="${distrib_ver%%.*}"
5440 distrib_ver="${distrib_ver#*.}"
5441 distrib_ver_minor="${distrib_ver%%.*}"
5442 fi
5443
5444 # Running the out of source CMake test on Ubuntu 16.04 using more than one
5445 # processor (as the CI does) can create a race condition whereby the build
5446 # fails to see a generated file, despite that file actually having been
5447 # generated. This problem appears to go away with 18.04 or newer, so make
5448 # the out of source tests unsupported on Ubuntu 16.04.
5449 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
5450}
5451
Gilles Peskine8f073122018-11-27 15:58:47 +01005452component_test_cmake_out_of_source () {
David Horstmann862abe22023-09-28 10:42:10 +01005453 # Remove existing generated files so that we use the ones cmake
David Horstmann9f48fff2023-09-27 15:53:54 +01005454 # generates
5455 make neat
5456
Gilles Peskine8f073122018-11-27 15:58:47 +01005457 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01005458 MBEDTLS_ROOT_DIR="$PWD"
5459 mkdir "$OUT_OF_SOURCE_DIR"
5460 cd "$OUT_OF_SOURCE_DIR"
David Horstmann9f48fff2023-09-27 15:53:54 +01005461 # Note: Explicitly generate files as these are turned off in releases
5462 cmake -D CMAKE_BUILD_TYPE:String=Check -D GEN_FILES=ON "$MBEDTLS_ROOT_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01005463 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005464
Gilles Peskine8f073122018-11-27 15:58:47 +01005465 msg "test: cmake 'out-of-source' build"
5466 make test
Gilles Peskinea841c2a2022-04-16 11:31:25 +02005467 # Check that ssl-opt.sh can find the test programs.
Gilles Peskine8f073122018-11-27 15:58:47 +01005468 # Also ensure that there are no error messages such as
5469 # "No such file or directory", which would indicate that some required
5470 # file is missing (ssl-opt.sh tolerates the absence of some files so
5471 # may exit with status 0 but emit errors).
Gilles Peskinea841c2a2022-04-16 11:31:25 +02005472 ./tests/ssl-opt.sh -f 'Default' >ssl-opt.out 2>ssl-opt.err
Gilles Peskine7393ec52022-04-15 22:43:38 +02005473 grep PASS ssl-opt.out
Gilles Peskinef7e956c2020-03-28 18:56:09 +01005474 cat ssl-opt.err >&2
5475 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005476 [ ! -s ssl-opt.err ]
Gilles Peskine7393ec52022-04-15 22:43:38 +02005477 rm ssl-opt.out ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01005478 cd "$MBEDTLS_ROOT_DIR"
5479 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01005480}
Andres AGdc192212016-08-31 17:33:13 +01005481
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005482component_test_cmake_as_subdirectory () {
David Horstmann9f48fff2023-09-27 15:53:54 +01005483 # Remove existing generated files so that we use the ones CMake
5484 # generates
5485 make neat
5486
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005487 msg "build: cmake 'as-subdirectory' build"
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005488 cd programs/test/cmake_subproject
David Horstmann9f48fff2023-09-27 15:53:54 +01005489 # Note: Explicitly generate files as these are turned off in releases
5490 cmake -D GEN_FILES=ON .
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005491 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005492 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005493}
Gilles Peskinea3000992022-02-04 00:21:12 +01005494support_test_cmake_as_subdirectory () {
5495 support_test_cmake_out_of_source
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005496}
5497
Chris Kayd259e342021-03-25 16:03:25 +00005498component_test_cmake_as_package () {
David Horstmann6c979852023-09-28 10:40:22 +01005499 # Remove existing generated files so that we use the ones CMake
5500 # generates
5501 make neat
5502
Chris Kayd259e342021-03-25 16:03:25 +00005503 msg "build: cmake 'as-package' build"
Chris Kayd259e342021-03-25 16:03:25 +00005504 cd programs/test/cmake_package
5505 cmake .
5506 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005507 ./cmake_package
Chris Kayd259e342021-03-25 16:03:25 +00005508}
Gilles Peskinea3000992022-02-04 00:21:12 +01005509support_test_cmake_as_package () {
5510 support_test_cmake_out_of_source
Chris Kayd259e342021-03-25 16:03:25 +00005511}
5512
5513component_test_cmake_as_package_install () {
David Horstmann6c979852023-09-28 10:40:22 +01005514 # Remove existing generated files so that we use the ones CMake
5515 # generates
5516 make neat
5517
Chris Kayd259e342021-03-25 16:03:25 +00005518 msg "build: cmake 'as-installed-package' build"
Chris Kayd259e342021-03-25 16:03:25 +00005519 cd programs/test/cmake_package_install
5520 cmake .
5521 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005522 ./cmake_package_install
Chris Kayd259e342021-03-25 16:03:25 +00005523}
Gilles Peskinea3000992022-02-04 00:21:12 +01005524support_test_cmake_as_package_install () {
5525 support_test_cmake_out_of_source
Chris Kayd259e342021-03-25 16:03:25 +00005526}
5527
David Horstmann20550e32023-01-12 14:17:01 +00005528component_build_cmake_custom_config_file () {
David Horstmann969c1452023-01-31 10:34:44 +00005529 # Make a copy of config file to use for the in-tree test
5530 cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h
David Horstmann20550e32023-01-12 14:17:01 +00005531
5532 MBEDTLS_ROOT_DIR="$PWD"
5533 mkdir "$OUT_OF_SOURCE_DIR"
5534 cd "$OUT_OF_SOURCE_DIR"
5535
David Horstmann969c1452023-01-31 10:34:44 +00005536 # Build once to get the generated files (which need an intact config file)
David Horstmann20550e32023-01-12 14:17:01 +00005537 cmake "$MBEDTLS_ROOT_DIR"
5538 make
5539
5540 msg "build: cmake with -DMBEDTLS_CONFIG_FILE"
5541 scripts/config.py -w full_config.h full
David Horstmann969c1452023-01-31 10:34:44 +00005542 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005543 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR"
5544 make
5545
5546 msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
5547 # In the user config, disable one feature (for simplicity, pick a feature
5548 # that nothing else depends on).
5549 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
5550
5551 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR"
5552 make
5553 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5554
5555 rm -f user_config.h full_config.h
5556
5557 cd "$MBEDTLS_ROOT_DIR"
5558 rm -rf "$OUT_OF_SOURCE_DIR"
5559
5560 # Now repeat the test for an in-tree build:
5561
David Horstmann969c1452023-01-31 10:34:44 +00005562 # Restore config for the in-tree test
5563 mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005564
David Horstmann969c1452023-01-31 10:34:44 +00005565 # Build once to get the generated files (which need an intact config)
David Horstmann20550e32023-01-12 14:17:01 +00005566 cmake .
5567 make
5568
5569 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE"
5570 scripts/config.py -w full_config.h full
David Horstmann969c1452023-01-31 10:34:44 +00005571 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005572 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h .
5573 make
5574
5575 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
5576 # In the user config, disable one feature (for simplicity, pick a feature
5577 # that nothing else depends on).
5578 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
5579
5580 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h .
5581 make
5582 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5583
5584 rm -f user_config.h full_config.h
5585}
5586support_build_cmake_custom_config_file () {
5587 support_test_cmake_out_of_source
5588}
5589
5590
Tom Cosgrovedaddf112023-09-01 10:40:15 +01005591component_build_zeroize_checks () {
5592 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
5593
5594 scripts/config.py full
5595
5596 # Only compile - we're looking for sizeof-pointer-memaccess warnings
Tom Cosgroveb2fafa52023-09-01 14:40:21 +01005597 make CC=gcc CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess"
Tom Cosgrovedaddf112023-09-01 10:40:15 +01005598}
5599
5600
Gilles Peskine8f073122018-11-27 15:58:47 +01005601component_test_zeroize () {
5602 # Test that the function mbedtls_platform_zeroize() is not optimized away by
5603 # different combinations of compilers and optimization flags by using an
5604 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
5605 # system in all cases that the script fails, so we must manually search the
5606 # output to check whether the pass string is present and no failure strings
5607 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01005608
Gilles Peskine4976e822019-01-06 19:52:22 +00005609 # Don't try to disable ASLR. We don't care about ASLR here. We do care
5610 # about a spurious message if Gdb tries and fails, so suppress that.
5611 gdb_disable_aslr=
5612 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
5613 gdb_disable_aslr='set disable-randomization off'
5614 fi
5615
Gilles Peskine8f073122018-11-27 15:58:47 +01005616 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01005617 for compiler in clang gcc; do
5618 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
5619 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005620 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
5621 grep "The buffer was correctly zeroized" test_zeroize.log
5622 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01005623 rm -f test_zeroize.log
5624 make clean
5625 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01005626 done
Gilles Peskine8f073122018-11-27 15:58:47 +01005627}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005628
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005629component_test_psa_compliance () {
5630 msg "build: make, default config (out-of-box), libmbedcrypto.a only"
Bence Szépkútica9236b2021-10-25 19:29:07 +02005631 make -C library libmbedcrypto.a
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005632
5633 msg "unit test: test_psa_compliance.py"
5634 ./tests/scripts/test_psa_compliance.py
5635}
5636
5637support_test_psa_compliance () {
Bence Szépkútief0d02e2021-11-03 11:36:09 +01005638 # psa-compliance-tests only supports CMake >= 3.10.0
Bence Szépkútica9236b2021-10-25 19:29:07 +02005639 ver="$(cmake --version)"
5640 ver="${ver#cmake version }"
5641 ver_major="${ver%%.*}"
5642
5643 ver="${ver#*.}"
5644 ver_minor="${ver%%.*}"
5645
5646 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005647}
5648
Gilles Peskinec848d222022-12-09 12:23:35 +01005649component_check_code_style () {
5650 msg "Check C code style"
5651 ./scripts/code_style.py
David Horstmann92b5ac12022-11-10 18:30:52 +00005652}
5653
Gilles Peskinec848d222022-12-09 12:23:35 +01005654support_check_code_style() {
David Horstmann92b5ac12022-11-10 18:30:52 +00005655 case $(uncrustify --version) in
5656 *0.75.1*) true;;
5657 *) false;;
5658 esac
5659}
5660
Gilles Peskine8f073122018-11-27 15:58:47 +01005661component_check_python_files () {
5662 msg "Lint: Python scripts"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005663 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01005664}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005665
Joe Subbianid614c0b2021-07-29 11:18:29 +01005666component_check_test_helpers () {
5667 msg "unit test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02005668 # unittest writes out mundane stuff like number or tests run on stderr.
5669 # Our convention is to reserve stderr for actual errors, and write
5670 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005671 ./tests/scripts/test_generate_test_code.py 2>&1
Joe Subbianid614c0b2021-07-29 11:18:29 +01005672
Joe Subbiania25ffab2021-08-06 09:41:27 +01005673 msg "unit test: translate_ciphers.py"
5674 python3 -m unittest tests/scripts/translate_ciphers.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01005675}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005676
Jerry Yud767cc42023-03-31 15:03:55 +08005677
Gilles Peskine192c72f2017-12-21 15:59:21 +01005678################################################################
5679#### Termination
5680################################################################
5681
Gilles Peskine8f073122018-11-27 15:58:47 +01005682post_report () {
5683 msg "Done, cleaning up"
Gilles Peskinef83eb822020-03-30 20:11:39 +02005684 final_cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005685
Gilles Peskine8f073122018-11-27 15:58:47 +01005686 final_report
5687}
5688
5689
5690
5691################################################################
5692#### Run all the things
5693################################################################
5694
Gilles Peskine5d996822020-03-28 21:09:21 +01005695# Function invoked by --error-test to test error reporting.
5696pseudo_component_error_test () {
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005697 msg "Testing error reporting $error_test_i"
Gilles Peskine5d996822020-03-28 21:09:21 +01005698 if [ $KEEP_GOING -ne 0 ]; then
5699 echo "Expect three failing commands."
5700 fi
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005701 # If the component doesn't run in a subshell, changing error_test_i to an
5702 # invalid integer will cause an error in the loop that runs this function.
5703 error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
Gilles Peskineec135542021-08-02 23:14:03 +02005704 # Expected error: 'grep non_existent /dev/null -> 1'
Gilles Peskine5d996822020-03-28 21:09:21 +01005705 grep non_existent /dev/null
Gilles Peskineec135542021-08-02 23:14:03 +02005706 # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
Gilles Peskine5d996822020-03-28 21:09:21 +01005707 not grep -q . "$0"
Gilles Peskineec135542021-08-02 23:14:03 +02005708 # Expected error: 'make unknown_target -> 2'
Gilles Peskine5d996822020-03-28 21:09:21 +01005709 make unknown_target
5710 false "this should not be executed"
5711}
5712
Gilles Peskinee48351a2018-11-27 16:06:30 +01005713# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01005714run_component () {
Gilles Peskineffcdeff2018-12-04 12:49:28 +01005715 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02005716 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005717
5718 # Unconditionally create a seedfile that's sufficiently long.
5719 # Do this before each component, because a previous component may
5720 # have messed it up or shortened it.
Gilles Peskine88a07452021-07-08 19:03:50 +02005721 local dd_cmd
5722 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
5723 case $OSTYPE in
Tom Cosgrove226aca12022-03-16 14:11:07 +00005724 linux*|freebsd*|openbsd*) dd_cmd+=(status=none)
Gilles Peskine88a07452021-07-08 19:03:50 +02005725 esac
5726 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005727
Gilles Peskineec135542021-08-02 23:14:03 +02005728 # Run the component in a subshell, with error trapping and output
5729 # redirection set up based on the relevant options.
Gilles Peskinece266c42020-03-28 18:50:43 +01005730 if [ $KEEP_GOING -eq 1 ]; then
Gilles Peskineec135542021-08-02 23:14:03 +02005731 # We want to keep running if the subshell fails, so 'set -e' must
5732 # be off when the subshell runs.
Gilles Peskinece266c42020-03-28 18:50:43 +01005733 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02005734 fi
Gilles Peskinece266c42020-03-28 18:50:43 +01005735 (
5736 if [ $QUIET -eq 1 ]; then
5737 # msg() will be silenced, so just print the component name here.
5738 echo "${current_component#component_}"
5739 exec >/dev/null
5740 fi
5741 if [ $KEEP_GOING -eq 1 ]; then
5742 # Keep "set -e" off, and run an ERR trap instead to record failures.
5743 set -E
5744 trap err_trap ERR
5745 fi
5746 # The next line is what runs the component
5747 "$@"
5748 if [ $KEEP_GOING -eq 1 ]; then
5749 trap - ERR
5750 exit $last_failure_status
5751 fi
5752 )
5753 component_status=$?
5754 if [ $KEEP_GOING -eq 1 ]; then
5755 set -e
5756 if [ $component_status -ne 0 ]; then
5757 failure_count=$((failure_count + 1))
5758 fi
5759 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005760
5761 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01005762 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02005763 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01005764}
5765
5766# Preliminary setup
5767pre_check_environment
Tom Cosgrove730addc2023-06-09 14:20:18 +01005768pre_parse_command_line_for_dirs "$@"
Gilles Peskine8f073122018-11-27 15:58:47 +01005769pre_initialize_variables
5770pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01005771
Gilles Peskine878cf602019-01-06 20:50:38 +00005772pre_check_git
Gilles Peskine568f53a2021-07-12 18:16:01 +02005773pre_restore_files
Gilles Peskinef83eb822020-03-30 20:11:39 +02005774pre_back_up
Andrzej Kurekeb508712019-02-14 07:18:59 -05005775
Gilles Peskine878cf602019-01-06 20:50:38 +00005776build_status=0
5777if [ $KEEP_GOING -eq 1 ]; then
5778 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01005779fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02005780pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00005781pre_print_configuration
5782pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005783cleanup
David Horstmann76a77382023-08-17 17:32:26 +01005784if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +01005785 pre_generate_files
5786fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005787
Gilles Peskinebeb3a812019-01-06 22:11:25 +00005788# Run the requested tests.
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005789for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
Gilles Peskine5d996822020-03-28 21:09:21 +01005790 run_component pseudo_component_error_test
Gilles Peskine5d996822020-03-28 21:09:21 +01005791done
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005792unset error_test_i
Gilles Peskinebeb3a812019-01-06 22:11:25 +00005793for component in $RUN_COMPONENTS; do
5794 run_component "component_$component"
5795done
Gilles Peskine8f073122018-11-27 15:58:47 +01005796
5797# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00005798post_report