Merge branch 'Mbed-TLS:development' into threadsafe-key-locking
This commit is contained in:
commit
e02b63ac89
156 changed files with 6545 additions and 2274 deletions
|
@ -129,12 +129,30 @@ int psa_can_do_cipher(psa_key_type_t key_type, psa_algorithm_t cipher_alg)
|
|||
defined(PSA_WANT_KEY_TYPE_DH_KEY_PAIR_GENERATE)
|
||||
static int psa_is_dh_key_size_valid(size_t bits)
|
||||
{
|
||||
if (bits != 2048 && bits != 3072 && bits != 4096 &&
|
||||
bits != 6144 && bits != 8192) {
|
||||
return 0;
|
||||
switch (bits) {
|
||||
#if defined(PSA_WANT_DH_RFC7919_2048)
|
||||
case 2048:
|
||||
return 1;
|
||||
#endif /* PSA_WANT_DH_RFC7919_2048 */
|
||||
#if defined(PSA_WANT_DH_RFC7919_3072)
|
||||
case 3072:
|
||||
return 1;
|
||||
#endif /* PSA_WANT_DH_RFC7919_3072 */
|
||||
#if defined(PSA_WANT_DH_RFC7919_4096)
|
||||
case 4096:
|
||||
return 1;
|
||||
#endif /* PSA_WANT_DH_RFC7919_4096 */
|
||||
#if defined(PSA_WANT_DH_RFC7919_6144)
|
||||
case 6144:
|
||||
return 1;
|
||||
#endif /* PSA_WANT_DH_RFC7919_6144 */
|
||||
#if defined(PSA_WANT_DH_RFC7919_8192)
|
||||
case 8192:
|
||||
return 1;
|
||||
#endif /* PSA_WANT_DH_RFC7919_8192 */
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif /* MBEDTLS_PSA_BUILTIN_KEY_TYPE_DH_KEY_PAIR_IMPORT ||
|
||||
MBEDTLS_PSA_BUILTIN_KEY_TYPE_DH_PUBLIC_KEY ||
|
||||
|
@ -577,7 +595,7 @@ psa_status_t psa_import_key_into_slot(
|
|||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_DH_PUBLIC_KEY)
|
||||
if (PSA_KEY_TYPE_IS_DH(type)) {
|
||||
if (psa_is_dh_key_size_valid(PSA_BYTES_TO_BITS(data_length)) == 0) {
|
||||
return PSA_ERROR_INVALID_ARGUMENT;
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
return mbedtls_psa_ffdh_import_key(attributes,
|
||||
data, data_length,
|
||||
|
@ -6096,6 +6114,91 @@ static psa_status_t psa_hash_try_support(psa_algorithm_t alg)
|
|||
return status;
|
||||
}
|
||||
|
||||
static psa_status_t psa_key_derivation_set_maximum_capacity(
|
||||
psa_key_derivation_operation_t *operation,
|
||||
psa_algorithm_t kdf_alg)
|
||||
{
|
||||
#if defined(PSA_WANT_ALG_TLS12_ECJPAKE_TO_PMS)
|
||||
if (kdf_alg == PSA_ALG_TLS12_ECJPAKE_TO_PMS) {
|
||||
operation->capacity = PSA_HASH_LENGTH(PSA_ALG_SHA_256);
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
#if defined(PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128)
|
||||
if (kdf_alg == PSA_ALG_PBKDF2_AES_CMAC_PRF_128) {
|
||||
#if (SIZE_MAX > UINT32_MAX)
|
||||
operation->capacity = UINT32_MAX * (size_t) PSA_MAC_LENGTH(
|
||||
PSA_KEY_TYPE_AES,
|
||||
128U,
|
||||
PSA_ALG_CMAC);
|
||||
#else
|
||||
operation->capacity = SIZE_MAX;
|
||||
#endif
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
#endif /* PSA_WANT_ALG_PBKDF2_AES_CMAC_PRF_128 */
|
||||
|
||||
/* After this point, if kdf_alg is not valid then value of hash_alg may be
|
||||
* invalid or meaningless but it does not affect this function */
|
||||
psa_algorithm_t hash_alg = PSA_ALG_GET_HASH(kdf_alg);
|
||||
size_t hash_size = PSA_HASH_LENGTH(hash_alg);
|
||||
if (hash_size == 0) {
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
/* Make sure that hash_alg is a supported hash algorithm. Otherwise
|
||||
* we might fail later, which is somewhat unfriendly and potentially
|
||||
* risk-prone. */
|
||||
psa_status_t status = psa_hash_try_support(hash_alg);
|
||||
if (status != PSA_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
|
||||
#if defined(PSA_WANT_ALG_HKDF)
|
||||
if (PSA_ALG_IS_HKDF(kdf_alg)) {
|
||||
operation->capacity = 255 * hash_size;
|
||||
} else
|
||||
#endif
|
||||
#if defined(PSA_WANT_ALG_HKDF_EXTRACT)
|
||||
if (PSA_ALG_IS_HKDF_EXTRACT(kdf_alg)) {
|
||||
operation->capacity = hash_size;
|
||||
} else
|
||||
#endif
|
||||
#if defined(PSA_WANT_ALG_HKDF_EXPAND)
|
||||
if (PSA_ALG_IS_HKDF_EXPAND(kdf_alg)) {
|
||||
operation->capacity = 255 * hash_size;
|
||||
} else
|
||||
#endif
|
||||
#if defined(PSA_WANT_ALG_TLS12_PRF)
|
||||
if (PSA_ALG_IS_TLS12_PRF(kdf_alg) &&
|
||||
(hash_alg == PSA_ALG_SHA_256 || hash_alg == PSA_ALG_SHA_384)) {
|
||||
operation->capacity = SIZE_MAX;
|
||||
} else
|
||||
#endif
|
||||
#if defined(PSA_WANT_ALG_TLS12_PSK_TO_MS)
|
||||
if (PSA_ALG_IS_TLS12_PSK_TO_MS(kdf_alg) &&
|
||||
(hash_alg == PSA_ALG_SHA_256 || hash_alg == PSA_ALG_SHA_384)) {
|
||||
/* Master Secret is always 48 bytes
|
||||
* https://datatracker.ietf.org/doc/html/rfc5246.html#section-8.1 */
|
||||
operation->capacity = 48U;
|
||||
} else
|
||||
#endif
|
||||
#if defined(PSA_WANT_ALG_PBKDF2_HMAC)
|
||||
if (PSA_ALG_IS_PBKDF2_HMAC(kdf_alg)) {
|
||||
#if (SIZE_MAX > UINT32_MAX)
|
||||
operation->capacity = UINT32_MAX * hash_size;
|
||||
#else
|
||||
operation->capacity = SIZE_MAX;
|
||||
#endif
|
||||
} else
|
||||
#endif /* PSA_WANT_ALG_PBKDF2_HMAC */
|
||||
{
|
||||
(void) hash_size;
|
||||
status = PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
static psa_status_t psa_key_derivation_setup_kdf(
|
||||
psa_key_derivation_operation_t *operation,
|
||||
psa_algorithm_t kdf_alg)
|
||||
|
@ -6109,43 +6212,9 @@ static psa_status_t psa_key_derivation_setup_kdf(
|
|||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
/* All currently supported key derivation algorithms (apart from
|
||||
* ecjpake to pms and pbkdf2_aes_cmac_128) are based on a hash algorithm. */
|
||||
psa_algorithm_t hash_alg = PSA_ALG_HKDF_GET_HASH(kdf_alg);
|
||||
size_t hash_size = PSA_HASH_LENGTH(hash_alg);
|
||||
if (kdf_alg == PSA_ALG_TLS12_ECJPAKE_TO_PMS) {
|
||||
hash_size = PSA_HASH_LENGTH(PSA_ALG_SHA_256);
|
||||
} else if (kdf_alg == PSA_ALG_PBKDF2_AES_CMAC_PRF_128) {
|
||||
hash_size = PSA_MAC_LENGTH(PSA_KEY_TYPE_AES, 128U, PSA_ALG_CMAC);
|
||||
} else {
|
||||
if (hash_size == 0) {
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
/* Make sure that hash_alg is a supported hash algorithm. Otherwise
|
||||
* we might fail later, which is somewhat unfriendly and potentially
|
||||
* risk-prone. */
|
||||
psa_status_t status = psa_hash_try_support(hash_alg);
|
||||
if (status != PSA_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
if ((PSA_ALG_IS_TLS12_PRF(kdf_alg) ||
|
||||
PSA_ALG_IS_TLS12_PSK_TO_MS(kdf_alg)) &&
|
||||
!(hash_alg == PSA_ALG_SHA_256 || hash_alg == PSA_ALG_SHA_384)) {
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
#if defined(MBEDTLS_PSA_BUILTIN_ALG_HKDF_EXTRACT) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_TLS12_ECJPAKE_TO_PMS)
|
||||
if (PSA_ALG_IS_HKDF_EXTRACT(kdf_alg) ||
|
||||
(kdf_alg == PSA_ALG_TLS12_ECJPAKE_TO_PMS)) {
|
||||
operation->capacity = hash_size;
|
||||
} else
|
||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_HKDF_EXTRACT ||
|
||||
MBEDTLS_PSA_BUILTIN_ALG_TLS12_ECJPAKE_TO_PMS */
|
||||
operation->capacity = 255 * hash_size;
|
||||
return PSA_SUCCESS;
|
||||
psa_status_t status = psa_key_derivation_set_maximum_capacity(operation,
|
||||
kdf_alg);
|
||||
return status;
|
||||
}
|
||||
|
||||
static psa_status_t psa_key_agreement_try_support(psa_algorithm_t alg)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue