Poly

Struct Poly 

Source
pub struct Poly { /* private fields */ }
Expand description

Struct that holds a polynomial for a specific context.

Implementations§

Source§

impl Poly

Source

pub fn zero(ctx: &Arc<Context>, representation: Representation) -> Self

Creates a polynomial holding the constant 0.

Source

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.

Source

pub fn disallow_variable_time_computations(&mut self)

Disable variable time computations when this polynomial is involved.

Source

pub const fn representation(&self) -> &Representation

Current representation of the polynomial.

Source

pub fn change_representation(&mut self, to: Representation)

Change the representation of the underlying polynomial.

Source

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.

Source

pub fn random<R: RngCore + CryptoRng>( ctx: &Arc<Context>, representation: Representation, rng: &mut R, ) -> Self

Generate a random polynomial.

Source

pub fn random_from_seed( ctx: &Arc<Context>, representation: Representation, seed: <ChaCha8Rng as SeedableRng>::Seed, ) -> Self

Generate a random polynomial deterministically from a seed.

Source

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].

Source

pub fn coefficients(&self) -> ArrayView2<'_, u64>

Access the polynomial coefficients in RNS representation.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn scale(&self, scaler: &Scaler) -> Result<Poly>

Scale a polynomial using a scaler.

Source

pub fn ctx(&self) -> &Arc<Context>

Returns the context of the underlying polynomial

Source

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 Add<&Poly> for &Poly

Source§

type Output = Poly

The resulting type after applying the + operator.
Source§

fn add(self, p: &Poly) -> Poly

Performs the + operation. Read more
Source§

impl Add for Poly

Source§

type Output = Poly

The resulting type after applying the + operator.
Source§

fn add(self, p: Poly) -> Poly

Performs the + operation. Read more
Source§

impl AddAssign<&Poly> for Poly

Source§

fn add_assign(&mut self, p: &Poly)

Performs the += operation. Read more
Source§

impl AsMut<Poly> for Poly

Source§

fn as_mut(&mut self) -> &mut Poly

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<Poly> for Poly

Source§

fn as_ref(&self) -> &Poly

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Poly

Source§

fn clone(&self) -> Poly

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Poly

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Poly

Source§

fn default() -> Poly

Returns the “default value” for a type. Read more
Source§

impl DeserializeWithContext for Poly

Source§

type Error = Error

The type of error returned.
Source§

type Context = Context

The type of context.
Source§

fn from_bytes(bytes: &[u8], ctx: &Arc<Context>) -> Result<Self, Self::Error>

Attempt to deserialize from a vector of bytes
Source§

impl From<&Poly> for Vec<BigUint>

Source§

fn from(p: &Poly) -> Self

Converts to this type from the input type.
Source§

impl From<&Poly> for Vec<u64>

Source§

fn from(p: &Poly) -> Self

Converts to this type from the input type.
Source§

impl Mul<&BigUint> for &Poly

Source§

type Output = Poly

The resulting type after applying the * operator.
Source§

fn mul(self, p: &BigUint) -> Poly

Performs the * operation. Read more
Source§

impl Mul<&Poly> for &BigUint

Source§

type Output = Poly

The resulting type after applying the * operator.
Source§

fn mul(self, p: &Poly) -> Poly

Performs the * operation. Read more
Source§

impl Mul<&Poly> for &Poly

Source§

type Output = Poly

The resulting type after applying the * operator.
Source§

fn mul(self, p: &Poly) -> Poly

Performs the * operation. Read more
Source§

impl MulAssign<&BigUint> for Poly

Source§

fn mul_assign(&mut self, p: &BigUint)

Performs the *= operation. Read more
Source§

impl MulAssign<&Poly> for Poly

Source§

fn mul_assign(&mut self, p: &Poly)

Performs the *= operation. Read more
Source§

impl Neg for &Poly

Source§

type Output = Poly

The resulting type after applying the - operator.
Source§

fn neg(self) -> Poly

Performs the unary - operation. Read more
Source§

impl Neg for Poly

Source§

type Output = Poly

The resulting type after applying the - operator.
Source§

fn neg(self) -> Poly

Performs the unary - operation. Read more
Source§

impl PartialEq for Poly

Source§

fn eq(&self, other: &Poly) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Poly

Source§

fn to_bytes(&self) -> Vec<u8>

Serialize Self into a vector of bytes.
Source§

impl Sub<&Poly> for &Poly

Source§

type Output = Poly

The resulting type after applying the - operator.
Source§

fn sub(self, p: &Poly) -> Poly

Performs the - operation. Read more
Source§

impl SubAssign<&Poly> for Poly

Source§

fn sub_assign(&mut self, p: &Poly)

Performs the -= operation. Read more
Source§

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>

Attempt to convert the 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

Source§

fn try_convert_from<R>( v: &'a [BigUint; N], ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>

Attempt to convert the 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

Source§

fn try_convert_from<R>( v: &'a [i64], ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>

Attempt to convert the 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

Source§

fn try_convert_from<R>( v: &'a [i64; N], ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>

Attempt to convert the 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

Source§

fn try_convert_from<R>( v: &'a [u64], ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>

Attempt to convert the 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

Source§

fn try_convert_from<R>( v: &'a [u64; N], ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>

Attempt to convert the 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

Source§

fn try_convert_from<R>( v: &'a Vec<i64>, ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>

Attempt to convert the 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

Source§

fn try_convert_from<R>( v: &'a Vec<u64>, ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>

Attempt to convert the 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

Source§

fn try_convert_from<R>( a: Array2<u64>, ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>

Attempt to convert the 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

Source§

fn try_convert_from<R>( v: Vec<u64>, ctx: &Arc<Context>, variable_time: bool, representation: R, ) -> Result<Self>

Attempt to convert the 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 Zeroize for Poly

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

impl Eq for Poly

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V