Closed voidus closed 1 year ago
For block ciphers we have helper functions aeadSimpleEncrypt
and aeadSimpleDecrypt
.
No problem adding similar functions for ChaChaPoly1305.
When not incremental, a decryption function which is lazy enough should give the short-circuit evaluation you want.
Currently, the only way to decrypt ChaChaPoly1305-encrypted data is:
This isn't ideal, we want to compare the tag before operating on the data. This is very inconvenient with the current implementation:
And this doesn't even use AAD, not to mention that it leaks quite a bit of the implementation.
authenticate :: ByteArray ba => ba -> State -> State
, which updates the Poly1305-State but doesn't decrypt the data?This with a similar function for encryption would make things more usable, and it would encapsulate the MAC verification in the case where two passes over the data are acceptable, i.e. we can MAC-then-decrypt.
If you like the idea, I could give it a try.