poseidon_parameters/alpha.rs
1/// The exponent in `Sbox(x) = x^\alpha`.
2#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3pub enum Alpha {
4 /// A positive exponent $x^{alpha}$.
5 Exponent(u32),
6 /// 1/x
7 Inverse,
8}
9
10impl Alpha {
11 /// Return the memory representation of alpha as a byte array in little-endian byte order.
12 pub fn to_bytes_le(&self) -> [u8; 4] {
13 match self {
14 Alpha::Exponent(exp) => exp.to_le_bytes(),
15 Alpha::Inverse => (-1i32).to_le_bytes(),
16 }
17 }
18}
19
20impl From<Alpha> for f64 {
21 fn from(alpha: Alpha) -> Self {
22 match alpha {
23 Alpha::Exponent(exp) => exp as f64,
24 Alpha::Inverse => -1.0,
25 }
26 }
27}