blob: 9290aa6d910776bd3561d699d804fe57cbd95de1 [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 Peskine7be571a2023-08-27 21:39:21 +020053# * OpenSSL and GnuTLS command line tools, in suitable versions for the
54# interoperability tests. The following are the official versions at the
55# time of writing:
56# * GNUTLS_{CLI,SERV} = 3.4.10
57# * GNUTLS_NEXT_{CLI,SERV} = 3.7.2
58# * OPENSSL = 1.0.2g (without Debian/Ubuntu patches)
59# * OPENSSL_NEXT = 1.1.1a
Gilles Peskine192c72f2017-12-21 15:59:21 +010060# See the invocation of check_tools below for details.
61#
62# This script must be invoked from the toplevel directory of a git
63# working copy of Mbed TLS.
64#
Gilles Peskinece266c42020-03-28 18:50:43 +010065# The behavior on an error depends on whether --keep-going (alias -k)
66# is in effect.
67# * Without --keep-going: the script stops on the first error without
68# cleaning up. This lets you work in the configuration of the failing
69# component.
70# * With --keep-going: the script runs all requested components and
71# reports failures at the end. In particular the script always cleans
72# up on exit.
73#
Gilles Peskine192c72f2017-12-21 15:59:21 +010074# Note that the output is not saved. You may want to run
75# script -c tests/scripts/all.sh
76# or
77# tests/scripts/all.sh >all.log 2>&1
78#
79# Notes for maintainers
80# ---------------------
81#
Gilles Peskine8f073122018-11-27 15:58:47 +010082# The bulk of the code is organized into functions that follow one of the
83# following naming conventions:
84# * pre_XXX: things to do before running the tests, in order.
85# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010086# * component_check_XXX: quick tests that aren't worth parallelizing.
87# * component_build_XXX: build things but don't run them.
88# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000089# * support_XXX: if support_XXX exists and returns false then
90# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010091# * post_XXX: things to do after running the tests.
92# * other: miscellaneous support functions.
93#
Gilles Peskinec70637a2019-01-09 22:29:17 +010094# Each component must start by invoking `msg` with a short informative message.
95#
Gilles Peskinea681c592020-03-28 21:27:40 +010096# Warning: due to the way bash detects errors, the failure of a command
97# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
98#
Gilles Peskinece266c42020-03-28 18:50:43 +010099# Each component is executed in a separate shell process. The component
100# fails if any command in it returns a non-zero status.
101#
Gilles Peskinec70637a2019-01-09 22:29:17 +0100102# The framework performs some cleanup tasks after each component. This
103# means that components can assume that the working directory is in a
104# cleaned-up state, and don't need to perform the cleanup themselves.
105# * Run `make clean`.
Bence Szépkúti414d6bd2021-06-28 14:11:11 +0100106# * Restore `include/mbedtls/mbedtls_config.h` from a backup made before running
Gilles Peskinec70637a2019-01-09 22:29:17 +0100107# the component.
Gilles Peskine636c26a2020-03-04 20:46:15 +0100108# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
109# `tests/Makefile` and `programs/fuzz/Makefile` from git.
110# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +0100111#
Gilles Peskine192c72f2017-12-21 15:59:21 +0100112# The tests are roughly in order from fastest to slowest. This doesn't
113# have to be exact, but in general you should add slower tests towards
114# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100115
116
117
118################################################################
119#### Initialization and command line parsing
120################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100121
Gilles Peskine36647802020-03-28 18:50:49 +0100122# Abort on errors (even on the left-hand side of a pipe).
123# Treat uninitialised variables as errors.
124set -e -o pipefail -u
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100125
Gilles Peskine076f7252022-08-30 21:02:44 +0200126# Enable ksh/bash extended file matching patterns
127shopt -s extglob
128
David Horstmann76a77382023-08-17 17:32:26 +0100129in_mbedtls_repo () {
David Horstmannd02b5f82023-08-29 09:53:52 +0100130 test -d include -a -d library -a -d programs -a -d tests
131}
132
Ronald Cron070e8652023-10-09 10:25:45 +0200133in_tf_psa_crypto_repo () {
David Horstmannd02b5f82023-08-29 09:53:52 +0100134 test -d include -a -d core -a -d drivers -a -d programs -a -d tests
David Horstmann9a6c45b2023-07-14 12:30:00 +0100135}
136
Gilles Peskine8f073122018-11-27 15:58:47 +0100137pre_check_environment () {
Ronald Cron070e8652023-10-09 10:25:45 +0200138 if in_mbedtls_repo || in_tf_psa_crypto_repo; then :; else
139 echo "Must be run from Mbed TLS / TF-PSA-Crypto root" >&2
Gilles Peskine8f073122018-11-27 15:58:47 +0100140 exit 1
141 fi
142}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100143
Gilles Peskine8f073122018-11-27 15:58:47 +0100144pre_initialize_variables () {
David Horstmann76a77382023-08-17 17:32:26 +0100145 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100146 CONFIG_H='include/mbedtls/mbedtls_config.h'
David Horstmann76a77382023-08-17 17:32:26 +0100147 else
148 CONFIG_H='drivers/builtin/include/mbedtls/mbedtls_config.h'
David Horstmann9a6c45b2023-07-14 12:30:00 +0100149 fi
John Durkopbd069d32020-10-31 22:14:03 -0700150 CRYPTO_CONFIG_H='include/psa/crypto_config.h'
Manuel Pégourié-Gonnard462e3a92022-12-27 12:35:11 +0100151 CONFIG_TEST_DRIVER_H='tests/include/test/drivers/config_test_driver.h'
Gilles Peskinef83eb822020-03-30 20:11:39 +0200152
153 # Files that are clobbered by some jobs will be backed up. Use a different
154 # suffix from auxiliary scripts so that all.sh and auxiliary scripts can
155 # independently decide when to remove the backup file.
156 backup_suffix='.all.bak'
157 # Files clobbered by config.py
Janos Follath2f045822023-07-31 10:57:16 +0100158 files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H $CONFIG_TEST_DRIVER_H"
David Horstmann76a77382023-08-17 17:32:26 +0100159 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100160 # Files clobbered by in-tree cmake
161 files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile"
162 fi
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200163
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200164 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100165 MEMORY=0
166 FORCE=0
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200167 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100168 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100169
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200170 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard54304472020-06-22 10:11:47 +0200171 #
172 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
173 # both values are kept in sync. If you change the value here because it
174 # breaks some tests, you'll definitely want to change it in
175 # basic-build-test.sh as well.
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200176 RELEASE_SEED=1
177
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200178 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200179 : ${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 +0200180 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200181 export MBEDTLS_TEST_PLATFORM
182
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000183 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100184 : ${OPENSSL:="openssl"}
Gilles Peskine8f073122018-11-27 15:58:47 +0100185 : ${OPENSSL_NEXT:="$OPENSSL"}
186 : ${GNUTLS_CLI:="gnutls-cli"}
187 : ${GNUTLS_SERV:="gnutls-serv"}
Gilles Peskine8f073122018-11-27 15:58:47 +0100188 : ${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.
Gilles Peskine709346a2017-12-10 23:43:39 +0100303 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100304 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100305EOF
SimonB2e23c822016-04-16 21:54:39 +0100306}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100307
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200308# Cleanup before/after running a component.
309# Remove built files as well as the cmake cache/config.
310# Does not remove generated source files.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100311cleanup()
312{
David Horstmann76a77382023-08-17 17:32:26 +0100313 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100314 command make clean
315 fi
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200316
Gilles Peskine31b07e22018-03-21 12:15:06 +0100317 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000318 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100319 -iname CMakeFiles -exec rm -rf {} \+ -o \
320 \( -iname cmake_install.cmake -o \
321 -iname CTestTestfile.cmake -o \
Manuel Pégourié-Gonnardbfe54d72021-09-09 11:11:44 +0200322 -iname CMakeCache.txt -o \
323 -path './cmake/*.cmake' \) -exec rm -f {} \+
Gilles Peskine31b07e22018-03-21 12:15:06 +0100324 # Recover files overwritten by in-tree CMake builds
Gilles Peskine076f7252022-08-30 21:02:44 +0200325 rm -f include/Makefile include/mbedtls/Makefile programs/!(fuzz)/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200326
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100327 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
328 rm -rf programs/test/cmake_subproject/build
329 rm -f programs/test/cmake_subproject/Makefile
330 rm -f programs/test/cmake_subproject/cmake_subproject
331
Chris Kayd259e342021-03-25 16:03:25 +0000332 # Remove any artifacts from the component_test_cmake_as_package test.
333 rm -rf programs/test/cmake_package/build
334 rm -f programs/test/cmake_package/Makefile
335 rm -f programs/test/cmake_package/cmake_package
336
337 # Remove any artifacts from the component_test_cmake_as_installed_package test.
338 rm -rf programs/test/cmake_package_install/build
339 rm -f programs/test/cmake_package_install/Makefile
340 rm -f programs/test/cmake_package_install/cmake_package_install
341
Gilles Peskinef83eb822020-03-30 20:11:39 +0200342 # Restore files that may have been clobbered by the job
343 for x in $files_to_back_up; do
Gilles Peskinedd06efb2022-08-30 21:02:00 +0200344 if [[ -e "$x$backup_suffix" ]]; then
345 cp -p "$x$backup_suffix" "$x"
346 fi
Gilles Peskinef83eb822020-03-30 20:11:39 +0200347 done
348}
John Durkopbd069d32020-10-31 22:14:03 -0700349
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200350# Final cleanup when this script exits (except when exiting on a failure
351# in non-keep-going mode).
Gilles Peskinef83eb822020-03-30 20:11:39 +0200352final_cleanup () {
353 cleanup
354
355 for x in $files_to_back_up; do
356 rm -f "$x$backup_suffix"
357 done
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100358}
359
Gilles Peskine7c652162017-12-11 00:01:40 +0100360# Executed on exit. May be redefined depending on command line options.
361final_report () {
362 :
363}
364
365fatal_signal () {
Gilles Peskinef83eb822020-03-30 20:11:39 +0200366 final_cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100367 final_report $1
368 trap - $1
369 kill -$1 $$
370}
371
372trap 'fatal_signal HUP' HUP
373trap 'fatal_signal INT' INT
374trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200375
Gilles Peskine050d2fc2021-09-30 18:24:21 +0200376# Number of processors on this machine. Used as the default setting
377# for parallel make.
378all_sh_nproc ()
379{
380 {
381 nproc || # Linux
382 sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
383 sysctl -n hw.ncpu || # FreeBSD
384 echo 1
385 } 2>/dev/null
386}
387
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100388msg()
389{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100390 if [ -n "${current_component:-}" ]; then
391 current_section="${current_component#component_}: $1"
392 else
393 current_section="$1"
394 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200395
396 if [ $QUIET -eq 1 ]; then
397 return
398 fi
399
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100400 echo ""
401 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100402 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000403 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100404 echo "******************************************************************"
405}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100406
Gilles Peskine8f073122018-11-27 15:58:47 +0100407armc6_build_test()
408{
409 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100410
Gilles Peskine18487f62020-04-30 23:11:54 +0200411 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100412 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
Dave Rodgman1c232a82023-03-02 13:39:04 +0000413 WARNING_CFLAGS='-Werror -xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200414
415 msg "size: ARM Compiler 6 ($FLAGS)"
416 "$ARMC6_FROMELF" -z library/*.o
417
Gilles Peskine8f073122018-11-27 15:58:47 +0100418 make clean
419}
Andres AGa5cd9732016-10-17 15:23:10 +0100420
Andres AGd9eba4b2016-08-26 14:42:14 +0100421err_msg()
422{
423 echo "$1" >&2
424}
425
426check_tools()
427{
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200428 for tool in "$@"; do
429 if ! `type "$tool" >/dev/null 2>&1`; then
430 err_msg "$tool not found!"
Andres AGd9eba4b2016-08-26 14:42:14 +0100431 exit 1
432 fi
433 done
434}
435
Tom Cosgrove730addc2023-06-09 14:20:18 +0100436pre_parse_command_line_for_dirs () {
437 # Make an early pass through the options given, so we can set directories
438 # for Arm compilers, before SUPPORTED_COMPONENTS is determined.
439 while [ $# -gt 0 ]; do
440 case "$1" in
441 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
442 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
443 esac
444 shift
445 done
446}
447
Gilles Peskine8f073122018-11-27 15:58:47 +0100448pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000449 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100450 all_except=0
Gilles Peskine5d996822020-03-28 21:09:21 +0100451 error_test=0
Gilles Peskine80ddb992021-08-06 11:51:59 +0200452 restore_first=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000453 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100454
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000455 # Note that legacy options are ignored instead of being omitted from this
456 # list of options, so invocations that worked with previous version of
457 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100458 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100459 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200460 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200461 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +0200462 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000463 --armcc) no_armcc=;;
Tom Cosgrove730addc2023-06-09 14:20:18 +0100464 --armc5-bin-dir) shift; ;; # assignment to ARMC5_BIN_DIR done in pre_parse_command_line_for_dirs
465 --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 +0100466 --clang-earliest) shift; CLANG_EARLIEST="$1";;
467 --clang-latest) shift; CLANG_LATEST="$1";;
Gilles Peskine5d996822020-03-28 21:09:21 +0100468 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000469 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100470 --force|-f) FORCE=1;;
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +0100471 --gcc-earliest) shift; GCC_EARLIEST="$1";;
472 --gcc-latest) shift; GCC_LATEST="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100473 --gnutls-cli) shift; GNUTLS_CLI="$1";;
Gilles Peskine7be571a2023-08-27 21:39:21 +0200474 --gnutls-legacy-cli) shift;; # ignored for backward compatibility
475 --gnutls-legacy-serv) shift;; # ignored for backward compatibility
Gilles Peskine55f7c942019-01-09 22:28:21 +0100476 --gnutls-serv) shift; GNUTLS_SERV="$1";;
477 --help|-h) usage; exit;;
478 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000479 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
480 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100481 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200482 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000483 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100484 --no-force) FORCE=0;;
485 --no-keep-going) KEEP_GOING=0;;
486 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200487 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100488 --openssl) shift; OPENSSL="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100489 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200490 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100491 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200492 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100493 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200494 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine80ddb992021-08-06 11:51:59 +0200495 --restore) restore_first=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100496 --seed|-s) shift; SEED="$1";;
497 -*)
498 echo >&2 "Unknown option: $1"
499 echo >&2 "Run $0 --help for usage."
500 exit 120
501 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000502 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100503 esac
504 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100505 done
SimonB2e23c822016-04-16 21:54:39 +0100506
Gilles Peskinea28db922019-01-10 00:05:18 +0100507 # With no list of components, run everything.
Gilles Peskine80ddb992021-08-06 11:51:59 +0200508 if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000509 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100510 fi
511
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000512 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
513 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100514 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000515 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100516 fi
SimonB2e23c822016-04-16 21:54:39 +0100517
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200518 # Error out if an explicitly requested component doesn't exist.
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100519 if [ $all_except -eq 0 ]; then
520 unsupported=0
Gilles Peskine03af6782021-08-06 11:35:17 +0200521 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
522 # only does word splitting.
Gilles Peskine1d475b62021-08-03 13:43:36 +0200523 set -f
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100524 for component in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine1d475b62021-08-03 13:43:36 +0200525 set +f
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200526 # If the requested name includes a wildcard character, don't
527 # check it. Accept wildcard patterns that don't match anything.
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100528 case $component in
529 *[*?\[]*) continue;;
530 esac
531 case " $SUPPORTED_COMPONENTS " in
532 *" $component "*) :;;
533 *)
534 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
535 unsupported=$((unsupported + 1));;
536 esac
537 done
Gilles Peskine1d475b62021-08-03 13:43:36 +0200538 set +f
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100539 if [ $unsupported -ne 0 ]; then
540 exit 2
541 fi
542 fi
543
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000544 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100545 RUN_COMPONENTS=
546 for component in $SUPPORTED_COMPONENTS; do
547 if is_component_included "$component"; [ $? -eq $all_except ]; then
548 RUN_COMPONENTS="$RUN_COMPONENTS $component"
549 fi
550 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000551
552 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000553 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100554}
SimonB2e23c822016-04-16 21:54:39 +0100555
Gilles Peskine8f073122018-11-27 15:58:47 +0100556pre_check_git () {
557 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100558 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100559 git checkout-index -f -q $CONFIG_H
560 cleanup
561 else
SimonB2e23c822016-04-16 21:54:39 +0100562
Gilles Peskine8f073122018-11-27 15:58:47 +0100563 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
564 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
565 echo "You can either delete this directory manually, or force the test by rerunning"
566 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
567 exit 1
568 fi
569
Ronald Cron7a93ac52023-07-20 09:49:12 +0200570 if ! git diff --quiet "$CONFIG_H"; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100571 err_msg "Warning - the configuration file '$CONFIG_H' has been edited. "
Gilles Peskine8f073122018-11-27 15:58:47 +0100572 echo "You can either delete or preserve your work, or force the test by rerunning the"
573 echo "script as: $0 --force"
574 exit 1
575 fi
SimonB2e23c822016-04-16 21:54:39 +0100576 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500577}
578
Gilles Peskine568f53a2021-07-12 18:16:01 +0200579pre_restore_files () {
580 # If the makefiles have been generated by a framework such as cmake,
581 # restore them from git. If the makefiles look like modifications from
582 # the ones checked into git, take care not to modify them. Whatever
583 # this function leaves behind is what the script will restore before
584 # each component.
585 case "$(head -n1 Makefile)" in
586 *[Gg]enerated*)
587 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
588 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
589 ;;
590 esac
591}
592
Gilles Peskinef83eb822020-03-30 20:11:39 +0200593pre_back_up () {
594 for x in $files_to_back_up; do
595 cp -p "$x" "$x$backup_suffix"
596 done
597}
598
Gilles Peskine8f073122018-11-27 15:58:47 +0100599pre_setup_keep_going () {
Gilles Peskinece266c42020-03-28 18:50:43 +0100600 failure_count=0 # Number of failed components
601 last_failure_status=0 # Last failure status in this component
602
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100603 # See err_trap
604 previous_failure_status=0
605 previous_failed_command=
606 previous_failure_funcall_depth=0
Gilles Peskinea681c592020-03-28 21:27:40 +0100607 unset report_failed_command
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100608
Gilles Peskine7c652162017-12-11 00:01:40 +0100609 start_red=
610 end_color=
611 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100612 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100613 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
614 start_red=$(printf '\033[31m')
615 end_color=$(printf '\033[0m')
616 ;;
617 esac
618 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100619
620 # Keep a summary of failures in a file. We'll print it out at the end.
621 failure_summary_file=$PWD/all-sh-failures-$$.log
622 : >"$failure_summary_file"
623
624 # Whether it makes sense to keep a component going after the specified
625 # command fails (test command) or not (configure or build).
Gilles Peskine03af6782021-08-06 11:35:17 +0200626 # This function normally receives the failing simple command
627 # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
628 # this is passed instead.
Gilles Peskinece266c42020-03-28 18:50:43 +0100629 # This doesn't have to be 100% accurate: all failures are recorded anyway.
Gilles Peskinec111e242021-08-02 23:29:53 +0200630 # False positives result in running things that can't be expected to
631 # work. False negatives result in things not running after something else
632 # failed even though they might have given useful feedback.
Gilles Peskinece266c42020-03-28 18:50:43 +0100633 can_keep_going_after_failure () {
634 case "$1" in
635 "msg "*) false;;
Gilles Peskinec111e242021-08-02 23:29:53 +0200636 "cd "*) false;;
637 *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
638 *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
639 *make*check*) true;;
640 "grep "*) true;;
641 "[ "*) true;;
642 "! "*) true;;
Gilles Peskinece266c42020-03-28 18:50:43 +0100643 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100644 esac
645 }
Gilles Peskinece266c42020-03-28 18:50:43 +0100646
647 # This function runs if there is any error in a component.
648 # It must either exit with a nonzero status, or set
649 # last_failure_status to a nonzero value.
650 err_trap () {
651 # Save $? (status of the failing command). This must be the very
652 # first thing, before $? is overridden.
653 last_failure_status=$?
Gilles Peskinea681c592020-03-28 21:27:40 +0100654 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskinece266c42020-03-28 18:50:43 +0100655
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100656 if [[ $last_failure_status -eq $previous_failure_status &&
657 "$failed_command" == "$previous_failed_command" &&
658 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
659 then
660 # The same command failed twice in a row, but this time one level
661 # less deep in the function call stack. This happens when the last
662 # command of a function returns a nonzero status, and the function
663 # returns that same status. Ignore the second failure.
664 previous_failure_funcall_depth=${#FUNCNAME[@]}
665 return
666 fi
667 previous_failure_status=$last_failure_status
668 previous_failed_command=$failed_command
669 previous_failure_funcall_depth=${#FUNCNAME[@]}
670
Gilles Peskinece266c42020-03-28 18:50:43 +0100671 text="$current_section: $failed_command -> $last_failure_status"
672 echo "${start_red}^^^^$text^^^^${end_color}" >&2
673 echo "$text" >>"$failure_summary_file"
674
675 # If the command is fatal (configure or build command), stop this
676 # component. Otherwise (test command) keep the component running
677 # (run more tests from the same build).
678 if ! can_keep_going_after_failure "$failed_command"; then
679 exit $last_failure_status
680 fi
681 }
682
Gilles Peskine7c652162017-12-11 00:01:40 +0100683 final_report () {
684 if [ $failure_count -gt 0 ]; then
685 echo
686 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskinece266c42020-03-28 18:50:43 +0100687 echo "${start_red}FAILED: $failure_count components${end_color}"
688 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100689 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
690 elif [ -z "${1-}" ]; then
691 echo "SUCCESS :)"
692 fi
693 if [ -n "${1-}" ]; then
694 echo "Killed by SIG$1."
695 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100696 rm -f "$failure_summary_file"
697 if [ $failure_count -gt 0 ]; then
698 exit 1
699 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100700 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100701}
702
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200703# record_status() and if_build_succeeded() are kept temporarily for backward
704# compatibility. Don't use them in new components.
Gilles Peskinece266c42020-03-28 18:50:43 +0100705record_status () {
706 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100707}
Gilles Peskine7c652162017-12-11 00:01:40 +0100708if_build_succeeded () {
Gilles Peskinece266c42020-03-28 18:50:43 +0100709 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100710}
711
Gilles Peskinea681c592020-03-28 21:27:40 +0100712# '! true' does not trigger the ERR trap. Arrange to trigger it, with
713# a reasonably informative error message (not just "$@").
714not () {
715 if "$@"; then
716 report_failed_command="! $*"
717 false
718 unset report_failed_command
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200719 fi
720}
721
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200722pre_prepare_outcome_file () {
723 case "$MBEDTLS_TEST_OUTCOME_FILE" in
724 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
725 esac
726 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
727 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
728 fi
729}
730
Gilles Peskine8f073122018-11-27 15:58:47 +0100731pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200732 if [ $QUIET -eq 1 ]; then
733 return
734 fi
735
Gilles Peskine8f073122018-11-27 15:58:47 +0100736 msg "info: $0 configuration"
737 echo "MEMORY: $MEMORY"
738 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200739 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100740 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100741 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100742 echo "OPENSSL: $OPENSSL"
Gilles Peskine8f073122018-11-27 15:58:47 +0100743 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
744 echo "GNUTLS_CLI: $GNUTLS_CLI"
745 echo "GNUTLS_SERV: $GNUTLS_SERV"
Gilles Peskine8f073122018-11-27 15:58:47 +0100746 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
747 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
748}
Andres AG7770ea82016-10-10 15:46:20 +0100749
Andres AGd9eba4b2016-08-26 14:42:14 +0100750# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100751pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000752 # Build the list of variables to pass to output_env.sh.
753 set env
SimonB2e23c822016-04-16 21:54:39 +0100754
Gilles Peskine87964262019-01-06 22:40:00 +0000755 case " $RUN_COMPONENTS " in
756 # Require OpenSSL and GnuTLS if running any tests (as opposed to
757 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
758 # is a good enough approximation in practice.
759 *" test_"*)
760 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
761 # and ssl-opt.sh, we just export the variables they require.
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +0100762 export OPENSSL="$OPENSSL"
Gilles Peskine87964262019-01-06 22:40:00 +0000763 export GNUTLS_CLI="$GNUTLS_CLI"
764 export GNUTLS_SERV="$GNUTLS_SERV"
765 # Avoid passing --seed flag in every call to ssl-opt.sh
766 if [ -n "${SEED-}" ]; then
767 export SEED
768 fi
Gilles Peskine7be571a2023-08-27 21:39:21 +0200769 set "$@" OPENSSL="$OPENSSL"
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000770 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
Gilles Peskine7be571a2023-08-27 21:39:21 +0200771 check_tools "$OPENSSL" "$OPENSSL_NEXT" \
772 "$GNUTLS_CLI" "$GNUTLS_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000773 ;;
774 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200775
Gilles Peskine87964262019-01-06 22:40:00 +0000776 case " $RUN_COMPONENTS " in
777 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
778 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100779
Gilles Peskine87964262019-01-06 22:40:00 +0000780 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200781 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000782 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100783
Gilles Peskine87964262019-01-06 22:40:00 +0000784 case " $RUN_COMPONENTS " in
785 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
786 esac
787
788 case " $RUN_COMPONENTS " in
789 *" test_zeroize "*) check_tools "gdb";;
790 esac
791
792 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000793 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000794 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
795 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200796 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000797 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
798 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200799 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
800 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
801 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000802 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000803
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200804 # past this point, no call to check_tool, only printing output
805 if [ $QUIET -eq 1 ]; then
806 return
807 fi
808
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000809 msg "info: output_env.sh"
810 case $RUN_COMPONENTS in
811 *_armcc*)
812 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
813 *) set "$@" RUN_ARMCC=0;;
814 esac
815 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100816}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100817
Gilles Peskine1570b592021-04-22 01:10:12 +0200818pre_generate_files() {
Manuel Pégourié-Gonnard87db8a22021-06-18 13:30:14 +0200819 # since make doesn't have proper dependencies, remove any possibly outdate
820 # file that might be around before generating fresh ones
821 make neat
Gilles Peskine72385032021-07-08 19:07:07 +0200822 if [ $QUIET -eq 1 ]; then
Gilles Peskine75301632021-08-05 15:10:47 +0200823 make generated_files >/dev/null
Gilles Peskine72385032021-07-08 19:07:07 +0200824 else
825 make generated_files
826 fi
Gilles Peskine1570b592021-04-22 01:10:12 +0200827}
828
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200829################################################################
830#### Helpers for components using libtestdriver1
831################################################################
Gilles Peskine192c72f2017-12-21 15:59:21 +0100832
Manuel Pégourié-Gonnardf5c5d972023-06-06 11:14:57 +0200833# How to use libtestdriver1
834# -------------------------
835#
836# 1. Define the list algorithms and key types to accelerate,
837# designated the same way as PSA_WANT_ macros but without PSA_WANT_.
838# Examples:
839# - loc_accel_list="ALG_JPAKE"
840# - loc_accel_list="ALG_FFDH KEY_TYPE_DH_KEY_PAIR KEY_TYPE_DH_PUBLIC_KEY"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200841# 2. Make configurations changes for the driver and/or main libraries.
842# 2a. Call helper_libtestdriver1_adjust_config <base>, where the argument
843# can be either "default" to start with the default config, or a name
844# supported by scripts/config.py (for example, "full"). This selects
Manuel Pégourié-Gonnard2336c8e2023-06-12 17:17:54 +0200845# the base to use, and makes common adjustments.
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200846# 2b. If desired, adjust the PSA_WANT symbols in psa/crypto_config.h.
847# These changes affect both the driver and the main libraries.
848# (Note: they need to have the same set of PSA_WANT symbols, as that
849# determines the ABI between them.)
850# 2c. Adjust MBEDTLS_ symbols in mbedtls_config.h. This only affects the
851# main libraries. Typically, you want to disable the module(s) that are
852# being accelerated. You may need to also disable modules that depend
853# on them or options that are not supported with drivers.
854# 2d. On top of psa/crypto_config.h, the driver library uses its own config
855# file: tests/include/test/drivers/config_test_driver.h. You usually
856# don't need to edit it: using loc_extra_list (see below) is preferred.
857# However, when there's no PSA symbol for what you want to enable,
858# calling scripts/config.py on this file remains the only option.
859# 3. Build the driver library, then the main libraries, test, and programs.
860# 3a. Call helper_libtestdriver1_make_drivers "$loc_accel_list". You may
861# need to enable more algorithms here, typically hash algorithms when
862# accelerating some signature algorithms (ECDSA, RSAv2). This is done
863# by passing a 2nd argument listing the extra algorithms.
864# Example:
865# loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
866# helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
867# 4b. Call helper_libtestdriver1_make_main "$loc_accel_list". Any
868# additional arguments will be passed to make: this can be useful if
869# you don't want to build everything when iterating during development.
870# Example:
871# helper_libtestdriver1_make_main "$loc_accel_list" -C tests test_suite_foo
872# 4. Run the tests you want.
Manuel Pégourié-Gonnardf5c5d972023-06-06 11:14:57 +0200873
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200874# Adjust the configuration - for both libtestdriver1 and main library,
875# as they should have the same PSA_WANT macros.
876helper_libtestdriver1_adjust_config() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200877 base_config=$1
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200878 # Select the base configuration
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200879 if [ "$base_config" != "default" ]; then
880 scripts/config.py "$base_config"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200881 fi
882
883 # Enable PSA-based config (necessary to use drivers)
884 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
885
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200886 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
887 # partial support for cipher operations in the driver test library.
Ronald Cron6b49b552023-07-20 09:57:54 +0200888 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_STREAM_CIPHER
889 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
Manuel Pégourié-Gonnard2336c8e2023-06-12 17:17:54 +0200890
891 # Dynamic secure element support is a deprecated feature and needs to be disabled here.
892 # This is done to have the same form of psa_key_attributes_s for libdriver and library.
893 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200894}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100895
Valerio Settib2fd6732023-08-15 17:10:47 +0200896# When called with no parameter this function disables all builtin curves.
Valerio Setti4ca250b2023-09-04 14:01:41 +0200897# The function optionally accepts 1 parameter: a space-separated list of the
898# curves that should be kept enabled.
Valerio Settib2fd6732023-08-15 17:10:47 +0200899helper_disable_builtin_curves() {
900 allowed_list="${1:-}"
901 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
902
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200903 for curve in $allowed_list; do
904 scripts/config.py set $curve
Valerio Settib2fd6732023-08-15 17:10:47 +0200905 done
906}
907
908# Helper returning the list of supported elliptic curves from CRYPTO_CONFIG_H,
909# without the "PSA_WANT_" prefix. This becomes handy for accelerating curves
910# in the following helpers.
911helper_get_psa_curve_list () {
912 loc_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200913 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
914 loc_list="$loc_list $item"
Valerio Settib2fd6732023-08-15 17:10:47 +0200915 done
916
917 echo "$loc_list"
918}
919
920# Get the list of uncommented PSA_WANT_KEY_TYPE_xxx_ from CRYPTO_CONFIG_H. This
Valerio Setti0a342c92023-09-01 09:12:31 +0200921# is useful to easily get a list of key type symbols to accelerate.
Valerio Settib2fd6732023-08-15 17:10:47 +0200922# The function accepts a single argument which is the key type: ECC, DH, RSA.
Valerio Setti0a342c92023-09-01 09:12:31 +0200923helper_get_psa_key_type_list() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200924 key_type="$1"
Valerio Settib2fd6732023-08-15 17:10:47 +0200925 loc_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200926 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 +0200927 # Skip DERIVE for elliptic keys since there is no driver dispatch for
928 # it so it cannot be accelerated.
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200929 if [ "$item" != "KEY_TYPE_ECC_KEY_PAIR_DERIVE" ]; then
930 loc_list="$loc_list $item"
Valerio Settib2fd6732023-08-15 17:10:47 +0200931 fi
932 done
933
934 echo "$loc_list"
935}
936
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +0200937# Build the drivers library libtestdriver1.a (with ASan).
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +0200938#
939# Parameters:
940# 1. a space-separated list of things to accelerate;
941# 2. optional: a space-separate list of things to also support.
942# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
943helper_libtestdriver1_make_drivers() {
944 loc_accel_flags=$( echo "$1 ${2-}" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
945 make -C tests libtestdriver1.a CFLAGS=" $ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
946}
947
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +0200948# Build the main libraries, programs and tests,
949# linking to the drivers library (with ASan).
950#
951# Parameters:
952# 1. a space-separated list of things to accelerate;
953# *. remaining arguments if any are passed directly to make
954# (examples: lib, -C tests test_suite_xxx, etc.)
955# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
956helper_libtestdriver1_make_main() {
957 loc_accel_list=$1
958 shift
959
960 # we need flags both with and without the LIBTESTDRIVER1_ prefix
961 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
962 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
963 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" "$@"
964}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100965
966################################################################
967#### Basic checks
968################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100969
970#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200971# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100972#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100973# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200974# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100975# 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 +0200976# time, so start with a GCC build).
977# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100978#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100979# Indicative running times are given for reference.
980
Gilles Peskine8f073122018-11-27 15:58:47 +0100981component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200982 msg "Check: recursion.pl" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200983 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100984}
Janos Follathb72c6782016-07-19 14:54:17 +0100985
Gilles Peskine67debb62021-05-18 16:09:50 +0200986component_check_generated_files () {
987 msg "Check: check-generated-files, files generated with make" # 2s
988 make generated_files
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200989 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200990
991 msg "Check: check-generated-files -u, files present" # 2s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200992 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +0200993 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200994 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200995
996 msg "Check: check-generated-files -u, files absent" # 2s
997 command make neat
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200998 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +0200999 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001000 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +02001001
1002 # This component ends with the generated files present in the source tree.
1003 # This is necessary for subsequent components!
1004}
1005
Gilles Peskine8f073122018-11-27 15:58:47 +01001006component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001007 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001008 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001009}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001010
Gilles Peskine8f073122018-11-27 15:58:47 +01001011component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001012 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001013 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +01001014}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001015
Gilles Peskine30e0bb42020-05-10 17:40:49 +02001016component_check_changelog () {
1017 msg "Check: changelog entries" # < 1s
1018 rm -f ChangeLog.new
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001019 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +02001020 if [ -e ChangeLog.new ]; then
1021 # Show the diff for information. It isn't an error if the diff is
1022 # non-empty.
1023 diff -u ChangeLog ChangeLog.new || true
1024 rm ChangeLog.new
1025 fi
1026}
1027
Gilles Peskine8f073122018-11-27 15:58:47 +01001028component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001029 msg "Check: declared and exported names (builds the library)" # < 3s
Yuto Takanoc3a6f632021-09-24 18:02:56 +01001030 tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +01001031}
Darryl Greena07039c2018-03-13 16:48:16 +00001032
Gilles Peskine895868b2019-09-19 21:30:05 +02001033component_check_test_cases () {
1034 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001035 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001036 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001037 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001038 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001039 fi
Gilles Peskine031114d2022-12-15 14:46:31 +01001040 tests/scripts/check_test_cases.py -q $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001041 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +02001042}
1043
Gilles Peskine8f073122018-11-27 15:58:47 +01001044component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001045 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001046 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001047}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001048
Gilles Peskine192c72f2017-12-21 15:59:21 +01001049
Gilles Peskine636c26a2020-03-04 20:46:15 +01001050
Gilles Peskine192c72f2017-12-21 15:59:21 +01001051################################################################
1052#### Build and test many configurations and targets
1053################################################################
1054
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001055component_test_default_out_of_box () {
1056 msg "build: make, default config (out-of-box)" # ~1min
1057 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02001058 # Disable fancy stuff
1059 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001060
1061 msg "test: main suites make, default config (out-of-box)" # ~10s
1062 make test
1063
1064 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001065 programs/test/selftest
Gilles Peskine82b27272019-06-14 18:27:03 +02001066
1067 msg "program demos: make, default config (out-of-box)" # ~10s
1068 tests/scripts/run_demos.py
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001069}
1070
Gilles Peskine8f073122018-11-27 15:58:47 +01001071component_test_default_cmake_gcc_asan () {
1072 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +01001073 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1074 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001075
Gilles Peskine8f073122018-11-27 15:58:47 +01001076 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
1077 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001078
Gilles Peskine82b27272019-06-14 18:27:03 +02001079 msg "program demos (ASan build)" # ~10s
1080 tests/scripts/run_demos.py
1081
Gilles Peskine97bea012020-04-23 23:37:45 +02001082 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001083 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +02001084
Gilles Peskine8f073122018-11-27 15:58:47 +01001085 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001086 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001087
Gilles Peskine8f073122018-11-27 15:58:47 +01001088 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001089 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001090
1091 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001092 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001093}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001094
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001095component_test_default_cmake_gcc_asan_new_bignum () {
1096 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Janos Follath2f045822023-07-31 10:57:16 +01001097 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001098 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Janos Follath82823b22023-07-27 12:25:05 +01001099 make
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001100
1101 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
1102 make test
1103
1104 msg "test: selftest (ASan build)" # ~ 10s
1105 programs/test/selftest
1106
1107 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
1108 tests/ssl-opt.sh
1109
1110 msg "test: compat.sh (ASan build)" # ~ 6 min
1111 tests/compat.sh
1112
1113 msg "test: context-info.sh (ASan build)" # ~ 15 sec
1114 tests/context-info.sh
1115}
1116
Hanno Becker01635512019-02-26 14:27:09 +00001117component_test_full_cmake_gcc_asan () {
1118 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001119 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +00001120 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1121 make
1122
1123 msg "test: main suites (inc. selftests) (full config, ASan build)"
1124 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01001125
Gilles Peskine97bea012020-04-23 23:37:45 +02001126 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001127 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +02001128
Gilles Peskine636c26a2020-03-04 20:46:15 +01001129 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001130 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001131
1132 msg "test: compat.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001133 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001134
1135 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001136 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001137}
1138
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001139
1140component_test_full_cmake_gcc_asan_new_bignum () {
1141 msg "build: full config, cmake, gcc, ASan"
1142 scripts/config.py full
Janos Follath2f045822023-07-31 10:57:16 +01001143 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001144 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Janos Follath82823b22023-07-27 12:25:05 +01001145 make
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001146
1147 msg "test: main suites (inc. selftests) (full config, ASan build)"
1148 make test
1149
1150 msg "test: selftest (ASan build)" # ~ 10s
1151 programs/test/selftest
1152
1153 msg "test: ssl-opt.sh (full config, ASan build)"
1154 tests/ssl-opt.sh
1155
1156 msg "test: compat.sh (full config, ASan build)"
1157 tests/compat.sh
1158
1159 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
1160 tests/context-info.sh
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001161}
1162
Ronald Cronc3623db2020-10-29 10:51:32 +01001163component_test_psa_crypto_key_id_encodes_owner () {
Andrzej Kurek03e01462022-01-03 12:53:24 +01001164 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
Ronald Cronc3623db2020-10-29 10:51:32 +01001165 scripts/config.py full
Ronald Cronc3623db2020-10-29 10:51:32 +01001166 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1167 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1168 make
1169
1170 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
1171 make test
1172}
1173
Gilles Peskinea3548672021-06-17 11:37:52 +02001174# check_renamed_symbols HEADER LIB
1175# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
1176# name is LIB.
1177check_renamed_symbols () {
1178 ! nm "$2" | sed 's/.* //' |
1179 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
1180}
1181
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001182component_build_psa_crypto_spm () {
Andrzej Kurek03e01462022-01-03 12:53:24 +01001183 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001184 scripts/config.py full
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001185 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
1186 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1187 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
1188 # We can only compile, not link, since our test and sample programs
1189 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
1190 # is active.
1191 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskinea3548672021-06-17 11:37:52 +02001192
1193 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
1194 # version is not present.
1195 echo "Checking for renamed symbols in the library"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001196 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001197}
1198
Ronald Cron336678b2021-01-28 17:54:24 +01001199component_test_psa_crypto_client () {
1200 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
1201 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1202 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1203 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
Raef Colesb4568c52022-09-28 17:11:42 +01001204 scripts/config.py unset MBEDTLS_LMS_C
1205 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Ronald Cron336678b2021-01-28 17:54:24 +01001206 make
1207
1208 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
1209 make test
1210}
1211
Jaeden Amero424fa932021-05-14 08:34:32 +01001212component_test_psa_crypto_rsa_no_genprime() {
1213 msg "build: default config minus MBEDTLS_GENPRIME"
1214 scripts/config.py unset MBEDTLS_GENPRIME
1215 make
1216
1217 msg "test: default config minus MBEDTLS_GENPRIME"
1218 make test
1219}
1220
Gilles Peskine782f4112018-11-27 16:11:09 +01001221component_test_ref_configs () {
1222 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Manuel Pégourié-Gonnard9327fb32021-09-09 11:46:25 +02001223 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
1224 # want to re-generate generated files that depend on it, quite correctly.
1225 # However this doesn't work as the generation script expects a specific
1226 # format for mbedtls_config.h, which the other files don't follow. Also,
1227 # cmake can't know this, but re-generation is actually not necessary as
David Horstmannd64f4b22021-10-20 12:29:47 +01001228 # the generated files only depend on the list of available options, not
Manuel Pégourié-Gonnard9327fb32021-09-09 11:46:25 +02001229 # whether they're on or off. So, disable cmake's (over-sensitive here)
1230 # dependency resolution for generated files and just rely on them being
David Horstmanna8d14062021-10-20 17:14:23 +01001231 # present (thanks to pre_generate_files) by turning GEN_FILES off.
1232 CC=gcc cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001233 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +01001234}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001235
Gilles Peskine8f073122018-11-27 15:58:47 +01001236component_test_no_renegotiation () {
1237 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001238 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001239 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1240 make
Simon Butcher3ea7f522016-03-07 23:22:10 +00001241
Gilles Peskine8f073122018-11-27 15:58:47 +01001242 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1243 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +01001244
Gilles Peskine8f073122018-11-27 15:58:47 +01001245 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001246 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001247}
Hanno Becker134c2ab2017-10-12 15:29:50 +01001248
Gilles Peskine636c26a2020-03-04 20:46:15 +01001249component_test_no_pem_no_fs () {
1250 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1251 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1252 scripts/config.py unset MBEDTLS_FS_IO
1253 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1254 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
1255 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1256 make
1257
1258 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1259 make test
1260
1261 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001262 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001263}
1264
Gilles Peskine8f073122018-11-27 15:58:47 +01001265component_test_rsa_no_crt () {
1266 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001267 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +01001268 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1269 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +01001270
Gilles Peskine8f073122018-11-27 15:58:47 +01001271 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1272 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001273
Gilles Peskine8f073122018-11-27 15:58:47 +01001274 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001275 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001276
Gilles Peskine8f073122018-11-27 15:58:47 +01001277 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001278 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001279
1280 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001281 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001282}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001283
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001284component_test_no_ctr_drbg_classic () {
1285 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001286 scripts/config.py full
1287 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001288 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001289 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001290
1291 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1292 make
1293
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001294 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001295 make test
1296
Gilles Peskineba749042021-01-13 20:02:03 +01001297 # In this configuration, the TLS test programs use HMAC_DRBG.
1298 # The SSL tests are slow, so run a small subset, just enough to get
1299 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001300 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001301 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001302
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001303 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001304 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001305}
1306
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001307component_test_no_ctr_drbg_use_psa () {
1308 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001309 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001310 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1311 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001312
1313 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1314 make
1315
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001316 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1317 make test
1318
1319 # In this configuration, the TLS test programs use HMAC_DRBG.
1320 # The SSL tests are slow, so run a small subset, just enough to get
1321 # confidence that the SSL code copes with HMAC_DRBG.
1322 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001323 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001324
1325 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001326 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001327}
1328
1329component_test_no_hmac_drbg_classic () {
1330 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1331 scripts/config.py full
1332 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1333 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1334 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001335 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001336
1337 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1338 make
1339
1340 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001341 make test
1342
Gilles Peskinea2224342020-11-19 22:14:34 +01001343 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1344 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1345 # instead.
1346 # Test SSL with non-deterministic ECDSA. Only test features that
1347 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001348 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001349 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001350
1351 # To save time, only test one protocol version, since this part of
1352 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001353 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001354 tests/compat.sh -m tls12 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001355}
1356
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001357component_test_no_hmac_drbg_use_psa () {
1358 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1359 scripts/config.py full
1360 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1361 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1362 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1363
1364 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1365 make
1366
1367 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1368 make test
1369
1370 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1371 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1372 # instead.
1373 # Test SSL with non-deterministic ECDSA. Only test features that
1374 # might be affected by how ECDSA signature is performed.
1375 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001376 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001377
1378 # To save time, only test one protocol version, since this part of
1379 # the protocol is identical in (D)TLS up to 1.2.
1380 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001381 tests/compat.sh -m tls12 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001382}
1383
1384component_test_psa_external_rng_no_drbg_classic () {
1385 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1386 scripts/config.py full
1387 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001388 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001389 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001390 scripts/config.py unset MBEDTLS_ENTROPY_C
1391 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1392 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001393 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1394 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1395 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001396 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1397 # the SSL test programs don't have an RNG and can't work. Explicitly
1398 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1399 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001400
1401 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1402 make test
1403
Gilles Peskine8eb29432021-02-03 20:07:11 +01001404 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001405 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001406}
1407
1408component_test_psa_external_rng_no_drbg_use_psa () {
1409 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001410 scripts/config.py full
1411 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001412 scripts/config.py unset MBEDTLS_ENTROPY_C
1413 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1414 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001415 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1416 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1417 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskinec109b372020-11-23 17:39:04 +01001418 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1419
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001420 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001421 make test
1422
Gilles Peskine8eb29432021-02-03 20:07:11 +01001423 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001424 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001425}
1426
Gilles Peskine4bdb2542023-04-28 19:25:25 +02001427component_test_psa_external_rng_use_psa_crypto () {
1428 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1429 scripts/config.py full
1430 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1431 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1432 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1433 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1434
1435 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1436 make test
1437
1438 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1439 tests/ssl-opt.sh -f 'Default\|opaque'
1440}
1441
Gilles Peskine801c4332023-04-28 21:04:28 +02001442component_test_psa_inject_entropy () {
1443 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
1444 scripts/config.py full
1445 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
1446 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
1447 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1448 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1449 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
1450 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
1451 make CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
1452
1453 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
1454 make test
1455}
1456
Andrzej Kurek06969fc2023-04-12 10:34:50 -04001457component_test_sw_inet_pton () {
1458 msg "build: default plus MBEDTLS_TEST_SW_INET_PTON"
1459
1460 # MBEDTLS_TEST_HOOKS required for x509_crt_parse_cn_inet_pton
1461 scripts/config.py set MBEDTLS_TEST_HOOKS
1462 make CFLAGS="-DMBEDTLS_TEST_SW_INET_PTON"
1463
1464 msg "test: default plus MBEDTLS_TEST_SW_INET_PTON"
1465 make test
1466}
1467
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001468component_test_crypto_full_md_light_only () {
1469 msg "build: crypto_full with only the light subset of MD"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001470 scripts/config.py crypto_full
Gilles Peskine884b4622023-07-20 20:11:51 +02001471 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001472 # Disable MD
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001473 scripts/config.py unset MBEDTLS_MD_C
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001474 # Disable direct dependencies of MD_C
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001475 scripts/config.py unset MBEDTLS_HKDF_C
1476 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
Nick Child89e82e12022-11-09 10:36:10 -06001477 scripts/config.py unset MBEDTLS_PKCS7_C
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001478 # Disable indirect dependencies of MD_C
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001479 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001480 # Disable things that would auto-enable MD_C
1481 scripts/config.py unset MBEDTLS_PKCS5_C
1482
Manuel Pégourié-Gonnard1b5ffc62023-03-14 10:11:20 +01001483 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
1484 # which we haven't disabled, so no need to explicitly enable it.
1485 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001486
Manuel Pégourié-Gonnard0d415212023-02-23 13:02:13 +01001487 # Make sure we don't have the HMAC functions, but the hashing functions
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001488 not grep mbedtls_md_hmac library/md.o
Manuel Pégourié-Gonnard0d415212023-02-23 13:02:13 +01001489 grep mbedtls_md library/md.o
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001490
1491 msg "test: crypto_full with only the light subset of MD"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001492 make test
1493}
1494
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001495component_test_full_no_cipher () {
1496 msg "build: full minus CIPHER"
1497 scripts/config.py full
1498 scripts/config.py unset MBEDTLS_CIPHER_C
Gilles Peskine9b8dead2023-08-09 19:48:42 +02001499 # Don't pull in cipher via PSA mechanisms
1500 # (currently ignored anyway because we completely disable PSA)
1501 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Przemek Stekielda5f4832022-05-12 09:46:29 +02001502 # Direct dependencies
1503 scripts/config.py unset MBEDTLS_CCM_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001504 scripts/config.py unset MBEDTLS_CMAC_C
Przemek Stekielda5f4832022-05-12 09:46:29 +02001505 scripts/config.py unset MBEDTLS_GCM_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001506 scripts/config.py unset MBEDTLS_NIST_KW_C
1507 scripts/config.py unset MBEDTLS_PKCS12_C
1508 scripts/config.py unset MBEDTLS_PKCS5_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001509 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1510 scripts/config.py unset MBEDTLS_SSL_TLS_C
1511 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielda5f4832022-05-12 09:46:29 +02001512 # Indirect dependencies
1513 scripts/config.py unset MBEDTLS_SSL_CLI_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001514 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
1515 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001516 scripts/config.py unset MBEDTLS_SSL_DTLS_ANTI_REPLAY
1517 scripts/config.py unset MBEDTLS_SSL_DTLS_CONNECTION_ID
Dave Rodgman1df70702022-10-26 17:08:54 +01001518 scripts/config.py unset MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT
Przemek Stekielda5f4832022-05-12 09:46:29 +02001519 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1520 scripts/config.py unset MBEDTLS_SSL_SRV_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001521 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Raef Colesa7e03ad2022-09-28 09:32:48 +01001522 scripts/config.py unset MBEDTLS_LMS_C
Raef Coles47bccb72022-09-28 12:00:20 +01001523 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001524 make
1525
1526 msg "test: full minus CIPHER"
1527 make test
1528}
1529
Valerio Settie1655b82023-01-03 15:35:25 +01001530component_test_full_no_bignum () {
1531 msg "build: full minus bignum"
1532 scripts/config.py full
1533 scripts/config.py unset MBEDTLS_BIGNUM_C
1534 # Direct dependencies of bignum
1535 scripts/config.py unset MBEDTLS_ECP_C
1536 scripts/config.py unset MBEDTLS_RSA_C
1537 scripts/config.py unset MBEDTLS_DHM_C
1538 # Direct dependencies of ECP
1539 scripts/config.py unset MBEDTLS_ECDH_C
1540 scripts/config.py unset MBEDTLS_ECDSA_C
1541 scripts/config.py unset MBEDTLS_ECJPAKE_C
1542 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Setti22d0a792023-06-14 17:23:19 +02001543 # Disable what auto-enables ECP_LIGHT
1544 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1545 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
Valerio Settie1655b82023-01-03 15:35:25 +01001546 # Indirect dependencies of ECP
1547 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1548 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1549 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1550 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1551 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1552 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
1553 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
1554 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
1555 # Direct dependencies of DHM
1556 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1557 # Direct dependencies of RSA
1558 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1559 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1560 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1561 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1562 # PK and its dependencies
1563 scripts/config.py unset MBEDTLS_PK_C
1564 scripts/config.py unset MBEDTLS_PK_PARSE_C
1565 scripts/config.py unset MBEDTLS_PK_WRITE_C
1566 scripts/config.py unset MBEDTLS_X509_USE_C
1567 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
1568 scripts/config.py unset MBEDTLS_X509_CRL_PARSE_C
1569 scripts/config.py unset MBEDTLS_X509_CSR_PARSE_C
1570 scripts/config.py unset MBEDTLS_X509_CREATE_C
1571 scripts/config.py unset MBEDTLS_X509_CRT_WRITE_C
1572 scripts/config.py unset MBEDTLS_X509_CSR_WRITE_C
1573 scripts/config.py unset MBEDTLS_PKCS7_C
1574 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
1575 scripts/config.py unset MBEDTLS_SSL_ASYNC_PRIVATE
1576 scripts/config.py unset MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
1577
1578 make
1579
1580 msg "test: full minus bignum"
1581 make test
1582}
1583
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001584component_test_tls1_2_default_stream_cipher_only () {
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001585 msg "build: default with only stream cipher"
1586
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001587 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001588 scripts/config.py unset MBEDTLS_GCM_C
1589 scripts/config.py unset MBEDTLS_CCM_C
1590 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001591 # 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 +02001592 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001593 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001594 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001595 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1596 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001597 # Modules that depend on AEAD
Przemek Stekield582a012022-09-28 07:59:01 +02001598 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001599 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001600
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001601 make
1602
1603 msg "test: default with only stream cipher"
1604 make test
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001605
1606 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001607}
1608
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001609component_test_tls1_2_default_stream_cipher_only_use_psa () {
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001610 msg "build: default with only stream cipher use psa"
Przemek Stekiel9550c052022-09-28 09:51:55 +02001611
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001612 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001613 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel9550c052022-09-28 09:51:55 +02001614 scripts/config.py unset MBEDTLS_GCM_C
1615 scripts/config.py unset MBEDTLS_CCM_C
1616 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001617 # 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 +02001618 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001619 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekiel9550c052022-09-28 09:51:55 +02001620 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001621 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1622 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001623 # Modules that depend on AEAD
Przemek Stekiel9550c052022-09-28 09:51:55 +02001624 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001625 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel9550c052022-09-28 09:51:55 +02001626
Przemek Stekiel9550c052022-09-28 09:51:55 +02001627 make
1628
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001629 msg "test: default with only stream cipher use psa"
Przemek Stekiel9550c052022-09-28 09:51:55 +02001630 make test
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001631
1632 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
Przemek Stekiel9550c052022-09-28 09:51:55 +02001633}
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001634
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001635component_test_tls1_2_default_cbc_legacy_cipher_only () {
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001636 msg "build: default with only CBC-legacy cipher"
1637
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001638 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001639 scripts/config.py unset MBEDTLS_GCM_C
1640 scripts/config.py unset MBEDTLS_CCM_C
1641 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001642 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1643 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1644 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001645 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001646 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001647 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001648 # Modules that depend on AEAD
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001649 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001650 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001651
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001652 make
1653
1654 msg "test: default with only CBC-legacy cipher"
1655 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001656
1657 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1658 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001659}
1660
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001661component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001662 msg "build: default with only CBC-legacy cipher use psa"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001663
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001664 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001665 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001666 scripts/config.py unset MBEDTLS_GCM_C
1667 scripts/config.py unset MBEDTLS_CCM_C
1668 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001669 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1670 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1671 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001672 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001673 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001674 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001675 # Modules that depend on AEAD
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001676 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001677 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001678
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001679 make
1680
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001681 msg "test: default with only CBC-legacy cipher use psa"
1682 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001683
1684 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1685 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001686}
1687
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001688component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001689 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1690
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001691 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001692 scripts/config.py unset MBEDTLS_GCM_C
1693 scripts/config.py unset MBEDTLS_CCM_C
1694 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001695 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1696 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1697 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1698 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1699 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001700 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001701 # Modules that depend on AEAD
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001702 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001703 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001704
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001705 make
1706
1707 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1708 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001709
1710 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1711 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001712}
1713
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001714component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
1715 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001716
1717 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001718 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001719 scripts/config.py unset MBEDTLS_GCM_C
1720 scripts/config.py unset MBEDTLS_CCM_C
1721 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001722 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1723 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1724 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1725 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1726 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001727 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001728 # Modules that depend on AEAD
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001729 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001730 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001731
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001732 make
1733
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001734 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001735 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001736
1737 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
1738 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001739}
1740
Valerio Setti9f0ec532022-11-08 13:03:24 +01001741# We're not aware of any other (open source) implementation of EC J-PAKE in TLS
1742# that we could use for interop testing. However, we now have sort of two
1743# implementations ourselves: one using PSA, the other not. At least test that
1744# these two interoperate with each other.
1745component_test_tls1_2_ecjpake_compatibility() {
1746 msg "build: TLS1.2 server+client w/ EC-JPAKE w/o USE_PSA"
1747 scripts/config.py set MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
Gilles Peskineedc84562023-09-20 15:03:18 +02001748 # Explicitly make lib first to avoid a race condition:
1749 # https://github.com/Mbed-TLS/mbedtls/issues/8229
1750 make lib
Valerio Setti9f0ec532022-11-08 13:03:24 +01001751 make -C programs ssl/ssl_server2 ssl/ssl_client2
1752 cp programs/ssl/ssl_server2 s2_no_use_psa
1753 cp programs/ssl/ssl_client2 c2_no_use_psa
1754
1755 msg "build: TLS1.2 server+client w/ EC-JPAKE w/ USE_PSA"
1756 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1757 make clean
Gilles Peskineedc84562023-09-20 15:03:18 +02001758 make lib
Valerio Setti9f0ec532022-11-08 13:03:24 +01001759 make -C programs ssl/ssl_server2 ssl/ssl_client2
1760 make -C programs test/udp_proxy test/query_compile_time_config
1761
Valerio Setti70e02902022-12-02 16:21:56 +01001762 msg "test: server w/o USE_PSA - client w/ USE_PSA, text password"
1763 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
1764 msg "test: server w/o USE_PSA - client w/ USE_PSA, opaque password"
1765 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password client only, working, TLS"
1766 msg "test: client w/o USE_PSA - server w/ USE_PSA, text password"
1767 P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
1768 msg "test: client w/o USE_PSA - server w/ USE_PSA, opaque password"
1769 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 +01001770
1771 rm s2_no_use_psa c2_no_use_psa
1772}
1773
Gilles Peskine636c26a2020-03-04 20:46:15 +01001774component_test_everest () {
1775 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine636c26a2020-03-04 20:46:15 +01001776 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1777 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1778 make
1779
1780 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1781 make test
1782
1783 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001784 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001785
1786 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1787 # Exclude some symmetric ciphers that are redundant here to gain time.
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02001788 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001789}
1790
Gilles Peskined3beca92020-07-03 00:15:37 +02001791component_test_everest_curve25519_only () {
1792 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
Gilles Peskined3beca92020-07-03 00:15:37 +02001793 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1794 scripts/config.py unset MBEDTLS_ECDSA_C
1795 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1796 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
TRodziewicz7c1d41d2021-04-23 13:33:44 +02001797 scripts/config.py unset MBEDTLS_ECJPAKE_C
Gilles Peskined3beca92020-07-03 00:15:37 +02001798 # Disable all curves
Valerio Setti2e0275d2023-07-28 16:33:13 +02001799 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
Gilles Peskined3beca92020-07-03 00:15:37 +02001800 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1801
1802 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1803
1804 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1805 make test
1806}
1807
Gilles Peskine8f073122018-11-27 15:58:47 +01001808component_test_small_ssl_out_content_len () {
1809 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001810 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1811 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001812 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1813 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001814
Gilles Peskine8f073122018-11-27 15:58:47 +01001815 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001816 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001817}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001818
Gilles Peskine8f073122018-11-27 15:58:47 +01001819component_test_small_ssl_in_content_len () {
1820 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001821 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1822 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001823 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1824 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001825
Gilles Peskine8f073122018-11-27 15:58:47 +01001826 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001827 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001828}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001829
Gilles Peskine8f073122018-11-27 15:58:47 +01001830component_test_small_ssl_dtls_max_buffering () {
1831 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001832 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001833 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1834 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001835
Gilles Peskine8f073122018-11-27 15:58:47 +01001836 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001837 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 +01001838}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001839
Gilles Peskine8f073122018-11-27 15:58:47 +01001840component_test_small_mbedtls_ssl_dtls_max_buffering () {
1841 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001842 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001843 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1844 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001845
Gilles Peskine8f073122018-11-27 15:58:47 +01001846 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001847 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001848}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001849
Gilles Peskine75cc7712019-09-06 19:47:17 +02001850component_test_psa_collect_statuses () {
1851 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001852 scripts/config.py full
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001853 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001854 # Check that psa_crypto_init() succeeded at least once
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001855 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001856 rm -f tests/statuses.log
1857}
1858
Gilles Peskine8f073122018-11-27 15:58:47 +01001859component_test_full_cmake_clang () {
1860 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001861 scripts/config.py full
Gilles Peskineda6017c2022-10-30 21:02:40 +01001862 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 +01001863 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001864
k-stachowiak0291cb72019-06-26 15:52:12 +02001865 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001866 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001867
Gilles Peskineda6017c2022-10-30 21:02:40 +01001868 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
1869 programs/test/cpp_dummy_build
1870
Gilles Peskine82b27272019-06-14 18:27:03 +02001871 msg "program demos (full config, clang)" # ~10s
1872 tests/scripts/run_demos.py
1873
k-stachowiak0291cb72019-06-26 15:52:12 +02001874 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001875 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001876
Gilles Peskine8f073122018-11-27 15:58:47 +01001877 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001878 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001879
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02001880 msg "test: compat.sh NULL (full config)" # ~ 2 min
Gilles Peskinee29203b2023-08-27 21:43:00 +02001881 tests/compat.sh -e '^$' -f 'NULL'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001882
Gilles Peskine8f073122018-11-27 15:58:47 +01001883 msg "test: compat.sh ARIA + ChachaPoly"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01001884 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001885}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001886
Gilles Peskine0c671602022-11-29 16:01:41 +01001887skip_suites_without_constant_flow () {
1888 # Skip the test suites that don't have any constant-flow annotations.
1889 # This will need to be adjusted if we ever start declaring things as
1890 # secret from macros or functions inside tests/include or tests/src.
1891 SKIP_TEST_SUITES=$(
1892 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
1893 sed 's/test_suite_//; s/\.function$//' |
1894 tr '\n' ,)
1895 export SKIP_TEST_SUITES
1896}
1897
Dave Rodgman246210e2023-07-31 18:07:44 +01001898skip_all_except_given_suite () {
1899 # Skip all but the given test suite
1900 SKIP_TEST_SUITES=$(
1901 ls -1 tests/suites/test_suite_*.function |
1902 grep -v $1.function |
1903 sed 's/tests.suites.test_suite_//; s/\.function$//' |
1904 tr '\n' ,)
1905 export SKIP_TEST_SUITES
1906}
1907
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001908component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001909 # This tests both (1) accesses to undefined memory, and (2) branches or
1910 # memory access depending on secret values. To distinguish between those:
1911 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1912 # - or alternatively, change the build type to MemSanDbg, which enables
1913 # origin tracking and nicer stack traces (which are useful for debugging
1914 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001915 msg "build: cmake MSan (clang), full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
1916 scripts/config.py full
1917 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1918 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1919 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1920 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1921 make
1922
1923 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO, Msan + constant flow)"
1924 make test
1925}
1926
1927component_test_memsan_constant_flow_psa () {
1928 # This tests both (1) accesses to undefined memory, and (2) branches or
1929 # memory access depending on secret values. To distinguish between those:
1930 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1931 # - or alternatively, change the build type to MemSanDbg, which enables
1932 # origin tracking and nicer stack traces (which are useful for debugging
1933 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001934 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001935 scripts/config.py full
1936 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1937 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1938 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1939 make
1940
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001941 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001942 make test
1943}
1944
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001945component_test_valgrind_constant_flow () {
1946 # This tests both (1) everything that valgrind's memcheck usually checks
1947 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1948 # etc.) and (2) branches or memory access depending on secret values,
1949 # which will be reported as uninitialized memory. To distinguish between
1950 # secret and actually uninitialized:
1951 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1952 # - or alternatively, build with debug info and manually run the offending
1953 # test suite with valgrind --track-origins=yes, then check if the origin
1954 # was TEST_CF_SECRET() or something else.
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001955 msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
1956 scripts/config.py full
1957 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
1958 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine0c671602022-11-29 16:01:41 +01001959 skip_suites_without_constant_flow
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001960 cmake -D CMAKE_BUILD_TYPE:String=Release .
1961 make
1962
1963 # this only shows a summary of the results (how many of each type)
1964 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine0c671602022-11-29 16:01:41 +01001965 msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, valgrind + constant flow)"
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001966 make memcheck
Dave Rodgman246210e2023-07-31 18:07:44 +01001967
1968 # Test asm path in constant time module - by default, it will test the plain C
1969 # path under Valgrind or Memsan. Running only the constant_time tests is fast (<1s)
1970 msg "test: valgrind asm constant_time"
1971 scripts/config.py --force set MBEDTLS_TEST_CONSTANT_FLOW_ASM
1972 skip_all_except_given_suite test_suite_constant_time
1973 cmake -D CMAKE_BUILD_TYPE:String=Release .
1974 make clean
1975 make
1976 make memcheck
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001977}
1978
1979component_test_valgrind_constant_flow_psa () {
1980 # This tests both (1) everything that valgrind's memcheck usually checks
1981 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1982 # etc.) and (2) branches or memory access depending on secret values,
1983 # which will be reported as uninitialized memory. To distinguish between
1984 # secret and actually uninitialized:
1985 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1986 # - or alternatively, build with debug info and manually run the offending
1987 # test suite with valgrind --track-origins=yes, then check if the origin
1988 # was TEST_CF_SECRET() or something else.
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001989 msg "build: cmake release GCC, full config with constant flow testing"
1990 scripts/config.py full
1991 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Gilles Peskine0c671602022-11-29 16:01:41 +01001992 skip_suites_without_constant_flow
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001993 cmake -D CMAKE_BUILD_TYPE:String=Release .
1994 make
1995
1996 # this only shows a summary of the results (how many of each type)
1997 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine0c671602022-11-29 16:01:41 +01001998 msg "test: some suites (valgrind + constant flow)"
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001999 make memcheck
2000}
2001
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002002component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02002003 # Test that removing the deprecated features from the default
2004 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002005 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
2006 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
2007 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
2008
2009 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
2010 make test
2011}
2012
2013component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02002014 msg "build: make, full_no_deprecated config" # ~ 30s
2015 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002016 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
2017
Gilles Peskine30de2e82020-04-20 21:39:22 +02002018 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002019 make test
Valerio Setti41b5fb62023-01-09 12:20:45 +01002020
2021 msg "test: ensure that X509 has no direct dependency on BIGNUM_C"
2022 not grep mbedtls_mpi library/libmbedx509.a
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002023}
2024
Gilles Peskine8386ea22020-04-30 09:07:29 +02002025component_test_full_no_deprecated_deprecated_warning () {
2026 # Test that there is nothing deprecated in "full_no_deprecated".
2027 # A deprecated feature would trigger a warning (made fatal) from
2028 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02002029 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
2030 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002031 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
2032 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
2033 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
2034
Gilles Peskine30de2e82020-04-20 21:39:22 +02002035 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002036 make test
2037}
2038
Gilles Peskine8386ea22020-04-30 09:07:29 +02002039component_test_full_deprecated_warning () {
2040 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
2041 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002042 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002043 scripts/config.py full
2044 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002045 # Expect warnings from '#warning' directives in check_config.h.
2046 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01002047
Gilles Peskine8386ea22020-04-30 09:07:29 +02002048 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
2049 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
2050 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002051 # Expect warnings from '#warning' directives in check_config.h and
2052 # from the use of deprecated functions in test suites.
2053 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -Wno-error=cpp -DMBEDTLS_TEST_DEPRECATED' tests
Gilles Peskine841b14b2019-11-26 17:37:37 +01002054
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002055 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
2056 make test
Gilles Peskine82b27272019-06-14 18:27:03 +02002057
2058 msg "program demos: full config + MBEDTLS_TEST_DEPRECATED" # ~10s
2059 tests/scripts/run_demos.py
Gilles Peskine8f073122018-11-27 15:58:47 +01002060}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00002061
Gilles Peskineec541fe2020-01-31 14:24:14 +01002062# Check that the specified libraries exist and are empty.
2063are_empty_libraries () {
2064 nm "$@" >/dev/null 2>/dev/null
2065 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
2066}
2067
2068component_build_crypto_default () {
2069 msg "build: make, crypto only"
2070 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01002071 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002072 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002073}
2074
2075component_build_crypto_full () {
2076 msg "build: make, crypto only, full config"
2077 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01002078 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002079 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002080}
2081
Gilles Peskinefc4f11b2022-10-21 19:34:54 +02002082component_test_crypto_for_psa_service () {
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002083 msg "build: make, config for PSA crypto service"
2084 scripts/config.py crypto
2085 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
2086 # Disable things that are not needed for just cryptography, to
2087 # reach a configuration that would be typical for a PSA cryptography
2088 # service providing all implemented PSA algorithms.
2089 # System stuff
2090 scripts/config.py unset MBEDTLS_ERROR_C
2091 scripts/config.py unset MBEDTLS_TIMING_C
Gilles Peskine78bffd12022-10-25 21:02:33 +02002092 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002093 # Crypto stuff with no PSA interface
2094 scripts/config.py unset MBEDTLS_BASE64_C
Gilles Peskine649e04e2022-10-25 21:05:57 +02002095 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
Gilles Peskineb06f0712022-10-25 21:06:11 +02002096 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
Gilles Peskine649e04e2022-10-25 21:05:57 +02002097 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002098 scripts/config.py unset MBEDTLS_NIST_KW_C
2099 scripts/config.py unset MBEDTLS_PEM_PARSE_C
2100 scripts/config.py unset MBEDTLS_PEM_WRITE_C
2101 scripts/config.py unset MBEDTLS_PKCS12_C
2102 scripts/config.py unset MBEDTLS_PKCS5_C
Gilles Peskinefcee7402022-10-11 21:15:24 +02002103 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
2104 # in PSA code to work with RSA keys. We don't require users to set those:
2105 # they will be reenabled in build_info.h.
Gilles Peskine1f108072022-10-25 21:02:56 +02002106 scripts/config.py unset MBEDTLS_PK_C
Gilles Peskinefcee7402022-10-11 21:15:24 +02002107 scripts/config.py unset MBEDTLS_PK_PARSE_C
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002108 scripts/config.py unset MBEDTLS_PK_WRITE_C
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002109 make CFLAGS='-O1 -Werror' all test
2110 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
2111}
2112
Gilles Peskineec541fe2020-01-31 14:24:14 +01002113component_build_crypto_baremetal () {
2114 msg "build: make, crypto only, baremetal config"
2115 scripts/config.py crypto_baremetal
David Horstmann61faf662021-11-30 11:40:54 +00002116 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002117 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002118}
Daniel Axtens446af202020-09-02 21:30:13 +10002119support_build_crypto_baremetal () {
Daniel Axtens814c8132020-08-31 14:22:58 +10002120 support_build_baremetal "$@"
2121}
2122
2123component_build_baremetal () {
2124 msg "build: make, baremetal config"
2125 scripts/config.py baremetal
David Horstmann61faf662021-11-30 11:40:54 +00002126 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Daniel Axtens814c8132020-08-31 14:22:58 +10002127}
2128support_build_baremetal () {
Daniel Axtens446af202020-09-02 21:30:13 +10002129 # Older Glibc versions include time.h from other headers such as stdlib.h,
2130 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
2131 # problem, Ubuntu 18.04 is ok.
2132 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
2133}
Gilles Peskineec541fe2020-01-31 14:24:14 +01002134
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002135# depends.py family of tests
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002136component_test_depends_py_cipher_id () {
2137 msg "test/build: depends.py cipher_id (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002138 tests/scripts/depends.py cipher_id --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002139}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00002140
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002141component_test_depends_py_cipher_chaining () {
2142 msg "test/build: depends.py cipher_chaining (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002143 tests/scripts/depends.py cipher_chaining --unset-use-psa
John Durkopc14be902020-08-20 06:16:41 -07002144}
2145
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002146component_test_depends_py_cipher_padding () {
2147 msg "test/build: depends.py cipher_padding (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002148 tests/scripts/depends.py cipher_padding --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002149}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00002150
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002151component_test_depends_py_curves () {
2152 msg "test/build: depends.py curves (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002153 tests/scripts/depends.py curves --unset-use-psa
John Durkop2ec2eaa2020-08-24 18:29:15 -07002154}
2155
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002156component_test_depends_py_hashes () {
2157 msg "test/build: depends.py hashes (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002158 tests/scripts/depends.py hashes --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002159}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002160
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002161component_test_depends_py_kex () {
2162 msg "test/build: depends.py kex (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002163 tests/scripts/depends.py kex --unset-use-psa
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002164}
2165
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002166component_test_depends_py_pkalgs () {
2167 msg "test/build: depends.py pkalgs (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002168 tests/scripts/depends.py pkalgs --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002169}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002170
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002171# PSA equivalents of the depends.py tests
2172component_test_depends_py_cipher_id_psa () {
2173 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2174 tests/scripts/depends.py cipher_id
2175}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002176
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002177component_test_depends_py_cipher_chaining_psa () {
2178 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2179 tests/scripts/depends.py cipher_chaining
2180}
2181
2182component_test_depends_py_cipher_padding_psa () {
2183 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2184 tests/scripts/depends.py cipher_padding
2185}
2186
2187component_test_depends_py_curves_psa () {
2188 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2189 tests/scripts/depends.py curves
2190}
2191
2192component_test_depends_py_hashes_psa () {
2193 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2194 tests/scripts/depends.py hashes
2195}
2196
2197component_test_depends_py_kex_psa () {
2198 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2199 tests/scripts/depends.py kex
2200}
2201
2202component_test_depends_py_pkalgs_psa () {
2203 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002204 tests/scripts/depends.py pkalgs
Gilles Peskine8f073122018-11-27 15:58:47 +01002205}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002206
Dave Rodgman1a034dc2023-01-20 13:18:05 +00002207component_build_no_pk_rsa_alt_support () {
2208 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
2209
2210 scripts/config.py full
2211 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
2212 scripts/config.py set MBEDTLS_RSA_C
2213 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
2214
2215 # Only compile - this is primarily to test for compile issues
2216 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
2217}
2218
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002219component_build_module_alt () {
2220 msg "build: MBEDTLS_XXX_ALT" # ~30s
2221 scripts/config.py full
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002222
2223 # Disable options that are incompatible with some ALT implementations:
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002224 # aesni.c and padlock.c reference mbedtls_aes_context fields directly.
2225 scripts/config.py unset MBEDTLS_AESNI_C
2226 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08002227 scripts/config.py unset MBEDTLS_AESCE_C
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002228 # MBEDTLS_ECP_RESTARTABLE is documented as incompatible.
2229 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002230 # You can only have one threading implementation: alt or pthread, not both.
2231 scripts/config.py unset MBEDTLS_THREADING_PTHREAD
Gilles Peskine5c3f18d2021-05-31 21:21:12 +02002232 # The SpecifiedECDomain parsing code accesses mbedtls_ecp_group fields
2233 # directly and assumes the implementation works with partial groups.
2234 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
Tom Cosgrovef3ebd902022-02-20 22:25:31 +00002235 # MBEDTLS_SHA256_*ALT can't be used with MBEDTLS_SHA256_USE_A64_CRYPTO_*
2236 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2237 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00002238 # MBEDTLS_SHA512_*ALT can't be used with MBEDTLS_SHA512_USE_A64_CRYPTO_*
2239 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2240 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002241
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002242 # Enable all MBEDTLS_XXX_ALT for whole modules. Do not enable
2243 # MBEDTLS_XXX_YYY_ALT which are for single functions.
2244 scripts/config.py set-all 'MBEDTLS_([A-Z0-9]*|NIST_KW)_ALT'
Gilles Peskine1628a9c2021-05-31 22:09:58 +02002245 scripts/config.py unset MBEDTLS_DHM_ALT #incompatible with MBEDTLS_DEBUG_C
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002246
Gilles Peskine1628a9c2021-05-31 22:09:58 +02002247 # We can only compile, not link, since we don't have any implementations
2248 # suitable for testing with the dummy alt headers.
2249 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
2250}
2251
2252component_build_dhm_alt () {
2253 msg "build: MBEDTLS_DHM_ALT" # ~30s
2254 scripts/config.py full
2255 scripts/config.py set MBEDTLS_DHM_ALT
2256 # debug.c currently references mbedtls_dhm_context fields directly.
2257 scripts/config.py unset MBEDTLS_DEBUG_C
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002258 # We can only compile, not link, since we don't have any implementations
2259 # suitable for testing with the dummy alt headers.
2260 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
2261}
2262
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002263component_test_no_use_psa_crypto_full_cmake_asan() {
2264 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02002265 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002266 scripts/config.py full
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002267 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
2268 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cron6f135e12021-12-08 16:57:54 +01002269 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002270 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02002271 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002272 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Raef Colesa7e03ad2022-09-28 09:32:48 +01002273 scripts/config.py unset MBEDTLS_LMS_C
Raef Coles47bccb72022-09-28 12:00:20 +01002274 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01002275 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002276 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02002277
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002278 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002279 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02002280
Manuel Pégourié-Gonnard182a23b2022-12-07 10:38:43 +01002281 # Note: ssl-opt.sh has some test cases that depend on
2282 # MBEDTLS_ECP_RESTARTABLE && !MBEDTLS_USE_PSA_CRYPTO
2283 # This is the only component where those tests are not skipped.
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002284 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002285 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002286
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002287 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002288 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04002289
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02002290 msg "test: compat.sh NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinee29203b2023-08-27 21:43:00 +02002291 tests/compat.sh -f 'NULL'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002292
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002293 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01002294 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002295}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002296
Ronald Cron403c15c2021-09-13 09:38:05 +02002297component_test_psa_crypto_config_accel_ecdsa () {
Valerio Setti5aab43f2023-03-29 10:42:07 +02002298 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
Ronald Cron403c15c2021-09-13 09:38:05 +02002299
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002300 # Algorithms and key types to accelerate
Valerio Settic0d2f842023-06-28 10:48:08 +02002301 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
Valerio Setti0a342c92023-09-01 09:12:31 +02002302 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002303
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002304 # Note: Those are handled in a special way by the libtestdriver machinery,
2305 # so we only want to include them in the accel list when building the main
2306 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002307 loc_curve_list="$(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002308
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002309 # Configure
2310 # ---------
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002311
Manuel Pégourié-Gonnard8d645dc2023-06-15 09:07:10 +02002312 # Start from default config (no USE_PSA) + TLS 1.3
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002313 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard6d7db932022-12-28 09:48:01 +01002314 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002315
2316 # Disable the module that's accelerated
Ronald Cron403c15c2021-09-13 09:38:05 +02002317 scripts/config.py unset MBEDTLS_ECDSA_C
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002318
2319 # Disable things that depend on it
Ronald Cron403c15c2021-09-13 09:38:05 +02002320 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2321 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2322
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002323 # Build
2324 # -----
2325
2326 # These hashes are needed for some ECDSA signature tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02002327 loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2328 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002329
2330 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2331
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002332 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02002333
Manuel Pégourié-Gonnarde3095e72022-12-28 10:09:53 +01002334 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine827dbd92022-02-04 00:30:54 +01002335 not grep mbedtls_ecdsa_ library/ecdsa.o
Ronald Cron403c15c2021-09-13 09:38:05 +02002336
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002337 # Run the tests
2338 # -------------
2339
Ronald Cron403c15c2021-09-13 09:38:05 +02002340 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
2341 make test
2342}
2343
Valerio Setti44b178c2023-03-22 14:02:57 +01002344component_test_psa_crypto_config_accel_ecdh () {
Valerio Setti5aab43f2023-03-29 10:42:07 +02002345 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002346
2347 # Algorithms and key types to accelerate
Valerio Settic0d2f842023-06-28 10:48:08 +02002348 loc_accel_list="ALG_ECDH \
Valerio Setti0a342c92023-09-01 09:12:31 +02002349 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002350
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002351 # Note: Those are handled in a special way by the libtestdriver machinery,
2352 # so we only want to include them in the accel list when building the main
2353 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002354 loc_curve_list="$(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002355
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002356 # Configure
2357 # ---------
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002358
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002359 # Start from default config (no TLS 1.3, no USE_PSA)
2360 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002361
Valerio Setti44b178c2023-03-22 14:02:57 +01002362 # Disable the module that's accelerated
2363 scripts/config.py unset MBEDTLS_ECDH_C
2364
2365 # Disable things that depend on it
2366 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2367 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2368 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2369 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2370 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2371
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002372 # Build
2373 # -----
2374
2375 helper_libtestdriver1_make_drivers "$loc_accel_list"
2376
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002377 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002378
Valerio Setti44b178c2023-03-22 14:02:57 +01002379 # Make sure this was not re-enabled by accident (additive config)
2380 not grep mbedtls_ecdh_ library/ecdh.o
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002381
2382 # Run the tests
2383 # -------------
2384
Valerio Setti44b178c2023-03-22 14:02:57 +01002385 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002386 make test
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +01002387}
2388
Przemek Stekieldccb2022023-05-11 10:48:50 +02002389component_test_psa_crypto_config_accel_ffdh () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002390 msg "build: full with accelerated FFDH"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002391
2392 # Algorithms and key types to accelerate
Valerio Setti27602c32023-07-10 16:38:59 +02002393 loc_accel_list="ALG_FFDH \
Valerio Setti0a342c92023-09-01 09:12:31 +02002394 $(helper_get_psa_key_type_list "DH")"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002395
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002396 # Configure
2397 # ---------
Przemek Stekieldccb2022023-05-11 10:48:50 +02002398
Przemek Stekiel565353e2023-07-05 11:07:07 +02002399 # start with full (USE_PSA and TLS 1.3)
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002400 helper_libtestdriver1_adjust_config "full"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002401
2402 # Disable the module that's accelerated
2403 scripts/config.py unset MBEDTLS_DHM_C
2404
2405 # Disable things that depend on it
2406 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2407 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2408
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002409 # Build
2410 # -----
2411
2412 helper_libtestdriver1_make_drivers "$loc_accel_list"
2413
Manuel Pégourié-Gonnard981732e2023-06-08 09:15:59 +02002414 helper_libtestdriver1_make_main "$loc_accel_list"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002415
2416 # Make sure this was not re-enabled by accident (additive config)
2417 not grep mbedtls_dhm_ library/dhm.o
2418
2419 # Run the tests
2420 # -------------
2421
Gilles Peskine14302ed2023-07-19 19:30:04 +02002422 msg "test: full with accelerated FFDH"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002423 make test
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002424
Gilles Peskine14302ed2023-07-19 19:30:04 +02002425 msg "ssl-opt: full with accelerated FFDH alg"
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002426 tests/ssl-opt.sh -f "ffdh"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002427}
2428
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002429component_test_psa_crypto_config_reference_ffdh () {
Gilles Peskineb7d577e2023-08-09 19:48:58 +02002430 msg "build: full with non-accelerated FFDH"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002431
2432 # Start with full (USE_PSA and TLS 1.3)
Przemek Stekiel565353e2023-07-05 11:07:07 +02002433 helper_libtestdriver1_adjust_config "full"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002434
2435 # Disable things that are not supported
2436 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2437 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002438 make
2439
Gilles Peskine14302ed2023-07-19 19:30:04 +02002440 msg "test suites: full with non-accelerated FFDH alg"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002441 make test
2442
Gilles Peskine14302ed2023-07-19 19:30:04 +02002443 msg "ssl-opt: full with non-accelerated FFDH alg"
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002444 tests/ssl-opt.sh -f "ffdh"
Valerio Setti42d5f192023-03-20 13:54:41 +01002445}
2446
Valerio Setti44b178c2023-03-22 14:02:57 +01002447component_test_psa_crypto_config_accel_pake() {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002448 msg "build: full with accelerated PAKE"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002449
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002450 loc_accel_list="ALG_JPAKE \
2451 $(helper_get_psa_key_type_list "ECC")"
2452
2453 # Note: Those are handled in a special way by the libtestdriver machinery,
2454 # so we only want to include them in the accel list when building the main
2455 # libraries, hence the use of a separate variable.
2456 loc_curve_list="$(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002457
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002458 # Configure
2459 # ---------
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002460
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002461 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002462
2463 # Make built-in fallback not available
2464 scripts/config.py unset MBEDTLS_ECJPAKE_C
2465 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
2466
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002467 # Build
2468 # -----
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002469
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002470 helper_libtestdriver1_make_drivers "$loc_accel_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002471
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002472 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002473
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002474 # Make sure this was not re-enabled by accident (additive config)
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002475 not grep mbedtls_ecjpake_init library/ecjpake.o
2476
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002477 # Run the tests
2478 # -------------
2479
Gilles Peskine14302ed2023-07-19 19:30:04 +02002480 msg "test: full with accelerated PAKE"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002481 make test
2482}
2483
Manuel Pégourié-Gonnard5c210362023-09-26 12:03:10 +02002484component_test_psa_crypto_config_accel_ecc_some_key_types () {
2485 msg "build: full with accelerated EC algs and some key types"
2486
2487 # Algorithms and key types to accelerate
2488 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
2489 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2490 ALG_ECDH \
2491 ALG_JPAKE \
2492 KEY_TYPE_ECC_PUBLIC_KEY \
2493 KEY_TYPE_ECC_KEY_PAIR_BASIC \
2494 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
2495 KEY_TYPE_ECC_KEY_PAIR_EXPORT"
2496
2497 # Note: Curves are handled in a special way by the libtestdriver machinery,
2498 # so we only want to include them in the accel list when building the main
2499 # libraries, hence the use of a separate variable.
2500 loc_curve_list="$(helper_get_psa_curve_list)"
2501
2502 # Configure
2503 # ---------
2504
2505 # start with config full for maximum coverage (also enables USE_PSA)
2506 helper_libtestdriver1_adjust_config "full"
2507
2508 # Disable modules that are accelerated - some will be re-enabled
2509 scripts/config.py unset MBEDTLS_ECDSA_C
2510 scripts/config.py unset MBEDTLS_ECDH_C
2511 scripts/config.py unset MBEDTLS_ECJPAKE_C
2512 scripts/config.py unset MBEDTLS_ECP_C
2513
2514 # Disable all curves - those that aren't accelerated should be re-enabled
2515 helper_disable_builtin_curves
2516
2517 # Restartable feature is not yet supported by PSA. Once it will in
2518 # the future, the following line could be removed (see issues
2519 # 6061, 6332 and following ones)
2520 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2521
2522 # this is not supported by the driver API yet
2523 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2524
2525 # Build
2526 # -----
2527
2528 # These hashes are needed for some ECDSA signature tests.
2529 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2530 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2531 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2532
2533 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
2534
2535 # ECP should be re-enabled but not the others
2536 not grep mbedtls_ecdh_ library/ecdh.o
2537 not grep mbedtls_ecdsa library/ecdsa.o
2538 not grep mbedtls_ecjpake library/ecjpake.o
2539 grep mbedtls_ecp library/ecp.o
2540
2541 # Run the tests
2542 # -------------
2543
2544 msg "test suites: full with accelerated EC algs and some key types"
2545 make test
2546}
2547
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002548# Run tests with only (non-)Weierstrass accelerated
2549# Common code used in:
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002550# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
2551# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002552common_test_psa_crypto_config_accel_ecc_some_curves () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002553 weierstrass=$1
2554 if [ $weierstrass -eq 1 ]; then
2555 desc="Weierstrass"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002556 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002557 desc="non-Weierstrass"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002558 fi
2559
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002560 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002561
2562 # Algorithms and key types to accelerate
2563 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2564 ALG_ECDH \
2565 ALG_JPAKE \
2566 $(helper_get_psa_key_type_list "ECC")"
2567
2568 # Note: Curves are handled in a special way by the libtestdriver machinery,
2569 # so we only want to include them in the accel list when building the main
2570 # libraries, hence the use of a separate variable.
2571 # Note: the following loop is a modified version of
2572 # helper_get_psa_curve_list that only keeps Weierstrass families.
2573 loc_weierstrass_list=""
2574 loc_non_weierstrass_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002575 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
2576 case $item in
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002577 ECC_BRAINPOOL*|ECC_SECP*)
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002578 loc_weierstrass_list="$loc_weierstrass_list $item"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002579 ;;
2580 *)
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002581 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002582 ;;
2583 esac
2584 done
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002585 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002586 loc_curve_list=$loc_weierstrass_list
2587 else
2588 loc_curve_list=$loc_non_weierstrass_list
2589 fi
2590
2591 # Configure
2592 # ---------
2593
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002594 # Start with config crypto_full and remove PK_C:
2595 # that's what's supported now, see docs/driver-only-builds.md.
2596 helper_libtestdriver1_adjust_config "crypto_full"
2597 scripts/config.py unset MBEDTLS_PK_C
2598 scripts/config.py unset MBEDTLS_PK_PARSE_C
2599 scripts/config.py unset MBEDTLS_PK_WRITE_C
2600 # We need to disable RSA too or PK will be re-enabled.
2601 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
2602 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
2603 scripts/config.py unset MBEDTLS_RSA_C
2604 scripts/config.py unset MBEDTLS_PKCS1_V15
2605 scripts/config.py unset MBEDTLS_PKCS1_V21
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002606
2607 # Disable modules that are accelerated - some will be re-enabled
2608 scripts/config.py unset MBEDTLS_ECDSA_C
2609 scripts/config.py unset MBEDTLS_ECDH_C
2610 scripts/config.py unset MBEDTLS_ECJPAKE_C
2611 scripts/config.py unset MBEDTLS_ECP_C
2612
2613 # Disable all curves - those that aren't accelerated should be re-enabled
2614 helper_disable_builtin_curves
2615
2616 # Restartable feature is not yet supported by PSA. Once it will in
2617 # the future, the following line could be removed (see issues
2618 # 6061, 6332 and following ones)
2619 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2620
2621 # this is not supported by the driver API yet
2622 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2623
2624 # Build
2625 # -----
2626
2627 # These hashes are needed for some ECDSA signature tests.
2628 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2629 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2630 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2631
2632 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
2633
2634 # We expect ECDH to be re-enabled for the missing curves
2635 grep mbedtls_ecdh_ library/ecdh.o
2636 # We expect ECP to be re-enabled, however the parts specific to the
2637 # families of curves that are accelerated should be ommited.
2638 # - functions with mxz in the name are specific to Montgomery curves
2639 # - ecp_muladd is specific to Weierstrass curves
2640 ##nm library/ecp.o | tee ecp.syms
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002641 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002642 not grep mbedtls_ecp_muladd library/ecp.o
2643 grep mxz library/ecp.o
2644 else
2645 grep mbedtls_ecp_muladd library/ecp.o
2646 not grep mxz library/ecp.o
2647 fi
2648 # We expect ECDSA and ECJPAKE to be re-enabled only when
2649 # Weierstrass curves are not accelerated
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002650 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002651 not grep mbedtls_ecdsa library/ecdsa.o
2652 not grep mbedtls_ecjpake library/ecjpake.o
2653 else
2654 grep mbedtls_ecdsa library/ecdsa.o
2655 grep mbedtls_ecjpake library/ecjpake.o
2656 fi
2657
2658 # Run the tests
2659 # -------------
2660
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002661 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
2662 make test
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002663}
2664
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002665component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002666 common_test_psa_crypto_config_accel_ecc_some_curves 1
2667}
2668
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002669component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002670 common_test_psa_crypto_config_accel_ecc_some_curves 0
2671}
2672
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002673# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
2674# ECDH, ECDSA) with and without drivers.
2675# The input parameter is a boolean value which indicates:
2676# - 0 keep built-in EC algs,
2677# - 1 exclude built-in EC algs (driver only).
2678#
2679# This is used by the two following components to ensure they always use the
2680# same config, except for the use of driver or built-in EC algorithms:
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002681# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
2682# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002683# This supports comparing their test coverage with analyze_outcomes.py.
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02002684config_psa_crypto_config_ecp_light_only () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002685 driver_only="$1"
Valerio Setti42d5f192023-03-20 13:54:41 +01002686 # start with config full for maximum coverage (also enables USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002687 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002688 if [ "$driver_only" -eq 1 ]; then
Valerio Setti42d5f192023-03-20 13:54:41 +01002689 # Disable modules that are accelerated
2690 scripts/config.py unset MBEDTLS_ECDSA_C
2691 scripts/config.py unset MBEDTLS_ECDH_C
2692 scripts/config.py unset MBEDTLS_ECJPAKE_C
Valerio Setti29b395c2023-04-05 18:20:30 +02002693 scripts/config.py unset MBEDTLS_ECP_C
Valerio Setti42d5f192023-03-20 13:54:41 +01002694 fi
2695
2696 # Restartable feature is not yet supported by PSA. Once it will in
2697 # the future, the following line could be removed (see issues
2698 # 6061, 6332 and following ones)
2699 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Setti42d5f192023-03-20 13:54:41 +01002700}
2701
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002702# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
2703component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002704 msg "build: full with accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002705
2706 # Algorithms and key types to accelerate
2707 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2708 ALG_ECDH \
2709 ALG_JPAKE \
Valerio Setti0a342c92023-09-01 09:12:31 +02002710 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002711
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002712 # Note: Those are handled in a special way by the libtestdriver machinery,
2713 # so we only want to include them in the accel list when building the main
2714 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002715 loc_curve_list="$(helper_get_psa_curve_list)"
Valerio Setti42d5f192023-03-20 13:54:41 +01002716
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002717 # Configure
2718 # ---------
Valerio Setti42d5f192023-03-20 13:54:41 +01002719
2720 # Use the same config as reference, only without built-in EC algs
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02002721 config_psa_crypto_config_ecp_light_only 1
Valerio Setti42d5f192023-03-20 13:54:41 +01002722
Valerio Setti0a342c92023-09-01 09:12:31 +02002723 # Do not disable builtin curves because that support is required for:
Valerio Settib2fd6732023-08-15 17:10:47 +02002724 # - MBEDTLS_PK_PARSE_EC_EXTENDED
2725 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
2726
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002727 # Build
2728 # -----
2729
2730 # These hashes are needed for some ECDSA signature tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02002731 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2732 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002733 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2734
Valerio Settib2fd6732023-08-15 17:10:47 +02002735 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Valerio Setti42d5f192023-03-20 13:54:41 +01002736
2737 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
2738 not grep mbedtls_ecdsa_ library/ecdsa.o
2739 not grep mbedtls_ecdh_ library/ecdh.o
2740 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Setti29b395c2023-04-05 18:20:30 +02002741 not grep mbedtls_ecp_mul library/ecp.o
Valerio Setti42d5f192023-03-20 13:54:41 +01002742
2743 # Run the tests
2744 # -------------
2745
Gilles Peskine14302ed2023-07-19 19:30:04 +02002746 msg "test suites: full with accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002747 make test
2748
Gilles Peskine14302ed2023-07-19 19:30:04 +02002749 msg "ssl-opt: full with accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002750 tests/ssl-opt.sh
2751}
2752
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002753# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
2754component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002755 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002756
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02002757 config_psa_crypto_config_ecp_light_only 0
Valerio Setti42d5f192023-03-20 13:54:41 +01002758
2759 make
2760
Gilles Peskine14302ed2023-07-19 19:30:04 +02002761 msg "test suites: full with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002762 make test
2763
Gilles Peskine14302ed2023-07-19 19:30:04 +02002764 msg "ssl-opt: full with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002765 tests/ssl-opt.sh
2766}
2767
Valerio Settie618cb02023-04-12 14:59:16 +02002768# This helper function is used by:
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002769# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
2770# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Valerio Settie618cb02023-04-12 14:59:16 +02002771# to ensure that both tests use the same underlying configuration when testing
2772# driver's coverage with analyze_outcomes.py.
2773#
2774# This functions accepts 1 boolean parameter as follows:
2775# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
2776# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
2777# - 0: include built-in implementation of EC algorithms.
2778#
2779# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
2780# on the ECP module.
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002781config_psa_crypto_no_ecp_at_all () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002782 driver_only="$1"
Valerio Settiaafe9002023-06-26 15:23:44 +02002783 # start with full config for maximum coverage (also enables USE_PSA)
2784 helper_libtestdriver1_adjust_config "full"
2785
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002786 if [ "$driver_only" -eq 1 ]; then
Valerio Settie618cb02023-04-12 14:59:16 +02002787 # Disable modules that are accelerated
2788 scripts/config.py unset MBEDTLS_ECDSA_C
2789 scripts/config.py unset MBEDTLS_ECDH_C
2790 scripts/config.py unset MBEDTLS_ECJPAKE_C
2791 # Disable ECP module (entirely)
2792 scripts/config.py unset MBEDTLS_ECP_C
Valerio Settie618cb02023-04-12 14:59:16 +02002793 fi
2794
Valerio Settiaecd32c2023-06-14 10:42:31 +02002795 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
2796 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
Valerio Settiaddeee42023-06-14 10:46:55 +02002797 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
Ronald Cron6b49b552023-07-20 09:57:54 +02002798 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Valerio Settiaecd32c2023-06-14 10:42:31 +02002799
Valerio Settie618cb02023-04-12 14:59:16 +02002800 # Restartable feature is not yet supported by PSA. Once it will in
2801 # the future, the following line could be removed (see issues
2802 # 6061, 6332 and following ones)
2803 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Settie618cb02023-04-12 14:59:16 +02002804}
2805
2806# Build and test a configuration where driver accelerates all EC algs while
2807# all support and dependencies from ECP and ECP_LIGHT are removed on the library
2808# side.
2809#
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002810# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
2811component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002812 msg "build: full + accelerated EC algs - ECP"
Valerio Settie618cb02023-04-12 14:59:16 +02002813
2814 # Algorithms and key types to accelerate
2815 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2816 ALG_ECDH \
2817 ALG_JPAKE \
Valerio Setti0a342c92023-09-01 09:12:31 +02002818 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002819
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002820 # Note: Those are handled in a special way by the libtestdriver machinery,
2821 # so we only want to include them in the accel list when building the main
2822 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002823 loc_curve_list="$(helper_get_psa_curve_list)"
Valerio Settie618cb02023-04-12 14:59:16 +02002824
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002825 # Configure
2826 # ---------
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002827
Valerio Settie618cb02023-04-12 14:59:16 +02002828 # Set common configurations between library's and driver's builds
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002829 config_psa_crypto_no_ecp_at_all 1
Valerio Settib2fd6732023-08-15 17:10:47 +02002830 # Disable all the builtin curves. All the required algs are accelerated.
2831 helper_disable_builtin_curves
Valerio Settie618cb02023-04-12 14:59:16 +02002832
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002833 # Build
2834 # -----
Valerio Settie618cb02023-04-12 14:59:16 +02002835
2836 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02002837 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
2838 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2839 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Valerio Settie618cb02023-04-12 14:59:16 +02002840
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +02002841 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
Valerio Settie618cb02023-04-12 14:59:16 +02002842
Valerio Settib2fd6732023-08-15 17:10:47 +02002843 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Valerio Settie618cb02023-04-12 14:59:16 +02002844
2845 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
2846 not grep mbedtls_ecdsa_ library/ecdsa.o
2847 not grep mbedtls_ecdh_ library/ecdh.o
2848 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Settib2fd6732023-08-15 17:10:47 +02002849 # Also ensure that ECP module was not re-enabled
Valerio Settie618cb02023-04-12 14:59:16 +02002850 not grep mbedtls_ecp_ library/ecp.o
Valerio Settie618cb02023-04-12 14:59:16 +02002851
2852 # Run the tests
2853 # -------------
2854
Gilles Peskine14302ed2023-07-19 19:30:04 +02002855 msg "test: full + accelerated EC algs - ECP"
Valerio Settie618cb02023-04-12 14:59:16 +02002856 make test
Valerio Setti16b70f22023-06-27 17:45:49 +02002857
Gilles Peskine14302ed2023-07-19 19:30:04 +02002858 msg "ssl-opt: full + accelerated EC algs - ECP"
Valerio Setti16b70f22023-06-27 17:45:49 +02002859 tests/ssl-opt.sh
Valerio Settie618cb02023-04-12 14:59:16 +02002860}
2861
2862# Reference function used for driver's coverage analysis in analyze_outcomes.py
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002863# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
Valerio Settie618cb02023-04-12 14:59:16 +02002864# Keep in sync with its accelerated counterpart.
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002865component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002866 msg "build: full + non accelerated EC algs"
Valerio Settie618cb02023-04-12 14:59:16 +02002867
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002868 config_psa_crypto_no_ecp_at_all 0
Valerio Settie618cb02023-04-12 14:59:16 +02002869
2870 make
2871
Gilles Peskine14302ed2023-07-19 19:30:04 +02002872 msg "test: full + non accelerated EC algs"
Valerio Settie618cb02023-04-12 14:59:16 +02002873 make test
Valerio Setti16b70f22023-06-27 17:45:49 +02002874
Gilles Peskine14302ed2023-07-19 19:30:04 +02002875 msg "ssl-opt: full + non accelerated EC algs"
Valerio Setti16b70f22023-06-27 17:45:49 +02002876 tests/ssl-opt.sh
Valerio Settie618cb02023-04-12 14:59:16 +02002877}
2878
Valerio Setti4e2f2442023-08-15 10:10:26 +02002879# This is a common configuration helper used directly from:
2880# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
2881# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
2882# and indirectly from:
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002883# - component_test_psa_crypto_config_accel_ecc_no_bignum
Valerio Setti4e2f2442023-08-15 10:10:26 +02002884# - accelerate all EC algs, disable RSA and FFDH
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002885# - component_test_psa_crypto_config_reference_ecc_no_bignum
Valerio Setti4e2f2442023-08-15 10:10:26 +02002886# - this is the reference component of the above
2887# - it still disables RSA and FFDH, but it uses builtin EC algs
2888# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
2889# - accelerate all EC and FFDH algs, disable only RSA
2890# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
2891# - this is the reference component of the above
2892# - it still disables RSA, but it uses builtin EC and FFDH algs
2893#
2894# This function accepts 2 parameters:
Valerio Setti5dfaca42023-09-05 08:48:51 +02002895# $1: a boolean value which states if we are testing an accelerated scenario
2896# or not.
2897# $2: a string value which states which components are tested. Allowed values
2898# are "ECC" or "ECC_DH".
Valerio Setti4e2f2442023-08-15 10:10:26 +02002899config_psa_crypto_config_accel_ecc_ffdh_no_bignum() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002900 driver_only="$1"
2901 test_target="$2"
Valerio Setti18535c32023-07-31 11:27:17 +02002902 # start with full config for maximum coverage (also enables USE_PSA)
Valerio Setti29c1b4d2023-07-27 10:08:45 +02002903 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002904
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002905 if [ "$driver_only" -eq 1 ]; then
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002906 # Disable modules that are accelerated
2907 scripts/config.py unset MBEDTLS_ECDSA_C
2908 scripts/config.py unset MBEDTLS_ECDH_C
2909 scripts/config.py unset MBEDTLS_ECJPAKE_C
2910 # Disable ECP module (entirely)
2911 scripts/config.py unset MBEDTLS_ECP_C
Manuel Pégourié-Gonnard660bbf22023-06-12 18:42:40 +02002912 # Also disable bignum
2913 scripts/config.py unset MBEDTLS_BIGNUM_C
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002914 fi
2915
2916 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
2917 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
2918 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
2919 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2920
Manuel Pégourié-Gonnard7dccb662023-06-12 18:28:42 +02002921 # RSA support is intentionally disabled on this test because RSA_C depends
2922 # on BIGNUM_C.
Valerio Setti2e0275d2023-07-28 16:33:13 +02002923 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
2924 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 +02002925 scripts/config.py unset MBEDTLS_RSA_C
2926 scripts/config.py unset MBEDTLS_PKCS1_V15
2927 scripts/config.py unset MBEDTLS_PKCS1_V21
2928 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2929 # Also disable key exchanges that depend on RSA
2930 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2931 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2932 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2933 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2934 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2935
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002936 if [ "$test_target" = "ECC" ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02002937 # When testing ECC only, we disable FFDH support, both from builtin and
2938 # PSA sides, and also disable the key exchanges that depend on DHM.
2939 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_FFDH
2940 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
2941 scripts/config.py unset MBEDTLS_DHM_C
2942 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2943 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2944 else
2945 # When testing ECC and DH instead, we disable DHM and depending key
2946 # exchanges only in the accelerated build
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002947 if [ "$driver_only" -eq 1 ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02002948 scripts/config.py unset MBEDTLS_DHM_C
2949 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2950 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2951 fi
2952 fi
Manuel Pégourié-Gonnard7dccb662023-06-12 18:28:42 +02002953
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002954 # Restartable feature is not yet supported by PSA. Once it will in
2955 # the future, the following line could be removed (see issues
2956 # 6061, 6332 and following ones)
2957 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2958}
2959
Valerio Setti4e2f2442023-08-15 10:10:26 +02002960# Common helper used by:
2961# - component_test_psa_crypto_config_accel_ecc_no_bignum
2962# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002963#
Valerio Setti4e2f2442023-08-15 10:10:26 +02002964# The goal is to build and test accelerating either:
2965# - ECC only or
2966# - both ECC and FFDH
2967#
2968# It is meant to be used in conjunction with
Valerio Setti5dfaca42023-09-05 08:48:51 +02002969# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
2970# coverage analysis in the "analyze_outcomes.py" script.
Valerio Setti4e2f2442023-08-15 10:10:26 +02002971common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002972 test_target="$1"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002973
Valerio Setti5dfaca42023-09-05 08:48:51 +02002974 # This is an internal helper to simplify text message handling
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002975 if [ "$test_target" = "ECC_DH" ]; then
2976 accel_text="ECC/FFDH"
2977 removed_text="ECP - DH"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002978 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002979 accel_text="ECC"
2980 removed_text="ECP"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002981 fi
2982
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002983 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002984
2985 # By default we accelerate all EC keys/algs
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002986 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2987 ALG_ECDH \
2988 ALG_JPAKE \
Valerio Setti0a342c92023-09-01 09:12:31 +02002989 $(helper_get_psa_key_type_list "ECC")"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002990 # Optionally we can also add DH to the list of accelerated items
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002991 if [ "$test_target" = "ECC_DH" ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02002992 loc_accel_list="$loc_accel_list \
2993 ALG_FFDH \
Manuel Pégourié-Gonnard85ff5e62023-09-22 09:05:48 +02002994 $(helper_get_psa_key_type_list "DH")"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002995 fi
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002996
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002997 # Note: Those are handled in a special way by the libtestdriver machinery,
2998 # so we only want to include them in the accel list when building the main
2999 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02003000 loc_curve_list="$(helper_get_psa_curve_list)"
3001
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003002 # Configure
3003 # ---------
3004
3005 # Set common configurations between library's and driver's builds
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003006 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
Valerio Settib2fd6732023-08-15 17:10:47 +02003007 # Disable all the builtin curves. All the required algs are accelerated.
3008 helper_disable_builtin_curves
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003009
3010 # Build
3011 # -----
3012
3013 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02003014 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
3015 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3016 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003017
3018 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
3019
Valerio Settib2fd6732023-08-15 17:10:47 +02003020 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003021
3022 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
3023 not grep mbedtls_ecdsa_ library/ecdsa.o
3024 not grep mbedtls_ecdh_ library/ecdh.o
3025 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Setti4e2f2442023-08-15 10:10:26 +02003026 # Also ensure that ECP, RSA, [DHM] or BIGNUM modules were not re-enabled
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003027 not grep mbedtls_ecp_ library/ecp.o
Manuel Pégourié-Gonnard06aebe42023-06-12 18:33:34 +02003028 not grep mbedtls_rsa_ library/rsa.o
Manuel Pégourié-Gonnard660bbf22023-06-12 18:42:40 +02003029 not grep mbedtls_mpi_ library/bignum.o
Valerio Setti4e2f2442023-08-15 10:10:26 +02003030 not grep mbedtls_dhm_ library/dhm.o
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003031
3032 # Run the tests
3033 # -------------
3034
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003035 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - DHM - BIGNUM"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003036
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003037 make test
3038
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003039 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Valerio Setti18535c32023-07-31 11:27:17 +02003040 tests/ssl-opt.sh
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003041}
3042
Valerio Setti4e2f2442023-08-15 10:10:26 +02003043# Common helper used by:
3044# - component_test_psa_crypto_config_reference_ecc_no_bignum
3045# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
3046#
3047# The goal is to build and test a reference scenario (i.e. with builtin
3048# components) compared to the ones used in
3049# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
3050#
3051# It is meant to be used in conjunction with
3052# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
3053# coverage analysis in "analyze_outcomes.py" script.
3054common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003055 test_target="$1"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003056
Valerio Setti5dfaca42023-09-05 08:48:51 +02003057 # This is an internal helper to simplify text message handling
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003058 if [ "$test_target" = "ECC_DH" ]; then
3059 accel_text="ECC/FFDH"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003060 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003061 accel_text="ECC"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003062 fi
3063
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003064 msg "build: full + non accelerated $accel_text algs + USE_PSA"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003065
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003066 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003067
3068 make
3069
Valerio Setti29c1b4d2023-07-27 10:08:45 +02003070 msg "test suites: full + non accelerated EC algs + USE_PSA"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003071 make test
3072
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003073 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
Valerio Setti18535c32023-07-31 11:27:17 +02003074 tests/ssl-opt.sh
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003075}
3076
Valerio Setti4e2f2442023-08-15 10:10:26 +02003077component_test_psa_crypto_config_accel_ecc_no_bignum () {
3078 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
3079}
3080
3081component_test_psa_crypto_config_reference_ecc_no_bignum () {
3082 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
3083}
3084
3085component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
3086 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
3087}
3088
3089component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
3090 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
3091}
3092
Valerio Settiac6d35f2023-08-04 12:49:11 +02003093# Helper for setting common configurations between:
3094# - component_test_tfm_config_p256m_driver_accel_ec()
3095# - component_test_tfm_config()
Valerio Setti52ba0e32023-08-04 12:43:03 +02003096common_tfm_config () {
3097 # Enable TF-M config
Valerio Settic5c4bd22023-08-03 14:28:20 +02003098 cp configs/tfm_mbedcrypto_config_profile_medium.h "$CONFIG_H"
3099 cp configs/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
3100
Valerio Setti52ba0e32023-08-04 12:43:03 +02003101 # Adjust for the fact that we're building outside the TF-M environment.
3102 #
3103 # TF-M has separation, our build doesn't
3104 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SPM
3105 scripts/config.py unset MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
3106 # TF-M provdes its own (dummy) implemenation, from their tree
3107 scripts/config.py unset MBEDTLS_AES_DECRYPT_ALT
3108 scripts/config.py unset MBEDTLS_AES_SETKEY_DEC_ALT
3109 # We have an OS that provides entropy, use it
3110 scripts/config.py unset MBEDTLS_NO_PLATFORM_ENTROPY
3111
3112 # Other config adjustments to make the tests pass.
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003113 # Those should probably be adopted upstream.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003114 #
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003115 # - USE_PSA_CRYPTO for PK_HAVE_ECC_KEYS
3116 echo "#define MBEDTLS_USE_PSA_CRYPTO" >> "$CONFIG_H"
Valerio Setti52ba0e32023-08-04 12:43:03 +02003117 # pkparse.c and pkwrite.c fail to link without this
3118 echo "#define MBEDTLS_OID_C" >> "$CONFIG_H"
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003119 # - ASN1_[PARSE/WRITE]_C found by check_config.h for pkparse/pkwrite
3120 echo "#define MBEDTLS_ASN1_PARSE_C" >> "$CONFIG_H"
3121 echo "#define MBEDTLS_ASN1_WRITE_C" >> "$CONFIG_H"
3122 # - MD_C for HKDF_C
3123 echo "#define MBEDTLS_MD_C" >> "$CONFIG_H"
Valerio Setti52ba0e32023-08-04 12:43:03 +02003124
Manuel Pégourié-Gonnardf7298cd2023-09-18 09:55:24 +02003125 # Config adjustments for better test coverage in our environment.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003126 # These are not needed just to build and pass tests.
3127 #
3128 # Enable filesystem I/O for the benefit of PK parse/write tests.
3129 echo "#define MBEDTLS_FS_IO" >> "$CONFIG_H"
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003130 # Disable this for maximal ASan efficiency
3131 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
3132
Manuel Pégourié-Gonnardf7298cd2023-09-18 09:55:24 +02003133 # Config adjustments for features that are not supported
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003134 # when using only drivers / by p256-m
3135 #
3136 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
3137 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
3138 # Disable deterministic ECDSA as p256-m only does randomized
3139 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
3140
Valerio Setti52ba0e32023-08-04 12:43:03 +02003141}
3142
Valerio Settiac6d35f2023-08-04 12:49:11 +02003143# Keep this in sync with component_test_tfm_config() as they are both meant
3144# to be used in analyze_outcomes.py for driver's coverage analysis.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003145component_test_tfm_config_p256m_driver_accel_ec () {
3146 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
3147
3148 common_tfm_config
Valerio Settic5c4bd22023-08-03 14:28:20 +02003149
Valerio Settic5c4bd22023-08-03 14:28:20 +02003150 # Build crypto library specifying we want to use P256M code for EC operations
Manuel Pégourié-Gonnardeda70862023-09-22 12:17:50 +02003151 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 +02003152
Valerio Settic5c4bd22023-08-03 14:28:20 +02003153 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003154 not grep mbedtls_ecdsa_ library/ecdsa.o
Valerio Settic5c4bd22023-08-03 14:28:20 +02003155 not grep mbedtls_ecdh_ library/ecdh.o
3156 not grep mbedtls_ecjpake_ library/ecjpake.o
3157 # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003158 not grep mbedtls_ecp_ library/ecp.o
Valerio Settic5c4bd22023-08-03 14:28:20 +02003159 not grep mbedtls_rsa_ library/rsa.o
3160 not grep mbedtls_dhm_ library/dhm.o
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003161 not grep mbedtls_mpi_ library/bignum.o
Valerio Settic5c4bd22023-08-03 14:28:20 +02003162
3163 # Run the tests
Valerio Setti52ba0e32023-08-04 12:43:03 +02003164 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
Valerio Settic5c4bd22023-08-03 14:28:20 +02003165 make test
Valerio Setti52ba0e32023-08-04 12:43:03 +02003166}
Valerio Settic5c4bd22023-08-03 14:28:20 +02003167
Valerio Settiac6d35f2023-08-04 12:49:11 +02003168# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
3169# they are both meant to be used in analyze_outcomes.py for driver's coverage
3170# analysis.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003171component_test_tfm_config() {
3172 common_tfm_config
3173
3174 msg "build: TF-M config"
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02003175 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' tests
Valerio Setti52ba0e32023-08-04 12:43:03 +02003176
3177 msg "test: TF-M config"
3178 make test
Valerio Settic5c4bd22023-08-03 14:28:20 +02003179}
3180
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003181# Common helper for component_full_without_ecdhe_ecdsa() and
3182# component_full_without_ecdhe_ecdsa_and_tls13() which:
3183# - starts from the "full" configuration minus the list of symbols passed in
3184# as 1st parameter
3185# - build
3186# - test only TLS (i.e. test_suite_tls and ssl-opt)
3187build_full_minus_something_and_test_tls () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003188 symbols_to_disable="$1"
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003189
3190 msg "build: full minus something, test TLS"
3191
3192 scripts/config.py full
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003193 for sym in $symbols_to_disable; do
3194 echo "Disabling $sym"
3195 scripts/config.py unset $sym
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003196 done
3197
3198 make
3199
3200 msg "test: full minus something, test TLS"
3201 ( cd tests; ./test_suite_ssl )
3202
3203 msg "ssl-opt: full minus something, test TLS"
3204 tests/ssl-opt.sh
3205}
3206
3207component_full_without_ecdhe_ecdsa () {
3208 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED"
3209}
3210
3211component_full_without_ecdhe_ecdsa_and_tls13 () {
3212 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
3213 MBEDTLS_SSL_PROTO_TLS1_3"
3214}
3215
Valerio Setti249b18a2023-06-20 12:08:30 +02003216# This is an helper used by:
3217# - component_test_psa_ecc_key_pair_no_derive
3218# - component_test_psa_ecc_key_pair_no_generate
3219# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
3220# enabled, but one. Input arguments are as follows:
3221# - $1 is the key type under test, i.e. ECC/RSA/DH
3222# - $2 is the key option to be unset (i.e. generate, derive, etc)
Valerio Settia9836552023-06-22 11:22:23 +02003223build_and_test_psa_want_key_pair_partial() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003224 key_type=$1
3225 unset_option=$2
3226 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003227
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003228 msg "build: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003229 scripts/config.py full
Valerio Setti249b18a2023-06-20 12:08:30 +02003230 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3231 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3232
3233 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
3234 # crypto_config.h so we just disable the one we don't want.
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003235 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
Valerio Setti249b18a2023-06-20 12:08:30 +02003236
Valerio Settif6587be2023-06-22 11:33:14 +02003237 make CC=gcc CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Valerio Setti249b18a2023-06-20 12:08:30 +02003238
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003239 msg "test: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003240 make test
3241}
3242
3243component_test_psa_ecc_key_pair_no_derive() {
Valerio Settia9836552023-06-22 11:22:23 +02003244 build_and_test_psa_want_key_pair_partial "ECC" "DERIVE"
Valerio Setti249b18a2023-06-20 12:08:30 +02003245}
3246
3247component_test_psa_ecc_key_pair_no_generate() {
Valerio Settia9836552023-06-22 11:22:23 +02003248 build_and_test_psa_want_key_pair_partial "ECC" "GENERATE"
Valerio Setti249b18a2023-06-20 12:08:30 +02003249}
3250
Ronald Cron403c15c2021-09-13 09:38:05 +02003251component_test_psa_crypto_config_accel_rsa_signature () {
3252 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
3253
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003254 loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
3255
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003256 # Configure
3257 # ---------
Ronald Cron403c15c2021-09-13 09:38:05 +02003258
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003259 # Start from default config (no TLS 1.3, no USE_PSA)
3260 helper_libtestdriver1_adjust_config "default"
Ronald Cron403c15c2021-09-13 09:38:05 +02003261
3262 # It seems it is not possible to remove only the support for RSA signature
3263 # in the library. Thus we have to remove all RSA support (signature and
3264 # encryption/decryption). AS there is no driver support for asymmetric
3265 # encryption/decryption so far remove RSA encryption/decryption from the
3266 # application algorithm list.
Ronald Cron6b49b552023-07-20 09:57:54 +02003267 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3268 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
Ronald Cron403c15c2021-09-13 09:38:05 +02003269
Manuel Pégourié-Gonnardaed1d782023-06-12 17:22:24 +02003270 # Remove RSA support and its dependencies
3271 scripts/config.py unset MBEDTLS_RSA_C
3272 scripts/config.py unset MBEDTLS_PKCS1_V15
3273 scripts/config.py unset MBEDTLS_PKCS1_V21
3274 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
3275 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3276 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3277 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3278 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
3279 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
3280
Ronald Cron403c15c2021-09-13 09:38:05 +02003281 # Make sure both the library and the test library support the SHA hash
3282 # algorithms and only those ones (SHA256 is included by default). That way:
3283 # - the test library can compute the RSA signatures even in the case of a
3284 # composite RSA signature algorithm based on a SHA hash (no other hash
3285 # used in the unit tests).
3286 # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
3287 # fulfilled as the hash SHA algorithm is supported by the library, and
3288 # thus the tests are run, not skipped.
3289 # - when testing a signature key with an algorithm wildcard built from
3290 # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
3291 # algorithm based on the hashes supported by the library is also
3292 # supported by the test library.
Manuel Pégourié-Gonnardaed1d782023-06-12 17:22:24 +02003293 # Disable unwanted hashes here, we'll enable hashes we want in loc_extra_list.
Ronald Cron6b49b552023-07-20 09:57:54 +02003294 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3295 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160_C
Ronald Cron403c15c2021-09-13 09:38:05 +02003296 scripts/config.py unset MBEDTLS_MD5_C
3297 scripts/config.py unset MBEDTLS_RIPEMD160_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003298
3299 # We need PEM parsing in the test library as well to support the import
3300 # of PEM encoded RSA keys.
Ronald Cron7612d8c2023-07-20 10:03:54 +02003301 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
3302 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003303
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003304 # Build
3305 # -----
3306
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003307 # These hashes are needed for some RSA-PSS signature tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02003308 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3309 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003310 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02003311
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003312 helper_libtestdriver1_make_main "$loc_accel_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02003313
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003314 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine827dbd92022-02-04 00:30:54 +01003315 not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
3316 not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
Ronald Cron403c15c2021-09-13 09:38:05 +02003317
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003318 # Run the tests
3319 # -------------
3320
Ronald Cron403c15c2021-09-13 09:38:05 +02003321 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
3322 make test
3323}
3324
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003325# This is a temporary test to verify that full RSA support is present even when
Valerio Setti01cc88a2023-06-15 11:53:08 +02003326# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003327component_test_new_psa_want_key_pair_symbol() {
Valerio Setti01cc88a2023-06-15 11:53:08 +02003328 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003329
Valerio Setti4590bc22023-06-13 15:39:23 +02003330 # Create a temporary output file unless there is already one set
3331 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
3332 REMOVE_OUTCOME_ON_EXIT="no"
3333 else
3334 REMOVE_OUTCOME_ON_EXIT="yes"
3335 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
3336 export MBEDTLS_TEST_OUTCOME_FILE
3337 fi
3338
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003339 # Start from crypto configuration
3340 scripts/config.py crypto
3341
3342 # Remove RSA support and its dependencies
3343 scripts/config.py unset MBEDTLS_PKCS1_V15
3344 scripts/config.py unset MBEDTLS_PKCS1_V21
3345 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3346 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3347 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3348 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
3349 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
3350 scripts/config.py unset MBEDTLS_RSA_C
3351 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
3352
3353 # Enable PSA support
3354 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3355
Valerio Setti01cc88a2023-06-15 11:53:08 +02003356 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003357 # that proper translations is done in crypto_legacy.h.
Ronald Cron6b49b552023-07-20 09:57:54 +02003358 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
3359 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
3360 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003361
3362 make
3363
Valerio Setti01cc88a2023-06-15 11:53:08 +02003364 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Valerio Setti4590bc22023-06-13 15:39:23 +02003365 make test
3366
3367 # Parse only 1 relevant line from the outcome file, i.e. a test which is
3368 # performing RSA signature.
3369 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
3370 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
3371
3372 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
3373 rm $MBEDTLS_TEST_OUTCOME_FILE
3374 fi
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003375}
3376
Ronald Cronb2312452021-05-08 14:32:59 +02003377component_test_psa_crypto_config_accel_hash () {
3378 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
3379
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003380 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3381 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3382 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Ronald Cronb2312452021-05-08 14:32:59 +02003383
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003384 # Configure
3385 # ---------
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003386
3387 # Start from default config (no TLS 1.3, no USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003388 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003389
3390 # Disable the things that are being accelerated
Ronald Cronb2312452021-05-08 14:32:59 +02003391 scripts/config.py unset MBEDTLS_MD5_C
3392 scripts/config.py unset MBEDTLS_RIPEMD160_C
3393 scripts/config.py unset MBEDTLS_SHA1_C
Manuel Pégourié-Gonnardc584c272023-03-22 00:32:04 +01003394 scripts/config.py unset MBEDTLS_SHA224_C
3395 scripts/config.py unset MBEDTLS_SHA256_C
Ronald Cronb2312452021-05-08 14:32:59 +02003396 scripts/config.py unset MBEDTLS_SHA384_C
3397 scripts/config.py unset MBEDTLS_SHA512_C
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003398 scripts/config.py unset MBEDTLS_SHA3_C
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003399
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003400 # Build
3401 # -----
3402
3403 helper_libtestdriver1_make_drivers "$loc_accel_list"
3404
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003405 helper_libtestdriver1_make_main "$loc_accel_list"
Ronald Cronb2312452021-05-08 14:32:59 +02003406
Manuel Pégourié-Gonnardc584c272023-03-22 00:32:04 +01003407 # There's a risk of something getting re-enabled via config_psa.h;
3408 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
3409 not grep mbedtls_md5 library/md5.o
3410 not grep mbedtls_sha1 library/sha1.o
3411 not grep mbedtls_sha256 library/sha256.o
3412 not grep mbedtls_sha512 library/sha512.o
3413 not grep mbedtls_ripemd160 library/ripemd160.o
Ronald Cronb2312452021-05-08 14:32:59 +02003414
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003415 # Run the tests
3416 # -------------
3417
Ronald Cronb2312452021-05-08 14:32:59 +02003418 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
3419 make test
3420}
3421
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003422component_test_psa_crypto_config_accel_hash_keep_builtins () {
3423 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
3424 # This component ensures that all the test cases for
3425 # md_psa_dynamic_dispatch with legacy+driver in test_suite_md are run.
3426
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003427 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3428 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3429 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003430
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003431 # Start from default config (no TLS 1.3, no USE_PSA)
3432 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003433
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +02003434 helper_libtestdriver1_make_drivers "$loc_accel_list"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003435
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003436 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003437
3438 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
3439 make test
3440}
3441
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003442# Auxiliary function to build config for hashes with and without drivers
3443config_psa_crypto_hash_use_psa () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003444 driver_only="$1"
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003445 # start with config full for maximum coverage (also enables USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003446 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003447 if [ "$driver_only" -eq 1 ]; then
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003448 # disable the built-in implementation of hashes
3449 scripts/config.py unset MBEDTLS_MD5_C
3450 scripts/config.py unset MBEDTLS_RIPEMD160_C
3451 scripts/config.py unset MBEDTLS_SHA1_C
3452 scripts/config.py unset MBEDTLS_SHA224_C
3453 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
3454 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
3455 scripts/config.py unset MBEDTLS_SHA384_C
3456 scripts/config.py unset MBEDTLS_SHA512_C
3457 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003458 scripts/config.py unset MBEDTLS_SHA3_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003459 fi
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003460}
3461
Przemek Stekiel120ed8f2022-10-27 10:29:15 +02003462# Note that component_test_psa_crypto_config_reference_hash_use_psa
3463# is related to this component and both components need to be kept in sync.
3464# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003465component_test_psa_crypto_config_accel_hash_use_psa () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02003466 msg "test: full with accelerated hashes"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003467
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003468 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3469 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3470 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003471
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003472 # Configure
3473 # ---------
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003474
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003475 config_psa_crypto_hash_use_psa 1
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003476
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003477 # Build
3478 # -----
3479
3480 helper_libtestdriver1_make_drivers "$loc_accel_list"
3481
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003482 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003483
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003484 # There's a risk of something getting re-enabled via config_psa.h;
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01003485 # 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 +02003486 not grep mbedtls_md5 library/md5.o
3487 not grep mbedtls_sha1 library/sha1.o
Manuel Pégourié-Gonnard7b0825d2022-07-11 11:06:09 +02003488 not grep mbedtls_sha256 library/sha256.o
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003489 not grep mbedtls_sha512 library/sha512.o
3490 not grep mbedtls_ripemd160 library/ripemd160.o
3491
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003492 # Run the tests
3493 # -------------
3494
Gilles Peskine14302ed2023-07-19 19:30:04 +02003495 msg "test: full with accelerated hashes"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003496 make test
Andrzej Kurek07e35702022-09-05 15:39:23 -04003497
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003498 # This is mostly useful so that we can later compare outcome files with
3499 # the reference config in analyze_outcomes.py, to check that the
3500 # dependency declarations in ssl-opt.sh and in TLS code are correct.
Gilles Peskine14302ed2023-07-19 19:30:04 +02003501 msg "test: ssl-opt.sh, full with accelerated hashes"
Przemek Stekiel5f6f32a2022-10-27 08:24:43 +02003502 tests/ssl-opt.sh
Andrzej Kurek07e35702022-09-05 15:39:23 -04003503
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003504 # This is to make sure all ciphersuites are exercised, but we don't need
3505 # interop testing (besides, we already got some from ssl-opt.sh).
Gilles Peskine14302ed2023-07-19 19:30:04 +02003506 msg "test: compat.sh, full with accelerated hashes"
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003507 tests/compat.sh -p mbedTLS -V YES
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003508}
3509
Przemek Stekiel120ed8f2022-10-27 10:29:15 +02003510# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
3511# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
3512# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
3513# Both components need to be kept in sync.
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003514component_test_psa_crypto_config_reference_hash_use_psa() {
Gilles Peskine14302ed2023-07-19 19:30:04 +02003515 msg "test: full without accelerated hashes"
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003516
3517 config_psa_crypto_hash_use_psa 0
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003518
Przemek Stekielab0451b2022-10-24 11:29:35 +02003519 make
3520
Gilles Peskine14302ed2023-07-19 19:30:04 +02003521 msg "test: full without accelerated hashes"
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003522 make test
3523
Gilles Peskine14302ed2023-07-19 19:30:04 +02003524 msg "test: ssl-opt.sh, full without accelerated hashes"
Przemek Stekiel5f6f32a2022-10-27 08:24:43 +02003525 tests/ssl-opt.sh
Ronald Cron3a8714d2021-10-18 11:26:01 +02003526}
Manuel Pégourié-Gonnard97ab2a32022-07-06 10:46:57 +02003527
John Durkop4377bf72020-10-23 01:26:57 -07003528component_test_psa_crypto_config_accel_cipher () {
3529 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
3530
3531 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 -08003532
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003533 # Configure
3534 # ---------
John Durkop1b7ee052020-11-27 08:51:22 -08003535
Valerio Setti9a427302023-10-17 11:40:42 +02003536 # Start from the full config
Valerio Settia797ce32023-10-03 15:16:38 +02003537 helper_libtestdriver1_adjust_config "full"
John Durkop1b7ee052020-11-27 08:51:22 -08003538
Manuel Pégourié-Gonnard7ae342f2023-06-08 09:26:04 +02003539 # There is no intended accelerator support for ALG CMAC. Therefore, asking
3540 # for it in the build implies the inclusion of the Mbed TLS cipher
3541 # operations. As we want to test here with cipher operations solely
3542 # supported by accelerators, disabled this PSA configuration option.
3543 # (Note: the same applies to STREAM_CIPHER and ECB_NO_PADDING, which are
3544 # already disabled by helper_libtestdriver1_adjust_config above.)
Ronald Cron6b49b552023-07-20 09:57:54 +02003545 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
John Durkop1b7ee052020-11-27 08:51:22 -08003546
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003547 # Disable the things that are being accelerated
John Durkop1b7ee052020-11-27 08:51:22 -08003548 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3549 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
3550 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
3551 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
3552 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
3553 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
3554 scripts/config.py unset MBEDTLS_DES_C
3555
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003556 # Build
3557 # -----
John Durkop1b7ee052020-11-27 08:51:22 -08003558
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003559 helper_libtestdriver1_make_drivers "$loc_accel_list"
3560
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003561 helper_libtestdriver1_make_main "$loc_accel_list"
John Durkop1b7ee052020-11-27 08:51:22 -08003562
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003563 # Make sure this was not re-enabled by accident (additive config)
John Durkop1b7ee052020-11-27 08:51:22 -08003564 not grep mbedtls_des* library/des.o
3565
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003566 # Run the tests
3567 # -------------
3568
John Durkop1b7ee052020-11-27 08:51:22 -08003569 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
3570 make test
3571}
3572
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003573component_test_psa_crypto_config_accel_aead () {
3574 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
3575
Valerio Setti3f02bb72023-10-02 15:57:33 +02003576 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
3577 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003578
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003579 # Configure
3580 # ---------
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003581
Valerio Setti3f02bb72023-10-02 15:57:33 +02003582 # Start from full config
3583 helper_libtestdriver1_adjust_config "full"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003584
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003585 # Disable things that are being accelerated
Przemek Stekielee1bb412022-10-11 11:52:25 +02003586 scripts/config.py unset MBEDTLS_GCM_C
3587 scripts/config.py unset MBEDTLS_CCM_C
3588 scripts/config.py unset MBEDTLS_CHACHAPOLY_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 Rodgman54ada8b2023-10-04 11:55:25 +01003922# Test that the given .o file builds with all (valid) combinations of the given options.
3923#
3924# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
3925#
3926# The validator function is the name of a function to validate the combination of options.
3927# It may be "" if all combinations are valid.
3928# It receives a string containing a combination of options, as passed to the compiler,
Dave Rodgmanf3803a12023-10-16 13:47:15 +01003929# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Dave Rodgman920343a2023-10-01 18:41:09 +01003930build_test_config_combos() {
Dave Rodgman28e38d82023-10-04 11:50:30 +01003931 file=$1
Dave Rodgman920343a2023-10-01 18:41:09 +01003932 shift
Dave Rodgman28e38d82023-10-04 11:50:30 +01003933 validate_options=$1
Dave Rodgman920343a2023-10-01 18:41:09 +01003934 shift
Dave Rodgman28e38d82023-10-04 11:50:30 +01003935 options=("$@")
Dave Rodgman0f0f7692023-06-29 12:10:45 +01003936
Dave Rodgman42436102023-10-03 15:47:05 +01003937 # clear all of the options so that they can be overridden on the clang commandline
Dave Rodgman28e38d82023-10-04 11:50:30 +01003938 for opt in "${options[@]}"; do
3939 ./scripts/config.py unset ${opt}
Dave Rodgman42436102023-10-03 15:47:05 +01003940 done
3941
3942 # enter the directory containing the target file & strip the dir from the filename
Dave Rodgman28e38d82023-10-04 11:50:30 +01003943 cd $(dirname ${file})
3944 file=$(basename ${file})
Dave Rodgman42436102023-10-03 15:47:05 +01003945
Dave Rodgman920343a2023-10-01 18:41:09 +01003946 # The most common issue is unused variables/functions, so ensure -Wunused is set.
Dave Rodgman28e38d82023-10-04 11:50:30 +01003947 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
Dave Rodgman97285622023-09-29 17:32:06 +01003948
Dave Rodgman42436102023-10-03 15:47:05 +01003949 # Extract the command generated by the Makefile to build the target file.
3950 # This ensures that we have any include paths, macro definitions, etc
3951 # that may be applied by make.
3952 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01003953 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
Dave Rodgman42436102023-10-03 15:47:05 +01003954
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01003955 makefile=$(TMPDIR=. mktemp)
Dave Rodgman28e38d82023-10-04 11:50:30 +01003956 deps=""
Dave Rodgman97285622023-09-29 17:32:06 +01003957
Dave Rodgman28e38d82023-10-04 11:50:30 +01003958 len=${#options[@]}
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01003959 source_file=${file%.o}.c
3960
3961 targets=0
3962 echo 'include Makefile' >${makefile}
Dave Rodgman97285622023-09-29 17:32:06 +01003963
Dave Rodgman28e38d82023-10-04 11:50:30 +01003964 for ((i = 0; i < $((2**${len})); i++)); do
Dave Rodgman920343a2023-10-01 18:41:09 +01003965 # generate each of 2^n combinations of options
Dave Rodgman28e38d82023-10-04 11:50:30 +01003966 # each bit of $i is used to determine if options[i] will be set or not
3967 target="t"
3968 clang_args=""
3969 for ((j = 0; j < ${len}; j++)); do
Dave Rodgmanb1107ae2023-10-04 12:30:23 +01003970 if (((i >> j) & 1)); then
Dave Rodgmana7127eb2023-10-04 13:38:41 +01003971 opt=-D${options[$j]}
Dave Rodgman7a8a2492023-10-04 13:14:20 +01003972 clang_args="${clang_args} ${opt}"
3973 target="${target}${opt}"
Dave Rodgmanb1107ae2023-10-04 12:30:23 +01003974 fi
Dave Rodgman920343a2023-10-01 18:41:09 +01003975 done
3976
Dave Rodgmanb1107ae2023-10-04 12:30:23 +01003977 # if combination is not known to be invalid, add it to the makefile
Dave Rodgmanf3803a12023-10-16 13:47:15 +01003978 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
Dave Rodgman28e38d82023-10-04 11:50:30 +01003979 cmd="${compile_cmd} ${clang_args}"
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01003980 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
Dave Rodgman920343a2023-10-01 18:41:09 +01003981
Dave Rodgman28e38d82023-10-04 11:50:30 +01003982 deps="${deps} ${target}"
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01003983 ((++targets))
Dave Rodgman745af9f2023-09-29 15:47:07 +01003984 fi
Dave Rodgman97285622023-09-29 17:32:06 +01003985 done
Dave Rodgman6001fb22023-06-29 09:29:00 +01003986
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01003987 echo "build_test_config_combos: ${deps}" >> ${makefile}
Dave Rodgmanaea01c92023-09-29 18:54:49 +01003988
Dave Rodgman920343a2023-10-01 18:41:09 +01003989 # execute all of the commands via Make (probably in parallel)
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01003990 make -s -f ${makefile} build_test_config_combos
3991 echo "$targets targets checked"
Dave Rodgman920343a2023-10-01 18:41:09 +01003992
3993 # clean up the temporary makefile
Dave Rodgman28e38d82023-10-04 11:50:30 +01003994 rm ${makefile}
Dave Rodgman6001fb22023-06-29 09:29:00 +01003995}
3996
Dave Rodgman43a5ce82023-10-02 17:09:37 +01003997validate_aes_config_variations() {
Dave Rodgman920343a2023-10-01 18:41:09 +01003998 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
3999 if [[ "$1" == *"MBEDTLS_PADLOCK_C"* ]]; then
Dave Rodgman41bc7982023-10-16 14:04:21 +01004000 return 1
Dave Rodgman920343a2023-10-01 18:41:09 +01004001 fi
4002 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
4003 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
Dave Rodgman41bc7982023-10-16 14:04:21 +01004004 return 1
Dave Rodgman920343a2023-10-01 18:41:09 +01004005 fi
4006 fi
Dave Rodgman41bc7982023-10-16 14:04:21 +01004007 return 0
Dave Rodgman920343a2023-10-01 18:41:09 +01004008}
4009
4010component_build_aes_variations() {
4011 # 18s - around 90ms per clang invocation on M1 Pro
4012 #
4013 # aes.o has many #if defined(...) guards that intersect in complex ways.
4014 # Test that all the combinations build cleanly.
4015
4016 msg "build: aes.o for all combinations of relevant config options"
4017
Dave Rodgman42436102023-10-03 15:47:05 +01004018 build_test_config_combos library/aes.o validate_aes_config_variations \
Dave Rodgman920343a2023-10-01 18:41:09 +01004019 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
4020 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
4021 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
4022 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
4023}
4024
Gilles Peskine8f073122018-11-27 15:58:47 +01004025component_test_no_platform () {
4026 # Full configuration build, without platform support, file IO and net sockets.
4027 # This should catch missing mbedtls_printf definitions, and by disabling file
4028 # IO, it should catch missing '#include <stdio.h>'
4029 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004030 scripts/config.py full
4031 scripts/config.py unset MBEDTLS_PLATFORM_C
4032 scripts/config.py unset MBEDTLS_NET_C
4033 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
4034 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
4035 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
4036 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskineef843f22022-09-18 14:05:23 +02004037 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004038 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
4039 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskine6497b5a2022-06-30 17:01:40 +02004040 scripts/config.py unset MBEDTLS_PLATFORM_SETBUF_ALT
Gilles Peskine32e889d2020-04-12 23:43:28 +02004041 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004042 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
4043 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004044 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004045 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
4046 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01004047 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
4048 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02004049 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
4050 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01004051}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00004052
Gilles Peskine8f073122018-11-27 15:58:47 +01004053component_build_no_std_function () {
4054 # catch compile bugs in _uninit functions
4055 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004056 scripts/config.py full
4057 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
4058 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02004059 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinef4d2fd42021-10-08 11:45:47 +02004060 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskinedbf7b7e2021-10-07 19:34:57 +02004061 make
Gilles Peskine8f073122018-11-27 15:58:47 +01004062}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01004063
Gilles Peskine8f073122018-11-27 15:58:47 +01004064component_build_no_ssl_srv () {
Ronald Cronde1adee2022-03-07 16:20:30 +01004065 msg "build: full config except SSL server, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004066 scripts/config.py full
4067 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02004068 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01004069}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02004070
Gilles Peskine8f073122018-11-27 15:58:47 +01004071component_build_no_ssl_cli () {
Ronald Cronde1adee2022-03-07 16:20:30 +01004072 msg "build: full config except SSL client, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004073 scripts/config.py full
4074 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02004075 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01004076}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02004077
Gilles Peskine8f073122018-11-27 15:58:47 +01004078component_build_no_sockets () {
4079 # Note, C99 compliance can also be tested with the sockets support disabled,
4080 # as that requires a POSIX platform (which isn't the same as C99).
4081 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004082 scripts/config.py full
4083 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
4084 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02004085 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01004086}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02004087
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04004088component_test_memory_buffer_allocator_backtrace () {
4089 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004090 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4091 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4092 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
4093 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02004094 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04004095 make
4096
4097 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
4098 make test
4099}
4100
4101component_test_memory_buffer_allocator () {
4102 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004103 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4104 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02004105 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Hanno Becker0fb9ba22019-02-26 14:34:13 +00004106 make
4107
4108 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
4109 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01004110
4111 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
4112 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004113 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00004114}
4115
Gilles Peskine8f073122018-11-27 15:58:47 +01004116component_test_no_max_fragment_length () {
4117 # Run max fragment length tests with MFL disabled
4118 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004119 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01004120 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4121 make
Hanno Becker5175ac62017-09-18 15:36:25 +01004122
Gilles Peskine8f073122018-11-27 15:58:47 +01004123 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004124 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01004125}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004126
Hanno Becker545ced42019-02-19 11:10:48 +00004127component_test_asan_remove_peer_certificate () {
4128 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004129 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00004130 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4131 make
4132
4133 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
4134 make test
4135
4136 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004137 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00004138
4139 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004140 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02004141
4142 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004143 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00004144}
4145
Gilles Peskine8f073122018-11-27 15:58:47 +01004146component_test_no_max_fragment_length_small_ssl_out_content_len () {
4147 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004148 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4149 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
4150 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01004151 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4152 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10004153
Gilles Peskine8f073122018-11-27 15:58:47 +01004154 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004155 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02004156
4157 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004158 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01004159}
Angus Grattonc4dd0732018-04-11 16:28:39 +10004160
Darryl Greenaad82f92019-12-02 10:53:11 +00004161component_test_variable_ssl_in_out_buffer_len () {
4162 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
4163 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
4164 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4165 make
4166
4167 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
4168 make test
4169
4170 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004171 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004172
4173 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004174 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004175}
4176
Manuel Pégourié-Gonnard6a543ba2022-11-25 11:30:10 +01004177component_test_dtls_cid_legacy () {
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004178 msg "build: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled (ASan build)"
Hannes Tschofenigfd6cca42021-10-12 09:22:33 +02004179 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 1
Darryl Greenaad82f92019-12-02 10:53:11 +00004180
4181 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4182 make
4183
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004184 msg "test: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy)"
Darryl Greenaad82f92019-12-02 10:53:11 +00004185 make test
4186
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004187 msg "test: ssl-opt.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004188 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004189
Manuel Pégourié-Gonnard6a543ba2022-11-25 11:30:10 +01004190 msg "test: compat.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004191 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004192}
4193
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004194component_test_ssl_alloc_buffer_and_mfl () {
4195 msg "build: default config with memory buffer allocator and MFL extension"
4196 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4197 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4198 scripts/config.py set MBEDTLS_MEMORY_DEBUG
4199 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4200 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02004201 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004202 make
4203
4204 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
4205 make test
4206
4207 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 +02004208 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004209}
4210
Gilles Peskine636c26a2020-03-04 20:46:15 +01004211component_test_when_no_ciphersuites_have_mac () {
4212 msg "build: when no ciphersuites have MAC"
4213 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Gilles Peskine636c26a2020-03-04 20:46:15 +01004214 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
TRodziewicz2add5c12021-04-28 16:50:20 +02004215 scripts/config.py unset MBEDTLS_CMAC_C
Gilles Peskine636c26a2020-03-04 20:46:15 +01004216 make
4217
4218 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
4219 make test
4220
4221 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004222 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01004223}
4224
Raoul Strackxa4e86142020-06-15 17:03:13 +02004225component_test_no_date_time () {
4226 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
4227 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
Gilles Peskinef4d2fd42021-10-08 11:45:47 +02004228 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Raoul Strackxa4e86142020-06-15 17:03:13 +02004229 make
4230
4231 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
4232 make test
4233}
4234
Gilles Peskine8f073122018-11-27 15:58:47 +01004235component_test_platform_calloc_macro () {
4236 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004237 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4238 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
4239 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01004240 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4241 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01004242
Gilles Peskine8f073122018-11-27 15:58:47 +01004243 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
4244 make test
4245}
Hanno Beckere5fecec2018-10-11 11:02:52 +01004246
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02004247component_test_malloc_0_null () {
4248 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004249 scripts/config.py full
Gilles Peskinecf4fe582023-07-20 19:00:15 +02004250 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 +02004251
4252 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
4253 make test
4254
4255 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
4256 # Just the calloc selftest. "make test" ran the others as part of the
4257 # test suites.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004258 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01004259
4260 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
4261 # Run a subset of the tests. The choice is a balance between coverage
4262 # and time (including time indirectly wasted due to flaky tests).
4263 # The current choice is to skip tests whose description includes
4264 # "proxy", which is an approximation of skipping tests that use the
4265 # UDP proxy, which tend to be slower and flakier.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004266 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02004267}
4268
Dave Rodgman6a08b682023-06-19 11:51:33 +01004269support_test_aesni() {
4270 # Check that gcc targets x86_64 (we can build AESNI), and check for
4271 # AESNI support on the host (we can run AESNI).
4272 #
4273 # The name of this function is possibly slightly misleading, but needs to align
4274 # with the name of the corresponding test, component_test_aesni.
Dave Rodgmanf8986e32023-06-19 10:55:59 +01004275 #
4276 # In principle 32-bit x86 can support AESNI, but our implementation does not
4277 # support 32-bit x86, so we check for x86-64.
4278 # We can only grep /proc/cpuinfo on Linux, so this also checks for Linux
Dave Rodgman6a08b682023-06-19 11:51:33 +01004279 (gcc -v 2>&1 | grep Target | grep -q x86_64) &&
4280 [[ "$HOSTTYPE" == "x86_64" && "$OSTYPE" == "linux-gnu" ]] &&
Jerry Yua7de78d2023-08-08 12:57:35 +08004281 (lscpu | grep -qw aes)
Dave Rodgmanf8986e32023-06-19 10:55:59 +01004282}
4283
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004284component_test_aesni () { # ~ 60s
4285 # This tests the two AESNI implementations (intrinsics and assembly), and also the plain C
4286 # fallback. It also tests the logic that is used to select which implementation(s) to build.
4287 #
4288 # This test does not require the host to have support for AESNI (if it doesn't, the run-time
4289 # AESNI detection will fallback to the plain C implementation, so the tests will instead
4290 # exercise the plain C impl).
4291
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004292 msg "build: default config with different AES implementations"
Dave Rodgman838dc462023-06-16 13:18:19 +01004293 scripts/config.py set MBEDTLS_AESNI_C
Jerry Yu17a9d2e2023-08-03 16:14:18 +08004294 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Dave Rodgman838dc462023-06-16 13:18:19 +01004295 scripts/config.py set MBEDTLS_HAVE_ASM
4296
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004297 # test the intrinsics implementation
4298 msg "AES tests, test intrinsics"
Dave Rodgman838dc462023-06-16 13:18:19 +01004299 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004300 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004301 # check that we built intrinsics - this should be used by default when supported by the compiler
Jerry Yu1221a312023-08-03 16:09:07 +08004302 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004303
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004304 # test the asm implementation
4305 msg "AES tests, test assembly"
4306 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004307 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mno-pclmul -mno-sse2 -mno-aes'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004308 # check that we built assembly - this should be built if the compiler does not support intrinsics
Jerry Yu1221a312023-08-03 16:09:07 +08004309 ./programs/test/selftest aes | grep "AESNI code" | grep -q "assembly"
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004310
4311 # test the plain C implementation
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004312 scripts/config.py unset MBEDTLS_AESNI_C
Jerry Yu17a9d2e2023-08-03 16:14:18 +08004313 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004314 msg "AES tests, plain C"
4315 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004316 make CC=gcc CFLAGS='-O2 -Werror'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004317 # check that there is no AESNI code present
Jerry Yu1221a312023-08-03 16:09:07 +08004318 ./programs/test/selftest aes | not grep -q "AESNI code"
Jerry Yu76a51b92023-08-08 16:03:55 +08004319 not grep -q "AES note: using AESNI" ./programs/test/selftest
4320 grep -q "AES note: built-in implementation." ./programs/test/selftest
Jerry Yu8a599c02023-08-03 17:01:02 +08004321
4322 # test the intrinsics implementation
4323 scripts/config.py set MBEDTLS_AESNI_C
4324 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4325 msg "AES tests, test AESNI only"
4326 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004327 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
Jerry Yua7de78d2023-08-08 12:57:35 +08004328 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
4329 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
Jerry Yu76a51b92023-08-08 16:03:55 +08004330 grep -q "AES note: using AESNI" ./programs/test/selftest
4331 not grep -q "AES note: built-in implementation." ./programs/test/selftest
Dave Rodgman838dc462023-06-16 13:18:19 +01004332}
4333
Jerry Yu193cbc02023-08-03 17:06:29 +08004334
Jerry Yub6d39c22023-08-16 15:11:48 +08004335
4336support_test_aesni_m32() {
4337 support_test_m32_o0 && (lscpu | grep -qw aes)
4338}
4339
4340component_test_aesni_m32 () { # ~ 60s
4341 # This tests are duplicated from component_test_aesni for i386 target
4342 #
4343 # AESNI intrinsic code supports i386 and assembly code does not support it.
4344
4345 msg "build: default config with different AES implementations"
4346 scripts/config.py set MBEDTLS_AESNI_C
4347 scripts/config.py set MBEDTLS_PADLOCK_C
4348 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4349 scripts/config.py set MBEDTLS_HAVE_ASM
4350
4351 # test the intrinsics implementation
4352 msg "AES tests, test intrinsics"
4353 make clean
4354 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
4355 # check that we built intrinsics - this should be used by default when supported by the compiler
4356 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
4357 grep -q "AES note: using AESNI" ./programs/test/selftest
4358 grep -q "AES note: built-in implementation." ./programs/test/selftest
4359 grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4360 grep -q mbedtls_aesni_has_support ./programs/test/selftest
4361
4362 scripts/config.py set MBEDTLS_AESNI_C
Jerry Yub6d39c22023-08-16 15:11:48 +08004363 scripts/config.py unset MBEDTLS_PADLOCK_C
4364 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4365 msg "AES tests, test AESNI only"
4366 make clean
4367 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
4368 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
4369 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
4370 grep -q "AES note: using AESNI" ./programs/test/selftest
4371 not grep -q "AES note: built-in implementation." ./programs/test/selftest
4372 not grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4373 not grep -q mbedtls_aesni_has_support ./programs/test/selftest
4374}
4375
Jerry Yu193cbc02023-08-03 17:06:29 +08004376# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
4377component_build_aes_aesce_armcc () {
4378 msg "Build: AESCE test on arm64 platform without plain C."
4379 scripts/config.py baremetal
4380
4381 # armc[56] don't support SHA-512 intrinsics
4382 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
4383
4384 # Stop armclang warning about feature detection for A64_CRYPTO.
4385 # With this enabled, the library does build correctly under armclang,
4386 # but in baremetal builds (as tested here), feature detection is
4387 # unavailable, and the user is notified via a #warning. So enabling
4388 # this feature would prevent us from building with -Werror on
4389 # armclang. Tracked in #7198.
4390 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
4391 scripts/config.py set MBEDTLS_HAVE_ASM
4392
4393 msg "AESCE, build with default configuration."
4394 scripts/config.py set MBEDTLS_AESCE_C
4395 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4396 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
4397
4398 msg "AESCE, build AESCE only"
4399 scripts/config.py set MBEDTLS_AESCE_C
4400 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4401 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
4402}
4403
Jerry Yuc935aa62023-08-03 17:08:27 +08004404# For timebeing, no VIA Padlock platform available.
4405component_build_aes_via_padlock () {
4406
4407 msg "AES:VIA PadLock, build with default configuration."
Jerry Yu506759f2023-08-16 17:11:22 +08004408 scripts/config.py unset MBEDTLS_AESNI_C
Jerry Yuc935aa62023-08-03 17:08:27 +08004409 scripts/config.py set MBEDTLS_PADLOCK_C
4410 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4411 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Jerry Yu506759f2023-08-16 17:11:22 +08004412 grep -q mbedtls_padlock_has_support ./programs/test/selftest
Jerry Yuc935aa62023-08-03 17:08:27 +08004413
4414}
4415
4416support_build_aes_via_padlock_only () {
4417 ( [ "$MBEDTLS_TEST_PLATFORM" == "Linux-x86_64" ] || \
4418 [ "$MBEDTLS_TEST_PLATFORM" == "Linux-amd64" ] ) && \
4419 [ "`dpkg --print-foreign-architectures`" == "i386" ]
4420}
4421
Jerry Yu193cbc02023-08-03 17:06:29 +08004422support_build_aes_aesce_armcc () {
4423 support_build_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +01004424}
4425
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004426component_test_aes_only_128_bit_keys () {
Gilles Peskine8f073122018-11-27 15:58:47 +01004427 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
Hanno Becker83ebf782017-07-07 12:29:15 +01004428 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01004429 scripts/config.py unset MBEDTLS_PADLOCK_C
4430
4431 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01004432
Gilles Peskine8f073122018-11-27 15:58:47 +01004433 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
4434 make test
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004435}
4436
Gilles Peskine8f073122018-11-27 15:58:47 +01004437component_test_no_ctr_drbg_aes_only_128_bit_keys () {
Hanno Becker83ebf782017-07-07 12:29:15 +01004438 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
Gilles Peskine8f073122018-11-27 15:58:47 +01004439 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4440 scripts/config.py unset MBEDTLS_CTR_DRBG_C
4441 scripts/config.py unset MBEDTLS_PADLOCK_C
4442
Gilles Peskine592f5912019-10-07 18:49:32 +02004443 make CC=clang CFLAGS='-Werror -Wall -Wextra'
4444
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004445 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
4446 make test
4447}
Gilles Peskine592f5912019-10-07 18:49:32 +02004448
4449component_test_aes_only_128_bit_keys_have_builtins () {
4450 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4451 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4452 scripts/config.py unset MBEDTLS_PADLOCK_C
4453 scripts/config.py unset MBEDTLS_AESNI_C
4454 scripts/config.py unset MBEDTLS_AESCE_C
4455
4456 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004457
4458 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4459 make test
Gilles Peskine592f5912019-10-07 18:49:32 +02004460
4461 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4462 programs/test/selftest
4463}
4464
4465component_test_aes_fewer_tables () {
4466 msg "build: default config with AES_FEWER_TABLES enabled"
4467 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
4468 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004469
4470 msg "test: AES_FEWER_TABLES"
4471 make test
4472}
Gilles Peskine592f5912019-10-07 18:49:32 +02004473
4474component_test_aes_rom_tables () {
4475 msg "build: default config with AES_ROM_TABLES enabled"
4476 scripts/config.py set MBEDTLS_AES_ROM_TABLES
4477 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
4478
4479 msg "test: AES_ROM_TABLES"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02004480 make test
4481}
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004482
Gilles Peskine004206c2019-10-21 17:11:33 +02004483component_test_aes_fewer_tables_and_rom_tables () {
Gilles Peskinef96aefe2019-07-24 14:58:38 +02004484 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
4485 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
4486 scripts/config.py set MBEDTLS_AES_ROM_TABLES
4487 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
4488
Steven Cooremand57203d2020-07-16 20:28:59 +02004489 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
Ronald Cron32a432a2023-03-28 09:19:04 +02004490 make test
Steven Cooreman753f9732021-03-15 11:38:44 +01004491}
Steven Cooreman6801f082021-02-19 17:21:22 +01004492
Gilles Peskine3587dfd2021-09-20 19:20:04 +02004493component_test_ctr_drbg_aes_256_sha_256 () {
4494 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Ronald Cron17b3afc2020-12-10 18:17:09 +01004495 scripts/config.py full
4496 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4497 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Steven Cooremand57203d2020-07-16 20:28:59 +02004498 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Ronald Cron32a432a2023-03-28 09:19:04 +02004499 make
Steven Cooremand57203d2020-07-16 20:28:59 +02004500
4501 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4502 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01004503}
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004504
Andrzej Kurek232e8f92019-10-03 03:18:01 -04004505component_test_ctr_drbg_aes_128_sha_512 () {
Gilles Peskine56c01612019-07-03 20:43:32 +02004506 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskineca144592021-11-04 12:52:14 +01004507 scripts/config.py full
Gilles Peskine8f073122018-11-27 15:58:47 +01004508 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02004509 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskinecf740502019-07-03 20:43:05 +02004510 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4511 make
4512
4513 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine56c01612019-07-03 20:43:32 +02004514 make test
Gilles Peskinecf740502019-07-03 20:43:05 +02004515}
Gilles Peskineca144592021-11-04 12:52:14 +01004516
Gilles Peskinecf740502019-07-03 20:43:05 +02004517component_test_ctr_drbg_aes_128_sha_256 () {
4518 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskineec10bf12019-09-20 19:56:06 +02004519 scripts/config.py full
4520 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4521 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
4522 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskinee094a182020-04-14 20:08:41 +02004523 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskineec10bf12019-09-20 19:56:06 +02004524 make
4525
4526 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4527 make test
4528}
4529
4530component_test_se_default () {
4531 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
4532 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
4533 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004534
Gilles Peskineec10bf12019-09-20 19:56:06 +02004535 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
4536 make test
4537}
4538
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004539component_test_psa_crypto_drivers () {
Gilles Peskine1997f302023-07-26 18:45:20 +02004540 msg "build: full + test drivers dispatching to builtins"
Gilles Peskineec10bf12019-09-20 19:56:06 +02004541 scripts/config.py full
Gilles Peskine1997f302023-07-26 18:45:20 +02004542 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Gilles Peskineec10bf12019-09-20 19:56:06 +02004543 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
4544 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
4545 loc_cflags="${loc_cflags} -I../tests/include -O2"
4546
4547 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
4548
Gilles Peskine1997f302023-07-26 18:45:20 +02004549 msg "test: full + test drivers dispatching to builtins"
Gilles Peskineec10bf12019-09-20 19:56:06 +02004550 make test
4551}
4552
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02004553component_test_make_shared () {
4554 msg "build/test: make shared" # ~ 40s
4555 make SHARED=1 all check
4556 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004557 programs/test/dlopen_demo.sh
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02004558}
4559
4560component_test_cmake_shared () {
4561 msg "build/test: cmake shared" # ~ 2min
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004562 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
4563 make
Gilles Peskine8f073122018-11-27 15:58:47 +01004564 ldd programs/util/strerror | grep libmbedcrypto
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004565 make test
4566 programs/test/dlopen_demo.sh
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004567}
Gilles Peskine8fd59422019-10-21 17:11:33 +02004568
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004569test_build_opt () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004570 info=$1 cc=$2; shift 2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004571 $cc --version
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004572 for opt in "$@"; do
Gilles Peskine14c3c062018-01-29 21:25:12 +01004573 msg "build/test: $cc $opt, $info" # ~ 30s
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004574 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskine14c3c062018-01-29 21:25:12 +01004575 # We're confident enough in compilers to not run _all_ the tests,
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004576 # but at least run the unit tests. In particular, runs with
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01004577 # optimizations use inline assembly whereas runs with -O0
Gilles Peskine14c3c062018-01-29 21:25:12 +01004578 # skip inline assembly.
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01004579 make test # ~30s
4580 make clean
4581 done
4582}
4583
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004584# For FreeBSD we invoke the function by name so this condition is added
4585# to disable the existing test_clang_opt function for linux.
4586if [[ $(uname) != "Linux" ]]; then
4587 component_test_clang_opt () {
4588 scripts/config.py full
4589 test_build_opt 'full config' clang -O0 -Os -O2
4590 }
4591fi
4592
4593component_test_clang_latest_opt () {
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004594 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004595 test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004596}
4597support_test_clang_latest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004598 type "$CLANG_LATEST" >/dev/null 2>/dev/null
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004599}
4600
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004601component_test_clang_earliest_opt () {
Gilles Peskine878cf602019-01-06 20:50:38 +00004602 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004603 test_build_opt 'full config' "$CLANG_EARLIEST" -O0
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004604}
4605support_test_clang_earliest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004606 type "$CLANG_EARLIEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004607}
4608
4609component_test_gcc_latest_opt () {
4610 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004611 test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004612}
4613support_test_gcc_latest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004614 type "$GCC_LATEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004615}
4616
4617component_test_gcc_earliest_opt () {
4618 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004619 test_build_opt 'full config' "$GCC_EARLIEST" -O0
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004620}
4621support_test_gcc_earliest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004622 type "$GCC_EARLIEST" >/dev/null 2>/dev/null
Gilles Peskine878cf602019-01-06 20:50:38 +00004623}
4624
4625component_build_mbedtls_config_file () {
4626 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
Gilles Peskine2003c2f2022-04-07 20:55:57 +02004627 scripts/config.py -w full_config.h full
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004628 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
4629 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
Gilles Peskine45e680e2022-04-13 23:23:21 +02004630 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskinee10df772022-04-07 21:06:41 +02004631 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
4632 make clean
4633
4634 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
4635 # In the user config, disable one feature (for simplicity, pick a feature
4636 # that nothing else depends on).
4637 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
4638 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
4639 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
4640
4641 rm -f user_config.h full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004642}
4643
Gilles Peskine7d904e72022-04-07 21:59:14 +02004644component_build_psa_config_file () {
4645 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
4646 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
4647 cp "$CRYPTO_CONFIG_H" psa_test_config.h
4648 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
4649 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Gilles Peskine45e680e2022-04-13 23:23:21 +02004650 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine7d904e72022-04-07 21:59:14 +02004651 programs/test/query_compile_time_config MBEDTLS_CMAC_C
4652 make clean
4653
4654 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
4655 # In the user config, disable one feature, which will reflect on the
4656 # mbedtls configuration so we can query it with query_compile_time_config.
4657 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
4658 scripts/config.py unset MBEDTLS_CMAC_C
4659 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
4660 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
4661
4662 rm -f psa_test_config.h psa_user_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004663}
4664
Gilles Peskinedf6e84a2023-02-22 22:09:51 +01004665component_build_psa_alt_headers () {
4666 msg "build: make with PSA alt headers" # ~20s
4667
4668 # Generate alternative versions of the substitutable headers with the
4669 # same content except different include guards.
4670 make -C tests include/alt-extra/psa/crypto_platform_alt.h include/alt-extra/psa/crypto_struct_alt.h
4671
4672 # Build the library and some programs.
4673 # Don't build the fuzzers to avoid having to go through hoops to set
4674 # a correct include path for programs/fuzz/Makefile.
4675 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
4676 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\"'"
4677
4678 # Check that we're getting the alternative include guards and not the
4679 # original include guards.
4680 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
4681 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
4682 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
4683 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
4684}
4685
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004686component_test_m32_o0 () {
Gilles Peskine77f05352021-10-07 19:27:16 +02004687 # Build without optimization, so as to use portable C code (in a 32-bit
4688 # build) and not the i386-specific inline assembly.
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004689 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
4690 scripts/config.py full
Jerry Yubdd96b92023-08-16 17:34:27 +08004691 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004692 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
4693
4694 msg "test: i386, make, gcc -O0 (ASan build)"
4695 make test
4696}
4697support_test_m32_o0 () {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02004698 case $(uname -m) in
Pengyu Lvc92df3b2022-10-21 10:50:26 +00004699 amd64|x86_64) true;;
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004700 *) false;;
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004701 esac
4702}
4703
Gilles Peskineff0aee02021-10-05 09:36:03 +02004704component_test_m32_o2 () {
4705 # Build with optimization, to use the i386 specific inline assembly
4706 # and go faster for tests.
4707 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004708 scripts/config.py full
Jerry Yubdd96b92023-08-16 17:34:27 +08004709 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Gilles Peskineff0aee02021-10-05 09:36:03 +02004710 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004711
Gilles Peskineff0aee02021-10-05 09:36:03 +02004712 msg "test: i386, make, gcc -O2 (ASan build)"
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004713 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01004714
Gilles Peskineff0aee02021-10-05 09:36:03 +02004715 msg "test ssl-opt.sh, i386, make, gcc-O2"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004716 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01004717}
Gilles Peskinecf522222021-10-07 19:25:29 +02004718support_test_m32_o2 () {
Gilles Peskine878cf602019-01-06 20:50:38 +00004719 support_test_m32_o0 "$@"
4720}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004721
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004722component_test_m32_everest () {
4723 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004724 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Jerry Yubdd96b92023-08-16 17:34:27 +08004725 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Gilles Peskine8fd59422019-10-21 17:11:33 +02004726 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004727
4728 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
4729 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01004730
4731 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004732 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01004733
4734 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
4735 # Exclude some symmetric ciphers that are redundant here to gain time.
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02004736 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004737}
4738support_test_m32_everest () {
4739 support_test_m32_o0 "$@"
4740}
4741
Gilles Peskine8f073122018-11-27 15:58:47 +01004742component_test_mx32 () {
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004743 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004744 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02004745 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004746
4747 msg "test: 64-bit ILP32, make, gcc"
4748 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01004749}
Gilles Peskine878cf602019-01-06 20:50:38 +00004750support_test_mx32 () {
4751 case $(uname -m) in
4752 amd64|x86_64) true;;
4753 *) false;;
4754 esac
4755}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004756
Peter Kolbus60c6da22018-12-27 06:59:04 -06004757component_test_min_mpi_window_size () {
4758 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004759 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06004760 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4761 make
4762
4763 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
4764 make test
4765}
4766
Gilles Peskine8f073122018-11-27 15:58:47 +01004767component_test_have_int32 () {
4768 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004769 scripts/config.py unset MBEDTLS_HAVE_ASM
4770 scripts/config.py unset MBEDTLS_AESNI_C
4771 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08004772 scripts/config.py unset MBEDTLS_AESCE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01004773 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02004774
Gilles Peskine8f073122018-11-27 15:58:47 +01004775 msg "test: gcc, force 32-bit bignum limbs"
4776 make test
4777}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01004778
Gilles Peskine8f073122018-11-27 15:58:47 +01004779component_test_have_int64 () {
4780 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004781 scripts/config.py unset MBEDTLS_HAVE_ASM
4782 scripts/config.py unset MBEDTLS_AESNI_C
4783 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08004784 scripts/config.py unset MBEDTLS_AESCE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01004785 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01004786
Gilles Peskine8f073122018-11-27 15:58:47 +01004787 msg "test: gcc, force 64-bit bignum limbs"
4788 make test
4789}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004790
Gabor Mezeie256cc12023-07-26 17:28:48 +02004791component_test_have_int32_cmake_new_bignum () {
4792 msg "build: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
4793 scripts/config.py unset MBEDTLS_HAVE_ASM
4794 scripts/config.py unset MBEDTLS_AESNI_C
4795 scripts/config.py unset MBEDTLS_PADLOCK_C
4796 scripts/config.py unset MBEDTLS_AESCE_C
4797 scripts/config.py set MBEDTLS_TEST_HOOKS
Janos Follath2f045822023-07-31 10:57:16 +01004798 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Janos Follathf3135af2023-07-31 10:07:57 +01004799 make CC=gcc CFLAGS="$ASAN_CFLAGS -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32" LDFLAGS="$ASAN_CFLAGS"
Gabor Mezeie256cc12023-07-26 17:28:48 +02004800
4801 msg "test: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
4802 make test
4803}
4804
Gilles Peskine8f073122018-11-27 15:58:47 +01004805component_test_no_udbl_division () {
4806 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004807 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004808 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01004809 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004810
Gilles Peskine8f073122018-11-27 15:58:47 +01004811 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
4812 make test
4813}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004814
Gilles Peskine8f073122018-11-27 15:58:47 +01004815component_test_no_64bit_multiplication () {
4816 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004817 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004818 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01004819 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004820
Gilles Peskine8f073122018-11-27 15:58:47 +01004821 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
4822 make test
4823}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004824
Gilles Peskine3809f5f2020-11-09 15:40:05 +01004825component_test_no_strings () {
4826 msg "build: no strings" # ~10s
4827 scripts/config.py full
4828 # Disable options that activate a large amount of string constants.
4829 scripts/config.py unset MBEDTLS_DEBUG_C
4830 scripts/config.py unset MBEDTLS_ERROR_C
4831 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
4832 scripts/config.py unset MBEDTLS_VERSION_FEATURES
4833 make CFLAGS='-Werror -Os'
4834
4835 msg "test: no strings" # ~ 10s
4836 make test
4837}
4838
Hanno Beckerc5722d12020-10-09 11:10:42 +01004839component_test_no_x509_info () {
4840 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
4841 scripts/config.pl full
4842 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
4843 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
Gilles Peskineff0aee02021-10-05 09:36:03 +02004844 make CFLAGS='-Werror -O2'
Hanno Beckerc5722d12020-10-09 11:10:42 +01004845
4846 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
4847 make test
4848
4849 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004850 tests/ssl-opt.sh
Hanno Beckerc5722d12020-10-09 11:10:42 +01004851}
4852
Gilles Peskine8f073122018-11-27 15:58:47 +01004853component_build_arm_none_eabi_gcc () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02004854 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004855 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02004856 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 +02004857
Gilles Peskinee36fe812021-09-01 20:00:33 +02004858 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02004859 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01004860}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004861
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004862component_build_arm_linux_gnueabi_gcc_arm5vte () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02004863 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004864 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02004865 # Build for a target platform that's close to what Debian uses
4866 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
Dave Rodgman017a1992022-03-31 14:07:01 +01004867 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004868 # Build everything including programs, see for example
Dave Rodgman017a1992022-03-31 14:07:01 +01004869 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004870 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'
4871
Gilles Peskinee36fe812021-09-01 20:00:33 +02004872 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02004873 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t library/*.o
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004874}
4875support_build_arm_linux_gnueabi_gcc_arm5vte () {
4876 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
4877}
4878
4879component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02004880 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004881 scripts/config.py baremetal
4882 # This is an imperfect substitute for
4883 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnardae505ee2021-07-06 09:44:59 +02004884 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02004885 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 +02004886
Gilles Peskinee36fe812021-09-01 20:00:33 +02004887 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02004888 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02004889}
4890
Gilles Peskine6e2fb862020-04-30 23:00:53 +02004891component_build_arm_none_eabi_gcc_m0plus () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02004892 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
4893 scripts/config.py baremetal_size
Gilles Peskineaeedd742020-09-02 11:03:04 +02004894 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 +02004895
Gilles Peskinee36fe812021-09-01 20:00:33 +02004896 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02004897 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Manuel Pégourié-Gonnard67f80372023-06-06 13:01:18 +02004898 for lib in library/*.a; do
4899 echo "$lib:"
4900 ${ARM_NONE_EABI_GCC_PREFIX}size -t $lib | grep TOTALS
4901 done
Gilles Peskine6e2fb862020-04-30 23:00:53 +02004902}
4903
Gilles Peskine8f073122018-11-27 15:58:47 +01004904component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02004905 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004906 scripts/config.py baremetal
4907 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02004908 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 +01004909 echo "Checking that software 64-bit division is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004910 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01004911}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004912
Gilles Peskine8f073122018-11-27 15:58:47 +01004913component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02004914 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004915 scripts/config.py baremetal
4916 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02004917 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 +01004918 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004919 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01004920}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004921
Dave Rodgman8c315f22023-06-02 10:26:24 -04004922component_build_arm_clang_thumb () {
4923 # ~ 30s
4924
4925 scripts/config.py baremetal
4926
4927 msg "build: clang thumb 2, make"
4928 make clean
4929 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
4930
4931 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
4932 msg "build: clang thumb 1 -O0, make"
4933 make clean
4934 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
4935
4936 msg "build: clang thumb 1 -Os, make"
4937 make clean
4938 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
4939}
4940
Gilles Peskine8f073122018-11-27 15:58:47 +01004941component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02004942 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004943 scripts/config.py baremetal
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00004944 # armc[56] don't support SHA-512 intrinsics
4945 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Dave Rodgman2f386c52023-03-02 13:38:33 +00004946
Dave Rodgman0fddf822023-03-02 15:32:12 +00004947 # Stop armclang warning about feature detection for A64_CRYPTO.
4948 # With this enabled, the library does build correctly under armclang,
4949 # but in baremetal builds (as tested here), feature detection is
4950 # unavailable, and the user is notified via a #warning. So enabling
4951 # this feature would prevent us from building with -Werror on
4952 # armclang. Tracked in #7198.
Dave Rodgman2f386c52023-03-02 13:38:33 +00004953 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
4954
Hanno Beckerf0762e92022-07-15 12:08:19 +01004955 scripts/config.py set MBEDTLS_HAVE_ASM
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00004956
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004957 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02004958
4959 msg "size: ARM Compiler 5"
4960 "$ARMC5_FROMELF" -z library/*.o
4961
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004962 make clean
Andres AG87bb5772016-09-27 15:05:15 +01004963
Dave Rodgmanb45d58b2023-06-02 13:54:00 -04004964 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
Hanno Beckerf0762e92022-07-15 12:08:19 +01004965
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004966 # ARM Compiler 6 - Target ARMv7-A
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01004967 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02004968
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004969 # ARM Compiler 6 - Target ARMv7-M
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01004970 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m"
4971
4972 # ARM Compiler 6 - Target ARMv7-M+DSP
4973 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m+dsp"
Simon Butcher940737f2017-07-23 13:42:36 +02004974
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004975 # ARM Compiler 6 - Target ARMv8-A - AArch32
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01004976 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02004977
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004978 # ARM Compiler 6 - Target ARMv8-M
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01004979 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02004980
Tom Cosgrove6ec39ca2023-06-09 15:34:31 +01004981 # ARM Compiler 6 - Target ARMv8.2-A - AArch64
4982 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
4983
Dave Rodgmanb45d58b2023-06-02 13:54:00 -04004984 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
4985 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
4986
Dave Rodgman99318e62023-05-24 12:27:42 +01004987 # ARM Compiler 6 - Target Cortex-M0
4988 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
Gilles Peskine8f073122018-11-27 15:58:47 +01004989}
Tom Cosgrove6ec39ca2023-06-09 15:34:31 +01004990
Pengyu Lvdf070032023-02-24 16:03:31 +08004991support_build_armcc () {
Pengyu Lvc6298ad2023-03-01 10:31:29 +08004992 armc5_cc="$ARMC5_BIN_DIR/armcc"
4993 armc6_cc="$ARMC6_BIN_DIR/armclang"
4994 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
Pengyu Lvdf070032023-02-24 16:03:31 +08004995}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01004996
Jerry Yu81d5e1f2022-01-27 13:01:01 +08004997component_test_tls13_only () {
4998 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3, without MBEDTLS_SSL_PROTO_TLS1_2"
Ronald Cronc2e110f2022-11-22 09:01:46 +01004999 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Jerry Yuda5af222021-12-24 18:45:45 +08005000 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5001
Gilles Peskine4bb369c2022-10-29 17:44:19 +02005002 msg "test: TLS 1.3 only, all key exchange modes enabled"
5003 make test
Jerry Yubaa49342022-02-15 10:26:40 +08005004
Ronald Cronc3f43b62022-10-17 17:35:32 +02005005 msg "ssl-opt.sh: TLS 1.3 only, all key exchange modes enabled"
5006 tests/ssl-opt.sh
Jerry Yuda5af222021-12-24 18:45:45 +08005007}
5008
Ronald Cronc3f43b62022-10-17 17:35:32 +02005009component_test_tls13_only_psk () {
5010 msg "build: TLS 1.3 only from default, only PSK key exchange mode"
5011 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5012 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
5013 scripts/config.py unset MBEDTLS_ECDH_C
Przemek Stekiel0c231472023-06-14 11:12:45 +02005014 scripts/config.py unset MBEDTLS_DHM_C
Ronald Cronc3f43b62022-10-17 17:35:32 +02005015 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5016 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5017 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5018 scripts/config.py unset MBEDTLS_ECDSA_C
5019 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00005020 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01005021 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Crone3dac4a2022-06-10 17:21:51 +02005022 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5023
Ronald Cronc3f43b62022-10-17 17:35:32 +02005024 msg "test_suite_ssl: TLS 1.3 only, only PSK key exchange mode enabled"
5025 cd tests; ./test_suite_ssl; cd ..
Ronald Crone3dac4a2022-06-10 17:21:51 +02005026
Ronald Cronc3f43b62022-10-17 17:35:32 +02005027 msg "ssl-opt.sh: TLS 1.3 only, only PSK key exchange mode enabled"
5028 tests/ssl-opt.sh
5029}
5030
5031component_test_tls13_only_ephemeral () {
5032 msg "build: TLS 1.3 only from default, only ephemeral key exchange mode"
5033 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5034 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
Xiaokang Qian2dbfeda2022-11-15 10:52:57 +00005035 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005036 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5037
5038 msg "test_suite_ssl: TLS 1.3 only, only ephemeral key exchange mode"
5039 cd tests; ./test_suite_ssl; cd ..
5040
5041 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral key exchange mode"
5042 tests/ssl-opt.sh
5043}
5044
Przemek Stekiela01c2422023-06-13 10:46:48 +02005045component_test_tls13_only_ephemeral_ffdh () {
5046 msg "build: TLS 1.3 only from default, only ephemeral ffdh key exchange mode"
5047 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5048 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
5049 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
Przemek Stekielce05f542023-06-15 16:44:08 +02005050 scripts/config.py unset MBEDTLS_ECDH_C
5051
Przemek Stekiela01c2422023-06-13 10:46:48 +02005052 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5053
5054 msg "test_suite_ssl: TLS 1.3 only, only ephemeral ffdh key exchange mode"
5055 cd tests; ./test_suite_ssl; cd ..
5056
5057 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral ffdh key exchange mode"
5058 tests/ssl-opt.sh
5059}
5060
Ronald Cronc3f43b62022-10-17 17:35:32 +02005061component_test_tls13_only_psk_ephemeral () {
5062 msg "build: TLS 1.3 only from default, only PSK ephemeral key exchange mode"
5063 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5064 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5065 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5066 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5067 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5068 scripts/config.py unset MBEDTLS_ECDSA_C
5069 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00005070 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01005071 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005072 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5073
5074 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral key exchange mode"
5075 cd tests; ./test_suite_ssl; cd ..
5076
5077 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral key exchange mode"
5078 tests/ssl-opt.sh
5079}
5080
Przemek Stekiela01c2422023-06-13 10:46:48 +02005081component_test_tls13_only_psk_ephemeral_ffdh () {
5082 msg "build: TLS 1.3 only from default, only PSK ephemeral ffdh key exchange mode"
5083 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5084 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5085 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5086 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5087 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5088 scripts/config.py unset MBEDTLS_ECDSA_C
5089 scripts/config.py unset MBEDTLS_PKCS1_V21
5090 scripts/config.py unset MBEDTLS_PKCS7_C
5091 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Przemek Stekielce05f542023-06-15 16:44:08 +02005092 scripts/config.py unset MBEDTLS_ECDH_C
Przemek Stekiela01c2422023-06-13 10:46:48 +02005093 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5094
5095 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
5096 cd tests; ./test_suite_ssl; cd ..
5097
5098 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
5099 tests/ssl-opt.sh
5100}
5101
Ronald Cronc3f43b62022-10-17 17:35:32 +02005102component_test_tls13_only_psk_all () {
5103 msg "build: TLS 1.3 only from default, without ephemeral key exchange mode"
5104 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5105 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5106 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5107 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5108 scripts/config.py unset MBEDTLS_ECDSA_C
5109 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00005110 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01005111 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005112 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5113
5114 msg "test_suite_ssl: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
5115 cd tests; ./test_suite_ssl; cd ..
5116
5117 msg "ssl-opt.sh: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
5118 tests/ssl-opt.sh
5119}
5120
5121component_test_tls13_only_ephemeral_all () {
5122 msg "build: TLS 1.3 only from default, without PSK key exchange mode"
5123 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
Ronald Cronc2e110f2022-11-22 09:01:46 +01005124 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005125 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5126
5127 msg "test_suite_ssl: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
5128 cd tests; ./test_suite_ssl; cd ..
5129
5130 msg "ssl-opt.sh: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
5131 tests/ssl-opt.sh
Ronald Crone3dac4a2022-06-10 17:21:51 +02005132}
5133
Ronald Cron6f135e12021-12-08 16:57:54 +01005134component_test_tls13 () {
5135 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
5136 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005137 scripts/config.py set MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
5138 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
Ronald Cronc2e110f2022-11-22 09:01:46 +01005139 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005140 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
5141 make
Ronald Cron6f135e12021-12-08 16:57:54 +01005142 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005143 make test
Ronald Cron6f135e12021-12-08 16:57:54 +01005144 msg "ssl-opt.sh (TLS 1.3)"
Gilles Peskine827dbd92022-02-04 00:30:54 +01005145 tests/ssl-opt.sh
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005146}
5147
Ronald Cron6f135e12021-12-08 16:57:54 +01005148component_test_tls13_no_compatibility_mode () {
5149 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
5150 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005151 scripts/config.py unset MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
5152 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
Ronald Cronc2e110f2022-11-22 09:01:46 +01005153 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Hanno Beckera711f6e2020-05-04 12:03:51 +01005154 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
5155 make
Ronald Cron6f135e12021-12-08 16:57:54 +01005156 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
Hanno Becker6c53ecc2021-08-01 19:20:10 +01005157 make test
Ronald Cron6f135e12021-12-08 16:57:54 +01005158 msg "ssl-opt.sh (TLS 1.3 no compatibility mode)"
Gilles Peskine827dbd92022-02-04 00:30:54 +01005159 tests/ssl-opt.sh
Hanno Becker6c53ecc2021-08-01 19:20:10 +01005160}
5161
Jan Bruckner151f6422023-02-10 12:45:19 +01005162component_test_tls13_only_record_size_limit () {
5163 msg "build: TLS 1.3 only from default, record size limit extension enabled"
5164 scripts/config.py set MBEDTLS_SSL_RECORD_SIZE_LIMIT
5165 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5166
5167 msg "test_suite_ssl: TLS 1.3 only, record size limit extension enabled"
5168 cd tests; ./test_suite_ssl; cd ..
5169
5170 msg "ssl-opt.sh: (TLS 1.3 only, record size limit extension tests only)"
5171 # Both the server and the client will currently abort the handshake when they encounter the
5172 # record size limit extension. There is no way to prevent gnutls-cli from sending the extension
5173 # which makes all G_NEXT_CLI + P_SRV tests fail. Thus, run only the tests for the this extension.
5174 tests/ssl-opt.sh -f "Record Size Limit"
5175}
5176
Gilles Peskine8f073122018-11-27 15:58:47 +01005177component_build_mingw () {
5178 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Jerry Yubdd96b92023-08-16 17:34:27 +08005179 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Andrzej Kurek232e8f92019-10-03 03:18:01 -04005180 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 +00005181
Gilles Peskine8f073122018-11-27 15:58:47 +01005182 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04005183 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 +01005184 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02005185
Gilles Peskine8f073122018-11-27 15:58:47 +01005186 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04005187 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
5188 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 +01005189 make WINDOWS_BUILD=1 clean
5190}
Jaeden Amero117b8a42019-04-17 15:19:26 +01005191support_build_mingw() {
Pengyu Lv51b5f002023-02-24 15:38:52 +08005192 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
5193 [0-5]*|"") false;;
Jaeden Amero117b8a42019-04-17 15:19:26 +01005194 *) true;;
5195 esac
5196}
Simon Butcher91aef332016-11-17 09:20:50 +00005197
Gilles Peskine8f073122018-11-27 15:58:47 +01005198component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005199 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005200 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005201 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
5202 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02005203
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005204 msg "test: main suites (MSan)" # ~ 10s
5205 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005206
Gilles Peskine82b27272019-06-14 18:27:03 +02005207 msg "program demos (MSan)" # ~20s
5208 tests/scripts/run_demos.py
5209
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005210 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005211 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005212
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005213 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005214
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005215 if [ "$MEMORY" -gt 0 ]; then
5216 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005217 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005218 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01005219}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005220
Gilles Peskine69f190e2019-01-10 00:11:42 +01005221component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005222 msg "build: Release (clang)"
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005223 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005224 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
5225 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005226
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005227 msg "test: main suites, Valgrind (default config)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005228 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005229
Gilles Peskine636c26a2020-03-04 20:46:15 +01005230 # Optional parts (slow; currently broken on OS X because programs don't
5231 # seem to receive signals under valgrind on OS X).
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005232 # These optional parts don't run on the CI.
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005233 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005234 msg "test: ssl-opt.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005235 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005236 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005237
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005238 if [ "$MEMORY" -gt 1 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005239 msg "test: compat.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005240 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005241 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02005242
5243 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005244 msg "test: context-info.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005245 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02005246 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01005247}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005248
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005249component_test_valgrind_psa () {
5250 msg "build: Release, full (clang)"
5251 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
5252 scripts/config.py full
5253 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
5254 make
5255
5256 msg "test: main suites, Valgrind (full config)"
5257 make memcheck
5258}
5259
Paul Elliott62dc3922021-11-25 17:29:40 +00005260support_test_cmake_out_of_source () {
5261 distrib_id=""
5262 distrib_ver=""
5263 distrib_ver_minor=""
5264 distrib_ver_major=""
5265
5266 # Attempt to parse lsb-release to find out distribution and version. If not
5267 # found this should fail safe (test is supported).
5268 if [[ -f /etc/lsb-release ]]; then
5269
5270 while read -r lsb_line; do
5271 case "$lsb_line" in
5272 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
5273 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
5274 esac
5275 done < /etc/lsb-release
5276
5277 distrib_ver_major="${distrib_ver%%.*}"
5278 distrib_ver="${distrib_ver#*.}"
5279 distrib_ver_minor="${distrib_ver%%.*}"
5280 fi
5281
5282 # Running the out of source CMake test on Ubuntu 16.04 using more than one
5283 # processor (as the CI does) can create a race condition whereby the build
5284 # fails to see a generated file, despite that file actually having been
5285 # generated. This problem appears to go away with 18.04 or newer, so make
5286 # the out of source tests unsupported on Ubuntu 16.04.
5287 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
5288}
5289
Gilles Peskine8f073122018-11-27 15:58:47 +01005290component_test_cmake_out_of_source () {
David Horstmann862abe22023-09-28 10:42:10 +01005291 # Remove existing generated files so that we use the ones cmake
David Horstmann9f48fff2023-09-27 15:53:54 +01005292 # generates
5293 make neat
5294
Gilles Peskine8f073122018-11-27 15:58:47 +01005295 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01005296 MBEDTLS_ROOT_DIR="$PWD"
5297 mkdir "$OUT_OF_SOURCE_DIR"
5298 cd "$OUT_OF_SOURCE_DIR"
David Horstmann9f48fff2023-09-27 15:53:54 +01005299 # Note: Explicitly generate files as these are turned off in releases
5300 cmake -D CMAKE_BUILD_TYPE:String=Check -D GEN_FILES=ON "$MBEDTLS_ROOT_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01005301 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005302
Gilles Peskine8f073122018-11-27 15:58:47 +01005303 msg "test: cmake 'out-of-source' build"
5304 make test
Gilles Peskinea841c2a2022-04-16 11:31:25 +02005305 # Check that ssl-opt.sh can find the test programs.
Gilles Peskine8f073122018-11-27 15:58:47 +01005306 # Also ensure that there are no error messages such as
5307 # "No such file or directory", which would indicate that some required
5308 # file is missing (ssl-opt.sh tolerates the absence of some files so
5309 # may exit with status 0 but emit errors).
Gilles Peskinea841c2a2022-04-16 11:31:25 +02005310 ./tests/ssl-opt.sh -f 'Default' >ssl-opt.out 2>ssl-opt.err
Gilles Peskine7393ec52022-04-15 22:43:38 +02005311 grep PASS ssl-opt.out
Gilles Peskinef7e956c2020-03-28 18:56:09 +01005312 cat ssl-opt.err >&2
5313 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005314 [ ! -s ssl-opt.err ]
Gilles Peskine7393ec52022-04-15 22:43:38 +02005315 rm ssl-opt.out ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01005316 cd "$MBEDTLS_ROOT_DIR"
5317 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01005318}
Andres AGdc192212016-08-31 17:33:13 +01005319
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005320component_test_cmake_as_subdirectory () {
David Horstmann9f48fff2023-09-27 15:53:54 +01005321 # Remove existing generated files so that we use the ones CMake
5322 # generates
5323 make neat
5324
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005325 msg "build: cmake 'as-subdirectory' build"
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005326 cd programs/test/cmake_subproject
David Horstmann9f48fff2023-09-27 15:53:54 +01005327 # Note: Explicitly generate files as these are turned off in releases
5328 cmake -D GEN_FILES=ON .
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005329 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005330 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005331}
Gilles Peskinea3000992022-02-04 00:21:12 +01005332support_test_cmake_as_subdirectory () {
5333 support_test_cmake_out_of_source
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005334}
5335
Chris Kayd259e342021-03-25 16:03:25 +00005336component_test_cmake_as_package () {
David Horstmann6c979852023-09-28 10:40:22 +01005337 # Remove existing generated files so that we use the ones CMake
5338 # generates
5339 make neat
5340
Chris Kayd259e342021-03-25 16:03:25 +00005341 msg "build: cmake 'as-package' build"
Chris Kayd259e342021-03-25 16:03:25 +00005342 cd programs/test/cmake_package
5343 cmake .
5344 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005345 ./cmake_package
Chris Kayd259e342021-03-25 16:03:25 +00005346}
Gilles Peskinea3000992022-02-04 00:21:12 +01005347support_test_cmake_as_package () {
5348 support_test_cmake_out_of_source
Chris Kayd259e342021-03-25 16:03:25 +00005349}
5350
5351component_test_cmake_as_package_install () {
David Horstmann6c979852023-09-28 10:40:22 +01005352 # Remove existing generated files so that we use the ones CMake
5353 # generates
5354 make neat
5355
Chris Kayd259e342021-03-25 16:03:25 +00005356 msg "build: cmake 'as-installed-package' build"
Chris Kayd259e342021-03-25 16:03:25 +00005357 cd programs/test/cmake_package_install
5358 cmake .
5359 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005360 ./cmake_package_install
Chris Kayd259e342021-03-25 16:03:25 +00005361}
Gilles Peskinea3000992022-02-04 00:21:12 +01005362support_test_cmake_as_package_install () {
5363 support_test_cmake_out_of_source
Chris Kayd259e342021-03-25 16:03:25 +00005364}
5365
David Horstmann20550e32023-01-12 14:17:01 +00005366component_build_cmake_custom_config_file () {
David Horstmann969c1452023-01-31 10:34:44 +00005367 # Make a copy of config file to use for the in-tree test
5368 cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h
David Horstmann20550e32023-01-12 14:17:01 +00005369
5370 MBEDTLS_ROOT_DIR="$PWD"
5371 mkdir "$OUT_OF_SOURCE_DIR"
5372 cd "$OUT_OF_SOURCE_DIR"
5373
David Horstmann969c1452023-01-31 10:34:44 +00005374 # Build once to get the generated files (which need an intact config file)
David Horstmann20550e32023-01-12 14:17:01 +00005375 cmake "$MBEDTLS_ROOT_DIR"
5376 make
5377
5378 msg "build: cmake with -DMBEDTLS_CONFIG_FILE"
5379 scripts/config.py -w full_config.h full
David Horstmann969c1452023-01-31 10:34:44 +00005380 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005381 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR"
5382 make
5383
5384 msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
5385 # In the user config, disable one feature (for simplicity, pick a feature
5386 # that nothing else depends on).
5387 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
5388
5389 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR"
5390 make
5391 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5392
5393 rm -f user_config.h full_config.h
5394
5395 cd "$MBEDTLS_ROOT_DIR"
5396 rm -rf "$OUT_OF_SOURCE_DIR"
5397
5398 # Now repeat the test for an in-tree build:
5399
David Horstmann969c1452023-01-31 10:34:44 +00005400 # Restore config for the in-tree test
5401 mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005402
David Horstmann969c1452023-01-31 10:34:44 +00005403 # Build once to get the generated files (which need an intact config)
David Horstmann20550e32023-01-12 14:17:01 +00005404 cmake .
5405 make
5406
5407 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE"
5408 scripts/config.py -w full_config.h full
David Horstmann969c1452023-01-31 10:34:44 +00005409 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005410 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h .
5411 make
5412
5413 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
5414 # In the user config, disable one feature (for simplicity, pick a feature
5415 # that nothing else depends on).
5416 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
5417
5418 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h .
5419 make
5420 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5421
5422 rm -f user_config.h full_config.h
5423}
5424support_build_cmake_custom_config_file () {
5425 support_test_cmake_out_of_source
5426}
5427
5428
Tom Cosgrovedaddf112023-09-01 10:40:15 +01005429component_build_zeroize_checks () {
5430 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
5431
5432 scripts/config.py full
5433
5434 # Only compile - we're looking for sizeof-pointer-memaccess warnings
Tom Cosgroveb2fafa52023-09-01 14:40:21 +01005435 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 +01005436}
5437
5438
Gilles Peskine8f073122018-11-27 15:58:47 +01005439component_test_zeroize () {
5440 # Test that the function mbedtls_platform_zeroize() is not optimized away by
5441 # different combinations of compilers and optimization flags by using an
5442 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
5443 # system in all cases that the script fails, so we must manually search the
5444 # output to check whether the pass string is present and no failure strings
5445 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01005446
Gilles Peskine4976e822019-01-06 19:52:22 +00005447 # Don't try to disable ASLR. We don't care about ASLR here. We do care
5448 # about a spurious message if Gdb tries and fails, so suppress that.
5449 gdb_disable_aslr=
5450 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
5451 gdb_disable_aslr='set disable-randomization off'
5452 fi
5453
Gilles Peskine8f073122018-11-27 15:58:47 +01005454 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01005455 for compiler in clang gcc; do
5456 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
5457 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005458 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
5459 grep "The buffer was correctly zeroized" test_zeroize.log
5460 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01005461 rm -f test_zeroize.log
5462 make clean
5463 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01005464 done
Gilles Peskine8f073122018-11-27 15:58:47 +01005465}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005466
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005467component_test_psa_compliance () {
5468 msg "build: make, default config (out-of-box), libmbedcrypto.a only"
Bence Szépkútica9236b2021-10-25 19:29:07 +02005469 make -C library libmbedcrypto.a
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005470
5471 msg "unit test: test_psa_compliance.py"
5472 ./tests/scripts/test_psa_compliance.py
5473}
5474
5475support_test_psa_compliance () {
Bence Szépkútief0d02e2021-11-03 11:36:09 +01005476 # psa-compliance-tests only supports CMake >= 3.10.0
Bence Szépkútica9236b2021-10-25 19:29:07 +02005477 ver="$(cmake --version)"
5478 ver="${ver#cmake version }"
5479 ver_major="${ver%%.*}"
5480
5481 ver="${ver#*.}"
5482 ver_minor="${ver%%.*}"
5483
5484 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005485}
5486
Gilles Peskinec848d222022-12-09 12:23:35 +01005487component_check_code_style () {
5488 msg "Check C code style"
5489 ./scripts/code_style.py
David Horstmann92b5ac12022-11-10 18:30:52 +00005490}
5491
Gilles Peskinec848d222022-12-09 12:23:35 +01005492support_check_code_style() {
David Horstmann92b5ac12022-11-10 18:30:52 +00005493 case $(uncrustify --version) in
5494 *0.75.1*) true;;
5495 *) false;;
5496 esac
5497}
5498
Gilles Peskine8f073122018-11-27 15:58:47 +01005499component_check_python_files () {
5500 msg "Lint: Python scripts"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005501 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01005502}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005503
Joe Subbianid614c0b2021-07-29 11:18:29 +01005504component_check_test_helpers () {
5505 msg "unit test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02005506 # unittest writes out mundane stuff like number or tests run on stderr.
5507 # Our convention is to reserve stderr for actual errors, and write
5508 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005509 ./tests/scripts/test_generate_test_code.py 2>&1
Joe Subbianid614c0b2021-07-29 11:18:29 +01005510
Joe Subbiania25ffab2021-08-06 09:41:27 +01005511 msg "unit test: translate_ciphers.py"
5512 python3 -m unittest tests/scripts/translate_ciphers.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01005513}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005514
Jerry Yud767cc42023-03-31 15:03:55 +08005515
Gilles Peskine192c72f2017-12-21 15:59:21 +01005516################################################################
5517#### Termination
5518################################################################
5519
Gilles Peskine8f073122018-11-27 15:58:47 +01005520post_report () {
5521 msg "Done, cleaning up"
Gilles Peskinef83eb822020-03-30 20:11:39 +02005522 final_cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005523
Gilles Peskine8f073122018-11-27 15:58:47 +01005524 final_report
5525}
5526
5527
5528
5529################################################################
5530#### Run all the things
5531################################################################
5532
Gilles Peskine5d996822020-03-28 21:09:21 +01005533# Function invoked by --error-test to test error reporting.
5534pseudo_component_error_test () {
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005535 msg "Testing error reporting $error_test_i"
Gilles Peskine5d996822020-03-28 21:09:21 +01005536 if [ $KEEP_GOING -ne 0 ]; then
5537 echo "Expect three failing commands."
5538 fi
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005539 # If the component doesn't run in a subshell, changing error_test_i to an
5540 # invalid integer will cause an error in the loop that runs this function.
5541 error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
Gilles Peskineec135542021-08-02 23:14:03 +02005542 # Expected error: 'grep non_existent /dev/null -> 1'
Gilles Peskine5d996822020-03-28 21:09:21 +01005543 grep non_existent /dev/null
Gilles Peskineec135542021-08-02 23:14:03 +02005544 # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
Gilles Peskine5d996822020-03-28 21:09:21 +01005545 not grep -q . "$0"
Gilles Peskineec135542021-08-02 23:14:03 +02005546 # Expected error: 'make unknown_target -> 2'
Gilles Peskine5d996822020-03-28 21:09:21 +01005547 make unknown_target
5548 false "this should not be executed"
5549}
5550
Gilles Peskinee48351a2018-11-27 16:06:30 +01005551# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01005552run_component () {
Gilles Peskineffcdeff2018-12-04 12:49:28 +01005553 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02005554 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005555
5556 # Unconditionally create a seedfile that's sufficiently long.
5557 # Do this before each component, because a previous component may
5558 # have messed it up or shortened it.
Gilles Peskine88a07452021-07-08 19:03:50 +02005559 local dd_cmd
5560 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
5561 case $OSTYPE in
Tom Cosgrove226aca12022-03-16 14:11:07 +00005562 linux*|freebsd*|openbsd*) dd_cmd+=(status=none)
Gilles Peskine88a07452021-07-08 19:03:50 +02005563 esac
5564 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005565
Gilles Peskineec135542021-08-02 23:14:03 +02005566 # Run the component in a subshell, with error trapping and output
5567 # redirection set up based on the relevant options.
Gilles Peskinece266c42020-03-28 18:50:43 +01005568 if [ $KEEP_GOING -eq 1 ]; then
Gilles Peskineec135542021-08-02 23:14:03 +02005569 # We want to keep running if the subshell fails, so 'set -e' must
5570 # be off when the subshell runs.
Gilles Peskinece266c42020-03-28 18:50:43 +01005571 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02005572 fi
Gilles Peskinece266c42020-03-28 18:50:43 +01005573 (
5574 if [ $QUIET -eq 1 ]; then
5575 # msg() will be silenced, so just print the component name here.
5576 echo "${current_component#component_}"
5577 exec >/dev/null
5578 fi
5579 if [ $KEEP_GOING -eq 1 ]; then
5580 # Keep "set -e" off, and run an ERR trap instead to record failures.
5581 set -E
5582 trap err_trap ERR
5583 fi
5584 # The next line is what runs the component
5585 "$@"
5586 if [ $KEEP_GOING -eq 1 ]; then
5587 trap - ERR
5588 exit $last_failure_status
5589 fi
5590 )
5591 component_status=$?
5592 if [ $KEEP_GOING -eq 1 ]; then
5593 set -e
5594 if [ $component_status -ne 0 ]; then
5595 failure_count=$((failure_count + 1))
5596 fi
5597 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005598
5599 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01005600 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02005601 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01005602}
5603
5604# Preliminary setup
5605pre_check_environment
Tom Cosgrove730addc2023-06-09 14:20:18 +01005606pre_parse_command_line_for_dirs "$@"
Gilles Peskine8f073122018-11-27 15:58:47 +01005607pre_initialize_variables
5608pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01005609
Gilles Peskine878cf602019-01-06 20:50:38 +00005610pre_check_git
Gilles Peskine568f53a2021-07-12 18:16:01 +02005611pre_restore_files
Gilles Peskinef83eb822020-03-30 20:11:39 +02005612pre_back_up
Andrzej Kurekeb508712019-02-14 07:18:59 -05005613
Gilles Peskine878cf602019-01-06 20:50:38 +00005614build_status=0
5615if [ $KEEP_GOING -eq 1 ]; then
5616 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01005617fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02005618pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00005619pre_print_configuration
5620pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005621cleanup
David Horstmann76a77382023-08-17 17:32:26 +01005622if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +01005623 pre_generate_files
5624fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005625
Gilles Peskinebeb3a812019-01-06 22:11:25 +00005626# Run the requested tests.
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005627for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
Gilles Peskine5d996822020-03-28 21:09:21 +01005628 run_component pseudo_component_error_test
Gilles Peskine5d996822020-03-28 21:09:21 +01005629done
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005630unset error_test_i
Gilles Peskinebeb3a812019-01-06 22:11:25 +00005631for component in $RUN_COMPONENTS; do
5632 run_component "component_$component"
5633done
Gilles Peskine8f073122018-11-27 15:58:47 +01005634
5635# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00005636post_report