-
Notifications
You must be signed in to change notification settings - Fork 50
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
salsa20: revert sse2 #346
salsa20: revert sse2 #346
Conversation
This reverts RustCrypto#328. The changes introduced here generate failure when used in `scrypt`. The `scrypt_block_mix` would generate a different value. I'm not able to figure out why that change breaks scrypt. Reverting until we can figure out why.
cc @oxarbitrage Sorry for the set back. I'd love your help on fixing this. |
Agreed we should remove this for now. Perhaps it would be possible to add proptests between the two implementations to ensure they function equivalently. Turning the inputs/outputs from the linked failures into a regression test would be good as well. |
https://github.com/baloo/salsa20-inconsistency |
Last commit adds a regression test, the output of it on master:
|
Thank you for tagging me and for the regression test to expose the issue, I can take a look in about 24 hours and let you know if i can make a fix. |
I see the reverse was already merged, that gives me some more time. I was not able to find the problem in a quick lookup however i will find out. Ill keep you posted here. |
We needed to merge the revert because that was blocking the dependencies. |
Yea, that is fine and understandable, ill figure out whats going on there. Thanks you again. |
It seems that the SSE2 setup i did will only work for salsa20 with 10 double rounds (salsa20/20). The scrypt uses the salsa20/8 version. A quick workaround is to call the software backend when we are in the SSE2 mode and using other than salsa20/20. This call can be around here, something like: if !is_salsa20(&backend) {
f.call(&mut crate::backends::soft::Backend(&mut SalsaCore::<R> {
state: *state,
rounds: PhantomData,
}));
}
else {
f.call(&mut backend);
state[8] = _mm_cvtsi128_si32(backend.v[2]) as u32;
} A function to know if we are in salsa20/20 can be coded as:
This is far from ideal as we loss SSE2 optimization for salsa20/8. I can try to make that work but it will take more time or, i can push a PR adding back SSE2, the quick fix for versions that are not salsa20/20 and documenting that the SSE2 optimization will only be used in salsa20/20. I am also open to other alternatives, let me know. |
You should be able to do: if R::USIZE == 10 ...which should allow the compiler to remove the branch as it can be determined at compile-time. Otherwise I think falling back to the soft implementation for non-Salsa20/20 sounds fine for now. Of course it would be really nice to get it working for Salsa20/8 for scrypt, since it's bottlenecked on that. |
Thanks. Ill do this for now and ill work in a possible implementation of the sse2 optimization for salsa20/8 with some more time. Will push a PR with this soon. |
This reverts commit fea3dd0.
This reverts #328.
The changes introduced here generate failure when used in
scrypt
. Thescrypt_block_mix
would generate a different value.I'm not able to figure out why that change breaks scrypt. Reverting until we can figure out why.