-
Notifications
You must be signed in to change notification settings - Fork 81
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 as a possible addition to examples area #328
Comments
I believe that issue isn't about bit rotation, but lane rotation. |
Bit rotation for integers (as is needed for chacha) would be reasonable — AFAIK it's only really supported by the AMD's XOP instruction set extension (admittedly that's a deprecated), but it is a method integers have, so I'm honestly a little surprised we don't already have something here. |
bit rotation of vectors can be done using bit rotation of vectors is also supported in PowerISA (both in VMX/AltiVec and in SimpleV). |
Are bits generally rotated independently in each lane, or all together by the same amount? Just curious--I'm not sure this actually matters for the API, since independent rotation can be emulated with select. |
independent rotation amounts are common in cryptography |
All lanes are rotated by the same amount for chacha. |
yep that's correct. I didn't see an api for bit-rotation, so I converted back into an array for that operation, though as programmerjake mentioned, there are specific instructions for bit rotation on architectures like AVX. The RustCrypto library uses a different trick though, involving |
Yes, the shuffle works for the part of the algorithm that needs rotation by a 16 and by 8, but other parts require rotation by 12 bits, and by 7 bits (it's 16, 12, 8, 7). In those cases, the RustCrypto implementation uses shift and or (well, xor). In any case, as to the comment about this being a potential addition to our examples: while it's a simple algorithm (and one I've implemented myself multiple times), I don't think we want to maintain any cryptography in our examples. |
bitwise rotation is tracked by #14 |
I wrote a portable-simd enabled implementation of the chacha20 stream cipher, as a partial rewrite of Rust-Crypto to play around with portable simd and const generic techniques. It might be a useful base for a short example; the cipher is extremely simple, but also documents an application of bit-rotation, for if and when #216 is resolved.
My implementation: https://github.com/thor314/tkcrypto/blob/main/src/chacha.rs#L217
Ported from: https://github.com/RustCrypto/stream-ciphers/tree/master/chacha20/src/backends
If this seems a worthwhile example, I'll repackage the example with further comments and submit a PR.
The text was updated successfully, but these errors were encountered: