Struct concrete_core::backends::default::entities::GlweCiphertextView64
source · [−]pub struct GlweCiphertextView64<'a>(_);
Expand description
A structure representing a GLWE ciphertext view, with 32 bits of precision.
By view here, we mean that the entity does not own the data, but immutably borrows it.
Notes:
This view is not Clone as Clone for a slice is not defined. It is not Deserialize either, as Deserialize of a slice is not defined. Immutable variant.
Trait Implementations
sourceimpl AbstractEntity for GlweCiphertextView64<'_>
impl AbstractEntity for GlweCiphertextView64<'_>
type Kind = GlweCiphertextKind
type Kind = GlweCiphertextKind
sourceimpl<'a> Debug for GlweCiphertextView64<'a>
impl<'a> Debug for GlweCiphertextView64<'a>
sourceimpl<'b> EntitySerializationEngine<GlweCiphertextView64<'b>, Vec<u8, Global>> for DefaultSerializationEngine
impl<'b> EntitySerializationEngine<GlweCiphertextView64<'b>, Vec<u8, Global>> for DefaultSerializationEngine
Description:
Implementation of EntitySerializationEngine
for DefaultSerializationEngine
that operates
on 64 bits integers. It serializes a GLWE ciphertext view entity.
sourcefn serialize(
&mut self,
entity: &GlweCiphertextView64<'b>
) -> Result<Vec<u8>, EntitySerializationError<Self::EngineError>>
fn serialize(
&mut self,
entity: &GlweCiphertextView64<'b>
) -> Result<Vec<u8>, EntitySerializationError<Self::EngineError>>
Example:
use concrete_core::prelude::{GlweDimension, PolynomialSize, Variance, *};
// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let glwe_dimension = GlweDimension(2);
let polynomial_size = PolynomialSize(4);
// There are always polynomial_size messages encrypted in the GLWE ciphertext
// Here a hard-set encoding is applied (shift by 50 bits)
let input = vec![3_u64 << 50; polynomial_size.0];
let noise = Variance(2_f64.powf(-25.));
// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let key: GlweSecretKey64 =
engine.generate_new_glwe_secret_key(glwe_dimension, polynomial_size)?;
let plaintext_vector = engine.create_plaintext_vector_from(&input)?;
let ciphertext = engine.encrypt_glwe_ciphertext(&key, &plaintext_vector, noise)?;
let raw_buffer = engine.consume_retrieve_glwe_ciphertext(ciphertext)?;
let view: GlweCiphertextView64 =
engine.create_glwe_ciphertext_from(raw_buffer.as_slice(), polynomial_size)?;
let mut serialization_engine = DefaultSerializationEngine::new(())?;
let serialized = serialization_engine.serialize(&view)?;
let recovered: GlweCiphertext64 = serialization_engine.deserialize(serialized.as_slice())?;
let recovered_buffer = engine.consume_retrieve_glwe_ciphertext(recovered)?;
assert_eq!(raw_buffer, recovered_buffer);
sourceunsafe fn serialize_unchecked(
&mut self,
entity: &GlweCiphertextView64<'b>
) -> Vec<u8>
unsafe fn serialize_unchecked(
&mut self,
entity: &GlweCiphertextView64<'b>
) -> Vec<u8>
sourceimpl<'data> GlweCiphertextConsumingRetrievalEngine<GlweCiphertextView64<'data>, &'data [u64]> for DefaultEngine
impl<'data> GlweCiphertextConsumingRetrievalEngine<GlweCiphertextView64<'data>, &'data [u64]> for DefaultEngine
Description:
Implementation of GlweCiphertextConsumingRetrievalEngine
for DefaultEngine
that returns
the underlying slice of a GlweCiphertextView64
consuming it in the process
sourcefn consume_retrieve_glwe_ciphertext(
&mut self,
ciphertext: GlweCiphertextView64<'data>
) -> Result<&'data [u64], GlweCiphertextConsumingRetrievalError<Self::EngineError>>
fn consume_retrieve_glwe_ciphertext(
&mut self,
ciphertext: GlweCiphertextView64<'data>
) -> Result<&'data [u64], GlweCiphertextConsumingRetrievalError<Self::EngineError>>
Example:
use concrete_core::prelude::{GlweSize, PolynomialSize, *};
// Here we create a container outside of the engine
// Note that the size here is just for demonstration purposes and should not be chosen
// without proper security analysis for production
let glwe_size = GlweSize(600);
let polynomial_size = PolynomialSize(1024);
// You have to make sure you size the container properly
let mut owned_container = vec![0_u64; glwe_size.0 * polynomial_size.0];
let slice = &owned_container[..];
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: GlweCiphertextView64 =
engine.create_glwe_ciphertext_from(slice, polynomial_size)?;
let retrieved_slice = engine.consume_retrieve_glwe_ciphertext(ciphertext_view)?;
assert_eq!(slice, retrieved_slice);
sourceunsafe fn consume_retrieve_glwe_ciphertext_unchecked(
&mut self,
ciphertext: GlweCiphertextView64<'data>
) -> &'data [u64]
unsafe fn consume_retrieve_glwe_ciphertext_unchecked(
&mut self,
ciphertext: GlweCiphertextView64<'data>
) -> &'data [u64]
sourceimpl<'data> GlweCiphertextCreationEngine<&'data [u64], GlweCiphertextView64<'data>> for DefaultEngine
impl<'data> GlweCiphertextCreationEngine<&'data [u64], GlweCiphertextView64<'data>> for DefaultEngine
Description:
Implementation of GlweCiphertextCreationEngine
for DefaultEngine
which returns an
immutable GlweCiphertextView64
that does not own its memory.
sourcefn create_glwe_ciphertext_from(
&mut self,
container: &'data [u64],
polynomial_size: PolynomialSize
) -> Result<GlweCiphertextView64<'data>, GlweCiphertextCreationError<Self::EngineError>>
fn create_glwe_ciphertext_from(
&mut self,
container: &'data [u64],
polynomial_size: PolynomialSize
) -> Result<GlweCiphertextView64<'data>, GlweCiphertextCreationError<Self::EngineError>>
Example:
use concrete_core::prelude::{PolynomialSize, *};
// Here we create a container outside of the engine
// Note that the size here is just for demonstration purposes and should not be chosen
// without proper security analysis for production
let glwe_size = 600_usize;
let polynomial_size = PolynomialSize(1024);
// You have to make sure you size the container properly
let mut owned_container = vec![0_u64; (glwe_size + 1) * polynomial_size.0];
let slice = &owned_container[..];
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let ciphertext_view: GlweCiphertextView64 =
engine.create_glwe_ciphertext_from(slice, polynomial_size)?;
sourceunsafe fn create_glwe_ciphertext_from_unchecked(
&mut self,
container: &'data [u64],
polynomial_size: PolynomialSize
) -> GlweCiphertextView64<'data>
unsafe fn create_glwe_ciphertext_from_unchecked(
&mut self,
container: &'data [u64],
polynomial_size: PolynomialSize
) -> GlweCiphertextView64<'data>
sourceimpl GlweCiphertextEntity for GlweCiphertextView64<'_>
impl GlweCiphertextEntity for GlweCiphertextView64<'_>
sourcefn glwe_dimension(&self) -> GlweDimension
fn glwe_dimension(&self) -> GlweDimension
sourcefn polynomial_size(&self) -> PolynomialSize
fn polynomial_size(&self) -> PolynomialSize
sourceimpl LweCiphertextDiscardingBootstrapEngine<FftFourierLweBootstrapKey64, GlweCiphertextView64<'_>, LweCiphertextView64<'_>, LweCiphertextMutView64<'_>> for FftEngine
impl LweCiphertextDiscardingBootstrapEngine<FftFourierLweBootstrapKey64, GlweCiphertextView64<'_>, LweCiphertextView64<'_>, LweCiphertextMutView64<'_>> for FftEngine
Description
Implementation of LweCiphertextDiscardingBootstrapEngine
for FftEngine
that operates
on 64 bit integers.
sourcefn discard_bootstrap_lwe_ciphertext(
&mut self,
output: &mut LweCiphertextMutView64<'_>,
input: &LweCiphertextView64<'_>,
acc: &GlweCiphertextView64<'_>,
bsk: &FftFourierLweBootstrapKey64
) -> Result<(), LweCiphertextDiscardingBootstrapError<Self::EngineError>>
fn discard_bootstrap_lwe_ciphertext(
&mut self,
output: &mut LweCiphertextMutView64<'_>,
input: &LweCiphertextView64<'_>,
acc: &GlweCiphertextView64<'_>,
bsk: &FftFourierLweBootstrapKey64
) -> Result<(), LweCiphertextDiscardingBootstrapError<Self::EngineError>>
Example
use concrete_core::prelude::{
DecompositionBaseLog, DecompositionLevelCount, GlweDimension, LweDimension, PolynomialSize,
Variance, *,
};
// Here a hard-set encoding is applied (shift by 20 bits)
use concrete_core::backends::fft::engines::FftEngine;
use concrete_core::backends::fft::entities::FftFourierLweBootstrapKey32;
let input = 3_u64 << 20;
// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let (lwe_dim, lwe_dim_output, glwe_dim, poly_size) = (
LweDimension(4),
LweDimension(1024),
GlweDimension(1),
PolynomialSize(1024),
);
let (dec_lc, dec_bl) = (DecompositionLevelCount(3), DecompositionBaseLog(5));
// A constant function is applied during the bootstrap
let lut = vec![8_u64 << 20; poly_size.0];
let noise = Variance(2_f64.powf(-25.));
// Unix seeder must be given a secret input.
// Here we just give it 0, which is totally unsafe.
const UNSAFE_SECRET: u128 = 0;
let mut default_engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut fft_engine = FftEngine::new(())?;
let lwe_sk: LweSecretKey64 = default_engine.generate_new_lwe_secret_key(lwe_dim)?;
let glwe_sk: GlweSecretKey64 =
default_engine.generate_new_glwe_secret_key(glwe_dim, poly_size)?;
let bsk: LweBootstrapKey64 =
default_engine.generate_new_lwe_bootstrap_key(&lwe_sk, &glwe_sk, dec_bl, dec_lc, noise)?;
let bsk: FftFourierLweBootstrapKey64 = fft_engine.convert_lwe_bootstrap_key(&bsk)?;
let lwe_sk_output: LweSecretKey64 =
default_engine.generate_new_lwe_secret_key(lwe_dim_output)?;
let plaintext = default_engine.create_plaintext_from(&input)?;
let plaintext_vector = default_engine.create_plaintext_vector_from(&lut)?;
let acc = default_engine
.trivially_encrypt_glwe_ciphertext(glwe_dim.to_glwe_size(), &plaintext_vector)?;
// Get the GlweCiphertext as a View
let raw_glwe = default_engine.consume_retrieve_glwe_ciphertext(acc)?;
let acc: GlweCiphertextView64 =
default_engine.create_glwe_ciphertext_from(&raw_glwe[..], poly_size)?;
let mut raw_input_container = vec![0_u64; lwe_sk.lwe_dimension().to_lwe_size().0];
let input: LweCiphertextMutView64 =
default_engine.create_lwe_ciphertext_from(&mut raw_input_container[..])?;
let input = default_engine.encrypt_lwe_ciphertext(&lwe_sk, &plaintext, noise)?;
// Convert MutView to View
let raw_input = default_engine.consume_retrieve_lwe_ciphertext(input)?;
let input = default_engine.create_lwe_ciphertext_from(&raw_input[..])?;
let mut raw_output_container = vec![0_u64; lwe_sk_output.lwe_dimension().to_lwe_size().0];
let mut output = default_engine.create_lwe_ciphertext_from(&mut raw_output_container[..])?;
fft_engine.discard_bootstrap_lwe_ciphertext(&mut output, &input, &acc, &bsk)?;
assert_eq!(output.lwe_dimension(), lwe_dim_output);