blob: c63e65a9a9c6f3d33b04379cef95920d2759194f [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é-Gonnard1b08c5f2021-09-21 11:21:23 +020024New APIs / API extensions
25-------------------------
26
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020027### PSA-held (opaque) keys in the PK layer
28
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020029**New API function:** `mbedtls_pk_setup_opaque()` - can be used to
30wrap 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 +020031operations and its public part can be exported.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020032
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020033**Benefits:** isolation of long-term secrets, use of PSA Crypto drivers.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020034
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020035**Limitations:** can only wrap a key pair, can only use it for private key
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020036operations. (That is, signature generation, and for RSA decryption too.)
37Note: for ECDSA, currently this uses randomized ECDSA while Mbed TLS uses
38deterministic ECDSA by default. The following operations are not supported
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020039with a context set this way, while they would be available with a normal
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020040context: `mbedtls_pk_check_pair()`, `mbedtls_pk_debug()`, all public key
41operations.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020042
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020043**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 +020044using the new API in order to get the benefits; it can then pass the
45resulting context to the following existing APIs:
46
47- `mbedtls_ssl_conf_own_cert()` or `mbedtls_ssl_set_hs_own_cert()` to use the
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020048 key together with a certificate for certificate-based key exchanges;
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020049- `mbedtls_x509write_csr_set_key()` to generate a CSR (certificate signature
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020050 request);
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020051- `mbedtls_x509write_crt_set_issuer_key()` to generate a certificate.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020052
Manuel Pégourié-Gonnard9155b0e2021-09-24 10:17:07 +020053### PSA-held (opaque) keys for TLS pre-shared keys (PSK)
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020054
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020055**New API functions:** `mbedtls_ssl_conf_psk_opaque()` and
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020056`mbedtls_ssl_set_hs_psk_opaque()`. Call one of these from an application to
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020057register a PSA key for use with a PSK key exchange.
58
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020059**Benefits:** isolation of long-term secrets.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020060
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020061**Limitations:** none.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020062
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020063**Use in TLS:** opt-in. The application needs to register the key using one of
64the new APIs to get the benefits.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020065
66### PSA-based operations in the Cipher layer
67
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020068There is a new API function `mbedtls_cipher_setup_psa()` to set up a context
69that will call PSA to store the key and perform the operations.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020070
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020071This function only worked for a small number of ciphers. It is now deprecated
72and it is recommended to use `psa_cipher_xxx()` or `psa_aead_xxx()` functions
73directly instead.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020074
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020075**Warning:** This function will be removed in a future version of Mbed TLS. If
76you are using it and would like us to keep it, please let us know about your
77use case.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020078
79Internal changes
80----------------
81
82All of these internal changes are active as soon as `MBEDTLS_USE_PSA_CRYPTO`
83is enabled, no change required on the application side.
84
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020085### TLS: most crypto operations based on PSA
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020086
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020087Current exceptions:
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020088
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +010089- Finite-field (non-EC) Diffie-Hellman (used in key exchanges: DHE-RSA,
90 DHE-PSK).
91- Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see
92 the documentation of that option).
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020093
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020094Other than the above exceptions, all crypto operations are based on PSA when
95`MBEDTLS_USE_PSA_CRYPTO` is enabled.
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
Manuel Pégourié-Gonnard481846c2022-07-12 09:27:39 +0200104Other than the above exception, all crypto operations are based on PSA when
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200105`MBEDTLS_USE_PSA_CRYPTO` is enabled.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200106
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200107### PK layer: most crypto operations based on PSA
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200108
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +0100109Current exceptions:
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200110
Manuel Pégourié-Gonnarda6e02912022-12-21 09:59:33 +0100111- Verification of RSA-PSS signatures with an MGF hash that's different from
112 the message hash.
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +0100113- Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see
114 the documentation of that option).
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200115
Manuel Pégourié-Gonnarda6e02912022-12-21 09:59:33 +0100116Other than the above exceptions, all crypto operations are based on PSA when
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200117`MBEDTLS_USE_PSA_CRYPTO` is enabled.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200118