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 | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 7 | General considerations |
| 8 | ---------------------- |
Manuel Pégourié-Gonnard | 13b0beb | 2021-09-20 13:21:25 +0200 | [diff] [blame] | 9 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +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 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 13 | **Application code:** when this option is enabled, you need to call |
Manuel Pégourié-Gonnard | f3f79a0 | 2022-05-11 13:31:47 +0200 | [diff] [blame] | 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 | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 17 | **Scope:** `MBEDTLS_USE_PSA_CRYPTO` has no effect on the parts of the code that |
Manuel Pégourié-Gonnard | 97ec0b7 | 2022-04-20 15:20:15 +0200 | [diff] [blame] | 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 |
Manuel Pégourié-Gonnard | 481846c | 2022-07-12 09:27:39 +0200 | [diff] [blame] | 21 | handshake hash, and X.509. You need to enable `MBEDTLS_USE_PSA_CRYPTO` if you |
Manuel Pégourié-Gonnard | 0dba51c | 2022-06-07 10:28:02 +0200 | [diff] [blame] | 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 | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 29 | **New API function:** `mbedtls_pk_setup_opaque()` - can be used to |
| 30 | wrap a PSA key pair into a PK context. The key can be used for private-key |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 31 | operations and its public part can be exported. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 32 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 33 | **Benefits:** isolation of long-term secrets, use of PSA Crypto drivers. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 34 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 35 | **Limitations:** can only wrap a key pair, can only use it for private key |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 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 | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 40 | context: `mbedtls_pk_check_pair()`, `mbedtls_pk_debug()`, all public key |
| 41 | operations. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 42 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 43 | **Use in X.509 and TLS:** opt-in. The application needs to construct the PK context |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 44 | using the new API in order to get the benefits; it can then pass the |
| 45 | resulting 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é-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 48 | key together with a certificate for certificate-based key exchanges; |
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 |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 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 | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 55 | **New API functions:** `mbedtls_ssl_conf_psk_opaque()` and |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 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 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 59 | **Benefits:** isolation of long-term secrets. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 60 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 61 | **Limitations:** none. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 62 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 63 | **Use in TLS:** opt-in. The application needs to register the key using one of |
| 64 | the new APIs to get the benefits. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 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 | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 75 | **Warning:** This function will be removed in a future version of Mbed TLS. If |
| 76 | you are using it and would like us to keep it, please let us know about your |
| 77 | use case. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 78 | |
| 79 | Internal changes |
| 80 | ---------------- |
| 81 | |
| 82 | All of these internal changes are active as soon as `MBEDTLS_USE_PSA_CRYPTO` |
| 83 | is enabled, no change required on the application side. |
| 84 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 85 | ### TLS: most crypto operations based on PSA |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 86 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 87 | Current exceptions: |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 88 | |
Manuel Pégourié-Gonnard | b5b27c1 | 2022-06-10 11:09:03 +0200 | [diff] [blame] | 89 | - 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é-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 91 | DHE-PSK) |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 92 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 93 | Other than the above exceptions, all crypto operations are based on PSA when |
| 94 | `MBEDTLS_USE_PSA_CRYPTO` is enabled. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 95 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 96 | ### X.509: most crypto operations based on PSA |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 97 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 98 | Current exception: |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 99 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 100 | - verification of RSA-PSS signatures with a salt length that is different from |
| 101 | the hash length. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 102 | |
Manuel Pégourié-Gonnard | 481846c | 2022-07-12 09:27:39 +0200 | [diff] [blame] | 103 | Other than the above exception, all crypto operations are based on PSA when |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 104 | `MBEDTLS_USE_PSA_CRYPTO` is enabled. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 105 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 106 | ### PK layer: most crypto operations based on PSA |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 107 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 108 | Current exception: |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 109 | |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 110 | - verification of RSA-PSS signatures with a salt length that is different from |
Manuel Pégourié-Gonnard | 481846c | 2022-07-12 09:27:39 +0200 | [diff] [blame] | 111 | the hash length, or with an MGF hash that's different from the message hash. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 112 | |
Manuel Pégourié-Gonnard | 481846c | 2022-07-12 09:27:39 +0200 | [diff] [blame] | 113 | Other than the above exception, all crypto operations are based on PSA when |
Manuel Pégourié-Gonnard | b2bd34e | 2022-04-20 15:58:00 +0200 | [diff] [blame] | 114 | `MBEDTLS_USE_PSA_CRYPTO` is enabled. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 115 | |