pub struct ClientKey { /* private fields */ }
Expand description
A structure containing the client key, which must be kept secret.
This key can be used to encrypt both in Radix and CRT decompositions.
Using this key, for both decompositions, each block will use the same crypto parameters.
Implementations§
Source§impl ClientKey
impl ClientKey
Sourcepub fn new(parameter_set: Parameters) -> Self
pub fn new(parameter_set: Parameters) -> Self
Creates a Client Key.
§Example
use concrete_integer::ClientKey;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
// Generate the client key, that can encrypt in
// radix and crt decomposition, where each block of the decomposition
// have over 2 bits of message modulus.
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
pub fn parameters(&self) -> Parameters
Sourcepub fn encrypt_radix(&self, message: u64, num_blocks: usize) -> RadixCiphertext
pub fn encrypt_radix(&self, message: u64, num_blocks: usize) -> RadixCiphertext
Encrypts an integer in radix decomposition
§Example
use concrete_integer::ClientKey;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
let num_block = 4;
let msg = 167_u64;
// 2 * 4 = 8 bits of message
let ct = cks.encrypt_radix(msg, num_block);
// Decryption
let dec = cks.decrypt_radix(&ct);
assert_eq!(msg, dec);
Sourcepub fn encrypt_radix_without_padding(
&self,
message: u64,
num_blocks: usize,
) -> RadixCiphertext
pub fn encrypt_radix_without_padding( &self, message: u64, num_blocks: usize, ) -> RadixCiphertext
Encrypts an integer in radix decomposition without padding bit
§Example
use concrete_integer::ClientKey;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
let num_block = 4;
let msg = 167_u64;
// 2 * 4 = 8 bits of message
let ct = cks.encrypt_radix_without_padding(msg, num_block);
// Decryption
let dec = cks.decrypt_radix_without_padding(&ct);
assert_eq!(msg, dec);
Sourcepub fn encrypt_one_block(&self, message: u64) -> Ciphertext
pub fn encrypt_one_block(&self, message: u64) -> Ciphertext
Encrypts one block.
This returns a shortint ciphertext.
§Example
use concrete_integer::ClientKey;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
let num_block = 4;
let msg = 2_u64;
// Encryption
let ct = cks.encrypt_one_block(msg);
// Decryption
let dec = cks.decrypt_one_block(&ct);
assert_eq!(msg, dec);
Sourcepub fn decrypt_one_block(&self, ct: &Ciphertext) -> u64
pub fn decrypt_one_block(&self, ct: &Ciphertext) -> u64
Decrypts one block.
This takes a shortint ciphertext as input.
Sourcepub fn decrypt_radix(&self, ctxt: &RadixCiphertext) -> u64
pub fn decrypt_radix(&self, ctxt: &RadixCiphertext) -> u64
Decrypts a ciphertext encrypting an radix integer
§Example
use concrete_integer::ClientKey;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
let num_block = 4;
let msg = 191_u64;
// Encryption
let ct = cks.encrypt_radix(msg, num_block);
// Decryption
let dec = cks.decrypt_radix(&ct);
assert_eq!(msg, dec);
Sourcepub fn decrypt_radix_without_padding(&self, ctxt: &RadixCiphertext) -> u64
pub fn decrypt_radix_without_padding(&self, ctxt: &RadixCiphertext) -> u64
Decrypts a ciphertext encrypting an radix integer encrypted without padding
§Example
use concrete_integer::ClientKey;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
let num_block = 4;
let msg = 191_u64;
// Encryption
let ct = cks.encrypt_radix_without_padding(msg, num_block);
// Decryption
let dec = cks.decrypt_radix_without_padding(&ct);
assert_eq!(msg, dec);
Sourcepub fn encrypt_crt(&self, message: u64, base_vec: Vec<u64>) -> CrtCiphertext
pub fn encrypt_crt(&self, message: u64, base_vec: Vec<u64>) -> CrtCiphertext
Encrypts an integer using crt representation
§Example
use concrete_integer::ClientKey;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
let msg = 13_u64;
// Encryption:
let basis: Vec<u64> = vec![2, 3, 5];
let ct = cks.encrypt_crt(msg, basis);
// Decryption:
let dec = cks.decrypt_crt(&ct);
assert_eq!(msg, dec);
Sourcepub fn decrypt_crt(&self, ctxt: &CrtCiphertext) -> u64
pub fn decrypt_crt(&self, ctxt: &CrtCiphertext) -> u64
Decrypts an integer in crt decomposition
§Example
use concrete_integer::ClientKey;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
// Generate the client key and the server key:
let mut cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
let msg = 27_u64;
let basis: Vec<u64> = vec![2, 3, 5];
// Encryption:
let mut ct = cks.encrypt_crt(msg, basis);
// Decryption:
let dec = cks.decrypt_crt(&ct);
assert_eq!(msg, dec);
Sourcepub fn encrypt_native_crt(
&self,
message: u64,
base_vec: Vec<u64>,
) -> CrtCiphertext
pub fn encrypt_native_crt( &self, message: u64, base_vec: Vec<u64>, ) -> CrtCiphertext
Encrypts a small integer message using the client key and some moduli without padding bit.
§Example
use concrete_integer::ClientKey;
use concrete_shortint::parameters::PARAM_MESSAGE_3_CARRY_3;
let cks = ClientKey::new(PARAM_MESSAGE_3_CARRY_3);
let msg = 13_u64;
// Encryption of one message:
let basis: Vec<u64> = vec![2, 3, 5];
let ct = cks.encrypt_native_crt(msg, basis);
// Decryption:
let dec = cks.decrypt_native_crt(&ct);
assert_eq!(msg, dec);
Sourcepub fn decrypt_native_crt(&self, ct: &CrtCiphertext) -> u64
pub fn decrypt_native_crt(&self, ct: &CrtCiphertext) -> u64
Decrypts a ciphertext encrypting an integer message with some moduli basis without padding bit.
§Example
use concrete_integer::ClientKey;
use concrete_shortint::parameters::PARAM_MESSAGE_3_CARRY_3;
let cks = ClientKey::new(PARAM_MESSAGE_3_CARRY_3);
let msg = 27_u64;
let basis: Vec<u64> = vec![2, 3, 5];
// Encryption of one message:
let mut ct = cks.encrypt_native_crt(msg, basis);
// Decryption:
let dec = cks.decrypt_native_crt(&ct);
assert_eq!(msg, dec);
Trait Implementations§
Source§impl AsRef<ClientKey> for CrtClientKey
impl AsRef<ClientKey> for CrtClientKey
Source§impl AsRef<ClientKey> for RadixClientKey
impl AsRef<ClientKey> for RadixClientKey
Source§impl<'de> Deserialize<'de> for ClientKey
impl<'de> Deserialize<'de> for ClientKey
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>,
impl StructuralPartialEq for ClientKey
Auto Trait Implementations§
impl Freeze for ClientKey
impl RefUnwindSafe for ClientKey
impl Send for ClientKey
impl Sync for ClientKey
impl Unpin for ClientKey
impl UnwindSafe for ClientKey
Blanket Implementations§
Source§impl<'short, T, Target> AsGeneralizedRef<'short, &'short Target> for T
impl<'short, T, Target> AsGeneralizedRef<'short, &'short Target> for T
fn as_generalized_ref(&'short self) -> &'short Target
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
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>
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>
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