RustCrypto / block-ciphers

Collection of block cipher algorithms written in pure Rust
678 stars 130 forks source link

kuznyechik: use `const fn` to compute the fused tables #448

Closed newpavlov closed 2 months ago

newpavlov commented 3 months ago

Right now the tables are included as binary blobs which not only make it harder to review them, but also increase size of the crate. Ideally, the tables should be computed at compile time based on the S-box constant.

valaphee commented 2 months ago

I have a version which uses const fns to generate the tables, but it takes a considerable time to calculate them, and requires the #[allow(long_running_const_eval)] lint.

Constant time evaluation of functions seem to take way longer compared to runtime evaluation. (+12 seconds)

newpavlov commented 2 months ago

Can you share the code? I guess one potential alternative is to use build scripts, which should be a fair bit faster than const eval, but it may impact total compilation time negatively.

valaphee commented 2 months ago

Sure, https://gist.github.com/valaphee/b7e32e3208bcdebdc97a7669187f487a (const version can't have for-loop in stable rust)

Hmm probably still way faster then const, I could also switch to a lookup table version of mul gf256 (which is probably taking the most time)

newpavlov commented 2 months ago

@valaphee Based on your code I created #451. The tables have helped, but we still really close to the default const eval limit.