chacha20: fix bug in starts() and add test for it
Previously the streaming API would fail when encrypting multiple messages with
the same key.
diff --git a/library/chacha20.c b/library/chacha20.c
index 5ede455..d89000d 100644
--- a/library/chacha20.c
+++ b/library/chacha20.c
@@ -243,6 +243,12 @@
ctx->initial_state[14] = BYTES_TO_U32_LE( nonce, 4 );
ctx->initial_state[15] = BYTES_TO_U32_LE( nonce, 8 );
+ mbedtls_zeroize( ctx->working_state, sizeof( ctx->working_state ) );
+ mbedtls_zeroize( ctx->keystream8, sizeof( ctx->keystream8 ) );
+
+ /* Initially, there's no keystream bytes available */
+ ctx->keystream_bytes_used = CHACHA20_BLOCK_SIZE_BYTES;
+
return( 0 );
}