Skip to content

Commit

Permalink
feat(all): versionize missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarlin-zama committed Jul 16, 2024
1 parent 704f06a commit 5f3cf96
Show file tree
Hide file tree
Showing 60 changed files with 525 additions and 43 deletions.
13 changes: 13 additions & 0 deletions tfhe/src/boolean/backward_compatibility/ciphertext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use tfhe_versionable::VersionsDispatch;

use crate::boolean::ciphertext::{Ciphertext, CompressedCiphertext};

#[derive(VersionsDispatch)]
pub enum CiphertextVersions {
V0(Ciphertext),
}

#[derive(VersionsDispatch)]
pub enum CompressedCiphertextVersions {
V0(CompressedCiphertext),
}
8 changes: 8 additions & 0 deletions tfhe/src/boolean/backward_compatibility/client_key.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use tfhe_versionable::VersionsDispatch;

use crate::boolean::client_key::ClientKey;

#[derive(VersionsDispatch)]
pub enum ClientKeyVersions {
V0(ClientKey),
}
8 changes: 8 additions & 0 deletions tfhe/src/boolean/backward_compatibility/key_switching_key.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use tfhe_versionable::VersionsDispatch;

use crate::boolean::key_switching_key::KeySwitchingKey;

#[derive(VersionsDispatch)]
pub enum KeySwitchingKeyVersions {
V0(KeySwitchingKey),
}
6 changes: 6 additions & 0 deletions tfhe/src/boolean/backward_compatibility/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod ciphertext;
pub mod client_key;
pub mod key_switching_key;
pub mod parameters;
pub mod public_key;
pub mod server_key;
13 changes: 13 additions & 0 deletions tfhe/src/boolean/backward_compatibility/parameters.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use tfhe_versionable::VersionsDispatch;

use crate::boolean::parameters::{BooleanKeySwitchingParameters, BooleanParameters};

#[derive(VersionsDispatch)]
pub enum BooleanParametersVersions {
V0(BooleanParameters),
}

#[derive(VersionsDispatch)]
pub enum BooleanKeySwitchingParametersVersions {
V0(BooleanKeySwitchingParameters),
}
13 changes: 13 additions & 0 deletions tfhe/src/boolean/backward_compatibility/public_key.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use tfhe_versionable::VersionsDispatch;

use crate::boolean::public_key::{CompressedPublicKey, PublicKey};

#[derive(VersionsDispatch)]
pub enum PublicKeyVersions {
V0(PublicKey),
}

#[derive(VersionsDispatch)]
pub enum CompressedPublicKeyVersions {
V0(CompressedPublicKey),
}
13 changes: 13 additions & 0 deletions tfhe/src/boolean/backward_compatibility/server_key.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use tfhe_versionable::VersionsDispatch;

use crate::boolean::server_key::{CompressedServerKey, ServerKey};

#[derive(VersionsDispatch)]
pub enum ServerKeyVersions {
V0(ServerKey),
}

#[derive(VersionsDispatch)]
pub enum CompressedServerKeyVersions {
V0(CompressedServerKey),
}
9 changes: 7 additions & 2 deletions tfhe/src/boolean/ciphertext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
use crate::core_crypto::entities::*;
use serde::{Deserialize, Serialize};
use tfhe_versionable::Versionize;

use super::backward_compatibility::ciphertext::{CiphertextVersions, CompressedCiphertextVersions};

/// A structure containing a ciphertext, meant to encrypt a Boolean message.
///
/// It is used to evaluate a Boolean circuits homomorphically.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, Versionize)]
#[versionize(CiphertextVersions)]
pub enum Ciphertext {
Encrypted(LweCiphertextOwned<u32>),
Trivial(bool),
Expand All @@ -17,7 +21,8 @@ pub enum Ciphertext {
/// A structure containing a compressed ciphertext, meant to encrypt a Boolean message.
///
/// It has to be decompressed before evaluating a Boolean circuit.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, Versionize)]
#[versionize(CompressedCiphertextVersions)]
pub struct CompressedCiphertext {
pub(crate) ciphertext: SeededLweCiphertext<u32>,
}
Expand Down
6 changes: 5 additions & 1 deletion tfhe/src/boolean/client_key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use crate::boolean::parameters::{BooleanParameters, DynamicDistribution, Encrypt
use crate::core_crypto::entities::*;
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Formatter};
use tfhe_versionable::Versionize;

use super::backward_compatibility::client_key::ClientKeyVersions;

/// A structure containing the client key, which must be kept secret.
///
Expand All @@ -18,7 +21,8 @@ use std::fmt::{Debug, Formatter};
/// * `glwe_secret_key` - a GLWE secret key, used to generate the bootstrapping keys and key
/// switching keys.
/// * `parameters` - the cryptographic parameter set.
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize, Versionize)]
#[versionize(ClientKeyVersions)]
pub struct ClientKey {
pub(crate) lwe_secret_key: LweSecretKeyOwned<u32>,
pub(crate) glwe_secret_key: GlweSecretKeyOwned<u32>,
Expand Down
10 changes: 8 additions & 2 deletions tfhe/src/boolean/engine/bootstrapping.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use crate::boolean::backward_compatibility::server_key::{
CompressedServerKeyVersions, ServerKeyVersions,
};
use crate::boolean::ciphertext::Ciphertext;
use crate::boolean::{ClientKey, PLAINTEXT_TRUE};
use crate::core_crypto::algorithms::*;
Expand All @@ -8,6 +11,7 @@ use crate::core_crypto::commons::parameters::{CiphertextModulus, PBSOrder};
use crate::core_crypto::entities::*;
use crate::core_crypto::fft_impl::fft64::math::fft::Fft;
use serde::{Deserialize, Serialize};
use tfhe_versionable::Versionize;

/// Memory used as buffer for the bootstrap
///
Expand Down Expand Up @@ -89,7 +93,8 @@ impl Memory {
/// In more details, it contains:
/// * `bootstrapping_key` - a public key, used to perform the bootstrapping operation.
/// * `key_switching_key` - a public key, used to perform the key-switching operation.
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize, Versionize)]
#[versionize(ServerKeyVersions)]
pub struct ServerKey {
pub(crate) bootstrapping_key: FourierLweBootstrapKeyOwned,
pub(crate) key_switching_key: LweKeyswitchKeyOwned<u32>,
Expand Down Expand Up @@ -182,7 +187,8 @@ impl ServerKey {
/// In more details, it contains:
/// * `bootstrapping_key` - a public key, used to perform the bootstrapping operation.
/// * `key_switching_key` - a public key, used to perform the key-switching operation.
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize, Versionize)]
#[versionize(CompressedServerKeyVersions)]
pub struct CompressedServerKey {
pub(crate) bootstrapping_key: SeededLweBootstrapKeyOwned<u32>,
pub(crate) key_switching_key: SeededLweKeyswitchKeyOwned<u32>,
Expand Down
7 changes: 6 additions & 1 deletion tfhe/src/boolean/key_switching_key/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
use tfhe_versionable::Versionize;

use crate::boolean::engine::{BooleanEngine, WithThreadLocalEngine};
use crate::boolean::parameters::BooleanKeySwitchingParameters;
use crate::boolean::prelude::Ciphertext;
use crate::boolean::ClientKey;
use crate::core_crypto::prelude::{keyswitch_lwe_ciphertext, LweKeyswitchKeyOwned};

use super::backward_compatibility::key_switching_key::KeySwitchingKeyVersions;

#[cfg(test)]
mod test;

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Versionize)]
#[versionize(KeySwitchingKeyVersions)]
pub struct KeySwitchingKey {
pub(crate) key_switching_key: LweKeyswitchKeyOwned<u32>,
}
Expand Down
1 change: 1 addition & 0 deletions tfhe/src/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use crate::boolean::server_key::ServerKey;
#[cfg(test)]
use rand::Rng;

pub mod backward_compatibility;
pub mod ciphertext;
pub mod client_key;
pub mod engine;
Expand Down
11 changes: 9 additions & 2 deletions tfhe/src/boolean/parameters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ pub use crate::core_crypto::commons::parameters::{
};

use serde::{Deserialize, Serialize};
use tfhe_versionable::Versionize;

use super::backward_compatibility::parameters::{
BooleanKeySwitchingParametersVersions, BooleanParametersVersions,
};

/// A set of cryptographic parameters for homomorphic Boolean circuit evaluation.
/// The choice of encryption key for (`boolean ciphertext`)[`super::ciphertext::Ciphertext`].
Expand All @@ -39,7 +44,8 @@ use serde::{Deserialize, Serialize};
/// key`)[`super::public_key::PublicKey`] sizes are much more manageable and should always fit in
/// memory. When refreshing a ciphertext and/or evaluating a table lookup the keyswitch is
/// computed first followed by a PBS.
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Versionize)]
#[versionize(BooleanParametersVersions)]
pub struct BooleanParameters {
pub lwe_dimension: LweDimension,
pub glwe_dimension: GlweDimension,
Expand Down Expand Up @@ -91,7 +97,8 @@ impl BooleanParameters {
}

/// A set of cryptographic parameters for homomorphic Boolean key switching.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Versionize)]
#[versionize(BooleanKeySwitchingParametersVersions)]
pub struct BooleanKeySwitchingParameters {
pub ks_base_log: DecompositionBaseLog,
pub ks_level: DecompositionLevelCount,
Expand Down
5 changes: 4 additions & 1 deletion tfhe/src/boolean/public_key/compressed.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::boolean::backward_compatibility::public_key::CompressedPublicKeyVersions;
use crate::boolean::engine::{BooleanEngine, WithThreadLocalEngine};
use crate::boolean::prelude::{BooleanParameters, Ciphertext, ClientKey};
use crate::core_crypto::prelude::SeededLwePublicKeyOwned;
use serde::{Deserialize, Serialize};
use tfhe_versionable::Versionize;

/// A structure containing a compressed public key.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Versionize)]
#[versionize(CompressedPublicKeyVersions)]
pub struct CompressedPublicKey {
pub(crate) compressed_lwe_public_key: SeededLwePublicKeyOwned<u32>,
pub parameters: BooleanParameters,
Expand Down
5 changes: 4 additions & 1 deletion tfhe/src/boolean/public_key/standard.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
//! Module with the definition of the encryption PublicKey.
use super::compressed::CompressedPublicKey;
use crate::boolean::backward_compatibility::public_key::PublicKeyVersions;
use crate::boolean::ciphertext::Ciphertext;
use crate::boolean::client_key::ClientKey;
use crate::boolean::engine::{BooleanEngine, WithThreadLocalEngine};
use crate::boolean::parameters::BooleanParameters;
use crate::core_crypto::entities::*;
use serde::{Deserialize, Serialize};
use tfhe_versionable::Versionize;

/// A structure containing a public key.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, Versionize)]
#[versionize(PublicKeyVersions)]
pub struct PublicKey {
pub(crate) lwe_public_key: LwePublicKeyOwned<u32>,
pub(crate) parameters: BooleanParameters,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::core_crypto::commons::dispersion::StandardDev;
use tfhe_versionable::VersionsDispatch;

#[derive(VersionsDispatch)]
pub enum StandardDevVersions {
V0(StandardDev),
}
1 change: 1 addition & 0 deletions tfhe/src/core_crypto/backward_compatibility/commons/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod ciphertext_modulus;
pub mod dispersion;
pub mod math;
pub mod parameters;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use tfhe_versionable::VersionsDispatch;

use crate::core_crypto::prelude::{Cleartext, Numeric};

#[derive(VersionsDispatch)]
pub enum CleartextVersions<T: Numeric> {
V0(Cleartext<T>),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use tfhe_versionable::VersionsDispatch;

use crate::core_crypto::prelude::compressed_modulus_switched_glwe_ciphertext::CompressedModulusSwitchedGlweCiphertext;
use crate::core_crypto::prelude::UnsignedInteger;

#[derive(VersionsDispatch)]
pub enum CompressedModulusSwitchedGlweCiphertextVersions<Scalar: UnsignedInteger> {
V0(CompressedModulusSwitchedGlweCiphertext<Scalar>),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use tfhe_versionable::VersionsDispatch;

use crate::core_crypto::prelude::{Container, GswCiphertext};

#[derive(VersionsDispatch)]
pub enum GswCiphertextVersions<C: Container> {
V0(GswCiphertext<C>),
}
10 changes: 10 additions & 0 deletions tfhe/src/core_crypto/backward_compatibility/entities/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
pub mod cleartext;
pub mod compressed_modulus_switched_glwe_ciphertext;
pub mod compressed_modulus_switched_lwe_ciphertext;
pub mod compressed_modulus_switched_multi_bit_lwe_ciphertext;
pub mod ggsw_ciphertext;
pub mod ggsw_ciphertext_list;
pub mod glwe_ciphertext;
pub mod glwe_ciphertext_list;
pub mod glwe_secret_key;
pub mod gsw_ciphertext;
pub mod lwe_bootstrap_key;
pub mod lwe_ciphertext;
pub mod lwe_ciphertext_list;
Expand All @@ -17,7 +20,14 @@ pub mod lwe_private_functional_packing_keyswitch_key;
pub mod lwe_private_functional_packing_keyswitch_key_list;
pub mod lwe_public_key;
pub mod lwe_secret_key;
pub mod ntt_ggsw_ciphertext;
pub mod ntt_ggsw_ciphertext_list;
pub mod ntt_lwe_bootstrap_key;
pub mod packed_integers;
pub mod plaintext;
pub mod plaintext_list;
pub mod polynomial;
pub mod polynomial_list;
pub mod seeded_ggsw_ciphertext;
pub mod seeded_ggsw_ciphertext_list;
pub mod seeded_glwe_ciphertext;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use tfhe_versionable::VersionsDispatch;

use crate::core_crypto::prelude::{Container, NttGgswCiphertext, UnsignedInteger};

#[derive(VersionsDispatch)]
pub enum NttGgswCiphertextVersions<C: Container>
where
C::Element: UnsignedInteger,
{
V0(NttGgswCiphertext<C>),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use tfhe_versionable::VersionsDispatch;

use crate::core_crypto::prelude::{Container, NttGgswCiphertextList, UnsignedInteger};

#[derive(VersionsDispatch)]
pub enum NttGgswCiphertextListVersions<C: Container>
where
C::Element: UnsignedInteger,
{
V0(NttGgswCiphertextList<C>),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use tfhe_versionable::VersionsDispatch;

use crate::core_crypto::prelude::{Container, NttLweBootstrapKey, UnsignedInteger};

#[derive(VersionsDispatch)]
pub enum NttLweBootstrapKeyVersions<C: Container>
where
C::Element: UnsignedInteger,
{
V0(NttLweBootstrapKey<C>),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use tfhe_versionable::VersionsDispatch;

use crate::core_crypto::prelude::{Numeric, Plaintext};

#[derive(VersionsDispatch)]
pub enum PlaintextVersions<T: Numeric> {
V0(Plaintext<T>),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use tfhe_versionable::VersionsDispatch;

use crate::core_crypto::prelude::{Container, PlaintextList};

#[derive(VersionsDispatch)]
pub enum PlaintextListVersions<C: Container> {
V0(PlaintextList<C>),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use tfhe_versionable::VersionsDispatch;

use crate::core_crypto::prelude::{Container, Polynomial};

#[derive(VersionsDispatch)]
pub enum PolynomialVersions<C: Container> {
V0(Polynomial<C>),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use tfhe_versionable::VersionsDispatch;

use crate::core_crypto::prelude::{Container, PolynomialList};

#[derive(VersionsDispatch)]
pub enum PolynomialListVersions<C: Container> {
V0(PolynomialList<C>),
}
Loading

0 comments on commit 5f3cf96

Please sign in to comment.