Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hlapi): fix Client/Server Key versionning #1437

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 57 additions & 11 deletions tfhe/src/high_level_api/backward_compatibility/keys.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::high_level_api::keys::*;
use crate::shortint::list_compression::{CompressionKey, CompressionPrivateKeys, DecompressionKey};
use std::convert::Infallible;
use std::sync::Arc;

use tfhe_versionable::{Upgrade, Version, VersionsDispatch};

use crate::high_level_api::keys::*;

#[derive(VersionsDispatch)]
pub enum ClientKeyVersions {
V0(ClientKey),
Expand Down Expand Up @@ -70,23 +69,45 @@ pub(crate) struct IntegerClientKeyV0 {
pub(crate) wopbs_block_parameters: Option<crate::shortint::WopbsParameters>,
}

impl Upgrade<IntegerClientKey> for IntegerClientKeyV0 {
#[derive(Version)]
pub(crate) struct IntegerClientKeyV1 {
pub(crate) key: crate::integer::ClientKey,
pub(crate) wopbs_block_parameters: Option<crate::shortint::WopbsParameters>,
pub(crate) dedicated_compact_private_key: Option<CompactPrivateKey>,
pub(crate) compression_key: Option<CompressionPrivateKeys>,
}

impl Upgrade<IntegerClientKeyV1> for IntegerClientKeyV0 {
type Error = Infallible;

fn upgrade(self) -> Result<IntegerClientKey, Self::Error> {
Ok(IntegerClientKey {
fn upgrade(self) -> Result<IntegerClientKeyV1, Self::Error> {
Ok(IntegerClientKeyV1 {
key: self.key,
wopbs_block_parameters: self.wopbs_block_parameters,
dedicated_compact_private_key: None,
compression_key: None,
})
}
}

impl Upgrade<IntegerClientKey> for IntegerClientKeyV1 {
type Error = Infallible;

fn upgrade(self) -> Result<IntegerClientKey, Self::Error> {
Ok(IntegerClientKey {
key: self.key,
dedicated_compact_private_key: self.dedicated_compact_private_key,
compression_key: self.compression_key,
})
}
}

#[derive(VersionsDispatch)]
#[allow(unused)]
pub(crate) enum IntegerClientKeyVersions {
V0(IntegerClientKeyV0),
V1(IntegerClientKey),
V1(IntegerClientKeyV1),
V2(IntegerClientKey),
}

#[derive(Version)]
Expand All @@ -95,23 +116,48 @@ pub struct IntegerServerKeyV0 {
pub(crate) wopbs_key: Option<crate::integer::wopbs::WopbsKey>,
}

impl Upgrade<IntegerServerKey> for IntegerServerKeyV0 {
#[derive(Version)]
pub struct IntegerServerKeyV1 {
pub(crate) key: crate::integer::ServerKey,
pub(crate) wopbs_key: Option<crate::integer::wopbs::WopbsKey>,
pub(crate) cpk_key_switching_key_material:
Option<crate::integer::key_switching_key::KeySwitchingKeyMaterial>,
pub(crate) compression_key: Option<CompressionKey>,
pub(crate) decompression_key: Option<DecompressionKey>,
}

impl Upgrade<IntegerServerKeyV1> for IntegerServerKeyV0 {
type Error = Infallible;

fn upgrade(self) -> Result<IntegerServerKey, Self::Error> {
Ok(IntegerServerKey {
fn upgrade(self) -> Result<IntegerServerKeyV1, Self::Error> {
Ok(IntegerServerKeyV1 {
key: self.key,
wopbs_key: self.wopbs_key,
cpk_key_switching_key_material: None,
compression_key: None,
decompression_key: None,
})
}
}

impl Upgrade<IntegerServerKey> for IntegerServerKeyV1 {
type Error = Infallible;

fn upgrade(self) -> Result<IntegerServerKey, Self::Error> {
Ok(IntegerServerKey {
key: self.key,
cpk_key_switching_key_material: self.cpk_key_switching_key_material,
compression_key: self.compression_key,
decompression_key: self.decompression_key,
nsarlin-zama marked this conversation as resolved.
Show resolved Hide resolved
})
}
}

#[derive(VersionsDispatch)]
pub enum IntegerServerKeyVersions {
V0(IntegerServerKeyV0),
V1(IntegerServerKey),
V1(IntegerServerKeyV1),
V2(IntegerServerKey),
}

#[derive(Version)]
Expand Down
Loading