diff --git a/Src/crypto/chacha20.c b/Src/crypto/chacha20.c index 730f24a..5bfbfcb 100644 --- a/Src/crypto/chacha20.c +++ b/Src/crypto/chacha20.c @@ -76,7 +76,7 @@ quarterround(uint32_t* a, uint32_t* b, uint32_t* c, uint32_t* d) { *b = BitManipulation_rotl32(*b ^ *c, 7); } -static void +static bool chacha20_block(const byte_t key[CHACHA20_KEY_SIZE], const uint32_t counter, const byte_t nonce[CHACHA20_NONCE_SIZE], byte_t out[KEY_STREAM_SIZE]) { @@ -153,9 +153,9 @@ chacha20(const byte_t* plaintext, uint32_t blocks = plaintext_len / BLOCK_SIZE; uint32_t remaining_bytes = plaintext_len % BLOCK_SIZE; + static byte_t key_stream[KEY_STREAM_SIZE] = ARRAY_64_ZERO_VALUES; for (uint32_t j = 0; j < blocks; ++j) { - byte_t key_stream[KEY_STREAM_SIZE] = ARRAY_64_ZERO_VALUES; chacha20_block(key, j + inc, nonce, key_stream); for (uint8_t i = 0; i < BLOCK_SIZE; ++i) { @@ -164,7 +164,6 @@ chacha20(const byte_t* plaintext, } if (0U != remaining_bytes) { - byte_t key_stream[KEY_STREAM_SIZE] = ARRAY_64_ZERO_VALUES; chacha20_block(key, blocks + inc, nonce, key_stream); for (uint32_t i = 0; i < remaining_bytes; ++i) {