mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-06-25 12:41:56 +03:00
Fix buffer protection handling for cipher_generate_iv
Use the `LOCAL_OUTPUT_` macros for buffer protection instead of the existing local variable. Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
This commit is contained in:
@ -4322,14 +4322,15 @@ psa_status_t psa_cipher_decrypt_setup(psa_cipher_operation_t *operation,
|
|||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t psa_cipher_generate_iv(psa_cipher_operation_t *operation,
|
psa_status_t psa_cipher_generate_iv(psa_cipher_operation_t *operation,
|
||||||
uint8_t *iv,
|
uint8_t *iv_external,
|
||||||
size_t iv_size,
|
size_t iv_size,
|
||||||
size_t *iv_length)
|
size_t *iv_length)
|
||||||
{
|
{
|
||||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
uint8_t local_iv[PSA_CIPHER_IV_MAX_SIZE];
|
|
||||||
size_t default_iv_length = 0;
|
size_t default_iv_length = 0;
|
||||||
|
|
||||||
|
LOCAL_OUTPUT_DECLARE(iv_external, iv);
|
||||||
|
|
||||||
if (operation->id == 0) {
|
if (operation->id == 0) {
|
||||||
status = PSA_ERROR_BAD_STATE;
|
status = PSA_ERROR_BAD_STATE;
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -4351,24 +4352,29 @@ psa_status_t psa_cipher_generate_iv(psa_cipher_operation_t *operation,
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = psa_generate_random(local_iv, default_iv_length);
|
LOCAL_OUTPUT_ALLOC(iv_external, default_iv_length, iv);
|
||||||
|
|
||||||
|
status = psa_generate_random(iv, default_iv_length);
|
||||||
if (status != PSA_SUCCESS) {
|
if (status != PSA_SUCCESS) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = psa_driver_wrapper_cipher_set_iv(operation,
|
status = psa_driver_wrapper_cipher_set_iv(operation,
|
||||||
local_iv, default_iv_length);
|
iv, default_iv_length);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (status == PSA_SUCCESS) {
|
if (status == PSA_SUCCESS) {
|
||||||
psa_crypto_copy_output(local_iv, default_iv_length, iv, iv_size);
|
|
||||||
*iv_length = default_iv_length;
|
*iv_length = default_iv_length;
|
||||||
operation->iv_set = 1;
|
operation->iv_set = 1;
|
||||||
} else {
|
} else {
|
||||||
*iv_length = 0;
|
*iv_length = 0;
|
||||||
psa_cipher_abort(operation);
|
psa_cipher_abort(operation);
|
||||||
|
if (iv != NULL) {
|
||||||
|
mbedtls_platform_zeroize(iv, default_iv_length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOCAL_OUTPUT_FREE(iv_external, iv);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user