Tidy ChaCha20 counter limit handling

Signed-off-by: Ben Taylor <[email protected]>
This commit is contained in:
Ben Taylor
2026-05-29 13:17:36 +01:00
parent 7bf0215f8d
commit dcf3b11749
3 changed files with 4 additions and 2 deletions
+2 -1
View File
@@ -38,7 +38,8 @@ extern "C" {
typedef struct mbedtls_chacha20_context {
uint32_t MBEDTLS_PRIVATE(state)[16]; /*! The state (before round operations). */
uint8_t MBEDTLS_PRIVATE(keystream8)[64]; /*! Leftover keystream bytes. */
size_t MBEDTLS_PRIVATE(keystream_bytes_used); /*! Number of keystream bytes already used. */
size_t MBEDTLS_PRIVATE(keystream_bytes_used); /*! Number of keystream bytes already used,
* or an internal sentinel value. */
}
mbedtls_chacha20_context;
+1 -1
View File
@@ -31,7 +31,7 @@
#define CHACHA20_BLOCK_SIZE_BYTES (4U * 16U)
#define CHACHA20_MAX_BLOCKS 0xFFFFFFFF
#define CHACHA20_MAX_BLOCKS UINT32_MAX
#define CHACHA20_COUNTER_EXHAUSTED (CHACHA20_BLOCK_SIZE_BYTES + 1U)
@@ -96,6 +96,7 @@ void chacha20_input_len_too_long(void)
/* Consume the rest of the final counter block, then reject more input. */
TEST_EQUAL(mbedtls_chacha20_update(&ctx, 63, input, output), 0);
TEST_EQUAL(mbedtls_chacha20_update(&ctx, 0, NULL, NULL), 0);
TEST_EQUAL(mbedtls_chacha20_update(&ctx, 1, input, output),
MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA);