blob: eb12a89d7471d10c0663a114ab29e3d5f4527643 [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
Valerio Settib680fc42023-10-13 09:29:37 +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"
Yanray Wang0df6d962023-10-11 13:27:25 +0800867# 3b. Call helper_libtestdriver1_make_main "$loc_accel_list". Any
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200868# 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é-Gonnard2336c8e2023-06-12 17:17:54 +0200886 # Dynamic secure element support is a deprecated feature and needs to be disabled here.
887 # This is done to have the same form of psa_key_attributes_s for libdriver and library.
888 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200889}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100890
Valerio Settib2fd6732023-08-15 17:10:47 +0200891# When called with no parameter this function disables all builtin curves.
Valerio Setti4ca250b2023-09-04 14:01:41 +0200892# The function optionally accepts 1 parameter: a space-separated list of the
893# curves that should be kept enabled.
Valerio Settib2fd6732023-08-15 17:10:47 +0200894helper_disable_builtin_curves() {
895 allowed_list="${1:-}"
896 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
897
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200898 for curve in $allowed_list; do
899 scripts/config.py set $curve
Valerio Settib2fd6732023-08-15 17:10:47 +0200900 done
901}
902
903# Helper returning the list of supported elliptic curves from CRYPTO_CONFIG_H,
904# without the "PSA_WANT_" prefix. This becomes handy for accelerating curves
905# in the following helpers.
906helper_get_psa_curve_list () {
907 loc_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200908 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
909 loc_list="$loc_list $item"
Valerio Settib2fd6732023-08-15 17:10:47 +0200910 done
911
912 echo "$loc_list"
913}
914
915# Get the list of uncommented PSA_WANT_KEY_TYPE_xxx_ from CRYPTO_CONFIG_H. This
Valerio Setti0a342c92023-09-01 09:12:31 +0200916# is useful to easily get a list of key type symbols to accelerate.
Valerio Settib2fd6732023-08-15 17:10:47 +0200917# The function accepts a single argument which is the key type: ECC, DH, RSA.
Valerio Setti0a342c92023-09-01 09:12:31 +0200918helper_get_psa_key_type_list() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200919 key_type="$1"
Valerio Settib2fd6732023-08-15 17:10:47 +0200920 loc_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200921 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 +0200922 # Skip DERIVE for elliptic keys since there is no driver dispatch for
923 # it so it cannot be accelerated.
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200924 if [ "$item" != "KEY_TYPE_ECC_KEY_PAIR_DERIVE" ]; then
925 loc_list="$loc_list $item"
Valerio Settib2fd6732023-08-15 17:10:47 +0200926 fi
927 done
928
929 echo "$loc_list"
930}
931
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +0200932# Build the drivers library libtestdriver1.a (with ASan).
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +0200933#
934# Parameters:
935# 1. a space-separated list of things to accelerate;
936# 2. optional: a space-separate list of things to also support.
937# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
938helper_libtestdriver1_make_drivers() {
939 loc_accel_flags=$( echo "$1 ${2-}" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
940 make -C tests libtestdriver1.a CFLAGS=" $ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
941}
942
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +0200943# Build the main libraries, programs and tests,
944# linking to the drivers library (with ASan).
945#
946# Parameters:
947# 1. a space-separated list of things to accelerate;
948# *. remaining arguments if any are passed directly to make
949# (examples: lib, -C tests test_suite_xxx, etc.)
950# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
951helper_libtestdriver1_make_main() {
952 loc_accel_list=$1
953 shift
954
955 # we need flags both with and without the LIBTESTDRIVER1_ prefix
956 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
957 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
958 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" "$@"
959}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100960
961################################################################
962#### Basic checks
963################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100964
965#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200966# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100967#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100968# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200969# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100970# 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 +0200971# time, so start with a GCC build).
972# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100973#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100974# Indicative running times are given for reference.
975
Gilles Peskine8f073122018-11-27 15:58:47 +0100976component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200977 msg "Check: recursion.pl" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200978 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100979}
Janos Follathb72c6782016-07-19 14:54:17 +0100980
Gilles Peskine67debb62021-05-18 16:09:50 +0200981component_check_generated_files () {
982 msg "Check: check-generated-files, files generated with make" # 2s
983 make generated_files
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200984 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200985
986 msg "Check: check-generated-files -u, files present" # 2s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200987 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +0200988 # Check that the generated files are considered up to date.
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 absent" # 2s
992 command make neat
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200993 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +0200994 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200995 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200996
997 # This component ends with the generated files present in the source tree.
998 # This is necessary for subsequent components!
999}
1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001001component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001002 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001003 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001004}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001005
Gilles Peskine8f073122018-11-27 15:58:47 +01001006component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001007 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001008 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +01001009}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001010
Gilles Peskine30e0bb42020-05-10 17:40:49 +02001011component_check_changelog () {
1012 msg "Check: changelog entries" # < 1s
1013 rm -f ChangeLog.new
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001014 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +02001015 if [ -e ChangeLog.new ]; then
1016 # Show the diff for information. It isn't an error if the diff is
1017 # non-empty.
1018 diff -u ChangeLog ChangeLog.new || true
1019 rm ChangeLog.new
1020 fi
1021}
1022
Gilles Peskine8f073122018-11-27 15:58:47 +01001023component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001024 msg "Check: declared and exported names (builds the library)" # < 3s
Yuto Takanoc3a6f632021-09-24 18:02:56 +01001025 tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +01001026}
Darryl Greena07039c2018-03-13 16:48:16 +00001027
Gilles Peskine895868b2019-09-19 21:30:05 +02001028component_check_test_cases () {
1029 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001030 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001031 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001032 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001033 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001034 fi
Gilles Peskine031114d2022-12-15 14:46:31 +01001035 tests/scripts/check_test_cases.py -q $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001036 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +02001037}
1038
Gilles Peskine8f073122018-11-27 15:58:47 +01001039component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001040 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001041 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001042}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001043
Gilles Peskine192c72f2017-12-21 15:59:21 +01001044
Gilles Peskine636c26a2020-03-04 20:46:15 +01001045
Gilles Peskine192c72f2017-12-21 15:59:21 +01001046################################################################
1047#### Build and test many configurations and targets
1048################################################################
1049
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001050component_test_default_out_of_box () {
1051 msg "build: make, default config (out-of-box)" # ~1min
1052 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02001053 # Disable fancy stuff
1054 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001055
1056 msg "test: main suites make, default config (out-of-box)" # ~10s
1057 make test
1058
1059 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001060 programs/test/selftest
Gilles Peskine82b27272019-06-14 18:27:03 +02001061
1062 msg "program demos: make, default config (out-of-box)" # ~10s
1063 tests/scripts/run_demos.py
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001064}
1065
Gilles Peskine8f073122018-11-27 15:58:47 +01001066component_test_default_cmake_gcc_asan () {
1067 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +01001068 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1069 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001070
Gilles Peskine8f073122018-11-27 15:58:47 +01001071 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
1072 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001073
Gilles Peskine82b27272019-06-14 18:27:03 +02001074 msg "program demos (ASan build)" # ~10s
1075 tests/scripts/run_demos.py
1076
Gilles Peskine97bea012020-04-23 23:37:45 +02001077 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001078 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +02001079
Gilles Peskine8f073122018-11-27 15:58:47 +01001080 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001081 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001082
Gilles Peskine8f073122018-11-27 15:58:47 +01001083 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001084 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001085
1086 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001087 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001088}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001089
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001090component_test_default_cmake_gcc_asan_new_bignum () {
1091 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Janos Follath2f045822023-07-31 10:57:16 +01001092 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001093 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Janos Follath82823b22023-07-27 12:25:05 +01001094 make
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001095
1096 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
1097 make test
1098
1099 msg "test: selftest (ASan build)" # ~ 10s
1100 programs/test/selftest
1101
1102 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
1103 tests/ssl-opt.sh
1104
1105 msg "test: compat.sh (ASan build)" # ~ 6 min
1106 tests/compat.sh
1107
1108 msg "test: context-info.sh (ASan build)" # ~ 15 sec
1109 tests/context-info.sh
1110}
1111
Hanno Becker01635512019-02-26 14:27:09 +00001112component_test_full_cmake_gcc_asan () {
1113 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001114 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +00001115 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1116 make
1117
1118 msg "test: main suites (inc. selftests) (full config, ASan build)"
1119 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01001120
Gilles Peskine97bea012020-04-23 23:37:45 +02001121 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001122 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +02001123
Gilles Peskine636c26a2020-03-04 20:46:15 +01001124 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001125 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001126
1127 msg "test: compat.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001128 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001129
1130 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001131 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001132}
1133
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001134
1135component_test_full_cmake_gcc_asan_new_bignum () {
1136 msg "build: full config, cmake, gcc, ASan"
1137 scripts/config.py full
Janos Follath2f045822023-07-31 10:57:16 +01001138 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001139 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Janos Follath82823b22023-07-27 12:25:05 +01001140 make
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001141
1142 msg "test: main suites (inc. selftests) (full config, ASan build)"
1143 make test
1144
1145 msg "test: selftest (ASan build)" # ~ 10s
1146 programs/test/selftest
1147
1148 msg "test: ssl-opt.sh (full config, ASan build)"
1149 tests/ssl-opt.sh
1150
1151 msg "test: compat.sh (full config, ASan build)"
1152 tests/compat.sh
1153
1154 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
1155 tests/context-info.sh
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001156}
1157
Ronald Cronc3623db2020-10-29 10:51:32 +01001158component_test_psa_crypto_key_id_encodes_owner () {
Andrzej Kurek03e01462022-01-03 12:53:24 +01001159 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
Ronald Cronc3623db2020-10-29 10:51:32 +01001160 scripts/config.py full
Ronald Cronc3623db2020-10-29 10:51:32 +01001161 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1162 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1163 make
1164
1165 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
1166 make test
1167}
1168
Gilles Peskinea3548672021-06-17 11:37:52 +02001169# check_renamed_symbols HEADER LIB
1170# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
1171# name is LIB.
1172check_renamed_symbols () {
1173 ! nm "$2" | sed 's/.* //' |
1174 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
1175}
1176
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001177component_build_psa_crypto_spm () {
Andrzej Kurek03e01462022-01-03 12:53:24 +01001178 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001179 scripts/config.py full
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001180 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
1181 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1182 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
1183 # We can only compile, not link, since our test and sample programs
1184 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
1185 # is active.
1186 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskinea3548672021-06-17 11:37:52 +02001187
1188 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
1189 # version is not present.
1190 echo "Checking for renamed symbols in the library"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001191 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001192}
1193
Ronald Cron336678b2021-01-28 17:54:24 +01001194component_test_psa_crypto_client () {
1195 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
1196 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1197 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1198 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
Raef Colesb4568c52022-09-28 17:11:42 +01001199 scripts/config.py unset MBEDTLS_LMS_C
1200 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Ronald Cron336678b2021-01-28 17:54:24 +01001201 make
1202
1203 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
1204 make test
1205}
1206
Jaeden Amero424fa932021-05-14 08:34:32 +01001207component_test_psa_crypto_rsa_no_genprime() {
1208 msg "build: default config minus MBEDTLS_GENPRIME"
1209 scripts/config.py unset MBEDTLS_GENPRIME
1210 make
1211
1212 msg "test: default config minus MBEDTLS_GENPRIME"
1213 make test
1214}
1215
Gilles Peskine782f4112018-11-27 16:11:09 +01001216component_test_ref_configs () {
1217 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Manuel Pégourié-Gonnard9327fb32021-09-09 11:46:25 +02001218 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
1219 # want to re-generate generated files that depend on it, quite correctly.
1220 # However this doesn't work as the generation script expects a specific
1221 # format for mbedtls_config.h, which the other files don't follow. Also,
1222 # cmake can't know this, but re-generation is actually not necessary as
David Horstmannd64f4b22021-10-20 12:29:47 +01001223 # the generated files only depend on the list of available options, not
Manuel Pégourié-Gonnard9327fb32021-09-09 11:46:25 +02001224 # whether they're on or off. So, disable cmake's (over-sensitive here)
1225 # dependency resolution for generated files and just rely on them being
David Horstmanna8d14062021-10-20 17:14:23 +01001226 # present (thanks to pre_generate_files) by turning GEN_FILES off.
1227 CC=gcc cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001228 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +01001229}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001230
Gilles Peskine8f073122018-11-27 15:58:47 +01001231component_test_no_renegotiation () {
1232 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001233 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001234 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1235 make
Simon Butcher3ea7f522016-03-07 23:22:10 +00001236
Gilles Peskine8f073122018-11-27 15:58:47 +01001237 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1238 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +01001239
Gilles Peskine8f073122018-11-27 15:58:47 +01001240 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001241 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001242}
Hanno Becker134c2ab2017-10-12 15:29:50 +01001243
Gilles Peskine636c26a2020-03-04 20:46:15 +01001244component_test_no_pem_no_fs () {
1245 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1246 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1247 scripts/config.py unset MBEDTLS_FS_IO
1248 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1249 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
1250 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1251 make
1252
1253 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1254 make test
1255
1256 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001257 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001258}
1259
Gilles Peskine8f073122018-11-27 15:58:47 +01001260component_test_rsa_no_crt () {
1261 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001262 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +01001263 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1264 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +01001265
Gilles Peskine8f073122018-11-27 15:58:47 +01001266 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1267 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001268
Gilles Peskine8f073122018-11-27 15:58:47 +01001269 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001270 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001271
Gilles Peskine8f073122018-11-27 15:58:47 +01001272 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001273 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001274
1275 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001276 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001277}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001278
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001279component_test_no_ctr_drbg_classic () {
1280 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001281 scripts/config.py full
1282 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001283 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001284 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001285
1286 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1287 make
1288
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001289 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001290 make test
1291
Gilles Peskineba749042021-01-13 20:02:03 +01001292 # In this configuration, the TLS test programs use HMAC_DRBG.
1293 # The SSL tests are slow, so run a small subset, just enough to get
1294 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001295 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001296 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001297
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001298 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001299 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001300}
1301
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001302component_test_no_ctr_drbg_use_psa () {
1303 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001304 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001305 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1306 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001307
1308 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1309 make
1310
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001311 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1312 make test
1313
1314 # In this configuration, the TLS test programs use HMAC_DRBG.
1315 # The SSL tests are slow, so run a small subset, just enough to get
1316 # confidence that the SSL code copes with HMAC_DRBG.
1317 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001318 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001319
1320 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001321 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001322}
1323
1324component_test_no_hmac_drbg_classic () {
1325 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1326 scripts/config.py full
1327 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1328 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1329 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001330 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001331
1332 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1333 make
1334
1335 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001336 make test
1337
Gilles Peskinea2224342020-11-19 22:14:34 +01001338 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1339 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1340 # instead.
1341 # Test SSL with non-deterministic ECDSA. Only test features that
1342 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001343 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001344 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001345
1346 # To save time, only test one protocol version, since this part of
1347 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001348 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001349 tests/compat.sh -m tls12 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001350}
1351
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001352component_test_no_hmac_drbg_use_psa () {
1353 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1354 scripts/config.py full
1355 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1356 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1357 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1358
1359 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1360 make
1361
1362 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1363 make test
1364
1365 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1366 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1367 # instead.
1368 # Test SSL with non-deterministic ECDSA. Only test features that
1369 # might be affected by how ECDSA signature is performed.
1370 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001371 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001372
1373 # To save time, only test one protocol version, since this part of
1374 # the protocol is identical in (D)TLS up to 1.2.
1375 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001376 tests/compat.sh -m tls12 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001377}
1378
1379component_test_psa_external_rng_no_drbg_classic () {
1380 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1381 scripts/config.py full
1382 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001383 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001384 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001385 scripts/config.py unset MBEDTLS_ENTROPY_C
1386 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1387 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001388 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1389 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1390 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001391 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1392 # the SSL test programs don't have an RNG and can't work. Explicitly
1393 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1394 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001395
1396 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1397 make test
1398
Gilles Peskine8eb29432021-02-03 20:07:11 +01001399 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001400 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001401}
1402
1403component_test_psa_external_rng_no_drbg_use_psa () {
1404 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001405 scripts/config.py full
1406 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001407 scripts/config.py unset MBEDTLS_ENTROPY_C
1408 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1409 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001410 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1411 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1412 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskinec109b372020-11-23 17:39:04 +01001413 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1414
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001415 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001416 make test
1417
Gilles Peskine8eb29432021-02-03 20:07:11 +01001418 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001419 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001420}
1421
Gilles Peskine4bdb2542023-04-28 19:25:25 +02001422component_test_psa_external_rng_use_psa_crypto () {
1423 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1424 scripts/config.py full
1425 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1426 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1427 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1428 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1429
1430 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1431 make test
1432
1433 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1434 tests/ssl-opt.sh -f 'Default\|opaque'
1435}
1436
Gilles Peskine801c4332023-04-28 21:04:28 +02001437component_test_psa_inject_entropy () {
1438 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
1439 scripts/config.py full
1440 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
1441 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
1442 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1443 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1444 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
1445 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
1446 make CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
1447
1448 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
1449 make test
1450}
1451
Andrzej Kurek06969fc2023-04-12 10:34:50 -04001452component_test_sw_inet_pton () {
1453 msg "build: default plus MBEDTLS_TEST_SW_INET_PTON"
1454
1455 # MBEDTLS_TEST_HOOKS required for x509_crt_parse_cn_inet_pton
1456 scripts/config.py set MBEDTLS_TEST_HOOKS
1457 make CFLAGS="-DMBEDTLS_TEST_SW_INET_PTON"
1458
1459 msg "test: default plus MBEDTLS_TEST_SW_INET_PTON"
1460 make test
1461}
1462
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001463component_test_crypto_full_md_light_only () {
1464 msg "build: crypto_full with only the light subset of MD"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001465 scripts/config.py crypto_full
Gilles Peskine884b4622023-07-20 20:11:51 +02001466 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001467 # Disable MD
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001468 scripts/config.py unset MBEDTLS_MD_C
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001469 # Disable direct dependencies of MD_C
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001470 scripts/config.py unset MBEDTLS_HKDF_C
1471 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
Nick Child89e82e12022-11-09 10:36:10 -06001472 scripts/config.py unset MBEDTLS_PKCS7_C
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001473 # Disable indirect dependencies of MD_C
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001474 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001475 # Disable things that would auto-enable MD_C
1476 scripts/config.py unset MBEDTLS_PKCS5_C
1477
Manuel Pégourié-Gonnard1b5ffc62023-03-14 10:11:20 +01001478 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
1479 # which we haven't disabled, so no need to explicitly enable it.
1480 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001481
Manuel Pégourié-Gonnard0d415212023-02-23 13:02:13 +01001482 # Make sure we don't have the HMAC functions, but the hashing functions
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001483 not grep mbedtls_md_hmac library/md.o
Manuel Pégourié-Gonnard0d415212023-02-23 13:02:13 +01001484 grep mbedtls_md library/md.o
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001485
1486 msg "test: crypto_full with only the light subset of MD"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001487 make test
1488}
1489
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001490component_test_full_no_cipher () {
Valerio Settidf17a102023-10-23 14:14:19 +02001491 msg "build: full no CIPHER no PSA_CRYPTO_C"
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001492 scripts/config.py full
1493 scripts/config.py unset MBEDTLS_CIPHER_C
Gilles Peskine9b8dead2023-08-09 19:48:42 +02001494 # Don't pull in cipher via PSA mechanisms
1495 # (currently ignored anyway because we completely disable PSA)
1496 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Valerio Setti4529d652023-10-24 11:51:58 +02001497 # Disable features that depend on CIPHER_C
Przemek Stekielda5f4832022-05-12 09:46:29 +02001498 scripts/config.py unset MBEDTLS_CCM_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001499 scripts/config.py unset MBEDTLS_CMAC_C
Przemek Stekielda5f4832022-05-12 09:46:29 +02001500 scripts/config.py unset MBEDTLS_GCM_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001501 scripts/config.py unset MBEDTLS_NIST_KW_C
1502 scripts/config.py unset MBEDTLS_PKCS12_C
1503 scripts/config.py unset MBEDTLS_PKCS5_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001504 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1505 scripts/config.py unset MBEDTLS_SSL_TLS_C
1506 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Valerio Setti4529d652023-10-24 11:51:58 +02001507 # Disable features that depend on PSA_CRYPTO_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001508 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
1509 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001510 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Raef Colesa7e03ad2022-09-28 09:32:48 +01001511 scripts/config.py unset MBEDTLS_LMS_C
Raef Coles47bccb72022-09-28 12:00:20 +01001512 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001513 make
1514
Valerio Settidf17a102023-10-23 14:14:19 +02001515 msg "test: full no CIPHER no PSA_CRYPTO_C"
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001516 make test
1517}
1518
Valerio Setti7e710e82023-08-25 09:14:15 +02001519# This is a common configurator and test function that is used in:
1520# - component_test_full_no_cipher_with_crypto
1521# - component_test_full_no_cipher_with_crypto_config
1522# It accepts 2 input parameters:
1523# - $1: boolean value which basically reflects status of MBEDTLS_PSA_CRYPTO_CONFIG
1524# - $2: a text string which describes the test component
Valerio Setti5b4039f2023-10-24 13:41:44 +02001525common_test_full_no_cipher_with_psa_crypto () {
Valerio Setti7e710e82023-08-25 09:14:15 +02001526 USE_CRYPTO_CONFIG="$1"
1527 COMPONENT_DESCRIPTION="$2"
1528
1529 msg "build: $COMPONENT_DESCRIPTION"
1530
1531 scripts/config.py full
1532 scripts/config.py unset MBEDTLS_CIPHER_C
1533
1534 if [ "$USE_CRYPTO_CONFIG" -eq 1 ]; then
Valerio Setti862021a2023-10-24 13:52:06 +02001535 # The built-in implementation of the following algs/key-types depends
1536 # on CIPHER_C so we disable them.
1537 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
1538 # so we keep them enabled.
Valerio Setti7e710e82023-08-25 09:14:15 +02001539 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM
1540 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1541 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_GCM
1542 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CMAC
1543 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
1544 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
1545 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CFB
1546 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CTR
1547 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
1548 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_OFB
1549 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_STREAM_CIPHER
1550 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_AES
1551 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
1552 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_CAMELLIA
1553 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_ARIA
1554 else
1555 # Don't pull in cipher via PSA mechanisms
1556 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
1557 fi
Valerio Settic84d9402023-10-23 14:58:25 +02001558 # The following modules directly depends on CIPHER_C
Valerio Setti7e710e82023-08-25 09:14:15 +02001559 scripts/config.py unset MBEDTLS_CCM_C
1560 scripts/config.py unset MBEDTLS_CMAC_C
1561 scripts/config.py unset MBEDTLS_GCM_C
1562 scripts/config.py unset MBEDTLS_NIST_KW_C
1563 scripts/config.py unset MBEDTLS_PKCS12_C
1564 scripts/config.py unset MBEDTLS_PKCS5_C
1565 scripts/config.py unset MBEDTLS_SSL_TLS_C
1566 scripts/config.py unset MBEDTLS_SSL_TICKET_C
1567 # Disable cipher modes/keys that make PSA depend on CIPHER_C.
Valerio Setti862021a2023-10-24 13:52:06 +02001568 # Keep CHACHA20 and CHACHAPOLY enabled since they do not depend on CIPHER_C.
Valerio Setti7e710e82023-08-25 09:14:15 +02001569 scripts/config.py unset-all MBEDTLS_CIPHER_MODE
1570 scripts/config.py unset MBEDTLS_AES_C
1571 scripts/config.py unset MBEDTLS_DES_C
1572 scripts/config.py unset MBEDTLS_ARIA_C
1573 scripts/config.py unset MBEDTLS_CAMELLIA_C
1574 # Dependencies on AES_C
1575 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Valerio Settifb0b0ff2023-10-23 14:58:55 +02001576
Valerio Setti7e710e82023-08-25 09:14:15 +02001577 make
1578
1579 # Ensure that CIPHER_C was not re-enabled
1580 not grep mbedtls_cipher_init library/cipher.o
1581
1582 msg "test: $COMPONENT_DESCRIPTION"
1583 make test
1584}
1585
1586component_test_full_no_cipher_with_crypto() {
Valerio Setti5b4039f2023-10-24 13:41:44 +02001587 common_test_full_no_cipher_with_psa_crypto 0 "full no CIPHER no CRYPTO_CONFIG"
Valerio Setti7e710e82023-08-25 09:14:15 +02001588}
1589
1590component_test_full_no_cipher_with_crypto_config() {
Valerio Setti5b4039f2023-10-24 13:41:44 +02001591 common_test_full_no_cipher_with_psa_crypto 1 "full no CIPHER"
Valerio Setti7e710e82023-08-25 09:14:15 +02001592}
1593
Valerio Settie1655b82023-01-03 15:35:25 +01001594component_test_full_no_bignum () {
1595 msg "build: full minus bignum"
1596 scripts/config.py full
1597 scripts/config.py unset MBEDTLS_BIGNUM_C
1598 # Direct dependencies of bignum
1599 scripts/config.py unset MBEDTLS_ECP_C
1600 scripts/config.py unset MBEDTLS_RSA_C
1601 scripts/config.py unset MBEDTLS_DHM_C
1602 # Direct dependencies of ECP
1603 scripts/config.py unset MBEDTLS_ECDH_C
1604 scripts/config.py unset MBEDTLS_ECDSA_C
1605 scripts/config.py unset MBEDTLS_ECJPAKE_C
1606 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Setti22d0a792023-06-14 17:23:19 +02001607 # Disable what auto-enables ECP_LIGHT
1608 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1609 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
Valerio Settie1655b82023-01-03 15:35:25 +01001610 # Indirect dependencies of ECP
1611 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1612 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1613 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1614 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1615 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1616 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
1617 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
1618 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
1619 # Direct dependencies of DHM
1620 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1621 # Direct dependencies of RSA
1622 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1623 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1624 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1625 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1626 # PK and its dependencies
1627 scripts/config.py unset MBEDTLS_PK_C
1628 scripts/config.py unset MBEDTLS_PK_PARSE_C
1629 scripts/config.py unset MBEDTLS_PK_WRITE_C
1630 scripts/config.py unset MBEDTLS_X509_USE_C
1631 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
1632 scripts/config.py unset MBEDTLS_X509_CRL_PARSE_C
1633 scripts/config.py unset MBEDTLS_X509_CSR_PARSE_C
1634 scripts/config.py unset MBEDTLS_X509_CREATE_C
1635 scripts/config.py unset MBEDTLS_X509_CRT_WRITE_C
1636 scripts/config.py unset MBEDTLS_X509_CSR_WRITE_C
1637 scripts/config.py unset MBEDTLS_PKCS7_C
1638 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
1639 scripts/config.py unset MBEDTLS_SSL_ASYNC_PRIVATE
1640 scripts/config.py unset MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
1641
1642 make
1643
1644 msg "test: full minus bignum"
1645 make test
1646}
1647
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001648component_test_tls1_2_default_stream_cipher_only () {
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001649 msg "build: default with only stream cipher"
1650
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001651 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001652 scripts/config.py unset MBEDTLS_GCM_C
1653 scripts/config.py unset MBEDTLS_CCM_C
1654 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001655 # 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 +02001656 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001657 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001658 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001659 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1660 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001661 # Modules that depend on AEAD
Przemek Stekield582a012022-09-28 07:59:01 +02001662 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001663 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001664
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001665 make
1666
1667 msg "test: default with only stream cipher"
1668 make test
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001669
1670 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001671}
1672
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001673component_test_tls1_2_default_stream_cipher_only_use_psa () {
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001674 msg "build: default with only stream cipher use psa"
Przemek Stekiel9550c052022-09-28 09:51:55 +02001675
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001676 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001677 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel9550c052022-09-28 09:51:55 +02001678 scripts/config.py unset MBEDTLS_GCM_C
1679 scripts/config.py unset MBEDTLS_CCM_C
1680 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001681 # 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 +02001682 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001683 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekiel9550c052022-09-28 09:51:55 +02001684 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001685 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1686 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001687 # Modules that depend on AEAD
Przemek Stekiel9550c052022-09-28 09:51:55 +02001688 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001689 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel9550c052022-09-28 09:51:55 +02001690
Przemek Stekiel9550c052022-09-28 09:51:55 +02001691 make
1692
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001693 msg "test: default with only stream cipher use psa"
Przemek Stekiel9550c052022-09-28 09:51:55 +02001694 make test
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001695
1696 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
Przemek Stekiel9550c052022-09-28 09:51:55 +02001697}
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001698
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001699component_test_tls1_2_default_cbc_legacy_cipher_only () {
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001700 msg "build: default with only CBC-legacy cipher"
1701
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001702 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001703 scripts/config.py unset MBEDTLS_GCM_C
1704 scripts/config.py unset MBEDTLS_CCM_C
1705 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001706 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1707 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1708 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001709 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001710 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001711 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001712 # Modules that depend on AEAD
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001713 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001714 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001715
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001716 make
1717
1718 msg "test: default with only CBC-legacy cipher"
1719 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001720
1721 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1722 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001723}
1724
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001725component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001726 msg "build: default with only CBC-legacy cipher use psa"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001727
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001728 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001729 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001730 scripts/config.py unset MBEDTLS_GCM_C
1731 scripts/config.py unset MBEDTLS_CCM_C
1732 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001733 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1734 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1735 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001736 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001737 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001738 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001739 # Modules that depend on AEAD
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001740 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001741 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001742
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001743 make
1744
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001745 msg "test: default with only CBC-legacy cipher use psa"
1746 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001747
1748 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1749 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001750}
1751
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001752component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001753 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1754
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001755 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001756 scripts/config.py unset MBEDTLS_GCM_C
1757 scripts/config.py unset MBEDTLS_CCM_C
1758 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001759 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1760 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1761 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1762 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1763 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001764 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001765 # Modules that depend on AEAD
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001766 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001767 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001768
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001769 make
1770
1771 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1772 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001773
1774 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1775 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001776}
1777
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001778component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
1779 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001780
1781 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001782 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001783 scripts/config.py unset MBEDTLS_GCM_C
1784 scripts/config.py unset MBEDTLS_CCM_C
1785 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001786 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1787 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1788 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1789 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1790 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001791 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001792 # Modules that depend on AEAD
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001793 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001794 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001795
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001796 make
1797
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001798 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001799 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001800
1801 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
1802 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001803}
1804
Valerio Setti9f0ec532022-11-08 13:03:24 +01001805# We're not aware of any other (open source) implementation of EC J-PAKE in TLS
1806# that we could use for interop testing. However, we now have sort of two
1807# implementations ourselves: one using PSA, the other not. At least test that
1808# these two interoperate with each other.
1809component_test_tls1_2_ecjpake_compatibility() {
1810 msg "build: TLS1.2 server+client w/ EC-JPAKE w/o USE_PSA"
1811 scripts/config.py set MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
Gilles Peskineedc84562023-09-20 15:03:18 +02001812 # Explicitly make lib first to avoid a race condition:
1813 # https://github.com/Mbed-TLS/mbedtls/issues/8229
1814 make lib
Valerio Setti9f0ec532022-11-08 13:03:24 +01001815 make -C programs ssl/ssl_server2 ssl/ssl_client2
1816 cp programs/ssl/ssl_server2 s2_no_use_psa
1817 cp programs/ssl/ssl_client2 c2_no_use_psa
1818
1819 msg "build: TLS1.2 server+client w/ EC-JPAKE w/ USE_PSA"
1820 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1821 make clean
Gilles Peskineedc84562023-09-20 15:03:18 +02001822 make lib
Valerio Setti9f0ec532022-11-08 13:03:24 +01001823 make -C programs ssl/ssl_server2 ssl/ssl_client2
1824 make -C programs test/udp_proxy test/query_compile_time_config
1825
Valerio Setti70e02902022-12-02 16:21:56 +01001826 msg "test: server w/o USE_PSA - client w/ USE_PSA, text password"
1827 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
1828 msg "test: server w/o USE_PSA - client w/ USE_PSA, opaque password"
1829 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password client only, working, TLS"
1830 msg "test: client w/o USE_PSA - server w/ USE_PSA, text password"
1831 P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
1832 msg "test: client w/o USE_PSA - server w/ USE_PSA, opaque password"
1833 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 +01001834
1835 rm s2_no_use_psa c2_no_use_psa
1836}
1837
Gilles Peskine636c26a2020-03-04 20:46:15 +01001838component_test_everest () {
1839 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine636c26a2020-03-04 20:46:15 +01001840 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1841 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1842 make
1843
1844 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1845 make test
1846
1847 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001848 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001849
1850 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1851 # Exclude some symmetric ciphers that are redundant here to gain time.
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02001852 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001853}
1854
Gilles Peskined3beca92020-07-03 00:15:37 +02001855component_test_everest_curve25519_only () {
1856 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
Gilles Peskined3beca92020-07-03 00:15:37 +02001857 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1858 scripts/config.py unset MBEDTLS_ECDSA_C
1859 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1860 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
TRodziewicz7c1d41d2021-04-23 13:33:44 +02001861 scripts/config.py unset MBEDTLS_ECJPAKE_C
Gilles Peskined3beca92020-07-03 00:15:37 +02001862 # Disable all curves
Valerio Setti2e0275d2023-07-28 16:33:13 +02001863 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
Gilles Peskined3beca92020-07-03 00:15:37 +02001864 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1865
1866 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1867
1868 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1869 make test
1870}
1871
Gilles Peskine8f073122018-11-27 15:58:47 +01001872component_test_small_ssl_out_content_len () {
1873 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001874 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1875 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001876 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1877 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001878
Gilles Peskine8f073122018-11-27 15:58:47 +01001879 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001880 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001881}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001882
Gilles Peskine8f073122018-11-27 15:58:47 +01001883component_test_small_ssl_in_content_len () {
1884 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001885 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1886 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001887 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1888 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001889
Gilles Peskine8f073122018-11-27 15:58:47 +01001890 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001891 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001892}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001893
Gilles Peskine8f073122018-11-27 15:58:47 +01001894component_test_small_ssl_dtls_max_buffering () {
1895 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001896 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001897 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1898 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001899
Gilles Peskine8f073122018-11-27 15:58:47 +01001900 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001901 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 +01001902}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001903
Gilles Peskine8f073122018-11-27 15:58:47 +01001904component_test_small_mbedtls_ssl_dtls_max_buffering () {
1905 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001906 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001907 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1908 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001909
Gilles Peskine8f073122018-11-27 15:58:47 +01001910 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001911 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001912}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001913
Gilles Peskine75cc7712019-09-06 19:47:17 +02001914component_test_psa_collect_statuses () {
1915 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001916 scripts/config.py full
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001917 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001918 # Check that psa_crypto_init() succeeded at least once
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001919 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001920 rm -f tests/statuses.log
1921}
1922
Gilles Peskine8f073122018-11-27 15:58:47 +01001923component_test_full_cmake_clang () {
1924 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001925 scripts/config.py full
Gilles Peskineda6017c2022-10-30 21:02:40 +01001926 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 +01001927 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001928
k-stachowiak0291cb72019-06-26 15:52:12 +02001929 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001930 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001931
Gilles Peskineda6017c2022-10-30 21:02:40 +01001932 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
1933 programs/test/cpp_dummy_build
1934
Gilles Peskine82b27272019-06-14 18:27:03 +02001935 msg "program demos (full config, clang)" # ~10s
1936 tests/scripts/run_demos.py
1937
k-stachowiak0291cb72019-06-26 15:52:12 +02001938 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001939 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001940
Gilles Peskine8f073122018-11-27 15:58:47 +01001941 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001942 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001943
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02001944 msg "test: compat.sh NULL (full config)" # ~ 2 min
Gilles Peskinee29203b2023-08-27 21:43:00 +02001945 tests/compat.sh -e '^$' -f 'NULL'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001946
Gilles Peskine8f073122018-11-27 15:58:47 +01001947 msg "test: compat.sh ARIA + ChachaPoly"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01001948 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001949}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001950
Gilles Peskine0c671602022-11-29 16:01:41 +01001951skip_suites_without_constant_flow () {
1952 # Skip the test suites that don't have any constant-flow annotations.
1953 # This will need to be adjusted if we ever start declaring things as
1954 # secret from macros or functions inside tests/include or tests/src.
1955 SKIP_TEST_SUITES=$(
1956 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
1957 sed 's/test_suite_//; s/\.function$//' |
1958 tr '\n' ,)
1959 export SKIP_TEST_SUITES
1960}
1961
Dave Rodgman246210e2023-07-31 18:07:44 +01001962skip_all_except_given_suite () {
1963 # Skip all but the given test suite
1964 SKIP_TEST_SUITES=$(
1965 ls -1 tests/suites/test_suite_*.function |
1966 grep -v $1.function |
1967 sed 's/tests.suites.test_suite_//; s/\.function$//' |
1968 tr '\n' ,)
1969 export SKIP_TEST_SUITES
1970}
1971
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001972component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001973 # This tests both (1) accesses to undefined memory, and (2) branches or
1974 # memory access depending on secret values. To distinguish between those:
1975 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1976 # - or alternatively, change the build type to MemSanDbg, which enables
1977 # origin tracking and nicer stack traces (which are useful for debugging
1978 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001979 msg "build: cmake MSan (clang), full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
1980 scripts/config.py full
1981 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1982 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1983 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1984 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1985 make
1986
1987 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO, Msan + constant flow)"
1988 make test
1989}
1990
1991component_test_memsan_constant_flow_psa () {
1992 # This tests both (1) accesses to undefined memory, and (2) branches or
1993 # memory access depending on secret values. To distinguish between those:
1994 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1995 # - or alternatively, change the build type to MemSanDbg, which enables
1996 # origin tracking and nicer stack traces (which are useful for debugging
1997 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001998 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001999 scripts/config.py full
2000 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
2001 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
2002 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
2003 make
2004
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02002005 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02002006 make test
2007}
2008
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02002009component_test_valgrind_constant_flow () {
2010 # This tests both (1) everything that valgrind's memcheck usually checks
2011 # (heap buffer overflows, use of uninitialized memory, use-after-free,
2012 # etc.) and (2) branches or memory access depending on secret values,
2013 # which will be reported as uninitialized memory. To distinguish between
2014 # secret and actually uninitialized:
2015 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
2016 # - or alternatively, build with debug info and manually run the offending
2017 # test suite with valgrind --track-origins=yes, then check if the origin
2018 # was TEST_CF_SECRET() or something else.
Neil Armstrong0ab7a232022-03-18 09:57:32 +01002019 msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
2020 scripts/config.py full
2021 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
2022 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine0c671602022-11-29 16:01:41 +01002023 skip_suites_without_constant_flow
Neil Armstrong0ab7a232022-03-18 09:57:32 +01002024 cmake -D CMAKE_BUILD_TYPE:String=Release .
2025 make
2026
2027 # this only shows a summary of the results (how many of each type)
2028 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine0c671602022-11-29 16:01:41 +01002029 msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, valgrind + constant flow)"
Neil Armstrong0ab7a232022-03-18 09:57:32 +01002030 make memcheck
Dave Rodgman246210e2023-07-31 18:07:44 +01002031
2032 # Test asm path in constant time module - by default, it will test the plain C
2033 # path under Valgrind or Memsan. Running only the constant_time tests is fast (<1s)
2034 msg "test: valgrind asm constant_time"
2035 scripts/config.py --force set MBEDTLS_TEST_CONSTANT_FLOW_ASM
2036 skip_all_except_given_suite test_suite_constant_time
2037 cmake -D CMAKE_BUILD_TYPE:String=Release .
2038 make clean
2039 make
2040 make memcheck
Neil Armstrong0ab7a232022-03-18 09:57:32 +01002041}
2042
2043component_test_valgrind_constant_flow_psa () {
2044 # This tests both (1) everything that valgrind's memcheck usually checks
2045 # (heap buffer overflows, use of uninitialized memory, use-after-free,
2046 # etc.) and (2) branches or memory access depending on secret values,
2047 # which will be reported as uninitialized memory. To distinguish between
2048 # secret and actually uninitialized:
2049 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
2050 # - or alternatively, build with debug info and manually run the offending
2051 # test suite with valgrind --track-origins=yes, then check if the origin
2052 # was TEST_CF_SECRET() or something else.
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02002053 msg "build: cmake release GCC, full config with constant flow testing"
2054 scripts/config.py full
2055 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Gilles Peskine0c671602022-11-29 16:01:41 +01002056 skip_suites_without_constant_flow
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02002057 cmake -D CMAKE_BUILD_TYPE:String=Release .
2058 make
2059
2060 # this only shows a summary of the results (how many of each type)
2061 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine0c671602022-11-29 16:01:41 +01002062 msg "test: some suites (valgrind + constant flow)"
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02002063 make memcheck
2064}
2065
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002066component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02002067 # Test that removing the deprecated features from the default
2068 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002069 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
2070 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
2071 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
2072
2073 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
2074 make test
2075}
2076
2077component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02002078 msg "build: make, full_no_deprecated config" # ~ 30s
2079 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002080 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
2081
Gilles Peskine30de2e82020-04-20 21:39:22 +02002082 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002083 make test
Valerio Setti41b5fb62023-01-09 12:20:45 +01002084
2085 msg "test: ensure that X509 has no direct dependency on BIGNUM_C"
2086 not grep mbedtls_mpi library/libmbedx509.a
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002087}
2088
Gilles Peskine8386ea22020-04-30 09:07:29 +02002089component_test_full_no_deprecated_deprecated_warning () {
2090 # Test that there is nothing deprecated in "full_no_deprecated".
2091 # A deprecated feature would trigger a warning (made fatal) from
2092 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02002093 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
2094 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002095 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
2096 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
2097 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
2098
Gilles Peskine30de2e82020-04-20 21:39:22 +02002099 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002100 make test
2101}
2102
Gilles Peskine8386ea22020-04-30 09:07:29 +02002103component_test_full_deprecated_warning () {
2104 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
2105 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002106 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002107 scripts/config.py full
2108 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002109 # Expect warnings from '#warning' directives in check_config.h.
2110 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01002111
Gilles Peskine8386ea22020-04-30 09:07:29 +02002112 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
2113 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
2114 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002115 # Expect warnings from '#warning' directives in check_config.h and
2116 # from the use of deprecated functions in test suites.
2117 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 +01002118
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002119 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
2120 make test
Gilles Peskine82b27272019-06-14 18:27:03 +02002121
2122 msg "program demos: full config + MBEDTLS_TEST_DEPRECATED" # ~10s
2123 tests/scripts/run_demos.py
Gilles Peskine8f073122018-11-27 15:58:47 +01002124}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00002125
Gilles Peskineec541fe2020-01-31 14:24:14 +01002126# Check that the specified libraries exist and are empty.
2127are_empty_libraries () {
2128 nm "$@" >/dev/null 2>/dev/null
2129 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
2130}
2131
2132component_build_crypto_default () {
2133 msg "build: make, crypto only"
2134 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01002135 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002136 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002137}
2138
2139component_build_crypto_full () {
2140 msg "build: make, crypto only, full config"
2141 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01002142 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002143 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002144}
2145
Gilles Peskinefc4f11b2022-10-21 19:34:54 +02002146component_test_crypto_for_psa_service () {
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002147 msg "build: make, config for PSA crypto service"
2148 scripts/config.py crypto
2149 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
2150 # Disable things that are not needed for just cryptography, to
2151 # reach a configuration that would be typical for a PSA cryptography
2152 # service providing all implemented PSA algorithms.
2153 # System stuff
2154 scripts/config.py unset MBEDTLS_ERROR_C
2155 scripts/config.py unset MBEDTLS_TIMING_C
Gilles Peskine78bffd12022-10-25 21:02:33 +02002156 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002157 # Crypto stuff with no PSA interface
2158 scripts/config.py unset MBEDTLS_BASE64_C
Gilles Peskine649e04e2022-10-25 21:05:57 +02002159 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
Gilles Peskineb06f0712022-10-25 21:06:11 +02002160 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
Gilles Peskine649e04e2022-10-25 21:05:57 +02002161 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002162 scripts/config.py unset MBEDTLS_NIST_KW_C
2163 scripts/config.py unset MBEDTLS_PEM_PARSE_C
2164 scripts/config.py unset MBEDTLS_PEM_WRITE_C
2165 scripts/config.py unset MBEDTLS_PKCS12_C
2166 scripts/config.py unset MBEDTLS_PKCS5_C
Gilles Peskinefcee7402022-10-11 21:15:24 +02002167 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
2168 # in PSA code to work with RSA keys. We don't require users to set those:
2169 # they will be reenabled in build_info.h.
Gilles Peskine1f108072022-10-25 21:02:56 +02002170 scripts/config.py unset MBEDTLS_PK_C
Gilles Peskinefcee7402022-10-11 21:15:24 +02002171 scripts/config.py unset MBEDTLS_PK_PARSE_C
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002172 scripts/config.py unset MBEDTLS_PK_WRITE_C
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002173 make CFLAGS='-O1 -Werror' all test
2174 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
2175}
2176
Gilles Peskineec541fe2020-01-31 14:24:14 +01002177component_build_crypto_baremetal () {
2178 msg "build: make, crypto only, baremetal config"
2179 scripts/config.py crypto_baremetal
David Horstmann61faf662021-11-30 11:40:54 +00002180 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002181 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002182}
Daniel Axtens446af202020-09-02 21:30:13 +10002183support_build_crypto_baremetal () {
Daniel Axtens814c8132020-08-31 14:22:58 +10002184 support_build_baremetal "$@"
2185}
2186
2187component_build_baremetal () {
2188 msg "build: make, baremetal config"
2189 scripts/config.py baremetal
David Horstmann61faf662021-11-30 11:40:54 +00002190 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Daniel Axtens814c8132020-08-31 14:22:58 +10002191}
2192support_build_baremetal () {
Daniel Axtens446af202020-09-02 21:30:13 +10002193 # Older Glibc versions include time.h from other headers such as stdlib.h,
2194 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
2195 # problem, Ubuntu 18.04 is ok.
2196 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
2197}
Gilles Peskineec541fe2020-01-31 14:24:14 +01002198
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002199# depends.py family of tests
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002200component_test_depends_py_cipher_id () {
2201 msg "test/build: depends.py cipher_id (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002202 tests/scripts/depends.py cipher_id --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002203}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00002204
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002205component_test_depends_py_cipher_chaining () {
2206 msg "test/build: depends.py cipher_chaining (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002207 tests/scripts/depends.py cipher_chaining --unset-use-psa
John Durkopc14be902020-08-20 06:16:41 -07002208}
2209
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002210component_test_depends_py_cipher_padding () {
2211 msg "test/build: depends.py cipher_padding (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002212 tests/scripts/depends.py cipher_padding --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002213}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00002214
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002215component_test_depends_py_curves () {
2216 msg "test/build: depends.py curves (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002217 tests/scripts/depends.py curves --unset-use-psa
John Durkop2ec2eaa2020-08-24 18:29:15 -07002218}
2219
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002220component_test_depends_py_hashes () {
2221 msg "test/build: depends.py hashes (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002222 tests/scripts/depends.py hashes --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002223}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002224
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002225component_test_depends_py_kex () {
2226 msg "test/build: depends.py kex (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002227 tests/scripts/depends.py kex --unset-use-psa
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002228}
2229
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002230component_test_depends_py_pkalgs () {
2231 msg "test/build: depends.py pkalgs (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002232 tests/scripts/depends.py pkalgs --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002233}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002234
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002235# PSA equivalents of the depends.py tests
2236component_test_depends_py_cipher_id_psa () {
2237 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2238 tests/scripts/depends.py cipher_id
2239}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002240
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002241component_test_depends_py_cipher_chaining_psa () {
2242 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2243 tests/scripts/depends.py cipher_chaining
2244}
2245
2246component_test_depends_py_cipher_padding_psa () {
2247 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2248 tests/scripts/depends.py cipher_padding
2249}
2250
2251component_test_depends_py_curves_psa () {
2252 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2253 tests/scripts/depends.py curves
2254}
2255
2256component_test_depends_py_hashes_psa () {
2257 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2258 tests/scripts/depends.py hashes
2259}
2260
2261component_test_depends_py_kex_psa () {
2262 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2263 tests/scripts/depends.py kex
2264}
2265
2266component_test_depends_py_pkalgs_psa () {
2267 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002268 tests/scripts/depends.py pkalgs
Gilles Peskine8f073122018-11-27 15:58:47 +01002269}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002270
Dave Rodgman1a034dc2023-01-20 13:18:05 +00002271component_build_no_pk_rsa_alt_support () {
2272 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
2273
2274 scripts/config.py full
2275 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
2276 scripts/config.py set MBEDTLS_RSA_C
2277 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
2278
2279 # Only compile - this is primarily to test for compile issues
2280 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
2281}
2282
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002283component_build_module_alt () {
2284 msg "build: MBEDTLS_XXX_ALT" # ~30s
2285 scripts/config.py full
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002286
2287 # Disable options that are incompatible with some ALT implementations:
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002288 # aesni.c and padlock.c reference mbedtls_aes_context fields directly.
2289 scripts/config.py unset MBEDTLS_AESNI_C
2290 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08002291 scripts/config.py unset MBEDTLS_AESCE_C
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002292 # MBEDTLS_ECP_RESTARTABLE is documented as incompatible.
2293 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002294 # You can only have one threading implementation: alt or pthread, not both.
2295 scripts/config.py unset MBEDTLS_THREADING_PTHREAD
Gilles Peskine5c3f18d2021-05-31 21:21:12 +02002296 # The SpecifiedECDomain parsing code accesses mbedtls_ecp_group fields
2297 # directly and assumes the implementation works with partial groups.
2298 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
Dave Rodgman5b89c552023-10-10 14:59:02 +01002299 # MBEDTLS_SHA256_*ALT can't be used with MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*
2300 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2301 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00002302 # MBEDTLS_SHA512_*ALT can't be used with MBEDTLS_SHA512_USE_A64_CRYPTO_*
2303 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2304 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002305
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002306 # Enable all MBEDTLS_XXX_ALT for whole modules. Do not enable
2307 # MBEDTLS_XXX_YYY_ALT which are for single functions.
2308 scripts/config.py set-all 'MBEDTLS_([A-Z0-9]*|NIST_KW)_ALT'
Gilles Peskine1628a9c2021-05-31 22:09:58 +02002309 scripts/config.py unset MBEDTLS_DHM_ALT #incompatible with MBEDTLS_DEBUG_C
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002310
Gilles Peskine1628a9c2021-05-31 22:09:58 +02002311 # We can only compile, not link, since we don't have any implementations
2312 # suitable for testing with the dummy alt headers.
2313 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
2314}
2315
2316component_build_dhm_alt () {
2317 msg "build: MBEDTLS_DHM_ALT" # ~30s
2318 scripts/config.py full
2319 scripts/config.py set MBEDTLS_DHM_ALT
2320 # debug.c currently references mbedtls_dhm_context fields directly.
2321 scripts/config.py unset MBEDTLS_DEBUG_C
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002322 # We can only compile, not link, since we don't have any implementations
2323 # suitable for testing with the dummy alt headers.
2324 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
2325}
2326
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002327component_test_no_use_psa_crypto_full_cmake_asan() {
2328 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02002329 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002330 scripts/config.py full
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002331 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
2332 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cron6f135e12021-12-08 16:57:54 +01002333 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002334 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02002335 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002336 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Raef Colesa7e03ad2022-09-28 09:32:48 +01002337 scripts/config.py unset MBEDTLS_LMS_C
Raef Coles47bccb72022-09-28 12:00:20 +01002338 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01002339 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002340 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02002341
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002342 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002343 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02002344
Manuel Pégourié-Gonnard182a23b2022-12-07 10:38:43 +01002345 # Note: ssl-opt.sh has some test cases that depend on
2346 # MBEDTLS_ECP_RESTARTABLE && !MBEDTLS_USE_PSA_CRYPTO
2347 # This is the only component where those tests are not skipped.
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002348 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002349 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002350
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002351 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002352 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04002353
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02002354 msg "test: compat.sh NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskinee29203b2023-08-27 21:43:00 +02002355 tests/compat.sh -f 'NULL'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002356
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002357 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01002358 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002359}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002360
Ronald Cron403c15c2021-09-13 09:38:05 +02002361component_test_psa_crypto_config_accel_ecdsa () {
Valerio Setti5aab43f2023-03-29 10:42:07 +02002362 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
Ronald Cron403c15c2021-09-13 09:38:05 +02002363
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002364 # Algorithms and key types to accelerate
Valerio Settic0d2f842023-06-28 10:48:08 +02002365 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
Valerio Setti0a342c92023-09-01 09:12:31 +02002366 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002367
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002368 # Note: Those are handled in a special way by the libtestdriver machinery,
2369 # so we only want to include them in the accel list when building the main
2370 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002371 loc_curve_list="$(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002372
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002373 # Configure
2374 # ---------
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002375
Manuel Pégourié-Gonnard8d645dc2023-06-15 09:07:10 +02002376 # Start from default config (no USE_PSA) + TLS 1.3
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002377 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard6d7db932022-12-28 09:48:01 +01002378 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002379
2380 # Disable the module that's accelerated
Ronald Cron403c15c2021-09-13 09:38:05 +02002381 scripts/config.py unset MBEDTLS_ECDSA_C
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002382
2383 # Disable things that depend on it
Ronald Cron403c15c2021-09-13 09:38:05 +02002384 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2385 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2386
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002387 # Build
2388 # -----
2389
2390 # These hashes are needed for some ECDSA signature tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02002391 loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2392 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002393
2394 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2395
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002396 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02002397
Manuel Pégourié-Gonnarde3095e72022-12-28 10:09:53 +01002398 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine827dbd92022-02-04 00:30:54 +01002399 not grep mbedtls_ecdsa_ library/ecdsa.o
Ronald Cron403c15c2021-09-13 09:38:05 +02002400
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002401 # Run the tests
2402 # -------------
2403
Ronald Cron403c15c2021-09-13 09:38:05 +02002404 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
2405 make test
2406}
2407
Valerio Setti44b178c2023-03-22 14:02:57 +01002408component_test_psa_crypto_config_accel_ecdh () {
Valerio Setti5aab43f2023-03-29 10:42:07 +02002409 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002410
2411 # Algorithms and key types to accelerate
Valerio Settic0d2f842023-06-28 10:48:08 +02002412 loc_accel_list="ALG_ECDH \
Valerio Setti0a342c92023-09-01 09:12:31 +02002413 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002414
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002415 # Note: Those are handled in a special way by the libtestdriver machinery,
2416 # so we only want to include them in the accel list when building the main
2417 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002418 loc_curve_list="$(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002419
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002420 # Configure
2421 # ---------
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002422
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002423 # Start from default config (no TLS 1.3, no USE_PSA)
2424 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002425
Valerio Setti44b178c2023-03-22 14:02:57 +01002426 # Disable the module that's accelerated
2427 scripts/config.py unset MBEDTLS_ECDH_C
2428
2429 # Disable things that depend on it
2430 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2431 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2432 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2433 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2434 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2435
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002436 # Build
2437 # -----
2438
2439 helper_libtestdriver1_make_drivers "$loc_accel_list"
2440
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002441 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002442
Valerio Setti44b178c2023-03-22 14:02:57 +01002443 # Make sure this was not re-enabled by accident (additive config)
2444 not grep mbedtls_ecdh_ library/ecdh.o
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002445
2446 # Run the tests
2447 # -------------
2448
Valerio Setti44b178c2023-03-22 14:02:57 +01002449 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002450 make test
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +01002451}
2452
Przemek Stekieldccb2022023-05-11 10:48:50 +02002453component_test_psa_crypto_config_accel_ffdh () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002454 msg "build: full with accelerated FFDH"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002455
2456 # Algorithms and key types to accelerate
Valerio Setti27602c32023-07-10 16:38:59 +02002457 loc_accel_list="ALG_FFDH \
Valerio Setti0a342c92023-09-01 09:12:31 +02002458 $(helper_get_psa_key_type_list "DH")"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002459
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002460 # Configure
2461 # ---------
Przemek Stekieldccb2022023-05-11 10:48:50 +02002462
Przemek Stekiel565353e2023-07-05 11:07:07 +02002463 # start with full (USE_PSA and TLS 1.3)
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002464 helper_libtestdriver1_adjust_config "full"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002465
2466 # Disable the module that's accelerated
2467 scripts/config.py unset MBEDTLS_DHM_C
2468
2469 # Disable things that depend on it
2470 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2471 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2472
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002473 # Build
2474 # -----
2475
2476 helper_libtestdriver1_make_drivers "$loc_accel_list"
2477
Manuel Pégourié-Gonnard981732e2023-06-08 09:15:59 +02002478 helper_libtestdriver1_make_main "$loc_accel_list"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002479
2480 # Make sure this was not re-enabled by accident (additive config)
2481 not grep mbedtls_dhm_ library/dhm.o
2482
2483 # Run the tests
2484 # -------------
2485
Gilles Peskine14302ed2023-07-19 19:30:04 +02002486 msg "test: full with accelerated FFDH"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002487 make test
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002488
Gilles Peskine14302ed2023-07-19 19:30:04 +02002489 msg "ssl-opt: full with accelerated FFDH alg"
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002490 tests/ssl-opt.sh -f "ffdh"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002491}
2492
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002493component_test_psa_crypto_config_reference_ffdh () {
Gilles Peskineb7d577e2023-08-09 19:48:58 +02002494 msg "build: full with non-accelerated FFDH"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002495
2496 # Start with full (USE_PSA and TLS 1.3)
Przemek Stekiel565353e2023-07-05 11:07:07 +02002497 helper_libtestdriver1_adjust_config "full"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002498
2499 # Disable things that are not supported
2500 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2501 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002502 make
2503
Gilles Peskine14302ed2023-07-19 19:30:04 +02002504 msg "test suites: full with non-accelerated FFDH alg"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002505 make test
2506
Gilles Peskine14302ed2023-07-19 19:30:04 +02002507 msg "ssl-opt: full with non-accelerated FFDH alg"
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002508 tests/ssl-opt.sh -f "ffdh"
Valerio Setti42d5f192023-03-20 13:54:41 +01002509}
2510
Valerio Setti44b178c2023-03-22 14:02:57 +01002511component_test_psa_crypto_config_accel_pake() {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002512 msg "build: full with accelerated PAKE"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002513
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002514 loc_accel_list="ALG_JPAKE \
2515 $(helper_get_psa_key_type_list "ECC")"
2516
2517 # Note: Those are handled in a special way by the libtestdriver machinery,
2518 # so we only want to include them in the accel list when building the main
2519 # libraries, hence the use of a separate variable.
2520 loc_curve_list="$(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002521
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002522 # Configure
2523 # ---------
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002524
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002525 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002526
2527 # Make built-in fallback not available
2528 scripts/config.py unset MBEDTLS_ECJPAKE_C
2529 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
2530
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002531 # Build
2532 # -----
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002533
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002534 helper_libtestdriver1_make_drivers "$loc_accel_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002535
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002536 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002537
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002538 # Make sure this was not re-enabled by accident (additive config)
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002539 not grep mbedtls_ecjpake_init library/ecjpake.o
2540
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002541 # Run the tests
2542 # -------------
2543
Gilles Peskine14302ed2023-07-19 19:30:04 +02002544 msg "test: full with accelerated PAKE"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002545 make test
2546}
2547
Manuel Pégourié-Gonnard5c210362023-09-26 12:03:10 +02002548component_test_psa_crypto_config_accel_ecc_some_key_types () {
2549 msg "build: full with accelerated EC algs and some key types"
2550
2551 # Algorithms and key types to accelerate
2552 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
2553 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2554 ALG_ECDH \
2555 ALG_JPAKE \
2556 KEY_TYPE_ECC_PUBLIC_KEY \
2557 KEY_TYPE_ECC_KEY_PAIR_BASIC \
2558 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
2559 KEY_TYPE_ECC_KEY_PAIR_EXPORT"
2560
2561 # Note: Curves are handled in a special way by the libtestdriver machinery,
2562 # so we only want to include them in the accel list when building the main
2563 # libraries, hence the use of a separate variable.
2564 loc_curve_list="$(helper_get_psa_curve_list)"
2565
2566 # Configure
2567 # ---------
2568
2569 # start with config full for maximum coverage (also enables USE_PSA)
2570 helper_libtestdriver1_adjust_config "full"
2571
2572 # Disable modules that are accelerated - some will be re-enabled
2573 scripts/config.py unset MBEDTLS_ECDSA_C
2574 scripts/config.py unset MBEDTLS_ECDH_C
2575 scripts/config.py unset MBEDTLS_ECJPAKE_C
2576 scripts/config.py unset MBEDTLS_ECP_C
2577
2578 # Disable all curves - those that aren't accelerated should be re-enabled
2579 helper_disable_builtin_curves
2580
2581 # Restartable feature is not yet supported by PSA. Once it will in
2582 # the future, the following line could be removed (see issues
2583 # 6061, 6332 and following ones)
2584 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2585
2586 # this is not supported by the driver API yet
2587 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2588
2589 # Build
2590 # -----
2591
2592 # These hashes are needed for some ECDSA signature tests.
2593 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2594 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2595 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2596
2597 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
2598
2599 # ECP should be re-enabled but not the others
2600 not grep mbedtls_ecdh_ library/ecdh.o
2601 not grep mbedtls_ecdsa library/ecdsa.o
2602 not grep mbedtls_ecjpake library/ecjpake.o
2603 grep mbedtls_ecp library/ecp.o
2604
2605 # Run the tests
2606 # -------------
2607
2608 msg "test suites: full with accelerated EC algs and some key types"
2609 make test
2610}
2611
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002612# Run tests with only (non-)Weierstrass accelerated
2613# Common code used in:
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002614# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
2615# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002616common_test_psa_crypto_config_accel_ecc_some_curves () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002617 weierstrass=$1
2618 if [ $weierstrass -eq 1 ]; then
2619 desc="Weierstrass"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002620 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002621 desc="non-Weierstrass"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002622 fi
2623
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002624 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002625
2626 # Algorithms and key types to accelerate
2627 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2628 ALG_ECDH \
2629 ALG_JPAKE \
2630 $(helper_get_psa_key_type_list "ECC")"
2631
2632 # Note: Curves are handled in a special way by the libtestdriver machinery,
2633 # so we only want to include them in the accel list when building the main
2634 # libraries, hence the use of a separate variable.
2635 # Note: the following loop is a modified version of
2636 # helper_get_psa_curve_list that only keeps Weierstrass families.
2637 loc_weierstrass_list=""
2638 loc_non_weierstrass_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002639 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
2640 case $item in
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002641 ECC_BRAINPOOL*|ECC_SECP*)
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002642 loc_weierstrass_list="$loc_weierstrass_list $item"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002643 ;;
2644 *)
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002645 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002646 ;;
2647 esac
2648 done
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002649 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002650 loc_curve_list=$loc_weierstrass_list
2651 else
2652 loc_curve_list=$loc_non_weierstrass_list
2653 fi
2654
2655 # Configure
2656 # ---------
2657
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002658 # Start with config crypto_full and remove PK_C:
2659 # that's what's supported now, see docs/driver-only-builds.md.
2660 helper_libtestdriver1_adjust_config "crypto_full"
2661 scripts/config.py unset MBEDTLS_PK_C
2662 scripts/config.py unset MBEDTLS_PK_PARSE_C
2663 scripts/config.py unset MBEDTLS_PK_WRITE_C
2664 # We need to disable RSA too or PK will be re-enabled.
2665 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
2666 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
2667 scripts/config.py unset MBEDTLS_RSA_C
2668 scripts/config.py unset MBEDTLS_PKCS1_V15
2669 scripts/config.py unset MBEDTLS_PKCS1_V21
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002670
2671 # Disable modules that are accelerated - some will be re-enabled
2672 scripts/config.py unset MBEDTLS_ECDSA_C
2673 scripts/config.py unset MBEDTLS_ECDH_C
2674 scripts/config.py unset MBEDTLS_ECJPAKE_C
2675 scripts/config.py unset MBEDTLS_ECP_C
2676
2677 # Disable all curves - those that aren't accelerated should be re-enabled
2678 helper_disable_builtin_curves
2679
2680 # Restartable feature is not yet supported by PSA. Once it will in
2681 # the future, the following line could be removed (see issues
2682 # 6061, 6332 and following ones)
2683 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2684
2685 # this is not supported by the driver API yet
2686 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2687
2688 # Build
2689 # -----
2690
2691 # These hashes are needed for some ECDSA signature tests.
2692 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2693 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2694 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2695
2696 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
2697
2698 # We expect ECDH to be re-enabled for the missing curves
2699 grep mbedtls_ecdh_ library/ecdh.o
2700 # We expect ECP to be re-enabled, however the parts specific to the
2701 # families of curves that are accelerated should be ommited.
2702 # - functions with mxz in the name are specific to Montgomery curves
2703 # - ecp_muladd is specific to Weierstrass curves
2704 ##nm library/ecp.o | tee ecp.syms
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002705 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002706 not grep mbedtls_ecp_muladd library/ecp.o
2707 grep mxz library/ecp.o
2708 else
2709 grep mbedtls_ecp_muladd library/ecp.o
2710 not grep mxz library/ecp.o
2711 fi
2712 # We expect ECDSA and ECJPAKE to be re-enabled only when
2713 # Weierstrass curves are not accelerated
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002714 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002715 not grep mbedtls_ecdsa library/ecdsa.o
2716 not grep mbedtls_ecjpake library/ecjpake.o
2717 else
2718 grep mbedtls_ecdsa library/ecdsa.o
2719 grep mbedtls_ecjpake library/ecjpake.o
2720 fi
2721
2722 # Run the tests
2723 # -------------
2724
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002725 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
2726 make test
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002727}
2728
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002729component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002730 common_test_psa_crypto_config_accel_ecc_some_curves 1
2731}
2732
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002733component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002734 common_test_psa_crypto_config_accel_ecc_some_curves 0
2735}
2736
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002737# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
2738# ECDH, ECDSA) with and without drivers.
2739# The input parameter is a boolean value which indicates:
2740# - 0 keep built-in EC algs,
2741# - 1 exclude built-in EC algs (driver only).
2742#
2743# This is used by the two following components to ensure they always use the
2744# same config, except for the use of driver or built-in EC algorithms:
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002745# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
2746# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002747# This supports comparing their test coverage with analyze_outcomes.py.
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02002748config_psa_crypto_config_ecp_light_only () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002749 driver_only="$1"
Valerio Setti42d5f192023-03-20 13:54:41 +01002750 # start with config full for maximum coverage (also enables USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002751 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002752 if [ "$driver_only" -eq 1 ]; then
Valerio Setti42d5f192023-03-20 13:54:41 +01002753 # Disable modules that are accelerated
2754 scripts/config.py unset MBEDTLS_ECDSA_C
2755 scripts/config.py unset MBEDTLS_ECDH_C
2756 scripts/config.py unset MBEDTLS_ECJPAKE_C
Valerio Setti29b395c2023-04-05 18:20:30 +02002757 scripts/config.py unset MBEDTLS_ECP_C
Valerio Setti42d5f192023-03-20 13:54:41 +01002758 fi
2759
2760 # Restartable feature is not yet supported by PSA. Once it will in
2761 # the future, the following line could be removed (see issues
2762 # 6061, 6332 and following ones)
2763 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Setti42d5f192023-03-20 13:54:41 +01002764}
2765
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002766# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
2767component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002768 msg "build: full with accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002769
2770 # Algorithms and key types to accelerate
2771 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2772 ALG_ECDH \
2773 ALG_JPAKE \
Valerio Setti0a342c92023-09-01 09:12:31 +02002774 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002775
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002776 # Note: Those are handled in a special way by the libtestdriver machinery,
2777 # so we only want to include them in the accel list when building the main
2778 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002779 loc_curve_list="$(helper_get_psa_curve_list)"
Valerio Setti42d5f192023-03-20 13:54:41 +01002780
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002781 # Configure
2782 # ---------
Valerio Setti42d5f192023-03-20 13:54:41 +01002783
2784 # Use the same config as reference, only without built-in EC algs
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02002785 config_psa_crypto_config_ecp_light_only 1
Valerio Setti42d5f192023-03-20 13:54:41 +01002786
Valerio Setti0a342c92023-09-01 09:12:31 +02002787 # Do not disable builtin curves because that support is required for:
Valerio Settib2fd6732023-08-15 17:10:47 +02002788 # - MBEDTLS_PK_PARSE_EC_EXTENDED
2789 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
2790
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002791 # Build
2792 # -----
2793
2794 # These hashes are needed for some ECDSA signature tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02002795 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2796 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002797 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2798
Valerio Settib2fd6732023-08-15 17:10:47 +02002799 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Valerio Setti42d5f192023-03-20 13:54:41 +01002800
2801 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
2802 not grep mbedtls_ecdsa_ library/ecdsa.o
2803 not grep mbedtls_ecdh_ library/ecdh.o
2804 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Setti29b395c2023-04-05 18:20:30 +02002805 not grep mbedtls_ecp_mul library/ecp.o
Valerio Setti42d5f192023-03-20 13:54:41 +01002806
2807 # Run the tests
2808 # -------------
2809
Gilles Peskine14302ed2023-07-19 19:30:04 +02002810 msg "test suites: full with accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002811 make test
2812
Gilles Peskine14302ed2023-07-19 19:30:04 +02002813 msg "ssl-opt: full with accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002814 tests/ssl-opt.sh
2815}
2816
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002817# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
2818component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002819 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002820
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02002821 config_psa_crypto_config_ecp_light_only 0
Valerio Setti42d5f192023-03-20 13:54:41 +01002822
2823 make
2824
Gilles Peskine14302ed2023-07-19 19:30:04 +02002825 msg "test suites: full with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002826 make test
2827
Gilles Peskine14302ed2023-07-19 19:30:04 +02002828 msg "ssl-opt: full with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002829 tests/ssl-opt.sh
2830}
2831
Valerio Settie618cb02023-04-12 14:59:16 +02002832# This helper function is used by:
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002833# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
2834# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Valerio Settie618cb02023-04-12 14:59:16 +02002835# to ensure that both tests use the same underlying configuration when testing
2836# driver's coverage with analyze_outcomes.py.
2837#
2838# This functions accepts 1 boolean parameter as follows:
2839# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
2840# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
2841# - 0: include built-in implementation of EC algorithms.
2842#
2843# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
2844# on the ECP module.
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002845config_psa_crypto_no_ecp_at_all () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002846 driver_only="$1"
Valerio Settiaafe9002023-06-26 15:23:44 +02002847 # start with full config for maximum coverage (also enables USE_PSA)
2848 helper_libtestdriver1_adjust_config "full"
2849
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002850 if [ "$driver_only" -eq 1 ]; then
Valerio Settie618cb02023-04-12 14:59:16 +02002851 # Disable modules that are accelerated
2852 scripts/config.py unset MBEDTLS_ECDSA_C
2853 scripts/config.py unset MBEDTLS_ECDH_C
2854 scripts/config.py unset MBEDTLS_ECJPAKE_C
2855 # Disable ECP module (entirely)
2856 scripts/config.py unset MBEDTLS_ECP_C
Valerio Settie618cb02023-04-12 14:59:16 +02002857 fi
2858
Valerio Settiaecd32c2023-06-14 10:42:31 +02002859 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
2860 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
Valerio Settiaddeee42023-06-14 10:46:55 +02002861 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
Ronald Cron6b49b552023-07-20 09:57:54 +02002862 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Valerio Settiaecd32c2023-06-14 10:42:31 +02002863
Valerio Settie618cb02023-04-12 14:59:16 +02002864 # Restartable feature is not yet supported by PSA. Once it will in
2865 # the future, the following line could be removed (see issues
2866 # 6061, 6332 and following ones)
2867 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Settie618cb02023-04-12 14:59:16 +02002868}
2869
2870# Build and test a configuration where driver accelerates all EC algs while
2871# all support and dependencies from ECP and ECP_LIGHT are removed on the library
2872# side.
2873#
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002874# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
2875component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002876 msg "build: full + accelerated EC algs - ECP"
Valerio Settie618cb02023-04-12 14:59:16 +02002877
2878 # Algorithms and key types to accelerate
2879 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2880 ALG_ECDH \
2881 ALG_JPAKE \
Valerio Setti0a342c92023-09-01 09:12:31 +02002882 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002883
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002884 # Note: Those are handled in a special way by the libtestdriver machinery,
2885 # so we only want to include them in the accel list when building the main
2886 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002887 loc_curve_list="$(helper_get_psa_curve_list)"
Valerio Settie618cb02023-04-12 14:59:16 +02002888
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002889 # Configure
2890 # ---------
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002891
Valerio Settie618cb02023-04-12 14:59:16 +02002892 # Set common configurations between library's and driver's builds
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002893 config_psa_crypto_no_ecp_at_all 1
Valerio Settib2fd6732023-08-15 17:10:47 +02002894 # Disable all the builtin curves. All the required algs are accelerated.
2895 helper_disable_builtin_curves
Valerio Settie618cb02023-04-12 14:59:16 +02002896
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002897 # Build
2898 # -----
Valerio Settie618cb02023-04-12 14:59:16 +02002899
2900 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02002901 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
2902 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2903 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Valerio Settie618cb02023-04-12 14:59:16 +02002904
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +02002905 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
Valerio Settie618cb02023-04-12 14:59:16 +02002906
Valerio Settib2fd6732023-08-15 17:10:47 +02002907 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Valerio Settie618cb02023-04-12 14:59:16 +02002908
2909 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
2910 not grep mbedtls_ecdsa_ library/ecdsa.o
2911 not grep mbedtls_ecdh_ library/ecdh.o
2912 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Settib2fd6732023-08-15 17:10:47 +02002913 # Also ensure that ECP module was not re-enabled
Valerio Settie618cb02023-04-12 14:59:16 +02002914 not grep mbedtls_ecp_ library/ecp.o
Valerio Settie618cb02023-04-12 14:59:16 +02002915
2916 # Run the tests
2917 # -------------
2918
Gilles Peskine14302ed2023-07-19 19:30:04 +02002919 msg "test: full + accelerated EC algs - ECP"
Valerio Settie618cb02023-04-12 14:59:16 +02002920 make test
Valerio Setti16b70f22023-06-27 17:45:49 +02002921
Gilles Peskine14302ed2023-07-19 19:30:04 +02002922 msg "ssl-opt: full + accelerated EC algs - ECP"
Valerio Setti16b70f22023-06-27 17:45:49 +02002923 tests/ssl-opt.sh
Valerio Settie618cb02023-04-12 14:59:16 +02002924}
2925
2926# Reference function used for driver's coverage analysis in analyze_outcomes.py
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002927# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
Valerio Settie618cb02023-04-12 14:59:16 +02002928# Keep in sync with its accelerated counterpart.
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002929component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002930 msg "build: full + non accelerated EC algs"
Valerio Settie618cb02023-04-12 14:59:16 +02002931
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002932 config_psa_crypto_no_ecp_at_all 0
Valerio Settie618cb02023-04-12 14:59:16 +02002933
2934 make
2935
Gilles Peskine14302ed2023-07-19 19:30:04 +02002936 msg "test: full + non accelerated EC algs"
Valerio Settie618cb02023-04-12 14:59:16 +02002937 make test
Valerio Setti16b70f22023-06-27 17:45:49 +02002938
Gilles Peskine14302ed2023-07-19 19:30:04 +02002939 msg "ssl-opt: full + non accelerated EC algs"
Valerio Setti16b70f22023-06-27 17:45:49 +02002940 tests/ssl-opt.sh
Valerio Settie618cb02023-04-12 14:59:16 +02002941}
2942
Valerio Setti4e2f2442023-08-15 10:10:26 +02002943# This is a common configuration helper used directly from:
2944# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
2945# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
2946# and indirectly from:
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002947# - component_test_psa_crypto_config_accel_ecc_no_bignum
Valerio Setti4e2f2442023-08-15 10:10:26 +02002948# - accelerate all EC algs, disable RSA and FFDH
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002949# - component_test_psa_crypto_config_reference_ecc_no_bignum
Valerio Setti4e2f2442023-08-15 10:10:26 +02002950# - this is the reference component of the above
2951# - it still disables RSA and FFDH, but it uses builtin EC algs
2952# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
2953# - accelerate all EC and FFDH algs, disable only RSA
2954# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
2955# - this is the reference component of the above
2956# - it still disables RSA, but it uses builtin EC and FFDH algs
2957#
2958# This function accepts 2 parameters:
Valerio Setti5dfaca42023-09-05 08:48:51 +02002959# $1: a boolean value which states if we are testing an accelerated scenario
2960# or not.
2961# $2: a string value which states which components are tested. Allowed values
2962# are "ECC" or "ECC_DH".
Valerio Setti4e2f2442023-08-15 10:10:26 +02002963config_psa_crypto_config_accel_ecc_ffdh_no_bignum() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002964 driver_only="$1"
2965 test_target="$2"
Valerio Setti18535c32023-07-31 11:27:17 +02002966 # start with full config for maximum coverage (also enables USE_PSA)
Valerio Setti29c1b4d2023-07-27 10:08:45 +02002967 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002968
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002969 if [ "$driver_only" -eq 1 ]; then
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002970 # Disable modules that are accelerated
2971 scripts/config.py unset MBEDTLS_ECDSA_C
2972 scripts/config.py unset MBEDTLS_ECDH_C
2973 scripts/config.py unset MBEDTLS_ECJPAKE_C
2974 # Disable ECP module (entirely)
2975 scripts/config.py unset MBEDTLS_ECP_C
Manuel Pégourié-Gonnard660bbf22023-06-12 18:42:40 +02002976 # Also disable bignum
2977 scripts/config.py unset MBEDTLS_BIGNUM_C
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002978 fi
2979
2980 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
2981 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
2982 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
2983 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2984
Manuel Pégourié-Gonnard7dccb662023-06-12 18:28:42 +02002985 # RSA support is intentionally disabled on this test because RSA_C depends
2986 # on BIGNUM_C.
Valerio Setti2e0275d2023-07-28 16:33:13 +02002987 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
2988 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 +02002989 scripts/config.py unset MBEDTLS_RSA_C
2990 scripts/config.py unset MBEDTLS_PKCS1_V15
2991 scripts/config.py unset MBEDTLS_PKCS1_V21
2992 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2993 # Also disable key exchanges that depend on RSA
2994 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2995 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2996 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2997 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2998 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2999
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003000 if [ "$test_target" = "ECC" ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02003001 # When testing ECC only, we disable FFDH support, both from builtin and
3002 # PSA sides, and also disable the key exchanges that depend on DHM.
3003 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_FFDH
3004 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
3005 scripts/config.py unset MBEDTLS_DHM_C
3006 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
3007 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3008 else
3009 # When testing ECC and DH instead, we disable DHM and depending key
3010 # exchanges only in the accelerated build
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003011 if [ "$driver_only" -eq 1 ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02003012 scripts/config.py unset MBEDTLS_DHM_C
3013 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
3014 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3015 fi
3016 fi
Manuel Pégourié-Gonnard7dccb662023-06-12 18:28:42 +02003017
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003018 # Restartable feature is not yet supported by PSA. Once it will in
3019 # the future, the following line could be removed (see issues
3020 # 6061, 6332 and following ones)
3021 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
3022}
3023
Valerio Setti4e2f2442023-08-15 10:10:26 +02003024# Common helper used by:
3025# - component_test_psa_crypto_config_accel_ecc_no_bignum
3026# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003027#
Valerio Setti4e2f2442023-08-15 10:10:26 +02003028# The goal is to build and test accelerating either:
3029# - ECC only or
3030# - both ECC and FFDH
3031#
3032# It is meant to be used in conjunction with
Valerio Setti5dfaca42023-09-05 08:48:51 +02003033# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
3034# coverage analysis in the "analyze_outcomes.py" script.
Valerio Setti4e2f2442023-08-15 10:10:26 +02003035common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003036 test_target="$1"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003037
Valerio Setti5dfaca42023-09-05 08:48:51 +02003038 # This is an internal helper to simplify text message handling
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003039 if [ "$test_target" = "ECC_DH" ]; then
3040 accel_text="ECC/FFDH"
3041 removed_text="ECP - DH"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003042 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003043 accel_text="ECC"
3044 removed_text="ECP"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003045 fi
3046
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003047 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003048
3049 # By default we accelerate all EC keys/algs
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003050 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
3051 ALG_ECDH \
3052 ALG_JPAKE \
Valerio Setti0a342c92023-09-01 09:12:31 +02003053 $(helper_get_psa_key_type_list "ECC")"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003054 # Optionally we can also add DH to the list of accelerated items
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003055 if [ "$test_target" = "ECC_DH" ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02003056 loc_accel_list="$loc_accel_list \
3057 ALG_FFDH \
Manuel Pégourié-Gonnard85ff5e62023-09-22 09:05:48 +02003058 $(helper_get_psa_key_type_list "DH")"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003059 fi
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003060
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02003061 # Note: Those are handled in a special way by the libtestdriver machinery,
3062 # so we only want to include them in the accel list when building the main
3063 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02003064 loc_curve_list="$(helper_get_psa_curve_list)"
3065
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003066 # Configure
3067 # ---------
3068
3069 # Set common configurations between library's and driver's builds
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003070 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
Valerio Settib2fd6732023-08-15 17:10:47 +02003071 # Disable all the builtin curves. All the required algs are accelerated.
3072 helper_disable_builtin_curves
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003073
3074 # Build
3075 # -----
3076
3077 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02003078 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
3079 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3080 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003081
3082 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
3083
Valerio Settib2fd6732023-08-15 17:10:47 +02003084 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003085
3086 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
3087 not grep mbedtls_ecdsa_ library/ecdsa.o
3088 not grep mbedtls_ecdh_ library/ecdh.o
3089 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Setti4e2f2442023-08-15 10:10:26 +02003090 # Also ensure that ECP, RSA, [DHM] or BIGNUM modules were not re-enabled
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003091 not grep mbedtls_ecp_ library/ecp.o
Manuel Pégourié-Gonnard06aebe42023-06-12 18:33:34 +02003092 not grep mbedtls_rsa_ library/rsa.o
Manuel Pégourié-Gonnard660bbf22023-06-12 18:42:40 +02003093 not grep mbedtls_mpi_ library/bignum.o
Valerio Setti4e2f2442023-08-15 10:10:26 +02003094 not grep mbedtls_dhm_ library/dhm.o
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003095
3096 # Run the tests
3097 # -------------
3098
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003099 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - DHM - BIGNUM"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003100
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003101 make test
3102
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003103 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Valerio Setti18535c32023-07-31 11:27:17 +02003104 tests/ssl-opt.sh
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003105}
3106
Valerio Setti4e2f2442023-08-15 10:10:26 +02003107# Common helper used by:
3108# - component_test_psa_crypto_config_reference_ecc_no_bignum
3109# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
3110#
3111# The goal is to build and test a reference scenario (i.e. with builtin
3112# components) compared to the ones used in
3113# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
3114#
3115# It is meant to be used in conjunction with
3116# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
3117# coverage analysis in "analyze_outcomes.py" script.
3118common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003119 test_target="$1"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003120
Valerio Setti5dfaca42023-09-05 08:48:51 +02003121 # This is an internal helper to simplify text message handling
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003122 if [ "$test_target" = "ECC_DH" ]; then
3123 accel_text="ECC/FFDH"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003124 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003125 accel_text="ECC"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003126 fi
3127
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003128 msg "build: full + non accelerated $accel_text algs + USE_PSA"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003129
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003130 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003131
3132 make
3133
Valerio Setti29c1b4d2023-07-27 10:08:45 +02003134 msg "test suites: full + non accelerated EC algs + USE_PSA"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003135 make test
3136
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003137 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
Valerio Setti18535c32023-07-31 11:27:17 +02003138 tests/ssl-opt.sh
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003139}
3140
Valerio Setti4e2f2442023-08-15 10:10:26 +02003141component_test_psa_crypto_config_accel_ecc_no_bignum () {
3142 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
3143}
3144
3145component_test_psa_crypto_config_reference_ecc_no_bignum () {
3146 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
3147}
3148
3149component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
3150 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
3151}
3152
3153component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
3154 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
3155}
3156
Valerio Settiac6d35f2023-08-04 12:49:11 +02003157# Helper for setting common configurations between:
3158# - component_test_tfm_config_p256m_driver_accel_ec()
3159# - component_test_tfm_config()
Valerio Setti52ba0e32023-08-04 12:43:03 +02003160common_tfm_config () {
3161 # Enable TF-M config
Valerio Settic5c4bd22023-08-03 14:28:20 +02003162 cp configs/tfm_mbedcrypto_config_profile_medium.h "$CONFIG_H"
3163 cp configs/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
3164
Valerio Setti52ba0e32023-08-04 12:43:03 +02003165 # Adjust for the fact that we're building outside the TF-M environment.
3166 #
3167 # TF-M has separation, our build doesn't
3168 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SPM
3169 scripts/config.py unset MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
3170 # TF-M provdes its own (dummy) implemenation, from their tree
3171 scripts/config.py unset MBEDTLS_AES_DECRYPT_ALT
3172 scripts/config.py unset MBEDTLS_AES_SETKEY_DEC_ALT
3173 # We have an OS that provides entropy, use it
3174 scripts/config.py unset MBEDTLS_NO_PLATFORM_ENTROPY
3175
3176 # Other config adjustments to make the tests pass.
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003177 # Those should probably be adopted upstream.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003178 #
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003179 # - USE_PSA_CRYPTO for PK_HAVE_ECC_KEYS
3180 echo "#define MBEDTLS_USE_PSA_CRYPTO" >> "$CONFIG_H"
Valerio Setti52ba0e32023-08-04 12:43:03 +02003181 # pkparse.c and pkwrite.c fail to link without this
3182 echo "#define MBEDTLS_OID_C" >> "$CONFIG_H"
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003183 # - ASN1_[PARSE/WRITE]_C found by check_config.h for pkparse/pkwrite
3184 echo "#define MBEDTLS_ASN1_PARSE_C" >> "$CONFIG_H"
3185 echo "#define MBEDTLS_ASN1_WRITE_C" >> "$CONFIG_H"
3186 # - MD_C for HKDF_C
3187 echo "#define MBEDTLS_MD_C" >> "$CONFIG_H"
Valerio Setti52ba0e32023-08-04 12:43:03 +02003188
Manuel Pégourié-Gonnardf7298cd2023-09-18 09:55:24 +02003189 # Config adjustments for better test coverage in our environment.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003190 # These are not needed just to build and pass tests.
3191 #
3192 # Enable filesystem I/O for the benefit of PK parse/write tests.
3193 echo "#define MBEDTLS_FS_IO" >> "$CONFIG_H"
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003194 # Disable this for maximal ASan efficiency
3195 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
3196
Manuel Pégourié-Gonnardf7298cd2023-09-18 09:55:24 +02003197 # Config adjustments for features that are not supported
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003198 # when using only drivers / by p256-m
3199 #
3200 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
3201 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
3202 # Disable deterministic ECDSA as p256-m only does randomized
3203 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
3204
Valerio Setti52ba0e32023-08-04 12:43:03 +02003205}
3206
Valerio Settiac6d35f2023-08-04 12:49:11 +02003207# Keep this in sync with component_test_tfm_config() as they are both meant
3208# to be used in analyze_outcomes.py for driver's coverage analysis.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003209component_test_tfm_config_p256m_driver_accel_ec () {
3210 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
3211
3212 common_tfm_config
Valerio Settic5c4bd22023-08-03 14:28:20 +02003213
Valerio Settic5c4bd22023-08-03 14:28:20 +02003214 # Build crypto library specifying we want to use P256M code for EC operations
Manuel Pégourié-Gonnardeda70862023-09-22 12:17:50 +02003215 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 +02003216
Valerio Settic5c4bd22023-08-03 14:28:20 +02003217 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003218 not grep mbedtls_ecdsa_ library/ecdsa.o
Valerio Settic5c4bd22023-08-03 14:28:20 +02003219 not grep mbedtls_ecdh_ library/ecdh.o
3220 not grep mbedtls_ecjpake_ library/ecjpake.o
3221 # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003222 not grep mbedtls_ecp_ library/ecp.o
Valerio Settic5c4bd22023-08-03 14:28:20 +02003223 not grep mbedtls_rsa_ library/rsa.o
3224 not grep mbedtls_dhm_ library/dhm.o
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003225 not grep mbedtls_mpi_ library/bignum.o
Valerio Settic5c4bd22023-08-03 14:28:20 +02003226
3227 # Run the tests
Valerio Setti52ba0e32023-08-04 12:43:03 +02003228 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
Valerio Settic5c4bd22023-08-03 14:28:20 +02003229 make test
Valerio Setti52ba0e32023-08-04 12:43:03 +02003230}
Valerio Settic5c4bd22023-08-03 14:28:20 +02003231
Valerio Settiac6d35f2023-08-04 12:49:11 +02003232# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
3233# they are both meant to be used in analyze_outcomes.py for driver's coverage
3234# analysis.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003235component_test_tfm_config() {
3236 common_tfm_config
3237
3238 msg "build: TF-M config"
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02003239 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' tests
Valerio Setti52ba0e32023-08-04 12:43:03 +02003240
3241 msg "test: TF-M config"
3242 make test
Valerio Settic5c4bd22023-08-03 14:28:20 +02003243}
3244
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003245# Common helper for component_full_without_ecdhe_ecdsa() and
3246# component_full_without_ecdhe_ecdsa_and_tls13() which:
3247# - starts from the "full" configuration minus the list of symbols passed in
3248# as 1st parameter
3249# - build
3250# - test only TLS (i.e. test_suite_tls and ssl-opt)
3251build_full_minus_something_and_test_tls () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003252 symbols_to_disable="$1"
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003253
3254 msg "build: full minus something, test TLS"
3255
3256 scripts/config.py full
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003257 for sym in $symbols_to_disable; do
3258 echo "Disabling $sym"
3259 scripts/config.py unset $sym
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003260 done
3261
3262 make
3263
3264 msg "test: full minus something, test TLS"
3265 ( cd tests; ./test_suite_ssl )
3266
3267 msg "ssl-opt: full minus something, test TLS"
3268 tests/ssl-opt.sh
3269}
3270
3271component_full_without_ecdhe_ecdsa () {
3272 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED"
3273}
3274
3275component_full_without_ecdhe_ecdsa_and_tls13 () {
3276 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
3277 MBEDTLS_SSL_PROTO_TLS1_3"
3278}
3279
Valerio Setti249b18a2023-06-20 12:08:30 +02003280# This is an helper used by:
3281# - component_test_psa_ecc_key_pair_no_derive
3282# - component_test_psa_ecc_key_pair_no_generate
3283# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
3284# enabled, but one. Input arguments are as follows:
3285# - $1 is the key type under test, i.e. ECC/RSA/DH
3286# - $2 is the key option to be unset (i.e. generate, derive, etc)
Valerio Settia9836552023-06-22 11:22:23 +02003287build_and_test_psa_want_key_pair_partial() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003288 key_type=$1
3289 unset_option=$2
3290 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003291
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003292 msg "build: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003293 scripts/config.py full
Valerio Setti249b18a2023-06-20 12:08:30 +02003294 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3295 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3296
3297 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
3298 # crypto_config.h so we just disable the one we don't want.
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003299 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
Valerio Setti249b18a2023-06-20 12:08:30 +02003300
Valerio Settif6587be2023-06-22 11:33:14 +02003301 make CC=gcc CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Valerio Setti249b18a2023-06-20 12:08:30 +02003302
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003303 msg "test: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003304 make test
3305}
3306
3307component_test_psa_ecc_key_pair_no_derive() {
Valerio Settia9836552023-06-22 11:22:23 +02003308 build_and_test_psa_want_key_pair_partial "ECC" "DERIVE"
Valerio Setti249b18a2023-06-20 12:08:30 +02003309}
3310
3311component_test_psa_ecc_key_pair_no_generate() {
Valerio Settia9836552023-06-22 11:22:23 +02003312 build_and_test_psa_want_key_pair_partial "ECC" "GENERATE"
Valerio Setti249b18a2023-06-20 12:08:30 +02003313}
3314
Ronald Cron403c15c2021-09-13 09:38:05 +02003315component_test_psa_crypto_config_accel_rsa_signature () {
3316 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
3317
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003318 loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
3319
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003320 # Configure
3321 # ---------
Ronald Cron403c15c2021-09-13 09:38:05 +02003322
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003323 # Start from default config (no TLS 1.3, no USE_PSA)
3324 helper_libtestdriver1_adjust_config "default"
Ronald Cron403c15c2021-09-13 09:38:05 +02003325
3326 # It seems it is not possible to remove only the support for RSA signature
3327 # in the library. Thus we have to remove all RSA support (signature and
3328 # encryption/decryption). AS there is no driver support for asymmetric
3329 # encryption/decryption so far remove RSA encryption/decryption from the
3330 # application algorithm list.
Ronald Cron6b49b552023-07-20 09:57:54 +02003331 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3332 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
Ronald Cron403c15c2021-09-13 09:38:05 +02003333
Manuel Pégourié-Gonnardaed1d782023-06-12 17:22:24 +02003334 # Remove RSA support and its dependencies
3335 scripts/config.py unset MBEDTLS_RSA_C
3336 scripts/config.py unset MBEDTLS_PKCS1_V15
3337 scripts/config.py unset MBEDTLS_PKCS1_V21
3338 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
3339 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3340 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3341 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3342 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
3343 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
3344
Ronald Cron403c15c2021-09-13 09:38:05 +02003345 # Make sure both the library and the test library support the SHA hash
3346 # algorithms and only those ones (SHA256 is included by default). That way:
3347 # - the test library can compute the RSA signatures even in the case of a
3348 # composite RSA signature algorithm based on a SHA hash (no other hash
3349 # used in the unit tests).
3350 # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
3351 # fulfilled as the hash SHA algorithm is supported by the library, and
3352 # thus the tests are run, not skipped.
3353 # - when testing a signature key with an algorithm wildcard built from
3354 # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
3355 # algorithm based on the hashes supported by the library is also
3356 # supported by the test library.
Manuel Pégourié-Gonnardaed1d782023-06-12 17:22:24 +02003357 # Disable unwanted hashes here, we'll enable hashes we want in loc_extra_list.
Ronald Cron6b49b552023-07-20 09:57:54 +02003358 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3359 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160_C
Ronald Cron403c15c2021-09-13 09:38:05 +02003360 scripts/config.py unset MBEDTLS_MD5_C
3361 scripts/config.py unset MBEDTLS_RIPEMD160_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003362
3363 # We need PEM parsing in the test library as well to support the import
3364 # of PEM encoded RSA keys.
Ronald Cron7612d8c2023-07-20 10:03:54 +02003365 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
3366 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003367
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003368 # Build
3369 # -----
3370
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003371 # These hashes are needed for some RSA-PSS signature tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02003372 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3373 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003374 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02003375
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003376 helper_libtestdriver1_make_main "$loc_accel_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02003377
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003378 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine827dbd92022-02-04 00:30:54 +01003379 not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
3380 not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
Ronald Cron403c15c2021-09-13 09:38:05 +02003381
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003382 # Run the tests
3383 # -------------
3384
Ronald Cron403c15c2021-09-13 09:38:05 +02003385 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
3386 make test
3387}
3388
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003389# This is a temporary test to verify that full RSA support is present even when
Valerio Setti01cc88a2023-06-15 11:53:08 +02003390# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003391component_test_new_psa_want_key_pair_symbol() {
Valerio Setti01cc88a2023-06-15 11:53:08 +02003392 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003393
Valerio Setti4590bc22023-06-13 15:39:23 +02003394 # Create a temporary output file unless there is already one set
3395 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
3396 REMOVE_OUTCOME_ON_EXIT="no"
3397 else
3398 REMOVE_OUTCOME_ON_EXIT="yes"
3399 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
3400 export MBEDTLS_TEST_OUTCOME_FILE
3401 fi
3402
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003403 # Start from crypto configuration
3404 scripts/config.py crypto
3405
3406 # Remove RSA support and its dependencies
3407 scripts/config.py unset MBEDTLS_PKCS1_V15
3408 scripts/config.py unset MBEDTLS_PKCS1_V21
3409 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3410 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3411 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3412 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
3413 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
3414 scripts/config.py unset MBEDTLS_RSA_C
3415 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
3416
3417 # Enable PSA support
3418 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3419
Valerio Setti01cc88a2023-06-15 11:53:08 +02003420 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003421 # that proper translations is done in crypto_legacy.h.
Ronald Cron6b49b552023-07-20 09:57:54 +02003422 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
3423 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
3424 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003425
3426 make
3427
Valerio Setti01cc88a2023-06-15 11:53:08 +02003428 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Valerio Setti4590bc22023-06-13 15:39:23 +02003429 make test
3430
3431 # Parse only 1 relevant line from the outcome file, i.e. a test which is
3432 # performing RSA signature.
3433 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
3434 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
3435
3436 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
3437 rm $MBEDTLS_TEST_OUTCOME_FILE
3438 fi
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003439}
3440
Ronald Cronb2312452021-05-08 14:32:59 +02003441component_test_psa_crypto_config_accel_hash () {
3442 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
3443
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003444 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3445 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3446 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Ronald Cronb2312452021-05-08 14:32:59 +02003447
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003448 # Configure
3449 # ---------
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003450
3451 # Start from default config (no TLS 1.3, no USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003452 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003453
3454 # Disable the things that are being accelerated
Ronald Cronb2312452021-05-08 14:32:59 +02003455 scripts/config.py unset MBEDTLS_MD5_C
3456 scripts/config.py unset MBEDTLS_RIPEMD160_C
3457 scripts/config.py unset MBEDTLS_SHA1_C
Manuel Pégourié-Gonnardc584c272023-03-22 00:32:04 +01003458 scripts/config.py unset MBEDTLS_SHA224_C
3459 scripts/config.py unset MBEDTLS_SHA256_C
Ronald Cronb2312452021-05-08 14:32:59 +02003460 scripts/config.py unset MBEDTLS_SHA384_C
3461 scripts/config.py unset MBEDTLS_SHA512_C
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003462 scripts/config.py unset MBEDTLS_SHA3_C
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003463
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003464 # Build
3465 # -----
3466
3467 helper_libtestdriver1_make_drivers "$loc_accel_list"
3468
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003469 helper_libtestdriver1_make_main "$loc_accel_list"
Ronald Cronb2312452021-05-08 14:32:59 +02003470
Manuel Pégourié-Gonnardc584c272023-03-22 00:32:04 +01003471 # There's a risk of something getting re-enabled via config_psa.h;
3472 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
3473 not grep mbedtls_md5 library/md5.o
3474 not grep mbedtls_sha1 library/sha1.o
3475 not grep mbedtls_sha256 library/sha256.o
3476 not grep mbedtls_sha512 library/sha512.o
3477 not grep mbedtls_ripemd160 library/ripemd160.o
Ronald Cronb2312452021-05-08 14:32:59 +02003478
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003479 # Run the tests
3480 # -------------
3481
Ronald Cronb2312452021-05-08 14:32:59 +02003482 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
3483 make test
3484}
3485
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003486component_test_psa_crypto_config_accel_hash_keep_builtins () {
3487 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
3488 # This component ensures that all the test cases for
3489 # md_psa_dynamic_dispatch with legacy+driver in test_suite_md are run.
3490
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003491 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3492 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3493 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003494
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003495 # Start from default config (no TLS 1.3, no USE_PSA)
3496 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003497
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +02003498 helper_libtestdriver1_make_drivers "$loc_accel_list"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003499
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003500 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003501
3502 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
3503 make test
3504}
3505
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003506# Auxiliary function to build config for hashes with and without drivers
3507config_psa_crypto_hash_use_psa () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003508 driver_only="$1"
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003509 # start with config full for maximum coverage (also enables USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003510 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003511 if [ "$driver_only" -eq 1 ]; then
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003512 # disable the built-in implementation of hashes
3513 scripts/config.py unset MBEDTLS_MD5_C
3514 scripts/config.py unset MBEDTLS_RIPEMD160_C
3515 scripts/config.py unset MBEDTLS_SHA1_C
3516 scripts/config.py unset MBEDTLS_SHA224_C
3517 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
Dave Rodgman5b89c552023-10-10 14:59:02 +01003518 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003519 scripts/config.py unset MBEDTLS_SHA384_C
3520 scripts/config.py unset MBEDTLS_SHA512_C
3521 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003522 scripts/config.py unset MBEDTLS_SHA3_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003523 fi
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003524}
3525
Przemek Stekiel120ed8f2022-10-27 10:29:15 +02003526# Note that component_test_psa_crypto_config_reference_hash_use_psa
3527# is related to this component and both components need to be kept in sync.
3528# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003529component_test_psa_crypto_config_accel_hash_use_psa () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02003530 msg "test: full with accelerated hashes"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003531
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003532 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3533 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3534 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003535
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003536 # Configure
3537 # ---------
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003538
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003539 config_psa_crypto_hash_use_psa 1
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003540
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003541 # Build
3542 # -----
3543
3544 helper_libtestdriver1_make_drivers "$loc_accel_list"
3545
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003546 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003547
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003548 # There's a risk of something getting re-enabled via config_psa.h;
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01003549 # 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 +02003550 not grep mbedtls_md5 library/md5.o
3551 not grep mbedtls_sha1 library/sha1.o
Manuel Pégourié-Gonnard7b0825d2022-07-11 11:06:09 +02003552 not grep mbedtls_sha256 library/sha256.o
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003553 not grep mbedtls_sha512 library/sha512.o
3554 not grep mbedtls_ripemd160 library/ripemd160.o
3555
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003556 # Run the tests
3557 # -------------
3558
Gilles Peskine14302ed2023-07-19 19:30:04 +02003559 msg "test: full with accelerated hashes"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003560 make test
Andrzej Kurek07e35702022-09-05 15:39:23 -04003561
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003562 # This is mostly useful so that we can later compare outcome files with
3563 # the reference config in analyze_outcomes.py, to check that the
3564 # dependency declarations in ssl-opt.sh and in TLS code are correct.
Gilles Peskine14302ed2023-07-19 19:30:04 +02003565 msg "test: ssl-opt.sh, full with accelerated hashes"
Przemek Stekiel5f6f32a2022-10-27 08:24:43 +02003566 tests/ssl-opt.sh
Andrzej Kurek07e35702022-09-05 15:39:23 -04003567
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003568 # This is to make sure all ciphersuites are exercised, but we don't need
3569 # interop testing (besides, we already got some from ssl-opt.sh).
Gilles Peskine14302ed2023-07-19 19:30:04 +02003570 msg "test: compat.sh, full with accelerated hashes"
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003571 tests/compat.sh -p mbedTLS -V YES
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003572}
3573
Przemek Stekiel120ed8f2022-10-27 10:29:15 +02003574# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
3575# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
3576# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
3577# Both components need to be kept in sync.
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003578component_test_psa_crypto_config_reference_hash_use_psa() {
Gilles Peskine14302ed2023-07-19 19:30:04 +02003579 msg "test: full without accelerated hashes"
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003580
3581 config_psa_crypto_hash_use_psa 0
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003582
Przemek Stekielab0451b2022-10-24 11:29:35 +02003583 make
3584
Gilles Peskine14302ed2023-07-19 19:30:04 +02003585 msg "test: full without accelerated hashes"
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003586 make test
3587
Gilles Peskine14302ed2023-07-19 19:30:04 +02003588 msg "test: ssl-opt.sh, full without accelerated hashes"
Przemek Stekiel5f6f32a2022-10-27 08:24:43 +02003589 tests/ssl-opt.sh
Ronald Cron3a8714d2021-10-18 11:26:01 +02003590}
Manuel Pégourié-Gonnard97ab2a32022-07-06 10:46:57 +02003591
John Durkop4377bf72020-10-23 01:26:57 -07003592component_test_psa_crypto_config_accel_cipher () {
3593 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
3594
Valerio Setti0244fbb2023-10-19 10:42:31 +02003595 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 \
3596 ALG_CTR ALG_CFB ALG_OFB ALG_XTS ALG_CMAC \
3597 KEY_TYPE_DES"
John Durkop1b7ee052020-11-27 08:51:22 -08003598
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003599 # Configure
3600 # ---------
John Durkop1b7ee052020-11-27 08:51:22 -08003601
Valerio Setti9a427302023-10-17 11:40:42 +02003602 # Start from the full config
Valerio Settia797ce32023-10-03 15:16:38 +02003603 helper_libtestdriver1_adjust_config "full"
John Durkop1b7ee052020-11-27 08:51:22 -08003604
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003605 # Disable the things that are being accelerated
John Durkop1b7ee052020-11-27 08:51:22 -08003606 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3607 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
3608 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
3609 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
3610 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
3611 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
3612 scripts/config.py unset MBEDTLS_DES_C
Yanray Wangaf5003a2023-10-11 11:57:10 +08003613 scripts/config.py unset MBEDTLS_CMAC_C
John Durkop1b7ee052020-11-27 08:51:22 -08003614
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003615 # Build
3616 # -----
John Durkop1b7ee052020-11-27 08:51:22 -08003617
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003618 helper_libtestdriver1_make_drivers "$loc_accel_list"
3619
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003620 helper_libtestdriver1_make_main "$loc_accel_list"
John Durkop1b7ee052020-11-27 08:51:22 -08003621
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003622 # Make sure this was not re-enabled by accident (additive config)
John Durkop1b7ee052020-11-27 08:51:22 -08003623 not grep mbedtls_des* library/des.o
3624
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003625 # Run the tests
3626 # -------------
3627
John Durkop1b7ee052020-11-27 08:51:22 -08003628 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
3629 make test
3630}
3631
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003632component_test_psa_crypto_config_accel_aead () {
3633 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
3634
Valerio Setti3f02bb72023-10-02 15:57:33 +02003635 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
3636 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003637
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003638 # Configure
3639 # ---------
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003640
Valerio Setti3f02bb72023-10-02 15:57:33 +02003641 # Start from full config
3642 helper_libtestdriver1_adjust_config "full"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003643
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003644 # Disable things that are being accelerated
Przemek Stekielee1bb412022-10-11 11:52:25 +02003645 scripts/config.py unset MBEDTLS_GCM_C
3646 scripts/config.py unset MBEDTLS_CCM_C
3647 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003648
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003649 # Build
3650 # -----
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003651
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003652 helper_libtestdriver1_make_drivers "$loc_accel_list"
3653
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003654 helper_libtestdriver1_make_main "$loc_accel_list"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003655
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003656 # Make sure this was not re-enabled by accident (additive config)
Przemek Stekielee1bb412022-10-11 11:52:25 +02003657 not grep mbedtls_ccm library/ccm.o
3658 not grep mbedtls_gcm library/gcm.o
3659 not grep mbedtls_chachapoly library/chachapoly.o
3660
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003661 # Run the tests
3662 # -------------
3663
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003664 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
3665 make test
3666}
3667
Valerio Settib680fc42023-10-13 09:29:37 +02003668# This is a common configuration function used in:
3669# - component_test_psa_crypto_config_accel_cipher_aead
3670# - component_test_psa_crypto_config_reference_cipher_aead
3671common_psa_crypto_config_accel_cipher_aead() {
Valerio Settib680fc42023-10-13 09:29:37 +02003672 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Valerio Settib680fc42023-10-13 09:29:37 +02003673 scripts/config.py unset MBEDTLS_NIST_KW_C
3674}
3675
Valerio Settib6b301f2023-10-04 12:05:05 +02003676# The 2 following test components, i.e.
3677# - component_test_psa_crypto_config_accel_cipher_aead
3678# - component_test_psa_crypto_config_reference_cipher_aead
3679# are meant to be used together in analyze_outcomes.py script in order to test
3680# driver's coverage for ciphers and AEADs.
3681component_test_psa_crypto_config_accel_cipher_aead () {
3682 msg "test: crypto config with accelerated cipher and AEAD"
3683
Valerio Settiad8b7f02023-10-25 12:39:50 +02003684 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
3685 ALG_OFB ALG_XTS ALG_STREAM_CIPHER \
Valerio Setti97454fd2023-10-25 12:27:12 +02003686 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
Valerio Settib6b301f2023-10-04 12:05:05 +02003687 KEY_TYPE_DES KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
3688
3689 # Configure
3690 # ---------
3691
3692 # Start from the crypto config (no X509 and TLS)
Valerio Setti29bcd012023-10-12 18:54:58 +02003693 helper_libtestdriver1_adjust_config "crypto_full"
Valerio Settib6b301f2023-10-04 12:05:05 +02003694
Valerio Settib680fc42023-10-13 09:29:37 +02003695 common_psa_crypto_config_accel_cipher_aead
Valerio Settib6b301f2023-10-04 12:05:05 +02003696
3697 # Disable the things that are being accelerated
3698 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3699 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
3700 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
3701 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
3702 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
3703 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
3704 scripts/config.py unset MBEDTLS_GCM_C
3705 scripts/config.py unset MBEDTLS_CCM_C
3706 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Valerio Setti97454fd2023-10-25 12:27:12 +02003707 scripts/config.py unset MBEDTLS_CMAC_C
Valerio Settib6b301f2023-10-04 12:05:05 +02003708 scripts/config.py unset MBEDTLS_DES_C
3709 scripts/config.py unset MBEDTLS_AES_C
3710 scripts/config.py unset MBEDTLS_ARIA_C
3711 scripts/config.py unset MBEDTLS_CHACHA20_C
3712 scripts/config.py unset MBEDTLS_CAMELLIA_C
3713
Valerio Settib6b301f2023-10-04 12:05:05 +02003714 # Build
3715 # -----
3716
3717 helper_libtestdriver1_make_drivers "$loc_accel_list"
3718
3719 helper_libtestdriver1_make_main "$loc_accel_list"
3720
3721 # Make sure this was not re-enabled by accident (additive config)
Valerio Setti58d2b1a2023-10-12 15:24:12 +02003722 not grep mbedtls_des library/des.o
3723 not grep mbedtls_aes library/aes.o
3724 not grep mbedtls_aria library/aria.o
3725 not grep mbedtls_camellia library/camellia.o
Valerio Settib6b301f2023-10-04 12:05:05 +02003726 not grep mbedtls_ccm library/ccm.o
3727 not grep mbedtls_gcm library/gcm.o
3728 not grep mbedtls_chachapoly library/chachapoly.o
3729 not grep mbedtls_cmac library/cmac.o
3730
3731 # Run the tests
3732 # -------------
3733
3734 msg "test: crypto config with accelerated cipher and AEAD"
3735 make test
3736}
3737
3738component_test_psa_crypto_config_reference_cipher_aead () {
Valerio Setti29bcd012023-10-12 18:54:58 +02003739 helper_libtestdriver1_adjust_config "crypto_full"
Valerio Settib6b301f2023-10-04 12:05:05 +02003740
Valerio Settib680fc42023-10-13 09:29:37 +02003741 common_psa_crypto_config_accel_cipher_aead
Valerio Settib6b301f2023-10-04 12:05:05 +02003742
Valerio Settib6b301f2023-10-04 12:05:05 +02003743 msg "test: crypto config with non-accelerated cipher and AEAD"
3744 make test
3745}
3746
Gilles Peskine36dea152023-07-20 22:19:45 +02003747component_test_aead_chachapoly_disabled() {
3748 msg "build: full minus CHACHAPOLY"
John Durkopf4c4cb02020-10-28 20:09:55 -07003749 scripts/config.py full
John Durkop9814fa22020-11-04 12:28:15 -08003750 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Ronald Cron6b49b552023-07-20 09:57:54 +02003751 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
John Durkopf4c4cb02020-10-28 20:09:55 -07003752 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop6ba40d12020-11-10 08:50:04 -08003753
Gilles Peskine36dea152023-07-20 22:19:45 +02003754 msg "test: full minus CHACHAPOLY"
3755 make test
3756}
3757
3758component_test_aead_only_ccm() {
3759 msg "build: full minus CHACHAPOLY and GCM"
3760 scripts/config.py full
3761 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
3762 scripts/config.py unset MBEDTLS_GCM_C
3763 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
3764 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
3765 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
3766
3767 msg "test: full minus CHACHAPOLY and GCM"
John Durkop9814fa22020-11-04 12:28:15 -08003768 make test
John Durkopf4c4cb02020-10-28 20:09:55 -07003769}
3770
Ronald Crone501d0e2023-07-10 08:31:19 +02003771component_test_ccm_aes_sha256() {
3772 msg "build: CCM + AES + SHA256 configuration"
3773
Ronald Cron7612d8c2023-07-20 10:03:54 +02003774 cp "$CONFIG_TEST_DRIVER_H" "$CONFIG_H"
Ronald Cron6b49b552023-07-20 09:57:54 +02003775 cp configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
Ronald Crone501d0e2023-07-10 08:31:19 +02003776
3777 make CC=gcc
3778
3779 msg "test: CCM + AES + SHA256 configuration"
3780 make test
3781}
3782
John Durkop9814fa22020-11-04 12:28:15 -08003783# 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 -07003784component_build_psa_accel_alg_ecdh() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003785 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
John Durkopd0321952020-10-29 21:37:36 -07003786 scripts/config.py full
John Durkopd0321952020-10-29 21:37:36 -07003787 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003788 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkopd0321952020-10-29 21:37:36 -07003789 scripts/config.py unset MBEDTLS_ECDH_C
3790 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3791 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
3792 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
3793 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3794 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
3795 # 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 -08003796 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 -07003797}
3798
John Durkop1b7ee052020-11-27 08:51:22 -08003799# This should be renamed to test and updated once the accelerator HMAC code is in place and ready to test.
3800component_build_psa_accel_alg_hmac() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003801 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
John Durkop1b7ee052020-11-27 08:51:22 -08003802 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003803 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003804 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkop1b7ee052020-11-27 08:51:22 -08003805 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3806 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3807}
3808
3809# This should be renamed to test and updated once the accelerator HKDF code is in place and ready to test.
3810component_build_psa_accel_alg_hkdf() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003811 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
John Durkop1b7ee052020-11-27 08:51:22 -08003812 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003813 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003814 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkop1b7ee052020-11-27 08:51:22 -08003815 scripts/config.py unset MBEDTLS_HKDF_C
Ronald Cron6f135e12021-12-08 16:57:54 +01003816 # Make sure to unset TLS1_3 since it requires HKDF_C and will not build properly without it.
3817 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkop1b7ee052020-11-27 08:51:22 -08003818 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3819 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3820}
3821
3822# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
3823component_build_psa_accel_alg_md5() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003824 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003825 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003826 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003827 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003828 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3829 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3830 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3831 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3832 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3833 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3834 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003835 scripts/config.py unset MBEDTLS_LMS_C
3836 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003837 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3838 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3839}
3840
3841# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
3842component_build_psa_accel_alg_ripemd160() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003843 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003844 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003845 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003846 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003847 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3848 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3849 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3850 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3851 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3852 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3853 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003854 scripts/config.py unset MBEDTLS_LMS_C
3855 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003856 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3857 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3858}
3859
3860# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
3861component_build_psa_accel_alg_sha1() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003862 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003863 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003864 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003865 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003866 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3867 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3868 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3869 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3870 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3871 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3872 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003873 scripts/config.py unset MBEDTLS_LMS_C
3874 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003875 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3876 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3877}
3878
3879# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
3880component_build_psa_accel_alg_sha224() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003881 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003882 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003883 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003884 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003885 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3886 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3887 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3888 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3889 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3890 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
John Durkop1b7ee052020-11-27 08:51:22 -08003891 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3892 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3893}
3894
3895# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
3896component_build_psa_accel_alg_sha256() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003897 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003898 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003899 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003900 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003901 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3902 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3903 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3904 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3905 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3906 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
John Durkop1b7ee052020-11-27 08:51:22 -08003907 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3908 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3909}
3910
3911# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
3912component_build_psa_accel_alg_sha384() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003913 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003914 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003915 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003916 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003917 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3918 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3919 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3920 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3921 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3922 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003923 scripts/config.py unset MBEDTLS_LMS_C
3924 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003925 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3926 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3927}
3928
3929# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
3930component_build_psa_accel_alg_sha512() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003931 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003932 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003933 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003934 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003935 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3936 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3937 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3938 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3939 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3940 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3941 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003942 scripts/config.py unset MBEDTLS_LMS_C
3943 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003944 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3945 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3946}
3947
John Durkopd0321952020-10-29 21:37:36 -07003948# 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 -08003949component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003950 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 -07003951 scripts/config.py full
John Durkopd0321952020-10-29 21:37:36 -07003952 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003953 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003954 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
3955 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3956 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3957 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07003958 # 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 -07003959 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3960}
3961
3962# 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 -08003963component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003964 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 -07003965 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003966 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003967 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003968 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
3969 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3970 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3971 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07003972 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3973 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3974}
3975
3976# 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 -08003977component_build_psa_accel_alg_rsa_oaep() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003978 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 -07003979 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003980 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003981 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003982 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_OAEP 1
3983 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3984 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3985 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07003986 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3987 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3988}
3989
3990# 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 -08003991component_build_psa_accel_alg_rsa_pss() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003992 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 -07003993 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003994 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003995 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003996 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
3997 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3998 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3999 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07004000 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4001 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
4002}
4003
4004# 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 -08004005component_build_psa_accel_key_type_rsa_key_pair() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02004006 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 -07004007 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07004008 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01004009 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02004010 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
4011 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC 1
4012 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT 1
4013 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT 1
4014 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE 1
John Durkopbd069d32020-10-31 22:14:03 -07004015 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4016 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"
4017}
4018
4019# 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 -08004020component_build_psa_accel_key_type_rsa_public_key() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02004021 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 -07004022 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07004023 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01004024 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02004025 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
4026 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
John Durkopbd069d32020-10-31 22:14:03 -07004027 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4028 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 -07004029}
4030
Dave Rodgmanc164c072023-06-28 09:43:23 +01004031
Dave Rodgman904c5892023-06-28 17:36:02 +01004032support_build_tfm_armcc () {
Dave Rodgmanc164c072023-06-28 09:43:23 +01004033 armc6_cc="$ARMC6_BIN_DIR/armclang"
4034 (check_tools "$armc6_cc" > /dev/null 2>&1)
4035}
4036
Dave Rodgman904c5892023-06-28 17:36:02 +01004037component_build_tfm_armcc() {
4038 # test the TF-M configuration can build cleanly with various warning flags enabled
Ronald Cron7a93ac52023-07-20 09:49:12 +02004039 cp configs/tfm_mbedcrypto_config_profile_medium.h "$CONFIG_H"
Ronald Cron6b49b552023-07-20 09:57:54 +02004040 cp configs/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Dave Rodgmanc164c072023-06-28 09:43:23 +01004041
Dave Rodgman88651c42023-06-29 12:35:51 +01004042 msg "build: TF-M config, armclang armv7-m thumb2"
Dave Rodgmanfb374e62023-06-29 11:58:16 +01004043 make clean
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02004044 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 +01004045}
4046
4047component_build_tfm() {
4048 # test the TF-M configuration can build cleanly with various warning flags enabled
Ronald Cron7a93ac52023-07-20 09:49:12 +02004049 cp configs/tfm_mbedcrypto_config_profile_medium.h "$CONFIG_H"
Ronald Cron6b49b552023-07-20 09:57:54 +02004050 cp configs/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Dave Rodgmanfb374e62023-06-29 11:58:16 +01004051
Dave Rodgman88651c42023-06-29 12:35:51 +01004052 msg "build: TF-M config, clang, armv7-m thumb2"
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02004053 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 +01004054
Dave Rodgman904c5892023-06-28 17:36:02 +01004055 msg "build: TF-M config, gcc native build"
4056 make clean
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02004057 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 +01004058}
4059
Dave Rodgman54ada8b2023-10-04 11:55:25 +01004060# Test that the given .o file builds with all (valid) combinations of the given options.
4061#
4062# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
4063#
4064# The validator function is the name of a function to validate the combination of options.
4065# It may be "" if all combinations are valid.
4066# It receives a string containing a combination of options, as passed to the compiler,
Dave Rodgmanf3803a12023-10-16 13:47:15 +01004067# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Dave Rodgman920343a2023-10-01 18:41:09 +01004068build_test_config_combos() {
Dave Rodgman28e38d82023-10-04 11:50:30 +01004069 file=$1
Dave Rodgman920343a2023-10-01 18:41:09 +01004070 shift
Dave Rodgman28e38d82023-10-04 11:50:30 +01004071 validate_options=$1
Dave Rodgman920343a2023-10-01 18:41:09 +01004072 shift
Dave Rodgman28e38d82023-10-04 11:50:30 +01004073 options=("$@")
Dave Rodgman0f0f7692023-06-29 12:10:45 +01004074
Dave Rodgman42436102023-10-03 15:47:05 +01004075 # clear all of the options so that they can be overridden on the clang commandline
Dave Rodgman28e38d82023-10-04 11:50:30 +01004076 for opt in "${options[@]}"; do
4077 ./scripts/config.py unset ${opt}
Dave Rodgman42436102023-10-03 15:47:05 +01004078 done
4079
4080 # enter the directory containing the target file & strip the dir from the filename
Dave Rodgman28e38d82023-10-04 11:50:30 +01004081 cd $(dirname ${file})
4082 file=$(basename ${file})
Dave Rodgman42436102023-10-03 15:47:05 +01004083
Dave Rodgman920343a2023-10-01 18:41:09 +01004084 # The most common issue is unused variables/functions, so ensure -Wunused is set.
Dave Rodgman28e38d82023-10-04 11:50:30 +01004085 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 +01004086
Dave Rodgman42436102023-10-03 15:47:05 +01004087 # Extract the command generated by the Makefile to build the target file.
4088 # This ensures that we have any include paths, macro definitions, etc
4089 # that may be applied by make.
4090 # 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 +01004091 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
Dave Rodgman42436102023-10-03 15:47:05 +01004092
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01004093 makefile=$(TMPDIR=. mktemp)
Dave Rodgman28e38d82023-10-04 11:50:30 +01004094 deps=""
Dave Rodgman97285622023-09-29 17:32:06 +01004095
Dave Rodgman28e38d82023-10-04 11:50:30 +01004096 len=${#options[@]}
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01004097 source_file=${file%.o}.c
4098
4099 targets=0
4100 echo 'include Makefile' >${makefile}
Dave Rodgman97285622023-09-29 17:32:06 +01004101
Dave Rodgman28e38d82023-10-04 11:50:30 +01004102 for ((i = 0; i < $((2**${len})); i++)); do
Dave Rodgman920343a2023-10-01 18:41:09 +01004103 # generate each of 2^n combinations of options
Dave Rodgman28e38d82023-10-04 11:50:30 +01004104 # each bit of $i is used to determine if options[i] will be set or not
4105 target="t"
4106 clang_args=""
4107 for ((j = 0; j < ${len}; j++)); do
Dave Rodgmanb1107ae2023-10-04 12:30:23 +01004108 if (((i >> j) & 1)); then
Dave Rodgmana7127eb2023-10-04 13:38:41 +01004109 opt=-D${options[$j]}
Dave Rodgman7a8a2492023-10-04 13:14:20 +01004110 clang_args="${clang_args} ${opt}"
4111 target="${target}${opt}"
Dave Rodgmanb1107ae2023-10-04 12:30:23 +01004112 fi
Dave Rodgman920343a2023-10-01 18:41:09 +01004113 done
4114
Dave Rodgmanb1107ae2023-10-04 12:30:23 +01004115 # if combination is not known to be invalid, add it to the makefile
Dave Rodgmanf3803a12023-10-16 13:47:15 +01004116 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
Dave Rodgman28e38d82023-10-04 11:50:30 +01004117 cmd="${compile_cmd} ${clang_args}"
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01004118 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
Dave Rodgman920343a2023-10-01 18:41:09 +01004119
Dave Rodgman28e38d82023-10-04 11:50:30 +01004120 deps="${deps} ${target}"
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01004121 ((++targets))
Dave Rodgman745af9f2023-09-29 15:47:07 +01004122 fi
Dave Rodgman97285622023-09-29 17:32:06 +01004123 done
Dave Rodgman6001fb22023-06-29 09:29:00 +01004124
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01004125 echo "build_test_config_combos: ${deps}" >> ${makefile}
Dave Rodgmanaea01c92023-09-29 18:54:49 +01004126
Dave Rodgman920343a2023-10-01 18:41:09 +01004127 # execute all of the commands via Make (probably in parallel)
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01004128 make -s -f ${makefile} build_test_config_combos
4129 echo "$targets targets checked"
Dave Rodgman920343a2023-10-01 18:41:09 +01004130
4131 # clean up the temporary makefile
Dave Rodgman28e38d82023-10-04 11:50:30 +01004132 rm ${makefile}
Dave Rodgman6001fb22023-06-29 09:29:00 +01004133}
4134
Dave Rodgman43a5ce82023-10-02 17:09:37 +01004135validate_aes_config_variations() {
Dave Rodgman920343a2023-10-01 18:41:09 +01004136 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
4137 if [[ "$1" == *"MBEDTLS_PADLOCK_C"* ]]; then
Dave Rodgman41bc7982023-10-16 14:04:21 +01004138 return 1
Dave Rodgman920343a2023-10-01 18:41:09 +01004139 fi
4140 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
4141 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
Dave Rodgman41bc7982023-10-16 14:04:21 +01004142 return 1
Dave Rodgman920343a2023-10-01 18:41:09 +01004143 fi
4144 fi
Dave Rodgman41bc7982023-10-16 14:04:21 +01004145 return 0
Dave Rodgman920343a2023-10-01 18:41:09 +01004146}
4147
4148component_build_aes_variations() {
4149 # 18s - around 90ms per clang invocation on M1 Pro
4150 #
4151 # aes.o has many #if defined(...) guards that intersect in complex ways.
4152 # Test that all the combinations build cleanly.
4153
4154 msg "build: aes.o for all combinations of relevant config options"
4155
Dave Rodgman42436102023-10-03 15:47:05 +01004156 build_test_config_combos library/aes.o validate_aes_config_variations \
Dave Rodgman920343a2023-10-01 18:41:09 +01004157 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
4158 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
4159 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
4160 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
4161}
4162
Gilles Peskine8f073122018-11-27 15:58:47 +01004163component_test_no_platform () {
4164 # Full configuration build, without platform support, file IO and net sockets.
4165 # This should catch missing mbedtls_printf definitions, and by disabling file
4166 # IO, it should catch missing '#include <stdio.h>'
4167 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004168 scripts/config.py full
4169 scripts/config.py unset MBEDTLS_PLATFORM_C
4170 scripts/config.py unset MBEDTLS_NET_C
4171 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
4172 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
4173 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
4174 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskineef843f22022-09-18 14:05:23 +02004175 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004176 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
4177 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskine6497b5a2022-06-30 17:01:40 +02004178 scripts/config.py unset MBEDTLS_PLATFORM_SETBUF_ALT
Gilles Peskine32e889d2020-04-12 23:43:28 +02004179 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004180 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
4181 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004182 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004183 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
4184 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01004185 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
4186 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02004187 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
4188 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01004189}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00004190
Gilles Peskine8f073122018-11-27 15:58:47 +01004191component_build_no_std_function () {
4192 # catch compile bugs in _uninit functions
4193 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004194 scripts/config.py full
4195 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
4196 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02004197 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinef4d2fd42021-10-08 11:45:47 +02004198 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskinedbf7b7e2021-10-07 19:34:57 +02004199 make
Gilles Peskine8f073122018-11-27 15:58:47 +01004200}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01004201
Gilles Peskine8f073122018-11-27 15:58:47 +01004202component_build_no_ssl_srv () {
Ronald Cronde1adee2022-03-07 16:20:30 +01004203 msg "build: full config except SSL server, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004204 scripts/config.py full
4205 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02004206 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01004207}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02004208
Gilles Peskine8f073122018-11-27 15:58:47 +01004209component_build_no_ssl_cli () {
Ronald Cronde1adee2022-03-07 16:20:30 +01004210 msg "build: full config except SSL client, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004211 scripts/config.py full
4212 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02004213 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01004214}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02004215
Gilles Peskine8f073122018-11-27 15:58:47 +01004216component_build_no_sockets () {
4217 # Note, C99 compliance can also be tested with the sockets support disabled,
4218 # as that requires a POSIX platform (which isn't the same as C99).
4219 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004220 scripts/config.py full
4221 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
4222 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02004223 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01004224}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02004225
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04004226component_test_memory_buffer_allocator_backtrace () {
4227 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004228 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4229 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4230 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
4231 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02004232 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04004233 make
4234
4235 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
4236 make test
4237}
4238
4239component_test_memory_buffer_allocator () {
4240 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004241 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4242 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02004243 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Hanno Becker0fb9ba22019-02-26 14:34:13 +00004244 make
4245
4246 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
4247 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01004248
4249 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
4250 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004251 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00004252}
4253
Gilles Peskine8f073122018-11-27 15:58:47 +01004254component_test_no_max_fragment_length () {
4255 # Run max fragment length tests with MFL disabled
4256 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004257 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01004258 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4259 make
Hanno Becker5175ac62017-09-18 15:36:25 +01004260
Gilles Peskine8f073122018-11-27 15:58:47 +01004261 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004262 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01004263}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004264
Hanno Becker545ced42019-02-19 11:10:48 +00004265component_test_asan_remove_peer_certificate () {
4266 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004267 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00004268 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4269 make
4270
4271 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
4272 make test
4273
4274 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004275 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00004276
4277 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004278 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02004279
4280 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004281 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00004282}
4283
Gilles Peskine8f073122018-11-27 15:58:47 +01004284component_test_no_max_fragment_length_small_ssl_out_content_len () {
4285 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004286 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4287 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
4288 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01004289 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4290 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10004291
Gilles Peskine8f073122018-11-27 15:58:47 +01004292 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004293 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02004294
4295 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004296 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01004297}
Angus Grattonc4dd0732018-04-11 16:28:39 +10004298
Darryl Greenaad82f92019-12-02 10:53:11 +00004299component_test_variable_ssl_in_out_buffer_len () {
4300 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
4301 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
4302 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4303 make
4304
4305 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
4306 make test
4307
4308 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004309 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004310
4311 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004312 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004313}
4314
Manuel Pégourié-Gonnard6a543ba2022-11-25 11:30:10 +01004315component_test_dtls_cid_legacy () {
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004316 msg "build: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled (ASan build)"
Hannes Tschofenigfd6cca42021-10-12 09:22:33 +02004317 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 1
Darryl Greenaad82f92019-12-02 10:53:11 +00004318
4319 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4320 make
4321
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004322 msg "test: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy)"
Darryl Greenaad82f92019-12-02 10:53:11 +00004323 make test
4324
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004325 msg "test: ssl-opt.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004326 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004327
Manuel Pégourié-Gonnard6a543ba2022-11-25 11:30:10 +01004328 msg "test: compat.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004329 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004330}
4331
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004332component_test_ssl_alloc_buffer_and_mfl () {
4333 msg "build: default config with memory buffer allocator and MFL extension"
4334 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4335 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4336 scripts/config.py set MBEDTLS_MEMORY_DEBUG
4337 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4338 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02004339 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004340 make
4341
4342 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
4343 make test
4344
4345 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 +02004346 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004347}
4348
Gilles Peskine636c26a2020-03-04 20:46:15 +01004349component_test_when_no_ciphersuites_have_mac () {
4350 msg "build: when no ciphersuites have MAC"
4351 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Gilles Peskine636c26a2020-03-04 20:46:15 +01004352 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
TRodziewicz2add5c12021-04-28 16:50:20 +02004353 scripts/config.py unset MBEDTLS_CMAC_C
Gilles Peskine636c26a2020-03-04 20:46:15 +01004354 make
4355
4356 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
4357 make test
4358
4359 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004360 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01004361}
4362
Raoul Strackxa4e86142020-06-15 17:03:13 +02004363component_test_no_date_time () {
4364 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
4365 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
Gilles Peskinef4d2fd42021-10-08 11:45:47 +02004366 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Raoul Strackxa4e86142020-06-15 17:03:13 +02004367 make
4368
4369 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
4370 make test
4371}
4372
Gilles Peskine8f073122018-11-27 15:58:47 +01004373component_test_platform_calloc_macro () {
4374 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004375 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4376 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
4377 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01004378 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4379 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01004380
Gilles Peskine8f073122018-11-27 15:58:47 +01004381 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
4382 make test
4383}
Hanno Beckere5fecec2018-10-11 11:02:52 +01004384
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02004385component_test_malloc_0_null () {
4386 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004387 scripts/config.py full
Gilles Peskinecf4fe582023-07-20 19:00:15 +02004388 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 +02004389
4390 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
4391 make test
4392
4393 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
4394 # Just the calloc selftest. "make test" ran the others as part of the
4395 # test suites.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004396 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01004397
4398 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
4399 # Run a subset of the tests. The choice is a balance between coverage
4400 # and time (including time indirectly wasted due to flaky tests).
4401 # The current choice is to skip tests whose description includes
4402 # "proxy", which is an approximation of skipping tests that use the
4403 # UDP proxy, which tend to be slower and flakier.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004404 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02004405}
4406
Dave Rodgman6a08b682023-06-19 11:51:33 +01004407support_test_aesni() {
4408 # Check that gcc targets x86_64 (we can build AESNI), and check for
4409 # AESNI support on the host (we can run AESNI).
4410 #
4411 # The name of this function is possibly slightly misleading, but needs to align
4412 # with the name of the corresponding test, component_test_aesni.
Dave Rodgmanf8986e32023-06-19 10:55:59 +01004413 #
4414 # In principle 32-bit x86 can support AESNI, but our implementation does not
4415 # support 32-bit x86, so we check for x86-64.
4416 # We can only grep /proc/cpuinfo on Linux, so this also checks for Linux
Dave Rodgman6a08b682023-06-19 11:51:33 +01004417 (gcc -v 2>&1 | grep Target | grep -q x86_64) &&
4418 [[ "$HOSTTYPE" == "x86_64" && "$OSTYPE" == "linux-gnu" ]] &&
Jerry Yua7de78d2023-08-08 12:57:35 +08004419 (lscpu | grep -qw aes)
Dave Rodgmanf8986e32023-06-19 10:55:59 +01004420}
4421
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004422component_test_aesni () { # ~ 60s
4423 # This tests the two AESNI implementations (intrinsics and assembly), and also the plain C
4424 # fallback. It also tests the logic that is used to select which implementation(s) to build.
4425 #
4426 # This test does not require the host to have support for AESNI (if it doesn't, the run-time
4427 # AESNI detection will fallback to the plain C implementation, so the tests will instead
4428 # exercise the plain C impl).
4429
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004430 msg "build: default config with different AES implementations"
Dave Rodgman838dc462023-06-16 13:18:19 +01004431 scripts/config.py set MBEDTLS_AESNI_C
Jerry Yu17a9d2e2023-08-03 16:14:18 +08004432 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Dave Rodgman838dc462023-06-16 13:18:19 +01004433 scripts/config.py set MBEDTLS_HAVE_ASM
4434
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004435 # test the intrinsics implementation
4436 msg "AES tests, test intrinsics"
Dave Rodgman838dc462023-06-16 13:18:19 +01004437 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004438 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004439 # check that we built intrinsics - this should be used by default when supported by the compiler
Jerry Yu1221a312023-08-03 16:09:07 +08004440 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004441
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004442 # test the asm implementation
4443 msg "AES tests, test assembly"
4444 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004445 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mno-pclmul -mno-sse2 -mno-aes'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004446 # check that we built assembly - this should be built if the compiler does not support intrinsics
Jerry Yu1221a312023-08-03 16:09:07 +08004447 ./programs/test/selftest aes | grep "AESNI code" | grep -q "assembly"
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004448
4449 # test the plain C implementation
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004450 scripts/config.py unset MBEDTLS_AESNI_C
Jerry Yu17a9d2e2023-08-03 16:14:18 +08004451 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004452 msg "AES tests, plain C"
4453 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004454 make CC=gcc CFLAGS='-O2 -Werror'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004455 # check that there is no AESNI code present
Jerry Yu1221a312023-08-03 16:09:07 +08004456 ./programs/test/selftest aes | not grep -q "AESNI code"
Jerry Yu76a51b92023-08-08 16:03:55 +08004457 not grep -q "AES note: using AESNI" ./programs/test/selftest
4458 grep -q "AES note: built-in implementation." ./programs/test/selftest
Jerry Yu8a599c02023-08-03 17:01:02 +08004459
4460 # test the intrinsics implementation
4461 scripts/config.py set MBEDTLS_AESNI_C
4462 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4463 msg "AES tests, test AESNI only"
4464 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004465 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
Jerry Yua7de78d2023-08-08 12:57:35 +08004466 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
4467 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
Jerry Yu76a51b92023-08-08 16:03:55 +08004468 grep -q "AES note: using AESNI" ./programs/test/selftest
4469 not grep -q "AES note: built-in implementation." ./programs/test/selftest
Dave Rodgman838dc462023-06-16 13:18:19 +01004470}
4471
Jerry Yu193cbc02023-08-03 17:06:29 +08004472
Jerry Yub6d39c22023-08-16 15:11:48 +08004473
4474support_test_aesni_m32() {
4475 support_test_m32_o0 && (lscpu | grep -qw aes)
4476}
4477
4478component_test_aesni_m32 () { # ~ 60s
4479 # This tests are duplicated from component_test_aesni for i386 target
4480 #
4481 # AESNI intrinsic code supports i386 and assembly code does not support it.
4482
4483 msg "build: default config with different AES implementations"
4484 scripts/config.py set MBEDTLS_AESNI_C
4485 scripts/config.py set MBEDTLS_PADLOCK_C
4486 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4487 scripts/config.py set MBEDTLS_HAVE_ASM
4488
4489 # test the intrinsics implementation
4490 msg "AES tests, test intrinsics"
4491 make clean
4492 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
4493 # check that we built intrinsics - this should be used by default when supported by the compiler
4494 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
4495 grep -q "AES note: using AESNI" ./programs/test/selftest
4496 grep -q "AES note: built-in implementation." ./programs/test/selftest
4497 grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4498 grep -q mbedtls_aesni_has_support ./programs/test/selftest
4499
4500 scripts/config.py set MBEDTLS_AESNI_C
Jerry Yub6d39c22023-08-16 15:11:48 +08004501 scripts/config.py unset MBEDTLS_PADLOCK_C
4502 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4503 msg "AES tests, test AESNI only"
4504 make clean
4505 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
4506 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
4507 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
4508 grep -q "AES note: using AESNI" ./programs/test/selftest
4509 not grep -q "AES note: built-in implementation." ./programs/test/selftest
4510 not grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4511 not grep -q mbedtls_aesni_has_support ./programs/test/selftest
4512}
4513
Jerry Yu193cbc02023-08-03 17:06:29 +08004514# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
4515component_build_aes_aesce_armcc () {
4516 msg "Build: AESCE test on arm64 platform without plain C."
4517 scripts/config.py baremetal
4518
4519 # armc[56] don't support SHA-512 intrinsics
4520 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
4521
4522 # Stop armclang warning about feature detection for A64_CRYPTO.
4523 # With this enabled, the library does build correctly under armclang,
4524 # but in baremetal builds (as tested here), feature detection is
4525 # unavailable, and the user is notified via a #warning. So enabling
4526 # this feature would prevent us from building with -Werror on
4527 # armclang. Tracked in #7198.
Dave Rodgman5b89c552023-10-10 14:59:02 +01004528 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Jerry Yu193cbc02023-08-03 17:06:29 +08004529 scripts/config.py set MBEDTLS_HAVE_ASM
4530
4531 msg "AESCE, build with default configuration."
4532 scripts/config.py set MBEDTLS_AESCE_C
4533 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4534 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
4535
4536 msg "AESCE, build AESCE only"
4537 scripts/config.py set MBEDTLS_AESCE_C
4538 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4539 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
4540}
4541
Dave Rodgman9ed18532023-10-05 00:06:47 +01004542support_build_sha_armce() {
Dave Rodgmanf2ea08a2023-10-16 11:37:28 +01004543 if command -v clang > /dev/null ; then
Dave Rodgmand35b1882023-10-16 10:25:30 +01004544 # clang >= 4 is required to build with SHA extensions
4545 clang_ver="$(clang --version|grep version|sed -E 's#.*version ([0-9]+).*#\1#')"
Dave Rodgmanab0cff52023-10-13 09:32:04 +01004546
Dave Rodgman66d55122023-10-23 15:12:32 +01004547 [[ "${clang_ver}" -ge 4 ]]
Dave Rodgmand35b1882023-10-16 10:25:30 +01004548 else
4549 # clang not available
4550 false
4551 fi
Dave Rodgman9ed18532023-10-05 00:06:47 +01004552}
4553
Dave Rodgmand9e80832023-10-04 17:17:46 +01004554component_build_sha_armce () {
Dave Rodgman5b89c552023-10-10 14:59:02 +01004555 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004556
4557
4558 # Test variations of SHA256 Armv8 crypto extensions
Dave Rodgman5b89c552023-10-10 14:59:02 +01004559 scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004560 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, aarch64"
4561 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
4562 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, arm"
4563 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
4564 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
Dave Rodgmand9e80832023-10-04 17:17:46 +01004565
Dave Rodgmand9e80832023-10-04 17:17:46 +01004566
Dave Rodgman94a634d2023-10-10 12:59:29 +01004567 # test the deprecated form of the config option
Dave Rodgman94a634d2023-10-10 12:59:29 +01004568 scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004569 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY clang, thumb"
4570 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
4571 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
Dave Rodgmand9e80832023-10-04 17:17:46 +01004572
Dave Rodgman5b89c552023-10-10 14:59:02 +01004573 scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004574 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT clang, aarch64"
4575 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
4576 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Dave Rodgmand9e80832023-10-04 17:17:46 +01004577
Dave Rodgmancd654002023-10-05 09:40:07 +01004578
Dave Rodgman94a634d2023-10-10 12:59:29 +01004579 # test the deprecated form of the config option
Dave Rodgman94a634d2023-10-10 12:59:29 +01004580 scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004581 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, arm"
4582 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -std=c99"
4583 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, thumb"
4584 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
4585 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
Dave Rodgman94a634d2023-10-10 12:59:29 +01004586
Dave Rodgmancd654002023-10-05 09:40:07 +01004587
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004588 # examine the disassembly for presence of SHA instructions
4589 for opt in MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT; do
4590 scripts/config.py set ${opt}
4591 msg "${opt} clang, test A32 crypto instructions built"
4592 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
4593 grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4594
4595 msg "${opt} clang, test T32 crypto instructions built"
4596 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
4597 grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4598
4599 msg "${opt} clang, test aarch64 crypto instructions built"
4600 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
4601 grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.o
4602 scripts/config.py unset ${opt}
4603 done
4604
4605
4606 # examine the disassembly for absence of SHA instructions
4607 msg "clang, test A32 crypto instructions not built"
4608 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
4609 not grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4610
4611 msg "clang, test T32 crypto instructions not built"
4612 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
4613 not grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4614
4615 msg "clang, test aarch64 crypto instructions not built"
4616 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
4617 not grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.o
Dave Rodgmand9e80832023-10-04 17:17:46 +01004618}
4619
Jerry Yuc935aa62023-08-03 17:08:27 +08004620# For timebeing, no VIA Padlock platform available.
4621component_build_aes_via_padlock () {
4622
4623 msg "AES:VIA PadLock, build with default configuration."
Jerry Yu506759f2023-08-16 17:11:22 +08004624 scripts/config.py unset MBEDTLS_AESNI_C
Jerry Yuc935aa62023-08-03 17:08:27 +08004625 scripts/config.py set MBEDTLS_PADLOCK_C
4626 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4627 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Jerry Yu506759f2023-08-16 17:11:22 +08004628 grep -q mbedtls_padlock_has_support ./programs/test/selftest
Jerry Yuc935aa62023-08-03 17:08:27 +08004629
4630}
4631
4632support_build_aes_via_padlock_only () {
4633 ( [ "$MBEDTLS_TEST_PLATFORM" == "Linux-x86_64" ] || \
4634 [ "$MBEDTLS_TEST_PLATFORM" == "Linux-amd64" ] ) && \
4635 [ "`dpkg --print-foreign-architectures`" == "i386" ]
4636}
4637
Jerry Yu193cbc02023-08-03 17:06:29 +08004638support_build_aes_aesce_armcc () {
4639 support_build_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +01004640}
4641
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004642component_test_aes_only_128_bit_keys () {
Gilles Peskine8f073122018-11-27 15:58:47 +01004643 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
Hanno Becker83ebf782017-07-07 12:29:15 +01004644 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01004645 scripts/config.py unset MBEDTLS_PADLOCK_C
4646
4647 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01004648
Gilles Peskine8f073122018-11-27 15:58:47 +01004649 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
4650 make test
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004651}
4652
Gilles Peskine8f073122018-11-27 15:58:47 +01004653component_test_no_ctr_drbg_aes_only_128_bit_keys () {
Hanno Becker83ebf782017-07-07 12:29:15 +01004654 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
Gilles Peskine8f073122018-11-27 15:58:47 +01004655 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4656 scripts/config.py unset MBEDTLS_CTR_DRBG_C
4657 scripts/config.py unset MBEDTLS_PADLOCK_C
4658
Gilles Peskine592f5912019-10-07 18:49:32 +02004659 make CC=clang CFLAGS='-Werror -Wall -Wextra'
4660
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004661 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
4662 make test
4663}
Gilles Peskine592f5912019-10-07 18:49:32 +02004664
4665component_test_aes_only_128_bit_keys_have_builtins () {
4666 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4667 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4668 scripts/config.py unset MBEDTLS_PADLOCK_C
4669 scripts/config.py unset MBEDTLS_AESNI_C
4670 scripts/config.py unset MBEDTLS_AESCE_C
4671
4672 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004673
4674 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4675 make test
Gilles Peskine592f5912019-10-07 18:49:32 +02004676
4677 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4678 programs/test/selftest
4679}
4680
4681component_test_aes_fewer_tables () {
4682 msg "build: default config with AES_FEWER_TABLES enabled"
4683 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
4684 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004685
4686 msg "test: AES_FEWER_TABLES"
4687 make test
4688}
Gilles Peskine592f5912019-10-07 18:49:32 +02004689
4690component_test_aes_rom_tables () {
4691 msg "build: default config with AES_ROM_TABLES enabled"
4692 scripts/config.py set MBEDTLS_AES_ROM_TABLES
4693 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
4694
4695 msg "test: AES_ROM_TABLES"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02004696 make test
4697}
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004698
Gilles Peskine004206c2019-10-21 17:11:33 +02004699component_test_aes_fewer_tables_and_rom_tables () {
Gilles Peskinef96aefe2019-07-24 14:58:38 +02004700 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
4701 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
4702 scripts/config.py set MBEDTLS_AES_ROM_TABLES
4703 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
4704
Steven Cooremand57203d2020-07-16 20:28:59 +02004705 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
Ronald Cron32a432a2023-03-28 09:19:04 +02004706 make test
Steven Cooreman753f9732021-03-15 11:38:44 +01004707}
Steven Cooreman6801f082021-02-19 17:21:22 +01004708
Gilles Peskine3587dfd2021-09-20 19:20:04 +02004709component_test_ctr_drbg_aes_256_sha_256 () {
4710 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Ronald Cron17b3afc2020-12-10 18:17:09 +01004711 scripts/config.py full
4712 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4713 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Steven Cooremand57203d2020-07-16 20:28:59 +02004714 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Ronald Cron32a432a2023-03-28 09:19:04 +02004715 make
Steven Cooremand57203d2020-07-16 20:28:59 +02004716
4717 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4718 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01004719}
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004720
Andrzej Kurek232e8f92019-10-03 03:18:01 -04004721component_test_ctr_drbg_aes_128_sha_512 () {
Gilles Peskine56c01612019-07-03 20:43:32 +02004722 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskineca144592021-11-04 12:52:14 +01004723 scripts/config.py full
Gilles Peskine8f073122018-11-27 15:58:47 +01004724 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02004725 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskinecf740502019-07-03 20:43:05 +02004726 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4727 make
4728
4729 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine56c01612019-07-03 20:43:32 +02004730 make test
Gilles Peskinecf740502019-07-03 20:43:05 +02004731}
Gilles Peskineca144592021-11-04 12:52:14 +01004732
Gilles Peskinecf740502019-07-03 20:43:05 +02004733component_test_ctr_drbg_aes_128_sha_256 () {
4734 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskineec10bf12019-09-20 19:56:06 +02004735 scripts/config.py full
4736 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4737 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
4738 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskinee094a182020-04-14 20:08:41 +02004739 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskineec10bf12019-09-20 19:56:06 +02004740 make
4741
4742 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4743 make test
4744}
4745
4746component_test_se_default () {
4747 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
4748 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
4749 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004750
Gilles Peskineec10bf12019-09-20 19:56:06 +02004751 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
4752 make test
4753}
4754
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004755component_test_psa_crypto_drivers () {
Gilles Peskine1997f302023-07-26 18:45:20 +02004756 msg "build: full + test drivers dispatching to builtins"
Gilles Peskineec10bf12019-09-20 19:56:06 +02004757 scripts/config.py full
Gilles Peskine1997f302023-07-26 18:45:20 +02004758 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Gilles Peskineec10bf12019-09-20 19:56:06 +02004759 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
4760 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
4761 loc_cflags="${loc_cflags} -I../tests/include -O2"
4762
4763 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
4764
Gilles Peskine1997f302023-07-26 18:45:20 +02004765 msg "test: full + test drivers dispatching to builtins"
Gilles Peskineec10bf12019-09-20 19:56:06 +02004766 make test
4767}
4768
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02004769component_test_make_shared () {
4770 msg "build/test: make shared" # ~ 40s
4771 make SHARED=1 all check
4772 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004773 programs/test/dlopen_demo.sh
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02004774}
4775
4776component_test_cmake_shared () {
4777 msg "build/test: cmake shared" # ~ 2min
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004778 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
4779 make
Gilles Peskine8f073122018-11-27 15:58:47 +01004780 ldd programs/util/strerror | grep libmbedcrypto
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004781 make test
4782 programs/test/dlopen_demo.sh
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004783}
Gilles Peskine8fd59422019-10-21 17:11:33 +02004784
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004785test_build_opt () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004786 info=$1 cc=$2; shift 2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004787 $cc --version
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004788 for opt in "$@"; do
Gilles Peskine14c3c062018-01-29 21:25:12 +01004789 msg "build/test: $cc $opt, $info" # ~ 30s
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004790 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskine14c3c062018-01-29 21:25:12 +01004791 # We're confident enough in compilers to not run _all_ the tests,
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004792 # but at least run the unit tests. In particular, runs with
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01004793 # optimizations use inline assembly whereas runs with -O0
Gilles Peskine14c3c062018-01-29 21:25:12 +01004794 # skip inline assembly.
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01004795 make test # ~30s
4796 make clean
4797 done
4798}
4799
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004800# For FreeBSD we invoke the function by name so this condition is added
4801# to disable the existing test_clang_opt function for linux.
4802if [[ $(uname) != "Linux" ]]; then
4803 component_test_clang_opt () {
4804 scripts/config.py full
4805 test_build_opt 'full config' clang -O0 -Os -O2
4806 }
4807fi
4808
4809component_test_clang_latest_opt () {
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004810 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004811 test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004812}
4813support_test_clang_latest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004814 type "$CLANG_LATEST" >/dev/null 2>/dev/null
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004815}
4816
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004817component_test_clang_earliest_opt () {
Gilles Peskine878cf602019-01-06 20:50:38 +00004818 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004819 test_build_opt 'full config' "$CLANG_EARLIEST" -O0
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004820}
4821support_test_clang_earliest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004822 type "$CLANG_EARLIEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004823}
4824
4825component_test_gcc_latest_opt () {
4826 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004827 test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004828}
4829support_test_gcc_latest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004830 type "$GCC_LATEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004831}
4832
4833component_test_gcc_earliest_opt () {
4834 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004835 test_build_opt 'full config' "$GCC_EARLIEST" -O0
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004836}
4837support_test_gcc_earliest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004838 type "$GCC_EARLIEST" >/dev/null 2>/dev/null
Gilles Peskine878cf602019-01-06 20:50:38 +00004839}
4840
4841component_build_mbedtls_config_file () {
4842 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
Gilles Peskine2003c2f2022-04-07 20:55:57 +02004843 scripts/config.py -w full_config.h full
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004844 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
4845 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
Gilles Peskine45e680e2022-04-13 23:23:21 +02004846 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskinee10df772022-04-07 21:06:41 +02004847 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
4848 make clean
4849
4850 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
4851 # In the user config, disable one feature (for simplicity, pick a feature
4852 # that nothing else depends on).
4853 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
4854 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
4855 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
4856
4857 rm -f user_config.h full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004858}
4859
Gilles Peskine7d904e72022-04-07 21:59:14 +02004860component_build_psa_config_file () {
4861 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
4862 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
4863 cp "$CRYPTO_CONFIG_H" psa_test_config.h
4864 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
4865 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Gilles Peskine45e680e2022-04-13 23:23:21 +02004866 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine7d904e72022-04-07 21:59:14 +02004867 programs/test/query_compile_time_config MBEDTLS_CMAC_C
4868 make clean
4869
4870 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
4871 # In the user config, disable one feature, which will reflect on the
4872 # mbedtls configuration so we can query it with query_compile_time_config.
4873 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
4874 scripts/config.py unset MBEDTLS_CMAC_C
4875 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
4876 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
4877
4878 rm -f psa_test_config.h psa_user_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004879}
4880
Gilles Peskinedf6e84a2023-02-22 22:09:51 +01004881component_build_psa_alt_headers () {
4882 msg "build: make with PSA alt headers" # ~20s
4883
4884 # Generate alternative versions of the substitutable headers with the
4885 # same content except different include guards.
4886 make -C tests include/alt-extra/psa/crypto_platform_alt.h include/alt-extra/psa/crypto_struct_alt.h
4887
4888 # Build the library and some programs.
4889 # Don't build the fuzzers to avoid having to go through hoops to set
4890 # a correct include path for programs/fuzz/Makefile.
4891 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
4892 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\"'"
4893
4894 # Check that we're getting the alternative include guards and not the
4895 # original include guards.
4896 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
4897 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
4898 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
4899 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
4900}
4901
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004902component_test_m32_o0 () {
Gilles Peskine77f05352021-10-07 19:27:16 +02004903 # Build without optimization, so as to use portable C code (in a 32-bit
4904 # build) and not the i386-specific inline assembly.
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004905 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
4906 scripts/config.py full
Pengyu Lv13226132023-10-16 14:03:29 +08004907 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004908 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
4909
4910 msg "test: i386, make, gcc -O0 (ASan build)"
4911 make test
4912}
4913support_test_m32_o0 () {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02004914 case $(uname -m) in
Pengyu Lvc92df3b2022-10-21 10:50:26 +00004915 amd64|x86_64) true;;
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004916 *) false;;
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004917 esac
4918}
4919
Gilles Peskineff0aee02021-10-05 09:36:03 +02004920component_test_m32_o2 () {
4921 # Build with optimization, to use the i386 specific inline assembly
4922 # and go faster for tests.
4923 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004924 scripts/config.py full
Pengyu Lv13226132023-10-16 14:03:29 +08004925 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
Gilles Peskineff0aee02021-10-05 09:36:03 +02004926 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004927
Gilles Peskineff0aee02021-10-05 09:36:03 +02004928 msg "test: i386, make, gcc -O2 (ASan build)"
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004929 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01004930
Gilles Peskineff0aee02021-10-05 09:36:03 +02004931 msg "test ssl-opt.sh, i386, make, gcc-O2"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004932 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01004933}
Gilles Peskinecf522222021-10-07 19:25:29 +02004934support_test_m32_o2 () {
Gilles Peskine878cf602019-01-06 20:50:38 +00004935 support_test_m32_o0 "$@"
4936}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004937
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004938component_test_m32_everest () {
4939 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004940 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Pengyu Lv13226132023-10-16 14:03:29 +08004941 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
Gilles Peskine8fd59422019-10-21 17:11:33 +02004942 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004943
4944 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
4945 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01004946
4947 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004948 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01004949
4950 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
4951 # Exclude some symmetric ciphers that are redundant here to gain time.
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02004952 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004953}
4954support_test_m32_everest () {
4955 support_test_m32_o0 "$@"
4956}
4957
Gilles Peskine8f073122018-11-27 15:58:47 +01004958component_test_mx32 () {
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004959 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004960 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02004961 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004962
4963 msg "test: 64-bit ILP32, make, gcc"
4964 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01004965}
Gilles Peskine878cf602019-01-06 20:50:38 +00004966support_test_mx32 () {
4967 case $(uname -m) in
4968 amd64|x86_64) true;;
4969 *) false;;
4970 esac
4971}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004972
Peter Kolbus60c6da22018-12-27 06:59:04 -06004973component_test_min_mpi_window_size () {
4974 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004975 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06004976 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4977 make
4978
4979 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
4980 make test
4981}
4982
Gilles Peskine8f073122018-11-27 15:58:47 +01004983component_test_have_int32 () {
4984 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004985 scripts/config.py unset MBEDTLS_HAVE_ASM
4986 scripts/config.py unset MBEDTLS_AESNI_C
4987 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08004988 scripts/config.py unset MBEDTLS_AESCE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01004989 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02004990
Gilles Peskine8f073122018-11-27 15:58:47 +01004991 msg "test: gcc, force 32-bit bignum limbs"
4992 make test
4993}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01004994
Gilles Peskine8f073122018-11-27 15:58:47 +01004995component_test_have_int64 () {
4996 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004997 scripts/config.py unset MBEDTLS_HAVE_ASM
4998 scripts/config.py unset MBEDTLS_AESNI_C
4999 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08005000 scripts/config.py unset MBEDTLS_AESCE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01005001 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01005002
Gilles Peskine8f073122018-11-27 15:58:47 +01005003 msg "test: gcc, force 64-bit bignum limbs"
5004 make test
5005}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00005006
Gabor Mezeie256cc12023-07-26 17:28:48 +02005007component_test_have_int32_cmake_new_bignum () {
5008 msg "build: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
5009 scripts/config.py unset MBEDTLS_HAVE_ASM
5010 scripts/config.py unset MBEDTLS_AESNI_C
5011 scripts/config.py unset MBEDTLS_PADLOCK_C
5012 scripts/config.py unset MBEDTLS_AESCE_C
5013 scripts/config.py set MBEDTLS_TEST_HOOKS
Janos Follath2f045822023-07-31 10:57:16 +01005014 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Janos Follathf3135af2023-07-31 10:07:57 +01005015 make CC=gcc CFLAGS="$ASAN_CFLAGS -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32" LDFLAGS="$ASAN_CFLAGS"
Gabor Mezeie256cc12023-07-26 17:28:48 +02005016
5017 msg "test: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
5018 make test
5019}
5020
Gilles Peskine8f073122018-11-27 15:58:47 +01005021component_test_no_udbl_division () {
5022 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02005023 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02005024 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01005025 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02005026
Gilles Peskine8f073122018-11-27 15:58:47 +01005027 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
5028 make test
5029}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02005030
Gilles Peskine8f073122018-11-27 15:58:47 +01005031component_test_no_64bit_multiplication () {
5032 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02005033 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02005034 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01005035 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02005036
Gilles Peskine8f073122018-11-27 15:58:47 +01005037 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
5038 make test
5039}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02005040
Gilles Peskine3809f5f2020-11-09 15:40:05 +01005041component_test_no_strings () {
5042 msg "build: no strings" # ~10s
5043 scripts/config.py full
5044 # Disable options that activate a large amount of string constants.
5045 scripts/config.py unset MBEDTLS_DEBUG_C
5046 scripts/config.py unset MBEDTLS_ERROR_C
5047 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
5048 scripts/config.py unset MBEDTLS_VERSION_FEATURES
5049 make CFLAGS='-Werror -Os'
5050
5051 msg "test: no strings" # ~ 10s
5052 make test
5053}
5054
Hanno Beckerc5722d12020-10-09 11:10:42 +01005055component_test_no_x509_info () {
5056 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
5057 scripts/config.pl full
5058 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
5059 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
Gilles Peskineff0aee02021-10-05 09:36:03 +02005060 make CFLAGS='-Werror -O2'
Hanno Beckerc5722d12020-10-09 11:10:42 +01005061
5062 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
5063 make test
5064
5065 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005066 tests/ssl-opt.sh
Hanno Beckerc5722d12020-10-09 11:10:42 +01005067}
5068
Gilles Peskine8f073122018-11-27 15:58:47 +01005069component_build_arm_none_eabi_gcc () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02005070 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005071 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02005072 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 +02005073
Gilles Peskinee36fe812021-09-01 20:00:33 +02005074 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02005075 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01005076}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02005077
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02005078component_build_arm_linux_gnueabi_gcc_arm5vte () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02005079 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005080 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02005081 # Build for a target platform that's close to what Debian uses
5082 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
Dave Rodgman017a1992022-03-31 14:07:01 +01005083 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02005084 # Build everything including programs, see for example
Dave Rodgman017a1992022-03-31 14:07:01 +01005085 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02005086 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'
5087
Gilles Peskinee36fe812021-09-01 20:00:33 +02005088 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02005089 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t library/*.o
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02005090}
5091support_build_arm_linux_gnueabi_gcc_arm5vte () {
5092 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
5093}
5094
5095component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02005096 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02005097 scripts/config.py baremetal
5098 # This is an imperfect substitute for
5099 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnardae505ee2021-07-06 09:44:59 +02005100 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02005101 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 +02005102
Gilles Peskinee36fe812021-09-01 20:00:33 +02005103 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02005104 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02005105}
5106
Gilles Peskine6e2fb862020-04-30 23:00:53 +02005107component_build_arm_none_eabi_gcc_m0plus () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02005108 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
5109 scripts/config.py baremetal_size
Gilles Peskineaeedd742020-09-02 11:03:04 +02005110 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 +02005111
Gilles Peskinee36fe812021-09-01 20:00:33 +02005112 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02005113 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Manuel Pégourié-Gonnard67f80372023-06-06 13:01:18 +02005114 for lib in library/*.a; do
5115 echo "$lib:"
5116 ${ARM_NONE_EABI_GCC_PREFIX}size -t $lib | grep TOTALS
5117 done
Gilles Peskine6e2fb862020-04-30 23:00:53 +02005118}
5119
Gilles Peskine8f073122018-11-27 15:58:47 +01005120component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02005121 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005122 scripts/config.py baremetal
5123 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02005124 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 +01005125 echo "Checking that software 64-bit division is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005126 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01005127}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02005128
Gilles Peskine8f073122018-11-27 15:58:47 +01005129component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02005130 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005131 scripts/config.py baremetal
5132 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02005133 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 +01005134 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005135 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01005136}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02005137
Dave Rodgman8c315f22023-06-02 10:26:24 -04005138component_build_arm_clang_thumb () {
5139 # ~ 30s
5140
5141 scripts/config.py baremetal
5142
5143 msg "build: clang thumb 2, make"
5144 make clean
5145 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
5146
5147 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
5148 msg "build: clang thumb 1 -O0, make"
5149 make clean
5150 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
5151
5152 msg "build: clang thumb 1 -Os, make"
5153 make clean
5154 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
5155}
5156
Gilles Peskine8f073122018-11-27 15:58:47 +01005157component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02005158 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005159 scripts/config.py baremetal
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00005160 # armc[56] don't support SHA-512 intrinsics
5161 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Dave Rodgman2f386c52023-03-02 13:38:33 +00005162
Dave Rodgman0fddf822023-03-02 15:32:12 +00005163 # Stop armclang warning about feature detection for A64_CRYPTO.
5164 # With this enabled, the library does build correctly under armclang,
5165 # but in baremetal builds (as tested here), feature detection is
5166 # unavailable, and the user is notified via a #warning. So enabling
5167 # this feature would prevent us from building with -Werror on
5168 # armclang. Tracked in #7198.
Dave Rodgman5b89c552023-10-10 14:59:02 +01005169 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Dave Rodgman2f386c52023-03-02 13:38:33 +00005170
Hanno Beckerf0762e92022-07-15 12:08:19 +01005171 scripts/config.py set MBEDTLS_HAVE_ASM
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00005172
Gilles Peskinebca6ab92017-12-19 18:24:31 +01005173 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02005174
5175 msg "size: ARM Compiler 5"
5176 "$ARMC5_FROMELF" -z library/*.o
5177
Gilles Peskinebca6ab92017-12-19 18:24:31 +01005178 make clean
Andres AG87bb5772016-09-27 15:05:15 +01005179
Dave Rodgmanb45d58b2023-06-02 13:54:00 -04005180 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
Hanno Beckerf0762e92022-07-15 12:08:19 +01005181
Gilles Peskinebca6ab92017-12-19 18:24:31 +01005182 # ARM Compiler 6 - Target ARMv7-A
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01005183 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02005184
Gilles Peskinebca6ab92017-12-19 18:24:31 +01005185 # ARM Compiler 6 - Target ARMv7-M
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01005186 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m"
5187
5188 # ARM Compiler 6 - Target ARMv7-M+DSP
5189 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m+dsp"
Simon Butcher940737f2017-07-23 13:42:36 +02005190
Gilles Peskinebca6ab92017-12-19 18:24:31 +01005191 # ARM Compiler 6 - Target ARMv8-A - AArch32
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01005192 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02005193
Gilles Peskinebca6ab92017-12-19 18:24:31 +01005194 # ARM Compiler 6 - Target ARMv8-M
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01005195 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02005196
Tom Cosgrove6ec39ca2023-06-09 15:34:31 +01005197 # ARM Compiler 6 - Target ARMv8.2-A - AArch64
5198 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
5199
Dave Rodgmanb45d58b2023-06-02 13:54:00 -04005200 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
5201 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
5202
Dave Rodgman99318e62023-05-24 12:27:42 +01005203 # ARM Compiler 6 - Target Cortex-M0
5204 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
Gilles Peskine8f073122018-11-27 15:58:47 +01005205}
Tom Cosgrove6ec39ca2023-06-09 15:34:31 +01005206
Pengyu Lvdf070032023-02-24 16:03:31 +08005207support_build_armcc () {
Pengyu Lvc6298ad2023-03-01 10:31:29 +08005208 armc5_cc="$ARMC5_BIN_DIR/armcc"
5209 armc6_cc="$ARMC6_BIN_DIR/armclang"
5210 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
Pengyu Lvdf070032023-02-24 16:03:31 +08005211}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01005212
Jerry Yu81d5e1f2022-01-27 13:01:01 +08005213component_test_tls13_only () {
5214 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3, without MBEDTLS_SSL_PROTO_TLS1_2"
Ronald Cronc2e110f2022-11-22 09:01:46 +01005215 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Jerry Yuda5af222021-12-24 18:45:45 +08005216 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5217
Gilles Peskine4bb369c2022-10-29 17:44:19 +02005218 msg "test: TLS 1.3 only, all key exchange modes enabled"
5219 make test
Jerry Yubaa49342022-02-15 10:26:40 +08005220
Ronald Cronc3f43b62022-10-17 17:35:32 +02005221 msg "ssl-opt.sh: TLS 1.3 only, all key exchange modes enabled"
5222 tests/ssl-opt.sh
Jerry Yuda5af222021-12-24 18:45:45 +08005223}
5224
Ronald Cronc3f43b62022-10-17 17:35:32 +02005225component_test_tls13_only_psk () {
5226 msg "build: TLS 1.3 only from default, only PSK key exchange mode"
5227 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5228 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
5229 scripts/config.py unset MBEDTLS_ECDH_C
Przemek Stekiel0c231472023-06-14 11:12:45 +02005230 scripts/config.py unset MBEDTLS_DHM_C
Ronald Cronc3f43b62022-10-17 17:35:32 +02005231 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5232 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5233 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5234 scripts/config.py unset MBEDTLS_ECDSA_C
5235 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00005236 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01005237 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Crone3dac4a2022-06-10 17:21:51 +02005238 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5239
Ronald Cronc3f43b62022-10-17 17:35:32 +02005240 msg "test_suite_ssl: TLS 1.3 only, only PSK key exchange mode enabled"
5241 cd tests; ./test_suite_ssl; cd ..
Ronald Crone3dac4a2022-06-10 17:21:51 +02005242
Ronald Cronc3f43b62022-10-17 17:35:32 +02005243 msg "ssl-opt.sh: TLS 1.3 only, only PSK key exchange mode enabled"
5244 tests/ssl-opt.sh
5245}
5246
5247component_test_tls13_only_ephemeral () {
5248 msg "build: TLS 1.3 only from default, only ephemeral key exchange mode"
5249 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5250 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
Xiaokang Qian2dbfeda2022-11-15 10:52:57 +00005251 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005252 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5253
5254 msg "test_suite_ssl: TLS 1.3 only, only ephemeral key exchange mode"
5255 cd tests; ./test_suite_ssl; cd ..
5256
5257 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral key exchange mode"
5258 tests/ssl-opt.sh
5259}
5260
Przemek Stekiela01c2422023-06-13 10:46:48 +02005261component_test_tls13_only_ephemeral_ffdh () {
5262 msg "build: TLS 1.3 only from default, only ephemeral ffdh key exchange mode"
5263 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5264 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
5265 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
Przemek Stekielce05f542023-06-15 16:44:08 +02005266 scripts/config.py unset MBEDTLS_ECDH_C
5267
Przemek Stekiela01c2422023-06-13 10:46:48 +02005268 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5269
5270 msg "test_suite_ssl: TLS 1.3 only, only ephemeral ffdh key exchange mode"
5271 cd tests; ./test_suite_ssl; cd ..
5272
5273 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral ffdh key exchange mode"
5274 tests/ssl-opt.sh
5275}
5276
Ronald Cronc3f43b62022-10-17 17:35:32 +02005277component_test_tls13_only_psk_ephemeral () {
5278 msg "build: TLS 1.3 only from default, only PSK ephemeral key exchange mode"
5279 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5280 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5281 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5282 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5283 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5284 scripts/config.py unset MBEDTLS_ECDSA_C
5285 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00005286 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01005287 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005288 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5289
5290 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral key exchange mode"
5291 cd tests; ./test_suite_ssl; cd ..
5292
5293 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral key exchange mode"
5294 tests/ssl-opt.sh
5295}
5296
Przemek Stekiela01c2422023-06-13 10:46:48 +02005297component_test_tls13_only_psk_ephemeral_ffdh () {
5298 msg "build: TLS 1.3 only from default, only PSK ephemeral ffdh key exchange mode"
5299 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5300 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5301 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5302 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5303 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5304 scripts/config.py unset MBEDTLS_ECDSA_C
5305 scripts/config.py unset MBEDTLS_PKCS1_V21
5306 scripts/config.py unset MBEDTLS_PKCS7_C
5307 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Przemek Stekielce05f542023-06-15 16:44:08 +02005308 scripts/config.py unset MBEDTLS_ECDH_C
Przemek Stekiela01c2422023-06-13 10:46:48 +02005309 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5310
5311 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
5312 cd tests; ./test_suite_ssl; cd ..
5313
5314 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
5315 tests/ssl-opt.sh
5316}
5317
Ronald Cronc3f43b62022-10-17 17:35:32 +02005318component_test_tls13_only_psk_all () {
5319 msg "build: TLS 1.3 only from default, without ephemeral key exchange mode"
5320 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5321 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5322 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5323 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5324 scripts/config.py unset MBEDTLS_ECDSA_C
5325 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00005326 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01005327 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005328 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5329
5330 msg "test_suite_ssl: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
5331 cd tests; ./test_suite_ssl; cd ..
5332
5333 msg "ssl-opt.sh: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
5334 tests/ssl-opt.sh
5335}
5336
5337component_test_tls13_only_ephemeral_all () {
5338 msg "build: TLS 1.3 only from default, without PSK key exchange mode"
5339 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
Ronald Cronc2e110f2022-11-22 09:01:46 +01005340 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005341 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5342
5343 msg "test_suite_ssl: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
5344 cd tests; ./test_suite_ssl; cd ..
5345
5346 msg "ssl-opt.sh: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
5347 tests/ssl-opt.sh
Ronald Crone3dac4a2022-06-10 17:21:51 +02005348}
5349
Ronald Cron6f135e12021-12-08 16:57:54 +01005350component_test_tls13 () {
5351 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
5352 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005353 scripts/config.py set MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
5354 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
Ronald Cronc2e110f2022-11-22 09:01:46 +01005355 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005356 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
5357 make
Ronald Cron6f135e12021-12-08 16:57:54 +01005358 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005359 make test
Ronald Cron6f135e12021-12-08 16:57:54 +01005360 msg "ssl-opt.sh (TLS 1.3)"
Gilles Peskine827dbd92022-02-04 00:30:54 +01005361 tests/ssl-opt.sh
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005362}
5363
Ronald Cron6f135e12021-12-08 16:57:54 +01005364component_test_tls13_no_compatibility_mode () {
5365 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
5366 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005367 scripts/config.py unset MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
5368 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
Ronald Cronc2e110f2022-11-22 09:01:46 +01005369 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Hanno Beckera711f6e2020-05-04 12:03:51 +01005370 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
5371 make
Ronald Cron6f135e12021-12-08 16:57:54 +01005372 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
Hanno Becker6c53ecc2021-08-01 19:20:10 +01005373 make test
Ronald Cron6f135e12021-12-08 16:57:54 +01005374 msg "ssl-opt.sh (TLS 1.3 no compatibility mode)"
Gilles Peskine827dbd92022-02-04 00:30:54 +01005375 tests/ssl-opt.sh
Hanno Becker6c53ecc2021-08-01 19:20:10 +01005376}
5377
Jan Bruckner151f6422023-02-10 12:45:19 +01005378component_test_tls13_only_record_size_limit () {
5379 msg "build: TLS 1.3 only from default, record size limit extension enabled"
5380 scripts/config.py set MBEDTLS_SSL_RECORD_SIZE_LIMIT
5381 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5382
5383 msg "test_suite_ssl: TLS 1.3 only, record size limit extension enabled"
5384 cd tests; ./test_suite_ssl; cd ..
5385
5386 msg "ssl-opt.sh: (TLS 1.3 only, record size limit extension tests only)"
5387 # Both the server and the client will currently abort the handshake when they encounter the
5388 # record size limit extension. There is no way to prevent gnutls-cli from sending the extension
5389 # which makes all G_NEXT_CLI + P_SRV tests fail. Thus, run only the tests for the this extension.
5390 tests/ssl-opt.sh -f "Record Size Limit"
5391}
5392
Gilles Peskine8f073122018-11-27 15:58:47 +01005393component_build_mingw () {
5394 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Pengyu Lv64cca2f2023-10-10 18:22:24 +08005395 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 lib programs
Hanno Beckere963efa2018-01-03 10:03:43 +00005396
Gilles Peskine8f073122018-11-27 15:58:47 +01005397 # note Make tests only builds the tests, but doesn't run them
Pengyu Lv64cca2f2023-10-10 18:22:24 +08005398 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -maes -msse2 -mpclmul' WINDOWS_BUILD=1 tests
Gilles Peskine8f073122018-11-27 15:58:47 +01005399 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02005400
Gilles Peskine8f073122018-11-27 15:58:47 +01005401 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Pengyu Lv64cca2f2023-10-10 18:22:24 +08005402 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 SHARED=1 lib programs
5403 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 SHARED=1 tests
Gilles Peskine8f073122018-11-27 15:58:47 +01005404 make WINDOWS_BUILD=1 clean
Pengyu Lvbb4f63c2023-10-19 10:38:58 +08005405
Pengyu Lv158eead2023-10-19 11:27:05 +08005406 msg "build: Windows cross build - mingw64, make (Library only, default config without MBEDTLS_AESNI_C)" # ~ 30s
Pengyu Lvbb4f63c2023-10-19 10:38:58 +08005407 ./scripts/config.py unset MBEDTLS_AESNI_C #
Pengyu Lv158eead2023-10-19 11:27:05 +08005408 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib
Gilles Peskine8f073122018-11-27 15:58:47 +01005409 make WINDOWS_BUILD=1 clean
5410}
Jaeden Amero117b8a42019-04-17 15:19:26 +01005411support_build_mingw() {
Pengyu Lv51b5f002023-02-24 15:38:52 +08005412 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
5413 [0-5]*|"") false;;
Jaeden Amero117b8a42019-04-17 15:19:26 +01005414 *) true;;
5415 esac
5416}
Simon Butcher91aef332016-11-17 09:20:50 +00005417
Gilles Peskine8f073122018-11-27 15:58:47 +01005418component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005419 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005420 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005421 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
5422 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02005423
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005424 msg "test: main suites (MSan)" # ~ 10s
5425 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005426
Gilles Peskine82b27272019-06-14 18:27:03 +02005427 msg "program demos (MSan)" # ~20s
5428 tests/scripts/run_demos.py
5429
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005430 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005431 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005432
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005433 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005434
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005435 if [ "$MEMORY" -gt 0 ]; then
5436 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005437 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005438 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01005439}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005440
Gilles Peskine69f190e2019-01-10 00:11:42 +01005441component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005442 msg "build: Release (clang)"
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005443 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005444 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
5445 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005446
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005447 msg "test: main suites, Valgrind (default config)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005448 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005449
Gilles Peskine636c26a2020-03-04 20:46:15 +01005450 # Optional parts (slow; currently broken on OS X because programs don't
5451 # seem to receive signals under valgrind on OS X).
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005452 # These optional parts don't run on the CI.
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005453 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005454 msg "test: ssl-opt.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005455 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005456 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005457
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005458 if [ "$MEMORY" -gt 1 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005459 msg "test: compat.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005460 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005461 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02005462
5463 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005464 msg "test: context-info.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005465 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02005466 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01005467}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005468
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005469component_test_valgrind_psa () {
5470 msg "build: Release, full (clang)"
5471 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
5472 scripts/config.py full
5473 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
5474 make
5475
5476 msg "test: main suites, Valgrind (full config)"
5477 make memcheck
5478}
5479
Paul Elliott62dc3922021-11-25 17:29:40 +00005480support_test_cmake_out_of_source () {
5481 distrib_id=""
5482 distrib_ver=""
5483 distrib_ver_minor=""
5484 distrib_ver_major=""
5485
5486 # Attempt to parse lsb-release to find out distribution and version. If not
5487 # found this should fail safe (test is supported).
5488 if [[ -f /etc/lsb-release ]]; then
5489
5490 while read -r lsb_line; do
5491 case "$lsb_line" in
5492 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
5493 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
5494 esac
5495 done < /etc/lsb-release
5496
5497 distrib_ver_major="${distrib_ver%%.*}"
5498 distrib_ver="${distrib_ver#*.}"
5499 distrib_ver_minor="${distrib_ver%%.*}"
5500 fi
5501
5502 # Running the out of source CMake test on Ubuntu 16.04 using more than one
5503 # processor (as the CI does) can create a race condition whereby the build
5504 # fails to see a generated file, despite that file actually having been
5505 # generated. This problem appears to go away with 18.04 or newer, so make
5506 # the out of source tests unsupported on Ubuntu 16.04.
5507 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
5508}
5509
Gilles Peskine8f073122018-11-27 15:58:47 +01005510component_test_cmake_out_of_source () {
David Horstmann862abe22023-09-28 10:42:10 +01005511 # Remove existing generated files so that we use the ones cmake
David Horstmann9f48fff2023-09-27 15:53:54 +01005512 # generates
5513 make neat
5514
Gilles Peskine8f073122018-11-27 15:58:47 +01005515 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01005516 MBEDTLS_ROOT_DIR="$PWD"
5517 mkdir "$OUT_OF_SOURCE_DIR"
5518 cd "$OUT_OF_SOURCE_DIR"
David Horstmann9f48fff2023-09-27 15:53:54 +01005519 # Note: Explicitly generate files as these are turned off in releases
5520 cmake -D CMAKE_BUILD_TYPE:String=Check -D GEN_FILES=ON "$MBEDTLS_ROOT_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01005521 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005522
Gilles Peskine8f073122018-11-27 15:58:47 +01005523 msg "test: cmake 'out-of-source' build"
5524 make test
Gilles Peskinea841c2a2022-04-16 11:31:25 +02005525 # Check that ssl-opt.sh can find the test programs.
Gilles Peskine8f073122018-11-27 15:58:47 +01005526 # Also ensure that there are no error messages such as
5527 # "No such file or directory", which would indicate that some required
5528 # file is missing (ssl-opt.sh tolerates the absence of some files so
5529 # may exit with status 0 but emit errors).
Gilles Peskinea841c2a2022-04-16 11:31:25 +02005530 ./tests/ssl-opt.sh -f 'Default' >ssl-opt.out 2>ssl-opt.err
Gilles Peskine7393ec52022-04-15 22:43:38 +02005531 grep PASS ssl-opt.out
Gilles Peskinef7e956c2020-03-28 18:56:09 +01005532 cat ssl-opt.err >&2
5533 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005534 [ ! -s ssl-opt.err ]
Gilles Peskine7393ec52022-04-15 22:43:38 +02005535 rm ssl-opt.out ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01005536 cd "$MBEDTLS_ROOT_DIR"
5537 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01005538}
Andres AGdc192212016-08-31 17:33:13 +01005539
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005540component_test_cmake_as_subdirectory () {
David Horstmann9f48fff2023-09-27 15:53:54 +01005541 # Remove existing generated files so that we use the ones CMake
5542 # generates
5543 make neat
5544
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005545 msg "build: cmake 'as-subdirectory' build"
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005546 cd programs/test/cmake_subproject
David Horstmann9f48fff2023-09-27 15:53:54 +01005547 # Note: Explicitly generate files as these are turned off in releases
5548 cmake -D GEN_FILES=ON .
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005549 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005550 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005551}
Gilles Peskinea3000992022-02-04 00:21:12 +01005552support_test_cmake_as_subdirectory () {
5553 support_test_cmake_out_of_source
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005554}
5555
Chris Kayd259e342021-03-25 16:03:25 +00005556component_test_cmake_as_package () {
David Horstmann6c979852023-09-28 10:40:22 +01005557 # Remove existing generated files so that we use the ones CMake
5558 # generates
5559 make neat
5560
Chris Kayd259e342021-03-25 16:03:25 +00005561 msg "build: cmake 'as-package' build"
Chris Kayd259e342021-03-25 16:03:25 +00005562 cd programs/test/cmake_package
5563 cmake .
5564 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005565 ./cmake_package
Chris Kayd259e342021-03-25 16:03:25 +00005566}
Gilles Peskinea3000992022-02-04 00:21:12 +01005567support_test_cmake_as_package () {
5568 support_test_cmake_out_of_source
Chris Kayd259e342021-03-25 16:03:25 +00005569}
5570
5571component_test_cmake_as_package_install () {
David Horstmann6c979852023-09-28 10:40:22 +01005572 # Remove existing generated files so that we use the ones CMake
5573 # generates
5574 make neat
5575
Chris Kayd259e342021-03-25 16:03:25 +00005576 msg "build: cmake 'as-installed-package' build"
Chris Kayd259e342021-03-25 16:03:25 +00005577 cd programs/test/cmake_package_install
5578 cmake .
5579 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005580 ./cmake_package_install
Chris Kayd259e342021-03-25 16:03:25 +00005581}
Gilles Peskinea3000992022-02-04 00:21:12 +01005582support_test_cmake_as_package_install () {
5583 support_test_cmake_out_of_source
Chris Kayd259e342021-03-25 16:03:25 +00005584}
5585
David Horstmann20550e32023-01-12 14:17:01 +00005586component_build_cmake_custom_config_file () {
David Horstmann969c1452023-01-31 10:34:44 +00005587 # Make a copy of config file to use for the in-tree test
5588 cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h
David Horstmann20550e32023-01-12 14:17:01 +00005589
5590 MBEDTLS_ROOT_DIR="$PWD"
5591 mkdir "$OUT_OF_SOURCE_DIR"
5592 cd "$OUT_OF_SOURCE_DIR"
5593
David Horstmann969c1452023-01-31 10:34:44 +00005594 # Build once to get the generated files (which need an intact config file)
David Horstmann20550e32023-01-12 14:17:01 +00005595 cmake "$MBEDTLS_ROOT_DIR"
5596 make
5597
5598 msg "build: cmake with -DMBEDTLS_CONFIG_FILE"
5599 scripts/config.py -w full_config.h full
David Horstmann969c1452023-01-31 10:34:44 +00005600 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005601 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR"
5602 make
5603
5604 msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
5605 # In the user config, disable one feature (for simplicity, pick a feature
5606 # that nothing else depends on).
5607 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
5608
5609 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR"
5610 make
5611 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5612
5613 rm -f user_config.h full_config.h
5614
5615 cd "$MBEDTLS_ROOT_DIR"
5616 rm -rf "$OUT_OF_SOURCE_DIR"
5617
5618 # Now repeat the test for an in-tree build:
5619
David Horstmann969c1452023-01-31 10:34:44 +00005620 # Restore config for the in-tree test
5621 mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005622
David Horstmann969c1452023-01-31 10:34:44 +00005623 # Build once to get the generated files (which need an intact config)
David Horstmann20550e32023-01-12 14:17:01 +00005624 cmake .
5625 make
5626
5627 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE"
5628 scripts/config.py -w full_config.h full
David Horstmann969c1452023-01-31 10:34:44 +00005629 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005630 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h .
5631 make
5632
5633 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
5634 # In the user config, disable one feature (for simplicity, pick a feature
5635 # that nothing else depends on).
5636 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
5637
5638 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h .
5639 make
5640 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5641
5642 rm -f user_config.h full_config.h
5643}
5644support_build_cmake_custom_config_file () {
5645 support_test_cmake_out_of_source
5646}
5647
5648
Tom Cosgrovedaddf112023-09-01 10:40:15 +01005649component_build_zeroize_checks () {
5650 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
5651
5652 scripts/config.py full
5653
5654 # Only compile - we're looking for sizeof-pointer-memaccess warnings
Tom Cosgroveb2fafa52023-09-01 14:40:21 +01005655 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 +01005656}
5657
5658
Gilles Peskine8f073122018-11-27 15:58:47 +01005659component_test_zeroize () {
5660 # Test that the function mbedtls_platform_zeroize() is not optimized away by
5661 # different combinations of compilers and optimization flags by using an
5662 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
5663 # system in all cases that the script fails, so we must manually search the
5664 # output to check whether the pass string is present and no failure strings
5665 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01005666
Gilles Peskine4976e822019-01-06 19:52:22 +00005667 # Don't try to disable ASLR. We don't care about ASLR here. We do care
5668 # about a spurious message if Gdb tries and fails, so suppress that.
5669 gdb_disable_aslr=
5670 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
5671 gdb_disable_aslr='set disable-randomization off'
5672 fi
5673
Gilles Peskine8f073122018-11-27 15:58:47 +01005674 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01005675 for compiler in clang gcc; do
5676 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
5677 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005678 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
5679 grep "The buffer was correctly zeroized" test_zeroize.log
5680 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01005681 rm -f test_zeroize.log
5682 make clean
5683 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01005684 done
Gilles Peskine8f073122018-11-27 15:58:47 +01005685}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005686
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005687component_test_psa_compliance () {
5688 msg "build: make, default config (out-of-box), libmbedcrypto.a only"
Bence Szépkútica9236b2021-10-25 19:29:07 +02005689 make -C library libmbedcrypto.a
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005690
5691 msg "unit test: test_psa_compliance.py"
5692 ./tests/scripts/test_psa_compliance.py
5693}
5694
5695support_test_psa_compliance () {
Bence Szépkútief0d02e2021-11-03 11:36:09 +01005696 # psa-compliance-tests only supports CMake >= 3.10.0
Bence Szépkútica9236b2021-10-25 19:29:07 +02005697 ver="$(cmake --version)"
5698 ver="${ver#cmake version }"
5699 ver_major="${ver%%.*}"
5700
5701 ver="${ver#*.}"
5702 ver_minor="${ver%%.*}"
5703
5704 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005705}
5706
Gilles Peskinec848d222022-12-09 12:23:35 +01005707component_check_code_style () {
5708 msg "Check C code style"
5709 ./scripts/code_style.py
David Horstmann92b5ac12022-11-10 18:30:52 +00005710}
5711
Gilles Peskinec848d222022-12-09 12:23:35 +01005712support_check_code_style() {
David Horstmann92b5ac12022-11-10 18:30:52 +00005713 case $(uncrustify --version) in
5714 *0.75.1*) true;;
5715 *) false;;
5716 esac
5717}
5718
Gilles Peskine8f073122018-11-27 15:58:47 +01005719component_check_python_files () {
5720 msg "Lint: Python scripts"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005721 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01005722}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005723
Joe Subbianid614c0b2021-07-29 11:18:29 +01005724component_check_test_helpers () {
5725 msg "unit test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02005726 # unittest writes out mundane stuff like number or tests run on stderr.
5727 # Our convention is to reserve stderr for actual errors, and write
5728 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005729 ./tests/scripts/test_generate_test_code.py 2>&1
Joe Subbianid614c0b2021-07-29 11:18:29 +01005730
Joe Subbiania25ffab2021-08-06 09:41:27 +01005731 msg "unit test: translate_ciphers.py"
5732 python3 -m unittest tests/scripts/translate_ciphers.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01005733}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005734
Jerry Yud767cc42023-03-31 15:03:55 +08005735
Gilles Peskine192c72f2017-12-21 15:59:21 +01005736################################################################
5737#### Termination
5738################################################################
5739
Gilles Peskine8f073122018-11-27 15:58:47 +01005740post_report () {
5741 msg "Done, cleaning up"
Gilles Peskinef83eb822020-03-30 20:11:39 +02005742 final_cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005743
Gilles Peskine8f073122018-11-27 15:58:47 +01005744 final_report
5745}
5746
5747
5748
5749################################################################
5750#### Run all the things
5751################################################################
5752
Gilles Peskine5d996822020-03-28 21:09:21 +01005753# Function invoked by --error-test to test error reporting.
5754pseudo_component_error_test () {
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005755 msg "Testing error reporting $error_test_i"
Gilles Peskine5d996822020-03-28 21:09:21 +01005756 if [ $KEEP_GOING -ne 0 ]; then
5757 echo "Expect three failing commands."
5758 fi
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005759 # If the component doesn't run in a subshell, changing error_test_i to an
5760 # invalid integer will cause an error in the loop that runs this function.
5761 error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
Gilles Peskineec135542021-08-02 23:14:03 +02005762 # Expected error: 'grep non_existent /dev/null -> 1'
Gilles Peskine5d996822020-03-28 21:09:21 +01005763 grep non_existent /dev/null
Gilles Peskineec135542021-08-02 23:14:03 +02005764 # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
Gilles Peskine5d996822020-03-28 21:09:21 +01005765 not grep -q . "$0"
Gilles Peskineec135542021-08-02 23:14:03 +02005766 # Expected error: 'make unknown_target -> 2'
Gilles Peskine5d996822020-03-28 21:09:21 +01005767 make unknown_target
5768 false "this should not be executed"
5769}
5770
Gilles Peskinee48351a2018-11-27 16:06:30 +01005771# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01005772run_component () {
Gilles Peskineffcdeff2018-12-04 12:49:28 +01005773 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02005774 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005775
5776 # Unconditionally create a seedfile that's sufficiently long.
5777 # Do this before each component, because a previous component may
5778 # have messed it up or shortened it.
Gilles Peskine88a07452021-07-08 19:03:50 +02005779 local dd_cmd
5780 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
5781 case $OSTYPE in
Tom Cosgrove226aca12022-03-16 14:11:07 +00005782 linux*|freebsd*|openbsd*) dd_cmd+=(status=none)
Gilles Peskine88a07452021-07-08 19:03:50 +02005783 esac
5784 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005785
Gilles Peskineec135542021-08-02 23:14:03 +02005786 # Run the component in a subshell, with error trapping and output
5787 # redirection set up based on the relevant options.
Gilles Peskinece266c42020-03-28 18:50:43 +01005788 if [ $KEEP_GOING -eq 1 ]; then
Gilles Peskineec135542021-08-02 23:14:03 +02005789 # We want to keep running if the subshell fails, so 'set -e' must
5790 # be off when the subshell runs.
Gilles Peskinece266c42020-03-28 18:50:43 +01005791 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02005792 fi
Gilles Peskinece266c42020-03-28 18:50:43 +01005793 (
5794 if [ $QUIET -eq 1 ]; then
5795 # msg() will be silenced, so just print the component name here.
5796 echo "${current_component#component_}"
5797 exec >/dev/null
5798 fi
5799 if [ $KEEP_GOING -eq 1 ]; then
5800 # Keep "set -e" off, and run an ERR trap instead to record failures.
5801 set -E
5802 trap err_trap ERR
5803 fi
5804 # The next line is what runs the component
5805 "$@"
5806 if [ $KEEP_GOING -eq 1 ]; then
5807 trap - ERR
5808 exit $last_failure_status
5809 fi
5810 )
5811 component_status=$?
5812 if [ $KEEP_GOING -eq 1 ]; then
5813 set -e
5814 if [ $component_status -ne 0 ]; then
5815 failure_count=$((failure_count + 1))
5816 fi
5817 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005818
5819 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01005820 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02005821 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01005822}
5823
5824# Preliminary setup
5825pre_check_environment
Tom Cosgrove730addc2023-06-09 14:20:18 +01005826pre_parse_command_line_for_dirs "$@"
Gilles Peskine8f073122018-11-27 15:58:47 +01005827pre_initialize_variables
5828pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01005829
Gilles Peskine878cf602019-01-06 20:50:38 +00005830pre_check_git
Gilles Peskine568f53a2021-07-12 18:16:01 +02005831pre_restore_files
Gilles Peskinef83eb822020-03-30 20:11:39 +02005832pre_back_up
Andrzej Kurekeb508712019-02-14 07:18:59 -05005833
Gilles Peskine878cf602019-01-06 20:50:38 +00005834build_status=0
5835if [ $KEEP_GOING -eq 1 ]; then
5836 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01005837fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02005838pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00005839pre_print_configuration
5840pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005841cleanup
David Horstmann76a77382023-08-17 17:32:26 +01005842if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +01005843 pre_generate_files
5844fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005845
Gilles Peskinebeb3a812019-01-06 22:11:25 +00005846# Run the requested tests.
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005847for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
Gilles Peskine5d996822020-03-28 21:09:21 +01005848 run_component pseudo_component_error_test
Gilles Peskine5d996822020-03-28 21:09:21 +01005849done
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005850unset error_test_i
Gilles Peskinebeb3a812019-01-06 22:11:25 +00005851for component in $RUN_COMPONENTS; do
5852 run_component "component_$component"
5853done
Gilles Peskine8f073122018-11-27 15:58:47 +01005854
5855# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00005856post_report