chore(shortint): remove the Default impl for Parameters

The rationale behind this is that, `shortint::Parameters::default()`
does not convey the information about how much bit of message
and carry this parameter provides, and so might lead to
errors/confusions.

Instead user will be forced to use the param name like
`PARAM_MESSAGE_2_CARRY_2` which is less ambiguous.

This is obviously a breaking change.
This commit is contained in:
tmontaigu
2023-04-06 16:12:39 +02:00
parent 72e7f16179
commit 412463ed27
15 changed files with 77 additions and 77 deletions

View File

@@ -99,8 +99,9 @@ Another example of how the library can be used with shortints:
use tfhe::shortint::prelude::*;
fn main() {
// Generate a set of client/server keys, using the default parameters:
let (client_key, server_key) = gen_keys(Parameters::default());
// Generate a set of client/server keys
// with 2 bits of message and 2 bits of carry
let (client_key, server_key) = gen_keys(PARAM_MESSAGE_2_CARRY_2);
let msg1 = 3;
let msg2 = 2;

View File

@@ -115,8 +115,9 @@ Use the `--release` flag to run this example (eg: `cargo run --release`)
use tfhe::shortint::prelude::*;
fn main() {
// We generate a set of client/server keys, using the default parameters:
let (client_key, server_key) = gen_keys(Parameters::default());
// We generate a set of client/server keys
// using parameters with 2 bits of message and 2 bits of carry
let (client_key, server_key) = gen_keys(PARAM_MESSAGE_2_CARRY_2);
let msg1 = 1;
let msg2 = 0;

View File

@@ -23,7 +23,7 @@ use tfhe::shortint::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let (client_key, server_key) = gen_keys(Parameters::default());
let (client_key, server_key) = gen_keys(PARAM_MESSAGE_2_CARRY_2);
let msg1 = 1;
let msg2 = 0;

View File

@@ -19,8 +19,8 @@ To reflect that, computation/operation methods are tied to the `ServerKey` type.
use tfhe::shortint::prelude::*;
fn main() {
// We generate a set of client/server keys, using the default parameters:
let (client_key, server_key) = gen_keys(Parameters::default());
// We generate a set of client/server keys
let (client_key, server_key) = gen_keys(PARAM_MESSAGE_2_CARRY_2);
}
```
@@ -32,8 +32,8 @@ Once the keys have been generated, the client key is used to encrypt data:
use tfhe::shortint::prelude::*;
fn main() {
// We generate a set of client/server keys, using the default parameters:
let (client_key, server_key) = gen_keys(Parameters::default());
// We generate a set of client/server keys
let (client_key, server_key) = gen_keys(PARAM_MESSAGE_2_CARRY_2);
let msg1 = 1;
let msg2 = 0;
@@ -52,8 +52,8 @@ Once the keys have been generated, the client key is used to encrypt data:
use tfhe::shortint::prelude::*;
fn main() {
// We generate a set of client/server keys, using the default parameters:
let (client_key, _) = gen_keys(Parameters::default());
// We generate a set of client/server keys
let (client_key, _) = gen_keys(PARAM_MESSAGE_2_CARRY_2);
let public_key = PublicKeyBig::new(&client_key);
let msg1 = 1;
@@ -73,8 +73,8 @@ With our `server_key` and encrypted values, we can now do an addition and then d
use tfhe::shortint::prelude::*;
fn main() {
// We generate a set of client/server keys, using the default parameters:
let (client_key, server_key) = gen_keys(Parameters::default());
// We generate a set of client/server keys
let (client_key, server_key) = gen_keys(PARAM_MESSAGE_2_CARRY_2);
let msg1 = 1;
let msg2 = 0;

View File

@@ -57,11 +57,11 @@ impl ServerKey {
///
/// ```rust
/// use tfhe::integer::gen_keys_crt;
/// use tfhe::shortint::parameters::DEFAULT_PARAMETERS;
/// use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
///
/// // Generate the client key and the server key:
/// let basis = vec![2, 3, 5];
/// let (cks, sks) = gen_keys_crt(&DEFAULT_PARAMETERS, basis);
/// let (cks, sks) = gen_keys_crt(&PARAM_MESSAGE_2_CARRY_2, basis);
///
/// let clear_1 = 28;
///

View File

@@ -56,11 +56,11 @@ impl ServerKey {
///
/// ```rust
/// use tfhe::integer::gen_keys_crt;
/// use tfhe::shortint::parameters::DEFAULT_PARAMETERS;
/// use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
///
/// // Generate the client key and the server key:
/// let basis = vec![2, 3, 5];
/// let (cks, sks) = gen_keys_crt(&DEFAULT_PARAMETERS, basis);
/// let (cks, sks) = gen_keys_crt(&PARAM_MESSAGE_2_CARRY_2, basis);
///
/// let clear_1 = 28;
///

View File

@@ -24,12 +24,12 @@ impl ServerKey {
///
/// ```rust
/// use tfhe::integer::{gen_keys_radix, RadixCiphertextBig};
/// use tfhe::shortint::parameters::DEFAULT_PARAMETERS;
/// use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
///
/// let num_blocks = 4;
///
/// // Generate the client key and the server key:
/// let (cks, sks) = gen_keys_radix(&DEFAULT_PARAMETERS, num_blocks);
/// let (cks, sks) = gen_keys_radix(&PARAM_MESSAGE_2_CARRY_2, num_blocks);
///
/// let ctxt: RadixCiphertextBig = sks.create_trivial_zero_radix(num_blocks);
///

View File

@@ -35,10 +35,10 @@ impl ClientKey {
///
/// ```rust
/// use tfhe::shortint::client_key::ClientKey;
/// use tfhe::shortint::parameters::Parameters;
/// use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
///
/// // Generate the client key:
/// let cks = ClientKey::new(Parameters::default());
/// let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
/// ```
pub fn new(parameters: Parameters) -> ClientKey {
ShortintEngine::with_thread_local_mut(|engine| engine.new_client_key(parameters).unwrap())
@@ -185,11 +185,11 @@ impl ClientKey {
/// # Example
///
/// ```rust
/// use tfhe::shortint::parameters::MessageModulus;
/// use tfhe::shortint::{ClientKey, Parameters};
/// use tfhe::shortint::parameters::{MessageModulus, PARAM_MESSAGE_2_CARRY_2};
/// use tfhe::shortint::ClientKey;
///
/// // Generate the client key
/// let cks = ClientKey::new(Parameters::default());
/// let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
///
/// let msg = 3;
///
@@ -250,11 +250,11 @@ impl ClientKey {
/// # Example
///
/// ```rust
/// use tfhe::shortint::parameters::MessageModulus;
/// use tfhe::shortint::{ClientKey, Parameters};
/// use tfhe::shortint::parameters::{MessageModulus, PARAM_MESSAGE_2_CARRY_2};
/// use tfhe::shortint::ClientKey;
///
/// // Generate the client key
/// let cks = ClientKey::new(Parameters::default());
/// let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
///
/// let msg = 3;
///
@@ -319,10 +319,11 @@ impl ClientKey {
/// # Example
///
/// ```rust
/// use tfhe::shortint::{ClientKey, Parameters};
/// use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
/// use tfhe::shortint::ClientKey;
///
/// // Generate the client key
/// let cks = ClientKey::new(Parameters::default());
/// let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
///
/// let msg = 7;
/// let ct = cks.unchecked_encrypt(msg);
@@ -639,10 +640,11 @@ impl ClientKey {
/// # Example
///
/// ```rust
/// use tfhe::shortint::{ClientKey, Parameters};
/// use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
/// use tfhe::shortint::ClientKey;
///
/// // Generate the client key
/// let cks = ClientKey::new(Parameters::default());
/// let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
///
/// let msg = 2;
/// let modulus = 3;
@@ -701,10 +703,11 @@ impl ClientKey {
/// # Example
///
/// ```rust
/// use tfhe::shortint::{ClientKey, Parameters};
/// use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
/// use tfhe::shortint::ClientKey;
///
/// // Generate the client key
/// let cks = ClientKey::new(Parameters::default());
/// let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
///
/// let msg = 2;
/// let modulus = 3;

View File

@@ -30,7 +30,7 @@
//! use tfhe::shortint::{gen_keys, Parameters};
//!
//! // We generate a set of client/server keys, using the default parameters:
//! let (mut client_key, mut server_key) = gen_keys(Parameters::default());
//! let (mut client_key, mut server_key) = gen_keys(PARAM_MESSAGE_2_CARRY_2);
//!
//! let msg1 = 1;
//! let msg2 = 0;
@@ -78,9 +78,10 @@ pub use server_key::{CheckError, CompressedServerKey, ServerKey};
///
/// ```rust
/// use tfhe::shortint::gen_keys;
/// use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
///
/// // generate the client key and the server key:
/// let (cks, sks) = gen_keys(Default::default());
/// let (cks, sks) = gen_keys(PARAM_MESSAGE_2_CARRY_2);
/// ```
pub fn gen_keys(parameters_set: Parameters) -> (ClientKey, ServerKey) {
let cks = ClientKey::new(parameters_set);

View File

@@ -93,12 +93,6 @@ impl Parameters {
}
}
impl Default for Parameters {
fn default() -> Self {
DEFAULT_PARAMETERS
}
}
/// Vector containing all parameter sets
pub const ALL_PARAMETER_VEC: [Parameters; 28] = WITH_CARRY_PARAMETERS_VEC;
@@ -154,9 +148,6 @@ pub const BIVARIATE_PBS_COMPLIANT_PARAMETER_SET_VEC: [Parameters; 16] = [
PARAM_MESSAGE_4_CARRY_4,
];
/// Default parameter set
pub const DEFAULT_PARAMETERS: Parameters = PARAM_MESSAGE_2_CARRY_2;
/// Nomenclature: PARAM_MESSAGE_X_CARRY_Y: the message (respectively carry) modulus is
/// encoded over X (reps. Y) bits, i.e., message_modulus = 2^{X} (resp. carry_modulus = 2^{Y}).
/// All parameter sets guarantee 128-bits of security and an error probability smaller than
@@ -900,7 +891,7 @@ pub const PARAM_SMALL_MESSAGE_4_CARRY_4: Parameters = Parameters {
/// assert_eq!(param, PARAM_MESSAGE_3_CARRY_1);
/// ```
pub fn get_parameters_from_message_and_carry(msg_space: usize, carry_space: usize) -> Parameters {
let mut out = Parameters::default();
let mut out = PARAM_MESSAGE_2_CARRY_2;
let mut flag: bool = false;
let mut rescaled_message_space = f64::ceil(f64::log2(msg_space as f64)) as usize;
rescaled_message_space = 1 << rescaled_message_space;

View File

@@ -6,7 +6,7 @@ pub use crate::core_crypto::commons::parameters::{
};
use crate::shortint::parameters::parameters_wopbs::*;
use crate::shortint::parameters::parameters_wopbs_prime_moduli::*;
use crate::shortint::parameters::{CarryModulus, MessageModulus};
use crate::shortint::parameters::{CarryModulus, MessageModulus, PARAM_MESSAGE_2_CARRY_2};
use crate::shortint::Parameters;
pub const ALL_PARAMETER_VEC_WOPBS: [Parameters; 116] = [
@@ -943,7 +943,7 @@ pub fn get_parameters_from_message_and_carry_wopbs(
msg_space: usize,
carry_space: usize,
) -> Parameters {
let mut out = Parameters::default();
let mut out = PARAM_MESSAGE_2_CARRY_2;
let mut flag: bool = false;
let mut rescaled_message_space = f64::ceil(f64::log2(msg_space as f64)) as usize;
rescaled_message_space = 1 << rescaled_message_space;

View File

@@ -11,13 +11,12 @@ pub use super::client_key::ClientKey;
pub use super::gen_keys;
pub use super::parameters::{
CarryModulus, DecompositionBaseLog, DecompositionLevelCount, GlweDimension, LweDimension,
MessageModulus, Parameters, PolynomialSize, StandardDev, DEFAULT_PARAMETERS,
PARAM_MESSAGE_1_CARRY_1, PARAM_MESSAGE_1_CARRY_2, PARAM_MESSAGE_1_CARRY_3,
PARAM_MESSAGE_1_CARRY_4, PARAM_MESSAGE_1_CARRY_5, PARAM_MESSAGE_1_CARRY_6,
PARAM_MESSAGE_1_CARRY_7, PARAM_MESSAGE_2_CARRY_2, PARAM_MESSAGE_2_CARRY_3,
PARAM_MESSAGE_2_CARRY_4, PARAM_MESSAGE_2_CARRY_5, PARAM_MESSAGE_2_CARRY_6,
PARAM_MESSAGE_3_CARRY_3, PARAM_MESSAGE_3_CARRY_4, PARAM_MESSAGE_3_CARRY_5,
PARAM_MESSAGE_4_CARRY_4,
MessageModulus, Parameters, PolynomialSize, StandardDev, PARAM_MESSAGE_1_CARRY_1,
PARAM_MESSAGE_1_CARRY_2, PARAM_MESSAGE_1_CARRY_3, PARAM_MESSAGE_1_CARRY_4,
PARAM_MESSAGE_1_CARRY_5, PARAM_MESSAGE_1_CARRY_6, PARAM_MESSAGE_1_CARRY_7,
PARAM_MESSAGE_2_CARRY_2, PARAM_MESSAGE_2_CARRY_3, PARAM_MESSAGE_2_CARRY_4,
PARAM_MESSAGE_2_CARRY_5, PARAM_MESSAGE_2_CARRY_6, PARAM_MESSAGE_3_CARRY_3,
PARAM_MESSAGE_3_CARRY_4, PARAM_MESSAGE_3_CARRY_5, PARAM_MESSAGE_4_CARRY_4,
};
pub use super::public_key::{PublicKeyBase, PublicKeyBig, PublicKeySmall};
pub use super::server_key::ServerKey;

View File

@@ -27,11 +27,11 @@ impl CompressedPublicKeyBig {
///
/// ```rust
/// use tfhe::shortint::client_key::ClientKey;
/// use tfhe::shortint::parameters::Parameters;
/// use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
/// use tfhe::shortint::public_key::CompressedPublicKeyBig;
///
/// // Generate the client key:
/// let cks = ClientKey::new(Parameters::default());
/// let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
///
/// let pk = CompressedPublicKeyBig::new(&cks);
/// ```
@@ -49,11 +49,11 @@ impl CompressedPublicKeySmall {
///
/// ```rust
/// use tfhe::shortint::client_key::ClientKey;
/// use tfhe::shortint::parameters::Parameters;
/// use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
/// use tfhe::shortint::public_key::CompressedPublicKeySmall;
///
/// // Generate the client key:
/// let cks = ClientKey::new(Parameters::default());
/// let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
///
/// let pk = CompressedPublicKeySmall::new(&cks);
/// ```
@@ -125,11 +125,11 @@ impl<OpOrder: PBSOrderMarker> CompressedPublicKeyBase<OpOrder> {
/// # Example
///
/// ```rust
/// use tfhe::shortint::parameters::MessageModulus;
/// use tfhe::shortint::{ClientKey, CompressedPublicKeyBig, CompressedPublicKeySmall, Parameters};
/// use tfhe::shortint::parameters::{MessageModulus, PARAM_MESSAGE_2_CARRY_2};
/// use tfhe::shortint::{ClientKey, CompressedPublicKeyBig, CompressedPublicKeySmall};
///
/// // Generate the client key:
/// let cks = ClientKey::new(Parameters::default());
/// let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
///
/// let pk = CompressedPublicKeyBig::new(&cks);
///
@@ -174,10 +174,11 @@ impl<OpOrder: PBSOrderMarker> CompressedPublicKeyBase<OpOrder> {
/// # Example
///
/// ```rust
/// use tfhe::shortint::{ClientKey, CompressedPublicKeyBig, CompressedPublicKeySmall, Parameters};
/// use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
/// use tfhe::shortint::{ClientKey, CompressedPublicKeyBig, CompressedPublicKeySmall};
///
/// // Generate the client key:
/// let cks = ClientKey::new(Parameters::default());
/// let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
///
/// let pk = CompressedPublicKeyBig::new(&cks);
///
@@ -256,10 +257,11 @@ impl<OpOrder: PBSOrderMarker> CompressedPublicKeyBase<OpOrder> {
/// # Example
///
/// ```rust
/// use tfhe::shortint::{ClientKey, CompressedPublicKeyBig, CompressedPublicKeySmall, Parameters};
/// use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
/// use tfhe::shortint::{ClientKey, CompressedPublicKeyBig, CompressedPublicKeySmall};
///
/// // Generate the client key:
/// let cks = ClientKey::new(Parameters::default());
/// let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
///
/// let pk = CompressedPublicKeyBig::new(&cks);
///

View File

@@ -27,11 +27,11 @@ impl PublicKeyBig {
///
/// ```rust
/// use tfhe::shortint::client_key::ClientKey;
/// use tfhe::shortint::parameters::Parameters;
/// use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
/// use tfhe::shortint::public_key::PublicKeyBig;
///
/// // Generate the client key:
/// let cks = ClientKey::new(Parameters::default());
/// let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
///
/// let pk = PublicKeyBig::new(&cks);
/// ```
@@ -47,11 +47,11 @@ impl PublicKeySmall {
///
/// ```rust
/// use tfhe::shortint::client_key::ClientKey;
/// use tfhe::shortint::parameters::Parameters;
/// use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
/// use tfhe::shortint::public_key::PublicKeySmall;
///
/// // Generate the client key:
/// let cks = ClientKey::new(Parameters::default());
/// let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
///
/// let pk = PublicKeySmall::new(&cks);
/// ```
@@ -119,11 +119,11 @@ impl<OpOrder: PBSOrderMarker> PublicKeyBase<OpOrder> {
/// # Example
///
/// ```rust
/// use tfhe::shortint::parameters::MessageModulus;
/// use tfhe::shortint::{ClientKey, Parameters, PublicKeyBig, PublicKeySmall};
/// use tfhe::shortint::parameters::{MessageModulus, PARAM_MESSAGE_2_CARRY_2};
/// use tfhe::shortint::{ClientKey, PublicKeyBig, PublicKeySmall};
///
/// // Generate the client key:
/// let cks = ClientKey::new(Parameters::default());
/// let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
///
/// let pk = PublicKeyBig::new(&cks);
///
@@ -164,10 +164,11 @@ impl<OpOrder: PBSOrderMarker> PublicKeyBase<OpOrder> {
/// # Example
///
/// ```rust
/// use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
/// use tfhe::shortint::{ClientKey, Parameters, PublicKeyBig, PublicKeySmall};
///
/// // Generate the client key:
/// let cks = ClientKey::new(Parameters::default());
/// let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
///
/// let pk = PublicKeyBig::new(&cks);
///
@@ -247,10 +248,11 @@ impl<OpOrder: PBSOrderMarker> PublicKeyBase<OpOrder> {
/// # Example
///
/// ```rust
/// use tfhe::shortint::{ClientKey, Parameters, PublicKeyBig, PublicKeySmall};
/// use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
/// use tfhe::shortint::{ClientKey, PublicKeyBig, PublicKeySmall};
///
/// // Generate the client key:
/// let cks = ClientKey::new(Parameters::default());
/// let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
///
/// let pk = PublicKeyBig::new(&cks);
///

View File

@@ -30,11 +30,11 @@ impl CompressedServerKey {
///
/// ```rust
/// use tfhe::shortint::client_key::ClientKey;
/// use tfhe::shortint::parameters::Parameters;
/// use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
/// use tfhe::shortint::server_key::CompressedServerKey;
///
/// // Generate the client key:
/// let cks = ClientKey::new(Parameters::default());
/// let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
///
/// let sks = CompressedServerKey::new(&cks);
/// ```