pk: improve mbedtls_pk_copy_from_psa()

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
Valerio Setti 2024-03-11 10:09:32 +01:00
parent 6f5f9f5ce8
commit e095a67bb2
2 changed files with 3 additions and 4 deletions

View File

@ -1402,7 +1402,7 @@ int mbedtls_pk_copy_from_psa(mbedtls_svc_key_id_t key_id, mbedtls_pk_context *pk
status = psa_export_key(key_id, exp_key, sizeof(exp_key), &exp_key_len);
if (status != PSA_SUCCESS) {
ret = MBEDTLS_ERR_PK_BAD_INPUT_DATA;
ret = PSA_PK_TO_MBEDTLS_ERR(status);
goto exit;
}
@ -1429,8 +1429,7 @@ int mbedtls_pk_copy_from_psa(mbedtls_svc_key_id_t key_id, mbedtls_pk_context *pk
}
mbedtls_md_type_t md_type = MBEDTLS_MD_NONE;
if ((PSA_ALG_GET_HASH(alg_type) != PSA_ALG_NONE) &&
(PSA_ALG_GET_HASH(alg_type) != PSA_ALG_ANY_HASH)) {
if (PSA_ALG_GET_HASH(alg_type) != PSA_ALG_ANY_HASH) {
md_type = mbedtls_md_type_from_psa_alg(alg_type);
}

View File

@ -2340,7 +2340,7 @@ void pk_copy_from_psa_fail(void)
/* Generate an EC key which cannot be exported. */
PSA_ASSERT(pk_psa_genkey_generic(PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1), 256,
0, PSA_ALG_NONE, &key_id));
TEST_EQUAL(mbedtls_pk_copy_from_psa(key_id, &pk_ctx), MBEDTLS_ERR_PK_BAD_INPUT_DATA);
TEST_EQUAL(mbedtls_pk_copy_from_psa(key_id, &pk_ctx), MBEDTLS_ERR_PK_TYPE_MISMATCH);
psa_destroy_key(key_id);
#endif /* MBEDTLS_PK_HAVE_ECC_KEYS && PSA_WANT_ECC_SECP_R1_256 &&
PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE */