blob: 458b8155891d8c03a97ea87646a680329b3af244 [file] [log] [blame] [view]
Janos Follath1eb85622024-11-20 12:25:58 +00001This document describes how PSA Crypto is used in the X.509 and TLS libraries
2from a user's perspective.
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +02003
Janos Follath1eb85622024-11-20 12:25:58 +00004In 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é-Gonnard2ca08c82023-03-24 09:21:46 +01008 `mbedtls_pk_setup_opaque()` and `mbedtls_ssl_conf_psk_opaque()`, see
Janos Follath1eb85622024-11-20 12:25:58 +00009"PSA key APIs" below.
Manuel Pégourié-Gonnardf3f79a02022-05-11 13:31:47 +020010
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020011General considerations
12----------------------
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +020013
Janos Follath1eb85622024-11-20 12:25:58 +000014**Application code:** you need to call `psa_crypto_init()` before calling any
15function from the SSL/TLS, X.509 or PK modules, except for the various
16mbedtls_xxx_init() functions which can be called at any time.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020017
Janos Follath1eb85622024-11-20 12:25:58 +000018PSA Key APIs
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020019-------------------------
20
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020021### PSA-held (opaque) keys in the PK layer
22
Janos Follath1eb85622024-11-20 12:25:58 +000023**API function:** `mbedtls_pk_setup_opaque()` - can be used to wrap a PSA key
24pair into a PK context. The key can be used for private-key operations and its
25public part can be exported.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020026
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020027**Benefits:** isolation of long-term secrets, use of PSA Crypto drivers.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020028
Valerio Settiac81e232024-03-21 16:49:02 +010029**Limitations:** please refer to the documentation of `mbedtls_pk_setup_opaque()`
30for a full list of supported operations and limitations.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020031
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020032**Use in X.509 and TLS:** opt-in. The application needs to construct the PK context
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020033using the new API in order to get the benefits; it can then pass the
34resulting 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é-Gonnardb5b27c12022-06-10 11:09:03 +020037 key together with a certificate for certificate-based key exchanges;
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020038- `mbedtls_x509write_csr_set_key()` to generate a CSR (certificate signature
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020039 request);
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020040- `mbedtls_x509write_crt_set_issuer_key()` to generate a certificate.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020041
Manuel Pégourié-Gonnard9155b0e2021-09-24 10:17:07 +020042### PSA-held (opaque) keys for TLS pre-shared keys (PSK)
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020043
Janos Follath1eb85622024-11-20 12:25:58 +000044**API functions:** `mbedtls_ssl_conf_psk_opaque()` and
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020045`mbedtls_ssl_set_hs_psk_opaque()`. Call one of these from an application to
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020046register a PSA key for use with a PSK key exchange.
47
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020048**Benefits:** isolation of long-term secrets.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020049
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020050**Limitations:** none.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020051
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020052**Use in TLS:** opt-in. The application needs to register the key using one of
Janos Follath1eb85622024-11-20 12:25:58 +000053the above APIs to get the benefits.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020054
Manuel Pégourié-Gonnard86efa852023-03-24 09:26:40 +010055### PSA-held (opaque) keys for TLS 1.2 EC J-PAKE key exchange
56
Janos Follath1eb85622024-11-20 12:25:58 +000057**API function:** `mbedtls_ssl_set_hs_ecjpake_password_opaque()`. Call this
58function from an application to register a PSA key for use with the TLS 1.2 EC
59J-PAKE key exchange.
Manuel Pégourié-Gonnard86efa852023-03-24 09:26:40 +010060
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 Follath1eb85622024-11-20 12:25:58 +000066the above APIs to get the benefits.
Manuel Pégourié-Gonnard86efa852023-03-24 09:26:40 +010067
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020068### PSA-based operations in the Cipher layer
69
Janos Follath1eb85622024-11-20 12:25:58 +000070There is an API function `mbedtls_cipher_setup_psa()` to set up a context
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020071that will call PSA to store the key and perform the operations.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020072
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020073This function only worked for a small number of ciphers. It is now deprecated
74and it is recommended to use `psa_cipher_xxx()` or `psa_aead_xxx()` functions
75directly instead.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020076
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020077**Warning:** This function will be removed in a future version of Mbed TLS. If
78you are using it and would like us to keep it, please let us know about your
79use case.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020080
Janos Follath1eb85622024-11-20 12:25:58 +000081Internal uses
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020082----------------
83
Janos Follath1eb85622024-11-20 12:25:58 +000084All of these internal uses are relying on PSA Crypto.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020085
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020086### TLS: most crypto operations based on PSA
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020087
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020088Current exceptions:
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020089
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +010090- 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é-Gonnard1b08c5f2021-09-21 11:21:23 +020094
Janos Follath1eb85622024-11-20 12:25:58 +000095Other than the above exceptions, all crypto operations are based on PSA.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020096
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020097### X.509: most crypto operations based on PSA
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020098
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +010099Current exceptions:
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200100
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +0100101- Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see
102 the documentation of that option).
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200103
Janos Follath1eb85622024-11-20 12:25:58 +0000104Other than the above exception, all crypto operations are based on PSA.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200105
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200106### PK layer: most crypto operations based on PSA
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200107
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +0100108Current exceptions:
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200109
Manuel Pégourié-Gonnarda6e02912022-12-21 09:59:33 +0100110- Verification of RSA-PSS signatures with an MGF hash that's different from
111 the message hash.
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +0100112- Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see
113 the documentation of that option).
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200114
Janos Follath1eb85622024-11-20 12:25:58 +0000115Other than the above exceptions, all crypto operations are based on PSA.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200116