ethrex_crypto/blake2f/
mod.rs1#[cfg(all(feature = "std", target_arch = "aarch64"))]
2mod aarch64;
3mod portable;
4#[cfg(all(feature = "std", any(target_arch = "x86", target_arch = "x86_64")))]
5mod x86_64;
6
7#[cfg(feature = "std")]
8use std::sync::LazyLock;
9
10#[cfg(feature = "std")]
11type Blake2Func = fn(usize, &mut [u64; 8], &[u64; 16], &[u64; 2], bool);
12
13#[cfg(feature = "std")]
14static BLAKE2_FUNC: LazyLock<Blake2Func> = LazyLock::new(|| {
15 #[cfg(target_arch = "aarch64")]
16 if std::arch::is_aarch64_feature_detected!("neon")
17 && std::arch::is_aarch64_feature_detected!("sha3")
18 {
19 return self::aarch64::blake2b_f;
20 }
21
22 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
23 if std::arch::is_x86_feature_detected!("avx2") {
24 return self::x86_64::blake2b_f;
25 }
26
27 self::portable::blake2b_f
28});
29
30#[cfg(feature = "std")]
31pub fn blake2b_f(rounds: usize, h: &mut [u64; 8], m: &[u64; 16], t: &[u64; 2], f: bool) {
32 BLAKE2_FUNC(rounds, h, m, t, f)
33}
34
35#[cfg(not(feature = "std"))]
36pub fn blake2b_f(rounds: usize, h: &mut [u64; 8], m: &[u64; 16], t: &[u64; 2], f: bool) {
37 self::portable::blake2b_f(rounds, h, m, t, f)
38}