Struct concrete_shortint::client_key::ClientKey
source · pub struct ClientKey {
pub parameters: Parameters,
/* private fields */
}
Expand description
A structure containing the client key, which must be kept secret.
In more details, it contains:
lwe_secret_key
- an LWE secret key, used to encrypt the inputs and decrypt the outputs. This secret key is also used in the generation of bootstrapping and key switching keys.glwe_secret_key
- a GLWE secret key, used to generate the bootstrapping keys and key switching keys.parameters
- the cryptographic parameter set.
Fields
parameters: Parameters
Implementations
sourceimpl ClientKey
impl ClientKey
sourcepub fn new(parameters: Parameters) -> ClientKey
pub fn new(parameters: Parameters) -> ClientKey
Generates a client key.
Example
use concrete_shortint::client_key::ClientKey;
use concrete_shortint::parameters::Parameters;
// Generate the client key:
let cks = ClientKey::new(Parameters::default());
sourcepub fn encrypt(&self, message: u64) -> Ciphertext
pub fn encrypt(&self, message: u64) -> Ciphertext
Encrypts a small integer message using the client key.
The input message is reduced to the encrypted message space modulus
Example
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
use concrete_shortint::ClientKey;
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
// Encryption of one message that is within the encrypted message modulus:
let msg = 3;
let ct = cks.encrypt(msg);
let dec = cks.decrypt(&ct);
assert_eq!(msg, dec);
// Encryption of one message that is outside the encrypted message modulus:
let msg = 5;
let ct = cks.encrypt(msg);
let dec = cks.decrypt(&ct);
let modulus = cks.parameters.message_modulus.0 as u64;
assert_eq!(msg % modulus, dec);
sourcepub fn encrypt_with_message_modulus(
&self,
message: u64,
message_modulus: MessageModulus
) -> Ciphertext
pub fn encrypt_with_message_modulus(
&self,
message: u64,
message_modulus: MessageModulus
) -> Ciphertext
Encrypts a small integer message using the client key with a specific message modulus
Example
use concrete_shortint::parameters::MessageModulus;
use concrete_shortint::{ClientKey, Parameters};
// Generate the client key
let cks = ClientKey::new(Parameters::default());
let msg = 3;
// Encryption of one message:
let ct = cks.encrypt_with_message_modulus(msg, MessageModulus(6));
// Decryption:
let dec = cks.decrypt(&ct);
assert_eq!(msg, dec);
sourcepub fn unchecked_encrypt(&self, message: u64) -> Ciphertext
pub fn unchecked_encrypt(&self, message: u64) -> Ciphertext
Encrypts an integer without reducing the input message modulus the message space
Example
use concrete_shortint::{ClientKey, Parameters};
// Generate the client key
let cks = ClientKey::new(Parameters::default());
let msg = 7;
let ct = cks.unchecked_encrypt(msg);
// | ct |
// | carry | message |
// |-------|---------|
// | 0 1 | 1 1 |
let dec = cks.decrypt_message_and_carry(&ct);
assert_eq!(msg, dec);
sourcepub fn decrypt_message_and_carry(&self, ct: &Ciphertext) -> u64
pub fn decrypt_message_and_carry(&self, ct: &Ciphertext) -> u64
Decrypts a ciphertext encrypting an integer message and carries using the client key.
Example
use concrete_shortint::{ClientKey, Parameters};
// Generate the client key
let cks = ClientKey::new(Parameters::default());
let msg = 3;
// Encryption of one message:
let ct = cks.encrypt(msg);
// Decryption:
let dec = cks.decrypt_message_and_carry(&ct);
assert_eq!(msg, dec);
sourcepub fn decrypt(&self, ct: &Ciphertext) -> u64
pub fn decrypt(&self, ct: &Ciphertext) -> u64
Decrypts a ciphertext encrypting a message using the client key.
Example
use concrete_shortint::{ClientKey, Parameters};
// Generate the client key
let cks = ClientKey::new(Parameters::default());
let msg = 3;
// 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 small integer message using the client key without padding bit.
The input message is reduced to the encrypted message space modulus
Example
use concrete_shortint::parameters::PARAM_MESSAGE_2_CARRY_2;
use concrete_shortint::ClientKey;
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2);
// Encryption of one message that is within the encrypted message modulus:
let msg = 6;
let ct = cks.encrypt_without_padding(msg);
let dec = cks.decrypt_message_and_carry_without_padding(&ct);
assert_eq!(msg, dec);
sourcepub fn decrypt_message_and_carry_without_padding(&self, ct: &Ciphertext) -> u64
pub fn decrypt_message_and_carry_without_padding(&self, ct: &Ciphertext) -> u64
Decrypts a ciphertext encrypting an integer message and carries using the client key, where the ciphertext is assumed to not have any padding bit.
Example
use concrete_shortint::parameters::PARAM_MESSAGE_1_CARRY_1;
use concrete_shortint::ClientKey;
// Generate the client key
let cks = ClientKey::new(PARAM_MESSAGE_1_CARRY_1);
let msg = 3;
// Encryption of one message:
let ct = cks.encrypt_without_padding(msg);
// Decryption:
let dec = cks.decrypt_message_and_carry_without_padding(&ct);
assert_eq!(msg, dec);
sourcepub fn decrypt_without_padding(&self, ct: &Ciphertext) -> u64
pub fn decrypt_without_padding(&self, ct: &Ciphertext) -> u64
Decrypts a ciphertext encrypting an integer message using the client key, where the ciphertext is assumed to not have any padding bit.
Example
use concrete_shortint::{ClientKey, Parameters};
// Generate the client key
let cks = ClientKey::new(Parameters::default());
let msg = 7;
let modulus = 4;
// Encryption of one message:
let ct = cks.encrypt_without_padding(msg);
// Decryption:
let dec = cks.decrypt_without_padding(&ct);
assert_eq!(msg % modulus, dec);
sourcepub fn encrypt_native_crt(&self, message: u64, message_modulus: u8) -> Ciphertext
pub fn encrypt_native_crt(&self, message: u64, message_modulus: u8) -> Ciphertext
Encrypts a small integer message using the client key without padding bit with some modulus.
The input message is reduced to the encrypted message space modulus
Example
use concrete_shortint::{ClientKey, Parameters};
// Generate the client key
let cks = ClientKey::new(Parameters::default());
let msg = 2;
let modulus = 3;
// Encryption of one message:
let ct = cks.encrypt_native_crt(msg, modulus);
// Decryption:
let dec = cks.decrypt_message_native_crt(&ct, modulus);
assert_eq!(msg, dec % modulus as u64);
sourcepub fn decrypt_message_native_crt(
&self,
ct: &Ciphertext,
message_modulus: u8
) -> u64
pub fn decrypt_message_native_crt(
&self,
ct: &Ciphertext,
message_modulus: u8
) -> u64
Decrypts a ciphertext encrypting an integer message using the client key, where the ciphertext is assumed to not have any padding bit and is related to some modulus.
Example
use concrete_shortint::{ClientKey, Parameters};
// Generate the client key
let cks = ClientKey::new(Parameters::default());
let msg = 1;
let modulus = 3;
// Encryption of one message:
let ct = cks.encrypt_native_crt(msg, modulus);
// Decryption:
let dec = cks.decrypt_message_native_crt(&ct, modulus);
assert_eq!(msg, dec % modulus as u64);