Struct Rq

Source
pub struct Rq<const D: usize> { /* private fields */ }
Expand description

This module provides implementations for various operations in the polynomial ring R = Z_q[X] / (X^d + 1).

Implementations§

Source§

impl<const D: usize> Rq<D>

Source

pub const fn new(coeffs: [Zq; D]) -> Self

Constructor for the polynomial ring

Source

pub fn get_coefficients(&self) -> &[Zq; D]

Get the coefficients as a vector

Source

pub fn iter_mut(&mut self) -> IterMut<'_, Zq>

Source

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

Dot product between coefficients

Source

pub fn scalar_mul(&self, s: Zq) -> Self

Scalar multiplication

Source

pub fn eval(&self, x: Zq) -> Zq

Evaluate the polynomial at a specific point

Source

pub fn is_zero(&self) -> bool

Check if Polynomial == 0

Source

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

Check if two polynomials are equal

Source

pub fn random<R: Rng + CryptoRng>(rng: &mut R) -> Self

Generate random polynomial with a provided cryptographically secure RNG

Source

pub fn random_ternary<R: Rng + CryptoRng>(rng: &mut R) -> Self

Generate random small polynomial with secure RNG implementation

Source

pub fn decompose(&self, base: Zq, num_parts: usize) -> Vec<Self>

Decomposes a polynomial into base-B representation: p = p⁽⁰⁾ + p⁽¹⁾·B + p⁽²⁾·B² + … + p⁽ᵗ⁻¹⁾·B^(t-1) Where each p⁽ⁱ⁾ has small coefficients, using centered representatives

Source

pub fn encode_message(message: &[bool]) -> Option<Self>

Encode message into polynomial with small coefficients.

§Arguments
  • message - A slice of booleans representing a binary message
§Returns
  • Some(Rq) - A polynomial where each coefficient is 0 or 1 based on the message bits
  • None - If the message length exceeds the polynomial degree D
§Format
  • Each boolean is encoded as a coefficient: false -> 0, true -> 1
  • Message bits are mapped to coefficients in order (index 0 -> constant term)
  • Remaining coefficients (if message is shorter than D) are set to 0
Source

pub fn iter(&self) -> Iter<'_, Zq>

Iterator over coefficients

Source

pub fn check_bounds(&self, bound: Zq) -> bool

Check if polynomial coefficients are within bounds

Source

pub const fn zero() -> Self

Trait Implementations§

Source§

impl<const D: usize> Add for Rq<D>

Source§

type Output = Rq<D>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<const D: usize> AddAssign for Rq<D>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<const D: usize> Clone for Rq<D>

Source§

fn clone(&self) -> Rq<D>

Returns a copy 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<const D: usize> Debug for Rq<D>

Source§

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

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

impl<const D: usize> From<PolyRing> for Rq<D>

Source§

fn from(zqs: PolyRing) -> Self

Converts to this type from the input type.
Source§

impl<const D: usize> From<Vec<Zq>> for Rq<D>

Source§

fn from(vec: Vec<Zq>) -> Self

Converts to this type from the input type.
Source§

impl<const D: usize> From<ZqVector> for Rq<D>

Source§

fn from(zqs: ZqVector) -> Self

Converts to this type from the input type.
Source§

impl<const D: usize> Mul for Rq<D>

Source§

type Output = Rq<D>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<const D: usize> MulAssign for Rq<D>

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl<const D: usize> Neg for Rq<D>

Source§

fn neg(self) -> Self

Polynomial negation

Source§

type Output = Rq<D>

The resulting type after applying the - operator.
Source§

impl<const D: usize> PartialEq for Rq<D>

Source§

fn eq(&self, other: &Rq<D>) -> 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<const D: usize> Sub for Rq<D>

Source§

type Output = Rq<D>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<const D: usize> SubAssign for Rq<D>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<const D: usize> Eq for Rq<D>

Source§

impl<const D: usize> StructuralPartialEq for Rq<D>

Auto Trait Implementations§

§

impl<const D: usize> Freeze for Rq<D>

§

impl<const D: usize> RefUnwindSafe for Rq<D>

§

impl<const D: usize> Send for Rq<D>

§

impl<const D: usize> Sync for Rq<D>

§

impl<const D: usize> Unpin for Rq<D>

§

impl<const D: usize> UnwindSafe for Rq<D>

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.
§

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

§

fn vzip(self) -> V