pub struct Poly { /* private fields */ }Expand description
Struct that holds a polynomial for a specific context.
Implementations§
Source§impl Poly
impl Poly
Sourcepub fn zero(ctx: &Arc<Context>, representation: Representation) -> Self
pub fn zero(ctx: &Arc<Context>, representation: Representation) -> Self
Creates a polynomial holding the constant 0.
Sourcepub unsafe fn allow_variable_time_computations(&mut self)
pub unsafe fn allow_variable_time_computations(&mut self)
Enable variable time computations when this polynomial is involved.
§Safety
By default, this is marked as unsafe, but is usually safe when only public data is processed.
Sourcepub fn disallow_variable_time_computations(&mut self)
pub fn disallow_variable_time_computations(&mut self)
Disable variable time computations when this polynomial is involved.
Sourcepub const fn representation(&self) -> &Representation
pub const fn representation(&self) -> &Representation
Current representation of the polynomial.
Sourcepub fn change_representation(&mut self, to: Representation)
pub fn change_representation(&mut self, to: Representation)
Change the representation of the underlying polynomial.
Sourcepub unsafe fn override_representation(&mut self, to: Representation)
pub unsafe fn override_representation(&mut self, to: Representation)
Override the internal representation to a given representation.
§Safety
Prefer the change_representation function to safely modify the
polynomial representation. If the to representation is NttShoup, the
coefficients are still computed correctly to avoid being in an unstable
state. If we override a polynomial with Shoup coefficients, we zeroize
them.
Sourcepub fn random<R: RngCore + CryptoRng>(
ctx: &Arc<Context>,
representation: Representation,
rng: &mut R,
) -> Self
pub fn random<R: RngCore + CryptoRng>( ctx: &Arc<Context>, representation: Representation, rng: &mut R, ) -> Self
Generate a random polynomial.
Sourcepub fn random_from_seed(
ctx: &Arc<Context>,
representation: Representation,
seed: <ChaCha8Rng as SeedableRng>::Seed,
) -> Self
pub fn random_from_seed( ctx: &Arc<Context>, representation: Representation, seed: <ChaCha8Rng as SeedableRng>::Seed, ) -> Self
Generate a random polynomial deterministically from a seed.
Sourcepub fn small<T: RngCore + CryptoRng>(
ctx: &Arc<Context>,
representation: Representation,
variance: usize,
rng: &mut T,
) -> Result<Self>
pub fn small<T: RngCore + CryptoRng>( ctx: &Arc<Context>, representation: Representation, variance: usize, rng: &mut T, ) -> Result<Self>
Generate a small polynomial and convert into the specified representation.
Returns an error if the variance does not belong to [1, …, 16].
Sourcepub fn coefficients(&self) -> ArrayView2<'_, u64>
pub fn coefficients(&self) -> ArrayView2<'_, u64>
Access the polynomial coefficients in RNS representation.
Sourcepub fn substitute(&self, i: &SubstitutionExponent) -> Result<Poly>
pub fn substitute(&self, i: &SubstitutionExponent) -> Result<Poly>
Substitute x by x^i in a polynomial. In PowerBasis representation, i can be any integer that is not a multiple of 2 * degree. In Ntt and NttShoup representation, i can be any odd integer that is not a multiple of 2 * degree.
Sourcepub unsafe fn create_constant_ntt_polynomial_with_lazy_coefficients_and_variable_time(
power_basis_coefficients: &[u64],
ctx: &Arc<Context>,
) -> Self
pub unsafe fn create_constant_ntt_polynomial_with_lazy_coefficients_and_variable_time( power_basis_coefficients: &[u64], ctx: &Arc<Context>, ) -> Self
Create a polynomial which can only be multiplied by a polynomial in NttShoup representation. All other operations may panic.
§Safety
This operation also creates a polynomial that allows variable time operations.
Sourcepub fn switch_down(&mut self) -> Result<()>
pub fn switch_down(&mut self) -> Result<()>
Modulus switch down the polynomial by dividing and rounding each coefficient by the last modulus in the chain, then drops the last modulus, as described in Algorithm 2 of https://eprint.iacr.org/2018/931.pdf.
Returns an error if there is no next context or if the representation is not PowerBasis.
Sourcepub fn switch_down_to(&mut self, context: &Arc<Context>) -> Result<()>
pub fn switch_down_to(&mut self, context: &Arc<Context>) -> Result<()>
Modulo switch down to a smaller context.
Returns an error if there is the provided context is not a child of the current context, or if the polynomial is not in PowerBasis representation.
Sourcepub fn switch(&self, switcher: &Switcher) -> Result<Poly>
pub fn switch(&self, switcher: &Switcher) -> Result<Poly>
Modulo switch to another context. The target context needs not to be related to the current context.
Sourcepub fn multiply_inverse_power_of_x(&mut self, power: usize) -> Result<()>
pub fn multiply_inverse_power_of_x(&mut self, power: usize) -> Result<()>
Multiplies a polynomial in PowerBasis representation by x^(-power).
Trait Implementations§
Source§impl AddAssign<&Poly> for Poly
impl AddAssign<&Poly> for Poly
Source§fn add_assign(&mut self, p: &Poly)
fn add_assign(&mut self, p: &Poly)
+= operation. Read moreSource§impl DeserializeWithContext for Poly
impl DeserializeWithContext for Poly
Source§impl MulAssign<&BigUint> for Poly
impl MulAssign<&BigUint> for Poly
Source§fn mul_assign(&mut self, p: &BigUint)
fn mul_assign(&mut self, p: &BigUint)
*= operation. Read moreSource§impl MulAssign<&Poly> for Poly
impl MulAssign<&Poly> for Poly
Source§fn mul_assign(&mut self, p: &Poly)
fn mul_assign(&mut self, p: &Poly)
*= operation. Read moreSource§impl SubAssign<&Poly> for Poly
impl SubAssign<&Poly> for Poly
Source§fn sub_assign(&mut self, p: &Poly)
fn sub_assign(&mut self, p: &Poly)
-= operation. Read moreSource§impl<'a> TryConvertFrom<&'a [BigUint]> for Poly
impl<'a> TryConvertFrom<&'a [BigUint]> for Poly
Source§fn try_convert_from<R>(
v: &'a [BigUint],
ctx: &Arc<Context>,
variable_time: bool,
representation: R,
) -> Result<Self>
fn try_convert_from<R>( v: &'a [BigUint], ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>
value into a polynomial with a specific context
and under a specific representation. The representation may optional and
be specified as None; this is useful for example when converting from
a value that encodes the representation (e.g., serialization, protobuf,
etc.).Source§impl<'a, const N: usize> TryConvertFrom<&'a [BigUint; N]> for Poly
impl<'a, const N: usize> TryConvertFrom<&'a [BigUint; N]> for Poly
Source§fn try_convert_from<R>(
v: &'a [BigUint; N],
ctx: &Arc<Context>,
variable_time: bool,
representation: R,
) -> Result<Self>
fn try_convert_from<R>( v: &'a [BigUint; N], ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>
value into a polynomial with a specific context
and under a specific representation. The representation may optional and
be specified as None; this is useful for example when converting from
a value that encodes the representation (e.g., serialization, protobuf,
etc.).Source§impl<'a> TryConvertFrom<&'a [i64]> for Poly
impl<'a> TryConvertFrom<&'a [i64]> for Poly
Source§fn try_convert_from<R>(
v: &'a [i64],
ctx: &Arc<Context>,
variable_time: bool,
representation: R,
) -> Result<Self>
fn try_convert_from<R>( v: &'a [i64], ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>
value into a polynomial with a specific context
and under a specific representation. The representation may optional and
be specified as None; this is useful for example when converting from
a value that encodes the representation (e.g., serialization, protobuf,
etc.).Source§impl<'a, const N: usize> TryConvertFrom<&'a [i64; N]> for Poly
impl<'a, const N: usize> TryConvertFrom<&'a [i64; N]> for Poly
Source§fn try_convert_from<R>(
v: &'a [i64; N],
ctx: &Arc<Context>,
variable_time: bool,
representation: R,
) -> Result<Self>
fn try_convert_from<R>( v: &'a [i64; N], ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>
value into a polynomial with a specific context
and under a specific representation. The representation may optional and
be specified as None; this is useful for example when converting from
a value that encodes the representation (e.g., serialization, protobuf,
etc.).Source§impl<'a> TryConvertFrom<&'a [u64]> for Poly
impl<'a> TryConvertFrom<&'a [u64]> for Poly
Source§fn try_convert_from<R>(
v: &'a [u64],
ctx: &Arc<Context>,
variable_time: bool,
representation: R,
) -> Result<Self>
fn try_convert_from<R>( v: &'a [u64], ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>
value into a polynomial with a specific context
and under a specific representation. The representation may optional and
be specified as None; this is useful for example when converting from
a value that encodes the representation (e.g., serialization, protobuf,
etc.).Source§impl<'a, const N: usize> TryConvertFrom<&'a [u64; N]> for Poly
impl<'a, const N: usize> TryConvertFrom<&'a [u64; N]> for Poly
Source§fn try_convert_from<R>(
v: &'a [u64; N],
ctx: &Arc<Context>,
variable_time: bool,
representation: R,
) -> Result<Self>
fn try_convert_from<R>( v: &'a [u64; N], ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>
value into a polynomial with a specific context
and under a specific representation. The representation may optional and
be specified as None; this is useful for example when converting from
a value that encodes the representation (e.g., serialization, protobuf,
etc.).Source§impl<'a> TryConvertFrom<&'a Vec<i64>> for Poly
impl<'a> TryConvertFrom<&'a Vec<i64>> for Poly
Source§fn try_convert_from<R>(
v: &'a Vec<i64>,
ctx: &Arc<Context>,
variable_time: bool,
representation: R,
) -> Result<Self>
fn try_convert_from<R>( v: &'a Vec<i64>, ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>
value into a polynomial with a specific context
and under a specific representation. The representation may optional and
be specified as None; this is useful for example when converting from
a value that encodes the representation (e.g., serialization, protobuf,
etc.).Source§impl<'a> TryConvertFrom<&'a Vec<u64>> for Poly
impl<'a> TryConvertFrom<&'a Vec<u64>> for Poly
Source§fn try_convert_from<R>(
v: &'a Vec<u64>,
ctx: &Arc<Context>,
variable_time: bool,
representation: R,
) -> Result<Self>
fn try_convert_from<R>( v: &'a Vec<u64>, ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>
value into a polynomial with a specific context
and under a specific representation. The representation may optional and
be specified as None; this is useful for example when converting from
a value that encodes the representation (e.g., serialization, protobuf,
etc.).Source§impl TryConvertFrom<ArrayBase<OwnedRepr<u64>, Dim<[usize; 2]>>> for Poly
impl TryConvertFrom<ArrayBase<OwnedRepr<u64>, Dim<[usize; 2]>>> for Poly
Source§fn try_convert_from<R>(
a: Array2<u64>,
ctx: &Arc<Context>,
variable_time: bool,
representation: R,
) -> Result<Self>
fn try_convert_from<R>( a: Array2<u64>, ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>
value into a polynomial with a specific context
and under a specific representation. The representation may optional and
be specified as None; this is useful for example when converting from
a value that encodes the representation (e.g., serialization, protobuf,
etc.).Source§impl TryConvertFrom<Vec<u64>> for Poly
impl TryConvertFrom<Vec<u64>> for Poly
Source§fn try_convert_from<R>(
v: Vec<u64>,
ctx: &Arc<Context>,
variable_time: bool,
representation: R,
) -> Result<Self>
fn try_convert_from<R>( v: Vec<u64>, ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>
value into a polynomial with a specific context
and under a specific representation. The representation may optional and
be specified as None; this is useful for example when converting from
a value that encodes the representation (e.g., serialization, protobuf,
etc.).impl Eq for Poly
impl StructuralPartialEq for Poly
Auto Trait Implementations§
impl Freeze for Poly
impl RefUnwindSafe for Poly
impl Send for Poly
impl Sync for Poly
impl Unpin for Poly
impl UnwindSafe for Poly
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