qfall_math/integer_mod_q/
modulus_polynomial_ring_zq.rs

1// Copyright © 2023 Marvin Beckmann
2//
3// This file is part of qFALL-math.
4//
5// qFALL-math is free software: you can redistribute it and/or modify it under
6// the terms of the Mozilla Public License Version 2.0 as published by the
7// Mozilla Foundation. See <https://mozilla.org/en-US/MPL/2.0/>.
8
9//! [`ModulusPolynomialRingZq`] is the context object for
10//! [`PolynomialRingZq`](super::PolynomialRingZq).
11//! This implementation uses the [FLINT](https://flintlib.org/) library.
12
13use super::ntt_basis_polynomial_ring_zq::NTTBasisPolynomialRingZq;
14use flint_sys::fq::fq_ctx_struct;
15use std::{fmt, rc::Rc};
16
17mod cmp;
18mod coefficient_embedding;
19mod from;
20mod get;
21mod norm;
22mod ntt_basis;
23mod ownership;
24mod serialize;
25mod to_string;
26mod unsafe_functions;
27
28/// [`ModulusPolynomialRingZq`] represents the modulus object for
29/// [`PolynomialRingZq`](crate::integer_mod_q::PolynomialRingZq)
30///
31/// Attributes
32/// - `modulus`: holds the specific content, i.e. the modulus `q` and f(X); it
33///   holds [FLINT](https://flintlib.org/)'s [struct](fq_ctx_struct)
34///
35/// # Examples
36/// ```
37/// use qfall_math::integer_mod_q::ModulusPolynomialRingZq;
38/// use qfall_math::integer_mod_q::PolyOverZq;
39/// use std::str::FromStr;
40///
41/// // initialize X^2 + 1 mod 17, i.e. a polynomial with modulus
42/// let poly_mod = PolyOverZq::from_str("3  1 0 1 mod 17").unwrap();
43/// let modulus = ModulusPolynomialRingZq::from(poly_mod);
44/// ```
45pub struct ModulusPolynomialRingZq {
46    modulus: Rc<fq_ctx_struct>,
47    pub(crate) ntt_basis: Rc<Option<NTTBasisPolynomialRingZq>>,
48}
49
50impl fmt::Debug for ModulusPolynomialRingZq {
51    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52        write!(
53            f,
54            "ModulusPolynomialRingZq {{ modulus: {}, storage: {{modulus: {:?}}}}}",
55            self, self.modulus
56        )
57    }
58}