RustCrypto / stream-ciphers

Collection of stream cipher algorithms
255 stars 49 forks source link

chacha20: unify `quarter_round` in soft backend and xchacha #349

Closed oxarbitrage closed 4 months ago

oxarbitrage commented 5 months ago

The quarter_round function is duplicated inside xchacha. We can just use the soft backend version, which is the same code.

https://github.com/RustCrypto/stream-ciphers/pull/348#pullrequestreview-1958048341

tarcieri commented 5 months ago

It seems it was duplicated because soft isn't always available:

https://github.com/RustCrypto/stream-ciphers/actions/runs/8427139184/job/23077019314?pr=349#step:7:106

   Compiling chacha20 v0.10.0-pre (/project/chacha20)
error[E0432]: unresolved import `crate::backends::soft`
  --> chacha20/src/xchacha.rs:11:22
   |
11 | use crate::backends::soft::quarter_round;
   |                      ^^^^ could not find `soft` in `backends`

Perhaps it could be relocated somewhere it's always available. Failing other options, the toplevel of the module module of the crate is a choice.

oxarbitrage commented 5 months ago

Ok, i remember now the problem on using the soft backend version here and in xsalsa20. The soft backend is not compiled when we are in sse2 (or other) mode so is not available.

In salsa20 we made this available because we are using soft when we are in any no salsa20/20 variant. https://github.com/RustCrypto/stream-ciphers/pull/348/files#diff-7b9d071b5f65d5c089bd999ab817ac1b72b33a365f1ec2e0ced9ef43d6495efeR1

I guess we can make it available for xchacha as well but i am unsure if compiling the extra code will be acceptable.

oxarbitrage commented 5 months ago

Perhaps it could be relocated somewhere it's always available. Failing other options, the toplevel of the module is a choice.

Ok!

tarcieri commented 5 months ago

Now I'm noticing we should really get #333 landed first

tarcieri commented 4 months ago

@oxarbitrage need to re-evaluate this PR now that #333 has been merged

tarcieri commented 4 months ago

Thanks!