Struct concrete_core::crypto::lwe::LweCiphertext[][src]

pub struct LweCiphertext<Cont> { /* fields omitted */ }

A ciphertext encrypted using the LWE scheme.

Implementations

impl<Scalar> LweCiphertext<Vec<Scalar>> where
    Scalar: Copy
[src]

pub fn allocate(value: Scalar, size: LweSize) -> Self[src]

Allocates a new ciphertext.

Example

use concrete_core::crypto::{*, lwe::LweCiphertext};
let ct = LweCiphertext::allocate(0 as u8, LweSize(4));
assert_eq!(ct.lwe_size(), LweSize(4));
assert_eq!(ct.get_mask().mask_size(), LweDimension(3));

impl<Cont> LweCiphertext<Cont>[src]

pub fn from_container(cont: Cont) -> LweCiphertext<Cont>[src]

Creates a ciphertext from a container of values.

Example

use concrete_core::crypto::{*, lwe::LweCiphertext};
let vector = vec![0 as u8; 10];
let ct = LweCiphertext::from_container(vector.as_slice());
assert_eq!(ct.lwe_size(), LweSize(10));
assert_eq!(ct.get_mask().mask_size(), LweDimension(9));

pub fn lwe_size(&self) -> LweSize where
    Self: AsRefTensor
[src]

Returns the size of the cipher, e.g. the size of the mask + 1 for the body.

Example

use concrete_core::crypto::{*, lwe::LweCiphertext};
let ct = LweCiphertext::allocate(0 as u8, LweSize(4));
assert_eq!(ct.lwe_size(), LweSize(4));

pub fn get_body<Scalar>(&self) -> &LweBody<Scalar> where
    Self: AsRefTensor<Element = Scalar>, 
[src]

Returns the body of the ciphertext.

Example

use concrete_core::crypto::{*, lwe::*};
let ciphertext = LweCiphertext::from_container(vec![0 as u8; 10]);
let body = ciphertext.get_body();
assert_eq!(body, &LweBody(0 as u8));

pub fn get_mask<Scalar>(&self) -> LweMask<&[Scalar]> where
    Self: AsRefTensor<Element = Scalar>, 
[src]

Returns the mask of the ciphertext.

Example

use concrete_core::crypto::{*, lwe::*};
let ciphertext = LweCiphertext::from_container(vec![0 as u8; 10]);
let mask = ciphertext.get_mask();
assert_eq!(mask.mask_size(), LweDimension(9));

pub fn get_body_and_mask<Scalar>(
    &self
) -> (&LweBody<Scalar>, LweMask<&[Scalar]>) where
    Self: AsRefTensor<Element = Scalar>, 
[src]

Returns the body and the mask of the ciphertext.

Example

use concrete_core::crypto::{*, lwe::*};
let ciphertext = LweCiphertext::from_container(vec![0 as u8; 10]);
let (body, mask) = ciphertext.get_body_and_mask();
assert_eq!(body, &LweBody(0));
assert_eq!(mask.mask_size(), LweDimension(9));

pub fn get_mut_body<Scalar>(&mut self) -> &mut LweBody<Scalar> where
    Self: AsMutTensor<Element = Scalar>, 
[src]

Returns the mutable body of the ciphertext.

Example

use concrete_core::crypto::{*, lwe::*};
let mut ciphertext = LweCiphertext::from_container(vec![0 as u8; 10]);
let mut body = ciphertext.get_mut_body();
*body = LweBody(8);
let body = ciphertext.get_body();
assert_eq!(body, &LweBody(8 as u8));

pub fn get_mut_mask<Scalar>(&mut self) -> LweMask<&mut [Scalar]> where
    Self: AsMutTensor<Element = Scalar>, 
[src]

Returns the mutable mask of the ciphertext.

Example

use concrete_core::crypto::{*, lwe::*};
let mut ciphertext = LweCiphertext::from_container(vec![0 as u8; 10]);
let mut mask = ciphertext.get_mut_mask();
for mut elt in mask.mask_element_iter_mut() {
    *elt = 8;
}
let mask = ciphertext.get_mask();
for elt in mask.mask_element_iter(){
    assert_eq!(*elt,8);
}
assert_eq!(mask.mask_element_iter().count(), 9);

pub fn get_mut_body_and_mask<Scalar>(
    &mut self
) -> (&mut LweBody<Scalar>, LweMask<&mut [Scalar]>) where
    Self: AsMutTensor<Element = Scalar>, 
[src]

Returns the mutable body and mask of the ciphertext.

Example

use concrete_core::crypto::{*, lwe::*};
let mut ciphertext = LweCiphertext::from_container(vec![0 as u8; 10]);
let (body, mask) = ciphertext.get_mut_body_and_mask();
assert_eq!(body, &mut LweBody(0));
assert_eq!(mask.mask_size(), LweDimension(9));

pub fn fill_with_scalar_mul<Scalar, InputCont>(
    &mut self,
    input: &LweCiphertext<InputCont>,
    scalar: &Cleartext<Scalar>
) where
    Self: AsMutTensor<Element = Scalar>,
    LweCiphertext<InputCont>: AsRefTensor<Element = Scalar>,
    Scalar: UnsignedInteger
[src]

Fills the ciphertext with the result of the multiplication of the input ciphertext by the scalar cleartext.

Example

use concrete_core::crypto::{*, secret::LweSecretKey, lwe::*, encoding::*};
use concrete_core::math::dispersion::LogStandardDev;

let secret_key = LweSecretKey::generate(LweDimension(256));
let noise = LogStandardDev::from_log_standard_dev(-15.);
let encoder = RealEncoder{offset: 0. as f32, delta: 10.};

let cleartext = Cleartext(2. as f32);
let plaintext: Plaintext<u32> = encoder.encode(cleartext);
let mut ciphertext = LweCiphertext::from_container(vec![0. as u32;257]);
secret_key.encrypt_lwe(&mut ciphertext, &plaintext, noise);

let mut processed = LweCiphertext::from_container(vec![0 as u32; 257]);
processed.fill_with_scalar_mul(&ciphertext, &Cleartext(4));

let mut decrypted = Plaintext(0 as u32);
secret_key.decrypt_lwe(&mut decrypted, &processed);
let decoded = encoder.decode(decrypted);
assert!((decoded.0-(cleartext.0 * 4.)).abs() < 0.2);

pub fn fill_with_multisum_with_bias<Scalar, InputCont, WeightCont>(
    &mut self,
    input_list: &LweList<InputCont>,
    weights: &CleartextList<WeightCont>,
    bias: &Plaintext<Scalar>
) where
    Self: AsMutTensor<Element = Scalar>,
    LweList<InputCont>: AsRefTensor<Element = Scalar>,
    CleartextList<WeightCont>: AsRefTensor<Element = Scalar>,
    Scalar: UnsignedInteger
[src]

Fills the ciphertext with the result of the multisum of the input_list with the weights values, and adds a bias.

Said differently, this function fills self with: $$ bias + \sum_i input_list[i] * weights[i] $$

Example

use concrete_core::crypto::{*, secret::LweSecretKey, lwe::*, encoding::*};
use concrete_core::math::dispersion::LogStandardDev;

let secret_key = LweSecretKey::generate(LweDimension(4));
let noise = LogStandardDev::from_log_standard_dev(-15.);
let encoder = RealEncoder{offset: 0. as f32, delta: 100.};

let clear_values = CleartextList::from_container(vec![1. as f32, 2., 3.]);
let mut plain_values = PlaintextList::from_container(vec![0 as u32; 3]);
encoder.encode_list(&mut plain_values, &clear_values);
let mut ciphertext_values = LweList::from_container(
    vec![0. as u32; 5*3],
    LweSize(5)
);
secret_key.encrypt_lwe_list(&mut ciphertext_values, &plain_values, noise);

let mut output = LweCiphertext::from_container(vec![0. as u32; 5]);
let weights = CleartextList::from_container(vec![7, 8, 9]);
let bias = encoder.encode(Cleartext(13.));

output.fill_with_multisum_with_bias(&ciphertext_values, &weights, &bias);

let mut decrypted = Plaintext(0 as u32);
secret_key.decrypt_lwe(&mut decrypted, &output);
let decoded = encoder.decode(decrypted);
assert!((decoded.0-63.).abs() < 0.1);

pub fn update_with_add<OtherCont, Scalar>(
    &mut self,
    other: &LweCiphertext<OtherCont>
) where
    Self: AsMutTensor<Element = Scalar>,
    LweCiphertext<OtherCont>: AsRefTensor<Element = Scalar>,
    Scalar: UnsignedTorus
[src]

Adds the other ciphertext to the current one.

Example

use concrete_core::crypto::{*, secret::LweSecretKey, lwe::*, encoding::*};
use concrete_core::math::dispersion::LogStandardDev;

let secret_key = LweSecretKey::generate(LweDimension(256));
let noise = LogStandardDev::from_log_standard_dev(-15.);
let encoder = RealEncoder{offset: 0. as f32, delta: 10.};

let clear_1 = Cleartext(2. as f32);
let plain_1: Plaintext<u32> = encoder.encode(clear_1);
let mut cipher_1 = LweCiphertext::from_container(vec![0. as u32;257]);
secret_key.encrypt_lwe(&mut cipher_1, &plain_1, noise);

let clear_2 = Cleartext(3. as f32);
let plain_2: Plaintext<u32> = encoder.encode(clear_2);
let mut cipher_2 = LweCiphertext::from_container(vec![0. as u32;257]);
secret_key.encrypt_lwe(&mut cipher_2, &plain_2, noise);

cipher_1.update_with_add(&cipher_2);

let mut decrypted = Plaintext(0 as u32);
secret_key.decrypt_lwe(&mut decrypted, &cipher_1);
let decoded = encoder.decode(decrypted);

assert!((decoded.0-5.).abs() < 0.1);

pub fn update_with_sub<OtherCont, Scalar>(
    &mut self,
    other: &LweCiphertext<OtherCont>
) where
    Self: AsMutTensor<Element = Scalar>,
    LweCiphertext<OtherCont>: AsRefTensor<Element = Scalar>,
    Scalar: UnsignedTorus
[src]

Subtracts the other ciphertext from the current one.

Example

use concrete_core::crypto::{*, secret::LweSecretKey, lwe::*, encoding::*};
use concrete_core::math::dispersion::LogStandardDev;

let secret_key = LweSecretKey::generate(LweDimension(256));
let noise = LogStandardDev::from_log_standard_dev(-15.);
let encoder = RealEncoder{offset: 0. as f32, delta: 10.};

let clear_1 = Cleartext(3. as f32);
let plain_1: Plaintext<u32> = encoder.encode(clear_1);
let mut cipher_1 = LweCiphertext::from_container(vec![0. as u32;257]);
secret_key.encrypt_lwe(&mut cipher_1, &plain_1, noise);

let clear_2 = Cleartext(2. as f32);
let plain_2: Plaintext<u32> = encoder.encode(clear_2);
let mut cipher_2 = LweCiphertext::from_container(vec![0. as u32;257]);
secret_key.encrypt_lwe(&mut cipher_2, &plain_2, noise);

cipher_1.update_with_sub(&cipher_2);

let mut decrypted = Plaintext(0 as u32);
secret_key.decrypt_lwe(&mut decrypted, &cipher_1);
let decoded = encoder.decode(decrypted);

assert!((decoded.0-1.).abs() < 0.1);

pub fn update_with_neg<Scalar>(&mut self) where
    Self: AsMutTensor<Element = Scalar>,
    Scalar: UnsignedTorus
[src]

Negates the ciphertext.

Example

use concrete_core::crypto::{*, secret::LweSecretKey, lwe::*, encoding::*};
use concrete_core::math::dispersion::LogStandardDev;

let secret_key = LweSecretKey::generate(LweDimension(256));
let noise = LogStandardDev::from_log_standard_dev(-15.);
let encoder = RealEncoder{offset: -5. as f32, delta: 10.};

let clear = Cleartext(2. as f32);
let plain: Plaintext<u32> = encoder.encode(clear);
let mut cipher = LweCiphertext::from_container(vec![0. as u32;257]);
secret_key.encrypt_lwe( &mut cipher, &plain, noise);

cipher.update_with_neg();

let mut decrypted = Plaintext(0 as u32);
secret_key.decrypt_lwe(&mut decrypted, &cipher);
let decoded = encoder.decode(decrypted);

assert!((decoded.0-(-2.)).abs() < 0.1);

pub fn update_with_scalar_mul<Scalar>(&mut self, scalar: Cleartext<Scalar>) where
    Self: AsMutTensor<Element = Scalar>,
    Scalar: UnsignedTorus
[src]

Multiplies the current ciphertext with a scalar value inplace.

Example

use concrete_core::crypto::{*, secret::LweSecretKey, lwe::*, encoding::*};
use concrete_core::math::dispersion::LogStandardDev;

let secret_key = LweSecretKey::generate(LweDimension(256));
let noise = LogStandardDev::from_log_standard_dev(-15.);
let encoder = RealEncoder{offset: 0. as f32, delta: 10.};

let clear = Cleartext(2. as f32);
let plain: Plaintext<u32> = encoder.encode(clear);
let mut cipher = LweCiphertext::from_container(vec![0. as u32;257]);
secret_key.encrypt_lwe(&mut cipher, &plain, noise);

cipher.update_with_scalar_mul(Cleartext(3));

let mut decrypted = Plaintext(0 as u32);
secret_key.decrypt_lwe(&mut decrypted, &cipher);
let decoded = encoder.decode(decrypted);

assert!((decoded.0-6.).abs() < 0.2);

Trait Implementations

impl<Element> AsMutTensor for LweCiphertext<Vec<Element>>[src]

type Element = Element

The element type.

type Container = Vec<Element>

The container used by the tensor.

impl<Element> AsMutTensor for LweCiphertext<[Element; 1]>[src]

type Element = Element

The element type.

type Container = [Element; 1]

The container used by the tensor.

impl<Element> AsMutTensor for LweCiphertext<AlignedVec<Element>>[src]

type Element = Element

The element type.

type Container = AlignedVec<Element>

The container used by the tensor.

impl<'a, Element> AsMutTensor for LweCiphertext<&'a mut [Element]>[src]

type Element = Element

The element type.

type Container = &'a mut [Element]

The container used by the tensor.

impl<Element> AsRefTensor for LweCiphertext<Vec<Element>>[src]

type Element = Element

The element type.

type Container = Vec<Element>

The container used by the tensor.

impl<Element> AsRefTensor for LweCiphertext<AlignedVec<Element>>[src]

type Element = Element

The element type.

type Container = AlignedVec<Element>

The container used by the tensor.

impl<Element> AsRefTensor for LweCiphertext<[Element; 1]>[src]

type Element = Element

The element type.

type Container = [Element; 1]

The container used by the tensor.

impl<'a, Element> AsRefTensor for LweCiphertext<&'a [Element]>[src]

type Element = Element

The element type.

type Container = &'a [Element]

The container used by the tensor.

impl<'a, Element> AsRefTensor for LweCiphertext<&'a mut [Element]>[src]

type Element = Element

The element type.

type Container = &'a mut [Element]

The container used by the tensor.

impl<Cont: Clone> Clone for LweCiphertext<Cont>[src]

impl<Cont: Debug> Debug for LweCiphertext<Cont>[src]

impl<'de, Cont> Deserialize<'de> for LweCiphertext<Cont> where
    Cont: Deserialize<'de>, 
[src]

impl<Element> IntoTensor for LweCiphertext<Vec<Element>>[src]

type Element = Element

The element type of the collection container.

type Container = Vec<Element>

The type of the collection container.

impl<Element> IntoTensor for LweCiphertext<AlignedVec<Element>>[src]

type Element = Element

The element type of the collection container.

type Container = AlignedVec<Element>

The type of the collection container.

impl<Element> IntoTensor for LweCiphertext<[Element; 1]>[src]

type Element = Element

The element type of the collection container.

type Container = [Element; 1]

The type of the collection container.

impl<'a, Element> IntoTensor for LweCiphertext<&'a [Element]>[src]

type Element = Element

The element type of the collection container.

type Container = &'a [Element]

The type of the collection container.

impl<'a, Element> IntoTensor for LweCiphertext<&'a mut [Element]>[src]

type Element = Element

The element type of the collection container.

type Container = &'a mut [Element]

The type of the collection container.

impl<Cont: PartialEq> PartialEq<LweCiphertext<Cont>> for LweCiphertext<Cont>[src]

impl<Cont> Serialize for LweCiphertext<Cont> where
    Cont: Serialize
[src]

impl<Cont> StructuralPartialEq for LweCiphertext<Cont>[src]

Auto Trait Implementations

impl<Cont> RefUnwindSafe for LweCiphertext<Cont> where
    Cont: RefUnwindSafe

impl<Cont> Send for LweCiphertext<Cont> where
    Cont: Send

impl<Cont> Sync for LweCiphertext<Cont> where
    Cont: Sync

impl<Cont> Unpin for LweCiphertext<Cont> where
    Cont: Unpin

impl<Cont> UnwindSafe for LweCiphertext<Cont> where
    Cont: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Input, Output> CastInto<Output> for Input where
    Output: CastFrom<Input>, 
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.