1*62c56f98SSadaf Ebrahimi# Migrating from Mbed TLS 2.x to Mbed TLS 3.0 2*62c56f98SSadaf Ebrahimi 3*62c56f98SSadaf EbrahimiThis guide details the steps required to migrate from Mbed TLS version 2.x to 4*62c56f98SSadaf EbrahimiMbed TLS version 3.0 or greater. Unlike normal releases, Mbed TLS 3.0 breaks 5*62c56f98SSadaf Ebrahimicompatibility with previous versions, so users (and alt implementers) might 6*62c56f98SSadaf Ebrahimineed to change their own code in order to make it work with Mbed TLS 3.0. 7*62c56f98SSadaf Ebrahimi 8*62c56f98SSadaf EbrahimiHere's the list of breaking changes; each entry should help you answer these 9*62c56f98SSadaf Ebrahimitwo questions: (1) am I affected? (2) if yes, what's my migration path? 10*62c56f98SSadaf Ebrahimi 11*62c56f98SSadaf EbrahimiThe changes are detailed below, and include: 12*62c56f98SSadaf Ebrahimi 13*62c56f98SSadaf Ebrahimi- Removal of many insecure or obsolete features 14*62c56f98SSadaf Ebrahimi- Tidying up of configuration options (including removing some less useful options). 15*62c56f98SSadaf Ebrahimi- Changing function signatures, e.g. adding return codes, adding extra parameters, or making some arguments const. 16*62c56f98SSadaf Ebrahimi- Removal of functions, macros, and types previously marked as deprecated. 17*62c56f98SSadaf Ebrahimi 18*62c56f98SSadaf EbrahimiMuch of the information needed to determine a migration path can be found in the Mbed TLS 2.x documentation. 19*62c56f98SSadaf Ebrahimi 20*62c56f98SSadaf Ebrahimi 21*62c56f98SSadaf Ebrahimi## Accessing the Mbed TLS 2.x documentation 22*62c56f98SSadaf Ebrahimi 23*62c56f98SSadaf EbrahimiFor features previously marked as deprecated, Mbed TLS 2.x documentation may 24*62c56f98SSadaf Ebrahimiexplain how to upgrade, and should be referred to when migrating code. Where a 25*62c56f98SSadaf Ebrahimimigration path is not provided in prior documentation, changes made and the 26*62c56f98SSadaf Ebrahimiupgrade steps required will be explained later in this guide. 27*62c56f98SSadaf Ebrahimi 28*62c56f98SSadaf EbrahimiIt's best to use the latest version of Mbed TLS 2.x for this purpose, which is the 2.28 LTS release. 29*62c56f98SSadaf EbrahimiSo to generate the documentation, checkout the `mbedtls-2.28` branch and follow 30*62c56f98SSadaf Ebrahimithe instructions in the [Documentation section of the README](https://github.com/Mbed-TLS/mbedtls/blob/mbedtls-2.28/README.md#documentation). 31*62c56f98SSadaf EbrahimiThen browse `apidoc/deprecated.html` for guidance on upgrading deprecated code. 32*62c56f98SSadaf Ebrahimi 33*62c56f98SSadaf EbrahimiFor some deprecated functions, 2.x documentation will suggest using a variant 34*62c56f98SSadaf Ebrahimisuffixed with `_ret`. In Mbed TLS 3.x, this change may not be required, as most 35*62c56f98SSadaf Ebrahimiof these variants have been renamed without the suffix. The section 36*62c56f98SSadaf Ebrahimi[Rename mbedtls_*_ret...](#rename-mbedtls__ret-cryptography-functions-whose-deprecated-variants-have-been-removed) 37*62c56f98SSadaf Ebrahimihas further detail on which functions this applies to. 38*62c56f98SSadaf Ebrahimi 39*62c56f98SSadaf Ebrahimi 40*62c56f98SSadaf Ebrahimi## General changes 41*62c56f98SSadaf Ebrahimi 42*62c56f98SSadaf Ebrahimi### Introduce a level of indirection and versioning in the config files 43*62c56f98SSadaf Ebrahimi 44*62c56f98SSadaf Ebrahimi`config.h` was split into `build_info.h` and `mbedtls_config.h`. 45*62c56f98SSadaf Ebrahimi 46*62c56f98SSadaf Ebrahimi* In code, use `#include <mbedtls/build_info.h>`. Don't include `mbedtls/config.h` and don't refer to `MBEDTLS_CONFIG_FILE`. 47*62c56f98SSadaf Ebrahimi* In build tools, edit `mbedtls_config.h`, or edit `MBEDTLS_CONFIG_FILE` as before. 48*62c56f98SSadaf Ebrahimi* If you had a tool that parsed the library version from `include/mbedtls/version.h`, this has moved to `include/mbedtls/build_info.h`. From C code, both headers now define the `MBEDTLS_VERSION_xxx` macros. 49*62c56f98SSadaf Ebrahimi 50*62c56f98SSadaf EbrahimiAlso, if you have a custom configuration file: 51*62c56f98SSadaf Ebrahimi 52*62c56f98SSadaf Ebrahimi* Don't include `check_config.h` or `config_psa.h` anymore. 53*62c56f98SSadaf Ebrahimi* Don't define `MBEDTLS_CONFIG_H` anymore. 54*62c56f98SSadaf Ebrahimi 55*62c56f98SSadaf EbrahimiA config file version symbol, `MBEDTLS_CONFIG_VERSION` was introduced. 56*62c56f98SSadaf EbrahimiDefining it to a particular value will ensure that Mbed TLS interprets 57*62c56f98SSadaf Ebrahimithe config file in a way that's compatible with the config file format 58*62c56f98SSadaf Ebrahimiused by the Mbed TLS release whose `MBEDTLS_VERSION_NUMBER` has the same 59*62c56f98SSadaf Ebrahimivalue. 60*62c56f98SSadaf EbrahimiThe only value supported by Mbed TLS 3.0.0 is `0x03000000`. 61*62c56f98SSadaf Ebrahimi 62*62c56f98SSadaf Ebrahimi### Most structure fields are now private 63*62c56f98SSadaf Ebrahimi 64*62c56f98SSadaf EbrahimiDirect access to fields of structures (`struct` types) declared in public headers is no longer supported. In Mbed TLS 3, the layout of structures is not considered part of the stable API, and minor versions (3.1, 3.2, etc.) may add, remove, rename, reorder or change the type of structure fields. 65*62c56f98SSadaf Ebrahimi 66*62c56f98SSadaf EbrahimiThere is a small number of exceptions where some fields are guaranteed to remain stable throughout the lifetime of Mbed TLS 3.x. These fields are explicitly documented as public. Please note that even if all the fields of a structure are public, future versions may add new fields. Also, as before, some public fields should be considered read-only, since modifying them may make the structure inconsistent; check the documentation in each case. 67*62c56f98SSadaf Ebrahimi 68*62c56f98SSadaf EbrahimiAttempting to access a private field directly will result in a compilation error. 69*62c56f98SSadaf Ebrahimi 70*62c56f98SSadaf EbrahimiIf you were accessing structure fields directly, and these fields are not documented as public, you need to change your code. If an accessor (getter/setter) function exists, use that. Direct accessor functions are usually called `mbedtls_<MODULE>_{get,set}_<FIELD>` or `mbedtls_<MODULE>_<STRUCTURE>_{get,set}_<FIELD>`. Accessor functions that change the format may use different verbs, for example `read`/`write` for functions that import/export data from/to a text or byte string. 71*62c56f98SSadaf Ebrahimi 72*62c56f98SSadaf EbrahimiIf no accessor function exists, please open an [enhancement request against Mbed TLS](https://github.com/Mbed-TLS/mbedtls/issues/new?template=feature_request.md) and describe your use case. The Mbed TLS development team is aware that some useful accessor functions are missing in the 3.0 release, and we expect to add them to the first minor release(s) (3.1, etc.). 73*62c56f98SSadaf Ebrahimi 74*62c56f98SSadaf EbrahimiAs a last resort, you can access the field `foo` of a structure `bar` by writing `bar.MBEDTLS_PRIVATE(foo)`. Note that you do so at your own risk, since such code is likely to break in a future minor version of Mbed TLS. 75*62c56f98SSadaf Ebrahimi 76*62c56f98SSadaf Ebrahimi### Move part of timing module out of the library 77*62c56f98SSadaf Ebrahimi 78*62c56f98SSadaf EbrahimiThe change affects users who use any of the following functions: 79*62c56f98SSadaf Ebrahimi`mbedtls_timing_self_test()`, `mbedtls_hardclock_poll()`, 80*62c56f98SSadaf Ebrahimi`mbedtls_timing_hardclock()` and `mbedtls_set_alarm()`. 81*62c56f98SSadaf Ebrahimi 82*62c56f98SSadaf EbrahimiIf you were relying on these functions, you'll now need to change to using your 83*62c56f98SSadaf Ebrahimiplatform's corresponding functions directly. 84*62c56f98SSadaf Ebrahimi 85*62c56f98SSadaf Ebrahimi### Deprecated net.h file was removed 86*62c56f98SSadaf Ebrahimi 87*62c56f98SSadaf EbrahimiThe file `include/mbedtls/net.h` was removed because its only function was to 88*62c56f98SSadaf Ebrahimiinclude `mbedtls/net_sockets.h` which now should be included directly. 89*62c56f98SSadaf Ebrahimi 90*62c56f98SSadaf Ebrahimi### Remove `MBEDTLS_CHECK_PARAMS` option 91*62c56f98SSadaf Ebrahimi 92*62c56f98SSadaf EbrahimiThis change does not affect users who use the default configuration; it only 93*62c56f98SSadaf Ebrahimiaffects users who enabled that option. 94*62c56f98SSadaf Ebrahimi 95*62c56f98SSadaf EbrahimiThe option `MBEDTLS_CHECK_PARAMS` (disabled by default) enabled certain kinds 96*62c56f98SSadaf Ebrahimiof “parameter validation”. It covered two kinds of validations: 97*62c56f98SSadaf Ebrahimi 98*62c56f98SSadaf Ebrahimi- In some functions that require a valid pointer, “parameter validation” checks 99*62c56f98SSadaf Ebrahimithat the pointer is non-null. With the feature disabled, a null pointer is not 100*62c56f98SSadaf Ebrahimitreated differently from any other invalid pointer, and typically leads to a 101*62c56f98SSadaf Ebrahimiruntime crash. 90% of the uses of the feature are of this kind. 102*62c56f98SSadaf Ebrahimi- In some functions that take an enum-like argument, “parameter validation” 103*62c56f98SSadaf Ebrahimichecks that the value is a valid one. With the feature disabled, an invalid 104*62c56f98SSadaf Ebrahimivalue causes a silent default to one of the valid values. 105*62c56f98SSadaf Ebrahimi 106*62c56f98SSadaf EbrahimiThe default reaction to a failed check was to call a function 107*62c56f98SSadaf Ebrahimi`mbedtls_param_failed()` which the application had to provide. If this function 108*62c56f98SSadaf Ebrahimireturned, its caller returned an error `MBEDTLS_ERR_xxx_BAD_INPUT_DATA`. 109*62c56f98SSadaf Ebrahimi 110*62c56f98SSadaf EbrahimiThis feature was only used in some classic (non-PSA) cryptography modules. It was 111*62c56f98SSadaf Ebrahiminot used in X.509, TLS or in PSA crypto, and it was not implemented in all 112*62c56f98SSadaf Ebrahimiclassic crypto modules. 113*62c56f98SSadaf Ebrahimi 114*62c56f98SSadaf EbrahimiThis feature has been removed. The library no longer checks for NULL pointers; 115*62c56f98SSadaf Ebrahimichecks for enum-like arguments will be kept or re-introduced on a case-by-case 116*62c56f98SSadaf Ebrahimibasis, but their presence will no longer be dependent on a compile-time option. 117*62c56f98SSadaf Ebrahimi 118*62c56f98SSadaf EbrahimiValidation of enum-like values is somewhat useful, but not extremely important, 119*62c56f98SSadaf Ebrahimibecause the parameters concerned are usually constants in applications. 120*62c56f98SSadaf Ebrahimi 121*62c56f98SSadaf EbrahimiFor more information see issue #4313. 122*62c56f98SSadaf Ebrahimi 123*62c56f98SSadaf Ebrahimi### Remove the `MBEDTLS_TEST_NULL_ENTROPY` configuration option 124*62c56f98SSadaf Ebrahimi 125*62c56f98SSadaf EbrahimiThis does not affect users who use the default `mbedtls_config.h`, as this option was 126*62c56f98SSadaf Ebrahimialready off by default. 127*62c56f98SSadaf Ebrahimi 128*62c56f98SSadaf EbrahimiIf you were using the `MBEDTLS_TEST_NULL_ENTROPY` option and your platform 129*62c56f98SSadaf Ebrahimidoesn't have any entropy source, you should use `MBEDTLS_ENTROPY_NV_SEED` 130*62c56f98SSadaf Ebrahimiand make sure your device is provisioned with a strong random seed. 131*62c56f98SSadaf EbrahimiAlternatively, for testing purposes only, you can create and register a fake 132*62c56f98SSadaf Ebrahimientropy function. 133*62c56f98SSadaf Ebrahimi 134*62c56f98SSadaf Ebrahimi### Remove the HAVEGE module 135*62c56f98SSadaf Ebrahimi 136*62c56f98SSadaf EbrahimiThis doesn't affect people using the default configuration as it was already 137*62c56f98SSadaf Ebrahimidisabled by default. 138*62c56f98SSadaf Ebrahimi 139*62c56f98SSadaf EbrahimiThis only affects users who called the HAVEGE modules directly (not 140*62c56f98SSadaf Ebrahimirecommended), or users who used it through the entropy module but had it as the 141*62c56f98SSadaf Ebrahimionly source of entropy. If you're in that case, please declare OS or hardware 142*62c56f98SSadaf EbrahimiRNG interfaces with `mbedtls_entropy_add_source()` and/or use an entropy seed 143*62c56f98SSadaf Ebrahimifile created securely during device provisioning. See 144*62c56f98SSadaf Ebrahimi<https://mbed-tls.readthedocs.io/en/latest/kb/how-to/add-entropy-sources-to-entropy-pool> for more 145*62c56f98SSadaf Ebrahimiinformation. 146*62c56f98SSadaf Ebrahimi 147*62c56f98SSadaf Ebrahimi### Remove helpers for the transition from Mbed TLS 1.3 to Mbed TLS 2.0 148*62c56f98SSadaf Ebrahimi 149*62c56f98SSadaf EbrahimiThis only affects people who've been using Mbed TLS since before version 2.0 150*62c56f98SSadaf Ebrahimiand still relied on `compat-1.3.h` in their code. 151*62c56f98SSadaf Ebrahimi 152*62c56f98SSadaf EbrahimiPlease use the new names directly in your code; `scripts/rename.pl` (from any 153*62c56f98SSadaf Ebrahimiof the 2.x releases — no longer included in 3.0) might help you do that. 154*62c56f98SSadaf Ebrahimi 155*62c56f98SSadaf Ebrahimi 156*62c56f98SSadaf Ebrahimi## Low-level crypto 157*62c56f98SSadaf Ebrahimi 158*62c56f98SSadaf EbrahimiPlease also refer to the section [High-level crypto](#high-level-crypto) for 159*62c56f98SSadaf Ebrahimichanges that could sit in either category. 160*62c56f98SSadaf Ebrahimi 161*62c56f98SSadaf Ebrahimi### Deprecated functions were removed from bignum 162*62c56f98SSadaf Ebrahimi 163*62c56f98SSadaf EbrahimiThe function `mbedtls_mpi_is_prime()` was removed. Please use 164*62c56f98SSadaf Ebrahimi`mbedtls_mpi_is_prime_ext()` instead which additionally allows specifying the 165*62c56f98SSadaf Ebrahiminumber of Miller-Rabin rounds. 166*62c56f98SSadaf Ebrahimi 167*62c56f98SSadaf Ebrahimi### Deprecated functions were removed from DRBGs 168*62c56f98SSadaf Ebrahimi 169*62c56f98SSadaf EbrahimiThe functions `mbedtls_ctr_drbg_update_ret()` and `mbedtls_hmac_drbg_update_ret()` 170*62c56f98SSadaf Ebrahimiwere renamed to replace the corresponding functions without `_ret` appended. Please call 171*62c56f98SSadaf Ebrahimithe name without `_ret` appended and check the return value. 172*62c56f98SSadaf Ebrahimi 173*62c56f98SSadaf Ebrahimi### Deprecated hex-encoded primes were removed from DHM 174*62c56f98SSadaf Ebrahimi 175*62c56f98SSadaf EbrahimiThe macros `MBEDTLS_DHM_RFC5114_MODP_2048_P`, `MBEDTLS_DHM_RFC5114_MODP_2048_G`, 176*62c56f98SSadaf Ebrahimi`MBEDTLS_DHM_RFC3526_MODP_2048_P`, `MBEDTLS_DHM_RFC3526_MODP_2048_G`, 177*62c56f98SSadaf Ebrahimi`MBEDTLS_DHM_RFC3526_MODP_3072_P`, `MBEDTLS_DHM_RFC3526_MODP_3072_G`, 178*62c56f98SSadaf Ebrahimi`MBEDTLS_DHM_RFC3526_MODP_4096_P `and `MBEDTLS_DHM_RFC3526_MODP_4096_G` were 179*62c56f98SSadaf Ebrahimiremoved. The primes from RFC 5114 are deprecated because their derivation is not 180*62c56f98SSadaf Ebrahimidocumented and therefore their usage constitutes a security risk; they are fully 181*62c56f98SSadaf Ebrahimiremoved from the library. Please use parameters from RFC 3526 (still in the 182*62c56f98SSadaf Ebrahimilibrary, only in binary form) or RFC 7919 (also available in the library) or 183*62c56f98SSadaf Ebrahimiother trusted sources instead. 184*62c56f98SSadaf Ebrahimi 185*62c56f98SSadaf Ebrahimi### Deprecated functions were removed from hashing modules 186*62c56f98SSadaf Ebrahimi 187*62c56f98SSadaf EbrahimiModules: MD5, SHA1, SHA256, SHA512, MD. 188*62c56f98SSadaf Ebrahimi 189*62c56f98SSadaf Ebrahimi- The functions `mbedtls_xxx_starts_ret()`, `mbedtls_xxx_update_ret()`, 190*62c56f98SSadaf Ebrahimi `mbedtls_xxx_finish_ret()` and `mbedtls_xxx_ret()` were renamed to replace 191*62c56f98SSadaf Ebrahimi the corresponding functions without `_ret` appended. Please call the name without `_ret` appended and check the return value. 192*62c56f98SSadaf Ebrahimi- The function `mbedtls_md_init_ctx()` was removed; please use 193*62c56f98SSadaf Ebrahimi `mbedtls_md_setup()` instead. 194*62c56f98SSadaf Ebrahimi- The functions `mbedtls_xxx_process()` were removed. You normally don't need 195*62c56f98SSadaf Ebrahimi to call that from application code. However if you do (or if you want to 196*62c56f98SSadaf Ebrahimi provide your own version of that function), please use 197*62c56f98SSadaf Ebrahimi `mbedtls_internal_xxx_process()` instead, and check the return value. 198*62c56f98SSadaf Ebrahimi 199*62c56f98SSadaf Ebrahimi### Change `MBEDTLS_ECP_FIXED_POINT_OPTIM` behavior 200*62c56f98SSadaf Ebrahimi 201*62c56f98SSadaf EbrahimiThe option `MBEDTLS_ECP_FIXED_POINT_OPTIM` now increases code size and it does 202*62c56f98SSadaf Ebrahiminot increase peak RAM usage anymore. 203*62c56f98SSadaf Ebrahimi 204*62c56f98SSadaf EbrahimiIf you are limited by code size, you can define `MBEDTLS_ECP_FIXED_POINT_OPTIM` 205*62c56f98SSadaf Ebrahimito `0` in your config file. The impact depends on the number and size of 206*62c56f98SSadaf Ebrahimienabled curves. For example, for P-256 the difference is 1KB; see the documentation 207*62c56f98SSadaf Ebrahimiof this option for details. 208*62c56f98SSadaf Ebrahimi 209*62c56f98SSadaf Ebrahimi### Separated `MBEDTLS_SHA224_C` and `MBEDTLS_SHA256_C` 210*62c56f98SSadaf Ebrahimi 211*62c56f98SSadaf EbrahimiThis does not affect users who use the default `mbedtls_config.h`. `MBEDTLS_SHA256_C` 212*62c56f98SSadaf Ebrahimiwas enabled by default. Now both `MBEDTLS_SHA256_C` and `MBEDTLS_SHA224_C` are 213*62c56f98SSadaf Ebrahimienabled. 214*62c56f98SSadaf Ebrahimi 215*62c56f98SSadaf EbrahimiIf you were using custom config file with `MBEDTLS_SHA256_C` enabled, then 216*62c56f98SSadaf Ebrahimiyou will need to add `#define MBEDTLS_SHA224_C` option to your config. 217*62c56f98SSadaf EbrahimiCurrent version of the library does not support enabling `MBEDTLS_SHA256_C` 218*62c56f98SSadaf Ebrahimiwithout `MBEDTLS_SHA224_C`. 219*62c56f98SSadaf Ebrahimi 220*62c56f98SSadaf Ebrahimi### Replaced `MBEDTLS_SHA512_NO_SHA384` with `MBEDTLS_SHA384_C` 221*62c56f98SSadaf Ebrahimi 222*62c56f98SSadaf EbrahimiThis does not affect users who use the default `mbedtls_config.h`. 223*62c56f98SSadaf Ebrahimi`MBEDTLS_SHA512_NO_SHA384` was disabled by default, now `MBEDTLS_SHA384_C` is 224*62c56f98SSadaf Ebrahimienabled by default. 225*62c56f98SSadaf Ebrahimi 226*62c56f98SSadaf EbrahimiIf you were using a config file with both `MBEDTLS_SHA512_C` and 227*62c56f98SSadaf EbrahimiMBEDTLS_SHA512_NO_SHA384, then just remove the `MBEDTLS_SHA512_NO_SHA384`. 228*62c56f98SSadaf EbrahimiIf you were using a config file with `MBEDTLS_SHA512_C` and without 229*62c56f98SSadaf Ebrahimi`MBEDTLS_SHA512_NO_SHA384` and you need the SHA-384 algorithm, then add 230*62c56f98SSadaf Ebrahimi`#define MBEDTLS_SHA384_C` to your config file. 231*62c56f98SSadaf Ebrahimi 232*62c56f98SSadaf Ebrahimi### GCM multipart interface: application changes 233*62c56f98SSadaf Ebrahimi 234*62c56f98SSadaf EbrahimiThe GCM module now supports arbitrary chunked input in the multipart interface. 235*62c56f98SSadaf EbrahimiThis changes the interface for applications using the GCM module directly for multipart operations. 236*62c56f98SSadaf EbrahimiApplications using one-shot GCM or using GCM via the `mbedtls_cipher_xxx` or `psa_aead_xxx` interfaces do not require any changes. 237*62c56f98SSadaf Ebrahimi 238*62c56f98SSadaf Ebrahimi* `mbedtls_gcm_starts()` now only sets the mode and the nonce (IV). Call the new function `mbedtls_gcm_update_ad()` to pass the associated data. 239*62c56f98SSadaf Ebrahimi* `mbedtls_gcm_update()` now takes an extra parameter to indicate the actual output length. In Mbed TLS 2.x, applications had to pass inputs consisting of whole 16-byte blocks except for the last block (this limitation has been lifted). In this case: 240*62c56f98SSadaf Ebrahimi * As long as the input remains block-aligned, the output length is exactly the input length, as before. 241*62c56f98SSadaf Ebrahimi * If the length of the last input is not a multiple of 16, alternative implementations may return the last partial block in the call to `mbedtls_gcm_finish()` instead of returning it in the last call to `mbedtls_gcm_update()`. 242*62c56f98SSadaf Ebrahimi* `mbedtls_gcm_finish()` now takes an extra output buffer for the last partial block. This is needed for alternative implementations that can only process a whole block at a time. 243*62c56f98SSadaf Ebrahimi 244*62c56f98SSadaf Ebrahimi### GCM interface changes: impact for alternative implementations 245*62c56f98SSadaf Ebrahimi 246*62c56f98SSadaf EbrahimiThe GCM multipart interface has changed as described in [“GCM multipart interface: application changes”](#gcm-multipart-interface-application-changes). The consequences for an alternative implementation of GCM (`MBEDTLS_GCM_ALT`) are as follows: 247*62c56f98SSadaf Ebrahimi 248*62c56f98SSadaf Ebrahimi* `mbedtls_gcm_starts()` now only sets the mode and the nonce (IV). The new function `mbedtls_gcm_update_ad()` receives the associated data. It may be called multiple times. 249*62c56f98SSadaf Ebrahimi* `mbedtls_gcm_update()` now allows arbitrary-length inputs, takes an extra parameter to indicate the actual output length. Alternative implementations may choose between two modes: 250*62c56f98SSadaf Ebrahimi * Always return the partial output immediately, even if it does not consist of a whole number of blocks. 251*62c56f98SSadaf Ebrahimi * Buffer the data for the last partial block, to be returned in the next call to `mbedtls_gcm_update()` or `mbedtls_gcm_finish()`. 252*62c56f98SSadaf Ebrahimi* `mbedtls_gcm_finish()` now takes an extra output buffer for the last partial block if needed. 253*62c56f98SSadaf Ebrahimi 254*62c56f98SSadaf Ebrahimi### The configuration option `MBEDTLS_ECP_NO_INTERNAL_RNG` was removed 255*62c56f98SSadaf Ebrahimi 256*62c56f98SSadaf EbrahimiThis doesn't affect users of the default configuration; it only affects people 257*62c56f98SSadaf Ebrahimiwho were explicitly setting this option. 258*62c56f98SSadaf Ebrahimi 259*62c56f98SSadaf EbrahimiThis was a trade-off between code size and countermeasures; it is no longer 260*62c56f98SSadaf Ebrahimirelevant as the countermeasure is now always on at no cost in code size. 261*62c56f98SSadaf Ebrahimi 262*62c56f98SSadaf Ebrahimi### SHA-512 and SHA-256 output type change 263*62c56f98SSadaf Ebrahimi 264*62c56f98SSadaf EbrahimiThe output parameter of `mbedtls_sha256_finish()`, `mbedtls_sha256()`, `mbedtls_sha512_finish()`, `mbedtls_sha512()` now has a pointer type rather than array type. This makes no difference in terms of C semantics, but removes spurious warnings in some compilers when outputting a SHA-384 hash into a 48-byte buffer or a SHA-224 hash into a 28-byte buffer. 265*62c56f98SSadaf Ebrahimi 266*62c56f98SSadaf EbrahimiThis makes no difference to a vast majority of applications. If your code takes a pointer to one of these functions, you may need to change the type of the pointer. 267*62c56f98SSadaf Ebrahimi 268*62c56f98SSadaf EbrahimiAlternative implementations of the SHA256 and SHA512 modules must adjust their functions' prototype accordingly. 269*62c56f98SSadaf Ebrahimi 270*62c56f98SSadaf Ebrahimi### Deprecated error codes for hardware failures were removed 271*62c56f98SSadaf Ebrahimi 272*62c56f98SSadaf Ebrahimi- The macros `MBEDTLS_ERR_xxx_FEATURE_UNAVAILABLE` from various crypto modules 273*62c56f98SSadaf Ebrahimi were removed; `MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED` is now used 274*62c56f98SSadaf Ebrahimi instead. 275*62c56f98SSadaf Ebrahimi- The macro `MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION` was removed; 276*62c56f98SSadaf Ebrahimi `MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED` is now used instead. 277*62c56f98SSadaf Ebrahimi- The macros `MBEDTLS_ERR_xxx_HW_ACCEL_FAILED` from various crypto modules 278*62c56f98SSadaf Ebrahimi were removed; `MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED` is now used instead. 279*62c56f98SSadaf Ebrahimi 280*62c56f98SSadaf Ebrahimi### Deprecated error codes for invalid input data were removed 281*62c56f98SSadaf Ebrahimi 282*62c56f98SSadaf Ebrahimi- The macros `MBEDTLS_ERR_xxx_INVALID_KEY_LENGTH` from ARIA and Camellia 283*62c56f98SSadaf Ebrahimi modules were removed; `MBEDTLS_ERR_xxx_BAD_INPUT_DATA` is now used instead. 284*62c56f98SSadaf Ebrahimi 285*62c56f98SSadaf Ebrahimi### Remove the mode parameter from RSA functions 286*62c56f98SSadaf Ebrahimi 287*62c56f98SSadaf EbrahimiThis affects all users who use the RSA encrypt, decrypt, sign and 288*62c56f98SSadaf Ebrahimiverify APIs. 289*62c56f98SSadaf Ebrahimi 290*62c56f98SSadaf EbrahimiThe RSA module no longer supports private-key operations with the public key or 291*62c56f98SSadaf Ebrahimivice versa. As a consequence, RSA operation functions no longer have a mode 292*62c56f98SSadaf Ebrahimiparameter. If you were calling RSA operations with the normal mode (public key 293*62c56f98SSadaf Ebrahimifor verification or encryption, private key for signature or decryption), remove 294*62c56f98SSadaf Ebrahimithe `MBEDTLS_RSA_PUBLIC` or `MBEDTLS_RSA_PRIVATE` argument. If you were calling 295*62c56f98SSadaf EbrahimiRSA operations with the wrong mode, which rarely makes sense from a security 296*62c56f98SSadaf Ebrahimiperspective, this is no longer supported. 297*62c56f98SSadaf Ebrahimi 298*62c56f98SSadaf Ebrahimi### Deprecated functions were removed from AES 299*62c56f98SSadaf Ebrahimi 300*62c56f98SSadaf EbrahimiThe functions `mbedtls_aes_encrypt()` and `mbedtls_aes_decrypt()` were 301*62c56f98SSadaf Ebrahimiremoved. 302*62c56f98SSadaf Ebrahimi 303*62c56f98SSadaf EbrahimiIf you're simply using the AES module, you should be calling the higher-level 304*62c56f98SSadaf Ebrahimifunctions `mbedtls_aes_crypt_xxx()`. 305*62c56f98SSadaf Ebrahimi 306*62c56f98SSadaf EbrahimiIf you're providing an alternative implementation using 307*62c56f98SSadaf Ebrahimi`MBEDTLS_AES_ENCRYPT_ALT` or `MBEDTLS_AES_DECRYPT_ALT`, you should be 308*62c56f98SSadaf Ebrahimireplacing the removed functions with `mbedtls_internal_aes_encrypt()` and 309*62c56f98SSadaf Ebrahimi`mbedtls_internal_aes_decrypt()` respectively. 310*62c56f98SSadaf Ebrahimi 311*62c56f98SSadaf Ebrahimi### Deprecated functions were removed from ECDSA 312*62c56f98SSadaf Ebrahimi 313*62c56f98SSadaf EbrahimiThe functions `mbedtls_ecdsa_write_signature_det()` and 314*62c56f98SSadaf Ebrahimi`mbedtls_ecdsa_sign_det()` were removed. They were superseded by 315*62c56f98SSadaf Ebrahimi`mbedtls_ecdsa_write_signature()` and `mbedtls_ecdsa_sign_det_ext()` 316*62c56f98SSadaf Ebrahimirespectively. 317*62c56f98SSadaf Ebrahimi 318*62c56f98SSadaf Ebrahimi### Rename `mbedtls_*_ret()` cryptography functions whose deprecated variants have been removed 319*62c56f98SSadaf Ebrahimi 320*62c56f98SSadaf EbrahimiThis change affects users who were using the `mbedtls_*_ret()` cryptography 321*62c56f98SSadaf Ebrahimifunctions. 322*62c56f98SSadaf Ebrahimi 323*62c56f98SSadaf EbrahimiThose functions were created based on now-deprecated functions according to a 324*62c56f98SSadaf Ebrahimirequirement that a function needs to return a value. This change brings back the 325*62c56f98SSadaf Ebrahimioriginal names of those functions. The renamed functions are: 326*62c56f98SSadaf Ebrahimi 327*62c56f98SSadaf Ebrahimi| name before this change | after the change | 328*62c56f98SSadaf Ebrahimi|--------------------------------|----------------------------| 329*62c56f98SSadaf Ebrahimi| `mbedtls_ctr_drbg_update_ret` | `mbedtls_ctr_drbg_update` | 330*62c56f98SSadaf Ebrahimi| `mbedtls_hmac_drbg_update_ret` | `mbedtls_hmac_drbg_update` | 331*62c56f98SSadaf Ebrahimi| `mbedtls_md5_starts_ret` | `mbedtls_md5_starts` | 332*62c56f98SSadaf Ebrahimi| `mbedtls_md5_update_ret` | `mbedtls_md5_update` | 333*62c56f98SSadaf Ebrahimi| `mbedtls_md5_finish_ret` | `mbedtls_md5_finish` | 334*62c56f98SSadaf Ebrahimi| `mbedtls_md5_ret` | `mbedtls_md5` | 335*62c56f98SSadaf Ebrahimi| `mbedtls_ripemd160_starts_ret` | `mbedtls_ripemd160_starts` | 336*62c56f98SSadaf Ebrahimi| `mbedtls_ripemd160_update_ret` | `mbedtls_ripemd160_update` | 337*62c56f98SSadaf Ebrahimi| `mbedtls_ripemd160_finish_ret` | `mbedtls_ripemd160_finish` | 338*62c56f98SSadaf Ebrahimi| `mbedtls_ripemd160_ret` | `mbedtls_ripemd160` | 339*62c56f98SSadaf Ebrahimi| `mbedtls_sha1_starts_ret` | `mbedtls_sha1_starts` | 340*62c56f98SSadaf Ebrahimi| `mbedtls_sha1_update_ret` | `mbedtls_sha1_update` | 341*62c56f98SSadaf Ebrahimi| `mbedtls_sha1_finish_ret` | `mbedtls_sha1_finish` | 342*62c56f98SSadaf Ebrahimi| `mbedtls_sha1_ret` | `mbedtls_sha1` | 343*62c56f98SSadaf Ebrahimi| `mbedtls_sha256_starts_ret` | `mbedtls_sha256_starts` | 344*62c56f98SSadaf Ebrahimi| `mbedtls_sha256_update_ret` | `mbedtls_sha256_update` | 345*62c56f98SSadaf Ebrahimi| `mbedtls_sha256_finish_ret` | `mbedtls_sha256_finish` | 346*62c56f98SSadaf Ebrahimi| `mbedtls_sha256_ret` | `mbedtls_sha256` | 347*62c56f98SSadaf Ebrahimi| `mbedtls_sha512_starts_ret` | `mbedtls_sha512_starts` | 348*62c56f98SSadaf Ebrahimi| `mbedtls_sha512_update_ret` | `mbedtls_sha512_update` | 349*62c56f98SSadaf Ebrahimi| `mbedtls_sha512_finish_ret` | `mbedtls_sha512_finish` | 350*62c56f98SSadaf Ebrahimi| `mbedtls_sha512_ret` | `mbedtls_sha512` | 351*62c56f98SSadaf Ebrahimi 352*62c56f98SSadaf EbrahimiTo migrate to the this change the user can keep the `*_ret` names in their code 353*62c56f98SSadaf Ebrahimiand include the `compat_2.x.h` header file which holds macros with proper 354*62c56f98SSadaf Ebrahimirenaming or to rename those functions in their code according to the list from 355*62c56f98SSadaf Ebrahimimentioned header file. 356*62c56f98SSadaf Ebrahimi 357*62c56f98SSadaf Ebrahimi### Remove the RNG parameter from RSA verify functions 358*62c56f98SSadaf Ebrahimi 359*62c56f98SSadaf EbrahimiRSA verification functions also no longer take random generator arguments (this 360*62c56f98SSadaf Ebrahimiwas only needed when using a private key). This affects all applications using 361*62c56f98SSadaf Ebrahimithe RSA verify functions. 362*62c56f98SSadaf Ebrahimi 363*62c56f98SSadaf Ebrahimi### Remove the padding parameters from `mbedtls_rsa_init()` 364*62c56f98SSadaf Ebrahimi 365*62c56f98SSadaf EbrahimiThis affects all users who use the RSA encrypt, decrypt, sign and 366*62c56f98SSadaf Ebrahimiverify APIs. 367*62c56f98SSadaf Ebrahimi 368*62c56f98SSadaf EbrahimiThe function `mbedtls_rsa_init()` no longer supports selecting the PKCS#1 v2.1 369*62c56f98SSadaf Ebrahimiencoding and its hash. It just selects the PKCS#1 v1.5 encoding by default. If 370*62c56f98SSadaf Ebrahimiyou were using the PKCS#1 v2.1 encoding you now need, subsequently to the call 371*62c56f98SSadaf Ebrahimito `mbedtls_rsa_init()`, to call `mbedtls_rsa_set_padding()` to set it. 372*62c56f98SSadaf Ebrahimi 373*62c56f98SSadaf EbrahimiTo choose the padding type when initializing a context, instead of 374*62c56f98SSadaf Ebrahimi 375*62c56f98SSadaf Ebrahimi```C 376*62c56f98SSadaf Ebrahimi mbedtls_rsa_init(ctx, padding, hash_id); 377*62c56f98SSadaf Ebrahimi``` 378*62c56f98SSadaf Ebrahimi 379*62c56f98SSadaf Ebrahimiuse 380*62c56f98SSadaf Ebrahimi 381*62c56f98SSadaf Ebrahimi```C 382*62c56f98SSadaf Ebrahimi mbedtls_rsa_init(ctx); 383*62c56f98SSadaf Ebrahimi mbedtls_rsa_set_padding(ctx, padding, hash_id); 384*62c56f98SSadaf Ebrahimi``` 385*62c56f98SSadaf Ebrahimi 386*62c56f98SSadaf EbrahimiTo use PKCS#1 v1.5 padding, instead of 387*62c56f98SSadaf Ebrahimi 388*62c56f98SSadaf Ebrahimi```C 389*62c56f98SSadaf Ebrahimi mbedtls_rsa_init(ctx, MBEDTLS_RSA_PKCS_V15, <ignored>); 390*62c56f98SSadaf Ebrahimi``` 391*62c56f98SSadaf Ebrahimi 392*62c56f98SSadaf Ebrahimijust use 393*62c56f98SSadaf Ebrahimi 394*62c56f98SSadaf Ebrahimi```C 395*62c56f98SSadaf Ebrahimi mbedtls_rsa_init(ctx); 396*62c56f98SSadaf Ebrahimi``` 397*62c56f98SSadaf Ebrahimi 398*62c56f98SSadaf Ebrahimi 399*62c56f98SSadaf Ebrahimi## High-level crypto 400*62c56f98SSadaf Ebrahimi 401*62c56f98SSadaf EbrahimiPlease also refer to the section [Low-level crypto](#low-level-crypto) for 402*62c56f98SSadaf Ebrahimichanges that could sit in either category. 403*62c56f98SSadaf Ebrahimi 404*62c56f98SSadaf Ebrahimi### Calling `mbedtls_cipher_finish()` is mandatory for all multi-part operations 405*62c56f98SSadaf Ebrahimi 406*62c56f98SSadaf EbrahimiThis only affects people who use the cipher module to perform AEAD operations 407*62c56f98SSadaf Ebrahimiusing the multi-part API. 408*62c56f98SSadaf Ebrahimi 409*62c56f98SSadaf EbrahimiPreviously, the documentation didn't state explicitly if it was OK to call 410*62c56f98SSadaf Ebrahimi`mbedtls_cipher_check_tag()` or `mbedtls_cipher_write_tag()` directly after 411*62c56f98SSadaf Ebrahimithe last call to `mbedtls_cipher_update()` — that is, without calling 412*62c56f98SSadaf Ebrahimi`mbedtls_cipher_finish()` in-between. If you code was missing that call, 413*62c56f98SSadaf Ebrahimiplease add it and be prepared to get as much as 15 bytes of output. 414*62c56f98SSadaf Ebrahimi 415*62c56f98SSadaf EbrahimiCurrently the output is always 0 bytes, but it may be more when alternative 416*62c56f98SSadaf Ebrahimiimplementations of the underlying primitives are in use, or with future 417*62c56f98SSadaf Ebrahimiversions of the library. 418*62c56f98SSadaf Ebrahimi 419*62c56f98SSadaf Ebrahimi### Remove MD2, MD4, RC4, Blowfish and XTEA algorithms 420*62c56f98SSadaf Ebrahimi 421*62c56f98SSadaf EbrahimiThis change affects users of the MD2, MD4, RC4, Blowfish and XTEA algorithms. 422*62c56f98SSadaf Ebrahimi 423*62c56f98SSadaf EbrahimiThey are already niche or obsolete and most of them are weak or broken. For 424*62c56f98SSadaf Ebrahimithose reasons possible users should consider switching to modern and safe 425*62c56f98SSadaf Ebrahimialternatives to be found in literature. 426*62c56f98SSadaf Ebrahimi 427*62c56f98SSadaf Ebrahimi### Deprecated functions were removed from cipher 428*62c56f98SSadaf Ebrahimi 429*62c56f98SSadaf EbrahimiThe functions `mbedtls_cipher_auth_encrypt()` and 430*62c56f98SSadaf Ebrahimi`mbedtls_cipher_auth_decrypt()` were removed. They were superseded by 431*62c56f98SSadaf Ebrahimi`mbedtls_cipher_auth_encrypt_ext()` and `mbedtls_cipher_auth_decrypt_ext()` 432*62c56f98SSadaf Ebrahimirespectively which additionally support key wrapping algorithms such as 433*62c56f98SSadaf EbrahimiNIST_KW. 434*62c56f98SSadaf Ebrahimi 435*62c56f98SSadaf Ebrahimi### Extra parameter for the output buffer size 436*62c56f98SSadaf Ebrahimi 437*62c56f98SSadaf EbrahimiThe following functions now take an extra parameter indicating the size of the output buffer: 438*62c56f98SSadaf Ebrahimi 439*62c56f98SSadaf Ebrahimi* `mbedtls_ecdsa_write_signature()`, `mbedtls_ecdsa_write_signature_restartable()` 440*62c56f98SSadaf Ebrahimi* `mbedtls_pk_sign()`, `mbedtls_pk_sign_restartable()` 441*62c56f98SSadaf Ebrahimi 442*62c56f98SSadaf EbrahimiThe requirements for the output buffer have not changed, but passing a buffer that is too small now reliably causes the functions to return an error, rather than overflowing the buffer. 443*62c56f98SSadaf Ebrahimi 444*62c56f98SSadaf Ebrahimi### Signature functions now require the hash length to match the expected value 445*62c56f98SSadaf Ebrahimi 446*62c56f98SSadaf EbrahimiThis affects users of the PK API as well as users of the low-level API in the RSA module. Users of the PSA API or of the ECDSA module are unaffected. 447*62c56f98SSadaf Ebrahimi 448*62c56f98SSadaf EbrahimiAll the functions in the RSA module that accept a `hashlen` parameter used to 449*62c56f98SSadaf Ebrahimiignore it unless the `md_alg` parameter was `MBEDTLS_MD_NONE`, indicating raw 450*62c56f98SSadaf Ebrahimidata was signed. The `hashlen` parameter is now always the size that is read 451*62c56f98SSadaf Ebrahimifrom the `hash` input buffer. This length must be equal to the output size of 452*62c56f98SSadaf Ebrahimithe hash algorithm used when signing a hash. (The requirements when signing 453*62c56f98SSadaf Ebrahimiraw data are unchanged.) This affects the following functions: 454*62c56f98SSadaf Ebrahimi 455*62c56f98SSadaf Ebrahimi* `mbedtls_rsa_pkcs1_sign`, `mbedtls_rsa_pkcs1_verify` 456*62c56f98SSadaf Ebrahimi* `mbedtls_rsa_rsassa_pkcs1_v15_sign`, `mbedtls_rsa_rsassa_pkcs1_v15_verify` 457*62c56f98SSadaf Ebrahimi* `mbedtls_rsa_rsassa_pss_sign`, `mbedtls_rsa_rsassa_pss_verify` 458*62c56f98SSadaf Ebrahimi* `mbedtls_rsa_rsassa_pss_sign_ext`, `mbedtls_rsa_rsassa_pss_verify_ext` 459*62c56f98SSadaf Ebrahimi 460*62c56f98SSadaf EbrahimiThe signature functions in the PK module no longer accept 0 as the `hash_len` parameter. The `hash_len` parameter is now always the size that is read from the `hash` input buffer. This affects the following functions: 461*62c56f98SSadaf Ebrahimi 462*62c56f98SSadaf Ebrahimi* `mbedtls_pk_sign`, `mbedtls_pk_verify` 463*62c56f98SSadaf Ebrahimi* `mbedtls_pk_sign_restartable`, `mbedtls_pk_verify_restartable` 464*62c56f98SSadaf Ebrahimi* `mbedtls_pk_verify_ext` 465*62c56f98SSadaf Ebrahimi 466*62c56f98SSadaf EbrahimiThe migration path is to pass the correct value to those functions. 467*62c56f98SSadaf Ebrahimi 468*62c56f98SSadaf Ebrahimi### Some function parameters were made const 469*62c56f98SSadaf Ebrahimi 470*62c56f98SSadaf EbrahimiVarious functions in the PK and ASN.1 modules had a `const` qualifier added to 471*62c56f98SSadaf Ebrahimisome of their parameters. 472*62c56f98SSadaf Ebrahimi 473*62c56f98SSadaf EbrahimiThis normally doesn't affect your code, unless you use pointers to reference 474*62c56f98SSadaf Ebrahimithose functions. In this case, you'll need to update the type of your pointers 475*62c56f98SSadaf Ebrahimiin order to match the new signature. 476*62c56f98SSadaf Ebrahimi 477*62c56f98SSadaf Ebrahimi### The RNG parameter is now mandatory for all functions that accept one 478*62c56f98SSadaf Ebrahimi 479*62c56f98SSadaf EbrahimiThis change affects all users who called a function accepting a `f_rng` 480*62c56f98SSadaf Ebrahimiparameter with `NULL` as the value of this argument; this is no longer 481*62c56f98SSadaf Ebrahimisupported. 482*62c56f98SSadaf Ebrahimi 483*62c56f98SSadaf EbrahimiThe changed functions are: the X.509 CRT and CSR writing functions; the PK and 484*62c56f98SSadaf EbrahimiRSA sign and decrypt functions; `mbedtls_rsa_private()`; the functions in DHM 485*62c56f98SSadaf Ebrahimiand ECDH that compute the shared secret; the scalar multiplication functions in 486*62c56f98SSadaf EbrahimiECP. 487*62c56f98SSadaf Ebrahimi 488*62c56f98SSadaf EbrahimiYou now need to pass a properly seeded, cryptographically secure RNG to all 489*62c56f98SSadaf Ebrahimifunctions that accept a `f_rng` parameter. It is of course still possible to 490*62c56f98SSadaf Ebrahimipass `NULL` as the context pointer `p_rng` if your RNG function doesn't need a 491*62c56f98SSadaf Ebrahimicontext. 492*62c56f98SSadaf Ebrahimi 493*62c56f98SSadaf EbrahimiAlternative implementations of a module (enabled with the `MBEDTLS_module_ALT` 494*62c56f98SSadaf Ebrahimiconfiguration options) may have their own internal and are free to ignore the 495*62c56f98SSadaf Ebrahimi`f_rng` argument but must allow users to pass one anyway. 496*62c56f98SSadaf Ebrahimi 497*62c56f98SSadaf Ebrahimi### Some functions gained an RNG parameter 498*62c56f98SSadaf Ebrahimi 499*62c56f98SSadaf EbrahimiThis affects users of the following functions: `mbedtls_ecp_check_pub_priv()`, 500*62c56f98SSadaf Ebrahimi`mbedtls_pk_check_pair()`, `mbedtls_pk_parse_key()`, and 501*62c56f98SSadaf Ebrahimi`mbedtls_pk_parse_keyfile()`. 502*62c56f98SSadaf Ebrahimi 503*62c56f98SSadaf EbrahimiYou now need to pass a properly seeded, cryptographically secure RNG when 504*62c56f98SSadaf Ebrahimicalling these functions. It is used for blinding, a countermeasure against 505*62c56f98SSadaf Ebrahimiside-channel attacks. 506*62c56f98SSadaf Ebrahimi 507*62c56f98SSadaf Ebrahimi 508*62c56f98SSadaf Ebrahimi## PSA 509*62c56f98SSadaf Ebrahimi 510*62c56f98SSadaf Ebrahimi### Deprecated names for PSA constants and types were removed 511*62c56f98SSadaf Ebrahimi 512*62c56f98SSadaf EbrahimiSome constants and types that were present in beta versions of the PSA Crypto 513*62c56f98SSadaf EbrahimiAPI were removed from version 1.0 of specification. Please switch to the new 514*62c56f98SSadaf Ebrahiminames provided by the 1.0 specification instead. 515*62c56f98SSadaf Ebrahimi 516*62c56f98SSadaf Ebrahimi 517*62c56f98SSadaf Ebrahimi## Changes that only affect alternative implementations 518*62c56f98SSadaf Ebrahimi 519*62c56f98SSadaf Ebrahimi### Internal / alt-focused headers were moved to a private location 520*62c56f98SSadaf Ebrahimi 521*62c56f98SSadaf EbrahimiThis shouldn't affect users who took care not to include headers that 522*62c56f98SSadaf Ebrahimiwere documented as internal, despite being in the public include directory. 523*62c56f98SSadaf Ebrahimi 524*62c56f98SSadaf EbrahimiIf you're providing alt implementations of ECP or RSA, you'll need to add our 525*62c56f98SSadaf Ebrahimi`library` directory to your include path when building your alt 526*62c56f98SSadaf Ebrahimiimplementations, and note that `ecp_internal.h` and `rsa_internal.h` have been 527*62c56f98SSadaf Ebrahimirenamed to `ecp_internal_alt.h` and `rsa_alt_helpers.h` respectively. 528*62c56f98SSadaf Ebrahimi 529*62c56f98SSadaf EbrahimiIf you're a library user and used to rely on having access to a structure or 530*62c56f98SSadaf Ebrahimifunction that's now in a private header, please reach out on the mailing list 531*62c56f98SSadaf Ebrahimiand explain your need; we'll consider adding a new API in a future version. 532*62c56f98SSadaf Ebrahimi 533*62c56f98SSadaf Ebrahimi### CCM interface changes: impact for alternative implementations 534*62c56f98SSadaf Ebrahimi 535*62c56f98SSadaf EbrahimiThe CCM interface has changed with the addition of support for 536*62c56f98SSadaf Ebrahimimulti-part operations. Five new API functions have been defined: 537*62c56f98SSadaf Ebrahimi `mbedtls_ccm_starts()`, `mbedtls_ccm_set_lengths()`, 538*62c56f98SSadaf Ebrahimi `mbedtls_ccm_update_ad()`, `mbedtls_ccm_update()` and `mbedtls_ccm_finish()`. 539*62c56f98SSadaf EbrahimiAlternative implementations of CCM (`MBEDTLS_CCM_ALT`) have now to 540*62c56f98SSadaf Ebrahimiimplement those additional five API functions. 541*62c56f98SSadaf Ebrahimi 542*62c56f98SSadaf Ebrahimi 543*62c56f98SSadaf Ebrahimi## X.509 544*62c56f98SSadaf Ebrahimi 545*62c56f98SSadaf Ebrahimi### Remove the certs module from the library 546*62c56f98SSadaf Ebrahimi 547*62c56f98SSadaf EbrahimiThis should not affect production use of the library, as the certificates and 548*62c56f98SSadaf Ebrahimikeys included there were never suitable for production use. 549*62c56f98SSadaf Ebrahimi 550*62c56f98SSadaf EbrahimiHowever it might affect you if you relied on them for testing purposes. In 551*62c56f98SSadaf Ebrahimithat case, please embed your own test certificates in your test code; now that 552*62c56f98SSadaf Ebrahimi`certs.c` is out of the library there is no longer any stability guaranteed 553*62c56f98SSadaf Ebrahimiand it may change in incompatible ways at any time. 554*62c56f98SSadaf Ebrahimi 555*62c56f98SSadaf Ebrahimi### Change the API to allow adding critical extensions to CSRs 556*62c56f98SSadaf Ebrahimi 557*62c56f98SSadaf EbrahimiThis affects applications that call the `mbedtls_x509write_csr_set_extension` 558*62c56f98SSadaf Ebrahimifunction. 559*62c56f98SSadaf Ebrahimi 560*62c56f98SSadaf EbrahimiThe API is changed to include the parameter `critical` which enables marking an 561*62c56f98SSadaf Ebrahimiextension included in a CSR as critical. To get the previous behavior pass 0. 562*62c56f98SSadaf Ebrahimi 563*62c56f98SSadaf Ebrahimi### Remove the config option `MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION` 564*62c56f98SSadaf Ebrahimi 565*62c56f98SSadaf EbrahimiThis change does not affect users of the default configuration; it only affects 566*62c56f98SSadaf Ebrahimiusers who enable this option. 567*62c56f98SSadaf Ebrahimi 568*62c56f98SSadaf EbrahimiThe X.509 standard says that implementations must reject critical extensions that 569*62c56f98SSadaf Ebrahimithey don't recognize, and this is what Mbed TLS does by default. This option 570*62c56f98SSadaf Ebrahimiallowed to continue parsing those certificates but didn't provide a convenient 571*62c56f98SSadaf Ebrahimiway to handle those extensions. 572*62c56f98SSadaf Ebrahimi 573*62c56f98SSadaf EbrahimiThe migration path from that option is to use the 574*62c56f98SSadaf Ebrahimi`mbedtls_x509_crt_parse_der_with_ext_cb()` function which is functionally 575*62c56f98SSadaf Ebrahimiequivalent to `mbedtls_x509_crt_parse_der()`, and/or 576*62c56f98SSadaf Ebrahimi`mbedtls_x509_crt_parse_der_nocopy()` but it calls the callback with every 577*62c56f98SSadaf Ebrahimiunsupported certificate extension and additionally the "certificate policies" 578*62c56f98SSadaf Ebrahimiextension if it contains any unsupported certificate policies. 579*62c56f98SSadaf Ebrahimi 580*62c56f98SSadaf Ebrahimi### Remove `MBEDTLS_X509_CHECK_*_KEY_USAGE` options from `mbedtls_config.h` 581*62c56f98SSadaf Ebrahimi 582*62c56f98SSadaf EbrahimiThis change affects users who have chosen the configuration options to disable the 583*62c56f98SSadaf Ebrahimilibrary's verification of the `keyUsage` and `extendedKeyUsage` fields of X.509 584*62c56f98SSadaf Ebrahimicertificates. 585*62c56f98SSadaf Ebrahimi 586*62c56f98SSadaf EbrahimiThe `MBEDTLS_X509_CHECK_KEY_USAGE` and `MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE` 587*62c56f98SSadaf Ebrahimiconfiguration options are removed and the X.509 code now behaves as if they were 588*62c56f98SSadaf Ebrahimialways enabled. It is consequently not possible anymore to disable at compile 589*62c56f98SSadaf Ebrahimitime the verification of the `keyUsage` and `extendedKeyUsage` fields of X.509 590*62c56f98SSadaf Ebrahimicertificates. 591*62c56f98SSadaf Ebrahimi 592*62c56f98SSadaf EbrahimiThe verification of the `keyUsage` and `extendedKeyUsage` fields is important, 593*62c56f98SSadaf Ebrahimidisabling it can cause security issues and it is thus not recommended. If the 594*62c56f98SSadaf Ebrahimiverification is for some reason undesirable, it can still be disabled by means 595*62c56f98SSadaf Ebrahimiof the verification callback function passed to `mbedtls_x509_crt_verify()` (see 596*62c56f98SSadaf Ebrahimithe documentation of this function for more information). 597*62c56f98SSadaf Ebrahimi 598*62c56f98SSadaf Ebrahimi### Remove the `MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3` option 599*62c56f98SSadaf Ebrahimi 600*62c56f98SSadaf EbrahimiThis change does not affect users who were using the default configuration, as 601*62c56f98SSadaf Ebrahimithis option was already disabled by default. Also, it does not affect users who 602*62c56f98SSadaf Ebrahimiare working with current V3 X.509 certificates. 603*62c56f98SSadaf Ebrahimi 604*62c56f98SSadaf EbrahimiExtensions were added in V3 of the X.509 specification, so pre-V3 certificates 605*62c56f98SSadaf Ebrahimicontaining extensions were never compliant. Mbed TLS now rejects them with a 606*62c56f98SSadaf Ebrahimiparsing error in all configurations, as it did previously in the default 607*62c56f98SSadaf Ebrahimiconfiguration. 608*62c56f98SSadaf Ebrahimi 609*62c56f98SSadaf EbrahimiIf you are working with the pre-V3 certificates you need to switch to the 610*62c56f98SSadaf Ebrahimicurrent ones. 611*62c56f98SSadaf Ebrahimi 612*62c56f98SSadaf Ebrahimi### Strengthen default algorithm selection for X.509 613*62c56f98SSadaf Ebrahimi 614*62c56f98SSadaf EbrahimiThis is described in the section [Strengthen default algorithm selection for X.509 and TLS](#strengthen-default-algorithm-selection-for-x.509-and-tls). 615*62c56f98SSadaf Ebrahimi 616*62c56f98SSadaf Ebrahimi### Remove wrapper for libpkcs11-helper 617*62c56f98SSadaf Ebrahimi 618*62c56f98SSadaf EbrahimiThis doesn't affect people using the default configuration as it was already 619*62c56f98SSadaf Ebrahimidisabled by default. 620*62c56f98SSadaf Ebrahimi 621*62c56f98SSadaf EbrahimiIf you used to rely on this module in order to store your private keys 622*62c56f98SSadaf Ebrahimisecurely, please have a look at the key management facilities provided by the 623*62c56f98SSadaf EbrahimiPSA crypto API. If you have a use case that's not covered yet by this API, 624*62c56f98SSadaf Ebrahimiplease reach out on the mailing list. 625*62c56f98SSadaf Ebrahimi 626*62c56f98SSadaf Ebrahimi 627*62c56f98SSadaf Ebrahimi## SSL 628*62c56f98SSadaf Ebrahimi 629*62c56f98SSadaf Ebrahimi### Remove support for TLS 1.0, 1.1 and DTLS 1.0 630*62c56f98SSadaf Ebrahimi 631*62c56f98SSadaf EbrahimiThis change affects users of the TLS 1.0, 1.1 and DTLS 1.0 protocols. 632*62c56f98SSadaf Ebrahimi 633*62c56f98SSadaf EbrahimiThese versions have been deprecated by RFC 8996. 634*62c56f98SSadaf EbrahimiKeeping them in the library creates opportunities for misconfiguration 635*62c56f98SSadaf Ebrahimiand possibly downgrade attacks. More generally, more code means a larger attack 636*62c56f98SSadaf Ebrahimisurface, even if the code is supposedly not used. 637*62c56f98SSadaf Ebrahimi 638*62c56f98SSadaf EbrahimiThe migration path is to adopt the latest versions of the protocol. 639*62c56f98SSadaf Ebrahimi 640*62c56f98SSadaf EbrahimiAs a consequence of removing TLS 1.0, support for CBC record splitting was 641*62c56f98SSadaf Ebrahimialso removed, as it was a work-around for a weakness in this particular 642*62c56f98SSadaf Ebrahimiversion. There is no migration path since the feature is no longer relevant. 643*62c56f98SSadaf Ebrahimi 644*62c56f98SSadaf EbrahimiAs a consequence of currently supporting only one version of (D)TLS (and in the 645*62c56f98SSadaf Ebrahimifuture 1.3 which will have a different version negotiation mechanism), support 646*62c56f98SSadaf Ebrahimifor fallback SCSV (RFC 7507) was also removed. There is no migration path as 647*62c56f98SSadaf Ebrahimiit's no longer useful with TLS 1.2 and later. 648*62c56f98SSadaf Ebrahimi 649*62c56f98SSadaf EbrahimiAs a consequence of currently supporting only one version of (D)TLS (and in the 650*62c56f98SSadaf Ebrahimifuture 1.3 which will have a different concept of ciphersuites), support for 651*62c56f98SSadaf Ebrahimiconfiguring ciphersuites separately for each version via 652*62c56f98SSadaf Ebrahimi`mbedtls_ssl_conf_ciphersuites_for_version()` was removed. Use 653*62c56f98SSadaf Ebrahimi`mbedtls_ssl_conf_ciphersuites()` to configure ciphersuites to use with (D)TLS 654*62c56f98SSadaf Ebrahimi1.2; in the future a different API will be added for (D)TLS 1.3. 655*62c56f98SSadaf Ebrahimi 656*62c56f98SSadaf Ebrahimi### Remove support for SSL 3.0 657*62c56f98SSadaf Ebrahimi 658*62c56f98SSadaf EbrahimiThis doesn't affect people using the default configuration as it was already 659*62c56f98SSadaf Ebrahimidisabled by default. 660*62c56f98SSadaf Ebrahimi 661*62c56f98SSadaf EbrahimiThis only affects TLS users who explicitly enabled `MBEDTLS_SSL_PROTO_SSL3` 662*62c56f98SSadaf Ebrahimiand relied on that version in order to communicate with peers that are not up 663*62c56f98SSadaf Ebrahimito date. If one of your peers is in that case, please try contacting them and 664*62c56f98SSadaf Ebrahimiencouraging them to upgrade their software. 665*62c56f98SSadaf Ebrahimi 666*62c56f98SSadaf Ebrahimi### Remove support for parsing SSLv2 ClientHello 667*62c56f98SSadaf Ebrahimi 668*62c56f98SSadaf EbrahimiThis doesn't affect people using the default configuration as it was already 669*62c56f98SSadaf Ebrahimidisabled by default. 670*62c56f98SSadaf Ebrahimi 671*62c56f98SSadaf EbrahimiThis only affects TLS servers that have clients who send an SSLv2 ClientHello. 672*62c56f98SSadaf EbrahimiThese days clients are very unlikely to do that. If you have a client that 673*62c56f98SSadaf Ebrahimidoes, please try contacting them and encouraging them to upgrade their 674*62c56f98SSadaf Ebrahimisoftware. 675*62c56f98SSadaf Ebrahimi 676*62c56f98SSadaf Ebrahimi### Remove support for truncated HMAC 677*62c56f98SSadaf Ebrahimi 678*62c56f98SSadaf EbrahimiThis affects users of truncated HMAC, that is, users who called 679*62c56f98SSadaf Ebrahimi`mbedtls_ssl_conf_truncated_hmac( ..., MBEDTLS_SSL_TRUNC_HMAC_ENABLED)`, 680*62c56f98SSadaf Ebrahimiregardless of whether the standard version was used or compatibility version 681*62c56f98SSadaf Ebrahimi(`MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT`). 682*62c56f98SSadaf Ebrahimi 683*62c56f98SSadaf EbrahimiThe recommended migration path for people who want minimal overhead is to use a 684*62c56f98SSadaf EbrahimiCCM-8 ciphersuite. 685*62c56f98SSadaf Ebrahimi 686*62c56f98SSadaf Ebrahimi### Remove support for TLS record-level compression 687*62c56f98SSadaf Ebrahimi 688*62c56f98SSadaf EbrahimiThis doesn't affect people using the default configuration as it was already 689*62c56f98SSadaf Ebrahimidisabled by default. 690*62c56f98SSadaf Ebrahimi 691*62c56f98SSadaf EbrahimiThis only affects TLS users who enabled `MBEDTLS_ZLIB_SUPPORT`. This will not 692*62c56f98SSadaf Ebrahimicause any failures however if you used to enable TLS record-level compression 693*62c56f98SSadaf Ebrahimiyou may find that your bandwidth usage increases without compression. There's 694*62c56f98SSadaf Ebrahimino general solution to this problem; application protocols might have their 695*62c56f98SSadaf Ebrahimiown compression mechanisms and are in a better position than the TLS stack to 696*62c56f98SSadaf Ebrahimiavoid variants of the CRIME and BREACH attacks. 697*62c56f98SSadaf Ebrahimi 698*62c56f98SSadaf Ebrahimi### Remove support for TLS RC4-based ciphersuites 699*62c56f98SSadaf Ebrahimi 700*62c56f98SSadaf EbrahimiThis does not affect people who used the default `mbedtls_config.h` and the default 701*62c56f98SSadaf Ebrahimilist of ciphersuites, as RC4-based ciphersuites were already not negotiated in 702*62c56f98SSadaf Ebrahimithat case. 703*62c56f98SSadaf Ebrahimi 704*62c56f98SSadaf EbrahimiPlease switch to any of the modern, recommended ciphersuites (based on 705*62c56f98SSadaf EbrahimiAES-GCM, AES-CCM or ChachaPoly for example) and if your peer doesn't support 706*62c56f98SSadaf Ebrahimiany, encourage them to upgrade their software. 707*62c56f98SSadaf Ebrahimi 708*62c56f98SSadaf Ebrahimi### Remove support for TLS single-DES ciphersuites 709*62c56f98SSadaf Ebrahimi 710*62c56f98SSadaf EbrahimiThis doesn't affect people using the default configuration as it was already 711*62c56f98SSadaf Ebrahimidisabled by default. 712*62c56f98SSadaf Ebrahimi 713*62c56f98SSadaf EbrahimiPlease switch to any of the modern, recommended ciphersuites (based on 714*62c56f98SSadaf EbrahimiAES-GCM, AES-CCM or ChachaPoly for example) and if your peer doesn't support 715*62c56f98SSadaf Ebrahimiany, encourage them to upgrade their software. 716*62c56f98SSadaf Ebrahimi 717*62c56f98SSadaf Ebrahimi### Remove support for TLS record-level hardware acceleration 718*62c56f98SSadaf Ebrahimi 719*62c56f98SSadaf EbrahimiThis doesn't affect people using the default configuration as it was already 720*62c56f98SSadaf Ebrahimidisabled by default. 721*62c56f98SSadaf Ebrahimi 722*62c56f98SSadaf EbrahimiThis feature had been broken for a while so we doubt anyone still used it. 723*62c56f98SSadaf EbrahimiHowever if you did, please reach out on the mailing list and let us know about 724*62c56f98SSadaf Ebrahimiyour use case. 725*62c56f98SSadaf Ebrahimi 726*62c56f98SSadaf Ebrahimi### Remove config option `MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME` 727*62c56f98SSadaf Ebrahimi 728*62c56f98SSadaf EbrahimiThis doesn't affect people using the default configuration. 729*62c56f98SSadaf Ebrahimi 730*62c56f98SSadaf EbrahimiThis option has not had any effect for a long time. Please use the `lifetime` 731*62c56f98SSadaf Ebrahimiparameter of `mbedtls_ssl_ticket_setup()` instead. 732*62c56f98SSadaf Ebrahimi 733*62c56f98SSadaf Ebrahimi### Combine the `MBEDTLS_SSL_CID_PADDING_GRANULARITY` and `MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY` options 734*62c56f98SSadaf Ebrahimi 735*62c56f98SSadaf EbrahimiThis change affects users who modified the default `mbedtls_config.h` padding granularity 736*62c56f98SSadaf Ebrahimisettings, i.e. enabled at least one of the options. 737*62c56f98SSadaf Ebrahimi 738*62c56f98SSadaf EbrahimiThe `mbedtls_config.h` options `MBEDTLS_SSL_CID_PADDING_GRANULARITY` and 739*62c56f98SSadaf Ebrahimi`MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY` were combined into one option because 740*62c56f98SSadaf Ebrahimithey used exactly the same padding mechanism and hence their respective padding 741*62c56f98SSadaf Ebrahimigranularities can be used in exactly the same way. This change simplifies the 742*62c56f98SSadaf Ebrahimicode maintenance. 743*62c56f98SSadaf Ebrahimi 744*62c56f98SSadaf EbrahimiThe new single option `MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY` can be used 745*62c56f98SSadaf Ebrahimifor both DTLS-CID and TLS 1.3. 746*62c56f98SSadaf Ebrahimi 747*62c56f98SSadaf Ebrahimi### TLS now favors faster curves over larger curves 748*62c56f98SSadaf Ebrahimi 749*62c56f98SSadaf EbrahimiThe default preference order for curves in TLS now favors resource usage (performance and memory consumption) over size. The exact order is unspecified and may change, but generally you can expect 256-bit curves to be preferred over larger curves. 750*62c56f98SSadaf Ebrahimi 751*62c56f98SSadaf EbrahimiIf you prefer a different order, call `mbedtls_ssl_conf_curves()` when configuring a TLS connection. 752*62c56f98SSadaf Ebrahimi 753*62c56f98SSadaf Ebrahimi### SSL key export interface change 754*62c56f98SSadaf Ebrahimi 755*62c56f98SSadaf EbrahimiThis affects users of the SSL key export APIs: 756*62c56f98SSadaf Ebrahimi``` 757*62c56f98SSadaf Ebrahimi mbedtls_ssl_conf_export_keys_cb() 758*62c56f98SSadaf Ebrahimi mbedtls_ssl_conf_export_keys_ext_cb() 759*62c56f98SSadaf Ebrahimi``` 760*62c56f98SSadaf Ebrahimi 761*62c56f98SSadaf EbrahimiThose APIs have been removed and replaced by the new API 762*62c56f98SSadaf Ebrahimi`mbedtls_ssl_set_export_keys_cb()`. This API differs from 763*62c56f98SSadaf Ebrahimithe previous key export API in the following ways: 764*62c56f98SSadaf Ebrahimi 765*62c56f98SSadaf Ebrahimi- It is no longer bound to an SSL configuration, but to an 766*62c56f98SSadaf Ebrahimi SSL context. This allows users to more easily identify the 767*62c56f98SSadaf Ebrahimi connection an exported key belongs to. 768*62c56f98SSadaf Ebrahimi- It no longer exports raw keys and IV. 769*62c56f98SSadaf Ebrahimi- A secret type parameter has been added to identify which key 770*62c56f98SSadaf Ebrahimi is being exported. For TLS 1.2, only the master secret is 771*62c56f98SSadaf Ebrahimi exported, but upcoming TLS 1.3 support will add other kinds of keys. 772*62c56f98SSadaf Ebrahimi- The callback now specifies a void return type, rather than 773*62c56f98SSadaf Ebrahimi returning an error code. It is the responsibility of the application 774*62c56f98SSadaf Ebrahimi to handle failures in the key export callback, for example by 775*62c56f98SSadaf Ebrahimi shutting down the TLS connection. 776*62c56f98SSadaf Ebrahimi 777*62c56f98SSadaf EbrahimiFor users which do not rely on raw keys and IV, adjusting to the new 778*62c56f98SSadaf Ebrahimicallback type should be straightforward — see the example programs 779*62c56f98SSadaf Ebrahimi`programs/ssl/ssl_client2` and `programs/ssl/ssl_server2` for callbacks 780*62c56f98SSadaf Ebrahimifor NSSKeylog, EAP-TLS and DTLS-SRTP. 781*62c56f98SSadaf Ebrahimi 782*62c56f98SSadaf EbrahimiUsers which require access to the raw keys used to secure application 783*62c56f98SSadaf Ebrahimitraffic may derive those by hand based on the master secret and the 784*62c56f98SSadaf Ebrahimihandshake transcript hashes which can be obtained from the raw data 785*62c56f98SSadaf Ebrahimion the wire. Such users are also encouraged to reach out to the 786*62c56f98SSadaf EbrahimiMbed TLS team on the mailing list, to let the team know about their 787*62c56f98SSadaf Ebrahimiuse case. 788*62c56f98SSadaf Ebrahimi 789*62c56f98SSadaf Ebrahimi### Remove MaximumFragmentLength (MFL) query API 790*62c56f98SSadaf Ebrahimi 791*62c56f98SSadaf EbrahimiThis affects users which use the MFL query APIs 792*62c56f98SSadaf Ebrahimi`mbedtls_ssl_get_{input,output}_max_frag_len()` to 793*62c56f98SSadaf Ebrahimiinfer upper bounds on the plaintext size of incoming and 794*62c56f98SSadaf Ebrahimioutgoing record. 795*62c56f98SSadaf Ebrahimi 796*62c56f98SSadaf EbrahimiUsers should switch to `mbedtls_ssl_get_max_{in,out}_record_payload()` 797*62c56f98SSadaf Ebrahimiinstead, which also provides such upper bounds but takes more factors 798*62c56f98SSadaf Ebrahimithan just the MFL configuration into account. 799*62c56f98SSadaf Ebrahimi 800*62c56f98SSadaf Ebrahimi### Relaxed semantics for PSK configuration 801*62c56f98SSadaf Ebrahimi 802*62c56f98SSadaf EbrahimiThis affects users which call the PSK configuration APIs 803*62c56f98SSadaf Ebrahimi`mbedtls_ssl_conf_psk()` and `mbedtls_ssl_conf_psk_opaque()` 804*62c56f98SSadaf Ebrahimimultiple times on the same SSL configuration. 805*62c56f98SSadaf Ebrahimi 806*62c56f98SSadaf EbrahimiIn Mbed TLS 2.x, users would observe later calls overwriting 807*62c56f98SSadaf Ebrahimithe effect of earlier calls, with the prevailing PSK being 808*62c56f98SSadaf Ebrahimithe one that has been configured last. In Mbed TLS 3.0, 809*62c56f98SSadaf Ebrahimicalling `mbedtls_ssl_conf_[opaque_]psk()` multiple times 810*62c56f98SSadaf Ebrahimiwill return an error, leaving the first PSK intact. 811*62c56f98SSadaf Ebrahimi 812*62c56f98SSadaf EbrahimiTo achieve equivalent functionality when migrating to Mbed TLS 3.0, 813*62c56f98SSadaf Ebrahimiusers calling `mbedtls_ssl_conf_[opaque_]psk()` multiple times should 814*62c56f98SSadaf Ebrahimiremove all but the last call, so that only one call to _either_ 815*62c56f98SSadaf Ebrahimi`mbedtls_ssl_conf_psk()` _or_ `mbedtls_ssl_conf_psk_opaque()` 816*62c56f98SSadaf Ebrahimiremains. 817*62c56f98SSadaf Ebrahimi 818*62c56f98SSadaf Ebrahimi### Remove the configuration to enable weak ciphersuites in SSL / TLS 819*62c56f98SSadaf Ebrahimi 820*62c56f98SSadaf EbrahimiThis does not affect users who use the default `mbedtls_config.h`, as this option was 821*62c56f98SSadaf Ebrahimialready off by default. 822*62c56f98SSadaf Ebrahimi 823*62c56f98SSadaf EbrahimiIf you were using a weak cipher, please switch to any of the modern, 824*62c56f98SSadaf Ebrahimirecommended ciphersuites (based on AES-GCM, AES-CCM or ChachaPoly for example) 825*62c56f98SSadaf Ebrahimiand if your peer doesn't support any, encourage them to upgrade their software. 826*62c56f98SSadaf Ebrahimi 827*62c56f98SSadaf EbrahimiIf you were using a ciphersuite without encryption, you just have to 828*62c56f98SSadaf Ebrahimienable `MBEDTLS_CIPHER_NULL_CIPHER` now. 829*62c56f98SSadaf Ebrahimi 830*62c56f98SSadaf Ebrahimi### Remove the `MBEDTLS_SSL_MAX_CONTENT_LEN` configuration option 831*62c56f98SSadaf Ebrahimi 832*62c56f98SSadaf EbrahimiThis affects users who use the `MBEDTLS_SSL_MAX_CONTENT_LEN` option to 833*62c56f98SSadaf Ebrahimiset the maximum length of incoming and outgoing plaintext fragments, 834*62c56f98SSadaf Ebrahimiwhich can save memory by reducing the size of the TLS I/O buffers. 835*62c56f98SSadaf Ebrahimi 836*62c56f98SSadaf EbrahimiThis option is replaced by the more fine-grained options 837*62c56f98SSadaf Ebrahimi`MBEDTLS_SSL_IN_CONTENT_LEN` and `MBEDTLS_SSL_OUT_CONTENT_LEN` that set 838*62c56f98SSadaf Ebrahimithe maximum incoming and outgoing plaintext fragment lengths, respectively. 839*62c56f98SSadaf Ebrahimi 840*62c56f98SSadaf Ebrahimi### Remove the SSL API `mbedtls_ssl_get_session_pointer()` 841*62c56f98SSadaf Ebrahimi 842*62c56f98SSadaf EbrahimiThis affects two classes of users: 843*62c56f98SSadaf Ebrahimi 844*62c56f98SSadaf Ebrahimi1. Users who manually inspect parts of the current session through 845*62c56f98SSadaf Ebrahimi direct structure field access. 846*62c56f98SSadaf Ebrahimi 847*62c56f98SSadaf Ebrahimi2. Users of session resumption who query the current session 848*62c56f98SSadaf Ebrahimi via `mbedtls_ssl_get_session_pointer()` prior to saving or exporting 849*62c56f98SSadaf Ebrahimi it via `mbedtls_ssl_session_copy()` or `mbedtls_ssl_session_save()`, 850*62c56f98SSadaf Ebrahimi respectively. 851*62c56f98SSadaf Ebrahimi 852*62c56f98SSadaf EbrahimiMigration paths: 853*62c56f98SSadaf Ebrahimi 854*62c56f98SSadaf Ebrahimi1. Mbed TLS 3.0 does not offer a migration path for the use case 1: Like many 855*62c56f98SSadaf Ebrahimi other Mbed TLS structures, the structure of `mbedtls_ssl_session` is no 856*62c56f98SSadaf Ebrahimi longer part of the public API in Mbed TLS 3.0, and direct structure field 857*62c56f98SSadaf Ebrahimi access is no longer supported. Please see the [section on private structure fields](#most-structure-fields-are-now-private) for more details. 858*62c56f98SSadaf Ebrahimi 859*62c56f98SSadaf Ebrahimi2. Users should replace calls to `mbedtls_ssl_get_session_pointer()` by 860*62c56f98SSadaf Ebrahimi calls to `mbedtls_ssl_get_session()` as demonstrated in the example 861*62c56f98SSadaf Ebrahimi program `programs/ssl/ssl_client2.c`. 862*62c56f98SSadaf Ebrahimi 863*62c56f98SSadaf Ebrahimi### Remove `MBEDTLS_SSL_DTLS_BADMAC_LIMIT` option 864*62c56f98SSadaf Ebrahimi 865*62c56f98SSadaf EbrahimiThis change does not affect users who used the default `mbedtls_config.h`, as the option 866*62c56f98SSadaf Ebrahimi`MBEDTLS_SSL_DTLS_BADMAC_LIMIT` was already on by default. 867*62c56f98SSadaf Ebrahimi 868*62c56f98SSadaf EbrahimiThis option was a trade-off between functionality and code size: it allowed 869*62c56f98SSadaf Ebrahimiusers who didn't need that feature to avoid paying the cost in code size, by 870*62c56f98SSadaf Ebrahimidisabling it. 871*62c56f98SSadaf Ebrahimi 872*62c56f98SSadaf EbrahimiThis option is no longer present, but its functionality is now always enabled. 873*62c56f98SSadaf Ebrahimi 874*62c56f98SSadaf Ebrahimi### Deprecated functions were removed from SSL 875*62c56f98SSadaf Ebrahimi 876*62c56f98SSadaf EbrahimiThe function `mbedtls_ssl_conf_dh_param()` was removed. Please use 877*62c56f98SSadaf Ebrahimi`mbedtls_ssl_conf_dh_param_bin()` or `mbedtls_ssl_conf_dh_param_ctx()` instead. 878*62c56f98SSadaf Ebrahimi 879*62c56f98SSadaf EbrahimiThe function `mbedtls_ssl_get_max_frag_len()` was removed. Please use 880*62c56f98SSadaf Ebrahimi`mbedtls_ssl_get_max_out_record_payload()` and 881*62c56f98SSadaf Ebrahimi`mbedtls_ssl_get_max_in_record_payload()` 882*62c56f98SSadaf Ebrahimiinstead. 883*62c56f98SSadaf Ebrahimi 884*62c56f98SSadaf Ebrahimi### Remove `MBEDTLS_SSL_RECORD_CHECKING` option and enable its action by default 885*62c56f98SSadaf Ebrahimi 886*62c56f98SSadaf EbrahimiThis change does not affect users who use the default `mbedtls_config.h`, as the 887*62c56f98SSadaf Ebrahimioption `MBEDTLS_SSL_RECORD_CHECKING` was already on by default. 888*62c56f98SSadaf Ebrahimi 889*62c56f98SSadaf EbrahimiThis option was added only to control compilation of one function, 890*62c56f98SSadaf Ebrahimi `mbedtls_ssl_check_record()`, which is only useful in some specific cases, so it 891*62c56f98SSadaf Ebrahimiwas made optional to allow users who don't need it to save some code space. 892*62c56f98SSadaf EbrahimiHowever, the same effect can be achieved by using link-time garbage collection. 893*62c56f98SSadaf Ebrahimi 894*62c56f98SSadaf EbrahimiUsers who changed the default setting of the option need to change the config/ 895*62c56f98SSadaf Ebrahimibuild system to remove that change. 896*62c56f98SSadaf Ebrahimi 897*62c56f98SSadaf Ebrahimi### Session Cache API Change 898*62c56f98SSadaf Ebrahimi 899*62c56f98SSadaf EbrahimiThis affects users who use `mbedtls_ssl_conf_session_cache()` 900*62c56f98SSadaf Ebrahimito configure a custom session cache implementation different 901*62c56f98SSadaf Ebrahimifrom the one Mbed TLS implements in `library/ssl_cache.c`. 902*62c56f98SSadaf Ebrahimi 903*62c56f98SSadaf EbrahimiThose users will need to modify the API of their session cache 904*62c56f98SSadaf Ebrahimiimplementation to that of a key-value store with keys being 905*62c56f98SSadaf Ebrahimisession IDs and values being instances of `mbedtls_ssl_session`: 906*62c56f98SSadaf Ebrahimi 907*62c56f98SSadaf Ebrahimi```C 908*62c56f98SSadaf Ebrahimitypedef int mbedtls_ssl_cache_get_t( void *data, 909*62c56f98SSadaf Ebrahimi unsigned char const *session_id, 910*62c56f98SSadaf Ebrahimi size_t session_id_len, 911*62c56f98SSadaf Ebrahimi mbedtls_ssl_session *session ); 912*62c56f98SSadaf Ebrahimitypedef int mbedtls_ssl_cache_set_t( void *data, 913*62c56f98SSadaf Ebrahimi unsigned char const *session_id, 914*62c56f98SSadaf Ebrahimi size_t session_id_len, 915*62c56f98SSadaf Ebrahimi const mbedtls_ssl_session *session ); 916*62c56f98SSadaf Ebrahimi``` 917*62c56f98SSadaf Ebrahimi 918*62c56f98SSadaf EbrahimiSince the structure of `mbedtls_ssl_session` is no longer public from 3.0 919*62c56f98SSadaf Ebrahimionwards, portable session cache implementations must not access fields of 920*62c56f98SSadaf Ebrahimi`mbedtls_ssl_session`. See the corresponding migration guide. Users that 921*62c56f98SSadaf Ebrahimifind themselves unable to migrate their session cache functionality without 922*62c56f98SSadaf Ebrahimiaccessing fields of `mbedtls_ssl_session` should describe their use case 923*62c56f98SSadaf Ebrahimion the Mbed TLS mailing list. 924*62c56f98SSadaf Ebrahimi 925*62c56f98SSadaf Ebrahimi### Changes in the SSL error code space 926*62c56f98SSadaf Ebrahimi 927*62c56f98SSadaf EbrahimiThis affects users manually checking for the following error codes: 928*62c56f98SSadaf Ebrahimi 929*62c56f98SSadaf Ebrahimi- `MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED` 930*62c56f98SSadaf Ebrahimi- `MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH` 931*62c56f98SSadaf Ebrahimi- `MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE` 932*62c56f98SSadaf Ebrahimi- `MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN` 933*62c56f98SSadaf Ebrahimi- `MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE` 934*62c56f98SSadaf Ebrahimi- `MBEDTLS_ERR_SSL_BAD_HS_XXX` 935*62c56f98SSadaf Ebrahimi 936*62c56f98SSadaf EbrahimiMigration paths: 937*62c56f98SSadaf Ebrahimi- `MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE` has been removed, and 938*62c56f98SSadaf Ebrahimi `MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL` is returned instead if the user's own certificate 939*62c56f98SSadaf Ebrahimi is too large to fit into the output buffers. 940*62c56f98SSadaf Ebrahimi 941*62c56f98SSadaf Ebrahimi Users should check for `MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL` instead, and potentially 942*62c56f98SSadaf Ebrahimi compare the size of their own certificate against the configured size of the output buffer to 943*62c56f98SSadaf Ebrahimi understand if the error is due to an overly large certificate. 944*62c56f98SSadaf Ebrahimi 945*62c56f98SSadaf Ebrahimi- `MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN` and `MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE` have been 946*62c56f98SSadaf Ebrahimi replaced by `MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE`. 947*62c56f98SSadaf Ebrahimi 948*62c56f98SSadaf Ebrahimi- All codes of the form `MBEDTLS_ERR_SSL_BAD_HS_XXX` have been replaced by various alternatives, which give more information about the type of error raised. 949*62c56f98SSadaf Ebrahimi 950*62c56f98SSadaf Ebrahimi Users should check for the newly introduced generic error codes 951*62c56f98SSadaf Ebrahimi 952*62c56f98SSadaf Ebrahimi * `MBEDTLS_ERR_SSL_DECODE_ERROR` 953*62c56f98SSadaf Ebrahimi * `MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER`, 954*62c56f98SSadaf Ebrahimi * `MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE` 955*62c56f98SSadaf Ebrahimi * `MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION` 956*62c56f98SSadaf Ebrahimi * `MBEDTLS_ERR_SSL_BAD_CERTIFICATE` 957*62c56f98SSadaf Ebrahimi * `MBEDTLS_ERR_SSL_UNRECOGNIZED_NAME` 958*62c56f98SSadaf Ebrahimi * `MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION` 959*62c56f98SSadaf Ebrahimi * `MBEDTLS_ERR_SSL_NO_APPLICATION_PROTOCOL` 960*62c56f98SSadaf Ebrahimi 961*62c56f98SSadaf Ebrahimi and the pre-existing generic error codes 962*62c56f98SSadaf Ebrahimi 963*62c56f98SSadaf Ebrahimi * `MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE` 964*62c56f98SSadaf Ebrahimi * `MBEDTLS_ERR_SSL_INTERNAL_ERROR` 965*62c56f98SSadaf Ebrahimi 966*62c56f98SSadaf Ebrahimi instead. 967*62c56f98SSadaf Ebrahimi 968*62c56f98SSadaf Ebrahimi### Modified semantics of `mbedtls_ssl_{get,set}_session()` 969*62c56f98SSadaf Ebrahimi 970*62c56f98SSadaf EbrahimiThis affects users who call `mbedtls_ssl_get_session()` or 971*62c56f98SSadaf Ebrahimi`mbedtls_ssl_set_session()` multiple times on the same SSL context 972*62c56f98SSadaf Ebrahimirepresenting an established TLS 1.2 connection. 973*62c56f98SSadaf EbrahimiThose users will now observe the second call to fail with 974*62c56f98SSadaf Ebrahimi`MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE`. 975*62c56f98SSadaf Ebrahimi 976*62c56f98SSadaf EbrahimiMigration path: 977*62c56f98SSadaf Ebrahimi- Exporting the same TLS 1.2 connection multiple times via 978*62c56f98SSadaf Ebrahimi `mbedtls_ssl_get_session()` leads to multiple copies of 979*62c56f98SSadaf Ebrahimi the same session. This use of `mbedtls_ssl_get_session()` 980*62c56f98SSadaf Ebrahimi is discouraged, and the following should be considered: 981*62c56f98SSadaf Ebrahimi * If the various session copies are later loaded into 982*62c56f98SSadaf Ebrahimi fresh SSL contexts via `mbedtls_ssl_set_session()`, 983*62c56f98SSadaf Ebrahimi export via `mbedtls_ssl_get_session()` only once and 984*62c56f98SSadaf Ebrahimi load the same session into different contexts via 985*62c56f98SSadaf Ebrahimi `mbedtls_ssl_set_session()`. Since `mbedtls_ssl_set_session()` 986*62c56f98SSadaf Ebrahimi makes a copy of the session that's being loaded, this 987*62c56f98SSadaf Ebrahimi is functionally equivalent. 988*62c56f98SSadaf Ebrahimi * If the various session copies are later serialized 989*62c56f98SSadaf Ebrahimi via `mbedtls_ssl_session_save()`, export and serialize 990*62c56f98SSadaf Ebrahimi the session only once via `mbedtls_ssl_get_session()` and 991*62c56f98SSadaf Ebrahimi `mbedtls_ssl_session_save()` and make copies of the raw 992*62c56f98SSadaf Ebrahimi data instead. 993*62c56f98SSadaf Ebrahimi- Calling `mbedtls_ssl_set_session()` multiple times in Mbed TLS 2.x 994*62c56f98SSadaf Ebrahimi is not useful since subsequent calls overwrite the effect of previous 995*62c56f98SSadaf Ebrahimi calls. Applications achieve equivalent functional behavior by 996*62c56f98SSadaf Ebrahimi issuing only the very last call to `mbedtls_ssl_set_session()`. 997*62c56f98SSadaf Ebrahimi 998*62c56f98SSadaf Ebrahimi### Turn `MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE` configuration option into a runtime option 999*62c56f98SSadaf Ebrahimi 1000*62c56f98SSadaf EbrahimiThis change affects users who were enabling `MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE` 1001*62c56f98SSadaf Ebrahimioption in the `mbedtls_config.h` 1002*62c56f98SSadaf Ebrahimi 1003*62c56f98SSadaf EbrahimiThis option has been removed and a new function with similar functionality has 1004*62c56f98SSadaf Ebrahimibeen introduced into the SSL API. 1005*62c56f98SSadaf Ebrahimi 1006*62c56f98SSadaf EbrahimiThis new function `mbedtls_ssl_conf_preference_order()` can be used to 1007*62c56f98SSadaf Ebrahimichange the preferred order of ciphersuites on the server to those used on the client, 1008*62c56f98SSadaf Ebrahimie.g.: `mbedtls_ssl_conf_preference_order(ssl_config, MBEDTLS_SSL_SRV_CIPHERSUITE_ORDER_CLIENT)` 1009*62c56f98SSadaf Ebrahimihas the same effect as enabling the removed option. The default state is to use 1010*62c56f98SSadaf Ebrahimithe server order of suites. 1011*62c56f98SSadaf Ebrahimi 1012*62c56f98SSadaf Ebrahimi### Strengthen default algorithm selection for X.509 and TLS 1013*62c56f98SSadaf Ebrahimi 1014*62c56f98SSadaf EbrahimiThe default X.509 verification profile (`mbedtls_x509_crt_profile_default`) and the default curve and hash selection in TLS have changed. They are now aligned, except that the X.509 profile only lists curves that support signature verification. 1015*62c56f98SSadaf Ebrahimi 1016*62c56f98SSadaf EbrahimiHashes and curves weaker than 255 bits (security strength less than 128 bits) are no longer accepted by default. The following hashes have been removed: SHA-1 (formerly only accepted for key exchanges but not for certificate signatures), SHA-224 (weaker hashes were already not accepted). The following curves have been removed: secp192r1, secp224r1, secp192k1, secp224k1. 1017*62c56f98SSadaf Ebrahimi 1018*62c56f98SSadaf EbrahimiThe compile-time options `MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES` and `MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE` are no longer available. 1019*62c56f98SSadaf Ebrahimi 1020*62c56f98SSadaf EbrahimiThe curve secp256k1 has also been removed from the default X.509 and TLS profiles. [RFC 8422](https://datatracker.ietf.org/doc/html/rfc8422#section-5.1.1) deprecates it in TLS, and it is very rarely used, although it is not known to be weak at the time of writing. 1021*62c56f98SSadaf Ebrahimi 1022*62c56f98SSadaf EbrahimiIf you still need to accept certificates signed with algorithms that have been removed from the default profile, call `mbedtls_x509_crt_verify_with_profile` instead of `mbedtls_x509_crt_verify` and pass a profile that allows the curves and hashes you want. For example, to allow SHA-224: 1023*62c56f98SSadaf Ebrahimi```C 1024*62c56f98SSadaf Ebrahimimbedtls_x509_crt_profile my_profile = mbedtls_x509_crt_profile_default; 1025*62c56f98SSadaf Ebrahimimy_profile.allowed_mds |= MBEDTLS_X509_ID_FLAG( MBEDTLS_MD_SHA224 ); 1026*62c56f98SSadaf Ebrahimi``` 1027*62c56f98SSadaf Ebrahimi 1028*62c56f98SSadaf EbrahimiIf you still need to allow hashes and curves in TLS that have been removed from the default configuration, call `mbedtls_ssl_conf_sig_hashes()` and `mbedtls_ssl_conf_curves()` with the desired lists. 1029*62c56f98SSadaf Ebrahimi 1030*62c56f98SSadaf Ebrahimi### Remove 3DES ciphersuites 1031*62c56f98SSadaf Ebrahimi 1032*62c56f98SSadaf EbrahimiThis change does not affect users using default settings for 3DES in `mbedtls_config.h` 1033*62c56f98SSadaf Ebrahimibecause the 3DES ciphersuites were disabled by that. 1034*62c56f98SSadaf Ebrahimi 1035*62c56f98SSadaf Ebrahimi3DES has weaknesses/limitations and there are better alternatives, and more and 1036*62c56f98SSadaf Ebrahimimore standard bodies are recommending against its use in TLS. 1037*62c56f98SSadaf Ebrahimi 1038*62c56f98SSadaf EbrahimiThe migration path here is to chose from the alternatives recommended in the 1039*62c56f98SSadaf Ebrahimiliterature, such as AES. 1040