mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Merge branch 'development-restricted' into generate-random-buffer-protection
Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
@ -2705,35 +2705,48 @@ psa_status_t psa_mac_verify_setup(psa_mac_operation_t *operation,
|
||||
}
|
||||
|
||||
psa_status_t psa_mac_update(psa_mac_operation_t *operation,
|
||||
const uint8_t *input,
|
||||
const uint8_t *input_external,
|
||||
size_t input_length)
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
LOCAL_INPUT_DECLARE(input_external, input);
|
||||
|
||||
if (operation->id == 0) {
|
||||
return PSA_ERROR_BAD_STATE;
|
||||
status = PSA_ERROR_BAD_STATE;
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Don't require hash implementations to behave correctly on a
|
||||
* zero-length input, which may have an invalid pointer. */
|
||||
if (input_length == 0) {
|
||||
return PSA_SUCCESS;
|
||||
status = PSA_SUCCESS;
|
||||
return status;
|
||||
}
|
||||
|
||||
psa_status_t status = psa_driver_wrapper_mac_update(operation,
|
||||
input, input_length);
|
||||
LOCAL_INPUT_ALLOC(input_external, input_length, input);
|
||||
status = psa_driver_wrapper_mac_update(operation, input, input_length);
|
||||
|
||||
if (status != PSA_SUCCESS) {
|
||||
psa_mac_abort(operation);
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
|
||||
exit:
|
||||
#endif
|
||||
LOCAL_INPUT_FREE(input_external, input);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
psa_status_t psa_mac_sign_finish(psa_mac_operation_t *operation,
|
||||
uint8_t *mac,
|
||||
uint8_t *mac_external,
|
||||
size_t mac_size,
|
||||
size_t *mac_length)
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t abort_status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
LOCAL_OUTPUT_DECLARE(mac_external, mac);
|
||||
LOCAL_OUTPUT_ALLOC(mac_external, mac_size, mac);
|
||||
|
||||
if (operation->id == 0) {
|
||||
status = PSA_ERROR_BAD_STATE;
|
||||
@ -2757,6 +2770,7 @@ psa_status_t psa_mac_sign_finish(psa_mac_operation_t *operation,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
||||
status = psa_driver_wrapper_mac_sign_finish(operation,
|
||||
mac, operation->mac_size,
|
||||
mac_length);
|
||||
@ -2773,19 +2787,23 @@ exit:
|
||||
operation->mac_size = 0;
|
||||
}
|
||||
|
||||
psa_wipe_tag_output_buffer(mac, status, mac_size, *mac_length);
|
||||
if (mac != NULL) {
|
||||
psa_wipe_tag_output_buffer(mac, status, mac_size, *mac_length);
|
||||
}
|
||||
|
||||
abort_status = psa_mac_abort(operation);
|
||||
LOCAL_OUTPUT_FREE(mac_external, mac);
|
||||
|
||||
return status == PSA_SUCCESS ? abort_status : status;
|
||||
}
|
||||
|
||||
psa_status_t psa_mac_verify_finish(psa_mac_operation_t *operation,
|
||||
const uint8_t *mac,
|
||||
const uint8_t *mac_external,
|
||||
size_t mac_length)
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t abort_status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
LOCAL_INPUT_DECLARE(mac_external, mac);
|
||||
|
||||
if (operation->id == 0) {
|
||||
status = PSA_ERROR_BAD_STATE;
|
||||
@ -2802,11 +2820,13 @@ psa_status_t psa_mac_verify_finish(psa_mac_operation_t *operation,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
LOCAL_INPUT_ALLOC(mac_external, mac_length, mac);
|
||||
status = psa_driver_wrapper_mac_verify_finish(operation,
|
||||
mac, mac_length);
|
||||
|
||||
exit:
|
||||
abort_status = psa_mac_abort(operation);
|
||||
LOCAL_INPUT_FREE(mac_external, mac);
|
||||
|
||||
return status == PSA_SUCCESS ? abort_status : status;
|
||||
}
|
||||
@ -2878,28 +2898,45 @@ exit:
|
||||
|
||||
psa_status_t psa_mac_compute(mbedtls_svc_key_id_t key,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *input,
|
||||
const uint8_t *input_external,
|
||||
size_t input_length,
|
||||
uint8_t *mac,
|
||||
uint8_t *mac_external,
|
||||
size_t mac_size,
|
||||
size_t *mac_length)
|
||||
{
|
||||
return psa_mac_compute_internal(key, alg,
|
||||
input, input_length,
|
||||
mac, mac_size, mac_length, 1);
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
LOCAL_INPUT_DECLARE(input_external, input);
|
||||
LOCAL_OUTPUT_DECLARE(mac_external, mac);
|
||||
|
||||
LOCAL_INPUT_ALLOC(input_external, input_length, input);
|
||||
LOCAL_OUTPUT_ALLOC(mac_external, mac_size, mac);
|
||||
status = psa_mac_compute_internal(key, alg,
|
||||
input, input_length,
|
||||
mac, mac_size, mac_length, 1);
|
||||
|
||||
#if defined(MBEDTLS_PSA_COPY_CALLER_BUFFERS)
|
||||
exit:
|
||||
#endif
|
||||
LOCAL_INPUT_FREE(input_external, input);
|
||||
LOCAL_OUTPUT_FREE(mac_external, mac);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
psa_status_t psa_mac_verify(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 *mac,
|
||||
const uint8_t *mac_external,
|
||||
size_t mac_length)
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
uint8_t actual_mac[PSA_MAC_MAX_SIZE];
|
||||
size_t actual_mac_length;
|
||||
LOCAL_INPUT_DECLARE(input_external, input);
|
||||
LOCAL_INPUT_DECLARE(mac_external, mac);
|
||||
|
||||
LOCAL_INPUT_ALLOC(input_external, input_length, input);
|
||||
status = psa_mac_compute_internal(key, alg,
|
||||
input, input_length,
|
||||
actual_mac, sizeof(actual_mac),
|
||||
@ -2912,6 +2949,8 @@ psa_status_t psa_mac_verify(mbedtls_svc_key_id_t key,
|
||||
status = PSA_ERROR_INVALID_SIGNATURE;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
LOCAL_INPUT_ALLOC(mac_external, mac_length, mac);
|
||||
if (mbedtls_ct_memcmp(mac, actual_mac, actual_mac_length) != 0) {
|
||||
status = PSA_ERROR_INVALID_SIGNATURE;
|
||||
goto exit;
|
||||
@ -2919,6 +2958,8 @@ psa_status_t psa_mac_verify(mbedtls_svc_key_id_t key,
|
||||
|
||||
exit:
|
||||
mbedtls_platform_zeroize(actual_mac, sizeof(actual_mac));
|
||||
LOCAL_INPUT_FREE(input_external, input);
|
||||
LOCAL_INPUT_FREE(mac_external, mac);
|
||||
|
||||
return status;
|
||||
}
|
||||
@ -3336,11 +3377,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)
|
||||
{
|
||||
@ -3348,6 +3389,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;
|
||||
@ -3376,6 +3420,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,
|
||||
@ -3383,16 +3430,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)
|
||||
{
|
||||
@ -3401,6 +3452,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;
|
||||
@ -3427,6 +3482,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,
|
||||
@ -3435,6 +3493,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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user