-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(tfhe)!: update key level order for better performance
- use natural order for decomposition levels in bsk co-authored-by: Agnes Leroy <[email protected]>
- Loading branch information
1 parent
dda9388
commit 615ed3d
Showing
45 changed files
with
361 additions
and
269 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
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
12 changes: 11 additions & 1 deletion
12
tfhe/src/core_crypto/backward_compatibility/entities/ggsw_ciphertext.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,21 @@ | ||
use tfhe_versionable::deprecation::{Deprecable, Deprecated}; | ||
use tfhe_versionable::VersionsDispatch; | ||
|
||
use crate::core_crypto::prelude::{Container, GgswCiphertext, UnsignedInteger}; | ||
|
||
impl<C: Container> Deprecable for GgswCiphertext<C> | ||
where | ||
C::Element: UnsignedInteger, | ||
{ | ||
const TYPE_NAME: &'static str = "GgswCiphertext"; | ||
const MIN_SUPPORTED_APP_VERSION: &'static str = "TFHE-rs v0.10"; | ||
} | ||
|
||
#[derive(VersionsDispatch)] | ||
pub enum GgswCiphertextVersions<C: Container> | ||
where | ||
C::Element: UnsignedInteger, | ||
{ | ||
V0(GgswCiphertext<C>), | ||
V0(Deprecated<GgswCiphertext<C>>), | ||
V1(GgswCiphertext<C>), | ||
} |
12 changes: 11 additions & 1 deletion
12
tfhe/src/core_crypto/backward_compatibility/entities/ggsw_ciphertext_list.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,21 @@ | ||
use tfhe_versionable::deprecation::{Deprecable, Deprecated}; | ||
use tfhe_versionable::VersionsDispatch; | ||
|
||
use crate::core_crypto::prelude::{Container, GgswCiphertextList, UnsignedInteger}; | ||
|
||
impl<C: Container> Deprecable for GgswCiphertextList<C> | ||
where | ||
C::Element: UnsignedInteger, | ||
{ | ||
const TYPE_NAME: &'static str = "GgswCiphertextList"; | ||
const MIN_SUPPORTED_APP_VERSION: &'static str = "TFHE-rs v0.10"; | ||
} | ||
|
||
#[derive(VersionsDispatch)] | ||
pub enum GgswCiphertextListVersions<C: Container> | ||
where | ||
C::Element: UnsignedInteger, | ||
{ | ||
V0(GgswCiphertextList<C>), | ||
V0(Deprecated<GgswCiphertextList<C>>), | ||
V1(GgswCiphertextList<C>), | ||
} |
12 changes: 11 additions & 1 deletion
12
tfhe/src/core_crypto/backward_compatibility/entities/lwe_bootstrap_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,21 @@ | ||
use tfhe_versionable::deprecation::{Deprecable, Deprecated}; | ||
use tfhe_versionable::VersionsDispatch; | ||
|
||
use crate::core_crypto::prelude::{Container, LweBootstrapKey, UnsignedInteger}; | ||
|
||
impl<C: Container> Deprecable for LweBootstrapKey<C> | ||
where | ||
C::Element: UnsignedInteger, | ||
{ | ||
const TYPE_NAME: &'static str = "LweBootstrapKey"; | ||
const MIN_SUPPORTED_APP_VERSION: &'static str = "TFHE-rs v0.10"; | ||
} | ||
|
||
#[derive(VersionsDispatch)] | ||
pub enum LweBootstrapKeyVersions<C: Container> | ||
where | ||
C::Element: UnsignedInteger, | ||
{ | ||
V0(LweBootstrapKey<C>), | ||
V0(Deprecated<LweBootstrapKey<C>>), | ||
V1(LweBootstrapKey<C>), | ||
} |
53 changes: 9 additions & 44 deletions
53
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,57 +1,22 @@ | ||
use tfhe_versionable::{Upgrade, Version, VersionsDispatch}; | ||
use tfhe_versionable::deprecation::{Deprecable, Deprecated}; | ||
use tfhe_versionable::VersionsDispatch; | ||
|
||
use crate::core_crypto::prelude::{ | ||
CiphertextModulus, Container, ContainerMut, ContiguousEntityContainerMut, DecompositionBaseLog, | ||
DecompositionLevelCount, LweKeyswitchKey, LweSize, UnsignedInteger, | ||
}; | ||
use crate::core_crypto::prelude::{Container, LweKeyswitchKey, UnsignedInteger}; | ||
|
||
#[derive(Version)] | ||
pub struct LweKeyswitchKeyV0<C: Container> | ||
impl<C: Container> Deprecable for LweKeyswitchKey<C> | ||
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) | ||
} | ||
const TYPE_NAME: &'static str = "LweKeyswitchKey"; | ||
const MIN_SUPPORTED_APP_VERSION: &'static str = "TFHE-rs v0.10"; | ||
} | ||
|
||
#[derive(VersionsDispatch)] | ||
pub enum LweKeyswitchKeyVersions<C: Container> | ||
where | ||
C::Element: UnsignedInteger, | ||
{ | ||
V0(LweKeyswitchKeyV0<C>), | ||
V1(LweKeyswitchKey<C>), | ||
V0(Deprecated<LweKeyswitchKey<C>>), | ||
V1(Deprecated<LweKeyswitchKey<C>>), | ||
V2(LweKeyswitchKey<C>), | ||
} |
Oops, something went wrong.