blob: fc5317af89f0f286416ef9b11c9ce216f2902e9e [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é-Gonnardb5b27c12022-06-10 11:09:03 +020014**Scope:** `MBEDTLS_USE_PSA_CRYPTO` has no effect on the parts of the code that
Manuel Pégourié-Gonnard97ec0b72022-04-20 15:20:15 +020015are specific to TLS 1.3; those parts always use PSA Crypto. The parts of the
Manuel Pégourié-Gonnard0dba51c2022-06-07 10:28:02 +020016TLS 1.3 code that are common with TLS 1.2, however, follow this option;
17currently this is the record protection code, computation of the running
Manuel Pégourié-Gonnard481846c2022-07-12 09:27:39 +020018handshake hash, and X.509. You need to enable `MBEDTLS_USE_PSA_CRYPTO` if you
Manuel Pégourié-Gonnard0dba51c2022-06-07 10:28:02 +020019want TLS 1.3 to use PSA everywhere.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020020
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020021New APIs / API extensions
22-------------------------
23
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020024### PSA-held (opaque) keys in the PK layer
25
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020026**New API function:** `mbedtls_pk_setup_opaque()` - can be used to
27wrap 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 +020028operations and its public part can be exported.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020029
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020030**Benefits:** isolation of long-term secrets, use of PSA Crypto drivers.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020031
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020032**Limitations:** can only wrap a key pair, can only use it for private key
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020033operations. (That is, signature generation, and for RSA decryption too.)
34Note: for ECDSA, currently this uses randomized ECDSA while Mbed TLS uses
35deterministic ECDSA by default. The following operations are not supported
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020036with a context set this way, while they would be available with a normal
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020037context: `mbedtls_pk_check_pair()`, `mbedtls_pk_debug()`, all public key
38operations.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020039
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020040**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 +020041using the new API in order to get the benefits; it can then pass the
42resulting context to the following existing APIs:
43
44- `mbedtls_ssl_conf_own_cert()` or `mbedtls_ssl_set_hs_own_cert()` to use the
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020045 key together with a certificate for certificate-based key exchanges;
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020046- `mbedtls_x509write_csr_set_key()` to generate a CSR (certificate signature
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020047 request);
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020048- `mbedtls_x509write_crt_set_issuer_key()` to generate a certificate.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020049
Manuel Pégourié-Gonnard9155b0e2021-09-24 10:17:07 +020050### PSA-held (opaque) keys for TLS pre-shared keys (PSK)
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020051
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020052**New API functions:** `mbedtls_ssl_conf_psk_opaque()` and
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020053`mbedtls_ssl_set_hs_psk_opaque()`. Call one of these from an application to
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020054register a PSA key for use with a PSK key exchange.
55
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020056**Benefits:** isolation of long-term secrets.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020057
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020058**Limitations:** none.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020059
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020060**Use in TLS:** opt-in. The application needs to register the key using one of
61the new APIs to get the benefits.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020062
63### PSA-based operations in the Cipher layer
64
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020065There is a new API function `mbedtls_cipher_setup_psa()` to set up a context
66that will call PSA to store the key and perform the operations.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020067
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020068This function only worked for a small number of ciphers. It is now deprecated
69and it is recommended to use `psa_cipher_xxx()` or `psa_aead_xxx()` functions
70directly instead.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020071
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020072**Warning:** This function will be removed in a future version of Mbed TLS. If
73you are using it and would like us to keep it, please let us know about your
74use case.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020075
76Internal changes
77----------------
78
79All of these internal changes are active as soon as `MBEDTLS_USE_PSA_CRYPTO`
80is enabled, no change required on the application side.
81
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020082### TLS: most crypto operations based on PSA
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020083
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020084Current exceptions:
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020085
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +010086- Finite-field (non-EC) Diffie-Hellman (used in key exchanges: DHE-RSA,
87 DHE-PSK).
88- Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see
89 the documentation of that option).
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020090
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020091Other than the above exceptions, all crypto operations are based on PSA when
92`MBEDTLS_USE_PSA_CRYPTO` is enabled.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020093
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020094### X.509: most crypto operations based on PSA
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020095
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +010096Current exceptions:
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020097
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +010098- Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see
99 the documentation of that option).
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200100
Manuel Pégourié-Gonnard481846c2022-07-12 09:27:39 +0200101Other than the above exception, all crypto operations are based on PSA when
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200102`MBEDTLS_USE_PSA_CRYPTO` is enabled.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200103
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200104### PK layer: most crypto operations based on PSA
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200105
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +0100106Current exceptions:
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200107
Manuel Pégourié-Gonnarda6e02912022-12-21 09:59:33 +0100108- Verification of RSA-PSS signatures with an MGF hash that's different from
109 the message hash.
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +0100110- Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see
111 the documentation of that option).
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200112
Manuel Pégourié-Gonnarda6e02912022-12-21 09:59:33 +0100113Other than the above exceptions, all crypto operations are based on PSA when
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200114`MBEDTLS_USE_PSA_CRYPTO` is enabled.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200115