1a8e1175bSopenharmony_ci#! /usr/bin/env bash
2a8e1175bSopenharmony_ci
3a8e1175bSopenharmony_ci# all.sh
4a8e1175bSopenharmony_ci#
5a8e1175bSopenharmony_ci# Copyright The Mbed TLS Contributors
6a8e1175bSopenharmony_ci# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7a8e1175bSopenharmony_ci
8a8e1175bSopenharmony_ci
9a8e1175bSopenharmony_ci
10a8e1175bSopenharmony_ci################################################################
11a8e1175bSopenharmony_ci#### Documentation
12a8e1175bSopenharmony_ci################################################################
13a8e1175bSopenharmony_ci
14a8e1175bSopenharmony_ci# Purpose
15a8e1175bSopenharmony_ci# -------
16a8e1175bSopenharmony_ci#
17a8e1175bSopenharmony_ci# To run all tests possible or available on the platform.
18a8e1175bSopenharmony_ci#
19a8e1175bSopenharmony_ci# Notes for users
20a8e1175bSopenharmony_ci# ---------------
21a8e1175bSopenharmony_ci#
22a8e1175bSopenharmony_ci# Warning: the test is destructive. It includes various build modes and
23a8e1175bSopenharmony_ci# configurations, and can and will arbitrarily change the current CMake
24a8e1175bSopenharmony_ci# configuration. The following files must be committed into git:
25a8e1175bSopenharmony_ci#    * include/mbedtls/mbedtls_config.h
26a8e1175bSopenharmony_ci#    * Makefile, library/Makefile, programs/Makefile, tests/Makefile,
27a8e1175bSopenharmony_ci#      programs/fuzz/Makefile
28a8e1175bSopenharmony_ci# After running this script, the CMake cache will be lost and CMake
29a8e1175bSopenharmony_ci# will no longer be initialised.
30a8e1175bSopenharmony_ci#
31a8e1175bSopenharmony_ci# The script assumes the presence of a number of tools:
32a8e1175bSopenharmony_ci#   * Basic Unix tools (Windows users note: a Unix-style find must be before
33a8e1175bSopenharmony_ci#     the Windows find in the PATH)
34a8e1175bSopenharmony_ci#   * Perl
35a8e1175bSopenharmony_ci#   * GNU Make
36a8e1175bSopenharmony_ci#   * CMake
37a8e1175bSopenharmony_ci#   * GCC and Clang (recent enough for using ASan with gcc and MemSan with clang, or valgrind)
38a8e1175bSopenharmony_ci#   * G++
39a8e1175bSopenharmony_ci#   * arm-gcc and mingw-gcc
40a8e1175bSopenharmony_ci#   * ArmCC 5 and ArmCC 6, unless invoked with --no-armcc
41a8e1175bSopenharmony_ci#   * OpenSSL and GnuTLS command line tools, in suitable versions for the
42a8e1175bSopenharmony_ci#     interoperability tests. The following are the official versions at the
43a8e1175bSopenharmony_ci#     time of writing:
44a8e1175bSopenharmony_ci#     * GNUTLS_{CLI,SERV} = 3.4.10
45a8e1175bSopenharmony_ci#     * GNUTLS_NEXT_{CLI,SERV} = 3.7.2
46a8e1175bSopenharmony_ci#     * OPENSSL = 1.0.2g (without Debian/Ubuntu patches)
47a8e1175bSopenharmony_ci#     * OPENSSL_NEXT = 1.1.1a
48a8e1175bSopenharmony_ci# See the invocation of check_tools below for details.
49a8e1175bSopenharmony_ci#
50a8e1175bSopenharmony_ci# This script must be invoked from the toplevel directory of a git
51a8e1175bSopenharmony_ci# working copy of Mbed TLS.
52a8e1175bSopenharmony_ci#
53a8e1175bSopenharmony_ci# The behavior on an error depends on whether --keep-going (alias -k)
54a8e1175bSopenharmony_ci# is in effect.
55a8e1175bSopenharmony_ci#  * Without --keep-going: the script stops on the first error without
56a8e1175bSopenharmony_ci#    cleaning up. This lets you work in the configuration of the failing
57a8e1175bSopenharmony_ci#    component.
58a8e1175bSopenharmony_ci#  * With --keep-going: the script runs all requested components and
59a8e1175bSopenharmony_ci#    reports failures at the end. In particular the script always cleans
60a8e1175bSopenharmony_ci#    up on exit.
61a8e1175bSopenharmony_ci#
62a8e1175bSopenharmony_ci# Note that the output is not saved. You may want to run
63a8e1175bSopenharmony_ci#   script -c tests/scripts/all.sh
64a8e1175bSopenharmony_ci# or
65a8e1175bSopenharmony_ci#   tests/scripts/all.sh >all.log 2>&1
66a8e1175bSopenharmony_ci#
67a8e1175bSopenharmony_ci# Notes for maintainers
68a8e1175bSopenharmony_ci# ---------------------
69a8e1175bSopenharmony_ci#
70a8e1175bSopenharmony_ci# The bulk of the code is organized into functions that follow one of the
71a8e1175bSopenharmony_ci# following naming conventions:
72a8e1175bSopenharmony_ci#  * pre_XXX: things to do before running the tests, in order.
73a8e1175bSopenharmony_ci#  * component_XXX: independent components. They can be run in any order.
74a8e1175bSopenharmony_ci#      * component_check_XXX: quick tests that aren't worth parallelizing.
75a8e1175bSopenharmony_ci#      * component_build_XXX: build things but don't run them.
76a8e1175bSopenharmony_ci#      * component_test_XXX: build and test.
77a8e1175bSopenharmony_ci#      * component_release_XXX: tests that the CI should skip during PR testing.
78a8e1175bSopenharmony_ci#  * support_XXX: if support_XXX exists and returns false then
79a8e1175bSopenharmony_ci#    component_XXX is not run by default.
80a8e1175bSopenharmony_ci#  * post_XXX: things to do after running the tests.
81a8e1175bSopenharmony_ci#  * other: miscellaneous support functions.
82a8e1175bSopenharmony_ci#
83a8e1175bSopenharmony_ci# Each component must start by invoking `msg` with a short informative message.
84a8e1175bSopenharmony_ci#
85a8e1175bSopenharmony_ci# Warning: due to the way bash detects errors, the failure of a command
86a8e1175bSopenharmony_ci# inside 'if' or '!' is not detected. Use the 'not' function instead of '!'.
87a8e1175bSopenharmony_ci#
88a8e1175bSopenharmony_ci# Each component is executed in a separate shell process. The component
89a8e1175bSopenharmony_ci# fails if any command in it returns a non-zero status.
90a8e1175bSopenharmony_ci#
91a8e1175bSopenharmony_ci# The framework performs some cleanup tasks after each component. This
92a8e1175bSopenharmony_ci# means that components can assume that the working directory is in a
93a8e1175bSopenharmony_ci# cleaned-up state, and don't need to perform the cleanup themselves.
94a8e1175bSopenharmony_ci# * Run `make clean`.
95a8e1175bSopenharmony_ci# * Restore `include/mbedtls/mbedtls_config.h` from a backup made before running
96a8e1175bSopenharmony_ci#   the component.
97a8e1175bSopenharmony_ci# * Check out `Makefile`, `library/Makefile`, `programs/Makefile`,
98a8e1175bSopenharmony_ci#   `tests/Makefile` and `programs/fuzz/Makefile` from git.
99a8e1175bSopenharmony_ci#   This cleans up after an in-tree use of CMake.
100a8e1175bSopenharmony_ci#
101a8e1175bSopenharmony_ci# The tests are roughly in order from fastest to slowest. This doesn't
102a8e1175bSopenharmony_ci# have to be exact, but in general you should add slower tests towards
103a8e1175bSopenharmony_ci# the end and fast checks near the beginning.
104a8e1175bSopenharmony_ci
105a8e1175bSopenharmony_ci
106a8e1175bSopenharmony_ci
107a8e1175bSopenharmony_ci################################################################
108a8e1175bSopenharmony_ci#### Initialization and command line parsing
109a8e1175bSopenharmony_ci################################################################
110a8e1175bSopenharmony_ci
111a8e1175bSopenharmony_ci# Abort on errors (even on the left-hand side of a pipe).
112a8e1175bSopenharmony_ci# Treat uninitialised variables as errors.
113a8e1175bSopenharmony_ciset -e -o pipefail -u
114a8e1175bSopenharmony_ci
115a8e1175bSopenharmony_ci# Enable ksh/bash extended file matching patterns
116a8e1175bSopenharmony_cishopt -s extglob
117a8e1175bSopenharmony_ci
118a8e1175bSopenharmony_ciin_mbedtls_repo () {
119a8e1175bSopenharmony_ci    test -d include -a -d library -a -d programs -a -d tests
120a8e1175bSopenharmony_ci}
121a8e1175bSopenharmony_ci
122a8e1175bSopenharmony_ciin_tf_psa_crypto_repo () {
123a8e1175bSopenharmony_ci    test -d include -a -d core -a -d drivers -a -d programs -a -d tests
124a8e1175bSopenharmony_ci}
125a8e1175bSopenharmony_ci
126a8e1175bSopenharmony_cipre_check_environment () {
127a8e1175bSopenharmony_ci    if in_mbedtls_repo || in_tf_psa_crypto_repo; then :; else
128a8e1175bSopenharmony_ci        echo "Must be run from Mbed TLS / TF-PSA-Crypto root" >&2
129a8e1175bSopenharmony_ci        exit 1
130a8e1175bSopenharmony_ci    fi
131a8e1175bSopenharmony_ci}
132a8e1175bSopenharmony_ci
133a8e1175bSopenharmony_cipre_initialize_variables () {
134a8e1175bSopenharmony_ci    if in_mbedtls_repo; then
135a8e1175bSopenharmony_ci        CONFIG_H='include/mbedtls/mbedtls_config.h'
136a8e1175bSopenharmony_ci    else
137a8e1175bSopenharmony_ci        CONFIG_H='drivers/builtin/include/mbedtls/mbedtls_config.h'
138a8e1175bSopenharmony_ci    fi
139a8e1175bSopenharmony_ci    CRYPTO_CONFIG_H='include/psa/crypto_config.h'
140a8e1175bSopenharmony_ci    CONFIG_TEST_DRIVER_H='tests/include/test/drivers/config_test_driver.h'
141a8e1175bSopenharmony_ci
142a8e1175bSopenharmony_ci    # Files that are clobbered by some jobs will be backed up. Use a different
143a8e1175bSopenharmony_ci    # suffix from auxiliary scripts so that all.sh and auxiliary scripts can
144a8e1175bSopenharmony_ci    # independently decide when to remove the backup file.
145a8e1175bSopenharmony_ci    backup_suffix='.all.bak'
146a8e1175bSopenharmony_ci    # Files clobbered by config.py
147a8e1175bSopenharmony_ci    files_to_back_up="$CONFIG_H $CRYPTO_CONFIG_H $CONFIG_TEST_DRIVER_H"
148a8e1175bSopenharmony_ci    if in_mbedtls_repo; then
149a8e1175bSopenharmony_ci        # Files clobbered by in-tree cmake
150a8e1175bSopenharmony_ci        files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile"
151a8e1175bSopenharmony_ci    fi
152a8e1175bSopenharmony_ci
153a8e1175bSopenharmony_ci    append_outcome=0
154a8e1175bSopenharmony_ci    MEMORY=0
155a8e1175bSopenharmony_ci    FORCE=0
156a8e1175bSopenharmony_ci    QUIET=0
157a8e1175bSopenharmony_ci    KEEP_GOING=0
158a8e1175bSopenharmony_ci
159a8e1175bSopenharmony_ci    # Seed value used with the --release-test option.
160a8e1175bSopenharmony_ci    #
161a8e1175bSopenharmony_ci    # See also RELEASE_SEED in basic-build-test.sh. Debugging is easier if
162a8e1175bSopenharmony_ci    # both values are kept in sync. If you change the value here because it
163a8e1175bSopenharmony_ci    # breaks some tests, you'll definitely want to change it in
164a8e1175bSopenharmony_ci    # basic-build-test.sh as well.
165a8e1175bSopenharmony_ci    RELEASE_SEED=1
166a8e1175bSopenharmony_ci
167a8e1175bSopenharmony_ci    # Specify character collation for regular expressions and sorting with C locale
168a8e1175bSopenharmony_ci    export LC_COLLATE=C
169a8e1175bSopenharmony_ci
170a8e1175bSopenharmony_ci    : ${MBEDTLS_TEST_OUTCOME_FILE=}
171a8e1175bSopenharmony_ci    : ${MBEDTLS_TEST_PLATFORM="$(uname -s | tr -c \\n0-9A-Za-z _)-$(uname -m | tr -c \\n0-9A-Za-z _)"}
172a8e1175bSopenharmony_ci    export MBEDTLS_TEST_OUTCOME_FILE
173a8e1175bSopenharmony_ci    export MBEDTLS_TEST_PLATFORM
174a8e1175bSopenharmony_ci
175a8e1175bSopenharmony_ci    # Default commands, can be overridden by the environment
176a8e1175bSopenharmony_ci    : ${OPENSSL:="openssl"}
177a8e1175bSopenharmony_ci    : ${OPENSSL_NEXT:="$OPENSSL"}
178a8e1175bSopenharmony_ci    : ${GNUTLS_CLI:="gnutls-cli"}
179a8e1175bSopenharmony_ci    : ${GNUTLS_SERV:="gnutls-serv"}
180a8e1175bSopenharmony_ci    : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build}
181a8e1175bSopenharmony_ci    : ${ARMC5_BIN_DIR:=/usr/bin}
182a8e1175bSopenharmony_ci    : ${ARMC6_BIN_DIR:=/usr/bin}
183a8e1175bSopenharmony_ci    : ${ARM_NONE_EABI_GCC_PREFIX:=arm-none-eabi-}
184a8e1175bSopenharmony_ci    : ${ARM_LINUX_GNUEABI_GCC_PREFIX:=arm-linux-gnueabi-}
185a8e1175bSopenharmony_ci    : ${CLANG_LATEST:="clang-latest"}
186a8e1175bSopenharmony_ci    : ${CLANG_EARLIEST:="clang-earliest"}
187a8e1175bSopenharmony_ci    : ${GCC_LATEST:="gcc-latest"}
188a8e1175bSopenharmony_ci    : ${GCC_EARLIEST:="gcc-earliest"}
189a8e1175bSopenharmony_ci    # if MAKEFLAGS is not set add the -j option to speed up invocations of make
190a8e1175bSopenharmony_ci    if [ -z "${MAKEFLAGS+set}" ]; then
191a8e1175bSopenharmony_ci        export MAKEFLAGS="-j$(all_sh_nproc)"
192a8e1175bSopenharmony_ci    fi
193a8e1175bSopenharmony_ci    # if CC is not set, use clang by default (if present) to improve build times
194a8e1175bSopenharmony_ci    if [ -z "${CC+set}" ] && (type clang > /dev/null 2>&1); then
195a8e1175bSopenharmony_ci        export CC="clang"
196a8e1175bSopenharmony_ci    fi
197a8e1175bSopenharmony_ci
198a8e1175bSopenharmony_ci    # Include more verbose output for failing tests run by CMake or make
199a8e1175bSopenharmony_ci    export CTEST_OUTPUT_ON_FAILURE=1
200a8e1175bSopenharmony_ci
201a8e1175bSopenharmony_ci    # CFLAGS and LDFLAGS for Asan builds that don't use CMake
202a8e1175bSopenharmony_ci    # default to -O2, use -Ox _after_ this if you want another level
203a8e1175bSopenharmony_ci    ASAN_CFLAGS='-O2 -Werror -fsanitize=address,undefined -fno-sanitize-recover=all'
204a8e1175bSopenharmony_ci    # Normally, tests should use this compiler for ASAN testing
205a8e1175bSopenharmony_ci    ASAN_CC=clang
206a8e1175bSopenharmony_ci
207a8e1175bSopenharmony_ci    # Platform tests have an allocation that returns null
208a8e1175bSopenharmony_ci    export ASAN_OPTIONS="allocator_may_return_null=1"
209a8e1175bSopenharmony_ci    export MSAN_OPTIONS="allocator_may_return_null=1"
210a8e1175bSopenharmony_ci
211a8e1175bSopenharmony_ci    # Gather the list of available components. These are the functions
212a8e1175bSopenharmony_ci    # defined in this script whose name starts with "component_".
213a8e1175bSopenharmony_ci    ALL_COMPONENTS=$(compgen -A function component_ | sed 's/component_//')
214a8e1175bSopenharmony_ci
215a8e1175bSopenharmony_ci    # Delay determining SUPPORTED_COMPONENTS until the command line options have a chance to override
216a8e1175bSopenharmony_ci    # the commands set by the environment
217a8e1175bSopenharmony_ci}
218a8e1175bSopenharmony_ci
219a8e1175bSopenharmony_cisetup_quiet_wrappers()
220a8e1175bSopenharmony_ci{
221a8e1175bSopenharmony_ci    # Pick up "quiet" wrappers for make and cmake, which don't output very much
222a8e1175bSopenharmony_ci    # unless there is an error. This reduces logging overhead in the CI.
223a8e1175bSopenharmony_ci    #
224a8e1175bSopenharmony_ci    # Note that the cmake wrapper breaks unless we use an absolute path here.
225a8e1175bSopenharmony_ci    if [[ -e ${PWD}/tests/scripts/quiet ]]; then
226a8e1175bSopenharmony_ci        export PATH=${PWD}/tests/scripts/quiet:$PATH
227a8e1175bSopenharmony_ci    fi
228a8e1175bSopenharmony_ci}
229a8e1175bSopenharmony_ci
230a8e1175bSopenharmony_ci# Test whether the component $1 is included in the command line patterns.
231a8e1175bSopenharmony_ciis_component_included()
232a8e1175bSopenharmony_ci{
233a8e1175bSopenharmony_ci    # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
234a8e1175bSopenharmony_ci    # only does word splitting.
235a8e1175bSopenharmony_ci    set -f
236a8e1175bSopenharmony_ci    for pattern in $COMMAND_LINE_COMPONENTS; do
237a8e1175bSopenharmony_ci        set +f
238a8e1175bSopenharmony_ci        case ${1#component_} in $pattern) return 0;; esac
239a8e1175bSopenharmony_ci    done
240a8e1175bSopenharmony_ci    set +f
241a8e1175bSopenharmony_ci    return 1
242a8e1175bSopenharmony_ci}
243a8e1175bSopenharmony_ci
244a8e1175bSopenharmony_ciusage()
245a8e1175bSopenharmony_ci{
246a8e1175bSopenharmony_ci    cat <<EOF
247a8e1175bSopenharmony_ciUsage: $0 [OPTION]... [COMPONENT]...
248a8e1175bSopenharmony_ciRun mbedtls release validation tests.
249a8e1175bSopenharmony_ciBy default, run all tests. With one or more COMPONENT, run only those.
250a8e1175bSopenharmony_ciCOMPONENT can be the name of a component or a shell wildcard pattern.
251a8e1175bSopenharmony_ci
252a8e1175bSopenharmony_ciExamples:
253a8e1175bSopenharmony_ci  $0 "check_*"
254a8e1175bSopenharmony_ci    Run all sanity checks.
255a8e1175bSopenharmony_ci  $0 --no-armcc --except test_memsan
256a8e1175bSopenharmony_ci    Run everything except builds that require armcc and MemSan.
257a8e1175bSopenharmony_ci
258a8e1175bSopenharmony_ciSpecial options:
259a8e1175bSopenharmony_ci  -h|--help             Print this help and exit.
260a8e1175bSopenharmony_ci  --list-all-components List all available test components and exit.
261a8e1175bSopenharmony_ci  --list-components     List components supported on this platform and exit.
262a8e1175bSopenharmony_ci
263a8e1175bSopenharmony_ciGeneral options:
264a8e1175bSopenharmony_ci  -q|--quiet            Only output component names, and errors if any.
265a8e1175bSopenharmony_ci  -f|--force            Force the tests to overwrite any modified files.
266a8e1175bSopenharmony_ci  -k|--keep-going       Run all tests and report errors at the end.
267a8e1175bSopenharmony_ci  -m|--memory           Additional optional memory tests.
268a8e1175bSopenharmony_ci     --append-outcome   Append to the outcome file (if used).
269a8e1175bSopenharmony_ci     --arm-none-eabi-gcc-prefix=<string>
270a8e1175bSopenharmony_ci                        Prefix for a cross-compiler for arm-none-eabi
271a8e1175bSopenharmony_ci                        (default: "${ARM_NONE_EABI_GCC_PREFIX}")
272a8e1175bSopenharmony_ci     --arm-linux-gnueabi-gcc-prefix=<string>
273a8e1175bSopenharmony_ci                        Prefix for a cross-compiler for arm-linux-gnueabi
274a8e1175bSopenharmony_ci                        (default: "${ARM_LINUX_GNUEABI_GCC_PREFIX}")
275a8e1175bSopenharmony_ci     --armcc            Run ARM Compiler builds (on by default).
276a8e1175bSopenharmony_ci     --restore          First clean up the build tree, restoring backed up
277a8e1175bSopenharmony_ci                        files. Do not run any components unless they are
278a8e1175bSopenharmony_ci                        explicitly specified.
279a8e1175bSopenharmony_ci     --error-test       Error test mode: run a failing function in addition
280a8e1175bSopenharmony_ci                        to any specified component. May be repeated.
281a8e1175bSopenharmony_ci     --except           Exclude the COMPONENTs listed on the command line,
282a8e1175bSopenharmony_ci                        instead of running only those.
283a8e1175bSopenharmony_ci     --no-append-outcome    Write a new outcome file and analyze it (default).
284a8e1175bSopenharmony_ci     --no-armcc         Skip ARM Compiler builds.
285a8e1175bSopenharmony_ci     --no-force         Refuse to overwrite modified files (default).
286a8e1175bSopenharmony_ci     --no-keep-going    Stop at the first error (default).
287a8e1175bSopenharmony_ci     --no-memory        No additional memory tests (default).
288a8e1175bSopenharmony_ci     --no-quiet         Print full output from components.
289a8e1175bSopenharmony_ci     --out-of-source-dir=<path>  Directory used for CMake out-of-source build tests.
290a8e1175bSopenharmony_ci     --outcome-file=<path>  File where test outcomes are written (not done if
291a8e1175bSopenharmony_ci                            empty; default: \$MBEDTLS_TEST_OUTCOME_FILE).
292a8e1175bSopenharmony_ci     --random-seed      Use a random seed value for randomized tests (default).
293a8e1175bSopenharmony_ci  -r|--release-test     Run this script in release mode. This fixes the seed value to ${RELEASE_SEED}.
294a8e1175bSopenharmony_ci  -s|--seed             Integer seed value to use for this test run.
295a8e1175bSopenharmony_ci
296a8e1175bSopenharmony_ciTool path options:
297a8e1175bSopenharmony_ci     --armc5-bin-dir=<ARMC5_bin_dir_path>       ARM Compiler 5 bin directory.
298a8e1175bSopenharmony_ci     --armc6-bin-dir=<ARMC6_bin_dir_path>       ARM Compiler 6 bin directory.
299a8e1175bSopenharmony_ci     --clang-earliest=<Clang_earliest_path>     Earliest version of clang available
300a8e1175bSopenharmony_ci     --clang-latest=<Clang_latest_path>         Latest version of clang available
301a8e1175bSopenharmony_ci     --gcc-earliest=<GCC_earliest_path>         Earliest version of GCC available
302a8e1175bSopenharmony_ci     --gcc-latest=<GCC_latest_path>             Latest version of GCC available
303a8e1175bSopenharmony_ci     --gnutls-cli=<GnuTLS_cli_path>             GnuTLS client executable to use for most tests.
304a8e1175bSopenharmony_ci     --gnutls-serv=<GnuTLS_serv_path>           GnuTLS server executable to use for most tests.
305a8e1175bSopenharmony_ci     --openssl=<OpenSSL_path>                   OpenSSL executable to use for most tests.
306a8e1175bSopenharmony_ci     --openssl-next=<OpenSSL_path>              OpenSSL executable to use for recent things like ARIA
307a8e1175bSopenharmony_ciEOF
308a8e1175bSopenharmony_ci}
309a8e1175bSopenharmony_ci
310a8e1175bSopenharmony_ci# Cleanup before/after running a component.
311a8e1175bSopenharmony_ci# Remove built files as well as the cmake cache/config.
312a8e1175bSopenharmony_ci# Does not remove generated source files.
313a8e1175bSopenharmony_cicleanup()
314a8e1175bSopenharmony_ci{
315a8e1175bSopenharmony_ci    if in_mbedtls_repo; then
316a8e1175bSopenharmony_ci        command make clean
317a8e1175bSopenharmony_ci    fi
318a8e1175bSopenharmony_ci
319a8e1175bSopenharmony_ci    # Remove CMake artefacts
320a8e1175bSopenharmony_ci    find . -name .git -prune -o \
321a8e1175bSopenharmony_ci           -iname CMakeFiles -exec rm -rf {} \+ -o \
322a8e1175bSopenharmony_ci           \( -iname cmake_install.cmake -o \
323a8e1175bSopenharmony_ci              -iname CTestTestfile.cmake -o \
324a8e1175bSopenharmony_ci              -iname CMakeCache.txt -o \
325a8e1175bSopenharmony_ci              -path './cmake/*.cmake' \) -exec rm -f {} \+
326a8e1175bSopenharmony_ci    # Recover files overwritten by in-tree CMake builds
327a8e1175bSopenharmony_ci    rm -f include/Makefile include/mbedtls/Makefile programs/!(fuzz)/Makefile
328a8e1175bSopenharmony_ci
329a8e1175bSopenharmony_ci    # Remove any artifacts from the component_test_cmake_as_subdirectory test.
330a8e1175bSopenharmony_ci    rm -rf programs/test/cmake_subproject/build
331a8e1175bSopenharmony_ci    rm -f programs/test/cmake_subproject/Makefile
332a8e1175bSopenharmony_ci    rm -f programs/test/cmake_subproject/cmake_subproject
333a8e1175bSopenharmony_ci
334a8e1175bSopenharmony_ci    # Remove any artifacts from the component_test_cmake_as_package test.
335a8e1175bSopenharmony_ci    rm -rf programs/test/cmake_package/build
336a8e1175bSopenharmony_ci    rm -f programs/test/cmake_package/Makefile
337a8e1175bSopenharmony_ci    rm -f programs/test/cmake_package/cmake_package
338a8e1175bSopenharmony_ci
339a8e1175bSopenharmony_ci    # Remove any artifacts from the component_test_cmake_as_installed_package test.
340a8e1175bSopenharmony_ci    rm -rf programs/test/cmake_package_install/build
341a8e1175bSopenharmony_ci    rm -f programs/test/cmake_package_install/Makefile
342a8e1175bSopenharmony_ci    rm -f programs/test/cmake_package_install/cmake_package_install
343a8e1175bSopenharmony_ci
344a8e1175bSopenharmony_ci    # Restore files that may have been clobbered by the job
345a8e1175bSopenharmony_ci    for x in $files_to_back_up; do
346a8e1175bSopenharmony_ci        if [[ -e "$x$backup_suffix" ]]; then
347a8e1175bSopenharmony_ci            cp -p "$x$backup_suffix" "$x"
348a8e1175bSopenharmony_ci        fi
349a8e1175bSopenharmony_ci    done
350a8e1175bSopenharmony_ci}
351a8e1175bSopenharmony_ci
352a8e1175bSopenharmony_ci# Final cleanup when this script exits (except when exiting on a failure
353a8e1175bSopenharmony_ci# in non-keep-going mode).
354a8e1175bSopenharmony_cifinal_cleanup () {
355a8e1175bSopenharmony_ci    cleanup
356a8e1175bSopenharmony_ci
357a8e1175bSopenharmony_ci    for x in $files_to_back_up; do
358a8e1175bSopenharmony_ci        rm -f "$x$backup_suffix"
359a8e1175bSopenharmony_ci    done
360a8e1175bSopenharmony_ci}
361a8e1175bSopenharmony_ci
362a8e1175bSopenharmony_ci# Executed on exit. May be redefined depending on command line options.
363a8e1175bSopenharmony_cifinal_report () {
364a8e1175bSopenharmony_ci    :
365a8e1175bSopenharmony_ci}
366a8e1175bSopenharmony_ci
367a8e1175bSopenharmony_cifatal_signal () {
368a8e1175bSopenharmony_ci    final_cleanup
369a8e1175bSopenharmony_ci    final_report $1
370a8e1175bSopenharmony_ci    trap - $1
371a8e1175bSopenharmony_ci    kill -$1 $$
372a8e1175bSopenharmony_ci}
373a8e1175bSopenharmony_ci
374a8e1175bSopenharmony_citrap 'fatal_signal HUP' HUP
375a8e1175bSopenharmony_citrap 'fatal_signal INT' INT
376a8e1175bSopenharmony_citrap 'fatal_signal TERM' TERM
377a8e1175bSopenharmony_ci
378a8e1175bSopenharmony_ci# Number of processors on this machine. Used as the default setting
379a8e1175bSopenharmony_ci# for parallel make.
380a8e1175bSopenharmony_ciall_sh_nproc ()
381a8e1175bSopenharmony_ci{
382a8e1175bSopenharmony_ci    {
383a8e1175bSopenharmony_ci        nproc || # Linux
384a8e1175bSopenharmony_ci        sysctl -n hw.ncpuonline || # NetBSD, OpenBSD
385a8e1175bSopenharmony_ci        sysctl -n hw.ncpu || # FreeBSD
386a8e1175bSopenharmony_ci        echo 1
387a8e1175bSopenharmony_ci    } 2>/dev/null
388a8e1175bSopenharmony_ci}
389a8e1175bSopenharmony_ci
390a8e1175bSopenharmony_cimsg()
391a8e1175bSopenharmony_ci{
392a8e1175bSopenharmony_ci    if [ -n "${current_component:-}" ]; then
393a8e1175bSopenharmony_ci        current_section="${current_component#component_}: $1"
394a8e1175bSopenharmony_ci    else
395a8e1175bSopenharmony_ci        current_section="$1"
396a8e1175bSopenharmony_ci    fi
397a8e1175bSopenharmony_ci
398a8e1175bSopenharmony_ci    if [ $QUIET -eq 1 ]; then
399a8e1175bSopenharmony_ci        return
400a8e1175bSopenharmony_ci    fi
401a8e1175bSopenharmony_ci
402a8e1175bSopenharmony_ci    echo ""
403a8e1175bSopenharmony_ci    echo "******************************************************************"
404a8e1175bSopenharmony_ci    echo "* $current_section "
405a8e1175bSopenharmony_ci    printf "* "; date
406a8e1175bSopenharmony_ci    echo "******************************************************************"
407a8e1175bSopenharmony_ci}
408a8e1175bSopenharmony_ci
409a8e1175bSopenharmony_ciarmc6_build_test()
410a8e1175bSopenharmony_ci{
411a8e1175bSopenharmony_ci    FLAGS="$1"
412a8e1175bSopenharmony_ci
413a8e1175bSopenharmony_ci    msg "build: ARM Compiler 6 ($FLAGS)"
414a8e1175bSopenharmony_ci    make clean
415a8e1175bSopenharmony_ci    ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \
416a8e1175bSopenharmony_ci                    WARNING_CFLAGS='-Werror -xc -std=c99' make lib
417a8e1175bSopenharmony_ci
418a8e1175bSopenharmony_ci    msg "size: ARM Compiler 6 ($FLAGS)"
419a8e1175bSopenharmony_ci    "$ARMC6_FROMELF" -z library/*.o
420a8e1175bSopenharmony_ci}
421a8e1175bSopenharmony_ci
422a8e1175bSopenharmony_cierr_msg()
423a8e1175bSopenharmony_ci{
424a8e1175bSopenharmony_ci    echo "$1" >&2
425a8e1175bSopenharmony_ci}
426a8e1175bSopenharmony_ci
427a8e1175bSopenharmony_cicheck_tools()
428a8e1175bSopenharmony_ci{
429a8e1175bSopenharmony_ci    for tool in "$@"; do
430a8e1175bSopenharmony_ci        if ! `type "$tool" >/dev/null 2>&1`; then
431a8e1175bSopenharmony_ci            err_msg "$tool not found!"
432a8e1175bSopenharmony_ci            exit 1
433a8e1175bSopenharmony_ci        fi
434a8e1175bSopenharmony_ci    done
435a8e1175bSopenharmony_ci}
436a8e1175bSopenharmony_ci
437a8e1175bSopenharmony_cipre_parse_command_line () {
438a8e1175bSopenharmony_ci    COMMAND_LINE_COMPONENTS=
439a8e1175bSopenharmony_ci    all_except=0
440a8e1175bSopenharmony_ci    error_test=0
441a8e1175bSopenharmony_ci    list_components=0
442a8e1175bSopenharmony_ci    restore_first=0
443a8e1175bSopenharmony_ci    no_armcc=
444a8e1175bSopenharmony_ci
445a8e1175bSopenharmony_ci    # Note that legacy options are ignored instead of being omitted from this
446a8e1175bSopenharmony_ci    # list of options, so invocations that worked with previous version of
447a8e1175bSopenharmony_ci    # all.sh will still run and work properly.
448a8e1175bSopenharmony_ci    while [ $# -gt 0 ]; do
449a8e1175bSopenharmony_ci        case "$1" in
450a8e1175bSopenharmony_ci            --append-outcome) append_outcome=1;;
451a8e1175bSopenharmony_ci            --arm-none-eabi-gcc-prefix) shift; ARM_NONE_EABI_GCC_PREFIX="$1";;
452a8e1175bSopenharmony_ci            --arm-linux-gnueabi-gcc-prefix) shift; ARM_LINUX_GNUEABI_GCC_PREFIX="$1";;
453a8e1175bSopenharmony_ci            --armcc) no_armcc=;;
454a8e1175bSopenharmony_ci            --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";;
455a8e1175bSopenharmony_ci            --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";;
456a8e1175bSopenharmony_ci            --clang-earliest) shift; CLANG_EARLIEST="$1";;
457a8e1175bSopenharmony_ci            --clang-latest) shift; CLANG_LATEST="$1";;
458a8e1175bSopenharmony_ci            --error-test) error_test=$((error_test + 1));;
459a8e1175bSopenharmony_ci            --except) all_except=1;;
460a8e1175bSopenharmony_ci            --force|-f) FORCE=1;;
461a8e1175bSopenharmony_ci            --gcc-earliest) shift; GCC_EARLIEST="$1";;
462a8e1175bSopenharmony_ci            --gcc-latest) shift; GCC_LATEST="$1";;
463a8e1175bSopenharmony_ci            --gnutls-cli) shift; GNUTLS_CLI="$1";;
464a8e1175bSopenharmony_ci            --gnutls-legacy-cli) shift;; # ignored for backward compatibility
465a8e1175bSopenharmony_ci            --gnutls-legacy-serv) shift;; # ignored for backward compatibility
466a8e1175bSopenharmony_ci            --gnutls-serv) shift; GNUTLS_SERV="$1";;
467a8e1175bSopenharmony_ci            --help|-h) usage; exit;;
468a8e1175bSopenharmony_ci            --keep-going|-k) KEEP_GOING=1;;
469a8e1175bSopenharmony_ci            --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;;
470a8e1175bSopenharmony_ci            --list-components) list_components=1;;
471a8e1175bSopenharmony_ci            --memory|-m) MEMORY=1;;
472a8e1175bSopenharmony_ci            --no-append-outcome) append_outcome=0;;
473a8e1175bSopenharmony_ci            --no-armcc) no_armcc=1;;
474a8e1175bSopenharmony_ci            --no-force) FORCE=0;;
475a8e1175bSopenharmony_ci            --no-keep-going) KEEP_GOING=0;;
476a8e1175bSopenharmony_ci            --no-memory) MEMORY=0;;
477a8e1175bSopenharmony_ci            --no-quiet) QUIET=0;;
478a8e1175bSopenharmony_ci            --openssl) shift; OPENSSL="$1";;
479a8e1175bSopenharmony_ci            --openssl-next) shift; OPENSSL_NEXT="$1";;
480a8e1175bSopenharmony_ci            --outcome-file) shift; MBEDTLS_TEST_OUTCOME_FILE="$1";;
481a8e1175bSopenharmony_ci            --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";;
482a8e1175bSopenharmony_ci            --quiet|-q) QUIET=1;;
483a8e1175bSopenharmony_ci            --random-seed) unset SEED;;
484a8e1175bSopenharmony_ci            --release-test|-r) SEED=$RELEASE_SEED;;
485a8e1175bSopenharmony_ci            --restore) restore_first=1;;
486a8e1175bSopenharmony_ci            --seed|-s) shift; SEED="$1";;
487a8e1175bSopenharmony_ci            -*)
488a8e1175bSopenharmony_ci                echo >&2 "Unknown option: $1"
489a8e1175bSopenharmony_ci                echo >&2 "Run $0 --help for usage."
490a8e1175bSopenharmony_ci                exit 120
491a8e1175bSopenharmony_ci                ;;
492a8e1175bSopenharmony_ci            *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";;
493a8e1175bSopenharmony_ci        esac
494a8e1175bSopenharmony_ci        shift
495a8e1175bSopenharmony_ci    done
496a8e1175bSopenharmony_ci
497a8e1175bSopenharmony_ci    # Exclude components that are not supported on this platform.
498a8e1175bSopenharmony_ci    SUPPORTED_COMPONENTS=
499a8e1175bSopenharmony_ci    for component in $ALL_COMPONENTS; do
500a8e1175bSopenharmony_ci        case $(type "support_$component" 2>&1) in
501a8e1175bSopenharmony_ci            *' function'*)
502a8e1175bSopenharmony_ci                if ! support_$component; then continue; fi;;
503a8e1175bSopenharmony_ci        esac
504a8e1175bSopenharmony_ci        SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component"
505a8e1175bSopenharmony_ci    done
506a8e1175bSopenharmony_ci
507a8e1175bSopenharmony_ci    if [ $list_components -eq 1 ]; then
508a8e1175bSopenharmony_ci        printf '%s\n' $SUPPORTED_COMPONENTS
509a8e1175bSopenharmony_ci        exit
510a8e1175bSopenharmony_ci    fi
511a8e1175bSopenharmony_ci
512a8e1175bSopenharmony_ci    # With no list of components, run everything.
513a8e1175bSopenharmony_ci    if [ -z "$COMMAND_LINE_COMPONENTS" ] && [ $restore_first -eq 0 ]; then
514a8e1175bSopenharmony_ci        all_except=1
515a8e1175bSopenharmony_ci    fi
516a8e1175bSopenharmony_ci
517a8e1175bSopenharmony_ci    # --no-armcc is a legacy option. The modern way is --except '*_armcc*'.
518a8e1175bSopenharmony_ci    # Ignore it if components are listed explicitly on the command line.
519a8e1175bSopenharmony_ci    if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then
520a8e1175bSopenharmony_ci        COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*"
521a8e1175bSopenharmony_ci    fi
522a8e1175bSopenharmony_ci
523a8e1175bSopenharmony_ci    # Error out if an explicitly requested component doesn't exist.
524a8e1175bSopenharmony_ci    if [ $all_except -eq 0 ]; then
525a8e1175bSopenharmony_ci        unsupported=0
526a8e1175bSopenharmony_ci        # Temporarily disable wildcard expansion so that $COMMAND_LINE_COMPONENTS
527a8e1175bSopenharmony_ci        # only does word splitting.
528a8e1175bSopenharmony_ci        set -f
529a8e1175bSopenharmony_ci        for component in $COMMAND_LINE_COMPONENTS; do
530a8e1175bSopenharmony_ci            set +f
531a8e1175bSopenharmony_ci            # If the requested name includes a wildcard character, don't
532a8e1175bSopenharmony_ci            # check it. Accept wildcard patterns that don't match anything.
533a8e1175bSopenharmony_ci            case $component in
534a8e1175bSopenharmony_ci                *[*?\[]*) continue;;
535a8e1175bSopenharmony_ci            esac
536a8e1175bSopenharmony_ci            case " $SUPPORTED_COMPONENTS " in
537a8e1175bSopenharmony_ci                *" $component "*) :;;
538a8e1175bSopenharmony_ci                *)
539a8e1175bSopenharmony_ci                    echo >&2 "Component $component was explicitly requested, but is not known or not supported."
540a8e1175bSopenharmony_ci                    unsupported=$((unsupported + 1));;
541a8e1175bSopenharmony_ci            esac
542a8e1175bSopenharmony_ci        done
543a8e1175bSopenharmony_ci        set +f
544a8e1175bSopenharmony_ci        if [ $unsupported -ne 0 ]; then
545a8e1175bSopenharmony_ci            exit 2
546a8e1175bSopenharmony_ci        fi
547a8e1175bSopenharmony_ci    fi
548a8e1175bSopenharmony_ci
549a8e1175bSopenharmony_ci    # Build the list of components to run.
550a8e1175bSopenharmony_ci    RUN_COMPONENTS=
551a8e1175bSopenharmony_ci    for component in $SUPPORTED_COMPONENTS; do
552a8e1175bSopenharmony_ci        if is_component_included "$component"; [ $? -eq $all_except ]; then
553a8e1175bSopenharmony_ci            RUN_COMPONENTS="$RUN_COMPONENTS $component"
554a8e1175bSopenharmony_ci        fi
555a8e1175bSopenharmony_ci    done
556a8e1175bSopenharmony_ci
557a8e1175bSopenharmony_ci    unset all_except
558a8e1175bSopenharmony_ci    unset no_armcc
559a8e1175bSopenharmony_ci}
560a8e1175bSopenharmony_ci
561a8e1175bSopenharmony_cipre_check_git () {
562a8e1175bSopenharmony_ci    if [ $FORCE -eq 1 ]; then
563a8e1175bSopenharmony_ci        rm -rf "$OUT_OF_SOURCE_DIR"
564a8e1175bSopenharmony_ci        git checkout-index -f -q $CONFIG_H
565a8e1175bSopenharmony_ci        cleanup
566a8e1175bSopenharmony_ci    else
567a8e1175bSopenharmony_ci
568a8e1175bSopenharmony_ci        if [ -d "$OUT_OF_SOURCE_DIR" ]; then
569a8e1175bSopenharmony_ci            echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2
570a8e1175bSopenharmony_ci            echo "You can either delete this directory manually, or force the test by rerunning"
571a8e1175bSopenharmony_ci            echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR"
572a8e1175bSopenharmony_ci            exit 1
573a8e1175bSopenharmony_ci        fi
574a8e1175bSopenharmony_ci
575a8e1175bSopenharmony_ci        if ! git diff --quiet "$CONFIG_H"; then
576a8e1175bSopenharmony_ci            err_msg "Warning - the configuration file '$CONFIG_H' has been edited. "
577a8e1175bSopenharmony_ci            echo "You can either delete or preserve your work, or force the test by rerunning the"
578a8e1175bSopenharmony_ci            echo "script as: $0 --force"
579a8e1175bSopenharmony_ci            exit 1
580a8e1175bSopenharmony_ci        fi
581a8e1175bSopenharmony_ci    fi
582a8e1175bSopenharmony_ci}
583a8e1175bSopenharmony_ci
584a8e1175bSopenharmony_cipre_restore_files () {
585a8e1175bSopenharmony_ci    # If the makefiles have been generated by a framework such as cmake,
586a8e1175bSopenharmony_ci    # restore them from git. If the makefiles look like modifications from
587a8e1175bSopenharmony_ci    # the ones checked into git, take care not to modify them. Whatever
588a8e1175bSopenharmony_ci    # this function leaves behind is what the script will restore before
589a8e1175bSopenharmony_ci    # each component.
590a8e1175bSopenharmony_ci    case "$(head -n1 Makefile)" in
591a8e1175bSopenharmony_ci        *[Gg]enerated*)
592a8e1175bSopenharmony_ci            git update-index --no-skip-worktree Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
593a8e1175bSopenharmony_ci            git checkout -- Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile
594a8e1175bSopenharmony_ci            ;;
595a8e1175bSopenharmony_ci    esac
596a8e1175bSopenharmony_ci}
597a8e1175bSopenharmony_ci
598a8e1175bSopenharmony_cipre_back_up () {
599a8e1175bSopenharmony_ci    for x in $files_to_back_up; do
600a8e1175bSopenharmony_ci        cp -p "$x" "$x$backup_suffix"
601a8e1175bSopenharmony_ci    done
602a8e1175bSopenharmony_ci}
603a8e1175bSopenharmony_ci
604a8e1175bSopenharmony_cipre_setup_keep_going () {
605a8e1175bSopenharmony_ci    failure_count=0 # Number of failed components
606a8e1175bSopenharmony_ci    last_failure_status=0 # Last failure status in this component
607a8e1175bSopenharmony_ci
608a8e1175bSopenharmony_ci    # See err_trap
609a8e1175bSopenharmony_ci    previous_failure_status=0
610a8e1175bSopenharmony_ci    previous_failed_command=
611a8e1175bSopenharmony_ci    previous_failure_funcall_depth=0
612a8e1175bSopenharmony_ci    unset report_failed_command
613a8e1175bSopenharmony_ci
614a8e1175bSopenharmony_ci    start_red=
615a8e1175bSopenharmony_ci    end_color=
616a8e1175bSopenharmony_ci    if [ -t 1 ]; then
617a8e1175bSopenharmony_ci        case "${TERM:-}" in
618a8e1175bSopenharmony_ci            *color*|cygwin|linux|rxvt*|screen|[Eex]term*)
619a8e1175bSopenharmony_ci                start_red=$(printf '\033[31m')
620a8e1175bSopenharmony_ci                end_color=$(printf '\033[0m')
621a8e1175bSopenharmony_ci                ;;
622a8e1175bSopenharmony_ci        esac
623a8e1175bSopenharmony_ci    fi
624a8e1175bSopenharmony_ci
625a8e1175bSopenharmony_ci    # Keep a summary of failures in a file. We'll print it out at the end.
626a8e1175bSopenharmony_ci    failure_summary_file=$PWD/all-sh-failures-$$.log
627a8e1175bSopenharmony_ci    : >"$failure_summary_file"
628a8e1175bSopenharmony_ci
629a8e1175bSopenharmony_ci    # Whether it makes sense to keep a component going after the specified
630a8e1175bSopenharmony_ci    # command fails (test command) or not (configure or build).
631a8e1175bSopenharmony_ci    # This function normally receives the failing simple command
632a8e1175bSopenharmony_ci    # ($BASH_COMMAND) as an argument, but if $report_failed_command is set,
633a8e1175bSopenharmony_ci    # this is passed instead.
634a8e1175bSopenharmony_ci    # This doesn't have to be 100% accurate: all failures are recorded anyway.
635a8e1175bSopenharmony_ci    # False positives result in running things that can't be expected to
636a8e1175bSopenharmony_ci    # work. False negatives result in things not running after something else
637a8e1175bSopenharmony_ci    # failed even though they might have given useful feedback.
638a8e1175bSopenharmony_ci    can_keep_going_after_failure () {
639a8e1175bSopenharmony_ci        case "$1" in
640a8e1175bSopenharmony_ci            "msg "*) false;;
641a8e1175bSopenharmony_ci            "cd "*) false;;
642a8e1175bSopenharmony_ci            "diff "*) true;;
643a8e1175bSopenharmony_ci            *make*[\ /]tests*) false;; # make tests, make CFLAGS=-I../tests, ...
644a8e1175bSopenharmony_ci            *test*) true;; # make test, tests/stuff, env V=v tests/stuff, ...
645a8e1175bSopenharmony_ci            *make*check*) true;;
646a8e1175bSopenharmony_ci            "grep "*) true;;
647a8e1175bSopenharmony_ci            "[ "*) true;;
648a8e1175bSopenharmony_ci            "! "*) true;;
649a8e1175bSopenharmony_ci            *) false;;
650a8e1175bSopenharmony_ci        esac
651a8e1175bSopenharmony_ci    }
652a8e1175bSopenharmony_ci
653a8e1175bSopenharmony_ci    # This function runs if there is any error in a component.
654a8e1175bSopenharmony_ci    # It must either exit with a nonzero status, or set
655a8e1175bSopenharmony_ci    # last_failure_status to a nonzero value.
656a8e1175bSopenharmony_ci    err_trap () {
657a8e1175bSopenharmony_ci        # Save $? (status of the failing command). This must be the very
658a8e1175bSopenharmony_ci        # first thing, before $? is overridden.
659a8e1175bSopenharmony_ci        last_failure_status=$?
660a8e1175bSopenharmony_ci        failed_command=${report_failed_command-$BASH_COMMAND}
661a8e1175bSopenharmony_ci
662a8e1175bSopenharmony_ci        if [[ $last_failure_status -eq $previous_failure_status &&
663a8e1175bSopenharmony_ci              "$failed_command" == "$previous_failed_command" &&
664a8e1175bSopenharmony_ci              ${#FUNCNAME[@]} == $((previous_failure_funcall_depth - 1)) ]]
665a8e1175bSopenharmony_ci        then
666a8e1175bSopenharmony_ci            # The same command failed twice in a row, but this time one level
667a8e1175bSopenharmony_ci            # less deep in the function call stack. This happens when the last
668a8e1175bSopenharmony_ci            # command of a function returns a nonzero status, and the function
669a8e1175bSopenharmony_ci            # returns that same status. Ignore the second failure.
670a8e1175bSopenharmony_ci            previous_failure_funcall_depth=${#FUNCNAME[@]}
671a8e1175bSopenharmony_ci            return
672a8e1175bSopenharmony_ci        fi
673a8e1175bSopenharmony_ci        previous_failure_status=$last_failure_status
674a8e1175bSopenharmony_ci        previous_failed_command=$failed_command
675a8e1175bSopenharmony_ci        previous_failure_funcall_depth=${#FUNCNAME[@]}
676a8e1175bSopenharmony_ci
677a8e1175bSopenharmony_ci        text="$current_section: $failed_command -> $last_failure_status"
678a8e1175bSopenharmony_ci        echo "${start_red}^^^^$text^^^^${end_color}" >&2
679a8e1175bSopenharmony_ci        echo "$text" >>"$failure_summary_file"
680a8e1175bSopenharmony_ci
681a8e1175bSopenharmony_ci        # If the command is fatal (configure or build command), stop this
682a8e1175bSopenharmony_ci        # component. Otherwise (test command) keep the component running
683a8e1175bSopenharmony_ci        # (run more tests from the same build).
684a8e1175bSopenharmony_ci        if ! can_keep_going_after_failure "$failed_command"; then
685a8e1175bSopenharmony_ci            exit $last_failure_status
686a8e1175bSopenharmony_ci        fi
687a8e1175bSopenharmony_ci    }
688a8e1175bSopenharmony_ci
689a8e1175bSopenharmony_ci    final_report () {
690a8e1175bSopenharmony_ci        if [ $failure_count -gt 0 ]; then
691a8e1175bSopenharmony_ci            echo
692a8e1175bSopenharmony_ci            echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
693a8e1175bSopenharmony_ci            echo "${start_red}FAILED: $failure_count components${end_color}"
694a8e1175bSopenharmony_ci            cat "$failure_summary_file"
695a8e1175bSopenharmony_ci            echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
696a8e1175bSopenharmony_ci        elif [ -z "${1-}" ]; then
697a8e1175bSopenharmony_ci            echo "SUCCESS :)"
698a8e1175bSopenharmony_ci        fi
699a8e1175bSopenharmony_ci        if [ -n "${1-}" ]; then
700a8e1175bSopenharmony_ci            echo "Killed by SIG$1."
701a8e1175bSopenharmony_ci        fi
702a8e1175bSopenharmony_ci        rm -f "$failure_summary_file"
703a8e1175bSopenharmony_ci        if [ $failure_count -gt 0 ]; then
704a8e1175bSopenharmony_ci            exit 1
705a8e1175bSopenharmony_ci        fi
706a8e1175bSopenharmony_ci    }
707a8e1175bSopenharmony_ci}
708a8e1175bSopenharmony_ci
709a8e1175bSopenharmony_ci# record_status() and if_build_succeeded() are kept temporarily for backward
710a8e1175bSopenharmony_ci# compatibility. Don't use them in new components.
711a8e1175bSopenharmony_cirecord_status () {
712a8e1175bSopenharmony_ci    "$@"
713a8e1175bSopenharmony_ci}
714a8e1175bSopenharmony_ciif_build_succeeded () {
715a8e1175bSopenharmony_ci    "$@"
716a8e1175bSopenharmony_ci}
717a8e1175bSopenharmony_ci
718a8e1175bSopenharmony_ci# '! true' does not trigger the ERR trap. Arrange to trigger it, with
719a8e1175bSopenharmony_ci# a reasonably informative error message (not just "$@").
720a8e1175bSopenharmony_cinot () {
721a8e1175bSopenharmony_ci    if "$@"; then
722a8e1175bSopenharmony_ci        report_failed_command="! $*"
723a8e1175bSopenharmony_ci        false
724a8e1175bSopenharmony_ci        unset report_failed_command
725a8e1175bSopenharmony_ci    fi
726a8e1175bSopenharmony_ci}
727a8e1175bSopenharmony_ci
728a8e1175bSopenharmony_cipre_prepare_outcome_file () {
729a8e1175bSopenharmony_ci    case "$MBEDTLS_TEST_OUTCOME_FILE" in
730a8e1175bSopenharmony_ci      [!/]*) MBEDTLS_TEST_OUTCOME_FILE="$PWD/$MBEDTLS_TEST_OUTCOME_FILE";;
731a8e1175bSopenharmony_ci    esac
732a8e1175bSopenharmony_ci    if [ -n "$MBEDTLS_TEST_OUTCOME_FILE" ] && [ "$append_outcome" -eq 0 ]; then
733a8e1175bSopenharmony_ci        rm -f "$MBEDTLS_TEST_OUTCOME_FILE"
734a8e1175bSopenharmony_ci    fi
735a8e1175bSopenharmony_ci}
736a8e1175bSopenharmony_ci
737a8e1175bSopenharmony_cipre_print_configuration () {
738a8e1175bSopenharmony_ci    if [ $QUIET -eq 1 ]; then
739a8e1175bSopenharmony_ci        return
740a8e1175bSopenharmony_ci    fi
741a8e1175bSopenharmony_ci
742a8e1175bSopenharmony_ci    msg "info: $0 configuration"
743a8e1175bSopenharmony_ci    echo "MEMORY: $MEMORY"
744a8e1175bSopenharmony_ci    echo "FORCE: $FORCE"
745a8e1175bSopenharmony_ci    echo "MBEDTLS_TEST_OUTCOME_FILE: ${MBEDTLS_TEST_OUTCOME_FILE:-(none)}"
746a8e1175bSopenharmony_ci    echo "SEED: ${SEED-"UNSET"}"
747a8e1175bSopenharmony_ci    echo
748a8e1175bSopenharmony_ci    echo "OPENSSL: $OPENSSL"
749a8e1175bSopenharmony_ci    echo "OPENSSL_NEXT: $OPENSSL_NEXT"
750a8e1175bSopenharmony_ci    echo "GNUTLS_CLI: $GNUTLS_CLI"
751a8e1175bSopenharmony_ci    echo "GNUTLS_SERV: $GNUTLS_SERV"
752a8e1175bSopenharmony_ci    echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR"
753a8e1175bSopenharmony_ci    echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR"
754a8e1175bSopenharmony_ci}
755a8e1175bSopenharmony_ci
756a8e1175bSopenharmony_ci# Make sure the tools we need are available.
757a8e1175bSopenharmony_cipre_check_tools () {
758a8e1175bSopenharmony_ci    # Build the list of variables to pass to output_env.sh.
759a8e1175bSopenharmony_ci    set env
760a8e1175bSopenharmony_ci
761a8e1175bSopenharmony_ci    case " $RUN_COMPONENTS " in
762a8e1175bSopenharmony_ci        # Require OpenSSL and GnuTLS if running any tests (as opposed to
763a8e1175bSopenharmony_ci        # only doing builds). Not all tests run OpenSSL and GnuTLS, but this
764a8e1175bSopenharmony_ci        # is a good enough approximation in practice.
765a8e1175bSopenharmony_ci        *" test_"* | *" release_test_"*)
766a8e1175bSopenharmony_ci            # To avoid setting OpenSSL and GnuTLS for each call to compat.sh
767a8e1175bSopenharmony_ci            # and ssl-opt.sh, we just export the variables they require.
768a8e1175bSopenharmony_ci            export OPENSSL="$OPENSSL"
769a8e1175bSopenharmony_ci            export GNUTLS_CLI="$GNUTLS_CLI"
770a8e1175bSopenharmony_ci            export GNUTLS_SERV="$GNUTLS_SERV"
771a8e1175bSopenharmony_ci            # Avoid passing --seed flag in every call to ssl-opt.sh
772a8e1175bSopenharmony_ci            if [ -n "${SEED-}" ]; then
773a8e1175bSopenharmony_ci                export SEED
774a8e1175bSopenharmony_ci            fi
775a8e1175bSopenharmony_ci            set "$@" OPENSSL="$OPENSSL"
776a8e1175bSopenharmony_ci            set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV"
777a8e1175bSopenharmony_ci            check_tools "$OPENSSL" "$OPENSSL_NEXT" \
778a8e1175bSopenharmony_ci                        "$GNUTLS_CLI" "$GNUTLS_SERV"
779a8e1175bSopenharmony_ci            ;;
780a8e1175bSopenharmony_ci    esac
781a8e1175bSopenharmony_ci
782a8e1175bSopenharmony_ci    case " $RUN_COMPONENTS " in
783a8e1175bSopenharmony_ci        *_doxygen[_\ ]*) check_tools "doxygen" "dot";;
784a8e1175bSopenharmony_ci    esac
785a8e1175bSopenharmony_ci
786a8e1175bSopenharmony_ci    case " $RUN_COMPONENTS " in
787a8e1175bSopenharmony_ci        *_arm_none_eabi_gcc[_\ ]*) check_tools "${ARM_NONE_EABI_GCC_PREFIX}gcc";;
788a8e1175bSopenharmony_ci    esac
789a8e1175bSopenharmony_ci
790a8e1175bSopenharmony_ci    case " $RUN_COMPONENTS " in
791a8e1175bSopenharmony_ci        *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";;
792a8e1175bSopenharmony_ci    esac
793a8e1175bSopenharmony_ci
794a8e1175bSopenharmony_ci    case " $RUN_COMPONENTS " in
795a8e1175bSopenharmony_ci        *" test_zeroize "*) check_tools "gdb";;
796a8e1175bSopenharmony_ci    esac
797a8e1175bSopenharmony_ci
798a8e1175bSopenharmony_ci    case " $RUN_COMPONENTS " in
799a8e1175bSopenharmony_ci        *_armcc*)
800a8e1175bSopenharmony_ci            ARMC5_CC="$ARMC5_BIN_DIR/armcc"
801a8e1175bSopenharmony_ci            ARMC5_AR="$ARMC5_BIN_DIR/armar"
802a8e1175bSopenharmony_ci            ARMC5_FROMELF="$ARMC5_BIN_DIR/fromelf"
803a8e1175bSopenharmony_ci            ARMC6_CC="$ARMC6_BIN_DIR/armclang"
804a8e1175bSopenharmony_ci            ARMC6_AR="$ARMC6_BIN_DIR/armar"
805a8e1175bSopenharmony_ci            ARMC6_FROMELF="$ARMC6_BIN_DIR/fromelf"
806a8e1175bSopenharmony_ci            check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC5_FROMELF" \
807a8e1175bSopenharmony_ci                        "$ARMC6_CC" "$ARMC6_AR" "$ARMC6_FROMELF";;
808a8e1175bSopenharmony_ci    esac
809a8e1175bSopenharmony_ci
810a8e1175bSopenharmony_ci    # past this point, no call to check_tool, only printing output
811a8e1175bSopenharmony_ci    if [ $QUIET -eq 1 ]; then
812a8e1175bSopenharmony_ci        return
813a8e1175bSopenharmony_ci    fi
814a8e1175bSopenharmony_ci
815a8e1175bSopenharmony_ci    msg "info: output_env.sh"
816a8e1175bSopenharmony_ci    case $RUN_COMPONENTS in
817a8e1175bSopenharmony_ci        *_armcc*)
818a8e1175bSopenharmony_ci            set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;;
819a8e1175bSopenharmony_ci        *) set "$@" RUN_ARMCC=0;;
820a8e1175bSopenharmony_ci    esac
821a8e1175bSopenharmony_ci    "$@" scripts/output_env.sh
822a8e1175bSopenharmony_ci}
823a8e1175bSopenharmony_ci
824a8e1175bSopenharmony_cipre_generate_files() {
825a8e1175bSopenharmony_ci    # since make doesn't have proper dependencies, remove any possibly outdate
826a8e1175bSopenharmony_ci    # file that might be around before generating fresh ones
827a8e1175bSopenharmony_ci    make neat
828a8e1175bSopenharmony_ci    if [ $QUIET -eq 1 ]; then
829a8e1175bSopenharmony_ci        make generated_files >/dev/null
830a8e1175bSopenharmony_ci    else
831a8e1175bSopenharmony_ci        make generated_files
832a8e1175bSopenharmony_ci    fi
833a8e1175bSopenharmony_ci}
834a8e1175bSopenharmony_ci
835a8e1175bSopenharmony_ciclang_version() {
836a8e1175bSopenharmony_ci    if command -v clang > /dev/null ; then
837a8e1175bSopenharmony_ci        clang --version|grep version|sed -E 's#.*version ([0-9]+).*#\1#'
838a8e1175bSopenharmony_ci    else
839a8e1175bSopenharmony_ci        echo 0  # report version 0 for "no clang"
840a8e1175bSopenharmony_ci    fi
841a8e1175bSopenharmony_ci}
842a8e1175bSopenharmony_ci
843a8e1175bSopenharmony_ci################################################################
844a8e1175bSopenharmony_ci#### Helpers for components using libtestdriver1
845a8e1175bSopenharmony_ci################################################################
846a8e1175bSopenharmony_ci
847a8e1175bSopenharmony_ci# How to use libtestdriver1
848a8e1175bSopenharmony_ci# -------------------------
849a8e1175bSopenharmony_ci#
850a8e1175bSopenharmony_ci# 1. Define the list algorithms and key types to accelerate,
851a8e1175bSopenharmony_ci#    designated the same way as PSA_WANT_ macros but without PSA_WANT_.
852a8e1175bSopenharmony_ci#    Examples:
853a8e1175bSopenharmony_ci#      - loc_accel_list="ALG_JPAKE"
854a8e1175bSopenharmony_ci#      - loc_accel_list="ALG_FFDH KEY_TYPE_DH_KEY_PAIR KEY_TYPE_DH_PUBLIC_KEY"
855a8e1175bSopenharmony_ci# 2. Make configurations changes for the driver and/or main libraries.
856a8e1175bSopenharmony_ci#    2a. Call helper_libtestdriver1_adjust_config <base>, where the argument
857a8e1175bSopenharmony_ci#        can be either "default" to start with the default config, or a name
858a8e1175bSopenharmony_ci#        supported by scripts/config.py (for example, "full"). This selects
859a8e1175bSopenharmony_ci#        the base to use, and makes common adjustments.
860a8e1175bSopenharmony_ci#    2b. If desired, adjust the PSA_WANT symbols in psa/crypto_config.h.
861a8e1175bSopenharmony_ci#        These changes affect both the driver and the main libraries.
862a8e1175bSopenharmony_ci#        (Note: they need to have the same set of PSA_WANT symbols, as that
863a8e1175bSopenharmony_ci#        determines the ABI between them.)
864a8e1175bSopenharmony_ci#    2c. Adjust MBEDTLS_ symbols in mbedtls_config.h. This only affects the
865a8e1175bSopenharmony_ci#        main libraries. Typically, you want to disable the module(s) that are
866a8e1175bSopenharmony_ci#        being accelerated. You may need to also disable modules that depend
867a8e1175bSopenharmony_ci#        on them or options that are not supported with drivers.
868a8e1175bSopenharmony_ci#    2d. On top of psa/crypto_config.h, the driver library uses its own config
869a8e1175bSopenharmony_ci#        file: tests/include/test/drivers/config_test_driver.h. You usually
870a8e1175bSopenharmony_ci#        don't need to edit it: using loc_extra_list (see below) is preferred.
871a8e1175bSopenharmony_ci#        However, when there's no PSA symbol for what you want to enable,
872a8e1175bSopenharmony_ci#        calling scripts/config.py on this file remains the only option.
873a8e1175bSopenharmony_ci# 3. Build the driver library, then the main libraries, test, and programs.
874a8e1175bSopenharmony_ci#    3a. Call helper_libtestdriver1_make_drivers "$loc_accel_list". You may
875a8e1175bSopenharmony_ci#        need to enable more algorithms here, typically hash algorithms when
876a8e1175bSopenharmony_ci#        accelerating some signature algorithms (ECDSA, RSAv2). This is done
877a8e1175bSopenharmony_ci#        by passing a 2nd argument listing the extra algorithms.
878a8e1175bSopenharmony_ci#        Example:
879a8e1175bSopenharmony_ci#          loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512"
880a8e1175bSopenharmony_ci#          helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
881a8e1175bSopenharmony_ci#    3b. Call helper_libtestdriver1_make_main "$loc_accel_list". Any
882a8e1175bSopenharmony_ci#        additional arguments will be passed to make: this can be useful if
883a8e1175bSopenharmony_ci#        you don't want to build everything when iterating during development.
884a8e1175bSopenharmony_ci#        Example:
885a8e1175bSopenharmony_ci#          helper_libtestdriver1_make_main "$loc_accel_list" -C tests test_suite_foo
886a8e1175bSopenharmony_ci# 4. Run the tests you want.
887a8e1175bSopenharmony_ci
888a8e1175bSopenharmony_ci# Adjust the configuration - for both libtestdriver1 and main library,
889a8e1175bSopenharmony_ci# as they should have the same PSA_WANT macros.
890a8e1175bSopenharmony_cihelper_libtestdriver1_adjust_config() {
891a8e1175bSopenharmony_ci    base_config=$1
892a8e1175bSopenharmony_ci    # Select the base configuration
893a8e1175bSopenharmony_ci    if [ "$base_config" != "default" ]; then
894a8e1175bSopenharmony_ci        scripts/config.py "$base_config"
895a8e1175bSopenharmony_ci    fi
896a8e1175bSopenharmony_ci
897a8e1175bSopenharmony_ci    # Enable PSA-based config (necessary to use drivers)
898a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
899a8e1175bSopenharmony_ci
900a8e1175bSopenharmony_ci    # Dynamic secure element support is a deprecated feature and needs to be disabled here.
901a8e1175bSopenharmony_ci    # This is done to have the same form of psa_key_attributes_s for libdriver and library.
902a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
903a8e1175bSopenharmony_ci
904a8e1175bSopenharmony_ci    # If threading is enabled on the normal build, then we need to enable it in the drivers as well,
905a8e1175bSopenharmony_ci    # otherwise we will end up running multithreaded tests without mutexes to protect them.
906a8e1175bSopenharmony_ci    if scripts/config.py get MBEDTLS_THREADING_C; then
907a8e1175bSopenharmony_ci        scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_THREADING_C
908a8e1175bSopenharmony_ci    fi
909a8e1175bSopenharmony_ci
910a8e1175bSopenharmony_ci    if scripts/config.py get MBEDTLS_THREADING_PTHREAD; then
911a8e1175bSopenharmony_ci        scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_THREADING_PTHREAD
912a8e1175bSopenharmony_ci    fi
913a8e1175bSopenharmony_ci}
914a8e1175bSopenharmony_ci
915a8e1175bSopenharmony_ci# When called with no parameter this function disables all builtin curves.
916a8e1175bSopenharmony_ci# The function optionally accepts 1 parameter: a space-separated list of the
917a8e1175bSopenharmony_ci# curves that should be kept enabled.
918a8e1175bSopenharmony_cihelper_disable_builtin_curves() {
919a8e1175bSopenharmony_ci    allowed_list="${1:-}"
920a8e1175bSopenharmony_ci    scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
921a8e1175bSopenharmony_ci
922a8e1175bSopenharmony_ci    for curve in $allowed_list; do
923a8e1175bSopenharmony_ci        scripts/config.py set $curve
924a8e1175bSopenharmony_ci    done
925a8e1175bSopenharmony_ci}
926a8e1175bSopenharmony_ci
927a8e1175bSopenharmony_ci# Helper returning the list of supported elliptic curves from CRYPTO_CONFIG_H,
928a8e1175bSopenharmony_ci# without the "PSA_WANT_" prefix. This becomes handy for accelerating curves
929a8e1175bSopenharmony_ci# in the following helpers.
930a8e1175bSopenharmony_cihelper_get_psa_curve_list () {
931a8e1175bSopenharmony_ci    loc_list=""
932a8e1175bSopenharmony_ci    for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
933a8e1175bSopenharmony_ci        loc_list="$loc_list $item"
934a8e1175bSopenharmony_ci    done
935a8e1175bSopenharmony_ci
936a8e1175bSopenharmony_ci    echo "$loc_list"
937a8e1175bSopenharmony_ci}
938a8e1175bSopenharmony_ci
939a8e1175bSopenharmony_ci# Helper returning the list of supported DH groups from CRYPTO_CONFIG_H,
940a8e1175bSopenharmony_ci# without the "PSA_WANT_" prefix. This becomes handy for accelerating DH groups
941a8e1175bSopenharmony_ci# in the following helpers.
942a8e1175bSopenharmony_cihelper_get_psa_dh_group_list () {
943a8e1175bSopenharmony_ci    loc_list=""
944a8e1175bSopenharmony_ci    for item in $(sed -n 's/^#define PSA_WANT_\(DH_RFC7919_[0-9]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
945a8e1175bSopenharmony_ci        loc_list="$loc_list $item"
946a8e1175bSopenharmony_ci    done
947a8e1175bSopenharmony_ci
948a8e1175bSopenharmony_ci    echo "$loc_list"
949a8e1175bSopenharmony_ci}
950a8e1175bSopenharmony_ci
951a8e1175bSopenharmony_ci# Get the list of uncommented PSA_WANT_KEY_TYPE_xxx_ from CRYPTO_CONFIG_H. This
952a8e1175bSopenharmony_ci# is useful to easily get a list of key type symbols to accelerate.
953a8e1175bSopenharmony_ci# The function accepts a single argument which is the key type: ECC, DH, RSA.
954a8e1175bSopenharmony_cihelper_get_psa_key_type_list() {
955a8e1175bSopenharmony_ci    key_type="$1"
956a8e1175bSopenharmony_ci    loc_list=""
957a8e1175bSopenharmony_ci    for item in $(sed -n "s/^#define PSA_WANT_\(KEY_TYPE_${key_type}_[0-9A-Z_a-z]*\).*/\1/p" <"$CRYPTO_CONFIG_H"); do
958a8e1175bSopenharmony_ci        # Skip DERIVE for elliptic keys since there is no driver dispatch for
959a8e1175bSopenharmony_ci        # it so it cannot be accelerated.
960a8e1175bSopenharmony_ci        if [ "$item" != "KEY_TYPE_ECC_KEY_PAIR_DERIVE" ]; then
961a8e1175bSopenharmony_ci            loc_list="$loc_list $item"
962a8e1175bSopenharmony_ci        fi
963a8e1175bSopenharmony_ci    done
964a8e1175bSopenharmony_ci
965a8e1175bSopenharmony_ci    echo "$loc_list"
966a8e1175bSopenharmony_ci}
967a8e1175bSopenharmony_ci
968a8e1175bSopenharmony_ci# Build the drivers library libtestdriver1.a (with ASan).
969a8e1175bSopenharmony_ci#
970a8e1175bSopenharmony_ci# Parameters:
971a8e1175bSopenharmony_ci# 1. a space-separated list of things to accelerate;
972a8e1175bSopenharmony_ci# 2. optional: a space-separate list of things to also support.
973a8e1175bSopenharmony_ci# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
974a8e1175bSopenharmony_cihelper_libtestdriver1_make_drivers() {
975a8e1175bSopenharmony_ci    loc_accel_flags=$( echo "$1 ${2-}" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
976a8e1175bSopenharmony_ci    make CC=$ASAN_CC -C tests libtestdriver1.a CFLAGS=" $ASAN_CFLAGS $loc_accel_flags" LDFLAGS="$ASAN_CFLAGS"
977a8e1175bSopenharmony_ci}
978a8e1175bSopenharmony_ci
979a8e1175bSopenharmony_ci# Build the main libraries, programs and tests,
980a8e1175bSopenharmony_ci# linking to the drivers library (with ASan).
981a8e1175bSopenharmony_ci#
982a8e1175bSopenharmony_ci# Parameters:
983a8e1175bSopenharmony_ci# 1. a space-separated list of things to accelerate;
984a8e1175bSopenharmony_ci# *. remaining arguments if any are passed directly to make
985a8e1175bSopenharmony_ci#    (examples: lib, -C tests test_suite_xxx, etc.)
986a8e1175bSopenharmony_ci# Here "things" are PSA_WANT_ symbols but with PSA_WANT_ removed.
987a8e1175bSopenharmony_cihelper_libtestdriver1_make_main() {
988a8e1175bSopenharmony_ci    loc_accel_list=$1
989a8e1175bSopenharmony_ci    shift
990a8e1175bSopenharmony_ci
991a8e1175bSopenharmony_ci    # we need flags both with and without the LIBTESTDRIVER1_ prefix
992a8e1175bSopenharmony_ci    loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' )
993a8e1175bSopenharmony_ci    loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )"
994a8e1175bSopenharmony_ci    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" "$@"
995a8e1175bSopenharmony_ci}
996a8e1175bSopenharmony_ci
997a8e1175bSopenharmony_ci################################################################
998a8e1175bSopenharmony_ci#### Basic checks
999a8e1175bSopenharmony_ci################################################################
1000a8e1175bSopenharmony_ci
1001a8e1175bSopenharmony_ci#
1002a8e1175bSopenharmony_ci# Test Suites to be executed
1003a8e1175bSopenharmony_ci#
1004a8e1175bSopenharmony_ci# The test ordering tries to optimize for the following criteria:
1005a8e1175bSopenharmony_ci# 1. Catch possible problems early, by running first tests that run quickly
1006a8e1175bSopenharmony_ci#    and/or are more likely to fail than others (eg I use Clang most of the
1007a8e1175bSopenharmony_ci#    time, so start with a GCC build).
1008a8e1175bSopenharmony_ci# 2. Minimize total running time, by avoiding useless rebuilds
1009a8e1175bSopenharmony_ci#
1010a8e1175bSopenharmony_ci# Indicative running times are given for reference.
1011a8e1175bSopenharmony_ci
1012a8e1175bSopenharmony_cicomponent_check_recursion () {
1013a8e1175bSopenharmony_ci    msg "Check: recursion.pl" # < 1s
1014a8e1175bSopenharmony_ci    tests/scripts/recursion.pl library/*.c
1015a8e1175bSopenharmony_ci}
1016a8e1175bSopenharmony_ci
1017a8e1175bSopenharmony_cicomponent_check_generated_files () {
1018a8e1175bSopenharmony_ci    msg "Check: check-generated-files, files generated with make" # 2s
1019a8e1175bSopenharmony_ci    make generated_files
1020a8e1175bSopenharmony_ci    tests/scripts/check-generated-files.sh
1021a8e1175bSopenharmony_ci
1022a8e1175bSopenharmony_ci    msg "Check: check-generated-files -u, files present" # 2s
1023a8e1175bSopenharmony_ci    tests/scripts/check-generated-files.sh -u
1024a8e1175bSopenharmony_ci    # Check that the generated files are considered up to date.
1025a8e1175bSopenharmony_ci    tests/scripts/check-generated-files.sh
1026a8e1175bSopenharmony_ci
1027a8e1175bSopenharmony_ci    msg "Check: check-generated-files -u, files absent" # 2s
1028a8e1175bSopenharmony_ci    command make neat
1029a8e1175bSopenharmony_ci    tests/scripts/check-generated-files.sh -u
1030a8e1175bSopenharmony_ci    # Check that the generated files are considered up to date.
1031a8e1175bSopenharmony_ci    tests/scripts/check-generated-files.sh
1032a8e1175bSopenharmony_ci
1033a8e1175bSopenharmony_ci    # This component ends with the generated files present in the source tree.
1034a8e1175bSopenharmony_ci    # This is necessary for subsequent components!
1035a8e1175bSopenharmony_ci}
1036a8e1175bSopenharmony_ci
1037a8e1175bSopenharmony_cicomponent_check_doxy_blocks () {
1038a8e1175bSopenharmony_ci    msg "Check: doxygen markup outside doxygen blocks" # < 1s
1039a8e1175bSopenharmony_ci    tests/scripts/check-doxy-blocks.pl
1040a8e1175bSopenharmony_ci}
1041a8e1175bSopenharmony_ci
1042a8e1175bSopenharmony_cicomponent_check_files () {
1043a8e1175bSopenharmony_ci    msg "Check: file sanity checks (permissions, encodings)" # < 1s
1044a8e1175bSopenharmony_ci    tests/scripts/check_files.py
1045a8e1175bSopenharmony_ci}
1046a8e1175bSopenharmony_ci
1047a8e1175bSopenharmony_cicomponent_check_changelog () {
1048a8e1175bSopenharmony_ci    msg "Check: changelog entries" # < 1s
1049a8e1175bSopenharmony_ci    rm -f ChangeLog.new
1050a8e1175bSopenharmony_ci    scripts/assemble_changelog.py -o ChangeLog.new
1051a8e1175bSopenharmony_ci    if [ -e ChangeLog.new ]; then
1052a8e1175bSopenharmony_ci        # Show the diff for information. It isn't an error if the diff is
1053a8e1175bSopenharmony_ci        # non-empty.
1054a8e1175bSopenharmony_ci        diff -u ChangeLog ChangeLog.new || true
1055a8e1175bSopenharmony_ci        rm ChangeLog.new
1056a8e1175bSopenharmony_ci    fi
1057a8e1175bSopenharmony_ci}
1058a8e1175bSopenharmony_ci
1059a8e1175bSopenharmony_cicomponent_check_names () {
1060a8e1175bSopenharmony_ci    msg "Check: declared and exported names (builds the library)" # < 3s
1061a8e1175bSopenharmony_ci    tests/scripts/check_names.py -v
1062a8e1175bSopenharmony_ci}
1063a8e1175bSopenharmony_ci
1064a8e1175bSopenharmony_cicomponent_check_test_cases () {
1065a8e1175bSopenharmony_ci    msg "Check: test case descriptions" # < 1s
1066a8e1175bSopenharmony_ci    if [ $QUIET -eq 1 ]; then
1067a8e1175bSopenharmony_ci        opt='--quiet'
1068a8e1175bSopenharmony_ci    else
1069a8e1175bSopenharmony_ci        opt=''
1070a8e1175bSopenharmony_ci    fi
1071a8e1175bSopenharmony_ci    tests/scripts/check_test_cases.py -q $opt
1072a8e1175bSopenharmony_ci    unset opt
1073a8e1175bSopenharmony_ci}
1074a8e1175bSopenharmony_ci
1075a8e1175bSopenharmony_cicomponent_check_test_dependencies () {
1076a8e1175bSopenharmony_ci    msg "Check: test case dependencies: legacy vs PSA" # < 1s
1077a8e1175bSopenharmony_ci    # The purpose of this component is to catch unjustified dependencies on
1078a8e1175bSopenharmony_ci    # legacy feature macros (MBEDTLS_xxx) in PSA tests. Generally speaking,
1079a8e1175bSopenharmony_ci    # PSA test should use PSA feature macros (PSA_WANT_xxx, more rarely
1080a8e1175bSopenharmony_ci    # MBEDTLS_PSA_xxx).
1081a8e1175bSopenharmony_ci    #
1082a8e1175bSopenharmony_ci    # Most of the time, use of legacy MBEDTLS_xxx macros are mistakes, which
1083a8e1175bSopenharmony_ci    # this component is meant to catch. However a few of them are justified,
1084a8e1175bSopenharmony_ci    # mostly by the absence of a PSA equivalent, so this component includes a
1085a8e1175bSopenharmony_ci    # list of expected exceptions.
1086a8e1175bSopenharmony_ci
1087a8e1175bSopenharmony_ci    found="check-test-deps-found-$$"
1088a8e1175bSopenharmony_ci    expected="check-test-deps-expected-$$"
1089a8e1175bSopenharmony_ci
1090a8e1175bSopenharmony_ci    # Find legacy dependencies in PSA tests
1091a8e1175bSopenharmony_ci    grep 'depends_on' \
1092a8e1175bSopenharmony_ci        tests/suites/test_suite_psa*.data tests/suites/test_suite_psa*.function |
1093a8e1175bSopenharmony_ci        grep -Eo '!?MBEDTLS_[^: ]*' |
1094a8e1175bSopenharmony_ci        grep -v -e MBEDTLS_PSA_ -e MBEDTLS_TEST_ |
1095a8e1175bSopenharmony_ci        sort -u > $found
1096a8e1175bSopenharmony_ci
1097a8e1175bSopenharmony_ci    # Expected ones with justification - keep in sorted order by ASCII table!
1098a8e1175bSopenharmony_ci    rm -f $expected
1099a8e1175bSopenharmony_ci    # No PSA equivalent - WANT_KEY_TYPE_AES means all sizes
1100a8e1175bSopenharmony_ci    echo "!MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH" >> $expected
1101a8e1175bSopenharmony_ci    # No PSA equivalent - used to skip decryption tests in PSA-ECB, CBC/XTS/NIST_KW/DES
1102a8e1175bSopenharmony_ci    echo "!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT" >> $expected
1103a8e1175bSopenharmony_ci    # MBEDTLS_ASN1_WRITE_C is used by import_rsa_made_up() in test_suite_psa_crypto
1104a8e1175bSopenharmony_ci    # in order to build a fake RSA key of the wanted size based on
1105a8e1175bSopenharmony_ci    # PSA_VENDOR_RSA_MAX_KEY_BITS. The legacy module is only used by
1106a8e1175bSopenharmony_ci    # the test code and that's probably the most convenient way of achieving
1107a8e1175bSopenharmony_ci    # the test's goal.
1108a8e1175bSopenharmony_ci    echo "MBEDTLS_ASN1_WRITE_C" >> $expected
1109a8e1175bSopenharmony_ci    # No PSA equivalent - we should probably have one in the future.
1110a8e1175bSopenharmony_ci    echo "MBEDTLS_ECP_RESTARTABLE" >> $expected
1111a8e1175bSopenharmony_ci    # No PSA equivalent - needed by some init tests
1112a8e1175bSopenharmony_ci    echo "MBEDTLS_ENTROPY_NV_SEED" >> $expected
1113a8e1175bSopenharmony_ci    # No PSA equivalent - required to run threaded tests.
1114a8e1175bSopenharmony_ci    echo "MBEDTLS_THREADING_PTHREAD" >> $expected
1115a8e1175bSopenharmony_ci
1116a8e1175bSopenharmony_ci    # Compare reality with expectation.
1117a8e1175bSopenharmony_ci    # We want an exact match, to ensure the above list remains up-to-date.
1118a8e1175bSopenharmony_ci    #
1119a8e1175bSopenharmony_ci    # The output should be empty. When it's not:
1120a8e1175bSopenharmony_ci    # - Each '+' line is a macro that was found but not expected. You want to
1121a8e1175bSopenharmony_ci    # find where that macro occurs, and either replace it with PSA macros, or
1122a8e1175bSopenharmony_ci    # add it to the exceptions list above with a justification.
1123a8e1175bSopenharmony_ci    # - Each '-' line is a macro that was expected but not found; it means the
1124a8e1175bSopenharmony_ci    # exceptions list above should be updated by removing that macro.
1125a8e1175bSopenharmony_ci    diff -U0 $expected $found
1126a8e1175bSopenharmony_ci
1127a8e1175bSopenharmony_ci    rm $found $expected
1128a8e1175bSopenharmony_ci}
1129a8e1175bSopenharmony_ci
1130a8e1175bSopenharmony_cicomponent_check_doxygen_warnings () {
1131a8e1175bSopenharmony_ci    msg "Check: doxygen warnings (builds the documentation)" # ~ 3s
1132a8e1175bSopenharmony_ci    tests/scripts/doxygen.sh
1133a8e1175bSopenharmony_ci}
1134a8e1175bSopenharmony_ci
1135a8e1175bSopenharmony_ci
1136a8e1175bSopenharmony_ci
1137a8e1175bSopenharmony_ci################################################################
1138a8e1175bSopenharmony_ci#### Build and test many configurations and targets
1139a8e1175bSopenharmony_ci################################################################
1140a8e1175bSopenharmony_ci
1141a8e1175bSopenharmony_cicomponent_test_default_out_of_box () {
1142a8e1175bSopenharmony_ci    msg "build: make, default config (out-of-box)" # ~1min
1143a8e1175bSopenharmony_ci    make
1144a8e1175bSopenharmony_ci    # Disable fancy stuff
1145a8e1175bSopenharmony_ci    unset MBEDTLS_TEST_OUTCOME_FILE
1146a8e1175bSopenharmony_ci
1147a8e1175bSopenharmony_ci    msg "test: main suites make, default config (out-of-box)" # ~10s
1148a8e1175bSopenharmony_ci    make test
1149a8e1175bSopenharmony_ci
1150a8e1175bSopenharmony_ci    msg "selftest: make, default config (out-of-box)" # ~10s
1151a8e1175bSopenharmony_ci    programs/test/selftest
1152a8e1175bSopenharmony_ci
1153a8e1175bSopenharmony_ci    msg "program demos: make, default config (out-of-box)" # ~10s
1154a8e1175bSopenharmony_ci    tests/scripts/run_demos.py
1155a8e1175bSopenharmony_ci}
1156a8e1175bSopenharmony_ci
1157a8e1175bSopenharmony_cicomponent_test_default_cmake_gcc_asan () {
1158a8e1175bSopenharmony_ci    msg "build: cmake, gcc, ASan" # ~ 1 min 50s
1159a8e1175bSopenharmony_ci    CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1160a8e1175bSopenharmony_ci    make
1161a8e1175bSopenharmony_ci
1162a8e1175bSopenharmony_ci    msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
1163a8e1175bSopenharmony_ci    make test
1164a8e1175bSopenharmony_ci
1165a8e1175bSopenharmony_ci    msg "program demos (ASan build)" # ~10s
1166a8e1175bSopenharmony_ci    tests/scripts/run_demos.py
1167a8e1175bSopenharmony_ci
1168a8e1175bSopenharmony_ci    msg "test: selftest (ASan build)" # ~ 10s
1169a8e1175bSopenharmony_ci    programs/test/selftest
1170a8e1175bSopenharmony_ci
1171a8e1175bSopenharmony_ci    msg "test: metatests (GCC, ASan build)"
1172a8e1175bSopenharmony_ci    tests/scripts/run-metatests.sh any asan poison
1173a8e1175bSopenharmony_ci
1174a8e1175bSopenharmony_ci    msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
1175a8e1175bSopenharmony_ci    tests/ssl-opt.sh
1176a8e1175bSopenharmony_ci
1177a8e1175bSopenharmony_ci    msg "test: compat.sh (ASan build)" # ~ 6 min
1178a8e1175bSopenharmony_ci    tests/compat.sh
1179a8e1175bSopenharmony_ci
1180a8e1175bSopenharmony_ci    msg "test: context-info.sh (ASan build)" # ~ 15 sec
1181a8e1175bSopenharmony_ci    tests/context-info.sh
1182a8e1175bSopenharmony_ci}
1183a8e1175bSopenharmony_ci
1184a8e1175bSopenharmony_cicomponent_test_default_cmake_gcc_asan_new_bignum () {
1185a8e1175bSopenharmony_ci    msg "build: cmake, gcc, ASan" # ~ 1 min 50s
1186a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
1187a8e1175bSopenharmony_ci    CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1188a8e1175bSopenharmony_ci    make
1189a8e1175bSopenharmony_ci
1190a8e1175bSopenharmony_ci    msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s
1191a8e1175bSopenharmony_ci    make test
1192a8e1175bSopenharmony_ci
1193a8e1175bSopenharmony_ci    msg "test: selftest (ASan build)" # ~ 10s
1194a8e1175bSopenharmony_ci    programs/test/selftest
1195a8e1175bSopenharmony_ci
1196a8e1175bSopenharmony_ci    msg "test: ssl-opt.sh (ASan build)" # ~ 1 min
1197a8e1175bSopenharmony_ci    tests/ssl-opt.sh
1198a8e1175bSopenharmony_ci
1199a8e1175bSopenharmony_ci    msg "test: compat.sh (ASan build)" # ~ 6 min
1200a8e1175bSopenharmony_ci    tests/compat.sh
1201a8e1175bSopenharmony_ci
1202a8e1175bSopenharmony_ci    msg "test: context-info.sh (ASan build)" # ~ 15 sec
1203a8e1175bSopenharmony_ci    tests/context-info.sh
1204a8e1175bSopenharmony_ci}
1205a8e1175bSopenharmony_ci
1206a8e1175bSopenharmony_cicomponent_test_full_cmake_gcc_asan () {
1207a8e1175bSopenharmony_ci    msg "build: full config, cmake, gcc, ASan"
1208a8e1175bSopenharmony_ci    scripts/config.py full
1209a8e1175bSopenharmony_ci    CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1210a8e1175bSopenharmony_ci    make
1211a8e1175bSopenharmony_ci
1212a8e1175bSopenharmony_ci    msg "test: main suites (inc. selftests) (full config, ASan build)"
1213a8e1175bSopenharmony_ci    make test
1214a8e1175bSopenharmony_ci
1215a8e1175bSopenharmony_ci    msg "test: selftest (ASan build)" # ~ 10s
1216a8e1175bSopenharmony_ci    programs/test/selftest
1217a8e1175bSopenharmony_ci
1218a8e1175bSopenharmony_ci    msg "test: ssl-opt.sh (full config, ASan build)"
1219a8e1175bSopenharmony_ci    tests/ssl-opt.sh
1220a8e1175bSopenharmony_ci
1221a8e1175bSopenharmony_ci    msg "test: compat.sh (full config, ASan build)"
1222a8e1175bSopenharmony_ci    tests/compat.sh
1223a8e1175bSopenharmony_ci
1224a8e1175bSopenharmony_ci    msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
1225a8e1175bSopenharmony_ci    tests/context-info.sh
1226a8e1175bSopenharmony_ci}
1227a8e1175bSopenharmony_ci
1228a8e1175bSopenharmony_ci
1229a8e1175bSopenharmony_cicomponent_test_full_cmake_gcc_asan_new_bignum () {
1230a8e1175bSopenharmony_ci    msg "build: full config, cmake, gcc, ASan"
1231a8e1175bSopenharmony_ci    scripts/config.py full
1232a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
1233a8e1175bSopenharmony_ci    CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1234a8e1175bSopenharmony_ci    make
1235a8e1175bSopenharmony_ci
1236a8e1175bSopenharmony_ci    msg "test: main suites (inc. selftests) (full config, ASan build)"
1237a8e1175bSopenharmony_ci    make test
1238a8e1175bSopenharmony_ci
1239a8e1175bSopenharmony_ci    msg "test: selftest (ASan build)" # ~ 10s
1240a8e1175bSopenharmony_ci    programs/test/selftest
1241a8e1175bSopenharmony_ci
1242a8e1175bSopenharmony_ci    msg "test: ssl-opt.sh (full config, ASan build)"
1243a8e1175bSopenharmony_ci    tests/ssl-opt.sh
1244a8e1175bSopenharmony_ci
1245a8e1175bSopenharmony_ci    msg "test: compat.sh (full config, ASan build)"
1246a8e1175bSopenharmony_ci    tests/compat.sh
1247a8e1175bSopenharmony_ci
1248a8e1175bSopenharmony_ci    msg "test: context-info.sh (full config, ASan build)" # ~ 15 sec
1249a8e1175bSopenharmony_ci    tests/context-info.sh
1250a8e1175bSopenharmony_ci}
1251a8e1175bSopenharmony_ci
1252a8e1175bSopenharmony_cicomponent_test_psa_crypto_key_id_encodes_owner () {
1253a8e1175bSopenharmony_ci    msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
1254a8e1175bSopenharmony_ci    scripts/config.py full
1255a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1256a8e1175bSopenharmony_ci    CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1257a8e1175bSopenharmony_ci    make
1258a8e1175bSopenharmony_ci
1259a8e1175bSopenharmony_ci    msg "test: full config - USE_PSA_CRYPTO + PSA_CRYPTO_KEY_ID_ENCODES_OWNER, cmake, gcc, ASan"
1260a8e1175bSopenharmony_ci    make test
1261a8e1175bSopenharmony_ci}
1262a8e1175bSopenharmony_ci
1263a8e1175bSopenharmony_cicomponent_test_psa_assume_exclusive_buffers () {
1264a8e1175bSopenharmony_ci    msg "build: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
1265a8e1175bSopenharmony_ci    scripts/config.py full
1266a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS
1267a8e1175bSopenharmony_ci    CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
1268a8e1175bSopenharmony_ci    make
1269a8e1175bSopenharmony_ci
1270a8e1175bSopenharmony_ci    msg "test: full config + MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS, cmake, gcc, ASan"
1271a8e1175bSopenharmony_ci    make test
1272a8e1175bSopenharmony_ci}
1273a8e1175bSopenharmony_ci
1274a8e1175bSopenharmony_ci# check_renamed_symbols HEADER LIB
1275a8e1175bSopenharmony_ci# Check that if HEADER contains '#define MACRO ...' then MACRO is not a symbol
1276a8e1175bSopenharmony_ci# name is LIB.
1277a8e1175bSopenharmony_cicheck_renamed_symbols () {
1278a8e1175bSopenharmony_ci    ! nm "$2" | sed 's/.* //' |
1279a8e1175bSopenharmony_ci      grep -x -F "$(sed -n 's/^ *# *define  *\([A-Z_a-z][0-9A-Z_a-z]*\)..*/\1/p' "$1")"
1280a8e1175bSopenharmony_ci}
1281a8e1175bSopenharmony_ci
1282a8e1175bSopenharmony_cicomponent_build_psa_crypto_spm () {
1283a8e1175bSopenharmony_ci    msg "build: full config + PSA_CRYPTO_KEY_ID_ENCODES_OWNER + PSA_CRYPTO_SPM, make, gcc"
1284a8e1175bSopenharmony_ci    scripts/config.py full
1285a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
1286a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
1287a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PSA_CRYPTO_SPM
1288a8e1175bSopenharmony_ci    # We can only compile, not link, since our test and sample programs
1289a8e1175bSopenharmony_ci    # aren't equipped for the modified names used when MBEDTLS_PSA_CRYPTO_SPM
1290a8e1175bSopenharmony_ci    # is active.
1291a8e1175bSopenharmony_ci    make CC=gcc CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' lib
1292a8e1175bSopenharmony_ci
1293a8e1175bSopenharmony_ci    # Check that if a symbol is renamed by crypto_spe.h, the non-renamed
1294a8e1175bSopenharmony_ci    # version is not present.
1295a8e1175bSopenharmony_ci    echo "Checking for renamed symbols in the library"
1296a8e1175bSopenharmony_ci    check_renamed_symbols tests/include/spe/crypto_spe.h library/libmbedcrypto.a
1297a8e1175bSopenharmony_ci}
1298a8e1175bSopenharmony_ci
1299a8e1175bSopenharmony_ci# Get a list of library-wise undefined symbols and ensure that they only
1300a8e1175bSopenharmony_ci# belong to psa_xxx() functions and not to mbedtls_yyy() ones.
1301a8e1175bSopenharmony_ci# This function is a common helper used by both:
1302a8e1175bSopenharmony_ci# - component_test_default_psa_crypto_client_without_crypto_provider
1303a8e1175bSopenharmony_ci# - component_build_full_psa_crypto_client_without_crypto_provider.
1304a8e1175bSopenharmony_cicommon_check_mbedtls_missing_symbols() {
1305a8e1175bSopenharmony_ci    nm library/libmbedcrypto.a | grep ' [TRrDC] ' | grep -Eo '(mbedtls_|psa_).*' | sort -u > sym_def.txt
1306a8e1175bSopenharmony_ci    nm library/libmbedcrypto.a | grep ' U ' | grep -Eo '(mbedtls_|psa_).*' | sort -u > sym_undef.txt
1307a8e1175bSopenharmony_ci    comm sym_def.txt sym_undef.txt -13 > linking_errors.txt
1308a8e1175bSopenharmony_ci    not grep mbedtls_ linking_errors.txt
1309a8e1175bSopenharmony_ci
1310a8e1175bSopenharmony_ci    rm sym_def.txt sym_undef.txt linking_errors.txt
1311a8e1175bSopenharmony_ci}
1312a8e1175bSopenharmony_ci
1313a8e1175bSopenharmony_cicomponent_test_default_psa_crypto_client_without_crypto_provider () {
1314a8e1175bSopenharmony_ci    msg "build: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
1315a8e1175bSopenharmony_ci
1316a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1317a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1318a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
1319a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1320a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PSA_CRYPTO_CLIENT
1321a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_LMS_C
1322a8e1175bSopenharmony_ci
1323a8e1175bSopenharmony_ci    make
1324a8e1175bSopenharmony_ci
1325a8e1175bSopenharmony_ci    msg "check missing symbols: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
1326a8e1175bSopenharmony_ci    common_check_mbedtls_missing_symbols
1327a8e1175bSopenharmony_ci
1328a8e1175bSopenharmony_ci    msg "test: default config - PSA_CRYPTO_C + PSA_CRYPTO_CLIENT"
1329a8e1175bSopenharmony_ci    make test
1330a8e1175bSopenharmony_ci}
1331a8e1175bSopenharmony_ci
1332a8e1175bSopenharmony_cicomponent_build_full_psa_crypto_client_without_crypto_provider () {
1333a8e1175bSopenharmony_ci    msg "build: full config - PSA_CRYPTO_C"
1334a8e1175bSopenharmony_ci
1335a8e1175bSopenharmony_ci    # Use full config which includes USE_PSA and CRYPTO_CLIENT.
1336a8e1175bSopenharmony_ci    scripts/config.py full
1337a8e1175bSopenharmony_ci
1338a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1339a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1340a8e1175bSopenharmony_ci    # Dynamic secure element support is a deprecated feature and it is not
1341a8e1175bSopenharmony_ci    # available when CRYPTO_C and PSA_CRYPTO_STORAGE_C are disabled.
1342a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
1343a8e1175bSopenharmony_ci
1344a8e1175bSopenharmony_ci    # Since there is no crypto provider in this build it is not possible to
1345a8e1175bSopenharmony_ci    # build all the test executables and progrems due to missing PSA functions
1346a8e1175bSopenharmony_ci    # at link time. Therefore we will just build libraries and we'll check
1347a8e1175bSopenharmony_ci    # that symbols of interest are there.
1348a8e1175bSopenharmony_ci    make lib
1349a8e1175bSopenharmony_ci
1350a8e1175bSopenharmony_ci    msg "check missing symbols: full config - PSA_CRYPTO_C"
1351a8e1175bSopenharmony_ci
1352a8e1175bSopenharmony_ci    common_check_mbedtls_missing_symbols
1353a8e1175bSopenharmony_ci
1354a8e1175bSopenharmony_ci    # Ensure that desired functions are included into the build (extend the
1355a8e1175bSopenharmony_ci    # following list as required).
1356a8e1175bSopenharmony_ci    grep mbedtls_pk_get_psa_attributes library/libmbedcrypto.a
1357a8e1175bSopenharmony_ci    grep mbedtls_pk_import_into_psa library/libmbedcrypto.a
1358a8e1175bSopenharmony_ci    grep mbedtls_pk_copy_from_psa library/libmbedcrypto.a
1359a8e1175bSopenharmony_ci}
1360a8e1175bSopenharmony_ci
1361a8e1175bSopenharmony_cicomponent_test_psa_crypto_rsa_no_genprime() {
1362a8e1175bSopenharmony_ci    msg "build: default config minus MBEDTLS_GENPRIME"
1363a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_GENPRIME
1364a8e1175bSopenharmony_ci    make
1365a8e1175bSopenharmony_ci
1366a8e1175bSopenharmony_ci    msg "test: default config minus MBEDTLS_GENPRIME"
1367a8e1175bSopenharmony_ci    make test
1368a8e1175bSopenharmony_ci}
1369a8e1175bSopenharmony_ci
1370a8e1175bSopenharmony_cicomponent_test_ref_configs () {
1371a8e1175bSopenharmony_ci    msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s
1372a8e1175bSopenharmony_ci    # test-ref-configs works by overwriting mbedtls_config.h; this makes cmake
1373a8e1175bSopenharmony_ci    # want to re-generate generated files that depend on it, quite correctly.
1374a8e1175bSopenharmony_ci    # However this doesn't work as the generation script expects a specific
1375a8e1175bSopenharmony_ci    # format for mbedtls_config.h, which the other files don't follow. Also,
1376a8e1175bSopenharmony_ci    # cmake can't know this, but re-generation is actually not necessary as
1377a8e1175bSopenharmony_ci    # the generated files only depend on the list of available options, not
1378a8e1175bSopenharmony_ci    # whether they're on or off. So, disable cmake's (over-sensitive here)
1379a8e1175bSopenharmony_ci    # dependency resolution for generated files and just rely on them being
1380a8e1175bSopenharmony_ci    # present (thanks to pre_generate_files) by turning GEN_FILES off.
1381a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D GEN_FILES=Off -D CMAKE_BUILD_TYPE:String=Asan .
1382a8e1175bSopenharmony_ci    tests/scripts/test-ref-configs.pl
1383a8e1175bSopenharmony_ci}
1384a8e1175bSopenharmony_ci
1385a8e1175bSopenharmony_cicomponent_test_no_renegotiation () {
1386a8e1175bSopenharmony_ci    msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min
1387a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_RENEGOTIATION
1388a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1389a8e1175bSopenharmony_ci    make
1390a8e1175bSopenharmony_ci
1391a8e1175bSopenharmony_ci    msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s
1392a8e1175bSopenharmony_ci    make test
1393a8e1175bSopenharmony_ci
1394a8e1175bSopenharmony_ci    msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min
1395a8e1175bSopenharmony_ci    tests/ssl-opt.sh
1396a8e1175bSopenharmony_ci}
1397a8e1175bSopenharmony_ci
1398a8e1175bSopenharmony_cicomponent_test_no_pem_no_fs () {
1399a8e1175bSopenharmony_ci    msg "build: Default + !MBEDTLS_PEM_PARSE_C + !MBEDTLS_FS_IO (ASan build)"
1400a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PEM_PARSE_C
1401a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_FS_IO
1402a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem
1403a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS
1404a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1405a8e1175bSopenharmony_ci    make
1406a8e1175bSopenharmony_ci
1407a8e1175bSopenharmony_ci    msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - main suites (inc. selftests) (ASan build)" # ~ 50s
1408a8e1175bSopenharmony_ci    make test
1409a8e1175bSopenharmony_ci
1410a8e1175bSopenharmony_ci    msg "test: !MBEDTLS_PEM_PARSE_C !MBEDTLS_FS_IO - ssl-opt.sh (ASan build)" # ~ 6 min
1411a8e1175bSopenharmony_ci    tests/ssl-opt.sh
1412a8e1175bSopenharmony_ci}
1413a8e1175bSopenharmony_ci
1414a8e1175bSopenharmony_cicomponent_test_rsa_no_crt () {
1415a8e1175bSopenharmony_ci    msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min
1416a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_RSA_NO_CRT
1417a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1418a8e1175bSopenharmony_ci    make
1419a8e1175bSopenharmony_ci
1420a8e1175bSopenharmony_ci    msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s
1421a8e1175bSopenharmony_ci    make test
1422a8e1175bSopenharmony_ci
1423a8e1175bSopenharmony_ci    msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s
1424a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f RSA
1425a8e1175bSopenharmony_ci
1426a8e1175bSopenharmony_ci    msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min
1427a8e1175bSopenharmony_ci    tests/compat.sh -t RSA
1428a8e1175bSopenharmony_ci
1429a8e1175bSopenharmony_ci    msg "test: RSA_NO_CRT - RSA-related part of context-info.sh (ASan build)" # ~ 15 sec
1430a8e1175bSopenharmony_ci    tests/context-info.sh
1431a8e1175bSopenharmony_ci}
1432a8e1175bSopenharmony_ci
1433a8e1175bSopenharmony_cicomponent_test_no_ctr_drbg_classic () {
1434a8e1175bSopenharmony_ci    msg "build: Full minus CTR_DRBG, classic crypto in TLS"
1435a8e1175bSopenharmony_ci    scripts/config.py full
1436a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CTR_DRBG_C
1437a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1438a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1439a8e1175bSopenharmony_ci
1440a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1441a8e1175bSopenharmony_ci    make
1442a8e1175bSopenharmony_ci
1443a8e1175bSopenharmony_ci    msg "test: Full minus CTR_DRBG, classic crypto - main suites"
1444a8e1175bSopenharmony_ci    make test
1445a8e1175bSopenharmony_ci
1446a8e1175bSopenharmony_ci    # In this configuration, the TLS test programs use HMAC_DRBG.
1447a8e1175bSopenharmony_ci    # The SSL tests are slow, so run a small subset, just enough to get
1448a8e1175bSopenharmony_ci    # confidence that the SSL code copes with HMAC_DRBG.
1449a8e1175bSopenharmony_ci    msg "test: Full minus CTR_DRBG, classic crypto - ssl-opt.sh (subset)"
1450a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
1451a8e1175bSopenharmony_ci
1452a8e1175bSopenharmony_ci    msg "test: Full minus CTR_DRBG, classic crypto - compat.sh (subset)"
1453a8e1175bSopenharmony_ci    tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
1454a8e1175bSopenharmony_ci}
1455a8e1175bSopenharmony_ci
1456a8e1175bSopenharmony_cicomponent_test_no_ctr_drbg_use_psa () {
1457a8e1175bSopenharmony_ci    msg "build: Full minus CTR_DRBG, PSA crypto in TLS"
1458a8e1175bSopenharmony_ci    scripts/config.py full
1459a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CTR_DRBG_C
1460a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1461a8e1175bSopenharmony_ci
1462a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1463a8e1175bSopenharmony_ci    make
1464a8e1175bSopenharmony_ci
1465a8e1175bSopenharmony_ci    msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - main suites"
1466a8e1175bSopenharmony_ci    make test
1467a8e1175bSopenharmony_ci
1468a8e1175bSopenharmony_ci    # In this configuration, the TLS test programs use HMAC_DRBG.
1469a8e1175bSopenharmony_ci    # The SSL tests are slow, so run a small subset, just enough to get
1470a8e1175bSopenharmony_ci    # confidence that the SSL code copes with HMAC_DRBG.
1471a8e1175bSopenharmony_ci    msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
1472a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f 'Default\|SSL async private.*delay=\|tickets enabled on server'
1473a8e1175bSopenharmony_ci
1474a8e1175bSopenharmony_ci    msg "test: Full minus CTR_DRBG, USE_PSA_CRYPTO - compat.sh (subset)"
1475a8e1175bSopenharmony_ci    tests/compat.sh -m tls12 -t 'ECDSA PSK' -V NO -p OpenSSL
1476a8e1175bSopenharmony_ci}
1477a8e1175bSopenharmony_ci
1478a8e1175bSopenharmony_cicomponent_test_no_hmac_drbg_classic () {
1479a8e1175bSopenharmony_ci    msg "build: Full minus HMAC_DRBG, classic crypto in TLS"
1480a8e1175bSopenharmony_ci    scripts/config.py full
1481a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1482a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1483a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1484a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1485a8e1175bSopenharmony_ci
1486a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1487a8e1175bSopenharmony_ci    make
1488a8e1175bSopenharmony_ci
1489a8e1175bSopenharmony_ci    msg "test: Full minus HMAC_DRBG, classic crypto - main suites"
1490a8e1175bSopenharmony_ci    make test
1491a8e1175bSopenharmony_ci
1492a8e1175bSopenharmony_ci    # Normally our ECDSA implementation uses deterministic ECDSA. But since
1493a8e1175bSopenharmony_ci    # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1494a8e1175bSopenharmony_ci    # instead.
1495a8e1175bSopenharmony_ci    # Test SSL with non-deterministic ECDSA. Only test features that
1496a8e1175bSopenharmony_ci    # might be affected by how ECDSA signature is performed.
1497a8e1175bSopenharmony_ci    msg "test: Full minus HMAC_DRBG, classic crypto - ssl-opt.sh (subset)"
1498a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
1499a8e1175bSopenharmony_ci
1500a8e1175bSopenharmony_ci    # To save time, only test one protocol version, since this part of
1501a8e1175bSopenharmony_ci    # the protocol is identical in (D)TLS up to 1.2.
1502a8e1175bSopenharmony_ci    msg "test: Full minus HMAC_DRBG, classic crypto - compat.sh (ECDSA)"
1503a8e1175bSopenharmony_ci    tests/compat.sh -m tls12 -t 'ECDSA'
1504a8e1175bSopenharmony_ci}
1505a8e1175bSopenharmony_ci
1506a8e1175bSopenharmony_cicomponent_test_no_hmac_drbg_use_psa () {
1507a8e1175bSopenharmony_ci    msg "build: Full minus HMAC_DRBG, PSA crypto in TLS"
1508a8e1175bSopenharmony_ci    scripts/config.py full
1509a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1510a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1511a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1512a8e1175bSopenharmony_ci
1513a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
1514a8e1175bSopenharmony_ci    make
1515a8e1175bSopenharmony_ci
1516a8e1175bSopenharmony_ci    msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - main suites"
1517a8e1175bSopenharmony_ci    make test
1518a8e1175bSopenharmony_ci
1519a8e1175bSopenharmony_ci    # Normally our ECDSA implementation uses deterministic ECDSA. But since
1520a8e1175bSopenharmony_ci    # HMAC_DRBG is disabled in this configuration, randomized ECDSA is used
1521a8e1175bSopenharmony_ci    # instead.
1522a8e1175bSopenharmony_ci    # Test SSL with non-deterministic ECDSA. Only test features that
1523a8e1175bSopenharmony_ci    # might be affected by how ECDSA signature is performed.
1524a8e1175bSopenharmony_ci    msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - ssl-opt.sh (subset)"
1525a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f 'Default\|SSL async private: sign'
1526a8e1175bSopenharmony_ci
1527a8e1175bSopenharmony_ci    # To save time, only test one protocol version, since this part of
1528a8e1175bSopenharmony_ci    # the protocol is identical in (D)TLS up to 1.2.
1529a8e1175bSopenharmony_ci    msg "test: Full minus HMAC_DRBG, USE_PSA_CRYPTO - compat.sh (ECDSA)"
1530a8e1175bSopenharmony_ci    tests/compat.sh -m tls12 -t 'ECDSA'
1531a8e1175bSopenharmony_ci}
1532a8e1175bSopenharmony_ci
1533a8e1175bSopenharmony_cicomponent_test_psa_external_rng_no_drbg_classic () {
1534a8e1175bSopenharmony_ci    msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto in TLS"
1535a8e1175bSopenharmony_ci    scripts/config.py full
1536a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1537a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1538a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1539a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ENTROPY_C
1540a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1541a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1542a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CTR_DRBG_C
1543a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1544a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1545a8e1175bSopenharmony_ci    # When MBEDTLS_USE_PSA_CRYPTO is disabled and there is no DRBG,
1546a8e1175bSopenharmony_ci    # the SSL test programs don't have an RNG and can't work. Explicitly
1547a8e1175bSopenharmony_ci    # make them use the PSA RNG with -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG.
1548a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DMBEDTLS_TEST_USE_PSA_CRYPTO_RNG" LDFLAGS="$ASAN_CFLAGS"
1549a8e1175bSopenharmony_ci
1550a8e1175bSopenharmony_ci    msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - main suites"
1551a8e1175bSopenharmony_ci    make test
1552a8e1175bSopenharmony_ci
1553a8e1175bSopenharmony_ci    msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, classic crypto - ssl-opt.sh (subset)"
1554a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f 'Default'
1555a8e1175bSopenharmony_ci}
1556a8e1175bSopenharmony_ci
1557a8e1175bSopenharmony_cicomponent_test_psa_external_rng_no_drbg_use_psa () {
1558a8e1175bSopenharmony_ci    msg "build: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto in TLS"
1559a8e1175bSopenharmony_ci    scripts/config.py full
1560a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1561a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ENTROPY_C
1562a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
1563a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1564a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CTR_DRBG_C
1565a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1566a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG
1567a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1568a8e1175bSopenharmony_ci
1569a8e1175bSopenharmony_ci    msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - main suites"
1570a8e1175bSopenharmony_ci    make test
1571a8e1175bSopenharmony_ci
1572a8e1175bSopenharmony_ci    msg "test: PSA_CRYPTO_EXTERNAL_RNG minus *_DRBG, PSA crypto - ssl-opt.sh (subset)"
1573a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f 'Default\|opaque'
1574a8e1175bSopenharmony_ci}
1575a8e1175bSopenharmony_ci
1576a8e1175bSopenharmony_cicomponent_test_psa_external_rng_use_psa_crypto () {
1577a8e1175bSopenharmony_ci    msg "build: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1578a8e1175bSopenharmony_ci    scripts/config.py full
1579a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG
1580a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1581a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CTR_DRBG_C
1582a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1583a8e1175bSopenharmony_ci
1584a8e1175bSopenharmony_ci    msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1585a8e1175bSopenharmony_ci    make test
1586a8e1175bSopenharmony_ci
1587a8e1175bSopenharmony_ci    msg "test: full + PSA_CRYPTO_EXTERNAL_RNG + USE_PSA_CRYPTO minus CTR_DRBG"
1588a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f 'Default\|opaque'
1589a8e1175bSopenharmony_ci}
1590a8e1175bSopenharmony_ci
1591a8e1175bSopenharmony_cicomponent_test_psa_inject_entropy () {
1592a8e1175bSopenharmony_ci    msg "build: full + MBEDTLS_PSA_INJECT_ENTROPY"
1593a8e1175bSopenharmony_ci    scripts/config.py full
1594a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PSA_INJECT_ENTROPY
1595a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_ENTROPY_NV_SEED
1596a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
1597a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
1598a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_READ
1599a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PLATFORM_STD_NV_SEED_WRITE
1600a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'" LDFLAGS="$ASAN_CFLAGS"
1601a8e1175bSopenharmony_ci
1602a8e1175bSopenharmony_ci    msg "test: full + MBEDTLS_PSA_INJECT_ENTROPY"
1603a8e1175bSopenharmony_ci    make test
1604a8e1175bSopenharmony_ci}
1605a8e1175bSopenharmony_ci
1606a8e1175bSopenharmony_cicomponent_test_sw_inet_pton () {
1607a8e1175bSopenharmony_ci    msg "build: default plus MBEDTLS_TEST_SW_INET_PTON"
1608a8e1175bSopenharmony_ci
1609a8e1175bSopenharmony_ci    # MBEDTLS_TEST_HOOKS required for x509_crt_parse_cn_inet_pton
1610a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_TEST_HOOKS
1611a8e1175bSopenharmony_ci    make CFLAGS="-DMBEDTLS_TEST_SW_INET_PTON"
1612a8e1175bSopenharmony_ci
1613a8e1175bSopenharmony_ci    msg "test: default plus MBEDTLS_TEST_SW_INET_PTON"
1614a8e1175bSopenharmony_ci    make test
1615a8e1175bSopenharmony_ci}
1616a8e1175bSopenharmony_ci
1617a8e1175bSopenharmony_cicomponent_full_no_pkparse_pkwrite() {
1618a8e1175bSopenharmony_ci    msg "build: full without pkparse and pkwrite"
1619a8e1175bSopenharmony_ci
1620a8e1175bSopenharmony_ci    scripts/config.py crypto_full
1621a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PK_PARSE_C
1622a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PK_WRITE_C
1623a8e1175bSopenharmony_ci
1624a8e1175bSopenharmony_ci    make CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1625a8e1175bSopenharmony_ci
1626a8e1175bSopenharmony_ci    # Ensure that PK_[PARSE|WRITE]_C were not re-enabled accidentally (additive config).
1627a8e1175bSopenharmony_ci    not grep mbedtls_pk_parse_key library/pkparse.o
1628a8e1175bSopenharmony_ci    not grep mbedtls_pk_write_key_der library/pkwrite.o
1629a8e1175bSopenharmony_ci
1630a8e1175bSopenharmony_ci    msg "test: full without pkparse and pkwrite"
1631a8e1175bSopenharmony_ci    make test
1632a8e1175bSopenharmony_ci}
1633a8e1175bSopenharmony_ci
1634a8e1175bSopenharmony_cicomponent_test_crypto_full_md_light_only () {
1635a8e1175bSopenharmony_ci    msg "build: crypto_full with only the light subset of MD"
1636a8e1175bSopenharmony_ci    scripts/config.py crypto_full
1637a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
1638a8e1175bSopenharmony_ci    # Disable MD
1639a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_MD_C
1640a8e1175bSopenharmony_ci    # Disable direct dependencies of MD_C
1641a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_HKDF_C
1642a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_HMAC_DRBG_C
1643a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PKCS7_C
1644a8e1175bSopenharmony_ci    # Disable indirect dependencies of MD_C
1645a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # needs HMAC_DRBG
1646a8e1175bSopenharmony_ci    # Disable things that would auto-enable MD_C
1647a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PKCS5_C
1648a8e1175bSopenharmony_ci
1649a8e1175bSopenharmony_ci    # Note: MD-light is auto-enabled in build_info.h by modules that need it,
1650a8e1175bSopenharmony_ci    # which we haven't disabled, so no need to explicitly enable it.
1651a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
1652a8e1175bSopenharmony_ci
1653a8e1175bSopenharmony_ci    # Make sure we don't have the HMAC functions, but the hashing functions
1654a8e1175bSopenharmony_ci    not grep mbedtls_md_hmac library/md.o
1655a8e1175bSopenharmony_ci    grep mbedtls_md library/md.o
1656a8e1175bSopenharmony_ci
1657a8e1175bSopenharmony_ci    msg "test: crypto_full with only the light subset of MD"
1658a8e1175bSopenharmony_ci    make test
1659a8e1175bSopenharmony_ci}
1660a8e1175bSopenharmony_ci
1661a8e1175bSopenharmony_cicomponent_test_full_no_cipher_no_psa_crypto () {
1662a8e1175bSopenharmony_ci    msg "build: full no CIPHER no PSA_CRYPTO_C"
1663a8e1175bSopenharmony_ci    scripts/config.py full
1664a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_C
1665a8e1175bSopenharmony_ci    # Don't pull in cipher via PSA mechanisms
1666a8e1175bSopenharmony_ci    # (currently ignored anyway because we completely disable PSA)
1667a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
1668a8e1175bSopenharmony_ci    # Disable features that depend on CIPHER_C
1669a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CMAC_C
1670a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_NIST_KW_C
1671a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
1672a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_CLIENT
1673a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TLS_C
1674a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TICKET_C
1675a8e1175bSopenharmony_ci    # Disable features that depend on PSA_CRYPTO_C
1676a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
1677a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
1678a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
1679a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_LMS_C
1680a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_LMS_PRIVATE
1681a8e1175bSopenharmony_ci
1682a8e1175bSopenharmony_ci    msg "test: full no CIPHER no PSA_CRYPTO_C"
1683a8e1175bSopenharmony_ci    make test
1684a8e1175bSopenharmony_ci}
1685a8e1175bSopenharmony_ci
1686a8e1175bSopenharmony_ci# This is a common configurator and test function that is used in:
1687a8e1175bSopenharmony_ci# - component_test_full_no_cipher_with_psa_crypto
1688a8e1175bSopenharmony_ci# - component_test_full_no_cipher_with_psa_crypto_config
1689a8e1175bSopenharmony_ci# It accepts 2 input parameters:
1690a8e1175bSopenharmony_ci# - $1: boolean value which basically reflects status of MBEDTLS_PSA_CRYPTO_CONFIG
1691a8e1175bSopenharmony_ci# - $2: a text string which describes the test component
1692a8e1175bSopenharmony_cicommon_test_full_no_cipher_with_psa_crypto () {
1693a8e1175bSopenharmony_ci    USE_CRYPTO_CONFIG="$1"
1694a8e1175bSopenharmony_ci    COMPONENT_DESCRIPTION="$2"
1695a8e1175bSopenharmony_ci
1696a8e1175bSopenharmony_ci    msg "build: $COMPONENT_DESCRIPTION"
1697a8e1175bSopenharmony_ci
1698a8e1175bSopenharmony_ci    scripts/config.py full
1699a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_C
1700a8e1175bSopenharmony_ci
1701a8e1175bSopenharmony_ci    if [ "$USE_CRYPTO_CONFIG" -eq 1 ]; then
1702a8e1175bSopenharmony_ci        # The built-in implementation of the following algs/key-types depends
1703a8e1175bSopenharmony_ci        # on CIPHER_C so we disable them.
1704a8e1175bSopenharmony_ci        # This does not hold for KEY_TYPE_CHACHA20 and ALG_CHACHA20_POLY1305
1705a8e1175bSopenharmony_ci        # so we keep them enabled.
1706a8e1175bSopenharmony_ci        scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1707a8e1175bSopenharmony_ci        scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CMAC
1708a8e1175bSopenharmony_ci        scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_NO_PADDING
1709a8e1175bSopenharmony_ci        scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CBC_PKCS7
1710a8e1175bSopenharmony_ci        scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CFB
1711a8e1175bSopenharmony_ci        scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_CTR
1712a8e1175bSopenharmony_ci        scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_ECB_NO_PADDING
1713a8e1175bSopenharmony_ci        scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_OFB
1714a8e1175bSopenharmony_ci        scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_ALG_STREAM_CIPHER
1715a8e1175bSopenharmony_ci        scripts/config.py -f $CRYPTO_CONFIG_H unset PSA_WANT_KEY_TYPE_DES
1716a8e1175bSopenharmony_ci    else
1717a8e1175bSopenharmony_ci        # Don't pull in cipher via PSA mechanisms
1718a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
1719a8e1175bSopenharmony_ci        # Disable cipher modes/keys that make PSA depend on CIPHER_C.
1720a8e1175bSopenharmony_ci        # Keep CHACHA20 and CHACHAPOLY enabled since they do not depend on CIPHER_C.
1721a8e1175bSopenharmony_ci        scripts/config.py unset-all MBEDTLS_CIPHER_MODE
1722a8e1175bSopenharmony_ci    fi
1723a8e1175bSopenharmony_ci    # The following modules directly depends on CIPHER_C
1724a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CMAC_C
1725a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_NIST_KW_C
1726a8e1175bSopenharmony_ci
1727a8e1175bSopenharmony_ci    make
1728a8e1175bSopenharmony_ci
1729a8e1175bSopenharmony_ci    # Ensure that CIPHER_C was not re-enabled
1730a8e1175bSopenharmony_ci    not grep mbedtls_cipher_init library/cipher.o
1731a8e1175bSopenharmony_ci
1732a8e1175bSopenharmony_ci    msg "test: $COMPONENT_DESCRIPTION"
1733a8e1175bSopenharmony_ci    make test
1734a8e1175bSopenharmony_ci}
1735a8e1175bSopenharmony_ci
1736a8e1175bSopenharmony_cicomponent_test_full_no_cipher_with_psa_crypto() {
1737a8e1175bSopenharmony_ci    common_test_full_no_cipher_with_psa_crypto 0 "full no CIPHER no CRYPTO_CONFIG"
1738a8e1175bSopenharmony_ci}
1739a8e1175bSopenharmony_ci
1740a8e1175bSopenharmony_cicomponent_test_full_no_cipher_with_psa_crypto_config() {
1741a8e1175bSopenharmony_ci    common_test_full_no_cipher_with_psa_crypto 1 "full no CIPHER"
1742a8e1175bSopenharmony_ci}
1743a8e1175bSopenharmony_ci
1744a8e1175bSopenharmony_cicomponent_test_full_no_ccm() {
1745a8e1175bSopenharmony_ci    msg "build: full no PSA_WANT_ALG_CCM"
1746a8e1175bSopenharmony_ci
1747a8e1175bSopenharmony_ci    # Full config enables:
1748a8e1175bSopenharmony_ci    # - USE_PSA_CRYPTO so that TLS code dispatches cipher/AEAD to PSA
1749a8e1175bSopenharmony_ci    # - CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
1750a8e1175bSopenharmony_ci    scripts/config.py full
1751a8e1175bSopenharmony_ci
1752a8e1175bSopenharmony_ci    # Disable PSA_WANT_ALG_CCM so that CCM is not supported in PSA. CCM_C is still
1753a8e1175bSopenharmony_ci    # enabled, but not used from TLS since USE_PSA is set.
1754a8e1175bSopenharmony_ci    # This is helpful to ensure that TLS tests below have proper dependencies.
1755a8e1175bSopenharmony_ci    #
1756a8e1175bSopenharmony_ci    # Note: also PSA_WANT_ALG_CCM_STAR_NO_TAG is enabled, but it does not cause
1757a8e1175bSopenharmony_ci    # PSA_WANT_ALG_CCM to be re-enabled.
1758a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM
1759a8e1175bSopenharmony_ci
1760a8e1175bSopenharmony_ci    make
1761a8e1175bSopenharmony_ci
1762a8e1175bSopenharmony_ci    msg "test: full no PSA_WANT_ALG_CCM"
1763a8e1175bSopenharmony_ci    make test
1764a8e1175bSopenharmony_ci}
1765a8e1175bSopenharmony_ci
1766a8e1175bSopenharmony_cicomponent_test_full_no_ccm_star_no_tag() {
1767a8e1175bSopenharmony_ci    msg "build: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
1768a8e1175bSopenharmony_ci
1769a8e1175bSopenharmony_ci    # Full config enables CRYPTO_CONFIG so that PSA_WANT config symbols are evaluated
1770a8e1175bSopenharmony_ci    scripts/config.py full
1771a8e1175bSopenharmony_ci
1772a8e1175bSopenharmony_ci    # Disable CCM_STAR_NO_TAG, which is the target of this test, as well as all
1773a8e1175bSopenharmony_ci    # other components that enable MBEDTLS_PSA_BUILTIN_CIPHER internal symbol.
1774a8e1175bSopenharmony_ci    # This basically disables all unauthenticated ciphers on the PSA side, while
1775a8e1175bSopenharmony_ci    # keeping AEADs enabled.
1776a8e1175bSopenharmony_ci    #
1777a8e1175bSopenharmony_ci    # Note: PSA_WANT_ALG_CCM is enabled, but it does not cause
1778a8e1175bSopenharmony_ci    # PSA_WANT_ALG_CCM_STAR_NO_TAG to be re-enabled.
1779a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
1780a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_STREAM_CIPHER
1781a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
1782a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
1783a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
1784a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
1785a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
1786a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
1787a8e1175bSopenharmony_ci
1788a8e1175bSopenharmony_ci    make
1789a8e1175bSopenharmony_ci
1790a8e1175bSopenharmony_ci    # Ensure MBEDTLS_PSA_BUILTIN_CIPHER was not enabled
1791a8e1175bSopenharmony_ci    not grep mbedtls_psa_cipher library/psa_crypto_cipher.o
1792a8e1175bSopenharmony_ci
1793a8e1175bSopenharmony_ci    msg "test: full no PSA_WANT_ALG_CCM_STAR_NO_TAG"
1794a8e1175bSopenharmony_ci    make test
1795a8e1175bSopenharmony_ci}
1796a8e1175bSopenharmony_ci
1797a8e1175bSopenharmony_cicomponent_test_full_no_bignum () {
1798a8e1175bSopenharmony_ci    msg "build: full minus bignum"
1799a8e1175bSopenharmony_ci    scripts/config.py full
1800a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_BIGNUM_C
1801a8e1175bSopenharmony_ci    # Direct dependencies of bignum
1802a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECP_C
1803a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_RSA_C
1804a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_DHM_C
1805a8e1175bSopenharmony_ci    # Direct dependencies of ECP
1806a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDH_C
1807a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDSA_C
1808a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECJPAKE_C
1809a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
1810a8e1175bSopenharmony_ci    # Disable what auto-enables ECP_LIGHT
1811a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
1812a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
1813a8e1175bSopenharmony_ci    # Indirect dependencies of ECP
1814a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
1815a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
1816a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
1817a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
1818a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
1819a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
1820a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
1821a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
1822a8e1175bSopenharmony_ci    # Direct dependencies of DHM
1823a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
1824a8e1175bSopenharmony_ci    # Direct dependencies of RSA
1825a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
1826a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
1827a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
1828a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
1829a8e1175bSopenharmony_ci    # PK and its dependencies
1830a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PK_C
1831a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PK_PARSE_C
1832a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PK_WRITE_C
1833a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_USE_C
1834a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
1835a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_CRL_PARSE_C
1836a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_CSR_PARSE_C
1837a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_CREATE_C
1838a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_CRT_WRITE_C
1839a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_CSR_WRITE_C
1840a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PKCS7_C
1841a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
1842a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_ASYNC_PRIVATE
1843a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
1844a8e1175bSopenharmony_ci
1845a8e1175bSopenharmony_ci    make
1846a8e1175bSopenharmony_ci
1847a8e1175bSopenharmony_ci    msg "test: full minus bignum"
1848a8e1175bSopenharmony_ci    make test
1849a8e1175bSopenharmony_ci}
1850a8e1175bSopenharmony_ci
1851a8e1175bSopenharmony_cicomponent_test_tls1_2_default_stream_cipher_only () {
1852a8e1175bSopenharmony_ci    msg "build: default with only stream cipher"
1853a8e1175bSopenharmony_ci
1854a8e1175bSopenharmony_ci    # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C
1855a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_GCM_C
1856a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CCM_C
1857a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1858a8e1175bSopenharmony_ci    #Disable TLS 1.3 (as no AEAD)
1859a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1860a8e1175bSopenharmony_ci    # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1861a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1862a8e1175bSopenharmony_ci    # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1863a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1864a8e1175bSopenharmony_ci    # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1865a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1866a8e1175bSopenharmony_ci    # Modules that depend on AEAD
1867a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
1868a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TICKET_C
1869a8e1175bSopenharmony_ci
1870a8e1175bSopenharmony_ci    make
1871a8e1175bSopenharmony_ci
1872a8e1175bSopenharmony_ci    msg "test: default with only stream cipher"
1873a8e1175bSopenharmony_ci    make test
1874a8e1175bSopenharmony_ci
1875a8e1175bSopenharmony_ci    # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1876a8e1175bSopenharmony_ci}
1877a8e1175bSopenharmony_ci
1878a8e1175bSopenharmony_cicomponent_test_tls1_2_default_stream_cipher_only_use_psa () {
1879a8e1175bSopenharmony_ci    msg "build: default with only stream cipher use psa"
1880a8e1175bSopenharmony_ci
1881a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1882a8e1175bSopenharmony_ci    # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1883a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_GCM_C
1884a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CCM_C
1885a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1886a8e1175bSopenharmony_ci    #Disable TLS 1.3 (as no AEAD)
1887a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1888a8e1175bSopenharmony_ci    # Disable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1889a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
1890a8e1175bSopenharmony_ci    # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1891a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1892a8e1175bSopenharmony_ci    # Enable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1893a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_CIPHER_NULL_CIPHER
1894a8e1175bSopenharmony_ci    # Modules that depend on AEAD
1895a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
1896a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TICKET_C
1897a8e1175bSopenharmony_ci
1898a8e1175bSopenharmony_ci    make
1899a8e1175bSopenharmony_ci
1900a8e1175bSopenharmony_ci    msg "test: default with only stream cipher use psa"
1901a8e1175bSopenharmony_ci    make test
1902a8e1175bSopenharmony_ci
1903a8e1175bSopenharmony_ci    # Not running ssl-opt.sh because most tests require a non-NULL ciphersuite.
1904a8e1175bSopenharmony_ci}
1905a8e1175bSopenharmony_ci
1906a8e1175bSopenharmony_cicomponent_test_tls1_2_default_cbc_legacy_cipher_only () {
1907a8e1175bSopenharmony_ci    msg "build: default with only CBC-legacy cipher"
1908a8e1175bSopenharmony_ci
1909a8e1175bSopenharmony_ci    # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1910a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_GCM_C
1911a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CCM_C
1912a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1913a8e1175bSopenharmony_ci    #Disable TLS 1.3 (as no AEAD)
1914a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1915a8e1175bSopenharmony_ci    # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1916a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1917a8e1175bSopenharmony_ci    # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1918a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1919a8e1175bSopenharmony_ci    # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1920a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1921a8e1175bSopenharmony_ci    # Modules that depend on AEAD
1922a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
1923a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TICKET_C
1924a8e1175bSopenharmony_ci
1925a8e1175bSopenharmony_ci    make
1926a8e1175bSopenharmony_ci
1927a8e1175bSopenharmony_ci    msg "test: default with only CBC-legacy cipher"
1928a8e1175bSopenharmony_ci    make test
1929a8e1175bSopenharmony_ci
1930a8e1175bSopenharmony_ci    msg "test: default with only CBC-legacy cipher - ssl-opt.sh (subset)"
1931a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f "TLS 1.2"
1932a8e1175bSopenharmony_ci}
1933a8e1175bSopenharmony_ci
1934a8e1175bSopenharmony_cicomponent_test_tls1_2_deafult_cbc_legacy_cipher_only_use_psa () {
1935a8e1175bSopenharmony_ci    msg "build: default with only CBC-legacy cipher use psa"
1936a8e1175bSopenharmony_ci
1937a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1938a8e1175bSopenharmony_ci    # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1939a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_GCM_C
1940a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CCM_C
1941a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1942a8e1175bSopenharmony_ci    #Disable TLS 1.3 (as no AEAD)
1943a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1944a8e1175bSopenharmony_ci    # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1945a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1946a8e1175bSopenharmony_ci    # Disable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1947a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_ENCRYPT_THEN_MAC
1948a8e1175bSopenharmony_ci    # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1949a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1950a8e1175bSopenharmony_ci    # Modules that depend on AEAD
1951a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
1952a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TICKET_C
1953a8e1175bSopenharmony_ci
1954a8e1175bSopenharmony_ci    make
1955a8e1175bSopenharmony_ci
1956a8e1175bSopenharmony_ci    msg "test: default with only CBC-legacy cipher use psa"
1957a8e1175bSopenharmony_ci    make test
1958a8e1175bSopenharmony_ci
1959a8e1175bSopenharmony_ci    msg "test: default with only CBC-legacy cipher use psa - ssl-opt.sh (subset)"
1960a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f "TLS 1.2"
1961a8e1175bSopenharmony_ci}
1962a8e1175bSopenharmony_ci
1963a8e1175bSopenharmony_cicomponent_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only () {
1964a8e1175bSopenharmony_ci    msg "build: default with only CBC-legacy and CBC-EtM ciphers"
1965a8e1175bSopenharmony_ci
1966a8e1175bSopenharmony_ci    # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1967a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_GCM_C
1968a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CCM_C
1969a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1970a8e1175bSopenharmony_ci    #Disable TLS 1.3 (as no AEAD)
1971a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
1972a8e1175bSopenharmony_ci    # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
1973a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
1974a8e1175bSopenharmony_ci    # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1975a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
1976a8e1175bSopenharmony_ci    # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
1977a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
1978a8e1175bSopenharmony_ci    # Modules that depend on AEAD
1979a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
1980a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TICKET_C
1981a8e1175bSopenharmony_ci
1982a8e1175bSopenharmony_ci    make
1983a8e1175bSopenharmony_ci
1984a8e1175bSopenharmony_ci    msg "test: default with only CBC-legacy and CBC-EtM ciphers"
1985a8e1175bSopenharmony_ci    make test
1986a8e1175bSopenharmony_ci
1987a8e1175bSopenharmony_ci    msg "test: default with only CBC-legacy and CBC-EtM ciphers - ssl-opt.sh (subset)"
1988a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f "TLS 1.2"
1989a8e1175bSopenharmony_ci}
1990a8e1175bSopenharmony_ci
1991a8e1175bSopenharmony_cicomponent_test_tls1_2_default_cbc_legacy_cbc_etm_cipher_only_use_psa () {
1992a8e1175bSopenharmony_ci    msg "build: default with only CBC-legacy and CBC-EtM ciphers use psa"
1993a8e1175bSopenharmony_ci
1994a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
1995a8e1175bSopenharmony_ci    # Disable AEAD (controlled by the presence of one of GCM_C, CCM_C, CHACHAPOLY_C)
1996a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_GCM_C
1997a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CCM_C
1998a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CHACHAPOLY_C
1999a8e1175bSopenharmony_ci    #Disable TLS 1.3 (as no AEAD)
2000a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2001a8e1175bSopenharmony_ci    # Enable CBC-legacy (controlled by MBEDTLS_CIPHER_MODE_CBC plus at least one block cipher (AES, ARIA, Camellia, DES))
2002a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_CIPHER_MODE_CBC
2003a8e1175bSopenharmony_ci    # Enable CBC-EtM (controlled by the same as CBC-legacy plus MBEDTLS_SSL_ENCRYPT_THEN_MAC)
2004a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_ENCRYPT_THEN_MAC
2005a8e1175bSopenharmony_ci    # Disable stream (currently that's just the NULL pseudo-cipher (controlled by MBEDTLS_CIPHER_NULL_CIPHER))
2006a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
2007a8e1175bSopenharmony_ci    # Modules that depend on AEAD
2008a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_CONTEXT_SERIALIZATION
2009a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TICKET_C
2010a8e1175bSopenharmony_ci
2011a8e1175bSopenharmony_ci    make
2012a8e1175bSopenharmony_ci
2013a8e1175bSopenharmony_ci    msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa"
2014a8e1175bSopenharmony_ci    make test
2015a8e1175bSopenharmony_ci
2016a8e1175bSopenharmony_ci    msg "test: default with only CBC-legacy and CBC-EtM ciphers use psa - ssl-opt.sh (subset)"
2017a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f "TLS 1.2"
2018a8e1175bSopenharmony_ci}
2019a8e1175bSopenharmony_ci
2020a8e1175bSopenharmony_ci# We're not aware of any other (open source) implementation of EC J-PAKE in TLS
2021a8e1175bSopenharmony_ci# that we could use for interop testing. However, we now have sort of two
2022a8e1175bSopenharmony_ci# implementations ourselves: one using PSA, the other not. At least test that
2023a8e1175bSopenharmony_ci# these two interoperate with each other.
2024a8e1175bSopenharmony_cicomponent_test_tls1_2_ecjpake_compatibility() {
2025a8e1175bSopenharmony_ci    msg "build: TLS1.2 server+client w/ EC-JPAKE w/o USE_PSA"
2026a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
2027a8e1175bSopenharmony_ci    # Explicitly make lib first to avoid a race condition:
2028a8e1175bSopenharmony_ci    # https://github.com/Mbed-TLS/mbedtls/issues/8229
2029a8e1175bSopenharmony_ci    make lib
2030a8e1175bSopenharmony_ci    make -C programs ssl/ssl_server2 ssl/ssl_client2
2031a8e1175bSopenharmony_ci    cp programs/ssl/ssl_server2 s2_no_use_psa
2032a8e1175bSopenharmony_ci    cp programs/ssl/ssl_client2 c2_no_use_psa
2033a8e1175bSopenharmony_ci
2034a8e1175bSopenharmony_ci    msg "build: TLS1.2 server+client w/ EC-JPAKE w/ USE_PSA"
2035a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_USE_PSA_CRYPTO
2036a8e1175bSopenharmony_ci    make clean
2037a8e1175bSopenharmony_ci    make lib
2038a8e1175bSopenharmony_ci    make -C programs ssl/ssl_server2 ssl/ssl_client2
2039a8e1175bSopenharmony_ci    make -C programs test/udp_proxy test/query_compile_time_config
2040a8e1175bSopenharmony_ci
2041a8e1175bSopenharmony_ci    msg "test: server w/o USE_PSA - client w/ USE_PSA, text password"
2042a8e1175bSopenharmony_ci    P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
2043a8e1175bSopenharmony_ci    msg "test: server w/o USE_PSA - client w/ USE_PSA, opaque password"
2044a8e1175bSopenharmony_ci    P_SRV=../s2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password client only, working, TLS"
2045a8e1175bSopenharmony_ci    msg "test: client w/o USE_PSA - server w/ USE_PSA, text password"
2046a8e1175bSopenharmony_ci    P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: working, TLS"
2047a8e1175bSopenharmony_ci    msg "test: client w/o USE_PSA - server w/ USE_PSA, opaque password"
2048a8e1175bSopenharmony_ci    P_CLI=../c2_no_use_psa tests/ssl-opt.sh -f "ECJPAKE: opaque password server only, working, TLS"
2049a8e1175bSopenharmony_ci
2050a8e1175bSopenharmony_ci    rm s2_no_use_psa c2_no_use_psa
2051a8e1175bSopenharmony_ci}
2052a8e1175bSopenharmony_ci
2053a8e1175bSopenharmony_cicomponent_test_everest () {
2054a8e1175bSopenharmony_ci    msg "build: Everest ECDH context (ASan build)" # ~ 6 min
2055a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
2056a8e1175bSopenharmony_ci    CC=clang cmake -D CMAKE_BUILD_TYPE:String=Asan .
2057a8e1175bSopenharmony_ci    make
2058a8e1175bSopenharmony_ci
2059a8e1175bSopenharmony_ci    msg "test: Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
2060a8e1175bSopenharmony_ci    make test
2061a8e1175bSopenharmony_ci
2062a8e1175bSopenharmony_ci    msg "test: metatests (clang, ASan)"
2063a8e1175bSopenharmony_ci    tests/scripts/run-metatests.sh any asan poison
2064a8e1175bSopenharmony_ci
2065a8e1175bSopenharmony_ci    msg "test: Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
2066a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f ECDH
2067a8e1175bSopenharmony_ci
2068a8e1175bSopenharmony_ci    msg "test: Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
2069a8e1175bSopenharmony_ci    # Exclude some symmetric ciphers that are redundant here to gain time.
2070a8e1175bSopenharmony_ci    tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
2071a8e1175bSopenharmony_ci}
2072a8e1175bSopenharmony_ci
2073a8e1175bSopenharmony_cicomponent_test_everest_curve25519_only () {
2074a8e1175bSopenharmony_ci    msg "build: Everest ECDH context, only Curve25519" # ~ 6 min
2075a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
2076a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDSA_C
2077a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2078a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2079a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECJPAKE_C
2080a8e1175bSopenharmony_ci    # Disable all curves
2081a8e1175bSopenharmony_ci    scripts/config.py unset-all "MBEDTLS_ECP_DP_[0-9A-Z_a-z]*_ENABLED"
2082a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_ECP_DP_CURVE25519_ENABLED
2083a8e1175bSopenharmony_ci
2084a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
2085a8e1175bSopenharmony_ci
2086a8e1175bSopenharmony_ci    msg "test: Everest ECDH context, only Curve25519" # ~ 50s
2087a8e1175bSopenharmony_ci    make test
2088a8e1175bSopenharmony_ci}
2089a8e1175bSopenharmony_ci
2090a8e1175bSopenharmony_cicomponent_test_small_ssl_out_content_len () {
2091a8e1175bSopenharmony_ci    msg "build: small SSL_OUT_CONTENT_LEN (ASan build)"
2092a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
2093a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
2094a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2095a8e1175bSopenharmony_ci    make
2096a8e1175bSopenharmony_ci
2097a8e1175bSopenharmony_ci    msg "test: small SSL_OUT_CONTENT_LEN - ssl-opt.sh MFL and large packet tests"
2098a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f "Max fragment\|Large packet"
2099a8e1175bSopenharmony_ci}
2100a8e1175bSopenharmony_ci
2101a8e1175bSopenharmony_cicomponent_test_small_ssl_in_content_len () {
2102a8e1175bSopenharmony_ci    msg "build: small SSL_IN_CONTENT_LEN (ASan build)"
2103a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 4096
2104a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 16384
2105a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2106a8e1175bSopenharmony_ci    make
2107a8e1175bSopenharmony_ci
2108a8e1175bSopenharmony_ci    msg "test: small SSL_IN_CONTENT_LEN - ssl-opt.sh MFL tests"
2109a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f "Max fragment"
2110a8e1175bSopenharmony_ci}
2111a8e1175bSopenharmony_ci
2112a8e1175bSopenharmony_cicomponent_test_small_ssl_dtls_max_buffering () {
2113a8e1175bSopenharmony_ci    msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0"
2114a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 1000
2115a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2116a8e1175bSopenharmony_ci    make
2117a8e1175bSopenharmony_ci
2118a8e1175bSopenharmony_ci    msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #0 - ssl-opt.sh specific reordering test"
2119a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f "DTLS reordering: Buffer out-of-order hs msg before reassembling next, free buffered msg"
2120a8e1175bSopenharmony_ci}
2121a8e1175bSopenharmony_ci
2122a8e1175bSopenharmony_cicomponent_test_small_mbedtls_ssl_dtls_max_buffering () {
2123a8e1175bSopenharmony_ci    msg "build: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1"
2124a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_DTLS_MAX_BUFFERING 190
2125a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2126a8e1175bSopenharmony_ci    make
2127a8e1175bSopenharmony_ci
2128a8e1175bSopenharmony_ci    msg "test: small MBEDTLS_SSL_DTLS_MAX_BUFFERING #1 - ssl-opt.sh specific reordering test"
2129a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f "DTLS reordering: Buffer encrypted Finished message, drop for fragmented NewSessionTicket"
2130a8e1175bSopenharmony_ci}
2131a8e1175bSopenharmony_ci
2132a8e1175bSopenharmony_cicomponent_test_psa_collect_statuses () {
2133a8e1175bSopenharmony_ci  msg "build+test: psa_collect_statuses" # ~30s
2134a8e1175bSopenharmony_ci  scripts/config.py full
2135a8e1175bSopenharmony_ci  tests/scripts/psa_collect_statuses.py
2136a8e1175bSopenharmony_ci  # Check that psa_crypto_init() succeeded at least once
2137a8e1175bSopenharmony_ci  grep -q '^0:psa_crypto_init:' tests/statuses.log
2138a8e1175bSopenharmony_ci  rm -f tests/statuses.log
2139a8e1175bSopenharmony_ci}
2140a8e1175bSopenharmony_ci
2141a8e1175bSopenharmony_cicomponent_test_full_cmake_clang () {
2142a8e1175bSopenharmony_ci    msg "build: cmake, full config, clang" # ~ 50s
2143a8e1175bSopenharmony_ci    scripts/config.py full
2144a8e1175bSopenharmony_ci    CC=clang CXX=clang cmake -D CMAKE_BUILD_TYPE:String=Release -D ENABLE_TESTING=On -D TEST_CPP=1 .
2145a8e1175bSopenharmony_ci    make
2146a8e1175bSopenharmony_ci
2147a8e1175bSopenharmony_ci    msg "test: main suites (full config, clang)" # ~ 5s
2148a8e1175bSopenharmony_ci    make test
2149a8e1175bSopenharmony_ci
2150a8e1175bSopenharmony_ci    msg "test: cpp_dummy_build (full config, clang)" # ~ 1s
2151a8e1175bSopenharmony_ci    programs/test/cpp_dummy_build
2152a8e1175bSopenharmony_ci
2153a8e1175bSopenharmony_ci    msg "test: metatests (clang)"
2154a8e1175bSopenharmony_ci    tests/scripts/run-metatests.sh any pthread
2155a8e1175bSopenharmony_ci
2156a8e1175bSopenharmony_ci    msg "program demos (full config, clang)" # ~10s
2157a8e1175bSopenharmony_ci    tests/scripts/run_demos.py
2158a8e1175bSopenharmony_ci
2159a8e1175bSopenharmony_ci    msg "test: psa_constant_names (full config, clang)" # ~ 1s
2160a8e1175bSopenharmony_ci    tests/scripts/test_psa_constant_names.py
2161a8e1175bSopenharmony_ci
2162a8e1175bSopenharmony_ci    msg "test: ssl-opt.sh default, ECJPAKE, SSL async (full config)" # ~ 1s
2163a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f 'Default\|ECJPAKE\|SSL async private'
2164a8e1175bSopenharmony_ci
2165a8e1175bSopenharmony_ci    msg "test: compat.sh NULL (full config)" # ~ 2 min
2166a8e1175bSopenharmony_ci    tests/compat.sh -e '^$' -f 'NULL'
2167a8e1175bSopenharmony_ci
2168a8e1175bSopenharmony_ci    msg "test: compat.sh ARIA + ChachaPoly"
2169a8e1175bSopenharmony_ci    env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
2170a8e1175bSopenharmony_ci}
2171a8e1175bSopenharmony_ci
2172a8e1175bSopenharmony_ciskip_suites_without_constant_flow () {
2173a8e1175bSopenharmony_ci    # Skip the test suites that don't have any constant-flow annotations.
2174a8e1175bSopenharmony_ci    # This will need to be adjusted if we ever start declaring things as
2175a8e1175bSopenharmony_ci    # secret from macros or functions inside tests/include or tests/src.
2176a8e1175bSopenharmony_ci    SKIP_TEST_SUITES=$(
2177a8e1175bSopenharmony_ci        git -C tests/suites grep -L TEST_CF_ 'test_suite_*.function' |
2178a8e1175bSopenharmony_ci            sed 's/test_suite_//; s/\.function$//' |
2179a8e1175bSopenharmony_ci            tr '\n' ,)
2180a8e1175bSopenharmony_ci    export SKIP_TEST_SUITES
2181a8e1175bSopenharmony_ci}
2182a8e1175bSopenharmony_ci
2183a8e1175bSopenharmony_ciskip_all_except_given_suite () {
2184a8e1175bSopenharmony_ci    # Skip all but the given test suite
2185a8e1175bSopenharmony_ci    SKIP_TEST_SUITES=$(
2186a8e1175bSopenharmony_ci        ls -1 tests/suites/test_suite_*.function |
2187a8e1175bSopenharmony_ci        grep -v $1.function |
2188a8e1175bSopenharmony_ci         sed 's/tests.suites.test_suite_//; s/\.function$//' |
2189a8e1175bSopenharmony_ci        tr '\n' ,)
2190a8e1175bSopenharmony_ci    export SKIP_TEST_SUITES
2191a8e1175bSopenharmony_ci}
2192a8e1175bSopenharmony_ci
2193a8e1175bSopenharmony_cicomponent_test_memsan_constant_flow () {
2194a8e1175bSopenharmony_ci    # This tests both (1) accesses to undefined memory, and (2) branches or
2195a8e1175bSopenharmony_ci    # memory access depending on secret values. To distinguish between those:
2196a8e1175bSopenharmony_ci    # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
2197a8e1175bSopenharmony_ci    # - or alternatively, change the build type to MemSanDbg, which enables
2198a8e1175bSopenharmony_ci    # origin tracking and nicer stack traces (which are useful for debugging
2199a8e1175bSopenharmony_ci    # anyway), and check if the origin was TEST_CF_SECRET() or something else.
2200a8e1175bSopenharmony_ci    msg "build: cmake MSan (clang), full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
2201a8e1175bSopenharmony_ci    scripts/config.py full
2202a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
2203a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2204a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
2205a8e1175bSopenharmony_ci    CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
2206a8e1175bSopenharmony_ci    make
2207a8e1175bSopenharmony_ci
2208a8e1175bSopenharmony_ci    msg "test: main suites (full minus MBEDTLS_USE_PSA_CRYPTO, Msan + constant flow)"
2209a8e1175bSopenharmony_ci    make test
2210a8e1175bSopenharmony_ci}
2211a8e1175bSopenharmony_ci
2212a8e1175bSopenharmony_cicomponent_test_memsan_constant_flow_psa () {
2213a8e1175bSopenharmony_ci    # This tests both (1) accesses to undefined memory, and (2) branches or
2214a8e1175bSopenharmony_ci    # memory access depending on secret values. To distinguish between those:
2215a8e1175bSopenharmony_ci    # - unset MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN - does the failure persist?
2216a8e1175bSopenharmony_ci    # - or alternatively, change the build type to MemSanDbg, which enables
2217a8e1175bSopenharmony_ci    # origin tracking and nicer stack traces (which are useful for debugging
2218a8e1175bSopenharmony_ci    # anyway), and check if the origin was TEST_CF_SECRET() or something else.
2219a8e1175bSopenharmony_ci    msg "build: cmake MSan (clang), full config with constant flow testing"
2220a8e1175bSopenharmony_ci    scripts/config.py full
2221a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
2222a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
2223a8e1175bSopenharmony_ci    CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
2224a8e1175bSopenharmony_ci    make
2225a8e1175bSopenharmony_ci
2226a8e1175bSopenharmony_ci    msg "test: main suites (Msan + constant flow)"
2227a8e1175bSopenharmony_ci    make test
2228a8e1175bSopenharmony_ci}
2229a8e1175bSopenharmony_ci
2230a8e1175bSopenharmony_cicomponent_release_test_valgrind_constant_flow () {
2231a8e1175bSopenharmony_ci    # This tests both (1) everything that valgrind's memcheck usually checks
2232a8e1175bSopenharmony_ci    # (heap buffer overflows, use of uninitialized memory, use-after-free,
2233a8e1175bSopenharmony_ci    # etc.) and (2) branches or memory access depending on secret values,
2234a8e1175bSopenharmony_ci    # which will be reported as uninitialized memory. To distinguish between
2235a8e1175bSopenharmony_ci    # secret and actually uninitialized:
2236a8e1175bSopenharmony_ci    # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
2237a8e1175bSopenharmony_ci    # - or alternatively, build with debug info and manually run the offending
2238a8e1175bSopenharmony_ci    # test suite with valgrind --track-origins=yes, then check if the origin
2239a8e1175bSopenharmony_ci    # was TEST_CF_SECRET() or something else.
2240a8e1175bSopenharmony_ci    msg "build: cmake release GCC, full config minus MBEDTLS_USE_PSA_CRYPTO with constant flow testing"
2241a8e1175bSopenharmony_ci    scripts/config.py full
2242a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
2243a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2244a8e1175bSopenharmony_ci    skip_suites_without_constant_flow
2245a8e1175bSopenharmony_ci    cmake -D CMAKE_BUILD_TYPE:String=Release .
2246a8e1175bSopenharmony_ci    make
2247a8e1175bSopenharmony_ci
2248a8e1175bSopenharmony_ci    # this only shows a summary of the results (how many of each type)
2249a8e1175bSopenharmony_ci    # details are left in Testing/<date>/DynamicAnalysis.xml
2250a8e1175bSopenharmony_ci    msg "test: some suites (full minus MBEDTLS_USE_PSA_CRYPTO, valgrind + constant flow)"
2251a8e1175bSopenharmony_ci    make memcheck
2252a8e1175bSopenharmony_ci
2253a8e1175bSopenharmony_ci    # Test asm path in constant time module - by default, it will test the plain C
2254a8e1175bSopenharmony_ci    # path under Valgrind or Memsan. Running only the constant_time tests is fast (<1s)
2255a8e1175bSopenharmony_ci    msg "test: valgrind asm constant_time"
2256a8e1175bSopenharmony_ci    scripts/config.py --force set MBEDTLS_TEST_CONSTANT_FLOW_ASM
2257a8e1175bSopenharmony_ci    skip_all_except_given_suite test_suite_constant_time
2258a8e1175bSopenharmony_ci    cmake -D CMAKE_BUILD_TYPE:String=Release .
2259a8e1175bSopenharmony_ci    make clean
2260a8e1175bSopenharmony_ci    make
2261a8e1175bSopenharmony_ci    make memcheck
2262a8e1175bSopenharmony_ci}
2263a8e1175bSopenharmony_ci
2264a8e1175bSopenharmony_cicomponent_release_test_valgrind_constant_flow_psa () {
2265a8e1175bSopenharmony_ci    # This tests both (1) everything that valgrind's memcheck usually checks
2266a8e1175bSopenharmony_ci    # (heap buffer overflows, use of uninitialized memory, use-after-free,
2267a8e1175bSopenharmony_ci    # etc.) and (2) branches or memory access depending on secret values,
2268a8e1175bSopenharmony_ci    # which will be reported as uninitialized memory. To distinguish between
2269a8e1175bSopenharmony_ci    # secret and actually uninitialized:
2270a8e1175bSopenharmony_ci    # - unset MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND - does the failure persist?
2271a8e1175bSopenharmony_ci    # - or alternatively, build with debug info and manually run the offending
2272a8e1175bSopenharmony_ci    # test suite with valgrind --track-origins=yes, then check if the origin
2273a8e1175bSopenharmony_ci    # was TEST_CF_SECRET() or something else.
2274a8e1175bSopenharmony_ci    msg "build: cmake release GCC, full config with constant flow testing"
2275a8e1175bSopenharmony_ci    scripts/config.py full
2276a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
2277a8e1175bSopenharmony_ci    skip_suites_without_constant_flow
2278a8e1175bSopenharmony_ci    cmake -D CMAKE_BUILD_TYPE:String=Release .
2279a8e1175bSopenharmony_ci    make
2280a8e1175bSopenharmony_ci
2281a8e1175bSopenharmony_ci    # this only shows a summary of the results (how many of each type)
2282a8e1175bSopenharmony_ci    # details are left in Testing/<date>/DynamicAnalysis.xml
2283a8e1175bSopenharmony_ci    msg "test: some suites (valgrind + constant flow)"
2284a8e1175bSopenharmony_ci    make memcheck
2285a8e1175bSopenharmony_ci}
2286a8e1175bSopenharmony_ci
2287a8e1175bSopenharmony_cicomponent_test_tsan () {
2288a8e1175bSopenharmony_ci    msg "build: TSan (clang)"
2289a8e1175bSopenharmony_ci    scripts/config.py full
2290a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_THREADING_C
2291a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_THREADING_PTHREAD
2292a8e1175bSopenharmony_ci    # Self-tests do not currently use multiple threads.
2293a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SELF_TEST
2294a8e1175bSopenharmony_ci
2295a8e1175bSopenharmony_ci    # The deprecated MBEDTLS_PSA_CRYPTO_SE_C interface is not thread safe.
2296a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
2297a8e1175bSopenharmony_ci
2298a8e1175bSopenharmony_ci    CC=clang cmake -D CMAKE_BUILD_TYPE:String=TSan .
2299a8e1175bSopenharmony_ci    make
2300a8e1175bSopenharmony_ci
2301a8e1175bSopenharmony_ci    msg "test: main suites (TSan)"
2302a8e1175bSopenharmony_ci    make test
2303a8e1175bSopenharmony_ci}
2304a8e1175bSopenharmony_ci
2305a8e1175bSopenharmony_cicomponent_test_default_no_deprecated () {
2306a8e1175bSopenharmony_ci    # Test that removing the deprecated features from the default
2307a8e1175bSopenharmony_ci    # configuration leaves something consistent.
2308a8e1175bSopenharmony_ci    msg "build: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 30s
2309a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
2310a8e1175bSopenharmony_ci    make CFLAGS='-O -Werror -Wall -Wextra'
2311a8e1175bSopenharmony_ci
2312a8e1175bSopenharmony_ci    msg "test: make, default + MBEDTLS_DEPRECATED_REMOVED" # ~ 5s
2313a8e1175bSopenharmony_ci    make test
2314a8e1175bSopenharmony_ci}
2315a8e1175bSopenharmony_ci
2316a8e1175bSopenharmony_cicomponent_test_full_no_deprecated () {
2317a8e1175bSopenharmony_ci    msg "build: make, full_no_deprecated config" # ~ 30s
2318a8e1175bSopenharmony_ci    scripts/config.py full_no_deprecated
2319a8e1175bSopenharmony_ci    make CFLAGS='-O -Werror -Wall -Wextra'
2320a8e1175bSopenharmony_ci
2321a8e1175bSopenharmony_ci    msg "test: make, full_no_deprecated config" # ~ 5s
2322a8e1175bSopenharmony_ci    make test
2323a8e1175bSopenharmony_ci
2324a8e1175bSopenharmony_ci    msg "test: ensure that X509 has no direct dependency on BIGNUM_C"
2325a8e1175bSopenharmony_ci    not grep mbedtls_mpi library/libmbedx509.a
2326a8e1175bSopenharmony_ci}
2327a8e1175bSopenharmony_ci
2328a8e1175bSopenharmony_cicomponent_test_full_no_deprecated_deprecated_warning () {
2329a8e1175bSopenharmony_ci    # Test that there is nothing deprecated in "full_no_deprecated".
2330a8e1175bSopenharmony_ci    # A deprecated feature would trigger a warning (made fatal) from
2331a8e1175bSopenharmony_ci    # MBEDTLS_DEPRECATED_WARNING.
2332a8e1175bSopenharmony_ci    msg "build: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 30s
2333a8e1175bSopenharmony_ci    scripts/config.py full_no_deprecated
2334a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_DEPRECATED_REMOVED
2335a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_DEPRECATED_WARNING
2336a8e1175bSopenharmony_ci    make CFLAGS='-O -Werror -Wall -Wextra'
2337a8e1175bSopenharmony_ci
2338a8e1175bSopenharmony_ci    msg "test: make, full_no_deprecated config, MBEDTLS_DEPRECATED_WARNING" # ~ 5s
2339a8e1175bSopenharmony_ci    make test
2340a8e1175bSopenharmony_ci}
2341a8e1175bSopenharmony_ci
2342a8e1175bSopenharmony_cicomponent_test_full_deprecated_warning () {
2343a8e1175bSopenharmony_ci    # Test that when MBEDTLS_DEPRECATED_WARNING is enabled, the build passes
2344a8e1175bSopenharmony_ci    # with only certain whitelisted types of warnings.
2345a8e1175bSopenharmony_ci    msg "build: make, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
2346a8e1175bSopenharmony_ci    scripts/config.py full
2347a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_DEPRECATED_WARNING
2348a8e1175bSopenharmony_ci    # Expect warnings from '#warning' directives in check_config.h.
2349a8e1175bSopenharmony_ci    # Note that gcc is required to allow the use of -Wno-error=cpp, which allows us to
2350a8e1175bSopenharmony_ci    # display #warning messages without them being treated as errors.
2351a8e1175bSopenharmony_ci    make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=cpp' lib programs
2352a8e1175bSopenharmony_ci
2353a8e1175bSopenharmony_ci    msg "build: make tests, full config + MBEDTLS_DEPRECATED_WARNING, expect warnings" # ~ 30s
2354a8e1175bSopenharmony_ci    # Set MBEDTLS_TEST_DEPRECATED to enable tests for deprecated features.
2355a8e1175bSopenharmony_ci    # By default those are disabled when MBEDTLS_DEPRECATED_WARNING is set.
2356a8e1175bSopenharmony_ci    # Expect warnings from '#warning' directives in check_config.h and
2357a8e1175bSopenharmony_ci    # from the use of deprecated functions in test suites.
2358a8e1175bSopenharmony_ci    make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-error=deprecated-declarations -Wno-error=cpp -DMBEDTLS_TEST_DEPRECATED' tests
2359a8e1175bSopenharmony_ci
2360a8e1175bSopenharmony_ci    msg "test: full config + MBEDTLS_TEST_DEPRECATED" # ~ 30s
2361a8e1175bSopenharmony_ci    make test
2362a8e1175bSopenharmony_ci
2363a8e1175bSopenharmony_ci    msg "program demos: full config + MBEDTLS_TEST_DEPRECATED" # ~10s
2364a8e1175bSopenharmony_ci    tests/scripts/run_demos.py
2365a8e1175bSopenharmony_ci}
2366a8e1175bSopenharmony_ci
2367a8e1175bSopenharmony_ci# Check that the specified libraries exist and are empty.
2368a8e1175bSopenharmony_ciare_empty_libraries () {
2369a8e1175bSopenharmony_ci  nm "$@" >/dev/null 2>/dev/null
2370a8e1175bSopenharmony_ci  ! nm "$@" 2>/dev/null | grep -v ':$' | grep .
2371a8e1175bSopenharmony_ci}
2372a8e1175bSopenharmony_ci
2373a8e1175bSopenharmony_cicomponent_build_crypto_default () {
2374a8e1175bSopenharmony_ci  msg "build: make, crypto only"
2375a8e1175bSopenharmony_ci  scripts/config.py crypto
2376a8e1175bSopenharmony_ci  make CFLAGS='-O1 -Werror'
2377a8e1175bSopenharmony_ci  are_empty_libraries library/libmbedx509.* library/libmbedtls.*
2378a8e1175bSopenharmony_ci}
2379a8e1175bSopenharmony_ci
2380a8e1175bSopenharmony_cicomponent_build_crypto_full () {
2381a8e1175bSopenharmony_ci  msg "build: make, crypto only, full config"
2382a8e1175bSopenharmony_ci  scripts/config.py crypto_full
2383a8e1175bSopenharmony_ci  make CFLAGS='-O1 -Werror'
2384a8e1175bSopenharmony_ci  are_empty_libraries library/libmbedx509.* library/libmbedtls.*
2385a8e1175bSopenharmony_ci}
2386a8e1175bSopenharmony_ci
2387a8e1175bSopenharmony_cicomponent_test_crypto_for_psa_service () {
2388a8e1175bSopenharmony_ci  msg "build: make, config for PSA crypto service"
2389a8e1175bSopenharmony_ci  scripts/config.py crypto
2390a8e1175bSopenharmony_ci  scripts/config.py set MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
2391a8e1175bSopenharmony_ci  # Disable things that are not needed for just cryptography, to
2392a8e1175bSopenharmony_ci  # reach a configuration that would be typical for a PSA cryptography
2393a8e1175bSopenharmony_ci  # service providing all implemented PSA algorithms.
2394a8e1175bSopenharmony_ci  # System stuff
2395a8e1175bSopenharmony_ci  scripts/config.py unset MBEDTLS_ERROR_C
2396a8e1175bSopenharmony_ci  scripts/config.py unset MBEDTLS_TIMING_C
2397a8e1175bSopenharmony_ci  scripts/config.py unset MBEDTLS_VERSION_FEATURES
2398a8e1175bSopenharmony_ci  # Crypto stuff with no PSA interface
2399a8e1175bSopenharmony_ci  scripts/config.py unset MBEDTLS_BASE64_C
2400a8e1175bSopenharmony_ci  # Keep MBEDTLS_CIPHER_C because psa_crypto_cipher, CCM and GCM need it.
2401a8e1175bSopenharmony_ci  scripts/config.py unset MBEDTLS_HKDF_C # PSA's HKDF is independent
2402a8e1175bSopenharmony_ci  # Keep MBEDTLS_MD_C because deterministic ECDSA needs it for HMAC_DRBG.
2403a8e1175bSopenharmony_ci  scripts/config.py unset MBEDTLS_NIST_KW_C
2404a8e1175bSopenharmony_ci  scripts/config.py unset MBEDTLS_PEM_PARSE_C
2405a8e1175bSopenharmony_ci  scripts/config.py unset MBEDTLS_PEM_WRITE_C
2406a8e1175bSopenharmony_ci  scripts/config.py unset MBEDTLS_PKCS12_C
2407a8e1175bSopenharmony_ci  scripts/config.py unset MBEDTLS_PKCS5_C
2408a8e1175bSopenharmony_ci  # MBEDTLS_PK_PARSE_C and MBEDTLS_PK_WRITE_C are actually currently needed
2409a8e1175bSopenharmony_ci  # in PSA code to work with RSA keys. We don't require users to set those:
2410a8e1175bSopenharmony_ci  # they will be reenabled in build_info.h.
2411a8e1175bSopenharmony_ci  scripts/config.py unset MBEDTLS_PK_C
2412a8e1175bSopenharmony_ci  scripts/config.py unset MBEDTLS_PK_PARSE_C
2413a8e1175bSopenharmony_ci  scripts/config.py unset MBEDTLS_PK_WRITE_C
2414a8e1175bSopenharmony_ci  make CFLAGS='-O1 -Werror' all test
2415a8e1175bSopenharmony_ci  are_empty_libraries library/libmbedx509.* library/libmbedtls.*
2416a8e1175bSopenharmony_ci}
2417a8e1175bSopenharmony_ci
2418a8e1175bSopenharmony_cicomponent_build_crypto_baremetal () {
2419a8e1175bSopenharmony_ci  msg "build: make, crypto only, baremetal config"
2420a8e1175bSopenharmony_ci  scripts/config.py crypto_baremetal
2421a8e1175bSopenharmony_ci  make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
2422a8e1175bSopenharmony_ci  are_empty_libraries library/libmbedx509.* library/libmbedtls.*
2423a8e1175bSopenharmony_ci}
2424a8e1175bSopenharmony_cisupport_build_crypto_baremetal () {
2425a8e1175bSopenharmony_ci    support_build_baremetal "$@"
2426a8e1175bSopenharmony_ci}
2427a8e1175bSopenharmony_ci
2428a8e1175bSopenharmony_cicomponent_build_baremetal () {
2429a8e1175bSopenharmony_ci  msg "build: make, baremetal config"
2430a8e1175bSopenharmony_ci  scripts/config.py baremetal
2431a8e1175bSopenharmony_ci  make CFLAGS="-O1 -Werror -I$PWD/tests/include/baremetal-override/"
2432a8e1175bSopenharmony_ci}
2433a8e1175bSopenharmony_cisupport_build_baremetal () {
2434a8e1175bSopenharmony_ci    # Older Glibc versions include time.h from other headers such as stdlib.h,
2435a8e1175bSopenharmony_ci    # which makes the no-time.h-in-baremetal check fail. Ubuntu 16.04 has this
2436a8e1175bSopenharmony_ci    # problem, Ubuntu 18.04 is ok.
2437a8e1175bSopenharmony_ci    ! grep -q -F time.h /usr/include/x86_64-linux-gnu/sys/types.h
2438a8e1175bSopenharmony_ci}
2439a8e1175bSopenharmony_ci
2440a8e1175bSopenharmony_ci# depends.py family of tests
2441a8e1175bSopenharmony_cicomponent_test_depends_py_cipher_id () {
2442a8e1175bSopenharmony_ci    msg "test/build: depends.py cipher_id (gcc)"
2443a8e1175bSopenharmony_ci    tests/scripts/depends.py cipher_id --unset-use-psa
2444a8e1175bSopenharmony_ci}
2445a8e1175bSopenharmony_ci
2446a8e1175bSopenharmony_cicomponent_test_depends_py_cipher_chaining () {
2447a8e1175bSopenharmony_ci    msg "test/build: depends.py cipher_chaining (gcc)"
2448a8e1175bSopenharmony_ci    tests/scripts/depends.py cipher_chaining --unset-use-psa
2449a8e1175bSopenharmony_ci}
2450a8e1175bSopenharmony_ci
2451a8e1175bSopenharmony_cicomponent_test_depends_py_cipher_padding () {
2452a8e1175bSopenharmony_ci    msg "test/build: depends.py cipher_padding (gcc)"
2453a8e1175bSopenharmony_ci    tests/scripts/depends.py cipher_padding --unset-use-psa
2454a8e1175bSopenharmony_ci}
2455a8e1175bSopenharmony_ci
2456a8e1175bSopenharmony_cicomponent_test_depends_py_curves () {
2457a8e1175bSopenharmony_ci    msg "test/build: depends.py curves (gcc)"
2458a8e1175bSopenharmony_ci    tests/scripts/depends.py curves --unset-use-psa
2459a8e1175bSopenharmony_ci}
2460a8e1175bSopenharmony_ci
2461a8e1175bSopenharmony_cicomponent_test_depends_py_hashes () {
2462a8e1175bSopenharmony_ci    msg "test/build: depends.py hashes (gcc)"
2463a8e1175bSopenharmony_ci    tests/scripts/depends.py hashes --unset-use-psa
2464a8e1175bSopenharmony_ci}
2465a8e1175bSopenharmony_ci
2466a8e1175bSopenharmony_cicomponent_test_depends_py_kex () {
2467a8e1175bSopenharmony_ci    msg "test/build: depends.py kex (gcc)"
2468a8e1175bSopenharmony_ci    tests/scripts/depends.py kex --unset-use-psa
2469a8e1175bSopenharmony_ci}
2470a8e1175bSopenharmony_ci
2471a8e1175bSopenharmony_cicomponent_test_depends_py_pkalgs () {
2472a8e1175bSopenharmony_ci    msg "test/build: depends.py pkalgs (gcc)"
2473a8e1175bSopenharmony_ci    tests/scripts/depends.py pkalgs --unset-use-psa
2474a8e1175bSopenharmony_ci}
2475a8e1175bSopenharmony_ci
2476a8e1175bSopenharmony_ci# PSA equivalents of the depends.py tests
2477a8e1175bSopenharmony_cicomponent_test_depends_py_cipher_id_psa () {
2478a8e1175bSopenharmony_ci    msg "test/build: depends.py cipher_id (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2479a8e1175bSopenharmony_ci    tests/scripts/depends.py cipher_id
2480a8e1175bSopenharmony_ci}
2481a8e1175bSopenharmony_ci
2482a8e1175bSopenharmony_cicomponent_test_depends_py_cipher_chaining_psa () {
2483a8e1175bSopenharmony_ci    msg "test/build: depends.py cipher_chaining (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2484a8e1175bSopenharmony_ci    tests/scripts/depends.py cipher_chaining
2485a8e1175bSopenharmony_ci}
2486a8e1175bSopenharmony_ci
2487a8e1175bSopenharmony_cicomponent_test_depends_py_cipher_padding_psa () {
2488a8e1175bSopenharmony_ci    msg "test/build: depends.py cipher_padding (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2489a8e1175bSopenharmony_ci    tests/scripts/depends.py cipher_padding
2490a8e1175bSopenharmony_ci}
2491a8e1175bSopenharmony_ci
2492a8e1175bSopenharmony_cicomponent_test_depends_py_curves_psa () {
2493a8e1175bSopenharmony_ci    msg "test/build: depends.py curves (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2494a8e1175bSopenharmony_ci    tests/scripts/depends.py curves
2495a8e1175bSopenharmony_ci}
2496a8e1175bSopenharmony_ci
2497a8e1175bSopenharmony_cicomponent_test_depends_py_hashes_psa () {
2498a8e1175bSopenharmony_ci    msg "test/build: depends.py hashes (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2499a8e1175bSopenharmony_ci    tests/scripts/depends.py hashes
2500a8e1175bSopenharmony_ci}
2501a8e1175bSopenharmony_ci
2502a8e1175bSopenharmony_cicomponent_test_depends_py_kex_psa () {
2503a8e1175bSopenharmony_ci    msg "test/build: depends.py kex (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2504a8e1175bSopenharmony_ci    tests/scripts/depends.py kex
2505a8e1175bSopenharmony_ci}
2506a8e1175bSopenharmony_ci
2507a8e1175bSopenharmony_cicomponent_test_depends_py_pkalgs_psa () {
2508a8e1175bSopenharmony_ci    msg "test/build: depends.py pkalgs (gcc) with MBEDTLS_USE_PSA_CRYPTO defined"
2509a8e1175bSopenharmony_ci    tests/scripts/depends.py pkalgs
2510a8e1175bSopenharmony_ci}
2511a8e1175bSopenharmony_ci
2512a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_ffdh_2048_only () {
2513a8e1175bSopenharmony_ci    msg "build: full config - only DH 2048"
2514a8e1175bSopenharmony_ci
2515a8e1175bSopenharmony_ci    scripts/config.py full
2516a8e1175bSopenharmony_ci
2517a8e1175bSopenharmony_ci    # Disable all DH groups other than 2048.
2518a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_3072
2519a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_4096
2520a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_6144
2521a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_DH_RFC7919_8192
2522a8e1175bSopenharmony_ci
2523a8e1175bSopenharmony_ci    make CFLAGS="$ASAN_CFLAGS -Werror" LDFLAGS="$ASAN_CFLAGS"
2524a8e1175bSopenharmony_ci
2525a8e1175bSopenharmony_ci    msg "test: full config - only DH 2048"
2526a8e1175bSopenharmony_ci    make test
2527a8e1175bSopenharmony_ci
2528a8e1175bSopenharmony_ci    msg "ssl-opt: full config - only DH 2048"
2529a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f "ffdh"
2530a8e1175bSopenharmony_ci}
2531a8e1175bSopenharmony_ci
2532a8e1175bSopenharmony_cicomponent_build_no_pk_rsa_alt_support () {
2533a8e1175bSopenharmony_ci    msg "build: !MBEDTLS_PK_RSA_ALT_SUPPORT" # ~30s
2534a8e1175bSopenharmony_ci
2535a8e1175bSopenharmony_ci    scripts/config.py full
2536a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PK_RSA_ALT_SUPPORT
2537a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_RSA_C
2538a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_X509_CRT_WRITE_C
2539a8e1175bSopenharmony_ci
2540a8e1175bSopenharmony_ci    # Only compile - this is primarily to test for compile issues
2541a8e1175bSopenharmony_ci    make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy'
2542a8e1175bSopenharmony_ci}
2543a8e1175bSopenharmony_ci
2544a8e1175bSopenharmony_cicomponent_build_module_alt () {
2545a8e1175bSopenharmony_ci    msg "build: MBEDTLS_XXX_ALT" # ~30s
2546a8e1175bSopenharmony_ci    scripts/config.py full
2547a8e1175bSopenharmony_ci
2548a8e1175bSopenharmony_ci    # Disable options that are incompatible with some ALT implementations:
2549a8e1175bSopenharmony_ci    # aesni.c and padlock.c reference mbedtls_aes_context fields directly.
2550a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESNI_C
2551a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PADLOCK_C
2552a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESCE_C
2553a8e1175bSopenharmony_ci    # MBEDTLS_ECP_RESTARTABLE is documented as incompatible.
2554a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2555a8e1175bSopenharmony_ci    # You can only have one threading implementation: alt or pthread, not both.
2556a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_THREADING_PTHREAD
2557a8e1175bSopenharmony_ci    # The SpecifiedECDomain parsing code accesses mbedtls_ecp_group fields
2558a8e1175bSopenharmony_ci    # directly and assumes the implementation works with partial groups.
2559a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
2560a8e1175bSopenharmony_ci    # MBEDTLS_SHA256_*ALT can't be used with MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*
2561a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
2562a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
2563a8e1175bSopenharmony_ci    # MBEDTLS_SHA512_*ALT can't be used with MBEDTLS_SHA512_USE_A64_CRYPTO_*
2564a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
2565a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY
2566a8e1175bSopenharmony_ci
2567a8e1175bSopenharmony_ci    # Enable all MBEDTLS_XXX_ALT for whole modules. Do not enable
2568a8e1175bSopenharmony_ci    # MBEDTLS_XXX_YYY_ALT which are for single functions.
2569a8e1175bSopenharmony_ci    scripts/config.py set-all 'MBEDTLS_([A-Z0-9]*|NIST_KW)_ALT'
2570a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_DHM_ALT #incompatible with MBEDTLS_DEBUG_C
2571a8e1175bSopenharmony_ci
2572a8e1175bSopenharmony_ci    # We can only compile, not link, since we don't have any implementations
2573a8e1175bSopenharmony_ci    # suitable for testing with the dummy alt headers.
2574a8e1175bSopenharmony_ci    make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
2575a8e1175bSopenharmony_ci}
2576a8e1175bSopenharmony_ci
2577a8e1175bSopenharmony_cicomponent_build_dhm_alt () {
2578a8e1175bSopenharmony_ci    msg "build: MBEDTLS_DHM_ALT" # ~30s
2579a8e1175bSopenharmony_ci    scripts/config.py full
2580a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_DHM_ALT
2581a8e1175bSopenharmony_ci    # debug.c currently references mbedtls_dhm_context fields directly.
2582a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_DEBUG_C
2583a8e1175bSopenharmony_ci    # We can only compile, not link, since we don't have any implementations
2584a8e1175bSopenharmony_ci    # suitable for testing with the dummy alt headers.
2585a8e1175bSopenharmony_ci    make CFLAGS='-Werror -Wall -Wextra -I../tests/include/alt-dummy' lib
2586a8e1175bSopenharmony_ci}
2587a8e1175bSopenharmony_ci
2588a8e1175bSopenharmony_cicomponent_test_no_psa_crypto_full_cmake_asan() {
2589a8e1175bSopenharmony_ci    # full minus MBEDTLS_PSA_CRYPTO_C: run the same set of tests as basic-build-test.sh
2590a8e1175bSopenharmony_ci    msg "build: cmake, full config minus PSA crypto, ASan"
2591a8e1175bSopenharmony_ci    scripts/config.py full
2592a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_C
2593a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_CLIENT
2594a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
2595a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
2596a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
2597a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
2598a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
2599a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_LMS_C
2600a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_LMS_PRIVATE
2601a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
2602a8e1175bSopenharmony_ci    make
2603a8e1175bSopenharmony_ci
2604a8e1175bSopenharmony_ci    msg "test: main suites (full minus PSA crypto)"
2605a8e1175bSopenharmony_ci    make test
2606a8e1175bSopenharmony_ci
2607a8e1175bSopenharmony_ci    # Note: ssl-opt.sh has some test cases that depend on
2608a8e1175bSopenharmony_ci    # MBEDTLS_ECP_RESTARTABLE && !MBEDTLS_USE_PSA_CRYPTO
2609a8e1175bSopenharmony_ci    # This is the only component where those tests are not skipped.
2610a8e1175bSopenharmony_ci    msg "test: ssl-opt.sh (full minus PSA crypto)"
2611a8e1175bSopenharmony_ci    tests/ssl-opt.sh
2612a8e1175bSopenharmony_ci
2613a8e1175bSopenharmony_ci    msg "test: compat.sh default (full minus PSA crypto)"
2614a8e1175bSopenharmony_ci    tests/compat.sh
2615a8e1175bSopenharmony_ci
2616a8e1175bSopenharmony_ci    msg "test: compat.sh NULL (full minus PSA crypto)"
2617a8e1175bSopenharmony_ci    tests/compat.sh -f 'NULL'
2618a8e1175bSopenharmony_ci
2619a8e1175bSopenharmony_ci    msg "test: compat.sh ARIA + ChachaPoly (full minus PSA crypto)"
2620a8e1175bSopenharmony_ci    env OPENSSL="$OPENSSL_NEXT" tests/compat.sh -e '^$' -f 'ARIA\|CHACHA'
2621a8e1175bSopenharmony_ci}
2622a8e1175bSopenharmony_ci
2623a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_ecdsa () {
2624a8e1175bSopenharmony_ci    msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
2625a8e1175bSopenharmony_ci
2626a8e1175bSopenharmony_ci    # Algorithms and key types to accelerate
2627a8e1175bSopenharmony_ci    loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2628a8e1175bSopenharmony_ci                    $(helper_get_psa_key_type_list "ECC") \
2629a8e1175bSopenharmony_ci                    $(helper_get_psa_curve_list)"
2630a8e1175bSopenharmony_ci
2631a8e1175bSopenharmony_ci    # Configure
2632a8e1175bSopenharmony_ci    # ---------
2633a8e1175bSopenharmony_ci
2634a8e1175bSopenharmony_ci    # Start from default config (no USE_PSA) + TLS 1.3
2635a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "default"
2636a8e1175bSopenharmony_ci
2637a8e1175bSopenharmony_ci    # Disable the module that's accelerated
2638a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDSA_C
2639a8e1175bSopenharmony_ci
2640a8e1175bSopenharmony_ci    # Disable things that depend on it
2641a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2642a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2643a8e1175bSopenharmony_ci
2644a8e1175bSopenharmony_ci    # Build
2645a8e1175bSopenharmony_ci    # -----
2646a8e1175bSopenharmony_ci
2647a8e1175bSopenharmony_ci    # These hashes are needed for some ECDSA signature tests.
2648a8e1175bSopenharmony_ci    loc_extra_list="ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2649a8e1175bSopenharmony_ci                    ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2650a8e1175bSopenharmony_ci
2651a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2652a8e1175bSopenharmony_ci
2653a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
2654a8e1175bSopenharmony_ci
2655a8e1175bSopenharmony_ci    # Make sure this was not re-enabled by accident (additive config)
2656a8e1175bSopenharmony_ci    not grep mbedtls_ecdsa_ library/ecdsa.o
2657a8e1175bSopenharmony_ci
2658a8e1175bSopenharmony_ci    # Run the tests
2659a8e1175bSopenharmony_ci    # -------------
2660a8e1175bSopenharmony_ci
2661a8e1175bSopenharmony_ci    msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDSA"
2662a8e1175bSopenharmony_ci    make test
2663a8e1175bSopenharmony_ci}
2664a8e1175bSopenharmony_ci
2665a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_ecdh () {
2666a8e1175bSopenharmony_ci    msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
2667a8e1175bSopenharmony_ci
2668a8e1175bSopenharmony_ci    # Algorithms and key types to accelerate
2669a8e1175bSopenharmony_ci    loc_accel_list="ALG_ECDH \
2670a8e1175bSopenharmony_ci                    $(helper_get_psa_key_type_list "ECC") \
2671a8e1175bSopenharmony_ci                    $(helper_get_psa_curve_list)"
2672a8e1175bSopenharmony_ci
2673a8e1175bSopenharmony_ci    # Configure
2674a8e1175bSopenharmony_ci    # ---------
2675a8e1175bSopenharmony_ci
2676a8e1175bSopenharmony_ci    # Start from default config (no USE_PSA)
2677a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "default"
2678a8e1175bSopenharmony_ci
2679a8e1175bSopenharmony_ci    # Disable the module that's accelerated
2680a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDH_C
2681a8e1175bSopenharmony_ci
2682a8e1175bSopenharmony_ci    # Disable things that depend on it
2683a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
2684a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
2685a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
2686a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
2687a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
2688a8e1175bSopenharmony_ci
2689a8e1175bSopenharmony_ci    # Build
2690a8e1175bSopenharmony_ci    # -----
2691a8e1175bSopenharmony_ci
2692a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list"
2693a8e1175bSopenharmony_ci
2694a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
2695a8e1175bSopenharmony_ci
2696a8e1175bSopenharmony_ci    # Make sure this was not re-enabled by accident (additive config)
2697a8e1175bSopenharmony_ci    not grep mbedtls_ecdh_ library/ecdh.o
2698a8e1175bSopenharmony_ci
2699a8e1175bSopenharmony_ci    # Run the tests
2700a8e1175bSopenharmony_ci    # -------------
2701a8e1175bSopenharmony_ci
2702a8e1175bSopenharmony_ci    msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated ECDH"
2703a8e1175bSopenharmony_ci    make test
2704a8e1175bSopenharmony_ci}
2705a8e1175bSopenharmony_ci
2706a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_ffdh () {
2707a8e1175bSopenharmony_ci    msg "build: full with accelerated FFDH"
2708a8e1175bSopenharmony_ci
2709a8e1175bSopenharmony_ci    # Algorithms and key types to accelerate
2710a8e1175bSopenharmony_ci    loc_accel_list="ALG_FFDH \
2711a8e1175bSopenharmony_ci                    $(helper_get_psa_key_type_list "DH") \
2712a8e1175bSopenharmony_ci                    $(helper_get_psa_dh_group_list)"
2713a8e1175bSopenharmony_ci
2714a8e1175bSopenharmony_ci    # Configure
2715a8e1175bSopenharmony_ci    # ---------
2716a8e1175bSopenharmony_ci
2717a8e1175bSopenharmony_ci    # start with full (USE_PSA and TLS 1.3)
2718a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "full"
2719a8e1175bSopenharmony_ci
2720a8e1175bSopenharmony_ci    # Disable the module that's accelerated
2721a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_DHM_C
2722a8e1175bSopenharmony_ci
2723a8e1175bSopenharmony_ci    # Disable things that depend on it
2724a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2725a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2726a8e1175bSopenharmony_ci
2727a8e1175bSopenharmony_ci    # Build
2728a8e1175bSopenharmony_ci    # -----
2729a8e1175bSopenharmony_ci
2730a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list"
2731a8e1175bSopenharmony_ci
2732a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
2733a8e1175bSopenharmony_ci
2734a8e1175bSopenharmony_ci    # Make sure this was not re-enabled by accident (additive config)
2735a8e1175bSopenharmony_ci    not grep mbedtls_dhm_ library/dhm.o
2736a8e1175bSopenharmony_ci
2737a8e1175bSopenharmony_ci    # Run the tests
2738a8e1175bSopenharmony_ci    # -------------
2739a8e1175bSopenharmony_ci
2740a8e1175bSopenharmony_ci    msg "test: full with accelerated FFDH"
2741a8e1175bSopenharmony_ci    make test
2742a8e1175bSopenharmony_ci
2743a8e1175bSopenharmony_ci    msg "ssl-opt: full with accelerated FFDH alg"
2744a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f "ffdh"
2745a8e1175bSopenharmony_ci}
2746a8e1175bSopenharmony_ci
2747a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_reference_ffdh () {
2748a8e1175bSopenharmony_ci    msg "build: full with non-accelerated FFDH"
2749a8e1175bSopenharmony_ci
2750a8e1175bSopenharmony_ci    # Start with full (USE_PSA and TLS 1.3)
2751a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "full"
2752a8e1175bSopenharmony_ci
2753a8e1175bSopenharmony_ci    # Disable things that are not supported
2754a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
2755a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
2756a8e1175bSopenharmony_ci    make
2757a8e1175bSopenharmony_ci
2758a8e1175bSopenharmony_ci    msg "test suites: full with non-accelerated FFDH alg"
2759a8e1175bSopenharmony_ci    make test
2760a8e1175bSopenharmony_ci
2761a8e1175bSopenharmony_ci    msg "ssl-opt: full with non-accelerated FFDH alg"
2762a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f "ffdh"
2763a8e1175bSopenharmony_ci}
2764a8e1175bSopenharmony_ci
2765a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_pake() {
2766a8e1175bSopenharmony_ci    msg "build: full with accelerated PAKE"
2767a8e1175bSopenharmony_ci
2768a8e1175bSopenharmony_ci    loc_accel_list="ALG_JPAKE \
2769a8e1175bSopenharmony_ci                    $(helper_get_psa_key_type_list "ECC") \
2770a8e1175bSopenharmony_ci                    $(helper_get_psa_curve_list)"
2771a8e1175bSopenharmony_ci
2772a8e1175bSopenharmony_ci    # Configure
2773a8e1175bSopenharmony_ci    # ---------
2774a8e1175bSopenharmony_ci
2775a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "full"
2776a8e1175bSopenharmony_ci
2777a8e1175bSopenharmony_ci    # Make built-in fallback not available
2778a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECJPAKE_C
2779a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
2780a8e1175bSopenharmony_ci
2781a8e1175bSopenharmony_ci    # Build
2782a8e1175bSopenharmony_ci    # -----
2783a8e1175bSopenharmony_ci
2784a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list"
2785a8e1175bSopenharmony_ci
2786a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
2787a8e1175bSopenharmony_ci
2788a8e1175bSopenharmony_ci    # Make sure this was not re-enabled by accident (additive config)
2789a8e1175bSopenharmony_ci    not grep mbedtls_ecjpake_init library/ecjpake.o
2790a8e1175bSopenharmony_ci
2791a8e1175bSopenharmony_ci    # Run the tests
2792a8e1175bSopenharmony_ci    # -------------
2793a8e1175bSopenharmony_ci
2794a8e1175bSopenharmony_ci    msg "test: full with accelerated PAKE"
2795a8e1175bSopenharmony_ci    make test
2796a8e1175bSopenharmony_ci}
2797a8e1175bSopenharmony_ci
2798a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_ecc_some_key_types () {
2799a8e1175bSopenharmony_ci    msg "build: full with accelerated EC algs and some key types"
2800a8e1175bSopenharmony_ci
2801a8e1175bSopenharmony_ci    # Algorithms and key types to accelerate
2802a8e1175bSopenharmony_ci    # For key types, use an explicitly list to omit GENERATE (and DERIVE)
2803a8e1175bSopenharmony_ci    loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2804a8e1175bSopenharmony_ci                    ALG_ECDH \
2805a8e1175bSopenharmony_ci                    ALG_JPAKE \
2806a8e1175bSopenharmony_ci                    KEY_TYPE_ECC_PUBLIC_KEY \
2807a8e1175bSopenharmony_ci                    KEY_TYPE_ECC_KEY_PAIR_BASIC \
2808a8e1175bSopenharmony_ci                    KEY_TYPE_ECC_KEY_PAIR_IMPORT \
2809a8e1175bSopenharmony_ci                    KEY_TYPE_ECC_KEY_PAIR_EXPORT \
2810a8e1175bSopenharmony_ci                    $(helper_get_psa_curve_list)"
2811a8e1175bSopenharmony_ci
2812a8e1175bSopenharmony_ci    # Configure
2813a8e1175bSopenharmony_ci    # ---------
2814a8e1175bSopenharmony_ci
2815a8e1175bSopenharmony_ci    # start with config full for maximum coverage (also enables USE_PSA)
2816a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "full"
2817a8e1175bSopenharmony_ci
2818a8e1175bSopenharmony_ci    # Disable modules that are accelerated - some will be re-enabled
2819a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDSA_C
2820a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDH_C
2821a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECJPAKE_C
2822a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECP_C
2823a8e1175bSopenharmony_ci
2824a8e1175bSopenharmony_ci    # Disable all curves - those that aren't accelerated should be re-enabled
2825a8e1175bSopenharmony_ci    helper_disable_builtin_curves
2826a8e1175bSopenharmony_ci
2827a8e1175bSopenharmony_ci    # Restartable feature is not yet supported by PSA. Once it will in
2828a8e1175bSopenharmony_ci    # the future, the following line could be removed (see issues
2829a8e1175bSopenharmony_ci    # 6061, 6332 and following ones)
2830a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2831a8e1175bSopenharmony_ci
2832a8e1175bSopenharmony_ci    # this is not supported by the driver API yet
2833a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2834a8e1175bSopenharmony_ci
2835a8e1175bSopenharmony_ci    # Build
2836a8e1175bSopenharmony_ci    # -----
2837a8e1175bSopenharmony_ci
2838a8e1175bSopenharmony_ci    # These hashes are needed for some ECDSA signature tests.
2839a8e1175bSopenharmony_ci    loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2840a8e1175bSopenharmony_ci                    ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2841a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2842a8e1175bSopenharmony_ci
2843a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
2844a8e1175bSopenharmony_ci
2845a8e1175bSopenharmony_ci    # ECP should be re-enabled but not the others
2846a8e1175bSopenharmony_ci    not grep mbedtls_ecdh_ library/ecdh.o
2847a8e1175bSopenharmony_ci    not grep mbedtls_ecdsa library/ecdsa.o
2848a8e1175bSopenharmony_ci    not grep mbedtls_ecjpake  library/ecjpake.o
2849a8e1175bSopenharmony_ci    grep mbedtls_ecp library/ecp.o
2850a8e1175bSopenharmony_ci
2851a8e1175bSopenharmony_ci    # Run the tests
2852a8e1175bSopenharmony_ci    # -------------
2853a8e1175bSopenharmony_ci
2854a8e1175bSopenharmony_ci    msg "test suites: full with accelerated EC algs and some key types"
2855a8e1175bSopenharmony_ci    make test
2856a8e1175bSopenharmony_ci}
2857a8e1175bSopenharmony_ci
2858a8e1175bSopenharmony_ci# Run tests with only (non-)Weierstrass accelerated
2859a8e1175bSopenharmony_ci# Common code used in:
2860a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_accel_ecc_weierstrass_curves
2861a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_accel_ecc_non_weierstrass_curves
2862a8e1175bSopenharmony_cicommon_test_psa_crypto_config_accel_ecc_some_curves () {
2863a8e1175bSopenharmony_ci    weierstrass=$1
2864a8e1175bSopenharmony_ci    if [ $weierstrass -eq 1 ]; then
2865a8e1175bSopenharmony_ci        desc="Weierstrass"
2866a8e1175bSopenharmony_ci    else
2867a8e1175bSopenharmony_ci        desc="non-Weierstrass"
2868a8e1175bSopenharmony_ci    fi
2869a8e1175bSopenharmony_ci
2870a8e1175bSopenharmony_ci    msg "build: crypto_full minus PK with accelerated EC algs and $desc curves"
2871a8e1175bSopenharmony_ci
2872a8e1175bSopenharmony_ci    # Note: Curves are handled in a special way by the libtestdriver machinery,
2873a8e1175bSopenharmony_ci    # so we only want to include them in the accel list when building the main
2874a8e1175bSopenharmony_ci    # libraries, hence the use of a separate variable.
2875a8e1175bSopenharmony_ci    # Note: the following loop is a modified version of
2876a8e1175bSopenharmony_ci    # helper_get_psa_curve_list that only keeps Weierstrass families.
2877a8e1175bSopenharmony_ci    loc_weierstrass_list=""
2878a8e1175bSopenharmony_ci    loc_non_weierstrass_list=""
2879a8e1175bSopenharmony_ci    for item in $(sed -n 's/^#define PSA_WANT_\(ECC_[0-9A-Z_a-z]*\).*/\1/p' <"$CRYPTO_CONFIG_H"); do
2880a8e1175bSopenharmony_ci        case $item in
2881a8e1175bSopenharmony_ci            ECC_BRAINPOOL*|ECC_SECP*)
2882a8e1175bSopenharmony_ci                loc_weierstrass_list="$loc_weierstrass_list $item"
2883a8e1175bSopenharmony_ci                ;;
2884a8e1175bSopenharmony_ci            *)
2885a8e1175bSopenharmony_ci                loc_non_weierstrass_list="$loc_non_weierstrass_list $item"
2886a8e1175bSopenharmony_ci                ;;
2887a8e1175bSopenharmony_ci        esac
2888a8e1175bSopenharmony_ci    done
2889a8e1175bSopenharmony_ci    if [ $weierstrass -eq 1 ]; then
2890a8e1175bSopenharmony_ci        loc_curve_list=$loc_weierstrass_list
2891a8e1175bSopenharmony_ci    else
2892a8e1175bSopenharmony_ci        loc_curve_list=$loc_non_weierstrass_list
2893a8e1175bSopenharmony_ci    fi
2894a8e1175bSopenharmony_ci
2895a8e1175bSopenharmony_ci    # Algorithms and key types to accelerate
2896a8e1175bSopenharmony_ci    loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
2897a8e1175bSopenharmony_ci                    ALG_ECDH \
2898a8e1175bSopenharmony_ci                    ALG_JPAKE \
2899a8e1175bSopenharmony_ci                    $(helper_get_psa_key_type_list "ECC") \
2900a8e1175bSopenharmony_ci                    $loc_curve_list"
2901a8e1175bSopenharmony_ci
2902a8e1175bSopenharmony_ci    # Configure
2903a8e1175bSopenharmony_ci    # ---------
2904a8e1175bSopenharmony_ci
2905a8e1175bSopenharmony_ci    # Start with config crypto_full and remove PK_C:
2906a8e1175bSopenharmony_ci    # that's what's supported now, see docs/driver-only-builds.md.
2907a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "crypto_full"
2908a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PK_C
2909a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PK_PARSE_C
2910a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PK_WRITE_C
2911a8e1175bSopenharmony_ci
2912a8e1175bSopenharmony_ci    # Disable modules that are accelerated - some will be re-enabled
2913a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDSA_C
2914a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDH_C
2915a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECJPAKE_C
2916a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECP_C
2917a8e1175bSopenharmony_ci
2918a8e1175bSopenharmony_ci    # Disable all curves - those that aren't accelerated should be re-enabled
2919a8e1175bSopenharmony_ci    helper_disable_builtin_curves
2920a8e1175bSopenharmony_ci
2921a8e1175bSopenharmony_ci    # Restartable feature is not yet supported by PSA. Once it will in
2922a8e1175bSopenharmony_ci    # the future, the following line could be removed (see issues
2923a8e1175bSopenharmony_ci    # 6061, 6332 and following ones)
2924a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
2925a8e1175bSopenharmony_ci
2926a8e1175bSopenharmony_ci    # this is not supported by the driver API yet
2927a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
2928a8e1175bSopenharmony_ci
2929a8e1175bSopenharmony_ci    # Build
2930a8e1175bSopenharmony_ci    # -----
2931a8e1175bSopenharmony_ci
2932a8e1175bSopenharmony_ci    # These hashes are needed for some ECDSA signature tests.
2933a8e1175bSopenharmony_ci    loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
2934a8e1175bSopenharmony_ci                    ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
2935a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
2936a8e1175bSopenharmony_ci
2937a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
2938a8e1175bSopenharmony_ci
2939a8e1175bSopenharmony_ci    # We expect ECDH to be re-enabled for the missing curves
2940a8e1175bSopenharmony_ci    grep mbedtls_ecdh_ library/ecdh.o
2941a8e1175bSopenharmony_ci    # We expect ECP to be re-enabled, however the parts specific to the
2942a8e1175bSopenharmony_ci    # families of curves that are accelerated should be ommited.
2943a8e1175bSopenharmony_ci    # - functions with mxz in the name are specific to Montgomery curves
2944a8e1175bSopenharmony_ci    # - ecp_muladd is specific to Weierstrass curves
2945a8e1175bSopenharmony_ci    ##nm library/ecp.o | tee ecp.syms
2946a8e1175bSopenharmony_ci    if [ $weierstrass -eq 1 ]; then
2947a8e1175bSopenharmony_ci        not grep mbedtls_ecp_muladd library/ecp.o
2948a8e1175bSopenharmony_ci        grep mxz library/ecp.o
2949a8e1175bSopenharmony_ci    else
2950a8e1175bSopenharmony_ci        grep mbedtls_ecp_muladd library/ecp.o
2951a8e1175bSopenharmony_ci        not grep mxz library/ecp.o
2952a8e1175bSopenharmony_ci    fi
2953a8e1175bSopenharmony_ci    # We expect ECDSA and ECJPAKE to be re-enabled only when
2954a8e1175bSopenharmony_ci    # Weierstrass curves are not accelerated
2955a8e1175bSopenharmony_ci    if [ $weierstrass -eq 1 ]; then
2956a8e1175bSopenharmony_ci        not grep mbedtls_ecdsa library/ecdsa.o
2957a8e1175bSopenharmony_ci        not grep mbedtls_ecjpake  library/ecjpake.o
2958a8e1175bSopenharmony_ci    else
2959a8e1175bSopenharmony_ci        grep mbedtls_ecdsa library/ecdsa.o
2960a8e1175bSopenharmony_ci        grep mbedtls_ecjpake  library/ecjpake.o
2961a8e1175bSopenharmony_ci    fi
2962a8e1175bSopenharmony_ci
2963a8e1175bSopenharmony_ci    # Run the tests
2964a8e1175bSopenharmony_ci    # -------------
2965a8e1175bSopenharmony_ci
2966a8e1175bSopenharmony_ci    msg "test suites: crypto_full minus PK with accelerated EC algs and $desc curves"
2967a8e1175bSopenharmony_ci    make test
2968a8e1175bSopenharmony_ci}
2969a8e1175bSopenharmony_ci
2970a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_ecc_weierstrass_curves () {
2971a8e1175bSopenharmony_ci    common_test_psa_crypto_config_accel_ecc_some_curves 1
2972a8e1175bSopenharmony_ci}
2973a8e1175bSopenharmony_ci
2974a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_ecc_non_weierstrass_curves () {
2975a8e1175bSopenharmony_ci    common_test_psa_crypto_config_accel_ecc_some_curves 0
2976a8e1175bSopenharmony_ci}
2977a8e1175bSopenharmony_ci
2978a8e1175bSopenharmony_ci# Auxiliary function to build config for all EC based algorithms (EC-JPAKE,
2979a8e1175bSopenharmony_ci# ECDH, ECDSA) with and without drivers.
2980a8e1175bSopenharmony_ci# The input parameter is a boolean value which indicates:
2981a8e1175bSopenharmony_ci# - 0 keep built-in EC algs,
2982a8e1175bSopenharmony_ci# - 1 exclude built-in EC algs (driver only).
2983a8e1175bSopenharmony_ci#
2984a8e1175bSopenharmony_ci# This is used by the two following components to ensure they always use the
2985a8e1175bSopenharmony_ci# same config, except for the use of driver or built-in EC algorithms:
2986a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_accel_ecc_ecp_light_only;
2987a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_reference_ecc_ecp_light_only.
2988a8e1175bSopenharmony_ci# This supports comparing their test coverage with analyze_outcomes.py.
2989a8e1175bSopenharmony_ciconfig_psa_crypto_config_ecp_light_only () {
2990a8e1175bSopenharmony_ci    driver_only="$1"
2991a8e1175bSopenharmony_ci    # start with config full for maximum coverage (also enables USE_PSA)
2992a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "full"
2993a8e1175bSopenharmony_ci    if [ "$driver_only" -eq 1 ]; then
2994a8e1175bSopenharmony_ci        # Disable modules that are accelerated
2995a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_ECDSA_C
2996a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_ECDH_C
2997a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_ECJPAKE_C
2998a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_ECP_C
2999a8e1175bSopenharmony_ci    fi
3000a8e1175bSopenharmony_ci
3001a8e1175bSopenharmony_ci    # Restartable feature is not yet supported by PSA. Once it will in
3002a8e1175bSopenharmony_ci    # the future, the following line could be removed (see issues
3003a8e1175bSopenharmony_ci    # 6061, 6332 and following ones)
3004a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
3005a8e1175bSopenharmony_ci}
3006a8e1175bSopenharmony_ci
3007a8e1175bSopenharmony_ci# Keep in sync with component_test_psa_crypto_config_reference_ecc_ecp_light_only
3008a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_ecc_ecp_light_only () {
3009a8e1175bSopenharmony_ci    msg "build: full with accelerated EC algs"
3010a8e1175bSopenharmony_ci
3011a8e1175bSopenharmony_ci    # Algorithms and key types to accelerate
3012a8e1175bSopenharmony_ci    loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
3013a8e1175bSopenharmony_ci                    ALG_ECDH \
3014a8e1175bSopenharmony_ci                    ALG_JPAKE \
3015a8e1175bSopenharmony_ci                    $(helper_get_psa_key_type_list "ECC") \
3016a8e1175bSopenharmony_ci                    $(helper_get_psa_curve_list)"
3017a8e1175bSopenharmony_ci
3018a8e1175bSopenharmony_ci    # Configure
3019a8e1175bSopenharmony_ci    # ---------
3020a8e1175bSopenharmony_ci
3021a8e1175bSopenharmony_ci    # Use the same config as reference, only without built-in EC algs
3022a8e1175bSopenharmony_ci    config_psa_crypto_config_ecp_light_only 1
3023a8e1175bSopenharmony_ci
3024a8e1175bSopenharmony_ci    # Do not disable builtin curves because that support is required for:
3025a8e1175bSopenharmony_ci    # - MBEDTLS_PK_PARSE_EC_EXTENDED
3026a8e1175bSopenharmony_ci    # - MBEDTLS_PK_PARSE_EC_COMPRESSED
3027a8e1175bSopenharmony_ci
3028a8e1175bSopenharmony_ci    # Build
3029a8e1175bSopenharmony_ci    # -----
3030a8e1175bSopenharmony_ci
3031a8e1175bSopenharmony_ci    # These hashes are needed for some ECDSA signature tests.
3032a8e1175bSopenharmony_ci    loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3033a8e1175bSopenharmony_ci                    ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
3034a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
3035a8e1175bSopenharmony_ci
3036a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
3037a8e1175bSopenharmony_ci
3038a8e1175bSopenharmony_ci    # Make sure any built-in EC alg was not re-enabled by accident (additive config)
3039a8e1175bSopenharmony_ci    not grep mbedtls_ecdsa_ library/ecdsa.o
3040a8e1175bSopenharmony_ci    not grep mbedtls_ecdh_ library/ecdh.o
3041a8e1175bSopenharmony_ci    not grep mbedtls_ecjpake_ library/ecjpake.o
3042a8e1175bSopenharmony_ci    not grep mbedtls_ecp_mul library/ecp.o
3043a8e1175bSopenharmony_ci
3044a8e1175bSopenharmony_ci    # Run the tests
3045a8e1175bSopenharmony_ci    # -------------
3046a8e1175bSopenharmony_ci
3047a8e1175bSopenharmony_ci    msg "test suites: full with accelerated EC algs"
3048a8e1175bSopenharmony_ci    make test
3049a8e1175bSopenharmony_ci
3050a8e1175bSopenharmony_ci    msg "ssl-opt: full with accelerated EC algs"
3051a8e1175bSopenharmony_ci    tests/ssl-opt.sh
3052a8e1175bSopenharmony_ci}
3053a8e1175bSopenharmony_ci
3054a8e1175bSopenharmony_ci# Keep in sync with component_test_psa_crypto_config_accel_ecc_ecp_light_only
3055a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_reference_ecc_ecp_light_only () {
3056a8e1175bSopenharmony_ci    msg "build: MBEDTLS_PSA_CRYPTO_CONFIG with non-accelerated EC algs"
3057a8e1175bSopenharmony_ci
3058a8e1175bSopenharmony_ci    config_psa_crypto_config_ecp_light_only 0
3059a8e1175bSopenharmony_ci
3060a8e1175bSopenharmony_ci    make
3061a8e1175bSopenharmony_ci
3062a8e1175bSopenharmony_ci    msg "test suites: full with non-accelerated EC algs"
3063a8e1175bSopenharmony_ci    make test
3064a8e1175bSopenharmony_ci
3065a8e1175bSopenharmony_ci    msg "ssl-opt: full with non-accelerated EC algs"
3066a8e1175bSopenharmony_ci    tests/ssl-opt.sh
3067a8e1175bSopenharmony_ci}
3068a8e1175bSopenharmony_ci
3069a8e1175bSopenharmony_ci# This helper function is used by:
3070a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_accel_ecc_no_ecp_at_all()
3071a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
3072a8e1175bSopenharmony_ci# to ensure that both tests use the same underlying configuration when testing
3073a8e1175bSopenharmony_ci# driver's coverage with analyze_outcomes.py.
3074a8e1175bSopenharmony_ci#
3075a8e1175bSopenharmony_ci# This functions accepts 1 boolean parameter as follows:
3076a8e1175bSopenharmony_ci# - 1: building with accelerated EC algorithms (ECDSA, ECDH, ECJPAKE), therefore
3077a8e1175bSopenharmony_ci#      excluding their built-in implementation as well as ECP_C & ECP_LIGHT
3078a8e1175bSopenharmony_ci# - 0: include built-in implementation of EC algorithms.
3079a8e1175bSopenharmony_ci#
3080a8e1175bSopenharmony_ci# PK_C and RSA_C are always disabled to ensure there is no remaining dependency
3081a8e1175bSopenharmony_ci# on the ECP module.
3082a8e1175bSopenharmony_ciconfig_psa_crypto_no_ecp_at_all () {
3083a8e1175bSopenharmony_ci    driver_only="$1"
3084a8e1175bSopenharmony_ci    # start with full config for maximum coverage (also enables USE_PSA)
3085a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "full"
3086a8e1175bSopenharmony_ci
3087a8e1175bSopenharmony_ci    if [ "$driver_only" -eq 1 ]; then
3088a8e1175bSopenharmony_ci        # Disable modules that are accelerated
3089a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_ECDSA_C
3090a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_ECDH_C
3091a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_ECJPAKE_C
3092a8e1175bSopenharmony_ci        # Disable ECP module (entirely)
3093a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_ECP_C
3094a8e1175bSopenharmony_ci    fi
3095a8e1175bSopenharmony_ci
3096a8e1175bSopenharmony_ci    # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
3097a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
3098a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
3099a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
3100a8e1175bSopenharmony_ci
3101a8e1175bSopenharmony_ci    # Restartable feature is not yet supported by PSA. Once it will in
3102a8e1175bSopenharmony_ci    # the future, the following line could be removed (see issues
3103a8e1175bSopenharmony_ci    # 6061, 6332 and following ones)
3104a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
3105a8e1175bSopenharmony_ci}
3106a8e1175bSopenharmony_ci
3107a8e1175bSopenharmony_ci# Build and test a configuration where driver accelerates all EC algs while
3108a8e1175bSopenharmony_ci# all support and dependencies from ECP and ECP_LIGHT are removed on the library
3109a8e1175bSopenharmony_ci# side.
3110a8e1175bSopenharmony_ci#
3111a8e1175bSopenharmony_ci# Keep in sync with component_test_psa_crypto_config_reference_ecc_no_ecp_at_all()
3112a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_ecc_no_ecp_at_all () {
3113a8e1175bSopenharmony_ci    msg "build: full + accelerated EC algs - ECP"
3114a8e1175bSopenharmony_ci
3115a8e1175bSopenharmony_ci    # Algorithms and key types to accelerate
3116a8e1175bSopenharmony_ci    loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
3117a8e1175bSopenharmony_ci                    ALG_ECDH \
3118a8e1175bSopenharmony_ci                    ALG_JPAKE \
3119a8e1175bSopenharmony_ci                    $(helper_get_psa_key_type_list "ECC") \
3120a8e1175bSopenharmony_ci                    $(helper_get_psa_curve_list)"
3121a8e1175bSopenharmony_ci
3122a8e1175bSopenharmony_ci    # Configure
3123a8e1175bSopenharmony_ci    # ---------
3124a8e1175bSopenharmony_ci
3125a8e1175bSopenharmony_ci    # Set common configurations between library's and driver's builds
3126a8e1175bSopenharmony_ci    config_psa_crypto_no_ecp_at_all 1
3127a8e1175bSopenharmony_ci    # Disable all the builtin curves. All the required algs are accelerated.
3128a8e1175bSopenharmony_ci    helper_disable_builtin_curves
3129a8e1175bSopenharmony_ci
3130a8e1175bSopenharmony_ci    # Build
3131a8e1175bSopenharmony_ci    # -----
3132a8e1175bSopenharmony_ci
3133a8e1175bSopenharmony_ci    # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
3134a8e1175bSopenharmony_ci    # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
3135a8e1175bSopenharmony_ci    loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3136a8e1175bSopenharmony_ci                    ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
3137a8e1175bSopenharmony_ci
3138a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
3139a8e1175bSopenharmony_ci
3140a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
3141a8e1175bSopenharmony_ci
3142a8e1175bSopenharmony_ci    # Make sure any built-in EC alg was not re-enabled by accident (additive config)
3143a8e1175bSopenharmony_ci    not grep mbedtls_ecdsa_ library/ecdsa.o
3144a8e1175bSopenharmony_ci    not grep mbedtls_ecdh_ library/ecdh.o
3145a8e1175bSopenharmony_ci    not grep mbedtls_ecjpake_ library/ecjpake.o
3146a8e1175bSopenharmony_ci    # Also ensure that ECP module was not re-enabled
3147a8e1175bSopenharmony_ci    not grep mbedtls_ecp_ library/ecp.o
3148a8e1175bSopenharmony_ci
3149a8e1175bSopenharmony_ci    # Run the tests
3150a8e1175bSopenharmony_ci    # -------------
3151a8e1175bSopenharmony_ci
3152a8e1175bSopenharmony_ci    msg "test: full + accelerated EC algs - ECP"
3153a8e1175bSopenharmony_ci    make test
3154a8e1175bSopenharmony_ci
3155a8e1175bSopenharmony_ci    msg "ssl-opt: full + accelerated EC algs - ECP"
3156a8e1175bSopenharmony_ci    tests/ssl-opt.sh
3157a8e1175bSopenharmony_ci}
3158a8e1175bSopenharmony_ci
3159a8e1175bSopenharmony_ci# Reference function used for driver's coverage analysis in analyze_outcomes.py
3160a8e1175bSopenharmony_ci# in conjunction with component_test_psa_crypto_config_accel_ecc_no_ecp_at_all().
3161a8e1175bSopenharmony_ci# Keep in sync with its accelerated counterpart.
3162a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_reference_ecc_no_ecp_at_all () {
3163a8e1175bSopenharmony_ci    msg "build: full + non accelerated EC algs"
3164a8e1175bSopenharmony_ci
3165a8e1175bSopenharmony_ci    config_psa_crypto_no_ecp_at_all 0
3166a8e1175bSopenharmony_ci
3167a8e1175bSopenharmony_ci    make
3168a8e1175bSopenharmony_ci
3169a8e1175bSopenharmony_ci    msg "test: full + non accelerated EC algs"
3170a8e1175bSopenharmony_ci    make test
3171a8e1175bSopenharmony_ci
3172a8e1175bSopenharmony_ci    msg "ssl-opt: full + non accelerated EC algs"
3173a8e1175bSopenharmony_ci    tests/ssl-opt.sh
3174a8e1175bSopenharmony_ci}
3175a8e1175bSopenharmony_ci
3176a8e1175bSopenharmony_ci# This is a common configuration helper used directly from:
3177a8e1175bSopenharmony_ci# - common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
3178a8e1175bSopenharmony_ci# - common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
3179a8e1175bSopenharmony_ci# and indirectly from:
3180a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_accel_ecc_no_bignum
3181a8e1175bSopenharmony_ci#       - accelerate all EC algs, disable RSA and FFDH
3182a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_reference_ecc_no_bignum
3183a8e1175bSopenharmony_ci#       - this is the reference component of the above
3184a8e1175bSopenharmony_ci#       - it still disables RSA and FFDH, but it uses builtin EC algs
3185a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
3186a8e1175bSopenharmony_ci#       - accelerate all EC and FFDH algs, disable only RSA
3187a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
3188a8e1175bSopenharmony_ci#       - this is the reference component of the above
3189a8e1175bSopenharmony_ci#       - it still disables RSA, but it uses builtin EC and FFDH algs
3190a8e1175bSopenharmony_ci#
3191a8e1175bSopenharmony_ci# This function accepts 2 parameters:
3192a8e1175bSopenharmony_ci# $1: a boolean value which states if we are testing an accelerated scenario
3193a8e1175bSopenharmony_ci#     or not.
3194a8e1175bSopenharmony_ci# $2: a string value which states which components are tested. Allowed values
3195a8e1175bSopenharmony_ci#     are "ECC" or "ECC_DH".
3196a8e1175bSopenharmony_ciconfig_psa_crypto_config_accel_ecc_ffdh_no_bignum() {
3197a8e1175bSopenharmony_ci    driver_only="$1"
3198a8e1175bSopenharmony_ci    test_target="$2"
3199a8e1175bSopenharmony_ci    # start with full config for maximum coverage (also enables USE_PSA)
3200a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "full"
3201a8e1175bSopenharmony_ci
3202a8e1175bSopenharmony_ci    if [ "$driver_only" -eq 1 ]; then
3203a8e1175bSopenharmony_ci        # Disable modules that are accelerated
3204a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_ECDSA_C
3205a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_ECDH_C
3206a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_ECJPAKE_C
3207a8e1175bSopenharmony_ci        # Disable ECP module (entirely)
3208a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_ECP_C
3209a8e1175bSopenharmony_ci        # Also disable bignum
3210a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_BIGNUM_C
3211a8e1175bSopenharmony_ci    fi
3212a8e1175bSopenharmony_ci
3213a8e1175bSopenharmony_ci    # Disable all the features that auto-enable ECP_LIGHT (see build_info.h)
3214a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PK_PARSE_EC_EXTENDED
3215a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PK_PARSE_EC_COMPRESSED
3216a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE
3217a8e1175bSopenharmony_ci
3218a8e1175bSopenharmony_ci    # RSA support is intentionally disabled on this test because RSA_C depends
3219a8e1175bSopenharmony_ci    # on BIGNUM_C.
3220a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_RSA_[0-9A-Z_a-z]*"
3221a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_ALG_RSA_[0-9A-Z_a-z]*"
3222a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_RSA_C
3223a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PKCS1_V15
3224a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PKCS1_V21
3225a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
3226a8e1175bSopenharmony_ci    # Also disable key exchanges that depend on RSA
3227a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
3228a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
3229a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3230a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3231a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3232a8e1175bSopenharmony_ci
3233a8e1175bSopenharmony_ci    if [ "$test_target" = "ECC" ]; then
3234a8e1175bSopenharmony_ci        # When testing ECC only, we disable FFDH support, both from builtin and
3235a8e1175bSopenharmony_ci        # PSA sides, and also disable the key exchanges that depend on DHM.
3236a8e1175bSopenharmony_ci        scripts/config.py -f include/psa/crypto_config.h unset PSA_WANT_ALG_FFDH
3237a8e1175bSopenharmony_ci        scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_KEY_TYPE_DH_[0-9A-Z_a-z]*"
3238a8e1175bSopenharmony_ci        scripts/config.py -f "$CRYPTO_CONFIG_H" unset-all "PSA_WANT_DH_RFC7919_[0-9]*"
3239a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_DHM_C
3240a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
3241a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3242a8e1175bSopenharmony_ci    else
3243a8e1175bSopenharmony_ci        # When testing ECC and DH instead, we disable DHM and depending key
3244a8e1175bSopenharmony_ci        # exchanges only in the accelerated build
3245a8e1175bSopenharmony_ci        if [ "$driver_only" -eq 1 ]; then
3246a8e1175bSopenharmony_ci            scripts/config.py unset MBEDTLS_DHM_C
3247a8e1175bSopenharmony_ci            scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
3248a8e1175bSopenharmony_ci            scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3249a8e1175bSopenharmony_ci        fi
3250a8e1175bSopenharmony_ci    fi
3251a8e1175bSopenharmony_ci
3252a8e1175bSopenharmony_ci    # Restartable feature is not yet supported by PSA. Once it will in
3253a8e1175bSopenharmony_ci    # the future, the following line could be removed (see issues
3254a8e1175bSopenharmony_ci    # 6061, 6332 and following ones)
3255a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECP_RESTARTABLE
3256a8e1175bSopenharmony_ci}
3257a8e1175bSopenharmony_ci
3258a8e1175bSopenharmony_ci# Common helper used by:
3259a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_accel_ecc_no_bignum
3260a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_accel_ecc_ffdh_no_bignum
3261a8e1175bSopenharmony_ci#
3262a8e1175bSopenharmony_ci# The goal is to build and test accelerating either:
3263a8e1175bSopenharmony_ci# - ECC only or
3264a8e1175bSopenharmony_ci# - both ECC and FFDH
3265a8e1175bSopenharmony_ci#
3266a8e1175bSopenharmony_ci# It is meant to be used in conjunction with
3267a8e1175bSopenharmony_ci# common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum() for drivers
3268a8e1175bSopenharmony_ci# coverage analysis in the "analyze_outcomes.py" script.
3269a8e1175bSopenharmony_cicommon_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
3270a8e1175bSopenharmony_ci    test_target="$1"
3271a8e1175bSopenharmony_ci
3272a8e1175bSopenharmony_ci    # This is an internal helper to simplify text message handling
3273a8e1175bSopenharmony_ci    if [ "$test_target" = "ECC_DH" ]; then
3274a8e1175bSopenharmony_ci        accel_text="ECC/FFDH"
3275a8e1175bSopenharmony_ci        removed_text="ECP - DH"
3276a8e1175bSopenharmony_ci    else
3277a8e1175bSopenharmony_ci        accel_text="ECC"
3278a8e1175bSopenharmony_ci        removed_text="ECP"
3279a8e1175bSopenharmony_ci    fi
3280a8e1175bSopenharmony_ci
3281a8e1175bSopenharmony_ci    msg "build: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
3282a8e1175bSopenharmony_ci
3283a8e1175bSopenharmony_ci    # By default we accelerate all EC keys/algs
3284a8e1175bSopenharmony_ci    loc_accel_list="ALG_ECDSA ALG_DETERMINISTIC_ECDSA \
3285a8e1175bSopenharmony_ci                    ALG_ECDH \
3286a8e1175bSopenharmony_ci                    ALG_JPAKE \
3287a8e1175bSopenharmony_ci                    $(helper_get_psa_key_type_list "ECC") \
3288a8e1175bSopenharmony_ci                    $(helper_get_psa_curve_list)"
3289a8e1175bSopenharmony_ci    # Optionally we can also add DH to the list of accelerated items
3290a8e1175bSopenharmony_ci    if [ "$test_target" = "ECC_DH" ]; then
3291a8e1175bSopenharmony_ci        loc_accel_list="$loc_accel_list \
3292a8e1175bSopenharmony_ci                        ALG_FFDH \
3293a8e1175bSopenharmony_ci                        $(helper_get_psa_key_type_list "DH") \
3294a8e1175bSopenharmony_ci                        $(helper_get_psa_dh_group_list)"
3295a8e1175bSopenharmony_ci    fi
3296a8e1175bSopenharmony_ci
3297a8e1175bSopenharmony_ci    # Configure
3298a8e1175bSopenharmony_ci    # ---------
3299a8e1175bSopenharmony_ci
3300a8e1175bSopenharmony_ci    # Set common configurations between library's and driver's builds
3301a8e1175bSopenharmony_ci    config_psa_crypto_config_accel_ecc_ffdh_no_bignum 1 "$test_target"
3302a8e1175bSopenharmony_ci    # Disable all the builtin curves. All the required algs are accelerated.
3303a8e1175bSopenharmony_ci    helper_disable_builtin_curves
3304a8e1175bSopenharmony_ci
3305a8e1175bSopenharmony_ci    # Build
3306a8e1175bSopenharmony_ci    # -----
3307a8e1175bSopenharmony_ci
3308a8e1175bSopenharmony_ci    # Things we wanted supported in libtestdriver1, but not accelerated in the main library:
3309a8e1175bSopenharmony_ci    # SHA-1 and all SHA-2/3 variants, as they are used by ECDSA deterministic.
3310a8e1175bSopenharmony_ci    loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3311a8e1175bSopenharmony_ci                    ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
3312a8e1175bSopenharmony_ci
3313a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
3314a8e1175bSopenharmony_ci
3315a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
3316a8e1175bSopenharmony_ci
3317a8e1175bSopenharmony_ci    # Make sure any built-in EC alg was not re-enabled by accident (additive config)
3318a8e1175bSopenharmony_ci    not grep mbedtls_ecdsa_ library/ecdsa.o
3319a8e1175bSopenharmony_ci    not grep mbedtls_ecdh_ library/ecdh.o
3320a8e1175bSopenharmony_ci    not grep mbedtls_ecjpake_ library/ecjpake.o
3321a8e1175bSopenharmony_ci    # Also ensure that ECP, RSA, [DHM] or BIGNUM modules were not re-enabled
3322a8e1175bSopenharmony_ci    not grep mbedtls_ecp_ library/ecp.o
3323a8e1175bSopenharmony_ci    not grep mbedtls_rsa_ library/rsa.o
3324a8e1175bSopenharmony_ci    not grep mbedtls_mpi_ library/bignum.o
3325a8e1175bSopenharmony_ci    not grep mbedtls_dhm_ library/dhm.o
3326a8e1175bSopenharmony_ci
3327a8e1175bSopenharmony_ci    # Run the tests
3328a8e1175bSopenharmony_ci    # -------------
3329a8e1175bSopenharmony_ci
3330a8e1175bSopenharmony_ci    msg "test suites: full + accelerated $accel_text algs + USE_PSA - $removed_text - DHM - BIGNUM"
3331a8e1175bSopenharmony_ci
3332a8e1175bSopenharmony_ci    make test
3333a8e1175bSopenharmony_ci
3334a8e1175bSopenharmony_ci    msg "ssl-opt: full + accelerated $accel_text algs + USE_PSA - $removed_text - BIGNUM"
3335a8e1175bSopenharmony_ci    tests/ssl-opt.sh
3336a8e1175bSopenharmony_ci}
3337a8e1175bSopenharmony_ci
3338a8e1175bSopenharmony_ci# Common helper used by:
3339a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_reference_ecc_no_bignum
3340a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_reference_ecc_ffdh_no_bignum
3341a8e1175bSopenharmony_ci#
3342a8e1175bSopenharmony_ci# The goal is to build and test a reference scenario (i.e. with builtin
3343a8e1175bSopenharmony_ci# components) compared to the ones used in
3344a8e1175bSopenharmony_ci# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() above.
3345a8e1175bSopenharmony_ci#
3346a8e1175bSopenharmony_ci# It is meant to be used in conjunction with
3347a8e1175bSopenharmony_ci# common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum() for drivers'
3348a8e1175bSopenharmony_ci# coverage analysis in "analyze_outcomes.py" script.
3349a8e1175bSopenharmony_cicommon_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
3350a8e1175bSopenharmony_ci    test_target="$1"
3351a8e1175bSopenharmony_ci
3352a8e1175bSopenharmony_ci    # This is an internal helper to simplify text message handling
3353a8e1175bSopenharmony_ci    if [ "$test_target" = "ECC_DH" ]; then
3354a8e1175bSopenharmony_ci        accel_text="ECC/FFDH"
3355a8e1175bSopenharmony_ci    else
3356a8e1175bSopenharmony_ci        accel_text="ECC"
3357a8e1175bSopenharmony_ci    fi
3358a8e1175bSopenharmony_ci
3359a8e1175bSopenharmony_ci    msg "build: full + non accelerated $accel_text algs + USE_PSA"
3360a8e1175bSopenharmony_ci
3361a8e1175bSopenharmony_ci    config_psa_crypto_config_accel_ecc_ffdh_no_bignum 0 "$test_target"
3362a8e1175bSopenharmony_ci
3363a8e1175bSopenharmony_ci    make
3364a8e1175bSopenharmony_ci
3365a8e1175bSopenharmony_ci    msg "test suites: full + non accelerated EC algs + USE_PSA"
3366a8e1175bSopenharmony_ci    make test
3367a8e1175bSopenharmony_ci
3368a8e1175bSopenharmony_ci    msg "ssl-opt: full + non accelerated $accel_text algs + USE_PSA"
3369a8e1175bSopenharmony_ci    tests/ssl-opt.sh
3370a8e1175bSopenharmony_ci}
3371a8e1175bSopenharmony_ci
3372a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_ecc_no_bignum () {
3373a8e1175bSopenharmony_ci    common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC"
3374a8e1175bSopenharmony_ci}
3375a8e1175bSopenharmony_ci
3376a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_reference_ecc_no_bignum () {
3377a8e1175bSopenharmony_ci    common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC"
3378a8e1175bSopenharmony_ci}
3379a8e1175bSopenharmony_ci
3380a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_ecc_ffdh_no_bignum () {
3381a8e1175bSopenharmony_ci    common_test_psa_crypto_config_accel_ecc_ffdh_no_bignum "ECC_DH"
3382a8e1175bSopenharmony_ci}
3383a8e1175bSopenharmony_ci
3384a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_reference_ecc_ffdh_no_bignum () {
3385a8e1175bSopenharmony_ci    common_test_psa_crypto_config_reference_ecc_ffdh_no_bignum "ECC_DH"
3386a8e1175bSopenharmony_ci}
3387a8e1175bSopenharmony_ci
3388a8e1175bSopenharmony_ci# Helper for setting common configurations between:
3389a8e1175bSopenharmony_ci# - component_test_tfm_config_p256m_driver_accel_ec()
3390a8e1175bSopenharmony_ci# - component_test_tfm_config()
3391a8e1175bSopenharmony_cicommon_tfm_config () {
3392a8e1175bSopenharmony_ci    # Enable TF-M config
3393a8e1175bSopenharmony_ci    cp configs/config-tfm.h "$CONFIG_H"
3394a8e1175bSopenharmony_ci    echo "#undef MBEDTLS_PSA_CRYPTO_CONFIG_FILE" >> "$CONFIG_H"
3395a8e1175bSopenharmony_ci    cp configs/ext/crypto_config_profile_medium.h "$CRYPTO_CONFIG_H"
3396a8e1175bSopenharmony_ci
3397a8e1175bSopenharmony_ci    # Other config adjustment to make the tests pass.
3398a8e1175bSopenharmony_ci    # This should probably be adopted upstream.
3399a8e1175bSopenharmony_ci    #
3400a8e1175bSopenharmony_ci    # - USE_PSA_CRYPTO for PK_HAVE_ECC_KEYS
3401a8e1175bSopenharmony_ci    echo "#define MBEDTLS_USE_PSA_CRYPTO" >> "$CONFIG_H"
3402a8e1175bSopenharmony_ci
3403a8e1175bSopenharmony_ci    # Config adjustment for better test coverage in our environment.
3404a8e1175bSopenharmony_ci    # This is not needed just to build and pass tests.
3405a8e1175bSopenharmony_ci    #
3406a8e1175bSopenharmony_ci    # Enable filesystem I/O for the benefit of PK parse/write tests.
3407a8e1175bSopenharmony_ci    echo "#define MBEDTLS_FS_IO" >> "$CONFIG_H"
3408a8e1175bSopenharmony_ci}
3409a8e1175bSopenharmony_ci
3410a8e1175bSopenharmony_ci# Keep this in sync with component_test_tfm_config() as they are both meant
3411a8e1175bSopenharmony_ci# to be used in analyze_outcomes.py for driver's coverage analysis.
3412a8e1175bSopenharmony_cicomponent_test_tfm_config_p256m_driver_accel_ec () {
3413a8e1175bSopenharmony_ci    msg "build: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
3414a8e1175bSopenharmony_ci
3415a8e1175bSopenharmony_ci    common_tfm_config
3416a8e1175bSopenharmony_ci
3417a8e1175bSopenharmony_ci    # Build crypto library
3418a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../tests/include/spe" LDFLAGS="$ASAN_CFLAGS"
3419a8e1175bSopenharmony_ci
3420a8e1175bSopenharmony_ci    # Make sure any built-in EC alg was not re-enabled by accident (additive config)
3421a8e1175bSopenharmony_ci    not grep mbedtls_ecdsa_ library/ecdsa.o
3422a8e1175bSopenharmony_ci    not grep mbedtls_ecdh_ library/ecdh.o
3423a8e1175bSopenharmony_ci    not grep mbedtls_ecjpake_ library/ecjpake.o
3424a8e1175bSopenharmony_ci    # Also ensure that ECP, RSA, DHM or BIGNUM modules were not re-enabled
3425a8e1175bSopenharmony_ci    not grep mbedtls_ecp_ library/ecp.o
3426a8e1175bSopenharmony_ci    not grep mbedtls_rsa_ library/rsa.o
3427a8e1175bSopenharmony_ci    not grep mbedtls_dhm_ library/dhm.o
3428a8e1175bSopenharmony_ci    not grep mbedtls_mpi_ library/bignum.o
3429a8e1175bSopenharmony_ci    # Check that p256m was built
3430a8e1175bSopenharmony_ci    grep -q p256_ecdsa_ library/libmbedcrypto.a
3431a8e1175bSopenharmony_ci
3432a8e1175bSopenharmony_ci    # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
3433a8e1175bSopenharmony_ci    # files, so we want to ensure that it has not be re-enabled accidentally.
3434a8e1175bSopenharmony_ci    not grep mbedtls_cipher library/cipher.o
3435a8e1175bSopenharmony_ci
3436a8e1175bSopenharmony_ci    # Run the tests
3437a8e1175bSopenharmony_ci    msg "test: TF-M config + p256m driver + accel ECDH(E)/ECDSA"
3438a8e1175bSopenharmony_ci    make test
3439a8e1175bSopenharmony_ci}
3440a8e1175bSopenharmony_ci
3441a8e1175bSopenharmony_ci# Keep this in sync with component_test_tfm_config_p256m_driver_accel_ec() as
3442a8e1175bSopenharmony_ci# they are both meant to be used in analyze_outcomes.py for driver's coverage
3443a8e1175bSopenharmony_ci# analysis.
3444a8e1175bSopenharmony_cicomponent_test_tfm_config() {
3445a8e1175bSopenharmony_ci    common_tfm_config
3446a8e1175bSopenharmony_ci
3447a8e1175bSopenharmony_ci    # Disable P256M driver, which is on by default, so that analyze_outcomes
3448a8e1175bSopenharmony_ci    # can compare this test with test_tfm_config_p256m_driver_accel_ec
3449a8e1175bSopenharmony_ci    echo "#undef MBEDTLS_PSA_P256M_DRIVER_ENABLED" >> "$CONFIG_H"
3450a8e1175bSopenharmony_ci
3451a8e1175bSopenharmony_ci    msg "build: TF-M config"
3452a8e1175bSopenharmony_ci    make CFLAGS='-Werror -Wall -Wextra -I../tests/include/spe' tests
3453a8e1175bSopenharmony_ci
3454a8e1175bSopenharmony_ci    # Check that p256m was not built
3455a8e1175bSopenharmony_ci    not grep p256_ecdsa_ library/libmbedcrypto.a
3456a8e1175bSopenharmony_ci
3457a8e1175bSopenharmony_ci    # In "config-tfm.h" we disabled CIPHER_C tweaking TF-M's configuration
3458a8e1175bSopenharmony_ci    # files, so we want to ensure that it has not be re-enabled accidentally.
3459a8e1175bSopenharmony_ci    not grep mbedtls_cipher library/cipher.o
3460a8e1175bSopenharmony_ci
3461a8e1175bSopenharmony_ci    msg "test: TF-M config"
3462a8e1175bSopenharmony_ci    make test
3463a8e1175bSopenharmony_ci}
3464a8e1175bSopenharmony_ci
3465a8e1175bSopenharmony_ci# Common helper for component_full_without_ecdhe_ecdsa() and
3466a8e1175bSopenharmony_ci# component_full_without_ecdhe_ecdsa_and_tls13() which:
3467a8e1175bSopenharmony_ci# - starts from the "full" configuration minus the list of symbols passed in
3468a8e1175bSopenharmony_ci#   as 1st parameter
3469a8e1175bSopenharmony_ci# - build
3470a8e1175bSopenharmony_ci# - test only TLS (i.e. test_suite_tls and ssl-opt)
3471a8e1175bSopenharmony_cibuild_full_minus_something_and_test_tls () {
3472a8e1175bSopenharmony_ci    symbols_to_disable="$1"
3473a8e1175bSopenharmony_ci
3474a8e1175bSopenharmony_ci    msg "build: full minus something, test TLS"
3475a8e1175bSopenharmony_ci
3476a8e1175bSopenharmony_ci    scripts/config.py full
3477a8e1175bSopenharmony_ci    for sym in $symbols_to_disable; do
3478a8e1175bSopenharmony_ci        echo "Disabling $sym"
3479a8e1175bSopenharmony_ci        scripts/config.py unset $sym
3480a8e1175bSopenharmony_ci    done
3481a8e1175bSopenharmony_ci
3482a8e1175bSopenharmony_ci    make
3483a8e1175bSopenharmony_ci
3484a8e1175bSopenharmony_ci    msg "test: full minus something, test TLS"
3485a8e1175bSopenharmony_ci    ( cd tests; ./test_suite_ssl )
3486a8e1175bSopenharmony_ci
3487a8e1175bSopenharmony_ci    msg "ssl-opt: full minus something, test TLS"
3488a8e1175bSopenharmony_ci    tests/ssl-opt.sh
3489a8e1175bSopenharmony_ci}
3490a8e1175bSopenharmony_ci
3491a8e1175bSopenharmony_cicomponent_full_without_ecdhe_ecdsa () {
3492a8e1175bSopenharmony_ci    build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED"
3493a8e1175bSopenharmony_ci}
3494a8e1175bSopenharmony_ci
3495a8e1175bSopenharmony_cicomponent_full_without_ecdhe_ecdsa_and_tls13 () {
3496a8e1175bSopenharmony_ci    build_full_minus_something_and_test_tls "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
3497a8e1175bSopenharmony_ci                                             MBEDTLS_SSL_PROTO_TLS1_3"
3498a8e1175bSopenharmony_ci}
3499a8e1175bSopenharmony_ci
3500a8e1175bSopenharmony_ci# This is an helper used by:
3501a8e1175bSopenharmony_ci# - component_test_psa_ecc_key_pair_no_derive
3502a8e1175bSopenharmony_ci# - component_test_psa_ecc_key_pair_no_generate
3503a8e1175bSopenharmony_ci# The goal is to test with all PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy symbols
3504a8e1175bSopenharmony_ci# enabled, but one. Input arguments are as follows:
3505a8e1175bSopenharmony_ci# - $1 is the key type under test, i.e. ECC/RSA/DH
3506a8e1175bSopenharmony_ci# - $2 is the key option to be unset (i.e. generate, derive, etc)
3507a8e1175bSopenharmony_cibuild_and_test_psa_want_key_pair_partial() {
3508a8e1175bSopenharmony_ci    key_type=$1
3509a8e1175bSopenharmony_ci    unset_option=$2
3510a8e1175bSopenharmony_ci    disabled_psa_want="PSA_WANT_KEY_TYPE_${key_type}_KEY_PAIR_${unset_option}"
3511a8e1175bSopenharmony_ci
3512a8e1175bSopenharmony_ci    msg "build: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
3513a8e1175bSopenharmony_ci    scripts/config.py full
3514a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
3515a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
3516a8e1175bSopenharmony_ci
3517a8e1175bSopenharmony_ci    # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in
3518a8e1175bSopenharmony_ci    # crypto_config.h so we just disable the one we don't want.
3519a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset "$disabled_psa_want"
3520a8e1175bSopenharmony_ci
3521a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
3522a8e1175bSopenharmony_ci
3523a8e1175bSopenharmony_ci    msg "test: full - MBEDTLS_USE_PSA_CRYPTO - ${disabled_psa_want}"
3524a8e1175bSopenharmony_ci    make test
3525a8e1175bSopenharmony_ci}
3526a8e1175bSopenharmony_ci
3527a8e1175bSopenharmony_cicomponent_test_psa_ecc_key_pair_no_derive() {
3528a8e1175bSopenharmony_ci    build_and_test_psa_want_key_pair_partial "ECC" "DERIVE"
3529a8e1175bSopenharmony_ci}
3530a8e1175bSopenharmony_ci
3531a8e1175bSopenharmony_cicomponent_test_psa_ecc_key_pair_no_generate() {
3532a8e1175bSopenharmony_ci    build_and_test_psa_want_key_pair_partial "ECC" "GENERATE"
3533a8e1175bSopenharmony_ci}
3534a8e1175bSopenharmony_ci
3535a8e1175bSopenharmony_ciconfig_psa_crypto_accel_rsa () {
3536a8e1175bSopenharmony_ci    driver_only=$1
3537a8e1175bSopenharmony_ci
3538a8e1175bSopenharmony_ci    # Start from crypto_full config (no X.509, no TLS)
3539a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "crypto_full"
3540a8e1175bSopenharmony_ci
3541a8e1175bSopenharmony_ci    if [ "$driver_only" -eq 1 ]; then
3542a8e1175bSopenharmony_ci        # Remove RSA support and its dependencies
3543a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_RSA_C
3544a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_PKCS1_V15
3545a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_PKCS1_V21
3546a8e1175bSopenharmony_ci
3547a8e1175bSopenharmony_ci        # We need PEM parsing in the test library as well to support the import
3548a8e1175bSopenharmony_ci        # of PEM encoded RSA keys.
3549a8e1175bSopenharmony_ci        scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_PEM_PARSE_C
3550a8e1175bSopenharmony_ci        scripts/config.py -f "$CONFIG_TEST_DRIVER_H" set MBEDTLS_BASE64_C
3551a8e1175bSopenharmony_ci    fi
3552a8e1175bSopenharmony_ci}
3553a8e1175bSopenharmony_ci
3554a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_rsa_crypto () {
3555a8e1175bSopenharmony_ci    msg "build: crypto_full with accelerated RSA"
3556a8e1175bSopenharmony_ci
3557a8e1175bSopenharmony_ci    loc_accel_list="ALG_RSA_OAEP ALG_RSA_PSS \
3558a8e1175bSopenharmony_ci                    ALG_RSA_PKCS1V15_CRYPT ALG_RSA_PKCS1V15_SIGN \
3559a8e1175bSopenharmony_ci                    KEY_TYPE_RSA_PUBLIC_KEY \
3560a8e1175bSopenharmony_ci                    KEY_TYPE_RSA_KEY_PAIR_BASIC \
3561a8e1175bSopenharmony_ci                    KEY_TYPE_RSA_KEY_PAIR_GENERATE \
3562a8e1175bSopenharmony_ci                    KEY_TYPE_RSA_KEY_PAIR_IMPORT \
3563a8e1175bSopenharmony_ci                    KEY_TYPE_RSA_KEY_PAIR_EXPORT"
3564a8e1175bSopenharmony_ci
3565a8e1175bSopenharmony_ci    # Configure
3566a8e1175bSopenharmony_ci    # ---------
3567a8e1175bSopenharmony_ci
3568a8e1175bSopenharmony_ci    config_psa_crypto_accel_rsa 1
3569a8e1175bSopenharmony_ci
3570a8e1175bSopenharmony_ci    # Build
3571a8e1175bSopenharmony_ci    # -----
3572a8e1175bSopenharmony_ci
3573a8e1175bSopenharmony_ci    # These hashes are needed for unit tests.
3574a8e1175bSopenharmony_ci    loc_extra_list="ALG_SHA_1 ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3575a8e1175bSopenharmony_ci                    ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512 ALG_MD5"
3576a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list" "$loc_extra_list"
3577a8e1175bSopenharmony_ci
3578a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
3579a8e1175bSopenharmony_ci
3580a8e1175bSopenharmony_ci    # Make sure this was not re-enabled by accident (additive config)
3581a8e1175bSopenharmony_ci    not grep mbedtls_rsa library/rsa.o
3582a8e1175bSopenharmony_ci
3583a8e1175bSopenharmony_ci    # Run the tests
3584a8e1175bSopenharmony_ci    # -------------
3585a8e1175bSopenharmony_ci
3586a8e1175bSopenharmony_ci    msg "test: crypto_full with accelerated RSA"
3587a8e1175bSopenharmony_ci    make test
3588a8e1175bSopenharmony_ci}
3589a8e1175bSopenharmony_ci
3590a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_reference_rsa_crypto () {
3591a8e1175bSopenharmony_ci    msg "build: crypto_full with non-accelerated RSA"
3592a8e1175bSopenharmony_ci
3593a8e1175bSopenharmony_ci    # Configure
3594a8e1175bSopenharmony_ci    # ---------
3595a8e1175bSopenharmony_ci    config_psa_crypto_accel_rsa 0
3596a8e1175bSopenharmony_ci
3597a8e1175bSopenharmony_ci    # Build
3598a8e1175bSopenharmony_ci    # -----
3599a8e1175bSopenharmony_ci    make
3600a8e1175bSopenharmony_ci
3601a8e1175bSopenharmony_ci    # Run the tests
3602a8e1175bSopenharmony_ci    # -------------
3603a8e1175bSopenharmony_ci    msg "test: crypto_full with non-accelerated RSA"
3604a8e1175bSopenharmony_ci    make test
3605a8e1175bSopenharmony_ci}
3606a8e1175bSopenharmony_ci
3607a8e1175bSopenharmony_ci# This is a temporary test to verify that full RSA support is present even when
3608a8e1175bSopenharmony_ci# only one single new symbols (PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) is defined.
3609a8e1175bSopenharmony_cicomponent_test_new_psa_want_key_pair_symbol() {
3610a8e1175bSopenharmony_ci    msg "Build: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
3611a8e1175bSopenharmony_ci
3612a8e1175bSopenharmony_ci    # Create a temporary output file unless there is already one set
3613a8e1175bSopenharmony_ci    if [ "$MBEDTLS_TEST_OUTCOME_FILE" ]; then
3614a8e1175bSopenharmony_ci        REMOVE_OUTCOME_ON_EXIT="no"
3615a8e1175bSopenharmony_ci    else
3616a8e1175bSopenharmony_ci        REMOVE_OUTCOME_ON_EXIT="yes"
3617a8e1175bSopenharmony_ci        MBEDTLS_TEST_OUTCOME_FILE="$PWD/out.csv"
3618a8e1175bSopenharmony_ci        export MBEDTLS_TEST_OUTCOME_FILE
3619a8e1175bSopenharmony_ci    fi
3620a8e1175bSopenharmony_ci
3621a8e1175bSopenharmony_ci    # Start from crypto configuration
3622a8e1175bSopenharmony_ci    scripts/config.py crypto
3623a8e1175bSopenharmony_ci
3624a8e1175bSopenharmony_ci    # Remove RSA support and its dependencies
3625a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PKCS1_V15
3626a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PKCS1_V21
3627a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
3628a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
3629a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
3630a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
3631a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
3632a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_RSA_C
3633a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
3634a8e1175bSopenharmony_ci
3635a8e1175bSopenharmony_ci    # Enable PSA support
3636a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
3637a8e1175bSopenharmony_ci
3638a8e1175bSopenharmony_ci    # Keep only PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC enabled in order to ensure
3639a8e1175bSopenharmony_ci    # that proper translations is done in crypto_legacy.h.
3640a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
3641a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT
3642a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE
3643a8e1175bSopenharmony_ci
3644a8e1175bSopenharmony_ci    make
3645a8e1175bSopenharmony_ci
3646a8e1175bSopenharmony_ci    msg "Test: crypto config - MBEDTLS_RSA_C + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC"
3647a8e1175bSopenharmony_ci    make test
3648a8e1175bSopenharmony_ci
3649a8e1175bSopenharmony_ci    # Parse only 1 relevant line from the outcome file, i.e. a test which is
3650a8e1175bSopenharmony_ci    # performing RSA signature.
3651a8e1175bSopenharmony_ci    msg "Verify that 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' is PASS"
3652a8e1175bSopenharmony_ci    cat $MBEDTLS_TEST_OUTCOME_FILE | grep 'RSA PKCS1 Sign #1 (SHA512, 1536 bits RSA)' | grep -q "PASS"
3653a8e1175bSopenharmony_ci
3654a8e1175bSopenharmony_ci    if [ "$REMOVE_OUTCOME_ON_EXIT" == "yes" ]; then
3655a8e1175bSopenharmony_ci        rm $MBEDTLS_TEST_OUTCOME_FILE
3656a8e1175bSopenharmony_ci    fi
3657a8e1175bSopenharmony_ci}
3658a8e1175bSopenharmony_ci
3659a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_hash () {
3660a8e1175bSopenharmony_ci    msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
3661a8e1175bSopenharmony_ci
3662a8e1175bSopenharmony_ci    loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3663a8e1175bSopenharmony_ci                    ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3664a8e1175bSopenharmony_ci                    ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
3665a8e1175bSopenharmony_ci
3666a8e1175bSopenharmony_ci    # Configure
3667a8e1175bSopenharmony_ci    # ---------
3668a8e1175bSopenharmony_ci
3669a8e1175bSopenharmony_ci    # Start from default config (no USE_PSA)
3670a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "default"
3671a8e1175bSopenharmony_ci
3672a8e1175bSopenharmony_ci    # Disable the things that are being accelerated
3673a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_MD5_C
3674a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_RIPEMD160_C
3675a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA1_C
3676a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA224_C
3677a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA256_C
3678a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA384_C
3679a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA512_C
3680a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA3_C
3681a8e1175bSopenharmony_ci
3682a8e1175bSopenharmony_ci    # Build
3683a8e1175bSopenharmony_ci    # -----
3684a8e1175bSopenharmony_ci
3685a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list"
3686a8e1175bSopenharmony_ci
3687a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
3688a8e1175bSopenharmony_ci
3689a8e1175bSopenharmony_ci    # There's a risk of something getting re-enabled via config_psa.h;
3690a8e1175bSopenharmony_ci    # make sure it did not happen. Note: it's OK for MD_C to be enabled.
3691a8e1175bSopenharmony_ci    not grep mbedtls_md5 library/md5.o
3692a8e1175bSopenharmony_ci    not grep mbedtls_sha1 library/sha1.o
3693a8e1175bSopenharmony_ci    not grep mbedtls_sha256 library/sha256.o
3694a8e1175bSopenharmony_ci    not grep mbedtls_sha512 library/sha512.o
3695a8e1175bSopenharmony_ci    not grep mbedtls_ripemd160 library/ripemd160.o
3696a8e1175bSopenharmony_ci
3697a8e1175bSopenharmony_ci    # Run the tests
3698a8e1175bSopenharmony_ci    # -------------
3699a8e1175bSopenharmony_ci
3700a8e1175bSopenharmony_ci    msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash"
3701a8e1175bSopenharmony_ci    make test
3702a8e1175bSopenharmony_ci}
3703a8e1175bSopenharmony_ci
3704a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_hash_keep_builtins () {
3705a8e1175bSopenharmony_ci    msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
3706a8e1175bSopenharmony_ci    # This component ensures that all the test cases for
3707a8e1175bSopenharmony_ci    # md_psa_dynamic_dispatch with legacy+driver in test_suite_md are run.
3708a8e1175bSopenharmony_ci
3709a8e1175bSopenharmony_ci    loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3710a8e1175bSopenharmony_ci                    ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3711a8e1175bSopenharmony_ci                    ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
3712a8e1175bSopenharmony_ci
3713a8e1175bSopenharmony_ci    # Start from default config (no USE_PSA)
3714a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "default"
3715a8e1175bSopenharmony_ci
3716a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list"
3717a8e1175bSopenharmony_ci
3718a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
3719a8e1175bSopenharmony_ci
3720a8e1175bSopenharmony_ci    msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated+builtin hash"
3721a8e1175bSopenharmony_ci    make test
3722a8e1175bSopenharmony_ci}
3723a8e1175bSopenharmony_ci
3724a8e1175bSopenharmony_ci# Auxiliary function to build config for hashes with and without drivers
3725a8e1175bSopenharmony_ciconfig_psa_crypto_hash_use_psa () {
3726a8e1175bSopenharmony_ci    driver_only="$1"
3727a8e1175bSopenharmony_ci    # start with config full for maximum coverage (also enables USE_PSA)
3728a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "full"
3729a8e1175bSopenharmony_ci    if [ "$driver_only" -eq 1 ]; then
3730a8e1175bSopenharmony_ci        # disable the built-in implementation of hashes
3731a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_MD5_C
3732a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_RIPEMD160_C
3733a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_SHA1_C
3734a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_SHA224_C
3735a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_SHA256_C # see external RNG below
3736a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
3737a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_SHA384_C
3738a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_SHA512_C
3739a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
3740a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_SHA3_C
3741a8e1175bSopenharmony_ci    fi
3742a8e1175bSopenharmony_ci}
3743a8e1175bSopenharmony_ci
3744a8e1175bSopenharmony_ci# Note that component_test_psa_crypto_config_reference_hash_use_psa
3745a8e1175bSopenharmony_ci# is related to this component and both components need to be kept in sync.
3746a8e1175bSopenharmony_ci# For details please see comments for component_test_psa_crypto_config_reference_hash_use_psa.
3747a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_hash_use_psa () {
3748a8e1175bSopenharmony_ci    msg "test: full with accelerated hashes"
3749a8e1175bSopenharmony_ci
3750a8e1175bSopenharmony_ci    loc_accel_list="ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3751a8e1175bSopenharmony_ci                    ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3752a8e1175bSopenharmony_ci                    ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
3753a8e1175bSopenharmony_ci
3754a8e1175bSopenharmony_ci    # Configure
3755a8e1175bSopenharmony_ci    # ---------
3756a8e1175bSopenharmony_ci
3757a8e1175bSopenharmony_ci    config_psa_crypto_hash_use_psa 1
3758a8e1175bSopenharmony_ci
3759a8e1175bSopenharmony_ci    # Build
3760a8e1175bSopenharmony_ci    # -----
3761a8e1175bSopenharmony_ci
3762a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list"
3763a8e1175bSopenharmony_ci
3764a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
3765a8e1175bSopenharmony_ci
3766a8e1175bSopenharmony_ci    # There's a risk of something getting re-enabled via config_psa.h;
3767a8e1175bSopenharmony_ci    # make sure it did not happen. Note: it's OK for MD_C to be enabled.
3768a8e1175bSopenharmony_ci    not grep mbedtls_md5 library/md5.o
3769a8e1175bSopenharmony_ci    not grep mbedtls_sha1 library/sha1.o
3770a8e1175bSopenharmony_ci    not grep mbedtls_sha256 library/sha256.o
3771a8e1175bSopenharmony_ci    not grep mbedtls_sha512 library/sha512.o
3772a8e1175bSopenharmony_ci    not grep mbedtls_ripemd160 library/ripemd160.o
3773a8e1175bSopenharmony_ci
3774a8e1175bSopenharmony_ci    # Run the tests
3775a8e1175bSopenharmony_ci    # -------------
3776a8e1175bSopenharmony_ci
3777a8e1175bSopenharmony_ci    msg "test: full with accelerated hashes"
3778a8e1175bSopenharmony_ci    make test
3779a8e1175bSopenharmony_ci
3780a8e1175bSopenharmony_ci    # This is mostly useful so that we can later compare outcome files with
3781a8e1175bSopenharmony_ci    # the reference config in analyze_outcomes.py, to check that the
3782a8e1175bSopenharmony_ci    # dependency declarations in ssl-opt.sh and in TLS code are correct.
3783a8e1175bSopenharmony_ci    msg "test: ssl-opt.sh, full with accelerated hashes"
3784a8e1175bSopenharmony_ci    tests/ssl-opt.sh
3785a8e1175bSopenharmony_ci
3786a8e1175bSopenharmony_ci    # This is to make sure all ciphersuites are exercised, but we don't need
3787a8e1175bSopenharmony_ci    # interop testing (besides, we already got some from ssl-opt.sh).
3788a8e1175bSopenharmony_ci    msg "test: compat.sh, full with accelerated hashes"
3789a8e1175bSopenharmony_ci    tests/compat.sh -p mbedTLS -V YES
3790a8e1175bSopenharmony_ci}
3791a8e1175bSopenharmony_ci
3792a8e1175bSopenharmony_ci# This component provides reference configuration for test_psa_crypto_config_accel_hash_use_psa
3793a8e1175bSopenharmony_ci# without accelerated hash. The outcome from both components are used by the analyze_outcomes.py
3794a8e1175bSopenharmony_ci# script to find regression in test coverage when accelerated hash is used (tests and ssl-opt).
3795a8e1175bSopenharmony_ci# Both components need to be kept in sync.
3796a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_reference_hash_use_psa() {
3797a8e1175bSopenharmony_ci    msg "test: full without accelerated hashes"
3798a8e1175bSopenharmony_ci
3799a8e1175bSopenharmony_ci    config_psa_crypto_hash_use_psa 0
3800a8e1175bSopenharmony_ci
3801a8e1175bSopenharmony_ci    make
3802a8e1175bSopenharmony_ci
3803a8e1175bSopenharmony_ci    msg "test: full without accelerated hashes"
3804a8e1175bSopenharmony_ci    make test
3805a8e1175bSopenharmony_ci
3806a8e1175bSopenharmony_ci    msg "test: ssl-opt.sh, full without accelerated hashes"
3807a8e1175bSopenharmony_ci    tests/ssl-opt.sh
3808a8e1175bSopenharmony_ci}
3809a8e1175bSopenharmony_ci
3810a8e1175bSopenharmony_ci# Auxiliary function to build config for hashes with and without drivers
3811a8e1175bSopenharmony_ciconfig_psa_crypto_hmac_use_psa () {
3812a8e1175bSopenharmony_ci    driver_only="$1"
3813a8e1175bSopenharmony_ci    # start with config full for maximum coverage (also enables USE_PSA)
3814a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "full"
3815a8e1175bSopenharmony_ci
3816a8e1175bSopenharmony_ci    if [ "$driver_only" -eq 1 ]; then
3817a8e1175bSopenharmony_ci        # Disable MD_C in order to disable the builtin support for HMAC. MD_LIGHT
3818a8e1175bSopenharmony_ci        # is still enabled though (for ENTROPY_C among others).
3819a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_MD_C
3820a8e1175bSopenharmony_ci        # Disable also the builtin hashes since they are supported by the driver
3821a8e1175bSopenharmony_ci        # and MD module is able to perform PSA dispathing.
3822a8e1175bSopenharmony_ci        scripts/config.py unset-all MBEDTLS_SHA
3823a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_MD5_C
3824a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_RIPEMD160_C
3825a8e1175bSopenharmony_ci    fi
3826a8e1175bSopenharmony_ci
3827a8e1175bSopenharmony_ci    # Direct dependencies of MD_C. We disable them also in the reference
3828a8e1175bSopenharmony_ci    # component to work with the same set of features.
3829a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PKCS7_C
3830a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PKCS5_C
3831a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_HMAC_DRBG_C
3832a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_HKDF_C
3833a8e1175bSopenharmony_ci    # Dependencies of HMAC_DRBG
3834a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC
3835a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_DETERMINISTIC_ECDSA
3836a8e1175bSopenharmony_ci}
3837a8e1175bSopenharmony_ci
3838a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_hmac() {
3839a8e1175bSopenharmony_ci    msg "test: full with accelerated hmac"
3840a8e1175bSopenharmony_ci
3841a8e1175bSopenharmony_ci    loc_accel_list="ALG_HMAC KEY_TYPE_HMAC \
3842a8e1175bSopenharmony_ci                    ALG_MD5 ALG_RIPEMD160 ALG_SHA_1 \
3843a8e1175bSopenharmony_ci                    ALG_SHA_224 ALG_SHA_256 ALG_SHA_384 ALG_SHA_512 \
3844a8e1175bSopenharmony_ci                    ALG_SHA3_224 ALG_SHA3_256 ALG_SHA3_384 ALG_SHA3_512"
3845a8e1175bSopenharmony_ci
3846a8e1175bSopenharmony_ci    # Configure
3847a8e1175bSopenharmony_ci    # ---------
3848a8e1175bSopenharmony_ci
3849a8e1175bSopenharmony_ci    config_psa_crypto_hmac_use_psa 1
3850a8e1175bSopenharmony_ci
3851a8e1175bSopenharmony_ci    # Build
3852a8e1175bSopenharmony_ci    # -----
3853a8e1175bSopenharmony_ci
3854a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list"
3855a8e1175bSopenharmony_ci
3856a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
3857a8e1175bSopenharmony_ci
3858a8e1175bSopenharmony_ci    # Ensure that built-in support for HMAC is disabled.
3859a8e1175bSopenharmony_ci    not grep mbedtls_md_hmac library/md.o
3860a8e1175bSopenharmony_ci
3861a8e1175bSopenharmony_ci    # Run the tests
3862a8e1175bSopenharmony_ci    # -------------
3863a8e1175bSopenharmony_ci
3864a8e1175bSopenharmony_ci    msg "test: full with accelerated hmac"
3865a8e1175bSopenharmony_ci    make test
3866a8e1175bSopenharmony_ci}
3867a8e1175bSopenharmony_ci
3868a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_reference_hmac() {
3869a8e1175bSopenharmony_ci    msg "test: full without accelerated hmac"
3870a8e1175bSopenharmony_ci
3871a8e1175bSopenharmony_ci    config_psa_crypto_hmac_use_psa 0
3872a8e1175bSopenharmony_ci
3873a8e1175bSopenharmony_ci    make
3874a8e1175bSopenharmony_ci
3875a8e1175bSopenharmony_ci    msg "test: full without accelerated hmac"
3876a8e1175bSopenharmony_ci    make test
3877a8e1175bSopenharmony_ci}
3878a8e1175bSopenharmony_ci
3879a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_des () {
3880a8e1175bSopenharmony_ci    msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
3881a8e1175bSopenharmony_ci
3882a8e1175bSopenharmony_ci    # Albeit this components aims at accelerating DES which should only support
3883a8e1175bSopenharmony_ci    # CBC and ECB modes, we need to accelerate more than that otherwise DES_C
3884a8e1175bSopenharmony_ci    # would automatically be re-enabled by "config_adjust_legacy_from_psa.c"
3885a8e1175bSopenharmony_ci    loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 \
3886a8e1175bSopenharmony_ci                    ALG_CTR ALG_CFB ALG_OFB ALG_XTS ALG_CMAC \
3887a8e1175bSopenharmony_ci                    KEY_TYPE_DES"
3888a8e1175bSopenharmony_ci
3889a8e1175bSopenharmony_ci    # Note: we cannot accelerate all ciphers' key types otherwise we would also
3890a8e1175bSopenharmony_ci    # have to either disable CCM/GCM or accelerate them, but that's out of scope
3891a8e1175bSopenharmony_ci    # of this component. This limitation will be addressed by #8598.
3892a8e1175bSopenharmony_ci
3893a8e1175bSopenharmony_ci    # Configure
3894a8e1175bSopenharmony_ci    # ---------
3895a8e1175bSopenharmony_ci
3896a8e1175bSopenharmony_ci    # Start from the full config
3897a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "full"
3898a8e1175bSopenharmony_ci
3899a8e1175bSopenharmony_ci    # Disable the things that are being accelerated
3900a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3901a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
3902a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
3903a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
3904a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
3905a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
3906a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_DES_C
3907a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CMAC_C
3908a8e1175bSopenharmony_ci
3909a8e1175bSopenharmony_ci    # Build
3910a8e1175bSopenharmony_ci    # -----
3911a8e1175bSopenharmony_ci
3912a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list"
3913a8e1175bSopenharmony_ci
3914a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
3915a8e1175bSopenharmony_ci
3916a8e1175bSopenharmony_ci    # Make sure this was not re-enabled by accident (additive config)
3917a8e1175bSopenharmony_ci    not grep mbedtls_des* library/des.o
3918a8e1175bSopenharmony_ci
3919a8e1175bSopenharmony_ci    # Run the tests
3920a8e1175bSopenharmony_ci    # -------------
3921a8e1175bSopenharmony_ci
3922a8e1175bSopenharmony_ci    msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated DES"
3923a8e1175bSopenharmony_ci    make test
3924a8e1175bSopenharmony_ci}
3925a8e1175bSopenharmony_ci
3926a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_aead () {
3927a8e1175bSopenharmony_ci    msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
3928a8e1175bSopenharmony_ci
3929a8e1175bSopenharmony_ci    loc_accel_list="ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 \
3930a8e1175bSopenharmony_ci                    KEY_TYPE_AES KEY_TYPE_CHACHA20 KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
3931a8e1175bSopenharmony_ci
3932a8e1175bSopenharmony_ci    # Configure
3933a8e1175bSopenharmony_ci    # ---------
3934a8e1175bSopenharmony_ci
3935a8e1175bSopenharmony_ci    # Start from full config
3936a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "full"
3937a8e1175bSopenharmony_ci
3938a8e1175bSopenharmony_ci    # Disable things that are being accelerated
3939a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_GCM_C
3940a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CCM_C
3941a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CHACHAPOLY_C
3942a8e1175bSopenharmony_ci
3943a8e1175bSopenharmony_ci    # Disable CCM_STAR_NO_TAG because this re-enables CCM_C.
3944a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
3945a8e1175bSopenharmony_ci
3946a8e1175bSopenharmony_ci    # Build
3947a8e1175bSopenharmony_ci    # -----
3948a8e1175bSopenharmony_ci
3949a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list"
3950a8e1175bSopenharmony_ci
3951a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
3952a8e1175bSopenharmony_ci
3953a8e1175bSopenharmony_ci    # Make sure this was not re-enabled by accident (additive config)
3954a8e1175bSopenharmony_ci    not grep mbedtls_ccm library/ccm.o
3955a8e1175bSopenharmony_ci    not grep mbedtls_gcm library/gcm.o
3956a8e1175bSopenharmony_ci    not grep mbedtls_chachapoly library/chachapoly.o
3957a8e1175bSopenharmony_ci
3958a8e1175bSopenharmony_ci    # Run the tests
3959a8e1175bSopenharmony_ci    # -------------
3960a8e1175bSopenharmony_ci
3961a8e1175bSopenharmony_ci    msg "test: MBEDTLS_PSA_CRYPTO_CONFIG with accelerated AEAD"
3962a8e1175bSopenharmony_ci    make test
3963a8e1175bSopenharmony_ci}
3964a8e1175bSopenharmony_ci
3965a8e1175bSopenharmony_ci# This is a common configuration function used in:
3966a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_accel_cipher_aead_cmac
3967a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_reference_cipher_aead_cmac
3968a8e1175bSopenharmony_cicommon_psa_crypto_config_accel_cipher_aead_cmac() {
3969a8e1175bSopenharmony_ci    # Start from the full config
3970a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "full"
3971a8e1175bSopenharmony_ci
3972a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_NIST_KW_C
3973a8e1175bSopenharmony_ci}
3974a8e1175bSopenharmony_ci
3975a8e1175bSopenharmony_ci# The 2 following test components, i.e.
3976a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_accel_cipher_aead_cmac
3977a8e1175bSopenharmony_ci# - component_test_psa_crypto_config_reference_cipher_aead_cmac
3978a8e1175bSopenharmony_ci# are meant to be used together in analyze_outcomes.py script in order to test
3979a8e1175bSopenharmony_ci# driver's coverage for ciphers and AEADs.
3980a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_accel_cipher_aead_cmac () {
3981a8e1175bSopenharmony_ci    msg "build: full config with accelerated cipher inc. AEAD and CMAC"
3982a8e1175bSopenharmony_ci
3983a8e1175bSopenharmony_ci    loc_accel_list="ALG_ECB_NO_PADDING ALG_CBC_NO_PADDING ALG_CBC_PKCS7 ALG_CTR ALG_CFB \
3984a8e1175bSopenharmony_ci                    ALG_OFB ALG_XTS ALG_STREAM_CIPHER ALG_CCM_STAR_NO_TAG \
3985a8e1175bSopenharmony_ci                    ALG_GCM ALG_CCM ALG_CHACHA20_POLY1305 ALG_CMAC \
3986a8e1175bSopenharmony_ci                    KEY_TYPE_DES KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CHACHA20 KEY_TYPE_CAMELLIA"
3987a8e1175bSopenharmony_ci
3988a8e1175bSopenharmony_ci    # Configure
3989a8e1175bSopenharmony_ci    # ---------
3990a8e1175bSopenharmony_ci
3991a8e1175bSopenharmony_ci    common_psa_crypto_config_accel_cipher_aead_cmac
3992a8e1175bSopenharmony_ci
3993a8e1175bSopenharmony_ci    # Disable the things that are being accelerated
3994a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
3995a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_PADDING_PKCS7
3996a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_MODE_CTR
3997a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_MODE_CFB
3998a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_MODE_OFB
3999a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
4000a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_GCM_C
4001a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CCM_C
4002a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CHACHAPOLY_C
4003a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CMAC_C
4004a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_DES_C
4005a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AES_C
4006a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ARIA_C
4007a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CHACHA20_C
4008a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CAMELLIA_C
4009a8e1175bSopenharmony_ci
4010a8e1175bSopenharmony_ci    # Disable CIPHER_C entirely as all ciphers/AEADs are accelerated and PSA
4011a8e1175bSopenharmony_ci    # does not depend on it.
4012a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_C
4013a8e1175bSopenharmony_ci
4014a8e1175bSopenharmony_ci    # Build
4015a8e1175bSopenharmony_ci    # -----
4016a8e1175bSopenharmony_ci
4017a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list"
4018a8e1175bSopenharmony_ci
4019a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
4020a8e1175bSopenharmony_ci
4021a8e1175bSopenharmony_ci    # Make sure this was not re-enabled by accident (additive config)
4022a8e1175bSopenharmony_ci    not grep mbedtls_cipher library/cipher.o
4023a8e1175bSopenharmony_ci    not grep mbedtls_des library/des.o
4024a8e1175bSopenharmony_ci    not grep mbedtls_aes library/aes.o
4025a8e1175bSopenharmony_ci    not grep mbedtls_aria library/aria.o
4026a8e1175bSopenharmony_ci    not grep mbedtls_camellia library/camellia.o
4027a8e1175bSopenharmony_ci    not grep mbedtls_ccm library/ccm.o
4028a8e1175bSopenharmony_ci    not grep mbedtls_gcm library/gcm.o
4029a8e1175bSopenharmony_ci    not grep mbedtls_chachapoly library/chachapoly.o
4030a8e1175bSopenharmony_ci    not grep mbedtls_cmac library/cmac.o
4031a8e1175bSopenharmony_ci
4032a8e1175bSopenharmony_ci    # Run the tests
4033a8e1175bSopenharmony_ci    # -------------
4034a8e1175bSopenharmony_ci
4035a8e1175bSopenharmony_ci    msg "test: full config with accelerated cipher inc. AEAD and CMAC"
4036a8e1175bSopenharmony_ci    make test
4037a8e1175bSopenharmony_ci
4038a8e1175bSopenharmony_ci    msg "ssl-opt: full config with accelerated cipher inc. AEAD and CMAC"
4039a8e1175bSopenharmony_ci    tests/ssl-opt.sh
4040a8e1175bSopenharmony_ci
4041a8e1175bSopenharmony_ci    msg "compat.sh: full config with accelerated cipher inc. AEAD and CMAC"
4042a8e1175bSopenharmony_ci    tests/compat.sh -V NO -p mbedTLS
4043a8e1175bSopenharmony_ci}
4044a8e1175bSopenharmony_ci
4045a8e1175bSopenharmony_cicomponent_test_psa_crypto_config_reference_cipher_aead_cmac () {
4046a8e1175bSopenharmony_ci    msg "build: full config with non-accelerated cipher inc. AEAD and CMAC"
4047a8e1175bSopenharmony_ci    common_psa_crypto_config_accel_cipher_aead_cmac
4048a8e1175bSopenharmony_ci
4049a8e1175bSopenharmony_ci    make
4050a8e1175bSopenharmony_ci
4051a8e1175bSopenharmony_ci    msg "test: full config with non-accelerated cipher inc. AEAD and CMAC"
4052a8e1175bSopenharmony_ci    make test
4053a8e1175bSopenharmony_ci
4054a8e1175bSopenharmony_ci    msg "ssl-opt: full config with non-accelerated cipher inc. AEAD and CMAC"
4055a8e1175bSopenharmony_ci    tests/ssl-opt.sh
4056a8e1175bSopenharmony_ci
4057a8e1175bSopenharmony_ci    msg "compat.sh: full config with non-accelerated cipher inc. AEAD and CMAC"
4058a8e1175bSopenharmony_ci    tests/compat.sh -V NO -p mbedTLS
4059a8e1175bSopenharmony_ci}
4060a8e1175bSopenharmony_ci
4061a8e1175bSopenharmony_cicommon_block_cipher_dispatch() {
4062a8e1175bSopenharmony_ci    TEST_WITH_DRIVER="$1"
4063a8e1175bSopenharmony_ci
4064a8e1175bSopenharmony_ci    # Start from the full config
4065a8e1175bSopenharmony_ci    helper_libtestdriver1_adjust_config "full"
4066a8e1175bSopenharmony_ci
4067a8e1175bSopenharmony_ci    if [ "$TEST_WITH_DRIVER" -eq 1 ]; then
4068a8e1175bSopenharmony_ci        # Disable key types that are accelerated (there is no legacy equivalent
4069a8e1175bSopenharmony_ci        # symbol for ECB)
4070a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_AES_C
4071a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_ARIA_C
4072a8e1175bSopenharmony_ci        scripts/config.py unset MBEDTLS_CAMELLIA_C
4073a8e1175bSopenharmony_ci    fi
4074a8e1175bSopenharmony_ci
4075a8e1175bSopenharmony_ci    # Disable cipher's modes that, when not accelerated, cause
4076a8e1175bSopenharmony_ci    # legacy key types to be re-enabled in "config_adjust_legacy_from_psa.h".
4077a8e1175bSopenharmony_ci    # Keep this also in the reference component in order to skip the same tests
4078a8e1175bSopenharmony_ci    # that were skipped in the accelerated one.
4079a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CTR
4080a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CFB
4081a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_OFB
4082a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
4083a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
4084a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CMAC
4085a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CCM_STAR_NO_TAG
4086a8e1175bSopenharmony_ci
4087a8e1175bSopenharmony_ci    # Disable direct dependency on AES_C
4088a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_NIST_KW_C
4089a8e1175bSopenharmony_ci
4090a8e1175bSopenharmony_ci    # Prevent the cipher module from using deprecated PSA path. The reason is
4091a8e1175bSopenharmony_ci    # that otherwise there will be tests relying on "aes_info" (defined in
4092a8e1175bSopenharmony_ci    # "cipher_wrap.c") whose functions are not available when AES_C is
4093a8e1175bSopenharmony_ci    # not defined. ARIA and Camellia are not a problem in this case because
4094a8e1175bSopenharmony_ci    # the PSA path is not tested for these key types.
4095a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_DEPRECATED_REMOVED
4096a8e1175bSopenharmony_ci}
4097a8e1175bSopenharmony_ci
4098a8e1175bSopenharmony_cicomponent_test_full_block_cipher_psa_dispatch () {
4099a8e1175bSopenharmony_ci    msg "build: full + PSA dispatch in block_cipher"
4100a8e1175bSopenharmony_ci
4101a8e1175bSopenharmony_ci    loc_accel_list="ALG_ECB_NO_PADDING \
4102a8e1175bSopenharmony_ci                    KEY_TYPE_AES KEY_TYPE_ARIA KEY_TYPE_CAMELLIA"
4103a8e1175bSopenharmony_ci
4104a8e1175bSopenharmony_ci    # Configure
4105a8e1175bSopenharmony_ci    # ---------
4106a8e1175bSopenharmony_ci
4107a8e1175bSopenharmony_ci    common_block_cipher_dispatch 1
4108a8e1175bSopenharmony_ci
4109a8e1175bSopenharmony_ci    # Build
4110a8e1175bSopenharmony_ci    # -----
4111a8e1175bSopenharmony_ci
4112a8e1175bSopenharmony_ci    helper_libtestdriver1_make_drivers "$loc_accel_list"
4113a8e1175bSopenharmony_ci
4114a8e1175bSopenharmony_ci    helper_libtestdriver1_make_main "$loc_accel_list"
4115a8e1175bSopenharmony_ci
4116a8e1175bSopenharmony_ci    # Make sure disabled components were not re-enabled by accident (additive
4117a8e1175bSopenharmony_ci    # config)
4118a8e1175bSopenharmony_ci    not grep mbedtls_aes_ library/aes.o
4119a8e1175bSopenharmony_ci    not grep mbedtls_aria_ library/aria.o
4120a8e1175bSopenharmony_ci    not grep mbedtls_camellia_ library/camellia.o
4121a8e1175bSopenharmony_ci
4122a8e1175bSopenharmony_ci    # Run the tests
4123a8e1175bSopenharmony_ci    # -------------
4124a8e1175bSopenharmony_ci
4125a8e1175bSopenharmony_ci    msg "test: full + PSA dispatch in block_cipher"
4126a8e1175bSopenharmony_ci    make test
4127a8e1175bSopenharmony_ci}
4128a8e1175bSopenharmony_ci
4129a8e1175bSopenharmony_ci# This is the reference component of component_test_full_block_cipher_psa_dispatch
4130a8e1175bSopenharmony_cicomponent_test_full_block_cipher_legacy_dispatch () {
4131a8e1175bSopenharmony_ci    msg "build: full + legacy dispatch in block_cipher"
4132a8e1175bSopenharmony_ci
4133a8e1175bSopenharmony_ci    common_block_cipher_dispatch 0
4134a8e1175bSopenharmony_ci
4135a8e1175bSopenharmony_ci    make
4136a8e1175bSopenharmony_ci
4137a8e1175bSopenharmony_ci    msg "test: full + legacy dispatch in block_cipher"
4138a8e1175bSopenharmony_ci    make test
4139a8e1175bSopenharmony_ci}
4140a8e1175bSopenharmony_ci
4141a8e1175bSopenharmony_cicomponent_test_aead_chachapoly_disabled() {
4142a8e1175bSopenharmony_ci    msg "build: full minus CHACHAPOLY"
4143a8e1175bSopenharmony_ci    scripts/config.py full
4144a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CHACHAPOLY_C
4145a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
4146a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
4147a8e1175bSopenharmony_ci
4148a8e1175bSopenharmony_ci    msg "test: full minus CHACHAPOLY"
4149a8e1175bSopenharmony_ci    make test
4150a8e1175bSopenharmony_ci}
4151a8e1175bSopenharmony_ci
4152a8e1175bSopenharmony_cicomponent_test_aead_only_ccm() {
4153a8e1175bSopenharmony_ci    msg "build: full minus CHACHAPOLY and GCM"
4154a8e1175bSopenharmony_ci    scripts/config.py full
4155a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CHACHAPOLY_C
4156a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_GCM_C
4157a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CHACHA20_POLY1305
4158a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_GCM
4159a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
4160a8e1175bSopenharmony_ci
4161a8e1175bSopenharmony_ci    msg "test: full minus CHACHAPOLY and GCM"
4162a8e1175bSopenharmony_ci    make test
4163a8e1175bSopenharmony_ci}
4164a8e1175bSopenharmony_ci
4165a8e1175bSopenharmony_cicomponent_test_ccm_aes_sha256() {
4166a8e1175bSopenharmony_ci    msg "build: CCM + AES + SHA256 configuration"
4167a8e1175bSopenharmony_ci
4168a8e1175bSopenharmony_ci    cp "$CONFIG_TEST_DRIVER_H" "$CONFIG_H"
4169a8e1175bSopenharmony_ci    cp configs/crypto-config-ccm-aes-sha256.h "$CRYPTO_CONFIG_H"
4170a8e1175bSopenharmony_ci
4171a8e1175bSopenharmony_ci    make
4172a8e1175bSopenharmony_ci
4173a8e1175bSopenharmony_ci    msg "test: CCM + AES + SHA256 configuration"
4174a8e1175bSopenharmony_ci    make test
4175a8e1175bSopenharmony_ci}
4176a8e1175bSopenharmony_ci
4177a8e1175bSopenharmony_ci# This should be renamed to test and updated once the accelerator ECDH code is in place and ready to test.
4178a8e1175bSopenharmony_cicomponent_build_psa_accel_alg_ecdh() {
4179a8e1175bSopenharmony_ci    msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_ECDH without MBEDTLS_ECDH_C"
4180a8e1175bSopenharmony_ci    scripts/config.py full
4181a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
4182a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4183a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDH_C
4184a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
4185a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
4186a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
4187a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
4188a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
4189a8e1175bSopenharmony_ci    # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4190a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_ECDH -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
4191a8e1175bSopenharmony_ci}
4192a8e1175bSopenharmony_ci
4193a8e1175bSopenharmony_ci# This should be renamed to test and updated once the accelerator HMAC code is in place and ready to test.
4194a8e1175bSopenharmony_cicomponent_build_psa_accel_alg_hmac() {
4195a8e1175bSopenharmony_ci    msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HMAC"
4196a8e1175bSopenharmony_ci    scripts/config.py full
4197a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
4198a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4199a8e1175bSopenharmony_ci    # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4200a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
4201a8e1175bSopenharmony_ci}
4202a8e1175bSopenharmony_ci
4203a8e1175bSopenharmony_ci# This should be renamed to test and updated once the accelerator HKDF code is in place and ready to test.
4204a8e1175bSopenharmony_cicomponent_build_psa_accel_alg_hkdf() {
4205a8e1175bSopenharmony_ci    msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_HKDF without MBEDTLS_HKDF_C"
4206a8e1175bSopenharmony_ci    scripts/config.py full
4207a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
4208a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_HKDF_C
4209a8e1175bSopenharmony_ci    # Make sure to unset TLS1_3 since it requires HKDF_C and will not build properly without it.
4210a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4211a8e1175bSopenharmony_ci    # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4212a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
4213a8e1175bSopenharmony_ci}
4214a8e1175bSopenharmony_ci
4215a8e1175bSopenharmony_ci# This should be renamed to test and updated once the accelerator MD5 code is in place and ready to test.
4216a8e1175bSopenharmony_cicomponent_build_psa_accel_alg_md5() {
4217a8e1175bSopenharmony_ci    msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_MD5 - other hashes"
4218a8e1175bSopenharmony_ci    scripts/config.py full
4219a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
4220a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4221a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
4222a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
4223a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
4224a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
4225a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
4226a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
4227a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
4228a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_LMS_C
4229a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_LMS_PRIVATE
4230a8e1175bSopenharmony_ci    # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4231a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_MD5 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
4232a8e1175bSopenharmony_ci}
4233a8e1175bSopenharmony_ci
4234a8e1175bSopenharmony_ci# This should be renamed to test and updated once the accelerator RIPEMD160 code is in place and ready to test.
4235a8e1175bSopenharmony_cicomponent_build_psa_accel_alg_ripemd160() {
4236a8e1175bSopenharmony_ci    msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RIPEMD160 - other hashes"
4237a8e1175bSopenharmony_ci    scripts/config.py full
4238a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
4239a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4240a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
4241a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
4242a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
4243a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
4244a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
4245a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
4246a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
4247a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_LMS_C
4248a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_LMS_PRIVATE
4249a8e1175bSopenharmony_ci    # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4250a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RIPEMD160 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
4251a8e1175bSopenharmony_ci}
4252a8e1175bSopenharmony_ci
4253a8e1175bSopenharmony_ci# This should be renamed to test and updated once the accelerator SHA1 code is in place and ready to test.
4254a8e1175bSopenharmony_cicomponent_build_psa_accel_alg_sha1() {
4255a8e1175bSopenharmony_ci    msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_1 - other hashes"
4256a8e1175bSopenharmony_ci    scripts/config.py full
4257a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
4258a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4259a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
4260a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
4261a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
4262a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
4263a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
4264a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
4265a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
4266a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_LMS_C
4267a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_LMS_PRIVATE
4268a8e1175bSopenharmony_ci    # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4269a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_1 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
4270a8e1175bSopenharmony_ci}
4271a8e1175bSopenharmony_ci
4272a8e1175bSopenharmony_ci# This should be renamed to test and updated once the accelerator SHA224 code is in place and ready to test.
4273a8e1175bSopenharmony_cicomponent_build_psa_accel_alg_sha224() {
4274a8e1175bSopenharmony_ci    msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_224 - other hashes"
4275a8e1175bSopenharmony_ci    scripts/config.py full
4276a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
4277a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4278a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
4279a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
4280a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
4281a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
4282a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
4283a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
4284a8e1175bSopenharmony_ci    # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4285a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_224 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
4286a8e1175bSopenharmony_ci}
4287a8e1175bSopenharmony_ci
4288a8e1175bSopenharmony_ci# This should be renamed to test and updated once the accelerator SHA256 code is in place and ready to test.
4289a8e1175bSopenharmony_cicomponent_build_psa_accel_alg_sha256() {
4290a8e1175bSopenharmony_ci    msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_256 - other hashes"
4291a8e1175bSopenharmony_ci    scripts/config.py full
4292a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
4293a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4294a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
4295a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
4296a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
4297a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
4298a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
4299a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_512
4300a8e1175bSopenharmony_ci    # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4301a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_256 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
4302a8e1175bSopenharmony_ci}
4303a8e1175bSopenharmony_ci
4304a8e1175bSopenharmony_ci# This should be renamed to test and updated once the accelerator SHA384 code is in place and ready to test.
4305a8e1175bSopenharmony_cicomponent_build_psa_accel_alg_sha384() {
4306a8e1175bSopenharmony_ci    msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_384 - other hashes"
4307a8e1175bSopenharmony_ci    scripts/config.py full
4308a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
4309a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4310a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
4311a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
4312a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
4313a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
4314a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
4315a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
4316a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_LMS_C
4317a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_LMS_PRIVATE
4318a8e1175bSopenharmony_ci    # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4319a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_384 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
4320a8e1175bSopenharmony_ci}
4321a8e1175bSopenharmony_ci
4322a8e1175bSopenharmony_ci# This should be renamed to test and updated once the accelerator SHA512 code is in place and ready to test.
4323a8e1175bSopenharmony_cicomponent_build_psa_accel_alg_sha512() {
4324a8e1175bSopenharmony_ci    msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_SHA_512 - other hashes"
4325a8e1175bSopenharmony_ci    scripts/config.py full
4326a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
4327a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4328a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5
4329a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160
4330a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1
4331a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224
4332a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_256
4333a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_384
4334a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS
4335a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_LMS_C
4336a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_LMS_PRIVATE
4337a8e1175bSopenharmony_ci    # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4338a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_SHA_512 -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
4339a8e1175bSopenharmony_ci}
4340a8e1175bSopenharmony_ci
4341a8e1175bSopenharmony_ci# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
4342a8e1175bSopenharmony_cicomponent_build_psa_accel_alg_rsa_pkcs1v15_crypt() {
4343a8e1175bSopenharmony_ci    msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_CRYPT + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
4344a8e1175bSopenharmony_ci    scripts/config.py full
4345a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
4346a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4347a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1
4348a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
4349a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
4350a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
4351a8e1175bSopenharmony_ci    # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4352a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
4353a8e1175bSopenharmony_ci}
4354a8e1175bSopenharmony_ci
4355a8e1175bSopenharmony_ci# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
4356a8e1175bSopenharmony_cicomponent_build_psa_accel_alg_rsa_pkcs1v15_sign() {
4357a8e1175bSopenharmony_ci    msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PKCS1V15_SIGN + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
4358a8e1175bSopenharmony_ci    scripts/config.py full
4359a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
4360a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4361a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1
4362a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
4363a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
4364a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
4365a8e1175bSopenharmony_ci    # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4366a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_SIGN -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
4367a8e1175bSopenharmony_ci}
4368a8e1175bSopenharmony_ci
4369a8e1175bSopenharmony_ci# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
4370a8e1175bSopenharmony_cicomponent_build_psa_accel_alg_rsa_oaep() {
4371a8e1175bSopenharmony_ci    msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_OAEP + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
4372a8e1175bSopenharmony_ci    scripts/config.py full
4373a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
4374a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4375a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_OAEP 1
4376a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
4377a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
4378a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PSS
4379a8e1175bSopenharmony_ci    # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4380a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_OAEP -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
4381a8e1175bSopenharmony_ci}
4382a8e1175bSopenharmony_ci
4383a8e1175bSopenharmony_ci# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
4384a8e1175bSopenharmony_cicomponent_build_psa_accel_alg_rsa_pss() {
4385a8e1175bSopenharmony_ci    msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_ALG_RSA_PSS + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY"
4386a8e1175bSopenharmony_ci    scripts/config.py full
4387a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
4388a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4389a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
4390a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT
4391a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN
4392a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP
4393a8e1175bSopenharmony_ci    # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4394a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_RSA_PSS -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
4395a8e1175bSopenharmony_ci}
4396a8e1175bSopenharmony_ci
4397a8e1175bSopenharmony_ci# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
4398a8e1175bSopenharmony_cicomponent_build_psa_accel_key_type_rsa_key_pair() {
4399a8e1175bSopenharmony_ci    msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_xxx + PSA_WANT_ALG_RSA_PSS"
4400a8e1175bSopenharmony_ci    scripts/config.py full
4401a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
4402a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4403a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
4404a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC 1
4405a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT 1
4406a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_EXPORT 1
4407a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_GENERATE 1
4408a8e1175bSopenharmony_ci    # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4409a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
4410a8e1175bSopenharmony_ci}
4411a8e1175bSopenharmony_ci
4412a8e1175bSopenharmony_ci# This should be renamed to test and updated once the accelerator RSA code is in place and ready to test.
4413a8e1175bSopenharmony_cicomponent_build_psa_accel_key_type_rsa_public_key() {
4414a8e1175bSopenharmony_ci    msg "build: full - MBEDTLS_USE_PSA_CRYPTO + PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY + PSA_WANT_ALG_RSA_PSS"
4415a8e1175bSopenharmony_ci    scripts/config.py full
4416a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO
4417a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4418a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1
4419a8e1175bSopenharmony_ci    scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1
4420a8e1175bSopenharmony_ci    # Need to define the correct symbol and include the test driver header path in order to build with the test driver
4421a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY -I../tests/include" LDFLAGS="$ASAN_CFLAGS"
4422a8e1175bSopenharmony_ci}
4423a8e1175bSopenharmony_ci
4424a8e1175bSopenharmony_ci
4425a8e1175bSopenharmony_cisupport_build_tfm_armcc () {
4426a8e1175bSopenharmony_ci    support_build_armcc
4427a8e1175bSopenharmony_ci}
4428a8e1175bSopenharmony_ci
4429a8e1175bSopenharmony_cicomponent_build_tfm_armcc() {
4430a8e1175bSopenharmony_ci    # test the TF-M configuration can build cleanly with various warning flags enabled
4431a8e1175bSopenharmony_ci    cp configs/config-tfm.h "$CONFIG_H"
4432a8e1175bSopenharmony_ci
4433a8e1175bSopenharmony_ci    msg "build: TF-M config, armclang armv7-m thumb2"
4434a8e1175bSopenharmony_ci    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"
4435a8e1175bSopenharmony_ci}
4436a8e1175bSopenharmony_ci
4437a8e1175bSopenharmony_cicomponent_build_tfm() {
4438a8e1175bSopenharmony_ci    # Check that the TF-M configuration can build cleanly with various
4439a8e1175bSopenharmony_ci    # warning flags enabled. We don't build or run tests, since the
4440a8e1175bSopenharmony_ci    # TF-M configuration needs a TF-M platform. A tweaked version of
4441a8e1175bSopenharmony_ci    # the configuration that works on mainstream platforms is in
4442a8e1175bSopenharmony_ci    # configs/config-tfm.h, tested via test-ref-configs.pl.
4443a8e1175bSopenharmony_ci    cp configs/config-tfm.h "$CONFIG_H"
4444a8e1175bSopenharmony_ci
4445a8e1175bSopenharmony_ci    msg "build: TF-M config, clang, armv7-m thumb2"
4446a8e1175bSopenharmony_ci    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"
4447a8e1175bSopenharmony_ci
4448a8e1175bSopenharmony_ci    msg "build: TF-M config, gcc native build"
4449a8e1175bSopenharmony_ci    make clean
4450a8e1175bSopenharmony_ci    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"
4451a8e1175bSopenharmony_ci}
4452a8e1175bSopenharmony_ci
4453a8e1175bSopenharmony_ci# Test that the given .o file builds with all (valid) combinations of the given options.
4454a8e1175bSopenharmony_ci#
4455a8e1175bSopenharmony_ci# Syntax: build_test_config_combos FILE VALIDATOR_FUNCTION OPT1 OPT2 ...
4456a8e1175bSopenharmony_ci#
4457a8e1175bSopenharmony_ci# The validator function is the name of a function to validate the combination of options.
4458a8e1175bSopenharmony_ci# It may be "" if all combinations are valid.
4459a8e1175bSopenharmony_ci# It receives a string containing a combination of options, as passed to the compiler,
4460a8e1175bSopenharmony_ci# e.g. "-DOPT1 -DOPT2 ...". It must return 0 iff the combination is valid, non-zero if invalid.
4461a8e1175bSopenharmony_cibuild_test_config_combos() {
4462a8e1175bSopenharmony_ci    file=$1
4463a8e1175bSopenharmony_ci    shift
4464a8e1175bSopenharmony_ci    validate_options=$1
4465a8e1175bSopenharmony_ci    shift
4466a8e1175bSopenharmony_ci    options=("$@")
4467a8e1175bSopenharmony_ci
4468a8e1175bSopenharmony_ci    # clear all of the options so that they can be overridden on the clang commandline
4469a8e1175bSopenharmony_ci    for opt in "${options[@]}"; do
4470a8e1175bSopenharmony_ci        ./scripts/config.py unset ${opt}
4471a8e1175bSopenharmony_ci    done
4472a8e1175bSopenharmony_ci
4473a8e1175bSopenharmony_ci    # enter the directory containing the target file & strip the dir from the filename
4474a8e1175bSopenharmony_ci    cd $(dirname ${file})
4475a8e1175bSopenharmony_ci    file=$(basename ${file})
4476a8e1175bSopenharmony_ci
4477a8e1175bSopenharmony_ci    # The most common issue is unused variables/functions, so ensure -Wunused is set.
4478a8e1175bSopenharmony_ci    warning_flags="-Werror -Wall -Wextra -Wwrite-strings -Wpointer-arith -Wimplicit-fallthrough -Wshadow -Wvla -Wformat=2 -Wno-format-nonliteral -Wshadow -Wasm-operand-widths -Wunused"
4479a8e1175bSopenharmony_ci
4480a8e1175bSopenharmony_ci    # Extract the command generated by the Makefile to build the target file.
4481a8e1175bSopenharmony_ci    # This ensures that we have any include paths, macro definitions, etc
4482a8e1175bSopenharmony_ci    # that may be applied by make.
4483a8e1175bSopenharmony_ci    # Add -fsyntax-only as we only want a syntax check and don't need to generate a file.
4484a8e1175bSopenharmony_ci    compile_cmd="clang \$(LOCAL_CFLAGS) ${warning_flags} -fsyntax-only -c"
4485a8e1175bSopenharmony_ci
4486a8e1175bSopenharmony_ci    makefile=$(TMPDIR=. mktemp)
4487a8e1175bSopenharmony_ci    deps=""
4488a8e1175bSopenharmony_ci
4489a8e1175bSopenharmony_ci    len=${#options[@]}
4490a8e1175bSopenharmony_ci    source_file=${file%.o}.c
4491a8e1175bSopenharmony_ci
4492a8e1175bSopenharmony_ci    targets=0
4493a8e1175bSopenharmony_ci    echo 'include Makefile' >${makefile}
4494a8e1175bSopenharmony_ci
4495a8e1175bSopenharmony_ci    for ((i = 0; i < $((2**${len})); i++)); do
4496a8e1175bSopenharmony_ci        # generate each of 2^n combinations of options
4497a8e1175bSopenharmony_ci        # each bit of $i is used to determine if options[i] will be set or not
4498a8e1175bSopenharmony_ci        target="t"
4499a8e1175bSopenharmony_ci        clang_args=""
4500a8e1175bSopenharmony_ci        for ((j = 0; j < ${len}; j++)); do
4501a8e1175bSopenharmony_ci            if (((i >> j) & 1)); then
4502a8e1175bSopenharmony_ci                opt=-D${options[$j]}
4503a8e1175bSopenharmony_ci                clang_args="${clang_args} ${opt}"
4504a8e1175bSopenharmony_ci                target="${target}${opt}"
4505a8e1175bSopenharmony_ci            fi
4506a8e1175bSopenharmony_ci        done
4507a8e1175bSopenharmony_ci
4508a8e1175bSopenharmony_ci        # if combination is not known to be invalid, add it to the makefile
4509a8e1175bSopenharmony_ci        if [[ -z $validate_options ]] || $validate_options "${clang_args}"; then
4510a8e1175bSopenharmony_ci            cmd="${compile_cmd} ${clang_args}"
4511a8e1175bSopenharmony_ci            echo "${target}: ${source_file}; $cmd ${source_file}" >> ${makefile}
4512a8e1175bSopenharmony_ci
4513a8e1175bSopenharmony_ci            deps="${deps} ${target}"
4514a8e1175bSopenharmony_ci            ((++targets))
4515a8e1175bSopenharmony_ci        fi
4516a8e1175bSopenharmony_ci    done
4517a8e1175bSopenharmony_ci
4518a8e1175bSopenharmony_ci    echo "build_test_config_combos: ${deps}" >> ${makefile}
4519a8e1175bSopenharmony_ci
4520a8e1175bSopenharmony_ci    # execute all of the commands via Make (probably in parallel)
4521a8e1175bSopenharmony_ci    make -s -f ${makefile} build_test_config_combos
4522a8e1175bSopenharmony_ci    echo "$targets targets checked"
4523a8e1175bSopenharmony_ci
4524a8e1175bSopenharmony_ci    # clean up the temporary makefile
4525a8e1175bSopenharmony_ci    rm ${makefile}
4526a8e1175bSopenharmony_ci}
4527a8e1175bSopenharmony_ci
4528a8e1175bSopenharmony_civalidate_aes_config_variations() {
4529a8e1175bSopenharmony_ci    if [[ "$1" == *"MBEDTLS_AES_USE_HARDWARE_ONLY"* ]]; then
4530a8e1175bSopenharmony_ci        if [[ "$1" == *"MBEDTLS_PADLOCK_C"* ]]; then
4531a8e1175bSopenharmony_ci            return 1
4532a8e1175bSopenharmony_ci        fi
4533a8e1175bSopenharmony_ci        if [[ !(("$HOSTTYPE" == "aarch64" && "$1" != *"MBEDTLS_AESCE_C"*) || \
4534a8e1175bSopenharmony_ci                ("$HOSTTYPE" == "x86_64"  && "$1" != *"MBEDTLS_AESNI_C"*)) ]]; then
4535a8e1175bSopenharmony_ci            return 1
4536a8e1175bSopenharmony_ci        fi
4537a8e1175bSopenharmony_ci    fi
4538a8e1175bSopenharmony_ci    return 0
4539a8e1175bSopenharmony_ci}
4540a8e1175bSopenharmony_ci
4541a8e1175bSopenharmony_cicomponent_build_aes_variations() {
4542a8e1175bSopenharmony_ci    # 18s - around 90ms per clang invocation on M1 Pro
4543a8e1175bSopenharmony_ci    #
4544a8e1175bSopenharmony_ci    # aes.o has many #if defined(...) guards that intersect in complex ways.
4545a8e1175bSopenharmony_ci    # Test that all the combinations build cleanly.
4546a8e1175bSopenharmony_ci
4547a8e1175bSopenharmony_ci    MBEDTLS_ROOT_DIR="$PWD"
4548a8e1175bSopenharmony_ci    msg "build: aes.o for all combinations of relevant config options"
4549a8e1175bSopenharmony_ci
4550a8e1175bSopenharmony_ci    build_test_config_combos library/aes.o validate_aes_config_variations \
4551a8e1175bSopenharmony_ci        "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
4552a8e1175bSopenharmony_ci        "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
4553a8e1175bSopenharmony_ci        "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
4554a8e1175bSopenharmony_ci        "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
4555a8e1175bSopenharmony_ci
4556a8e1175bSopenharmony_ci    cd "$MBEDTLS_ROOT_DIR"
4557a8e1175bSopenharmony_ci    msg "build: aes.o for all combinations of relevant config options + BLOCK_CIPHER_NO_DECRYPT"
4558a8e1175bSopenharmony_ci
4559a8e1175bSopenharmony_ci    # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT is incompatible with ECB in PSA, CBC/XTS/NIST_KW/DES,
4560a8e1175bSopenharmony_ci    # manually set or unset those configurations to check
4561a8e1175bSopenharmony_ci    # MBEDTLS_BLOCK_CIPHER_NO_DECRYPT with various combinations in aes.o.
4562a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
4563a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
4564a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
4565a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_DES_C
4566a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_NIST_KW_C
4567a8e1175bSopenharmony_ci    build_test_config_combos library/aes.o validate_aes_config_variations \
4568a8e1175bSopenharmony_ci        "MBEDTLS_AES_SETKEY_ENC_ALT" "MBEDTLS_AES_DECRYPT_ALT" \
4569a8e1175bSopenharmony_ci        "MBEDTLS_AES_ROM_TABLES" "MBEDTLS_AES_ENCRYPT_ALT" "MBEDTLS_AES_SETKEY_DEC_ALT" \
4570a8e1175bSopenharmony_ci        "MBEDTLS_AES_FEWER_TABLES" "MBEDTLS_PADLOCK_C" "MBEDTLS_AES_USE_HARDWARE_ONLY" \
4571a8e1175bSopenharmony_ci        "MBEDTLS_AESNI_C" "MBEDTLS_AESCE_C" "MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH"
4572a8e1175bSopenharmony_ci}
4573a8e1175bSopenharmony_ci
4574a8e1175bSopenharmony_cicomponent_test_no_platform () {
4575a8e1175bSopenharmony_ci    # Full configuration build, without platform support, file IO and net sockets.
4576a8e1175bSopenharmony_ci    # This should catch missing mbedtls_printf definitions, and by disabling file
4577a8e1175bSopenharmony_ci    # IO, it should catch missing '#include <stdio.h>'
4578a8e1175bSopenharmony_ci    msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s
4579a8e1175bSopenharmony_ci    scripts/config.py full_no_platform
4580a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PLATFORM_C
4581a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_NET_C
4582a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_FS_IO
4583a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C
4584a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C
4585a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C
4586a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
4587a8e1175bSopenharmony_ci    # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19,
4588a8e1175bSopenharmony_ci    # to re-enable platform integration features otherwise disabled in C99 builds
4589a8e1175bSopenharmony_ci    make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -Os -D_DEFAULT_SOURCE' lib programs
4590a8e1175bSopenharmony_ci    make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' test
4591a8e1175bSopenharmony_ci}
4592a8e1175bSopenharmony_ci
4593a8e1175bSopenharmony_cicomponent_build_no_std_function () {
4594a8e1175bSopenharmony_ci    # catch compile bugs in _uninit functions
4595a8e1175bSopenharmony_ci    msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s
4596a8e1175bSopenharmony_ci    scripts/config.py full
4597a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
4598a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED
4599a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PLATFORM_NV_SEED_ALT
4600a8e1175bSopenharmony_ci    CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Check .
4601a8e1175bSopenharmony_ci    make
4602a8e1175bSopenharmony_ci}
4603a8e1175bSopenharmony_ci
4604a8e1175bSopenharmony_cicomponent_build_no_ssl_srv () {
4605a8e1175bSopenharmony_ci    msg "build: full config except SSL server, make, gcc" # ~ 30s
4606a8e1175bSopenharmony_ci    scripts/config.py full
4607a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_SRV_C
4608a8e1175bSopenharmony_ci    make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
4609a8e1175bSopenharmony_ci}
4610a8e1175bSopenharmony_ci
4611a8e1175bSopenharmony_cicomponent_build_no_ssl_cli () {
4612a8e1175bSopenharmony_ci    msg "build: full config except SSL client, make, gcc" # ~ 30s
4613a8e1175bSopenharmony_ci    scripts/config.py full
4614a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_CLI_C
4615a8e1175bSopenharmony_ci    make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1'
4616a8e1175bSopenharmony_ci}
4617a8e1175bSopenharmony_ci
4618a8e1175bSopenharmony_cicomponent_build_no_sockets () {
4619a8e1175bSopenharmony_ci    # Note, C99 compliance can also be tested with the sockets support disabled,
4620a8e1175bSopenharmony_ci    # as that requires a POSIX platform (which isn't the same as C99).
4621a8e1175bSopenharmony_ci    msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s
4622a8e1175bSopenharmony_ci    scripts/config.py full
4623a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc.
4624a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux
4625a8e1175bSopenharmony_ci    make CC=gcc CFLAGS='-Werror -Wall -Wextra -O1 -std=c99 -pedantic' lib
4626a8e1175bSopenharmony_ci}
4627a8e1175bSopenharmony_ci
4628a8e1175bSopenharmony_cicomponent_test_memory_buffer_allocator_backtrace () {
4629a8e1175bSopenharmony_ci    msg "build: default config with memory buffer allocator and backtrace enabled"
4630a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4631a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4632a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_MEMORY_BACKTRACE
4633a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_MEMORY_DEBUG
4634a8e1175bSopenharmony_ci    cmake -DCMAKE_BUILD_TYPE:String=Release .
4635a8e1175bSopenharmony_ci    make
4636a8e1175bSopenharmony_ci
4637a8e1175bSopenharmony_ci    msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE"
4638a8e1175bSopenharmony_ci    make test
4639a8e1175bSopenharmony_ci}
4640a8e1175bSopenharmony_ci
4641a8e1175bSopenharmony_cicomponent_test_memory_buffer_allocator () {
4642a8e1175bSopenharmony_ci    msg "build: default config with memory buffer allocator"
4643a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4644a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4645a8e1175bSopenharmony_ci    cmake -DCMAKE_BUILD_TYPE:String=Release .
4646a8e1175bSopenharmony_ci    make
4647a8e1175bSopenharmony_ci
4648a8e1175bSopenharmony_ci    msg "test: MBEDTLS_MEMORY_BUFFER_ALLOC_C"
4649a8e1175bSopenharmony_ci    make test
4650a8e1175bSopenharmony_ci
4651a8e1175bSopenharmony_ci    msg "test: ssl-opt.sh, MBEDTLS_MEMORY_BUFFER_ALLOC_C"
4652a8e1175bSopenharmony_ci    # MBEDTLS_MEMORY_BUFFER_ALLOC is slow. Skip tests that tend to time out.
4653a8e1175bSopenharmony_ci    tests/ssl-opt.sh -e '^DTLS proxy'
4654a8e1175bSopenharmony_ci}
4655a8e1175bSopenharmony_ci
4656a8e1175bSopenharmony_cicomponent_test_no_max_fragment_length () {
4657a8e1175bSopenharmony_ci    # Run max fragment length tests with MFL disabled
4658a8e1175bSopenharmony_ci    msg "build: default config except MFL extension (ASan build)" # ~ 30s
4659a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4660a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
4661a8e1175bSopenharmony_ci    make
4662a8e1175bSopenharmony_ci
4663a8e1175bSopenharmony_ci    msg "test: ssl-opt.sh, MFL-related tests"
4664a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f "Max fragment length"
4665a8e1175bSopenharmony_ci}
4666a8e1175bSopenharmony_ci
4667a8e1175bSopenharmony_cicomponent_test_asan_remove_peer_certificate () {
4668a8e1175bSopenharmony_ci    msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
4669a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
4670a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
4671a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
4672a8e1175bSopenharmony_ci    make
4673a8e1175bSopenharmony_ci
4674a8e1175bSopenharmony_ci    msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
4675a8e1175bSopenharmony_ci    make test
4676a8e1175bSopenharmony_ci
4677a8e1175bSopenharmony_ci    msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
4678a8e1175bSopenharmony_ci    tests/ssl-opt.sh
4679a8e1175bSopenharmony_ci
4680a8e1175bSopenharmony_ci    msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
4681a8e1175bSopenharmony_ci    tests/compat.sh
4682a8e1175bSopenharmony_ci
4683a8e1175bSopenharmony_ci    msg "test: context-info.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
4684a8e1175bSopenharmony_ci    tests/context-info.sh
4685a8e1175bSopenharmony_ci}
4686a8e1175bSopenharmony_ci
4687a8e1175bSopenharmony_cicomponent_test_no_max_fragment_length_small_ssl_out_content_len () {
4688a8e1175bSopenharmony_ci    msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
4689a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4690a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_IN_CONTENT_LEN 16384
4691a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_OUT_CONTENT_LEN 4096
4692a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
4693a8e1175bSopenharmony_ci    make
4694a8e1175bSopenharmony_ci
4695a8e1175bSopenharmony_ci    msg "test: MFL tests (disabled MFL extension case) & large packet tests"
4696a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f "Max fragment length\|Large buffer"
4697a8e1175bSopenharmony_ci
4698a8e1175bSopenharmony_ci    msg "test: context-info.sh (disabled MFL extension case)"
4699a8e1175bSopenharmony_ci    tests/context-info.sh
4700a8e1175bSopenharmony_ci}
4701a8e1175bSopenharmony_ci
4702a8e1175bSopenharmony_cicomponent_test_variable_ssl_in_out_buffer_len () {
4703a8e1175bSopenharmony_ci    msg "build: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled (ASan build)"
4704a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
4705a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
4706a8e1175bSopenharmony_ci    make
4707a8e1175bSopenharmony_ci
4708a8e1175bSopenharmony_ci    msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
4709a8e1175bSopenharmony_ci    make test
4710a8e1175bSopenharmony_ci
4711a8e1175bSopenharmony_ci    msg "test: ssl-opt.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
4712a8e1175bSopenharmony_ci    tests/ssl-opt.sh
4713a8e1175bSopenharmony_ci
4714a8e1175bSopenharmony_ci    msg "test: compat.sh, MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH enabled"
4715a8e1175bSopenharmony_ci    tests/compat.sh
4716a8e1175bSopenharmony_ci}
4717a8e1175bSopenharmony_ci
4718a8e1175bSopenharmony_cicomponent_test_dtls_cid_legacy () {
4719a8e1175bSopenharmony_ci    msg "build: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled (ASan build)"
4720a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 1
4721a8e1175bSopenharmony_ci
4722a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
4723a8e1175bSopenharmony_ci    make
4724a8e1175bSopenharmony_ci
4725a8e1175bSopenharmony_ci    msg "test: MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy)"
4726a8e1175bSopenharmony_ci    make test
4727a8e1175bSopenharmony_ci
4728a8e1175bSopenharmony_ci    msg "test: ssl-opt.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
4729a8e1175bSopenharmony_ci    tests/ssl-opt.sh
4730a8e1175bSopenharmony_ci
4731a8e1175bSopenharmony_ci    msg "test: compat.sh, MBEDTLS_SSL_DTLS_CONNECTION_ID (legacy) enabled"
4732a8e1175bSopenharmony_ci    tests/compat.sh
4733a8e1175bSopenharmony_ci}
4734a8e1175bSopenharmony_ci
4735a8e1175bSopenharmony_cicomponent_test_ssl_alloc_buffer_and_mfl () {
4736a8e1175bSopenharmony_ci    msg "build: default config with memory buffer allocator and MFL extension"
4737a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_MEMORY_BUFFER_ALLOC_C
4738a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4739a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_MEMORY_DEBUG
4740a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
4741a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
4742a8e1175bSopenharmony_ci    cmake -DCMAKE_BUILD_TYPE:String=Release .
4743a8e1175bSopenharmony_ci    make
4744a8e1175bSopenharmony_ci
4745a8e1175bSopenharmony_ci    msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
4746a8e1175bSopenharmony_ci    make test
4747a8e1175bSopenharmony_ci
4748a8e1175bSopenharmony_ci    msg "test: MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH, MBEDTLS_MEMORY_BUFFER_ALLOC_C, MBEDTLS_MEMORY_DEBUG and MBEDTLS_SSL_MAX_FRAGMENT_LENGTH"
4749a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f "Handshake memory usage"
4750a8e1175bSopenharmony_ci}
4751a8e1175bSopenharmony_ci
4752a8e1175bSopenharmony_cicomponent_test_when_no_ciphersuites_have_mac () {
4753a8e1175bSopenharmony_ci    msg "build: when no ciphersuites have MAC"
4754a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_NULL_CIPHER
4755a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
4756a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CMAC_C
4757a8e1175bSopenharmony_ci    make
4758a8e1175bSopenharmony_ci
4759a8e1175bSopenharmony_ci    msg "test: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
4760a8e1175bSopenharmony_ci    make test
4761a8e1175bSopenharmony_ci
4762a8e1175bSopenharmony_ci    msg "test ssl-opt.sh: !MBEDTLS_SSL_SOME_MODES_USE_MAC"
4763a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f 'Default\|EtM' -e 'without EtM'
4764a8e1175bSopenharmony_ci}
4765a8e1175bSopenharmony_ci
4766a8e1175bSopenharmony_cicomponent_test_no_date_time () {
4767a8e1175bSopenharmony_ci    msg "build: default config without MBEDTLS_HAVE_TIME_DATE"
4768a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_HAVE_TIME_DATE
4769a8e1175bSopenharmony_ci    cmake -D CMAKE_BUILD_TYPE:String=Check .
4770a8e1175bSopenharmony_ci    make
4771a8e1175bSopenharmony_ci
4772a8e1175bSopenharmony_ci    msg "test: !MBEDTLS_HAVE_TIME_DATE - main suites"
4773a8e1175bSopenharmony_ci    make test
4774a8e1175bSopenharmony_ci}
4775a8e1175bSopenharmony_ci
4776a8e1175bSopenharmony_cicomponent_test_platform_calloc_macro () {
4777a8e1175bSopenharmony_ci    msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
4778a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PLATFORM_MEMORY
4779a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PLATFORM_CALLOC_MACRO calloc
4780a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PLATFORM_FREE_MACRO   free
4781a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
4782a8e1175bSopenharmony_ci    make
4783a8e1175bSopenharmony_ci
4784a8e1175bSopenharmony_ci    msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)"
4785a8e1175bSopenharmony_ci    make test
4786a8e1175bSopenharmony_ci}
4787a8e1175bSopenharmony_ci
4788a8e1175bSopenharmony_cicomponent_test_malloc_0_null () {
4789a8e1175bSopenharmony_ci    msg "build: malloc(0) returns NULL (ASan+UBSan build)"
4790a8e1175bSopenharmony_ci    scripts/config.py full
4791a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"$PWD/tests/configs/user-config-malloc-0-null.h\"' $ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS"
4792a8e1175bSopenharmony_ci
4793a8e1175bSopenharmony_ci    msg "test: malloc(0) returns NULL (ASan+UBSan build)"
4794a8e1175bSopenharmony_ci    make test
4795a8e1175bSopenharmony_ci
4796a8e1175bSopenharmony_ci    msg "selftest: malloc(0) returns NULL (ASan+UBSan build)"
4797a8e1175bSopenharmony_ci    # Just the calloc selftest. "make test" ran the others as part of the
4798a8e1175bSopenharmony_ci    # test suites.
4799a8e1175bSopenharmony_ci    programs/test/selftest calloc
4800a8e1175bSopenharmony_ci
4801a8e1175bSopenharmony_ci    msg "test ssl-opt.sh: malloc(0) returns NULL (ASan+UBSan build)"
4802a8e1175bSopenharmony_ci    # Run a subset of the tests. The choice is a balance between coverage
4803a8e1175bSopenharmony_ci    # and time (including time indirectly wasted due to flaky tests).
4804a8e1175bSopenharmony_ci    # The current choice is to skip tests whose description includes
4805a8e1175bSopenharmony_ci    # "proxy", which is an approximation of skipping tests that use the
4806a8e1175bSopenharmony_ci    # UDP proxy, which tend to be slower and flakier.
4807a8e1175bSopenharmony_ci    tests/ssl-opt.sh -e 'proxy'
4808a8e1175bSopenharmony_ci}
4809a8e1175bSopenharmony_ci
4810a8e1175bSopenharmony_cisupport_test_aesni() {
4811a8e1175bSopenharmony_ci    # Check that gcc targets x86_64 (we can build AESNI), and check for
4812a8e1175bSopenharmony_ci    # AESNI support on the host (we can run AESNI).
4813a8e1175bSopenharmony_ci    #
4814a8e1175bSopenharmony_ci    # The name of this function is possibly slightly misleading, but needs to align
4815a8e1175bSopenharmony_ci    # with the name of the corresponding test, component_test_aesni.
4816a8e1175bSopenharmony_ci    #
4817a8e1175bSopenharmony_ci    # In principle 32-bit x86 can support AESNI, but our implementation does not
4818a8e1175bSopenharmony_ci    # support 32-bit x86, so we check for x86-64.
4819a8e1175bSopenharmony_ci    # We can only grep /proc/cpuinfo on Linux, so this also checks for Linux
4820a8e1175bSopenharmony_ci    (gcc -v 2>&1 | grep Target | grep -q x86_64) &&
4821a8e1175bSopenharmony_ci        [[ "$HOSTTYPE" == "x86_64" && "$OSTYPE" == "linux-gnu" ]] &&
4822a8e1175bSopenharmony_ci        (lscpu | grep -qw aes)
4823a8e1175bSopenharmony_ci}
4824a8e1175bSopenharmony_ci
4825a8e1175bSopenharmony_cicomponent_test_aesni () { # ~ 60s
4826a8e1175bSopenharmony_ci    # This tests the two AESNI implementations (intrinsics and assembly), and also the plain C
4827a8e1175bSopenharmony_ci    # fallback. It also tests the logic that is used to select which implementation(s) to build.
4828a8e1175bSopenharmony_ci    #
4829a8e1175bSopenharmony_ci    # This test does not require the host to have support for AESNI (if it doesn't, the run-time
4830a8e1175bSopenharmony_ci    # AESNI detection will fallback to the plain C implementation, so the tests will instead
4831a8e1175bSopenharmony_ci    # exercise the plain C impl).
4832a8e1175bSopenharmony_ci
4833a8e1175bSopenharmony_ci    msg "build: default config with different AES implementations"
4834a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AESNI_C
4835a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4836a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_HAVE_ASM
4837a8e1175bSopenharmony_ci
4838a8e1175bSopenharmony_ci    # test the intrinsics implementation
4839a8e1175bSopenharmony_ci    msg "AES tests, test intrinsics"
4840a8e1175bSopenharmony_ci    make clean
4841a8e1175bSopenharmony_ci    make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
4842a8e1175bSopenharmony_ci    # check that we built intrinsics - this should be used by default when supported by the compiler
4843a8e1175bSopenharmony_ci    ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
4844a8e1175bSopenharmony_ci
4845a8e1175bSopenharmony_ci    # test the asm implementation
4846a8e1175bSopenharmony_ci    msg "AES tests, test assembly"
4847a8e1175bSopenharmony_ci    make clean
4848a8e1175bSopenharmony_ci    make CC=gcc CFLAGS='-Werror -Wall -Wextra -mno-pclmul -mno-sse2 -mno-aes'
4849a8e1175bSopenharmony_ci    # check that we built assembly - this should be built if the compiler does not support intrinsics
4850a8e1175bSopenharmony_ci    ./programs/test/selftest aes | grep "AESNI code" | grep -q "assembly"
4851a8e1175bSopenharmony_ci
4852a8e1175bSopenharmony_ci    # test the plain C implementation
4853a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESNI_C
4854a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4855a8e1175bSopenharmony_ci    msg "AES tests, plain C"
4856a8e1175bSopenharmony_ci    make clean
4857a8e1175bSopenharmony_ci    make CC=gcc CFLAGS='-O2 -Werror'
4858a8e1175bSopenharmony_ci    # check that there is no AESNI code present
4859a8e1175bSopenharmony_ci    ./programs/test/selftest aes | not grep -q "AESNI code"
4860a8e1175bSopenharmony_ci    not grep -q "AES note: using AESNI" ./programs/test/selftest
4861a8e1175bSopenharmony_ci    grep -q "AES note: built-in implementation." ./programs/test/selftest
4862a8e1175bSopenharmony_ci
4863a8e1175bSopenharmony_ci    # test the intrinsics implementation
4864a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AESNI_C
4865a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4866a8e1175bSopenharmony_ci    msg "AES tests, test AESNI only"
4867a8e1175bSopenharmony_ci    make clean
4868a8e1175bSopenharmony_ci    make CC=gcc CFLAGS='-Werror -Wall -Wextra -mpclmul -msse2 -maes'
4869a8e1175bSopenharmony_ci    ./programs/test/selftest aes | grep -q "AES note: using AESNI"
4870a8e1175bSopenharmony_ci    ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
4871a8e1175bSopenharmony_ci    grep -q "AES note: using AESNI" ./programs/test/selftest
4872a8e1175bSopenharmony_ci    not grep -q "AES note: built-in implementation." ./programs/test/selftest
4873a8e1175bSopenharmony_ci}
4874a8e1175bSopenharmony_ci
4875a8e1175bSopenharmony_cicomponent_test_sha3_variations() {
4876a8e1175bSopenharmony_ci    msg "sha3 loop unroll variations"
4877a8e1175bSopenharmony_ci
4878a8e1175bSopenharmony_ci    # define minimal config sufficient to test SHA3
4879a8e1175bSopenharmony_ci    cat > include/mbedtls/mbedtls_config.h << END
4880a8e1175bSopenharmony_ci        #define MBEDTLS_SELF_TEST
4881a8e1175bSopenharmony_ci        #define MBEDTLS_SHA3_C
4882a8e1175bSopenharmony_ciEND
4883a8e1175bSopenharmony_ci
4884a8e1175bSopenharmony_ci    msg "all loops unrolled"
4885a8e1175bSopenharmony_ci    make clean
4886a8e1175bSopenharmony_ci    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"
4887a8e1175bSopenharmony_ci    ./tests/test_suite_shax
4888a8e1175bSopenharmony_ci
4889a8e1175bSopenharmony_ci    msg "all loops rolled up"
4890a8e1175bSopenharmony_ci    make clean
4891a8e1175bSopenharmony_ci    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"
4892a8e1175bSopenharmony_ci    ./tests/test_suite_shax
4893a8e1175bSopenharmony_ci}
4894a8e1175bSopenharmony_ci
4895a8e1175bSopenharmony_cisupport_test_aesni_m32() {
4896a8e1175bSopenharmony_ci    support_test_m32_no_asm && (lscpu | grep -qw aes)
4897a8e1175bSopenharmony_ci}
4898a8e1175bSopenharmony_ci
4899a8e1175bSopenharmony_cicomponent_test_aesni_m32 () { # ~ 60s
4900a8e1175bSopenharmony_ci    # This tests are duplicated from component_test_aesni for i386 target
4901a8e1175bSopenharmony_ci    #
4902a8e1175bSopenharmony_ci    # AESNI intrinsic code supports i386 and assembly code does not support it.
4903a8e1175bSopenharmony_ci
4904a8e1175bSopenharmony_ci    msg "build: default config with different AES implementations"
4905a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AESNI_C
4906a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PADLOCK_C
4907a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4908a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_HAVE_ASM
4909a8e1175bSopenharmony_ci
4910a8e1175bSopenharmony_ci    # test the intrinsics implementation with gcc
4911a8e1175bSopenharmony_ci    msg "AES tests, test intrinsics (gcc)"
4912a8e1175bSopenharmony_ci    make clean
4913a8e1175bSopenharmony_ci    make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra' LDFLAGS='-m32'
4914a8e1175bSopenharmony_ci    # check that we built intrinsics - this should be used by default when supported by the compiler
4915a8e1175bSopenharmony_ci    ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
4916a8e1175bSopenharmony_ci    grep -q "AES note: using AESNI" ./programs/test/selftest
4917a8e1175bSopenharmony_ci    grep -q "AES note: built-in implementation." ./programs/test/selftest
4918a8e1175bSopenharmony_ci    grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4919a8e1175bSopenharmony_ci    grep -q mbedtls_aesni_has_support ./programs/test/selftest
4920a8e1175bSopenharmony_ci
4921a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AESNI_C
4922a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PADLOCK_C
4923a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4924a8e1175bSopenharmony_ci    msg "AES tests, test AESNI only"
4925a8e1175bSopenharmony_ci    make clean
4926a8e1175bSopenharmony_ci    make CC=gcc CFLAGS='-m32 -Werror -Wall -Wextra -mpclmul -msse2 -maes' LDFLAGS='-m32'
4927a8e1175bSopenharmony_ci    ./programs/test/selftest aes | grep -q "AES note: using AESNI"
4928a8e1175bSopenharmony_ci    ./programs/test/selftest aes | not grep -q "AES note: built-in implementation."
4929a8e1175bSopenharmony_ci    grep -q "AES note: using AESNI" ./programs/test/selftest
4930a8e1175bSopenharmony_ci    not grep -q "AES note: built-in implementation." ./programs/test/selftest
4931a8e1175bSopenharmony_ci    not grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4932a8e1175bSopenharmony_ci    not grep -q mbedtls_aesni_has_support ./programs/test/selftest
4933a8e1175bSopenharmony_ci}
4934a8e1175bSopenharmony_ci
4935a8e1175bSopenharmony_cisupport_test_aesni_m32_clang() {
4936a8e1175bSopenharmony_ci    # clang >= 4 is required to build with target attributes
4937a8e1175bSopenharmony_ci    support_test_aesni_m32 && [[ $(clang_version) -ge 4 ]]
4938a8e1175bSopenharmony_ci}
4939a8e1175bSopenharmony_ci
4940a8e1175bSopenharmony_cicomponent_test_aesni_m32_clang() {
4941a8e1175bSopenharmony_ci
4942a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AESNI_C
4943a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PADLOCK_C
4944a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4945a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_HAVE_ASM
4946a8e1175bSopenharmony_ci
4947a8e1175bSopenharmony_ci    # test the intrinsics implementation with clang
4948a8e1175bSopenharmony_ci    msg "AES tests, test intrinsics (clang)"
4949a8e1175bSopenharmony_ci    make clean
4950a8e1175bSopenharmony_ci    make CC=clang CFLAGS='-m32 -Werror -Wall -Wextra' LDFLAGS='-m32'
4951a8e1175bSopenharmony_ci    # check that we built intrinsics - this should be used by default when supported by the compiler
4952a8e1175bSopenharmony_ci    ./programs/test/selftest aes | grep "AESNI code" | grep -q "intrinsics"
4953a8e1175bSopenharmony_ci    grep -q "AES note: using AESNI" ./programs/test/selftest
4954a8e1175bSopenharmony_ci    grep -q "AES note: built-in implementation." ./programs/test/selftest
4955a8e1175bSopenharmony_ci    grep -q "AES note: using VIA Padlock" ./programs/test/selftest
4956a8e1175bSopenharmony_ci    grep -q mbedtls_aesni_has_support ./programs/test/selftest
4957a8e1175bSopenharmony_ci}
4958a8e1175bSopenharmony_ci
4959a8e1175bSopenharmony_ci# For timebeing, no aarch64 gcc available in CI and no arm64 CI node.
4960a8e1175bSopenharmony_cicomponent_build_aes_aesce_armcc () {
4961a8e1175bSopenharmony_ci    msg "Build: AESCE test on arm64 platform without plain C."
4962a8e1175bSopenharmony_ci    scripts/config.py baremetal
4963a8e1175bSopenharmony_ci
4964a8e1175bSopenharmony_ci    # armc[56] don't support SHA-512 intrinsics
4965a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
4966a8e1175bSopenharmony_ci
4967a8e1175bSopenharmony_ci    # Stop armclang warning about feature detection for A64_CRYPTO.
4968a8e1175bSopenharmony_ci    # With this enabled, the library does build correctly under armclang,
4969a8e1175bSopenharmony_ci    # but in baremetal builds (as tested here), feature detection is
4970a8e1175bSopenharmony_ci    # unavailable, and the user is notified via a #warning. So enabling
4971a8e1175bSopenharmony_ci    # this feature would prevent us from building with -Werror on
4972a8e1175bSopenharmony_ci    # armclang. Tracked in #7198.
4973a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
4974a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_HAVE_ASM
4975a8e1175bSopenharmony_ci
4976a8e1175bSopenharmony_ci    msg "AESCE, build with default configuration."
4977a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AESCE_C
4978a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
4979a8e1175bSopenharmony_ci    armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
4980a8e1175bSopenharmony_ci
4981a8e1175bSopenharmony_ci    msg "AESCE, build AESCE only"
4982a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AESCE_C
4983a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4984a8e1175bSopenharmony_ci    armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto"
4985a8e1175bSopenharmony_ci}
4986a8e1175bSopenharmony_ci
4987a8e1175bSopenharmony_cisupport_build_aes_armce() {
4988a8e1175bSopenharmony_ci    # clang >= 11 is required to build with AES extensions
4989a8e1175bSopenharmony_ci    [[ $(clang_version) -ge 11 ]]
4990a8e1175bSopenharmony_ci}
4991a8e1175bSopenharmony_ci
4992a8e1175bSopenharmony_cicomponent_build_aes_armce () {
4993a8e1175bSopenharmony_ci    # Test variations of AES with Armv8 crypto extensions
4994a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AESCE_C
4995a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
4996a8e1175bSopenharmony_ci
4997a8e1175bSopenharmony_ci    msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, aarch64"
4998a8e1175bSopenharmony_ci    make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
4999a8e1175bSopenharmony_ci
5000a8e1175bSopenharmony_ci    msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, arm"
5001a8e1175bSopenharmony_ci    make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
5002a8e1175bSopenharmony_ci
5003a8e1175bSopenharmony_ci    msg "MBEDTLS_AES_USE_HARDWARE_ONLY, clang, thumb"
5004a8e1175bSopenharmony_ci    make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
5005a8e1175bSopenharmony_ci
5006a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
5007a8e1175bSopenharmony_ci
5008a8e1175bSopenharmony_ci    msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, aarch64"
5009a8e1175bSopenharmony_ci    make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a+crypto"
5010a8e1175bSopenharmony_ci
5011a8e1175bSopenharmony_ci    msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, arm"
5012a8e1175bSopenharmony_ci    make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
5013a8e1175bSopenharmony_ci
5014a8e1175bSopenharmony_ci    msg "no MBEDTLS_AES_USE_HARDWARE_ONLY, clang, thumb"
5015a8e1175bSopenharmony_ci    make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
5016a8e1175bSopenharmony_ci
5017a8e1175bSopenharmony_ci    # test for presence of AES instructions
5018a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AES_USE_HARDWARE_ONLY
5019a8e1175bSopenharmony_ci    msg "clang, test A32 crypto instructions built"
5020a8e1175bSopenharmony_ci    make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
5021a8e1175bSopenharmony_ci    grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
5022a8e1175bSopenharmony_ci    msg "clang, test T32 crypto instructions built"
5023a8e1175bSopenharmony_ci    make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
5024a8e1175bSopenharmony_ci    grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
5025a8e1175bSopenharmony_ci    msg "clang, test aarch64 crypto instructions built"
5026a8e1175bSopenharmony_ci    make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
5027a8e1175bSopenharmony_ci    grep -E 'aes[a-z]+\s*[qv]' library/aesce.o
5028a8e1175bSopenharmony_ci
5029a8e1175bSopenharmony_ci    # test for absence of AES instructions
5030a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
5031a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESCE_C
5032a8e1175bSopenharmony_ci    msg "clang, test A32 crypto instructions not built"
5033a8e1175bSopenharmony_ci    make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
5034a8e1175bSopenharmony_ci    not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
5035a8e1175bSopenharmony_ci    msg "clang, test T32 crypto instructions not built"
5036a8e1175bSopenharmony_ci    make -B library/aesce.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
5037a8e1175bSopenharmony_ci    not grep -E 'aes[0-9a-z]+.[0-9]\s*[qv]' library/aesce.o
5038a8e1175bSopenharmony_ci    msg "clang, test aarch64 crypto instructions not built"
5039a8e1175bSopenharmony_ci    make -B library/aesce.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
5040a8e1175bSopenharmony_ci    not grep -E 'aes[a-z]+\s*[qv]' library/aesce.o
5041a8e1175bSopenharmony_ci}
5042a8e1175bSopenharmony_ci
5043a8e1175bSopenharmony_cisupport_build_sha_armce() {
5044a8e1175bSopenharmony_ci    # clang >= 4 is required to build with SHA extensions
5045a8e1175bSopenharmony_ci    [[ $(clang_version) -ge 4 ]]
5046a8e1175bSopenharmony_ci}
5047a8e1175bSopenharmony_ci
5048a8e1175bSopenharmony_cicomponent_build_sha_armce () {
5049a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
5050a8e1175bSopenharmony_ci
5051a8e1175bSopenharmony_ci
5052a8e1175bSopenharmony_ci    # Test variations of SHA256 Armv8 crypto extensions
5053a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
5054a8e1175bSopenharmony_ci        msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, aarch64"
5055a8e1175bSopenharmony_ci        make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
5056a8e1175bSopenharmony_ci        msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY clang, arm"
5057a8e1175bSopenharmony_ci        make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm"
5058a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY
5059a8e1175bSopenharmony_ci
5060a8e1175bSopenharmony_ci
5061a8e1175bSopenharmony_ci    # test the deprecated form of the config option
5062a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
5063a8e1175bSopenharmony_ci        msg "MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY clang, thumb"
5064a8e1175bSopenharmony_ci        make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
5065a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY
5066a8e1175bSopenharmony_ci
5067a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
5068a8e1175bSopenharmony_ci        msg "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT clang, aarch64"
5069a8e1175bSopenharmony_ci        make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a"
5070a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
5071a8e1175bSopenharmony_ci
5072a8e1175bSopenharmony_ci
5073a8e1175bSopenharmony_ci    # test the deprecated form of the config option
5074a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
5075a8e1175bSopenharmony_ci        msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, arm"
5076a8e1175bSopenharmony_ci        make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -std=c99"
5077a8e1175bSopenharmony_ci        msg "MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT clang, thumb"
5078a8e1175bSopenharmony_ci        make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb"
5079a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
5080a8e1175bSopenharmony_ci
5081a8e1175bSopenharmony_ci
5082a8e1175bSopenharmony_ci    # examine the disassembly for presence of SHA instructions
5083a8e1175bSopenharmony_ci    for opt in MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT; do
5084a8e1175bSopenharmony_ci        scripts/config.py set ${opt}
5085a8e1175bSopenharmony_ci            msg "${opt} clang, test A32 crypto instructions built"
5086a8e1175bSopenharmony_ci            make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
5087a8e1175bSopenharmony_ci            grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
5088a8e1175bSopenharmony_ci
5089a8e1175bSopenharmony_ci            msg "${opt} clang, test T32 crypto instructions built"
5090a8e1175bSopenharmony_ci            make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
5091a8e1175bSopenharmony_ci            grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
5092a8e1175bSopenharmony_ci
5093a8e1175bSopenharmony_ci            msg "${opt} clang, test aarch64 crypto instructions built"
5094a8e1175bSopenharmony_ci            make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
5095a8e1175bSopenharmony_ci            grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.o
5096a8e1175bSopenharmony_ci        scripts/config.py unset ${opt}
5097a8e1175bSopenharmony_ci    done
5098a8e1175bSopenharmony_ci
5099a8e1175bSopenharmony_ci
5100a8e1175bSopenharmony_ci    # examine the disassembly for absence of SHA instructions
5101a8e1175bSopenharmony_ci    msg "clang, test A32 crypto instructions not built"
5102a8e1175bSopenharmony_ci    make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a72+crypto -marm -S"
5103a8e1175bSopenharmony_ci    not grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
5104a8e1175bSopenharmony_ci
5105a8e1175bSopenharmony_ci    msg "clang, test T32 crypto instructions not built"
5106a8e1175bSopenharmony_ci    make -B library/sha256.o CC=clang CFLAGS="--target=arm-linux-gnueabihf -mcpu=cortex-a32+crypto -mthumb -S"
5107a8e1175bSopenharmony_ci    not grep -E 'sha256[a-z0-9]+.32\s+[qv]' library/sha256.o
5108a8e1175bSopenharmony_ci
5109a8e1175bSopenharmony_ci    msg "clang, test aarch64 crypto instructions not built"
5110a8e1175bSopenharmony_ci    make -B library/sha256.o CC=clang CFLAGS="--target=aarch64-linux-gnu -march=armv8-a -S"
5111a8e1175bSopenharmony_ci    not grep -E 'sha256[a-z0-9]+\s+[qv]' library/sha256.o
5112a8e1175bSopenharmony_ci}
5113a8e1175bSopenharmony_ci
5114a8e1175bSopenharmony_ci# For timebeing, no VIA Padlock platform available.
5115a8e1175bSopenharmony_cicomponent_build_aes_via_padlock () {
5116a8e1175bSopenharmony_ci
5117a8e1175bSopenharmony_ci    msg "AES:VIA PadLock, build with default configuration."
5118a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESNI_C
5119a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PADLOCK_C
5120a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AES_USE_HARDWARE_ONLY
5121a8e1175bSopenharmony_ci    make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
5122a8e1175bSopenharmony_ci    grep -q mbedtls_padlock_has_support ./programs/test/selftest
5123a8e1175bSopenharmony_ci
5124a8e1175bSopenharmony_ci}
5125a8e1175bSopenharmony_ci
5126a8e1175bSopenharmony_cisupport_build_aes_via_padlock_only () {
5127a8e1175bSopenharmony_ci    ( [ "$MBEDTLS_TEST_PLATFORM" == "Linux-x86_64" ] || \
5128a8e1175bSopenharmony_ci        [ "$MBEDTLS_TEST_PLATFORM" == "Linux-amd64" ] ) && \
5129a8e1175bSopenharmony_ci    [ "`dpkg --print-foreign-architectures`" == "i386" ]
5130a8e1175bSopenharmony_ci}
5131a8e1175bSopenharmony_ci
5132a8e1175bSopenharmony_cisupport_build_aes_aesce_armcc () {
5133a8e1175bSopenharmony_ci    support_build_armcc
5134a8e1175bSopenharmony_ci}
5135a8e1175bSopenharmony_ci
5136a8e1175bSopenharmony_cicomponent_test_aes_only_128_bit_keys () {
5137a8e1175bSopenharmony_ci    msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH"
5138a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
5139a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PADLOCK_C
5140a8e1175bSopenharmony_ci
5141a8e1175bSopenharmony_ci    make CFLAGS='-O2 -Werror -Wall -Wextra'
5142a8e1175bSopenharmony_ci
5143a8e1175bSopenharmony_ci    msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH"
5144a8e1175bSopenharmony_ci    make test
5145a8e1175bSopenharmony_ci}
5146a8e1175bSopenharmony_ci
5147a8e1175bSopenharmony_cicomponent_test_no_ctr_drbg_aes_only_128_bit_keys () {
5148a8e1175bSopenharmony_ci    msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
5149a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
5150a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CTR_DRBG_C
5151a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PADLOCK_C
5152a8e1175bSopenharmony_ci
5153a8e1175bSopenharmony_ci    make CC=clang CFLAGS='-Werror -Wall -Wextra'
5154a8e1175bSopenharmony_ci
5155a8e1175bSopenharmony_ci    msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - CTR_DRBG_C"
5156a8e1175bSopenharmony_ci    make test
5157a8e1175bSopenharmony_ci}
5158a8e1175bSopenharmony_ci
5159a8e1175bSopenharmony_cicomponent_test_aes_only_128_bit_keys_have_builtins () {
5160a8e1175bSopenharmony_ci    msg "build: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
5161a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH
5162a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PADLOCK_C
5163a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESNI_C
5164a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESCE_C
5165a8e1175bSopenharmony_ci
5166a8e1175bSopenharmony_ci    make CFLAGS='-O2 -Werror -Wall -Wextra'
5167a8e1175bSopenharmony_ci
5168a8e1175bSopenharmony_ci    msg "test: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
5169a8e1175bSopenharmony_ci    make test
5170a8e1175bSopenharmony_ci
5171a8e1175bSopenharmony_ci    msg "selftest: default config + AES_ONLY_128_BIT_KEY_LENGTH - AESNI_C - AESCE_C"
5172a8e1175bSopenharmony_ci    programs/test/selftest
5173a8e1175bSopenharmony_ci}
5174a8e1175bSopenharmony_ci
5175a8e1175bSopenharmony_cicomponent_test_gcm_largetable () {
5176a8e1175bSopenharmony_ci    msg "build: default config + GCM_LARGE_TABLE - AESNI_C - AESCE_C"
5177a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_GCM_LARGE_TABLE
5178a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PADLOCK_C
5179a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESNI_C
5180a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESCE_C
5181a8e1175bSopenharmony_ci
5182a8e1175bSopenharmony_ci    make CFLAGS='-O2 -Werror -Wall -Wextra'
5183a8e1175bSopenharmony_ci
5184a8e1175bSopenharmony_ci    msg "test: default config - GCM_LARGE_TABLE - AESNI_C - AESCE_C"
5185a8e1175bSopenharmony_ci    make test
5186a8e1175bSopenharmony_ci}
5187a8e1175bSopenharmony_ci
5188a8e1175bSopenharmony_cicomponent_test_aes_fewer_tables () {
5189a8e1175bSopenharmony_ci    msg "build: default config with AES_FEWER_TABLES enabled"
5190a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AES_FEWER_TABLES
5191a8e1175bSopenharmony_ci    make CFLAGS='-O2 -Werror -Wall -Wextra'
5192a8e1175bSopenharmony_ci
5193a8e1175bSopenharmony_ci    msg "test: AES_FEWER_TABLES"
5194a8e1175bSopenharmony_ci    make test
5195a8e1175bSopenharmony_ci}
5196a8e1175bSopenharmony_ci
5197a8e1175bSopenharmony_cicomponent_test_aes_rom_tables () {
5198a8e1175bSopenharmony_ci    msg "build: default config with AES_ROM_TABLES enabled"
5199a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AES_ROM_TABLES
5200a8e1175bSopenharmony_ci    make CFLAGS='-O2 -Werror -Wall -Wextra'
5201a8e1175bSopenharmony_ci
5202a8e1175bSopenharmony_ci    msg "test: AES_ROM_TABLES"
5203a8e1175bSopenharmony_ci    make test
5204a8e1175bSopenharmony_ci}
5205a8e1175bSopenharmony_ci
5206a8e1175bSopenharmony_cicomponent_test_aes_fewer_tables_and_rom_tables () {
5207a8e1175bSopenharmony_ci    msg "build: default config with AES_ROM_TABLES and AES_FEWER_TABLES enabled"
5208a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AES_FEWER_TABLES
5209a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AES_ROM_TABLES
5210a8e1175bSopenharmony_ci    make CFLAGS='-O2 -Werror -Wall -Wextra'
5211a8e1175bSopenharmony_ci
5212a8e1175bSopenharmony_ci    msg "test: AES_FEWER_TABLES + AES_ROM_TABLES"
5213a8e1175bSopenharmony_ci    make test
5214a8e1175bSopenharmony_ci}
5215a8e1175bSopenharmony_ci
5216a8e1175bSopenharmony_ci# helper for common_block_cipher_no_decrypt() which:
5217a8e1175bSopenharmony_ci# - enable/disable the list of config options passed from -s/-u respectively.
5218a8e1175bSopenharmony_ci# - build
5219a8e1175bSopenharmony_ci# - test for tests_suite_xxx
5220a8e1175bSopenharmony_ci# - selftest
5221a8e1175bSopenharmony_ci#
5222a8e1175bSopenharmony_ci# Usage: helper_block_cipher_no_decrypt_build_test
5223a8e1175bSopenharmony_ci#        [-s set_opts] [-u unset_opts] [-c cflags] [-l ldflags] [option [...]]
5224a8e1175bSopenharmony_ci# Options:  -s set_opts     the list of config options to enable
5225a8e1175bSopenharmony_ci#           -u unset_opts   the list of config options to disable
5226a8e1175bSopenharmony_ci#           -c cflags       the list of options passed to CFLAGS
5227a8e1175bSopenharmony_ci#           -l ldflags      the list of options passed to LDFLAGS
5228a8e1175bSopenharmony_cihelper_block_cipher_no_decrypt_build_test () {
5229a8e1175bSopenharmony_ci    while [ $# -gt 0 ]; do
5230a8e1175bSopenharmony_ci        case "$1" in
5231a8e1175bSopenharmony_ci            -s)
5232a8e1175bSopenharmony_ci                shift; local set_opts="$1";;
5233a8e1175bSopenharmony_ci            -u)
5234a8e1175bSopenharmony_ci                shift; local unset_opts="$1";;
5235a8e1175bSopenharmony_ci            -c)
5236a8e1175bSopenharmony_ci                shift; local cflags="-Werror -Wall -Wextra $1";;
5237a8e1175bSopenharmony_ci            -l)
5238a8e1175bSopenharmony_ci                shift; local ldflags="$1";;
5239a8e1175bSopenharmony_ci        esac
5240a8e1175bSopenharmony_ci        shift
5241a8e1175bSopenharmony_ci    done
5242a8e1175bSopenharmony_ci    set_opts="${set_opts:-}"
5243a8e1175bSopenharmony_ci    unset_opts="${unset_opts:-}"
5244a8e1175bSopenharmony_ci    cflags="${cflags:-}"
5245a8e1175bSopenharmony_ci    ldflags="${ldflags:-}"
5246a8e1175bSopenharmony_ci
5247a8e1175bSopenharmony_ci    [ -n "$set_opts" ] && echo "Enabling: $set_opts" && scripts/config.py set-all $set_opts
5248a8e1175bSopenharmony_ci    [ -n "$unset_opts" ] && echo "Disabling: $unset_opts" && scripts/config.py unset-all $unset_opts
5249a8e1175bSopenharmony_ci
5250a8e1175bSopenharmony_ci    msg "build: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
5251a8e1175bSopenharmony_ci    make clean
5252a8e1175bSopenharmony_ci    make CFLAGS="-O2 $cflags" LDFLAGS="$ldflags"
5253a8e1175bSopenharmony_ci
5254a8e1175bSopenharmony_ci    # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
5255a8e1175bSopenharmony_ci    not grep mbedtls_aes_setkey_dec library/aes.o
5256a8e1175bSopenharmony_ci    not grep mbedtls_aria_setkey_dec library/aria.o
5257a8e1175bSopenharmony_ci    not grep mbedtls_camellia_setkey_dec library/camellia.o
5258a8e1175bSopenharmony_ci    # Make sure we don't have mbedtls_internal_aes_decrypt in AES
5259a8e1175bSopenharmony_ci    not grep mbedtls_internal_aes_decrypt library/aes.o
5260a8e1175bSopenharmony_ci    # Make sure we don't have mbedtls_aesni_inverse_key in AESNI
5261a8e1175bSopenharmony_ci    not grep mbedtls_aesni_inverse_key library/aesni.o
5262a8e1175bSopenharmony_ci
5263a8e1175bSopenharmony_ci    msg "test: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
5264a8e1175bSopenharmony_ci    make test
5265a8e1175bSopenharmony_ci
5266a8e1175bSopenharmony_ci    msg "selftest: default config + BLOCK_CIPHER_NO_DECRYPT${set_opts:+ + $set_opts}${unset_opts:+ - $unset_opts} with $cflags${ldflags:+, $ldflags}"
5267a8e1175bSopenharmony_ci    programs/test/selftest
5268a8e1175bSopenharmony_ci}
5269a8e1175bSopenharmony_ci
5270a8e1175bSopenharmony_ci# This is a common configuration function used in:
5271a8e1175bSopenharmony_ci# - component_test_block_cipher_no_decrypt_aesni_legacy()
5272a8e1175bSopenharmony_ci# - component_test_block_cipher_no_decrypt_aesni_use_psa()
5273a8e1175bSopenharmony_ci# in order to test BLOCK_CIPHER_NO_DECRYPT with AESNI intrinsics,
5274a8e1175bSopenharmony_ci# AESNI assembly and AES C implementation on x86_64 and with AESNI intrinsics
5275a8e1175bSopenharmony_ci# on x86.
5276a8e1175bSopenharmony_cicommon_block_cipher_no_decrypt () {
5277a8e1175bSopenharmony_ci    # test AESNI intrinsics
5278a8e1175bSopenharmony_ci    helper_block_cipher_no_decrypt_build_test \
5279a8e1175bSopenharmony_ci        -s "MBEDTLS_AESNI_C" \
5280a8e1175bSopenharmony_ci        -c "-mpclmul -msse2 -maes"
5281a8e1175bSopenharmony_ci
5282a8e1175bSopenharmony_ci    # test AESNI assembly
5283a8e1175bSopenharmony_ci    helper_block_cipher_no_decrypt_build_test \
5284a8e1175bSopenharmony_ci        -s "MBEDTLS_AESNI_C" \
5285a8e1175bSopenharmony_ci        -c "-mno-pclmul -mno-sse2 -mno-aes"
5286a8e1175bSopenharmony_ci
5287a8e1175bSopenharmony_ci    # test AES C implementation
5288a8e1175bSopenharmony_ci    helper_block_cipher_no_decrypt_build_test \
5289a8e1175bSopenharmony_ci        -u "MBEDTLS_AESNI_C"
5290a8e1175bSopenharmony_ci
5291a8e1175bSopenharmony_ci    # test AESNI intrinsics for i386 target
5292a8e1175bSopenharmony_ci    helper_block_cipher_no_decrypt_build_test \
5293a8e1175bSopenharmony_ci        -s "MBEDTLS_AESNI_C" \
5294a8e1175bSopenharmony_ci        -c "-m32 -mpclmul -msse2 -maes" \
5295a8e1175bSopenharmony_ci        -l "-m32"
5296a8e1175bSopenharmony_ci}
5297a8e1175bSopenharmony_ci
5298a8e1175bSopenharmony_ci# This is a configuration function used in component_test_block_cipher_no_decrypt_xxx:
5299a8e1175bSopenharmony_ci# usage: 0: no PSA crypto configuration
5300a8e1175bSopenharmony_ci#        1: use PSA crypto configuration
5301a8e1175bSopenharmony_ciconfig_block_cipher_no_decrypt () {
5302a8e1175bSopenharmony_ci    use_psa=$1
5303a8e1175bSopenharmony_ci
5304a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_BLOCK_CIPHER_NO_DECRYPT
5305a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_MODE_CBC
5306a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CIPHER_MODE_XTS
5307a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_DES_C
5308a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_NIST_KW_C
5309a8e1175bSopenharmony_ci
5310a8e1175bSopenharmony_ci    if [ "$use_psa" -eq 1 ]; then
5311a8e1175bSopenharmony_ci        # Enable support for cryptographic mechanisms through the PSA API.
5312a8e1175bSopenharmony_ci        # Note: XTS, KW are not yet supported via the PSA API in Mbed TLS.
5313a8e1175bSopenharmony_ci        scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
5314a8e1175bSopenharmony_ci        scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_NO_PADDING
5315a8e1175bSopenharmony_ci        scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_CBC_PKCS7
5316a8e1175bSopenharmony_ci        scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_ECB_NO_PADDING
5317a8e1175bSopenharmony_ci        scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_KEY_TYPE_DES
5318a8e1175bSopenharmony_ci    fi
5319a8e1175bSopenharmony_ci}
5320a8e1175bSopenharmony_ci
5321a8e1175bSopenharmony_cicomponent_test_block_cipher_no_decrypt_aesni () {
5322a8e1175bSopenharmony_ci    # This consistently causes an llvm crash on clang 3.8, so use gcc
5323a8e1175bSopenharmony_ci    export CC=gcc
5324a8e1175bSopenharmony_ci    config_block_cipher_no_decrypt 0
5325a8e1175bSopenharmony_ci    common_block_cipher_no_decrypt
5326a8e1175bSopenharmony_ci}
5327a8e1175bSopenharmony_ci
5328a8e1175bSopenharmony_cicomponent_test_block_cipher_no_decrypt_aesni_use_psa () {
5329a8e1175bSopenharmony_ci    # This consistently causes an llvm crash on clang 3.8, so use gcc
5330a8e1175bSopenharmony_ci    export CC=gcc
5331a8e1175bSopenharmony_ci    config_block_cipher_no_decrypt 1
5332a8e1175bSopenharmony_ci    common_block_cipher_no_decrypt
5333a8e1175bSopenharmony_ci}
5334a8e1175bSopenharmony_ci
5335a8e1175bSopenharmony_cisupport_test_block_cipher_no_decrypt_aesce_armcc () {
5336a8e1175bSopenharmony_ci    support_build_armcc
5337a8e1175bSopenharmony_ci}
5338a8e1175bSopenharmony_ci
5339a8e1175bSopenharmony_cicomponent_test_block_cipher_no_decrypt_aesce_armcc () {
5340a8e1175bSopenharmony_ci    scripts/config.py baremetal
5341a8e1175bSopenharmony_ci
5342a8e1175bSopenharmony_ci    # armc[56] don't support SHA-512 intrinsics
5343a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
5344a8e1175bSopenharmony_ci
5345a8e1175bSopenharmony_ci    # Stop armclang warning about feature detection for A64_CRYPTO.
5346a8e1175bSopenharmony_ci    # With this enabled, the library does build correctly under armclang,
5347a8e1175bSopenharmony_ci    # but in baremetal builds (as tested here), feature detection is
5348a8e1175bSopenharmony_ci    # unavailable, and the user is notified via a #warning. So enabling
5349a8e1175bSopenharmony_ci    # this feature would prevent us from building with -Werror on
5350a8e1175bSopenharmony_ci    # armclang. Tracked in #7198.
5351a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT
5352a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_HAVE_ASM
5353a8e1175bSopenharmony_ci
5354a8e1175bSopenharmony_ci    config_block_cipher_no_decrypt 1
5355a8e1175bSopenharmony_ci
5356a8e1175bSopenharmony_ci    # test AESCE baremetal build
5357a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AESCE_C
5358a8e1175bSopenharmony_ci    msg "build: default config + BLOCK_CIPHER_NO_DECRYPT with AESCE"
5359a8e1175bSopenharmony_ci    armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8-a+crypto -Werror -Wall -Wextra"
5360a8e1175bSopenharmony_ci
5361a8e1175bSopenharmony_ci    # Make sure we don't have mbedtls_xxx_setkey_dec in AES/ARIA/CAMELLIA
5362a8e1175bSopenharmony_ci    not grep mbedtls_aes_setkey_dec library/aes.o
5363a8e1175bSopenharmony_ci    not grep mbedtls_aria_setkey_dec library/aria.o
5364a8e1175bSopenharmony_ci    not grep mbedtls_camellia_setkey_dec library/camellia.o
5365a8e1175bSopenharmony_ci    # Make sure we don't have mbedtls_internal_aes_decrypt in AES
5366a8e1175bSopenharmony_ci    not grep mbedtls_internal_aes_decrypt library/aes.o
5367a8e1175bSopenharmony_ci    # Make sure we don't have mbedtls_aesce_inverse_key and aesce_decrypt_block in AESCE
5368a8e1175bSopenharmony_ci    not grep mbedtls_aesce_inverse_key library/aesce.o
5369a8e1175bSopenharmony_ci    not grep aesce_decrypt_block library/aesce.o
5370a8e1175bSopenharmony_ci}
5371a8e1175bSopenharmony_ci
5372a8e1175bSopenharmony_cicomponent_test_ctr_drbg_aes_256_sha_256 () {
5373a8e1175bSopenharmony_ci    msg "build: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
5374a8e1175bSopenharmony_ci    scripts/config.py full
5375a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
5376a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
5377a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
5378a8e1175bSopenharmony_ci    make
5379a8e1175bSopenharmony_ci
5380a8e1175bSopenharmony_ci    msg "test: full + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
5381a8e1175bSopenharmony_ci    make test
5382a8e1175bSopenharmony_ci}
5383a8e1175bSopenharmony_ci
5384a8e1175bSopenharmony_cicomponent_test_ctr_drbg_aes_128_sha_512 () {
5385a8e1175bSopenharmony_ci    msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
5386a8e1175bSopenharmony_ci    scripts/config.py full
5387a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
5388a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
5389a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
5390a8e1175bSopenharmony_ci    make
5391a8e1175bSopenharmony_ci
5392a8e1175bSopenharmony_ci    msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY (ASan build)"
5393a8e1175bSopenharmony_ci    make test
5394a8e1175bSopenharmony_ci}
5395a8e1175bSopenharmony_ci
5396a8e1175bSopenharmony_cicomponent_test_ctr_drbg_aes_128_sha_256 () {
5397a8e1175bSopenharmony_ci    msg "build: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
5398a8e1175bSopenharmony_ci    scripts/config.py full
5399a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_MEMORY_BUFFER_ALLOC_C
5400a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
5401a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_ENTROPY_FORCE_SHA256
5402a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
5403a8e1175bSopenharmony_ci    make
5404a8e1175bSopenharmony_ci
5405a8e1175bSopenharmony_ci    msg "test: full + MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + MBEDTLS_ENTROPY_FORCE_SHA256 (ASan build)"
5406a8e1175bSopenharmony_ci    make test
5407a8e1175bSopenharmony_ci}
5408a8e1175bSopenharmony_ci
5409a8e1175bSopenharmony_cicomponent_test_se_default () {
5410a8e1175bSopenharmony_ci    msg "build: default config + MBEDTLS_PSA_CRYPTO_SE_C"
5411a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PSA_CRYPTO_SE_C
5412a8e1175bSopenharmony_ci    make CC=clang CFLAGS="$ASAN_CFLAGS -Os" LDFLAGS="$ASAN_CFLAGS"
5413a8e1175bSopenharmony_ci
5414a8e1175bSopenharmony_ci    msg "test: default config + MBEDTLS_PSA_CRYPTO_SE_C"
5415a8e1175bSopenharmony_ci    make test
5416a8e1175bSopenharmony_ci}
5417a8e1175bSopenharmony_ci
5418a8e1175bSopenharmony_cicomponent_test_psa_crypto_drivers () {
5419a8e1175bSopenharmony_ci    msg "build: full + test drivers dispatching to builtins"
5420a8e1175bSopenharmony_ci    scripts/config.py full
5421a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PSA_CRYPTO_CONFIG
5422a8e1175bSopenharmony_ci    loc_cflags="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST_ALL"
5423a8e1175bSopenharmony_ci    loc_cflags="${loc_cflags} '-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-for-test.h\"'"
5424a8e1175bSopenharmony_ci    loc_cflags="${loc_cflags} -I../tests/include -O2"
5425a8e1175bSopenharmony_ci
5426a8e1175bSopenharmony_ci    make CC=$ASAN_CC CFLAGS="${loc_cflags}" LDFLAGS="$ASAN_CFLAGS"
5427a8e1175bSopenharmony_ci
5428a8e1175bSopenharmony_ci    msg "test: full + test drivers dispatching to builtins"
5429a8e1175bSopenharmony_ci    make test
5430a8e1175bSopenharmony_ci}
5431a8e1175bSopenharmony_ci
5432a8e1175bSopenharmony_cicomponent_test_make_shared () {
5433a8e1175bSopenharmony_ci    msg "build/test: make shared" # ~ 40s
5434a8e1175bSopenharmony_ci    make SHARED=1 all check
5435a8e1175bSopenharmony_ci    ldd programs/util/strerror | grep libmbedcrypto
5436a8e1175bSopenharmony_ci    programs/test/dlopen_demo.sh
5437a8e1175bSopenharmony_ci}
5438a8e1175bSopenharmony_ci
5439a8e1175bSopenharmony_cicomponent_test_cmake_shared () {
5440a8e1175bSopenharmony_ci    msg "build/test: cmake shared" # ~ 2min
5441a8e1175bSopenharmony_ci    cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
5442a8e1175bSopenharmony_ci    make
5443a8e1175bSopenharmony_ci    ldd programs/util/strerror | grep libmbedcrypto
5444a8e1175bSopenharmony_ci    make test
5445a8e1175bSopenharmony_ci    programs/test/dlopen_demo.sh
5446a8e1175bSopenharmony_ci}
5447a8e1175bSopenharmony_ci
5448a8e1175bSopenharmony_citest_build_opt () {
5449a8e1175bSopenharmony_ci    info=$1 cc=$2; shift 2
5450a8e1175bSopenharmony_ci    $cc --version
5451a8e1175bSopenharmony_ci    for opt in "$@"; do
5452a8e1175bSopenharmony_ci          msg "build/test: $cc $opt, $info" # ~ 30s
5453a8e1175bSopenharmony_ci          make CC="$cc" CFLAGS="$opt -std=c99 -pedantic -Wall -Wextra -Werror"
5454a8e1175bSopenharmony_ci          # We're confident enough in compilers to not run _all_ the tests,
5455a8e1175bSopenharmony_ci          # but at least run the unit tests. In particular, runs with
5456a8e1175bSopenharmony_ci          # optimizations use inline assembly whereas runs with -O0
5457a8e1175bSopenharmony_ci          # skip inline assembly.
5458a8e1175bSopenharmony_ci          make test # ~30s
5459a8e1175bSopenharmony_ci          make clean
5460a8e1175bSopenharmony_ci    done
5461a8e1175bSopenharmony_ci}
5462a8e1175bSopenharmony_ci
5463a8e1175bSopenharmony_ci# For FreeBSD we invoke the function by name so this condition is added
5464a8e1175bSopenharmony_ci# to disable the existing test_clang_opt function for linux.
5465a8e1175bSopenharmony_ciif [[ $(uname) != "Linux" ]]; then
5466a8e1175bSopenharmony_ci    component_test_clang_opt () {
5467a8e1175bSopenharmony_ci        scripts/config.py full
5468a8e1175bSopenharmony_ci        test_build_opt 'full config' clang -O0 -Os -O2
5469a8e1175bSopenharmony_ci    }
5470a8e1175bSopenharmony_cifi
5471a8e1175bSopenharmony_ci
5472a8e1175bSopenharmony_cicomponent_test_clang_latest_opt () {
5473a8e1175bSopenharmony_ci    scripts/config.py full
5474a8e1175bSopenharmony_ci    test_build_opt 'full config' "$CLANG_LATEST" -O0 -Os -O2
5475a8e1175bSopenharmony_ci}
5476a8e1175bSopenharmony_cisupport_test_clang_latest_opt () {
5477a8e1175bSopenharmony_ci    type "$CLANG_LATEST" >/dev/null 2>/dev/null
5478a8e1175bSopenharmony_ci}
5479a8e1175bSopenharmony_ci
5480a8e1175bSopenharmony_cicomponent_test_clang_earliest_opt () {
5481a8e1175bSopenharmony_ci    scripts/config.py full
5482a8e1175bSopenharmony_ci    test_build_opt 'full config' "$CLANG_EARLIEST" -O0
5483a8e1175bSopenharmony_ci}
5484a8e1175bSopenharmony_cisupport_test_clang_earliest_opt () {
5485a8e1175bSopenharmony_ci    type "$CLANG_EARLIEST" >/dev/null 2>/dev/null
5486a8e1175bSopenharmony_ci}
5487a8e1175bSopenharmony_ci
5488a8e1175bSopenharmony_cicomponent_test_gcc_latest_opt () {
5489a8e1175bSopenharmony_ci    scripts/config.py full
5490a8e1175bSopenharmony_ci    test_build_opt 'full config' "$GCC_LATEST" -O0 -Os -O2
5491a8e1175bSopenharmony_ci}
5492a8e1175bSopenharmony_cisupport_test_gcc_latest_opt () {
5493a8e1175bSopenharmony_ci    type "$GCC_LATEST" >/dev/null 2>/dev/null
5494a8e1175bSopenharmony_ci}
5495a8e1175bSopenharmony_ci
5496a8e1175bSopenharmony_cicomponent_test_gcc_earliest_opt () {
5497a8e1175bSopenharmony_ci    scripts/config.py full
5498a8e1175bSopenharmony_ci    test_build_opt 'full config' "$GCC_EARLIEST" -O0
5499a8e1175bSopenharmony_ci}
5500a8e1175bSopenharmony_cisupport_test_gcc_earliest_opt () {
5501a8e1175bSopenharmony_ci    type "$GCC_EARLIEST" >/dev/null 2>/dev/null
5502a8e1175bSopenharmony_ci}
5503a8e1175bSopenharmony_ci
5504a8e1175bSopenharmony_cicomponent_build_mbedtls_config_file () {
5505a8e1175bSopenharmony_ci    msg "build: make with MBEDTLS_CONFIG_FILE" # ~40s
5506a8e1175bSopenharmony_ci    scripts/config.py -w full_config.h full
5507a8e1175bSopenharmony_ci    echo '#error "MBEDTLS_CONFIG_FILE is not working"' >"$CONFIG_H"
5508a8e1175bSopenharmony_ci    make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"'"
5509a8e1175bSopenharmony_ci    # Make sure this feature is enabled. We'll disable it in the next phase.
5510a8e1175bSopenharmony_ci    programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5511a8e1175bSopenharmony_ci    make clean
5512a8e1175bSopenharmony_ci
5513a8e1175bSopenharmony_ci    msg "build: make with MBEDTLS_CONFIG_FILE + MBEDTLS_USER_CONFIG_FILE"
5514a8e1175bSopenharmony_ci    # In the user config, disable one feature (for simplicity, pick a feature
5515a8e1175bSopenharmony_ci    # that nothing else depends on).
5516a8e1175bSopenharmony_ci    echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
5517a8e1175bSopenharmony_ci    make CFLAGS="-I '$PWD' -DMBEDTLS_CONFIG_FILE='\"full_config.h\"' -DMBEDTLS_USER_CONFIG_FILE='\"user_config.h\"'"
5518a8e1175bSopenharmony_ci    not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
5519a8e1175bSopenharmony_ci
5520a8e1175bSopenharmony_ci    rm -f user_config.h full_config.h
5521a8e1175bSopenharmony_ci}
5522a8e1175bSopenharmony_ci
5523a8e1175bSopenharmony_cicomponent_build_psa_config_file () {
5524a8e1175bSopenharmony_ci    msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE" # ~40s
5525a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_PSA_CRYPTO_CONFIG
5526a8e1175bSopenharmony_ci    cp "$CRYPTO_CONFIG_H" psa_test_config.h
5527a8e1175bSopenharmony_ci    echo '#error "MBEDTLS_PSA_CRYPTO_CONFIG_FILE is not working"' >"$CRYPTO_CONFIG_H"
5528a8e1175bSopenharmony_ci    make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"'"
5529a8e1175bSopenharmony_ci    # Make sure this feature is enabled. We'll disable it in the next phase.
5530a8e1175bSopenharmony_ci    programs/test/query_compile_time_config MBEDTLS_CMAC_C
5531a8e1175bSopenharmony_ci    make clean
5532a8e1175bSopenharmony_ci
5533a8e1175bSopenharmony_ci    msg "build: make with MBEDTLS_PSA_CRYPTO_CONFIG_FILE + MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE" # ~40s
5534a8e1175bSopenharmony_ci    # In the user config, disable one feature, which will reflect on the
5535a8e1175bSopenharmony_ci    # mbedtls configuration so we can query it with query_compile_time_config.
5536a8e1175bSopenharmony_ci    echo '#undef PSA_WANT_ALG_CMAC' >psa_user_config.h
5537a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_CMAC_C
5538a8e1175bSopenharmony_ci    make CFLAGS="-I '$PWD' -DMBEDTLS_PSA_CRYPTO_CONFIG_FILE='\"psa_test_config.h\"' -DMBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE='\"psa_user_config.h\"'"
5539a8e1175bSopenharmony_ci    not programs/test/query_compile_time_config MBEDTLS_CMAC_C
5540a8e1175bSopenharmony_ci
5541a8e1175bSopenharmony_ci    rm -f psa_test_config.h psa_user_config.h
5542a8e1175bSopenharmony_ci}
5543a8e1175bSopenharmony_ci
5544a8e1175bSopenharmony_cicomponent_build_psa_alt_headers () {
5545a8e1175bSopenharmony_ci    msg "build: make with PSA alt headers" # ~20s
5546a8e1175bSopenharmony_ci
5547a8e1175bSopenharmony_ci    # Generate alternative versions of the substitutable headers with the
5548a8e1175bSopenharmony_ci    # same content except different include guards.
5549a8e1175bSopenharmony_ci    make -C tests include/alt-extra/psa/crypto_platform_alt.h include/alt-extra/psa/crypto_struct_alt.h
5550a8e1175bSopenharmony_ci
5551a8e1175bSopenharmony_ci    # Build the library and some programs.
5552a8e1175bSopenharmony_ci    # Don't build the fuzzers to avoid having to go through hoops to set
5553a8e1175bSopenharmony_ci    # a correct include path for programs/fuzz/Makefile.
5554a8e1175bSopenharmony_ci    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
5555a8e1175bSopenharmony_ci    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\"'"
5556a8e1175bSopenharmony_ci
5557a8e1175bSopenharmony_ci    # Check that we're getting the alternative include guards and not the
5558a8e1175bSopenharmony_ci    # original include guards.
5559a8e1175bSopenharmony_ci    programs/test/query_included_headers | grep -x PSA_CRYPTO_PLATFORM_ALT_H
5560a8e1175bSopenharmony_ci    programs/test/query_included_headers | grep -x PSA_CRYPTO_STRUCT_ALT_H
5561a8e1175bSopenharmony_ci    programs/test/query_included_headers | not grep -x PSA_CRYPTO_PLATFORM_H
5562a8e1175bSopenharmony_ci    programs/test/query_included_headers | not grep -x PSA_CRYPTO_STRUCT_H
5563a8e1175bSopenharmony_ci}
5564a8e1175bSopenharmony_ci
5565a8e1175bSopenharmony_cicomponent_test_m32_no_asm () {
5566a8e1175bSopenharmony_ci    # Build without assembly, so as to use portable C code (in a 32-bit
5567a8e1175bSopenharmony_ci    # build) and not the i386-specific inline assembly.
5568a8e1175bSopenharmony_ci    #
5569a8e1175bSopenharmony_ci    # Note that we require gcc, because clang Asan builds fail to link for
5570a8e1175bSopenharmony_ci    # this target (cannot find libclang_rt.lsan-i386.a - this is a known clang issue).
5571a8e1175bSopenharmony_ci    msg "build: i386, make, gcc, no asm (ASan build)" # ~ 30s
5572a8e1175bSopenharmony_ci    scripts/config.py full
5573a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_HAVE_ASM
5574a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PADLOCK_C
5575a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
5576a8e1175bSopenharmony_ci    make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
5577a8e1175bSopenharmony_ci
5578a8e1175bSopenharmony_ci    msg "test: i386, make, gcc, no asm (ASan build)"
5579a8e1175bSopenharmony_ci    make test
5580a8e1175bSopenharmony_ci}
5581a8e1175bSopenharmony_cisupport_test_m32_no_asm () {
5582a8e1175bSopenharmony_ci    case $(uname -m) in
5583a8e1175bSopenharmony_ci        amd64|x86_64) true;;
5584a8e1175bSopenharmony_ci        *) false;;
5585a8e1175bSopenharmony_ci    esac
5586a8e1175bSopenharmony_ci}
5587a8e1175bSopenharmony_ci
5588a8e1175bSopenharmony_cicomponent_test_m32_o2 () {
5589a8e1175bSopenharmony_ci    # Build with optimization, to use the i386 specific inline assembly
5590a8e1175bSopenharmony_ci    # and go faster for tests.
5591a8e1175bSopenharmony_ci    msg "build: i386, make, gcc -O2 (ASan build)" # ~ 30s
5592a8e1175bSopenharmony_ci    scripts/config.py full
5593a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
5594a8e1175bSopenharmony_ci    make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
5595a8e1175bSopenharmony_ci
5596a8e1175bSopenharmony_ci    msg "test: i386, make, gcc -O2 (ASan build)"
5597a8e1175bSopenharmony_ci    make test
5598a8e1175bSopenharmony_ci
5599a8e1175bSopenharmony_ci    msg "test ssl-opt.sh, i386, make, gcc-O2"
5600a8e1175bSopenharmony_ci    tests/ssl-opt.sh
5601a8e1175bSopenharmony_ci}
5602a8e1175bSopenharmony_cisupport_test_m32_o2 () {
5603a8e1175bSopenharmony_ci    support_test_m32_no_asm "$@"
5604a8e1175bSopenharmony_ci}
5605a8e1175bSopenharmony_ci
5606a8e1175bSopenharmony_cicomponent_test_m32_everest () {
5607a8e1175bSopenharmony_ci    msg "build: i386, Everest ECDH context (ASan build)" # ~ 6 min
5608a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED
5609a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESNI_C # AESNI for 32-bit is tested in test_aesni_m32
5610a8e1175bSopenharmony_ci    make CC=gcc CFLAGS="$ASAN_CFLAGS -m32" LDFLAGS="-m32 $ASAN_CFLAGS"
5611a8e1175bSopenharmony_ci
5612a8e1175bSopenharmony_ci    msg "test: i386, Everest ECDH context - main suites (inc. selftests) (ASan build)" # ~ 50s
5613a8e1175bSopenharmony_ci    make test
5614a8e1175bSopenharmony_ci
5615a8e1175bSopenharmony_ci    msg "test: i386, Everest ECDH context - ECDH-related part of ssl-opt.sh (ASan build)" # ~ 5s
5616a8e1175bSopenharmony_ci    tests/ssl-opt.sh -f ECDH
5617a8e1175bSopenharmony_ci
5618a8e1175bSopenharmony_ci    msg "test: i386, Everest ECDH context - compat.sh with some ECDH ciphersuites (ASan build)" # ~ 3 min
5619a8e1175bSopenharmony_ci    # Exclude some symmetric ciphers that are redundant here to gain time.
5620a8e1175bSopenharmony_ci    tests/compat.sh -f ECDH -V NO -e 'ARIA\|CAMELLIA\|CHACHA'
5621a8e1175bSopenharmony_ci}
5622a8e1175bSopenharmony_cisupport_test_m32_everest () {
5623a8e1175bSopenharmony_ci    support_test_m32_no_asm "$@"
5624a8e1175bSopenharmony_ci}
5625a8e1175bSopenharmony_ci
5626a8e1175bSopenharmony_cicomponent_test_mx32 () {
5627a8e1175bSopenharmony_ci    msg "build: 64-bit ILP32, make, gcc" # ~ 30s
5628a8e1175bSopenharmony_ci    scripts/config.py full
5629a8e1175bSopenharmony_ci    make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -mx32' LDFLAGS='-mx32'
5630a8e1175bSopenharmony_ci
5631a8e1175bSopenharmony_ci    msg "test: 64-bit ILP32, make, gcc"
5632a8e1175bSopenharmony_ci    make test
5633a8e1175bSopenharmony_ci}
5634a8e1175bSopenharmony_cisupport_test_mx32 () {
5635a8e1175bSopenharmony_ci    case $(uname -m) in
5636a8e1175bSopenharmony_ci        amd64|x86_64) true;;
5637a8e1175bSopenharmony_ci        *) false;;
5638a8e1175bSopenharmony_ci    esac
5639a8e1175bSopenharmony_ci}
5640a8e1175bSopenharmony_ci
5641a8e1175bSopenharmony_cicomponent_test_min_mpi_window_size () {
5642a8e1175bSopenharmony_ci    msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s
5643a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_MPI_WINDOW_SIZE 1
5644a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
5645a8e1175bSopenharmony_ci    make
5646a8e1175bSopenharmony_ci
5647a8e1175bSopenharmony_ci    msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s
5648a8e1175bSopenharmony_ci    make test
5649a8e1175bSopenharmony_ci}
5650a8e1175bSopenharmony_ci
5651a8e1175bSopenharmony_cicomponent_test_have_int32 () {
5652a8e1175bSopenharmony_ci    msg "build: gcc, force 32-bit bignum limbs"
5653a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_HAVE_ASM
5654a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESNI_C
5655a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PADLOCK_C
5656a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESCE_C
5657a8e1175bSopenharmony_ci    make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32'
5658a8e1175bSopenharmony_ci
5659a8e1175bSopenharmony_ci    msg "test: gcc, force 32-bit bignum limbs"
5660a8e1175bSopenharmony_ci    make test
5661a8e1175bSopenharmony_ci}
5662a8e1175bSopenharmony_ci
5663a8e1175bSopenharmony_cicomponent_test_have_int64 () {
5664a8e1175bSopenharmony_ci    msg "build: gcc, force 64-bit bignum limbs"
5665a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_HAVE_ASM
5666a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESNI_C
5667a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PADLOCK_C
5668a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESCE_C
5669a8e1175bSopenharmony_ci    make CC=gcc CFLAGS='-O2 -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64'
5670a8e1175bSopenharmony_ci
5671a8e1175bSopenharmony_ci    msg "test: gcc, force 64-bit bignum limbs"
5672a8e1175bSopenharmony_ci    make test
5673a8e1175bSopenharmony_ci}
5674a8e1175bSopenharmony_ci
5675a8e1175bSopenharmony_cicomponent_test_have_int32_cmake_new_bignum () {
5676a8e1175bSopenharmony_ci    msg "build: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
5677a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_HAVE_ASM
5678a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESNI_C
5679a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PADLOCK_C
5680a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESCE_C
5681a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_TEST_HOOKS
5682a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_ECP_WITH_MPI_UINT
5683a8e1175bSopenharmony_ci    make CC=gcc CFLAGS="$ASAN_CFLAGS -Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32" LDFLAGS="$ASAN_CFLAGS"
5684a8e1175bSopenharmony_ci
5685a8e1175bSopenharmony_ci    msg "test: gcc, force 32-bit bignum limbs, new bignum interface, test hooks (ASan build)"
5686a8e1175bSopenharmony_ci    make test
5687a8e1175bSopenharmony_ci}
5688a8e1175bSopenharmony_ci
5689a8e1175bSopenharmony_cicomponent_test_no_udbl_division () {
5690a8e1175bSopenharmony_ci    msg "build: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
5691a8e1175bSopenharmony_ci    scripts/config.py full
5692a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
5693a8e1175bSopenharmony_ci    make CFLAGS='-Werror -O1'
5694a8e1175bSopenharmony_ci
5695a8e1175bSopenharmony_ci    msg "test: MBEDTLS_NO_UDBL_DIVISION native" # ~ 10s
5696a8e1175bSopenharmony_ci    make test
5697a8e1175bSopenharmony_ci}
5698a8e1175bSopenharmony_ci
5699a8e1175bSopenharmony_cicomponent_test_no_64bit_multiplication () {
5700a8e1175bSopenharmony_ci    msg "build: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
5701a8e1175bSopenharmony_ci    scripts/config.py full
5702a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
5703a8e1175bSopenharmony_ci    make CFLAGS='-Werror -O1'
5704a8e1175bSopenharmony_ci
5705a8e1175bSopenharmony_ci    msg "test: MBEDTLS_NO_64BIT_MULTIPLICATION native" # ~ 10s
5706a8e1175bSopenharmony_ci    make test
5707a8e1175bSopenharmony_ci}
5708a8e1175bSopenharmony_ci
5709a8e1175bSopenharmony_cicomponent_test_no_strings () {
5710a8e1175bSopenharmony_ci    msg "build: no strings" # ~10s
5711a8e1175bSopenharmony_ci    scripts/config.py full
5712a8e1175bSopenharmony_ci    # Disable options that activate a large amount of string constants.
5713a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_DEBUG_C
5714a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ERROR_C
5715a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_ERROR_STRERROR_DUMMY
5716a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_VERSION_FEATURES
5717a8e1175bSopenharmony_ci    make CFLAGS='-Werror -Os'
5718a8e1175bSopenharmony_ci
5719a8e1175bSopenharmony_ci    msg "test: no strings" # ~ 10s
5720a8e1175bSopenharmony_ci    make test
5721a8e1175bSopenharmony_ci}
5722a8e1175bSopenharmony_ci
5723a8e1175bSopenharmony_cicomponent_test_no_x509_info () {
5724a8e1175bSopenharmony_ci    msg "build: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
5725a8e1175bSopenharmony_ci    scripts/config.pl full
5726a8e1175bSopenharmony_ci    scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests
5727a8e1175bSopenharmony_ci    scripts/config.pl set MBEDTLS_X509_REMOVE_INFO
5728a8e1175bSopenharmony_ci    make CFLAGS='-Werror -O2'
5729a8e1175bSopenharmony_ci
5730a8e1175bSopenharmony_ci    msg "test: full + MBEDTLS_X509_REMOVE_INFO" # ~ 10s
5731a8e1175bSopenharmony_ci    make test
5732a8e1175bSopenharmony_ci
5733a8e1175bSopenharmony_ci    msg "test: ssl-opt.sh, full + MBEDTLS_X509_REMOVE_INFO" # ~ 1 min
5734a8e1175bSopenharmony_ci    tests/ssl-opt.sh
5735a8e1175bSopenharmony_ci}
5736a8e1175bSopenharmony_ci
5737a8e1175bSopenharmony_cicomponent_build_arm_none_eabi_gcc () {
5738a8e1175bSopenharmony_ci    msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug" # ~ 10s
5739a8e1175bSopenharmony_ci    scripts/config.py baremetal
5740a8e1175bSopenharmony_ci    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
5741a8e1175bSopenharmony_ci
5742a8e1175bSopenharmony_ci    msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -O1, baremetal+debug"
5743a8e1175bSopenharmony_ci    ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
5744a8e1175bSopenharmony_ci}
5745a8e1175bSopenharmony_ci
5746a8e1175bSopenharmony_cicomponent_build_arm_linux_gnueabi_gcc_arm5vte () {
5747a8e1175bSopenharmony_ci    msg "build: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
5748a8e1175bSopenharmony_ci    scripts/config.py baremetal
5749a8e1175bSopenharmony_ci    # Build for a target platform that's close to what Debian uses
5750a8e1175bSopenharmony_ci    # for its "armel" distribution (https://wiki.debian.org/ArmEabiPort).
5751a8e1175bSopenharmony_ci    # See https://github.com/Mbed-TLS/mbedtls/pull/2169 and comments.
5752a8e1175bSopenharmony_ci    # Build everything including programs, see for example
5753a8e1175bSopenharmony_ci    # https://github.com/Mbed-TLS/mbedtls/pull/3449#issuecomment-675313720
5754a8e1175bSopenharmony_ci    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'
5755a8e1175bSopenharmony_ci
5756a8e1175bSopenharmony_ci    msg "size: ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
5757a8e1175bSopenharmony_ci    ${ARM_LINUX_GNUEABI_GCC_PREFIX}size -t library/*.o
5758a8e1175bSopenharmony_ci}
5759a8e1175bSopenharmony_cisupport_build_arm_linux_gnueabi_gcc_arm5vte () {
5760a8e1175bSopenharmony_ci    type ${ARM_LINUX_GNUEABI_GCC_PREFIX}gcc >/dev/null 2>&1
5761a8e1175bSopenharmony_ci}
5762a8e1175bSopenharmony_ci
5763a8e1175bSopenharmony_cicomponent_build_arm_none_eabi_gcc_arm5vte () {
5764a8e1175bSopenharmony_ci    msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=arm5vte, baremetal+debug" # ~ 10s
5765a8e1175bSopenharmony_ci    scripts/config.py baremetal
5766a8e1175bSopenharmony_ci    # This is an imperfect substitute for
5767a8e1175bSopenharmony_ci    # component_build_arm_linux_gnueabi_gcc_arm5vte
5768a8e1175bSopenharmony_ci    # in case the gcc-arm-linux-gnueabi toolchain is not available
5769a8e1175bSopenharmony_ci    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
5770a8e1175bSopenharmony_ci
5771a8e1175bSopenharmony_ci    msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -march=armv5te -O1, baremetal+debug"
5772a8e1175bSopenharmony_ci    ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
5773a8e1175bSopenharmony_ci}
5774a8e1175bSopenharmony_ci
5775a8e1175bSopenharmony_cicomponent_build_arm_none_eabi_gcc_m0plus () {
5776a8e1175bSopenharmony_ci    msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus, baremetal_size" # ~ 10s
5777a8e1175bSopenharmony_ci    scripts/config.py baremetal_size
5778a8e1175bSopenharmony_ci    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
5779a8e1175bSopenharmony_ci
5780a8e1175bSopenharmony_ci    msg "size: ${ARM_NONE_EABI_GCC_PREFIX}gcc -mthumb -mcpu=cortex-m0plus -Os, baremetal_size"
5781a8e1175bSopenharmony_ci    ${ARM_NONE_EABI_GCC_PREFIX}size -t library/*.o
5782a8e1175bSopenharmony_ci    for lib in library/*.a; do
5783a8e1175bSopenharmony_ci        echo "$lib:"
5784a8e1175bSopenharmony_ci        ${ARM_NONE_EABI_GCC_PREFIX}size -t $lib | grep TOTALS
5785a8e1175bSopenharmony_ci    done
5786a8e1175bSopenharmony_ci}
5787a8e1175bSopenharmony_ci
5788a8e1175bSopenharmony_cicomponent_build_arm_none_eabi_gcc_no_udbl_division () {
5789a8e1175bSopenharmony_ci    msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s
5790a8e1175bSopenharmony_ci    scripts/config.py baremetal
5791a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_NO_UDBL_DIVISION
5792a8e1175bSopenharmony_ci    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
5793a8e1175bSopenharmony_ci    echo "Checking that software 64-bit division is not required"
5794a8e1175bSopenharmony_ci    not grep __aeabi_uldiv library/*.o
5795a8e1175bSopenharmony_ci}
5796a8e1175bSopenharmony_ci
5797a8e1175bSopenharmony_cicomponent_build_arm_none_eabi_gcc_no_64bit_multiplication () {
5798a8e1175bSopenharmony_ci    msg "build: ${ARM_NONE_EABI_GCC_PREFIX}gcc MBEDTLS_NO_64BIT_MULTIPLICATION, make" # ~ 10s
5799a8e1175bSopenharmony_ci    scripts/config.py baremetal
5800a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_NO_64BIT_MULTIPLICATION
5801a8e1175bSopenharmony_ci    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
5802a8e1175bSopenharmony_ci    echo "Checking that software 64-bit multiplication is not required"
5803a8e1175bSopenharmony_ci    not grep __aeabi_lmul library/*.o
5804a8e1175bSopenharmony_ci}
5805a8e1175bSopenharmony_ci
5806a8e1175bSopenharmony_cicomponent_build_arm_clang_thumb () {
5807a8e1175bSopenharmony_ci    # ~ 30s
5808a8e1175bSopenharmony_ci
5809a8e1175bSopenharmony_ci    scripts/config.py baremetal
5810a8e1175bSopenharmony_ci
5811a8e1175bSopenharmony_ci    msg "build: clang thumb 2, make"
5812a8e1175bSopenharmony_ci    make clean
5813a8e1175bSopenharmony_ci    make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -march=armv7-m -mthumb' lib
5814a8e1175bSopenharmony_ci
5815a8e1175bSopenharmony_ci    # Some Thumb 1 asm is sensitive to optimisation level, so test both -O0 and -Os
5816a8e1175bSopenharmony_ci    msg "build: clang thumb 1 -O0, make"
5817a8e1175bSopenharmony_ci    make clean
5818a8e1175bSopenharmony_ci    make CC="clang" CFLAGS='-std=c99 -Werror -O0 --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
5819a8e1175bSopenharmony_ci
5820a8e1175bSopenharmony_ci    msg "build: clang thumb 1 -Os, make"
5821a8e1175bSopenharmony_ci    make clean
5822a8e1175bSopenharmony_ci    make CC="clang" CFLAGS='-std=c99 -Werror -Os --target=arm-linux-gnueabihf -mcpu=arm1136j-s -mthumb' lib
5823a8e1175bSopenharmony_ci}
5824a8e1175bSopenharmony_ci
5825a8e1175bSopenharmony_cicomponent_build_armcc () {
5826a8e1175bSopenharmony_ci    msg "build: ARM Compiler 5"
5827a8e1175bSopenharmony_ci    scripts/config.py baremetal
5828a8e1175bSopenharmony_ci    # armc[56] don't support SHA-512 intrinsics
5829a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT
5830a8e1175bSopenharmony_ci
5831a8e1175bSopenharmony_ci    # older versions of armcc/armclang don't support AESCE_C on 32-bit Arm
5832a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESCE_C
5833a8e1175bSopenharmony_ci
5834a8e1175bSopenharmony_ci    # Stop armclang warning about feature detection for A64_CRYPTO.
5835a8e1175bSopenharmony_ci    # With this enabled, the library does build correctly under armclang,
5836a8e1175bSopenharmony_ci    # but in baremetal builds (as tested here), feature detection is
5837a8e1175bSopenharmony_ci    # unavailable, and the user is notified via a #warning. So enabling
5838a8e1175bSopenharmony_ci    # this feature would prevent us from building with -Werror on
5839a8e1175bSopenharmony_ci    # armclang. Tracked in #7198.
5840a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT
5841a8e1175bSopenharmony_ci
5842a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_HAVE_ASM
5843a8e1175bSopenharmony_ci
5844a8e1175bSopenharmony_ci    make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib
5845a8e1175bSopenharmony_ci
5846a8e1175bSopenharmony_ci    msg "size: ARM Compiler 5"
5847a8e1175bSopenharmony_ci    "$ARMC5_FROMELF" -z library/*.o
5848a8e1175bSopenharmony_ci
5849a8e1175bSopenharmony_ci    # Compile mostly with -O1 since some Arm inline assembly is disabled for -O0.
5850a8e1175bSopenharmony_ci
5851a8e1175bSopenharmony_ci    # ARM Compiler 6 - Target ARMv7-A
5852a8e1175bSopenharmony_ci    armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-a"
5853a8e1175bSopenharmony_ci
5854a8e1175bSopenharmony_ci    # ARM Compiler 6 - Target ARMv7-M
5855a8e1175bSopenharmony_ci    armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m"
5856a8e1175bSopenharmony_ci
5857a8e1175bSopenharmony_ci    # ARM Compiler 6 - Target ARMv7-M+DSP
5858a8e1175bSopenharmony_ci    armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv7-m+dsp"
5859a8e1175bSopenharmony_ci
5860a8e1175bSopenharmony_ci    # ARM Compiler 6 - Target ARMv8-A - AArch32
5861a8e1175bSopenharmony_ci    armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8.2-a"
5862a8e1175bSopenharmony_ci
5863a8e1175bSopenharmony_ci    # ARM Compiler 6 - Target ARMv8-M
5864a8e1175bSopenharmony_ci    armc6_build_test "-O1 --target=arm-arm-none-eabi -march=armv8-m.main"
5865a8e1175bSopenharmony_ci
5866a8e1175bSopenharmony_ci    # ARM Compiler 6 - Target Cortex-M0 - no optimisation
5867a8e1175bSopenharmony_ci    armc6_build_test "-O0 --target=arm-arm-none-eabi -mcpu=cortex-m0"
5868a8e1175bSopenharmony_ci
5869a8e1175bSopenharmony_ci    # ARM Compiler 6 - Target Cortex-M0
5870a8e1175bSopenharmony_ci    armc6_build_test "-Os --target=arm-arm-none-eabi -mcpu=cortex-m0"
5871a8e1175bSopenharmony_ci
5872a8e1175bSopenharmony_ci    # ARM Compiler 6 - Target ARMv8.2-A - AArch64
5873a8e1175bSopenharmony_ci    #
5874a8e1175bSopenharmony_ci    # Re-enable MBEDTLS_AESCE_C as this should be supported by the version of armclang
5875a8e1175bSopenharmony_ci    # that we have in our CI
5876a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_AESCE_C
5877a8e1175bSopenharmony_ci    armc6_build_test "-O1 --target=aarch64-arm-none-eabi -march=armv8.2-a+crypto"
5878a8e1175bSopenharmony_ci}
5879a8e1175bSopenharmony_ci
5880a8e1175bSopenharmony_cisupport_build_armcc () {
5881a8e1175bSopenharmony_ci    armc5_cc="$ARMC5_BIN_DIR/armcc"
5882a8e1175bSopenharmony_ci    armc6_cc="$ARMC6_BIN_DIR/armclang"
5883a8e1175bSopenharmony_ci    (check_tools "$armc5_cc" "$armc6_cc" > /dev/null 2>&1)
5884a8e1175bSopenharmony_ci}
5885a8e1175bSopenharmony_ci
5886a8e1175bSopenharmony_cicomponent_test_tls12_only () {
5887a8e1175bSopenharmony_ci    msg "build: default config without MBEDTLS_SSL_PROTO_TLS1_3, cmake, gcc, ASan"
5888a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3
5889a8e1175bSopenharmony_ci    CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
5890a8e1175bSopenharmony_ci    make
5891a8e1175bSopenharmony_ci
5892a8e1175bSopenharmony_ci    msg "test: main suites (inc. selftests) (ASan build)"
5893a8e1175bSopenharmony_ci    make test
5894a8e1175bSopenharmony_ci
5895a8e1175bSopenharmony_ci    msg "test: ssl-opt.sh (ASan build)"
5896a8e1175bSopenharmony_ci    tests/ssl-opt.sh
5897a8e1175bSopenharmony_ci
5898a8e1175bSopenharmony_ci    msg "test: compat.sh (ASan build)"
5899a8e1175bSopenharmony_ci    tests/compat.sh
5900a8e1175bSopenharmony_ci}
5901a8e1175bSopenharmony_ci
5902a8e1175bSopenharmony_cicomponent_test_tls13_only () {
5903a8e1175bSopenharmony_ci    msg "build: default config without MBEDTLS_SSL_PROTO_TLS1_2"
5904a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_EARLY_DATA
5905a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_RECORD_SIZE_LIMIT
5906a8e1175bSopenharmony_ci    make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5907a8e1175bSopenharmony_ci
5908a8e1175bSopenharmony_ci    msg "test: TLS 1.3 only, all key exchange modes enabled"
5909a8e1175bSopenharmony_ci    make test
5910a8e1175bSopenharmony_ci
5911a8e1175bSopenharmony_ci    msg "ssl-opt.sh: TLS 1.3 only, all key exchange modes enabled"
5912a8e1175bSopenharmony_ci    tests/ssl-opt.sh
5913a8e1175bSopenharmony_ci}
5914a8e1175bSopenharmony_ci
5915a8e1175bSopenharmony_cicomponent_test_tls13_only_psk () {
5916a8e1175bSopenharmony_ci    msg "build: TLS 1.3 only from default, only PSK key exchange mode"
5917a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5918a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
5919a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDH_C
5920a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_DHM_C
5921a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5922a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5923a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5924a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDSA_C
5925a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PKCS1_V21
5926a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PKCS7_C
5927a8e1175bSopenharmony_ci    scripts/config.py set   MBEDTLS_SSL_EARLY_DATA
5928a8e1175bSopenharmony_ci    make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5929a8e1175bSopenharmony_ci
5930a8e1175bSopenharmony_ci    msg "test_suite_ssl: TLS 1.3 only, only PSK key exchange mode enabled"
5931a8e1175bSopenharmony_ci    cd tests; ./test_suite_ssl; cd ..
5932a8e1175bSopenharmony_ci
5933a8e1175bSopenharmony_ci    msg "ssl-opt.sh: TLS 1.3 only, only PSK key exchange mode enabled"
5934a8e1175bSopenharmony_ci    tests/ssl-opt.sh
5935a8e1175bSopenharmony_ci}
5936a8e1175bSopenharmony_ci
5937a8e1175bSopenharmony_cicomponent_test_tls13_only_ephemeral () {
5938a8e1175bSopenharmony_ci    msg "build: TLS 1.3 only from default, only ephemeral key exchange mode"
5939a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5940a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
5941a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
5942a8e1175bSopenharmony_ci    make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5943a8e1175bSopenharmony_ci
5944a8e1175bSopenharmony_ci    msg "test_suite_ssl: TLS 1.3 only, only ephemeral key exchange mode"
5945a8e1175bSopenharmony_ci    cd tests; ./test_suite_ssl; cd ..
5946a8e1175bSopenharmony_ci
5947a8e1175bSopenharmony_ci    msg "ssl-opt.sh: TLS 1.3 only, only ephemeral key exchange mode"
5948a8e1175bSopenharmony_ci    tests/ssl-opt.sh
5949a8e1175bSopenharmony_ci}
5950a8e1175bSopenharmony_ci
5951a8e1175bSopenharmony_cicomponent_test_tls13_only_ephemeral_ffdh () {
5952a8e1175bSopenharmony_ci    msg "build: TLS 1.3 only from default, only ephemeral ffdh key exchange mode"
5953a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5954a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED
5955a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_EARLY_DATA
5956a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDH_C
5957a8e1175bSopenharmony_ci
5958a8e1175bSopenharmony_ci    make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5959a8e1175bSopenharmony_ci
5960a8e1175bSopenharmony_ci    msg "test_suite_ssl: TLS 1.3 only, only ephemeral ffdh key exchange mode"
5961a8e1175bSopenharmony_ci    cd tests; ./test_suite_ssl; cd ..
5962a8e1175bSopenharmony_ci
5963a8e1175bSopenharmony_ci    msg "ssl-opt.sh: TLS 1.3 only, only ephemeral ffdh key exchange mode"
5964a8e1175bSopenharmony_ci    tests/ssl-opt.sh
5965a8e1175bSopenharmony_ci}
5966a8e1175bSopenharmony_ci
5967a8e1175bSopenharmony_cicomponent_test_tls13_only_psk_ephemeral () {
5968a8e1175bSopenharmony_ci    msg "build: TLS 1.3 only from default, only PSK ephemeral key exchange mode"
5969a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5970a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5971a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5972a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5973a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5974a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDSA_C
5975a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PKCS1_V21
5976a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PKCS7_C
5977a8e1175bSopenharmony_ci    scripts/config.py set   MBEDTLS_SSL_EARLY_DATA
5978a8e1175bSopenharmony_ci    make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
5979a8e1175bSopenharmony_ci
5980a8e1175bSopenharmony_ci    msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral key exchange mode"
5981a8e1175bSopenharmony_ci    cd tests; ./test_suite_ssl; cd ..
5982a8e1175bSopenharmony_ci
5983a8e1175bSopenharmony_ci    msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral key exchange mode"
5984a8e1175bSopenharmony_ci    tests/ssl-opt.sh
5985a8e1175bSopenharmony_ci}
5986a8e1175bSopenharmony_ci
5987a8e1175bSopenharmony_cicomponent_test_tls13_only_psk_ephemeral_ffdh () {
5988a8e1175bSopenharmony_ci    msg "build: TLS 1.3 only from default, only PSK ephemeral ffdh key exchange mode"
5989a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
5990a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
5991a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
5992a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
5993a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
5994a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDSA_C
5995a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PKCS1_V21
5996a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PKCS7_C
5997a8e1175bSopenharmony_ci    scripts/config.py set   MBEDTLS_SSL_EARLY_DATA
5998a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDH_C
5999a8e1175bSopenharmony_ci    make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
6000a8e1175bSopenharmony_ci
6001a8e1175bSopenharmony_ci    msg "test_suite_ssl: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
6002a8e1175bSopenharmony_ci    cd tests; ./test_suite_ssl; cd ..
6003a8e1175bSopenharmony_ci
6004a8e1175bSopenharmony_ci    msg "ssl-opt.sh: TLS 1.3 only, only PSK ephemeral ffdh key exchange mode"
6005a8e1175bSopenharmony_ci    tests/ssl-opt.sh
6006a8e1175bSopenharmony_ci}
6007a8e1175bSopenharmony_ci
6008a8e1175bSopenharmony_cicomponent_test_tls13_only_psk_all () {
6009a8e1175bSopenharmony_ci    msg "build: TLS 1.3 only from default, without ephemeral key exchange mode"
6010a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED
6011a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_CRT_PARSE_C
6012a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_X509_RSASSA_PSS_SUPPORT
6013a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_SERVER_NAME_INDICATION
6014a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_ECDSA_C
6015a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PKCS1_V21
6016a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_PKCS7_C
6017a8e1175bSopenharmony_ci    scripts/config.py set   MBEDTLS_SSL_EARLY_DATA
6018a8e1175bSopenharmony_ci    make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
6019a8e1175bSopenharmony_ci
6020a8e1175bSopenharmony_ci    msg "test_suite_ssl: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
6021a8e1175bSopenharmony_ci    cd tests; ./test_suite_ssl; cd ..
6022a8e1175bSopenharmony_ci
6023a8e1175bSopenharmony_ci    msg "ssl-opt.sh: TLS 1.3 only, PSK and PSK ephemeral key exchange modes"
6024a8e1175bSopenharmony_ci    tests/ssl-opt.sh
6025a8e1175bSopenharmony_ci}
6026a8e1175bSopenharmony_ci
6027a8e1175bSopenharmony_cicomponent_test_tls13_only_ephemeral_all () {
6028a8e1175bSopenharmony_ci    msg "build: TLS 1.3 only from default, without PSK key exchange mode"
6029a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED
6030a8e1175bSopenharmony_ci    scripts/config.py set   MBEDTLS_SSL_EARLY_DATA
6031a8e1175bSopenharmony_ci    make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'"
6032a8e1175bSopenharmony_ci
6033a8e1175bSopenharmony_ci    msg "test_suite_ssl: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
6034a8e1175bSopenharmony_ci    cd tests; ./test_suite_ssl; cd ..
6035a8e1175bSopenharmony_ci
6036a8e1175bSopenharmony_ci    msg "ssl-opt.sh: TLS 1.3 only, ephemeral and PSK ephemeral key exchange modes"
6037a8e1175bSopenharmony_ci    tests/ssl-opt.sh
6038a8e1175bSopenharmony_ci}
6039a8e1175bSopenharmony_ci
6040a8e1175bSopenharmony_cicomponent_test_tls13_no_padding () {
6041a8e1175bSopenharmony_ci    msg "build: default config plus early data minus padding"
6042a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 1
6043a8e1175bSopenharmony_ci    scripts/config.py set MBEDTLS_SSL_EARLY_DATA
6044a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
6045a8e1175bSopenharmony_ci    make
6046a8e1175bSopenharmony_ci    msg "test: default config plus early data minus padding"
6047a8e1175bSopenharmony_ci    make test
6048a8e1175bSopenharmony_ci    msg "ssl-opt.sh (TLS 1.3 no padding)"
6049a8e1175bSopenharmony_ci    tests/ssl-opt.sh
6050a8e1175bSopenharmony_ci}
6051a8e1175bSopenharmony_ci
6052a8e1175bSopenharmony_cicomponent_test_tls13_no_compatibility_mode () {
6053a8e1175bSopenharmony_ci    msg "build: default config plus early data minus middlebox compatibility mode"
6054a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE
6055a8e1175bSopenharmony_ci    scripts/config.py set   MBEDTLS_SSL_EARLY_DATA
6056a8e1175bSopenharmony_ci    CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan .
6057a8e1175bSopenharmony_ci    make
6058a8e1175bSopenharmony_ci    msg "test: default config plus early data minus middlebox compatibility mode"
6059a8e1175bSopenharmony_ci    make test
6060a8e1175bSopenharmony_ci    msg "ssl-opt.sh (TLS 1.3 no compatibility mode)"
6061a8e1175bSopenharmony_ci    tests/ssl-opt.sh
6062a8e1175bSopenharmony_ci}
6063a8e1175bSopenharmony_ci
6064a8e1175bSopenharmony_cicomponent_build_mingw () {
6065a8e1175bSopenharmony_ci    msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s
6066a8e1175bSopenharmony_ci    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
6067a8e1175bSopenharmony_ci
6068a8e1175bSopenharmony_ci    # note Make tests only builds the tests, but doesn't run them
6069a8e1175bSopenharmony_ci    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
6070a8e1175bSopenharmony_ci    make WINDOWS_BUILD=1 clean
6071a8e1175bSopenharmony_ci
6072a8e1175bSopenharmony_ci    msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s
6073a8e1175bSopenharmony_ci    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
6074a8e1175bSopenharmony_ci    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
6075a8e1175bSopenharmony_ci    make WINDOWS_BUILD=1 clean
6076a8e1175bSopenharmony_ci
6077a8e1175bSopenharmony_ci    msg "build: Windows cross build - mingw64, make (Library only, default config without MBEDTLS_AESNI_C)" # ~ 30s
6078a8e1175bSopenharmony_ci    ./scripts/config.py unset MBEDTLS_AESNI_C #
6079a8e1175bSopenharmony_ci    make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib
6080a8e1175bSopenharmony_ci    make WINDOWS_BUILD=1 clean
6081a8e1175bSopenharmony_ci}
6082a8e1175bSopenharmony_cisupport_build_mingw() {
6083a8e1175bSopenharmony_ci    case $(i686-w64-mingw32-gcc -dumpversion 2>/dev/null) in
6084a8e1175bSopenharmony_ci        [0-5]*|"") false;;
6085a8e1175bSopenharmony_ci        *) true;;
6086a8e1175bSopenharmony_ci    esac
6087a8e1175bSopenharmony_ci}
6088a8e1175bSopenharmony_ci
6089a8e1175bSopenharmony_cicomponent_test_memsan () {
6090a8e1175bSopenharmony_ci    msg "build: MSan (clang)" # ~ 1 min 20s
6091a8e1175bSopenharmony_ci    scripts/config.py unset MBEDTLS_AESNI_C # memsan doesn't grok asm
6092a8e1175bSopenharmony_ci    CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan .
6093a8e1175bSopenharmony_ci    make
6094a8e1175bSopenharmony_ci
6095a8e1175bSopenharmony_ci    msg "test: main suites (MSan)" # ~ 10s
6096a8e1175bSopenharmony_ci    make test
6097a8e1175bSopenharmony_ci
6098a8e1175bSopenharmony_ci    msg "test: metatests (MSan)"
6099a8e1175bSopenharmony_ci    tests/scripts/run-metatests.sh any msan
6100a8e1175bSopenharmony_ci
6101a8e1175bSopenharmony_ci    msg "program demos (MSan)" # ~20s
6102a8e1175bSopenharmony_ci    tests/scripts/run_demos.py
6103a8e1175bSopenharmony_ci
6104a8e1175bSopenharmony_ci    msg "test: ssl-opt.sh (MSan)" # ~ 1 min
6105a8e1175bSopenharmony_ci    tests/ssl-opt.sh
6106a8e1175bSopenharmony_ci
6107a8e1175bSopenharmony_ci    # Optional part(s)
6108a8e1175bSopenharmony_ci
6109a8e1175bSopenharmony_ci    if [ "$MEMORY" -gt 0 ]; then
6110a8e1175bSopenharmony_ci        msg "test: compat.sh (MSan)" # ~ 6 min 20s
6111a8e1175bSopenharmony_ci        tests/compat.sh
6112a8e1175bSopenharmony_ci    fi
6113a8e1175bSopenharmony_ci}
6114a8e1175bSopenharmony_ci
6115a8e1175bSopenharmony_cicomponent_release_test_valgrind () {
6116a8e1175bSopenharmony_ci    msg "build: Release (clang)"
6117a8e1175bSopenharmony_ci    # default config, in particular without MBEDTLS_USE_PSA_CRYPTO
6118a8e1175bSopenharmony_ci    CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
6119a8e1175bSopenharmony_ci    make
6120a8e1175bSopenharmony_ci
6121a8e1175bSopenharmony_ci    msg "test: main suites, Valgrind (default config)"
6122a8e1175bSopenharmony_ci    make memcheck
6123a8e1175bSopenharmony_ci
6124a8e1175bSopenharmony_ci    # Optional parts (slow; currently broken on OS X because programs don't
6125a8e1175bSopenharmony_ci    # seem to receive signals under valgrind on OS X).
6126a8e1175bSopenharmony_ci    # These optional parts don't run on the CI.
6127a8e1175bSopenharmony_ci    if [ "$MEMORY" -gt 0 ]; then
6128a8e1175bSopenharmony_ci        msg "test: ssl-opt.sh --memcheck (default config)"
6129a8e1175bSopenharmony_ci        tests/ssl-opt.sh --memcheck
6130a8e1175bSopenharmony_ci    fi
6131a8e1175bSopenharmony_ci
6132a8e1175bSopenharmony_ci    if [ "$MEMORY" -gt 1 ]; then
6133a8e1175bSopenharmony_ci        msg "test: compat.sh --memcheck (default config)"
6134a8e1175bSopenharmony_ci        tests/compat.sh --memcheck
6135a8e1175bSopenharmony_ci    fi
6136a8e1175bSopenharmony_ci
6137a8e1175bSopenharmony_ci    if [ "$MEMORY" -gt 0 ]; then
6138a8e1175bSopenharmony_ci        msg "test: context-info.sh --memcheck (default config)"
6139a8e1175bSopenharmony_ci        tests/context-info.sh --memcheck
6140a8e1175bSopenharmony_ci    fi
6141a8e1175bSopenharmony_ci}
6142a8e1175bSopenharmony_ci
6143a8e1175bSopenharmony_cicomponent_release_test_valgrind_psa () {
6144a8e1175bSopenharmony_ci    msg "build: Release, full (clang)"
6145a8e1175bSopenharmony_ci    # full config, in particular with MBEDTLS_USE_PSA_CRYPTO
6146a8e1175bSopenharmony_ci    scripts/config.py full
6147a8e1175bSopenharmony_ci    CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release .
6148a8e1175bSopenharmony_ci    make
6149a8e1175bSopenharmony_ci
6150a8e1175bSopenharmony_ci    msg "test: main suites, Valgrind (full config)"
6151a8e1175bSopenharmony_ci    make memcheck
6152a8e1175bSopenharmony_ci}
6153a8e1175bSopenharmony_ci
6154a8e1175bSopenharmony_cisupport_test_cmake_out_of_source () {
6155a8e1175bSopenharmony_ci    distrib_id=""
6156a8e1175bSopenharmony_ci    distrib_ver=""
6157a8e1175bSopenharmony_ci    distrib_ver_minor=""
6158a8e1175bSopenharmony_ci    distrib_ver_major=""
6159a8e1175bSopenharmony_ci
6160a8e1175bSopenharmony_ci    # Attempt to parse lsb-release to find out distribution and version. If not
6161a8e1175bSopenharmony_ci    # found this should fail safe (test is supported).
6162a8e1175bSopenharmony_ci    if [[ -f /etc/lsb-release ]]; then
6163a8e1175bSopenharmony_ci
6164a8e1175bSopenharmony_ci        while read -r lsb_line; do
6165a8e1175bSopenharmony_ci            case "$lsb_line" in
6166a8e1175bSopenharmony_ci                "DISTRIB_ID"*) distrib_id=${lsb_line/#DISTRIB_ID=};;
6167a8e1175bSopenharmony_ci                "DISTRIB_RELEASE"*) distrib_ver=${lsb_line/#DISTRIB_RELEASE=};;
6168a8e1175bSopenharmony_ci            esac
6169a8e1175bSopenharmony_ci        done < /etc/lsb-release
6170a8e1175bSopenharmony_ci
6171a8e1175bSopenharmony_ci        distrib_ver_major="${distrib_ver%%.*}"
6172a8e1175bSopenharmony_ci        distrib_ver="${distrib_ver#*.}"
6173a8e1175bSopenharmony_ci        distrib_ver_minor="${distrib_ver%%.*}"
6174a8e1175bSopenharmony_ci    fi
6175a8e1175bSopenharmony_ci
6176a8e1175bSopenharmony_ci    # Running the out of source CMake test on Ubuntu 16.04 using more than one
6177a8e1175bSopenharmony_ci    # processor (as the CI does) can create a race condition whereby the build
6178a8e1175bSopenharmony_ci    # fails to see a generated file, despite that file actually having been
6179a8e1175bSopenharmony_ci    # generated. This problem appears to go away with 18.04 or newer, so make
6180a8e1175bSopenharmony_ci    # the out of source tests unsupported on Ubuntu 16.04.
6181a8e1175bSopenharmony_ci    [ "$distrib_id" != "Ubuntu" ] || [ "$distrib_ver_major" -gt 16 ]
6182a8e1175bSopenharmony_ci}
6183a8e1175bSopenharmony_ci
6184a8e1175bSopenharmony_cicomponent_test_cmake_out_of_source () {
6185a8e1175bSopenharmony_ci    # Remove existing generated files so that we use the ones cmake
6186a8e1175bSopenharmony_ci    # generates
6187a8e1175bSopenharmony_ci    make neat
6188a8e1175bSopenharmony_ci
6189a8e1175bSopenharmony_ci    msg "build: cmake 'out-of-source' build"
6190a8e1175bSopenharmony_ci    MBEDTLS_ROOT_DIR="$PWD"
6191a8e1175bSopenharmony_ci    mkdir "$OUT_OF_SOURCE_DIR"
6192a8e1175bSopenharmony_ci    cd "$OUT_OF_SOURCE_DIR"
6193a8e1175bSopenharmony_ci    # Note: Explicitly generate files as these are turned off in releases
6194a8e1175bSopenharmony_ci    cmake -D CMAKE_BUILD_TYPE:String=Check -D GEN_FILES=ON "$MBEDTLS_ROOT_DIR"
6195a8e1175bSopenharmony_ci    make
6196a8e1175bSopenharmony_ci
6197a8e1175bSopenharmony_ci    msg "test: cmake 'out-of-source' build"
6198a8e1175bSopenharmony_ci    make test
6199a8e1175bSopenharmony_ci    # Check that ssl-opt.sh can find the test programs.
6200a8e1175bSopenharmony_ci    # Also ensure that there are no error messages such as
6201a8e1175bSopenharmony_ci    # "No such file or directory", which would indicate that some required
6202a8e1175bSopenharmony_ci    # file is missing (ssl-opt.sh tolerates the absence of some files so
6203a8e1175bSopenharmony_ci    # may exit with status 0 but emit errors).
6204a8e1175bSopenharmony_ci    ./tests/ssl-opt.sh -f 'Default' >ssl-opt.out 2>ssl-opt.err
6205a8e1175bSopenharmony_ci    grep PASS ssl-opt.out
6206a8e1175bSopenharmony_ci    cat ssl-opt.err >&2
6207a8e1175bSopenharmony_ci    # If ssl-opt.err is non-empty, record an error and keep going.
6208a8e1175bSopenharmony_ci    [ ! -s ssl-opt.err ]
6209a8e1175bSopenharmony_ci    rm ssl-opt.out ssl-opt.err
6210a8e1175bSopenharmony_ci    cd "$MBEDTLS_ROOT_DIR"
6211a8e1175bSopenharmony_ci    rm -rf "$OUT_OF_SOURCE_DIR"
6212a8e1175bSopenharmony_ci}
6213a8e1175bSopenharmony_ci
6214a8e1175bSopenharmony_cicomponent_test_cmake_as_subdirectory () {
6215a8e1175bSopenharmony_ci    # Remove existing generated files so that we use the ones CMake
6216a8e1175bSopenharmony_ci    # generates
6217a8e1175bSopenharmony_ci    make neat
6218a8e1175bSopenharmony_ci
6219a8e1175bSopenharmony_ci    msg "build: cmake 'as-subdirectory' build"
6220a8e1175bSopenharmony_ci    cd programs/test/cmake_subproject
6221a8e1175bSopenharmony_ci    # Note: Explicitly generate files as these are turned off in releases
6222a8e1175bSopenharmony_ci    cmake -D GEN_FILES=ON .
6223a8e1175bSopenharmony_ci    make
6224a8e1175bSopenharmony_ci    ./cmake_subproject
6225a8e1175bSopenharmony_ci}
6226a8e1175bSopenharmony_cisupport_test_cmake_as_subdirectory () {
6227a8e1175bSopenharmony_ci    support_test_cmake_out_of_source
6228a8e1175bSopenharmony_ci}
6229a8e1175bSopenharmony_ci
6230a8e1175bSopenharmony_cicomponent_test_cmake_as_package () {
6231a8e1175bSopenharmony_ci    # Remove existing generated files so that we use the ones CMake
6232a8e1175bSopenharmony_ci    # generates
6233a8e1175bSopenharmony_ci    make neat
6234a8e1175bSopenharmony_ci
6235a8e1175bSopenharmony_ci    msg "build: cmake 'as-package' build"
6236a8e1175bSopenharmony_ci    cd programs/test/cmake_package
6237a8e1175bSopenharmony_ci    cmake .
6238a8e1175bSopenharmony_ci    make
6239a8e1175bSopenharmony_ci    ./cmake_package
6240a8e1175bSopenharmony_ci}
6241a8e1175bSopenharmony_cisupport_test_cmake_as_package () {
6242a8e1175bSopenharmony_ci    support_test_cmake_out_of_source
6243a8e1175bSopenharmony_ci}
6244a8e1175bSopenharmony_ci
6245a8e1175bSopenharmony_cicomponent_test_cmake_as_package_install () {
6246a8e1175bSopenharmony_ci    # Remove existing generated files so that we use the ones CMake
6247a8e1175bSopenharmony_ci    # generates
6248a8e1175bSopenharmony_ci    make neat
6249a8e1175bSopenharmony_ci
6250a8e1175bSopenharmony_ci    msg "build: cmake 'as-installed-package' build"
6251a8e1175bSopenharmony_ci    cd programs/test/cmake_package_install
6252a8e1175bSopenharmony_ci    cmake .
6253a8e1175bSopenharmony_ci    make
6254a8e1175bSopenharmony_ci    ./cmake_package_install
6255a8e1175bSopenharmony_ci}
6256a8e1175bSopenharmony_cisupport_test_cmake_as_package_install () {
6257a8e1175bSopenharmony_ci    support_test_cmake_out_of_source
6258a8e1175bSopenharmony_ci}
6259a8e1175bSopenharmony_ci
6260a8e1175bSopenharmony_cicomponent_build_cmake_custom_config_file () {
6261a8e1175bSopenharmony_ci    # Make a copy of config file to use for the in-tree test
6262a8e1175bSopenharmony_ci    cp "$CONFIG_H" include/mbedtls_config_in_tree_copy.h
6263a8e1175bSopenharmony_ci
6264a8e1175bSopenharmony_ci    MBEDTLS_ROOT_DIR="$PWD"
6265a8e1175bSopenharmony_ci    mkdir "$OUT_OF_SOURCE_DIR"
6266a8e1175bSopenharmony_ci    cd "$OUT_OF_SOURCE_DIR"
6267a8e1175bSopenharmony_ci
6268a8e1175bSopenharmony_ci    # Build once to get the generated files (which need an intact config file)
6269a8e1175bSopenharmony_ci    cmake "$MBEDTLS_ROOT_DIR"
6270a8e1175bSopenharmony_ci    make
6271a8e1175bSopenharmony_ci
6272a8e1175bSopenharmony_ci    msg "build: cmake with -DMBEDTLS_CONFIG_FILE"
6273a8e1175bSopenharmony_ci    scripts/config.py -w full_config.h full
6274a8e1175bSopenharmony_ci    echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
6275a8e1175bSopenharmony_ci    cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h "$MBEDTLS_ROOT_DIR"
6276a8e1175bSopenharmony_ci    make
6277a8e1175bSopenharmony_ci
6278a8e1175bSopenharmony_ci    msg "build: cmake with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
6279a8e1175bSopenharmony_ci    # In the user config, disable one feature (for simplicity, pick a feature
6280a8e1175bSopenharmony_ci    # that nothing else depends on).
6281a8e1175bSopenharmony_ci    echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
6282a8e1175bSopenharmony_ci
6283a8e1175bSopenharmony_ci    cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h "$MBEDTLS_ROOT_DIR"
6284a8e1175bSopenharmony_ci    make
6285a8e1175bSopenharmony_ci    not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
6286a8e1175bSopenharmony_ci
6287a8e1175bSopenharmony_ci    rm -f user_config.h full_config.h
6288a8e1175bSopenharmony_ci
6289a8e1175bSopenharmony_ci    cd "$MBEDTLS_ROOT_DIR"
6290a8e1175bSopenharmony_ci    rm -rf "$OUT_OF_SOURCE_DIR"
6291a8e1175bSopenharmony_ci
6292a8e1175bSopenharmony_ci    # Now repeat the test for an in-tree build:
6293a8e1175bSopenharmony_ci
6294a8e1175bSopenharmony_ci    # Restore config for the in-tree test
6295a8e1175bSopenharmony_ci    mv include/mbedtls_config_in_tree_copy.h "$CONFIG_H"
6296a8e1175bSopenharmony_ci
6297a8e1175bSopenharmony_ci    # Build once to get the generated files (which need an intact config)
6298a8e1175bSopenharmony_ci    cmake .
6299a8e1175bSopenharmony_ci    make
6300a8e1175bSopenharmony_ci
6301a8e1175bSopenharmony_ci    msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE"
6302a8e1175bSopenharmony_ci    scripts/config.py -w full_config.h full
6303a8e1175bSopenharmony_ci    echo '#error "cmake -DMBEDTLS_CONFIG_FILE is not working."' > "$MBEDTLS_ROOT_DIR/$CONFIG_H"
6304a8e1175bSopenharmony_ci    cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h .
6305a8e1175bSopenharmony_ci    make
6306a8e1175bSopenharmony_ci
6307a8e1175bSopenharmony_ci    msg "build: cmake (in-tree) with -DMBEDTLS_CONFIG_FILE + -DMBEDTLS_USER_CONFIG_FILE"
6308a8e1175bSopenharmony_ci    # In the user config, disable one feature (for simplicity, pick a feature
6309a8e1175bSopenharmony_ci    # that nothing else depends on).
6310a8e1175bSopenharmony_ci    echo '#undef MBEDTLS_NIST_KW_C' >user_config.h
6311a8e1175bSopenharmony_ci
6312a8e1175bSopenharmony_ci    cmake -DGEN_FILES=OFF -DMBEDTLS_CONFIG_FILE=full_config.h -DMBEDTLS_USER_CONFIG_FILE=user_config.h .
6313a8e1175bSopenharmony_ci    make
6314a8e1175bSopenharmony_ci    not programs/test/query_compile_time_config MBEDTLS_NIST_KW_C
6315a8e1175bSopenharmony_ci
6316a8e1175bSopenharmony_ci    rm -f user_config.h full_config.h
6317a8e1175bSopenharmony_ci}
6318a8e1175bSopenharmony_cisupport_build_cmake_custom_config_file () {
6319a8e1175bSopenharmony_ci    support_test_cmake_out_of_source
6320a8e1175bSopenharmony_ci}
6321a8e1175bSopenharmony_ci
6322a8e1175bSopenharmony_ci
6323a8e1175bSopenharmony_cicomponent_build_zeroize_checks () {
6324a8e1175bSopenharmony_ci    msg "build: check for obviously wrong calls to mbedtls_platform_zeroize()"
6325a8e1175bSopenharmony_ci
6326a8e1175bSopenharmony_ci    scripts/config.py full
6327a8e1175bSopenharmony_ci
6328a8e1175bSopenharmony_ci    # Only compile - we're looking for sizeof-pointer-memaccess warnings
6329a8e1175bSopenharmony_ci    make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/user-config-zeroize-memset.h\"' -DMBEDTLS_TEST_DEFINES_ZEROIZE -Werror -Wsizeof-pointer-memaccess"
6330a8e1175bSopenharmony_ci}
6331a8e1175bSopenharmony_ci
6332a8e1175bSopenharmony_ci
6333a8e1175bSopenharmony_cicomponent_test_zeroize () {
6334a8e1175bSopenharmony_ci    # Test that the function mbedtls_platform_zeroize() is not optimized away by
6335a8e1175bSopenharmony_ci    # different combinations of compilers and optimization flags by using an
6336a8e1175bSopenharmony_ci    # auxiliary GDB script. Unfortunately, GDB does not return error values to the
6337a8e1175bSopenharmony_ci    # system in all cases that the script fails, so we must manually search the
6338a8e1175bSopenharmony_ci    # output to check whether the pass string is present and no failure strings
6339a8e1175bSopenharmony_ci    # were printed.
6340a8e1175bSopenharmony_ci
6341a8e1175bSopenharmony_ci    # Don't try to disable ASLR. We don't care about ASLR here. We do care
6342a8e1175bSopenharmony_ci    # about a spurious message if Gdb tries and fails, so suppress that.
6343a8e1175bSopenharmony_ci    gdb_disable_aslr=
6344a8e1175bSopenharmony_ci    if [ -z "$(gdb -batch -nw -ex 'set disable-randomization off' 2>&1)" ]; then
6345a8e1175bSopenharmony_ci        gdb_disable_aslr='set disable-randomization off'
6346a8e1175bSopenharmony_ci    fi
6347a8e1175bSopenharmony_ci
6348a8e1175bSopenharmony_ci    for optimization_flag in -O2 -O3 -Ofast -Os; do
6349a8e1175bSopenharmony_ci        for compiler in clang gcc; do
6350a8e1175bSopenharmony_ci            msg "test: $compiler $optimization_flag, mbedtls_platform_zeroize()"
6351a8e1175bSopenharmony_ci            make programs CC="$compiler" DEBUG=1 CFLAGS="$optimization_flag"
6352a8e1175bSopenharmony_ci            gdb -ex "$gdb_disable_aslr" -x tests/scripts/test_zeroize.gdb -nw -batch -nx 2>&1 | tee test_zeroize.log
6353a8e1175bSopenharmony_ci            grep "The buffer was correctly zeroized" test_zeroize.log
6354a8e1175bSopenharmony_ci            not grep -i "error" test_zeroize.log
6355a8e1175bSopenharmony_ci            rm -f test_zeroize.log
6356a8e1175bSopenharmony_ci            make clean
6357a8e1175bSopenharmony_ci        done
6358a8e1175bSopenharmony_ci    done
6359a8e1175bSopenharmony_ci}
6360a8e1175bSopenharmony_ci
6361a8e1175bSopenharmony_cicomponent_test_psa_compliance () {
6362a8e1175bSopenharmony_ci    # The arch tests build with gcc, so require use of gcc here to link properly
6363a8e1175bSopenharmony_ci    msg "build: make, default config (out-of-box), libmbedcrypto.a only"
6364a8e1175bSopenharmony_ci    CC=gcc make -C library libmbedcrypto.a
6365a8e1175bSopenharmony_ci
6366a8e1175bSopenharmony_ci    msg "unit test: test_psa_compliance.py"
6367a8e1175bSopenharmony_ci    CC=gcc ./tests/scripts/test_psa_compliance.py
6368a8e1175bSopenharmony_ci}
6369a8e1175bSopenharmony_ci
6370a8e1175bSopenharmony_cisupport_test_psa_compliance () {
6371a8e1175bSopenharmony_ci    # psa-compliance-tests only supports CMake >= 3.10.0
6372a8e1175bSopenharmony_ci    ver="$(cmake --version)"
6373a8e1175bSopenharmony_ci    ver="${ver#cmake version }"
6374a8e1175bSopenharmony_ci    ver_major="${ver%%.*}"
6375a8e1175bSopenharmony_ci
6376a8e1175bSopenharmony_ci    ver="${ver#*.}"
6377a8e1175bSopenharmony_ci    ver_minor="${ver%%.*}"
6378a8e1175bSopenharmony_ci
6379a8e1175bSopenharmony_ci    [ "$ver_major" -eq 3 ] && [ "$ver_minor" -ge 10 ]
6380a8e1175bSopenharmony_ci}
6381a8e1175bSopenharmony_ci
6382a8e1175bSopenharmony_cicomponent_check_code_style () {
6383a8e1175bSopenharmony_ci    msg "Check C code style"
6384a8e1175bSopenharmony_ci    ./scripts/code_style.py
6385a8e1175bSopenharmony_ci}
6386a8e1175bSopenharmony_ci
6387a8e1175bSopenharmony_cisupport_check_code_style() {
6388a8e1175bSopenharmony_ci    case $(uncrustify --version) in
6389a8e1175bSopenharmony_ci        *0.75.1*) true;;
6390a8e1175bSopenharmony_ci        *) false;;
6391a8e1175bSopenharmony_ci    esac
6392a8e1175bSopenharmony_ci}
6393a8e1175bSopenharmony_ci
6394a8e1175bSopenharmony_cicomponent_check_python_files () {
6395a8e1175bSopenharmony_ci    msg "Lint: Python scripts"
6396a8e1175bSopenharmony_ci    tests/scripts/check-python-files.sh
6397a8e1175bSopenharmony_ci}
6398a8e1175bSopenharmony_ci
6399a8e1175bSopenharmony_cicomponent_check_test_helpers () {
6400a8e1175bSopenharmony_ci    msg "unit test: generate_test_code.py"
6401a8e1175bSopenharmony_ci    # unittest writes out mundane stuff like number or tests run on stderr.
6402a8e1175bSopenharmony_ci    # Our convention is to reserve stderr for actual errors, and write
6403a8e1175bSopenharmony_ci    # harmless info on stdout so it can be suppress with --quiet.
6404a8e1175bSopenharmony_ci    ./tests/scripts/test_generate_test_code.py 2>&1
6405a8e1175bSopenharmony_ci
6406a8e1175bSopenharmony_ci    msg "unit test: translate_ciphers.py"
6407a8e1175bSopenharmony_ci    python3 -m unittest tests/scripts/translate_ciphers.py 2>&1
6408a8e1175bSopenharmony_ci}
6409a8e1175bSopenharmony_ci
6410a8e1175bSopenharmony_ci
6411a8e1175bSopenharmony_ci################################################################
6412a8e1175bSopenharmony_ci#### Termination
6413a8e1175bSopenharmony_ci################################################################
6414a8e1175bSopenharmony_ci
6415a8e1175bSopenharmony_cipost_report () {
6416a8e1175bSopenharmony_ci    msg "Done, cleaning up"
6417a8e1175bSopenharmony_ci    final_cleanup
6418a8e1175bSopenharmony_ci
6419a8e1175bSopenharmony_ci    final_report
6420a8e1175bSopenharmony_ci}
6421a8e1175bSopenharmony_ci
6422a8e1175bSopenharmony_ci
6423a8e1175bSopenharmony_ci
6424a8e1175bSopenharmony_ci################################################################
6425a8e1175bSopenharmony_ci#### Run all the things
6426a8e1175bSopenharmony_ci################################################################
6427a8e1175bSopenharmony_ci
6428a8e1175bSopenharmony_ci# Function invoked by --error-test to test error reporting.
6429a8e1175bSopenharmony_cipseudo_component_error_test () {
6430a8e1175bSopenharmony_ci    msg "Testing error reporting $error_test_i"
6431a8e1175bSopenharmony_ci    if [ $KEEP_GOING -ne 0 ]; then
6432a8e1175bSopenharmony_ci        echo "Expect three failing commands."
6433a8e1175bSopenharmony_ci    fi
6434a8e1175bSopenharmony_ci    # If the component doesn't run in a subshell, changing error_test_i to an
6435a8e1175bSopenharmony_ci    # invalid integer will cause an error in the loop that runs this function.
6436a8e1175bSopenharmony_ci    error_test_i=this_should_not_be_used_since_the_component_runs_in_a_subshell
6437a8e1175bSopenharmony_ci    # Expected error: 'grep non_existent /dev/null -> 1'
6438a8e1175bSopenharmony_ci    grep non_existent /dev/null
6439a8e1175bSopenharmony_ci    # Expected error: '! grep -q . tests/scripts/all.sh -> 1'
6440a8e1175bSopenharmony_ci    not grep -q . "$0"
6441a8e1175bSopenharmony_ci    # Expected error: 'make unknown_target -> 2'
6442a8e1175bSopenharmony_ci    make unknown_target
6443a8e1175bSopenharmony_ci    false "this should not be executed"
6444a8e1175bSopenharmony_ci}
6445a8e1175bSopenharmony_ci
6446a8e1175bSopenharmony_ci# Run one component and clean up afterwards.
6447a8e1175bSopenharmony_cirun_component () {
6448a8e1175bSopenharmony_ci    current_component="$1"
6449a8e1175bSopenharmony_ci    export MBEDTLS_TEST_CONFIGURATION="$current_component"
6450a8e1175bSopenharmony_ci
6451a8e1175bSopenharmony_ci    # Unconditionally create a seedfile that's sufficiently long.
6452a8e1175bSopenharmony_ci    # Do this before each component, because a previous component may
6453a8e1175bSopenharmony_ci    # have messed it up or shortened it.
6454a8e1175bSopenharmony_ci    local dd_cmd
6455a8e1175bSopenharmony_ci    dd_cmd=(dd if=/dev/urandom of=./tests/seedfile bs=64 count=1)
6456a8e1175bSopenharmony_ci    case $OSTYPE in
6457a8e1175bSopenharmony_ci        linux*|freebsd*|openbsd*) dd_cmd+=(status=none)
6458a8e1175bSopenharmony_ci    esac
6459a8e1175bSopenharmony_ci    "${dd_cmd[@]}"
6460a8e1175bSopenharmony_ci
6461a8e1175bSopenharmony_ci    # Run the component in a subshell, with error trapping and output
6462a8e1175bSopenharmony_ci    # redirection set up based on the relevant options.
6463a8e1175bSopenharmony_ci    if [ $KEEP_GOING -eq 1 ]; then
6464a8e1175bSopenharmony_ci        # We want to keep running if the subshell fails, so 'set -e' must
6465a8e1175bSopenharmony_ci        # be off when the subshell runs.
6466a8e1175bSopenharmony_ci        set +e
6467a8e1175bSopenharmony_ci    fi
6468a8e1175bSopenharmony_ci    (
6469a8e1175bSopenharmony_ci        if [ $QUIET -eq 1 ]; then
6470a8e1175bSopenharmony_ci            # msg() will be silenced, so just print the component name here.
6471a8e1175bSopenharmony_ci            echo "${current_component#component_}"
6472a8e1175bSopenharmony_ci            exec >/dev/null
6473a8e1175bSopenharmony_ci        fi
6474a8e1175bSopenharmony_ci        if [ $KEEP_GOING -eq 1 ]; then
6475a8e1175bSopenharmony_ci            # Keep "set -e" off, and run an ERR trap instead to record failures.
6476a8e1175bSopenharmony_ci            set -E
6477a8e1175bSopenharmony_ci            trap err_trap ERR
6478a8e1175bSopenharmony_ci        fi
6479a8e1175bSopenharmony_ci        # The next line is what runs the component
6480a8e1175bSopenharmony_ci        "$@"
6481a8e1175bSopenharmony_ci        if [ $KEEP_GOING -eq 1 ]; then
6482a8e1175bSopenharmony_ci            trap - ERR
6483a8e1175bSopenharmony_ci            exit $last_failure_status
6484a8e1175bSopenharmony_ci        fi
6485a8e1175bSopenharmony_ci    )
6486a8e1175bSopenharmony_ci    component_status=$?
6487a8e1175bSopenharmony_ci    if [ $KEEP_GOING -eq 1 ]; then
6488a8e1175bSopenharmony_ci        set -e
6489a8e1175bSopenharmony_ci        if [ $component_status -ne 0 ]; then
6490a8e1175bSopenharmony_ci            failure_count=$((failure_count + 1))
6491a8e1175bSopenharmony_ci        fi
6492a8e1175bSopenharmony_ci    fi
6493a8e1175bSopenharmony_ci
6494a8e1175bSopenharmony_ci    # Restore the build tree to a clean state.
6495a8e1175bSopenharmony_ci    cleanup
6496a8e1175bSopenharmony_ci    unset current_component
6497a8e1175bSopenharmony_ci}
6498a8e1175bSopenharmony_ci
6499a8e1175bSopenharmony_ci# Preliminary setup
6500a8e1175bSopenharmony_cipre_check_environment
6501a8e1175bSopenharmony_cipre_initialize_variables
6502a8e1175bSopenharmony_cipre_parse_command_line "$@"
6503a8e1175bSopenharmony_ci
6504a8e1175bSopenharmony_cisetup_quiet_wrappers
6505a8e1175bSopenharmony_cipre_check_git
6506a8e1175bSopenharmony_cipre_restore_files
6507a8e1175bSopenharmony_cipre_back_up
6508a8e1175bSopenharmony_ci
6509a8e1175bSopenharmony_cibuild_status=0
6510a8e1175bSopenharmony_ciif [ $KEEP_GOING -eq 1 ]; then
6511a8e1175bSopenharmony_ci    pre_setup_keep_going
6512a8e1175bSopenharmony_cifi
6513a8e1175bSopenharmony_cipre_prepare_outcome_file
6514a8e1175bSopenharmony_cipre_print_configuration
6515a8e1175bSopenharmony_cipre_check_tools
6516a8e1175bSopenharmony_cicleanup
6517a8e1175bSopenharmony_ciif in_mbedtls_repo; then
6518a8e1175bSopenharmony_ci    pre_generate_files
6519a8e1175bSopenharmony_cifi
6520a8e1175bSopenharmony_ci
6521a8e1175bSopenharmony_ci# Run the requested tests.
6522a8e1175bSopenharmony_cifor ((error_test_i=1; error_test_i <= error_test; error_test_i++)); do
6523a8e1175bSopenharmony_ci    run_component pseudo_component_error_test
6524a8e1175bSopenharmony_cidone
6525a8e1175bSopenharmony_ciunset error_test_i
6526a8e1175bSopenharmony_cifor component in $RUN_COMPONENTS; do
6527a8e1175bSopenharmony_ci    run_component "component_$component"
6528a8e1175bSopenharmony_cidone
6529a8e1175bSopenharmony_ci
6530a8e1175bSopenharmony_ci# We're done.
6531a8e1175bSopenharmony_cipost_report
6532