blob: 1f554e5f4d4bccf4a52bc295001e9865cd6a6143 [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
15Effect: `MBEDTLS_USE_PSA_CRYPTO` currently has no effect on TLS 1.3 (which is
16itself experimental and only partially supported so far): TLS 1.3 always uses
17the legacy APIs even when this option is set.
18
19Stability: any API that's only available when `MBEDTLS_USE_PSA_CRYPTO` is
20defined is considered experimental and may change in incompatible ways at any
21time. Said otherwise, these APIs are explicitly excluded from the usual API
22stability promises.
23
24New APIs / API extensions
25-------------------------
26
27Some of these APIs are meant for the application to use in place of
28pre-existing APIs, in order to get access to the benefits; in the sub-sections
29below these are indicated by "Use in (X.509 and) TLS: opt-in", meaning that
30this requires changes to the application code for the (X.509 and) TLS layers
31to pick up the improvements.
32
33Some of these APIs are mostly meant for internal use by the TLS (and X.509)
34layers; they are indicated below by "Use in (X.509 and) TLS: automatic",
35meaning that no changes to the application code are required for the TLS (and
36X.509) layers to pick up the improvements.
37
38### PSA-held (opaque) keys in the PK layer
39
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020040There is a new API function `mbedtls_pk_setup_opaque()` that can be used to
41wrap a PSA keypair into a PK context. The key can be used for private-key
42operations and its public part can be exported.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020043
44Benefits: isolation of long-term secrets, use of PSA Crypto drivers.
45
46Limitations: only for private keys, only ECC. (That is, only ECDSA signature
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020047generation. Note: currently this will use randomized ECDSA while Mbed TLS uses
48deterministic ECDSA by default.) The following operations are not supported
49with a context set this way, while they would be available with a normal
50`ECKEY` context: `mbedtls_pk_verify()`, `mbedtls_pk_check_pair()`,
51`mbedtls_pk_debug()`.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020052
53Use in X.509 and TLS: opt-in. The application needs to construct the PK context
54using the new API in order to get the benefits; it can then pass the
55resulting context to the following existing APIs:
56
57- `mbedtls_ssl_conf_own_cert()` or `mbedtls_ssl_set_hs_own_cert()` to use the
Manuel Pégourié-Gonnard13841cb2021-09-24 11:43:14 +020058 key together with a certificate for ECDSA-based key exchanges (note: while
59this is supported on both sides, it's currently only tested client-side);
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020060- `mbedtls_x509write_csr_set_key()` to generate a CSR (certificate signature
61 request).
62
Manuel Pégourié-Gonnard1b52d092021-09-29 12:28:57 +020063In the TLS and X.509 API, there's one other function which accepts a keypair
64as a PK context: `mbedtls_x509write_crt_set_issuer_key()`. Use of opaque
65contexts here probably works but is so far untested.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020066
Manuel Pégourié-Gonnard9155b0e2021-09-24 10:17:07 +020067### PSA-held (opaque) keys for TLS pre-shared keys (PSK)
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020068
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020069There are two new API functions `mbedtls_ssl_conf_psk_opaque()` and
70`mbedtls_ssl_set_hs_psk_opaque()`. Call one of these from an application to
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020071register a PSA key for use with a PSK key exchange.
72
73Benefits: isolation of long-term secrets.
74
Manuel Pégourié-Gonnard9155b0e2021-09-24 10:17:07 +020075Limitations: the key can only be used with "pure"
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020076PSK key exchanges (ciphersuites starting with `TLS_PSK_WITH_`), to the
77exclusion of RSA-PSK, DHE-PSK and ECDHE-PSK key exchanges. It is the responsibility of
78the user to make sure that when provisioning an opaque pre-shared key, the
79only PSK ciphersuites that can be negotiated are "pure" PSK; other XXX-PSK key
80exchanges will result in a handshake failure with the handshake function
81returning `MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE`.
82
83Use in TLS: opt-in. The application needs to register the key using the new
84APIs to get the benefits.
85
86### PSA-based operations in the Cipher layer
87
Manuel Pégourié-Gonnardca910172021-09-24 10:14:32 +020088There is a new API function `mbedtls_cipher_setup_psa()` to set up a context
89that will call PSA to store the key and perform the operations.
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +020090
91Benefits: use of PSA Crypto drivers; partial isolation of short-term secrets
92(still generated outside of PSA, but then held by PSA).
93
94Limitations: the key is still passed in the clear by the application. The
95multi-part APIs are not supported, only the one-shot APIs. The only modes
96supported are ECB, CBC without padding, GCM and CCM (this excludes stream
97ciphers and ChachaPoly); the only cipher supported is AES (this excludes Aria,
Manuel Pégourié-Gonnard13841cb2021-09-24 11:43:14 +020098Camellia, and ChachaPoly). (Note: ECB is currently not tested.) (Note: it is
99possible to perform multiple one-shot operations with the same context;
100however this is not unit-tested, only tested via usage in TLS.)
Manuel Pégourié-Gonnard1b08c5f2021-09-21 11:21:23 +0200101
102Use in TLS: automatic. Used when the cipher and mode is supported (with
103gracious fallback to the legacy API otherwise) in all places where a cipher is
104used. There are two such places: in `ssl_tls.c` for record protection, and in
105`ssl_ticket.c` for protecting tickets we issue.
106
107Internal changes
108----------------
109
110All of these internal changes are active as soon as `MBEDTLS_USE_PSA_CRYPTO`
111is enabled, no change required on the application side.
112
113### TLS: cipher operations based on PSA
114
115See "PSA-based operations in the Cipher layer" above.
116
117### PK layer: ECDSA verification based on PSA
118
119Scope: `mbedtls_pk_verify()` will call to PSA for ECDSA signature
120verification.
121
122Benefits: use of PSA Crypto drivers.
123
124Use in TLS and X.509: in all places where an ECDSA signature is verified.
125
126### TLS: ECDHE computation based on PSA
127
128Scope: Client-side, for ECDHE-RSA and ECDHE-ECDSA key exchanges, the
129computation of the ECDHE key exchange is done by PSA.
130
131Limitations: client-side only, ECDHE-PSK not covered
132
133Benefits: use of PSA Crypto drivers.
134
135### TLS: handshake hashes and PRF computed with PSA
136
137Scope: with TLS 1.2, the following are computed with PSA:
138- the running handshake hashes;
139- the hash of the ServerKeyExchange part that is signed;
140- the `verify_data` part of the Finished message;
141- the TLS PRF.
142
143Benefits: use of PSA Crypto drivers.
144
145### X.509: some hashes computed with PSA
146
147Scope: the following hashes are computed with PSA:
148- when verifying a certificate chain, hash of the child for verifying the
149 parent's signature;
150- when writing a CSR, hash of the request for self-signing the request.
151
152Benefits: use of PSA Crypto drivers.
153
154Parts that are not covered yet
155==============================
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +0200156
Manuel Pégourié-Gonnard73a0e1d2021-09-21 13:55:00 +0200157This is only a high-level overview, grouped by theme
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +0200158
Manuel Pégourié-Gonnard9155b0e2021-09-24 10:17:07 +0200159TLS: 1.3 experimental support
160-----------------------------
161
162No part of the experimental support for TLS 1.3 is covered at the moment.
163
Manuel Pégourié-Gonnard73a0e1d2021-09-21 13:55:00 +0200164TLS: key exchanges / asymmetric crypto
165--------------------------------------
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +0200166
Manuel Pégourié-Gonnardd3ac4a92021-09-24 10:06:04 +0200167The following key exchanges are not covered at all:
168
169- RSA
170- DHE-RSA
171- DHE-PSK
172- RSA-PSK
173- ECDHE-PSK
174- ECDH-RSA
175- ECDH-ECDSA
176- ECJPAKE
177
178The following key exchanges are only partially covered:
179
180- ECDHE-RSA: RSA operations are not covered and, server-side, the ECDHE
181 operation isn't either
182- ECDHE-ECDSA: server-side, the ECDHE operation isn't covered. (ECDSA
183 signature generation is only covered if using `mbedtls_pk_setup_opaque()`.)
184
185PSK if covered when the application uses `mbedtls_ssl_conf_psk_opaque()` or
186`mbedtls_ssl_set_hs_psk_opaque()`.
Manuel Pégourié-Gonnard13b0beb2021-09-20 13:21:25 +0200187
Manuel Pégourié-Gonnard73a0e1d2021-09-21 13:55:00 +0200188TLS: symmetric crypto
189---------------------
190
191- some ciphers not supported via PSA yet: ARIA, Camellia, ChachaPoly (silent
192 fallback to the legacy APIs)
Manuel Pégourié-Gonnardd3ac4a92021-09-24 10:06:04 +0200193- the HMAC part of the CBC and NULL ciphersuites
Manuel Pégourié-Gonnard73a0e1d2021-09-21 13:55:00 +0200194- the HMAC computation in `ssl_cookie.c`
195
196X.509
197-----
198
199- most hash operations are still done via the legacy API, except the few that
200 are documented above as using PSA
Manuel Pégourié-Gonnardd3ac4a92021-09-24 10:06:04 +0200201- RSA PKCS#1 v1.5 signature generation (from PSA-held keys)
202- RSA PKCS#1 v1.5 signature verification
203- RSA-PSS signature verification