blob: fe2d73f0cd153e16b692dda6de127c29e23d11cd [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
Dave Rodgmane3c05852023-11-03 12:21:36 +00006# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskine192c72f2017-12-21 15:59:21 +01007
8
9
10################################################################
11#### Documentation
12################################################################
13
Simon Butcher3ea7f522016-03-07 23:22:10 +000014# Purpose
Gilles Peskine192c72f2017-12-21 15:59:21 +010015# -------
Simon Butcher3ea7f522016-03-07 23:22:10 +000016#
SimonB2e23c822016-04-16 21:54:39 +010017# To run all tests possible or available on the platform.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +010018#
Gilles Peskine192c72f2017-12-21 15:59:21 +010019# Notes for users
20# ---------------
21#
SimonB2e23c822016-04-16 21:54:39 +010022# Warning: the test is destructive. It includes various build modes and
23# configurations, and can and will arbitrarily change the current CMake
Gilles Peskine192c72f2017-12-21 15:59:21 +010024# configuration. The following files must be committed into git:
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +020025# * include/mbedtls/mbedtls_config.h
Gilles Peskine636c26a2020-03-04 20:46:15 +010026# * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
27# programs/fuzz/Makefile
Gilles Peskine192c72f2017-12-21 15:59:21 +010028# After running this script, the CMake cache will be lost and CMake
29# will no longer be initialised.
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +010030#
Gilles Peskine192c72f2017-12-21 15:59:21 +010031# The script assumes the presence of a number of tools:
32# * Basic Unix tools (Windows users note: a Unix-style find must be before
33# the Windows find in the PATH)
34# * Perl
35# * GNU Make
36# * CMake
37# * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
Andrzej Kurek05be06c2018-06-28 04:41:50 -040038# * G++
Gilles Peskine192c72f2017-12-21 15:59:21 +010039# * arm-gcc and mingw-gcc
40# * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
Gilles Peskine192c72f2017-12-21 15:59:21 +010041# * OpenSSL and GnuTLS command line tools, recent enough for the
Mateusz Starzykf5c53512021-04-15 13:28:52 +020042# interoperability tests. If they don't support old features which we want
43# to test, then a legacy version of these tools must be present as well
44# (search for LEGACY below).
Gilles Peskine192c72f2017-12-21 15:59:21 +010045# See the invocation of check_tools below for details.
46#
47# This script must be invoked from the toplevel directory of a git
48# working copy of Mbed TLS.
49#
Gilles Peskinece266c42020-03-28 18:50:43 +010050# The behavior on an error depends on whether --keep-going (alias -k)
51# is in effect.
52# * Without --keep-going: the script stops on the first error without
53# cleaning up. This lets you work in the configuration of the failing
54# component.
55# * With --keep-going: the script runs all requested components and
56# reports failures at the end. In particular the script always cleans
57# up on exit.
58#
Gilles Peskine192c72f2017-12-21 15:59:21 +010059# Note that the output is not saved. You may want to run
60# script -c tests/scripts/all.sh
61# or
62# tests/scripts/all.sh >all.log 2>&1
63#
64# Notes for maintainers
65# ---------------------
66#
Gilles Peskine8f073122018-11-27 15:58:47 +010067# The bulk of the code is organized into functions that follow one of the
68# following naming conventions:
69# * pre_XXX: things to do before running the tests, in order.
70# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010071# * component_check_XXX: quick tests that aren't worth parallelizing.
72# * component_build_XXX: build things but don't run them.
73# * component_test_XXX: build and test.
Gilles Peskine878cf602019-01-06 20:50:38 +000074# * support_XXX: if support_XXX exists and returns false then
75# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010076# * post_XXX: things to do after running the tests.
77# * other: miscellaneous support functions.
78#
Gilles Peskinec70637a2019-01-09 22:29:17 +010079# Each component must start by invoking `msg` with a short informative message.
80#
Gilles Peskinea681c592020-03-28 21:27:40 +010081# Warning: due to the way bash detects errors, the failure of a command
82# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
83#
Gilles Peskinece266c42020-03-28 18:50:43 +010084# Each component is executed in a separate shell process. The component
85# fails if any command in it returns a non-zero status.
86#
Gilles Peskinec70637a2019-01-09 22:29:17 +010087# The framework performs some cleanup tasks after each component. This
88# means that components can assume that the working directory is in a
89# cleaned-up state, and don't need to perform the cleanup themselves.
90# * Run `make clean`.
Bence Szépkúti414d6bd2021-06-28 14:11:11 +010091# * Restore `include/mbedtls/mbedtls_config.h` from a backup made before running
Gilles Peskinec70637a2019-01-09 22:29:17 +010092# the component.
Gilles Peskine636c26a2020-03-04 20:46:15 +010093# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
94# `tests/Makefile` and `programs/fuzz/Makefile` from git.
95# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +010096#
Gilles Peskine192c72f2017-12-21 15:59:21 +010097# The tests are roughly in order from fastest to slowest. This doesn't
98# have to be exact, but in general you should add slower tests towards
99# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100100
101
102
103################################################################
104#### Initialization and command line parsing
105################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100106
Gilles Peskine36647802020-03-28 18:50:49 +0100107# Abort on errors (even on the left-hand side of a pipe).
108# Treat uninitialised variables as errors.
109set -e -o pipefail -u
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100110
Gilles Peskine076f7252022-08-30 21:02:44 +0200111# Enable ksh/bash extended file matching patterns
112shopt -s extglob
113
David Horstmann76a77382023-08-17 17:32:26 +0100114in_mbedtls_repo () {
David Horstmannd02b5f82023-08-29 09:53:52 +0100115 test -d include -a -d library -a -d programs -a -d tests
116}
117
118in_psa_crypto_repo () {
119 test -d include -a -d core -a -d drivers -a -d programs -a -d tests
David Horstmann9a6c45b2023-07-14 12:30:00 +0100120}
121
Gilles Peskine8f073122018-11-27 15:58:47 +0100122pre_check_environment () {
David Horstmann58cf7c62023-08-29 10:15:05 +0100123 if in_mbedtls_repo || in_psa_crypto_repo; then :; else
David Horstmannc69074d2023-08-29 13:46:11 +0100124 echo "Must be run from Mbed TLS / psa-crypto root" >&2
Gilles Peskine8f073122018-11-27 15:58:47 +0100125 exit 1
126 fi
127}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100128
Gilles Peskine8f073122018-11-27 15:58:47 +0100129pre_initialize_variables () {
David Horstmann76a77382023-08-17 17:32:26 +0100130 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100131 CONFIG_H='include/mbedtls/mbedtls_config.h'
David Horstmann76a77382023-08-17 17:32:26 +0100132 else
133 CONFIG_H='drivers/builtin/include/mbedtls/mbedtls_config.h'
David Horstmann9a6c45b2023-07-14 12:30:00 +0100134 fi
John Durkopbd069d32020-10-31 22:14:03 -0700135 CRYPTO_CONFIG_H='include/psa/crypto_config.h'
Manuel Pégourié-Gonnard462e3a92022-12-27 12:35:11 +0100136 CONFIG_TEST_DRIVER_H='tests/include/test/drivers/config_test_driver.h'
Gilles Peskinef83eb822020-03-30 20:11:39 +0200137
138 # Files that are clobbered by some jobs will be backed up. Use a different
139 # suffix from auxiliary scripts so that all.sh and auxiliary scripts can
140 # independently decide when to remove the backup file.
141 backup_suffix='.all.bak'
142 # Files clobbered by config.py
Janos Follath2f045822023-07-31 10:57:16 +0100143 files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H $CONFIG_TEST_DRIVER_H"
David Horstmann76a77382023-08-17 17:32:26 +0100144 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100145 # Files clobbered by in-tree cmake
146 files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile"
147 fi
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200148
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200149 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100150 MEMORY=0
151 FORCE=0
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200152 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100153 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100154
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200155 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard54304472020-06-22 10:11:47 +0200156 #
157 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
158 # both values are kept in sync. If you change the value here because it
159 # breaks some tests, you'll definitely want to change it in
160 # basic-build-test.sh as well.
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200161 RELEASE_SEED=1
162
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200163 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200164 : ${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 +0200165 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200166 export MBEDTLS_TEST_PLATFORM
167
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000168 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100169 : ${OPENSSL:="openssl"}
170 : ${OPENSSL_LEGACY:="$OPENSSL"}
171 : ${OPENSSL_NEXT:="$OPENSSL"}
172 : ${GNUTLS_CLI:="gnutls-cli"}
173 : ${GNUTLS_SERV:="gnutls-serv"}
174 : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"}
175 : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"}
176 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
177 : ${ARMC5_BIN_DIR:=/usr/bin}
178 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskine6d061342020-04-30 18:19:32 +0200179 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +0200180 : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
Gowtham Suresh Kumar9da40b82023-07-31 16:38:10 +0100181 : ${CLANG_LATEST:="clang-latest"}
182 : ${CLANG_EARLIEST:="clang-earliest"}
183 : ${GCC_LATEST:="gcc-latest"}
184 : ${GCC_EARLIEST:="gcc-earliest"}
Gilles Peskine8f073122018-11-27 15:58:47 +0100185 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000186 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine050d2fc2021-09-30 18:24:21 +0200187 export MAKEFLAGS="-j$(all_sh_nproc)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100188 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000189
Gilles Peskine396853a2021-09-20 18:57:55 +0200190 # Include more verbose output for failing tests run by CMake or make
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000191 export CTEST_OUTPUT_ON_FAILURE=1
192
Gilles Peskine8fd59422019-10-21 17:11:33 +0200193 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Manuel Pégourié-Gonnardfe549a72022-11-30 10:42:03 +0100194 # default to -O2, use -Ox _after_ this if you want another level
Przemek Stekiel6efa6082023-05-31 09:38:21 +0200195 ASAN_CFLAGS='-O2 -Werror -fsanitize=address,undefined -fno-sanitize-recover=all'
Gilles Peskine8fd59422019-10-21 17:11:33 +0200196
Andrzej Kurek04bfe572023-06-27 10:02:09 -0400197 # Platform tests have an allocation that returns null
198 export ASAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurek026235c2023-07-05 08:32:43 -0400199 export MSAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurek04bfe572023-06-27 10:02:09 -0400200
Gilles Peskine878cf602019-01-06 20:50:38 +0000201 # Gather the list of available components. These are the functions
202 # defined in this script whose name starts with "component_".
Gowtham Suresh Kumar1e829a42023-07-28 16:41:21 +0100203 ALL_COMPONENTS=$(compgen -A function component_ | sed 's/component_//')
Gilles Peskine878cf602019-01-06 20:50:38 +0000204
205 # Exclude components that are not supported on this platform.
206 SUPPORTED_COMPONENTS=
207 for component in $ALL_COMPONENTS; do
208 case $(type "support_$component" 2>&1) in
209 *' function'*)
210 if ! support_$component; then continue; fi;;
211 esac
212 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
213 done
Gilles Peskine8f073122018-11-27 15:58:47 +0100214}
Andres AG38495a32016-07-12 16:54:33 +0100215
Gilles Peskinea28db922019-01-10 00:05:18 +0100216# Test whether the component $1 is included in the command line patterns.
217is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100218{
Gilles Peskine03af6782021-08-06 11:35:17 +0200219 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
220 # only does word splitting.
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100221 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000222 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100223 set +f
224 case ${1#component_} in $pattern) return 0;; esac
225 done
226 set +f
227 return 1
228}
Andres AG7770ea82016-10-10 15:46:20 +0100229
Simon Butcher41eeccf2016-09-07 00:07:09 +0100230usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100231{
Gilles Peskine709346a2017-12-10 23:43:39 +0100232 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100233Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100234Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100235By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100236COMPONENT can be the name of a component or a shell wildcard pattern.
237
238Examples:
239 $0 "check_*"
240 Run all sanity checks.
241 $0 --no-armcc --except test_memsan
242 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100243
244Special options:
245 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000246 --list-all-components List all available test components and exit.
247 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100248
249General options:
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200250 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100251 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100252 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100253 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200254 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200255 --arm-none-eabi-gcc-prefix=<string>
256 Prefix for a cross-compiler for arm-none-eabi
257 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +0200258 --arm-linux-gnueabi-gcc-prefix=<string>
259 Prefix for a cross-compiler for arm-linux-gnueabi
260 (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100261 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine80ddb992021-08-06 11:51:59 +0200262 --restore First clean up the build tree, restoring backed up
263 files. Do not run any components unless they are
264 explicitly specified.
Gilles Peskine5d996822020-03-28 21:09:21 +0100265 --error-test Error test mode: run a failing function in addition
Gilles Peskine86f61292021-08-05 15:11:33 +0200266 to any specified component. May be repeated.
Gilles Peskinea28db922019-01-10 00:05:18 +0100267 --except Exclude the COMPONENTs listed on the command line,
268 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200269 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100270 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100271 --no-force Refuse to overwrite modified files (default).
272 --no-keep-going Stop at the first error (default).
273 --no-memory No additional memory tests (default).
Shaun Case8b0ecbc2021-12-20 21:14:10 -0800274 --no-quiet Print full output from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100275 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200276 --outcome-file=<path> File where test outcomes are written (not done if
277 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100278 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200279 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100280 -s|--seed Integer seed value to use for this test run.
281
282Tool path options:
283 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
284 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +0100285 --clang-earliest=<Clang_earliest_path> Earliest version of clang available
286 --clang-latest=<Clang_latest_path> Latest version of clang available
287 --gcc-earliest=<GCC_earliest_path> Earliest version of GCC available
288 --gcc-latest=<GCC_latest_path> Latest version of GCC available
Gilles Peskine709346a2017-12-10 23:43:39 +0100289 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
290 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
291 --gnutls-legacy-cli=<GnuTLS_cli_path> GnuTLS client executable to use for legacy tests.
292 --gnutls-legacy-serv=<GnuTLS_serv_path> GnuTLS server executable to use for legacy tests.
293 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
Mateusz Starzyk06b07fb2021-02-18 13:55:21 +0100294 --openssl-legacy=<OpenSSL_path> OpenSSL executable to use for legacy tests..
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100295 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100296EOF
SimonB2e23c822016-04-16 21:54:39 +0100297}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100298
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200299# Cleanup before/after running a component.
300# Remove built files as well as the cmake cache/config.
301# Does not remove generated source files.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100302cleanup()
303{
David Horstmann76a77382023-08-17 17:32:26 +0100304 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100305 command make clean
306 fi
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200307
Gilles Peskine31b07e22018-03-21 12:15:06 +0100308 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000309 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100310 -iname CMakeFiles -exec rm -rf {} \+ -o \
311 \( -iname cmake_install.cmake -o \
312 -iname CTestTestfile.cmake -o \
Manuel Pégourié-Gonnardbfe54d72021-09-09 11:11:44 +0200313 -iname CMakeCache.txt -o \
314 -path './cmake/*.cmake' \) -exec rm -f {} \+
Gilles Peskine31b07e22018-03-21 12:15:06 +0100315 # Recover files overwritten by in-tree CMake builds
Gilles Peskine076f7252022-08-30 21:02:44 +0200316 rm -f include/Makefile include/mbedtls/Makefile programs/!(fuzz)/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200317
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100318 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
319 rm -rf programs/test/cmake_subproject/build
320 rm -f programs/test/cmake_subproject/Makefile
321 rm -f programs/test/cmake_subproject/cmake_subproject
322
Chris Kayd259e342021-03-25 16:03:25 +0000323 # Remove any artifacts from the component_test_cmake_as_package test.
324 rm -rf programs/test/cmake_package/build
325 rm -f programs/test/cmake_package/Makefile
326 rm -f programs/test/cmake_package/cmake_package
327
328 # Remove any artifacts from the component_test_cmake_as_installed_package test.
329 rm -rf programs/test/cmake_package_install/build
330 rm -f programs/test/cmake_package_install/Makefile
331 rm -f programs/test/cmake_package_install/cmake_package_install
332
Gilles Peskinef83eb822020-03-30 20:11:39 +0200333 # Restore files that may have been clobbered by the job
334 for x in $files_to_back_up; do
Gilles Peskinedd06efb2022-08-30 21:02:00 +0200335 if [[ -e "$x$backup_suffix" ]]; then
336 cp -p "$x$backup_suffix" "$x"
337 fi
Gilles Peskinef83eb822020-03-30 20:11:39 +0200338 done
339}
John Durkopbd069d32020-10-31 22:14:03 -0700340
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200341# Final cleanup when this script exits (except when exiting on a failure
342# in non-keep-going mode).
Gilles Peskinef83eb822020-03-30 20:11:39 +0200343final_cleanup () {
344 cleanup
345
346 for x in $files_to_back_up; do
347 rm -f "$x$backup_suffix"
348 done
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100349}
350
Gilles Peskine7c652162017-12-11 00:01:40 +0100351# Executed on exit. May be redefined depending on command line options.
352final_report () {
353 :
354}
355
356fatal_signal () {
Gilles Peskinef83eb822020-03-30 20:11:39 +0200357 final_cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100358 final_report $1
359 trap - $1
360 kill -$1 $$
361}
362
363trap 'fatal_signal HUP' HUP
364trap 'fatal_signal INT' INT
365trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200366
Gilles Peskine050d2fc2021-09-30 18:24:21 +0200367# Number of processors on this machine. Used as the default setting
368# for parallel make.
369all_sh_nproc ()
370{
371 {
372 nproc || # Linux
373 sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
374 sysctl -n hw.ncpu || # FreeBSD
375 echo 1
376 } 2>/dev/null
377}
378
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100379msg()
380{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100381 if [ -n "${current_component:-}" ]; then
382 current_section="${current_component#component_}: $1"
383 else
384 current_section="$1"
385 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200386
387 if [ $QUIET -eq 1 ]; then
388 return
389 fi
390
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100391 echo ""
392 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100393 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000394 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100395 echo "******************************************************************"
396}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100397
Gilles Peskine8f073122018-11-27 15:58:47 +0100398armc6_build_test()
399{
400 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100401
Gilles Peskine18487f62020-04-30 23:11:54 +0200402 msg "build: ARM Compiler 6 ($FLAGS)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100403 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
Dave Rodgman1c232a82023-03-02 13:39:04 +0000404 WARNING_CFLAGS='-Werror -xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200405
406 msg "size: ARM Compiler 6 ($FLAGS)"
407 "$ARMC6_FROMELF" -z library/*.o
408
Gilles Peskine8f073122018-11-27 15:58:47 +0100409 make clean
410}
Andres AGa5cd9732016-10-17 15:23:10 +0100411
Andres AGd9eba4b2016-08-26 14:42:14 +0100412err_msg()
413{
414 echo "$1" >&2
415}
416
417check_tools()
418{
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200419 for tool in "$@"; do
420 if ! `type "$tool" >/dev/null 2>&1`; then
421 err_msg "$tool not found!"
Andres AGd9eba4b2016-08-26 14:42:14 +0100422 exit 1
423 fi
424 done
425}
426
Tom Cosgrove730addc2023-06-09 14:20:18 +0100427pre_parse_command_line_for_dirs () {
428 # Make an early pass through the options given, so we can set directories
429 # for Arm compilers, before SUPPORTED_COMPONENTS is determined.
430 while [ $# -gt 0 ]; do
431 case "$1" in
432 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
433 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
434 esac
435 shift
436 done
437}
438
Gilles Peskine8f073122018-11-27 15:58:47 +0100439pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000440 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100441 all_except=0
Gilles Peskine5d996822020-03-28 21:09:21 +0100442 error_test=0
Gilles Peskine80ddb992021-08-06 11:51:59 +0200443 restore_first=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000444 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100445
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000446 # Note that legacy options are ignored instead of being omitted from this
447 # list of options, so invocations that worked with previous version of
448 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100449 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100450 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200451 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200452 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +0200453 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000454 --armcc) no_armcc=;;
Tom Cosgrove730addc2023-06-09 14:20:18 +0100455 --armc5-bin-dir) shift; ;; # assignment to ARMC5_BIN_DIR done in pre_parse_command_line_for_dirs
456 --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 +0100457 --clang-earliest) shift; CLANG_EARLIEST="$1";;
458 --clang-latest) shift; CLANG_LATEST="$1";;
Gilles Peskine5d996822020-03-28 21:09:21 +0100459 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000460 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100461 --force|-f) FORCE=1;;
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +0100462 --gcc-earliest) shift; GCC_EARLIEST="$1";;
463 --gcc-latest) shift; GCC_LATEST="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100464 --gnutls-cli) shift; GNUTLS_CLI="$1";;
465 --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";;
466 --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";;
467 --gnutls-serv) shift; GNUTLS_SERV="$1";;
468 --help|-h) usage; exit;;
469 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000470 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
471 --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100472 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200473 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000474 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100475 --no-force) FORCE=0;;
476 --no-keep-going) KEEP_GOING=0;;
477 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200478 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100479 --openssl) shift; OPENSSL="$1";;
480 --openssl-legacy) shift; OPENSSL_LEGACY="$1";;
481 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200482 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100483 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200484 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100485 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200486 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine80ddb992021-08-06 11:51:59 +0200487 --restore) restore_first=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100488 --seed|-s) shift; SEED="$1";;
489 -*)
490 echo >&2 "Unknown option: $1"
491 echo >&2 "Run $0 --help for usage."
492 exit 120
493 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000494 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100495 esac
496 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100497 done
SimonB2e23c822016-04-16 21:54:39 +0100498
Gilles Peskinea28db922019-01-10 00:05:18 +0100499 # With no list of components, run everything.
Gilles Peskine80ddb992021-08-06 11:51:59 +0200500 if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000501 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100502 fi
503
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000504 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
505 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100506 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000507 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100508 fi
SimonB2e23c822016-04-16 21:54:39 +0100509
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200510 # Error out if an explicitly requested component doesn't exist.
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100511 if [ $all_except -eq 0 ]; then
512 unsupported=0
Gilles Peskine03af6782021-08-06 11:35:17 +0200513 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
514 # only does word splitting.
Gilles Peskine1d475b62021-08-03 13:43:36 +0200515 set -f
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100516 for component in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine1d475b62021-08-03 13:43:36 +0200517 set +f
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200518 # If the requested name includes a wildcard character, don't
519 # check it. Accept wildcard patterns that don't match anything.
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100520 case $component in
521 *[*?\[]*) continue;;
522 esac
523 case " $SUPPORTED_COMPONENTS " in
524 *" $component "*) :;;
525 *)
526 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
527 unsupported=$((unsupported + 1));;
528 esac
529 done
Gilles Peskine1d475b62021-08-03 13:43:36 +0200530 set +f
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100531 if [ $unsupported -ne 0 ]; then
532 exit 2
533 fi
534 fi
535
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000536 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100537 RUN_COMPONENTS=
538 for component in $SUPPORTED_COMPONENTS; do
539 if is_component_included "$component"; [ $? -eq $all_except ]; then
540 RUN_COMPONENTS="$RUN_COMPONENTS $component"
541 fi
542 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000543
544 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000545 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100546}
SimonB2e23c822016-04-16 21:54:39 +0100547
Gilles Peskine8f073122018-11-27 15:58:47 +0100548pre_check_git () {
549 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100550 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100551 git checkout-index -f -q $CONFIG_H
552 cleanup
553 else
SimonB2e23c822016-04-16 21:54:39 +0100554
Gilles Peskine8f073122018-11-27 15:58:47 +0100555 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
556 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
557 echo "You can either delete this directory manually, or force the test by rerunning"
558 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
559 exit 1
560 fi
561
Ronald Cron7a93ac52023-07-20 09:49:12 +0200562 if ! git diff --quiet "$CONFIG_H"; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100563 err_msg "Warning - the configuration file '$CONFIG_H' has been edited. "
Gilles Peskine8f073122018-11-27 15:58:47 +0100564 echo "You can either delete or preserve your work, or force the test by rerunning the"
565 echo "script as: $0 --force"
566 exit 1
567 fi
SimonB2e23c822016-04-16 21:54:39 +0100568 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500569}
570
Gilles Peskine568f53a2021-07-12 18:16:01 +0200571pre_restore_files () {
572 # If the makefiles have been generated by a framework such as cmake,
573 # restore them from git. If the makefiles look like modifications from
574 # the ones checked into git, take care not to modify them. Whatever
575 # this function leaves behind is what the script will restore before
576 # each component.
577 case "$(head -n1 Makefile)" in
578 *[Gg]enerated*)
579 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
580 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
581 ;;
582 esac
583}
584
Gilles Peskinef83eb822020-03-30 20:11:39 +0200585pre_back_up () {
586 for x in $files_to_back_up; do
587 cp -p "$x" "$x$backup_suffix"
588 done
589}
590
Gilles Peskine8f073122018-11-27 15:58:47 +0100591pre_setup_keep_going () {
Gilles Peskinece266c42020-03-28 18:50:43 +0100592 failure_count=0 # Number of failed components
593 last_failure_status=0 # Last failure status in this component
594
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100595 # See err_trap
596 previous_failure_status=0
597 previous_failed_command=
598 previous_failure_funcall_depth=0
Gilles Peskinea681c592020-03-28 21:27:40 +0100599 unset report_failed_command
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100600
Gilles Peskine7c652162017-12-11 00:01:40 +0100601 start_red=
602 end_color=
603 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100604 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100605 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
606 start_red=$(printf '\033[31m')
607 end_color=$(printf '\033[0m')
608 ;;
609 esac
610 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100611
612 # Keep a summary of failures in a file. We'll print it out at the end.
613 failure_summary_file=$PWD/all-sh-failures-$$.log
614 : >"$failure_summary_file"
615
616 # Whether it makes sense to keep a component going after the specified
617 # command fails (test command) or not (configure or build).
Gilles Peskine03af6782021-08-06 11:35:17 +0200618 # This function normally receives the failing simple command
619 # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
620 # this is passed instead.
Gilles Peskinece266c42020-03-28 18:50:43 +0100621 # This doesn't have to be 100% accurate: all failures are recorded anyway.
Gilles Peskinec111e242021-08-02 23:29:53 +0200622 # False positives result in running things that can't be expected to
623 # work. False negatives result in things not running after something else
624 # failed even though they might have given useful feedback.
Gilles Peskinece266c42020-03-28 18:50:43 +0100625 can_keep_going_after_failure () {
626 case "$1" in
627 "msg "*) false;;
Gilles Peskinec111e242021-08-02 23:29:53 +0200628 "cd "*) false;;
629 *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
630 *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
631 *make*check*) true;;
632 "grep "*) true;;
633 "[ "*) true;;
634 "! "*) true;;
Gilles Peskinece266c42020-03-28 18:50:43 +0100635 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100636 esac
637 }
Gilles Peskinece266c42020-03-28 18:50:43 +0100638
639 # This function runs if there is any error in a component.
640 # It must either exit with a nonzero status, or set
641 # last_failure_status to a nonzero value.
642 err_trap () {
643 # Save $? (status of the failing command). This must be the very
644 # first thing, before $? is overridden.
645 last_failure_status=$?
Gilles Peskinea681c592020-03-28 21:27:40 +0100646 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskinece266c42020-03-28 18:50:43 +0100647
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100648 if [[ $last_failure_status -eq $previous_failure_status &&
649 "$failed_command" == "$previous_failed_command" &&
650 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
651 then
652 # The same command failed twice in a row, but this time one level
653 # less deep in the function call stack. This happens when the last
654 # command of a function returns a nonzero status, and the function
655 # returns that same status. Ignore the second failure.
656 previous_failure_funcall_depth=${#FUNCNAME[@]}
657 return
658 fi
659 previous_failure_status=$last_failure_status
660 previous_failed_command=$failed_command
661 previous_failure_funcall_depth=${#FUNCNAME[@]}
662
Gilles Peskinece266c42020-03-28 18:50:43 +0100663 text="$current_section: $failed_command -> $last_failure_status"
664 echo "${start_red}^^^^$text^^^^${end_color}" >&2
665 echo "$text" >>"$failure_summary_file"
666
667 # If the command is fatal (configure or build command), stop this
668 # component. Otherwise (test command) keep the component running
669 # (run more tests from the same build).
670 if ! can_keep_going_after_failure "$failed_command"; then
671 exit $last_failure_status
672 fi
673 }
674
Gilles Peskine7c652162017-12-11 00:01:40 +0100675 final_report () {
676 if [ $failure_count -gt 0 ]; then
677 echo
678 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskinece266c42020-03-28 18:50:43 +0100679 echo "${start_red}FAILED: $failure_count components${end_color}"
680 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100681 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
682 elif [ -z "${1-}" ]; then
683 echo "SUCCESS :)"
684 fi
685 if [ -n "${1-}" ]; then
686 echo "Killed by SIG$1."
687 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100688 rm -f "$failure_summary_file"
689 if [ $failure_count -gt 0 ]; then
690 exit 1
691 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100692 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100693}
694
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200695# record_status() and if_build_succeeded() are kept temporarily for backward
696# compatibility. Don't use them in new components.
Gilles Peskinece266c42020-03-28 18:50:43 +0100697record_status () {
698 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100699}
Gilles Peskine7c652162017-12-11 00:01:40 +0100700if_build_succeeded () {
Gilles Peskinece266c42020-03-28 18:50:43 +0100701 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100702}
703
Gilles Peskinea681c592020-03-28 21:27:40 +0100704# '! true' does not trigger the ERR trap. Arrange to trigger it, with
705# a reasonably informative error message (not just "$@").
706not () {
707 if "$@"; then
708 report_failed_command="! $*"
709 false
710 unset report_failed_command
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200711 fi
712}
713
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200714pre_prepare_outcome_file () {
715 case "$MBEDTLS_TEST_OUTCOME_FILE" in
716 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
717 esac
718 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
719 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
720 fi
721}
722
Gilles Peskine8f073122018-11-27 15:58:47 +0100723pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200724 if [ $QUIET -eq 1 ]; then
725 return
726 fi
727
Gilles Peskine8f073122018-11-27 15:58:47 +0100728 msg "info: $0 configuration"
729 echo "MEMORY: $MEMORY"
730 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200731 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100732 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100733 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100734 echo "OPENSSL: $OPENSSL"
735 echo "OPENSSL_LEGACY: $OPENSSL_LEGACY"
736 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
737 echo "GNUTLS_CLI: $GNUTLS_CLI"
738 echo "GNUTLS_SERV: $GNUTLS_SERV"
739 echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI"
740 echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV"
741 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
742 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
743}
Andres AG7770ea82016-10-10 15:46:20 +0100744
Andres AGd9eba4b2016-08-26 14:42:14 +0100745# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100746pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000747 # Build the list of variables to pass to output_env.sh.
748 set env
SimonB2e23c822016-04-16 21:54:39 +0100749
Gilles Peskine87964262019-01-06 22:40:00 +0000750 case " $RUN_COMPONENTS " in
751 # Require OpenSSL and GnuTLS if running any tests (as opposed to
752 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
753 # is a good enough approximation in practice.
754 *" test_"*)
755 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
756 # and ssl-opt.sh, we just export the variables they require.
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +0100757 export OPENSSL="$OPENSSL"
Gilles Peskine87964262019-01-06 22:40:00 +0000758 export GNUTLS_CLI="$GNUTLS_CLI"
759 export GNUTLS_SERV="$GNUTLS_SERV"
760 # Avoid passing --seed flag in every call to ssl-opt.sh
761 if [ -n "${SEED-}" ]; then
762 export SEED
763 fi
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000764 set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY"
765 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
766 set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI"
767 set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000768 check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$OPENSSL_NEXT" \
769 "$GNUTLS_CLI" "$GNUTLS_SERV" \
770 "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV"
771 ;;
772 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200773
Gilles Peskine87964262019-01-06 22:40:00 +0000774 case " $RUN_COMPONENTS " in
775 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
776 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100777
Gilles Peskine87964262019-01-06 22:40:00 +0000778 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200779 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000780 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100781
Gilles Peskine87964262019-01-06 22:40:00 +0000782 case " $RUN_COMPONENTS " in
783 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
784 esac
785
786 case " $RUN_COMPONENTS " in
787 *" test_zeroize "*) check_tools "gdb";;
788 esac
789
790 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000791 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000792 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
793 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200794 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000795 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
796 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200797 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
798 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
799 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000800 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000801
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200802 # past this point, no call to check_tool, only printing output
803 if [ $QUIET -eq 1 ]; then
804 return
805 fi
806
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000807 msg "info: output_env.sh"
808 case $RUN_COMPONENTS in
809 *_armcc*)
810 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
811 *) set "$@" RUN_ARMCC=0;;
812 esac
813 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100814}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100815
Gilles Peskine1570b592021-04-22 01:10:12 +0200816pre_generate_files() {
Manuel Pégourié-Gonnard87db8a22021-06-18 13:30:14 +0200817 # since make doesn't have proper dependencies, remove any possibly outdate
818 # file that might be around before generating fresh ones
819 make neat
Gilles Peskine72385032021-07-08 19:07:07 +0200820 if [ $QUIET -eq 1 ]; then
Gilles Peskine75301632021-08-05 15:10:47 +0200821 make generated_files >/dev/null
Gilles Peskine72385032021-07-08 19:07:07 +0200822 else
823 make generated_files
824 fi
Gilles Peskine1570b592021-04-22 01:10:12 +0200825}
826
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200827################################################################
828#### Helpers for components using libtestdriver1
829################################################################
Gilles Peskine192c72f2017-12-21 15:59:21 +0100830
Manuel Pégourié-Gonnardf5c5d972023-06-06 11:14:57 +0200831# How to use libtestdriver1
832# -------------------------
833#
834# 1. Define the list algorithms and key types to accelerate,
835# designated the same way as PSA_WANT_ macros but without PSA_WANT_.
836# Examples:
837# - loc_accel_list="ALG_JPAKE"
838# - loc_accel_list="ALG_FFDH KEY_TYPE_DH_KEY_PAIR KEY_TYPE_DH_PUBLIC_KEY"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200839# 2. Make configurations changes for the driver and/or main libraries.
840# 2a. Call helper_libtestdriver1_adjust_config <base>, where the argument
841# can be either "default" to start with the default config, or a name
842# supported by scripts/config.py (for example, "full"). This selects
Manuel Pégourié-Gonnard2336c8e2023-06-12 17:17:54 +0200843# the base to use, and makes common adjustments.
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200844# 2b. If desired, adjust the PSA_WANT symbols in psa/crypto_config.h.
845# These changes affect both the driver and the main libraries.
846# (Note: they need to have the same set of PSA_WANT symbols, as that
847# determines the ABI between them.)
848# 2c. Adjust MBEDTLS_ symbols in mbedtls_config.h. This only affects the
849# main libraries. Typically, you want to disable the module(s) that are
850# being accelerated. You may need to also disable modules that depend
851# on them or options that are not supported with drivers.
852# 2d. On top of psa/crypto_config.h, the driver library uses its own config
853# file: tests/include/test/drivers/config_test_driver.h. You usually
854# don't need to edit it: using loc_extra_list (see below) is preferred.
855# However, when there's no PSA symbol for what you want to enable,
856# calling scripts/config.py on this file remains the only option.
857# 3. Build the driver library, then the main libraries, test, and programs.
858# 3a. Call helper_libtestdriver1_make_drivers "$loc_accel_list". You may
859# need to enable more algorithms here, typically hash algorithms when
860# accelerating some signature algorithms (ECDSA, RSAv2). This is done
861# by passing a 2nd argument listing the extra algorithms.
862# Example:
863# loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
864# helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
865# 4b. Call helper_libtestdriver1_make_main "$loc_accel_list". Any
866# additional arguments will be passed to make: this can be useful if
867# you don't want to build everything when iterating during development.
868# Example:
869# helper_libtestdriver1_make_main "$loc_accel_list" -C tests test_suite_foo
870# 4. Run the tests you want.
Manuel Pégourié-Gonnardf5c5d972023-06-06 11:14:57 +0200871
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200872# Adjust the configuration - for both libtestdriver1 and main library,
873# as they should have the same PSA_WANT macros.
874helper_libtestdriver1_adjust_config() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200875 base_config=$1
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200876 # Select the base configuration
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200877 if [ "$base_config" != "default" ]; then
878 scripts/config.py "$base_config"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200879 fi
880
881 # Enable PSA-based config (necessary to use drivers)
882 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
883
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200884 # Disable ALG_STREAM_CIPHER and ALG_ECB_NO_PADDING to avoid having
885 # partial support for cipher operations in the driver test library.
Ronald Cron6b49b552023-07-20 09:57:54 +0200886 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_STREAM_CIPHER
887 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
Manuel Pégourié-Gonnard2336c8e2023-06-12 17:17:54 +0200888
889 # Dynamic secure element support is a deprecated feature and needs to be disabled here.
890 # This is done to have the same form of psa_key_attributes_s for libdriver and library.
891 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200892}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100893
Valerio Settib2fd6732023-08-15 17:10:47 +0200894# When called with no parameter this function disables all builtin curves.
Valerio Setti4ca250b2023-09-04 14:01:41 +0200895# The function optionally accepts 1 parameter: a space-separated list of the
896# curves that should be kept enabled.
Valerio Settib2fd6732023-08-15 17:10:47 +0200897helper_disable_builtin_curves() {
898 allowed_list="${1:-}"
899 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
900
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200901 for curve in $allowed_list; do
902 scripts/config.py set $curve
Valerio Settib2fd6732023-08-15 17:10:47 +0200903 done
904}
905
906# Helper returning the list of supported elliptic curves from CRYPTO_CONFIG_H,
907# without the "PSA_WANT_" prefix. This becomes handy for accelerating curves
908# in the following helpers.
909helper_get_psa_curve_list () {
910 loc_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200911 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
912 loc_list="$loc_list $item"
Valerio Settib2fd6732023-08-15 17:10:47 +0200913 done
914
915 echo "$loc_list"
916}
917
918# Get the list of uncommented PSA_WANT_KEY_TYPE_xxx_ from CRYPTO_CONFIG_H. This
Valerio Setti0a342c92023-09-01 09:12:31 +0200919# is useful to easily get a list of key type symbols to accelerate.
Valerio Settib2fd6732023-08-15 17:10:47 +0200920# The function accepts a single argument which is the key type: ECC, DH, RSA.
Valerio Setti0a342c92023-09-01 09:12:31 +0200921helper_get_psa_key_type_list() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200922 key_type="$1"
Valerio Settib2fd6732023-08-15 17:10:47 +0200923 loc_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200924 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 +0200925 # Skip DERIVE for elliptic keys since there is no driver dispatch for
926 # it so it cannot be accelerated.
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200927 if [ "$item" != "KEY_TYPE_ECC_KEY_PAIR_DERIVE" ]; then
928 loc_list="$loc_list $item"
Valerio Settib2fd6732023-08-15 17:10:47 +0200929 fi
930 done
931
932 echo "$loc_list"
933}
934
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +0200935# Build the drivers library libtestdriver1.a (with ASan).
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +0200936#
937# Parameters:
938# 1. a space-separated list of things to accelerate;
939# 2. optional: a space-separate list of things to also support.
940# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
941helper_libtestdriver1_make_drivers() {
942 loc_accel_flags=$( echo "$1 ${2-}" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
943 make -C tests libtestdriver1.a CFLAGS=" $ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
944}
945
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +0200946# Build the main libraries, programs and tests,
947# linking to the drivers library (with ASan).
948#
949# Parameters:
950# 1. a space-separated list of things to accelerate;
951# *. remaining arguments if any are passed directly to make
952# (examples: lib, -C tests test_suite_xxx, etc.)
953# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
954helper_libtestdriver1_make_main() {
955 loc_accel_list=$1
956 shift
957
958 # we need flags both with and without the LIBTESTDRIVER1_ prefix
959 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
960 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
961 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" "$@"
962}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100963
964################################################################
965#### Basic checks
966################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100967
968#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200969# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100970#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +0100971# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200972# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100973# 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 +0200974# time, so start with a GCC build).
975# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +0100976#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +0100977# Indicative running times are given for reference.
978
Gilles Peskine8f073122018-11-27 15:58:47 +0100979component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +0200980 msg "Check: recursion.pl" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200981 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +0100982}
Janos Follathb72c6782016-07-19 14:54:17 +0100983
Gilles Peskine67debb62021-05-18 16:09:50 +0200984component_check_generated_files () {
985 msg "Check: check-generated-files, files generated with make" # 2s
986 make generated_files
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200987 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200988
989 msg "Check: check-generated-files -u, files present" # 2s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200990 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +0200991 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200992 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200993
994 msg "Check: check-generated-files -u, files absent" # 2s
995 command make neat
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200996 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +0200997 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200998 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +0200999
1000 # This component ends with the generated files present in the source tree.
1001 # This is necessary for subsequent components!
1002}
1003
Gilles Peskine8f073122018-11-27 15:58:47 +01001004component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001005 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001006 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001007}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001008
Gilles Peskine8f073122018-11-27 15:58:47 +01001009component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001010 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001011 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +01001012}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001013
Gilles Peskine30e0bb42020-05-10 17:40:49 +02001014component_check_changelog () {
1015 msg "Check: changelog entries" # < 1s
1016 rm -f ChangeLog.new
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001017 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +02001018 if [ -e ChangeLog.new ]; then
1019 # Show the diff for information. It isn't an error if the diff is
1020 # non-empty.
1021 diff -u ChangeLog ChangeLog.new || true
1022 rm ChangeLog.new
1023 fi
1024}
1025
Gilles Peskine8f073122018-11-27 15:58:47 +01001026component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001027 msg "Check: declared and exported names (builds the library)" # < 3s
Yuto Takanoc3a6f632021-09-24 18:02:56 +01001028 tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +01001029}
Darryl Greena07039c2018-03-13 16:48:16 +00001030
Gilles Peskine895868b2019-09-19 21:30:05 +02001031component_check_test_cases () {
1032 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001033 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001034 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001035 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001036 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001037 fi
Gilles Peskine031114d2022-12-15 14:46:31 +01001038 tests/scripts/check_test_cases.py -q $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001039 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +02001040}
1041
Gilles Peskine8f073122018-11-27 15:58:47 +01001042component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001043 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001044 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001045}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001046
Gilles Peskine192c72f2017-12-21 15:59:21 +01001047
Gilles Peskine636c26a2020-03-04 20:46:15 +01001048
Gilles Peskine192c72f2017-12-21 15:59:21 +01001049################################################################
1050#### Build and test many configurations and targets
1051################################################################
1052
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001053component_test_default_out_of_box () {
1054 msg "build: make, default config (out-of-box)" # ~1min
1055 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02001056 # Disable fancy stuff
1057 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001058
1059 msg "test: main suites make, default config (out-of-box)" # ~10s
1060 make test
1061
1062 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001063 programs/test/selftest
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 Peskine97bea012020-04-23 23:37:45 +02001074 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001075 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +02001076
Gilles Peskine8f073122018-11-27 15:58:47 +01001077 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001078 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001079
Gilles Peskine8f073122018-11-27 15:58:47 +01001080 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001081 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001082
1083 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001084 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001085}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001086
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001087component_test_default_cmake_gcc_asan_new_bignum () {
1088 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Janos Follath2f045822023-07-31 10:57:16 +01001089 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001090 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Janos Follath82823b22023-07-27 12:25:05 +01001091 make
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001092
1093 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
1094 make test
1095
1096 msg "test: selftest (ASan build)" # ~ 10s
1097 programs/test/selftest
1098
1099 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
1100 tests/ssl-opt.sh
1101
1102 msg "test: compat.sh (ASan build)" # ~ 6 min
1103 tests/compat.sh
1104
1105 msg "test: context-info.sh (ASan build)" # ~ 15 sec
1106 tests/context-info.sh
1107}
1108
Hanno Becker01635512019-02-26 14:27:09 +00001109component_test_full_cmake_gcc_asan () {
1110 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001111 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +00001112 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1113 make
1114
1115 msg "test: main suites (inc. selftests) (full config, ASan build)"
1116 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01001117
Gilles Peskine97bea012020-04-23 23:37:45 +02001118 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001119 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +02001120
Gilles Peskine636c26a2020-03-04 20:46:15 +01001121 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001122 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001123
1124 msg "test: compat.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001125 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001126
1127 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001128 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001129}
1130
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001131
1132component_test_full_cmake_gcc_asan_new_bignum () {
1133 msg "build: full config, cmake, gcc, ASan"
1134 scripts/config.py full
Janos Follath2f045822023-07-31 10:57:16 +01001135 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001136 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Janos Follath82823b22023-07-27 12:25:05 +01001137 make
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001138
1139 msg "test: main suites (inc. selftests) (full config, ASan build)"
1140 make test
1141
1142 msg "test: selftest (ASan build)" # ~ 10s
1143 programs/test/selftest
1144
1145 msg "test: ssl-opt.sh (full config, ASan build)"
1146 tests/ssl-opt.sh
1147
1148 msg "test: compat.sh (full config, ASan build)"
1149 tests/compat.sh
1150
1151 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
1152 tests/context-info.sh
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001153}
1154
Gabor Mezei6db60472023-07-05 16:38:42 +02001155component_test_full_cmake_gcc_asan_new_bignum_test_hooks () {
1156 msg "build: full config, cmake, gcc, ASan"
1157 scripts/config.py full
1158 scripts/config.py set MBEDTLS_TEST_HOOKS
Janos Follath2f045822023-07-31 10:57:16 +01001159 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Gabor Mezei6db60472023-07-05 16:38:42 +02001160 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Janos Follath82823b22023-07-27 12:25:05 +01001161 make
Gabor Mezei6db60472023-07-05 16:38:42 +02001162
1163 msg "test: main suites (inc. selftests) (full config, ASan build)"
1164 make test
1165
1166 msg "test: selftest (ASan build)" # ~ 10s
1167 programs/test/selftest
1168}
1169
Ronald Cronc3623db2020-10-29 10:51:32 +01001170component_test_psa_crypto_key_id_encodes_owner () {
Andrzej Kurek03e01462022-01-03 12:53:24 +01001171 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
Ronald Cronc3623db2020-10-29 10:51:32 +01001172 scripts/config.py full
Ronald Cronc3623db2020-10-29 10:51:32 +01001173 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1174 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1175 make
1176
1177 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
1178 make test
1179}
1180
Gilles Peskinea3548672021-06-17 11:37:52 +02001181# check_renamed_symbols HEADER LIB
1182# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
1183# name is LIB.
1184check_renamed_symbols () {
1185 ! nm "$2" | sed 's/.* //' |
1186 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
1187}
1188
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001189component_build_psa_crypto_spm () {
Andrzej Kurek03e01462022-01-03 12:53:24 +01001190 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001191 scripts/config.py full
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001192 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
1193 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1194 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
1195 # We can only compile, not link, since our test and sample programs
1196 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
1197 # is active.
1198 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskinea3548672021-06-17 11:37:52 +02001199
1200 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
1201 # version is not present.
1202 echo "Checking for renamed symbols in the library"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001203 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001204}
1205
Ronald Cron336678b2021-01-28 17:54:24 +01001206component_test_psa_crypto_client () {
1207 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
1208 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1209 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1210 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
Raef Colesb4568c52022-09-28 17:11:42 +01001211 scripts/config.py unset MBEDTLS_LMS_C
1212 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Ronald Cron336678b2021-01-28 17:54:24 +01001213 make
1214
1215 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT, make"
1216 make test
1217}
1218
Jaeden Amero424fa932021-05-14 08:34:32 +01001219component_test_psa_crypto_rsa_no_genprime() {
1220 msg "build: default config minus MBEDTLS_GENPRIME"
1221 scripts/config.py unset MBEDTLS_GENPRIME
1222 make
1223
1224 msg "test: default config minus MBEDTLS_GENPRIME"
1225 make test
1226}
1227
Gilles Peskine782f4112018-11-27 16:11:09 +01001228component_test_ref_configs () {
1229 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Manuel Pégourié-Gonnard9327fb32021-09-09 11:46:25 +02001230 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
1231 # want to re-generate generated files that depend on it, quite correctly.
1232 # However this doesn't work as the generation script expects a specific
1233 # format for mbedtls_config.h, which the other files don't follow. Also,
1234 # cmake can't know this, but re-generation is actually not necessary as
David Horstmannd64f4b22021-10-20 12:29:47 +01001235 # the generated files only depend on the list of available options, not
Manuel Pégourié-Gonnard9327fb32021-09-09 11:46:25 +02001236 # whether they're on or off. So, disable cmake's (over-sensitive here)
1237 # dependency resolution for generated files and just rely on them being
David Horstmanna8d14062021-10-20 17:14:23 +01001238 # present (thanks to pre_generate_files) by turning GEN_FILES off.
1239 CC=gcc cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001240 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +01001241}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001242
Gilles Peskine8f073122018-11-27 15:58:47 +01001243component_test_no_renegotiation () {
1244 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001245 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Gilles Peskine8f073122018-11-27 15:58:47 +01001246 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1247 make
Simon Butcher3ea7f522016-03-07 23:22:10 +00001248
Gilles Peskine8f073122018-11-27 15:58:47 +01001249 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1250 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +01001251
Gilles Peskine8f073122018-11-27 15:58:47 +01001252 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001253 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001254}
Hanno Becker134c2ab2017-10-12 15:29:50 +01001255
Gilles Peskine636c26a2020-03-04 20:46:15 +01001256component_test_no_pem_no_fs () {
1257 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1258 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1259 scripts/config.py unset MBEDTLS_FS_IO
1260 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1261 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
1262 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1263 make
1264
1265 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1266 make test
1267
1268 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001269 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001270}
1271
Gilles Peskine8f073122018-11-27 15:58:47 +01001272component_test_rsa_no_crt () {
1273 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001274 scripts/config.py set MBEDTLS_RSA_NO_CRT
Gilles Peskine8f073122018-11-27 15:58:47 +01001275 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1276 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +01001277
Gilles Peskine8f073122018-11-27 15:58:47 +01001278 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1279 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001280
Gilles Peskine8f073122018-11-27 15:58:47 +01001281 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001282 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001283
Gilles Peskine8f073122018-11-27 15:58:47 +01001284 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001285 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001286
1287 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001288 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001289}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001290
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001291component_test_no_ctr_drbg_classic () {
1292 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001293 scripts/config.py full
1294 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001295 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001296 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001297
1298 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1299 make
1300
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001301 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001302 make test
1303
Gilles Peskineba749042021-01-13 20:02:03 +01001304 # In this configuration, the TLS test programs use HMAC_DRBG.
1305 # The SSL tests are slow, so run a small subset, just enough to get
1306 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001307 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001308 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001309
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001310 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001311 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001312}
1313
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001314component_test_no_ctr_drbg_use_psa () {
1315 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001316 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001317 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1318 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001319
1320 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1321 make
1322
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001323 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1324 make test
1325
1326 # In this configuration, the TLS test programs use HMAC_DRBG.
1327 # The SSL tests are slow, so run a small subset, just enough to get
1328 # confidence that the SSL code copes with HMAC_DRBG.
1329 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001330 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001331
1332 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001333 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001334}
1335
1336component_test_no_hmac_drbg_classic () {
1337 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1338 scripts/config.py full
1339 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1340 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1341 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001342 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001343
1344 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1345 make
1346
1347 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001348 make test
1349
Gilles Peskinea2224342020-11-19 22:14:34 +01001350 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1351 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1352 # instead.
1353 # Test SSL with non-deterministic ECDSA. Only test features that
1354 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001355 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001356 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001357
1358 # To save time, only test one protocol version, since this part of
1359 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001360 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001361 tests/compat.sh -m tls12 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001362}
1363
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001364component_test_no_hmac_drbg_use_psa () {
1365 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1366 scripts/config.py full
1367 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1368 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1369 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1370
1371 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1372 make
1373
1374 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1375 make test
1376
1377 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1378 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1379 # instead.
1380 # Test SSL with non-deterministic ECDSA. Only test features that
1381 # might be affected by how ECDSA signature is performed.
1382 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001383 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001384
1385 # To save time, only test one protocol version, since this part of
1386 # the protocol is identical in (D)TLS up to 1.2.
1387 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001388 tests/compat.sh -m tls12 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001389}
1390
1391component_test_psa_external_rng_no_drbg_classic () {
1392 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1393 scripts/config.py full
1394 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001395 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001396 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001397 scripts/config.py unset MBEDTLS_ENTROPY_C
1398 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1399 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001400 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1401 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1402 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001403 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1404 # the SSL test programs don't have an RNG and can't work. Explicitly
1405 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1406 make CFLAGS="$ASAN_CFLAGS -O2 -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001407
1408 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1409 make test
1410
Gilles Peskine8eb29432021-02-03 20:07:11 +01001411 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001412 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001413}
1414
1415component_test_psa_external_rng_no_drbg_use_psa () {
1416 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001417 scripts/config.py full
1418 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001419 scripts/config.py unset MBEDTLS_ENTROPY_C
1420 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1421 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001422 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1423 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1424 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskinec109b372020-11-23 17:39:04 +01001425 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1426
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001427 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001428 make test
1429
Gilles Peskine8eb29432021-02-03 20:07:11 +01001430 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001431 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001432}
1433
Gilles Peskine4bdb2542023-04-28 19:25:25 +02001434component_test_psa_external_rng_use_psa_crypto () {
1435 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1436 scripts/config.py full
1437 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1438 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1439 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1440 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1441
1442 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1443 make test
1444
1445 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1446 tests/ssl-opt.sh -f 'Default\|opaque'
1447}
1448
Gilles Peskine801c4332023-04-28 21:04:28 +02001449component_test_psa_inject_entropy () {
1450 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
1451 scripts/config.py full
1452 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
1453 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
1454 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1455 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1456 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
1457 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
1458 make CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
1459
1460 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
1461 make test
1462}
1463
Andrzej Kurek06969fc2023-04-12 10:34:50 -04001464component_test_sw_inet_pton () {
1465 msg "build: default plus MBEDTLS_TEST_SW_INET_PTON"
1466
1467 # MBEDTLS_TEST_HOOKS required for x509_crt_parse_cn_inet_pton
1468 scripts/config.py set MBEDTLS_TEST_HOOKS
1469 make CFLAGS="-DMBEDTLS_TEST_SW_INET_PTON"
1470
1471 msg "test: default plus MBEDTLS_TEST_SW_INET_PTON"
1472 make test
1473}
1474
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001475component_test_crypto_full_md_light_only () {
1476 msg "build: crypto_full with only the light subset of MD"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001477 scripts/config.py crypto_full
Gilles Peskine884b4622023-07-20 20:11:51 +02001478 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001479 # Disable MD
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001480 scripts/config.py unset MBEDTLS_MD_C
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001481 # Disable direct dependencies of MD_C
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001482 scripts/config.py unset MBEDTLS_HKDF_C
1483 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
Nick Child89e82e12022-11-09 10:36:10 -06001484 scripts/config.py unset MBEDTLS_PKCS7_C
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001485 # Disable indirect dependencies of MD_C
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001486 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001487 # Disable things that would auto-enable MD_C
1488 scripts/config.py unset MBEDTLS_PKCS5_C
1489
Manuel Pégourié-Gonnard1b5ffc62023-03-14 10:11:20 +01001490 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
1491 # which we haven't disabled, so no need to explicitly enable it.
1492 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001493
Manuel Pégourié-Gonnard0d415212023-02-23 13:02:13 +01001494 # Make sure we don't have the HMAC functions, but the hashing functions
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001495 not grep mbedtls_md_hmac library/md.o
Manuel Pégourié-Gonnard0d415212023-02-23 13:02:13 +01001496 grep mbedtls_md library/md.o
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001497
1498 msg "test: crypto_full with only the light subset of MD"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001499 make test
1500}
1501
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001502component_test_full_no_cipher () {
1503 msg "build: full minus CIPHER"
1504 scripts/config.py full
1505 scripts/config.py unset MBEDTLS_CIPHER_C
Gilles Peskine9b8dead2023-08-09 19:48:42 +02001506 # Don't pull in cipher via PSA mechanisms
1507 # (currently ignored anyway because we completely disable PSA)
1508 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Przemek Stekielda5f4832022-05-12 09:46:29 +02001509 # Direct dependencies
1510 scripts/config.py unset MBEDTLS_CCM_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001511 scripts/config.py unset MBEDTLS_CMAC_C
Przemek Stekielda5f4832022-05-12 09:46:29 +02001512 scripts/config.py unset MBEDTLS_GCM_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001513 scripts/config.py unset MBEDTLS_NIST_KW_C
1514 scripts/config.py unset MBEDTLS_PKCS12_C
1515 scripts/config.py unset MBEDTLS_PKCS5_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001516 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1517 scripts/config.py unset MBEDTLS_SSL_TLS_C
1518 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielda5f4832022-05-12 09:46:29 +02001519 # Indirect dependencies
1520 scripts/config.py unset MBEDTLS_SSL_CLI_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001521 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
1522 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001523 scripts/config.py unset MBEDTLS_SSL_DTLS_ANTI_REPLAY
1524 scripts/config.py unset MBEDTLS_SSL_DTLS_CONNECTION_ID
Dave Rodgman1df70702022-10-26 17:08:54 +01001525 scripts/config.py unset MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT
Przemek Stekielda5f4832022-05-12 09:46:29 +02001526 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1527 scripts/config.py unset MBEDTLS_SSL_SRV_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001528 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Raef Colesa7e03ad2022-09-28 09:32:48 +01001529 scripts/config.py unset MBEDTLS_LMS_C
Raef Coles47bccb72022-09-28 12:00:20 +01001530 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001531 make
1532
1533 msg "test: full minus CIPHER"
1534 make test
1535}
1536
Valerio Settie1655b82023-01-03 15:35:25 +01001537component_test_full_no_bignum () {
1538 msg "build: full minus bignum"
1539 scripts/config.py full
1540 scripts/config.py unset MBEDTLS_BIGNUM_C
1541 # Direct dependencies of bignum
1542 scripts/config.py unset MBEDTLS_ECP_C
1543 scripts/config.py unset MBEDTLS_RSA_C
1544 scripts/config.py unset MBEDTLS_DHM_C
1545 # Direct dependencies of ECP
1546 scripts/config.py unset MBEDTLS_ECDH_C
1547 scripts/config.py unset MBEDTLS_ECDSA_C
1548 scripts/config.py unset MBEDTLS_ECJPAKE_C
1549 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Setti22d0a792023-06-14 17:23:19 +02001550 # Disable what auto-enables ECP_LIGHT
1551 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1552 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
Valerio Settie1655b82023-01-03 15:35:25 +01001553 # Indirect dependencies of ECP
1554 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1555 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1556 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1557 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1558 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1559 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
1560 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
1561 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
1562 # Direct dependencies of DHM
1563 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1564 # Direct dependencies of RSA
1565 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1566 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1567 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1568 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1569 # PK and its dependencies
1570 scripts/config.py unset MBEDTLS_PK_C
1571 scripts/config.py unset MBEDTLS_PK_PARSE_C
1572 scripts/config.py unset MBEDTLS_PK_WRITE_C
1573 scripts/config.py unset MBEDTLS_X509_USE_C
1574 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
1575 scripts/config.py unset MBEDTLS_X509_CRL_PARSE_C
1576 scripts/config.py unset MBEDTLS_X509_CSR_PARSE_C
1577 scripts/config.py unset MBEDTLS_X509_CREATE_C
1578 scripts/config.py unset MBEDTLS_X509_CRT_WRITE_C
1579 scripts/config.py unset MBEDTLS_X509_CSR_WRITE_C
1580 scripts/config.py unset MBEDTLS_PKCS7_C
1581 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
1582 scripts/config.py unset MBEDTLS_SSL_ASYNC_PRIVATE
1583 scripts/config.py unset MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
1584
1585 make
1586
1587 msg "test: full minus bignum"
1588 make test
1589}
1590
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001591component_test_tls1_2_default_stream_cipher_only () {
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001592 msg "build: default with only stream cipher"
1593
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001594 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001595 scripts/config.py unset MBEDTLS_GCM_C
1596 scripts/config.py unset MBEDTLS_CCM_C
1597 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001598 # 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 +02001599 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001600 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001601 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001602 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1603 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001604 # Modules that depend on AEAD
Przemek Stekield582a012022-09-28 07:59:01 +02001605 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001606 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001607
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001608 make
1609
1610 msg "test: default with only stream cipher"
1611 make test
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001612
1613 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001614}
1615
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001616component_test_tls1_2_default_stream_cipher_only_use_psa () {
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001617 msg "build: default with only stream cipher use psa"
Przemek Stekiel9550c052022-09-28 09:51:55 +02001618
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001619 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001620 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel9550c052022-09-28 09:51:55 +02001621 scripts/config.py unset MBEDTLS_GCM_C
1622 scripts/config.py unset MBEDTLS_CCM_C
1623 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001624 # 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 +02001625 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001626 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekiel9550c052022-09-28 09:51:55 +02001627 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001628 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1629 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001630 # Modules that depend on AEAD
Przemek Stekiel9550c052022-09-28 09:51:55 +02001631 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001632 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel9550c052022-09-28 09:51:55 +02001633
Przemek Stekiel9550c052022-09-28 09:51:55 +02001634 make
1635
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001636 msg "test: default with only stream cipher use psa"
Przemek Stekiel9550c052022-09-28 09:51:55 +02001637 make test
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001638
1639 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
Przemek Stekiel9550c052022-09-28 09:51:55 +02001640}
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001641
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001642component_test_tls1_2_default_cbc_legacy_cipher_only () {
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001643 msg "build: default with only CBC-legacy cipher"
1644
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001645 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001646 scripts/config.py unset MBEDTLS_GCM_C
1647 scripts/config.py unset MBEDTLS_CCM_C
1648 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001649 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1650 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1651 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001652 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001653 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001654 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001655 # Modules that depend on AEAD
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001656 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001657 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001658
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001659 make
1660
1661 msg "test: default with only CBC-legacy cipher"
1662 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001663
1664 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1665 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001666}
1667
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001668component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001669 msg "build: default with only CBC-legacy cipher use psa"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001670
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001671 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001672 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001673 scripts/config.py unset MBEDTLS_GCM_C
1674 scripts/config.py unset MBEDTLS_CCM_C
1675 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001676 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1677 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1678 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001679 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001680 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001681 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001682 # Modules that depend on AEAD
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001683 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001684 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001685
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001686 make
1687
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001688 msg "test: default with only CBC-legacy cipher use psa"
1689 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001690
1691 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1692 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001693}
1694
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001695component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001696 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1697
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001698 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001699 scripts/config.py unset MBEDTLS_GCM_C
1700 scripts/config.py unset MBEDTLS_CCM_C
1701 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001702 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1703 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1704 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1705 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1706 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001707 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001708 # Modules that depend on AEAD
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001709 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001710 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001711
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001712 make
1713
1714 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1715 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001716
1717 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1718 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001719}
1720
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001721component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
1722 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001723
1724 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001725 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001726 scripts/config.py unset MBEDTLS_GCM_C
1727 scripts/config.py unset MBEDTLS_CCM_C
1728 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001729 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1730 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1731 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1732 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1733 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001734 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001735 # Modules that depend on AEAD
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001736 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001737 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001738
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001739 make
1740
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001741 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001742 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001743
1744 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
1745 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001746}
1747
Valerio Setti9f0ec532022-11-08 13:03:24 +01001748# We're not aware of any other (open source) implementation of EC J-PAKE in TLS
1749# that we could use for interop testing. However, we now have sort of two
1750# implementations ourselves: one using PSA, the other not. At least test that
1751# these two interoperate with each other.
1752component_test_tls1_2_ecjpake_compatibility() {
1753 msg "build: TLS1.2 server+client w/ EC-JPAKE w/o USE_PSA"
1754 scripts/config.py set MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
Gilles Peskineedc84562023-09-20 15:03:18 +02001755 # Explicitly make lib first to avoid a race condition:
1756 # https://github.com/Mbed-TLS/mbedtls/issues/8229
1757 make lib
Valerio Setti9f0ec532022-11-08 13:03:24 +01001758 make -C programs ssl/ssl_server2 ssl/ssl_client2
1759 cp programs/ssl/ssl_server2 s2_no_use_psa
1760 cp programs/ssl/ssl_client2 c2_no_use_psa
1761
1762 msg "build: TLS1.2 server+client w/ EC-JPAKE w/ USE_PSA"
1763 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1764 make clean
Gilles Peskineedc84562023-09-20 15:03:18 +02001765 make lib
Valerio Setti9f0ec532022-11-08 13:03:24 +01001766 make -C programs ssl/ssl_server2 ssl/ssl_client2
1767 make -C programs test/udp_proxy test/query_compile_time_config
1768
Valerio Setti70e02902022-12-02 16:21:56 +01001769 msg "test: server w/o USE_PSA - client w/ USE_PSA, text password"
1770 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
1771 msg "test: server w/o USE_PSA - client w/ USE_PSA, opaque password"
1772 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password client only, working, TLS"
1773 msg "test: client w/o USE_PSA - server w/ USE_PSA, text password"
1774 P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
1775 msg "test: client w/o USE_PSA - server w/ USE_PSA, opaque password"
1776 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 +01001777
1778 rm s2_no_use_psa c2_no_use_psa
1779}
1780
Gilles Peskine636c26a2020-03-04 20:46:15 +01001781component_test_everest () {
1782 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine636c26a2020-03-04 20:46:15 +01001783 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1784 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
1785 make
1786
1787 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
1788 make test
1789
1790 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001791 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01001792
1793 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
1794 # Exclude some symmetric ciphers that are redundant here to gain time.
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02001795 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
Gilles Peskine636c26a2020-03-04 20:46:15 +01001796}
1797
Gilles Peskined3beca92020-07-03 00:15:37 +02001798component_test_everest_curve25519_only () {
1799 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
Gilles Peskined3beca92020-07-03 00:15:37 +02001800 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
1801 scripts/config.py unset MBEDTLS_ECDSA_C
1802 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1803 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
TRodziewicz7c1d41d2021-04-23 13:33:44 +02001804 scripts/config.py unset MBEDTLS_ECJPAKE_C
Gilles Peskined3beca92020-07-03 00:15:37 +02001805 # Disable all curves
Valerio Setti2e0275d2023-07-28 16:33:13 +02001806 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
Gilles Peskined3beca92020-07-03 00:15:37 +02001807 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
1808
1809 make CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
1810
1811 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
1812 make test
1813}
1814
Gilles Peskine8f073122018-11-27 15:58:47 +01001815component_test_small_ssl_out_content_len () {
1816 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001817 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
1818 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01001819 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1820 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001821
Gilles Peskine8f073122018-11-27 15:58:47 +01001822 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001823 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01001824}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001825
Gilles Peskine8f073122018-11-27 15:58:47 +01001826component_test_small_ssl_in_content_len () {
1827 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001828 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
1829 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Gilles Peskine8f073122018-11-27 15:58:47 +01001830 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1831 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001832
Gilles Peskine8f073122018-11-27 15:58:47 +01001833 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001834 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01001835}
Angus Grattonc4dd0732018-04-11 16:28:39 +10001836
Gilles Peskine8f073122018-11-27 15:58:47 +01001837component_test_small_ssl_dtls_max_buffering () {
1838 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001839 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Gilles Peskine8f073122018-11-27 15:58:47 +01001840 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1841 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10001842
Gilles Peskine8f073122018-11-27 15:58:47 +01001843 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001844 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 +01001845}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001846
Gilles Peskine8f073122018-11-27 15:58:47 +01001847component_test_small_mbedtls_ssl_dtls_max_buffering () {
1848 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001849 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Gilles Peskine8f073122018-11-27 15:58:47 +01001850 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1851 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001852
Gilles Peskine8f073122018-11-27 15:58:47 +01001853 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001854 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01001855}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001856
Gilles Peskine75cc7712019-09-06 19:47:17 +02001857component_test_psa_collect_statuses () {
1858 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02001859 scripts/config.py full
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001860 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02001861 # Check that psa_crypto_init() succeeded at least once
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001862 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02001863 rm -f tests/statuses.log
1864}
1865
Gilles Peskine8f073122018-11-27 15:58:47 +01001866component_test_full_cmake_clang () {
1867 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001868 scripts/config.py full
Gilles Peskineda6017c2022-10-30 21:02:40 +01001869 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 +01001870 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01001871
k-stachowiak0291cb72019-06-26 15:52:12 +02001872 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01001873 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01001874
Gilles Peskineda6017c2022-10-30 21:02:40 +01001875 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
1876 programs/test/cpp_dummy_build
1877
k-stachowiak0291cb72019-06-26 15:52:12 +02001878 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001879 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01001880
Gilles Peskine8f073122018-11-27 15:58:47 +01001881 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001882 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001883
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02001884 msg "test: compat.sh NULL (full config)" # ~ 2 min
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01001885 env OPENSSL="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '^$' -f 'NULL'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001886
Gilles Peskine8f073122018-11-27 15:58:47 +01001887 msg "test: compat.sh ARIA + ChachaPoly"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01001888 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01001889}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02001890
Gilles Peskine0c671602022-11-29 16:01:41 +01001891skip_suites_without_constant_flow () {
1892 # Skip the test suites that don't have any constant-flow annotations.
1893 # This will need to be adjusted if we ever start declaring things as
1894 # secret from macros or functions inside tests/include or tests/src.
1895 SKIP_TEST_SUITES=$(
1896 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
1897 sed 's/test_suite_//; s/\.function$//' |
1898 tr '\n' ,)
1899 export SKIP_TEST_SUITES
1900}
1901
Dave Rodgman246210e2023-07-31 18:07:44 +01001902skip_all_except_given_suite () {
1903 # Skip all but the given test suite
1904 SKIP_TEST_SUITES=$(
1905 ls -1 tests/suites/test_suite_*.function |
1906 grep -v $1.function |
1907 sed 's/tests.suites.test_suite_//; s/\.function$//' |
1908 tr '\n' ,)
1909 export SKIP_TEST_SUITES
1910}
1911
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001912component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001913 # This tests both (1) accesses to undefined memory, and (2) branches or
1914 # memory access depending on secret values. To distinguish between those:
1915 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1916 # - or alternatively, change the build type to MemSanDbg, which enables
1917 # origin tracking and nicer stack traces (which are useful for debugging
1918 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001919 msg "build: cmake MSan (clang), full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
1920 scripts/config.py full
1921 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1922 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1923 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1924 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1925 make
1926
1927 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO, Msan + constant flow)"
1928 make test
1929}
1930
1931component_test_memsan_constant_flow_psa () {
1932 # This tests both (1) accesses to undefined memory, and (2) branches or
1933 # memory access depending on secret values. To distinguish between those:
1934 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
1935 # - or alternatively, change the build type to MemSanDbg, which enables
1936 # origin tracking and nicer stack traces (which are useful for debugging
1937 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001938 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001939 scripts/config.py full
1940 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
1941 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
1942 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
1943 make
1944
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02001945 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02001946 make test
1947}
1948
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001949component_test_valgrind_constant_flow () {
1950 # This tests both (1) everything that valgrind's memcheck usually checks
1951 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1952 # etc.) and (2) branches or memory access depending on secret values,
1953 # which will be reported as uninitialized memory. To distinguish between
1954 # secret and actually uninitialized:
1955 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1956 # - or alternatively, build with debug info and manually run the offending
1957 # test suite with valgrind --track-origins=yes, then check if the origin
1958 # was TEST_CF_SECRET() or something else.
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001959 msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
1960 scripts/config.py full
1961 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
1962 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine0c671602022-11-29 16:01:41 +01001963 skip_suites_without_constant_flow
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001964 cmake -D CMAKE_BUILD_TYPE:String=Release .
1965 make
1966
1967 # this only shows a summary of the results (how many of each type)
1968 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine0c671602022-11-29 16:01:41 +01001969 msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, valgrind + constant flow)"
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001970 make memcheck
Dave Rodgman246210e2023-07-31 18:07:44 +01001971
1972 # Test asm path in constant time module - by default, it will test the plain C
1973 # path under Valgrind or Memsan. Running only the constant_time tests is fast (<1s)
1974 msg "test: valgrind asm constant_time"
1975 scripts/config.py --force set MBEDTLS_TEST_CONSTANT_FLOW_ASM
1976 skip_all_except_given_suite test_suite_constant_time
1977 cmake -D CMAKE_BUILD_TYPE:String=Release .
1978 make clean
1979 make
1980 make memcheck
Neil Armstrong0ab7a232022-03-18 09:57:32 +01001981}
1982
1983component_test_valgrind_constant_flow_psa () {
1984 # This tests both (1) everything that valgrind's memcheck usually checks
1985 # (heap buffer overflows, use of uninitialized memory, use-after-free,
1986 # etc.) and (2) branches or memory access depending on secret values,
1987 # which will be reported as uninitialized memory. To distinguish between
1988 # secret and actually uninitialized:
1989 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
1990 # - or alternatively, build with debug info and manually run the offending
1991 # test suite with valgrind --track-origins=yes, then check if the origin
1992 # was TEST_CF_SECRET() or something else.
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001993 msg "build: cmake release GCC, full config with constant flow testing"
1994 scripts/config.py full
1995 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Gilles Peskine0c671602022-11-29 16:01:41 +01001996 skip_suites_without_constant_flow
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02001997 cmake -D CMAKE_BUILD_TYPE:String=Release .
1998 make
1999
2000 # this only shows a summary of the results (how many of each type)
2001 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine0c671602022-11-29 16:01:41 +01002002 msg "test: some suites (valgrind + constant flow)"
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02002003 make memcheck
2004}
2005
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002006component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02002007 # Test that removing the deprecated features from the default
2008 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002009 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
2010 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
2011 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
2012
2013 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
2014 make test
2015}
2016
2017component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02002018 msg "build: make, full_no_deprecated config" # ~ 30s
2019 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002020 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
2021
Gilles Peskine30de2e82020-04-20 21:39:22 +02002022 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002023 make test
Valerio Setti41b5fb62023-01-09 12:20:45 +01002024
2025 msg "test: ensure that X509 has no direct dependency on BIGNUM_C"
2026 not grep mbedtls_mpi library/libmbedx509.a
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002027}
2028
Gilles Peskine8386ea22020-04-30 09:07:29 +02002029component_test_full_no_deprecated_deprecated_warning () {
2030 # Test that there is nothing deprecated in "full_no_deprecated".
2031 # A deprecated feature would trigger a warning (made fatal) from
2032 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02002033 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
2034 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002035 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
2036 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
2037 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra'
2038
Gilles Peskine30de2e82020-04-20 21:39:22 +02002039 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002040 make test
2041}
2042
Gilles Peskine8386ea22020-04-30 09:07:29 +02002043component_test_full_deprecated_warning () {
2044 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
2045 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002046 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002047 scripts/config.py full
2048 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002049 # Expect warnings from '#warning' directives in check_config.h.
2050 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01002051
Gilles Peskine8386ea22020-04-30 09:07:29 +02002052 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
2053 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
2054 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002055 # Expect warnings from '#warning' directives in check_config.h and
2056 # from the use of deprecated functions in test suites.
2057 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 +01002058
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002059 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
2060 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01002061}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00002062
Gilles Peskineec541fe2020-01-31 14:24:14 +01002063# Check that the specified libraries exist and are empty.
2064are_empty_libraries () {
2065 nm "$@" >/dev/null 2>/dev/null
2066 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
2067}
2068
2069component_build_crypto_default () {
2070 msg "build: make, crypto only"
2071 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01002072 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002073 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002074}
2075
2076component_build_crypto_full () {
2077 msg "build: make, crypto only, full config"
2078 scripts/config.py crypto_full
Gilles Peskine6bb39152020-02-03 11:59:20 +01002079 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002080 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002081}
2082
Gilles Peskinefc4f11b2022-10-21 19:34:54 +02002083component_test_crypto_for_psa_service () {
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002084 msg "build: make, config for PSA crypto service"
2085 scripts/config.py crypto
2086 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
2087 # Disable things that are not needed for just cryptography, to
2088 # reach a configuration that would be typical for a PSA cryptography
2089 # service providing all implemented PSA algorithms.
2090 # System stuff
2091 scripts/config.py unset MBEDTLS_ERROR_C
2092 scripts/config.py unset MBEDTLS_TIMING_C
Gilles Peskine78bffd12022-10-25 21:02:33 +02002093 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002094 # Crypto stuff with no PSA interface
2095 scripts/config.py unset MBEDTLS_BASE64_C
Gilles Peskine649e04e2022-10-25 21:05:57 +02002096 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
Gilles Peskineb06f0712022-10-25 21:06:11 +02002097 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
Gilles Peskine649e04e2022-10-25 21:05:57 +02002098 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002099 scripts/config.py unset MBEDTLS_NIST_KW_C
2100 scripts/config.py unset MBEDTLS_PEM_PARSE_C
2101 scripts/config.py unset MBEDTLS_PEM_WRITE_C
2102 scripts/config.py unset MBEDTLS_PKCS12_C
2103 scripts/config.py unset MBEDTLS_PKCS5_C
Gilles Peskinefcee7402022-10-11 21:15:24 +02002104 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
2105 # in PSA code to work with RSA keys. We don't require users to set those:
2106 # they will be reenabled in build_info.h.
Gilles Peskine1f108072022-10-25 21:02:56 +02002107 scripts/config.py unset MBEDTLS_PK_C
Gilles Peskinefcee7402022-10-11 21:15:24 +02002108 scripts/config.py unset MBEDTLS_PK_PARSE_C
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002109 scripts/config.py unset MBEDTLS_PK_WRITE_C
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002110 make CFLAGS='-O1 -Werror' all test
2111 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
2112}
2113
Gilles Peskineec541fe2020-01-31 14:24:14 +01002114component_build_crypto_baremetal () {
2115 msg "build: make, crypto only, baremetal config"
2116 scripts/config.py crypto_baremetal
David Horstmann61faf662021-11-30 11:40:54 +00002117 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002118 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002119}
Daniel Axtens446af202020-09-02 21:30:13 +10002120support_build_crypto_baremetal () {
Daniel Axtens814c8132020-08-31 14:22:58 +10002121 support_build_baremetal "$@"
2122}
2123
2124component_build_baremetal () {
2125 msg "build: make, baremetal config"
2126 scripts/config.py baremetal
David Horstmann61faf662021-11-30 11:40:54 +00002127 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Daniel Axtens814c8132020-08-31 14:22:58 +10002128}
2129support_build_baremetal () {
Daniel Axtens446af202020-09-02 21:30:13 +10002130 # Older Glibc versions include time.h from other headers such as stdlib.h,
2131 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
2132 # problem, Ubuntu 18.04 is ok.
2133 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
2134}
Gilles Peskineec541fe2020-01-31 14:24:14 +01002135
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002136# depends.py family of tests
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002137component_test_depends_py_cipher_id () {
2138 msg "test/build: depends.py cipher_id (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002139 tests/scripts/depends.py cipher_id --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002140}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00002141
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002142component_test_depends_py_cipher_chaining () {
2143 msg "test/build: depends.py cipher_chaining (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002144 tests/scripts/depends.py cipher_chaining --unset-use-psa
John Durkopc14be902020-08-20 06:16:41 -07002145}
2146
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002147component_test_depends_py_cipher_padding () {
2148 msg "test/build: depends.py cipher_padding (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002149 tests/scripts/depends.py cipher_padding --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002150}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00002151
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002152component_test_depends_py_curves () {
2153 msg "test/build: depends.py curves (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002154 tests/scripts/depends.py curves --unset-use-psa
John Durkop2ec2eaa2020-08-24 18:29:15 -07002155}
2156
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002157component_test_depends_py_hashes () {
2158 msg "test/build: depends.py hashes (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002159 tests/scripts/depends.py hashes --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002160}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002161
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002162component_test_depends_py_kex () {
2163 msg "test/build: depends.py kex (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002164 tests/scripts/depends.py kex --unset-use-psa
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002165}
2166
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002167component_test_depends_py_pkalgs () {
2168 msg "test/build: depends.py pkalgs (gcc)"
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002169 tests/scripts/depends.py pkalgs --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002170}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002171
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002172# PSA equivalents of the depends.py tests
2173component_test_depends_py_cipher_id_psa () {
2174 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2175 tests/scripts/depends.py cipher_id
2176}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002177
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002178component_test_depends_py_cipher_chaining_psa () {
2179 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2180 tests/scripts/depends.py cipher_chaining
2181}
2182
2183component_test_depends_py_cipher_padding_psa () {
2184 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2185 tests/scripts/depends.py cipher_padding
2186}
2187
2188component_test_depends_py_curves_psa () {
2189 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2190 tests/scripts/depends.py curves
2191}
2192
2193component_test_depends_py_hashes_psa () {
2194 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2195 tests/scripts/depends.py hashes
2196}
2197
2198component_test_depends_py_kex_psa () {
2199 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2200 tests/scripts/depends.py kex
2201}
2202
2203component_test_depends_py_pkalgs_psa () {
2204 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002205 tests/scripts/depends.py pkalgs
Gilles Peskine8f073122018-11-27 15:58:47 +01002206}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002207
Dave Rodgman1a034dc2023-01-20 13:18:05 +00002208component_build_no_pk_rsa_alt_support () {
2209 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
2210
2211 scripts/config.py full
2212 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
2213 scripts/config.py set MBEDTLS_RSA_C
2214 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
2215
2216 # Only compile - this is primarily to test for compile issues
2217 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
2218}
2219
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002220component_build_module_alt () {
2221 msg "build: MBEDTLS_XXX_ALT" # ~30s
2222 scripts/config.py full
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002223
2224 # Disable options that are incompatible with some ALT implementations:
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002225 # aesni.c and padlock.c reference mbedtls_aes_context fields directly.
2226 scripts/config.py unset MBEDTLS_AESNI_C
2227 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08002228 scripts/config.py unset MBEDTLS_AESCE_C
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002229 # MBEDTLS_ECP_RESTARTABLE is documented as incompatible.
2230 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002231 # You can only have one threading implementation: alt or pthread, not both.
2232 scripts/config.py unset MBEDTLS_THREADING_PTHREAD
Gilles Peskine5c3f18d2021-05-31 21:21:12 +02002233 # The SpecifiedECDomain parsing code accesses mbedtls_ecp_group fields
2234 # directly and assumes the implementation works with partial groups.
2235 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
Tom Cosgrovef3ebd902022-02-20 22:25:31 +00002236 # MBEDTLS_SHA256_*ALT can't be used with MBEDTLS_SHA256_USE_A64_CRYPTO_*
2237 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
2238 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00002239 # MBEDTLS_SHA512_*ALT can't be used with MBEDTLS_SHA512_USE_A64_CRYPTO_*
2240 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2241 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002242
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002243 # Enable all MBEDTLS_XXX_ALT for whole modules. Do not enable
2244 # MBEDTLS_XXX_YYY_ALT which are for single functions.
2245 scripts/config.py set-all 'MBEDTLS_([A-Z0-9]*|NIST_KW)_ALT'
Gilles Peskine1628a9c2021-05-31 22:09:58 +02002246 scripts/config.py unset MBEDTLS_DHM_ALT #incompatible with MBEDTLS_DEBUG_C
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002247
Gilles Peskine1628a9c2021-05-31 22:09:58 +02002248 # We can only compile, not link, since we don't have any implementations
2249 # suitable for testing with the dummy alt headers.
2250 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
2251}
2252
2253component_build_dhm_alt () {
2254 msg "build: MBEDTLS_DHM_ALT" # ~30s
2255 scripts/config.py full
2256 scripts/config.py set MBEDTLS_DHM_ALT
2257 # debug.c currently references mbedtls_dhm_context fields directly.
2258 scripts/config.py unset MBEDTLS_DEBUG_C
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002259 # We can only compile, not link, since we don't have any implementations
2260 # suitable for testing with the dummy alt headers.
2261 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
2262}
2263
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002264component_test_no_use_psa_crypto_full_cmake_asan() {
2265 # full minus MBEDTLS_USE_PSA_CRYPTO: run the same set of tests as basic-build-test.sh
Gilles Peskinedc3a1792019-09-03 11:42:04 +02002266 msg "build: cmake, full config minus MBEDTLS_USE_PSA_CRYPTO, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002267 scripts/config.py full
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002268 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
2269 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cron6f135e12021-12-08 16:57:54 +01002270 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002271 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02002272 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002273 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Raef Colesa7e03ad2022-09-28 09:32:48 +01002274 scripts/config.py unset MBEDTLS_LMS_C
Raef Coles47bccb72022-09-28 12:00:20 +01002275 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Manuel Pégourié-Gonnardd8167e82019-02-01 11:12:52 +01002276 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002277 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02002278
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002279 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002280 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02002281
Manuel Pégourié-Gonnard182a23b2022-12-07 10:38:43 +01002282 # Note: ssl-opt.sh has some test cases that depend on
2283 # MBEDTLS_ECP_RESTARTABLE && !MBEDTLS_USE_PSA_CRYPTO
2284 # This is the only component where those tests are not skipped.
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002285 msg "test: ssl-opt.sh (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002286 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002287
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002288 msg "test: compat.sh default (full minus MBEDTLS_USE_PSA_CRYPTO)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002289 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04002290
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02002291 msg "test: compat.sh NULL (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01002292 env OPENSSL="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -f 'NULL'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002293
Manuel Pégourié-Gonnard971dea32019-02-01 12:38:40 +01002294 msg "test: compat.sh ARIA + ChachaPoly (full minus MBEDTLS_USE_PSA_CRYPTO)"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01002295 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002296}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002297
Ronald Cron403c15c2021-09-13 09:38:05 +02002298component_test_psa_crypto_config_accel_ecdsa () {
Valerio Setti5aab43f2023-03-29 10:42:07 +02002299 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
Ronald Cron403c15c2021-09-13 09:38:05 +02002300
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002301 # Algorithms and key types to accelerate
Valerio Settic0d2f842023-06-28 10:48:08 +02002302 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
Valerio Setti0a342c92023-09-01 09:12:31 +02002303 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002304
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002305 # Note: Those are handled in a special way by the libtestdriver machinery,
2306 # so we only want to include them in the accel list when building the main
2307 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002308 loc_curve_list="$(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002309
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002310 # Configure
2311 # ---------
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002312
Manuel Pégourié-Gonnard8d645dc2023-06-15 09:07:10 +02002313 # Start from default config (no USE_PSA) + TLS 1.3
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002314 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard6d7db932022-12-28 09:48:01 +01002315 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002316
2317 # Disable the module that's accelerated
Ronald Cron403c15c2021-09-13 09:38:05 +02002318 scripts/config.py unset MBEDTLS_ECDSA_C
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002319
2320 # Disable things that depend on it
Ronald Cron403c15c2021-09-13 09:38:05 +02002321 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2322 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2323
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002324 # Build
2325 # -----
2326
2327 # These hashes are needed for some ECDSA signature tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02002328 loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2329 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002330
2331 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2332
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002333 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02002334
Manuel Pégourié-Gonnarde3095e72022-12-28 10:09:53 +01002335 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine827dbd92022-02-04 00:30:54 +01002336 not grep mbedtls_ecdsa_ library/ecdsa.o
Ronald Cron403c15c2021-09-13 09:38:05 +02002337
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002338 # Run the tests
2339 # -------------
2340
Ronald Cron403c15c2021-09-13 09:38:05 +02002341 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
2342 make test
2343}
2344
Valerio Setti44b178c2023-03-22 14:02:57 +01002345component_test_psa_crypto_config_accel_ecdh () {
Valerio Setti5aab43f2023-03-29 10:42:07 +02002346 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002347
2348 # Algorithms and key types to accelerate
Valerio Settic0d2f842023-06-28 10:48:08 +02002349 loc_accel_list="ALG_ECDH \
Valerio Setti0a342c92023-09-01 09:12:31 +02002350 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002351
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002352 # Note: Those are handled in a special way by the libtestdriver machinery,
2353 # so we only want to include them in the accel list when building the main
2354 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002355 loc_curve_list="$(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002356
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002357 # Configure
2358 # ---------
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002359
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002360 # Start from default config (no TLS 1.3, no USE_PSA)
2361 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002362
Valerio Setti44b178c2023-03-22 14:02:57 +01002363 # Disable the module that's accelerated
2364 scripts/config.py unset MBEDTLS_ECDH_C
2365
2366 # Disable things that depend on it
2367 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2368 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2369 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2370 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2371 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2372
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002373 # Build
2374 # -----
2375
2376 helper_libtestdriver1_make_drivers "$loc_accel_list"
2377
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002378 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002379
Valerio Setti44b178c2023-03-22 14:02:57 +01002380 # Make sure this was not re-enabled by accident (additive config)
2381 not grep mbedtls_ecdh_ library/ecdh.o
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002382
2383 # Run the tests
2384 # -------------
2385
Valerio Setti44b178c2023-03-22 14:02:57 +01002386 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002387 make test
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +01002388}
2389
Przemek Stekieldccb2022023-05-11 10:48:50 +02002390component_test_psa_crypto_config_accel_ffdh () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002391 msg "build: full with accelerated FFDH"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002392
2393 # Algorithms and key types to accelerate
Valerio Setti27602c32023-07-10 16:38:59 +02002394 loc_accel_list="ALG_FFDH \
Valerio Setti0a342c92023-09-01 09:12:31 +02002395 $(helper_get_psa_key_type_list "DH")"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002396
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002397 # Configure
2398 # ---------
Przemek Stekieldccb2022023-05-11 10:48:50 +02002399
Przemek Stekiel565353e2023-07-05 11:07:07 +02002400 # start with full (USE_PSA and TLS 1.3)
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002401 helper_libtestdriver1_adjust_config "full"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002402
2403 # Disable the module that's accelerated
2404 scripts/config.py unset MBEDTLS_DHM_C
2405
2406 # Disable things that depend on it
2407 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2408 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2409
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002410 # Build
2411 # -----
2412
2413 helper_libtestdriver1_make_drivers "$loc_accel_list"
2414
Manuel Pégourié-Gonnard981732e2023-06-08 09:15:59 +02002415 helper_libtestdriver1_make_main "$loc_accel_list"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002416
2417 # Make sure this was not re-enabled by accident (additive config)
2418 not grep mbedtls_dhm_ library/dhm.o
2419
2420 # Run the tests
2421 # -------------
2422
Gilles Peskine14302ed2023-07-19 19:30:04 +02002423 msg "test: full with accelerated FFDH"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002424 make test
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002425
Gilles Peskine14302ed2023-07-19 19:30:04 +02002426 msg "ssl-opt: full with accelerated FFDH alg"
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002427 tests/ssl-opt.sh -f "ffdh"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002428}
2429
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002430component_test_psa_crypto_config_reference_ffdh () {
Gilles Peskineb7d577e2023-08-09 19:48:58 +02002431 msg "build: full with non-accelerated FFDH"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002432
2433 # Start with full (USE_PSA and TLS 1.3)
Przemek Stekiel565353e2023-07-05 11:07:07 +02002434 helper_libtestdriver1_adjust_config "full"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002435
2436 # Disable things that are not supported
2437 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2438 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002439 make
2440
Gilles Peskine14302ed2023-07-19 19:30:04 +02002441 msg "test suites: full with non-accelerated FFDH alg"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002442 make test
2443
Gilles Peskine14302ed2023-07-19 19:30:04 +02002444 msg "ssl-opt: full with non-accelerated FFDH alg"
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002445 tests/ssl-opt.sh -f "ffdh"
Valerio Setti42d5f192023-03-20 13:54:41 +01002446}
2447
Valerio Setti44b178c2023-03-22 14:02:57 +01002448component_test_psa_crypto_config_accel_pake() {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002449 msg "build: full with accelerated PAKE"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002450
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002451 loc_accel_list="ALG_JPAKE \
2452 $(helper_get_psa_key_type_list "ECC")"
2453
2454 # Note: Those are handled in a special way by the libtestdriver machinery,
2455 # so we only want to include them in the accel list when building the main
2456 # libraries, hence the use of a separate variable.
2457 loc_curve_list="$(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002458
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002459 # Configure
2460 # ---------
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002461
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002462 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002463
2464 # Make built-in fallback not available
2465 scripts/config.py unset MBEDTLS_ECJPAKE_C
2466 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
2467
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002468 # Build
2469 # -----
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002470
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002471 helper_libtestdriver1_make_drivers "$loc_accel_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002472
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002473 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002474
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002475 # Make sure this was not re-enabled by accident (additive config)
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002476 not grep mbedtls_ecjpake_init library/ecjpake.o
2477
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002478 # Run the tests
2479 # -------------
2480
Gilles Peskine14302ed2023-07-19 19:30:04 +02002481 msg "test: full with accelerated PAKE"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002482 make test
2483}
2484
Manuel Pégourié-Gonnard5c210362023-09-26 12:03:10 +02002485component_test_psa_crypto_config_accel_ecc_some_key_types () {
2486 msg "build: full with accelerated EC algs and some key types"
2487
2488 # Algorithms and key types to accelerate
2489 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
2490 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2491 ALG_ECDH \
2492 ALG_JPAKE \
2493 KEY_TYPE_ECC_PUBLIC_KEY \
2494 KEY_TYPE_ECC_KEY_PAIR_BASIC \
2495 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
2496 KEY_TYPE_ECC_KEY_PAIR_EXPORT"
2497
2498 # Note: Curves are handled in a special way by the libtestdriver machinery,
2499 # so we only want to include them in the accel list when building the main
2500 # libraries, hence the use of a separate variable.
2501 loc_curve_list="$(helper_get_psa_curve_list)"
2502
2503 # Configure
2504 # ---------
2505
2506 # start with config full for maximum coverage (also enables USE_PSA)
2507 helper_libtestdriver1_adjust_config "full"
2508
2509 # Disable modules that are accelerated - some will be re-enabled
2510 scripts/config.py unset MBEDTLS_ECDSA_C
2511 scripts/config.py unset MBEDTLS_ECDH_C
2512 scripts/config.py unset MBEDTLS_ECJPAKE_C
2513 scripts/config.py unset MBEDTLS_ECP_C
2514
2515 # Disable all curves - those that aren't accelerated should be re-enabled
2516 helper_disable_builtin_curves
2517
2518 # Restartable feature is not yet supported by PSA. Once it will in
2519 # the future, the following line could be removed (see issues
2520 # 6061, 6332 and following ones)
2521 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2522
2523 # this is not supported by the driver API yet
2524 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2525
2526 # Build
2527 # -----
2528
2529 # These hashes are needed for some ECDSA signature tests.
2530 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2531 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2532 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2533
2534 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
2535
2536 # ECP should be re-enabled but not the others
2537 not grep mbedtls_ecdh_ library/ecdh.o
2538 not grep mbedtls_ecdsa library/ecdsa.o
2539 not grep mbedtls_ecjpake library/ecjpake.o
2540 grep mbedtls_ecp library/ecp.o
2541
2542 # Run the tests
2543 # -------------
2544
2545 msg "test suites: full with accelerated EC algs and some key types"
2546 make test
2547}
2548
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002549# Run tests with only (non-)Weierstrass accelerated
2550# Common code used in:
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002551# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
2552# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002553common_test_psa_crypto_config_accel_ecc_some_curves () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002554 weierstrass=$1
2555 if [ $weierstrass -eq 1 ]; then
2556 desc="Weierstrass"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002557 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002558 desc="non-Weierstrass"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002559 fi
2560
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002561 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002562
2563 # Algorithms and key types to accelerate
2564 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2565 ALG_ECDH \
2566 ALG_JPAKE \
2567 $(helper_get_psa_key_type_list "ECC")"
2568
2569 # Note: Curves are handled in a special way by the libtestdriver machinery,
2570 # so we only want to include them in the accel list when building the main
2571 # libraries, hence the use of a separate variable.
2572 # Note: the following loop is a modified version of
2573 # helper_get_psa_curve_list that only keeps Weierstrass families.
2574 loc_weierstrass_list=""
2575 loc_non_weierstrass_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002576 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
2577 case $item in
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002578 ECC_BRAINPOOL*|ECC_SECP*)
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002579 loc_weierstrass_list="$loc_weierstrass_list $item"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002580 ;;
2581 *)
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002582 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002583 ;;
2584 esac
2585 done
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002586 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002587 loc_curve_list=$loc_weierstrass_list
2588 else
2589 loc_curve_list=$loc_non_weierstrass_list
2590 fi
2591
2592 # Configure
2593 # ---------
2594
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002595 # Start with config crypto_full and remove PK_C:
2596 # that's what's supported now, see docs/driver-only-builds.md.
2597 helper_libtestdriver1_adjust_config "crypto_full"
2598 scripts/config.py unset MBEDTLS_PK_C
2599 scripts/config.py unset MBEDTLS_PK_PARSE_C
2600 scripts/config.py unset MBEDTLS_PK_WRITE_C
2601 # We need to disable RSA too or PK will be re-enabled.
2602 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
2603 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
2604 scripts/config.py unset MBEDTLS_RSA_C
2605 scripts/config.py unset MBEDTLS_PKCS1_V15
2606 scripts/config.py unset MBEDTLS_PKCS1_V21
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002607
2608 # Disable modules that are accelerated - some will be re-enabled
2609 scripts/config.py unset MBEDTLS_ECDSA_C
2610 scripts/config.py unset MBEDTLS_ECDH_C
2611 scripts/config.py unset MBEDTLS_ECJPAKE_C
2612 scripts/config.py unset MBEDTLS_ECP_C
2613
2614 # Disable all curves - those that aren't accelerated should be re-enabled
2615 helper_disable_builtin_curves
2616
2617 # Restartable feature is not yet supported by PSA. Once it will in
2618 # the future, the following line could be removed (see issues
2619 # 6061, 6332 and following ones)
2620 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2621
2622 # this is not supported by the driver API yet
2623 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2624
2625 # Build
2626 # -----
2627
2628 # These hashes are needed for some ECDSA signature tests.
2629 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2630 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2631 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2632
2633 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
2634
2635 # We expect ECDH to be re-enabled for the missing curves
2636 grep mbedtls_ecdh_ library/ecdh.o
2637 # We expect ECP to be re-enabled, however the parts specific to the
2638 # families of curves that are accelerated should be ommited.
2639 # - functions with mxz in the name are specific to Montgomery curves
2640 # - ecp_muladd is specific to Weierstrass curves
2641 ##nm library/ecp.o | tee ecp.syms
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002642 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002643 not grep mbedtls_ecp_muladd library/ecp.o
2644 grep mxz library/ecp.o
2645 else
2646 grep mbedtls_ecp_muladd library/ecp.o
2647 not grep mxz library/ecp.o
2648 fi
2649 # We expect ECDSA and ECJPAKE to be re-enabled only when
2650 # Weierstrass curves are not accelerated
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002651 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002652 not grep mbedtls_ecdsa library/ecdsa.o
2653 not grep mbedtls_ecjpake library/ecjpake.o
2654 else
2655 grep mbedtls_ecdsa library/ecdsa.o
2656 grep mbedtls_ecjpake library/ecjpake.o
2657 fi
2658
2659 # Run the tests
2660 # -------------
2661
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002662 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
2663 make test
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002664}
2665
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002666component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002667 common_test_psa_crypto_config_accel_ecc_some_curves 1
2668}
2669
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002670component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002671 common_test_psa_crypto_config_accel_ecc_some_curves 0
2672}
2673
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002674# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
2675# ECDH, ECDSA) with and without drivers.
2676# The input parameter is a boolean value which indicates:
2677# - 0 keep built-in EC algs,
2678# - 1 exclude built-in EC algs (driver only).
2679#
2680# This is used by the two following components to ensure they always use the
2681# same config, except for the use of driver or built-in EC algorithms:
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002682# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
2683# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002684# This supports comparing their test coverage with analyze_outcomes.py.
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02002685config_psa_crypto_config_ecp_light_only () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002686 driver_only="$1"
Valerio Setti42d5f192023-03-20 13:54:41 +01002687 # start with config full for maximum coverage (also enables USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002688 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002689 if [ "$driver_only" -eq 1 ]; then
Valerio Setti42d5f192023-03-20 13:54:41 +01002690 # Disable modules that are accelerated
2691 scripts/config.py unset MBEDTLS_ECDSA_C
2692 scripts/config.py unset MBEDTLS_ECDH_C
2693 scripts/config.py unset MBEDTLS_ECJPAKE_C
Valerio Setti29b395c2023-04-05 18:20:30 +02002694 scripts/config.py unset MBEDTLS_ECP_C
Valerio Setti42d5f192023-03-20 13:54:41 +01002695 fi
2696
2697 # Restartable feature is not yet supported by PSA. Once it will in
2698 # the future, the following line could be removed (see issues
2699 # 6061, 6332 and following ones)
2700 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Setti42d5f192023-03-20 13:54:41 +01002701}
2702
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002703# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
2704component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002705 msg "build: full with accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002706
2707 # Algorithms and key types to accelerate
2708 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2709 ALG_ECDH \
2710 ALG_JPAKE \
Valerio Setti0a342c92023-09-01 09:12:31 +02002711 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002712
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002713 # Note: Those are handled in a special way by the libtestdriver machinery,
2714 # so we only want to include them in the accel list when building the main
2715 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002716 loc_curve_list="$(helper_get_psa_curve_list)"
Valerio Setti42d5f192023-03-20 13:54:41 +01002717
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002718 # Configure
2719 # ---------
Valerio Setti42d5f192023-03-20 13:54:41 +01002720
2721 # Use the same config as reference, only without built-in EC algs
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02002722 config_psa_crypto_config_ecp_light_only 1
Valerio Setti42d5f192023-03-20 13:54:41 +01002723
Valerio Setti0a342c92023-09-01 09:12:31 +02002724 # Do not disable builtin curves because that support is required for:
Valerio Settib2fd6732023-08-15 17:10:47 +02002725 # - MBEDTLS_PK_PARSE_EC_EXTENDED
2726 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
2727
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002728 # Build
2729 # -----
2730
2731 # These hashes are needed for some ECDSA signature tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02002732 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2733 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002734 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2735
Valerio Settib2fd6732023-08-15 17:10:47 +02002736 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Valerio Setti42d5f192023-03-20 13:54:41 +01002737
2738 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
2739 not grep mbedtls_ecdsa_ library/ecdsa.o
2740 not grep mbedtls_ecdh_ library/ecdh.o
2741 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Setti29b395c2023-04-05 18:20:30 +02002742 not grep mbedtls_ecp_mul library/ecp.o
Valerio Setti42d5f192023-03-20 13:54:41 +01002743
2744 # Run the tests
2745 # -------------
2746
Gilles Peskine14302ed2023-07-19 19:30:04 +02002747 msg "test suites: full with accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002748 make test
2749
Gilles Peskine14302ed2023-07-19 19:30:04 +02002750 msg "ssl-opt: full with accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002751 tests/ssl-opt.sh
2752}
2753
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002754# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
2755component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002756 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002757
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02002758 config_psa_crypto_config_ecp_light_only 0
Valerio Setti42d5f192023-03-20 13:54:41 +01002759
2760 make
2761
Gilles Peskine14302ed2023-07-19 19:30:04 +02002762 msg "test suites: full with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002763 make test
2764
Gilles Peskine14302ed2023-07-19 19:30:04 +02002765 msg "ssl-opt: full with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01002766 tests/ssl-opt.sh
2767}
2768
Valerio Settie618cb02023-04-12 14:59:16 +02002769# This helper function is used by:
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002770# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
2771# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Valerio Settie618cb02023-04-12 14:59:16 +02002772# to ensure that both tests use the same underlying configuration when testing
2773# driver's coverage with analyze_outcomes.py.
2774#
2775# This functions accepts 1 boolean parameter as follows:
2776# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
2777# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
2778# - 0: include built-in implementation of EC algorithms.
2779#
2780# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
2781# on the ECP module.
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002782config_psa_crypto_no_ecp_at_all () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002783 driver_only="$1"
Valerio Settiaafe9002023-06-26 15:23:44 +02002784 # start with full config for maximum coverage (also enables USE_PSA)
2785 helper_libtestdriver1_adjust_config "full"
2786
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002787 if [ "$driver_only" -eq 1 ]; then
Valerio Settie618cb02023-04-12 14:59:16 +02002788 # Disable modules that are accelerated
2789 scripts/config.py unset MBEDTLS_ECDSA_C
2790 scripts/config.py unset MBEDTLS_ECDH_C
2791 scripts/config.py unset MBEDTLS_ECJPAKE_C
2792 # Disable ECP module (entirely)
2793 scripts/config.py unset MBEDTLS_ECP_C
Valerio Settie618cb02023-04-12 14:59:16 +02002794 fi
2795
Valerio Settiaecd32c2023-06-14 10:42:31 +02002796 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
2797 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
Valerio Settiaddeee42023-06-14 10:46:55 +02002798 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
Ronald Cron6b49b552023-07-20 09:57:54 +02002799 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Valerio Settiaecd32c2023-06-14 10:42:31 +02002800
Valerio Settie618cb02023-04-12 14:59:16 +02002801 # Restartable feature is not yet supported by PSA. Once it will in
2802 # the future, the following line could be removed (see issues
2803 # 6061, 6332 and following ones)
2804 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Settie618cb02023-04-12 14:59:16 +02002805}
2806
2807# Build and test a configuration where driver accelerates all EC algs while
2808# all support and dependencies from ECP and ECP_LIGHT are removed on the library
2809# side.
2810#
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002811# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
2812component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002813 msg "build: full + accelerated EC algs - ECP"
Valerio Settie618cb02023-04-12 14:59:16 +02002814
2815 # Algorithms and key types to accelerate
2816 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2817 ALG_ECDH \
2818 ALG_JPAKE \
Valerio Setti0a342c92023-09-01 09:12:31 +02002819 $(helper_get_psa_key_type_list "ECC")"
Valerio Settib2fd6732023-08-15 17:10:47 +02002820
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002821 # Note: Those are handled in a special way by the libtestdriver machinery,
2822 # so we only want to include them in the accel list when building the main
2823 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02002824 loc_curve_list="$(helper_get_psa_curve_list)"
Valerio Settie618cb02023-04-12 14:59:16 +02002825
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002826 # Configure
2827 # ---------
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002828
Valerio Settie618cb02023-04-12 14:59:16 +02002829 # Set common configurations between library's and driver's builds
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002830 config_psa_crypto_no_ecp_at_all 1
Valerio Settib2fd6732023-08-15 17:10:47 +02002831 # Disable all the builtin curves. All the required algs are accelerated.
2832 helper_disable_builtin_curves
Valerio Settie618cb02023-04-12 14:59:16 +02002833
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002834 # Build
2835 # -----
Valerio Settie618cb02023-04-12 14:59:16 +02002836
2837 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02002838 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
2839 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2840 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Valerio Settie618cb02023-04-12 14:59:16 +02002841
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +02002842 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
Valerio Settie618cb02023-04-12 14:59:16 +02002843
Valerio Settib2fd6732023-08-15 17:10:47 +02002844 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Valerio Settie618cb02023-04-12 14:59:16 +02002845
2846 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
2847 not grep mbedtls_ecdsa_ library/ecdsa.o
2848 not grep mbedtls_ecdh_ library/ecdh.o
2849 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Settib2fd6732023-08-15 17:10:47 +02002850 # Also ensure that ECP module was not re-enabled
Valerio Settie618cb02023-04-12 14:59:16 +02002851 not grep mbedtls_ecp_ library/ecp.o
Valerio Settie618cb02023-04-12 14:59:16 +02002852
2853 # Run the tests
2854 # -------------
2855
Gilles Peskine14302ed2023-07-19 19:30:04 +02002856 msg "test: full + accelerated EC algs - ECP"
Valerio Settie618cb02023-04-12 14:59:16 +02002857 make test
Valerio Setti16b70f22023-06-27 17:45:49 +02002858
Gilles Peskine14302ed2023-07-19 19:30:04 +02002859 msg "ssl-opt: full + accelerated EC algs - ECP"
Valerio Setti16b70f22023-06-27 17:45:49 +02002860 tests/ssl-opt.sh
Valerio Settie618cb02023-04-12 14:59:16 +02002861}
2862
2863# Reference function used for driver's coverage analysis in analyze_outcomes.py
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002864# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
Valerio Settie618cb02023-04-12 14:59:16 +02002865# Keep in sync with its accelerated counterpart.
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002866component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002867 msg "build: full + non accelerated EC algs"
Valerio Settie618cb02023-04-12 14:59:16 +02002868
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002869 config_psa_crypto_no_ecp_at_all 0
Valerio Settie618cb02023-04-12 14:59:16 +02002870
2871 make
2872
Gilles Peskine14302ed2023-07-19 19:30:04 +02002873 msg "test: full + non accelerated EC algs"
Valerio Settie618cb02023-04-12 14:59:16 +02002874 make test
Valerio Setti16b70f22023-06-27 17:45:49 +02002875
Gilles Peskine14302ed2023-07-19 19:30:04 +02002876 msg "ssl-opt: full + non accelerated EC algs"
Valerio Setti16b70f22023-06-27 17:45:49 +02002877 tests/ssl-opt.sh
Valerio Settie618cb02023-04-12 14:59:16 +02002878}
2879
Valerio Setti4e2f2442023-08-15 10:10:26 +02002880# This is a common configuration helper used directly from:
2881# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
2882# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
2883# and indirectly from:
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002884# - component_test_psa_crypto_config_accel_ecc_no_bignum
Valerio Setti4e2f2442023-08-15 10:10:26 +02002885# - accelerate all EC algs, disable RSA and FFDH
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002886# - component_test_psa_crypto_config_reference_ecc_no_bignum
Valerio Setti4e2f2442023-08-15 10:10:26 +02002887# - this is the reference component of the above
2888# - it still disables RSA and FFDH, but it uses builtin EC algs
2889# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
2890# - accelerate all EC and FFDH algs, disable only RSA
2891# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
2892# - this is the reference component of the above
2893# - it still disables RSA, but it uses builtin EC and FFDH algs
2894#
2895# This function accepts 2 parameters:
Valerio Setti5dfaca42023-09-05 08:48:51 +02002896# $1: a boolean value which states if we are testing an accelerated scenario
2897# or not.
2898# $2: a string value which states which components are tested. Allowed values
2899# are "ECC" or "ECC_DH".
Valerio Setti4e2f2442023-08-15 10:10:26 +02002900config_psa_crypto_config_accel_ecc_ffdh_no_bignum() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002901 driver_only="$1"
2902 test_target="$2"
Valerio Setti18535c32023-07-31 11:27:17 +02002903 # start with full config for maximum coverage (also enables USE_PSA)
Valerio Setti29c1b4d2023-07-27 10:08:45 +02002904 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002905
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002906 if [ "$driver_only" -eq 1 ]; then
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002907 # Disable modules that are accelerated
2908 scripts/config.py unset MBEDTLS_ECDSA_C
2909 scripts/config.py unset MBEDTLS_ECDH_C
2910 scripts/config.py unset MBEDTLS_ECJPAKE_C
2911 # Disable ECP module (entirely)
2912 scripts/config.py unset MBEDTLS_ECP_C
Manuel Pégourié-Gonnard660bbf22023-06-12 18:42:40 +02002913 # Also disable bignum
2914 scripts/config.py unset MBEDTLS_BIGNUM_C
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002915 fi
2916
2917 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
2918 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
2919 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
2920 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2921
Manuel Pégourié-Gonnard7dccb662023-06-12 18:28:42 +02002922 # RSA support is intentionally disabled on this test because RSA_C depends
2923 # on BIGNUM_C.
Valerio Setti2e0275d2023-07-28 16:33:13 +02002924 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
2925 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 +02002926 scripts/config.py unset MBEDTLS_RSA_C
2927 scripts/config.py unset MBEDTLS_PKCS1_V15
2928 scripts/config.py unset MBEDTLS_PKCS1_V21
2929 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
2930 # Also disable key exchanges that depend on RSA
2931 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
2932 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
2933 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2934 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2935 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2936
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002937 if [ "$test_target" = "ECC" ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02002938 # When testing ECC only, we disable FFDH support, both from builtin and
2939 # PSA sides, and also disable the key exchanges that depend on DHM.
2940 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_FFDH
2941 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
2942 scripts/config.py unset MBEDTLS_DHM_C
2943 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2944 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2945 else
2946 # When testing ECC and DH instead, we disable DHM and depending key
2947 # exchanges only in the accelerated build
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002948 if [ "$driver_only" -eq 1 ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02002949 scripts/config.py unset MBEDTLS_DHM_C
2950 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2951 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2952 fi
2953 fi
Manuel Pégourié-Gonnard7dccb662023-06-12 18:28:42 +02002954
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002955 # Restartable feature is not yet supported by PSA. Once it will in
2956 # the future, the following line could be removed (see issues
2957 # 6061, 6332 and following ones)
2958 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2959}
2960
Valerio Setti4e2f2442023-08-15 10:10:26 +02002961# Common helper used by:
2962# - component_test_psa_crypto_config_accel_ecc_no_bignum
2963# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002964#
Valerio Setti4e2f2442023-08-15 10:10:26 +02002965# The goal is to build and test accelerating either:
2966# - ECC only or
2967# - both ECC and FFDH
2968#
2969# It is meant to be used in conjunction with
Valerio Setti5dfaca42023-09-05 08:48:51 +02002970# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
2971# coverage analysis in the "analyze_outcomes.py" script.
Valerio Setti4e2f2442023-08-15 10:10:26 +02002972common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002973 test_target="$1"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002974
Valerio Setti5dfaca42023-09-05 08:48:51 +02002975 # This is an internal helper to simplify text message handling
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002976 if [ "$test_target" = "ECC_DH" ]; then
2977 accel_text="ECC/FFDH"
2978 removed_text="ECP - DH"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002979 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002980 accel_text="ECC"
2981 removed_text="ECP"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002982 fi
2983
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002984 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002985
2986 # By default we accelerate all EC keys/algs
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002987 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2988 ALG_ECDH \
2989 ALG_JPAKE \
Valerio Setti0a342c92023-09-01 09:12:31 +02002990 $(helper_get_psa_key_type_list "ECC")"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002991 # Optionally we can also add DH to the list of accelerated items
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002992 if [ "$test_target" = "ECC_DH" ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02002993 loc_accel_list="$loc_accel_list \
2994 ALG_FFDH \
Manuel Pégourié-Gonnard85ff5e62023-09-22 09:05:48 +02002995 $(helper_get_psa_key_type_list "DH")"
Valerio Setti4e2f2442023-08-15 10:10:26 +02002996 fi
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02002997
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002998 # Note: Those are handled in a special way by the libtestdriver machinery,
2999 # so we only want to include them in the accel list when building the main
3000 # libraries, hence the use of a separate variable.
Valerio Settib2fd6732023-08-15 17:10:47 +02003001 loc_curve_list="$(helper_get_psa_curve_list)"
3002
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003003 # Configure
3004 # ---------
3005
3006 # Set common configurations between library's and driver's builds
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003007 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
Valerio Settib2fd6732023-08-15 17:10:47 +02003008 # Disable all the builtin curves. All the required algs are accelerated.
3009 helper_disable_builtin_curves
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003010
3011 # Build
3012 # -----
3013
3014 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02003015 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
3016 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3017 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003018
3019 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
3020
Valerio Settib2fd6732023-08-15 17:10:47 +02003021 helper_libtestdriver1_make_main "$loc_accel_list $loc_curve_list"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003022
3023 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
3024 not grep mbedtls_ecdsa_ library/ecdsa.o
3025 not grep mbedtls_ecdh_ library/ecdh.o
3026 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Setti4e2f2442023-08-15 10:10:26 +02003027 # Also ensure that ECP, RSA, [DHM] or BIGNUM modules were not re-enabled
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003028 not grep mbedtls_ecp_ library/ecp.o
Manuel Pégourié-Gonnard06aebe42023-06-12 18:33:34 +02003029 not grep mbedtls_rsa_ library/rsa.o
Manuel Pégourié-Gonnard660bbf22023-06-12 18:42:40 +02003030 not grep mbedtls_mpi_ library/bignum.o
Valerio Setti4e2f2442023-08-15 10:10:26 +02003031 not grep mbedtls_dhm_ library/dhm.o
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003032
3033 # Run the tests
3034 # -------------
3035
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003036 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - DHM - BIGNUM"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003037
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003038 make test
3039
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003040 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Valerio Setti18535c32023-07-31 11:27:17 +02003041 tests/ssl-opt.sh
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003042}
3043
Valerio Setti4e2f2442023-08-15 10:10:26 +02003044# Common helper used by:
3045# - component_test_psa_crypto_config_reference_ecc_no_bignum
3046# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
3047#
3048# The goal is to build and test a reference scenario (i.e. with builtin
3049# components) compared to the ones used in
3050# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
3051#
3052# It is meant to be used in conjunction with
3053# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
3054# coverage analysis in "analyze_outcomes.py" script.
3055common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003056 test_target="$1"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003057
Valerio Setti5dfaca42023-09-05 08:48:51 +02003058 # This is an internal helper to simplify text message handling
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003059 if [ "$test_target" = "ECC_DH" ]; then
3060 accel_text="ECC/FFDH"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003061 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003062 accel_text="ECC"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003063 fi
3064
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003065 msg "build: full + non accelerated $accel_text algs + USE_PSA"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003066
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003067 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003068
3069 make
3070
Valerio Setti29c1b4d2023-07-27 10:08:45 +02003071 msg "test suites: full + non accelerated EC algs + USE_PSA"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003072 make test
3073
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003074 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
Valerio Setti18535c32023-07-31 11:27:17 +02003075 tests/ssl-opt.sh
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003076}
3077
Valerio Setti4e2f2442023-08-15 10:10:26 +02003078component_test_psa_crypto_config_accel_ecc_no_bignum () {
3079 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
3080}
3081
3082component_test_psa_crypto_config_reference_ecc_no_bignum () {
3083 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
3084}
3085
3086component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
3087 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
3088}
3089
3090component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
3091 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
3092}
3093
Valerio Settiac6d35f2023-08-04 12:49:11 +02003094# Helper for setting common configurations between:
3095# - component_test_tfm_config_p256m_driver_accel_ec()
3096# - component_test_tfm_config()
Valerio Setti52ba0e32023-08-04 12:43:03 +02003097common_tfm_config () {
3098 # Enable TF-M config
Valerio Settic5c4bd22023-08-03 14:28:20 +02003099 cp configs/tfm_mbedcrypto_config_profile_medium.h "$CONFIG_H"
3100 cp configs/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
3101
Valerio Setti52ba0e32023-08-04 12:43:03 +02003102 # Adjust for the fact that we're building outside the TF-M environment.
3103 #
3104 # TF-M has separation, our build doesn't
3105 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SPM
3106 scripts/config.py unset MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
3107 # TF-M provdes its own (dummy) implemenation, from their tree
3108 scripts/config.py unset MBEDTLS_AES_DECRYPT_ALT
3109 scripts/config.py unset MBEDTLS_AES_SETKEY_DEC_ALT
3110 # We have an OS that provides entropy, use it
3111 scripts/config.py unset MBEDTLS_NO_PLATFORM_ENTROPY
3112
3113 # Other config adjustments to make the tests pass.
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003114 # Those should probably be adopted upstream.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003115 #
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003116 # - USE_PSA_CRYPTO for PK_HAVE_ECC_KEYS
3117 echo "#define MBEDTLS_USE_PSA_CRYPTO" >> "$CONFIG_H"
Valerio Setti52ba0e32023-08-04 12:43:03 +02003118 # pkparse.c and pkwrite.c fail to link without this
3119 echo "#define MBEDTLS_OID_C" >> "$CONFIG_H"
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003120 # - ASN1_[PARSE/WRITE]_C found by check_config.h for pkparse/pkwrite
3121 echo "#define MBEDTLS_ASN1_PARSE_C" >> "$CONFIG_H"
3122 echo "#define MBEDTLS_ASN1_WRITE_C" >> "$CONFIG_H"
3123 # - MD_C for HKDF_C
3124 echo "#define MBEDTLS_MD_C" >> "$CONFIG_H"
Valerio Setti52ba0e32023-08-04 12:43:03 +02003125
Manuel Pégourié-Gonnardf7298cd2023-09-18 09:55:24 +02003126 # Config adjustments for better test coverage in our environment.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003127 # These are not needed just to build and pass tests.
3128 #
3129 # Enable filesystem I/O for the benefit of PK parse/write tests.
3130 echo "#define MBEDTLS_FS_IO" >> "$CONFIG_H"
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003131 # Disable this for maximal ASan efficiency
3132 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
3133
Manuel Pégourié-Gonnardf7298cd2023-09-18 09:55:24 +02003134 # Config adjustments for features that are not supported
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003135 # when using only drivers / by p256-m
3136 #
3137 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
3138 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
3139 # Disable deterministic ECDSA as p256-m only does randomized
3140 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
3141
Valerio Setti52ba0e32023-08-04 12:43:03 +02003142}
3143
Valerio Settiac6d35f2023-08-04 12:49:11 +02003144# Keep this in sync with component_test_tfm_config() as they are both meant
3145# to be used in analyze_outcomes.py for driver's coverage analysis.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003146component_test_tfm_config_p256m_driver_accel_ec () {
3147 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
3148
3149 common_tfm_config
Valerio Settic5c4bd22023-08-03 14:28:20 +02003150
Valerio Settic5c4bd22023-08-03 14:28:20 +02003151 # Build crypto library specifying we want to use P256M code for EC operations
Manuel Pégourié-Gonnardeda70862023-09-22 12:17:50 +02003152 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 +02003153
Valerio Settic5c4bd22023-08-03 14:28:20 +02003154 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003155 not grep mbedtls_ecdsa_ library/ecdsa.o
Valerio Settic5c4bd22023-08-03 14:28:20 +02003156 not grep mbedtls_ecdh_ library/ecdh.o
3157 not grep mbedtls_ecjpake_ library/ecjpake.o
3158 # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003159 not grep mbedtls_ecp_ library/ecp.o
Valerio Settic5c4bd22023-08-03 14:28:20 +02003160 not grep mbedtls_rsa_ library/rsa.o
3161 not grep mbedtls_dhm_ library/dhm.o
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003162 not grep mbedtls_mpi_ library/bignum.o
Valerio Settic5c4bd22023-08-03 14:28:20 +02003163
3164 # Run the tests
Valerio Setti52ba0e32023-08-04 12:43:03 +02003165 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
Valerio Settic5c4bd22023-08-03 14:28:20 +02003166 make test
Valerio Setti52ba0e32023-08-04 12:43:03 +02003167}
Valerio Settic5c4bd22023-08-03 14:28:20 +02003168
Valerio Settiac6d35f2023-08-04 12:49:11 +02003169# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
3170# they are both meant to be used in analyze_outcomes.py for driver's coverage
3171# analysis.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003172component_test_tfm_config() {
3173 common_tfm_config
3174
3175 msg "build: TF-M config"
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02003176 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' tests
Valerio Setti52ba0e32023-08-04 12:43:03 +02003177
3178 msg "test: TF-M config"
3179 make test
Valerio Settic5c4bd22023-08-03 14:28:20 +02003180}
3181
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003182# Common helper for component_full_without_ecdhe_ecdsa() and
3183# component_full_without_ecdhe_ecdsa_and_tls13() which:
3184# - starts from the "full" configuration minus the list of symbols passed in
3185# as 1st parameter
3186# - build
3187# - test only TLS (i.e. test_suite_tls and ssl-opt)
3188build_full_minus_something_and_test_tls () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003189 symbols_to_disable="$1"
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003190
3191 msg "build: full minus something, test TLS"
3192
3193 scripts/config.py full
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003194 for sym in $symbols_to_disable; do
3195 echo "Disabling $sym"
3196 scripts/config.py unset $sym
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003197 done
3198
3199 make
3200
3201 msg "test: full minus something, test TLS"
3202 ( cd tests; ./test_suite_ssl )
3203
3204 msg "ssl-opt: full minus something, test TLS"
3205 tests/ssl-opt.sh
3206}
3207
3208component_full_without_ecdhe_ecdsa () {
3209 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED"
3210}
3211
3212component_full_without_ecdhe_ecdsa_and_tls13 () {
3213 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
3214 MBEDTLS_SSL_PROTO_TLS1_3"
3215}
3216
Valerio Setti249b18a2023-06-20 12:08:30 +02003217# This is an helper used by:
3218# - component_test_psa_ecc_key_pair_no_derive
3219# - component_test_psa_ecc_key_pair_no_generate
3220# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
3221# enabled, but one. Input arguments are as follows:
3222# - $1 is the key type under test, i.e. ECC/RSA/DH
3223# - $2 is the key option to be unset (i.e. generate, derive, etc)
Valerio Settia9836552023-06-22 11:22:23 +02003224build_and_test_psa_want_key_pair_partial() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003225 key_type=$1
3226 unset_option=$2
3227 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003228
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003229 msg "build: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003230 scripts/config.py full
Valerio Setti249b18a2023-06-20 12:08:30 +02003231 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3232 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3233
3234 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
3235 # crypto_config.h so we just disable the one we don't want.
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003236 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
Valerio Setti249b18a2023-06-20 12:08:30 +02003237
Valerio Settif6587be2023-06-22 11:33:14 +02003238 make CC=gcc CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Valerio Setti249b18a2023-06-20 12:08:30 +02003239
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003240 msg "test: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003241 make test
3242}
3243
3244component_test_psa_ecc_key_pair_no_derive() {
Valerio Settia9836552023-06-22 11:22:23 +02003245 build_and_test_psa_want_key_pair_partial "ECC" "DERIVE"
Valerio Setti249b18a2023-06-20 12:08:30 +02003246}
3247
3248component_test_psa_ecc_key_pair_no_generate() {
Valerio Settia9836552023-06-22 11:22:23 +02003249 build_and_test_psa_want_key_pair_partial "ECC" "GENERATE"
Valerio Setti249b18a2023-06-20 12:08:30 +02003250}
3251
Ronald Cron403c15c2021-09-13 09:38:05 +02003252component_test_psa_crypto_config_accel_rsa_signature () {
3253 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
3254
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003255 loc_accel_list="ALG_RSA_PKCS1V15_SIGN ALG_RSA_PSS KEY_TYPE_RSA_KEY_PAIR KEY_TYPE_RSA_PUBLIC_KEY"
3256
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003257 # Configure
3258 # ---------
Ronald Cron403c15c2021-09-13 09:38:05 +02003259
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003260 # Start from default config (no TLS 1.3, no USE_PSA)
3261 helper_libtestdriver1_adjust_config "default"
Ronald Cron403c15c2021-09-13 09:38:05 +02003262
3263 # It seems it is not possible to remove only the support for RSA signature
3264 # in the library. Thus we have to remove all RSA support (signature and
3265 # encryption/decryption). AS there is no driver support for asymmetric
3266 # encryption/decryption so far remove RSA encryption/decryption from the
3267 # application algorithm list.
Ronald Cron6b49b552023-07-20 09:57:54 +02003268 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3269 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
Ronald Cron403c15c2021-09-13 09:38:05 +02003270
Manuel Pégourié-Gonnardaed1d782023-06-12 17:22:24 +02003271 # Remove RSA support and its dependencies
3272 scripts/config.py unset MBEDTLS_RSA_C
3273 scripts/config.py unset MBEDTLS_PKCS1_V15
3274 scripts/config.py unset MBEDTLS_PKCS1_V21
3275 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
3276 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3277 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3278 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3279 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
3280 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
3281
Ronald Cron403c15c2021-09-13 09:38:05 +02003282 # Make sure both the library and the test library support the SHA hash
3283 # algorithms and only those ones (SHA256 is included by default). That way:
3284 # - the test library can compute the RSA signatures even in the case of a
3285 # composite RSA signature algorithm based on a SHA hash (no other hash
3286 # used in the unit tests).
3287 # - the dependency of RSA signature tests on PSA_WANT_ALG_SHA_xyz is
3288 # fulfilled as the hash SHA algorithm is supported by the library, and
3289 # thus the tests are run, not skipped.
3290 # - when testing a signature key with an algorithm wildcard built from
3291 # PSA_ALG_ANY_HASH as algorithm to test with the key, the chosen hash
3292 # algorithm based on the hashes supported by the library is also
3293 # supported by the test library.
Manuel Pégourié-Gonnardaed1d782023-06-12 17:22:24 +02003294 # Disable unwanted hashes here, we'll enable hashes we want in loc_extra_list.
Ronald Cron6b49b552023-07-20 09:57:54 +02003295 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3296 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160_C
Ronald Cron403c15c2021-09-13 09:38:05 +02003297 scripts/config.py unset MBEDTLS_MD5_C
3298 scripts/config.py unset MBEDTLS_RIPEMD160_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003299
3300 # We need PEM parsing in the test library as well to support the import
3301 # of PEM encoded RSA keys.
Ronald Cron7612d8c2023-07-20 10:03:54 +02003302 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
3303 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003304
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003305 # Build
3306 # -----
3307
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003308 # These hashes are needed for some RSA-PSS signature tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02003309 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3310 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003311 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02003312
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003313 helper_libtestdriver1_make_main "$loc_accel_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02003314
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003315 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine827dbd92022-02-04 00:30:54 +01003316 not grep mbedtls_rsa_rsassa_pkcs1_v15_sign library/rsa.o
3317 not grep mbedtls_rsa_rsassa_pss_sign_ext library/rsa.o
Ronald Cron403c15c2021-09-13 09:38:05 +02003318
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003319 # Run the tests
3320 # -------------
3321
Ronald Cron403c15c2021-09-13 09:38:05 +02003322 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated RSA signature"
3323 make test
3324}
3325
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003326# This is a temporary test to verify that full RSA support is present even when
Valerio Setti01cc88a2023-06-15 11:53:08 +02003327# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003328component_test_new_psa_want_key_pair_symbol() {
Valerio Setti01cc88a2023-06-15 11:53:08 +02003329 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003330
Valerio Setti4590bc22023-06-13 15:39:23 +02003331 # Create a temporary output file unless there is already one set
3332 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
3333 REMOVE_OUTCOME_ON_EXIT="no"
3334 else
3335 REMOVE_OUTCOME_ON_EXIT="yes"
3336 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
3337 export MBEDTLS_TEST_OUTCOME_FILE
3338 fi
3339
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003340 # Start from crypto configuration
3341 scripts/config.py crypto
3342
3343 # Remove RSA support and its dependencies
3344 scripts/config.py unset MBEDTLS_PKCS1_V15
3345 scripts/config.py unset MBEDTLS_PKCS1_V21
3346 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3347 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3348 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3349 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
3350 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
3351 scripts/config.py unset MBEDTLS_RSA_C
3352 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
3353
3354 # Enable PSA support
3355 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3356
Valerio Setti01cc88a2023-06-15 11:53:08 +02003357 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003358 # that proper translations is done in crypto_legacy.h.
Ronald Cron6b49b552023-07-20 09:57:54 +02003359 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
3360 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
3361 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003362
3363 make
3364
Valerio Setti01cc88a2023-06-15 11:53:08 +02003365 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Valerio Setti4590bc22023-06-13 15:39:23 +02003366 make test
3367
3368 # Parse only 1 relevant line from the outcome file, i.e. a test which is
3369 # performing RSA signature.
3370 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
3371 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
3372
3373 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
3374 rm $MBEDTLS_TEST_OUTCOME_FILE
3375 fi
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003376}
3377
Ronald Cronb2312452021-05-08 14:32:59 +02003378component_test_psa_crypto_config_accel_hash () {
3379 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
3380
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003381 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3382 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3383 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Ronald Cronb2312452021-05-08 14:32:59 +02003384
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003385 # Configure
3386 # ---------
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003387
3388 # Start from default config (no TLS 1.3, no USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003389 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003390
3391 # Disable the things that are being accelerated
Ronald Cronb2312452021-05-08 14:32:59 +02003392 scripts/config.py unset MBEDTLS_MD5_C
3393 scripts/config.py unset MBEDTLS_RIPEMD160_C
3394 scripts/config.py unset MBEDTLS_SHA1_C
Manuel Pégourié-Gonnardc584c272023-03-22 00:32:04 +01003395 scripts/config.py unset MBEDTLS_SHA224_C
3396 scripts/config.py unset MBEDTLS_SHA256_C
Ronald Cronb2312452021-05-08 14:32:59 +02003397 scripts/config.py unset MBEDTLS_SHA384_C
3398 scripts/config.py unset MBEDTLS_SHA512_C
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003399 scripts/config.py unset MBEDTLS_SHA3_C
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003400
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003401 # Build
3402 # -----
3403
3404 helper_libtestdriver1_make_drivers "$loc_accel_list"
3405
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003406 helper_libtestdriver1_make_main "$loc_accel_list"
Ronald Cronb2312452021-05-08 14:32:59 +02003407
Manuel Pégourié-Gonnardc584c272023-03-22 00:32:04 +01003408 # There's a risk of something getting re-enabled via config_psa.h;
3409 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
3410 not grep mbedtls_md5 library/md5.o
3411 not grep mbedtls_sha1 library/sha1.o
3412 not grep mbedtls_sha256 library/sha256.o
3413 not grep mbedtls_sha512 library/sha512.o
3414 not grep mbedtls_ripemd160 library/ripemd160.o
Ronald Cronb2312452021-05-08 14:32:59 +02003415
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003416 # Run the tests
3417 # -------------
3418
Ronald Cronb2312452021-05-08 14:32:59 +02003419 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
3420 make test
3421}
3422
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003423component_test_psa_crypto_config_accel_hash_keep_builtins () {
3424 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
3425 # This component ensures that all the test cases for
3426 # md_psa_dynamic_dispatch with legacy+driver in test_suite_md are run.
3427
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003428 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3429 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3430 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003431
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003432 # Start from default config (no TLS 1.3, no USE_PSA)
3433 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003434
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +02003435 helper_libtestdriver1_make_drivers "$loc_accel_list"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003436
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003437 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard9b146392023-03-09 15:56:14 +01003438
3439 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
3440 make test
3441}
3442
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003443# Auxiliary function to build config for hashes with and without drivers
3444config_psa_crypto_hash_use_psa () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003445 driver_only="$1"
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003446 # start with config full for maximum coverage (also enables USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003447 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003448 if [ "$driver_only" -eq 1 ]; then
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003449 # disable the built-in implementation of hashes
3450 scripts/config.py unset MBEDTLS_MD5_C
3451 scripts/config.py unset MBEDTLS_RIPEMD160_C
3452 scripts/config.py unset MBEDTLS_SHA1_C
3453 scripts/config.py unset MBEDTLS_SHA224_C
3454 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
3455 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
3456 scripts/config.py unset MBEDTLS_SHA384_C
3457 scripts/config.py unset MBEDTLS_SHA512_C
3458 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003459 scripts/config.py unset MBEDTLS_SHA3_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003460 fi
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003461}
3462
Przemek Stekiel120ed8f2022-10-27 10:29:15 +02003463# Note that component_test_psa_crypto_config_reference_hash_use_psa
3464# is related to this component and both components need to be kept in sync.
3465# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003466component_test_psa_crypto_config_accel_hash_use_psa () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02003467 msg "test: full with accelerated hashes"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003468
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003469 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3470 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3471 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003472
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003473 # Configure
3474 # ---------
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003475
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003476 config_psa_crypto_hash_use_psa 1
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003477
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003478 # Build
3479 # -----
3480
3481 helper_libtestdriver1_make_drivers "$loc_accel_list"
3482
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003483 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003484
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003485 # There's a risk of something getting re-enabled via config_psa.h;
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01003486 # 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 +02003487 not grep mbedtls_md5 library/md5.o
3488 not grep mbedtls_sha1 library/sha1.o
Manuel Pégourié-Gonnard7b0825d2022-07-11 11:06:09 +02003489 not grep mbedtls_sha256 library/sha256.o
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003490 not grep mbedtls_sha512 library/sha512.o
3491 not grep mbedtls_ripemd160 library/ripemd160.o
3492
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003493 # Run the tests
3494 # -------------
3495
Gilles Peskine14302ed2023-07-19 19:30:04 +02003496 msg "test: full with accelerated hashes"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003497 make test
Andrzej Kurek07e35702022-09-05 15:39:23 -04003498
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003499 # This is mostly useful so that we can later compare outcome files with
3500 # the reference config in analyze_outcomes.py, to check that the
3501 # dependency declarations in ssl-opt.sh and in TLS code are correct.
Gilles Peskine14302ed2023-07-19 19:30:04 +02003502 msg "test: ssl-opt.sh, full with accelerated hashes"
Przemek Stekiel5f6f32a2022-10-27 08:24:43 +02003503 tests/ssl-opt.sh
Andrzej Kurek07e35702022-09-05 15:39:23 -04003504
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003505 # This is to make sure all ciphersuites are exercised, but we don't need
3506 # interop testing (besides, we already got some from ssl-opt.sh).
Gilles Peskine14302ed2023-07-19 19:30:04 +02003507 msg "test: compat.sh, full with accelerated hashes"
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003508 tests/compat.sh -p mbedTLS -V YES
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003509}
3510
Przemek Stekiel120ed8f2022-10-27 10:29:15 +02003511# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
3512# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
3513# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
3514# Both components need to be kept in sync.
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003515component_test_psa_crypto_config_reference_hash_use_psa() {
Gilles Peskine14302ed2023-07-19 19:30:04 +02003516 msg "test: full without accelerated hashes"
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003517
3518 config_psa_crypto_hash_use_psa 0
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003519
Przemek Stekielab0451b2022-10-24 11:29:35 +02003520 make
3521
Gilles Peskine14302ed2023-07-19 19:30:04 +02003522 msg "test: full without accelerated hashes"
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003523 make test
3524
Gilles Peskine14302ed2023-07-19 19:30:04 +02003525 msg "test: ssl-opt.sh, full without accelerated hashes"
Przemek Stekiel5f6f32a2022-10-27 08:24:43 +02003526 tests/ssl-opt.sh
Ronald Cron3a8714d2021-10-18 11:26:01 +02003527}
Manuel Pégourié-Gonnard97ab2a32022-07-06 10:46:57 +02003528
John Durkop4377bf72020-10-23 01:26:57 -07003529component_test_psa_crypto_config_accel_cipher () {
3530 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
3531
3532 loc_accel_list="ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB ALG_OFB ALG_XTS KEY_TYPE_DES"
John Durkop1b7ee052020-11-27 08:51:22 -08003533
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003534 # Configure
3535 # ---------
John Durkop1b7ee052020-11-27 08:51:22 -08003536
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003537 # Start from the default config (no TLS 1.3, no USE_PSA)
3538 helper_libtestdriver1_adjust_config "default"
John Durkop1b7ee052020-11-27 08:51:22 -08003539
Manuel Pégourié-Gonnard7ae342f2023-06-08 09:26:04 +02003540 # There is no intended accelerator support for ALG CMAC. Therefore, asking
3541 # for it in the build implies the inclusion of the Mbed TLS cipher
3542 # operations. As we want to test here with cipher operations solely
3543 # supported by accelerators, disabled this PSA configuration option.
3544 # (Note: the same applies to STREAM_CIPHER and ECB_NO_PADDING, which are
3545 # already disabled by helper_libtestdriver1_adjust_config above.)
Ronald Cron6b49b552023-07-20 09:57:54 +02003546 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
John Durkop1b7ee052020-11-27 08:51:22 -08003547
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003548 # Disable the things that are being accelerated
John Durkop1b7ee052020-11-27 08:51:22 -08003549 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3550 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
3551 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
3552 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
3553 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
3554 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
3555 scripts/config.py unset MBEDTLS_DES_C
3556
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003557 # Build
3558 # -----
John Durkop1b7ee052020-11-27 08:51:22 -08003559
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003560 helper_libtestdriver1_make_drivers "$loc_accel_list"
3561
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003562 helper_libtestdriver1_make_main "$loc_accel_list"
John Durkop1b7ee052020-11-27 08:51:22 -08003563
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003564 # Make sure this was not re-enabled by accident (additive config)
John Durkop1b7ee052020-11-27 08:51:22 -08003565 not grep mbedtls_des* library/des.o
3566
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003567 # Run the tests
3568 # -------------
3569
John Durkop1b7ee052020-11-27 08:51:22 -08003570 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated cipher"
3571 make test
3572}
3573
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003574component_test_psa_crypto_config_accel_aead () {
3575 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
3576
Przemek Stekielee1bb412022-10-11 11:52:25 +02003577 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003578
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003579 # Configure
3580 # ---------
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003581
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003582 # Start from default config (no TLS 1.3, no USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003583 helper_libtestdriver1_adjust_config "default"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003584
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003585 # Disable things that are being accelerated
Przemek Stekielee1bb412022-10-11 11:52:25 +02003586 scripts/config.py unset MBEDTLS_GCM_C
3587 scripts/config.py unset MBEDTLS_CCM_C
3588 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
3589 # Features that depend on AEAD
3590 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel072fad12022-10-13 09:59:52 +02003591 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003592
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003593 # Build
3594 # -----
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003595
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003596 helper_libtestdriver1_make_drivers "$loc_accel_list"
3597
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003598 helper_libtestdriver1_make_main "$loc_accel_list"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003599
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003600 # Make sure this was not re-enabled by accident (additive config)
Przemek Stekielee1bb412022-10-11 11:52:25 +02003601 not grep mbedtls_ccm library/ccm.o
3602 not grep mbedtls_gcm library/gcm.o
3603 not grep mbedtls_chachapoly library/chachapoly.o
3604
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003605 # Run the tests
3606 # -------------
3607
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003608 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
3609 make test
3610}
3611
Gilles Peskine36dea152023-07-20 22:19:45 +02003612component_test_aead_chachapoly_disabled() {
3613 msg "build: full minus CHACHAPOLY"
John Durkopf4c4cb02020-10-28 20:09:55 -07003614 scripts/config.py full
John Durkop9814fa22020-11-04 12:28:15 -08003615 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Ronald Cron6b49b552023-07-20 09:57:54 +02003616 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
John Durkopf4c4cb02020-10-28 20:09:55 -07003617 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
John Durkop6ba40d12020-11-10 08:50:04 -08003618
Gilles Peskine36dea152023-07-20 22:19:45 +02003619 msg "test: full minus CHACHAPOLY"
3620 make test
3621}
3622
3623component_test_aead_only_ccm() {
3624 msg "build: full minus CHACHAPOLY and GCM"
3625 scripts/config.py full
3626 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
3627 scripts/config.py unset MBEDTLS_GCM_C
3628 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
3629 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
3630 make CC=gcc CFLAGS="$ASAN_CFLAGS -O2" LDFLAGS="$ASAN_CFLAGS"
3631
3632 msg "test: full minus CHACHAPOLY and GCM"
John Durkop9814fa22020-11-04 12:28:15 -08003633 make test
John Durkopf4c4cb02020-10-28 20:09:55 -07003634}
3635
Ronald Crone501d0e2023-07-10 08:31:19 +02003636component_test_ccm_aes_sha256() {
3637 msg "build: CCM + AES + SHA256 configuration"
3638
Ronald Cron7612d8c2023-07-20 10:03:54 +02003639 cp "$CONFIG_TEST_DRIVER_H" "$CONFIG_H"
Ronald Cron6b49b552023-07-20 09:57:54 +02003640 cp configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
Ronald Crone501d0e2023-07-10 08:31:19 +02003641
3642 make CC=gcc
3643
3644 msg "test: CCM + AES + SHA256 configuration"
3645 make test
3646}
3647
John Durkop9814fa22020-11-04 12:28:15 -08003648# 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 -07003649component_build_psa_accel_alg_ecdh() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003650 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
John Durkopd0321952020-10-29 21:37:36 -07003651 scripts/config.py full
John Durkopd0321952020-10-29 21:37:36 -07003652 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003653 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkopd0321952020-10-29 21:37:36 -07003654 scripts/config.py unset MBEDTLS_ECDH_C
3655 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3656 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
3657 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
3658 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3659 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
3660 # 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 -08003661 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 -07003662}
3663
John Durkop1b7ee052020-11-27 08:51:22 -08003664# This should be renamed to test and updated once the accelerator HMAC code is in place and ready to test.
3665component_build_psa_accel_alg_hmac() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003666 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
John Durkop1b7ee052020-11-27 08:51:22 -08003667 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003668 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003669 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkop1b7ee052020-11-27 08:51:22 -08003670 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3671 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3672}
3673
3674# This should be renamed to test and updated once the accelerator HKDF code is in place and ready to test.
3675component_build_psa_accel_alg_hkdf() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003676 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
John Durkop1b7ee052020-11-27 08:51:22 -08003677 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003678 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003679 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkop1b7ee052020-11-27 08:51:22 -08003680 scripts/config.py unset MBEDTLS_HKDF_C
Ronald Cron6f135e12021-12-08 16:57:54 +01003681 # Make sure to unset TLS1_3 since it requires HKDF_C and will not build properly without it.
3682 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
John Durkop1b7ee052020-11-27 08:51:22 -08003683 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3684 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3685}
3686
3687# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
3688component_build_psa_accel_alg_md5() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003689 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003690 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003691 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003692 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003693 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3694 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3695 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3696 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3697 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3698 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3699 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003700 scripts/config.py unset MBEDTLS_LMS_C
3701 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003702 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3703 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3704}
3705
3706# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
3707component_build_psa_accel_alg_ripemd160() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003708 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003709 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003710 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003711 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003712 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3713 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3714 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3715 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3716 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3717 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3718 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003719 scripts/config.py unset MBEDTLS_LMS_C
3720 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003721 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3722 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3723}
3724
3725# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
3726component_build_psa_accel_alg_sha1() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003727 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003728 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003729 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003730 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003731 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3732 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3733 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3734 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3735 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3736 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3737 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003738 scripts/config.py unset MBEDTLS_LMS_C
3739 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003740 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3741 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3742}
3743
3744# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
3745component_build_psa_accel_alg_sha224() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003746 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003747 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003748 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003749 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003750 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3751 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3752 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3753 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3754 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
3755 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
John Durkop1b7ee052020-11-27 08:51:22 -08003756 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3757 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3758}
3759
3760# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
3761component_build_psa_accel_alg_sha256() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003762 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003763 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003764 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003765 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003766 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3767 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3768 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3769 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3770 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3771 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
John Durkop1b7ee052020-11-27 08:51:22 -08003772 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3773 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3774}
3775
3776# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
3777component_build_psa_accel_alg_sha384() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003778 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003779 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003780 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003781 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003782 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3783 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3784 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3785 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3786 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3787 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003788 scripts/config.py unset MBEDTLS_LMS_C
3789 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003790 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3791 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3792}
3793
3794# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
3795component_build_psa_accel_alg_sha512() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003796 msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
John Durkop1b7ee052020-11-27 08:51:22 -08003797 scripts/config.py full
John Durkop1b7ee052020-11-27 08:51:22 -08003798 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003799 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003800 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
3801 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
3802 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
3803 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
3804 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
3805 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
3806 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
Gilles Peskinefa652372022-10-13 22:05:38 +02003807 scripts/config.py unset MBEDTLS_LMS_C
3808 scripts/config.py unset MBEDTLS_LMS_PRIVATE
John Durkop1b7ee052020-11-27 08:51:22 -08003809 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3810 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3811}
3812
John Durkopd0321952020-10-29 21:37:36 -07003813# 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 -08003814component_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003815 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 -07003816 scripts/config.py full
John Durkopd0321952020-10-29 21:37:36 -07003817 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003818 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003819 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
3820 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3821 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3822 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
John Durkopd0321952020-10-29 21:37:36 -07003823 # 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 -07003824 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3825}
3826
3827# 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 -08003828component_build_psa_accel_alg_rsa_pkcs1v15_sign() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003829 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 -07003830 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003831 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003832 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003833 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
3834 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3835 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
3836 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07003837 # 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_RSA_PKCS1V15_SIGN -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3839}
3840
3841# 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 -08003842component_build_psa_accel_alg_rsa_oaep() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003843 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 -07003844 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003845 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" set PSA_WANT_ALG_RSA_OAEP 1
3848 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3849 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3850 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
John Durkopbd069d32020-10-31 22:14:03 -07003851 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3852 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3853}
3854
3855# 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 -08003856component_build_psa_accel_alg_rsa_pss() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003857 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 -07003858 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003859 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003860 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003861 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
3862 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
3863 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
3864 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
John Durkopbd069d32020-10-31 22:14:03 -07003865 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3866 make CC=gcc CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include -O2" LDFLAGS="$ASAN_CFLAGS"
3867}
3868
3869# 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 -08003870component_build_psa_accel_key_type_rsa_key_pair() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003871 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 -07003872 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003873 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003874 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003875 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
3876 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC 1
3877 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT 1
3878 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT 1
3879 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE 1
John Durkopbd069d32020-10-31 22:14:03 -07003880 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3881 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"
3882}
3883
3884# 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 -08003885component_build_psa_accel_key_type_rsa_public_key() {
Gilles Peskineeb41e0d2023-07-19 19:36:55 +02003886 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 -07003887 scripts/config.py full
John Durkopbd069d32020-10-31 22:14:03 -07003888 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01003889 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron6b49b552023-07-20 09:57:54 +02003890 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
3891 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
John Durkopbd069d32020-10-31 22:14:03 -07003892 # Need to define the correct symbol and include the test driver header path in order to build with the test driver
3893 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 -07003894}
3895
Dave Rodgmanc164c072023-06-28 09:43:23 +01003896
Dave Rodgman904c5892023-06-28 17:36:02 +01003897support_build_tfm_armcc () {
Dave Rodgmanc164c072023-06-28 09:43:23 +01003898 armc6_cc="$ARMC6_BIN_DIR/armclang"
3899 (check_tools "$armc6_cc" > /dev/null 2>&1)
3900}
3901
Dave Rodgman904c5892023-06-28 17:36:02 +01003902component_build_tfm_armcc() {
3903 # test the TF-M configuration can build cleanly with various warning flags enabled
Ronald Cron7a93ac52023-07-20 09:49:12 +02003904 cp configs/tfm_mbedcrypto_config_profile_medium.h "$CONFIG_H"
Ronald Cron6b49b552023-07-20 09:57:54 +02003905 cp configs/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Dave Rodgmanc164c072023-06-28 09:43:23 +01003906
Dave Rodgman88651c42023-06-29 12:35:51 +01003907 msg "build: TF-M config, armclang armv7-m thumb2"
Dave Rodgmanfb374e62023-06-29 11:58:16 +01003908 make clean
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02003909 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 +01003910}
3911
3912component_build_tfm() {
3913 # test the TF-M configuration can build cleanly with various warning flags enabled
Ronald Cron7a93ac52023-07-20 09:49:12 +02003914 cp configs/tfm_mbedcrypto_config_profile_medium.h "$CONFIG_H"
Ronald Cron6b49b552023-07-20 09:57:54 +02003915 cp configs/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Dave Rodgmanfb374e62023-06-29 11:58:16 +01003916
Dave Rodgman88651c42023-06-29 12:35:51 +01003917 msg "build: TF-M config, clang, armv7-m thumb2"
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02003918 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 +01003919
Dave Rodgman904c5892023-06-28 17:36:02 +01003920 msg "build: TF-M config, gcc native build"
3921 make clean
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02003922 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 +01003923}
3924
Dave Rodgman6001fb22023-06-29 09:29:00 +01003925component_build_aes_variations() { # ~45s
Dave Rodgmancd040202023-06-29 09:29:00 +01003926 # aes.o has many #if defined(...) guards that intersect in complex ways.
3927 # Test that all the combinations build cleanly. The most common issue is
3928 # unused variables/functions, so ensure -Wunused is set.
3929
Dave Rodgman6001fb22023-06-29 09:29:00 +01003930 msg "build: aes.o for all combinations of relevant config options"
Dave Rodgman0f0f7692023-06-29 12:10:45 +01003931
Dave Rodgman6001fb22023-06-29 09:29:00 +01003932 for a in set unset; do
3933 for b in set unset; do
3934 for c in set unset; do
3935 for d in set unset; do
3936 for e in set unset; do
3937 for f in set unset; do
3938 for g in set unset; do
Dave Rodgman0f0f7692023-06-29 12:10:45 +01003939 echo ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
3940 echo ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
3941 echo ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
3942 echo ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
3943 echo ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
3944 echo ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
3945 echo ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman6001fb22023-06-29 09:29:00 +01003946
Dave Rodgman0f0f7692023-06-29 12:10:45 +01003947 ./scripts/config.py $a MBEDTLS_AES_SETKEY_ENC_ALT
3948 ./scripts/config.py $b MBEDTLS_AES_DECRYPT_ALT
3949 ./scripts/config.py $c MBEDTLS_AES_ROM_TABLES
3950 ./scripts/config.py $d MBEDTLS_AES_ENCRYPT_ALT
3951 ./scripts/config.py $e MBEDTLS_AES_SETKEY_DEC_ALT
3952 ./scripts/config.py $f MBEDTLS_AES_FEWER_TABLES
3953 ./scripts/config.py $g MBEDTLS_PADLOCK_C
Dave Rodgman6001fb22023-06-29 09:29:00 +01003954
Dave Rodgman0f0f7692023-06-29 12:10:45 +01003955 rm -f library/aes.o
3956 make -C library aes.o CC="clang" CFLAGS="-O0 -std=c99 -Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
Dave Rodgman6001fb22023-06-29 09:29:00 +01003957 done
3958 done
3959 done
3960 done
3961 done
3962 done
3963 done
3964}
3965
Gilles Peskine8f073122018-11-27 15:58:47 +01003966component_test_no_platform () {
3967 # Full configuration build, without platform support, file IO and net sockets.
3968 # This should catch missing mbedtls_printf definitions, and by disabling file
3969 # IO, it should catch missing '#include <stdio.h>'
3970 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003971 scripts/config.py full
3972 scripts/config.py unset MBEDTLS_PLATFORM_C
3973 scripts/config.py unset MBEDTLS_NET_C
3974 scripts/config.py unset MBEDTLS_PLATFORM_MEMORY
3975 scripts/config.py unset MBEDTLS_PLATFORM_PRINTF_ALT
3976 scripts/config.py unset MBEDTLS_PLATFORM_FPRINTF_ALT
3977 scripts/config.py unset MBEDTLS_PLATFORM_SNPRINTF_ALT
Gilles Peskineef843f22022-09-18 14:05:23 +02003978 scripts/config.py unset MBEDTLS_PLATFORM_VSNPRINTF_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003979 scripts/config.py unset MBEDTLS_PLATFORM_TIME_ALT
3980 scripts/config.py unset MBEDTLS_PLATFORM_EXIT_ALT
Gilles Peskine6497b5a2022-06-30 17:01:40 +02003981 scripts/config.py unset MBEDTLS_PLATFORM_SETBUF_ALT
Gilles Peskine32e889d2020-04-12 23:43:28 +02003982 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003983 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
3984 scripts/config.py unset MBEDTLS_FS_IO
Gilles Peskine3bdd4122019-07-27 23:52:53 +02003985 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003986 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
3987 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01003988 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
3989 # to re-enable platform integration features otherwise disabled in C99 builds
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02003990 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
3991 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Gilles Peskine8f073122018-11-27 15:58:47 +01003992}
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00003993
Gilles Peskine8f073122018-11-27 15:58:47 +01003994component_build_no_std_function () {
3995 # catch compile bugs in _uninit functions
3996 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02003997 scripts/config.py full
3998 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
3999 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Gilles Peskine32e889d2020-04-12 23:43:28 +02004000 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinef4d2fd42021-10-08 11:45:47 +02004001 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Gilles Peskinedbf7b7e2021-10-07 19:34:57 +02004002 make
Gilles Peskine8f073122018-11-27 15:58:47 +01004003}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01004004
Gilles Peskine8f073122018-11-27 15:58:47 +01004005component_build_no_ssl_srv () {
Ronald Cronde1adee2022-03-07 16:20:30 +01004006 msg "build: full config except SSL server, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004007 scripts/config.py full
4008 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02004009 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01004010}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02004011
Gilles Peskine8f073122018-11-27 15:58:47 +01004012component_build_no_ssl_cli () {
Ronald Cronde1adee2022-03-07 16:20:30 +01004013 msg "build: full config except SSL client, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004014 scripts/config.py full
4015 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02004016 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01004017}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02004018
Gilles Peskine8f073122018-11-27 15:58:47 +01004019component_build_no_sockets () {
4020 # Note, C99 compliance can also be tested with the sockets support disabled,
4021 # as that requires a POSIX platform (which isn't the same as C99).
4022 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004023 scripts/config.py full
4024 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
4025 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
Gilles Peskine6ec0f0f2019-09-20 19:23:10 +02004026 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
Gilles Peskine8f073122018-11-27 15:58:47 +01004027}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02004028
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04004029component_test_memory_buffer_allocator_backtrace () {
4030 msg "build: default config with memory buffer allocator and backtrace enabled"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004031 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4032 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4033 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
4034 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02004035 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04004036 make
4037
4038 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
4039 make test
4040}
4041
4042component_test_memory_buffer_allocator () {
4043 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004044 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4045 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02004046 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Hanno Becker0fb9ba22019-02-26 14:34:13 +00004047 make
4048
4049 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
4050 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01004051
4052 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
4053 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004054 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00004055}
4056
Gilles Peskine8f073122018-11-27 15:58:47 +01004057component_test_no_max_fragment_length () {
4058 # Run max fragment length tests with MFL disabled
4059 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004060 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01004061 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4062 make
Hanno Becker5175ac62017-09-18 15:36:25 +01004063
Gilles Peskine8f073122018-11-27 15:58:47 +01004064 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004065 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01004066}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004067
Hanno Becker545ced42019-02-19 11:10:48 +00004068component_test_asan_remove_peer_certificate () {
4069 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004070 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Hanno Becker545ced42019-02-19 11:10:48 +00004071 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4072 make
4073
4074 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
4075 make test
4076
4077 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004078 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00004079
4080 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004081 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02004082
4083 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004084 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00004085}
4086
Gilles Peskine8f073122018-11-27 15:58:47 +01004087component_test_no_max_fragment_length_small_ssl_out_content_len () {
4088 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004089 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4090 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
4091 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Gilles Peskine8f073122018-11-27 15:58:47 +01004092 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4093 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10004094
Gilles Peskine8f073122018-11-27 15:58:47 +01004095 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004096 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02004097
4098 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004099 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01004100}
Angus Grattonc4dd0732018-04-11 16:28:39 +10004101
Darryl Greenaad82f92019-12-02 10:53:11 +00004102component_test_variable_ssl_in_out_buffer_len () {
4103 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
4104 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
4105 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4106 make
4107
4108 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
4109 make test
4110
4111 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004112 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004113
4114 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004115 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004116}
4117
Manuel Pégourié-Gonnard6a543ba2022-11-25 11:30:10 +01004118component_test_dtls_cid_legacy () {
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004119 msg "build: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled (ASan build)"
Hannes Tschofenigfd6cca42021-10-12 09:22:33 +02004120 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 1
Darryl Greenaad82f92019-12-02 10:53:11 +00004121
4122 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4123 make
4124
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004125 msg "test: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy)"
Darryl Greenaad82f92019-12-02 10:53:11 +00004126 make test
4127
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004128 msg "test: ssl-opt.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004129 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004130
Manuel Pégourié-Gonnard6a543ba2022-11-25 11:30:10 +01004131 msg "test: compat.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004132 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004133}
4134
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004135component_test_ssl_alloc_buffer_and_mfl () {
4136 msg "build: default config with memory buffer allocator and MFL extension"
4137 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4138 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4139 scripts/config.py set MBEDTLS_MEMORY_DEBUG
4140 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4141 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02004142 CC=gcc cmake -DCMAKE_BUILD_TYPE:String=Release .
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004143 make
4144
4145 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
4146 make test
4147
4148 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 +02004149 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004150}
4151
Gilles Peskine636c26a2020-03-04 20:46:15 +01004152component_test_when_no_ciphersuites_have_mac () {
4153 msg "build: when no ciphersuites have MAC"
4154 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Gilles Peskine636c26a2020-03-04 20:46:15 +01004155 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
TRodziewicz2add5c12021-04-28 16:50:20 +02004156 scripts/config.py unset MBEDTLS_CMAC_C
Gilles Peskine636c26a2020-03-04 20:46:15 +01004157 make
4158
4159 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
4160 make test
4161
4162 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004163 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01004164}
4165
Raoul Strackxa4e86142020-06-15 17:03:13 +02004166component_test_no_date_time () {
4167 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
4168 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
Gilles Peskinef4d2fd42021-10-08 11:45:47 +02004169 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
Raoul Strackxa4e86142020-06-15 17:03:13 +02004170 make
4171
4172 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
4173 make test
4174}
4175
Gilles Peskine8f073122018-11-27 15:58:47 +01004176component_test_platform_calloc_macro () {
4177 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004178 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4179 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
4180 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Gilles Peskine8f073122018-11-27 15:58:47 +01004181 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4182 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01004183
Gilles Peskine8f073122018-11-27 15:58:47 +01004184 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
4185 make test
4186}
Hanno Beckere5fecec2018-10-11 11:02:52 +01004187
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02004188component_test_malloc_0_null () {
4189 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004190 scripts/config.py full
Gilles Peskinecf4fe582023-07-20 19:00:15 +02004191 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 +02004192
4193 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
4194 make test
4195
4196 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
4197 # Just the calloc selftest. "make test" ran the others as part of the
4198 # test suites.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004199 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01004200
4201 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
4202 # Run a subset of the tests. The choice is a balance between coverage
4203 # and time (including time indirectly wasted due to flaky tests).
4204 # The current choice is to skip tests whose description includes
4205 # "proxy", which is an approximation of skipping tests that use the
4206 # UDP proxy, which tend to be slower and flakier.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004207 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02004208}
4209
Dave Rodgman6a08b682023-06-19 11:51:33 +01004210support_test_aesni() {
4211 # Check that gcc targets x86_64 (we can build AESNI), and check for
4212 # AESNI support on the host (we can run AESNI).
4213 #
4214 # The name of this function is possibly slightly misleading, but needs to align
4215 # with the name of the corresponding test, component_test_aesni.
Dave Rodgmanf8986e32023-06-19 10:55:59 +01004216 #
4217 # In principle 32-bit x86 can support AESNI, but our implementation does not
4218 # support 32-bit x86, so we check for x86-64.
4219 # We can only grep /proc/cpuinfo on Linux, so this also checks for Linux
Dave Rodgman6a08b682023-06-19 11:51:33 +01004220 (gcc -v 2>&1 | grep Target | grep -q x86_64) &&
4221 [[ "$HOSTTYPE" == "x86_64" && "$OSTYPE" == "linux-gnu" ]] &&
Jerry Yua7de78d2023-08-08 12:57:35 +08004222 (lscpu | grep -qw aes)
Dave Rodgmanf8986e32023-06-19 10:55:59 +01004223}
4224
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004225component_test_aesni () { # ~ 60s
4226 # This tests the two AESNI implementations (intrinsics and assembly), and also the plain C
4227 # fallback. It also tests the logic that is used to select which implementation(s) to build.
4228 #
4229 # This test does not require the host to have support for AESNI (if it doesn't, the run-time
4230 # AESNI detection will fallback to the plain C implementation, so the tests will instead
4231 # exercise the plain C impl).
4232
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004233 msg "build: default config with different AES implementations"
Dave Rodgman838dc462023-06-16 13:18:19 +01004234 scripts/config.py set MBEDTLS_AESNI_C
Jerry Yu17a9d2e2023-08-03 16:14:18 +08004235 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Dave Rodgman838dc462023-06-16 13:18:19 +01004236 scripts/config.py set MBEDTLS_HAVE_ASM
4237
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004238 # test the intrinsics implementation
4239 msg "AES tests, test intrinsics"
Dave Rodgman838dc462023-06-16 13:18:19 +01004240 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004241 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004242 # check that we built intrinsics - this should be used by default when supported by the compiler
Jerry Yu1221a312023-08-03 16:09:07 +08004243 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004244
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004245 # test the asm implementation
4246 msg "AES tests, test assembly"
4247 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004248 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mno-pclmul -mno-sse2 -mno-aes'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004249 # check that we built assembly - this should be built if the compiler does not support intrinsics
Jerry Yu1221a312023-08-03 16:09:07 +08004250 ./programs/test/selftest aes | grep "AESNI code" | grep -q "assembly"
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004251
4252 # test the plain C implementation
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004253 scripts/config.py unset MBEDTLS_AESNI_C
Jerry Yu17a9d2e2023-08-03 16:14:18 +08004254 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004255 msg "AES tests, plain C"
4256 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004257 make CC=gcc CFLAGS='-O2 -Werror'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004258 # check that there is no AESNI code present
Jerry Yu1221a312023-08-03 16:09:07 +08004259 ./programs/test/selftest aes | not grep -q "AESNI code"
Jerry Yu76a51b92023-08-08 16:03:55 +08004260 not grep -q "AES note: using AESNI" ./programs/test/selftest
4261 grep -q "AES note: built-in implementation." ./programs/test/selftest
Jerry Yu8a599c02023-08-03 17:01:02 +08004262
4263 # test the intrinsics implementation
4264 scripts/config.py set MBEDTLS_AESNI_C
4265 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4266 msg "AES tests, test AESNI only"
4267 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004268 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
Jerry Yua7de78d2023-08-08 12:57:35 +08004269 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
4270 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
Jerry Yu76a51b92023-08-08 16:03:55 +08004271 grep -q "AES note: using AESNI" ./programs/test/selftest
4272 not grep -q "AES note: built-in implementation." ./programs/test/selftest
Dave Rodgman838dc462023-06-16 13:18:19 +01004273}
4274
Jerry Yu193cbc02023-08-03 17:06:29 +08004275
Jerry Yub6d39c22023-08-16 15:11:48 +08004276
4277support_test_aesni_m32() {
4278 support_test_m32_o0 && (lscpu | grep -qw aes)
4279}
4280
4281component_test_aesni_m32 () { # ~ 60s
4282 # This tests are duplicated from component_test_aesni for i386 target
4283 #
4284 # AESNI intrinsic code supports i386 and assembly code does not support it.
4285
4286 msg "build: default config with different AES implementations"
4287 scripts/config.py set MBEDTLS_AESNI_C
4288 scripts/config.py set MBEDTLS_PADLOCK_C
4289 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4290 scripts/config.py set MBEDTLS_HAVE_ASM
4291
4292 # test the intrinsics implementation
4293 msg "AES tests, test intrinsics"
4294 make clean
4295 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
4296 # check that we built intrinsics - this should be used by default when supported by the compiler
4297 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
4298 grep -q "AES note: using AESNI" ./programs/test/selftest
4299 grep -q "AES note: built-in implementation." ./programs/test/selftest
4300 grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4301 grep -q mbedtls_aesni_has_support ./programs/test/selftest
4302
4303 scripts/config.py set MBEDTLS_AESNI_C
Jerry Yub6d39c22023-08-16 15:11:48 +08004304 scripts/config.py unset MBEDTLS_PADLOCK_C
4305 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4306 msg "AES tests, test AESNI only"
4307 make clean
4308 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
4309 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
4310 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
4311 grep -q "AES note: using AESNI" ./programs/test/selftest
4312 not grep -q "AES note: built-in implementation." ./programs/test/selftest
4313 not grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4314 not grep -q mbedtls_aesni_has_support ./programs/test/selftest
4315}
4316
Jerry Yu193cbc02023-08-03 17:06:29 +08004317# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
4318component_build_aes_aesce_armcc () {
4319 msg "Build: AESCE test on arm64 platform without plain C."
4320 scripts/config.py baremetal
4321
4322 # armc[56] don't support SHA-512 intrinsics
4323 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
4324
4325 # Stop armclang warning about feature detection for A64_CRYPTO.
4326 # With this enabled, the library does build correctly under armclang,
4327 # but in baremetal builds (as tested here), feature detection is
4328 # unavailable, and the user is notified via a #warning. So enabling
4329 # this feature would prevent us from building with -Werror on
4330 # armclang. Tracked in #7198.
4331 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
4332 scripts/config.py set MBEDTLS_HAVE_ASM
4333
4334 msg "AESCE, build with default configuration."
4335 scripts/config.py set MBEDTLS_AESCE_C
4336 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4337 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
4338
4339 msg "AESCE, build AESCE only"
4340 scripts/config.py set MBEDTLS_AESCE_C
4341 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4342 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
4343}
4344
Jerry Yuc935aa62023-08-03 17:08:27 +08004345# For timebeing, no VIA Padlock platform available.
4346component_build_aes_via_padlock () {
4347
4348 msg "AES:VIA PadLock, build with default configuration."
Jerry Yu506759f2023-08-16 17:11:22 +08004349 scripts/config.py unset MBEDTLS_AESNI_C
Jerry Yuc935aa62023-08-03 17:08:27 +08004350 scripts/config.py set MBEDTLS_PADLOCK_C
4351 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4352 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Jerry Yu506759f2023-08-16 17:11:22 +08004353 grep -q mbedtls_padlock_has_support ./programs/test/selftest
Jerry Yuc935aa62023-08-03 17:08:27 +08004354
4355}
4356
4357support_build_aes_via_padlock_only () {
4358 ( [ "$MBEDTLS_TEST_PLATFORM" == "Linux-x86_64" ] || \
4359 [ "$MBEDTLS_TEST_PLATFORM" == "Linux-amd64" ] ) && \
4360 [ "`dpkg --print-foreign-architectures`" == "i386" ]
4361}
4362
Jerry Yu193cbc02023-08-03 17:06:29 +08004363support_build_aes_aesce_armcc () {
4364 support_build_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +01004365}
4366
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004367component_test_aes_only_128_bit_keys () {
Gilles Peskine8f073122018-11-27 15:58:47 +01004368 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
Hanno Becker83ebf782017-07-07 12:29:15 +01004369 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01004370 scripts/config.py unset MBEDTLS_PADLOCK_C
4371
4372 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01004373
Gilles Peskine8f073122018-11-27 15:58:47 +01004374 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
4375 make test
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004376}
4377
Gilles Peskine8f073122018-11-27 15:58:47 +01004378component_test_no_ctr_drbg_aes_only_128_bit_keys () {
Hanno Becker83ebf782017-07-07 12:29:15 +01004379 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
Gilles Peskine8f073122018-11-27 15:58:47 +01004380 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4381 scripts/config.py unset MBEDTLS_CTR_DRBG_C
4382 scripts/config.py unset MBEDTLS_PADLOCK_C
4383
Gilles Peskine592f5912019-10-07 18:49:32 +02004384 make CC=clang CFLAGS='-Werror -Wall -Wextra'
4385
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004386 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
4387 make test
4388}
Gilles Peskine592f5912019-10-07 18:49:32 +02004389
4390component_test_aes_only_128_bit_keys_have_builtins () {
4391 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4392 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4393 scripts/config.py unset MBEDTLS_PADLOCK_C
4394 scripts/config.py unset MBEDTLS_AESNI_C
4395 scripts/config.py unset MBEDTLS_AESCE_C
4396
4397 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004398
4399 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4400 make test
Gilles Peskine592f5912019-10-07 18:49:32 +02004401
4402 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4403 programs/test/selftest
4404}
4405
4406component_test_aes_fewer_tables () {
4407 msg "build: default config with AES_FEWER_TABLES enabled"
4408 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
4409 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004410
4411 msg "test: AES_FEWER_TABLES"
4412 make test
4413}
Gilles Peskine592f5912019-10-07 18:49:32 +02004414
4415component_test_aes_rom_tables () {
4416 msg "build: default config with AES_ROM_TABLES enabled"
4417 scripts/config.py set MBEDTLS_AES_ROM_TABLES
4418 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
4419
4420 msg "test: AES_ROM_TABLES"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02004421 make test
4422}
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004423
Gilles Peskine004206c2019-10-21 17:11:33 +02004424component_test_aes_fewer_tables_and_rom_tables () {
Gilles Peskinef96aefe2019-07-24 14:58:38 +02004425 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
4426 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
4427 scripts/config.py set MBEDTLS_AES_ROM_TABLES
4428 make CC=gcc CFLAGS='-Werror -Wall -Wextra'
4429
Steven Cooremand57203d2020-07-16 20:28:59 +02004430 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
Ronald Cron32a432a2023-03-28 09:19:04 +02004431 make test
Steven Cooreman753f9732021-03-15 11:38:44 +01004432}
Steven Cooreman6801f082021-02-19 17:21:22 +01004433
Gilles Peskine3587dfd2021-09-20 19:20:04 +02004434component_test_ctr_drbg_aes_256_sha_256 () {
4435 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Ronald Cron17b3afc2020-12-10 18:17:09 +01004436 scripts/config.py full
4437 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4438 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Steven Cooremand57203d2020-07-16 20:28:59 +02004439 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Ronald Cron32a432a2023-03-28 09:19:04 +02004440 make
Steven Cooremand57203d2020-07-16 20:28:59 +02004441
4442 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4443 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01004444}
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004445
Andrzej Kurek232e8f92019-10-03 03:18:01 -04004446component_test_ctr_drbg_aes_128_sha_512 () {
Gilles Peskine56c01612019-07-03 20:43:32 +02004447 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskineca144592021-11-04 12:52:14 +01004448 scripts/config.py full
Gilles Peskine8f073122018-11-27 15:58:47 +01004449 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02004450 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Gilles Peskinecf740502019-07-03 20:43:05 +02004451 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4452 make
4453
4454 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine56c01612019-07-03 20:43:32 +02004455 make test
Gilles Peskinecf740502019-07-03 20:43:05 +02004456}
Gilles Peskineca144592021-11-04 12:52:14 +01004457
Gilles Peskinecf740502019-07-03 20:43:05 +02004458component_test_ctr_drbg_aes_128_sha_256 () {
4459 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskineec10bf12019-09-20 19:56:06 +02004460 scripts/config.py full
4461 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
4462 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
4463 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Gilles Peskinee094a182020-04-14 20:08:41 +02004464 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskineec10bf12019-09-20 19:56:06 +02004465 make
4466
4467 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
4468 make test
4469}
4470
4471component_test_se_default () {
4472 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
4473 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
4474 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004475
Gilles Peskineec10bf12019-09-20 19:56:06 +02004476 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
4477 make test
4478}
4479
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004480component_test_psa_crypto_drivers () {
Gilles Peskine1997f302023-07-26 18:45:20 +02004481 msg "build: full + test drivers dispatching to builtins"
Gilles Peskineec10bf12019-09-20 19:56:06 +02004482 scripts/config.py full
Gilles Peskine1997f302023-07-26 18:45:20 +02004483 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Gilles Peskineec10bf12019-09-20 19:56:06 +02004484 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
4485 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
4486 loc_cflags="${loc_cflags} -I../tests/include -O2"
4487
4488 make CC=gcc CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
4489
Gilles Peskine1997f302023-07-26 18:45:20 +02004490 msg "test: full + test drivers dispatching to builtins"
Gilles Peskineec10bf12019-09-20 19:56:06 +02004491 make test
4492}
4493
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02004494component_test_make_shared () {
4495 msg "build/test: make shared" # ~ 40s
4496 make SHARED=1 all check
4497 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004498 programs/test/dlopen_demo.sh
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02004499}
4500
4501component_test_cmake_shared () {
4502 msg "build/test: cmake shared" # ~ 2min
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004503 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
4504 make
Gilles Peskine8f073122018-11-27 15:58:47 +01004505 ldd programs/util/strerror | grep libmbedcrypto
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004506 make test
4507 programs/test/dlopen_demo.sh
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004508}
Gilles Peskine8fd59422019-10-21 17:11:33 +02004509
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004510test_build_opt () {
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004511 info=$1 cc=$2; shift 2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004512 $cc --version
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004513 for opt in "$@"; do
Gilles Peskine14c3c062018-01-29 21:25:12 +01004514 msg "build/test: $cc $opt, $info" # ~ 30s
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004515 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskine14c3c062018-01-29 21:25:12 +01004516 # We're confident enough in compilers to not run _all_ the tests,
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004517 # but at least run the unit tests. In particular, runs with
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01004518 # optimizations use inline assembly whereas runs with -O0
Gilles Peskine14c3c062018-01-29 21:25:12 +01004519 # skip inline assembly.
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01004520 make test # ~30s
4521 make clean
4522 done
4523}
4524
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004525# For FreeBSD we invoke the function by name so this condition is added
4526# to disable the existing test_clang_opt function for linux.
4527if [[ $(uname) != "Linux" ]]; then
4528 component_test_clang_opt () {
4529 scripts/config.py full
4530 test_build_opt 'full config' clang -O0 -Os -O2
4531 }
4532fi
4533
4534component_test_clang_latest_opt () {
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004535 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004536 test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004537}
4538support_test_clang_latest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004539 type "$CLANG_LATEST" >/dev/null 2>/dev/null
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004540}
4541
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004542component_test_clang_earliest_opt () {
Gilles Peskine878cf602019-01-06 20:50:38 +00004543 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004544 test_build_opt 'full config' "$CLANG_EARLIEST" -O0
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004545}
4546support_test_clang_earliest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004547 type "$CLANG_EARLIEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004548}
4549
4550component_test_gcc_latest_opt () {
4551 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004552 test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004553}
4554support_test_gcc_latest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004555 type "$GCC_LATEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004556}
4557
4558component_test_gcc_earliest_opt () {
4559 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004560 test_build_opt 'full config' "$GCC_EARLIEST" -O0
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01004561}
4562support_test_gcc_earliest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01004563 type "$GCC_EARLIEST" >/dev/null 2>/dev/null
Gilles Peskine878cf602019-01-06 20:50:38 +00004564}
4565
4566component_build_mbedtls_config_file () {
4567 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
Gilles Peskine2003c2f2022-04-07 20:55:57 +02004568 scripts/config.py -w full_config.h full
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004569 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
4570 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
Gilles Peskine45e680e2022-04-13 23:23:21 +02004571 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskinee10df772022-04-07 21:06:41 +02004572 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
4573 make clean
4574
4575 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
4576 # In the user config, disable one feature (for simplicity, pick a feature
4577 # that nothing else depends on).
4578 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
4579 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
4580 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
4581
4582 rm -f user_config.h full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004583}
4584
Gilles Peskine7d904e72022-04-07 21:59:14 +02004585component_build_psa_config_file () {
4586 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
4587 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
4588 cp "$CRYPTO_CONFIG_H" psa_test_config.h
4589 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
4590 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Gilles Peskine45e680e2022-04-13 23:23:21 +02004591 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine7d904e72022-04-07 21:59:14 +02004592 programs/test/query_compile_time_config MBEDTLS_CMAC_C
4593 make clean
4594
4595 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
4596 # In the user config, disable one feature, which will reflect on the
4597 # mbedtls configuration so we can query it with query_compile_time_config.
4598 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
4599 scripts/config.py unset MBEDTLS_CMAC_C
4600 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
4601 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
4602
4603 rm -f psa_test_config.h psa_user_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004604}
4605
Gilles Peskinedf6e84a2023-02-22 22:09:51 +01004606component_build_psa_alt_headers () {
4607 msg "build: make with PSA alt headers" # ~20s
4608
4609 # Generate alternative versions of the substitutable headers with the
4610 # same content except different include guards.
4611 make -C tests include/alt-extra/psa/crypto_platform_alt.h include/alt-extra/psa/crypto_struct_alt.h
4612
4613 # Build the library and some programs.
4614 # Don't build the fuzzers to avoid having to go through hoops to set
4615 # a correct include path for programs/fuzz/Makefile.
4616 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
4617 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\"'"
4618
4619 # Check that we're getting the alternative include guards and not the
4620 # original include guards.
4621 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
4622 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
4623 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
4624 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
4625}
4626
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004627component_test_m32_o0 () {
Gilles Peskine77f05352021-10-07 19:27:16 +02004628 # Build without optimization, so as to use portable C code (in a 32-bit
4629 # build) and not the i386-specific inline assembly.
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004630 msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s
4631 scripts/config.py full
Jerry Yubdd96b92023-08-16 17:34:27 +08004632 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004633 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O0" LDFLAGS="-m32 $ASAN_CFLAGS"
4634
4635 msg "test: i386, make, gcc -O0 (ASan build)"
4636 make test
4637}
4638support_test_m32_o0 () {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02004639 case $(uname -m) in
Pengyu Lvc92df3b2022-10-21 10:50:26 +00004640 amd64|x86_64) true;;
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004641 *) false;;
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004642 esac
4643}
4644
Gilles Peskineff0aee02021-10-05 09:36:03 +02004645component_test_m32_o2 () {
4646 # Build with optimization, to use the i386 specific inline assembly
4647 # and go faster for tests.
4648 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004649 scripts/config.py full
Jerry Yubdd96b92023-08-16 17:34:27 +08004650 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Gilles Peskineff0aee02021-10-05 09:36:03 +02004651 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01004652
Gilles Peskineff0aee02021-10-05 09:36:03 +02004653 msg "test: i386, make, gcc -O2 (ASan build)"
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004654 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01004655
Gilles Peskineff0aee02021-10-05 09:36:03 +02004656 msg "test ssl-opt.sh, i386, make, gcc-O2"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004657 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01004658}
Gilles Peskinecf522222021-10-07 19:25:29 +02004659support_test_m32_o2 () {
Gilles Peskine878cf602019-01-06 20:50:38 +00004660 support_test_m32_o0 "$@"
4661}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004662
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004663component_test_m32_everest () {
4664 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004665 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Jerry Yubdd96b92023-08-16 17:34:27 +08004666 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Gilles Peskine8fd59422019-10-21 17:11:33 +02004667 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32 -O2" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004668
4669 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
4670 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01004671
4672 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004673 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01004674
4675 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
4676 # Exclude some symmetric ciphers that are redundant here to gain time.
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02004677 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02004678}
4679support_test_m32_everest () {
4680 support_test_m32_o0 "$@"
4681}
4682
Gilles Peskine8f073122018-11-27 15:58:47 +01004683component_test_mx32 () {
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004684 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004685 scripts/config.py full
Gilles Peskine5d26e7c2019-06-07 14:50:09 +02004686 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004687
4688 msg "test: 64-bit ILP32, make, gcc"
4689 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01004690}
Gilles Peskine878cf602019-01-06 20:50:38 +00004691support_test_mx32 () {
4692 case $(uname -m) in
4693 amd64|x86_64) true;;
4694 *) false;;
4695 esac
4696}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004697
Peter Kolbus60c6da22018-12-27 06:59:04 -06004698component_test_min_mpi_window_size () {
4699 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004700 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Peter Kolbus60c6da22018-12-27 06:59:04 -06004701 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
4702 make
4703
4704 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
4705 make test
4706}
4707
Gilles Peskine8f073122018-11-27 15:58:47 +01004708component_test_have_int32 () {
4709 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004710 scripts/config.py unset MBEDTLS_HAVE_ASM
4711 scripts/config.py unset MBEDTLS_AESNI_C
4712 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08004713 scripts/config.py unset MBEDTLS_AESCE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01004714 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02004715
Gilles Peskine8f073122018-11-27 15:58:47 +01004716 msg "test: gcc, force 32-bit bignum limbs"
4717 make test
4718}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01004719
Gilles Peskine8f073122018-11-27 15:58:47 +01004720component_test_have_int64 () {
4721 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004722 scripts/config.py unset MBEDTLS_HAVE_ASM
4723 scripts/config.py unset MBEDTLS_AESNI_C
4724 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08004725 scripts/config.py unset MBEDTLS_AESCE_C
Gilles Peskine8f073122018-11-27 15:58:47 +01004726 make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01004727
Gilles Peskine8f073122018-11-27 15:58:47 +01004728 msg "test: gcc, force 64-bit bignum limbs"
4729 make test
4730}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004731
Gabor Mezeie256cc12023-07-26 17:28:48 +02004732component_test_have_int32_cmake_new_bignum () {
4733 msg "build: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
4734 scripts/config.py unset MBEDTLS_HAVE_ASM
4735 scripts/config.py unset MBEDTLS_AESNI_C
4736 scripts/config.py unset MBEDTLS_PADLOCK_C
4737 scripts/config.py unset MBEDTLS_AESCE_C
4738 scripts/config.py set MBEDTLS_TEST_HOOKS
Janos Follath2f045822023-07-31 10:57:16 +01004739 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Janos Follathf3135af2023-07-31 10:07:57 +01004740 make CC=gcc CFLAGS="$ASAN_CFLAGS -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32" LDFLAGS="$ASAN_CFLAGS"
Gabor Mezeie256cc12023-07-26 17:28:48 +02004741
4742 msg "test: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
4743 make test
4744}
4745
Gilles Peskine8f073122018-11-27 15:58:47 +01004746component_test_no_udbl_division () {
4747 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004748 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004749 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine8f073122018-11-27 15:58:47 +01004750 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004751
Gilles Peskine8f073122018-11-27 15:58:47 +01004752 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
4753 make test
4754}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004755
Gilles Peskine8f073122018-11-27 15:58:47 +01004756component_test_no_64bit_multiplication () {
4757 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004758 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004759 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine8f073122018-11-27 15:58:47 +01004760 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004761
Gilles Peskine8f073122018-11-27 15:58:47 +01004762 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
4763 make test
4764}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004765
Gilles Peskine3809f5f2020-11-09 15:40:05 +01004766component_test_no_strings () {
4767 msg "build: no strings" # ~10s
4768 scripts/config.py full
4769 # Disable options that activate a large amount of string constants.
4770 scripts/config.py unset MBEDTLS_DEBUG_C
4771 scripts/config.py unset MBEDTLS_ERROR_C
4772 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
4773 scripts/config.py unset MBEDTLS_VERSION_FEATURES
4774 make CFLAGS='-Werror -Os'
4775
4776 msg "test: no strings" # ~ 10s
4777 make test
4778}
4779
Hanno Beckerc5722d12020-10-09 11:10:42 +01004780component_test_no_x509_info () {
4781 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
4782 scripts/config.pl full
4783 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
4784 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
Gilles Peskineff0aee02021-10-05 09:36:03 +02004785 make CFLAGS='-Werror -O2'
Hanno Beckerc5722d12020-10-09 11:10:42 +01004786
4787 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
4788 make test
4789
4790 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004791 tests/ssl-opt.sh
Hanno Beckerc5722d12020-10-09 11:10:42 +01004792}
4793
Gilles Peskine8f073122018-11-27 15:58:47 +01004794component_build_arm_none_eabi_gcc () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02004795 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004796 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02004797 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 +02004798
Gilles Peskinee36fe812021-09-01 20:00:33 +02004799 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02004800 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01004801}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004802
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004803component_build_arm_linux_gnueabi_gcc_arm5vte () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02004804 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004805 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02004806 # Build for a target platform that's close to what Debian uses
4807 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
Dave Rodgman017a1992022-03-31 14:07:01 +01004808 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004809 # Build everything including programs, see for example
Dave Rodgman017a1992022-03-31 14:07:01 +01004810 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004811 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'
4812
Gilles Peskinee36fe812021-09-01 20:00:33 +02004813 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02004814 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t library/*.o
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004815}
4816support_build_arm_linux_gnueabi_gcc_arm5vte () {
4817 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
4818}
4819
4820component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02004821 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02004822 scripts/config.py baremetal
4823 # This is an imperfect substitute for
4824 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnardae505ee2021-07-06 09:44:59 +02004825 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02004826 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 +02004827
Gilles Peskinee36fe812021-09-01 20:00:33 +02004828 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02004829 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02004830}
4831
Gilles Peskine6e2fb862020-04-30 23:00:53 +02004832component_build_arm_none_eabi_gcc_m0plus () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02004833 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
4834 scripts/config.py baremetal_size
Gilles Peskineaeedd742020-09-02 11:03:04 +02004835 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 +02004836
Gilles Peskinee36fe812021-09-01 20:00:33 +02004837 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02004838 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Manuel Pégourié-Gonnard67f80372023-06-06 13:01:18 +02004839 for lib in library/*.a; do
4840 echo "$lib:"
4841 ${ARM_NONE_EABI_GCC_PREFIX}size -t $lib | grep TOTALS
4842 done
Gilles Peskine6e2fb862020-04-30 23:00:53 +02004843}
4844
Gilles Peskine8f073122018-11-27 15:58:47 +01004845component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02004846 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004847 scripts/config.py baremetal
4848 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02004849 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 +01004850 echo "Checking that software 64-bit division is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004851 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01004852}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004853
Gilles Peskine8f073122018-11-27 15:58:47 +01004854component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02004855 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004856 scripts/config.py baremetal
4857 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02004858 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 +01004859 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004860 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01004861}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02004862
Dave Rodgman8c315f22023-06-02 10:26:24 -04004863component_build_arm_clang_thumb () {
4864 # ~ 30s
4865
4866 scripts/config.py baremetal
4867
4868 msg "build: clang thumb 2, make"
4869 make clean
4870 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
4871
4872 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
4873 msg "build: clang thumb 1 -O0, make"
4874 make clean
4875 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
4876
4877 msg "build: clang thumb 1 -Os, make"
4878 make clean
4879 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
4880}
4881
Gilles Peskine8f073122018-11-27 15:58:47 +01004882component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02004883 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004884 scripts/config.py baremetal
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00004885 # armc[56] don't support SHA-512 intrinsics
4886 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Dave Rodgman2f386c52023-03-02 13:38:33 +00004887
Dave Rodgman0fddf822023-03-02 15:32:12 +00004888 # Stop armclang warning about feature detection for A64_CRYPTO.
4889 # With this enabled, the library does build correctly under armclang,
4890 # but in baremetal builds (as tested here), feature detection is
4891 # unavailable, and the user is notified via a #warning. So enabling
4892 # this feature would prevent us from building with -Werror on
4893 # armclang. Tracked in #7198.
Dave Rodgman2f386c52023-03-02 13:38:33 +00004894 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
4895
Hanno Beckerf0762e92022-07-15 12:08:19 +01004896 scripts/config.py set MBEDTLS_HAVE_ASM
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00004897
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004898 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02004899
4900 msg "size: ARM Compiler 5"
4901 "$ARMC5_FROMELF" -z library/*.o
4902
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004903 make clean
Andres AG87bb5772016-09-27 15:05:15 +01004904
Dave Rodgmanb45d58b2023-06-02 13:54:00 -04004905 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
Hanno Beckerf0762e92022-07-15 12:08:19 +01004906
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004907 # ARM Compiler 6 - Target ARMv7-A
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01004908 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02004909
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004910 # ARM Compiler 6 - Target ARMv7-M
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01004911 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m"
4912
4913 # ARM Compiler 6 - Target ARMv7-M+DSP
4914 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m+dsp"
Simon Butcher940737f2017-07-23 13:42:36 +02004915
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004916 # ARM Compiler 6 - Target ARMv8-A - AArch32
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01004917 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02004918
Gilles Peskinebca6ab92017-12-19 18:24:31 +01004919 # ARM Compiler 6 - Target ARMv8-M
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01004920 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02004921
Tom Cosgrove6ec39ca2023-06-09 15:34:31 +01004922 # ARM Compiler 6 - Target ARMv8.2-A - AArch64
4923 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
4924
Dave Rodgmanb45d58b2023-06-02 13:54:00 -04004925 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
4926 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
4927
Dave Rodgman99318e62023-05-24 12:27:42 +01004928 # ARM Compiler 6 - Target Cortex-M0
4929 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
Gilles Peskine8f073122018-11-27 15:58:47 +01004930}
Tom Cosgrove6ec39ca2023-06-09 15:34:31 +01004931
Pengyu Lvdf070032023-02-24 16:03:31 +08004932support_build_armcc () {
Pengyu Lvc6298ad2023-03-01 10:31:29 +08004933 armc5_cc="$ARMC5_BIN_DIR/armcc"
4934 armc6_cc="$ARMC6_BIN_DIR/armclang"
4935 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
Pengyu Lvdf070032023-02-24 16:03:31 +08004936}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01004937
Jerry Yu81d5e1f2022-01-27 13:01:01 +08004938component_test_tls13_only () {
4939 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3, without MBEDTLS_SSL_PROTO_TLS1_2"
Ronald Cronc2e110f2022-11-22 09:01:46 +01004940 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Jerry Yuda5af222021-12-24 18:45:45 +08004941 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4942
Gilles Peskine4bb369c2022-10-29 17:44:19 +02004943 msg "test: TLS 1.3 only, all key exchange modes enabled"
4944 make test
Jerry Yubaa49342022-02-15 10:26:40 +08004945
Ronald Cronc3f43b62022-10-17 17:35:32 +02004946 msg "ssl-opt.sh: TLS 1.3 only, all key exchange modes enabled"
4947 tests/ssl-opt.sh
Jerry Yuda5af222021-12-24 18:45:45 +08004948}
4949
Ronald Cronc3f43b62022-10-17 17:35:32 +02004950component_test_tls13_only_psk () {
4951 msg "build: TLS 1.3 only from default, only PSK key exchange mode"
4952 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
4953 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
4954 scripts/config.py unset MBEDTLS_ECDH_C
Przemek Stekiel0c231472023-06-14 11:12:45 +02004955 scripts/config.py unset MBEDTLS_DHM_C
Ronald Cronc3f43b62022-10-17 17:35:32 +02004956 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
4957 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
4958 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
4959 scripts/config.py unset MBEDTLS_ECDSA_C
4960 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00004961 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01004962 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Crone3dac4a2022-06-10 17:21:51 +02004963 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4964
Ronald Cronc3f43b62022-10-17 17:35:32 +02004965 msg "test_suite_ssl: TLS 1.3 only, only PSK key exchange mode enabled"
4966 cd tests; ./test_suite_ssl; cd ..
Ronald Crone3dac4a2022-06-10 17:21:51 +02004967
Ronald Cronc3f43b62022-10-17 17:35:32 +02004968 msg "ssl-opt.sh: TLS 1.3 only, only PSK key exchange mode enabled"
4969 tests/ssl-opt.sh
4970}
4971
4972component_test_tls13_only_ephemeral () {
4973 msg "build: TLS 1.3 only from default, only ephemeral key exchange mode"
4974 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4975 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
Xiaokang Qian2dbfeda2022-11-15 10:52:57 +00004976 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02004977 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4978
4979 msg "test_suite_ssl: TLS 1.3 only, only ephemeral key exchange mode"
4980 cd tests; ./test_suite_ssl; cd ..
4981
4982 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral key exchange mode"
4983 tests/ssl-opt.sh
4984}
4985
Przemek Stekiela01c2422023-06-13 10:46:48 +02004986component_test_tls13_only_ephemeral_ffdh () {
4987 msg "build: TLS 1.3 only from default, only ephemeral ffdh key exchange mode"
4988 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
4989 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
4990 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
Przemek Stekielce05f542023-06-15 16:44:08 +02004991 scripts/config.py unset MBEDTLS_ECDH_C
4992
Przemek Stekiela01c2422023-06-13 10:46:48 +02004993 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
4994
4995 msg "test_suite_ssl: TLS 1.3 only, only ephemeral ffdh key exchange mode"
4996 cd tests; ./test_suite_ssl; cd ..
4997
4998 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral ffdh key exchange mode"
4999 tests/ssl-opt.sh
5000}
5001
Ronald Cronc3f43b62022-10-17 17:35:32 +02005002component_test_tls13_only_psk_ephemeral () {
5003 msg "build: TLS 1.3 only from default, only PSK ephemeral key exchange mode"
5004 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5005 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5006 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5007 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5008 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5009 scripts/config.py unset MBEDTLS_ECDSA_C
5010 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00005011 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01005012 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005013 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5014
5015 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral key exchange mode"
5016 cd tests; ./test_suite_ssl; cd ..
5017
5018 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral key exchange mode"
5019 tests/ssl-opt.sh
5020}
5021
Przemek Stekiela01c2422023-06-13 10:46:48 +02005022component_test_tls13_only_psk_ephemeral_ffdh () {
5023 msg "build: TLS 1.3 only from default, only PSK ephemeral ffdh key exchange mode"
5024 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5025 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5026 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5027 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5028 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5029 scripts/config.py unset MBEDTLS_ECDSA_C
5030 scripts/config.py unset MBEDTLS_PKCS1_V21
5031 scripts/config.py unset MBEDTLS_PKCS7_C
5032 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Przemek Stekielce05f542023-06-15 16:44:08 +02005033 scripts/config.py unset MBEDTLS_ECDH_C
Przemek Stekiela01c2422023-06-13 10:46:48 +02005034 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5035
5036 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
5037 cd tests; ./test_suite_ssl; cd ..
5038
5039 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
5040 tests/ssl-opt.sh
5041}
5042
Ronald Cronc3f43b62022-10-17 17:35:32 +02005043component_test_tls13_only_psk_all () {
5044 msg "build: TLS 1.3 only from default, without ephemeral key exchange mode"
5045 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5046 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5047 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5048 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5049 scripts/config.py unset MBEDTLS_ECDSA_C
5050 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00005051 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01005052 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005053 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5054
5055 msg "test_suite_ssl: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
5056 cd tests; ./test_suite_ssl; cd ..
5057
5058 msg "ssl-opt.sh: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
5059 tests/ssl-opt.sh
5060}
5061
5062component_test_tls13_only_ephemeral_all () {
5063 msg "build: TLS 1.3 only from default, without PSK key exchange mode"
5064 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
Ronald Cronc2e110f2022-11-22 09:01:46 +01005065 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005066 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5067
5068 msg "test_suite_ssl: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
5069 cd tests; ./test_suite_ssl; cd ..
5070
5071 msg "ssl-opt.sh: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
5072 tests/ssl-opt.sh
Ronald Crone3dac4a2022-06-10 17:21:51 +02005073}
5074
Ronald Cron6f135e12021-12-08 16:57:54 +01005075component_test_tls13 () {
5076 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
5077 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005078 scripts/config.py set MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
5079 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
Ronald Cronc2e110f2022-11-22 09:01:46 +01005080 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005081 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
5082 make
Ronald Cron6f135e12021-12-08 16:57:54 +01005083 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005084 make test
Ronald Cron6f135e12021-12-08 16:57:54 +01005085 msg "ssl-opt.sh (TLS 1.3)"
Gilles Peskine827dbd92022-02-04 00:30:54 +01005086 tests/ssl-opt.sh
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005087}
5088
Ronald Cron6f135e12021-12-08 16:57:54 +01005089component_test_tls13_no_compatibility_mode () {
5090 msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
5091 scripts/config.py set MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005092 scripts/config.py unset MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
5093 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
Ronald Cronc2e110f2022-11-22 09:01:46 +01005094 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Hanno Beckera711f6e2020-05-04 12:03:51 +01005095 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
5096 make
Ronald Cron6f135e12021-12-08 16:57:54 +01005097 msg "test: default config with MBEDTLS_SSL_PROTO_TLS1_3 enabled, without padding"
Hanno Becker6c53ecc2021-08-01 19:20:10 +01005098 make test
Ronald Cron6f135e12021-12-08 16:57:54 +01005099 msg "ssl-opt.sh (TLS 1.3 no compatibility mode)"
Gilles Peskine827dbd92022-02-04 00:30:54 +01005100 tests/ssl-opt.sh
Hanno Becker6c53ecc2021-08-01 19:20:10 +01005101}
5102
Jan Bruckner151f6422023-02-10 12:45:19 +01005103component_test_tls13_only_record_size_limit () {
5104 msg "build: TLS 1.3 only from default, record size limit extension enabled"
5105 scripts/config.py set MBEDTLS_SSL_RECORD_SIZE_LIMIT
5106 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5107
5108 msg "test_suite_ssl: TLS 1.3 only, record size limit extension enabled"
5109 cd tests; ./test_suite_ssl; cd ..
5110
5111 msg "ssl-opt.sh: (TLS 1.3 only, record size limit extension tests only)"
5112 # Both the server and the client will currently abort the handshake when they encounter the
5113 # record size limit extension. There is no way to prevent gnutls-cli from sending the extension
5114 # which makes all G_NEXT_CLI + P_SRV tests fail. Thus, run only the tests for the this extension.
5115 tests/ssl-opt.sh -f "Record Size Limit"
5116}
5117
Gilles Peskine8f073122018-11-27 15:58:47 +01005118component_build_mingw () {
5119 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Jerry Yubdd96b92023-08-16 17:34:27 +08005120 scripts/config.py unset MBEDTLS_AESNI_C # AESNI depends on cpu modifiers
Andrzej Kurek232e8f92019-10-03 03:18:01 -04005121 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs
Hanno Beckere963efa2018-01-03 10:03:43 +00005122
Gilles Peskine8f073122018-11-27 15:58:47 +01005123 # note Make tests only builds the tests, but doesn't run them
Andrzej Kurek232e8f92019-10-03 03:18:01 -04005124 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests
Gilles Peskine8f073122018-11-27 15:58:47 +01005125 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02005126
Gilles Peskine8f073122018-11-27 15:58:47 +01005127 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04005128 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 lib programs
5129 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 tests
Gilles Peskine8f073122018-11-27 15:58:47 +01005130 make WINDOWS_BUILD=1 clean
5131}
Jaeden Amero117b8a42019-04-17 15:19:26 +01005132support_build_mingw() {
Pengyu Lv51b5f002023-02-24 15:38:52 +08005133 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
5134 [0-5]*|"") false;;
Jaeden Amero117b8a42019-04-17 15:19:26 +01005135 *) true;;
5136 esac
5137}
Simon Butcher91aef332016-11-17 09:20:50 +00005138
Gilles Peskine8f073122018-11-27 15:58:47 +01005139component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005140 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005141 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005142 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
5143 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02005144
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005145 msg "test: main suites (MSan)" # ~ 10s
5146 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005147
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005148 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005149 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005150
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005151 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005152
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005153 if [ "$MEMORY" -gt 0 ]; then
5154 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005155 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005156 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01005157}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005158
Gilles Peskine69f190e2019-01-10 00:11:42 +01005159component_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005160 msg "build: Release (clang)"
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005161 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005162 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
5163 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005164
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005165 msg "test: main suites, Valgrind (default config)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005166 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005167
Gilles Peskine636c26a2020-03-04 20:46:15 +01005168 # Optional parts (slow; currently broken on OS X because programs don't
5169 # seem to receive signals under valgrind on OS X).
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005170 # These optional parts don't run on the CI.
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005171 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005172 msg "test: ssl-opt.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005173 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005174 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005175
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005176 if [ "$MEMORY" -gt 1 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005177 msg "test: compat.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005178 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005179 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02005180
5181 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005182 msg "test: context-info.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005183 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02005184 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01005185}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005186
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005187component_test_valgrind_psa () {
5188 msg "build: Release, full (clang)"
5189 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
5190 scripts/config.py full
5191 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
5192 make
5193
5194 msg "test: main suites, Valgrind (full config)"
5195 make memcheck
5196}
5197
Paul Elliott62dc3922021-11-25 17:29:40 +00005198support_test_cmake_out_of_source () {
5199 distrib_id=""
5200 distrib_ver=""
5201 distrib_ver_minor=""
5202 distrib_ver_major=""
5203
5204 # Attempt to parse lsb-release to find out distribution and version. If not
5205 # found this should fail safe (test is supported).
5206 if [[ -f /etc/lsb-release ]]; then
5207
5208 while read -r lsb_line; do
5209 case "$lsb_line" in
5210 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
5211 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
5212 esac
5213 done < /etc/lsb-release
5214
5215 distrib_ver_major="${distrib_ver%%.*}"
5216 distrib_ver="${distrib_ver#*.}"
5217 distrib_ver_minor="${distrib_ver%%.*}"
5218 fi
5219
5220 # Running the out of source CMake test on Ubuntu 16.04 using more than one
5221 # processor (as the CI does) can create a race condition whereby the build
5222 # fails to see a generated file, despite that file actually having been
5223 # generated. This problem appears to go away with 18.04 or newer, so make
5224 # the out of source tests unsupported on Ubuntu 16.04.
5225 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
5226}
5227
Gilles Peskine8f073122018-11-27 15:58:47 +01005228component_test_cmake_out_of_source () {
David Horstmann862abe22023-09-28 10:42:10 +01005229 # Remove existing generated files so that we use the ones cmake
David Horstmann9f48fff2023-09-27 15:53:54 +01005230 # generates
5231 make neat
5232
Gilles Peskine8f073122018-11-27 15:58:47 +01005233 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01005234 MBEDTLS_ROOT_DIR="$PWD"
5235 mkdir "$OUT_OF_SOURCE_DIR"
5236 cd "$OUT_OF_SOURCE_DIR"
David Horstmann9f48fff2023-09-27 15:53:54 +01005237 # Note: Explicitly generate files as these are turned off in releases
5238 cmake -D CMAKE_BUILD_TYPE:String=Check -D GEN_FILES=ON "$MBEDTLS_ROOT_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01005239 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005240
Gilles Peskine8f073122018-11-27 15:58:47 +01005241 msg "test: cmake 'out-of-source' build"
5242 make test
Gilles Peskinea841c2a2022-04-16 11:31:25 +02005243 # Check that ssl-opt.sh can find the test programs.
Gilles Peskine8f073122018-11-27 15:58:47 +01005244 # Also ensure that there are no error messages such as
5245 # "No such file or directory", which would indicate that some required
5246 # file is missing (ssl-opt.sh tolerates the absence of some files so
5247 # may exit with status 0 but emit errors).
Gilles Peskinea841c2a2022-04-16 11:31:25 +02005248 ./tests/ssl-opt.sh -f 'Default' >ssl-opt.out 2>ssl-opt.err
Gilles Peskine7393ec52022-04-15 22:43:38 +02005249 grep PASS ssl-opt.out
Gilles Peskinef7e956c2020-03-28 18:56:09 +01005250 cat ssl-opt.err >&2
5251 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005252 [ ! -s ssl-opt.err ]
Gilles Peskine7393ec52022-04-15 22:43:38 +02005253 rm ssl-opt.out ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01005254 cd "$MBEDTLS_ROOT_DIR"
5255 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01005256}
Andres AGdc192212016-08-31 17:33:13 +01005257
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005258component_test_cmake_as_subdirectory () {
David Horstmann9f48fff2023-09-27 15:53:54 +01005259 # Remove existing generated files so that we use the ones CMake
5260 # generates
5261 make neat
5262
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005263 msg "build: cmake 'as-subdirectory' build"
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005264 cd programs/test/cmake_subproject
David Horstmann9f48fff2023-09-27 15:53:54 +01005265 # Note: Explicitly generate files as these are turned off in releases
5266 cmake -D GEN_FILES=ON .
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005267 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005268 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005269}
Gilles Peskinea3000992022-02-04 00:21:12 +01005270support_test_cmake_as_subdirectory () {
5271 support_test_cmake_out_of_source
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005272}
5273
Chris Kayd259e342021-03-25 16:03:25 +00005274component_test_cmake_as_package () {
David Horstmann6c979852023-09-28 10:40:22 +01005275 # Remove existing generated files so that we use the ones CMake
5276 # generates
5277 make neat
5278
Chris Kayd259e342021-03-25 16:03:25 +00005279 msg "build: cmake 'as-package' build"
Chris Kayd259e342021-03-25 16:03:25 +00005280 cd programs/test/cmake_package
5281 cmake .
5282 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005283 ./cmake_package
Chris Kayd259e342021-03-25 16:03:25 +00005284}
Gilles Peskinea3000992022-02-04 00:21:12 +01005285support_test_cmake_as_package () {
5286 support_test_cmake_out_of_source
Chris Kayd259e342021-03-25 16:03:25 +00005287}
5288
5289component_test_cmake_as_package_install () {
David Horstmann6c979852023-09-28 10:40:22 +01005290 # Remove existing generated files so that we use the ones CMake
5291 # generates
5292 make neat
5293
Chris Kayd259e342021-03-25 16:03:25 +00005294 msg "build: cmake 'as-installed-package' build"
Chris Kayd259e342021-03-25 16:03:25 +00005295 cd programs/test/cmake_package_install
5296 cmake .
5297 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005298 ./cmake_package_install
Chris Kayd259e342021-03-25 16:03:25 +00005299}
Gilles Peskinea3000992022-02-04 00:21:12 +01005300support_test_cmake_as_package_install () {
5301 support_test_cmake_out_of_source
Chris Kayd259e342021-03-25 16:03:25 +00005302}
5303
David Horstmann20550e32023-01-12 14:17:01 +00005304component_build_cmake_custom_config_file () {
David Horstmann969c1452023-01-31 10:34:44 +00005305 # Make a copy of config file to use for the in-tree test
5306 cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h
David Horstmann20550e32023-01-12 14:17:01 +00005307
5308 MBEDTLS_ROOT_DIR="$PWD"
5309 mkdir "$OUT_OF_SOURCE_DIR"
5310 cd "$OUT_OF_SOURCE_DIR"
5311
David Horstmann969c1452023-01-31 10:34:44 +00005312 # Build once to get the generated files (which need an intact config file)
David Horstmann20550e32023-01-12 14:17:01 +00005313 cmake "$MBEDTLS_ROOT_DIR"
5314 make
5315
5316 msg "build: cmake with -DMBEDTLS_CONFIG_FILE"
5317 scripts/config.py -w full_config.h full
David Horstmann969c1452023-01-31 10:34:44 +00005318 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005319 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR"
5320 make
5321
5322 msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
5323 # In the user config, disable one feature (for simplicity, pick a feature
5324 # that nothing else depends on).
5325 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
5326
5327 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR"
5328 make
5329 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5330
5331 rm -f user_config.h full_config.h
5332
5333 cd "$MBEDTLS_ROOT_DIR"
5334 rm -rf "$OUT_OF_SOURCE_DIR"
5335
5336 # Now repeat the test for an in-tree build:
5337
David Horstmann969c1452023-01-31 10:34:44 +00005338 # Restore config for the in-tree test
5339 mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005340
David Horstmann969c1452023-01-31 10:34:44 +00005341 # Build once to get the generated files (which need an intact config)
David Horstmann20550e32023-01-12 14:17:01 +00005342 cmake .
5343 make
5344
5345 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE"
5346 scripts/config.py -w full_config.h full
David Horstmann969c1452023-01-31 10:34:44 +00005347 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00005348 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h .
5349 make
5350
5351 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
5352 # In the user config, disable one feature (for simplicity, pick a feature
5353 # that nothing else depends on).
5354 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
5355
5356 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h .
5357 make
5358 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5359
5360 rm -f user_config.h full_config.h
5361}
5362support_build_cmake_custom_config_file () {
5363 support_test_cmake_out_of_source
5364}
5365
5366
Tom Cosgrovedaddf112023-09-01 10:40:15 +01005367component_build_zeroize_checks () {
5368 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
5369
5370 scripts/config.py full
5371
5372 # Only compile - we're looking for sizeof-pointer-memaccess warnings
Tom Cosgroveb2fafa52023-09-01 14:40:21 +01005373 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 +01005374}
5375
5376
Gilles Peskine8f073122018-11-27 15:58:47 +01005377component_test_zeroize () {
5378 # Test that the function mbedtls_platform_zeroize() is not optimized away by
5379 # different combinations of compilers and optimization flags by using an
5380 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
5381 # system in all cases that the script fails, so we must manually search the
5382 # output to check whether the pass string is present and no failure strings
5383 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01005384
Gilles Peskine4976e822019-01-06 19:52:22 +00005385 # Don't try to disable ASLR. We don't care about ASLR here. We do care
5386 # about a spurious message if Gdb tries and fails, so suppress that.
5387 gdb_disable_aslr=
5388 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
5389 gdb_disable_aslr='set disable-randomization off'
5390 fi
5391
Gilles Peskine8f073122018-11-27 15:58:47 +01005392 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01005393 for compiler in clang gcc; do
5394 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
5395 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005396 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
5397 grep "The buffer was correctly zeroized" test_zeroize.log
5398 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01005399 rm -f test_zeroize.log
5400 make clean
5401 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01005402 done
Gilles Peskine8f073122018-11-27 15:58:47 +01005403}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005404
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005405component_test_psa_compliance () {
5406 msg "build: make, default config (out-of-box), libmbedcrypto.a only"
Bence Szépkútica9236b2021-10-25 19:29:07 +02005407 make -C library libmbedcrypto.a
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005408
5409 msg "unit test: test_psa_compliance.py"
5410 ./tests/scripts/test_psa_compliance.py
5411}
5412
5413support_test_psa_compliance () {
Bence Szépkútief0d02e2021-11-03 11:36:09 +01005414 # psa-compliance-tests only supports CMake >= 3.10.0
Bence Szépkútica9236b2021-10-25 19:29:07 +02005415 ver="$(cmake --version)"
5416 ver="${ver#cmake version }"
5417 ver_major="${ver%%.*}"
5418
5419 ver="${ver#*.}"
5420 ver_minor="${ver%%.*}"
5421
5422 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
Bence Szépkúti80b31c52021-10-19 15:05:36 +02005423}
5424
Gilles Peskinec848d222022-12-09 12:23:35 +01005425component_check_code_style () {
5426 msg "Check C code style"
5427 ./scripts/code_style.py
David Horstmann92b5ac12022-11-10 18:30:52 +00005428}
5429
Gilles Peskinec848d222022-12-09 12:23:35 +01005430support_check_code_style() {
David Horstmann92b5ac12022-11-10 18:30:52 +00005431 case $(uncrustify --version) in
5432 *0.75.1*) true;;
5433 *) false;;
5434 esac
5435}
5436
Gilles Peskine8f073122018-11-27 15:58:47 +01005437component_check_python_files () {
5438 msg "Lint: Python scripts"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005439 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01005440}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005441
Joe Subbianid614c0b2021-07-29 11:18:29 +01005442component_check_test_helpers () {
5443 msg "unit test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02005444 # unittest writes out mundane stuff like number or tests run on stderr.
5445 # Our convention is to reserve stderr for actual errors, and write
5446 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005447 ./tests/scripts/test_generate_test_code.py 2>&1
Joe Subbianid614c0b2021-07-29 11:18:29 +01005448
Joe Subbiania25ffab2021-08-06 09:41:27 +01005449 msg "unit test: translate_ciphers.py"
5450 python3 -m unittest tests/scripts/translate_ciphers.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01005451}
Gilles Peskine192c72f2017-12-21 15:59:21 +01005452
Jerry Yud767cc42023-03-31 15:03:55 +08005453
Gilles Peskine192c72f2017-12-21 15:59:21 +01005454################################################################
5455#### Termination
5456################################################################
5457
Gilles Peskine8f073122018-11-27 15:58:47 +01005458post_report () {
5459 msg "Done, cleaning up"
Gilles Peskinef83eb822020-03-30 20:11:39 +02005460 final_cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005461
Gilles Peskine8f073122018-11-27 15:58:47 +01005462 final_report
5463}
5464
5465
5466
5467################################################################
5468#### Run all the things
5469################################################################
5470
Gilles Peskine5d996822020-03-28 21:09:21 +01005471# Function invoked by --error-test to test error reporting.
5472pseudo_component_error_test () {
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005473 msg "Testing error reporting $error_test_i"
Gilles Peskine5d996822020-03-28 21:09:21 +01005474 if [ $KEEP_GOING -ne 0 ]; then
5475 echo "Expect three failing commands."
5476 fi
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005477 # If the component doesn't run in a subshell, changing error_test_i to an
5478 # invalid integer will cause an error in the loop that runs this function.
5479 error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
Gilles Peskineec135542021-08-02 23:14:03 +02005480 # Expected error: 'grep non_existent /dev/null -> 1'
Gilles Peskine5d996822020-03-28 21:09:21 +01005481 grep non_existent /dev/null
Gilles Peskineec135542021-08-02 23:14:03 +02005482 # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
Gilles Peskine5d996822020-03-28 21:09:21 +01005483 not grep -q . "$0"
Gilles Peskineec135542021-08-02 23:14:03 +02005484 # Expected error: 'make unknown_target -> 2'
Gilles Peskine5d996822020-03-28 21:09:21 +01005485 make unknown_target
5486 false "this should not be executed"
5487}
5488
Gilles Peskinee48351a2018-11-27 16:06:30 +01005489# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01005490run_component () {
Gilles Peskineffcdeff2018-12-04 12:49:28 +01005491 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02005492 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005493
5494 # Unconditionally create a seedfile that's sufficiently long.
5495 # Do this before each component, because a previous component may
5496 # have messed it up or shortened it.
Gilles Peskine88a07452021-07-08 19:03:50 +02005497 local dd_cmd
5498 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
5499 case $OSTYPE in
Tom Cosgrove226aca12022-03-16 14:11:07 +00005500 linux*|freebsd*|openbsd*) dd_cmd+=(status=none)
Gilles Peskine88a07452021-07-08 19:03:50 +02005501 esac
5502 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005503
Gilles Peskineec135542021-08-02 23:14:03 +02005504 # Run the component in a subshell, with error trapping and output
5505 # redirection set up based on the relevant options.
Gilles Peskinece266c42020-03-28 18:50:43 +01005506 if [ $KEEP_GOING -eq 1 ]; then
Gilles Peskineec135542021-08-02 23:14:03 +02005507 # We want to keep running if the subshell fails, so 'set -e' must
5508 # be off when the subshell runs.
Gilles Peskinece266c42020-03-28 18:50:43 +01005509 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02005510 fi
Gilles Peskinece266c42020-03-28 18:50:43 +01005511 (
5512 if [ $QUIET -eq 1 ]; then
5513 # msg() will be silenced, so just print the component name here.
5514 echo "${current_component#component_}"
5515 exec >/dev/null
5516 fi
5517 if [ $KEEP_GOING -eq 1 ]; then
5518 # Keep "set -e" off, and run an ERR trap instead to record failures.
5519 set -E
5520 trap err_trap ERR
5521 fi
5522 # The next line is what runs the component
5523 "$@"
5524 if [ $KEEP_GOING -eq 1 ]; then
5525 trap - ERR
5526 exit $last_failure_status
5527 fi
5528 )
5529 component_status=$?
5530 if [ $KEEP_GOING -eq 1 ]; then
5531 set -e
5532 if [ $component_status -ne 0 ]; then
5533 failure_count=$((failure_count + 1))
5534 fi
5535 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02005536
5537 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01005538 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02005539 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01005540}
5541
5542# Preliminary setup
5543pre_check_environment
Tom Cosgrove730addc2023-06-09 14:20:18 +01005544pre_parse_command_line_for_dirs "$@"
Gilles Peskine8f073122018-11-27 15:58:47 +01005545pre_initialize_variables
5546pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01005547
Gilles Peskine878cf602019-01-06 20:50:38 +00005548pre_check_git
Gilles Peskine568f53a2021-07-12 18:16:01 +02005549pre_restore_files
Gilles Peskinef83eb822020-03-30 20:11:39 +02005550pre_back_up
Andrzej Kurekeb508712019-02-14 07:18:59 -05005551
Gilles Peskine878cf602019-01-06 20:50:38 +00005552build_status=0
5553if [ $KEEP_GOING -eq 1 ]; then
5554 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01005555fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02005556pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00005557pre_print_configuration
5558pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005559cleanup
David Horstmann76a77382023-08-17 17:32:26 +01005560if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +01005561 pre_generate_files
5562fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005563
Gilles Peskinebeb3a812019-01-06 22:11:25 +00005564# Run the requested tests.
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005565for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
Gilles Peskine5d996822020-03-28 21:09:21 +01005566 run_component pseudo_component_error_test
Gilles Peskine5d996822020-03-28 21:09:21 +01005567done
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02005568unset error_test_i
Gilles Peskinebeb3a812019-01-06 22:11:25 +00005569for component in $RUN_COMPONENTS; do
5570 run_component "component_$component"
5571done
Gilles Peskine8f073122018-11-27 15:58:47 +01005572
5573# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00005574post_report