1
0
mirror of https://github.com/ARMmbed/mbedtls.git synced 2025-05-13 18:29:52 +08:00

Add buffer copying to psa_sign_hash_start/complete

Add buffer protection to:
* psa_sign_hash_start(), which takes an input buffer for the hash.
* psa_sign_hash_complete(), which takes an output buffer for the
  calculated signature.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
David Horstmann 2024-03-11 13:32:16 +00:00
parent 63dfb45e5e
commit 4a523a608e

View File

@ -3556,13 +3556,15 @@ static psa_status_t psa_sign_hash_abort_internal(
psa_status_t psa_sign_hash_start( psa_status_t psa_sign_hash_start(
psa_sign_hash_interruptible_operation_t *operation, psa_sign_hash_interruptible_operation_t *operation,
mbedtls_svc_key_id_t key, psa_algorithm_t alg, mbedtls_svc_key_id_t key, psa_algorithm_t alg,
const uint8_t *hash, size_t hash_length) const uint8_t *hash_external, size_t hash_length)
{ {
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED; psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
psa_key_slot_t *slot; psa_key_slot_t *slot;
psa_key_attributes_t attributes; psa_key_attributes_t attributes;
LOCAL_INPUT_DECLARE(hash_external, hash);
/* Check that start has not been previously called, or operation has not /* Check that start has not been previously called, or operation has not
* previously errored. */ * previously errored. */
if (operation->id != 0 || operation->error_occurred) { if (operation->id != 0 || operation->error_occurred) {
@ -3588,6 +3590,8 @@ psa_status_t psa_sign_hash_start(
goto exit; goto exit;
} }
LOCAL_INPUT_ALLOC(hash_external, hash_length, hash);
attributes = (psa_key_attributes_t) { attributes = (psa_key_attributes_t) {
.core = slot->attr .core = slot->attr
}; };
@ -3612,17 +3616,21 @@ exit:
operation->error_occurred = 1; operation->error_occurred = 1;
} }
LOCAL_INPUT_FREE(hash_external, hash);
return (status == PSA_SUCCESS) ? unlock_status : status; return (status == PSA_SUCCESS) ? unlock_status : status;
} }
psa_status_t psa_sign_hash_complete( psa_status_t psa_sign_hash_complete(
psa_sign_hash_interruptible_operation_t *operation, psa_sign_hash_interruptible_operation_t *operation,
uint8_t *signature, size_t signature_size, uint8_t *signature_external, size_t signature_size,
size_t *signature_length) size_t *signature_length)
{ {
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
LOCAL_OUTPUT_DECLARE(signature_external, signature);
*signature_length = 0; *signature_length = 0;
/* Check that start has been called first, and that operation has not /* Check that start has been called first, and that operation has not
@ -3639,6 +3647,8 @@ psa_status_t psa_sign_hash_complete(
goto exit; goto exit;
} }
LOCAL_OUTPUT_ALLOC(signature_external, signature_size, signature);
status = psa_driver_wrapper_sign_hash_complete(operation, signature, status = psa_driver_wrapper_sign_hash_complete(operation, signature,
signature_size, signature_size,
signature_length); signature_length);
@ -3659,6 +3669,8 @@ exit:
psa_sign_hash_abort_internal(operation); psa_sign_hash_abort_internal(operation);
} }
LOCAL_OUTPUT_FREE(signature_external, signature);
return status; return status;
} }