Manuel Pégourié-Gonnard | 73a0e1d | 2021-09-21 13:55:00 +0200 | [diff] [blame] | 1 | This document describes the compile-time configuration option |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 2 | `MBEDTLS_USE_PSA_CRYPTO` from a user's perspective. |
Manuel Pégourié-Gonnard | 13b0beb | 2021-09-20 13:21:25 +0200 | [diff] [blame] | 3 | |
Manuel Pégourié-Gonnard | f3f79a0 | 2022-05-11 13:31:47 +0200 | [diff] [blame] | 4 | This option makes the X.509 and TLS library use PSA for cryptographic |
| 5 | operations, and enables new APIs for using keys handled by PSA Crypto. |
| 6 | |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 7 | General limitations |
| 8 | ------------------- |
Manuel Pégourié-Gonnard | 13b0beb | 2021-09-20 13:21:25 +0200 | [diff] [blame] | 9 | |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 10 | Compile-time: enabling `MBEDTLS_USE_PSA_CRYPTO` requires |
Manuel Pégourié-Gonnard | f3f79a0 | 2022-05-11 13:31:47 +0200 | [diff] [blame] | 11 | `MBEDTLS_ECP_RESTARTABLE` to be disabled. |
| 12 | |
| 13 | Application code: when this option is enabled, you need to call |
| 14 | `psa_crypto_init()` before calling any function from the SSL/TLS, X.509 or PK |
| 15 | module. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 16 | |
Manuel Pégourié-Gonnard | 97ec0b7 | 2022-04-20 15:20:15 +0200 | [diff] [blame] | 17 | Scope: `MBEDTLS_USE_PSA_CRYPTO` has no effect on the parts of the code that |
| 18 | are specific to TLS 1.3; those parts always use PSA Crypto. The parts of the |
Manuel Pégourié-Gonnard | 0dba51c | 2022-06-07 10:28:02 +0200 | [diff] [blame^] | 19 | TLS 1.3 code that are common with TLS 1.2, however, follow this option; |
| 20 | currently this is the record protection code, computation of the running |
| 21 | handshake hash, and X.509). You need to enable `MBEDTLS_USE_PSA_CRYPTO` if you |
| 22 | want TLS 1.3 to use PSA everywhere. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 23 | |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 24 | New APIs / API extensions |
| 25 | ------------------------- |
| 26 | |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 27 | ### PSA-held (opaque) keys in the PK layer |
| 28 | |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 29 | There is a new API function `mbedtls_pk_setup_opaque()` that can be used to |
| 30 | wrap a PSA keypair into a PK context. The key can be used for private-key |
| 31 | operations and its public part can be exported. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 32 | |
| 33 | Benefits: isolation of long-term secrets, use of PSA Crypto drivers. |
| 34 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 35 | Limitations: can only wrap a keypair, can only use it for private key |
| 36 | operations. (That is, signature generation, and for RSA decryption too.) |
| 37 | Note: for ECDSA, currently this uses randomized ECDSA while Mbed TLS uses |
| 38 | deterministic ECDSA by default. The following operations are not supported |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 39 | with a context set this way, while they would be available with a normal |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 40 | `mbedtls_pk_check_pair()`, `mbedtls_pk_debug()`, all public key operations. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 41 | |
| 42 | Use in X.509 and TLS: opt-in. The application needs to construct the PK context |
| 43 | using the new API in order to get the benefits; it can then pass the |
| 44 | resulting context to the following existing APIs: |
| 45 | |
| 46 | - `mbedtls_ssl_conf_own_cert()` or `mbedtls_ssl_set_hs_own_cert()` to use the |
Manuel Pégourié-Gonnard | 13841cb | 2021-09-24 11:43:14 +0200 | [diff] [blame] | 47 | key together with a certificate for ECDSA-based key exchanges (note: while |
| 48 | this is supported on both sides, it's currently only tested client-side); |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 49 | - `mbedtls_x509write_csr_set_key()` to generate a CSR (certificate signature |
| 50 | request). |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 51 | - `mbedtls_x509write_crt_set_issuer_key()` to generate a certificate. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 52 | |
Manuel Pégourié-Gonnard | 9155b0e | 2021-09-24 10:17:07 +0200 | [diff] [blame] | 53 | ### PSA-held (opaque) keys for TLS pre-shared keys (PSK) |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 54 | |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 55 | There are two new API functions `mbedtls_ssl_conf_psk_opaque()` and |
| 56 | `mbedtls_ssl_set_hs_psk_opaque()`. Call one of these from an application to |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 57 | register a PSA key for use with a PSK key exchange. |
| 58 | |
| 59 | Benefits: isolation of long-term secrets. |
| 60 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 61 | Limitations: only TLS 1.2 for now. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 62 | |
| 63 | Use in TLS: opt-in. The application needs to register the key using the new |
| 64 | APIs to get the benefits. |
| 65 | |
| 66 | ### PSA-based operations in the Cipher layer |
| 67 | |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 68 | There is a new API function `mbedtls_cipher_setup_psa()` to set up a context |
| 69 | that will call PSA to store the key and perform the operations. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 70 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 71 | This function only worked for a small number of ciphers. It is now deprecated |
| 72 | and it is recommended to use `psa_cipher_xxx()` or `psa_aead_xxx()` functions |
| 73 | directly instead. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 74 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 75 | This function will be removed in a future version of Mbed TLS. If you are using |
| 76 | it and would like us to keep it, please let us know about your use case. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 77 | |
| 78 | Internal changes |
| 79 | ---------------- |
| 80 | |
| 81 | All of these internal changes are active as soon as `MBEDTLS_USE_PSA_CRYPTO` |
| 82 | is enabled, no change required on the application side. |
| 83 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 84 | ### TLS: most crypto operations based on PSA |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 85 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 86 | Current exceptions: |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 87 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 88 | - EC J-PAKE (when `MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED`) |
| 89 | - finite-field (non-EC) Diffie-Hellman (use in key exchanges: DHE-RSA, |
| 90 | DHE-PSK) |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 91 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 92 | Other than the above exceptions, all crypto operations are based on PSA when |
| 93 | `MBEDTLS_USE_PSA_CRYPTO` is enabled. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 94 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 95 | ### X.509: most crypto operations based on PSA |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 96 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 97 | Current exception: |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 98 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 99 | - verification of RSA-PSS signatures with a salt length that is different from |
| 100 | the hash length. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 101 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 102 | Other than the above exceptions, all crypto operations are based on PSA when |
| 103 | `MBEDTLS_USE_PSA_CRYPTO` is enabled. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 104 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 105 | ### PK layer: most crypto operations based on PSA |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 106 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 107 | Current exception: |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 108 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 109 | - verification of RSA-PSS signatures with a salt length that is different from |
| 110 | the hash length. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 111 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 112 | Other than the above exceptions, all crypto operations are based on PSA when |
| 113 | `MBEDTLS_USE_PSA_CRYPTO` is enabled. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 114 | |