1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

Use one maximum key_len for all exported keys

Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
This commit is contained in:
Max Fillinger
2024-11-01 16:05:34 +01:00
parent a9a9e99a6b
commit c6fd1a24d2
3 changed files with 23 additions and 16 deletions

View File

@ -9000,16 +9000,13 @@ static int mbedtls_ssl_tls13_export_keying_material(mbedtls_ssl_context *ssl,
const size_t hash_len = PSA_HASH_LENGTH(hash_alg);
const unsigned char *secret = ssl->session->app_secrets.exporter_master_secret;
/* Validate the length of the label and the desired key length. The key
* length can be at most 255 * hash_len by definition of HKDF-Expand in
* RFC 5869.
/* The length of the label must be at most 250 bytes to fit into the HkdfLabel
* struct as defined in RFC 8446, Section 7.1.
*
* The length of the label must be at most 250 bytes long to fit into the
* HkdfLabel struct as defined in RFC 8446, Section 7.1. This struct also
* requires that key_len fits into a uint16, but until we have to deal with
* a hash function with more than 2048 bits of output, the 255 * hash_len
* limit will guarantee that. */
if (key_len > 255 * hash_len || label_len > 250) {
* The length of the context is unlimited even though the context field in the
* struct can only hold up to 256 bytes. This is because we place a *hash* of
* the context in the field. */
if (label_len > 250) {
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
}
@ -9029,6 +9026,10 @@ int mbedtls_ssl_export_keying_material(mbedtls_ssl_context *ssl,
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
}
if (key_len > MBEDTLS_SSL_EXPORT_MAX_KEY_LEN) {
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
}
int ciphersuite_id = mbedtls_ssl_get_ciphersuite_id_from_ssl(ssl);
const mbedtls_ssl_ciphersuite_t *ciphersuite = mbedtls_ssl_ciphersuite_from_id(ciphersuite_id);
const mbedtls_md_type_t hash_alg = ciphersuite->mac;