diff --git a/libi2pd/ChaCha20.cpp b/libi2pd/ChaCha20.cpp index 30e02f42..be012cbd 100644 --- a/libi2pd/ChaCha20.cpp +++ b/libi2pd/ChaCha20.cpp @@ -111,7 +111,8 @@ void Chacha20Encrypt (Chacha20State& state, uint8_t * buf, size_t sz) buf[i] ^= state.block.data[state.offset + i]; buf += s; sz -= s; - state.offset = 0; + state.offset += s; + if (state.offset >= chacha::blocksize) state.offset = 0; } for (size_t i = 0; i < sz; i += chacha::blocksize) { diff --git a/tests/test-aeadchacha20poly1305.cpp b/tests/test-aeadchacha20poly1305.cpp index 822744c1..de9f1db2 100644 --- a/tests/test-aeadchacha20poly1305.cpp +++ b/tests/test-aeadchacha20poly1305.cpp @@ -53,7 +53,7 @@ int main () assert (memcmp (buf1, text, 114) == 0); // test encryption of multiple buffers memcpy (buf, text, 114); - std::vector > bufs{ std::make_pair (buf, 50), std::make_pair (buf + 50, 50), std::make_pair (buf + 100, 14) }; + std::vector > bufs{ std::make_pair (buf, 20), std::make_pair (buf + 20, 10), std::make_pair (buf + 30, 70), std::make_pair (buf + 100, 14) }; i2p::crypto::AEADChaCha20Poly1305Encrypt (bufs, key, nonce, buf + 114); i2p::crypto::AEADChaCha20Poly1305 (buf, 114, nullptr, 0, key, nonce, buf1, 114, false); assert (memcmp (buf1, text, 114) == 0);