mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 13:16:44 +01:00
fixed overflow
This commit is contained in:
@@ -18,7 +18,12 @@ impl AutoPermMap {
|
||||
gal_el
|
||||
}
|
||||
|
||||
pub fn gen<O: Unsigned, const NTT: bool>(&mut self, ring: &Ring<O>, gen_1: usize, gen_2: bool) -> usize {
|
||||
pub fn gen<O: Unsigned, const NTT: bool>(
|
||||
&mut self,
|
||||
ring: &Ring<O>,
|
||||
gen_1: usize,
|
||||
gen_2: bool,
|
||||
) -> usize {
|
||||
self.insert(AutoPerm::new::<O, NTT>(ring, gen_1, gen_2))
|
||||
}
|
||||
|
||||
@@ -27,7 +32,9 @@ impl AutoPermMap {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AutoPerm {
|
||||
pub ntt: bool,
|
||||
pub gal_el: usize,
|
||||
pub permutation: Vec<usize>,
|
||||
}
|
||||
@@ -64,6 +71,7 @@ impl AutoPerm {
|
||||
}
|
||||
|
||||
Self {
|
||||
ntt: NTT,
|
||||
gal_el: gal_el,
|
||||
permutation: permutation,
|
||||
}
|
||||
|
||||
@@ -45,11 +45,10 @@ impl<O: Unsigned> Ring<O> {
|
||||
e >>= 1;
|
||||
}
|
||||
|
||||
let nth_root = 1 << self.cyclotomic_order;
|
||||
gal_el &= nth_root - 1;
|
||||
gal_el &= self.cyclotomic_order - 1;
|
||||
|
||||
if gen_2 {
|
||||
return nth_root - gal_el;
|
||||
return self.cyclotomic_order - gal_el;
|
||||
}
|
||||
gal_el
|
||||
}
|
||||
|
||||
@@ -158,6 +158,13 @@ impl Ring<u64> {
|
||||
b.n()
|
||||
);
|
||||
|
||||
assert!(
|
||||
NTT == auto_perm.ntt,
|
||||
"missmatch between AutoPerm NTT flag={} and method NTT flag={}",
|
||||
auto_perm.ntt,
|
||||
NTT
|
||||
);
|
||||
|
||||
let b_vec: &mut Vec<u64> = &mut b.0;
|
||||
let a_vec: &Vec<u64> = &a.0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user