diff --git a/poulpy-core/src/glwe_packing.rs b/poulpy-core/src/glwe_packing.rs index 0e2f71a..e729929 100644 --- a/poulpy-core/src/glwe_packing.rs +++ b/poulpy-core/src/glwe_packing.rs @@ -20,7 +20,7 @@ pub trait GLWEPacking { keys: &H, scratch: &mut Scratch, ) where - R: GLWEToMut, + R: GLWEToMut + GLWEInfos, A: GLWEToMut + GLWEToRef + GLWEInfos, K: GGLWEPreparedToRef + GetGaloisElement + GGLWEInfos, H: GLWEAutomorphismKeyHelper; @@ -50,7 +50,7 @@ where keys: &H, scratch: &mut Scratch, ) where - R: GLWEToMut, + R: GLWEToMut + GLWEInfos, A: GLWEToMut + GLWEToRef + GLWEInfos, K: GGLWEPreparedToRef + GetGaloisElement + GGLWEInfos, H: GLWEAutomorphismKeyHelper, diff --git a/poulpy-core/src/glwe_trace.rs b/poulpy-core/src/glwe_trace.rs index 2142301..ad49c4e 100644 --- a/poulpy-core/src/glwe_trace.rs +++ b/poulpy-core/src/glwe_trace.rs @@ -33,7 +33,7 @@ impl GLWE> { impl GLWE { pub fn trace(&mut self, module: &M, skip: usize, a: &A, keys: &H, scratch: &mut Scratch) where - A: GLWEToRef, + A: GLWEToRef + GLWEInfos, K: GGLWEPreparedToRef + GetGaloisElement + GGLWEInfos, H: GLWEAutomorphismKeyHelper, Scratch: ScratchTakeCore, @@ -98,18 +98,31 @@ where return glwe_conv + trace; } - trace + let tmp = if res_infos.k() > a_infos.k() { + GLWE::bytes_of_from_infos(res_infos) + } else { + GLWE::bytes_of_from_infos(a_infos) + }; + + trace + tmp } fn glwe_trace(&self, res: &mut R, skip: usize, a: &A, keys: &H, scratch: &mut Scratch) where - R: GLWEToMut, - A: GLWEToRef, + R: GLWEToMut + GLWEInfos, + A: GLWEToRef + GLWEInfos, K: GGLWEPreparedToRef + GetGaloisElement + GGLWEInfos, H: GLWEAutomorphismKeyHelper, { - self.glwe_copy(res, a); - self.glwe_trace_inplace(res, skip, keys, scratch); + let (mut tmp, scratch_1) = if a.k() > res.k() { + scratch.take_glwe(a) + } else { + scratch.take_glwe(res) + }; + + self.glwe_copy(&mut tmp, a); + self.glwe_trace_inplace(&mut tmp, skip, keys, scratch_1); + self.glwe_copy(res, &tmp); } fn glwe_trace_inplace(&self, res: &mut R, skip: usize, keys: &H, scratch: &mut Scratch) @@ -177,8 +190,6 @@ where ); } } else { - // println!("res: {}", res); - for i in skip..log_n { self.glwe_rsh(1, res, scratch); @@ -209,8 +220,8 @@ pub trait GLWETrace { fn glwe_trace(&self, res: &mut R, skip: usize, a: &A, keys: &H, scratch: &mut Scratch) where - R: GLWEToMut, - A: GLWEToRef, + R: GLWEToMut + GLWEInfos, + A: GLWEToRef + GLWEInfos, K: GGLWEPreparedToRef + GetGaloisElement + GGLWEInfos, H: GLWEAutomorphismKeyHelper;