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