-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CHACHAPOLY_MAX is too large by 1 block #2
Comments
Yes, you're right; it should be (2^32 - 1) * 64 🙈 When it comes to input validation in the |
I mean that if as a result of the n += 1 line, |
Ah, ok 😊 [profile.release]
overflow-checks = true so it should panic on any overflow in the crate. |
Oh, I missed that. Excellent! |
In the AEAD construction, block counter = 0 is used to generate the poly1305 key, and encryption of data blocks starts with block counter = 1, so at most 2^32 - 1 blocks can be encrypted. However, the value of CHACHAPOLY_MAX is 2^32 blocks. I believe this means that the code will let you encrypt 2^32*64 bytes, and the last block will be XORed with the poly1305 key, because of n overflowing (at least in release builds).
In addition to fixing the constant I'd recommend adding a check (that works even in release builds) for
n
overflowing in thexor
function.The text was updated successfully, but these errors were encountered: