blob: 9c97b5d5c7410287c512e326313283f9fecaad00 [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
Ronald Cron0abf07c2021-12-08 15:26:59 +010015Effect: `MBEDTLS_USE_PSA_CRYPTO` has no effect on TLS 1.3 for which PSA
16cryptography is mandatory.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020017
18Stability: any API that's only available when `MBEDTLS_USE_PSA_CRYPTO` is
19defined is considered experimental and may change in incompatible ways at any
20time. Said otherwise, these APIs are explicitly excluded from the usual API
21stability promises.
22
23New APIs / API extensions
24-------------------------
25
26Some of these APIs are meant for the application to use in place of
27pre-existing APIs, in order to get access to the benefits; in the sub-sections
28below these are indicated by "Use in (X.509 and) TLS: opt-in", meaning that
29this requires changes to the application code for the (X.509 and) TLS layers
30to pick up the improvements.
31
32Some of these APIs are mostly meant for internal use by the TLS (and X.509)
33layers; they are indicated below by "Use in (X.509 and) TLS: automatic",
34meaning that no changes to the application code are required for the TLS (and
35X.509) layers to pick up the improvements.
36
37### PSA-held (opaque) keys in the PK layer
38
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020039There is a new API function `mbedtls_pk_setup_opaque()` that can be used to
40wrap a PSA keypair into a PK context. The key can be used for private-key
41operations and its public part can be exported.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020042
43Benefits: isolation of long-term secrets, use of PSA Crypto drivers.
44
45Limitations: only for private keys, only ECC. (That is, only ECDSA signature
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020046generation. Note: currently this will use randomized ECDSA while Mbed TLS uses
47deterministic ECDSA by default.) The following operations are not supported
48with 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é-Gonnard1b08c5f2021-09-21 11:21:23 +020051
52Use in X.509 and TLS: opt-in. The application needs to construct the PK context
53using the new API in order to get the benefits; it can then pass the
54resulting 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é-Gonnard13841cb2021-09-24 11:43:14 +020057 key together with a certificate for ECDSA-based key exchanges (note: while
58this is supported on both sides, it's currently only tested client-side);
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020059- `mbedtls_x509write_csr_set_key()` to generate a CSR (certificate signature
60 request).
61
Manuel Pégourié-Gonnard1b52d092021-09-29 12:28:57 +020062In the TLS and X.509 API, there's one other function which accepts a keypair
63as a PK context: `mbedtls_x509write_crt_set_issuer_key()`. Use of opaque
64contexts here probably works but is so far untested.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020065
Manuel Pégourié-Gonnard9155b0e2021-09-24 10:17:07 +020066### PSA-held (opaque) keys for TLS pre-shared keys (PSK)
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020067
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020068There 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é-Gonnard1b08c5f2021-09-21 11:21:23 +020070register a PSA key for use with a PSK key exchange.
71
72Benefits: isolation of long-term secrets.
73
Manuel Pégourié-Gonnard9155b0e2021-09-24 10:17:07 +020074Limitations: the key can only be used with "pure"
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020075PSK key exchanges (ciphersuites starting with `TLS_PSK_WITH_`), to the
76exclusion of RSA-PSK, DHE-PSK and ECDHE-PSK key exchanges. It is the responsibility of
77the user to make sure that when provisioning an opaque pre-shared key, the
78only PSK ciphersuites that can be negotiated are "pure" PSK; other XXX-PSK key
79exchanges will result in a handshake failure with the handshake function
80returning `MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE`.
81
82Use in TLS: opt-in. The application needs to register the key using the new
83APIs to get the benefits.
84
85### PSA-based operations in the Cipher layer
86
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020087There is a new API function `mbedtls_cipher_setup_psa()` to set up a context
88that will call PSA to store the key and perform the operations.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020089
90Benefits: use of PSA Crypto drivers; partial isolation of short-term secrets
91(still generated outside of PSA, but then held by PSA).
92
93Limitations: the key is still passed in the clear by the application. The
94multi-part APIs are not supported, only the one-shot APIs. The only modes
95supported are ECB, CBC without padding, GCM and CCM (this excludes stream
96ciphers and ChachaPoly); the only cipher supported is AES (this excludes Aria,
Manuel Pégourié-Gonnard13841cb2021-09-24 11:43:14 +020097Camellia, and ChachaPoly). (Note: ECB is currently not tested.) (Note: it is
98possible to perform multiple one-shot operations with the same context;
99however this is not unit-tested, only tested via usage in TLS.)
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200100
101Use in TLS: automatic. Used when the cipher and mode is supported (with
102gracious fallback to the legacy API otherwise) in all places where a cipher is
103used. There are two such places: in `ssl_tls.c` for record protection, and in
104`ssl_ticket.c` for protecting tickets we issue.
105
106Internal changes
107----------------
108
109All of these internal changes are active as soon as `MBEDTLS_USE_PSA_CRYPTO`
110is enabled, no change required on the application side.
111
112### TLS: cipher operations based on PSA
113
114See "PSA-based operations in the Cipher layer" above.
115
116### PK layer: ECDSA verification based on PSA
117
118Scope: `mbedtls_pk_verify()` will call to PSA for ECDSA signature
119verification.
120
121Benefits: use of PSA Crypto drivers.
122
123Use in TLS and X.509: in all places where an ECDSA signature is verified.
124
125### TLS: ECDHE computation based on PSA
126
127Scope: Client-side, for ECDHE-RSA and ECDHE-ECDSA key exchanges, the
128computation of the ECDHE key exchange is done by PSA.
129
130Limitations: client-side only, ECDHE-PSK not covered
131
132Benefits: use of PSA Crypto drivers.
133
134### TLS: handshake hashes and PRF computed with PSA
135
136Scope: 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
142Benefits: use of PSA Crypto drivers.
143
144### X.509: some hashes computed with PSA
145
146Scope: 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
151Benefits: use of PSA Crypto drivers.
152
153Parts that are not covered yet
154==============================
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +0200155
Manuel Pégourié-Gonnard73a0e1d2021-09-21 13:55:00 +0200156This is only a high-level overview, grouped by theme
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +0200157
Manuel Pégourié-Gonnard73a0e1d2021-09-21 13:55:00 +0200158TLS: key exchanges / asymmetric crypto
159--------------------------------------
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +0200160
Manuel Pégourié-Gonnardd3ac4a92021-09-24 10:06:04 +0200161The 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
172The 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
179PSK if covered when the application uses `mbedtls_ssl_conf_psk_opaque()` or
180`mbedtls_ssl_set_hs_psk_opaque()`.
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +0200181
Manuel Pégourié-Gonnard73a0e1d2021-09-21 13:55:00 +0200182TLS: 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é-Gonnardd3ac4a92021-09-24 10:06:04 +0200187- the HMAC part of the CBC and NULL ciphersuites
Manuel Pégourié-Gonnard73a0e1d2021-09-21 13:55:00 +0200188- the HMAC computation in `ssl_cookie.c`
189
190X.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é-Gonnardd3ac4a92021-09-24 10:06:04 +0200195- RSA PKCS#1 v1.5 signature generation (from PSA-held keys)
196- RSA PKCS#1 v1.5 signature verification
197- RSA-PSS signature verification