arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/src/ring/impl_u64/ring.rs
src/ring/impl_u64/ring.rsRaw
 1use crate::ring::Ring;
 2use crate::dft::ntt::Table;
 3use crate::modulus::prime::Prime;
 4use crate::poly::Poly;
 5
 6impl Ring<u64>{
 7    pub fn new(n:usize, q_base:u64, q_power:usize) -> Self{
 8        let prime: Prime<u64> = Prime::<u64>::new(q_base, q_power);
 9        Self {
10            n: n,
11            modulus: prime.clone(),
12            dft: Box::new(Table::<u64>::new(prime, (2 * n) as u64)),
13        }
14    }
15
16    pub fn n(&self) -> usize{
17        return self.n
18    }
19
20    pub fn new_poly(&self) -> Poly<u64>{
21        Poly::<u64>::new(self.n())
22    }
23
24    pub fn ntt_inplace<const LAZY:bool>(&self, poly: &mut Poly<u64>){
25        match LAZY{
26            true => self.dft.forward_inplace_lazy(&mut poly.0),
27            false => self.dft.forward_inplace(&mut poly.0)
28        }
29    }
30
31    pub fn intt_inplace<const LAZY:bool>(&self, poly: &mut Poly<u64>){
32        match LAZY{
33            true => self.dft.forward_inplace_lazy(&mut poly.0),
34            false => self.dft.forward_inplace(&mut poly.0)
35        }
36    }
37
38    pub fn ntt<const LAZY:bool>(&self, poly_in: &Poly<u64>, poly_out: &mut Poly<u64>){
39        poly_out.0.copy_from_slice(&poly_in.0);
40        match LAZY{
41            true => self.dft.backward_inplace_lazy(&mut poly_out.0),
42            false => self.dft.backward_inplace(&mut poly_out.0)
43        }
44    }
45
46    pub fn intt<const LAZY:bool>(&self, poly_in: &Poly<u64>, poly_out: &mut Poly<u64>){
47        poly_out.0.copy_from_slice(&poly_in.0);
48        match LAZY{
49            true => self.dft.backward_inplace_lazy(&mut poly_out.0),
50            false => self.dft.backward_inplace(&mut poly_out.0)
51        }
52    }
53}