Manuel Pégourié-Gonnard | 73a0e1d | 2021-09-21 13:55:00 +0200 | [diff] [blame] | 1 | This document describes the compile-time configuration option |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 2 | `MBEDTLS_USE_PSA_CRYPTO` from a user's perspective. |
Manuel Pégourié-Gonnard | 13b0beb | 2021-09-20 13:21:25 +0200 | [diff] [blame] | 3 | |
Manuel Pégourié-Gonnard | 2ca08c8 | 2023-03-24 09:21:46 +0100 | [diff] [blame] | 4 | This option: |
| 5 | - makes the X.509 and TLS libraries use PSA for cryptographic operations as |
| 6 | much as possible, see "Internal changes" below; |
| 7 | - enables new APIs for using keys handled by PSA Crypto, such as |
| 8 | `mbedtls_pk_setup_opaque()` and `mbedtls_ssl_conf_psk_opaque()`, see |
| 9 | "New APIs / API extensions" below. |
Manuel Pégourié-Gonnard | f3f79a0 | 2022-05-11 13:31:47 +0200 | [diff] [blame] | 10 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 11 | General considerations |
| 12 | ---------------------- |
Manuel Pégourié-Gonnard | 13b0beb | 2021-09-20 13:21:25 +0200 | [diff] [blame] | 13 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 14 | **Application code:** when this option is enabled, you need to call |
Manuel Pégourié-Gonnard | f3f79a0 | 2022-05-11 13:31:47 +0200 | [diff] [blame] | 15 | `psa_crypto_init()` before calling any function from the SSL/TLS, X.509 or PK |
| 16 | module. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 17 | |
Manuel Pégourié-Gonnard | 2ca08c8 | 2023-03-24 09:21:46 +0100 | [diff] [blame] | 18 | **Relationship with other options:** This option depends on |
| 19 | `MBEDTLS_PSA_CRYPTO_C`. These two options differ in the following way: |
| 20 | - `MBEDTLS_PSA_CRYPTO_C` enables the implementation of the PSA Crypto API. |
| 21 | When it is enabled, `psa_xxx()` APIs are available and you must call |
| 22 | `psa_crypto_init()` before you call any other `psa_xxx()` function. Other |
| 23 | modules in the library (non-PSA crypto APIs, X.509, TLS) may or may not use |
| 24 | PSA Crypto but you're not required to call `psa_crypto_init()` before calling |
| 25 | non-PSA functions, unless when explicitly documented (TLS 1.3). |
| 26 | - `MBEDTLS_USE_PSA_CRYPTO` means that X.509 and TLS will use PSA Crypto as |
| 27 | much as possible (that is, everywhere except for features that are not |
| 28 | supported by PSA Crypto, see "Internal Changes" below for a complete list of |
| 29 | exceptions). When it is enabled, you need to call `psa_crypto_init()` before |
| 30 | calling any function from PK, X.509 or TLS; however it doesn't change anything |
| 31 | for the rest of the library. |
| 32 | |
| 33 | **Scope:** `MBEDTLS_USE_PSA_CRYPTO` has no effect on modules other than PK, |
| 34 | X.509 and TLS. It also has no effect on most of the TLS 1.3 code, which always |
| 35 | uses PSA crypto. The parts of the TLS 1.3 code that will use PSA Crypto or not |
| 36 | depending on this option being set or not are: |
Manuel Pégourié-Gonnard | 439dbc5 | 2023-03-10 12:33:15 +0100 | [diff] [blame] | 37 | - record protection; |
| 38 | - running handshake hash; |
| 39 | - asymmetric signature verification & generation; |
| 40 | - X.509 certificate chain verification. |
| 41 | You need to enable `MBEDTLS_USE_PSA_CRYPTO` if you want TLS 1.3 to use PSA |
| 42 | everywhere. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 43 | |
Manuel Pégourié-Gonnard | 2ca08c8 | 2023-03-24 09:21:46 +0100 | [diff] [blame] | 44 | **Historical note:** This option was introduced at a time when PSA Crypto was |
| 45 | still beta and not ready for production, so we made its use in X.509 and TLS |
| 46 | opt-in: by default, these modules would keep using the stable, |
| 47 | production-ready legacy (pre-PSA) crypto APIs. So, the scope of was X.509 and |
| 48 | TLS, as well as some of PK for technical reasons. Nowadays PSA Crypto is no |
| 49 | longer beta, and production quality, so there's no longer any reason to make |
| 50 | its use in other modules opt-in. However, PSA Crypto functions require that |
| 51 | `psa_crypto_init()` has been called before their use, and for backwards |
| 52 | compatibility reasons we can't impose this requirement on non-PSA functions |
| 53 | that didn't have such a requirement before. So, nowadays the main meaning of |
| 54 | `MBEDTLS_USE_PSA_CRYPTO` is that the user promises to call `psa_crypto_init()` |
| 55 | before calling any PK, X.509 or TLS functions. For the same compatibility |
| 56 | reasons, we can't extend its scope. However, new modules in the library, such |
| 57 | as TLS 1.3, can be introduced with a requirement to call `psa_crypto_init()`. |
Manuel Pégourié-Gonnard | 3dd9add | 2023-03-22 16:17:54 +0100 | [diff] [blame] | 58 | |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 59 | New APIs / API extensions |
| 60 | ------------------------- |
| 61 | |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 62 | ### PSA-held (opaque) keys in the PK layer |
| 63 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 64 | **New API function:** `mbedtls_pk_setup_opaque()` - can be used to |
| 65 | wrap a PSA key pair into a PK context. The key can be used for private-key |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 66 | operations and its public part can be exported. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 67 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 68 | **Benefits:** isolation of long-term secrets, use of PSA Crypto drivers. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 69 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 70 | **Limitations:** can only wrap a key pair, can only use it for private key |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 71 | operations. (That is, signature generation, and for RSA decryption too.) |
| 72 | Note: for ECDSA, currently this uses randomized ECDSA while Mbed TLS uses |
| 73 | deterministic ECDSA by default. The following operations are not supported |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 74 | with a context set this way, while they would be available with a normal |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 75 | context: `mbedtls_pk_check_pair()`, `mbedtls_pk_debug()`, all public key |
| 76 | operations. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 77 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 78 | **Use in X.509 and TLS:** opt-in. The application needs to construct the PK context |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 79 | using the new API in order to get the benefits; it can then pass the |
| 80 | resulting context to the following existing APIs: |
| 81 | |
| 82 | - `mbedtls_ssl_conf_own_cert()` or `mbedtls_ssl_set_hs_own_cert()` to use the |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 83 | key together with a certificate for certificate-based key exchanges; |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 84 | - `mbedtls_x509write_csr_set_key()` to generate a CSR (certificate signature |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 85 | request); |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 86 | - `mbedtls_x509write_crt_set_issuer_key()` to generate a certificate. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 87 | |
Manuel Pégourié-Gonnard | 9155b0e | 2021-09-24 10:17:07 +0200 | [diff] [blame] | 88 | ### PSA-held (opaque) keys for TLS pre-shared keys (PSK) |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 89 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 90 | **New API functions:** `mbedtls_ssl_conf_psk_opaque()` and |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 91 | `mbedtls_ssl_set_hs_psk_opaque()`. Call one of these from an application to |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 92 | register a PSA key for use with a PSK key exchange. |
| 93 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 94 | **Benefits:** isolation of long-term secrets. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 95 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 96 | **Limitations:** none. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 97 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 98 | **Use in TLS:** opt-in. The application needs to register the key using one of |
| 99 | the new APIs to get the benefits. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 100 | |
Manuel Pégourié-Gonnard | 86efa85 | 2023-03-24 09:26:40 +0100 | [diff] [blame^] | 101 | ### PSA-held (opaque) keys for TLS 1.2 EC J-PAKE key exchange |
| 102 | |
| 103 | **New API function:** `mbedtls_ssl_set_hs_ecjpake_password_opaque()`. |
| 104 | Call this function from an application to register a PSA key for use with the |
| 105 | TLS 1.2 EC J-PAKE key exchange. |
| 106 | |
| 107 | **Benefits:** isolation of long-term secrets. |
| 108 | |
| 109 | **Limitations:** none. |
| 110 | |
| 111 | **Use in TLS:** opt-in. The application needs to register the key using one of |
| 112 | the new APIs to get the benefits. |
| 113 | |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 114 | ### PSA-based operations in the Cipher layer |
| 115 | |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 116 | There is a new API function `mbedtls_cipher_setup_psa()` to set up a context |
| 117 | that will call PSA to store the key and perform the operations. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 118 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 119 | This function only worked for a small number of ciphers. It is now deprecated |
| 120 | and it is recommended to use `psa_cipher_xxx()` or `psa_aead_xxx()` functions |
| 121 | directly instead. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 122 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 123 | **Warning:** This function will be removed in a future version of Mbed TLS. If |
| 124 | you are using it and would like us to keep it, please let us know about your |
| 125 | use case. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 126 | |
| 127 | Internal changes |
| 128 | ---------------- |
| 129 | |
| 130 | All of these internal changes are active as soon as `MBEDTLS_USE_PSA_CRYPTO` |
| 131 | is enabled, no change required on the application side. |
| 132 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 133 | ### TLS: most crypto operations based on PSA |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 134 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 135 | Current exceptions: |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 136 | |
Manuel Pégourié-Gonnard | 55a188b | 2022-12-06 12:00:33 +0100 | [diff] [blame] | 137 | - Finite-field (non-EC) Diffie-Hellman (used in key exchanges: DHE-RSA, |
| 138 | DHE-PSK). |
| 139 | - Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see |
| 140 | the documentation of that option). |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 141 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 142 | Other than the above exceptions, all crypto operations are based on PSA when |
| 143 | `MBEDTLS_USE_PSA_CRYPTO` is enabled. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 144 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 145 | ### X.509: most crypto operations based on PSA |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 146 | |
Manuel Pégourié-Gonnard | 55a188b | 2022-12-06 12:00:33 +0100 | [diff] [blame] | 147 | Current exceptions: |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 148 | |
Manuel Pégourié-Gonnard | 55a188b | 2022-12-06 12:00:33 +0100 | [diff] [blame] | 149 | - Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see |
| 150 | the documentation of that option). |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 151 | |
Manuel Pégourié-Gonnard | 481846c | 2022-07-12 09:27:39 +0200 | [diff] [blame] | 152 | Other than the above exception, all crypto operations are based on PSA when |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 153 | `MBEDTLS_USE_PSA_CRYPTO` is enabled. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 154 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 155 | ### PK layer: most crypto operations based on PSA |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 156 | |
Manuel Pégourié-Gonnard | 55a188b | 2022-12-06 12:00:33 +0100 | [diff] [blame] | 157 | Current exceptions: |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 158 | |
Manuel Pégourié-Gonnard | a6e0291 | 2022-12-21 09:59:33 +0100 | [diff] [blame] | 159 | - Verification of RSA-PSS signatures with an MGF hash that's different from |
| 160 | the message hash. |
Manuel Pégourié-Gonnard | 55a188b | 2022-12-06 12:00:33 +0100 | [diff] [blame] | 161 | - Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see |
| 162 | the documentation of that option). |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 163 | |
Manuel Pégourié-Gonnard | a6e0291 | 2022-12-21 09:59:33 +0100 | [diff] [blame] | 164 | Other than the above exceptions, all crypto operations are based on PSA when |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 165 | `MBEDTLS_USE_PSA_CRYPTO` is enabled. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 166 | |