Revise how output allocation is checked

Signed-off-by: Thomas Daubney <thomas.daubney@arm.com>
This commit is contained in:
Thomas Daubney 2024-02-21 15:15:00 +00:00
parent 89d8c2a1b4
commit 0576a6a174

View File

@ -7429,20 +7429,16 @@ psa_status_t psa_raw_key_agreement(psa_algorithm_t alg,
output_length); output_length);
exit: exit:
/* Check for successful allocation of output. */ if (output != NULL && status != PSA_SUCCESS) {
if (output != NULL && status != PSA_ERROR_INSUFFICIENT_MEMORY) { /* If an error happens and is not handled properly, the output
/* output allocated. */ * may be used as a key to protect sensitive data. Arrange for such
if (status != PSA_SUCCESS) { * a key to be random, which is likely to result in decryption or
/* If an error happens and is not handled properly, the output * verification errors. This is better than filling the buffer with
* may be used as a key to protect sensitive data. Arrange for such * some constant data such as zeros, which would result in the data
* a key to be random, which is likely to result in decryption or * being protected with a reproducible, easily knowable key.
* verification errors. This is better than filling the buffer with */
* some constant data such as zeros, which would result in the data psa_generate_random(output, output_size);
* being protected with a reproducible, easily knowable key. *output_length = output_size;
*/
psa_generate_random(output, output_size);
*output_length = output_size;
}
} else { } else {
/* output allocation failed. */ /* output allocation failed. */
*output_length = 0; *output_length = 0;