Skip to main content

UpgradeKeyChain

Struct UpgradeKeyChain 

Source
pub struct UpgradeKeyChain { /* private fields */ }
Expand description

This struct is meant to provide a mean to change the parameters under which ciphertexts are encrypted in.

This is to help applications which will change parameters used to keep good security or to be able to target new hardware and still be able to easily load and update old ciphertexts (with old parameters). Provided an upgrade path exists.

Parameters are identified by 3 components:

To register parameters, add a key

Then upgrade keys that allow to go from one parameter set to another should be added with Self::add_upgrade_key

§Example

use tfhe::prelude::*;
use tfhe::shortint::parameters::{
    COMP_PARAM_MESSAGE_2_CARRY_2, PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
    PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
};
use tfhe::upgrade::UpgradeKeyChain;
use tfhe::{
    set_server_key, ClientKey, ConfigBuilder, Device, FheUint32, KeySwitchingKey, ServerKey,
};

let compute_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128;
let compression_parameters = COMP_PARAM_MESSAGE_2_CARRY_2;

let config = ConfigBuilder::with_custom_parameters(compute_params)
    .enable_compression(compression_parameters)
    .build();

let mut ck1 = ClientKey::generate(config);
ck1.tag_mut().set_u64(1);
let sk1 = ServerKey::new(&ck1);
assert_eq!(sk1.tag().as_u64(), 1);

let mut ck2 = ClientKey::generate(config);
ck2.tag_mut().set_u64(2);
let sk2 = ServerKey::new(&ck2);
assert_eq!(sk2.tag().as_u64(), 2);

let ksk = KeySwitchingKey::with_parameters(
    (&ck1, &sk1),
    (&ck2, &sk2),
    PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
);

let mut upgrader = UpgradeKeyChain::new();
upgrader.add_key_set(&sk1);
upgrader.add_key_set(&sk2);
upgrader.add_upgrade_key(ksk).unwrap();

let clear_a = 23428u32;
let clear_b = 985427u32;

let a = FheUint32::encrypt(clear_a, &ck1);
let b = FheUint32::encrypt(clear_b, &ck1);

let upgraded_a = upgrader.upgrade(&a, ck2.tag(), Device::Cpu).unwrap();
let upgraded_b = upgrader.upgrade(&b, ck2.tag(), Device::Cpu).unwrap();

set_server_key(sk2);

let c = upgraded_a + upgraded_b;
let dc: u32 = c.decrypt(&ck2);
assert_eq!(dc, clear_a.wrapping_add(clear_b));

Implementations§

Source§

impl UpgradeKeyChain

Source

pub fn new() -> Self

Creates a new and empty upgrader

Source

pub fn add_key_set(&mut self, sks: &ServerKey)

Adds the CPU server key into the upgrade system

  • It adds the compute parameters
  • It adds the compression parameters (if they exist)
  • It adds a path to go from compression parameters to compute parameters
Source

pub fn add_key_set_gpu(&mut self, sks: &CudaServerKey)

Adds the GPU server key into the upgrade system

  • It adds the compute parameters
  • It adds the compression parameters (if they exist)
Source

pub fn add_upgrade_key(&mut self, key: impl Into<UpgradeKey>) -> Result<()>

Adds an upgrade key to the system

There are 2 types of UpgradeKey

  • KeySwitchKey: to go from compute params to other compute params
  • Decompression: to go from compressed params to some compute params
Source

pub fn upgrade<T>( &self, ct: &T, dest_tag: &Tag, dest_device: Device, ) -> Result<T>

Upgrades the input ciphertext to the compute params of the selected tag and device

Returns an error if no upgrade path could be found

Source

pub fn upgrade_from_compressed<T>( &self, input: &CompressedCiphertextList, index: usize, dest_tag: &Tag, dest_device: Device, ) -> Result<T>

Upgrades the input compressed ciphertext to the compute params of the selected tag and device

Returns an error if no upgrade path could be found

Trait Implementations§

Source§

impl Default for UpgradeKeyChain

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Input, Output> CastInto<Output> for Input
where Output: CastFrom<Input>,

Source§

fn cast_into(self) -> Output

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more