1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-11-02 09:33:20 +03:00

Refactor & improve internal iop export public-key setup and complete APIs

Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
This commit is contained in:
Waleed Elmelegy
2024-12-09 18:00:45 +00:00
parent 1daabc113b
commit c66147df72

View File

@@ -666,17 +666,17 @@ psa_status_t mbedtls_psa_ecp_generate_key_iop_abort(
psa_status_t mbedtls_psa_ecp_export_public_key_iop_setup( psa_status_t mbedtls_psa_ecp_export_public_key_iop_setup(
mbedtls_psa_export_public_key_iop_t *operation, mbedtls_psa_export_public_key_iop_t *operation,
uint8_t *private_key, uint8_t *key,
size_t private_key_len, size_t key_len,
const psa_key_attributes_t *private_key_attributes) const psa_key_attributes_t *key_attributes)
{ {
int status = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
status = mbedtls_psa_ecp_load_representation( status = mbedtls_psa_ecp_load_representation(
psa_get_key_type(private_key_attributes), psa_get_key_type(key_attributes),
psa_get_key_bits(private_key_attributes), psa_get_key_bits(key_attributes),
private_key, key,
private_key_len, key_len,
&operation->key); &operation->key);
if (status != PSA_SUCCESS) { if (status != PSA_SUCCESS) {
goto exit; goto exit;
@@ -695,25 +695,25 @@ psa_status_t mbedtls_psa_ecp_export_public_key_iop_complete(
size_t pub_key_size, size_t pub_key_size,
size_t *pub_key_len) size_t *pub_key_len)
{ {
int status = 0; int ret = 0;
if (mbedtls_ecp_is_zero(&operation->key->Q)) { if (mbedtls_ecp_is_zero(&operation->key->Q)) {
mbedtls_psa_interruptible_set_max_ops(psa_interruptible_get_max_ops()); mbedtls_psa_interruptible_set_max_ops(psa_interruptible_get_max_ops());
status = mbedtls_ecp_mul_restartable(&operation->key->grp, &operation->key->Q, ret = mbedtls_ecp_mul_restartable(&operation->key->grp, &operation->key->Q,
&operation->key->d, &operation->key->grp.G, &operation->key->d, &operation->key->grp.G,
mbedtls_psa_get_random, MBEDTLS_PSA_RANDOM_STATE, mbedtls_psa_get_random, MBEDTLS_PSA_RANDOM_STATE,
&operation->restart_ctx); &operation->restart_ctx);
operation->num_ops += operation->restart_ctx.ops_done; operation->num_ops += operation->restart_ctx.ops_done;
} }
if (status == 0) { if (ret == 0) {
status = mbedtls_ecp_write_public_key((const mbedtls_ecp_keypair *) operation->key, ret = mbedtls_ecp_write_public_key(operation->key,
MBEDTLS_ECP_PF_UNCOMPRESSED, pub_key_len, MBEDTLS_ECP_PF_UNCOMPRESSED, pub_key_len,
pub_key, pub_key_size); pub_key, pub_key_size);
} }
return mbedtls_to_psa_error(status); return mbedtls_to_psa_error(ret);
} }
psa_status_t mbedtls_psa_ecp_export_public_key_iop_abort( psa_status_t mbedtls_psa_ecp_export_public_key_iop_abort(