How to encrypt a large chunked plaintext using AEAD?

I want to use XChaCha20-Poly1305 to a encrypt plaintext and then decrypt the result. I want to do this by splitting large data into chunks to reduce memory usage.

The encryption and decryption methods without splitting the plaintext into chunks are described below:

But I couldn't find a way to encrypt and decrypt the chunked plaintext. How can I do this? I want the final results of encryption and decryption to be the same for the chunked plaintext and the non-chunked plaintext.

Unfortunately, this is currently not supported, see this issue:

You have to either use the STREAM construction or mmap your file. In the latter case you should fully understand potential consequences.

1 Like

Will the final results obtained using the STREAM construction be the same as the normal way?

You mean whether you get the same data after decryption as before encryption? Well, obviously yes. But encrypted data will be bigger since it will contain an additional MAC tag for each processed chunk instead of one tag for the whole message as with the "classical" AEAD.

1 Like

I want to get the ciphertext and the tag for the whole message as with the "classical" AEAD. So I don't think the STREAM construction will achieve my purpose.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.