Struct concrete_core::crypto::secret::LweSecretKey[][src]

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

A LWE secret key.

Implementations

impl LweSecretKey<Vec<bool>>[src]

pub fn generate(size: LweDimension) -> Self[src]

Generates a new secret key; e.g. allocates a storage and samples random values for the key.

Example

use concrete_core::crypto::{*, secret::*};
let secret_key = LweSecretKey::generate(LweDimension(256));
assert_eq!(secret_key.key_size(), LweDimension(256));

impl<Cont> LweSecretKey<Cont>[src]

pub fn from_container(cont: Cont) -> Self where
    Cont: AsRefSlice
[src]

Creates an lwe secret key from a container.

Notes

This method does not fill the container with random values to create a new key. It merely wraps a container into the appropriate type. See LweSecretKey::generate for a generation method.

Example

use concrete_core::crypto::{*, secret::*};
let secret_key = LweSecretKey::from_container(vec![true; 256]);
assert_eq!(secret_key.key_size(), LweDimension(256));

pub fn key_size(&self) -> LweDimension where
    Self: AsRefTensor
[src]

Returns the size of the secret key.

Example

use concrete_core::crypto::{*, secret::*};
let secret_key = LweSecretKey::from_container(vec![true; 256]);
assert_eq!(secret_key.key_size(), LweDimension(256));

pub fn encrypt_lwe<OutputCont, Scalar>(
    &self,
    output: &mut LweCiphertext<OutputCont>,
    encoded: &Plaintext<Scalar>,
    noise_parameters: impl DispersionParameter
) where
    Self: AsRefTensor<Element = bool>,
    LweCiphertext<OutputCont>: AsMutTensor<Element = Scalar>,
    Scalar: UnsignedTorus
[src]

Encrypts a single ciphertext.

Example

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

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

let clear = Cleartext(2. as f32);
let plain: Plaintext<u32> = encoder.encode(clear);
let mut encrypted = LweCiphertext::allocate(0u32, LweSize(257));
secret_key.encrypt_lwe(&mut encrypted, &plain, noise);

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

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

pub fn encrypt_lwe_list<OutputCont, InputCont, Scalar>(
    &self,
    output: &mut LweList<OutputCont>,
    encoded: &PlaintextList<InputCont>,
    noise_parameters: impl DispersionParameter
) where
    Self: AsRefTensor<Element = bool>,
    LweList<OutputCont>: AsMutTensor<Element = Scalar>,
    PlaintextList<InputCont>: AsRefTensor<Element = Scalar>,
    Scalar: UnsignedTorus
[src]

Encrypts a list of ciphertexts.

Example

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

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

let clear_values = CleartextList::allocate(2. as f32, CleartextCount(100));
let mut plain_values = PlaintextList::allocate(0u32, PlaintextCount(100));
encoder.encode_list(&mut plain_values, &clear_values);
let mut encrypted_values = LweList::allocate(
    0u32,
    LweSize(257),
    CiphertextCount(100)
);
secret_key.encrypt_lwe_list(&mut encrypted_values, &plain_values, noise);

let mut decrypted_values = PlaintextList::allocate(0u32, PlaintextCount(100));
secret_key.decrypt_lwe_list(&mut decrypted_values, &encrypted_values);
let mut decoded_values = CleartextList::allocate(0. as f32, CleartextCount(100));
encoder.decode_list(&mut decoded_values, &decrypted_values);
for (clear, decoded) in clear_values.cleartext_iter().zip(decoded_values.cleartext_iter()) {
    assert!((clear.0 - decoded.0).abs() < 0.1);
}

pub fn trivial_encrypt_lwe<OutputCont, Scalar>(
    &self,
    output: &mut LweCiphertext<OutputCont>,
    encoded: &Plaintext<Scalar>,
    noise_parameters: impl DispersionParameter
) where
    Self: AsRefTensor<Element = bool>,
    LweCiphertext<OutputCont>: AsMutTensor<Element = Scalar>,
    Scalar: UnsignedTorus
[src]

Encrypts a single ciphertext with null masks.

Example

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

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

let clear = Cleartext(2. as f32);
let plain: Plaintext<u32> = encoder.encode(clear);
let mut encrypted = LweCiphertext::allocate(0u32, LweSize(257));
secret_key.trivial_encrypt_lwe(&mut encrypted, &plain, noise);

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

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

pub fn trivial_encrypt_lwe_list<OutputCont, InputCont, Scalar>(
    &self,
    output: &mut LweList<OutputCont>,
    encoded: &PlaintextList<InputCont>,
    noise_parameters: impl DispersionParameter
) where
    Self: AsRefTensor<Element = bool>,
    LweList<OutputCont>: AsMutTensor<Element = Scalar>,
    PlaintextList<InputCont>: AsRefTensor<Element = Scalar>,
    Scalar: UnsignedTorus
[src]

Encrypts a list of ciphertexts with null masks.

Example

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

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

let clear_values = CleartextList::allocate(2. as f32, CleartextCount(100));
let mut plain_values = PlaintextList::allocate(0u32, PlaintextCount(100));
encoder.encode_list(&mut plain_values, &clear_values);
let mut encrypted_values = LweList::allocate(
    0u32,
    LweSize(257),
    CiphertextCount(100)
);
secret_key.trivial_encrypt_lwe_list(&mut encrypted_values, &plain_values, noise);

for ciphertext in encrypted_values.ciphertext_iter(){
    for mask in ciphertext.get_mask().mask_element_iter(){
        assert_eq!(*mask, 0);
    }
}

let mut decrypted_values = PlaintextList::allocate(0u32, PlaintextCount(100));
secret_key.decrypt_lwe_list(&mut decrypted_values, &encrypted_values);
let mut decoded_values = CleartextList::allocate(0. as f32, CleartextCount(100));
encoder.decode_list(&mut decoded_values, &decrypted_values);
for (clear, decoded) in clear_values.cleartext_iter().zip(decoded_values.cleartext_iter()) {
    assert!((clear.0 - decoded.0).abs() < 0.1);
}

pub fn decrypt_lwe<Scalar, CipherCont>(
    &self,
    output: &mut Plaintext<Scalar>,
    cipher: &LweCiphertext<CipherCont>
) where
    Self: AsRefTensor<Element = bool>,
    LweCiphertext<CipherCont>: AsRefTensor<Element = Scalar>,
    Scalar: UnsignedTorus
[src]

Decrypts a single ciphertext.

See [‘encrypt_lwe’] for an example.

pub fn decrypt_lwe_list<Scalar, EncodedCont, CipherCont>(
    &self,
    output: &mut PlaintextList<EncodedCont>,
    cipher: &LweList<CipherCont>
) where
    Self: AsRefTensor<Element = bool>,
    PlaintextList<EncodedCont>: AsMutTensor<Element = Scalar>,
    LweList<CipherCont>: AsRefTensor<Element = Scalar>,
    Scalar: UnsignedTorus
[src]

Decrypts a list of ciphertexts.

See [‘encrypt_lwe_list’] for an example.

Trait Implementations

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

type Element = Element

The element type.

type Container = Vec<Element>

The container used by the tensor.

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

type Element = Element

The element type.

type Container = [Element; 1]

The container used by the tensor.

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

type Element = Element

The element type.

type Container = AlignedVec<Element>

The container used by the tensor.

impl<'a, Element> AsMutTensor for LweSecretKey<&'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 LweSecretKey<Vec<Element>>[src]

type Element = Element

The element type.

type Container = Vec<Element>

The container used by the tensor.

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

type Element = Element

The element type.

type Container = AlignedVec<Element>

The container used by the tensor.

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

type Element = Element

The element type.

type Container = [Element; 1]

The container used by the tensor.

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

type Element = Element

The element type.

type Container = &'a [Element]

The container used by the tensor.

impl<'a, Element> AsRefTensor for LweSecretKey<&'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 LweSecretKey<Cont>[src]

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

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

impl<Element> IntoTensor for LweSecretKey<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 LweSecretKey<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 LweSecretKey<[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 LweSecretKey<&'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 LweSecretKey<&'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<LweSecretKey<Cont>> for LweSecretKey<Cont>[src]

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

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

Auto Trait Implementations

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

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

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

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

impl<Cont> UnwindSafe for LweSecretKey<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.