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<P>(parameter_set: P) -> Self
pub fn new<P>(parameter_set: P) -> Self
Creates a Client Key.
§Example
use tfhe::integer::ClientKey;
use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128;
// 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_KS_PBS_GAUSSIAN_2M128);Sourcepub fn into_raw_parts(self) -> ShortintClientKey
pub fn into_raw_parts(self) -> ShortintClientKey
Deconstruct a ClientKey into its constituents.
§Example
use tfhe::integer::ClientKey;
use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128;
// 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_KS_PBS_GAUSSIAN_2M128);
let key = cks.into_raw_parts();Sourcepub fn from_raw_parts(key: ShortintClientKey) -> Self
pub fn from_raw_parts(key: ShortintClientKey) -> Self
Construct a ClientKey from its constituents.
§Example
use tfhe::integer::ClientKey;
use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128;
// 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_KS_PBS_GAUSSIAN_2M128);
let key = cks.into_raw_parts();
let cks = ClientKey::from_raw_parts(key);pub fn parameters(&self) -> AtomicPatternParameters
Sourcepub fn encrypt_radix<T>(&self, message: T, num_blocks: usize) -> RadixCiphertext
pub fn encrypt_radix<T>(&self, message: T, num_blocks: usize) -> RadixCiphertext
Encrypts an integer in radix decomposition
§Example
use tfhe::integer::ClientKey;
use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128;
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128);
let num_block = 4;
let msg = 167_u64;
// 2 * 4 = 8 bits of message
let ct = cks.encrypt_radix(msg, num_block);
let dec = cks.decrypt_radix(&ct);
assert_eq!(msg, dec);Sourcepub fn encrypt_radix_without_padding<T: DecomposableInto<u64> + UnsignedNumeric>(
&self,
message: T,
num_blocks: usize,
) -> RadixCiphertext
pub fn encrypt_radix_without_padding<T: DecomposableInto<u64> + UnsignedNumeric>( &self, message: T, num_blocks: usize, ) -> RadixCiphertext
Encrypts an integer in radix decomposition without padding bit
§Example
use tfhe::integer::ClientKey;
use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128;
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128);
let num_block = 4;
let msg = 167_u64;
// 2 * 4 = 8 bits of message
let ct = cks.encrypt_radix_without_padding(msg, num_block);
let dec = cks.decrypt_radix_without_padding(&ct);
assert_eq!(msg, dec);pub fn encrypt_radix_compressed<T: DecomposableInto<u64> + UnsignedNumeric>( &self, message: T, num_blocks: usize, ) -> CompressedRadixCiphertext
pub fn encrypt_radix_without_padding_compressed<T: DecomposableInto<u64> + UnsignedNumeric>( &self, message: T, num_blocks: usize, ) -> CompressedRadixCiphertext
Sourcepub fn encrypt_words_radix<Block, RadixCiphertextType, T, F>(
&self,
message_words: T,
num_blocks: usize,
encrypt_block: F,
) -> RadixCiphertextTypewhere
T: DecomposableInto<u64> + UnsignedNumeric,
F: Fn(&ClientKey, u64) -> Block,
RadixCiphertextType: From<Vec<Block>>,
pub fn encrypt_words_radix<Block, RadixCiphertextType, T, F>(
&self,
message_words: T,
num_blocks: usize,
encrypt_block: F,
) -> RadixCiphertextTypewhere
T: DecomposableInto<u64> + UnsignedNumeric,
F: Fn(&ClientKey, u64) -> Block,
RadixCiphertextType: From<Vec<Block>>,
Encrypts 64-bits words into a ciphertext in radix decomposition
The words are assumed to be in little endian order.
If there are not enough words for the requested num_block, encryptions of zeros will be appended.
Sourcepub fn decrypt_radix<T>(&self, ctxt: &RadixCiphertext) -> T
pub fn decrypt_radix<T>(&self, ctxt: &RadixCiphertext) -> T
Decrypts a ciphertext encrypting an radix integer
§Example
use tfhe::integer::ClientKey;
use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128;
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128);
let num_block = 4;
let msg = 191_u64;
let ct = cks.encrypt_radix(msg, num_block);
let dec = cks.decrypt_radix(&ct);
assert_eq!(msg, dec);Sourcepub fn decrypt_radix_without_padding<T>(&self, ctxt: &RadixCiphertext) -> T
pub fn decrypt_radix_without_padding<T>(&self, ctxt: &RadixCiphertext) -> T
Decrypts a ciphertext encrypting an radix integer encrypted without padding
§Example
use tfhe::integer::ClientKey;
use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128;
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128);
let num_block = 4;
let msg = 191_u64;
let ct = cks.encrypt_radix_without_padding(msg, num_block);
let dec = cks.decrypt_radix_without_padding(&ct);
assert_eq!(msg, dec);pub fn encrypt_signed_radix<T>( &self, message: T, num_blocks: usize, ) -> SignedRadixCiphertext
pub fn encrypt_signed_radix_without_padding<T>( &self, message: T, num_blocks: usize, ) -> SignedRadixCiphertext
pub fn encrypt_signed_radix_compressed<T: DecomposableInto<u64> + SignedNumeric>( &self, message: T, num_blocks: usize, ) -> CompressedSignedRadixCiphertext
pub fn encrypt_signed_radix_without_padding_compressed<T: DecomposableInto<u64> + SignedNumeric>( &self, message: T, num_blocks: usize, ) -> CompressedSignedRadixCiphertext
pub fn decrypt_signed_radix<T>(&self, ctxt: &SignedRadixCiphertext) -> Twhere
T: RecomposableSignedInteger,
pub fn decrypt_signed_radix_impl<T, F>( &self, ctxt: &SignedRadixCiphertext, decrypt_block: F, ) -> T
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 tfhe::integer::ClientKey;
use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128;
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128);
let msg = 2_u64;
let ct = cks.encrypt_one_block(msg);
let dec = cks.decrypt_one_block(&ct);
assert_eq!(msg, dec);Sourcepub fn encrypt_bool(&self, msg: bool) -> BooleanBlock
pub fn encrypt_bool(&self, msg: bool) -> BooleanBlock
Encrypts a bool to a BooleanBlock
§Example
use tfhe::integer::gen_keys_radix;
use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128;
// We have 4 * 2 = 8 bits of message
let size = 4;
let (cks, sks) = gen_keys_radix(PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128, size);
let a = cks.encrypt_bool(false);
let dec = cks.decrypt_bool(&a);
assert!(!dec);
let a = a.into_radix(size, &sks);
let dec: u64 = cks.decrypt(&a);
assert_eq!(dec, 0);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_bool(&self, ct: &BooleanBlock) -> bool
pub fn decrypt_bool(&self, ct: &BooleanBlock) -> bool
Decrypts a ciphertext marked as holding a boolean value to a bool
Treats 0 as false and the rest as true
§Example
use tfhe::integer::{BooleanBlock, ClientKey};
use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128;
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128);
let a = cks.encrypt_one_block(1u64);
let wrapped = BooleanBlock::new_unchecked(a);
let dec = cks.decrypt_bool(&wrapped);
assert!(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 tfhe::integer::ClientKey;
use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128;
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128);
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);pub fn encrypt_crt_compressed( &self, message: u64, base_vec: Vec<u64>, ) -> CompressedCrtCiphertext
Sourcepub fn decrypt_crt(&self, ctxt: &CrtCiphertext) -> u64
pub fn decrypt_crt(&self, ctxt: &CrtCiphertext) -> u64
Decrypts an integer in crt decomposition
§Example
use tfhe::integer::ClientKey;
use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128;
// Generate the client key and the server key:
let cks = ClientKey::new(PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128);
let msg = 27_u64;
let basis: Vec<u64> = vec![2, 3, 5];
// Encryption:
let 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 tfhe::integer::ClientKey;
use tfhe::shortint::parameters::PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128;
let cks = ClientKey::new(PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128);
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);pub fn encrypt_native_crt_compressed( &self, message: u64, base_vec: Vec<u64>, ) -> CompressedCrtCiphertext
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 tfhe::integer::ClientKey;
use tfhe::shortint::parameters::PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128;
let cks = ClientKey::new(PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M128);
let msg = 27_u64;
let basis: Vec<u64> = vec![2, 3, 5];
// Encryption of one message:
let ct = cks.encrypt_native_crt(msg, basis);
// Decryption:
let dec = cks.decrypt_native_crt(&ct);
assert_eq!(msg, dec);pub fn new_compression_private_key( &self, params: CompressionParameters, ) -> CompressionPrivateKeys
pub fn new_compression_decompression_keys( &self, private_compression_key: &CompressionPrivateKeys, ) -> (CompressionKey, DecompressionKey)
Source§impl ClientKey
impl ClientKey
pub fn new_compressed_compression_decompression_keys( &self, private_compression_key: &CompressionPrivateKeys, ) -> (CompressedCompressionKey, CompressedDecompressionKey)
Source§impl ClientKey
impl ClientKey
pub fn new_compressed_noise_squashing_key( &self, noise_squashing_private_key: &NoiseSquashingPrivateKey, ) -> CompressedNoiseSquashingKey
pub fn new_noise_squashing_key( &self, noise_squashing_private_key: &NoiseSquashingPrivateKey, ) -> NoiseSquashingKey
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 AsRef<GenericClientKey<AtomicPatternClientKey>> for ClientKey
impl AsRef<GenericClientKey<AtomicPatternClientKey>> for ClientKey
Source§fn as_ref(&self) -> &ShortintClientKey
fn as_ref(&self) -> &ShortintClientKey
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>,
Source§impl From<GenericClientKey<AtomicPatternClientKey>> for ClientKey
impl From<GenericClientKey<AtomicPatternClientKey>> for ClientKey
Source§fn from(key: ShortintClientKey) -> Self
fn from(key: ShortintClientKey) -> Self
Source§impl From<RadixClientKey> for ClientKey
impl From<RadixClientKey> for ClientKey
Source§fn from(ck: RadixClientKey) -> Self
fn from(ck: RadixClientKey) -> Self
impl StructuralPartialEq for ClientKey
Source§impl Unversionize for ClientKeywhere
ClientKeyVersions: VersionsDispatch<Self>,
impl Unversionize for ClientKeywhere
ClientKeyVersions: VersionsDispatch<Self>,
Source§fn unversionize(
versioned: Self::VersionedOwned,
) -> Result<Self, UnversionizeError>
fn unversionize( versioned: Self::VersionedOwned, ) -> Result<Self, UnversionizeError>
Source§impl UnversionizeVec for ClientKeywhere
ClientKeyVersions: VersionsDispatch<Self>,
impl UnversionizeVec for ClientKeywhere
ClientKeyVersions: VersionsDispatch<Self>,
fn unversionize_vec( versioned: Self::VersionedVec, ) -> Result<Vec<Self>, UnversionizeError>
Source§impl Versionize for ClientKeywhere
ClientKeyVersions: VersionsDispatch<Self>,
impl Versionize for ClientKeywhere
ClientKeyVersions: VersionsDispatch<Self>,
Source§type Versioned<'vers> = <ClientKeyVersions as VersionsDispatch<ClientKey>>::Ref<'vers>
type Versioned<'vers> = <ClientKeyVersions as VersionsDispatch<ClientKey>>::Ref<'vers>
Source§fn versionize(&self) -> Self::Versioned<'_>
fn versionize(&self) -> Self::Versioned<'_>
Source§impl VersionizeOwned for ClientKeywhere
ClientKeyVersions: VersionsDispatch<Self>,
impl VersionizeOwned for ClientKeywhere
ClientKeyVersions: VersionsDispatch<Self>,
type VersionedOwned = <ClientKeyVersions as VersionsDispatch<ClientKey>>::Owned
Source§fn versionize_owned(self) -> Self::VersionedOwned
fn versionize_owned(self) -> Self::VersionedOwned
Source§impl VersionizeSlice for ClientKeywhere
ClientKeyVersions: VersionsDispatch<Self>,
impl VersionizeSlice for ClientKeywhere
ClientKeyVersions: VersionsDispatch<Self>,
type VersionedSlice<'vers> = Vec<<ClientKey as Versionize>::Versioned<'vers>>
fn versionize_slice(slice: &[Self]) -> Self::VersionedSlice<'_>
Source§impl VersionizeVec for ClientKeywhere
ClientKeyVersions: VersionsDispatch<Self>,
impl VersionizeVec for ClientKeywhere
ClientKeyVersions: VersionsDispatch<Self>,
type VersionedVec = Vec<<ClientKey as VersionizeOwned>::VersionedOwned>
fn versionize_vec(vec: Vec<Self>) -> Self::VersionedVec
Auto Trait Implementations§
impl Freeze for ClientKey
impl RefUnwindSafe for ClientKey
impl Send for ClientKey
impl Sync for ClientKey
impl Unpin for ClientKey
impl UnsafeUnpin for ClientKey
impl UnwindSafe for ClientKey
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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