Exposing blake2 compression function
Hi,
Would it be in scope to expose the compression function for blake2?
The usecase I have in mind is to replace this particular function: https://github.com/bluealloy/revm/blob/b8396776a9d53e1553c0396c96a14b461cda17ce/crates/precompile/src/blake2.rs#L55
We expose the compression functions in the sha2 crate so IMO this is conceptually fine
Re using blake2 in general -- Is this issue still relevant: https://github.com/RustCrypto/hashes/issues/407 ?
@kevaundray we've long planned to completely replace the implementation: https://github.com/RustCrypto/hashes/pull/228.
Unfortunately that PR has long gone by the wayside.
Hi,
I'm working on a project that requires the compress blake2s function. We currently have an ad hoc Blake2s implementation but would like to remove it in favor of depending on this crate instead. I've been working on how to expose the low-level blake2s functions, and would like to share what I've come up with so far:
We could add two new modules, blake2s and blake2b, that implement the low-level cryptographic primitives of Blake2. These modules would be public.
pub mod blake2s {
pub fn initial_state(
salt: &[u8],
persona: &[u8],
key_size: usize,
output_size: usize,
) -> [u32; 8];
pub fn compress<const ROUNDS: usize>(
state: [u32; 8],
message: &[u32; 16],
t: u64,
f0: u32,
f1: u32,
) -> [u32; 8]
}
These modules could be defined automatically by a macro if we want to remove code duplication.
blake2_impl!(
blake2s, // Module name
u32, // Word
16, // R1
12, // R1
8, // R2
7, // R3
BLAKE2S_IV, // IV
);
Then, those modules can be used directly in the core structure (block API). We would need to adapt the current macros to call the functions from the inner module instead.
// Analogue to current `blake2_impl` macro
blake2_core_impl!(
Blake2sVarCore, // Struct name
"Blake2s", // Algorithm name
blake2s // Module to take the implementation from
"Blake2s instance with a variable output.",
"Blake2s instance with a fixed output.",
);
I haven't worked out the specifics of the macro signatures yet, so it might change once I finish implementing them. I will continue to work on this, but please let me know if you have any thoughts on the idea!
Cheers,
For me, this would be great! Though I defer to @tarcieri on whether its something they would be interested in being upstreamed.
Maybe also check PR 704