blob: 33bad3987437698c7919f83bc11d375028c30ff2 [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 () {
127 test ! -d core
David Horstmann9a6c45b2023-07-14 12:30:00 +0100128}
129
Gilles Peskine8f073122018-11-27 15:58:47 +0100130pre_check_environment () {
David Horstmann9a6c45b2023-07-14 12:30:00 +0100131 if [ \( -d library -o -d core \) -a -d include -a -d tests ]; then :; else
132 echo "Must be run from Mbed TLS root" >&2
Gilles Peskine8f073122018-11-27 15:58:47 +0100133 exit 1
134 fi
135}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100136
Gilles Peskine8f073122018-11-27 15:58:47 +0100137pre_initialize_variables () {
David Horstmann76a77382023-08-17 17:32:26 +0100138 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100139 CONFIG_H='include/mbedtls/mbedtls_config.h'
David Horstmann76a77382023-08-17 17:32:26 +0100140 else
141 CONFIG_H='drivers/builtin/include/mbedtls/mbedtls_config.h'
David Horstmann9a6c45b2023-07-14 12:30:00 +0100142 fi
John Durkopbd069d32020-10-31 22:14:03 -0700143 CRYPTO_CONFIG_H='include/psa/crypto_config.h'
Manuel Pégourié-Gonnard462e3a92022-12-27 12:35:11 +0100144 CONFIG_TEST_DRIVER_H='tests/include/test/drivers/config_test_driver.h'
Gilles Peskinef83eb822020-03-30 20:11:39 +0200145
146 # Files that are clobbered by some jobs will be backed up. Use a different
147 # suffix from auxiliary scripts so that all.sh and auxiliary scripts can
148 # independently decide when to remove the backup file.
149 backup_suffix='.all.bak'
150 # Files clobbered by config.py
Janos Follath2f045822023-07-31 10:57:16 +0100151 files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H $CONFIG_TEST_DRIVER_H"
David Horstmann76a77382023-08-17 17:32:26 +0100152 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100153 # Files clobbered by in-tree cmake
154 files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile"
155 fi
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200156
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200157 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100158 MEMORY=0
159 FORCE=0
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200160 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100161 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100162
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200163 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard54304472020-06-22 10:11:47 +0200164 #
165 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
166 # both values are kept in sync. If you change the value here because it
167 # breaks some tests, you'll definitely want to change it in
168 # basic-build-test.sh as well.
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200169 RELEASE_SEED=1
170
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200171 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200172 : ${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 +0200173 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200174 export MBEDTLS_TEST_PLATFORM
175
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000176 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100177 : ${OPENSSL:="openssl"}
178 : ${OPENSSL_LEGACY:="$OPENSSL"}
179 : ${OPENSSL_NEXT:="$OPENSSL"}
180 : ${GNUTLS_CLI:="gnutls-cli"}
181 : ${GNUTLS_SERV:="gnutls-serv"}
182 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
183 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
184 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
185 : ${ARMC5_BIN_DIR:=/usr/bin}
186 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskine6d061342020-04-30 18:19:32 +0200187 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +0200188 : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
Gowtham Suresh Kumar9da40b82023-07-31 16:38:10 +0100189 : ${CLANG_LATEST:="clang-latest"}
190 : ${CLANG_EARLIEST:="clang-earliest"}
191 : ${GCC_LATEST:="gcc-latest"}
192 : ${GCC_EARLIEST:="gcc-earliest"}
Gilles Peskine8f073122018-11-27 15:58:47 +0100193 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000194 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine050d2fc2021-09-30 18:24:21 +0200195 export MAKEFLAGS="-j$(all_sh_nproc)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100196 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000197
Gilles Peskine396853a2021-09-20 18:57:55 +0200198 # Include more verbose output for failing tests run by CMake or make
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000199 export CTEST_OUTPUT_ON_FAILURE=1
200
Gilles Peskine8fd59422019-10-21 17:11:33 +0200201 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Manuel Pégourié-Gonnardfe549a72022-11-30 10:42:03 +0100202 # default to -O2, use -Ox _after_ this if you want another level
Przemek Stekiel6efa6082023-05-31 09:38:21 +0200203 ASAN_CFLAGS='-O2 -Werror -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200204
Andrzej Kurek04bfe572023-06-27 10:02:09 -0400205 # Platform tests have an allocation that returns null
206 export ASAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurek026235c2023-07-05 08:32:43 -0400207 export MSAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurek04bfe572023-06-27 10:02:09 -0400208
Gilles Peskine878cf602019-01-06 20:50:38 +0000209 # Gather the list of available components. These are the functions
210 # defined in this script whose name starts with "component_".
Gowtham Suresh Kumar1e829a42023-07-28 16:41:21 +0100211 ALL_COMPONENTS=$(compgen -A function component_ | sed 's/component_//')
Gilles Peskine878cf602019-01-06 20:50:38 +0000212
213 # Exclude components that are not supported on this platform.
214 SUPPORTED_COMPONENTS=
215 for component in $ALL_COMPONENTS; do
216 case $(type "support_$component" 2>&1) in
217 *' function'*)
218 if ! support_$component; then continue; fi;;
219 esac
220 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
221 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100222}
Andres AG38495a32016-07-12 16:54:33 +0100223
Gilles Peskinea28db922019-01-10 00:05:18 +0100224# Test whether the component $1 is included in the command line patterns.
225is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100226{
Gilles Peskine03af6782021-08-06 11:35:17 +0200227 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
228 # only does word splitting.
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100229 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000230 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100231 set +f
232 case ${1#component_} in $pattern) return 0;; esac
233 done
234 set +f
235 return 1
236}
Andres AG7770ea82016-10-10 15:46:20 +0100237
Simon Butcher41eeccf2016-09-07 00:07:09 +0100238usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100239{
Gilles Peskine709346a2017-12-10 23:43:39 +0100240 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100241Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100242Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100243By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100244COMPONENT can be the name of a component or a shell wildcard pattern.
245
246Examples:
247 $0 "check_*"
248 Run all sanity checks.
249 $0 --no-armcc --except test_memsan
250 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100251
252Special options:
253 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000254 --list-all-components List all available test components and exit.
255 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100256
257General options:
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200258 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100259 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100260 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100261 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200262 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200263 --arm-none-eabi-gcc-prefix=<string>
264 Prefix for a cross-compiler for arm-none-eabi
265 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +0200266 --arm-linux-gnueabi-gcc-prefix=<string>
267 Prefix for a cross-compiler for arm-linux-gnueabi
268 (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100269 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine80ddb992021-08-06 11:51:59 +0200270 --restore First clean up the build tree, restoring backed up
271 files. Do not run any components unless they are
272 explicitly specified.
Gilles Peskine5d996822020-03-28 21:09:21 +0100273 --error-test Error test mode: run a failing function in addition
Gilles Peskine86f61292021-08-05 15:11:33 +0200274 to any specified component. May be repeated.
Gilles Peskinea28db922019-01-10 00:05:18 +0100275 --except Exclude the COMPONENTs listed on the command line,
276 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200277 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100278 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100279 --no-force Refuse to overwrite modified files (default).
280 --no-keep-going Stop at the first error (default).
281 --no-memory No additional memory tests (default).
Shaun Case8b0ecbc2021-12-20 21:14:10 -0800282 --no-quiet Print full output from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100283 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200284 --outcome-file=<path> File where test outcomes are written (not done if
285 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100286 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200287 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100288 -s|--seed Integer seed value to use for this test run.
289
290Tool path options:
291 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
292 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +0100293 --clang-earliest=<Clang_earliest_path> Earliest version of clang available
294 --clang-latest=<Clang_latest_path> Latest version of clang available
295 --gcc-earliest=<GCC_earliest_path> Earliest version of GCC available
296 --gcc-latest=<GCC_latest_path> Latest version of GCC available
Gilles Peskine709346a2017-12-10 23:43:39 +0100297 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
298 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
299 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
300 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
301 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
Mateusz Starzyk06b07fb2021-02-18 13:55:21 +0100302 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests..
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100303 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100304EOF
SimonB2e23c822016-04-16 21:54:39 +0100305}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100306
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200307# Cleanup before/after running a component.
308# Remove built files as well as the cmake cache/config.
309# Does not remove generated source files.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100310cleanup()
311{
David Horstmann76a77382023-08-17 17:32:26 +0100312 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100313 command make clean
314 fi
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200315
Gilles Peskine31b07e22018-03-21 12:15:06 +0100316 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000317 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100318 -iname CMakeFiles -exec rm -rf {} \+ -o \
319 \( -iname cmake_install.cmake -o \
320 -iname CTestTestfile.cmake -o \
Manuel Pégourié-Gonnardbfe54d72021-09-09 11:11:44 +0200321 -iname CMakeCache.txt -o \
322 -path './cmake/*.cmake' \) -exec rm -f {} \+
Gilles Peskine31b07e22018-03-21 12:15:06 +0100323 # Recover files overwritten by in-tree CMake builds
Gilles Peskine076f7252022-08-30 21:02:44 +0200324 rm -f include/Makefile include/mbedtls/Makefile programs/!(fuzz)/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200325
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100326 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
327 rm -rf programs/test/cmake_subproject/build
328 rm -f programs/test/cmake_subproject/Makefile
329 rm -f programs/test/cmake_subproject/cmake_subproject
330
Chris Kayd259e342021-03-25 16:03:25 +0000331 # Remove any artifacts from the component_test_cmake_as_package test.
332 rm -rf programs/test/cmake_package/build
333 rm -f programs/test/cmake_package/Makefile
334 rm -f programs/test/cmake_package/cmake_package
335
336 # Remove any artifacts from the component_test_cmake_as_installed_package test.
337 rm -rf programs/test/cmake_package_install/build
338 rm -f programs/test/cmake_package_install/Makefile
339 rm -f programs/test/cmake_package_install/cmake_package_install
340
Gilles Peskinef83eb822020-03-30 20:11:39 +0200341 # Restore files that may have been clobbered by the job
342 for x in $files_to_back_up; do
Gilles Peskinedd06efb2022-08-30 21:02:00 +0200343 if [[ -e "$x$backup_suffix" ]]; then
344 cp -p "$x$backup_suffix" "$x"
345 fi
Gilles Peskinef83eb822020-03-30 20:11:39 +0200346 done
347}
John Durkopbd069d32020-10-31 22:14:03 -0700348
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200349# Final cleanup when this script exits (except when exiting on a failure
350# in non-keep-going mode).
Gilles Peskinef83eb822020-03-30 20:11:39 +0200351final_cleanup () {
352 cleanup
353
354 for x in $files_to_back_up; do
355 rm -f "$x$backup_suffix"
356 done
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100357}
358
Gilles Peskine7c652162017-12-11 00:01:40 +0100359# Executed on exit. May be redefined depending on command line options.
360final_report () {
361 :
362}
363
364fatal_signal () {
Gilles Peskinef83eb822020-03-30 20:11:39 +0200365 final_cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100366 final_report $1
367 trap - $1
368 kill -$1 $$
369}
370
371trap 'fatal_signal HUP' HUP
372trap 'fatal_signal INT' INT
373trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200374
Gilles Peskine050d2fc2021-09-30 18:24:21 +0200375# Number of processors on this machine. Used as the default setting
376# for parallel make.
377all_sh_nproc ()
378{
379 {
380 nproc || # Linux
381 sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
382 sysctl -n hw.ncpu || # FreeBSD
383 echo 1
384 } 2>/dev/null
385}
386
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100387msg()
388{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100389 if [ -n "${current_component:-}" ]; then
390 current_section="${current_component#component_}: $1"
391 else
392 current_section="$1"
393 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200394
395 if [ $QUIET -eq 1 ]; then
396 return
397 fi
398
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100399 echo ""
400 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100401 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000402 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100403 echo "******************************************************************"
404}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100405
Gilles Peskine8f073122018-11-27 15:58:47 +0100406armc6_build_test()
407{
408 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100409
Gilles Peskine18487f62020-04-30 23:11:54 +0200410 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100411 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
Dave Rodgman1c232a82023-03-02 13:39:04 +0000412 WARNING_CFLAGS='-Werror -xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200413
414 msg "size: ARM Compiler 6 ($FLAGS)"
415 "$ARMC6_FROMELF" -z library/*.o
416
Gilles Peskine8f073122018-11-27 15:58:47 +0100417 make clean
418}
Andres AGa5cd9732016-10-17 15:23:10 +0100419
Andres AGd9eba4b2016-08-26 14:42:14 +0100420err_msg()
421{
422 echo "$1" >&2
423}
424
425check_tools()
426{
427 for TOOL in "$@"; do
Andres AG98393602017-01-31 17:04:45 +0000428 if ! `type "$TOOL" >/dev/null 2>&1`; then
Andres AGd9eba4b2016-08-26 14:42:14 +0100429 err_msg "$TOOL not found!"
430 exit 1
431 fi
432 done
433}
434
Tom Cosgrove730addc2023-06-09 14:20:18 +0100435pre_parse_command_line_for_dirs () {
436 # Make an early pass through the options given, so we can set directories
437 # for Arm compilers, before SUPPORTED_COMPONENTS is determined.
438 while [ $# -gt 0 ]; do
439 case "$1" in
440 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
441 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
442 esac
443 shift
444 done
445}
446
Gilles Peskine8f073122018-11-27 15:58:47 +0100447pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000448 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100449 all_except=0
Gilles Peskine5d996822020-03-28 21:09:21 +0100450 error_test=0
Gilles Peskine80ddb992021-08-06 11:51:59 +0200451 restore_first=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000452 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100453
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000454 # Note that legacy options are ignored instead of being omitted from this
455 # list of options, so invocations that worked with previous version of
456 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100457 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100458 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200459 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200460 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +0200461 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000462 --armcc) no_armcc=;;
Tom Cosgrove730addc2023-06-09 14:20:18 +0100463 --armc5-bin-dir) shift; ;; # assignment to ARMC5_BIN_DIR done in pre_parse_command_line_for_dirs
464 --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 +0100465 --clang-earliest) shift; CLANG_EARLIEST="$1";;
466 --clang-latest) shift; CLANG_LATEST="$1";;
Gilles Peskine5d996822020-03-28 21:09:21 +0100467 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000468 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100469 --force|-f) FORCE=1;;
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +0100470 --gcc-earliest) shift; GCC_EARLIEST="$1";;
471 --gcc-latest) shift; GCC_LATEST="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100472 --gnutls-cli) shift; GNUTLS_CLI="$1";;
473 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
474 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
475 --gnutls-serv) shift; GNUTLS_SERV="$1";;
476 --help|-h) usage; exit;;
477 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000478 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
479 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100480 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200481 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000482 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100483 --no-force) FORCE=0;;
484 --no-keep-going) KEEP_GOING=0;;
485 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200486 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100487 --openssl) shift; OPENSSL="$1";;
488 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
489 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200490 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100491 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200492 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100493 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200494 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine80ddb992021-08-06 11:51:59 +0200495 --restore) restore_first=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100496 --seed|-s) shift; SEED="$1";;
497 -*)
498 echo >&2 "Unknown option: $1"
499 echo >&2 "Run $0 --help for usage."
500 exit 120
501 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000502 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100503 esac
504 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100505 done
SimonB2e23c822016-04-16 21:54:39 +0100506
Gilles Peskinea28db922019-01-10 00:05:18 +0100507 # With no list of components, run everything.
Gilles Peskine80ddb992021-08-06 11:51:59 +0200508 if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000509 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100510 fi
511
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000512 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
513 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100514 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000515 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100516 fi
SimonB2e23c822016-04-16 21:54:39 +0100517
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200518 # Error out if an explicitly requested component doesn't exist.
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100519 if [ $all_except -eq 0 ]; then
520 unsupported=0
Gilles Peskine03af6782021-08-06 11:35:17 +0200521 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
522 # only does word splitting.
Gilles Peskine1d475b62021-08-03 13:43:36 +0200523 set -f
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100524 for component in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine1d475b62021-08-03 13:43:36 +0200525 set +f
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200526 # If the requested name includes a wildcard character, don't
527 # check it. Accept wildcard patterns that don't match anything.
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100528 case $component in
529 *[*?\[]*) continue;;
530 esac
531 case " $SUPPORTED_COMPONENTS " in
532 *" $component "*) :;;
533 *)
534 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
535 unsupported=$((unsupported + 1));;
536 esac
537 done
Gilles Peskine1d475b62021-08-03 13:43:36 +0200538 set +f
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100539 if [ $unsupported -ne 0 ]; then
540 exit 2
541 fi
542 fi
543
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000544 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100545 RUN_COMPONENTS=
546 for component in $SUPPORTED_COMPONENTS; do
547 if is_component_included "$component"; [ $? -eq $all_except ]; then
548 RUN_COMPONENTS="$RUN_COMPONENTS $component"
549 fi
550 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000551
552 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000553 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100554}
SimonB2e23c822016-04-16 21:54:39 +0100555
Gilles Peskine8f073122018-11-27 15:58:47 +0100556pre_check_git () {
557 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100558 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100559 git checkout-index -f -q $CONFIG_H
560 cleanup
561 else
SimonB2e23c822016-04-16 21:54:39 +0100562
Gilles Peskine8f073122018-11-27 15:58:47 +0100563 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
564 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
565 echo "You can either delete this directory manually, or force the test by rerunning"
566 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
567 exit 1
568 fi
569
Ronald Cron7a93ac52023-07-20 09:49:12 +0200570 if ! git diff --quiet "$CONFIG_H"; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100571 err_msg "Warning - the configuration file '$CONFIG_H' has been edited. "
Gilles Peskine8f073122018-11-27 15:58:47 +0100572 echo "You can either delete or preserve your work, or force the test by rerunning the"
573 echo "script as: $0 --force"
574 exit 1
575 fi
SimonB2e23c822016-04-16 21:54:39 +0100576 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500577}
578
Gilles Peskine568f53a2021-07-12 18:16:01 +0200579pre_restore_files () {
580 # If the makefiles have been generated by a framework such as cmake,
581 # restore them from git. If the makefiles look like modifications from
582 # the ones checked into git, take care not to modify them. Whatever
583 # this function leaves behind is what the script will restore before
584 # each component.
585 case "$(head -n1 Makefile)" in
586 *[Gg]enerated*)
587 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
588 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
589 ;;
590 esac
591}
592
Gilles Peskinef83eb822020-03-30 20:11:39 +0200593pre_back_up () {
594 for x in $files_to_back_up; do
595 cp -p "$x" "$x$backup_suffix"
596 done
597}
598
Gilles Peskine8f073122018-11-27 15:58:47 +0100599pre_setup_keep_going () {
Gilles Peskinece266c42020-03-28 18:50:43 +0100600 failure_count=0 # Number of failed components
601 last_failure_status=0 # Last failure status in this component
602
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100603 # See err_trap
604 previous_failure_status=0
605 previous_failed_command=
606 previous_failure_funcall_depth=0
Gilles Peskinea681c592020-03-28 21:27:40 +0100607 unset report_failed_command
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100608
Gilles Peskine7c652162017-12-11 00:01:40 +0100609 start_red=
610 end_color=
611 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100612 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100613 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
614 start_red=$(printf '\033[31m')
615 end_color=$(printf '\033[0m')
616 ;;
617 esac
618 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100619
620 # Keep a summary of failures in a file. We'll print it out at the end.
621 failure_summary_file=$PWD/all-sh-failures-$$.log
622 : >"$failure_summary_file"
623
624 # Whether it makes sense to keep a component going after the specified
625 # command fails (test command) or not (configure or build).
Gilles Peskine03af6782021-08-06 11:35:17 +0200626 # This function normally receives the failing simple command
627 # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
628 # this is passed instead.
Gilles Peskinece266c42020-03-28 18:50:43 +0100629 # This doesn't have to be 100% accurate: all failures are recorded anyway.
Gilles Peskinec111e242021-08-02 23:29:53 +0200630 # False positives result in running things that can't be expected to
631 # work. False negatives result in things not running after something else
632 # failed even though they might have given useful feedback.
Gilles Peskinece266c42020-03-28 18:50:43 +0100633 can_keep_going_after_failure () {
634 case "$1" in
635 "msg "*) false;;
Gilles Peskinec111e242021-08-02 23:29:53 +0200636 "cd "*) false;;
637 *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
638 *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
639 *make*check*) true;;
640 "grep "*) true;;
641 "[ "*) true;;
642 "! "*) true;;
Gilles Peskinece266c42020-03-28 18:50:43 +0100643 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100644 esac
645 }
Gilles Peskinece266c42020-03-28 18:50:43 +0100646
647 # This function runs if there is any error in a component.
648 # It must either exit with a nonzero status, or set
649 # last_failure_status to a nonzero value.
650 err_trap () {
651 # Save $? (status of the failing command). This must be the very
652 # first thing, before $? is overridden.
653 last_failure_status=$?
Gilles Peskinea681c592020-03-28 21:27:40 +0100654 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskinece266c42020-03-28 18:50:43 +0100655
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100656 if [[ $last_failure_status -eq $previous_failure_status &&
657 "$failed_command" == "$previous_failed_command" &&
658 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
659 then
660 # The same command failed twice in a row, but this time one level
661 # less deep in the function call stack. This happens when the last
662 # command of a function returns a nonzero status, and the function
663 # returns that same status. Ignore the second failure.
664 previous_failure_funcall_depth=${#FUNCNAME[@]}
665 return
666 fi
667 previous_failure_status=$last_failure_status
668 previous_failed_command=$failed_command
669 previous_failure_funcall_depth=${#FUNCNAME[@]}
670
Gilles Peskinece266c42020-03-28 18:50:43 +0100671 text="$current_section: $failed_command -> $last_failure_status"
672 echo "${start_red}^^^^$text^^^^${end_color}" >&2
673 echo "$text" >>"$failure_summary_file"
674
675 # If the command is fatal (configure or build command), stop this
676 # component. Otherwise (test command) keep the component running
677 # (run more tests from the same build).
678 if ! can_keep_going_after_failure "$failed_command"; then
679 exit $last_failure_status
680 fi
681 }
682
Gilles Peskine7c652162017-12-11 00:01:40 +0100683 final_report () {
684 if [ $failure_count -gt 0 ]; then
685 echo
686 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskinece266c42020-03-28 18:50:43 +0100687 echo "${start_red}FAILED: $failure_count components${end_color}"
688 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100689 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
690 elif [ -z "${1-}" ]; then
691 echo "SUCCESS :)"
692 fi
693 if [ -n "${1-}" ]; then
694 echo "Killed by SIG$1."
695 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100696 rm -f "$failure_summary_file"
697 if [ $failure_count -gt 0 ]; then
698 exit 1
699 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100700 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100701}
702
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200703# record_status() and if_build_succeeded() are kept temporarily for backward
704# compatibility. Don't use them in new components.
Gilles Peskinece266c42020-03-28 18:50:43 +0100705record_status () {
706 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100707}
Gilles Peskine7c652162017-12-11 00:01:40 +0100708if_build_succeeded () {
Gilles Peskinece266c42020-03-28 18:50:43 +0100709 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100710}
711
Gilles Peskinea681c592020-03-28 21:27:40 +0100712# '! true' does not trigger the ERR trap. Arrange to trigger it, with
713# a reasonably informative error message (not just "$@").
714not () {
715 if "$@"; then
716 report_failed_command="! $*"
717 false
718 unset report_failed_command
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200719 fi
720}
721
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200722pre_prepare_outcome_file () {
723 case "$MBEDTLS_TEST_OUTCOME_FILE" in
724 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
725 esac
726 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
727 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
728 fi
729}
730
Gilles Peskine8f073122018-11-27 15:58:47 +0100731pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200732 if [ $QUIET -eq 1 ]; then
733 return
734 fi
735
Gilles Peskine8f073122018-11-27 15:58:47 +0100736 msg "info: $0 configuration"
737 echo "MEMORY: $MEMORY"
738 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200739 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100740 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100741 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100742 echo "OPENSSL: $OPENSSL"
743 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
744 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
745 echo "GNUTLS_CLI: $GNUTLS_CLI"
746 echo "GNUTLS_SERV: $GNUTLS_SERV"
747 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
748 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
749 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
750 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
751}
Andres AG7770ea82016-10-10 15:46:20 +0100752
Andres AGd9eba4b2016-08-26 14:42:14 +0100753# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100754pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000755 # Build the list of variables to pass to output_env.sh.
756 set env
SimonB2e23c822016-04-16 21:54:39 +0100757
Gilles Peskine87964262019-01-06 22:40:00 +0000758 case " $RUN_COMPONENTS " in
759 # Require OpenSSL and GnuTLS if running any tests (as opposed to
760 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
761 # is a good enough approximation in practice.
762 *" test_"*)
763 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
764 # and ssl-opt.sh, we just export the variables they require.
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +0100765 export OPENSSL="$OPENSSL"
Gilles Peskine87964262019-01-06 22:40:00 +0000766 export GNUTLS_CLI="$GNUTLS_CLI"
767 export GNUTLS_SERV="$GNUTLS_SERV"
768 # Avoid passing --seed flag in every call to ssl-opt.sh
769 if [ -n "${SEED-}" ]; then
770 export SEED
771 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000772 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
773 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
774 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
775 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000776 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
777 "$GNUTLS_CLI" "$GNUTLS_SERV" \
778 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
779 ;;
780 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200781
Gilles Peskine87964262019-01-06 22:40:00 +0000782 case " $RUN_COMPONENTS " in
783 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
784 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100785
Gilles Peskine87964262019-01-06 22:40:00 +0000786 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200787 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000788 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100789
Gilles Peskine87964262019-01-06 22:40:00 +0000790 case " $RUN_COMPONENTS " in
791 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
792 esac
793
794 case " $RUN_COMPONENTS " in
795 *" test_zeroize "*) check_tools "gdb";;
796 esac
797
798 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000799 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000800 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
801 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200802 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000803 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
804 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200805 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
806 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
807 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000808 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000809
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200810 # past this point, no call to check_tool, only printing output
811 if [ $QUIET -eq 1 ]; then
812 return
813 fi
814
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000815 msg "info: output_env.sh"
816 case $RUN_COMPONENTS in
817 *_armcc*)
818 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
819 *) set "$@" RUN_ARMCC=0;;
820 esac
821 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100822}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100823
Gilles Peskine1570b592021-04-22 01:10:12 +0200824pre_generate_files() {
Manuel Pégourié-Gonnard87db8a22021-06-18 13:30:14 +0200825 # since make doesn't have proper dependencies, remove any possibly outdate
826 # file that might be around before generating fresh ones
827 make neat
Gilles Peskine72385032021-07-08 19:07:07 +0200828 if [ $QUIET -eq 1 ]; then
Gilles Peskine75301632021-08-05 15:10:47 +0200829 make generated_files >/dev/null
Gilles Peskine72385032021-07-08 19:07:07 +0200830 else
831 make generated_files
832 fi
Gilles Peskine1570b592021-04-22 01:10:12 +0200833}
834
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200835################################################################
836#### Helpers for components using libtestdriver1
837################################################################
Gilles Peskine192c72f2017-12-21 15:59:21 +0100838
Manuel Pégourié-Gonnardf5c5d972023-06-06 11:14:57 +0200839# How to use libtestdriver1
840# -------------------------
841#
842# 1. Define the list algorithms and key types to accelerate,
843# designated the same way as PSA_WANT_ macros but without PSA_WANT_.
844# Examples:
845# - loc_accel_list="ALG_JPAKE"
846# - loc_accel_list="ALG_FFDH KEY_TYPE_DH_KEY_PAIR KEY_TYPE_DH_PUBLIC_KEY"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200847# 2. Make configurations changes for the driver and/or main libraries.
848# 2a. Call helper_libtestdriver1_adjust_config <base>, where the argument
849# can be either "default" to start with the default config, or a name
850# supported by scripts/config.py (for example, "full"). This selects
Manuel Pégourié-Gonnard2336c8e2023-06-12 17:17:54 +0200851# the base to use, and makes common adjustments.
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200852# 2b. If desired, adjust the PSA_WANT symbols in psa/crypto_config.h.
853# These changes affect both the driver and the main libraries.
854# (Note: they need to have the same set of PSA_WANT symbols, as that
855# determines the ABI between them.)
856# 2c. Adjust MBEDTLS_ symbols in mbedtls_config.h. This only affects the
857# main libraries. Typically, you want to disable the module(s) that are
858# being accelerated. You may need to also disable modules that depend
859# on them or options that are not supported with drivers.
860# 2d. On top of psa/crypto_config.h, the driver library uses its own config
861# file: tests/include/test/drivers/config_test_driver.h. You usually
862# don't need to edit it: using loc_extra_list (see below) is preferred.
863# However, when there's no PSA symbol for what you want to enable,
864# calling scripts/config.py on this file remains the only option.
865# 3. Build the driver library, then the main libraries, test, and programs.
866# 3a. Call helper_libtestdriver1_make_drivers "$loc_accel_list". You may
867# need to enable more algorithms here, typically hash algorithms when
868# accelerating some signature algorithms (ECDSA, RSAv2). This is done
869# by passing a 2nd argument listing the extra algorithms.
870# Example:
871# loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
872# helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
873# 4b. Call helper_libtestdriver1_make_main "$loc_accel_list". Any
874# additional arguments will be passed to make: this can be useful if
875# you don't want to build everything when iterating during development.
876# Example:
877# helper_libtestdriver1_make_main "$loc_accel_list" -C tests test_suite_foo
878# 4. Run the tests you want.
Manuel Pégourié-Gonnardf5c5d972023-06-06 11:14:57 +0200879
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200880# Adjust the configuration - for both libtestdriver1 and main library,
881# as they should have the same PSA_WANT macros.
882helper_libtestdriver1_adjust_config() {
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200883 BASE_CONFIG=$1
884 # Select the base configuration
885 if [ "$BASE_CONFIG" != "default" ]; then
886 scripts/config.py "$BASE_CONFIG"
887 fi
888
889 # Enable PSA-based config (necessary to use drivers)
890 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
891
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200892 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
893 # partial support for cipher operations in the driver test library.
Ronald Cron6b49b552023-07-20 09:57:54 +0200894 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_STREAM_CIPHER
895 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
Manuel Pégourié-Gonnard2336c8e2023-06-12 17:17:54 +0200896
897 # Dynamic secure element support is a deprecated feature and needs to be disabled here.
898 # This is done to have the same form of psa_key_attributes_s for libdriver and library.
899 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200900}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100901
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +0200902# Build the drivers library libtestdriver1.a (with ASan).
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +0200903#
904# Parameters:
905# 1. a space-separated list of things to accelerate;
906# 2. optional: a space-separate list of things to also support.
907# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
908helper_libtestdriver1_make_drivers() {
909 loc_accel_flags=$( echo "$1 ${2-}" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
910 make -C tests libtestdriver1.a CFLAGS=" $ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
911}
912
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +0200913# Build the main libraries, programs and tests,
914# linking to the drivers library (with ASan).
915#
916# Parameters:
917# 1. a space-separated list of things to accelerate;
918# *. remaining arguments if any are passed directly to make
919# (examples: lib, -C tests test_suite_xxx, etc.)
920# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
921helper_libtestdriver1_make_main() {
922 loc_accel_list=$1
923 shift
924
925 # we need flags both with and without the LIBTESTDRIVER1_ prefix
926 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
927 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
928 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" "$@"
929}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100930
931################################################################
932#### Basic checks
933################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100934
935#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200936# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100937#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100938# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200939# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100940# 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 +0200941# time, so start with a GCC build).
942# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100943#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100944# Indicative running times are given for reference.
945
Gilles Peskine8f073122018-11-27 15:58:47 +0100946component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200947 msg "Check: recursion.pl" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200948 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100949}
Janos Follathb72c6782016-07-19 14:54:17 +0100950
Gilles Peskine67debb62021-05-18 16:09:50 +0200951component_check_generated_files () {
952 msg "Check: check-generated-files, files generated with make" # 2s
953 make generated_files
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200954 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200955
956 msg "Check: check-generated-files -u, files present" # 2s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200957 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +0200958 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200959 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200960
961 msg "Check: check-generated-files -u, files absent" # 2s
962 command make neat
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200963 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +0200964 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200965 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200966
967 # This component ends with the generated files present in the source tree.
968 # This is necessary for subsequent components!
969}
970
Gilles Peskine8f073122018-11-27 15:58:47 +0100971component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200972 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200973 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +0100974}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200975
Gilles Peskine8f073122018-11-27 15:58:47 +0100976component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200977 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200978 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +0100979}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200980
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200981component_check_changelog () {
982 msg "Check: changelog entries" # < 1s
983 rm -f ChangeLog.new
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200984 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +0200985 if [ -e ChangeLog.new ]; then
986 # Show the diff for information. It isn't an error if the diff is
987 # non-empty.
988 diff -u ChangeLog ChangeLog.new || true
989 rm ChangeLog.new
990 fi
991}
992
Gilles Peskine8f073122018-11-27 15:58:47 +0100993component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200994 msg "Check: declared and exported names (builds the library)" # < 3s
Yuto Takanoc3a6f632021-09-24 18:02:56 +0100995 tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +0100996}
Darryl Greena07039c2018-03-13 16:48:16 +0000997
Gilles Peskine895868b2019-09-19 21:30:05 +0200998component_check_test_cases () {
999 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001000 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001001 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001002 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001003 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001004 fi
Gilles Peskine031114d2022-12-15 14:46:31 +01001005 tests/scripts/check_test_cases.py -q $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001006 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +02001007}
1008
Gilles Peskine8f073122018-11-27 15:58:47 +01001009component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001010 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001011 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001012}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001013
Gilles Peskine192c72f2017-12-21 15:59:21 +01001014
Gilles Peskine636c26a2020-03-04 20:46:15 +01001015
Gilles Peskine192c72f2017-12-21 15:59:21 +01001016################################################################
1017#### Build and test many configurations and targets
1018################################################################
1019
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001020component_test_default_out_of_box () {
1021 msg "build: make, default config (out-of-box)" # ~1min
1022 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02001023 # Disable fancy stuff
1024 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001025
1026 msg "test: main suites make, default config (out-of-box)" # ~10s
1027 make test
1028
1029 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001030 programs/test/selftest
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001031}
1032
Gilles Peskine8f073122018-11-27 15:58:47 +01001033component_test_default_cmake_gcc_asan () {
1034 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +01001035 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1036 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001037
Gilles Peskine8f073122018-11-27 15:58:47 +01001038 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
1039 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001040
Gilles Peskine97bea012020-04-23 23:37:45 +02001041 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001042 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +02001043
Gilles Peskine8f073122018-11-27 15:58:47 +01001044 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001045 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001046
Gilles Peskine8f073122018-11-27 15:58:47 +01001047 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001048 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001049
1050 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001051 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001052}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001053
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001054component_test_default_cmake_gcc_asan_new_bignum () {
1055 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Janos Follath2f045822023-07-31 10:57:16 +01001056 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001057 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Janos Follath82823b22023-07-27 12:25:05 +01001058 make
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001059
1060 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
1061 make test
1062
1063 msg "test: selftest (ASan build)" # ~ 10s
1064 programs/test/selftest
1065
1066 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
1067 tests/ssl-opt.sh
1068
1069 msg "test: compat.sh (ASan build)" # ~ 6 min
1070 tests/compat.sh
1071
1072 msg "test: context-info.sh (ASan build)" # ~ 15 sec
1073 tests/context-info.sh
1074}
1075
Hanno Becker01635512019-02-26 14:27:09 +00001076component_test_full_cmake_gcc_asan () {
1077 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001078 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +00001079 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1080 make
1081
1082 msg "test: main suites (inc. selftests) (full config, ASan build)"
1083 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01001084
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 Peskine636c26a2020-03-04 20:46:15 +01001088 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001089 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001090
1091 msg "test: compat.sh (full config, ASan build)"
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 (full config, ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001095 tests/context-info.sh
Valerio Setti3322f612022-12-30 17:45:05 +01001096
Valerio Setti67419f02023-01-04 16:12:42 +01001097 msg "test: check direct ECP dependencies in TLS and X.509"
Valerio Setti3322f612022-12-30 17:45:05 +01001098 docs/architecture/psa-migration/syms.sh full
1099
Valerio Setti67419f02023-01-04 16:12:42 +01001100 # TODO: replace "mbedtls_ecp_curve" with "mbedtls_ecp" also for
1101 # "full-tls-external" once Issue6839 is completed
valerio0b048642023-04-20 13:28:39 +02001102 not grep mbedtls_ecp_curve full-libmbedtls-external
1103 not grep mbedtls_ecp full-libmbedx509-external
Valerio Setti3322f612022-12-30 17:45:05 +01001104
valerio0b048642023-04-20 13:28:39 +02001105 rm full-libmbedtls-external \
1106 full-libmbedtls-modules \
1107 full-libmbedx509-external \
1108 full-libmbedx509-modules
Gilles Peskine636c26a2020-03-04 20:46:15 +01001109}
1110
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001111
1112component_test_full_cmake_gcc_asan_new_bignum () {
1113 msg "build: full config, cmake, gcc, ASan"
1114 scripts/config.py full
Janos Follath2f045822023-07-31 10:57:16 +01001115 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001116 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Janos Follath82823b22023-07-27 12:25:05 +01001117 make
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001118
1119 msg "test: main suites (inc. selftests) (full config, ASan build)"
1120 make test
1121
1122 msg "test: selftest (ASan build)" # ~ 10s
1123 programs/test/selftest
1124
1125 msg "test: ssl-opt.sh (full config, ASan build)"
1126 tests/ssl-opt.sh
1127
1128 msg "test: compat.sh (full config, ASan build)"
1129 tests/compat.sh
1130
1131 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
1132 tests/context-info.sh
1133
1134 msg "test: check direct ECP dependencies in TLS and X.509"
1135 docs/architecture/psa-migration/syms.sh full
1136
1137 # TODO: replace "mbedtls_ecp_curve" with "mbedtls_ecp" also for
1138 # "full-tls-external" once Issue6839 is completed
1139 not grep mbedtls_ecp_curve full-libmbedtls-external
1140 not grep mbedtls_ecp full-libmbedx509-external
1141
1142 rm full-libmbedtls-external \
1143 full-libmbedtls-modules \
1144 full-libmbedx509-external \
1145 full-libmbedx509-modules
1146}
1147
Gabor Mezei6db60472023-07-05 16:38:42 +02001148component_test_full_cmake_gcc_asan_new_bignum_test_hooks () {
1149 msg "build: full config, cmake, gcc, ASan"
1150 scripts/config.py full
1151 scripts/config.py set MBEDTLS_TEST_HOOKS
Janos Follath2f045822023-07-31 10:57:16 +01001152 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Gabor Mezei6db60472023-07-05 16:38:42 +02001153 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Janos Follath82823b22023-07-27 12:25:05 +01001154 make
Gabor Mezei6db60472023-07-05 16:38:42 +02001155
1156 msg "test: main suites (inc. selftests) (full config, ASan build)"
1157 make test
1158
1159 msg "test: selftest (ASan build)" # ~ 10s
1160 programs/test/selftest
1161}
1162
Ronald Cronc3623db2020-10-29 10:51:32 +01001163component_test_psa_crypto_key_id_encodes_owner () {
Andrzej Kurek03e01462022-01-03 12:53:24 +01001164 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
Ronald Cronc3623db2020-10-29 10:51:32 +01001165 scripts/config.py full
Ronald Cronc3623db2020-10-29 10:51:32 +01001166 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1167 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1168 make
1169
1170 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
1171 make test
1172}
1173
Gilles Peskinea3548672021-06-17 11:37:52 +02001174# check_renamed_symbols HEADER LIB
1175# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
1176# name is LIB.
1177check_renamed_symbols () {
1178 ! nm "$2" | sed 's/.* //' |
1179 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
1180}
1181
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001182component_build_psa_crypto_spm () {
Andrzej Kurek03e01462022-01-03 12:53:24 +01001183 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001184 scripts/config.py full
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001185 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
1186 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1187 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
1188 # We can only compile, not link, since our test and sample programs
1189 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
1190 # is active.
1191 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskinea3548672021-06-17 11:37:52 +02001192
1193 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
1194 # version is not present.
1195 echo "Checking for renamed symbols in the library"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001196 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001197}
1198
Ronald Cron336678b2021-01-28 17:54:24 +01001199component_test_psa_crypto_client () {
1200 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
1201 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1202 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1203 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
Raef Colesb4568c52022-09-28 17:11:42 +01001204 scripts/config.py unset MBEDTLS_LMS_C
1205 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Ronald Cron336678b2021-01-28 17:54:24 +01001206 make
1207
1208 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
1209 make test
1210}
1211
Jaeden Amero424fa932021-05-14 08:34:32 +01001212component_test_psa_crypto_rsa_no_genprime() {
1213 msg "build: default config minus MBEDTLS_GENPRIME"
1214 scripts/config.py unset MBEDTLS_GENPRIME
1215 make
1216
1217 msg "test: default config minus MBEDTLS_GENPRIME"
1218 make test
1219}
1220
Gilles Peskine782f4112018-11-27 16:11:09 +01001221component_test_ref_configs () {
1222 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Manuel Pégourié-Gonnard9327fb32021-09-09 11:46:25 +02001223 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
1224 # want to re-generate generated files that depend on it, quite correctly.
1225 # However this doesn't work as the generation script expects a specific
1226 # format for mbedtls_config.h, which the other files don't follow. Also,
1227 # cmake can't know this, but re-generation is actually not necessary as
David Horstmannd64f4b22021-10-20 12:29:47 +01001228 # the generated files only depend on the list of available options, not
Manuel Pégourié-Gonnard9327fb32021-09-09 11:46:25 +02001229 # whether they're on or off. So, disable cmake's (over-sensitive here)
1230 # dependency resolution for generated files and just rely on them being
David Horstmanna8d14062021-10-20 17:14:23 +01001231 # present (thanks to pre_generate_files) by turning GEN_FILES off.
1232 CC=gcc cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001233 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +01001234}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001235
Gilles Peskine8f073122018-11-27 15:58:47 +01001236component_test_no_renegotiation () {
1237 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001238 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001239 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1240 make
Simon Butcher3ea7f522016-03-07 23:22:10 +00001241
Gilles Peskine8f073122018-11-27 15:58:47 +01001242 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1243 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +01001244
Gilles Peskine8f073122018-11-27 15:58:47 +01001245 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001246 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001247}
Hanno Becker134c2ab2017-10-12 15:29:50 +01001248
Gilles Peskine636c26a2020-03-04 20:46:15 +01001249component_test_no_pem_no_fs () {
1250 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1251 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1252 scripts/config.py unset MBEDTLS_FS_IO
1253 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1254 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
1255 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1256 make
1257
1258 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1259 make test
1260
1261 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001262 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001263}
1264
Gilles Peskine8f073122018-11-27 15:58:47 +01001265component_test_rsa_no_crt () {
1266 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001267 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +01001268 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1269 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +01001270
Gilles Peskine8f073122018-11-27 15:58:47 +01001271 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1272 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001273
Gilles Peskine8f073122018-11-27 15:58:47 +01001274 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001275 tests/ssl-opt.sh -f RSA
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 compat.sh (ASan build)" # ~ 3 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001278 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001279
1280 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001281 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001282}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001283
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001284component_test_no_ctr_drbg_classic () {
1285 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001286 scripts/config.py full
1287 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001288 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001289 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001290
1291 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1292 make
1293
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001294 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001295 make test
1296
Gilles Peskineba749042021-01-13 20:02:03 +01001297 # In this configuration, the TLS test programs use HMAC_DRBG.
1298 # The SSL tests are slow, so run a small subset, just enough to get
1299 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001300 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001301 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001302
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001303 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001304 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001305}
1306
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001307component_test_no_ctr_drbg_use_psa () {
1308 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001309 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001310 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1311 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001312
1313 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1314 make
1315
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001316 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1317 make test
1318
1319 # In this configuration, the TLS test programs use HMAC_DRBG.
1320 # The SSL tests are slow, so run a small subset, just enough to get
1321 # confidence that the SSL code copes with HMAC_DRBG.
1322 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001323 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001324
1325 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001326 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001327}
1328
1329component_test_no_hmac_drbg_classic () {
1330 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1331 scripts/config.py full
1332 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1333 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1334 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001335 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001336
1337 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1338 make
1339
1340 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001341 make test
1342
Gilles Peskinea2224342020-11-19 22:14:34 +01001343 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1344 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1345 # instead.
1346 # Test SSL with non-deterministic ECDSA. Only test features that
1347 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001348 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001349 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001350
1351 # To save time, only test one protocol version, since this part of
1352 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001353 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001354 tests/compat.sh -m tls12 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001355}
1356
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001357component_test_no_hmac_drbg_use_psa () {
1358 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1359 scripts/config.py full
1360 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1361 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1362 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1363
1364 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1365 make
1366
1367 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1368 make test
1369
1370 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1371 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1372 # instead.
1373 # Test SSL with non-deterministic ECDSA. Only test features that
1374 # might be affected by how ECDSA signature is performed.
1375 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001376 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001377
1378 # To save time, only test one protocol version, since this part of
1379 # the protocol is identical in (D)TLS up to 1.2.
1380 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001381 tests/compat.sh -m tls12 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001382}
1383
1384component_test_psa_external_rng_no_drbg_classic () {
1385 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1386 scripts/config.py full
1387 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001388 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001389 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001390 scripts/config.py unset MBEDTLS_ENTROPY_C
1391 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1392 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001393 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1394 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1395 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001396 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1397 # the SSL test programs don't have an RNG and can't work. Explicitly
1398 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1399 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001400
1401 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1402 make test
1403
Gilles Peskine8eb29432021-02-03 20:07:11 +01001404 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001405 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001406}
1407
1408component_test_psa_external_rng_no_drbg_use_psa () {
1409 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001410 scripts/config.py full
1411 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001412 scripts/config.py unset MBEDTLS_ENTROPY_C
1413 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1414 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001415 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1416 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1417 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskinec109b372020-11-23 17:39:04 +01001418 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1419
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001420 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001421 make test
1422
Gilles Peskine8eb29432021-02-03 20:07:11 +01001423 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001424 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001425}
1426
Gilles Peskine4bdb2542023-04-28 19:25:25 +02001427component_test_psa_external_rng_use_psa_crypto () {
1428 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1429 scripts/config.py full
1430 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1431 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1432 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1433 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1434
1435 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1436 make test
1437
1438 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1439 tests/ssl-opt.sh -f 'Default\|opaque'
1440}
1441
Gilles Peskine801c4332023-04-28 21:04:28 +02001442component_test_psa_inject_entropy () {
1443 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
1444 scripts/config.py full
1445 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
1446 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
1447 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1448 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1449 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
1450 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
1451 make CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
1452
1453 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
1454 make test
1455}
1456
Andrzej Kurek06969fc2023-04-12 10:34:50 -04001457component_test_sw_inet_pton () {
1458 msg "build: default plus MBEDTLS_TEST_SW_INET_PTON"
1459
1460 # MBEDTLS_TEST_HOOKS required for x509_crt_parse_cn_inet_pton
1461 scripts/config.py set MBEDTLS_TEST_HOOKS
1462 make CFLAGS="-DMBEDTLS_TEST_SW_INET_PTON"
1463
1464 msg "test: default plus MBEDTLS_TEST_SW_INET_PTON"
1465 make test
1466}
1467
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001468component_test_crypto_full_md_light_only () {
1469 msg "build: crypto_full with only the light subset of MD"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001470 scripts/config.py crypto_full
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001471 # Disable MD
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001472 scripts/config.py unset MBEDTLS_MD_C
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001473 # Disable direct dependencies of MD_C
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001474 scripts/config.py unset MBEDTLS_HKDF_C
1475 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
Nick Child89e82e12022-11-09 10:36:10 -06001476 scripts/config.py unset MBEDTLS_PKCS7_C
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001477 # Disable indirect dependencies of MD_C
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001478 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001479 # Disable things that would auto-enable MD_C
1480 scripts/config.py unset MBEDTLS_PKCS5_C
1481
Manuel Pégourié-Gonnard1b5ffc62023-03-14 10:11:20 +01001482 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
1483 # which we haven't disabled, so no need to explicitly enable it.
1484 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001485
Manuel Pégourié-Gonnard0d415212023-02-23 13:02:13 +01001486 # Make sure we don't have the HMAC functions, but the hashing functions
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001487 not grep mbedtls_md_hmac library/md.o
Manuel Pégourié-Gonnard0d415212023-02-23 13:02:13 +01001488 grep mbedtls_md library/md.o
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001489
1490 msg "test: crypto_full with only the light subset of MD"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001491 make test
1492}
1493
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001494component_test_full_no_cipher () {
1495 msg "build: full minus CIPHER"
1496 scripts/config.py full
1497 scripts/config.py unset MBEDTLS_CIPHER_C
Przemek Stekielda5f4832022-05-12 09:46:29 +02001498 # Direct dependencies
1499 scripts/config.py unset MBEDTLS_CCM_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001500 scripts/config.py unset MBEDTLS_CMAC_C
Przemek Stekielda5f4832022-05-12 09:46:29 +02001501 scripts/config.py unset MBEDTLS_GCM_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001502 scripts/config.py unset MBEDTLS_NIST_KW_C
1503 scripts/config.py unset MBEDTLS_PKCS12_C
1504 scripts/config.py unset MBEDTLS_PKCS5_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001505 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1506 scripts/config.py unset MBEDTLS_SSL_TLS_C
1507 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielda5f4832022-05-12 09:46:29 +02001508 # Indirect dependencies
1509 scripts/config.py unset MBEDTLS_SSL_CLI_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001510 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
1511 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001512 scripts/config.py unset MBEDTLS_SSL_DTLS_ANTI_REPLAY
1513 scripts/config.py unset MBEDTLS_SSL_DTLS_CONNECTION_ID
Dave Rodgman1df70702022-10-26 17:08:54 +01001514 scripts/config.py unset MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT
Przemek Stekielda5f4832022-05-12 09:46:29 +02001515 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1516 scripts/config.py unset MBEDTLS_SSL_SRV_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001517 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Raef Colesa7e03ad2022-09-28 09:32:48 +01001518 scripts/config.py unset MBEDTLS_LMS_C
Raef Coles47bccb72022-09-28 12:00:20 +01001519 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001520 make
1521
1522 msg "test: full minus CIPHER"
1523 make test
1524}
1525
Valerio Settie1655b82023-01-03 15:35:25 +01001526component_test_full_no_bignum () {
1527 msg "build: full minus bignum"
1528 scripts/config.py full
1529 scripts/config.py unset MBEDTLS_BIGNUM_C
1530 # Direct dependencies of bignum
1531 scripts/config.py unset MBEDTLS_ECP_C
1532 scripts/config.py unset MBEDTLS_RSA_C
1533 scripts/config.py unset MBEDTLS_DHM_C
1534 # Direct dependencies of ECP
1535 scripts/config.py unset MBEDTLS_ECDH_C
1536 scripts/config.py unset MBEDTLS_ECDSA_C
1537 scripts/config.py unset MBEDTLS_ECJPAKE_C
1538 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Setti22d0a792023-06-14 17:23:19 +02001539 # Disable what auto-enables ECP_LIGHT
1540 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1541 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
Valerio Settie1655b82023-01-03 15:35:25 +01001542 # Indirect dependencies of ECP
1543 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1544 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1545 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1546 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1547 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1548 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
1549 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
1550 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
1551 # Direct dependencies of DHM
1552 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1553 # Direct dependencies of RSA
1554 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1555 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1556 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1557 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1558 # PK and its dependencies
1559 scripts/config.py unset MBEDTLS_PK_C
1560 scripts/config.py unset MBEDTLS_PK_PARSE_C
1561 scripts/config.py unset MBEDTLS_PK_WRITE_C
1562 scripts/config.py unset MBEDTLS_X509_USE_C
1563 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
1564 scripts/config.py unset MBEDTLS_X509_CRL_PARSE_C
1565 scripts/config.py unset MBEDTLS_X509_CSR_PARSE_C
1566 scripts/config.py unset MBEDTLS_X509_CREATE_C
1567 scripts/config.py unset MBEDTLS_X509_CRT_WRITE_C
1568 scripts/config.py unset MBEDTLS_X509_CSR_WRITE_C
1569 scripts/config.py unset MBEDTLS_PKCS7_C
1570 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
1571 scripts/config.py unset MBEDTLS_SSL_ASYNC_PRIVATE
1572 scripts/config.py unset MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
1573
1574 make
1575
1576 msg "test: full minus bignum"
1577 make test
1578}
1579
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001580component_test_tls1_2_default_stream_cipher_only () {
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001581 msg "build: default with only stream cipher"
1582
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001583 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001584 scripts/config.py unset MBEDTLS_GCM_C
1585 scripts/config.py unset MBEDTLS_CCM_C
1586 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001587 # 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 +02001588 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001589 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001590 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001591 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1592 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001593 # Modules that depend on AEAD
Przemek Stekield582a012022-09-28 07:59:01 +02001594 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001595 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001596
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001597 make
1598
1599 msg "test: default with only stream cipher"
1600 make test
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001601
1602 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001603}
1604
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001605component_test_tls1_2_default_stream_cipher_only_use_psa () {
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001606 msg "build: default with only stream cipher use psa"
Przemek Stekiel9550c052022-09-28 09:51:55 +02001607
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001608 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001609 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel9550c052022-09-28 09:51:55 +02001610 scripts/config.py unset MBEDTLS_GCM_C
1611 scripts/config.py unset MBEDTLS_CCM_C
1612 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001613 # 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 +02001614 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001615 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekiel9550c052022-09-28 09:51:55 +02001616 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001617 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1618 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001619 # Modules that depend on AEAD
Przemek Stekiel9550c052022-09-28 09:51:55 +02001620 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001621 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel9550c052022-09-28 09:51:55 +02001622
Przemek Stekiel9550c052022-09-28 09:51:55 +02001623 make
1624
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001625 msg "test: default with only stream cipher use psa"
Przemek Stekiel9550c052022-09-28 09:51:55 +02001626 make test
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001627
1628 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
Przemek Stekiel9550c052022-09-28 09:51:55 +02001629}
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001630
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001631component_test_tls1_2_default_cbc_legacy_cipher_only () {
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001632 msg "build: default with only CBC-legacy cipher"
1633
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001634 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001635 scripts/config.py unset MBEDTLS_GCM_C
1636 scripts/config.py unset MBEDTLS_CCM_C
1637 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001638 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1639 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1640 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001641 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001642 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001643 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001644 # Modules that depend on AEAD
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001645 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001646 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001647
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001648 make
1649
1650 msg "test: default with only CBC-legacy cipher"
1651 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001652
1653 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1654 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001655}
1656
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001657component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001658 msg "build: default with only CBC-legacy cipher use psa"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001659
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001660 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001661 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001662 scripts/config.py unset MBEDTLS_GCM_C
1663 scripts/config.py unset MBEDTLS_CCM_C
1664 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001665 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1666 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1667 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001668 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001669 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001670 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001671 # Modules that depend on AEAD
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001672 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001673 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001674
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001675 make
1676
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001677 msg "test: default with only CBC-legacy cipher use psa"
1678 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001679
1680 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1681 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001682}
1683
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001684component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001685 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1686
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001687 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001688 scripts/config.py unset MBEDTLS_GCM_C
1689 scripts/config.py unset MBEDTLS_CCM_C
1690 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001691 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1692 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1693 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1694 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1695 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001696 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001697 # Modules that depend on AEAD
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001698 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001699 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001700
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001701 make
1702
1703 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1704 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001705
1706 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1707 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001708}
1709
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001710component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
1711 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001712
1713 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001714 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001715 scripts/config.py unset MBEDTLS_GCM_C
1716 scripts/config.py unset MBEDTLS_CCM_C
1717 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001718 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1719 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1720 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1721 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1722 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001723 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001724 # Modules that depend on AEAD
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001725 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001726 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001727
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001728 make
1729
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001730 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001731 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001732
1733 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
1734 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001735}
1736
Valerio Setti9f0ec532022-11-08 13:03:24 +01001737# We're not aware of any other (open source) implementation of EC J-PAKE in TLS
1738# that we could use for interop testing. However, we now have sort of two
1739# implementations ourselves: one using PSA, the other not. At least test that
1740# these two interoperate with each other.
1741component_test_tls1_2_ecjpake_compatibility() {
1742 msg "build: TLS1.2 server+client w/ EC-JPAKE w/o USE_PSA"
1743 scripts/config.py set MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
1744 make -C programs ssl/ssl_server2 ssl/ssl_client2
1745 cp programs/ssl/ssl_server2 s2_no_use_psa
1746 cp programs/ssl/ssl_client2 c2_no_use_psa
1747
1748 msg "build: TLS1.2 server+client w/ EC-JPAKE w/ USE_PSA"
1749 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1750 make clean
1751 make -C programs ssl/ssl_server2 ssl/ssl_client2
1752 make -C programs test/udp_proxy test/query_compile_time_config
1753
Valerio Setti70e02902022-12-02 16:21:56 +01001754 msg "test: server w/o USE_PSA - client w/ USE_PSA, text password"
1755 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
1756 msg "test: server w/o USE_PSA - client w/ USE_PSA, opaque password"
1757 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password client only, working, TLS"
1758 msg "test: client w/o USE_PSA - server w/ USE_PSA, text password"
1759 P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
1760 msg "test: client w/o USE_PSA - server w/ USE_PSA, opaque password"
1761 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 +01001762
1763 rm s2_no_use_psa c2_no_use_psa
1764}
1765
Gilles Peskine636c26a2020-03-04 20:46:15 +01001766component_test_everest () {
1767 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine636c26a2020-03-04 20:46:15 +01001768 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1769 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1770 make
1771
1772 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1773 make test
1774
1775 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001776 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001777
1778 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1779 # Exclude some symmetric ciphers that are redundant here to gain time.
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02001780 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001781}
1782
Gilles Peskined3beca92020-07-03 00:15:37 +02001783component_test_everest_curve25519_only () {
1784 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
Gilles Peskined3beca92020-07-03 00:15:37 +02001785 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1786 scripts/config.py unset MBEDTLS_ECDSA_C
1787 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1788 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
TRodziewicz7c1d41d2021-04-23 13:33:44 +02001789 scripts/config.py unset MBEDTLS_ECJPAKE_C
Gilles Peskined3beca92020-07-03 00:15:37 +02001790 # Disable all curves
Valerio Setti2e0275d2023-07-28 16:33:13 +02001791 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
Gilles Peskined3beca92020-07-03 00:15:37 +02001792 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1793
1794 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1795
1796 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1797 make test
1798}
1799
Gilles Peskine8f073122018-11-27 15:58:47 +01001800component_test_small_ssl_out_content_len () {
1801 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001802 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1803 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001804 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1805 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001806
Gilles Peskine8f073122018-11-27 15:58:47 +01001807 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001808 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001809}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001810
Gilles Peskine8f073122018-11-27 15:58:47 +01001811component_test_small_ssl_in_content_len () {
1812 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001813 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1814 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001815 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1816 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001817
Gilles Peskine8f073122018-11-27 15:58:47 +01001818 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001819 tests/ssl-opt.sh -f "Max fragment"
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_dtls_max_buffering () {
1823 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001824 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001825 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1826 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001827
Gilles Peskine8f073122018-11-27 15:58:47 +01001828 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001829 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 +01001830}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001831
Gilles Peskine8f073122018-11-27 15:58:47 +01001832component_test_small_mbedtls_ssl_dtls_max_buffering () {
1833 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001834 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001835 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1836 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001837
Gilles Peskine8f073122018-11-27 15:58:47 +01001838 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001839 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001840}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001841
Gilles Peskine75cc7712019-09-06 19:47:17 +02001842component_test_psa_collect_statuses () {
1843 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001844 scripts/config.py full
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001845 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001846 # Check that psa_crypto_init() succeeded at least once
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001847 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001848 rm -f tests/statuses.log
1849}
1850
Gilles Peskine8f073122018-11-27 15:58:47 +01001851component_test_full_cmake_clang () {
1852 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001853 scripts/config.py full
Gilles Peskineda6017c2022-10-30 21:02:40 +01001854 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 +01001855 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001856
k-stachowiak0291cb72019-06-26 15:52:12 +02001857 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001858 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001859
Gilles Peskineda6017c2022-10-30 21:02:40 +01001860 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
1861 programs/test/cpp_dummy_build
1862
k-stachowiak0291cb72019-06-26 15:52:12 +02001863 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001864 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001865
Gilles Peskine8f073122018-11-27 15:58:47 +01001866 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001867 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001868
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02001869 msg "test: compat.sh NULL (full config)" # ~ 2 min
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01001870 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 +02001871
Gilles Peskine8f073122018-11-27 15:58:47 +01001872 msg "test: compat.sh ARIA + ChachaPoly"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01001873 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001874}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001875
Gilles Peskine0c671602022-11-29 16:01:41 +01001876skip_suites_without_constant_flow () {
1877 # Skip the test suites that don't have any constant-flow annotations.
1878 # This will need to be adjusted if we ever start declaring things as
1879 # secret from macros or functions inside tests/include or tests/src.
1880 SKIP_TEST_SUITES=$(
1881 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
1882 sed 's/test_suite_//; s/\.function$//' |
1883 tr '\n' ,)
1884 export SKIP_TEST_SUITES
1885}
1886
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001887component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001888 # This tests both (1) accesses to undefined memory, and (2) branches or
1889 # memory access depending on secret values. To distinguish between those:
1890 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1891 # - or alternatively, change the build type to MemSanDbg, which enables
1892 # origin tracking and nicer stack traces (which are useful for debugging
1893 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001894 msg "build: cmake MSan (clang), full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
1895 scripts/config.py full
1896 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1897 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1898 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1899 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1900 make
1901
1902 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO, Msan + constant flow)"
1903 make test
1904}
1905
1906component_test_memsan_constant_flow_psa () {
1907 # This tests both (1) accesses to undefined memory, and (2) branches or
1908 # memory access depending on secret values. To distinguish between those:
1909 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1910 # - or alternatively, change the build type to MemSanDbg, which enables
1911 # origin tracking and nicer stack traces (which are useful for debugging
1912 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001913 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001914 scripts/config.py full
1915 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1916 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1917 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1918 make
1919
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001920 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001921 make test
1922}
1923
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001924component_test_valgrind_constant_flow () {
1925 # This tests both (1) everything that valgrind's memcheck usually checks
1926 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1927 # etc.) and (2) branches or memory access depending on secret values,
1928 # which will be reported as uninitialized memory. To distinguish between
1929 # secret and actually uninitialized:
1930 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1931 # - or alternatively, build with debug info and manually run the offending
1932 # test suite with valgrind --track-origins=yes, then check if the origin
1933 # was TEST_CF_SECRET() or something else.
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001934 msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
1935 scripts/config.py full
1936 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
1937 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine0c671602022-11-29 16:01:41 +01001938 skip_suites_without_constant_flow
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001939 cmake -D CMAKE_BUILD_TYPE:String=Release .
1940 make
1941
1942 # this only shows a summary of the results (how many of each type)
1943 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine0c671602022-11-29 16:01:41 +01001944 msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, valgrind + constant flow)"
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001945 make memcheck
1946}
1947
1948component_test_valgrind_constant_flow_psa () {
1949 # This tests both (1) everything that valgrind's memcheck usually checks
1950 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1951 # etc.) and (2) branches or memory access depending on secret values,
1952 # which will be reported as uninitialized memory. To distinguish between
1953 # secret and actually uninitialized:
1954 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1955 # - or alternatively, build with debug info and manually run the offending
1956 # test suite with valgrind --track-origins=yes, then check if the origin
1957 # was TEST_CF_SECRET() or something else.
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001958 msg "build: cmake release GCC, full config with constant flow testing"
1959 scripts/config.py full
1960 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Gilles Peskine0c671602022-11-29 16:01:41 +01001961 skip_suites_without_constant_flow
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001962 cmake -D CMAKE_BUILD_TYPE:String=Release .
1963 make
1964
1965 # this only shows a summary of the results (how many of each type)
1966 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine0c671602022-11-29 16:01:41 +01001967 msg "test: some suites (valgrind + constant flow)"
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001968 make memcheck
1969}
1970
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001971component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02001972 # Test that removing the deprecated features from the default
1973 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001974 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
1975 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
1976 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1977
1978 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
1979 make test
1980}
1981
1982component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02001983 msg "build: make, full_no_deprecated config" # ~ 30s
1984 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001985 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
1986
Gilles Peskine30de2e82020-04-20 21:39:22 +02001987 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001988 make test
Valerio Setti41b5fb62023-01-09 12:20:45 +01001989
1990 msg "test: ensure that X509 has no direct dependency on BIGNUM_C"
1991 not grep mbedtls_mpi library/libmbedx509.a
Gilles Peskine1093d9f2020-04-13 01:03:21 +02001992}
1993
Gilles Peskine8386ea22020-04-30 09:07:29 +02001994component_test_full_no_deprecated_deprecated_warning () {
1995 # Test that there is nothing deprecated in "full_no_deprecated".
1996 # A deprecated feature would trigger a warning (made fatal) from
1997 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02001998 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
1999 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002000 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
2001 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
2002 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
2003
Gilles Peskine30de2e82020-04-20 21:39:22 +02002004 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002005 make test
2006}
2007
Gilles Peskine8386ea22020-04-30 09:07:29 +02002008component_test_full_deprecated_warning () {
2009 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
2010 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002011 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002012 scripts/config.py full
2013 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002014 # Expect warnings from '#warning' directives in check_config.h.
2015 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01002016
Gilles Peskine8386ea22020-04-30 09:07:29 +02002017 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
2018 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
2019 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002020 # Expect warnings from '#warning' directives in check_config.h and
2021 # from the use of deprecated functions in test suites.
2022 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 +01002023
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002024 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
2025 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01002026}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00002027
Gilles Peskineec541fe2020-01-31 14:24:14 +01002028# Check that the specified libraries exist and are empty.
2029are_empty_libraries () {
2030 nm "$@" >/dev/null 2>/dev/null
2031 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
2032}
2033
2034component_build_crypto_default () {
2035 msg "build: make, crypto only"
2036 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01002037 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002038 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002039}
2040
2041component_build_crypto_full () {
2042 msg "build: make, crypto only, full config"
2043 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01002044 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002045 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002046}
2047
Gilles Peskinefc4f11b2022-10-21 19:34:54 +02002048component_test_crypto_for_psa_service () {
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002049 msg "build: make, config for PSA crypto service"
2050 scripts/config.py crypto
2051 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
2052 # Disable things that are not needed for just cryptography, to
2053 # reach a configuration that would be typical for a PSA cryptography
2054 # service providing all implemented PSA algorithms.
2055 # System stuff
2056 scripts/config.py unset MBEDTLS_ERROR_C
2057 scripts/config.py unset MBEDTLS_TIMING_C
Gilles Peskine78bffd12022-10-25 21:02:33 +02002058 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002059 # Crypto stuff with no PSA interface
2060 scripts/config.py unset MBEDTLS_BASE64_C
Gilles Peskine649e04e2022-10-25 21:05:57 +02002061 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
Gilles Peskineb06f0712022-10-25 21:06:11 +02002062 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
Gilles Peskine649e04e2022-10-25 21:05:57 +02002063 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002064 scripts/config.py unset MBEDTLS_NIST_KW_C
2065 scripts/config.py unset MBEDTLS_PEM_PARSE_C
2066 scripts/config.py unset MBEDTLS_PEM_WRITE_C
2067 scripts/config.py unset MBEDTLS_PKCS12_C
2068 scripts/config.py unset MBEDTLS_PKCS5_C
Gilles Peskinefcee7402022-10-11 21:15:24 +02002069 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
2070 # in PSA code to work with RSA keys. We don't require users to set those:
2071 # they will be reenabled in build_info.h.
Gilles Peskine1f108072022-10-25 21:02:56 +02002072 scripts/config.py unset MBEDTLS_PK_C
Gilles Peskinefcee7402022-10-11 21:15:24 +02002073 scripts/config.py unset MBEDTLS_PK_PARSE_C
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002074 scripts/config.py unset MBEDTLS_PK_WRITE_C
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002075 make CFLAGS='-O1 -Werror' all test
2076 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
2077}
2078
Gilles Peskineec541fe2020-01-31 14:24:14 +01002079component_build_crypto_baremetal () {
2080 msg "build: make, crypto only, baremetal config"
2081 scripts/config.py crypto_baremetal
David Horstmann61faf662021-11-30 11:40:54 +00002082 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002083 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002084}
Daniel Axtens446af202020-09-02 21:30:13 +10002085support_build_crypto_baremetal () {
Daniel Axtens814c8132020-08-31 14:22:58 +10002086 support_build_baremetal "$@"
2087}
2088
2089component_build_baremetal () {
2090 msg "build: make, baremetal config"
2091 scripts/config.py baremetal
David Horstmann61faf662021-11-30 11:40:54 +00002092 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Daniel Axtens814c8132020-08-31 14:22:58 +10002093}
2094support_build_baremetal () {
Daniel Axtens446af202020-09-02 21:30:13 +10002095 # Older Glibc versions include time.h from other headers such as stdlib.h,
2096 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
2097 # problem, Ubuntu 18.04 is ok.
2098 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
2099}
Gilles Peskineec541fe2020-01-31 14:24:14 +01002100
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002101# depends.py family of tests
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002102component_test_depends_py_cipher_id () {
2103 msg "test/build: depends.py cipher_id (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002104 tests/scripts/depends.py cipher_id --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002105}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00002106
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002107component_test_depends_py_cipher_chaining () {
2108 msg "test/build: depends.py cipher_chaining (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002109 tests/scripts/depends.py cipher_chaining --unset-use-psa
John Durkopc14be902020-08-20 06:16:41 -07002110}
2111
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002112component_test_depends_py_cipher_padding () {
2113 msg "test/build: depends.py cipher_padding (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002114 tests/scripts/depends.py cipher_padding --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002115}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00002116
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002117component_test_depends_py_curves () {
2118 msg "test/build: depends.py curves (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002119 tests/scripts/depends.py curves --unset-use-psa
John Durkop2ec2eaa2020-08-24 18:29:15 -07002120}
2121
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002122component_test_depends_py_hashes () {
2123 msg "test/build: depends.py hashes (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002124 tests/scripts/depends.py hashes --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002125}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002126
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002127component_test_depends_py_kex () {
2128 msg "test/build: depends.py kex (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002129 tests/scripts/depends.py kex --unset-use-psa
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002130}
2131
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002132component_test_depends_py_pkalgs () {
2133 msg "test/build: depends.py pkalgs (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002134 tests/scripts/depends.py pkalgs --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002135}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002136
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002137# PSA equivalents of the depends.py tests
2138component_test_depends_py_cipher_id_psa () {
2139 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2140 tests/scripts/depends.py cipher_id
2141}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002142
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002143component_test_depends_py_cipher_chaining_psa () {
2144 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2145 tests/scripts/depends.py cipher_chaining
2146}
2147
2148component_test_depends_py_cipher_padding_psa () {
2149 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2150 tests/scripts/depends.py cipher_padding
2151}
2152
2153component_test_depends_py_curves_psa () {
2154 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2155 tests/scripts/depends.py curves
2156}
2157
2158component_test_depends_py_hashes_psa () {
2159 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2160 tests/scripts/depends.py hashes
2161}
2162
2163component_test_depends_py_kex_psa () {
2164 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2165 tests/scripts/depends.py kex
2166}
2167
2168component_test_depends_py_pkalgs_psa () {
2169 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002170 tests/scripts/depends.py pkalgs
Gilles Peskine8f073122018-11-27 15:58:47 +01002171}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002172
Dave Rodgman1a034dc2023-01-20 13:18:05 +00002173component_build_no_pk_rsa_alt_support () {
2174 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
2175
2176 scripts/config.py full
2177 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
2178 scripts/config.py set MBEDTLS_RSA_C
2179 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
2180
2181 # Only compile - this is primarily to test for compile issues
2182 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
2183}
2184
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002185component_build_module_alt () {
2186 msg "build: MBEDTLS_XXX_ALT" # ~30s
2187 scripts/config.py full
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002188
2189 # Disable options that are incompatible with some ALT implementations:
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002190 # aesni.c and padlock.c reference mbedtls_aes_context fields directly.
2191 scripts/config.py unset MBEDTLS_AESNI_C
2192 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08002193 scripts/config.py unset MBEDTLS_AESCE_C
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002194 # MBEDTLS_ECP_RESTARTABLE is documented as incompatible.
2195 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002196 # You can only have one threading implementation: alt or pthread, not both.
2197 scripts/config.py unset MBEDTLS_THREADING_PTHREAD
Gilles Peskine5c3f18d2021-05-31 21:21:12 +02002198 # The SpecifiedECDomain parsing code accesses mbedtls_ecp_group fields
2199 # directly and assumes the implementation works with partial groups.
2200 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
Tom Cosgrovef3ebd902022-02-20 22:25:31 +00002201 # MBEDTLS_SHA256_*ALT can't be used with MBEDTLS_SHA256_USE_A64_CRYPTO_*
2202 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2203 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00002204 # MBEDTLS_SHA512_*ALT can't be used with MBEDTLS_SHA512_USE_A64_CRYPTO_*
2205 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2206 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002207
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002208 # Enable all MBEDTLS_XXX_ALT for whole modules. Do not enable
2209 # MBEDTLS_XXX_YYY_ALT which are for single functions.
2210 scripts/config.py set-all 'MBEDTLS_([A-Z0-9]*|NIST_KW)_ALT'
Gilles Peskine1628a9c2021-05-31 22:09:58 +02002211 scripts/config.py unset MBEDTLS_DHM_ALT #incompatible with MBEDTLS_DEBUG_C
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002212
Gilles Peskine1628a9c2021-05-31 22:09:58 +02002213 # We can only compile, not link, since we don't have any implementations
2214 # suitable for testing with the dummy alt headers.
2215 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
2216}
2217
2218component_build_dhm_alt () {
2219 msg "build: MBEDTLS_DHM_ALT" # ~30s
2220 scripts/config.py full
2221 scripts/config.py set MBEDTLS_DHM_ALT
2222 # debug.c currently references mbedtls_dhm_context fields directly.
2223 scripts/config.py unset MBEDTLS_DEBUG_C
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002224 # We can only compile, not link, since we don't have any implementations
2225 # suitable for testing with the dummy alt headers.
2226 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
2227}
2228
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002229component_test_no_use_psa_crypto_full_cmake_asan() {
2230 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02002231 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002232 scripts/config.py full
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002233 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
2234 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cron6f135e12021-12-08 16:57:54 +01002235 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002236 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02002237 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002238 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Raef Colesa7e03ad2022-09-28 09:32:48 +01002239 scripts/config.py unset MBEDTLS_LMS_C
Raef Coles47bccb72022-09-28 12:00:20 +01002240 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01002241 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002242 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02002243
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002244 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002245 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02002246
Manuel Pégourié-Gonnard182a23b2022-12-07 10:38:43 +01002247 # Note: ssl-opt.sh has some test cases that depend on
2248 # MBEDTLS_ECP_RESTARTABLE && !MBEDTLS_USE_PSA_CRYPTO
2249 # This is the only component where those tests are not skipped.
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002250 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002251 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002252
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002253 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002254 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04002255
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02002256 msg "test: compat.sh NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01002257 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 -05002258
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002259 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01002260 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002261}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002262
Ronald Cron403c15c2021-09-13 09:38:05 +02002263component_test_psa_crypto_config_accel_ecdsa () {
Valerio Setti5aab43f2023-03-29 10:42:07 +02002264 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
Ronald Cron403c15c2021-09-13 09:38:05 +02002265
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002266 # Algorithms and key types to accelerate
Valerio Settic0d2f842023-06-28 10:48:08 +02002267 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2268 KEY_TYPE_ECC_KEY_PAIR_BASIC \
2269 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
2270 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
2271 KEY_TYPE_ECC_KEY_PAIR_GENERATE \
2272 KEY_TYPE_ECC_PUBLIC_KEY"
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002273
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002274 # Configure
2275 # ---------
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002276
Manuel Pégourié-Gonnard8d645dc2023-06-15 09:07:10 +02002277 # Start from default config (no USE_PSA) + TLS 1.3
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002278 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard6d7db932022-12-28 09:48:01 +01002279 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002280
2281 # Disable the module that's accelerated
Ronald Cron403c15c2021-09-13 09:38:05 +02002282 scripts/config.py unset MBEDTLS_ECDSA_C
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002283
2284 # Disable things that depend on it
Ronald Cron403c15c2021-09-13 09:38:05 +02002285 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2286 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2287
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002288 # Build
2289 # -----
2290
2291 # These hashes are needed for some ECDSA signature tests.
2292 loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
2293
2294 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2295
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02002296 helper_libtestdriver1_make_main "$loc_accel_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02002297
Manuel Pégourié-Gonnarde3095e72022-12-28 10:09:53 +01002298 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine827dbd92022-02-04 00:30:54 +01002299 not grep mbedtls_ecdsa_ library/ecdsa.o
Ronald Cron403c15c2021-09-13 09:38:05 +02002300
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002301 # Run the tests
2302 # -------------
2303
Ronald Cron403c15c2021-09-13 09:38:05 +02002304 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
2305 make test
2306}
2307
Valerio Setti44b178c2023-03-22 14:02:57 +01002308component_test_psa_crypto_config_accel_ecdh () {
Valerio Setti5aab43f2023-03-29 10:42:07 +02002309 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002310
2311 # Algorithms and key types to accelerate
Valerio Settic0d2f842023-06-28 10:48:08 +02002312 loc_accel_list="ALG_ECDH \
2313 KEY_TYPE_ECC_KEY_PAIR_BASIC \
2314 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
2315 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
2316 KEY_TYPE_ECC_KEY_PAIR_GENERATE \
2317 KEY_TYPE_ECC_PUBLIC_KEY"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002318
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002319 # Configure
2320 # ---------
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002321
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002322 # Start from default config (no TLS 1.3, no USE_PSA)
2323 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002324
Valerio Setti44b178c2023-03-22 14:02:57 +01002325 # Disable the module that's accelerated
2326 scripts/config.py unset MBEDTLS_ECDH_C
2327
2328 # Disable things that depend on it
2329 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2330 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2331 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2332 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2333 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2334
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002335 # Build
2336 # -----
2337
2338 helper_libtestdriver1_make_drivers "$loc_accel_list"
2339
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02002340 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002341
Valerio Setti44b178c2023-03-22 14:02:57 +01002342 # Make sure this was not re-enabled by accident (additive config)
2343 not grep mbedtls_ecdh_ library/ecdh.o
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002344
2345 # Run the tests
2346 # -------------
2347
Valerio Setti44b178c2023-03-22 14:02:57 +01002348 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002349 make test
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +01002350}
2351
Przemek Stekieldccb2022023-05-11 10:48:50 +02002352component_test_psa_crypto_config_accel_ffdh () {
2353 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated FFDH"
2354
2355 # Algorithms and key types to accelerate
Valerio Setti27602c32023-07-10 16:38:59 +02002356 loc_accel_list="ALG_FFDH \
2357 KEY_TYPE_DH_KEY_PAIR_BASIC \
2358 KEY_TYPE_DH_KEY_PAIR_IMPORT \
2359 KEY_TYPE_DH_KEY_PAIR_EXPORT \
2360 KEY_TYPE_DH_KEY_PAIR_GENERATE \
2361 KEY_TYPE_DH_PUBLIC_KEY"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002362
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002363 # Configure
2364 # ---------
Przemek Stekieldccb2022023-05-11 10:48:50 +02002365
Przemek Stekiel565353e2023-07-05 11:07:07 +02002366 # start with full (USE_PSA and TLS 1.3)
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002367 helper_libtestdriver1_adjust_config "full"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002368
2369 # Disable the module that's accelerated
2370 scripts/config.py unset MBEDTLS_DHM_C
2371
2372 # Disable things that depend on it
2373 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2374 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2375
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002376 # Build
2377 # -----
2378
2379 helper_libtestdriver1_make_drivers "$loc_accel_list"
2380
Manuel Pégourié-Gonnard981732e2023-06-08 09:15:59 +02002381 helper_libtestdriver1_make_main "$loc_accel_list"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002382
2383 # Make sure this was not re-enabled by accident (additive config)
2384 not grep mbedtls_dhm_ library/dhm.o
2385
2386 # Run the tests
2387 # -------------
2388
2389 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated FFDH"
2390 make test
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002391
2392 msg "ssl-opt: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated FFDH alg"
2393 tests/ssl-opt.sh -f "ffdh"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002394}
2395
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002396component_test_psa_crypto_config_reference_ffdh () {
2397 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated FFDH"
2398
2399 # Start with full (USE_PSA and TLS 1.3)
Przemek Stekiel565353e2023-07-05 11:07:07 +02002400 helper_libtestdriver1_adjust_config "full"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002401
2402 # Disable things that are not supported
2403 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2404 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002405 make
2406
2407 msg "test suites: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated FFDH alg + USE_PSA"
2408 make test
2409
2410 msg "ssl-opt: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated FFDH alg + USE_PSA"
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002411 tests/ssl-opt.sh -f "ffdh"
Valerio Setti42d5f192023-03-20 13:54:41 +01002412}
2413
Valerio Setti44b178c2023-03-22 14:02:57 +01002414component_test_psa_crypto_config_accel_pake() {
Valerio Setti42d5f192023-03-20 13:54:41 +01002415 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated PAKE"
2416
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002417 loc_accel_list="ALG_JPAKE"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002418
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002419 # Configure
2420 # ---------
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002421
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002422 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002423
2424 # Make built-in fallback not available
2425 scripts/config.py unset MBEDTLS_ECJPAKE_C
2426 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
2427
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002428 # Build
2429 # -----
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002430
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002431 helper_libtestdriver1_make_drivers "$loc_accel_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002432
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02002433 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002434
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002435 # Make sure this was not re-enabled by accident (additive config)
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002436 not grep mbedtls_ecjpake_init library/ecjpake.o
2437
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002438 # Run the tests
2439 # -------------
2440
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002441 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated PAKE"
2442 make test
2443}
2444
2445# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
2446# ECDH, ECDSA) with and without drivers.
2447# The input parameter is a boolean value which indicates:
2448# - 0 keep built-in EC algs,
2449# - 1 exclude built-in EC algs (driver only).
2450#
2451# This is used by the two following components to ensure they always use the
2452# same config, except for the use of driver or built-in EC algorithms:
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002453# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
2454# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002455# This supports comparing their test coverage with analyze_outcomes.py.
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002456config_psa_crypto_config_ecp_ligh_only () {
Valerio Setti42d5f192023-03-20 13:54:41 +01002457 DRIVER_ONLY="$1"
2458 # start with config full for maximum coverage (also enables USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002459 helper_libtestdriver1_adjust_config "full"
Valerio Setti42d5f192023-03-20 13:54:41 +01002460 if [ "$DRIVER_ONLY" -eq 1 ]; then
2461 # Disable modules that are accelerated
2462 scripts/config.py unset MBEDTLS_ECDSA_C
2463 scripts/config.py unset MBEDTLS_ECDH_C
2464 scripts/config.py unset MBEDTLS_ECJPAKE_C
Valerio Setti29b395c2023-04-05 18:20:30 +02002465 scripts/config.py unset MBEDTLS_ECP_C
Valerio Setti42d5f192023-03-20 13:54:41 +01002466 fi
2467
2468 # Restartable feature is not yet supported by PSA. Once it will in
2469 # the future, the following line could be removed (see issues
2470 # 6061, 6332 and following ones)
2471 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Setti42d5f192023-03-20 13:54:41 +01002472}
2473
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002474# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
2475component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
Valerio Setti42d5f192023-03-20 13:54:41 +01002476 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated EC algs + USE_PSA"
2477
2478 # Algorithms and key types to accelerate
2479 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2480 ALG_ECDH \
2481 ALG_JPAKE \
Valerio Settic0d2f842023-06-28 10:48:08 +02002482 KEY_TYPE_ECC_KEY_PAIR_BASIC \
2483 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
2484 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
2485 KEY_TYPE_ECC_KEY_PAIR_GENERATE \
2486 KEY_TYPE_ECC_PUBLIC_KEY"
Valerio Setti42d5f192023-03-20 13:54:41 +01002487
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002488 # Configure
2489 # ---------
Valerio Setti42d5f192023-03-20 13:54:41 +01002490
2491 # Use the same config as reference, only without built-in EC algs
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002492 config_psa_crypto_config_ecp_ligh_only 1
Valerio Setti42d5f192023-03-20 13:54:41 +01002493
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002494 # Build
2495 # -----
2496
2497 # These hashes are needed for some ECDSA signature tests.
2498 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
2499 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2500
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02002501 helper_libtestdriver1_make_main "$loc_accel_list"
Valerio Setti42d5f192023-03-20 13:54:41 +01002502
2503 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
2504 not grep mbedtls_ecdsa_ library/ecdsa.o
2505 not grep mbedtls_ecdh_ library/ecdh.o
2506 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Setti29b395c2023-04-05 18:20:30 +02002507 not grep mbedtls_ecp_mul library/ecp.o
Valerio Setti42d5f192023-03-20 13:54:41 +01002508
2509 # Run the tests
2510 # -------------
2511
2512 msg "test suites: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated EC algs + USE_PSA"
2513 make test
2514
2515 msg "ssl-opt: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated EC algs + USE_PSA"
2516 tests/ssl-opt.sh
2517}
2518
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002519# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
2520component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
Valerio Setti42d5f192023-03-20 13:54:41 +01002521 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated EC algs + USE_PSA"
2522
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002523 config_psa_crypto_config_ecp_ligh_only 0
Valerio Setti42d5f192023-03-20 13:54:41 +01002524
2525 make
2526
2527 msg "test suites: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated EC algs + USE_PSA"
2528 make test
2529
2530 msg "ssl-opt: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated EC algs + USE_PSA"
2531 tests/ssl-opt.sh
2532}
2533
Valerio Settie618cb02023-04-12 14:59:16 +02002534# This helper function is used by:
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002535# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
2536# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Valerio Settie618cb02023-04-12 14:59:16 +02002537# to ensure that both tests use the same underlying configuration when testing
2538# driver's coverage with analyze_outcomes.py.
2539#
2540# This functions accepts 1 boolean parameter as follows:
2541# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
2542# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
2543# - 0: include built-in implementation of EC algorithms.
2544#
2545# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
2546# on the ECP module.
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002547config_psa_crypto_no_ecp_at_all () {
Valerio Settie618cb02023-04-12 14:59:16 +02002548 DRIVER_ONLY="$1"
Valerio Settiaafe9002023-06-26 15:23:44 +02002549 # start with full config for maximum coverage (also enables USE_PSA)
2550 helper_libtestdriver1_adjust_config "full"
2551
Valerio Settie618cb02023-04-12 14:59:16 +02002552 if [ "$DRIVER_ONLY" -eq 1 ]; then
2553 # Disable modules that are accelerated
2554 scripts/config.py unset MBEDTLS_ECDSA_C
2555 scripts/config.py unset MBEDTLS_ECDH_C
2556 scripts/config.py unset MBEDTLS_ECJPAKE_C
2557 # Disable ECP module (entirely)
2558 scripts/config.py unset MBEDTLS_ECP_C
Valerio Settie618cb02023-04-12 14:59:16 +02002559 fi
2560
Valerio Settiaecd32c2023-06-14 10:42:31 +02002561 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
2562 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
Valerio Settiaddeee42023-06-14 10:46:55 +02002563 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
Ronald Cron6b49b552023-07-20 09:57:54 +02002564 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Valerio Settiaecd32c2023-06-14 10:42:31 +02002565
Valerio Settie618cb02023-04-12 14:59:16 +02002566 # Restartable feature is not yet supported by PSA. Once it will in
2567 # the future, the following line could be removed (see issues
2568 # 6061, 6332 and following ones)
2569 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Settie618cb02023-04-12 14:59:16 +02002570}
2571
2572# Build and test a configuration where driver accelerates all EC algs while
2573# all support and dependencies from ECP and ECP_LIGHT are removed on the library
2574# side.
2575#
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002576# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
2577component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
Valerio Setti887f8232023-06-27 17:16:33 +02002578 msg "build: full + accelerated EC algs + USE_PSA - ECP"
Valerio Settie618cb02023-04-12 14:59:16 +02002579
2580 # Algorithms and key types to accelerate
2581 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2582 ALG_ECDH \
2583 ALG_JPAKE \
Valerio Settic0d2f842023-06-28 10:48:08 +02002584 KEY_TYPE_ECC_KEY_PAIR_BASIC \
2585 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
2586 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
2587 KEY_TYPE_ECC_KEY_PAIR_GENERATE \
2588 KEY_TYPE_ECC_PUBLIC_KEY"
Valerio Settie618cb02023-04-12 14:59:16 +02002589
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002590 # Configure
2591 # ---------
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002592
Valerio Settie618cb02023-04-12 14:59:16 +02002593 # Set common configurations between library's and driver's builds
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002594 config_psa_crypto_no_ecp_at_all 1
Valerio Settie618cb02023-04-12 14:59:16 +02002595
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002596 # Build
2597 # -----
Valerio Settie618cb02023-04-12 14:59:16 +02002598
2599 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
2600 # SHA-1 and all SHA-2 variants, as they are used by ECDSA deterministic.
2601 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
Valerio Settie618cb02023-04-12 14:59:16 +02002602
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +02002603 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
Valerio Settie618cb02023-04-12 14:59:16 +02002604
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02002605 helper_libtestdriver1_make_main "$loc_accel_list"
Valerio Settie618cb02023-04-12 14:59:16 +02002606
2607 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
2608 not grep mbedtls_ecdsa_ library/ecdsa.o
2609 not grep mbedtls_ecdh_ library/ecdh.o
2610 not grep mbedtls_ecjpake_ library/ecjpake.o
2611 # Also ensure that ECP or RSA modules were not re-enabled
2612 not grep mbedtls_ecp_ library/ecp.o
Valerio Settie618cb02023-04-12 14:59:16 +02002613
2614 # Run the tests
2615 # -------------
2616
Valerio Setti887f8232023-06-27 17:16:33 +02002617 msg "test: full + accelerated EC algs + USE_PSA - ECP"
Valerio Settie618cb02023-04-12 14:59:16 +02002618 make test
Valerio Setti16b70f22023-06-27 17:45:49 +02002619
2620 msg "ssl-opt: full + accelerated EC algs + USE_PSA - ECP"
2621 tests/ssl-opt.sh
Valerio Settie618cb02023-04-12 14:59:16 +02002622}
2623
2624# Reference function used for driver's coverage analysis in analyze_outcomes.py
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002625# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
Valerio Settie618cb02023-04-12 14:59:16 +02002626# Keep in sync with its accelerated counterpart.
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002627component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
Valerio Setti887f8232023-06-27 17:16:33 +02002628 msg "build: full + non accelerated EC algs + USE_PSA"
Valerio Settie618cb02023-04-12 14:59:16 +02002629
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002630 config_psa_crypto_no_ecp_at_all 0
Valerio Settie618cb02023-04-12 14:59:16 +02002631
2632 make
2633
Valerio Setti0085c2e2023-06-28 10:17:44 +02002634 msg "test: full + non accelerated EC algs + USE_PSA"
Valerio Settie618cb02023-04-12 14:59:16 +02002635 make test
Valerio Setti16b70f22023-06-27 17:45:49 +02002636
Valerio Setti0085c2e2023-06-28 10:17:44 +02002637 msg "ssl-opt: full + non accelerated EC algs + USE_PSA"
Valerio Setti16b70f22023-06-27 17:45:49 +02002638 tests/ssl-opt.sh
Valerio Settie618cb02023-04-12 14:59:16 +02002639}
2640
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002641# This function is really similar to config_psa_crypto_no_ecp_at_all() above so
2642# its description is basically the same. The main difference in this case is
2643# that when the EC built-in implementation is disabled, then also Bignum module
2644# and its dependencies are disabled as well.
2645#
2646# This is the common helper between:
2647# - component_test_psa_crypto_config_accel_ecc_no_bignum
2648# - component_test_psa_crypto_config_reference_ecc_no_bignum
2649config_psa_crypto_config_accel_ecc_no_bignum() {
2650 DRIVER_ONLY="$1"
Valerio Setti18535c32023-07-31 11:27:17 +02002651 # start with full config for maximum coverage (also enables USE_PSA)
Valerio Setti29c1b4d2023-07-27 10:08:45 +02002652 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002653
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002654 if [ "$DRIVER_ONLY" -eq 1 ]; then
2655 # Disable modules that are accelerated
2656 scripts/config.py unset MBEDTLS_ECDSA_C
2657 scripts/config.py unset MBEDTLS_ECDH_C
2658 scripts/config.py unset MBEDTLS_ECJPAKE_C
2659 # Disable ECP module (entirely)
2660 scripts/config.py unset MBEDTLS_ECP_C
Manuel Pégourié-Gonnard660bbf22023-06-12 18:42:40 +02002661 # Also disable bignum
2662 scripts/config.py unset MBEDTLS_BIGNUM_C
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002663 fi
2664
2665 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
2666 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
2667 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
2668 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2669
Manuel Pégourié-Gonnard7dccb662023-06-12 18:28:42 +02002670 # RSA support is intentionally disabled on this test because RSA_C depends
2671 # on BIGNUM_C.
Valerio Setti2e0275d2023-07-28 16:33:13 +02002672 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
2673 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 +02002674 scripts/config.py unset MBEDTLS_RSA_C
2675 scripts/config.py unset MBEDTLS_PKCS1_V15
2676 scripts/config.py unset MBEDTLS_PKCS1_V21
2677 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2678 # Also disable key exchanges that depend on RSA
2679 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2680 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2681 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2682 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2683 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2684
Manuel Pégourié-Gonnard06aebe42023-06-12 18:33:34 +02002685 # Disable FFDH because it also depends on BIGNUM.
2686 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_FFDH
Valerio Setti2e0275d2023-07-28 16:33:13 +02002687 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
Manuel Pégourié-Gonnard06aebe42023-06-12 18:33:34 +02002688 scripts/config.py unset MBEDTLS_DHM_C
2689 # Also disable key exchanges that depend on FFDH
2690 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2691 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
Manuel Pégourié-Gonnard7dccb662023-06-12 18:28:42 +02002692
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002693 # 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
2697}
2698
2699# Build and test a configuration where driver accelerates all EC algs while
2700# all support and dependencies from ECP and ECP_LIGHT are removed on the library
2701# side.
2702#
2703# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_bignum()
2704component_test_psa_crypto_config_accel_ecc_no_bignum () {
Valerio Setti18535c32023-07-31 11:27:17 +02002705 msg "build: full + accelerated EC algs + USE_PSA - ECP - BIGNUM"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002706
2707 # Algorithms and key types to accelerate
2708 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2709 ALG_ECDH \
2710 ALG_JPAKE \
2711 KEY_TYPE_ECC_KEY_PAIR_BASIC \
2712 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
2713 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
2714 KEY_TYPE_ECC_KEY_PAIR_GENERATE \
2715 KEY_TYPE_ECC_PUBLIC_KEY"
2716
2717 # Configure
2718 # ---------
2719
2720 # Set common configurations between library's and driver's builds
2721 config_psa_crypto_config_accel_ecc_no_bignum 1
2722
2723 # Build
2724 # -----
2725
2726 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
2727 # SHA-1 and all SHA-2 variants, as they are used by ECDSA deterministic.
2728 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
2729
2730 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2731
2732 helper_libtestdriver1_make_main "$loc_accel_list"
2733
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 Settife7d96c2023-07-27 11:59:22 +02002738 # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002739 not grep mbedtls_ecp_ library/ecp.o
Manuel Pégourié-Gonnard06aebe42023-06-12 18:33:34 +02002740 not grep mbedtls_rsa_ library/rsa.o
2741 not grep mbedtls_dhm_ library/dhm.o
Manuel Pégourié-Gonnard660bbf22023-06-12 18:42:40 +02002742 not grep mbedtls_mpi_ library/bignum.o
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002743
2744 # Run the tests
2745 # -------------
2746
Valerio Setti18535c32023-07-31 11:27:17 +02002747 msg "test suites: full + accelerated EC algs + USE_PSA - ECP - BIGNUM"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002748 make test
2749
2750 # The following will be enabled in #7756
Valerio Setti18535c32023-07-31 11:27:17 +02002751 msg "ssl-opt: full + accelerated EC algs + USE_PSA - ECP - BIGNUM"
2752 tests/ssl-opt.sh
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002753}
2754
2755# Reference function used for driver's coverage analysis in analyze_outcomes.py
2756# in conjunction with component_test_psa_crypto_config_accel_ecc_no_bignum().
2757# Keep in sync with its accelerated counterpart.
2758component_test_psa_crypto_config_reference_ecc_no_bignum () {
Valerio Setti29c1b4d2023-07-27 10:08:45 +02002759 msg "build: full + non accelerated EC algs + USE_PSA"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002760
2761 config_psa_crypto_config_accel_ecc_no_bignum 0
2762
2763 make
2764
Valerio Setti29c1b4d2023-07-27 10:08:45 +02002765 msg "test suites: full + non accelerated EC algs + USE_PSA"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002766 make test
2767
2768 # The following will be enabled in #7756
Valerio Setti18535c32023-07-31 11:27:17 +02002769 msg "ssl-opt: full + non accelerated EC algs + USE_PSA"
2770 tests/ssl-opt.sh
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002771}
2772
Valerio Settie4758aa2023-03-24 16:51:17 +01002773# Helper function used in:
2774# - component_test_psa_crypto_config_accel_all_curves_except_p192
2775# - component_test_psa_crypto_config_accel_all_curves_except_x25519
2776# to build and test with all accelerated curves a part from the specified one.
2777psa_crypto_config_accel_all_curves_except_one () {
2778 BUILTIN_CURVE=$1
2779
Valerio Setti1f1420d2023-03-28 10:35:45 +02002780 msg "build: PSA_CRYPTO_CONFIG + all accelerated EC algs (excl $BUILTIN_CURVE) + USE_PSA_CRYPTO"
Valerio Settib7e95442023-03-21 11:52:33 +01002781
2782 # Accelerate all EC algs (all EC curves are automatically accelerated as
2783 # well in the built-in version due to the "PSA_WANT_xxx" symbols in
2784 # "crypto_config.h")
2785 loc_accel_list="ALG_ECDH \
2786 ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2787 ALG_JPAKE \
Valerio Setti072bded2023-06-27 12:08:56 +02002788 KEY_TYPE_ECC_KEY_PAIR_BASIC \
2789 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
2790 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
2791 KEY_TYPE_ECC_KEY_PAIR_GENERATE \
2792 KEY_TYPE_ECC_PUBLIC_KEY"
Valerio Settib7e95442023-03-21 11:52:33 +01002793
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002794 # Configure
2795 # ---------
Valerio Settib7e95442023-03-21 11:52:33 +01002796
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002797 helper_libtestdriver1_adjust_config "full"
Valerio Setti1a6d96f2023-03-24 14:10:24 +01002798
2799 # restartable is not yet supported in PSA
2800 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Settib7e95442023-03-21 11:52:33 +01002801
2802 # disable modules for which we have drivers
2803 scripts/config.py unset MBEDTLS_ECDSA_C
2804 scripts/config.py unset MBEDTLS_ECDH_C
2805 scripts/config.py unset MBEDTLS_ECJPAKE_C
2806
Valerio Settic6ecdad2023-04-03 08:26:35 +02002807 # Ensure also RSA and asssociated algs are disabled so that the size of
2808 # the public/private keys cannot be taken from there
Valerio Settib7e95442023-03-21 11:52:33 +01002809 scripts/config.py unset MBEDTLS_RSA_C
Valerio Settic6ecdad2023-04-03 08:26:35 +02002810 scripts/config.py unset MBEDTLS_PKCS1_V15
2811 scripts/config.py unset MBEDTLS_PKCS1_V21
2812 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002813 # Disable RSA on the PSA side too
Valerio Setti2e0275d2023-07-28 16:33:13 +02002814 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
2815 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
Valerio Settic6ecdad2023-04-03 08:26:35 +02002816 # Also disable key exchanges that depend on RSA
Valerio Setti3ebecc92023-03-23 16:52:22 +01002817 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2818 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2819 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2820 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2821 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
Valerio Settib7e95442023-03-21 11:52:33 +01002822
Valerio Settiee97a1e2023-03-27 12:44:15 +02002823 # Explicitly disable all SW implementation for elliptic curves
Valerio Setti2e0275d2023-07-28 16:33:13 +02002824 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
Valerio Settiee97a1e2023-03-27 12:44:15 +02002825 # Just leave SW implementation for the specified curve for allowing to
2826 # build with ECP_C.
Valerio Settie4758aa2023-03-24 16:51:17 +01002827 scripts/config.py set $BUILTIN_CURVE
Valerio Settiee97a1e2023-03-27 12:44:15 +02002828 # Accelerate all curves listed in "crypto_config.h" (skipping the ones that
Manuel Pégourié-Gonnardf8930e22023-06-13 09:51:32 +02002829 # are commented out).
2830 # Note: Those are handled in a special way by the libtestdriver machinery,
2831 # so we only want to include them in the accel list when building the main
2832 # libraries, hence the use of a separate variable.
2833 loc_curve_list=""
Valerio Settid0c644d2023-03-27 13:36:13 +02002834 for CURVE in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
Manuel Pégourié-Gonnardf8930e22023-06-13 09:51:32 +02002835 loc_curve_list="$loc_curve_list $CURVE"
Valerio Settiee97a1e2023-03-27 12:44:15 +02002836 done
Valerio Settib7e95442023-03-21 11:52:33 +01002837
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002838 # Build
2839 # -----
2840
2841 # These hashes are needed for some ECDSA signature tests.
2842 loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
2843 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2844
Manuel Pégourié-Gonnardf8930e22023-06-13 09:51:32 +02002845 # (See above regarding loc_curve_list.)
2846 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Valerio Settib7e95442023-03-21 11:52:33 +01002847
2848 # make sure excluded modules were not auto-re-enabled by accident
2849 not grep mbedtls_ecdh_ library/ecdh.o
2850 not grep mbedtls_ecdsa_ library/ecdsa.o
2851 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Settie4758aa2023-03-24 16:51:17 +01002852 if [ $BUILTIN_CURVE == "MBEDTLS_ECP_DP_SECP192R1_ENABLED" ]; then
Valerio Settiee97a1e2023-03-27 12:44:15 +02002853 # The only built-in curve is Short Weierstrass, so ECP shouldn't have
2854 # support for Montgomery curves. Functions with mxz in their name
2855 # are specific to Montgomery curves.
Valerio Settie4758aa2023-03-24 16:51:17 +01002856 not grep mxz library/ecp.o
Valerio Settiee97a1e2023-03-27 12:44:15 +02002857 elif [ $BUILTIN_CURVE == "MBEDTLS_ECP_DP_CURVE25519_ENABLED" ]; then
2858 # The only built-in curve is Montgomery, so ECP shouldn't have
2859 # support for Short Weierstrass curves. Functions with mbedtls_ecp_muladd
2860 # in their name are specific to Short Weierstrass curves.
Valerio Settie4758aa2023-03-24 16:51:17 +01002861 not grep mbedtls_ecp_muladd library/ecp.o
Valerio Settiee97a1e2023-03-27 12:44:15 +02002862 else
2863 err_msg "Error: $BUILTIN_CURVE is not supported in psa_crypto_config_accel_all_curves_except_one()"
2864 exit 1
Valerio Settie4758aa2023-03-24 16:51:17 +01002865 fi
Valerio Settib7e95442023-03-21 11:52:33 +01002866
2867 # Run the tests
2868 # -------------
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002869
Valerio Setti1f1420d2023-03-28 10:35:45 +02002870 msg "test: PSA_CRYPTO_CONFIG + all accelerated EC algs (excl $BUILTIN_CURVE) + USE_PSA_CRYPTO"
Valerio Settib7e95442023-03-21 11:52:33 +01002871 make test
2872}
2873
Valerio Settie4758aa2023-03-24 16:51:17 +01002874component_test_psa_crypto_config_accel_all_curves_except_p192 () {
2875 psa_crypto_config_accel_all_curves_except_one MBEDTLS_ECP_DP_SECP192R1_ENABLED
2876}
2877
2878component_test_psa_crypto_config_accel_all_curves_except_x25519 () {
2879 psa_crypto_config_accel_all_curves_except_one MBEDTLS_ECP_DP_CURVE25519_ENABLED
2880}
2881
Valerio Setti249b18a2023-06-20 12:08:30 +02002882# This is an helper used by:
2883# - component_test_psa_ecc_key_pair_no_derive
2884# - component_test_psa_ecc_key_pair_no_generate
2885# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
2886# enabled, but one. Input arguments are as follows:
2887# - $1 is the key type under test, i.e. ECC/RSA/DH
2888# - $2 is the key option to be unset (i.e. generate, derive, etc)
Valerio Settia9836552023-06-22 11:22:23 +02002889build_and_test_psa_want_key_pair_partial() {
Valerio Setti249b18a2023-06-20 12:08:30 +02002890 KEY_TYPE=$1
2891 UNSET_OPTION=$2
Valerio Settif6587be2023-06-22 11:33:14 +02002892 DISABLED_PSA_WANT="PSA_WANT_KEY_TYPE_${KEY_TYPE}_KEY_PAIR_${UNSET_OPTION}"
Valerio Setti249b18a2023-06-20 12:08:30 +02002893
Valerio Settif6587be2023-06-22 11:33:14 +02002894 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG - ${DISABLED_PSA_WANT}"
Valerio Setti249b18a2023-06-20 12:08:30 +02002895 scripts/config.py full
2896 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
2897 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2898 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2899
2900 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
2901 # crypto_config.h so we just disable the one we don't want.
Ronald Cron6b49b552023-07-20 09:57:54 +02002902 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$DISABLED_PSA_WANT"
Valerio Setti249b18a2023-06-20 12:08:30 +02002903
Valerio Settif6587be2023-06-22 11:33:14 +02002904 make CC=gcc CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Valerio Setti249b18a2023-06-20 12:08:30 +02002905
Valerio Settif6587be2023-06-22 11:33:14 +02002906 msg "test: full + MBEDTLS_PSA_CRYPTO_CONFIG - ${DISABLED_PSA_WANT}"
Valerio Setti249b18a2023-06-20 12:08:30 +02002907 make test
2908}
2909
2910component_test_psa_ecc_key_pair_no_derive() {
Valerio Settia9836552023-06-22 11:22:23 +02002911 build_and_test_psa_want_key_pair_partial "ECC" "DERIVE"
Valerio Setti249b18a2023-06-20 12:08:30 +02002912}
2913
2914component_test_psa_ecc_key_pair_no_generate() {
Valerio Settia9836552023-06-22 11:22:23 +02002915 build_and_test_psa_want_key_pair_partial "ECC" "GENERATE"
Valerio Setti249b18a2023-06-20 12:08:30 +02002916}
2917
Ronald Cron403c15c2021-09-13 09:38:05 +02002918component_test_psa_crypto_config_accel_rsa_signature () {
2919 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
2920
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002921 loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
2922
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002923 # Configure
2924 # ---------
Ronald Cron403c15c2021-09-13 09:38:05 +02002925
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002926 # Start from default config (no TLS 1.3, no USE_PSA)
2927 helper_libtestdriver1_adjust_config "default"
Ronald Cron403c15c2021-09-13 09:38:05 +02002928
2929 # It seems it is not possible to remove only the support for RSA signature
2930 # in the library. Thus we have to remove all RSA support (signature and
2931 # encryption/decryption). AS there is no driver support for asymmetric
2932 # encryption/decryption so far remove RSA encryption/decryption from the
2933 # application algorithm list.
Ronald Cron6b49b552023-07-20 09:57:54 +02002934 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
2935 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
Ronald Cron403c15c2021-09-13 09:38:05 +02002936
Manuel Pégourié-Gonnardaed1d782023-06-12 17:22:24 +02002937 # Remove RSA support and its dependencies
2938 scripts/config.py unset MBEDTLS_RSA_C
2939 scripts/config.py unset MBEDTLS_PKCS1_V15
2940 scripts/config.py unset MBEDTLS_PKCS1_V21
2941 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2942 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2943 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2944 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2945 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2946 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2947
Ronald Cron403c15c2021-09-13 09:38:05 +02002948 # Make sure both the library and the test library support the SHA hash
2949 # algorithms and only those ones (SHA256 is included by default). That way:
2950 # - the test library can compute the RSA signatures even in the case of a
2951 # composite RSA signature algorithm based on a SHA hash (no other hash
2952 # used in the unit tests).
2953 # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
2954 # fulfilled as the hash SHA algorithm is supported by the library, and
2955 # thus the tests are run, not skipped.
2956 # - when testing a signature key with an algorithm wildcard built from
2957 # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
2958 # algorithm based on the hashes supported by the library is also
2959 # supported by the test library.
Manuel Pégourié-Gonnardaed1d782023-06-12 17:22:24 +02002960 # Disable unwanted hashes here, we'll enable hashes we want in loc_extra_list.
Ronald Cron6b49b552023-07-20 09:57:54 +02002961 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
2962 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160_C
Ronald Cron403c15c2021-09-13 09:38:05 +02002963 scripts/config.py unset MBEDTLS_MD5_C
2964 scripts/config.py unset MBEDTLS_RIPEMD160_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01002965
2966 # We need PEM parsing in the test library as well to support the import
2967 # of PEM encoded RSA keys.
Ronald Cron7612d8c2023-07-20 10:03:54 +02002968 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
2969 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01002970
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002971 # Build
2972 # -----
2973
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01002974 # These hashes are needed for some RSA-PSS signature tests.
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002975 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
2976 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02002977
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02002978 helper_libtestdriver1_make_main "$loc_accel_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02002979
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002980 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine827dbd92022-02-04 00:30:54 +01002981 not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
2982 not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
Ronald Cron403c15c2021-09-13 09:38:05 +02002983
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002984 # Run the tests
2985 # -------------
2986
Ronald Cron403c15c2021-09-13 09:38:05 +02002987 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
2988 make test
2989}
2990
Valerio Settia1a0b1b2023-06-13 14:19:03 +02002991# This is a temporary test to verify that full RSA support is present even when
Valerio Setti01cc88a2023-06-15 11:53:08 +02002992# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Valerio Settia1a0b1b2023-06-13 14:19:03 +02002993component_test_new_psa_want_key_pair_symbol() {
Valerio Setti01cc88a2023-06-15 11:53:08 +02002994 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Valerio Settia1a0b1b2023-06-13 14:19:03 +02002995
Valerio Setti4590bc22023-06-13 15:39:23 +02002996 # Create a temporary output file unless there is already one set
2997 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
2998 REMOVE_OUTCOME_ON_EXIT="no"
2999 else
3000 REMOVE_OUTCOME_ON_EXIT="yes"
3001 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
3002 export MBEDTLS_TEST_OUTCOME_FILE
3003 fi
3004
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003005 # Start from crypto configuration
3006 scripts/config.py crypto
3007
3008 # Remove RSA support and its dependencies
3009 scripts/config.py unset MBEDTLS_PKCS1_V15
3010 scripts/config.py unset MBEDTLS_PKCS1_V21
3011 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3012 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3013 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3014 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
3015 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
3016 scripts/config.py unset MBEDTLS_RSA_C
3017 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
3018
3019 # Enable PSA support
3020 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3021
Valerio Setti01cc88a2023-06-15 11:53:08 +02003022 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003023 # that proper translations is done in crypto_legacy.h.
Ronald Cron6b49b552023-07-20 09:57:54 +02003024 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
3025 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
3026 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003027
3028 make
3029
Valerio Setti01cc88a2023-06-15 11:53:08 +02003030 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Valerio Setti4590bc22023-06-13 15:39:23 +02003031 make test
3032
3033 # Parse only 1 relevant line from the outcome file, i.e. a test which is
3034 # performing RSA signature.
3035 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
3036 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
3037
3038 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
3039 rm $MBEDTLS_TEST_OUTCOME_FILE
3040 fi
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003041}
3042
Ronald Cronb2312452021-05-08 14:32:59 +02003043component_test_psa_crypto_config_accel_hash () {
3044 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
3045
Ronald Cron27d47712021-12-07 09:54:36 +01003046 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
Ronald Cronb2312452021-05-08 14:32:59 +02003047
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003048 # Configure
3049 # ---------
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003050
3051 # Start from default config (no TLS 1.3, no USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003052 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003053
3054 # Disable the things that are being accelerated
Ronald Cronb2312452021-05-08 14:32:59 +02003055 scripts/config.py unset MBEDTLS_MD5_C
3056 scripts/config.py unset MBEDTLS_RIPEMD160_C
3057 scripts/config.py unset MBEDTLS_SHA1_C
Manuel Pégourié-Gonnardc584c272023-03-22 00:32:04 +01003058 scripts/config.py unset MBEDTLS_SHA224_C
3059 scripts/config.py unset MBEDTLS_SHA256_C
Ronald Cronb2312452021-05-08 14:32:59 +02003060 scripts/config.py unset MBEDTLS_SHA384_C
3061 scripts/config.py unset MBEDTLS_SHA512_C
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003062
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003063 # Build
3064 # -----
3065
3066 helper_libtestdriver1_make_drivers "$loc_accel_list"
3067
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003068 helper_libtestdriver1_make_main "$loc_accel_list"
Ronald Cronb2312452021-05-08 14:32:59 +02003069
Manuel Pégourié-Gonnardc584c272023-03-22 00:32:04 +01003070 # There's a risk of something getting re-enabled via config_psa.h;
3071 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
3072 not grep mbedtls_md5 library/md5.o
3073 not grep mbedtls_sha1 library/sha1.o
3074 not grep mbedtls_sha256 library/sha256.o
3075 not grep mbedtls_sha512 library/sha512.o
3076 not grep mbedtls_ripemd160 library/ripemd160.o
Ronald Cronb2312452021-05-08 14:32:59 +02003077
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003078 # Run the tests
3079 # -------------
3080
Ronald Cronb2312452021-05-08 14:32:59 +02003081 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
3082 make test
3083}
3084
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003085component_test_psa_crypto_config_accel_hash_keep_builtins () {
3086 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
3087 # This component ensures that all the test cases for
3088 # md_psa_dynamic_dispatch with legacy+driver in test_suite_md are run.
3089
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003090 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003091
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003092 # Start from default config (no TLS 1.3, no USE_PSA)
3093 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003094
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +02003095 helper_libtestdriver1_make_drivers "$loc_accel_list"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003096
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003097 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003098
3099 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
3100 make test
3101}
3102
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003103# Auxiliary function to build config for hashes with and without drivers
3104config_psa_crypto_hash_use_psa () {
3105 DRIVER_ONLY="$1"
3106 # start with config full for maximum coverage (also enables USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003107 helper_libtestdriver1_adjust_config "full"
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003108 if [ "$DRIVER_ONLY" -eq 1 ]; then
3109 # disable the built-in implementation of hashes
3110 scripts/config.py unset MBEDTLS_MD5_C
3111 scripts/config.py unset MBEDTLS_RIPEMD160_C
3112 scripts/config.py unset MBEDTLS_SHA1_C
3113 scripts/config.py unset MBEDTLS_SHA224_C
3114 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
3115 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
3116 scripts/config.py unset MBEDTLS_SHA384_C
3117 scripts/config.py unset MBEDTLS_SHA512_C
3118 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
3119 fi
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003120}
3121
Przemek Stekiel120ed8f2022-10-27 10:29:15 +02003122# Note that component_test_psa_crypto_config_reference_hash_use_psa
3123# is related to this component and both components need to be kept in sync.
3124# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003125component_test_psa_crypto_config_accel_hash_use_psa () {
3126 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash and USE_PSA"
3127
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003128 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003129
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003130 # Configure
3131 # ---------
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003132
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003133 config_psa_crypto_hash_use_psa 1
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003134
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003135 # Build
3136 # -----
3137
3138 helper_libtestdriver1_make_drivers "$loc_accel_list"
3139
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003140 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003141
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003142 # There's a risk of something getting re-enabled via config_psa.h;
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01003143 # 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 +02003144 not grep mbedtls_md5 library/md5.o
3145 not grep mbedtls_sha1 library/sha1.o
Manuel Pégourié-Gonnard7b0825d2022-07-11 11:06:09 +02003146 not grep mbedtls_sha256 library/sha256.o
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003147 not grep mbedtls_sha512 library/sha512.o
3148 not grep mbedtls_ripemd160 library/ripemd160.o
3149
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003150 # Run the tests
3151 # -------------
3152
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003153 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash and USE_PSA"
3154 make test
Andrzej Kurek07e35702022-09-05 15:39:23 -04003155
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003156 # This is mostly useful so that we can later compare outcome files with
3157 # the reference config in analyze_outcomes.py, to check that the
3158 # dependency declarations in ssl-opt.sh and in TLS code are correct.
Przemek Stekiel5f6f32a2022-10-27 08:24:43 +02003159 msg "test: ssl-opt.sh, MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash and USE_PSA"
3160 tests/ssl-opt.sh
Andrzej Kurek07e35702022-09-05 15:39:23 -04003161
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003162 # This is to make sure all ciphersuites are exercised, but we don't need
3163 # interop testing (besides, we already got some from ssl-opt.sh).
3164 msg "test: compat.sh, MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash and USE_PSA"
3165 tests/compat.sh -p mbedTLS -V YES
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003166}
3167
Przemek Stekiel120ed8f2022-10-27 10:29:15 +02003168# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
3169# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
3170# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
3171# Both components need to be kept in sync.
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003172component_test_psa_crypto_config_reference_hash_use_psa() {
3173 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG without accelerated hash and USE_PSA"
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003174
3175 config_psa_crypto_hash_use_psa 0
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003176
Przemek Stekielab0451b2022-10-24 11:29:35 +02003177 make
3178
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003179 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG without accelerated hash and USE_PSA"
3180 make test
3181
Przemek Stekiel5f6f32a2022-10-27 08:24:43 +02003182 msg "test: ssl-opt.sh, MBEDTLS_PSA_CRYPTO_CONFIG without accelerated hash and USE_PSA"
3183 tests/ssl-opt.sh
Ronald Cron3a8714d2021-10-18 11:26:01 +02003184}
Manuel Pégourié-Gonnard97ab2a32022-07-06 10:46:57 +02003185
John Durkop4377bf72020-10-23 01:26:57 -07003186component_test_psa_crypto_config_accel_cipher () {
3187 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
3188
3189 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 -08003190
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003191 # Configure
3192 # ---------
John Durkop1b7ee052020-11-27 08:51:22 -08003193
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003194 # Start from the default config (no TLS 1.3, no USE_PSA)
3195 helper_libtestdriver1_adjust_config "default"
John Durkop1b7ee052020-11-27 08:51:22 -08003196
Manuel Pégourié-Gonnard7ae342f2023-06-08 09:26:04 +02003197 # There is no intended accelerator support for ALG CMAC. Therefore, asking
3198 # for it in the build implies the inclusion of the Mbed TLS cipher
3199 # operations. As we want to test here with cipher operations solely
3200 # supported by accelerators, disabled this PSA configuration option.
3201 # (Note: the same applies to STREAM_CIPHER and ECB_NO_PADDING, which are
3202 # already disabled by helper_libtestdriver1_adjust_config above.)
Ronald Cron6b49b552023-07-20 09:57:54 +02003203 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
John Durkop1b7ee052020-11-27 08:51:22 -08003204
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003205 # Disable the things that are being accelerated
John Durkop1b7ee052020-11-27 08:51:22 -08003206 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3207 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
3208 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
3209 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
3210 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
3211 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
3212 scripts/config.py unset MBEDTLS_DES_C
3213
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003214 # Build
3215 # -----
John Durkop1b7ee052020-11-27 08:51:22 -08003216
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003217 helper_libtestdriver1_make_drivers "$loc_accel_list"
3218
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003219 helper_libtestdriver1_make_main "$loc_accel_list"
John Durkop1b7ee052020-11-27 08:51:22 -08003220
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003221 # Make sure this was not re-enabled by accident (additive config)
John Durkop1b7ee052020-11-27 08:51:22 -08003222 not grep mbedtls_des* library/des.o
3223
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003224 # Run the tests
3225 # -------------
3226
John Durkop1b7ee052020-11-27 08:51:22 -08003227 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
3228 make test
3229}
3230
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003231component_test_psa_crypto_config_accel_aead () {
3232 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
3233
Przemek Stekielee1bb412022-10-11 11:52:25 +02003234 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 +02003235
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003236 # Configure
3237 # ---------
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003238
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003239 # Start from default config (no TLS 1.3, no USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003240 helper_libtestdriver1_adjust_config "default"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003241
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003242 # Disable things that are being accelerated
Przemek Stekielee1bb412022-10-11 11:52:25 +02003243 scripts/config.py unset MBEDTLS_GCM_C
3244 scripts/config.py unset MBEDTLS_CCM_C
3245 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
3246 # Features that depend on AEAD
3247 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel072fad12022-10-13 09:59:52 +02003248 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003249
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003250 # Build
3251 # -----
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003252
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003253 helper_libtestdriver1_make_drivers "$loc_accel_list"
3254
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003255 helper_libtestdriver1_make_main "$loc_accel_list"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003256
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003257 # Make sure this was not re-enabled by accident (additive config)
Przemek Stekielee1bb412022-10-11 11:52:25 +02003258 not grep mbedtls_ccm library/ccm.o
3259 not grep mbedtls_gcm library/gcm.o
3260 not grep mbedtls_chachapoly library/chachapoly.o
3261
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003262 # Run the tests
3263 # -------------
3264
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003265 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
3266 make test
3267}
3268
Ronald Crone6e6b752023-01-16 16:56:51 +01003269component_test_psa_crypto_config_accel_pake() {
3270 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated PAKE"
John Durkop9814fa22020-11-04 12:28:15 -08003271
Ronald Crone6e6b752023-01-16 16:56:51 +01003272 loc_accel_list="ALG_JPAKE"
Ronald Crone6e6b752023-01-16 16:56:51 +01003273
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003274 # Configure
3275 # ---------
Ronald Crone6e6b752023-01-16 16:56:51 +01003276
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003277 helper_libtestdriver1_adjust_config "full"
Ronald Crone6e6b752023-01-16 16:56:51 +01003278
3279 # Make build-in fallback not available
3280 scripts/config.py unset MBEDTLS_ECJPAKE_C
3281 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
3282
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003283 # Build
3284 # -----
Ronald Crone6e6b752023-01-16 16:56:51 +01003285
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003286 helper_libtestdriver1_make_drivers "$loc_accel_list"
Ronald Crone6e6b752023-01-16 16:56:51 +01003287
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003288 helper_libtestdriver1_make_main "$loc_accel_list"
Ronald Crone6e6b752023-01-16 16:56:51 +01003289
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003290 # Make sure this was not re-enabled by accident (additive config)
Ronald Crone6e6b752023-01-16 16:56:51 +01003291 not grep mbedtls_ecjpake_init library/ecjpake.o
3292
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003293 # Run the tests
3294 # -------------
3295
Ronald Crone6e6b752023-01-16 16:56:51 +01003296 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated PAKE"
John Durkopf4c4cb02020-10-28 20:09:55 -07003297 make test
3298}
3299
3300component_test_psa_crypto_config_chachapoly_disabled() {
John Durkop9814fa22020-11-04 12:28:15 -08003301 # full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305
John Durkop07cc04a2020-11-16 22:08:34 -08003302 msg "build: full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305"
John Durkopf4c4cb02020-10-28 20:09:55 -07003303 scripts/config.py full
John Durkop9814fa22020-11-04 12:28:15 -08003304 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Ronald Cron6b49b552023-07-20 09:57:54 +02003305 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
3306 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
John Durkopf4c4cb02020-10-28 20:09:55 -07003307 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop6ba40d12020-11-10 08:50:04 -08003308
John Durkop9814fa22020-11-04 12:28:15 -08003309 msg "test: full minus MBEDTLS_CHACHAPOLY_C without PSA_WANT_ALG_GCM and PSA_WANT_ALG_CHACHA20_POLY1305"
3310 make test
John Durkopf4c4cb02020-10-28 20:09:55 -07003311}
3312
Ronald Crone501d0e2023-07-10 08:31:19 +02003313component_test_ccm_aes_sha256() {
3314 msg "build: CCM + AES + SHA256 configuration"
3315
Ronald Cron7612d8c2023-07-20 10:03:54 +02003316 cp "$CONFIG_TEST_DRIVER_H" "$CONFIG_H"
Ronald Cron6b49b552023-07-20 09:57:54 +02003317 cp configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
Ronald Crone501d0e2023-07-10 08:31:19 +02003318
3319 make CC=gcc
3320
3321 msg "test: CCM + AES + SHA256 configuration"
3322 make test
3323}
3324
John Durkop9814fa22020-11-04 12:28:15 -08003325# 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 -07003326component_build_psa_accel_alg_ecdh() {
3327 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_ECDH
John Durkopd0321952020-10-29 21:37:36 -07003328 # without MBEDTLS_ECDH_C
John Durkop6ba40d12020-11-10 08:50:04 -08003329 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
John Durkopd0321952020-10-29 21:37:36 -07003330 scripts/config.py full
3331 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkopd0321952020-10-29 21:37:36 -07003332 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003333 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkopd0321952020-10-29 21:37:36 -07003334 scripts/config.py unset MBEDTLS_ECDH_C
3335 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3336 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
3337 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
3338 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3339 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
3340 # 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 -08003341 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 -07003342}
3343
3344# This should be renamed to test and updated once the accelerator ECC key pair code is in place and ready to test.
3345component_build_psa_accel_key_type_ecc_key_pair() {
Valerio Settiff7f8612023-05-26 13:49:33 +02003346 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_xxx
3347 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_xxx"
John Durkopd0321952020-10-29 21:37:36 -07003348 scripts/config.py full
3349 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkopbd069d32020-10-31 22:14:03 -07003350 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003351 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003352 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC 1
3353 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT 1
3354 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT 1
3355 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE 1
3356 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE 1
3357 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
John Durkopd0321952020-10-29 21:37:36 -07003358 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3359 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop1b7ee052020-11-27 08:51:22 -08003360}
3361
3362# This should be renamed to test and updated once the accelerator ECC public key code is in place and ready to test.
3363component_build_psa_accel_key_type_ecc_public_key() {
3364 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY
3365 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY"
3366 scripts/config.py full
3367 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkop1b7ee052020-11-27 08:51:22 -08003368 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003369 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003370 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY 1
3371 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC
3372 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT
3373 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT
3374 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE
3375 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
John Durkop1b7ee052020-11-27 08:51:22 -08003376 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3377 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3378}
3379
3380# This should be renamed to test and updated once the accelerator HMAC code is in place and ready to test.
3381component_build_psa_accel_alg_hmac() {
3382 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HMAC
3383 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HMAC"
3384 scripts/config.py full
3385 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkop1b7ee052020-11-27 08:51:22 -08003386 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003387 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkop1b7ee052020-11-27 08:51:22 -08003388 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3389 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3390}
3391
3392# This should be renamed to test and updated once the accelerator HKDF code is in place and ready to test.
3393component_build_psa_accel_alg_hkdf() {
3394 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_HKDF
3395 # without MBEDTLS_HKDF_C
3396 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
3397 scripts/config.py full
3398 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkop1b7ee052020-11-27 08:51:22 -08003399 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003400 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkop1b7ee052020-11-27 08:51:22 -08003401 scripts/config.py unset MBEDTLS_HKDF_C
Ronald Cron6f135e12021-12-08 16:57:54 +01003402 # Make sure to unset TLS1_3 since it requires HKDF_C and will not build properly without it.
3403 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkop1b7ee052020-11-27 08:51:22 -08003404 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3405 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3406}
3407
3408# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
3409component_build_psa_accel_alg_md5() {
3410 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_MD5 without other hashes
3411 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_MD5 - other hashes"
3412 scripts/config.py full
3413 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkop1b7ee052020-11-27 08:51:22 -08003414 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003415 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003416 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3417 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3418 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3419 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3420 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3421 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3422 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003423 scripts/config.py unset MBEDTLS_LMS_C
3424 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003425 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3426 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3427}
3428
3429# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
3430component_build_psa_accel_alg_ripemd160() {
3431 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RIPEMD160 without other hashes
3432 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RIPEMD160 - other hashes"
3433 scripts/config.py full
3434 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkop1b7ee052020-11-27 08:51:22 -08003435 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003436 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003437 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3438 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3439 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3440 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3441 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3442 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3443 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003444 scripts/config.py unset MBEDTLS_LMS_C
3445 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003446 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3447 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3448}
3449
3450# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
3451component_build_psa_accel_alg_sha1() {
3452 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_1 without other hashes
3453 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_1 - other hashes"
3454 scripts/config.py full
3455 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkop1b7ee052020-11-27 08:51:22 -08003456 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003457 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003458 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3459 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3460 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3461 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3462 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3463 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3464 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003465 scripts/config.py unset MBEDTLS_LMS_C
3466 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003467 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3468 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3469}
3470
3471# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
3472component_build_psa_accel_alg_sha224() {
3473 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_224 without other hashes
3474 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_224 - other hashes"
3475 scripts/config.py full
3476 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkop1b7ee052020-11-27 08:51:22 -08003477 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003478 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003479 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3480 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3481 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3482 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3483 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3484 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
John Durkop1b7ee052020-11-27 08:51:22 -08003485 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3486 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3487}
3488
3489# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
3490component_build_psa_accel_alg_sha256() {
3491 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_256 without other hashes
3492 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_256 - other hashes"
3493 scripts/config.py full
3494 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkop1b7ee052020-11-27 08:51:22 -08003495 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003496 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003497 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3498 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3499 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3500 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3501 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3502 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
John Durkop1b7ee052020-11-27 08:51:22 -08003503 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3504 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3505}
3506
3507# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
3508component_build_psa_accel_alg_sha384() {
3509 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_384 without other hashes
3510 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_384 - other hashes"
3511 scripts/config.py full
3512 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkop1b7ee052020-11-27 08:51:22 -08003513 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003514 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003515 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3516 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3517 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3518 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3519 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3520 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003521 scripts/config.py unset MBEDTLS_LMS_C
3522 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003523 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3524 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3525}
3526
3527# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
3528component_build_psa_accel_alg_sha512() {
3529 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_SHA_512 without other hashes
3530 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_SHA_512 - other hashes"
3531 scripts/config.py full
3532 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkop1b7ee052020-11-27 08:51:22 -08003533 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003534 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003535 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3536 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3537 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3538 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3539 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3540 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3541 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003542 scripts/config.py unset MBEDTLS_LMS_C
3543 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003544 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3545 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3546}
3547
John Durkopd0321952020-10-29 21:37:36 -07003548# 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 -08003549component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
John Durkopbd069d32020-10-31 22:14:03 -07003550 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3551 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
John Durkopd0321952020-10-29 21:37:36 -07003552 scripts/config.py full
3553 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkopd0321952020-10-29 21:37:36 -07003554 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003555 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003556 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
3557 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3558 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3559 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07003560 # 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 -07003561 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3562}
3563
3564# 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 -08003565component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
John Durkopbd069d32020-10-31 22:14:03 -07003566 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PKCS1V15_SIGN and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
3567 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
3568 scripts/config.py full
3569 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkopbd069d32020-10-31 22:14:03 -07003570 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003571 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003572 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
3573 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3574 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3575 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07003576 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3577 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3578}
3579
3580# 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 -08003581component_build_psa_accel_alg_rsa_oaep() {
John Durkopbd069d32020-10-31 22:14:03 -07003582 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_OAEP and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
3583 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
3584 scripts/config.py full
3585 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkopbd069d32020-10-31 22:14:03 -07003586 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003587 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003588 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_OAEP 1
3589 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3590 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3591 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07003592 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3593 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3594}
3595
3596# 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 -08003597component_build_psa_accel_alg_rsa_pss() {
John Durkopbd069d32020-10-31 22:14:03 -07003598 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_ALG_RSA_PSS and PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
3599 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
3600 scripts/config.py full
3601 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkopbd069d32020-10-31 22:14:03 -07003602 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003603 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003604 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
3605 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3606 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3607 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07003608 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3609 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3610}
3611
3612# 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 -08003613component_build_psa_accel_key_type_rsa_key_pair() {
Valerio Settiff7f8612023-05-26 13:49:33 +02003614 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_xxx and PSA_WANT_ALG_RSA_PSS
3615 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_xxx + PSA_WANT_ALG_RSA_PSS"
John Durkopbd069d32020-10-31 22:14:03 -07003616 scripts/config.py full
3617 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkopbd069d32020-10-31 22:14:03 -07003618 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003619 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003620 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
3621 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC 1
3622 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT 1
3623 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT 1
3624 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE 1
John Durkopbd069d32020-10-31 22:14:03 -07003625 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3626 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"
3627}
3628
3629# 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 -08003630component_build_psa_accel_key_type_rsa_public_key() {
John Durkopbd069d32020-10-31 22:14:03 -07003631 # full plus MBEDTLS_PSA_CRYPTO_CONFIG with PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY and PSA_WANT_ALG_RSA_PSS
3632 msg "build: full + MBEDTLS_PSA_CRYPTO_CONFIG + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
3633 scripts/config.py full
3634 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
John Durkopbd069d32020-10-31 22:14:03 -07003635 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003636 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003637 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
3638 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
John Durkopbd069d32020-10-31 22:14:03 -07003639 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3640 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 -07003641}
3642
Dave Rodgmanc164c072023-06-28 09:43:23 +01003643
Dave Rodgman904c5892023-06-28 17:36:02 +01003644support_build_tfm_armcc () {
Dave Rodgmanc164c072023-06-28 09:43:23 +01003645 armc6_cc="$ARMC6_BIN_DIR/armclang"
3646 (check_tools "$armc6_cc" > /dev/null 2>&1)
3647}
3648
Dave Rodgman904c5892023-06-28 17:36:02 +01003649component_build_tfm_armcc() {
3650 # test the TF-M configuration can build cleanly with various warning flags enabled
Ronald Cron7a93ac52023-07-20 09:49:12 +02003651 cp configs/tfm_mbedcrypto_config_profile_medium.h "$CONFIG_H"
Ronald Cron6b49b552023-07-20 09:57:54 +02003652 cp configs/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Dave Rodgmanc164c072023-06-28 09:43:23 +01003653
Dave Rodgman88651c42023-06-29 12:35:51 +01003654 msg "build: TF-M config, armclang armv7-m thumb2"
Dave Rodgmanfb374e62023-06-29 11:58:16 +01003655 make clean
3656 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"
3657}
3658
3659component_build_tfm() {
3660 # test the TF-M configuration can build cleanly with various warning flags enabled
Ronald Cron7a93ac52023-07-20 09:49:12 +02003661 cp configs/tfm_mbedcrypto_config_profile_medium.h "$CONFIG_H"
Ronald Cron6b49b552023-07-20 09:57:54 +02003662 cp configs/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Dave Rodgmanfb374e62023-06-29 11:58:16 +01003663
Dave Rodgman88651c42023-06-29 12:35:51 +01003664 msg "build: TF-M config, clang, armv7-m thumb2"
3665 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"
Dave Rodgmanc164c072023-06-28 09:43:23 +01003666
Dave Rodgman904c5892023-06-28 17:36:02 +01003667 msg "build: TF-M config, gcc native build"
3668 make clean
Dave Rodgman1a4936a2023-06-29 14:07:50 +01003669 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"
Dave Rodgmanc164c072023-06-28 09:43:23 +01003670}
3671
Dave Rodgman6001fb22023-06-29 09:29:00 +01003672component_build_aes_variations() { # ~45s
Dave Rodgmancd040202023-06-29 09:29:00 +01003673 # aes.o has many #if defined(...) guards that intersect in complex ways.
3674 # Test that all the combinations build cleanly. The most common issue is
3675 # unused variables/functions, so ensure -Wunused is set.
3676
Dave Rodgman6001fb22023-06-29 09:29:00 +01003677 msg "build: aes.o for all combinations of relevant config options"
Dave Rodgman0f0f7692023-06-29 12:10:45 +01003678
Dave Rodgman6001fb22023-06-29 09:29:00 +01003679 for a in set unset; do
3680 for b in set unset; do
3681 for c in set unset; do
3682 for d in set unset; do
3683 for e in set unset; do
3684 for f in set unset; do
3685 for g in set unset; do
Dave Rodgman0f0f7692023-06-29 12:10:45 +01003686 echo ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
3687 echo ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
3688 echo ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
3689 echo ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
3690 echo ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
3691 echo ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
3692 echo ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman6001fb22023-06-29 09:29:00 +01003693
Dave Rodgman0f0f7692023-06-29 12:10:45 +01003694 ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
3695 ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
3696 ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
3697 ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
3698 ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
3699 ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
3700 ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman6001fb22023-06-29 09:29:00 +01003701
Dave Rodgman0f0f7692023-06-29 12:10:45 +01003702 rm -f library/aes.o
3703 make -C library aes.o CC="clang" CFLAGS="-O0 -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
Dave Rodgman6001fb22023-06-29 09:29:00 +01003704 done
3705 done
3706 done
3707 done
3708 done
3709 done
3710 done
3711}
3712
Gilles Peskine8f073122018-11-27 15:58:47 +01003713component_test_no_platform () {
3714 # Full configuration build, without platform support, file IO and net sockets.
3715 # This should catch missing mbedtls_printf definitions, and by disabling file
3716 # IO, it should catch missing '#include <stdio.h>'
3717 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003718 scripts/config.py full
3719 scripts/config.py unset MBEDTLS_PLATFORM_C
3720 scripts/config.py unset MBEDTLS_NET_C
3721 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
3722 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
3723 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
3724 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskineef843f22022-09-18 14:05:23 +02003725 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003726 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
3727 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskine6497b5a2022-06-30 17:01:40 +02003728 scripts/config.py unset MBEDTLS_PLATFORM_SETBUF_ALT
Gilles Peskine32e889d2020-04-12 23:43:28 +02003729 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003730 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
3731 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003732 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003733 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
3734 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01003735 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
3736 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02003737 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
3738 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01003739}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00003740
Gilles Peskine8f073122018-11-27 15:58:47 +01003741component_build_no_std_function () {
3742 # catch compile bugs in _uninit functions
3743 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003744 scripts/config.py full
3745 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
3746 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02003747 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinef4d2fd42021-10-08 11:45:47 +02003748 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskinedbf7b7e2021-10-07 19:34:57 +02003749 make
Gilles Peskine8f073122018-11-27 15:58:47 +01003750}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01003751
Gilles Peskine8f073122018-11-27 15:58:47 +01003752component_build_no_ssl_srv () {
Ronald Cronde1adee2022-03-07 16:20:30 +01003753 msg "build: full config except SSL server, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003754 scripts/config.py full
3755 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02003756 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01003757}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02003758
Gilles Peskine8f073122018-11-27 15:58:47 +01003759component_build_no_ssl_cli () {
Ronald Cronde1adee2022-03-07 16:20:30 +01003760 msg "build: full config except SSL client, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003761 scripts/config.py full
3762 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02003763 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01003764}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02003765
Gilles Peskine8f073122018-11-27 15:58:47 +01003766component_build_no_sockets () {
3767 # Note, C99 compliance can also be tested with the sockets support disabled,
3768 # as that requires a POSIX platform (which isn't the same as C99).
3769 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003770 scripts/config.py full
3771 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
3772 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02003773 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01003774}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02003775
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04003776component_test_memory_buffer_allocator_backtrace () {
3777 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003778 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
3779 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
3780 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
3781 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02003782 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04003783 make
3784
3785 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
3786 make test
3787}
3788
3789component_test_memory_buffer_allocator () {
3790 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003791 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
3792 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02003793 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Hanno Becker0fb9ba22019-02-26 14:34:13 +00003794 make
3795
3796 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
3797 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01003798
3799 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
3800 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02003801 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00003802}
3803
Gilles Peskine8f073122018-11-27 15:58:47 +01003804component_test_no_max_fragment_length () {
3805 # Run max fragment length tests with MFL disabled
3806 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003807 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01003808 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3809 make
Hanno Becker5175ac62017-09-18 15:36:25 +01003810
Gilles Peskine8f073122018-11-27 15:58:47 +01003811 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02003812 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01003813}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00003814
Hanno Becker545ced42019-02-19 11:10:48 +00003815component_test_asan_remove_peer_certificate () {
3816 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003817 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00003818 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3819 make
3820
3821 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
3822 make test
3823
3824 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02003825 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00003826
3827 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02003828 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003829
3830 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02003831 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00003832}
3833
Gilles Peskine8f073122018-11-27 15:58:47 +01003834component_test_no_max_fragment_length_small_ssl_out_content_len () {
3835 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003836 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
3837 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
3838 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01003839 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3840 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10003841
Gilles Peskine8f073122018-11-27 15:58:47 +01003842 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02003843 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02003844
3845 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02003846 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01003847}
Angus Grattonc4dd0732018-04-11 16:28:39 +10003848
Darryl Greenaad82f92019-12-02 10:53:11 +00003849component_test_variable_ssl_in_out_buffer_len () {
3850 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
3851 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
3852 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3853 make
3854
3855 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
3856 make test
3857
3858 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02003859 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00003860
3861 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02003862 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00003863}
3864
Manuel Pégourié-Gonnard6a543ba2022-11-25 11:30:10 +01003865component_test_dtls_cid_legacy () {
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01003866 msg "build: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled (ASan build)"
Hannes Tschofenigfd6cca42021-10-12 09:22:33 +02003867 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 1
Darryl Greenaad82f92019-12-02 10:53:11 +00003868
3869 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3870 make
3871
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01003872 msg "test: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy)"
Darryl Greenaad82f92019-12-02 10:53:11 +00003873 make test
3874
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01003875 msg "test: ssl-opt.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02003876 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00003877
Manuel Pégourié-Gonnard6a543ba2022-11-25 11:30:10 +01003878 msg "test: compat.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02003879 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00003880}
3881
Piotr Nowicki0937ed22019-11-26 16:32:40 +01003882component_test_ssl_alloc_buffer_and_mfl () {
3883 msg "build: default config with memory buffer allocator and MFL extension"
3884 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
3885 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
3886 scripts/config.py set MBEDTLS_MEMORY_DEBUG
3887 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
3888 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02003889 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Piotr Nowicki0937ed22019-11-26 16:32:40 +01003890 make
3891
3892 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
3893 make test
3894
3895 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02003896 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01003897}
3898
Gilles Peskine636c26a2020-03-04 20:46:15 +01003899component_test_when_no_ciphersuites_have_mac () {
3900 msg "build: when no ciphersuites have MAC"
3901 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Gilles Peskine636c26a2020-03-04 20:46:15 +01003902 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
TRodziewicz2add5c12021-04-28 16:50:20 +02003903 scripts/config.py unset MBEDTLS_CMAC_C
Gilles Peskine636c26a2020-03-04 20:46:15 +01003904 make
3905
3906 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
3907 make test
3908
3909 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02003910 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01003911}
3912
Raoul Strackxa4e86142020-06-15 17:03:13 +02003913component_test_no_date_time () {
3914 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
3915 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
Gilles Peskinef4d2fd42021-10-08 11:45:47 +02003916 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Raoul Strackxa4e86142020-06-15 17:03:13 +02003917 make
3918
3919 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
3920 make test
3921}
3922
Gilles Peskine8f073122018-11-27 15:58:47 +01003923component_test_platform_calloc_macro () {
3924 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003925 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
3926 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
3927 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01003928 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
3929 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01003930
Gilles Peskine8f073122018-11-27 15:58:47 +01003931 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
3932 make test
3933}
Hanno Beckere5fecec2018-10-11 11:02:52 +01003934
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02003935component_test_malloc_0_null () {
3936 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01003937 scripts/config.py full
Gilles Peskine004206c2019-10-21 17:11:33 +02003938 make CC=gcc CFLAGS="'-DMBEDTLS_CONFIG_FILE=\"$PWD/tests/configs/config-wrapper-malloc-0-null.h\"' $ASAN_CFLAGS -O" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02003939
3940 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
3941 make test
3942
3943 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
3944 # Just the calloc selftest. "make test" ran the others as part of the
3945 # test suites.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02003946 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01003947
3948 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
3949 # Run a subset of the tests. The choice is a balance between coverage
3950 # and time (including time indirectly wasted due to flaky tests).
3951 # The current choice is to skip tests whose description includes
3952 # "proxy", which is an approximation of skipping tests that use the
3953 # UDP proxy, which tend to be slower and flakier.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02003954 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02003955}
3956
Dave Rodgman6a08b682023-06-19 11:51:33 +01003957support_test_aesni() {
3958 # Check that gcc targets x86_64 (we can build AESNI), and check for
3959 # AESNI support on the host (we can run AESNI).
3960 #
3961 # The name of this function is possibly slightly misleading, but needs to align
3962 # with the name of the corresponding test, component_test_aesni.
Dave Rodgmanf8986e32023-06-19 10:55:59 +01003963 #
3964 # In principle 32-bit x86 can support AESNI, but our implementation does not
3965 # support 32-bit x86, so we check for x86-64.
3966 # We can only grep /proc/cpuinfo on Linux, so this also checks for Linux
Dave Rodgman6a08b682023-06-19 11:51:33 +01003967 (gcc -v 2>&1 | grep Target | grep -q x86_64) &&
3968 [[ "$HOSTTYPE" == "x86_64" && "$OSTYPE" == "linux-gnu" ]] &&
Jerry Yua7de78d2023-08-08 12:57:35 +08003969 (lscpu | grep -qw aes)
Dave Rodgmanf8986e32023-06-19 10:55:59 +01003970}
3971
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01003972component_test_aesni () { # ~ 60s
3973 # This tests the two AESNI implementations (intrinsics and assembly), and also the plain C
3974 # fallback. It also tests the logic that is used to select which implementation(s) to build.
3975 #
3976 # This test does not require the host to have support for AESNI (if it doesn't, the run-time
3977 # AESNI detection will fallback to the plain C implementation, so the tests will instead
3978 # exercise the plain C impl).
3979
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01003980 msg "build: default config with different AES implementations"
Dave Rodgman838dc462023-06-16 13:18:19 +01003981 scripts/config.py set MBEDTLS_AESNI_C
Jerry Yu17a9d2e2023-08-03 16:14:18 +08003982 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Dave Rodgman838dc462023-06-16 13:18:19 +01003983 scripts/config.py set MBEDTLS_HAVE_ASM
3984
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01003985 # test the intrinsics implementation
3986 msg "AES tests, test intrinsics"
Dave Rodgman838dc462023-06-16 13:18:19 +01003987 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08003988 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01003989 # check that we built intrinsics - this should be used by default when supported by the compiler
Jerry Yu1221a312023-08-03 16:09:07 +08003990 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01003991
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01003992 # test the asm implementation
3993 msg "AES tests, test assembly"
3994 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08003995 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mno-pclmul -mno-sse2 -mno-aes'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01003996 # check that we built assembly - this should be built if the compiler does not support intrinsics
Jerry Yu1221a312023-08-03 16:09:07 +08003997 ./programs/test/selftest aes | grep "AESNI code" | grep -q "assembly"
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01003998
3999 # test the plain C implementation
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004000 scripts/config.py unset MBEDTLS_AESNI_C
Jerry Yu17a9d2e2023-08-03 16:14:18 +08004001 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004002 msg "AES tests, plain C"
4003 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004004 make CC=gcc CFLAGS='-O2 -Werror'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004005 # check that there is no AESNI code present
Jerry Yu1221a312023-08-03 16:09:07 +08004006 ./programs/test/selftest aes | not grep -q "AESNI code"
Jerry Yu76a51b92023-08-08 16:03:55 +08004007 not grep -q "AES note: using AESNI" ./programs/test/selftest
4008 grep -q "AES note: built-in implementation." ./programs/test/selftest
Jerry Yu8a599c02023-08-03 17:01:02 +08004009
4010 # test the intrinsics implementation
4011 scripts/config.py set MBEDTLS_AESNI_C
4012 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4013 msg "AES tests, test AESNI only"
4014 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004015 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
Jerry Yua7de78d2023-08-08 12:57:35 +08004016 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
4017 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
Jerry Yu76a51b92023-08-08 16:03:55 +08004018 grep -q "AES note: using AESNI" ./programs/test/selftest
4019 not grep -q "AES note: built-in implementation." ./programs/test/selftest
Dave Rodgman838dc462023-06-16 13:18:19 +01004020}
4021
Jerry Yu193cbc02023-08-03 17:06:29 +08004022
Jerry Yub6d39c22023-08-16 15:11:48 +08004023
4024support_test_aesni_m32() {
4025 support_test_m32_o0 && (lscpu | grep -qw aes)
4026}
4027
4028component_test_aesni_m32 () { # ~ 60s
4029 # This tests are duplicated from component_test_aesni for i386 target
4030 #
4031 # AESNI intrinsic code supports i386 and assembly code does not support it.
4032
4033 msg "build: default config with different AES implementations"
4034 scripts/config.py set MBEDTLS_AESNI_C
4035 scripts/config.py set MBEDTLS_PADLOCK_C
4036 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4037 scripts/config.py set MBEDTLS_HAVE_ASM
4038
4039 # test the intrinsics implementation
4040 msg "AES tests, test intrinsics"
4041 make clean
4042 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
4043 # check that we built intrinsics - this should be used by default when supported by the compiler
4044 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
4045 grep -q "AES note: using AESNI" ./programs/test/selftest
4046 grep -q "AES note: built-in implementation." ./programs/test/selftest
4047 grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4048 grep -q mbedtls_aesni_has_support ./programs/test/selftest
4049
4050 scripts/config.py set MBEDTLS_AESNI_C
Jerry Yub6d39c22023-08-16 15:11:48 +08004051 scripts/config.py unset MBEDTLS_PADLOCK_C
4052 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4053 msg "AES tests, test AESNI only"
4054 make clean
4055 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
4056 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
4057 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
4058 grep -q "AES note: using AESNI" ./programs/test/selftest
4059 not grep -q "AES note: built-in implementation." ./programs/test/selftest
4060 not grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4061 not grep -q mbedtls_aesni_has_support ./programs/test/selftest
4062}
4063
Jerry Yu193cbc02023-08-03 17:06:29 +08004064# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
4065component_build_aes_aesce_armcc () {
4066 msg "Build: AESCE test on arm64 platform without plain C."
4067 scripts/config.py baremetal
4068
4069 # armc[56] don't support SHA-512 intrinsics
4070 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
4071
4072 # Stop armclang warning about feature detection for A64_CRYPTO.
4073 # With this enabled, the library does build correctly under armclang,
4074 # but in baremetal builds (as tested here), feature detection is
4075 # unavailable, and the user is notified via a #warning. So enabling
4076 # this feature would prevent us from building with -Werror on
4077 # armclang. Tracked in #7198.
4078 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
4079 scripts/config.py set MBEDTLS_HAVE_ASM
4080
4081 msg "AESCE, build with default configuration."
4082 scripts/config.py set MBEDTLS_AESCE_C
4083 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4084 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
4085
4086 msg "AESCE, build AESCE only"
4087 scripts/config.py set MBEDTLS_AESCE_C
4088 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4089 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
4090}
4091
Jerry Yuc935aa62023-08-03 17:08:27 +08004092# For timebeing, no VIA Padlock platform available.
4093component_build_aes_via_padlock () {
4094
4095 msg "AES:VIA PadLock, build with default configuration."
Jerry Yu506759f2023-08-16 17:11:22 +08004096 scripts/config.py unset MBEDTLS_AESNI_C
Jerry Yuc935aa62023-08-03 17:08:27 +08004097 scripts/config.py set MBEDTLS_PADLOCK_C
4098 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4099 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Jerry Yu506759f2023-08-16 17:11:22 +08004100 grep -q mbedtls_padlock_has_support ./programs/test/selftest
Jerry Yuc935aa62023-08-03 17:08:27 +08004101
4102}
4103
4104support_build_aes_via_padlock_only () {
4105 ( [ "$MBEDTLS_TEST_PLATFORM" == "Linux-x86_64" ] || \
4106 [ "$MBEDTLS_TEST_PLATFORM" == "Linux-amd64" ] ) && \
4107 [ "`dpkg --print-foreign-architectures`" == "i386" ]
4108}
4109
Jerry Yu193cbc02023-08-03 17:06:29 +08004110support_build_aes_aesce_armcc () {
4111 support_build_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +01004112}
4113
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004114component_test_aes_only_128_bit_keys () {
Gilles Peskine8f073122018-11-27 15:58:47 +01004115 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
Hanno Becker83ebf782017-07-07 12:29:15 +01004116 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01004117 scripts/config.py unset MBEDTLS_PADLOCK_C
4118
4119 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01004120
Gilles Peskine8f073122018-11-27 15:58:47 +01004121 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
4122 make test
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004123}
4124
Gilles Peskine8f073122018-11-27 15:58:47 +01004125component_test_no_ctr_drbg_aes_only_128_bit_keys () {
Hanno Becker83ebf782017-07-07 12:29:15 +01004126 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
Gilles Peskine8f073122018-11-27 15:58:47 +01004127 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4128 scripts/config.py unset MBEDTLS_CTR_DRBG_C
4129 scripts/config.py unset MBEDTLS_PADLOCK_C
4130
Gilles Peskine592f5912019-10-07 18:49:32 +02004131 make CC=clang CFLAGS='-Werror -Wall -Wextra'
4132
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004133 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
4134 make test
4135}
Gilles Peskine592f5912019-10-07 18:49:32 +02004136
4137component_test_aes_only_128_bit_keys_have_builtins () {
4138 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4139 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4140 scripts/config.py unset MBEDTLS_PADLOCK_C
4141 scripts/config.py unset MBEDTLS_AESNI_C
4142 scripts/config.py unset MBEDTLS_AESCE_C
4143
4144 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004145
4146 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4147 make test
Gilles Peskine592f5912019-10-07 18:49:32 +02004148
4149 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4150 programs/test/selftest
4151}
4152
4153component_test_aes_fewer_tables () {
4154 msg "build: default config with AES_FEWER_TABLES enabled"
4155 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
4156 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004157
4158 msg "test: AES_FEWER_TABLES"
4159 make test
4160}
Gilles Peskine592f5912019-10-07 18:49:32 +02004161
4162component_test_aes_rom_tables () {
4163 msg "build: default config with AES_ROM_TABLES enabled"
4164 scripts/config.py set MBEDTLS_AES_ROM_TABLES
4165 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
4166
4167 msg "test: AES_ROM_TABLES"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02004168 make test
4169}
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004170
Gilles Peskine004206c2019-10-21 17:11:33 +02004171component_test_aes_fewer_tables_and_rom_tables () {
Gilles Peskinef96aefe2019-07-24 14:58:38 +02004172 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
4173 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
4174 scripts/config.py set MBEDTLS_AES_ROM_TABLES
4175 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
4176
Steven Cooremand57203d2020-07-16 20:28:59 +02004177 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
Ronald Cron32a432a2023-03-28 09:19:04 +02004178 make test
Steven Cooreman753f9732021-03-15 11:38:44 +01004179}
Steven Cooreman6801f082021-02-19 17:21:22 +01004180
Gilles Peskine3587dfd2021-09-20 19:20:04 +02004181component_test_ctr_drbg_aes_256_sha_256 () {
4182 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Ronald Cron17b3afc2020-12-10 18:17:09 +01004183 scripts/config.py full
4184 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4185 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Steven Cooremand57203d2020-07-16 20:28:59 +02004186 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Ronald Cron32a432a2023-03-28 09:19:04 +02004187 make
Steven Cooremand57203d2020-07-16 20:28:59 +02004188
4189 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4190 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01004191}
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004192
Andrzej Kurek232e8f92019-10-03 03:18:01 -04004193component_test_ctr_drbg_aes_128_sha_512 () {
Gilles Peskine56c01612019-07-03 20:43:32 +02004194 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskineca144592021-11-04 12:52:14 +01004195 scripts/config.py full
Gilles Peskine8f073122018-11-27 15:58:47 +01004196 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02004197 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskinecf740502019-07-03 20:43:05 +02004198 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4199 make
4200
4201 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine56c01612019-07-03 20:43:32 +02004202 make test
Gilles Peskinecf740502019-07-03 20:43:05 +02004203}
Gilles Peskineca144592021-11-04 12:52:14 +01004204
Gilles Peskinecf740502019-07-03 20:43:05 +02004205component_test_ctr_drbg_aes_128_sha_256 () {
4206 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskineec10bf12019-09-20 19:56:06 +02004207 scripts/config.py full
4208 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4209 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
4210 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskinee094a182020-04-14 20:08:41 +02004211 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskineec10bf12019-09-20 19:56:06 +02004212 make
4213
4214 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4215 make test
4216}
4217
4218component_test_se_default () {
4219 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
4220 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
4221 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004222
Gilles Peskineec10bf12019-09-20 19:56:06 +02004223 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
4224 make test
4225}
4226
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004227component_test_psa_crypto_drivers () {
Gilles Peskineec10bf12019-09-20 19:56:06 +02004228 msg "build: full + MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS + test drivers"
4229 scripts/config.py full
4230 scripts/config.py set MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02004231 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
4232 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
Gilles Peskine2003c2f2022-04-07 20:55:57 +02004233 loc_cflags="${loc_cflags} -I../tests/include -O2"
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02004234
4235 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine45e680e2022-04-13 23:23:21 +02004236
Gilles Peskinee10df772022-04-07 21:06:41 +02004237 msg "test: full + MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS + test drivers"
4238 make test
4239}
4240
4241component_test_make_shared () {
4242 msg "build/test: make shared" # ~ 40s
4243 make SHARED=1 all check
4244 ldd programs/util/strerror | grep libmbedcrypto
4245 programs/test/dlopen_demo.sh
4246}
4247
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004248component_test_cmake_shared () {
4249 msg "build/test: cmake shared" # ~ 2min
Gilles Peskine7d904e72022-04-07 21:59:14 +02004250 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
4251 make
4252 ldd programs/util/strerror | grep libmbedcrypto
4253 make test
4254 programs/test/dlopen_demo.sh
4255}
Gilles Peskine45e680e2022-04-13 23:23:21 +02004256
Gilles Peskine7d904e72022-04-07 21:59:14 +02004257test_build_opt () {
4258 info=$1 cc=$2; shift 2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004259 $cc --version
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004260 for opt in "$@"; do
4261 msg "build/test: $cc $opt, $info" # ~ 30s
4262 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
4263 # We're confident enough in compilers to not run _all_ the tests,
4264 # but at least run the unit tests. In particular, runs with
4265 # optimizations use inline assembly whereas runs with -O0
Gilles Peskine8f073122018-11-27 15:58:47 +01004266 # skip inline assembly.
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004267 make test # ~30s
4268 make clean
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004269 done
Gilles Peskine8fd59422019-10-21 17:11:33 +02004270}
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004271
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004272# For FreeBSD we invoke the function by name so this condition is added
4273# to disable the existing test_clang_opt function for linux.
4274if [[ $(uname) != "Linux" ]]; then
4275 component_test_clang_opt () {
4276 scripts/config.py full
4277 test_build_opt 'full config' clang -O0 -Os -O2
4278 }
4279fi
4280
4281component_test_clang_latest_opt () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004282 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004283 test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004284}
4285support_test_clang_latest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004286 type "$CLANG_LATEST" >/dev/null 2>/dev/null
Gilles Peskine878cf602019-01-06 20:50:38 +00004287}
4288
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004289component_test_clang_earliest_opt () {
Gilles Peskine878cf602019-01-06 20:50:38 +00004290 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004291 test_build_opt 'full config' "$CLANG_EARLIEST" -O0
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004292}
4293support_test_clang_earliest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004294 type "$CLANG_EARLIEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004295}
4296
4297component_test_gcc_latest_opt () {
4298 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004299 test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004300}
4301support_test_gcc_latest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004302 type "$GCC_LATEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004303}
4304
4305component_test_gcc_earliest_opt () {
4306 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004307 test_build_opt 'full config' "$GCC_EARLIEST" -O0
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004308}
4309support_test_gcc_earliest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004310 type "$GCC_EARLIEST" >/dev/null 2>/dev/null
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004311}
4312
4313component_build_mbedtls_config_file () {
4314 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
4315 scripts/config.py -w full_config.h full
Gilles Peskine14c3c062018-01-29 21:25:12 +01004316 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004317 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
Gilles Peskine14c3c062018-01-29 21:25:12 +01004318 # Make sure this feature is enabled. We'll disable it in the next phase.
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004319 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01004320 make clean
Gilles Peskine14c3c062018-01-29 21:25:12 +01004321
Gilles Peskine77f05352021-10-07 19:27:16 +02004322 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
4323 # In the user config, disable one feature (for simplicity, pick a feature
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004324 # that nothing else depends on).
4325 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
4326 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
4327 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004328
4329 rm -f user_config.h full_config.h
Gilles Peskine8f073122018-11-27 15:58:47 +01004330}
Gilles Peskine7d904e72022-04-07 21:59:14 +02004331
4332component_build_psa_config_file () {
4333 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
4334 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
4335 cp "$CRYPTO_CONFIG_H" psa_test_config.h
4336 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
4337 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
4338 # Make sure this feature is enabled. We'll disable it in the next phase.
4339 programs/test/query_compile_time_config MBEDTLS_CMAC_C
4340 make clean
4341
4342 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
4343 # In the user config, disable one feature, which will reflect on the
4344 # mbedtls configuration so we can query it with query_compile_time_config.
4345 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
4346 scripts/config.py unset MBEDTLS_CMAC_C
4347 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
4348 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
4349
4350 rm -f psa_test_config.h psa_user_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004351}
4352
Gilles Peskinedf6e84a2023-02-22 22:09:51 +01004353component_build_psa_alt_headers () {
4354 msg "build: make with PSA alt headers" # ~20s
4355
4356 # Generate alternative versions of the substitutable headers with the
4357 # same content except different include guards.
4358 make -C tests include/alt-extra/psa/crypto_platform_alt.h include/alt-extra/psa/crypto_struct_alt.h
4359
4360 # Build the library and some programs.
4361 # Don't build the fuzzers to avoid having to go through hoops to set
4362 # a correct include path for programs/fuzz/Makefile.
4363 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
4364 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\"'"
4365
4366 # Check that we're getting the alternative include guards and not the
4367 # original include guards.
4368 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
4369 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
4370 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
4371 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
4372}
4373
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004374component_test_m32_o0 () {
4375 # Build without optimization, so as to use portable C code (in a 32-bit
4376 # build) and not the i386-specific inline assembly.
4377 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
4378 scripts/config.py full
Jerry Yubdd96b92023-08-16 17:34:27 +08004379 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004380 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
4381
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004382 msg "test: i386, make, gcc -O0 (ASan build)"
4383 make test
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004384}
Gilles Peskine878cf602019-01-06 20:50:38 +00004385support_test_m32_o0 () {
4386 case $(uname -m) in
Pengyu Lvc92df3b2022-10-21 10:50:26 +00004387 amd64|x86_64) true;;
Gilles Peskine878cf602019-01-06 20:50:38 +00004388 *) false;;
4389 esac
4390}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004391
Gilles Peskineff0aee02021-10-05 09:36:03 +02004392component_test_m32_o2 () {
4393 # Build with optimization, to use the i386 specific inline assembly
4394 # and go faster for tests.
4395 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004396 scripts/config.py full
Jerry Yubdd96b92023-08-16 17:34:27 +08004397 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Gilles Peskineff0aee02021-10-05 09:36:03 +02004398 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004399
Gilles Peskineff0aee02021-10-05 09:36:03 +02004400 msg "test: i386, make, gcc -O2 (ASan build)"
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004401 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01004402
Gilles Peskineff0aee02021-10-05 09:36:03 +02004403 msg "test ssl-opt.sh, i386, make, gcc-O2"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004404 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01004405}
Gilles Peskinecf522222021-10-07 19:25:29 +02004406support_test_m32_o2 () {
Gilles Peskine878cf602019-01-06 20:50:38 +00004407 support_test_m32_o0 "$@"
4408}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004409
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004410component_test_m32_everest () {
4411 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004412 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Jerry Yubdd96b92023-08-16 17:34:27 +08004413 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Gilles Peskine8fd59422019-10-21 17:11:33 +02004414 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004415
4416 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
4417 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01004418
4419 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004420 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01004421
4422 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
4423 # Exclude some symmetric ciphers that are redundant here to gain time.
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02004424 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004425}
4426support_test_m32_everest () {
4427 support_test_m32_o0 "$@"
4428}
4429
Gilles Peskine8f073122018-11-27 15:58:47 +01004430component_test_mx32 () {
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004431 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004432 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02004433 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004434
4435 msg "test: 64-bit ILP32, make, gcc"
4436 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01004437}
Gilles Peskine878cf602019-01-06 20:50:38 +00004438support_test_mx32 () {
4439 case $(uname -m) in
4440 amd64|x86_64) true;;
4441 *) false;;
4442 esac
4443}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004444
Peter Kolbus60c6da22018-12-27 06:59:04 -06004445component_test_min_mpi_window_size () {
4446 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004447 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06004448 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4449 make
4450
4451 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
4452 make test
4453}
4454
Gilles Peskine8f073122018-11-27 15:58:47 +01004455component_test_have_int32 () {
4456 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004457 scripts/config.py unset MBEDTLS_HAVE_ASM
4458 scripts/config.py unset MBEDTLS_AESNI_C
4459 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08004460 scripts/config.py unset MBEDTLS_AESCE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01004461 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02004462
Gilles Peskine8f073122018-11-27 15:58:47 +01004463 msg "test: gcc, force 32-bit bignum limbs"
4464 make test
4465}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01004466
Gilles Peskine8f073122018-11-27 15:58:47 +01004467component_test_have_int64 () {
4468 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004469 scripts/config.py unset MBEDTLS_HAVE_ASM
4470 scripts/config.py unset MBEDTLS_AESNI_C
4471 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08004472 scripts/config.py unset MBEDTLS_AESCE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01004473 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01004474
Gilles Peskine8f073122018-11-27 15:58:47 +01004475 msg "test: gcc, force 64-bit bignum limbs"
4476 make test
4477}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004478
Gabor Mezeie256cc12023-07-26 17:28:48 +02004479component_test_have_int32_cmake_new_bignum () {
4480 msg "build: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
4481 scripts/config.py unset MBEDTLS_HAVE_ASM
4482 scripts/config.py unset MBEDTLS_AESNI_C
4483 scripts/config.py unset MBEDTLS_PADLOCK_C
4484 scripts/config.py unset MBEDTLS_AESCE_C
4485 scripts/config.py set MBEDTLS_TEST_HOOKS
Janos Follath2f045822023-07-31 10:57:16 +01004486 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Janos Follathf3135af2023-07-31 10:07:57 +01004487 make CC=gcc CFLAGS="$ASAN_CFLAGS -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32" LDFLAGS="$ASAN_CFLAGS"
Gabor Mezeie256cc12023-07-26 17:28:48 +02004488
4489 msg "test: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
4490 make test
4491}
4492
Gilles Peskine8f073122018-11-27 15:58:47 +01004493component_test_no_udbl_division () {
4494 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004495 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004496 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01004497 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004498
Gilles Peskine8f073122018-11-27 15:58:47 +01004499 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
4500 make test
4501}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004502
Gilles Peskine8f073122018-11-27 15:58:47 +01004503component_test_no_64bit_multiplication () {
4504 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004505 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004506 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01004507 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004508
Gilles Peskine8f073122018-11-27 15:58:47 +01004509 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
4510 make test
4511}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004512
Gilles Peskine3809f5f2020-11-09 15:40:05 +01004513component_test_no_strings () {
4514 msg "build: no strings" # ~10s
4515 scripts/config.py full
4516 # Disable options that activate a large amount of string constants.
4517 scripts/config.py unset MBEDTLS_DEBUG_C
4518 scripts/config.py unset MBEDTLS_ERROR_C
4519 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
4520 scripts/config.py unset MBEDTLS_VERSION_FEATURES
4521 make CFLAGS='-Werror -Os'
4522
4523 msg "test: no strings" # ~ 10s
4524 make test
4525}
4526
Hanno Beckerc5722d12020-10-09 11:10:42 +01004527component_test_no_x509_info () {
4528 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
4529 scripts/config.pl full
4530 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
4531 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
Gilles Peskineff0aee02021-10-05 09:36:03 +02004532 make CFLAGS='-Werror -O2'
Hanno Beckerc5722d12020-10-09 11:10:42 +01004533
4534 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
4535 make test
4536
4537 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004538 tests/ssl-opt.sh
Hanno Beckerc5722d12020-10-09 11:10:42 +01004539}
4540
Gilles Peskine8f073122018-11-27 15:58:47 +01004541component_build_arm_none_eabi_gcc () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02004542 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004543 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02004544 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 +02004545
Gilles Peskinee36fe812021-09-01 20:00:33 +02004546 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02004547 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01004548}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004549
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004550component_build_arm_linux_gnueabi_gcc_arm5vte () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02004551 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004552 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02004553 # Build for a target platform that's close to what Debian uses
4554 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
Dave Rodgman017a1992022-03-31 14:07:01 +01004555 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004556 # Build everything including programs, see for example
Dave Rodgman017a1992022-03-31 14:07:01 +01004557 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004558 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'
4559
Gilles Peskinee36fe812021-09-01 20:00:33 +02004560 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02004561 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t library/*.o
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004562}
4563support_build_arm_linux_gnueabi_gcc_arm5vte () {
4564 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
4565}
4566
4567component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02004568 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004569 scripts/config.py baremetal
4570 # This is an imperfect substitute for
4571 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnardae505ee2021-07-06 09:44:59 +02004572 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02004573 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 +02004574
Gilles Peskinee36fe812021-09-01 20:00:33 +02004575 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02004576 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02004577}
4578
Gilles Peskine6e2fb862020-04-30 23:00:53 +02004579component_build_arm_none_eabi_gcc_m0plus () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02004580 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
4581 scripts/config.py baremetal_size
Gilles Peskineaeedd742020-09-02 11:03:04 +02004582 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 +02004583
Gilles Peskinee36fe812021-09-01 20:00:33 +02004584 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02004585 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Manuel Pégourié-Gonnard67f80372023-06-06 13:01:18 +02004586 for lib in library/*.a; do
4587 echo "$lib:"
4588 ${ARM_NONE_EABI_GCC_PREFIX}size -t $lib | grep TOTALS
4589 done
Gilles Peskine6e2fb862020-04-30 23:00:53 +02004590}
4591
Gilles Peskine8f073122018-11-27 15:58:47 +01004592component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02004593 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004594 scripts/config.py baremetal
4595 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02004596 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 +01004597 echo "Checking that software 64-bit division is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004598 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01004599}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004600
Gilles Peskine8f073122018-11-27 15:58:47 +01004601component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02004602 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004603 scripts/config.py baremetal
4604 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02004605 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 +01004606 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004607 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01004608}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004609
Dave Rodgman8c315f22023-06-02 10:26:24 -04004610component_build_arm_clang_thumb () {
4611 # ~ 30s
4612
4613 scripts/config.py baremetal
4614
4615 msg "build: clang thumb 2, make"
4616 make clean
4617 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
4618
4619 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
4620 msg "build: clang thumb 1 -O0, make"
4621 make clean
4622 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
4623
4624 msg "build: clang thumb 1 -Os, make"
4625 make clean
4626 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
4627}
4628
Gilles Peskine8f073122018-11-27 15:58:47 +01004629component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02004630 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004631 scripts/config.py baremetal
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00004632 # armc[56] don't support SHA-512 intrinsics
4633 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Dave Rodgman2f386c52023-03-02 13:38:33 +00004634
Dave Rodgman0fddf822023-03-02 15:32:12 +00004635 # Stop armclang warning about feature detection for A64_CRYPTO.
4636 # With this enabled, the library does build correctly under armclang,
4637 # but in baremetal builds (as tested here), feature detection is
4638 # unavailable, and the user is notified via a #warning. So enabling
4639 # this feature would prevent us from building with -Werror on
4640 # armclang. Tracked in #7198.
Dave Rodgman2f386c52023-03-02 13:38:33 +00004641 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
4642
Hanno Beckerf0762e92022-07-15 12:08:19 +01004643 scripts/config.py set MBEDTLS_HAVE_ASM
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00004644
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004645 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02004646
4647 msg "size: ARM Compiler 5"
4648 "$ARMC5_FROMELF" -z library/*.o
4649
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004650 make clean
Andres AG87bb5772016-09-27 15:05:15 +01004651
Dave Rodgmanb45d58b2023-06-02 13:54:00 -04004652 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
Hanno Beckerf0762e92022-07-15 12:08:19 +01004653
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004654 # ARM Compiler 6 - Target ARMv7-A
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01004655 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02004656
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004657 # ARM Compiler 6 - Target ARMv7-M
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01004658 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m"
4659
4660 # ARM Compiler 6 - Target ARMv7-M+DSP
4661 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m+dsp"
Simon Butcher940737f2017-07-23 13:42:36 +02004662
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004663 # ARM Compiler 6 - Target ARMv8-A - AArch32
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01004664 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02004665
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004666 # ARM Compiler 6 - Target ARMv8-M
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01004667 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02004668
Tom Cosgrove6ec39ca2023-06-09 15:34:31 +01004669 # ARM Compiler 6 - Target ARMv8.2-A - AArch64
4670 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
4671
Dave Rodgmanb45d58b2023-06-02 13:54:00 -04004672 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
4673 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
4674
Dave Rodgman99318e62023-05-24 12:27:42 +01004675 # ARM Compiler 6 - Target Cortex-M0
4676 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
Gilles Peskine8f073122018-11-27 15:58:47 +01004677}
Tom Cosgrove6ec39ca2023-06-09 15:34:31 +01004678
Pengyu Lvdf070032023-02-24 16:03:31 +08004679support_build_armcc () {
Pengyu Lvc6298ad2023-03-01 10:31:29 +08004680 armc5_cc="$ARMC5_BIN_DIR/armcc"
4681 armc6_cc="$ARMC6_BIN_DIR/armclang"
4682 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
Pengyu Lvdf070032023-02-24 16:03:31 +08004683}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01004684
Jerry Yu81d5e1f2022-01-27 13:01:01 +08004685component_test_tls13_only () {
4686 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3, without MBEDTLS_SSL_PROTO_TLS1_2"
Ronald Cronc2e110f2022-11-22 09:01:46 +01004687 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Jerry Yuda5af222021-12-24 18:45:45 +08004688 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4689
Gilles Peskine4bb369c2022-10-29 17:44:19 +02004690 msg "test: TLS 1.3 only, all key exchange modes enabled"
4691 make test
Jerry Yubaa49342022-02-15 10:26:40 +08004692
Ronald Cronc3f43b62022-10-17 17:35:32 +02004693 msg "ssl-opt.sh: TLS 1.3 only, all key exchange modes enabled"
4694 tests/ssl-opt.sh
Jerry Yuda5af222021-12-24 18:45:45 +08004695}
4696
Ronald Cronc3f43b62022-10-17 17:35:32 +02004697component_test_tls13_only_psk () {
4698 msg "build: TLS 1.3 only from default, only PSK key exchange mode"
4699 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4700 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
4701 scripts/config.py unset MBEDTLS_ECDH_C
Przemek Stekiel0c231472023-06-14 11:12:45 +02004702 scripts/config.py unset MBEDTLS_DHM_C
Ronald Cronc3f43b62022-10-17 17:35:32 +02004703 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
4704 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
4705 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
4706 scripts/config.py unset MBEDTLS_ECDSA_C
4707 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00004708 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01004709 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Crone3dac4a2022-06-10 17:21:51 +02004710 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4711
Ronald Cronc3f43b62022-10-17 17:35:32 +02004712 msg "test_suite_ssl: TLS 1.3 only, only PSK key exchange mode enabled"
4713 cd tests; ./test_suite_ssl; cd ..
Ronald Crone3dac4a2022-06-10 17:21:51 +02004714
Ronald Cronc3f43b62022-10-17 17:35:32 +02004715 msg "ssl-opt.sh: TLS 1.3 only, only PSK key exchange mode enabled"
4716 tests/ssl-opt.sh
4717}
4718
4719component_test_tls13_only_ephemeral () {
4720 msg "build: TLS 1.3 only from default, only ephemeral key exchange mode"
4721 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4722 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
Xiaokang Qian2dbfeda2022-11-15 10:52:57 +00004723 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02004724 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4725
4726 msg "test_suite_ssl: TLS 1.3 only, only ephemeral key exchange mode"
4727 cd tests; ./test_suite_ssl; cd ..
4728
4729 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral key exchange mode"
4730 tests/ssl-opt.sh
4731}
4732
Przemek Stekiela01c2422023-06-13 10:46:48 +02004733component_test_tls13_only_ephemeral_ffdh () {
4734 msg "build: TLS 1.3 only from default, only ephemeral ffdh key exchange mode"
4735 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4736 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
4737 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
Przemek Stekielce05f542023-06-15 16:44:08 +02004738 scripts/config.py unset MBEDTLS_ECDH_C
4739
Przemek Stekiela01c2422023-06-13 10:46:48 +02004740 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4741
4742 msg "test_suite_ssl: TLS 1.3 only, only ephemeral ffdh key exchange mode"
4743 cd tests; ./test_suite_ssl; cd ..
4744
4745 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral ffdh key exchange mode"
4746 tests/ssl-opt.sh
4747}
4748
Ronald Cronc3f43b62022-10-17 17:35:32 +02004749component_test_tls13_only_psk_ephemeral () {
4750 msg "build: TLS 1.3 only from default, only PSK ephemeral key exchange mode"
4751 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4752 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4753 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
4754 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
4755 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
4756 scripts/config.py unset MBEDTLS_ECDSA_C
4757 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00004758 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01004759 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02004760 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4761
4762 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral key exchange mode"
4763 cd tests; ./test_suite_ssl; cd ..
4764
4765 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral key exchange mode"
4766 tests/ssl-opt.sh
4767}
4768
Przemek Stekiela01c2422023-06-13 10:46:48 +02004769component_test_tls13_only_psk_ephemeral_ffdh () {
4770 msg "build: TLS 1.3 only from default, only PSK ephemeral ffdh key exchange mode"
4771 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4772 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4773 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
4774 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
4775 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
4776 scripts/config.py unset MBEDTLS_ECDSA_C
4777 scripts/config.py unset MBEDTLS_PKCS1_V21
4778 scripts/config.py unset MBEDTLS_PKCS7_C
4779 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Przemek Stekielce05f542023-06-15 16:44:08 +02004780 scripts/config.py unset MBEDTLS_ECDH_C
Przemek Stekiela01c2422023-06-13 10:46:48 +02004781 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4782
4783 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
4784 cd tests; ./test_suite_ssl; cd ..
4785
4786 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
4787 tests/ssl-opt.sh
4788}
4789
Ronald Cronc3f43b62022-10-17 17:35:32 +02004790component_test_tls13_only_psk_all () {
4791 msg "build: TLS 1.3 only from default, without ephemeral key exchange mode"
4792 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4793 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
4794 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
4795 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
4796 scripts/config.py unset MBEDTLS_ECDSA_C
4797 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00004798 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01004799 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02004800 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4801
4802 msg "test_suite_ssl: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
4803 cd tests; ./test_suite_ssl; cd ..
4804
4805 msg "ssl-opt.sh: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
4806 tests/ssl-opt.sh
4807}
4808
4809component_test_tls13_only_ephemeral_all () {
4810 msg "build: TLS 1.3 only from default, without PSK key exchange mode"
4811 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
Ronald Cronc2e110f2022-11-22 09:01:46 +01004812 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02004813 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4814
4815 msg "test_suite_ssl: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
4816 cd tests; ./test_suite_ssl; cd ..
4817
4818 msg "ssl-opt.sh: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
4819 tests/ssl-opt.sh
Ronald Crone3dac4a2022-06-10 17:21:51 +02004820}
4821
Ronald Cron6f135e12021-12-08 16:57:54 +01004822component_test_tls13 () {
4823 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
4824 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01004825 scripts/config.py set MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
4826 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
Ronald Cronc2e110f2022-11-22 09:01:46 +01004827 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01004828 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4829 make
Ronald Cron6f135e12021-12-08 16:57:54 +01004830 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01004831 make test
Ronald Cron6f135e12021-12-08 16:57:54 +01004832 msg "ssl-opt.sh (TLS 1.3)"
Gilles Peskine827dbd92022-02-04 00:30:54 +01004833 tests/ssl-opt.sh
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01004834}
4835
Ronald Cron6f135e12021-12-08 16:57:54 +01004836component_test_tls13_no_compatibility_mode () {
4837 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
4838 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01004839 scripts/config.py unset MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
4840 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
Ronald Cronc2e110f2022-11-22 09:01:46 +01004841 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Hanno Beckera711f6e2020-05-04 12:03:51 +01004842 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4843 make
Ronald Cron6f135e12021-12-08 16:57:54 +01004844 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
Hanno Becker6c53ecc2021-08-01 19:20:10 +01004845 make test
Ronald Cron6f135e12021-12-08 16:57:54 +01004846 msg "ssl-opt.sh (TLS 1.3 no compatibility mode)"
Gilles Peskine827dbd92022-02-04 00:30:54 +01004847 tests/ssl-opt.sh
Hanno Becker6c53ecc2021-08-01 19:20:10 +01004848}
4849
Jan Bruckner151f6422023-02-10 12:45:19 +01004850component_test_tls13_only_record_size_limit () {
4851 msg "build: TLS 1.3 only from default, record size limit extension enabled"
4852 scripts/config.py set MBEDTLS_SSL_RECORD_SIZE_LIMIT
4853 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4854
4855 msg "test_suite_ssl: TLS 1.3 only, record size limit extension enabled"
4856 cd tests; ./test_suite_ssl; cd ..
4857
4858 msg "ssl-opt.sh: (TLS 1.3 only, record size limit extension tests only)"
4859 # Both the server and the client will currently abort the handshake when they encounter the
4860 # record size limit extension. There is no way to prevent gnutls-cli from sending the extension
4861 # which makes all G_NEXT_CLI + P_SRV tests fail. Thus, run only the tests for the this extension.
4862 tests/ssl-opt.sh -f "Record Size Limit"
4863}
4864
Gilles Peskine8f073122018-11-27 15:58:47 +01004865component_build_mingw () {
4866 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Jerry Yubdd96b92023-08-16 17:34:27 +08004867 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Andrzej Kurek232e8f92019-10-03 03:18:01 -04004868 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 +00004869
Gilles Peskine8f073122018-11-27 15:58:47 +01004870 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04004871 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 +01004872 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02004873
Gilles Peskine8f073122018-11-27 15:58:47 +01004874 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04004875 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
4876 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 +01004877 make WINDOWS_BUILD=1 clean
4878}
Jaeden Amero117b8a42019-04-17 15:19:26 +01004879support_build_mingw() {
Pengyu Lv51b5f002023-02-24 15:38:52 +08004880 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
4881 [0-5]*|"") false;;
Jaeden Amero117b8a42019-04-17 15:19:26 +01004882 *) true;;
4883 esac
4884}
Simon Butcher91aef332016-11-17 09:20:50 +00004885
Gilles Peskine8f073122018-11-27 15:58:47 +01004886component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004887 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004888 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004889 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
4890 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02004891
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004892 msg "test: main suites (MSan)" # ~ 10s
4893 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01004894
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004895 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004896 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01004897
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004898 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01004899
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004900 if [ "$MEMORY" -gt 0 ]; then
4901 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004902 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004903 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01004904}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01004905
Gilles Peskine69f190e2019-01-10 00:11:42 +01004906component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004907 msg "build: Release (clang)"
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01004908 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004909 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
4910 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00004911
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01004912 msg "test: main suites, Valgrind (default config)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004913 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00004914
Gilles Peskine636c26a2020-03-04 20:46:15 +01004915 # Optional parts (slow; currently broken on OS X because programs don't
4916 # seem to receive signals under valgrind on OS X).
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01004917 # These optional parts don't run on the CI.
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004918 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01004919 msg "test: ssl-opt.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004920 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004921 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00004922
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004923 if [ "$MEMORY" -gt 1 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01004924 msg "test: compat.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004925 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004926 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02004927
4928 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01004929 msg "test: context-info.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004930 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02004931 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01004932}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00004933
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01004934component_test_valgrind_psa () {
4935 msg "build: Release, full (clang)"
4936 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
4937 scripts/config.py full
4938 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
4939 make
4940
4941 msg "test: main suites, Valgrind (full config)"
4942 make memcheck
4943}
4944
Paul Elliott62dc3922021-11-25 17:29:40 +00004945support_test_cmake_out_of_source () {
4946 distrib_id=""
4947 distrib_ver=""
4948 distrib_ver_minor=""
4949 distrib_ver_major=""
4950
4951 # Attempt to parse lsb-release to find out distribution and version. If not
4952 # found this should fail safe (test is supported).
4953 if [[ -f /etc/lsb-release ]]; then
4954
4955 while read -r lsb_line; do
4956 case "$lsb_line" in
4957 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
4958 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
4959 esac
4960 done < /etc/lsb-release
4961
4962 distrib_ver_major="${distrib_ver%%.*}"
4963 distrib_ver="${distrib_ver#*.}"
4964 distrib_ver_minor="${distrib_ver%%.*}"
4965 fi
4966
4967 # Running the out of source CMake test on Ubuntu 16.04 using more than one
4968 # processor (as the CI does) can create a race condition whereby the build
4969 # fails to see a generated file, despite that file actually having been
4970 # generated. This problem appears to go away with 18.04 or newer, so make
4971 # the out of source tests unsupported on Ubuntu 16.04.
4972 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
4973}
4974
Gilles Peskine8f073122018-11-27 15:58:47 +01004975component_test_cmake_out_of_source () {
4976 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01004977 MBEDTLS_ROOT_DIR="$PWD"
4978 mkdir "$OUT_OF_SOURCE_DIR"
4979 cd "$OUT_OF_SOURCE_DIR"
Gilles Peskinedbf7b7e2021-10-07 19:34:57 +02004980 cmake -D CMAKE_BUILD_TYPE:String=Check "$MBEDTLS_ROOT_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01004981 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00004982
Gilles Peskine8f073122018-11-27 15:58:47 +01004983 msg "test: cmake 'out-of-source' build"
4984 make test
Gilles Peskinea841c2a2022-04-16 11:31:25 +02004985 # Check that ssl-opt.sh can find the test programs.
Gilles Peskine8f073122018-11-27 15:58:47 +01004986 # Also ensure that there are no error messages such as
4987 # "No such file or directory", which would indicate that some required
4988 # file is missing (ssl-opt.sh tolerates the absence of some files so
4989 # may exit with status 0 but emit errors).
Gilles Peskinea841c2a2022-04-16 11:31:25 +02004990 ./tests/ssl-opt.sh -f 'Default' >ssl-opt.out 2>ssl-opt.err
Gilles Peskine7393ec52022-04-15 22:43:38 +02004991 grep PASS ssl-opt.out
Gilles Peskinef7e956c2020-03-28 18:56:09 +01004992 cat ssl-opt.err >&2
4993 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004994 [ ! -s ssl-opt.err ]
Gilles Peskine7393ec52022-04-15 22:43:38 +02004995 rm ssl-opt.out ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01004996 cd "$MBEDTLS_ROOT_DIR"
4997 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01004998}
Andres AGdc192212016-08-31 17:33:13 +01004999
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005000component_test_cmake_as_subdirectory () {
5001 msg "build: cmake 'as-subdirectory' build"
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005002 cd programs/test/cmake_subproject
5003 cmake .
5004 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005005 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005006}
Gilles Peskinea3000992022-02-04 00:21:12 +01005007support_test_cmake_as_subdirectory () {
5008 support_test_cmake_out_of_source
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005009}
5010
Chris Kayd259e342021-03-25 16:03:25 +00005011component_test_cmake_as_package () {
5012 msg "build: cmake 'as-package' build"
Chris Kayd259e342021-03-25 16:03:25 +00005013 cd programs/test/cmake_package
5014 cmake .
5015 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005016 ./cmake_package
Chris Kayd259e342021-03-25 16:03:25 +00005017}
Gilles Peskinea3000992022-02-04 00:21:12 +01005018support_test_cmake_as_package () {
5019 support_test_cmake_out_of_source
Chris Kayd259e342021-03-25 16:03:25 +00005020}
5021
5022component_test_cmake_as_package_install () {
5023 msg "build: cmake 'as-installed-package' build"
Chris Kayd259e342021-03-25 16:03:25 +00005024 cd programs/test/cmake_package_install
5025 cmake .
5026 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005027 ./cmake_package_install
Chris Kayd259e342021-03-25 16:03:25 +00005028}
Gilles Peskinea3000992022-02-04 00:21:12 +01005029support_test_cmake_as_package_install () {
5030 support_test_cmake_out_of_source
Chris Kayd259e342021-03-25 16:03:25 +00005031}
5032
David Horstmann20550e32023-01-12 14:17:01 +00005033component_build_cmake_custom_config_file () {
David Horstmann969c1452023-01-31 10:34:44 +00005034 # Make a copy of config file to use for the in-tree test
5035 cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h
David Horstmann20550e32023-01-12 14:17:01 +00005036
5037 MBEDTLS_ROOT_DIR="$PWD"
5038 mkdir "$OUT_OF_SOURCE_DIR"
5039 cd "$OUT_OF_SOURCE_DIR"
5040
David Horstmann969c1452023-01-31 10:34:44 +00005041 # Build once to get the generated files (which need an intact config file)
David Horstmann20550e32023-01-12 14:17:01 +00005042 cmake "$MBEDTLS_ROOT_DIR"
5043 make
5044
5045 msg "build: cmake with -DMBEDTLS_CONFIG_FILE"
5046 scripts/config.py -w full_config.h full
David Horstmann969c1452023-01-31 10:34:44 +00005047 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005048 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR"
5049 make
5050
5051 msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
5052 # In the user config, disable one feature (for simplicity, pick a feature
5053 # that nothing else depends on).
5054 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
5055
5056 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR"
5057 make
5058 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5059
5060 rm -f user_config.h full_config.h
5061
5062 cd "$MBEDTLS_ROOT_DIR"
5063 rm -rf "$OUT_OF_SOURCE_DIR"
5064
5065 # Now repeat the test for an in-tree build:
5066
David Horstmann969c1452023-01-31 10:34:44 +00005067 # Restore config for the in-tree test
5068 mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005069
David Horstmann969c1452023-01-31 10:34:44 +00005070 # Build once to get the generated files (which need an intact config)
David Horstmann20550e32023-01-12 14:17:01 +00005071 cmake .
5072 make
5073
5074 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE"
5075 scripts/config.py -w full_config.h full
David Horstmann969c1452023-01-31 10:34:44 +00005076 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005077 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h .
5078 make
5079
5080 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
5081 # In the user config, disable one feature (for simplicity, pick a feature
5082 # that nothing else depends on).
5083 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
5084
5085 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h .
5086 make
5087 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5088
5089 rm -f user_config.h full_config.h
5090}
5091support_build_cmake_custom_config_file () {
5092 support_test_cmake_out_of_source
5093}
5094
5095
Gilles Peskine8f073122018-11-27 15:58:47 +01005096component_test_zeroize () {
5097 # Test that the function mbedtls_platform_zeroize() is not optimized away by
5098 # different combinations of compilers and optimization flags by using an
5099 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
5100 # system in all cases that the script fails, so we must manually search the
5101 # output to check whether the pass string is present and no failure strings
5102 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01005103
Gilles Peskine4976e822019-01-06 19:52:22 +00005104 # Don't try to disable ASLR. We don't care about ASLR here. We do care
5105 # about a spurious message if Gdb tries and fails, so suppress that.
5106 gdb_disable_aslr=
5107 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
5108 gdb_disable_aslr='set disable-randomization off'
5109 fi
5110
Gilles Peskine8f073122018-11-27 15:58:47 +01005111 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01005112 for compiler in clang gcc; do
5113 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
5114 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005115 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
5116 grep "The buffer was correctly zeroized" test_zeroize.log
5117 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01005118 rm -f test_zeroize.log
5119 make clean
5120 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01005121 done
Gilles Peskine8f073122018-11-27 15:58:47 +01005122}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005123
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005124component_test_psa_compliance () {
5125 msg "build: make, default config (out-of-box), libmbedcrypto.a only"
Bence Szépkútica9236b2021-10-25 19:29:07 +02005126 make -C library libmbedcrypto.a
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005127
5128 msg "unit test: test_psa_compliance.py"
5129 ./tests/scripts/test_psa_compliance.py
5130}
5131
5132support_test_psa_compliance () {
Bence Szépkútief0d02e2021-11-03 11:36:09 +01005133 # psa-compliance-tests only supports CMake >= 3.10.0
Bence Szépkútica9236b2021-10-25 19:29:07 +02005134 ver="$(cmake --version)"
5135 ver="${ver#cmake version }"
5136 ver_major="${ver%%.*}"
5137
5138 ver="${ver#*.}"
5139 ver_minor="${ver%%.*}"
5140
5141 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005142}
5143
Gilles Peskinec848d222022-12-09 12:23:35 +01005144component_check_code_style () {
5145 msg "Check C code style"
5146 ./scripts/code_style.py
David Horstmann92b5ac12022-11-10 18:30:52 +00005147}
5148
Gilles Peskinec848d222022-12-09 12:23:35 +01005149support_check_code_style() {
David Horstmann92b5ac12022-11-10 18:30:52 +00005150 case $(uncrustify --version) in
5151 *0.75.1*) true;;
5152 *) false;;
5153 esac
5154}
5155
Gilles Peskine8f073122018-11-27 15:58:47 +01005156component_check_python_files () {
5157 msg "Lint: Python scripts"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005158 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01005159}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005160
Joe Subbianid614c0b2021-07-29 11:18:29 +01005161component_check_test_helpers () {
5162 msg "unit test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02005163 # unittest writes out mundane stuff like number or tests run on stderr.
5164 # Our convention is to reserve stderr for actual errors, and write
5165 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005166 ./tests/scripts/test_generate_test_code.py 2>&1
Joe Subbianid614c0b2021-07-29 11:18:29 +01005167
Joe Subbiania25ffab2021-08-06 09:41:27 +01005168 msg "unit test: translate_ciphers.py"
5169 python3 -m unittest tests/scripts/translate_ciphers.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01005170}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005171
Jerry Yud767cc42023-03-31 15:03:55 +08005172
Gilles Peskine192c72f2017-12-21 15:59:21 +01005173################################################################
5174#### Termination
5175################################################################
5176
Gilles Peskine8f073122018-11-27 15:58:47 +01005177post_report () {
5178 msg "Done, cleaning up"
Gilles Peskinef83eb822020-03-30 20:11:39 +02005179 final_cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005180
Gilles Peskine8f073122018-11-27 15:58:47 +01005181 final_report
5182}
5183
5184
5185
5186################################################################
5187#### Run all the things
5188################################################################
5189
Gilles Peskine5d996822020-03-28 21:09:21 +01005190# Function invoked by --error-test to test error reporting.
5191pseudo_component_error_test () {
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005192 msg "Testing error reporting $error_test_i"
Gilles Peskine5d996822020-03-28 21:09:21 +01005193 if [ $KEEP_GOING -ne 0 ]; then
5194 echo "Expect three failing commands."
5195 fi
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005196 # If the component doesn't run in a subshell, changing error_test_i to an
5197 # invalid integer will cause an error in the loop that runs this function.
5198 error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
Gilles Peskineec135542021-08-02 23:14:03 +02005199 # Expected error: 'grep non_existent /dev/null -> 1'
Gilles Peskine5d996822020-03-28 21:09:21 +01005200 grep non_existent /dev/null
Gilles Peskineec135542021-08-02 23:14:03 +02005201 # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
Gilles Peskine5d996822020-03-28 21:09:21 +01005202 not grep -q . "$0"
Gilles Peskineec135542021-08-02 23:14:03 +02005203 # Expected error: 'make unknown_target -> 2'
Gilles Peskine5d996822020-03-28 21:09:21 +01005204 make unknown_target
5205 false "this should not be executed"
5206}
5207
Gilles Peskinee48351a2018-11-27 16:06:30 +01005208# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01005209run_component () {
Gilles Peskineffcdeff2018-12-04 12:49:28 +01005210 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02005211 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005212
5213 # Unconditionally create a seedfile that's sufficiently long.
5214 # Do this before each component, because a previous component may
5215 # have messed it up or shortened it.
Gilles Peskine88a07452021-07-08 19:03:50 +02005216 local dd_cmd
5217 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
5218 case $OSTYPE in
Tom Cosgrove226aca12022-03-16 14:11:07 +00005219 linux*|freebsd*|openbsd*) dd_cmd+=(status=none)
Gilles Peskine88a07452021-07-08 19:03:50 +02005220 esac
5221 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005222
Gilles Peskineec135542021-08-02 23:14:03 +02005223 # Run the component in a subshell, with error trapping and output
5224 # redirection set up based on the relevant options.
Gilles Peskinece266c42020-03-28 18:50:43 +01005225 if [ $KEEP_GOING -eq 1 ]; then
Gilles Peskineec135542021-08-02 23:14:03 +02005226 # We want to keep running if the subshell fails, so 'set -e' must
5227 # be off when the subshell runs.
Gilles Peskinece266c42020-03-28 18:50:43 +01005228 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02005229 fi
Gilles Peskinece266c42020-03-28 18:50:43 +01005230 (
5231 if [ $QUIET -eq 1 ]; then
5232 # msg() will be silenced, so just print the component name here.
5233 echo "${current_component#component_}"
5234 exec >/dev/null
5235 fi
5236 if [ $KEEP_GOING -eq 1 ]; then
5237 # Keep "set -e" off, and run an ERR trap instead to record failures.
5238 set -E
5239 trap err_trap ERR
5240 fi
5241 # The next line is what runs the component
5242 "$@"
5243 if [ $KEEP_GOING -eq 1 ]; then
5244 trap - ERR
5245 exit $last_failure_status
5246 fi
5247 )
5248 component_status=$?
5249 if [ $KEEP_GOING -eq 1 ]; then
5250 set -e
5251 if [ $component_status -ne 0 ]; then
5252 failure_count=$((failure_count + 1))
5253 fi
5254 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005255
5256 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01005257 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02005258 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01005259}
5260
5261# Preliminary setup
5262pre_check_environment
Tom Cosgrove730addc2023-06-09 14:20:18 +01005263pre_parse_command_line_for_dirs "$@"
Gilles Peskine8f073122018-11-27 15:58:47 +01005264pre_initialize_variables
5265pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01005266
Gilles Peskine878cf602019-01-06 20:50:38 +00005267pre_check_git
Gilles Peskine568f53a2021-07-12 18:16:01 +02005268pre_restore_files
Gilles Peskinef83eb822020-03-30 20:11:39 +02005269pre_back_up
Andrzej Kurekeb508712019-02-14 07:18:59 -05005270
Gilles Peskine878cf602019-01-06 20:50:38 +00005271build_status=0
5272if [ $KEEP_GOING -eq 1 ]; then
5273 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01005274fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02005275pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00005276pre_print_configuration
5277pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005278cleanup
David Horstmann76a77382023-08-17 17:32:26 +01005279if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +01005280 pre_generate_files
5281fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005282
Gilles Peskinebeb3a812019-01-06 22:11:25 +00005283# Run the requested tests.
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005284for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
Gilles Peskine5d996822020-03-28 21:09:21 +01005285 run_component pseudo_component_error_test
Gilles Peskine5d996822020-03-28 21:09:21 +01005286done
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005287unset error_test_i
Gilles Peskinebeb3a812019-01-06 22:11:25 +00005288for component in $RUN_COMPONENTS; do
5289 run_component "component_$component"
5290done
Gilles Peskine8f073122018-11-27 15:58:47 +01005291
5292# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00005293post_report