blob: 28767eb3f373318cc0c479a22a25745c2bc3e682 [file] [log] [blame]
Gilles Peskine62cf2e82020-03-27 16:35:23 +01001#! /usr/bin/env bash
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002
Simon Butcher3ea7f522016-03-07 23:22:10 +00003# all.sh
4#
Bence Szépkúti1e148272020-08-07 13:07:28 +02005# Copyright The Mbed TLS Contributors
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02006# SPDX-License-Identifier: Apache-2.0
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
Gilles Peskine192c72f2017-12-21 15:59:21 +010019
20
21
22################################################################
23#### Documentation
24################################################################
25
Simon Butcher3ea7f522016-03-07 23:22:10 +000026# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010027# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000028#
SimonB2e23c822016-04-16 21:54:39 +010029# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# Notes for users
32# ---------------
33#
SimonB2e23c822016-04-16 21:54:39 +010034# Warning: the test is destructive. It includes various build modes and
35# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010036# configuration. The following files must be committed into git:
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +020037# * include/mbedtls/mbedtls_config.h
Gilles Peskine636c26a2020-03-04 20:46:15 +010038# * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
39# programs/fuzz/Makefile
Gilles Peskine192c72f2017-12-21 15:59:21 +010040# After running this script, the CMake cache will be lost and CMake
41# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010042#
Gilles Peskine192c72f2017-12-21 15:59:21 +010043# The script assumes the presence of a number of tools:
44# * Basic Unix tools (Windows users note: a Unix-style find must be before
45# the Windows find in the PATH)
46# * Perl
47# * GNU Make
48# * CMake
49# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040050# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010051# * arm-gcc and mingw-gcc
52# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010053# * OpenSSL and GnuTLS command line tools, recent enough for the
Mateusz Starzykf5c53512021-04-15 13:28:52 +020054# interoperability tests. If they don't support old features which we want
55# to test, then a legacy version of these tools must be present as well
56# (search for LEGACY below).
Gilles Peskine192c72f2017-12-21 15:59:21 +010057# See the invocation of check_tools below for details.
58#
59# This script must be invoked from the toplevel directory of a git
60# working copy of Mbed TLS.
61#
Gilles Peskinece266c42020-03-28 18:50:43 +010062# The behavior on an error depends on whether --keep-going (alias -k)
63# is in effect.
64# * Without --keep-going: the script stops on the first error without
65# cleaning up. This lets you work in the configuration of the failing
66# component.
67# * With --keep-going: the script runs all requested components and
68# reports failures at the end. In particular the script always cleans
69# up on exit.
70#
Gilles Peskine192c72f2017-12-21 15:59:21 +010071# Note that the output is not saved. You may want to run
72# script -c tests/scripts/all.sh
73# or
74# tests/scripts/all.sh >all.log 2>&1
75#
76# Notes for maintainers
77# ---------------------
78#
Gilles Peskine8f073122018-11-27 15:58:47 +010079# The bulk of the code is organized into functions that follow one of the
80# following naming conventions:
81# * pre_XXX: things to do before running the tests, in order.
82# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010083# * component_check_XXX: quick tests that aren't worth parallelizing.
84# * component_build_XXX: build things but don't run them.
85# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000086# * support_XXX: if support_XXX exists and returns false then
87# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010088# * post_XXX: things to do after running the tests.
89# * other: miscellaneous support functions.
90#
Gilles Peskinec70637a2019-01-09 22:29:17 +010091# Each component must start by invoking `msg` with a short informative message.
92#
Gilles Peskinea681c592020-03-28 21:27:40 +010093# Warning: due to the way bash detects errors, the failure of a command
94# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
95#
Gilles Peskinece266c42020-03-28 18:50:43 +010096# Each component is executed in a separate shell process. The component
97# fails if any command in it returns a non-zero status.
98#
Gilles Peskinec70637a2019-01-09 22:29:17 +010099# The framework performs some cleanup tasks after each component. This
100# means that components can assume that the working directory is in a
101# cleaned-up state, and don't need to perform the cleanup themselves.
102# * Run `make clean`.
Bence Szépkúti414d6bd2021-06-28 14:11:11 +0100103# * Restore `include/mbedtls/mbedtls_config.h` from a backup made before running
Gilles Peskinec70637a2019-01-09 22:29:17 +0100104# the component.
Gilles Peskine636c26a2020-03-04 20:46:15 +0100105# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
106# `tests/Makefile` and `programs/fuzz/Makefile` from git.
107# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +0100108#
Gilles Peskine192c72f2017-12-21 15:59:21 +0100109# The tests are roughly in order from fastest to slowest. This doesn't
110# have to be exact, but in general you should add slower tests towards
111# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100112
113
114
115################################################################
116#### Initialization and command line parsing
117################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100118
Gilles Peskine36647802020-03-28 18:50:49 +0100119# Abort on errors (even on the left-hand side of a pipe).
120# Treat uninitialised variables as errors.
121set -e -o pipefail -u
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100122
Gilles Peskine076f7252022-08-30 21:02:44 +0200123# Enable ksh/bash extended file matching patterns
124shopt -s extglob
125
David Horstmann76a77382023-08-17 17:32:26 +0100126in_mbedtls_repo () {
David Horstmannd02b5f82023-08-29 09:53:52 +0100127 test -d include -a -d library -a -d programs -a -d tests
128}
129
Ronald Cron070e8652023-10-09 10:25:45 +0200130in_tf_psa_crypto_repo () {
David Horstmannd02b5f82023-08-29 09:53:52 +0100131 test -d include -a -d core -a -d drivers -a -d programs -a -d tests
David Horstmann9a6c45b2023-07-14 12:30:00 +0100132}
133
Gilles Peskine8f073122018-11-27 15:58:47 +0100134pre_check_environment () {
Ronald Cron070e8652023-10-09 10:25:45 +0200135 if in_mbedtls_repo || in_tf_psa_crypto_repo; then :; else
136 echo "Must be run from Mbed TLS / TF-PSA-Crypto root" >&2
Gilles Peskine8f073122018-11-27 15:58:47 +0100137 exit 1
138 fi
139}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100140
Gilles Peskine8f073122018-11-27 15:58:47 +0100141pre_initialize_variables () {
David Horstmann76a77382023-08-17 17:32:26 +0100142 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100143 CONFIG_H='include/mbedtls/mbedtls_config.h'
David Horstmann76a77382023-08-17 17:32:26 +0100144 else
145 CONFIG_H='drivers/builtin/include/mbedtls/mbedtls_config.h'
David Horstmann9a6c45b2023-07-14 12:30:00 +0100146 fi
John Durkopbd069d32020-10-31 22:14:03 -0700147 CRYPTO_CONFIG_H='include/psa/crypto_config.h'
Manuel Pégourié-Gonnard462e3a92022-12-27 12:35:11 +0100148 CONFIG_TEST_DRIVER_H='tests/include/test/drivers/config_test_driver.h'
Gilles Peskinef83eb822020-03-30 20:11:39 +0200149
150 # Files that are clobbered by some jobs will be backed up. Use a different
151 # suffix from auxiliary scripts so that all.sh and auxiliary scripts can
152 # independently decide when to remove the backup file.
153 backup_suffix='.all.bak'
154 # Files clobbered by config.py
Janos Follath2f045822023-07-31 10:57:16 +0100155 files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H $CONFIG_TEST_DRIVER_H"
David Horstmann76a77382023-08-17 17:32:26 +0100156 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100157 # Files clobbered by in-tree cmake
158 files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile"
159 fi
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200160
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200161 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100162 MEMORY=0
163 FORCE=0
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200164 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100165 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100166
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200167 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard54304472020-06-22 10:11:47 +0200168 #
169 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
170 # both values are kept in sync. If you change the value here because it
171 # breaks some tests, you'll definitely want to change it in
172 # basic-build-test.sh as well.
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200173 RELEASE_SEED=1
174
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200175 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200176 : ${MBEDTLS_TEST_PLATFORM="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200177 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200178 export MBEDTLS_TEST_PLATFORM
179
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000180 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100181 : ${OPENSSL:="openssl"}
182 : ${OPENSSL_LEGACY:="$OPENSSL"}
183 : ${OPENSSL_NEXT:="$OPENSSL"}
184 : ${GNUTLS_CLI:="gnutls-cli"}
185 : ${GNUTLS_SERV:="gnutls-serv"}
186 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
187 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
188 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
189 : ${ARMC5_BIN_DIR:=/usr/bin}
190 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskine6d061342020-04-30 18:19:32 +0200191 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +0200192 : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
Gowtham Suresh Kumar9da40b82023-07-31 16:38:10 +0100193 : ${CLANG_LATEST:="clang-latest"}
194 : ${CLANG_EARLIEST:="clang-earliest"}
195 : ${GCC_LATEST:="gcc-latest"}
196 : ${GCC_EARLIEST:="gcc-earliest"}
Gilles Peskine8f073122018-11-27 15:58:47 +0100197 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000198 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine050d2fc2021-09-30 18:24:21 +0200199 export MAKEFLAGS="-j$(all_sh_nproc)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100200 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000201
Gilles Peskine396853a2021-09-20 18:57:55 +0200202 # Include more verbose output for failing tests run by CMake or make
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000203 export CTEST_OUTPUT_ON_FAILURE=1
204
Gilles Peskine8fd59422019-10-21 17:11:33 +0200205 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Manuel Pégourié-Gonnardfe549a72022-11-30 10:42:03 +0100206 # default to -O2, use -Ox _after_ this if you want another level
Przemek Stekiel6efa6082023-05-31 09:38:21 +0200207 ASAN_CFLAGS='-O2 -Werror -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200208
Andrzej Kurek04bfe572023-06-27 10:02:09 -0400209 # Platform tests have an allocation that returns null
210 export ASAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurek026235c2023-07-05 08:32:43 -0400211 export MSAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurek04bfe572023-06-27 10:02:09 -0400212
Gilles Peskine878cf602019-01-06 20:50:38 +0000213 # Gather the list of available components. These are the functions
214 # defined in this script whose name starts with "component_".
Gowtham Suresh Kumar1e829a42023-07-28 16:41:21 +0100215 ALL_COMPONENTS=$(compgen -A function component_ | sed 's/component_//')
Gilles Peskine878cf602019-01-06 20:50:38 +0000216
217 # Exclude components that are not supported on this platform.
218 SUPPORTED_COMPONENTS=
219 for component in $ALL_COMPONENTS; do
220 case $(type "support_$component" 2>&1) in
221 *' function'*)
222 if ! support_$component; then continue; fi;;
223 esac
224 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
225 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100226}
Andres AG38495a32016-07-12 16:54:33 +0100227
Gilles Peskinea28db922019-01-10 00:05:18 +0100228# Test whether the component $1 is included in the command line patterns.
229is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100230{
Gilles Peskine03af6782021-08-06 11:35:17 +0200231 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
232 # only does word splitting.
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100233 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000234 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100235 set +f
236 case ${1#component_} in $pattern) return 0;; esac
237 done
238 set +f
239 return 1
240}
Andres AG7770ea82016-10-10 15:46:20 +0100241
Simon Butcher41eeccf2016-09-07 00:07:09 +0100242usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100243{
Gilles Peskine709346a2017-12-10 23:43:39 +0100244 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100245Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100246Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100247By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100248COMPONENT can be the name of a component or a shell wildcard pattern.
249
250Examples:
251 $0 "check_*"
252 Run all sanity checks.
253 $0 --no-armcc --except test_memsan
254 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100255
256Special options:
257 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000258 --list-all-components List all available test components and exit.
259 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100260
261General options:
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200262 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100263 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100264 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100265 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200266 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200267 --arm-none-eabi-gcc-prefix=<string>
268 Prefix for a cross-compiler for arm-none-eabi
269 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +0200270 --arm-linux-gnueabi-gcc-prefix=<string>
271 Prefix for a cross-compiler for arm-linux-gnueabi
272 (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100273 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine80ddb992021-08-06 11:51:59 +0200274 --restore First clean up the build tree, restoring backed up
275 files. Do not run any components unless they are
276 explicitly specified.
Gilles Peskine5d996822020-03-28 21:09:21 +0100277 --error-test Error test mode: run a failing function in addition
Gilles Peskine86f61292021-08-05 15:11:33 +0200278 to any specified component. May be repeated.
Gilles Peskinea28db922019-01-10 00:05:18 +0100279 --except Exclude the COMPONENTs listed on the command line,
280 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200281 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100282 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100283 --no-force Refuse to overwrite modified files (default).
284 --no-keep-going Stop at the first error (default).
285 --no-memory No additional memory tests (default).
Shaun Case8b0ecbc2021-12-20 21:14:10 -0800286 --no-quiet Print full output from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100287 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200288 --outcome-file=<path> File where test outcomes are written (not done if
289 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100290 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200291 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100292 -s|--seed Integer seed value to use for this test run.
293
294Tool path options:
295 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
296 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +0100297 --clang-earliest=<Clang_earliest_path> Earliest version of clang available
298 --clang-latest=<Clang_latest_path> Latest version of clang available
299 --gcc-earliest=<GCC_earliest_path> Earliest version of GCC available
300 --gcc-latest=<GCC_latest_path> Latest version of GCC available
Gilles Peskine709346a2017-12-10 23:43:39 +0100301 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
302 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
303 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
304 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
305 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
Mateusz Starzyk06b07fb2021-02-18 13:55:21 +0100306 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests..
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100307 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100308EOF
SimonB2e23c822016-04-16 21:54:39 +0100309}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100310
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200311# Cleanup before/after running a component.
312# Remove built files as well as the cmake cache/config.
313# Does not remove generated source files.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100314cleanup()
315{
David Horstmann76a77382023-08-17 17:32:26 +0100316 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100317 command make clean
318 fi
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200319
Gilles Peskine31b07e22018-03-21 12:15:06 +0100320 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000321 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100322 -iname CMakeFiles -exec rm -rf {} \+ -o \
323 \( -iname cmake_install.cmake -o \
324 -iname CTestTestfile.cmake -o \
Manuel Pégourié-Gonnardbfe54d72021-09-09 11:11:44 +0200325 -iname CMakeCache.txt -o \
326 -path './cmake/*.cmake' \) -exec rm -f {} \+
Gilles Peskine31b07e22018-03-21 12:15:06 +0100327 # Recover files overwritten by in-tree CMake builds
Gilles Peskine076f7252022-08-30 21:02:44 +0200328 rm -f include/Makefile include/mbedtls/Makefile programs/!(fuzz)/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200329
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100330 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
331 rm -rf programs/test/cmake_subproject/build
332 rm -f programs/test/cmake_subproject/Makefile
333 rm -f programs/test/cmake_subproject/cmake_subproject
334
Chris Kayd259e342021-03-25 16:03:25 +0000335 # Remove any artifacts from the component_test_cmake_as_package test.
336 rm -rf programs/test/cmake_package/build
337 rm -f programs/test/cmake_package/Makefile
338 rm -f programs/test/cmake_package/cmake_package
339
340 # Remove any artifacts from the component_test_cmake_as_installed_package test.
341 rm -rf programs/test/cmake_package_install/build
342 rm -f programs/test/cmake_package_install/Makefile
343 rm -f programs/test/cmake_package_install/cmake_package_install
344
Gilles Peskinef83eb822020-03-30 20:11:39 +0200345 # Restore files that may have been clobbered by the job
346 for x in $files_to_back_up; do
Gilles Peskinedd06efb2022-08-30 21:02:00 +0200347 if [[ -e "$x$backup_suffix" ]]; then
348 cp -p "$x$backup_suffix" "$x"
349 fi
Gilles Peskinef83eb822020-03-30 20:11:39 +0200350 done
351}
John Durkopbd069d32020-10-31 22:14:03 -0700352
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200353# Final cleanup when this script exits (except when exiting on a failure
354# in non-keep-going mode).
Gilles Peskinef83eb822020-03-30 20:11:39 +0200355final_cleanup () {
356 cleanup
357
358 for x in $files_to_back_up; do
359 rm -f "$x$backup_suffix"
360 done
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100361}
362
Gilles Peskine7c652162017-12-11 00:01:40 +0100363# Executed on exit. May be redefined depending on command line options.
364final_report () {
365 :
366}
367
368fatal_signal () {
Gilles Peskinef83eb822020-03-30 20:11:39 +0200369 final_cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100370 final_report $1
371 trap - $1
372 kill -$1 $$
373}
374
375trap 'fatal_signal HUP' HUP
376trap 'fatal_signal INT' INT
377trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200378
Gilles Peskine050d2fc2021-09-30 18:24:21 +0200379# Number of processors on this machine. Used as the default setting
380# for parallel make.
381all_sh_nproc ()
382{
383 {
384 nproc || # Linux
385 sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
386 sysctl -n hw.ncpu || # FreeBSD
387 echo 1
388 } 2>/dev/null
389}
390
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100391msg()
392{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100393 if [ -n "${current_component:-}" ]; then
394 current_section="${current_component#component_}: $1"
395 else
396 current_section="$1"
397 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200398
399 if [ $QUIET -eq 1 ]; then
400 return
401 fi
402
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100403 echo ""
404 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100405 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000406 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100407 echo "******************************************************************"
408}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100409
Gilles Peskine8f073122018-11-27 15:58:47 +0100410armc6_build_test()
411{
412 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100413
Gilles Peskine18487f62020-04-30 23:11:54 +0200414 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100415 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
Dave Rodgman1c232a82023-03-02 13:39:04 +0000416 WARNING_CFLAGS='-Werror -xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200417
418 msg "size: ARM Compiler 6 ($FLAGS)"
419 "$ARMC6_FROMELF" -z library/*.o
420
Gilles Peskine8f073122018-11-27 15:58:47 +0100421 make clean
422}
Andres AGa5cd9732016-10-17 15:23:10 +0100423
Andres AGd9eba4b2016-08-26 14:42:14 +0100424err_msg()
425{
426 echo "$1" >&2
427}
428
429check_tools()
430{
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200431 for tool in "$@"; do
432 if ! `type "$tool" >/dev/null 2>&1`; then
433 err_msg "$tool not found!"
Andres AGd9eba4b2016-08-26 14:42:14 +0100434 exit 1
435 fi
436 done
437}
438
Tom Cosgrove730addc2023-06-09 14:20:18 +0100439pre_parse_command_line_for_dirs () {
440 # Make an early pass through the options given, so we can set directories
441 # for Arm compilers, before SUPPORTED_COMPONENTS is determined.
442 while [ $# -gt 0 ]; do
443 case "$1" in
444 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
445 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
446 esac
447 shift
448 done
449}
450
Gilles Peskine8f073122018-11-27 15:58:47 +0100451pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000452 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100453 all_except=0
Gilles Peskine5d996822020-03-28 21:09:21 +0100454 error_test=0
Gilles Peskine80ddb992021-08-06 11:51:59 +0200455 restore_first=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000456 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100457
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000458 # Note that legacy options are ignored instead of being omitted from this
459 # list of options, so invocations that worked with previous version of
460 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100461 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100462 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200463 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200464 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +0200465 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000466 --armcc) no_armcc=;;
Tom Cosgrove730addc2023-06-09 14:20:18 +0100467 --armc5-bin-dir) shift; ;; # assignment to ARMC5_BIN_DIR done in pre_parse_command_line_for_dirs
468 --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 +0100469 --clang-earliest) shift; CLANG_EARLIEST="$1";;
470 --clang-latest) shift; CLANG_LATEST="$1";;
Gilles Peskine5d996822020-03-28 21:09:21 +0100471 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000472 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100473 --force|-f) FORCE=1;;
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +0100474 --gcc-earliest) shift; GCC_EARLIEST="$1";;
475 --gcc-latest) shift; GCC_LATEST="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100476 --gnutls-cli) shift; GNUTLS_CLI="$1";;
477 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
478 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
479 --gnutls-serv) shift; GNUTLS_SERV="$1";;
480 --help|-h) usage; exit;;
481 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000482 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
483 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100484 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200485 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000486 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100487 --no-force) FORCE=0;;
488 --no-keep-going) KEEP_GOING=0;;
489 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200490 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100491 --openssl) shift; OPENSSL="$1";;
492 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
493 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200494 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100495 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200496 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100497 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200498 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine80ddb992021-08-06 11:51:59 +0200499 --restore) restore_first=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100500 --seed|-s) shift; SEED="$1";;
501 -*)
502 echo >&2 "Unknown option: $1"
503 echo >&2 "Run $0 --help for usage."
504 exit 120
505 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000506 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100507 esac
508 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100509 done
SimonB2e23c822016-04-16 21:54:39 +0100510
Gilles Peskinea28db922019-01-10 00:05:18 +0100511 # With no list of components, run everything.
Gilles Peskine80ddb992021-08-06 11:51:59 +0200512 if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000513 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100514 fi
515
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000516 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
517 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100518 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000519 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100520 fi
SimonB2e23c822016-04-16 21:54:39 +0100521
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200522 # Error out if an explicitly requested component doesn't exist.
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100523 if [ $all_except -eq 0 ]; then
524 unsupported=0
Gilles Peskine03af6782021-08-06 11:35:17 +0200525 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
526 # only does word splitting.
Gilles Peskine1d475b62021-08-03 13:43:36 +0200527 set -f
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100528 for component in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine1d475b62021-08-03 13:43:36 +0200529 set +f
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200530 # If the requested name includes a wildcard character, don't
531 # check it. Accept wildcard patterns that don't match anything.
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100532 case $component in
533 *[*?\[]*) continue;;
534 esac
535 case " $SUPPORTED_COMPONENTS " in
536 *" $component "*) :;;
537 *)
538 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
539 unsupported=$((unsupported + 1));;
540 esac
541 done
Gilles Peskine1d475b62021-08-03 13:43:36 +0200542 set +f
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100543 if [ $unsupported -ne 0 ]; then
544 exit 2
545 fi
546 fi
547
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000548 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100549 RUN_COMPONENTS=
550 for component in $SUPPORTED_COMPONENTS; do
551 if is_component_included "$component"; [ $? -eq $all_except ]; then
552 RUN_COMPONENTS="$RUN_COMPONENTS $component"
553 fi
554 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000555
556 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000557 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100558}
SimonB2e23c822016-04-16 21:54:39 +0100559
Gilles Peskine8f073122018-11-27 15:58:47 +0100560pre_check_git () {
561 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100562 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100563 git checkout-index -f -q $CONFIG_H
564 cleanup
565 else
SimonB2e23c822016-04-16 21:54:39 +0100566
Gilles Peskine8f073122018-11-27 15:58:47 +0100567 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
568 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
569 echo "You can either delete this directory manually, or force the test by rerunning"
570 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
571 exit 1
572 fi
573
Ronald Cron7a93ac52023-07-20 09:49:12 +0200574 if ! git diff --quiet "$CONFIG_H"; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100575 err_msg "Warning - the configuration file '$CONFIG_H' has been edited. "
Gilles Peskine8f073122018-11-27 15:58:47 +0100576 echo "You can either delete or preserve your work, or force the test by rerunning the"
577 echo "script as: $0 --force"
578 exit 1
579 fi
SimonB2e23c822016-04-16 21:54:39 +0100580 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500581}
582
Gilles Peskine568f53a2021-07-12 18:16:01 +0200583pre_restore_files () {
584 # If the makefiles have been generated by a framework such as cmake,
585 # restore them from git. If the makefiles look like modifications from
586 # the ones checked into git, take care not to modify them. Whatever
587 # this function leaves behind is what the script will restore before
588 # each component.
589 case "$(head -n1 Makefile)" in
590 *[Gg]enerated*)
591 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
592 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
593 ;;
594 esac
595}
596
Gilles Peskinef83eb822020-03-30 20:11:39 +0200597pre_back_up () {
598 for x in $files_to_back_up; do
599 cp -p "$x" "$x$backup_suffix"
600 done
601}
602
Gilles Peskine8f073122018-11-27 15:58:47 +0100603pre_setup_keep_going () {
Gilles Peskinece266c42020-03-28 18:50:43 +0100604 failure_count=0 # Number of failed components
605 last_failure_status=0 # Last failure status in this component
606
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100607 # See err_trap
608 previous_failure_status=0
609 previous_failed_command=
610 previous_failure_funcall_depth=0
Gilles Peskinea681c592020-03-28 21:27:40 +0100611 unset report_failed_command
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100612
Gilles Peskine7c652162017-12-11 00:01:40 +0100613 start_red=
614 end_color=
615 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100616 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100617 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
618 start_red=$(printf '\033[31m')
619 end_color=$(printf '\033[0m')
620 ;;
621 esac
622 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100623
624 # Keep a summary of failures in a file. We'll print it out at the end.
625 failure_summary_file=$PWD/all-sh-failures-$$.log
626 : >"$failure_summary_file"
627
628 # Whether it makes sense to keep a component going after the specified
629 # command fails (test command) or not (configure or build).
Gilles Peskine03af6782021-08-06 11:35:17 +0200630 # This function normally receives the failing simple command
631 # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
632 # this is passed instead.
Gilles Peskinece266c42020-03-28 18:50:43 +0100633 # This doesn't have to be 100% accurate: all failures are recorded anyway.
Gilles Peskinec111e242021-08-02 23:29:53 +0200634 # False positives result in running things that can't be expected to
635 # work. False negatives result in things not running after something else
636 # failed even though they might have given useful feedback.
Gilles Peskinece266c42020-03-28 18:50:43 +0100637 can_keep_going_after_failure () {
638 case "$1" in
639 "msg "*) false;;
Gilles Peskinec111e242021-08-02 23:29:53 +0200640 "cd "*) false;;
641 *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
642 *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
643 *make*check*) true;;
644 "grep "*) true;;
645 "[ "*) true;;
646 "! "*) true;;
Gilles Peskinece266c42020-03-28 18:50:43 +0100647 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100648 esac
649 }
Gilles Peskinece266c42020-03-28 18:50:43 +0100650
651 # This function runs if there is any error in a component.
652 # It must either exit with a nonzero status, or set
653 # last_failure_status to a nonzero value.
654 err_trap () {
655 # Save $? (status of the failing command). This must be the very
656 # first thing, before $? is overridden.
657 last_failure_status=$?
Gilles Peskinea681c592020-03-28 21:27:40 +0100658 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskinece266c42020-03-28 18:50:43 +0100659
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100660 if [[ $last_failure_status -eq $previous_failure_status &&
661 "$failed_command" == "$previous_failed_command" &&
662 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
663 then
664 # The same command failed twice in a row, but this time one level
665 # less deep in the function call stack. This happens when the last
666 # command of a function returns a nonzero status, and the function
667 # returns that same status. Ignore the second failure.
668 previous_failure_funcall_depth=${#FUNCNAME[@]}
669 return
670 fi
671 previous_failure_status=$last_failure_status
672 previous_failed_command=$failed_command
673 previous_failure_funcall_depth=${#FUNCNAME[@]}
674
Gilles Peskinece266c42020-03-28 18:50:43 +0100675 text="$current_section: $failed_command -> $last_failure_status"
676 echo "${start_red}^^^^$text^^^^${end_color}" >&2
677 echo "$text" >>"$failure_summary_file"
678
679 # If the command is fatal (configure or build command), stop this
680 # component. Otherwise (test command) keep the component running
681 # (run more tests from the same build).
682 if ! can_keep_going_after_failure "$failed_command"; then
683 exit $last_failure_status
684 fi
685 }
686
Gilles Peskine7c652162017-12-11 00:01:40 +0100687 final_report () {
688 if [ $failure_count -gt 0 ]; then
689 echo
690 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskinece266c42020-03-28 18:50:43 +0100691 echo "${start_red}FAILED: $failure_count components${end_color}"
692 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100693 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
694 elif [ -z "${1-}" ]; then
695 echo "SUCCESS :)"
696 fi
697 if [ -n "${1-}" ]; then
698 echo "Killed by SIG$1."
699 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100700 rm -f "$failure_summary_file"
701 if [ $failure_count -gt 0 ]; then
702 exit 1
703 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100704 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100705}
706
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200707# record_status() and if_build_succeeded() are kept temporarily for backward
708# compatibility. Don't use them in new components.
Gilles Peskinece266c42020-03-28 18:50:43 +0100709record_status () {
710 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100711}
Gilles Peskine7c652162017-12-11 00:01:40 +0100712if_build_succeeded () {
Gilles Peskinece266c42020-03-28 18:50:43 +0100713 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100714}
715
Gilles Peskinea681c592020-03-28 21:27:40 +0100716# '! true' does not trigger the ERR trap. Arrange to trigger it, with
717# a reasonably informative error message (not just "$@").
718not () {
719 if "$@"; then
720 report_failed_command="! $*"
721 false
722 unset report_failed_command
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200723 fi
724}
725
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200726pre_prepare_outcome_file () {
727 case "$MBEDTLS_TEST_OUTCOME_FILE" in
728 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
729 esac
730 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
731 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
732 fi
733}
734
Gilles Peskine8f073122018-11-27 15:58:47 +0100735pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200736 if [ $QUIET -eq 1 ]; then
737 return
738 fi
739
Gilles Peskine8f073122018-11-27 15:58:47 +0100740 msg "info: $0 configuration"
741 echo "MEMORY: $MEMORY"
742 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200743 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100744 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100745 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100746 echo "OPENSSL: $OPENSSL"
747 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
748 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
749 echo "GNUTLS_CLI: $GNUTLS_CLI"
750 echo "GNUTLS_SERV: $GNUTLS_SERV"
751 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
752 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
753 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
754 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
755}
Andres AG7770ea82016-10-10 15:46:20 +0100756
Andres AGd9eba4b2016-08-26 14:42:14 +0100757# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100758pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000759 # Build the list of variables to pass to output_env.sh.
760 set env
SimonB2e23c822016-04-16 21:54:39 +0100761
Gilles Peskine87964262019-01-06 22:40:00 +0000762 case " $RUN_COMPONENTS " in
763 # Require OpenSSL and GnuTLS if running any tests (as opposed to
764 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
765 # is a good enough approximation in practice.
766 *" test_"*)
767 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
768 # and ssl-opt.sh, we just export the variables they require.
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +0100769 export OPENSSL="$OPENSSL"
Gilles Peskine87964262019-01-06 22:40:00 +0000770 export GNUTLS_CLI="$GNUTLS_CLI"
771 export GNUTLS_SERV="$GNUTLS_SERV"
772 # Avoid passing --seed flag in every call to ssl-opt.sh
773 if [ -n "${SEED-}" ]; then
774 export SEED
775 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000776 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
777 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
778 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
779 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000780 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
781 "$GNUTLS_CLI" "$GNUTLS_SERV" \
782 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
783 ;;
784 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200785
Gilles Peskine87964262019-01-06 22:40:00 +0000786 case " $RUN_COMPONENTS " in
787 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
788 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100789
Gilles Peskine87964262019-01-06 22:40:00 +0000790 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200791 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000792 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100793
Gilles Peskine87964262019-01-06 22:40:00 +0000794 case " $RUN_COMPONENTS " in
795 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
796 esac
797
798 case " $RUN_COMPONENTS " in
799 *" test_zeroize "*) check_tools "gdb";;
800 esac
801
802 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000803 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000804 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
805 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200806 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000807 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
808 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200809 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
810 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
811 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000812 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000813
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200814 # past this point, no call to check_tool, only printing output
815 if [ $QUIET -eq 1 ]; then
816 return
817 fi
818
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000819 msg "info: output_env.sh"
820 case $RUN_COMPONENTS in
821 *_armcc*)
822 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
823 *) set "$@" RUN_ARMCC=0;;
824 esac
825 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100826}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100827
Gilles Peskine1570b592021-04-22 01:10:12 +0200828pre_generate_files() {
Manuel Pégourié-Gonnard87db8a22021-06-18 13:30:14 +0200829 # since make doesn't have proper dependencies, remove any possibly outdate
830 # file that might be around before generating fresh ones
831 make neat
Gilles Peskine72385032021-07-08 19:07:07 +0200832 if [ $QUIET -eq 1 ]; then
Gilles Peskine75301632021-08-05 15:10:47 +0200833 make generated_files >/dev/null
Gilles Peskine72385032021-07-08 19:07:07 +0200834 else
835 make generated_files
836 fi
Gilles Peskine1570b592021-04-22 01:10:12 +0200837}
838
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200839################################################################
840#### Helpers for components using libtestdriver1
841################################################################
Gilles Peskine192c72f2017-12-21 15:59:21 +0100842
Manuel Pégourié-Gonnardf5c5d972023-06-06 11:14:57 +0200843# How to use libtestdriver1
844# -------------------------
845#
846# 1. Define the list algorithms and key types to accelerate,
847# designated the same way as PSA_WANT_ macros but without PSA_WANT_.
848# Examples:
849# - loc_accel_list="ALG_JPAKE"
850# - loc_accel_list="ALG_FFDH KEY_TYPE_DH_KEY_PAIR KEY_TYPE_DH_PUBLIC_KEY"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200851# 2. Make configurations changes for the driver and/or main libraries.
852# 2a. Call helper_libtestdriver1_adjust_config <base>, where the argument
853# can be either "default" to start with the default config, or a name
854# supported by scripts/config.py (for example, "full"). This selects
Manuel Pégourié-Gonnard2336c8e2023-06-12 17:17:54 +0200855# the base to use, and makes common adjustments.
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200856# 2b. If desired, adjust the PSA_WANT symbols in psa/crypto_config.h.
857# These changes affect both the driver and the main libraries.
858# (Note: they need to have the same set of PSA_WANT symbols, as that
859# determines the ABI between them.)
860# 2c. Adjust MBEDTLS_ symbols in mbedtls_config.h. This only affects the
861# main libraries. Typically, you want to disable the module(s) that are
862# being accelerated. You may need to also disable modules that depend
863# on them or options that are not supported with drivers.
864# 2d. On top of psa/crypto_config.h, the driver library uses its own config
865# file: tests/include/test/drivers/config_test_driver.h. You usually
866# don't need to edit it: using loc_extra_list (see below) is preferred.
867# However, when there's no PSA symbol for what you want to enable,
868# calling scripts/config.py on this file remains the only option.
869# 3. Build the driver library, then the main libraries, test, and programs.
870# 3a. Call helper_libtestdriver1_make_drivers "$loc_accel_list". You may
871# need to enable more algorithms here, typically hash algorithms when
872# accelerating some signature algorithms (ECDSA, RSAv2). This is done
873# by passing a 2nd argument listing the extra algorithms.
874# Example:
875# loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
876# helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
877# 4b. Call helper_libtestdriver1_make_main "$loc_accel_list". Any
878# additional arguments will be passed to make: this can be useful if
879# you don't want to build everything when iterating during development.
880# Example:
881# helper_libtestdriver1_make_main "$loc_accel_list" -C tests test_suite_foo
882# 4. Run the tests you want.
Manuel Pégourié-Gonnardf5c5d972023-06-06 11:14:57 +0200883
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200884# Adjust the configuration - for both libtestdriver1 and main library,
885# as they should have the same PSA_WANT macros.
886helper_libtestdriver1_adjust_config() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200887 base_config=$1
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200888 # Select the base configuration
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200889 if [ "$base_config" != "default" ]; then
890 scripts/config.py "$base_config"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200891 fi
892
893 # Enable PSA-based config (necessary to use drivers)
894 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
895
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200896 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
897 # partial support for cipher operations in the driver test library.
Ronald Cron6b49b552023-07-20 09:57:54 +0200898 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_STREAM_CIPHER
899 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
Manuel Pégourié-Gonnard2336c8e2023-06-12 17:17:54 +0200900
901 # Dynamic secure element support is a deprecated feature and needs to be disabled here.
902 # This is done to have the same form of psa_key_attributes_s for libdriver and library.
903 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200904}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100905
Valerio Settib2fd6732023-08-15 17:10:47 +0200906# When called with no parameter this function disables all builtin curves.
Valerio Setti4ca250b2023-09-04 14:01:41 +0200907# The function optionally accepts 1 parameter: a space-separated list of the
908# curves that should be kept enabled.
Valerio Settib2fd6732023-08-15 17:10:47 +0200909helper_disable_builtin_curves() {
910 allowed_list="${1:-}"
911 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
912
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200913 for curve in $allowed_list; do
914 scripts/config.py set $curve
Valerio Settib2fd6732023-08-15 17:10:47 +0200915 done
916}
917
918# Helper returning the list of supported elliptic curves from CRYPTO_CONFIG_H,
919# without the "PSA_WANT_" prefix. This becomes handy for accelerating curves
920# in the following helpers.
921helper_get_psa_curve_list () {
922 loc_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200923 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
924 loc_list="$loc_list $item"
Valerio Settib2fd6732023-08-15 17:10:47 +0200925 done
926
927 echo "$loc_list"
928}
929
930# Get the list of uncommented PSA_WANT_KEY_TYPE_xxx_ from CRYPTO_CONFIG_H. This
Valerio Setti0a342c92023-09-01 09:12:31 +0200931# is useful to easily get a list of key type symbols to accelerate.
Valerio Settib2fd6732023-08-15 17:10:47 +0200932# The function accepts a single argument which is the key type: ECC, DH, RSA.
Valerio Setti0a342c92023-09-01 09:12:31 +0200933helper_get_psa_key_type_list() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200934 key_type="$1"
Valerio Settib2fd6732023-08-15 17:10:47 +0200935 loc_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200936 for item in $(sed -n "s/^#define PSA_WANT_\(KEY_TYPE_${key_type}_[0-9A-Z_a-z]*\).*/\1/p" <"$CRYPTO_CONFIG_H"); do
Valerio Settib2fd6732023-08-15 17:10:47 +0200937 # Skip DERIVE for elliptic keys since there is no driver dispatch for
938 # it so it cannot be accelerated.
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200939 if [ "$item" != "KEY_TYPE_ECC_KEY_PAIR_DERIVE" ]; then
940 loc_list="$loc_list $item"
Valerio Settib2fd6732023-08-15 17:10:47 +0200941 fi
942 done
943
944 echo "$loc_list"
945}
946
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +0200947# Build the drivers library libtestdriver1.a (with ASan).
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +0200948#
949# Parameters:
950# 1. a space-separated list of things to accelerate;
951# 2. optional: a space-separate list of things to also support.
952# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
953helper_libtestdriver1_make_drivers() {
954 loc_accel_flags=$( echo "$1 ${2-}" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
955 make -C tests libtestdriver1.a CFLAGS=" $ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
956}
957
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +0200958# Build the main libraries, programs and tests,
959# linking to the drivers library (with ASan).
960#
961# Parameters:
962# 1. a space-separated list of things to accelerate;
963# *. remaining arguments if any are passed directly to make
964# (examples: lib, -C tests test_suite_xxx, etc.)
965# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
966helper_libtestdriver1_make_main() {
967 loc_accel_list=$1
968 shift
969
970 # we need flags both with and without the LIBTESTDRIVER1_ prefix
971 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
972 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
973 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" "$@"
974}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100975
976################################################################
977#### Basic checks
978################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100979
980#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200981# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100982#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100983# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200984# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100985# 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 +0200986# time, so start with a GCC build).
987# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100988#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100989# Indicative running times are given for reference.
990
Gilles Peskine8f073122018-11-27 15:58:47 +0100991component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200992 msg "Check: recursion.pl" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200993 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100994}
Janos Follathb72c6782016-07-19 14:54:17 +0100995
Gilles Peskine67debb62021-05-18 16:09:50 +0200996component_check_generated_files () {
997 msg "Check: check-generated-files, files generated with make" # 2s
998 make generated_files
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200999 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +02001000
1001 msg "Check: check-generated-files -u, files present" # 2s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001002 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +02001003 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001004 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +02001005
1006 msg "Check: check-generated-files -u, files absent" # 2s
1007 command make neat
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001008 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +02001009 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001010 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +02001011
1012 # This component ends with the generated files present in the source tree.
1013 # This is necessary for subsequent components!
1014}
1015
Gilles Peskine8f073122018-11-27 15:58:47 +01001016component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001017 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001018 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001019}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001020
Gilles Peskine8f073122018-11-27 15:58:47 +01001021component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001022 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001023 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +01001024}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001025
Gilles Peskine30e0bb42020-05-10 17:40:49 +02001026component_check_changelog () {
1027 msg "Check: changelog entries" # < 1s
1028 rm -f ChangeLog.new
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001029 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +02001030 if [ -e ChangeLog.new ]; then
1031 # Show the diff for information. It isn't an error if the diff is
1032 # non-empty.
1033 diff -u ChangeLog ChangeLog.new || true
1034 rm ChangeLog.new
1035 fi
1036}
1037
Gilles Peskine8f073122018-11-27 15:58:47 +01001038component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001039 msg "Check: declared and exported names (builds the library)" # < 3s
Yuto Takanoc3a6f632021-09-24 18:02:56 +01001040 tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +01001041}
Darryl Greena07039c2018-03-13 16:48:16 +00001042
Gilles Peskine895868b2019-09-19 21:30:05 +02001043component_check_test_cases () {
1044 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001045 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001046 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001047 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001048 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001049 fi
Gilles Peskine031114d2022-12-15 14:46:31 +01001050 tests/scripts/check_test_cases.py -q $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001051 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +02001052}
1053
Gilles Peskine8f073122018-11-27 15:58:47 +01001054component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001055 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001056 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001057}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001058
Gilles Peskine192c72f2017-12-21 15:59:21 +01001059
Gilles Peskine636c26a2020-03-04 20:46:15 +01001060
Gilles Peskine192c72f2017-12-21 15:59:21 +01001061################################################################
1062#### Build and test many configurations and targets
1063################################################################
1064
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001065component_test_default_out_of_box () {
1066 msg "build: make, default config (out-of-box)" # ~1min
1067 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02001068 # Disable fancy stuff
1069 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001070
1071 msg "test: main suites make, default config (out-of-box)" # ~10s
1072 make test
1073
1074 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001075 programs/test/selftest
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001076}
1077
Gilles Peskine8f073122018-11-27 15:58:47 +01001078component_test_default_cmake_gcc_asan () {
1079 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +01001080 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1081 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001082
Gilles Peskine8f073122018-11-27 15:58:47 +01001083 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
1084 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001085
Gilles Peskine97bea012020-04-23 23:37:45 +02001086 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001087 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +02001088
Gilles Peskine8f073122018-11-27 15:58:47 +01001089 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001090 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001091
Gilles Peskine8f073122018-11-27 15:58:47 +01001092 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001093 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001094
1095 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001096 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001097}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001098
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001099component_test_default_cmake_gcc_asan_new_bignum () {
1100 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Janos Follath2f045822023-07-31 10:57:16 +01001101 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001102 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Janos Follath82823b22023-07-27 12:25:05 +01001103 make
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001104
1105 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
1106 make test
1107
1108 msg "test: selftest (ASan build)" # ~ 10s
1109 programs/test/selftest
1110
1111 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
1112 tests/ssl-opt.sh
1113
1114 msg "test: compat.sh (ASan build)" # ~ 6 min
1115 tests/compat.sh
1116
1117 msg "test: context-info.sh (ASan build)" # ~ 15 sec
1118 tests/context-info.sh
1119}
1120
Hanno Becker01635512019-02-26 14:27:09 +00001121component_test_full_cmake_gcc_asan () {
1122 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001123 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +00001124 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1125 make
1126
1127 msg "test: main suites (inc. selftests) (full config, ASan build)"
1128 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01001129
Gilles Peskine97bea012020-04-23 23:37:45 +02001130 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001131 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +02001132
Gilles Peskine636c26a2020-03-04 20:46:15 +01001133 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001134 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001135
1136 msg "test: compat.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001137 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001138
1139 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001140 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001141}
1142
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001143
1144component_test_full_cmake_gcc_asan_new_bignum () {
1145 msg "build: full config, cmake, gcc, ASan"
1146 scripts/config.py full
Janos Follath2f045822023-07-31 10:57:16 +01001147 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001148 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Janos Follath82823b22023-07-27 12:25:05 +01001149 make
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001150
1151 msg "test: main suites (inc. selftests) (full config, ASan build)"
1152 make test
1153
1154 msg "test: selftest (ASan build)" # ~ 10s
1155 programs/test/selftest
1156
1157 msg "test: ssl-opt.sh (full config, ASan build)"
1158 tests/ssl-opt.sh
1159
1160 msg "test: compat.sh (full config, ASan build)"
1161 tests/compat.sh
1162
1163 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
1164 tests/context-info.sh
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001165}
1166
Ronald Cronc3623db2020-10-29 10:51:32 +01001167component_test_psa_crypto_key_id_encodes_owner () {
Andrzej Kurek03e01462022-01-03 12:53:24 +01001168 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
Ronald Cronc3623db2020-10-29 10:51:32 +01001169 scripts/config.py full
Ronald Cronc3623db2020-10-29 10:51:32 +01001170 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1171 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1172 make
1173
1174 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
1175 make test
1176}
1177
Gilles Peskinea3548672021-06-17 11:37:52 +02001178# check_renamed_symbols HEADER LIB
1179# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
1180# name is LIB.
1181check_renamed_symbols () {
1182 ! nm "$2" | sed 's/.* //' |
1183 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
1184}
1185
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001186component_build_psa_crypto_spm () {
Andrzej Kurek03e01462022-01-03 12:53:24 +01001187 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001188 scripts/config.py full
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001189 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
1190 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1191 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
1192 # We can only compile, not link, since our test and sample programs
1193 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
1194 # is active.
1195 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskinea3548672021-06-17 11:37:52 +02001196
1197 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
1198 # version is not present.
1199 echo "Checking for renamed symbols in the library"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001200 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001201}
1202
Ronald Cron336678b2021-01-28 17:54:24 +01001203component_test_psa_crypto_client () {
1204 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
1205 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1206 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1207 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
Raef Colesb4568c52022-09-28 17:11:42 +01001208 scripts/config.py unset MBEDTLS_LMS_C
1209 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Ronald Cron336678b2021-01-28 17:54:24 +01001210 make
1211
1212 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
1213 make test
1214}
1215
Jaeden Amero424fa932021-05-14 08:34:32 +01001216component_test_psa_crypto_rsa_no_genprime() {
1217 msg "build: default config minus MBEDTLS_GENPRIME"
1218 scripts/config.py unset MBEDTLS_GENPRIME
1219 make
1220
1221 msg "test: default config minus MBEDTLS_GENPRIME"
1222 make test
1223}
1224
Gilles Peskine782f4112018-11-27 16:11:09 +01001225component_test_ref_configs () {
1226 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Manuel Pégourié-Gonnard9327fb32021-09-09 11:46:25 +02001227 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
1228 # want to re-generate generated files that depend on it, quite correctly.
1229 # However this doesn't work as the generation script expects a specific
1230 # format for mbedtls_config.h, which the other files don't follow. Also,
1231 # cmake can't know this, but re-generation is actually not necessary as
David Horstmannd64f4b22021-10-20 12:29:47 +01001232 # the generated files only depend on the list of available options, not
Manuel Pégourié-Gonnard9327fb32021-09-09 11:46:25 +02001233 # whether they're on or off. So, disable cmake's (over-sensitive here)
1234 # dependency resolution for generated files and just rely on them being
David Horstmanna8d14062021-10-20 17:14:23 +01001235 # present (thanks to pre_generate_files) by turning GEN_FILES off.
1236 CC=gcc cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001237 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +01001238}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001239
Gilles Peskine8f073122018-11-27 15:58:47 +01001240component_test_no_renegotiation () {
1241 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001242 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001243 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1244 make
Simon Butcher3ea7f522016-03-07 23:22:10 +00001245
Gilles Peskine8f073122018-11-27 15:58:47 +01001246 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1247 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +01001248
Gilles Peskine8f073122018-11-27 15:58:47 +01001249 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001250 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001251}
Hanno Becker134c2ab2017-10-12 15:29:50 +01001252
Gilles Peskine636c26a2020-03-04 20:46:15 +01001253component_test_no_pem_no_fs () {
1254 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1255 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1256 scripts/config.py unset MBEDTLS_FS_IO
1257 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1258 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
1259 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1260 make
1261
1262 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1263 make test
1264
1265 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001266 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001267}
1268
Gilles Peskine8f073122018-11-27 15:58:47 +01001269component_test_rsa_no_crt () {
1270 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001271 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +01001272 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1273 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +01001274
Gilles Peskine8f073122018-11-27 15:58:47 +01001275 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1276 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001277
Gilles Peskine8f073122018-11-27 15:58:47 +01001278 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001279 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001280
Gilles Peskine8f073122018-11-27 15:58:47 +01001281 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001282 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001283
1284 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001285 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001286}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001287
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001288component_test_no_ctr_drbg_classic () {
1289 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001290 scripts/config.py full
1291 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001292 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001293 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001294
1295 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1296 make
1297
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001298 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001299 make test
1300
Gilles Peskineba749042021-01-13 20:02:03 +01001301 # In this configuration, the TLS test programs use HMAC_DRBG.
1302 # The SSL tests are slow, so run a small subset, just enough to get
1303 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001304 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001305 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001306
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001307 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001308 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001309}
1310
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001311component_test_no_ctr_drbg_use_psa () {
1312 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001313 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001314 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1315 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001316
1317 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1318 make
1319
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001320 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1321 make test
1322
1323 # In this configuration, the TLS test programs use HMAC_DRBG.
1324 # The SSL tests are slow, so run a small subset, just enough to get
1325 # confidence that the SSL code copes with HMAC_DRBG.
1326 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001327 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001328
1329 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001330 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001331}
1332
1333component_test_no_hmac_drbg_classic () {
1334 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1335 scripts/config.py full
1336 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1337 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1338 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001339 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001340
1341 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1342 make
1343
1344 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001345 make test
1346
Gilles Peskinea2224342020-11-19 22:14:34 +01001347 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1348 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1349 # instead.
1350 # Test SSL with non-deterministic ECDSA. Only test features that
1351 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001352 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001353 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001354
1355 # To save time, only test one protocol version, since this part of
1356 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001357 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001358 tests/compat.sh -m tls12 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001359}
1360
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001361component_test_no_hmac_drbg_use_psa () {
1362 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1363 scripts/config.py full
1364 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1365 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1366 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1367
1368 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1369 make
1370
1371 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1372 make test
1373
1374 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1375 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1376 # instead.
1377 # Test SSL with non-deterministic ECDSA. Only test features that
1378 # might be affected by how ECDSA signature is performed.
1379 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001380 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001381
1382 # To save time, only test one protocol version, since this part of
1383 # the protocol is identical in (D)TLS up to 1.2.
1384 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001385 tests/compat.sh -m tls12 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001386}
1387
1388component_test_psa_external_rng_no_drbg_classic () {
1389 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1390 scripts/config.py full
1391 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001392 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001393 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001394 scripts/config.py unset MBEDTLS_ENTROPY_C
1395 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1396 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001397 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1398 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1399 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001400 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1401 # the SSL test programs don't have an RNG and can't work. Explicitly
1402 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1403 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001404
1405 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1406 make test
1407
Gilles Peskine8eb29432021-02-03 20:07:11 +01001408 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001409 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001410}
1411
1412component_test_psa_external_rng_no_drbg_use_psa () {
1413 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001414 scripts/config.py full
1415 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001416 scripts/config.py unset MBEDTLS_ENTROPY_C
1417 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1418 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001419 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1420 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1421 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskinec109b372020-11-23 17:39:04 +01001422 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1423
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001424 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001425 make test
1426
Gilles Peskine8eb29432021-02-03 20:07:11 +01001427 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001428 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001429}
1430
Gilles Peskine4bdb2542023-04-28 19:25:25 +02001431component_test_psa_external_rng_use_psa_crypto () {
1432 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1433 scripts/config.py full
1434 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1435 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1436 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1437 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1438
1439 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1440 make test
1441
1442 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1443 tests/ssl-opt.sh -f 'Default\|opaque'
1444}
1445
Gilles Peskine801c4332023-04-28 21:04:28 +02001446component_test_psa_inject_entropy () {
1447 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
1448 scripts/config.py full
1449 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
1450 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
1451 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1452 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1453 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
1454 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
1455 make CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
1456
1457 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
1458 make test
1459}
1460
Andrzej Kurek06969fc2023-04-12 10:34:50 -04001461component_test_sw_inet_pton () {
1462 msg "build: default plus MBEDTLS_TEST_SW_INET_PTON"
1463
1464 # MBEDTLS_TEST_HOOKS required for x509_crt_parse_cn_inet_pton
1465 scripts/config.py set MBEDTLS_TEST_HOOKS
1466 make CFLAGS="-DMBEDTLS_TEST_SW_INET_PTON"
1467
1468 msg "test: default plus MBEDTLS_TEST_SW_INET_PTON"
1469 make test
1470}
1471
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001472component_test_crypto_full_md_light_only () {
1473 msg "build: crypto_full with only the light subset of MD"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001474 scripts/config.py crypto_full
Gilles Peskine884b4622023-07-20 20:11:51 +02001475 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001476 # Disable MD
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001477 scripts/config.py unset MBEDTLS_MD_C
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001478 # Disable direct dependencies of MD_C
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001479 scripts/config.py unset MBEDTLS_HKDF_C
1480 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
Nick Child89e82e12022-11-09 10:36:10 -06001481 scripts/config.py unset MBEDTLS_PKCS7_C
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001482 # Disable indirect dependencies of MD_C
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001483 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001484 # Disable things that would auto-enable MD_C
1485 scripts/config.py unset MBEDTLS_PKCS5_C
1486
Manuel Pégourié-Gonnard1b5ffc62023-03-14 10:11:20 +01001487 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
1488 # which we haven't disabled, so no need to explicitly enable it.
1489 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001490
Manuel Pégourié-Gonnard0d415212023-02-23 13:02:13 +01001491 # Make sure we don't have the HMAC functions, but the hashing functions
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001492 not grep mbedtls_md_hmac library/md.o
Manuel Pégourié-Gonnard0d415212023-02-23 13:02:13 +01001493 grep mbedtls_md library/md.o
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001494
1495 msg "test: crypto_full with only the light subset of MD"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001496 make test
1497}
1498
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001499component_test_full_no_cipher () {
1500 msg "build: full minus CIPHER"
1501 scripts/config.py full
1502 scripts/config.py unset MBEDTLS_CIPHER_C
Gilles Peskine9b8dead2023-08-09 19:48:42 +02001503 # Don't pull in cipher via PSA mechanisms
1504 # (currently ignored anyway because we completely disable PSA)
1505 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Przemek Stekielda5f4832022-05-12 09:46:29 +02001506 # Direct dependencies
1507 scripts/config.py unset MBEDTLS_CCM_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001508 scripts/config.py unset MBEDTLS_CMAC_C
Przemek Stekielda5f4832022-05-12 09:46:29 +02001509 scripts/config.py unset MBEDTLS_GCM_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001510 scripts/config.py unset MBEDTLS_NIST_KW_C
1511 scripts/config.py unset MBEDTLS_PKCS12_C
1512 scripts/config.py unset MBEDTLS_PKCS5_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001513 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1514 scripts/config.py unset MBEDTLS_SSL_TLS_C
1515 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielda5f4832022-05-12 09:46:29 +02001516 # Indirect dependencies
1517 scripts/config.py unset MBEDTLS_SSL_CLI_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001518 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
1519 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001520 scripts/config.py unset MBEDTLS_SSL_DTLS_ANTI_REPLAY
1521 scripts/config.py unset MBEDTLS_SSL_DTLS_CONNECTION_ID
Dave Rodgman1df70702022-10-26 17:08:54 +01001522 scripts/config.py unset MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT
Przemek Stekielda5f4832022-05-12 09:46:29 +02001523 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1524 scripts/config.py unset MBEDTLS_SSL_SRV_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001525 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Raef Colesa7e03ad2022-09-28 09:32:48 +01001526 scripts/config.py unset MBEDTLS_LMS_C
Raef Coles47bccb72022-09-28 12:00:20 +01001527 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001528 make
1529
1530 msg "test: full minus CIPHER"
1531 make test
1532}
1533
Valerio Settie1655b82023-01-03 15:35:25 +01001534component_test_full_no_bignum () {
1535 msg "build: full minus bignum"
1536 scripts/config.py full
1537 scripts/config.py unset MBEDTLS_BIGNUM_C
1538 # Direct dependencies of bignum
1539 scripts/config.py unset MBEDTLS_ECP_C
1540 scripts/config.py unset MBEDTLS_RSA_C
1541 scripts/config.py unset MBEDTLS_DHM_C
1542 # Direct dependencies of ECP
1543 scripts/config.py unset MBEDTLS_ECDH_C
1544 scripts/config.py unset MBEDTLS_ECDSA_C
1545 scripts/config.py unset MBEDTLS_ECJPAKE_C
1546 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Setti22d0a792023-06-14 17:23:19 +02001547 # Disable what auto-enables ECP_LIGHT
1548 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1549 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
Valerio Settie1655b82023-01-03 15:35:25 +01001550 # Indirect dependencies of ECP
1551 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1552 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1553 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1554 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1555 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1556 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
1557 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
1558 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
1559 # Direct dependencies of DHM
1560 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1561 # Direct dependencies of RSA
1562 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1563 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1564 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1565 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1566 # PK and its dependencies
1567 scripts/config.py unset MBEDTLS_PK_C
1568 scripts/config.py unset MBEDTLS_PK_PARSE_C
1569 scripts/config.py unset MBEDTLS_PK_WRITE_C
1570 scripts/config.py unset MBEDTLS_X509_USE_C
1571 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
1572 scripts/config.py unset MBEDTLS_X509_CRL_PARSE_C
1573 scripts/config.py unset MBEDTLS_X509_CSR_PARSE_C
1574 scripts/config.py unset MBEDTLS_X509_CREATE_C
1575 scripts/config.py unset MBEDTLS_X509_CRT_WRITE_C
1576 scripts/config.py unset MBEDTLS_X509_CSR_WRITE_C
1577 scripts/config.py unset MBEDTLS_PKCS7_C
1578 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
1579 scripts/config.py unset MBEDTLS_SSL_ASYNC_PRIVATE
1580 scripts/config.py unset MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
1581
1582 make
1583
1584 msg "test: full minus bignum"
1585 make test
1586}
1587
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001588component_test_tls1_2_default_stream_cipher_only () {
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001589 msg "build: default with only stream cipher"
1590
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001591 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001592 scripts/config.py unset MBEDTLS_GCM_C
1593 scripts/config.py unset MBEDTLS_CCM_C
1594 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001595 # 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 +02001596 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001597 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001598 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001599 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1600 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001601 # Modules that depend on AEAD
Przemek Stekield582a012022-09-28 07:59:01 +02001602 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001603 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001604
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001605 make
1606
1607 msg "test: default with only stream cipher"
1608 make test
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001609
1610 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001611}
1612
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001613component_test_tls1_2_default_stream_cipher_only_use_psa () {
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001614 msg "build: default with only stream cipher use psa"
Przemek Stekiel9550c052022-09-28 09:51:55 +02001615
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001616 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001617 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel9550c052022-09-28 09:51:55 +02001618 scripts/config.py unset MBEDTLS_GCM_C
1619 scripts/config.py unset MBEDTLS_CCM_C
1620 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001621 # 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 +02001622 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001623 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekiel9550c052022-09-28 09:51:55 +02001624 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001625 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1626 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001627 # Modules that depend on AEAD
Przemek Stekiel9550c052022-09-28 09:51:55 +02001628 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001629 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel9550c052022-09-28 09:51:55 +02001630
Przemek Stekiel9550c052022-09-28 09:51:55 +02001631 make
1632
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001633 msg "test: default with only stream cipher use psa"
Przemek Stekiel9550c052022-09-28 09:51:55 +02001634 make test
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001635
1636 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
Przemek Stekiel9550c052022-09-28 09:51:55 +02001637}
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001638
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001639component_test_tls1_2_default_cbc_legacy_cipher_only () {
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001640 msg "build: default with only CBC-legacy cipher"
1641
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001642 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001643 scripts/config.py unset MBEDTLS_GCM_C
1644 scripts/config.py unset MBEDTLS_CCM_C
1645 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001646 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1647 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1648 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001649 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001650 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001651 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001652 # Modules that depend on AEAD
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001653 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001654 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001655
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001656 make
1657
1658 msg "test: default with only CBC-legacy cipher"
1659 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001660
1661 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1662 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001663}
1664
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001665component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001666 msg "build: default with only CBC-legacy cipher use psa"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001667
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001668 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001669 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001670 scripts/config.py unset MBEDTLS_GCM_C
1671 scripts/config.py unset MBEDTLS_CCM_C
1672 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001673 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1674 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1675 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001676 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001677 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001678 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001679 # Modules that depend on AEAD
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001680 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001681 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001682
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001683 make
1684
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001685 msg "test: default with only CBC-legacy cipher use psa"
1686 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001687
1688 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1689 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001690}
1691
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001692component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001693 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1694
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001695 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001696 scripts/config.py unset MBEDTLS_GCM_C
1697 scripts/config.py unset MBEDTLS_CCM_C
1698 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001699 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1700 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1701 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1702 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1703 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001704 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001705 # Modules that depend on AEAD
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001706 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001707 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001708
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001709 make
1710
1711 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1712 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001713
1714 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1715 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001716}
1717
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001718component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
1719 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001720
1721 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001722 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001723 scripts/config.py unset MBEDTLS_GCM_C
1724 scripts/config.py unset MBEDTLS_CCM_C
1725 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001726 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1727 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1728 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1729 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1730 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001731 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001732 # Modules that depend on AEAD
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001733 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001734 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001735
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001736 make
1737
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001738 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001739 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001740
1741 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
1742 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001743}
1744
Valerio Setti9f0ec532022-11-08 13:03:24 +01001745# We're not aware of any other (open source) implementation of EC J-PAKE in TLS
1746# that we could use for interop testing. However, we now have sort of two
1747# implementations ourselves: one using PSA, the other not. At least test that
1748# these two interoperate with each other.
1749component_test_tls1_2_ecjpake_compatibility() {
1750 msg "build: TLS1.2 server+client w/ EC-JPAKE w/o USE_PSA"
1751 scripts/config.py set MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
Gilles Peskineedc84562023-09-20 15:03:18 +02001752 # Explicitly make lib first to avoid a race condition:
1753 # https://github.com/Mbed-TLS/mbedtls/issues/8229
1754 make lib
Valerio Setti9f0ec532022-11-08 13:03:24 +01001755 make -C programs ssl/ssl_server2 ssl/ssl_client2
1756 cp programs/ssl/ssl_server2 s2_no_use_psa
1757 cp programs/ssl/ssl_client2 c2_no_use_psa
1758
1759 msg "build: TLS1.2 server+client w/ EC-JPAKE w/ USE_PSA"
1760 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1761 make clean
Gilles Peskineedc84562023-09-20 15:03:18 +02001762 make lib
Valerio Setti9f0ec532022-11-08 13:03:24 +01001763 make -C programs ssl/ssl_server2 ssl/ssl_client2
1764 make -C programs test/udp_proxy test/query_compile_time_config
1765
Valerio Setti70e02902022-12-02 16:21:56 +01001766 msg "test: server w/o USE_PSA - client w/ USE_PSA, text password"
1767 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
1768 msg "test: server w/o USE_PSA - client w/ USE_PSA, opaque password"
1769 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password client only, working, TLS"
1770 msg "test: client w/o USE_PSA - server w/ USE_PSA, text password"
1771 P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
1772 msg "test: client w/o USE_PSA - server w/ USE_PSA, opaque password"
1773 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 +01001774
1775 rm s2_no_use_psa c2_no_use_psa
1776}
1777
Gilles Peskine636c26a2020-03-04 20:46:15 +01001778component_test_everest () {
1779 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine636c26a2020-03-04 20:46:15 +01001780 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1781 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1782 make
1783
1784 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1785 make test
1786
1787 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001788 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001789
1790 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1791 # Exclude some symmetric ciphers that are redundant here to gain time.
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02001792 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001793}
1794
Gilles Peskined3beca92020-07-03 00:15:37 +02001795component_test_everest_curve25519_only () {
1796 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
Gilles Peskined3beca92020-07-03 00:15:37 +02001797 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1798 scripts/config.py unset MBEDTLS_ECDSA_C
1799 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1800 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
TRodziewicz7c1d41d2021-04-23 13:33:44 +02001801 scripts/config.py unset MBEDTLS_ECJPAKE_C
Gilles Peskined3beca92020-07-03 00:15:37 +02001802 # Disable all curves
Valerio Setti2e0275d2023-07-28 16:33:13 +02001803 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
Gilles Peskined3beca92020-07-03 00:15:37 +02001804 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1805
1806 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1807
1808 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1809 make test
1810}
1811
Gilles Peskine8f073122018-11-27 15:58:47 +01001812component_test_small_ssl_out_content_len () {
1813 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001814 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1815 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001816 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1817 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001818
Gilles Peskine8f073122018-11-27 15:58:47 +01001819 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001820 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001821}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001822
Gilles Peskine8f073122018-11-27 15:58:47 +01001823component_test_small_ssl_in_content_len () {
1824 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001825 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1826 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001827 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1828 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001829
Gilles Peskine8f073122018-11-27 15:58:47 +01001830 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001831 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001832}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001833
Gilles Peskine8f073122018-11-27 15:58:47 +01001834component_test_small_ssl_dtls_max_buffering () {
1835 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001836 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001837 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1838 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001839
Gilles Peskine8f073122018-11-27 15:58:47 +01001840 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001841 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 +01001842}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001843
Gilles Peskine8f073122018-11-27 15:58:47 +01001844component_test_small_mbedtls_ssl_dtls_max_buffering () {
1845 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001846 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001847 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1848 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001849
Gilles Peskine8f073122018-11-27 15:58:47 +01001850 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001851 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001852}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001853
Gilles Peskine75cc7712019-09-06 19:47:17 +02001854component_test_psa_collect_statuses () {
1855 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001856 scripts/config.py full
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001857 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001858 # Check that psa_crypto_init() succeeded at least once
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001859 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001860 rm -f tests/statuses.log
1861}
1862
Gilles Peskine8f073122018-11-27 15:58:47 +01001863component_test_full_cmake_clang () {
1864 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001865 scripts/config.py full
Gilles Peskineda6017c2022-10-30 21:02:40 +01001866 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 +01001867 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001868
k-stachowiak0291cb72019-06-26 15:52:12 +02001869 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001870 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001871
Gilles Peskineda6017c2022-10-30 21:02:40 +01001872 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
1873 programs/test/cpp_dummy_build
1874
k-stachowiak0291cb72019-06-26 15:52:12 +02001875 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001876 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001877
Gilles Peskine8f073122018-11-27 15:58:47 +01001878 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001879 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001880
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02001881 msg "test: compat.sh NULL (full config)" # ~ 2 min
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01001882 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 +02001883
Gilles Peskine8f073122018-11-27 15:58:47 +01001884 msg "test: compat.sh ARIA + ChachaPoly"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01001885 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001886}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001887
Gilles Peskine0c671602022-11-29 16:01:41 +01001888skip_suites_without_constant_flow () {
1889 # Skip the test suites that don't have any constant-flow annotations.
1890 # This will need to be adjusted if we ever start declaring things as
1891 # secret from macros or functions inside tests/include or tests/src.
1892 SKIP_TEST_SUITES=$(
1893 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
1894 sed 's/test_suite_//; s/\.function$//' |
1895 tr '\n' ,)
1896 export SKIP_TEST_SUITES
1897}
1898
Dave Rodgman246210e2023-07-31 18:07:44 +01001899skip_all_except_given_suite () {
1900 # Skip all but the given test suite
1901 SKIP_TEST_SUITES=$(
1902 ls -1 tests/suites/test_suite_*.function |
1903 grep -v $1.function |
1904 sed 's/tests.suites.test_suite_//; s/\.function$//' |
1905 tr '\n' ,)
1906 export SKIP_TEST_SUITES
1907}
1908
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001909component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001910 # This tests both (1) accesses to undefined memory, and (2) branches or
1911 # memory access depending on secret values. To distinguish between those:
1912 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1913 # - or alternatively, change the build type to MemSanDbg, which enables
1914 # origin tracking and nicer stack traces (which are useful for debugging
1915 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001916 msg "build: cmake MSan (clang), full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
1917 scripts/config.py full
1918 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1919 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1920 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1921 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1922 make
1923
1924 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO, Msan + constant flow)"
1925 make test
1926}
1927
1928component_test_memsan_constant_flow_psa () {
1929 # This tests both (1) accesses to undefined memory, and (2) branches or
1930 # memory access depending on secret values. To distinguish between those:
1931 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1932 # - or alternatively, change the build type to MemSanDbg, which enables
1933 # origin tracking and nicer stack traces (which are useful for debugging
1934 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001935 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001936 scripts/config.py full
1937 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1938 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1939 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1940 make
1941
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001942 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001943 make test
1944}
1945
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001946component_test_valgrind_constant_flow () {
1947 # This tests both (1) everything that valgrind's memcheck usually checks
1948 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1949 # etc.) and (2) branches or memory access depending on secret values,
1950 # which will be reported as uninitialized memory. To distinguish between
1951 # secret and actually uninitialized:
1952 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1953 # - or alternatively, build with debug info and manually run the offending
1954 # test suite with valgrind --track-origins=yes, then check if the origin
1955 # was TEST_CF_SECRET() or something else.
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001956 msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
1957 scripts/config.py full
1958 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
1959 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine0c671602022-11-29 16:01:41 +01001960 skip_suites_without_constant_flow
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001961 cmake -D CMAKE_BUILD_TYPE:String=Release .
1962 make
1963
1964 # this only shows a summary of the results (how many of each type)
1965 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine0c671602022-11-29 16:01:41 +01001966 msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, valgrind + constant flow)"
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001967 make memcheck
Dave Rodgman246210e2023-07-31 18:07:44 +01001968
1969 # Test asm path in constant time module - by default, it will test the plain C
1970 # path under Valgrind or Memsan. Running only the constant_time tests is fast (<1s)
1971 msg "test: valgrind asm constant_time"
1972 scripts/config.py --force set MBEDTLS_TEST_CONSTANT_FLOW_ASM
1973 skip_all_except_given_suite test_suite_constant_time
1974 cmake -D CMAKE_BUILD_TYPE:String=Release .
1975 make clean
1976 make
1977 make memcheck
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001978}
1979
1980component_test_valgrind_constant_flow_psa () {
1981 # This tests both (1) everything that valgrind's memcheck usually checks
1982 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1983 # etc.) and (2) branches or memory access depending on secret values,
1984 # which will be reported as uninitialized memory. To distinguish between
1985 # secret and actually uninitialized:
1986 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1987 # - or alternatively, build with debug info and manually run the offending
1988 # test suite with valgrind --track-origins=yes, then check if the origin
1989 # was TEST_CF_SECRET() or something else.
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001990 msg "build: cmake release GCC, full config with constant flow testing"
1991 scripts/config.py full
1992 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Gilles Peskine0c671602022-11-29 16:01:41 +01001993 skip_suites_without_constant_flow
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001994 cmake -D CMAKE_BUILD_TYPE:String=Release .
1995 make
1996
1997 # this only shows a summary of the results (how many of each type)
1998 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine0c671602022-11-29 16:01:41 +01001999 msg "test: some suites (valgrind + constant flow)"
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02002000 make memcheck
2001}
2002
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002003component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02002004 # Test that removing the deprecated features from the default
2005 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002006 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
2007 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
2008 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
2009
2010 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
2011 make test
2012}
2013
2014component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02002015 msg "build: make, full_no_deprecated config" # ~ 30s
2016 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002017 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
2018
Gilles Peskine30de2e82020-04-20 21:39:22 +02002019 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002020 make test
Valerio Setti41b5fb62023-01-09 12:20:45 +01002021
2022 msg "test: ensure that X509 has no direct dependency on BIGNUM_C"
2023 not grep mbedtls_mpi library/libmbedx509.a
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002024}
2025
Gilles Peskine8386ea22020-04-30 09:07:29 +02002026component_test_full_no_deprecated_deprecated_warning () {
2027 # Test that there is nothing deprecated in "full_no_deprecated".
2028 # A deprecated feature would trigger a warning (made fatal) from
2029 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02002030 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
2031 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002032 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
2033 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
2034 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
2035
Gilles Peskine30de2e82020-04-20 21:39:22 +02002036 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002037 make test
2038}
2039
Gilles Peskine8386ea22020-04-30 09:07:29 +02002040component_test_full_deprecated_warning () {
2041 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
2042 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002043 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002044 scripts/config.py full
2045 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002046 # Expect warnings from '#warning' directives in check_config.h.
2047 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01002048
Gilles Peskine8386ea22020-04-30 09:07:29 +02002049 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
2050 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
2051 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002052 # Expect warnings from '#warning' directives in check_config.h and
2053 # from the use of deprecated functions in test suites.
2054 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 +01002055
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002056 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
2057 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01002058}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00002059
Gilles Peskineec541fe2020-01-31 14:24:14 +01002060# Check that the specified libraries exist and are empty.
2061are_empty_libraries () {
2062 nm "$@" >/dev/null 2>/dev/null
2063 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
2064}
2065
2066component_build_crypto_default () {
2067 msg "build: make, crypto only"
2068 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01002069 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002070 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002071}
2072
2073component_build_crypto_full () {
2074 msg "build: make, crypto only, full config"
2075 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01002076 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002077 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002078}
2079
Gilles Peskinefc4f11b2022-10-21 19:34:54 +02002080component_test_crypto_for_psa_service () {
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002081 msg "build: make, config for PSA crypto service"
2082 scripts/config.py crypto
2083 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
2084 # Disable things that are not needed for just cryptography, to
2085 # reach a configuration that would be typical for a PSA cryptography
2086 # service providing all implemented PSA algorithms.
2087 # System stuff
2088 scripts/config.py unset MBEDTLS_ERROR_C
2089 scripts/config.py unset MBEDTLS_TIMING_C
Gilles Peskine78bffd12022-10-25 21:02:33 +02002090 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002091 # Crypto stuff with no PSA interface
2092 scripts/config.py unset MBEDTLS_BASE64_C
Gilles Peskine649e04e2022-10-25 21:05:57 +02002093 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
Gilles Peskineb06f0712022-10-25 21:06:11 +02002094 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
Gilles Peskine649e04e2022-10-25 21:05:57 +02002095 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002096 scripts/config.py unset MBEDTLS_NIST_KW_C
2097 scripts/config.py unset MBEDTLS_PEM_PARSE_C
2098 scripts/config.py unset MBEDTLS_PEM_WRITE_C
2099 scripts/config.py unset MBEDTLS_PKCS12_C
2100 scripts/config.py unset MBEDTLS_PKCS5_C
Gilles Peskinefcee7402022-10-11 21:15:24 +02002101 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
2102 # in PSA code to work with RSA keys. We don't require users to set those:
2103 # they will be reenabled in build_info.h.
Gilles Peskine1f108072022-10-25 21:02:56 +02002104 scripts/config.py unset MBEDTLS_PK_C
Gilles Peskinefcee7402022-10-11 21:15:24 +02002105 scripts/config.py unset MBEDTLS_PK_PARSE_C
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002106 scripts/config.py unset MBEDTLS_PK_WRITE_C
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002107 make CFLAGS='-O1 -Werror' all test
2108 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
2109}
2110
Gilles Peskineec541fe2020-01-31 14:24:14 +01002111component_build_crypto_baremetal () {
2112 msg "build: make, crypto only, baremetal config"
2113 scripts/config.py crypto_baremetal
David Horstmann61faf662021-11-30 11:40:54 +00002114 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002115 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002116}
Daniel Axtens446af202020-09-02 21:30:13 +10002117support_build_crypto_baremetal () {
Daniel Axtens814c8132020-08-31 14:22:58 +10002118 support_build_baremetal "$@"
2119}
2120
2121component_build_baremetal () {
2122 msg "build: make, baremetal config"
2123 scripts/config.py baremetal
David Horstmann61faf662021-11-30 11:40:54 +00002124 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Daniel Axtens814c8132020-08-31 14:22:58 +10002125}
2126support_build_baremetal () {
Daniel Axtens446af202020-09-02 21:30:13 +10002127 # Older Glibc versions include time.h from other headers such as stdlib.h,
2128 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
2129 # problem, Ubuntu 18.04 is ok.
2130 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
2131}
Gilles Peskineec541fe2020-01-31 14:24:14 +01002132
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002133# depends.py family of tests
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002134component_test_depends_py_cipher_id () {
2135 msg "test/build: depends.py cipher_id (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002136 tests/scripts/depends.py cipher_id --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002137}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00002138
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002139component_test_depends_py_cipher_chaining () {
2140 msg "test/build: depends.py cipher_chaining (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002141 tests/scripts/depends.py cipher_chaining --unset-use-psa
John Durkopc14be902020-08-20 06:16:41 -07002142}
2143
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002144component_test_depends_py_cipher_padding () {
2145 msg "test/build: depends.py cipher_padding (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002146 tests/scripts/depends.py cipher_padding --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002147}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00002148
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002149component_test_depends_py_curves () {
2150 msg "test/build: depends.py curves (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002151 tests/scripts/depends.py curves --unset-use-psa
John Durkop2ec2eaa2020-08-24 18:29:15 -07002152}
2153
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002154component_test_depends_py_hashes () {
2155 msg "test/build: depends.py hashes (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002156 tests/scripts/depends.py hashes --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002157}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002158
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002159component_test_depends_py_kex () {
2160 msg "test/build: depends.py kex (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002161 tests/scripts/depends.py kex --unset-use-psa
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002162}
2163
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002164component_test_depends_py_pkalgs () {
2165 msg "test/build: depends.py pkalgs (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002166 tests/scripts/depends.py pkalgs --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002167}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002168
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002169# PSA equivalents of the depends.py tests
2170component_test_depends_py_cipher_id_psa () {
2171 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2172 tests/scripts/depends.py cipher_id
2173}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002174
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002175component_test_depends_py_cipher_chaining_psa () {
2176 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2177 tests/scripts/depends.py cipher_chaining
2178}
2179
2180component_test_depends_py_cipher_padding_psa () {
2181 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2182 tests/scripts/depends.py cipher_padding
2183}
2184
2185component_test_depends_py_curves_psa () {
2186 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2187 tests/scripts/depends.py curves
2188}
2189
2190component_test_depends_py_hashes_psa () {
2191 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2192 tests/scripts/depends.py hashes
2193}
2194
2195component_test_depends_py_kex_psa () {
2196 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2197 tests/scripts/depends.py kex
2198}
2199
2200component_test_depends_py_pkalgs_psa () {
2201 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002202 tests/scripts/depends.py pkalgs
Gilles Peskine8f073122018-11-27 15:58:47 +01002203}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002204
Dave Rodgman1a034dc2023-01-20 13:18:05 +00002205component_build_no_pk_rsa_alt_support () {
2206 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
2207
2208 scripts/config.py full
2209 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
2210 scripts/config.py set MBEDTLS_RSA_C
2211 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
2212
2213 # Only compile - this is primarily to test for compile issues
2214 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
2215}
2216
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002217component_build_module_alt () {
2218 msg "build: MBEDTLS_XXX_ALT" # ~30s
2219 scripts/config.py full
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002220
2221 # Disable options that are incompatible with some ALT implementations:
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002222 # aesni.c and padlock.c reference mbedtls_aes_context fields directly.
2223 scripts/config.py unset MBEDTLS_AESNI_C
2224 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08002225 scripts/config.py unset MBEDTLS_AESCE_C
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002226 # MBEDTLS_ECP_RESTARTABLE is documented as incompatible.
2227 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002228 # You can only have one threading implementation: alt or pthread, not both.
2229 scripts/config.py unset MBEDTLS_THREADING_PTHREAD
Gilles Peskine5c3f18d2021-05-31 21:21:12 +02002230 # The SpecifiedECDomain parsing code accesses mbedtls_ecp_group fields
2231 # directly and assumes the implementation works with partial groups.
2232 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
Dave Rodgman5b89c552023-10-10 14:59:02 +01002233 # MBEDTLS_SHA256_*ALT can't be used with MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*
2234 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2235 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
Dave Rodgmanbe7915a2023-10-11 10:46:38 +01002236 # MBEDTLS_SHA512_*ALT can't be used with MBEDTLS_SHA512_USE_A64_CRYPTO_*
2237 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2238 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002239
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002240 # Enable all MBEDTLS_XXX_ALT for whole modules. Do not enable
2241 # MBEDTLS_XXX_YYY_ALT which are for single functions.
2242 scripts/config.py set-all 'MBEDTLS_([A-Z0-9]*|NIST_KW)_ALT'
Gilles Peskine1628a9c2021-05-31 22:09:58 +02002243 scripts/config.py unset MBEDTLS_DHM_ALT #incompatible with MBEDTLS_DEBUG_C
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002244
Gilles Peskine1628a9c2021-05-31 22:09:58 +02002245 # We can only compile, not link, since we don't have any implementations
2246 # suitable for testing with the dummy alt headers.
2247 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
2248}
2249
2250component_build_dhm_alt () {
2251 msg "build: MBEDTLS_DHM_ALT" # ~30s
2252 scripts/config.py full
2253 scripts/config.py set MBEDTLS_DHM_ALT
2254 # debug.c currently references mbedtls_dhm_context fields directly.
2255 scripts/config.py unset MBEDTLS_DEBUG_C
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002256 # We can only compile, not link, since we don't have any implementations
2257 # suitable for testing with the dummy alt headers.
2258 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
2259}
2260
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002261component_test_no_use_psa_crypto_full_cmake_asan() {
2262 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02002263 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002264 scripts/config.py full
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002265 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
2266 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cron6f135e12021-12-08 16:57:54 +01002267 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002268 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02002269 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002270 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Raef Colesa7e03ad2022-09-28 09:32:48 +01002271 scripts/config.py unset MBEDTLS_LMS_C
Raef Coles47bccb72022-09-28 12:00:20 +01002272 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01002273 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002274 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02002275
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002276 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002277 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02002278
Manuel Pégourié-Gonnard182a23b2022-12-07 10:38:43 +01002279 # Note: ssl-opt.sh has some test cases that depend on
2280 # MBEDTLS_ECP_RESTARTABLE && !MBEDTLS_USE_PSA_CRYPTO
2281 # This is the only component where those tests are not skipped.
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002282 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002283 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002284
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002285 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002286 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04002287
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02002288 msg "test: compat.sh NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01002289 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 -05002290
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002291 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01002292 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002293}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002294
Ronald Cron403c15c2021-09-13 09:38:05 +02002295component_test_psa_crypto_config_accel_ecdsa () {
Valerio Setti5aab43f2023-03-29 10:42:07 +02002296 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
Ronald Cron403c15c2021-09-13 09:38:05 +02002297
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002298 # Algorithms and key types to accelerate
Valerio Settic0d2f842023-06-28 10:48:08 +02002299 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
Valerio Setti0a342c92023-09-01 09:12:31 +02002300 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002301
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002302 # Note: Those are handled in a special way by the libtestdriver machinery,
2303 # so we only want to include them in the accel list when building the main
2304 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002305 loc_curve_list="$(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002306
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002307 # Configure
2308 # ---------
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002309
Manuel Pégourié-Gonnard8d645dc2023-06-15 09:07:10 +02002310 # Start from default config (no USE_PSA) + TLS 1.3
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002311 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard6d7db932022-12-28 09:48:01 +01002312 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002313
2314 # Disable the module that's accelerated
Ronald Cron403c15c2021-09-13 09:38:05 +02002315 scripts/config.py unset MBEDTLS_ECDSA_C
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002316
2317 # Disable things that depend on it
Ronald Cron403c15c2021-09-13 09:38:05 +02002318 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2319 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2320
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002321 # Build
2322 # -----
2323
2324 # These hashes are needed for some ECDSA signature tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02002325 loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2326 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002327
2328 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2329
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002330 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02002331
Manuel Pégourié-Gonnarde3095e72022-12-28 10:09:53 +01002332 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine827dbd92022-02-04 00:30:54 +01002333 not grep mbedtls_ecdsa_ library/ecdsa.o
Ronald Cron403c15c2021-09-13 09:38:05 +02002334
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002335 # Run the tests
2336 # -------------
2337
Ronald Cron403c15c2021-09-13 09:38:05 +02002338 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
2339 make test
2340}
2341
Valerio Setti44b178c2023-03-22 14:02:57 +01002342component_test_psa_crypto_config_accel_ecdh () {
Valerio Setti5aab43f2023-03-29 10:42:07 +02002343 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002344
2345 # Algorithms and key types to accelerate
Valerio Settic0d2f842023-06-28 10:48:08 +02002346 loc_accel_list="ALG_ECDH \
Valerio Setti0a342c92023-09-01 09:12:31 +02002347 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002348
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002349 # Note: Those are handled in a special way by the libtestdriver machinery,
2350 # so we only want to include them in the accel list when building the main
2351 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002352 loc_curve_list="$(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002353
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002354 # Configure
2355 # ---------
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002356
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002357 # Start from default config (no TLS 1.3, no USE_PSA)
2358 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002359
Valerio Setti44b178c2023-03-22 14:02:57 +01002360 # Disable the module that's accelerated
2361 scripts/config.py unset MBEDTLS_ECDH_C
2362
2363 # Disable things that depend on it
2364 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2365 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2366 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2367 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2368 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2369
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002370 # Build
2371 # -----
2372
2373 helper_libtestdriver1_make_drivers "$loc_accel_list"
2374
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002375 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002376
Valerio Setti44b178c2023-03-22 14:02:57 +01002377 # Make sure this was not re-enabled by accident (additive config)
2378 not grep mbedtls_ecdh_ library/ecdh.o
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002379
2380 # Run the tests
2381 # -------------
2382
Valerio Setti44b178c2023-03-22 14:02:57 +01002383 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002384 make test
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +01002385}
2386
Przemek Stekieldccb2022023-05-11 10:48:50 +02002387component_test_psa_crypto_config_accel_ffdh () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002388 msg "build: full with accelerated FFDH"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002389
2390 # Algorithms and key types to accelerate
Valerio Setti27602c32023-07-10 16:38:59 +02002391 loc_accel_list="ALG_FFDH \
Valerio Setti0a342c92023-09-01 09:12:31 +02002392 $(helper_get_psa_key_type_list "DH")"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002393
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002394 # Configure
2395 # ---------
Przemek Stekieldccb2022023-05-11 10:48:50 +02002396
Przemek Stekiel565353e2023-07-05 11:07:07 +02002397 # start with full (USE_PSA and TLS 1.3)
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002398 helper_libtestdriver1_adjust_config "full"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002399
2400 # Disable the module that's accelerated
2401 scripts/config.py unset MBEDTLS_DHM_C
2402
2403 # Disable things that depend on it
2404 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2405 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2406
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002407 # Build
2408 # -----
2409
2410 helper_libtestdriver1_make_drivers "$loc_accel_list"
2411
Manuel Pégourié-Gonnard981732e2023-06-08 09:15:59 +02002412 helper_libtestdriver1_make_main "$loc_accel_list"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002413
2414 # Make sure this was not re-enabled by accident (additive config)
2415 not grep mbedtls_dhm_ library/dhm.o
2416
2417 # Run the tests
2418 # -------------
2419
Gilles Peskine14302ed2023-07-19 19:30:04 +02002420 msg "test: full with accelerated FFDH"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002421 make test
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002422
Gilles Peskine14302ed2023-07-19 19:30:04 +02002423 msg "ssl-opt: full with accelerated FFDH alg"
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002424 tests/ssl-opt.sh -f "ffdh"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002425}
2426
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002427component_test_psa_crypto_config_reference_ffdh () {
Gilles Peskineb7d577e2023-08-09 19:48:58 +02002428 msg "build: full with non-accelerated FFDH"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002429
2430 # Start with full (USE_PSA and TLS 1.3)
Przemek Stekiel565353e2023-07-05 11:07:07 +02002431 helper_libtestdriver1_adjust_config "full"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002432
2433 # Disable things that are not supported
2434 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2435 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002436 make
2437
Gilles Peskine14302ed2023-07-19 19:30:04 +02002438 msg "test suites: full with non-accelerated FFDH alg"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002439 make test
2440
Gilles Peskine14302ed2023-07-19 19:30:04 +02002441 msg "ssl-opt: full with non-accelerated FFDH alg"
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002442 tests/ssl-opt.sh -f "ffdh"
Valerio Setti42d5f192023-03-20 13:54:41 +01002443}
2444
Valerio Setti44b178c2023-03-22 14:02:57 +01002445component_test_psa_crypto_config_accel_pake() {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002446 msg "build: full with accelerated PAKE"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002447
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002448 loc_accel_list="ALG_JPAKE \
2449 $(helper_get_psa_key_type_list "ECC")"
2450
2451 # Note: Those are handled in a special way by the libtestdriver machinery,
2452 # so we only want to include them in the accel list when building the main
2453 # libraries, hence the use of a separate variable.
2454 loc_curve_list="$(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002455
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002456 # Configure
2457 # ---------
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002458
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002459 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002460
2461 # Make built-in fallback not available
2462 scripts/config.py unset MBEDTLS_ECJPAKE_C
2463 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
2464
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002465 # Build
2466 # -----
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002467
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002468 helper_libtestdriver1_make_drivers "$loc_accel_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002469
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002470 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002471
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002472 # Make sure this was not re-enabled by accident (additive config)
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002473 not grep mbedtls_ecjpake_init library/ecjpake.o
2474
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002475 # Run the tests
2476 # -------------
2477
Gilles Peskine14302ed2023-07-19 19:30:04 +02002478 msg "test: full with accelerated PAKE"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002479 make test
2480}
2481
Manuel Pégourié-Gonnard5c210362023-09-26 12:03:10 +02002482component_test_psa_crypto_config_accel_ecc_some_key_types () {
2483 msg "build: full with accelerated EC algs and some key types"
2484
2485 # Algorithms and key types to accelerate
2486 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
2487 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2488 ALG_ECDH \
2489 ALG_JPAKE \
2490 KEY_TYPE_ECC_PUBLIC_KEY \
2491 KEY_TYPE_ECC_KEY_PAIR_BASIC \
2492 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
2493 KEY_TYPE_ECC_KEY_PAIR_EXPORT"
2494
2495 # Note: Curves are handled in a special way by the libtestdriver machinery,
2496 # so we only want to include them in the accel list when building the main
2497 # libraries, hence the use of a separate variable.
2498 loc_curve_list="$(helper_get_psa_curve_list)"
2499
2500 # Configure
2501 # ---------
2502
2503 # start with config full for maximum coverage (also enables USE_PSA)
2504 helper_libtestdriver1_adjust_config "full"
2505
2506 # Disable modules that are accelerated - some will be re-enabled
2507 scripts/config.py unset MBEDTLS_ECDSA_C
2508 scripts/config.py unset MBEDTLS_ECDH_C
2509 scripts/config.py unset MBEDTLS_ECJPAKE_C
2510 scripts/config.py unset MBEDTLS_ECP_C
2511
2512 # Disable all curves - those that aren't accelerated should be re-enabled
2513 helper_disable_builtin_curves
2514
2515 # Restartable feature is not yet supported by PSA. Once it will in
2516 # the future, the following line could be removed (see issues
2517 # 6061, 6332 and following ones)
2518 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2519
2520 # this is not supported by the driver API yet
2521 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2522
2523 # Build
2524 # -----
2525
2526 # These hashes are needed for some ECDSA signature tests.
2527 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2528 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2529 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2530
2531 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
2532
2533 # ECP should be re-enabled but not the others
2534 not grep mbedtls_ecdh_ library/ecdh.o
2535 not grep mbedtls_ecdsa library/ecdsa.o
2536 not grep mbedtls_ecjpake library/ecjpake.o
2537 grep mbedtls_ecp library/ecp.o
2538
2539 # Run the tests
2540 # -------------
2541
2542 msg "test suites: full with accelerated EC algs and some key types"
2543 make test
2544}
2545
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002546# Run tests with only (non-)Weierstrass accelerated
2547# Common code used in:
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002548# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
2549# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002550common_test_psa_crypto_config_accel_ecc_some_curves () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002551 weierstrass=$1
2552 if [ $weierstrass -eq 1 ]; then
2553 desc="Weierstrass"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002554 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002555 desc="non-Weierstrass"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002556 fi
2557
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002558 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002559
2560 # Algorithms and key types to accelerate
2561 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2562 ALG_ECDH \
2563 ALG_JPAKE \
2564 $(helper_get_psa_key_type_list "ECC")"
2565
2566 # Note: Curves are handled in a special way by the libtestdriver machinery,
2567 # so we only want to include them in the accel list when building the main
2568 # libraries, hence the use of a separate variable.
2569 # Note: the following loop is a modified version of
2570 # helper_get_psa_curve_list that only keeps Weierstrass families.
2571 loc_weierstrass_list=""
2572 loc_non_weierstrass_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002573 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
2574 case $item in
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002575 ECC_BRAINPOOL*|ECC_SECP*)
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002576 loc_weierstrass_list="$loc_weierstrass_list $item"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002577 ;;
2578 *)
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002579 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002580 ;;
2581 esac
2582 done
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002583 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002584 loc_curve_list=$loc_weierstrass_list
2585 else
2586 loc_curve_list=$loc_non_weierstrass_list
2587 fi
2588
2589 # Configure
2590 # ---------
2591
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002592 # Start with config crypto_full and remove PK_C:
2593 # that's what's supported now, see docs/driver-only-builds.md.
2594 helper_libtestdriver1_adjust_config "crypto_full"
2595 scripts/config.py unset MBEDTLS_PK_C
2596 scripts/config.py unset MBEDTLS_PK_PARSE_C
2597 scripts/config.py unset MBEDTLS_PK_WRITE_C
2598 # We need to disable RSA too or PK will be re-enabled.
2599 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
2600 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
2601 scripts/config.py unset MBEDTLS_RSA_C
2602 scripts/config.py unset MBEDTLS_PKCS1_V15
2603 scripts/config.py unset MBEDTLS_PKCS1_V21
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002604
2605 # Disable modules that are accelerated - some will be re-enabled
2606 scripts/config.py unset MBEDTLS_ECDSA_C
2607 scripts/config.py unset MBEDTLS_ECDH_C
2608 scripts/config.py unset MBEDTLS_ECJPAKE_C
2609 scripts/config.py unset MBEDTLS_ECP_C
2610
2611 # Disable all curves - those that aren't accelerated should be re-enabled
2612 helper_disable_builtin_curves
2613
2614 # Restartable feature is not yet supported by PSA. Once it will in
2615 # the future, the following line could be removed (see issues
2616 # 6061, 6332 and following ones)
2617 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2618
2619 # this is not supported by the driver API yet
2620 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2621
2622 # Build
2623 # -----
2624
2625 # These hashes are needed for some ECDSA signature tests.
2626 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2627 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2628 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2629
2630 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
2631
2632 # We expect ECDH to be re-enabled for the missing curves
2633 grep mbedtls_ecdh_ library/ecdh.o
2634 # We expect ECP to be re-enabled, however the parts specific to the
2635 # families of curves that are accelerated should be ommited.
2636 # - functions with mxz in the name are specific to Montgomery curves
2637 # - ecp_muladd is specific to Weierstrass curves
2638 ##nm library/ecp.o | tee ecp.syms
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002639 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002640 not grep mbedtls_ecp_muladd library/ecp.o
2641 grep mxz library/ecp.o
2642 else
2643 grep mbedtls_ecp_muladd library/ecp.o
2644 not grep mxz library/ecp.o
2645 fi
2646 # We expect ECDSA and ECJPAKE to be re-enabled only when
2647 # Weierstrass curves are not accelerated
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002648 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002649 not grep mbedtls_ecdsa library/ecdsa.o
2650 not grep mbedtls_ecjpake library/ecjpake.o
2651 else
2652 grep mbedtls_ecdsa library/ecdsa.o
2653 grep mbedtls_ecjpake library/ecjpake.o
2654 fi
2655
2656 # Run the tests
2657 # -------------
2658
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002659 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
2660 make test
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002661}
2662
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002663component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002664 common_test_psa_crypto_config_accel_ecc_some_curves 1
2665}
2666
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002667component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002668 common_test_psa_crypto_config_accel_ecc_some_curves 0
2669}
2670
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002671# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
2672# ECDH, ECDSA) with and without drivers.
2673# The input parameter is a boolean value which indicates:
2674# - 0 keep built-in EC algs,
2675# - 1 exclude built-in EC algs (driver only).
2676#
2677# This is used by the two following components to ensure they always use the
2678# same config, except for the use of driver or built-in EC algorithms:
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002679# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
2680# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002681# This supports comparing their test coverage with analyze_outcomes.py.
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02002682config_psa_crypto_config_ecp_light_only () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002683 driver_only="$1"
Valerio Setti42d5f192023-03-20 13:54:41 +01002684 # start with config full for maximum coverage (also enables USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002685 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002686 if [ "$driver_only" -eq 1 ]; then
Valerio Setti42d5f192023-03-20 13:54:41 +01002687 # Disable modules that are accelerated
2688 scripts/config.py unset MBEDTLS_ECDSA_C
2689 scripts/config.py unset MBEDTLS_ECDH_C
2690 scripts/config.py unset MBEDTLS_ECJPAKE_C
Valerio Setti29b395c2023-04-05 18:20:30 +02002691 scripts/config.py unset MBEDTLS_ECP_C
Valerio Setti42d5f192023-03-20 13:54:41 +01002692 fi
2693
2694 # Restartable feature is not yet supported by PSA. Once it will in
2695 # the future, the following line could be removed (see issues
2696 # 6061, 6332 and following ones)
2697 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Setti42d5f192023-03-20 13:54:41 +01002698}
2699
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002700# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
2701component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002702 msg "build: full with accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002703
2704 # Algorithms and key types to accelerate
2705 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2706 ALG_ECDH \
2707 ALG_JPAKE \
Valerio Setti0a342c92023-09-01 09:12:31 +02002708 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002709
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002710 # Note: Those are handled in a special way by the libtestdriver machinery,
2711 # so we only want to include them in the accel list when building the main
2712 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002713 loc_curve_list="$(helper_get_psa_curve_list)"
Valerio Setti42d5f192023-03-20 13:54:41 +01002714
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002715 # Configure
2716 # ---------
Valerio Setti42d5f192023-03-20 13:54:41 +01002717
2718 # Use the same config as reference, only without built-in EC algs
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02002719 config_psa_crypto_config_ecp_light_only 1
Valerio Setti42d5f192023-03-20 13:54:41 +01002720
Valerio Setti0a342c92023-09-01 09:12:31 +02002721 # Do not disable builtin curves because that support is required for:
Valerio Settib2fd6732023-08-15 17:10:47 +02002722 # - MBEDTLS_PK_PARSE_EC_EXTENDED
2723 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
2724
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002725 # Build
2726 # -----
2727
2728 # These hashes are needed for some ECDSA signature tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02002729 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2730 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002731 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2732
Valerio Settib2fd6732023-08-15 17:10:47 +02002733 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Valerio Setti42d5f192023-03-20 13:54:41 +01002734
2735 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
2736 not grep mbedtls_ecdsa_ library/ecdsa.o
2737 not grep mbedtls_ecdh_ library/ecdh.o
2738 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Setti29b395c2023-04-05 18:20:30 +02002739 not grep mbedtls_ecp_mul library/ecp.o
Valerio Setti42d5f192023-03-20 13:54:41 +01002740
2741 # Run the tests
2742 # -------------
2743
Gilles Peskine14302ed2023-07-19 19:30:04 +02002744 msg "test suites: full with accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002745 make test
2746
Gilles Peskine14302ed2023-07-19 19:30:04 +02002747 msg "ssl-opt: full with accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002748 tests/ssl-opt.sh
2749}
2750
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002751# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
2752component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002753 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002754
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02002755 config_psa_crypto_config_ecp_light_only 0
Valerio Setti42d5f192023-03-20 13:54:41 +01002756
2757 make
2758
Gilles Peskine14302ed2023-07-19 19:30:04 +02002759 msg "test suites: full with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002760 make test
2761
Gilles Peskine14302ed2023-07-19 19:30:04 +02002762 msg "ssl-opt: full with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002763 tests/ssl-opt.sh
2764}
2765
Valerio Settie618cb02023-04-12 14:59:16 +02002766# This helper function is used by:
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002767# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
2768# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Valerio Settie618cb02023-04-12 14:59:16 +02002769# to ensure that both tests use the same underlying configuration when testing
2770# driver's coverage with analyze_outcomes.py.
2771#
2772# This functions accepts 1 boolean parameter as follows:
2773# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
2774# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
2775# - 0: include built-in implementation of EC algorithms.
2776#
2777# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
2778# on the ECP module.
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002779config_psa_crypto_no_ecp_at_all () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002780 driver_only="$1"
Valerio Settiaafe9002023-06-26 15:23:44 +02002781 # start with full config for maximum coverage (also enables USE_PSA)
2782 helper_libtestdriver1_adjust_config "full"
2783
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002784 if [ "$driver_only" -eq 1 ]; then
Valerio Settie618cb02023-04-12 14:59:16 +02002785 # Disable modules that are accelerated
2786 scripts/config.py unset MBEDTLS_ECDSA_C
2787 scripts/config.py unset MBEDTLS_ECDH_C
2788 scripts/config.py unset MBEDTLS_ECJPAKE_C
2789 # Disable ECP module (entirely)
2790 scripts/config.py unset MBEDTLS_ECP_C
Valerio Settie618cb02023-04-12 14:59:16 +02002791 fi
2792
Valerio Settiaecd32c2023-06-14 10:42:31 +02002793 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
2794 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
Valerio Settiaddeee42023-06-14 10:46:55 +02002795 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
Ronald Cron6b49b552023-07-20 09:57:54 +02002796 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Valerio Settiaecd32c2023-06-14 10:42:31 +02002797
Valerio Settie618cb02023-04-12 14:59:16 +02002798 # Restartable feature is not yet supported by PSA. Once it will in
2799 # the future, the following line could be removed (see issues
2800 # 6061, 6332 and following ones)
2801 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Settie618cb02023-04-12 14:59:16 +02002802}
2803
2804# Build and test a configuration where driver accelerates all EC algs while
2805# all support and dependencies from ECP and ECP_LIGHT are removed on the library
2806# side.
2807#
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002808# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
2809component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002810 msg "build: full + accelerated EC algs - ECP"
Valerio Settie618cb02023-04-12 14:59:16 +02002811
2812 # Algorithms and key types to accelerate
2813 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2814 ALG_ECDH \
2815 ALG_JPAKE \
Valerio Setti0a342c92023-09-01 09:12:31 +02002816 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002817
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002818 # Note: Those are handled in a special way by the libtestdriver machinery,
2819 # so we only want to include them in the accel list when building the main
2820 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002821 loc_curve_list="$(helper_get_psa_curve_list)"
Valerio Settie618cb02023-04-12 14:59:16 +02002822
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002823 # Configure
2824 # ---------
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002825
Valerio Settie618cb02023-04-12 14:59:16 +02002826 # Set common configurations between library's and driver's builds
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002827 config_psa_crypto_no_ecp_at_all 1
Valerio Settib2fd6732023-08-15 17:10:47 +02002828 # Disable all the builtin curves. All the required algs are accelerated.
2829 helper_disable_builtin_curves
Valerio Settie618cb02023-04-12 14:59:16 +02002830
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002831 # Build
2832 # -----
Valerio Settie618cb02023-04-12 14:59:16 +02002833
2834 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02002835 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
2836 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2837 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Valerio Settie618cb02023-04-12 14:59:16 +02002838
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +02002839 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
Valerio Settie618cb02023-04-12 14:59:16 +02002840
Valerio Settib2fd6732023-08-15 17:10:47 +02002841 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Valerio Settie618cb02023-04-12 14:59:16 +02002842
2843 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
2844 not grep mbedtls_ecdsa_ library/ecdsa.o
2845 not grep mbedtls_ecdh_ library/ecdh.o
2846 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Settib2fd6732023-08-15 17:10:47 +02002847 # Also ensure that ECP module was not re-enabled
Valerio Settie618cb02023-04-12 14:59:16 +02002848 not grep mbedtls_ecp_ library/ecp.o
Valerio Settie618cb02023-04-12 14:59:16 +02002849
2850 # Run the tests
2851 # -------------
2852
Gilles Peskine14302ed2023-07-19 19:30:04 +02002853 msg "test: full + accelerated EC algs - ECP"
Valerio Settie618cb02023-04-12 14:59:16 +02002854 make test
Valerio Setti16b70f22023-06-27 17:45:49 +02002855
Gilles Peskine14302ed2023-07-19 19:30:04 +02002856 msg "ssl-opt: full + accelerated EC algs - ECP"
Valerio Setti16b70f22023-06-27 17:45:49 +02002857 tests/ssl-opt.sh
Valerio Settie618cb02023-04-12 14:59:16 +02002858}
2859
2860# Reference function used for driver's coverage analysis in analyze_outcomes.py
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002861# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
Valerio Settie618cb02023-04-12 14:59:16 +02002862# Keep in sync with its accelerated counterpart.
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002863component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002864 msg "build: full + non accelerated EC algs"
Valerio Settie618cb02023-04-12 14:59:16 +02002865
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002866 config_psa_crypto_no_ecp_at_all 0
Valerio Settie618cb02023-04-12 14:59:16 +02002867
2868 make
2869
Gilles Peskine14302ed2023-07-19 19:30:04 +02002870 msg "test: full + non accelerated EC algs"
Valerio Settie618cb02023-04-12 14:59:16 +02002871 make test
Valerio Setti16b70f22023-06-27 17:45:49 +02002872
Gilles Peskine14302ed2023-07-19 19:30:04 +02002873 msg "ssl-opt: full + non accelerated EC algs"
Valerio Setti16b70f22023-06-27 17:45:49 +02002874 tests/ssl-opt.sh
Valerio Settie618cb02023-04-12 14:59:16 +02002875}
2876
Valerio Setti4e2f2442023-08-15 10:10:26 +02002877# This is a common configuration helper used directly from:
2878# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
2879# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
2880# and indirectly from:
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002881# - component_test_psa_crypto_config_accel_ecc_no_bignum
Valerio Setti4e2f2442023-08-15 10:10:26 +02002882# - accelerate all EC algs, disable RSA and FFDH
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002883# - component_test_psa_crypto_config_reference_ecc_no_bignum
Valerio Setti4e2f2442023-08-15 10:10:26 +02002884# - this is the reference component of the above
2885# - it still disables RSA and FFDH, but it uses builtin EC algs
2886# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
2887# - accelerate all EC and FFDH algs, disable only RSA
2888# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
2889# - this is the reference component of the above
2890# - it still disables RSA, but it uses builtin EC and FFDH algs
2891#
2892# This function accepts 2 parameters:
Valerio Setti5dfaca42023-09-05 08:48:51 +02002893# $1: a boolean value which states if we are testing an accelerated scenario
2894# or not.
2895# $2: a string value which states which components are tested. Allowed values
2896# are "ECC" or "ECC_DH".
Valerio Setti4e2f2442023-08-15 10:10:26 +02002897config_psa_crypto_config_accel_ecc_ffdh_no_bignum() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002898 driver_only="$1"
2899 test_target="$2"
Valerio Setti18535c32023-07-31 11:27:17 +02002900 # start with full config for maximum coverage (also enables USE_PSA)
Valerio Setti29c1b4d2023-07-27 10:08:45 +02002901 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002902
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002903 if [ "$driver_only" -eq 1 ]; then
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002904 # Disable modules that are accelerated
2905 scripts/config.py unset MBEDTLS_ECDSA_C
2906 scripts/config.py unset MBEDTLS_ECDH_C
2907 scripts/config.py unset MBEDTLS_ECJPAKE_C
2908 # Disable ECP module (entirely)
2909 scripts/config.py unset MBEDTLS_ECP_C
Manuel Pégourié-Gonnard660bbf22023-06-12 18:42:40 +02002910 # Also disable bignum
2911 scripts/config.py unset MBEDTLS_BIGNUM_C
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002912 fi
2913
2914 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
2915 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
2916 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
2917 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2918
Manuel Pégourié-Gonnard7dccb662023-06-12 18:28:42 +02002919 # RSA support is intentionally disabled on this test because RSA_C depends
2920 # on BIGNUM_C.
Valerio Setti2e0275d2023-07-28 16:33:13 +02002921 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
2922 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 +02002923 scripts/config.py unset MBEDTLS_RSA_C
2924 scripts/config.py unset MBEDTLS_PKCS1_V15
2925 scripts/config.py unset MBEDTLS_PKCS1_V21
2926 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2927 # Also disable key exchanges that depend on RSA
2928 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2929 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2930 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2931 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2932 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2933
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002934 if [ "$test_target" = "ECC" ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02002935 # When testing ECC only, we disable FFDH support, both from builtin and
2936 # PSA sides, and also disable the key exchanges that depend on DHM.
2937 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_FFDH
2938 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
2939 scripts/config.py unset MBEDTLS_DHM_C
2940 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2941 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2942 else
2943 # When testing ECC and DH instead, we disable DHM and depending key
2944 # exchanges only in the accelerated build
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002945 if [ "$driver_only" -eq 1 ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02002946 scripts/config.py unset MBEDTLS_DHM_C
2947 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2948 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2949 fi
2950 fi
Manuel Pégourié-Gonnard7dccb662023-06-12 18:28:42 +02002951
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002952 # Restartable feature is not yet supported by PSA. Once it will in
2953 # the future, the following line could be removed (see issues
2954 # 6061, 6332 and following ones)
2955 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2956}
2957
Valerio Setti4e2f2442023-08-15 10:10:26 +02002958# Common helper used by:
2959# - component_test_psa_crypto_config_accel_ecc_no_bignum
2960# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002961#
Valerio Setti4e2f2442023-08-15 10:10:26 +02002962# The goal is to build and test accelerating either:
2963# - ECC only or
2964# - both ECC and FFDH
2965#
2966# It is meant to be used in conjunction with
Valerio Setti5dfaca42023-09-05 08:48:51 +02002967# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
2968# coverage analysis in the "analyze_outcomes.py" script.
Valerio Setti4e2f2442023-08-15 10:10:26 +02002969common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002970 test_target="$1"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002971
Valerio Setti5dfaca42023-09-05 08:48:51 +02002972 # This is an internal helper to simplify text message handling
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002973 if [ "$test_target" = "ECC_DH" ]; then
2974 accel_text="ECC/FFDH"
2975 removed_text="ECP - DH"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002976 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002977 accel_text="ECC"
2978 removed_text="ECP"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002979 fi
2980
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002981 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002982
2983 # By default we accelerate all EC keys/algs
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002984 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2985 ALG_ECDH \
2986 ALG_JPAKE \
Valerio Setti0a342c92023-09-01 09:12:31 +02002987 $(helper_get_psa_key_type_list "ECC")"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002988 # Optionally we can also add DH to the list of accelerated items
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002989 if [ "$test_target" = "ECC_DH" ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02002990 loc_accel_list="$loc_accel_list \
2991 ALG_FFDH \
Manuel Pégourié-Gonnard85ff5e62023-09-22 09:05:48 +02002992 $(helper_get_psa_key_type_list "DH")"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002993 fi
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002994
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002995 # Note: Those are handled in a special way by the libtestdriver machinery,
2996 # so we only want to include them in the accel list when building the main
2997 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002998 loc_curve_list="$(helper_get_psa_curve_list)"
2999
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003000 # Configure
3001 # ---------
3002
3003 # Set common configurations between library's and driver's builds
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003004 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
Valerio Settib2fd6732023-08-15 17:10:47 +02003005 # Disable all the builtin curves. All the required algs are accelerated.
3006 helper_disable_builtin_curves
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003007
3008 # Build
3009 # -----
3010
3011 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02003012 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
3013 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3014 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003015
3016 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
3017
Valerio Settib2fd6732023-08-15 17:10:47 +02003018 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003019
3020 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
3021 not grep mbedtls_ecdsa_ library/ecdsa.o
3022 not grep mbedtls_ecdh_ library/ecdh.o
3023 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Setti4e2f2442023-08-15 10:10:26 +02003024 # Also ensure that ECP, RSA, [DHM] or BIGNUM modules were not re-enabled
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003025 not grep mbedtls_ecp_ library/ecp.o
Manuel Pégourié-Gonnard06aebe42023-06-12 18:33:34 +02003026 not grep mbedtls_rsa_ library/rsa.o
Manuel Pégourié-Gonnard660bbf22023-06-12 18:42:40 +02003027 not grep mbedtls_mpi_ library/bignum.o
Valerio Setti4e2f2442023-08-15 10:10:26 +02003028 not grep mbedtls_dhm_ library/dhm.o
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003029
3030 # Run the tests
3031 # -------------
3032
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003033 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - DHM - BIGNUM"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003034
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003035 make test
3036
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003037 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Valerio Setti18535c32023-07-31 11:27:17 +02003038 tests/ssl-opt.sh
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003039}
3040
Valerio Setti4e2f2442023-08-15 10:10:26 +02003041# Common helper used by:
3042# - component_test_psa_crypto_config_reference_ecc_no_bignum
3043# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
3044#
3045# The goal is to build and test a reference scenario (i.e. with builtin
3046# components) compared to the ones used in
3047# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
3048#
3049# It is meant to be used in conjunction with
3050# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
3051# coverage analysis in "analyze_outcomes.py" script.
3052common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003053 test_target="$1"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003054
Valerio Setti5dfaca42023-09-05 08:48:51 +02003055 # This is an internal helper to simplify text message handling
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003056 if [ "$test_target" = "ECC_DH" ]; then
3057 accel_text="ECC/FFDH"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003058 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003059 accel_text="ECC"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003060 fi
3061
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003062 msg "build: full + non accelerated $accel_text algs + USE_PSA"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003063
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003064 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003065
3066 make
3067
Valerio Setti29c1b4d2023-07-27 10:08:45 +02003068 msg "test suites: full + non accelerated EC algs + USE_PSA"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003069 make test
3070
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003071 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
Valerio Setti18535c32023-07-31 11:27:17 +02003072 tests/ssl-opt.sh
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003073}
3074
Valerio Setti4e2f2442023-08-15 10:10:26 +02003075component_test_psa_crypto_config_accel_ecc_no_bignum () {
3076 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
3077}
3078
3079component_test_psa_crypto_config_reference_ecc_no_bignum () {
3080 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
3081}
3082
3083component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
3084 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
3085}
3086
3087component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
3088 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
3089}
3090
Valerio Settiac6d35f2023-08-04 12:49:11 +02003091# Helper for setting common configurations between:
3092# - component_test_tfm_config_p256m_driver_accel_ec()
3093# - component_test_tfm_config()
Valerio Setti52ba0e32023-08-04 12:43:03 +02003094common_tfm_config () {
3095 # Enable TF-M config
Valerio Settic5c4bd22023-08-03 14:28:20 +02003096 cp configs/tfm_mbedcrypto_config_profile_medium.h "$CONFIG_H"
3097 cp configs/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
3098
Valerio Setti52ba0e32023-08-04 12:43:03 +02003099 # Adjust for the fact that we're building outside the TF-M environment.
3100 #
3101 # TF-M has separation, our build doesn't
3102 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SPM
3103 scripts/config.py unset MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
3104 # TF-M provdes its own (dummy) implemenation, from their tree
3105 scripts/config.py unset MBEDTLS_AES_DECRYPT_ALT
3106 scripts/config.py unset MBEDTLS_AES_SETKEY_DEC_ALT
3107 # We have an OS that provides entropy, use it
3108 scripts/config.py unset MBEDTLS_NO_PLATFORM_ENTROPY
3109
3110 # Other config adjustments to make the tests pass.
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003111 # Those should probably be adopted upstream.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003112 #
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003113 # - USE_PSA_CRYPTO for PK_HAVE_ECC_KEYS
3114 echo "#define MBEDTLS_USE_PSA_CRYPTO" >> "$CONFIG_H"
Valerio Setti52ba0e32023-08-04 12:43:03 +02003115 # pkparse.c and pkwrite.c fail to link without this
3116 echo "#define MBEDTLS_OID_C" >> "$CONFIG_H"
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003117 # - ASN1_[PARSE/WRITE]_C found by check_config.h for pkparse/pkwrite
3118 echo "#define MBEDTLS_ASN1_PARSE_C" >> "$CONFIG_H"
3119 echo "#define MBEDTLS_ASN1_WRITE_C" >> "$CONFIG_H"
3120 # - MD_C for HKDF_C
3121 echo "#define MBEDTLS_MD_C" >> "$CONFIG_H"
Valerio Setti52ba0e32023-08-04 12:43:03 +02003122
Manuel Pégourié-Gonnardf7298cd2023-09-18 09:55:24 +02003123 # Config adjustments for better test coverage in our environment.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003124 # These are not needed just to build and pass tests.
3125 #
3126 # Enable filesystem I/O for the benefit of PK parse/write tests.
3127 echo "#define MBEDTLS_FS_IO" >> "$CONFIG_H"
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003128 # Disable this for maximal ASan efficiency
3129 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
3130
Manuel Pégourié-Gonnardf7298cd2023-09-18 09:55:24 +02003131 # Config adjustments for features that are not supported
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003132 # when using only drivers / by p256-m
3133 #
3134 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
3135 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
3136 # Disable deterministic ECDSA as p256-m only does randomized
3137 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
3138
Valerio Setti52ba0e32023-08-04 12:43:03 +02003139}
3140
Valerio Settiac6d35f2023-08-04 12:49:11 +02003141# Keep this in sync with component_test_tfm_config() as they are both meant
3142# to be used in analyze_outcomes.py for driver's coverage analysis.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003143component_test_tfm_config_p256m_driver_accel_ec () {
3144 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
3145
3146 common_tfm_config
Valerio Settic5c4bd22023-08-03 14:28:20 +02003147
Valerio Settic5c4bd22023-08-03 14:28:20 +02003148 # Build crypto library specifying we want to use P256M code for EC operations
Manuel Pégourié-Gonnardeda70862023-09-22 12:17:50 +02003149 make CFLAGS="$ASAN_CFLAGS -DMBEDTLS_PSA_P256M_DRIVER_ENABLED -I../tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
Manuel Pégourié-Gonnard3c4f3442023-09-22 09:20:42 +02003150
Valerio Settic5c4bd22023-08-03 14:28:20 +02003151 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003152 not grep mbedtls_ecdsa_ library/ecdsa.o
Valerio Settic5c4bd22023-08-03 14:28:20 +02003153 not grep mbedtls_ecdh_ library/ecdh.o
3154 not grep mbedtls_ecjpake_ library/ecjpake.o
3155 # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003156 not grep mbedtls_ecp_ library/ecp.o
Valerio Settic5c4bd22023-08-03 14:28:20 +02003157 not grep mbedtls_rsa_ library/rsa.o
3158 not grep mbedtls_dhm_ library/dhm.o
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003159 not grep mbedtls_mpi_ library/bignum.o
Valerio Settic5c4bd22023-08-03 14:28:20 +02003160
3161 # Run the tests
Valerio Setti52ba0e32023-08-04 12:43:03 +02003162 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
Valerio Settic5c4bd22023-08-03 14:28:20 +02003163 make test
Valerio Setti52ba0e32023-08-04 12:43:03 +02003164}
Valerio Settic5c4bd22023-08-03 14:28:20 +02003165
Valerio Settiac6d35f2023-08-04 12:49:11 +02003166# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
3167# they are both meant to be used in analyze_outcomes.py for driver's coverage
3168# analysis.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003169component_test_tfm_config() {
3170 common_tfm_config
3171
3172 msg "build: TF-M config"
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02003173 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' tests
Valerio Setti52ba0e32023-08-04 12:43:03 +02003174
3175 msg "test: TF-M config"
3176 make test
Valerio Settic5c4bd22023-08-03 14:28:20 +02003177}
3178
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003179# Common helper for component_full_without_ecdhe_ecdsa() and
3180# component_full_without_ecdhe_ecdsa_and_tls13() which:
3181# - starts from the "full" configuration minus the list of symbols passed in
3182# as 1st parameter
3183# - build
3184# - test only TLS (i.e. test_suite_tls and ssl-opt)
3185build_full_minus_something_and_test_tls () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003186 symbols_to_disable="$1"
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003187
3188 msg "build: full minus something, test TLS"
3189
3190 scripts/config.py full
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003191 for sym in $symbols_to_disable; do
3192 echo "Disabling $sym"
3193 scripts/config.py unset $sym
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003194 done
3195
3196 make
3197
3198 msg "test: full minus something, test TLS"
3199 ( cd tests; ./test_suite_ssl )
3200
3201 msg "ssl-opt: full minus something, test TLS"
3202 tests/ssl-opt.sh
3203}
3204
3205component_full_without_ecdhe_ecdsa () {
3206 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED"
3207}
3208
3209component_full_without_ecdhe_ecdsa_and_tls13 () {
3210 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
3211 MBEDTLS_SSL_PROTO_TLS1_3"
3212}
3213
Valerio Setti249b18a2023-06-20 12:08:30 +02003214# This is an helper used by:
3215# - component_test_psa_ecc_key_pair_no_derive
3216# - component_test_psa_ecc_key_pair_no_generate
3217# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
3218# enabled, but one. Input arguments are as follows:
3219# - $1 is the key type under test, i.e. ECC/RSA/DH
3220# - $2 is the key option to be unset (i.e. generate, derive, etc)
Valerio Settia9836552023-06-22 11:22:23 +02003221build_and_test_psa_want_key_pair_partial() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003222 key_type=$1
3223 unset_option=$2
3224 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003225
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003226 msg "build: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003227 scripts/config.py full
Valerio Setti249b18a2023-06-20 12:08:30 +02003228 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3229 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3230
3231 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
3232 # crypto_config.h so we just disable the one we don't want.
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003233 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
Valerio Setti249b18a2023-06-20 12:08:30 +02003234
Valerio Settif6587be2023-06-22 11:33:14 +02003235 make CC=gcc CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Valerio Setti249b18a2023-06-20 12:08:30 +02003236
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003237 msg "test: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003238 make test
3239}
3240
3241component_test_psa_ecc_key_pair_no_derive() {
Valerio Settia9836552023-06-22 11:22:23 +02003242 build_and_test_psa_want_key_pair_partial "ECC" "DERIVE"
Valerio Setti249b18a2023-06-20 12:08:30 +02003243}
3244
3245component_test_psa_ecc_key_pair_no_generate() {
Valerio Settia9836552023-06-22 11:22:23 +02003246 build_and_test_psa_want_key_pair_partial "ECC" "GENERATE"
Valerio Setti249b18a2023-06-20 12:08:30 +02003247}
3248
Ronald Cron403c15c2021-09-13 09:38:05 +02003249component_test_psa_crypto_config_accel_rsa_signature () {
3250 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
3251
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003252 loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
3253
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003254 # Configure
3255 # ---------
Ronald Cron403c15c2021-09-13 09:38:05 +02003256
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003257 # Start from default config (no TLS 1.3, no USE_PSA)
3258 helper_libtestdriver1_adjust_config "default"
Ronald Cron403c15c2021-09-13 09:38:05 +02003259
3260 # It seems it is not possible to remove only the support for RSA signature
3261 # in the library. Thus we have to remove all RSA support (signature and
3262 # encryption/decryption). AS there is no driver support for asymmetric
3263 # encryption/decryption so far remove RSA encryption/decryption from the
3264 # application algorithm list.
Ronald Cron6b49b552023-07-20 09:57:54 +02003265 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3266 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
Ronald Cron403c15c2021-09-13 09:38:05 +02003267
Manuel Pégourié-Gonnardaed1d782023-06-12 17:22:24 +02003268 # Remove RSA support and its dependencies
3269 scripts/config.py unset MBEDTLS_RSA_C
3270 scripts/config.py unset MBEDTLS_PKCS1_V15
3271 scripts/config.py unset MBEDTLS_PKCS1_V21
3272 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
3273 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3274 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3275 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3276 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
3277 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
3278
Ronald Cron403c15c2021-09-13 09:38:05 +02003279 # Make sure both the library and the test library support the SHA hash
3280 # algorithms and only those ones (SHA256 is included by default). That way:
3281 # - the test library can compute the RSA signatures even in the case of a
3282 # composite RSA signature algorithm based on a SHA hash (no other hash
3283 # used in the unit tests).
3284 # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
3285 # fulfilled as the hash SHA algorithm is supported by the library, and
3286 # thus the tests are run, not skipped.
3287 # - when testing a signature key with an algorithm wildcard built from
3288 # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
3289 # algorithm based on the hashes supported by the library is also
3290 # supported by the test library.
Manuel Pégourié-Gonnardaed1d782023-06-12 17:22:24 +02003291 # Disable unwanted hashes here, we'll enable hashes we want in loc_extra_list.
Ronald Cron6b49b552023-07-20 09:57:54 +02003292 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3293 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160_C
Ronald Cron403c15c2021-09-13 09:38:05 +02003294 scripts/config.py unset MBEDTLS_MD5_C
3295 scripts/config.py unset MBEDTLS_RIPEMD160_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003296
3297 # We need PEM parsing in the test library as well to support the import
3298 # of PEM encoded RSA keys.
Ronald Cron7612d8c2023-07-20 10:03:54 +02003299 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
3300 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003301
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003302 # Build
3303 # -----
3304
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003305 # These hashes are needed for some RSA-PSS signature tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02003306 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3307 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003308 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02003309
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003310 helper_libtestdriver1_make_main "$loc_accel_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02003311
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003312 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine827dbd92022-02-04 00:30:54 +01003313 not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
3314 not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
Ronald Cron403c15c2021-09-13 09:38:05 +02003315
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003316 # Run the tests
3317 # -------------
3318
Ronald Cron403c15c2021-09-13 09:38:05 +02003319 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
3320 make test
3321}
3322
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003323# This is a temporary test to verify that full RSA support is present even when
Valerio Setti01cc88a2023-06-15 11:53:08 +02003324# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003325component_test_new_psa_want_key_pair_symbol() {
Valerio Setti01cc88a2023-06-15 11:53:08 +02003326 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003327
Valerio Setti4590bc22023-06-13 15:39:23 +02003328 # Create a temporary output file unless there is already one set
3329 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
3330 REMOVE_OUTCOME_ON_EXIT="no"
3331 else
3332 REMOVE_OUTCOME_ON_EXIT="yes"
3333 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
3334 export MBEDTLS_TEST_OUTCOME_FILE
3335 fi
3336
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003337 # Start from crypto configuration
3338 scripts/config.py crypto
3339
3340 # Remove RSA support and its dependencies
3341 scripts/config.py unset MBEDTLS_PKCS1_V15
3342 scripts/config.py unset MBEDTLS_PKCS1_V21
3343 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3344 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3345 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3346 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
3347 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
3348 scripts/config.py unset MBEDTLS_RSA_C
3349 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
3350
3351 # Enable PSA support
3352 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3353
Valerio Setti01cc88a2023-06-15 11:53:08 +02003354 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003355 # that proper translations is done in crypto_legacy.h.
Ronald Cron6b49b552023-07-20 09:57:54 +02003356 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
3357 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
3358 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003359
3360 make
3361
Valerio Setti01cc88a2023-06-15 11:53:08 +02003362 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Valerio Setti4590bc22023-06-13 15:39:23 +02003363 make test
3364
3365 # Parse only 1 relevant line from the outcome file, i.e. a test which is
3366 # performing RSA signature.
3367 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
3368 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
3369
3370 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
3371 rm $MBEDTLS_TEST_OUTCOME_FILE
3372 fi
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003373}
3374
Ronald Cronb2312452021-05-08 14:32:59 +02003375component_test_psa_crypto_config_accel_hash () {
3376 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
3377
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003378 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3379 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3380 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Ronald Cronb2312452021-05-08 14:32:59 +02003381
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003382 # Configure
3383 # ---------
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003384
3385 # Start from default config (no TLS 1.3, no USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003386 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003387
3388 # Disable the things that are being accelerated
Ronald Cronb2312452021-05-08 14:32:59 +02003389 scripts/config.py unset MBEDTLS_MD5_C
3390 scripts/config.py unset MBEDTLS_RIPEMD160_C
3391 scripts/config.py unset MBEDTLS_SHA1_C
Manuel Pégourié-Gonnardc584c272023-03-22 00:32:04 +01003392 scripts/config.py unset MBEDTLS_SHA224_C
3393 scripts/config.py unset MBEDTLS_SHA256_C
Ronald Cronb2312452021-05-08 14:32:59 +02003394 scripts/config.py unset MBEDTLS_SHA384_C
3395 scripts/config.py unset MBEDTLS_SHA512_C
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003396 scripts/config.py unset MBEDTLS_SHA3_C
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003397
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003398 # Build
3399 # -----
3400
3401 helper_libtestdriver1_make_drivers "$loc_accel_list"
3402
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003403 helper_libtestdriver1_make_main "$loc_accel_list"
Ronald Cronb2312452021-05-08 14:32:59 +02003404
Manuel Pégourié-Gonnardc584c272023-03-22 00:32:04 +01003405 # There's a risk of something getting re-enabled via config_psa.h;
3406 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
3407 not grep mbedtls_md5 library/md5.o
3408 not grep mbedtls_sha1 library/sha1.o
3409 not grep mbedtls_sha256 library/sha256.o
3410 not grep mbedtls_sha512 library/sha512.o
3411 not grep mbedtls_ripemd160 library/ripemd160.o
Ronald Cronb2312452021-05-08 14:32:59 +02003412
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003413 # Run the tests
3414 # -------------
3415
Ronald Cronb2312452021-05-08 14:32:59 +02003416 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
3417 make test
3418}
3419
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003420component_test_psa_crypto_config_accel_hash_keep_builtins () {
3421 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
3422 # This component ensures that all the test cases for
3423 # md_psa_dynamic_dispatch with legacy+driver in test_suite_md are run.
3424
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003425 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3426 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3427 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003428
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003429 # Start from default config (no TLS 1.3, no USE_PSA)
3430 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003431
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +02003432 helper_libtestdriver1_make_drivers "$loc_accel_list"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003433
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003434 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003435
3436 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
3437 make test
3438}
3439
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003440# Auxiliary function to build config for hashes with and without drivers
3441config_psa_crypto_hash_use_psa () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003442 driver_only="$1"
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003443 # start with config full for maximum coverage (also enables USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003444 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003445 if [ "$driver_only" -eq 1 ]; then
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003446 # disable the built-in implementation of hashes
3447 scripts/config.py unset MBEDTLS_MD5_C
3448 scripts/config.py unset MBEDTLS_RIPEMD160_C
3449 scripts/config.py unset MBEDTLS_SHA1_C
3450 scripts/config.py unset MBEDTLS_SHA224_C
3451 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
Dave Rodgman5b89c552023-10-10 14:59:02 +01003452 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003453 scripts/config.py unset MBEDTLS_SHA384_C
3454 scripts/config.py unset MBEDTLS_SHA512_C
Dave Rodgmanbe7915a2023-10-11 10:46:38 +01003455 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003456 scripts/config.py unset MBEDTLS_SHA3_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003457 fi
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003458}
3459
Przemek Stekiel120ed8f2022-10-27 10:29:15 +02003460# Note that component_test_psa_crypto_config_reference_hash_use_psa
3461# is related to this component and both components need to be kept in sync.
3462# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003463component_test_psa_crypto_config_accel_hash_use_psa () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02003464 msg "test: full with accelerated hashes"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003465
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003466 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3467 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3468 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003469
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003470 # Configure
3471 # ---------
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003472
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003473 config_psa_crypto_hash_use_psa 1
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003474
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003475 # Build
3476 # -----
3477
3478 helper_libtestdriver1_make_drivers "$loc_accel_list"
3479
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003480 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003481
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003482 # There's a risk of something getting re-enabled via config_psa.h;
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01003483 # 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 +02003484 not grep mbedtls_md5 library/md5.o
3485 not grep mbedtls_sha1 library/sha1.o
Manuel Pégourié-Gonnard7b0825d2022-07-11 11:06:09 +02003486 not grep mbedtls_sha256 library/sha256.o
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003487 not grep mbedtls_sha512 library/sha512.o
3488 not grep mbedtls_ripemd160 library/ripemd160.o
3489
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003490 # Run the tests
3491 # -------------
3492
Gilles Peskine14302ed2023-07-19 19:30:04 +02003493 msg "test: full with accelerated hashes"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003494 make test
Andrzej Kurek07e35702022-09-05 15:39:23 -04003495
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003496 # This is mostly useful so that we can later compare outcome files with
3497 # the reference config in analyze_outcomes.py, to check that the
3498 # dependency declarations in ssl-opt.sh and in TLS code are correct.
Gilles Peskine14302ed2023-07-19 19:30:04 +02003499 msg "test: ssl-opt.sh, full with accelerated hashes"
Przemek Stekiel5f6f32a2022-10-27 08:24:43 +02003500 tests/ssl-opt.sh
Andrzej Kurek07e35702022-09-05 15:39:23 -04003501
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003502 # This is to make sure all ciphersuites are exercised, but we don't need
3503 # interop testing (besides, we already got some from ssl-opt.sh).
Gilles Peskine14302ed2023-07-19 19:30:04 +02003504 msg "test: compat.sh, full with accelerated hashes"
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003505 tests/compat.sh -p mbedTLS -V YES
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003506}
3507
Przemek Stekiel120ed8f2022-10-27 10:29:15 +02003508# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
3509# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
3510# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
3511# Both components need to be kept in sync.
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003512component_test_psa_crypto_config_reference_hash_use_psa() {
Gilles Peskine14302ed2023-07-19 19:30:04 +02003513 msg "test: full without accelerated hashes"
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003514
3515 config_psa_crypto_hash_use_psa 0
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003516
Przemek Stekielab0451b2022-10-24 11:29:35 +02003517 make
3518
Gilles Peskine14302ed2023-07-19 19:30:04 +02003519 msg "test: full without accelerated hashes"
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003520 make test
3521
Gilles Peskine14302ed2023-07-19 19:30:04 +02003522 msg "test: ssl-opt.sh, full without accelerated hashes"
Przemek Stekiel5f6f32a2022-10-27 08:24:43 +02003523 tests/ssl-opt.sh
Ronald Cron3a8714d2021-10-18 11:26:01 +02003524}
Manuel Pégourié-Gonnard97ab2a32022-07-06 10:46:57 +02003525
John Durkop4377bf72020-10-23 01:26:57 -07003526component_test_psa_crypto_config_accel_cipher () {
3527 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
3528
3529 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 -08003530
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003531 # Configure
3532 # ---------
John Durkop1b7ee052020-11-27 08:51:22 -08003533
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003534 # Start from the default config (no TLS 1.3, no USE_PSA)
3535 helper_libtestdriver1_adjust_config "default"
John Durkop1b7ee052020-11-27 08:51:22 -08003536
Manuel Pégourié-Gonnard7ae342f2023-06-08 09:26:04 +02003537 # There is no intended accelerator support for ALG CMAC. Therefore, asking
3538 # for it in the build implies the inclusion of the Mbed TLS cipher
3539 # operations. As we want to test here with cipher operations solely
3540 # supported by accelerators, disabled this PSA configuration option.
3541 # (Note: the same applies to STREAM_CIPHER and ECB_NO_PADDING, which are
3542 # already disabled by helper_libtestdriver1_adjust_config above.)
Ronald Cron6b49b552023-07-20 09:57:54 +02003543 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
John Durkop1b7ee052020-11-27 08:51:22 -08003544
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003545 # Disable the things that are being accelerated
John Durkop1b7ee052020-11-27 08:51:22 -08003546 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3547 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
3548 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
3549 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
3550 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
3551 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
3552 scripts/config.py unset MBEDTLS_DES_C
3553
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003554 # Build
3555 # -----
John Durkop1b7ee052020-11-27 08:51:22 -08003556
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003557 helper_libtestdriver1_make_drivers "$loc_accel_list"
3558
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003559 helper_libtestdriver1_make_main "$loc_accel_list"
John Durkop1b7ee052020-11-27 08:51:22 -08003560
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003561 # Make sure this was not re-enabled by accident (additive config)
John Durkop1b7ee052020-11-27 08:51:22 -08003562 not grep mbedtls_des* library/des.o
3563
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003564 # Run the tests
3565 # -------------
3566
John Durkop1b7ee052020-11-27 08:51:22 -08003567 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
3568 make test
3569}
3570
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003571component_test_psa_crypto_config_accel_aead () {
3572 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
3573
Przemek Stekielee1bb412022-10-11 11:52:25 +02003574 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 +02003575
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003576 # Configure
3577 # ---------
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003578
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003579 # Start from default config (no TLS 1.3, no USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003580 helper_libtestdriver1_adjust_config "default"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003581
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003582 # Disable things that are being accelerated
Przemek Stekielee1bb412022-10-11 11:52:25 +02003583 scripts/config.py unset MBEDTLS_GCM_C
3584 scripts/config.py unset MBEDTLS_CCM_C
3585 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
3586 # Features that depend on AEAD
3587 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel072fad12022-10-13 09:59:52 +02003588 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003589
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003590 # Build
3591 # -----
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003592
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003593 helper_libtestdriver1_make_drivers "$loc_accel_list"
3594
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003595 helper_libtestdriver1_make_main "$loc_accel_list"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003596
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003597 # Make sure this was not re-enabled by accident (additive config)
Przemek Stekielee1bb412022-10-11 11:52:25 +02003598 not grep mbedtls_ccm library/ccm.o
3599 not grep mbedtls_gcm library/gcm.o
3600 not grep mbedtls_chachapoly library/chachapoly.o
3601
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003602 # Run the tests
3603 # -------------
3604
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003605 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
3606 make test
3607}
3608
Gilles Peskine36dea152023-07-20 22:19:45 +02003609component_test_aead_chachapoly_disabled() {
3610 msg "build: full minus CHACHAPOLY"
John Durkopf4c4cb02020-10-28 20:09:55 -07003611 scripts/config.py full
John Durkop9814fa22020-11-04 12:28:15 -08003612 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Ronald Cron6b49b552023-07-20 09:57:54 +02003613 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
John Durkopf4c4cb02020-10-28 20:09:55 -07003614 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop6ba40d12020-11-10 08:50:04 -08003615
Gilles Peskine36dea152023-07-20 22:19:45 +02003616 msg "test: full minus CHACHAPOLY"
3617 make test
3618}
3619
3620component_test_aead_only_ccm() {
3621 msg "build: full minus CHACHAPOLY and GCM"
3622 scripts/config.py full
3623 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
3624 scripts/config.py unset MBEDTLS_GCM_C
3625 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
3626 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
3627 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
3628
3629 msg "test: full minus CHACHAPOLY and GCM"
John Durkop9814fa22020-11-04 12:28:15 -08003630 make test
John Durkopf4c4cb02020-10-28 20:09:55 -07003631}
3632
Ronald Crone501d0e2023-07-10 08:31:19 +02003633component_test_ccm_aes_sha256() {
3634 msg "build: CCM + AES + SHA256 configuration"
3635
Ronald Cron7612d8c2023-07-20 10:03:54 +02003636 cp "$CONFIG_TEST_DRIVER_H" "$CONFIG_H"
Ronald Cron6b49b552023-07-20 09:57:54 +02003637 cp configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
Ronald Crone501d0e2023-07-10 08:31:19 +02003638
3639 make CC=gcc
3640
3641 msg "test: CCM + AES + SHA256 configuration"
3642 make test
3643}
3644
John Durkop9814fa22020-11-04 12:28:15 -08003645# 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 -07003646component_build_psa_accel_alg_ecdh() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003647 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
John Durkopd0321952020-10-29 21:37:36 -07003648 scripts/config.py full
John Durkopd0321952020-10-29 21:37:36 -07003649 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003650 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkopd0321952020-10-29 21:37:36 -07003651 scripts/config.py unset MBEDTLS_ECDH_C
3652 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3653 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
3654 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
3655 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3656 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
3657 # 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 -08003658 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 -07003659}
3660
John Durkop1b7ee052020-11-27 08:51:22 -08003661# This should be renamed to test and updated once the accelerator HMAC code is in place and ready to test.
3662component_build_psa_accel_alg_hmac() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003663 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
John Durkop1b7ee052020-11-27 08:51:22 -08003664 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003665 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003666 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkop1b7ee052020-11-27 08:51:22 -08003667 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3668 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3669}
3670
3671# This should be renamed to test and updated once the accelerator HKDF code is in place and ready to test.
3672component_build_psa_accel_alg_hkdf() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003673 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
John Durkop1b7ee052020-11-27 08:51:22 -08003674 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003675 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003676 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkop1b7ee052020-11-27 08:51:22 -08003677 scripts/config.py unset MBEDTLS_HKDF_C
Ronald Cron6f135e12021-12-08 16:57:54 +01003678 # Make sure to unset TLS1_3 since it requires HKDF_C and will not build properly without it.
3679 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkop1b7ee052020-11-27 08:51:22 -08003680 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3681 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3682}
3683
3684# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
3685component_build_psa_accel_alg_md5() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003686 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003687 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003688 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003689 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003690 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3691 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3692 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3693 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3694 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3695 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3696 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003697 scripts/config.py unset MBEDTLS_LMS_C
3698 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003699 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3700 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3701}
3702
3703# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
3704component_build_psa_accel_alg_ripemd160() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003705 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003706 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003707 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003708 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003709 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3710 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3711 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3712 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3713 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3714 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3715 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003716 scripts/config.py unset MBEDTLS_LMS_C
3717 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003718 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3719 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3720}
3721
3722# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
3723component_build_psa_accel_alg_sha1() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003724 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003725 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003726 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003727 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003728 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3729 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3730 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3731 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3732 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3733 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3734 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003735 scripts/config.py unset MBEDTLS_LMS_C
3736 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003737 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3738 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3739}
3740
3741# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
3742component_build_psa_accel_alg_sha224() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003743 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003744 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003745 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003746 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003747 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3748 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3749 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3750 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3751 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3752 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
John Durkop1b7ee052020-11-27 08:51:22 -08003753 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3754 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3755}
3756
3757# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
3758component_build_psa_accel_alg_sha256() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003759 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003760 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003761 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003762 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003763 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3764 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3765 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3766 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3767 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3768 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
John Durkop1b7ee052020-11-27 08:51:22 -08003769 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3770 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3771}
3772
3773# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
3774component_build_psa_accel_alg_sha384() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003775 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003776 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003777 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003778 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003779 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3780 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3781 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3782 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3783 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3784 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003785 scripts/config.py unset MBEDTLS_LMS_C
3786 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003787 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3788 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3789}
3790
3791# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
3792component_build_psa_accel_alg_sha512() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003793 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003794 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003795 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003796 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003797 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3798 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3799 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3800 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3801 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3802 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3803 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003804 scripts/config.py unset MBEDTLS_LMS_C
3805 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003806 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3807 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3808}
3809
John Durkopd0321952020-10-29 21:37:36 -07003810# 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 -08003811component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003812 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
John Durkopd0321952020-10-29 21:37:36 -07003813 scripts/config.py full
John Durkopd0321952020-10-29 21:37:36 -07003814 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003815 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003816 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
3817 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3818 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3819 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07003820 # 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 -07003821 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3822}
3823
3824# 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 -08003825component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003826 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
John Durkopbd069d32020-10-31 22:14:03 -07003827 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003828 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003829 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003830 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
3831 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3832 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3833 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07003834 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3835 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3836}
3837
3838# 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 -08003839component_build_psa_accel_alg_rsa_oaep() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003840 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
John Durkopbd069d32020-10-31 22:14:03 -07003841 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003842 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003843 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003844 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_OAEP 1
3845 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3846 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3847 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07003848 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3849 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3850}
3851
3852# 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 -08003853component_build_psa_accel_alg_rsa_pss() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003854 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
John Durkopbd069d32020-10-31 22:14:03 -07003855 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003856 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003857 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003858 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
3859 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3860 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3861 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07003862 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3863 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3864}
3865
3866# 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 -08003867component_build_psa_accel_key_type_rsa_key_pair() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003868 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_xxx + PSA_WANT_ALG_RSA_PSS"
John Durkopbd069d32020-10-31 22:14:03 -07003869 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003870 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003871 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003872 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
3873 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC 1
3874 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT 1
3875 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT 1
3876 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE 1
John Durkopbd069d32020-10-31 22:14:03 -07003877 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3878 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"
3879}
3880
3881# 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 -08003882component_build_psa_accel_key_type_rsa_public_key() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003883 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
John Durkopbd069d32020-10-31 22:14:03 -07003884 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003885 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003886 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003887 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
3888 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
John Durkopbd069d32020-10-31 22:14:03 -07003889 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3890 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 -07003891}
3892
Dave Rodgmanc164c072023-06-28 09:43:23 +01003893
Dave Rodgman904c5892023-06-28 17:36:02 +01003894support_build_tfm_armcc () {
Dave Rodgmanc164c072023-06-28 09:43:23 +01003895 armc6_cc="$ARMC6_BIN_DIR/armclang"
3896 (check_tools "$armc6_cc" > /dev/null 2>&1)
3897}
3898
Dave Rodgman904c5892023-06-28 17:36:02 +01003899component_build_tfm_armcc() {
3900 # test the TF-M configuration can build cleanly with various warning flags enabled
Ronald Cron7a93ac52023-07-20 09:49:12 +02003901 cp configs/tfm_mbedcrypto_config_profile_medium.h "$CONFIG_H"
Ronald Cron6b49b552023-07-20 09:57:54 +02003902 cp configs/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Dave Rodgmanc164c072023-06-28 09:43:23 +01003903
Dave Rodgman88651c42023-06-29 12:35:51 +01003904 msg "build: TF-M config, armclang armv7-m thumb2"
Dave Rodgmanfb374e62023-06-29 11:58:16 +01003905 make clean
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02003906 armc6_build_test "--target=arm-arm-none-eabi -march=armv7-m -mthumb -Os -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused -I../tests/include/spe"
Dave Rodgmanfb374e62023-06-29 11:58:16 +01003907}
3908
3909component_build_tfm() {
3910 # test the TF-M configuration can build cleanly with various warning flags enabled
Ronald Cron7a93ac52023-07-20 09:49:12 +02003911 cp configs/tfm_mbedcrypto_config_profile_medium.h "$CONFIG_H"
Ronald Cron6b49b552023-07-20 09:57:54 +02003912 cp configs/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Dave Rodgmanfb374e62023-06-29 11:58:16 +01003913
Dave Rodgman88651c42023-06-29 12:35:51 +01003914 msg "build: TF-M config, clang, armv7-m thumb2"
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02003915 make lib CC="clang" CFLAGS="--target=arm-linux-gnueabihf -march=armv7-m -mthumb -Os -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused -I../tests/include/spe"
Dave Rodgmanc164c072023-06-28 09:43:23 +01003916
Dave Rodgman904c5892023-06-28 17:36:02 +01003917 msg "build: TF-M config, gcc native build"
3918 make clean
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02003919 make lib CC="gcc" CFLAGS="-Os -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wformat-signedness -Wlogical-op -I../tests/include/spe"
Dave Rodgmanc164c072023-06-28 09:43:23 +01003920}
3921
Dave Rodgman6001fb22023-06-29 09:29:00 +01003922component_build_aes_variations() { # ~45s
Dave Rodgmancd040202023-06-29 09:29:00 +01003923 # aes.o has many #if defined(...) guards that intersect in complex ways.
3924 # Test that all the combinations build cleanly. The most common issue is
3925 # unused variables/functions, so ensure -Wunused is set.
3926
Dave Rodgman6001fb22023-06-29 09:29:00 +01003927 msg "build: aes.o for all combinations of relevant config options"
Dave Rodgman0f0f7692023-06-29 12:10:45 +01003928
Dave Rodgman6001fb22023-06-29 09:29:00 +01003929 for a in set unset; do
3930 for b in set unset; do
3931 for c in set unset; do
3932 for d in set unset; do
3933 for e in set unset; do
3934 for f in set unset; do
3935 for g in set unset; do
Dave Rodgman0f0f7692023-06-29 12:10:45 +01003936 echo ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
3937 echo ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
3938 echo ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
3939 echo ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
3940 echo ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
3941 echo ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
3942 echo ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman6001fb22023-06-29 09:29:00 +01003943
Dave Rodgman0f0f7692023-06-29 12:10:45 +01003944 ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
3945 ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
3946 ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
3947 ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
3948 ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
3949 ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
3950 ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman6001fb22023-06-29 09:29:00 +01003951
Dave Rodgman0f0f7692023-06-29 12:10:45 +01003952 rm -f library/aes.o
3953 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 +01003954 done
3955 done
3956 done
3957 done
3958 done
3959 done
3960 done
3961}
3962
Gilles Peskine8f073122018-11-27 15:58:47 +01003963component_test_no_platform () {
3964 # Full configuration build, without platform support, file IO and net sockets.
3965 # This should catch missing mbedtls_printf definitions, and by disabling file
3966 # IO, it should catch missing '#include <stdio.h>'
3967 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003968 scripts/config.py full
3969 scripts/config.py unset MBEDTLS_PLATFORM_C
3970 scripts/config.py unset MBEDTLS_NET_C
3971 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
3972 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
3973 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
3974 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskineef843f22022-09-18 14:05:23 +02003975 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003976 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
3977 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskine6497b5a2022-06-30 17:01:40 +02003978 scripts/config.py unset MBEDTLS_PLATFORM_SETBUF_ALT
Gilles Peskine32e889d2020-04-12 23:43:28 +02003979 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003980 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
3981 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003982 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003983 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
3984 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01003985 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
3986 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02003987 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
3988 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01003989}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00003990
Gilles Peskine8f073122018-11-27 15:58:47 +01003991component_build_no_std_function () {
3992 # catch compile bugs in _uninit functions
3993 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003994 scripts/config.py full
3995 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
3996 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02003997 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinef4d2fd42021-10-08 11:45:47 +02003998 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskinedbf7b7e2021-10-07 19:34:57 +02003999 make
Gilles Peskine8f073122018-11-27 15:58:47 +01004000}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01004001
Gilles Peskine8f073122018-11-27 15:58:47 +01004002component_build_no_ssl_srv () {
Ronald Cronde1adee2022-03-07 16:20:30 +01004003 msg "build: full config except SSL server, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004004 scripts/config.py full
4005 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02004006 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01004007}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02004008
Gilles Peskine8f073122018-11-27 15:58:47 +01004009component_build_no_ssl_cli () {
Ronald Cronde1adee2022-03-07 16:20:30 +01004010 msg "build: full config except SSL client, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004011 scripts/config.py full
4012 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02004013 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01004014}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02004015
Gilles Peskine8f073122018-11-27 15:58:47 +01004016component_build_no_sockets () {
4017 # Note, C99 compliance can also be tested with the sockets support disabled,
4018 # as that requires a POSIX platform (which isn't the same as C99).
4019 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004020 scripts/config.py full
4021 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
4022 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02004023 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01004024}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02004025
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04004026component_test_memory_buffer_allocator_backtrace () {
4027 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004028 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4029 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4030 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
4031 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02004032 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04004033 make
4034
4035 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
4036 make test
4037}
4038
4039component_test_memory_buffer_allocator () {
4040 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004041 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4042 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02004043 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Hanno Becker0fb9ba22019-02-26 14:34:13 +00004044 make
4045
4046 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
4047 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01004048
4049 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
4050 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004051 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00004052}
4053
Gilles Peskine8f073122018-11-27 15:58:47 +01004054component_test_no_max_fragment_length () {
4055 # Run max fragment length tests with MFL disabled
4056 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004057 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01004058 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4059 make
Hanno Becker5175ac62017-09-18 15:36:25 +01004060
Gilles Peskine8f073122018-11-27 15:58:47 +01004061 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004062 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01004063}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004064
Hanno Becker545ced42019-02-19 11:10:48 +00004065component_test_asan_remove_peer_certificate () {
4066 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004067 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00004068 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4069 make
4070
4071 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
4072 make test
4073
4074 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004075 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00004076
4077 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004078 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02004079
4080 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004081 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00004082}
4083
Gilles Peskine8f073122018-11-27 15:58:47 +01004084component_test_no_max_fragment_length_small_ssl_out_content_len () {
4085 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004086 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4087 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
4088 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01004089 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4090 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10004091
Gilles Peskine8f073122018-11-27 15:58:47 +01004092 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004093 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02004094
4095 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004096 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01004097}
Angus Grattonc4dd0732018-04-11 16:28:39 +10004098
Darryl Greenaad82f92019-12-02 10:53:11 +00004099component_test_variable_ssl_in_out_buffer_len () {
4100 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
4101 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
4102 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4103 make
4104
4105 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
4106 make test
4107
4108 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004109 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004110
4111 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004112 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004113}
4114
Manuel Pégourié-Gonnard6a543ba2022-11-25 11:30:10 +01004115component_test_dtls_cid_legacy () {
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004116 msg "build: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled (ASan build)"
Hannes Tschofenigfd6cca42021-10-12 09:22:33 +02004117 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 1
Darryl Greenaad82f92019-12-02 10:53:11 +00004118
4119 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4120 make
4121
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004122 msg "test: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy)"
Darryl Greenaad82f92019-12-02 10:53:11 +00004123 make test
4124
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004125 msg "test: ssl-opt.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004126 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004127
Manuel Pégourié-Gonnard6a543ba2022-11-25 11:30:10 +01004128 msg "test: compat.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004129 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004130}
4131
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004132component_test_ssl_alloc_buffer_and_mfl () {
4133 msg "build: default config with memory buffer allocator and MFL extension"
4134 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4135 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4136 scripts/config.py set MBEDTLS_MEMORY_DEBUG
4137 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4138 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02004139 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004140 make
4141
4142 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
4143 make test
4144
4145 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 +02004146 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004147}
4148
Gilles Peskine636c26a2020-03-04 20:46:15 +01004149component_test_when_no_ciphersuites_have_mac () {
4150 msg "build: when no ciphersuites have MAC"
4151 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Gilles Peskine636c26a2020-03-04 20:46:15 +01004152 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
TRodziewicz2add5c12021-04-28 16:50:20 +02004153 scripts/config.py unset MBEDTLS_CMAC_C
Gilles Peskine636c26a2020-03-04 20:46:15 +01004154 make
4155
4156 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
4157 make test
4158
4159 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004160 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01004161}
4162
Raoul Strackxa4e86142020-06-15 17:03:13 +02004163component_test_no_date_time () {
4164 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
4165 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
Gilles Peskinef4d2fd42021-10-08 11:45:47 +02004166 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Raoul Strackxa4e86142020-06-15 17:03:13 +02004167 make
4168
4169 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
4170 make test
4171}
4172
Gilles Peskine8f073122018-11-27 15:58:47 +01004173component_test_platform_calloc_macro () {
4174 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004175 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4176 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
4177 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01004178 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4179 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01004180
Gilles Peskine8f073122018-11-27 15:58:47 +01004181 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
4182 make test
4183}
Hanno Beckere5fecec2018-10-11 11:02:52 +01004184
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02004185component_test_malloc_0_null () {
4186 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004187 scripts/config.py full
Gilles Peskinecf4fe582023-07-20 19:00:15 +02004188 make CC=gcc CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"$PWD/tests/configs/user-config-malloc-0-null.h\"' $ASAN_CFLAGS -O" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02004189
4190 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
4191 make test
4192
4193 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
4194 # Just the calloc selftest. "make test" ran the others as part of the
4195 # test suites.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004196 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01004197
4198 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
4199 # Run a subset of the tests. The choice is a balance between coverage
4200 # and time (including time indirectly wasted due to flaky tests).
4201 # The current choice is to skip tests whose description includes
4202 # "proxy", which is an approximation of skipping tests that use the
4203 # UDP proxy, which tend to be slower and flakier.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004204 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02004205}
4206
Dave Rodgman6a08b682023-06-19 11:51:33 +01004207support_test_aesni() {
4208 # Check that gcc targets x86_64 (we can build AESNI), and check for
4209 # AESNI support on the host (we can run AESNI).
4210 #
4211 # The name of this function is possibly slightly misleading, but needs to align
4212 # with the name of the corresponding test, component_test_aesni.
Dave Rodgmanf8986e32023-06-19 10:55:59 +01004213 #
4214 # In principle 32-bit x86 can support AESNI, but our implementation does not
4215 # support 32-bit x86, so we check for x86-64.
4216 # We can only grep /proc/cpuinfo on Linux, so this also checks for Linux
Dave Rodgman6a08b682023-06-19 11:51:33 +01004217 (gcc -v 2>&1 | grep Target | grep -q x86_64) &&
4218 [[ "$HOSTTYPE" == "x86_64" && "$OSTYPE" == "linux-gnu" ]] &&
Jerry Yua7de78d2023-08-08 12:57:35 +08004219 (lscpu | grep -qw aes)
Dave Rodgmanf8986e32023-06-19 10:55:59 +01004220}
4221
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004222component_test_aesni () { # ~ 60s
4223 # This tests the two AESNI implementations (intrinsics and assembly), and also the plain C
4224 # fallback. It also tests the logic that is used to select which implementation(s) to build.
4225 #
4226 # This test does not require the host to have support for AESNI (if it doesn't, the run-time
4227 # AESNI detection will fallback to the plain C implementation, so the tests will instead
4228 # exercise the plain C impl).
4229
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004230 msg "build: default config with different AES implementations"
Dave Rodgman838dc462023-06-16 13:18:19 +01004231 scripts/config.py set MBEDTLS_AESNI_C
Jerry Yu17a9d2e2023-08-03 16:14:18 +08004232 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Dave Rodgman838dc462023-06-16 13:18:19 +01004233 scripts/config.py set MBEDTLS_HAVE_ASM
4234
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004235 # test the intrinsics implementation
4236 msg "AES tests, test intrinsics"
Dave Rodgman838dc462023-06-16 13:18:19 +01004237 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004238 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004239 # check that we built intrinsics - this should be used by default when supported by the compiler
Jerry Yu1221a312023-08-03 16:09:07 +08004240 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004241
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004242 # test the asm implementation
4243 msg "AES tests, test assembly"
4244 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004245 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mno-pclmul -mno-sse2 -mno-aes'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004246 # check that we built assembly - this should be built if the compiler does not support intrinsics
Jerry Yu1221a312023-08-03 16:09:07 +08004247 ./programs/test/selftest aes | grep "AESNI code" | grep -q "assembly"
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004248
4249 # test the plain C implementation
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004250 scripts/config.py unset MBEDTLS_AESNI_C
Jerry Yu17a9d2e2023-08-03 16:14:18 +08004251 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004252 msg "AES tests, plain C"
4253 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004254 make CC=gcc CFLAGS='-O2 -Werror'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004255 # check that there is no AESNI code present
Jerry Yu1221a312023-08-03 16:09:07 +08004256 ./programs/test/selftest aes | not grep -q "AESNI code"
Jerry Yu76a51b92023-08-08 16:03:55 +08004257 not grep -q "AES note: using AESNI" ./programs/test/selftest
4258 grep -q "AES note: built-in implementation." ./programs/test/selftest
Jerry Yu8a599c02023-08-03 17:01:02 +08004259
4260 # test the intrinsics implementation
4261 scripts/config.py set MBEDTLS_AESNI_C
4262 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4263 msg "AES tests, test AESNI only"
4264 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004265 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
Jerry Yua7de78d2023-08-08 12:57:35 +08004266 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
4267 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
Jerry Yu76a51b92023-08-08 16:03:55 +08004268 grep -q "AES note: using AESNI" ./programs/test/selftest
4269 not grep -q "AES note: built-in implementation." ./programs/test/selftest
Dave Rodgman838dc462023-06-16 13:18:19 +01004270}
4271
Jerry Yu193cbc02023-08-03 17:06:29 +08004272
Jerry Yub6d39c22023-08-16 15:11:48 +08004273
4274support_test_aesni_m32() {
4275 support_test_m32_o0 && (lscpu | grep -qw aes)
4276}
4277
4278component_test_aesni_m32 () { # ~ 60s
4279 # This tests are duplicated from component_test_aesni for i386 target
4280 #
4281 # AESNI intrinsic code supports i386 and assembly code does not support it.
4282
4283 msg "build: default config with different AES implementations"
4284 scripts/config.py set MBEDTLS_AESNI_C
4285 scripts/config.py set MBEDTLS_PADLOCK_C
4286 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4287 scripts/config.py set MBEDTLS_HAVE_ASM
4288
4289 # test the intrinsics implementation
4290 msg "AES tests, test intrinsics"
4291 make clean
4292 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
4293 # check that we built intrinsics - this should be used by default when supported by the compiler
4294 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
4295 grep -q "AES note: using AESNI" ./programs/test/selftest
4296 grep -q "AES note: built-in implementation." ./programs/test/selftest
4297 grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4298 grep -q mbedtls_aesni_has_support ./programs/test/selftest
4299
4300 scripts/config.py set MBEDTLS_AESNI_C
Jerry Yub6d39c22023-08-16 15:11:48 +08004301 scripts/config.py unset MBEDTLS_PADLOCK_C
4302 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4303 msg "AES tests, test AESNI only"
4304 make clean
4305 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
4306 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
4307 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
4308 grep -q "AES note: using AESNI" ./programs/test/selftest
4309 not grep -q "AES note: built-in implementation." ./programs/test/selftest
4310 not grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4311 not grep -q mbedtls_aesni_has_support ./programs/test/selftest
4312}
4313
Jerry Yu193cbc02023-08-03 17:06:29 +08004314# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
4315component_build_aes_aesce_armcc () {
4316 msg "Build: AESCE test on arm64 platform without plain C."
4317 scripts/config.py baremetal
4318
4319 # armc[56] don't support SHA-512 intrinsics
Dave Rodgmanbe7915a2023-10-11 10:46:38 +01004320 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Jerry Yu193cbc02023-08-03 17:06:29 +08004321
4322 # Stop armclang warning about feature detection for A64_CRYPTO.
4323 # With this enabled, the library does build correctly under armclang,
4324 # but in baremetal builds (as tested here), feature detection is
4325 # unavailable, and the user is notified via a #warning. So enabling
4326 # this feature would prevent us from building with -Werror on
4327 # armclang. Tracked in #7198.
Dave Rodgman5b89c552023-10-10 14:59:02 +01004328 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Jerry Yu193cbc02023-08-03 17:06:29 +08004329 scripts/config.py set MBEDTLS_HAVE_ASM
4330
4331 msg "AESCE, build with default configuration."
4332 scripts/config.py set MBEDTLS_AESCE_C
4333 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4334 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
4335
4336 msg "AESCE, build AESCE only"
4337 scripts/config.py set MBEDTLS_AESCE_C
4338 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4339 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
4340}
4341
Dave Rodgman9ed18532023-10-05 00:06:47 +01004342support_build_sha_armce() {
Dave Rodgmanf2ea08a2023-10-16 11:37:28 +01004343 if command -v clang > /dev/null ; then
Dave Rodgmand35b1882023-10-16 10:25:30 +01004344 # clang >= 4 is required to build with SHA extensions
4345 clang_ver="$(clang --version|grep version|sed -E 's#.*version ([0-9]+).*#\1#')"
Dave Rodgmanab0cff52023-10-13 09:32:04 +01004346
Dave Rodgmand35b1882023-10-16 10:25:30 +01004347 # we need asm/hwcap.h available for runtime detection
4348 echo '#include <asm/hwcap.h>' | clang -E - >/dev/null 2>&1 && have_hwcap=1 || have_hwcap=0
Dave Rodgmanab0cff52023-10-13 09:32:04 +01004349
Dave Rodgmand35b1882023-10-16 10:25:30 +01004350 [[ "${clang_ver}" -ge 4 && "${have_hwcap}" -eq 1 ]]
4351 else
4352 # clang not available
4353 false
4354 fi
Dave Rodgman9ed18532023-10-05 00:06:47 +01004355}
4356
Dave Rodgmand9e80832023-10-04 17:17:46 +01004357component_build_sha_armce () {
Dave Rodgman5b89c552023-10-10 14:59:02 +01004358 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004359
4360
4361 # Test variations of SHA256 Armv8 crypto extensions
Dave Rodgman5b89c552023-10-10 14:59:02 +01004362 scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004363 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, aarch64"
4364 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
4365 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, arm"
4366 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
4367 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
Dave Rodgmand9e80832023-10-04 17:17:46 +01004368
Dave Rodgmand9e80832023-10-04 17:17:46 +01004369
Dave Rodgman94a634d2023-10-10 12:59:29 +01004370 # test the deprecated form of the config option
Dave Rodgman94a634d2023-10-10 12:59:29 +01004371 scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004372 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY clang, thumb"
4373 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
4374 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
Dave Rodgmand9e80832023-10-04 17:17:46 +01004375
Dave Rodgman5b89c552023-10-10 14:59:02 +01004376 scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004377 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT clang, aarch64"
4378 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
4379 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Dave Rodgmand9e80832023-10-04 17:17:46 +01004380
Dave Rodgmancd654002023-10-05 09:40:07 +01004381
Dave Rodgman94a634d2023-10-10 12:59:29 +01004382 # test the deprecated form of the config option
Dave Rodgman94a634d2023-10-10 12:59:29 +01004383 scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004384 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, arm"
4385 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -std=c99"
4386 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, thumb"
4387 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
4388 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
Dave Rodgman94a634d2023-10-10 12:59:29 +01004389
Dave Rodgmancd654002023-10-05 09:40:07 +01004390
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004391 # examine the disassembly for presence of SHA instructions
4392 for opt in MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT; do
4393 scripts/config.py set ${opt}
4394 msg "${opt} clang, test A32 crypto instructions built"
4395 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
4396 grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4397
4398 msg "${opt} clang, test T32 crypto instructions built"
4399 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
4400 grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4401
4402 msg "${opt} clang, test aarch64 crypto instructions built"
4403 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
4404 grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.o
4405 scripts/config.py unset ${opt}
4406 done
4407
4408
4409 # examine the disassembly for absence of SHA instructions
4410 msg "clang, test A32 crypto instructions not built"
4411 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
4412 not grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4413
4414 msg "clang, test T32 crypto instructions not built"
4415 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
4416 not grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4417
4418 msg "clang, test aarch64 crypto instructions not built"
4419 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
4420 not grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.o
Dave Rodgmand9e80832023-10-04 17:17:46 +01004421}
4422
Jerry Yuc935aa62023-08-03 17:08:27 +08004423# For timebeing, no VIA Padlock platform available.
4424component_build_aes_via_padlock () {
4425
4426 msg "AES:VIA PadLock, build with default configuration."
Jerry Yu506759f2023-08-16 17:11:22 +08004427 scripts/config.py unset MBEDTLS_AESNI_C
Jerry Yuc935aa62023-08-03 17:08:27 +08004428 scripts/config.py set MBEDTLS_PADLOCK_C
4429 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4430 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Jerry Yu506759f2023-08-16 17:11:22 +08004431 grep -q mbedtls_padlock_has_support ./programs/test/selftest
Jerry Yuc935aa62023-08-03 17:08:27 +08004432
4433}
4434
4435support_build_aes_via_padlock_only () {
4436 ( [ "$MBEDTLS_TEST_PLATFORM" == "Linux-x86_64" ] || \
4437 [ "$MBEDTLS_TEST_PLATFORM" == "Linux-amd64" ] ) && \
4438 [ "`dpkg --print-foreign-architectures`" == "i386" ]
4439}
4440
Jerry Yu193cbc02023-08-03 17:06:29 +08004441support_build_aes_aesce_armcc () {
4442 support_build_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +01004443}
4444
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004445component_test_aes_only_128_bit_keys () {
Gilles Peskine8f073122018-11-27 15:58:47 +01004446 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
Hanno Becker83ebf782017-07-07 12:29:15 +01004447 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01004448 scripts/config.py unset MBEDTLS_PADLOCK_C
4449
4450 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01004451
Gilles Peskine8f073122018-11-27 15:58:47 +01004452 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
4453 make test
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004454}
4455
Gilles Peskine8f073122018-11-27 15:58:47 +01004456component_test_no_ctr_drbg_aes_only_128_bit_keys () {
Hanno Becker83ebf782017-07-07 12:29:15 +01004457 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
Gilles Peskine8f073122018-11-27 15:58:47 +01004458 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4459 scripts/config.py unset MBEDTLS_CTR_DRBG_C
4460 scripts/config.py unset MBEDTLS_PADLOCK_C
4461
Gilles Peskine592f5912019-10-07 18:49:32 +02004462 make CC=clang CFLAGS='-Werror -Wall -Wextra'
4463
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004464 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
4465 make test
4466}
Gilles Peskine592f5912019-10-07 18:49:32 +02004467
4468component_test_aes_only_128_bit_keys_have_builtins () {
4469 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4470 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4471 scripts/config.py unset MBEDTLS_PADLOCK_C
4472 scripts/config.py unset MBEDTLS_AESNI_C
4473 scripts/config.py unset MBEDTLS_AESCE_C
4474
4475 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004476
4477 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4478 make test
Gilles Peskine592f5912019-10-07 18:49:32 +02004479
4480 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4481 programs/test/selftest
4482}
4483
4484component_test_aes_fewer_tables () {
4485 msg "build: default config with AES_FEWER_TABLES enabled"
4486 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
4487 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004488
4489 msg "test: AES_FEWER_TABLES"
4490 make test
4491}
Gilles Peskine592f5912019-10-07 18:49:32 +02004492
4493component_test_aes_rom_tables () {
4494 msg "build: default config with AES_ROM_TABLES enabled"
4495 scripts/config.py set MBEDTLS_AES_ROM_TABLES
4496 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
4497
4498 msg "test: AES_ROM_TABLES"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02004499 make test
4500}
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004501
Gilles Peskine004206c2019-10-21 17:11:33 +02004502component_test_aes_fewer_tables_and_rom_tables () {
Gilles Peskinef96aefe2019-07-24 14:58:38 +02004503 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
4504 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
4505 scripts/config.py set MBEDTLS_AES_ROM_TABLES
4506 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
4507
Steven Cooremand57203d2020-07-16 20:28:59 +02004508 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
Ronald Cron32a432a2023-03-28 09:19:04 +02004509 make test
Steven Cooreman753f9732021-03-15 11:38:44 +01004510}
Steven Cooreman6801f082021-02-19 17:21:22 +01004511
Gilles Peskine3587dfd2021-09-20 19:20:04 +02004512component_test_ctr_drbg_aes_256_sha_256 () {
4513 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Ronald Cron17b3afc2020-12-10 18:17:09 +01004514 scripts/config.py full
4515 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4516 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Steven Cooremand57203d2020-07-16 20:28:59 +02004517 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Ronald Cron32a432a2023-03-28 09:19:04 +02004518 make
Steven Cooremand57203d2020-07-16 20:28:59 +02004519
4520 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4521 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01004522}
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004523
Andrzej Kurek232e8f92019-10-03 03:18:01 -04004524component_test_ctr_drbg_aes_128_sha_512 () {
Gilles Peskine56c01612019-07-03 20:43:32 +02004525 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskineca144592021-11-04 12:52:14 +01004526 scripts/config.py full
Gilles Peskine8f073122018-11-27 15:58:47 +01004527 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02004528 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskinecf740502019-07-03 20:43:05 +02004529 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4530 make
4531
4532 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine56c01612019-07-03 20:43:32 +02004533 make test
Gilles Peskinecf740502019-07-03 20:43:05 +02004534}
Gilles Peskineca144592021-11-04 12:52:14 +01004535
Gilles Peskinecf740502019-07-03 20:43:05 +02004536component_test_ctr_drbg_aes_128_sha_256 () {
4537 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskineec10bf12019-09-20 19:56:06 +02004538 scripts/config.py full
4539 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4540 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
4541 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskinee094a182020-04-14 20:08:41 +02004542 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskineec10bf12019-09-20 19:56:06 +02004543 make
4544
4545 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4546 make test
4547}
4548
4549component_test_se_default () {
4550 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
4551 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
4552 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004553
Gilles Peskineec10bf12019-09-20 19:56:06 +02004554 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
4555 make test
4556}
4557
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004558component_test_psa_crypto_drivers () {
Gilles Peskine1997f302023-07-26 18:45:20 +02004559 msg "build: full + test drivers dispatching to builtins"
Gilles Peskineec10bf12019-09-20 19:56:06 +02004560 scripts/config.py full
Gilles Peskine1997f302023-07-26 18:45:20 +02004561 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Gilles Peskineec10bf12019-09-20 19:56:06 +02004562 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
4563 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
4564 loc_cflags="${loc_cflags} -I../tests/include -O2"
4565
4566 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
4567
Gilles Peskine1997f302023-07-26 18:45:20 +02004568 msg "test: full + test drivers dispatching to builtins"
Gilles Peskineec10bf12019-09-20 19:56:06 +02004569 make test
4570}
4571
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02004572component_test_make_shared () {
4573 msg "build/test: make shared" # ~ 40s
4574 make SHARED=1 all check
4575 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004576 programs/test/dlopen_demo.sh
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02004577}
4578
4579component_test_cmake_shared () {
4580 msg "build/test: cmake shared" # ~ 2min
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004581 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
4582 make
Gilles Peskine8f073122018-11-27 15:58:47 +01004583 ldd programs/util/strerror | grep libmbedcrypto
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004584 make test
4585 programs/test/dlopen_demo.sh
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004586}
Gilles Peskine8fd59422019-10-21 17:11:33 +02004587
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004588test_build_opt () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004589 info=$1 cc=$2; shift 2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004590 $cc --version
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004591 for opt in "$@"; do
Gilles Peskine14c3c062018-01-29 21:25:12 +01004592 msg "build/test: $cc $opt, $info" # ~ 30s
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004593 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskine14c3c062018-01-29 21:25:12 +01004594 # We're confident enough in compilers to not run _all_ the tests,
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004595 # but at least run the unit tests. In particular, runs with
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01004596 # optimizations use inline assembly whereas runs with -O0
Gilles Peskine14c3c062018-01-29 21:25:12 +01004597 # skip inline assembly.
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01004598 make test # ~30s
4599 make clean
4600 done
4601}
4602
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004603# For FreeBSD we invoke the function by name so this condition is added
4604# to disable the existing test_clang_opt function for linux.
4605if [[ $(uname) != "Linux" ]]; then
4606 component_test_clang_opt () {
4607 scripts/config.py full
4608 test_build_opt 'full config' clang -O0 -Os -O2
4609 }
4610fi
4611
4612component_test_clang_latest_opt () {
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004613 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004614 test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004615}
4616support_test_clang_latest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004617 type "$CLANG_LATEST" >/dev/null 2>/dev/null
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004618}
4619
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004620component_test_clang_earliest_opt () {
Gilles Peskine878cf602019-01-06 20:50:38 +00004621 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004622 test_build_opt 'full config' "$CLANG_EARLIEST" -O0
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004623}
4624support_test_clang_earliest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004625 type "$CLANG_EARLIEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004626}
4627
4628component_test_gcc_latest_opt () {
4629 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004630 test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004631}
4632support_test_gcc_latest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004633 type "$GCC_LATEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004634}
4635
4636component_test_gcc_earliest_opt () {
4637 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004638 test_build_opt 'full config' "$GCC_EARLIEST" -O0
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004639}
4640support_test_gcc_earliest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004641 type "$GCC_EARLIEST" >/dev/null 2>/dev/null
Gilles Peskine878cf602019-01-06 20:50:38 +00004642}
4643
4644component_build_mbedtls_config_file () {
4645 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
Gilles Peskine2003c2f2022-04-07 20:55:57 +02004646 scripts/config.py -w full_config.h full
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004647 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
4648 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
Gilles Peskine45e680e2022-04-13 23:23:21 +02004649 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskinee10df772022-04-07 21:06:41 +02004650 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
4651 make clean
4652
4653 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
4654 # In the user config, disable one feature (for simplicity, pick a feature
4655 # that nothing else depends on).
4656 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
4657 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
4658 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
4659
4660 rm -f user_config.h full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004661}
4662
Gilles Peskine7d904e72022-04-07 21:59:14 +02004663component_build_psa_config_file () {
4664 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
4665 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
4666 cp "$CRYPTO_CONFIG_H" psa_test_config.h
4667 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
4668 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Gilles Peskine45e680e2022-04-13 23:23:21 +02004669 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine7d904e72022-04-07 21:59:14 +02004670 programs/test/query_compile_time_config MBEDTLS_CMAC_C
4671 make clean
4672
4673 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
4674 # In the user config, disable one feature, which will reflect on the
4675 # mbedtls configuration so we can query it with query_compile_time_config.
4676 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
4677 scripts/config.py unset MBEDTLS_CMAC_C
4678 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
4679 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
4680
4681 rm -f psa_test_config.h psa_user_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004682}
4683
Gilles Peskinedf6e84a2023-02-22 22:09:51 +01004684component_build_psa_alt_headers () {
4685 msg "build: make with PSA alt headers" # ~20s
4686
4687 # Generate alternative versions of the substitutable headers with the
4688 # same content except different include guards.
4689 make -C tests include/alt-extra/psa/crypto_platform_alt.h include/alt-extra/psa/crypto_struct_alt.h
4690
4691 # Build the library and some programs.
4692 # Don't build the fuzzers to avoid having to go through hoops to set
4693 # a correct include path for programs/fuzz/Makefile.
4694 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
4695 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\"'"
4696
4697 # Check that we're getting the alternative include guards and not the
4698 # original include guards.
4699 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
4700 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
4701 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
4702 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
4703}
4704
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004705component_test_m32_o0 () {
Gilles Peskine77f05352021-10-07 19:27:16 +02004706 # Build without optimization, so as to use portable C code (in a 32-bit
4707 # build) and not the i386-specific inline assembly.
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004708 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
4709 scripts/config.py full
Jerry Yubdd96b92023-08-16 17:34:27 +08004710 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004711 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
4712
4713 msg "test: i386, make, gcc -O0 (ASan build)"
4714 make test
4715}
4716support_test_m32_o0 () {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02004717 case $(uname -m) in
Pengyu Lvc92df3b2022-10-21 10:50:26 +00004718 amd64|x86_64) true;;
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004719 *) false;;
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004720 esac
4721}
4722
Gilles Peskineff0aee02021-10-05 09:36:03 +02004723component_test_m32_o2 () {
4724 # Build with optimization, to use the i386 specific inline assembly
4725 # and go faster for tests.
4726 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004727 scripts/config.py full
Jerry Yubdd96b92023-08-16 17:34:27 +08004728 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Gilles Peskineff0aee02021-10-05 09:36:03 +02004729 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004730
Gilles Peskineff0aee02021-10-05 09:36:03 +02004731 msg "test: i386, make, gcc -O2 (ASan build)"
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004732 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01004733
Gilles Peskineff0aee02021-10-05 09:36:03 +02004734 msg "test ssl-opt.sh, i386, make, gcc-O2"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004735 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01004736}
Gilles Peskinecf522222021-10-07 19:25:29 +02004737support_test_m32_o2 () {
Gilles Peskine878cf602019-01-06 20:50:38 +00004738 support_test_m32_o0 "$@"
4739}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004740
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004741component_test_m32_everest () {
4742 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004743 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Jerry Yubdd96b92023-08-16 17:34:27 +08004744 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Gilles Peskine8fd59422019-10-21 17:11:33 +02004745 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004746
4747 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
4748 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01004749
4750 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004751 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01004752
4753 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
4754 # Exclude some symmetric ciphers that are redundant here to gain time.
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02004755 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004756}
4757support_test_m32_everest () {
4758 support_test_m32_o0 "$@"
4759}
4760
Gilles Peskine8f073122018-11-27 15:58:47 +01004761component_test_mx32 () {
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004762 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004763 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02004764 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004765
4766 msg "test: 64-bit ILP32, make, gcc"
4767 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01004768}
Gilles Peskine878cf602019-01-06 20:50:38 +00004769support_test_mx32 () {
4770 case $(uname -m) in
4771 amd64|x86_64) true;;
4772 *) false;;
4773 esac
4774}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004775
Peter Kolbus60c6da22018-12-27 06:59:04 -06004776component_test_min_mpi_window_size () {
4777 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004778 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06004779 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4780 make
4781
4782 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
4783 make test
4784}
4785
Gilles Peskine8f073122018-11-27 15:58:47 +01004786component_test_have_int32 () {
4787 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004788 scripts/config.py unset MBEDTLS_HAVE_ASM
4789 scripts/config.py unset MBEDTLS_AESNI_C
4790 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08004791 scripts/config.py unset MBEDTLS_AESCE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01004792 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02004793
Gilles Peskine8f073122018-11-27 15:58:47 +01004794 msg "test: gcc, force 32-bit bignum limbs"
4795 make test
4796}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01004797
Gilles Peskine8f073122018-11-27 15:58:47 +01004798component_test_have_int64 () {
4799 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004800 scripts/config.py unset MBEDTLS_HAVE_ASM
4801 scripts/config.py unset MBEDTLS_AESNI_C
4802 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08004803 scripts/config.py unset MBEDTLS_AESCE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01004804 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01004805
Gilles Peskine8f073122018-11-27 15:58:47 +01004806 msg "test: gcc, force 64-bit bignum limbs"
4807 make test
4808}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004809
Gabor Mezeie256cc12023-07-26 17:28:48 +02004810component_test_have_int32_cmake_new_bignum () {
4811 msg "build: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
4812 scripts/config.py unset MBEDTLS_HAVE_ASM
4813 scripts/config.py unset MBEDTLS_AESNI_C
4814 scripts/config.py unset MBEDTLS_PADLOCK_C
4815 scripts/config.py unset MBEDTLS_AESCE_C
4816 scripts/config.py set MBEDTLS_TEST_HOOKS
Janos Follath2f045822023-07-31 10:57:16 +01004817 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Janos Follathf3135af2023-07-31 10:07:57 +01004818 make CC=gcc CFLAGS="$ASAN_CFLAGS -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32" LDFLAGS="$ASAN_CFLAGS"
Gabor Mezeie256cc12023-07-26 17:28:48 +02004819
4820 msg "test: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
4821 make test
4822}
4823
Gilles Peskine8f073122018-11-27 15:58:47 +01004824component_test_no_udbl_division () {
4825 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004826 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004827 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01004828 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004829
Gilles Peskine8f073122018-11-27 15:58:47 +01004830 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
4831 make test
4832}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004833
Gilles Peskine8f073122018-11-27 15:58:47 +01004834component_test_no_64bit_multiplication () {
4835 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004836 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004837 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01004838 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004839
Gilles Peskine8f073122018-11-27 15:58:47 +01004840 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
4841 make test
4842}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004843
Gilles Peskine3809f5f2020-11-09 15:40:05 +01004844component_test_no_strings () {
4845 msg "build: no strings" # ~10s
4846 scripts/config.py full
4847 # Disable options that activate a large amount of string constants.
4848 scripts/config.py unset MBEDTLS_DEBUG_C
4849 scripts/config.py unset MBEDTLS_ERROR_C
4850 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
4851 scripts/config.py unset MBEDTLS_VERSION_FEATURES
4852 make CFLAGS='-Werror -Os'
4853
4854 msg "test: no strings" # ~ 10s
4855 make test
4856}
4857
Hanno Beckerc5722d12020-10-09 11:10:42 +01004858component_test_no_x509_info () {
4859 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
4860 scripts/config.pl full
4861 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
4862 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
Gilles Peskineff0aee02021-10-05 09:36:03 +02004863 make CFLAGS='-Werror -O2'
Hanno Beckerc5722d12020-10-09 11:10:42 +01004864
4865 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
4866 make test
4867
4868 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004869 tests/ssl-opt.sh
Hanno Beckerc5722d12020-10-09 11:10:42 +01004870}
4871
Gilles Peskine8f073122018-11-27 15:58:47 +01004872component_build_arm_none_eabi_gcc () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02004873 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004874 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02004875 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 +02004876
Gilles Peskinee36fe812021-09-01 20:00:33 +02004877 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02004878 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01004879}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004880
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004881component_build_arm_linux_gnueabi_gcc_arm5vte () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02004882 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004883 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02004884 # Build for a target platform that's close to what Debian uses
4885 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
Dave Rodgman017a1992022-03-31 14:07:01 +01004886 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004887 # Build everything including programs, see for example
Dave Rodgman017a1992022-03-31 14:07:01 +01004888 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004889 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'
4890
Gilles Peskinee36fe812021-09-01 20:00:33 +02004891 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02004892 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t library/*.o
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004893}
4894support_build_arm_linux_gnueabi_gcc_arm5vte () {
4895 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
4896}
4897
4898component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02004899 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004900 scripts/config.py baremetal
4901 # This is an imperfect substitute for
4902 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnardae505ee2021-07-06 09:44:59 +02004903 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02004904 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 +02004905
Gilles Peskinee36fe812021-09-01 20:00:33 +02004906 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02004907 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02004908}
4909
Gilles Peskine6e2fb862020-04-30 23:00:53 +02004910component_build_arm_none_eabi_gcc_m0plus () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02004911 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
4912 scripts/config.py baremetal_size
Gilles Peskineaeedd742020-09-02 11:03:04 +02004913 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 +02004914
Gilles Peskinee36fe812021-09-01 20:00:33 +02004915 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02004916 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Manuel Pégourié-Gonnard67f80372023-06-06 13:01:18 +02004917 for lib in library/*.a; do
4918 echo "$lib:"
4919 ${ARM_NONE_EABI_GCC_PREFIX}size -t $lib | grep TOTALS
4920 done
Gilles Peskine6e2fb862020-04-30 23:00:53 +02004921}
4922
Gilles Peskine8f073122018-11-27 15:58:47 +01004923component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02004924 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004925 scripts/config.py baremetal
4926 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02004927 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 +01004928 echo "Checking that software 64-bit division is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004929 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01004930}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004931
Gilles Peskine8f073122018-11-27 15:58:47 +01004932component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02004933 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004934 scripts/config.py baremetal
4935 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02004936 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 +01004937 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004938 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01004939}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004940
Dave Rodgman8c315f22023-06-02 10:26:24 -04004941component_build_arm_clang_thumb () {
4942 # ~ 30s
4943
4944 scripts/config.py baremetal
4945
4946 msg "build: clang thumb 2, make"
4947 make clean
4948 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
4949
4950 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
4951 msg "build: clang thumb 1 -O0, make"
4952 make clean
4953 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
4954
4955 msg "build: clang thumb 1 -Os, make"
4956 make clean
4957 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
4958}
4959
Gilles Peskine8f073122018-11-27 15:58:47 +01004960component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02004961 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004962 scripts/config.py baremetal
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00004963 # armc[56] don't support SHA-512 intrinsics
Dave Rodgmanbe7915a2023-10-11 10:46:38 +01004964 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Dave Rodgman2f386c52023-03-02 13:38:33 +00004965
Dave Rodgman0fddf822023-03-02 15:32:12 +00004966 # Stop armclang warning about feature detection for A64_CRYPTO.
4967 # With this enabled, the library does build correctly under armclang,
4968 # but in baremetal builds (as tested here), feature detection is
4969 # unavailable, and the user is notified via a #warning. So enabling
4970 # this feature would prevent us from building with -Werror on
4971 # armclang. Tracked in #7198.
Dave Rodgman5b89c552023-10-10 14:59:02 +01004972 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Dave Rodgman2f386c52023-03-02 13:38:33 +00004973
Hanno Beckerf0762e92022-07-15 12:08:19 +01004974 scripts/config.py set MBEDTLS_HAVE_ASM
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00004975
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004976 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02004977
4978 msg "size: ARM Compiler 5"
4979 "$ARMC5_FROMELF" -z library/*.o
4980
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004981 make clean
Andres AG87bb5772016-09-27 15:05:15 +01004982
Dave Rodgmanb45d58b2023-06-02 13:54:00 -04004983 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
Hanno Beckerf0762e92022-07-15 12:08:19 +01004984
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004985 # ARM Compiler 6 - Target ARMv7-A
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01004986 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02004987
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004988 # ARM Compiler 6 - Target ARMv7-M
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01004989 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m"
4990
4991 # ARM Compiler 6 - Target ARMv7-M+DSP
4992 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m+dsp"
Simon Butcher940737f2017-07-23 13:42:36 +02004993
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004994 # ARM Compiler 6 - Target ARMv8-A - AArch32
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01004995 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02004996
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004997 # ARM Compiler 6 - Target ARMv8-M
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01004998 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02004999
Tom Cosgrove6ec39ca2023-06-09 15:34:31 +01005000 # ARM Compiler 6 - Target ARMv8.2-A - AArch64
5001 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
5002
Dave Rodgmanb45d58b2023-06-02 13:54:00 -04005003 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
5004 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
5005
Dave Rodgman99318e62023-05-24 12:27:42 +01005006 # ARM Compiler 6 - Target Cortex-M0
5007 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
Gilles Peskine8f073122018-11-27 15:58:47 +01005008}
Tom Cosgrove6ec39ca2023-06-09 15:34:31 +01005009
Pengyu Lvdf070032023-02-24 16:03:31 +08005010support_build_armcc () {
Pengyu Lvc6298ad2023-03-01 10:31:29 +08005011 armc5_cc="$ARMC5_BIN_DIR/armcc"
5012 armc6_cc="$ARMC6_BIN_DIR/armclang"
5013 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
Pengyu Lvdf070032023-02-24 16:03:31 +08005014}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01005015
Jerry Yu81d5e1f2022-01-27 13:01:01 +08005016component_test_tls13_only () {
5017 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3, without MBEDTLS_SSL_PROTO_TLS1_2"
Ronald Cronc2e110f2022-11-22 09:01:46 +01005018 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Jerry Yuda5af222021-12-24 18:45:45 +08005019 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5020
Gilles Peskine4bb369c2022-10-29 17:44:19 +02005021 msg "test: TLS 1.3 only, all key exchange modes enabled"
5022 make test
Jerry Yubaa49342022-02-15 10:26:40 +08005023
Ronald Cronc3f43b62022-10-17 17:35:32 +02005024 msg "ssl-opt.sh: TLS 1.3 only, all key exchange modes enabled"
5025 tests/ssl-opt.sh
Jerry Yuda5af222021-12-24 18:45:45 +08005026}
5027
Ronald Cronc3f43b62022-10-17 17:35:32 +02005028component_test_tls13_only_psk () {
5029 msg "build: TLS 1.3 only from default, only PSK key exchange mode"
5030 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5031 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
5032 scripts/config.py unset MBEDTLS_ECDH_C
Przemek Stekiel0c231472023-06-14 11:12:45 +02005033 scripts/config.py unset MBEDTLS_DHM_C
Ronald Cronc3f43b62022-10-17 17:35:32 +02005034 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5035 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5036 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5037 scripts/config.py unset MBEDTLS_ECDSA_C
5038 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00005039 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01005040 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Crone3dac4a2022-06-10 17:21:51 +02005041 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5042
Ronald Cronc3f43b62022-10-17 17:35:32 +02005043 msg "test_suite_ssl: TLS 1.3 only, only PSK key exchange mode enabled"
5044 cd tests; ./test_suite_ssl; cd ..
Ronald Crone3dac4a2022-06-10 17:21:51 +02005045
Ronald Cronc3f43b62022-10-17 17:35:32 +02005046 msg "ssl-opt.sh: TLS 1.3 only, only PSK key exchange mode enabled"
5047 tests/ssl-opt.sh
5048}
5049
5050component_test_tls13_only_ephemeral () {
5051 msg "build: TLS 1.3 only from default, only ephemeral key exchange mode"
5052 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5053 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
Xiaokang Qian2dbfeda2022-11-15 10:52:57 +00005054 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005055 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5056
5057 msg "test_suite_ssl: TLS 1.3 only, only ephemeral key exchange mode"
5058 cd tests; ./test_suite_ssl; cd ..
5059
5060 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral key exchange mode"
5061 tests/ssl-opt.sh
5062}
5063
Przemek Stekiela01c2422023-06-13 10:46:48 +02005064component_test_tls13_only_ephemeral_ffdh () {
5065 msg "build: TLS 1.3 only from default, only ephemeral ffdh key exchange mode"
5066 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5067 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
5068 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
Przemek Stekielce05f542023-06-15 16:44:08 +02005069 scripts/config.py unset MBEDTLS_ECDH_C
5070
Przemek Stekiela01c2422023-06-13 10:46:48 +02005071 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5072
5073 msg "test_suite_ssl: TLS 1.3 only, only ephemeral ffdh key exchange mode"
5074 cd tests; ./test_suite_ssl; cd ..
5075
5076 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral ffdh key exchange mode"
5077 tests/ssl-opt.sh
5078}
5079
Ronald Cronc3f43b62022-10-17 17:35:32 +02005080component_test_tls13_only_psk_ephemeral () {
5081 msg "build: TLS 1.3 only from default, only PSK ephemeral key exchange mode"
5082 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5083 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5084 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5085 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5086 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5087 scripts/config.py unset MBEDTLS_ECDSA_C
5088 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00005089 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01005090 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005091 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5092
5093 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral key exchange mode"
5094 cd tests; ./test_suite_ssl; cd ..
5095
5096 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral key exchange mode"
5097 tests/ssl-opt.sh
5098}
5099
Przemek Stekiela01c2422023-06-13 10:46:48 +02005100component_test_tls13_only_psk_ephemeral_ffdh () {
5101 msg "build: TLS 1.3 only from default, only PSK ephemeral ffdh key exchange mode"
5102 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5103 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5104 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5105 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5106 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5107 scripts/config.py unset MBEDTLS_ECDSA_C
5108 scripts/config.py unset MBEDTLS_PKCS1_V21
5109 scripts/config.py unset MBEDTLS_PKCS7_C
5110 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Przemek Stekielce05f542023-06-15 16:44:08 +02005111 scripts/config.py unset MBEDTLS_ECDH_C
Przemek Stekiela01c2422023-06-13 10:46:48 +02005112 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5113
5114 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
5115 cd tests; ./test_suite_ssl; cd ..
5116
5117 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
5118 tests/ssl-opt.sh
5119}
5120
Ronald Cronc3f43b62022-10-17 17:35:32 +02005121component_test_tls13_only_psk_all () {
5122 msg "build: TLS 1.3 only from default, without ephemeral key exchange mode"
5123 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5124 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5125 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5126 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5127 scripts/config.py unset MBEDTLS_ECDSA_C
5128 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00005129 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01005130 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005131 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5132
5133 msg "test_suite_ssl: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
5134 cd tests; ./test_suite_ssl; cd ..
5135
5136 msg "ssl-opt.sh: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
5137 tests/ssl-opt.sh
5138}
5139
5140component_test_tls13_only_ephemeral_all () {
5141 msg "build: TLS 1.3 only from default, without PSK key exchange mode"
5142 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
Ronald Cronc2e110f2022-11-22 09:01:46 +01005143 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005144 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5145
5146 msg "test_suite_ssl: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
5147 cd tests; ./test_suite_ssl; cd ..
5148
5149 msg "ssl-opt.sh: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
5150 tests/ssl-opt.sh
Ronald Crone3dac4a2022-06-10 17:21:51 +02005151}
5152
Ronald Cron6f135e12021-12-08 16:57:54 +01005153component_test_tls13 () {
5154 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
5155 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005156 scripts/config.py set MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
5157 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
Ronald Cronc2e110f2022-11-22 09:01:46 +01005158 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005159 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
5160 make
Ronald Cron6f135e12021-12-08 16:57:54 +01005161 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005162 make test
Ronald Cron6f135e12021-12-08 16:57:54 +01005163 msg "ssl-opt.sh (TLS 1.3)"
Gilles Peskine827dbd92022-02-04 00:30:54 +01005164 tests/ssl-opt.sh
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005165}
5166
Ronald Cron6f135e12021-12-08 16:57:54 +01005167component_test_tls13_no_compatibility_mode () {
5168 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
5169 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005170 scripts/config.py unset MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
5171 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
Ronald Cronc2e110f2022-11-22 09:01:46 +01005172 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Hanno Beckera711f6e2020-05-04 12:03:51 +01005173 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
5174 make
Ronald Cron6f135e12021-12-08 16:57:54 +01005175 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
Hanno Becker6c53ecc2021-08-01 19:20:10 +01005176 make test
Ronald Cron6f135e12021-12-08 16:57:54 +01005177 msg "ssl-opt.sh (TLS 1.3 no compatibility mode)"
Gilles Peskine827dbd92022-02-04 00:30:54 +01005178 tests/ssl-opt.sh
Hanno Becker6c53ecc2021-08-01 19:20:10 +01005179}
5180
Jan Bruckner151f6422023-02-10 12:45:19 +01005181component_test_tls13_only_record_size_limit () {
5182 msg "build: TLS 1.3 only from default, record size limit extension enabled"
5183 scripts/config.py set MBEDTLS_SSL_RECORD_SIZE_LIMIT
5184 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5185
5186 msg "test_suite_ssl: TLS 1.3 only, record size limit extension enabled"
5187 cd tests; ./test_suite_ssl; cd ..
5188
5189 msg "ssl-opt.sh: (TLS 1.3 only, record size limit extension tests only)"
5190 # Both the server and the client will currently abort the handshake when they encounter the
5191 # record size limit extension. There is no way to prevent gnutls-cli from sending the extension
5192 # which makes all G_NEXT_CLI + P_SRV tests fail. Thus, run only the tests for the this extension.
5193 tests/ssl-opt.sh -f "Record Size Limit"
5194}
5195
Gilles Peskine8f073122018-11-27 15:58:47 +01005196component_build_mingw () {
5197 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Jerry Yubdd96b92023-08-16 17:34:27 +08005198 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Andrzej Kurek232e8f92019-10-03 03:18:01 -04005199 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 +00005200
Gilles Peskine8f073122018-11-27 15:58:47 +01005201 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04005202 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 +01005203 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02005204
Gilles Peskine8f073122018-11-27 15:58:47 +01005205 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04005206 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
5207 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 +01005208 make WINDOWS_BUILD=1 clean
5209}
Jaeden Amero117b8a42019-04-17 15:19:26 +01005210support_build_mingw() {
Pengyu Lv51b5f002023-02-24 15:38:52 +08005211 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
5212 [0-5]*|"") false;;
Jaeden Amero117b8a42019-04-17 15:19:26 +01005213 *) true;;
5214 esac
5215}
Simon Butcher91aef332016-11-17 09:20:50 +00005216
Gilles Peskine8f073122018-11-27 15:58:47 +01005217component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005218 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005219 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005220 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
5221 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02005222
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005223 msg "test: main suites (MSan)" # ~ 10s
5224 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005225
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005226 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005227 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005228
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005229 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005230
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005231 if [ "$MEMORY" -gt 0 ]; then
5232 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005233 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005234 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01005235}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005236
Gilles Peskine69f190e2019-01-10 00:11:42 +01005237component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005238 msg "build: Release (clang)"
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005239 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005240 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
5241 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005242
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005243 msg "test: main suites, Valgrind (default config)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005244 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005245
Gilles Peskine636c26a2020-03-04 20:46:15 +01005246 # Optional parts (slow; currently broken on OS X because programs don't
5247 # seem to receive signals under valgrind on OS X).
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005248 # These optional parts don't run on the CI.
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005249 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005250 msg "test: ssl-opt.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005251 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005252 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005253
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005254 if [ "$MEMORY" -gt 1 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005255 msg "test: compat.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005256 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005257 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02005258
5259 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005260 msg "test: context-info.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005261 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02005262 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01005263}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005264
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005265component_test_valgrind_psa () {
5266 msg "build: Release, full (clang)"
5267 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
5268 scripts/config.py full
5269 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
5270 make
5271
5272 msg "test: main suites, Valgrind (full config)"
5273 make memcheck
5274}
5275
Paul Elliott62dc3922021-11-25 17:29:40 +00005276support_test_cmake_out_of_source () {
5277 distrib_id=""
5278 distrib_ver=""
5279 distrib_ver_minor=""
5280 distrib_ver_major=""
5281
5282 # Attempt to parse lsb-release to find out distribution and version. If not
5283 # found this should fail safe (test is supported).
5284 if [[ -f /etc/lsb-release ]]; then
5285
5286 while read -r lsb_line; do
5287 case "$lsb_line" in
5288 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
5289 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
5290 esac
5291 done < /etc/lsb-release
5292
5293 distrib_ver_major="${distrib_ver%%.*}"
5294 distrib_ver="${distrib_ver#*.}"
5295 distrib_ver_minor="${distrib_ver%%.*}"
5296 fi
5297
5298 # Running the out of source CMake test on Ubuntu 16.04 using more than one
5299 # processor (as the CI does) can create a race condition whereby the build
5300 # fails to see a generated file, despite that file actually having been
5301 # generated. This problem appears to go away with 18.04 or newer, so make
5302 # the out of source tests unsupported on Ubuntu 16.04.
5303 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
5304}
5305
Gilles Peskine8f073122018-11-27 15:58:47 +01005306component_test_cmake_out_of_source () {
David Horstmann862abe22023-09-28 10:42:10 +01005307 # Remove existing generated files so that we use the ones cmake
David Horstmann9f48fff2023-09-27 15:53:54 +01005308 # generates
5309 make neat
5310
Gilles Peskine8f073122018-11-27 15:58:47 +01005311 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01005312 MBEDTLS_ROOT_DIR="$PWD"
5313 mkdir "$OUT_OF_SOURCE_DIR"
5314 cd "$OUT_OF_SOURCE_DIR"
David Horstmann9f48fff2023-09-27 15:53:54 +01005315 # Note: Explicitly generate files as these are turned off in releases
5316 cmake -D CMAKE_BUILD_TYPE:String=Check -D GEN_FILES=ON "$MBEDTLS_ROOT_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01005317 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005318
Gilles Peskine8f073122018-11-27 15:58:47 +01005319 msg "test: cmake 'out-of-source' build"
5320 make test
Gilles Peskinea841c2a2022-04-16 11:31:25 +02005321 # Check that ssl-opt.sh can find the test programs.
Gilles Peskine8f073122018-11-27 15:58:47 +01005322 # Also ensure that there are no error messages such as
5323 # "No such file or directory", which would indicate that some required
5324 # file is missing (ssl-opt.sh tolerates the absence of some files so
5325 # may exit with status 0 but emit errors).
Gilles Peskinea841c2a2022-04-16 11:31:25 +02005326 ./tests/ssl-opt.sh -f 'Default' >ssl-opt.out 2>ssl-opt.err
Gilles Peskine7393ec52022-04-15 22:43:38 +02005327 grep PASS ssl-opt.out
Gilles Peskinef7e956c2020-03-28 18:56:09 +01005328 cat ssl-opt.err >&2
5329 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005330 [ ! -s ssl-opt.err ]
Gilles Peskine7393ec52022-04-15 22:43:38 +02005331 rm ssl-opt.out ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01005332 cd "$MBEDTLS_ROOT_DIR"
5333 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01005334}
Andres AGdc192212016-08-31 17:33:13 +01005335
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005336component_test_cmake_as_subdirectory () {
David Horstmann9f48fff2023-09-27 15:53:54 +01005337 # Remove existing generated files so that we use the ones CMake
5338 # generates
5339 make neat
5340
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005341 msg "build: cmake 'as-subdirectory' build"
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005342 cd programs/test/cmake_subproject
David Horstmann9f48fff2023-09-27 15:53:54 +01005343 # Note: Explicitly generate files as these are turned off in releases
5344 cmake -D GEN_FILES=ON .
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005345 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005346 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005347}
Gilles Peskinea3000992022-02-04 00:21:12 +01005348support_test_cmake_as_subdirectory () {
5349 support_test_cmake_out_of_source
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005350}
5351
Chris Kayd259e342021-03-25 16:03:25 +00005352component_test_cmake_as_package () {
David Horstmann6c979852023-09-28 10:40:22 +01005353 # Remove existing generated files so that we use the ones CMake
5354 # generates
5355 make neat
5356
Chris Kayd259e342021-03-25 16:03:25 +00005357 msg "build: cmake 'as-package' build"
Chris Kayd259e342021-03-25 16:03:25 +00005358 cd programs/test/cmake_package
5359 cmake .
5360 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005361 ./cmake_package
Chris Kayd259e342021-03-25 16:03:25 +00005362}
Gilles Peskinea3000992022-02-04 00:21:12 +01005363support_test_cmake_as_package () {
5364 support_test_cmake_out_of_source
Chris Kayd259e342021-03-25 16:03:25 +00005365}
5366
5367component_test_cmake_as_package_install () {
David Horstmann6c979852023-09-28 10:40:22 +01005368 # Remove existing generated files so that we use the ones CMake
5369 # generates
5370 make neat
5371
Chris Kayd259e342021-03-25 16:03:25 +00005372 msg "build: cmake 'as-installed-package' build"
Chris Kayd259e342021-03-25 16:03:25 +00005373 cd programs/test/cmake_package_install
5374 cmake .
5375 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005376 ./cmake_package_install
Chris Kayd259e342021-03-25 16:03:25 +00005377}
Gilles Peskinea3000992022-02-04 00:21:12 +01005378support_test_cmake_as_package_install () {
5379 support_test_cmake_out_of_source
Chris Kayd259e342021-03-25 16:03:25 +00005380}
5381
David Horstmann20550e32023-01-12 14:17:01 +00005382component_build_cmake_custom_config_file () {
David Horstmann969c1452023-01-31 10:34:44 +00005383 # Make a copy of config file to use for the in-tree test
5384 cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h
David Horstmann20550e32023-01-12 14:17:01 +00005385
5386 MBEDTLS_ROOT_DIR="$PWD"
5387 mkdir "$OUT_OF_SOURCE_DIR"
5388 cd "$OUT_OF_SOURCE_DIR"
5389
David Horstmann969c1452023-01-31 10:34:44 +00005390 # Build once to get the generated files (which need an intact config file)
David Horstmann20550e32023-01-12 14:17:01 +00005391 cmake "$MBEDTLS_ROOT_DIR"
5392 make
5393
5394 msg "build: cmake with -DMBEDTLS_CONFIG_FILE"
5395 scripts/config.py -w full_config.h full
David Horstmann969c1452023-01-31 10:34:44 +00005396 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005397 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR"
5398 make
5399
5400 msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
5401 # In the user config, disable one feature (for simplicity, pick a feature
5402 # that nothing else depends on).
5403 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
5404
5405 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR"
5406 make
5407 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5408
5409 rm -f user_config.h full_config.h
5410
5411 cd "$MBEDTLS_ROOT_DIR"
5412 rm -rf "$OUT_OF_SOURCE_DIR"
5413
5414 # Now repeat the test for an in-tree build:
5415
David Horstmann969c1452023-01-31 10:34:44 +00005416 # Restore config for the in-tree test
5417 mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005418
David Horstmann969c1452023-01-31 10:34:44 +00005419 # Build once to get the generated files (which need an intact config)
David Horstmann20550e32023-01-12 14:17:01 +00005420 cmake .
5421 make
5422
5423 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE"
5424 scripts/config.py -w full_config.h full
David Horstmann969c1452023-01-31 10:34:44 +00005425 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005426 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h .
5427 make
5428
5429 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
5430 # In the user config, disable one feature (for simplicity, pick a feature
5431 # that nothing else depends on).
5432 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
5433
5434 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h .
5435 make
5436 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5437
5438 rm -f user_config.h full_config.h
5439}
5440support_build_cmake_custom_config_file () {
5441 support_test_cmake_out_of_source
5442}
5443
5444
Tom Cosgrovedaddf112023-09-01 10:40:15 +01005445component_build_zeroize_checks () {
5446 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
5447
5448 scripts/config.py full
5449
5450 # Only compile - we're looking for sizeof-pointer-memaccess warnings
Tom Cosgroveb2fafa52023-09-01 14:40:21 +01005451 make CC=gcc CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess"
Tom Cosgrovedaddf112023-09-01 10:40:15 +01005452}
5453
5454
Gilles Peskine8f073122018-11-27 15:58:47 +01005455component_test_zeroize () {
5456 # Test that the function mbedtls_platform_zeroize() is not optimized away by
5457 # different combinations of compilers and optimization flags by using an
5458 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
5459 # system in all cases that the script fails, so we must manually search the
5460 # output to check whether the pass string is present and no failure strings
5461 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01005462
Gilles Peskine4976e822019-01-06 19:52:22 +00005463 # Don't try to disable ASLR. We don't care about ASLR here. We do care
5464 # about a spurious message if Gdb tries and fails, so suppress that.
5465 gdb_disable_aslr=
5466 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
5467 gdb_disable_aslr='set disable-randomization off'
5468 fi
5469
Gilles Peskine8f073122018-11-27 15:58:47 +01005470 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01005471 for compiler in clang gcc; do
5472 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
5473 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005474 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
5475 grep "The buffer was correctly zeroized" test_zeroize.log
5476 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01005477 rm -f test_zeroize.log
5478 make clean
5479 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01005480 done
Gilles Peskine8f073122018-11-27 15:58:47 +01005481}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005482
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005483component_test_psa_compliance () {
5484 msg "build: make, default config (out-of-box), libmbedcrypto.a only"
Bence Szépkútica9236b2021-10-25 19:29:07 +02005485 make -C library libmbedcrypto.a
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005486
5487 msg "unit test: test_psa_compliance.py"
5488 ./tests/scripts/test_psa_compliance.py
5489}
5490
5491support_test_psa_compliance () {
Bence Szépkútief0d02e2021-11-03 11:36:09 +01005492 # psa-compliance-tests only supports CMake >= 3.10.0
Bence Szépkútica9236b2021-10-25 19:29:07 +02005493 ver="$(cmake --version)"
5494 ver="${ver#cmake version }"
5495 ver_major="${ver%%.*}"
5496
5497 ver="${ver#*.}"
5498 ver_minor="${ver%%.*}"
5499
5500 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005501}
5502
Gilles Peskinec848d222022-12-09 12:23:35 +01005503component_check_code_style () {
5504 msg "Check C code style"
5505 ./scripts/code_style.py
David Horstmann92b5ac12022-11-10 18:30:52 +00005506}
5507
Gilles Peskinec848d222022-12-09 12:23:35 +01005508support_check_code_style() {
David Horstmann92b5ac12022-11-10 18:30:52 +00005509 case $(uncrustify --version) in
5510 *0.75.1*) true;;
5511 *) false;;
5512 esac
5513}
5514
Gilles Peskine8f073122018-11-27 15:58:47 +01005515component_check_python_files () {
5516 msg "Lint: Python scripts"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005517 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01005518}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005519
Joe Subbianid614c0b2021-07-29 11:18:29 +01005520component_check_test_helpers () {
5521 msg "unit test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02005522 # unittest writes out mundane stuff like number or tests run on stderr.
5523 # Our convention is to reserve stderr for actual errors, and write
5524 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005525 ./tests/scripts/test_generate_test_code.py 2>&1
Joe Subbianid614c0b2021-07-29 11:18:29 +01005526
Joe Subbiania25ffab2021-08-06 09:41:27 +01005527 msg "unit test: translate_ciphers.py"
5528 python3 -m unittest tests/scripts/translate_ciphers.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01005529}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005530
Jerry Yud767cc42023-03-31 15:03:55 +08005531
Gilles Peskine192c72f2017-12-21 15:59:21 +01005532################################################################
5533#### Termination
5534################################################################
5535
Gilles Peskine8f073122018-11-27 15:58:47 +01005536post_report () {
5537 msg "Done, cleaning up"
Gilles Peskinef83eb822020-03-30 20:11:39 +02005538 final_cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005539
Gilles Peskine8f073122018-11-27 15:58:47 +01005540 final_report
5541}
5542
5543
5544
5545################################################################
5546#### Run all the things
5547################################################################
5548
Gilles Peskine5d996822020-03-28 21:09:21 +01005549# Function invoked by --error-test to test error reporting.
5550pseudo_component_error_test () {
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005551 msg "Testing error reporting $error_test_i"
Gilles Peskine5d996822020-03-28 21:09:21 +01005552 if [ $KEEP_GOING -ne 0 ]; then
5553 echo "Expect three failing commands."
5554 fi
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005555 # If the component doesn't run in a subshell, changing error_test_i to an
5556 # invalid integer will cause an error in the loop that runs this function.
5557 error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
Gilles Peskineec135542021-08-02 23:14:03 +02005558 # Expected error: 'grep non_existent /dev/null -> 1'
Gilles Peskine5d996822020-03-28 21:09:21 +01005559 grep non_existent /dev/null
Gilles Peskineec135542021-08-02 23:14:03 +02005560 # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
Gilles Peskine5d996822020-03-28 21:09:21 +01005561 not grep -q . "$0"
Gilles Peskineec135542021-08-02 23:14:03 +02005562 # Expected error: 'make unknown_target -> 2'
Gilles Peskine5d996822020-03-28 21:09:21 +01005563 make unknown_target
5564 false "this should not be executed"
5565}
5566
Gilles Peskinee48351a2018-11-27 16:06:30 +01005567# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01005568run_component () {
Gilles Peskineffcdeff2018-12-04 12:49:28 +01005569 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02005570 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005571
5572 # Unconditionally create a seedfile that's sufficiently long.
5573 # Do this before each component, because a previous component may
5574 # have messed it up or shortened it.
Gilles Peskine88a07452021-07-08 19:03:50 +02005575 local dd_cmd
5576 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
5577 case $OSTYPE in
Tom Cosgrove226aca12022-03-16 14:11:07 +00005578 linux*|freebsd*|openbsd*) dd_cmd+=(status=none)
Gilles Peskine88a07452021-07-08 19:03:50 +02005579 esac
5580 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005581
Gilles Peskineec135542021-08-02 23:14:03 +02005582 # Run the component in a subshell, with error trapping and output
5583 # redirection set up based on the relevant options.
Gilles Peskinece266c42020-03-28 18:50:43 +01005584 if [ $KEEP_GOING -eq 1 ]; then
Gilles Peskineec135542021-08-02 23:14:03 +02005585 # We want to keep running if the subshell fails, so 'set -e' must
5586 # be off when the subshell runs.
Gilles Peskinece266c42020-03-28 18:50:43 +01005587 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02005588 fi
Gilles Peskinece266c42020-03-28 18:50:43 +01005589 (
5590 if [ $QUIET -eq 1 ]; then
5591 # msg() will be silenced, so just print the component name here.
5592 echo "${current_component#component_}"
5593 exec >/dev/null
5594 fi
5595 if [ $KEEP_GOING -eq 1 ]; then
5596 # Keep "set -e" off, and run an ERR trap instead to record failures.
5597 set -E
5598 trap err_trap ERR
5599 fi
5600 # The next line is what runs the component
5601 "$@"
5602 if [ $KEEP_GOING -eq 1 ]; then
5603 trap - ERR
5604 exit $last_failure_status
5605 fi
5606 )
5607 component_status=$?
5608 if [ $KEEP_GOING -eq 1 ]; then
5609 set -e
5610 if [ $component_status -ne 0 ]; then
5611 failure_count=$((failure_count + 1))
5612 fi
5613 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005614
5615 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01005616 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02005617 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01005618}
5619
5620# Preliminary setup
5621pre_check_environment
Tom Cosgrove730addc2023-06-09 14:20:18 +01005622pre_parse_command_line_for_dirs "$@"
Gilles Peskine8f073122018-11-27 15:58:47 +01005623pre_initialize_variables
5624pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01005625
Gilles Peskine878cf602019-01-06 20:50:38 +00005626pre_check_git
Gilles Peskine568f53a2021-07-12 18:16:01 +02005627pre_restore_files
Gilles Peskinef83eb822020-03-30 20:11:39 +02005628pre_back_up
Andrzej Kurekeb508712019-02-14 07:18:59 -05005629
Gilles Peskine878cf602019-01-06 20:50:38 +00005630build_status=0
5631if [ $KEEP_GOING -eq 1 ]; then
5632 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01005633fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02005634pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00005635pre_print_configuration
5636pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005637cleanup
David Horstmann76a77382023-08-17 17:32:26 +01005638if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +01005639 pre_generate_files
5640fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005641
Gilles Peskinebeb3a812019-01-06 22:11:25 +00005642# Run the requested tests.
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005643for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
Gilles Peskine5d996822020-03-28 21:09:21 +01005644 run_component pseudo_component_error_test
Gilles Peskine5d996822020-03-28 21:09:21 +01005645done
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005646unset error_test_i
Gilles Peskinebeb3a812019-01-06 22:11:25 +00005647for component in $RUN_COMPONENTS; do
5648 run_component "component_$component"
5649done
Gilles Peskine8f073122018-11-27 15:58:47 +01005650
5651# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00005652post_report