Janos Follath | 1eb8562 | 2024-11-20 12:25:58 +0000 | [diff] [blame^] | 1 | This document describes how PSA Crypto is used in the X.509 and TLS libraries |
| 2 | from a user's perspective. |
Manuel Pégourié-Gonnard | 13b0beb | 2021-09-20 13:21:25 +0200 | [diff] [blame] | 3 | |
Janos Follath | 1eb8562 | 2024-11-20 12:25:58 +0000 | [diff] [blame^] | 4 | In particular: |
| 5 | - X.509 and TLS libraries use PSA for cryptographic operations as much as |
| 6 | possible, see "Internal changes" below; |
| 7 | - APIs for using keys handled by PSA Crypto, such as |
Manuel Pégourié-Gonnard | 2ca08c8 | 2023-03-24 09:21:46 +0100 | [diff] [blame] | 8 | `mbedtls_pk_setup_opaque()` and `mbedtls_ssl_conf_psk_opaque()`, see |
Janos Follath | 1eb8562 | 2024-11-20 12:25:58 +0000 | [diff] [blame^] | 9 | "PSA key APIs" 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 | |
Janos Follath | 1eb8562 | 2024-11-20 12:25:58 +0000 | [diff] [blame^] | 14 | **Application code:** you need to call `psa_crypto_init()` before calling any |
| 15 | function from the SSL/TLS, X.509 or PK modules, except for the various |
| 16 | mbedtls_xxx_init() functions which can be called at any time. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 17 | |
Janos Follath | 1eb8562 | 2024-11-20 12:25:58 +0000 | [diff] [blame^] | 18 | PSA Key APIs |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 19 | ------------------------- |
| 20 | |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 21 | ### PSA-held (opaque) keys in the PK layer |
| 22 | |
Janos Follath | 1eb8562 | 2024-11-20 12:25:58 +0000 | [diff] [blame^] | 23 | **API function:** `mbedtls_pk_setup_opaque()` - can be used to wrap a PSA key |
| 24 | pair into a PK context. The key can be used for private-key operations and its |
| 25 | public part can be exported. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 26 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 27 | **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] | 28 | |
Valerio Setti | ac81e23 | 2024-03-21 16:49:02 +0100 | [diff] [blame] | 29 | **Limitations:** please refer to the documentation of `mbedtls_pk_setup_opaque()` |
| 30 | for a full list of supported operations and limitations. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 31 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 32 | **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] | 33 | using the new API in order to get the benefits; it can then pass the |
| 34 | resulting context to the following existing APIs: |
| 35 | |
| 36 | - `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] | 37 | key together with a certificate for certificate-based key exchanges; |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 38 | - `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] | 39 | request); |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 40 | - `mbedtls_x509write_crt_set_issuer_key()` to generate a certificate. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 41 | |
Manuel Pégourié-Gonnard | 9155b0e | 2021-09-24 10:17:07 +0200 | [diff] [blame] | 42 | ### PSA-held (opaque) keys for TLS pre-shared keys (PSK) |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 43 | |
Janos Follath | 1eb8562 | 2024-11-20 12:25:58 +0000 | [diff] [blame^] | 44 | **API functions:** `mbedtls_ssl_conf_psk_opaque()` and |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 45 | `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] | 46 | register a PSA key for use with a PSK key exchange. |
| 47 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 48 | **Benefits:** isolation of long-term secrets. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 49 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 50 | **Limitations:** none. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 51 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 52 | **Use in TLS:** opt-in. The application needs to register the key using one of |
Janos Follath | 1eb8562 | 2024-11-20 12:25:58 +0000 | [diff] [blame^] | 53 | the above APIs to get the benefits. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 54 | |
Manuel Pégourié-Gonnard | 86efa85 | 2023-03-24 09:26:40 +0100 | [diff] [blame] | 55 | ### PSA-held (opaque) keys for TLS 1.2 EC J-PAKE key exchange |
| 56 | |
Janos Follath | 1eb8562 | 2024-11-20 12:25:58 +0000 | [diff] [blame^] | 57 | **API function:** `mbedtls_ssl_set_hs_ecjpake_password_opaque()`. Call this |
| 58 | function from an application to register a PSA key for use with the TLS 1.2 EC |
| 59 | J-PAKE key exchange. |
Manuel Pégourié-Gonnard | 86efa85 | 2023-03-24 09:26:40 +0100 | [diff] [blame] | 60 | |
| 61 | **Benefits:** isolation of long-term secrets. |
| 62 | |
| 63 | **Limitations:** none. |
| 64 | |
| 65 | **Use in TLS:** opt-in. The application needs to register the key using one of |
Janos Follath | 1eb8562 | 2024-11-20 12:25:58 +0000 | [diff] [blame^] | 66 | the above APIs to get the benefits. |
Manuel Pégourié-Gonnard | 86efa85 | 2023-03-24 09:26:40 +0100 | [diff] [blame] | 67 | |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 68 | ### PSA-based operations in the Cipher layer |
| 69 | |
Janos Follath | 1eb8562 | 2024-11-20 12:25:58 +0000 | [diff] [blame^] | 70 | There is an API function `mbedtls_cipher_setup_psa()` to set up a context |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 71 | 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] | 72 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 73 | This function only worked for a small number of ciphers. It is now deprecated |
| 74 | and it is recommended to use `psa_cipher_xxx()` or `psa_aead_xxx()` functions |
| 75 | directly instead. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 76 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 77 | **Warning:** This function will be removed in a future version of Mbed TLS. If |
| 78 | you are using it and would like us to keep it, please let us know about your |
| 79 | use case. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 80 | |
Janos Follath | 1eb8562 | 2024-11-20 12:25:58 +0000 | [diff] [blame^] | 81 | Internal uses |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 82 | ---------------- |
| 83 | |
Janos Follath | 1eb8562 | 2024-11-20 12:25:58 +0000 | [diff] [blame^] | 84 | All of these internal uses are relying on PSA Crypto. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 85 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 86 | ### TLS: most crypto operations based on PSA |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 87 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 88 | Current exceptions: |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 89 | |
Manuel Pégourié-Gonnard | 55a188b | 2022-12-06 12:00:33 +0100 | [diff] [blame] | 90 | - Finite-field (non-EC) Diffie-Hellman (used in key exchanges: DHE-RSA, |
| 91 | DHE-PSK). |
| 92 | - Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see |
| 93 | the documentation of that option). |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 94 | |
Janos Follath | 1eb8562 | 2024-11-20 12:25:58 +0000 | [diff] [blame^] | 95 | Other than the above exceptions, all crypto operations are based on PSA. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 96 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 97 | ### X.509: most crypto operations based on PSA |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 98 | |
Manuel Pégourié-Gonnard | 55a188b | 2022-12-06 12:00:33 +0100 | [diff] [blame] | 99 | Current exceptions: |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 100 | |
Manuel Pégourié-Gonnard | 55a188b | 2022-12-06 12:00:33 +0100 | [diff] [blame] | 101 | - Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see |
| 102 | the documentation of that option). |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 103 | |
Janos Follath | 1eb8562 | 2024-11-20 12:25:58 +0000 | [diff] [blame^] | 104 | Other than the above exception, all crypto operations are based on PSA. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 105 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 106 | ### PK layer: most crypto operations based on PSA |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 107 | |
Manuel Pégourié-Gonnard | 55a188b | 2022-12-06 12:00:33 +0100 | [diff] [blame] | 108 | Current exceptions: |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 109 | |
Manuel Pégourié-Gonnard | a6e0291 | 2022-12-21 09:59:33 +0100 | [diff] [blame] | 110 | - Verification of RSA-PSS signatures with an MGF hash that's different from |
| 111 | the message hash. |
Manuel Pégourié-Gonnard | 55a188b | 2022-12-06 12:00:33 +0100 | [diff] [blame] | 112 | - Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see |
| 113 | the documentation of that option). |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 114 | |
Janos Follath | 1eb8562 | 2024-11-20 12:25:58 +0000 | [diff] [blame^] | 115 | Other than the above exceptions, all crypto operations are based on PSA. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 116 | |