Struct concrete_core::crypto::secret::LweSecretKey [−][src]
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]
Cont: AsRefSlice,
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]
Self: AsRefTensor,
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]
&self,
output: &mut LweCiphertext<OutputCont>,
encoded: &Plaintext<Scalar>,
noise_parameters: impl DispersionParameter
) where
Self: AsRefTensor<Element = bool>,
LweCiphertext<OutputCont>: AsMutTensor<Element = Scalar>,
Scalar: UnsignedTorus,
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]
&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,
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]
&self,
output: &mut LweCiphertext<OutputCont>,
encoded: &Plaintext<Scalar>,
noise_parameters: impl DispersionParameter
) where
Self: AsRefTensor<Element = bool>,
LweCiphertext<OutputCont>: AsMutTensor<Element = Scalar>,
Scalar: UnsignedTorus,
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]
&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,
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]
&self,
output: &mut Plaintext<Scalar>,
cipher: &LweCiphertext<CipherCont>
) where
Self: AsRefTensor<Element = bool>,
LweCiphertext<CipherCont>: AsRefTensor<Element = Scalar>,
Scalar: UnsignedTorus,
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]
&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,
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.
fn as_mut_tensor(&mut self) -> &mut Tensor<Self::Container>
[src]
impl<Element> AsMutTensor for LweSecretKey<[Element; 1]>
[src]
type Element = Element
The element type.
type Container = [Element; 1]
The container used by the tensor.
fn as_mut_tensor(&mut self) -> &mut Tensor<Self::Container>
[src]
impl<Element> AsMutTensor for LweSecretKey<AlignedVec<Element>>
[src]
type Element = Element
The element type.
type Container = AlignedVec<Element>
The container used by the tensor.
fn as_mut_tensor(&mut self) -> &mut Tensor<Self::Container>
[src]
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.
fn as_mut_tensor(&mut self) -> &mut Tensor<Self::Container>
[src]
impl<Element> AsRefTensor for LweSecretKey<Vec<Element>>
[src]
type Element = Element
The element type.
type Container = Vec<Element>
The container used by the tensor.
fn as_tensor(&self) -> &Tensor<Self::Container>
[src]
impl<Element> AsRefTensor for LweSecretKey<AlignedVec<Element>>
[src]
type Element = Element
The element type.
type Container = AlignedVec<Element>
The container used by the tensor.
fn as_tensor(&self) -> &Tensor<Self::Container>
[src]
impl<Element> AsRefTensor for LweSecretKey<[Element; 1]>
[src]
type Element = Element
The element type.
type Container = [Element; 1]
The container used by the tensor.
fn as_tensor(&self) -> &Tensor<Self::Container>
[src]
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.
fn as_tensor(&self) -> &Tensor<Self::Container>
[src]
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.
fn as_tensor(&self) -> &Tensor<Self::Container>
[src]
impl<Cont: Clone> Clone for LweSecretKey<Cont>
[src]
fn clone(&self) -> LweSecretKey<Cont>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<Cont: Debug> Debug for LweSecretKey<Cont>
[src]
impl<'de, Cont> Deserialize<'de> for LweSecretKey<Cont> where
Cont: Deserialize<'de>,
[src]
Cont: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
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.
fn into_tensor(self) -> Tensor<Self::Container>
[src]
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.
fn into_tensor(self) -> Tensor<Self::Container>
[src]
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.
fn into_tensor(self) -> Tensor<Self::Container>
[src]
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.
fn into_tensor(self) -> Tensor<Self::Container>
[src]
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.
fn into_tensor(self) -> Tensor<Self::Container>
[src]
impl<Cont: PartialEq> PartialEq<LweSecretKey<Cont>> for LweSecretKey<Cont>
[src]
fn eq(&self, other: &LweSecretKey<Cont>) -> bool
[src]
fn ne(&self, other: &LweSecretKey<Cont>) -> bool
[src]
impl<Cont> Serialize for LweSecretKey<Cont> where
Cont: Serialize,
[src]
Cont: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<Cont> StructuralPartialEq for LweSecretKey<Cont>
[src]
Auto Trait Implementations
impl<Cont> RefUnwindSafe for LweSecretKey<Cont> where
Cont: RefUnwindSafe,
Cont: RefUnwindSafe,
impl<Cont> Send for LweSecretKey<Cont> where
Cont: Send,
Cont: Send,
impl<Cont> Sync for LweSecretKey<Cont> where
Cont: Sync,
Cont: Sync,
impl<Cont> Unpin for LweSecretKey<Cont> where
Cont: Unpin,
Cont: Unpin,
impl<Cont> UnwindSafe for LweSecretKey<Cont> where
Cont: UnwindSafe,
Cont: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<Input, Output> CastInto<Output> for Input where
Output: CastFrom<Input>,
[src]
Output: CastFrom<Input>,
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,