Commit Graph

45 Commits (mbed-os-6.17.0-rc3)

Author SHA1 Message Date
Chun-Chieh Li 9345c8a014 Mbed TLS: Fix wrong MPI N in ECP Curve448 curve
In loading Curve448, MPI N is in uninitialized state and its sign flag N.s isn't initialized to 1.
This is fixed by following:
https://github.com/Mbed-TLS/mbedtls/pull/5811
2022-05-24 16:24:46 +08:00
Chun-Chieh Li 56f4b4cd29 Mbed TLS: Fix compile error with ECP alternative
Fix un-paired parenthesis when MBEDTLS_ECP_RANDOMIZE_MXZ_ALT is enabled
2022-04-08 17:24:55 +08:00
Lingkai Dong db8852c5d8 CMake: connectivity: Guard unit test directories
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.
2021-09-20 16:28:54 +01:00
Rajkumar Kanagaraj f5002269c0 CMake: Limit the mbed-stubs-mbedtls to required dependency mocks 2021-07-12 07:18:41 -07:00
Rajkumar Kanagaraj d57ed8d95a CMake: Move mbedtls stub headers to the mbedtls doubles dir
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.
2021-07-12 07:19:04 -07:00
Rajkumar Kanagaraj ef7699d824 CMake: Update netsocket, lorawan unittest to use mbed-stubs-mbedtls
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.
2021-07-12 07:18:41 -07:00
Rajkumar Kanagaraj 66019cb80e CMake: Move mbedtls stubs to the mbedtls dir
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.
2021-07-12 07:18:41 -07:00
Jaeden Amero 270ea5deb7
Merge pull request #14815 from LDong-Arm/test_psa_k64f_k66f
Enable PSA tests on K64F/K66F and fix missing PSA Crypto init in TLSSocketWrapper
2021-06-30 15:20:05 +01:00
Hari Limaye f95052cf6f CMake: Require TEST_SOURCES in greentea CMake file
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.
2021-06-29 13:33:42 +01:00
Lingkai Dong fbca8e9c84 platform_mbed.h: Fix and align EXPERIMENTAL_API check
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.
2021-06-28 11:46:57 +01:00
Martin Kojtal fd7e33b361
Merge pull request #14772 from LDong-Arm/mbedtls_timing
Improve implementation of Mbed TLS timing
2021-06-15 13:09:49 +02:00
Lingkai Dong 49163f0f33 Move Mbed TLS self tests to a separate configuration
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.
2021-06-15 10:50:14 +01:00
Lingkai Dong d6f825ebf0 mbedtls: Run mbedtls_timing_self_test if MBEDTLS_TIMING_C
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.
2021-06-14 17:49:17 +01:00
Lingkai Dong ca719a96a8 mbedtls: Use LowPowerTimeout for mbedtls_set_alarm() if available
The function `mbedtls_set_alarm()` is only precise to seconds, so
`LowPowerTimeout` is enough and saves power.
2021-06-14 17:49:17 +01:00
Lingkai Dong e16f59a2ee timing_mbed.cpp: Check MBEDTLS_TIMING_ALT
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.
2021-06-14 17:48:42 +01:00
Lingkai Dong 17ae051075 mbedtls: Add full platform implementation of timing
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.
2021-06-14 17:29:19 +01:00
Lingkai Dong f96f98e60e mbedtls: Use LowPowerTimer/Timer for timing
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.
2021-06-14 17:25:08 +01:00
Martin Kojtal 1606b00186
Merge pull request #14741 from boraozgen/trng-def-checks
MbedTLS: Add definition checks for TRNG
2021-06-14 12:05:16 +02:00
Jaeden Amero 87d1992f4f mbedtls: Rename Mbed timing implementation
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
2021-06-10 17:02:28 +01:00
Jaeden Amero b8781e527b mbedtls: Add an alt implementation of timing
Implement the MBEDTLS_TIMING_ALT interface for Mbed OS. This
implementation is sufficient to run the Mbed TLS benchmarking
application.
2021-06-09 17:43:18 +01:00
Bora Özgen eabc477f3c MbedTLS: Add definition checks for TRNG
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.
2021-06-07 15:40:46 +02:00
Martin Kojtal a2d62f9597
Merge pull request #14652 from Patater/upgrade-mbedtls-2.25.0
tls: Upgrade to Mbed TLS v2.25.0
2021-05-31 11:36:26 +02:00
Jaeden Amero f275a83593 tls: Add fix for Mbed TLS configuration issue
Until we have a fix for https://github.com/ARMmbed/mbedtls/issues/4512,
we need to patch the fix during import time. Otherwise, we run into
linker errors when PSA attempts to use RSA key generation, which we've
excluded.

This patch is extracted from
https://github.com/ARMmbed/mbedtls/pull/4513
2021-05-14 10:51:04 +01:00
Jaeden Amero 9360e0fe82 tls: Upgrade to Mbed TLS v2.25.0 2021-05-12 15:49:36 +01:00
Jaeden Amero 2300a56863 mbedtls: Don't attempt to use default_random_seed
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"
2021-05-04 13:56:54 +01:00
Lingkai Dong 86e7bc559b CMake: Fix Mbed TLS compilation for Cortex-M0/0+/1/M23
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.

Fixes ARMmbed/mbed-os-example-lorawan#220
2021-04-15 11:04:40 +01:00
Lingkai Dong 1f4f6dd0b6 Mbed TLS importer: don't import unnecessary files
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.
2021-02-25 14:02:57 +00:00
Lingkai Dong 241b062cdf Update .gitignore for Mbed TLS importer
The directory `mbed-tls-lib` previously in `.gitignore` no longer
exists. Instead, we can simply ignore the entire TARGET_IGNORE.
2021-02-25 14:02:57 +00:00
Lingkai Dong 410a1bad6b Import mbedtls-2.24 and Mbed PSA Service (non-TFM)
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.
2021-02-25 14:02:55 +00:00
Lingkai Dong e0d2c3d03a Fix paths in Mbed TLS importer
Note: Now we need to export common.h to the include path, because
this header is now also needed by PSA Crypto service.
2021-02-25 14:02:54 +00:00
Lingkai Dong e3641576d0 Move hash_wrappers.c to platform subdirectory
hash_wrappers.c is specific to Mbed OS, moving it into platform
as its original directory is for imported Mbed TLS source only.
2021-02-25 14:02:54 +00:00
Lingkai Dong 9e48b782b9 Add copyright header to hash_wrappers.c 2021-02-25 14:02:54 +00:00
Rajkumar Kanagaraj 6824b14e48 CMake: rename greentea test macro 2021-02-02 07:43:40 -08:00
Hugues Kamba 9a1c24e254 CMake: Add support for Mbed TLS Greentea tests
The Mbed TLS Greentea tests can now be built with CMake.
2021-01-25 10:48:15 +00:00
Devaraj Ranganna 61009ba05a tests: Limit PSA crypto tests to Arm-v7M targets
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>
2021-01-14 11:56:04 +00:00
Devaraj Ranganna 9186fe57b2 tests: Fix test_crypto_asymmetric_encrypt_decrypt
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>
2021-01-14 11:52:36 +00:00
Hugues Kamba bf84a5b329 CMake: Rename CMake targets
* mbed-os renamed mbed-core
* mbed-os-<COMPONENT> renamed mbed-<COMPONENT>
2020-11-06 17:25:22 +00:00
Hugues Kamba fa98689639 CMake: Componentize Mbed OS into multiple CMake targets (#13732)
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>
2020-11-06 17:25:21 +00:00
Hugues Kamba fbaeae5a8e CMake: Fix failure due to MbedTLS rdir relocation 2020-11-06 17:25:19 +00:00
Harrison Mutai 4fad1112e5 Add SPDX license identifier to Arm files
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.
2020-10-15 10:47:27 +01:00
George Psimenos bf6693a204 Create mbed_lib.json for mbedtls target code 2020-08-11 11:32:09 +01:00
George Psimenos 6a477619b9 Move mbedtls target-specific code 2020-08-11 11:32:09 +01:00
George Psimenos 54d8fe74ca Update mbedtls paths 2020-08-11 11:32:08 +01:00
George Psimenos bf3cf13cde Move mbedtls greentea tests 2020-08-11 11:32:08 +01:00
George Psimenos c8cc5bd180 Move mbedtls 2020-08-11 11:32:08 +01:00