-
Notifications
You must be signed in to change notification settings - Fork 54
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
chacha20
regression: Looping counters and 32-bit counter for xchacha
#391
Comments
64-bit counter support is tracked as #334. Counter looping and the removal of tests is definitely quite unfortunate. Sorry to hear that happened. It seems like we should track it as a security vulnerability as it results in the reuse of the keystream. |
The check is performed in the
The same distinction is present in the I understand that it's a somewhat brittle and misusable API, so it may be worth to tweak it in cipher v0.5. |
I'm not sure how it's getting skipped but if that overflow check was sufficient it should make this test pass:
which indicates that encryption |
technically I think that test may still fail based on that assertion if the counter doesn't return a special overflow value, but removing that assertion causes the subsequent |
You hit an unfortunate corner-case of the implemented check. I don't remember the exact details, but it was more efficient to check whether user tries to generate the last keystream block instead of whether we consume the last byte in it. This test passes as expected: #[test]
fn bad_overflow_check4() {
let mut cipher = chacha20::ChaCha20::new(&Default::default(), &Default:>
cipher
.try_seek(OFFSET_256GB - 65)
.expect("Couldn't seek to nearly 256GB");
let mut data = [0u8; 1];
cipher
.try_apply_keystream(&mut data)
.expect("Couldn't encrypt the last byte of 256GB");
let mut data = [0u8; 1];
cipher
.try_apply_keystream(&mut data)
.expect_err("Could encrypt past the last byte of 256GB");
} It may be worth to return an error from |
I think we can close this issue? If you have proposals on how we can improve the wrapping detection, then it's better to discuss them in the traits repo. |
It appears that all the tests added by my previous PRs #217 and #216 were removed. The behavior checked by those tests appears to have regressed. In particular, xchacha20 can no longer use the full 64-bit counter space and instead sets the upper 32 bits to 0, and the overflow handling allows for looping counters -- e.g.,
stream-ciphers/chacha20/src/backends/soft.rs
Line 31 in 44beace
The commit which removed these tests, and which also appears to have introduced a regression on all this behavior, is the following commit by @newpavlov :
The text was updated successfully, but these errors were encountered: