From 9c8f3ec67b3d8413ec0ede19cb7a264121b0277f Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sat, 17 Oct 2026 21:41:03 +0900 Subject: [PATCH] Crypto: fix ChaCha partial block continuation Count consumed input bytes so short updates don't skip unused keystream. Reset the saved offset when the block is exhausted. Reported by @router0mail. --- src/Crypto/chacha256.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Crypto/chacha256.c b/src/Crypto/chacha256.c index 685f7886..2dd7b521 100644 --- a/src/Crypto/chacha256.c +++ b/src/Crypto/chacha256.c @@ -151,12 +151,14 @@ static VC_INLINE void do_encrypt(const unsigned char* in, size_t len, unsigned c size_t i = 0, pos = *posPtr; if (pos) { - while (pos < len && pos < 64) + while (i < len && pos < 64) { out[i] = in[i] ^ ((unsigned char*)block)[pos++]; ++i; } len -= i; + if (pos == 64) + pos = 0; } if (len) pos = 0;