32165 Commits

Author SHA1 Message Date
Ashish Sharma
b5d87eaa67
fix(mbedtls): update minimum cmake required to 3.10.2 2025-07-02 11:26:47 +05:30
Ashish Sharma
32ae5590eb
feat(component/mbedtls): Add support for RSASSA-PSS with RSA alt
- set RSA padding only when DS peripheral is configured
2025-07-02 11:26:46 +05:30
nilesh.kale
f80458a160
Flatten the submodule 'framework'
For easier maintenance the framework repository is flattened here and
added to the forked branch in source format.
2025-07-02 11:25:32 +05:30
harshal.patil
9f7b965b3b
gcm: Support software fallback for non-AES ciphers in a gcm operation.
When MBEDTLS_HARDWARE_GCM is enabled, we ALT all the GCM functions that are
declared in mbedtls/gcm.h with our H/W port functions, due to which even
if non-AES ciphers such as ARIA, CAMELLIA, BLOWFISH, etc. are selected
for a GCM operation, we perform an AES-GCM operation, thus resulting into
an incorrect calculation.
Thus in such cases we need to fallback to the software definitions of
GCM.

Currently, it is not directly possible to pull in software definitions of GCM
related functions directly due to gcm_alt.h, but this commit renames the
functions by appending `_soft` to their names, thus making them look different
functions in all and thus they are made available to pull in during compilation.

The change is configrable using the config MBEDTLS_GCM_NON_AES_CIPHER_SOFT_FALLBACK.
As this config is enabled by default, building the mbedtls crypto library
(libmbedcrypto.a) with this change increases its size by ~2.5KB.
2025-07-01 09:59:45 +05:30
Frantisek Hrbata
3081b5f28b
initial version of the sbom.yml file
This is an initial version of the sbom.yml file for Espressif's mbedtls.
It's used by the esp-idf-sbom[1] tool to generate an SBOM file in the SPDX
format for esp-idf projects.

[1] - https://github.com/espressif/esp-idf-sbom

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>

fix(sbom): add note about Espressif modifications

Since our mbedtls code is not a pure upstream version, let's add a note
about this in the SBOM manifest description, which will be included in
the generated SPDX file. We used the same approach e.g. for freertos.

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
2025-07-01 09:59:45 +05:30
Laukik Hase
b22b0188b9
cmake: Removed CMake flags for controlling C standard
- `CMAKE_C_EXTENSIONS`: Enable/disable compiler-specific extensions
- `CMAKE_C_STANDARD`: Set C standard (C99, C11)
- These variables (as set in mbedtls) set the C standard to C99
  for ESP-IDF as well, resulting in build errors related to
  `asm volatile`

(cherry picked from commit e39975969d548572a39875ad29abd88b23285f94)
2025-07-01 09:59:44 +05:30
Sachin Parekh
059ef604ce
ecp: Add support for hardware implementation of ECP routines
- ESP32C2 has a hardware ECC accelerator that supports NIST P-192 and NIST P-256 curves,
    which can increase the performance of the point multiplication and point
    verification operation.
  - Provision is also added to fallback to software implementation in
    case the curve is not from the supported curves

- Override ecp_mul_restartable_internal with accelerator
  - Many ECC operations use the internal API ecp_mul_restartable_internal
    instead of the public API mbedtls_ecp_mul for point multiplication.
    This will improve the performance of all those parent operations as
    well

(cherry picked from commit 0ecb27b9d88059e8980c8ae6e111283f5f2859f8)
2025-07-01 09:59:44 +05:30
Mahavir Jain
937836545f
bignum: add provision for combined software and hardware MPI approach
For exponential mod (API mbedtls_mpi_exp_mod) operation, some ESP target
chips needs to have ability for both hardware and software implementation.

Hardware implementation provided performance advantage but it can only
support upto 3072 bit operations (e.g., ESP32-C3) and hence we fallback
to software implementation in such cases (e.g., 4096 bit operations).

Earlier this was handled using linker "--wrap" flag but that does not
work in all scenarios as API `mbedtls_mpi_exp_mod` is being used in
same tranlation (compilation unit).

This approach was found to be next best option with minimal changes in
mbedTLS library.

(cherry picked from commit ab3a845107377c6cdf148f86015cad94434a1f2e)
2025-07-01 09:59:44 +05:30
Angus Gratton
267c0a4ea5
mbedtls: Re-apply MBEDTLS_BIGNUM_ALT & related macros for custom bignum functions
(IDF-specific patch.)

(cherry picked from commit f859b9bc7579246703446c158270ae038442351c)
2025-07-01 09:51:36 +05:30
minosgalanakis
c765c831e5
Merge pull request #1373 from Mbed-TLS/mbedtls-3.6.4rc0-pr
Mbedtls 3.6.4rc0
mbedtls-3.6.4
2025-06-25 20:56:00 +01:00
Minos Galanakis
59e8b3a6b0 Added generated files
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-25 14:18:23 +01:00
Minos Galanakis
5374262f3b Version bump 3.6.4
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-25 14:07:55 +01:00
Minos Galanakis
c52f68fd21 Assemble ChangeLog
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-25 14:07:55 +01:00
Gilles Peskine
4cbf802231 Properly initialize SSL endpoint objects
In some cases, we were calling `mbedtls_test_ssl_endpoint_free()` on an
uninitialized `mbedtls_test_ssl_endpoint` object if the test case failed
early, e.g. due to `psa_crypto_init()` failing. This was largely harmless,
but could have caused weird test results in case of failure, and was flagged
by Coverity.

Use a more systematic style for initializing the stack object as soon as
it's declared.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-25 14:07:55 +01:00
Gilles Peskine
ae9a5e86f3 Fix accidentally skipped test assertion
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-25 14:07:55 +01:00
Minos Galanakis
f36277558a Merge remote-tracking branch 'restricted/mbedtls-3.6-restricted' into mbedtls-3.6.4rc0-pr
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-23 18:52:17 +01:00
Ronald Cron
3527ea9b78
Merge pull request #10243 from ronald-cron-arm/mbedtls-3.6-release-sync
The PR is based on mbedtls-3.6 HEAD and the merge queue is empty. No need to go through the merge queue, merging directly.
2025-06-23 11:51:59 +02:00
Ronald Cron
bad1679623 Update framework pointer (release-sync)
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2025-06-23 09:32:12 +02:00
David Horstmann
54ceaf7a53
Merge pull request #10200 from aslze/mbedtls-3.6
[3.6] Fix build C++ apps with MSVC
2025-06-19 14:25:50 +00:00
Ronald Cron
7df899211a fix: additional MSVC v142 build issue with tls1.3 configuration enabled.
Signed-off-by: Cesar Cruz <cesar.cruz@philips.com>
Signed-off-by: ccrugoPhilips <cesar.cruz@philips.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2025-06-18 10:13:54 +02:00
David Horstmann
a84be59757
Merge pull request #1366 from gilles-peskine-arm/base64-decode-clean-3.6
Backport 3.6: mbedtls_base64_decode: fix sloppiness
2025-06-17 14:55:39 +01:00
Ronald Cron
d1f51696a6 Remove blank line
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2025-06-16 11:08:46 +02:00
Gilles Peskine
3c9ad42719
Merge pull request #1367 from gilles-peskine-arm/aesni_has_support-volatile-3.6
Backport 3.6: Fix race condition in mbedtls_aesni_has_support
2025-06-13 23:20:28 +02:00
Manuel Pégourié-Gonnard
d593c54b3c
Merge pull request #10215 from felixc-arm/gcc-15-warning-3.6
[3.6] Fix GCC 15 warning 'Wunterminated-string-initialization'
2025-06-13 12:34:55 +00:00
Felix Conway
b8d14734fd Simplify changelog
Signed-off-by: Felix Conway <felix.conway@arm.com>
2025-06-13 09:33:24 +01:00
Gilles Peskine
853cfbdced Add a note about processor memory reordering
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-12 18:30:45 +02:00
Felix Conway
80ca13f07d Add changelog
Signed-off-by: Felix Conway <felix.conway@arm.com>
2025-06-12 13:28:26 +01:00
Felix Conway
766be1f8f4 Replace __attribute__((nonstring)) with macro MBEDTLS_ATTRIBUTE_UNTERMINATED_STRING
This macro applies __attribute__((nonstring)) when the compiler supports
it

Signed-off-by: Felix Conway <felix.conway@arm.com>
2025-06-12 11:13:33 +01:00
Gilles Peskine
51dccfb2a6 Improve some explanations
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-11 18:47:31 +02:00
Gilles Peskine
03303d88fb Don't mutate dst_size
This lead to `dst_size` not having the intended value in subsequent code.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-11 18:24:26 +02:00
Felix Conway
2e1399f1e1 Add __attribute__ ((nonstring)) to remove unterminated-string-initialization warning
Signed-off-by: Felix Conway <felix.conway@arm.com>
2025-06-11 16:04:30 +01:00
Gilles Peskine
f5db3e9436 Note that GCM is also impacted
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-11 10:45:41 +02:00
Gilles Peskine
a79525239f
Merge pull request #1359 from Mbed-TLS/bugfix_1351_1352_1353_lms_drivers_3.6bp
[3.6 Backport]Bugfix: lms/lmots driver hardening.
2025-06-10 19:08:15 +02:00
Manuel Pégourié-Gonnard
7ed3653c57
Merge pull request #1363 from gilles-peskine-arm/3.6-restricted-merge-20250606
Merge mbedtls-3.6 into mbedtls-3.6-restricted
2025-06-10 11:01:11 +02:00
Manuel Pégourié-Gonnard
cae443405e
Merge pull request #1347 from mpg/fix-asn1-store-named-data-null-deref-3.6
Backport 3.6: Fix asn1 store named data null deref
2025-06-10 09:50:34 +02:00
Manuel Pégourié-Gonnard
4c26d7d54c
Merge pull request #10179 from gilles-peskine-arm/union-initialization-gcc15-driver-checks-3.6
Backport 3.6: Check union initialization portably
2025-06-10 07:43:10 +00:00
Gilles Peskine
55d211388a Adjust test case with invalid base64
Now that Base64 validates the number of trailing equals, adjust the PEM test
case that has a Base64 payload with a wrong number of trailing equals, where
`mbedtls_pem_read_buffer()` now returns a different error code. I'm not sure
what the exact intent of the test was, so add a variant with trailing equals
as well.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-10 09:42:03 +02:00
Gilles Peskine
8c67ac0f7f Fix race condition in mbedtls_aesni_has_support
Fix a race condition in `mbedtls_aes_ni_has_support()` with some compilers.
A compiler could hoist the assignment `done = 1` above the assignment to `c`,
in which case if two threads call `mbedtls_aes_ni_has_support()` at almost
the same time, they could be interleaved as follows:

    Initially: done = 0, c = 0

    thread A                thread B
    if (!done)
      done = 1;                                     # hoisted
                            if (!done)
                                return c & what;    # wrong!
      c = cpuid();
    return c & what

This would lead to thread B using software AES even though AESNI was
available. This is a very minor performance bug. But also, given a very
powerful adversary who can block thread A indefinitely (which may be
possible when attacking an SGX enclave), thread B could use software AES for
a long time, opening the way to a timing side channel attack.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-09 23:48:34 +02:00
Gilles Peskine
13cc0c2122 mbedtls_base64_decode: test dst=NULL with dlen>0
The documentation explicitly says that `*dst = NULL` **or** `dlen = 0`
triggers tell-me-the-output-length mode.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-09 23:08:42 +02:00
Gilles Peskine
e7ed8c4c2f Explain some aspects of the tests
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-09 23:08:40 +02:00
Gilles Peskine
2b3d6a8f28 mbedtls_base64_decode: insist on correct padding
Correct base64 input (excluding ignored characters such as spaces) consists
of exactly 4*k, 4*k-1 or 4*k-2 digits, followed by 0, 1 or 2 equal signs
respectively.

Previously, any number of trailing equal signs up to 2 was accepted, but if
there fewer than 4*k digits-or-equals, the last partial block was counted in
`*olen` in buffer-too-small mode, but was not output despite returning 0.

Now `mbedtls_base64_decode()` insists on correct padding. This is
backward-compatible since the only plausible useful inputs that used to be
accepted were inputs with 4*k-1 or 4*k-2 digits and no trailing equal signs,
and those led to invalid (truncated) output. Furthermore the function now
always reports the exact output size in buffer-too-small mode.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-09 23:01:21 +02:00
Minos Galanakis
255c492dab Added CVE's to ChangeLogs
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-08 23:10:58 +01:00
Minos Galanakis
df2f0aae81 lms.c: Updated documentation
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-06 14:35:07 +01:00
Minos Galanakis
58a4479ace test_suite_lms.data: Updated comments
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-06 14:35:07 +01:00
Gilles Peskine
7df273bb34 Merge remote-tracking branch 'mbedtls-3.6' into mbedtls-3.6-restricted 2025-06-06 10:46:03 +02:00
Gilles Peskine
84999d1a7b Fix mbedtls_base64_decode() accepting invalid inputs with 4n+1 digits
The last digit was ignored.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-05 16:15:41 +02:00
Gilles Peskine
683a46e6c1 mbedtls_base64_decode: assert sloppy behavior with bad number of =
Add unit tests covering cases where the number of digits plus equal signs is
not a multiple of 4. These are invalid inputs, but they are currently
accepted as long as the number of equal signs is at most 2.

The tests assert the current behavior, not behavior that is desirable.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-05 16:15:41 +02:00
Gilles Peskine
715bbf3e0c mbedtls_base64_decode: test the reported output length
Reinforce the unit test for `mbedtls_base64_decode()` with valid inputs to
systematically call the function with a smaller output buffer and with an
empty output buffer. Assert the reported necessary output length in those
cases.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-06-05 16:15:41 +02:00
Minos Galanakis
c7beb847c9 test_suite_lms: Added negative test for corrupted Merkle path
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-05 09:23:59 +01:00
Minos Galanakis
b72573853a test_suite_lms: Added a test for importing invalid sized key
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2025-06-05 09:23:59 +01:00