From 0e9be79ea38cdfd608ef13171962b79d35121a51 Mon Sep 17 00:00:00 2001 From: Ben Taylor Date: Wed, 27 May 2026 08:22:21 +0100 Subject: [PATCH] Add simplification of if statement in chacha20 Signed-off-by: Ben Taylor --- library/chacha20.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/library/chacha20.c b/library/chacha20.c index 45bef2c090..bef493a6dd 100644 --- a/library/chacha20.c +++ b/library/chacha20.c @@ -233,9 +233,7 @@ static int chacha20_check_counter_wrap(const mbedtls_chacha20_context *ctx, needed_blocks++; } - if (needed_blocks != 0U && - needed_blocks - 1U > - (uint64_t) CHACHA20_MAX_BLOCKS - ctx->state[CHACHA20_CTR_INDEX]) { + if (needed_blocks > (uint64_t) CHACHA20_MAX_BLOCKS + 1 - ctx->state[CHACHA20_CTR_INDEX]) { return MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA; }