fixed overflow

This commit is contained in:
Jean-Philippe Bossuat
2025-01-16 17:59:01 +01:00
parent 556346d623
commit 3b7d889971
3 changed files with 18 additions and 4 deletions

View File

@@ -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,
}

View File

@@ -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
}

View File

@@ -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;