pk: fix return codes' precedence and code style

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
Valerio Setti 2023-04-07 08:59:24 +02:00
parent 9d65f0ef12
commit 1df94f841b
2 changed files with 21 additions and 22 deletions

View file

@ -1107,7 +1107,7 @@ cleanup:
static int eckey_check_pair_psa(const mbedtls_ecp_keypair *pub,
const mbedtls_ecp_keypair *prv)
{
psa_status_t status;
psa_status_t status, destruction_status;
psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_ecp_keypair *prv_ctx = (mbedtls_ecp_keypair *) prv;
mbedtls_ecp_keypair *pub_ctx = (mbedtls_ecp_keypair *) pub;
@ -1134,20 +1134,21 @@ static int eckey_check_pair_psa(const mbedtls_ecp_keypair *pub,
}
status = psa_import_key(&key_attr, prv_key_buf, curve_bytes, &key_id);
if (status != PSA_SUCCESS) {
ret = PSA_PK_TO_MBEDTLS_ERR(status);
ret = PSA_PK_TO_MBEDTLS_ERR(status);
if (ret != 0) {
return ret;
}
mbedtls_platform_zeroize(prv_key_buf, sizeof(prv_key_buf));
ret = PSA_PK_TO_MBEDTLS_ERR(psa_export_public_key(key_id,
prv_key_buf,
sizeof(prv_key_buf),
&prv_key_len));
status = psa_destroy_key(key_id);
if (ret != 0 || status != PSA_SUCCESS) {
return (ret != 0) ? ret : PSA_PK_TO_MBEDTLS_ERR(status);
status = psa_export_public_key(key_id, prv_key_buf, sizeof(prv_key_buf),
&prv_key_len);
ret = PSA_PK_TO_MBEDTLS_ERR(status);
destruction_status = psa_destroy_key(key_id);
if (ret != 0) {
return ret;
} else if (destruction_status != PSA_SUCCESS) {
return PSA_PK_TO_MBEDTLS_ERR(destruction_status);
}
ret = mbedtls_ecp_point_write_binary(&pub_ctx->grp, &pub_ctx->Q,

View file

@ -885,7 +885,7 @@ cleanup:
static int pk_derive_public_key(mbedtls_ecp_group *grp, mbedtls_ecp_point *Q,
const mbedtls_mpi *d)
{
psa_status_t status;
psa_status_t status, destruction_status;
psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT;
size_t curve_bits;
psa_ecc_family_t curve = mbedtls_ecc_group_to_psa(grp->id, &curve_bits);
@ -906,26 +906,24 @@ static int pk_derive_public_key(mbedtls_ecp_group *grp, mbedtls_ecp_point *Q,
}
status = psa_import_key(&key_attr, key_buf, key_len, &key_id);
if (status != PSA_SUCCESS) {
ret = psa_pk_status_to_mbedtls(status);
ret = psa_pk_status_to_mbedtls(status);
if (ret != 0) {
return ret;
}
mbedtls_platform_zeroize(key_buf, sizeof(key_buf));
status = psa_export_public_key(key_id, key_buf, sizeof(key_buf), &key_len);
if (status != PSA_SUCCESS) {
ret = psa_pk_status_to_mbedtls(status);
status = psa_destroy_key(key_id);
return (status != PSA_SUCCESS) ? psa_pk_status_to_mbedtls(status) : ret;
ret = psa_pk_status_to_mbedtls(status);
destruction_status = psa_destroy_key(key_id);
if (ret != 0) {
return ret;
} else if (destruction_status != PSA_SUCCESS) {
return psa_pk_status_to_mbedtls(destruction_status);
}
ret = mbedtls_ecp_point_read_binary(grp, Q, key_buf, key_len);
status = psa_destroy_key(key_id);
if (status != PSA_SUCCESS) {
return psa_pk_status_to_mbedtls(status);
}
return ret;
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */