Skip to content

Commit

Permalink
fix(shortint): add ciphertext_modulus_after_packing_ks to compression…
Browse files Browse the repository at this point in the history
… parameters
  • Loading branch information
mayeul-zama committed Jan 2, 2025
1 parent a9d48c7 commit 5b02635
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tfhe/src/integer/gpu/client_key/radix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl RadixClientKey {
params.packing_ks_base_log,
params.packing_ks_level,
params.packing_ks_key_noise_distribution,
self.parameters().ciphertext_modulus(),
params.ciphertext_modulus_after_packing_ks,
&mut engine.encryption_generator,
)
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl ClientKey {
params.packing_ks_base_log,
params.packing_ks_level,
params.packing_ks_key_noise_distribution,
self.parameters.ciphertext_modulus(),
params.ciphertext_modulus_after_packing_ks,
&mut engine.seeder,
)
});
Expand Down
17 changes: 13 additions & 4 deletions tfhe/src/shortint/list_compression/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ impl CompressionKey {
let lwe_pksk = &self.packing_key_switching_key;

let polynomial_size = lwe_pksk.output_polynomial_size();
let ciphertext_modulus = lwe_pksk.ciphertext_modulus();

let out_ciphertext_modulus = lwe_pksk.ciphertext_modulus();

let glwe_size = lwe_pksk.output_glwe_size();
let lwe_size = lwe_pksk.input_key_lwe_dimension().to_lwe_size();

Expand All @@ -43,6 +45,7 @@ impl CompressionKey {
let message_modulus = first_ct.message_modulus;
let carry_modulus = first_ct.carry_modulus;
let pbs_order = first_ct.pbs_order;
let in_ciphertext_modulus = first_ct.ct.ciphertext_modulus();

assert!(
message_modulus.0 <= carry_modulus.0,
Expand Down Expand Up @@ -86,6 +89,12 @@ impl CompressionKey {
"All ciphertexts do not have the same pbs order"
);

assert_eq!(
in_ciphertext_modulus,
ct.ct.ciphertext_modulus(),
"All ciphertexts do not have the same ciphertext modulus"
);

let mut ct = ct.clone();
let max_noise_level =
MaxNoiseLevel::new((ct.noise_level() * message_modulus.0).get());
Expand All @@ -94,12 +103,12 @@ impl CompressionKey {
list.extend(ct.ct.as_ref());
}

let list = LweCiphertextList::from_container(list, lwe_size, ciphertext_modulus);
let list = LweCiphertextList::from_container(list, lwe_size, in_ciphertext_modulus);

let bodies_count = LweCiphertextCount(ct_list.len());

let mut out =
GlweCiphertext::new(0, glwe_size, polynomial_size, ciphertext_modulus);
GlweCiphertext::new(0, glwe_size, polynomial_size, out_ciphertext_modulus);

par_keyswitch_lwe_ciphertext_list_and_pack_in_glwe_ciphertext(
lwe_pksk, &list, &mut out,
Expand All @@ -120,7 +129,7 @@ impl CompressionKey {
pbs_order,
lwe_per_glwe,
count,
ciphertext_modulus,
ciphertext_modulus: out_ciphertext_modulus,
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions tfhe/src/shortint/list_compression/server_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl ClientKey {
params.packing_ks_base_log,
params.packing_ks_level,
params.packing_ks_key_noise_distribution,
self.parameters.ciphertext_modulus(),
params.ciphertext_modulus_after_packing_ks,
&mut engine.encryption_generator,
)
});
Expand Down Expand Up @@ -116,6 +116,7 @@ pub struct CompressionConformanceParameters {
pub packing_ks_base_log: DecompositionBaseLog,
pub packing_ks_polynomial_size: PolynomialSize,
pub packing_ks_glwe_dimension: GlweDimension,
pub ciphertext_modulus_after_packing_ks: CiphertextModulus<u64>,
pub lwe_per_glwe: LweCiphertextCount,
pub storage_log_modulus: CiphertextModulusLog,
pub uncompressed_polynomial_size: PolynomialSize,
Expand All @@ -132,6 +133,8 @@ impl From<(PBSParameters, CompressionParameters)> for CompressionConformancePara
packing_ks_base_log: compression_params.packing_ks_base_log,
packing_ks_polynomial_size: compression_params.packing_ks_polynomial_size,
packing_ks_glwe_dimension: compression_params.packing_ks_glwe_dimension,
ciphertext_modulus_after_packing_ks: compression_params
.ciphertext_modulus_after_packing_ks,
lwe_per_glwe: compression_params.lwe_per_glwe,
storage_log_modulus: compression_params.storage_log_modulus,
uncompressed_polynomial_size: pbs_params.polynomial_size(),
Expand Down Expand Up @@ -159,7 +162,7 @@ impl ParameterSetConformant for CompressionKey {
.to_equivalent_lwe_dimension(parameter_set.uncompressed_polynomial_size),
output_glwe_size: parameter_set.packing_ks_glwe_dimension.to_glwe_size(),
output_polynomial_size: parameter_set.packing_ks_polynomial_size,
ciphertext_modulus: parameter_set.cipherext_modulus,
ciphertext_modulus: parameter_set.ciphertext_modulus_after_packing_ks,
};

packing_key_switching_key.is_conformant(&params)
Expand Down
3 changes: 3 additions & 0 deletions tfhe/src/shortint/parameters/list_compression.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use tfhe_versionable::Versionize;

use super::CiphertextModulus;
use crate::core_crypto::prelude::{CiphertextModulusLog, LweCiphertextCount};
use crate::shortint::backward_compatibility::parameters::list_compression::CompressionParametersVersions;
use crate::shortint::parameters::{
Expand All @@ -20,6 +21,7 @@ pub struct CompressionParameters {
pub lwe_per_glwe: LweCiphertextCount,
pub storage_log_modulus: CiphertextModulusLog,
pub packing_ks_key_noise_distribution: DynamicDistribution<u64>,
pub ciphertext_modulus_after_packing_ks: CiphertextModulus,
}

pub const COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64: CompressionParameters =
Expand All @@ -33,4 +35,5 @@ pub const COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64: CompressionParamete
lwe_per_glwe: LweCiphertextCount(256),
storage_log_modulus: CiphertextModulusLog(12),
packing_ks_key_noise_distribution: DynamicDistribution::new_t_uniform(42),
ciphertext_modulus_after_packing_ks: CiphertextModulus::new_native(),
};

0 comments on commit 5b02635

Please sign in to comment.