1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-30 22:43:08 +03:00

Protect buffer in psa_import_key

Signed-off-by: Ryan Everett <ryan.everett@arm.com>
This commit is contained in:
Ryan Everett
2024-01-19 16:02:59 +00:00
parent 3e7ef37e07
commit 6b97025466

View File

@ -2063,11 +2063,12 @@ rsa_exit:
} }
psa_status_t psa_import_key(const psa_key_attributes_t *attributes, psa_status_t psa_import_key(const psa_key_attributes_t *attributes,
const uint8_t *data, const uint8_t *data_external,
size_t data_length, size_t data_length,
mbedtls_svc_key_id_t *key) mbedtls_svc_key_id_t *key)
{ {
psa_status_t status; psa_status_t status;
LOCAL_INPUT_DECLARE(data_external, data);
psa_key_slot_t *slot = NULL; psa_key_slot_t *slot = NULL;
psa_se_drv_table_entry_t *driver = NULL; psa_se_drv_table_entry_t *driver = NULL;
size_t bits; size_t bits;
@ -2081,6 +2082,8 @@ psa_status_t psa_import_key(const psa_key_attributes_t *attributes,
return PSA_ERROR_INVALID_ARGUMENT; return PSA_ERROR_INVALID_ARGUMENT;
} }
LOCAL_INPUT_ALLOC(data_external, data_length, data);
status = psa_start_key_creation(PSA_KEY_CREATION_IMPORT, attributes, status = psa_start_key_creation(PSA_KEY_CREATION_IMPORT, attributes,
&slot, &driver); &slot, &driver);
if (status != PSA_SUCCESS) { if (status != PSA_SUCCESS) {
@ -2122,6 +2125,7 @@ psa_status_t psa_import_key(const psa_key_attributes_t *attributes,
status = psa_finish_key_creation(slot, driver, key); status = psa_finish_key_creation(slot, driver, key);
exit: exit:
LOCAL_INPUT_FREE(data_external, data);
if (status != PSA_SUCCESS) { if (status != PSA_SUCCESS) {
psa_fail_key_creation(slot, driver); psa_fail_key_creation(slot, driver);
} }