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

The kind of the entity.
Formats the value using the given formatter. Read more

Description:

Implementation of EntitySerializationEngine for DefaultSerializationEngine that operates on 32 bits integers. It serializes a LWE ciphertext vector view entity. Immutable variant.

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);
Unsafely serializes an entity. Read more

Description:

Implementation of LweCiphertextVectorConsumingRetrievalEngine for DefaultEngine that returns the underlying slice of a LweCiphertextVectorView32 consuming it in the process

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);
Unsafely retrieves the content of the container from an LWE ciphertext vector, consuming it in the process. Read more

Description:

Implementation of LweCiphertextVectorCreationEngine for DefaultEngine which returns an immutable LweCiphertextVectorView32 that does not own its memory.

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)?;
Unsafely creates an LWE ciphertext vector from an arbitrary container. Read more

Description:

Implementation of LweCiphertextVectorDecryptionEngine for DefaultEngine that operates on 32 bits integers.

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)
);
Unsafely decrypts an LWE ciphertext vector. Read more
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)
);
Unsafely performs the circuit bootstrapping on all boolean input LWE ciphertexts followed by vertical packing using the provided look-up table. Read more
Returns the LWE dimension of the ciphertexts.
Returns the number of ciphertexts contained in the vector.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.