Skip to content

Commit

Permalink
chore!: homogenize conformance parameters
Browse files Browse the repository at this point in the history
BREAKING CHANGE: renamed some conformance parameters public types
  • Loading branch information
nsarlin-zama committed Feb 17, 2025
1 parent 1b7f7a5 commit d901468
Show file tree
Hide file tree
Showing 31 changed files with 135 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,9 @@ impl<Scalar: UnsignedTorus> CompressedModulusSwitchedGlweCiphertext<Scalar> {
impl<Scalar: UnsignedInteger> ParameterSetConformant
for CompressedModulusSwitchedGlweCiphertext<Scalar>
{
type ParameterSet = GlweCiphertextConformanceParameters<Scalar>;
type ParameterSet = GlweCiphertextConformanceParams<Scalar>;

fn is_conformant(
&self,
lwe_ct_parameters: &GlweCiphertextConformanceParameters<Scalar>,
) -> bool {
fn is_conformant(&self, lwe_ct_parameters: &GlweCiphertextConformanceParams<Scalar>) -> bool {
let Self {
packed_integers,
glwe_dimension,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ impl<Scalar: UnsignedTorus> CompressedModulusSwitchedLweCiphertext<Scalar> {
impl<Scalar: UnsignedInteger> ParameterSetConformant
for CompressedModulusSwitchedLweCiphertext<Scalar>
{
type ParameterSet = LweCiphertextParameters<Scalar>;
type ParameterSet = LweCiphertextConformanceParams<Scalar>;

fn is_conformant(&self, lwe_ct_parameters: &LweCiphertextParameters<Scalar>) -> bool {
fn is_conformant(&self, lwe_ct_parameters: &LweCiphertextConformanceParams<Scalar>) -> bool {
let Self {
packed_integers,
lwe_dimension,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ impl MultiBitModulusSwitchedCt for FromCompressionMultiBitModulusSwitchedCt {
impl<Scalar: UnsignedInteger + CastInto<usize> + CastFrom<usize>> ParameterSetConformant
for CompressedModulusSwitchedMultiBitLweCiphertext<Scalar>
{
type ParameterSet = LweCiphertextParameters<Scalar>;
type ParameterSet = LweCiphertextConformanceParams<Scalar>;

fn is_conformant(&self, lwe_ct_parameters: &LweCiphertextParameters<Scalar>) -> bool {
fn is_conformant(&self, lwe_ct_parameters: &LweCiphertextConformanceParams<Scalar>) -> bool {
let Self {
body,
packed_mask,
Expand Down
6 changes: 3 additions & 3 deletions tfhe/src/core_crypto/entities/glwe_ciphertext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ impl<Scalar: UnsignedInteger, C: Container<Element = Scalar>> CreateFrom<C> for
/// Can be used on a server to check if client inputs are well formed
/// before running a computation on them
#[derive(Copy, Clone)]
pub struct GlweCiphertextConformanceParameters<T: UnsignedInteger> {
pub struct GlweCiphertextConformanceParams<T: UnsignedInteger> {
pub glwe_dim: GlweDimension,
pub polynomial_size: PolynomialSize,
pub ct_modulus: CiphertextModulus<T>,
Expand All @@ -643,11 +643,11 @@ impl<C: Container> ParameterSetConformant for GlweCiphertext<C>
where
C::Element: UnsignedInteger,
{
type ParameterSet = GlweCiphertextConformanceParameters<C::Element>;
type ParameterSet = GlweCiphertextConformanceParams<C::Element>;

fn is_conformant(
&self,
glwe_ct_parameters: &GlweCiphertextConformanceParameters<C::Element>,
glwe_ct_parameters: &GlweCiphertextConformanceParams<C::Element>,
) -> bool {
let Self {
data,
Expand Down
9 changes: 6 additions & 3 deletions tfhe/src/core_crypto/entities/lwe_ciphertext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ pub type LweCiphertextMutView<'data, Scalar> = LweCiphertext<&'data mut [Scalar]
/// Can be used on a server to check if client inputs are well formed
/// before running a computation on them
#[derive(Copy, Clone)]
pub struct LweCiphertextParameters<T: UnsignedInteger> {
pub struct LweCiphertextConformanceParams<T: UnsignedInteger> {
pub lwe_dim: LweDimension,
pub ct_modulus: CiphertextModulus<T>,
pub ms_decompression_method: MsDecompressionType,
Expand All @@ -766,9 +766,12 @@ impl<C: Container> ParameterSetConformant for LweCiphertext<C>
where
C::Element: UnsignedInteger,
{
type ParameterSet = LweCiphertextParameters<C::Element>;
type ParameterSet = LweCiphertextConformanceParams<C::Element>;

fn is_conformant(&self, lwe_ct_parameters: &LweCiphertextParameters<C::Element>) -> bool {
fn is_conformant(
&self,
lwe_ct_parameters: &LweCiphertextConformanceParams<C::Element>,
) -> bool {
let Self {
data,
ciphertext_modulus,
Expand Down
6 changes: 3 additions & 3 deletions tfhe/src/core_crypto/entities/lwe_compact_ciphertext_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,16 @@ pub type LweCompactCiphertextListMutView<'data, Scalar> =
/// Can be used on a server to check if client inputs are well formed
/// before running a computation on them
#[derive(Copy, Clone)]
pub struct LweCiphertextListParameters<T: UnsignedInteger> {
pub struct LweCiphertextListConformanceParams<T: UnsignedInteger> {
pub lwe_dim: LweDimension,
pub lwe_ciphertext_count_constraint: ListSizeConstraint,
pub ct_modulus: CiphertextModulus<T>,
}

impl<T: UnsignedInteger> ParameterSetConformant for LweCompactCiphertextListOwned<T> {
type ParameterSet = LweCiphertextListParameters<T>;
type ParameterSet = LweCiphertextListConformanceParams<T>;

fn is_conformant(&self, param: &LweCiphertextListParameters<T>) -> bool {
fn is_conformant(&self, param: &LweCiphertextListConformanceParams<T>) -> bool {
let Self {
data,
lwe_size,
Expand Down
6 changes: 3 additions & 3 deletions tfhe/src/core_crypto/entities/lwe_compact_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl<Scalar: UnsignedInteger> LweCompactPublicKeyOwned<Scalar> {
}

#[derive(Clone, Copy)]
pub struct LweCompactPublicKeyEncryptionParameters<Scalar: UnsignedInteger> {
pub struct LweCompactPublicKeyConformanceParams<Scalar: UnsignedInteger> {
pub encryption_lwe_dimension: LweDimension,
pub ciphertext_modulus: CiphertextModulus<Scalar>,
}
Expand All @@ -195,7 +195,7 @@ impl<C: Container> ParameterSetConformant for LweCompactPublicKey<C>
where
C::Element: UnsignedInteger,
{
type ParameterSet = LweCompactPublicKeyEncryptionParameters<C::Element>;
type ParameterSet = LweCompactPublicKeyConformanceParams<C::Element>;

fn is_conformant(&self, parameter_set: &Self::ParameterSet) -> bool {
let Self { glwe_ciphertext } = self;
Expand All @@ -204,7 +204,7 @@ where
return false;
}

let glwe_ciphertext_conformance_parameters = GlweCiphertextConformanceParameters {
let glwe_ciphertext_conformance_parameters = GlweCiphertextConformanceParams {
glwe_dim: GlweDimension(1),
polynomial_size: PolynomialSize(parameter_set.encryption_lwe_dimension.0),
ct_modulus: parameter_set.ciphertext_modulus,
Expand Down
4 changes: 2 additions & 2 deletions tfhe/src/core_crypto/entities/lwe_keyswitch_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ impl<Scalar: UnsignedInteger, C: ContainerMut<Element = Scalar>> ContiguousEntit
Self: 'this;
}

pub struct KeyswitchKeyConformanceParams {
pub struct LweKeyswitchKeyConformanceParams {
pub decomp_base_log: DecompositionBaseLog,
pub decomp_level_count: DecompositionLevelCount,
pub output_lwe_size: LweSize,
Expand All @@ -444,7 +444,7 @@ pub struct KeyswitchKeyConformanceParams {
}

impl<C: Container<Element = u64>> ParameterSetConformant for LweKeyswitchKey<C> {
type ParameterSet = KeyswitchKeyConformanceParams;
type ParameterSet = LweKeyswitchKeyConformanceParams;

fn is_conformant(&self, parameter_set: &Self::ParameterSet) -> bool {
let Self {
Expand Down
4 changes: 2 additions & 2 deletions tfhe/src/core_crypto/entities/lwe_packing_keyswitch_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ impl<Scalar: UnsignedInteger, C: ContainerMut<Element = Scalar>> ContiguousEntit
Self: 'this;
}

pub struct PackingKeyswitchConformanceParams {
pub struct LwePackingKeyswitchKeyConformanceParams {
pub decomp_base_log: DecompositionBaseLog,
pub decomp_level_count: DecompositionLevelCount,
pub input_lwe_dimension: LweDimension,
Expand All @@ -412,7 +412,7 @@ pub struct PackingKeyswitchConformanceParams {
}

impl<C: Container<Element = u64>> ParameterSetConformant for LwePackingKeyswitchKey<C> {
type ParameterSet = PackingKeyswitchConformanceParams;
type ParameterSet = LwePackingKeyswitchKeyConformanceParams;

fn is_conformant(&self, parameter_set: &Self::ParameterSet) -> bool {
let Self {
Expand Down
12 changes: 6 additions & 6 deletions tfhe/src/core_crypto/entities/seeded_ggsw_ciphertext_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::core_crypto::commons::math::random::{
use crate::core_crypto::commons::parameters::*;
use crate::core_crypto::commons::traits::*;
use crate::core_crypto::entities::*;
use crate::core_crypto::fft_impl::fft64::crypto::bootstrap::BootstrapKeyConformanceParams;
use crate::core_crypto::fft_impl::fft64::crypto::bootstrap::LweBootstrapKeyConformanceParams;
use tfhe_versionable::Versionize;

/// A contiguous list containing
Expand Down Expand Up @@ -472,7 +472,7 @@ impl<Scalar: UnsignedInteger, C: ContainerMut<Element = Scalar>> ContiguousEntit
Self: 'this;
}

pub struct GgswCiphertextListConformanceParameters {
pub struct GgswCiphertextListConformanceParams {
pub len: usize,
pub glwe_size: GlweSize,
pub polynomial_size: PolynomialSize,
Expand All @@ -481,7 +481,7 @@ pub struct GgswCiphertextListConformanceParameters {
pub ciphertext_modulus: CiphertextModulus<u64>,
}

impl TryFrom<&MultiBitBootstrapKeyConformanceParams> for GgswCiphertextListConformanceParameters {
impl TryFrom<&MultiBitBootstrapKeyConformanceParams> for GgswCiphertextListConformanceParams {
type Error = ();

fn try_from(value: &MultiBitBootstrapKeyConformanceParams) -> Result<Self, ()> {
Expand All @@ -502,8 +502,8 @@ impl TryFrom<&MultiBitBootstrapKeyConformanceParams> for GgswCiphertextListConfo
}
}

impl From<&BootstrapKeyConformanceParams> for GgswCiphertextListConformanceParameters {
fn from(value: &BootstrapKeyConformanceParams) -> Self {
impl From<&LweBootstrapKeyConformanceParams> for GgswCiphertextListConformanceParams {
fn from(value: &LweBootstrapKeyConformanceParams) -> Self {
Self {
len: value.input_lwe_dimension.0,
glwe_size: value.output_glwe_size,
Expand All @@ -516,7 +516,7 @@ impl From<&BootstrapKeyConformanceParams> for GgswCiphertextListConformanceParam
}

impl<C: Container<Element = u64>> ParameterSetConformant for SeededGgswCiphertextList<C> {
type ParameterSet = GgswCiphertextListConformanceParameters;
type ParameterSet = GgswCiphertextListConformanceParams;

fn is_conformant(&self, parameter_set: &Self::ParameterSet) -> bool {
let Self {
Expand Down
4 changes: 2 additions & 2 deletions tfhe/src/core_crypto/entities/seeded_glwe_ciphertext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ impl<C: Container> ParameterSetConformant for SeededGlweCiphertext<C>
where
C::Element: UnsignedInteger,
{
type ParameterSet = GlweCiphertextConformanceParameters<C::Element>;
type ParameterSet = GlweCiphertextConformanceParams<C::Element>;

fn is_conformant(
&self,
glwe_ct_parameters: &GlweCiphertextConformanceParameters<C::Element>,
glwe_ct_parameters: &GlweCiphertextConformanceParams<C::Element>,
) -> bool {
let Self {
compression_seed: _,
Expand Down
4 changes: 2 additions & 2 deletions tfhe/src/core_crypto/entities/seeded_lwe_bootstrap_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::core_crypto::commons::math::random::{CompressionSeed, DefaultRandomGe
use crate::core_crypto::commons::parameters::*;
use crate::core_crypto::commons::traits::*;
use crate::core_crypto::entities::*;
use crate::core_crypto::fft_impl::fft64::crypto::bootstrap::BootstrapKeyConformanceParams;
use crate::core_crypto::fft_impl::fft64::crypto::bootstrap::LweBootstrapKeyConformanceParams;

/// A [`seeded LWE bootstrap key`](`SeededLweBootstrapKey`).
///
Expand Down Expand Up @@ -324,7 +324,7 @@ impl<Scalar: UnsignedInteger> SeededLweBootstrapKeyOwned<Scalar> {
}

impl<C: Container<Element = u64>> ParameterSetConformant for SeededLweBootstrapKey<C> {
type ParameterSet = BootstrapKeyConformanceParams;
type ParameterSet = LweBootstrapKeyConformanceParams;

fn is_conformant(&self, parameter_set: &Self::ParameterSet) -> bool {
let Self { ggsw_list } = self;
Expand Down
4 changes: 2 additions & 2 deletions tfhe/src/core_crypto/entities/seeded_lwe_ciphertext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ pub struct SeededLweCiphertext<Scalar: UnsignedInteger> {
}

impl<T: UnsignedInteger> ParameterSetConformant for SeededLweCiphertext<T> {
type ParameterSet = LweCiphertextParameters<T>;
type ParameterSet = LweCiphertextConformanceParams<T>;

fn is_conformant(&self, lwe_ct_parameters: &LweCiphertextParameters<T>) -> bool {
fn is_conformant(&self, lwe_ct_parameters: &LweCiphertextConformanceParams<T>) -> bool {
let Self {
data,
lwe_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl<C: Container> ParameterSetConformant for SeededLweCompactPublicKey<C>
where
C::Element: UnsignedInteger,
{
type ParameterSet = LweCompactPublicKeyEncryptionParameters<C::Element>;
type ParameterSet = LweCompactPublicKeyConformanceParams<C::Element>;

fn is_conformant(&self, parameter_set: &Self::ParameterSet) -> bool {
let Self {
Expand All @@ -246,7 +246,7 @@ where
return false;
}

let glwe_ciphertext_conformance_parameters = GlweCiphertextConformanceParameters {
let glwe_ciphertext_conformance_parameters = GlweCiphertextConformanceParams {
glwe_dim: GlweDimension(1),
polynomial_size: PolynomialSize(parameter_set.encryption_lwe_dimension.0),
ct_modulus: parameter_set.ciphertext_modulus,
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/core_crypto/entities/seeded_lwe_keyswitch_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl<Scalar: UnsignedInteger, C: ContainerMut<Element = Scalar>> ContiguousEntit
}

impl<C: Container<Element = u64>> ParameterSetConformant for SeededLweKeyswitchKey<C> {
type ParameterSet = KeyswitchKeyConformanceParams;
type ParameterSet = LweKeyswitchKeyConformanceParams;

fn is_conformant(&self, parameter_set: &Self::ParameterSet) -> bool {
let Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ impl<Scalar: UnsignedInteger, C: ContainerMut<Element = Scalar>> ContiguousEntit
}

impl<C: Container<Element = u64>> ParameterSetConformant for SeededLwePackingKeyswitchKey<C> {
type ParameterSet = PackingKeyswitchConformanceParams;
type ParameterSet = LwePackingKeyswitchKeyConformanceParams;

fn is_conformant(&self, parameter_set: &Self::ParameterSet) -> bool {
let Self {
Expand Down
4 changes: 2 additions & 2 deletions tfhe/src/core_crypto/fft_impl/fft64/crypto/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ where
}
}

pub struct BootstrapKeyConformanceParams {
pub struct LweBootstrapKeyConformanceParams {
pub decomp_base_log: DecompositionBaseLog,
pub decomp_level_count: DecompositionLevelCount,
pub input_lwe_dimension: LweDimension,
Expand All @@ -630,7 +630,7 @@ pub struct BootstrapKeyConformanceParams {
}

impl<C: Container<Element = c64>> ParameterSetConformant for FourierLweBootstrapKey<C> {
type ParameterSet = BootstrapKeyConformanceParams;
type ParameterSet = LweBootstrapKeyConformanceParams;

fn is_conformant(&self, parameter_set: &Self::ParameterSet) -> bool {
let Self {
Expand Down
4 changes: 2 additions & 2 deletions tfhe/src/high_level_api/keys/inner.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::conformance::ParameterSetConformant;
use crate::core_crypto::commons::generators::DeterministicSeeder;
use crate::core_crypto::prelude::{DefaultRandomGenerator, KeyswitchKeyConformanceParams};
use crate::core_crypto::prelude::{DefaultRandomGenerator, LweKeyswitchKeyConformanceParams};
use crate::high_level_api::backward_compatibility::keys::*;
use crate::integer::compression_keys::{
CompressedCompressionKey, CompressedDecompressionKey, CompressionKey, CompressionPrivateKeys,
Expand Down Expand Up @@ -517,7 +517,7 @@ impl
.try_into()?;

Ok(Self {
keyswitch_key_conformance_params: KeyswitchKeyConformanceParams {
keyswitch_key_conformance_params: LweKeyswitchKeyConformanceParams {
decomp_base_log: ks_params.ks_base_log,
decomp_level_count: ks_params.ks_level,
output_lwe_size,
Expand Down
10 changes: 5 additions & 5 deletions tfhe/src/integer/compression_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ impl ClientKey {
}
}

use crate::shortint::list_compression::CompressionConformanceParameters;
use crate::shortint::list_compression::CompressionKeyConformanceParams;

impl ParameterSetConformant for CompressionKey {
type ParameterSet = CompressionConformanceParameters;
type ParameterSet = CompressionKeyConformanceParams;

fn is_conformant(&self, parameter_set: &Self::ParameterSet) -> bool {
let Self { key } = self;
Expand All @@ -133,7 +133,7 @@ impl ParameterSetConformant for CompressionKey {
}

impl ParameterSetConformant for DecompressionKey {
type ParameterSet = CompressionConformanceParameters;
type ParameterSet = CompressionKeyConformanceParams;

fn is_conformant(&self, parameter_set: &Self::ParameterSet) -> bool {
let Self { key } = self;
Expand All @@ -143,7 +143,7 @@ impl ParameterSetConformant for DecompressionKey {
}

impl ParameterSetConformant for CompressedCompressionKey {
type ParameterSet = CompressionConformanceParameters;
type ParameterSet = CompressionKeyConformanceParams;

fn is_conformant(&self, parameter_set: &Self::ParameterSet) -> bool {
let Self { key } = self;
Expand All @@ -153,7 +153,7 @@ impl ParameterSetConformant for CompressedCompressionKey {
}

impl ParameterSetConformant for CompressedDecompressionKey {
type ParameterSet = CompressionConformanceParameters;
type ParameterSet = CompressionKeyConformanceParams;

fn is_conformant(&self, parameter_set: &Self::ParameterSet) -> bool {
let Self { key } = self;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::common::*;
use crate::conformance::ParameterSetConformant;
use crate::core_crypto::prelude::compressed_modulus_switched_lwe_ciphertext::CompressedModulusSwitchedLweCiphertext;
use crate::core_crypto::prelude::compressed_modulus_switched_multi_bit_lwe_ciphertext::CompressedModulusSwitchedMultiBitLweCiphertext;
use crate::core_crypto::prelude::LweCiphertextParameters;
use crate::core_crypto::prelude::LweCiphertextConformanceParams;
use crate::shortint::backward_compatibility::ciphertext::{
CompressedModulusSwitchedCiphertextVersions,
InternalCompressedModulusSwitchedCiphertextVersions,
Expand Down Expand Up @@ -76,9 +76,9 @@ pub(crate) enum InternalCompressedModulusSwitchedCiphertext {
}

impl ParameterSetConformant for InternalCompressedModulusSwitchedCiphertext {
type ParameterSet = LweCiphertextParameters<u64>;
type ParameterSet = LweCiphertextConformanceParams<u64>;

fn is_conformant(&self, param: &LweCiphertextParameters<u64>) -> bool {
fn is_conformant(&self, param: &LweCiphertextConformanceParams<u64>) -> bool {
match self {
Self::Classic(a) => a.is_conformant(param),
Self::MultiBit(a) => a.is_conformant(param),
Expand Down
Loading

0 comments on commit d901468

Please sign in to comment.