blob: e0e9d1500bb1fbe06863d311fdde4a51fe768a4a [file] [log] [blame] [view]
Manuel Pégourié-Gonnard73a0e1d2021-09-21 13:55:00 +02001This document describes the compile-time configuration option
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +02002`MBEDTLS_USE_PSA_CRYPTO` from a user's perspective.
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +02003
Manuel Pégourié-Gonnardf3f79a02022-05-11 13:31:47 +02004This option makes the X.509 and TLS library use PSA for cryptographic
5operations, and enables new APIs for using keys handled by PSA Crypto.
6
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +02007General considerations
8----------------------
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +02009
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020010**Application code:** when this option is enabled, you need to call
Manuel Pégourié-Gonnardf3f79a02022-05-11 13:31:47 +020011`psa_crypto_init()` before calling any function from the SSL/TLS, X.509 or PK
12module.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020013
Manuel Pégourié-Gonnard439dbc52023-03-10 12:33:15 +010014**Scope:** `MBEDTLS_USE_PSA_CRYPTO` has no effect on the most of the TLS 1.3
15code, which always uses PSA crypto. The parts of the TLS 1.3 code that will
16use 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.
21You need to enable `MBEDTLS_USE_PSA_CRYPTO` if you want TLS 1.3 to use PSA
22everywhere.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020023
Manuel Pégourié-Gonnard3dd9add2023-03-22 16:17:54 +010024**Important note:** Even with this option disabled, some modules may still use
25PSA Crypto. However, it is then their responsibility to make sure it's safe to
26do so; in particular those modules do not require `psa_crypto_init()` to be
27called. 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).
32Conversely, 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),
34but modules can still decide to use PSA if they can determine it is available
35and initialized.
36
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020037New APIs / API extensions
38-------------------------
39
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020040### PSA-held (opaque) keys in the PK layer
41
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020042**New API function:** `mbedtls_pk_setup_opaque()` - can be used to
43wrap a PSA key pair into a PK context. The key can be used for private-key
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020044operations and its public part can be exported.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020045
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020046**Benefits:** isolation of long-term secrets, use of PSA Crypto drivers.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020047
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020048**Limitations:** can only wrap a key pair, can only use it for private key
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020049operations. (That is, signature generation, and for RSA decryption too.)
50Note: for ECDSA, currently this uses randomized ECDSA while Mbed TLS uses
51deterministic ECDSA by default. The following operations are not supported
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020052with a context set this way, while they would be available with a normal
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020053context: `mbedtls_pk_check_pair()`, `mbedtls_pk_debug()`, all public key
54operations.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020055
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020056**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 +020057using the new API in order to get the benefits; it can then pass the
58resulting 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é-Gonnardb5b27c12022-06-10 11:09:03 +020061 key together with a certificate for certificate-based key exchanges;
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020062- `mbedtls_x509write_csr_set_key()` to generate a CSR (certificate signature
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020063 request);
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020064- `mbedtls_x509write_crt_set_issuer_key()` to generate a certificate.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020065
Manuel Pégourié-Gonnard9155b0e2021-09-24 10:17:07 +020066### PSA-held (opaque) keys for TLS pre-shared keys (PSK)
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020067
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020068**New API functions:** `mbedtls_ssl_conf_psk_opaque()` and
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020069`mbedtls_ssl_set_hs_psk_opaque()`. Call one of these from an application to
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020070register a PSA key for use with a PSK key exchange.
71
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020072**Benefits:** isolation of long-term secrets.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020073
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020074**Limitations:** none.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020075
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020076**Use in TLS:** opt-in. The application needs to register the key using one of
77the new APIs to get the benefits.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020078
79### PSA-based operations in the Cipher layer
80
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020081There is a new API function `mbedtls_cipher_setup_psa()` to set up a context
82that will call PSA to store the key and perform the operations.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020083
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020084This function only worked for a small number of ciphers. It is now deprecated
85and it is recommended to use `psa_cipher_xxx()` or `psa_aead_xxx()` functions
86directly instead.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020087
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020088**Warning:** This function will be removed in a future version of Mbed TLS. If
89you are using it and would like us to keep it, please let us know about your
90use case.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020091
92Internal changes
93----------------
94
95All of these internal changes are active as soon as `MBEDTLS_USE_PSA_CRYPTO`
96is enabled, no change required on the application side.
97
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020098### TLS: most crypto operations based on PSA
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020099
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200100Current exceptions:
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200101
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +0100102- 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é-Gonnard1b08c5f2021-09-21 11:21:23 +0200106
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200107Other than the above exceptions, all crypto operations are based on PSA when
108`MBEDTLS_USE_PSA_CRYPTO` is enabled.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200109
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200110### X.509: most crypto operations based on PSA
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200111
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +0100112Current exceptions:
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200113
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +0100114- Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see
115 the documentation of that option).
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200116
Manuel Pégourié-Gonnard481846c2022-07-12 09:27:39 +0200117Other than the above exception, all crypto operations are based on PSA when
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200118`MBEDTLS_USE_PSA_CRYPTO` is enabled.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200119
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200120### PK layer: most crypto operations based on PSA
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200121
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +0100122Current exceptions:
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200123
Manuel Pégourié-Gonnarda6e02912022-12-21 09:59:33 +0100124- Verification of RSA-PSS signatures with an MGF hash that's different from
125 the message hash.
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +0100126- Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see
127 the documentation of that option).
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200128
Manuel Pégourié-Gonnarda6e02912022-12-21 09:59:33 +0100129Other than the above exceptions, all crypto operations are based on PSA when
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200130`MBEDTLS_USE_PSA_CRYPTO` is enabled.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200131