use std::sync::Arc;
use crate::bfv::BfvParameters;
use crate::Result;
use fhe_math::rq::Poly;
use rand::{CryptoRng, RngCore};
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct CommonRandomPoly {
pub(crate) poly: Poly,
}
impl CommonRandomPoly {
pub fn new<R: RngCore + CryptoRng>(par: &Arc<BfvParameters>, rng: &mut R) -> Result<Self> {
Self::new_leveled(par, 0, rng)
}
pub fn new_vec<R: RngCore + CryptoRng>(
par: &Arc<BfvParameters>,
rng: &mut R,
) -> Result<Vec<Self>> {
(0..par.moduli().len())
.map(|_| Self::new(par, rng))
.collect()
}
pub fn new_leveled<R: RngCore + CryptoRng>(
par: &Arc<BfvParameters>,
level: usize,
rng: &mut R,
) -> Result<Self> {
let ctx = par.context_at_level(level)?;
let poly = Poly::random(ctx, fhe_math::rq::Representation::Ntt, rng);
Ok(Self { poly })
}
}