Add guard to prevent wraparound if SIZE_MAX > UINT64_MAX in chacha20

Signed-off-by: Ben Taylor <[email protected]>
This commit is contained in:
Ben Taylor
2026-05-29 13:17:29 +01:00
parent 3a358b0677
commit 7bf0215f8d
+6
View File
@@ -212,6 +212,12 @@ static int chacha20_check_counter_wrap(const mbedtls_chacha20_context *ctx,
return size == 0U ? 0 : MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA;
}
#if SIZE_MAX >= UINT64_MAX
if (size > UINT64_MAX / 2) {
return MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA;
}
#endif
if (ctx->keystream_bytes_used < CHACHA20_BLOCK_SIZE_BYTES) {
available_keystream =
CHACHA20_BLOCK_SIZE_BYTES - ctx->keystream_bytes_used;