Skip to main content

RingZq

Struct RingZq 

Source
pub struct RingZq {
    pub n: usize,
    pub q: u64,
}
Expand description

Polynomial-ring arithmetic over Z_q[x]/(x^n + 1).

Supports the ring operations needed for Ring-LWE and NTRU-based schemes.

§WARNING

Educational implementation. Not optimized or secure.

Fields§

§n: usize

Ring dimension n (must be a power of 2 for NTT)

§q: u64

Modulus q

Implementations§

Source§

impl RingZq

Source

pub fn new(n: usize, q: u64) -> Self

Create a new ring Z_q[x]/(x^n + 1).

Source

pub fn reduce(&self, poly: &[u64]) -> Vec<u64>

Reduce polynomial coefficients modulo q.

Source

pub fn add(&self, a: &[u64], b: &[u64]) -> Vec<u64>

Add two polynomials in the ring.

Source

pub fn sub(&self, a: &[u64], b: &[u64]) -> Vec<u64>

Subtract two polynomials in the ring.

Source

pub fn mul(&self, a: &[u64], b: &[u64]) -> Vec<u64>

Multiply two polynomials in Z_q[x]/(x^n + 1) using schoolbook multiplication.

O(n^2) — for educational purposes. Real implementations use NTT.

Source

pub fn linf_norm(&self, poly: &[u64]) -> u64

L-infinity norm: max absolute deviation from 0 or q (viewing coefficients as centered in (-q/2, q/2]).

Auto Trait Implementations§

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