blob: 9b4768a3a1962cd5b8256ed15f97fc789c82650b [file] [log] [blame] [view]
Gilles Peskine75a36bd2025-10-10 17:45:33 +02001# Migrating from Mbed TLS 3.x to Mbed TLS 4.0
Gilles Peskine2c0cb992025-10-10 15:56:21 +02002
Gilles Peskined83c4762025-10-10 16:36:42 +02003This guide details the steps required to migrate from Mbed TLS version 3.x to Mbed TLS version 4.0 or greater. Unlike normal releases, Mbed TLS 4.0 breaks compatibility with previous versions, so users, integrators and package maintainers might need to change their own code in order to make it work with Mbed TLS 4.0.
Gilles Peskine2c0cb992025-10-10 15:56:21 +02004
5Here's the list of breaking changes; each entry should help you answer these two questions: (1) am I affected? (2) if yes, what's my migration path?
6
Gilles Peskinefa4e9462025-10-10 17:54:00 +02007The changes are detailed below. Here is a summary of the main points:
8
Gilles Peskine2c0cb992025-10-10 15:56:21 +02009- Mbed TLS has been split between two products: TF-PSA-Crypto for cryptography, and Mbed TLS for X.509 and (D)TLS.
10- CMake is now the only supported build system.
11- The cryptography API is now mostly the PSA API: most legacy cryptography APIs have been removed. This has led to adaptations in some X.509 and TLS APIs, notably because the library always uses the PSA random generator.
12- Various deprecated or minor functionality has been removed.
13
14Please consult the [TF-PSA-Crypto migration guide](../tf-psa-crypto/docs/1.0-migration-guide.md) for all information related to the crytography part of the library.
15
Gilles Peskinee79923c2025-10-10 15:50:20 +020016## CMake as the only build system
17Mbed TLS now uses CMake exclusively to configure and drive its build process.
18Support for the GNU Make and Microsoft Visual Studio project-based build systems has been removed.
19
20The previous `.sln` and `.vcxproj` files are no longer distributed or generated.
21
22See the `Compiling` section in README.md for instructions on building the Mbed TLS libraries and tests with CMake.
23If you develop in Microsoft Visual Studio, you could either generate a Visual Studio solution using a CMake generator, or open the CMake project directly in Visual Studio.
24
25### Translating Make commands to CMake
26
27With the removal of GNU Make support, all build, test, and installation operations must now be performed using CMake.
28This section provides a quick reference for translating common `make` commands into their CMake equivalents.
29
30#### Basic build workflow
31
32Run `cmake -S . -B build` once before building to configure the build and generate native build files (e.g., Makefiles) in the `build` directory.
33This sets up an out-of-tree build, which is recommended.
34
35| Make command | CMake equivalent | Description |
36|----------------|------------------------------------------------|--------------------------------------------------------------------|
37| `make` | `cmake --build build` | Build the libraries, programs, and tests in the `build` directory. |
38| `make test` | `ctest --test-dir build` | Run the tests produced by the previous build. |
39| `make clean` | `cmake --build build --target clean` | Remove build artifacts produced by the previous build. |
40| `make install` | `cmake --install build --prefix build/install` | Install the built libraries, headers, and tests to `build/install`. |
41
42#### Building specific targets
43
44Unless otherwise specified, the CMake command in the table below should be preceded by a `cmake -S . -B build` call to configure the build and generate build files in the `build` directory.
45
46| Make command | CMake equivalent | Description |
47|-----------------|---------------------------------------------------------------------|---------------------------|
48| `make lib` | `cmake --build build --target lib` | Build only the libraries. |
49| `make tests` | `cmake -S . -B build -DENABLE_PROGRAMS=Off && cmake --build build` | Build test suites. |
50| `make programs` | `cmake --build build --target programs` | Build example programs. |
51| `make apidoc` | `cmake --build build --target mbedtls-apidoc` | Build documentation. |
52
53Target names may differ slightly; use `cmake --build build --target help` to list all available CMake targets.
54
55There is no CMake equivalent for `make generated_files` or `make neat`.
56Generated files are automatically created in the build tree with `cmake --build build` and removed with `cmake --build build --target clean`.
57If you need to build the generated files in the source tree without involving CMake, you can call `framework/scripts/make_generated_files.py`.
58
59There is currently no equivalent for `make uninstall` in the Mbed TLS CMake build system.
60
61#### Common build options
62
63The following table illustrates the approximate CMake equivalents of common make commands.
64Most CMake examples show only the configuration step, others (like installation) correspond to different stages of the build process.
65
66| Make usage | CMake usage | Description |
67|----------------------------|-------------------------------------------------------|----------------------|
68| `make DEBUG=1` | `cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug` | Build in debug mode. |
69| `make SHARED=1` | `cmake -S . -B build -DUSE_SHARED_MBEDTLS_LIBRARY=On` | Also build shared libraries. |
70| `make GEN_FILES=""` | `cmake -S . -B build -DGEN_FILES=OFF` | Skip generating files (not a strict equivalent). |
71| `make DESTDIR=install_dir` | `cmake --install build --prefix install_dir` | Specify installation path. |
72| `make CC=clang` | `cmake -S . -B build -DCMAKE_C_COMPILER=clang` | Set the compiler. |
73| `make CFLAGS='-O2 -Wall'` | `cmake -S . -B build -DCMAKE_C_FLAGS="-O2 -Wall"` | Set compiler flags. |
74
75## Repository split
76In Mbed TLS 4.0, the project was split into two repositories:
77- [Mbed TLS](https://github.com/Mbed-TLS/mbedtls): provides TLS and X.509 functionality.
78- [TF-PSA-Crypto](https://github.com/Mbed-TLS/TF-PSA-Crypto): provides the standalone cryptography library, implementing the PSA Cryptography API.
79Mbed TLS consumes TF-PSA-Crypto as a submodule.
80You should stay with Mbed TLS if you use TLS or X.509 functionality. You still have direct access to the cryptography library.
81
82### File and directory relocations
83
84The following table summarizes the file and directory relocations resulting from the repository split between Mbed TLS and TF-PSA-Crypto.
85These changes reflect the move of cryptographic, cryptographic-adjacent, and platform components from Mbed TLS into the new TF-PSA-Crypto repository.
86
87| Original location | New location(s) | Notes |
88|-----------------------------------------|--------------------------------------------------------------------------------------|-------|
89| `library/*` (<sup>†</sup>) | `tf-psa-crypto/core/`<br>`tf-psa-crypto/drivers/builtin/src/` | Contains cryptographic, cryptographic-adjacent (e.g., ASN.1, Base64), and platform C modules and headers. |
90| `include/mbedtls/*` (<sup>†</sup>) | `tf-psa-crypto/include/mbedtls/`<br>`tf-psa-crypto/drivers/builtin/include/private/` | Public headers moved to `include/mbedtls`; now internal headers moved to `include/private`. |
91| `include/psa` | `tf-psa-crypto/include/psa` | All PSA headers consolidated here. |
92| `3rdparty/everest`<br>`3rdparty/p256-m` | `tf-psa-crypto/drivers/everest`<br>`tf-psa-crypto/drivers/p256-m` | Third-party crypto driver implementations. |
93
94(<sup>†</sup>) The `library` and `include/mbedtls` directories still exist in Mbed TLS, but now contain only TLS and X.509 components.
95
96### Configuration file split
97Cryptography and platform configuration options have been moved from `include/mbedtls/mbedtls_config.h` to `tf-psa-crypto/include/psa/crypto_config.h`, which is now mandatory.
98See [Compile-time configuration](#compile-time-configuration).
99
100The header `include/mbedtls/mbedtls_config.h` still exists and now contains only the TLS and X.509 configuration options.
101
102If you use the Python script `scripts/config.py` to adjust your configuration, you do not need to modify your scripts to specify which configuration file to edit, the script automatically updates the correct file.
103
104There have been significant changes in the configuration options, primarily affecting cryptography.
105
106#### Cryptography configuration
107- See [psa-transition.md](https://github.com/Mbed-TLS/TF-PSA-Crypto/blob/development/docs/psa-transition.md#compile-time-configuration).
108- See also the following sections in the TF-PSA-Crypto 1.0 migration guide:
109 - *PSA as the Only Cryptography API* and its sub-section *Impact on the Library Configuration*
110 - *Random Number Generation Configuration*
111
112#### TLS configuration
113For details about TLS-related changes, see [Changes to TLS options](#changes-to-tls-options).
114
115### Impact on some usages of the library
116
117#### Checking out a branch or a tag
118After checking out a branch or tag of the Mbed TLS repository, you must now recursively update the submodules, as TF-PSA-Crypto contains itself a nested submodule:
119```
120git submodule update --init --recursive
121```
122
123#### Linking directly to a built library
124
125The Mbed TLS CMake build system still provides the cryptography libraries under their legacy name, `libmbedcrypto.<ext>`, so you can continue linking against them.
126These libraries are still located in the `library` directory within the build tree.
127
128The cryptography libraries are also now provided as `libtfpsacrypto.<ext>`, consistent with the naming used in the TF-PSA-Crypto repository.
129
130You may need to update include paths to the public header files, see [File and Directory Relocations](#file-and-directory-relocations) for details.
131
132#### Using Mbed TLS as a CMake subproject
133
134The base name of the libraries are now `tfpsacrypto` (formely `mbedcrypto`), `mbedx509` and `mbedtls`.
135As before, these base names are also the names of CMake targets to build each library.
136If your CMake scripts reference a cryptography library target, you need to update its name accordingly.
137
138For example, the following CMake code:
139```
140target_link_libraries(mytarget PRIVATE mbedcrypto)
141```
142should be updated to:
143```
144target_link_libraries(mytarget PRIVATE tfpsacrypto)
145```
146
147You can refer to the following example demonstrating how to consume Mbed TLS as a CMake subproject:
148- `programs/test/cmake_subproject`
149
150#### Using Mbed TLS as a CMake package
151
152The same renaming applies to the cryptography library targets declared as part of the Mbed TLS CMake package, use `MbedTLS::tfpsacrypto` instead of `MbedTLS::mbedcrypto`.
153
154For example, the following CMake code:
155```
156find_package(MbedTLS REQUIRED)
157target_link_libraries(myapp PRIVATE MbedTLS::mbedcrypto)
158```
159should be updated to:
160```
161find_package(MbedTLS REQUIRED)
162target_link_libraries(myapp PRIVATE MbedTLS::tfpsacrypto)
163```
164You can also refer to the following example programs demonstrating how to consume Mbed TLS as a CMake package:
165- `programs/test/cmake_package`
166- `programs/test/cmake_package_install`
167
168#### Using the Mbed TLS Crypto pkg-config file
169
170The Mbed TLS CMake build system still provides the pkg-config file mbedcrypto.pc, so you can continue using it.
171Internally, it now references the tfpsacrypto library.
172
173A new pkg-config file, `tfpsacrypto.pc`, is also provided.
174Both `mbedcrypto.pc` and `tfpsacrypto.pc` are functionally equivalent, providing the same compiler and linker flags.
175
176#### Using Mbed TLS as an installed library
177
178The Mbed TLS CMake build system still installs the cryptography libraries under their legacy name, `libmbedcrypto.<ext>`, so you can continue linking against them.
179The cryptography library is also now provided as `libtfpsacrypto.<ext>`.
180
181Regarding the headers, the main change is the relocation of some headers to subdirectories called `private`.
182These headers are installed primarily to satisfy compiler dependencies.
183Others remain for historical reasons and may be cleaned up in later versions of the library.
184
185We strongly recommend not relying on the declarations in these headers, as they may be removed or modified without notice.
186See the section Private Declarations in the TF-PSA-Crypto 1.0 migration guide for more information.
187
188Finally, note the new `include/tf-psa-crypto` directory, which contains the TF-PSA-Crypto version and build-time configuration headers.
189
190### Audience-Specific Notes
191
192#### Application Developers using a distribution package
193- See [Impact on usages of the library](#impact-on-some-usages-of-the-library) for the possible impacts on:
194 - Linking against the cryptography library or CMake targets.
195 - Using the Mbed TLS Crypto pkg-config file.
196 - Using Mbed TLS as an installed library
197
198### Developer or package maintainers
199If you build or distribute Mbed TLS:
200- The build system is now CMake only, Makefiles and Visual Studio projects are removed.
201- You may need to adapt packaging scripts to handle the TF-PSA-Crypto submodule.
202- You should update submodules recursively after checkout.
203- Review [File and directory relocations](#file-and-directory-relocations) for updated paths.
204- See [Impact on usages of the library](#impact-on-some-usages-of-the-library) for the possible impacts on:
205 - Linking against the cryptography library or CMake targets.
206 - Using the Mbed TLS Crypto pkg-config file (`mbedcrypto.pc` or `tfpsacrypto.pc`).
207 - Using Mbed TLS as an installed library
208- Configuration note: cryptography and platform options are now in `crypto_config.h` (see [Configuration file split](#configuration-file-split)).
209
210### Platform Integrators
211If you integrate Mbed TLS with a platform or hardware drivers:
212- TF-PSA-Crypto is now a submodule, update integration scripts to initialize submodules recursively.
213- The PSA driver wrapper is now generated in TF-PSA-Crypto.
214- Platform-specific configuration are now handled in `crypto_config.h`.
215- See [Repository split](#repository-split) for how platform components moved to TF-PSA-Crypto.
Gilles Peskine66719092025-10-10 15:51:17 +0200216
Gilles Peskinee79923c2025-10-10 15:50:20 +0200217## Compile-time configuration
218
219### Configuration file split
220
221All configuration options that are relevant to TF-PSA-Crypto must now be configured in one of its configuration files, namely:
222
223* `TF_PSA_CRYPTO_CONFIG_FILE`, if set on the preprocessor command line;
224* otherwise `<psa/crypto_config.h>`;
225* additionally `TF_PSA_CRYPTO_USER_CONFIG_FILE`, if set.
226
227Configuration options that are relevant to X.509 or TLS should still be set in the Mbed TLS configuration file (`MBEDTLS_CONFIG_FILE` or `<mbedtls/mbedtls_config.h>`, plus `MBEDTLS_USER_CONFIG_FILE` if it is set). However, you can define all options in the crypto configuration, and Mbed TLS will pick them up.
228
229Generally speaking, the options that must be configured in TF-PSA-Crypto are:
230
231* options related to platform settings;
232* options related to the choice of cryptographic mechanisms included in the build;
233* options related to the inner workings of cryptographic mechanisms, such as size/memory/performance compromises;
234* options related to crypto-adjacent features, such as ASN.1 and Base64.
235
236See `include/psa/crypto_config.h` in TF-PSA-Crypto and `include/mbedtls/mbedtls_config.h` in Mbed TLS for details.
237
238Notably, `<psa/crypto_config.h>` is no longer limited to `PSA_WANT_xxx` options.
239
240Note that many options related to cryptography have changed; see the TF-PSA-Crypto migration guide for details.
241
242### Split of `build_info.h` and `version.h`
243
244The header file `<mbedtls/build_info.h>`, which includes the configuration file and provides the adjusted configuration macros, now has an similar file `<tf-psa-crypto/build_info.h>` in TF-PSA-Crypto. The Mbed TLS header includes the TF-PSA-Crypto header, so including `<mbedtls/build_info.h>` remains sufficient to obtain information about the crypto configuration.
245
246TF-PSA-Crypto exposes its version through `<tf-psa-crypto/version.h>`, similar to `<mbedtls/version.h>` in Mbed TLS.
247
248### Removal of `check_config.h`
249
250The header `mbedtls/check_config.h` is no longer present. Including it from user configuration files was already obsolete in Mbed TLS 3.x, since it enforces properties the configuration as adjusted by `mbedtls/build_info.h`, not properties that the user configuration is expected to meet.
251
252### Changes to TLS options
253
254#### Enabling null cipher suites
255
256The option to enable null cipher suites in TLS 1.2 has been renamed from `MBEDTLS_CIPHER_NULL_CIPHER` to `MBEDTLS_SSL_NULL_CIPHERSUITES`. It remains disabled in the default configuration.
257
258#### Removal of backward compatibility options
259
260The option `MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT` has been removed. Only the version standardized in RFC 9146 is supported now.
Gilles Peskine66719092025-10-10 15:51:17 +0200261
Gilles Peskinee79923c2025-10-10 15:50:20 +0200262## PSA as the only cryptography API
263
264The PSA API is now the only API for cryptographic primitives.
265
266### Impact on application code
267
Gilles Peskine2c0cb992025-10-10 15:56:21 +0200268The X.509, PKCS7 and SSL modules always use PSA for cryptography, with a few exceptions documented in the [PSA limitations](architecture/psa-migration/psa-limitations.md) document. (These limitations are mostly transparent unless you want to leverage PSA accelerator drivers.) This corresponds to the behavior of Mbed TLS 3.x when `MBEDTLS_USE_PSA_CRYPTO` is enabled. In effect, `MBEDTLS_USE_PSA_CRYPTO` is now always enabled.
Gilles Peskinee79923c2025-10-10 15:50:20 +0200269
270`psa_crypto_init()` must be called before performing any cryptographic operation, including indirect requests such as parsing a key or certificate or starting a TLS handshake.
271
272A few functions take different parameters to migrate them to the PSA API. See “[Function prototype changes](#function-prototype-changes)”.
273
274### No random generator instantiation
275
276Formerly, applications using TLS, asymmetric cryptography operations involving a private key, or other features needing random numbers, needed to provide a random generator, generally by instantiating an entropy context (`mbedtls_entropy_context`) and a DRBG context (`mbedtls_ctr_drbg_context` or `mbedtls_hmac_drbg_context`). This is no longer necessary, or possible. All features that require a random generator (RNG) now use the one provided by the PSA subsystem.
277
278Instead, applications that use random generators or keys (even public keys) need to call `psa_crypto_init()` before any cryptographic operation or key management operation.
279
280See also [function prototype changes](#function-prototype-changes), many of which are related to the move from RNG callbacks to a global RNG.
281
282### Impact on the library configuration
283
284Mbed TLS follows the configuration of TF-PSA-Crypto with respect to cryptographic mechanisms. They are now based on `PSA_WANT_xxx` macros instead of legacy configuration macros such as `MBEDTLS_RSA_C`, `MBEDTLS_PKCS1_V15`, etc. The configuration of X.509 and TLS is not directly affected by the configuration. However, applications and middleware that rely on these configuration symbols to know which cryptographic mechanisms to support will need to migrate to `PSA_WANT_xxx` macros. For more information, consult the PSA transition guide in TF-PSA-Crypto.
Gilles Peskine66719092025-10-10 15:51:17 +0200285
Gilles Peskinee79923c2025-10-10 15:50:20 +0200286## Private declarations
287
288Since Mbed TLS 3.0, some things that are declared in a public header are not part of the stable application programming interface (API), but instead are considered private. Private elements may be removed or may have their semantics changed in a future minor release without notice.
289
290### Understanding private declarations in public headers
291
292In Mbed TLS 4.x, private elements in header files include:
293
294* Anything appearing in a header file whose path contains `/private` (unless re-exported and documented in another non-private header).
295* Structure and union fields declared with `MBEDTLS_PRIVATE(field_name)` in the source code, and appearing as `private_field_name` in the rendered documentation. (This was already the case since Mbed TLS 3.0.)
296* Any preprocessor macro that is not documented with a Doxygen comment.
297 In the source code, Doxygen comments start with `/**` or `/*!`. If a macro only has a comment above that starts with `/*`, the macro is considered private.
298 In the rendered documentation, private macros appear with only an automatically rendered parameter list, value and location, but no custom text.
299* Any declaration that is guarded by the preprocessor macro `MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS`.
300
301### Usage of private declarations
302
303Some private declarations are present in public headers for technical reasons, because they need to be visible to the compiler. Others are present for historical reasons and may be cleaned up in later versions of the library. We strongly recommend against relying on these declarations, since they may be removed or may have their semantics changed without notice.
304
305Note that Mbed TLS 4.0 still relies on some private interfaces of TF-PSA-Crypto 1.0. We expect to remove this reliance gradually in future minor releases.
306
307Sample programs have not been fully updated yet and some of them might still
308use APIs that are no longer public. You can recognize them by the fact that they
309define the macro `MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS` (or
310`MBEDTLS_ALLOW_PRIVATE_ACCESS`) at the very top (before including headers). When
311you see one of these two macros in a sample program, be aware it has not been
312updated and parts of it do not demonstrate current practice.
313
314We strongly recommend against defining `MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS` or
315`MBEDTLS_ALLOW_PRIVATE_ACCESS` in your own application. If you do so, your code
316may not compile or work with future minor releases. If there's something you
317want to do that you feel can only be achieved by using one of these two macros,
318please reach out on github or the mailing list.
Gilles Peskine66719092025-10-10 15:51:17 +0200319
Gilles Peskinee79923c2025-10-10 15:50:20 +0200320## Error codes
321
322### Unified error code space
323
324The convention still applies that functions return 0 for success and a negative value between -32767 and -1 on error. PSA functions (`psa_xxx()` or `mbedtls_psa_xxx()`) still return a `PSA_ERROR_xxx` error codes. Non-PSA functions (`mbedtls_xxx()` excluding `mbedtls_psa_xxx()`) can return either `PSA_ERROR_xxx` or `MBEDTLS_ERR_xxx` error codes.
325
326There may be cases where an `MBEDTLS_ERR_xxx` constant has the same numerical value as a `PSA_ERROR_xxx`. In such cases, they have the same meaning: they are different names for the same error condition.
327
328### Simplified legacy error codes
329
330All values returned by a function to indicate an error now have a defined constant named `MBEDTLS_ERR_xxx` or `PSA_ERROR_xxx`. Functions no longer return the sum of a “low-level” and a “high-level” error code.
331
332Generally, functions that used to return the sum of two error codes now return the low-level code. However, as before, the exact error code returned in a given scenario can change without notice unless the condition is specifically described in the function's documentation and no other condition is applicable.
333
334As a consequence, the functions `mbedtls_low_level_strerr()` and `mbedtls_high_level_strerr()` no longer exist.
335
336### Removed error code names
337
338Many legacy error codes have been removed in favor of PSA error codes. Generally, functions that returned a legacy error code in the table below in Mbed TLS 3.6 now return the PSA error code listed on the same row. Similarly, callbacks should apply the same changes to error code, unless there has been a relevant change to the callback's interface.
339
340| Legacy constant (Mbed TLS 3.6) | PSA constant (Mbed TLS 4.0) |
341|-----------------------------------------|---------------------------------|
342| `MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED` | `PSA_ERROR_CORRUPTION_DETECTED` |
343| `MBEDTLS_ERR_ERROR_GENERIC_ERROR` | `PSA_ERROR_GENERIC_ERROR` |
344| `MBEDTLS_ERR_NET_BUFFER_TOO_SMALL` | `PSA_ERROR_BUFFER_TOO_SMALL` |
345| `MBEDTLS_ERR_OID_BUF_TOO_SMALL` | `PSA_ERROR_BUFFER_TOO_SMALL` |
346| `MBEDTLS_ERR_OID_NOT_FOUND` | `PSA_ERROR_NOT_SUPPORTED` |
347| `MBEDTLS_ERR_PKCS7_ALLOC_FAILED` | `PSA_ERROR_INSUFFICIENT_MEMORY` |
348| `MBEDTLS_ERR_PKCS7_BAD_INPUT_DATA` | `PSA_ERROR_INVALID_ARGUMENT` |
349| `MBEDTLS_ERR_PKCS7_VERIFY_FAIL` | `PSA_ERROR_INVALID_SIGNATURE` |
350| `MBEDTLS_ERR_SSL_ALLOC_FAILED` | `PSA_ERROR_INSUFFICIENT_MEMORY` |
351| `MBEDTLS_ERR_SSL_BAD_INPUT_DATA` | `PSA_ERROR_INVALID_ARGUMENT` |
352| `MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL` | `PSA_ERROR_BUFFER_TOO_SMALL` |
353| `MBEDTLS_ERR_X509_ALLOC_FAILED` | `PSA_ERROR_INSUFFICIENT_MEMORY` |
354| `MBEDTLS_ERR_X509_BUFFER_TOO_SMALL` | `PSA_ERROR_BUFFER_TOO_SMALL` |
355
356See also the corresponding section in the TF-PSA-Crypto migration guide, which lists error codes from cryptography modules.
Gilles Peskine66719092025-10-10 15:51:17 +0200357
Gilles Peskinee79923c2025-10-10 15:50:20 +0200358## Removal of deprecated functions
359
360### Removal of deprecated X.509 functions
361
362The deprecated function `mbedtls_x509write_crt_set_serial()` has been removed. The function was superseded by `mbedtls_x509write_crt_set_serial_raw()`.
363
364### Removal of deprecated SSL functions
365
366The deprecated function `mbedtls_ssl_conf_curves()` has been removed.
367The function was superseded by `mbedtls_ssl_conf_groups()`.
368
369### Removal of `compat-2.x.h`
370
371The header `compat-2.x.h`, containing some definitions for backward compatibility with Mbed TLS 2.x, has been removed.
Gilles Peskine66719092025-10-10 15:51:17 +0200372
Gilles Peskinee79923c2025-10-10 15:50:20 +0200373## Removed features
374
375### Removal of obsolete key exchanges methods in (D)TLS 1.2
376
377Mbed TLS 4.0 no longer supports key exchange methods that rely on finite-field Diffie-Hellman (DHE) in TLS 1.2 and DTLS 1.2. (Only ephemeral Diffie-Hellman was ever supported, Mbed TLS 3.x already did not support static Diffie-Hellman.) Finite-field Diffie-Hellman remains supported in TLS 1.3.
378
379Mbed TLS 4.0 no longer supports key exchange methods that rely on RSA decryption (without forward secrecy). RSA signatures remain supported. This affects TLS 1.2 and DTLS 1.2 (TLS 1.3 does not have key exchanges using RSA decryption).
380
381That is, the following key exchange types are no longer supported:
382
383* RSA-PSK;
384* RSA (i.e. cipher suites using only RSA decryption: cipher suites using RSA signatures remain supported);
385* DHE-PSK (except in TLS 1.3);
386* DHE-RSA (except in TLS 1.3).
387* static ECDH (ECDH-RSA and ECDH-ECDSA, as opposed to ephemeral ECDH (ECDHE) which remains supported).
388
389The full list of removed cipher suites is:
390
391```
392TLS-DHE-PSK-WITH-AES-128-CBC-SHA
393TLS-DHE-PSK-WITH-AES-128-CBC-SHA256
394TLS-DHE-PSK-WITH-AES-128-CCM
395TLS-DHE-PSK-WITH-AES-128-CCM-8
396TLS-DHE-PSK-WITH-AES-128-GCM-SHA256
397TLS-DHE-PSK-WITH-AES-256-CBC-SHA
398TLS-DHE-PSK-WITH-AES-256-CBC-SHA384
399TLS-DHE-PSK-WITH-AES-256-CCM
400TLS-DHE-PSK-WITH-AES-256-CCM-8
401TLS-DHE-PSK-WITH-AES-256-GCM-SHA384
402TLS-DHE-PSK-WITH-ARIA-128-CBC-SHA256
403TLS-DHE-PSK-WITH-ARIA-128-GCM-SHA256
404TLS-DHE-PSK-WITH-ARIA-256-CBC-SHA384
405TLS-DHE-PSK-WITH-ARIA-256-GCM-SHA384
406TLS-DHE-PSK-WITH-CAMELLIA-128-CBC-SHA256
407TLS-DHE-PSK-WITH-CAMELLIA-128-GCM-SHA256
408TLS-DHE-PSK-WITH-CAMELLIA-256-CBC-SHA384
409TLS-DHE-PSK-WITH-CAMELLIA-256-GCM-SHA384
410TLS-DHE-PSK-WITH-CHACHA20-POLY1305-SHA256
411TLS-DHE-PSK-WITH-NULL-SHA
412TLS-DHE-PSK-WITH-NULL-SHA256
413TLS-DHE-PSK-WITH-NULL-SHA384
414TLS-DHE-RSA-WITH-AES-128-CBC-SHA
415TLS-DHE-RSA-WITH-AES-128-CBC-SHA256
416TLS-DHE-RSA-WITH-AES-128-CCM
417TLS-DHE-RSA-WITH-AES-128-CCM-8
418TLS-DHE-RSA-WITH-AES-128-GCM-SHA256
419TLS-DHE-RSA-WITH-AES-256-CBC-SHA
420TLS-DHE-RSA-WITH-AES-256-CBC-SHA256
421TLS-DHE-RSA-WITH-AES-256-CCM
422TLS-DHE-RSA-WITH-AES-256-CCM-8
423TLS-DHE-RSA-WITH-AES-256-GCM-SHA384
424TLS-DHE-RSA-WITH-ARIA-128-CBC-SHA256
425TLS-DHE-RSA-WITH-ARIA-128-GCM-SHA256
426TLS-DHE-RSA-WITH-ARIA-256-CBC-SHA384
427TLS-DHE-RSA-WITH-ARIA-256-GCM-SHA384
428TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA
429TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA256
430TLS-DHE-RSA-WITH-CAMELLIA-128-GCM-SHA256
431TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA
432TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA256
433TLS-DHE-RSA-WITH-CAMELLIA-256-GCM-SHA384
434TLS-DHE-RSA-WITH-CHACHA20-POLY1305-SHA256
435TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA
436TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA256
437TLS-ECDH-ECDSA-WITH-AES-128-GCM-SHA256
438TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA
439TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA384
440TLS-ECDH-ECDSA-WITH-AES-256-GCM-SHA384
441TLS-ECDH-ECDSA-WITH-ARIA-128-CBC-SHA256
442TLS-ECDH-ECDSA-WITH-ARIA-128-GCM-SHA256
443TLS-ECDH-ECDSA-WITH-ARIA-256-CBC-SHA384
444TLS-ECDH-ECDSA-WITH-ARIA-256-GCM-SHA384
445TLS-ECDH-ECDSA-WITH-CAMELLIA-128-CBC-SHA256
446TLS-ECDH-ECDSA-WITH-CAMELLIA-128-GCM-SHA256
447TLS-ECDH-ECDSA-WITH-CAMELLIA-256-CBC-SHA384
448TLS-ECDH-ECDSA-WITH-CAMELLIA-256-GCM-SHA384
449TLS-ECDH-ECDSA-WITH-NULL-SHA
450TLS-ECDH-RSA-WITH-AES-128-CBC-SHA
451TLS-ECDH-RSA-WITH-AES-128-CBC-SHA256
452TLS-ECDH-RSA-WITH-AES-128-GCM-SHA256
453TLS-ECDH-RSA-WITH-AES-256-CBC-SHA
454TLS-ECDH-RSA-WITH-AES-256-CBC-SHA384
455TLS-ECDH-RSA-WITH-AES-256-GCM-SHA384
456TLS-ECDH-RSA-WITH-ARIA-128-CBC-SHA256
457TLS-ECDH-RSA-WITH-ARIA-128-GCM-SHA256
458TLS-ECDH-RSA-WITH-ARIA-256-CBC-SHA384
459TLS-ECDH-RSA-WITH-ARIA-256-GCM-SHA384
460TLS-ECDH-RSA-WITH-CAMELLIA-128-CBC-SHA256
461TLS-ECDH-RSA-WITH-CAMELLIA-128-GCM-SHA256
462TLS-ECDH-RSA-WITH-CAMELLIA-256-CBC-SHA384
463TLS-ECDH-RSA-WITH-CAMELLIA-256-GCM-SHA384
464TLS-ECDH-RSA-WITH-NULL-SHA
465TLS-RSA-PSK-WITH-AES-128-CBC-SHA
466TLS-RSA-PSK-WITH-AES-128-CBC-SHA256
467TLS-RSA-PSK-WITH-AES-128-GCM-SHA256
468TLS-RSA-PSK-WITH-AES-256-CBC-SHA
469TLS-RSA-PSK-WITH-AES-256-CBC-SHA384
470TLS-RSA-PSK-WITH-AES-256-GCM-SHA384
471TLS-RSA-PSK-WITH-ARIA-128-CBC-SHA256
472TLS-RSA-PSK-WITH-ARIA-128-GCM-SHA256
473TLS-RSA-PSK-WITH-ARIA-256-CBC-SHA384
474TLS-RSA-PSK-WITH-ARIA-256-GCM-SHA384
475TLS-RSA-PSK-WITH-CAMELLIA-128-CBC-SHA256
476TLS-RSA-PSK-WITH-CAMELLIA-128-GCM-SHA256
477TLS-RSA-PSK-WITH-CAMELLIA-256-CBC-SHA384
478TLS-RSA-PSK-WITH-CAMELLIA-256-GCM-SHA384
479TLS-RSA-PSK-WITH-CHACHA20-POLY1305-SHA256
480TLS-RSA-PSK-WITH-NULL-SHA
481TLS-RSA-PSK-WITH-NULL-SHA256
482TLS-RSA-PSK-WITH-NULL-SHA384
483TLS-RSA-WITH-AES-128-CBC-SHA
484TLS-RSA-WITH-AES-128-CBC-SHA256
485TLS-RSA-WITH-AES-128-CCM
486TLS-RSA-WITH-AES-128-CCM-8
487TLS-RSA-WITH-AES-128-GCM-SHA256
488TLS-RSA-WITH-AES-256-CBC-SHA
489TLS-RSA-WITH-AES-256-CBC-SHA256
490TLS-RSA-WITH-AES-256-CCM
491TLS-RSA-WITH-AES-256-CCM-8
492TLS-RSA-WITH-AES-256-GCM-SHA384
493TLS-RSA-WITH-ARIA-128-CBC-SHA256
494TLS-RSA-WITH-ARIA-128-GCM-SHA256
495TLS-RSA-WITH-ARIA-256-CBC-SHA384
496TLS-RSA-WITH-ARIA-256-GCM-SHA384
497TLS-RSA-WITH-CAMELLIA-128-CBC-SHA
498TLS-RSA-WITH-CAMELLIA-128-CBC-SHA256
499TLS-RSA-WITH-CAMELLIA-128-GCM-SHA256
500TLS-RSA-WITH-CAMELLIA-256-CBC-SHA
501TLS-RSA-WITH-CAMELLIA-256-CBC-SHA256
502TLS-RSA-WITH-CAMELLIA-256-GCM-SHA384
503TLS-RSA-WITH-NULL-MD5
504TLS-RSA-WITH-NULL-SHA
505TLS-RSA-WITH-NULL-SHA256
506```
507
508As a consequence of the removal of support for DHE in (D)TLS 1.2, the following functions are no longer useful and have been removed:
509
510```
511mbedtls_ssl_conf_dh_param_bin()
512mbedtls_ssl_conf_dh_param_ctx()
513mbedtls_ssl_conf_dhm_min_bitlen()
514```
515
516### Removal of elliptic curves
517
518Following their removal from the crypto library, elliptic curves of less than 250 bits (secp192r1, secp192k1, secp224r1, secp224k1) are no longer supported in certificates and in TLS.
519
520### Removal of deprecated functions
521
522The deprecated functions `mbedtls_ssl_conf_min_version()` and `mbedtls_ssl_conf_max_version()`, and the associated constants `MBEDTLS_SSL_MAJOR_VERSION_3`, `MBEDTLS_SSL_MINOR_VERSION_3` and `MBEDTLS_SSL_MINOR_VERSION_4` have been removed. Use `mbedtls_ssl_conf_min_tls_version()` and `mbedtls_ssl_conf_max_tls_version()` with `MBEDTLS_SSL_VERSION_TLS1_2` or `MBEDTLS_SSL_VERSION_TLS1_3` instead.
523
524The deprecated function `mbedtls_ssl_conf_sig_hashes()` has been removed. Use `mbedtls_ssl_conf_sig_algs()` instead.
Gilles Peskine66719092025-10-10 15:51:17 +0200525
Gilles Peskinee79923c2025-10-10 15:50:20 +0200526## Function prototype changes
527
528A number of existing functions now take a different list of arguments, mostly to migrate them to the PSA API.
529
530### Public functions no longer take a RNG callback
531
532Functions that need randomness no longer take an RNG callback in the form of `f_rng, p_rng` arguments. Instead, they use the PSA Crypto random generator (accessible as `psa_generate_random()`). All software using the X.509 or SSL modules must call `psa_crypto_init()` before calling any of the functions listed here.
533
534### RNG removal in X.509
535
536The following function prototypes have been changed in `mbedtls/x509_crt.h`:
537
538```c
539int mbedtls_x509write_crt_der(mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
540 int (*f_rng)(void *, unsigned char *, size_t),
541 void *p_rng);
542
543int mbedtls_x509write_crt_pem(mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size,
544 int (*f_rng)(void *, unsigned char *, size_t),
545 void *p_rng);
546```
547
548to
549
550```c
551int mbedtls_x509write_crt_der(mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size);
552
553int mbedtls_x509write_crt_pem(mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size);
554```
555
556The following function prototypes have been changed in `mbedtls/x509_csr.h`:
557```c
558int mbedtls_x509write_csr_der(mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size,
559 int (*f_rng)(void *, unsigned char *, size_t),
560 void *p_rng);
561
562int mbedtls_x509write_csr_pem(mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size,
563 int (*f_rng)(void *, unsigned char *, size_t),
564 void *p_rng);
565```
566
567to
568
569```c
570int mbedtls_x509write_csr_der(mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size);
571
572int mbedtls_x509write_csr_pem(mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size);
573```
574
575### RNG removal in SSL
576
577The following function prototype has been changed in `mbedtls/ssl_cookie.h`:
578
579```c
580int mbedtls_ssl_cookie_setup(mbedtls_ssl_cookie_ctx *ctx,
581 int (*f_rng)(void *, unsigned char *, size_t),
582 void *p_rng);
583```
584
585to
586
587```c
588int mbedtls_ssl_cookie_setup(mbedtls_ssl_cookie_ctx *ctx);
589```
590
591### Removal of `mbedtls_ssl_conf_rng`
592
593`mbedtls_ssl_conf_rng()` has been removed from the library. Its sole purpose was to configure the RNG used for TLS, but now the PSA Crypto random generator is used throughout the library.
594
595### Changes to mbedtls_ssl_ticket_setup
596
597In the arguments of the function `mbedtls_ssl_ticket_setup()`, the `mbedtls_cipher_type_t` argument specifying the AEAD mechanism for ticket protection has been replaced by an equivalent PSA description consisting of a key type, a size and an algorithm. Also, the function no longer takes RNG arguments.
598
599The prototype in `mbedtls/ssl_ticket.h` has changed from
600
601```c
602int mbedtls_ssl_ticket_setup(mbedtls_ssl_ticket_context *ctx,
603 mbedtls_f_rng_t *f_rng, void *p_rng,
604 mbedtls_cipher_type_t cipher,
605 uint32_t lifetime);
606```
607
608to
609
610```c
611int mbedtls_ssl_ticket_setup(mbedtls_ssl_ticket_context *ctx,
612 psa_algorithm_t alg, psa_key_type_t key_type, psa_key_bits_t key_bits,
613 uint32_t lifetime);
614```
Gilles Peskine66719092025-10-10 15:51:17 +0200615
Gilles Peskinee79923c2025-10-10 15:50:20 +0200616## OID module
617
618The compilation option `MBEDTLS_OID_C` no longer exists. OID tables are included in the build automatically as needed for parsing and writing X.509 data.
619
620Mbed TLS no longer offers interfaces to look up values by OID or OID by enum values (`mbedtls_oid_get_<thing>()` and `mbedtls_oid_get_oid_by_<thing>()`).
621
622The header `<mbedtls/oid.h>` now only provides functions to convert between binary and dotted string OID representations. These functions are now part of `libmbedx509` rather than the crypto library. The function `mbedtls_oid_get_numeric_string()` is guarded by `MBEDTLS_X509_USE_C`, and `mbedtls_oid_from_numeric_string()` by `MBEDTLS_X509_CREATE_C`. The header also still defines macros for OID strings that are relevant to X.509.