-
Notifications
You must be signed in to change notification settings - Fork 52
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
XChaCha20 unnecessarily limits keystream to 256gb #213
Comments
Unfortunately this is one of those things where XChaCha20 is a non-standard construction with no spec, and thus no clear guidance around data volume limits. Internally the counters are 64-bit, but all implementations presently respect the data volume limits of the IETF construction. The former is largely the result of legacy: the initial implementation of the RFC8439 Section 2.3. says the following:
The mention of RFC5116 Section 3.2 mostly appears to be in regard to the use of a 96-bit nonce, and the choice of a 32-bit counter the effect of the modified 96-bit nonce (over the original "djb" 64-bit nonce) being to supply 32-bits of leading counter value, effectively splitting the 64-bit counter in half. In XChaCha20, that upper (in terms of ChaCha core inputs) 32-bit counter value (i.e. upper half of the 64-bit counter) is always initialized to 0 (by way of the first 4 bytes of the non-extended nonce), which I think is what you're getting at here. So this is one of those things where I could go either way, and for lack of a true spec it's unclear which way to go. https://tools.ietf.org/html/draft-arciszewski-xchacha-03 appears to be assuming that XChaCha20 implementations will be composed in terms of the IETF implementation at its core, with its prescriptive use of a 32-bit counter value. Indeed that's how the In terms of parity with other implementations, libsodium's AEAD limitations documentation gives the separate data volume limits you're suggesting, with a limit of 2^64 for XChaCha20. |
My understanding of the mess around 256gb was that:
Enforcing the 32-bit counter for 96-bit chacha20 is totally sensible to catch dangerous misuse. However, I'm pretty sure the implementations we have here don't have the looping-keystream problem, and for things like 64-bit-nonce chacha20 and xchacha20 it would be nice to be able to encrypt multi-terabyte tarballs. |
In absence of an XChaCha20 RFC providing explicit advice, I'm weakly in favor of aligning with the implementation in libsodium, which uses a 64-bit counter for XChaCha20. |
Forgive me if this is off-topic, but do you know what the |
No idea, nor does it appear to be references anywhere in the code contents. |
The code seems to be using
so idk what the 4gb problem could really be unless Regardless, the implementation here doesn't seem to have that problem, since counter management is outside the vectorized backend. I have some time available this week -- I'll try to get a PR with some test cases ready for review. |
XChaCha20 can support a full 64-bit keystream for any given nonce, so the MAX_BLOCKS limit of 96-bit-nonce ChaCha20 shouldn't apply.
Technically this wouldn't comply with https://tools.ietf.org/html/draft-arciszewski-xchacha-03 but a cursory glance through the counter handling code makes me think that nothing would actually go wrong -- everything is done with a 64bit counter and split into two 32bit words in the backends.
As a side note, I'm preeeeetty sure that in this implementation 32-bit counter "overflows" would roll over to the next nonce instead of actually leading to nonce reuse. Not great, but #64 may not have been as critical as it looked.
The text was updated successfully, but these errors were encountered: