Skip to content

Commit

Permalink
refactor(hlapi): remove wopbs_block_parameters from IntegerConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeul-zama committed Jun 27, 2024
1 parent 773adcc commit caf5b42
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 64 deletions.
3 changes: 1 addition & 2 deletions tfhe/benches/high_level_api/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ bench_type!(FheUint64);
bench_type!(FheUint128);

fn main() {
let config =
ConfigBuilder::with_custom_parameters(PARAM_MESSAGE_2_CARRY_2_KS_PBS, None).build();
let config = ConfigBuilder::with_custom_parameters(PARAM_MESSAGE_2_CARRY_2_KS_PBS).build();
let cks = ClientKey::generate(config);
let compressed_sks = CompressedServerKey::new(&cks);

Expand Down
2 changes: 1 addition & 1 deletion tfhe/examples/dist_tuniform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
my_params.glwe_noise_distribution = DynamicDistribution::new_t_uniform(10);

let config = ConfigBuilder::default()
.use_custom_parameters(my_params, None)
.use_custom_parameters(my_params)
.build();

let (keys, server_keys) = generate_keys(config);
Expand Down
14 changes: 6 additions & 8 deletions tfhe/examples/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,12 @@ fn main() -> Result<(), std::io::Error> {
println!("key gen start");
let config = match args.multibit {
None => ConfigBuilder::default(),
Some(2) => ConfigBuilder::with_custom_parameters(
PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_2_KS_PBS,
None,
),
Some(3) => ConfigBuilder::with_custom_parameters(
PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS,
None,
),
Some(2) => {
ConfigBuilder::with_custom_parameters(PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_2_KS_PBS)
}
Some(3) => {
ConfigBuilder::with_custom_parameters(PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS)
}
Some(v) => {
panic!("Invalid multibit setting {v}");
}
Expand Down
8 changes: 4 additions & 4 deletions tfhe/examples/utilities/hlapi_compact_pk_ct_sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn cpk_and_cctl_sizes(results_file: &Path) {
{
let params = PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS;
let config = ConfigBuilder::default()
.use_custom_parameters(params, None)
.use_custom_parameters(params)
.build();
let (client_key, _) = generate_keys(config);
let test_name = format!("hlapi_sizes_{}_cpk", params.name());
Expand Down Expand Up @@ -99,7 +99,7 @@ pub fn cpk_and_cctl_sizes(results_file: &Path) {
{
let params = PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS;
let config = ConfigBuilder::default()
.use_custom_parameters(params, None)
.use_custom_parameters(params)
.build();
let (client_key, _) = generate_keys(config);
let test_name = format!("hlapi_sizes_{}_cpk", params.name());
Expand Down Expand Up @@ -158,7 +158,7 @@ pub fn cpk_and_cctl_sizes(results_file: &Path) {
{
let params = PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS;
let config = ConfigBuilder::default()
.use_custom_parameters(params, None)
.use_custom_parameters(params)
.build();
let (client_key, _) = generate_keys(config);

Expand Down Expand Up @@ -206,7 +206,7 @@ pub fn cpk_and_cctl_sizes(results_file: &Path) {
{
let params = PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS;
let config = ConfigBuilder::default()
.use_custom_parameters(params, None)
.use_custom_parameters(params)
.build();
let (client_key, _) = generate_keys(config);

Expand Down
4 changes: 1 addition & 3 deletions tfhe/src/c_api/high_level_api/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ pub unsafe extern "C" fn config_builder_use_custom_parameters(
let params: crate::shortint::ClassicPBSParameters =
shortint_block_parameters.try_into().unwrap();

let inner = Box::from_raw(*builder)
.0
.use_custom_parameters(params, None);
let inner = Box::from_raw(*builder).0.use_custom_parameters(params);
*builder = Box::into_raw(Box::new(ConfigBuilder(inner)));
})
}
Expand Down
4 changes: 2 additions & 2 deletions tfhe/src/high_level_api/booleans/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ mod cpu {
fn test_safe_deserialize_conformant_fhe_bool() {
let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS;
let (client_key, server_key) =
generate_keys(ConfigBuilder::with_custom_parameters(block_params, None));
generate_keys(ConfigBuilder::with_custom_parameters(block_params));
set_server_key(server_key.clone());

let clear_a = random::<bool>();
Expand All @@ -698,7 +698,7 @@ mod cpu {
fn test_safe_deserialize_conformant_compressed_fhe_bool() {
let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS;
let (client_key, server_key) =
generate_keys(ConfigBuilder::with_custom_parameters(block_params, None));
generate_keys(ConfigBuilder::with_custom_parameters(block_params));
set_server_key(server_key.clone());
let clear_a = random::<bool>();
let a = CompressedFheBool::encrypt(clear_a, &client_key);
Expand Down
2 changes: 0 additions & 2 deletions tfhe/src/high_level_api/compact_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ mod tests {

let config = crate::ConfigBuilder::with_custom_parameters(
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64,
None,
)
.build();

Expand Down Expand Up @@ -446,7 +445,6 @@ mod tests {

let config = crate::ConfigBuilder::with_custom_parameters(
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64,
None,
)
.use_dedicated_compact_public_key_parameters((
PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64,
Expand Down
1 change: 0 additions & 1 deletion tfhe/src/high_level_api/compressed_ciphertext_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ mod tests {
fn test_compressed_ct_list() {
let config = crate::ConfigBuilder::with_custom_parameters(
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64,
None,
)
.enable_compression(COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64)
.build();
Expand Down
16 changes: 4 additions & 12 deletions tfhe/src/high_level_api/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,13 @@ impl ConfigBuilder {
}
}

pub fn with_custom_parameters<P>(
block_parameters: P,
wopbs_block_parameters: Option<crate::shortint::WopbsParameters>,
) -> Self
pub fn with_custom_parameters<P>(block_parameters: P) -> Self
where
P: Into<crate::shortint::PBSParameters>,
{
Self {
config: Config {
inner: IntegerConfig::new(block_parameters.into(), wopbs_block_parameters, None),
inner: IntegerConfig::new(block_parameters.into()),
},
}
}
Expand All @@ -96,16 +93,11 @@ impl ConfigBuilder {
self
}

pub fn use_custom_parameters<P>(
mut self,
block_parameters: P,
wopbs_block_parameters: Option<crate::shortint::WopbsParameters>,
) -> Self
pub fn use_custom_parameters<P>(mut self, block_parameters: P) -> Self
where
P: Into<crate::shortint::PBSParameters>,
{
self.config.inner =
IntegerConfig::new(block_parameters.into(), wopbs_block_parameters, None);
self.config.inner = IntegerConfig::new(block_parameters.into());
self
}

Expand Down
8 changes: 2 additions & 6 deletions tfhe/src/high_level_api/integers/signed/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ fn test_multi_bit_rotate() {
let config = ConfigBuilder::default()
.use_custom_parameters(
crate::shortint::parameters::PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS,
None,
)
.build();
fhe_int64_rotate(config);
Expand Down Expand Up @@ -368,7 +367,6 @@ fn test_multi_div_rem() {
let config = ConfigBuilder::default()
.use_custom_parameters(
crate::shortint::parameters::PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS,
None,
)
.build();
fhe_int32_div_rem(config);
Expand Down Expand Up @@ -546,7 +544,6 @@ fn test_compact_public_key_big() {
let config = ConfigBuilder::default()
.use_custom_parameters(
crate::shortint::parameters::classic::compact_pk::PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS,
None,
)
.build();
let (client_key, _) = generate_keys(config);
Expand All @@ -567,7 +564,6 @@ fn test_compact_public_key_small() {
let config = ConfigBuilder::default()
.use_custom_parameters(
crate::shortint::parameters::classic::compact_pk::PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS,
None,
)
.build();
let (client_key, _) = generate_keys(config);
Expand Down Expand Up @@ -646,7 +642,7 @@ fn test_leading_trailing_zeros_ones() {
fn test_safe_deserialize_conformant_fhe_int32() {
let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS;
let (client_key, server_key) =
generate_keys(ConfigBuilder::with_custom_parameters(block_params, None));
generate_keys(ConfigBuilder::with_custom_parameters(block_params));
set_server_key(server_key.clone());

let clear_a = random::<i32>();
Expand All @@ -668,7 +664,7 @@ fn test_safe_deserialize_conformant_fhe_int32() {
fn test_safe_deserialize_conformant_compressed_fhe_int32() {
let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS;
let (client_key, server_key) =
generate_keys(ConfigBuilder::with_custom_parameters(block_params, None));
generate_keys(ConfigBuilder::with_custom_parameters(block_params));
set_server_key(server_key.clone());

let clear_a = random::<i32>();
Expand Down
18 changes: 9 additions & 9 deletions tfhe/src/high_level_api/integers/unsigned/tests/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rand::prelude::*;
fn setup_cpu(params: Option<impl Into<PBSParameters>>) -> ClientKey {
let config = params
.map_or_else(ConfigBuilder::default, |p| {
ConfigBuilder::with_custom_parameters(p.into(), None)
ConfigBuilder::with_custom_parameters(p.into())
})
.build();

Expand Down Expand Up @@ -108,7 +108,7 @@ fn test_uint32_shift() {
#[test]
fn test_uint32_shift_multibit() {
let config = ConfigBuilder::default()
.use_custom_parameters(PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS, None)
.use_custom_parameters(PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS)
.build();

let (client_key, server_key) = generate_keys(config);
Expand Down Expand Up @@ -196,7 +196,7 @@ fn test_decompressed_public_key_encrypt() {
#[test]
fn test_compact_public_key_big() {
let config = ConfigBuilder::default()
.use_custom_parameters(PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS, None)
.use_custom_parameters(PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS)
.build();
let (client_key, _) = generate_keys(config);

Expand All @@ -214,7 +214,7 @@ fn test_compact_public_key_big() {
#[test]
fn test_compact_public_key_small() {
let config = ConfigBuilder::default()
.use_custom_parameters(PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS, None)
.use_custom_parameters(PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS)
.build();
let (client_key, _) = generate_keys(config);

Expand Down Expand Up @@ -401,7 +401,7 @@ fn test_sum() {
fn test_safe_deserialize_conformant_fhe_uint32() {
let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS;
let (client_key, server_key) =
generate_keys(ConfigBuilder::with_custom_parameters(block_params, None));
generate_keys(ConfigBuilder::with_custom_parameters(block_params));
set_server_key(server_key.clone());

let clear_a = random::<u32>();
Expand All @@ -422,7 +422,7 @@ fn test_safe_deserialize_conformant_fhe_uint32() {
fn test_safe_deserialize_conformant_compressed_fhe_uint32() {
let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS;
let (client_key, server_key) =
generate_keys(ConfigBuilder::with_custom_parameters(block_params, None));
generate_keys(ConfigBuilder::with_custom_parameters(block_params));
set_server_key(server_key.clone());

let clear_a = random::<u32>();
Expand All @@ -445,7 +445,7 @@ fn test_safe_deserialize_conformant_compressed_fhe_uint32() {
fn test_safe_deserialize_conformant_compact_fhe_uint32() {
let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS;
let (client_key, server_key) =
generate_keys(ConfigBuilder::with_custom_parameters(block_params, None));
generate_keys(ConfigBuilder::with_custom_parameters(block_params));
set_server_key(server_key);
let pk = CompactPublicKey::new(&client_key);

Expand Down Expand Up @@ -491,7 +491,7 @@ fn test_cpk_encrypt_cast_compute_hl() {
let modulus = param_fhe.message_modulus.0.pow(num_block as u32) as u64;

let (client_key, server_key) = generate_keys(
ConfigBuilder::with_custom_parameters(param_fhe, None)
ConfigBuilder::with_custom_parameters(param_fhe)
.use_dedicated_compact_public_key_parameters((param_pke_only, param_ksk)),
);
set_server_key(server_key);
Expand Down Expand Up @@ -539,7 +539,7 @@ fn test_compressed_cpk_encrypt_cast_compute_hl() {

let modulus = param_fhe.message_modulus.0.pow(num_block as u32) as u64;

let config = ConfigBuilder::with_custom_parameters(param_fhe, None)
let config = ConfigBuilder::with_custom_parameters(param_fhe)
.use_dedicated_compact_public_key_parameters((param_pke_only, param_ksk))
.build();
let client_key = ClientKey::generate(config);
Expand Down
15 changes: 2 additions & 13 deletions tfhe/src/high_level_api/keys/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use tfhe_versionable::Versionize;
#[allow(clippy::struct_field_names)]
pub(crate) struct IntegerConfig {
pub(crate) block_parameters: crate::shortint::PBSParameters,
pub(crate) wopbs_block_parameters: Option<crate::shortint::WopbsParameters>,
pub(crate) dedicated_compact_public_key_parameters: Option<(
crate::shortint::parameters::CompactPublicKeyEncryptionParameters,
crate::shortint::parameters::ShortintKeySwitchingParameters,
Expand All @@ -29,26 +28,17 @@ pub(crate) struct IntegerConfig {
}

impl IntegerConfig {
pub(crate) fn new(
block_parameters: crate::shortint::PBSParameters,
wopbs_block_parameters: Option<crate::shortint::WopbsParameters>,
dedicated_compact_public_key_parameters: Option<(
crate::shortint::parameters::CompactPublicKeyEncryptionParameters,
crate::shortint::parameters::ShortintKeySwitchingParameters,
)>,
) -> Self {
pub(crate) fn new(block_parameters: crate::shortint::PBSParameters) -> Self {
Self {
block_parameters,
wopbs_block_parameters,
dedicated_compact_public_key_parameters,
dedicated_compact_public_key_parameters: None,
compression_parameters: None,
}
}

pub(in crate::high_level_api) fn default_big() -> Self {
Self {
block_parameters: crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS.into(),
wopbs_block_parameters: None,
dedicated_compact_public_key_parameters: None,
compression_parameters: None,
}
Expand All @@ -57,7 +47,6 @@ impl IntegerConfig {
pub(in crate::high_level_api) fn default_small() -> Self {
Self {
block_parameters: crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_PBS_KS.into(),
wopbs_block_parameters: None,
dedicated_compact_public_key_parameters: None,
compression_parameters: None,
}
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/js_on_wasm_api/js_high_level_api/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl TfheConfigBuilder {
self,
block_parameters: &crate::js_on_wasm_api::shortint::ShortintParameters,
) -> Self {
Self(self.0.use_custom_parameters(block_parameters.0, None))
Self(self.0.use_custom_parameters(block_parameters.0))
}

#[wasm_bindgen]
Expand Down

0 comments on commit caf5b42

Please sign in to comment.