From 325fe6e2a55ee08ca7382b14deb065dbc5cacd8e Mon Sep 17 00:00:00 2001 From: Nicolas Sarlin Date: Fri, 20 Dec 2024 14:59:52 +0100 Subject: [PATCH] chore(shortint): move tuniform 0.10 parameters into their own folder --- .../tuniform/p_fail_2_minus_64/ks_pbs.rs | 20 ----------------- .../p_fail_2_minus_64/ks_pbs.rs | 12 ---------- .../key_switching/p_fail_2_minus_64/ks_pbs.rs | 19 ---------------- tfhe/src/shortint/parameters/mod.rs | 3 +++ .../shortint/parameters/v0_10/classic/mod.rs | 1 + .../parameters/v0_10/classic/tuniform/mod.rs | 1 + .../tuniform/p_fail_2_minus_64/ks_pbs.rs | 22 +++++++++++++++++++ .../classic/tuniform/p_fail_2_minus_64/mod.rs | 1 + .../v0_10/compact_public_key_only/mod.rs | 1 + .../p_fail_2_minus_64/ks_pbs.rs | 19 ++++++++++++++++ .../p_fail_2_minus_64/mod.rs | 1 + .../parameters/v0_10/key_switching/mod.rs | 1 + .../key_switching/p_fail_2_minus_64/ks_pbs.rs | 22 +++++++++++++++++++ .../key_switching/p_fail_2_minus_64/mod.rs | 1 + tfhe/src/shortint/parameters/v0_10/mod.rs | 6 +++++ 15 files changed, 79 insertions(+), 51 deletions(-) create mode 100644 tfhe/src/shortint/parameters/v0_10/classic/tuniform/mod.rs create mode 100644 tfhe/src/shortint/parameters/v0_10/classic/tuniform/p_fail_2_minus_64/ks_pbs.rs create mode 100644 tfhe/src/shortint/parameters/v0_10/classic/tuniform/p_fail_2_minus_64/mod.rs create mode 100644 tfhe/src/shortint/parameters/v0_10/compact_public_key_only/mod.rs create mode 100644 tfhe/src/shortint/parameters/v0_10/compact_public_key_only/p_fail_2_minus_64/ks_pbs.rs create mode 100644 tfhe/src/shortint/parameters/v0_10/compact_public_key_only/p_fail_2_minus_64/mod.rs create mode 100644 tfhe/src/shortint/parameters/v0_10/key_switching/mod.rs create mode 100644 tfhe/src/shortint/parameters/v0_10/key_switching/p_fail_2_minus_64/ks_pbs.rs create mode 100644 tfhe/src/shortint/parameters/v0_10/key_switching/p_fail_2_minus_64/mod.rs diff --git a/tfhe/src/shortint/parameters/classic/tuniform/p_fail_2_minus_64/ks_pbs.rs b/tfhe/src/shortint/parameters/classic/tuniform/p_fail_2_minus_64/ks_pbs.rs index f915ce79ec..2388e43ca1 100644 --- a/tfhe/src/shortint/parameters/classic/tuniform/p_fail_2_minus_64/ks_pbs.rs +++ b/tfhe/src/shortint/parameters/classic/tuniform/p_fail_2_minus_64/ks_pbs.rs @@ -24,23 +24,3 @@ pub const V0_11_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64: ClassicPBSParamete ciphertext_modulus: CiphertextModulus::new_native(), encryption_key_choice: EncryptionKeyChoice::Big, }; - -// security = 132 bits, p-fail = 2^-64.138, algorithmic cost ~ 113, 2-norm = 5 -pub const V0_10_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64: ClassicPBSParameters = - ClassicPBSParameters { - lwe_dimension: LweDimension(887), - glwe_dimension: GlweDimension(1), - polynomial_size: PolynomialSize(2048), - lwe_noise_distribution: DynamicDistribution::new_t_uniform(46), - glwe_noise_distribution: DynamicDistribution::new_t_uniform(17), - pbs_base_log: DecompositionBaseLog(22), - pbs_level: DecompositionLevelCount(1), - ks_base_log: DecompositionBaseLog(3), - ks_level: DecompositionLevelCount(5), - message_modulus: MessageModulus(4), - carry_modulus: CarryModulus(4), - max_noise_level: MaxNoiseLevel::new(5), - log2_p_fail: -64.138, - ciphertext_modulus: CiphertextModulus::new_native(), - encryption_key_choice: EncryptionKeyChoice::Big, - }; diff --git a/tfhe/src/shortint/parameters/compact_public_key_only/p_fail_2_minus_64/ks_pbs.rs b/tfhe/src/shortint/parameters/compact_public_key_only/p_fail_2_minus_64/ks_pbs.rs index f1999d86c9..2b38c8269a 100644 --- a/tfhe/src/shortint/parameters/compact_public_key_only/p_fail_2_minus_64/ks_pbs.rs +++ b/tfhe/src/shortint/parameters/compact_public_key_only/p_fail_2_minus_64/ks_pbs.rs @@ -44,15 +44,3 @@ pub const V0_11_PARAM_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64_ZKV1: expansion_kind: CompactCiphertextListExpansionKind::RequiresCasting, } .validate(); - -/// This legacy parameter set were used with the v1 pke zk scheme on TFHE-rs v0.10 and lower -pub const V0_10_PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64_ZKV1: - CompactPublicKeyEncryptionParameters = CompactPublicKeyEncryptionParameters { - encryption_lwe_dimension: LweDimension(1024), - encryption_noise_distribution: DynamicDistribution::new_t_uniform(42), - message_modulus: MessageModulus(4), - carry_modulus: CarryModulus(4), - ciphertext_modulus: CiphertextModulus::new_native(), - expansion_kind: CompactCiphertextListExpansionKind::RequiresCasting, -} -.validate(); diff --git a/tfhe/src/shortint/parameters/key_switching/p_fail_2_minus_64/ks_pbs.rs b/tfhe/src/shortint/parameters/key_switching/p_fail_2_minus_64/ks_pbs.rs index f63c877e3c..33fd3a2678 100644 --- a/tfhe/src/shortint/parameters/key_switching/p_fail_2_minus_64/ks_pbs.rs +++ b/tfhe/src/shortint/parameters/key_switching/p_fail_2_minus_64/ks_pbs.rs @@ -52,22 +52,3 @@ pub const V0_11_PARAM_KEYSWITCH_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M6 ks_base_log: DecompositionBaseLog(24), destination_key: EncryptionKeyChoice::Big, }; - -// These are the same parameters as they where defined in TFHE-rs 0.10 and before -pub const V0_10_PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64: - ShortintKeySwitchingParameters = - V0_10_PARAM_KEYSWITCH_PKE_TO_SMALL_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64; - -pub const V0_10_PARAM_KEYSWITCH_PKE_TO_SMALL_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64: - ShortintKeySwitchingParameters = ShortintKeySwitchingParameters { - ks_level: DecompositionLevelCount(5), - ks_base_log: DecompositionBaseLog(3), - destination_key: EncryptionKeyChoice::Small, -}; - -pub const V0_10_PARAM_KEYSWITCH_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64: - ShortintKeySwitchingParameters = ShortintKeySwitchingParameters { - ks_level: DecompositionLevelCount(1), - ks_base_log: DecompositionBaseLog(27), - destination_key: EncryptionKeyChoice::Big, -}; diff --git a/tfhe/src/shortint/parameters/mod.rs b/tfhe/src/shortint/parameters/mod.rs index d82413ba70..33b34fd7a1 100644 --- a/tfhe/src/shortint/parameters/mod.rs +++ b/tfhe/src/shortint/parameters/mod.rs @@ -58,6 +58,9 @@ pub use crate::shortint::parameters::v0_10::classic::compact_pk::gaussian::p_fai pub use crate::shortint::parameters::v0_10::classic::gaussian::p_fail_2_minus_64::ks_pbs::*; pub use crate::shortint::parameters::v0_10::classic::gaussian::p_fail_2_minus_64::pbs_ks::*; pub use crate::shortint::parameters::v0_10::multi_bit::gaussian::p_fail_2_minus_64::ks_pbs::*; +pub use crate::shortint::parameters::v0_10::classic::tuniform::p_fail_2_minus_64::ks_pbs::*; +pub use crate::shortint::parameters::v0_10::key_switching::p_fail_2_minus_64::ks_pbs::*; +pub use crate::shortint::parameters::v0_10::compact_public_key_only::p_fail_2_minus_64::ks_pbs::*; #[cfg(tarpaulin)] pub use coverage_parameters::*; diff --git a/tfhe/src/shortint/parameters/v0_10/classic/mod.rs b/tfhe/src/shortint/parameters/v0_10/classic/mod.rs index bab9016ea5..6a760df77f 100644 --- a/tfhe/src/shortint/parameters/v0_10/classic/mod.rs +++ b/tfhe/src/shortint/parameters/v0_10/classic/mod.rs @@ -1,2 +1,3 @@ pub mod compact_pk; pub mod gaussian; +pub mod tuniform; diff --git a/tfhe/src/shortint/parameters/v0_10/classic/tuniform/mod.rs b/tfhe/src/shortint/parameters/v0_10/classic/tuniform/mod.rs new file mode 100644 index 0000000000..55c2d9ab42 --- /dev/null +++ b/tfhe/src/shortint/parameters/v0_10/classic/tuniform/mod.rs @@ -0,0 +1 @@ +pub mod p_fail_2_minus_64; diff --git a/tfhe/src/shortint/parameters/v0_10/classic/tuniform/p_fail_2_minus_64/ks_pbs.rs b/tfhe/src/shortint/parameters/v0_10/classic/tuniform/p_fail_2_minus_64/ks_pbs.rs new file mode 100644 index 0000000000..639a94a273 --- /dev/null +++ b/tfhe/src/shortint/parameters/v0_10/classic/tuniform/p_fail_2_minus_64/ks_pbs.rs @@ -0,0 +1,22 @@ +use crate::core_crypto::prelude::*; +use crate::shortint::{CarryModulus, ClassicPBSParameters, MaxNoiseLevel, MessageModulus}; + +// security = 132 bits, p-fail = 2^-64.138, algorithmic cost ~ 113, 2-norm = 5 +pub const V0_10_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64: ClassicPBSParameters = + ClassicPBSParameters { + lwe_dimension: LweDimension(887), + glwe_dimension: GlweDimension(1), + polynomial_size: PolynomialSize(2048), + lwe_noise_distribution: DynamicDistribution::new_t_uniform(46), + glwe_noise_distribution: DynamicDistribution::new_t_uniform(17), + pbs_base_log: DecompositionBaseLog(22), + pbs_level: DecompositionLevelCount(1), + ks_base_log: DecompositionBaseLog(3), + ks_level: DecompositionLevelCount(5), + message_modulus: MessageModulus(4), + carry_modulus: CarryModulus(4), + max_noise_level: MaxNoiseLevel::new(5), + log2_p_fail: -64.138, + ciphertext_modulus: CiphertextModulus::new_native(), + encryption_key_choice: EncryptionKeyChoice::Big, + }; diff --git a/tfhe/src/shortint/parameters/v0_10/classic/tuniform/p_fail_2_minus_64/mod.rs b/tfhe/src/shortint/parameters/v0_10/classic/tuniform/p_fail_2_minus_64/mod.rs new file mode 100644 index 0000000000..cf32dbe64e --- /dev/null +++ b/tfhe/src/shortint/parameters/v0_10/classic/tuniform/p_fail_2_minus_64/mod.rs @@ -0,0 +1 @@ +pub mod ks_pbs; diff --git a/tfhe/src/shortint/parameters/v0_10/compact_public_key_only/mod.rs b/tfhe/src/shortint/parameters/v0_10/compact_public_key_only/mod.rs new file mode 100644 index 0000000000..55c2d9ab42 --- /dev/null +++ b/tfhe/src/shortint/parameters/v0_10/compact_public_key_only/mod.rs @@ -0,0 +1 @@ +pub mod p_fail_2_minus_64; diff --git a/tfhe/src/shortint/parameters/v0_10/compact_public_key_only/p_fail_2_minus_64/ks_pbs.rs b/tfhe/src/shortint/parameters/v0_10/compact_public_key_only/p_fail_2_minus_64/ks_pbs.rs new file mode 100644 index 0000000000..d83f0e3aef --- /dev/null +++ b/tfhe/src/shortint/parameters/v0_10/compact_public_key_only/p_fail_2_minus_64/ks_pbs.rs @@ -0,0 +1,19 @@ +use crate::core_crypto::commons::parameters::{ + CiphertextModulus, DynamicDistribution, LweDimension, +}; +use crate::shortint::parameters::{ + CarryModulus, CompactCiphertextListExpansionKind, CompactPublicKeyEncryptionParameters, + MessageModulus, +}; + +/// This legacy parameter set were used with the v1 pke zk scheme on TFHE-rs v0.10 and lower +pub const V0_10_PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64_ZKV1: + CompactPublicKeyEncryptionParameters = CompactPublicKeyEncryptionParameters { + encryption_lwe_dimension: LweDimension(1024), + encryption_noise_distribution: DynamicDistribution::new_t_uniform(42), + message_modulus: MessageModulus(4), + carry_modulus: CarryModulus(4), + ciphertext_modulus: CiphertextModulus::new_native(), + expansion_kind: CompactCiphertextListExpansionKind::RequiresCasting, +} +.validate(); diff --git a/tfhe/src/shortint/parameters/v0_10/compact_public_key_only/p_fail_2_minus_64/mod.rs b/tfhe/src/shortint/parameters/v0_10/compact_public_key_only/p_fail_2_minus_64/mod.rs new file mode 100644 index 0000000000..cf32dbe64e --- /dev/null +++ b/tfhe/src/shortint/parameters/v0_10/compact_public_key_only/p_fail_2_minus_64/mod.rs @@ -0,0 +1 @@ +pub mod ks_pbs; diff --git a/tfhe/src/shortint/parameters/v0_10/key_switching/mod.rs b/tfhe/src/shortint/parameters/v0_10/key_switching/mod.rs new file mode 100644 index 0000000000..55c2d9ab42 --- /dev/null +++ b/tfhe/src/shortint/parameters/v0_10/key_switching/mod.rs @@ -0,0 +1 @@ +pub mod p_fail_2_minus_64; diff --git a/tfhe/src/shortint/parameters/v0_10/key_switching/p_fail_2_minus_64/ks_pbs.rs b/tfhe/src/shortint/parameters/v0_10/key_switching/p_fail_2_minus_64/ks_pbs.rs new file mode 100644 index 0000000000..e0d12960e7 --- /dev/null +++ b/tfhe/src/shortint/parameters/v0_10/key_switching/p_fail_2_minus_64/ks_pbs.rs @@ -0,0 +1,22 @@ +use crate::shortint::parameters::{ + DecompositionBaseLog, DecompositionLevelCount, EncryptionKeyChoice, + ShortintKeySwitchingParameters, +}; + +pub const V0_10_PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64: + ShortintKeySwitchingParameters = + V0_10_PARAM_KEYSWITCH_PKE_TO_SMALL_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64; + +pub const V0_10_PARAM_KEYSWITCH_PKE_TO_SMALL_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64: + ShortintKeySwitchingParameters = ShortintKeySwitchingParameters { + ks_level: DecompositionLevelCount(5), + ks_base_log: DecompositionBaseLog(3), + destination_key: EncryptionKeyChoice::Small, +}; + +pub const V0_10_PARAM_KEYSWITCH_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64: + ShortintKeySwitchingParameters = ShortintKeySwitchingParameters { + ks_level: DecompositionLevelCount(1), + ks_base_log: DecompositionBaseLog(27), + destination_key: EncryptionKeyChoice::Big, +}; diff --git a/tfhe/src/shortint/parameters/v0_10/key_switching/p_fail_2_minus_64/mod.rs b/tfhe/src/shortint/parameters/v0_10/key_switching/p_fail_2_minus_64/mod.rs new file mode 100644 index 0000000000..cf32dbe64e --- /dev/null +++ b/tfhe/src/shortint/parameters/v0_10/key_switching/p_fail_2_minus_64/mod.rs @@ -0,0 +1 @@ +pub mod ks_pbs; diff --git a/tfhe/src/shortint/parameters/v0_10/mod.rs b/tfhe/src/shortint/parameters/v0_10/mod.rs index 076b39dc75..94ce0d066b 100644 --- a/tfhe/src/shortint/parameters/v0_10/mod.rs +++ b/tfhe/src/shortint/parameters/v0_10/mod.rs @@ -1,2 +1,8 @@ +//! FHE Parameters as they were defined in TFHE-rs 0.10 and before. +//! +//! These parameters may be used for backward compatibility. + pub mod classic; +pub mod compact_public_key_only; +pub mod key_switching; pub mod multi_bit;