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

pub struct GlweSecretKey<Container> { /* fields omitted */ }

A GLWE secret key

Implementations

impl GlweSecretKey<Vec<bool>>[src]

pub fn generate(dimension: GlweDimension, poly_size: PolynomialSize) -> Self[src]

Allocates a container for a new key, and fill it with random values.

Example

use concrete_core::crypto::{*, secret::*};
use concrete_core::math::polynomial::PolynomialSize;
let secret_key = GlweSecretKey::generate(
    GlweDimension(256),
    PolynomialSize(10),
);
assert_eq!(secret_key.key_size(), GlweDimension(256));
assert_eq!(secret_key.polynomial_size(), PolynomialSize(10));

pub fn into_lwe_secret_key(self) -> LweSecretKey<Vec<bool>>[src]

Consumes the current GLWE secret key and turns it into an LWE secret key.

Examples

use concrete_core::crypto::secret::GlweSecretKey;
use concrete_core::crypto::{GlweDimension, LweDimension};
use concrete_core::math::polynomial::PolynomialSize;
let glwe_secret_key = GlweSecretKey::generate(
    GlweDimension(2),
    PolynomialSize(10),
);
let lwe_secret_key = glwe_secret_key.into_lwe_secret_key();
assert_eq!(lwe_secret_key.key_size(), LweDimension(20))

impl<Cont> GlweSecretKey<Cont>[src]

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

Creates a key from a container.

Notes

This method does not fill the container with random data. It merely wraps the container in the appropriate type. For a method that generate a new random key see GlweSecretKey::generate.

Example

use concrete_core::crypto::{*, secret::*};
use concrete_core::math::polynomial::PolynomialSize;
let secret_key = GlweSecretKey::from_container(
    vec![0 as u8; 11 * 256],
    PolynomialSize(11),
);
assert_eq!(secret_key.key_size(), GlweDimension(256));
assert_eq!(secret_key.polynomial_size(), PolynomialSize(11));

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

Returns the size of the secret key.

This is equivalent to the number of masks in the GlweCiphertext.

Example

use concrete_core::crypto::{*, secret::*};
use concrete_core::math::polynomial::PolynomialSize;
let secret_key = GlweSecretKey::generate(
    GlweDimension(256),
    PolynomialSize(10),
);
assert_eq!(secret_key.key_size(), GlweDimension(256));

pub fn polynomial_size(&self) -> PolynomialSize[src]

Returns the size of the secret key polynomials.

Example

use concrete_core::crypto::{*, secret::*};
use concrete_core::math::polynomial::PolynomialSize;
let secret_key = GlweSecretKey::generate(
    GlweDimension(256),
    PolynomialSize(10),
);
assert_eq!(secret_key.polynomial_size(), PolynomialSize(10));

pub fn as_polynomial_list(&self) -> PolynomialList<&[Self::Element]> where
    Self: AsRefTensor
[src]

Returns a borrowed polynomial list from the current key.

Example

use concrete_core::crypto::{*, secret::*};
use concrete_core::math::polynomial::{PolynomialCount, PolynomialSize};
let secret_key = GlweSecretKey::generate(
    GlweDimension(256),
    PolynomialSize(10),
);
let poly = secret_key.as_polynomial_list();
assert_eq!(poly.polynomial_count(), PolynomialCount(256));
assert_eq!(poly.polynomial_size(), PolynomialSize(10));

pub fn as_mut_polynomial_list(&mut self) -> PolynomialList<&mut [Self::Element]> where
    Self: AsMutTensor
[src]

Returns a mutably borrowed polynomial list from the current key.

Example

use concrete_core::crypto::{*, secret::*};
use concrete_core::math::polynomial::{PolynomialCount, PolynomialSize};
use concrete_core::math::tensor::{AsMutTensor, AsRefTensor};
let mut secret_key = GlweSecretKey::generate(
    GlweDimension(256),
    PolynomialSize(10),
);
let mut poly = secret_key.as_mut_polynomial_list();
poly.as_mut_tensor().fill_with_element(true);
assert!(secret_key.as_tensor().iter().all(|a| *a));

pub fn encrypt_glwe<OutputCont, EncCont, Scalar>(
    &self,
    encrypted: &mut GlweCiphertext<OutputCont>,
    encoded: &PlaintextList<EncCont>,
    noise_parameter: impl DispersionParameter
) where
    Self: AsRefTensor<Element = bool>,
    GlweCiphertext<OutputCont>: AsMutTensor<Element = Scalar>,
    PlaintextList<EncCont>: AsRefTensor<Element = Scalar>,
    Scalar: UnsignedTorus
[src]

Encrypts a single GLWE ciphertext.

Example

use concrete_core::crypto::{*, secret::*};
use concrete_core::math::polynomial::{PolynomialSize, PolynomialCount};
use concrete_core::math::tensor::{AsMutTensor, AsRefTensor};
use concrete_core::crypto::encoding::PlaintextList;
use concrete_core::crypto::glwe::GlweCiphertext;
use concrete_core::math::dispersion::LogStandardDev;
let secret_key = GlweSecretKey::generate(
    GlweDimension(256),
    PolynomialSize(5),
);
let noise = LogStandardDev::from_log_standard_dev(-25.);
let plaintexts = PlaintextList::from_container(
    vec![100000 as u32,200000,300000,400000, 500000]
);
let mut  ciphertext = GlweCiphertext::allocate(0 as u32, PolynomialSize(5), GlweSize(257));
secret_key.encrypt_glwe(&mut ciphertext, &plaintexts, noise);
let mut decrypted = PlaintextList::from_container(vec![0 as u32,0,0,0,0]);
secret_key.decrypt_glwe(&mut decrypted, &ciphertext);
for (dec, plain) in decrypted.plaintext_iter().zip(plaintexts.plaintext_iter()){
    let d0 = dec.0.wrapping_sub(plain.0);
    let d1 = plain.0.wrapping_sub(dec.0);
    let dist = std::cmp::min(d0, d1);
    assert!(dist < 400, "dist: {:?}", dist);
}

pub fn encrypt_zero_glwe<Scalar, OutputCont>(
    &self,
    encrypted: &mut GlweCiphertext<OutputCont>,
    noise_parameters: impl DispersionParameter
) where
    Self: AsRefTensor<Element = bool>,
    GlweCiphertext<OutputCont>: AsMutTensor<Element = Scalar>,
    Scalar: UnsignedTorus
[src]

Encrypts a zero plaintext into a GLWE ciphertext.

Example

use concrete_core::crypto::{*, secret::*};
use concrete_core::math::polynomial::{PolynomialSize, PolynomialCount};
use concrete_core::math::tensor::{AsMutTensor, AsRefTensor};
use concrete_core::crypto::encoding::PlaintextList;
use concrete_core::crypto::glwe::GlweCiphertext;
use concrete_core::math::dispersion::LogStandardDev;
let secret_key = GlweSecretKey::generate(
    GlweDimension(256),
    PolynomialSize(5),
);
let noise = LogStandardDev::from_log_standard_dev(-25.);
let mut  ciphertext = GlweCiphertext::allocate(0 as u32, PolynomialSize(5), GlweSize(257));
secret_key.encrypt_zero_glwe(&mut ciphertext, noise);
let mut decrypted = PlaintextList::from_container(vec![0 as u32,0,0,0,0]);
secret_key.decrypt_glwe(&mut decrypted, &ciphertext);
for dec in decrypted.plaintext_iter(){
    let d0 = dec.0.wrapping_sub(0u32);
    let d1 = 0u32.wrapping_sub(dec.0);
    let dist = std::cmp::min(d0, d1);
    assert!(dist < 500, "dist: {:?}", dist);
}

pub fn encrypt_glwe_list<CiphCont, EncCont, Scalar>(
    &self,
    encrypt: &mut GlweList<CiphCont>,
    encoded: &PlaintextList<EncCont>,
    noise_parameters: impl DispersionParameter
) where
    Self: AsRefTensor<Element = bool>,
    GlweList<CiphCont>: AsMutTensor<Element = Scalar>,
    PlaintextList<EncCont>: AsRefTensor<Element = Scalar>,
    Scalar: UnsignedTorus,
    PlaintextList<&'a [Scalar]>: AsRefTensor<Element = Scalar>, 
[src]

Encrypts a list of GLWE ciphertexts.

Example

use concrete_core::crypto::{*, secret::*};
use concrete_core::math::polynomial::{PolynomialSize, PolynomialCount};
use concrete_core::math::tensor::{AsMutTensor, AsRefTensor};
use concrete_core::crypto::encoding::PlaintextList;
use concrete_core::crypto::glwe::{GlweCiphertext, GlweList};
use concrete_core::math::dispersion::LogStandardDev;
let secret_key = GlweSecretKey::generate(
    GlweDimension(256),
    PolynomialSize(2),
);
let noise = LogStandardDev::from_log_standard_dev(-25.);
let plaintexts = PlaintextList::from_container(vec![1000 as u32,2000,3000,4000]);
let mut  ciphertexts = GlweList::allocate(
    0 as u32,
    PolynomialSize(2),
    GlweDimension(256),
    CiphertextCount(2)
);
secret_key.encrypt_glwe_list(&mut ciphertexts, &plaintexts, noise);
let mut decrypted = PlaintextList::from_container(vec![0 as u32,0,0,0]);
secret_key.decrypt_glwe_list(&mut decrypted, &ciphertexts);
for (dec, plain) in decrypted.plaintext_iter().zip(plaintexts.plaintext_iter()){
    let d0 = dec.0.wrapping_sub(plain.0);
    let d1 = plain.0.wrapping_sub(dec.0);
    let dist = std::cmp::min(d0, d1);
    assert!(dist < 400, "dist: {:?}", dist);
}

pub fn encrypt_zero_glwe_list<Scalar, OutputCont>(
    &self,
    encrypted: &mut GlweList<OutputCont>,
    noise_parameters: impl DispersionParameter
) where
    Self: AsRefTensor<Element = bool>,
    GlweList<OutputCont>: AsMutTensor<Element = Scalar>,
    Scalar: UnsignedTorus + Add
[src]

Encrypts a list of GLWE ciphertexts, with a zero plaintext.

Example

use concrete_core::crypto::{*, secret::*};
use concrete_core::math::polynomial::{PolynomialSize, PolynomialCount};
use concrete_core::math::tensor::{AsMutTensor, AsRefTensor};
use concrete_core::crypto::encoding::PlaintextList;
use concrete_core::crypto::glwe::{GlweCiphertext, GlweList};
use concrete_core::math::dispersion::LogStandardDev;
let secret_key = GlweSecretKey::generate(
    GlweDimension(256),
    PolynomialSize(2),
);
let noise = LogStandardDev::from_log_standard_dev(-25.);
let mut ciphertexts = GlweList::allocate(
    0 as u32,
    PolynomialSize(2),
    GlweDimension(256),
    CiphertextCount(2)
);
secret_key.encrypt_zero_glwe_list(&mut ciphertexts, noise);
let mut decrypted = PlaintextList::from_container(vec![0 as u32,0,0,0]);
secret_key.decrypt_glwe_list(&mut decrypted, &ciphertexts);
for dec in decrypted.plaintext_iter(){
    let d0 = dec.0.wrapping_sub(0u32);
    let d1 = 0u32.wrapping_sub(dec.0);
    let dist = std::cmp::min(d0, d1);
    assert!(dist < 400, "dist: {:?}", dist);
}

pub fn decrypt_glwe<CiphCont, EncCont, Scalar>(
    &self,
    encoded: &mut PlaintextList<EncCont>,
    encrypted: &GlweCiphertext<CiphCont>
) where
    Self: AsRefTensor<Element = bool>,
    PlaintextList<EncCont>: AsMutTensor<Element = Scalar>,
    GlweCiphertext<CiphCont>: AsRefTensor<Element = Scalar>,
    Scalar: UnsignedTorus + Add
[src]

Decrypts a single GLWE ciphertext.

See [’GlweSecretKey::encrypt_glwe`] for an example.

pub fn decrypt_glwe_list<CiphCont, EncCont, Scalar>(
    &self,
    encoded: &mut PlaintextList<EncCont>,
    encrypted: &GlweList<CiphCont>
) where
    Self: AsRefTensor<Element = bool>,
    PlaintextList<EncCont>: AsMutTensor<Element = Scalar>,
    GlweList<CiphCont>: AsRefTensor<Element = Scalar>,
    Scalar: UnsignedTorus + Add,
    PlaintextList<&'a mut [Scalar]>: AsMutTensor<Element = Scalar>, 
[src]

Decrypts a list of GLWE ciphertexts.

See [’GlweSecretKey::encrypt_glwe_list`] for an example.

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

This function encrypts a message as a GGSW ciphertext.

Examples

use concrete_core::crypto::secret::GlweSecretKey;
use concrete_core::math::polynomial::PolynomialSize;
use concrete_core::crypto::{GlweSize, GlweDimension};
use concrete_core::math::decomposition::{DecompositionLevelCount, DecompositionBaseLog};
use concrete_core::math::dispersion::LogStandardDev;
use concrete_core::crypto::encoding::Plaintext;
use concrete_core::crypto::ggsw::GgswCiphertext;
let secret_key = GlweSecretKey::generate(
    GlweDimension(2),
    PolynomialSize(10),
);
let mut ciphertext = GgswCiphertext::allocate(
    0 as u32,
    PolynomialSize(10),
    GlweSize(3),
    DecompositionLevelCount(3),
    DecompositionBaseLog(7)
);
let noise = LogStandardDev::from_log_standard_dev(-15.);
secret_key.encrypt_constant_ggsw(&mut ciphertext, &Plaintext(10), noise);

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

This function encrypts a message as a GGSW ciphertext whose rlwe masks are all zero.

Examples

use concrete_core::crypto::secret::GlweSecretKey;
use concrete_core::math::polynomial::PolynomialSize;
use concrete_core::crypto::{GlweSize, GlweDimension};
use concrete_core::math::decomposition::{DecompositionLevelCount, DecompositionBaseLog};
use concrete_core::math::dispersion::LogStandardDev;
use concrete_core::crypto::encoding::Plaintext;
use concrete_core::crypto::ggsw::GgswCiphertext;
let secret_key = GlweSecretKey::generate(
    GlweDimension(2),
    PolynomialSize(10),
);
let mut ciphertext = GgswCiphertext::allocate(
    0 as u32,
    PolynomialSize(10),
    GlweSize(3),
    DecompositionLevelCount(3),
    DecompositionBaseLog(7)
);
let noise = LogStandardDev::from_log_standard_dev(-15.);
secret_key.trivial_encrypt_constant_ggsw(&mut ciphertext, &Plaintext(10), noise);

Trait Implementations

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

type Element = Element

The element type.

type Container = Vec<Element>

The container used by the tensor.

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

type Element = Element

The element type.

type Container = [Element; 1]

The container used by the tensor.

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

type Element = Element

The element type.

type Container = AlignedVec<Element>

The container used by the tensor.

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

type Element = Element

The element type.

type Container = Vec<Element>

The container used by the tensor.

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

type Element = Element

The element type.

type Container = AlignedVec<Element>

The container used by the tensor.

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

type Element = Element

The element type.

type Container = [Element; 1]

The container used by the tensor.

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

type Element = Element

The element type.

type Container = &'a [Element]

The container used by the tensor.

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

type Element = Element

The element type.

type Container = &'a mut [Element]

The container used by the tensor.

impl<Container: Clone> Clone for GlweSecretKey<Container>[src]

impl<Container: Debug> Debug for GlweSecretKey<Container>[src]

impl<'de, Container> Deserialize<'de> for GlweSecretKey<Container> where
    Container: Deserialize<'de>, 
[src]

impl<Element> IntoTensor for GlweSecretKey<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 GlweSecretKey<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 GlweSecretKey<[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 GlweSecretKey<&'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 GlweSecretKey<&'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<Container: PartialEq> PartialEq<GlweSecretKey<Container>> for GlweSecretKey<Container>[src]

impl<Container> Serialize for GlweSecretKey<Container> where
    Container: Serialize
[src]

impl<Container> StructuralPartialEq for GlweSecretKey<Container>[src]

Auto Trait Implementations

impl<Container> RefUnwindSafe for GlweSecretKey<Container> where
    Container: RefUnwindSafe

impl<Container> Send for GlweSecretKey<Container> where
    Container: Send

impl<Container> Sync for GlweSecretKey<Container> where
    Container: Sync

impl<Container> Unpin for GlweSecretKey<Container> where
    Container: Unpin

impl<Container> UnwindSafe for GlweSecretKey<Container> where
    Container: 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.