Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 1 | This document lists current limitations of the PSA Crypto API (as of version |
| 2 | 1.1) that may impact our ability to (1) use it for all crypto operations in |
| 3 | TLS and X.509 and (2) support isolation of all long-term secrets in TLS (that |
Manuel Pégourié-Gonnard | 8e559da | 2022-02-01 10:26:07 +0100 | [diff] [blame] | 4 | is, goals G1 and G2 in [strategy.md](strategy.md) in the same directory). |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 5 | |
| 6 | This is supposed to be a complete list, based on a exhaustive review of crypto |
| 7 | operations done in TLS and X.509 code, but of course it's still possible that |
| 8 | subtle-but-important issues have been missed. The only way to be really sure |
| 9 | is, of course, to actually do the migration work. |
| 10 | |
| 11 | Limitations relevant for G1 (performing crypto operations) |
| 12 | ========================================================== |
| 13 | |
| 14 | Restartable ECC operations |
| 15 | -------------------------- |
| 16 | |
| 17 | There is currently no support for that in PSA at all. API design, as well as |
| 18 | implementation, would be non-trivial. |
| 19 | |
| 20 | Currently, `MBEDTLS_USE_PSA_CRYPTO` is simply incompatible with |
| 21 | `MBEDTLS_ECP_RESTARTABLE`. |
| 22 | |
Manuel Pégourié-Gonnard | 8e559da | 2022-02-01 10:26:07 +0100 | [diff] [blame] | 23 | Things that are in the API but not implemented yet |
| 24 | -------------------------------------------------- |
| 25 | |
| 26 | PSA 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 |
| 28 | github. |
| 29 | |
Dave Rodgman | 017a199 | 2022-03-31 14:07:01 +0100 | [diff] [blame] | 30 | [ffdh]: https://github.com/Mbed-TLS/mbedtls/issues/3261 |
Manuel Pégourié-Gonnard | 8e559da | 2022-02-01 10:26:07 +0100 | [diff] [blame] | 31 | |
| 32 | PSA Crypto has an experimental API for EC J-PAKE, but it's not implemented in |
| 33 | Mbed TLS yet. See the [EC J-PAKE follow-up EPIC][ecjp] on github. |
| 34 | |
Dave Rodgman | 017a199 | 2022-03-31 14:07:01 +0100 | [diff] [blame] | 35 | [ecjp]: https://github.com/orgs/Mbed-TLS/projects/1#column-17950140 |
Manuel Pégourié-Gonnard | 8e559da | 2022-02-01 10:26:07 +0100 | [diff] [blame] | 36 | |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 37 | Arbitrary parameters for FFDH |
| 38 | ----------------------------- |
| 39 | |
Manuel Pégourié-Gonnard | 8e559da | 2022-02-01 10:26:07 +0100 | [diff] [blame] | 40 | (See also the first paragraph in the previous section.) |
| 41 | |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 42 | Currently, the PSA Crypto API can only perform FFDH with a limited set of |
Manuel Pégourié-Gonnard | 58d101b | 2022-02-10 12:58:09 +0100 | [diff] [blame] | 43 | well-known parameters (some of them defined in the spec, but implementations |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 44 | are free to extend that set). |
| 45 | |
| 46 | TLS 1.2 (and earlier) on the other hand have the server send explicit |
Manuel Pégourié-Gonnard | 58d101b | 2022-02-10 12:58:09 +0100 | [diff] [blame] | 47 | parameters (P and G) in its ServerKeyExchange message. This has been found to |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 48 | be suboptimal for security, as it is prohibitively hard for the client to |
| 49 | verify the strength of these parameters. This led to the development of RFC |
| 50 | 7919 which allows use of named groups in TLS 1.2 - however as this is only an |
| 51 | extension, servers can still send custom parameters if they don't support the |
| 52 | extension. |
| 53 | |
| 54 | In TLS 1.3 the situation will be simpler: named groups are the only |
| 55 | option, so the current PSA Crypto API is a good match for that. (Not |
Manuel Pégourié-Gonnard | c7f3254 | 2022-02-10 13:00:33 +0100 | [diff] [blame] | 56 | coincidentally, all the groups used by RFC 7919 and TLS 1.3 are included |
| 57 | in the PSA specification.) |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 58 | |
| 59 | There are several options here: |
| 60 | |
| 61 | 1. Implement support for custom FFDH parameters in PSA Crypto: this would pose |
| 62 | non-trivial API design problem, but most importantly seems backwards, as |
| 63 | the crypto community is moving away from custom FFDH parameters. |
| 64 | 2. Drop the DHE-RSA and DHE-PSK key exchanges in TLS 1.2 when moving to PSA. |
| 65 | 3. Implement RFC 7919, support DHE-RSA and DHE-PSK only in conjunction with it |
| 66 | when moving to PSA. We can modify our server so that it only selects a DHE |
| 67 | ciphersuite if the client offered name FFDH groups; unfortunately |
| 68 | client-side the only option is to offer named groups and break the handshake |
| 69 | if the server didn't take on our offer. This is not fully satisfying, but is |
| 70 | perhaps the least unsatisfying option in terms of result; it's also probably |
| 71 | the one that requires the most work, but it would deliver value beyond PSA |
| 72 | migration by implementing RFC 7919. |
| 73 | |
| 74 | RSA-PSS parameters |
| 75 | ------------------ |
| 76 | |
| 77 | RSA-PSS signatures are defined by PKCS#1 v2, re-published as RFC 8017 |
| 78 | (previously RFC 3447). |
| 79 | |
| 80 | As standardized, the signature scheme takes several parameters, in addition to |
| 81 | the hash algorithm potentially used to hash the message being signed: |
Manuel Pégourié-Gonnard | e459be2 | 2021-10-27 13:25:49 +0200 | [diff] [blame] | 82 | - a hash algorithm used for the encoding function |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 83 | - a mask generation function |
| 84 | - most commonly MGF1, which in turn is parametrized by a hash algorithm |
| 85 | - a salt length |
Manuel Pégourié-Gonnard | c70013e | 2022-02-10 13:07:22 +0100 | [diff] [blame] | 86 | - a trailer field - the value is fixed to 0xBC by PKCS#1 v2.1, but was left |
Andrzej Kurek | 5c65c57 | 2022-04-13 14:28:52 -0400 | [diff] [blame^] | 87 | configurable in the original scheme; 0xBC is used everywhere in practice. |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 88 | |
| 89 | Both the existing `mbedtls_` API and the PSA API support only MGF1 as the |
Manuel Pégourié-Gonnard | e459be2 | 2021-10-27 13:25:49 +0200 | [diff] [blame] | 90 | generation function (and only 0xBC as the trailer field), but there are |
| 91 | discrepancies in handling the salt length and which of the various hash |
| 92 | algorithms can differ from each other. |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 93 | |
| 94 | ### API comparison |
| 95 | |
| 96 | - RSA: |
| 97 | - signature: `mbedtls_rsa_rsassa_pss_sign()` |
| 98 | - message hashed externally |
| 99 | - encoding hash = MGF1 hash (from context, or argument = message hash) |
| 100 | - salt length: always using the maximum legal value |
| 101 | - signature: `mbedtls_rsa_rsassa_pss_sign_ext()` |
| 102 | - message hashed externally |
| 103 | - encoding hash = MGF1 hash (from context, or argument = message hash) |
| 104 | - salt length: specified explicitly |
| 105 | - verification: `mbedtls_rsassa_pss_verify()` |
| 106 | - message hashed externally |
| 107 | - encoding hash = MGF1 hash (from context, or argument = message hash) |
| 108 | - salt length: any valid length accepted |
| 109 | - verification: `mbedtls_rsassa_pss_verify_ext()` |
| 110 | - message hashed externally |
| 111 | - encoding hash = MGF1 hash from dedicated argument |
| 112 | - expected salt length: specified explicitly, can specify "ANY" |
| 113 | - PK: |
| 114 | - signature: not supported |
| 115 | - verification: `mbedtls_pk_verify_ext()` |
| 116 | - message hashed externally |
| 117 | - encoding hash = MGF1 hash, specified explicitly |
| 118 | - expected salt length: specified explicitly, can specify "ANY" |
| 119 | - PSA: |
| 120 | - algorithm specification: |
| 121 | - hash alg used for message hashing, encoding and MGF1 |
Manuel Pégourié-Gonnard | 539b9a5 | 2022-02-07 10:19:08 +0100 | [diff] [blame] | 122 | - salt length can be either "standard" (<= hashlen, see note) or "any" |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 123 | - signature generation: |
Manuel Pégourié-Gonnard | 539b9a5 | 2022-02-07 10:19:08 +0100 | [diff] [blame] | 124 | - salt length: always <= hashlen (see note) and random salt |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 125 | - verification: |
Manuel Pégourié-Gonnard | 539b9a5 | 2022-02-07 10:19:08 +0100 | [diff] [blame] | 126 | - salt length: either <= hashlen (see note), or any depending on algorithm |
| 127 | |
| 128 | Note: above, "<= hashlen" means that hashlen is used if possible, but if it |
Manuel Pégourié-Gonnard | 80759c4 | 2022-02-08 10:33:11 +0100 | [diff] [blame] | 129 | doesn't fit because the key is too short, then the maximum length that fits is |
Manuel Pégourié-Gonnard | 539b9a5 | 2022-02-07 10:19:08 +0100 | [diff] [blame] | 130 | used. |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 131 | |
| 132 | The RSA/PK API is in principle more flexible than the PSA Crypto API. The |
| 133 | following sub-sections study whether and how this matters in practice. |
| 134 | |
| 135 | ### Use in X.509 |
| 136 | |
| 137 | RFC 4055 Section 3.1 defines the encoding of RSA-PSS that's used in X.509. |
| 138 | It allows independently specifying the message hash (also used for encoding |
| 139 | hash), the MGF (and its hash if MGF1 is used), and the salt length (plus an |
| 140 | extra parameter "trailer field" that doesn't vary in practice"). These can be |
| 141 | encoded as part of the key, and of the signature. If both encoding are |
| 142 | presents, all values must match except possibly for the salt length, where the |
| 143 | value from the signature parameters is used. |
| 144 | |
| 145 | In Mbed TLS, RSA-PSS parameters can be parsed and displayed for various |
| 146 | objects (certificates, CRLs, CSRs). During parsing, the following properties |
| 147 | are enforced: |
Manuel Pégourié-Gonnard | e459be2 | 2021-10-27 13:25:49 +0200 | [diff] [blame] | 148 | - the extra "trailer field" parameter must have its default value |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 149 | - the mask generation function is MGF1 |
| 150 | - encoding hash = message hashing algorithm (may differ from MGF1 hash) |
| 151 | |
| 152 | When it comes to cryptographic operations, only two things are supported: |
| 153 | - verifying the signature on a certificate from its parent; |
| 154 | - verifying the signature on a CRL from the issuing CA. |
| 155 | |
| 156 | The verification is done using `mbedtls_pk_verify_ext()`. |
| 157 | |
| 158 | Note: since X.509 parsing ensures that message hash = encoding hash, and |
Manuel Pégourié-Gonnard | 58d101b | 2022-02-10 12:58:09 +0100 | [diff] [blame] | 159 | `mbedtls_pk_verify_ext()` uses encoding hash = mgf1 hash, it looks like all |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 160 | three hash algorithms must be equal, which would be good news as it would |
Manuel Pégourié-Gonnard | e459be2 | 2021-10-27 13:25:49 +0200 | [diff] [blame] | 161 | match a limitation of the PSA API. |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 162 | |
Manuel Pégourié-Gonnard | e459be2 | 2021-10-27 13:25:49 +0200 | [diff] [blame] | 163 | It is unclear what parameters people use in practice. It looks like by default |
| 164 | OpenSSL picks saltlen = keylen - hashlen - 2 (tested with openssl 1.1.1f). |
| 165 | The `certool` command provided by GnuTLS seems to be picking saltlen = hashlen |
Manuel Pégourié-Gonnard | 839bb8a | 2022-02-08 10:33:41 +0100 | [diff] [blame] | 166 | by default (tested with GnuTLS 3.6.13). FIPS 186-4 requires 0 <= saltlen <= |
Manuel Pégourié-Gonnard | 8e559da | 2022-02-01 10:26:07 +0100 | [diff] [blame] | 167 | hashlen. |
Manuel Pégourié-Gonnard | f5ee4b3 | 2021-10-21 13:04:01 +0200 | [diff] [blame] | 168 | |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 169 | ### Use in TLS |
| 170 | |
| 171 | In TLS 1.2 (or lower), RSA-PSS signatures are never used, except via X.509. |
| 172 | |
| 173 | In TLS 1.3, RSA-PSS signatures can be used directly in the protocol (in |
| 174 | addition to indirect use via X.509). It has two sets of three signature |
| 175 | algorithm identifiers (for SHA-256, SHA-384 and SHA-512), depending of what |
| 176 | the OID of the public key is (rsaEncryption or RSASSA-PSS). |
| 177 | |
| 178 | In both cases, it specifies that: |
| 179 | - the mask generation function is MGF1 |
| 180 | - all three hashes are equal |
| 181 | - the length of the salt MUST be equal to the length of the digest algorithm |
| 182 | |
| 183 | When signing, the salt length picked by PSA is the one required by TLS 1.3 |
| 184 | (unless the key is unreasonably small). |
| 185 | |
Manuel Pégourié-Gonnard | e459be2 | 2021-10-27 13:25:49 +0200 | [diff] [blame] | 186 | When verifying signatures, PSA will by default enforce the salt len is the one |
| 187 | required by TLS 1.3. |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 188 | |
| 189 | ### Current testing - X509 |
| 190 | |
Manuel Pégourié-Gonnard | e459be2 | 2021-10-27 13:25:49 +0200 | [diff] [blame] | 191 | All test files use the default trailer field of 0xBC, as enforced by our |
| 192 | parser. (There's a negative test for that using the |
| 193 | `x509_parse_rsassa_pss_params` test function and hex data.) |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 194 | |
Manuel Pégourié-Gonnard | e459be2 | 2021-10-27 13:25:49 +0200 | [diff] [blame] | 195 | Files with "bad" in the name are expected to be invalid and rejected in tests. |
Manuel Pégourié-Gonnard | f5ee4b3 | 2021-10-21 13:04:01 +0200 | [diff] [blame] | 196 | |
| 197 | **Test certificates:** |
| 198 | |
| 199 | server9-bad-mgfhash.crt (announcing mgf1(sha224), signed with another mgf) |
| 200 | Hash Algorithm: sha256 |
| 201 | Mask Algorithm: mgf1 with sha224 |
| 202 | Salt Length: 0xDE |
| 203 | server9-bad-saltlen.crt (announcing saltlen = 0xDE, signed with another len) |
| 204 | Hash Algorithm: sha256 |
| 205 | Mask Algorithm: mgf1 with sha256 |
| 206 | Salt Length: 0xDE |
| 207 | server9-badsign.crt (one bit flipped in the signature) |
| 208 | Hash Algorithm: sha1 (default) |
| 209 | Mask Algorithm: mgf1 with sha1 (default) |
| 210 | Salt Length: 0xEA |
| 211 | server9-defaults.crt |
| 212 | Hash Algorithm: sha1 (default) |
| 213 | Mask Algorithm: mgf1 with sha1 (default) |
| 214 | Salt Length: 0x14 (default) |
| 215 | server9-sha224.crt |
| 216 | Hash Algorithm: sha224 |
| 217 | Mask Algorithm: mgf1 with sha224 |
| 218 | Salt Length: 0xE2 |
| 219 | server9-sha256.crt |
| 220 | Hash Algorithm: sha256 |
| 221 | Mask Algorithm: mgf1 with sha256 |
| 222 | Salt Length: 0xDE |
| 223 | server9-sha384.crt |
| 224 | Hash Algorithm: sha384 |
| 225 | Mask Algorithm: mgf1 with sha384 |
| 226 | Salt Length: 0xCE |
| 227 | server9-sha512.crt |
| 228 | Hash Algorithm: sha512 |
| 229 | Mask Algorithm: mgf1 with sha512 |
| 230 | Salt Length: 0xBE |
| 231 | server9-with-ca.crt |
| 232 | Hash Algorithm: sha1 (default) |
| 233 | Mask Algorithm: mgf1 with sha1 (default) |
| 234 | Salt Length: 0xEA |
| 235 | server9.crt |
| 236 | Hash Algorithm: sha1 (default) |
| 237 | Mask Algorithm: mgf1 with sha1 (default) |
| 238 | Salt Length: 0xEA |
| 239 | |
| 240 | These certificates are signed with a 2048-bit key. It appears that they are |
| 241 | all using saltlen = keylen - hashlen - 2, except for server9-defaults which is |
| 242 | using saltlen = hashlen. |
| 243 | |
| 244 | **Test CRLs:** |
| 245 | |
| 246 | crl-rsa-pss-sha1-badsign.pem |
| 247 | Hash Algorithm: sha1 (default) |
| 248 | Mask Algorithm: mgf1 with sha1 (default) |
| 249 | Salt Length: 0xEA |
| 250 | crl-rsa-pss-sha1.pem |
| 251 | Hash Algorithm: sha1 (default) |
| 252 | Mask Algorithm: mgf1 with sha1 (default) |
| 253 | Salt Length: 0xEA |
| 254 | crl-rsa-pss-sha224.pem |
| 255 | Hash Algorithm: sha224 |
| 256 | Mask Algorithm: mgf1 with sha224 |
| 257 | Salt Length: 0xE2 |
| 258 | crl-rsa-pss-sha256.pem |
| 259 | Hash Algorithm: sha256 |
| 260 | Mask Algorithm: mgf1 with sha256 |
| 261 | Salt Length: 0xDE |
| 262 | crl-rsa-pss-sha384.pem |
| 263 | Hash Algorithm: sha384 |
| 264 | Mask Algorithm: mgf1 with sha384 |
| 265 | Salt Length: 0xCE |
| 266 | crl-rsa-pss-sha512.pem |
| 267 | Hash Algorithm: sha512 |
| 268 | Mask Algorithm: mgf1 with sha512 |
| 269 | Salt Length: 0xBE |
| 270 | |
| 271 | These CRLs are signed with a 2048-bit key. It appears that they are |
| 272 | all using saltlen = keylen - hashlen - 2. |
| 273 | |
| 274 | **Test CSRs:** |
| 275 | |
| 276 | server9.req.sha1 |
| 277 | Hash Algorithm: sha1 (default) |
| 278 | Mask Algorithm: mgf1 with sha1 (default) |
| 279 | Salt Length: 0x6A |
| 280 | server9.req.sha224 |
| 281 | Hash Algorithm: sha224 |
| 282 | Mask Algorithm: mgf1 with sha224 |
| 283 | Salt Length: 0x62 |
| 284 | server9.req.sha256 |
| 285 | Hash Algorithm: sha256 |
| 286 | Mask Algorithm: mgf1 with sha256 |
| 287 | Salt Length: 0x5E |
| 288 | server9.req.sha384 |
| 289 | Hash Algorithm: sha384 |
| 290 | Mask Algorithm: mgf1 with sha384 |
| 291 | Salt Length: 0x4E |
| 292 | server9.req.sha512 |
| 293 | Hash Algorithm: sha512 |
| 294 | Mask Algorithm: mgf1 with sha512 |
| 295 | Salt Length: 0x3E |
| 296 | |
| 297 | These CSRss are signed with a 2048-bit key. It appears that they are |
| 298 | all using saltlen = keylen - hashlen - 2. |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 299 | |
Manuel Pégourié-Gonnard | e459be2 | 2021-10-27 13:25:49 +0200 | [diff] [blame] | 300 | ### Possible courses of action |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 301 | |
Manuel Pégourié-Gonnard | e459be2 | 2021-10-27 13:25:49 +0200 | [diff] [blame] | 302 | There's no question about what to do with TLS (any version); the only question |
| 303 | is about X.509 signature verification. Options include: |
| 304 | |
| 305 | 1. Doing all verifications with `PSA_ALG_RSA_PSS_ANY_SALT` - while this |
| 306 | wouldn't cause a concrete security issue, this would be non-compliant. |
| 307 | 2. Doing verifications with `PSA_ALG_RSA_PSS` when we're lucky and the encoded |
| 308 | saltlen happens to match hashlen, and falling back to `ANY_SALT` otherwise. |
| 309 | Same issue as with the previous point, except more contained. |
| 310 | 3. Reject all certificates with saltlen != hashlen. This includes all |
| 311 | certificates generate with OpenSSL using the default parameters, so it's |
| 312 | probably not acceptable. |
| 313 | 4. Request an extension to the PSA Crypto API and use one of the above options |
| 314 | in the meantime. Such an extension seems inconvenient and not motivated by |
| 315 | strong security arguments, so it's unclear whether it would be accepted. |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 316 | |
Manuel Pégourié-Gonnard | 5218774 | 2022-01-17 11:02:31 +0100 | [diff] [blame] | 317 | HKDF: Expand not exposed on its own (TLS 1.3) |
| 318 | --------------------------------------------- |
| 319 | |
Andrzej Kurek | 5c65c57 | 2022-04-13 14:28:52 -0400 | [diff] [blame^] | 320 | The HKDF function uses and Extract-then-Expand approach, that is: |
Manuel Pégourié-Gonnard | 5218774 | 2022-01-17 11:02:31 +0100 | [diff] [blame] | 321 | |
| 322 | HKDF(x, ...) = HKDF-Expand(HKDF-Extract(x, ...), ...) |
| 323 | |
| 324 | Only the full HKDF function is safe in general, however there are cases when |
| 325 | one case safely use the individual Extract and Expand; the TLS 1.3 key |
| 326 | schedule does so. Specifically, looking at the [hierarchy of secrets][13hs] |
| 327 | is seems that Expand and Extract are always chained, so that this hierarchy |
| 328 | can be implemented using only the full HKDF. However, looking at the |
| 329 | derivation of traffic keys (7.3) and the update mechanism (7.2) it appears |
| 330 | that calls to HKDF-Expand are iterated without any intermediated call to |
| 331 | HKDF-Extract : that is, the traffic keys are computed as |
| 332 | |
| 333 | HKDF-Expand(HKDF-Expand(HKDF-Extract(...))) |
| 334 | |
| 335 | (with possibly more than two Expands in a row with update). |
| 336 | |
| 337 | [13hs]: https://datatracker.ietf.org/doc/html/rfc8446#page-93 |
| 338 | |
| 339 | In the short term (early 2022), we'll work around that by re-implementing HKDF |
| 340 | in `ssl_tls13_keys.c` based on the `psa_mac_` APIs (for HMAC). |
| 341 | |
Manuel Pégourié-Gonnard | 8e559da | 2022-02-01 10:26:07 +0100 | [diff] [blame] | 342 | In the long term, it is desirable to extend the PSA API. See |
| 343 | https://github.com/ARM-software/psa-crypto-api/issues/539 |
Manuel Pégourié-Gonnard | 5218774 | 2022-01-17 11:02:31 +0100 | [diff] [blame] | 344 | |
Manuel Pégourié-Gonnard | d9edd56 | 2021-09-30 15:05:01 +0200 | [diff] [blame] | 345 | Limitations relevant for G2 (isolation of long-term secrets) |
| 346 | ============================================================ |
| 347 | |
| 348 | Custom key derivations for mixed-PSK handshake |
| 349 | ---------------------------------------------- |
| 350 | |
| 351 | Currently, `MBEDTLS_USE_PSA_CRYPTO` enables the new configuration function |
| 352 | `mbedtls_ssl_conf_psk_opaque()` which allows a PSA-held key to be used for the |
| 353 | (pure) `PSK` key exchange in TLS 1.2. This requires that the derivation of the |
| 354 | Master Secret (MS) be done on the PSA side. To support this, an algorithm |
| 355 | family `PSA_ALG_TLS12_PSK_TO_MS(hash_alg)` was added to PSA Crypto. |
| 356 | |
| 357 | If we want to support key isolation for the "mixed PSK" key exchanges: |
| 358 | DHE-PSK, RSA-PSK, ECDHE-PSK, where the PSK is concatenated with the result of |
| 359 | a DH key agreement (resp. RSA decryption) to form the pre-master secret (PMS) |
| 360 | from which the MS is derived. If the value of the PSK is to remain hidden, we |
| 361 | need the derivation PSK + secondary secret -> MS to be implemented as an |
| 362 | ad-hoc PSA key derivation algorithm. |
| 363 | |
| 364 | Adding this new, TLS-specific, key derivation algorithm to PSA Crypto should |
| 365 | be no harder than it was to add `PSA_ALG_TLS12_PSK_TO_MS()` but still requires |
| 366 | an extension to PSA Crypto. |
| 367 | |
| 368 | Note: looking at RFCs 4279 and 5489, it appears that the structure of the PMS |
| 369 | is always the same: 2-byte length of the secondary secret, secondary secret, |
| 370 | 2-byte length of the PSK, PSK. So, a single key derivation algorithm should be |
| 371 | able to cover the 3 key exchanges DHE-PSK, RSA-PSK and ECDHE-PSK. (That's a |
| 372 | minor gain: adding 3 algorithms would not be a blocker anyway.) |
| 373 | |
| 374 | Note: if later we want to also isolate short-term secret (G3), the "secondary |
| 375 | secret" (output of DHE/ECDHE key agreement or RSA decryption) could be a |
| 376 | candidate. This wouldn't be a problem as the PSA key derivation API always |
| 377 | allows inputs from key slots. (Tangent: the hard part in isolating the result |
| 378 | of RSA decryption would be still checking that is has the correct format: |
| 379 | 48 bytes, the first two matching the TLS version - note that this is timing |
| 380 | sensitive.) |
| 381 | |
Manuel Pégourié-Gonnard | 5218774 | 2022-01-17 11:02:31 +0100 | [diff] [blame] | 382 | HKDF: Expand not exposed on its own (TLS 1.3) |
| 383 | --------------------------------------------- |
| 384 | |
Manuel Pégourié-Gonnard | 8ebed21 | 2022-02-07 10:23:49 +0100 | [diff] [blame] | 385 | See the section with the same name in the G1 part above for background. |
Manuel Pégourié-Gonnard | 5218774 | 2022-01-17 11:02:31 +0100 | [diff] [blame] | 386 | |
| 387 | The work-around mentioned there works well enough just for acceleration, but |
| 388 | is not sufficient for key isolation or generally proper key management (it |
| 389 | requires marking keys are usable for HMAC while they should only be used for |
| 390 | key derivation). |
| 391 | |
| 392 | The obvious long-term solution is to make HKDF-Expand available as a new KDF |
| 393 | (in addition to the full HKDF) in PSA (with appropriate warnings in the |
| 394 | documentation). |