pub struct BaseRadixCiphertext<Block> { /* private fields */ }Expand description
Structure containing a ciphertext in radix decomposition holding an unsigned value.
Implementations§
Source§impl BaseRadixCiphertext<Ciphertext>
impl BaseRadixCiphertext<Ciphertext>
pub fn block_carries_are_empty(&self) -> bool
pub fn is_trivial(&self) -> bool
Sourcepub fn decrypt_trivial<Clear>(&self) -> Result<Clear, NotTrivialCiphertextError>
pub fn decrypt_trivial<Clear>(&self) -> Result<Clear, NotTrivialCiphertextError>
Decrypts a trivial ciphertext
Trivial ciphertexts are ciphertexts which are not encrypted meaning they can be decrypted by any key, or even without a key.
For debugging it can be useful to use trivial ciphertext to speed up execution, and use Self::decrypt_trivial to decrypt temporary values and debug.
§Example
use tfhe::integer::{gen_keys_radix, RadixCiphertext};
use tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128;
// 8 bits
let (cks, sks) = gen_keys_radix(PARAM_MESSAGE_2_CARRY_2_KS_PBS_GAUSSIAN_2M128, 4);
let msg = 124u8;
let msg2 = 17u8;
// Trivial encryption
let trivial_ct: RadixCiphertext = sks.create_trivial_radix(msg, 4);
let non_trivial_ct = cks.encrypt(msg2);
let res = trivial_ct.decrypt_trivial();
assert_eq!(Ok(msg), res);
let res = non_trivial_ct.decrypt_trivial::<u8>();
assert!(res.is_err());
// Doing operations that mixes trivial and non trivial
// will always return a non trivial
let ct_res = sks.add_parallelized(&trivial_ct, &non_trivial_ct);
let res = ct_res.decrypt_trivial::<u8>();
assert!(res.is_err());
// Doing operations using only trivial ciphertexts
// will return a trivial
let ct_res = sks.add_parallelized(&trivial_ct, &trivial_ct);
let res = ct_res.decrypt_trivial::<u8>();
assert_eq!(Ok(msg + msg), res);pub fn re_randomize( &mut self, re_randomization_key: ReRandomizationKey<'_>, seed: ReRandomizationSeed, ) -> Result<()>
Source§impl BaseRadixCiphertext<CompressedCiphertext>
impl BaseRadixCiphertext<CompressedCiphertext>
pub fn decompress(&self) -> RadixCiphertext
Trait Implementations§
Source§impl<Block: Clone> Clone for BaseRadixCiphertext<Block>
impl<Block: Clone> Clone for BaseRadixCiphertext<Block>
Source§fn clone(&self) -> BaseRadixCiphertext<Block>
fn clone(&self) -> BaseRadixCiphertext<Block>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<Block: Debug> Debug for BaseRadixCiphertext<Block>
impl<Block: Debug> Debug for BaseRadixCiphertext<Block>
Source§impl<'de, Block> Deserialize<'de> for BaseRadixCiphertext<Block>where
Block: Deserialize<'de>,
impl<'de, Block> Deserialize<'de> for BaseRadixCiphertext<Block>where
Block: Deserialize<'de>,
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<Block: Eq> Eq for BaseRadixCiphertext<Block>
Source§impl<Block> From<Vec<Block>> for BaseRadixCiphertext<Block>
impl<Block> From<Vec<Block>> for BaseRadixCiphertext<Block>
Source§impl<T: ParameterSetConformant<ParameterSet = CiphertextConformanceParams>> ParameterSetConformant for BaseRadixCiphertext<T>
impl<T: ParameterSetConformant<ParameterSet = CiphertextConformanceParams>> ParameterSetConformant for BaseRadixCiphertext<T>
type ParameterSet = RadixCiphertextConformanceParams
fn is_conformant(&self, params: &RadixCiphertextConformanceParams) -> bool
Source§impl<Block: PartialEq> PartialEq for BaseRadixCiphertext<Block>
impl<Block: PartialEq> PartialEq for BaseRadixCiphertext<Block>
Source§impl<Block> Serialize for BaseRadixCiphertext<Block>where
Block: Serialize,
impl<Block> Serialize for BaseRadixCiphertext<Block>where
Block: Serialize,
Source§impl<Scalar> ServerKeyDefaultCMux<&BaseRadixCiphertext<Ciphertext>, Scalar> for ServerKeywhere
Scalar: DecomposableInto<u64>,
impl<Scalar> ServerKeyDefaultCMux<&BaseRadixCiphertext<Ciphertext>, Scalar> for ServerKeywhere
Scalar: DecomposableInto<u64>,
Source§fn if_then_else_parallelized(
&self,
condition: &BooleanBlock,
true_ct: &RadixCiphertext,
false_value: Scalar,
) -> Self::Output
fn if_then_else_parallelized( &self, condition: &BooleanBlock, true_ct: &RadixCiphertext, false_value: Scalar, ) -> Self::Output
FHE “if then else” selection.
Returns a new ciphertext that encrypts the same value as either true_ct or a clear false_value depending on the value of condition:
- If condition == 1, the returned ciphertext will encrypt the same value as true_ct.
- If condition == 0, the returned ciphertext will encrypt the same value as false_value.
To ensure correct results, condition must encrypt either 0 or 1 (e.g result from a comparison).
Note that while the returned ciphertext encrypts the same value as true_ct, it won’t exactly be true_ct.
use tfhe::integer::gen_keys_radix;
use tfhe::integer::prelude::*;
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 = 126i8;
let b = -55i8;
let ct_a = cks.encrypt_signed(a);
let condition = sks.scalar_lt_parallelized(&ct_a, 66);
let ct_res = sks.if_then_else_parallelized(&condition, &ct_a, b);
// Decrypt:
let dec: i8 = cks.decrypt_signed(&ct_res);
assert_eq!(if a < 66 { a } else { b }, dec);
assert_ne!(ct_a, ct_res);type Output = BaseRadixCiphertext<Ciphertext>
fn flip_parallelized( &self, condition: &BooleanBlock, true_ct: &RadixCiphertext, false_ct: Scalar, ) -> (Self::Output, Self::Output)
fn select_parallelized( &self, condition: &BooleanBlock, ct_when_true: TrueCt, ct_when_false: FalseCt, ) -> Self::Output
fn cmux_parallelized( &self, condition: &BooleanBlock, true_ct: TrueCt, false_ct: FalseCt, ) -> Self::Output
Source§impl<Scalar> ServerKeyDefaultCMux<Scalar, &BaseRadixCiphertext<Ciphertext>> for ServerKeywhere
Scalar: DecomposableInto<u64>,
impl<Scalar> ServerKeyDefaultCMux<Scalar, &BaseRadixCiphertext<Ciphertext>> for ServerKeywhere
Scalar: DecomposableInto<u64>,
Source§fn if_then_else_parallelized(
&self,
condition: &BooleanBlock,
true_value: Scalar,
false_ct: &RadixCiphertext,
) -> Self::Output
fn if_then_else_parallelized( &self, condition: &BooleanBlock, true_value: Scalar, false_ct: &RadixCiphertext, ) -> Self::Output
FHE “if then else” selection.
Returns a new ciphertext that encrypts the same value as either true_value or a false_ct depending on the value of condition:
- If condition == 1, the returned ciphertext will encrypt the same value as true_value.
- If condition == 0, the returned ciphertext will encrypt the same value as false_ct.
To ensure correct results, condition must encrypt either 0 or 1 (e.g result from a comparison).
Note that while the returned ciphertext encrypts the same value as true_ct, it won’t exactly be true_ct.
use tfhe::integer::gen_keys_radix;
use tfhe::integer::prelude::*;
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 = 126u8;
let b = 55u8;
let ct_b = cks.encrypt(b);
let condition = sks.scalar_lt_parallelized(&ct_b, 66);
let ct_res = sks.if_then_else_parallelized(&condition, a, &ct_b);
// Decrypt:
let dec: u8 = cks.decrypt(&ct_res);
assert_eq!(if b < 66 { a } else { b }, dec);
assert_ne!(ct_b, ct_res);type Output = BaseRadixCiphertext<Ciphertext>
fn flip_parallelized( &self, condition: &BooleanBlock, true_value: Scalar, false_ct: &RadixCiphertext, ) -> (Self::Output, Self::Output)
fn select_parallelized( &self, condition: &BooleanBlock, ct_when_true: TrueCt, ct_when_false: FalseCt, ) -> Self::Output
fn cmux_parallelized( &self, condition: &BooleanBlock, true_ct: TrueCt, false_ct: FalseCt, ) -> Self::Output
impl<Block: PartialEq> StructuralPartialEq for BaseRadixCiphertext<Block>
Source§impl<Id> TryFrom<BaseRadixCiphertext<Ciphertext>> for FheUint<Id>where
Id: FheUintId,
impl<Id> TryFrom<BaseRadixCiphertext<Ciphertext>> for FheUint<Id>where
Id: FheUintId,
Source§impl<Block> Unversionize for BaseRadixCiphertext<Block>where
BaseRadixCiphertextVersions<Block>: VersionsDispatch<Self>,
impl<Block> Unversionize for BaseRadixCiphertext<Block>where
BaseRadixCiphertextVersions<Block>: VersionsDispatch<Self>,
Source§fn unversionize(
versioned: Self::VersionedOwned,
) -> Result<Self, UnversionizeError>
fn unversionize( versioned: Self::VersionedOwned, ) -> Result<Self, UnversionizeError>
Source§impl<Block> UnversionizeVec for BaseRadixCiphertext<Block>where
BaseRadixCiphertextVersions<Block>: VersionsDispatch<Self>,
impl<Block> UnversionizeVec for BaseRadixCiphertext<Block>where
BaseRadixCiphertextVersions<Block>: VersionsDispatch<Self>,
fn unversionize_vec( versioned: Self::VersionedVec, ) -> Result<Vec<Self>, UnversionizeError>
Source§impl<Block> Version for BaseRadixCiphertext<Block>
impl<Block> Version for BaseRadixCiphertext<Block>
Source§impl<Block> Versionize for BaseRadixCiphertext<Block>where
BaseRadixCiphertextVersions<Block>: VersionsDispatch<Self>,
impl<Block> Versionize for BaseRadixCiphertext<Block>where
BaseRadixCiphertextVersions<Block>: VersionsDispatch<Self>,
Source§type Versioned<'vers> = <BaseRadixCiphertextVersions<Block> as VersionsDispatch<BaseRadixCiphertext<Block>>>::Ref<'vers>
where
Block: 'vers
type Versioned<'vers> = <BaseRadixCiphertextVersions<Block> as VersionsDispatch<BaseRadixCiphertext<Block>>>::Ref<'vers> where Block: 'vers
Source§fn versionize(&self) -> Self::Versioned<'_>
fn versionize(&self) -> Self::Versioned<'_>
Source§impl<Block> VersionizeOwned for BaseRadixCiphertext<Block>where
BaseRadixCiphertextVersions<Block>: VersionsDispatch<Self>,
impl<Block> VersionizeOwned for BaseRadixCiphertext<Block>where
BaseRadixCiphertextVersions<Block>: VersionsDispatch<Self>,
type VersionedOwned = <BaseRadixCiphertextVersions<Block> as VersionsDispatch<BaseRadixCiphertext<Block>>>::Owned
Source§fn versionize_owned(self) -> Self::VersionedOwned
fn versionize_owned(self) -> Self::VersionedOwned
Source§impl<Block> VersionizeSlice for BaseRadixCiphertext<Block>where
BaseRadixCiphertextVersions<Block>: VersionsDispatch<Self>,
impl<Block> VersionizeSlice for BaseRadixCiphertext<Block>where
BaseRadixCiphertextVersions<Block>: VersionsDispatch<Self>,
type VersionedSlice<'vers> = Vec<<BaseRadixCiphertext<Block> as Versionize>::Versioned<'vers>> where Block: 'vers
fn versionize_slice(slice: &[Self]) -> Self::VersionedSlice<'_>
Source§impl<Block> VersionizeVec for BaseRadixCiphertext<Block>where
BaseRadixCiphertextVersions<Block>: VersionsDispatch<Self>,
impl<Block> VersionizeVec for BaseRadixCiphertext<Block>where
BaseRadixCiphertextVersions<Block>: VersionsDispatch<Self>,
type VersionedVec = Vec<<BaseRadixCiphertext<Block> as VersionizeOwned>::VersionedOwned>
fn versionize_vec(vec: Vec<Self>) -> Self::VersionedVec
Source§impl<Block> VersionsDispatch<BaseRadixCiphertext<Block>> for BaseRadixCiphertextVersions<Block>where
BaseRadixCiphertext<Block>: Version,
impl<Block> VersionsDispatch<BaseRadixCiphertext<Block>> for BaseRadixCiphertextVersions<Block>where
BaseRadixCiphertext<Block>: Version,
Auto Trait Implementations§
impl<Block> Freeze for BaseRadixCiphertext<Block>
impl<Block> RefUnwindSafe for BaseRadixCiphertext<Block>where
Block: RefUnwindSafe,
impl<Block> Send for BaseRadixCiphertext<Block>where
Block: Send,
impl<Block> Sync for BaseRadixCiphertext<Block>where
Block: Sync,
impl<Block> Unpin for BaseRadixCiphertext<Block>where
Block: Unpin,
impl<Block> UnsafeUnpin for BaseRadixCiphertext<Block>
impl<Block> UnwindSafe for BaseRadixCiphertext<Block>where
Block: UnwindSafe,
Blanket Implementations§
impl<T> Annotation for T
Source§impl<T> AsShortintCiphertextSlice for Twhere
T: IntegerCiphertext,
impl<T> AsShortintCiphertextSlice for Twhere
T: IntegerCiphertext,
fn as_ciphertext_slice(&self) -> &[Ciphertext]
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Expandable for Twhere
T: IntegerRadixCiphertext,
impl<T> Expandable for Twhere
T: IntegerRadixCiphertext,
fn from_expanded_blocks( blocks: Vec<Ciphertext>, kind: DataKind, ) -> Result<T, Error>
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