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>
impl<const D: usize> Rq<D>
Sourcepub fn get_coefficients(&self) -> &[Zq; D]
pub fn get_coefficients(&self) -> &[Zq; D]
Get the coefficients as a vector
pub fn iter_mut(&mut self) -> IterMut<'_, Zq>
Sourcepub fn inner_product(&self, other: &Self) -> Zq
pub fn inner_product(&self, other: &Self) -> Zq
Dot product between coefficients
Sourcepub fn scalar_mul(&self, s: Zq) -> Self
pub fn scalar_mul(&self, s: Zq) -> Self
Scalar multiplication
Sourcepub fn random<R: Rng + CryptoRng>(rng: &mut R) -> Self
pub fn random<R: Rng + CryptoRng>(rng: &mut R) -> Self
Generate random polynomial with a provided cryptographically secure RNG
Sourcepub fn random_ternary<R: Rng + CryptoRng>(rng: &mut R) -> Self
pub fn random_ternary<R: Rng + CryptoRng>(rng: &mut R) -> Self
Generate random small polynomial with secure RNG implementation
Sourcepub fn decompose(&self, base: Zq, num_parts: usize) -> Vec<Self>
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
Sourcepub fn encode_message(message: &[bool]) -> Option<Self>
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 bitsNone
- 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
Sourcepub fn check_bounds(&self, bound: Zq) -> bool
pub fn check_bounds(&self, bound: Zq) -> bool
Check if polynomial coefficients are within bounds
pub const fn zero() -> Self
Trait Implementations§
Source§impl<const D: usize> AddAssign for Rq<D>
impl<const D: usize> AddAssign for Rq<D>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+=
operation. Read moreSource§impl<const D: usize> MulAssign for Rq<D>
impl<const D: usize> MulAssign for Rq<D>
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
Performs the
*=
operation. Read moreSource§impl<const D: usize> SubAssign for Rq<D>
impl<const D: usize> SubAssign for Rq<D>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-=
operation. Read moreimpl<const D: usize> Eq for Rq<D>
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> 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
Mutably borrows from an owned value. Read more