bug fixes

This commit is contained in:
Jean-Philippe Bossuat
2025-05-26 13:55:21 +02:00
parent cb284a4c4c
commit 4c3a568108
7 changed files with 57 additions and 46 deletions

View File

@@ -1,7 +1,7 @@
use backend::{
Backend, FFT64, MatZnxDft, MatZnxDftOps, MatZnxDftToMut, MatZnxDftToRef, Module, ScalarZnx, ScalarZnxDftOps, ScalarZnxOps,
ScalarZnxToRef, Scratch, VecZnx, VecZnxBigAlloc, VecZnxDftAlloc, VecZnxDftOps, VecZnxDftToMut, VecZnxDftToRef, VecZnxOps,
ZnxZero,
Backend, FFT64, MatZnxDft, MatZnxDftOps, MatZnxDftToMut, MatZnxDftToRef, Module, ScalarZnx, ScalarZnxDftAlloc,
ScalarZnxDftOps, ScalarZnxOps, ScalarZnxToRef, Scratch, VecZnx, VecZnxBigAlloc, VecZnxDftAlloc, VecZnxDftOps, VecZnxDftToMut,
VecZnxDftToRef, VecZnxOps, ZnxZero,
};
use sampling::source::Source;
@@ -107,7 +107,7 @@ where
impl AutomorphismKey<Vec<u8>, FFT64> {
pub fn generate_from_sk_scratch_space(module: &Module<FFT64>, rank: usize, size: usize) -> usize {
GGLWECiphertext::generate_from_sk_scratch_space(module, rank, size)
GGLWECiphertext::generate_from_sk_scratch_space(module, rank, size) + module.bytes_of_scalar_znx_dft(rank)
}
pub fn generate_from_pk_scratch_space(module: &Module<FFT64>, rank: usize, pk_size: usize) -> usize {
@@ -188,6 +188,15 @@ where
assert_eq!(sk.n(), module.n());
assert_eq!(self.rank_out(), self.rank_in());
assert_eq!(sk.rank(), self.rank());
assert!(
scratch.available() >= AutomorphismKey::generate_from_sk_scratch_space(module, self.rank(), self.size()),
"scratch.available(): {} < AutomorphismKey::generate_from_sk_scratch_space(module, self.rank()={}, \
self.size()={}): {}",
scratch.available(),
self.rank(),
self.size(),
AutomorphismKey::generate_from_sk_scratch_space(module, self.rank(), self.size())
)
}
let (sk_out_dft_data, scratch_1) = scratch.tmp_scalar_znx_dft(module, sk.rank());

View File

@@ -1,7 +1,7 @@
use backend::{
Backend, FFT64, MatZnxDft, MatZnxDftAlloc, MatZnxDftOps, MatZnxDftToMut, MatZnxDftToRef, Module, ScalarZnx, ScalarZnxDft,
ScalarZnxDftToRef, ScalarZnxToRef, Scratch, VecZnxAlloc, VecZnxDftAlloc, VecZnxDftToMut, VecZnxDftToRef, VecZnxOps, ZnxInfos,
ZnxZero,
ScalarZnxDftToRef, ScalarZnxToRef, Scratch, VecZnxAlloc, VecZnxBigScratch, VecZnxDftAlloc, VecZnxDftToMut, VecZnxDftToRef,
VecZnxOps, ZnxInfos, ZnxZero,
};
use sampling::source::Source;
@@ -115,6 +115,15 @@ where
assert_eq!(self.n(), module.n());
assert_eq!(sk_dft.n(), module.n());
assert_eq!(pt.n(), module.n());
assert!(
scratch.available() >= GGLWECiphertext::generate_from_sk_scratch_space(module, self.rank(), self.size()),
"scratch.available: {} < GGLWECiphertext::generate_from_sk_scratch_space(module, self.rank()={}, \
self.size()={}): {}",
scratch.available(),
self.rank(),
self.size(),
GGLWECiphertext::generate_from_sk_scratch_space(module, self.rank(), self.size())
)
}
let rows: usize = self.rows();

View File

@@ -97,9 +97,7 @@ where
impl GLWECiphertext<Vec<u8>> {
pub fn encrypt_sk_scratch_space(module: &Module<FFT64>, ct_size: usize) -> usize {
module.vec_znx_big_normalize_tmp_bytes()
+ module.bytes_of_vec_znx_dft(1, ct_size)
+ module.bytes_of_vec_znx_big(1, ct_size)
module.vec_znx_big_normalize_tmp_bytes() + module.bytes_of_vec_znx_dft(1, ct_size) + module.bytes_of_vec_znx(1, ct_size)
}
pub fn encrypt_pk_scratch_space(module: &Module<FFT64>, pk_size: usize) -> usize {
((module.bytes_of_vec_znx_dft(1, pk_size) + module.bytes_of_vec_znx_big(1, pk_size)) | module.bytes_of_scalar_znx(1))
@@ -534,11 +532,11 @@ where
module.vec_znx_big_automorphism_inplace(apply_auto, &mut res_big, i);
}
match OP{
1=> module.vec_znx_big_add_small_inplace(&mut res_big, i, lhs, i),
2=> module.vec_znx_big_sub_small_a_inplace(&mut res_big, i, lhs, i),
3=> module.vec_znx_big_sub_small_b_inplace(&mut res_big, i, lhs, i),
_=>{},
match OP {
1 => module.vec_znx_big_add_small_inplace(&mut res_big, i, lhs, i),
2 => module.vec_znx_big_sub_small_a_inplace(&mut res_big, i, lhs, i),
3 => module.vec_znx_big_sub_small_b_inplace(&mut res_big, i, lhs, i),
_ => {}
}
module.vec_znx_big_normalize(basek, self, i, &res_big, i, scratch1);
});
@@ -636,6 +634,12 @@ where
assert_eq!(pt.n(), module.n());
assert!(col < self.rank() + 1);
}
assert!(
scratch.available() >= GLWECiphertext::encrypt_sk_scratch_space(module, self.size()),
"scratch.available(): {} < GLWECiphertext::encrypt_sk_scratch_space: {}",
scratch.available(),
GLWECiphertext::encrypt_sk_scratch_space(module, self.size())
)
}
let basek: usize = self.basek();

View File

@@ -175,7 +175,7 @@ where
self.set_k(a.k());
}
pub fn rotate_inplace(&mut self, module: &Module<FFT64>, k: i64){
pub fn rotate_inplace(&mut self, module: &Module<FFT64>, k: i64) {
#[cfg(debug_assertions)]
{
assert_eq!(self.n(), module.n());
@@ -240,8 +240,8 @@ where
}
}
impl GLWECiphertext<Vec<u8>>{
pub fn rsh_scratch_space(module: &Module<FFT64>) -> usize{
impl GLWECiphertext<Vec<u8>> {
pub fn rsh_scratch_space(module: &Module<FFT64>) -> usize {
VecZnx::rsh_scratch_space(module.n())
}
}
}