blob: 7c0397f62c858cb79c913641e806bf969299a41b [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é-Gonnard2ca08c82023-03-24 09:21:46 +01004This option:
5- makes the X.509 and TLS libraries use PSA for cryptographic operations as
6 much as possible, see "Internal changes" below;
7- enables new APIs for using keys handled by PSA Crypto, such as
8 `mbedtls_pk_setup_opaque()` and `mbedtls_ssl_conf_psk_opaque()`, see
9"New APIs / API extensions" 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
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020014**Application code:** when this option is enabled, you need to call
Manuel Pégourié-Gonnardf3f79a02022-05-11 13:31:47 +020015`psa_crypto_init()` before calling any function from the SSL/TLS, X.509 or PK
16module.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020017
Manuel Pégourié-Gonnard93b21e72023-03-29 10:30:26 +020018**Why enable this option:** to fully take advantage of PSA drivers in PK,
19X.509 and TLS. For example, enabling this option is what allows use of drivers
20for ECDSA, ECDH and EC J-PAKE in those modules. However, note that ven with
21this option disabled, some code in PK, X.509, TLS or the crypto library might
22still use PSA drivers, if it can determine it's safe to do so; currently
23that's the case for hashes.
24
Manuel Pégourié-Gonnard2ca08c82023-03-24 09:21:46 +010025**Relationship with other options:** This option depends on
26`MBEDTLS_PSA_CRYPTO_C`. These two options differ in the following way:
27- `MBEDTLS_PSA_CRYPTO_C` enables the implementation of the PSA Crypto API.
28 When it is enabled, `psa_xxx()` APIs are available and you must call
29`psa_crypto_init()` before you call any other `psa_xxx()` function. Other
30modules in the library (non-PSA crypto APIs, X.509, TLS) may or may not use
31PSA Crypto but you're not required to call `psa_crypto_init()` before calling
Manuel Pégourié-Gonnard5c8c9e02023-03-29 10:33:03 +020032non-PSA functions, unless explicitly documented (TLS 1.3).
Manuel Pégourié-Gonnard2ca08c82023-03-24 09:21:46 +010033- `MBEDTLS_USE_PSA_CRYPTO` means that X.509 and TLS will use PSA Crypto as
34 much as possible (that is, everywhere except for features that are not
35supported by PSA Crypto, see "Internal Changes" below for a complete list of
36exceptions). When it is enabled, you need to call `psa_crypto_init()` before
37calling any function from PK, X.509 or TLS; however it doesn't change anything
38for the rest of the library.
39
40**Scope:** `MBEDTLS_USE_PSA_CRYPTO` has no effect on modules other than PK,
41X.509 and TLS. It also has no effect on most of the TLS 1.3 code, which always
42uses PSA crypto. The parts of the TLS 1.3 code that will use PSA Crypto or not
43depending on this option being set or not are:
Manuel Pégourié-Gonnard439dbc52023-03-10 12:33:15 +010044- record protection;
45- running handshake hash;
46- asymmetric signature verification & generation;
47- X.509 certificate chain verification.
48You need to enable `MBEDTLS_USE_PSA_CRYPTO` if you want TLS 1.3 to use PSA
49everywhere.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020050
Manuel Pégourié-Gonnard2ca08c82023-03-24 09:21:46 +010051**Historical note:** This option was introduced at a time when PSA Crypto was
52still beta and not ready for production, so we made its use in X.509 and TLS
53opt-in: by default, these modules would keep using the stable,
54production-ready legacy (pre-PSA) crypto APIs. So, the scope of was X.509 and
55TLS, as well as some of PK for technical reasons. Nowadays PSA Crypto is no
56longer beta, and production quality, so there's no longer any reason to make
57its use in other modules opt-in. However, PSA Crypto functions require that
58`psa_crypto_init()` has been called before their use, and for backwards
59compatibility reasons we can't impose this requirement on non-PSA functions
60that didn't have such a requirement before. So, nowadays the main meaning of
61`MBEDTLS_USE_PSA_CRYPTO` is that the user promises to call `psa_crypto_init()`
62before calling any PK, X.509 or TLS functions. For the same compatibility
63reasons, we can't extend its scope. However, new modules in the library, such
64as TLS 1.3, can be introduced with a requirement to call `psa_crypto_init()`.
Manuel Pégourié-Gonnard3dd9add2023-03-22 16:17:54 +010065
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020066New APIs / API extensions
67-------------------------
68
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020069### PSA-held (opaque) keys in the PK layer
70
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020071**New API function:** `mbedtls_pk_setup_opaque()` - can be used to
72wrap 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 +020073operations and its public part can be exported.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020074
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020075**Benefits:** isolation of long-term secrets, use of PSA Crypto drivers.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020076
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020077**Limitations:** can only wrap a key pair, can only use it for private key
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020078operations. (That is, signature generation, and for RSA decryption too.)
79Note: for ECDSA, currently this uses randomized ECDSA while Mbed TLS uses
80deterministic ECDSA by default. The following operations are not supported
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020081with a context set this way, while they would be available with a normal
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020082context: `mbedtls_pk_check_pair()`, `mbedtls_pk_debug()`, all public key
83operations.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020084
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020085**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 +020086using the new API in order to get the benefits; it can then pass the
87resulting context to the following existing APIs:
88
89- `mbedtls_ssl_conf_own_cert()` or `mbedtls_ssl_set_hs_own_cert()` to use the
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020090 key together with a certificate for certificate-based key exchanges;
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020091- `mbedtls_x509write_csr_set_key()` to generate a CSR (certificate signature
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020092 request);
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020093- `mbedtls_x509write_crt_set_issuer_key()` to generate a certificate.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020094
Manuel Pégourié-Gonnard9155b0e2021-09-24 10:17:07 +020095### PSA-held (opaque) keys for TLS pre-shared keys (PSK)
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020096
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020097**New API functions:** `mbedtls_ssl_conf_psk_opaque()` and
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020098`mbedtls_ssl_set_hs_psk_opaque()`. Call one of these from an application to
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020099register a PSA key for use with a PSK key exchange.
100
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +0200101**Benefits:** isolation of long-term secrets.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200102
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +0200103**Limitations:** none.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200104
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +0200105**Use in TLS:** opt-in. The application needs to register the key using one of
106the new APIs to get the benefits.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200107
Manuel Pégourié-Gonnard86efa852023-03-24 09:26:40 +0100108### PSA-held (opaque) keys for TLS 1.2 EC J-PAKE key exchange
109
110**New API function:** `mbedtls_ssl_set_hs_ecjpake_password_opaque()`.
111Call this function from an application to register a PSA key for use with the
112TLS 1.2 EC J-PAKE key exchange.
113
114**Benefits:** isolation of long-term secrets.
115
116**Limitations:** none.
117
118**Use in TLS:** opt-in. The application needs to register the key using one of
119the new APIs to get the benefits.
120
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200121### PSA-based operations in the Cipher layer
122
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +0200123There is a new API function `mbedtls_cipher_setup_psa()` to set up a context
124that will call PSA to store the key and perform the operations.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200125
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200126This function only worked for a small number of ciphers. It is now deprecated
127and it is recommended to use `psa_cipher_xxx()` or `psa_aead_xxx()` functions
128directly instead.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200129
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +0200130**Warning:** This function will be removed in a future version of Mbed TLS. If
131you are using it and would like us to keep it, please let us know about your
132use case.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200133
134Internal changes
135----------------
136
137All of these internal changes are active as soon as `MBEDTLS_USE_PSA_CRYPTO`
138is enabled, no change required on the application side.
139
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200140### TLS: most crypto operations based on PSA
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200141
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200142Current exceptions:
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200143
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +0100144- Finite-field (non-EC) Diffie-Hellman (used in key exchanges: DHE-RSA,
145 DHE-PSK).
146- Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see
147 the documentation of that option).
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200148
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200149Other than the above exceptions, all crypto operations are based on PSA when
150`MBEDTLS_USE_PSA_CRYPTO` is enabled.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200151
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200152### X.509: most crypto operations based on PSA
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200153
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +0100154Current exceptions:
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200155
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +0100156- Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see
157 the documentation of that option).
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200158
Manuel Pégourié-Gonnard481846c2022-07-12 09:27:39 +0200159Other than the above exception, all crypto operations are based on PSA when
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200160`MBEDTLS_USE_PSA_CRYPTO` is enabled.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200161
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200162### PK layer: most crypto operations based on PSA
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200163
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +0100164Current exceptions:
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200165
Manuel Pégourié-Gonnarda6e02912022-12-21 09:59:33 +0100166- Verification of RSA-PSS signatures with an MGF hash that's different from
167 the message hash.
Manuel Pégourié-Gonnard55a188b2022-12-06 12:00:33 +0100168- Restartable operations when `MBEDTLS_ECP_RESTARTABLE` is also enabled (see
169 the documentation of that option).
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200170
Manuel Pégourié-Gonnarda6e02912022-12-21 09:59:33 +0100171Other than the above exceptions, all crypto operations are based on PSA when
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200172`MBEDTLS_USE_PSA_CRYPTO` is enabled.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200173