mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-28 08:37:25 +00:00
pk: fix return codes' precedence and code style
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
parent
9d65f0ef12
commit
1df94f841b
@ -1107,7 +1107,7 @@ cleanup:
|
|||||||
static int eckey_check_pair_psa(const mbedtls_ecp_keypair *pub,
|
static int eckey_check_pair_psa(const mbedtls_ecp_keypair *pub,
|
||||||
const mbedtls_ecp_keypair *prv)
|
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;
|
psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT;
|
||||||
mbedtls_ecp_keypair *prv_ctx = (mbedtls_ecp_keypair *) prv;
|
mbedtls_ecp_keypair *prv_ctx = (mbedtls_ecp_keypair *) prv;
|
||||||
mbedtls_ecp_keypair *pub_ctx = (mbedtls_ecp_keypair *) pub;
|
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);
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_platform_zeroize(prv_key_buf, sizeof(prv_key_buf));
|
mbedtls_platform_zeroize(prv_key_buf, sizeof(prv_key_buf));
|
||||||
|
|
||||||
ret = PSA_PK_TO_MBEDTLS_ERR(psa_export_public_key(key_id,
|
status = psa_export_public_key(key_id, prv_key_buf, sizeof(prv_key_buf),
|
||||||
prv_key_buf,
|
&prv_key_len);
|
||||||
sizeof(prv_key_buf),
|
ret = PSA_PK_TO_MBEDTLS_ERR(status);
|
||||||
&prv_key_len));
|
destruction_status = psa_destroy_key(key_id);
|
||||||
status = psa_destroy_key(key_id);
|
if (ret != 0) {
|
||||||
if (ret != 0 || status != PSA_SUCCESS) {
|
return ret;
|
||||||
return (ret != 0) ? ret : PSA_PK_TO_MBEDTLS_ERR(status);
|
} 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,
|
ret = mbedtls_ecp_point_write_binary(&pub_ctx->grp, &pub_ctx->Q,
|
||||||
|
@ -885,7 +885,7 @@ cleanup:
|
|||||||
static int pk_derive_public_key(mbedtls_ecp_group *grp, mbedtls_ecp_point *Q,
|
static int pk_derive_public_key(mbedtls_ecp_group *grp, mbedtls_ecp_point *Q,
|
||||||
const mbedtls_mpi *d)
|
const mbedtls_mpi *d)
|
||||||
{
|
{
|
||||||
psa_status_t status;
|
psa_status_t status, destruction_status;
|
||||||
psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT;
|
psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT;
|
||||||
size_t curve_bits;
|
size_t curve_bits;
|
||||||
psa_ecc_family_t curve = mbedtls_ecc_group_to_psa(grp->id, &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);
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_platform_zeroize(key_buf, sizeof(key_buf));
|
mbedtls_platform_zeroize(key_buf, sizeof(key_buf));
|
||||||
|
|
||||||
status = psa_export_public_key(key_id, key_buf, sizeof(key_buf), &key_len);
|
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);
|
||||||
ret = psa_pk_status_to_mbedtls(status);
|
destruction_status = psa_destroy_key(key_id);
|
||||||
status = psa_destroy_key(key_id);
|
if (ret != 0) {
|
||||||
return (status != PSA_SUCCESS) ? psa_pk_status_to_mbedtls(status) : ret;
|
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);
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user