mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Fix psa_key_derivation_output_bytes
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
This commit is contained in:
@ -5814,13 +5814,6 @@ psa_status_t psa_key_derivation_output_bytes(
|
|||||||
return PSA_ERROR_BAD_STATE;
|
return PSA_ERROR_BAD_STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output_length > operation->capacity) {
|
|
||||||
operation->capacity = 0;
|
|
||||||
/* Go through the error path to wipe all confidential data now
|
|
||||||
* that the operation object is useless. */
|
|
||||||
status = PSA_ERROR_INSUFFICIENT_DATA;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
if (output_length == 0 && operation->capacity == 0) {
|
if (output_length == 0 && operation->capacity == 0) {
|
||||||
/* Edge case: this is a finished operation, and 0 bytes
|
/* Edge case: this is a finished operation, and 0 bytes
|
||||||
* were requested. The right error in this case could
|
* were requested. The right error in this case could
|
||||||
@ -5832,6 +5825,14 @@ psa_status_t psa_key_derivation_output_bytes(
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOCAL_OUTPUT_ALLOC(output_external, output_length, output);
|
LOCAL_OUTPUT_ALLOC(output_external, output_length, output);
|
||||||
|
if (output_length > operation->capacity) {
|
||||||
|
operation->capacity = 0;
|
||||||
|
/* Go through the error path to wipe all confidential data now
|
||||||
|
* that the operation object is useless. */
|
||||||
|
status = PSA_ERROR_INSUFFICIENT_DATA;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
operation->capacity -= output_length;
|
operation->capacity -= output_length;
|
||||||
|
|
||||||
#if defined(BUILTIN_ALG_ANY_HKDF)
|
#if defined(BUILTIN_ALG_ANY_HKDF)
|
||||||
@ -5872,8 +5873,6 @@ psa_status_t psa_key_derivation_output_bytes(
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
LOCAL_OUTPUT_FREE(output_external, output);
|
|
||||||
|
|
||||||
if (status != PSA_SUCCESS) {
|
if (status != PSA_SUCCESS) {
|
||||||
/* Preserve the algorithm upon errors, but clear all sensitive state.
|
/* Preserve the algorithm upon errors, but clear all sensitive state.
|
||||||
* This allows us to differentiate between exhausted operations and
|
* This allows us to differentiate between exhausted operations and
|
||||||
@ -5884,6 +5883,8 @@ exit:
|
|||||||
operation->alg = alg;
|
operation->alg = alg;
|
||||||
memset(output, '!', output_length);
|
memset(output, '!', output_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOCAL_OUTPUT_FREE(output_external, output);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user