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 | f3f79a0 | 2022-05-11 13:31:47 +0200 | [diff] [blame] | 4 | This option makes the X.509 and TLS library use PSA for cryptographic |
| 5 | operations, and enables new APIs for using keys handled by PSA Crypto. |
| 6 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 7 | General considerations |
| 8 | ---------------------- |
Manuel Pégourié-Gonnard | 13b0beb | 2021-09-20 13:21:25 +0200 | [diff] [blame] | 9 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 10 | **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] | 11 | `psa_crypto_init()` before calling any function from the SSL/TLS, X.509 or PK |
| 12 | module. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 13 | |
Manuel Pégourié-Gonnard | 439dbc5 | 2023-03-10 12:33:15 +0100 | [diff] [blame] | 14 | **Scope:** `MBEDTLS_USE_PSA_CRYPTO` has no effect on the most of the TLS 1.3 |
| 15 | code, which always uses PSA crypto. The parts of the TLS 1.3 code that will |
| 16 | use PSA Crypto or not depending on the value of this option are: |
| 17 | - record protection; |
| 18 | - running handshake hash; |
| 19 | - asymmetric signature verification & generation; |
| 20 | - X.509 certificate chain verification. |
| 21 | You need to enable `MBEDTLS_USE_PSA_CRYPTO` if you want TLS 1.3 to use PSA |
| 22 | everywhere. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 23 | |
Manuel Pégourié-Gonnard | 3dd9add | 2023-03-22 16:17:54 +0100 | [diff] [blame^] | 24 | **Important note:** Even with this option disabled, some modules may still use |
| 25 | PSA Crypto. However, it is then their responsibility to make sure it's safe to |
| 26 | do so; in particular those modules do not require `psa_crypto_init()` to be |
| 27 | called. So, enabling `MBEDTLS_USE_PSA_CRYPTO` basically means: |
| 28 | - as a user, you promise to call `psa_crypto_init()` before using any function |
| 29 | from PK, X.509 or TLS; |
| 30 | - in return, those modules will use PSA Crypto as much as possible (see |
| 31 | exceptions belos). |
| 32 | Conversely, not enabling this option means you have no obligation to call |
| 33 | `psa_crypto_init()` (unless as documented by other options such as TLS 1.3), |
| 34 | but modules can still decide to use PSA if they can determine it is available |
| 35 | and initialized. |
| 36 | |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 37 | New APIs / API extensions |
| 38 | ------------------------- |
| 39 | |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 40 | ### PSA-held (opaque) keys in the PK layer |
| 41 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 42 | **New API function:** `mbedtls_pk_setup_opaque()` - can be used to |
| 43 | 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] | 44 | operations and its public part can be exported. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 45 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 46 | **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] | 47 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 48 | **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] | 49 | operations. (That is, signature generation, and for RSA decryption too.) |
| 50 | Note: for ECDSA, currently this uses randomized ECDSA while Mbed TLS uses |
| 51 | deterministic ECDSA by default. The following operations are not supported |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 52 | 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] | 53 | context: `mbedtls_pk_check_pair()`, `mbedtls_pk_debug()`, all public key |
| 54 | operations. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 55 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 56 | **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] | 57 | using the new API in order to get the benefits; it can then pass the |
| 58 | resulting context to the following existing APIs: |
| 59 | |
| 60 | - `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] | 61 | key together with a certificate for certificate-based key exchanges; |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 62 | - `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] | 63 | request); |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 64 | - `mbedtls_x509write_crt_set_issuer_key()` to generate a certificate. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 65 | |
Manuel Pégourié-Gonnard | 9155b0e | 2021-09-24 10:17:07 +0200 | [diff] [blame] | 66 | ### PSA-held (opaque) keys for TLS pre-shared keys (PSK) |
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 | **New API functions:** `mbedtls_ssl_conf_psk_opaque()` and |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 69 | `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] | 70 | register a PSA key for use with a PSK key exchange. |
| 71 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 72 | **Benefits:** isolation of long-term secrets. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 73 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 74 | **Limitations:** none. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 75 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 76 | **Use in TLS:** opt-in. The application needs to register the key using one of |
| 77 | the new APIs to get the benefits. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 78 | |
| 79 | ### PSA-based operations in the Cipher layer |
| 80 | |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 81 | There is a new API function `mbedtls_cipher_setup_psa()` to set up a context |
| 82 | 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] | 83 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 84 | This function only worked for a small number of ciphers. It is now deprecated |
| 85 | and it is recommended to use `psa_cipher_xxx()` or `psa_aead_xxx()` functions |
| 86 | directly instead. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 87 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 88 | **Warning:** This function will be removed in a future version of Mbed TLS. If |
| 89 | you are using it and would like us to keep it, please let us know about your |
| 90 | use case. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 91 | |
| 92 | Internal changes |
| 93 | ---------------- |
| 94 | |
| 95 | All of these internal changes are active as soon as `MBEDTLS_USE_PSA_CRYPTO` |
| 96 | is enabled, no change required on the application side. |
| 97 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 98 | ### TLS: most crypto operations based on PSA |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 99 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 100 | Current exceptions: |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 101 | |
Manuel Pégourié-Gonnard | 55a188b | 2022-12-06 12:00:33 +0100 | [diff] [blame] | 102 | - Finite-field (non-EC) Diffie-Hellman (used in key exchanges: DHE-RSA, |
| 103 | DHE-PSK). |
| 104 | - Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see |
| 105 | the documentation of that option). |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 106 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 107 | Other than the above exceptions, all crypto operations are based on PSA when |
| 108 | `MBEDTLS_USE_PSA_CRYPTO` is enabled. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 109 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 110 | ### X.509: most crypto operations based on PSA |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 111 | |
Manuel Pégourié-Gonnard | 55a188b | 2022-12-06 12:00:33 +0100 | [diff] [blame] | 112 | Current exceptions: |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 113 | |
Manuel Pégourié-Gonnard | 55a188b | 2022-12-06 12:00:33 +0100 | [diff] [blame] | 114 | - Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see |
| 115 | the documentation of that option). |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 116 | |
Manuel Pégourié-Gonnard | 481846c | 2022-07-12 09:27:39 +0200 | [diff] [blame] | 117 | 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] | 118 | `MBEDTLS_USE_PSA_CRYPTO` is enabled. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 119 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 120 | ### PK layer: most crypto operations based on PSA |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 121 | |
Manuel Pégourié-Gonnard | 55a188b | 2022-12-06 12:00:33 +0100 | [diff] [blame] | 122 | Current exceptions: |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 123 | |
Manuel Pégourié-Gonnard | a6e0291 | 2022-12-21 09:59:33 +0100 | [diff] [blame] | 124 | - Verification of RSA-PSS signatures with an MGF hash that's different from |
| 125 | the message hash. |
Manuel Pégourié-Gonnard | 55a188b | 2022-12-06 12:00:33 +0100 | [diff] [blame] | 126 | - Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see |
| 127 | the documentation of that option). |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 128 | |
Manuel Pégourié-Gonnard | a6e0291 | 2022-12-21 09:59:33 +0100 | [diff] [blame] | 129 | 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] | 130 | `MBEDTLS_USE_PSA_CRYPTO` is enabled. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 131 | |