mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-10-05 00:17:24 +00:00
Tidy ChaCha20 counter limit handling
Signed-off-by: Ben Taylor <[email protected]>
This commit is contained in:
@@ -38,7 +38,8 @@ extern "C" {
|
|||||||
typedef struct mbedtls_chacha20_context {
|
typedef struct mbedtls_chacha20_context {
|
||||||
uint32_t MBEDTLS_PRIVATE(state)[16]; /*! The state (before round operations). */
|
uint32_t MBEDTLS_PRIVATE(state)[16]; /*! The state (before round operations). */
|
||||||
uint8_t MBEDTLS_PRIVATE(keystream8)[64]; /*! Leftover keystream bytes. */
|
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;
|
mbedtls_chacha20_context;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
#define CHACHA20_BLOCK_SIZE_BYTES (4U * 16U)
|
#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)
|
#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. */
|
/* 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, 63, input, output), 0);
|
||||||
|
TEST_EQUAL(mbedtls_chacha20_update(&ctx, 0, NULL, NULL), 0);
|
||||||
TEST_EQUAL(mbedtls_chacha20_update(&ctx, 1, input, output),
|
TEST_EQUAL(mbedtls_chacha20_update(&ctx, 1, input, output),
|
||||||
MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA);
|
MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user