keccak: extract Keccak1600 struct with CPU feature detection#107
keccak: extract Keccak1600 struct with CPU feature detection#107
Keccak1600 struct with CPU feature detection#107Conversation
Extracts a struct to hold the state for Keccak-p1600/Keccak-f1600, along with a CPU feature detection `InitToken` which is queried at the time the state is initialized. The previous `p1600`/`f1600` functions with CPU feature detection support have been factored onto this struct, leaving the software implementation available unconditionally as part of the public API, and avoiding performing CPU feature detection on each invocation of the permutation. It looks like it should be possible to slot a struct like this into something like `Sha3HasherCore` in place of its current `state` array.
2c5b8f6 to
55ba965
Compare
|
Though this is ARMv8-only for now (but still works even in a soft-only config), there are assembly implementations of other backends we could potentially support from XKCP where the current ASM is sourced from, like one for AVX2: https://github.com/XKCP/XKCP/blob/716f007dd73ef28d357b8162173646be574ad1b7/lib/low/KeccakP-1600/AVX2/KeccakP-1600-AVX2.s Though yes, ideally we would have intrinsics (and if we did, could potentially get rid of the |
c68f815 to
f44516c
Compare
8866aec to
83643f0
Compare
There was a problem hiding this comment.
With this struct you still branch on each processed block, which prevents potential optimizations like using permuted data in registers to perform XOR without round-tripping through stack. As I wrote in the previous issue we probably need a callback-based API similar to the backend traits in cipher (but I think we could simplify it significantly).
But I guess this PR is a fine starting point.
|
|
||
| /// Extract the state array. | ||
| #[must_use] | ||
| pub fn into_inner(self) -> [u64; PLEN] { |
There was a problem hiding this comment.
I am not sure it's worth to duplicate the From impl with this method.
| /// ```toml | ||
| /// # In .cargo/config.toml | ||
| /// [build] | ||
| /// rustflags = ['--cfg', 'keccak_backend="armv8_asm"'] |
There was a problem hiding this comment.
It's probably better to put this to the crate docs/README.
Extracts a struct to hold the state for Keccak-p1600/Keccak-f1600, along with a CPU feature detection
InitTokenwhich is queried at the time the state is initialized.The previous
p1600/f1600functions with CPU feature detection support have been factored onto this struct, leaving the software implementation available unconditionally as part of the public API, and avoiding performing CPU feature detection on each invocation of the permutation.It looks like it should be possible to slot a struct like this into something like
Sha3HasherCorein place of its currentstatearray.