diff --git a/tfhe/src/integer/gpu/mod.rs b/tfhe/src/integer/gpu/mod.rs index ed27a12574..7982ce9987 100644 --- a/tfhe/src/integer/gpu/mod.rs +++ b/tfhe/src/integer/gpu/mod.rs @@ -82,7 +82,7 @@ where ks_level: wopbs_params.ks_level, message_modulus: wopbs_params.message_modulus, carry_modulus: wopbs_params.carry_modulus, - max_noise_level: crate::shortint::parameters::MaxNoiseLevel::from_msg_carry_modulus( + max_noise_level: crate::shortint::parameters::MaxNoiseLevel::integer_radix_server_key( wopbs_params.message_modulus, wopbs_params.carry_modulus, ), diff --git a/tfhe/src/integer/mod.rs b/tfhe/src/integer/mod.rs index 03ae281b20..99ffc7a7de 100755 --- a/tfhe/src/integer/mod.rs +++ b/tfhe/src/integer/mod.rs @@ -132,7 +132,7 @@ where ks_level: wopbs_params.ks_level, message_modulus: wopbs_params.message_modulus, carry_modulus: wopbs_params.carry_modulus, - max_noise_level: crate::shortint::parameters::MaxNoiseLevel::from_msg_carry_modulus( + max_noise_level: crate::shortint::parameters::MaxNoiseLevel::integer_radix_server_key( wopbs_params.message_modulus, wopbs_params.carry_modulus, ), diff --git a/tfhe/src/integer/server_key/mod.rs b/tfhe/src/integer/server_key/mod.rs index ef29e26187..5660147abf 100644 --- a/tfhe/src/integer/server_key/mod.rs +++ b/tfhe/src/integer/server_key/mod.rs @@ -15,7 +15,7 @@ use crate::integer::client_key::ClientKey; use crate::shortint::ciphertext::{Degree, MaxDegree}; /// Error returned when the carry buffer is full. pub use crate::shortint::CheckError; -use crate::shortint::{CarryModulus, MessageModulus, PBSParameters}; +use crate::shortint::{CarryModulus, MaxNoiseLevel, MessageModulus, PBSParameters}; pub use radix::scalar_mul::ScalarMultiplier; pub use radix::scalar_sub::TwosComplementNegation; pub use radix_parallel::{MatchValues, MiniUnsignedInteger, Reciprocable}; @@ -51,16 +51,14 @@ impl MaxDegree { message_modulus: MessageModulus, carry_modulus: CarryModulus, ) -> Self { - let full_max_degree = message_modulus.0 * carry_modulus.0 - 1; + let full_max_degree = Self::from_msg_carry_modulus(message_modulus, carry_modulus).get(); let carry_max_degree = carry_modulus.0 - 1; // We want to be have a margin to add a carry from another block Self::new(full_max_degree - carry_max_degree) } -} -impl MaxDegree { /// Compute the [`MaxDegree`] for an integer server key (compressed or uncompressed). /// This is tailored for [`CrtCiphertext`](`crate::integer::CrtCiphertext`) and not compatible /// for use with [`RadixCiphertext`](`crate::integer::RadixCiphertext`). @@ -68,9 +66,27 @@ impl MaxDegree { message_modulus: MessageModulus, carry_modulus: CarryModulus, ) -> Self { - let full_max_degree = message_modulus.0 * carry_modulus.0 - 1; + Self::from_msg_carry_modulus(message_modulus, carry_modulus) + } +} - Self::new(full_max_degree) +impl MaxNoiseLevel { + /// Compute the [`MaxNoiseLevel`] for an integer server key (compressed or uncompressed). + /// To allow carry propagation between shortint blocks in a + /// [`RadixCiphertext`](`crate::integer::RadixCiphertext`) (which includes adding the extracted + /// carry from one shortint block to the next block), this formula provisions space to add a + /// carry. + pub(crate) fn integer_radix_server_key( + message_modulus: MessageModulus, + carry_modulus: CarryModulus, + ) -> Self { + let full_max_noise_level = + Self::from_msg_carry_modulus(message_modulus, carry_modulus).get(); + + let carry_max_noise_level = 1; + + // We want to be have a margin to add a carry from another block + Self::new(full_max_noise_level - carry_max_noise_level) } }