Trait scuttlebutt::ring::FiniteRing
source · [−]pub trait FiniteRing: 'static + Clone + Copy + Send + Sync + Default + Debug + Eq + PartialEq + Hash + Sized + ConstantTimeEq + ConditionallySelectable + AddAssign<Self> + SubAssign<Self> + MulAssign<Self> + Add<Self, Output = Self> + Sub<Self, Output = Self> + Mul<Self, Output = Self> + Neg<Output = Self> + Sum + Product + Zero + One + CanonicalSerialize {
const ZERO: Self;
const ONE: Self;
fn from_uniform_bytes(x: &[u8; 16]) -> Self;
fn random<R: Rng + ?Sized>(rng: &mut R) -> Self;
fn random_nonzero<R: Rng + ?Sized>(rng: &mut R) -> Self { ... }
fn pow(&self, n: u128) -> Self { ... }
fn pow_bounded(&self, n: u128, bound: u16) -> Self { ... }
fn pow_var_time(&self, n: u128) -> Self { ... }
}
Expand description
Types that implement this trait are finite rings.
Required Associated Constants
Required Methods
sourcefn from_uniform_bytes(x: &[u8; 16]) -> Self
fn from_uniform_bytes(x: &[u8; 16]) -> Self
Construct an element from the given uniformly chosen random bytes.
Provided Methods
sourcefn random_nonzero<R: Rng + ?Sized>(rng: &mut R) -> Self
fn random_nonzero<R: Rng + ?Sized>(rng: &mut R) -> Self
Generate a random non-zero element.
Compute self
to the power of n
.
Constant-Time
This function will execute in constant-time, regardless of n
’s value.
sourcefn pow_bounded(&self, n: u128, bound: u16) -> Self
fn pow_bounded(&self, n: u128, bound: u16) -> Self
Compute self
to the power of n
, where n
is guaranteed to be <= 2^bound
.
Constant-Time
This function is constant time in n
, but not constant time in bound
.
sourcefn pow_var_time(&self, n: u128) -> Self
fn pow_var_time(&self, n: u128) -> Self
Compute self
to the power of n
, in non-constant time.