On Fri, Sep 25, 2020 at 11:04 AM Jeffrey Walton noloader@gmail.com wrote:
On Fri, Sep 25, 2020 at 10:25 AM Niels Möller nisse@lysator.liu.se wrote:
Jeffrey Walton noloader@gmail.com writes: ...
It should be easy enough to test. Start with a counter of 0xfffffff8 and encrypt a couple of [64-byte] blocks. You can use Bernstein's reference implementation to generate test vectors.[1]
My bad. Start with a counter of 0xfffffff8 and encrypt or decrypt 16*64 bytes. That will get you into the corner case.
Here's a hacked version of Bernstein's code that allows you to set the counter to something other than 0's: https://github.com/noloader/cryptopp-test/blob/master/ChaCha20/chacha.c. See the XXX_ctr_setup function.
While not obvious, setting the counter is how you seek in the ChaCha stream. It allows you to encrypt or decrypt an arbitrary block of 64-bytes.
Jeff