chore(tfhe): rename lwe_linear_algebra algorithms

This commit is contained in:
Arthur Meyre
2022-12-12 14:53:19 +01:00
committed by jborfila
parent 914007383f
commit 952f70fdf9
11 changed files with 37 additions and 37 deletions

View File

@@ -316,17 +316,17 @@ impl BooleanEngine {
// Compute the linear combination for first AND: ct_condition + ct_then +
// (0,...,0,-1/8)
lwe_ciphertext_addition(buffer_lwe_before_pbs, ct_condition_ct, &ct_then_ct);
lwe_ciphertext_add(buffer_lwe_before_pbs, ct_condition_ct, &ct_then_ct);
let cst = Plaintext(PLAINTEXT_FALSE);
lwe_ciphertext_plaintext_addition_assign(buffer_lwe_before_pbs, cst); // - 1/8
lwe_ciphertext_plaintext_add_assign(buffer_lwe_before_pbs, cst); // - 1/8
// Compute the linear combination for second AND: - ct_condition + ct_else +
// (0,...,0,-1/8)
let mut ct_temp_2 = ct_condition_ct.clone(); // ct_condition
lwe_ciphertext_opposite_assign(&mut ct_temp_2); // compute the negation
lwe_ciphertext_addition_assign(&mut ct_temp_2, &ct_else_ct); // + ct_else
lwe_ciphertext_add_assign(&mut ct_temp_2, &ct_else_ct); // + ct_else
let cst = Plaintext(PLAINTEXT_FALSE);
lwe_ciphertext_plaintext_addition_assign(&mut ct_temp_2, cst); // - 1/8
lwe_ciphertext_plaintext_add_assign(&mut ct_temp_2, cst); // - 1/8
// Compute the first programmable bootstrapping with fixed test polynomial:
let mut ct_pbs_1 = bootstrapper
@@ -337,9 +337,9 @@ impl BooleanEngine {
// Compute the linear combination to add the two results:
// buffer_lwe_pbs + ct_pbs_2 + (0,...,0, +1/8)
lwe_ciphertext_addition_assign(&mut ct_pbs_1, &ct_pbs_2); // + buffer_lwe_pbs
lwe_ciphertext_add_assign(&mut ct_pbs_1, &ct_pbs_2); // + buffer_lwe_pbs
let cst = Plaintext(PLAINTEXT_TRUE);
lwe_ciphertext_plaintext_addition_assign(&mut ct_pbs_1, cst); // + 1/8
lwe_ciphertext_plaintext_add_assign(&mut ct_pbs_1, cst); // + 1/8
let ct_ks = bootstrapper.keyswitch(&ct_pbs_1, server_key).unwrap();
@@ -380,10 +380,10 @@ impl BinaryGatesEngine<&Ciphertext, &Ciphertext, ServerKey> for BooleanEngine {
// compute the linear combination for AND: ct_left + ct_right + (0,...,0,-1/8)
// ct_left + ct_right
lwe_ciphertext_addition(&mut buffer_lwe_before_pbs, ct_left_ct, ct_right_ct);
lwe_ciphertext_add(&mut buffer_lwe_before_pbs, ct_left_ct, ct_right_ct);
let cst = Plaintext(PLAINTEXT_FALSE);
// - 1/8
lwe_ciphertext_plaintext_addition_assign(&mut buffer_lwe_before_pbs, cst);
lwe_ciphertext_plaintext_add_assign(&mut buffer_lwe_before_pbs, cst);
// compute the bootstrap and the key switch
bootstrapper
@@ -421,11 +421,11 @@ impl BinaryGatesEngine<&Ciphertext, &Ciphertext, ServerKey> for BooleanEngine {
// Compute the linear combination for NAND: - ct_left - ct_right + (0,...,0,1/8)
// ct_left + ct_right
lwe_ciphertext_addition(&mut buffer_lwe_before_pbs, ct_left_ct, ct_right_ct);
lwe_ciphertext_add(&mut buffer_lwe_before_pbs, ct_left_ct, ct_right_ct);
lwe_ciphertext_opposite_assign(&mut buffer_lwe_before_pbs);
let cst = Plaintext(PLAINTEXT_TRUE);
// + 1/8
lwe_ciphertext_plaintext_addition_assign(&mut buffer_lwe_before_pbs, cst);
lwe_ciphertext_plaintext_add_assign(&mut buffer_lwe_before_pbs, cst);
// compute the bootstrap and the key switch
bootstrapper
@@ -463,12 +463,12 @@ impl BinaryGatesEngine<&Ciphertext, &Ciphertext, ServerKey> for BooleanEngine {
// Compute the linear combination for NOR: - ct_left - ct_right + (0,...,0,-1/8)
// ct_left + ct_right
lwe_ciphertext_addition(&mut buffer_lwe_before_pbs, ct_left_ct, ct_right_ct);
lwe_ciphertext_add(&mut buffer_lwe_before_pbs, ct_left_ct, ct_right_ct);
// compute the negation
lwe_ciphertext_opposite_assign(&mut buffer_lwe_before_pbs);
let cst = Plaintext(PLAINTEXT_FALSE);
// - 1/8
lwe_ciphertext_plaintext_addition_assign(&mut buffer_lwe_before_pbs, cst);
lwe_ciphertext_plaintext_add_assign(&mut buffer_lwe_before_pbs, cst);
// compute the bootstrap and the key switch
bootstrapper
@@ -506,10 +506,10 @@ impl BinaryGatesEngine<&Ciphertext, &Ciphertext, ServerKey> for BooleanEngine {
// Compute the linear combination for OR: ct_left + ct_right + (0,...,0,+1/8)
// ct_left + ct_right
lwe_ciphertext_addition(&mut buffer_lwe_before_pbs, ct_left_ct, ct_right_ct);
lwe_ciphertext_add(&mut buffer_lwe_before_pbs, ct_left_ct, ct_right_ct);
let cst = Plaintext(PLAINTEXT_TRUE);
// + 1/8
lwe_ciphertext_plaintext_addition_assign(&mut buffer_lwe_before_pbs, cst);
lwe_ciphertext_plaintext_add_assign(&mut buffer_lwe_before_pbs, cst);
// compute the bootstrap and the key switch
bootstrapper
@@ -547,13 +547,13 @@ impl BinaryGatesEngine<&Ciphertext, &Ciphertext, ServerKey> for BooleanEngine {
// Compute the linear combination for XOR: 2*(ct_left + ct_right) + (0,...,0,1/4)
// ct_left + ct_right
lwe_ciphertext_addition(&mut buffer_lwe_before_pbs, ct_left_ct, ct_right_ct);
lwe_ciphertext_add(&mut buffer_lwe_before_pbs, ct_left_ct, ct_right_ct);
let cst_add = Plaintext(PLAINTEXT_TRUE);
// + 1/8
lwe_ciphertext_plaintext_addition_assign(&mut buffer_lwe_before_pbs, cst_add);
lwe_ciphertext_plaintext_add_assign(&mut buffer_lwe_before_pbs, cst_add);
let cst_mul = Cleartext(2u32);
//* 2
lwe_ciphertext_cleartext_multiplication_assign(&mut buffer_lwe_before_pbs, cst_mul);
lwe_ciphertext_cleartext_mul_assign(&mut buffer_lwe_before_pbs, cst_mul);
// compute the bootstrap and the key switch
bootstrapper
@@ -591,15 +591,15 @@ impl BinaryGatesEngine<&Ciphertext, &Ciphertext, ServerKey> for BooleanEngine {
// Compute the linear combination for XNOR: 2*(-ct_left - ct_right + (0,...,0,-1/8))
// ct_left + ct_right
lwe_ciphertext_addition(&mut buffer_lwe_before_pbs, ct_left_ct, ct_right_ct);
lwe_ciphertext_add(&mut buffer_lwe_before_pbs, ct_left_ct, ct_right_ct);
let cst_add = Plaintext(PLAINTEXT_TRUE);
// + 1/8
lwe_ciphertext_plaintext_addition_assign(&mut buffer_lwe_before_pbs, cst_add);
lwe_ciphertext_plaintext_add_assign(&mut buffer_lwe_before_pbs, cst_add);
// compute the negation
lwe_ciphertext_opposite_assign(&mut buffer_lwe_before_pbs);
let cst_mul = Cleartext(2u32);
//* 2
lwe_ciphertext_cleartext_multiplication_assign(&mut buffer_lwe_before_pbs, cst_mul);
lwe_ciphertext_cleartext_mul_assign(&mut buffer_lwe_before_pbs, cst_mul);
// compute the bootstrap and the key switch
bootstrapper

View File

@@ -742,7 +742,7 @@ pub fn encrypt_lwe_ciphertext_with_public_key<Scalar, KeyCont, OutputCont, Gen>(
// Add the public encryption of zeros to get the zero encryption
for (&chosen, public_encryption_of_zero) in ct_choice.iter().zip(lwe_public_key.iter()) {
if chosen == Scalar::ONE {
lwe_ciphertext_addition_assign(output, &public_encryption_of_zero);
lwe_ciphertext_add_assign(output, &public_encryption_of_zero);
}
}

View File

@@ -6,7 +6,7 @@ use crate::core_crypto::commons::numeric::UnsignedInteger;
use crate::core_crypto::commons::traits::*;
use crate::core_crypto::entities::*;
pub fn lwe_ciphertext_addition_assign<Scalar, LhsCont, RhsCont>(
pub fn lwe_ciphertext_add_assign<Scalar, LhsCont, RhsCont>(
lhs: &mut LweCiphertext<LhsCont>,
rhs: &LweCiphertext<RhsCont>,
) where
@@ -17,7 +17,7 @@ pub fn lwe_ciphertext_addition_assign<Scalar, LhsCont, RhsCont>(
slice_wrapping_add_assign(lhs.as_mut(), rhs.as_ref());
}
pub fn lwe_ciphertext_addition<Scalar, OutputCont, LhsCont, RhsCont>(
pub fn lwe_ciphertext_add<Scalar, OutputCont, LhsCont, RhsCont>(
output: &mut LweCiphertext<OutputCont>,
lhs: &LweCiphertext<LhsCont>,
rhs: &LweCiphertext<RhsCont>,
@@ -30,7 +30,7 @@ pub fn lwe_ciphertext_addition<Scalar, OutputCont, LhsCont, RhsCont>(
slice_wrapping_add(output.as_mut(), lhs.as_ref(), rhs.as_ref());
}
pub fn lwe_ciphertext_plaintext_addition_assign<Scalar, InCont>(
pub fn lwe_ciphertext_plaintext_add_assign<Scalar, InCont>(
lhs: &mut LweCiphertext<InCont>,
rhs: Plaintext<Scalar>,
) where
@@ -50,7 +50,7 @@ where
slice_wrapping_opposite_assign(ct.as_mut());
}
pub fn lwe_ciphertext_cleartext_multiplication_assign<Scalar, InCont>(
pub fn lwe_ciphertext_cleartext_mul_assign<Scalar, InCont>(
lhs: &mut LweCiphertext<InCont>,
rhs: Cleartext<Scalar>,
) where
@@ -60,7 +60,7 @@ pub fn lwe_ciphertext_cleartext_multiplication_assign<Scalar, InCont>(
slice_wrapping_scalar_mul_assign(lhs.as_mut(), rhs.0);
}
pub fn lwe_ciphertext_subtraction_assign<Scalar, LhsCont, RhsCont>(
pub fn lwe_ciphertext_sub_assign<Scalar, LhsCont, RhsCont>(
lhs: &mut LweCiphertext<LhsCont>,
rhs: &LweCiphertext<RhsCont>,
) where
@@ -71,7 +71,7 @@ pub fn lwe_ciphertext_subtraction_assign<Scalar, LhsCont, RhsCont>(
slice_wrapping_sub_assign(lhs.as_mut(), rhs.as_ref());
}
pub fn lwe_ciphertext_cleartext_multiplication<Scalar, InputCont, OutputCont>(
pub fn lwe_ciphertext_cleartext_mul<Scalar, InputCont, OutputCont>(
output: &mut LweCiphertext<OutputCont>,
lhs: &LweCiphertext<InputCont>,
rhs: Cleartext<Scalar>,
@@ -81,5 +81,5 @@ pub fn lwe_ciphertext_cleartext_multiplication<Scalar, InputCont, OutputCont>(
OutputCont: ContainerMut<Element = Scalar>,
{
output.as_mut().copy_from_slice(lhs.as_ref());
lwe_ciphertext_cleartext_multiplication_assign(output, rhs);
lwe_ciphertext_cleartext_mul_assign(output, rhs);
}

View File

@@ -348,7 +348,7 @@ pub fn homomorphic_shift_boolean<Scalar: UnsignedTorus + CastInto<usize>>(
let mut lwe_left_shift_buffer = LweCiphertext::from_container(&mut *lwe_left_shift_buffer_data);
// Shift message LSB on padding bit, at this point we expect to have messages with only 1 bit
// of information
lwe_ciphertext_cleartext_multiplication(
lwe_ciphertext_cleartext_mul(
&mut lwe_left_shift_buffer,
&lwe_in,
Cleartext(Scalar::ONE << (ciphertext_n_bits - delta_log.0 - 1)),

View File

@@ -19,7 +19,7 @@ impl ShortintEngine {
ct_left: &mut Ciphertext,
ct_right: &Ciphertext,
) -> EngineResult<()> {
lwe_ciphertext_addition_assign(&mut ct_left.ct, &ct_right.ct);
lwe_ciphertext_add_assign(&mut ct_left.ct, &ct_right.ct);
ct_left.degree = Degree(ct_left.degree.0 + ct_right.degree.0);
Ok(())
}

View File

@@ -54,7 +54,7 @@ impl ShortintEngine {
// (0,Delta*z) - ct
lwe_ciphertext_opposite_assign(&mut ct.ct);
lwe_ciphertext_plaintext_addition_assign(&mut ct.ct, w);
lwe_ciphertext_plaintext_add_assign(&mut ct.ct, w);
// Update the degree
ct.degree = Degree(z as usize);

View File

@@ -23,7 +23,7 @@ impl ShortintEngine {
let delta = (1_u64 << 63) / (ct.message_modulus.0 * ct.carry_modulus.0) as u64;
let shift_plaintext = u64::from(scalar) * delta;
let encoded_scalar = Plaintext(shift_plaintext);
lwe_ciphertext_plaintext_addition_assign(&mut ct.ct, encoded_scalar);
lwe_ciphertext_plaintext_add_assign(&mut ct.ct, encoded_scalar);
ct.degree = Degree(ct.degree.0 + scalar as usize);
Ok(())
@@ -39,7 +39,7 @@ impl ShortintEngine {
(1_u64 << 63) / (server_key.message_modulus.0 * server_key.carry_modulus.0) as u64;
let shift_plaintext = u64::from(scalar) * delta;
let encoded_scalar = Plaintext(shift_plaintext);
lwe_ciphertext_plaintext_addition_assign(&mut ct.ct, encoded_scalar);
lwe_ciphertext_plaintext_add_assign(&mut ct.ct, encoded_scalar);
ct.degree = Degree(ct.degree.0 + scalar as usize);
Ok(())

View File

@@ -23,7 +23,7 @@ impl ShortintEngine {
) -> EngineResult<()> {
let scalar = u64::from(scalar);
let cleartext_scalar = Cleartext(scalar);
lwe_ciphertext_cleartext_multiplication_assign(&mut ct.ct, cleartext_scalar);
lwe_ciphertext_cleartext_mul_assign(&mut ct.ct, cleartext_scalar);
ct.degree = Degree(ct.degree.0 * scalar as usize);
Ok(())

View File

@@ -25,7 +25,7 @@ impl ShortintEngine {
let shift_plaintext = neg_scalar * delta;
let encoded_scalar = Plaintext(shift_plaintext);
lwe_ciphertext_plaintext_addition_assign(&mut ct.ct, encoded_scalar);
lwe_ciphertext_plaintext_add_assign(&mut ct.ct, encoded_scalar);
ct.degree = Degree(ct.degree.0 + neg_scalar as usize);
Ok(())

View File

@@ -46,7 +46,7 @@ impl ShortintEngine {
) -> EngineResult<u64> {
let (neg_right, z) = self.unchecked_neg_with_z(server_key, ct_right)?;
lwe_ciphertext_addition_assign(&mut ct_left.ct, &neg_right.ct);
lwe_ciphertext_add_assign(&mut ct_left.ct, &neg_right.ct);
ct_left.degree = Degree(ct_left.degree.0 + z as usize);

View File

@@ -466,7 +466,7 @@ impl ShortintEngine {
(1 << (64 - nb_bit_to_extract - 1)) - (1 << (64 - nb_bit_to_extract - 5));
let tmp = LweCiphertextOwned::from_container(cont);
lwe_ciphertext_subtraction_assign(&mut ct_in.ct, &tmp);
lwe_ciphertext_sub_assign(&mut ct_in.ct, &tmp);
let ciphertext = self.extract_bits_circuit_bootstrapping(
wopbs_key,