Struct concrete_core::backends::default::entities::LweCiphertextVectorView32
source · [−]pub struct LweCiphertextVectorView32<'a>(_);Expand description
A structure representing a vector of LWE ciphertext views, 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 LweCiphertextVectorView32<'_>
impl AbstractEntity for LweCiphertextVectorView32<'_>
type Kind = LweCiphertextVectorKind
type Kind = LweCiphertextVectorKind
sourceimpl<'a> Debug for LweCiphertextVectorView32<'a>
impl<'a> Debug for LweCiphertextVectorView32<'a>
sourceimpl<'b> EntitySerializationEngine<LweCiphertextVectorView32<'b>, Vec<u8, Global>> for DefaultSerializationEngine
impl<'b> EntitySerializationEngine<LweCiphertextVectorView32<'b>, Vec<u8, Global>> for DefaultSerializationEngine
Description:
Implementation of EntitySerializationEngine for DefaultSerializationEngine that operates
on 32 bits integers. It serializes a LWE ciphertext vector view entity. Immutable variant.
sourcefn serialize(
&mut self,
entity: &LweCiphertextVectorView32<'b>
) -> Result<Vec<u8>, EntitySerializationError<Self::EngineError>>
fn serialize(
&mut self,
entity: &LweCiphertextVectorView32<'b>
) -> Result<Vec<u8>, EntitySerializationError<Self::EngineError>>
Example:
use concrete_core::prelude::{LweCiphertextCount, LweDimension, Variance, *};
// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(6);
let lwe_count = LweCiphertextCount(3);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; lwe_count.0];
let noise = Variance(2_f64.powf(-50.));
// 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: LweSecretKey32 = engine.generate_new_lwe_secret_key(lwe_dimension)?;
let plaintext_vector: PlaintextVector32 = engine.create_plaintext_vector_from(&input)?;
let mut ciphertext_vector: LweCiphertextVector32 =
engine.encrypt_lwe_ciphertext_vector(&key, &plaintext_vector, noise)?;
let raw_buffer = engine.consume_retrieve_lwe_ciphertext_vector(ciphertext_vector)?;
let view: LweCiphertextVectorView32 = engine
.create_lwe_ciphertext_vector_from(raw_buffer.as_slice(), lwe_dimension.to_lwe_size())?;
let mut serialization_engine = DefaultSerializationEngine::new(())?;
let serialized = serialization_engine.serialize(&view)?;
let recovered: LweCiphertextVector32 =
serialization_engine.deserialize(serialized.as_slice())?;
let recovered_buffer = engine.consume_retrieve_lwe_ciphertext_vector(recovered)?;
assert_eq!(raw_buffer, recovered_buffer);
sourceunsafe fn serialize_unchecked(
&mut self,
entity: &LweCiphertextVectorView32<'b>
) -> Vec<u8>
unsafe fn serialize_unchecked(
&mut self,
entity: &LweCiphertextVectorView32<'b>
) -> Vec<u8>
sourceimpl<'data> LweCiphertextVectorConsumingRetrievalEngine<LweCiphertextVectorView32<'data>, &'data [u32]> for DefaultEngine
impl<'data> LweCiphertextVectorConsumingRetrievalEngine<LweCiphertextVectorView32<'data>, &'data [u32]> for DefaultEngine
Description:
Implementation of LweCiphertextVectorConsumingRetrievalEngine for DefaultEngine that
returns the underlying slice of a LweCiphertextVectorView32 consuming it in the process
sourcefn consume_retrieve_lwe_ciphertext_vector(
&mut self,
ciphertext: LweCiphertextVectorView32<'data>
) -> Result<&'data [u32], LweCiphertextVectorConsumingRetrievalError<Self::EngineError>>
fn consume_retrieve_lwe_ciphertext_vector(
&mut self,
ciphertext: LweCiphertextVectorView32<'data>
) -> Result<&'data [u32], LweCiphertextVectorConsumingRetrievalError<Self::EngineError>>
Example:
use concrete_core::prelude::{LweSize, *};
// 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 lwe_size = LweSize(16);
let lwe_ciphertext_count = LweCiphertextCount(8);
let mut owned_container = vec![0_u32; lwe_size.0 * lwe_ciphertext_count.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_vector_view: LweCiphertextVectorView32 =
engine.create_lwe_ciphertext_vector_from(slice, lwe_size)?;
let retrieved_slice = engine.consume_retrieve_lwe_ciphertext_vector(ciphertext_vector_view)?;
assert_eq!(slice, retrieved_slice);sourceunsafe fn consume_retrieve_lwe_ciphertext_vector_unchecked(
&mut self,
ciphertext: LweCiphertextVectorView32<'data>
) -> &'data [u32]
unsafe fn consume_retrieve_lwe_ciphertext_vector_unchecked(
&mut self,
ciphertext: LweCiphertextVectorView32<'data>
) -> &'data [u32]
sourceimpl<'data> LweCiphertextVectorCreationEngine<&'data [u32], LweCiphertextVectorView32<'data>> for DefaultEngine
impl<'data> LweCiphertextVectorCreationEngine<&'data [u32], LweCiphertextVectorView32<'data>> for DefaultEngine
Description:
Implementation of LweCiphertextVectorCreationEngine for DefaultEngine which returns an
immutable LweCiphertextVectorView32 that does not own its memory.
sourcefn create_lwe_ciphertext_vector_from(
&mut self,
container: &'data [u32],
lwe_size: LweSize
) -> Result<LweCiphertextVectorView32<'data>, LweCiphertextVectorCreationError<Self::EngineError>>
fn create_lwe_ciphertext_vector_from(
&mut self,
container: &'data [u32],
lwe_size: LweSize
) -> Result<LweCiphertextVectorView32<'data>, LweCiphertextVectorCreationError<Self::EngineError>>
Example:
use concrete_core::prelude::*;
// 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 lwe_size = LweSize(16);
let lwe_count = LweCiphertextCount(3);
let mut owned_container = vec![0_u32; lwe_size.0 * lwe_count.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_vector_view: LweCiphertextVectorView32 =
engine.create_lwe_ciphertext_vector_from(slice, lwe_size)?;sourceunsafe fn create_lwe_ciphertext_vector_from_unchecked(
&mut self,
container: &'data [u32],
lwe_size: LweSize
) -> LweCiphertextVectorView32<'data>
unsafe fn create_lwe_ciphertext_vector_from_unchecked(
&mut self,
container: &'data [u32],
lwe_size: LweSize
) -> LweCiphertextVectorView32<'data>
sourceimpl LweCiphertextVectorDecryptionEngine<LweSecretKey32, LweCiphertextVectorView32<'_>, PlaintextVector32> for DefaultEngine
impl LweCiphertextVectorDecryptionEngine<LweSecretKey32, LweCiphertextVectorView32<'_>, PlaintextVector32> for DefaultEngine
Description:
Implementation of LweCiphertextVectorDecryptionEngine for DefaultEngine that
operates on 32 bits integers.
sourcefn decrypt_lwe_ciphertext_vector(
&mut self,
key: &LweSecretKey32,
input: &LweCiphertextVectorView32<'_>
) -> Result<PlaintextVector32, LweCiphertextVectorDecryptionError<Self::EngineError>>
fn decrypt_lwe_ciphertext_vector(
&mut self,
key: &LweSecretKey32,
input: &LweCiphertextVectorView32<'_>
) -> Result<PlaintextVector32, LweCiphertextVectorDecryptionError<Self::EngineError>>
Example:
use concrete_core::prelude::*;
// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let lwe_dimension = LweDimension(6);
let lwe_count = LweCiphertextCount(18);
// Here a hard-set encoding is applied (shift by 20 bits)
let input = vec![3_u32 << 20; lwe_count.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: LweSecretKey32 = engine.generate_new_lwe_secret_key(lwe_dimension)?;
let plaintext_vector = engine.create_plaintext_vector_from(&input)?;
let mut raw_ciphertext_vector = vec![0_u32; key.lwe_dimension().to_lwe_size().0 * lwe_count.0];
let mut ciphertext_vector_view: LweCiphertextVectorMutView32 = engine
.create_lwe_ciphertext_vector_from(
&mut raw_ciphertext_vector[..],
lwe_dimension.to_lwe_size(),
)?;
engine.discard_encrypt_lwe_ciphertext_vector(
&key,
&mut ciphertext_vector_view,
&plaintext_vector,
noise,
)?;
// Convert MutView to View
let raw_ciphertext_vector =
engine.consume_retrieve_lwe_ciphertext_vector(ciphertext_vector_view)?;
let ciphertext_vector_view: LweCiphertextVectorView32 = engine
.create_lwe_ciphertext_vector_from(
&raw_ciphertext_vector[..],
lwe_dimension.to_lwe_size(),
)?;
let decrypted_plaintext_vector =
engine.decrypt_lwe_ciphertext_vector(&key, &ciphertext_vector_view)?;
assert_eq!(
decrypted_plaintext_vector.plaintext_count(),
PlaintextCount(lwe_count.0)
);
sourceunsafe fn decrypt_lwe_ciphertext_vector_unchecked(
&mut self,
key: &LweSecretKey32,
input: &LweCiphertextVectorView32<'_>
) -> PlaintextVector32
unsafe fn decrypt_lwe_ciphertext_vector_unchecked(
&mut self,
key: &LweSecretKey32,
input: &LweCiphertextVectorView32<'_>
) -> PlaintextVector32
sourceimpl LweCiphertextVectorDiscardingCircuitBootstrapBooleanVerticalPackingEngine<LweCiphertextVectorView32<'_>, LweCiphertextVectorMutView32<'_>, FftFourierLweBootstrapKey32, PlaintextVector32, LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys32> for FftEngine
impl LweCiphertextVectorDiscardingCircuitBootstrapBooleanVerticalPackingEngine<LweCiphertextVectorView32<'_>, LweCiphertextVectorMutView32<'_>, FftFourierLweBootstrapKey32, PlaintextVector32, LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys32> for FftEngine
sourcefn discard_circuit_bootstrap_boolean_vertical_packing_lwe_ciphertext_vector(
&mut self,
output: &mut LweCiphertextVectorMutView32<'_>,
input: &LweCiphertextVectorView32<'_>,
bsk: &FftFourierLweBootstrapKey32,
luts: &PlaintextVector32,
cbs_level_count: DecompositionLevelCount,
cbs_base_log: DecompositionBaseLog,
cbs_pfpksk: &LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys32
) -> Result<(), LweCiphertextVectorDiscardingCircuitBootstrapBooleanVerticalPackingError<Self::EngineError>>
fn discard_circuit_bootstrap_boolean_vertical_packing_lwe_ciphertext_vector(
&mut self,
output: &mut LweCiphertextVectorMutView32<'_>,
input: &LweCiphertextVectorView32<'_>,
bsk: &FftFourierLweBootstrapKey32,
luts: &PlaintextVector32,
cbs_level_count: DecompositionLevelCount,
cbs_base_log: DecompositionBaseLog,
cbs_pfpksk: &LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys32
) -> Result<(), LweCiphertextVectorDiscardingCircuitBootstrapBooleanVerticalPackingError<Self::EngineError>>
Example:
use concrete_core::prelude::*;
// DISCLAIMER: the parameters used here are only for test purpose, and are not secure.
let polynomial_size = PolynomialSize(1024);
let glwe_dimension = GlweDimension(1);
let lwe_dimension = LweDimension(481);
let var_small = Variance::from_variance(2f64.powf(-70.0));
let var_big = Variance::from_variance(2f64.powf(-60.0));
const UNSAFE_SECRET: u128 = 0;
let mut default_engine = DefaultEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut default_parallel_engine =
DefaultParallelEngine::new(Box::new(UnixSeeder::new(UNSAFE_SECRET)))?;
let mut fft_engine = FftEngine::new(())?;
let glwe_sk: GlweSecretKey32 =
default_engine.generate_new_glwe_secret_key(glwe_dimension, polynomial_size)?;
let lwe_small_sk: LweSecretKey32 = default_engine.generate_new_lwe_secret_key(lwe_dimension)?;
let lwe_big_sk: LweSecretKey32 =
default_engine.transform_glwe_secret_key_to_lwe_secret_key(glwe_sk.clone())?;
let bsk_level_count = DecompositionLevelCount(7);
let bsk_base_log = DecompositionBaseLog(4);
let std_bsk: LweBootstrapKey32 = default_parallel_engine.generate_new_lwe_bootstrap_key(
&lwe_small_sk,
&glwe_sk,
bsk_base_log,
bsk_level_count,
var_small,
)?;
let fourier_bsk: FftFourierLweBootstrapKey32 =
fft_engine.convert_lwe_bootstrap_key(&std_bsk)?;
let ksk_level_count = DecompositionLevelCount(9);
let ksk_base_log = DecompositionBaseLog(1);
let ksk_big_to_small: LweKeyswitchKey32 = default_engine.generate_new_lwe_keyswitch_key(
&lwe_big_sk,
&lwe_small_sk,
ksk_level_count,
ksk_base_log,
var_big,
)?;
let pfpksk_level_count = DecompositionLevelCount(7);
let pfpksk_base_log = DecompositionBaseLog(4);
let cbs_pfpksk: LweCircuitBootstrapPrivateFunctionalPackingKeyswitchKeys32 = default_engine
.generate_new_lwe_circuit_bootstrap_private_functional_packing_keyswitch_keys(
&lwe_big_sk,
&glwe_sk,
pfpksk_base_log,
pfpksk_level_count,
var_small,
)?;
// We will have a message with 10 bits of information
let message_bits = 10;
let bits_to_extract = ExtractedBitsCount(message_bits);
// The value we encrypt is 42, we will extract the bits of this value and apply the
// circuit bootstrapping followed by the vertical packing on the extracted bits.
let cleartext = 42;
let delta_log_msg = DeltaLog(32 - message_bits);
let encoded_message = default_engine.create_plaintext_from(&(cleartext << delta_log_msg.0))?;
let lwe_in = default_engine.encrypt_lwe_ciphertext(&lwe_big_sk, &encoded_message, var_big)?;
// Bit extraction output, use the zero_encrypt engine to allocate a ciphertext vector
let mut bit_extraction_output = default_engine.zero_encrypt_lwe_ciphertext_vector(
&lwe_small_sk,
var_small,
LweCiphertextCount(bits_to_extract.0),
)?;
fft_engine.discard_extract_bits_lwe_ciphertext(
&mut bit_extraction_output,
&lwe_in,
&fourier_bsk,
&ksk_big_to_small,
bits_to_extract,
delta_log_msg,
)?;
// Though the delta log here is the same as the message delta log, in the general case they
// are different, so we create two DeltaLog parameters
let delta_log_lut = DeltaLog(32 - message_bits);
// Create a look-up table we want to apply during vertical packing, here just the identity
// with the proper encoding.
// Note that this particular table will not trigger the cmux tree from the vertical packing,
// adapt the LUT generation to your usage.
// Here we apply a single look-up table as we output a single ciphertext.
let number_of_luts_and_output_vp_ciphertexts = 1;
let lut_size = 1 << bits_to_extract.0;
let mut lut: Vec<u32> = Vec::with_capacity(lut_size);
for i in 0..lut_size {
lut.push((i as u32 % (1 << message_bits)) << delta_log_lut.0);
}
let lut_as_plaintext_vector = default_engine.create_plaintext_vector_from(lut.as_slice())?;
// We run on views, so we need a container for the output
let mut output_cbs_vp_ct_container = vec![
0u32;
lwe_big_sk.lwe_dimension().to_lwe_size().0
* number_of_luts_and_output_vp_ciphertexts
];
let mut output_cbs_vp_ct_mut_view: LweCiphertextVectorMutView32 = default_engine
.create_lwe_ciphertext_vector_from(
output_cbs_vp_ct_container.as_mut_slice(),
lwe_big_sk.lwe_dimension().to_lwe_size(),
)?;
// And we need to get a view on the bits extracted earlier that serve as inputs to the
// circuit bootstrap + vertical packing
let extracted_bits_lwe_size = bit_extraction_output.lwe_dimension().to_lwe_size();
let extracted_bits_container =
default_engine.consume_retrieve_lwe_ciphertext_vector(bit_extraction_output)?;
let cbs_vp_input_vector_view: LweCiphertextVectorView32 = default_engine
.create_lwe_ciphertext_vector_from(
extracted_bits_container.as_slice(),
extracted_bits_lwe_size,
)?;
let cbs_level_count = DecompositionLevelCount(4);
let cbs_base_log = DecompositionBaseLog(6);
fft_engine.discard_circuit_bootstrap_boolean_vertical_packing_lwe_ciphertext_vector(
&mut output_cbs_vp_ct_mut_view,
&cbs_vp_input_vector_view,
&fourier_bsk,
&lut_as_plaintext_vector,
cbs_level_count,
cbs_base_log,
&cbs_pfpksk,
)?;
assert_eq!(output_cbs_vp_ct_mut_view.lwe_ciphertext_count().0, 1);
assert_eq!(
output_cbs_vp_ct_mut_view.lwe_dimension(),
LweDimension(glwe_dimension.0 * polynomial_size.0)
);