Polynomial

Struct Polynomial 

Source
pub struct Polynomial<M: Modulus> {
    pub coeffs: Vec<u32>,
    /* private fields */
}
Expand description

A polynomial in a ring R_Q = Z_Q[X]/(X^N + 1)

Fields§

§coeffs: Vec<u32>

Coefficients of the polynomial, stored in standard representation

Implementations§

Source§

impl<M: NttModulus> Polynomial<M>

Extension methods for Polynomial

Source

pub fn ntt_inplace(&mut self) -> Result<()>

Convert polynomial to NTT domain

Source

pub fn from_ntt_inplace(&mut self) -> Result<()>

Convert polynomial from NTT domain

Source

pub fn ntt_mul(&self, other: &Self) -> Self

Pointwise multiplication in NTT domain

Both polynomials must already be in NTT domain. For Dilithium: inputs/output in standard domain (post-NTT) For Kyber: inputs/output in Montgomery domain

Source§

impl<M: Modulus> Polynomial<M>

Source

pub fn zero() -> Self

Creates a new polynomial with all coefficients set to zero

Source

pub fn from_coeffs(coeffs_slice: &[u32]) -> Result<Self>

Creates a polynomial from a slice of coefficients

Source

pub fn degree() -> usize

Returns the degree N of the polynomial

Source

pub fn modulus_q() -> u32

Returns the modulus Q for coefficient arithmetic

Source

pub fn as_coeffs_slice(&self) -> &[u32]

Returns a slice view of the coefficients

Source

pub fn as_mut_coeffs_slice(&mut self) -> &mut [u32]

Returns a mutable slice view of the coefficients

Source

pub fn add(&self, other: &Self) -> Self

Polynomial addition modulo Q

Source

pub fn sub(&self, other: &Self) -> Self

Polynomial subtraction modulo Q

Source

pub fn neg(&self) -> Self

Polynomial negation modulo Q

Source

pub fn scalar_mul(&self, scalar: u32) -> Self

Scalar multiplication

Source

pub fn schoolbook_mul(&self, other: &Self) -> Self

Schoolbook polynomial multiplication with NEGACYCLIC reduction for Dilithium In ring R_q[x]/(x^N + 1), when degree >= N, we have x^N ≡ -1

Source

pub fn reduce_coeffs(&mut self)

In-place coefficient reduction to ensure all coefficients are < Q

Trait Implementations§

Source§

impl<M: Modulus> Add for &Polynomial<M>

Source§

type Output = Polynomial<M>

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<M: Modulus> Add for Polynomial<M>

Source§

type Output = Polynomial<M>

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<M: Clone + Modulus> Clone for Polynomial<M>

Source§

fn clone(&self) -> Polynomial<M>

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<M: Debug + Modulus> Debug for Polynomial<M>

Source§

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

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

impl<M: Modulus> Neg for &Polynomial<M>

Source§

type Output = Polynomial<M>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<M: Modulus> Neg for Polynomial<M>

Source§

type Output = Polynomial<M>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<M: PartialEq + Modulus> PartialEq for Polynomial<M>

Source§

fn eq(&self, other: &Polynomial<M>) -> 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<M: NttModulus> PolynomialNttExt<M> for Polynomial<M>

Source§

fn scalar_mul_montgomery(&self, scalar: u32) -> Polynomial<M>

Fast scalar multiplication using Montgomery reduction
Source§

impl<M: Modulus> Sub for &Polynomial<M>

Source§

type Output = Polynomial<M>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<M: Modulus> Sub for Polynomial<M>

Source§

type Output = Polynomial<M>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<M: Modulus> Zeroize for Polynomial<M>

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<M: Eq + Modulus> Eq for Polynomial<M>

Source§

impl<M: Modulus> StructuralPartialEq for Polynomial<M>

Auto Trait Implementations§

§

impl<M> Freeze for Polynomial<M>

§

impl<M> RefUnwindSafe for Polynomial<M>
where M: RefUnwindSafe,

§

impl<M> Send for Polynomial<M>
where M: Send,

§

impl<M> Sync for Polynomial<M>
where M: Sync,

§

impl<M> Unpin for Polynomial<M>
where M: Unpin,

§

impl<M> UnwindSafe for Polynomial<M>
where M: UnwindSafe,

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