p3_symmetric/permutation.rs
1/// A permutation in the mathematical sense.
2pub trait Permutation<T: Clone>: Clone + Sync {
3 // The methods permute, permute_mut are defined in a circular manner
4 // so you only need to implement one of them and will get the other
5 // for free. If you implement neither, this will cause a run time
6 // error.
7
8 #[inline(always)]
9 fn permute(&self, mut input: T) -> T {
10 self.permute_mut(&mut input);
11 input
12 }
13
14 fn permute_mut(&self, input: &mut T) {
15 *input = self.permute(input.clone());
16 }
17}
18
19/// A permutation thought to be cryptographically secure, in the sense that it is thought to be
20/// difficult to distinguish (in a nontrivial way) from a random permutation.
21pub trait CryptographicPermutation<T: Clone>: Permutation<T> {}