Struct concrete_integer::client_key::ClientKey
source · [−]pub struct ClientKey { /* private fields */ }
Expand description
A structure containing the client key, which must be kept secret.
Implementations
sourceimpl ClientKey
impl ClientKey
sourcepub fn new(parameter_set: Parameters, size: usize) -> Self
pub fn new(parameter_set: Parameters, size: usize) -> Self
Allocates and generates a client key.
Example
use concrete_integer::client_key::ClientKey;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
// Generate the client key associated to integers over 4 blocks
// of messages with modulus over 2 bits
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2, 4);
sourcepub fn from_shortint(key: ClientKey, vector_length: VecLength) -> Self
pub fn from_shortint(key: ClientKey, vector_length: VecLength) -> Self
Allocates and generates a client key from an existing shortint client key.
Example
use concrete_integer::client_key::{ClientKey, VecLength};
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
let shortint_cks = concrete_shortint::ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
let cks = ClientKey::from_shortint(shortint_cks, VecLength(4));
sourcepub fn parameters(&self) -> Parameters
pub fn parameters(&self) -> Parameters
Returns the parameters used by the client key.
sourcepub fn encrypt(&self, message: u64) -> Ciphertext
pub fn encrypt(&self, message: u64) -> Ciphertext
Encrypts a integer message using the client key.
Example
use concrete_integer::client_key::ClientKey;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
let mut cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2, 4);
let msg = 12_u64;
// Encryption of one message:
let ct = cks.encrypt(msg);
// Decryption:
let dec = cks.decrypt(&ct);
assert_eq!(msg, dec);
sourcepub fn encrypt_without_padding(&self, message: u64) -> Ciphertext
pub fn encrypt_without_padding(&self, message: u64) -> Ciphertext
Encrypts a integer message using the client key.
Example
use concrete_integer::client_key::ClientKey;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
let mut cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2, 4);
let msg = 12_u64;
// Encryption of one message:
let ct = cks.encrypt_without_padding(msg);
// Decryption:
let dec = cks.decrypt_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::client_key::ClientKey;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
let mut cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2, 4);
let msg = 2_u64;
// Encryption of one message:
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(&self, ctxt: &Ciphertext) -> u64
pub fn decrypt(&self, ctxt: &Ciphertext) -> u64
Decrypts a ciphertext encrypting an integer message + carries using the client key.
Example
use concrete_integer::client_key::ClientKey;
use concrete_shortint::parameters::DEFAULT_PARAMETERS;
let cks = ClientKey::new(DEFAULT_PARAMETERS, 4);
let msg = 12_u64;
// Encryption of one message:
let ct = cks.encrypt(msg);
// Decryption:
let dec = cks.decrypt(&ct);
assert_eq!(msg, dec);
sourcepub fn decrypt_without_padding(&self, ctxt: &Ciphertext) -> u64
pub fn decrypt_without_padding(&self, ctxt: &Ciphertext) -> u64
Decrypts a ciphertext encrypting an integer message + carries using the client key.
Example
use concrete_integer::client_key::ClientKey;
use concrete_shortint::parameters::DEFAULT_PARAMETERS;
let cks = ClientKey::new(DEFAULT_PARAMETERS, 4);
let msg = 12_u64;
// Encryption of one message:
let ct = cks.encrypt(msg);
// Decryption:
let dec = cks.decrypt(&ct);
assert_eq!(msg, dec);
sourcepub fn encrypt_crt(&self, message: u64, base_vec: Vec<u64>) -> Ciphertext
pub fn encrypt_crt(&self, message: u64, base_vec: Vec<u64>) -> Ciphertext
Encrypts a small integer message using the client key.
Example
use concrete_integer::client_key::ClientKey;
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2, 3);
let msg = 13_u64;
// Encryption of one message:
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: &Ciphertext) -> u64
pub fn decrypt_crt(&self, ctxt: &Ciphertext) -> u64
Decrypts a ciphertext encrypting an integer message + carries using the client key.
Example
use concrete_integer::ciphertext::Ciphertext;
use concrete_integer::client_key::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, 3);
let msg = 27_u64;
let basis: Vec<u64> = vec![2, 3, 5];
// Encryption of one message:
let mut ct = cks.encrypt_crt(msg, basis);
// Decryption:
let dec = cks.decrypt_crt(&ct);
assert_eq!(msg, dec);
sourcepub fn encrypt_crt_not_power_of_two(
&self,
message: u64,
base_vec: Vec<u64>
) -> Ciphertext
pub fn encrypt_crt_not_power_of_two(
&self,
message: u64,
base_vec: Vec<u64>
) -> Ciphertext
Encrypts a small integer message using the client key and some moduli without padding bit.
Example
use concrete_integer::client_key::ClientKey;
use concrete_shortint::parameters::PARAM_MESSAGE_3_CARRY_3;
let cks = ClientKey::new(PARAM_MESSAGE_3_CARRY_3, 3);
let msg = 13_u64;
// Encryption of one message:
let basis: Vec<u64> = vec![2, 3, 5];
let ct = cks.encrypt_crt_not_power_of_two(msg, basis);
// Decryption:
let dec = cks.decrypt_crt_not_power_of_two(&ct);
assert_eq!(msg, dec);
sourcepub fn decrypt_crt_not_power_of_two(&self, ct: &Ciphertext) -> u64
pub fn decrypt_crt_not_power_of_two(&self, ct: &Ciphertext) -> u64
Decrypts a ciphertext encrypting an integer message with some moduli basis without padding bit.
Example
use concrete_integer::ciphertext::Ciphertext;
use concrete_integer::client_key::ClientKey;
use concrete_shortint::parameters::PARAM_MESSAGE_3_CARRY_3;
// Generate the client key and the server key:
let mut cks = ClientKey::new(PARAM_MESSAGE_3_CARRY_3, 3);
let msg = 27_u64;
let basis: Vec<u64> = vec![2, 3, 5];
// Encryption of one message:
let mut ct = cks.encrypt_crt(msg, basis);
// Decryption:
let dec = cks.decrypt_crt(&ct);
assert_eq!(msg, dec);
Trait Implementations
sourceimpl<'de> Deserialize<'de> for ClientKey
impl<'de> Deserialize<'de> for ClientKey
sourcefn 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
impl StructuralPartialEq for ClientKey
Auto Trait Implementations
impl RefUnwindSafe for ClientKey
impl Send for ClientKey
impl Sync for ClientKey
impl Unpin for ClientKey
impl UnwindSafe for ClientKey
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more