blob: 4058cb65fae6e61ff218e6727c8d0fb0f0c491cd [file] [log] [blame] [view]
Manuel Pégourié-Gonnard73a0e1d2021-09-21 13:55:00 +02001This document describes the compile-time configuration option
2`MBEDTLS_USE_PSA_CRYPTO` from a user's perspective, more specifically its
3current effects as well as the parts that aren't covered yet.
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +02004
5Current effects
6===============
7
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +02008General limitations
9-------------------
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +020010
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020011Compile-time: enabling `MBEDTLS_USE_PSA_CRYPTO` requires
12`MBEDTLS_ECP_RESTARTABLE` and
13`MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER` to be disabled.
14
Manuel Pégourié-Gonnard97ec0b72022-04-20 15:20:15 +020015Scope: `MBEDTLS_USE_PSA_CRYPTO` has no effect on the parts of the code that
16are specific to TLS 1.3; those parts always use PSA Crypto. The parts of the
17TLS 1.3 code that are common with TLS 1.2, however, follow this option (this
18is currently just the record protection code).
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020019
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020020New APIs / API extensions
21-------------------------
22
23Some of these APIs are meant for the application to use in place of
24pre-existing APIs, in order to get access to the benefits; in the sub-sections
25below these are indicated by "Use in (X.509 and) TLS: opt-in", meaning that
26this requires changes to the application code for the (X.509 and) TLS layers
27to pick up the improvements.
28
29Some of these APIs are mostly meant for internal use by the TLS (and X.509)
30layers; they are indicated below by "Use in (X.509 and) TLS: automatic",
31meaning that no changes to the application code are required for the TLS (and
32X.509) layers to pick up the improvements.
33
34### PSA-held (opaque) keys in the PK layer
35
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020036There is a new API function `mbedtls_pk_setup_opaque()` that can be used to
37wrap a PSA keypair into a PK context. The key can be used for private-key
38operations and its public part can be exported.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020039
40Benefits: isolation of long-term secrets, use of PSA Crypto drivers.
41
42Limitations: only for private keys, only ECC. (That is, only ECDSA signature
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020043generation. Note: currently this will use randomized ECDSA while Mbed TLS uses
44deterministic ECDSA by default.) The following operations are not supported
45with a context set this way, while they would be available with a normal
46`ECKEY` context: `mbedtls_pk_verify()`, `mbedtls_pk_check_pair()`,
47`mbedtls_pk_debug()`.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020048
49Use in X.509 and TLS: opt-in. The application needs to construct the PK context
50using the new API in order to get the benefits; it can then pass the
51resulting context to the following existing APIs:
52
53- `mbedtls_ssl_conf_own_cert()` or `mbedtls_ssl_set_hs_own_cert()` to use the
Manuel Pégourié-Gonnard13841cb2021-09-24 11:43:14 +020054 key together with a certificate for ECDSA-based key exchanges (note: while
55this is supported on both sides, it's currently only tested client-side);
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020056- `mbedtls_x509write_csr_set_key()` to generate a CSR (certificate signature
57 request).
58
Manuel Pégourié-Gonnard1b52d092021-09-29 12:28:57 +020059In the TLS and X.509 API, there's one other function which accepts a keypair
60as a PK context: `mbedtls_x509write_crt_set_issuer_key()`. Use of opaque
61contexts here probably works but is so far untested.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020062
Manuel Pégourié-Gonnard9155b0e2021-09-24 10:17:07 +020063### PSA-held (opaque) keys for TLS pre-shared keys (PSK)
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020064
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020065There are two new API functions `mbedtls_ssl_conf_psk_opaque()` and
66`mbedtls_ssl_set_hs_psk_opaque()`. Call one of these from an application to
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020067register a PSA key for use with a PSK key exchange.
68
69Benefits: isolation of long-term secrets.
70
Manuel Pégourié-Gonnard9155b0e2021-09-24 10:17:07 +020071Limitations: the key can only be used with "pure"
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020072PSK key exchanges (ciphersuites starting with `TLS_PSK_WITH_`), to the
73exclusion of RSA-PSK, DHE-PSK and ECDHE-PSK key exchanges. It is the responsibility of
74the user to make sure that when provisioning an opaque pre-shared key, the
75only PSK ciphersuites that can be negotiated are "pure" PSK; other XXX-PSK key
76exchanges will result in a handshake failure with the handshake function
77returning `MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE`.
78
79Use in TLS: opt-in. The application needs to register the key using the new
80APIs to get the benefits.
81
82### PSA-based operations in the Cipher layer
83
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020084There is a new API function `mbedtls_cipher_setup_psa()` to set up a context
85that will call PSA to store the key and perform the operations.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020086
87Benefits: use of PSA Crypto drivers; partial isolation of short-term secrets
88(still generated outside of PSA, but then held by PSA).
89
90Limitations: the key is still passed in the clear by the application. The
91multi-part APIs are not supported, only the one-shot APIs. The only modes
92supported are ECB, CBC without padding, GCM and CCM (this excludes stream
93ciphers and ChachaPoly); the only cipher supported is AES (this excludes Aria,
Manuel Pégourié-Gonnard13841cb2021-09-24 11:43:14 +020094Camellia, and ChachaPoly). (Note: ECB is currently not tested.) (Note: it is
95possible to perform multiple one-shot operations with the same context;
96however this is not unit-tested, only tested via usage in TLS.)
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020097
98Use in TLS: automatic. Used when the cipher and mode is supported (with
99gracious fallback to the legacy API otherwise) in all places where a cipher is
100used. There are two such places: in `ssl_tls.c` for record protection, and in
101`ssl_ticket.c` for protecting tickets we issue.
102
103Internal changes
104----------------
105
106All of these internal changes are active as soon as `MBEDTLS_USE_PSA_CRYPTO`
107is enabled, no change required on the application side.
108
109### TLS: cipher operations based on PSA
110
111See "PSA-based operations in the Cipher layer" above.
112
113### PK layer: ECDSA verification based on PSA
114
115Scope: `mbedtls_pk_verify()` will call to PSA for ECDSA signature
116verification.
117
118Benefits: use of PSA Crypto drivers.
119
120Use in TLS and X.509: in all places where an ECDSA signature is verified.
121
122### TLS: ECDHE computation based on PSA
123
124Scope: Client-side, for ECDHE-RSA and ECDHE-ECDSA key exchanges, the
125computation of the ECDHE key exchange is done by PSA.
126
127Limitations: client-side only, ECDHE-PSK not covered
128
129Benefits: use of PSA Crypto drivers.
130
131### TLS: handshake hashes and PRF computed with PSA
132
133Scope: with TLS 1.2, the following are computed with PSA:
134- the running handshake hashes;
135- the hash of the ServerKeyExchange part that is signed;
136- the `verify_data` part of the Finished message;
137- the TLS PRF.
138
139Benefits: use of PSA Crypto drivers.
140
141### X.509: some hashes computed with PSA
142
143Scope: the following hashes are computed with PSA:
144- when verifying a certificate chain, hash of the child for verifying the
145 parent's signature;
146- when writing a CSR, hash of the request for self-signing the request.
147
148Benefits: use of PSA Crypto drivers.
149
150Parts that are not covered yet
151==============================
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +0200152
Manuel Pégourié-Gonnard73a0e1d2021-09-21 13:55:00 +0200153This is only a high-level overview, grouped by theme
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +0200154
Manuel Pégourié-Gonnard73a0e1d2021-09-21 13:55:00 +0200155TLS: key exchanges / asymmetric crypto
156--------------------------------------
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +0200157
Manuel Pégourié-Gonnardd3ac4a92021-09-24 10:06:04 +0200158The following key exchanges are not covered at all:
159
160- RSA
161- DHE-RSA
162- DHE-PSK
163- RSA-PSK
164- ECDHE-PSK
165- ECDH-RSA
166- ECDH-ECDSA
167- ECJPAKE
168
169The following key exchanges are only partially covered:
170
171- ECDHE-RSA: RSA operations are not covered and, server-side, the ECDHE
172 operation isn't either
173- ECDHE-ECDSA: server-side, the ECDHE operation isn't covered. (ECDSA
174 signature generation is only covered if using `mbedtls_pk_setup_opaque()`.)
175
176PSK if covered when the application uses `mbedtls_ssl_conf_psk_opaque()` or
177`mbedtls_ssl_set_hs_psk_opaque()`.
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +0200178
Manuel Pégourié-Gonnard73a0e1d2021-09-21 13:55:00 +0200179TLS: symmetric crypto
180---------------------
181
182- some ciphers not supported via PSA yet: ARIA, Camellia, ChachaPoly (silent
183 fallback to the legacy APIs)
Manuel Pégourié-Gonnardd3ac4a92021-09-24 10:06:04 +0200184- the HMAC part of the CBC and NULL ciphersuites
Manuel Pégourié-Gonnard73a0e1d2021-09-21 13:55:00 +0200185- the HMAC computation in `ssl_cookie.c`
186
187X.509
188-----
189
190- most hash operations are still done via the legacy API, except the few that
191 are documented above as using PSA
Manuel Pégourié-Gonnardd3ac4a92021-09-24 10:06:04 +0200192- RSA PKCS#1 v1.5 signature generation (from PSA-held keys)
193- RSA PKCS#1 v1.5 signature verification
194- RSA-PSS signature verification