mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-10 15:18:33 -05:00
chore(tfhe): rename some primitives whose functionality changed
This commit is contained in:
@@ -287,7 +287,7 @@ impl ShortintEngine {
|
||||
let modulus = ct_left.message_modulus.0 as u64;
|
||||
let acc =
|
||||
self.generate_accumulator(server_key, |x| (x % modulus == scalar as u64) as u64)?;
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct_left, &acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct_left, &acc)?;
|
||||
ct_left.degree.0 = 1;
|
||||
Ok(())
|
||||
}
|
||||
@@ -364,7 +364,7 @@ impl ShortintEngine {
|
||||
let modulus = ct_left.message_modulus.0 as u64;
|
||||
let acc =
|
||||
self.generate_accumulator(server_key, |x| (x % modulus != scalar as u64) as u64)?;
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct_left, &acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct_left, &acc)?;
|
||||
ct_left.degree.0 = 1;
|
||||
Ok(())
|
||||
}
|
||||
@@ -387,7 +387,7 @@ impl ShortintEngine {
|
||||
scalar: u8,
|
||||
) -> EngineResult<()> {
|
||||
let acc = self.generate_accumulator(server_key, |x| (x >= scalar as u64) as u64)?;
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct_left, &acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct_left, &acc)?;
|
||||
ct_left.degree.0 = 1;
|
||||
Ok(())
|
||||
}
|
||||
@@ -410,7 +410,7 @@ impl ShortintEngine {
|
||||
scalar: u8,
|
||||
) -> EngineResult<()> {
|
||||
let acc = self.generate_accumulator(server_key, |x| (x <= scalar as u64) as u64)?;
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct_left, &acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct_left, &acc)?;
|
||||
ct_left.degree.0 = 1;
|
||||
Ok(())
|
||||
}
|
||||
@@ -433,7 +433,7 @@ impl ShortintEngine {
|
||||
scalar: u8,
|
||||
) -> EngineResult<()> {
|
||||
let acc = self.generate_accumulator(server_key, |x| (x > scalar as u64) as u64)?;
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct_left, &acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct_left, &acc)?;
|
||||
ct_left.degree.0 = 1;
|
||||
Ok(())
|
||||
}
|
||||
@@ -456,7 +456,7 @@ impl ShortintEngine {
|
||||
scalar: u8,
|
||||
) -> EngineResult<()> {
|
||||
let acc = self.generate_accumulator(server_key, |x| (x < scalar as u64) as u64)?;
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct_left, &acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct_left, &acc)?;
|
||||
ct_left.degree.0 = 1;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ impl ShortintEngine {
|
||||
assert_ne!(scalar, 0);
|
||||
//generate the accumulator for the multiplication
|
||||
let acc = self.generate_accumulator(server_key, |x| x / (scalar as u64))?;
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct, &acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct, &acc)?;
|
||||
ct.degree = Degree(ct.degree.0 / scalar as usize);
|
||||
Ok(())
|
||||
}
|
||||
@@ -123,7 +123,7 @@ impl ShortintEngine {
|
||||
) -> EngineResult<()> {
|
||||
assert_ne!(modulus, 0);
|
||||
let acc = self.generate_accumulator(server_key, |x| x % modulus as u64)?;
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct, &acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct, &acc)?;
|
||||
ct.degree = Degree(modulus as usize - 1);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -156,18 +156,18 @@ impl ShortintEngine {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn programmable_bootstrap_keyswitch(
|
||||
pub(crate) fn keyswitch_programmable_bootstrap(
|
||||
&mut self,
|
||||
server_key: &ServerKey,
|
||||
ct: &Ciphertext,
|
||||
acc: &GlweCiphertextOwned<u64>,
|
||||
) -> EngineResult<Ciphertext> {
|
||||
let mut ct_res = ct.clone();
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, &mut ct_res, acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, &mut ct_res, acc)?;
|
||||
Ok(ct_res)
|
||||
}
|
||||
|
||||
pub(crate) fn programmable_bootstrap_keyswitch_assign(
|
||||
pub(crate) fn keyswitch_programmable_bootstrap_assign(
|
||||
&mut self,
|
||||
server_key: &ServerKey,
|
||||
ct: &mut Ciphertext,
|
||||
@@ -210,7 +210,7 @@ impl ShortintEngine {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn programmable_bootstrap_keyswitch_bivariate(
|
||||
pub(crate) fn keyswitch_programmable_bootstrap_bivariate(
|
||||
&mut self,
|
||||
server_key: &ServerKey,
|
||||
ct_left: &Ciphertext,
|
||||
@@ -218,7 +218,7 @@ impl ShortintEngine {
|
||||
acc: &GlweCiphertextOwned<u64>,
|
||||
) -> EngineResult<Ciphertext> {
|
||||
let mut ct_res = ct_left.clone();
|
||||
self.programmable_bootstrap_keyswitch_bivariate_assign(
|
||||
self.keyswitch_programmable_bootstrap_bivariate_assign(
|
||||
server_key,
|
||||
&mut ct_res,
|
||||
ct_right,
|
||||
@@ -227,7 +227,7 @@ impl ShortintEngine {
|
||||
Ok(ct_res)
|
||||
}
|
||||
|
||||
pub(crate) fn programmable_bootstrap_keyswitch_bivariate_assign(
|
||||
pub(crate) fn keyswitch_programmable_bootstrap_bivariate_assign(
|
||||
&mut self,
|
||||
server_key: &ServerKey,
|
||||
ct_left: &mut Ciphertext,
|
||||
@@ -243,7 +243,7 @@ impl ShortintEngine {
|
||||
self.unchecked_add_assign(ct_left, ct_right)?;
|
||||
|
||||
// Compute the PBS
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct_left, acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct_left, acc)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -296,7 +296,7 @@ impl ShortintEngine {
|
||||
let acc = self.generate_accumulator(server_key, f)?;
|
||||
|
||||
// Compute the PBS
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct_left, &acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct_left, &acc)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -348,7 +348,7 @@ impl ShortintEngine {
|
||||
self.unchecked_add_assign(ct_left, ct_right)?;
|
||||
|
||||
// Compute the PBS
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct_left, acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct_left, acc)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -361,7 +361,7 @@ impl ShortintEngine {
|
||||
|
||||
let accumulator = self.generate_accumulator(server_key, |x| x / modulus)?;
|
||||
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct, &accumulator)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct, &accumulator)?;
|
||||
|
||||
// The degree of the carry
|
||||
ct.degree = Degree(min(modulus - 1, ct.degree.0 as u64 / modulus) as usize);
|
||||
@@ -387,7 +387,7 @@ impl ShortintEngine {
|
||||
|
||||
let acc = self.generate_accumulator(server_key, |x| x % modulus)?;
|
||||
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct, &acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct, &acc)?;
|
||||
|
||||
ct.degree = Degree(ct.message_modulus.0 - 1);
|
||||
Ok(())
|
||||
|
||||
@@ -36,7 +36,7 @@ impl ShortintEngine {
|
||||
((x / modulus) * (x % modulus)) % res_modulus
|
||||
})?;
|
||||
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct_left, &acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct_left, &acc)?;
|
||||
ct_left.degree = Degree(ct_left.message_modulus.0 - 1);
|
||||
Ok(())
|
||||
}
|
||||
@@ -76,7 +76,7 @@ impl ShortintEngine {
|
||||
((x / modulus) * (x % modulus)) / res_modulus
|
||||
})?;
|
||||
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct_left, &acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct_left, &acc)?;
|
||||
|
||||
ct_left.degree = Degree(deg);
|
||||
Ok(())
|
||||
@@ -101,8 +101,8 @@ impl ShortintEngine {
|
||||
let acc_sub =
|
||||
self.generate_accumulator(server_key, |x| (((x - z) * (x - z)) / 4) % modulus)?;
|
||||
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, &mut ct_tmp_left, &acc_add)?;
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, &mut ct_tmp_right, &acc_sub)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, &mut ct_tmp_left, &acc_add)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, &mut ct_tmp_right, &acc_sub)?;
|
||||
|
||||
//Last subtraction might fill one bit of carry
|
||||
self.unchecked_sub(server_key, &ct_tmp_left, &ct_tmp_right)
|
||||
|
||||
@@ -70,7 +70,7 @@ impl ShortintEngine {
|
||||
} else {
|
||||
// If the scalar is too large, PBS is used to compute the scalar mul
|
||||
let acc = self.generate_accumulator(server_key, |x| (scalar as u64 + x) % modulus)?;
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct, &acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct, &acc)?;
|
||||
ct.degree = Degree(server_key.message_modulus.0 - 1);
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -56,7 +56,7 @@ impl ShortintEngine {
|
||||
// If the ciphertext cannot be multiplied without exceeding the degree max
|
||||
else {
|
||||
let acc = self.generate_accumulator(server_key, |x| (scalar as u64 * x) % modulus)?;
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ctxt, &acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ctxt, &acc)?;
|
||||
ctxt.degree = Degree(server_key.message_modulus.0 - 1);
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -57,7 +57,7 @@ impl ShortintEngine {
|
||||
let scalar = u64::from(scalar);
|
||||
// If the scalar is too large, PBS is used to compute the scalar mul
|
||||
let acc = self.generate_accumulator(server_key, |x| (x - scalar) % modulus)?;
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct, &acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct, &acc)?;
|
||||
ct.degree = Degree(server_key.message_modulus.0 - 1);
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -21,7 +21,7 @@ impl ShortintEngine {
|
||||
shift: u8,
|
||||
) -> EngineResult<()> {
|
||||
let acc = self.generate_accumulator(server_key, |x| x >> shift)?;
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct, &acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct, &acc)?;
|
||||
|
||||
ct.degree = Degree(ct.degree.0 >> shift);
|
||||
Ok(())
|
||||
@@ -69,7 +69,7 @@ impl ShortintEngine {
|
||||
} else {
|
||||
let modulus = server_key.message_modulus.0 as u64;
|
||||
let acc = self.generate_accumulator(server_key, |x| (x << shift) % modulus)?;
|
||||
self.programmable_bootstrap_keyswitch_assign(server_key, ct, &acc)?;
|
||||
self.keyswitch_programmable_bootstrap_assign(server_key, ct, &acc)?;
|
||||
ct.degree = ct.degree.after_left_shift(shift, modulus as usize);
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -332,7 +332,7 @@ impl ShortintEngine {
|
||||
) -> EngineResult<Ciphertext> {
|
||||
// First PBS to remove the noise
|
||||
let acc = self.generate_accumulator(sks, |x| x)?;
|
||||
let ct_clean = self.programmable_bootstrap_keyswitch(sks, ct_in, &acc)?;
|
||||
let ct_clean = self.keyswitch_programmable_bootstrap(sks, ct_in, &acc)?;
|
||||
|
||||
let mut buffer_lwe_after_ks = LweCiphertextOwned::new(
|
||||
0,
|
||||
|
||||
@@ -248,7 +248,7 @@ impl ServerKey {
|
||||
) -> Ciphertext {
|
||||
ShortintEngine::with_thread_local_mut(|engine| {
|
||||
engine
|
||||
.programmable_bootstrap_keyswitch_bivariate(self, ct_left, ct_right, acc)
|
||||
.keyswitch_programmable_bootstrap_bivariate(self, ct_left, ct_right, acc)
|
||||
.unwrap()
|
||||
})
|
||||
}
|
||||
@@ -261,7 +261,7 @@ impl ServerKey {
|
||||
) {
|
||||
ShortintEngine::with_thread_local_mut(|engine| {
|
||||
engine
|
||||
.programmable_bootstrap_keyswitch_bivariate_assign(self, ct_left, ct_right, acc)
|
||||
.keyswitch_programmable_bootstrap_bivariate_assign(self, ct_left, ct_right, acc)
|
||||
.unwrap()
|
||||
})
|
||||
}
|
||||
@@ -296,7 +296,7 @@ impl ServerKey {
|
||||
) -> Ciphertext {
|
||||
ShortintEngine::with_thread_local_mut(|engine| {
|
||||
engine
|
||||
.programmable_bootstrap_keyswitch(self, ct_in, acc)
|
||||
.keyswitch_programmable_bootstrap(self, ct_in, acc)
|
||||
.unwrap()
|
||||
})
|
||||
}
|
||||
@@ -308,7 +308,7 @@ impl ServerKey {
|
||||
) {
|
||||
ShortintEngine::with_thread_local_mut(|engine| {
|
||||
engine
|
||||
.programmable_bootstrap_keyswitch_assign(self, ct_in, acc)
|
||||
.keyswitch_programmable_bootstrap_assign(self, ct_in, acc)
|
||||
.unwrap()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user