-
Notifications
You must be signed in to change notification settings - Fork 431
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
rand_chacha and reducing dependencies #872
Comments
I think @tarcieri plans to implement SIMD acceleration for BTW in RustCrypto we were thinking about introducing a generic wrapper à la This way dependency tree will look like:
UPD: We also could deprecate |
SIMD support in the I really like the idea of having a "raw" API for the ChaCha20 core and making the rest of the crate dependencies optional (but default-enabled). |
Having another fast implementation of ChaCha20 does give us options. Does it not still suffer the problem of language SIMD support being experimental? |
Well, x86(-64) intrinsics have been stable for a relatively long time (since 1.27), so I wouldn't call them "experimental". One noticeable issue is the absence of |
Just to +1 @newpavlov here, while there are a lot of unstable parts of |
|
The c2-chacha crate hasn't been updated for 2 months and has two PRs for 2 cq 5 months. It also doesnt work without at least SSE2 when the simd feature is enabled. (enabled by default) cryptocorrosion/cryptocorrosion#25 |
I'd be happy to look into adding SIMD support which "just works" and isn't gated on a feature to the It's definitely on my list of things to do (as part of starting to use the |
That would be brilliant @tarcieri. In the mean-time it does appear that @kazcw and the whole cryptocorrosion project has gone silent, but I am not aware of any significant issues other than the build issue with Cranelift mentioned by @bjorn3 (hopefully something you can work around for now?), thus I suggest we wait for the SIMD work on |
Patching c2-chacha works. |
We just landed SSE support in the We'll hopefully be adding an AVX2 backend soon as well. |
I did a little hacking, for testing purposes. This lets me run comparative benchmarks (
As you can see, there's a long way to go to catch up. One possible part of this is that These benches include 8- and 12-round versions of ChaCha, which in my opinion make for excellent RNGs where security is less important. The code in the Another thing to think about is the title of this thread: and reducing dependencies (which, as we all know, is not a very useful metric but never-the-less one that many users bring up). This is a cut from the
Thanks for the optimisation work @tarcieri, but I am skeptical about switching to |
Thanks for looking into it. We can probably reverse the relationship between the We've also talked about operating on several blocks in parallel as part of adding an AVX2 backend. |
I noticed several constants being pulled from the |
Yup, we can potentially have both |
Also re: the reduced round variants i.e. ChaCha8/ChaCha12, yes, we can potentially add those, probably gated under an off-by-default Cargo feature. |
I eliminated the lazy_static dependency:
|
The API surface coupling |
IMO the more reasonable of those two dependency eliminations (if we were to stop at one) would be splaying the |
I think this is good enough! If anything, we could get rid of |
Thanks @kazcw for taking another look at this and removing the We have in the past duplicated the
I agree; actually this is less about "Cargo is broken" than "people's metrics of complexity are broken". At this point my preference is actually no further changes, except possibly the one @vks mentions: drop |
In fact I believe this is the wrong approach; rather we should copy the
|
@dhardy while you’re looking into that, you might consider using ChaCha12 over ChaCha20: https://eprint.iacr.org/2019/1492 ChaCha12 still provides 5 rounds of safety margin over the best known attack, whereas ChaCha20 provides 13 which is excessive when the best attack is 7 (and even then that attack doesn’t result in a catastrophic breakage). The cited paper suggests ChaCha8 which only provides a single round of safety margin. I think ChaCha12 is at a happy medium of enough rounds to feel confident it’s highly unlikely to be broken by future attacks, and improving the performance through a lower number of rounds. |
@tarcieri sounds great! But considering that is a security issue, I think it deserves its own thread. Also, it's not "while you're looking into that". |
Sure, I can open a separate issue (edit: opened #932) |
I'm back, with something actually relevant to this thread. I just released v0.3 of the
|
This is basically forked from #850: a request to reduce the number of dependencies. This issue is opened for discussion since previously it did not have much. Also see: #667, #789.
As can be seen, this crate has several dependencies of its own, and is also the only required dependency of
rand
(besidesgetrandom
,rand_core
and on some platformslibc
):Probable resolution: no change
We don't need to change anything.
Possible resolution: subsume dependencies
We could copy some/all dependencies up into
rand_chacha
. Note that currently c2-chacha has no other dependent crates, while ppv-lite86 has two (both only used by the powhasher miner, as far as I can tell).CC @kazcw
Other resolutions
We could revert back to HC-128 which has a fast implementation without use of SIMD intrinsics.
We could revert to the old ChaCha implementation or use the
chacha20
crate, however this would not be good for performance.The text was updated successfully, but these errors were encountered: