blob: e565b283e95c73aa3b61a0a86ae461399dba7858 [file] [log] [blame] [view]
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +02001This document lists current limitations of the PSA Crypto API (as of version
21.1) that may impact our ability to (1) use it for all crypto operations in
3TLS and X.509 and (2) support isolation of all long-term secrets in TLS (that
Manuel Pégourié-Gonnard8e559da2022-02-01 10:26:07 +01004is, goals G1 and G2 in [strategy.md](strategy.md) in the same directory).
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +02005
6This is supposed to be a complete list, based on a exhaustive review of crypto
7operations done in TLS and X.509 code, but of course it's still possible that
8subtle-but-important issues have been missed. The only way to be really sure
9is, of course, to actually do the migration work.
10
11Limitations relevant for G1 (performing crypto operations)
12==========================================================
13
14Restartable ECC operations
15--------------------------
16
Manuel Pégourié-Gonnard9bf9b9e2022-06-07 10:16:24 +020017There is currently no support for that in PSA at all, but it will be added at
18some point, see <https://github.com/orgs/Mbed-TLS/projects/1#column-18816849>.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020019
20Currently, `MBEDTLS_USE_PSA_CRYPTO` is simply incompatible with
21`MBEDTLS_ECP_RESTARTABLE`.
22
Manuel Pégourié-Gonnard8e559da2022-02-01 10:26:07 +010023Things that are in the API but not implemented yet
24--------------------------------------------------
25
26PSA Crypto has an API for FFDH, but it's not implemented in Mbed TLS yet.
27(Regarding FFDH, see the next section as well.) See issue [3261][ffdh] on
28github.
29
Dave Rodgman017a1992022-03-31 14:07:01 +010030[ffdh]: https://github.com/Mbed-TLS/mbedtls/issues/3261
Manuel Pégourié-Gonnard8e559da2022-02-01 10:26:07 +010031
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020032Arbitrary parameters for FFDH
33-----------------------------
34
Manuel Pégourié-Gonnard8e559da2022-02-01 10:26:07 +010035(See also the first paragraph in the previous section.)
36
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020037Currently, the PSA Crypto API can only perform FFDH with a limited set of
Manuel Pégourié-Gonnard58d101b2022-02-10 12:58:09 +010038well-known parameters (some of them defined in the spec, but implementations
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020039are free to extend that set).
40
41TLS 1.2 (and earlier) on the other hand have the server send explicit
Manuel Pégourié-Gonnard58d101b2022-02-10 12:58:09 +010042parameters (P and G) in its ServerKeyExchange message. This has been found to
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020043be suboptimal for security, as it is prohibitively hard for the client to
44verify the strength of these parameters. This led to the development of RFC
457919 which allows use of named groups in TLS 1.2 - however as this is only an
46extension, servers can still send custom parameters if they don't support the
47extension.
48
49In TLS 1.3 the situation will be simpler: named groups are the only
50option, so the current PSA Crypto API is a good match for that. (Not
Manuel Pégourié-Gonnardc7f32542022-02-10 13:00:33 +010051coincidentally, all the groups used by RFC 7919 and TLS 1.3 are included
52in the PSA specification.)
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020053
54There are several options here:
55
561. Implement support for custom FFDH parameters in PSA Crypto: this would pose
57 non-trivial API design problem, but most importantly seems backwards, as
Manuel Pégourié-Gonnard83c53882022-04-20 14:27:48 +020058the crypto community is moving away from custom FFDH parameters. (Could be
59done any time.)
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200602. Drop the DHE-RSA and DHE-PSK key exchanges in TLS 1.2 when moving to PSA.
Manuel Pégourié-Gonnard83c53882022-04-20 14:27:48 +020061 (For people who want some algorithmic variety in case ECC collapses, FFDH
62would still be available in TLS 1.3, just not in 1.2.) (Can only be done in
634.0 or another major version.)
643. Variant of the precedent: only drop client-side support. Server-side is
65 easy to support in terms of API/protocol, as the server picks the
66parameters: we just need remove the existing `mbedtls_ssl_conf_dh_param_xxx()`
67APIs and tell people to use `mbedtls_ssl_conf_groups()` instead. (Can only be
68done in 4.0 or another major version.)
694. Implement RFC 7919, support DHE-RSA and DHE-PSK only in conjunction with it
70 when moving to PSA. Server-side would work as above; unfortunately
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020071client-side the only option is to offer named groups and break the handshake
72if the server didn't take on our offer. This is not fully satisfying, but is
73perhaps the least unsatisfying option in terms of result; it's also probably
74the one that requires the most work, but it would deliver value beyond PSA
Manuel Pégourié-Gonnard83c53882022-04-20 14:27:48 +020075migration by implementing RFC 7919. (Implementing RFC 7919 could be done any
76time; making it mandatory can only be done in 4.0 or another major version.)
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020077
78RSA-PSS parameters
79------------------
80
81RSA-PSS signatures are defined by PKCS#1 v2, re-published as RFC 8017
82(previously RFC 3447).
83
84As standardized, the signature scheme takes several parameters, in addition to
85the hash algorithm potentially used to hash the message being signed:
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +020086- a hash algorithm used for the encoding function
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020087- a mask generation function
88 - most commonly MGF1, which in turn is parametrized by a hash algorithm
89- a salt length
Manuel Pégourié-Gonnardc70013e2022-02-10 13:07:22 +010090- a trailer field - the value is fixed to 0xBC by PKCS#1 v2.1, but was left
Andrzej Kurek5c65c572022-04-13 14:28:52 -040091 configurable in the original scheme; 0xBC is used everywhere in practice.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020092
93Both the existing `mbedtls_` API and the PSA API support only MGF1 as the
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +020094generation function (and only 0xBC as the trailer field), but there are
95discrepancies in handling the salt length and which of the various hash
96algorithms can differ from each other.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +020097
98### API comparison
99
100- RSA:
101 - signature: `mbedtls_rsa_rsassa_pss_sign()`
102 - message hashed externally
103 - encoding hash = MGF1 hash (from context, or argument = message hash)
104 - salt length: always using the maximum legal value
105 - signature: `mbedtls_rsa_rsassa_pss_sign_ext()`
106 - message hashed externally
107 - encoding hash = MGF1 hash (from context, or argument = message hash)
108 - salt length: specified explicitly
109 - verification: `mbedtls_rsassa_pss_verify()`
110 - message hashed externally
111 - encoding hash = MGF1 hash (from context, or argument = message hash)
112 - salt length: any valid length accepted
113 - verification: `mbedtls_rsassa_pss_verify_ext()`
114 - message hashed externally
115 - encoding hash = MGF1 hash from dedicated argument
116 - expected salt length: specified explicitly, can specify "ANY"
117- PK:
118 - signature: not supported
119 - verification: `mbedtls_pk_verify_ext()`
120 - message hashed externally
121 - encoding hash = MGF1 hash, specified explicitly
122 - expected salt length: specified explicitly, can specify "ANY"
123- PSA:
124 - algorithm specification:
125 - hash alg used for message hashing, encoding and MGF1
Manuel Pégourié-Gonnard539b9a52022-02-07 10:19:08 +0100126 - salt length can be either "standard" (<= hashlen, see note) or "any"
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200127 - signature generation:
Manuel Pégourié-Gonnard539b9a52022-02-07 10:19:08 +0100128 - salt length: always <= hashlen (see note) and random salt
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200129 - verification:
Manuel Pégourié-Gonnard539b9a52022-02-07 10:19:08 +0100130 - salt length: either <= hashlen (see note), or any depending on algorithm
131
132Note: above, "<= hashlen" means that hashlen is used if possible, but if it
Manuel Pégourié-Gonnard80759c42022-02-08 10:33:11 +0100133doesn't fit because the key is too short, then the maximum length that fits is
Manuel Pégourié-Gonnard539b9a52022-02-07 10:19:08 +0100134used.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200135
136The RSA/PK API is in principle more flexible than the PSA Crypto API. The
137following sub-sections study whether and how this matters in practice.
138
139### Use in X.509
140
141RFC 4055 Section 3.1 defines the encoding of RSA-PSS that's used in X.509.
142It allows independently specifying the message hash (also used for encoding
143hash), the MGF (and its hash if MGF1 is used), and the salt length (plus an
144extra parameter "trailer field" that doesn't vary in practice"). These can be
145encoded as part of the key, and of the signature. If both encoding are
146presents, all values must match except possibly for the salt length, where the
147value from the signature parameters is used.
148
149In Mbed TLS, RSA-PSS parameters can be parsed and displayed for various
150objects (certificates, CRLs, CSRs). During parsing, the following properties
151are enforced:
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200152- the extra "trailer field" parameter must have its default value
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200153- the mask generation function is MGF1
154- encoding hash = message hashing algorithm (may differ from MGF1 hash)
155
156When it comes to cryptographic operations, only two things are supported:
157- verifying the signature on a certificate from its parent;
158- verifying the signature on a CRL from the issuing CA.
159
160The verification is done using `mbedtls_pk_verify_ext()`.
161
162Note: since X.509 parsing ensures that message hash = encoding hash, and
Manuel Pégourié-Gonnard58d101b2022-02-10 12:58:09 +0100163`mbedtls_pk_verify_ext()` uses encoding hash = mgf1 hash, it looks like all
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200164three hash algorithms must be equal, which would be good news as it would
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200165match a limitation of the PSA API.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200166
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200167It is unclear what parameters people use in practice. It looks like by default
168OpenSSL picks saltlen = keylen - hashlen - 2 (tested with openssl 1.1.1f).
Tom Cosgrove0b86ac12022-07-29 13:44:01 +0100169The `certtool` command provided by GnuTLS seems to be picking saltlen = hashlen
Manuel Pégourié-Gonnard839bb8a2022-02-08 10:33:41 +0100170by default (tested with GnuTLS 3.6.13). FIPS 186-4 requires 0 <= saltlen <=
Manuel Pégourié-Gonnard8e559da2022-02-01 10:26:07 +0100171hashlen.
Manuel Pégourié-Gonnardf5ee4b32021-10-21 13:04:01 +0200172
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200173### Use in TLS
174
175In TLS 1.2 (or lower), RSA-PSS signatures are never used, except via X.509.
176
177In TLS 1.3, RSA-PSS signatures can be used directly in the protocol (in
178addition to indirect use via X.509). It has two sets of three signature
179algorithm identifiers (for SHA-256, SHA-384 and SHA-512), depending of what
180the OID of the public key is (rsaEncryption or RSASSA-PSS).
181
182In both cases, it specifies that:
183- the mask generation function is MGF1
184- all three hashes are equal
185- the length of the salt MUST be equal to the length of the digest algorithm
186
187When signing, the salt length picked by PSA is the one required by TLS 1.3
188(unless the key is unreasonably small).
189
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200190When verifying signatures, PSA will by default enforce the salt len is the one
191required by TLS 1.3.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200192
193### Current testing - X509
194
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200195All test files use the default trailer field of 0xBC, as enforced by our
196parser. (There's a negative test for that using the
197`x509_parse_rsassa_pss_params` test function and hex data.)
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200198
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200199Files with "bad" in the name are expected to be invalid and rejected in tests.
Manuel Pégourié-Gonnardf5ee4b32021-10-21 13:04:01 +0200200
201**Test certificates:**
202
203server9-bad-mgfhash.crt (announcing mgf1(sha224), signed with another mgf)
204 Hash Algorithm: sha256
205 Mask Algorithm: mgf1 with sha224
206 Salt Length: 0xDE
207server9-bad-saltlen.crt (announcing saltlen = 0xDE, signed with another len)
208 Hash Algorithm: sha256
209 Mask Algorithm: mgf1 with sha256
210 Salt Length: 0xDE
211server9-badsign.crt (one bit flipped in the signature)
212 Hash Algorithm: sha1 (default)
213 Mask Algorithm: mgf1 with sha1 (default)
214 Salt Length: 0xEA
215server9-defaults.crt
216 Hash Algorithm: sha1 (default)
217 Mask Algorithm: mgf1 with sha1 (default)
218 Salt Length: 0x14 (default)
219server9-sha224.crt
220 Hash Algorithm: sha224
221 Mask Algorithm: mgf1 with sha224
222 Salt Length: 0xE2
223server9-sha256.crt
224 Hash Algorithm: sha256
225 Mask Algorithm: mgf1 with sha256
226 Salt Length: 0xDE
227server9-sha384.crt
228 Hash Algorithm: sha384
229 Mask Algorithm: mgf1 with sha384
230 Salt Length: 0xCE
231server9-sha512.crt
232 Hash Algorithm: sha512
233 Mask Algorithm: mgf1 with sha512
234 Salt Length: 0xBE
235server9-with-ca.crt
236 Hash Algorithm: sha1 (default)
237 Mask Algorithm: mgf1 with sha1 (default)
238 Salt Length: 0xEA
239server9.crt
240 Hash Algorithm: sha1 (default)
241 Mask Algorithm: mgf1 with sha1 (default)
242 Salt Length: 0xEA
243
244These certificates are signed with a 2048-bit key. It appears that they are
245all using saltlen = keylen - hashlen - 2, except for server9-defaults which is
246using saltlen = hashlen.
247
248**Test CRLs:**
249
250crl-rsa-pss-sha1-badsign.pem
251 Hash Algorithm: sha1 (default)
252 Mask Algorithm: mgf1 with sha1 (default)
253 Salt Length: 0xEA
254crl-rsa-pss-sha1.pem
255 Hash Algorithm: sha1 (default)
256 Mask Algorithm: mgf1 with sha1 (default)
257 Salt Length: 0xEA
258crl-rsa-pss-sha224.pem
259 Hash Algorithm: sha224
260 Mask Algorithm: mgf1 with sha224
261 Salt Length: 0xE2
262crl-rsa-pss-sha256.pem
263 Hash Algorithm: sha256
264 Mask Algorithm: mgf1 with sha256
265 Salt Length: 0xDE
266crl-rsa-pss-sha384.pem
267 Hash Algorithm: sha384
268 Mask Algorithm: mgf1 with sha384
269 Salt Length: 0xCE
270crl-rsa-pss-sha512.pem
271 Hash Algorithm: sha512
272 Mask Algorithm: mgf1 with sha512
273 Salt Length: 0xBE
274
275These CRLs are signed with a 2048-bit key. It appears that they are
276all using saltlen = keylen - hashlen - 2.
277
278**Test CSRs:**
279
280server9.req.sha1
281 Hash Algorithm: sha1 (default)
282 Mask Algorithm: mgf1 with sha1 (default)
283 Salt Length: 0x6A
284server9.req.sha224
285 Hash Algorithm: sha224
286 Mask Algorithm: mgf1 with sha224
287 Salt Length: 0x62
288server9.req.sha256
289 Hash Algorithm: sha256
290 Mask Algorithm: mgf1 with sha256
291 Salt Length: 0x5E
292server9.req.sha384
293 Hash Algorithm: sha384
294 Mask Algorithm: mgf1 with sha384
295 Salt Length: 0x4E
296server9.req.sha512
297 Hash Algorithm: sha512
298 Mask Algorithm: mgf1 with sha512
299 Salt Length: 0x3E
300
Manuel Pégourié-Gonnard83c53882022-04-20 14:27:48 +0200301These CSRs are signed with a 2048-bit key. It appears that they are
Manuel Pégourié-Gonnardf5ee4b32021-10-21 13:04:01 +0200302all using saltlen = keylen - hashlen - 2.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200303
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200304### Possible courses of action
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200305
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200306There's no question about what to do with TLS (any version); the only question
307is about X.509 signature verification. Options include:
308
3091. Doing all verifications with `PSA_ALG_RSA_PSS_ANY_SALT` - while this
310 wouldn't cause a concrete security issue, this would be non-compliant.
3112. Doing verifications with `PSA_ALG_RSA_PSS` when we're lucky and the encoded
312 saltlen happens to match hashlen, and falling back to `ANY_SALT` otherwise.
313Same issue as with the previous point, except more contained.
3143. Reject all certificates with saltlen != hashlen. This includes all
Manuel Pégourié-Gonnard83c53882022-04-20 14:27:48 +0200315 certificates generated with OpenSSL using the default parameters, so it's
Manuel Pégourié-Gonnarde459be22021-10-27 13:25:49 +0200316probably not acceptable.
3174. Request an extension to the PSA Crypto API and use one of the above options
318 in the meantime. Such an extension seems inconvenient and not motivated by
319strong security arguments, so it's unclear whether it would be accepted.
Manuel Pégourié-Gonnardd9edd562021-09-30 15:05:01 +0200320
321Limitations relevant for G2 (isolation of long-term secrets)
322============================================================
323
Manuel Pégourié-Gonnard103b9922022-05-11 13:21:39 +0200324Currently none.