mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-16 08:42:50 +00:00
Implement safe buffer copying in asymm. encryption
Use local copy buffer macros to implement safe copy mechanism in asymmetric encryption API. Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
This commit is contained in:
parent
ad736991bb
commit
6adbb2a351
@ -3283,11 +3283,11 @@ exit:
|
||||
|
||||
psa_status_t psa_asymmetric_encrypt(mbedtls_svc_key_id_t key,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *input,
|
||||
const uint8_t *input_external,
|
||||
size_t input_length,
|
||||
const uint8_t *salt,
|
||||
const uint8_t *salt_external,
|
||||
size_t salt_length,
|
||||
uint8_t *output,
|
||||
uint8_t *output_external,
|
||||
size_t output_size,
|
||||
size_t *output_length)
|
||||
{
|
||||
@ -3295,6 +3295,9 @@ psa_status_t psa_asymmetric_encrypt(mbedtls_svc_key_id_t key,
|
||||
psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_key_slot_t *slot;
|
||||
psa_key_attributes_t attributes;
|
||||
LOCAL_INPUT_DECLARE(input_external, input);
|
||||
LOCAL_INPUT_DECLARE(salt_external, salt);
|
||||
LOCAL_OUTPUT_DECLARE(output_external, output);
|
||||
|
||||
(void) input;
|
||||
(void) input_length;
|
||||
@ -3323,6 +3326,9 @@ psa_status_t psa_asymmetric_encrypt(mbedtls_svc_key_id_t key,
|
||||
.core = slot->attr
|
||||
};
|
||||
|
||||
LOCAL_INPUT_ALLOC(input_external, input_length, input);
|
||||
LOCAL_INPUT_ALLOC(salt_external, salt_length, salt);
|
||||
LOCAL_OUTPUT_ALLOC(output_external, output_size, output);
|
||||
status = psa_driver_wrapper_asymmetric_encrypt(
|
||||
&attributes, slot->key.data, slot->key.bytes,
|
||||
alg, input, input_length, salt, salt_length,
|
||||
@ -3330,16 +3336,20 @@ psa_status_t psa_asymmetric_encrypt(mbedtls_svc_key_id_t key,
|
||||
exit:
|
||||
unlock_status = psa_unregister_read(slot);
|
||||
|
||||
LOCAL_INPUT_FREE(input_external, input);
|
||||
LOCAL_INPUT_FREE(salt_external, salt);
|
||||
LOCAL_OUTPUT_FREE(output_external, output);
|
||||
|
||||
return (status == PSA_SUCCESS) ? unlock_status : status;
|
||||
}
|
||||
|
||||
psa_status_t psa_asymmetric_decrypt(mbedtls_svc_key_id_t key,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *input,
|
||||
const uint8_t *input_external,
|
||||
size_t input_length,
|
||||
const uint8_t *salt,
|
||||
const uint8_t *salt_external,
|
||||
size_t salt_length,
|
||||
uint8_t *output,
|
||||
uint8_t *output_external,
|
||||
size_t output_size,
|
||||
size_t *output_length)
|
||||
{
|
||||
@ -3348,6 +3358,10 @@ psa_status_t psa_asymmetric_decrypt(mbedtls_svc_key_id_t key,
|
||||
psa_key_slot_t *slot;
|
||||
psa_key_attributes_t attributes;
|
||||
|
||||
LOCAL_INPUT_DECLARE(input_external, input);
|
||||
LOCAL_INPUT_DECLARE(salt_external, salt);
|
||||
LOCAL_OUTPUT_DECLARE(output_external, output);
|
||||
|
||||
(void) input;
|
||||
(void) input_length;
|
||||
(void) salt;
|
||||
@ -3374,6 +3388,9 @@ psa_status_t psa_asymmetric_decrypt(mbedtls_svc_key_id_t key,
|
||||
.core = slot->attr
|
||||
};
|
||||
|
||||
LOCAL_INPUT_ALLOC(input_external, input_length, input);
|
||||
LOCAL_INPUT_ALLOC(salt_external, salt_length, salt);
|
||||
LOCAL_OUTPUT_ALLOC(output_external, output_size, output);
|
||||
status = psa_driver_wrapper_asymmetric_decrypt(
|
||||
&attributes, slot->key.data, slot->key.bytes,
|
||||
alg, input, input_length, salt, salt_length,
|
||||
@ -3382,6 +3399,10 @@ psa_status_t psa_asymmetric_decrypt(mbedtls_svc_key_id_t key,
|
||||
exit:
|
||||
unlock_status = psa_unregister_read(slot);
|
||||
|
||||
LOCAL_INPUT_FREE(input_external, input);
|
||||
LOCAL_INPUT_FREE(salt_external, salt);
|
||||
LOCAL_OUTPUT_FREE(output_external, output);
|
||||
|
||||
return (status == PSA_SUCCESS) ? unlock_status : status;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user