Skip to content

Commit

Permalink
feat(shortint): update noise level in operations
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeul-zama committed Oct 23, 2023
1 parent 4059dad commit 92cfa11
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions tfhe/src/shortint/engine/server_side/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl ShortintEngine {
) -> EngineResult<()> {
lwe_ciphertext_add_assign(&mut ct_left.ct, &ct_right.ct);
ct_left.degree = Degree(ct_left.degree.0 + ct_right.degree.0);
ct_left.noise_level += ct_right.noise_level;
Ok(())
}

Expand Down
6 changes: 5 additions & 1 deletion tfhe/src/shortint/engine/server_side/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::core_crypto::commons::parameters::{
use crate::core_crypto::entities::*;
use crate::core_crypto::fft_impl::fft64::crypto::bootstrap::FourierLweBootstrapKey;
use crate::core_crypto::fft_impl::fft64::math::fft::Fft;
use crate::shortint::ciphertext::Degree;
use crate::shortint::ciphertext::{Degree, NoiseLevel};
use crate::shortint::engine::EngineResult;
use crate::shortint::parameters::{MessageModulus, ShortintKeySwitchingParameters};
use crate::shortint::server_key::{
Expand Down Expand Up @@ -368,6 +368,7 @@ impl ShortintEngine {
};

ct.degree = acc.degree;
ct.noise_level = NoiseLevel::NOMINAL;

Ok(())
}
Expand Down Expand Up @@ -630,6 +631,7 @@ impl ShortintEngine {
);

ct.degree = acc.degree;
ct.noise_level = NoiseLevel::NOMINAL;

Ok(())
}
Expand Down Expand Up @@ -778,6 +780,8 @@ impl ShortintEngine {
trivially_encrypt_lwe_ciphertext(&mut ct.ct, encoded);

ct.degree = Degree(modular_value);
ct.noise_level = NoiseLevel::ZERO;

Ok(())
}
}
4 changes: 3 additions & 1 deletion tfhe/src/shortint/engine/server_side/scalar_mul.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::core_crypto::algorithms::*;
use crate::core_crypto::entities::*;
use crate::shortint::ciphertext::Degree;
use crate::shortint::ciphertext::{Degree, NoiseLevel};
use crate::shortint::engine::{EngineResult, ShortintEngine};
use crate::shortint::{Ciphertext, ServerKey};

Expand All @@ -24,6 +24,7 @@ impl ShortintEngine {
match scalar {
0 => {
trivially_encrypt_lwe_ciphertext(&mut ct.ct, Plaintext(0));
ct.noise_level = NoiseLevel::ZERO;
ct.degree = Degree(0);
}
1 => {
Expand All @@ -34,6 +35,7 @@ impl ShortintEngine {
let cleartext_scalar = Cleartext(scalar);
lwe_ciphertext_cleartext_mul_assign(&mut ct.ct, cleartext_scalar);

ct.noise_level *= scalar as usize;
ct.degree = Degree(ct.degree.0 * scalar as usize);
}
}
Expand Down
1 change: 1 addition & 0 deletions tfhe/src/shortint/engine/server_side/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl ShortintEngine {

lwe_ciphertext_add_assign(&mut ct_left.ct, &neg_right.ct);

ct_left.noise_level += ct_right.noise_level;
ct_left.degree = Degree(ct_left.degree.0 + z as usize);

Ok(z)
Expand Down

0 comments on commit 92cfa11

Please sign in to comment.