Skip to content

Commit

Permalink
Merge pull request #1273 from gowthamsk-arm/mem-alloc-cleanup-2.28
Browse files Browse the repository at this point in the history
Backport 2.28: Fix: Memory allocation cleanup in internal crypto api functions
  • Loading branch information
tom-cosgrove-arm authored Aug 19, 2024
2 parents b492272 + d9e16c4 commit 7c5160c
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions library/psa_crypto_rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,14 @@ psa_status_t mbedtls_psa_rsa_export_public_key(

status = mbedtls_psa_rsa_load_representation(
attributes->core.type, key_buffer, key_buffer_size, &rsa);
if (status != PSA_SUCCESS) {
return status;
if (status == PSA_SUCCESS) {
status = mbedtls_psa_rsa_export_key(PSA_KEY_TYPE_RSA_PUBLIC_KEY,
rsa,
data,
data_size,
data_length);
}

status = mbedtls_psa_rsa_export_key(PSA_KEY_TYPE_RSA_PUBLIC_KEY,
rsa,
data,
data_size,
data_length);

mbedtls_rsa_free(rsa);
mbedtls_free(rsa);

Expand Down Expand Up @@ -286,6 +284,7 @@ psa_status_t mbedtls_psa_rsa_generate_key(
(unsigned int) attributes->core.bits,
exponent);
if (ret != 0) {
mbedtls_rsa_free(&rsa);
return mbedtls_to_psa_error(ret);
}

Expand Down Expand Up @@ -354,7 +353,7 @@ psa_status_t mbedtls_psa_rsa_sign_hash(
key_buffer_size,
&rsa);
if (status != PSA_SUCCESS) {
return status;
goto exit;
}

status = psa_rsa_decode_md_type(alg, hash_length, &md_alg);
Expand Down

0 comments on commit 7c5160c

Please sign in to comment.