Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeul-zama committed Sep 26, 2024
1 parent 21f14d7 commit 7259c00
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
22 changes: 13 additions & 9 deletions tfhe/src/high_level_api/keys/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::integer::compression_keys::{
use crate::integer::public_key::CompactPublicKey;
use crate::integer::CompressedCompactPublicKey;
use crate::shortint::key_switching_key::KeySwitchingKeyConformanceParams;
use crate::shortint::list_compression::CompressionConformanceParameters;
use crate::shortint::parameters::list_compression::CompressionParameters;
use crate::shortint::{MessageModulus, PBSParameters};
use crate::Error;
Expand Down Expand Up @@ -451,10 +450,11 @@ impl IntegerCompressedCompactPublicKey {
}
}

#[allow(clippy::struct_field_names)]
pub struct IntegerServerKeyConformanceParams {
pub sk: PBSParameters,
pub sk_param: PBSParameters,
pub cpk_param: Option<KeySwitchingKeyConformanceParams>,
pub compression_param: Option<CompressionConformanceParameters>,
pub compression_param: Option<CompressionParameters>,
}

impl ParameterSetConformant for IntegerServerKey {
Expand Down Expand Up @@ -486,13 +486,15 @@ impl ParameterSetConformant for IntegerServerKey {
) {
(None, None, None) => true,
(Some(compression_key), Some(decompression_key), Some(compression_param)) => {
compression_key.is_conformant(compression_param)
&& decompression_key.is_conformant(compression_param)
let compression_param = (parameter_set.sk_param, *compression_param).into();

compression_key.is_conformant(&compression_param)
&& decompression_key.is_conformant(&compression_param)
}
_ => false,
};

key.is_conformant(&parameter_set.sk)
key.is_conformant(&parameter_set.sk_param)
&& cpk_key_switching_key_material_is_ok
&& compression_is_ok
}
Expand Down Expand Up @@ -527,13 +529,15 @@ impl ParameterSetConformant for IntegerCompressedServerKey {
) {
(None, None, None) => true,
(Some(compression_key), Some(decompression_key), Some(compression_param)) => {
compression_key.is_conformant(compression_param)
&& decompression_key.is_conformant(compression_param)
let compression_param = (parameter_set.sk_param, *compression_param).into();

compression_key.is_conformant(&compression_param)
&& decompression_key.is_conformant(&compression_param)
}
_ => return false,
};

key.is_conformant(&parameter_set.sk)
key.is_conformant(&parameter_set.sk_param)
&& cpk_key_switching_key_material_is_ok
&& compression_is_ok
}
Expand Down
18 changes: 6 additions & 12 deletions tfhe/src/high_level_api/keys/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,12 @@ mod test {
let ck = crate::ClientKey::generate(config);
let sk = crate::ServerKey::new(&ck);

let sk_params = PBSParameters::PBS(PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64);

let compression_param =
(sk_params, COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64).into();
let sk_param = PBSParameters::PBS(PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64);

let conformance_params = IntegerServerKeyConformanceParams {
sk: PBSParameters::PBS(PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64),
sk_param,
cpk_param: None,
compression_param: Some(compression_param),
compression_param: Some(COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64),
};

assert!(sk.is_conformant(&conformance_params));
Expand All @@ -377,15 +374,12 @@ mod test {
let ck = crate::ClientKey::generate(config);
let sk = crate::CompressedServerKey::new(&ck);

let sk_params = PBSParameters::PBS(PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64);

let compression_param =
(sk_params, COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64).into();
let sk_param = PBSParameters::PBS(PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64);

let conformance_params = IntegerServerKeyConformanceParams {
sk: PBSParameters::PBS(PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64),
sk_param,
cpk_param: None,
compression_param: Some(compression_param),
compression_param: Some(COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64),
};

assert!(sk.is_conformant(&conformance_params));
Expand Down

0 comments on commit 7259c00

Please sign in to comment.