blob: 66150725b1275717ea4b57217d3168b886e03f55 [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 Rodgman16799db2023-11-02 19:47:20 +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 Peskine7be571a2023-08-27 21:39:21 +020041# * OpenSSL and GnuTLS command line tools, in suitable versions for the
42# interoperability tests. The following are the official versions at the
43# time of writing:
44# * GNUTLS_{CLI,SERV} = 3.4.10
45# * GNUTLS_NEXT_{CLI,SERV} = 3.7.2
46# * OPENSSL = 1.0.2g (without Debian/Ubuntu patches)
Ronald Cronc5e81d22024-04-02 14:39:53 +020047# * OPENSSL_NEXT = 3.1.2
Gilles Peskine192c72f2017-12-21 15:59:21 +010048# See the invocation of check_tools below for details.
49#
50# This script must be invoked from the toplevel directory of a git
51# working copy of Mbed TLS.
52#
Gilles Peskinece266c42020-03-28 18:50:43 +010053# The behavior on an error depends on whether --keep-going (alias -k)
54# is in effect.
55# * Without --keep-going: the script stops on the first error without
56# cleaning up. This lets you work in the configuration of the failing
57# component.
58# * With --keep-going: the script runs all requested components and
59# reports failures at the end. In particular the script always cleans
60# up on exit.
61#
Gilles Peskine192c72f2017-12-21 15:59:21 +010062# Note that the output is not saved. You may want to run
63# script -c tests/scripts/all.sh
64# or
65# tests/scripts/all.sh >all.log 2>&1
66#
67# Notes for maintainers
68# ---------------------
69#
Gilles Peskine8f073122018-11-27 15:58:47 +010070# The bulk of the code is organized into functions that follow one of the
71# following naming conventions:
72# * pre_XXX: things to do before running the tests, in order.
73# * component_XXX: independent components. They can be run in any order.
Gilles Peskinec70637a2019-01-09 22:29:17 +010074# * component_check_XXX: quick tests that aren't worth parallelizing.
75# * component_build_XXX: build things but don't run them.
76# * component_test_XXX: build and test.
Bence Szépkúti89dd5c02023-12-15 17:05:15 +010077# * component_release_XXX: tests that the CI should skip during PR testing.
Gilles Peskine878cf602019-01-06 20:50:38 +000078# * support_XXX: if support_XXX exists and returns false then
79# component_XXX is not run by default.
Gilles Peskine8f073122018-11-27 15:58:47 +010080# * post_XXX: things to do after running the tests.
81# * other: miscellaneous support functions.
82#
Gilles Peskinec70637a2019-01-09 22:29:17 +010083# Each component must start by invoking `msg` with a short informative message.
84#
Gilles Peskinea681c592020-03-28 21:27:40 +010085# Warning: due to the way bash detects errors, the failure of a command
86# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
87#
Gilles Peskinece266c42020-03-28 18:50:43 +010088# Each component is executed in a separate shell process. The component
89# fails if any command in it returns a non-zero status.
90#
Gilles Peskinec70637a2019-01-09 22:29:17 +010091# The framework performs some cleanup tasks after each component. This
92# means that components can assume that the working directory is in a
93# cleaned-up state, and don't need to perform the cleanup themselves.
94# * Run `make clean`.
Bence Szépkúti414d6bd2021-06-28 14:11:11 +010095# * Restore `include/mbedtls/mbedtls_config.h` from a backup made before running
Gilles Peskinec70637a2019-01-09 22:29:17 +010096# the component.
Gilles Peskine636c26a2020-03-04 20:46:15 +010097# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
98# `tests/Makefile` and `programs/fuzz/Makefile` from git.
99# This cleans up after an in-tree use of CMake.
Gilles Peskinec70637a2019-01-09 22:29:17 +0100100#
Gilles Peskine192c72f2017-12-21 15:59:21 +0100101# The tests are roughly in order from fastest to slowest. This doesn't
102# have to be exact, but in general you should add slower tests towards
103# the end and fast checks near the beginning.
Gilles Peskine192c72f2017-12-21 15:59:21 +0100104
105
106
107################################################################
108#### Initialization and command line parsing
109################################################################
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100110
Gilles Peskine36647802020-03-28 18:50:49 +0100111# Abort on errors (even on the left-hand side of a pipe).
112# Treat uninitialised variables as errors.
113set -e -o pipefail -u
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100114
Gilles Peskine076f7252022-08-30 21:02:44 +0200115# Enable ksh/bash extended file matching patterns
116shopt -s extglob
117
David Horstmann76a77382023-08-17 17:32:26 +0100118in_mbedtls_repo () {
David Horstmannd02b5f82023-08-29 09:53:52 +0100119 test -d include -a -d library -a -d programs -a -d tests
120}
121
Ronald Cron070e8652023-10-09 10:25:45 +0200122in_tf_psa_crypto_repo () {
David Horstmannd02b5f82023-08-29 09:53:52 +0100123 test -d include -a -d core -a -d drivers -a -d programs -a -d tests
David Horstmann9a6c45b2023-07-14 12:30:00 +0100124}
125
Gilles Peskine8f073122018-11-27 15:58:47 +0100126pre_check_environment () {
Ronald Cron070e8652023-10-09 10:25:45 +0200127 if in_mbedtls_repo || in_tf_psa_crypto_repo; then :; else
128 echo "Must be run from Mbed TLS / TF-PSA-Crypto root" >&2
Gilles Peskine8f073122018-11-27 15:58:47 +0100129 exit 1
130 fi
131}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100132
Gilles Peskine8f073122018-11-27 15:58:47 +0100133pre_initialize_variables () {
David Horstmann76a77382023-08-17 17:32:26 +0100134 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100135 CONFIG_H='include/mbedtls/mbedtls_config.h'
David Horstmann76a77382023-08-17 17:32:26 +0100136 else
137 CONFIG_H='drivers/builtin/include/mbedtls/mbedtls_config.h'
David Horstmann9a6c45b2023-07-14 12:30:00 +0100138 fi
John Durkopbd069d32020-10-31 22:14:03 -0700139 CRYPTO_CONFIG_H='include/psa/crypto_config.h'
Manuel Pégourié-Gonnard462e3a92022-12-27 12:35:11 +0100140 CONFIG_TEST_DRIVER_H='tests/include/test/drivers/config_test_driver.h'
Gilles Peskinef83eb822020-03-30 20:11:39 +0200141
142 # Files that are clobbered by some jobs will be backed up. Use a different
143 # suffix from auxiliary scripts so that all.sh and auxiliary scripts can
144 # independently decide when to remove the backup file.
145 backup_suffix='.all.bak'
146 # Files clobbered by config.py
Janos Follath2f045822023-07-31 10:57:16 +0100147 files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H $CONFIG_TEST_DRIVER_H"
David Horstmann76a77382023-08-17 17:32:26 +0100148 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100149 # Files clobbered by in-tree cmake
150 files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile"
151 fi
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200152
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200153 append_outcome=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100154 MEMORY=0
155 FORCE=0
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200156 QUIET=0
Gilles Peskine8f073122018-11-27 15:58:47 +0100157 KEEP_GOING=0
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100158
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200159 # Seed value used with the --release-test option.
Manuel Pégourié-Gonnard54304472020-06-22 10:11:47 +0200160 #
161 # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
162 # both values are kept in sync. If you change the value here because it
163 # breaks some tests, you'll definitely want to change it in
164 # basic-build-test.sh as well.
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200165 RELEASE_SEED=1
166
Yanray Wang18040ed2023-11-23 21:29:56 +0800167 # Specify character collation for regular expressions and sorting with C locale
168 export LC_COLLATE=C
169
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200170 : ${MBEDTLS_TEST_OUTCOME_FILE=}
Gilles Peskine9004a172019-09-16 15:20:36 +0200171 : ${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 +0200172 export MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine9004a172019-09-16 15:20:36 +0200173 export MBEDTLS_TEST_PLATFORM
174
Jaeden Ameroc4cc2512019-01-30 15:35:44 +0000175 # Default commands, can be overridden by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100176 : ${OPENSSL:="openssl"}
Gilles Peskine8f073122018-11-27 15:58:47 +0100177 : ${OPENSSL_NEXT:="$OPENSSL"}
178 : ${GNUTLS_CLI:="gnutls-cli"}
179 : ${GNUTLS_SERV:="gnutls-serv"}
Gilles Peskine8f073122018-11-27 15:58:47 +0100180 : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
181 : ${ARMC5_BIN_DIR:=/usr/bin}
182 : ${ARMC6_BIN_DIR:=/usr/bin}
Gilles Peskine6d061342020-04-30 18:19:32 +0200183 : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +0200184 : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
Gowtham Suresh Kumar9da40b82023-07-31 16:38:10 +0100185 : ${CLANG_LATEST:="clang-latest"}
186 : ${CLANG_EARLIEST:="clang-earliest"}
187 : ${GCC_LATEST:="gcc-latest"}
188 : ${GCC_EARLIEST:="gcc-earliest"}
Gilles Peskine8f073122018-11-27 15:58:47 +0100189 # if MAKEFLAGS is not set add the -j option to speed up invocations of make
Gilles Peskinea1fc4b52019-01-06 20:15:26 +0000190 if [ -z "${MAKEFLAGS+set}" ]; then
Gilles Peskine050d2fc2021-09-30 18:24:21 +0200191 export MAKEFLAGS="-j$(all_sh_nproc)"
Gilles Peskine8f073122018-11-27 15:58:47 +0100192 fi
Dave Rodgman0c5bfe82023-12-18 19:53:25 +0000193 # if CC is not set, use clang by default (if present) to improve build times
194 if [ -z "${CC+set}" ] && (type clang > /dev/null 2>&1); then
Dave Rodgmanfc5b9552023-12-19 16:08:19 +0000195 export CC="clang"
Dave Rodgman66cbc832023-12-18 18:34:50 +0000196 fi
Gilles Peskine878cf602019-01-06 20:50:38 +0000197
Ronald Cronc5e81d22024-04-02 14:39:53 +0200198 if [ -n "${OPENSSL_3+set}" ]; then
199 export OPENSSL_NEXT="$OPENSSL_3"
200 fi
201
Gilles Peskine396853a2021-09-20 18:57:55 +0200202 # Include more verbose output for failing tests run by CMake or make
Jaeden Amerod48e9c72019-02-07 17:43:39 +0000203 export CTEST_OUTPUT_ON_FAILURE=1
204
Gilles Peskine8fd59422019-10-21 17:11:33 +0200205 # CFLAGS and LDFLAGS for Asan builds that don't use CMake
Manuel Pégourié-Gonnardfe549a72022-11-30 10:42:03 +0100206 # default to -O2, use -Ox _after_ this if you want another level
Przemek Stekiel6efa6082023-05-31 09:38:21 +0200207 ASAN_CFLAGS='-O2 -Werror -fsanitize=address,undefined -fno-sanitize-recover=all'
Dave Rodgman17127e92023-12-14 16:42:48 +0000208 # Normally, tests should use this compiler for ASAN testing
209 ASAN_CC=clang
Gilles Peskine8fd59422019-10-21 17:11:33 +0200210
Andrzej Kurek04bfe572023-06-27 10:02:09 -0400211 # Platform tests have an allocation that returns null
212 export ASAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurek026235c2023-07-05 08:32:43 -0400213 export MSAN_OPTIONS="allocator_may_return_null=1"
Andrzej Kurek04bfe572023-06-27 10:02:09 -0400214
Gilles Peskine878cf602019-01-06 20:50:38 +0000215 # Gather the list of available components. These are the functions
216 # defined in this script whose name starts with "component_".
Gowtham Suresh Kumar1e829a42023-07-28 16:41:21 +0100217 ALL_COMPONENTS=$(compgen -A function component_ | sed 's/component_//')
Gilles Peskine878cf602019-01-06 20:50:38 +0000218
Dave Rodgman5f8e2a22024-01-16 17:33:34 +0000219 # Delay determining SUPPORTED_COMPONENTS until the command line options have a chance to override
Bence Szépkúti71c71eb2023-12-15 19:20:31 +0100220 # the commands set by the environment
Gilles Peskine8f073122018-11-27 15:58:47 +0100221}
Andres AG38495a32016-07-12 16:54:33 +0100222
Dave Rodgman21900632024-02-26 11:41:19 +0000223setup_quiet_wrappers()
224{
225 # Pick up "quiet" wrappers for make and cmake, which don't output very much
226 # unless there is an error. This reduces logging overhead in the CI.
227 #
228 # Note that the cmake wrapper breaks unless we use an absolute path here.
Dave Rodgmana9e8dbe2024-02-26 17:27:18 +0000229 if [[ -e ${PWD}/tests/scripts/quiet ]]; then
230 export PATH=${PWD}/tests/scripts/quiet:$PATH
Dave Rodgman21900632024-02-26 11:41:19 +0000231 fi
232}
233
Gilles Peskinea28db922019-01-10 00:05:18 +0100234# Test whether the component $1 is included in the command line patterns.
235is_component_included()
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100236{
Gilles Peskine03af6782021-08-06 11:35:17 +0200237 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
238 # only does word splitting.
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100239 set -f
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000240 for pattern in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine81b96ed2018-11-27 21:37:53 +0100241 set +f
242 case ${1#component_} in $pattern) return 0;; esac
243 done
244 set +f
245 return 1
246}
Andres AG7770ea82016-10-10 15:46:20 +0100247
Simon Butcher41eeccf2016-09-07 00:07:09 +0100248usage()
Andres AGd9eba4b2016-08-26 14:42:14 +0100249{
Gilles Peskine709346a2017-12-10 23:43:39 +0100250 cat <<EOF
Gilles Peskine92525112018-11-27 18:15:35 +0100251Usage: $0 [OPTION]... [COMPONENT]...
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100252Run mbedtls release validation tests.
Gilles Peskine92525112018-11-27 18:15:35 +0100253By default, run all tests. With one or more COMPONENT, run only those.
Gilles Peskinea28db922019-01-10 00:05:18 +0100254COMPONENT can be the name of a component or a shell wildcard pattern.
255
256Examples:
257 $0 "check_*"
258 Run all sanity checks.
259 $0 --no-armcc --except test_memsan
260 Run everything except builds that require armcc and MemSan.
Gilles Peskine348fb9a2018-11-27 17:04:29 +0100261
262Special options:
263 -h|--help Print this help and exit.
Gilles Peskine878cf602019-01-06 20:50:38 +0000264 --list-all-components List all available test components and exit.
265 --list-components List components supported on this platform and exit.
Gilles Peskine709346a2017-12-10 23:43:39 +0100266
267General options:
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200268 -q|--quiet Only output component names, and errors if any.
Gilles Peskine709346a2017-12-10 23:43:39 +0100269 -f|--force Force the tests to overwrite any modified files.
Gilles Peskine7c652162017-12-11 00:01:40 +0100270 -k|--keep-going Run all tests and report errors at the end.
Gilles Peskine709346a2017-12-10 23:43:39 +0100271 -m|--memory Additional optional memory tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200272 --append-outcome Append to the outcome file (if used).
Gilles Peskine6d061342020-04-30 18:19:32 +0200273 --arm-none-eabi-gcc-prefix=<string>
274 Prefix for a cross-compiler for arm-none-eabi
275 (default: "${ARM_NONE_EABI_GCC_PREFIX}")
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +0200276 --arm-linux-gnueabi-gcc-prefix=<string>
277 Prefix for a cross-compiler for arm-linux-gnueabi
278 (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100279 --armcc Run ARM Compiler builds (on by default).
Gilles Peskine80ddb992021-08-06 11:51:59 +0200280 --restore First clean up the build tree, restoring backed up
281 files. Do not run any components unless they are
282 explicitly specified.
Gilles Peskine5d996822020-03-28 21:09:21 +0100283 --error-test Error test mode: run a failing function in addition
Gilles Peskine86f61292021-08-05 15:11:33 +0200284 to any specified component. May be repeated.
Gilles Peskinea28db922019-01-10 00:05:18 +0100285 --except Exclude the COMPONENTs listed on the command line,
286 instead of running only those.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200287 --no-append-outcome Write a new outcome file and analyze it (default).
Gilles Peskinebca6ab92017-12-19 18:24:31 +0100288 --no-armcc Skip ARM Compiler builds.
Gilles Peskine38d81652018-03-21 08:40:26 +0100289 --no-force Refuse to overwrite modified files (default).
290 --no-keep-going Stop at the first error (default).
291 --no-memory No additional memory tests (default).
Shaun Case8b0ecbc2021-12-20 21:14:10 -0800292 --no-quiet Print full output from components.
Gilles Peskine709346a2017-12-10 23:43:39 +0100293 --out-of-source-dir=<path> Directory used for CMake out-of-source build tests.
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200294 --outcome-file=<path> File where test outcomes are written (not done if
295 empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
Gilles Peskine38d81652018-03-21 08:40:26 +0100296 --random-seed Use a random seed value for randomized tests (default).
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200297 -r|--release-test Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
Gilles Peskine709346a2017-12-10 23:43:39 +0100298 -s|--seed Integer seed value to use for this test run.
299
300Tool path options:
301 --armc5-bin-dir=<ARMC5_bin_dir_path> ARM Compiler 5 bin directory.
302 --armc6-bin-dir=<ARMC6_bin_dir_path> ARM Compiler 6 bin directory.
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +0100303 --clang-earliest=<Clang_earliest_path> Earliest version of clang available
304 --clang-latest=<Clang_latest_path> Latest version of clang available
305 --gcc-earliest=<GCC_earliest_path> Earliest version of GCC available
306 --gcc-latest=<GCC_latest_path> Latest version of GCC available
Gilles Peskine709346a2017-12-10 23:43:39 +0100307 --gnutls-cli=<GnuTLS_cli_path> GnuTLS client executable to use for most tests.
308 --gnutls-serv=<GnuTLS_serv_path> GnuTLS server executable to use for most tests.
Gilles Peskine709346a2017-12-10 23:43:39 +0100309 --openssl=<OpenSSL_path> OpenSSL executable to use for most tests.
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +0100310 --openssl-next=<OpenSSL_path> OpenSSL executable to use for recent things like ARIA
Gilles Peskine709346a2017-12-10 23:43:39 +0100311EOF
SimonB2e23c822016-04-16 21:54:39 +0100312}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100313
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200314# Cleanup before/after running a component.
315# Remove built files as well as the cmake cache/config.
316# Does not remove generated source files.
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100317cleanup()
318{
David Horstmann76a77382023-08-17 17:32:26 +0100319 if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100320 command make clean
321 fi
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200322
Gilles Peskine31b07e22018-03-21 12:15:06 +0100323 # Remove CMake artefacts
Jaeden Amero2d0e00f2018-11-07 18:46:41 +0000324 find . -name .git -prune -o \
Gilles Peskine31b07e22018-03-21 12:15:06 +0100325 -iname CMakeFiles -exec rm -rf {} \+ -o \
326 \( -iname cmake_install.cmake -o \
327 -iname CTestTestfile.cmake -o \
Manuel Pégourié-Gonnardbfe54d72021-09-09 11:11:44 +0200328 -iname CMakeCache.txt -o \
329 -path './cmake/*.cmake' \) -exec rm -f {} \+
Gilles Peskine31b07e22018-03-21 12:15:06 +0100330 # Recover files overwritten by in-tree CMake builds
Gilles Peskine076f7252022-08-30 21:02:44 +0200331 rm -f include/Makefile include/mbedtls/Makefile programs/!(fuzz)/Makefile
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200332
Jaeden Ameroab83fdf2019-06-20 17:38:22 +0100333 # Remove any artifacts from the component_test_cmake_as_subdirectory test.
334 rm -rf programs/test/cmake_subproject/build
335 rm -f programs/test/cmake_subproject/Makefile
336 rm -f programs/test/cmake_subproject/cmake_subproject
337
Chris Kayd259e342021-03-25 16:03:25 +0000338 # Remove any artifacts from the component_test_cmake_as_package test.
339 rm -rf programs/test/cmake_package/build
340 rm -f programs/test/cmake_package/Makefile
341 rm -f programs/test/cmake_package/cmake_package
342
343 # Remove any artifacts from the component_test_cmake_as_installed_package test.
344 rm -rf programs/test/cmake_package_install/build
345 rm -f programs/test/cmake_package_install/Makefile
346 rm -f programs/test/cmake_package_install/cmake_package_install
347
Gilles Peskinef83eb822020-03-30 20:11:39 +0200348 # Restore files that may have been clobbered by the job
349 for x in $files_to_back_up; do
Gilles Peskinedd06efb2022-08-30 21:02:00 +0200350 if [[ -e "$x$backup_suffix" ]]; then
351 cp -p "$x$backup_suffix" "$x"
352 fi
Gilles Peskinef83eb822020-03-30 20:11:39 +0200353 done
354}
John Durkopbd069d32020-10-31 22:14:03 -0700355
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200356# Final cleanup when this script exits (except when exiting on a failure
357# in non-keep-going mode).
Gilles Peskinef83eb822020-03-30 20:11:39 +0200358final_cleanup () {
359 cleanup
360
361 for x in $files_to_back_up; do
362 rm -f "$x$backup_suffix"
363 done
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100364}
365
Gilles Peskine7c652162017-12-11 00:01:40 +0100366# Executed on exit. May be redefined depending on command line options.
367final_report () {
368 :
369}
370
371fatal_signal () {
Gilles Peskinef83eb822020-03-30 20:11:39 +0200372 final_cleanup
Gilles Peskine7c652162017-12-11 00:01:40 +0100373 final_report $1
374 trap - $1
375 kill -$1 $$
376}
377
378trap 'fatal_signal HUP' HUP
379trap 'fatal_signal INT' INT
380trap 'fatal_signal TERM' TERM
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +0200381
Gilles Peskine050d2fc2021-09-30 18:24:21 +0200382# Number of processors on this machine. Used as the default setting
383# for parallel make.
384all_sh_nproc ()
385{
386 {
387 nproc || # Linux
388 sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
389 sysctl -n hw.ncpu || # FreeBSD
390 echo 1
391 } 2>/dev/null
392}
393
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100394msg()
395{
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100396 if [ -n "${current_component:-}" ]; then
397 current_section="${current_component#component_}: $1"
398 else
399 current_section="$1"
400 fi
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200401
402 if [ $QUIET -eq 1 ]; then
403 return
404 fi
405
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100406 echo ""
407 echo "******************************************************************"
Gilles Peskineffcdeff2018-12-04 12:49:28 +0100408 echo "* $current_section "
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +0000409 printf "* "; date
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +0100410 echo "******************************************************************"
411}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +0100412
Gilles Peskine8f073122018-11-27 15:58:47 +0100413armc6_build_test()
414{
415 FLAGS="$1"
Andres AGa5cd9732016-10-17 15:23:10 +0100416
Gilles Peskine18487f62020-04-30 23:11:54 +0200417 msg "build: ARM Compiler 6 ($FLAGS)"
Yanray Wangbc7716c2023-09-08 11:20:59 +0800418 make clean
Gilles Peskine8f073122018-11-27 15:58:47 +0100419 ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
Dave Rodgman1c232a82023-03-02 13:39:04 +0000420 WARNING_CFLAGS='-Werror -xc -std=c99' make lib
Gilles Peskine18487f62020-04-30 23:11:54 +0200421
422 msg "size: ARM Compiler 6 ($FLAGS)"
423 "$ARMC6_FROMELF" -z library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +0100424}
Andres AGa5cd9732016-10-17 15:23:10 +0100425
Andres AGd9eba4b2016-08-26 14:42:14 +0100426err_msg()
427{
428 echo "$1" >&2
429}
430
431check_tools()
432{
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200433 for tool in "$@"; do
434 if ! `type "$tool" >/dev/null 2>&1`; then
435 err_msg "$tool not found!"
Andres AGd9eba4b2016-08-26 14:42:14 +0100436 exit 1
437 fi
438 done
439}
440
Gilles Peskine8f073122018-11-27 15:58:47 +0100441pre_parse_command_line () {
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000442 COMMAND_LINE_COMPONENTS=
Gilles Peskinea28db922019-01-10 00:05:18 +0100443 all_except=0
Gilles Peskine5d996822020-03-28 21:09:21 +0100444 error_test=0
Bence Szépkúti71c71eb2023-12-15 19:20:31 +0100445 list_components=0
Gilles Peskine80ddb992021-08-06 11:51:59 +0200446 restore_first=0
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000447 no_armcc=
SimonB2e23c822016-04-16 21:54:39 +0100448
Jaeden Amero9b90f2e2018-11-02 18:34:17 +0000449 # Note that legacy options are ignored instead of being omitted from this
450 # list of options, so invocations that worked with previous version of
451 # all.sh will still run and work properly.
Gilles Peskine8f073122018-11-27 15:58:47 +0100452 while [ $# -gt 0 ]; do
Gilles Peskine55f7c942019-01-09 22:28:21 +0100453 case "$1" in
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200454 --append-outcome) append_outcome=1;;
Gilles Peskine6d061342020-04-30 18:19:32 +0200455 --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +0200456 --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000457 --armcc) no_armcc=;;
Bence Szépkúti71c71eb2023-12-15 19:20:31 +0100458 --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
459 --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +0100460 --clang-earliest) shift; CLANG_EARLIEST="$1";;
461 --clang-latest) shift; CLANG_LATEST="$1";;
Gilles Peskine5d996822020-03-28 21:09:21 +0100462 --error-test) error_test=$((error_test + 1));;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000463 --except) all_except=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100464 --force|-f) FORCE=1;;
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +0100465 --gcc-earliest) shift; GCC_EARLIEST="$1";;
466 --gcc-latest) shift; GCC_LATEST="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100467 --gnutls-cli) shift; GNUTLS_CLI="$1";;
Gilles Peskine7be571a2023-08-27 21:39:21 +0200468 --gnutls-legacy-cli) shift;; # ignored for backward compatibility
469 --gnutls-legacy-serv) shift;; # ignored for backward compatibility
Gilles Peskine55f7c942019-01-09 22:28:21 +0100470 --gnutls-serv) shift; GNUTLS_SERV="$1";;
471 --help|-h) usage; exit;;
472 --keep-going|-k) KEEP_GOING=1;;
Gilles Peskine878cf602019-01-06 20:50:38 +0000473 --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
Bence Szépkúti71c71eb2023-12-15 19:20:31 +0100474 --list-components) list_components=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100475 --memory|-m) MEMORY=1;;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200476 --no-append-outcome) append_outcome=0;;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000477 --no-armcc) no_armcc=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100478 --no-force) FORCE=0;;
479 --no-keep-going) KEEP_GOING=0;;
480 --no-memory) MEMORY=0;;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200481 --no-quiet) QUIET=0;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100482 --openssl) shift; OPENSSL="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100483 --openssl-next) shift; OPENSSL_NEXT="$1";;
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200484 --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100485 --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200486 --quiet|-q) QUIET=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100487 --random-seed) unset SEED;;
Manuel Pégourié-Gonnarde0501912020-06-08 12:59:27 +0200488 --release-test|-r) SEED=$RELEASE_SEED;;
Gilles Peskine80ddb992021-08-06 11:51:59 +0200489 --restore) restore_first=1;;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100490 --seed|-s) shift; SEED="$1";;
491 -*)
492 echo >&2 "Unknown option: $1"
493 echo >&2 "Run $0 --help for usage."
494 exit 120
495 ;;
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000496 *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
Gilles Peskine55f7c942019-01-09 22:28:21 +0100497 esac
498 shift
Gilles Peskine8f073122018-11-27 15:58:47 +0100499 done
SimonB2e23c822016-04-16 21:54:39 +0100500
Bence Szépkúti71c71eb2023-12-15 19:20:31 +0100501 # Exclude components that are not supported on this platform.
502 SUPPORTED_COMPONENTS=
503 for component in $ALL_COMPONENTS; do
504 case $(type "support_$component" 2>&1) in
505 *' function'*)
506 if ! support_$component; then continue; fi;;
507 esac
508 SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
509 done
510
511 if [ $list_components -eq 1 ]; then
512 printf '%s\n' $SUPPORTED_COMPONENTS
513 exit
514 fi
515
Gilles Peskinea28db922019-01-10 00:05:18 +0100516 # With no list of components, run everything.
Gilles Peskine80ddb992021-08-06 11:51:59 +0200517 if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000518 all_except=1
Andres AGdc192212016-08-31 17:33:13 +0100519 fi
520
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000521 # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
522 # Ignore it if components are listed explicitly on the command line.
Gilles Peskinea28db922019-01-10 00:05:18 +0100523 if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000524 COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
SimonB2e23c822016-04-16 21:54:39 +0100525 fi
SimonB2e23c822016-04-16 21:54:39 +0100526
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200527 # Error out if an explicitly requested component doesn't exist.
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100528 if [ $all_except -eq 0 ]; then
529 unsupported=0
Gilles Peskine03af6782021-08-06 11:35:17 +0200530 # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
531 # only does word splitting.
Gilles Peskine1d475b62021-08-03 13:43:36 +0200532 set -f
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100533 for component in $COMMAND_LINE_COMPONENTS; do
Gilles Peskine1d475b62021-08-03 13:43:36 +0200534 set +f
Gilles Peskinebf66e2c2021-08-03 13:44:28 +0200535 # If the requested name includes a wildcard character, don't
536 # check it. Accept wildcard patterns that don't match anything.
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100537 case $component in
538 *[*?\[]*) continue;;
539 esac
540 case " $SUPPORTED_COMPONENTS " in
541 *" $component "*) :;;
542 *)
543 echo >&2 "Component $component was explicitly requested, but is not known or not supported."
544 unsupported=$((unsupported + 1));;
545 esac
546 done
Gilles Peskine1d475b62021-08-03 13:43:36 +0200547 set +f
Gilles Peskineb80f0d22020-03-28 21:37:59 +0100548 if [ $unsupported -ne 0 ]; then
549 exit 2
550 fi
551 fi
552
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000553 # Build the list of components to run.
Gilles Peskinea28db922019-01-10 00:05:18 +0100554 RUN_COMPONENTS=
555 for component in $SUPPORTED_COMPONENTS; do
556 if is_component_included "$component"; [ $? -eq $all_except ]; then
557 RUN_COMPONENTS="$RUN_COMPONENTS $component"
558 fi
559 done
Gilles Peskinebeb3a812019-01-06 22:11:25 +0000560
561 unset all_except
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000562 unset no_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +0100563}
SimonB2e23c822016-04-16 21:54:39 +0100564
Gilles Peskine8f073122018-11-27 15:58:47 +0100565pre_check_git () {
566 if [ $FORCE -eq 1 ]; then
Gilles Peskine53190e62019-01-09 23:17:35 +0100567 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +0100568 git checkout-index -f -q $CONFIG_H
569 cleanup
570 else
SimonB2e23c822016-04-16 21:54:39 +0100571
Gilles Peskine8f073122018-11-27 15:58:47 +0100572 if [ -d "$OUT_OF_SOURCE_DIR" ]; then
573 echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
574 echo "You can either delete this directory manually, or force the test by rerunning"
575 echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
576 exit 1
577 fi
578
Ronald Cron7a93ac52023-07-20 09:49:12 +0200579 if ! git diff --quiet "$CONFIG_H"; then
David Horstmann9a6c45b2023-07-14 12:30:00 +0100580 err_msg "Warning - the configuration file '$CONFIG_H' has been edited. "
Gilles Peskine8f073122018-11-27 15:58:47 +0100581 echo "You can either delete or preserve your work, or force the test by rerunning the"
582 echo "script as: $0 --force"
583 exit 1
584 fi
SimonB2e23c822016-04-16 21:54:39 +0100585 fi
Andrzej Kurekeb508712019-02-14 07:18:59 -0500586}
587
Gilles Peskine568f53a2021-07-12 18:16:01 +0200588pre_restore_files () {
589 # If the makefiles have been generated by a framework such as cmake,
590 # restore them from git. If the makefiles look like modifications from
591 # the ones checked into git, take care not to modify them. Whatever
592 # this function leaves behind is what the script will restore before
593 # each component.
594 case "$(head -n1 Makefile)" in
595 *[Gg]enerated*)
596 git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
597 git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
598 ;;
599 esac
600}
601
Gilles Peskinef83eb822020-03-30 20:11:39 +0200602pre_back_up () {
603 for x in $files_to_back_up; do
604 cp -p "$x" "$x$backup_suffix"
605 done
606}
607
Gilles Peskine8f073122018-11-27 15:58:47 +0100608pre_setup_keep_going () {
Gilles Peskinece266c42020-03-28 18:50:43 +0100609 failure_count=0 # Number of failed components
610 last_failure_status=0 # Last failure status in this component
611
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100612 # See err_trap
613 previous_failure_status=0
614 previous_failed_command=
615 previous_failure_funcall_depth=0
Gilles Peskinea681c592020-03-28 21:27:40 +0100616 unset report_failed_command
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100617
Gilles Peskine7c652162017-12-11 00:01:40 +0100618 start_red=
619 end_color=
620 if [ -t 1 ]; then
Gilles Peskine9736b9d2018-01-02 21:54:17 +0100621 case "${TERM:-}" in
Gilles Peskine7c652162017-12-11 00:01:40 +0100622 *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
623 start_red=$(printf '\033[31m')
624 end_color=$(printf '\033[0m')
625 ;;
626 esac
627 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100628
629 # Keep a summary of failures in a file. We'll print it out at the end.
630 failure_summary_file=$PWD/all-sh-failures-$$.log
631 : >"$failure_summary_file"
632
633 # Whether it makes sense to keep a component going after the specified
634 # command fails (test command) or not (configure or build).
Gilles Peskine03af6782021-08-06 11:35:17 +0200635 # This function normally receives the failing simple command
636 # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
637 # this is passed instead.
Gilles Peskinece266c42020-03-28 18:50:43 +0100638 # This doesn't have to be 100% accurate: all failures are recorded anyway.
Gilles Peskinec111e242021-08-02 23:29:53 +0200639 # False positives result in running things that can't be expected to
640 # work. False negatives result in things not running after something else
641 # failed even though they might have given useful feedback.
Gilles Peskinece266c42020-03-28 18:50:43 +0100642 can_keep_going_after_failure () {
643 case "$1" in
644 "msg "*) false;;
Gilles Peskinec111e242021-08-02 23:29:53 +0200645 "cd "*) false;;
Manuel Pégourié-Gonnarda7423372023-11-10 09:58:31 +0100646 "diff "*) true;;
Gilles Peskinec111e242021-08-02 23:29:53 +0200647 *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
648 *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
649 *make*check*) true;;
650 "grep "*) true;;
651 "[ "*) true;;
652 "! "*) true;;
Gilles Peskinece266c42020-03-28 18:50:43 +0100653 *) false;;
Gilles Peskine7c652162017-12-11 00:01:40 +0100654 esac
655 }
Gilles Peskinece266c42020-03-28 18:50:43 +0100656
657 # This function runs if there is any error in a component.
658 # It must either exit with a nonzero status, or set
659 # last_failure_status to a nonzero value.
660 err_trap () {
661 # Save $? (status of the failing command). This must be the very
662 # first thing, before $? is overridden.
663 last_failure_status=$?
Gilles Peskinea681c592020-03-28 21:27:40 +0100664 failed_command=${report_failed_command-$BASH_COMMAND}
Gilles Peskinece266c42020-03-28 18:50:43 +0100665
Gilles Peskinefec30cb2020-03-28 19:34:23 +0100666 if [[ $last_failure_status -eq $previous_failure_status &&
667 "$failed_command" == "$previous_failed_command" &&
668 ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
669 then
670 # The same command failed twice in a row, but this time one level
671 # less deep in the function call stack. This happens when the last
672 # command of a function returns a nonzero status, and the function
673 # returns that same status. Ignore the second failure.
674 previous_failure_funcall_depth=${#FUNCNAME[@]}
675 return
676 fi
677 previous_failure_status=$last_failure_status
678 previous_failed_command=$failed_command
679 previous_failure_funcall_depth=${#FUNCNAME[@]}
680
Gilles Peskinece266c42020-03-28 18:50:43 +0100681 text="$current_section: $failed_command -> $last_failure_status"
682 echo "${start_red}^^^^$text^^^^${end_color}" >&2
683 echo "$text" >>"$failure_summary_file"
684
685 # If the command is fatal (configure or build command), stop this
686 # component. Otherwise (test command) keep the component running
687 # (run more tests from the same build).
688 if ! can_keep_going_after_failure "$failed_command"; then
689 exit $last_failure_status
690 fi
691 }
692
Gilles Peskine7c652162017-12-11 00:01:40 +0100693 final_report () {
694 if [ $failure_count -gt 0 ]; then
695 echo
696 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Gilles Peskinece266c42020-03-28 18:50:43 +0100697 echo "${start_red}FAILED: $failure_count components${end_color}"
698 cat "$failure_summary_file"
Gilles Peskine7c652162017-12-11 00:01:40 +0100699 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
700 elif [ -z "${1-}" ]; then
701 echo "SUCCESS :)"
702 fi
703 if [ -n "${1-}" ]; then
704 echo "Killed by SIG$1."
705 fi
Gilles Peskinece266c42020-03-28 18:50:43 +0100706 rm -f "$failure_summary_file"
707 if [ $failure_count -gt 0 ]; then
708 exit 1
709 fi
Gilles Peskine7c652162017-12-11 00:01:40 +0100710 }
Gilles Peskine8f073122018-11-27 15:58:47 +0100711}
712
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +0200713# record_status() and if_build_succeeded() are kept temporarily for backward
714# compatibility. Don't use them in new components.
Gilles Peskinece266c42020-03-28 18:50:43 +0100715record_status () {
716 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100717}
Gilles Peskine7c652162017-12-11 00:01:40 +0100718if_build_succeeded () {
Gilles Peskinece266c42020-03-28 18:50:43 +0100719 "$@"
Gilles Peskine7c652162017-12-11 00:01:40 +0100720}
721
Gilles Peskinea681c592020-03-28 21:27:40 +0100722# '! true' does not trigger the ERR trap. Arrange to trigger it, with
723# a reasonably informative error message (not just "$@").
724not () {
725 if "$@"; then
726 report_failed_command="! $*"
727 false
728 unset report_failed_command
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200729 fi
730}
731
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200732pre_prepare_outcome_file () {
733 case "$MBEDTLS_TEST_OUTCOME_FILE" in
734 [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
735 esac
736 if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
737 rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
738 fi
739}
740
Gilles Peskine8f073122018-11-27 15:58:47 +0100741pre_print_configuration () {
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200742 if [ $QUIET -eq 1 ]; then
743 return
744 fi
745
Gilles Peskine8f073122018-11-27 15:58:47 +0100746 msg "info: $0 configuration"
747 echo "MEMORY: $MEMORY"
748 echo "FORCE: $FORCE"
Gilles Peskine67ffdaf2019-09-16 15:55:46 +0200749 echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
Gilles Peskine8f073122018-11-27 15:58:47 +0100750 echo "SEED: ${SEED-"UNSET"}"
Gilles Peskine636c26a2020-03-04 20:46:15 +0100751 echo
Gilles Peskine8f073122018-11-27 15:58:47 +0100752 echo "OPENSSL: $OPENSSL"
Gilles Peskine8f073122018-11-27 15:58:47 +0100753 echo "OPENSSL_NEXT: $OPENSSL_NEXT"
754 echo "GNUTLS_CLI: $GNUTLS_CLI"
755 echo "GNUTLS_SERV: $GNUTLS_SERV"
Gilles Peskine8f073122018-11-27 15:58:47 +0100756 echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
757 echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
758}
Andres AG7770ea82016-10-10 15:46:20 +0100759
Andres AGd9eba4b2016-08-26 14:42:14 +0100760# Make sure the tools we need are available.
Gilles Peskine8f073122018-11-27 15:58:47 +0100761pre_check_tools () {
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000762 # Build the list of variables to pass to output_env.sh.
763 set env
SimonB2e23c822016-04-16 21:54:39 +0100764
Gilles Peskine87964262019-01-06 22:40:00 +0000765 case " $RUN_COMPONENTS " in
766 # Require OpenSSL and GnuTLS if running any tests (as opposed to
767 # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
768 # is a good enough approximation in practice.
Bence Szépkútibbb5af92023-12-15 20:58:15 +0100769 *" test_"* | *" release_test_"*)
Gilles Peskine87964262019-01-06 22:40:00 +0000770 # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
771 # and ssl-opt.sh, we just export the variables they require.
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +0100772 export OPENSSL="$OPENSSL"
Gilles Peskine87964262019-01-06 22:40:00 +0000773 export GNUTLS_CLI="$GNUTLS_CLI"
774 export GNUTLS_SERV="$GNUTLS_SERV"
775 # Avoid passing --seed flag in every call to ssl-opt.sh
776 if [ -n "${SEED-}" ]; then
777 export SEED
778 fi
Gilles Peskine7be571a2023-08-27 21:39:21 +0200779 set "$@" OPENSSL="$OPENSSL"
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000780 set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
Gilles Peskine7be571a2023-08-27 21:39:21 +0200781 check_tools "$OPENSSL" "$OPENSSL_NEXT" \
782 "$GNUTLS_CLI" "$GNUTLS_SERV"
Gilles Peskine87964262019-01-06 22:40:00 +0000783 ;;
784 esac
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +0200785
Gilles Peskine87964262019-01-06 22:40:00 +0000786 case " $RUN_COMPONENTS " in
787 *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
788 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100789
Gilles Peskine87964262019-01-06 22:40:00 +0000790 case " $RUN_COMPONENTS " in
Gilles Peskine6d061342020-04-30 18:19:32 +0200791 *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
Gilles Peskine87964262019-01-06 22:40:00 +0000792 esac
Andres AGd9eba4b2016-08-26 14:42:14 +0100793
Gilles Peskine87964262019-01-06 22:40:00 +0000794 case " $RUN_COMPONENTS " in
795 *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
796 esac
797
798 case " $RUN_COMPONENTS " in
799 *" test_zeroize "*) check_tools "gdb";;
800 esac
801
802 case " $RUN_COMPONENTS " in
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000803 *_armcc*)
Gilles Peskine87964262019-01-06 22:40:00 +0000804 ARMC5_CC="$ARMC5_BIN_DIR/armcc"
805 ARMC5_AR="$ARMC5_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200806 ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
Gilles Peskine87964262019-01-06 22:40:00 +0000807 ARMC6_CC="$ARMC6_BIN_DIR/armclang"
808 ARMC6_AR="$ARMC6_BIN_DIR/armar"
Gilles Peskine18487f62020-04-30 23:11:54 +0200809 ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
810 check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
811 "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
Gilles Peskine5331c6e2019-01-06 22:23:42 +0000812 esac
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000813
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +0200814 # past this point, no call to check_tool, only printing output
815 if [ $QUIET -eq 1 ]; then
816 return
817 fi
818
Gilles Peskinecc9f0b92019-01-06 22:46:21 +0000819 msg "info: output_env.sh"
820 case $RUN_COMPONENTS in
821 *_armcc*)
822 set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
823 *) set "$@" RUN_ARMCC=0;;
824 esac
825 "$@" scripts/output_env.sh
Gilles Peskine8f073122018-11-27 15:58:47 +0100826}
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +0100827
Gilles Peskine1570b592021-04-22 01:10:12 +0200828pre_generate_files() {
Manuel Pégourié-Gonnard87db8a22021-06-18 13:30:14 +0200829 # since make doesn't have proper dependencies, remove any possibly outdate
830 # file that might be around before generating fresh ones
831 make neat
Gilles Peskine72385032021-07-08 19:07:07 +0200832 if [ $QUIET -eq 1 ]; then
Gilles Peskine75301632021-08-05 15:10:47 +0200833 make generated_files >/dev/null
Gilles Peskine72385032021-07-08 19:07:07 +0200834 else
835 make generated_files
836 fi
Gilles Peskine1570b592021-04-22 01:10:12 +0200837}
838
Tom Cosgroved4c373a2024-01-30 13:56:38 +0000839clang_version() {
840 if command -v clang > /dev/null ; then
841 clang --version|grep version|sed -E 's#.*version ([0-9]+).*#\1#'
842 else
843 echo 0 # report version 0 for "no clang"
844 fi
845}
846
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200847################################################################
848#### Helpers for components using libtestdriver1
849################################################################
Gilles Peskine192c72f2017-12-21 15:59:21 +0100850
Manuel Pégourié-Gonnardf5c5d972023-06-06 11:14:57 +0200851# How to use libtestdriver1
852# -------------------------
853#
854# 1. Define the list algorithms and key types to accelerate,
855# designated the same way as PSA_WANT_ macros but without PSA_WANT_.
856# Examples:
857# - loc_accel_list="ALG_JPAKE"
858# - loc_accel_list="ALG_FFDH KEY_TYPE_DH_KEY_PAIR KEY_TYPE_DH_PUBLIC_KEY"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200859# 2. Make configurations changes for the driver and/or main libraries.
860# 2a. Call helper_libtestdriver1_adjust_config <base>, where the argument
861# can be either "default" to start with the default config, or a name
862# supported by scripts/config.py (for example, "full"). This selects
Manuel Pégourié-Gonnard2336c8e2023-06-12 17:17:54 +0200863# the base to use, and makes common adjustments.
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200864# 2b. If desired, adjust the PSA_WANT symbols in psa/crypto_config.h.
865# These changes affect both the driver and the main libraries.
866# (Note: they need to have the same set of PSA_WANT symbols, as that
867# determines the ABI between them.)
868# 2c. Adjust MBEDTLS_ symbols in mbedtls_config.h. This only affects the
869# main libraries. Typically, you want to disable the module(s) that are
870# being accelerated. You may need to also disable modules that depend
871# on them or options that are not supported with drivers.
872# 2d. On top of psa/crypto_config.h, the driver library uses its own config
873# file: tests/include/test/drivers/config_test_driver.h. You usually
874# don't need to edit it: using loc_extra_list (see below) is preferred.
875# However, when there's no PSA symbol for what you want to enable,
876# calling scripts/config.py on this file remains the only option.
877# 3. Build the driver library, then the main libraries, test, and programs.
878# 3a. Call helper_libtestdriver1_make_drivers "$loc_accel_list". You may
879# need to enable more algorithms here, typically hash algorithms when
880# accelerating some signature algorithms (ECDSA, RSAv2). This is done
881# by passing a 2nd argument listing the extra algorithms.
882# Example:
883# loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
884# helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
Yanray Wang0df6d962023-10-11 13:27:25 +0800885# 3b. Call helper_libtestdriver1_make_main "$loc_accel_list". Any
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200886# additional arguments will be passed to make: this can be useful if
887# you don't want to build everything when iterating during development.
888# Example:
889# helper_libtestdriver1_make_main "$loc_accel_list" -C tests test_suite_foo
890# 4. Run the tests you want.
Manuel Pégourié-Gonnardf5c5d972023-06-06 11:14:57 +0200891
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200892# Adjust the configuration - for both libtestdriver1 and main library,
893# as they should have the same PSA_WANT macros.
894helper_libtestdriver1_adjust_config() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200895 base_config=$1
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200896 # Select the base configuration
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200897 if [ "$base_config" != "default" ]; then
898 scripts/config.py "$base_config"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +0200899 fi
900
901 # Enable PSA-based config (necessary to use drivers)
902 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
903
Manuel Pégourié-Gonnard2336c8e2023-06-12 17:17:54 +0200904 # Dynamic secure element support is a deprecated feature and needs to be disabled here.
905 # This is done to have the same form of psa_key_attributes_s for libdriver and library.
906 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Paul Elliott053b7882024-03-05 11:46:32 +0000907
908 # If threading is enabled on the normal build, then we need to enable it in the drivers as well,
909 # otherwise we will end up running multithreaded tests without mutexes to protect them.
910 if scripts/config.py get MBEDTLS_THREADING_C; then
911 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_THREADING_C
912 fi
913
914 if scripts/config.py get MBEDTLS_THREADING_PTHREAD; then
915 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_THREADING_PTHREAD
916 fi
Manuel Pégourié-Gonnard27e17672023-05-25 09:39:08 +0200917}
Gilles Peskine192c72f2017-12-21 15:59:21 +0100918
Manuel Pégourié-Gonnard733a67b2023-11-15 12:32:17 +0100919# Build the drivers library libtestdriver1.a (with ASan).
920#
921# Parameters:
922# 1. a space-separated list of things to accelerate;
923# 2. optional: a space-separate list of things to also support.
924# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
925helper_libtestdriver1_make_drivers() {
926 loc_accel_flags=$( echo "$1 ${2-}" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
927 make CC=$ASAN_CC -C tests libtestdriver1.a CFLAGS=" $ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
928}
929
930# Build the main libraries, programs and tests,
931# linking to the drivers library (with ASan).
932#
933# Parameters:
934# 1. a space-separated list of things to accelerate;
935# *. remaining arguments if any are passed directly to make
936# (examples: lib, -C tests test_suite_xxx, etc.)
937# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
938helper_libtestdriver1_make_main() {
939 loc_accel_list=$1
940 shift
941
942 # we need flags both with and without the LIBTESTDRIVER1_ prefix
943 loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
944 loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
945 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS" "$@"
946}
947
948################################################################
949#### Configuration helpers
950################################################################
951
Valerio Settib2fd6732023-08-15 17:10:47 +0200952# When called with no parameter this function disables all builtin curves.
Valerio Setti4ca250b2023-09-04 14:01:41 +0200953# The function optionally accepts 1 parameter: a space-separated list of the
954# curves that should be kept enabled.
Valerio Settib2fd6732023-08-15 17:10:47 +0200955helper_disable_builtin_curves() {
956 allowed_list="${1:-}"
957 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
958
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200959 for curve in $allowed_list; do
960 scripts/config.py set $curve
Valerio Settib2fd6732023-08-15 17:10:47 +0200961 done
962}
963
964# Helper returning the list of supported elliptic curves from CRYPTO_CONFIG_H,
965# without the "PSA_WANT_" prefix. This becomes handy for accelerating curves
966# in the following helpers.
967helper_get_psa_curve_list () {
968 loc_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200969 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
970 loc_list="$loc_list $item"
Valerio Settib2fd6732023-08-15 17:10:47 +0200971 done
972
973 echo "$loc_list"
974}
975
Valerio Setti78aa0bc2024-01-17 15:53:46 +0100976# Helper returning the list of supported DH groups from CRYPTO_CONFIG_H,
977# without the "PSA_WANT_" prefix. This becomes handy for accelerating DH groups
978# in the following helpers.
979helper_get_psa_dh_group_list () {
980 loc_list=""
981 for item in $(sed -n 's/^#define PSA_WANT_\(DH_RFC7919_[0-9]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
982 loc_list="$loc_list $item"
983 done
984
985 echo "$loc_list"
986}
987
Valerio Settib2fd6732023-08-15 17:10:47 +0200988# Get the list of uncommented PSA_WANT_KEY_TYPE_xxx_ from CRYPTO_CONFIG_H. This
Valerio Setti0a342c92023-09-01 09:12:31 +0200989# is useful to easily get a list of key type symbols to accelerate.
Valerio Settib2fd6732023-08-15 17:10:47 +0200990# The function accepts a single argument which is the key type: ECC, DH, RSA.
Valerio Setti0a342c92023-09-01 09:12:31 +0200991helper_get_psa_key_type_list() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200992 key_type="$1"
Valerio Settib2fd6732023-08-15 17:10:47 +0200993 loc_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200994 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 +0200995 # Skip DERIVE for elliptic keys since there is no driver dispatch for
996 # it so it cannot be accelerated.
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +0200997 if [ "$item" != "KEY_TYPE_ECC_KEY_PAIR_DERIVE" ]; then
998 loc_list="$loc_list $item"
Valerio Settib2fd6732023-08-15 17:10:47 +0200999 fi
1000 done
1001
1002 echo "$loc_list"
1003}
1004
Gilles Peskine192c72f2017-12-21 15:59:21 +01001005################################################################
1006#### Basic checks
1007################################################################
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01001008
1009#
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001010# Test Suites to be executed
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +01001011#
Manuel Pégourié-Gonnard3d404b42015-07-08 21:59:16 +01001012# The test ordering tries to optimize for the following criteria:
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001013# 1. Catch possible problems early, by running first tests that run quickly
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +01001014# 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 +02001015# time, so start with a GCC build).
1016# 2. Minimize total running time, by avoiding useless rebuilds
Manuel Pégourié-Gonnard89d69b32014-11-20 13:48:53 +01001017#
Manuel Pégourié-Gonnard259b08a2016-01-08 16:27:41 +01001018# Indicative running times are given for reference.
1019
Gilles Peskine8f073122018-11-27 15:58:47 +01001020component_check_recursion () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001021 msg "Check: recursion.pl" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001022 tests/scripts/recursion.pl library/*.c
Gilles Peskine8f073122018-11-27 15:58:47 +01001023}
Janos Follathb72c6782016-07-19 14:54:17 +01001024
Gilles Peskine67debb62021-05-18 16:09:50 +02001025component_check_generated_files () {
1026 msg "Check: check-generated-files, files generated with make" # 2s
1027 make generated_files
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001028 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +02001029
1030 msg "Check: check-generated-files -u, files present" # 2s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001031 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +02001032 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001033 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +02001034
1035 msg "Check: check-generated-files -u, files absent" # 2s
1036 command make neat
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001037 tests/scripts/check-generated-files.sh -u
Gilles Peskine67debb62021-05-18 16:09:50 +02001038 # Check that the generated files are considered up to date.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001039 tests/scripts/check-generated-files.sh
Gilles Peskine67debb62021-05-18 16:09:50 +02001040
1041 # This component ends with the generated files present in the source tree.
1042 # This is necessary for subsequent components!
1043}
1044
Gilles Peskine8f073122018-11-27 15:58:47 +01001045component_check_doxy_blocks () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001046 msg "Check: doxygen markup outside doxygen blocks" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001047 tests/scripts/check-doxy-blocks.pl
Gilles Peskine8f073122018-11-27 15:58:47 +01001048}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001049
Gilles Peskine8f073122018-11-27 15:58:47 +01001050component_check_files () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001051 msg "Check: file sanity checks (permissions, encodings)" # < 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001052 tests/scripts/check_files.py
Gilles Peskine8f073122018-11-27 15:58:47 +01001053}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001054
Gilles Peskine30e0bb42020-05-10 17:40:49 +02001055component_check_changelog () {
1056 msg "Check: changelog entries" # < 1s
1057 rm -f ChangeLog.new
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001058 scripts/assemble_changelog.py -o ChangeLog.new
Gilles Peskine30e0bb42020-05-10 17:40:49 +02001059 if [ -e ChangeLog.new ]; then
1060 # Show the diff for information. It isn't an error if the diff is
1061 # non-empty.
1062 diff -u ChangeLog ChangeLog.new || true
1063 rm ChangeLog.new
1064 fi
1065}
1066
Gilles Peskine8f073122018-11-27 15:58:47 +01001067component_check_names () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001068 msg "Check: declared and exported names (builds the library)" # < 3s
Yuto Takanoc3a6f632021-09-24 18:02:56 +01001069 tests/scripts/check_names.py -v
Gilles Peskine8f073122018-11-27 15:58:47 +01001070}
Darryl Greena07039c2018-03-13 16:48:16 +00001071
Gilles Peskine895868b2019-09-19 21:30:05 +02001072component_check_test_cases () {
1073 msg "Check: test case descriptions" # < 1s
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001074 if [ $QUIET -eq 1 ]; then
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001075 opt='--quiet'
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001076 else
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001077 opt=''
Manuel Pégourié-Gonnarda9119162020-06-02 11:51:40 +02001078 fi
Gilles Peskine031114d2022-12-15 14:46:31 +01001079 tests/scripts/check_test_cases.py -q $opt
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02001080 unset opt
Gilles Peskine895868b2019-09-19 21:30:05 +02001081}
1082
Manuel Pégourié-Gonnard3e1d39b2023-11-08 12:54:02 +01001083component_check_test_dependencies () {
1084 msg "Check: test case dependencies: legacy vs PSA" # < 1s
Manuel Pégourié-Gonnard9f164f02023-11-10 10:16:06 +01001085 # The purpose of this component is to catch unjustified dependencies on
1086 # legacy feature macros (MBEDTLS_xxx) in PSA tests. Generally speaking,
1087 # PSA test should use PSA feature macros (PSA_WANT_xxx, more rarely
1088 # MBEDTLS_PSA_xxx).
1089 #
1090 # Most of the time, use of legacy MBEDTLS_xxx macros are mistakes, which
1091 # this component is meant to catch. However a few of them are justified,
1092 # mostly by the absence of a PSA equivalent, so this component includes a
1093 # list of expected exceptions.
Manuel Pégourié-Gonnard3e1d39b2023-11-08 12:54:02 +01001094
1095 found="check-test-deps-found-$$"
1096 expected="check-test-deps-expected-$$"
1097
1098 # Find legacy dependencies in PSA tests
Manuel Pégourié-Gonnard5c6f7872023-11-10 10:04:22 +01001099 grep 'depends_on' \
1100 tests/suites/test_suite_psa*.data tests/suites/test_suite_psa*.function |
Manuel Pégourié-Gonnard3e1d39b2023-11-08 12:54:02 +01001101 grep -Eo '!?MBEDTLS_[^: ]*' |
Gilles Peskinea7d56622023-11-29 20:49:04 +01001102 grep -v -e MBEDTLS_PSA_ -e MBEDTLS_TEST_ |
Yanray Wang18040ed2023-11-23 21:29:56 +08001103 sort -u > $found
Manuel Pégourié-Gonnard3e1d39b2023-11-08 12:54:02 +01001104
Yanray Wang18040ed2023-11-23 21:29:56 +08001105 # Expected ones with justification - keep in sorted order by ASCII table!
Manuel Pégourié-Gonnard3e1d39b2023-11-08 12:54:02 +01001106 rm -f $expected
1107 # No PSA equivalent - WANT_KEY_TYPE_AES means all sizes
1108 echo "!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH" >> $expected
Yanray Wang18040ed2023-11-23 21:29:56 +08001109 # No PSA equivalent - used to skip decryption tests in PSA-ECB, CBC/XTS/NIST_KW/DES
1110 echo "!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT" >> $expected
Valerio Setti3ccb2b52024-01-10 10:51:24 +01001111 # MBEDTLS_ASN1_WRITE_C is used by import_rsa_made_up() in test_suite_psa_crypto
1112 # in order to build a fake RSA key of the wanted size based on
Manuel Pégourié-Gonnard3e1d39b2023-11-08 12:54:02 +01001113 # PSA_VENDOR_RSA_MAX_KEY_BITS. The legacy module is only used by
1114 # the test code and that's probably the most convenient way of achieving
1115 # the test's goal.
1116 echo "MBEDTLS_ASN1_WRITE_C" >> $expected
1117 # No PSA equivalent - we should probably have one in the future.
1118 echo "MBEDTLS_ECP_RESTARTABLE" >> $expected
1119 # No PSA equivalent - needed by some init tests
1120 echo "MBEDTLS_ENTROPY_NV_SEED" >> $expected
Paul Elliott16d51602024-03-05 14:54:28 +00001121 # No PSA equivalent - required to run threaded tests.
Paul Elliott16d51602024-03-05 14:54:28 +00001122 echo "MBEDTLS_THREADING_PTHREAD" >> $expected
Manuel Pégourié-Gonnard3e1d39b2023-11-08 12:54:02 +01001123
1124 # Compare reality with expectation.
1125 # We want an exact match, to ensure the above list remains up-to-date.
Manuel Pégourié-Gonnard9f164f02023-11-10 10:16:06 +01001126 #
1127 # The output should be empty. When it's not:
1128 # - Each '+' line is a macro that was found but not expected. You want to
1129 # find where that macro occurs, and either replace it with PSA macros, or
1130 # add it to the exceptions list above with a justification.
1131 # - Each '-' line is a macro that was expected but not found; it means the
1132 # exceptions list above should be updated by removing that macro.
Manuel Pégourié-Gonnard3e1d39b2023-11-08 12:54:02 +01001133 diff -U0 $expected $found
1134
1135 rm $found $expected
1136}
1137
Gilles Peskine8f073122018-11-27 15:58:47 +01001138component_check_doxygen_warnings () {
Gilles Peskine600bb692019-09-19 21:29:11 +02001139 msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001140 tests/scripts/doxygen.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001141}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001142
Gilles Peskine192c72f2017-12-21 15:59:21 +01001143
Gilles Peskine636c26a2020-03-04 20:46:15 +01001144
Gilles Peskine192c72f2017-12-21 15:59:21 +01001145################################################################
1146#### Build and test many configurations and targets
1147################################################################
1148
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001149component_test_default_out_of_box () {
1150 msg "build: make, default config (out-of-box)" # ~1min
1151 make
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02001152 # Disable fancy stuff
1153 unset MBEDTLS_TEST_OUTCOME_FILE
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001154
1155 msg "test: main suites make, default config (out-of-box)" # ~10s
1156 make test
1157
1158 msg "selftest: make, default config (out-of-box)" # ~10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001159 programs/test/selftest
Gilles Peskine82b27272019-06-14 18:27:03 +02001160
1161 msg "program demos: make, default config (out-of-box)" # ~10s
1162 tests/scripts/run_demos.py
Gilles Peskine7832c9f2019-04-08 17:00:15 +02001163}
1164
Gilles Peskine8f073122018-11-27 15:58:47 +01001165component_test_default_cmake_gcc_asan () {
1166 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Gilles Peskine8f073122018-11-27 15:58:47 +01001167 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1168 make
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001169
Gilles Peskine8f073122018-11-27 15:58:47 +01001170 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
1171 make test
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001172
Gilles Peskine82b27272019-06-14 18:27:03 +02001173 msg "program demos (ASan build)" # ~10s
1174 tests/scripts/run_demos.py
1175
Gilles Peskine97bea012020-04-23 23:37:45 +02001176 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001177 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +02001178
Gilles Peskine6848d172023-11-02 19:58:03 +01001179 msg "test: metatests (GCC, ASan build)"
David Horstmann9de6edd2024-01-17 14:53:08 +00001180 tests/scripts/run-metatests.sh any asan poison
Gilles Peskine6848d172023-11-02 19:58:03 +01001181
Gilles Peskine8f073122018-11-27 15:58:47 +01001182 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001183 tests/ssl-opt.sh
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001184
Gilles Peskine8f073122018-11-27 15:58:47 +01001185 msg "test: compat.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001186 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001187
1188 msg "test: context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001189 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001190}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001191
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001192component_test_default_cmake_gcc_asan_new_bignum () {
1193 msg "build: cmake, gcc, ASan" # ~ 1 min 50s
Janos Follath2f045822023-07-31 10:57:16 +01001194 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001195 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Janos Follath82823b22023-07-27 12:25:05 +01001196 make
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001197
1198 msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
1199 make test
1200
1201 msg "test: selftest (ASan build)" # ~ 10s
1202 programs/test/selftest
1203
1204 msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
1205 tests/ssl-opt.sh
1206
1207 msg "test: compat.sh (ASan build)" # ~ 6 min
1208 tests/compat.sh
1209
1210 msg "test: context-info.sh (ASan build)" # ~ 15 sec
1211 tests/context-info.sh
1212}
1213
Hanno Becker01635512019-02-26 14:27:09 +00001214component_test_full_cmake_gcc_asan () {
1215 msg "build: full config, cmake, gcc, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001216 scripts/config.py full
Hanno Becker01635512019-02-26 14:27:09 +00001217 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1218 make
1219
1220 msg "test: main suites (inc. selftests) (full config, ASan build)"
1221 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01001222
Gilles Peskine97bea012020-04-23 23:37:45 +02001223 msg "test: selftest (ASan build)" # ~ 10s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001224 programs/test/selftest
Gilles Peskine97bea012020-04-23 23:37:45 +02001225
Gilles Peskine636c26a2020-03-04 20:46:15 +01001226 msg "test: ssl-opt.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001227 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001228
1229 msg "test: compat.sh (full config, ASan build)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001230 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001231
1232 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001233 tests/context-info.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001234}
1235
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001236
1237component_test_full_cmake_gcc_asan_new_bignum () {
1238 msg "build: full config, cmake, gcc, ASan"
1239 scripts/config.py full
Janos Follath2f045822023-07-31 10:57:16 +01001240 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001241 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
Janos Follath82823b22023-07-27 12:25:05 +01001242 make
Gabor Mezei9b6b5a02023-06-06 17:22:25 +02001243
1244 msg "test: main suites (inc. selftests) (full config, ASan build)"
1245 make test
1246
1247 msg "test: selftest (ASan build)" # ~ 10s
1248 programs/test/selftest
1249
1250 msg "test: ssl-opt.sh (full config, ASan build)"
1251 tests/ssl-opt.sh
1252
1253 msg "test: compat.sh (full config, ASan build)"
1254 tests/compat.sh
1255
1256 msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
1257 tests/context-info.sh
Gabor Mezei6db60472023-07-05 16:38:42 +02001258}
1259
Ronald Cronc3623db2020-10-29 10:51:32 +01001260component_test_psa_crypto_key_id_encodes_owner () {
Andrzej Kurek03e01462022-01-03 12:53:24 +01001261 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
Ronald Cronc3623db2020-10-29 10:51:32 +01001262 scripts/config.py full
Ronald Cronc3623db2020-10-29 10:51:32 +01001263 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1264 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1265 make
1266
1267 msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
1268 make test
1269}
1270
David Horstmann4a48bec2024-03-13 15:42:31 +00001271component_test_psa_assume_exclusive_buffers () {
1272 msg "build: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
David Horstmann0f06bde2023-12-20 11:10:16 +00001273 scripts/config.py full
David Horstmann4a48bec2024-03-13 15:42:31 +00001274 scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
David Horstmann0f06bde2023-12-20 11:10:16 +00001275 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1276 make
1277
David Horstmann4a48bec2024-03-13 15:42:31 +00001278 msg "test: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
David Horstmann0f06bde2023-12-20 11:10:16 +00001279 make test
1280}
1281
Gilles Peskinea3548672021-06-17 11:37:52 +02001282# check_renamed_symbols HEADER LIB
1283# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
1284# name is LIB.
1285check_renamed_symbols () {
1286 ! nm "$2" | sed 's/.* //' |
1287 grep -x -F "$(sed -n 's/^ *# *define *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
1288}
1289
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001290component_build_psa_crypto_spm () {
Andrzej Kurek03e01462022-01-03 12:53:24 +01001291 msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001292 scripts/config.py full
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001293 scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
1294 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1295 scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
1296 # We can only compile, not link, since our test and sample programs
1297 # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
1298 # is active.
1299 make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
Gilles Peskinea3548672021-06-17 11:37:52 +02001300
1301 # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
1302 # version is not present.
1303 echo "Checking for renamed symbols in the library"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001304 check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
Gilles Peskined1dcfd52021-06-15 18:37:38 +02001305}
1306
Valerio Setti63097752024-03-12 13:18:13 +01001307# Get a list of library-wise undefined symbols and ensure that they only
1308# belong to psa_xxx() functions and not to mbedtls_yyy() ones.
1309# This function is a common helper used by both:
1310# - component_test_default_psa_crypto_client_without_crypto_provider
1311# - component_build_full_psa_crypto_client_without_crypto_provider.
1312common_check_mbedtls_missing_symbols() {
1313 nm library/libmbedcrypto.a | grep ' [TRrDC] ' | grep -Eo '(mbedtls_|psa_).*' | sort -u > sym_def.txt
1314 nm library/libmbedcrypto.a | grep ' U ' | grep -Eo '(mbedtls_|psa_).*' | sort -u > sym_undef.txt
1315 comm sym_def.txt sym_undef.txt -13 > linking_errors.txt
1316 not grep mbedtls_ linking_errors.txt
1317
1318 rm sym_def.txt sym_undef.txt linking_errors.txt
1319}
1320
1321component_test_default_psa_crypto_client_without_crypto_provider () {
1322 msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
1323
Ronald Cron336678b2021-01-28 17:54:24 +01001324 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1325 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Valerio Setti63097752024-03-12 13:18:13 +01001326 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Ronald Crona3f385d2024-03-18 10:25:37 +01001327 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Ronald Cron336678b2021-01-28 17:54:24 +01001328 scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
Raef Colesb4568c52022-09-28 17:11:42 +01001329 scripts/config.py unset MBEDTLS_LMS_C
Valerio Setti63097752024-03-12 13:18:13 +01001330
Ronald Cron336678b2021-01-28 17:54:24 +01001331 make
1332
Valerio Setti63097752024-03-12 13:18:13 +01001333 msg "check missing symbols: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
1334 common_check_mbedtls_missing_symbols
1335
1336 msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
Ronald Cron336678b2021-01-28 17:54:24 +01001337 make test
1338}
1339
Valerio Setti63097752024-03-12 13:18:13 +01001340component_build_full_psa_crypto_client_without_crypto_provider () {
1341 msg "build: full config - PSA_CRYPTO_C"
1342
1343 # Use full config which includes USE_PSA and CRYPTO_CLIENT.
1344 scripts/config.py full
1345
1346 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1347 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1348 # Dynamic secure element support is a deprecated feature and it is not
1349 # available when CRYPTO_C and PSA_CRYPTO_STORAGE_C are disabled.
1350 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
1351
1352 # Since there is no crypto provider in this build it is not possible to
1353 # build all the test executables and progrems due to missing PSA functions
1354 # at link time. Therefore we will just build libraries and we'll check
1355 # that symbols of interest are there.
1356 make lib
1357
1358 msg "check missing symbols: full config - PSA_CRYPTO_C"
1359
1360 common_check_mbedtls_missing_symbols
1361
1362 # Ensure that desired functions are included into the build (extend the
1363 # following list as required).
1364 grep mbedtls_pk_get_psa_attributes library/libmbedcrypto.a
1365 grep mbedtls_pk_import_into_psa library/libmbedcrypto.a
1366 grep mbedtls_pk_copy_from_psa library/libmbedcrypto.a
1367}
1368
Ryan Everettdaa322a2024-04-18 16:48:55 +01001369component_test_no_rsa_key_pair_generation() {
1370 msg "build: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
Jaeden Amero424fa932021-05-14 08:34:32 +01001371 scripts/config.py unset MBEDTLS_GENPRIME
Ryan Everettdaa322a2024-04-18 16:48:55 +01001372 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Jaeden Amero424fa932021-05-14 08:34:32 +01001373 make
1374
Ryan Everettdaa322a2024-04-18 16:48:55 +01001375 msg "test: default config minus PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE"
Jaeden Amero424fa932021-05-14 08:34:32 +01001376 make test
1377}
1378
Gilles Peskine782f4112018-11-27 16:11:09 +01001379component_test_ref_configs () {
1380 msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
Manuel Pégourié-Gonnard9327fb32021-09-09 11:46:25 +02001381 # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
1382 # want to re-generate generated files that depend on it, quite correctly.
1383 # However this doesn't work as the generation script expects a specific
1384 # format for mbedtls_config.h, which the other files don't follow. Also,
1385 # cmake can't know this, but re-generation is actually not necessary as
David Horstmannd64f4b22021-10-20 12:29:47 +01001386 # the generated files only depend on the list of available options, not
Manuel Pégourié-Gonnard9327fb32021-09-09 11:46:25 +02001387 # whether they're on or off. So, disable cmake's (over-sensitive here)
1388 # dependency resolution for generated files and just rely on them being
David Horstmanna8d14062021-10-20 17:14:23 +01001389 # present (thanks to pre_generate_files) by turning GEN_FILES off.
Dave Rodgman17127e92023-12-14 16:42:48 +00001390 CC=$ASAN_CC cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001391 tests/scripts/test-ref-configs.pl
Gilles Peskine782f4112018-11-27 16:11:09 +01001392}
Manuel Pégourié-Gonnard57255b12014-06-09 11:21:49 +02001393
Gilles Peskine8f073122018-11-27 15:58:47 +01001394component_test_no_renegotiation () {
1395 msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001396 scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
Dave Rodgman17127e92023-12-14 16:42:48 +00001397 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine8f073122018-11-27 15:58:47 +01001398 make
Simon Butcher3ea7f522016-03-07 23:22:10 +00001399
Gilles Peskine8f073122018-11-27 15:58:47 +01001400 msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1401 make test
Hanno Becker134c2ab2017-10-12 15:29:50 +01001402
Gilles Peskine8f073122018-11-27 15:58:47 +01001403 msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001404 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001405}
Hanno Becker134c2ab2017-10-12 15:29:50 +01001406
Gilles Peskine636c26a2020-03-04 20:46:15 +01001407component_test_no_pem_no_fs () {
1408 msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1409 scripts/config.py unset MBEDTLS_PEM_PARSE_C
1410 scripts/config.py unset MBEDTLS_FS_IO
1411 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1412 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
Dave Rodgman17127e92023-12-14 16:42:48 +00001413 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine636c26a2020-03-04 20:46:15 +01001414 make
1415
1416 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1417 make test
1418
1419 msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001420 tests/ssl-opt.sh
Gilles Peskine636c26a2020-03-04 20:46:15 +01001421}
1422
Gilles Peskine8f073122018-11-27 15:58:47 +01001423component_test_rsa_no_crt () {
1424 msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02001425 scripts/config.py set MBEDTLS_RSA_NO_CRT
Dave Rodgman17127e92023-12-14 16:42:48 +00001426 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine8f073122018-11-27 15:58:47 +01001427 make
Manuel Pégourié-Gonnard246978d2014-11-20 13:29:53 +01001428
Gilles Peskine8f073122018-11-27 15:58:47 +01001429 msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1430 make test
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001431
Gilles Peskine8f073122018-11-27 15:58:47 +01001432 msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001433 tests/ssl-opt.sh -f RSA
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001434
Gilles Peskine8f073122018-11-27 15:58:47 +01001435 msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001436 tests/compat.sh -t RSA
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02001437
1438 msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001439 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01001440}
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01001441
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001442component_test_no_ctr_drbg_classic () {
1443 msg "build: Full minus CTR_DRBG, classic crypto in TLS"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001444 scripts/config.py full
1445 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001446 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001447 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001448
Dave Rodgman17127e92023-12-14 16:42:48 +00001449 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001450 make
1451
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001452 msg "test: Full minus CTR_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001453 make test
1454
Gilles Peskineba749042021-01-13 20:02:03 +01001455 # In this configuration, the TLS test programs use HMAC_DRBG.
1456 # The SSL tests are slow, so run a small subset, just enough to get
1457 # confidence that the SSL code copes with HMAC_DRBG.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001458 msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001459 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskineba749042021-01-13 20:02:03 +01001460
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001461 msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001462 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001463}
1464
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001465component_test_no_ctr_drbg_use_psa () {
1466 msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001467 scripts/config.py full
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001468 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1469 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001470
Dave Rodgman17127e92023-12-14 16:42:48 +00001471 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001472 make
1473
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001474 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1475 make test
1476
1477 # In this configuration, the TLS test programs use HMAC_DRBG.
1478 # The SSL tests are slow, so run a small subset, just enough to get
1479 # confidence that the SSL code copes with HMAC_DRBG.
1480 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001481 tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001482
1483 msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001484 tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001485}
1486
1487component_test_no_hmac_drbg_classic () {
1488 msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1489 scripts/config.py full
1490 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1491 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1492 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001493 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001494
Dave Rodgman17127e92023-12-14 16:42:48 +00001495 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001496 make
1497
1498 msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
Manuel Pégourié-Gonnard5b942dc2020-06-05 09:29:51 +02001499 make test
1500
Gilles Peskinea2224342020-11-19 22:14:34 +01001501 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1502 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1503 # instead.
1504 # Test SSL with non-deterministic ECDSA. Only test features that
1505 # might be affected by how ECDSA signature is performed.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001506 msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001507 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskinea2224342020-11-19 22:14:34 +01001508
1509 # To save time, only test one protocol version, since this part of
1510 # the protocol is identical in (D)TLS up to 1.2.
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001511 msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001512 tests/compat.sh -m tls12 -t 'ECDSA'
Manuel Pégourié-Gonnard817e3682020-05-28 12:55:10 +02001513}
1514
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001515component_test_no_hmac_drbg_use_psa () {
1516 msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1517 scripts/config.py full
1518 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1519 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1520 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1521
Dave Rodgman17127e92023-12-14 16:42:48 +00001522 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001523 make
1524
1525 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1526 make test
1527
1528 # Normally our ECDSA implementation uses deterministic ECDSA. But since
1529 # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1530 # instead.
1531 # Test SSL with non-deterministic ECDSA. Only test features that
1532 # might be affected by how ECDSA signature is performed.
1533 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001534 tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001535
1536 # To save time, only test one protocol version, since this part of
1537 # the protocol is identical in (D)TLS up to 1.2.
1538 msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
Xiaofei Bai8b5c3822021-12-02 08:43:35 +00001539 tests/compat.sh -m tls12 -t 'ECDSA'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001540}
1541
1542component_test_psa_external_rng_no_drbg_classic () {
1543 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1544 scripts/config.py full
1545 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cronf6606552022-03-15 11:23:25 +01001546 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001547 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001548 scripts/config.py unset MBEDTLS_ENTROPY_C
1549 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1550 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001551 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1552 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1553 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskine8eb29432021-02-03 20:07:11 +01001554 # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1555 # the SSL test programs don't have an RNG and can't work. Explicitly
1556 # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
Gilles Peskine21570cf2023-12-22 11:49:50 +01001557 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001558
1559 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1560 make test
1561
Gilles Peskine8eb29432021-02-03 20:07:11 +01001562 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001563 tests/ssl-opt.sh -f 'Default'
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001564}
1565
1566component_test_psa_external_rng_no_drbg_use_psa () {
1567 msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001568 scripts/config.py full
1569 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
Gilles Peskine38c12fd2021-02-08 21:02:53 +01001570 scripts/config.py unset MBEDTLS_ENTROPY_C
1571 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1572 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
Gilles Peskinec109b372020-11-23 17:39:04 +01001573 scripts/config.py unset MBEDTLS_CTR_DRBG_C
1574 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1575 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
Gilles Peskine21570cf2023-12-22 11:49:50 +01001576 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinec109b372020-11-23 17:39:04 +01001577
Gilles Peskine2747d7d2021-02-03 14:56:51 +01001578 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
Gilles Peskinec109b372020-11-23 17:39:04 +01001579 make test
1580
Gilles Peskine8eb29432021-02-03 20:07:11 +01001581 msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001582 tests/ssl-opt.sh -f 'Default\|opaque'
Gilles Peskinec109b372020-11-23 17:39:04 +01001583}
1584
Gilles Peskine4bdb2542023-04-28 19:25:25 +02001585component_test_psa_external_rng_use_psa_crypto () {
1586 msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1587 scripts/config.py full
1588 scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1589 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1590 scripts/config.py unset MBEDTLS_CTR_DRBG_C
Gilles Peskine21570cf2023-12-22 11:49:50 +01001591 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine4bdb2542023-04-28 19:25:25 +02001592
1593 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1594 make test
1595
1596 msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1597 tests/ssl-opt.sh -f 'Default\|opaque'
1598}
1599
Gilles Peskine801c4332023-04-28 21:04:28 +02001600component_test_psa_inject_entropy () {
1601 msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
1602 scripts/config.py full
1603 scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
1604 scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
1605 scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1606 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1607 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
1608 scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
Gilles Peskine21570cf2023-12-22 11:49:50 +01001609 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine801c4332023-04-28 21:04:28 +02001610
1611 msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
1612 make test
1613}
1614
Andrzej Kurek06969fc2023-04-12 10:34:50 -04001615component_test_sw_inet_pton () {
1616 msg "build: default plus MBEDTLS_TEST_SW_INET_PTON"
1617
1618 # MBEDTLS_TEST_HOOKS required for x509_crt_parse_cn_inet_pton
1619 scripts/config.py set MBEDTLS_TEST_HOOKS
1620 make CFLAGS="-DMBEDTLS_TEST_SW_INET_PTON"
1621
1622 msg "test: default plus MBEDTLS_TEST_SW_INET_PTON"
1623 make test
1624}
1625
Valerio Settia41654d2024-02-08 10:33:11 +01001626component_full_no_pkparse_pkwrite() {
1627 msg "build: full without pkparse and pkwrite"
1628
1629 scripts/config.py crypto_full
1630 scripts/config.py unset MBEDTLS_PK_PARSE_C
1631 scripts/config.py unset MBEDTLS_PK_WRITE_C
1632
Valerio Settia41654d2024-02-08 10:33:11 +01001633 make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1634
1635 # Ensure that PK_[PARSE|WRITE]_C were not re-enabled accidentally (additive config).
1636 not grep mbedtls_pk_parse_key library/pkparse.o
1637 not grep mbedtls_pk_write_key_der library/pkwrite.o
1638
1639 msg "test: full without pkparse and pkwrite"
1640 make test
1641}
1642
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001643component_test_crypto_full_md_light_only () {
1644 msg "build: crypto_full with only the light subset of MD"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001645 scripts/config.py crypto_full
Gilles Peskine884b4622023-07-20 20:11:51 +02001646 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001647 # Disable MD
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001648 scripts/config.py unset MBEDTLS_MD_C
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001649 # Disable direct dependencies of MD_C
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001650 scripts/config.py unset MBEDTLS_HKDF_C
1651 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
Nick Child89e82e12022-11-09 10:36:10 -06001652 scripts/config.py unset MBEDTLS_PKCS7_C
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001653 # Disable indirect dependencies of MD_C
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001654 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01001655 # Disable things that would auto-enable MD_C
1656 scripts/config.py unset MBEDTLS_PKCS5_C
1657
Manuel Pégourié-Gonnard1b5ffc62023-03-14 10:11:20 +01001658 # Note: MD-light is auto-enabled in build_info.h by modules that need it,
1659 # which we haven't disabled, so no need to explicitly enable it.
Gilles Peskine21570cf2023-12-22 11:49:50 +01001660 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001661
Manuel Pégourié-Gonnard0d415212023-02-23 13:02:13 +01001662 # Make sure we don't have the HMAC functions, but the hashing functions
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001663 not grep mbedtls_md_hmac library/md.o
Manuel Pégourié-Gonnard0d415212023-02-23 13:02:13 +01001664 grep mbedtls_md library/md.o
Manuel Pégourié-Gonnardb9b630d2023-02-16 19:07:31 +01001665
1666 msg "test: crypto_full with only the light subset of MD"
Gilles Peskine21570cf2023-12-22 11:49:50 +01001667 make test
Przemek Stekielfe2367a2022-04-28 15:44:18 +02001668}
1669
Manuel Pégourié-Gonnard88bae8b2024-01-08 10:56:35 +01001670component_test_full_no_cipher_no_psa_crypto () {
Valerio Settidf17a102023-10-23 14:14:19 +02001671 msg "build: full no CIPHER no PSA_CRYPTO_C"
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001672 scripts/config.py full
1673 scripts/config.py unset MBEDTLS_CIPHER_C
Gilles Peskine9b8dead2023-08-09 19:48:42 +02001674 # Don't pull in cipher via PSA mechanisms
1675 # (currently ignored anyway because we completely disable PSA)
1676 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Valerio Setti4529d652023-10-24 11:51:58 +02001677 # Disable features that depend on CIPHER_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001678 scripts/config.py unset MBEDTLS_CMAC_C
1679 scripts/config.py unset MBEDTLS_NIST_KW_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001680 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
Gilles Peskine64996c32024-01-23 20:25:47 +01001681 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CLIENT
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001682 scripts/config.py unset MBEDTLS_SSL_TLS_C
1683 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Valerio Setti4529d652023-10-24 11:51:58 +02001684 # Disable features that depend on PSA_CRYPTO_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001685 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
1686 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001687 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Raef Colesa7e03ad2022-09-28 09:32:48 +01001688 scripts/config.py unset MBEDTLS_LMS_C
Raef Coles47bccb72022-09-28 12:00:20 +01001689 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001690
Valerio Settidf17a102023-10-23 14:14:19 +02001691 msg "test: full no CIPHER no PSA_CRYPTO_C"
Gilles Peskine21570cf2023-12-22 11:49:50 +01001692 make test
Przemek Stekiel10f3a602022-05-02 10:55:33 +02001693}
1694
Valerio Setti7e710e82023-08-25 09:14:15 +02001695# This is a common configurator and test function that is used in:
Manuel Pégourié-Gonnard88bae8b2024-01-08 10:56:35 +01001696# - component_test_full_no_cipher_with_psa_crypto
1697# - component_test_full_no_cipher_with_psa_crypto_config
Valerio Setti7e710e82023-08-25 09:14:15 +02001698# It accepts 2 input parameters:
1699# - $1: boolean value which basically reflects status of MBEDTLS_PSA_CRYPTO_CONFIG
1700# - $2: a text string which describes the test component
Valerio Setti5b4039f2023-10-24 13:41:44 +02001701common_test_full_no_cipher_with_psa_crypto () {
Valerio Setti7e710e82023-08-25 09:14:15 +02001702 USE_CRYPTO_CONFIG="$1"
1703 COMPONENT_DESCRIPTION="$2"
1704
1705 msg "build: $COMPONENT_DESCRIPTION"
1706
1707 scripts/config.py full
1708 scripts/config.py unset MBEDTLS_CIPHER_C
1709
1710 if [ "$USE_CRYPTO_CONFIG" -eq 1 ]; then
Valerio Setti862021a2023-10-24 13:52:06 +02001711 # The built-in implementation of the following algs/key-types depends
1712 # on CIPHER_C so we disable them.
1713 # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
1714 # so we keep them enabled.
Valerio Setti7e710e82023-08-25 09:14:15 +02001715 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
Valerio Setti7e710e82023-08-25 09:14:15 +02001716 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CMAC
1717 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
1718 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
1719 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CFB
1720 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CTR
1721 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
1722 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_OFB
1723 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_STREAM_CIPHER
Valerio Setti7e710e82023-08-25 09:14:15 +02001724 scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
Valerio Setti7e710e82023-08-25 09:14:15 +02001725 else
1726 # Don't pull in cipher via PSA mechanisms
1727 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Valerio Setti287f6d12023-10-24 14:12:59 +02001728 # Disable cipher modes/keys that make PSA depend on CIPHER_C.
1729 # Keep CHACHA20 and CHACHAPOLY enabled since they do not depend on CIPHER_C.
1730 scripts/config.py unset-all MBEDTLS_CIPHER_MODE
Valerio Setti7e710e82023-08-25 09:14:15 +02001731 fi
Valerio Settic84d9402023-10-23 14:58:25 +02001732 # The following modules directly depends on CIPHER_C
Valerio Setti7e710e82023-08-25 09:14:15 +02001733 scripts/config.py unset MBEDTLS_CMAC_C
Valerio Setti7e710e82023-08-25 09:14:15 +02001734 scripts/config.py unset MBEDTLS_NIST_KW_C
Valerio Settifb0b0ff2023-10-23 14:58:55 +02001735
Gilles Peskine21570cf2023-12-22 11:49:50 +01001736 make
Gilles Peskine636c26a2020-03-04 20:46:15 +01001737
Valerio Setti7e710e82023-08-25 09:14:15 +02001738 # Ensure that CIPHER_C was not re-enabled
1739 not grep mbedtls_cipher_init library/cipher.o
1740
1741 msg "test: $COMPONENT_DESCRIPTION"
1742 make test
1743}
1744
Manuel Pégourié-Gonnard88bae8b2024-01-08 10:56:35 +01001745component_test_full_no_cipher_with_psa_crypto() {
Valerio Setti5b4039f2023-10-24 13:41:44 +02001746 common_test_full_no_cipher_with_psa_crypto 0 "full no CIPHER no CRYPTO_CONFIG"
Valerio Setti7e710e82023-08-25 09:14:15 +02001747}
1748
Manuel Pégourié-Gonnard88bae8b2024-01-08 10:56:35 +01001749component_test_full_no_cipher_with_psa_crypto_config() {
Valerio Setti5b4039f2023-10-24 13:41:44 +02001750 common_test_full_no_cipher_with_psa_crypto 1 "full no CIPHER"
Valerio Setti7e710e82023-08-25 09:14:15 +02001751}
1752
Valerio Settibdfecb62023-11-07 15:37:20 +01001753component_test_full_no_ccm() {
1754 msg "build: full no PSA_WANT_ALG_CCM"
1755
1756 # Full config enables:
1757 # - USE_PSA_CRYPTO so that TLS code dispatches cipher/AEAD to PSA
1758 # - CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
1759 scripts/config.py full
1760
1761 # Disable PSA_WANT_ALG_CCM so that CCM is not supported in PSA. CCM_C is still
1762 # enabled, but not used from TLS since USE_PSA is set.
1763 # This is helpful to ensure that TLS tests below have proper dependencies.
1764 #
1765 # Note: also PSA_WANT_ALG_CCM_STAR_NO_TAG is enabled, but it does not cause
1766 # PSA_WANT_ALG_CCM to be re-enabled.
1767 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM
1768
Gilles Peskine21570cf2023-12-22 11:49:50 +01001769 make
Valerio Settibdfecb62023-11-07 15:37:20 +01001770
1771 msg "test: full no PSA_WANT_ALG_CCM"
Valerio Settiff2b06a2023-11-08 12:35:36 +01001772 make test
Valerio Settibdfecb62023-11-07 15:37:20 +01001773}
1774
1775component_test_full_no_ccm_star_no_tag() {
1776 msg "build: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
1777
1778 # Full config enables CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
1779 scripts/config.py full
1780
1781 # Disable CCM_STAR_NO_TAG, which is the target of this test, as well as all
1782 # other components that enable MBEDTLS_PSA_BUILTIN_CIPHER internal symbol.
1783 # This basically disables all unauthenticated ciphers on the PSA side, while
1784 # keeping AEADs enabled.
1785 #
1786 # Note: PSA_WANT_ALG_CCM is enabled, but it does not cause
1787 # PSA_WANT_ALG_CCM_STAR_NO_TAG to be re-enabled.
1788 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1789 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_STREAM_CIPHER
1790 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
1791 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
1792 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
1793 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
1794 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
1795 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
1796
Gilles Peskine21570cf2023-12-22 11:49:50 +01001797 make
Valerio Settibdfecb62023-11-07 15:37:20 +01001798
1799 # Ensure MBEDTLS_PSA_BUILTIN_CIPHER was not enabled
Valerio Settibdfecb62023-11-07 15:37:20 +01001800 not grep mbedtls_psa_cipher library/psa_crypto_cipher.o
Valerio Settiff2b06a2023-11-08 12:35:36 +01001801
1802 msg "test: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
Gilles Peskine636c26a2020-03-04 20:46:15 +01001803 make test
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02001804}
Gilles Peskine636c26a2020-03-04 20:46:15 +01001805
Valerio Settie1655b82023-01-03 15:35:25 +01001806component_test_full_no_bignum () {
1807 msg "build: full minus bignum"
1808 scripts/config.py full
1809 scripts/config.py unset MBEDTLS_BIGNUM_C
1810 # Direct dependencies of bignum
1811 scripts/config.py unset MBEDTLS_ECP_C
1812 scripts/config.py unset MBEDTLS_RSA_C
1813 scripts/config.py unset MBEDTLS_DHM_C
1814 # Direct dependencies of ECP
1815 scripts/config.py unset MBEDTLS_ECDH_C
1816 scripts/config.py unset MBEDTLS_ECDSA_C
1817 scripts/config.py unset MBEDTLS_ECJPAKE_C
1818 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Setti22d0a792023-06-14 17:23:19 +02001819 # Disable what auto-enables ECP_LIGHT
1820 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1821 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
Valerio Settie1655b82023-01-03 15:35:25 +01001822 # Indirect dependencies of ECP
1823 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1824 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1825 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1826 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1827 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1828 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
1829 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
1830 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
1831 # Direct dependencies of DHM
1832 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1833 # Direct dependencies of RSA
1834 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1835 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1836 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1837 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1838 # PK and its dependencies
1839 scripts/config.py unset MBEDTLS_PK_C
1840 scripts/config.py unset MBEDTLS_PK_PARSE_C
1841 scripts/config.py unset MBEDTLS_PK_WRITE_C
1842 scripts/config.py unset MBEDTLS_X509_USE_C
1843 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
1844 scripts/config.py unset MBEDTLS_X509_CRL_PARSE_C
1845 scripts/config.py unset MBEDTLS_X509_CSR_PARSE_C
1846 scripts/config.py unset MBEDTLS_X509_CREATE_C
1847 scripts/config.py unset MBEDTLS_X509_CRT_WRITE_C
1848 scripts/config.py unset MBEDTLS_X509_CSR_WRITE_C
1849 scripts/config.py unset MBEDTLS_PKCS7_C
1850 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
1851 scripts/config.py unset MBEDTLS_SSL_ASYNC_PRIVATE
1852 scripts/config.py unset MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
1853
Gilles Peskine21570cf2023-12-22 11:49:50 +01001854 make
Valerio Settie1655b82023-01-03 15:35:25 +01001855
1856 msg "test: full minus bignum"
1857 make test
1858}
1859
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001860component_test_tls1_2_default_stream_cipher_only () {
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001861 msg "build: default with only stream cipher"
1862
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001863 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001864 scripts/config.py unset MBEDTLS_GCM_C
1865 scripts/config.py unset MBEDTLS_CCM_C
1866 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Ronald Crona3f385d2024-03-18 10:25:37 +01001867 #Disable TLS 1.3 (as no AEAD)
1868 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001869 # 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 +02001870 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001871 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001872 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001873 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1874 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001875 # Modules that depend on AEAD
Przemek Stekield582a012022-09-28 07:59:01 +02001876 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001877 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001878
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001879 make
1880
1881 msg "test: default with only stream cipher"
1882 make test
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001883
1884 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001885}
1886
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001887component_test_tls1_2_default_stream_cipher_only_use_psa () {
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001888 msg "build: default with only stream cipher use psa"
Przemek Stekiel9550c052022-09-28 09:51:55 +02001889
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001890 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001891 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel9550c052022-09-28 09:51:55 +02001892 scripts/config.py unset MBEDTLS_GCM_C
1893 scripts/config.py unset MBEDTLS_CCM_C
1894 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Ronald Crona3f385d2024-03-18 10:25:37 +01001895 #Disable TLS 1.3 (as no AEAD)
1896 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001897 # 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 +02001898 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001899 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekiel9550c052022-09-28 09:51:55 +02001900 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001901 # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1902 scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001903 # Modules that depend on AEAD
Przemek Stekiel9550c052022-09-28 09:51:55 +02001904 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001905 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel9550c052022-09-28 09:51:55 +02001906
Przemek Stekiel9550c052022-09-28 09:51:55 +02001907 make
1908
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001909 msg "test: default with only stream cipher use psa"
Przemek Stekiel9550c052022-09-28 09:51:55 +02001910 make test
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001911
1912 # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
Przemek Stekiel9550c052022-09-28 09:51:55 +02001913}
Przemek Stekiel11c362a2022-09-27 13:34:31 +02001914
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001915component_test_tls1_2_default_cbc_legacy_cipher_only () {
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001916 msg "build: default with only CBC-legacy cipher"
1917
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001918 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001919 scripts/config.py unset MBEDTLS_GCM_C
1920 scripts/config.py unset MBEDTLS_CCM_C
1921 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Ronald Crona3f385d2024-03-18 10:25:37 +01001922 #Disable TLS 1.3 (as no AEAD)
1923 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001924 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1925 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1926 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001927 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001928 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001929 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001930 # Modules that depend on AEAD
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001931 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001932 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001933
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001934 make
1935
1936 msg "test: default with only CBC-legacy cipher"
1937 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001938
1939 msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1940 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001941}
1942
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001943component_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001944 msg "build: default with only CBC-legacy cipher use psa"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001945
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001946 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001947 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001948 scripts/config.py unset MBEDTLS_GCM_C
1949 scripts/config.py unset MBEDTLS_CCM_C
1950 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Ronald Crona3f385d2024-03-18 10:25:37 +01001951 #Disable TLS 1.3 (as no AEAD)
1952 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001953 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1954 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1955 # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001956 scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001957 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001958 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001959 # Modules that depend on AEAD
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001960 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001961 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001962
Przemek Stekielb0de1c02022-09-28 10:23:22 +02001963 make
1964
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001965 msg "test: default with only CBC-legacy cipher use psa"
1966 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001967
1968 msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1969 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001970}
1971
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001972component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001973 msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1974
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001975 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001976 scripts/config.py unset MBEDTLS_GCM_C
1977 scripts/config.py unset MBEDTLS_CCM_C
1978 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Ronald Crona3f385d2024-03-18 10:25:37 +01001979 #Disable TLS 1.3 (as no AEAD)
1980 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Przemek Stekiel68db0d22022-09-29 08:32:25 +02001981 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1982 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1983 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1984 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1985 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001986 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02001987 # Modules that depend on AEAD
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001988 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02001989 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001990
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001991 make
1992
1993 msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1994 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02001995
1996 msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1997 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02001998}
1999
Przemek Stekiel48a6a662022-09-29 15:22:01 +02002000component_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
2001 msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
Przemek Stekiel0cc34662022-09-28 12:06:57 +02002002
2003 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
Przemek Stekiel68db0d22022-09-29 08:32:25 +02002004 # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
Przemek Stekiel0cc34662022-09-28 12:06:57 +02002005 scripts/config.py unset MBEDTLS_GCM_C
2006 scripts/config.py unset MBEDTLS_CCM_C
2007 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Ronald Crona3f385d2024-03-18 10:25:37 +01002008 #Disable TLS 1.3 (as no AEAD)
2009 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Przemek Stekiel68db0d22022-09-29 08:32:25 +02002010 # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
2011 scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
2012 # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
2013 scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
2014 # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
Przemek Stekiel0cc34662022-09-28 12:06:57 +02002015 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Przemek Stekiel6a5cc742022-10-03 09:04:16 +02002016 # Modules that depend on AEAD
Przemek Stekiel0cc34662022-09-28 12:06:57 +02002017 scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
Przemek Stekiel52a428b2022-10-10 08:47:13 +02002018 scripts/config.py unset MBEDTLS_SSL_TICKET_C
Przemek Stekiel0cc34662022-09-28 12:06:57 +02002019
Przemek Stekiel0cc34662022-09-28 12:06:57 +02002020 make
2021
Przemek Stekiel48a6a662022-09-29 15:22:01 +02002022 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02002023 make test
Przemek Stekiel48a6a662022-09-29 15:22:01 +02002024
2025 msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
2026 tests/ssl-opt.sh -f "TLS 1.2"
Przemek Stekielb0de1c02022-09-28 10:23:22 +02002027}
2028
Valerio Setti9f0ec532022-11-08 13:03:24 +01002029# We're not aware of any other (open source) implementation of EC J-PAKE in TLS
2030# that we could use for interop testing. However, we now have sort of two
2031# implementations ourselves: one using PSA, the other not. At least test that
2032# these two interoperate with each other.
2033component_test_tls1_2_ecjpake_compatibility() {
2034 msg "build: TLS1.2 server+client w/ EC-JPAKE w/o USE_PSA"
2035 scripts/config.py set MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
Gilles Peskineedc84562023-09-20 15:03:18 +02002036 # Explicitly make lib first to avoid a race condition:
2037 # https://github.com/Mbed-TLS/mbedtls/issues/8229
2038 make lib
Valerio Setti9f0ec532022-11-08 13:03:24 +01002039 make -C programs ssl/ssl_server2 ssl/ssl_client2
2040 cp programs/ssl/ssl_server2 s2_no_use_psa
2041 cp programs/ssl/ssl_client2 c2_no_use_psa
2042
2043 msg "build: TLS1.2 server+client w/ EC-JPAKE w/ USE_PSA"
2044 scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
2045 make clean
Gilles Peskineedc84562023-09-20 15:03:18 +02002046 make lib
Valerio Setti9f0ec532022-11-08 13:03:24 +01002047 make -C programs ssl/ssl_server2 ssl/ssl_client2
2048 make -C programs test/udp_proxy test/query_compile_time_config
2049
Valerio Setti70e02902022-12-02 16:21:56 +01002050 msg "test: server w/o USE_PSA - client w/ USE_PSA, text password"
2051 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
2052 msg "test: server w/o USE_PSA - client w/ USE_PSA, opaque password"
2053 P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password client only, working, TLS"
2054 msg "test: client w/o USE_PSA - server w/ USE_PSA, text password"
2055 P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
2056 msg "test: client w/o USE_PSA - server w/ USE_PSA, opaque password"
2057 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 +01002058
2059 rm s2_no_use_psa c2_no_use_psa
2060}
2061
Gilles Peskine636c26a2020-03-04 20:46:15 +01002062component_test_everest () {
2063 msg "build: Everest ECDH context (ASan build)" # ~ 6 min
2064 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
2065 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
2066 make
2067
2068 msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
2069 make test
2070
Gilles Peskine6848d172023-11-02 19:58:03 +01002071 msg "test: metatests (clang, ASan)"
David Horstmann9de6edd2024-01-17 14:53:08 +00002072 tests/scripts/run-metatests.sh any asan poison
Gilles Peskine6848d172023-11-02 19:58:03 +01002073
Gilles Peskine636c26a2020-03-04 20:46:15 +01002074 msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
2075 tests/ssl-opt.sh -f ECDH
2076
2077 msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
2078 # Exclude some symmetric ciphers that are redundant here to gain time.
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02002079 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
Gilles Peskine636c26a2020-03-04 20:46:15 +01002080}
2081
Gilles Peskined3beca92020-07-03 00:15:37 +02002082component_test_everest_curve25519_only () {
2083 msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
Gilles Peskined3beca92020-07-03 00:15:37 +02002084 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
2085 scripts/config.py unset MBEDTLS_ECDSA_C
2086 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2087 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
TRodziewicz7c1d41d2021-04-23 13:33:44 +02002088 scripts/config.py unset MBEDTLS_ECJPAKE_C
Gilles Peskined3beca92020-07-03 00:15:37 +02002089 # Disable all curves
Valerio Setti2e0275d2023-07-28 16:33:13 +02002090 scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
Gilles Peskined3beca92020-07-03 00:15:37 +02002091 scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
2092
Dave Rodgman17127e92023-12-14 16:42:48 +00002093 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskined3beca92020-07-03 00:15:37 +02002094
2095 msg "test: Everest ECDH context, only Curve25519" # ~ 50s
2096 make test
2097}
2098
Gilles Peskine8f073122018-11-27 15:58:47 +01002099component_test_small_ssl_out_content_len () {
2100 msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002101 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
2102 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Dave Rodgman17127e92023-12-14 16:42:48 +00002103 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine8f073122018-11-27 15:58:47 +01002104 make
Hanno Beckerd5ba5ef2017-09-28 12:53:51 +01002105
Gilles Peskine8f073122018-11-27 15:58:47 +01002106 msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002107 tests/ssl-opt.sh -f "Max fragment\|Large packet"
Gilles Peskine8f073122018-11-27 15:58:47 +01002108}
Angus Grattonc4dd0732018-04-11 16:28:39 +10002109
Gilles Peskine8f073122018-11-27 15:58:47 +01002110component_test_small_ssl_in_content_len () {
2111 msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002112 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
2113 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
Dave Rodgman17127e92023-12-14 16:42:48 +00002114 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine8f073122018-11-27 15:58:47 +01002115 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10002116
Gilles Peskine8f073122018-11-27 15:58:47 +01002117 msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002118 tests/ssl-opt.sh -f "Max fragment"
Gilles Peskine8f073122018-11-27 15:58:47 +01002119}
Angus Grattonc4dd0732018-04-11 16:28:39 +10002120
Gilles Peskine8f073122018-11-27 15:58:47 +01002121component_test_small_ssl_dtls_max_buffering () {
2122 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002123 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
Dave Rodgman17127e92023-12-14 16:42:48 +00002124 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine8f073122018-11-27 15:58:47 +01002125 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10002126
Gilles Peskine8f073122018-11-27 15:58:47 +01002127 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002128 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 +01002129}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01002130
Gilles Peskine8f073122018-11-27 15:58:47 +01002131component_test_small_mbedtls_ssl_dtls_max_buffering () {
2132 msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
Gilles Peskine636c26a2020-03-04 20:46:15 +01002133 scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
Dave Rodgman17127e92023-12-14 16:42:48 +00002134 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine8f073122018-11-27 15:58:47 +01002135 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01002136
Gilles Peskine8f073122018-11-27 15:58:47 +01002137 msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002138 tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
Gilles Peskine8f073122018-11-27 15:58:47 +01002139}
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01002140
Gilles Peskine75cc7712019-09-06 19:47:17 +02002141component_test_psa_collect_statuses () {
2142 msg "build+test: psa_collect_statuses" # ~30s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02002143 scripts/config.py full
Gilles Peskine21570cf2023-12-22 11:49:50 +01002144 tests/scripts/psa_collect_statuses.py
Gilles Peskine75cc7712019-09-06 19:47:17 +02002145 # Check that psa_crypto_init() succeeded at least once
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002146 grep -q '^0:psa_crypto_init:' tests/statuses.log
Gilles Peskine75cc7712019-09-06 19:47:17 +02002147 rm -f tests/statuses.log
2148}
2149
Gilles Peskine8f073122018-11-27 15:58:47 +01002150component_test_full_cmake_clang () {
2151 msg "build: cmake, full config, clang" # ~ 50s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002152 scripts/config.py full
Gilles Peskineda6017c2022-10-30 21:02:40 +01002153 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 +01002154 make
Hanno Becker2f5aa4c2018-08-24 14:43:44 +01002155
k-stachowiak0291cb72019-06-26 15:52:12 +02002156 msg "test: main suites (full config, clang)" # ~ 5s
Gilles Peskine8f073122018-11-27 15:58:47 +01002157 make test
Manuel Pégourié-Gonnard3895f5a2014-03-27 14:44:04 +01002158
Gilles Peskineda6017c2022-10-30 21:02:40 +01002159 msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
2160 programs/test/cpp_dummy_build
2161
Gilles Peskine6848d172023-11-02 19:58:03 +01002162 msg "test: metatests (clang)"
Gilles Peskine102aea22023-11-03 18:05:38 +01002163 tests/scripts/run-metatests.sh any pthread
Gilles Peskine6848d172023-11-02 19:58:03 +01002164
Gilles Peskine82b27272019-06-14 18:27:03 +02002165 msg "program demos (full config, clang)" # ~10s
2166 tests/scripts/run_demos.py
2167
k-stachowiak0291cb72019-06-26 15:52:12 +02002168 msg "test: psa_constant_names (full config, clang)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002169 tests/scripts/test_psa_constant_names.py
Gilles Peskine69e8f7f2020-02-26 19:51:43 +01002170
Gilles Peskine8f073122018-11-27 15:58:47 +01002171 msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002172 tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02002173
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02002174 msg "test: compat.sh NULL (full config)" # ~ 2 min
Gilles Peskinee29203b2023-08-27 21:43:00 +02002175 tests/compat.sh -e '^$' -f 'NULL'
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02002176
Gilles Peskine8f073122018-11-27 15:58:47 +01002177 msg "test: compat.sh ARIA + ChachaPoly"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01002178 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Gilles Peskine8f073122018-11-27 15:58:47 +01002179}
Manuel Pégourié-Gonnarde73b2632014-07-12 04:00:00 +02002180
Gilles Peskine0c671602022-11-29 16:01:41 +01002181skip_suites_without_constant_flow () {
2182 # Skip the test suites that don't have any constant-flow annotations.
2183 # This will need to be adjusted if we ever start declaring things as
2184 # secret from macros or functions inside tests/include or tests/src.
2185 SKIP_TEST_SUITES=$(
2186 git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
2187 sed 's/test_suite_//; s/\.function$//' |
2188 tr '\n' ,)
2189 export SKIP_TEST_SUITES
2190}
2191
Dave Rodgman246210e2023-07-31 18:07:44 +01002192skip_all_except_given_suite () {
2193 # Skip all but the given test suite
2194 SKIP_TEST_SUITES=$(
2195 ls -1 tests/suites/test_suite_*.function |
2196 grep -v $1.function |
2197 sed 's/tests.suites.test_suite_//; s/\.function$//' |
2198 tr '\n' ,)
2199 export SKIP_TEST_SUITES
2200}
2201
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02002202component_test_memsan_constant_flow () {
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02002203 # This tests both (1) accesses to undefined memory, and (2) branches or
2204 # memory access depending on secret values. To distinguish between those:
2205 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
2206 # - or alternatively, change the build type to MemSanDbg, which enables
2207 # origin tracking and nicer stack traces (which are useful for debugging
2208 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
Neil Armstrong0ab7a232022-03-18 09:57:32 +01002209 msg "build: cmake MSan (clang), full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
2210 scripts/config.py full
2211 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
2212 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2213 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
2214 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
2215 make
2216
2217 msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO, Msan + constant flow)"
2218 make test
2219}
2220
2221component_test_memsan_constant_flow_psa () {
2222 # This tests both (1) accesses to undefined memory, and (2) branches or
2223 # memory access depending on secret values. To distinguish between those:
2224 # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
2225 # - or alternatively, change the build type to MemSanDbg, which enables
2226 # origin tracking and nicer stack traces (which are useful for debugging
2227 # anyway), and check if the origin was TEST_CF_SECRET() or something else.
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02002228 msg "build: cmake MSan (clang), full config with constant flow testing"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02002229 scripts/config.py full
2230 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
2231 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
2232 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
2233 make
2234
Manuel Pégourié-Gonnard0b2112d2020-07-22 11:09:28 +02002235 msg "test: main suites (Msan + constant flow)"
Manuel Pégourié-Gonnard6240def2020-07-10 09:35:54 +02002236 make test
2237}
2238
Bence Szépkúti0354d042023-12-06 16:14:37 +01002239component_release_test_valgrind_constant_flow () {
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02002240 # This tests both (1) everything that valgrind's memcheck usually checks
2241 # (heap buffer overflows, use of uninitialized memory, use-after-free,
2242 # etc.) and (2) branches or memory access depending on secret values,
2243 # which will be reported as uninitialized memory. To distinguish between
2244 # secret and actually uninitialized:
2245 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
2246 # - or alternatively, build with debug info and manually run the offending
2247 # test suite with valgrind --track-origins=yes, then check if the origin
2248 # was TEST_CF_SECRET() or something else.
Neil Armstrong0ab7a232022-03-18 09:57:32 +01002249 msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
2250 scripts/config.py full
2251 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
2252 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine0c671602022-11-29 16:01:41 +01002253 skip_suites_without_constant_flow
Neil Armstrong0ab7a232022-03-18 09:57:32 +01002254 cmake -D CMAKE_BUILD_TYPE:String=Release .
2255 make
2256
2257 # this only shows a summary of the results (how many of each type)
2258 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine0c671602022-11-29 16:01:41 +01002259 msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, valgrind + constant flow)"
Neil Armstrong0ab7a232022-03-18 09:57:32 +01002260 make memcheck
Dave Rodgman246210e2023-07-31 18:07:44 +01002261
2262 # Test asm path in constant time module - by default, it will test the plain C
2263 # path under Valgrind or Memsan. Running only the constant_time tests is fast (<1s)
2264 msg "test: valgrind asm constant_time"
2265 scripts/config.py --force set MBEDTLS_TEST_CONSTANT_FLOW_ASM
2266 skip_all_except_given_suite test_suite_constant_time
2267 cmake -D CMAKE_BUILD_TYPE:String=Release .
2268 make clean
2269 make
2270 make memcheck
Neil Armstrong0ab7a232022-03-18 09:57:32 +01002271}
2272
Bence Szépkúti0354d042023-12-06 16:14:37 +01002273component_release_test_valgrind_constant_flow_psa () {
Neil Armstrong0ab7a232022-03-18 09:57:32 +01002274 # This tests both (1) everything that valgrind's memcheck usually checks
2275 # (heap buffer overflows, use of uninitialized memory, use-after-free,
2276 # etc.) and (2) branches or memory access depending on secret values,
2277 # which will be reported as uninitialized memory. To distinguish between
2278 # secret and actually uninitialized:
2279 # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
2280 # - or alternatively, build with debug info and manually run the offending
2281 # test suite with valgrind --track-origins=yes, then check if the origin
2282 # was TEST_CF_SECRET() or something else.
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02002283 msg "build: cmake release GCC, full config with constant flow testing"
2284 scripts/config.py full
2285 scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
Gilles Peskine0c671602022-11-29 16:01:41 +01002286 skip_suites_without_constant_flow
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02002287 cmake -D CMAKE_BUILD_TYPE:String=Release .
2288 make
2289
2290 # this only shows a summary of the results (how many of each type)
2291 # details are left in Testing/<date>/DynamicAnalysis.xml
Gilles Peskine0c671602022-11-29 16:01:41 +01002292 msg "test: some suites (valgrind + constant flow)"
Manuel Pégourié-Gonnard73afa372020-08-19 10:27:38 +02002293 make memcheck
2294}
2295
Janos Follath9338cac2023-10-04 18:55:39 +01002296component_test_tsan () {
2297 msg "build: TSan (clang)"
Paul Elliott356597f2023-12-01 18:09:41 +00002298 scripts/config.py full
Janos Follath9338cac2023-10-04 18:55:39 +01002299 scripts/config.py set MBEDTLS_THREADING_C
2300 scripts/config.py set MBEDTLS_THREADING_PTHREAD
Ryanb0b3c0d2024-03-01 17:30:12 +00002301 # Self-tests do not currently use multiple threads.
2302 scripts/config.py unset MBEDTLS_SELF_TEST
Janos Follath9338cac2023-10-04 18:55:39 +01002303
Ryan6caf84f2024-03-05 13:57:00 +00002304 # The deprecated MBEDTLS_PSA_CRYPTO_SE_C interface is not thread safe.
2305 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
2306
Janos Follath9338cac2023-10-04 18:55:39 +01002307 CC=clang cmake -D CMAKE_BUILD_TYPE:String=TSan .
2308 make
2309
2310 msg "test: main suites (TSan)"
2311 make test
2312}
2313
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002314component_test_default_no_deprecated () {
Gilles Peskine8386ea22020-04-30 09:07:29 +02002315 # Test that removing the deprecated features from the default
2316 # configuration leaves something consistent.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002317 msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
2318 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
Dave Rodgmanea03ef92023-12-19 12:19:59 +00002319 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002320
2321 msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
2322 make test
2323}
2324
2325component_test_full_no_deprecated () {
Gilles Peskine30de2e82020-04-20 21:39:22 +02002326 msg "build: make, full_no_deprecated config" # ~ 30s
2327 scripts/config.py full_no_deprecated
Dave Rodgman84125a12024-01-02 11:42:38 +00002328 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002329
Gilles Peskine30de2e82020-04-20 21:39:22 +02002330 msg "test: make, full_no_deprecated config" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002331 make test
Valerio Setti41b5fb62023-01-09 12:20:45 +01002332
2333 msg "test: ensure that X509 has no direct dependency on BIGNUM_C"
2334 not grep mbedtls_mpi library/libmbedx509.a
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002335}
2336
Gilles Peskine8386ea22020-04-30 09:07:29 +02002337component_test_full_no_deprecated_deprecated_warning () {
2338 # Test that there is nothing deprecated in "full_no_deprecated".
2339 # A deprecated feature would trigger a warning (made fatal) from
2340 # MBEDTLS_DEPRECATED_WARNING.
Gilles Peskine30de2e82020-04-20 21:39:22 +02002341 msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
2342 scripts/config.py full_no_deprecated
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002343 scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
2344 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Dave Rodgman84125a12024-01-02 11:42:38 +00002345 make CFLAGS='-O -Werror -Wall -Wextra'
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002346
Gilles Peskine30de2e82020-04-20 21:39:22 +02002347 msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002348 make test
2349}
2350
Gilles Peskine8386ea22020-04-30 09:07:29 +02002351component_test_full_deprecated_warning () {
2352 # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
2353 # with only certain whitelisted types of warnings.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002354 msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002355 scripts/config.py full
2356 scripts/config.py set MBEDTLS_DEPRECATED_WARNING
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002357 # Expect warnings from '#warning' directives in check_config.h.
Dave Rodgmanbc8e61d2023-12-19 14:07:15 +00002358 # Note that gcc is required to allow the use of -Wno-error=cpp, which allows us to
2359 # display #warning messages without them being treated as errors.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002360 make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
Manuel Pégourié-Gonnard6b368922018-02-20 12:02:07 +01002361
Gilles Peskine8386ea22020-04-30 09:07:29 +02002362 msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
2363 # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
2364 # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002365 # Expect warnings from '#warning' directives in check_config.h and
2366 # from the use of deprecated functions in test suites.
Gilles Peskine21570cf2023-12-22 11:49:50 +01002367 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 +01002368
Gilles Peskine1093d9f2020-04-13 01:03:21 +02002369 msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
2370 make test
Gilles Peskine82b27272019-06-14 18:27:03 +02002371
2372 msg "program demos: full config + MBEDTLS_TEST_DEPRECATED" # ~10s
2373 tests/scripts/run_demos.py
Gilles Peskine8f073122018-11-27 15:58:47 +01002374}
Jaeden Ameroed93bdc2018-11-02 16:57:24 +00002375
Gilles Peskineec541fe2020-01-31 14:24:14 +01002376# Check that the specified libraries exist and are empty.
2377are_empty_libraries () {
2378 nm "$@" >/dev/null 2>/dev/null
2379 ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
2380}
2381
2382component_build_crypto_default () {
2383 msg "build: make, crypto only"
2384 scripts/config.py crypto
Gilles Peskine6bb39152020-02-03 11:59:20 +01002385 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002386 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002387}
2388
2389component_build_crypto_full () {
2390 msg "build: make, crypto only, full config"
2391 scripts/config.py crypto_full
Gilles Peskine21570cf2023-12-22 11:49:50 +01002392 make CFLAGS='-O1 -Werror'
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002393 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002394}
2395
Gilles Peskinefc4f11b2022-10-21 19:34:54 +02002396component_test_crypto_for_psa_service () {
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002397 msg "build: make, config for PSA crypto service"
2398 scripts/config.py crypto
2399 scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
2400 # Disable things that are not needed for just cryptography, to
2401 # reach a configuration that would be typical for a PSA cryptography
2402 # service providing all implemented PSA algorithms.
2403 # System stuff
2404 scripts/config.py unset MBEDTLS_ERROR_C
2405 scripts/config.py unset MBEDTLS_TIMING_C
Gilles Peskine78bffd12022-10-25 21:02:33 +02002406 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002407 # Crypto stuff with no PSA interface
2408 scripts/config.py unset MBEDTLS_BASE64_C
Gilles Peskine649e04e2022-10-25 21:05:57 +02002409 # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
Gilles Peskineb06f0712022-10-25 21:06:11 +02002410 scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
Gilles Peskine649e04e2022-10-25 21:05:57 +02002411 # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002412 scripts/config.py unset MBEDTLS_NIST_KW_C
2413 scripts/config.py unset MBEDTLS_PEM_PARSE_C
2414 scripts/config.py unset MBEDTLS_PEM_WRITE_C
2415 scripts/config.py unset MBEDTLS_PKCS12_C
2416 scripts/config.py unset MBEDTLS_PKCS5_C
Gilles Peskinefcee7402022-10-11 21:15:24 +02002417 # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
2418 # in PSA code to work with RSA keys. We don't require users to set those:
2419 # they will be reenabled in build_info.h.
Gilles Peskine1f108072022-10-25 21:02:56 +02002420 scripts/config.py unset MBEDTLS_PK_C
Gilles Peskinefcee7402022-10-11 21:15:24 +02002421 scripts/config.py unset MBEDTLS_PK_PARSE_C
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002422 scripts/config.py unset MBEDTLS_PK_WRITE_C
Gilles Peskineaef1ba62022-10-11 21:05:06 +02002423 make CFLAGS='-O1 -Werror' all test
2424 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
2425}
2426
Gilles Peskineec541fe2020-01-31 14:24:14 +01002427component_build_crypto_baremetal () {
2428 msg "build: make, crypto only, baremetal config"
2429 scripts/config.py crypto_baremetal
David Horstmann61faf662021-11-30 11:40:54 +00002430 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002431 are_empty_libraries library/libmbedx509.* library/libmbedtls.*
Gilles Peskineec541fe2020-01-31 14:24:14 +01002432}
Daniel Axtens446af202020-09-02 21:30:13 +10002433support_build_crypto_baremetal () {
Daniel Axtens814c8132020-08-31 14:22:58 +10002434 support_build_baremetal "$@"
2435}
2436
2437component_build_baremetal () {
2438 msg "build: make, baremetal config"
2439 scripts/config.py baremetal
David Horstmann61faf662021-11-30 11:40:54 +00002440 make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
Daniel Axtens814c8132020-08-31 14:22:58 +10002441}
2442support_build_baremetal () {
Daniel Axtens446af202020-09-02 21:30:13 +10002443 # Older Glibc versions include time.h from other headers such as stdlib.h,
2444 # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
2445 # problem, Ubuntu 18.04 is ok.
2446 ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
2447}
Gilles Peskineec541fe2020-01-31 14:24:14 +01002448
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002449# depends.py family of tests
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002450component_test_depends_py_cipher_id () {
2451 msg "test/build: depends.py cipher_id (gcc)"
Gilles Peskine21570cf2023-12-22 11:49:50 +01002452 tests/scripts/depends.py cipher_id --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002453}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00002454
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002455component_test_depends_py_cipher_chaining () {
2456 msg "test/build: depends.py cipher_chaining (gcc)"
Gilles Peskine21570cf2023-12-22 11:49:50 +01002457 tests/scripts/depends.py cipher_chaining --unset-use-psa
John Durkopc14be902020-08-20 06:16:41 -07002458}
2459
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002460component_test_depends_py_cipher_padding () {
2461 msg "test/build: depends.py cipher_padding (gcc)"
Gilles Peskine21570cf2023-12-22 11:49:50 +01002462 tests/scripts/depends.py cipher_padding --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002463}
Jaeden Ameroacaabe72018-11-07 11:52:52 +00002464
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002465component_test_depends_py_curves () {
2466 msg "test/build: depends.py curves (gcc)"
Gilles Peskine21570cf2023-12-22 11:49:50 +01002467 tests/scripts/depends.py curves --unset-use-psa
John Durkop2ec2eaa2020-08-24 18:29:15 -07002468}
2469
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002470component_test_depends_py_hashes () {
2471 msg "test/build: depends.py hashes (gcc)"
Gilles Peskine21570cf2023-12-22 11:49:50 +01002472 tests/scripts/depends.py hashes --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002473}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002474
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002475component_test_depends_py_kex () {
2476 msg "test/build: depends.py kex (gcc)"
Gilles Peskine21570cf2023-12-22 11:49:50 +01002477 tests/scripts/depends.py kex --unset-use-psa
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002478}
2479
Andrzej Kurekfcbd2ac2022-10-05 09:14:07 -04002480component_test_depends_py_pkalgs () {
2481 msg "test/build: depends.py pkalgs (gcc)"
Gilles Peskine21570cf2023-12-22 11:49:50 +01002482 tests/scripts/depends.py pkalgs --unset-use-psa
Gilles Peskine8f073122018-11-27 15:58:47 +01002483}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002484
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002485# PSA equivalents of the depends.py tests
2486component_test_depends_py_cipher_id_psa () {
2487 msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Gilles Peskine21570cf2023-12-22 11:49:50 +01002488 tests/scripts/depends.py cipher_id
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002489}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002490
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002491component_test_depends_py_cipher_chaining_psa () {
2492 msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Gilles Peskine21570cf2023-12-22 11:49:50 +01002493 tests/scripts/depends.py cipher_chaining
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002494}
2495
2496component_test_depends_py_cipher_padding_psa () {
2497 msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Gilles Peskine21570cf2023-12-22 11:49:50 +01002498 tests/scripts/depends.py cipher_padding
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002499}
2500
2501component_test_depends_py_curves_psa () {
2502 msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Gilles Peskine21570cf2023-12-22 11:49:50 +01002503 tests/scripts/depends.py curves
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002504}
2505
2506component_test_depends_py_hashes_psa () {
2507 msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Gilles Peskine21570cf2023-12-22 11:49:50 +01002508 tests/scripts/depends.py hashes
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002509}
2510
2511component_test_depends_py_kex_psa () {
2512 msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Gilles Peskine21570cf2023-12-22 11:49:50 +01002513 tests/scripts/depends.py kex
Andrzej Kurek7cb00772022-10-24 10:49:22 -04002514}
2515
2516component_test_depends_py_pkalgs_psa () {
2517 msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
Gilles Peskine21570cf2023-12-22 11:49:50 +01002518 tests/scripts/depends.py pkalgs
Gilles Peskine8f073122018-11-27 15:58:47 +01002519}
Manuel Pégourié-Gonnard655c0a82018-10-30 11:20:45 +01002520
Valerio Setti6bed64e2024-01-17 15:21:44 +01002521component_test_psa_crypto_config_ffdh_2048_only () {
2522 msg "build: full config - only DH 2048"
2523
2524 scripts/config.py full
2525
2526 # Disable all DH groups other than 2048.
2527 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_3072
2528 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_4096
2529 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_6144
2530 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_8192
2531
2532 make CFLAGS="$ASAN_CFLAGS -Werror" LDFLAGS="$ASAN_CFLAGS"
2533
2534 msg "test: full config - only DH 2048"
2535 make test
2536
2537 msg "ssl-opt: full config - only DH 2048"
2538 tests/ssl-opt.sh -f "ffdh"
2539}
2540
Dave Rodgman1a034dc2023-01-20 13:18:05 +00002541component_build_no_pk_rsa_alt_support () {
2542 msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
2543
2544 scripts/config.py full
2545 scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
2546 scripts/config.py set MBEDTLS_RSA_C
2547 scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
2548
2549 # Only compile - this is primarily to test for compile issues
Dave Rodgman84125a12024-01-02 11:42:38 +00002550 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
Dave Rodgman1a034dc2023-01-20 13:18:05 +00002551}
2552
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002553component_build_module_alt () {
2554 msg "build: MBEDTLS_XXX_ALT" # ~30s
2555 scripts/config.py full
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002556
2557 # Disable options that are incompatible with some ALT implementations:
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002558 # aesni.c and padlock.c reference mbedtls_aes_context fields directly.
2559 scripts/config.py unset MBEDTLS_AESNI_C
2560 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08002561 scripts/config.py unset MBEDTLS_AESCE_C
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002562 # MBEDTLS_ECP_RESTARTABLE is documented as incompatible.
2563 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002564 # You can only have one threading implementation: alt or pthread, not both.
2565 scripts/config.py unset MBEDTLS_THREADING_PTHREAD
Gilles Peskine5c3f18d2021-05-31 21:21:12 +02002566 # The SpecifiedECDomain parsing code accesses mbedtls_ecp_group fields
2567 # directly and assumes the implementation works with partial groups.
2568 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
Dave Rodgman5b89c552023-10-10 14:59:02 +01002569 # MBEDTLS_SHA256_*ALT can't be used with MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*
2570 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2571 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00002572 # MBEDTLS_SHA512_*ALT can't be used with MBEDTLS_SHA512_USE_A64_CRYPTO_*
2573 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2574 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002575
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002576 # Enable all MBEDTLS_XXX_ALT for whole modules. Do not enable
2577 # MBEDTLS_XXX_YYY_ALT which are for single functions.
2578 scripts/config.py set-all 'MBEDTLS_([A-Z0-9]*|NIST_KW)_ALT'
Gilles Peskine1628a9c2021-05-31 22:09:58 +02002579 scripts/config.py unset MBEDTLS_DHM_ALT #incompatible with MBEDTLS_DEBUG_C
Manuel Pégourié-Gonnarda6e3d3e2022-12-06 12:10:33 +01002580
Gilles Peskine1628a9c2021-05-31 22:09:58 +02002581 # We can only compile, not link, since we don't have any implementations
2582 # suitable for testing with the dummy alt headers.
Dave Rodgmanea03ef92023-12-19 12:19:59 +00002583 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
Gilles Peskine1628a9c2021-05-31 22:09:58 +02002584}
2585
2586component_build_dhm_alt () {
2587 msg "build: MBEDTLS_DHM_ALT" # ~30s
2588 scripts/config.py full
2589 scripts/config.py set MBEDTLS_DHM_ALT
2590 # debug.c currently references mbedtls_dhm_context fields directly.
2591 scripts/config.py unset MBEDTLS_DEBUG_C
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002592 # We can only compile, not link, since we don't have any implementations
2593 # suitable for testing with the dummy alt headers.
Dave Rodgmanea03ef92023-12-19 12:19:59 +00002594 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
Gilles Peskinecc73cc52021-05-25 09:04:46 +02002595}
2596
Gilles Peskine64996c32024-01-23 20:25:47 +01002597component_test_no_psa_crypto_full_cmake_asan() {
2598 # full minus MBEDTLS_PSA_CRYPTO_C: run the same set of tests as basic-build-test.sh
2599 msg "build: cmake, full config minus PSA crypto, ASan"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002600 scripts/config.py full
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002601 scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
Gilles Peskine64996c32024-01-23 20:25:47 +01002602 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CLIENT
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002603 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
Ronald Cron6f135e12021-12-08 16:57:54 +01002604 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002605 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Gilles Peskinedc6d8382020-04-12 14:21:55 +02002606 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02002607 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Raef Colesa7e03ad2022-09-28 09:32:48 +01002608 scripts/config.py unset MBEDTLS_LMS_C
Raef Coles47bccb72022-09-28 12:00:20 +01002609 scripts/config.py unset MBEDTLS_LMS_PRIVATE
Dave Rodgman17127e92023-12-14 16:42:48 +00002610 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002611 make
Manuel Pégourié-Gonnard43be6cd2017-06-20 09:53:42 +02002612
Gilles Peskine64996c32024-01-23 20:25:47 +01002613 msg "test: main suites (full minus PSA crypto)"
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002614 make test
Manuel Pégourié-Gonnard503a5ef2015-10-23 09:04:45 +02002615
Manuel Pégourié-Gonnard182a23b2022-12-07 10:38:43 +01002616 # Note: ssl-opt.sh has some test cases that depend on
2617 # MBEDTLS_ECP_RESTARTABLE && !MBEDTLS_USE_PSA_CRYPTO
2618 # This is the only component where those tests are not skipped.
Gilles Peskinee0c13cf2024-01-30 10:17:49 +01002619 msg "test: ssl-opt.sh (full minus PSA crypto)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002620 tests/ssl-opt.sh
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01002621
Gilles Peskinee0c13cf2024-01-30 10:17:49 +01002622 msg "test: compat.sh default (full minus PSA crypto)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02002623 tests/compat.sh
Andrzej Kurek991f9fe2018-07-02 09:08:21 -04002624
Gilles Peskinee0c13cf2024-01-30 10:17:49 +01002625 msg "test: compat.sh NULL (full minus PSA crypto)"
Gilles Peskinee29203b2023-08-27 21:43:00 +02002626 tests/compat.sh -f 'NULL'
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002627
Gilles Peskinee0c13cf2024-01-30 10:17:49 +01002628 msg "test: compat.sh ARIA + ChachaPoly (full minus PSA crypto)"
Manuel Pégourié-Gonnardc5722462022-12-19 11:42:12 +01002629 env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
Andrzej Kurekde5a0072019-02-01 07:03:03 -05002630}
Andrzej Kurekc470b6b2019-01-31 08:20:20 -05002631
Ronald Cron403c15c2021-09-13 09:38:05 +02002632component_test_psa_crypto_config_accel_ecdsa () {
Valerio Setti5aab43f2023-03-29 10:42:07 +02002633 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
Ronald Cron403c15c2021-09-13 09:38:05 +02002634
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002635 # Algorithms and key types to accelerate
Valerio Settic0d2f842023-06-28 10:48:08 +02002636 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
Valerio Setti3fe105b2023-10-30 11:08:12 +01002637 $(helper_get_psa_key_type_list "ECC") \
2638 $(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002639
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002640 # Configure
2641 # ---------
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002642
Manuel Pégourié-Gonnard8d645dc2023-06-15 09:07:10 +02002643 # Start from default config (no USE_PSA) + TLS 1.3
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002644 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002645
2646 # Disable the module that's accelerated
Ronald Cron403c15c2021-09-13 09:38:05 +02002647 scripts/config.py unset MBEDTLS_ECDSA_C
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002648
2649 # Disable things that depend on it
Ronald Cron403c15c2021-09-13 09:38:05 +02002650 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2651 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2652
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002653 # Build
2654 # -----
2655
2656 # These hashes are needed for some ECDSA signature tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02002657 loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2658 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002659
2660 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2661
Valerio Setti3fe105b2023-10-30 11:08:12 +01002662 helper_libtestdriver1_make_main "$loc_accel_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02002663
Manuel Pégourié-Gonnarde3095e72022-12-28 10:09:53 +01002664 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine827dbd92022-02-04 00:30:54 +01002665 not grep mbedtls_ecdsa_ library/ecdsa.o
Ronald Cron403c15c2021-09-13 09:38:05 +02002666
Manuel Pégourié-Gonnard200fd0f2022-12-27 13:03:10 +01002667 # Run the tests
2668 # -------------
2669
Ronald Cron403c15c2021-09-13 09:38:05 +02002670 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
2671 make test
2672}
2673
Valerio Setti44b178c2023-03-22 14:02:57 +01002674component_test_psa_crypto_config_accel_ecdh () {
Valerio Setti5aab43f2023-03-29 10:42:07 +02002675 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002676
2677 # Algorithms and key types to accelerate
Valerio Settic0d2f842023-06-28 10:48:08 +02002678 loc_accel_list="ALG_ECDH \
Valerio Setti3fe105b2023-10-30 11:08:12 +01002679 $(helper_get_psa_key_type_list "ECC") \
2680 $(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002681
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002682 # Configure
2683 # ---------
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002684
Ronald Cron46ac0652024-03-18 12:39:04 +01002685 # Start from default config (no USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002686 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002687
Valerio Setti44b178c2023-03-22 14:02:57 +01002688 # Disable the module that's accelerated
2689 scripts/config.py unset MBEDTLS_ECDH_C
2690
2691 # Disable things that depend on it
2692 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2693 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2694 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2695 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2696 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2697
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002698 # Build
2699 # -----
2700
2701 helper_libtestdriver1_make_drivers "$loc_accel_list"
2702
Valerio Setti3fe105b2023-10-30 11:08:12 +01002703 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002704
Valerio Setti44b178c2023-03-22 14:02:57 +01002705 # Make sure this was not re-enabled by accident (additive config)
2706 not grep mbedtls_ecdh_ library/ecdh.o
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002707
2708 # Run the tests
2709 # -------------
2710
Valerio Setti44b178c2023-03-22 14:02:57 +01002711 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002712 make test
Manuel Pégourié-Gonnard10e39632022-12-29 12:29:09 +01002713}
2714
Przemek Stekieldccb2022023-05-11 10:48:50 +02002715component_test_psa_crypto_config_accel_ffdh () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002716 msg "build: full with accelerated FFDH"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002717
2718 # Algorithms and key types to accelerate
Valerio Setti27602c32023-07-10 16:38:59 +02002719 loc_accel_list="ALG_FFDH \
Valerio Setti78aa0bc2024-01-17 15:53:46 +01002720 $(helper_get_psa_key_type_list "DH") \
2721 $(helper_get_psa_dh_group_list)"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002722
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002723 # Configure
2724 # ---------
Przemek Stekieldccb2022023-05-11 10:48:50 +02002725
Przemek Stekiel565353e2023-07-05 11:07:07 +02002726 # start with full (USE_PSA and TLS 1.3)
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002727 helper_libtestdriver1_adjust_config "full"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002728
2729 # Disable the module that's accelerated
2730 scripts/config.py unset MBEDTLS_DHM_C
2731
2732 # Disable things that depend on it
2733 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2734 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2735
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002736 # Build
2737 # -----
2738
2739 helper_libtestdriver1_make_drivers "$loc_accel_list"
2740
Manuel Pégourié-Gonnard981732e2023-06-08 09:15:59 +02002741 helper_libtestdriver1_make_main "$loc_accel_list"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002742
2743 # Make sure this was not re-enabled by accident (additive config)
2744 not grep mbedtls_dhm_ library/dhm.o
2745
2746 # Run the tests
2747 # -------------
2748
Gilles Peskine14302ed2023-07-19 19:30:04 +02002749 msg "test: full with accelerated FFDH"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002750 make test
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002751
Gilles Peskine14302ed2023-07-19 19:30:04 +02002752 msg "ssl-opt: full with accelerated FFDH alg"
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002753 tests/ssl-opt.sh -f "ffdh"
Przemek Stekieldccb2022023-05-11 10:48:50 +02002754}
2755
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002756component_test_psa_crypto_config_reference_ffdh () {
Gilles Peskineb7d577e2023-08-09 19:48:58 +02002757 msg "build: full with non-accelerated FFDH"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002758
2759 # Start with full (USE_PSA and TLS 1.3)
Przemek Stekiel565353e2023-07-05 11:07:07 +02002760 helper_libtestdriver1_adjust_config "full"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002761
2762 # Disable things that are not supported
2763 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2764 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
Gilles Peskine21570cf2023-12-22 11:49:50 +01002765 make
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002766
Gilles Peskine14302ed2023-07-19 19:30:04 +02002767 msg "test suites: full with non-accelerated FFDH alg"
Przemek Stekiel01c248c2023-05-26 10:19:49 +02002768 make test
2769
Gilles Peskine14302ed2023-07-19 19:30:04 +02002770 msg "ssl-opt: full with non-accelerated FFDH alg"
Przemek Stekiel84f4ff12023-07-04 12:35:31 +02002771 tests/ssl-opt.sh -f "ffdh"
Valerio Setti42d5f192023-03-20 13:54:41 +01002772}
2773
Valerio Setti44b178c2023-03-22 14:02:57 +01002774component_test_psa_crypto_config_accel_pake() {
Gilles Peskine14302ed2023-07-19 19:30:04 +02002775 msg "build: full with accelerated PAKE"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002776
Manuel Pégourié-Gonnard5a7523e2023-09-20 12:45:01 +02002777 loc_accel_list="ALG_JPAKE \
Valerio Setti3fe105b2023-10-30 11:08:12 +01002778 $(helper_get_psa_key_type_list "ECC") \
2779 $(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002780
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002781 # Configure
2782 # ---------
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002783
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002784 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002785
2786 # Make built-in fallback not available
2787 scripts/config.py unset MBEDTLS_ECJPAKE_C
2788 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
2789
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002790 # Build
2791 # -----
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002792
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02002793 helper_libtestdriver1_make_drivers "$loc_accel_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002794
Valerio Setti3fe105b2023-10-30 11:08:12 +01002795 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002796
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002797 # Make sure this was not re-enabled by accident (additive config)
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002798 not grep mbedtls_ecjpake_init library/ecjpake.o
2799
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02002800 # Run the tests
2801 # -------------
2802
Gilles Peskine14302ed2023-07-19 19:30:04 +02002803 msg "test: full with accelerated PAKE"
Gilles Peskine21570cf2023-12-22 11:49:50 +01002804 make test
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002805}
2806
Manuel Pégourié-Gonnard5c210362023-09-26 12:03:10 +02002807component_test_psa_crypto_config_accel_ecc_some_key_types () {
2808 msg "build: full with accelerated EC algs and some key types"
2809
2810 # Algorithms and key types to accelerate
2811 # For key types, use an explicitly list to omit GENERATE (and DERIVE)
2812 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2813 ALG_ECDH \
2814 ALG_JPAKE \
2815 KEY_TYPE_ECC_PUBLIC_KEY \
2816 KEY_TYPE_ECC_KEY_PAIR_BASIC \
2817 KEY_TYPE_ECC_KEY_PAIR_IMPORT \
Valerio Setti3fe105b2023-10-30 11:08:12 +01002818 KEY_TYPE_ECC_KEY_PAIR_EXPORT \
2819 $(helper_get_psa_curve_list)"
Manuel Pégourié-Gonnard5c210362023-09-26 12:03:10 +02002820
2821 # Configure
2822 # ---------
2823
2824 # start with config full for maximum coverage (also enables USE_PSA)
2825 helper_libtestdriver1_adjust_config "full"
2826
2827 # Disable modules that are accelerated - some will be re-enabled
2828 scripts/config.py unset MBEDTLS_ECDSA_C
2829 scripts/config.py unset MBEDTLS_ECDH_C
2830 scripts/config.py unset MBEDTLS_ECJPAKE_C
2831 scripts/config.py unset MBEDTLS_ECP_C
2832
2833 # Disable all curves - those that aren't accelerated should be re-enabled
2834 helper_disable_builtin_curves
2835
2836 # Restartable feature is not yet supported by PSA. Once it will in
2837 # the future, the following line could be removed (see issues
2838 # 6061, 6332 and following ones)
2839 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2840
2841 # this is not supported by the driver API yet
2842 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2843
2844 # Build
2845 # -----
2846
2847 # These hashes are needed for some ECDSA signature tests.
2848 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2849 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2850 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2851
Valerio Setti3fe105b2023-10-30 11:08:12 +01002852 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard5c210362023-09-26 12:03:10 +02002853
2854 # ECP should be re-enabled but not the others
2855 not grep mbedtls_ecdh_ library/ecdh.o
2856 not grep mbedtls_ecdsa library/ecdsa.o
2857 not grep mbedtls_ecjpake library/ecjpake.o
2858 grep mbedtls_ecp library/ecp.o
2859
2860 # Run the tests
2861 # -------------
2862
2863 msg "test suites: full with accelerated EC algs and some key types"
Gilles Peskine21570cf2023-12-22 11:49:50 +01002864 make test
Manuel Pégourié-Gonnard5c210362023-09-26 12:03:10 +02002865}
2866
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002867# Run tests with only (non-)Weierstrass accelerated
2868# Common code used in:
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002869# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
2870# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002871common_test_psa_crypto_config_accel_ecc_some_curves () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002872 weierstrass=$1
2873 if [ $weierstrass -eq 1 ]; then
2874 desc="Weierstrass"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002875 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002876 desc="non-Weierstrass"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002877 fi
2878
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002879 msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002880
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002881 # Note: Curves are handled in a special way by the libtestdriver machinery,
2882 # so we only want to include them in the accel list when building the main
2883 # libraries, hence the use of a separate variable.
2884 # Note: the following loop is a modified version of
2885 # helper_get_psa_curve_list that only keeps Weierstrass families.
2886 loc_weierstrass_list=""
2887 loc_non_weierstrass_list=""
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002888 for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
2889 case $item in
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002890 ECC_BRAINPOOL*|ECC_SECP*)
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002891 loc_weierstrass_list="$loc_weierstrass_list $item"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002892 ;;
2893 *)
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002894 loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002895 ;;
2896 esac
2897 done
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002898 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002899 loc_curve_list=$loc_weierstrass_list
2900 else
2901 loc_curve_list=$loc_non_weierstrass_list
2902 fi
2903
Valerio Setti3fe105b2023-10-30 11:08:12 +01002904 # Algorithms and key types to accelerate
2905 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2906 ALG_ECDH \
2907 ALG_JPAKE \
2908 $(helper_get_psa_key_type_list "ECC") \
2909 $loc_curve_list"
2910
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002911 # Configure
2912 # ---------
2913
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002914 # Start with config crypto_full and remove PK_C:
2915 # that's what's supported now, see docs/driver-only-builds.md.
2916 helper_libtestdriver1_adjust_config "crypto_full"
2917 scripts/config.py unset MBEDTLS_PK_C
2918 scripts/config.py unset MBEDTLS_PK_PARSE_C
2919 scripts/config.py unset MBEDTLS_PK_WRITE_C
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002920
2921 # Disable modules that are accelerated - some will be re-enabled
2922 scripts/config.py unset MBEDTLS_ECDSA_C
2923 scripts/config.py unset MBEDTLS_ECDH_C
2924 scripts/config.py unset MBEDTLS_ECJPAKE_C
2925 scripts/config.py unset MBEDTLS_ECP_C
2926
2927 # Disable all curves - those that aren't accelerated should be re-enabled
2928 helper_disable_builtin_curves
2929
2930 # Restartable feature is not yet supported by PSA. Once it will in
2931 # the future, the following line could be removed (see issues
2932 # 6061, 6332 and following ones)
2933 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2934
2935 # this is not supported by the driver API yet
2936 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2937
2938 # Build
2939 # -----
2940
2941 # These hashes are needed for some ECDSA signature tests.
2942 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2943 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2944 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2945
Valerio Settiac7a8092023-10-31 12:23:44 +01002946 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002947
2948 # We expect ECDH to be re-enabled for the missing curves
2949 grep mbedtls_ecdh_ library/ecdh.o
2950 # We expect ECP to be re-enabled, however the parts specific to the
2951 # families of curves that are accelerated should be ommited.
2952 # - functions with mxz in the name are specific to Montgomery curves
2953 # - ecp_muladd is specific to Weierstrass curves
2954 ##nm library/ecp.o | tee ecp.syms
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002955 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002956 not grep mbedtls_ecp_muladd library/ecp.o
2957 grep mxz library/ecp.o
2958 else
2959 grep mbedtls_ecp_muladd library/ecp.o
2960 not grep mxz library/ecp.o
2961 fi
2962 # We expect ECDSA and ECJPAKE to be re-enabled only when
2963 # Weierstrass curves are not accelerated
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002964 if [ $weierstrass -eq 1 ]; then
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002965 not grep mbedtls_ecdsa library/ecdsa.o
2966 not grep mbedtls_ecjpake library/ecjpake.o
2967 else
2968 grep mbedtls_ecdsa library/ecdsa.o
2969 grep mbedtls_ecjpake library/ecjpake.o
2970 fi
2971
2972 # Run the tests
2973 # -------------
2974
Manuel Pégourié-Gonnardc0c9b232023-09-28 10:05:57 +02002975 msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
2976 make test
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002977}
2978
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002979component_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002980 common_test_psa_crypto_config_accel_ecc_some_curves 1
2981}
2982
Manuel Pégourié-Gonnardfaea9192023-09-28 09:10:01 +02002983component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
Manuel Pégourié-Gonnard561bce62023-09-25 12:35:15 +02002984 common_test_psa_crypto_config_accel_ecc_some_curves 0
2985}
2986
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002987# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
2988# ECDH, ECDSA) with and without drivers.
2989# The input parameter is a boolean value which indicates:
2990# - 0 keep built-in EC algs,
2991# - 1 exclude built-in EC algs (driver only).
2992#
2993# This is used by the two following components to ensure they always use the
2994# same config, except for the use of driver or built-in EC algorithms:
Valerio Setti4d25a8d2023-06-14 10:33:10 +02002995# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
2996# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
Manuel Pégourié-Gonnard171c45f2022-12-29 11:31:35 +01002997# This supports comparing their test coverage with analyze_outcomes.py.
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02002998config_psa_crypto_config_ecp_light_only () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02002999 driver_only="$1"
Valerio Setti42d5f192023-03-20 13:54:41 +01003000 # start with config full for maximum coverage (also enables USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003001 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003002 if [ "$driver_only" -eq 1 ]; then
Valerio Setti42d5f192023-03-20 13:54:41 +01003003 # Disable modules that are accelerated
3004 scripts/config.py unset MBEDTLS_ECDSA_C
3005 scripts/config.py unset MBEDTLS_ECDH_C
3006 scripts/config.py unset MBEDTLS_ECJPAKE_C
Valerio Setti29b395c2023-04-05 18:20:30 +02003007 scripts/config.py unset MBEDTLS_ECP_C
Valerio Setti42d5f192023-03-20 13:54:41 +01003008 fi
3009
3010 # Restartable feature is not yet supported by PSA. Once it will in
3011 # the future, the following line could be removed (see issues
3012 # 6061, 6332 and following ones)
3013 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Setti42d5f192023-03-20 13:54:41 +01003014}
3015
Valerio Setti4d25a8d2023-06-14 10:33:10 +02003016# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
3017component_test_psa_crypto_config_accel_ecc_ecp_light_only () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02003018 msg "build: full with accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01003019
3020 # Algorithms and key types to accelerate
3021 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
3022 ALG_ECDH \
3023 ALG_JPAKE \
Valerio Setti3fe105b2023-10-30 11:08:12 +01003024 $(helper_get_psa_key_type_list "ECC") \
3025 $(helper_get_psa_curve_list)"
Valerio Setti42d5f192023-03-20 13:54:41 +01003026
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003027 # Configure
3028 # ---------
Valerio Setti42d5f192023-03-20 13:54:41 +01003029
3030 # Use the same config as reference, only without built-in EC algs
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02003031 config_psa_crypto_config_ecp_light_only 1
Valerio Setti42d5f192023-03-20 13:54:41 +01003032
Valerio Setti0a342c92023-09-01 09:12:31 +02003033 # Do not disable builtin curves because that support is required for:
Valerio Settib2fd6732023-08-15 17:10:47 +02003034 # - MBEDTLS_PK_PARSE_EC_EXTENDED
3035 # - MBEDTLS_PK_PARSE_EC_COMPRESSED
Valerio Setti42d5f192023-03-20 13:54:41 +01003036
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003037 # Build
3038 # -----
3039
3040 # These hashes are needed for some ECDSA signature tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02003041 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3042 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003043 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
3044
Valerio Setti3fe105b2023-10-30 11:08:12 +01003045 helper_libtestdriver1_make_main "$loc_accel_list"
Valerio Setti42d5f192023-03-20 13:54:41 +01003046
3047 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
3048 not grep mbedtls_ecdsa_ library/ecdsa.o
3049 not grep mbedtls_ecdh_ library/ecdh.o
3050 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Setti29b395c2023-04-05 18:20:30 +02003051 not grep mbedtls_ecp_mul library/ecp.o
Valerio Setti42d5f192023-03-20 13:54:41 +01003052
3053 # Run the tests
3054 # -------------
3055
Gilles Peskine14302ed2023-07-19 19:30:04 +02003056 msg "test suites: full with accelerated EC algs"
Gilles Peskine21570cf2023-12-22 11:49:50 +01003057 make test
Valerio Setti42d5f192023-03-20 13:54:41 +01003058
Gilles Peskine14302ed2023-07-19 19:30:04 +02003059 msg "ssl-opt: full with accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01003060 tests/ssl-opt.sh
3061}
3062
Valerio Setti4d25a8d2023-06-14 10:33:10 +02003063# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
3064component_test_psa_crypto_config_reference_ecc_ecp_light_only () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02003065 msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01003066
Gilles Peskine8dbdf2f2023-07-19 19:16:37 +02003067 config_psa_crypto_config_ecp_light_only 0
Valerio Setti42d5f192023-03-20 13:54:41 +01003068
Gilles Peskine21570cf2023-12-22 11:49:50 +01003069 make
Valerio Setti42d5f192023-03-20 13:54:41 +01003070
Gilles Peskine14302ed2023-07-19 19:30:04 +02003071 msg "test suites: full with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01003072 make test
3073
Gilles Peskine14302ed2023-07-19 19:30:04 +02003074 msg "ssl-opt: full with non-accelerated EC algs"
Valerio Setti42d5f192023-03-20 13:54:41 +01003075 tests/ssl-opt.sh
3076}
3077
Valerio Settie618cb02023-04-12 14:59:16 +02003078# This helper function is used by:
Valerio Setti4d25a8d2023-06-14 10:33:10 +02003079# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
3080# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
Valerio Settie618cb02023-04-12 14:59:16 +02003081# to ensure that both tests use the same underlying configuration when testing
3082# driver's coverage with analyze_outcomes.py.
3083#
3084# This functions accepts 1 boolean parameter as follows:
3085# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
3086# excluding their built-in implementation as well as ECP_C & ECP_LIGHT
3087# - 0: include built-in implementation of EC algorithms.
3088#
3089# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
3090# on the ECP module.
Valerio Setti4d25a8d2023-06-14 10:33:10 +02003091config_psa_crypto_no_ecp_at_all () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003092 driver_only="$1"
Valerio Settiaafe9002023-06-26 15:23:44 +02003093 # start with full config for maximum coverage (also enables USE_PSA)
3094 helper_libtestdriver1_adjust_config "full"
3095
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003096 if [ "$driver_only" -eq 1 ]; then
Valerio Settie618cb02023-04-12 14:59:16 +02003097 # Disable modules that are accelerated
3098 scripts/config.py unset MBEDTLS_ECDSA_C
3099 scripts/config.py unset MBEDTLS_ECDH_C
3100 scripts/config.py unset MBEDTLS_ECJPAKE_C
3101 # Disable ECP module (entirely)
3102 scripts/config.py unset MBEDTLS_ECP_C
Valerio Settie618cb02023-04-12 14:59:16 +02003103 fi
3104
Valerio Settiaecd32c2023-06-14 10:42:31 +02003105 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
3106 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
Valerio Settiaddeee42023-06-14 10:46:55 +02003107 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
Ronald Cron6b49b552023-07-20 09:57:54 +02003108 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
Valerio Settiaecd32c2023-06-14 10:42:31 +02003109
Valerio Settie618cb02023-04-12 14:59:16 +02003110 # Restartable feature is not yet supported by PSA. Once it will in
3111 # the future, the following line could be removed (see issues
3112 # 6061, 6332 and following ones)
3113 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
Valerio Settie618cb02023-04-12 14:59:16 +02003114}
3115
3116# Build and test a configuration where driver accelerates all EC algs while
3117# all support and dependencies from ECP and ECP_LIGHT are removed on the library
3118# side.
3119#
Valerio Setti4d25a8d2023-06-14 10:33:10 +02003120# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
3121component_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02003122 msg "build: full + accelerated EC algs - ECP"
Valerio Settie618cb02023-04-12 14:59:16 +02003123
3124 # Algorithms and key types to accelerate
3125 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
3126 ALG_ECDH \
3127 ALG_JPAKE \
Valerio Setti3fe105b2023-10-30 11:08:12 +01003128 $(helper_get_psa_key_type_list "ECC") \
3129 $(helper_get_psa_curve_list)"
Valerio Settie618cb02023-04-12 14:59:16 +02003130
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003131 # Configure
3132 # ---------
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003133
Valerio Settie618cb02023-04-12 14:59:16 +02003134 # Set common configurations between library's and driver's builds
Valerio Setti4d25a8d2023-06-14 10:33:10 +02003135 config_psa_crypto_no_ecp_at_all 1
Valerio Settib2fd6732023-08-15 17:10:47 +02003136 # Disable all the builtin curves. All the required algs are accelerated.
3137 helper_disable_builtin_curves
Valerio Settie618cb02023-04-12 14:59:16 +02003138
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003139 # Build
3140 # -----
Valerio Settie618cb02023-04-12 14:59:16 +02003141
3142 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02003143 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
3144 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3145 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Valerio Settie618cb02023-04-12 14:59:16 +02003146
Manuel Pégourié-Gonnard31639e42023-05-25 10:07:31 +02003147 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
Valerio Settie618cb02023-04-12 14:59:16 +02003148
Valerio Setti3fe105b2023-10-30 11:08:12 +01003149 helper_libtestdriver1_make_main "$loc_accel_list"
Valerio Settie618cb02023-04-12 14:59:16 +02003150
3151 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
3152 not grep mbedtls_ecdsa_ library/ecdsa.o
3153 not grep mbedtls_ecdh_ library/ecdh.o
3154 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Settib2fd6732023-08-15 17:10:47 +02003155 # Also ensure that ECP module was not re-enabled
Valerio Settie618cb02023-04-12 14:59:16 +02003156 not grep mbedtls_ecp_ library/ecp.o
Valerio Settie618cb02023-04-12 14:59:16 +02003157
3158 # Run the tests
3159 # -------------
3160
Gilles Peskine14302ed2023-07-19 19:30:04 +02003161 msg "test: full + accelerated EC algs - ECP"
Gilles Peskine21570cf2023-12-22 11:49:50 +01003162 make test
Valerio Setti16b70f22023-06-27 17:45:49 +02003163
Gilles Peskine14302ed2023-07-19 19:30:04 +02003164 msg "ssl-opt: full + accelerated EC algs - ECP"
Valerio Setti16b70f22023-06-27 17:45:49 +02003165 tests/ssl-opt.sh
Valerio Settie618cb02023-04-12 14:59:16 +02003166}
3167
3168# Reference function used for driver's coverage analysis in analyze_outcomes.py
Valerio Setti4d25a8d2023-06-14 10:33:10 +02003169# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
Valerio Settie618cb02023-04-12 14:59:16 +02003170# Keep in sync with its accelerated counterpart.
Valerio Setti4d25a8d2023-06-14 10:33:10 +02003171component_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02003172 msg "build: full + non accelerated EC algs"
Valerio Settie618cb02023-04-12 14:59:16 +02003173
Valerio Setti4d25a8d2023-06-14 10:33:10 +02003174 config_psa_crypto_no_ecp_at_all 0
Valerio Settie618cb02023-04-12 14:59:16 +02003175
Gilles Peskine21570cf2023-12-22 11:49:50 +01003176 make
Valerio Settie618cb02023-04-12 14:59:16 +02003177
Gilles Peskine14302ed2023-07-19 19:30:04 +02003178 msg "test: full + non accelerated EC algs"
Valerio Settie618cb02023-04-12 14:59:16 +02003179 make test
Valerio Setti16b70f22023-06-27 17:45:49 +02003180
Gilles Peskine14302ed2023-07-19 19:30:04 +02003181 msg "ssl-opt: full + non accelerated EC algs"
Valerio Setti16b70f22023-06-27 17:45:49 +02003182 tests/ssl-opt.sh
Valerio Settie618cb02023-04-12 14:59:16 +02003183}
3184
Valerio Setti4e2f2442023-08-15 10:10:26 +02003185# This is a common configuration helper used directly from:
3186# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
3187# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
3188# and indirectly from:
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003189# - component_test_psa_crypto_config_accel_ecc_no_bignum
Valerio Setti4e2f2442023-08-15 10:10:26 +02003190# - accelerate all EC algs, disable RSA and FFDH
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003191# - component_test_psa_crypto_config_reference_ecc_no_bignum
Valerio Setti4e2f2442023-08-15 10:10:26 +02003192# - this is the reference component of the above
3193# - it still disables RSA and FFDH, but it uses builtin EC algs
3194# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
3195# - accelerate all EC and FFDH algs, disable only RSA
3196# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
3197# - this is the reference component of the above
3198# - it still disables RSA, but it uses builtin EC and FFDH algs
3199#
3200# This function accepts 2 parameters:
Valerio Setti5dfaca42023-09-05 08:48:51 +02003201# $1: a boolean value which states if we are testing an accelerated scenario
3202# or not.
3203# $2: a string value which states which components are tested. Allowed values
3204# are "ECC" or "ECC_DH".
Valerio Setti4e2f2442023-08-15 10:10:26 +02003205config_psa_crypto_config_accel_ecc_ffdh_no_bignum() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003206 driver_only="$1"
3207 test_target="$2"
Valerio Setti18535c32023-07-31 11:27:17 +02003208 # start with full config for maximum coverage (also enables USE_PSA)
Valerio Setti29c1b4d2023-07-27 10:08:45 +02003209 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003210
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003211 if [ "$driver_only" -eq 1 ]; then
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003212 # Disable modules that are accelerated
3213 scripts/config.py unset MBEDTLS_ECDSA_C
3214 scripts/config.py unset MBEDTLS_ECDH_C
3215 scripts/config.py unset MBEDTLS_ECJPAKE_C
3216 # Disable ECP module (entirely)
3217 scripts/config.py unset MBEDTLS_ECP_C
Manuel Pégourié-Gonnard660bbf22023-06-12 18:42:40 +02003218 # Also disable bignum
3219 scripts/config.py unset MBEDTLS_BIGNUM_C
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003220 fi
3221
3222 # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
3223 scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
3224 scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
3225 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
3226
Manuel Pégourié-Gonnard7dccb662023-06-12 18:28:42 +02003227 # RSA support is intentionally disabled on this test because RSA_C depends
3228 # on BIGNUM_C.
Valerio Setti2e0275d2023-07-28 16:33:13 +02003229 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
3230 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 +02003231 scripts/config.py unset MBEDTLS_RSA_C
3232 scripts/config.py unset MBEDTLS_PKCS1_V15
3233 scripts/config.py unset MBEDTLS_PKCS1_V21
3234 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
3235 # Also disable key exchanges that depend on RSA
3236 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
3237 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
3238 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3239 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3240 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3241
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003242 if [ "$test_target" = "ECC" ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02003243 # When testing ECC only, we disable FFDH support, both from builtin and
3244 # PSA sides, and also disable the key exchanges that depend on DHM.
3245 scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_FFDH
3246 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
Valerio Setti78aa0bc2024-01-17 15:53:46 +01003247 scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003248 scripts/config.py unset MBEDTLS_DHM_C
3249 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
3250 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3251 else
3252 # When testing ECC and DH instead, we disable DHM and depending key
3253 # exchanges only in the accelerated build
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003254 if [ "$driver_only" -eq 1 ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02003255 scripts/config.py unset MBEDTLS_DHM_C
3256 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
3257 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3258 fi
3259 fi
Manuel Pégourié-Gonnard7dccb662023-06-12 18:28:42 +02003260
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003261 # Restartable feature is not yet supported by PSA. Once it will in
3262 # the future, the following line could be removed (see issues
3263 # 6061, 6332 and following ones)
3264 scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
3265}
3266
Valerio Setti4e2f2442023-08-15 10:10:26 +02003267# Common helper used by:
3268# - component_test_psa_crypto_config_accel_ecc_no_bignum
3269# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003270#
Valerio Setti4e2f2442023-08-15 10:10:26 +02003271# The goal is to build and test accelerating either:
3272# - ECC only or
3273# - both ECC and FFDH
3274#
3275# It is meant to be used in conjunction with
Valerio Setti5dfaca42023-09-05 08:48:51 +02003276# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
3277# coverage analysis in the "analyze_outcomes.py" script.
Valerio Setti4e2f2442023-08-15 10:10:26 +02003278common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003279 test_target="$1"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003280
Valerio Setti5dfaca42023-09-05 08:48:51 +02003281 # This is an internal helper to simplify text message handling
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003282 if [ "$test_target" = "ECC_DH" ]; then
3283 accel_text="ECC/FFDH"
3284 removed_text="ECP - DH"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003285 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003286 accel_text="ECC"
3287 removed_text="ECP"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003288 fi
3289
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003290 msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003291
3292 # By default we accelerate all EC keys/algs
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003293 loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
3294 ALG_ECDH \
3295 ALG_JPAKE \
Valerio Setti3fe105b2023-10-30 11:08:12 +01003296 $(helper_get_psa_key_type_list "ECC") \
3297 $(helper_get_psa_curve_list)"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003298 # Optionally we can also add DH to the list of accelerated items
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003299 if [ "$test_target" = "ECC_DH" ]; then
Valerio Setti4e2f2442023-08-15 10:10:26 +02003300 loc_accel_list="$loc_accel_list \
3301 ALG_FFDH \
Valerio Setti78aa0bc2024-01-17 15:53:46 +01003302 $(helper_get_psa_key_type_list "DH") \
3303 $(helper_get_psa_dh_group_list)"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003304 fi
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003305
3306 # Configure
3307 # ---------
3308
3309 # Set common configurations between library's and driver's builds
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003310 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
Valerio Settib2fd6732023-08-15 17:10:47 +02003311 # Disable all the builtin curves. All the required algs are accelerated.
3312 helper_disable_builtin_curves
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003313
3314 # Build
3315 # -----
3316
3317 # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02003318 # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
3319 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3320 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003321
3322 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
3323
Valerio Setti3fe105b2023-10-30 11:08:12 +01003324 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003325
3326 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
3327 not grep mbedtls_ecdsa_ library/ecdsa.o
3328 not grep mbedtls_ecdh_ library/ecdh.o
3329 not grep mbedtls_ecjpake_ library/ecjpake.o
Valerio Setti4e2f2442023-08-15 10:10:26 +02003330 # Also ensure that ECP, RSA, [DHM] or BIGNUM modules were not re-enabled
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003331 not grep mbedtls_ecp_ library/ecp.o
Manuel Pégourié-Gonnard06aebe42023-06-12 18:33:34 +02003332 not grep mbedtls_rsa_ library/rsa.o
Manuel Pégourié-Gonnard660bbf22023-06-12 18:42:40 +02003333 not grep mbedtls_mpi_ library/bignum.o
Valerio Setti4e2f2442023-08-15 10:10:26 +02003334 not grep mbedtls_dhm_ library/dhm.o
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003335
3336 # Run the tests
3337 # -------------
3338
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003339 msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - DHM - BIGNUM"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003340
Gilles Peskine21570cf2023-12-22 11:49:50 +01003341 make test
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003342
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003343 msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
Valerio Setti18535c32023-07-31 11:27:17 +02003344 tests/ssl-opt.sh
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003345}
3346
Valerio Setti4e2f2442023-08-15 10:10:26 +02003347# Common helper used by:
3348# - component_test_psa_crypto_config_reference_ecc_no_bignum
3349# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
3350#
3351# The goal is to build and test a reference scenario (i.e. with builtin
3352# components) compared to the ones used in
3353# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
3354#
3355# It is meant to be used in conjunction with
3356# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
3357# coverage analysis in "analyze_outcomes.py" script.
3358common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003359 test_target="$1"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003360
Valerio Setti5dfaca42023-09-05 08:48:51 +02003361 # This is an internal helper to simplify text message handling
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003362 if [ "$test_target" = "ECC_DH" ]; then
3363 accel_text="ECC/FFDH"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003364 else
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003365 accel_text="ECC"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003366 fi
3367
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003368 msg "build: full + non accelerated $accel_text algs + USE_PSA"
Valerio Setti4e2f2442023-08-15 10:10:26 +02003369
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003370 config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003371
Gilles Peskine21570cf2023-12-22 11:49:50 +01003372 make
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003373
Valerio Setti29c1b4d2023-07-27 10:08:45 +02003374 msg "test suites: full + non accelerated EC algs + USE_PSA"
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003375 make test
3376
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003377 msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
Valerio Setti18535c32023-07-31 11:27:17 +02003378 tests/ssl-opt.sh
Manuel Pégourié-Gonnardabd00d02023-06-12 17:51:33 +02003379}
3380
Valerio Setti4e2f2442023-08-15 10:10:26 +02003381component_test_psa_crypto_config_accel_ecc_no_bignum () {
3382 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
3383}
3384
3385component_test_psa_crypto_config_reference_ecc_no_bignum () {
3386 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
3387}
3388
3389component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
3390 common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
3391}
3392
3393component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
3394 common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
3395}
3396
Valerio Settiac6d35f2023-08-04 12:49:11 +02003397# Helper for setting common configurations between:
3398# - component_test_tfm_config_p256m_driver_accel_ec()
3399# - component_test_tfm_config()
Valerio Setti52ba0e32023-08-04 12:43:03 +02003400common_tfm_config () {
3401 # Enable TF-M config
Yanray Wang70505042023-09-21 17:11:40 +08003402 cp configs/config-tfm.h "$CONFIG_H"
3403 echo "#undef MBEDTLS_PSA_CRYPTO_CONFIG_FILE" >> "$CONFIG_H"
3404 cp configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
Valerio Settic5c4bd22023-08-03 14:28:20 +02003405
Yanray Wang73bb2312023-09-25 11:21:15 +08003406 # Other config adjustment to make the tests pass.
3407 # This should probably be adopted upstream.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003408 #
Manuel Pégourié-Gonnard96839e72023-08-08 13:01:29 +02003409 # - USE_PSA_CRYPTO for PK_HAVE_ECC_KEYS
3410 echo "#define MBEDTLS_USE_PSA_CRYPTO" >> "$CONFIG_H"
Valerio Setti52ba0e32023-08-04 12:43:03 +02003411
Yanray Wang73bb2312023-09-25 11:21:15 +08003412 # Config adjustment for better test coverage in our environment.
3413 # This is not needed just to build and pass tests.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003414 #
3415 # Enable filesystem I/O for the benefit of PK parse/write tests.
3416 echo "#define MBEDTLS_FS_IO" >> "$CONFIG_H"
3417}
3418
Valerio Settiac6d35f2023-08-04 12:49:11 +02003419# Keep this in sync with component_test_tfm_config() as they are both meant
3420# to be used in analyze_outcomes.py for driver's coverage analysis.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003421component_test_tfm_config_p256m_driver_accel_ec () {
3422 msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
3423
3424 common_tfm_config
Valerio Settic5c4bd22023-08-03 14:28:20 +02003425
Dave Rodgman897bb772023-11-15 16:34:20 +00003426 # Build crypto library
Dave Rodgman17127e92023-12-14 16:42:48 +00003427 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003428
Manuel Pégourié-Gonnardf8930e22023-06-13 09:51:32 +02003429 # Make sure any built-in EC alg was not re-enabled by accident (additive config)
3430 not grep mbedtls_ecdsa_ library/ecdsa.o
Valerio Settib7e95442023-03-21 11:52:33 +01003431 not grep mbedtls_ecdh_ library/ecdh.o
3432 not grep mbedtls_ecjpake_ library/ecjpake.o
3433 # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
3434 not grep mbedtls_ecp_ library/ecp.o
3435 not grep mbedtls_rsa_ library/rsa.o
Valerio Settie4758aa2023-03-24 16:51:17 +01003436 not grep mbedtls_dhm_ library/dhm.o
Valerio Settiee97a1e2023-03-27 12:44:15 +02003437 not grep mbedtls_mpi_ library/bignum.o
Dave Rodgman897bb772023-11-15 16:34:20 +00003438 # Check that p256m was built
Dave Rodgmanbe5489a2023-11-27 10:30:03 +00003439 grep -q p256_ecdsa_ library/libmbedcrypto.a
Valerio Settib7e95442023-03-21 11:52:33 +01003440
Valerio Setti5e18b902023-12-04 12:07:30 +01003441 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
3442 # files, so we want to ensure that it has not be re-enabled accidentally.
3443 not grep mbedtls_cipher library/cipher.o
3444
Valerio Settib7e95442023-03-21 11:52:33 +01003445 # Run the tests
Valerio Setti52ba0e32023-08-04 12:43:03 +02003446 msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
Valerio Settib7e95442023-03-21 11:52:33 +01003447 make test
Valerio Settie4758aa2023-03-24 16:51:17 +01003448}
Valerio Settiee97a1e2023-03-27 12:44:15 +02003449
Valerio Settiac6d35f2023-08-04 12:49:11 +02003450# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
3451# they are both meant to be used in analyze_outcomes.py for driver's coverage
3452# analysis.
Valerio Setti52ba0e32023-08-04 12:43:03 +02003453component_test_tfm_config() {
3454 common_tfm_config
Valerio Settiee97a1e2023-03-27 12:44:15 +02003455
Dave Rodgman897bb772023-11-15 16:34:20 +00003456 # Disable P256M driver, which is on by default, so that analyze_outcomes
3457 # can compare this test with test_tfm_config_p256m_driver_accel_ec
3458 echo "#undef MBEDTLS_PSA_P256M_DRIVER_ENABLED" >> "$CONFIG_H"
3459
Valerio Setti52ba0e32023-08-04 12:43:03 +02003460 msg "build: TF-M config"
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02003461 make CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' tests
Valerio Setti52ba0e32023-08-04 12:43:03 +02003462
Dave Rodgman897bb772023-11-15 16:34:20 +00003463 # Check that p256m was not built
Dave Rodgmanbe5489a2023-11-27 10:30:03 +00003464 not grep p256_ecdsa_ library/libmbedcrypto.a
Dave Rodgman897bb772023-11-15 16:34:20 +00003465
Valerio Setti5e18b902023-12-04 12:07:30 +01003466 # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
3467 # files, so we want to ensure that it has not be re-enabled accidentally.
3468 not grep mbedtls_cipher library/cipher.o
3469
Valerio Setti52ba0e32023-08-04 12:43:03 +02003470 msg "test: TF-M config"
3471 make test
Valerio Settic5c4bd22023-08-03 14:28:20 +02003472}
3473
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003474# Common helper for component_full_without_ecdhe_ecdsa() and
3475# component_full_without_ecdhe_ecdsa_and_tls13() which:
3476# - starts from the "full" configuration minus the list of symbols passed in
3477# as 1st parameter
3478# - build
3479# - test only TLS (i.e. test_suite_tls and ssl-opt)
3480build_full_minus_something_and_test_tls () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003481 symbols_to_disable="$1"
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003482
3483 msg "build: full minus something, test TLS"
3484
3485 scripts/config.py full
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003486 for sym in $symbols_to_disable; do
3487 echo "Disabling $sym"
3488 scripts/config.py unset $sym
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003489 done
Valerio Settie4758aa2023-03-24 16:51:17 +01003490
Gilles Peskine21570cf2023-12-22 11:49:50 +01003491 make
Valerio Settiee97a1e2023-03-27 12:44:15 +02003492
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003493 msg "test: full minus something, test TLS"
3494 ( cd tests; ./test_suite_ssl )
Valerio Settib7e95442023-03-21 11:52:33 +01003495
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003496 msg "ssl-opt: full minus something, test TLS"
Valerio Settib7e95442023-03-21 11:52:33 +01003497 tests/ssl-opt.sh
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003498}
Valerio Setti1f1420d2023-03-28 10:35:45 +02003499
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003500component_full_without_ecdhe_ecdsa () {
3501 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED"
Valerio Settib7e95442023-03-21 11:52:33 +01003502}
3503
Valerio Setti5a57e2a2023-08-02 11:30:50 +02003504component_full_without_ecdhe_ecdsa_and_tls13 () {
3505 build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
3506 MBEDTLS_SSL_PROTO_TLS1_3"
Valerio Settie4758aa2023-03-24 16:51:17 +01003507}
3508
Valerio Setti249b18a2023-06-20 12:08:30 +02003509# This is an helper used by:
3510# - component_test_psa_ecc_key_pair_no_derive
3511# - component_test_psa_ecc_key_pair_no_generate
3512# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
3513# enabled, but one. Input arguments are as follows:
3514# - $1 is the key type under test, i.e. ECC/RSA/DH
3515# - $2 is the key option to be unset (i.e. generate, derive, etc)
Valerio Settia9836552023-06-22 11:22:23 +02003516build_and_test_psa_want_key_pair_partial() {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003517 key_type=$1
3518 unset_option=$2
3519 disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003520
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003521 msg "build: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003522 scripts/config.py full
Valerio Setti249b18a2023-06-20 12:08:30 +02003523 scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3524 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3525
3526 # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
3527 # crypto_config.h so we just disable the one we don't want.
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003528 scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
Valerio Setti249b18a2023-06-20 12:08:30 +02003529
Gilles Peskine21570cf2023-12-22 11:49:50 +01003530 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Valerio Setti249b18a2023-06-20 12:08:30 +02003531
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003532 msg "test: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
Valerio Setti249b18a2023-06-20 12:08:30 +02003533 make test
3534}
3535
3536component_test_psa_ecc_key_pair_no_derive() {
Valerio Settia9836552023-06-22 11:22:23 +02003537 build_and_test_psa_want_key_pair_partial "ECC" "DERIVE"
Valerio Setti249b18a2023-06-20 12:08:30 +02003538}
3539
3540component_test_psa_ecc_key_pair_no_generate() {
Valerio Settia9836552023-06-22 11:22:23 +02003541 build_and_test_psa_want_key_pair_partial "ECC" "GENERATE"
Valerio Setti249b18a2023-06-20 12:08:30 +02003542}
3543
Pengyu Lve705f572023-12-06 16:38:15 +08003544config_psa_crypto_accel_rsa () {
3545 driver_only=$1
Ronald Cron403c15c2021-09-13 09:38:05 +02003546
Pengyu Lve705f572023-12-06 16:38:15 +08003547 # Start from crypto_full config (no X.509, no TLS)
3548 helper_libtestdriver1_adjust_config "crypto_full"
3549
3550 if [ "$driver_only" -eq 1 ]; then
3551 # Remove RSA support and its dependencies
3552 scripts/config.py unset MBEDTLS_RSA_C
3553 scripts/config.py unset MBEDTLS_PKCS1_V15
3554 scripts/config.py unset MBEDTLS_PKCS1_V21
3555
3556 # We need PEM parsing in the test library as well to support the import
3557 # of PEM encoded RSA keys.
3558 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
3559 scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
3560 fi
3561}
3562
3563component_test_psa_crypto_config_accel_rsa_crypto () {
3564 msg "build: crypto_full with accelerated RSA"
3565
3566 loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
3567 ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
3568 KEY_TYPE_RSA_PUBLIC_KEY \
3569 KEY_TYPE_RSA_KEY_PAIR_BASIC \
3570 KEY_TYPE_RSA_KEY_PAIR_GENERATE \
3571 KEY_TYPE_RSA_KEY_PAIR_IMPORT \
3572 KEY_TYPE_RSA_KEY_PAIR_EXPORT"
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003573
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003574 # Configure
3575 # ---------
Ronald Cron403c15c2021-09-13 09:38:05 +02003576
Pengyu Lve705f572023-12-06 16:38:15 +08003577 config_psa_crypto_accel_rsa 1
Ronald Cron403c15c2021-09-13 09:38:05 +02003578
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003579 # Build
3580 # -----
3581
Pengyu Lve705f572023-12-06 16:38:15 +08003582 # These hashes are needed for unit tests.
Manuel Pégourié-Gonnarde47c53e2023-09-23 08:54:30 +02003583 loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
Pengyu Lve705f572023-12-06 16:38:15 +08003584 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003585 helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02003586
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003587 helper_libtestdriver1_make_main "$loc_accel_list"
Ronald Cron403c15c2021-09-13 09:38:05 +02003588
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003589 # Make sure this was not re-enabled by accident (additive config)
Pengyu Lv98a90c62023-12-07 17:23:25 +08003590 not grep mbedtls_rsa library/rsa.o
Ronald Cron403c15c2021-09-13 09:38:05 +02003591
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003592 # Run the tests
3593 # -------------
3594
Pengyu Lve705f572023-12-06 16:38:15 +08003595 msg "test: crypto_full with accelerated RSA"
Gilles Peskine21570cf2023-12-22 11:49:50 +01003596 make test
Pengyu Lve705f572023-12-06 16:38:15 +08003597}
3598
3599component_test_psa_crypto_config_reference_rsa_crypto () {
3600 msg "build: crypto_full with non-accelerated RSA"
3601
3602 # Configure
3603 # ---------
3604 config_psa_crypto_accel_rsa 0
3605
3606 # Build
3607 # -----
Gilles Peskine21570cf2023-12-22 11:49:50 +01003608 make
Pengyu Lve705f572023-12-06 16:38:15 +08003609
3610 # Run the tests
3611 # -------------
3612 msg "test: crypto_full with non-accelerated RSA"
Ronald Cron403c15c2021-09-13 09:38:05 +02003613 make test
3614}
3615
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003616# This is a temporary test to verify that full RSA support is present even when
Valerio Setti01cc88a2023-06-15 11:53:08 +02003617# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003618component_test_new_psa_want_key_pair_symbol() {
Valerio Setti01cc88a2023-06-15 11:53:08 +02003619 msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003620
Valerio Setti4590bc22023-06-13 15:39:23 +02003621 # Create a temporary output file unless there is already one set
3622 if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
3623 REMOVE_OUTCOME_ON_EXIT="no"
3624 else
3625 REMOVE_OUTCOME_ON_EXIT="yes"
3626 MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
3627 export MBEDTLS_TEST_OUTCOME_FILE
3628 fi
3629
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003630 # Start from crypto configuration
3631 scripts/config.py crypto
3632
3633 # Remove RSA support and its dependencies
3634 scripts/config.py unset MBEDTLS_PKCS1_V15
3635 scripts/config.py unset MBEDTLS_PKCS1_V21
3636 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3637 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3638 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3639 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
3640 scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
3641 scripts/config.py unset MBEDTLS_RSA_C
3642 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
3643
3644 # Enable PSA support
3645 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3646
Valerio Setti01cc88a2023-06-15 11:53:08 +02003647 # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003648 # that proper translations is done in crypto_legacy.h.
Ronald Cron6b49b552023-07-20 09:57:54 +02003649 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
3650 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
3651 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003652
3653 make
3654
Valerio Setti01cc88a2023-06-15 11:53:08 +02003655 msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
Valerio Setti4590bc22023-06-13 15:39:23 +02003656 make test
3657
3658 # Parse only 1 relevant line from the outcome file, i.e. a test which is
3659 # performing RSA signature.
3660 msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
3661 cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
3662
3663 if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
3664 rm $MBEDTLS_TEST_OUTCOME_FILE
3665 fi
Valerio Settia1a0b1b2023-06-13 14:19:03 +02003666}
3667
Ronald Cronb2312452021-05-08 14:32:59 +02003668component_test_psa_crypto_config_accel_hash () {
3669 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
3670
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003671 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3672 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3673 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Ronald Cronb2312452021-05-08 14:32:59 +02003674
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003675 # Configure
3676 # ---------
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003677
Ronald Cron46ac0652024-03-18 12:39:04 +01003678 # Start from default config (no USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003679 helper_libtestdriver1_adjust_config "default"
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003680
3681 # Disable the things that are being accelerated
Ronald Cronb2312452021-05-08 14:32:59 +02003682 scripts/config.py unset MBEDTLS_MD5_C
3683 scripts/config.py unset MBEDTLS_RIPEMD160_C
3684 scripts/config.py unset MBEDTLS_SHA1_C
Manuel Pégourié-Gonnardc584c272023-03-22 00:32:04 +01003685 scripts/config.py unset MBEDTLS_SHA224_C
3686 scripts/config.py unset MBEDTLS_SHA256_C
Ronald Cronb2312452021-05-08 14:32:59 +02003687 scripts/config.py unset MBEDTLS_SHA384_C
3688 scripts/config.py unset MBEDTLS_SHA512_C
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003689 scripts/config.py unset MBEDTLS_SHA3_C
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003690
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003691 # Build
3692 # -----
3693
3694 helper_libtestdriver1_make_drivers "$loc_accel_list"
3695
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003696 helper_libtestdriver1_make_main "$loc_accel_list"
Ronald Cronb2312452021-05-08 14:32:59 +02003697
Manuel Pégourié-Gonnardc584c272023-03-22 00:32:04 +01003698 # There's a risk of something getting re-enabled via config_psa.h;
3699 # make sure it did not happen. Note: it's OK for MD_C to be enabled.
3700 not grep mbedtls_md5 library/md5.o
3701 not grep mbedtls_sha1 library/sha1.o
3702 not grep mbedtls_sha256 library/sha256.o
3703 not grep mbedtls_sha512 library/sha512.o
3704 not grep mbedtls_ripemd160 library/ripemd160.o
Ronald Cronb2312452021-05-08 14:32:59 +02003705
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003706 # Run the tests
3707 # -------------
3708
Ronald Cronb2312452021-05-08 14:32:59 +02003709 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
3710 make test
3711}
3712
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003713# Auxiliary function to build config for hashes with and without drivers
3714config_psa_crypto_hash_use_psa () {
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003715 driver_only="$1"
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003716 # start with config full for maximum coverage (also enables USE_PSA)
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003717 helper_libtestdriver1_adjust_config "full"
Manuel Pégourié-Gonnard6be64f72023-09-28 09:08:04 +02003718 if [ "$driver_only" -eq 1 ]; then
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003719 # disable the built-in implementation of hashes
3720 scripts/config.py unset MBEDTLS_MD5_C
3721 scripts/config.py unset MBEDTLS_RIPEMD160_C
3722 scripts/config.py unset MBEDTLS_SHA1_C
3723 scripts/config.py unset MBEDTLS_SHA224_C
3724 scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
Dave Rodgman5b89c552023-10-10 14:59:02 +01003725 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003726 scripts/config.py unset MBEDTLS_SHA384_C
3727 scripts/config.py unset MBEDTLS_SHA512_C
3728 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003729 scripts/config.py unset MBEDTLS_SHA3_C
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003730 fi
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003731}
3732
Przemek Stekiel120ed8f2022-10-27 10:29:15 +02003733# Note that component_test_psa_crypto_config_reference_hash_use_psa
3734# is related to this component and both components need to be kept in sync.
3735# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003736component_test_psa_crypto_config_accel_hash_use_psa () {
Gilles Peskine14302ed2023-07-19 19:30:04 +02003737 msg "test: full with accelerated hashes"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003738
Manuel Pégourié-Gonnardcc21ad42023-09-22 09:46:14 +02003739 loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3740 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3741 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003742
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003743 # Configure
3744 # ---------
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003745
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003746 config_psa_crypto_hash_use_psa 1
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003747
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003748 # Build
3749 # -----
3750
3751 helper_libtestdriver1_make_drivers "$loc_accel_list"
3752
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003753 helper_libtestdriver1_make_main "$loc_accel_list"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003754
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003755 # There's a risk of something getting re-enabled via config_psa.h;
Manuel Pégourié-Gonnard49e67f82023-03-16 11:39:20 +01003756 # 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 +02003757 not grep mbedtls_md5 library/md5.o
3758 not grep mbedtls_sha1 library/sha1.o
Manuel Pégourié-Gonnard7b0825d2022-07-11 11:06:09 +02003759 not grep mbedtls_sha256 library/sha256.o
Manuel Pégourié-Gonnardf0f63bc2022-07-08 19:12:33 +02003760 not grep mbedtls_sha512 library/sha512.o
3761 not grep mbedtls_ripemd160 library/ripemd160.o
3762
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003763 # Run the tests
3764 # -------------
3765
Gilles Peskine14302ed2023-07-19 19:30:04 +02003766 msg "test: full with accelerated hashes"
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003767 make test
Andrzej Kurek07e35702022-09-05 15:39:23 -04003768
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003769 # This is mostly useful so that we can later compare outcome files with
3770 # the reference config in analyze_outcomes.py, to check that the
3771 # dependency declarations in ssl-opt.sh and in TLS code are correct.
Gilles Peskine14302ed2023-07-19 19:30:04 +02003772 msg "test: ssl-opt.sh, full with accelerated hashes"
Przemek Stekiel5f6f32a2022-10-27 08:24:43 +02003773 tests/ssl-opt.sh
Andrzej Kurek07e35702022-09-05 15:39:23 -04003774
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003775 # This is to make sure all ciphersuites are exercised, but we don't need
3776 # interop testing (besides, we already got some from ssl-opt.sh).
Gilles Peskine14302ed2023-07-19 19:30:04 +02003777 msg "test: compat.sh, full with accelerated hashes"
Manuel Pégourié-Gonnard30d94662022-11-29 12:37:53 +01003778 tests/compat.sh -p mbedTLS -V YES
Manuel Pégourié-Gonnard525add62022-07-06 13:06:57 +02003779}
3780
Przemek Stekiel120ed8f2022-10-27 10:29:15 +02003781# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
3782# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
3783# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
3784# Both components need to be kept in sync.
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003785component_test_psa_crypto_config_reference_hash_use_psa() {
Gilles Peskine14302ed2023-07-19 19:30:04 +02003786 msg "test: full without accelerated hashes"
Przemek Stekielaa88e0b2022-11-15 13:21:14 +01003787
3788 config_psa_crypto_hash_use_psa 0
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003789
Gilles Peskine21570cf2023-12-22 11:49:50 +01003790 make
Przemek Stekielab0451b2022-10-24 11:29:35 +02003791
Gilles Peskine14302ed2023-07-19 19:30:04 +02003792 msg "test: full without accelerated hashes"
Przemek Stekiel01df9dd2022-10-20 14:21:21 +02003793 make test
3794
Gilles Peskine14302ed2023-07-19 19:30:04 +02003795 msg "test: ssl-opt.sh, full without accelerated hashes"
Przemek Stekiel5f6f32a2022-10-27 08:24:43 +02003796 tests/ssl-opt.sh
Ronald Cron3a8714d2021-10-18 11:26:01 +02003797}
Manuel Pégourié-Gonnard97ab2a32022-07-06 10:46:57 +02003798
Valerio Setti8eb310c2024-01-22 16:22:57 +01003799# Auxiliary function to build config for hashes with and without drivers
3800config_psa_crypto_hmac_use_psa () {
3801 driver_only="$1"
3802 # start with config full for maximum coverage (also enables USE_PSA)
3803 helper_libtestdriver1_adjust_config "full"
3804
Valerio Setticd89b0b2024-01-24 14:24:55 +01003805 if [ "$driver_only" -eq 1 ]; then
3806 # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
3807 # is still enabled though (for ENTROPY_C among others).
3808 scripts/config.py unset MBEDTLS_MD_C
3809 # Disable also the builtin hashes since they are supported by the driver
3810 # and MD module is able to perform PSA dispathing.
3811 scripts/config.py unset-all MBEDTLS_SHA
3812 scripts/config.py unset MBEDTLS_MD5_C
3813 scripts/config.py unset MBEDTLS_RIPEMD160_C
3814 fi
3815
Valerio Setti8eb310c2024-01-22 16:22:57 +01003816 # Direct dependencies of MD_C. We disable them also in the reference
3817 # component to work with the same set of features.
3818 scripts/config.py unset MBEDTLS_PKCS7_C
3819 scripts/config.py unset MBEDTLS_PKCS5_C
3820 scripts/config.py unset MBEDTLS_HMAC_DRBG_C
3821 scripts/config.py unset MBEDTLS_HKDF_C
3822 # Dependencies of HMAC_DRBG
3823 scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
3824 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
3825}
3826
3827component_test_psa_crypto_config_accel_hmac() {
3828 msg "test: full with accelerated hmac"
3829
3830 loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
3831 ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3832 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3833 ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
3834
3835 # Configure
3836 # ---------
3837
3838 config_psa_crypto_hmac_use_psa 1
3839
Valerio Setti8eb310c2024-01-22 16:22:57 +01003840 # Build
3841 # -----
3842
3843 helper_libtestdriver1_make_drivers "$loc_accel_list"
3844
3845 helper_libtestdriver1_make_main "$loc_accel_list"
3846
3847 # Ensure that built-in support for HMAC is disabled.
3848 not grep mbedtls_md_hmac library/md.o
3849
3850 # Run the tests
3851 # -------------
3852
3853 msg "test: full with accelerated hmac"
3854 make test
3855}
3856
3857component_test_psa_crypto_config_reference_hmac() {
3858 msg "test: full without accelerated hmac"
3859
3860 config_psa_crypto_hmac_use_psa 0
3861
3862 make
3863
3864 msg "test: full without accelerated hmac"
3865 make test
3866}
3867
Valerio Setti9da01a72023-12-18 17:38:18 +01003868component_test_psa_crypto_config_accel_des () {
Valerio Settib9f4bfc2023-12-28 11:07:48 +01003869 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
Ronald Cron067de3b2021-03-11 11:49:03 +01003870
Valerio Setti9da01a72023-12-18 17:38:18 +01003871 # Albeit this components aims at accelerating DES which should only support
3872 # CBC and ECB modes, we need to accelerate more than that otherwise DES_C
3873 # would automatically be re-enabled by "config_adjust_legacy_from_psa.c"
Valerio Setti0244fbb2023-10-19 10:42:31 +02003874 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 \
3875 ALG_CTR ALG_CFB ALG_OFB ALG_XTS ALG_CMAC \
3876 KEY_TYPE_DES"
John Durkopd8959392020-09-20 23:09:17 -07003877
Valerio Setti9da01a72023-12-18 17:38:18 +01003878 # Note: we cannot accelerate all ciphers' key types otherwise we would also
3879 # have to either disable CCM/GCM or accelerate them, but that's out of scope
3880 # of this component. This limitation will be addressed by #8598.
3881
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003882 # Configure
3883 # ---------
Ronald Cron067de3b2021-03-11 11:49:03 +01003884
Valerio Setti9a427302023-10-17 11:40:42 +02003885 # Start from the full config
Valerio Settia797ce32023-10-03 15:16:38 +02003886 helper_libtestdriver1_adjust_config "full"
Ronald Cron067de3b2021-03-11 11:49:03 +01003887
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003888 # Disable the things that are being accelerated
Ronald Cron067de3b2021-03-11 11:49:03 +01003889 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3890 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
3891 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
3892 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
3893 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
3894 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
3895 scripts/config.py unset MBEDTLS_DES_C
Yanray Wangaf5003a2023-10-11 11:57:10 +08003896 scripts/config.py unset MBEDTLS_CMAC_C
Ronald Cron067de3b2021-03-11 11:49:03 +01003897
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003898 # Build
3899 # -----
Gilles Peskine3587dfd2021-09-20 19:20:04 +02003900
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003901 helper_libtestdriver1_make_drivers "$loc_accel_list"
3902
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003903 helper_libtestdriver1_make_main "$loc_accel_list"
Gilles Peskine3587dfd2021-09-20 19:20:04 +02003904
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003905 # Make sure this was not re-enabled by accident (additive config)
Gilles Peskine3587dfd2021-09-20 19:20:04 +02003906 not grep mbedtls_des* library/des.o
Ronald Cron17b3afc2020-12-10 18:17:09 +01003907
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003908 # Run the tests
3909 # -------------
3910
Valerio Settib9f4bfc2023-12-28 11:07:48 +01003911 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
John Durkop4377bf72020-10-23 01:26:57 -07003912 make test
3913}
3914
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003915component_test_psa_crypto_config_accel_aead () {
3916 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
3917
Valerio Setti3f02bb72023-10-02 15:57:33 +02003918 loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
3919 KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003920
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003921 # Configure
3922 # ---------
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003923
Valerio Setti3f02bb72023-10-02 15:57:33 +02003924 # Start from full config
3925 helper_libtestdriver1_adjust_config "full"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003926
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003927 # Disable things that are being accelerated
Przemek Stekielee1bb412022-10-11 11:52:25 +02003928 scripts/config.py unset MBEDTLS_GCM_C
3929 scripts/config.py unset MBEDTLS_CCM_C
3930 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003931
Valerio Settia50b89e2023-11-08 15:58:47 +01003932 # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
3933 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003934
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003935 # Build
3936 # -----
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003937
Manuel Pégourié-Gonnard8df87bf2023-06-12 17:09:38 +02003938 helper_libtestdriver1_make_drivers "$loc_accel_list"
3939
Manuel Pégourié-Gonnard27dd73f2023-05-25 10:39:23 +02003940 helper_libtestdriver1_make_main "$loc_accel_list"
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003941
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003942 # Make sure this was not re-enabled by accident (additive config)
Przemek Stekielee1bb412022-10-11 11:52:25 +02003943 not grep mbedtls_ccm library/ccm.o
3944 not grep mbedtls_gcm library/gcm.o
3945 not grep mbedtls_chachapoly library/chachapoly.o
3946
Manuel Pégourié-Gonnard239094d2023-05-31 12:51:50 +02003947 # Run the tests
3948 # -------------
3949
Przemek Stekiele290f2e2022-10-02 20:58:39 +02003950 msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
3951 make test
3952}
3953
Valerio Settib680fc42023-10-13 09:29:37 +02003954# This is a common configuration function used in:
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +01003955# - component_test_psa_crypto_config_accel_cipher_aead_cmac
3956# - component_test_psa_crypto_config_reference_cipher_aead_cmac
3957common_psa_crypto_config_accel_cipher_aead_cmac() {
Pengyu Lv78657d02023-10-27 11:00:32 +08003958 # Start from the full config
3959 helper_libtestdriver1_adjust_config "full"
3960
Valerio Settib680fc42023-10-13 09:29:37 +02003961 scripts/config.py unset MBEDTLS_NIST_KW_C
3962}
3963
Valerio Settib6b301f2023-10-04 12:05:05 +02003964# The 2 following test components, i.e.
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +01003965# - component_test_psa_crypto_config_accel_cipher_aead_cmac
3966# - component_test_psa_crypto_config_reference_cipher_aead_cmac
Valerio Settib6b301f2023-10-04 12:05:05 +02003967# are meant to be used together in analyze_outcomes.py script in order to test
3968# driver's coverage for ciphers and AEADs.
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +01003969component_test_psa_crypto_config_accel_cipher_aead_cmac () {
3970 msg "build: full config with accelerated cipher inc. AEAD and CMAC"
Valerio Settib6b301f2023-10-04 12:05:05 +02003971
Valerio Settiad8b7f02023-10-25 12:39:50 +02003972 loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
Valerio Setti51d5b192023-11-08 10:56:54 +01003973 ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
Valerio Setti97454fd2023-10-25 12:27:12 +02003974 ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
Valerio Settib6b301f2023-10-04 12:05:05 +02003975 KEY_TYPE_DES KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
3976
3977 # Configure
3978 # ---------
3979
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +01003980 common_psa_crypto_config_accel_cipher_aead_cmac
Valerio Settib6b301f2023-10-04 12:05:05 +02003981
3982 # Disable the things that are being accelerated
3983 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3984 scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
3985 scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
3986 scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
3987 scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
3988 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
3989 scripts/config.py unset MBEDTLS_GCM_C
3990 scripts/config.py unset MBEDTLS_CCM_C
3991 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Valerio Setti97454fd2023-10-25 12:27:12 +02003992 scripts/config.py unset MBEDTLS_CMAC_C
Valerio Settib6b301f2023-10-04 12:05:05 +02003993 scripts/config.py unset MBEDTLS_DES_C
3994 scripts/config.py unset MBEDTLS_AES_C
3995 scripts/config.py unset MBEDTLS_ARIA_C
3996 scripts/config.py unset MBEDTLS_CHACHA20_C
3997 scripts/config.py unset MBEDTLS_CAMELLIA_C
3998
Valerio Settiec9b2582023-11-08 16:50:54 +01003999 # Disable CIPHER_C entirely as all ciphers/AEADs are accelerated and PSA
4000 # does not depend on it.
4001 scripts/config.py unset MBEDTLS_CIPHER_C
4002
Valerio Settib6b301f2023-10-04 12:05:05 +02004003 # Build
4004 # -----
4005
4006 helper_libtestdriver1_make_drivers "$loc_accel_list"
4007
4008 helper_libtestdriver1_make_main "$loc_accel_list"
4009
4010 # Make sure this was not re-enabled by accident (additive config)
Valerio Settiec9b2582023-11-08 16:50:54 +01004011 not grep mbedtls_cipher library/cipher.o
Valerio Setti58d2b1a2023-10-12 15:24:12 +02004012 not grep mbedtls_des library/des.o
4013 not grep mbedtls_aes library/aes.o
4014 not grep mbedtls_aria library/aria.o
4015 not grep mbedtls_camellia library/camellia.o
Valerio Settib6b301f2023-10-04 12:05:05 +02004016 not grep mbedtls_ccm library/ccm.o
4017 not grep mbedtls_gcm library/gcm.o
4018 not grep mbedtls_chachapoly library/chachapoly.o
4019 not grep mbedtls_cmac library/cmac.o
4020
4021 # Run the tests
4022 # -------------
4023
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +01004024 msg "test: full config with accelerated cipher inc. AEAD and CMAC"
Gilles Peskine21570cf2023-12-22 11:49:50 +01004025 make test
Valerio Settif9414552023-11-09 10:43:20 +01004026
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +01004027 msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
Valerio Settif9414552023-11-09 10:43:20 +01004028 tests/ssl-opt.sh
Pengyu Lvf561ed82023-11-14 17:33:32 +08004029
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +01004030 msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
Pengyu Lvf561ed82023-11-14 17:33:32 +08004031 tests/compat.sh -V NO -p mbedTLS
Valerio Settib6b301f2023-10-04 12:05:05 +02004032}
4033
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +01004034component_test_psa_crypto_config_reference_cipher_aead_cmac () {
4035 msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
4036 common_psa_crypto_config_accel_cipher_aead_cmac
Valerio Settib6b301f2023-10-04 12:05:05 +02004037
Gilles Peskine21570cf2023-12-22 11:49:50 +01004038 make
Valerio Settif9414552023-11-09 10:43:20 +01004039
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +01004040 msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
Valerio Settib6b301f2023-10-04 12:05:05 +02004041 make test
Valerio Settif9414552023-11-09 10:43:20 +01004042
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +01004043 msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
Valerio Settif9414552023-11-09 10:43:20 +01004044 tests/ssl-opt.sh
Pengyu Lvf561ed82023-11-14 17:33:32 +08004045
Manuel Pégourié-Gonnard7f48d5e2024-01-08 10:55:09 +01004046 msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
Pengyu Lvf561ed82023-11-14 17:33:32 +08004047 tests/compat.sh -V NO -p mbedTLS
Valerio Settib6b301f2023-10-04 12:05:05 +02004048}
4049
Valerio Setti4a8ef7c2023-12-19 11:16:27 +01004050common_block_cipher_dispatch() {
4051 TEST_WITH_DRIVER="$1"
4052
4053 # Start from the full config
4054 helper_libtestdriver1_adjust_config "full"
4055
4056 if [ "$TEST_WITH_DRIVER" -eq 1 ]; then
4057 # Disable key types that are accelerated (there is no legacy equivalent
4058 # symbol for ECB)
4059 scripts/config.py unset MBEDTLS_AES_C
4060 scripts/config.py unset MBEDTLS_ARIA_C
4061 scripts/config.py unset MBEDTLS_CAMELLIA_C
4062 fi
4063
Valerio Setti8c8b4da2024-01-02 11:44:30 +01004064 # Disable cipher's modes that, when not accelerated, cause
Valerio Setti4a8ef7c2023-12-19 11:16:27 +01004065 # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
Valerio Setticd21d4e2023-12-28 16:00:55 +01004066 # Keep this also in the reference component in order to skip the same tests
4067 # that were skipped in the accelerated one.
Valerio Setti4a8ef7c2023-12-19 11:16:27 +01004068 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
4069 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
4070 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
4071 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
4072 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
4073 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
4074 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
Valerio Setti4a8ef7c2023-12-19 11:16:27 +01004075
4076 # Disable direct dependency on AES_C
4077 scripts/config.py unset MBEDTLS_NIST_KW_C
4078
4079 # Prevent the cipher module from using deprecated PSA path. The reason is
4080 # that otherwise there will be tests relying on "aes_info" (defined in
4081 # "cipher_wrap.c") whose functions are not available when AES_C is
4082 # not defined. ARIA and Camellia are not a problem in this case because
4083 # the PSA path is not tested for these key types.
4084 scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
4085}
4086
Valerio Settif8e6cba2023-12-12 11:53:39 +01004087component_test_full_block_cipher_psa_dispatch () {
4088 msg "build: full + PSA dispatch in block_cipher"
4089
4090 loc_accel_list="ALG_ECB_NO_PADDING \
4091 KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
4092
4093 # Configure
4094 # ---------
4095
Valerio Setti4a8ef7c2023-12-19 11:16:27 +01004096 common_block_cipher_dispatch 1
Valerio Settif8e6cba2023-12-12 11:53:39 +01004097
Valerio Settif8e6cba2023-12-12 11:53:39 +01004098 # Build
4099 # -----
4100
4101 helper_libtestdriver1_make_drivers "$loc_accel_list"
4102
4103 helper_libtestdriver1_make_main "$loc_accel_list"
4104
Valerio Setti4a8ef7c2023-12-19 11:16:27 +01004105 # Make sure disabled components were not re-enabled by accident (additive
4106 # config)
4107 not grep mbedtls_aes_ library/aes.o
4108 not grep mbedtls_aria_ library/aria.o
4109 not grep mbedtls_camellia_ library/camellia.o
4110
Valerio Settif8e6cba2023-12-12 11:53:39 +01004111 # Run the tests
4112 # -------------
4113
4114 msg "test: full + PSA dispatch in block_cipher"
4115 make test
4116}
4117
Valerio Setti4a8ef7c2023-12-19 11:16:27 +01004118# This is the reference component of component_test_full_block_cipher_psa_dispatch
4119component_test_full_block_cipher_legacy_dispatch () {
4120 msg "build: full + legacy dispatch in block_cipher"
4121
4122 common_block_cipher_dispatch 0
4123
Valerio Setti4a8ef7c2023-12-19 11:16:27 +01004124 make
4125
4126 msg "test: full + legacy dispatch in block_cipher"
4127 make test
4128}
4129
Gilles Peskine36dea152023-07-20 22:19:45 +02004130component_test_aead_chachapoly_disabled() {
4131 msg "build: full minus CHACHAPOLY"
Przemyslaw Stekiel1ecfdea2021-10-13 11:09:44 +02004132 scripts/config.py full
4133 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
Ronald Cron6b49b552023-07-20 09:57:54 +02004134 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
Gilles Peskine21570cf2023-12-22 11:49:50 +01004135 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Przemyslaw Stekiel1ecfdea2021-10-13 11:09:44 +02004136
Gilles Peskine36dea152023-07-20 22:19:45 +02004137 msg "test: full minus CHACHAPOLY"
4138 make test
4139}
4140
4141component_test_aead_only_ccm() {
4142 msg "build: full minus CHACHAPOLY and GCM"
4143 scripts/config.py full
4144 scripts/config.py unset MBEDTLS_CHACHAPOLY_C
4145 scripts/config.py unset MBEDTLS_GCM_C
4146 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
4147 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
Gilles Peskine21570cf2023-12-22 11:49:50 +01004148 make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskine36dea152023-07-20 22:19:45 +02004149
4150 msg "test: full minus CHACHAPOLY and GCM"
Przemyslaw Stekiel1ecfdea2021-10-13 11:09:44 +02004151 make test
4152}
4153
Ronald Crone501d0e2023-07-10 08:31:19 +02004154component_test_ccm_aes_sha256() {
4155 msg "build: CCM + AES + SHA256 configuration"
4156
Ronald Cron7612d8c2023-07-20 10:03:54 +02004157 cp "$CONFIG_TEST_DRIVER_H" "$CONFIG_H"
Ronald Cron6b49b552023-07-20 09:57:54 +02004158 cp configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
Ronald Crone501d0e2023-07-10 08:31:19 +02004159
Dave Rodgmanea03ef92023-12-19 12:19:59 +00004160 make
Ronald Crone501d0e2023-07-10 08:31:19 +02004161
4162 msg "test: CCM + AES + SHA256 configuration"
4163 make test
4164}
4165
Dave Rodgman904c5892023-06-28 17:36:02 +01004166support_build_tfm_armcc () {
Yanray Wang799bd842023-11-10 12:21:35 +08004167 support_build_armcc
Dave Rodgmanc164c072023-06-28 09:43:23 +01004168}
4169
Dave Rodgman904c5892023-06-28 17:36:02 +01004170component_build_tfm_armcc() {
4171 # test the TF-M configuration can build cleanly with various warning flags enabled
Dave Rodgman82d7a872023-11-28 10:06:33 +00004172 cp configs/config-tfm.h "$CONFIG_H"
Dave Rodgmanc164c072023-06-28 09:43:23 +01004173
Dave Rodgman88651c42023-06-29 12:35:51 +01004174 msg "build: TF-M config, armclang armv7-m thumb2"
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02004175 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 +01004176}
4177
4178component_build_tfm() {
Gilles Peskineeaa1c562023-09-06 16:23:13 +02004179 # Check that the TF-M configuration can build cleanly with various
4180 # warning flags enabled. We don't build or run tests, since the
4181 # TF-M configuration needs a TF-M platform. A tweaked version of
4182 # the configuration that works on mainstream platforms is in
4183 # configs/config-tfm.h, tested via test-ref-configs.pl.
Dave Rodgman82d7a872023-11-28 10:06:33 +00004184 cp configs/config-tfm.h "$CONFIG_H"
Dave Rodgmanfb374e62023-06-29 11:58:16 +01004185
Dave Rodgman88651c42023-06-29 12:35:51 +01004186 msg "build: TF-M config, clang, armv7-m thumb2"
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02004187 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 +01004188
Dave Rodgman904c5892023-06-28 17:36:02 +01004189 msg "build: TF-M config, gcc native build"
4190 make clean
Gilles Peskinec1bedfe2023-09-27 15:53:08 +02004191 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 +01004192}
4193
Dave Rodgman54ada8b2023-10-04 11:55:25 +01004194# Test that the given .o file builds with all (valid) combinations of the given options.
4195#
4196# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
4197#
4198# The validator function is the name of a function to validate the combination of options.
4199# It may be "" if all combinations are valid.
4200# It receives a string containing a combination of options, as passed to the compiler,
Dave Rodgmanf3803a12023-10-16 13:47:15 +01004201# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
Dave Rodgman920343a2023-10-01 18:41:09 +01004202build_test_config_combos() {
Dave Rodgman28e38d82023-10-04 11:50:30 +01004203 file=$1
Dave Rodgman920343a2023-10-01 18:41:09 +01004204 shift
Dave Rodgman28e38d82023-10-04 11:50:30 +01004205 validate_options=$1
Dave Rodgman920343a2023-10-01 18:41:09 +01004206 shift
Dave Rodgman28e38d82023-10-04 11:50:30 +01004207 options=("$@")
Dave Rodgman0f0f7692023-06-29 12:10:45 +01004208
Dave Rodgman42436102023-10-03 15:47:05 +01004209 # clear all of the options so that they can be overridden on the clang commandline
Dave Rodgman28e38d82023-10-04 11:50:30 +01004210 for opt in "${options[@]}"; do
4211 ./scripts/config.py unset ${opt}
Dave Rodgman42436102023-10-03 15:47:05 +01004212 done
4213
4214 # enter the directory containing the target file & strip the dir from the filename
Dave Rodgman28e38d82023-10-04 11:50:30 +01004215 cd $(dirname ${file})
4216 file=$(basename ${file})
Dave Rodgman42436102023-10-03 15:47:05 +01004217
Dave Rodgman920343a2023-10-01 18:41:09 +01004218 # The most common issue is unused variables/functions, so ensure -Wunused is set.
Dave Rodgman28e38d82023-10-04 11:50:30 +01004219 warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
Dave Rodgman97285622023-09-29 17:32:06 +01004220
Dave Rodgman42436102023-10-03 15:47:05 +01004221 # Extract the command generated by the Makefile to build the target file.
4222 # This ensures that we have any include paths, macro definitions, etc
4223 # that may be applied by make.
4224 # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01004225 compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
Dave Rodgman42436102023-10-03 15:47:05 +01004226
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01004227 makefile=$(TMPDIR=. mktemp)
Dave Rodgman28e38d82023-10-04 11:50:30 +01004228 deps=""
Dave Rodgman97285622023-09-29 17:32:06 +01004229
Dave Rodgman28e38d82023-10-04 11:50:30 +01004230 len=${#options[@]}
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01004231 source_file=${file%.o}.c
4232
4233 targets=0
4234 echo 'include Makefile' >${makefile}
Dave Rodgman97285622023-09-29 17:32:06 +01004235
Dave Rodgman28e38d82023-10-04 11:50:30 +01004236 for ((i = 0; i < $((2**${len})); i++)); do
Dave Rodgman920343a2023-10-01 18:41:09 +01004237 # generate each of 2^n combinations of options
Dave Rodgman28e38d82023-10-04 11:50:30 +01004238 # each bit of $i is used to determine if options[i] will be set or not
4239 target="t"
4240 clang_args=""
4241 for ((j = 0; j < ${len}; j++)); do
Dave Rodgmanb1107ae2023-10-04 12:30:23 +01004242 if (((i >> j) & 1)); then
Dave Rodgmana7127eb2023-10-04 13:38:41 +01004243 opt=-D${options[$j]}
Dave Rodgman7a8a2492023-10-04 13:14:20 +01004244 clang_args="${clang_args} ${opt}"
4245 target="${target}${opt}"
Dave Rodgmanb1107ae2023-10-04 12:30:23 +01004246 fi
Dave Rodgman920343a2023-10-01 18:41:09 +01004247 done
4248
Dave Rodgmanb1107ae2023-10-04 12:30:23 +01004249 # if combination is not known to be invalid, add it to the makefile
Dave Rodgmanf3803a12023-10-16 13:47:15 +01004250 if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
Dave Rodgman28e38d82023-10-04 11:50:30 +01004251 cmd="${compile_cmd} ${clang_args}"
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01004252 echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
Dave Rodgman920343a2023-10-01 18:41:09 +01004253
Dave Rodgman28e38d82023-10-04 11:50:30 +01004254 deps="${deps} ${target}"
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01004255 ((++targets))
Dave Rodgman745af9f2023-09-29 15:47:07 +01004256 fi
Dave Rodgman97285622023-09-29 17:32:06 +01004257 done
Dave Rodgman6001fb22023-06-29 09:29:00 +01004258
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01004259 echo "build_test_config_combos: ${deps}" >> ${makefile}
Dave Rodgmanaea01c92023-09-29 18:54:49 +01004260
Dave Rodgman920343a2023-10-01 18:41:09 +01004261 # execute all of the commands via Make (probably in parallel)
Dave Rodgmancc88ccd2023-10-13 10:33:15 +01004262 make -s -f ${makefile} build_test_config_combos
4263 echo "$targets targets checked"
Dave Rodgman920343a2023-10-01 18:41:09 +01004264
4265 # clean up the temporary makefile
Dave Rodgman28e38d82023-10-04 11:50:30 +01004266 rm ${makefile}
Dave Rodgman6001fb22023-06-29 09:29:00 +01004267}
4268
Dave Rodgman43a5ce82023-10-02 17:09:37 +01004269validate_aes_config_variations() {
Dave Rodgman920343a2023-10-01 18:41:09 +01004270 if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
4271 if [[ "$1" == *"MBEDTLS_PADLOCK_C"* ]]; then
Dave Rodgman41bc7982023-10-16 14:04:21 +01004272 return 1
Dave Rodgman920343a2023-10-01 18:41:09 +01004273 fi
4274 if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
4275 ("$HOSTTYPE" == "x86_64" && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
Dave Rodgman41bc7982023-10-16 14:04:21 +01004276 return 1
Dave Rodgman920343a2023-10-01 18:41:09 +01004277 fi
4278 fi
Dave Rodgman41bc7982023-10-16 14:04:21 +01004279 return 0
Dave Rodgman920343a2023-10-01 18:41:09 +01004280}
4281
4282component_build_aes_variations() {
4283 # 18s - around 90ms per clang invocation on M1 Pro
4284 #
Gilles Peskine8f073122018-11-27 15:58:47 +01004285 # aes.o has many #if defined(...) guards that intersect in complex ways.
Dave Rodgman920343a2023-10-01 18:41:09 +01004286 # Test that all the combinations build cleanly.
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004287
Yanray Wangbc29aef2023-11-06 11:08:17 +08004288 MBEDTLS_ROOT_DIR="$PWD"
Gilles Peskine32e889d2020-04-12 23:43:28 +02004289 msg "build: aes.o for all combinations of relevant config options"
Gilles Peskinef4d2fd42021-10-08 11:45:47 +02004290
Dave Rodgman42436102023-10-03 15:47:05 +01004291 build_test_config_combos library/aes.o validate_aes_config_variations \
Dave Rodgman920343a2023-10-01 18:41:09 +01004292 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
4293 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
4294 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
4295 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
Yanray Wangbc29aef2023-11-06 11:08:17 +08004296
4297 cd "$MBEDTLS_ROOT_DIR"
4298 msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
4299
Yanray Wang42be1ba2023-11-23 14:28:47 +08004300 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES,
Yanray Wangbc29aef2023-11-06 11:08:17 +08004301 # manually set or unset those configurations to check
4302 # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
Yanray Wangbc29aef2023-11-06 11:08:17 +08004303 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
4304 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
4305 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
4306 scripts/config.py unset MBEDTLS_DES_C
4307 scripts/config.py unset MBEDTLS_NIST_KW_C
4308 build_test_config_combos library/aes.o validate_aes_config_variations \
4309 "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
4310 "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
4311 "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
4312 "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004313}
Gilles Peskinee7fc7ef2021-10-19 21:33:32 +02004314
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04004315component_test_no_platform () {
4316 # Full configuration build, without platform support, file IO and net sockets.
4317 # This should catch missing mbedtls_printf definitions, and by disabling file
4318 # IO, it should catch missing '#include <stdio.h>'
4319 msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
Paul Elliottfb81f772023-10-18 17:44:59 +01004320 scripts/config.py full_no_platform
Simon Butcherf95c1762016-11-10 17:25:58 +00004321 scripts/config.py unset MBEDTLS_PLATFORM_C
4322 scripts/config.py unset MBEDTLS_NET_C
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +01004323 scripts/config.py unset MBEDTLS_FS_IO
4324 scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
Simon Butcherb9283432016-07-13 11:02:41 +01004325 scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
Manuel Pégourié-Gonnard3d4755b2015-06-03 14:03:17 +01004326 scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
Paul Elliottfb81f772023-10-18 17:44:59 +01004327 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
Simon Butcher284b4c92016-06-26 13:10:00 +01004328 # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02004329 # to re-enable platform integration features otherwise disabled in C99 builds
4330 make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
Gilles Peskine21570cf2023-12-22 11:49:50 +01004331 make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
Simon Butchercb587002017-01-06 16:14:44 +00004332}
Gilles Peskine7c652162017-12-11 00:01:40 +01004333
4334component_build_no_std_function () {
Manuel Pégourié-Gonnarda71780e2015-02-13 13:56:55 +00004335 # catch compile bugs in _uninit functions
Gilles Peskine8f073122018-11-27 15:58:47 +01004336 msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
4337 scripts/config.py full
4338 scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
Gilles Peskine8f073122018-11-27 15:58:47 +01004339 scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
4340 scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
4341 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
4342 make
4343}
Manuel Pégourié-Gonnarddccb80b2015-06-03 10:20:33 +01004344
Gilles Peskine8f073122018-11-27 15:58:47 +01004345component_build_no_ssl_srv () {
4346 msg "build: full config except SSL server, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01004347 scripts/config.py full
4348 scripts/config.py unset MBEDTLS_SSL_SRV_C
Gilles Peskine21570cf2023-12-22 11:49:50 +01004349 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01004350}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02004351
Gilles Peskine8f073122018-11-27 15:58:47 +01004352component_build_no_ssl_cli () {
4353 msg "build: full config except SSL client, make, gcc" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01004354 scripts/config.py full
4355 scripts/config.py unset MBEDTLS_SSL_CLI_C
Gilles Peskine21570cf2023-12-22 11:49:50 +01004356 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
Gilles Peskine8f073122018-11-27 15:58:47 +01004357}
Manuel Pégourié-Gonnard66b8e952015-05-20 11:13:56 +02004358
Gilles Peskine8f073122018-11-27 15:58:47 +01004359component_build_no_sockets () {
4360 # Note, C99 compliance can also be tested with the sockets support disabled,
4361 # as that requires a POSIX platform (which isn't the same as C99).
4362 msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
Gilles Peskine8f073122018-11-27 15:58:47 +01004363 scripts/config.py full
4364 scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
4365 scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
4366 make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
4367}
Manuel Pégourié-Gonnard009a2642015-05-29 10:31:13 +02004368
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004369component_test_memory_buffer_allocator_backtrace () {
Hanno Becker0fb9ba22019-02-26 14:34:13 +00004370 msg "build: default config with memory buffer allocator and backtrace enabled"
4371 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4372 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4373 scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04004374 scripts/config.py set MBEDTLS_MEMORY_DEBUG
Dave Rodgmanea03ef92023-12-19 12:19:59 +00004375 cmake -DCMAKE_BUILD_TYPE:String=Release .
Andrzej Kurek69f20aa2019-09-05 09:27:47 -04004376 make
4377
4378 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
4379 make test
4380}
4381
4382component_test_memory_buffer_allocator () {
4383 msg "build: default config with memory buffer allocator"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004384 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4385 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
Dave Rodgmanea03ef92023-12-19 12:19:59 +00004386 cmake -DCMAKE_BUILD_TYPE:String=Release .
Hanno Becker0fb9ba22019-02-26 14:34:13 +00004387 make
4388
4389 msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
4390 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01004391
4392 msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
4393 # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004394 tests/ssl-opt.sh -e '^DTLS proxy'
Hanno Becker0fb9ba22019-02-26 14:34:13 +00004395}
4396
Gilles Peskine8f073122018-11-27 15:58:47 +01004397component_test_no_max_fragment_length () {
4398 # Run max fragment length tests with MFL disabled
4399 msg "build: default config except MFL extension (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004400 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
Dave Rodgman17127e92023-12-14 16:42:48 +00004401 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine8f073122018-11-27 15:58:47 +01004402 make
Hanno Becker5175ac62017-09-18 15:36:25 +01004403
Gilles Peskine8f073122018-11-27 15:58:47 +01004404 msg "test: ssl-opt.sh, MFL-related tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004405 tests/ssl-opt.sh -f "Max fragment length"
Gilles Peskine8f073122018-11-27 15:58:47 +01004406}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004407
Hanno Becker545ced42019-02-19 11:10:48 +00004408component_test_asan_remove_peer_certificate () {
4409 msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004410 scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
Ronald Crona3f385d2024-03-18 10:25:37 +01004411 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
Dave Rodgman17127e92023-12-14 16:42:48 +00004412 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Hanno Becker545ced42019-02-19 11:10:48 +00004413 make
4414
4415 msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
4416 make test
4417
4418 msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004419 tests/ssl-opt.sh
Hanno Becker545ced42019-02-19 11:10:48 +00004420
4421 msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004422 tests/compat.sh
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02004423
4424 msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004425 tests/context-info.sh
Hanno Becker545ced42019-02-19 11:10:48 +00004426}
4427
Gilles Peskine8f073122018-11-27 15:58:47 +01004428component_test_no_max_fragment_length_small_ssl_out_content_len () {
4429 msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004430 scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4431 scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
4432 scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
Dave Rodgman17127e92023-12-14 16:42:48 +00004433 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine8f073122018-11-27 15:58:47 +01004434 make
Angus Grattonc4dd0732018-04-11 16:28:39 +10004435
Gilles Peskine8f073122018-11-27 15:58:47 +01004436 msg "test: MFL tests (disabled MFL extension case) & large packet tests"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004437 tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02004438
4439 msg "test: context-info.sh (disabled MFL extension case)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004440 tests/context-info.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01004441}
Angus Grattonc4dd0732018-04-11 16:28:39 +10004442
Darryl Greenaad82f92019-12-02 10:53:11 +00004443component_test_variable_ssl_in_out_buffer_len () {
4444 msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
4445 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
Dave Rodgman17127e92023-12-14 16:42:48 +00004446 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Darryl Greenaad82f92019-12-02 10:53:11 +00004447 make
4448
4449 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
4450 make test
4451
4452 msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004453 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004454
4455 msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004456 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004457}
4458
Manuel Pégourié-Gonnard6a543ba2022-11-25 11:30:10 +01004459component_test_dtls_cid_legacy () {
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004460 msg "build: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled (ASan build)"
Hannes Tschofenigfd6cca42021-10-12 09:22:33 +02004461 scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 1
Darryl Greenaad82f92019-12-02 10:53:11 +00004462
Dave Rodgman17127e92023-12-14 16:42:48 +00004463 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Darryl Greenaad82f92019-12-02 10:53:11 +00004464 make
4465
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004466 msg "test: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy)"
Darryl Greenaad82f92019-12-02 10:53:11 +00004467 make test
4468
Hannes Tschofenigdf84bb32022-11-23 11:14:03 +01004469 msg "test: ssl-opt.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004470 tests/ssl-opt.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004471
Manuel Pégourié-Gonnard6a543ba2022-11-25 11:30:10 +01004472 msg "test: compat.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004473 tests/compat.sh
Darryl Greenaad82f92019-12-02 10:53:11 +00004474}
4475
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004476component_test_ssl_alloc_buffer_and_mfl () {
4477 msg "build: default config with memory buffer allocator and MFL extension"
4478 scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4479 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4480 scripts/config.py set MBEDTLS_MEMORY_DEBUG
4481 scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4482 scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
Dave Rodgmanea03ef92023-12-19 12:19:59 +00004483 cmake -DCMAKE_BUILD_TYPE:String=Release .
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004484 make
4485
4486 msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
4487 make test
4488
4489 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 +02004490 tests/ssl-opt.sh -f "Handshake memory usage"
Piotr Nowicki0937ed22019-11-26 16:32:40 +01004491}
4492
Gilles Peskine636c26a2020-03-04 20:46:15 +01004493component_test_when_no_ciphersuites_have_mac () {
4494 msg "build: when no ciphersuites have MAC"
4495 scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
Gilles Peskine636c26a2020-03-04 20:46:15 +01004496 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
TRodziewicz2add5c12021-04-28 16:50:20 +02004497 scripts/config.py unset MBEDTLS_CMAC_C
Gilles Peskine636c26a2020-03-04 20:46:15 +01004498 make
4499
4500 msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
4501 make test
4502
4503 msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004504 tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
Gilles Peskine636c26a2020-03-04 20:46:15 +01004505}
4506
Raoul Strackxa4e86142020-06-15 17:03:13 +02004507component_test_no_date_time () {
4508 msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
4509 scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
Dave Rodgmanea03ef92023-12-19 12:19:59 +00004510 cmake -D CMAKE_BUILD_TYPE:String=Check .
Raoul Strackxa4e86142020-06-15 17:03:13 +02004511 make
4512
4513 msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
4514 make test
4515}
4516
Gilles Peskine8f073122018-11-27 15:58:47 +01004517component_test_platform_calloc_macro () {
4518 msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02004519 scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4520 scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
4521 scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO free
Dave Rodgman17127e92023-12-14 16:42:48 +00004522 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine8f073122018-11-27 15:58:47 +01004523 make
Hanno Beckere5fecec2018-10-11 11:02:52 +01004524
Gilles Peskine8f073122018-11-27 15:58:47 +01004525 msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
4526 make test
4527}
Hanno Beckere5fecec2018-10-11 11:02:52 +01004528
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02004529component_test_malloc_0_null () {
4530 msg "build: malloc(0) returns NULL (ASan+UBSan build)"
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01004531 scripts/config.py full
Gilles Peskine21570cf2023-12-22 11:49:50 +01004532 make CC=$ASAN_CC CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"$PWD/tests/configs/user-config-malloc-0-null.h\"' $ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02004533
4534 msg "test: malloc(0) returns NULL (ASan+UBSan build)"
4535 make test
4536
4537 msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
4538 # Just the calloc selftest. "make test" ran the others as part of the
4539 # test suites.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004540 programs/test/selftest calloc
Gilles Peskine765d2402020-02-11 18:26:34 +01004541
4542 msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
4543 # Run a subset of the tests. The choice is a balance between coverage
4544 # and time (including time indirectly wasted due to flaky tests).
4545 # The current choice is to skip tests whose description includes
4546 # "proxy", which is an approximation of skipping tests that use the
4547 # UDP proxy, which tend to be slower and flakier.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02004548 tests/ssl-opt.sh -e 'proxy'
Gilles Peskinec4ef7a92019-09-17 19:04:38 +02004549}
4550
Dave Rodgman6a08b682023-06-19 11:51:33 +01004551support_test_aesni() {
4552 # Check that gcc targets x86_64 (we can build AESNI), and check for
4553 # AESNI support on the host (we can run AESNI).
4554 #
4555 # The name of this function is possibly slightly misleading, but needs to align
4556 # with the name of the corresponding test, component_test_aesni.
Dave Rodgmanf8986e32023-06-19 10:55:59 +01004557 #
4558 # In principle 32-bit x86 can support AESNI, but our implementation does not
4559 # support 32-bit x86, so we check for x86-64.
4560 # We can only grep /proc/cpuinfo on Linux, so this also checks for Linux
Dave Rodgman6a08b682023-06-19 11:51:33 +01004561 (gcc -v 2>&1 | grep Target | grep -q x86_64) &&
4562 [[ "$HOSTTYPE" == "x86_64" && "$OSTYPE" == "linux-gnu" ]] &&
Jerry Yua7de78d2023-08-08 12:57:35 +08004563 (lscpu | grep -qw aes)
Dave Rodgmanf8986e32023-06-19 10:55:59 +01004564}
4565
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004566component_test_aesni () { # ~ 60s
4567 # This tests the two AESNI implementations (intrinsics and assembly), and also the plain C
4568 # fallback. It also tests the logic that is used to select which implementation(s) to build.
4569 #
4570 # This test does not require the host to have support for AESNI (if it doesn't, the run-time
4571 # AESNI detection will fallback to the plain C implementation, so the tests will instead
4572 # exercise the plain C impl).
4573
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004574 msg "build: default config with different AES implementations"
Dave Rodgman838dc462023-06-16 13:18:19 +01004575 scripts/config.py set MBEDTLS_AESNI_C
Jerry Yu17a9d2e2023-08-03 16:14:18 +08004576 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Dave Rodgman838dc462023-06-16 13:18:19 +01004577 scripts/config.py set MBEDTLS_HAVE_ASM
4578
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004579 # test the intrinsics implementation
4580 msg "AES tests, test intrinsics"
Dave Rodgman838dc462023-06-16 13:18:19 +01004581 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004582 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004583 # check that we built intrinsics - this should be used by default when supported by the compiler
Jerry Yu1221a312023-08-03 16:09:07 +08004584 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004585
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004586 # test the asm implementation
4587 msg "AES tests, test assembly"
4588 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004589 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mno-pclmul -mno-sse2 -mno-aes'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004590 # check that we built assembly - this should be built if the compiler does not support intrinsics
Jerry Yu1221a312023-08-03 16:09:07 +08004591 ./programs/test/selftest aes | grep "AESNI code" | grep -q "assembly"
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004592
4593 # test the plain C implementation
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004594 scripts/config.py unset MBEDTLS_AESNI_C
Jerry Yu17a9d2e2023-08-03 16:14:18 +08004595 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Dave Rodgmanbe60fcc2023-06-16 17:04:52 +01004596 msg "AES tests, plain C"
4597 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004598 make CC=gcc CFLAGS='-O2 -Werror'
Dave Rodgman96a9e6a2023-06-16 20:18:36 +01004599 # check that there is no AESNI code present
Jerry Yu1221a312023-08-03 16:09:07 +08004600 ./programs/test/selftest aes | not grep -q "AESNI code"
Jerry Yu76a51b92023-08-08 16:03:55 +08004601 not grep -q "AES note: using AESNI" ./programs/test/selftest
4602 grep -q "AES note: built-in implementation." ./programs/test/selftest
Jerry Yu8a599c02023-08-03 17:01:02 +08004603
4604 # test the intrinsics implementation
4605 scripts/config.py set MBEDTLS_AESNI_C
4606 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4607 msg "AES tests, test AESNI only"
4608 make clean
Jerry Yua7de78d2023-08-08 12:57:35 +08004609 make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
Jerry Yua7de78d2023-08-08 12:57:35 +08004610 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
4611 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
Jerry Yu76a51b92023-08-08 16:03:55 +08004612 grep -q "AES note: using AESNI" ./programs/test/selftest
4613 not grep -q "AES note: built-in implementation." ./programs/test/selftest
Dave Rodgman838dc462023-06-16 13:18:19 +01004614}
4615
Dave Rodgman08b81bf2024-02-26 18:03:29 +00004616component_test_sha3_variations() {
4617 msg "sha3 loop unroll variations"
4618
4619 # define minimal config sufficient to test SHA3
4620 cat > include/mbedtls/mbedtls_config.h << END
4621 #define MBEDTLS_SELF_TEST
4622 #define MBEDTLS_SHA3_C
4623END
4624
4625 msg "all loops unrolled"
4626 make clean
4627 make -C tests test_suite_shax CFLAGS="-DMBEDTLS_SHA3_THETA_UNROLL=1 -DMBEDTLS_SHA3_PI_UNROLL=1 -DMBEDTLS_SHA3_CHI_UNROLL=1 -DMBEDTLS_SHA3_RHO_UNROLL=1"
4628 ./tests/test_suite_shax
4629
4630 msg "all loops rolled up"
4631 make clean
4632 make -C tests test_suite_shax CFLAGS="-DMBEDTLS_SHA3_THETA_UNROLL=0 -DMBEDTLS_SHA3_PI_UNROLL=0 -DMBEDTLS_SHA3_CHI_UNROLL=0 -DMBEDTLS_SHA3_RHO_UNROLL=0"
4633 ./tests/test_suite_shax
4634}
4635
Jerry Yub6d39c22023-08-16 15:11:48 +08004636support_test_aesni_m32() {
Dave Rodgman852de3c2023-12-14 14:46:45 +00004637 support_test_m32_no_asm && (lscpu | grep -qw aes)
Jerry Yub6d39c22023-08-16 15:11:48 +08004638}
4639
4640component_test_aesni_m32 () { # ~ 60s
4641 # This tests are duplicated from component_test_aesni for i386 target
4642 #
4643 # AESNI intrinsic code supports i386 and assembly code does not support it.
4644
4645 msg "build: default config with different AES implementations"
4646 scripts/config.py set MBEDTLS_AESNI_C
4647 scripts/config.py set MBEDTLS_PADLOCK_C
4648 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4649 scripts/config.py set MBEDTLS_HAVE_ASM
4650
Beniamin Sandu3bca7812023-10-24 18:55:36 +01004651 # test the intrinsics implementation with gcc
4652 msg "AES tests, test intrinsics (gcc)"
Jerry Yub6d39c22023-08-16 15:11:48 +08004653 make clean
Beniamin Sandu3bca7812023-10-24 18:55:36 +01004654 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra' LDFLAGS='-m32'
Jerry Yub6d39c22023-08-16 15:11:48 +08004655 # check that we built intrinsics - this should be used by default when supported by the compiler
4656 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
4657 grep -q "AES note: using AESNI" ./programs/test/selftest
4658 grep -q "AES note: built-in implementation." ./programs/test/selftest
4659 grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4660 grep -q mbedtls_aesni_has_support ./programs/test/selftest
4661
4662 scripts/config.py set MBEDTLS_AESNI_C
Jerry Yub6d39c22023-08-16 15:11:48 +08004663 scripts/config.py unset MBEDTLS_PADLOCK_C
4664 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4665 msg "AES tests, test AESNI only"
4666 make clean
4667 make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
4668 ./programs/test/selftest aes | grep -q "AES note: using AESNI"
4669 ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
4670 grep -q "AES note: using AESNI" ./programs/test/selftest
4671 not grep -q "AES note: built-in implementation." ./programs/test/selftest
4672 not grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4673 not grep -q mbedtls_aesni_has_support ./programs/test/selftest
4674}
4675
Beniamin Sandu3bca7812023-10-24 18:55:36 +01004676support_test_aesni_m32_clang() {
Tom Cosgroved4c373a2024-01-30 13:56:38 +00004677 # clang >= 4 is required to build with target attributes
4678 support_test_aesni_m32 && [[ $(clang_version) -ge 4 ]]
Beniamin Sandu3bca7812023-10-24 18:55:36 +01004679}
4680
4681component_test_aesni_m32_clang() {
4682
4683 scripts/config.py set MBEDTLS_AESNI_C
4684 scripts/config.py set MBEDTLS_PADLOCK_C
4685 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4686 scripts/config.py set MBEDTLS_HAVE_ASM
4687
4688 # test the intrinsics implementation with clang
4689 msg "AES tests, test intrinsics (clang)"
4690 make clean
4691 make CC=clang CFLAGS='-m32 -Werror -Wall -Wextra' LDFLAGS='-m32'
4692 # check that we built intrinsics - this should be used by default when supported by the compiler
4693 ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
4694 grep -q "AES note: using AESNI" ./programs/test/selftest
4695 grep -q "AES note: built-in implementation." ./programs/test/selftest
4696 grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4697 grep -q mbedtls_aesni_has_support ./programs/test/selftest
4698}
4699
Jerry Yu193cbc02023-08-03 17:06:29 +08004700# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
4701component_build_aes_aesce_armcc () {
4702 msg "Build: AESCE test on arm64 platform without plain C."
4703 scripts/config.py baremetal
4704
4705 # armc[56] don't support SHA-512 intrinsics
4706 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
4707
4708 # Stop armclang warning about feature detection for A64_CRYPTO.
4709 # With this enabled, the library does build correctly under armclang,
4710 # but in baremetal builds (as tested here), feature detection is
4711 # unavailable, and the user is notified via a #warning. So enabling
4712 # this feature would prevent us from building with -Werror on
4713 # armclang. Tracked in #7198.
Dave Rodgman5b89c552023-10-10 14:59:02 +01004714 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Jerry Yu193cbc02023-08-03 17:06:29 +08004715 scripts/config.py set MBEDTLS_HAVE_ASM
4716
4717 msg "AESCE, build with default configuration."
4718 scripts/config.py set MBEDTLS_AESCE_C
4719 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4720 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
4721
4722 msg "AESCE, build AESCE only"
4723 scripts/config.py set MBEDTLS_AESCE_C
4724 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4725 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
4726}
4727
Dave Rodgman0c584032023-10-08 12:26:54 +01004728support_build_aes_armce() {
Tom Cosgrove9e4eeff2024-01-30 13:51:18 +00004729 # clang >= 11 is required to build with AES extensions
Tom Cosgroved4c373a2024-01-30 13:56:38 +00004730 [[ $(clang_version) -ge 11 ]]
Dave Rodgman0c584032023-10-08 12:26:54 +01004731}
4732
4733component_build_aes_armce () {
4734 # Test variations of AES with Armv8 crypto extensions
4735 scripts/config.py set MBEDTLS_AESCE_C
4736 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4737
4738 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, aarch64"
Dave Rodgmanb622ff82023-10-08 22:25:16 +01004739 make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
Dave Rodgman0c584032023-10-08 12:26:54 +01004740
4741 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, arm"
4742 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
4743
4744 msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, thumb"
4745 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
4746
Dave Rodgman5e419372023-10-23 15:30:20 +01004747 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Dave Rodgman0c584032023-10-08 12:26:54 +01004748
Dave Rodgman5e419372023-10-23 15:30:20 +01004749 msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, aarch64"
4750 make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
Dave Rodgman0c584032023-10-08 12:26:54 +01004751
Dave Rodgman5e419372023-10-23 15:30:20 +01004752 msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, arm"
4753 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
Dave Rodgman0c584032023-10-08 12:26:54 +01004754
Dave Rodgman5e419372023-10-23 15:30:20 +01004755 msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, thumb"
4756 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
Dave Rodgmanf3501b42023-10-11 16:21:25 +01004757
4758 # test for presence of AES instructions
4759 scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4760 msg "clang, test A32 crypto instructions built"
4761 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
4762 grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
4763 msg "clang, test T32 crypto instructions built"
4764 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
4765 grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
4766 msg "clang, test aarch64 crypto instructions built"
4767 make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
4768 grep -E 'aes[a-z]+\s*[qv]' library/aesce.o
4769
4770 # test for absence of AES instructions
4771 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4772 scripts/config.py unset MBEDTLS_AESCE_C
4773 msg "clang, test A32 crypto instructions not built"
4774 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
4775 not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
4776 msg "clang, test T32 crypto instructions not built"
4777 make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
4778 not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
4779 msg "clang, test aarch64 crypto instructions not built"
4780 make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
4781 not grep -E 'aes[a-z]+\s*[qv]' library/aesce.o
Dave Rodgman0c584032023-10-08 12:26:54 +01004782}
4783
Dave Rodgman9ed18532023-10-05 00:06:47 +01004784support_build_sha_armce() {
Tom Cosgroved4c373a2024-01-30 13:56:38 +00004785 # clang >= 4 is required to build with SHA extensions
4786 [[ $(clang_version) -ge 4 ]]
Dave Rodgman9ed18532023-10-05 00:06:47 +01004787}
4788
Dave Rodgmand9e80832023-10-04 17:17:46 +01004789component_build_sha_armce () {
Dave Rodgman5b89c552023-10-10 14:59:02 +01004790 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004791
4792
4793 # Test variations of SHA256 Armv8 crypto extensions
Dave Rodgman5b89c552023-10-10 14:59:02 +01004794 scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004795 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, aarch64"
4796 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
4797 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, arm"
4798 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
4799 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
Dave Rodgmand9e80832023-10-04 17:17:46 +01004800
Dave Rodgmand9e80832023-10-04 17:17:46 +01004801
Dave Rodgman94a634d2023-10-10 12:59:29 +01004802 # test the deprecated form of the config option
Dave Rodgman94a634d2023-10-10 12:59:29 +01004803 scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004804 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY clang, thumb"
4805 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
4806 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
Dave Rodgmand9e80832023-10-04 17:17:46 +01004807
Dave Rodgman5b89c552023-10-10 14:59:02 +01004808 scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004809 msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT clang, aarch64"
4810 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
4811 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Dave Rodgmand9e80832023-10-04 17:17:46 +01004812
Dave Rodgmancd654002023-10-05 09:40:07 +01004813
Dave Rodgman94a634d2023-10-10 12:59:29 +01004814 # test the deprecated form of the config option
Dave Rodgman94a634d2023-10-10 12:59:29 +01004815 scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004816 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, arm"
4817 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -std=c99"
4818 msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, thumb"
4819 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
4820 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
Dave Rodgman94a634d2023-10-10 12:59:29 +01004821
Dave Rodgmancd654002023-10-05 09:40:07 +01004822
Dave Rodgmanf4b415c2023-10-11 16:11:42 +01004823 # examine the disassembly for presence of SHA instructions
4824 for opt in MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT; do
4825 scripts/config.py set ${opt}
4826 msg "${opt} clang, test A32 crypto instructions built"
4827 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
4828 grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4829
4830 msg "${opt} clang, test T32 crypto instructions built"
4831 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
4832 grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4833
4834 msg "${opt} clang, test aarch64 crypto instructions built"
4835 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
4836 grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.o
4837 scripts/config.py unset ${opt}
4838 done
4839
4840
4841 # examine the disassembly for absence of SHA instructions
4842 msg "clang, test A32 crypto instructions not built"
4843 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
4844 not grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4845
4846 msg "clang, test T32 crypto instructions not built"
4847 make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
4848 not grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
4849
4850 msg "clang, test aarch64 crypto instructions not built"
4851 make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
4852 not grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.o
Dave Rodgmand9e80832023-10-04 17:17:46 +01004853}
4854
Jerry Yuc935aa62023-08-03 17:08:27 +08004855# For timebeing, no VIA Padlock platform available.
4856component_build_aes_via_padlock () {
4857
4858 msg "AES:VIA PadLock, build with default configuration."
Jerry Yu506759f2023-08-16 17:11:22 +08004859 scripts/config.py unset MBEDTLS_AESNI_C
Jerry Yuc935aa62023-08-03 17:08:27 +08004860 scripts/config.py set MBEDTLS_PADLOCK_C
4861 scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
Dave Rodgmanb90f87b2023-12-14 23:27:33 +00004862 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
Jerry Yu506759f2023-08-16 17:11:22 +08004863 grep -q mbedtls_padlock_has_support ./programs/test/selftest
Jerry Yuc935aa62023-08-03 17:08:27 +08004864
4865}
4866
4867support_build_aes_via_padlock_only () {
4868 ( [ "$MBEDTLS_TEST_PLATFORM" == "Linux-x86_64" ] || \
4869 [ "$MBEDTLS_TEST_PLATFORM" == "Linux-amd64" ] ) && \
4870 [ "`dpkg --print-foreign-architectures`" == "i386" ]
4871}
4872
Jerry Yu193cbc02023-08-03 17:06:29 +08004873support_build_aes_aesce_armcc () {
4874 support_build_armcc
Gilles Peskine8f073122018-11-27 15:58:47 +01004875}
4876
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004877component_test_aes_only_128_bit_keys () {
Gilles Peskine8f073122018-11-27 15:58:47 +01004878 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
Hanno Becker83ebf782017-07-07 12:29:15 +01004879 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01004880 scripts/config.py unset MBEDTLS_PADLOCK_C
4881
Dave Rodgmand8d64512023-12-19 12:20:21 +00004882 make CFLAGS='-O2 -Werror -Wall -Wextra'
Hanno Becker83ebf782017-07-07 12:29:15 +01004883
4884 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
4885 make test
4886}
4887
4888component_test_no_ctr_drbg_aes_only_128_bit_keys () {
4889 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
4890 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
Gilles Peskine8f073122018-11-27 15:58:47 +01004891 scripts/config.py unset MBEDTLS_CTR_DRBG_C
4892 scripts/config.py unset MBEDTLS_PADLOCK_C
4893
Hanno Becker83ebf782017-07-07 12:29:15 +01004894 make CC=clang CFLAGS='-Werror -Wall -Wextra'
Gilles Peskine8f073122018-11-27 15:58:47 +01004895
4896 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02004897 make test
4898}
Gilles Peskine8f073122018-11-27 15:58:47 +01004899
Hanno Becker83ebf782017-07-07 12:29:15 +01004900component_test_aes_only_128_bit_keys_have_builtins () {
Gilles Peskine8f073122018-11-27 15:58:47 +01004901 msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4902 scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
4903 scripts/config.py unset MBEDTLS_PADLOCK_C
4904 scripts/config.py unset MBEDTLS_AESNI_C
Gilles Peskine592f5912019-10-07 18:49:32 +02004905 scripts/config.py unset MBEDTLS_AESCE_C
4906
Dave Rodgmand8d64512023-12-19 12:20:21 +00004907 make CFLAGS='-O2 -Werror -Wall -Wextra'
Gilles Peskine3b46cd32020-02-18 17:56:33 +01004908
4909 msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
Gilles Peskine592f5912019-10-07 18:49:32 +02004910 make test
4911
4912 msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
4913 programs/test/selftest
4914}
4915
Matthias Schulz0767fda2024-02-07 10:46:28 +01004916component_test_gcm_largetable () {
Matthias Schulza6ac0f12024-02-09 17:09:42 +01004917 msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
4918 scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
Matthias Schulz0767fda2024-02-07 10:46:28 +01004919 scripts/config.py unset MBEDTLS_PADLOCK_C
4920 scripts/config.py unset MBEDTLS_AESNI_C
4921 scripts/config.py unset MBEDTLS_AESCE_C
4922
4923 make CFLAGS='-O2 -Werror -Wall -Wextra'
4924
Matthias Schulza6ac0f12024-02-09 17:09:42 +01004925 msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
Matthias Schulz0767fda2024-02-07 10:46:28 +01004926 make test
4927}
4928
Manuel Pégourié-Gonnard9b06abe2015-06-25 09:56:07 +02004929component_test_aes_fewer_tables () {
4930 msg "build: default config with AES_FEWER_TABLES enabled"
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004931 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
Dave Rodgmand8d64512023-12-19 12:20:21 +00004932 make CFLAGS='-O2 -Werror -Wall -Wextra'
Gilles Peskine7ad603e2017-12-10 23:22:20 +01004933
Gilles Peskine7c652162017-12-11 00:01:40 +01004934 msg "test: AES_FEWER_TABLES"
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004935 make test
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01004936}
4937
4938component_test_aes_rom_tables () {
4939 msg "build: default config with AES_ROM_TABLES enabled"
4940 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Dave Rodgmand8d64512023-12-19 12:20:21 +00004941 make CFLAGS='-O2 -Werror -Wall -Wextra'
Andres Amaya Garciaf4fbdda2017-05-08 11:19:19 +01004942
4943 msg "test: AES_ROM_TABLES"
4944 make test
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00004945}
4946
Gilles Peskine14c3c062018-01-29 21:25:12 +01004947component_test_aes_fewer_tables_and_rom_tables () {
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004948 msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
4949 scripts/config.py set MBEDTLS_AES_FEWER_TABLES
4950 scripts/config.py set MBEDTLS_AES_ROM_TABLES
Dave Rodgmand8d64512023-12-19 12:20:21 +00004951 make CFLAGS='-O2 -Werror -Wall -Wextra'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01004952
Gilles Peskine8f073122018-11-27 15:58:47 +01004953 msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
4954 make test
4955}
4956
Yanray Wang49cd4b52023-11-10 11:58:37 +08004957# helper for common_block_cipher_no_decrypt() which:
4958# - enable/disable the list of config options passed from -s/-u respectively.
4959# - build
4960# - test for tests_suite_xxx
4961# - selftest
4962#
4963# Usage: helper_block_cipher_no_decrypt_build_test
4964# [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
4965# Options: -s set_opts the list of config options to enable
4966# -u unset_opts the list of config options to disable
4967# -c cflags the list of options passed to CFLAGS
4968# -l ldflags the list of options passed to LDFLAGS
4969helper_block_cipher_no_decrypt_build_test () {
4970 while [ $# -gt 0 ]; do
4971 case "$1" in
4972 -s)
4973 shift; local set_opts="$1";;
4974 -u)
4975 shift; local unset_opts="$1";;
4976 -c)
Yanray Wang07e663d2023-11-13 17:15:39 +08004977 shift; local cflags="-Werror -Wall -Wextra $1";;
Yanray Wang49cd4b52023-11-10 11:58:37 +08004978 -l)
4979 shift; local ldflags="$1";;
4980 esac
4981 shift
4982 done
4983 set_opts="${set_opts:-}"
4984 unset_opts="${unset_opts:-}"
4985 cflags="${cflags:-}"
4986 ldflags="${ldflags:-}"
4987
Yanray Wangb2d6e522023-11-13 16:57:47 +08004988 [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
4989 [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
Yanray Wang49cd4b52023-11-10 11:58:37 +08004990
4991 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
4992 make clean
Dave Rodgmandfe5ce82023-12-19 11:47:18 +00004993 make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
Yanray Wang49cd4b52023-11-10 11:58:37 +08004994
4995 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
4996 not grep mbedtls_aes_setkey_dec library/aes.o
4997 not grep mbedtls_aria_setkey_dec library/aria.o
4998 not grep mbedtls_camellia_setkey_dec library/camellia.o
4999 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
5000 not grep mbedtls_internal_aes_decrypt library/aes.o
Yanray Wang85b74652023-11-13 16:48:36 +08005001 # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
5002 not grep mbedtls_aesni_inverse_key library/aesni.o
Yanray Wang49cd4b52023-11-10 11:58:37 +08005003
5004 msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
5005 make test
5006
5007 msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
5008 programs/test/selftest
5009}
5010
5011# This is a common configuration function used in:
5012# - component_test_block_cipher_no_decrypt_aesni_legacy()
5013# - component_test_block_cipher_no_decrypt_aesni_use_psa()
5014# in order to test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics,
5015# AESNI assembly and AES C implementation on x86_64 and with AESNI intrinsics
5016# on x86.
5017common_block_cipher_no_decrypt () {
5018 # test AESNI intrinsics
5019 helper_block_cipher_no_decrypt_build_test \
5020 -s "MBEDTLS_AESNI_C" \
Yanray Wang07e663d2023-11-13 17:15:39 +08005021 -c "-mpclmul -msse2 -maes"
Yanray Wang49cd4b52023-11-10 11:58:37 +08005022
5023 # test AESNI assembly
5024 helper_block_cipher_no_decrypt_build_test \
5025 -s "MBEDTLS_AESNI_C" \
Yanray Wang07e663d2023-11-13 17:15:39 +08005026 -c "-mno-pclmul -mno-sse2 -mno-aes"
Yanray Wang49cd4b52023-11-10 11:58:37 +08005027
5028 # test AES C implementation
5029 helper_block_cipher_no_decrypt_build_test \
Yanray Wang07e663d2023-11-13 17:15:39 +08005030 -u "MBEDTLS_AESNI_C"
Yanray Wang49cd4b52023-11-10 11:58:37 +08005031
5032 # test AESNI intrinsics for i386 target
5033 helper_block_cipher_no_decrypt_build_test \
5034 -s "MBEDTLS_AESNI_C" \
Yanray Wang07e663d2023-11-13 17:15:39 +08005035 -c "-m32 -mpclmul -msse2 -maes" \
Yanray Wang49cd4b52023-11-10 11:58:37 +08005036 -l "-m32"
5037}
5038
Yanray Wang3ae11992023-11-13 17:32:09 +08005039# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
5040# usage: 0: no PSA crypto configuration
5041# 1: use PSA crypto configuration
5042config_block_cipher_no_decrypt () {
5043 use_psa=$1
5044
Yanray Wang66111392023-10-31 18:54:54 +08005045 scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
Yanray Wanga8ac23a2023-05-15 18:03:10 +08005046 scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
5047 scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
Yanray Wang3caaf0c2023-09-07 17:50:14 +08005048 scripts/config.py unset MBEDTLS_DES_C
Yanray Wanga8ac23a2023-05-15 18:03:10 +08005049 scripts/config.py unset MBEDTLS_NIST_KW_C
5050
Yanray Wang3ae11992023-11-13 17:32:09 +08005051 if [ "$use_psa" -eq 1 ]; then
5052 # Enable support for cryptographic mechanisms through the PSA API.
5053 # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
5054 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
5055 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
5056 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
5057 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
5058 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
5059 fi
5060}
5061
5062component_test_block_cipher_no_decrypt_aesni () {
Dave Rodgmanc3932222023-12-19 17:51:51 +00005063 # This consistently causes an llvm crash on clang 3.8, so use gcc
5064 export CC=gcc
Yanray Wang3ae11992023-11-13 17:32:09 +08005065 config_block_cipher_no_decrypt 0
Yanray Wang49cd4b52023-11-10 11:58:37 +08005066 common_block_cipher_no_decrypt
Yanray Wanga8ac23a2023-05-15 18:03:10 +08005067}
5068
Yanray Wangf1496402023-11-01 18:55:13 +08005069component_test_block_cipher_no_decrypt_aesni_use_psa () {
Dave Rodgmanc3932222023-12-19 17:51:51 +00005070 # This consistently causes an llvm crash on clang 3.8, so use gcc
5071 export CC=gcc
Yanray Wang3ae11992023-11-13 17:32:09 +08005072 config_block_cipher_no_decrypt 1
Yanray Wang49cd4b52023-11-10 11:58:37 +08005073 common_block_cipher_no_decrypt
Yanray Wang78219042023-08-31 15:00:57 +08005074}
5075
Yanray Wang66111392023-10-31 18:54:54 +08005076support_test_block_cipher_no_decrypt_aesce_armcc () {
Yanray Wang799bd842023-11-10 12:21:35 +08005077 support_build_armcc
Yanray Wangbf66ef92023-08-31 14:47:01 +08005078}
5079
Yanray Wang66111392023-10-31 18:54:54 +08005080component_test_block_cipher_no_decrypt_aesce_armcc () {
Yanray Wangbf66ef92023-08-31 14:47:01 +08005081 scripts/config.py baremetal
5082
5083 # armc[56] don't support SHA-512 intrinsics
5084 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
5085
5086 # Stop armclang warning about feature detection for A64_CRYPTO.
5087 # With this enabled, the library does build correctly under armclang,
5088 # but in baremetal builds (as tested here), feature detection is
5089 # unavailable, and the user is notified via a #warning. So enabling
5090 # this feature would prevent us from building with -Werror on
5091 # armclang. Tracked in #7198.
5092 scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
5093 scripts/config.py set MBEDTLS_HAVE_ASM
5094
Yanray Wang3ae11992023-11-13 17:32:09 +08005095 config_block_cipher_no_decrypt 1
Yanray Wangbf66ef92023-08-31 14:47:01 +08005096
5097 # test AESCE baremetal build
5098 scripts/config.py set MBEDTLS_AESCE_C
Yanray Wang66111392023-10-31 18:54:54 +08005099 msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
Yanray Wangc4347912023-11-14 10:10:49 +08005100 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
Yanray Wangbf66ef92023-08-31 14:47:01 +08005101
Yanray Wangef1b04d2023-09-08 11:09:26 +08005102 # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
5103 not grep mbedtls_aes_setkey_dec library/aes.o
5104 not grep mbedtls_aria_setkey_dec library/aria.o
5105 not grep mbedtls_camellia_setkey_dec library/camellia.o
5106 # Make sure we don't have mbedtls_internal_aes_decrypt in AES
5107 not grep mbedtls_internal_aes_decrypt library/aes.o
Yanray Wang85b74652023-11-13 16:48:36 +08005108 # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
Yanray Wang4cd1b162023-11-10 12:18:29 +08005109 not grep mbedtls_aesce_inverse_key library/aesce.o
5110 not grep aesce_decrypt_block library/aesce.o
Yanray Wangbf66ef92023-08-31 14:47:01 +08005111}
5112
Gilles Peskine592f5912019-10-07 18:49:32 +02005113component_test_ctr_drbg_aes_256_sha_256 () {
5114 msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
5115 scripts/config.py full
5116 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
5117 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Dave Rodgman17127e92023-12-14 16:42:48 +00005118 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine592f5912019-10-07 18:49:32 +02005119 make
5120
5121 msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
5122 make test
5123}
5124
5125component_test_ctr_drbg_aes_128_sha_512 () {
5126 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01005127 scripts/config.py full
5128 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
5129 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
Dave Rodgman17127e92023-12-14 16:42:48 +00005130 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine592f5912019-10-07 18:49:32 +02005131 make
5132
5133 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
5134 make test
5135}
5136
5137component_test_ctr_drbg_aes_128_sha_256 () {
5138 msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
Gilles Peskine3b46cd32020-02-18 17:56:33 +01005139 scripts/config.py full
5140 scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
5141 scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
5142 scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
Dave Rodgman17127e92023-12-14 16:42:48 +00005143 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Gilles Peskine592f5912019-10-07 18:49:32 +02005144 make
5145
5146 msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
5147 make test
5148}
5149
Gilles Peskinef96aefe2019-07-24 14:58:38 +02005150component_test_se_default () {
5151 msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02005152 scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
Gilles Peskine004206c2019-10-21 17:11:33 +02005153 make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
Gilles Peskinef96aefe2019-07-24 14:58:38 +02005154
5155 msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
5156 make test
5157}
5158
Steven Cooremand57203d2020-07-16 20:28:59 +02005159component_test_psa_crypto_drivers () {
Gilles Peskine1997f302023-07-26 18:45:20 +02005160 msg "build: full + test drivers dispatching to builtins"
Steven Cooreman753f9732021-03-15 11:38:44 +01005161 scripts/config.py full
Gilles Peskine1997f302023-07-26 18:45:20 +02005162 scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
Gilles Peskine3587dfd2021-09-20 19:20:04 +02005163 loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
5164 loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
Ronald Cron17b3afc2020-12-10 18:17:09 +01005165 loc_cflags="${loc_cflags} -I../tests/include -O2"
5166
Gilles Peskine21570cf2023-12-22 11:49:50 +01005167 make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
Steven Cooremand57203d2020-07-16 20:28:59 +02005168
Gilles Peskine1997f302023-07-26 18:45:20 +02005169 msg "test: full + test drivers dispatching to builtins"
Steven Cooremand57203d2020-07-16 20:28:59 +02005170 make test
5171}
5172
Gilles Peskine8f073122018-11-27 15:58:47 +01005173component_test_make_shared () {
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00005174 msg "build/test: make shared" # ~ 40s
Andrzej Kurek232e8f92019-10-03 03:18:01 -04005175 make SHARED=1 all check
Gilles Peskine56c01612019-07-03 20:43:32 +02005176 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskineca144592021-11-04 12:52:14 +01005177 programs/test/dlopen_demo.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01005178}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00005179
Gilles Peskinecf740502019-07-03 20:43:05 +02005180component_test_cmake_shared () {
5181 msg "build/test: cmake shared" # ~ 2min
5182 cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
5183 make
Gilles Peskine56c01612019-07-03 20:43:32 +02005184 ldd programs/util/strerror | grep libmbedcrypto
Gilles Peskinecf740502019-07-03 20:43:05 +02005185 make test
Gilles Peskineca144592021-11-04 12:52:14 +01005186 programs/test/dlopen_demo.sh
Gilles Peskinecf740502019-07-03 20:43:05 +02005187}
5188
Gilles Peskineec10bf12019-09-20 19:56:06 +02005189test_build_opt () {
5190 info=$1 cc=$2; shift 2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01005191 $cc --version
Gilles Peskineec10bf12019-09-20 19:56:06 +02005192 for opt in "$@"; do
5193 msg "build/test: $cc $opt, $info" # ~ 30s
Gilles Peskine21570cf2023-12-22 11:49:50 +01005194 make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
Gilles Peskineec10bf12019-09-20 19:56:06 +02005195 # We're confident enough in compilers to not run _all_ the tests,
5196 # but at least run the unit tests. In particular, runs with
5197 # optimizations use inline assembly whereas runs with -O0
5198 # skip inline assembly.
5199 make test # ~30s
5200 make clean
5201 done
5202}
5203
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01005204# For FreeBSD we invoke the function by name so this condition is added
5205# to disable the existing test_clang_opt function for linux.
5206if [[ $(uname) != "Linux" ]]; then
5207 component_test_clang_opt () {
5208 scripts/config.py full
5209 test_build_opt 'full config' clang -O0 -Os -O2
5210 }
5211fi
5212
5213component_test_clang_latest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01005214 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01005215 test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01005216}
5217support_test_clang_latest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01005218 type "$CLANG_LATEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02005219}
5220
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01005221component_test_clang_earliest_opt () {
Manuel Pégourié-Gonnard68192fc2020-03-04 10:34:47 +01005222 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01005223 test_build_opt 'full config' "$CLANG_EARLIEST" -O0
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01005224}
5225support_test_clang_earliest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01005226 type "$CLANG_EARLIEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01005227}
5228
5229component_test_gcc_latest_opt () {
5230 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01005231 test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01005232}
5233support_test_gcc_latest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01005234 type "$GCC_LATEST" >/dev/null 2>/dev/null
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01005235}
5236
5237component_test_gcc_earliest_opt () {
5238 scripts/config.py full
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01005239 test_build_opt 'full config' "$GCC_EARLIEST" -O0
Gowtham Suresh Kumara12baf82023-07-19 08:39:20 +01005240}
5241support_test_gcc_earliest_opt () {
Gowtham Suresh Kumar6f1977b2023-07-28 17:04:47 +01005242 type "$GCC_EARLIEST" >/dev/null 2>/dev/null
Gilles Peskineec10bf12019-09-20 19:56:06 +02005243}
5244
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02005245component_build_mbedtls_config_file () {
5246 msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
Gilles Peskine2003c2f2022-04-07 20:55:57 +02005247 scripts/config.py -w full_config.h full
Gilles Peskineabf9b4d2019-07-03 20:42:16 +02005248 echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
Gilles Peskine21570cf2023-12-22 11:49:50 +01005249 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
Gilles Peskine45e680e2022-04-13 23:23:21 +02005250 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskinee10df772022-04-07 21:06:41 +02005251 programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5252 make clean
5253
5254 msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
5255 # In the user config, disable one feature (for simplicity, pick a feature
5256 # that nothing else depends on).
5257 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
Gilles Peskine21570cf2023-12-22 11:49:50 +01005258 make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
Gilles Peskinee10df772022-04-07 21:06:41 +02005259 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5260
5261 rm -f user_config.h full_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00005262}
5263
Gilles Peskine7d904e72022-04-07 21:59:14 +02005264component_build_psa_config_file () {
5265 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
5266 scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
5267 cp "$CRYPTO_CONFIG_H" psa_test_config.h
5268 echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
5269 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
Gilles Peskine45e680e2022-04-13 23:23:21 +02005270 # Make sure this feature is enabled. We'll disable it in the next phase.
Gilles Peskine7d904e72022-04-07 21:59:14 +02005271 programs/test/query_compile_time_config MBEDTLS_CMAC_C
5272 make clean
5273
5274 msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
5275 # In the user config, disable one feature, which will reflect on the
5276 # mbedtls configuration so we can query it with query_compile_time_config.
5277 echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
5278 scripts/config.py unset MBEDTLS_CMAC_C
5279 make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
5280 not programs/test/query_compile_time_config MBEDTLS_CMAC_C
5281
5282 rm -f psa_test_config.h psa_user_config.h
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00005283}
5284
Gilles Peskinedf6e84a2023-02-22 22:09:51 +01005285component_build_psa_alt_headers () {
5286 msg "build: make with PSA alt headers" # ~20s
5287
5288 # Generate alternative versions of the substitutable headers with the
5289 # same content except different include guards.
5290 make -C tests include/alt-extra/psa/crypto_platform_alt.h include/alt-extra/psa/crypto_struct_alt.h
5291
5292 # Build the library and some programs.
5293 # Don't build the fuzzers to avoid having to go through hoops to set
5294 # a correct include path for programs/fuzz/Makefile.
5295 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
5296 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\"'"
5297
5298 # Check that we're getting the alternative include guards and not the
5299 # original include guards.
5300 programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
5301 programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
5302 programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
5303 programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
5304}
5305
Dave Rodgman852de3c2023-12-14 14:46:45 +00005306component_test_m32_no_asm () {
5307 # Build without assembly, so as to use portable C code (in a 32-bit
Gilles Peskine77f05352021-10-07 19:27:16 +02005308 # build) and not the i386-specific inline assembly.
Dave Rodgmana2cf2402023-12-15 11:04:13 +00005309 #
5310 # Note that we require gcc, because clang Asan builds fail to link for
5311 # this target (cannot find libclang_rt.lsan-i386.a - this is a known clang issue).
Dave Rodgman852de3c2023-12-14 14:46:45 +00005312 msg "build: i386, make, gcc, no asm (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005313 scripts/config.py full
Dave Rodgman852de3c2023-12-14 14:46:45 +00005314 scripts/config.py unset MBEDTLS_HAVE_ASM
5315 scripts/config.py unset MBEDTLS_PADLOCK_C
Pengyu Lv13226132023-10-16 14:03:29 +08005316 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
Gilles Peskine21570cf2023-12-22 11:49:50 +01005317 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00005318
Dave Rodgman852de3c2023-12-14 14:46:45 +00005319 msg "test: i386, make, gcc, no asm (ASan build)"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01005320 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01005321}
Dave Rodgman852de3c2023-12-14 14:46:45 +00005322support_test_m32_no_asm () {
Gilles Peskine878cf602019-01-06 20:50:38 +00005323 case $(uname -m) in
Pengyu Lvc92df3b2022-10-21 10:50:26 +00005324 amd64|x86_64) true;;
Gilles Peskine878cf602019-01-06 20:50:38 +00005325 *) false;;
5326 esac
5327}
Simon Butcher8e6a22a2018-07-20 21:27:33 +01005328
Gilles Peskineff0aee02021-10-05 09:36:03 +02005329component_test_m32_o2 () {
5330 # Build with optimization, to use the i386 specific inline assembly
5331 # and go faster for tests.
5332 msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005333 scripts/config.py full
Pengyu Lv13226132023-10-16 14:03:29 +08005334 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
Gilles Peskine21570cf2023-12-22 11:49:50 +01005335 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
Simon Butcher8e6a22a2018-07-20 21:27:33 +01005336
Gilles Peskineff0aee02021-10-05 09:36:03 +02005337 msg "test: i386, make, gcc -O2 (ASan build)"
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00005338 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01005339
Gilles Peskineff0aee02021-10-05 09:36:03 +02005340 msg "test ssl-opt.sh, i386, make, gcc-O2"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005341 tests/ssl-opt.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01005342}
Gilles Peskinecf522222021-10-07 19:25:29 +02005343support_test_m32_o2 () {
Dave Rodgman852de3c2023-12-14 14:46:45 +00005344 support_test_m32_no_asm "$@"
Gilles Peskine878cf602019-01-06 20:50:38 +00005345}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00005346
Gilles Peskine0c6b7992019-04-12 20:29:48 +02005347component_test_m32_everest () {
5348 msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005349 scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
Pengyu Lv13226132023-10-16 14:03:29 +08005350 scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
Dave Rodgmanb90f87b2023-12-14 23:27:33 +00005351 make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02005352
5353 msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
5354 make test
Gilles Peskine636c26a2020-03-04 20:46:15 +01005355
5356 msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005357 tests/ssl-opt.sh -f ECDH
Gilles Peskine636c26a2020-03-04 20:46:15 +01005358
5359 msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
5360 # Exclude some symmetric ciphers that are redundant here to gain time.
Manuel Pégourié-Gonnard296787f2022-04-06 13:28:27 +02005361 tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
Gilles Peskine0c6b7992019-04-12 20:29:48 +02005362}
5363support_test_m32_everest () {
Dave Rodgman852de3c2023-12-14 14:46:45 +00005364 support_test_m32_no_asm "$@"
Gilles Peskine0c6b7992019-04-12 20:29:48 +02005365}
5366
Gilles Peskine8f073122018-11-27 15:58:47 +01005367component_test_mx32 () {
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00005368 msg "build: 64-bit ILP32, make, gcc" # ~ 30s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005369 scripts/config.py full
Dave Rodgman84125a12024-01-02 11:42:38 +00005370 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00005371
5372 msg "test: 64-bit ILP32, make, gcc"
5373 make test
Gilles Peskine8f073122018-11-27 15:58:47 +01005374}
Gilles Peskine878cf602019-01-06 20:50:38 +00005375support_test_mx32 () {
5376 case $(uname -m) in
5377 amd64|x86_64) true;;
5378 *) false;;
5379 esac
5380}
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01005381
Peter Kolbus60c6da22018-12-27 06:59:04 -06005382component_test_min_mpi_window_size () {
5383 msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02005384 scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
Dave Rodgman17127e92023-12-14 16:42:48 +00005385 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Peter Kolbus60c6da22018-12-27 06:59:04 -06005386 make
5387
5388 msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
5389 make test
5390}
5391
Gilles Peskine8f073122018-11-27 15:58:47 +01005392component_test_have_int32 () {
5393 msg "build: gcc, force 32-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02005394 scripts/config.py unset MBEDTLS_HAVE_ASM
5395 scripts/config.py unset MBEDTLS_AESNI_C
5396 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08005397 scripts/config.py unset MBEDTLS_AESCE_C
Dave Rodgmand8d64512023-12-19 12:20:21 +00005398 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
Andres Amaya Garcia84e6ce82017-05-04 11:35:51 +01005399
Gilles Peskine8f073122018-11-27 15:58:47 +01005400 msg "test: gcc, force 32-bit bignum limbs"
5401 make test
5402}
Andres Amaya Garciafe843a32017-07-20 13:21:34 +01005403
Gilles Peskine8f073122018-11-27 15:58:47 +01005404component_test_have_int64 () {
5405 msg "build: gcc, force 64-bit bignum limbs"
Gilles Peskine3bdd4122019-07-27 23:52:53 +02005406 scripts/config.py unset MBEDTLS_HAVE_ASM
5407 scripts/config.py unset MBEDTLS_AESNI_C
5408 scripts/config.py unset MBEDTLS_PADLOCK_C
Jerry Yue51eddc2023-01-11 14:16:08 +08005409 scripts/config.py unset MBEDTLS_AESCE_C
Dave Rodgmand8d64512023-12-19 12:20:21 +00005410 make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
Gilles Peskine14c3c062018-01-29 21:25:12 +01005411
Gilles Peskine8f073122018-11-27 15:58:47 +01005412 msg "test: gcc, force 64-bit bignum limbs"
5413 make test
5414}
Manuel Pégourié-Gonnardedb2dc92015-02-10 14:36:31 +00005415
Gabor Mezeie256cc12023-07-26 17:28:48 +02005416component_test_have_int32_cmake_new_bignum () {
5417 msg "build: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
5418 scripts/config.py unset MBEDTLS_HAVE_ASM
5419 scripts/config.py unset MBEDTLS_AESNI_C
5420 scripts/config.py unset MBEDTLS_PADLOCK_C
5421 scripts/config.py unset MBEDTLS_AESCE_C
5422 scripts/config.py set MBEDTLS_TEST_HOOKS
Janos Follath2f045822023-07-31 10:57:16 +01005423 scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
Janos Follathf3135af2023-07-31 10:07:57 +01005424 make CC=gcc CFLAGS="$ASAN_CFLAGS -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32" LDFLAGS="$ASAN_CFLAGS"
Gabor Mezeie256cc12023-07-26 17:28:48 +02005425
5426 msg "test: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
5427 make test
5428}
5429
Gilles Peskine8f073122018-11-27 15:58:47 +01005430component_test_no_udbl_division () {
5431 msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02005432 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02005433 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskine21570cf2023-12-22 11:49:50 +01005434 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02005435
Gilles Peskine8f073122018-11-27 15:58:47 +01005436 msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
5437 make test
5438}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02005439
Gilles Peskine8f073122018-11-27 15:58:47 +01005440component_test_no_64bit_multiplication () {
5441 msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
Gilles Peskine3bdd4122019-07-27 23:52:53 +02005442 scripts/config.py full
Gilles Peskine3bdd4122019-07-27 23:52:53 +02005443 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskine21570cf2023-12-22 11:49:50 +01005444 make CFLAGS='-Werror -O1'
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02005445
Gilles Peskine8f073122018-11-27 15:58:47 +01005446 msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
5447 make test
5448}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02005449
Gilles Peskine3809f5f2020-11-09 15:40:05 +01005450component_test_no_strings () {
5451 msg "build: no strings" # ~10s
5452 scripts/config.py full
5453 # Disable options that activate a large amount of string constants.
5454 scripts/config.py unset MBEDTLS_DEBUG_C
5455 scripts/config.py unset MBEDTLS_ERROR_C
5456 scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
5457 scripts/config.py unset MBEDTLS_VERSION_FEATURES
Gilles Peskine21570cf2023-12-22 11:49:50 +01005458 make CFLAGS='-Werror -Os'
Gilles Peskine3809f5f2020-11-09 15:40:05 +01005459
5460 msg "test: no strings" # ~ 10s
5461 make test
5462}
5463
Hanno Beckerc5722d12020-10-09 11:10:42 +01005464component_test_no_x509_info () {
5465 msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
5466 scripts/config.pl full
5467 scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
5468 scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
Gilles Peskine21570cf2023-12-22 11:49:50 +01005469 make CFLAGS='-Werror -O2'
Hanno Beckerc5722d12020-10-09 11:10:42 +01005470
5471 msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
5472 make test
5473
5474 msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005475 tests/ssl-opt.sh
Hanno Beckerc5722d12020-10-09 11:10:42 +01005476}
5477
Gilles Peskine8f073122018-11-27 15:58:47 +01005478component_build_arm_none_eabi_gcc () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02005479 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005480 scripts/config.py baremetal
Gilles Peskineaeedd742020-09-02 11:03:04 +02005481 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 +02005482
Gilles Peskinee36fe812021-09-01 20:00:33 +02005483 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02005484 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01005485}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02005486
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02005487component_build_arm_linux_gnueabi_gcc_arm5vte () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02005488 msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005489 scripts/config.py baremetal
Gilles Peskine2c897d72019-08-09 16:05:05 +02005490 # Build for a target platform that's close to what Debian uses
5491 # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
Dave Rodgman017a1992022-03-31 14:07:01 +01005492 # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02005493 # Build everything including programs, see for example
Dave Rodgman017a1992022-03-31 14:07:01 +01005494 # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02005495 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'
5496
Gilles Peskinee36fe812021-09-01 20:00:33 +02005497 msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02005498 ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t library/*.o
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02005499}
5500support_build_arm_linux_gnueabi_gcc_arm5vte () {
5501 type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
5502}
5503
5504component_build_arm_none_eabi_gcc_arm5vte () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02005505 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
Manuel Pégourié-Gonnard3a6c7692020-08-18 10:28:51 +02005506 scripts/config.py baremetal
5507 # This is an imperfect substitute for
5508 # component_build_arm_linux_gnueabi_gcc_arm5vte
Manuel Pégourié-Gonnardae505ee2021-07-06 09:44:59 +02005509 # in case the gcc-arm-linux-gnueabi toolchain is not available
Gilles Peskineaeedd742020-09-02 11:03:04 +02005510 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 +02005511
Gilles Peskinee36fe812021-09-01 20:00:33 +02005512 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02005513 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Gilles Peskine93e4e032019-08-05 11:34:25 +02005514}
5515
Gilles Peskine6e2fb862020-04-30 23:00:53 +02005516component_build_arm_none_eabi_gcc_m0plus () {
Gilles Peskinee36fe812021-09-01 20:00:33 +02005517 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
5518 scripts/config.py baremetal_size
Gilles Peskineaeedd742020-09-02 11:03:04 +02005519 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 +02005520
Gilles Peskinee36fe812021-09-01 20:00:33 +02005521 msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
Manuel Pégourié-Gonnarda14b8f02023-03-28 12:49:39 +02005522 ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
Manuel Pégourié-Gonnard67f80372023-06-06 13:01:18 +02005523 for lib in library/*.a; do
5524 echo "$lib:"
5525 ${ARM_NONE_EABI_GCC_PREFIX}size -t $lib | grep TOTALS
5526 done
Gilles Peskine6e2fb862020-04-30 23:00:53 +02005527}
5528
Gilles Peskine8f073122018-11-27 15:58:47 +01005529component_build_arm_none_eabi_gcc_no_udbl_division () {
Gilles Peskine6d061342020-04-30 18:19:32 +02005530 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005531 scripts/config.py baremetal
5532 scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
Gilles Peskineaeedd742020-09-02 11:03:04 +02005533 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 +01005534 echo "Checking that software 64-bit division is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005535 not grep __aeabi_uldiv library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01005536}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02005537
Gilles Peskine8f073122018-11-27 15:58:47 +01005538component_build_arm_none_eabi_gcc_no_64bit_multiplication () {
Gilles Peskine6d061342020-04-30 18:19:32 +02005539 msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005540 scripts/config.py baremetal
5541 scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
Gilles Peskineaeedd742020-09-02 11:03:04 +02005542 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 +01005543 echo "Checking that software 64-bit multiplication is not required"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005544 not grep __aeabi_lmul library/*.o
Gilles Peskine8f073122018-11-27 15:58:47 +01005545}
Manuel Pégourié-Gonnard2adb3752018-06-07 10:51:44 +02005546
Dave Rodgman8c315f22023-06-02 10:26:24 -04005547component_build_arm_clang_thumb () {
5548 # ~ 30s
5549
5550 scripts/config.py baremetal
5551
5552 msg "build: clang thumb 2, make"
5553 make clean
5554 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
5555
5556 # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
5557 msg "build: clang thumb 1 -O0, make"
5558 make clean
5559 make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
5560
5561 msg "build: clang thumb 1 -Os, make"
5562 make clean
5563 make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
5564}
5565
Gilles Peskine8f073122018-11-27 15:58:47 +01005566component_build_armcc () {
Gilles Peskine18487f62020-04-30 23:11:54 +02005567 msg "build: ARM Compiler 5"
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005568 scripts/config.py baremetal
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00005569 # armc[56] don't support SHA-512 intrinsics
5570 scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
Dave Rodgman2f386c52023-03-02 13:38:33 +00005571
Dave Rodgman4b8e8dc2023-10-08 21:41:40 +01005572 # older versions of armcc/armclang don't support AESCE_C on 32-bit Arm
5573 scripts/config.py unset MBEDTLS_AESCE_C
5574
Dave Rodgman0fddf822023-03-02 15:32:12 +00005575 # Stop armclang warning about feature detection for A64_CRYPTO.
5576 # With this enabled, the library does build correctly under armclang,
5577 # but in baremetal builds (as tested here), feature detection is
5578 # unavailable, and the user is notified via a #warning. So enabling
5579 # this feature would prevent us from building with -Werror on
5580 # armclang. Tracked in #7198.
Dave Rodgman5b89c552023-10-10 14:59:02 +01005581 scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
Dave Rodgman2f386c52023-03-02 13:38:33 +00005582
Hanno Beckerf0762e92022-07-15 12:08:19 +01005583 scripts/config.py set MBEDTLS_HAVE_ASM
Tom Cosgrove87fbfb52022-03-15 10:51:52 +00005584
Gilles Peskinebca6ab92017-12-19 18:24:31 +01005585 make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
Gilles Peskine18487f62020-04-30 23:11:54 +02005586
5587 msg "size: ARM Compiler 5"
5588 "$ARMC5_FROMELF" -z library/*.o
5589
Dave Rodgmanb45d58b2023-06-02 13:54:00 -04005590 # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
Hanno Beckerf0762e92022-07-15 12:08:19 +01005591
Gilles Peskinebca6ab92017-12-19 18:24:31 +01005592 # ARM Compiler 6 - Target ARMv7-A
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01005593 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-a"
Simon Butcher940737f2017-07-23 13:42:36 +02005594
Gilles Peskinebca6ab92017-12-19 18:24:31 +01005595 # ARM Compiler 6 - Target ARMv7-M
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01005596 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m"
5597
5598 # ARM Compiler 6 - Target ARMv7-M+DSP
5599 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m+dsp"
Simon Butcher940737f2017-07-23 13:42:36 +02005600
Gilles Peskinebca6ab92017-12-19 18:24:31 +01005601 # ARM Compiler 6 - Target ARMv8-A - AArch32
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01005602 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8.2-a"
Simon Butcher940737f2017-07-23 13:42:36 +02005603
Gilles Peskinebca6ab92017-12-19 18:24:31 +01005604 # ARM Compiler 6 - Target ARMv8-M
Dave Rodgman03f7a6e2022-08-17 14:35:29 +01005605 armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
Simon Butcher940737f2017-07-23 13:42:36 +02005606
Dave Rodgmanb45d58b2023-06-02 13:54:00 -04005607 # ARM Compiler 6 - Target Cortex-M0 - no optimisation
5608 armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
5609
Dave Rodgman99318e62023-05-24 12:27:42 +01005610 # ARM Compiler 6 - Target Cortex-M0
5611 armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
Dave Rodgman4b8e8dc2023-10-08 21:41:40 +01005612
5613 # ARM Compiler 6 - Target ARMv8.2-A - AArch64
5614 #
5615 # Re-enable MBEDTLS_AESCE_C as this should be supported by the version of armclang
5616 # that we have in our CI
5617 scripts/config.py set MBEDTLS_AESCE_C
5618 armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
Gilles Peskine8f073122018-11-27 15:58:47 +01005619}
Tom Cosgrove6ec39ca2023-06-09 15:34:31 +01005620
Pengyu Lvdf070032023-02-24 16:03:31 +08005621support_build_armcc () {
Pengyu Lvc6298ad2023-03-01 10:31:29 +08005622 armc5_cc="$ARMC5_BIN_DIR/armcc"
5623 armc6_cc="$ARMC6_BIN_DIR/armclang"
5624 (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
Pengyu Lvdf070032023-02-24 16:03:31 +08005625}
Manuel Pégourié-Gonnardc5c59392015-02-10 17:38:54 +01005626
Ronald Crond2cb7f42024-03-18 12:49:18 +01005627component_test_tls12_only () {
5628 msg "build: default config without MBEDTLS_SSL_PROTO_TLS1_3, cmake, gcc, ASan"
5629 scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
5630 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
5631 make
5632
5633 msg "test: main suites (inc. selftests) (ASan build)"
5634 make test
5635
5636 msg "test: ssl-opt.sh (ASan build)"
5637 tests/ssl-opt.sh
5638
5639 msg "test: compat.sh (ASan build)"
5640 tests/compat.sh
5641}
5642
Jerry Yu81d5e1f2022-01-27 13:01:01 +08005643component_test_tls13_only () {
Ronald Cron46ac0652024-03-18 12:39:04 +01005644 msg "build: default config without MBEDTLS_SSL_PROTO_TLS1_2"
Ronald Cronc2e110f2022-11-22 09:01:46 +01005645 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Waleed Elmelegye8402632024-01-09 17:21:20 +00005646 scripts/config.py set MBEDTLS_SSL_RECORD_SIZE_LIMIT
Jerry Yuda5af222021-12-24 18:45:45 +08005647 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5648
Gilles Peskine4bb369c2022-10-29 17:44:19 +02005649 msg "test: TLS 1.3 only, all key exchange modes enabled"
5650 make test
Jerry Yubaa49342022-02-15 10:26:40 +08005651
Ronald Cronc3f43b62022-10-17 17:35:32 +02005652 msg "ssl-opt.sh: TLS 1.3 only, all key exchange modes enabled"
5653 tests/ssl-opt.sh
Jerry Yuda5af222021-12-24 18:45:45 +08005654}
5655
Ronald Cronc3f43b62022-10-17 17:35:32 +02005656component_test_tls13_only_psk () {
5657 msg "build: TLS 1.3 only from default, only PSK key exchange mode"
5658 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5659 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
5660 scripts/config.py unset MBEDTLS_ECDH_C
Przemek Stekiel0c231472023-06-14 11:12:45 +02005661 scripts/config.py unset MBEDTLS_DHM_C
Ronald Cronc3f43b62022-10-17 17:35:32 +02005662 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5663 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5664 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5665 scripts/config.py unset MBEDTLS_ECDSA_C
5666 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00005667 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01005668 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Crone3dac4a2022-06-10 17:21:51 +02005669 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5670
Ronald Cronc3f43b62022-10-17 17:35:32 +02005671 msg "test_suite_ssl: TLS 1.3 only, only PSK key exchange mode enabled"
5672 cd tests; ./test_suite_ssl; cd ..
Ronald Crone3dac4a2022-06-10 17:21:51 +02005673
Ronald Cronc3f43b62022-10-17 17:35:32 +02005674 msg "ssl-opt.sh: TLS 1.3 only, only PSK key exchange mode enabled"
5675 tests/ssl-opt.sh
5676}
5677
5678component_test_tls13_only_ephemeral () {
5679 msg "build: TLS 1.3 only from default, only ephemeral key exchange mode"
5680 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5681 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
Xiaokang Qian2dbfeda2022-11-15 10:52:57 +00005682 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005683 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5684
5685 msg "test_suite_ssl: TLS 1.3 only, only ephemeral key exchange mode"
5686 cd tests; ./test_suite_ssl; cd ..
5687
5688 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral key exchange mode"
5689 tests/ssl-opt.sh
5690}
5691
Przemek Stekiela01c2422023-06-13 10:46:48 +02005692component_test_tls13_only_ephemeral_ffdh () {
5693 msg "build: TLS 1.3 only from default, only ephemeral ffdh key exchange mode"
5694 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5695 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
5696 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
Przemek Stekielce05f542023-06-15 16:44:08 +02005697 scripts/config.py unset MBEDTLS_ECDH_C
5698
Przemek Stekiela01c2422023-06-13 10:46:48 +02005699 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5700
5701 msg "test_suite_ssl: TLS 1.3 only, only ephemeral ffdh key exchange mode"
5702 cd tests; ./test_suite_ssl; cd ..
5703
5704 msg "ssl-opt.sh: TLS 1.3 only, only ephemeral ffdh key exchange mode"
5705 tests/ssl-opt.sh
5706}
5707
Ronald Cronc3f43b62022-10-17 17:35:32 +02005708component_test_tls13_only_psk_ephemeral () {
5709 msg "build: TLS 1.3 only from default, only PSK ephemeral key exchange mode"
5710 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5711 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5712 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5713 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5714 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5715 scripts/config.py unset MBEDTLS_ECDSA_C
5716 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00005717 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01005718 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005719 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5720
5721 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral key exchange mode"
5722 cd tests; ./test_suite_ssl; cd ..
5723
5724 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral key exchange mode"
5725 tests/ssl-opt.sh
5726}
5727
Przemek Stekiela01c2422023-06-13 10:46:48 +02005728component_test_tls13_only_psk_ephemeral_ffdh () {
5729 msg "build: TLS 1.3 only from default, only PSK ephemeral ffdh key exchange mode"
5730 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5731 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5732 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5733 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5734 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5735 scripts/config.py unset MBEDTLS_ECDSA_C
5736 scripts/config.py unset MBEDTLS_PKCS1_V21
5737 scripts/config.py unset MBEDTLS_PKCS7_C
5738 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Przemek Stekielce05f542023-06-15 16:44:08 +02005739 scripts/config.py unset MBEDTLS_ECDH_C
Przemek Stekiela01c2422023-06-13 10:46:48 +02005740 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5741
5742 msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
5743 cd tests; ./test_suite_ssl; cd ..
5744
5745 msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
5746 tests/ssl-opt.sh
5747}
5748
Ronald Cronc3f43b62022-10-17 17:35:32 +02005749component_test_tls13_only_psk_all () {
5750 msg "build: TLS 1.3 only from default, without ephemeral key exchange mode"
5751 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5752 scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5753 scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5754 scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5755 scripts/config.py unset MBEDTLS_ECDSA_C
5756 scripts/config.py unset MBEDTLS_PKCS1_V21
Dave Rodgman71565cf2022-11-11 10:37:38 +00005757 scripts/config.py unset MBEDTLS_PKCS7_C
Ronald Cronc2e110f2022-11-22 09:01:46 +01005758 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005759 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5760
5761 msg "test_suite_ssl: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
5762 cd tests; ./test_suite_ssl; cd ..
5763
5764 msg "ssl-opt.sh: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
5765 tests/ssl-opt.sh
5766}
5767
5768component_test_tls13_only_ephemeral_all () {
5769 msg "build: TLS 1.3 only from default, without PSK key exchange mode"
5770 scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
Ronald Cronc2e110f2022-11-22 09:01:46 +01005771 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Ronald Cronc3f43b62022-10-17 17:35:32 +02005772 make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5773
5774 msg "test_suite_ssl: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
5775 cd tests; ./test_suite_ssl; cd ..
5776
5777 msg "ssl-opt.sh: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
5778 tests/ssl-opt.sh
Ronald Crone3dac4a2022-06-10 17:21:51 +02005779}
5780
Ronald Cron46ac0652024-03-18 12:39:04 +01005781component_test_tls13_no_padding () {
5782 msg "build: default config plus early data minus padding"
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005783 scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
Ronald Cronc2e110f2022-11-22 09:01:46 +01005784 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Dave Rodgman17127e92023-12-14 16:42:48 +00005785 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005786 make
Ronald Cron46ac0652024-03-18 12:39:04 +01005787 msg "test: default config plus early data minus padding"
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005788 make test
Ronald Cron46ac0652024-03-18 12:39:04 +01005789 msg "ssl-opt.sh (TLS 1.3 no padding)"
Gilles Peskine827dbd92022-02-04 00:30:54 +01005790 tests/ssl-opt.sh
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005791}
5792
Ronald Cron6f135e12021-12-08 16:57:54 +01005793component_test_tls13_no_compatibility_mode () {
Ronald Cron46ac0652024-03-18 12:39:04 +01005794 msg "build: default config plus early data minus middlebox compatibility mode"
Ronald Cronfdb0e3f2021-12-09 10:39:19 +01005795 scripts/config.py unset MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
Ronald Cronc2e110f2022-11-22 09:01:46 +01005796 scripts/config.py set MBEDTLS_SSL_EARLY_DATA
Dave Rodgman17127e92023-12-14 16:42:48 +00005797 CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
Hanno Beckera711f6e2020-05-04 12:03:51 +01005798 make
Ronald Cron46ac0652024-03-18 12:39:04 +01005799 msg "test: default config plus early data minus middlebox compatibility mode"
Hanno Becker6c53ecc2021-08-01 19:20:10 +01005800 make test
Ronald Cron6f135e12021-12-08 16:57:54 +01005801 msg "ssl-opt.sh (TLS 1.3 no compatibility mode)"
Gilles Peskine827dbd92022-02-04 00:30:54 +01005802 tests/ssl-opt.sh
Hanno Becker6c53ecc2021-08-01 19:20:10 +01005803}
5804
Ronald Crondd96c0a2024-04-02 12:34:24 +02005805component_test_full_minus_session_tickets() {
5806 msg "build: full config without session tickets"
5807 scripts/config.py full
Norbert Fabritiusd30e9112023-04-11 15:40:05 +02005808 scripts/config.py unset MBEDTLS_SSL_SESSION_TICKETS
Ronald Crondd96c0a2024-04-02 12:34:24 +02005809 scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
Norbert Fabritiusd30e9112023-04-11 15:40:05 +02005810 CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
5811 make
Ronald Crondd96c0a2024-04-02 12:34:24 +02005812 msg "test: full config without session tickets"
Norbert Fabritiusd30e9112023-04-11 15:40:05 +02005813 make test
Ronald Crondd96c0a2024-04-02 12:34:24 +02005814 msg "ssl-opt.sh (full config without session tickets)"
Norbert Fabritiusd30e9112023-04-11 15:40:05 +02005815 tests/ssl-opt.sh
5816}
5817
Gilles Peskine8f073122018-11-27 15:58:47 +01005818component_build_mingw () {
5819 msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
Pengyu Lv64cca2f2023-10-10 18:22:24 +08005820 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 lib programs
Hanno Beckere963efa2018-01-03 10:03:43 +00005821
Gilles Peskine8f073122018-11-27 15:58:47 +01005822 # note Make tests only builds the tests, but doesn't run them
Pengyu Lv64cca2f2023-10-10 18:22:24 +08005823 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -maes -msse2 -mpclmul' WINDOWS_BUILD=1 tests
Gilles Peskine8f073122018-11-27 15:58:47 +01005824 make WINDOWS_BUILD=1 clean
Gilles Peskine2a458da2017-05-12 15:26:58 +02005825
Gilles Peskine8f073122018-11-27 15:58:47 +01005826 msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
Pengyu Lv64cca2f2023-10-10 18:22:24 +08005827 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 SHARED=1 lib programs
5828 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 SHARED=1 tests
Gilles Peskine8f073122018-11-27 15:58:47 +01005829 make WINDOWS_BUILD=1 clean
Pengyu Lvbb4f63c2023-10-19 10:38:58 +08005830
Pengyu Lv158eead2023-10-19 11:27:05 +08005831 msg "build: Windows cross build - mingw64, make (Library only, default config without MBEDTLS_AESNI_C)" # ~ 30s
Pengyu Lvbb4f63c2023-10-19 10:38:58 +08005832 ./scripts/config.py unset MBEDTLS_AESNI_C #
Pengyu Lv158eead2023-10-19 11:27:05 +08005833 make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib
Gilles Peskine8f073122018-11-27 15:58:47 +01005834 make WINDOWS_BUILD=1 clean
5835}
Jaeden Amero117b8a42019-04-17 15:19:26 +01005836support_build_mingw() {
Pengyu Lv51b5f002023-02-24 15:38:52 +08005837 case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
5838 [0-5]*|"") false;;
Jaeden Amero117b8a42019-04-17 15:19:26 +01005839 *) true;;
5840 esac
5841}
Simon Butcher91aef332016-11-17 09:20:50 +00005842
Gilles Peskine8f073122018-11-27 15:58:47 +01005843component_test_memsan () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005844 msg "build: MSan (clang)" # ~ 1 min 20s
Gilles Peskine5d46f6a2019-07-27 23:52:53 +02005845 scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005846 CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
5847 make
Manuel Pégourié-Gonnard4a9dc2a2014-05-09 13:46:59 +02005848
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005849 msg "test: main suites (MSan)" # ~ 10s
5850 make test
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005851
Gilles Peskine6848d172023-11-02 19:58:03 +01005852 msg "test: metatests (MSan)"
5853 tests/scripts/run-metatests.sh any msan
5854
Gilles Peskine82b27272019-06-14 18:27:03 +02005855 msg "program demos (MSan)" # ~20s
5856 tests/scripts/run_demos.py
5857
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005858 msg "test: ssl-opt.sh (MSan)" # ~ 1 min
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005859 tests/ssl-opt.sh
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005860
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005861 # Optional part(s)
Manuel Pégourié-Gonnard9bda9b32014-11-20 13:10:22 +01005862
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005863 if [ "$MEMORY" -gt 0 ]; then
5864 msg "test: compat.sh (MSan)" # ~ 6 min 20s
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005865 tests/compat.sh
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005866 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01005867}
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01005868
Bence Szépkúti0354d042023-12-06 16:14:37 +01005869component_release_test_valgrind () {
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005870 msg "build: Release (clang)"
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005871 # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005872 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
5873 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005874
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005875 msg "test: main suites, Valgrind (default config)"
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005876 make memcheck
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005877
Gilles Peskine636c26a2020-03-04 20:46:15 +01005878 # Optional parts (slow; currently broken on OS X because programs don't
5879 # seem to receive signals under valgrind on OS X).
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005880 # These optional parts don't run on the CI.
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005881 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005882 msg "test: ssl-opt.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005883 tests/ssl-opt.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005884 fi
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005885
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005886 if [ "$MEMORY" -gt 1 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005887 msg "test: compat.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005888 tests/compat.sh --memcheck
Gilles Peskine7ad603e2017-12-10 23:22:20 +01005889 fi
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02005890
5891 if [ "$MEMORY" -gt 0 ]; then
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005892 msg "test: context-info.sh --memcheck (default config)"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005893 tests/context-info.sh --memcheck
Piotr Nowicki9978e6e2020-04-07 16:07:05 +02005894 fi
Gilles Peskine8f073122018-11-27 15:58:47 +01005895}
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005896
Bence Szépkúti0354d042023-12-06 16:14:37 +01005897component_release_test_valgrind_psa () {
Gilles Peskinedf3dd4c2022-11-29 16:45:30 +01005898 msg "build: Release, full (clang)"
5899 # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
5900 scripts/config.py full
5901 CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
5902 make
5903
5904 msg "test: main suites, Valgrind (full config)"
5905 make memcheck
5906}
5907
Paul Elliott62dc3922021-11-25 17:29:40 +00005908support_test_cmake_out_of_source () {
5909 distrib_id=""
5910 distrib_ver=""
5911 distrib_ver_minor=""
5912 distrib_ver_major=""
5913
5914 # Attempt to parse lsb-release to find out distribution and version. If not
5915 # found this should fail safe (test is supported).
5916 if [[ -f /etc/lsb-release ]]; then
5917
5918 while read -r lsb_line; do
5919 case "$lsb_line" in
5920 "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
5921 "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
5922 esac
5923 done < /etc/lsb-release
5924
5925 distrib_ver_major="${distrib_ver%%.*}"
5926 distrib_ver="${distrib_ver#*.}"
5927 distrib_ver_minor="${distrib_ver%%.*}"
5928 fi
5929
5930 # Running the out of source CMake test on Ubuntu 16.04 using more than one
5931 # processor (as the CI does) can create a race condition whereby the build
5932 # fails to see a generated file, despite that file actually having been
5933 # generated. This problem appears to go away with 18.04 or newer, so make
5934 # the out of source tests unsupported on Ubuntu 16.04.
5935 [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
5936}
5937
Gilles Peskine8f073122018-11-27 15:58:47 +01005938component_test_cmake_out_of_source () {
David Horstmann862abe22023-09-28 10:42:10 +01005939 # Remove existing generated files so that we use the ones cmake
David Horstmann9f48fff2023-09-27 15:53:54 +01005940 # generates
5941 make neat
5942
Gilles Peskine8f073122018-11-27 15:58:47 +01005943 msg "build: cmake 'out-of-source' build"
Gilles Peskine8f073122018-11-27 15:58:47 +01005944 MBEDTLS_ROOT_DIR="$PWD"
5945 mkdir "$OUT_OF_SOURCE_DIR"
5946 cd "$OUT_OF_SOURCE_DIR"
David Horstmann9f48fff2023-09-27 15:53:54 +01005947 # Note: Explicitly generate files as these are turned off in releases
5948 cmake -D CMAKE_BUILD_TYPE:String=Check -D GEN_FILES=ON "$MBEDTLS_ROOT_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01005949 make
Manuel Pégourié-Gonnard392d3dd2015-01-26 14:03:56 +00005950
Gilles Peskine8f073122018-11-27 15:58:47 +01005951 msg "test: cmake 'out-of-source' build"
5952 make test
Gilles Peskinea841c2a2022-04-16 11:31:25 +02005953 # Check that ssl-opt.sh can find the test programs.
Gilles Peskine8f073122018-11-27 15:58:47 +01005954 # Also ensure that there are no error messages such as
5955 # "No such file or directory", which would indicate that some required
5956 # file is missing (ssl-opt.sh tolerates the absence of some files so
5957 # may exit with status 0 but emit errors).
Gilles Peskinea841c2a2022-04-16 11:31:25 +02005958 ./tests/ssl-opt.sh -f 'Default' >ssl-opt.out 2>ssl-opt.err
Gilles Peskine7393ec52022-04-15 22:43:38 +02005959 grep PASS ssl-opt.out
Gilles Peskinef7e956c2020-03-28 18:56:09 +01005960 cat ssl-opt.err >&2
5961 # If ssl-opt.err is non-empty, record an error and keep going.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005962 [ ! -s ssl-opt.err ]
Gilles Peskine7393ec52022-04-15 22:43:38 +02005963 rm ssl-opt.out ssl-opt.err
Gilles Peskine8f073122018-11-27 15:58:47 +01005964 cd "$MBEDTLS_ROOT_DIR"
5965 rm -rf "$OUT_OF_SOURCE_DIR"
Gilles Peskine8f073122018-11-27 15:58:47 +01005966}
Andres AGdc192212016-08-31 17:33:13 +01005967
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005968component_test_cmake_as_subdirectory () {
David Horstmann9f48fff2023-09-27 15:53:54 +01005969 # Remove existing generated files so that we use the ones CMake
5970 # generates
5971 make neat
5972
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005973 msg "build: cmake 'as-subdirectory' build"
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005974 cd programs/test/cmake_subproject
David Horstmann9f48fff2023-09-27 15:53:54 +01005975 # Note: Explicitly generate files as these are turned off in releases
5976 cmake -D GEN_FILES=ON .
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005977 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005978 ./cmake_subproject
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005979}
Gilles Peskinea3000992022-02-04 00:21:12 +01005980support_test_cmake_as_subdirectory () {
5981 support_test_cmake_out_of_source
Jaeden Ameroab83fdf2019-06-20 17:38:22 +01005982}
5983
Chris Kayd259e342021-03-25 16:03:25 +00005984component_test_cmake_as_package () {
David Horstmann6c979852023-09-28 10:40:22 +01005985 # Remove existing generated files so that we use the ones CMake
5986 # generates
5987 make neat
5988
Chris Kayd259e342021-03-25 16:03:25 +00005989 msg "build: cmake 'as-package' build"
Chris Kayd259e342021-03-25 16:03:25 +00005990 cd programs/test/cmake_package
5991 cmake .
5992 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02005993 ./cmake_package
Chris Kayd259e342021-03-25 16:03:25 +00005994}
Gilles Peskinea3000992022-02-04 00:21:12 +01005995support_test_cmake_as_package () {
5996 support_test_cmake_out_of_source
Chris Kayd259e342021-03-25 16:03:25 +00005997}
5998
5999component_test_cmake_as_package_install () {
David Horstmann6c979852023-09-28 10:40:22 +01006000 # Remove existing generated files so that we use the ones CMake
6001 # generates
6002 make neat
6003
Chris Kayd259e342021-03-25 16:03:25 +00006004 msg "build: cmake 'as-installed-package' build"
Chris Kayd259e342021-03-25 16:03:25 +00006005 cd programs/test/cmake_package_install
6006 cmake .
6007 make
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02006008 ./cmake_package_install
Chris Kayd259e342021-03-25 16:03:25 +00006009}
Gilles Peskinea3000992022-02-04 00:21:12 +01006010support_test_cmake_as_package_install () {
6011 support_test_cmake_out_of_source
Chris Kayd259e342021-03-25 16:03:25 +00006012}
6013
David Horstmann20550e32023-01-12 14:17:01 +00006014component_build_cmake_custom_config_file () {
David Horstmann969c1452023-01-31 10:34:44 +00006015 # Make a copy of config file to use for the in-tree test
6016 cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h
David Horstmann20550e32023-01-12 14:17:01 +00006017
6018 MBEDTLS_ROOT_DIR="$PWD"
6019 mkdir "$OUT_OF_SOURCE_DIR"
6020 cd "$OUT_OF_SOURCE_DIR"
6021
David Horstmann969c1452023-01-31 10:34:44 +00006022 # Build once to get the generated files (which need an intact config file)
David Horstmann20550e32023-01-12 14:17:01 +00006023 cmake "$MBEDTLS_ROOT_DIR"
6024 make
6025
6026 msg "build: cmake with -DMBEDTLS_CONFIG_FILE"
6027 scripts/config.py -w full_config.h full
David Horstmann969c1452023-01-31 10:34:44 +00006028 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00006029 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR"
6030 make
6031
6032 msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
6033 # In the user config, disable one feature (for simplicity, pick a feature
6034 # that nothing else depends on).
6035 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
6036
6037 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR"
6038 make
6039 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
6040
6041 rm -f user_config.h full_config.h
6042
6043 cd "$MBEDTLS_ROOT_DIR"
6044 rm -rf "$OUT_OF_SOURCE_DIR"
6045
6046 # Now repeat the test for an in-tree build:
6047
David Horstmann969c1452023-01-31 10:34:44 +00006048 # Restore config for the in-tree test
6049 mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00006050
David Horstmann969c1452023-01-31 10:34:44 +00006051 # Build once to get the generated files (which need an intact config)
David Horstmann20550e32023-01-12 14:17:01 +00006052 cmake .
6053 make
6054
6055 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE"
6056 scripts/config.py -w full_config.h full
David Horstmann969c1452023-01-31 10:34:44 +00006057 echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
David Horstmann20550e32023-01-12 14:17:01 +00006058 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h .
6059 make
6060
6061 msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
6062 # In the user config, disable one feature (for simplicity, pick a feature
6063 # that nothing else depends on).
6064 echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
6065
6066 cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h .
6067 make
6068 not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
6069
6070 rm -f user_config.h full_config.h
6071}
6072support_build_cmake_custom_config_file () {
6073 support_test_cmake_out_of_source
6074}
6075
6076
Tom Cosgrovedaddf112023-09-01 10:40:15 +01006077component_build_zeroize_checks () {
6078 msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
6079
6080 scripts/config.py full
6081
6082 # Only compile - we're looking for sizeof-pointer-memaccess warnings
Dave Rodgman84125a12024-01-02 11:42:38 +00006083 make 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 +01006084}
6085
6086
Gilles Peskine8f073122018-11-27 15:58:47 +01006087component_test_zeroize () {
6088 # Test that the function mbedtls_platform_zeroize() is not optimized away by
6089 # different combinations of compilers and optimization flags by using an
6090 # auxiliary GDB script. Unfortunately, GDB does not return error values to the
6091 # system in all cases that the script fails, so we must manually search the
6092 # output to check whether the pass string is present and no failure strings
6093 # were printed.
Andres AGdc192212016-08-31 17:33:13 +01006094
Gilles Peskine4976e822019-01-06 19:52:22 +00006095 # Don't try to disable ASLR. We don't care about ASLR here. We do care
6096 # about a spurious message if Gdb tries and fails, so suppress that.
6097 gdb_disable_aslr=
6098 if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
6099 gdb_disable_aslr='set disable-randomization off'
6100 fi
6101
Gilles Peskine8f073122018-11-27 15:58:47 +01006102 for optimization_flag in -O2 -O3 -Ofast -Os; do
Gilles Peskine55f7c942019-01-09 22:28:21 +01006103 for compiler in clang gcc; do
6104 msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
6105 make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02006106 gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
6107 grep "The buffer was correctly zeroized" test_zeroize.log
6108 not grep -i "error" test_zeroize.log
Gilles Peskine55f7c942019-01-09 22:28:21 +01006109 rm -f test_zeroize.log
6110 make clean
6111 done
Andres Amaya Garcia29673812017-10-25 10:35:51 +01006112 done
Gilles Peskine8f073122018-11-27 15:58:47 +01006113}
Gilles Peskine192c72f2017-12-21 15:59:21 +01006114
Bence Szépkúti80b31c52021-10-19 15:05:36 +02006115component_test_psa_compliance () {
Dave Rodgman932ce852023-12-18 19:55:40 +00006116 # The arch tests build with gcc, so require use of gcc here to link properly
Bence Szépkúti80b31c52021-10-19 15:05:36 +02006117 msg "build: make, default config (out-of-box), libmbedcrypto.a only"
Dave Rodgman932ce852023-12-18 19:55:40 +00006118 CC=gcc make -C library libmbedcrypto.a
Bence Szépkúti80b31c52021-10-19 15:05:36 +02006119
6120 msg "unit test: test_psa_compliance.py"
Dave Rodgmand0a594d2023-12-18 22:29:56 +00006121 CC=gcc ./tests/scripts/test_psa_compliance.py
Bence Szépkúti80b31c52021-10-19 15:05:36 +02006122}
6123
6124support_test_psa_compliance () {
Bence Szépkútief0d02e2021-11-03 11:36:09 +01006125 # psa-compliance-tests only supports CMake >= 3.10.0
Bence Szépkútica9236b2021-10-25 19:29:07 +02006126 ver="$(cmake --version)"
6127 ver="${ver#cmake version }"
6128 ver_major="${ver%%.*}"
6129
6130 ver="${ver#*.}"
6131 ver_minor="${ver%%.*}"
6132
6133 [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
Bence Szépkúti80b31c52021-10-19 15:05:36 +02006134}
6135
Gilles Peskinec848d222022-12-09 12:23:35 +01006136component_check_code_style () {
6137 msg "Check C code style"
6138 ./scripts/code_style.py
David Horstmann92b5ac12022-11-10 18:30:52 +00006139}
6140
Gilles Peskinec848d222022-12-09 12:23:35 +01006141support_check_code_style() {
David Horstmann92b5ac12022-11-10 18:30:52 +00006142 case $(uncrustify --version) in
6143 *0.75.1*) true;;
6144 *) false;;
6145 esac
6146}
6147
Gilles Peskine8f073122018-11-27 15:58:47 +01006148component_check_python_files () {
6149 msg "Lint: Python scripts"
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02006150 tests/scripts/check-python-files.sh
Gilles Peskine8f073122018-11-27 15:58:47 +01006151}
Gilles Peskine192c72f2017-12-21 15:59:21 +01006152
Joe Subbianid614c0b2021-07-29 11:18:29 +01006153component_check_test_helpers () {
6154 msg "unit test: generate_test_code.py"
Manuel Pégourié-Gonnarddfb114a2020-06-02 11:40:08 +02006155 # unittest writes out mundane stuff like number or tests run on stderr.
6156 # Our convention is to reserve stderr for actual errors, and write
6157 # harmless info on stdout so it can be suppress with --quiet.
Gilles Peskine1f0cdaf2021-07-08 18:41:16 +02006158 ./tests/scripts/test_generate_test_code.py 2>&1
Joe Subbianid614c0b2021-07-29 11:18:29 +01006159
Joe Subbiania25ffab2021-08-06 09:41:27 +01006160 msg "unit test: translate_ciphers.py"
6161 python3 -m unittest tests/scripts/translate_ciphers.py 2>&1
Gilles Peskine8f073122018-11-27 15:58:47 +01006162}
Gilles Peskine192c72f2017-12-21 15:59:21 +01006163
Jerry Yud767cc42023-03-31 15:03:55 +08006164
Gilles Peskine192c72f2017-12-21 15:59:21 +01006165################################################################
6166#### Termination
6167################################################################
6168
Gilles Peskine8f073122018-11-27 15:58:47 +01006169post_report () {
6170 msg "Done, cleaning up"
Gilles Peskinef83eb822020-03-30 20:11:39 +02006171 final_cleanup
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01006172
Gilles Peskine8f073122018-11-27 15:58:47 +01006173 final_report
6174}
6175
6176
6177
6178################################################################
6179#### Run all the things
6180################################################################
6181
Gilles Peskine5d996822020-03-28 21:09:21 +01006182# Function invoked by --error-test to test error reporting.
6183pseudo_component_error_test () {
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02006184 msg "Testing error reporting $error_test_i"
Gilles Peskine5d996822020-03-28 21:09:21 +01006185 if [ $KEEP_GOING -ne 0 ]; then
6186 echo "Expect three failing commands."
6187 fi
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02006188 # If the component doesn't run in a subshell, changing error_test_i to an
6189 # invalid integer will cause an error in the loop that runs this function.
6190 error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
Gilles Peskineec135542021-08-02 23:14:03 +02006191 # Expected error: 'grep non_existent /dev/null -> 1'
Gilles Peskine5d996822020-03-28 21:09:21 +01006192 grep non_existent /dev/null
Gilles Peskineec135542021-08-02 23:14:03 +02006193 # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
Gilles Peskine5d996822020-03-28 21:09:21 +01006194 not grep -q . "$0"
Gilles Peskineec135542021-08-02 23:14:03 +02006195 # Expected error: 'make unknown_target -> 2'
Gilles Peskine5d996822020-03-28 21:09:21 +01006196 make unknown_target
6197 false "this should not be executed"
6198}
6199
Gilles Peskinee48351a2018-11-27 16:06:30 +01006200# Run one component and clean up afterwards.
Gilles Peskine8f073122018-11-27 15:58:47 +01006201run_component () {
Gilles Peskineffcdeff2018-12-04 12:49:28 +01006202 current_component="$1"
Gilles Peskine9004a172019-09-16 15:20:36 +02006203 export MBEDTLS_TEST_CONFIGURATION="$current_component"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02006204
6205 # Unconditionally create a seedfile that's sufficiently long.
6206 # Do this before each component, because a previous component may
6207 # have messed it up or shortened it.
Gilles Peskine88a07452021-07-08 19:03:50 +02006208 local dd_cmd
6209 dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
6210 case $OSTYPE in
Tom Cosgrove226aca12022-03-16 14:11:07 +00006211 linux*|freebsd*|openbsd*) dd_cmd+=(status=none)
Gilles Peskine88a07452021-07-08 19:03:50 +02006212 esac
6213 "${dd_cmd[@]}"
Gilles Peskine2ef377d2019-10-07 18:44:21 +02006214
Gilles Peskineec135542021-08-02 23:14:03 +02006215 # Run the component in a subshell, with error trapping and output
6216 # redirection set up based on the relevant options.
Gilles Peskinece266c42020-03-28 18:50:43 +01006217 if [ $KEEP_GOING -eq 1 ]; then
Gilles Peskineec135542021-08-02 23:14:03 +02006218 # We want to keep running if the subshell fails, so 'set -e' must
6219 # be off when the subshell runs.
Gilles Peskinece266c42020-03-28 18:50:43 +01006220 set +e
Manuel Pégourié-Gonnard2b2bdaa2020-06-02 11:28:07 +02006221 fi
Gilles Peskinece266c42020-03-28 18:50:43 +01006222 (
6223 if [ $QUIET -eq 1 ]; then
6224 # msg() will be silenced, so just print the component name here.
6225 echo "${current_component#component_}"
6226 exec >/dev/null
6227 fi
6228 if [ $KEEP_GOING -eq 1 ]; then
6229 # Keep "set -e" off, and run an ERR trap instead to record failures.
6230 set -E
6231 trap err_trap ERR
6232 fi
6233 # The next line is what runs the component
6234 "$@"
6235 if [ $KEEP_GOING -eq 1 ]; then
6236 trap - ERR
6237 exit $last_failure_status
6238 fi
6239 )
6240 component_status=$?
6241 if [ $KEEP_GOING -eq 1 ]; then
6242 set -e
6243 if [ $component_status -ne 0 ]; then
6244 failure_count=$((failure_count + 1))
6245 fi
6246 fi
Gilles Peskine2ef377d2019-10-07 18:44:21 +02006247
6248 # Restore the build tree to a clean state.
Gilles Peskinee48351a2018-11-27 16:06:30 +01006249 cleanup
Manuel Pégourié-Gonnard304b0992020-06-08 10:59:41 +02006250 unset current_component
Gilles Peskine8f073122018-11-27 15:58:47 +01006251}
6252
6253# Preliminary setup
6254pre_check_environment
6255pre_initialize_variables
6256pre_parse_command_line "$@"
Gilles Peskine348fb9a2018-11-27 17:04:29 +01006257
Dave Rodgman21900632024-02-26 11:41:19 +00006258setup_quiet_wrappers
Gilles Peskine878cf602019-01-06 20:50:38 +00006259pre_check_git
Gilles Peskine568f53a2021-07-12 18:16:01 +02006260pre_restore_files
Gilles Peskinef83eb822020-03-30 20:11:39 +02006261pre_back_up
Andrzej Kurekeb508712019-02-14 07:18:59 -05006262
Gilles Peskine878cf602019-01-06 20:50:38 +00006263build_status=0
6264if [ $KEEP_GOING -eq 1 ]; then
6265 pre_setup_keep_going
Gilles Peskine8f073122018-11-27 15:58:47 +01006266fi
Gilles Peskine67ffdaf2019-09-16 15:55:46 +02006267pre_prepare_outcome_file
Gilles Peskine878cf602019-01-06 20:50:38 +00006268pre_print_configuration
6269pre_check_tools
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01006270cleanup
David Horstmann76a77382023-08-17 17:32:26 +01006271if in_mbedtls_repo; then
David Horstmann9a6c45b2023-07-14 12:30:00 +01006272 pre_generate_files
6273fi
Manuel Pégourié-Gonnard80955ee2014-03-19 18:29:01 +01006274
Gilles Peskinebeb3a812019-01-06 22:11:25 +00006275# Run the requested tests.
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02006276for ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
Gilles Peskine5d996822020-03-28 21:09:21 +01006277 run_component pseudo_component_error_test
Gilles Peskine5d996822020-03-28 21:09:21 +01006278done
Gilles Peskine88a7c2b2021-08-02 23:28:00 +02006279unset error_test_i
Gilles Peskinebeb3a812019-01-06 22:11:25 +00006280for component in $RUN_COMPONENTS; do
6281 run_component "component_$component"
6282done
Gilles Peskine8f073122018-11-27 15:58:47 +01006283
6284# We're done.
Gilles Peskine878cf602019-01-06 20:50:38 +00006285post_report