Commit Graph

7218 Commits

Author SHA1 Message Date
Gilles Peskine
137b5b776d Simplify MBEDTLS_TIMING_C to use mbedtls_ms_time()
Don't ship two slightly different wheels.

This reduces our platform adherence by using only `clock_gettime()` in the
library and not `gettimeofday()` as well.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-19 16:53:52 +01:00
Gilles Peskine
86eac795c9 Have MBEDTLS_TIMING_C require MBEDTLS_HAVE_TIME
Nowadays, the timing module just builds on a function that provides a timer
with millisecond resolution. In terms of platform requirements, this is
almost exactly equivalent to `mbedtls_ms_time()`
provides (`mbedtls_ms_time()` is arguably a little stronger because it is
supposed to last longer than a single timer object, but an application could
start a timer when it starts, so there's no real difference.) So it's a bit
silly that `timing.c` essentially reimplements this. Rely on
`mbedtls_ms_time()` instead.

This is an API break because in Mbed TLS 4.0, it was possible to enable
`MBEDTLS_TIMING_C` without `MBEDTLS_HAVE_TIME`. However, `timing.c` only
provided an implementation for Windows and Unix-like platforms, and on those
platforms, it is very likely that the default implementation of
`MBEDTLS_HAVE_TIME` would also work. (The main exception would be a platform
that has the traditional Unix function `gettimeofday()`, but not the 1990s
novelty `clock_gettime()`.) So make this an official requirement, as a
belated change that really should have gone into 4.0 if we'd taken the time
to dig into it.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-19 16:53:52 +01:00
Valerio Setti
2a72766d75 Merge pull request #10570 from valeriosetti/issue10349
mbedtls 4.x does not expose mbedtls_ecp_curve_list()
2026-02-03 11:01:11 +00:00
David Horstmann
d0bff58379 Merge pull request #10514 from ng-gsmk/development
mbedtls_ssl_get_alert(): getter for fatal alerts
2026-01-28 16:49:09 +00:00
Valerio Setti
476a2edea7 library: extend mbedtls_ssl_iana_tls_group_info_t structure
Add new field that tells if the corresponding group is supported or not
in the current build.

Test function "test_mbedtls_ssl_get_supported_group_list" is extended
to verify this new feature.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-28 10:52:07 +01:00
Valerio Setti
9b49d5dbde library: ssl: fix documentation of IANA TLS group info
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-27 17:56:34 +01:00
Valerio Setti
4f1e4fba80 library: ssl: make the list of "TLS ID" <-> "group name" public when possible
This is only done when MBEDTLS_DEBUG_C is declared in order not to inflate
the library size.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-27 00:51:35 +01:00
Valerio Setti
fb317afa9f library: ssl: rework macro to define known TLS ID <-> group name list
- let the macro be an initializer for the array of known TLS IDs, not
  a variable declarator;
- last item's group name is NULL, not an empty string
- change then name of the macro from MBEDTLS_TLS_ID_GROUP_NAME_TABLE to
  MBEDTLS_SSL_IANA_TLS_GROUPS_INFO
- define a new public structure "mbedtls_ssl_iana_tls_group_info_t" to
  hold each element of the table and that can be used the go over the
  list from user code.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-27 00:36:17 +01:00
Nico Geyso
8a3bcb1434 Fix coding style conventions for mbedtls_ssl_context
Signed-off-by: Nico Geyso <ng@gsmk.de>
2026-01-26 15:38:50 +01:00
ng-gsmk
15c68993cb Apply suggestions from code review
Co-authored-by: Ronald Cron <ronald.cron@arm.com>
Signed-off-by: ng-gsmk <ng@gsmk.de>
2026-01-26 13:07:26 +01:00
Valerio Setti
7ca3c602b7 library: ssl: add macro for allocating a TLS-ID <-> group-name table
Being a macro allow the table to be instatiated only when/if necessary
by the consuming code.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-26 10:48:01 +01:00
Valerio Setti
6c5a9f04df library: ssl: improve/fix documentation of group related functions
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-22 17:04:46 +01:00
Valerio Setti
1ab51732e2 library: ssl: improve documentation of mbedtls_ssl_conf_groups()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-22 09:43:18 +01:00
Valerio Setti
0c8b25a684 library: ssl: add public function to retrieve the list of supported groups
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-22 09:43:17 +01:00
Ben Taylor
c23592d7ee Add improvements to code comments and docs
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-01-12 08:19:07 +00:00
Ben Taylor
085aef59ca Change function name from mbedtls_pk_key_type_to_string to mbedtls_x509_pk_type_as_string
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-01-12 08:19:07 +00:00
Ben Taylor
837a3cec40 rename function
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-01-12 08:19:07 +00:00
Ben Taylor
f9b95cedaa Fix style issues
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-01-12 08:19:07 +00:00
Ben Taylor
2481daa309 Replace mbedtls_pk_get_name with pk_key_type_to_string
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2026-01-12 08:19:07 +00:00
Valerio Setti
ebbaca0a99 library: debug: adjust guards for "mbedtls_debug_print_crt"
Keep MBEDTLS_PK_WRITE_C as guard only for "debug_print_pk" but let
"mbedtls_debug_print_crt" to work also when MBEDTLS_PK_WRITE_C is disabled.
In this case the only public key won't be printed, but the rest of the
certificate will be.

This commit also updates test coverage by duplicating test cases: now there
will be one case for when MBEDTLS_PK_WRITE_C is enabled and another one
for !MBEDTLS_PK_WRITE_C.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-08 10:32:57 +01:00
Valerio Setti
2af638a177 library: debug: fix print format in mbedtls_debug_print_buf_ext()
%zu creates problem in MinGW testing. Use MBEDTLS_PRINTF_SIZET intead.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-08 10:32:57 +01:00
Valerio Setti
d040eb823e include: debug: fix guards for MBEDTLS_SSL_DEBUG_CRT
Guards for "mbedtls_debug_print_crt()" were updated in previous commit,
but those changes were not applied to MBEDTLS_SSL_DEBUG_CRT therefore
causing build failures in the CI. This commit fixes the problem.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2026-01-08 10:32:57 +01:00
Ben Taylor
23aad2cdad Replace references of mbedtls_ecp_set_max_ops with psa_interruptible_set_max_ops as it is now internal
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-12-23 16:11:49 +00:00
Nico Geyso
13200ab116 Fix more C code style issues
Signed-off-by: Nico Geyso <ng@gsmk.de>
2025-12-10 19:37:07 +01:00
Nico Geyso
f9a734f2b7 Fix C code style issues
Signed-off-by: Nico Geyso <ng@gsmk.de>
2025-12-10 19:37:07 +01:00
Nico Geyso
d589854611 mbedtls_ssl_get_alert(): getter for fatal alerts
Even though the TLS RFCs do not mandate libraries to expose *Error
Alerts* (as defined in RFC8446 6.2 for TLS 1.3 and in RFC5246 7.2.2 for
TLS 1.2) to the user, there are use cases when it is handy to get the
actual last received fatal error instead of a generic one. For instance
this enables the user to differ between received fatal errors in case
`mbedtls_ssl_handshake()`, `mbedtls_ssl_handshake_step()` or
`mbedtls_ssl_read()` returned `MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE`.

This changesets stores the last incoming fatal alert in
`mbedtls_ssl_context` and provides `mbedtls_ssl_get_alert()` as a getter
for retrieving it. Another option would be to provide a callback
mechanisms for all kinds of alerts (not only fatals) but for simplicity
I discarded this option.

Signed-off-by: Nico Geyso <ng@gsmk.de>
2025-12-10 19:37:07 +01:00
Manuel Pégourié-Gonnard
5341c86877 Add comments for remaining internal includes
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-12-02 12:35:20 +01:00
Manuel Pégourié-Gonnard
d6551eaaa6 Add comment about internal crypto include
Besides using an internal crypto header, error.h is arguably the wrong
place: this file's docstring says it's about "Error to string
translation", quite unrelated to the things we use from error_common.h.
This is not surprising given the history, but no longer makes sense
today.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-12-01 11:06:02 +01:00
Manuel Pégourié-Gonnard
53c511578a x509: rm useless private include in public header
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-12-01 10:04:11 +01:00
Manuel Pégourié-Gonnard
59c9ebfaae ssl: rm useless private includes in public headers
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-12-01 10:04:06 +01:00
Luc Schrijvers
ffc2606bf2 Use GNUInstallDirs CMAKE_INSTALL_INCLUDEDDIR path for headers installation
Signed-off-by: Luc Schrijvers <begasus@gmail.com>
2025-10-24 12:50:51 +02:00
Gilles Peskine
24d058bc6c Enable checks for bad options in the config file
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-09-24 17:20:35 +02:00
Gilles Peskine
67f54d2213 Have the definition of MBEDTLS_CONFIG_VERSION uncommented by default
Checking through the history in https://github.com/Mbed-TLS/mbedtls/pull/4589,
this seems to have been what we intended from the start. But we couldn't do
it yet because the library version was still 2.x while the config version
was already 3.0, so we temporarily commented out the definition in
1cafe5ce20. But then we forgot to uncomment
it during the release since it wasn't part of any process.

Thinking about it independently of the history, I think it makes more sense
to have it uncommented by default. That way, if someone copies the config
from a given version and then keeps it around, they'll get the compatibility
mode for that version.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-09-19 10:52:35 +02:00
Ronald Cron
46acbcda84 Merge pull request #10404 from gilles-peskine-arm/config-version-4.0
Increment config version for the new product major version
2025-09-18 09:59:08 +00:00
Gilles Peskine
ff5d117df8 Increment config version for the new product major version
Since we're making incompatible changes to the configuration, we really
should advance the configuration version.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-09-17 21:18:39 +02:00
Ronald Cron
3091e40774 Remove usage of old crypto options in public headers
The remaining occurences were related to
dead code.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2025-09-17 16:06:31 +02:00
Ronald Cron
4fe3760a27 Cleanup following the removal of MBEDTLS_BIGNUM_C option
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2025-09-16 15:53:43 +02:00
Ronald Cron
feb5e26619 Cleanup following the removal of MBEDTLS_ECP_DP_.*_ENABLED options
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2025-09-16 15:53:43 +02:00
Ronald Cron
2ad1e5c1a2 Cleanup following the removal of MBEDTLS_ECJPAKE_C option
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2025-09-16 15:53:43 +02:00
Ronald Cron
3c6bbddfd4 Cleanup following the removal of MBEDTLS_ECDSA_C option
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2025-09-16 15:53:43 +02:00
Ronald Cron
a19ee2819e Cleanup following the removal of MBEDTLS_ECDH_C option
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2025-09-16 15:53:43 +02:00
Ronald Cron
919a1e4e22 Cleanup following the removal of RSA legacy options
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2025-09-16 15:53:43 +02:00
Ronald Cron
0dd31fe523 Introduce MBEDTLS_SSL_NULL_CIPHERSUITES
The support for TLS ciphersuites without
encryption does not rely anymore on the
MBEDTLS_CIPHER_NULL_CIPHER feature of
the cipher module. Introduce a specific
config option to enable these ciphersuites
and use it instead of MBEDTLS_CIPHER_NULL_CIPHER.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2025-09-16 15:53:43 +02:00
Ben Taylor
5cdbe30804 replace MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED with MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
After the ECDH keyexchange removal the two became synonyms so the former can
be removed.

Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-09-11 13:22:40 +01:00
Ben Taylor
4766a23f9c change MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED to MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-09-11 13:22:40 +01:00
Ben Taylor
c8823a262d Remove MBEDTLS_KEY_EXCHANGE_SOME_ECDHE_ENABLED as it appears to be causing issues
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-09-11 13:22:40 +01:00
Ben Taylor
a7b3f26864 reverted change to MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED, as it appears it could be causing issues
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-09-11 13:22:40 +01:00
Ben Taylor
b2f6a69d85 Replace MBEDTLS_KEY_EXCHANGE_SOME_ECDHE_ENABLED with MBEDTLS_KEY_EXCHANGE_SOME_ECDH_OR_ECDHE_1_2_ENABLED
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-09-11 13:22:40 +01:00
Ben Taylor
013f8aee4e Replace MBEDTLS_KEY_EXCHANGE_PSK_ENABLED with MBEDTLS_KEY_EXCHANGE_SOME_NON_PFS_ENABLED
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-09-11 13:22:40 +01:00
Ben Taylor
1d651cc8a1 Remove additional occurances of static ECDH symbols
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-09-11 13:22:40 +01:00