pub struct Modulus { /* private fields */ }Expand description
Structure encapsulating an integer modulus up to 62 bits.
Implementations§
Source§impl Modulus
impl Modulus
Sourcepub const fn add(&self, a: u64, b: u64) -> u64
pub const fn add(&self, a: u64, b: u64) -> u64
Performs the modular addition of a and b in constant time. Aborts if a >= p or b >= p in debug mode.
Sourcepub const unsafe fn add_vt(&self, a: u64, b: u64) -> u64
pub const unsafe fn add_vt(&self, a: u64, b: u64) -> u64
Performs the modular addition of a and b in variable time. Aborts if a >= p or b >= p in debug mode.
§Safety
This function is not constant time and its timing may reveal information about the values being added.
Sourcepub const fn sub(&self, a: u64, b: u64) -> u64
pub const fn sub(&self, a: u64, b: u64) -> u64
Performs the modular subtraction of a and b in constant time. Aborts if a >= p or b >= p in debug mode.
Sourcepub const fn mul(&self, a: u64, b: u64) -> u64
pub const fn mul(&self, a: u64, b: u64) -> u64
Performs the modular multiplication of a and b in constant time. Aborts if a >= p or b >= p in debug mode.
Sourcepub const fn mul_opt(&self, a: u64, b: u64) -> u64
pub const fn mul_opt(&self, a: u64, b: u64) -> u64
Optimized modular multiplication of a and b in constant time.
Aborts if a >= p or b >= p in debug mode.
Sourcepub const fn neg(&self, a: u64) -> u64
pub const fn neg(&self, a: u64) -> u64
Modular negation in constant time.
Aborts if a >= p in debug mode.
Sourcepub const fn shoup(&self, a: u64) -> u64
pub const fn shoup(&self, a: u64) -> u64
Compute the Shoup representation of a.
Aborts if a >= p in debug mode.
Sourcepub const fn mul_shoup(&self, a: u64, b: u64, b_shoup: u64) -> u64
pub const fn mul_shoup(&self, a: u64, b: u64, b_shoup: u64) -> u64
Shoup multiplication of a and b in constant time.
Aborts if b >= p or b_shoup != shoup(b) in debug mode.
Sourcepub const fn lazy_mul_shoup(&self, a: u64, b: u64, b_shoup: u64) -> u64
pub const fn lazy_mul_shoup(&self, a: u64, b: u64, b_shoup: u64) -> u64
Lazy Shoup multiplication of a and b in constant time. The output is in the interval [0, 2 * p).
Aborts if b >= p or b_shoup != shoup(b) in debug mode.
Sourcepub fn add_vec(&self, a: &mut [u64], b: &[u64])
pub fn add_vec(&self, a: &mut [u64], b: &[u64])
Modular addition of vectors in place in constant time.
Aborts if a and b differ in size, and if any of their values is >= p in debug mode.
Sourcepub unsafe fn add_vec_vt(&self, a: &mut [u64], b: &[u64])
pub unsafe fn add_vec_vt(&self, a: &mut [u64], b: &[u64])
Modular addition of vectors in place in variable time. Aborts if a and b differ in size, and if any of their values is >= p in debug mode.
§Safety
This function is not constant time and its timing may reveal information about the values being added.
Sourcepub fn sub_vec(&self, a: &mut [u64], b: &[u64])
pub fn sub_vec(&self, a: &mut [u64], b: &[u64])
Modular subtraction of vectors in place in constant time.
Aborts if a and b differ in size, and if any of their values is >= p in debug mode.
Sourcepub unsafe fn sub_vec_vt(&self, a: &mut [u64], b: &[u64])
pub unsafe fn sub_vec_vt(&self, a: &mut [u64], b: &[u64])
Modular subtraction of vectors in place in variable time. Aborts if a and b differ in size, and if any of their values is >= p in debug mode.
§Safety
This function is not constant time and its timing may reveal information about the values being subtracted.
Sourcepub fn mul_vec(&self, a: &mut [u64], b: &[u64])
pub fn mul_vec(&self, a: &mut [u64], b: &[u64])
Modular multiplication of vectors in place in constant time.
Aborts if a and b differ in size, and if any of their values is >= p in debug mode.
Sourcepub fn scalar_mul_vec(&self, a: &mut [u64], b: u64)
pub fn scalar_mul_vec(&self, a: &mut [u64], b: u64)
Modular scalar multiplication of vectors in place in constant time.
Aborts if any of the values in a is >= p in debug mode.
Sourcepub unsafe fn scalar_mul_vec_vt(&self, a: &mut [u64], b: u64)
pub unsafe fn scalar_mul_vec_vt(&self, a: &mut [u64], b: u64)
Modular scalar multiplication of vectors in place in variable time. Aborts if any of the values in a is >= p in debug mode.
§Safety
This function is not constant time and its timing may reveal information about the values being multiplied.
Sourcepub unsafe fn mul_vec_vt(&self, a: &mut [u64], b: &[u64])
pub unsafe fn mul_vec_vt(&self, a: &mut [u64], b: &[u64])
Modular multiplication of vectors in place in variable time. Aborts if a and b differ in size, and if any of their values is >= p in debug mode.
§Safety
This function is not constant time and its timing may reveal information about the values being subtracted.
Sourcepub fn shoup_vec(&self, a: &[u64]) -> Vec<u64>
pub fn shoup_vec(&self, a: &[u64]) -> Vec<u64>
Compute the Shoup representation of a vector.
Aborts if any of the values of the vector is >= p in debug mode.
Sourcepub fn mul_shoup_vec(&self, a: &mut [u64], b: &[u64], b_shoup: &[u64])
pub fn mul_shoup_vec(&self, a: &mut [u64], b: &[u64], b_shoup: &[u64])
Shoup modular multiplication of vectors in place in constant time.
Aborts if a and b differ in size, and if any of their values is >= p in debug mode.
Sourcepub unsafe fn mul_shoup_vec_vt(&self, a: &mut [u64], b: &[u64], b_shoup: &[u64])
pub unsafe fn mul_shoup_vec_vt(&self, a: &mut [u64], b: &[u64], b_shoup: &[u64])
Shoup modular multiplication of vectors in place in variable time. Aborts if a and b differ in size, and if any of their values is >= p in debug mode.
§Safety
This function is not constant time and its timing may reveal information about the values being multiplied.
Sourcepub fn reduce_vec(&self, a: &mut [u64])
pub fn reduce_vec(&self, a: &mut [u64])
Reduce a vector in place in constant time.
Sourcepub unsafe fn center_vec_vt(&self, a: &[u64]) -> Vec<i64>
pub unsafe fn center_vec_vt(&self, a: &[u64]) -> Vec<i64>
Center a vector in variable time.
§Safety
This function is not constant time and its timing may reveal information about the values being centered.
Sourcepub unsafe fn reduce_vec_vt(&self, a: &mut [u64])
pub unsafe fn reduce_vec_vt(&self, a: &mut [u64])
Reduce a vector in place in variable time.
§Safety
This function is not constant time and its timing may reveal information about the values being reduced.
Sourcepub fn reduce_vec_i64(&self, a: &[i64]) -> Vec<u64>
pub fn reduce_vec_i64(&self, a: &[i64]) -> Vec<u64>
Reduce a vector in place in constant time.
Sourcepub unsafe fn reduce_vec_i64_vt(&self, a: &[i64]) -> Vec<u64>
pub unsafe fn reduce_vec_i64_vt(&self, a: &[i64]) -> Vec<u64>
Reduce a vector in place in variable time.
§Safety
This function is not constant time and its timing may reveal information about the values being reduced.
Sourcepub fn reduce_vec_new(&self, a: &[u64]) -> Vec<u64>
pub fn reduce_vec_new(&self, a: &[u64]) -> Vec<u64>
Reduce a vector in constant time.
Sourcepub unsafe fn reduce_vec_new_vt(&self, a: &[u64]) -> Vec<u64>
pub unsafe fn reduce_vec_new_vt(&self, a: &[u64]) -> Vec<u64>
Reduce a vector in variable time.
§Safety
This function is not constant time and its timing may reveal information about the values being reduced.
Sourcepub fn neg_vec(&self, a: &mut [u64])
pub fn neg_vec(&self, a: &mut [u64])
Modular negation of a vector in place in constant time.
Aborts if any of the values in the vector is >= p in debug mode.
Sourcepub unsafe fn neg_vec_vt(&self, a: &mut [u64])
pub unsafe fn neg_vec_vt(&self, a: &mut [u64])
Modular negation of a vector in place in variable time. Aborts if any of the values in the vector is >= p in debug mode.
§Safety
This function is not constant time and its timing may reveal information about the values being negated.
Sourcepub fn pow(&self, a: u64, n: u64) -> u64
pub fn pow(&self, a: u64, n: u64) -> u64
Modular exponentiation in variable time.
Aborts if a >= p or n >= p in debug mode.
Sourcepub fn inv(&self, a: u64) -> Option<u64>
pub fn inv(&self, a: u64) -> Option<u64>
Modular inversion in variable time.
Returns None if p is not prime or a = 0. Aborts if a >= p in debug mode.
Sourcepub const fn reduce_u128(&self, a: u128) -> u64
pub const fn reduce_u128(&self, a: u128) -> u64
Modular reduction of a u128 in constant time.
Sourcepub const unsafe fn reduce_u128_vt(&self, a: u128) -> u64
pub const unsafe fn reduce_u128_vt(&self, a: u128) -> u64
Modular reduction of a u128 in variable time.
§Safety
This function is not constant time and its timing may reveal information about the value being reduced.
Sourcepub const unsafe fn reduce_vt(&self, a: u64) -> u64
pub const unsafe fn reduce_vt(&self, a: u64) -> u64
Modular reduction of a u64 in variable time.
§Safety
This function is not constant time and its timing may reveal information about the value being reduced.
Sourcepub const fn reduce_opt_u128(&self, a: u128) -> u64
pub const fn reduce_opt_u128(&self, a: u128) -> u64
Optimized modular reduction of a u128 in constant time.
Sourcepub const fn reduce_opt(&self, a: u64) -> u64
pub const fn reduce_opt(&self, a: u64) -> u64
Optimized modular reduction of a u64 in constant time.
Sourcepub const unsafe fn reduce_opt_vt(&self, a: u64) -> u64
pub const unsafe fn reduce_opt_vt(&self, a: u64) -> u64
Optimized modular reduction of a u64 in variable time.
§Safety
This function is not constant time and its timing may reveal information about the value being reduced.
Sourcepub const fn lazy_reduce_u128(&self, a: u128) -> u64
pub const fn lazy_reduce_u128(&self, a: u128) -> u64
Lazy modular reduction of a in constant time. The output is in the interval [0, 2 * p).
Sourcepub const fn lazy_reduce(&self, a: u64) -> u64
pub const fn lazy_reduce(&self, a: u64) -> u64
Lazy modular reduction of a in constant time. The output is in the interval [0, 2 * p).
Sourcepub const fn lazy_reduce_opt_u128(&self, a: u128) -> u64
pub const fn lazy_reduce_opt_u128(&self, a: u128) -> u64
Lazy optimized modular reduction of a in constant time. The output is in the interval [0, 2 * p).
Aborts if the input is >= p ^ 2 in debug mode.
Sourcepub fn lazy_reduce_vec(&self, a: &mut [u64])
pub fn lazy_reduce_vec(&self, a: &mut [u64])
Lazy modular reduction of a vector in constant time. The output coefficients are in the interval [0, 2 * p).
Sourcepub fn random_vec<R: RngCore + CryptoRng>(
&self,
size: usize,
rng: &mut R,
) -> Vec<u64>
pub fn random_vec<R: RngCore + CryptoRng>( &self, size: usize, rng: &mut R, ) -> Vec<u64>
Returns a random vector.
Sourcepub const fn serialization_length(&self, size: usize) -> usize
pub const fn serialization_length(&self, size: usize) -> usize
Length of the serialization of a vector of size size.
Panics if the size is not a multiple of 8.
Sourcepub fn serialize_vec(&self, a: &[u64]) -> Vec<u8> ⓘ
pub fn serialize_vec(&self, a: &[u64]) -> Vec<u8> ⓘ
Serialize a vector of elements of length a multiple of 8.
Panics if the length of the vector is not a multiple of 8.
Sourcepub fn deserialize_vec(&self, b: &[u8]) -> Vec<u64>
pub fn deserialize_vec(&self, b: &[u8]) -> Vec<u64>
Deserialize a vector of bytes into a vector of elements mod p.
Trait Implementations§
impl Eq for Modulus
Auto Trait Implementations§
impl Freeze for Modulus
impl RefUnwindSafe for Modulus
impl Send for Modulus
impl Sync for Modulus
impl Unpin for Modulus
impl UnwindSafe for Modulus
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more