Manuel Pégourié-Gonnard | 73a0e1d | 2021-09-21 13:55:00 +0200 | [diff] [blame] | 1 | This document describes the compile-time configuration option |
| 2 | `MBEDTLS_USE_PSA_CRYPTO` from a user's perspective, more specifically its |
| 3 | current effects as well as the parts that aren't covered yet. |
Manuel Pégourié-Gonnard | 13b0beb | 2021-09-20 13:21:25 +0200 | [diff] [blame] | 4 | |
| 5 | Current effects |
| 6 | =============== |
| 7 | |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 8 | General limitations |
| 9 | ------------------- |
Manuel Pégourié-Gonnard | 13b0beb | 2021-09-20 13:21:25 +0200 | [diff] [blame] | 10 | |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 11 | Compile-time: enabling `MBEDTLS_USE_PSA_CRYPTO` requires |
| 12 | `MBEDTLS_ECP_RESTARTABLE` and |
| 13 | `MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER` to be disabled. |
| 14 | |
Ronald Cron | 0abf07c | 2021-12-08 15:26:59 +0100 | [diff] [blame] | 15 | Effect: `MBEDTLS_USE_PSA_CRYPTO` has no effect on TLS 1.3 for which PSA |
| 16 | cryptography is mandatory. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 17 | |
| 18 | Stability: any API that's only available when `MBEDTLS_USE_PSA_CRYPTO` is |
| 19 | defined is considered experimental and may change in incompatible ways at any |
| 20 | time. Said otherwise, these APIs are explicitly excluded from the usual API |
| 21 | stability promises. |
| 22 | |
| 23 | New APIs / API extensions |
| 24 | ------------------------- |
| 25 | |
| 26 | Some of these APIs are meant for the application to use in place of |
| 27 | pre-existing APIs, in order to get access to the benefits; in the sub-sections |
| 28 | below these are indicated by "Use in (X.509 and) TLS: opt-in", meaning that |
| 29 | this requires changes to the application code for the (X.509 and) TLS layers |
| 30 | to pick up the improvements. |
| 31 | |
| 32 | Some of these APIs are mostly meant for internal use by the TLS (and X.509) |
| 33 | layers; they are indicated below by "Use in (X.509 and) TLS: automatic", |
| 34 | meaning that no changes to the application code are required for the TLS (and |
| 35 | X.509) layers to pick up the improvements. |
| 36 | |
| 37 | ### PSA-held (opaque) keys in the PK layer |
| 38 | |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 39 | There is a new API function `mbedtls_pk_setup_opaque()` that can be used to |
| 40 | wrap a PSA keypair into a PK context. The key can be used for private-key |
| 41 | operations and its public part can be exported. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 42 | |
| 43 | Benefits: isolation of long-term secrets, use of PSA Crypto drivers. |
| 44 | |
| 45 | Limitations: only for private keys, only ECC. (That is, only ECDSA signature |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 46 | generation. Note: currently this will use randomized ECDSA while Mbed TLS uses |
| 47 | deterministic ECDSA by default.) The following operations are not supported |
| 48 | with a context set this way, while they would be available with a normal |
| 49 | `ECKEY` context: `mbedtls_pk_verify()`, `mbedtls_pk_check_pair()`, |
| 50 | `mbedtls_pk_debug()`. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 51 | |
| 52 | Use in X.509 and TLS: opt-in. The application needs to construct the PK context |
| 53 | using the new API in order to get the benefits; it can then pass the |
| 54 | resulting context to the following existing APIs: |
| 55 | |
| 56 | - `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] | 57 | key together with a certificate for ECDSA-based key exchanges (note: while |
| 58 | 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] | 59 | - `mbedtls_x509write_csr_set_key()` to generate a CSR (certificate signature |
| 60 | request). |
| 61 | |
Manuel Pégourié-Gonnard | 1b52d09 | 2021-09-29 12:28:57 +0200 | [diff] [blame] | 62 | In the TLS and X.509 API, there's one other function which accepts a keypair |
| 63 | as a PK context: `mbedtls_x509write_crt_set_issuer_key()`. Use of opaque |
| 64 | contexts here probably works but is so far untested. |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 65 | |
Manuel Pégourié-Gonnard | 9155b0e | 2021-09-24 10:17:07 +0200 | [diff] [blame] | 66 | ### PSA-held (opaque) keys for TLS pre-shared keys (PSK) |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 67 | |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 68 | There are two new API functions `mbedtls_ssl_conf_psk_opaque()` and |
| 69 | `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] | 70 | register a PSA key for use with a PSK key exchange. |
| 71 | |
| 72 | Benefits: isolation of long-term secrets. |
| 73 | |
Manuel Pégourié-Gonnard | 9155b0e | 2021-09-24 10:17:07 +0200 | [diff] [blame] | 74 | Limitations: the key can only be used with "pure" |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 75 | PSK key exchanges (ciphersuites starting with `TLS_PSK_WITH_`), to the |
| 76 | exclusion of RSA-PSK, DHE-PSK and ECDHE-PSK key exchanges. It is the responsibility of |
| 77 | the user to make sure that when provisioning an opaque pre-shared key, the |
| 78 | only PSK ciphersuites that can be negotiated are "pure" PSK; other XXX-PSK key |
| 79 | exchanges will result in a handshake failure with the handshake function |
| 80 | returning `MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE`. |
| 81 | |
| 82 | Use in TLS: opt-in. The application needs to register the key using the new |
| 83 | APIs to get the benefits. |
| 84 | |
| 85 | ### PSA-based operations in the Cipher layer |
| 86 | |
Manuel Pégourié-Gonnard | ca91017 | 2021-09-24 10:14:32 +0200 | [diff] [blame] | 87 | There is a new API function `mbedtls_cipher_setup_psa()` to set up a context |
| 88 | 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] | 89 | |
| 90 | Benefits: use of PSA Crypto drivers; partial isolation of short-term secrets |
| 91 | (still generated outside of PSA, but then held by PSA). |
| 92 | |
| 93 | Limitations: the key is still passed in the clear by the application. The |
| 94 | multi-part APIs are not supported, only the one-shot APIs. The only modes |
| 95 | supported are ECB, CBC without padding, GCM and CCM (this excludes stream |
| 96 | ciphers and ChachaPoly); the only cipher supported is AES (this excludes Aria, |
Manuel Pégourié-Gonnard | 13841cb | 2021-09-24 11:43:14 +0200 | [diff] [blame] | 97 | Camellia, and ChachaPoly). (Note: ECB is currently not tested.) (Note: it is |
| 98 | possible to perform multiple one-shot operations with the same context; |
| 99 | however this is not unit-tested, only tested via usage in TLS.) |
Manuel Pégourié-Gonnard | 1b08c5f | 2021-09-21 11:21:23 +0200 | [diff] [blame] | 100 | |
| 101 | Use in TLS: automatic. Used when the cipher and mode is supported (with |
| 102 | gracious fallback to the legacy API otherwise) in all places where a cipher is |
| 103 | used. There are two such places: in `ssl_tls.c` for record protection, and in |
| 104 | `ssl_ticket.c` for protecting tickets we issue. |
| 105 | |
| 106 | Internal changes |
| 107 | ---------------- |
| 108 | |
| 109 | All of these internal changes are active as soon as `MBEDTLS_USE_PSA_CRYPTO` |
| 110 | is enabled, no change required on the application side. |
| 111 | |
| 112 | ### TLS: cipher operations based on PSA |
| 113 | |
| 114 | See "PSA-based operations in the Cipher layer" above. |
| 115 | |
| 116 | ### PK layer: ECDSA verification based on PSA |
| 117 | |
| 118 | Scope: `mbedtls_pk_verify()` will call to PSA for ECDSA signature |
| 119 | verification. |
| 120 | |
| 121 | Benefits: use of PSA Crypto drivers. |
| 122 | |
| 123 | Use in TLS and X.509: in all places where an ECDSA signature is verified. |
| 124 | |
| 125 | ### TLS: ECDHE computation based on PSA |
| 126 | |
| 127 | Scope: Client-side, for ECDHE-RSA and ECDHE-ECDSA key exchanges, the |
| 128 | computation of the ECDHE key exchange is done by PSA. |
| 129 | |
| 130 | Limitations: client-side only, ECDHE-PSK not covered |
| 131 | |
| 132 | Benefits: use of PSA Crypto drivers. |
| 133 | |
| 134 | ### TLS: handshake hashes and PRF computed with PSA |
| 135 | |
| 136 | Scope: with TLS 1.2, the following are computed with PSA: |
| 137 | - the running handshake hashes; |
| 138 | - the hash of the ServerKeyExchange part that is signed; |
| 139 | - the `verify_data` part of the Finished message; |
| 140 | - the TLS PRF. |
| 141 | |
| 142 | Benefits: use of PSA Crypto drivers. |
| 143 | |
| 144 | ### X.509: some hashes computed with PSA |
| 145 | |
| 146 | Scope: the following hashes are computed with PSA: |
| 147 | - when verifying a certificate chain, hash of the child for verifying the |
| 148 | parent's signature; |
| 149 | - when writing a CSR, hash of the request for self-signing the request. |
| 150 | |
| 151 | Benefits: use of PSA Crypto drivers. |
| 152 | |
| 153 | Parts that are not covered yet |
| 154 | ============================== |
Manuel Pégourié-Gonnard | 13b0beb | 2021-09-20 13:21:25 +0200 | [diff] [blame] | 155 | |
Manuel Pégourié-Gonnard | 73a0e1d | 2021-09-21 13:55:00 +0200 | [diff] [blame] | 156 | This is only a high-level overview, grouped by theme |
Manuel Pégourié-Gonnard | 13b0beb | 2021-09-20 13:21:25 +0200 | [diff] [blame] | 157 | |
Manuel Pégourié-Gonnard | 73a0e1d | 2021-09-21 13:55:00 +0200 | [diff] [blame] | 158 | TLS: key exchanges / asymmetric crypto |
| 159 | -------------------------------------- |
Manuel Pégourié-Gonnard | 13b0beb | 2021-09-20 13:21:25 +0200 | [diff] [blame] | 160 | |
Manuel Pégourié-Gonnard | d3ac4a9 | 2021-09-24 10:06:04 +0200 | [diff] [blame] | 161 | The following key exchanges are not covered at all: |
| 162 | |
| 163 | - RSA |
| 164 | - DHE-RSA |
| 165 | - DHE-PSK |
| 166 | - RSA-PSK |
| 167 | - ECDHE-PSK |
| 168 | - ECDH-RSA |
| 169 | - ECDH-ECDSA |
| 170 | - ECJPAKE |
| 171 | |
| 172 | The following key exchanges are only partially covered: |
| 173 | |
| 174 | - ECDHE-RSA: RSA operations are not covered and, server-side, the ECDHE |
| 175 | operation isn't either |
| 176 | - ECDHE-ECDSA: server-side, the ECDHE operation isn't covered. (ECDSA |
| 177 | signature generation is only covered if using `mbedtls_pk_setup_opaque()`.) |
| 178 | |
| 179 | PSK if covered when the application uses `mbedtls_ssl_conf_psk_opaque()` or |
| 180 | `mbedtls_ssl_set_hs_psk_opaque()`. |
Manuel Pégourié-Gonnard | 13b0beb | 2021-09-20 13:21:25 +0200 | [diff] [blame] | 181 | |
Manuel Pégourié-Gonnard | 73a0e1d | 2021-09-21 13:55:00 +0200 | [diff] [blame] | 182 | TLS: symmetric crypto |
| 183 | --------------------- |
| 184 | |
| 185 | - some ciphers not supported via PSA yet: ARIA, Camellia, ChachaPoly (silent |
| 186 | fallback to the legacy APIs) |
Manuel Pégourié-Gonnard | d3ac4a9 | 2021-09-24 10:06:04 +0200 | [diff] [blame] | 187 | - the HMAC part of the CBC and NULL ciphersuites |
Manuel Pégourié-Gonnard | 73a0e1d | 2021-09-21 13:55:00 +0200 | [diff] [blame] | 188 | - the HMAC computation in `ssl_cookie.c` |
| 189 | |
| 190 | X.509 |
| 191 | ----- |
| 192 | |
| 193 | - most hash operations are still done via the legacy API, except the few that |
| 194 | are documented above as using PSA |
Manuel Pégourié-Gonnard | d3ac4a9 | 2021-09-24 10:06:04 +0200 | [diff] [blame] | 195 | - RSA PKCS#1 v1.5 signature generation (from PSA-held keys) |
| 196 | - RSA PKCS#1 v1.5 signature verification |
| 197 | - RSA-PSS signature verification |