WopbsKey

Struct WopbsKey 

Source
pub struct WopbsKey { /* private fields */ }

Implementations§

Source§

impl WopbsKey

Source

pub fn new_wopbs_key( cks: &ClientKey, sks: &ServerKey, parameters: &Parameters, ) -> WopbsKey

Generates the server key required to compute a WoPBS from the client and the server keys.

§Example
use concrete_integer::gen_keys;
use concrete_shortint::parameters::parameters_wopbs_message_carry::WOPBS_PARAM_MESSAGE_1_CARRY_1;
use concrete_integer::wopbs::*;
use concrete_shortint::parameters::PARAM_MESSAGE_1_CARRY_1;

// Generate the client key and the server key:
let (mut cks, mut sks) = gen_keys(&PARAM_MESSAGE_1_CARRY_1);
let mut wopbs_key = WopbsKey::new_wopbs_key(&cks, &sks, &WOPBS_PARAM_MESSAGE_1_CARRY_1);
Source

pub fn new_from_shortint(wopbskey: &WopbsKey) -> WopbsKey

Source

pub fn new_wopbs_key_only_for_wopbs( cks: &ClientKey, sks: &ServerKey, ) -> WopbsKey

Source

pub fn wopbs<T>(&self, ct_in: &T, lut: &[Vec<u64>]) -> T

Computes the WoP-PBS given the luts.

This works for both RadixCiphertext and CrtCiphertext.

§Example
use concrete_integer::gen_keys;
use concrete_shortint::parameters::parameters_wopbs_message_carry::WOPBS_PARAM_MESSAGE_2_CARRY_2;
use concrete_integer::wopbs::*;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;

let nb_block = 3;
//Generate the client key and the server key:
let (mut cks, mut sks) = gen_keys(&PARAM_MESSAGE_2_CARRY_2);
let mut wopbs_key = WopbsKey::new_wopbs_key(&cks, &sks, &WOPBS_PARAM_MESSAGE_2_CARRY_2);
let mut moduli = 1_u64;
for _ in 0..nb_block{
    moduli *= cks.parameters().message_modulus.0 as u64;
}
let clear = 42 % moduli;
let ct = cks.encrypt_radix(clear as u64, nb_block);
let ct = wopbs_key.keyswitch_to_wopbs_params(&sks,&ct);
let lut = wopbs_key.generate_lut_radix(&ct, |x|x);
let ct_res = wopbs_key.wopbs(&ct, &lut);
let ct_res = wopbs_key.keyswitch_to_pbs_params(&ct_res);
let res = cks.decrypt_radix(&ct_res);

 assert_eq!(res, clear);
Source

pub fn wopbs_without_padding<T>(&self, ct_in: &T, lut: &[Vec<u64>]) -> T

§Example
use concrete_integer::gen_keys;
use concrete_integer::wopbs::WopbsKey;
use concrete_shortint::parameters::parameters_wopbs_message_carry::WOPBS_PARAM_MESSAGE_2_CARRY_2;

let nb_block = 3;
//Generate the client key and the server key:
let (mut cks, mut sks) = gen_keys(&WOPBS_PARAM_MESSAGE_2_CARRY_2);
let mut wopbs_key = WopbsKey::new_wopbs_key_only_for_wopbs(&cks, &sks);
let mut moduli = 1_u64;
for _ in 0..nb_block{
    moduli *= cks.parameters().message_modulus.0 as u64;
}
let clear = 15 % moduli;
let ct = cks.encrypt_radix_without_padding(clear as u64, nb_block);
let lut = wopbs_key.generate_lut_radix_without_padding(&ct, |x| 2 * x);
let ct_res = wopbs_key.wopbs_without_padding(&ct, &lut);
let res = cks.decrypt_radix_without_padding(&ct_res);

assert_eq!(res, (clear * 2) % moduli)
Source

pub fn wopbs_native_crt( &self, ct1: &CrtCiphertext, lut: &[Vec<u64>], ) -> CrtCiphertext

WOPBS for native CRT

§Example
use concrete_integer::gen_keys;
use concrete_integer::parameters::PARAM_4_BITS_5_BLOCKS;
use concrete_integer::wopbs::WopbsKey;

let basis: Vec<u64> = vec![9, 11];

let param = PARAM_4_BITS_5_BLOCKS;
//Generate the client key and the server key:
let (cks, sks) = gen_keys(&param);
let mut wopbs_key = WopbsKey::new_wopbs_key_only_for_wopbs(&cks, &sks);

let mut msg_space = 1;
for modulus in basis.iter() {
    msg_space *= modulus;
}
let clear = 42 % msg_space; // Encrypt the integers
let mut ct = cks.encrypt_native_crt(clear, basis.clone());
let lut = wopbs_key.generate_lut_native_crt(&ct, |x| x);
let ct_res = wopbs_key.wopbs_native_crt(&mut ct, &lut);
let res = cks.decrypt_native_crt(&ct_res);
assert_eq!(res, clear);
Source

pub fn bivariate_wopbs_with_degree<T>( &self, ct1: &T, ct2: &T, lut: &[Vec<u64>], ) -> T

§Example
use concrete_integer::gen_keys;
use concrete_shortint::parameters::parameters_wopbs_message_carry::WOPBS_PARAM_MESSAGE_2_CARRY_2;
use concrete_integer::wopbs::*;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;

let nb_block = 3;
//Generate the client key and the server key:
let (cks, sks) = gen_keys(&PARAM_MESSAGE_2_CARRY_2);

//Generate wopbs_v0 key    ///
let wopbs_key = WopbsKey::new_wopbs_key(&cks, &sks, &WOPBS_PARAM_MESSAGE_2_CARRY_2);
let mut moduli = 1_u64;
for _ in 0..nb_block{
    moduli *= cks.parameters().message_modulus.0 as u64;
}
let clear1 = 42 % moduli;
let clear2 = 24 % moduli;
let ct1 = cks.encrypt_radix(clear1 as u64, nb_block);
let ct2 = cks.encrypt_radix(clear2 as u64, nb_block);

let ct1 = wopbs_key.keyswitch_to_wopbs_params(&sks, &ct1);
let ct2 = wopbs_key.keyswitch_to_wopbs_params(&sks, &ct2);
let lut = wopbs_key.generate_lut_bivariate_radix(&ct1, &ct2, |x,y| 2 * x * y);
let ct_res = wopbs_key.bivariate_wopbs_with_degree(& ct1, & ct2, &lut);
let ct_res = wopbs_key.keyswitch_to_pbs_params(&ct_res);
let res = cks.decrypt_radix(&ct_res);

 assert_eq!(res, (2 * clear1 * clear2) % moduli);
Source

pub fn generate_lut_radix<F, T>(&self, ct: &T, f: F) -> Vec<Vec<u64>>
where F: Fn(u64) -> u64, T: IntegerCiphertext,

§Example
use concrete_integer::gen_keys;
use concrete_shortint::parameters::parameters_wopbs_message_carry::WOPBS_PARAM_MESSAGE_2_CARRY_2;
use concrete_integer::wopbs::*;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;

let nb_block = 3;
//Generate the client key and the server key:
let (cks, sks) = gen_keys(&PARAM_MESSAGE_2_CARRY_2);

//Generate wopbs_v0 key    ///
let mut wopbs_key = WopbsKey::new_wopbs_key(&cks, &sks, &WOPBS_PARAM_MESSAGE_2_CARRY_2);
let mut moduli = 1_u64;
for _ in 0..nb_block{
    moduli *= cks.parameters().message_modulus.0 as u64;
}
let clear = 42 % moduli;
let ct = cks.encrypt_radix(clear as u64, nb_block);
let ct = wopbs_key.keyswitch_to_wopbs_params(&sks, &ct);
let lut = wopbs_key.generate_lut_radix(&ct, |x| 2 * x);
let ct_res = wopbs_key.wopbs(&ct, &lut);
let ct_res = wopbs_key.keyswitch_to_pbs_params(&ct_res);
let res = cks.decrypt_radix(&ct_res);

 assert_eq!(res, (2 * clear) % moduli);
Source

pub fn generate_lut_radix_without_padding<F, T>( &self, ct: &T, f: F, ) -> Vec<Vec<u64>>
where F: Fn(u64) -> u64, T: IntegerCiphertext,

§Example
use concrete_integer::gen_keys;
use concrete_integer::wopbs::WopbsKey;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
use concrete_shortint::parameters::parameters_wopbs_message_carry::WOPBS_PARAM_MESSAGE_2_CARRY_2;

let nb_block = 3;
//Generate the client key and the server key:
let (cks, sks) = gen_keys(&PARAM_MESSAGE_2_CARRY_2);
//Generate wopbs_v0 key
let mut wopbs_key = WopbsKey::new_wopbs_key(&cks, &sks, &WOPBS_PARAM_MESSAGE_2_CARRY_2);
let mut moduli = 1_u64;
for _ in 0..nb_block{
    moduli *= cks.parameters().message_modulus.0 as u64;
}
let clear = 15 % moduli;
let ct = cks.encrypt_radix_without_padding(clear as u64, nb_block);
let ct = wopbs_key.keyswitch_to_wopbs_params(&sks,&ct);
let lut = wopbs_key.generate_lut_radix_without_padding(&ct, |x| 2 * x);
let ct_res = wopbs_key.wopbs_without_padding(&ct, &lut);
let ct_res = wopbs_key.keyswitch_to_pbs_params(&ct_res);
let res = cks.decrypt_radix_without_padding(&ct_res);

assert_eq!(res, (clear * 2) % moduli)
Source

pub fn generate_lut_native_crt<F>( &self, ct: &CrtCiphertext, f: F, ) -> Vec<Vec<u64>>
where F: Fn(u64) -> u64,

generate lut for native CRT

§Example
use concrete_integer::gen_keys;
use concrete_integer::parameters::PARAM_4_BITS_5_BLOCKS;
use concrete_integer::wopbs::WopbsKey;

let basis: Vec<u64> = vec![9, 11];

let param = PARAM_4_BITS_5_BLOCKS;
//Generate the client key and the server key:
let (cks, sks) = gen_keys(&param);
let mut wopbs_key = WopbsKey::new_wopbs_key_only_for_wopbs(&cks, &sks);

let mut msg_space = 1;
for modulus in basis.iter() {
    msg_space *= modulus;
}
let clear = 42 % msg_space; // Encrypt the integers
let mut ct = cks.encrypt_native_crt(clear, basis.clone());
let lut = wopbs_key.generate_lut_native_crt(&ct, |x| x);
let ct_res = wopbs_key.wopbs_native_crt(&mut ct, &lut);
let res = cks.decrypt_native_crt(&ct_res);
assert_eq!(res, clear);
Source

pub fn generate_lut_crt<F>(&self, ct: &CrtCiphertext, f: F) -> Vec<Vec<u64>>
where F: Fn(u64) -> u64,

generate LUt for crt

§Example
 
use concrete_integer::gen_keys;
use concrete_integer::wopbs::*;
use concrete_shortint::parameters::PARAM_MESSAGE_3_CARRY_3;
use concrete_shortint::parameters::parameters_wopbs_message_carry::WOPBS_PARAM_MESSAGE_3_CARRY_3;

let basis : Vec<u64> = vec![5,7];
let nb_block = basis.len();

//Generate the client key and the server key:
let (cks, sks) = gen_keys(&PARAM_MESSAGE_3_CARRY_3);
let wopbs_key =  WopbsKey::new_wopbs_key(&cks, &sks, &WOPBS_PARAM_MESSAGE_3_CARRY_3);

let mut msg_space = 1;
for modulus in basis.iter() {
    msg_space *= modulus;
}
let clear = 42 % msg_space;
let ct = cks.encrypt_crt(clear, basis.clone());
let ct = wopbs_key.keyswitch_to_wopbs_params(&sks,&ct);
let lut = wopbs_key.generate_lut_crt(&ct, |x| x);
let ct_res = wopbs_key.wopbs(&ct, &lut);
let ct_res = wopbs_key.keyswitch_to_pbs_params(&ct_res);
let res = cks.decrypt_crt(&ct_res);
assert_eq!(res, clear);
Source

pub fn generate_lut_bivariate_radix<F>( &self, ct1: &RadixCiphertext, ct2: &RadixCiphertext, f: F, ) -> Vec<Vec<u64>>
where F: Fn(u64, u64) -> u64,

§Example
use concrete_integer::gen_keys;
use concrete_shortint::parameters::parameters_wopbs_message_carry::WOPBS_PARAM_MESSAGE_2_CARRY_2;
use concrete_integer::wopbs::*;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;

let nb_block = 3;
//Generate the client key and the server key:
let (cks, sks) = gen_keys(&PARAM_MESSAGE_2_CARRY_2);

//Generate wopbs_v0 key    ///
let wopbs_key = WopbsKey::new_wopbs_key(&cks, &sks, &WOPBS_PARAM_MESSAGE_2_CARRY_2);
let mut moduli = 1_u64;
for _ in 0..nb_block{
    moduli *= cks.parameters().message_modulus.0 as u64;
}
let clear1 = 42 % moduli;
let clear2 = 24 % moduli;
let ct1 = cks.encrypt_radix(clear1 as u64, nb_block);
let ct2 = cks.encrypt_radix(clear2 as u64, nb_block);

let ct1 = wopbs_key.keyswitch_to_wopbs_params(&sks,&ct1);
let ct2 = wopbs_key.keyswitch_to_wopbs_params(&sks,&ct2);
let lut = wopbs_key.generate_lut_bivariate_radix(&ct1, &ct2, |x,y| 2 * x * y);
let ct_res = wopbs_key.bivariate_wopbs_with_degree(&ct1, &ct2, &lut);
let ct_res = wopbs_key.keyswitch_to_pbs_params(&ct_res);
let res = cks.decrypt_radix(&ct_res);

 assert_eq!(res, (2 * clear1 * clear2) % moduli);
Source

pub fn generate_lut_bivariate_crt<F>( &self, ct1: &CrtCiphertext, ct2: &CrtCiphertext, f: F, ) -> Vec<Vec<u64>>
where F: Fn(u64, u64) -> u64,

generate bivariate LUT for ‘fake’ CRT

§Example
 
use concrete_integer::gen_keys;
use concrete_integer::wopbs::*;
use concrete_shortint::parameters::PARAM_MESSAGE_3_CARRY_3;
use concrete_shortint::parameters::parameters_wopbs_message_carry::WOPBS_PARAM_MESSAGE_3_CARRY_3;

let basis : Vec<u64> = vec![5,7];
//Generate the client key and the server key:
let ( cks, sks) = gen_keys(&PARAM_MESSAGE_3_CARRY_3);
let wopbs_key =  WopbsKey::new_wopbs_key(&cks, &sks, &WOPBS_PARAM_MESSAGE_3_CARRY_3);

let mut msg_space = 1;
for modulus in basis.iter() {
    msg_space *= modulus;
}
let clear1 = 42 % msg_space;    // Encrypt the integers
let clear2 = 24 % msg_space;    // Encrypt the integers
let ct1 = cks.encrypt_crt(clear1, basis.clone());
let ct2 = cks.encrypt_crt(clear2, basis.clone());

let ct1 = wopbs_key.keyswitch_to_wopbs_params(&sks, &ct1);
let ct2 = wopbs_key.keyswitch_to_wopbs_params(&sks, &ct2);


let lut = wopbs_key.generate_lut_bivariate_crt(&ct1, &ct2, |x,y| x * y * 2);
let ct_res = wopbs_key.bivariate_wopbs_with_degree(&ct1, &ct2, &lut);
let ct_res = wopbs_key.keyswitch_to_pbs_params(&ct_res);
let res = cks.decrypt_crt(&ct_res);
assert_eq!(res, (clear1 * clear2 * 2) % msg_space );
Source

pub fn generate_lut_bivariate_native_crt<F>( &self, ct_1: &CrtCiphertext, f: F, ) -> Vec<Vec<u64>>
where F: Fn(u64, u64) -> u64,

generate bivariate LUT for ‘true’ CRT

§Example
use concrete_integer::gen_keys;
use concrete_integer::parameters::PARAM_4_BITS_5_BLOCKS;
use concrete_integer::wopbs::WopbsKey;

let basis: Vec<u64> = vec![9, 11];

let param = PARAM_4_BITS_5_BLOCKS;
//Generate the client key and the server key:
let (cks, sks) = gen_keys(&param);
let mut wopbs_key = WopbsKey::new_wopbs_key_only_for_wopbs(&cks, &sks);

let mut msg_space = 1;
for modulus in basis.iter() {
    msg_space *= modulus;
}
let clear1 = 42 % msg_space;
let clear2 = 24 % msg_space;
let mut ct1 = cks.encrypt_native_crt(clear1, basis.clone());
let mut ct2 = cks.encrypt_native_crt(clear2, basis.clone());
let lut = wopbs_key.generate_lut_bivariate_native_crt(&ct1, |x, y| x * y * 2);
let ct_res = wopbs_key.bivariate_wopbs_native_crt(&mut ct1, &mut ct2, &lut);
let res = cks.decrypt_native_crt(&ct_res);
assert_eq!(res, (clear1 * clear2 * 2) % msg_space);
Source

pub fn bivariate_wopbs_native_crt( &self, ct1: &CrtCiphertext, ct2: &CrtCiphertext, lut: &[Vec<u64>], ) -> CrtCiphertext

bivariate WOPBS for native CRT

§Example
use concrete_integer::gen_keys;
use concrete_integer::parameters::PARAM_4_BITS_5_BLOCKS;
use concrete_integer::wopbs::WopbsKey;

let basis: Vec<u64> = vec![9, 11];

let param = PARAM_4_BITS_5_BLOCKS;
//Generate the client key and the server key:
let (cks, sks) = gen_keys(&param);
let mut wopbs_key = WopbsKey::new_wopbs_key_only_for_wopbs(&cks, &sks);

let mut msg_space = 1;
for modulus in basis.iter() {
    msg_space *= modulus;
}
let clear1 = 42 % msg_space;
let clear2 = 24 % msg_space;
let mut ct1 = cks.encrypt_native_crt(clear1, basis.clone());
let mut ct2 = cks.encrypt_native_crt(clear2, basis.clone());
let lut = wopbs_key.generate_lut_bivariate_native_crt(&ct1, |x, y| x * y * 2);
let ct_res = wopbs_key.bivariate_wopbs_native_crt(&mut ct1, &mut ct2, &lut);
let res = cks.decrypt_native_crt(&ct_res);
assert_eq!(res, (clear1 * clear2 * 2) % msg_space);
Source

pub fn keyswitch_to_wopbs_params<T>(&self, sks: &ServerKey, ct_in: &T) -> T

Source

pub fn keyswitch_to_pbs_params<T>(&self, ct_in: &T) -> T

Trait Implementations§

Source§

impl Clone for WopbsKey

Source§

fn clone(&self) -> WopbsKey

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'de> Deserialize<'de> for WopbsKey

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<WopbsKey> for WopbsKey

Source§

fn from(wopbs_key: WopbsKey) -> Self

Converts to this type from the input type.
Source§

impl Serialize for WopbsKey

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,