Debian Codegraph @

debian/rust-vendor/keccak/src/backends.rs

raw
1 //! Keccak backend implementations.
2 use crate::consts::F1600_ROUNDS;
3 use crate::types::*;
4 #[cfg(feature = "parallel")]
5 use hybrid_array::ArraySize;
6
7 #[cfg(all(target_arch = "aarch64", not(target_abi = "softfloat")))]
8 pub(crate) mod aarch64_sha3;
9 #[cfg(any(
10 keccak_backend = "simd128",
11 keccak_backend = "simd256",
12 keccak_backend = "simd512",
13 ))]
14 pub(crate) mod simd;
15 pub(crate) mod soft;
16
17 /// Trait used to define a closure which operates over Keccak backends.
18 pub trait BackendClosure {
19 /// Execute closure with the provided backend.
20 fn call_once<B: Backend>(self);
21 }
22
23 /// Trait implemented by a Keccak backend.
24 pub trait Backend {
25 /// Parallelism width supported by the backend for [`State1600`].
26 #[cfg(feature = "parallel")]
27 type ParSize1600: ArraySize;
28
29 /// Get scalar `p1600` function with the specified number of rounds.
30 ///
31 /// # Panics
32 /// If `ROUNDS` is bigger than [`F1600_ROUNDS`].
33 #[must_use]
34 fn get_p1600<const ROUNDS: usize>() -> Fn1600;
35
36 /// Get parallel `p1600` function with the specified number of rounds.
37 ///
38 /// # Panics
39 /// If `ROUNDS` is bigger than [`F1600_ROUNDS`].
40 #[cfg(feature = "parallel")]
41 #[inline]
42 #[must_use]
43 fn get_par_p1600<const ROUNDS: usize>() -> ParFn1600<Self> {
44 |par_state| par_state.iter_mut().for_each(Self::get_p1600::<ROUNDS>())
45 }
46
47 /// Get scalar `f1600` function.
48 #[must_use]
49 fn get_f1600() -> Fn1600 {
50 Self::get_p1600::<F1600_ROUNDS>()
51 }
52
53 /// Get parallel `f1600` function.
54 #[cfg(feature = "parallel")]
55 #[inline]
56 #[must_use]
57 fn get_par_f1600() -> ParFn1600<Self> {
58 Self::get_par_p1600::<F1600_ROUNDS>()
59 }
60 }