Reject overlong PSA ChaChaPoly lengths

Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
This commit is contained in:
Ben Taylor 2026-05-29 08:49:51 +01:00
parent 3df9fac129
commit 96cb584a5e
2 changed files with 11 additions and 3 deletions

View File

@ -5357,7 +5357,13 @@ psa_status_t psa_aead_set_lengths(psa_aead_operation_t *operation,
#endif /* PSA_WANT_ALG_CCM */
#if defined(PSA_WANT_ALG_CHACHA20_POLY1305)
case PSA_ALG_CHACHA20_POLY1305:
/* No length restrictions for ChaChaPoly. */
#if SIZE_MAX > UINT32_MAX
if (plaintext_length > (size_t) UINT32_MAX *
64U) {
status = PSA_ERROR_INVALID_ARGUMENT;
goto exit;
}
#endif
break;
#endif /* PSA_WANT_ALG_CHACHA20_POLY1305 */
default:

View File

@ -6367,7 +6367,8 @@ void aead_multipart_state_test(int key_type_arg, data_t *key_data,
#if SIZE_MAX > UINT32_MAX
PSA_ASSERT(psa_aead_encrypt_setup(&operation, key, alg));
if (operation.alg == PSA_ALG_GCM) {
if (operation.alg == PSA_ALG_GCM ||
operation.alg == PSA_ALG_CHACHA20_POLY1305) {
TEST_EQUAL(psa_aead_set_lengths(&operation, additional_data->len,
SIZE_MAX),
PSA_ERROR_INVALID_ARGUMENT);
@ -6388,7 +6389,8 @@ void aead_multipart_state_test(int key_type_arg, data_t *key_data,
PSA_ASSERT(psa_aead_set_nonce(&operation, nonce->x, nonce->len));
if (operation.alg == PSA_ALG_GCM) {
if (operation.alg == PSA_ALG_GCM ||
operation.alg == PSA_ALG_CHACHA20_POLY1305) {
TEST_EQUAL(psa_aead_set_lengths(&operation, additional_data->len,
SIZE_MAX),
PSA_ERROR_INVALID_ARGUMENT);