pub struct NTTPolynomialRingZq {
pub poly: Vec<Z>,
pub modulus: ModulusPolynomialRingZq,
}Expand description
NTTPolynomialRingZq contains the NTT representation of some polynomial with respect to
a NTTBasisPolynomialRingZq that itself isn’t aware of.
Attributes
poly: holds the coefficientsmodulus: theModulusPolynomialRingZqdefining the modulusq, the ringZ_q[X]/f(X), and the NTT transformNTTBasisPolynomialRingZq
§Examples
use qfall_math::integer_mod_q::{Modulus, PolynomialRingZq, NTTPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
// Setup modulus with capability to perform NTT transform
let mut modulus = ModulusPolynomialRingZq::from_str("5 1 0 0 0 1 mod 257").unwrap();
modulus.set_ntt_unchecked(64);
// sample random polynomial
let rnd = NTTPolynomialRingZq::sample_uniform(&modulus);
// or instantiate polynomial from PolynomialRingZq (or PolyOverZq)
let poly_ring = PolynomialRingZq::sample_uniform(&modulus);
let ntt_poly_ring = NTTPolynomialRingZq::from(&poly_ring);
// multiply, add and subtract objects
let mod_q = Modulus::from(modulus.get_q());
let mut tmp_ntt = ntt_poly_ring * &rnd;
tmp_ntt += &rnd;
tmp_ntt -= &rnd;
// Return to PolynomialRingZq
let res = tmp_ntt.inv_ntt();Fields§
§poly: Vec<Z>§modulus: ModulusPolynomialRingZqImplementations§
Source§impl NTTPolynomialRingZq
impl NTTPolynomialRingZq
Sourcepub fn inv_ntt(self) -> PolynomialRingZq
pub fn inv_ntt(self) -> PolynomialRingZq
Computes the inverse NTT of self with respect to the given modulus.
Returns a new PolynomialRingZq with the specified ModulusPolynomialRingZq
and values as defined in self.
§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, PolyOverZq, ModulusPolynomialRingZq, NTTPolynomialRingZq};
use qfall_math::traits::SetCoefficient;
let n = 4;
let modulus = 7681;
let mut mod_poly = PolyOverZq::from(modulus);
mod_poly.set_coeff(0, 1).unwrap();
mod_poly.set_coeff(n, 1).unwrap();
let mut polynomial_modulus = ModulusPolynomialRingZq::from(&mod_poly);
polynomial_modulus.set_ntt_unchecked(1925);
let ntt = NTTPolynomialRingZq::sample_uniform(&polynomial_modulus);
let res = ntt.inv_ntt();§Panics …
- if the
NTTBasisPolynomialRingZqinmodulusis not set.
Source§impl NTTPolynomialRingZq
impl NTTPolynomialRingZq
Sourcepub fn get_mod(&self) -> ModulusPolynomialRingZq
pub fn get_mod(&self) -> ModulusPolynomialRingZq
Returns the modulus of the polynomial in NTT representation as a ModulusPolynomialRingZq.
§Examples
use qfall_math::integer_mod_q::{NTTPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let modulus = ModulusPolynomialRingZq::from_str("5 1 0 0 0 1 mod 17").unwrap();
let matrix = NTTPolynomialRingZq::sample_uniform(&modulus);
let modulus = matrix.get_mod();Source§impl NTTPolynomialRingZq
impl NTTPolynomialRingZq
Sourcepub fn sample_uniform(modulus: &ModulusPolynomialRingZq) -> Self
pub fn sample_uniform(modulus: &ModulusPolynomialRingZq) -> Self
Generates a NTTPolynomialRingZq instance with degree modulus_degree - 1
and entries chosen uniform at random in [0, modulus).
The internally used uniform at random chosen bytes are generated
by ThreadRng, which uses ChaCha12 and
is considered cryptographically secure.
Parameters:
modulus_degree: specifies the degree of the modulus polynomial, i.e. the maximum number of sampled coefficients ismodulus_degree - 1modulus: specifies the modulus of the values and thus, the interval size over which is sampled
Returns a fresh NTTPolynomialRingZq instance of length modulus_degree with entries
chosen uniform at random in [0, modulus).
§Examples
use qfall_math::integer_mod_q::{NTTPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let mut modulus = ModulusPolynomialRingZq::from_str("5 1 0 0 0 1 mod 257").unwrap();
modulus.set_ntt_unchecked(64);
let sample = NTTPolynomialRingZq::sample_uniform(&modulus);Trait Implementations§
Source§impl Add for &NTTPolynomialRingZq
impl Add for &NTTPolynomialRingZq
Source§fn add(self, other: Self) -> Self::Output
fn add(self, other: Self) -> Self::Output
Adds self with other.
Paramters:
other: specifies the NTT-representation of the polynomial to add toself
Returns the NTT-representation of the sum of self and other.
§Example
use qfall_math::integer_mod_q::{NTTPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let mut modulus = ModulusPolynomialRingZq::from_str("5 1 0 0 0 1 mod 257").unwrap();
modulus.set_ntt_unchecked(64);
let a = NTTPolynomialRingZq::sample_uniform(&modulus);
let b = NTTPolynomialRingZq::sample_uniform(&modulus);
let c = a + b;§Panics …
- if the moduli are not equal.
Source§type Output = NTTPolynomialRingZq
type Output = NTTPolynomialRingZq
+ operator.Source§impl AddAssign<&NTTPolynomialRingZq> for NTTPolynomialRingZq
impl AddAssign<&NTTPolynomialRingZq> for NTTPolynomialRingZq
Source§fn add_assign(&mut self, other: &Self)
fn add_assign(&mut self, other: &Self)
Adds self with other reusing the memory of self.
Paramters:
other: specifies the NTT-representation of the polynomial to add toself
Computes the NTT-representation of the sum of self and other.
§Example
use qfall_math::integer_mod_q::{NTTPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let mut modulus = ModulusPolynomialRingZq::from_str("5 1 0 0 0 1 mod 257").unwrap();
modulus.set_ntt_unchecked(64);
let mut a = NTTPolynomialRingZq::sample_uniform(&modulus);
let b = NTTPolynomialRingZq::sample_uniform(&modulus);
a += b;§Panics …
- if the moduli are not equal.
Source§impl AddAssign for NTTPolynomialRingZq
impl AddAssign for NTTPolynomialRingZq
Source§fn add_assign(&mut self, other: NTTPolynomialRingZq)
fn add_assign(&mut self, other: NTTPolynomialRingZq)
Documentation at NTTPolynomialRingZq::add_assign.
Source§impl Clone for NTTPolynomialRingZq
impl Clone for NTTPolynomialRingZq
Source§fn clone(&self) -> NTTPolynomialRingZq
fn clone(&self) -> NTTPolynomialRingZq
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl CompareBase<&NTTPolynomialRingZq> for NTTPolynomialRingZq
impl CompareBase<&NTTPolynomialRingZq> for NTTPolynomialRingZq
Source§fn compare_base(&self, other: &&NTTPolynomialRingZq) -> bool
fn compare_base(&self, other: &&NTTPolynomialRingZq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(
&self,
other: &&NTTPolynomialRingZq,
) -> Option<MathError>
fn call_compare_base_error( &self, other: &&NTTPolynomialRingZq, ) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<&PolyOverZ> for NTTPolynomialRingZq
impl CompareBase<&PolyOverZ> for NTTPolynomialRingZq
Source§impl CompareBase<&PolyOverZq> for NTTPolynomialRingZq
impl CompareBase<&PolyOverZq> for NTTPolynomialRingZq
Source§fn compare_base(&self, other: &&PolyOverZq) -> bool
fn compare_base(&self, other: &&PolyOverZq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &&PolyOverZq) -> Option<MathError>
fn call_compare_base_error(&self, other: &&PolyOverZq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<&PolynomialRingZq> for NTTPolynomialRingZq
impl CompareBase<&PolynomialRingZq> for NTTPolynomialRingZq
Source§fn compare_base(&self, other: &&PolynomialRingZq) -> bool
fn compare_base(&self, other: &&PolynomialRingZq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(
&self,
other: &&PolynomialRingZq,
) -> Option<MathError>
fn call_compare_base_error( &self, other: &&PolynomialRingZq, ) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<&Zq> for NTTPolynomialRingZq
impl CompareBase<&Zq> for NTTPolynomialRingZq
Source§fn compare_base(&self, other: &&Zq) -> bool
fn compare_base(&self, other: &&Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &&Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl<Integer: Into<Z>> CompareBase<Integer> for NTTPolynomialRingZq
impl<Integer: Into<Z>> CompareBase<Integer> for NTTPolynomialRingZq
Source§impl CompareBase<PolyOverZ> for NTTPolynomialRingZq
impl CompareBase<PolyOverZ> for NTTPolynomialRingZq
Source§impl CompareBase<PolyOverZq> for NTTPolynomialRingZq
impl CompareBase<PolyOverZq> for NTTPolynomialRingZq
Source§fn compare_base(&self, other: &PolyOverZq) -> bool
fn compare_base(&self, other: &PolyOverZq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &PolyOverZq) -> Option<MathError>
fn call_compare_base_error(&self, other: &PolyOverZq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<PolynomialRingZq> for NTTPolynomialRingZq
impl CompareBase<PolynomialRingZq> for NTTPolynomialRingZq
Source§fn compare_base(&self, other: &PolynomialRingZq) -> bool
fn compare_base(&self, other: &PolynomialRingZq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &PolynomialRingZq) -> Option<MathError>
fn call_compare_base_error(&self, other: &PolynomialRingZq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase<Zq> for NTTPolynomialRingZq
impl CompareBase<Zq> for NTTPolynomialRingZq
Source§fn compare_base(&self, other: &Zq) -> bool
fn compare_base(&self, other: &Zq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
fn call_compare_base_error(&self, other: &Zq) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl CompareBase for NTTPolynomialRingZq
impl CompareBase for NTTPolynomialRingZq
Source§fn compare_base(&self, other: &NTTPolynomialRingZq) -> bool
fn compare_base(&self, other: &NTTPolynomialRingZq) -> bool
Compares the moduli of the two elements.
Parameters:
other: The other object whose base is compared toself
Returns true if the moduli match and false otherwise.
Source§fn call_compare_base_error(
&self,
other: &NTTPolynomialRingZq,
) -> Option<MathError>
fn call_compare_base_error( &self, other: &NTTPolynomialRingZq, ) -> Option<MathError>
Returns an error that gives a small explanation of how the moduli are incomparable.
Parameters:
other: The other object whose base is compared toself
Returns a MathError of type MismatchingModulus.
Source§impl Debug for NTTPolynomialRingZq
impl Debug for NTTPolynomialRingZq
Source§impl<'de> Deserialize<'de> for NTTPolynomialRingZq
impl<'de> Deserialize<'de> for NTTPolynomialRingZq
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for NTTPolynomialRingZq
impl Display for NTTPolynomialRingZq
Source§impl From<&PolynomialRingZq> for NTTPolynomialRingZq
impl From<&PolynomialRingZq> for NTTPolynomialRingZq
Source§fn from(poly: &PolynomialRingZq) -> Self
fn from(poly: &PolynomialRingZq) -> Self
Computes the NTT representation of poly.
Parameters:
poly: the polynomial that’s going to be represented in NTT form.
Returns the NTT representation as a NTTPolynomialRingZq of poly.
§Examples
use qfall_math::integer_mod_q::{NTTPolynomialRingZq, PolynomialRingZq, ModulusPolynomialRingZq, PolyOverZq};
use crate::qfall_math::traits::SetCoefficient;
use std::str::FromStr;
let n = 4;
let modulus = 7681;
let mut mod_poly = PolyOverZq::from(modulus);
mod_poly.set_coeff(0, 1).unwrap();
mod_poly.set_coeff(n, 1).unwrap();
let mut polynomial_modulus = ModulusPolynomialRingZq::from(&mod_poly);
polynomial_modulus.set_ntt_unchecked(1925);
let poly_ring = PolynomialRingZq::sample_uniform(&polynomial_modulus);
let ntt_poly_ring = NTTPolynomialRingZq::from(&poly_ring);§Panics …
- if the
NTTBasisPolynomialRingZq, which is part of theModulusPolynomialRingZqinpolyis not set.
Source§impl From<NTTPolynomialRingZq> for PolynomialRingZq
impl From<NTTPolynomialRingZq> for PolynomialRingZq
Source§fn from(ntt: NTTPolynomialRingZq) -> Self
fn from(ntt: NTTPolynomialRingZq) -> Self
Creates a polynomial from NTTPolynomialRingZq generated with respect to the
NTTBasisPolynomialRingZq as part of
ModulusPolynomialRingZq.
Parameters:
ntt: the NTT representation of the polynomial.modulus: the modulus that is applied to the polynomial ring element.
Returns a new PolynomialRingZq with the specified ModulusPolynomialRingZq and
values as defined in ntt.
§Examples
use qfall_math::integer_mod_q::{PolynomialRingZq, PolyOverZq, ModulusPolynomialRingZq, NTTPolynomialRingZq};
use qfall_math::traits::SetCoefficient;
let n = 4;
let modulus = 7681;
let mut mod_poly = PolyOverZq::from(modulus);
mod_poly.set_coeff(0, 1).unwrap();
mod_poly.set_coeff(n, 1).unwrap();
let mut polynomial_modulus = ModulusPolynomialRingZq::from(&mod_poly);
polynomial_modulus.set_ntt_unchecked(1925);
let ntt = NTTPolynomialRingZq::sample_uniform(&polynomial_modulus);
let res = PolynomialRingZq::from(ntt);§Panics …
- if the
NTTBasisPolynomialRingZqinmodulusis not set.
Source§impl Mul for &NTTPolynomialRingZq
impl Mul for &NTTPolynomialRingZq
Source§fn mul(self, other: Self) -> Self::Output
fn mul(self, other: Self) -> Self::Output
Multiplies self with other.
Paramters:
other: specifies the NTT-representation of the polynomial to multiply toselfmodulus: defines the modulusq
Returns the NTT-representation of the multiplication of self and other.
§Example
use qfall_math::integer_mod_q::{NTTPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let mut modulus = ModulusPolynomialRingZq::from_str("5 1 0 0 0 1 mod 257").unwrap();
modulus.set_ntt_unchecked(64);
let a = NTTPolynomialRingZq::sample_uniform(&modulus);
let b = NTTPolynomialRingZq::sample_uniform(&modulus);
let c = a * b;§Panics …
- if the moduli are not equal.
Source§type Output = NTTPolynomialRingZq
type Output = NTTPolynomialRingZq
* operator.Source§impl MulAssign<&NTTPolynomialRingZq> for NTTPolynomialRingZq
impl MulAssign<&NTTPolynomialRingZq> for NTTPolynomialRingZq
Source§fn mul_assign(&mut self, other: &NTTPolynomialRingZq)
fn mul_assign(&mut self, other: &NTTPolynomialRingZq)
Multiplies self with other reusing the memory of self.
Paramters:
other: specifies the NTT-representation of the polynomial to multiply withself
Computes the NTT-representation of the multiplication of self and other.
§Example
use qfall_math::integer_mod_q::{NTTPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let mut modulus = ModulusPolynomialRingZq::from_str("5 1 0 0 0 1 mod 257").unwrap();
modulus.set_ntt_unchecked(64);
let mut a = NTTPolynomialRingZq::sample_uniform(&modulus);
let b = NTTPolynomialRingZq::sample_uniform(&modulus);
a *= b;§Panics …
- if the moduli are not equal.
Source§impl MulAssign for NTTPolynomialRingZq
impl MulAssign for NTTPolynomialRingZq
Source§fn mul_assign(&mut self, other: NTTPolynomialRingZq)
fn mul_assign(&mut self, other: NTTPolynomialRingZq)
Documentation at NTTPolynomialRingZq::mul_assign.
Source§impl PartialEq for NTTPolynomialRingZq
impl PartialEq for NTTPolynomialRingZq
Source§impl Serialize for NTTPolynomialRingZq
impl Serialize for NTTPolynomialRingZq
Source§impl Sub for &NTTPolynomialRingZq
impl Sub for &NTTPolynomialRingZq
Source§fn sub(self, other: Self) -> Self::Output
fn sub(self, other: Self) -> Self::Output
Subtracts other from self.
Paramters:
other: specifies the NTT-representation of the polynomial to subtract fromself
Returns the NTT-representation of the subtraction of other from self.
§Example
use qfall_math::integer_mod_q::{NTTPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let mut modulus = ModulusPolynomialRingZq::from_str("5 1 0 0 0 1 mod 257").unwrap();
modulus.set_ntt_unchecked(64);
let a = NTTPolynomialRingZq::sample_uniform(&modulus);
let b = NTTPolynomialRingZq::sample_uniform(&modulus);
let c = a - b;§Panics …
- if the moduli are not equal.
Source§type Output = NTTPolynomialRingZq
type Output = NTTPolynomialRingZq
- operator.Source§impl SubAssign<&NTTPolynomialRingZq> for NTTPolynomialRingZq
impl SubAssign<&NTTPolynomialRingZq> for NTTPolynomialRingZq
Source§fn sub_assign(&mut self, other: &Self)
fn sub_assign(&mut self, other: &Self)
Subtracts other from self reusing the memory of self.
Paramters:
other: specifies the NTT-representation of the polynomial to subtract fromself
Computes the NTT-representation of the subtraction of other from self.
§Example
use qfall_math::integer_mod_q::{NTTPolynomialRingZq, ModulusPolynomialRingZq};
use std::str::FromStr;
let mut modulus = ModulusPolynomialRingZq::from_str("5 1 0 0 0 1 mod 257").unwrap();
modulus.set_ntt_unchecked(64);
let mut a = NTTPolynomialRingZq::sample_uniform(&modulus);
let b = NTTPolynomialRingZq::sample_uniform(&modulus);
a -= b;§Panics …
- if the moduli are not equal.
Source§impl SubAssign for NTTPolynomialRingZq
impl SubAssign for NTTPolynomialRingZq
Source§fn sub_assign(&mut self, other: NTTPolynomialRingZq)
fn sub_assign(&mut self, other: NTTPolynomialRingZq)
Documentation at NTTPolynomialRingZq::sub_assign.