I'm currently working on replacing the chacha20 encryption in my app with chacha20poly1305, but I'm running into a few questions that I can't seem to find clear answers to, mainly stemming from the Rust chacha20poly1305
crate:
- Why does the
chacha20poly1305
crate require a nonce for every message, but chacha20
only requires a single nonce when initializing the cipher? Why does this not seem to be the case for other libraries, such as Python's PyCryptodome
?
- Does the ChaCha20Poly1305 algorithm require a new nonce for every message?
- I was under the understanding that the ChaCha20 algorithm has an internal counter which it combines with the key and nonce to generate blocks of the keystream (one block per increment of the counter). Is this not the case when it is used in ChaCha20Poly1305?
Finally, if ChaCha20Poly1305 (or in my case XChaCha20Poly1305) does need a new nonce for every message, would a 4-byte per-message counter combined with a 20-byte random per-session nonce be suitable to use as the per-message nonce? (the key is password-derived and so likely to repeat between sessions, and somehow storing a universal counter across all sessions is not feasible.)
Thanks!