When unit tests or unit test stubs get added as CMake targets, they
becomes part of the "all" target and get compiled when building the
whole project. When building greentea tests we need to disable unit
tests and stubs to avoid unnecessary compilation and errors.
Previously all the mbedtls stubs headers under mbed-stubs-headers,
so this PR move all mbedtls stubs headers under
mbedtls/tests/UNITTESTS/double directory and update CMake to include
stubs headers into mbed-stubs-mbedtls library to make mbedtls stubs
to be self-contained.
Update netsocket and lorawan unit tests to link with a mbed-stubs-mbedtls
library that it depends on instead of link with mbed-stubs
which is a group of stubs libraries.
Move the connectivity mbedtls stubs into the connectivity/mbedtls
component directory. So we can avoid duplicating the mbed-os source
tree in a central UNITTESTS folder.
Assumption that greentea test file is always named main.cpp is
incorrect. Updated mbed_greentea_add_test() macro to make TEST_SOURCES
parameter compulsory, which is used to specify greentea test
file(s). This allows tests to use C, or have a different name.
Therefore also updated all pre-existing greentea test CMake files to
explicity add main.cpp to TEST_SOURCES.
Some of the lines in `platform_mbed.h` only have `FEATURE_PSA`
checked, which is always set for Mbed OS PSA targets but the PSA
APIs are not actually available unless `FEATURE_EXPERIMENTAL_API`
is also enabled. To fix this and improve readability, group all
PSA-related lines and check both macros.
We potentially save flash space by not enabling Mbed TLS self-tests
by default. A new test config file, TESTS/configs/mbedtls.json, is
provided to enable self tests. This newly created JSON file also
enables timing in Mbed TLS so timing gets tested.
This allows us to verify the support for Mbed TLS timing on Mbed OS.
Note: The macros MBEDTLS_TIMING_C and MBEDTLS_TIMING_ALT are not
enabled by default and need to be additionally enabled to run this
test.
Do not compile the Mbed implementation of Mbed TLS unless
MBEDTLS_TIMING_ALT is defined. This prevents a macro check error on
devices that do not have LPTICKER or USTICKER when Mbed TLS timing
is not enabled.
When MBEDTLS_TIMING_C and MBEDTLS_TIMING_ALT are enabled,
the Arm Compiler generates errors like the following (one for
each missing symbol):
Error: L6218E: Undefined symbol mbedtls_timing_get_delay
Reason:
The function `mbedtls_timing_self_test()` in the Mbed TLS default
`timing.c` always gets compiled, if MBEDTLS_SELF_TEST is defined.
And MBEDTLS_SELF_TEST is always defined, as we have a Greentea test
to run some of the Mbed TLS self tests. (In the future we should try
not to enable MBEDTLS_SELF_TEST except for tests, but it requires
a rework in our test flow.)
`mbedtls_timing_self_test()` tests (calls) the full API declared in
`timing.h`, and the ARM Compiler requires all symbols referenced by
all functions to be defined, even those not used by the final
application. This is unlike GCC_ARM which resolves what are required.
Solution:
To fix the "undefined symbol" errors, we add an implementation of
`mbedtls_timing_get_timer()` based on Mbed OS `LowPowerTimer` or
`Timer` (depending on which one is available), and copy Mbed TLS's
default `mbedtls_timing_set_delay()` and `mbedtls_timing_get_delay()`
which are built on top of `mbedtls_timing_get_timer()`. This will also
benefit user applications that need to enable timing in Mbed TLS.
Previously we used `gettimeofday()` for Mbed TLS timing, but its
implementation provided by Mbed OS is only precise to seconds. The
microsecond component of the output `struct timeval` is always set
to zero. But Mbed TLS requires millisecond precision.
To provide required timing precision, switch to use `LowPowerTicker`
or (microsecond) `Ticker`. `LowPowerTicker` is preferred as it saves
power and Mbed TLS does not require microsecond precision.
We get a linker warning with the recently added timing module
implementation for Mbed. This is because there is Mbed TLS also ships a
file called timing.c, which we are including in Mbed OS also. With CLI
1, we get an error about unique object files because of the similarly
named implementation files.
Object file timing.o is not unique! It could be made from: mbed-os/connectivity/mbedtls/source/timing.c mbed-os/connectivity/mbedtls/platform/src/timing.cpp
Rename the Mbed timing module implementation to timing_mbed.cpp to avoid
this naming conflict.
Fixes: b8781e527b ("mbedtls: Add an alt implementation of timing")
Fixes#14759
The compiler gave redefinition warnings if
MBEDTLS_ENTROPY_HARDWARE_ALT is defined in the the compile
definitions. A check is added to prevent this warning.
Don't attempt to use default_random_seed unless both PSA and Experimental API
support are enabled. This prevents errors when the Mbed TLS NV Seed feature is
being used on platforms that have PSA enabled by default, but not Experimental
API support by default.
[DEBUG] Output: compilation terminated.
[ERROR] In file included from ./mbed-os/connectivity/mbedtls/include/mbedtls/config.h:31,
from ./mbed-os/connectivity/mbedtls/include/mbedtls/entropy.h:28,
./mbed-os/connectivity/mbedtls/platform/inc/platform_mbed.h:26:10: fatal error: default_random_seed.h: No such file or directory
26 | #include "default_random_seed.h"
Due to a known issue in Mbed TLS's architecture determination
(ARMmbed/mbedtls#1077), we get the error
error: inline assembly requires more registers than available
when compiling `bignum.c` for Cortex-M0/0+/1/M23 which do not have
the macro `__thumb2__` set by the compiler.
The workaround is to define the macro `MULADDC_CANNOT_USE_R7` which
is already defined by Mbed CLI 1 but missing in our CMake support.
FixesARMmbed/mbed-os-example-lorawan#220
The Mbed TLS importer accidentally imports Makefile and .gitignore
from Mbed TLS's `library/` directory. This commit restricts the
pattern to .h and .c files only, and removes the unnecessary files.
Files have been automatically imported by setting MBED_TLS_RELEASE to
mbedtls-2.24.0 in connectivity/mbedtls/tools/importer/Makefile and
running `make` in that directory.
The PSA crypto tests in
connectivity/mbedtls/tests/TESTS/mbedtls/sanity/main.cpp are only
supported for Arm-v7M PSA targets. For Arm-v8M PSA targets, crypto
regression tests provided by TF-M are used. Refer to
https://github.com/ARMmbed/mbed-os-tf-m-regression-tests for more
information.
Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>
The test `test_crypto_asymmetric_encrypt_decrypt` was incorrectly
setting the key usage flags. The key usage is updated to support both
encryption and decryption.
Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>
Aside from the core mbed-os CMake target, a number of targets have been created so they can optionally be included by application executables that require them using `target_link_libraries()`.
Co-authored-by: Martin Kojtal <martin.kojtal@arm.com>
Co-authored-by: Rajkumar Kanagaraj <rajkumar.kanagaraj@arm.com>
Add license identifier to files which Arm owns the copyright to,
and contain either BSD-3 or Apache-2.0 licenses. This is to address
license errors raised by scancode analysis.