blob: b22d37f65f4a2ec8145ddb6607b0b35863fa5d81 [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**Compile-time:** enabling `MBEDTLS_USE_PSA_CRYPTO` requires
Manuel Pégourié-Gonnardf3f79a02022-05-11 13:31:47 +020011`MBEDTLS_ECP_RESTARTABLE` to be disabled.
12
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020013**Application code:** when this option is enabled, you need to call
Manuel Pégourié-Gonnardf3f79a02022-05-11 13:31:47 +020014`psa_crypto_init()` before calling any function from the SSL/TLS, X.509 or PK
15module.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020016
Manuel Pégourié-Gonnardb5b27c12022-06-10 11:09:03 +020017**Scope:** `MBEDTLS_USE_PSA_CRYPTO` has no effect on the parts of the code that
Manuel Pégourié-Gonnard97ec0b72022-04-20 15:20:15 +020018are specific to TLS 1.3; those parts always use PSA Crypto. The parts of the
Manuel Pégourié-Gonnard0dba51c2022-06-07 10:28:02 +020019TLS 1.3 code that are common with TLS 1.2, however, follow this option;
20currently this is the record protection code, computation of the running
Manuel Pégourié-Gonnard481846c2022-07-12 09:27:39 +020021handshake hash, and X.509. You need to enable `MBEDTLS_USE_PSA_CRYPTO` if you
Manuel Pégourié-Gonnard0dba51c2022-06-07 10:28:02 +020022want TLS 1.3 to use PSA everywhere.
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é-Gonnardb5b27c12022-06-10 11:09:03 +020089- EC J-PAKE (when `MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED` is defined)
90- finite-field (non-EC) Diffie-Hellman (used in key exchanges: DHE-RSA,
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020091 DHE-PSK)
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020092
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020093Other than the above exceptions, all crypto operations are based on PSA when
94`MBEDTLS_USE_PSA_CRYPTO` is enabled.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020095
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020096### X.509: most crypto operations based on PSA
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020097
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +020098Current exception:
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020099
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200100- verification of RSA-PSS signatures with a salt length that is different from
101 the hash length.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200102
Manuel Pégourié-Gonnard481846c2022-07-12 09:27:39 +0200103Other than the above exception, all crypto operations are based on PSA when
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200104`MBEDTLS_USE_PSA_CRYPTO` is enabled.
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é-Gonnardb2bd34e2022-04-20 15:58:00 +0200108Current exception:
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200109
Manuel Pégourié-Gonnardb2bd34e2022-04-20 15:58:00 +0200110- verification of RSA-PSS signatures with a salt length that is different from
Manuel Pégourié-Gonnard481846c2022-07-12 09:27:39 +0200111 the hash length, or with an MGF hash that's different from the message hash.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200112
Manuel Pégourié-Gonnard481846c2022-07-12 09:27:39 +0200113Other than the above exception, 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