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.
This commit is contained in:
Mounir IDRASSI
2026-10-17 21:54:35 +09:00
parent 67ee92f508
commit 9c8f3ec67b
+3 -1
View File
@@ -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;