pub struct WopbsKey { /* private fields */ }Implementations§
Source§impl WopbsKey
impl WopbsKey
Sourcepub fn new_wopbs_key(
cks: &ClientKey,
sks: &ServerKey,
parameters: &Parameters,
) -> WopbsKey
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);pub fn new_from_shortint(wopbskey: &WopbsKey) -> WopbsKey
pub fn new_wopbs_key_only_for_wopbs( cks: &ClientKey, sks: &ServerKey, ) -> WopbsKey
Sourcepub fn wopbs<T>(&self, ct_in: &T, lut: &[Vec<u64>]) -> Twhere
T: IntegerCiphertext,
pub fn wopbs<T>(&self, ct_in: &T, lut: &[Vec<u64>]) -> Twhere
T: IntegerCiphertext,
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);Sourcepub fn wopbs_without_padding<T>(&self, ct_in: &T, lut: &[Vec<u64>]) -> Twhere
T: IntegerCiphertext,
pub fn wopbs_without_padding<T>(&self, ct_in: &T, lut: &[Vec<u64>]) -> Twhere
T: IntegerCiphertext,
§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)Sourcepub fn wopbs_native_crt(
&self,
ct1: &CrtCiphertext,
lut: &[Vec<u64>],
) -> CrtCiphertext
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(¶m);
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);Sourcepub fn bivariate_wopbs_with_degree<T>(
&self,
ct1: &T,
ct2: &T,
lut: &[Vec<u64>],
) -> Twhere
T: IntegerCiphertext,
pub fn bivariate_wopbs_with_degree<T>(
&self,
ct1: &T,
ct2: &T,
lut: &[Vec<u64>],
) -> Twhere
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 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);Sourcepub fn generate_lut_radix<F, T>(&self, ct: &T, f: F) -> Vec<Vec<u64>>
pub fn generate_lut_radix<F, T>(&self, ct: &T, f: F) -> Vec<Vec<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 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);Sourcepub fn generate_lut_radix_without_padding<F, T>(
&self,
ct: &T,
f: F,
) -> Vec<Vec<u64>>
pub fn generate_lut_radix_without_padding<F, T>( &self, ct: &T, f: F, ) -> Vec<Vec<u64>>
§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)Sourcepub fn generate_lut_native_crt<F>(
&self,
ct: &CrtCiphertext,
f: F,
) -> Vec<Vec<u64>>
pub fn generate_lut_native_crt<F>( &self, ct: &CrtCiphertext, f: F, ) -> Vec<Vec<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(¶m);
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);Sourcepub fn generate_lut_crt<F>(&self, ct: &CrtCiphertext, f: F) -> Vec<Vec<u64>>
pub fn generate_lut_crt<F>(&self, ct: &CrtCiphertext, f: F) -> Vec<Vec<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);Sourcepub fn generate_lut_bivariate_radix<F>(
&self,
ct1: &RadixCiphertext,
ct2: &RadixCiphertext,
f: F,
) -> Vec<Vec<u64>>
pub fn generate_lut_bivariate_radix<F>( &self, ct1: &RadixCiphertext, ct2: &RadixCiphertext, f: F, ) -> Vec<Vec<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);Sourcepub fn generate_lut_bivariate_crt<F>(
&self,
ct1: &CrtCiphertext,
ct2: &CrtCiphertext,
f: F,
) -> Vec<Vec<u64>>
pub fn generate_lut_bivariate_crt<F>( &self, ct1: &CrtCiphertext, ct2: &CrtCiphertext, f: F, ) -> Vec<Vec<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 );Sourcepub fn generate_lut_bivariate_native_crt<F>(
&self,
ct_1: &CrtCiphertext,
f: F,
) -> Vec<Vec<u64>>
pub fn generate_lut_bivariate_native_crt<F>( &self, ct_1: &CrtCiphertext, f: F, ) -> Vec<Vec<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(¶m);
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);Sourcepub fn bivariate_wopbs_native_crt(
&self,
ct1: &CrtCiphertext,
ct2: &CrtCiphertext,
lut: &[Vec<u64>],
) -> CrtCiphertext
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(¶m);
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);pub fn keyswitch_to_wopbs_params<T>(&self, sks: &ServerKey, ct_in: &T) -> Twhere
T: IntegerCiphertext,
pub fn keyswitch_to_pbs_params<T>(&self, ct_in: &T) -> Twhere
T: IntegerCiphertext,
Trait Implementations§
Source§impl<'de> Deserialize<'de> for WopbsKey
impl<'de> Deserialize<'de> for WopbsKey
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for WopbsKey
impl RefUnwindSafe for WopbsKey
impl Send for WopbsKey
impl Sync for WopbsKey
impl Unpin for WopbsKey
impl UnwindSafe for WopbsKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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