-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(data)!: breaking data changes for future compatibility
- invert the LweKeyswitchKey level order and propagate change - remove dependency on unsupported wopbs keys for the HL keys
- Loading branch information
1 parent
27dd30f
commit 9c971e3
Showing
31 changed files
with
373 additions
and
693 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 49 additions & 3 deletions
52
tfhe/src/core_crypto/backward_compatibility/entities/lwe_keyswitch_key.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,57 @@ | ||
use tfhe_versionable::VersionsDispatch; | ||
use tfhe_versionable::{Upgrade, Version, VersionsDispatch}; | ||
|
||
use crate::core_crypto::prelude::{Container, LweKeyswitchKey, UnsignedInteger}; | ||
use crate::core_crypto::prelude::{ | ||
CiphertextModulus, Container, ContainerMut, ContiguousEntityContainerMut, DecompositionBaseLog, | ||
DecompositionLevelCount, LweKeyswitchKey, LweSize, UnsignedInteger, | ||
}; | ||
|
||
#[derive(Version)] | ||
pub struct LweKeyswitchKeyV0<C: Container> | ||
where | ||
C::Element: UnsignedInteger, | ||
{ | ||
data: C, | ||
decomp_base_log: DecompositionBaseLog, | ||
decomp_level_count: DecompositionLevelCount, | ||
output_lwe_size: LweSize, | ||
ciphertext_modulus: CiphertextModulus<C::Element>, | ||
} | ||
|
||
impl<Scalar: UnsignedInteger, C: ContainerMut<Element = Scalar>> Upgrade<LweKeyswitchKey<C>> | ||
for LweKeyswitchKeyV0<C> | ||
{ | ||
type Error = std::convert::Infallible; | ||
|
||
fn upgrade(self) -> Result<LweKeyswitchKey<C>, Self::Error> { | ||
let Self { | ||
data, | ||
decomp_base_log, | ||
decomp_level_count, | ||
output_lwe_size, | ||
ciphertext_modulus, | ||
} = self; | ||
let mut new_ksk = LweKeyswitchKey::from_container( | ||
data, | ||
decomp_base_log, | ||
decomp_level_count, | ||
output_lwe_size, | ||
ciphertext_modulus, | ||
); | ||
|
||
// Invert levels | ||
for mut ksk_block in new_ksk.iter_mut() { | ||
ksk_block.reverse(); | ||
} | ||
|
||
Ok(new_ksk) | ||
} | ||
} | ||
|
||
#[derive(VersionsDispatch)] | ||
pub enum LweKeyswitchKeyVersions<C: Container> | ||
where | ||
C::Element: UnsignedInteger, | ||
{ | ||
V0(LweKeyswitchKey<C>), | ||
V0(LweKeyswitchKeyV0<C>), | ||
V1(LweKeyswitchKey<C>), | ||
} |
55 changes: 52 additions & 3 deletions
55
tfhe/src/core_crypto/backward_compatibility/entities/lwe_packing_keyswitch_key.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,60 @@ | ||
use tfhe_versionable::VersionsDispatch; | ||
use tfhe_versionable::{Upgrade, Version, VersionsDispatch}; | ||
|
||
use crate::core_crypto::prelude::{Container, LwePackingKeyswitchKey, UnsignedInteger}; | ||
use crate::core_crypto::prelude::{ | ||
CiphertextModulus, Container, ContainerMut, ContiguousEntityContainerMut, DecompositionBaseLog, | ||
DecompositionLevelCount, GlweSize, LwePackingKeyswitchKey, PolynomialSize, UnsignedInteger, | ||
}; | ||
|
||
#[derive(Version)] | ||
pub struct LwePackingKeyswitchKeyV0<C: Container> | ||
where | ||
C::Element: UnsignedInteger, | ||
{ | ||
data: C, | ||
decomp_base_log: DecompositionBaseLog, | ||
decomp_level_count: DecompositionLevelCount, | ||
output_glwe_size: GlweSize, | ||
output_polynomial_size: PolynomialSize, | ||
ciphertext_modulus: CiphertextModulus<C::Element>, | ||
} | ||
|
||
impl<Scalar: UnsignedInteger, C: ContainerMut<Element = Scalar>> Upgrade<LwePackingKeyswitchKey<C>> | ||
for LwePackingKeyswitchKeyV0<C> | ||
{ | ||
type Error = std::convert::Infallible; | ||
|
||
fn upgrade(self) -> Result<LwePackingKeyswitchKey<C>, Self::Error> { | ||
let Self { | ||
data, | ||
decomp_base_log, | ||
decomp_level_count, | ||
output_glwe_size, | ||
output_polynomial_size, | ||
ciphertext_modulus, | ||
} = self; | ||
let mut new_pksk = LwePackingKeyswitchKey::from_container( | ||
data, | ||
decomp_base_log, | ||
decomp_level_count, | ||
output_glwe_size, | ||
output_polynomial_size, | ||
ciphertext_modulus, | ||
); | ||
|
||
// Invert levels | ||
for mut pksk_block in new_pksk.iter_mut() { | ||
pksk_block.reverse(); | ||
} | ||
|
||
Ok(new_pksk) | ||
} | ||
} | ||
|
||
#[derive(VersionsDispatch)] | ||
pub enum LwePackingKeyswitchKeyVersions<C: Container> | ||
where | ||
C::Element: UnsignedInteger, | ||
{ | ||
V0(LwePackingKeyswitchKey<C>), | ||
V0(LwePackingKeyswitchKeyV0<C>), | ||
V1(LwePackingKeyswitchKey<C>), | ||
} |
22 changes: 20 additions & 2 deletions
22
tfhe/src/core_crypto/backward_compatibility/entities/seeded_lwe_keyswitch_key.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
use tfhe_versionable::VersionsDispatch; | ||
use tfhe_versionable::{Upgrade, Version, VersionsDispatch}; | ||
|
||
use crate::core_crypto::prelude::{Container, SeededLweKeyswitchKey, UnsignedInteger}; | ||
|
||
#[derive(Version)] | ||
pub struct UnsupportedSeededLweKeyswitchKeyV0; | ||
|
||
impl<Scalar: UnsignedInteger, C: Container<Element = Scalar>> Upgrade<SeededLweKeyswitchKey<C>> | ||
for UnsupportedSeededLweKeyswitchKeyV0 | ||
{ | ||
type Error = crate::Error; | ||
|
||
fn upgrade(self) -> Result<SeededLweKeyswitchKey<C>, Self::Error> { | ||
Err(crate::Error::new( | ||
"Unable to load SeededLweKeyswitchKey, \ | ||
this format is unsupported by this TFHE-rs version." | ||
.to_string(), | ||
)) | ||
} | ||
} | ||
|
||
#[derive(VersionsDispatch)] | ||
pub enum SeededLweKeyswitchKeyVersions<C: Container> | ||
where | ||
C::Element: UnsignedInteger, | ||
{ | ||
V0(SeededLweKeyswitchKey<C>), | ||
V0(UnsupportedSeededLweKeyswitchKeyV0), | ||
V1(SeededLweKeyswitchKey<C>), | ||
} |
22 changes: 20 additions & 2 deletions
22
tfhe/src/core_crypto/backward_compatibility/entities/seeded_lwe_packing_keyswitch_key.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
use tfhe_versionable::VersionsDispatch; | ||
use tfhe_versionable::{Upgrade, Version, VersionsDispatch}; | ||
|
||
use crate::core_crypto::prelude::{Container, SeededLwePackingKeyswitchKey, UnsignedInteger}; | ||
|
||
#[derive(Version)] | ||
pub struct UnsupportedSeededLwePackingKeyswitchKeyV0; | ||
|
||
impl<Scalar: UnsignedInteger, C: Container<Element = Scalar>> | ||
Upgrade<SeededLwePackingKeyswitchKey<C>> for UnsupportedSeededLwePackingKeyswitchKeyV0 | ||
{ | ||
type Error = crate::Error; | ||
|
||
fn upgrade(self) -> Result<SeededLwePackingKeyswitchKey<C>, Self::Error> { | ||
Err(crate::Error::new( | ||
"Unable to load SeededLwePackingKeyswitchKey, \ | ||
this format is unsupported by this TFHE-rs version." | ||
.to_string(), | ||
)) | ||
} | ||
} | ||
|
||
#[derive(VersionsDispatch)] | ||
pub enum SeededLwePackingKeyswitchKeyVersions<C: Container> | ||
where | ||
C::Element: UnsignedInteger, | ||
{ | ||
V0(SeededLwePackingKeyswitchKey<C>), | ||
V0(UnsupportedSeededLwePackingKeyswitchKeyV0), | ||
V1(SeededLwePackingKeyswitchKey<C>), | ||
} |
Oops, something went wrong.