qfall-math 0.1.1

Mathematical foundations for rapid prototyping of lattice-based cryptography
Documentation
// Copyright © 2023 Marvin Beckmann
//
// This file is part of qFALL-math.
//
// qFALL-math is free software: you can redistribute it and/or modify it under
// the terms of the Mozilla Public License Version 2.0 as published by the
// Mozilla Foundation. See <https://mozilla.org/en-US/MPL/2.0/>.

//! [`ModulusPolynomialRingZq`] is the context object for
//! [`PolynomialRingZq`](super::PolynomialRingZq).
//! This implementation uses the [FLINT](https://flintlib.org/) library.

use super::ntt_basis_polynomial_ring_zq::NTTBasisPolynomialRingZq;
use crate::integer_mod_q::PolyOverZq;
use std::{fmt, rc::Rc};

mod cmp;
mod coefficient_embedding;
mod from;
mod get;
mod norm;
mod ntt_basis;
mod ownership;
mod serialize;
mod to_string;

/// [`ModulusPolynomialRingZq`] represents the modulus object for
/// [`PolynomialRingZq`](crate::integer_mod_q::PolynomialRingZq)
///
/// Attributes
/// - `modulus`: holds the specific content, i.e. the modulus `q` and f(X)
///
/// # Examples
/// ```
/// use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
/// use qfall_math::integer_mod_q::PolyOverZq;
/// use std::str::FromStr;
///
/// // initialize X^2 + 1 mod 17, i.e. a polynomial with modulus
/// let poly_mod = PolyOverZq::from_str("3  1 0 1 mod 17").unwrap();
/// let modulus = ModulusPolynomialRingZq::from(poly_mod);
/// ```
pub struct ModulusPolynomialRingZq {
    pub(crate) modulus: Rc<PolyOverZq>,
    pub(crate) ntt_basis: Rc<Option<NTTBasisPolynomialRingZq>>,
    pub(crate) non_zero: Vec<usize>,
}

impl fmt::Debug for ModulusPolynomialRingZq {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "ModulusPolynomialRingZq {{ modulus: {}, storage: {{modulus: {:?}}}}}",
            self, self.modulus
        )
    }
}